@tsed/stripe 7.0.0-beta.1 → 7.0.0-beta.4

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/.mocharc.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- ...require('@tsed/mocha-config')(),
2
+ ...require("@tsed/mocha-config")(),
3
3
  spec: ["{src,test}/**/*.spec.ts"],
4
- exclude: [],
4
+ exclude: []
5
5
  };
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.STRIPE_WEBHOOK_SIGNATURE = exports.STRIPE_WEBHOOK_EVENT = void 0;
4
4
  exports.STRIPE_WEBHOOK_EVENT = "strip_webhook_event";
5
5
  exports.STRIPE_WEBHOOK_SIGNATURE = "strip_webhook_signature";
6
- //# sourceMappingURL=index.js.map
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,qBAAqB,CAAC;AAC7C,QAAA,wBAAwB,GAAG,yBAAyB,CAAC","sourcesContent":["export const STRIPE_WEBHOOK_EVENT = \"strip_webhook_event\";\nexport const STRIPE_WEBHOOK_SIGNATURE = \"strip_webhook_signature\";\n"]}
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebhookEvent = void 0;
4
- const common_1 = require("@tsed/common");
4
+ const platform_middlewares_1 = require("@tsed/platform-middlewares");
5
+ const platform_params_1 = require("@tsed/platform-params");
5
6
  const core_1 = require("@tsed/core");
6
7
  const schema_1 = require("@tsed/schema");
7
- const constants_1 = require("../constants");
8
+ const constants_1 = require("../constants/constants");
8
9
  const WebhookEventMiddleware_1 = require("../middlewares/WebhookEventMiddleware");
9
10
  /**
10
11
  * Get the stripe webhook event.
@@ -14,7 +15,7 @@ const WebhookEventMiddleware_1 = require("../middlewares/WebhookEventMiddleware"
14
15
  * @input
15
16
  */
16
17
  function WebhookEvent(options) {
17
- return (0, core_1.useDecorators)((0, core_1.useMethodDecorators)((0, schema_1.In)("body").Type(Object).Required().Description("The raw webhook payload"), (0, schema_1.In)("header").Name("stripe-signature").Type(String).Required().Description("The stripe webhook signature"), (0, core_1.StoreSet)(WebhookEventMiddleware_1.WebhookEventMiddleware, options), (0, common_1.UseBefore)(WebhookEventMiddleware_1.WebhookEventMiddleware)), (0, common_1.Context)(constants_1.STRIPE_WEBHOOK_EVENT));
18
+ return (0, core_1.useDecorators)((0, core_1.useMethodDecorators)((0, schema_1.In)("body").Type(Object).Required().Description("The raw webhook payload"), (0, schema_1.In)("header").Name("stripe-signature").Type(String).Required().Description("The stripe webhook signature"), (0, core_1.StoreSet)(WebhookEventMiddleware_1.WebhookEventMiddleware, options), (0, platform_middlewares_1.UseBefore)(WebhookEventMiddleware_1.WebhookEventMiddleware)), (0, platform_params_1.Context)(constants_1.STRIPE_WEBHOOK_EVENT));
18
19
  }
19
20
  exports.WebhookEvent = WebhookEvent;
20
21
  //# sourceMappingURL=webhookEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhookEvent.js","sourceRoot":"","sources":["../../../src/decorators/webhookEvent.ts"],"names":[],"mappings":";;;AAAA,yCAAgD;AAChD,qCAAwE;AACxE,yCAAgC;AAChC,4CAAkD;AAClD,kFAAkG;AAElG;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,OAAsC;IACjE,OAAO,IAAA,oBAAa,EAClB,IAAA,0BAAmB,EACjB,IAAA,WAAE,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,yBAAyB,CAAC,EACzE,IAAA,WAAE,EAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,8BAA8B,CAAC,EACzG,IAAA,eAAQ,EAAC,+CAAsB,EAAE,OAAO,CAAC,EACzC,IAAA,kBAAS,EAAC,+CAAsB,CAAC,CAClC,EACD,IAAA,gBAAO,EAAC,gCAAoB,CAAC,CAC9B,CAAC;AACJ,CAAC;AAVD,oCAUC","sourcesContent":["import {Context, UseBefore} from \"@tsed/common\";\nimport {StoreSet, useDecorators, useMethodDecorators} from \"@tsed/core\";\nimport {In} from \"@tsed/schema\";\nimport {STRIPE_WEBHOOK_EVENT} from \"../constants\";\nimport {WebhookEventMiddleware, WebhookEventOptions} from \"../middlewares/WebhookEventMiddleware\";\n\n/**\n * Get the stripe webhook event.\n *\n * @decorator\n * @operation\n * @input\n */\nexport function WebhookEvent(options?: Partial<WebhookEventOptions>) {\n return useDecorators(\n useMethodDecorators(\n In(\"body\").Type(Object).Required().Description(\"The raw webhook payload\"),\n In(\"header\").Name(\"stripe-signature\").Type(String).Required().Description(\"The stripe webhook signature\"),\n StoreSet(WebhookEventMiddleware, options),\n UseBefore(WebhookEventMiddleware)\n ),\n Context(STRIPE_WEBHOOK_EVENT)\n );\n}\n"]}
1
+ {"version":3,"file":"webhookEvent.js","sourceRoot":"","sources":["../../../src/decorators/webhookEvent.ts"],"names":[],"mappings":";;;AAAA,qEAAqD;AACrD,2DAA8C;AAC9C,qCAAwE;AACxE,yCAAgC;AAChC,sDAA4D;AAC5D,kFAAkG;AAElG;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,OAAsC;IACjE,OAAO,IAAA,oBAAa,EAClB,IAAA,0BAAmB,EACjB,IAAA,WAAE,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,yBAAyB,CAAC,EACzE,IAAA,WAAE,EAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,8BAA8B,CAAC,EACzG,IAAA,eAAQ,EAAC,+CAAsB,EAAE,OAAO,CAAC,EACzC,IAAA,gCAAS,EAAC,+CAAsB,CAAC,CAClC,EACD,IAAA,yBAAO,EAAC,gCAAoB,CAAC,CAC9B,CAAC;AACJ,CAAC;AAVD,oCAUC","sourcesContent":["import {UseBefore} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport {StoreSet, useDecorators, useMethodDecorators} from \"@tsed/core\";\nimport {In} from \"@tsed/schema\";\nimport {STRIPE_WEBHOOK_EVENT} from \"../constants/constants\";\nimport {WebhookEventMiddleware, WebhookEventOptions} from \"../middlewares/WebhookEventMiddleware\";\n\n/**\n * Get the stripe webhook event.\n *\n * @decorator\n * @operation\n * @input\n */\nexport function WebhookEvent(options?: Partial<WebhookEventOptions>) {\n return useDecorators(\n useMethodDecorators(\n In(\"body\").Type(Object).Required().Description(\"The raw webhook payload\"),\n In(\"header\").Name(\"stripe-signature\").Type(String).Required().Description(\"The stripe webhook signature\"),\n StoreSet(WebhookEventMiddleware, options),\n UseBefore(WebhookEventMiddleware)\n ),\n Context(STRIPE_WEBHOOK_EVENT)\n );\n}\n"]}
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./constants"), exports);
5
- (0, tslib_1.__exportStar)(require("./domain/index"), exports);
6
- (0, tslib_1.__exportStar)(require("./decorators/webhookEvent"), exports);
7
- (0, tslib_1.__exportStar)(require("./middlewares/WebhookEventMiddleware"), exports);
8
- (0, tslib_1.__exportStar)(require("./services/StripeFactory"), exports);
7
+ tslib_1.__exportStar(require("./constants/constants"), exports);
8
+ tslib_1.__exportStar(require("./decorators/webhookEvent"), exports);
9
+ tslib_1.__exportStar(require("./domain/StripSettings"), exports);
10
+ tslib_1.__exportStar(require("./middlewares/WebhookEventMiddleware"), exports);
11
+ tslib_1.__exportStar(require("./services/StripeFactory"), exports);
9
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAA4B;AAC5B,8DAA+B;AAC/B,yEAA0C;AAC1C,oFAAqD;AACrD,wEAAyC","sourcesContent":["export * from \"./constants\";\nexport * from \"./domain/index\";\nexport * from \"./decorators/webhookEvent\";\nexport * from \"./middlewares/WebhookEventMiddleware\";\nexport * from \"./services/StripeFactory\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,oEAA0C;AAC1C,iEAAuC;AACvC,+EAAqD;AACrD,mEAAyC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/webhookEvent\";\nexport * from \"./domain/StripSettings\";\nexport * from \"./middlewares/WebhookEventMiddleware\";\nexport * from \"./services/StripeFactory\";\n"]}
@@ -3,10 +3,12 @@ var WebhookEventMiddleware_1;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.WebhookEventMiddleware = void 0;
5
5
  const tslib_1 = require("tslib");
6
- const common_1 = require("@tsed/common");
6
+ const platform_params_1 = require("@tsed/platform-params");
7
+ const platform_middlewares_1 = require("@tsed/platform-middlewares");
8
+ const di_1 = require("@tsed/di");
7
9
  const exceptions_1 = require("@tsed/exceptions");
8
10
  const stripe_1 = require("stripe");
9
- const constants_1 = require("../constants");
11
+ const constants_1 = require("../constants/constants");
10
12
  require("../services/StripeFactory");
11
13
  let WebhookEventMiddleware = WebhookEventMiddleware_1 = class WebhookEventMiddleware {
12
14
  use(signature, body, ctx) {
@@ -26,24 +28,24 @@ let WebhookEventMiddleware = WebhookEventMiddleware_1 = class WebhookEventMiddle
26
28
  }
27
29
  }
28
30
  };
29
- (0, tslib_1.__decorate)([
30
- (0, common_1.Inject)(),
31
- (0, tslib_1.__metadata)("design:type", stripe_1.Stripe)
31
+ tslib_1.__decorate([
32
+ (0, di_1.Inject)(),
33
+ tslib_1.__metadata("design:type", stripe_1.Stripe)
32
34
  ], WebhookEventMiddleware.prototype, "stripe", void 0);
33
- (0, tslib_1.__decorate)([
34
- (0, common_1.Constant)("stripe.webhooks"),
35
- (0, tslib_1.__metadata)("design:type", Object)
35
+ tslib_1.__decorate([
36
+ (0, di_1.Constant)("stripe.webhooks"),
37
+ tslib_1.__metadata("design:type", Object)
36
38
  ], WebhookEventMiddleware.prototype, "webhooks", void 0);
37
- (0, tslib_1.__decorate)([
38
- (0, tslib_1.__param)(0, (0, common_1.HeaderParams)("stripe-signature")),
39
- (0, tslib_1.__param)(1, (0, common_1.RawBodyParams)()),
40
- (0, tslib_1.__param)(2, (0, common_1.Context)()),
41
- (0, tslib_1.__metadata)("design:type", Function),
42
- (0, tslib_1.__metadata)("design:paramtypes", [String, Buffer, Object]),
43
- (0, tslib_1.__metadata)("design:returntype", Object)
39
+ tslib_1.__decorate([
40
+ tslib_1.__param(0, (0, platform_params_1.HeaderParams)("stripe-signature")),
41
+ tslib_1.__param(1, (0, platform_params_1.RawBodyParams)()),
42
+ tslib_1.__param(2, (0, platform_params_1.Context)()),
43
+ tslib_1.__metadata("design:type", Function),
44
+ tslib_1.__metadata("design:paramtypes", [String, Buffer, Object]),
45
+ tslib_1.__metadata("design:returntype", Object)
44
46
  ], WebhookEventMiddleware.prototype, "use", null);
45
- WebhookEventMiddleware = WebhookEventMiddleware_1 = (0, tslib_1.__decorate)([
46
- (0, common_1.Middleware)()
47
+ WebhookEventMiddleware = WebhookEventMiddleware_1 = tslib_1.__decorate([
48
+ (0, platform_middlewares_1.Middleware)()
47
49
  ], WebhookEventMiddleware);
48
50
  exports.WebhookEventMiddleware = WebhookEventMiddleware;
49
51
  //# sourceMappingURL=WebhookEventMiddleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebhookEventMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/WebhookEventMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,yCAAmH;AACnH,iDAAiE;AACjE,mCAA8B;AAC9B,4CAA4E;AAC5E,qCAAmC;AAQnC,IAAa,sBAAsB,8BAAnC,MAAa,sBAAsB;IAOjC,GAAG,CAAmC,SAAiB,EAAmB,IAAY,EAAa,GAAY;QAC7G,MAAM,EAAC,MAAM,EAAE,SAAS,EAAC,GAAwB;YAC/C,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAsB,CAAC;SAClD,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,gCAAmB,CAC3B,qHAAqH,CACtH,CAAC;SACH;QAED,IAAI;YACF,GAAG,CAAC,GAAG,CAAC,oCAAwB,EAAE,SAAS,CAAC,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,gCAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;SACxG;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,uBAAU,CAAC,yBAAyB,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;SACnE;IACH,CAAC;CACF,CAAA;AAxBC;IADC,IAAA,eAAM,GAAE;2CACS,eAAM;sDAAC;AAGzB;IADC,IAAA,iBAAQ,EAAC,iBAAiB,CAAC;;wDACY;AAExC;IAAK,wBAAA,IAAA,qBAAY,EAAC,kBAAkB,CAAC,CAAA;IAAqB,wBAAA,IAAA,sBAAa,GAAE,CAAA;IAAgB,wBAAA,IAAA,gBAAO,GAAE,CAAA;;0DAAlB,MAAM;;iDAkBrF;AAzBU,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CA0BlC;AA1BY,wDAAsB","sourcesContent":["import {Constant, Context, HeaderParams, Inject, Middleware, MiddlewareMethods, RawBodyParams} from \"@tsed/common\";\nimport {BadRequest, InternalServerError} from \"@tsed/exceptions\";\nimport {Stripe} from \"stripe\";\nimport {STRIPE_WEBHOOK_EVENT, STRIPE_WEBHOOK_SIGNATURE} from \"../constants\";\nimport \"../services/StripeFactory\";\n\nexport interface WebhookEventOptions {\n secret: string;\n tolerance: number;\n}\n\n@Middleware()\nexport class WebhookEventMiddleware implements MiddlewareMethods {\n @Inject()\n protected stripe: Stripe;\n\n @Constant(\"stripe.webhooks\")\n protected webhooks: WebhookEventOptions;\n\n use(@HeaderParams(\"stripe-signature\") signature: string, @RawBodyParams() body: Buffer, @Context() ctx: Context): any {\n const {secret, tolerance}: WebhookEventOptions = {\n ...this.webhooks,\n ...ctx.endpoint.store.get(WebhookEventMiddleware)\n };\n\n if (!secret) {\n throw new InternalServerError(\n \"Missing Stripe webhooks secret key. You can get this in your dashboard. See: https://dashboard.stripe.com/webhooks.\"\n );\n }\n\n try {\n ctx.set(STRIPE_WEBHOOK_SIGNATURE, signature);\n ctx.set(STRIPE_WEBHOOK_EVENT, this.stripe.webhooks.constructEvent(body, signature, secret, tolerance));\n } catch (err) {\n throw new BadRequest(`Stripe webhook error: ${err.message}`, err);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"WebhookEventMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/WebhookEventMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,2DAA2E;AAC3E,qEAAyE;AACzE,iCAA0C;AAC1C,iDAAiE;AACjE,mCAA8B;AAC9B,sDAAsF;AACtF,qCAAmC;AAQnC,IAAa,sBAAsB,8BAAnC,MAAa,sBAAsB;IAOjC,GAAG,CAAmC,SAAiB,EAAmB,IAAY,EAAa,GAAY;QAC7G,MAAM,EAAC,MAAM,EAAE,SAAS,EAAC,GAAwB;YAC/C,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAsB,CAAC;SAClD,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,gCAAmB,CAC3B,qHAAqH,CACtH,CAAC;SACH;QAED,IAAI;YACF,GAAG,CAAC,GAAG,CAAC,oCAAwB,EAAE,SAAS,CAAC,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,gCAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;SACxG;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,uBAAU,CAAC,yBAAyB,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;SACnE;IACH,CAAC;CACF,CAAA;AAxBC;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;sDAAC;AAGzB;IADC,IAAA,aAAQ,EAAC,iBAAiB,CAAC;;wDACY;AAExC;IAAK,mBAAA,IAAA,8BAAY,EAAC,kBAAkB,CAAC,CAAA;IAAqB,mBAAA,IAAA,+BAAa,GAAE,CAAA;IAAgB,mBAAA,IAAA,yBAAO,GAAE,CAAA;;qDAAlB,MAAM;;iDAkBrF;AAzBU,sBAAsB;IADlC,IAAA,iCAAU,GAAE;GACA,sBAAsB,CA0BlC;AA1BY,wDAAsB","sourcesContent":["import {Context, HeaderParams, RawBodyParams} from \"@tsed/platform-params\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Constant, Inject} from \"@tsed/di\";\nimport {BadRequest, InternalServerError} from \"@tsed/exceptions\";\nimport {Stripe} from \"stripe\";\nimport {STRIPE_WEBHOOK_EVENT, STRIPE_WEBHOOK_SIGNATURE} from \"../constants/constants\";\nimport \"../services/StripeFactory\";\n\nexport interface WebhookEventOptions {\n secret: string;\n tolerance: number;\n}\n\n@Middleware()\nexport class WebhookEventMiddleware implements MiddlewareMethods {\n @Inject()\n protected stripe: Stripe;\n\n @Constant(\"stripe.webhooks\")\n protected webhooks: WebhookEventOptions;\n\n use(@HeaderParams(\"stripe-signature\") signature: string, @RawBodyParams() body: Buffer, @Context() ctx: Context): any {\n const {secret, tolerance}: WebhookEventOptions = {\n ...this.webhooks,\n ...ctx.endpoint.store.get(WebhookEventMiddleware)\n };\n\n if (!secret) {\n throw new InternalServerError(\n \"Missing Stripe webhooks secret key. You can get this in your dashboard. See: https://dashboard.stripe.com/webhooks.\"\n );\n }\n\n try {\n ctx.set(STRIPE_WEBHOOK_SIGNATURE, signature);\n ctx.set(STRIPE_WEBHOOK_EVENT, this.stripe.webhooks.constructEvent(body, signature, secret, tolerance));\n } catch (err) {\n throw new BadRequest(`Stripe webhook error: ${err.message}`, err);\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -1,3 +1,3 @@
1
1
  export const STRIPE_WEBHOOK_EVENT = "strip_webhook_event";
2
2
  export const STRIPE_WEBHOOK_SIGNATURE = "strip_webhook_signature";
3
- //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAC1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,yBAAyB,CAAC","sourcesContent":["export const STRIPE_WEBHOOK_EVENT = \"strip_webhook_event\";\nexport const STRIPE_WEBHOOK_SIGNATURE = \"strip_webhook_signature\";\n"]}
@@ -1,8 +1,9 @@
1
- import { Context, UseBefore } from "@tsed/common";
1
+ import { UseBefore } from "@tsed/platform-middlewares";
2
+ import { Context } from "@tsed/platform-params";
2
3
  import { StoreSet, useDecorators, useMethodDecorators } from "@tsed/core";
3
4
  import { In } from "@tsed/schema";
4
- import { STRIPE_WEBHOOK_EVENT } from "../constants";
5
- import { WebhookEventMiddleware } from "../middlewares/WebhookEventMiddleware";
5
+ import { STRIPE_WEBHOOK_EVENT } from "../constants/constants.js";
6
+ import { WebhookEventMiddleware } from "../middlewares/WebhookEventMiddleware.js";
6
7
  /**
7
8
  * Get the stripe webhook event.
8
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"webhookEvent.js","sourceRoot":"","sources":["../../../src/decorators/webhookEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,cAAc,CAAC;AAChD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAE,mBAAmB,EAAC,MAAM,YAAY,CAAC;AACxE,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,EAAC,oBAAoB,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,sBAAsB,EAAsB,MAAM,uCAAuC,CAAC;AAElG;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAsC;IACjE,OAAO,aAAa,CAClB,mBAAmB,CACjB,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,yBAAyB,CAAC,EACzE,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,8BAA8B,CAAC,EACzG,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC,EACzC,SAAS,CAAC,sBAAsB,CAAC,CAClC,EACD,OAAO,CAAC,oBAAoB,CAAC,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import {Context, UseBefore} from \"@tsed/common\";\nimport {StoreSet, useDecorators, useMethodDecorators} from \"@tsed/core\";\nimport {In} from \"@tsed/schema\";\nimport {STRIPE_WEBHOOK_EVENT} from \"../constants\";\nimport {WebhookEventMiddleware, WebhookEventOptions} from \"../middlewares/WebhookEventMiddleware\";\n\n/**\n * Get the stripe webhook event.\n *\n * @decorator\n * @operation\n * @input\n */\nexport function WebhookEvent(options?: Partial<WebhookEventOptions>) {\n return useDecorators(\n useMethodDecorators(\n In(\"body\").Type(Object).Required().Description(\"The raw webhook payload\"),\n In(\"header\").Name(\"stripe-signature\").Type(String).Required().Description(\"The stripe webhook signature\"),\n StoreSet(WebhookEventMiddleware, options),\n UseBefore(WebhookEventMiddleware)\n ),\n Context(STRIPE_WEBHOOK_EVENT)\n );\n}\n"]}
1
+ {"version":3,"file":"webhookEvent.js","sourceRoot":"","sources":["../../../src/decorators/webhookEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAE,mBAAmB,EAAC,MAAM,YAAY,CAAC;AACxE,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,sBAAsB,EAAsB,MAAM,uCAAuC,CAAC;AAElG;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAsC;IACjE,OAAO,aAAa,CAClB,mBAAmB,CACjB,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,yBAAyB,CAAC,EACzE,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,8BAA8B,CAAC,EACzG,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC,EACzC,SAAS,CAAC,sBAAsB,CAAC,CAClC,EACD,OAAO,CAAC,oBAAoB,CAAC,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import {UseBefore} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport {StoreSet, useDecorators, useMethodDecorators} from \"@tsed/core\";\nimport {In} from \"@tsed/schema\";\nimport {STRIPE_WEBHOOK_EVENT} from \"../constants/constants\";\nimport {WebhookEventMiddleware, WebhookEventOptions} from \"../middlewares/WebhookEventMiddleware\";\n\n/**\n * Get the stripe webhook event.\n *\n * @decorator\n * @operation\n * @input\n */\nexport function WebhookEvent(options?: Partial<WebhookEventOptions>) {\n return useDecorators(\n useMethodDecorators(\n In(\"body\").Type(Object).Required().Description(\"The raw webhook payload\"),\n In(\"header\").Name(\"stripe-signature\").Type(String).Required().Description(\"The stripe webhook signature\"),\n StoreSet(WebhookEventMiddleware, options),\n UseBefore(WebhookEventMiddleware)\n ),\n Context(STRIPE_WEBHOOK_EVENT)\n );\n}\n"]}
package/lib/esm/index.js CHANGED
@@ -1,6 +1,9 @@
1
- export * from "./constants";
2
- export * from "./domain/index";
3
- export * from "./decorators/webhookEvent";
4
- export * from "./middlewares/WebhookEventMiddleware";
5
- export * from "./services/StripeFactory";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./constants/constants.js";
5
+ export * from "./decorators/webhookEvent.js";
6
+ export * from "./domain/StripSettings.js";
7
+ export * from "./middlewares/WebhookEventMiddleware.js";
8
+ export * from "./services/StripeFactory.js";
6
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,cAAc,0BAA0B,CAAC","sourcesContent":["export * from \"./constants\";\nexport * from \"./domain/index\";\nexport * from \"./decorators/webhookEvent\";\nexport * from \"./middlewares/WebhookEventMiddleware\";\nexport * from \"./services/StripeFactory\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sCAAsC,CAAC;AACrD,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/webhookEvent\";\nexport * from \"./domain/StripSettings\";\nexport * from \"./middlewares/WebhookEventMiddleware\";\nexport * from \"./services/StripeFactory\";\n"]}
@@ -1,10 +1,12 @@
1
1
  var WebhookEventMiddleware_1;
2
2
  import { __decorate, __metadata, __param } from "tslib";
3
- import { Constant, Context, HeaderParams, Inject, Middleware, RawBodyParams } from "@tsed/common";
3
+ import { Context, HeaderParams, RawBodyParams } from "@tsed/platform-params";
4
+ import { Middleware } from "@tsed/platform-middlewares";
5
+ import { Constant, Inject } from "@tsed/di";
4
6
  import { BadRequest, InternalServerError } from "@tsed/exceptions";
5
7
  import { Stripe } from "stripe";
6
- import { STRIPE_WEBHOOK_EVENT, STRIPE_WEBHOOK_SIGNATURE } from "../constants";
7
- import "../services/StripeFactory";
8
+ import { STRIPE_WEBHOOK_EVENT, STRIPE_WEBHOOK_SIGNATURE } from "../constants/constants.js";
9
+ import "../services/StripeFactory.js";
8
10
  let WebhookEventMiddleware = WebhookEventMiddleware_1 = class WebhookEventMiddleware {
9
11
  use(signature, body, ctx) {
10
12
  const { secret, tolerance } = {
@@ -1 +1 @@
1
- {"version":3,"file":"WebhookEventMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/WebhookEventMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAqB,aAAa,EAAC,MAAM,cAAc,CAAC;AACnH,OAAO,EAAC,UAAU,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,oBAAoB,EAAE,wBAAwB,EAAC,MAAM,cAAc,CAAC;AAC5E,OAAO,2BAA2B,CAAC;AAQnC,IAAa,sBAAsB,8BAAnC,MAAa,sBAAsB;IAOjC,GAAG,CAAmC,SAAiB,EAAmB,IAAY,EAAa,GAAY;QAC7G,MAAM,EAAC,MAAM,EAAE,SAAS,EAAC,GAAwB;YAC/C,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAsB,CAAC;SAClD,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,mBAAmB,CAC3B,qHAAqH,CACtH,CAAC;SACH;QAED,IAAI;YACF,GAAG,CAAC,GAAG,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;SACxG;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,UAAU,CAAC,yBAAyB,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;SACnE;IACH,CAAC;CACF,CAAA;AAxBC;IADC,MAAM,EAAE;8BACS,MAAM;sDAAC;AAGzB;IADC,QAAQ,CAAC,iBAAiB,CAAC;;wDACY;AAExC;IAAK,WAAA,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAAqB,WAAA,aAAa,EAAE,CAAA;IAAgB,WAAA,OAAO,EAAE,CAAA;;6CAAlB,MAAM;;iDAkBrF;AAzBU,sBAAsB;IADlC,UAAU,EAAE;GACA,sBAAsB,CA0BlC;SA1BY,sBAAsB","sourcesContent":["import {Constant, Context, HeaderParams, Inject, Middleware, MiddlewareMethods, RawBodyParams} from \"@tsed/common\";\nimport {BadRequest, InternalServerError} from \"@tsed/exceptions\";\nimport {Stripe} from \"stripe\";\nimport {STRIPE_WEBHOOK_EVENT, STRIPE_WEBHOOK_SIGNATURE} from \"../constants\";\nimport \"../services/StripeFactory\";\n\nexport interface WebhookEventOptions {\n secret: string;\n tolerance: number;\n}\n\n@Middleware()\nexport class WebhookEventMiddleware implements MiddlewareMethods {\n @Inject()\n protected stripe: Stripe;\n\n @Constant(\"stripe.webhooks\")\n protected webhooks: WebhookEventOptions;\n\n use(@HeaderParams(\"stripe-signature\") signature: string, @RawBodyParams() body: Buffer, @Context() ctx: Context): any {\n const {secret, tolerance}: WebhookEventOptions = {\n ...this.webhooks,\n ...ctx.endpoint.store.get(WebhookEventMiddleware)\n };\n\n if (!secret) {\n throw new InternalServerError(\n \"Missing Stripe webhooks secret key. You can get this in your dashboard. See: https://dashboard.stripe.com/webhooks.\"\n );\n }\n\n try {\n ctx.set(STRIPE_WEBHOOK_SIGNATURE, signature);\n ctx.set(STRIPE_WEBHOOK_EVENT, this.stripe.webhooks.constructEvent(body, signature, secret, tolerance));\n } catch (err) {\n throw new BadRequest(`Stripe webhook error: ${err.message}`, err);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"WebhookEventMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/WebhookEventMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAC,UAAU,EAAoB,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,oBAAoB,EAAE,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AACtF,OAAO,2BAA2B,CAAC;AAQnC,IAAa,sBAAsB,8BAAnC,MAAa,sBAAsB;IAOjC,GAAG,CAAmC,SAAiB,EAAmB,IAAY,EAAa,GAAY;QAC7G,MAAM,EAAC,MAAM,EAAE,SAAS,EAAC,GAAwB;YAC/C,GAAG,IAAI,CAAC,QAAQ;YAChB,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAsB,CAAC;SAClD,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,mBAAmB,CAC3B,qHAAqH,CACtH,CAAC;SACH;QAED,IAAI;YACF,GAAG,CAAC,GAAG,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;SACxG;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,UAAU,CAAC,yBAAyB,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;SACnE;IACH,CAAC;CACF,CAAA;AAxBC;IADC,MAAM,EAAE;8BACS,MAAM;sDAAC;AAGzB;IADC,QAAQ,CAAC,iBAAiB,CAAC;;wDACY;AAExC;IAAK,WAAA,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAAqB,WAAA,aAAa,EAAE,CAAA;IAAgB,WAAA,OAAO,EAAE,CAAA;;6CAAlB,MAAM;;iDAkBrF;AAzBU,sBAAsB;IADlC,UAAU,EAAE;GACA,sBAAsB,CA0BlC;SA1BY,sBAAsB","sourcesContent":["import {Context, HeaderParams, RawBodyParams} from \"@tsed/platform-params\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Constant, Inject} from \"@tsed/di\";\nimport {BadRequest, InternalServerError} from \"@tsed/exceptions\";\nimport {Stripe} from \"stripe\";\nimport {STRIPE_WEBHOOK_EVENT, STRIPE_WEBHOOK_SIGNATURE} from \"../constants/constants\";\nimport \"../services/StripeFactory\";\n\nexport interface WebhookEventOptions {\n secret: string;\n tolerance: number;\n}\n\n@Middleware()\nexport class WebhookEventMiddleware implements MiddlewareMethods {\n @Inject()\n protected stripe: Stripe;\n\n @Constant(\"stripe.webhooks\")\n protected webhooks: WebhookEventOptions;\n\n use(@HeaderParams(\"stripe-signature\") signature: string, @RawBodyParams() body: Buffer, @Context() ctx: Context): any {\n const {secret, tolerance}: WebhookEventOptions = {\n ...this.webhooks,\n ...ctx.endpoint.store.get(WebhookEventMiddleware)\n };\n\n if (!secret) {\n throw new InternalServerError(\n \"Missing Stripe webhooks secret key. You can get this in your dashboard. See: https://dashboard.stripe.com/webhooks.\"\n );\n }\n\n try {\n ctx.set(STRIPE_WEBHOOK_SIGNATURE, signature);\n ctx.set(STRIPE_WEBHOOK_EVENT, this.stripe.webhooks.constructEvent(body, signature, secret, tolerance));\n } catch (err) {\n throw new BadRequest(`Stripe webhook error: ${err.message}`, err);\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -1,5 +1,8 @@
1
- export * from "./constants";
2
- export * from "./domain/index";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./constants/constants";
3
5
  export * from "./decorators/webhookEvent";
6
+ export * from "./domain/StripSettings";
4
7
  export * from "./middlewares/WebhookEventMiddleware";
5
8
  export * from "./services/StripeFactory";
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Context, MiddlewareMethods } from "@tsed/common";
2
+ import { Context } from "@tsed/platform-params";
3
+ import { MiddlewareMethods } from "@tsed/platform-middlewares";
3
4
  import { Stripe } from "stripe";
4
5
  import "../services/StripeFactory";
5
6
  export interface WebhookEventOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/stripe",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.4",
4
4
  "description": "Stripe package for Ts.ED framework",
5
5
  "private": false,
6
6
  "keywords": [
@@ -14,6 +14,7 @@
14
14
  ],
15
15
  "source": "./src/index.ts",
16
16
  "main": "./lib/cjs/index.js",
17
+ "module": "./lib/esm/index.js",
17
18
  "typings": "./lib/types/index.d.ts",
18
19
  "exports": {
19
20
  "types": "./lib/types/index.d.ts",
@@ -22,39 +23,55 @@
22
23
  "default": "./lib/esm/index.js"
23
24
  },
24
25
  "scripts": {
25
- "build": "yarn run build:esm && yarn run build:cjs",
26
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
26
27
  "build:cjs": "tsc --build tsconfig.compile.json",
27
28
  "build:esm": "tsc --build tsconfig.compile.esm.json",
29
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
28
30
  "test": "cross-env NODE_ENV=test nyc mocha"
29
31
  },
30
32
  "dependencies": {
31
- "tslib": "2.2.0"
33
+ "tslib": "2.3.1"
32
34
  },
33
35
  "devDependencies": {
34
- "@tsed/common": "7.0.0-beta.1",
35
- "@tsed/core": "7.0.0-beta.1",
36
- "@tsed/di": "7.0.0-beta.1",
37
- "@tsed/json-mapper": "7.0.0-beta.1",
38
- "@tsed/openspec": "7.0.0-beta.1",
39
- "@tsed/schema": "7.0.0-beta.1",
36
+ "@tsed/core": "7.0.0-beta.4",
37
+ "@tsed/di": "7.0.0-beta.4",
38
+ "@tsed/exceptions": "7.0.0-beta.4",
39
+ "@tsed/platform-middlewares": "7.0.0-beta.4",
40
+ "@tsed/platform-params": "7.0.0-beta.4",
41
+ "@tsed/schema": "7.0.0-beta.4",
40
42
  "stripe": "^8.129.0"
41
43
  },
42
44
  "peerDependencies": {
43
- "@tsed/common": "^7.0.0-beta.1",
44
- "@tsed/core": "^7.0.0-beta.1",
45
- "@tsed/di": "^7.0.0-beta.1",
46
- "@tsed/json-mapper": "^7.0.0-beta.1",
47
- "@tsed/openspec": "^7.0.0-beta.1",
48
- "@tsed/schema": "^7.0.0-beta.1",
45
+ "@tsed/exceptions": "^7.0.0-beta.4",
46
+ "@tsed/platform-middlewares": "^7.0.0-beta.4",
47
+ "@tsed/platform-params": "^7.0.0-beta.4",
48
+ "@tsed/schema": "^7.0.0-beta.4",
49
49
  "@types/body-parser": "^1.19.0",
50
50
  "body-parser": "^1.19.0",
51
51
  "stripe": "^8.129.0"
52
52
  },
53
+ "peerDependenciesMeta": {
54
+ "@tsed/platform-middlewares": {
55
+ "optional": false
56
+ },
57
+ "@tsed/platform-params": {
58
+ "optional": false
59
+ },
60
+ "@tsed/schema": {
61
+ "optional": false
62
+ },
63
+ "@tsed/exceptions": {
64
+ "optional": false
65
+ },
66
+ "stripe": {
67
+ "optional": false
68
+ }
69
+ },
53
70
  "repository": "https://github.com/tsedio/tsed",
54
71
  "bugs": {
55
72
  "url": "https://github.com/tsedio/tsed/issues"
56
73
  },
57
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/third-parties/stripe",
74
+ "homepage": "https://github.com/tsedio/tsed/tree/production/packages/third-parties/stripe",
58
75
  "author": "Romain Lenzotti",
59
76
  "license": "MIT"
60
77
  }
package/readme.md CHANGED
@@ -32,7 +32,7 @@ A package of Ts.ED framework. See website: https://tsed.io/tutorials/stripe.html
32
32
  ## Feature
33
33
 
34
34
  Currently, `@tsed/stripe` allows you:
35
-
35
+
36
36
  - Configure stripe,
37
37
  - Create webhooks,
38
38
  - Use stripe API.
@@ -50,33 +50,59 @@ Then import `@tsed/stripe` in your Server:
50
50
 
51
51
  ```typescript
52
52
  import {Configuration, PlatformApplication} from "@tsed/common";
53
- import "@tsed/stripe";
53
+ import "@tsed/stripe";
54
54
  import {Stripe} from "stripe";
55
55
 
56
56
  @Configuration({
57
57
  stripe: {
58
58
  apiKey: process.env.STRIPE_SECRET_KEY,
59
59
  webhooks: {
60
- secret: process.env.STRIPE_WEBHOOK_SECRET,
60
+ secret: process.env.STRIPE_WEBHOOK_SECRET
61
61
  },
62
62
  // Stripe options
63
- apiVersion: '2019-08-08',
64
- httpProxy: new ProxyAgent(process.env.http_proxy),
63
+ apiVersion: "2019-08-08",
64
+ httpProxy: new ProxyAgent(process.env.http_proxy)
65
65
  }
66
66
  })
67
67
  export class Server {
68
68
  @Inject()
69
69
  stripe: Stripe;
70
-
70
+
71
71
  $afterInit() {
72
72
  // do something with stripe
73
73
  // this.stripe.customers
74
74
  }
75
75
  }
76
76
  ```
77
+
77
78
  > See Stripe options for more details: https://www.npmjs.com/package/stripe
78
79
 
79
- ## Inject Stripe
80
+ ::: warning
81
+ Stripe needs to validate signature transaction when you received a webhook notification.
82
+ To work properly, you have to remove bodyParser add on `$beforeRoutesInit`.
83
+
84
+ ```diff
85
+ @Configuration({
86
+ + middlewares: [
87
+ + bodyParser.json(),
88
+ + bodyParser.urlencoded({extended: true})
89
+ + ]
90
+ })
91
+ export class Server {
92
+ @Inject()
93
+ protected app: PlatformApplication;
94
+
95
+ $beforeRoutesInit() {
96
+ - this.app
97
+ - .use(bodyParser.json())
98
+ - .use(bodyParser.urlencoded({extended: true}));
99
+ }
100
+ }
101
+ ```
102
+
103
+ ::
104
+
105
+ ## Inject Stripe
80
106
 
81
107
  ```typescript
82
108
  import {Injectable} from "@tsed/di";
@@ -85,15 +111,13 @@ import {Injectable} from "@tsed/di";
85
111
  class MyStripeService {
86
112
  @Inject()
87
113
  stripe: Stripe;
88
-
114
+
89
115
  $onInit() {
90
116
  // do something with stripe
91
- this.stripe.on('request', this.onRequest.bind(this));
92
- }
93
-
94
- protected onRequest(request: any) {
95
-
117
+ this.stripe.on("request", this.onRequest.bind(this));
96
118
  }
119
+
120
+ protected onRequest(request: any) {}
97
121
  }
98
122
  ```
99
123
 
@@ -102,7 +126,7 @@ class MyStripeService {
102
126
  Stripe can optionally sign the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third-party. You can read more about it [here](https://stripe.com/docs/webhooks#signatures).
103
127
 
104
128
  To register a Stripe webhook with Ts.ED, just use the `@WebhookEvent` decorator. It'll call for you the `stripe.webhooks.constructEvent` with the right parameters:
105
-
129
+
106
130
  ```typescript
107
131
  import {RawBodyParams, HeaderParams, Controller, Context} from "@tsed/common";
108
132
  import {Stripe} from "stripe";
@@ -111,15 +135,12 @@ import {Stripe} from "stripe";
111
135
  export class StripWebhookCtrl {
112
136
  @Inject()
113
137
  stripe: Stripe;
114
-
138
+
115
139
  @Post("/callback")
116
- successPaymentHook(
117
- @WebhookEvent() event: Stripe.Event,
118
- @Context() ctx: Context
119
- ) {
120
- ctx.logger.info({name: 'Webhook success', event});
121
-
122
- return {received: true}
140
+ successPaymentHook(@WebhookEvent() event: Stripe.Event, @Context() ctx: Context) {
141
+ ctx.logger.info({name: "Webhook success", event});
142
+
143
+ return {received: true};
123
144
  }
124
145
  }
125
146
  ```
@@ -133,41 +154,43 @@ import {Stripe} from "stripe";
133
154
  import {PlatformTest} from "@tsed/common";
134
155
  import {StripWebhookCtrl} from "./StripWebhookCtrl";
135
156
 
136
- describe('StripWebhookCtrl', () => {
137
- beforeEach(() => PlatformTest.create({
138
- stripe: {
139
- apiKey: 'fake_api_key',
140
- webhooks: {
141
- secret: 'whsec_test_secret',
142
- },
143
- // Stripe options
144
- apiVersion: '2019-08-08'
145
- }
146
- }))
147
- afterEach(PlatformTest.reset)
157
+ describe("StripWebhookCtrl", () => {
158
+ beforeEach(() =>
159
+ PlatformTest.create({
160
+ stripe: {
161
+ apiKey: "fake_api_key",
162
+ webhooks: {
163
+ secret: "whsec_test_secret"
164
+ },
165
+ // Stripe options
166
+ apiVersion: "2019-08-08"
167
+ }
168
+ })
169
+ );
170
+ afterEach(PlatformTest.reset);
148
171
  it("should call event", async () => {
149
- const stripe = PlatformTest.get<Stripe>(Stripe);
150
- const payload = {
151
- id: 'evt_test_webhook',
152
- object: 'event',
153
- };
154
- const payloadString = JSON.stringify(payload, null, 2);
155
-
156
- const header = stripe.webhooks.generateTestHeaderString({
157
- payload: payloadString,
158
- secret: 'whsec_test_secret',
159
- });
160
-
161
- const event = stripe.webhooks.constructEvent(payloadString, header, secret);
162
- const ctx = PlatformTest.createRequestContext()
163
-
164
- const ctrl = await PlatformTest.invoke<StripWebhookCtrl>(StripWebhookCtrl);
165
-
166
- const result = ctrl.successPaymentHook(event, ctx);
167
-
168
- expect(result).toEqual({received: true})
172
+ const stripe = PlatformTest.get<Stripe>(Stripe);
173
+ const payload = {
174
+ id: "evt_test_webhook",
175
+ object: "event"
176
+ };
177
+ const payloadString = JSON.stringify(payload, null, 2);
178
+
179
+ const header = stripe.webhooks.generateTestHeaderString({
180
+ payload: payloadString,
181
+ secret: "whsec_test_secret"
182
+ });
183
+
184
+ const event = stripe.webhooks.constructEvent(payloadString, header, secret);
185
+ const ctx = PlatformTest.createRequestContext();
186
+
187
+ const ctrl = await PlatformTest.invoke<StripWebhookCtrl>(StripWebhookCtrl);
188
+
189
+ const result = ctrl.successPaymentHook(event, ctx);
190
+
191
+ expect(result).toEqual({received: true});
169
192
  });
170
- })
193
+ });
171
194
  ```
172
195
 
173
196
  With SuperTest:
@@ -180,10 +203,9 @@ import {expect} from "chai";
180
203
  import {Stripe} from "stripe";
181
204
  import SuperTest from "supertest";
182
205
  import {StripeWebhooksCtrl} from "./StripWebhookCtrl";
183
- import {rootDir, Server} from "../Server";
206
+ import {Server} from "../Server";
184
207
 
185
208
  const utils = PlatformTestUtils.create({
186
- rootDir,
187
209
  platform: PlatformExpress,
188
210
  server: Server,
189
211
  logger: {
@@ -193,11 +215,13 @@ const utils = PlatformTestUtils.create({
193
215
 
194
216
  describe("Stripe", () => {
195
217
  let request: SuperTest.SuperTest<SuperTest.Test>;
196
- beforeEach(utils.bootstrap({
197
- mount: {
198
- "/rest": [StripWebhookCtrl]
199
- }
200
- }));
218
+ beforeEach(
219
+ utils.bootstrap({
220
+ mount: {
221
+ "/rest": [StripWebhookCtrl]
222
+ }
223
+ })
224
+ );
201
225
  beforeEach(() => {
202
226
  request = SuperTest.agent(PlatformTest.callback());
203
227
  });
@@ -217,33 +241,28 @@ describe("Stripe", () => {
217
241
  secret: "whsec_test_secret"
218
242
  });
219
243
 
220
- const response = await request
221
- .post("/rest/webhooks/callback")
222
- .send(payloadString)
223
- .set("stripe-signature", signature)
224
- .expect(200);
244
+ const response = await request.post("/rest/webhooks/callback").send(payloadString).set("stripe-signature", signature).expect(200);
225
245
 
226
246
  expect(response.body).to.deep.eq({
227
- "event": payload,
228
- "received": true
247
+ event: payload,
248
+ received: true
229
249
  });
230
250
  });
231
251
  });
232
252
  ```
233
253
 
234
254
  ## Contributors
255
+
235
256
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
236
257
 
237
258
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
238
259
 
239
-
240
260
  ## Backers
241
261
 
242
262
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
243
263
 
244
264
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
245
265
 
246
-
247
266
  ## Sponsors
248
267
 
249
268
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -8,16 +8,5 @@
8
8
  "declaration": true,
9
9
  "declarationDir": "./lib/types"
10
10
  },
11
- "exclude": [
12
- "node_modules",
13
- "test",
14
- "lib",
15
- "benchmark",
16
- "coverage",
17
- "spec",
18
- "**/*.benchmark.ts",
19
- "**/*.spec.ts",
20
- "keys",
21
- "jest.config.js"
22
- ]
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
23
12
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,qBAAqB,CAAC;AAC7C,QAAA,wBAAwB,GAAG,yBAAyB,CAAC","sourcesContent":["export const STRIPE_WEBHOOK_EVENT = \"strip_webhook_event\";\nexport const STRIPE_WEBHOOK_SIGNATURE = \"strip_webhook_signature\";\n"]}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./StripSettings"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/index.ts"],"names":[],"mappings":";;;AAAA,+DAAgC","sourcesContent":["export * from \"./StripSettings\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAC1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,yBAAyB,CAAC","sourcesContent":["export const STRIPE_WEBHOOK_EVENT = \"strip_webhook_event\";\nexport const STRIPE_WEBHOOK_SIGNATURE = \"strip_webhook_signature\";\n"]}
@@ -1,2 +0,0 @@
1
- export * from "./StripSettings";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./StripSettings\";\n"]}
@@ -1 +0,0 @@
1
- export * from "./StripSettings";