@dereekb/nestjs 13.0.0 → 13.0.2

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.
@@ -6,20 +6,20 @@ import { ConfigService, ConfigModule } from '@nestjs/config';
6
6
 
7
7
  var StripeWebhookEventType;
8
8
  (function (StripeWebhookEventType) {
9
- StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END"] = "customer.subscription.trial_will_end";
10
- StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_DELETED"] = "customer.subscription.deleted";
11
- StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_CREATED"] = "customer.subscription.created";
12
- StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_UPDATED"] = "customer.subscription.updated";
13
- StripeWebhookEventType["CHECKOUT_SESSION_COMPLETED"] = "checkout.session.completed";
14
- StripeWebhookEventType["CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED"] = "checkout.session.async_payment_failed";
15
- StripeWebhookEventType["CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED"] = "checkout.session.async_payment_suceeded";
16
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_ABORTED"] = "subscription_schedule.aborted";
17
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_CANCELLED"] = "subscription_schedule.canceled";
18
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_COMPLETED"] = "subscription_schedule.completed";
19
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_CREATED"] = "subscription_schedule.created";
20
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_EXPIRING"] = "subscription_schedule.expiring";
21
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_RELEASED"] = "subscription_schedule.released";
22
- StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_UPDATED"] = "subscription_schedule.updated";
9
+ StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END"] = "customer.subscription.trial_will_end";
10
+ StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_DELETED"] = "customer.subscription.deleted";
11
+ StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_CREATED"] = "customer.subscription.created";
12
+ StripeWebhookEventType["CUSTOMER_SUBSCRIPTION_UPDATED"] = "customer.subscription.updated";
13
+ StripeWebhookEventType["CHECKOUT_SESSION_COMPLETED"] = "checkout.session.completed";
14
+ StripeWebhookEventType["CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED"] = "checkout.session.async_payment_failed";
15
+ StripeWebhookEventType["CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED"] = "checkout.session.async_payment_suceeded";
16
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_ABORTED"] = "subscription_schedule.aborted";
17
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_CANCELLED"] = "subscription_schedule.canceled";
18
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_COMPLETED"] = "subscription_schedule.completed";
19
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_CREATED"] = "subscription_schedule.created";
20
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_EXPIRING"] = "subscription_schedule.expiring";
21
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_RELEASED"] = "subscription_schedule.released";
22
+ StripeWebhookEventType["SUBSCRIPTION_SCHEDULE_UPDATED"] = "subscription_schedule.updated";
23
23
  })(StripeWebhookEventType || (StripeWebhookEventType = {}));
24
24
  /**
25
25
  * Creates a StripeWebhookEvent and treats the data as the input type.
@@ -28,40 +28,40 @@ var StripeWebhookEventType;
28
28
  * @returns
29
29
  */
30
30
  function stripeWebhookEvent(event) {
31
- return {
32
- event,
33
- data: event.data.object
34
- };
31
+ return {
32
+ event,
33
+ data: event.data.object
34
+ };
35
35
  }
36
36
  function stripeWebhookEventMapper(mapFn) {
37
- return event => ({
38
- event,
39
- data: mapFn(event.data.object, event)
40
- });
37
+ return (event) => ({
38
+ event,
39
+ data: mapFn(event.data.object, event)
40
+ });
41
41
  }
42
- const stripeEventHandlerFactory = handlerFactory(x => x.type);
42
+ const stripeEventHandlerFactory = handlerFactory((x) => x.type);
43
43
  const stripeEventHandlerConfigurerFactory = handlerConfigurerFactory({
44
- configurerForAccessor: accessor => {
45
- // eslint-disable-next-line
46
- const fnWithKey = handlerMappedSetFunctionFactory(accessor, stripeWebhookEvent);
47
- const configurer = {
48
- ...accessor,
49
- handleCheckoutSessionComplete: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_COMPLETED),
50
- handleCheckoutSessionAsyncPaymentFailed: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED),
51
- handleCheckoutSessionAsyncPaymentSuccess: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED),
52
- handleCustomerSubscriptionCreated: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_CREATED),
53
- handleCustomerSubscriptionUpdated: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_UPDATED),
54
- handleCustomerSubscriptionDeleted: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_DELETED),
55
- handleSubscriptionScheduleAborted: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_ABORTED),
56
- handleSubscriptionScheduleCancelled: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_CANCELLED),
57
- handleSubscriptionScheduleCompleted: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_COMPLETED),
58
- handleSubscriptionScheduleCreated: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_CREATED),
59
- handleSubscriptionScheduleExpiring: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_EXPIRING),
60
- handleSubscriptionScheduleReleased: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_RELEASED),
61
- handleSubscriptionScheduleUpdated: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_UPDATED)
62
- };
63
- return configurer;
64
- }
44
+ configurerForAccessor: (accessor) => {
45
+ // eslint-disable-next-line
46
+ const fnWithKey = handlerMappedSetFunctionFactory(accessor, stripeWebhookEvent);
47
+ const configurer = {
48
+ ...accessor,
49
+ handleCheckoutSessionComplete: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_COMPLETED),
50
+ handleCheckoutSessionAsyncPaymentFailed: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_ASYNC_PAYMENT_FAILED),
51
+ handleCheckoutSessionAsyncPaymentSuccess: fnWithKey(StripeWebhookEventType.CHECKOUT_SESSION_ASYNC_PAYMENT_SUCCEEDED),
52
+ handleCustomerSubscriptionCreated: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_CREATED),
53
+ handleCustomerSubscriptionUpdated: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_UPDATED),
54
+ handleCustomerSubscriptionDeleted: fnWithKey(StripeWebhookEventType.CUSTOMER_SUBSCRIPTION_DELETED),
55
+ handleSubscriptionScheduleAborted: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_ABORTED),
56
+ handleSubscriptionScheduleCancelled: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_CANCELLED),
57
+ handleSubscriptionScheduleCompleted: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_COMPLETED),
58
+ handleSubscriptionScheduleCreated: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_CREATED),
59
+ handleSubscriptionScheduleExpiring: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_EXPIRING),
60
+ handleSubscriptionScheduleReleased: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_RELEASED),
61
+ handleSubscriptionScheduleUpdated: fnWithKey(StripeWebhookEventType.SUBSCRIPTION_SCHEDULE_UPDATED)
62
+ };
63
+ return configurer;
64
+ }
65
65
  });
66
66
 
67
67
  /******************************************************************************
@@ -105,111 +105,141 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
105
105
  * Configuration for StripeService
106
106
  */
107
107
  class StripeServiceConfig {
108
- stripe;
109
- static assertValidConfig(config) {
110
- if (!config.stripe.secret) {
111
- throw new Error('No stripe secret specified.');
112
- } else if (!config.stripe.webhookSecret) {
113
- throw new Error('No stripe webhook secret specified.');
108
+ stripe;
109
+ static assertValidConfig(config) {
110
+ if (!config.stripe.secret) {
111
+ throw new Error('No stripe secret specified.');
112
+ }
113
+ else if (!config.stripe.webhookSecret) {
114
+ throw new Error('No stripe webhook secret specified.');
115
+ }
114
116
  }
115
- }
116
117
  }
117
118
 
118
119
  let StripeApi = class StripeApi {
119
- config;
120
- stripe;
121
- constructor(config) {
122
- this.config = config;
123
- this.stripe = new Stripe(config.stripe.secret, config.stripe.config);
124
- }
125
- // MARK: Event
126
- /**
127
- * Verifies the event and reads the stripe signature from a request.
128
- */
129
- readStripeEventFromWebhookRequest(req, rawBody) {
130
- const signature = req.get('stripe-signature');
131
- if (!signature) {
132
- throw new BadRequestException(`missing stripe-signature`);
120
+ config;
121
+ stripe;
122
+ constructor(config) {
123
+ this.config = config;
124
+ this.stripe = new Stripe(config.stripe.secret, config.stripe.config);
133
125
  }
134
- let event;
135
- try {
136
- event = this.stripe.webhooks.constructEvent(rawBody, signature, this.config.stripe.webhookSecret);
137
- } catch (e) {
138
- throw new BadRequestException(`stripe signature read error: ${e?.message}`);
126
+ // MARK: Event
127
+ /**
128
+ * Verifies the event and reads the stripe signature from a request.
129
+ */
130
+ readStripeEventFromWebhookRequest(req, rawBody) {
131
+ const signature = req.get('stripe-signature');
132
+ if (!signature) {
133
+ throw new BadRequestException(`missing stripe-signature`);
134
+ }
135
+ let event;
136
+ try {
137
+ event = this.stripe.webhooks.constructEvent(rawBody, signature, this.config.stripe.webhookSecret);
138
+ }
139
+ catch (e) {
140
+ throw new BadRequestException(`stripe signature read error: ${e?.message}`);
141
+ }
142
+ return event;
139
143
  }
140
- return event;
141
- }
142
144
  };
143
- StripeApi = __decorate([Injectable(), __param(0, Inject(StripeServiceConfig)), __metadata("design:paramtypes", [StripeServiceConfig])], StripeApi);
145
+ StripeApi = __decorate([
146
+ Injectable(),
147
+ __param(0, Inject(StripeServiceConfig)),
148
+ __metadata("design:paramtypes", [StripeServiceConfig])
149
+ ], StripeApi);
144
150
 
145
151
  /**
146
152
  * Service that makes system changes based on Stripe webhook events.
147
153
  */
148
154
  let StripeWebhookService = class StripeWebhookService {
149
- logger = new Logger('StripeWebhookService');
150
- _stripeApi;
151
- handler = stripeEventHandlerFactory();
152
- configure = stripeEventHandlerConfigurerFactory(this.handler);
153
- constructor(stripeApi) {
154
- this._stripeApi = stripeApi;
155
- }
156
- async updateForWebhook(req, rawBody) {
157
- const event = this._stripeApi.readStripeEventFromWebhookRequest(req, rawBody);
158
- return this.updateForStripeEvent(event);
159
- }
160
- async updateForStripeEvent(event) {
161
- const handled = await this.handler(event);
162
- if (!handled) {
163
- this.logger.warn('Received unexpected/unhandled stripe event: ', event);
155
+ logger = new Logger('StripeWebhookService');
156
+ _stripeApi;
157
+ handler = stripeEventHandlerFactory();
158
+ configure = stripeEventHandlerConfigurerFactory(this.handler);
159
+ constructor(stripeApi) {
160
+ this._stripeApi = stripeApi;
161
+ }
162
+ async updateForWebhook(req, rawBody) {
163
+ const event = this._stripeApi.readStripeEventFromWebhookRequest(req, rawBody);
164
+ return this.updateForStripeEvent(event);
165
+ }
166
+ async updateForStripeEvent(event) {
167
+ const handled = await this.handler(event);
168
+ if (!handled) {
169
+ this.logger.warn('Received unexpected/unhandled stripe event: ', event);
170
+ }
171
+ return handled;
164
172
  }
165
- return handled;
166
- }
167
173
  };
168
- StripeWebhookService = __decorate([Injectable(), __param(0, Inject(StripeApi)), __metadata("design:paramtypes", [StripeApi])], StripeWebhookService);
174
+ StripeWebhookService = __decorate([
175
+ Injectable(),
176
+ __param(0, Inject(StripeApi)),
177
+ __metadata("design:paramtypes", [StripeApi])
178
+ ], StripeWebhookService);
169
179
 
170
180
  let StripeWebhookController = class StripeWebhookController {
171
- _stripeWebhookService;
172
- constructor(stripeWebhookService) {
173
- this._stripeWebhookService = stripeWebhookService;
174
- }
175
- async handleStripeWebhook(req, rawBody) {
176
- await this._stripeWebhookService.updateForWebhook(req, rawBody);
177
- }
181
+ _stripeWebhookService;
182
+ constructor(stripeWebhookService) {
183
+ this._stripeWebhookService = stripeWebhookService;
184
+ }
185
+ async handleStripeWebhook(req, rawBody) {
186
+ await this._stripeWebhookService.updateForWebhook(req, rawBody);
187
+ }
178
188
  };
179
- __decorate([Post(), __param(0, Req()), __param(1, RawBody()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise)], StripeWebhookController.prototype, "handleStripeWebhook", null);
180
- StripeWebhookController = __decorate([Controller('/webhook/stripe'), __param(0, Inject(StripeWebhookService)), __metadata("design:paramtypes", [StripeWebhookService])], StripeWebhookController);
189
+ __decorate([
190
+ Post(),
191
+ __param(0, Req()),
192
+ __param(1, RawBody()),
193
+ __metadata("design:type", Function),
194
+ __metadata("design:paramtypes", [Object, Object]),
195
+ __metadata("design:returntype", Promise)
196
+ ], StripeWebhookController.prototype, "handleStripeWebhook", null);
197
+ StripeWebhookController = __decorate([
198
+ Controller('/webhook/stripe'),
199
+ __param(0, Inject(StripeWebhookService)),
200
+ __metadata("design:paramtypes", [StripeWebhookService])
201
+ ], StripeWebhookController);
181
202
 
182
203
  const STRIPE_DEFAULT_API_VERSION = '2020-08-27';
183
204
  function stripeServiceConfigFactory(configService) {
184
- const config = {
185
- stripe: {
186
- secret: configService.get('STRIPE_SECRET'),
187
- webhookSecret: configService.get('STRIPE_WEBHOOK_SECRET'),
188
- config: {
189
- apiVersion: STRIPE_DEFAULT_API_VERSION
190
- }
191
- }
192
- };
193
- StripeServiceConfig.assertValidConfig(config);
194
- return config;
205
+ const config = {
206
+ stripe: {
207
+ secret: configService.get('STRIPE_SECRET'),
208
+ webhookSecret: configService.get('STRIPE_WEBHOOK_SECRET'),
209
+ config: {
210
+ apiVersion: STRIPE_DEFAULT_API_VERSION
211
+ }
212
+ }
213
+ };
214
+ StripeServiceConfig.assertValidConfig(config);
215
+ return config;
195
216
  }
196
- let StripeModule = class StripeModule {};
197
- StripeModule = __decorate([Module({
198
- imports: [ConfigModule],
199
- providers: [{
200
- provide: StripeServiceConfig,
201
- inject: [ConfigService],
202
- useFactory: stripeServiceConfigFactory
203
- }, StripeApi],
204
- exports: [StripeApi]
205
- })], StripeModule);
217
+ let StripeModule = class StripeModule {
218
+ };
219
+ StripeModule = __decorate([
220
+ Module({
221
+ imports: [ConfigModule],
222
+ providers: [
223
+ {
224
+ provide: StripeServiceConfig,
225
+ inject: [ConfigService],
226
+ useFactory: stripeServiceConfigFactory
227
+ },
228
+ StripeApi
229
+ ],
230
+ exports: [StripeApi]
231
+ })
232
+ ], StripeModule);
206
233
 
207
- let StripeWebhookModule = class StripeWebhookModule {};
208
- StripeWebhookModule = __decorate([Module({
209
- controllers: [StripeWebhookController],
210
- imports: [StripeModule],
211
- exports: [StripeModule, StripeWebhookService],
212
- providers: [StripeWebhookService]
213
- })], StripeWebhookModule);
234
+ let StripeWebhookModule = class StripeWebhookModule {
235
+ };
236
+ StripeWebhookModule = __decorate([
237
+ Module({
238
+ controllers: [StripeWebhookController],
239
+ imports: [StripeModule],
240
+ exports: [StripeModule, StripeWebhookService],
241
+ providers: [StripeWebhookService]
242
+ })
243
+ ], StripeWebhookModule);
214
244
 
215
245
  export { STRIPE_DEFAULT_API_VERSION, StripeApi, StripeModule, StripeServiceConfig, StripeWebhookController, StripeWebhookEventType, StripeWebhookModule, StripeWebhookService, stripeEventHandlerConfigurerFactory, stripeEventHandlerFactory, stripeServiceConfigFactory, stripeWebhookEvent, stripeWebhookEventMapper };
@@ -1,28 +1,27 @@
1
1
  {
2
2
  "name": "@dereekb/nestjs/stripe",
3
- "version": "13.0.0",
4
- "types": "./src/index.d.ts",
5
- "module": "./index.esm.js",
6
- "main": "./index.cjs.js",
3
+ "version": "13.0.2",
4
+ "peerDependencies": {
5
+ "@dereekb/date": "13.0.2",
6
+ "@dereekb/model": "13.0.2",
7
+ "@dereekb/nestjs": "13.0.2",
8
+ "@dereekb/rxjs": "13.0.2",
9
+ "@dereekb/util": "13.0.2",
10
+ "@nestjs/common": "^11.0.0",
11
+ "@nestjs/config": "^4.0.0",
12
+ "express": "^5.0.0",
13
+ "stripe": "^9.1.0"
14
+ },
7
15
  "exports": {
16
+ "./package.json": "./package.json",
8
17
  ".": {
9
- "types": "./src/index.d.ts",
10
- "node": {
11
- "require": "./index.cjs.js"
12
- },
13
- "browser": {
14
- "require": "./index.cjs.js",
15
- "import": "./index.esm.js"
16
- },
18
+ "module": "./index.esm.js",
19
+ "types": "./index.d.ts",
20
+ "import": "./index.cjs.mjs",
17
21
  "default": "./index.cjs.js"
18
22
  }
19
23
  },
20
- "peerDependencies": {
21
- "@dereekb/date": "13.0.0",
22
- "@dereekb/nestjs": "13.0.0",
23
- "@dereekb/model": "13.0.0",
24
- "@dereekb/rxjs": "13.0.0",
25
- "@dereekb/util": "13.0.0",
26
- "core-js": "^3.0.0"
27
- }
24
+ "module": "./index.esm.js",
25
+ "main": "./index.cjs.js",
26
+ "types": "./index.d.ts"
28
27
  }
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;