@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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { OrderStatus as ClientOrderStatus, LoginDeviceType, LoginEnvironment, LoginEnvironmentInput, MessageUI, PaymentEventData, PaymentEventType, PaymentParams, PaymentUI, PaymentUIOptions, PollOptions, WechatMessageBindingUIOptions, createMessageUI, createPaymentUI, detectLoginEnvironment } from './client.cjs';
2
2
  export { FeedbackActor, FeedbackCategoryOption, FeedbackIdentityKind, FeedbackWidgetController, FeedbackWidgetOptions, createFeedbackWidget, mountFeedbackWidget } from './feedback.cjs';
3
3
  export { L as LoginCallbackOptions, a as LoginDisplayMode, b as LoginEventData, c as LoginEventType, d as LoginFallbackRedirectMode, e as LoginParams, f as LoginResult, g as LoginUI, h as LoginUIOptions, i as createLoginUI, j as handleLoginCallbackIfPresent } from './login-Dqemys65.cjs';
4
- export { ActiveSubscriptionInfo, BindPhoneNumberParams, BindPhoneNumberResponse, CancelOrderResponse, CompleteFreeOrderResponse, CreateBankTransferOrderParams, CreateMiniProgramOrderParams, CreateOrderParams, CreateOrderResponse, CreateWechatMessageBindingParams, CreateWechatMessageBindingResponse, CustomAmountRechargeRule, CustomAmountRechargeValidationResult, GetPhoneBindingParams, MerchantPricing, MerchantPricingBreakdownItem, MerchantPricingSnapshot, MessageTemplateDataValue, OrderDetails, OrderStatus, PaymentCallbackData, PaymentClient, PaymentClientOptions, PaymentNotification, PhoneBinding, PricingBreakdown, Product, ProductCustomAmount, ProductCustomAmountCurrency, ProductEntitlements, ProductInventory, ProductMetadata, ProductPrice, ProductResetRule, ProductStock, ProductStockLookupMode, ProductStockQueryOptions, ProductStocksQueryParams, ProductSubscriptionPeriod, SendMessageParams, SendMessageResponse, SendPhoneVerificationCodeParams, SendPhoneVerificationCodeResponse, UpdatePhoneNumberParams, UpdatePhoneNumberResponse, VerifiedLoginToken, WebhookPayload, WechatJsapiPayParams, getCustomAmountRechargeRule, validateCustomAmountRecharge } from './server.cjs';
4
+ export { ActiveSubscriptionInfo, BillingSnapshot, BindPhoneNumberParams, BindPhoneNumberResponse, CancelOrderResponse, CompleteFreeOrderResponse, CreateBankTransferOrderParams, CreateMiniProgramOrderParams, CreateOrderParams, CreateOrderResponse, CreateWechatMessageBindingParams, CreateWechatMessageBindingResponse, CustomAmountRechargeRule, CustomAmountRechargeValidationResult, DiscountPolicy, GetPhoneBindingParams, MerchantPricing, MerchantPricingBreakdownItem, MerchantPricingSnapshot, MessageTemplateDataValue, OrderDetails, OrderStatus, PaymentApiError, PaymentCallbackData, PaymentClient, PaymentClientOptions, PaymentNotification, PhoneBinding, PricingBreakdown, Product, ProductCustomAmount, ProductCustomAmountCurrency, ProductEntitlements, ProductInventory, ProductMetadata, ProductPrice, ProductResetRule, ProductStock, ProductStockLookupMode, ProductStockQueryOptions, ProductStocksQueryParams, ProductSubscriptionPeriod, SendMessageParams, SendMessageResponse, SendPhoneVerificationCodeParams, SendPhoneVerificationCodeResponse, SubscriptionAction, SubscriptionAutoRefundStatus, SubscriptionBillingSnapshot, SubscriptionDetails, SubscriptionErrorCode, SubscriptionStatus, UpdatePhoneNumberParams, UpdatePhoneNumberResponse, UserProductDiscountEligibility, VerifiedLoginToken, WebhookPayload, WechatJsapiPayParams, getCustomAmountRechargeRule, validateCustomAmountRecharge } from './server.cjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { OrderStatus as ClientOrderStatus, LoginDeviceType, LoginEnvironment, LoginEnvironmentInput, MessageUI, PaymentEventData, PaymentEventType, PaymentParams, PaymentUI, PaymentUIOptions, PollOptions, WechatMessageBindingUIOptions, createMessageUI, createPaymentUI, detectLoginEnvironment } from './client.js';
2
2
  export { FeedbackActor, FeedbackCategoryOption, FeedbackIdentityKind, FeedbackWidgetController, FeedbackWidgetOptions, createFeedbackWidget, mountFeedbackWidget } from './feedback.js';
3
3
  export { L as LoginCallbackOptions, a as LoginDisplayMode, b as LoginEventData, c as LoginEventType, d as LoginFallbackRedirectMode, e as LoginParams, f as LoginResult, g as LoginUI, h as LoginUIOptions, i as createLoginUI, j as handleLoginCallbackIfPresent } from './login-Dqemys65.js';
4
- export { ActiveSubscriptionInfo, BindPhoneNumberParams, BindPhoneNumberResponse, CancelOrderResponse, CompleteFreeOrderResponse, CreateBankTransferOrderParams, CreateMiniProgramOrderParams, CreateOrderParams, CreateOrderResponse, CreateWechatMessageBindingParams, CreateWechatMessageBindingResponse, CustomAmountRechargeRule, CustomAmountRechargeValidationResult, GetPhoneBindingParams, MerchantPricing, MerchantPricingBreakdownItem, MerchantPricingSnapshot, MessageTemplateDataValue, OrderDetails, OrderStatus, PaymentCallbackData, PaymentClient, PaymentClientOptions, PaymentNotification, PhoneBinding, PricingBreakdown, Product, ProductCustomAmount, ProductCustomAmountCurrency, ProductEntitlements, ProductInventory, ProductMetadata, ProductPrice, ProductResetRule, ProductStock, ProductStockLookupMode, ProductStockQueryOptions, ProductStocksQueryParams, ProductSubscriptionPeriod, SendMessageParams, SendMessageResponse, SendPhoneVerificationCodeParams, SendPhoneVerificationCodeResponse, UpdatePhoneNumberParams, UpdatePhoneNumberResponse, VerifiedLoginToken, WebhookPayload, WechatJsapiPayParams, getCustomAmountRechargeRule, validateCustomAmountRecharge } from './server.js';
4
+ export { ActiveSubscriptionInfo, BillingSnapshot, BindPhoneNumberParams, BindPhoneNumberResponse, CancelOrderResponse, CompleteFreeOrderResponse, CreateBankTransferOrderParams, CreateMiniProgramOrderParams, CreateOrderParams, CreateOrderResponse, CreateWechatMessageBindingParams, CreateWechatMessageBindingResponse, CustomAmountRechargeRule, CustomAmountRechargeValidationResult, DiscountPolicy, GetPhoneBindingParams, MerchantPricing, MerchantPricingBreakdownItem, MerchantPricingSnapshot, MessageTemplateDataValue, OrderDetails, OrderStatus, PaymentApiError, PaymentCallbackData, PaymentClient, PaymentClientOptions, PaymentNotification, PhoneBinding, PricingBreakdown, Product, ProductCustomAmount, ProductCustomAmountCurrency, ProductEntitlements, ProductInventory, ProductMetadata, ProductPrice, ProductResetRule, ProductStock, ProductStockLookupMode, ProductStockQueryOptions, ProductStocksQueryParams, ProductSubscriptionPeriod, SendMessageParams, SendMessageResponse, SendPhoneVerificationCodeParams, SendPhoneVerificationCodeResponse, SubscriptionAction, SubscriptionAutoRefundStatus, SubscriptionBillingSnapshot, SubscriptionDetails, SubscriptionErrorCode, SubscriptionStatus, UpdatePhoneNumberParams, UpdatePhoneNumberResponse, UserProductDiscountEligibility, VerifiedLoginToken, WebhookPayload, WechatJsapiPayParams, getCustomAmountRechargeRule, validateCustomAmountRecharge } from './server.js';
package/dist/index.js CHANGED
@@ -2996,6 +2996,16 @@ function mountFeedbackWidget(container, options) {
2996
2996
 
2997
2997
  // src/server.ts
2998
2998
  import crypto2 from "crypto";
2999
+ var PaymentApiError = class extends Error {
3000
+ constructor(message, status, code) {
3001
+ super(message);
3002
+ __publicField(this, "status");
3003
+ __publicField(this, "code");
3004
+ this.name = "PaymentApiError";
3005
+ this.status = status;
3006
+ this.code = code;
3007
+ }
3008
+ };
2999
3009
  function getCustomAmountRechargeRule(product, currency) {
3000
3010
  if (!product || product.type !== "CREDIT") return null;
3001
3011
  const normalizedCurrency = currency.trim().toUpperCase();
@@ -3110,14 +3120,19 @@ var PaymentClient = class {
3110
3120
  } catch {
3111
3121
  }
3112
3122
  const message = parsedError?.message || parsedError?.error || errorText || "Request failed";
3113
- const error = new Error(message);
3114
- error.status = response.status;
3115
- error.code = parsedError?.code || parsedError?.error || void 0;
3116
- throw error;
3123
+ throw new PaymentApiError(
3124
+ message,
3125
+ response.status,
3126
+ parsedError?.code || void 0
3127
+ );
3117
3128
  }
3118
3129
  const json = await response.json();
3119
3130
  if (json.error) {
3120
- throw new Error(`Payment API Error: ${json.error}`);
3131
+ throw new PaymentApiError(
3132
+ `Payment API Error: ${json.error}`,
3133
+ response.status,
3134
+ json.code
3135
+ );
3121
3136
  }
3122
3137
  return json.data;
3123
3138
  }
@@ -3194,6 +3209,30 @@ var PaymentClient = class {
3194
3209
  const path = params.toString() ? `/products?${params.toString()}` : "/products";
3195
3210
  return this.request("GET", path);
3196
3211
  }
3212
+ /** Fetch all currently active discount policies for the configured app. */
3213
+ async getDiscountPolicies() {
3214
+ return this.request("GET", "/discount-policies");
3215
+ }
3216
+ /** Fetch currently active discount policies for one product. */
3217
+ async getProductDiscountPolicies(productIdOrCode) {
3218
+ const value = productIdOrCode?.trim();
3219
+ if (!value) throw new Error("productIdOrCode is required");
3220
+ return this.request(
3221
+ "GET",
3222
+ `/products/${encodeURIComponent(value)}/discount-policies`
3223
+ );
3224
+ }
3225
+ /** Query one user's discount eligibility for one product. */
3226
+ async getUserProductDiscountEligibility(userId, productIdOrCode) {
3227
+ const userValue = userId?.trim();
3228
+ const productValue = productIdOrCode?.trim();
3229
+ if (!userValue) throw new Error("userId is required");
3230
+ if (!productValue) throw new Error("productIdOrCode is required");
3231
+ return this.request(
3232
+ "GET",
3233
+ `/users/${encodeURIComponent(userValue)}/products/${encodeURIComponent(productValue)}/discount-eligibility`
3234
+ );
3235
+ }
3197
3236
  /**
3198
3237
  * Fetch the realtime stock snapshot for a single product.
3199
3238
  */
@@ -3548,6 +3587,7 @@ var PaymentClient = class {
3548
3587
  export {
3549
3588
  LoginUI,
3550
3589
  MessageUI,
3590
+ PaymentApiError,
3551
3591
  PaymentClient,
3552
3592
  PaymentUI,
3553
3593
  createFeedbackWidget,