@forklaunch/implementation-billing-stripe 1.1.31 → 1.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,8 +38,8 @@ import { StripeSubscriptionService } from './subscription.service';
38
38
  type StripeWebhookEventEntity = InferEntity<typeof StripeWebhookEvent>;
39
39
  // mikro-orm 7 narrowed EntityName's type to exclude strings, but the runtime
40
40
  // resolves registered entity names as it always has — and name resolution is
41
- // exactly what we need here (see above).
42
- const STRIPE_WEBHOOK_EVENT_ENTITY =
41
+ // exactly what we need by default (see above).
42
+ const DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY =
43
43
  'StripeWebhookEvent' as unknown as EntityName<StripeWebhookEventEntity>;
44
44
 
45
45
  export class StripeWebhookService<
@@ -57,6 +57,7 @@ export class StripeWebhookService<
57
57
  StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>
58
58
  > {
59
59
  protected readonly partyEnum: PartyEnum;
60
+ protected readonly webhookEventEntity: EntityName<StripeWebhookEventEntity>;
60
61
  protected readonly stripeClient: Stripe;
61
62
  protected readonly em: EntityManager;
62
63
  protected readonly schemaValidator: SchemaValidator;
@@ -110,8 +111,16 @@ export class StripeWebhookService<
110
111
  PartyEnum,
111
112
  SubscriptionEntities
112
113
  >,
113
- partyEnum: PartyEnum
114
+ partyEnum: PartyEnum,
115
+ /**
116
+ * The entity used for webhook idempotency records. Defaults to
117
+ * resolving the application's discovered entity named
118
+ * 'StripeWebhookEvent'; inject your own entity (mapper-style) to use a
119
+ * different one.
120
+ */
121
+ webhookEventEntity: EntityName<StripeWebhookEventEntity> = DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY
114
122
  ) {
123
+ this.webhookEventEntity = webhookEventEntity;
115
124
  this.partyEnum = partyEnum;
116
125
  this.stripeClient = stripeClient;
117
126
  this.em = em;
@@ -174,7 +183,7 @@ export class StripeWebhookService<
174
183
 
175
184
  if (
176
185
  await this.em.findOne<StripeWebhookEventEntity>(
177
- STRIPE_WEBHOOK_EVENT_ENTITY,
186
+ this.webhookEventEntity,
178
187
  {
179
188
  idempotencyKey: event.request?.idempotency_key
180
189
  }
@@ -497,7 +506,7 @@ export class StripeWebhookService<
497
506
  // em.create (not native em.insert): the app's entity generates its id and
498
507
  // timestamps via onCreate hooks, which native inserts bypass — a native
499
508
  // insert fails NOT NULL on id for sqlBaseProperties-style entities.
500
- this.em.create<StripeWebhookEventEntity>(STRIPE_WEBHOOK_EVENT_ENTITY, {
509
+ this.em.create<StripeWebhookEventEntity>(this.webhookEventEntity, {
501
510
  stripeId: event.id,
502
511
  idempotencyKey: event.request?.idempotency_key,
503
512
  eventType: event.type,
@@ -627,9 +627,10 @@ var BillingProviderEnum = {
627
627
  };
628
628
 
629
629
  // services/webhook.service.ts
630
- var STRIPE_WEBHOOK_EVENT_ENTITY = "StripeWebhookEvent";
630
+ var DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY = "StripeWebhookEvent";
631
631
  var StripeWebhookService = class {
632
632
  partyEnum;
633
+ webhookEventEntity;
633
634
  stripeClient;
634
635
  em;
635
636
  schemaValidator;
@@ -639,7 +640,8 @@ var StripeWebhookService = class {
639
640
  paymentLinkService;
640
641
  planService;
641
642
  subscriptionService;
642
- constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum) {
643
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum, webhookEventEntity = DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY) {
644
+ this.webhookEventEntity = webhookEventEntity;
643
645
  this.partyEnum = partyEnum;
644
646
  this.stripeClient = stripeClient;
645
647
  this.em = em;
@@ -686,7 +688,7 @@ var StripeWebhookService = class {
686
688
  this.openTelemetryCollector.info("Handling webhook event", event);
687
689
  }
688
690
  if (await this.em.findOne(
689
- STRIPE_WEBHOOK_EVENT_ENTITY,
691
+ this.webhookEventEntity,
690
692
  {
691
693
  idempotencyKey: event.request?.idempotency_key
692
694
  }
@@ -933,7 +935,7 @@ var StripeWebhookService = class {
933
935
  );
934
936
  break;
935
937
  }
936
- this.em.create(STRIPE_WEBHOOK_EVENT_ENTITY, {
938
+ this.em.create(this.webhookEventEntity, {
937
939
  stripeId: event.id,
938
940
  idempotencyKey: event.request?.idempotency_key,
939
941
  eventType: event.type,
@@ -595,9 +595,10 @@ var BillingProviderEnum = {
595
595
  };
596
596
 
597
597
  // services/webhook.service.ts
598
- var STRIPE_WEBHOOK_EVENT_ENTITY = "StripeWebhookEvent";
598
+ var DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY = "StripeWebhookEvent";
599
599
  var StripeWebhookService = class {
600
600
  partyEnum;
601
+ webhookEventEntity;
601
602
  stripeClient;
602
603
  em;
603
604
  schemaValidator;
@@ -607,7 +608,8 @@ var StripeWebhookService = class {
607
608
  paymentLinkService;
608
609
  planService;
609
610
  subscriptionService;
610
- constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum) {
611
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum, webhookEventEntity = DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY) {
612
+ this.webhookEventEntity = webhookEventEntity;
611
613
  this.partyEnum = partyEnum;
612
614
  this.stripeClient = stripeClient;
613
615
  this.em = em;
@@ -654,7 +656,7 @@ var StripeWebhookService = class {
654
656
  this.openTelemetryCollector.info("Handling webhook event", event);
655
657
  }
656
658
  if (await this.em.findOne(
657
- STRIPE_WEBHOOK_EVENT_ENTITY,
659
+ this.webhookEventEntity,
658
660
  {
659
661
  idempotencyKey: event.request?.idempotency_key
660
662
  }
@@ -901,7 +903,7 @@ var StripeWebhookService = class {
901
903
  );
902
904
  break;
903
905
  }
904
- this.em.create(STRIPE_WEBHOOK_EVENT_ENTITY, {
906
+ this.em.create(this.webhookEventEntity, {
905
907
  stripeId: event.id,
906
908
  idempotencyKey: event.request?.idempotency_key,
907
909
  eventType: event.type,
@@ -1,15 +1,29 @@
1
1
  import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
2
2
  import { AnySchemaValidator } from '@forklaunch/validator';
3
- import { EntityManager } from '@mikro-orm/core';
3
+ import { EntityManager, EntityName, InferEntity } from '@mikro-orm/core';
4
4
  import Stripe from 'stripe';
5
5
  import { StripeBillingPortalEntities, StripeCheckoutSessionEntities, StripePaymentLinkEntities, StripePlanEntities, StripeSubscriptionEntities } from '../domain/types/stripe.entity.types';
6
+ import { StripeWebhookEvent } from '../persistence/entities';
6
7
  import { StripeBillingPortalService } from './billingPortal.service';
7
8
  import { StripeCheckoutSessionService } from './checkoutSession.service';
8
9
  import { StripePaymentLinkService } from './paymentLink.service';
9
10
  import { StripePlanService } from './plan.service';
10
11
  import { StripeSubscriptionService } from './subscription.service';
12
+ /**
13
+ * Webhook idempotency records are looked up and written BY NAME so they
14
+ * resolve against the consuming application's discovered metadata. Passing
15
+ * this package's internal `StripeWebhookEvent` object to the EntityManager
16
+ * queries an entity the app's ORM never discovered, which mikro-orm 7.1.x
17
+ * rejects deep in EntityLoader (`meta.relations` is undefined for
18
+ * undiscovered entities). Applications must discover an entity named
19
+ * `StripeWebhookEvent` — either their own definition (the blueprint app
20
+ * ships one) or this package's, importable from
21
+ * `@forklaunch/implementation-billing-stripe/persistence`.
22
+ */
23
+ type StripeWebhookEventEntity = InferEntity<typeof StripeWebhookEvent>;
11
24
  export declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, StatusEnum, PartyEnum, BillingPortalEntities extends StripeBillingPortalEntities = StripeBillingPortalEntities, CheckoutSessionEntities extends StripeCheckoutSessionEntities<StatusEnum> = StripeCheckoutSessionEntities<StatusEnum>, PaymentLinkEntities extends StripePaymentLinkEntities<StatusEnum> = StripePaymentLinkEntities<StatusEnum>, PlanEntities extends StripePlanEntities = StripePlanEntities, SubscriptionEntities extends StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>> {
12
25
  protected readonly partyEnum: PartyEnum;
26
+ protected readonly webhookEventEntity: EntityName<StripeWebhookEventEntity>;
13
27
  protected readonly stripeClient: Stripe;
14
28
  protected readonly em: EntityManager;
15
29
  protected readonly schemaValidator: SchemaValidator;
@@ -19,7 +33,14 @@ export declare class StripeWebhookService<SchemaValidator extends AnySchemaValid
19
33
  protected readonly paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>;
20
34
  protected readonly planService: StripePlanService<SchemaValidator, PlanEntities>;
21
35
  protected readonly subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>;
22
- constructor(stripeClient: Stripe, em: EntityManager, schemaValidator: SchemaValidator, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, billingPortalService: StripeBillingPortalService<SchemaValidator, BillingPortalEntities>, checkoutSessionService: StripeCheckoutSessionService<SchemaValidator, StatusEnum, CheckoutSessionEntities>, paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>, planService: StripePlanService<SchemaValidator, PlanEntities>, subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>, partyEnum: PartyEnum);
36
+ constructor(stripeClient: Stripe, em: EntityManager, schemaValidator: SchemaValidator, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, billingPortalService: StripeBillingPortalService<SchemaValidator, BillingPortalEntities>, checkoutSessionService: StripeCheckoutSessionService<SchemaValidator, StatusEnum, CheckoutSessionEntities>, paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>, planService: StripePlanService<SchemaValidator, PlanEntities>, subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>, partyEnum: PartyEnum,
37
+ /**
38
+ * The entity used for webhook idempotency records. Defaults to
39
+ * resolving the application's discovered entity named
40
+ * 'StripeWebhookEvent'; inject your own entity (mapper-style) to use a
41
+ * different one.
42
+ */
43
+ webhookEventEntity?: EntityName<StripeWebhookEventEntity>);
23
44
  /**
24
45
  * Resolve the party type for a subscription event.
25
46
  * Stripe subscriptions are customer-scoped — customers map to users
@@ -36,4 +57,5 @@ export declare class StripeWebhookService<SchemaValidator extends AnySchemaValid
36
57
  private extractFeaturesFromProduct;
37
58
  handleWebhookEvent(event: Stripe.Event): Promise<void>;
38
59
  }
60
+ export {};
39
61
  //# sourceMappingURL=webhook.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.service.d.ts","sourceRoot":"","sources":["../../services/webhook.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAA2B,MAAM,iBAAiB,CAAC;AACzE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAoBnE,qBAAa,oBAAoB,CAC/B,eAAe,SAAS,kBAAkB,EAC1C,UAAU,EACV,SAAS,EACT,qBAAqB,SACnB,2BAA2B,GAAG,2BAA2B,EAC3D,uBAAuB,SACrB,6BAA6B,CAAC,UAAU,CAAC,GAAG,6BAA6B,CA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AAE,iBAAiB,CAC/C,eAAe,EACf,YAAY,CACb,CAAC;IACF,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,yBAAyB,CAC/D,eAAe,EACf,SAAS,EACT,oBAAoB,CACrB,CAAC;IAEF,YACE,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,aAAa,EACjB,eAAe,EAAE,eAAe,EAChC,sBAAsB,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,EACjE,oBAAoB,EAAE,0BAA0B,CAC9C,eAAe,EACf,qBAAqB,CACtB,EACD,sBAAsB,EAAE,4BAA4B,CAClD,eAAe,EACf,UAAU,EACV,uBAAuB,CACxB,EACD,kBAAkB,EAAE,wBAAwB,CAC1C,eAAe,EACf,UAAU,EACV,mBAAmB,CACpB,EACD,WAAW,EAAE,iBAAiB,CAAC,eAAe,EAAE,YAAY,CAAC,EAC7D,mBAAmB,EAAE,yBAAyB,CAC5C,eAAe,EACf,SAAS,EACT,oBAAoB,CACrB,EACD,SAAS,EAAE,SAAS;IACpB;;;;;OAKG;IACH,kBAAkB,GAAE,UAAU,CAAC,wBAAwB,CAAuC,EAa/F;IAED;;;;;OAKG;IACH,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,CAO3E;IAED;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAsB5B,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAiV3D;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-billing-stripe",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "description": "Stripe implementation for forklaunch billing",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {