Skip to content

Commit

Permalink
fix(elation): reverting to extensions core 1.0.18 and removing upstash
Browse files Browse the repository at this point in the history
  • Loading branch information
bejoinka committed Feb 6, 2025
1 parent 773aa75 commit 36b9818
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 181 deletions.
71 changes: 8 additions & 63 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
32 changes: 1 addition & 31 deletions extensions/elation/webhooks/appointmentCreatedOrUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ export const appointmentCreatedOrUpdated: Webhook<
> = {
key: 'appointmentCreatedOrUpdated',
dataPoints,
onEvent: async ({
payload: { payload, settings },
onSuccess,
onError,
helpers,
}) => {
onEvent: async ({ payload: { payload, settings }, onSuccess, onError }) => {
const { action, resource, data } = payload
const { id: appointmentId, patient: patientId } = data

Expand All @@ -40,31 +35,6 @@ export const appointmentCreatedOrUpdated: Webhook<
return
}

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')
// i'd rather use the unique hash here, but instead using an appointment ID
const { success } = await rateLimiter.limit(
`elation-appointment-${appointmentId}`,
)
if (!success) {
console.log(`ELATION: Rate limited for appointment_id=${appointmentId}`)
// we're sending a 200 response to elation to avoid them retrying the request
await onError({
response: {
statusCode: 200,
message: 'Rate limit exceeded',
},
})
return
}
}

if (resource !== 'appointments') {
await onError({
response: {
Expand Down
32 changes: 1 addition & 31 deletions extensions/elation/webhooks/patientCreatedOrUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ export const patientCreatedOrUpdated: Webhook<
> = {
key: 'patientCreatedOrUpdated',
dataPoints,
onEvent: async ({
payload: { payload, settings },
onSuccess,
onError,
helpers,
}) => {
onEvent: async ({ payload: { payload, settings }, onSuccess, onError }) => {
const { data, resource, action } = payload
const { id: patientId } = data

Expand All @@ -39,31 +34,6 @@ export const patientCreatedOrUpdated: Webhook<
return
}

const rateLimitDuration = rateLimitDurationSchema.parse(
settings.rateLimitDuration,
)

if (!isNil(rateLimitDuration)) {
const rateLimiter = helpers.rateLimit(1, rateLimitDuration as Duration)
const strPatient = JSON.stringify(data)
const uniqueHash = createHash('sha256').update(strPatient).digest('hex')
// i'd rather use the unique hash here, but instead using a patient ID
const { success } = await rateLimiter.limit(
`elation-patient-${patientId}`,
)
if (!success) {
console.log(`ELATION: Rate limited for patient_id=${patientId}`)
// we're sending a 200 response to elation to avoid them retrying the request
await onError({
response: {
statusCode: 200,
message: 'Rate limit exceeded',
},
})
return
}
}

if (resource !== 'patients') {
await onError({
response: {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"dependencies": {
"@awell-health/awell-sdk": "^0.1.20",
"@awell-health/extensions-core": "1.0.20",
"@awell-health/extensions-core": "1.0.18",
"@awell-health/healthie-sdk": "^0.1.1",
"@dropbox/sign": "^1.8.0",
"@hubspot/api-client": "^11.2.0",
Expand All @@ -91,7 +91,6 @@
"@sendgrid/helpers": "^7.7.0",
"@sendgrid/mail": "^7.7.0",
"@types/json-schema": "^7.0.15",
"@upstash/ratelimit": "^2.0.5",
"api": "^6.0.0",
"axios": "^1.6.8",
"body-parser": "^1.20.2",
Expand Down
37 changes: 26 additions & 11 deletions src/test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,36 @@ import {
AwellError,
} from '@awell-health/extensions-core'
import { extensions } from '../extensions'
import { Ratelimit } from '@upstash/ratelimit'
import { Redis } from 'ioredis'

const app = express()
const port = 3000

// type QueueInput = (
// | Parameters<OnCompleteCallback>[0]
// | Parameters<OnErrorCallback>[0]
// ) & { response: 'success' | 'failure' }

// const queue: QueueInput[] = []

app.use(bodyParser.json())

const limiter = Ratelimit.fixedWindow(1, '1m')
const rateLimit = new Ratelimit({
redis: new Redis({
host: 'localhost',
port: 6379,
password:
'VRmODJzStDXW0I0fr0G5UXd8v7Az5nJ4MvOMoGVR0iGhQEDuiACJLlNpBkBoyY8RUFhSW8tqt0ojoHIkqCJnLUeLRrmFHO47Og0DYv4wDv1pIfHCVU1uzFZOORNLDRp5',
}),
limiter,
})

app.post('/', async (req, res) => {
console.log(req.body)
try {
const { success } = await rateLimit.limit('test')
if (!success) {
res.status(429).send('Too many requests')
return
}
} catch (error) {
console.error(error)
}
res.send('ok')
})

Expand All @@ -45,7 +60,7 @@ app.post('/:extension/:action', async (req, res) => {
return
}
const action = Object.values(extension.actions).find(
({ key }) => key === actionKey
({ key }) => key === actionKey,
)
if (action === undefined) {
res
Expand Down Expand Up @@ -76,7 +91,7 @@ app.post('/:extension/:action', async (req, res) => {
},
],
})
}
},
)
// const result = queue.shift()
// res.send(result)
Expand All @@ -88,7 +103,7 @@ app.listen(port, () => {

const createOnCompleteCallback = (
// payload: NewActivityPayload,
res: express.Response
res: express.Response,
): OnCompleteCallback => {
return async (params = {}) => {
console.log({ ...params, response: 'success' })
Expand All @@ -98,7 +113,7 @@ const createOnCompleteCallback = (
}
const createOnErrorCallback = (
// payload: NewActivityPayload,
res: express.Response
res: express.Response,
): OnErrorCallback => {
return async (params = {}) => {
console.error({ ...params, response: 'failure' })
Expand Down
Loading

0 comments on commit 36b9818

Please sign in to comment.