@forklaunch/implementation-billing-stripe 1.1.32 → 1.1.33
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.
|
@@ -36,6 +36,19 @@ import { StripeSubscriptionService } from './subscription.service';
|
|
|
36
36
|
* `@forklaunch/implementation-billing-stripe/persistence`.
|
|
37
37
|
*/
|
|
38
38
|
type StripeWebhookEventEntity = InferEntity<typeof StripeWebhookEvent>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Structural constraint for injectable webhook event entities — the fields
|
|
42
|
+
* the idempotency flow reads and writes. Applications inject their own
|
|
43
|
+
* (typically richer, sqlBaseProperties-based) entity; the generic infers
|
|
44
|
+
* from the injected schema exactly like the mapper entity generics do.
|
|
45
|
+
*/
|
|
46
|
+
export type StripeWebhookEventShape = {
|
|
47
|
+
stripeId: string;
|
|
48
|
+
idempotencyKey?: string | null;
|
|
49
|
+
eventType: string;
|
|
50
|
+
eventData: unknown;
|
|
51
|
+
};
|
|
39
52
|
// mikro-orm 7 narrowed EntityName's type to exclude strings, but the runtime
|
|
40
53
|
// resolves registered entity names as it always has — and name resolution is
|
|
41
54
|
// exactly what we need by default (see above).
|
|
@@ -54,10 +67,11 @@ export class StripeWebhookService<
|
|
|
54
67
|
StripePaymentLinkEntities<StatusEnum> = StripePaymentLinkEntities<StatusEnum>,
|
|
55
68
|
PlanEntities extends StripePlanEntities = StripePlanEntities,
|
|
56
69
|
SubscriptionEntities extends
|
|
57
|
-
StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum
|
|
70
|
+
StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>,
|
|
71
|
+
WebhookEventEntity extends StripeWebhookEventShape = StripeWebhookEventEntity
|
|
58
72
|
> {
|
|
59
73
|
protected readonly partyEnum: PartyEnum;
|
|
60
|
-
protected readonly webhookEventEntity: EntityName<
|
|
74
|
+
protected readonly webhookEventEntity: EntityName<WebhookEventEntity>;
|
|
61
75
|
protected readonly stripeClient: Stripe;
|
|
62
76
|
protected readonly em: EntityManager;
|
|
63
77
|
protected readonly schemaValidator: SchemaValidator;
|
|
@@ -118,7 +132,7 @@ export class StripeWebhookService<
|
|
|
118
132
|
* 'StripeWebhookEvent'; inject your own entity (mapper-style) to use a
|
|
119
133
|
* different one.
|
|
120
134
|
*/
|
|
121
|
-
webhookEventEntity: EntityName<
|
|
135
|
+
webhookEventEntity: EntityName<WebhookEventEntity> = DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY as EntityName<WebhookEventEntity>
|
|
122
136
|
) {
|
|
123
137
|
this.webhookEventEntity = webhookEventEntity;
|
|
124
138
|
this.partyEnum = partyEnum;
|
|
@@ -182,8 +196,10 @@ export class StripeWebhookService<
|
|
|
182
196
|
}
|
|
183
197
|
|
|
184
198
|
if (
|
|
185
|
-
|
|
186
|
-
|
|
199
|
+
// querying through the structural shape with an internal cast, the same
|
|
200
|
+
// way the mapper services do (`mapper.entity as typeof Plan`)
|
|
201
|
+
await this.em.findOne<StripeWebhookEventShape>(
|
|
202
|
+
this.webhookEventEntity as EntityName<StripeWebhookEventShape>,
|
|
187
203
|
{
|
|
188
204
|
idempotencyKey: event.request?.idempotency_key
|
|
189
205
|
}
|
|
@@ -506,7 +522,8 @@ export class StripeWebhookService<
|
|
|
506
522
|
// em.create (not native em.insert): the app's entity generates its id and
|
|
507
523
|
// timestamps via onCreate hooks, which native inserts bypass — a native
|
|
508
524
|
// insert fails NOT NULL on id for sqlBaseProperties-style entities.
|
|
509
|
-
this.em.create<
|
|
525
|
+
this.em.create<StripeWebhookEventShape>(
|
|
526
|
+
this.webhookEventEntity as EntityName<StripeWebhookEventShape>, {
|
|
510
527
|
stripeId: event.id,
|
|
511
528
|
idempotencyKey: event.request?.idempotency_key,
|
|
512
529
|
eventType: event.type,
|
package/lib/services/index.js
CHANGED
|
@@ -687,12 +687,16 @@ var StripeWebhookService = class {
|
|
|
687
687
|
if (this.openTelemetryCollector) {
|
|
688
688
|
this.openTelemetryCollector.info("Handling webhook event", event);
|
|
689
689
|
}
|
|
690
|
-
if (
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
690
|
+
if (
|
|
691
|
+
// querying through the structural shape with an internal cast, the same
|
|
692
|
+
// way the mapper services do (`mapper.entity as typeof Plan`)
|
|
693
|
+
await this.em.findOne(
|
|
694
|
+
this.webhookEventEntity,
|
|
695
|
+
{
|
|
696
|
+
idempotencyKey: event.request?.idempotency_key
|
|
697
|
+
}
|
|
698
|
+
)
|
|
699
|
+
) {
|
|
696
700
|
this.openTelemetryCollector.info(
|
|
697
701
|
"Webhook event already processed",
|
|
698
702
|
event
|
|
@@ -935,12 +939,15 @@ var StripeWebhookService = class {
|
|
|
935
939
|
);
|
|
936
940
|
break;
|
|
937
941
|
}
|
|
938
|
-
this.em.create(
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
942
|
+
this.em.create(
|
|
943
|
+
this.webhookEventEntity,
|
|
944
|
+
{
|
|
945
|
+
stripeId: event.id,
|
|
946
|
+
idempotencyKey: event.request?.idempotency_key,
|
|
947
|
+
eventType: event.type,
|
|
948
|
+
eventData: event.data
|
|
949
|
+
}
|
|
950
|
+
);
|
|
944
951
|
await this.em.flush();
|
|
945
952
|
}
|
|
946
953
|
};
|
package/lib/services/index.mjs
CHANGED
|
@@ -655,12 +655,16 @@ var StripeWebhookService = class {
|
|
|
655
655
|
if (this.openTelemetryCollector) {
|
|
656
656
|
this.openTelemetryCollector.info("Handling webhook event", event);
|
|
657
657
|
}
|
|
658
|
-
if (
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
658
|
+
if (
|
|
659
|
+
// querying through the structural shape with an internal cast, the same
|
|
660
|
+
// way the mapper services do (`mapper.entity as typeof Plan`)
|
|
661
|
+
await this.em.findOne(
|
|
662
|
+
this.webhookEventEntity,
|
|
663
|
+
{
|
|
664
|
+
idempotencyKey: event.request?.idempotency_key
|
|
665
|
+
}
|
|
666
|
+
)
|
|
667
|
+
) {
|
|
664
668
|
this.openTelemetryCollector.info(
|
|
665
669
|
"Webhook event already processed",
|
|
666
670
|
event
|
|
@@ -903,12 +907,15 @@ var StripeWebhookService = class {
|
|
|
903
907
|
);
|
|
904
908
|
break;
|
|
905
909
|
}
|
|
906
|
-
this.em.create(
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
910
|
+
this.em.create(
|
|
911
|
+
this.webhookEventEntity,
|
|
912
|
+
{
|
|
913
|
+
stripeId: event.id,
|
|
914
|
+
idempotencyKey: event.request?.idempotency_key,
|
|
915
|
+
eventType: event.type,
|
|
916
|
+
eventData: event.data
|
|
917
|
+
}
|
|
918
|
+
);
|
|
912
919
|
await this.em.flush();
|
|
913
920
|
}
|
|
914
921
|
};
|
|
@@ -21,9 +21,21 @@ import { StripeSubscriptionService } from './subscription.service';
|
|
|
21
21
|
* `@forklaunch/implementation-billing-stripe/persistence`.
|
|
22
22
|
*/
|
|
23
23
|
type StripeWebhookEventEntity = InferEntity<typeof StripeWebhookEvent>;
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Structural constraint for injectable webhook event entities — the fields
|
|
26
|
+
* the idempotency flow reads and writes. Applications inject their own
|
|
27
|
+
* (typically richer, sqlBaseProperties-based) entity; the generic infers
|
|
28
|
+
* from the injected schema exactly like the mapper entity generics do.
|
|
29
|
+
*/
|
|
30
|
+
export type StripeWebhookEventShape = {
|
|
31
|
+
stripeId: string;
|
|
32
|
+
idempotencyKey?: string | null;
|
|
33
|
+
eventType: string;
|
|
34
|
+
eventData: unknown;
|
|
35
|
+
};
|
|
36
|
+
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>, WebhookEventEntity extends StripeWebhookEventShape = StripeWebhookEventEntity> {
|
|
25
37
|
protected readonly partyEnum: PartyEnum;
|
|
26
|
-
protected readonly webhookEventEntity: EntityName<
|
|
38
|
+
protected readonly webhookEventEntity: EntityName<WebhookEventEntity>;
|
|
27
39
|
protected readonly stripeClient: Stripe;
|
|
28
40
|
protected readonly em: EntityManager;
|
|
29
41
|
protected readonly schemaValidator: SchemaValidator;
|
|
@@ -40,7 +52,7 @@ export declare class StripeWebhookService<SchemaValidator extends AnySchemaValid
|
|
|
40
52
|
* 'StripeWebhookEvent'; inject your own entity (mapper-style) to use a
|
|
41
53
|
* different one.
|
|
42
54
|
*/
|
|
43
|
-
webhookEventEntity?: EntityName<
|
|
55
|
+
webhookEventEntity?: EntityName<WebhookEventEntity>);
|
|
44
56
|
/**
|
|
45
57
|
* Resolve the party type for a subscription event.
|
|
46
58
|
* Stripe subscriptions are customer-scoped — customers map to users
|
|
@@ -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,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,qCAAqC,CAA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