@darraghor/nest-backend-libs 5.7.5 → 6.0.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.
- package/README.md +87 -36
- package/dist/exports/authorization.d.ts +14 -0
- package/dist/exports/authorization.js +12 -0
- package/dist/exports/authorization.js.map +1 -0
- package/dist/exports/core.d.ts +11 -0
- package/dist/exports/core.js +10 -0
- package/dist/exports/core.js.map +1 -0
- package/dist/exports/database.d.ts +5 -0
- package/dist/exports/database.js +6 -0
- package/dist/exports/database.js.map +1 -0
- package/dist/exports/email.d.ts +4 -0
- package/dist/exports/email.js +4 -0
- package/dist/exports/email.js.map +1 -0
- package/dist/exports/invitations.d.ts +6 -0
- package/dist/exports/invitations.js +6 -0
- package/dist/exports/invitations.js.map +1 -0
- package/dist/exports/organisations.d.ts +11 -0
- package/dist/exports/organisations.js +12 -0
- package/dist/exports/organisations.js.map +1 -0
- package/dist/exports/stripe-legacy.d.ts +6 -0
- package/dist/exports/stripe-legacy.js +7 -0
- package/dist/exports/stripe-legacy.js.map +1 -0
- package/dist/exports/stripe.d.ts +11 -0
- package/dist/exports/stripe.js +9 -0
- package/dist/exports/stripe.js.map +1 -0
- package/dist/exports/twitter.d.ts +5 -0
- package/dist/exports/twitter.js +5 -0
- package/dist/exports/twitter.js.map +1 -0
- package/dist/exports/users.d.ts +10 -0
- package/dist/exports/users.js +11 -0
- package/dist/exports/users.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/organisation-subscriptions/entities/organisation-subscription.entity.js +2 -1
- package/dist/organisation-subscriptions/entities/organisation-subscription.entity.js.map +1 -1
- package/dist/stripe-client/StripeClientConfigurationService.js +1 -0
- package/dist/stripe-client/StripeClientConfigurationService.js.map +1 -1
- package/dist/stripe-client/controllers/stripe-checkout-controller.d.ts +1 -0
- package/dist/stripe-client/controllers/stripe-checkout-controller.js +1 -0
- package/dist/stripe-client/controllers/stripe-checkout-controller.js.map +1 -1
- package/dist/stripe-client/controllers/stripe-events-controller.js +1 -0
- package/dist/stripe-client/controllers/stripe-events-controller.js.map +1 -1
- package/dist/stripe-client/controllers/stripe-unauthenticated-checkout-controller.js +1 -0
- package/dist/stripe-client/controllers/stripe-unauthenticated-checkout-controller.js.map +1 -1
- package/dist/stripe-client/services/auth-stripe-checkout.service.js +1 -0
- package/dist/stripe-client/services/auth-stripe-checkout.service.js.map +1 -1
- package/dist/stripe-client/services/queued-payment-event.handler.d.ts +1 -0
- package/dist/stripe-client/services/queued-payment-event.handler.js +2 -0
- package/dist/stripe-client/services/queued-payment-event.handler.js.map +1 -1
- package/dist/stripe-client/services/stripe-checkout.service.d.ts +1 -0
- package/dist/stripe-client/services/stripe-checkout.service.js +2 -0
- package/dist/stripe-client/services/stripe-checkout.service.js.map +1 -1
- package/dist/stripe-client/stripe-account.module.d.ts +1 -0
- package/dist/stripe-client/stripe-account.module.js +2 -0
- package/dist/stripe-client/stripe-account.module.js.map +1 -1
- package/dist/stripe-client/stripe-account.options.d.ts +2 -0
- package/dist/stripe-client/stripe-account.options.js.map +1 -1
- package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.d.ts +10 -0
- package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.js +65 -0
- package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.js.map +1 -0
- package/dist/stripe-payments/controllers/secure-stripe-events.controller.d.ts +9 -0
- package/dist/stripe-payments/controllers/secure-stripe-events.controller.js +65 -0
- package/dist/stripe-payments/controllers/secure-stripe-events.controller.js.map +1 -0
- package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.d.ts +14 -0
- package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.js +112 -0
- package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.js.map +1 -0
- package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.d.ts +15 -0
- package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.js +88 -0
- package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.js.map +1 -0
- package/dist/stripe-payments/entities/stripe-payment-event.entity.d.ts +16 -0
- package/dist/stripe-payments/entities/stripe-payment-event.entity.js +101 -0
- package/dist/stripe-payments/entities/stripe-payment-event.entity.js.map +1 -0
- package/dist/stripe-payments/entities/stripe-payment-state.entity.d.ts +9 -0
- package/dist/stripe-payments/entities/stripe-payment-state.entity.js +53 -0
- package/dist/stripe-payments/entities/stripe-payment-state.entity.js.map +1 -0
- package/dist/stripe-payments/models/secure-checkout.dto.d.ts +14 -0
- package/dist/stripe-payments/models/secure-checkout.dto.js +105 -0
- package/dist/stripe-payments/models/secure-checkout.dto.js.map +1 -0
- package/dist/stripe-payments/models/secure-payment-response.dto.d.ts +7 -0
- package/dist/stripe-payments/models/secure-payment-response.dto.js +30 -0
- package/dist/stripe-payments/models/secure-payment-response.dto.js.map +1 -0
- package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.d.ts +12 -0
- package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.js +49 -0
- package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.js.map +1 -0
- package/dist/stripe-payments/services/secure-stripe-checkout.service.d.ts +24 -0
- package/dist/stripe-payments/services/secure-stripe-checkout.service.js +213 -0
- package/dist/stripe-payments/services/secure-stripe-checkout.service.js.map +1 -0
- package/dist/stripe-payments/services/secure-stripe-client.provider.d.ts +2 -0
- package/dist/stripe-payments/services/secure-stripe-client.provider.js +15 -0
- package/dist/stripe-payments/services/secure-stripe-client.provider.js.map +1 -0
- package/dist/stripe-payments/services/secure-stripe-product.service.d.ts +9 -0
- package/dist/stripe-payments/services/secure-stripe-product.service.js +54 -0
- package/dist/stripe-payments/services/secure-stripe-product.service.js.map +1 -0
- package/dist/stripe-payments/services/secure-stripe-webhook.service.d.ts +14 -0
- package/dist/stripe-payments/services/secure-stripe-webhook.service.js +58 -0
- package/dist/stripe-payments/services/secure-stripe-webhook.service.js.map +1 -0
- package/dist/stripe-payments/services/secure-subscription.service.d.ts +18 -0
- package/dist/stripe-payments/services/secure-subscription.service.js +217 -0
- package/dist/stripe-payments/services/secure-subscription.service.js.map +1 -0
- package/dist/stripe-payments/services/stripe-payment-event.processor.d.ts +15 -0
- package/dist/stripe-payments/services/stripe-payment-event.processor.js +78 -0
- package/dist/stripe-payments/services/stripe-payment-event.processor.js.map +1 -0
- package/dist/stripe-payments/services/stripe-payment-event.service.d.ts +20 -0
- package/dist/stripe-payments/services/stripe-payment-event.service.js +178 -0
- package/dist/stripe-payments/services/stripe-payment-event.service.js.map +1 -0
- package/dist/stripe-payments/services/stripe-payment-fulfillment.service.d.ts +31 -0
- package/dist/stripe-payments/services/stripe-payment-fulfillment.service.js +331 -0
- package/dist/stripe-payments/services/stripe-payment-fulfillment.service.js.map +1 -0
- package/dist/stripe-payments/services/stripe-payments-operations.service.d.ts +25 -0
- package/dist/stripe-payments/services/stripe-payments-operations.service.js +59 -0
- package/dist/stripe-payments/services/stripe-payments-operations.service.js.map +1 -0
- package/dist/stripe-payments/services/stripe-payments-telemetry.service.d.ts +7 -0
- package/dist/stripe-payments/services/stripe-payments-telemetry.service.js +40 -0
- package/dist/stripe-payments/services/stripe-payments-telemetry.service.js.map +1 -0
- package/dist/stripe-payments/stripe-payment.config.d.ts +19 -0
- package/dist/stripe-payments/stripe-payment.config.js +98 -0
- package/dist/stripe-payments/stripe-payment.config.js.map +1 -0
- package/dist/stripe-payments/stripe-payment.config.test.d.ts +1 -0
- package/dist/stripe-payments/stripe-payment.config.test.js +59 -0
- package/dist/stripe-payments/stripe-payment.config.test.js.map +1 -0
- package/dist/stripe-payments/stripe-payments.extensions.d.ts +69 -0
- package/dist/stripe-payments/stripe-payments.extensions.js +30 -0
- package/dist/stripe-payments/stripe-payments.extensions.js.map +1 -0
- package/dist/stripe-payments/stripe-payments.module.d.ts +12 -0
- package/dist/stripe-payments/stripe-payments.module.js +118 -0
- package/dist/stripe-payments/stripe-payments.module.js.map +1 -0
- package/dist/stripe-payments/stripe-payments.options.d.ts +21 -0
- package/dist/stripe-payments/stripe-payments.options.js +2 -0
- package/dist/stripe-payments/stripe-payments.options.js.map +1 -0
- package/dist/typeorm/entities.d.ts +15 -0
- package/dist/typeorm/entities.js +32 -0
- package/dist/typeorm/entities.js.map +1 -0
- package/package.json +41 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-stripe-checkout.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/secure-stripe-checkout.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACH,iBAAiB,EACjB,MAAM,EACN,UAAU,EACV,MAAM,EACN,2BAA2B,GAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,gBAAgB,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC;AASrD,OAAO,EAAC,qBAAqB,EAAC,MAAM,+CAA+C,CAAC;AACpF,OAAO,EAAC,0BAA0B,EAAC,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACH,6BAA6B,EAC7B,iCAAiC,GAGpC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,8BAA8B,EAAC,MAAM,wCAAwC,CAAC;AAEtF,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAGjD,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAKf;IAEA;IACA;IAEA;IAEA;IACA;IAZJ,MAAM,GAAG,IAAI,MAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;IAEvE,YAEqB,MAAc,EAEd,iBAAoD,EACpD,cAA0C,EAE1C,gBAAgD,EAEhD,YAAwC,EACxC,SAAyC;QARzC,WAAM,GAAN,MAAM,CAAQ;QAEd,sBAAiB,GAAjB,iBAAiB,CAAmC;QACpD,mBAAc,GAAd,cAAc,CAA4B;QAE1C,qBAAgB,GAAhB,gBAAgB,CAA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AAC;QACD,OAAO,cAAc,CAAC;IAC1B,CAAC;IAEO,qBAAqB,CACzB,OAA8B,EAC9B,OAAwC,EACxC,IAAiB,EACjB,OAAe;QAEf,IACI,OAAO,CAAC,gBAAgB,KAAK,OAAO,CAAC,gBAAgB;YACrD,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,IAAI;YAC9B,OAAO,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU;YACzC,OAAO,CAAC,OAAO,KAAK,OAAO,EAC7B,CAAC;YACC,MAAM,IAAI,iBAAiB,CACvB,2DAA2D,CAC9D,CAAC;QACN,CAAC;IACL,CAAC;IAEO,iBAAiB,CAAC,KAAc;QACpC,OAAO,CACH,KAAK,YAAY,gBAAgB;YAChC,KAA2D;iBACvD,WAAW,CAAC,IAAI,KAAK,OAAO,CACpC,CAAC;IACN,CAAC;CACJ,CAAA;AApPY,2BAA2B;IADvC,UAAU,EAAE;IAKJ,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAE5B,WAAA,gBAAgB,CAAC,qBAAqB,CAAC,CAAA;IAGvC,WAAA,MAAM,CAAC,iCAAiC,CAAC,CAAA;IAEzC,WAAA,MAAM,CAAC,6BAA6B,CAAC,CAAA;qCANb,MAAM;QAEK,UAAU;QACb,0BAA0B,kBAK/B,8BAA8B;GAbrD,2BAA2B,CAoPvC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import { SECURE_STRIPE_CONFIGURATION, } from "../stripe-payment.config.js";
|
|
3
|
+
export const secureStripeClientProvider = {
|
|
4
|
+
provide: "SecureStripeClient",
|
|
5
|
+
useFactory: (configuration) => new Stripe(configuration.accessToken, {
|
|
6
|
+
apiVersion: Stripe.API_VERSION,
|
|
7
|
+
appInfo: {
|
|
8
|
+
name: "Miller Secure Payments",
|
|
9
|
+
url: "https://usemiller.dev",
|
|
10
|
+
},
|
|
11
|
+
maxNetworkRetries: 2,
|
|
12
|
+
}),
|
|
13
|
+
inject: [SECURE_STRIPE_CONFIGURATION],
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=secure-stripe-client.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-stripe-client.provider.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/secure-stripe-client.provider.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACH,2BAA2B,GAE9B,MAAM,6BAA6B,CAAC;AAErC,MAAM,CAAC,MAAM,0BAA0B,GAAa;IAChD,OAAO,EAAE,oBAAoB;IAC7B,UAAU,EAAE,CAAC,aAAwC,EAAU,EAAE,CAC7D,IAAI,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE;QAClC,UAAU,EAAE,MAAM,CAAC,WAAW;QAC9B,OAAO,EAAE;YACL,IAAI,EAAE,wBAAwB;YAC9B,GAAG,EAAE,uBAAuB;SAC/B;QACD,iBAAiB,EAAE,CAAC;KACvB,CAAC;IACN,MAAM,EAAE,CAAC,2BAA2B,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SecureStripeConfiguration, SecureStripeProduct } from "../stripe-payment.config.js";
|
|
2
|
+
export declare class SecureStripeProductService {
|
|
3
|
+
private readonly configuration;
|
|
4
|
+
constructor(configuration: SecureStripeConfiguration);
|
|
5
|
+
getByKey(productKey: string): SecureStripeProduct;
|
|
6
|
+
getByPriceId(priceId: string): SecureStripeProduct;
|
|
7
|
+
getConfiguredProducts(): readonly SecureStripeProduct[];
|
|
8
|
+
buildRedirectUrl(path: string): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { BadRequestException, Inject, Injectable } from "@nestjs/common";
|
|
14
|
+
import { SECURE_STRIPE_CONFIGURATION, } from "../stripe-payment.config.js";
|
|
15
|
+
let SecureStripeProductService = class SecureStripeProductService {
|
|
16
|
+
configuration;
|
|
17
|
+
constructor(configuration) {
|
|
18
|
+
this.configuration = configuration;
|
|
19
|
+
}
|
|
20
|
+
getByKey(productKey) {
|
|
21
|
+
const product = this.configuration.products.get(productKey);
|
|
22
|
+
if (!product) {
|
|
23
|
+
throw new BadRequestException("Unknown payment product");
|
|
24
|
+
}
|
|
25
|
+
return product;
|
|
26
|
+
}
|
|
27
|
+
getByPriceId(priceId) {
|
|
28
|
+
const product = [...this.configuration.products.values()].find((candidate) => candidate.priceId === priceId);
|
|
29
|
+
if (!product) {
|
|
30
|
+
throw new Error("Stripe returned a price outside the configured catalog");
|
|
31
|
+
}
|
|
32
|
+
return product;
|
|
33
|
+
}
|
|
34
|
+
getConfiguredProducts() {
|
|
35
|
+
return [...this.configuration.products.values()];
|
|
36
|
+
}
|
|
37
|
+
buildRedirectUrl(path) {
|
|
38
|
+
const url = new URL(path, `${this.configuration.redirectsBaseUrl}/`);
|
|
39
|
+
const baseUrl = new URL(`${this.configuration.redirectsBaseUrl}/`);
|
|
40
|
+
if (url.origin !== baseUrl.origin ||
|
|
41
|
+
!path.startsWith("/") ||
|
|
42
|
+
path.startsWith("//")) {
|
|
43
|
+
throw new BadRequestException("Redirect path must remain on the configured application origin");
|
|
44
|
+
}
|
|
45
|
+
return url.toString();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
SecureStripeProductService = __decorate([
|
|
49
|
+
Injectable(),
|
|
50
|
+
__param(0, Inject(SECURE_STRIPE_CONFIGURATION)),
|
|
51
|
+
__metadata("design:paramtypes", [Object])
|
|
52
|
+
], SecureStripeProductService);
|
|
53
|
+
export { SecureStripeProductService };
|
|
54
|
+
//# sourceMappingURL=secure-stripe-product.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-stripe-product.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/secure-stripe-product.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAC,mBAAmB,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AACvE,OAAO,EACH,2BAA2B,GAG9B,MAAM,6BAA6B,CAAC;AAG9B,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAGd;IAFrB,YAEqB,aAAwC;QAAxC,kBAAa,GAAb,aAAa,CAA2B;IAC1D,CAAC;IAEJ,QAAQ,CAAC,UAAkB;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,YAAY,CAAC,OAAe;QACxB,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAC1D,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,KAAK,OAAO,CAC/C,CAAC;QACF,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACX,wDAAwD,CAC3D,CAAC;QACN,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,qBAAqB;QACjB,OAAO,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,gBAAgB,CAAC,IAAY;QACzB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,GAAG,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,GAAG,CAAC,CAAC;QACnE,IACI,GAAG,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM;YAC7B,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YACrB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EACvB,CAAC;YACC,MAAM,IAAI,mBAAmB,CACzB,gEAAgE,CACnE,CAAC;QACN,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;CACJ,CAAA;AA5CY,0BAA0B;IADtC,UAAU,EAAE;IAGJ,WAAA,MAAM,CAAC,2BAA2B,CAAC,CAAA;;GAF/B,0BAA0B,CA4CtC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import { SecureStripeConfiguration } from "../stripe-payment.config.js";
|
|
3
|
+
import { StripePaymentEventService } from "./stripe-payment-event.service.js";
|
|
4
|
+
export interface RawStripeWebhookRequest {
|
|
5
|
+
headers: Record<string, string | string[] | undefined>;
|
|
6
|
+
rawBody?: Buffer;
|
|
7
|
+
}
|
|
8
|
+
export declare class SecureStripeWebhookService {
|
|
9
|
+
private readonly stripe;
|
|
10
|
+
private readonly configuration;
|
|
11
|
+
private readonly paymentEventService;
|
|
12
|
+
constructor(stripe: Stripe, configuration: SecureStripeConfiguration, paymentEventService: StripePaymentEventService);
|
|
13
|
+
handleWebhook(request: RawStripeWebhookRequest): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { BadRequestException, Inject, Injectable, ServiceUnavailableException, } from "@nestjs/common";
|
|
14
|
+
import Stripe from "stripe";
|
|
15
|
+
import { SECURE_STRIPE_CONFIGURATION, } from "../stripe-payment.config.js";
|
|
16
|
+
import { StripePaymentEventService } from "./stripe-payment-event.service.js";
|
|
17
|
+
let SecureStripeWebhookService = class SecureStripeWebhookService {
|
|
18
|
+
stripe;
|
|
19
|
+
configuration;
|
|
20
|
+
paymentEventService;
|
|
21
|
+
constructor(stripe, configuration, paymentEventService) {
|
|
22
|
+
this.stripe = stripe;
|
|
23
|
+
this.configuration = configuration;
|
|
24
|
+
this.paymentEventService = paymentEventService;
|
|
25
|
+
}
|
|
26
|
+
async handleWebhook(request) {
|
|
27
|
+
if (!request.rawBody) {
|
|
28
|
+
throw new BadRequestException("Webhook body was not received as raw bytes");
|
|
29
|
+
}
|
|
30
|
+
const signatureHeader = request.headers["stripe-signature"];
|
|
31
|
+
if (typeof signatureHeader !== "string") {
|
|
32
|
+
throw new BadRequestException("Missing Stripe webhook signature");
|
|
33
|
+
}
|
|
34
|
+
let event;
|
|
35
|
+
try {
|
|
36
|
+
event = this.stripe.webhooks.constructEvent(request.rawBody, signatureHeader, this.configuration.webhookVerificationKey);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new BadRequestException("Invalid Stripe webhook signature");
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await this.paymentEventService.receive(event);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// A non-2xx response tells Stripe to retry delivery. The event row is
|
|
46
|
+
// deliberately durable so a later delivery can enqueue it again.
|
|
47
|
+
throw new ServiceUnavailableException("Payment event could not be queued");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
SecureStripeWebhookService = __decorate([
|
|
52
|
+
Injectable(),
|
|
53
|
+
__param(0, Inject("SecureStripeClient")),
|
|
54
|
+
__param(1, Inject(SECURE_STRIPE_CONFIGURATION)),
|
|
55
|
+
__metadata("design:paramtypes", [Stripe, Object, StripePaymentEventService])
|
|
56
|
+
], SecureStripeWebhookService);
|
|
57
|
+
export { SecureStripeWebhookService };
|
|
58
|
+
//# sourceMappingURL=secure-stripe-webhook.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-stripe-webhook.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/secure-stripe-webhook.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACH,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,2BAA2B,GAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACH,2BAA2B,GAE9B,MAAM,6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AC,2BAA2B,CAAC,CAAA;qCADX,MAAM,UAGO,yBAAyB;GAN1D,0BAA0B,CAyCtC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OrganisationSubscriptionRecord } from "../../organisation-subscriptions/entities/organisation-subscription.entity.js";
|
|
2
|
+
import { Queue } from "bullmq";
|
|
3
|
+
import { Repository } from "typeorm";
|
|
4
|
+
import type { StripePaymentsEntitlementInput } from "../stripe-payments.extensions.js";
|
|
5
|
+
export type SecureSubscriptionInput = StripePaymentsEntitlementInput;
|
|
6
|
+
export declare class SecureSubscriptionService {
|
|
7
|
+
private readonly subscriptionRepository;
|
|
8
|
+
private readonly activationQueue;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
constructor(subscriptionRepository: Repository<OrganisationSubscriptionRecord>, activationQueue: Queue);
|
|
11
|
+
findByUuid(uuid: string): Promise<OrganisationSubscriptionRecord>;
|
|
12
|
+
findByTransactionId(paymentSystemTransactionId: string): Promise<OrganisationSubscriptionRecord | null>;
|
|
13
|
+
findByCustomerId(paymentSystemCustomerId: string, mode?: string): Promise<OrganisationSubscriptionRecord[]>;
|
|
14
|
+
save(input: SecureSubscriptionInput): Promise<OrganisationSubscriptionRecord>;
|
|
15
|
+
revokeCustomerPayments(customerId: string, input: Pick<SecureSubscriptionInput, "stripeEventId" | "stripeEventCreatedAt" | "stripeStatus">): Promise<void>;
|
|
16
|
+
revokePayment(paymentSystemTransactionId: string, input: Pick<SecureSubscriptionInput, "stripeEventId" | "stripeEventCreatedAt" | "stripeStatus">): Promise<boolean>;
|
|
17
|
+
private saveRecord;
|
|
18
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var SecureSubscriptionService_1;
|
|
14
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
15
|
+
import { InjectQueue } from "@nestjs/bullmq";
|
|
16
|
+
import { Organisation } from "../../organisation/entities/organisation.entity.js";
|
|
17
|
+
import { OrganisationSubscriptionRecord } from "../../organisation-subscriptions/entities/organisation-subscription.entity.js";
|
|
18
|
+
import { Queue } from "bullmq";
|
|
19
|
+
import { InjectRepository } from "@nestjs/typeorm";
|
|
20
|
+
import { QueryFailedError, Repository } from "typeorm";
|
|
21
|
+
import { StripePaymentState } from "../entities/stripe-payment-state.entity.js";
|
|
22
|
+
let SecureSubscriptionService = SecureSubscriptionService_1 = class SecureSubscriptionService {
|
|
23
|
+
subscriptionRepository;
|
|
24
|
+
activationQueue;
|
|
25
|
+
logger = new Logger(SecureSubscriptionService_1.name);
|
|
26
|
+
constructor(subscriptionRepository, activationQueue) {
|
|
27
|
+
this.subscriptionRepository = subscriptionRepository;
|
|
28
|
+
this.activationQueue = activationQueue;
|
|
29
|
+
}
|
|
30
|
+
async findByUuid(uuid) {
|
|
31
|
+
const record = await this.subscriptionRepository.findOne({
|
|
32
|
+
where: { uuid },
|
|
33
|
+
relations: { organisation: true },
|
|
34
|
+
});
|
|
35
|
+
if (!record) {
|
|
36
|
+
throw new Error("Subscription record not found");
|
|
37
|
+
}
|
|
38
|
+
return record;
|
|
39
|
+
}
|
|
40
|
+
async findByTransactionId(paymentSystemTransactionId) {
|
|
41
|
+
return this.subscriptionRepository.findOne({
|
|
42
|
+
where: { paymentSystemTransactionId },
|
|
43
|
+
relations: { organisation: true },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async findByCustomerId(paymentSystemCustomerId, mode) {
|
|
47
|
+
return this.subscriptionRepository.find({
|
|
48
|
+
where: {
|
|
49
|
+
paymentSystemCustomerId,
|
|
50
|
+
...(mode ? { paymentSystemMode: mode } : {}),
|
|
51
|
+
},
|
|
52
|
+
relations: { organisation: true },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async save(input) {
|
|
56
|
+
const { record, shouldActivate } = await this.saveRecord(input);
|
|
57
|
+
if (shouldActivate) {
|
|
58
|
+
await this.activationQueue.add("activation-changed", {
|
|
59
|
+
organisationUuid: record.organisation.uuid,
|
|
60
|
+
subscriptionUuid: record.uuid,
|
|
61
|
+
productKey: record.internalSku,
|
|
62
|
+
active: record.validUntil > new Date(),
|
|
63
|
+
}, {
|
|
64
|
+
jobId: `subscription-activation:${record.uuid}:${String(record.validUntil.getTime())}`,
|
|
65
|
+
attempts: 5,
|
|
66
|
+
backoff: { type: "exponential", delay: 2_000 },
|
|
67
|
+
removeOnComplete: { age: 86_400, count: 10_000 },
|
|
68
|
+
removeOnFail: { age: 604_800, count: 10_000 },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return record;
|
|
72
|
+
}
|
|
73
|
+
async revokeCustomerPayments(customerId, input) {
|
|
74
|
+
const records = await this.findByCustomerId(customerId, "payment");
|
|
75
|
+
for (const record of records) {
|
|
76
|
+
await this.save({
|
|
77
|
+
paymentSystemTransactionId: record.paymentSystemTransactionId,
|
|
78
|
+
paymentSystemProductId: record.paymentSystemProductId,
|
|
79
|
+
paymentSystemCustomerId: record.paymentSystemCustomerId,
|
|
80
|
+
paymentSystemCustomerEmail: record.paymentSystemCustomerEmail,
|
|
81
|
+
paymentSystemMode: "payment",
|
|
82
|
+
paymentSystemName: "stripe",
|
|
83
|
+
validUntil: new Date(),
|
|
84
|
+
internalSku: record.internalSku,
|
|
85
|
+
productDisplayName: record.productDisplayName,
|
|
86
|
+
organisationUuid: record.organisation.uuid,
|
|
87
|
+
stripeEventId: input.stripeEventId,
|
|
88
|
+
stripeEventCreatedAt: input.stripeEventCreatedAt,
|
|
89
|
+
stripeStatus: input.stripeStatus,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async revokePayment(paymentSystemTransactionId, input) {
|
|
94
|
+
const record = await this.findByTransactionId(paymentSystemTransactionId);
|
|
95
|
+
if (record?.paymentSystemMode !== "payment") {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
await this.save({
|
|
99
|
+
paymentSystemTransactionId: record.paymentSystemTransactionId,
|
|
100
|
+
paymentSystemProductId: record.paymentSystemProductId,
|
|
101
|
+
paymentSystemCustomerId: record.paymentSystemCustomerId,
|
|
102
|
+
paymentSystemCustomerEmail: record.paymentSystemCustomerEmail,
|
|
103
|
+
paymentSystemMode: "payment",
|
|
104
|
+
paymentSystemName: "stripe",
|
|
105
|
+
validUntil: new Date(),
|
|
106
|
+
internalSku: record.internalSku,
|
|
107
|
+
productDisplayName: record.productDisplayName,
|
|
108
|
+
organisationUuid: record.organisation.uuid,
|
|
109
|
+
stripeEventId: input.stripeEventId,
|
|
110
|
+
stripeEventCreatedAt: input.stripeEventCreatedAt,
|
|
111
|
+
stripeStatus: input.stripeStatus,
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
async saveRecord(input) {
|
|
116
|
+
try {
|
|
117
|
+
return await this.subscriptionRepository.manager.transaction(async (manager) => {
|
|
118
|
+
await manager.query("SELECT pg_advisory_xact_lock(hashtext($1))", [input.paymentSystemTransactionId]);
|
|
119
|
+
const subscriptionRepository = manager.getRepository(OrganisationSubscriptionRecord);
|
|
120
|
+
const stateRepository = manager.getRepository(StripePaymentState);
|
|
121
|
+
const state = await stateRepository.findOne({
|
|
122
|
+
where: {
|
|
123
|
+
paymentSystemTransactionId: input.paymentSystemTransactionId,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
let record = await subscriptionRepository.findOne({
|
|
127
|
+
where: {
|
|
128
|
+
paymentSystemTransactionId: input.paymentSystemTransactionId,
|
|
129
|
+
},
|
|
130
|
+
relations: { organisation: true },
|
|
131
|
+
});
|
|
132
|
+
const isDuplicateEvent = state?.lastStripeEventCreatedAt.getTime() ===
|
|
133
|
+
input.stripeEventCreatedAt.getTime() &&
|
|
134
|
+
state.lastStripeEventId === input.stripeEventId;
|
|
135
|
+
if (record &&
|
|
136
|
+
state &&
|
|
137
|
+
(state.lastStripeEventCreatedAt >
|
|
138
|
+
input.stripeEventCreatedAt ||
|
|
139
|
+
isDuplicateEvent)) {
|
|
140
|
+
return {
|
|
141
|
+
record,
|
|
142
|
+
// Retry the durable activation notification if the
|
|
143
|
+
// previous attempt failed after the DB commit.
|
|
144
|
+
shouldActivate: isDuplicateEvent,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const isNewRecord = !record;
|
|
148
|
+
if (!record) {
|
|
149
|
+
const organisation = input.organisationUuid
|
|
150
|
+
? await manager
|
|
151
|
+
.getRepository(Organisation)
|
|
152
|
+
.findOne({
|
|
153
|
+
where: { uuid: input.organisationUuid },
|
|
154
|
+
})
|
|
155
|
+
: null;
|
|
156
|
+
if (!organisation) {
|
|
157
|
+
throw new Error("Payment could not be matched to an organisation");
|
|
158
|
+
}
|
|
159
|
+
record = subscriptionRepository.create({
|
|
160
|
+
organisation,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
const previousValidUntil = isNewRecord
|
|
164
|
+
? undefined
|
|
165
|
+
: record.validUntil.getTime();
|
|
166
|
+
record.paymentSystemTransactionId =
|
|
167
|
+
input.paymentSystemTransactionId;
|
|
168
|
+
record.paymentSystemProductId =
|
|
169
|
+
input.paymentSystemProductId;
|
|
170
|
+
record.paymentSystemCustomerId =
|
|
171
|
+
input.paymentSystemCustomerId;
|
|
172
|
+
record.paymentSystemCustomerEmail =
|
|
173
|
+
input.paymentSystemCustomerEmail;
|
|
174
|
+
record.paymentSystemMode = input.paymentSystemMode;
|
|
175
|
+
record.paymentSystemName = input.paymentSystemName;
|
|
176
|
+
record.validUntil = input.validUntil;
|
|
177
|
+
record.internalSku = input.internalSku;
|
|
178
|
+
record.productDisplayName = input.productDisplayName;
|
|
179
|
+
const savedRecord = await subscriptionRepository.save(record);
|
|
180
|
+
const shouldActivate = isNewRecord ||
|
|
181
|
+
state?.lastStripeEventId !== input.stripeEventId ||
|
|
182
|
+
previousValidUntil !== input.validUntil.getTime();
|
|
183
|
+
const paymentState = state ??
|
|
184
|
+
stateRepository.create({
|
|
185
|
+
paymentSystemTransactionId: input.paymentSystemTransactionId,
|
|
186
|
+
});
|
|
187
|
+
paymentState.lastStripeEventId = input.stripeEventId;
|
|
188
|
+
paymentState.lastStripeEventCreatedAt =
|
|
189
|
+
input.stripeEventCreatedAt;
|
|
190
|
+
paymentState.status = input.stripeStatus;
|
|
191
|
+
await stateRepository.save(paymentState);
|
|
192
|
+
return { record: savedRecord, shouldActivate };
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error instanceof QueryFailedError &&
|
|
197
|
+
error
|
|
198
|
+
.driverError.code === "23505") {
|
|
199
|
+
const existing = await this.findByTransactionId(input.paymentSystemTransactionId);
|
|
200
|
+
if (existing) {
|
|
201
|
+
this.logger.warn(`Ignored concurrent duplicate payment ${input.paymentSystemTransactionId}`);
|
|
202
|
+
return { record: existing, shouldActivate: false };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
SecureSubscriptionService = SecureSubscriptionService_1 = __decorate([
|
|
210
|
+
Injectable(),
|
|
211
|
+
__param(0, InjectRepository(OrganisationSubscriptionRecord)),
|
|
212
|
+
__param(1, InjectQueue("subscription-activation-changed")),
|
|
213
|
+
__metadata("design:paramtypes", [Repository,
|
|
214
|
+
Queue])
|
|
215
|
+
], SecureSubscriptionService);
|
|
216
|
+
export { SecureSubscriptionService };
|
|
217
|
+
//# sourceMappingURL=secure-subscription.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-subscription.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/secure-subscription.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,oDAAoD,CAAC;AAChF,OAAO,EAAC,8BAA8B,EAAC,MAAM,+EAA+E,CAAC;AAC7H,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,gBAAgB,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAC,MAAM,4CAA4C,CAAC;AAMvE,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAKb;IAEA;IANJ,MAAM,GAAG,IAAI,MAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;IAErE,YAEqB,sBAAkE,EAElE,eAAsB;QAFtB,2BAAsB,GAAtB,sBAAsB,CAA4C;QAElE,oBAAe,GAAf,eAAe,CAAO;IACxC,CAAC;IAEJ,KAAK,CAAC,UAAU,CAAC,IAAY;QACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACrD,KAAK,EAAE,EAAC,IAAI,EAAC;YACb,SAAS,EAAE,EAAC,YAAY,EAAE,IAAI,EAAC;SACl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AW,CAAC,IAAI,KAAK,OAAO,EACnC,CAAC;gBACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAC3C,KAAK,CAAC,0BAA0B,CACnC,CAAC;gBACF,IAAI,QAAQ,EAAE,CAAC;oBACX,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,wCAAwC,KAAK,CAAC,0BAA0B,EAAE,CAC7E,CAAC;oBACF,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAC,CAAC;gBACrD,CAAC;YACL,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ,CAAA;AA7PY,yBAAyB;IADrC,UAAU,EAAE;IAKJ,WAAA,gBAAgB,CAAC,8BAA8B,CAAC,CAAA;IAEhD,WAAA,WAAW,CAAC,iCAAiC,CAAC,CAAA;qCADN,UAAU;QAEjB,KAAK;GAPlC,yBAAyB,CA6PrC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Job } from "bullmq";
|
|
2
|
+
import { WorkerHost } from "@nestjs/bullmq";
|
|
3
|
+
import Stripe from "stripe";
|
|
4
|
+
import { StripePaymentEventService } from "./stripe-payment-event.service.js";
|
|
5
|
+
import { StripePaymentFulfillmentService } from "./stripe-payment-fulfillment.service.js";
|
|
6
|
+
import { StripePaymentsTelemetryService } from "./stripe-payments-telemetry.service.js";
|
|
7
|
+
export declare class StripePaymentEventProcessor extends WorkerHost {
|
|
8
|
+
private readonly eventService;
|
|
9
|
+
private readonly fulfillmentService;
|
|
10
|
+
private readonly telemetry;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
constructor(eventService: StripePaymentEventService, fulfillmentService: StripePaymentFulfillmentService, telemetry: StripePaymentsTelemetryService);
|
|
13
|
+
process(job: Job<Stripe.Event>): Promise<void>;
|
|
14
|
+
onFailed(job: Job<Stripe.Event> | undefined, error: Error): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var StripePaymentEventProcessor_1;
|
|
11
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
12
|
+
import { OnWorkerEvent, Processor, WorkerHost } from "@nestjs/bullmq";
|
|
13
|
+
import { StripePaymentEventService } from "./stripe-payment-event.service.js";
|
|
14
|
+
import { StripePaymentFulfillmentService } from "./stripe-payment-fulfillment.service.js";
|
|
15
|
+
import { StripePaymentsTelemetryService } from "./stripe-payments-telemetry.service.js";
|
|
16
|
+
let StripePaymentEventProcessor = StripePaymentEventProcessor_1 = class StripePaymentEventProcessor extends WorkerHost {
|
|
17
|
+
eventService;
|
|
18
|
+
fulfillmentService;
|
|
19
|
+
telemetry;
|
|
20
|
+
logger = new Logger(StripePaymentEventProcessor_1.name);
|
|
21
|
+
constructor(eventService, fulfillmentService, telemetry) {
|
|
22
|
+
super();
|
|
23
|
+
this.eventService = eventService;
|
|
24
|
+
this.fulfillmentService = fulfillmentService;
|
|
25
|
+
this.telemetry = telemetry;
|
|
26
|
+
}
|
|
27
|
+
async process(job) {
|
|
28
|
+
const event = job.data;
|
|
29
|
+
const isClaimed = await this.eventService.claim(event.id);
|
|
30
|
+
if (!isClaimed) {
|
|
31
|
+
if (await this.eventService.isProcessed(event.id)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Stripe event ${event.id} is currently claimed by another worker`);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await this.fulfillmentService.process(event);
|
|
38
|
+
await this.eventService.markProcessed(event.id);
|
|
39
|
+
await this.telemetry.record({
|
|
40
|
+
name: "webhook.processed",
|
|
41
|
+
stripeEventId: event.id,
|
|
42
|
+
eventType: event.type,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
await this.eventService.markFailed(event.id, error);
|
|
47
|
+
await this.telemetry.record({
|
|
48
|
+
name: "webhook.failed",
|
|
49
|
+
stripeEventId: event.id,
|
|
50
|
+
eventType: event.type,
|
|
51
|
+
error: error instanceof Error ? error.message : String(error),
|
|
52
|
+
});
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
onFailed(job, error) {
|
|
57
|
+
this.logger.error("Stripe payment queue job failed", {
|
|
58
|
+
jobId: job?.id,
|
|
59
|
+
eventId: job?.data.id,
|
|
60
|
+
error: error.message,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
__decorate([
|
|
65
|
+
OnWorkerEvent("failed"),
|
|
66
|
+
__metadata("design:type", Function),
|
|
67
|
+
__metadata("design:paramtypes", [Object, Error]),
|
|
68
|
+
__metadata("design:returntype", void 0)
|
|
69
|
+
], StripePaymentEventProcessor.prototype, "onFailed", null);
|
|
70
|
+
StripePaymentEventProcessor = StripePaymentEventProcessor_1 = __decorate([
|
|
71
|
+
Injectable(),
|
|
72
|
+
Processor("stripe-events"),
|
|
73
|
+
__metadata("design:paramtypes", [StripePaymentEventService,
|
|
74
|
+
StripePaymentFulfillmentService,
|
|
75
|
+
StripePaymentsTelemetryService])
|
|
76
|
+
], StripePaymentEventProcessor);
|
|
77
|
+
export { StripePaymentEventProcessor };
|
|
78
|
+
//# sourceMappingURL=stripe-payment-event.processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-payment-event.processor.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/stripe-payment-event.processor.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAC,aAAa,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAC,yBAAyB,EAAC,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAC,+BAA+B,EAAC,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAC,8BAA8B,EAAC,MAAM,wCAAwC,CAAC;AAI/E,IAAM,2BAA2B,mCAAjC,MAAM,2BAA4B,SAAQ,UAAU;IAIlC;IACA;IACA;IALJ,MAAM,GAAG,IAAI,MAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;IAEvE,YACqB,YAAuC,EACvC,kBAAmD,EACnD,SAAyC;QAE1D,KAAK,EAAE,CAAC;QAJS,iBAAY,GAAZ,YAAY,CAA2B;QACvC,uBAAkB,GAAlB,kBAAkB,CAAiC;QACnD,cAAS,GAAT,SAAS,CAAgC;IAG9D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAsB;QAChC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC;QACvB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,IAAI,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBAChD,OAAO;YACX,CAAC;YACD,MAAM,IAAI,KAAK,CACX,gBAAgB,KAAK,CAAC,EAAE,yCAAyC,CACpE,CAAC;QACN,CAAC;QAED,IAAI,CAAC;YACD,MAAM,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1,20 @@
|
|
|
1
|
+
import { Queue } from "bullmq";
|
|
2
|
+
import { Repository } from "typeorm";
|
|
3
|
+
import Stripe from "stripe";
|
|
4
|
+
import { StripeCheckoutEvent } from "../entities/stripe-payment-event.entity.js";
|
|
5
|
+
import { StripePaymentsTelemetryService } from "./stripe-payments-telemetry.service.js";
|
|
6
|
+
export declare class StripePaymentEventService {
|
|
7
|
+
private readonly eventRepository;
|
|
8
|
+
private readonly eventQueue;
|
|
9
|
+
private readonly telemetry;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
constructor(eventRepository: Repository<StripeCheckoutEvent>, eventQueue: Queue, telemetry: StripePaymentsTelemetryService);
|
|
12
|
+
receive(event: Stripe.Event): Promise<void>;
|
|
13
|
+
claim(eventId: string): Promise<boolean>;
|
|
14
|
+
isProcessed(eventId: string): Promise<boolean>;
|
|
15
|
+
markProcessed(eventId: string): Promise<void>;
|
|
16
|
+
markFailed(eventId: string, error: unknown): Promise<void>;
|
|
17
|
+
list(take: number, skip: number): Promise<StripeCheckoutEvent[]>;
|
|
18
|
+
replay(eventId: string): Promise<void>;
|
|
19
|
+
private getBaseJobId;
|
|
20
|
+
}
|