@coursebuilder/core
Version:
Core package for Course Builder
1 lines • 2.88 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/inngest/stripe/event-customer-subscription-updated.ts"],"sourcesContent":["import { CustomerSubscriptionUpdatedEvent } from 'src/schemas/stripe/customer-subscription-updated'\n\nimport {\n\tCoreInngestFunctionInput,\n\tCoreInngestHandler,\n\tCoreInngestTrigger,\n} from '../create-inngest-middleware'\n\nexport const STRIPE_CUSTOMER_SUBSCRIPTION_UPDATED_EVENT =\n\t'stripe/customer-subscription-updated'\n\nexport type StripeCustomerSubscriptionUpdated = {\n\tname: typeof STRIPE_CUSTOMER_SUBSCRIPTION_UPDATED_EVENT\n\tdata: {\n\t\tstripeEvent: CustomerSubscriptionUpdatedEvent\n\t}\n}\n\nexport const stripeCustomerSubscriptionUpdatedConfig = {\n\tid: 'stripe-customer-subscription-updated',\n\tname: 'Stripe Customer Subscription Updated',\n}\n\nexport const stripeCustomerSubscriptionUpdatedTrigger: CoreInngestTrigger = {\n\tevent: STRIPE_CUSTOMER_SUBSCRIPTION_UPDATED_EVENT,\n}\n\nexport const stripeCustomerSubscriptionUpdatedHandler: CoreInngestHandler =\n\tasync ({ event, step, db }: CoreInngestFunctionInput) => {\n\t\tconst subscription = event.data.stripeEvent.data.object\n\t\tconst previousAttributes = event.data.stripeEvent.data.previous_attributes\n\n\t\t// Handle status changes\n\t\tif (previousAttributes?.status) {\n\t\t\tawait step.run('handle subscription status change', async () => {\n\t\t\t\t// TODO: Update subscription status in our database\n\t\t\t\t// TODO: Handle cancellations, reactivations, etc.\n\t\t\t})\n\t\t}\n\n\t\t// Handle plan changes\n\t\tif (previousAttributes?.items) {\n\t\t\tawait step.run('handle subscription plan change', async () => {\n\t\t\t\t// TODO: Update subscription plan in our database\n\t\t\t\t// TODO: Handle any necessary side effects\n\t\t\t})\n\t\t}\n\t}\n\nexport const stripeCustomerSubscriptionUpdated = {\n\tconfig: stripeCustomerSubscriptionUpdatedConfig,\n\ttrigger: stripeCustomerSubscriptionUpdatedTrigger,\n\thandler: stripeCustomerSubscriptionUpdatedHandler,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA;;;;;;;;;AAAO,IAAMA,6CACZ;AASM,IAAMC,0CAA0C;EACtDC,IAAI;EACJC,MAAM;AACP;AAEO,IAAMC,2CAA+D;EAC3EC,OAAOL;AACR;AAEO,IAAMM,2CACZ,8BAAO,EAAED,OAAOE,MAAMC,GAAE,MAA4B;AACnD,QAAMC,eAAeJ,MAAMK,KAAKC,YAAYD,KAAKE;AACjD,QAAMC,qBAAqBR,MAAMK,KAAKC,YAAYD,KAAKI;AAGvD,MAAID,oBAAoBE,QAAQ;AAC/B,UAAMR,KAAKS,IAAI,qCAAqC,YAAA;IAGpD,CAAA;EACD;AAGA,MAAIH,oBAAoBI,OAAO;AAC9B,UAAMV,KAAKS,IAAI,mCAAmC,YAAA;IAGlD,CAAA;EACD;AACD,GAnBA;AAqBM,IAAME,oCAAoC;EAChDC,QAAQlB;EACRmB,SAAShB;EACTiB,SAASf;AACV;","names":["STRIPE_CUSTOMER_SUBSCRIPTION_UPDATED_EVENT","stripeCustomerSubscriptionUpdatedConfig","id","name","stripeCustomerSubscriptionUpdatedTrigger","event","stripeCustomerSubscriptionUpdatedHandler","step","db","subscription","data","stripeEvent","object","previousAttributes","previous_attributes","status","run","items","stripeCustomerSubscriptionUpdated","config","trigger","handler"]}