@purpleschool/gptbot 0.6.15 → 0.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/api/controllers/http/subscription.ts +1 -0
  2. package/build/api/controllers/http/subscription.js +1 -0
  3. package/build/commands/index.js +1 -0
  4. package/build/commands/subscription/index.js +1 -0
  5. package/build/commands/subscription/recover-past-due-subscription.command.js +13 -0
  6. package/build/commands/user/find-users-by-criteria.command.js +36 -6
  7. package/build/commands/user-to-product/index.js +17 -0
  8. package/build/commands/user-to-product/update-user-to-product.command.js +19 -0
  9. package/build/commands/user-to-subscription/index.js +1 -0
  10. package/build/commands/user-to-subscription/update-user-to-subscription.command.js +27 -0
  11. package/build/constants/errors/errors.js +5 -0
  12. package/build/constants/subscription/enums/user-to-subscription-marks.enum.js +1 -0
  13. package/build/models/filters.schema.js +16 -0
  14. package/build/models/index.js +1 -0
  15. package/commands/index.ts +1 -0
  16. package/commands/subscription/index.ts +1 -0
  17. package/commands/subscription/recover-past-due-subscription.command.ts +15 -0
  18. package/commands/user/find-users-by-criteria.command.ts +45 -7
  19. package/commands/user-to-product/index.ts +1 -0
  20. package/commands/user-to-product/update-user-to-product.command.ts +22 -0
  21. package/commands/user-to-subscription/index.ts +1 -0
  22. package/commands/user-to-subscription/update-user-to-subscription.command.ts +30 -0
  23. package/constants/errors/errors.ts +5 -0
  24. package/constants/subscription/enums/user-to-subscription-marks.enum.ts +1 -0
  25. package/models/filters.schema.ts +17 -0
  26. package/models/index.ts +1 -0
  27. package/package.json +1 -1
@@ -15,4 +15,5 @@ export const SUBSCRIPTION_ROUTES = {
15
15
  CREATE_CUSTOM: 'custom',
16
16
  FREE: 'free',
17
17
  SUMMARY: 'summary',
18
+ RECOVER_PAST_DUE: (uuid: string) => `${uuid}/recover-past-due`,
18
19
  } as const;
@@ -16,4 +16,5 @@ exports.SUBSCRIPTION_ROUTES = {
16
16
  CREATE_CUSTOM: 'custom',
17
17
  FREE: 'free',
18
18
  SUMMARY: 'summary',
19
+ RECOVER_PAST_DUE: (uuid) => `${uuid}/recover-past-due`,
19
20
  };
@@ -50,3 +50,4 @@ __exportStar(require("./prompt-category"), exports);
50
50
  __exportStar(require("./prompt-topic"), exports);
51
51
  __exportStar(require("./prompt"), exports);
52
52
  __exportStar(require("./folder"), exports);
53
+ __exportStar(require("./user-to-product"), exports);
@@ -23,6 +23,7 @@ __exportStar(require("./find-subscription.command"), exports);
23
23
  __exportStar(require("./get-available-upgrades.command"), exports);
24
24
  __exportStar(require("./get-free-subscription.command"), exports);
25
25
  __exportStar(require("./get-subscriptions-summary.command"), exports);
26
+ __exportStar(require("./recover-past-due-subscription.command"), exports);
26
27
  __exportStar(require("./recover-subscription.command"), exports);
27
28
  __exportStar(require("./update-subscription.command"), exports);
28
29
  __exportStar(require("./upgrade-subscription.command"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecoverPastDueSubscriptionCommand = void 0;
4
+ const zod_1 = require("zod");
5
+ var RecoverPastDueSubscriptionCommand;
6
+ (function (RecoverPastDueSubscriptionCommand) {
7
+ RecoverPastDueSubscriptionCommand.RequestParamSchema = zod_1.z.object({
8
+ uuid: zod_1.z.string().uuid(),
9
+ });
10
+ RecoverPastDueSubscriptionCommand.ResponseSchema = zod_1.z.object({
11
+ message: zod_1.z.string(),
12
+ });
13
+ })(RecoverPastDueSubscriptionCommand || (exports.RecoverPastDueSubscriptionCommand = RecoverPastDueSubscriptionCommand = {}));
@@ -9,24 +9,54 @@ const models_1 = require("../../models");
9
9
  const constants_1 = require("../../constants");
10
10
  var FindUsersByCriteriaCommand;
11
11
  (function (FindUsersByCriteriaCommand) {
12
- FindUsersByCriteriaCommand.RequestSchema = zod_1.default
13
- .object({
12
+ FindUsersByCriteriaCommand.RequestSchema = zod_1.default.preprocess((input) => {
13
+ if (input && typeof input === 'object' && !Array.isArray(input)) {
14
+ const obj = Object.assign({}, input);
15
+ const onlyNormalize = ['createdAt', 'updatedAt', 'tokenBonusBalance'];
16
+ const relevantBracketed = Object.keys(obj).some((key) => {
17
+ const match = key.match(/^(\w+)\[(\w+)\]$/);
18
+ return match && onlyNormalize.includes(match[1]);
19
+ });
20
+ if (!relevantBracketed) {
21
+ return obj;
22
+ }
23
+ const result = Object.assign({}, obj);
24
+ for (const key of Object.keys(obj)) {
25
+ const match = key.match(/^(\w+)\[(\w+)\]$/);
26
+ if (match && onlyNormalize.includes(match[1])) {
27
+ const [, outer, inner] = match;
28
+ result[outer] = result[outer] || {};
29
+ result[outer][inner] = obj[key];
30
+ delete result[key];
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ return input;
36
+ }, zod_1.default.object({
14
37
  uuid: zod_1.default.string().uuid().optional(),
15
38
  email: zod_1.default.string().email().optional(),
16
39
  status: zod_1.default.nativeEnum(constants_1.USER_STATUS).optional(),
17
40
  role: zod_1.default.nativeEnum(constants_1.ROLE).optional(),
18
- createdAt: zod_1.default.date().optional(),
19
- updatedAt: zod_1.default.date().optional(),
41
+ telegramId: zod_1.default.coerce.number().optional(),
42
+ createdAt: models_1.DateFilter.optional(),
43
+ updatedAt: models_1.DateFilter.optional(),
44
+ tokenBonusBalance: models_1.NumberFilter.optional(),
20
45
  sortBy: zod_1.default.nativeEnum(constants_1.USER_SORT_BY).optional(),
21
46
  sortOrder: zod_1.default.nativeEnum(constants_1.SORT_ORDER).default(constants_1.SORT_ORDER.DESC).optional(),
22
- })
23
- .partial();
47
+ limit: zod_1.default.coerce.number().min(1),
48
+ offset: zod_1.default.coerce.number().min(0).default(0),
49
+ }));
24
50
  FindUsersByCriteriaCommand.ResponseSchema = zod_1.default.object({
25
51
  data: zod_1.default.array(models_1.UserSchema.omit({
26
52
  verifyTokenHash: true,
27
53
  password: true,
28
54
  passwordHash: true,
29
55
  restoreTokenHash: true,
56
+ }).extend({
57
+ telegramId: zod_1.default.number().nullable(),
30
58
  })),
59
+ page: zod_1.default.number(),
60
+ totalPages: zod_1.default.number(),
31
61
  });
32
62
  })(FindUsersByCriteriaCommand || (exports.FindUsersByCriteriaCommand = FindUsersByCriteriaCommand = {}));
@@ -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("./update-user-to-product.command"), exports);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateUserToProductCommand = void 0;
4
+ const zod_1 = require("zod");
5
+ const models_1 = require("../../models");
6
+ var UpdateUserToProductCommand;
7
+ (function (UpdateUserToProductCommand) {
8
+ UpdateUserToProductCommand.RequestParamSchema = models_1.UserToProductSchema.pick({
9
+ uuid: true,
10
+ });
11
+ UpdateUserToProductCommand.RequestSchema = models_1.UserToProductSchema.pick({
12
+ initTokenBalance: true,
13
+ tokenBalance: true,
14
+ status: true,
15
+ }).partial();
16
+ UpdateUserToProductCommand.ResponseSchema = zod_1.z.object({
17
+ data: UpdateUserToProductCommand.RequestParamSchema,
18
+ });
19
+ })(UpdateUserToProductCommand || (exports.UpdateUserToProductCommand = UpdateUserToProductCommand = {}));
@@ -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("./get-user-to-subscriptions.command"), exports);
18
+ __exportStar(require("./update-user-to-subscription.command"), exports);
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateUserToSubscriptionCommand = void 0;
4
+ const zod_1 = require("zod");
5
+ const models_1 = require("../../models");
6
+ var UpdateUserToSubscriptionCommand;
7
+ (function (UpdateUserToSubscriptionCommand) {
8
+ UpdateUserToSubscriptionCommand.RequestParamSchema = models_1.UserToSubscriptionSchema.pick({
9
+ uuid: true,
10
+ });
11
+ UpdateUserToSubscriptionCommand.RequestSchema = zod_1.z
12
+ .object({
13
+ userId: zod_1.z.string().uuid(),
14
+ subscriptionId: zod_1.z.string(),
15
+ initTokenBalance: zod_1.z.number(),
16
+ active: zod_1.z.coerce.boolean(),
17
+ tokenBalance: zod_1.z.number(),
18
+ status: zod_1.z.string(),
19
+ endDate: zod_1.z.coerce.date().nullable(),
20
+ marks: zod_1.z.array(zod_1.z.string()),
21
+ intervalEndDate: zod_1.z.coerce.date().nullable(),
22
+ })
23
+ .partial();
24
+ UpdateUserToSubscriptionCommand.ResponseSchema = zod_1.z.object({
25
+ data: models_1.UserToSubscriptionSchema,
26
+ });
27
+ })(UpdateUserToSubscriptionCommand || (exports.UpdateUserToSubscriptionCommand = UpdateUserToSubscriptionCommand = {}));
@@ -1493,4 +1493,9 @@ exports.ERRORS = {
1493
1493
  message: 'Промпт тема с таким alias уже существует',
1494
1494
  httpCode: 409,
1495
1495
  },
1496
+ SUBSCRIPTION_NOT_PAST_DUE: {
1497
+ code: 'A320',
1498
+ message: 'Подписка не требует повторной оплаты',
1499
+ httpCode: 400,
1500
+ },
1496
1501
  };
@@ -6,4 +6,5 @@ var USER_TO_SUBSCRIPTION_MARKS;
6
6
  USER_TO_SUBSCRIPTION_MARKS["WITHOUT_AUTO_RENEWAL"] = "WITHOUT_AUTO_RENEWAL";
7
7
  USER_TO_SUBSCRIPTION_MARKS["MOCK"] = "MOCK";
8
8
  USER_TO_SUBSCRIPTION_MARKS["SENT_RENEWAL_REMINDER"] = "SENT_RENEWAL_REMINDER";
9
+ USER_TO_SUBSCRIPTION_MARKS["SENT_PAST_DUE_RECOVER_REQUEST"] = "SENT_PAST_DUE_RECOVER_REQUEST";
9
10
  })(USER_TO_SUBSCRIPTION_MARKS || (exports.USER_TO_SUBSCRIPTION_MARKS = USER_TO_SUBSCRIPTION_MARKS = {}));
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberFilter = exports.DateFilter = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.DateFilter = zod_1.z.object({
6
+ gt: zod_1.z.coerce.date().optional(),
7
+ gte: zod_1.z.coerce.date().optional(),
8
+ lt: zod_1.z.coerce.date().optional(),
9
+ lte: zod_1.z.coerce.date().optional(),
10
+ });
11
+ exports.NumberFilter = zod_1.z.object({
12
+ gt: zod_1.z.coerce.number().optional(),
13
+ gte: zod_1.z.coerce.number().optional(),
14
+ lt: zod_1.z.coerce.number().optional(),
15
+ lte: zod_1.z.coerce.number().optional(),
16
+ });
@@ -62,3 +62,4 @@ __exportStar(require("./prompt-category.schema"), exports);
62
62
  __exportStar(require("./prompt-topic.schema"), exports);
63
63
  __exportStar(require("./prompt.schema"), exports);
64
64
  __exportStar(require("./folder.schema"), exports);
65
+ __exportStar(require("./filters.schema"), exports);
package/commands/index.ts CHANGED
@@ -34,3 +34,4 @@ export * from './prompt-category';
34
34
  export * from './prompt-topic';
35
35
  export * from './prompt';
36
36
  export * from './folder';
37
+ export * from './user-to-product';
@@ -7,6 +7,7 @@ export * from './find-subscription.command';
7
7
  export * from './get-available-upgrades.command';
8
8
  export * from './get-free-subscription.command';
9
9
  export * from './get-subscriptions-summary.command';
10
+ export * from './recover-past-due-subscription.command';
10
11
  export * from './recover-subscription.command';
11
12
  export * from './update-subscription.command';
12
13
  export * from './upgrade-subscription.command';
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+
3
+ export namespace RecoverPastDueSubscriptionCommand {
4
+ export const RequestParamSchema = z.object({
5
+ uuid: z.string().uuid(),
6
+ });
7
+
8
+ export type RequestParam = z.infer<typeof RequestParamSchema>;
9
+
10
+ export const ResponseSchema = z.object({
11
+ message: z.string(),
12
+ });
13
+
14
+ export type Response = z.infer<typeof ResponseSchema>;
15
+ }
@@ -1,21 +1,55 @@
1
1
  import z from 'zod';
2
- import { UserSchema } from '../../models';
2
+ import { DateFilter, NumberFilter, UserSchema } from '../../models';
3
3
  import { ROLE, SORT_ORDER, USER_SORT_BY, USER_STATUS } from '../../constants';
4
4
 
5
5
  export namespace FindUsersByCriteriaCommand {
6
- export const RequestSchema = z
7
- .object({
6
+ export const RequestSchema = z.preprocess(
7
+ (input) => {
8
+ if (input && typeof input === 'object' && !Array.isArray(input)) {
9
+ const obj = { ...input } as Record<string, any>;
10
+ const onlyNormalize = ['createdAt', 'updatedAt', 'tokenBonusBalance'];
11
+
12
+ const relevantBracketed = Object.keys(obj).some((key) => {
13
+ const match = key.match(/^(\w+)\[(\w+)\]$/);
14
+ return match && onlyNormalize.includes(match[1]);
15
+ });
16
+
17
+ if (!relevantBracketed) {
18
+ return obj;
19
+ }
20
+
21
+ const result = { ...obj };
22
+ for (const key of Object.keys(obj)) {
23
+ const match = key.match(/^(\w+)\[(\w+)\]$/);
24
+ if (match && onlyNormalize.includes(match[1])) {
25
+ const [, outer, inner] = match;
26
+ result[outer] = result[outer] || {};
27
+ result[outer][inner] = obj[key];
28
+ delete result[key];
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ return input;
34
+ },
35
+ z.object({
8
36
  uuid: z.string().uuid().optional(),
9
37
  email: z.string().email().optional(),
10
38
  status: z.nativeEnum(USER_STATUS).optional(),
11
39
  role: z.nativeEnum(ROLE).optional(),
12
- createdAt: z.date().optional(),
13
- updatedAt: z.date().optional(),
40
+ telegramId: z.coerce.number().optional(),
41
+
42
+ createdAt: DateFilter.optional(),
43
+ updatedAt: DateFilter.optional(),
44
+ tokenBonusBalance: NumberFilter.optional(),
14
45
 
15
46
  sortBy: z.nativeEnum(USER_SORT_BY).optional(),
16
47
  sortOrder: z.nativeEnum(SORT_ORDER).default(SORT_ORDER.DESC).optional(),
17
- })
18
- .partial();
48
+
49
+ limit: z.coerce.number().min(1),
50
+ offset: z.coerce.number().min(0).default(0),
51
+ }),
52
+ );
19
53
 
20
54
  export type Request = z.infer<typeof RequestSchema>;
21
55
 
@@ -26,8 +60,12 @@ export namespace FindUsersByCriteriaCommand {
26
60
  password: true,
27
61
  passwordHash: true,
28
62
  restoreTokenHash: true,
63
+ }).extend({
64
+ telegramId: z.number().nullable(),
29
65
  }),
30
66
  ),
67
+ page: z.number(),
68
+ totalPages: z.number(),
31
69
  });
32
70
 
33
71
  export type Response = z.infer<typeof ResponseSchema>;
@@ -0,0 +1 @@
1
+ export * from './update-user-to-product.command';
@@ -0,0 +1,22 @@
1
+ import { z } from 'zod';
2
+ import { UserToProductSchema } from '../../models';
3
+
4
+ export namespace UpdateUserToProductCommand {
5
+ export const RequestParamSchema = UserToProductSchema.pick({
6
+ uuid: true,
7
+ });
8
+
9
+ export type RequestParam = z.infer<typeof RequestParamSchema>;
10
+
11
+ export const RequestSchema = UserToProductSchema.pick({
12
+ initTokenBalance: true,
13
+ tokenBalance: true,
14
+ status: true,
15
+ }).partial();
16
+
17
+ export const ResponseSchema = z.object({
18
+ data: RequestParamSchema,
19
+ });
20
+
21
+ export type Response = z.infer<typeof ResponseSchema>;
22
+ }
@@ -1 +1,2 @@
1
1
  export * from './get-user-to-subscriptions.command';
2
+ export * from './update-user-to-subscription.command';
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ import { UserToSubscriptionSchema } from '../../models';
3
+
4
+ export namespace UpdateUserToSubscriptionCommand {
5
+ export const RequestParamSchema = UserToSubscriptionSchema.pick({
6
+ uuid: true,
7
+ });
8
+
9
+ export type RequestParam = z.infer<typeof RequestParamSchema>;
10
+
11
+ export const RequestSchema = z
12
+ .object({
13
+ userId: z.string().uuid(),
14
+ subscriptionId: z.string(),
15
+ initTokenBalance: z.number(),
16
+ active: z.coerce.boolean(),
17
+ tokenBalance: z.number(),
18
+ status: z.string(),
19
+ endDate: z.coerce.date().nullable(),
20
+ marks: z.array(z.string()),
21
+ intervalEndDate: z.coerce.date().nullable(),
22
+ })
23
+ .partial();
24
+
25
+ export const ResponseSchema = z.object({
26
+ data: UserToSubscriptionSchema,
27
+ });
28
+
29
+ export type Response = z.infer<typeof ResponseSchema>;
30
+ }
@@ -1500,4 +1500,9 @@ export const ERRORS = {
1500
1500
  message: 'Промпт тема с таким alias уже существует',
1501
1501
  httpCode: 409,
1502
1502
  },
1503
+ SUBSCRIPTION_NOT_PAST_DUE: {
1504
+ code: 'A320',
1505
+ message: 'Подписка не требует повторной оплаты',
1506
+ httpCode: 400,
1507
+ },
1503
1508
  };
@@ -2,4 +2,5 @@ export enum USER_TO_SUBSCRIPTION_MARKS {
2
2
  WITHOUT_AUTO_RENEWAL = 'WITHOUT_AUTO_RENEWAL',
3
3
  MOCK = 'MOCK',
4
4
  SENT_RENEWAL_REMINDER = 'SENT_RENEWAL_REMINDER',
5
+ SENT_PAST_DUE_RECOVER_REQUEST = 'SENT_PAST_DUE_RECOVER_REQUEST',
5
6
  }
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+
3
+ export const DateFilter = z.object({
4
+ gt: z.coerce.date().optional(),
5
+ gte: z.coerce.date().optional(),
6
+ lt: z.coerce.date().optional(),
7
+ lte: z.coerce.date().optional(),
8
+ });
9
+ export type DateFilter = z.infer<typeof DateFilter>;
10
+
11
+ export const NumberFilter = z.object({
12
+ gt: z.coerce.number().optional(),
13
+ gte: z.coerce.number().optional(),
14
+ lt: z.coerce.number().optional(),
15
+ lte: z.coerce.number().optional(),
16
+ });
17
+ export type NumberFilter = z.infer<typeof NumberFilter>;
package/models/index.ts CHANGED
@@ -46,3 +46,4 @@ export * from './prompt-category.schema';
46
46
  export * from './prompt-topic.schema';
47
47
  export * from './prompt.schema';
48
48
  export * from './folder.schema';
49
+ export * from './filters.schema';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.6.15",
3
+ "version": "0.6.17",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",