@pristine-ts/stripe 0.0.188 → 0.0.192

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.
Files changed (26) hide show
  1. package/dist/lib/cjs/clients/stripe.client.js +10 -0
  2. package/dist/lib/cjs/clients/stripe.client.js.map +1 -1
  3. package/dist/lib/cjs/enums/stripe-event-type.enum.js +12 -0
  4. package/dist/lib/cjs/enums/stripe-event-type.enum.js.map +1 -1
  5. package/dist/lib/cjs/errors/stripe-authentication.error.js +3 -0
  6. package/dist/lib/cjs/errors/stripe-authentication.error.js.map +1 -1
  7. package/dist/lib/cjs/managers/stripe-webhooks.manager.js +15 -2
  8. package/dist/lib/cjs/managers/stripe-webhooks.manager.js.map +1 -1
  9. package/dist/lib/cjs/stripe.module.js +3 -0
  10. package/dist/lib/cjs/stripe.module.js.map +1 -1
  11. package/dist/lib/esm/clients/stripe.client.js +10 -0
  12. package/dist/lib/esm/clients/stripe.client.js.map +1 -1
  13. package/dist/lib/esm/enums/stripe-event-type.enum.js +12 -0
  14. package/dist/lib/esm/enums/stripe-event-type.enum.js.map +1 -1
  15. package/dist/lib/esm/errors/stripe-authentication.error.js +3 -0
  16. package/dist/lib/esm/errors/stripe-authentication.error.js.map +1 -1
  17. package/dist/lib/esm/managers/stripe-webhooks.manager.js +15 -2
  18. package/dist/lib/esm/managers/stripe-webhooks.manager.js.map +1 -1
  19. package/dist/lib/esm/stripe.module.js +3 -0
  20. package/dist/lib/esm/stripe.module.js.map +1 -1
  21. package/dist/types/clients/stripe.client.d.ts +14 -0
  22. package/dist/types/enums/stripe-event-type.enum.d.ts +12 -0
  23. package/dist/types/errors/stripe-authentication.error.d.ts +3 -0
  24. package/dist/types/interfaces/stripe-client.interface.d.ts +3 -0
  25. package/dist/types/managers/stripe-webhooks.manager.d.ts +11 -2
  26. package/package.json +8 -7
@@ -30,7 +30,17 @@ const common_1 = require("@pristine-ts/common");
30
30
  const stripe_authentication_error_1 = require("../errors/stripe-authentication.error");
31
31
  const stripe_module_keyname_1 = require("../stripe.module.keyname");
32
32
  const stripe_1 = __importDefault(require("stripe"));
33
+ /**
34
+ * The client to use to interact with Stripe. It is a wrapper around the Stripe library.
35
+ * It is tagged so it can be injected using StripeClientInterface.
36
+ */
33
37
  let StripeClient = class StripeClient {
38
+ /**
39
+ * The client to use to interact with Stripe. It is a wrapper around the Stripe library.
40
+ * It is tagged so it can be injected using StripeClientInterface.
41
+ * @param logHandler The log handler to output logs.
42
+ * @param stripeApiKey The api key to use when contacting Stripe.
43
+ */
34
44
  constructor(logHandler, stripeApiKey) {
35
45
  this.logHandler = logHandler;
36
46
  this.stripeApiKey = stripeApiKey;
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.client.js","sourceRoot":"","sources":["../../../../src/clients/stripe.client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA4C;AAE5C,gDAAwC;AAExC,uFAAgF;AAChF,oEAA6D;AAC7D,oDAA4B;AAK5B,IAAa,YAAY,GAAzB,MAAa,YAAY;IAIrB,YACoD,UAA+B,EACb,YAAoB;QADtC,eAAU,GAAV,UAAU,CAAqB;QACb,iBAAY,GAAZ,YAAY,CAAQ;IAE1F,CAAC;IAED;;OAEG;IACH,eAAe;;QACX,OAAO,IAAI,CAAC,MAAM,GAAG,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,gBAAM,CAAC,IAAI,CAAC,YAAY,EAAE;YAC9D,UAAU,EAAE,YAAY;SAC3B,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACG,eAAe,CAAC,OAAgB,EAAE,2BAAmC;;YACvE,IAAG,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;gBACzD,MAAM,IAAI,uDAAyB,CAAC,GAAG,EAAE,sCAAsC,CAAC,CAAC;aACpF;YAED,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAk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E,IAAG,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;gBACzD,MAAM,IAAI,uDAAyB,CAAC,GAAG,EAAE,sCAAsC,CAAC,CAAC;aACpF;YAED,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;YAE5D,IAAI;gBACA,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,EAAE,2BAA2B,CAAC,CAAC;aACxH;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,6BAA6B,EAAE,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAC,EAAE,2CAAmB,CAAC,CAAC;gBACjG,MAAM,IAAI,uDAAyB,CAAC,GAAG,EAAE,0CAA0C,CAAC,CAAC;aACxF;QACL,CAAC;KAAA;CACJ,CAAA;AAhDY,YAAY;IAFxB,YAAG,CAAC,uBAAuB,CAAC;IAC5B,qBAAU,EAAE;IAgBJ,WAAA,iBAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,iBAAM,CAAC,IAAI,2CAAmB,gBAAgB,CAAC,CAAA;;GAhB3C,YAAY,CAgDxB;AAhDY,oCAAY"}
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StripeEventTypeEnum = void 0;
4
+ /**
5
+ * The event types that we handle from Stripe.
6
+ */
4
7
  var StripeEventTypeEnum;
5
8
  (function (StripeEventTypeEnum) {
9
+ /**
10
+ * When a subscription was created.
11
+ */
6
12
  StripeEventTypeEnum["StripeSubscriptionCreated"] = "STRIPE_SUBSCRIPTION_CREATED";
13
+ /**
14
+ * When a subscription was updated.
15
+ */
7
16
  StripeEventTypeEnum["StripeSubscriptionUpdated"] = "STRIPE_SUBSCRIPTION_UPDATED";
17
+ /**
18
+ * When a subscription was deleted.
19
+ */
8
20
  StripeEventTypeEnum["StripeSubscriptionDeleted"] = "STRIPE_SUBSCRIPTION_DELETED";
9
21
  })(StripeEventTypeEnum = exports.StripeEventTypeEnum || (exports.StripeEventTypeEnum = {}));
10
22
  //# sourceMappingURL=stripe-event-type.enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stripe-event-type.enum.js","sourceRoot":"","sources":["../../../../src/enums/stripe-event-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,gFAAyD,CAAA;IACzD,gFAAyD,CAAA;IACzD,gFAAyD,CAAA;AAC7D,CAAC,EAJW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAI9B"}
1
+ {"version":3,"file":"stripe-event-type.enum.js","sourceRoot":"","sources":["../../../../src/enums/stripe-event-type.enum.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,mBAeX;AAfD,WAAY,mBAAmB;IAC3B;;OAEG;IACH,gFAAyD,CAAA;IAEzD;;OAEG;IACH,gFAAyD,CAAA;IAEzD;;OAEG;IACH,gFAAyD,CAAA;AAC7D,CAAC,EAfW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAe9B"}
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StripeAuthenticationError = void 0;
4
4
  const networking_1 = require("@pristine-ts/networking");
5
+ /**
6
+ * This Error represents an error when authenticating with Stripe.
7
+ */
5
8
  class StripeAuthenticationError extends networking_1.HttpError {
6
9
  constructor(httpStatus, message, errors) {
7
10
  super(httpStatus, message, errors);
@@ -1 +1 @@
1
- {"version":3,"file":"stripe-authentication.error.js","sourceRoot":"","sources":["../../../../src/errors/stripe-authentication.error.ts"],"names":[],"mappings":";;;AAAA,wDAAkD;AAElD,MAAa,yBAA0B,SAAQ,sBAAS;IACpD,YAA4B,UAAkB,EAAW,OAAe,EAAW,MAA0B;QACzG,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QADX,eAAU,GAAV,UAAU,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAoB;QAGzG,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACJ;AATD,8DASC"}
1
+ {"version":3,"file":"stripe-authentication.error.js","sourceRoot":"","sources":["../../../../src/errors/stripe-authentication.error.ts"],"names":[],"mappings":";;;AAAA,wDAAkD;AAElD;;GAEG;AACH,MAAa,yBAA0B,SAAQ,sBAAS;IACpD,YAA4B,UAAkB,EAAW,OAAe,EAAW,MAA0B;QACzG,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QADX,eAAU,GAAV,UAAU,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAoB;QAGzG,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACJ;AATD,8DASC"}
@@ -28,7 +28,16 @@ const core_1 = require("@pristine-ts/core");
28
28
  const stripe_event_type_enum_1 = require("../enums/stripe-event-type.enum");
29
29
  const stripe_client_1 = require("../clients/stripe.client");
30
30
  const stripe_module_keyname_1 = require("../stripe.module.keyname");
31
+ /**
32
+ * The StripeWebhooksManager handles webhooks calls from Stripe and transforms those into Pristine Events.
33
+ */
31
34
  let StripeWebhooksManager = StripeWebhooksManager_1 = class StripeWebhooksManager {
35
+ /**
36
+ * The StripeWebhooksManager handles webhooks calls from Stripe and transforms those into Pristine Events.
37
+ * @param eventDispatcher The event dispatcher to dispatch Pristine Events once webhook calls from Stripe are parsed.
38
+ * @param stripeClient The Stripe client.
39
+ * @param logHandler The log handler to output logs.
40
+ */
32
41
  constructor(eventDispatcher, stripeClient, logHandler) {
33
42
  this.eventDispatcher = eventDispatcher;
34
43
  this.stripeClient = stripeClient;
@@ -36,18 +45,21 @@ let StripeWebhooksManager = StripeWebhooksManager_1 = class StripeWebhooksManage
36
45
  }
37
46
  /**
38
47
  * Verifies the signature and dispatches an event based on the webhook request received from Stripe.
39
- * @param request
40
- * @param stripeSigningEndpointSecret
48
+ * @param request The webhook request received from Stripe
49
+ * @param stripeSigningEndpointSecret The Stripe signing endpoint secret with which the webhook request is signed.
41
50
  */
42
51
  emitSubscriptionEvent(request, stripeSigningEndpointSecret) {
43
52
  return __awaiter(this, void 0, void 0, function* () {
53
+ // Verify the signature of the stripe webhook request.
44
54
  const event = yield this.stripeClient.verifySignature(request, stripeSigningEndpointSecret);
55
+ // For the moment we only handle subscription events.
45
56
  if (!event.type.startsWith('customer.subscription')) {
46
57
  this.logHandler.error("Stripe event is not a subscription", { event, className: StripeWebhooksManager_1.name }, stripe_module_keyname_1.StripeModuleKeyname);
47
58
  throw new Error("Event is not a subscription");
48
59
  }
49
60
  const stripeSubscription = event.data.object;
50
61
  let type;
62
+ // Create the appropriate event type
51
63
  switch (event.type) {
52
64
  case "customer.subscription.created":
53
65
  type = stripe_event_type_enum_1.StripeEventTypeEnum.StripeSubscriptionCreated;
@@ -63,6 +75,7 @@ let StripeWebhooksManager = StripeWebhooksManager_1 = class StripeWebhooksManage
63
75
  return Promise.resolve();
64
76
  }
65
77
  const parsedEvent = new core_1.Event(type, stripeSubscription);
78
+ // Dispatch the event.
66
79
  yield this.eventDispatcher.dispatch(parsedEvent);
67
80
  });
68
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stripe-webhooks.manager.js","sourceRoot":"","sources":["../../../../src/managers/stripe-webhooks.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA4C;AAG5C,4CAAyD;AACzD,4EAAoE;AACpE,4DAAsD;A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C,IAAI,CAAC,MAA6B,CAAC;YAEzF,IAAI,IAA0B,CAAC;YAE/B,oCAAoC;YACpC,QAAQ,KAAK,CAAC,IAAI,EAAE;gBAChB,KAAK,+BAA+B;oBAChC,IAAI,GAAG,4CAAmB,CAAC,yBAAyB,CAAA;oBACpD,MAAM;gBACV,KAAK,+BAA+B;oBAChC,IAAI,GAAG,4CAAmB,CAAC,yBAAyB,CAAA;oBACpD,MAAM;gBACV,KAAK,+BAA+B;oBAChC,IAAI,GAAG,4CAAmB,CAAC,yBAAyB,CAAA;oBACpD,MAAM;gBACV;oBACI,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,kCAAkC,EAAE,EAAC,KAAK,EAAE,SAAS,EAAE,uBAAqB,CAAC,IAAI,EAAC,EAAE,2CAAmB,CAAC,CAAC;oBACrI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;aAChC;YAED,MAAM,WAAW,GAAG,IAAI,YAAK,CAAC,IAAK,EAAE,kBAAkB,CAAC,CAAA;YAExD,sBAAsB;YACtB,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QACpD,CAAC;KAAA;CACJ,CAAA;AAtDY,qBAAqB;IADjC,qBAAU,EAAE;IAYJ,WAAA,iBAAM,CAAC,qBAAqB,CAAC,CAAA;qCAFI,sBAAe;QAClB,4BAAY;GAVtC,qBAAqB,CAsDjC;AAtDY,sDAAqB"}
@@ -22,6 +22,9 @@ __exportStar(require("./stripe.module.keyname"), exports);
22
22
  exports.StripeModule = {
23
23
  keyname: stripe_module_keyname_1.StripeModuleKeyname,
24
24
  configurationDefinitions: [
25
+ /**
26
+ * The api key to use when contacting Stripe.
27
+ */
25
28
  {
26
29
  parameterName: stripe_module_keyname_1.StripeModuleKeyname + ".stripeApiKey",
27
30
  isRequired: true,
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.module.js","sourceRoot":"","sources":["../../../src/stripe.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,mEAA4D;AAC5D,wDAAyD;AAEzD,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,0DAAwC;AACxC,sDAAoC;AACpC,0DAAwC;AAE3B,QAAA,YAAY,GAAoB;IACzC,OAAO,EAAE,2CAAmB;IAC5B,wBAAwB,EAAE;QACtB;YACI,aAAa,EAAE,2CAAmB,GAAG,eAAe;YACpD,UAAU,EAAE,IAAI;SACnB;KACJ;IACD,aAAa,EAAE;QACX,6BAAgB;KACnB;CACJ,CAAA"}
1
+ {"version":3,"file":"stripe.module.js","sourceRoot":"","sources":["../../../src/stripe.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,mEAA4D;AAC5D,wDAAyD;AAEzD,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,0DAAwC;AACxC,sDAAoC;AACpC,0DAAwC;AAE3B,QAAA,YAAY,GAAoB;IACzC,OAAO,EAAE,2CAAmB;IAC5B,wBAAwB,EAAE;QACtB;;WAEG;QACH;YACI,aAAa,EAAE,2CAAmB,GAAG,eAAe;YACpD,UAAU,EAAE,IAAI;SACnB;KACJ;IACD,aAAa,EAAE;QACX,6BAAgB;KACnB;CACJ,CAAA"}
@@ -24,7 +24,17 @@ import { tag } from "@pristine-ts/common";
24
24
  import { StripeAuthenticationError } from "../errors/stripe-authentication.error";
25
25
  import { StripeModuleKeyname } from "../stripe.module.keyname";
26
26
  import Stripe from "stripe";
27
+ /**
28
+ * The client to use to interact with Stripe. It is a wrapper around the Stripe library.
29
+ * It is tagged so it can be injected using StripeClientInterface.
30
+ */
27
31
  let StripeClient = class StripeClient {
32
+ /**
33
+ * The client to use to interact with Stripe. It is a wrapper around the Stripe library.
34
+ * It is tagged so it can be injected using StripeClientInterface.
35
+ * @param logHandler The log handler to output logs.
36
+ * @param stripeApiKey The api key to use when contacting Stripe.
37
+ */
28
38
  constructor(logHandler, stripeApiKey) {
29
39
  this.logHandler = logHandler;
30
40
  this.stripeApiKey = stripeApiKey;
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AAE;gBACzD,MAAM,IAAI,yBAAyB,CAAC,GAAG,EAAE,sCAAsC,CAAC,CAAC;aACpF;YAED,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;YAE5D,IAAI;gBACA,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,EAAE,2BAA2B,CAAC,CAAC;aACxH;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,6BAA6B,EAAE,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAC,EAAE,mBAAmB,CAAC,CAAC;gBACjG,MAAM,IAAI,yBAAyB,CAAC,GAAG,EAAE,0CAA0C,CAAC,CAAC;aACxF;QACL,CAAC;KAAA;CACJ,CAAA;AAhDY,YAAY;IAFxB,GAAG,CAAC,uBAAuB,CAAC;IAC5B,UAAU,EAAE;IAgBJ,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,IAAI,mBAAmB,gBAAgB,CAAC,CAAA;;GAhB3C,YAAY,CAgDxB;SAhDY,YAAY"}
@@ -1,7 +1,19 @@
1
+ /**
2
+ * The event types that we handle from Stripe.
3
+ */
1
4
  export var StripeEventTypeEnum;
2
5
  (function (StripeEventTypeEnum) {
6
+ /**
7
+ * When a subscription was created.
8
+ */
3
9
  StripeEventTypeEnum["StripeSubscriptionCreated"] = "STRIPE_SUBSCRIPTION_CREATED";
10
+ /**
11
+ * When a subscription was updated.
12
+ */
4
13
  StripeEventTypeEnum["StripeSubscriptionUpdated"] = "STRIPE_SUBSCRIPTION_UPDATED";
14
+ /**
15
+ * When a subscription was deleted.
16
+ */
5
17
  StripeEventTypeEnum["StripeSubscriptionDeleted"] = "STRIPE_SUBSCRIPTION_DELETED";
6
18
  })(StripeEventTypeEnum || (StripeEventTypeEnum = {}));
7
19
  //# sourceMappingURL=stripe-event-type.enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stripe-event-type.enum.js","sourceRoot":"","sources":["../../../../src/enums/stripe-event-type.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,gFAAyD,CAAA;IACzD,gFAAyD,CAAA;IACzD,gFAAyD,CAAA;AAC7D,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B"}
1
+ {"version":3,"file":"stripe-event-type.enum.js","sourceRoot":"","sources":["../../../../src/enums/stripe-event-type.enum.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAeX;AAfD,WAAY,mBAAmB;IAC3B;;OAEG;IACH,gFAAyD,CAAA;IAEzD;;OAEG;IACH,gFAAyD,CAAA;IAEzD;;OAEG;IACH,gFAAyD,CAAA;AAC7D,CAAC,EAfW,mBAAmB,KAAnB,mBAAmB,QAe9B"}
@@ -1,4 +1,7 @@
1
1
  import { HttpError } from "@pristine-ts/networking";
2
+ /**
3
+ * This Error represents an error when authenticating with Stripe.
4
+ */
2
5
  export class StripeAuthenticationError extends HttpError {
3
6
  constructor(httpStatus, message, errors) {
4
7
  super(httpStatus, message, errors);
@@ -1 +1 @@
1
- {"version":3,"file":"stripe-authentication.error.js","sourceRoot":"","sources":["../../../../src/errors/stripe-authentication.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAElD,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IACpD,YAA4B,UAAkB,EAAW,OAAe,EAAW,MAA0B;QACzG,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QADX,eAAU,GAAV,UAAU,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAoB;QAGzG,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACJ"}
1
+ {"version":3,"file":"stripe-authentication.error.js","sourceRoot":"","sources":["../../../../src/errors/stripe-authentication.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IACpD,YAA4B,UAAkB,EAAW,OAAe,EAAW,MAA0B;QACzG,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QADX,eAAU,GAAV,UAAU,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAoB;QAGzG,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACJ"}
@@ -25,7 +25,16 @@ import { Event, EventDispatcher } from "@pristine-ts/core";
25
25
  import { StripeEventTypeEnum } from "../enums/stripe-event-type.enum";
26
26
  import { StripeClient } from "../clients/stripe.client";
27
27
  import { StripeModuleKeyname } from "../stripe.module.keyname";
28
+ /**
29
+ * The StripeWebhooksManager handles webhooks calls from Stripe and transforms those into Pristine Events.
30
+ */
28
31
  let StripeWebhooksManager = StripeWebhooksManager_1 = class StripeWebhooksManager {
32
+ /**
33
+ * The StripeWebhooksManager handles webhooks calls from Stripe and transforms those into Pristine Events.
34
+ * @param eventDispatcher The event dispatcher to dispatch Pristine Events once webhook calls from Stripe are parsed.
35
+ * @param stripeClient The Stripe client.
36
+ * @param logHandler The log handler to output logs.
37
+ */
29
38
  constructor(eventDispatcher, stripeClient, logHandler) {
30
39
  this.eventDispatcher = eventDispatcher;
31
40
  this.stripeClient = stripeClient;
@@ -33,18 +42,21 @@ let StripeWebhooksManager = StripeWebhooksManager_1 = class StripeWebhooksManage
33
42
  }
34
43
  /**
35
44
  * Verifies the signature and dispatches an event based on the webhook request received from Stripe.
36
- * @param request
37
- * @param stripeSigningEndpointSecret
45
+ * @param request The webhook request received from Stripe
46
+ * @param stripeSigningEndpointSecret The Stripe signing endpoint secret with which the webhook request is signed.
38
47
  */
39
48
  emitSubscriptionEvent(request, stripeSigningEndpointSecret) {
40
49
  return __awaiter(this, void 0, void 0, function* () {
50
+ // Verify the signature of the stripe webhook request.
41
51
  const event = yield this.stripeClient.verifySignature(request, stripeSigningEndpointSecret);
52
+ // For the moment we only handle subscription events.
42
53
  if (!event.type.startsWith('customer.subscription')) {
43
54
  this.logHandler.error("Stripe event is not a subscription", { event, className: StripeWebhooksManager_1.name }, StripeModuleKeyname);
44
55
  throw new Error("Event is not a subscription");
45
56
  }
46
57
  const stripeSubscription = event.data.object;
47
58
  let type;
59
+ // Create the appropriate event type
48
60
  switch (event.type) {
49
61
  case "customer.subscription.created":
50
62
  type = StripeEventTypeEnum.StripeSubscriptionCreated;
@@ -60,6 +72,7 @@ let StripeWebhooksManager = StripeWebhooksManager_1 = class StripeWebhooksManage
60
72
  return Promise.resolve();
61
73
  }
62
74
  const parsedEvent = new Event(type, stripeSubscription);
75
+ // Dispatch the event.
63
76
  yield this.eventDispatcher.dispatch(parsedEvent);
64
77
  });
65
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stripe-webhooks.manager.js","sourceRoot":"","sources":["../../../../src/managers/stripe-webhooks.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAC,KAAK,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAI7D,IAAa,qBAAqB,6BAAl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AAS,EAAE,uBAAqB,CAAC,IAAI,EAAC,EAAE,mBAAmB,CAAC,CAAC;gBACjI,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;aAClD;YAED,MAAM,kBAAkB,GAAwB,KAAK,CAAC,IAAI,CAAC,MAA6B,CAAC;YAEzF,IAAI,IAA0B,CAAC;YAE/B,oCAAoC;YACpC,QAAQ,KAAK,CAAC,IAAI,EAAE;gBAChB,KAAK,+BAA+B;oBAChC,IAAI,GAAG,mBAAmB,CAAC,yBAAyB,CAAA;oBACpD,MAAM;gBACV,KAAK,+BAA+B;oBAChC,IAAI,GAAG,mBAAmB,CAAC,yBAAyB,CAAA;oBACpD,MAAM;gBACV,KAAK,+BAA+B;oBAChC,IAAI,GAAG,mBAAmB,CAAC,yBAAyB,CAAA;oBACpD,MAAM;gBACV;oBACI,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,kCAAkC,EAAE,EAAC,KAAK,EAAE,SAAS,EAAE,uBAAqB,CAAC,IAAI,EAAC,EAAE,mBAAmB,CAAC,CAAC;oBACrI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;aAChC;YAED,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,IAAK,EAAE,kBAAkB,CAAC,CAAA;YAExD,sBAAsB;YACtB,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QACpD,CAAC;KAAA;CACJ,CAAA;AAtDY,qBAAqB;IADjC,UAAU,EAAE;IAYJ,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;qCAFI,eAAe;QAClB,YAAY;GAVtC,qBAAqB,CAsDjC;SAtDY,qBAAqB"}
@@ -9,6 +9,9 @@ export * from "./stripe.module.keyname";
9
9
  export const StripeModule = {
10
10
  keyname: StripeModuleKeyname,
11
11
  configurationDefinitions: [
12
+ /**
13
+ * The api key to use when contacting Stripe.
14
+ */
12
15
  {
13
16
  parameterName: StripeModuleKeyname + ".stripeApiKey",
14
17
  isRequired: true,
@@ -1 +1 @@
1
- {"version":3,"file":"stripe.module.js","sourceRoot":"","sources":["../../../src/stripe.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAC,MAAM,yBAAyB,CAAC;AAEzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AAExC,MAAM,CAAC,MAAM,YAAY,GAAoB;IACzC,OAAO,EAAE,mBAAmB;IAC5B,wBAAwB,EAAE;QACtB;YACI,aAAa,EAAE,mBAAmB,GAAG,eAAe;YACpD,UAAU,EAAE,IAAI;SACnB;KACJ;IACD,aAAa,EAAE;QACX,gBAAgB;KACnB;CACJ,CAAA"}
1
+ {"version":3,"file":"stripe.module.js","sourceRoot":"","sources":["../../../src/stripe.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAC,MAAM,yBAAyB,CAAC;AAEzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AAExC,MAAM,CAAC,MAAM,YAAY,GAAoB;IACzC,OAAO,EAAE,mBAAmB;IAC5B,wBAAwB,EAAE;QACtB;;WAEG;QACH;YACI,aAAa,EAAE,mBAAmB,GAAG,eAAe;YACpD,UAAU,EAAE,IAAI;SACnB;KACJ;IACD,aAAa,EAAE;QACX,gBAAgB;KACnB;CACJ,CAAA"}
@@ -2,10 +2,24 @@ import { LogHandlerInterface } from "@pristine-ts/logging";
2
2
  import { StripeClientInterface } from "../interfaces/stripe-client.interface";
3
3
  import Stripe from "stripe";
4
4
  import { Request } from "@pristine-ts/common";
5
+ /**
6
+ * The client to use to interact with Stripe. It is a wrapper around the Stripe library.
7
+ * It is tagged so it can be injected using StripeClientInterface.
8
+ */
5
9
  export declare class StripeClient implements StripeClientInterface {
6
10
  private readonly logHandler;
7
11
  private readonly stripeApiKey;
12
+ /**
13
+ * The client from the Stripe library.
14
+ * @private
15
+ */
8
16
  private client?;
17
+ /**
18
+ * The client to use to interact with Stripe. It is a wrapper around the Stripe library.
19
+ * It is tagged so it can be injected using StripeClientInterface.
20
+ * @param logHandler The log handler to output logs.
21
+ * @param stripeApiKey The api key to use when contacting Stripe.
22
+ */
9
23
  constructor(logHandler: LogHandlerInterface, stripeApiKey: string);
10
24
  /**
11
25
  * Returns the Stripe client of the Stripe library with the api version '2020-08-27'
@@ -1,5 +1,17 @@
1
+ /**
2
+ * The event types that we handle from Stripe.
3
+ */
1
4
  export declare enum StripeEventTypeEnum {
5
+ /**
6
+ * When a subscription was created.
7
+ */
2
8
  StripeSubscriptionCreated = "STRIPE_SUBSCRIPTION_CREATED",
9
+ /**
10
+ * When a subscription was updated.
11
+ */
3
12
  StripeSubscriptionUpdated = "STRIPE_SUBSCRIPTION_UPDATED",
13
+ /**
14
+ * When a subscription was deleted.
15
+ */
4
16
  StripeSubscriptionDeleted = "STRIPE_SUBSCRIPTION_DELETED"
5
17
  }
@@ -1,4 +1,7 @@
1
1
  import { HttpError } from "@pristine-ts/networking";
2
+ /**
3
+ * This Error represents an error when authenticating with Stripe.
4
+ */
2
5
  export declare class StripeAuthenticationError extends HttpError {
3
6
  readonly httpStatus: number;
4
7
  readonly message: string;
@@ -1,5 +1,8 @@
1
1
  import Stripe from "stripe";
2
2
  import { Request } from "@pristine-ts/common";
3
+ /**
4
+ * This interface represents the Stripe client and can be used to inject it. It facilitates mocking and testing.
5
+ */
3
6
  export interface StripeClientInterface {
4
7
  /**
5
8
  * Returns the Stripe client of the Stripe library with the api version '2020-08-27'
@@ -2,15 +2,24 @@ import { LogHandlerInterface } from "@pristine-ts/logging";
2
2
  import { EventDispatcher } from "@pristine-ts/core";
3
3
  import { StripeClient } from "../clients/stripe.client";
4
4
  import { Request } from "@pristine-ts/common";
5
+ /**
6
+ * The StripeWebhooksManager handles webhooks calls from Stripe and transforms those into Pristine Events.
7
+ */
5
8
  export declare class StripeWebhooksManager {
6
9
  private readonly eventDispatcher;
7
10
  private readonly stripeClient;
8
11
  private readonly logHandler;
12
+ /**
13
+ * The StripeWebhooksManager handles webhooks calls from Stripe and transforms those into Pristine Events.
14
+ * @param eventDispatcher The event dispatcher to dispatch Pristine Events once webhook calls from Stripe are parsed.
15
+ * @param stripeClient The Stripe client.
16
+ * @param logHandler The log handler to output logs.
17
+ */
9
18
  constructor(eventDispatcher: EventDispatcher, stripeClient: StripeClient, logHandler: LogHandlerInterface);
10
19
  /**
11
20
  * Verifies the signature and dispatches an event based on the webhook request received from Stripe.
12
- * @param request
13
- * @param stripeSigningEndpointSecret
21
+ * @param request The webhook request received from Stripe
22
+ * @param stripeSigningEndpointSecret The Stripe signing endpoint secret with which the webhook request is signed.
14
23
  */
15
24
  emitSubscriptionEvent(request: Request, stripeSigningEndpointSecret: string): Promise<void>;
16
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pristine-ts/stripe",
3
- "version": "0.0.188",
3
+ "version": "0.0.192",
4
4
  "description": "",
5
5
  "module": "dist/lib/esm/stripe.module.js",
6
6
  "main": "dist/lib/cjs/stripe.module.js",
@@ -8,13 +8,14 @@
8
8
  "scripts": {
9
9
  "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
10
10
  "prepublish": "npm run build",
11
- "test": "jest"
11
+ "test": "jest",
12
+ "test:cov": "jest --coverage"
12
13
  },
13
14
  "dependencies": {
14
- "@pristine-ts/common": "^0.0.188",
15
- "@pristine-ts/core": "^0.0.188",
16
- "@pristine-ts/logging": "^0.0.188",
17
- "@pristine-ts/networking": "^0.0.188",
15
+ "@pristine-ts/common": "^0.0.192",
16
+ "@pristine-ts/core": "^0.0.192",
17
+ "@pristine-ts/logging": "^0.0.192",
18
+ "@pristine-ts/networking": "^0.0.192",
18
19
  "stripe": "^8.161.0"
19
20
  },
20
21
  "files": [
@@ -59,5 +60,5 @@
59
60
  "src/*.{js,ts}"
60
61
  ]
61
62
  },
62
- "gitHead": "d9eeadc798c023e887715ed55151f3a439eec442"
63
+ "gitHead": "3f78bc1ae1441441fb9b57fd98b9fd6667a4d28a"
63
64
  }