From 08300c25db89bd4db8d4074c861fc7fd64861602 Mon Sep 17 00:00:00 2001 From: Vinicius Alberkovics Date: Tue, 30 Nov 2021 20:44:16 -0300 Subject: [PATCH 1/3] feat: Add option onPrescriptionExcluded in setOptions BREAKING CHANGE: LGPD enforces the deletion of data on the side of the partner that uses the Memed service, as prescriptions must also be saved by the partner. --- src/actions/setupOptions.ts | 3 ++- src/domain/MdHub.ts | 2 +- src/domain/ModuleOptions.ts | 1 + src/errors/PrescriptionExcludedNotFunctionError.ts | 1 + src/errors/index.ts | 1 + src/hooks/useMemed.ts | 11 +++++++++-- tsconfig.json | 7 +++++-- 7 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/errors/PrescriptionExcludedNotFunctionError.ts diff --git a/src/actions/setupOptions.ts b/src/actions/setupOptions.ts index 72afd00..59ed3a3 100644 --- a/src/actions/setupOptions.ts +++ b/src/actions/setupOptions.ts @@ -6,7 +6,8 @@ export default function setupOptions(options: ModuleOptions): void { throw MdHubNotInitializedError } - const { onPrescriptionPrinted } = options + const { onPrescriptionPrinted, onPrescriptionExcluded } = options window.MdHub.event.add('prescricaoImpressa', onPrescriptionPrinted) + window.MdHub.event.add('prescricaoExcluida', onPrescriptionExcluded) } diff --git a/src/domain/MdHub.ts b/src/domain/MdHub.ts index 477b1b5..1dd82bd 100644 --- a/src/domain/MdHub.ts +++ b/src/domain/MdHub.ts @@ -13,6 +13,6 @@ export interface MdHub { } module: Module event: { - add(name: string, handler: (...args: unknown[]) => void): void + add(name: string, handler: (...args: T[]) => void): void } } diff --git a/src/domain/ModuleOptions.ts b/src/domain/ModuleOptions.ts index 102d3ae..df0182e 100644 --- a/src/domain/ModuleOptions.ts +++ b/src/domain/ModuleOptions.ts @@ -1,3 +1,4 @@ export interface ModuleOptions { onPrescriptionPrinted: (prescriptionData: unknown) => void + onPrescriptionExcluded: (prescriptionId: number) => void } diff --git a/src/errors/PrescriptionExcludedNotFunctionError.ts b/src/errors/PrescriptionExcludedNotFunctionError.ts new file mode 100644 index 0000000..a24a0b7 --- /dev/null +++ b/src/errors/PrescriptionExcludedNotFunctionError.ts @@ -0,0 +1 @@ +export default new Error('onPrescriptionPrinted must be a function.') diff --git a/src/errors/index.ts b/src/errors/index.ts index 413b9da..63cf6b7 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -2,3 +2,4 @@ export { default as MdHubNotInitializedError } from './MdHubNotInitializedError' export { default as MdSinapsePrescricaoNotInitializedError } from './MdSinapsePrescricaoNotInitializedError' export { default as ProviderNotPlacedError } from './ProviderNotPlacedError' export { default as PrescriptionPrintedNotFunctionError } from './PrescriptionPrintedNotFunctionError' +export { default as PrescriptionExcludedNotFunctionError } from './PrescriptionExcludedNotFunctionError' diff --git a/src/hooks/useMemed.ts b/src/hooks/useMemed.ts index 70846e2..426038c 100644 --- a/src/hooks/useMemed.ts +++ b/src/hooks/useMemed.ts @@ -1,6 +1,10 @@ import React from 'react' -import { ProviderNotPlacedError, PrescriptionPrintedNotFunctionError } from '../errors' +import { + ProviderNotPlacedError, + PrescriptionPrintedNotFunctionError, + PrescriptionExcludedNotFunctionError +} from '../errors' import { ModuleOptions } from '../domain' import MemedContext, { MemedContextValue } from '../contexts/MemedContext' @@ -14,7 +18,7 @@ export default function useMemed(options?: ModuleOptions): MemedContextValue { React.useEffect(() => { if (options && !optionsSet) { - const { onPrescriptionPrinted } = options + const { onPrescriptionPrinted, onPrescriptionExcluded } = options /** * I had to do this because of non-ts-implementations using the lib @@ -23,7 +27,10 @@ export default function useMemed(options?: ModuleOptions): MemedContextValue { // @ts-ignore if (typeof onPrescriptionPrinted !== 'function') { throw PrescriptionPrintedNotFunctionError + } else if (typeof onPrescriptionExcluded !== 'function') { + throw PrescriptionExcludedNotFunctionError } + memed.setOptions(options) setOptionsSet(true) } diff --git a/tsconfig.json b/tsconfig.json index ac5bd64..7eaed66 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,10 @@ "baseUrl": "./", "target": "ES2018", "module": "esnext", - "lib": ["ES2018", "DOM"], + "lib": [ + "ES2018", + "DOM" + ], "declaration": true, "composite": false, "downlevelIteration": true, @@ -23,4 +26,4 @@ "exclude": [ "lib/**" ] -} +} \ No newline at end of file From b34e422911714160c8f7929640834e2335147166 Mon Sep 17 00:00:00 2001 From: Vinicius Alberkovics Date: Tue, 30 Nov 2021 20:47:11 -0300 Subject: [PATCH 2/3] package version --- package.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1f362c5..7ea890d 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,22 @@ { "name": "memed-react", - "version": "2.0.5", + "version": "3.0.5", "description": "React library to integrate with memed", "main": "lib/index.js", "repository": "git@github.com:jonatassales/memed-react.git", "homepage": "https://memed-react-refs.vercel.app/", "author": "Jonatas Sales ", "license": "MIT", - "keywords": ["memed", "react memed", "memed integracao"], + "keywords": [ + "memed", + "react memed", + "memed integracao" + ], "scripts": { "build": "tsc", "lint": "eslint --ext .ts,.tsx ./src" }, - "peerDependencies": { + "peerDependencies": { "react": "16.8.x || 17.x" }, "devDependencies": { @@ -38,4 +42,4 @@ "pre-commit": "yarn prettier --check ./src && yarn lint && yarn build" } } -} +} \ No newline at end of file From 925cd281edc7ae80afb47e175cacc13854b13ad2 Mon Sep 17 00:00:00 2001 From: Vinicius Alberkovics Date: Tue, 30 Nov 2021 20:58:26 -0300 Subject: [PATCH 3/3] fix: error message --- src/errors/PrescriptionExcludedNotFunctionError.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors/PrescriptionExcludedNotFunctionError.ts b/src/errors/PrescriptionExcludedNotFunctionError.ts index a24a0b7..c30f997 100644 --- a/src/errors/PrescriptionExcludedNotFunctionError.ts +++ b/src/errors/PrescriptionExcludedNotFunctionError.ts @@ -1 +1 @@ -export default new Error('onPrescriptionPrinted must be a function.') +export default new Error('onPrescriptionExcluded must be a function.')