vidspotai-shared 1.0.27 → 1.0.28
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/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/kling/kling.service.js +2 -3
- package/lib/services/aiGen/providers/openai/openai.service.d.ts +1 -1
- package/lib/services/aiGen/providers/openai/openai.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/openai/openai.service.js +3 -4
- package/lib/services/credit.service.d.ts.map +1 -1
- package/lib/services/credit.service.js +2 -0
- package/lib/utils/logger.d.ts +6 -0
- package/lib/utils/logger.d.ts.map +1 -0
- package/lib/utils/logger.js +87 -0
- package/package.json +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kling.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/kling/kling.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAWlB,qBAAa,YAAa,SAAQ,wBAAwB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;YAWnB,OAAO;IA6Bf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IA8B3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA8DjD,cAAc,IAAI,MAAM;IAexB,aAAa,CAAC,EACZ,QAAQ,EACR,IAA8B,EAC9B,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"kling.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/kling/kling.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAWlB,qBAAa,YAAa,SAAQ,wBAAwB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;YAWnB,OAAO;IA6Bf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IA8B3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA8DjD,cAAc,IAAI,MAAM;IAexB,aAAa,CAAC,EACZ,QAAQ,EACR,IAA8B,EAC9B,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;CAK9B"}
|
|
@@ -116,9 +116,8 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
116
116
|
}
|
|
117
117
|
getCreditUsed({ modelKey, mode = types_2.EVideoMode.PROFESSIONAL, duration = 5, }) {
|
|
118
118
|
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
: 0;
|
|
119
|
+
const cost = modelConfig?.cost?.table?.[mode]?.[duration];
|
|
120
|
+
return (0, helpers_2.getCreditsFromCost)(cost ?? 0);
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
exports.KlingService = KlingService;
|
|
@@ -7,6 +7,6 @@ export declare class OpenaiService extends BaseAiGenProviderService {
|
|
|
7
7
|
generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
8
8
|
checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult>;
|
|
9
9
|
generateText(params: TextGenerationParams): Promise<TextGenerationResult>;
|
|
10
|
-
getCreditUsed({ modelKey, duration }: CreditUsageParams): number;
|
|
10
|
+
getCreditUsed({ modelKey, resolution, duration, }: CreditUsageParams): number;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=openai.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/openai/openai.service.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,MAAM,CAAS;;IAQjB,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAoB3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsC3C,YAAY,CAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IA2ChC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"openai.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/openai/openai.service.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,MAAM,CAAS;;IAQjB,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAoB3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsC3C,YAAY,CAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IA2ChC,aAAa,CAAC,EACZ,QAAQ,EACR,UAAuB,EACvB,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;CAK9B"}
|
|
@@ -102,11 +102,10 @@ class OpenaiService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
102
102
|
text,
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
getCreditUsed({ modelKey, duration = 5 }) {
|
|
105
|
+
getCreditUsed({ modelKey, resolution = "720x1280", duration = 5, }) {
|
|
106
106
|
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: 0;
|
|
107
|
+
const cost = modelConfig?.cost?.table?.[resolution]?.[duration];
|
|
108
|
+
return (0, utils_1.getCreditsFromCost)(cost ?? 0);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
exports.OpenaiService = OpenaiService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../src/services/credit.service.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;WACX,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../src/services/credit.service.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;WACX,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;CAwBjB"}
|
|
@@ -14,6 +14,8 @@ class CreditService {
|
|
|
14
14
|
const credits = snap.data()?.credits;
|
|
15
15
|
const consumed = credits?.consumed ?? 0;
|
|
16
16
|
const total = credits?.total ?? 0;
|
|
17
|
+
// console.log(`Consuming ${creditsToConsume} credits for user ${userId}`);
|
|
18
|
+
// console.log(`Current credits: ${consumed}/${total}`);
|
|
17
19
|
// 🔒 HARD INVARIANT
|
|
18
20
|
if (consumed + creditsToConsume > total) {
|
|
19
21
|
throw new Error("INSUFFICIENT_CREDITS");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAsF1C;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,MAUnB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
const winston_1 = __importDefault(require("winston"));
|
|
8
|
+
const winston_slack_webhook_transport_1 = __importDefault(require("winston-slack-webhook-transport"));
|
|
9
|
+
const { combine, timestamp, errors, printf, colorize, json } = winston_1.default.format;
|
|
10
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
11
|
+
/**
|
|
12
|
+
* Console log format
|
|
13
|
+
*/
|
|
14
|
+
const consoleFormat = combine(colorize(), timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), printf((info) => {
|
|
15
|
+
const { timestamp, level, message, stack, ...meta } = info;
|
|
16
|
+
return `${timestamp} [${level}]: ${stack ?? message}${Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : ""}`;
|
|
17
|
+
}));
|
|
18
|
+
/**
|
|
19
|
+
* Slack transport (ERROR ONLY)
|
|
20
|
+
*/
|
|
21
|
+
const slackTransport = new winston_slack_webhook_transport_1.default({
|
|
22
|
+
webhookUrl: process.env.SLACK_WEBHOOK_URL,
|
|
23
|
+
level: "error",
|
|
24
|
+
// IMPORTANT: do not narrow the parameter type
|
|
25
|
+
formatter: (info) => {
|
|
26
|
+
const log = info;
|
|
27
|
+
return {
|
|
28
|
+
text: `🚨 *${process.env.SERVICE_NAME ?? "Service"} Error*`,
|
|
29
|
+
blocks: [
|
|
30
|
+
{
|
|
31
|
+
type: "header",
|
|
32
|
+
text: {
|
|
33
|
+
type: "plain_text",
|
|
34
|
+
text: "🚨 Application Error",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "section",
|
|
39
|
+
fields: [
|
|
40
|
+
{
|
|
41
|
+
type: "mrkdwn",
|
|
42
|
+
text: `*Service:*\n${process.env.SERVICE_NAME ?? "unknown"}`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "mrkdwn",
|
|
46
|
+
text: `*Environment:*\n${process.env.NODE_ENV ?? "unknown"}`,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "mrkdwn",
|
|
50
|
+
text: `*Level:*\n${log.level.toUpperCase()}`,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: "section",
|
|
56
|
+
text: {
|
|
57
|
+
type: "mrkdwn",
|
|
58
|
+
text: `*Message:*\n\`\`\`${log.message}\`\`\``,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
log.stack
|
|
62
|
+
? {
|
|
63
|
+
type: "section",
|
|
64
|
+
text: {
|
|
65
|
+
type: "mrkdwn",
|
|
66
|
+
text: `*Stack Trace:*\n\`\`\`${log.stack}\`\`\``,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
70
|
+
].filter(Boolean),
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Winston logger
|
|
76
|
+
*/
|
|
77
|
+
exports.logger = winston_1.default.createLogger({
|
|
78
|
+
level: "info",
|
|
79
|
+
format: json(),
|
|
80
|
+
transports: [
|
|
81
|
+
new winston_1.default.transports.Console({
|
|
82
|
+
format: consoleFormat,
|
|
83
|
+
}),
|
|
84
|
+
...(isProduction && process.env.SLACK_WEBHOOK_URL ? [slackTransport] : []),
|
|
85
|
+
],
|
|
86
|
+
exitOnError: false,
|
|
87
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vidspotai-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
"googleapis": "^170.0.0",
|
|
25
25
|
"ioredis": "^5.8.0",
|
|
26
26
|
"jsonwebtoken": "^9.0.2",
|
|
27
|
+
"logform": "^2.7.0",
|
|
27
28
|
"openai": "^6.1.0",
|
|
29
|
+
"winston": "^3.19.0",
|
|
30
|
+
"winston-slack-webhook-transport": "^2.3.6",
|
|
28
31
|
"zod": "^4.1.11"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|