@forklaunch/implementation-billing-stripe 1.1.33 → 1.2.1
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.
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
OpenTelemetryCollector
|
|
4
4
|
} from '@forklaunch/core/http';
|
|
5
5
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
6
|
-
import { EntityManager, EntityName
|
|
6
|
+
import { EntityManager, EntityName } from '@mikro-orm/core';
|
|
7
7
|
import Stripe from 'stripe';
|
|
8
8
|
import { BillingProviderEnum } from '../domain/enum/billingProvider.enum';
|
|
9
9
|
import { CurrencyEnum } from '../domain/enum/currency.enum';
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
StripePlanEntities,
|
|
17
17
|
StripeSubscriptionEntities
|
|
18
18
|
} from '../domain/types/stripe.entity.types';
|
|
19
|
-
import { StripeWebhookEvent } from '../persistence/entities';
|
|
20
19
|
import { StripeBillingPortalService } from './billingPortal.service';
|
|
21
20
|
|
|
22
21
|
import { StripeCheckoutSessionService } from './checkoutSession.service';
|
|
@@ -35,7 +34,6 @@ import { StripeSubscriptionService } from './subscription.service';
|
|
|
35
34
|
* ships one) or this package's, importable from
|
|
36
35
|
* `@forklaunch/implementation-billing-stripe/persistence`.
|
|
37
36
|
*/
|
|
38
|
-
type StripeWebhookEventEntity = InferEntity<typeof StripeWebhookEvent>;
|
|
39
37
|
|
|
40
38
|
/**
|
|
41
39
|
* Structural constraint for injectable webhook event entities — the fields
|
|
@@ -49,11 +47,6 @@ export type StripeWebhookEventShape = {
|
|
|
49
47
|
eventType: string;
|
|
50
48
|
eventData: unknown;
|
|
51
49
|
};
|
|
52
|
-
// mikro-orm 7 narrowed EntityName's type to exclude strings, but the runtime
|
|
53
|
-
// resolves registered entity names as it always has — and name resolution is
|
|
54
|
-
// exactly what we need by default (see above).
|
|
55
|
-
const DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY =
|
|
56
|
-
'StripeWebhookEvent' as unknown as EntityName<StripeWebhookEventEntity>;
|
|
57
50
|
|
|
58
51
|
export class StripeWebhookService<
|
|
59
52
|
SchemaValidator extends AnySchemaValidator,
|
|
@@ -68,10 +61,10 @@ export class StripeWebhookService<
|
|
|
68
61
|
PlanEntities extends StripePlanEntities = StripePlanEntities,
|
|
69
62
|
SubscriptionEntities extends
|
|
70
63
|
StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>,
|
|
71
|
-
WebhookEventEntity extends StripeWebhookEventShape =
|
|
64
|
+
WebhookEventEntity extends StripeWebhookEventShape = StripeWebhookEventShape
|
|
72
65
|
> {
|
|
73
66
|
protected readonly partyEnum: PartyEnum;
|
|
74
|
-
protected readonly webhookEventEntity:
|
|
67
|
+
protected readonly webhookEventEntity: { '~entity': WebhookEventEntity };
|
|
75
68
|
protected readonly stripeClient: Stripe;
|
|
76
69
|
protected readonly em: EntityManager;
|
|
77
70
|
protected readonly schemaValidator: SchemaValidator;
|
|
@@ -132,7 +125,14 @@ export class StripeWebhookService<
|
|
|
132
125
|
* 'StripeWebhookEvent'; inject your own entity (mapper-style) to use a
|
|
133
126
|
* different one.
|
|
134
127
|
*/
|
|
135
|
-
|
|
128
|
+
/**
|
|
129
|
+
* The application's discovered webhook idempotency entity — this sealed
|
|
130
|
+
* package must operate on the entity the app's ORM actually discovered
|
|
131
|
+
* (its own definition, or this package's via the ./persistence subpath).
|
|
132
|
+
* Querying an undiscovered entity object crashes mikro-orm 7.1.x deep in
|
|
133
|
+
* EntityLoader (meta.relations undefined).
|
|
134
|
+
*/
|
|
135
|
+
webhookEventEntity: { '~entity': WebhookEventEntity }
|
|
136
136
|
) {
|
|
137
137
|
this.webhookEventEntity = webhookEventEntity;
|
|
138
138
|
this.partyEnum = partyEnum;
|
|
@@ -198,8 +198,9 @@ export class StripeWebhookService<
|
|
|
198
198
|
if (
|
|
199
199
|
// querying through the structural shape with an internal cast, the same
|
|
200
200
|
// way the mapper services do (`mapper.entity as typeof Plan`)
|
|
201
|
-
await this.em.findOne
|
|
202
|
-
this
|
|
201
|
+
await this.em.findOne(
|
|
202
|
+
this
|
|
203
|
+
.webhookEventEntity as unknown as EntityName<StripeWebhookEventShape>,
|
|
203
204
|
{
|
|
204
205
|
idempotencyKey: event.request?.idempotency_key
|
|
205
206
|
}
|
|
@@ -523,12 +524,14 @@ export class StripeWebhookService<
|
|
|
523
524
|
// timestamps via onCreate hooks, which native inserts bypass — a native
|
|
524
525
|
// insert fails NOT NULL on id for sqlBaseProperties-style entities.
|
|
525
526
|
this.em.create<StripeWebhookEventShape>(
|
|
526
|
-
this.webhookEventEntity as EntityName<StripeWebhookEventShape>,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
527
|
+
this.webhookEventEntity as unknown as EntityName<StripeWebhookEventShape>,
|
|
528
|
+
{
|
|
529
|
+
stripeId: event.id,
|
|
530
|
+
idempotencyKey: event.request?.idempotency_key,
|
|
531
|
+
eventType: event.type,
|
|
532
|
+
eventData: event.data
|
|
533
|
+
} as never
|
|
534
|
+
);
|
|
532
535
|
await this.em.flush();
|
|
533
536
|
}
|
|
534
537
|
}
|
package/lib/services/index.js
CHANGED
|
@@ -627,7 +627,6 @@ var BillingProviderEnum = {
|
|
|
627
627
|
};
|
|
628
628
|
|
|
629
629
|
// services/webhook.service.ts
|
|
630
|
-
var DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY = "StripeWebhookEvent";
|
|
631
630
|
var StripeWebhookService = class {
|
|
632
631
|
partyEnum;
|
|
633
632
|
webhookEventEntity;
|
|
@@ -640,7 +639,7 @@ var StripeWebhookService = class {
|
|
|
640
639
|
paymentLinkService;
|
|
641
640
|
planService;
|
|
642
641
|
subscriptionService;
|
|
643
|
-
constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum, webhookEventEntity
|
|
642
|
+
constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum, webhookEventEntity) {
|
|
644
643
|
this.webhookEventEntity = webhookEventEntity;
|
|
645
644
|
this.partyEnum = partyEnum;
|
|
646
645
|
this.stripeClient = stripeClient;
|
package/lib/services/index.mjs
CHANGED
|
@@ -595,7 +595,6 @@ var BillingProviderEnum = {
|
|
|
595
595
|
};
|
|
596
596
|
|
|
597
597
|
// services/webhook.service.ts
|
|
598
|
-
var DEFAULT_STRIPE_WEBHOOK_EVENT_ENTITY = "StripeWebhookEvent";
|
|
599
598
|
var StripeWebhookService = class {
|
|
600
599
|
partyEnum;
|
|
601
600
|
webhookEventEntity;
|
|
@@ -608,7 +607,7 @@ var StripeWebhookService = class {
|
|
|
608
607
|
paymentLinkService;
|
|
609
608
|
planService;
|
|
610
609
|
subscriptionService;
|
|
611
|
-
constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum, webhookEventEntity
|
|
610
|
+
constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum, webhookEventEntity) {
|
|
612
611
|
this.webhookEventEntity = webhookEventEntity;
|
|
613
612
|
this.partyEnum = partyEnum;
|
|
614
613
|
this.stripeClient = stripeClient;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
|
|
2
2
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
3
|
-
import { EntityManager
|
|
3
|
+
import { EntityManager } 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';
|
|
7
6
|
import { StripeBillingPortalService } from './billingPortal.service';
|
|
8
7
|
import { StripeCheckoutSessionService } from './checkoutSession.service';
|
|
9
8
|
import { StripePaymentLinkService } from './paymentLink.service';
|
|
@@ -20,7 +19,6 @@ import { StripeSubscriptionService } from './subscription.service';
|
|
|
20
19
|
* ships one) or this package's, importable from
|
|
21
20
|
* `@forklaunch/implementation-billing-stripe/persistence`.
|
|
22
21
|
*/
|
|
23
|
-
type StripeWebhookEventEntity = InferEntity<typeof StripeWebhookEvent>;
|
|
24
22
|
/**
|
|
25
23
|
* Structural constraint for injectable webhook event entities — the fields
|
|
26
24
|
* the idempotency flow reads and writes. Applications inject their own
|
|
@@ -33,9 +31,11 @@ export type StripeWebhookEventShape = {
|
|
|
33
31
|
eventType: string;
|
|
34
32
|
eventData: unknown;
|
|
35
33
|
};
|
|
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 =
|
|
34
|
+
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 = StripeWebhookEventShape> {
|
|
37
35
|
protected readonly partyEnum: PartyEnum;
|
|
38
|
-
protected readonly webhookEventEntity:
|
|
36
|
+
protected readonly webhookEventEntity: {
|
|
37
|
+
'~entity': WebhookEventEntity;
|
|
38
|
+
};
|
|
39
39
|
protected readonly stripeClient: Stripe;
|
|
40
40
|
protected readonly em: EntityManager;
|
|
41
41
|
protected readonly schemaValidator: SchemaValidator;
|
|
@@ -52,7 +52,16 @@ export declare class StripeWebhookService<SchemaValidator extends AnySchemaValid
|
|
|
52
52
|
* 'StripeWebhookEvent'; inject your own entity (mapper-style) to use a
|
|
53
53
|
* different one.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The application's discovered webhook idempotency entity — this sealed
|
|
57
|
+
* package must operate on the entity the app's ORM actually discovered
|
|
58
|
+
* (its own definition, or this package's via the ./persistence subpath).
|
|
59
|
+
* Querying an undiscovered entity object crashes mikro-orm 7.1.x deep in
|
|
60
|
+
* EntityLoader (meta.relations undefined).
|
|
61
|
+
*/
|
|
62
|
+
webhookEventEntity: {
|
|
63
|
+
'~entity': WebhookEventEntity;
|
|
64
|
+
});
|
|
56
65
|
/**
|
|
57
66
|
* Resolve the party type for a subscription event.
|
|
58
67
|
* Stripe subscriptions are customer-scoped — customers map to users
|
|
@@ -69,5 +78,4 @@ export declare class StripeWebhookService<SchemaValidator extends AnySchemaValid
|
|
|
69
78
|
private extractFeaturesFromProduct;
|
|
70
79
|
handleWebhookEvent(event: Stripe.Event): Promise<void>;
|
|
71
80
|
}
|
|
72
|
-
export {};
|
|
73
81
|
//# 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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tB,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;;;;;;OAMG;IACH,kBAAkB,EAAE;QAAE,SAAS,EAAE,kBAAkB,CAAA;KAAE,EAatD;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,CAuV3D;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/implementation-billing-stripe",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Stripe implementation for forklaunch billing",
|
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@forklaunch/common": "^1.2.23",
|
|
67
|
-
"@forklaunch/core": "^1.5.
|
|
67
|
+
"@forklaunch/core": "^1.5.13",
|
|
68
68
|
"@forklaunch/internal": "^1.2.24",
|
|
69
69
|
"@forklaunch/validator": "^1.2.24",
|
|
70
|
-
"@mikro-orm/core": "7.1.11",
|
|
70
|
+
"@mikro-orm/core": "^7.1.11",
|
|
71
71
|
"@sinclair/typebox": "^0.34.52",
|
|
72
72
|
"ajv": "^8.20.0",
|
|
73
73
|
"stripe": "^22.4.0",
|
|
74
74
|
"zod": "^4.4.3",
|
|
75
|
-
"@forklaunch/implementation-billing-base": "^1.0.
|
|
75
|
+
"@forklaunch/implementation-billing-base": "^1.0.31",
|
|
76
76
|
"@forklaunch/interfaces-billing": "^1.0.30"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"depcheck": "^1.4.7",
|
|
81
81
|
"prettier": "^3.9.6",
|
|
82
82
|
"typedoc": "^0.28.20",
|
|
83
|
-
"@mikro-orm/sqlite": "7.1.11",
|
|
83
|
+
"@mikro-orm/sqlite": "^7.1.11",
|
|
84
84
|
"uuid": "^14.0.1"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|