@forklaunch/implementation-billing-stripe 1.0.1 → 1.1.0

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.
@@ -37,7 +37,7 @@ export class StripeWebhookService<
37
37
  SubscriptionEntities extends
38
38
  StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>
39
39
  > {
40
- protected readonly defaultPartyType: PartyEnum[keyof PartyEnum];
40
+ protected readonly partyEnum: PartyEnum;
41
41
  protected readonly stripeClient: Stripe;
42
42
  protected readonly em: EntityManager;
43
43
  protected readonly schemaValidator: SchemaValidator;
@@ -91,9 +91,9 @@ export class StripeWebhookService<
91
91
  PartyEnum,
92
92
  SubscriptionEntities
93
93
  >,
94
- defaultPartyType: PartyEnum[keyof PartyEnum]
94
+ partyEnum: PartyEnum
95
95
  ) {
96
- this.defaultPartyType = defaultPartyType;
96
+ this.partyEnum = partyEnum;
97
97
  this.stripeClient = stripeClient;
98
98
  this.em = em;
99
99
  this.schemaValidator = schemaValidator;
@@ -105,6 +105,25 @@ export class StripeWebhookService<
105
105
  this.subscriptionService = subscriptionService;
106
106
  }
107
107
 
108
+ /**
109
+ * Resolve the party type for a subscription event.
110
+ * Stripe subscriptions are customer-scoped — customers map to users
111
+ * by default. Override this method to implement organization-level
112
+ * subscriptions or other party resolution logic.
113
+ */
114
+ protected resolvePartyType(
115
+ _event: Stripe.Event
116
+ ): PartyEnum[keyof PartyEnum] {
117
+ // Default: first value in the enum container.
118
+ // Subclasses can override to inspect event metadata for party type.
119
+ const keys = Object.keys(
120
+ this.partyEnum as Record<string, unknown>
121
+ );
122
+ return (this.partyEnum as Record<string, PartyEnum[keyof PartyEnum]>)[
123
+ keys[0]
124
+ ];
125
+ }
126
+
108
127
  /**
109
128
  * Extract features from Stripe product metadata.
110
129
  * Features can be stored as:
@@ -379,7 +398,7 @@ export class StripeWebhookService<
379
398
  typeof event.data.object.customer === 'string'
380
399
  ? event.data.object.customer
381
400
  : event.data.object.customer.id,
382
- partyType: this.defaultPartyType,
401
+ partyType: this.resolvePartyType(event),
383
402
  description: event.data.object.description ?? undefined,
384
403
  active: true,
385
404
  productId: event.data.object.items.data[0].plan.id,
@@ -412,7 +431,7 @@ export class StripeWebhookService<
412
431
  typeof event.data.object.customer === 'string'
413
432
  ? event.data.object.customer
414
433
  : event.data.object.customer.id,
415
- partyType: this.defaultPartyType,
434
+ partyType: this.resolvePartyType(event),
416
435
  description: event.data.object.description ?? undefined,
417
436
  active: true,
418
437
  externalId: event.data.object.id,
@@ -159,7 +159,7 @@ declare class StripeSubscriptionService<SchemaValidator extends AnySchemaValidat
159
159
  }
160
160
 
161
161
  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>> {
162
- protected readonly defaultPartyType: PartyEnum[keyof PartyEnum];
162
+ protected readonly partyEnum: PartyEnum;
163
163
  protected readonly stripeClient: Stripe__default;
164
164
  protected readonly em: EntityManager;
165
165
  protected readonly schemaValidator: SchemaValidator;
@@ -169,7 +169,14 @@ declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, S
169
169
  protected readonly paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>;
170
170
  protected readonly planService: StripePlanService<SchemaValidator, PlanEntities>;
171
171
  protected readonly subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>;
172
- constructor(stripeClient: Stripe__default, 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>, defaultPartyType: PartyEnum[keyof PartyEnum]);
172
+ constructor(stripeClient: Stripe__default, 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);
173
+ /**
174
+ * Resolve the party type for a subscription event.
175
+ * Stripe subscriptions are customer-scoped — customers map to users
176
+ * by default. Override this method to implement organization-level
177
+ * subscriptions or other party resolution logic.
178
+ */
179
+ protected resolvePartyType(_event: Stripe__default.Event): PartyEnum[keyof PartyEnum];
173
180
  /**
174
181
  * Extract features from Stripe product metadata.
175
182
  * Features can be stored as:
@@ -159,7 +159,7 @@ declare class StripeSubscriptionService<SchemaValidator extends AnySchemaValidat
159
159
  }
160
160
 
161
161
  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>> {
162
- protected readonly defaultPartyType: PartyEnum[keyof PartyEnum];
162
+ protected readonly partyEnum: PartyEnum;
163
163
  protected readonly stripeClient: Stripe__default;
164
164
  protected readonly em: EntityManager;
165
165
  protected readonly schemaValidator: SchemaValidator;
@@ -169,7 +169,14 @@ declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, S
169
169
  protected readonly paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>;
170
170
  protected readonly planService: StripePlanService<SchemaValidator, PlanEntities>;
171
171
  protected readonly subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>;
172
- constructor(stripeClient: Stripe__default, 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>, defaultPartyType: PartyEnum[keyof PartyEnum]);
172
+ constructor(stripeClient: Stripe__default, 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);
173
+ /**
174
+ * Resolve the party type for a subscription event.
175
+ * Stripe subscriptions are customer-scoped — customers map to users
176
+ * by default. Override this method to implement organization-level
177
+ * subscriptions or other party resolution logic.
178
+ */
179
+ protected resolvePartyType(_event: Stripe__default.Event): PartyEnum[keyof PartyEnum];
173
180
  /**
174
181
  * Extract features from Stripe product metadata.
175
182
  * Features can be stored as:
@@ -692,7 +692,7 @@ var BillingProviderEnum = {
692
692
 
693
693
  // services/webhook.service.ts
694
694
  var StripeWebhookService = class {
695
- defaultPartyType;
695
+ partyEnum;
696
696
  stripeClient;
697
697
  em;
698
698
  schemaValidator;
@@ -702,8 +702,8 @@ var StripeWebhookService = class {
702
702
  paymentLinkService;
703
703
  planService;
704
704
  subscriptionService;
705
- constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, defaultPartyType) {
706
- this.defaultPartyType = defaultPartyType;
705
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum) {
706
+ this.partyEnum = partyEnum;
707
707
  this.stripeClient = stripeClient;
708
708
  this.em = em;
709
709
  this.schemaValidator = schemaValidator;
@@ -714,6 +714,18 @@ var StripeWebhookService = class {
714
714
  this.planService = planService;
715
715
  this.subscriptionService = subscriptionService;
716
716
  }
717
+ /**
718
+ * Resolve the party type for a subscription event.
719
+ * Stripe subscriptions are customer-scoped — customers map to users
720
+ * by default. Override this method to implement organization-level
721
+ * subscriptions or other party resolution logic.
722
+ */
723
+ resolvePartyType(_event) {
724
+ const keys = Object.keys(
725
+ this.partyEnum
726
+ );
727
+ return this.partyEnum[keys[0]];
728
+ }
717
729
  /**
718
730
  * Extract features from Stripe product metadata.
719
731
  * Features can be stored as:
@@ -922,7 +934,7 @@ var StripeWebhookService = class {
922
934
  {
923
935
  id: event.data.object.id,
924
936
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
925
- partyType: this.defaultPartyType,
937
+ partyType: this.resolvePartyType(event),
926
938
  description: event.data.object.description ?? void 0,
927
939
  active: true,
928
940
  productId: event.data.object.items.data[0].plan.id,
@@ -945,7 +957,7 @@ var StripeWebhookService = class {
945
957
  {
946
958
  id: event.data.object.id,
947
959
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
948
- partyType: this.defaultPartyType,
960
+ partyType: this.resolvePartyType(event),
949
961
  description: event.data.object.description ?? void 0,
950
962
  active: true,
951
963
  externalId: event.data.object.id,
@@ -660,7 +660,7 @@ var BillingProviderEnum = {
660
660
 
661
661
  // services/webhook.service.ts
662
662
  var StripeWebhookService = class {
663
- defaultPartyType;
663
+ partyEnum;
664
664
  stripeClient;
665
665
  em;
666
666
  schemaValidator;
@@ -670,8 +670,8 @@ var StripeWebhookService = class {
670
670
  paymentLinkService;
671
671
  planService;
672
672
  subscriptionService;
673
- constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, defaultPartyType) {
674
- this.defaultPartyType = defaultPartyType;
673
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum) {
674
+ this.partyEnum = partyEnum;
675
675
  this.stripeClient = stripeClient;
676
676
  this.em = em;
677
677
  this.schemaValidator = schemaValidator;
@@ -682,6 +682,18 @@ var StripeWebhookService = class {
682
682
  this.planService = planService;
683
683
  this.subscriptionService = subscriptionService;
684
684
  }
685
+ /**
686
+ * Resolve the party type for a subscription event.
687
+ * Stripe subscriptions are customer-scoped — customers map to users
688
+ * by default. Override this method to implement organization-level
689
+ * subscriptions or other party resolution logic.
690
+ */
691
+ resolvePartyType(_event) {
692
+ const keys = Object.keys(
693
+ this.partyEnum
694
+ );
695
+ return this.partyEnum[keys[0]];
696
+ }
685
697
  /**
686
698
  * Extract features from Stripe product metadata.
687
699
  * Features can be stored as:
@@ -890,7 +902,7 @@ var StripeWebhookService = class {
890
902
  {
891
903
  id: event.data.object.id,
892
904
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
893
- partyType: this.defaultPartyType,
905
+ partyType: this.resolvePartyType(event),
894
906
  description: event.data.object.description ?? void 0,
895
907
  active: true,
896
908
  productId: event.data.object.items.data[0].plan.id,
@@ -913,7 +925,7 @@ var StripeWebhookService = class {
913
925
  {
914
926
  id: event.data.object.id,
915
927
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
916
- partyType: this.defaultPartyType,
928
+ partyType: this.resolvePartyType(event),
917
929
  description: event.data.object.description ?? void 0,
918
930
  active: true,
919
931
  externalId: event.data.object.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-billing-stripe",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Stripe implementation for forklaunch billing",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {