vidspotai-shared 1.0.42 → 1.0.43
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/globals/plans.d.ts +5 -0
- package/lib/globals/plans.d.ts.map +1 -1
- package/lib/globals/plans.js +15 -1
- package/lib/models/user.model.d.ts +7 -0
- package/lib/models/user.model.d.ts.map +1 -1
- package/lib/services/aiGen/providers/minimax/minimax.service.js +1 -1
- package/lib/services/credit.service.d.ts.map +1 -1
- package/lib/services/credit.service.js +23 -6
- package/package.json +1 -1
package/lib/globals/plans.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { TPaymentPlans } from "./types";
|
|
2
2
|
export declare const PAYMENT_PLANS: Partial<TPaymentPlans>;
|
|
3
|
+
export declare const CREDIT_TOPUP_MIN = 20;
|
|
4
|
+
export declare const CREDIT_TOPUP_EXPIRY_MONTHS = 12;
|
|
5
|
+
export declare const CREDIT_TOPUP_RATE: (credits: number) => number;
|
|
6
|
+
/** Returns the Stripe charge amount in cents for a given credit count */
|
|
7
|
+
export declare const CREDIT_TOPUP_AMOUNT_CENTS: (credits: number) => number;
|
|
3
8
|
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/globals/plans.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,aAAa,CAqChD,CAAC"}
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/globals/plans.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,aAAa,CAqChD,CAAC;AAGF,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAInD,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,yBAAyB,GAAI,SAAS,MAAM,KAAG,MACJ,CAAC"}
|
package/lib/globals/plans.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PAYMENT_PLANS = void 0;
|
|
6
|
+
exports.CREDIT_TOPUP_AMOUNT_CENTS = exports.CREDIT_TOPUP_RATE = exports.CREDIT_TOPUP_EXPIRY_MONTHS = exports.CREDIT_TOPUP_MIN = exports.PAYMENT_PLANS = void 0;
|
|
7
7
|
const config_1 = __importDefault(require("./config"));
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
exports.PAYMENT_PLANS = {
|
|
@@ -44,6 +44,20 @@ exports.PAYMENT_PLANS = {
|
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
|
+
// Credit top-up pricing (tiered; always more expensive than subscription rate of $0.20/credit)
|
|
48
|
+
exports.CREDIT_TOPUP_MIN = 20;
|
|
49
|
+
exports.CREDIT_TOPUP_EXPIRY_MONTHS = 12;
|
|
50
|
+
const CREDIT_TOPUP_RATE = (credits) => {
|
|
51
|
+
if (credits < 50)
|
|
52
|
+
return 0.35;
|
|
53
|
+
if (credits < 150)
|
|
54
|
+
return 0.3;
|
|
55
|
+
return 0.25;
|
|
56
|
+
};
|
|
57
|
+
exports.CREDIT_TOPUP_RATE = CREDIT_TOPUP_RATE;
|
|
58
|
+
/** Returns the Stripe charge amount in cents for a given credit count */
|
|
59
|
+
const CREDIT_TOPUP_AMOUNT_CENTS = (credits) => Math.round(credits * (0, exports.CREDIT_TOPUP_RATE)(credits) * 100);
|
|
60
|
+
exports.CREDIT_TOPUP_AMOUNT_CENTS = CREDIT_TOPUP_AMOUNT_CENTS;
|
|
47
61
|
// export const SUBSCRIPTION_PLAN_DETAILS: TSubscriptionPlanDetails = {
|
|
48
62
|
// [ESUBSCRIPTION_PLANS.BASIC]: {
|
|
49
63
|
// price: 20,
|
|
@@ -27,6 +27,13 @@ export interface IUserCredts {
|
|
|
27
27
|
total: number;
|
|
28
28
|
consumed: number;
|
|
29
29
|
reserved?: number;
|
|
30
|
+
purchased?: {
|
|
31
|
+
total: number;
|
|
32
|
+
consumed: number;
|
|
33
|
+
expiresAt: string;
|
|
34
|
+
lastPurchasedAt: string;
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
};
|
|
30
37
|
}
|
|
31
38
|
export interface IUserSubscription {
|
|
32
39
|
status: ESUBSCRIPTION_STATUS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.model.d.ts","sourceRoot":"","sources":["../../src/models/user.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EACL,SAAS,EACT,kBAAkB,EAElB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,CAAC;IACtC,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;IACtB,QAAQ,EAAE,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC;IAC3D,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,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AAC,EAAE;QACT,SAAS,CAAC,EAAE,UAAU,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,oBAAoB,CAAC;IAE7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAOrC"}
|
|
@@ -77,7 +77,7 @@ class MinimaxService extends baseAiGenProvider_service_1.BaseAiGenProviderServic
|
|
|
77
77
|
duration: params.duration || 6,
|
|
78
78
|
};
|
|
79
79
|
const response = await this.request("/v1/video_generation", "POST", requestBody);
|
|
80
|
-
|
|
80
|
+
logger_1.logger.info("Minimax video generation task response", { taskId: response.task_id });
|
|
81
81
|
const taskId = response.task_id;
|
|
82
82
|
return { task: taskId, status: types_1.EVideoSceneStatus.TRIGGERED };
|
|
83
83
|
}
|
|
@@ -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;WAkDH,aAAa,CACxB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC;CAoBjB"}
|
|
@@ -14,15 +14,32 @@ class CreditService {
|
|
|
14
14
|
const credits = snap.data()?.credits;
|
|
15
15
|
const consumed = credits?.consumed ?? 0;
|
|
16
16
|
const total = credits?.total ?? 0;
|
|
17
|
-
|
|
18
|
-
//
|
|
17
|
+
const purchased = credits?.purchased;
|
|
18
|
+
// Subscription credits available
|
|
19
|
+
const subAvailable = total - consumed;
|
|
20
|
+
// Purchased credits available (only if pool exists and not expired)
|
|
21
|
+
const purchasedIsValid = purchased &&
|
|
22
|
+
purchased.total > 0 &&
|
|
23
|
+
new Date(purchased.expiresAt) > new Date();
|
|
24
|
+
const purchAvailable = purchasedIsValid
|
|
25
|
+
? purchased.total - purchased.consumed
|
|
26
|
+
: 0;
|
|
27
|
+
const totalAvailable = subAvailable + purchAvailable;
|
|
19
28
|
// 🔒 HARD INVARIANT
|
|
20
|
-
if (
|
|
29
|
+
if (creditsToConsume > totalAvailable) {
|
|
21
30
|
throw new Error("INSUFFICIENT_CREDITS");
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
// Consume subscription credits first, then purchased
|
|
33
|
+
const subDeduct = Math.min(creditsToConsume, subAvailable);
|
|
34
|
+
const purchDeduct = creditsToConsume - subDeduct;
|
|
35
|
+
const updates = {
|
|
36
|
+
"credits.consumed": consumed + subDeduct,
|
|
37
|
+
};
|
|
38
|
+
if (purchDeduct > 0) {
|
|
39
|
+
updates["credits.purchased.consumed"] =
|
|
40
|
+
(purchased?.consumed ?? 0) + purchDeduct;
|
|
41
|
+
}
|
|
42
|
+
tx.update(userRef, updates);
|
|
26
43
|
});
|
|
27
44
|
}
|
|
28
45
|
static async refundCredits(userId, creditsToRefund) {
|