Skip to content

Commit

Permalink
feat: use the TJS skill-secret to send event
Browse files Browse the repository at this point in the history
  • Loading branch information
jbranchaud authored and kodiakhq[bot] committed Mar 7, 2024
1 parent c1d66a7 commit 15bcfa0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/skill-api/src/core/services/process-stripe-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,23 @@ export async function receiveStripeWebhooks({
// 3. tell the appropriate app to handle it...
// 4. return a 200

const {siteName} = z
const {siteName: targetSiteName} = z
.object({siteName: z.string().default(METADATA_MISSING_SITE_NAME)})
.parse(event.data.object.metadata)

if (siteName === 'testing-javascript') {
if (targetSiteName === 'testing-javascript') {
// send event to TJS processing endpoint
const internalStripeWebhookEndpoint = z
.string()
.parse(process.env.TESTING_JAVASCRIPT_INTERNAL_STRIPE_URL)
const skillSecret = z
.string({
required_error: 'TJS_SKILL_SECRET must be set in this environemnt',
})
.parse(process.env.TJS_SKILL_SECRET)

const headers = new Headers({
'x-skill-secret': process.env.SKILL_SECRET || '',
'x-skill-secret': skillSecret,
})

// not awaiting the fetch so that endpoint can return 200 right away
Expand All @@ -155,7 +160,7 @@ export async function receiveStripeWebhooks({
body: JSON.stringify(event),
})

return {status: 200, body: `handled by ${siteName}`}
return {status: 200, body: `handled by ${targetSiteName}`}
} else {
return await processStripeWebhook(event, {
nextAuthOptions,
Expand Down

0 comments on commit 15bcfa0

Please sign in to comment.