@dereekb/nestjs 5.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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +28 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/decorators/index.d.ts +2 -0
- package/src/lib/decorators/index.js +6 -0
- package/src/lib/decorators/index.js.map +1 -0
- package/src/lib/decorators/local.decorator.d.ts +6 -0
- package/src/lib/decorators/local.decorator.js +18 -0
- package/src/lib/decorators/local.decorator.js.map +1 -0
- package/src/lib/decorators/rawbody.d.ts +9 -0
- package/src/lib/decorators/rawbody.js +45 -0
- package/src/lib/decorators/rawbody.js.map +1 -0
- package/src/lib/index.d.ts +3 -0
- package/src/lib/index.js +7 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/middlewares/index.d.ts +3 -0
- package/src/lib/middlewares/index.js +7 -0
- package/src/lib/middlewares/index.js.map +1 -0
- package/src/lib/middlewares/json.middleware.d.ts +5 -0
- package/src/lib/middlewares/json.middleware.js +16 -0
- package/src/lib/middlewares/json.middleware.js.map +1 -0
- package/src/lib/middlewares/rawbody.middleware.d.ts +5 -0
- package/src/lib/middlewares/rawbody.middleware.js +16 -0
- package/src/lib/middlewares/rawbody.middleware.js.map +1 -0
- package/src/lib/middlewares/webhook.d.ts +24 -0
- package/src/lib/middlewares/webhook.js +56 -0
- package/src/lib/middlewares/webhook.js.map +1 -0
- package/src/lib/module/client/client.config.d.ts +8 -0
- package/src/lib/module/client/client.config.js +12 -0
- package/src/lib/module/client/client.config.js.map +1 -0
- package/src/lib/module/client/client.d.ts +16 -0
- package/src/lib/module/client/client.js +8 -0
- package/src/lib/module/client/client.js.map +1 -0
- package/src/lib/module/client/client.module.d.ts +5 -0
- package/src/lib/module/client/client.module.js +39 -0
- package/src/lib/module/client/client.module.js.map +1 -0
- package/src/lib/module/client/client.service.d.ts +11 -0
- package/src/lib/module/client/client.service.js +26 -0
- package/src/lib/module/client/client.service.js.map +1 -0
- package/src/lib/module/client/index.d.ts +4 -0
- package/src/lib/module/client/index.js +8 -0
- package/src/lib/module/client/index.js.map +1 -0
- package/src/lib/module/index.d.ts +2 -0
- package/src/lib/module/index.js +6 -0
- package/src/lib/module/index.js.map +1 -0
- package/src/lib/module/module.d.ts +10 -0
- package/src/lib/module/module.js +21 -0
- package/src/lib/module/module.js.map +1 -0
- package/stripe/CHANGELOG.md +11 -0
- package/stripe/LICENSE +21 -0
- package/stripe/README.md +11 -0
- package/stripe/package.json +18 -0
- package/stripe/src/index.d.ts +1 -0
- package/stripe/src/index.js +5 -0
- package/stripe/src/index.js.map +1 -0
- package/stripe/src/lib/index.d.ts +4 -0
- package/stripe/src/lib/index.js +8 -0
- package/stripe/src/lib/index.js.map +1 -0
- package/stripe/src/lib/stripe.api.d.ts +13 -0
- package/stripe/src/lib/stripe.api.js +38 -0
- package/stripe/src/lib/stripe.api.js.map +1 -0
- package/stripe/src/lib/stripe.config.d.ts +13 -0
- package/stripe/src/lib/stripe.config.js +18 -0
- package/stripe/src/lib/stripe.config.js.map +1 -0
- package/stripe/src/lib/stripe.module.d.ts +7 -0
- package/stripe/src/lib/stripe.module.js +44 -0
- package/stripe/src/lib/stripe.module.js.map +1 -0
- package/stripe/src/lib/stripe.type.d.ts +13 -0
- package/stripe/src/lib/stripe.type.js +2 -0
- package/stripe/src/lib/stripe.type.js.map +1 -0
- package/stripe/src/lib/webhook/index.d.ts +4 -0
- package/stripe/src/lib/webhook/index.js +8 -0
- package/stripe/src/lib/webhook/index.js.map +1 -0
- package/stripe/src/lib/webhook/webhook.stripe.controller.d.ts +8 -0
- package/stripe/src/lib/webhook/webhook.stripe.controller.js +31 -0
- package/stripe/src/lib/webhook/webhook.stripe.controller.js.map +1 -0
- package/stripe/src/lib/webhook/webhook.stripe.d.ts +62 -0
- package/stripe/src/lib/webhook/webhook.stripe.js +51 -0
- package/stripe/src/lib/webhook/webhook.stripe.js.map +1 -0
- package/stripe/src/lib/webhook/webhook.stripe.module.d.ts +2 -0
- package/stripe/src/lib/webhook/webhook.stripe.module.js +20 -0
- package/stripe/src/lib/webhook/webhook.stripe.module.js.map +1 -0
- package/stripe/src/lib/webhook/webhook.stripe.service.d.ts +17 -0
- package/stripe/src/lib/webhook/webhook.stripe.service.js +39 -0
- package/stripe/src/lib/webhook/webhook.stripe.service.js.map +1 -0
package/stripe/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Hapier Creative LLC.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/stripe/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# nestjs-stripe
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build nestjs-stripe` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test nestjs-stripe` to execute the unit tests via [Jest](https://jestjs.io).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dereekb/nestjs/stripe",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"typings": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"stripe": "^9.1.0",
|
|
10
|
+
"@nestjs/common": "^8.4.0",
|
|
11
|
+
"@nestjs/config": "^2.0.1",
|
|
12
|
+
"@dereekb/nestjs": "5.0.0",
|
|
13
|
+
"@dereekb/util": "5.0.0",
|
|
14
|
+
"make-error": "^1.3.0",
|
|
15
|
+
"extra-set": "^2.2.11",
|
|
16
|
+
"tslib": "^2.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/nestjs/stripe/src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./webhook"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./stripe.module"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./stripe.api"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./stripe.module"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/nestjs/stripe/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,0DAAgC;AAChC,uDAA6B;AAC7B,0DAAgC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Stripe from 'stripe';
|
|
3
|
+
import { Request } from 'express';
|
|
4
|
+
import { StripeServiceConfig } from './stripe.config';
|
|
5
|
+
export declare class StripeApi {
|
|
6
|
+
readonly config: StripeServiceConfig;
|
|
7
|
+
readonly stripe: Stripe;
|
|
8
|
+
constructor(config: StripeServiceConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Verifies the event and reads the stripe signature from a request.
|
|
11
|
+
*/
|
|
12
|
+
readStripeEventFromWebhookRequest(req: Request, rawBody: Buffer): Stripe.Event;
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripeApi = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const stripe_1 = require("stripe");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const stripe_config_1 = require("./stripe.config");
|
|
8
|
+
let StripeApi = class StripeApi {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.stripe = new stripe_1.default(config.stripe.secret, config.stripe.config);
|
|
12
|
+
}
|
|
13
|
+
// MARK: Event
|
|
14
|
+
/**
|
|
15
|
+
* Verifies the event and reads the stripe signature from a request.
|
|
16
|
+
*/
|
|
17
|
+
readStripeEventFromWebhookRequest(req, rawBody) {
|
|
18
|
+
const signature = req.get('stripe-signature');
|
|
19
|
+
if (!signature) {
|
|
20
|
+
throw new common_1.BadRequestException(`missing stripe-signature`);
|
|
21
|
+
}
|
|
22
|
+
let event;
|
|
23
|
+
try {
|
|
24
|
+
event = this.stripe.webhooks.constructEvent(rawBody, signature, this.config.stripe.webhookSecret);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw new common_1.BadRequestException(`stripe signature read error: ${e === null || e === void 0 ? void 0 : e.message}`);
|
|
28
|
+
}
|
|
29
|
+
return event;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
StripeApi = tslib_1.__decorate([
|
|
33
|
+
(0, common_1.Injectable)(),
|
|
34
|
+
tslib_1.__param(0, (0, common_1.Inject)(stripe_config_1.StripeServiceConfig)),
|
|
35
|
+
tslib_1.__metadata("design:paramtypes", [stripe_config_1.StripeServiceConfig])
|
|
36
|
+
], StripeApi);
|
|
37
|
+
exports.StripeApi = StripeApi;
|
|
38
|
+
//# sourceMappingURL=stripe.api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.api.js","sourceRoot":"","sources":["../../../../../../packages/nestjs/stripe/src/lib/stripe.api.ts"],"names":[],"mappings":";;;;AAAA,mCAA4B;AAE5B,2CAAyE;AACzE,mDAAsD;AAGtD,IAAa,SAAS,GAAtB,MAAa,SAAS;IAIpB,YAAyD,MAA2B;QAA3B,WAAM,GAAN,MAAM,CAAqB;QAClF,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvE,CAAC;IAED,cAAc;IACd;;OAEG;IACH,iCAAiC,CAAC,GAAY,EAAE,OAAe;QAC7D,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAE9C,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,4BAAmB,CAAC,0BAA0B,CAAC,CAAC;SAC3D;QAED,IAAI,KAAmB,CAAC;QAExB,IAAI;YACF,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;SACnG;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,4BAAmB,CAAC,gCAAiC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,OAAO,EAAE,CAAC,CAAC;SACtF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CAEF,CAAA;AA9BY,SAAS;IADrB,IAAA,mBAAU,GAAE;IAKE,mBAAA,IAAA,eAAM,EAAC,mCAAmB,CAAC,CAAA;6CAAyB,mCAAmB;GAJzE,SAAS,CA8BrB;AA9BY,8BAAS"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
export interface StripeServiceApiConfig {
|
|
3
|
+
secret: string;
|
|
4
|
+
webhookSecret: string;
|
|
5
|
+
config: Stripe.StripeConfig;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for StripeService
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class StripeServiceConfig {
|
|
11
|
+
stripe: StripeServiceApiConfig;
|
|
12
|
+
static assertValidConfig(config: StripeServiceConfig): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripeServiceConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for StripeService
|
|
6
|
+
*/
|
|
7
|
+
class StripeServiceConfig {
|
|
8
|
+
static assertValidConfig(config) {
|
|
9
|
+
if (!config.stripe.secret) {
|
|
10
|
+
throw new Error('No stripe secret specified.');
|
|
11
|
+
}
|
|
12
|
+
else if (!config.stripe.webhookSecret) {
|
|
13
|
+
throw new Error('No stripe webhook secret specified.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.StripeServiceConfig = StripeServiceConfig;
|
|
18
|
+
//# sourceMappingURL=stripe.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.config.js","sourceRoot":"","sources":["../../../../../../packages/nestjs/stripe/src/lib/stripe.config.ts"],"names":[],"mappings":";;;AAQA;;GAEG;AACH,MAAsB,mBAAmB;IAIvC,MAAM,CAAC,iBAAiB,CAAC,MAA2B;QAClD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;aAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;IACH,CAAC;CAEF;AAZD,kDAYC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import * as stripe from 'stripe';
|
|
3
|
+
import { StripeServiceConfig } from './stripe.config';
|
|
4
|
+
export declare const STRIPE_DEFAULT_API_VERSION: stripe.Stripe.LatestApiVersion;
|
|
5
|
+
export declare function stripeServiceConfigFactory(configService: ConfigService): StripeServiceConfig;
|
|
6
|
+
export declare class StripeModule {
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripeModule = exports.stripeServiceConfigFactory = exports.STRIPE_DEFAULT_API_VERSION = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const config_1 = require("@nestjs/config");
|
|
7
|
+
const stripe_api_1 = require("./stripe.api");
|
|
8
|
+
const stripe_config_1 = require("./stripe.config");
|
|
9
|
+
exports.STRIPE_DEFAULT_API_VERSION = '2020-08-27';
|
|
10
|
+
function stripeServiceConfigFactory(configService) {
|
|
11
|
+
const config = {
|
|
12
|
+
stripe: {
|
|
13
|
+
secret: configService.get('STRIPE_SECRET'),
|
|
14
|
+
webhookSecret: configService.get('STRIPE_WEBHOOK_SECRET'),
|
|
15
|
+
config: {
|
|
16
|
+
apiVersion: exports.STRIPE_DEFAULT_API_VERSION
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
stripe_config_1.StripeServiceConfig.assertValidConfig(config);
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
exports.stripeServiceConfigFactory = stripeServiceConfigFactory;
|
|
24
|
+
;
|
|
25
|
+
let StripeModule = class StripeModule {
|
|
26
|
+
};
|
|
27
|
+
StripeModule = tslib_1.__decorate([
|
|
28
|
+
(0, common_1.Module)({
|
|
29
|
+
imports: [
|
|
30
|
+
config_1.ConfigModule
|
|
31
|
+
],
|
|
32
|
+
providers: [
|
|
33
|
+
{
|
|
34
|
+
provide: stripe_config_1.StripeServiceConfig,
|
|
35
|
+
inject: [config_1.ConfigService],
|
|
36
|
+
useFactory: stripeServiceConfigFactory
|
|
37
|
+
},
|
|
38
|
+
stripe_api_1.StripeApi
|
|
39
|
+
],
|
|
40
|
+
exports: [stripe_api_1.StripeApi],
|
|
41
|
+
})
|
|
42
|
+
], StripeModule);
|
|
43
|
+
exports.StripeModule = StripeModule;
|
|
44
|
+
//# sourceMappingURL=stripe.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.module.js","sourceRoot":"","sources":["../../../../../../packages/nestjs/stripe/src/lib/stripe.module.ts"],"names":[],"mappings":";;;;AAAA,2CAAwC;AACxC,2CAA6D;AAE7D,6CAAyC;AACzC,mDAAsD;AAEzC,QAAA,0BAA0B,GAAmC,YAAY,CAAC;AAEvF,SAAgB,0BAA0B,CAAC,aAA4B;IACrE,MAAM,MAAM,GAAwB;QAClC,MAAM,EAAE;YACN,MAAM,EAAE,aAAa,CAAC,GAAG,CAAS,eAAe,CAAE;YACnD,aAAa,EAAE,aAAa,CAAC,GAAG,CAAS,uBAAuB,CAAE;YAClE,MAAM,EAAE;gBACN,UAAU,EAAE,kCAA0B;aACvC;SACF;KACF,CAAC;IAEF,mCAAmB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,gEAaC;AAAA,CAAC;AAgBF,IAAa,YAAY,GAAzB,MAAa,YAAY;CAAI,CAAA;AAAhB,YAAY;IAdxB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,qBAAY;SACb;QACD,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,mCAAmB;gBAC5B,MAAM,EAAE,CAAC,sBAAa,CAAC;gBACvB,UAAU,EAAE,0BAA0B;aACvC;YACD,sBAAS;SACV;QACD,OAAO,EAAE,CAAC,sBAAS,CAAC;KACrB,CAAC;GACW,YAAY,CAAI;AAAhB,oCAAY"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module 'stripe' {
|
|
2
|
+
namespace Stripe {
|
|
3
|
+
type TypedEventDataObject<T> = T;
|
|
4
|
+
interface TypedEventData<T> extends Stripe.Event.Data {
|
|
5
|
+
object: T;
|
|
6
|
+
previous_attributes?: Partial<T>;
|
|
7
|
+
}
|
|
8
|
+
interface TypedEvent<T = any> extends Stripe.Event {
|
|
9
|
+
data: TypedEventData<T>;
|
|
10
|
+
type: Exclude<Stripe.WebhookEndpointCreateParams.EnabledEvent, '*'>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.type.js","sourceRoot":"","sources":["../../../../../../packages/nestjs/stripe/src/lib/stripe.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./webhook.stripe"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./webhook.stripe.controller"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./webhook.stripe.service"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./webhook.stripe.module"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/nestjs/stripe/src/lib/webhook/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,sEAA4C;AAC5C,mEAAyC;AACzC,kEAAwC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RawBodyBuffer } from '@dereekb/nestjs';
|
|
2
|
+
import { Request } from 'express';
|
|
3
|
+
import { StripeWebhookService } from './webhook.stripe.service';
|
|
4
|
+
export declare class StripeWebhookController {
|
|
5
|
+
private readonly stripeWebhookService;
|
|
6
|
+
constructor(stripeWebhookService: StripeWebhookService);
|
|
7
|
+
handleStripeWebhook(req: Request, rawBody: RawBodyBuffer): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripeWebhookController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const nestjs_1 = require("@dereekb/nestjs");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const webhook_stripe_service_1 = require("./webhook.stripe.service");
|
|
8
|
+
let StripeWebhookController = class StripeWebhookController {
|
|
9
|
+
constructor(stripeWebhookService) {
|
|
10
|
+
this.stripeWebhookService = stripeWebhookService;
|
|
11
|
+
}
|
|
12
|
+
handleStripeWebhook(req, rawBody) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
yield this.stripeWebhookService.updateForWebhook(req, rawBody);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
tslib_1.__decorate([
|
|
19
|
+
(0, common_1.Post)(),
|
|
20
|
+
tslib_1.__param(0, (0, common_1.Req)()),
|
|
21
|
+
tslib_1.__param(1, (0, nestjs_1.RawBody)()),
|
|
22
|
+
tslib_1.__metadata("design:type", Function),
|
|
23
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object]),
|
|
24
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
25
|
+
], StripeWebhookController.prototype, "handleStripeWebhook", null);
|
|
26
|
+
StripeWebhookController = tslib_1.__decorate([
|
|
27
|
+
(0, common_1.Controller)('/webhook/stripe'),
|
|
28
|
+
tslib_1.__metadata("design:paramtypes", [webhook_stripe_service_1.StripeWebhookService])
|
|
29
|
+
], StripeWebhookController);
|
|
30
|
+
exports.StripeWebhookController = StripeWebhookController;
|
|
31
|
+
//# sourceMappingURL=webhook.stripe.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.stripe.controller.js","sourceRoot":"","sources":["../../../../../../../packages/nestjs/stripe/src/lib/webhook/webhook.stripe.controller.ts"],"names":[],"mappings":";;;;AAAA,4CAAyD;AACzD,2CAAuD;AAEvD,qEAAgE;AAGhE,IAAa,uBAAuB,GAApC,MAAa,uBAAuB;IAElC,YAA6B,oBAA0C;QAA1C,yBAAoB,GAApB,oBAAoB,CAAsB;IAAI,CAAC;IAGtE,mBAAmB,CAAQ,GAAY,EAAa,OAAsB;;YAC9E,MAAM,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACjE,CAAC;KAAA;CAEF,CAAA;AAJC;IADC,IAAA,aAAI,GAAE;IACoB,mBAAA,IAAA,YAAG,GAAE,CAAA;IAAgB,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;kEAExD;AAPU,uBAAuB;IADnC,IAAA,mBAAU,EAAC,iBAAiB,CAAC;6CAGuB,6CAAoB;GAF5D,uBAAuB,CASnC;AATY,0DAAuB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HandlerBindAccessor, HandlerMappedSetFunction, Handler } from "@dereekb/util";
|
|
2
|
+
import Stripe from "stripe";
|
|
3
|
+
import '../stripe.type';
|
|
4
|
+
export declare enum StripeWebhookEventType {
|
|
5
|
+
CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END = "customer.subscription.trial_will_end",
|
|
6
|
+
CUSTOMER_SUBSCRIPTION_DELETED = "customer.subscription.deleted",
|
|
7
|
+
CUSTOMER_SUBSCRIPTION_CREATED = "customer.subscription.created",
|
|
8
|
+
CUSTOMER_SUBSCRIPTION_UPDATED = "customer.subscription.updated",
|
|
9
|
+
CHECKOUT_SESSION_COMPLETED = "checkout.session.completed",
|
|
10
|
+
CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED = "checkout.session.async_payment_failed",
|
|
11
|
+
CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED = "checkout.session.async_payment_suceeded",
|
|
12
|
+
SUBSCRIPTION_SCHEDULE_ABORTED = "subscription_schedule.aborted",
|
|
13
|
+
SUBSCRIPTION_SCHEDULE_CANCELLED = "subscription_schedule.canceled",
|
|
14
|
+
SUBSCRIPTION_SCHEDULE_COMPLETED = "subscription_schedule.completed",
|
|
15
|
+
SUBSCRIPTION_SCHEDULE_CREATED = "subscription_schedule.created",
|
|
16
|
+
SUBSCRIPTION_SCHEDULE_EXPIRING = "subscription_schedule.expiring",
|
|
17
|
+
SUBSCRIPTION_SCHEDULE_RELEASED = "subscription_schedule.released",
|
|
18
|
+
SUBSCRIPTION_SCHEDULE_UPDATED = "subscription_schedule.updated"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A parsed Stripe.Event that contains the relevant data and the original event.
|
|
22
|
+
*/
|
|
23
|
+
export interface StripeWebhookEvent<T = any> {
|
|
24
|
+
/**
|
|
25
|
+
* The event
|
|
26
|
+
*/
|
|
27
|
+
readonly event: Stripe.Event;
|
|
28
|
+
/**
|
|
29
|
+
* The relevant data associated with this type of event.
|
|
30
|
+
*/
|
|
31
|
+
readonly data: Stripe.TypedEventDataObject<T>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a StripeWebhookEvent and treats the data as the input type.
|
|
35
|
+
*
|
|
36
|
+
* @param event
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export declare function stripeWebhookEvent<T>(event: Stripe.Event): StripeWebhookEvent<T>;
|
|
40
|
+
export declare function stripeWebhookEventMapper<T>(mapFn: (object: Stripe.Event.Data.Object, event: Stripe.Event) => T): (event: Stripe.Event) => StripeWebhookEvent<T>;
|
|
41
|
+
export declare type StripeCheckoutSessionEventDataObject = Stripe.TypedEventDataObject<Stripe.Checkout.Session>;
|
|
42
|
+
export declare type StripeCustomerSubscriptionEventDataObject = Stripe.TypedEventDataObject<Stripe.Subscription>;
|
|
43
|
+
export declare type StripeSubscriptionScheduleEventDataObject = Stripe.TypedEventDataObject<Stripe.SubscriptionSchedule>;
|
|
44
|
+
export declare type StripeEventHandler = Handler<Stripe.Event, string>;
|
|
45
|
+
export declare const stripeEventHandlerFactory: import("@dereekb/util").HandlerFactory<Stripe.Event, string>;
|
|
46
|
+
export declare type StripeHandlerMappedSetFunction<T> = HandlerMappedSetFunction<StripeWebhookEvent<T>>;
|
|
47
|
+
export interface StripeEventHandlerConfigurer extends HandlerBindAccessor<Stripe.Event, string> {
|
|
48
|
+
readonly handleCheckoutSessionComplete: StripeHandlerMappedSetFunction<StripeCheckoutSessionEventDataObject>;
|
|
49
|
+
readonly handleCheckoutSessionAsyncPaymentFailed: StripeHandlerMappedSetFunction<StripeCheckoutSessionEventDataObject>;
|
|
50
|
+
readonly handleCheckoutSessionAsyncPaymentSuccess: StripeHandlerMappedSetFunction<StripeCheckoutSessionEventDataObject>;
|
|
51
|
+
readonly handleCustomerSubscriptionCreated: StripeHandlerMappedSetFunction<StripeCustomerSubscriptionEventDataObject>;
|
|
52
|
+
readonly handleCustomerSubscriptionUpdated: StripeHandlerMappedSetFunction<StripeCustomerSubscriptionEventDataObject>;
|
|
53
|
+
readonly handleCustomerSubscriptionDeleted: StripeHandlerMappedSetFunction<StripeCustomerSubscriptionEventDataObject>;
|
|
54
|
+
readonly handleSubscriptionScheduleAborted: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
55
|
+
readonly handleSubscriptionScheduleCancelled: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
56
|
+
readonly handleSubscriptionScheduleCompleted: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
57
|
+
readonly handleSubscriptionScheduleCreated: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
58
|
+
readonly handleSubscriptionScheduleExpiring: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
59
|
+
readonly handleSubscriptionScheduleReleased: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
60
|
+
readonly handleSubscriptionScheduleUpdated: StripeHandlerMappedSetFunction<StripeSubscriptionScheduleEventDataObject>;
|
|
61
|
+
}
|
|
62
|
+
export declare const stripeEventHandlerConfigurerFactory: import("@dereekb/util").HandlerConfigurerFactory<StripeEventHandlerConfigurer, Stripe.Event, string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripeEventHandlerConfigurerFactory = exports.stripeEventHandlerFactory = exports.stripeWebhookEventMapper = exports.stripeWebhookEvent = exports.StripeWebhookEventType = void 0;
|
|
4
|
+
const util_1 = require("@dereekb/util");
|
|
5
|
+
require("../stripe.type");
|
|
6
|
+
var StripeWebhookEventType;
|
|
7
|
+
(function (StripeWebhookEventType) {
|
|
8
|
+
StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END"] = "customer.subscription.trial_will_end";
|
|
9
|
+
StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_DELETED"] = "customer.subscription.deleted";
|
|
10
|
+
StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_CREATED"] = "customer.subscription.created";
|
|
11
|
+
StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_UPDATED"] = "customer.subscription.updated";
|
|
12
|
+
StripeWebhookEventType["CHECKOUT_SESSION_COMPLETED"] = "checkout.session.completed";
|
|
13
|
+
StripeWebhookEventType["CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED"] = "checkout.session.async_payment_failed";
|
|
14
|
+
StripeWebhookEventType["CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED"] = "checkout.session.async_payment_suceeded";
|
|
15
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_ABORTED"] = "subscription_schedule.aborted";
|
|
16
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_CANCELLED"] = "subscription_schedule.canceled";
|
|
17
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_COMPLETED"] = "subscription_schedule.completed";
|
|
18
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_CREATED"] = "subscription_schedule.created";
|
|
19
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_EXPIRING"] = "subscription_schedule.expiring";
|
|
20
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_RELEASED"] = "subscription_schedule.released";
|
|
21
|
+
StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_UPDATED"] = "subscription_schedule.updated";
|
|
22
|
+
})(StripeWebhookEventType = exports.StripeWebhookEventType || (exports.StripeWebhookEventType = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Creates a StripeWebhookEvent and treats the data as the input type.
|
|
25
|
+
*
|
|
26
|
+
* @param event
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
function stripeWebhookEvent(event) {
|
|
30
|
+
return {
|
|
31
|
+
event,
|
|
32
|
+
data: event.data.object
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.stripeWebhookEvent = stripeWebhookEvent;
|
|
36
|
+
function stripeWebhookEventMapper(mapFn) {
|
|
37
|
+
return (event) => ({
|
|
38
|
+
event,
|
|
39
|
+
data: mapFn(event.data.object, event)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.stripeWebhookEventMapper = stripeWebhookEventMapper;
|
|
43
|
+
exports.stripeEventHandlerFactory = (0, util_1.handlerFactory)((x) => x.type);
|
|
44
|
+
exports.stripeEventHandlerConfigurerFactory = (0, util_1.handlerConfigurerFactory)({
|
|
45
|
+
configurerForAccessor: (accessor) => {
|
|
46
|
+
const fnWithKey = (0, util_1.handlerMappedSetFunctionFactory)(accessor, stripeWebhookEvent);
|
|
47
|
+
const configurer = Object.assign(Object.assign({}, accessor), { handleCheckoutSessionComplete: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_COMPLETED), handleCheckoutSessionAsyncPaymentFailed: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED), handleCheckoutSessionAsyncPaymentSuccess: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED), handleCustomerSubscriptionCreated: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_CREATED), handleCustomerSubscriptionUpdated: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_UPDATED), handleCustomerSubscriptionDeleted: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_DELETED), handleSubscriptionScheduleAborted: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_ABORTED), handleSubscriptionScheduleCancelled: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_CANCELLED), handleSubscriptionScheduleCompleted: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_COMPLETED), handleSubscriptionScheduleCreated: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_CREATED), handleSubscriptionScheduleExpiring: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_EXPIRING), handleSubscriptionScheduleReleased: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_RELEASED), handleSubscriptionScheduleUpdated: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_UPDATED) });
|
|
48
|
+
return configurer;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=webhook.stripe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.stripe.js","sourceRoot":"","sources":["../../../../../../../packages/nestjs/stripe/src/lib/webhook/webhook.stripe.ts"],"names":[],"mappings":";;;AAAA,wCAAkK;AAElK,0BAAwB;AAExB,IAAY,sBAeX;AAfD,WAAY,sBAAsB;IAChC,uGAA6E,CAAA;IAC7E,yFAA+D,CAAA;IAC/D,yFAA+D,CAAA;IAC/D,yFAA+D,CAAA;IAC/D,mFAAyD,CAAA;IACzD,yGAA+E,CAAA;IAC/E,8GAAoF,CAAA;IACpF,yFAA+D,CAAA;IAC/D,4FAAkE,CAAA;IAClE,6FAAmE,CAAA;IACnE,yFAA+D,CAAA;IAC/D,2FAAiE,CAAA;IACjE,2FAAiE,CAAA;IACjE,yFAA+D,CAAA;AACjE,CAAC,EAfW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAejC;AAgBD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAI,KAAmB;IACvD,OAAO;QACL,KAAK;QACL,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAsB;KACxC,CAAC;AACJ,CAAC;AALD,gDAKC;AAED,SAAgB,wBAAwB,CAAI,KAAmE;IAC7G,OAAO,CAAC,KAAmB,EAAE,EAAE,CAAC,CAAC;QAC/B,KAAK;QACL,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;KACtC,CAAC,CAAC;AACL,CAAC;AALD,4DAKC;AAQY,QAAA,yBAAyB,GAAG,IAAA,qBAAc,EAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAoBxE,QAAA,mCAAmC,GAAG,IAAA,+BAAwB,EAA6C;IACtH,qBAAqB,EAAE,CAAC,QAA2C,EAAE,EAAE;QACrE,MAAM,SAAS,GAAG,IAAA,sCAA+B,EAA+B,QAAQ,EAAE,kBAAkB,CAAC,CAAC;QAE9G,MAAM,UAAU,mCACX,QAAQ,KACX,6BAA6B,EAAE,SAAS,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,EAC3F,uCAAuC,EAAE,SAAS,CAAC,sBAAsB,CAAC,qCAAqC,CAAC,EAChH,wCAAwC,EAAE,SAAS,CAAC,sBAAsB,CAAC,wCAAwC,CAAC,EACpH,iCAAiC,EAAE,SAAS,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,EAClG,iCAAiC,EAAE,SAAS,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,EAClG,iCAAiC,EAAE,SAAS,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,EAClG,iCAAiC,EAAE,SAAS,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,EAClG,mCAAmC,EAAE,SAAS,CAAC,sBAAsB,CAAC,+BAA+B,CAAC,EACtG,mCAAmC,EAAE,SAAS,CAAC,sBAAsB,CAAC,+BAA+B,CAAC,EACtG,iCAAiC,EAAE,SAAS,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,EAClG,kCAAkC,EAAE,SAAS,CAAC,sBAAsB,CAAC,8BAA8B,CAAC,EACpG,kCAAkC,EAAE,SAAS,CAAC,sBAAsB,CAAC,8BAA8B,CAAC,EACpG,iCAAiC,EAAE,SAAS,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,GACnG,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripeWebhookModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const webhook_stripe_controller_1 = require("./webhook.stripe.controller");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const stripe_module_1 = require("../stripe.module");
|
|
8
|
+
const webhook_stripe_service_1 = require("./webhook.stripe.service");
|
|
9
|
+
let StripeWebhookModule = class StripeWebhookModule {
|
|
10
|
+
};
|
|
11
|
+
StripeWebhookModule = tslib_1.__decorate([
|
|
12
|
+
(0, common_1.Module)({
|
|
13
|
+
controllers: [webhook_stripe_controller_1.StripeWebhookController],
|
|
14
|
+
imports: [stripe_module_1.StripeModule],
|
|
15
|
+
exports: [stripe_module_1.StripeModule, webhook_stripe_service_1.StripeWebhookService],
|
|
16
|
+
providers: [webhook_stripe_service_1.StripeWebhookService]
|
|
17
|
+
})
|
|
18
|
+
], StripeWebhookModule);
|
|
19
|
+
exports.StripeWebhookModule = StripeWebhookModule;
|
|
20
|
+
//# sourceMappingURL=webhook.stripe.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.stripe.module.js","sourceRoot":"","sources":["../../../../../../../packages/nestjs/stripe/src/lib/webhook/webhook.stripe.module.ts"],"names":[],"mappings":";;;;AAAA,2EAAsE;AACtE,2CAAwC;AACxC,oDAAgD;AAChD,qEAAgE;AAShE,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;CAAI,CAAA;AAAvB,mBAAmB;IAN/B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,mDAAuB,CAAC;QACtC,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,OAAO,EAAE,CAAC,4BAAY,EAAE,6CAAoB,CAAC;QAC7C,SAAS,EAAE,CAAC,6CAAoB,CAAC;KAClC,CAAC;GACW,mBAAmB,CAAI;AAAvB,kDAAmB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Stripe from 'stripe';
|
|
3
|
+
import { Request } from 'express';
|
|
4
|
+
import { StripeApi } from '../stripe.api';
|
|
5
|
+
import { Handler } from '@dereekb/util';
|
|
6
|
+
/**
|
|
7
|
+
* Service that makes system changes based on Stripe webhook events.
|
|
8
|
+
*/
|
|
9
|
+
export declare class StripeWebhookService {
|
|
10
|
+
private readonly stripeApi;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
readonly handler: Handler<Stripe.Event>;
|
|
13
|
+
readonly configure: import("@dereekb/util").HandlerConfigurer<import("./webhook.stripe").StripeEventHandlerConfigurer, Stripe.Event, string>;
|
|
14
|
+
constructor(stripeApi: StripeApi);
|
|
15
|
+
updateForWebhook(req: Request, rawBody: Buffer): Promise<any>;
|
|
16
|
+
updateForStripeEvent(event: Stripe.Event): Promise<boolean>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripeWebhookService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const webhook_stripe_1 = require("./webhook.stripe");
|
|
7
|
+
const stripe_api_1 = require("../stripe.api");
|
|
8
|
+
/**
|
|
9
|
+
* Service that makes system changes based on Stripe webhook events.
|
|
10
|
+
*/
|
|
11
|
+
let StripeWebhookService = class StripeWebhookService {
|
|
12
|
+
constructor(stripeApi) {
|
|
13
|
+
this.stripeApi = stripeApi;
|
|
14
|
+
this.logger = new common_1.Logger('StripeWebhookService');
|
|
15
|
+
this.handler = (0, webhook_stripe_1.stripeEventHandlerFactory)();
|
|
16
|
+
this.configure = (0, webhook_stripe_1.stripeEventHandlerConfigurerFactory)(this.handler);
|
|
17
|
+
}
|
|
18
|
+
updateForWebhook(req, rawBody) {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const event = this.stripeApi.readStripeEventFromWebhookRequest(req, rawBody);
|
|
21
|
+
return this.updateForStripeEvent(event);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
updateForStripeEvent(event) {
|
|
25
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const handled = yield this.handler(event);
|
|
27
|
+
if (!handled) {
|
|
28
|
+
this.logger.warn('Received unexpected/unhandled stripe event: ', event);
|
|
29
|
+
}
|
|
30
|
+
return handled;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
StripeWebhookService = tslib_1.__decorate([
|
|
35
|
+
(0, common_1.Injectable)(),
|
|
36
|
+
tslib_1.__metadata("design:paramtypes", [stripe_api_1.StripeApi])
|
|
37
|
+
], StripeWebhookService);
|
|
38
|
+
exports.StripeWebhookService = StripeWebhookService;
|
|
39
|
+
//# sourceMappingURL=webhook.stripe.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.stripe.service.js","sourceRoot":"","sources":["../../../../../../../packages/nestjs/stripe/src/lib/webhook/webhook.stripe.service.ts"],"names":[],"mappings":";;;;AACA,2CAAoD;AAEpD,qDAAkG;AAClG,8CAA0C;AAG1C;;GAEG;AAEH,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAO/B,YACmB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QANtB,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAsB,CAAC,CAAC;QAEpD,YAAO,GAA0B,IAAA,0CAAyB,GAAE,CAAC;QAC7D,cAAS,GAAG,IAAA,oDAAmC,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAInE,CAAC;IAEQ,gBAAgB,CAAC,GAAY,EAAE,OAAe;;YACzD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC7E,OAAO,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;KAAA;IAEK,oBAAoB,CAAC,KAAmB;;YAC5C,MAAM,OAAO,GAAY,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAEnD,IAAI,CAAC,OAAO,EAAE;gBACZ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;aACzE;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CAEF,CAAA;AA1BY,oBAAoB;IADhC,IAAA,mBAAU,GAAE;6CASmB,sBAAS;GAR5B,oBAAoB,CA0BhC;AA1BY,oDAAoB"}
|