diff --git a/.pnp.cjs b/.pnp.cjs index 86486ff1..8673e9c6 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -28,7 +28,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./",\ "packageDependencies": [\ ["@awell-health/awell-sdk", "npm:0.1.20"],\ - ["@awell-health/extensions-core", "virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.19"],\ + ["@awell-health/extensions-core", "virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.20"],\ ["@awell-health/healthie-sdk", "npm:0.1.1"],\ ["@dropbox/sign", "npm:1.8.0"],\ ["@faker-js/faker", "npm:8.4.1"],\ @@ -222,7 +222,7 @@ const RAW_RUNTIME_STATE = "packageDependencies": [\ ["@awell-health/awell-extensions", "workspace:."],\ ["@awell-health/awell-sdk", "npm:0.1.20"],\ - ["@awell-health/extensions-core", "virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.19"],\ + ["@awell-health/extensions-core", "virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.20"],\ ["@awell-health/healthie-sdk", "npm:0.1.1"],\ ["@dropbox/sign", "npm:1.8.0"],\ ["@faker-js/faker", "npm:8.4.1"],\ @@ -332,17 +332,17 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["@awell-health/extensions-core", [\ - ["npm:1.0.19", {\ - "packageLocation": "./.yarn/cache/@awell-health-extensions-core-npm-1.0.19-8daf047da8-25e8eb6a9a.zip/node_modules/@awell-health/extensions-core/",\ + ["npm:1.0.20", {\ + "packageLocation": "./.yarn/cache/@awell-health-extensions-core-npm-1.0.20-9f25e5c3ea-fd829c1ced.zip/node_modules/@awell-health/extensions-core/",\ "packageDependencies": [\ - ["@awell-health/extensions-core", "npm:1.0.19"]\ + ["@awell-health/extensions-core", "npm:1.0.20"]\ ],\ "linkType": "SOFT"\ }],\ - ["virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.19", {\ - "packageLocation": "./.yarn/__virtual__/@awell-health-extensions-core-virtual-fd73770327/0/cache/@awell-health-extensions-core-npm-1.0.19-8daf047da8-25e8eb6a9a.zip/node_modules/@awell-health/extensions-core/",\ + ["virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.20", {\ + "packageLocation": "./.yarn/__virtual__/@awell-health-extensions-core-virtual-03d9179995/0/cache/@awell-health-extensions-core-npm-1.0.20-9f25e5c3ea-fd829c1ced.zip/node_modules/@awell-health/extensions-core/",\ "packageDependencies": [\ - ["@awell-health/extensions-core", "virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.19"],\ + ["@awell-health/extensions-core", "virtual:6d1931a4340173b37cf492f77cb803dda2f92958adb6847175388be3c73eb24be6f6bfd25e0fc0b7ad8dba815a972ad5e9d1f18e67fb58466bb7c99205a9d42e#npm:1.0.20"],\ ["@awell-health/awell-sdk", "npm:0.1.20"],\ ["@types/awell-health__awell-sdk", null],\ ["@types/json-schema", "npm:7.0.15"],\ diff --git a/.yarn/cache/@awell-health-extensions-core-npm-1.0.19-8daf047da8-25e8eb6a9a.zip b/.yarn/cache/@awell-health-extensions-core-npm-1.0.20-9f25e5c3ea-fd829c1ced.zip similarity index 85% rename from .yarn/cache/@awell-health-extensions-core-npm-1.0.19-8daf047da8-25e8eb6a9a.zip rename to .yarn/cache/@awell-health-extensions-core-npm-1.0.20-9f25e5c3ea-fd829c1ced.zip index c4297347..e73fc981 100644 Binary files a/.yarn/cache/@awell-health-extensions-core-npm-1.0.19-8daf047da8-25e8eb6a9a.zip and b/.yarn/cache/@awell-health-extensions-core-npm-1.0.20-9f25e5c3ea-fd829c1ced.zip differ diff --git a/extensions/elation/settings.ts b/extensions/elation/settings.ts index 41a6bba7..f022c65d 100644 --- a/extensions/elation/settings.ts +++ b/extensions/elation/settings.ts @@ -56,6 +56,18 @@ export const settings = { }, } satisfies Record +export const rateLimitDurationSchema = z + .string() + .regex( + /^\d+[ ]+[smhd]$/, + 'Duration must be in format {number} {unit} where unit is s,m,h,d', + ) + .transform((val): Duration => { + const [number, unit] = val.split(' ') + return `${number}${unit}` as Duration + }) + .optional() + export const SettingsValidationSchema = z.object({ base_url: z.string().min(1), auth_url: z.string().min(1), @@ -68,17 +80,7 @@ export const SettingsValidationSchema = z.object({ */ username: z.string().optional(), password: z.string().optional(), - rateLimitDuration: z - .string() - .regex( - /^\d+[ ]+[smhd]$/, - 'Duration must be in format {number} {unit} where unit is s,m,h,d', - ) - .transform((val): Duration => { - const [number, unit] = val.split(' ') - return `${number}${unit}` as Duration - }) - .optional(), + rateLimitDuration: rateLimitDurationSchema, } satisfies Record) export type SettingsType = z.infer diff --git a/extensions/elation/webhooks/appointmentCreatedOrUpdated.ts b/extensions/elation/webhooks/appointmentCreatedOrUpdated.ts index a6648ab2..5fc84195 100644 --- a/extensions/elation/webhooks/appointmentCreatedOrUpdated.ts +++ b/extensions/elation/webhooks/appointmentCreatedOrUpdated.ts @@ -6,6 +6,8 @@ import { ELATION_SYSTEM } from '../constants' import { type SubscriptionEvent } from '../types/subscription' import { createHash } from 'node:crypto' import { Duration } from '@upstash/ratelimit' +import { rateLimitDurationSchema, SettingsValidationSchema } from '../settings' +import { isNil } from 'lodash' const dataPoints = { appointmentId: { @@ -31,7 +33,6 @@ export const appointmentCreatedOrUpdated: Webhook< helpers, }) => { const { action, resource, data } = payload - const { rateLimitDuration } = settings const { id: appointmentId, patient: patientId } = data // skip non 'saved' actions for that webhook @@ -39,7 +40,11 @@ export const appointmentCreatedOrUpdated: Webhook< return } - if (rateLimitDuration) { + const rateLimitDuration = rateLimitDurationSchema.parse( + settings.rateLimitDuration, + ) + + if (!isNil(rateLimitDuration)) { const rateLimiter = helpers.rateLimit(1, rateLimitDuration as Duration) const strAppt = JSON.stringify(data) const uniqueHash = createHash('sha256').update(strAppt).digest('hex') diff --git a/extensions/elation/webhooks/patientCreatedOrUpdated.ts b/extensions/elation/webhooks/patientCreatedOrUpdated.ts index 80dcb9f4..d3d0c392 100644 --- a/extensions/elation/webhooks/patientCreatedOrUpdated.ts +++ b/extensions/elation/webhooks/patientCreatedOrUpdated.ts @@ -4,6 +4,7 @@ import { } from '@awell-health/extensions-core' import { type SubscriptionEvent } from '../types/subscription' import { Duration } from '@upstash/ratelimit' +import { rateLimitDurationSchema } from '../settings' import { createHash } from 'node:crypto' const dataPoints = { @@ -30,7 +31,6 @@ export const patientCreatedOrUpdated: Webhook< helpers, }) => { const { data, resource, action } = payload - const { rateLimitDuration } = settings const { id: patientId } = data // skip non 'saved' actions for that webhook @@ -38,6 +38,10 @@ export const patientCreatedOrUpdated: Webhook< return } + const rateLimitDuration = rateLimitDurationSchema.parse( + settings.rateLimitDuration, + ) + if (rateLimitDuration) { const rateLimiter = helpers.rateLimit(1, rateLimitDuration as Duration) const strPatient = JSON.stringify(data) diff --git a/package.json b/package.json index 36534e07..48c77014 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ }, "dependencies": { "@awell-health/awell-sdk": "^0.1.20", - "@awell-health/extensions-core": "1.0.19", + "@awell-health/extensions-core": "1.0.20", "@awell-health/healthie-sdk": "^0.1.1", "@dropbox/sign": "^1.8.0", "@hubspot/api-client": "^11.2.0", diff --git a/yarn.lock b/yarn.lock index 31e723a1..e009b43f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -87,7 +87,7 @@ __metadata: resolution: "@awell-health/awell-extensions@workspace:." dependencies: "@awell-health/awell-sdk": "npm:^0.1.20" - "@awell-health/extensions-core": "npm:1.0.19" + "@awell-health/extensions-core": "npm:1.0.20" "@awell-health/healthie-sdk": "npm:^0.1.1" "@dropbox/sign": "npm:^1.8.0" "@faker-js/faker": "npm:^8.0.2" @@ -194,9 +194,9 @@ __metadata: languageName: node linkType: hard -"@awell-health/extensions-core@npm:1.0.19": - version: 1.0.19 - resolution: "@awell-health/extensions-core@npm:1.0.19" +"@awell-health/extensions-core@npm:1.0.20": + version: 1.0.20 + resolution: "@awell-health/extensions-core@npm:1.0.20" dependencies: "@types/json-schema": "npm:^7.0.15" "@upstash/ratelimit": "npm:^2.0.5" @@ -208,7 +208,7 @@ __metadata: zod-validation-error: "npm:^3.2.0" peerDependencies: "@awell-health/awell-sdk": "*" - checksum: 10/25e8eb6a9a3fb0a83de715a67e74cf143434e3e964003393a1a5f3a34e44f5af5f642408ebdf72d42c09cdf8a17697830fd5c0160c17c687bec87fdf04fba788 + checksum: 10/fd829c1ced8c44dfbc9775b31ad3d96bf1afc5082b835ea06948514d66e6665efea2b5578f150efadcd80c347f240f6d3f850c8db7d484c0b264dff97f42112e languageName: node linkType: hard