@dereekb/nestjs 13.0.0 → 13.0.1

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