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

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.12",
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,58 @@
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.12",
37
+ "@tsed/di": "7.0.0-beta.12",
38
+ "@tsed/exceptions": "7.0.0-beta.12",
39
+ "@tsed/platform-middlewares": "7.0.0-beta.12",
40
+ "@tsed/platform-params": "7.0.0-beta.12",
41
+ "@tsed/schema": "7.0.0-beta.12",
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.12",
46
+ "@tsed/platform-middlewares": "^7.0.0-beta.12",
47
+ "@tsed/platform-params": "^7.0.0-beta.12",
48
+ "@tsed/schema": "^7.0.0-beta.12",
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/beta/packages/third-parties/stripe",
58
75
  "author": "Romain Lenzotti",
59
- "license": "MIT"
76
+ "license": "MIT",
77
+ "publishConfig": {
78
+ "tag": "beta"
79
+ }
60
80
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
16
 
16
17
  </div>
17
18
 
@@ -32,7 +33,7 @@ A package of Ts.ED framework. See website: https://tsed.io/tutorials/stripe.html
32
33
  ## Feature
33
34
 
34
35
  Currently, `@tsed/stripe` allows you:
35
-
36
+
36
37
  - Configure stripe,
37
38
  - Create webhooks,
38
39
  - Use stripe API.
@@ -50,33 +51,59 @@ Then import `@tsed/stripe` in your Server:
50
51
 
51
52
  ```typescript
52
53
  import {Configuration, PlatformApplication} from "@tsed/common";
53
- import "@tsed/stripe";
54
+ import "@tsed/stripe";
54
55
  import {Stripe} from "stripe";
55
56
 
56
57
  @Configuration({
57
58
  stripe: {
58
59
  apiKey: process.env.STRIPE_SECRET_KEY,
59
60
  webhooks: {
60
- secret: process.env.STRIPE_WEBHOOK_SECRET,
61
+ secret: process.env.STRIPE_WEBHOOK_SECRET
61
62
  },
62
63
  // Stripe options
63
- apiVersion: '2019-08-08',
64
- httpProxy: new ProxyAgent(process.env.http_proxy),
64
+ apiVersion: "2019-08-08",
65
+ httpProxy: new ProxyAgent(process.env.http_proxy)
65
66
  }
66
67
  })
67
68
  export class Server {
68
69
  @Inject()
69
70
  stripe: Stripe;
70
-
71
+
71
72
  $afterInit() {
72
73
  // do something with stripe
73
74
  // this.stripe.customers
74
75
  }
75
76
  }
76
77
  ```
78
+
77
79
  > See Stripe options for more details: https://www.npmjs.com/package/stripe
78
80
 
79
- ## Inject Stripe
81
+ ::: warning
82
+ Stripe needs to validate signature transaction when you received a webhook notification.
83
+ To work properly, you have to remove bodyParser add on `$beforeRoutesInit`.
84
+
85
+ ```diff
86
+ @Configuration({
87
+ + middlewares: [
88
+ + bodyParser.json(),
89
+ + bodyParser.urlencoded({extended: true})
90
+ + ]
91
+ })
92
+ export class Server {
93
+ @Inject()
94
+ protected app: PlatformApplication;
95
+
96
+ $beforeRoutesInit() {
97
+ - this.app
98
+ - .use(bodyParser.json())
99
+ - .use(bodyParser.urlencoded({extended: true}));
100
+ }
101
+ }
102
+ ```
103
+
104
+ ::
105
+
106
+ ## Inject Stripe
80
107
 
81
108
  ```typescript
82
109
  import {Injectable} from "@tsed/di";
@@ -85,15 +112,13 @@ import {Injectable} from "@tsed/di";
85
112
  class MyStripeService {
86
113
  @Inject()
87
114
  stripe: Stripe;
88
-
115
+
89
116
  $onInit() {
90
117
  // do something with stripe
91
- this.stripe.on('request', this.onRequest.bind(this));
92
- }
93
-
94
- protected onRequest(request: any) {
95
-
118
+ this.stripe.on("request", this.onRequest.bind(this));
96
119
  }
120
+
121
+ protected onRequest(request: any) {}
97
122
  }
98
123
  ```
99
124
 
@@ -102,7 +127,7 @@ class MyStripeService {
102
127
  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
128
 
104
129
  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
-
130
+
106
131
  ```typescript
107
132
  import {RawBodyParams, HeaderParams, Controller, Context} from "@tsed/common";
108
133
  import {Stripe} from "stripe";
@@ -111,15 +136,12 @@ import {Stripe} from "stripe";
111
136
  export class StripWebhookCtrl {
112
137
  @Inject()
113
138
  stripe: Stripe;
114
-
139
+
115
140
  @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}
141
+ successPaymentHook(@WebhookEvent() event: Stripe.Event, @Context() ctx: Context) {
142
+ ctx.logger.info({name: "Webhook success", event});
143
+
144
+ return {received: true};
123
145
  }
124
146
  }
125
147
  ```
@@ -133,41 +155,43 @@ import {Stripe} from "stripe";
133
155
  import {PlatformTest} from "@tsed/common";
134
156
  import {StripWebhookCtrl} from "./StripWebhookCtrl";
135
157
 
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)
158
+ describe("StripWebhookCtrl", () => {
159
+ beforeEach(() =>
160
+ PlatformTest.create({
161
+ stripe: {
162
+ apiKey: "fake_api_key",
163
+ webhooks: {
164
+ secret: "whsec_test_secret"
165
+ },
166
+ // Stripe options
167
+ apiVersion: "2019-08-08"
168
+ }
169
+ })
170
+ );
171
+ afterEach(PlatformTest.reset);
148
172
  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})
173
+ const stripe = PlatformTest.get<Stripe>(Stripe);
174
+ const payload = {
175
+ id: "evt_test_webhook",
176
+ object: "event"
177
+ };
178
+ const payloadString = JSON.stringify(payload, null, 2);
179
+
180
+ const header = stripe.webhooks.generateTestHeaderString({
181
+ payload: payloadString,
182
+ secret: "whsec_test_secret"
183
+ });
184
+
185
+ const event = stripe.webhooks.constructEvent(payloadString, header, secret);
186
+ const ctx = PlatformTest.createRequestContext();
187
+
188
+ const ctrl = await PlatformTest.invoke<StripWebhookCtrl>(StripWebhookCtrl);
189
+
190
+ const result = ctrl.successPaymentHook(event, ctx);
191
+
192
+ expect(result).toEqual({received: true});
169
193
  });
170
- })
194
+ });
171
195
  ```
172
196
 
173
197
  With SuperTest:
@@ -180,10 +204,9 @@ import {expect} from "chai";
180
204
  import {Stripe} from "stripe";
181
205
  import SuperTest from "supertest";
182
206
  import {StripeWebhooksCtrl} from "./StripWebhookCtrl";
183
- import {rootDir, Server} from "../Server";
207
+ import {Server} from "../Server";
184
208
 
185
209
  const utils = PlatformTestUtils.create({
186
- rootDir,
187
210
  platform: PlatformExpress,
188
211
  server: Server,
189
212
  logger: {
@@ -193,11 +216,13 @@ const utils = PlatformTestUtils.create({
193
216
 
194
217
  describe("Stripe", () => {
195
218
  let request: SuperTest.SuperTest<SuperTest.Test>;
196
- beforeEach(utils.bootstrap({
197
- mount: {
198
- "/rest": [StripWebhookCtrl]
199
- }
200
- }));
219
+ beforeEach(
220
+ utils.bootstrap({
221
+ mount: {
222
+ "/rest": [StripWebhookCtrl]
223
+ }
224
+ })
225
+ );
201
226
  beforeEach(() => {
202
227
  request = SuperTest.agent(PlatformTest.callback());
203
228
  });
@@ -217,33 +242,28 @@ describe("Stripe", () => {
217
242
  secret: "whsec_test_secret"
218
243
  });
219
244
 
220
- const response = await request
221
- .post("/rest/webhooks/callback")
222
- .send(payloadString)
223
- .set("stripe-signature", signature)
224
- .expect(200);
245
+ const response = await request.post("/rest/webhooks/callback").send(payloadString).set("stripe-signature", signature).expect(200);
225
246
 
226
247
  expect(response.body).to.deep.eq({
227
- "event": payload,
228
- "received": true
248
+ event: payload,
249
+ received: true
229
250
  });
230
251
  });
231
252
  });
232
253
  ```
233
254
 
234
255
  ## Contributors
256
+
235
257
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
236
258
 
237
259
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
238
260
 
239
-
240
261
  ## Backers
241
262
 
242
263
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
243
264
 
244
265
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
245
266
 
246
-
247
267
  ## Sponsors
248
268
 
249
269
  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";