@youidian/sdk 3.4.5 → 3.5.0
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/dist/index.cjs +39 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -5
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +39 -5
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +113 -2
- package/dist/server.d.ts +113 -2
- package/dist/server.js +38 -5
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var src_exports = {};
|
|
|
34
34
|
__export(src_exports, {
|
|
35
35
|
LoginUI: () => LoginUI,
|
|
36
36
|
MessageUI: () => MessageUI,
|
|
37
|
+
PaymentApiError: () => PaymentApiError,
|
|
37
38
|
PaymentClient: () => PaymentClient,
|
|
38
39
|
PaymentUI: () => PaymentUI,
|
|
39
40
|
createFeedbackWidget: () => createFeedbackWidget,
|
|
@@ -3042,6 +3043,16 @@ function mountFeedbackWidget(container, options) {
|
|
|
3042
3043
|
|
|
3043
3044
|
// src/server.ts
|
|
3044
3045
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
3046
|
+
var PaymentApiError = class extends Error {
|
|
3047
|
+
constructor(message, status, code) {
|
|
3048
|
+
super(message);
|
|
3049
|
+
__publicField(this, "status");
|
|
3050
|
+
__publicField(this, "code");
|
|
3051
|
+
this.name = "PaymentApiError";
|
|
3052
|
+
this.status = status;
|
|
3053
|
+
this.code = code;
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3045
3056
|
function getCustomAmountRechargeRule(product, currency) {
|
|
3046
3057
|
if (!product || product.type !== "CREDIT") return null;
|
|
3047
3058
|
const normalizedCurrency = currency.trim().toUpperCase();
|
|
@@ -3156,14 +3167,19 @@ var PaymentClient = class {
|
|
|
3156
3167
|
} catch {
|
|
3157
3168
|
}
|
|
3158
3169
|
const message = parsedError?.message || parsedError?.error || errorText || "Request failed";
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3170
|
+
throw new PaymentApiError(
|
|
3171
|
+
message,
|
|
3172
|
+
response.status,
|
|
3173
|
+
parsedError?.code || void 0
|
|
3174
|
+
);
|
|
3163
3175
|
}
|
|
3164
3176
|
const json = await response.json();
|
|
3165
3177
|
if (json.error) {
|
|
3166
|
-
throw new
|
|
3178
|
+
throw new PaymentApiError(
|
|
3179
|
+
`Payment API Error: ${json.error}`,
|
|
3180
|
+
response.status,
|
|
3181
|
+
json.code
|
|
3182
|
+
);
|
|
3167
3183
|
}
|
|
3168
3184
|
return json.data;
|
|
3169
3185
|
}
|
|
@@ -3237,6 +3253,11 @@ var PaymentClient = class {
|
|
|
3237
3253
|
const params = new URLSearchParams();
|
|
3238
3254
|
if (options?.locale) params.append("locale", options.locale);
|
|
3239
3255
|
if (options?.currency) params.append("currency", options.currency);
|
|
3256
|
+
if (options?.userId !== void 0) {
|
|
3257
|
+
const userId = options.userId.trim();
|
|
3258
|
+
if (!userId) throw new Error("userId must be a non-empty string");
|
|
3259
|
+
params.append("userId", userId);
|
|
3260
|
+
}
|
|
3240
3261
|
const path = params.toString() ? `/products?${params.toString()}` : "/products";
|
|
3241
3262
|
return this.request("GET", path);
|
|
3242
3263
|
}
|
|
@@ -3425,6 +3446,18 @@ var PaymentClient = class {
|
|
|
3425
3446
|
async getActiveSubscription(userId) {
|
|
3426
3447
|
return this.request("GET", `/users/${userId}/active-subscription`);
|
|
3427
3448
|
}
|
|
3449
|
+
async getSubscriptionUpgradeOptions(userId, options) {
|
|
3450
|
+
const value = userId?.trim();
|
|
3451
|
+
if (!value) throw new Error("userId is required");
|
|
3452
|
+
const params = new URLSearchParams();
|
|
3453
|
+
if (options?.locale) params.set("locale", options.locale);
|
|
3454
|
+
if (options?.currency) params.set("currency", options.currency);
|
|
3455
|
+
const query = params.toString() ? `?${params.toString()}` : "";
|
|
3456
|
+
return this.request(
|
|
3457
|
+
"GET",
|
|
3458
|
+
`/users/${encodeURIComponent(value)}/subscription-upgrade-options${query}`
|
|
3459
|
+
);
|
|
3460
|
+
}
|
|
3428
3461
|
/**
|
|
3429
3462
|
* Ensure user exists and auto-assign trial product if new user
|
|
3430
3463
|
* This should be called when user first logs in or registers
|
|
@@ -3619,6 +3652,7 @@ var PaymentClient = class {
|
|
|
3619
3652
|
0 && (module.exports = {
|
|
3620
3653
|
LoginUI,
|
|
3621
3654
|
MessageUI,
|
|
3655
|
+
PaymentApiError,
|
|
3622
3656
|
PaymentClient,
|
|
3623
3657
|
PaymentUI,
|
|
3624
3658
|
createFeedbackWidget,
|