@youidian/sdk 3.4.4 → 3.4.6
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 +46 -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 +45 -5
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +46 -5
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +125 -3
- package/dist/server.d.ts +125 -3
- package/dist/server.js +45 -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
|
}
|
|
@@ -3240,6 +3256,30 @@ var PaymentClient = class {
|
|
|
3240
3256
|
const path = params.toString() ? `/products?${params.toString()}` : "/products";
|
|
3241
3257
|
return this.request("GET", path);
|
|
3242
3258
|
}
|
|
3259
|
+
/** Fetch all currently active discount policies for the configured app. */
|
|
3260
|
+
async getDiscountPolicies() {
|
|
3261
|
+
return this.request("GET", "/discount-policies");
|
|
3262
|
+
}
|
|
3263
|
+
/** Fetch currently active discount policies for one product. */
|
|
3264
|
+
async getProductDiscountPolicies(productIdOrCode) {
|
|
3265
|
+
const value = productIdOrCode?.trim();
|
|
3266
|
+
if (!value) throw new Error("productIdOrCode is required");
|
|
3267
|
+
return this.request(
|
|
3268
|
+
"GET",
|
|
3269
|
+
`/products/${encodeURIComponent(value)}/discount-policies`
|
|
3270
|
+
);
|
|
3271
|
+
}
|
|
3272
|
+
/** Query one user's discount eligibility for one product. */
|
|
3273
|
+
async getUserProductDiscountEligibility(userId, productIdOrCode) {
|
|
3274
|
+
const userValue = userId?.trim();
|
|
3275
|
+
const productValue = productIdOrCode?.trim();
|
|
3276
|
+
if (!userValue) throw new Error("userId is required");
|
|
3277
|
+
if (!productValue) throw new Error("productIdOrCode is required");
|
|
3278
|
+
return this.request(
|
|
3279
|
+
"GET",
|
|
3280
|
+
`/users/${encodeURIComponent(userValue)}/products/${encodeURIComponent(productValue)}/discount-eligibility`
|
|
3281
|
+
);
|
|
3282
|
+
}
|
|
3243
3283
|
/**
|
|
3244
3284
|
* Fetch the realtime stock snapshot for a single product.
|
|
3245
3285
|
*/
|
|
@@ -3595,6 +3635,7 @@ var PaymentClient = class {
|
|
|
3595
3635
|
0 && (module.exports = {
|
|
3596
3636
|
LoginUI,
|
|
3597
3637
|
MessageUI,
|
|
3638
|
+
PaymentApiError,
|
|
3598
3639
|
PaymentClient,
|
|
3599
3640
|
PaymentUI,
|
|
3600
3641
|
createFeedbackWidget,
|