@purpleschool/gptbot 0.5.8 → 0.5.13
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/api/controllers/index.ts +1 -0
- package/api/controllers/payment.ts +5 -0
- package/api/controllers/subscription.ts +3 -0
- package/build/api/controllers/index.js +1 -0
- package/build/api/controllers/payment.js +7 -0
- package/build/api/controllers/subscription.js +3 -0
- package/build/commands/index.js +1 -0
- package/build/commands/payment/get-payment-history.command.js +11 -0
- package/build/commands/payment/index.js +18 -0
- package/build/commands/subscription/create-custom-subscription-plan.command.js +24 -0
- package/build/commands/subscription/find-subscription.command.js +1 -1
- package/build/commands/subscription/get-available-upgrades.command.js +13 -0
- package/build/commands/subscription/index.js +3 -0
- package/build/commands/subscription/upgrade-subscription.command.js +41 -0
- package/build/constants/errors/errors.js +40 -0
- package/build/constants/order/enums/index.js +1 -0
- package/build/constants/order/enums/order-type.enum.js +8 -0
- package/build/constants/payment/enums/index.js +1 -0
- package/build/constants/payment/enums/payment-history-item-type.enum.js +8 -0
- package/build/constants/subscription/enums/index.js +4 -0
- package/build/constants/subscription/enums/subscription-action.enum.js +10 -0
- package/build/constants/subscription/enums/subscription-plan.enum.js +8 -0
- package/build/constants/subscription/enums/subscription-status.enum.js +1 -0
- package/build/constants/subscription/enums/subscription-type.enum.js +8 -0
- package/build/constants/subscription/enums/user-to-subscription-type.enum.js +8 -0
- package/build/helpers/index.js +17 -0
- package/build/helpers/subscription/calc-custom-subscription-price.helper.js +19 -0
- package/build/helpers/subscription/index.js +17 -0
- package/build/index.js +1 -0
- package/build/models/message.schema.js +1 -1
- package/build/models/payment-history-item.schema.js +14 -0
- package/build/models/subscription-upgrade-schema.js +8 -0
- package/build/models/subscription.schema.js +14 -2
- package/build/models/user-to-subscription.schema.js +1 -0
- package/commands/index.ts +1 -0
- package/commands/payment/get-payment-history.command.ts +10 -0
- package/commands/payment/index.ts +2 -0
- package/commands/subscription/create-custom-subscription-plan.command.ts +26 -0
- package/commands/subscription/find-subscription.command.ts +2 -2
- package/commands/subscription/get-available-upgrades.command.ts +15 -0
- package/commands/subscription/index.ts +3 -0
- package/commands/subscription/upgrade-subscription.command.ts +46 -0
- package/constants/errors/errors.ts +40 -0
- package/constants/order/enums/index.ts +1 -0
- package/constants/order/enums/order-type.enum.ts +4 -0
- package/constants/payment/enums/index.ts +1 -0
- package/constants/payment/enums/payment-history-item-type.enum.ts +4 -0
- package/constants/subscription/enums/index.ts +4 -0
- package/constants/subscription/enums/subscription-action.enum.ts +6 -0
- package/constants/subscription/enums/subscription-plan.enum.ts +4 -0
- package/constants/subscription/enums/subscription-status.enum.ts +1 -0
- package/constants/subscription/enums/subscription-type.enum.ts +4 -0
- package/constants/subscription/enums/user-to-subscription-type.enum.ts +4 -0
- package/helpers/index.ts +1 -0
- package/helpers/subscription/calc-custom-subscription-price.helper.ts +19 -0
- package/helpers/subscription/index.ts +1 -0
- package/index.ts +1 -0
- package/models/message.schema.ts +1 -1
- package/models/payment-history-item.schema.ts +12 -0
- package/models/subscription-upgrade-schema.ts +9 -0
- package/models/subscription.schema.ts +21 -1
- package/models/user-to-subscription.schema.ts +1 -0
- package/package.json +1 -1
package/api/controllers/index.ts
CHANGED
package/build/commands/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetPaymentHistoryCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const payment_history_item_schema_1 = require("../../models/payment-history-item.schema");
|
|
6
|
+
var GetPaymentHistoryCommand;
|
|
7
|
+
(function (GetPaymentHistoryCommand) {
|
|
8
|
+
GetPaymentHistoryCommand.ResponseSchema = zod_1.z.object({
|
|
9
|
+
data: zod_1.z.array(payment_history_item_schema_1.PaymentHistoryItemSchema),
|
|
10
|
+
});
|
|
11
|
+
})(GetPaymentHistoryCommand || (exports.GetPaymentHistoryCommand = GetPaymentHistoryCommand = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./get-payment-history.command"), exports);
|
|
18
|
+
__exportStar(require("./pay.command"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateCustomSubscriptionPlanCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
var CreateCustomSubscriptionPlanCommand;
|
|
7
|
+
(function (CreateCustomSubscriptionPlanCommand) {
|
|
8
|
+
CreateCustomSubscriptionPlanCommand.RequestSchema = zod_1.z.object({
|
|
9
|
+
tokens: zod_1.z
|
|
10
|
+
.number()
|
|
11
|
+
.refine((val) => val % 500 === 0, {
|
|
12
|
+
message: 'tokens must be a multiple of 500',
|
|
13
|
+
})
|
|
14
|
+
.refine((val) => val > 1000, {
|
|
15
|
+
message: 'tokens must be greater than 1000',
|
|
16
|
+
})
|
|
17
|
+
.refine((val) => val <= 10000, {
|
|
18
|
+
message: 'tokens must be equal or less than 10000',
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
CreateCustomSubscriptionPlanCommand.ResponseSchema = zod_1.z.object({
|
|
22
|
+
data: models_1.SubscriptionSchema,
|
|
23
|
+
});
|
|
24
|
+
})(CreateCustomSubscriptionPlanCommand || (exports.CreateCustomSubscriptionPlanCommand = CreateCustomSubscriptionPlanCommand = {}));
|
|
@@ -9,7 +9,7 @@ var FindSubscriptionCommand;
|
|
|
9
9
|
uuid: true,
|
|
10
10
|
});
|
|
11
11
|
FindSubscriptionCommand.ResponseSchema = zod_1.z.object({
|
|
12
|
-
data: zod_1.z.array(models_1.
|
|
12
|
+
data: zod_1.z.array(models_1.SubscriptionWithSubTypesSchema),
|
|
13
13
|
});
|
|
14
14
|
FindSubscriptionCommand.ResponseByUUIDSchema = zod_1.z.object({
|
|
15
15
|
data: models_1.SubscriptionSchema,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetAvailableUpgradesCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
const subscription_upgrade_schema_1 = require("../../models/subscription-upgrade-schema");
|
|
7
|
+
var GetAvailableUpgradesCommand;
|
|
8
|
+
(function (GetAvailableUpgradesCommand) {
|
|
9
|
+
GetAvailableUpgradesCommand.RequestSchema = models_1.SubscriptionSchema.pick({});
|
|
10
|
+
GetAvailableUpgradesCommand.ResponseSchema = zod_1.z.object({
|
|
11
|
+
data: zod_1.z.array(subscription_upgrade_schema_1.SubscriptionUpgradeSchema),
|
|
12
|
+
});
|
|
13
|
+
})(GetAvailableUpgradesCommand || (exports.GetAvailableUpgradesCommand = GetAvailableUpgradesCommand = {}));
|
|
@@ -20,3 +20,6 @@ __exportStar(require("./create-subscription.command"), exports);
|
|
|
20
20
|
__exportStar(require("./find-subscription.command"), exports);
|
|
21
21
|
__exportStar(require("./cancel-subscription.command"), exports);
|
|
22
22
|
__exportStar(require("./recover-subscription.command"), exports);
|
|
23
|
+
__exportStar(require("./get-available-upgrades.command"), exports);
|
|
24
|
+
__exportStar(require("./update-subscription.command"), exports);
|
|
25
|
+
__exportStar(require("./create-custom-subscription-plan.command"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpgradeSubscriptionCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
var UpgradeSubscriptionCommand;
|
|
7
|
+
(function (UpgradeSubscriptionCommand) {
|
|
8
|
+
UpgradeSubscriptionCommand.RequestSchema = models_1.SubscriptionSchema.pick({
|
|
9
|
+
uuid: true,
|
|
10
|
+
});
|
|
11
|
+
const IReceiptOrderSchema = zod_1.z.object({
|
|
12
|
+
items: zod_1.z.array(zod_1.z.object({
|
|
13
|
+
label: zod_1.z.string(),
|
|
14
|
+
price: zod_1.z.number(),
|
|
15
|
+
quantity: zod_1.z.number(),
|
|
16
|
+
amount: zod_1.z.number(),
|
|
17
|
+
vat: zod_1.z.number(),
|
|
18
|
+
})),
|
|
19
|
+
email: zod_1.z.string(),
|
|
20
|
+
isBso: zod_1.z.boolean(),
|
|
21
|
+
amounts: zod_1.z.object({
|
|
22
|
+
electronic: zod_1.z.number(),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
UpgradeSubscriptionCommand.ResponseSchema = zod_1.z.object({
|
|
26
|
+
publicId: zod_1.z.string(),
|
|
27
|
+
amount: zod_1.z.number(),
|
|
28
|
+
currency: zod_1.z.string(),
|
|
29
|
+
accountId: zod_1.z.string(),
|
|
30
|
+
description: zod_1.z.string(),
|
|
31
|
+
invoiceId: zod_1.z.string(),
|
|
32
|
+
email: zod_1.z.string(),
|
|
33
|
+
skin: zod_1.z.string(),
|
|
34
|
+
autoClose: zod_1.z.number(),
|
|
35
|
+
data: zod_1.z.object({
|
|
36
|
+
CloudPayments: zod_1.z.object({
|
|
37
|
+
CustomerReceipt: IReceiptOrderSchema,
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
})(UpgradeSubscriptionCommand || (exports.UpgradeSubscriptionCommand = UpgradeSubscriptionCommand = {}));
|
|
@@ -515,4 +515,44 @@ exports.ERRORS = {
|
|
|
515
515
|
message: 'Электронная почта уже подтверждена',
|
|
516
516
|
httpCode: 400,
|
|
517
517
|
},
|
|
518
|
+
GET_UNREGISTERED_SESSION_ERROR: {
|
|
519
|
+
code: 'A117',
|
|
520
|
+
message: 'Не удалось получить сессию с данным идентификатором',
|
|
521
|
+
httpCode: 500,
|
|
522
|
+
},
|
|
523
|
+
UNREGISTERED_USER_LIMIT_UPDATE_ERROR: {
|
|
524
|
+
code: 'A118',
|
|
525
|
+
message: 'Не удалось обновить баланс пользователя',
|
|
526
|
+
httpCode: 500,
|
|
527
|
+
},
|
|
528
|
+
PAYMENT_HISTORY_ERROR: {
|
|
529
|
+
code: 'A119',
|
|
530
|
+
message: 'Не удалось получить историю платежей',
|
|
531
|
+
httpCode: 500,
|
|
532
|
+
},
|
|
533
|
+
SUBSCRIPTION_GET_UPGRADES_ERROR: {
|
|
534
|
+
code: 'A120',
|
|
535
|
+
message: 'Не удалось получить информацию о возможных улучшениях для подписки',
|
|
536
|
+
httpCode: 500,
|
|
537
|
+
},
|
|
538
|
+
SUBSCRIPTION_UPGRADE_ERROR: {
|
|
539
|
+
code: 'A121',
|
|
540
|
+
message: 'Не удалось улучшить подписку',
|
|
541
|
+
httpCode: 500,
|
|
542
|
+
},
|
|
543
|
+
RECURRENT_UPDATE_ERROR: {
|
|
544
|
+
code: 'A122',
|
|
545
|
+
message: 'Не удалось изменить данные подписки',
|
|
546
|
+
httpCode: 500,
|
|
547
|
+
},
|
|
548
|
+
ALREADY_HAS_SUBSCRIPTION: {
|
|
549
|
+
code: 'A123',
|
|
550
|
+
message: 'На данной учетной записи уже есть подписка',
|
|
551
|
+
httpCode: 409,
|
|
552
|
+
},
|
|
553
|
+
SUBSCRIPTION_UPGRADE_INVALID: {
|
|
554
|
+
code: 'A124',
|
|
555
|
+
message: 'Невозможно улучшить подписку с данными параметрами',
|
|
556
|
+
httpCode: 400,
|
|
557
|
+
},
|
|
518
558
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ORDER_TYPE = void 0;
|
|
4
|
+
var ORDER_TYPE;
|
|
5
|
+
(function (ORDER_TYPE) {
|
|
6
|
+
ORDER_TYPE["purchase"] = "purchase";
|
|
7
|
+
ORDER_TYPE["upgrade"] = "upgrade";
|
|
8
|
+
})(ORDER_TYPE || (exports.ORDER_TYPE = ORDER_TYPE = {}));
|
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./payment-status.enum"), exports);
|
|
18
|
+
__exportStar(require("./payment-history-item-type.enum"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PAYMENT_HISTORY_ITEM_TYPE = void 0;
|
|
4
|
+
var PAYMENT_HISTORY_ITEM_TYPE;
|
|
5
|
+
(function (PAYMENT_HISTORY_ITEM_TYPE) {
|
|
6
|
+
PAYMENT_HISTORY_ITEM_TYPE["SUBSCRIPTION"] = "subscription";
|
|
7
|
+
PAYMENT_HISTORY_ITEM_TYPE["PRODUCT"] = "product";
|
|
8
|
+
})(PAYMENT_HISTORY_ITEM_TYPE || (exports.PAYMENT_HISTORY_ITEM_TYPE = PAYMENT_HISTORY_ITEM_TYPE = {}));
|
|
@@ -15,3 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./subscription-status.enum"), exports);
|
|
18
|
+
__exportStar(require("./subscription-plan.enum"), exports);
|
|
19
|
+
__exportStar(require("./user-to-subscription-type.enum"), exports);
|
|
20
|
+
__exportStar(require("./subscription-type.enum"), exports);
|
|
21
|
+
__exportStar(require("./subscription-action.enum"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUBSCRIPTION_ACTION = void 0;
|
|
4
|
+
var SUBSCRIPTION_ACTION;
|
|
5
|
+
(function (SUBSCRIPTION_ACTION) {
|
|
6
|
+
SUBSCRIPTION_ACTION["disabled"] = "disabled";
|
|
7
|
+
SUBSCRIPTION_ACTION["buy"] = "buy";
|
|
8
|
+
SUBSCRIPTION_ACTION["upgrade"] = "upgrade";
|
|
9
|
+
SUBSCRIPTION_ACTION["possible_upgrade"] = "possible_upgrade";
|
|
10
|
+
})(SUBSCRIPTION_ACTION || (exports.SUBSCRIPTION_ACTION = SUBSCRIPTION_ACTION = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUBSCRIPTION_PLAN = void 0;
|
|
4
|
+
var SUBSCRIPTION_PLAN;
|
|
5
|
+
(function (SUBSCRIPTION_PLAN) {
|
|
6
|
+
SUBSCRIPTION_PLAN["system"] = "system";
|
|
7
|
+
SUBSCRIPTION_PLAN["custom"] = "custom";
|
|
8
|
+
})(SUBSCRIPTION_PLAN || (exports.SUBSCRIPTION_PLAN = SUBSCRIPTION_PLAN = {}));
|
|
@@ -6,4 +6,5 @@ var SUBSCRIPTION_STATUS;
|
|
|
6
6
|
SUBSCRIPTION_STATUS["active"] = "active";
|
|
7
7
|
SUBSCRIPTION_STATUS["canceled"] = "canceled";
|
|
8
8
|
SUBSCRIPTION_STATUS["expired"] = "expired";
|
|
9
|
+
SUBSCRIPTION_STATUS["upgraded"] = "upgraded";
|
|
9
10
|
})(SUBSCRIPTION_STATUS || (exports.SUBSCRIPTION_STATUS = SUBSCRIPTION_STATUS = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUBSCRIPTION_TYPE = void 0;
|
|
4
|
+
var SUBSCRIPTION_TYPE;
|
|
5
|
+
(function (SUBSCRIPTION_TYPE) {
|
|
6
|
+
SUBSCRIPTION_TYPE["main"] = "main";
|
|
7
|
+
SUBSCRIPTION_TYPE["sub"] = "sub";
|
|
8
|
+
})(SUBSCRIPTION_TYPE || (exports.SUBSCRIPTION_TYPE = SUBSCRIPTION_TYPE = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USER_TO_SUBSCRIPTION_TYPE = void 0;
|
|
4
|
+
var USER_TO_SUBSCRIPTION_TYPE;
|
|
5
|
+
(function (USER_TO_SUBSCRIPTION_TYPE) {
|
|
6
|
+
USER_TO_SUBSCRIPTION_TYPE["paid"] = "paid";
|
|
7
|
+
USER_TO_SUBSCRIPTION_TYPE["interval"] = "interval";
|
|
8
|
+
})(USER_TO_SUBSCRIPTION_TYPE || (exports.USER_TO_SUBSCRIPTION_TYPE = USER_TO_SUBSCRIPTION_TYPE = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./subscription"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcCustomSubscriptionPrice = calcCustomSubscriptionPrice;
|
|
4
|
+
function calcCustomSubscriptionPrice(tokenCount, period) {
|
|
5
|
+
const MIN_TOKEN_COUNT = 1000;
|
|
6
|
+
const MAX_DISCOUNT = 0.85;
|
|
7
|
+
const DISCOUNT_PER_STEP = 0.005;
|
|
8
|
+
const STEP = 500;
|
|
9
|
+
const BASE_PRICE = 0.95;
|
|
10
|
+
if (tokenCount < 0) {
|
|
11
|
+
throw new Error('Token count must be a non-negative integer');
|
|
12
|
+
}
|
|
13
|
+
if (tokenCount < MIN_TOKEN_COUNT) {
|
|
14
|
+
throw new Error(`Token count must be at least ${MIN_TOKEN_COUNT}`);
|
|
15
|
+
}
|
|
16
|
+
const discount = Math.max(0, (tokenCount - MIN_TOKEN_COUNT) / STEP) * DISCOUNT_PER_STEP;
|
|
17
|
+
const priceMultiplier = Math.max(BASE_PRICE - discount, MAX_DISCOUNT);
|
|
18
|
+
return Math.round(tokenCount * priceMultiplier * period);
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./calc-custom-subscription-price.helper"), exports);
|
package/build/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const zod_1 = require("zod");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
exports.MessageSchema = zod_1.z.object({
|
|
7
7
|
uuid: zod_1.z.string().uuid(),
|
|
8
|
-
text: zod_1.z.string(),
|
|
8
|
+
text: zod_1.z.string().max(10000),
|
|
9
9
|
chatId: zod_1.z.nullable(zod_1.z.string().uuid()),
|
|
10
10
|
role: zod_1.z.string(),
|
|
11
11
|
tokenUsage: zod_1.z.number(),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentHistoryItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
exports.PaymentHistoryItemSchema = zod_1.z.object({
|
|
7
|
+
uuid: zod_1.z.string().uuid(),
|
|
8
|
+
status: zod_1.z.nativeEnum(constants_1.PAYMENT_STATUS),
|
|
9
|
+
sum: zod_1.z.number(),
|
|
10
|
+
description: zod_1.z.string(),
|
|
11
|
+
type: zod_1.z.nativeEnum(constants_1.PAYMENT_HISTORY_ITEM_TYPE),
|
|
12
|
+
createdAt: zod_1.z.date(),
|
|
13
|
+
updatedAt: zod_1.z.date(),
|
|
14
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubscriptionUpgradeSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const subscription_schema_1 = require("./subscription.schema");
|
|
6
|
+
exports.SubscriptionUpgradeSchema = zod_1.z.intersection(subscription_schema_1.SubscriptionSchema, zod_1.z.object({
|
|
7
|
+
upgradePrice: zod_1.z.number(),
|
|
8
|
+
}));
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubscriptionSchema = void 0;
|
|
3
|
+
exports.SubscriptionWithSubTypesSchema = exports.SubscriptionWithActionSchema = exports.SubscriptionSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const product_schema_1 = require("./product.schema");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
exports.SubscriptionSchema = zod_1.z.object({
|
|
7
8
|
uuid: zod_1.z.string().uuid(),
|
|
9
|
+
mainSubscriptionId: zod_1.z.nullable(zod_1.z.string().uuid()),
|
|
8
10
|
name: zod_1.z.string().min(3).max(16384),
|
|
9
11
|
requests: zod_1.z.number(),
|
|
10
12
|
price: zod_1.z.number(),
|
|
11
13
|
features: zod_1.z.array(product_schema_1.FeaturesSchema),
|
|
12
|
-
|
|
14
|
+
plan: zod_1.z.nativeEnum(constants_1.SUBSCRIPTION_PLAN),
|
|
15
|
+
type: zod_1.z.nativeEnum(constants_1.SUBSCRIPTION_TYPE),
|
|
16
|
+
discount: zod_1.z.number(),
|
|
17
|
+
period: zod_1.z.number(),
|
|
18
|
+
tokens: zod_1.z.number(),
|
|
13
19
|
createdAt: zod_1.z.date(),
|
|
14
20
|
updatedAt: zod_1.z.date(),
|
|
15
21
|
});
|
|
22
|
+
exports.SubscriptionWithActionSchema = zod_1.z.intersection(exports.SubscriptionSchema, zod_1.z.object({
|
|
23
|
+
action: zod_1.z.nativeEnum(constants_1.SUBSCRIPTION_ACTION),
|
|
24
|
+
}));
|
|
25
|
+
exports.SubscriptionWithSubTypesSchema = zod_1.z.intersection(exports.SubscriptionWithActionSchema, zod_1.z.object({
|
|
26
|
+
subTypes: zod_1.z.array(exports.SubscriptionWithActionSchema),
|
|
27
|
+
}));
|
|
@@ -11,6 +11,7 @@ exports.UserToSubscriptionSchema = zod_1.z.object({
|
|
|
11
11
|
tokenBalance: zod_1.z.number(),
|
|
12
12
|
status: zod_1.z.string(),
|
|
13
13
|
endDate: zod_1.z.date().nullable(),
|
|
14
|
+
intervalEndDate: zod_1.z.date().nullable(),
|
|
14
15
|
createdAt: zod_1.z.date(),
|
|
15
16
|
updatedAt: zod_1.z.date(),
|
|
16
17
|
});
|
package/commands/index.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PaymentHistoryItemSchema } from '../../models/payment-history-item.schema';
|
|
3
|
+
|
|
4
|
+
export namespace GetPaymentHistoryCommand {
|
|
5
|
+
export const ResponseSchema = z.object({
|
|
6
|
+
data: z.array(PaymentHistoryItemSchema),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SubscriptionSchema } from '../../models';
|
|
3
|
+
|
|
4
|
+
export namespace CreateCustomSubscriptionPlanCommand {
|
|
5
|
+
export const RequestSchema = z.object({
|
|
6
|
+
tokens: z
|
|
7
|
+
.number()
|
|
8
|
+
.refine((val) => val % 500 === 0, {
|
|
9
|
+
message: 'tokens must be a multiple of 500',
|
|
10
|
+
})
|
|
11
|
+
.refine((val) => val > 1000, {
|
|
12
|
+
message: 'tokens must be greater than 1000',
|
|
13
|
+
})
|
|
14
|
+
.refine((val) => val <= 10000, {
|
|
15
|
+
message: 'tokens must be equal or less than 10000',
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
20
|
+
|
|
21
|
+
export const ResponseSchema = z.object({
|
|
22
|
+
data: SubscriptionSchema,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
26
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { SubscriptionSchema } from '../../models';
|
|
2
|
+
import { SubscriptionSchema, SubscriptionWithSubTypesSchema } from '../../models';
|
|
3
3
|
|
|
4
4
|
export namespace FindSubscriptionCommand {
|
|
5
5
|
export const RequestSchema = SubscriptionSchema.pick({
|
|
@@ -9,7 +9,7 @@ export namespace FindSubscriptionCommand {
|
|
|
9
9
|
export type Request = z.infer<typeof RequestSchema>;
|
|
10
10
|
|
|
11
11
|
export const ResponseSchema = z.object({
|
|
12
|
-
data: z.array(
|
|
12
|
+
data: z.array(SubscriptionWithSubTypesSchema),
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
export type Response = z.infer<typeof ResponseSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SubscriptionSchema } from '../../models';
|
|
3
|
+
import { SubscriptionUpgradeSchema } from '../../models/subscription-upgrade-schema';
|
|
4
|
+
|
|
5
|
+
export namespace GetAvailableUpgradesCommand {
|
|
6
|
+
export const RequestSchema = SubscriptionSchema.pick({});
|
|
7
|
+
|
|
8
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
9
|
+
|
|
10
|
+
export const ResponseSchema = z.object({
|
|
11
|
+
data: z.array(SubscriptionUpgradeSchema),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
15
|
+
}
|
|
@@ -4,3 +4,6 @@ export * from './create-subscription.command';
|
|
|
4
4
|
export * from './find-subscription.command';
|
|
5
5
|
export * from './cancel-subscription.command';
|
|
6
6
|
export * from './recover-subscription.command';
|
|
7
|
+
export * from './get-available-upgrades.command';
|
|
8
|
+
export * from './update-subscription.command';
|
|
9
|
+
export * from './create-custom-subscription-plan.command';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SubscriptionSchema } from '../../models';
|
|
3
|
+
|
|
4
|
+
export namespace UpgradeSubscriptionCommand {
|
|
5
|
+
export const RequestSchema = SubscriptionSchema.pick({
|
|
6
|
+
uuid: true,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
10
|
+
|
|
11
|
+
const IReceiptOrderSchema = z.object({
|
|
12
|
+
items: z.array(
|
|
13
|
+
z.object({
|
|
14
|
+
label: z.string(),
|
|
15
|
+
price: z.number(),
|
|
16
|
+
quantity: z.number(),
|
|
17
|
+
amount: z.number(),
|
|
18
|
+
vat: z.number(),
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
email: z.string(),
|
|
22
|
+
isBso: z.boolean(),
|
|
23
|
+
amounts: z.object({
|
|
24
|
+
electronic: z.number(),
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const ResponseSchema = z.object({
|
|
29
|
+
publicId: z.string(),
|
|
30
|
+
amount: z.number(),
|
|
31
|
+
currency: z.string(),
|
|
32
|
+
accountId: z.string(),
|
|
33
|
+
description: z.string(),
|
|
34
|
+
invoiceId: z.string(),
|
|
35
|
+
email: z.string(),
|
|
36
|
+
skin: z.string(),
|
|
37
|
+
autoClose: z.number(),
|
|
38
|
+
data: z.object({
|
|
39
|
+
CloudPayments: z.object({
|
|
40
|
+
CustomerReceipt: IReceiptOrderSchema,
|
|
41
|
+
}),
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
46
|
+
}
|
|
@@ -515,4 +515,44 @@ export const ERRORS = {
|
|
|
515
515
|
message: 'Электронная почта уже подтверждена',
|
|
516
516
|
httpCode: 400,
|
|
517
517
|
},
|
|
518
|
+
GET_UNREGISTERED_SESSION_ERROR: {
|
|
519
|
+
code: 'A117',
|
|
520
|
+
message: 'Не удалось получить сессию с данным идентификатором',
|
|
521
|
+
httpCode: 500,
|
|
522
|
+
},
|
|
523
|
+
UNREGISTERED_USER_LIMIT_UPDATE_ERROR: {
|
|
524
|
+
code: 'A118',
|
|
525
|
+
message: 'Не удалось обновить баланс пользователя',
|
|
526
|
+
httpCode: 500,
|
|
527
|
+
},
|
|
528
|
+
PAYMENT_HISTORY_ERROR: {
|
|
529
|
+
code: 'A119',
|
|
530
|
+
message: 'Не удалось получить историю платежей',
|
|
531
|
+
httpCode: 500,
|
|
532
|
+
},
|
|
533
|
+
SUBSCRIPTION_GET_UPGRADES_ERROR: {
|
|
534
|
+
code: 'A120',
|
|
535
|
+
message: 'Не удалось получить информацию о возможных улучшениях для подписки',
|
|
536
|
+
httpCode: 500,
|
|
537
|
+
},
|
|
538
|
+
SUBSCRIPTION_UPGRADE_ERROR: {
|
|
539
|
+
code: 'A121',
|
|
540
|
+
message: 'Не удалось улучшить подписку',
|
|
541
|
+
httpCode: 500,
|
|
542
|
+
},
|
|
543
|
+
RECURRENT_UPDATE_ERROR: {
|
|
544
|
+
code: 'A122',
|
|
545
|
+
message: 'Не удалось изменить данные подписки',
|
|
546
|
+
httpCode: 500,
|
|
547
|
+
},
|
|
548
|
+
ALREADY_HAS_SUBSCRIPTION: {
|
|
549
|
+
code: 'A123',
|
|
550
|
+
message: 'На данной учетной записи уже есть подписка',
|
|
551
|
+
httpCode: 409,
|
|
552
|
+
},
|
|
553
|
+
SUBSCRIPTION_UPGRADE_INVALID: {
|
|
554
|
+
code: 'A124',
|
|
555
|
+
message: 'Невозможно улучшить подписку с данными параметрами',
|
|
556
|
+
httpCode: 400,
|
|
557
|
+
},
|
|
518
558
|
};
|
package/helpers/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './subscription';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function calcCustomSubscriptionPrice(tokenCount: number, period: number) {
|
|
2
|
+
const MIN_TOKEN_COUNT = 1000;
|
|
3
|
+
const MAX_DISCOUNT = 0.85;
|
|
4
|
+
const DISCOUNT_PER_STEP = 0.005;
|
|
5
|
+
const STEP = 500;
|
|
6
|
+
const BASE_PRICE = 0.95;
|
|
7
|
+
|
|
8
|
+
if (tokenCount < 0) {
|
|
9
|
+
throw new Error('Token count must be a non-negative integer');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (tokenCount < MIN_TOKEN_COUNT) {
|
|
13
|
+
throw new Error(`Token count must be at least ${MIN_TOKEN_COUNT}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const discount = Math.max(0, (tokenCount - MIN_TOKEN_COUNT) / STEP) * DISCOUNT_PER_STEP;
|
|
17
|
+
const priceMultiplier = Math.max(BASE_PRICE - discount, MAX_DISCOUNT);
|
|
18
|
+
return Math.round(tokenCount * priceMultiplier * period);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './calc-custom-subscription-price.helper';
|
package/index.ts
CHANGED
package/models/message.schema.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PAYMENT_HISTORY_ITEM_TYPE, PAYMENT_STATUS } from '../constants';
|
|
3
|
+
|
|
4
|
+
export const PaymentHistoryItemSchema = z.object({
|
|
5
|
+
uuid: z.string().uuid(),
|
|
6
|
+
status: z.nativeEnum(PAYMENT_STATUS),
|
|
7
|
+
sum: z.number(),
|
|
8
|
+
description: z.string(),
|
|
9
|
+
type: z.nativeEnum(PAYMENT_HISTORY_ITEM_TYPE),
|
|
10
|
+
createdAt: z.date(),
|
|
11
|
+
updatedAt: z.date(),
|
|
12
|
+
});
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { FeaturesSchema } from './product.schema';
|
|
3
|
+
import { SUBSCRIPTION_ACTION, SUBSCRIPTION_PLAN, SUBSCRIPTION_TYPE } from '../constants';
|
|
3
4
|
|
|
4
5
|
export const SubscriptionSchema = z.object({
|
|
5
6
|
uuid: z.string().uuid(),
|
|
7
|
+
mainSubscriptionId: z.nullable(z.string().uuid()),
|
|
6
8
|
name: z.string().min(3).max(16384),
|
|
7
9
|
requests: z.number(),
|
|
8
10
|
price: z.number(),
|
|
9
11
|
features: z.array(FeaturesSchema),
|
|
10
|
-
|
|
12
|
+
plan: z.nativeEnum(SUBSCRIPTION_PLAN),
|
|
13
|
+
type: z.nativeEnum(SUBSCRIPTION_TYPE),
|
|
14
|
+
discount: z.number(),
|
|
15
|
+
period: z.number(),
|
|
16
|
+
tokens: z.number(),
|
|
11
17
|
createdAt: z.date(),
|
|
12
18
|
updatedAt: z.date(),
|
|
13
19
|
});
|
|
20
|
+
|
|
21
|
+
export const SubscriptionWithActionSchema = z.intersection(
|
|
22
|
+
SubscriptionSchema,
|
|
23
|
+
z.object({
|
|
24
|
+
action: z.nativeEnum(SUBSCRIPTION_ACTION),
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const SubscriptionWithSubTypesSchema = z.intersection(
|
|
29
|
+
SubscriptionWithActionSchema,
|
|
30
|
+
z.object({
|
|
31
|
+
subTypes: z.array(SubscriptionWithActionSchema),
|
|
32
|
+
}),
|
|
33
|
+
);
|