@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.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, DiscountPolicy, 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, UserProductDiscountEligibility, 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, DiscountPolicy, 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, UserProductDiscountEligibility, 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
  }
@@ -3191,6 +3206,11 @@ var PaymentClient = class {
3191
3206
  const params = new URLSearchParams();
3192
3207
  if (options?.locale) params.append("locale", options.locale);
3193
3208
  if (options?.currency) params.append("currency", options.currency);
3209
+ if (options?.userId !== void 0) {
3210
+ const userId = options.userId.trim();
3211
+ if (!userId) throw new Error("userId must be a non-empty string");
3212
+ params.append("userId", userId);
3213
+ }
3194
3214
  const path = params.toString() ? `/products?${params.toString()}` : "/products";
3195
3215
  return this.request("GET", path);
3196
3216
  }
@@ -3379,6 +3399,18 @@ var PaymentClient = class {
3379
3399
  async getActiveSubscription(userId) {
3380
3400
  return this.request("GET", `/users/${userId}/active-subscription`);
3381
3401
  }
3402
+ async getSubscriptionUpgradeOptions(userId, options) {
3403
+ const value = userId?.trim();
3404
+ if (!value) throw new Error("userId is required");
3405
+ const params = new URLSearchParams();
3406
+ if (options?.locale) params.set("locale", options.locale);
3407
+ if (options?.currency) params.set("currency", options.currency);
3408
+ const query = params.toString() ? `?${params.toString()}` : "";
3409
+ return this.request(
3410
+ "GET",
3411
+ `/users/${encodeURIComponent(value)}/subscription-upgrade-options${query}`
3412
+ );
3413
+ }
3382
3414
  /**
3383
3415
  * Ensure user exists and auto-assign trial product if new user
3384
3416
  * This should be called when user first logs in or registers
@@ -3572,6 +3604,7 @@ var PaymentClient = class {
3572
3604
  export {
3573
3605
  LoginUI,
3574
3606
  MessageUI,
3607
+ PaymentApiError,
3575
3608
  PaymentClient,
3576
3609
  PaymentUI,
3577
3610
  createFeedbackWidget,