@carlonicora/nestjs-neo4jsonapi 6.8.0 → 7.0.0
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/dist/common/decorators/cache-invalidate.decorator.d.ts +2 -1
- package/dist/common/decorators/cache-invalidate.decorator.d.ts.map +1 -1
- package/dist/common/decorators/cache-invalidate.decorator.js +23 -3
- package/dist/common/decorators/cache-invalidate.decorator.js.map +1 -1
- package/dist/common/decorators/validate-id.decorator.d.ts +4 -1
- package/dist/common/decorators/validate-id.decorator.d.ts.map +1 -1
- package/dist/common/decorators/validate-id.decorator.js +22 -2
- package/dist/common/decorators/validate-id.decorator.js.map +1 -1
- package/dist/foundations/foundations.modules.d.ts.map +1 -1
- package/dist/foundations/foundations.modules.js +2 -0
- package/dist/foundations/foundations.modules.js.map +1 -1
- package/dist/foundations/handbook/controllers/handbook.controller.d.ts +2 -1
- package/dist/foundations/handbook/controllers/handbook.controller.d.ts.map +1 -1
- package/dist/foundations/handbook/controllers/handbook.controller.js +5 -4
- package/dist/foundations/handbook/controllers/handbook.controller.js.map +1 -1
- package/dist/foundations/role/controllers/role.controller.d.ts +3 -2
- package/dist/foundations/role/controllers/role.controller.d.ts.map +1 -1
- package/dist/foundations/role/controllers/role.controller.js +9 -7
- package/dist/foundations/role/controllers/role.controller.js.map +1 -1
- package/dist/foundations/stripe/index.d.ts +1 -0
- package/dist/foundations/stripe/index.d.ts.map +1 -1
- package/dist/foundations/stripe/index.js +2 -0
- package/dist/foundations/stripe/index.js.map +1 -1
- package/dist/foundations/stripe/services/stripe.payment.service.d.ts +33 -0
- package/dist/foundations/stripe/services/stripe.payment.service.d.ts.map +1 -1
- package/dist/foundations/stripe/services/stripe.payment.service.js +68 -0
- package/dist/foundations/stripe/services/stripe.payment.service.js.map +1 -1
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code-checkout.controller.d.ts +14 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code-checkout.controller.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code-checkout.controller.js +62 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code-checkout.controller.js.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code.controller.d.ts +28 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code.controller.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code.controller.js +136 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon-code.controller.js.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.controller.d.ts +26 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.controller.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.controller.js +131 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.controller.js.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.public.controller.d.ts +11 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.public.controller.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.public.controller.js +45 -0
- package/dist/foundations/stripe-coupon/controllers/stripe-coupon.public.controller.js.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.patch.dto.d.ts +13 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.patch.dto.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.patch.dto.js +55 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.patch.dto.js.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.post.dto.d.ts +24 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.post.dto.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.post.dto.js +105 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon-code.post.dto.js.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.dto.d.ts +8 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.dto.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.dto.js +36 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.dto.js.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.patch.dto.d.ts +12 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.patch.dto.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.patch.dto.js +51 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.patch.dto.js.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.post.dto.d.ts +31 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.post.dto.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.post.dto.js +120 -0
- package/dist/foundations/stripe-coupon/dtos/stripe-coupon.post.dto.js.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.d.ts +28 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.js +35 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.js.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.meta.d.ts +5 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.meta.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.meta.js +12 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-code.meta.js.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.d.ts +18 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.js +21 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.js.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.meta.d.ts +6 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.meta.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.meta.js +13 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon-offer.meta.js.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.d.ts +32 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.js +37 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.js.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.meta.d.ts +5 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.meta.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.meta.js +12 -0
- package/dist/foundations/stripe-coupon/entities/stripe-coupon.meta.js.map +1 -0
- package/dist/foundations/stripe-coupon/index.d.ts +21 -0
- package/dist/foundations/stripe-coupon/index.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/index.js +43 -0
- package/dist/foundations/stripe-coupon/index.js.map +1 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon-code.repository.d.ts +41 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon-code.repository.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon-code.repository.js +97 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon-code.repository.js.map +1 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon.repository.d.ts +29 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon.repository.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon.repository.js +55 -0
- package/dist/foundations/stripe-coupon/repositories/stripe-coupon.repository.js.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-api.service.d.ts +70 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-api.service.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-api.service.js +172 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-api.service.js.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code-checkout.service.d.ts +81 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code-checkout.service.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code-checkout.service.js +206 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code-checkout.service.js.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code.service.d.ts +92 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code.service.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code.service.js +134 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-code.service.js.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-offer.service.d.ts +29 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-offer.service.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-offer.service.js +73 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon-offer.service.js.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon.service.d.ts +65 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon.service.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon.service.js +200 -0
- package/dist/foundations/stripe-coupon/services/stripe-coupon.service.js.map +1 -0
- package/dist/foundations/stripe-coupon/stripe-coupon.module.d.ts +14 -0
- package/dist/foundations/stripe-coupon/stripe-coupon.module.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/stripe-coupon.module.js +91 -0
- package/dist/foundations/stripe-coupon/stripe-coupon.module.js.map +1 -0
- package/dist/foundations/stripe-coupon/utils/places-left.d.ts +19 -0
- package/dist/foundations/stripe-coupon/utils/places-left.d.ts.map +1 -0
- package/dist/foundations/stripe-coupon/utils/places-left.js +33 -0
- package/dist/foundations/stripe-coupon/utils/places-left.js.map +1 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.d.ts +22 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.d.ts.map +1 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.js +48 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.js.map +1 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-discount-backfill.service.d.ts +51 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-discount-backfill.service.d.ts.map +1 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-discount-backfill.service.js +129 -0
- package/dist/foundations/stripe-subscription/backfills/stripe-subscription-discount-backfill.service.js.map +1 -0
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.d.ts +7 -1
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js +18 -5
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js.map +1 -1
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.discount.d.ts +30 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.discount.d.ts.map +1 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.discount.js +57 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.discount.js.map +1 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.entity.d.ts +7 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.entity.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.map.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.map.js +6 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.map.js.map +1 -1
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.meta.d.ts +8 -0
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.meta.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.meta.js +9 -1
- package/dist/foundations/stripe-subscription/entities/stripe-subscription.meta.js.map +1 -1
- package/dist/foundations/stripe-subscription/index.d.ts +3 -2
- package/dist/foundations/stripe-subscription/index.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/index.js +5 -1
- package/dist/foundations/stripe-subscription/index.js.map +1 -1
- package/dist/foundations/stripe-subscription/repositories/stripe-subscription.repository.d.ts +14 -0
- package/dist/foundations/stripe-subscription/repositories/stripe-subscription.repository.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/repositories/stripe-subscription.repository.js +32 -0
- package/dist/foundations/stripe-subscription/repositories/stripe-subscription.repository.js.map +1 -1
- package/dist/foundations/stripe-subscription/serialisers/stripe-subscription.serialiser.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/serialisers/stripe-subscription.serialiser.js +6 -0
- package/dist/foundations/stripe-subscription/serialisers/stripe-subscription.serialiser.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.d.ts +36 -3
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.js +174 -38
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.d.ts +7 -0
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.js +29 -2
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/subscription-payment-confirmation.d.ts +27 -0
- package/dist/foundations/stripe-subscription/services/subscription-payment-confirmation.d.ts.map +1 -0
- package/dist/foundations/stripe-subscription/services/subscription-payment-confirmation.js +62 -0
- package/dist/foundations/stripe-subscription/services/subscription-payment-confirmation.js.map +1 -0
- package/dist/foundations/stripe-subscription/stripe-subscription.module.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/stripe-subscription.module.js +10 -0
- package/dist/foundations/stripe-subscription/stripe-subscription.module.js.map +1 -1
- package/dist/foundations/stripe-webhook/processors/stripe-webhook.processor.d.ts.map +1 -1
- package/dist/foundations/stripe-webhook/processors/stripe-webhook.processor.js +16 -1
- package/dist/foundations/stripe-webhook/processors/stripe-webhook.processor.js.map +1 -1
- package/dist/foundations/two-factor/controllers/passkey.controller.d.ts +1 -1
- package/dist/foundations/two-factor/controllers/passkey.controller.d.ts.map +1 -1
- package/dist/foundations/two-factor/controllers/passkey.controller.js +6 -5
- package/dist/foundations/two-factor/controllers/passkey.controller.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StripeCouponOfferService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
15
|
+
const jsonapi_paginator_1 = require("../../../core/jsonapi/serialisers/jsonapi.paginator");
|
|
16
|
+
const jsonapi_service_1 = require("../../../core/jsonapi/services/jsonapi.service");
|
|
17
|
+
const abstract_service_1 = require("../../../core/neo4j/abstracts/abstract.service");
|
|
18
|
+
const stripe_coupon_code_1 = require("../entities/stripe-coupon-code");
|
|
19
|
+
const stripe_coupon_offer_1 = require("../entities/stripe-coupon-offer");
|
|
20
|
+
const stripe_coupon_code_repository_1 = require("../repositories/stripe-coupon-code.repository");
|
|
21
|
+
const places_left_1 = require("../utils/places-left");
|
|
22
|
+
/**
|
|
23
|
+
* The public offer: places left on the automatic code, as a synthetic `stripe-coupon-offers`
|
|
24
|
+
* list of 0 or 1 offer. Reads our copy only, never Stripe.
|
|
25
|
+
*/
|
|
26
|
+
let StripeCouponOfferService = class StripeCouponOfferService extends abstract_service_1.AbstractService {
|
|
27
|
+
constructor(jsonApiService, stripeCouponCodeRepository, clsService) {
|
|
28
|
+
super(jsonApiService, stripeCouponCodeRepository, clsService, stripe_coupon_code_1.StripeCouponCodeDescriptor.model);
|
|
29
|
+
this.stripeCouponCodeRepository = stripeCouponCodeRepository;
|
|
30
|
+
this.descriptor = stripe_coupon_code_1.StripeCouponCodeDescriptor;
|
|
31
|
+
}
|
|
32
|
+
async findPublicOffers(params) {
|
|
33
|
+
const paginator = new jsonapi_paginator_1.JsonApiPaginator(params.query);
|
|
34
|
+
const offer = await this.buildOffer();
|
|
35
|
+
return this.jsonApiService.buildList(stripe_coupon_offer_1.StripeCouponOfferDescriptor.model, offer ? [offer] : [], paginator);
|
|
36
|
+
}
|
|
37
|
+
async buildOffer() {
|
|
38
|
+
const code = await this.stripeCouponCodeRepository.findAutomatic();
|
|
39
|
+
if (!code || !code.active || !code.automatic)
|
|
40
|
+
return null;
|
|
41
|
+
const coupon = code.coupon;
|
|
42
|
+
if (!coupon || !coupon.valid)
|
|
43
|
+
return null;
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
if (coupon.redeemBy && new Date(coupon.redeemBy).getTime() <= now)
|
|
46
|
+
return null;
|
|
47
|
+
if (code.expiresAt && new Date(code.expiresAt).getTime() <= now)
|
|
48
|
+
return null;
|
|
49
|
+
const left = (0, places_left_1.placesLeft)(code, coupon);
|
|
50
|
+
const total = (0, places_left_1.placesTotal)(code, coupon);
|
|
51
|
+
if (left === null || total === null || left <= 0)
|
|
52
|
+
return null;
|
|
53
|
+
return {
|
|
54
|
+
id: code.id,
|
|
55
|
+
discountType: coupon.discountType,
|
|
56
|
+
percentOff: coupon.percentOff,
|
|
57
|
+
amountOff: coupon.amountOff,
|
|
58
|
+
currency: coupon.currency,
|
|
59
|
+
duration: coupon.duration,
|
|
60
|
+
durationInMonths: coupon.durationInMonths,
|
|
61
|
+
placesLeft: left,
|
|
62
|
+
placesTotal: total,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.StripeCouponOfferService = StripeCouponOfferService;
|
|
67
|
+
exports.StripeCouponOfferService = StripeCouponOfferService = __decorate([
|
|
68
|
+
(0, common_1.Injectable)(),
|
|
69
|
+
__metadata("design:paramtypes", [jsonapi_service_1.JsonApiService,
|
|
70
|
+
stripe_coupon_code_repository_1.StripeCouponCodeRepository,
|
|
71
|
+
nestjs_cls_1.ClsService])
|
|
72
|
+
], StripeCouponOfferService);
|
|
73
|
+
//# sourceMappingURL=stripe-coupon-offer.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-coupon-offer.service.js","sourceRoot":"","sources":["../../../../src/foundations/stripe-coupon/services/stripe-coupon-offer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AAExC,2FAAuF;AACvF,oFAAgF;AAChF,qFAAiF;AACjF,uEAA8F;AAC9F,yEAAiG;AACjG,iGAA2F;AAC3F,sDAA+D;AAE/D;;;GAGG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,kCAG7C;IAGC,YACE,cAA8B,EACb,0BAAsD,EACvE,UAAsB;QAEtB,KAAK,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,MAAM,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAE9D,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,KAAK;SACE,CAAC;IACzB,CAAC;CACF,CAAA;AAhDY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAQO,gCAAc;QACe,0DAA0B;QAC3D,uBAAU;GATb,wBAAwB,CAgDpC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ClsService } from "nestjs-cls";
|
|
2
|
+
import { JsonApiSingleDocument } from "../../../core/jsonapi/interfaces/jsonapi.document.interface";
|
|
3
|
+
import { JsonApiService } from "../../../core/jsonapi/services/jsonapi.service";
|
|
4
|
+
import { AbstractService } from "../../../core/neo4j/abstracts/abstract.service";
|
|
5
|
+
import { StripeProductRepository } from "../../stripe-product/repositories/stripe-product.repository";
|
|
6
|
+
import { StripeCouponPatchDataDTO } from "../dtos/stripe-coupon.patch.dto";
|
|
7
|
+
import { StripeCouponPostDataDTO } from "../dtos/stripe-coupon.post.dto";
|
|
8
|
+
import { StripeCoupon, StripeCouponDescriptor } from "../entities/stripe-coupon";
|
|
9
|
+
import { StripeCouponCodeRepository } from "../repositories/stripe-coupon-code.repository";
|
|
10
|
+
import { StripeCouponRepository } from "../repositories/stripe-coupon.repository";
|
|
11
|
+
import { StripeCouponApiService } from "./stripe-coupon-api.service";
|
|
12
|
+
/**
|
|
13
|
+
* StripeCouponService
|
|
14
|
+
*
|
|
15
|
+
* Admin operations on coupons. A coupon is created in Stripe together with its
|
|
16
|
+
* first customer-facing code, then both are mirrored as nodes. Stripe forbids
|
|
17
|
+
* changing a coupon's discount, duration and limits, so the only edit is a
|
|
18
|
+
* rename; counts are refreshed from Stripe on demand.
|
|
19
|
+
*/
|
|
20
|
+
export declare class StripeCouponService extends AbstractService<StripeCoupon, typeof StripeCouponDescriptor.relationships> {
|
|
21
|
+
private readonly stripeCouponRepository;
|
|
22
|
+
private readonly stripeCouponCodeRepository;
|
|
23
|
+
private readonly stripeCouponApiService;
|
|
24
|
+
private readonly stripeProductRepository;
|
|
25
|
+
protected readonly descriptor: import("../../..").EntityDescriptor<StripeCoupon, {
|
|
26
|
+
codes: {
|
|
27
|
+
model: import("../../..").DataMeta;
|
|
28
|
+
direction: "out";
|
|
29
|
+
relationship: string;
|
|
30
|
+
cardinality: "many";
|
|
31
|
+
required: false;
|
|
32
|
+
dtoKey: string;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
private readonly logger;
|
|
36
|
+
constructor(jsonApiService: JsonApiService, stripeCouponRepository: StripeCouponRepository, clsService: ClsService, stripeCouponCodeRepository: StripeCouponCodeRepository, stripeCouponApiService: StripeCouponApiService, stripeProductRepository: StripeProductRepository);
|
|
37
|
+
/**
|
|
38
|
+
* Creates the Stripe coupon, then its first promotion code, then both nodes.
|
|
39
|
+
* When anything after the coupon fails, the Stripe coupon is deleted (which
|
|
40
|
+
* also deactivates any code already made from it) and the error re-thrown.
|
|
41
|
+
*/
|
|
42
|
+
createWithFirstCode(params: {
|
|
43
|
+
data: StripeCouponPostDataDTO;
|
|
44
|
+
}): Promise<JsonApiSingleDocument>;
|
|
45
|
+
/**
|
|
46
|
+
* Renames the coupon in Stripe, then on the node. Nothing else is editable.
|
|
47
|
+
*/
|
|
48
|
+
rename(params: {
|
|
49
|
+
data: StripeCouponPatchDataDTO;
|
|
50
|
+
}): Promise<JsonApiSingleDocument>;
|
|
51
|
+
/**
|
|
52
|
+
* Re-reads the coupon and each of its codes from Stripe and writes the
|
|
53
|
+
* redemption counts and status to the nodes.
|
|
54
|
+
*/
|
|
55
|
+
refreshCounts(params: {
|
|
56
|
+
id: string;
|
|
57
|
+
}): Promise<JsonApiSingleDocument>;
|
|
58
|
+
private assertCouponAttributes;
|
|
59
|
+
/**
|
|
60
|
+
* Maps our StripeProduct ids to Stripe product ids. Unknown ids are rejected.
|
|
61
|
+
*/
|
|
62
|
+
private mapProductIds;
|
|
63
|
+
private rollback;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=stripe-coupon.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-coupon.service.d.ts","sourceRoot":"","sources":["../../../../src/foundations/stripe-coupon/services/stripe-coupon.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6DAA6D,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6DAA6D,CAAC;AACtG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAiC,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;;;GAOG;AACH,qBACa,mBAAoB,SAAQ,eAAe,CAAC,YAAY,EAAE,OAAO,sBAAsB,CAAC,aAAa,CAAC;IAM/G,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAEvC,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IAT1C,SAAS,CAAC,QAAQ,CAAC,UAAU;;;;;;;;;OAA0B;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;gBAG7D,cAAc,EAAE,cAAc,EACb,sBAAsB,EAAE,sBAAsB,EAC/D,UAAU,EAAE,UAAU,EACL,0BAA0B,EAAE,0BAA0B,EACtD,sBAAsB,EAAE,sBAAsB,EAC9C,uBAAuB,EAAE,uBAAuB;IAKnE;;;;OAIG;IACG,mBAAmB,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,uBAAuB,CAAA;KAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAgEpG;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,wBAAwB,CAAA;KAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAYxF;;;OAGG;IACG,aAAa,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAuB3E,OAAO,CAAC,sBAAsB;IAoB9B;;OAEG;YACW,aAAa;YAab,QAAQ;CAevB"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var StripeCouponService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.StripeCouponService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
17
|
+
const jsonapi_service_1 = require("../../../core/jsonapi/services/jsonapi.service");
|
|
18
|
+
const abstract_service_1 = require("../../../core/neo4j/abstracts/abstract.service");
|
|
19
|
+
const stripe_product_repository_1 = require("../../stripe-product/repositories/stripe-product.repository");
|
|
20
|
+
const stripe_coupon_1 = require("../entities/stripe-coupon");
|
|
21
|
+
const stripe_coupon_code_repository_1 = require("../repositories/stripe-coupon-code.repository");
|
|
22
|
+
const stripe_coupon_repository_1 = require("../repositories/stripe-coupon.repository");
|
|
23
|
+
const stripe_coupon_api_service_1 = require("./stripe-coupon-api.service");
|
|
24
|
+
const stripe_coupon_code_service_1 = require("./stripe-coupon-code.service");
|
|
25
|
+
/**
|
|
26
|
+
* StripeCouponService
|
|
27
|
+
*
|
|
28
|
+
* Admin operations on coupons. A coupon is created in Stripe together with its
|
|
29
|
+
* first customer-facing code, then both are mirrored as nodes. Stripe forbids
|
|
30
|
+
* changing a coupon's discount, duration and limits, so the only edit is a
|
|
31
|
+
* rename; counts are refreshed from Stripe on demand.
|
|
32
|
+
*/
|
|
33
|
+
let StripeCouponService = StripeCouponService_1 = class StripeCouponService extends abstract_service_1.AbstractService {
|
|
34
|
+
constructor(jsonApiService, stripeCouponRepository, clsService, stripeCouponCodeRepository, stripeCouponApiService, stripeProductRepository) {
|
|
35
|
+
super(jsonApiService, stripeCouponRepository, clsService, stripe_coupon_1.StripeCouponDescriptor.model);
|
|
36
|
+
this.stripeCouponRepository = stripeCouponRepository;
|
|
37
|
+
this.stripeCouponCodeRepository = stripeCouponCodeRepository;
|
|
38
|
+
this.stripeCouponApiService = stripeCouponApiService;
|
|
39
|
+
this.stripeProductRepository = stripeProductRepository;
|
|
40
|
+
this.descriptor = stripe_coupon_1.StripeCouponDescriptor;
|
|
41
|
+
this.logger = new common_1.Logger(StripeCouponService_1.name);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates the Stripe coupon, then its first promotion code, then both nodes.
|
|
45
|
+
* When anything after the coupon fails, the Stripe coupon is deleted (which
|
|
46
|
+
* also deactivates any code already made from it) and the error re-thrown.
|
|
47
|
+
*/
|
|
48
|
+
async createWithFirstCode(params) {
|
|
49
|
+
const attributes = params.data.attributes;
|
|
50
|
+
const firstCode = attributes.firstCode;
|
|
51
|
+
this.assertCouponAttributes(attributes);
|
|
52
|
+
(0, stripe_coupon_code_service_1.assertCouponCodeAttributes)(firstCode);
|
|
53
|
+
const stripeProductIds = await this.mapProductIds(attributes.productIds);
|
|
54
|
+
const stripeCoupon = await this.stripeCouponApiService.createCoupon({
|
|
55
|
+
id: attributes.stripeCouponId,
|
|
56
|
+
name: attributes.name,
|
|
57
|
+
percentOff: attributes.discountType === "percent_off" ? attributes.percentOff : undefined,
|
|
58
|
+
amountOff: attributes.discountType === "amount_off" ? attributes.amountOff : undefined,
|
|
59
|
+
currency: attributes.discountType === "amount_off" ? attributes.currency?.toLowerCase() : undefined,
|
|
60
|
+
duration: attributes.duration,
|
|
61
|
+
durationInMonths: attributes.duration === "repeating" ? attributes.durationInMonths : undefined,
|
|
62
|
+
stripeProductIds,
|
|
63
|
+
redeemBy: attributes.redeemBy ? new Date(attributes.redeemBy) : undefined,
|
|
64
|
+
maxRedemptions: attributes.maxRedemptions,
|
|
65
|
+
});
|
|
66
|
+
const codeId = (0, crypto_1.randomUUID)();
|
|
67
|
+
let couponNodeCreated = false;
|
|
68
|
+
try {
|
|
69
|
+
const promotionCode = await this.stripeCouponApiService.createPromotionCode((0, stripe_coupon_code_service_1.couponCodeStripeParams)(stripeCoupon.id, firstCode));
|
|
70
|
+
await this.stripeCouponRepository.create({
|
|
71
|
+
id: params.data.id,
|
|
72
|
+
stripeCouponId: stripeCoupon.id,
|
|
73
|
+
name: attributes.name,
|
|
74
|
+
discountType: attributes.discountType,
|
|
75
|
+
percentOff: attributes.discountType === "percent_off" ? attributes.percentOff : undefined,
|
|
76
|
+
amountOff: attributes.discountType === "amount_off" ? attributes.amountOff : undefined,
|
|
77
|
+
currency: attributes.discountType === "amount_off" ? attributes.currency?.toLowerCase() : undefined,
|
|
78
|
+
duration: attributes.duration,
|
|
79
|
+
durationInMonths: attributes.duration === "repeating" ? attributes.durationInMonths : undefined,
|
|
80
|
+
stripeProductIds,
|
|
81
|
+
redeemBy: attributes.redeemBy,
|
|
82
|
+
maxRedemptions: attributes.maxRedemptions,
|
|
83
|
+
timesRedeemed: stripeCoupon.times_redeemed ?? 0,
|
|
84
|
+
valid: stripeCoupon.valid,
|
|
85
|
+
});
|
|
86
|
+
couponNodeCreated = true;
|
|
87
|
+
await this.stripeCouponCodeRepository.create((0, stripe_coupon_code_service_1.couponCodeNodeParams)({ id: codeId, couponId: params.data.id, attributes: firstCode, promotionCode }));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
await this.rollback({
|
|
91
|
+
stripeCouponId: stripeCoupon.id,
|
|
92
|
+
couponId: couponNodeCreated ? params.data.id : undefined,
|
|
93
|
+
});
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
if (firstCode.automatic)
|
|
97
|
+
await this.stripeCouponCodeRepository.setAutomatic({ id: codeId, automatic: true });
|
|
98
|
+
return this.findById({ id: params.data.id });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Renames the coupon in Stripe, then on the node. Nothing else is editable.
|
|
102
|
+
*/
|
|
103
|
+
async rename(params) {
|
|
104
|
+
const coupon = await this.stripeCouponRepository.findById({ id: params.data.id });
|
|
105
|
+
if (!coupon)
|
|
106
|
+
throw new common_1.NotFoundException("Coupon not found");
|
|
107
|
+
const name = params.data.attributes.name;
|
|
108
|
+
if (name === undefined)
|
|
109
|
+
return this.findById({ id: coupon.id });
|
|
110
|
+
await this.stripeCouponApiService.renameCoupon({ stripeCouponId: coupon.stripeCouponId, name });
|
|
111
|
+
return this.patch({ id: coupon.id, name });
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Re-reads the coupon and each of its codes from Stripe and writes the
|
|
115
|
+
* redemption counts and status to the nodes.
|
|
116
|
+
*/
|
|
117
|
+
async refreshCounts(params) {
|
|
118
|
+
const coupon = await this.stripeCouponRepository.findById({ id: params.id });
|
|
119
|
+
if (!coupon)
|
|
120
|
+
throw new common_1.NotFoundException("Coupon not found");
|
|
121
|
+
const stripeCoupon = await this.stripeCouponApiService.retrieveCoupon(coupon.stripeCouponId);
|
|
122
|
+
await this.stripeCouponRepository.patch({
|
|
123
|
+
id: coupon.id,
|
|
124
|
+
timesRedeemed: stripeCoupon.times_redeemed ?? 0,
|
|
125
|
+
valid: stripeCoupon.valid,
|
|
126
|
+
});
|
|
127
|
+
for (const code of coupon.codes ?? []) {
|
|
128
|
+
const promotionCode = await this.stripeCouponApiService.retrievePromotionCode(code.stripePromotionCodeId);
|
|
129
|
+
await this.stripeCouponCodeRepository.patch({
|
|
130
|
+
id: code.id,
|
|
131
|
+
timesRedeemed: promotionCode.times_redeemed ?? 0,
|
|
132
|
+
active: promotionCode.active,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return this.findById({ id: coupon.id });
|
|
136
|
+
}
|
|
137
|
+
assertCouponAttributes(attributes) {
|
|
138
|
+
if (attributes.discountType === "percent_off") {
|
|
139
|
+
if (attributes.percentOff === undefined)
|
|
140
|
+
throw new common_1.BadRequestException("A percentage coupon needs percentOff");
|
|
141
|
+
if (attributes.amountOff !== undefined || attributes.currency !== undefined)
|
|
142
|
+
throw new common_1.BadRequestException("A percentage coupon cannot have amountOff or currency");
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
if (attributes.amountOff === undefined || !attributes.currency)
|
|
146
|
+
throw new common_1.BadRequestException("A fixed-amount coupon needs amountOff and currency");
|
|
147
|
+
if (attributes.percentOff !== undefined)
|
|
148
|
+
throw new common_1.BadRequestException("A fixed-amount coupon cannot have percentOff");
|
|
149
|
+
}
|
|
150
|
+
if (attributes.duration === "repeating") {
|
|
151
|
+
if (attributes.durationInMonths === undefined)
|
|
152
|
+
throw new common_1.BadRequestException("A repeating coupon needs durationInMonths");
|
|
153
|
+
}
|
|
154
|
+
else if (attributes.durationInMonths !== undefined) {
|
|
155
|
+
throw new common_1.BadRequestException("durationInMonths applies only to a repeating coupon");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Maps our StripeProduct ids to Stripe product ids. Unknown ids are rejected.
|
|
160
|
+
*/
|
|
161
|
+
async mapProductIds(productIds) {
|
|
162
|
+
if (!productIds?.length)
|
|
163
|
+
return undefined;
|
|
164
|
+
const stripeProductIds = [];
|
|
165
|
+
for (const id of productIds) {
|
|
166
|
+
const product = await this.stripeProductRepository.findById({ id });
|
|
167
|
+
if (!product)
|
|
168
|
+
throw new common_1.BadRequestException(`Product ${id} not found`);
|
|
169
|
+
stripeProductIds.push(product.stripeProductId);
|
|
170
|
+
}
|
|
171
|
+
return stripeProductIds;
|
|
172
|
+
}
|
|
173
|
+
async rollback(params) {
|
|
174
|
+
try {
|
|
175
|
+
await this.stripeCouponApiService.deleteCoupon(params.stripeCouponId);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
this.logger.error(`Could not delete Stripe coupon ${params.stripeCouponId} after a failed create`, error);
|
|
179
|
+
}
|
|
180
|
+
if (!params.couponId)
|
|
181
|
+
return;
|
|
182
|
+
try {
|
|
183
|
+
await this.stripeCouponRepository.delete({ id: params.couponId });
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
this.logger.error(`Could not delete coupon node ${params.couponId} after a failed create`, error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
exports.StripeCouponService = StripeCouponService;
|
|
191
|
+
exports.StripeCouponService = StripeCouponService = StripeCouponService_1 = __decorate([
|
|
192
|
+
(0, common_1.Injectable)(),
|
|
193
|
+
__metadata("design:paramtypes", [jsonapi_service_1.JsonApiService,
|
|
194
|
+
stripe_coupon_repository_1.StripeCouponRepository,
|
|
195
|
+
nestjs_cls_1.ClsService,
|
|
196
|
+
stripe_coupon_code_repository_1.StripeCouponCodeRepository,
|
|
197
|
+
stripe_coupon_api_service_1.StripeCouponApiService,
|
|
198
|
+
stripe_product_repository_1.StripeProductRepository])
|
|
199
|
+
], StripeCouponService);
|
|
200
|
+
//# sourceMappingURL=stripe-coupon.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-coupon.service.js","sourceRoot":"","sources":["../../../../src/foundations/stripe-coupon/services/stripe-coupon.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4F;AAC5F,mCAAoC;AACpC,2CAAwC;AAExC,oFAAgF;AAChF,qFAAiF;AACjF,2GAAsG;AAGtG,6DAAiF;AACjF,iGAA2F;AAC3F,uFAAkF;AAClF,2EAAqE;AACrE,6EAAwH;AAExH;;;;;;;GAOG;AAEI,IAAM,mBAAmB,2BAAzB,MAAM,mBAAoB,SAAQ,kCAA0E;IAIjH,YACE,cAA8B,EACb,sBAA8C,EAC/D,UAAsB,EACL,0BAAsD,EACtD,sBAA8C,EAC9C,uBAAgD;QAEjE,KAAK,CAAC,cAAc,EAAE,sBAAsB,EAAE,UAAU,EAAE,sCAAsB,CAAC,KAAK,CAAC,CAAC;QANvE,2BAAsB,GAAtB,sBAAsB,CAAwB;QAE9C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*
|
|
5
|
+
* - Coupons and codes are created in Stripe first and mirrored as nodes
|
|
6
|
+
* (`StripeCoupon` -[:HAS_CODE]-> `StripeCouponCode`), like products
|
|
7
|
+
* - One code at a time can be "Apply automatically"; the subscription service
|
|
8
|
+
* attaches it at a GM's first payment (`StripeCouponCodeCheckoutService`)
|
|
9
|
+
* - A public read of the automatic code's places left (`StripeCouponPublicController`)
|
|
10
|
+
*/
|
|
11
|
+
export declare class StripeCouponModule implements OnModuleInit {
|
|
12
|
+
onModuleInit(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=stripe-coupon.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-coupon.module.d.ts","sourceRoot":"","sources":["../../../src/foundations/stripe-coupon/stripe-coupon.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAc,MAAM,gBAAgB,CAAC;AA2BlE;;;;;;;;GAQG;AACH,qBAmCa,kBAAmB,YAAW,YAAY;IACrD,YAAY;CAMb"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.StripeCouponModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const registry_1 = require("../../common/registries/registry");
|
|
12
|
+
const cache_module_1 = require("../../core/cache/cache.module");
|
|
13
|
+
const jsonapi_module_1 = require("../../core/jsonapi/jsonapi.module");
|
|
14
|
+
const neo4j_module_1 = require("../../core/neo4j/neo4j.module");
|
|
15
|
+
const security_module_1 = require("../../core/security/security.module");
|
|
16
|
+
const audit_module_1 = require("../audit/audit.module");
|
|
17
|
+
const stripe_customer_module_1 = require("../stripe-customer/stripe-customer.module");
|
|
18
|
+
const stripe_price_module_1 = require("../stripe-price/stripe-price.module");
|
|
19
|
+
const stripe_product_module_1 = require("../stripe-product/stripe-product.module");
|
|
20
|
+
const stripe_subscription_module_1 = require("../stripe-subscription/stripe-subscription.module");
|
|
21
|
+
const stripe_module_1 = require("../stripe/stripe.module");
|
|
22
|
+
const stripe_coupon_code_checkout_controller_1 = require("./controllers/stripe-coupon-code-checkout.controller");
|
|
23
|
+
const stripe_coupon_code_controller_1 = require("./controllers/stripe-coupon-code.controller");
|
|
24
|
+
const stripe_coupon_controller_1 = require("./controllers/stripe-coupon.controller");
|
|
25
|
+
const stripe_coupon_public_controller_1 = require("./controllers/stripe-coupon.public.controller");
|
|
26
|
+
const stripe_coupon_1 = require("./entities/stripe-coupon");
|
|
27
|
+
const stripe_coupon_code_1 = require("./entities/stripe-coupon-code");
|
|
28
|
+
const stripe_coupon_offer_1 = require("./entities/stripe-coupon-offer");
|
|
29
|
+
const stripe_coupon_code_repository_1 = require("./repositories/stripe-coupon-code.repository");
|
|
30
|
+
const stripe_coupon_repository_1 = require("./repositories/stripe-coupon.repository");
|
|
31
|
+
const stripe_coupon_api_service_1 = require("./services/stripe-coupon-api.service");
|
|
32
|
+
const stripe_coupon_code_checkout_service_1 = require("./services/stripe-coupon-code-checkout.service");
|
|
33
|
+
const stripe_coupon_code_service_1 = require("./services/stripe-coupon-code.service");
|
|
34
|
+
const stripe_coupon_offer_service_1 = require("./services/stripe-coupon-offer.service");
|
|
35
|
+
const stripe_coupon_service_1 = require("./services/stripe-coupon.service");
|
|
36
|
+
/**
|
|
37
|
+
* StripeCouponModule — admin-managed Stripe coupons and their customer-facing codes.
|
|
38
|
+
*
|
|
39
|
+
* - Coupons and codes are created in Stripe first and mirrored as nodes
|
|
40
|
+
* (`StripeCoupon` -[:HAS_CODE]-> `StripeCouponCode`), like products
|
|
41
|
+
* - One code at a time can be "Apply automatically"; the subscription service
|
|
42
|
+
* attaches it at a GM's first payment (`StripeCouponCodeCheckoutService`)
|
|
43
|
+
* - A public read of the automatic code's places left (`StripeCouponPublicController`)
|
|
44
|
+
*/
|
|
45
|
+
let StripeCouponModule = class StripeCouponModule {
|
|
46
|
+
onModuleInit() {
|
|
47
|
+
registry_1.modelRegistry.register(stripe_coupon_1.StripeCouponDescriptor.model);
|
|
48
|
+
registry_1.modelRegistry.register(stripe_coupon_code_1.StripeCouponCodeDescriptor.model);
|
|
49
|
+
// Synthetic resource (never a node): buildList needs it in the registry
|
|
50
|
+
registry_1.modelRegistry.register(stripe_coupon_offer_1.StripeCouponOfferDescriptor.model);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.StripeCouponModule = StripeCouponModule;
|
|
54
|
+
exports.StripeCouponModule = StripeCouponModule = __decorate([
|
|
55
|
+
(0, common_1.Module)({
|
|
56
|
+
imports: [
|
|
57
|
+
neo4j_module_1.Neo4JModule,
|
|
58
|
+
jsonapi_module_1.JsonApiModule,
|
|
59
|
+
security_module_1.SecurityModule,
|
|
60
|
+
cache_module_1.CacheModule,
|
|
61
|
+
audit_module_1.AuditModule,
|
|
62
|
+
(0, common_1.forwardRef)(() => stripe_module_1.StripeModule),
|
|
63
|
+
(0, common_1.forwardRef)(() => stripe_product_module_1.StripeProductModule),
|
|
64
|
+
(0, common_1.forwardRef)(() => stripe_price_module_1.StripePriceModule),
|
|
65
|
+
(0, common_1.forwardRef)(() => stripe_customer_module_1.StripeCustomerModule),
|
|
66
|
+
(0, common_1.forwardRef)(() => stripe_subscription_module_1.StripeSubscriptionModule),
|
|
67
|
+
],
|
|
68
|
+
// The checkout controller comes first: its literal `stripe-coupon-codes/automatic`
|
|
69
|
+
// route must register before `stripe-coupon-codes/:codeId`.
|
|
70
|
+
controllers: [
|
|
71
|
+
stripe_coupon_code_checkout_controller_1.StripeCouponCodeCheckoutController,
|
|
72
|
+
stripe_coupon_controller_1.StripeCouponController,
|
|
73
|
+
stripe_coupon_code_controller_1.StripeCouponCodeController,
|
|
74
|
+
stripe_coupon_public_controller_1.StripeCouponPublicController,
|
|
75
|
+
],
|
|
76
|
+
providers: [
|
|
77
|
+
stripe_coupon_1.StripeCouponDescriptor.model.serialiser,
|
|
78
|
+
stripe_coupon_code_1.StripeCouponCodeDescriptor.model.serialiser,
|
|
79
|
+
stripe_coupon_offer_1.StripeCouponOfferDescriptor.model.serialiser,
|
|
80
|
+
stripe_coupon_api_service_1.StripeCouponApiService,
|
|
81
|
+
stripe_coupon_repository_1.StripeCouponRepository,
|
|
82
|
+
stripe_coupon_code_repository_1.StripeCouponCodeRepository,
|
|
83
|
+
stripe_coupon_service_1.StripeCouponService,
|
|
84
|
+
stripe_coupon_code_service_1.StripeCouponCodeService,
|
|
85
|
+
stripe_coupon_code_checkout_service_1.StripeCouponCodeCheckoutService,
|
|
86
|
+
stripe_coupon_offer_service_1.StripeCouponOfferService,
|
|
87
|
+
],
|
|
88
|
+
exports: [stripe_coupon_code_checkout_service_1.StripeCouponCodeCheckoutService, stripe_coupon_code_repository_1.StripeCouponCodeRepository, stripe_coupon_api_service_1.StripeCouponApiService],
|
|
89
|
+
})
|
|
90
|
+
], StripeCouponModule);
|
|
91
|
+
//# sourceMappingURL=stripe-coupon.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-coupon.module.js","sourceRoot":"","sources":["../../../src/foundations/stripe-coupon/stripe-coupon.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAkE;AAClE,+DAAiE;AACjE,gEAA4D;AAC5D,sEAAkE;AAClE,gEAA4D;AAC5D,yEAAqE;AACrE,wDAAoD;AACpD,sFAAiF;AACj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KAAK,CAAC,UAAU;YAC5C,kDAAsB;YACtB,iDAAsB;YACtB,0DAA0B;YAC1B,2CAAmB;YACnB,oDAAuB;YACvB,qEAA+B;YAC/B,sDAAwB;SACzB;QACD,OAAO,EAAE,CAAC,qEAA+B,EAAE,0DAA0B,EAAE,kDAAsB,CAAC;KAC/F,CAAC;GACW,kBAAkB,CAO9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StripeCoupon } from "../entities/stripe-coupon";
|
|
2
|
+
import type { StripeCouponCode } from "../entities/stripe-coupon-code";
|
|
3
|
+
type CodeLimits = Pick<StripeCouponCode, "maxRedemptions" | "timesRedeemed">;
|
|
4
|
+
type CouponLimits = Pick<StripeCoupon, "maxRedemptions" | "timesRedeemed">;
|
|
5
|
+
/**
|
|
6
|
+
* Places left for a code: the smaller of (coupon limit - coupon redeemed) and
|
|
7
|
+
* (code limit - code redeemed), counting only the limits that are set. Never below zero.
|
|
8
|
+
*
|
|
9
|
+
* @returns null when neither limit is set (unlimited)
|
|
10
|
+
*/
|
|
11
|
+
export declare function placesLeft(code: CodeLimits, coupon: CouponLimits): number | null;
|
|
12
|
+
/**
|
|
13
|
+
* Total places for a code: the smaller of the set limits (coupon and code).
|
|
14
|
+
*
|
|
15
|
+
* @returns null when neither limit is set (unlimited)
|
|
16
|
+
*/
|
|
17
|
+
export declare function placesTotal(code: CodeLimits, coupon: CouponLimits): number | null;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=places-left.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"places-left.d.ts","sourceRoot":"","sources":["../../../../src/foundations/stripe-coupon/utils/places-left.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,KAAK,UAAU,GAAG,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,eAAe,CAAC,CAAC;AAC7E,KAAK,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,eAAe,CAAC,CAAC;AAI3E;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAMhF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAIjF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.placesLeft = placesLeft;
|
|
4
|
+
exports.placesTotal = placesTotal;
|
|
5
|
+
const isSet = (value) => value !== undefined && value !== null;
|
|
6
|
+
/**
|
|
7
|
+
* Places left for a code: the smaller of (coupon limit - coupon redeemed) and
|
|
8
|
+
* (code limit - code redeemed), counting only the limits that are set. Never below zero.
|
|
9
|
+
*
|
|
10
|
+
* @returns null when neither limit is set (unlimited)
|
|
11
|
+
*/
|
|
12
|
+
function placesLeft(code, coupon) {
|
|
13
|
+
const remaining = [];
|
|
14
|
+
if (isSet(coupon.maxRedemptions))
|
|
15
|
+
remaining.push(coupon.maxRedemptions - (coupon.timesRedeemed ?? 0));
|
|
16
|
+
if (isSet(code.maxRedemptions))
|
|
17
|
+
remaining.push(code.maxRedemptions - (code.timesRedeemed ?? 0));
|
|
18
|
+
if (remaining.length === 0)
|
|
19
|
+
return null;
|
|
20
|
+
return Math.max(0, Math.min(...remaining));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Total places for a code: the smaller of the set limits (coupon and code).
|
|
24
|
+
*
|
|
25
|
+
* @returns null when neither limit is set (unlimited)
|
|
26
|
+
*/
|
|
27
|
+
function placesTotal(code, coupon) {
|
|
28
|
+
const limits = [coupon.maxRedemptions, code.maxRedemptions].filter(isSet);
|
|
29
|
+
if (limits.length === 0)
|
|
30
|
+
return null;
|
|
31
|
+
return Math.min(...limits);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=places-left.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"places-left.js","sourceRoot":"","sources":["../../../../src/foundations/stripe-coupon/utils/places-left.ts"],"names":[],"mappings":";;AAcA,gCAMC;AAOD,kCAIC;AAzBD,MAAM,KAAK,GAAG,CAAC,KAAgC,EAAmB,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AAE3G;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAgB,EAAE,MAAoB;IAC/D,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC;QAAE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,CAAC,CAAC,CAAC,CAAC;IACtG,IAAI,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC;QAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,CAAC,CAAC;IAChG,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,IAAgB,EAAE,MAAoB;IAChE,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Neo4jService } from "../../../core/neo4j";
|
|
2
|
+
/**
|
|
3
|
+
* Records which one-off StripeSubscription backfills have finished, so a worker
|
|
4
|
+
* boot runs each of them once per database.
|
|
5
|
+
*
|
|
6
|
+
* The marker is a `(:StripeSubscriptionBackfill {id})` node. It is not a
|
|
7
|
+
* `(:Migration)` node on purpose: the migrator orders Migration nodes by their
|
|
8
|
+
* date/increment version and reads the newest as "last applied", so a library
|
|
9
|
+
* marker there would make it skip the app's own migrations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class StripeSubscriptionBackfillRepository {
|
|
12
|
+
private readonly neo4j;
|
|
13
|
+
constructor(neo4j: Neo4jService);
|
|
14
|
+
isCompleted(params: {
|
|
15
|
+
id: string;
|
|
16
|
+
}): Promise<boolean>;
|
|
17
|
+
markCompleted(params: {
|
|
18
|
+
id: string;
|
|
19
|
+
summary: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=stripe-subscription-backfill.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-subscription-backfill.repository.d.ts","sourceRoot":"","sources":["../../../../src/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;;;;;;;GAQG;AACH,qBACa,oCAAoC;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,YAAY;IAE1C,WAAW,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrD,aAAa,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAU5E"}
|
package/dist/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StripeSubscriptionBackfillRepository = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const neo4j_1 = require("../../../core/neo4j");
|
|
15
|
+
/**
|
|
16
|
+
* Records which one-off StripeSubscription backfills have finished, so a worker
|
|
17
|
+
* boot runs each of them once per database.
|
|
18
|
+
*
|
|
19
|
+
* The marker is a `(:StripeSubscriptionBackfill {id})` node. It is not a
|
|
20
|
+
* `(:Migration)` node on purpose: the migrator orders Migration nodes by their
|
|
21
|
+
* date/increment version and reads the newest as "last applied", so a library
|
|
22
|
+
* marker there would make it skip the app's own migrations.
|
|
23
|
+
*/
|
|
24
|
+
let StripeSubscriptionBackfillRepository = class StripeSubscriptionBackfillRepository {
|
|
25
|
+
constructor(neo4j) {
|
|
26
|
+
this.neo4j = neo4j;
|
|
27
|
+
}
|
|
28
|
+
async isCompleted(params) {
|
|
29
|
+
const total = await this.neo4j.readCount(`MATCH (backfill:StripeSubscriptionBackfill {id: $id}) RETURN count(backfill) AS total`, { id: params.id });
|
|
30
|
+
return total > 0;
|
|
31
|
+
}
|
|
32
|
+
async markCompleted(params) {
|
|
33
|
+
await this.neo4j.writeOne({
|
|
34
|
+
query: `
|
|
35
|
+
MERGE (backfill:StripeSubscriptionBackfill {id: $id})
|
|
36
|
+
ON CREATE SET backfill.createdAt = datetime()
|
|
37
|
+
SET backfill.completedAt = datetime(), backfill.summary = $summary
|
|
38
|
+
`,
|
|
39
|
+
queryParams: { id: params.id, summary: params.summary },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.StripeSubscriptionBackfillRepository = StripeSubscriptionBackfillRepository;
|
|
44
|
+
exports.StripeSubscriptionBackfillRepository = StripeSubscriptionBackfillRepository = __decorate([
|
|
45
|
+
(0, common_1.Injectable)(),
|
|
46
|
+
__metadata("design:paramtypes", [neo4j_1.Neo4jService])
|
|
47
|
+
], StripeSubscriptionBackfillRepository);
|
|
48
|
+
//# sourceMappingURL=stripe-subscription-backfill.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-subscription-backfill.repository.js","sourceRoot":"","sources":["../../../../src/foundations/stripe-subscription/backfills/stripe-subscription-backfill.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAmD;AAEnD;;;;;;;;GAQG;AAEI,IAAM,oCAAoC,GAA1C,MAAM,oCAAoC;IAC/C,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAEpD,KAAK,CAAC,WAAW,CAAC,MAAsB;QACtC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CACtC,uFAAuF,EACvF,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAClB,CAAC;QACF,OAAO,KAAK,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAuC;QACzD,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YACxB,KAAK,EAAE;;;;OAIN;YACD,WAAW,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;SACxD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArBY,oFAAoC;+CAApC,oCAAoC;IADhD,IAAA,mBAAU,GAAE;qCAEyB,oBAAY;GADrC,oCAAoC,CAqBhD"}
|