UNPKG

@coursebuilder/core

Version:

Core package for Course Builder

1 lines 2.34 kB
{"version":3,"sources":["../../../src/inngest/stripe/event-customer-subscription-created.ts"],"sourcesContent":["import { CustomerSubscriptionCreatedEvent } from 'src/schemas/stripe/customer-subscription-created'\n\nimport {\n\tCoreInngestFunctionInput,\n\tCoreInngestHandler,\n\tCoreInngestTrigger,\n} from '../create-inngest-middleware'\n\nexport const STRIPE_CUSTOMER_SUBSCRIPTION_CREATED_EVENT =\n\t'stripe/customer-subscription-created'\n\nexport type StripeCustomerSubscriptionCreated = {\n\tname: typeof STRIPE_CUSTOMER_SUBSCRIPTION_CREATED_EVENT\n\tdata: {\n\t\tstripeEvent: CustomerSubscriptionCreatedEvent\n\t}\n}\n\nexport const stripeCustomerSubscriptionCreatedConfig = {\n\tid: 'stripe-customer-subscription-created',\n\tname: 'Stripe Customer Subscription Created',\n}\n\nexport const stripeCustomerSubscriptionCreatedTrigger: CoreInngestTrigger = {\n\tevent: STRIPE_CUSTOMER_SUBSCRIPTION_CREATED_EVENT,\n}\n\nexport const stripeCustomerSubscriptionCreatedHandler: CoreInngestHandler =\n\tasync ({ event, step, db }: CoreInngestFunctionInput) => {\n\t\tconst subscription = event.data.stripeEvent.data.object\n\n\t\t// Validate subscription status\n\t\tif (\n\t\t\tsubscription.status !== 'active' &&\n\t\t\tsubscription.status !== 'trialing'\n\t\t) {\n\t\t\treturn\n\t\t}\n\n\t\t// TODO: Update subscription status in our database\n\t\t// TODO: Handle any necessary side effects (notifications, etc.)\n\t}\n\nexport const stripeCustomerSubscriptionCreated = {\n\tconfig: stripeCustomerSubscriptionCreatedConfig,\n\ttrigger: stripeCustomerSubscriptionCreatedTrigger,\n\thandler: stripeCustomerSubscriptionCreatedHandler,\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;AAGjD,MACCH,aAAaI,WAAW,YACxBJ,aAAaI,WAAW,YACvB;AACD;EACD;AAID,GAbA;AAeM,IAAMC,oCAAoC;EAChDC,QAAQd;EACRe,SAASZ;EACTa,SAASX;AACV;","names":["STRIPE_CUSTOMER_SUBSCRIPTION_CREATED_EVENT","stripeCustomerSubscriptionCreatedConfig","id","name","stripeCustomerSubscriptionCreatedTrigger","event","stripeCustomerSubscriptionCreatedHandler","step","db","subscription","data","stripeEvent","object","status","stripeCustomerSubscriptionCreated","config","trigger","handler"]}