@purpleschool/gptbot 0.9.40 → 0.9.41

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.
@@ -1,6 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateVideoEditingPrice = calculateVideoEditingPrice;
4
- function calculateVideoEditingPrice({ pricePerCall }) {
5
- return pricePerCall;
4
+ const constants_1 = require("../../constants");
5
+ function matchesCondition(condition, params) {
6
+ const keys = Object.keys(condition);
7
+ return keys.every((key) => {
8
+ const expected = condition[key];
9
+ if (expected === undefined || expected === null || expected === '') {
10
+ return true;
11
+ }
12
+ const value = params[key];
13
+ if (value === undefined || value === null) {
14
+ return false;
15
+ }
16
+ return value === expected;
17
+ });
18
+ }
19
+ function calculateVideoEditingPrice({ pricePerCall, params, rules, }) {
20
+ const perSecondRule = rules
21
+ .filter((r) => r.type === constants_1.VIDEO_EDITOR_PRICING_RULE_TYPE.PER_SECOND)
22
+ .find((r) => matchesCondition(r.condition, params));
23
+ const base = perSecondRule ? perSecondRule.value * params.duration : pricePerCall;
24
+ const flatMarkup = rules.reduce((sum, r) => {
25
+ if (r.type !== constants_1.VIDEO_EDITOR_PRICING_RULE_TYPE.FLAT) {
26
+ return sum;
27
+ }
28
+ return matchesCondition(r.condition, params) ? sum + r.value : sum;
29
+ }, 0);
30
+ return Math.ceil(base + flatMarkup);
6
31
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VideoEditorModelSchema = exports.VideoEditorModelParamsSchema = void 0;
3
+ exports.VideoEditorModelSchema = exports.VideoEditorModelPricingRulesSchema = exports.VideoEditorModelPricingRuleConditionSchema = exports.VideoEditorPricingRequestParamsSchema = exports.VideoEditorModelParamsSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const video_editor_model_limitation_enum_1 = require("../../../constants/tool-video-editor/enums/video-editor-model-limitation.enum");
6
6
  const video_editor_pricing_rule_type_enum_1 = require("../../../constants/tool-video-editor/enums/video-editor-pricing-rule-type.enum");
@@ -18,6 +18,19 @@ exports.VideoEditorModelParamsSchema = zod_1.z.object({
18
18
  })
19
19
  .optional(),
20
20
  });
21
+ exports.VideoEditorPricingRequestParamsSchema = zod_1.z.object({
22
+ duration: zod_1.z.number(),
23
+ resolution: zod_1.z.string().optional(),
24
+ });
25
+ exports.VideoEditorModelPricingRuleConditionSchema = zod_1.z.object({
26
+ duration: zod_1.z.number().optional(),
27
+ resolution: zod_1.z.string().optional(),
28
+ });
29
+ exports.VideoEditorModelPricingRulesSchema = zod_1.z.array(zod_1.z.object({
30
+ type: zod_1.z.nativeEnum(video_editor_pricing_rule_type_enum_1.VIDEO_EDITOR_PRICING_RULE_TYPE),
31
+ condition: exports.VideoEditorModelPricingRuleConditionSchema,
32
+ value: zod_1.z.number(),
33
+ }));
21
34
  exports.VideoEditorModelSchema = zod_1.z.object({
22
35
  uuid: zod_1.z.string(),
23
36
  title: zod_1.z.string(),
@@ -31,14 +44,7 @@ exports.VideoEditorModelSchema = zod_1.z.object({
31
44
  maxInputVideoDurationInSeconds: zod_1.z.number(),
32
45
  supportedFormats: zod_1.z.array(zod_1.z.string()),
33
46
  params: exports.VideoEditorModelParamsSchema,
34
- pricingRules: zod_1.z.array(zod_1.z.object({
35
- type: zod_1.z.nativeEnum(video_editor_pricing_rule_type_enum_1.VIDEO_EDITOR_PRICING_RULE_TYPE),
36
- condition: zod_1.z.object({
37
- duration: zod_1.z.number().optional(),
38
- resolution: zod_1.z.string().optional(),
39
- }),
40
- value: zod_1.z.number(),
41
- })),
47
+ pricingRules: exports.VideoEditorModelPricingRulesSchema,
42
48
  createdAt: zod_1.z.date(),
43
49
  updatedAt: zod_1.z.date(),
44
50
  unlockedBy: unlocked_by_subscription_schema_1.UnlockedBySchema.nullable(),
@@ -1,3 +1,53 @@
1
- export function calculateVideoEditingPrice({ pricePerCall }: { pricePerCall: number }) {
2
- return pricePerCall;
1
+ import { VIDEO_EDITOR_PRICING_RULE_TYPE } from '../../constants';
2
+ import {
3
+ VideoEditorModelPricingRuleCondition,
4
+ VideoEditorModelPricingRules,
5
+ VideoEditorPricingRequestParams,
6
+ } from '../../models';
7
+
8
+ function matchesCondition(
9
+ condition: VideoEditorModelPricingRuleCondition,
10
+ params: VideoEditorPricingRequestParams,
11
+ ): boolean {
12
+ const keys = Object.keys(condition) as (keyof VideoEditorModelPricingRuleCondition)[];
13
+
14
+ return keys.every((key) => {
15
+ const expected = condition[key];
16
+ if (expected === undefined || expected === null || expected === '') {
17
+ return true;
18
+ }
19
+
20
+ const value = params[key];
21
+ if (value === undefined || value === null) {
22
+ return false;
23
+ }
24
+
25
+ return value === expected;
26
+ });
27
+ }
28
+
29
+ export function calculateVideoEditingPrice({
30
+ pricePerCall,
31
+ params,
32
+ rules,
33
+ }: {
34
+ pricePerCall: number;
35
+ params: VideoEditorPricingRequestParams;
36
+ rules: VideoEditorModelPricingRules;
37
+ }): number {
38
+ const perSecondRule = rules
39
+ .filter((r) => r.type === VIDEO_EDITOR_PRICING_RULE_TYPE.PER_SECOND)
40
+ .find((r) => matchesCondition(r.condition, params));
41
+
42
+ const base = perSecondRule ? perSecondRule.value * params.duration : pricePerCall;
43
+
44
+ const flatMarkup = rules.reduce((sum, r) => {
45
+ if (r.type !== VIDEO_EDITOR_PRICING_RULE_TYPE.FLAT) {
46
+ return sum;
47
+ }
48
+
49
+ return matchesCondition(r.condition, params) ? sum + r.value : sum;
50
+ }, 0);
51
+
52
+ return Math.ceil(base + flatMarkup);
3
53
  }
@@ -17,6 +17,29 @@ export const VideoEditorModelParamsSchema = z.object({
17
17
  .optional(),
18
18
  });
19
19
 
20
+ export const VideoEditorPricingRequestParamsSchema = z.object({
21
+ duration: z.number(),
22
+ resolution: z.string().optional(),
23
+ });
24
+ export type VideoEditorPricingRequestParams = z.infer<typeof VideoEditorPricingRequestParamsSchema>;
25
+
26
+ export const VideoEditorModelPricingRuleConditionSchema = z.object({
27
+ duration: z.number().optional(),
28
+ resolution: z.string().optional(),
29
+ });
30
+ export type VideoEditorModelPricingRuleCondition = z.infer<
31
+ typeof VideoEditorModelPricingRuleConditionSchema
32
+ >;
33
+
34
+ export const VideoEditorModelPricingRulesSchema = z.array(
35
+ z.object({
36
+ type: z.nativeEnum(VIDEO_EDITOR_PRICING_RULE_TYPE),
37
+ condition: VideoEditorModelPricingRuleConditionSchema,
38
+ value: z.number(),
39
+ }),
40
+ );
41
+ export type VideoEditorModelPricingRules = z.infer<typeof VideoEditorModelPricingRulesSchema>;
42
+
20
43
  export const VideoEditorModelSchema = z.object({
21
44
  uuid: z.string(),
22
45
  title: z.string(),
@@ -30,16 +53,7 @@ export const VideoEditorModelSchema = z.object({
30
53
  maxInputVideoDurationInSeconds: z.number(),
31
54
  supportedFormats: z.array(z.string()),
32
55
  params: VideoEditorModelParamsSchema,
33
- pricingRules: z.array(
34
- z.object({
35
- type: z.nativeEnum(VIDEO_EDITOR_PRICING_RULE_TYPE),
36
- condition: z.object({
37
- duration: z.number().optional(),
38
- resolution: z.string().optional(),
39
- }),
40
- value: z.number(),
41
- }),
42
- ),
56
+ pricingRules: VideoEditorModelPricingRulesSchema,
43
57
  createdAt: z.date(),
44
58
  updatedAt: z.date(),
45
59
  unlockedBy: UnlockedBySchema.nullable(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.9.40",
3
+ "version": "0.9.41",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",