@commercengine/storefront-sdk 0.10.2 → 0.11.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.
@@ -11,12 +11,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
  return Math.random().toString(36).slice(2, 11);
12
12
  }
13
13
  function createClient(clientOptions) {
14
- let { baseUrl = "", Request: CustomRequest = globalThis.Request, fetch: baseFetch = globalThis.fetch, querySerializer: globalQuerySerializer, bodySerializer: globalBodySerializer, headers: baseHeaders, requestInitExt = void 0,...baseOptions } = { ...clientOptions };
14
+ let { baseUrl = "", Request: CustomRequest = globalThis.Request, fetch: baseFetch = globalThis.fetch, querySerializer: globalQuerySerializer, bodySerializer: globalBodySerializer, headers: baseHeaders, requestInitExt = void 0, ...baseOptions } = { ...clientOptions };
15
15
  requestInitExt = supportsRequestInitExt() ? requestInitExt : void 0;
16
16
  baseUrl = removeTrailingSlash(baseUrl);
17
17
  const middlewares = [];
18
18
  async function coreFetch(schemaPath, fetchOptions) {
19
- const { baseUrl: localBaseUrl, fetch: fetch$1 = baseFetch, Request: Request$1 = CustomRequest, headers, params = {}, parseAs = "json", querySerializer: requestQuerySerializer, bodySerializer = globalBodySerializer ?? defaultBodySerializer, body,...init } = fetchOptions || {};
19
+ const { baseUrl: localBaseUrl, fetch: fetch$1 = baseFetch, Request: Request$1 = CustomRequest, headers, params = {}, parseAs = "json", querySerializer: requestQuerySerializer, bodySerializer = globalBodySerializer ?? defaultBodySerializer, body, ...init } = fetchOptions || {};
20
20
  let finalBaseUrl = baseUrl;
21
21
  if (localBaseUrl) finalBaseUrl = removeTrailingSlash(localBaseUrl) ?? baseUrl;
22
22
  let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
@@ -779,13 +779,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
779
779
  }
780
780
 
781
781
  //#endregion
782
- //#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/lib/buffer_utils.js
782
+ //#region ../../node_modules/.pnpm/jose@6.1.3/node_modules/jose/dist/webapi/lib/buffer_utils.js
783
783
  const encoder = new TextEncoder();
784
784
  const decoder = new TextDecoder();
785
785
  const MAX_INT32 = 2 ** 32;
786
786
 
787
787
  //#endregion
788
- //#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/lib/base64.js
788
+ //#region ../../node_modules/.pnpm/jose@6.1.3/node_modules/jose/dist/webapi/lib/base64.js
789
789
  function decodeBase64(encoded) {
790
790
  if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
791
791
  const binary = atob(encoded);
@@ -795,12 +795,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
795
795
  }
796
796
 
797
797
  //#endregion
798
- //#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/util/base64url.js
798
+ //#region ../../node_modules/.pnpm/jose@6.1.3/node_modules/jose/dist/webapi/util/base64url.js
799
799
  function decode(input) {
800
800
  if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
801
801
  let encoded = input;
802
802
  if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
803
- encoded = encoded.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
803
+ encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
804
804
  try {
805
805
  return decodeBase64(encoded);
806
806
  } catch {
@@ -809,7 +809,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
809
809
  }
810
810
 
811
811
  //#endregion
812
- //#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/util/errors.js
812
+ //#region ../../node_modules/.pnpm/jose@6.1.3/node_modules/jose/dist/webapi/util/errors.js
813
813
  var JOSEError = class extends Error {
814
814
  static code = "ERR_JOSE_GENERIC";
815
815
  code = "ERR_JOSE_GENERIC";
@@ -833,20 +833,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
833
833
  };
834
834
 
835
835
  //#endregion
836
- //#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/lib/is_object.js
837
- function isObjectLike(value) {
838
- return typeof value === "object" && value !== null;
839
- }
840
- var is_object_default = (input) => {
836
+ //#region ../../node_modules/.pnpm/jose@6.1.3/node_modules/jose/dist/webapi/lib/is_object.js
837
+ const isObjectLike = (value) => typeof value === "object" && value !== null;
838
+ function isObject(input) {
841
839
  if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
842
840
  if (Object.getPrototypeOf(input) === null) return true;
843
841
  let proto = input;
844
842
  while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
845
843
  return Object.getPrototypeOf(input) === proto;
846
- };
844
+ }
847
845
 
848
846
  //#endregion
849
- //#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/util/decode_jwt.js
847
+ //#region ../../node_modules/.pnpm/jose@6.1.3/node_modules/jose/dist/webapi/util/decode_jwt.js
850
848
  function decodeJwt(jwt) {
851
849
  if (typeof jwt !== "string") throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
852
850
  const { 1: payload, length } = jwt.split(".");
@@ -865,7 +863,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
865
863
  } catch {
866
864
  throw new JWTInvalid("Failed to parse the decoded payload as JSON");
867
865
  }
868
- if (!is_object_default(result)) throw new JWTInvalid("Invalid JWT Claims Set");
866
+ if (!isObject(result)) throw new JWTInvalid("Invalid JWT Claims Set");
869
867
  return result;
870
868
  }
871
869
 
@@ -3336,27 +3334,80 @@ Object.defineProperty(exports, '__esModule', { value: true });
3336
3334
  * @returns Promise with order details
3337
3335
  * @example
3338
3336
  * ```typescript
3339
- * // Example with PayU payment gateway
3337
+ * // Juspay Hyper Checkout - Redirects to hosted payment page
3340
3338
  * const { data, error } = await sdk.order.createOrder({
3341
3339
  * cart_id: "cart_01H9XYZ12345ABCDE",
3342
- * payment_gateway: "PAYU",
3343
- * payment_gateway_params: {
3344
- * payment_gateway: "PAYU",
3345
- * furl: "https://yourapp.com/payment/failure",
3346
- * surl: "https://yourapp.com/payment/success"
3340
+ * payment_method: {
3341
+ * payment_provider_slug: "juspay",
3342
+ * integration_type: "hyper-checkout",
3343
+ * gateway_reference_id: "gateway_ref_123",
3344
+ * return_url: "https://yourapp.com/payment/return",
3345
+ * action: "paymentPage"
3347
3346
  * }
3348
3347
  * });
3349
3348
  *
3350
- * // Example with Juspay payment gateway
3349
+ * // Juspay Express Checkout - New Card
3351
3350
  * const { data, error } = await sdk.order.createOrder({
3352
3351
  * cart_id: "cart_01H9XYZ12345ABCDE",
3353
- * payment_gateway: "JUSPAY",
3354
- * payment_gateway_params: {
3355
- * payment_gateway: "JUSPAY",
3356
- * action: "paymentPage",
3357
- * integration_type: "hyper-checkout",
3352
+ * payment_method: {
3353
+ * payment_provider_slug: "juspay",
3354
+ * integration_type: "express-checkout",
3355
+ * gateway_reference_id: "gateway_ref_123",
3356
+ * return_url: "https://yourapp.com/payment/return",
3357
+ * payment_method_type: "CARD",
3358
+ * payment_method: "VISA",
3359
+ * auth_type: "OTP",
3360
+ * save_to_locker: true,
3361
+ * card_number: "4111111111111111",
3362
+ * card_exp_month: "12",
3363
+ * card_exp_year: "2025",
3364
+ * name_on_card: "John Doe",
3365
+ * card_security_code: "123"
3366
+ * }
3367
+ * });
3368
+ *
3369
+ * // Juspay Express Checkout - Saved Card Token
3370
+ * const { data, error } = await sdk.order.createOrder({
3371
+ * cart_id: "cart_01H9XYZ12345ABCDE",
3372
+ * payment_method: {
3373
+ * payment_provider_slug: "juspay",
3374
+ * integration_type: "express-checkout",
3375
+ * gateway_reference_id: "gateway_ref_123",
3376
+ * return_url: "https://yourapp.com/payment/return",
3377
+ * get_client_auth_token: true,
3378
+ * payment_method_type: "CARD",
3379
+ * payment_method: "VISA",
3380
+ * auth_type: "OTP",
3381
+ * save_to_locker: false,
3382
+ * card_token: "token_abc123",
3383
+ * card_security_code: "123"
3384
+ * }
3385
+ * });
3386
+ *
3387
+ * // Juspay Express Checkout - UPI Collect
3388
+ * const { data, error } = await sdk.order.createOrder({
3389
+ * cart_id: "cart_01H9XYZ12345ABCDE",
3390
+ * payment_method: {
3391
+ * payment_provider_slug: "juspay",
3392
+ * integration_type: "express-checkout",
3393
+ * gateway_reference_id: "gateway_ref_123",
3394
+ * return_url: "https://yourapp.com/payment/return",
3395
+ * payment_method_type: "UPI",
3396
+ * payment_method: "UPI_COLLECT",
3397
+ * upi_vpa: "user@upi"
3398
+ * }
3399
+ * });
3400
+ *
3401
+ * // Juspay Express Checkout - Net Banking
3402
+ * const { data, error } = await sdk.order.createOrder({
3403
+ * cart_id: "cart_01H9XYZ12345ABCDE",
3404
+ * payment_method: {
3405
+ * payment_provider_slug: "juspay",
3406
+ * integration_type: "express-checkout",
3407
+ * gateway_reference_id: "gateway_ref_123",
3358
3408
  * return_url: "https://yourapp.com/payment/return",
3359
- * gateway_reference_id: "juspay_gateway_ref_123"
3409
+ * payment_method_type: "NB",
3410
+ * payment_method: "NB_HDFC"
3360
3411
  * }
3361
3412
  * });
3362
3413
  *
@@ -3366,6 +3417,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
3366
3417
  * console.log("Order created:", data.order.id);
3367
3418
  * console.log("Payment required:", data.payment_required);
3368
3419
  * console.log("Payment info:", data.payment_info);
3420
+ *
3421
+ * // For hyper-checkout, redirect to payment page
3422
+ * if ("payment_links" in data.payment_info) {
3423
+ * window.location.href = data.payment_info.payment_links?.web;
3424
+ * }
3425
+ *
3426
+ * // For express-checkout with OTP authentication
3427
+ * if ("payment" in data.payment_info && data.payment_info.payment?.authentication?.params) {
3428
+ * const { id: txn_id, challenge_id } = data.payment_info.payment.authentication.params;
3429
+ * // Use txn_id and challenge_id with sdk.payments.authenticateDirectOtp()
3430
+ * }
3369
3431
  * }
3370
3432
  * ```
3371
3433
  */
@@ -3553,28 +3615,32 @@ Object.defineProperty(exports, '__esModule', { value: true });
3553
3615
  * @returns Promise with payment information
3554
3616
  * @example
3555
3617
  * ```typescript
3556
- * // Example with PayU payment gateway
3618
+ * // Juspay Hyper Checkout - Redirects to hosted payment page
3557
3619
  * const { data, error } = await sdk.order.retryOrderPayment(
3558
3620
  * { order_number: "ORD-2024-001" },
3559
3621
  * {
3560
- * payment_gateway_params: {
3561
- * payment_gateway: "PAYU",
3562
- * furl: "https://yourapp.com/payment/failure",
3563
- * surl: "https://yourapp.com/payment/success"
3622
+ * payment_method: {
3623
+ * payment_provider_slug: "juspay",
3624
+ * integration_type: "hyper-checkout",
3625
+ * gateway_reference_id: "gateway_ref_123",
3626
+ * return_url: "https://yourapp.com/payment/return",
3627
+ * action: "paymentPage"
3564
3628
  * }
3565
3629
  * }
3566
3630
  * );
3567
3631
  *
3568
- * // Example with Juspay payment gateway
3632
+ * // Juspay Express Checkout - UPI Collect
3569
3633
  * const { data, error } = await sdk.order.retryOrderPayment(
3570
3634
  * { order_number: "ORD-2024-001" },
3571
3635
  * {
3572
- * payment_gateway_params: {
3573
- * payment_gateway: "JUSPAY",
3574
- * action: "paymentPage",
3575
- * integration_type: "hyper-checkout",
3636
+ * payment_method: {
3637
+ * payment_provider_slug: "juspay",
3638
+ * integration_type: "express-checkout",
3639
+ * gateway_reference_id: "gateway_ref_123",
3576
3640
  * return_url: "https://yourapp.com/payment/return",
3577
- * gateway_reference_id: "juspay_gateway_ref_123"
3641
+ * payment_method_type: "UPI",
3642
+ * payment_method: "UPI_COLLECT",
3643
+ * upi_vpa: "user@upi"
3578
3644
  * }
3579
3645
  * }
3580
3646
  * );
@@ -3584,7 +3650,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
3584
3650
  * } else {
3585
3651
  * console.log("Payment retry initiated");
3586
3652
  * console.log("Payment info:", data.payment_info);
3587
- * console.log("Transaction ID:", data.payment_info.transaction_id);
3653
+ *
3654
+ * // For hyper-checkout, redirect to payment page
3655
+ * if ("payment_links" in data.payment_info) {
3656
+ * window.location.href = data.payment_info.payment_links?.web;
3657
+ * }
3588
3658
  * }
3589
3659
  * ```
3590
3660
  */
@@ -3596,6 +3666,126 @@ Object.defineProperty(exports, '__esModule', { value: true });
3596
3666
  }
3597
3667
  };
3598
3668
 
3669
+ //#endregion
3670
+ //#region src/lib/payments.ts
3671
+ /**
3672
+ * Client for interacting with payment endpoints
3673
+ */
3674
+ var PaymentsClient = class extends StorefrontAPIClient {
3675
+ /**
3676
+ * List all available payment methods
3677
+ *
3678
+ * @returns Promise with list of payment methods
3679
+ * @example
3680
+ * ```typescript
3681
+ * const { data, error } = await sdk.payments.listPaymentMethods();
3682
+ *
3683
+ * if (error) {
3684
+ * console.error("Failed to list payment methods:", error.message);
3685
+ * } else {
3686
+ * console.log("Payment methods:", data.payment_methods);
3687
+ *
3688
+ * data.payment_methods?.forEach(method => {
3689
+ * console.log("Payment method:", method.name);
3690
+ * console.log("Gateway:", method.payment_gateway);
3691
+ * });
3692
+ * }
3693
+ * ```
3694
+ */
3695
+ async listPaymentMethods() {
3696
+ return this.executeRequest(() => this.client.GET("/payments/payment-methods", {}));
3697
+ }
3698
+ /**
3699
+ * Verify a UPI Virtual Payment Address (VPA)
3700
+ *
3701
+ * @description The Virtual Payment Address or VPA is a unique ID given to an individual
3702
+ * using the Unified Payment Interface (UPI) service to send or receive money.
3703
+ * Validating the VPA helps reduce payment failure rates due to incorrect VPA.
3704
+ *
3705
+ * @param queryParams - Query parameters containing the VPA to verify
3706
+ * @returns Promise with VPA verification result
3707
+ * @example
3708
+ * ```typescript
3709
+ * const { data, error } = await sdk.payments.verifyVpa({
3710
+ * vpa: "user@upi"
3711
+ * });
3712
+ *
3713
+ * if (error) {
3714
+ * console.error("Failed to verify VPA:", error.message);
3715
+ * } else {
3716
+ * console.log("VPA:", data.vpa);
3717
+ * console.log("Status:", data.status);
3718
+ *
3719
+ * if (data.status === "VALID") {
3720
+ * console.log("VPA is valid and can be used for UPI payments");
3721
+ * } else {
3722
+ * console.log("VPA is invalid, please check and try again");
3723
+ * }
3724
+ * }
3725
+ * ```
3726
+ */
3727
+ async verifyVpa(queryParams) {
3728
+ return this.executeRequest(() => this.client.GET("/payments/verify-vpa", { params: { query: queryParams } }));
3729
+ }
3730
+ /**
3731
+ * Authenticate a direct OTP for payment verification
3732
+ *
3733
+ * @description Used to authenticate OTP during payment flows that require 2FA verification.
3734
+ * The txn_id and challenge_id can be obtained from the create order API response
3735
+ * under the payment_info.authentication.params object.
3736
+ *
3737
+ * @param body - OTP authentication request body
3738
+ * @returns Promise with authentication result
3739
+ * @example
3740
+ * ```typescript
3741
+ * // After creating an order, if OTP authentication is required:
3742
+ * const { data, error } = await sdk.payments.authenticateDirectOtp({
3743
+ * txn_id: "txn_01H9XYZ12345ABCDE",
3744
+ * challenge_id: "challenge_01H9XYZ12345ABCDE",
3745
+ * otp: "123456"
3746
+ * });
3747
+ *
3748
+ * if (error) {
3749
+ * console.error("OTP authentication failed:", error.message);
3750
+ * } else {
3751
+ * console.log("Authentication success:", data.success);
3752
+ * console.log("Message:", data.message);
3753
+ * }
3754
+ * ```
3755
+ */
3756
+ async authenticateDirectOtp(body) {
3757
+ return this.executeRequest(() => this.client.POST("/payments/authenticate-direct-otp", { body }));
3758
+ }
3759
+ /**
3760
+ * Resend a direct OTP for payment verification
3761
+ *
3762
+ * @description Used to resend OTP during payment flows that require 2FA verification.
3763
+ * The txn_id and challenge_id can be obtained from the create order API response
3764
+ * under the payment_info.authentication.params object.
3765
+ *
3766
+ * @param body - OTP resend request body
3767
+ * @returns Promise with new payment info containing updated OTP challenge
3768
+ * @example
3769
+ * ```typescript
3770
+ * // If user didn't receive OTP or it expired:
3771
+ * const { data, error } = await sdk.payments.resendDirectOtp({
3772
+ * txn_id: "txn_01H9XYZ12345ABCDE",
3773
+ * challenge_id: "challenge_01H9XYZ12345ABCDE"
3774
+ * });
3775
+ *
3776
+ * if (error) {
3777
+ * console.error("Failed to resend OTP:", error.message);
3778
+ * } else {
3779
+ * console.log("OTP resent successfully");
3780
+ * console.log("New payment info:", data.payment_info);
3781
+ * }
3782
+ * ```
3783
+ */
3784
+ async resendDirectOtp(body) {
3785
+ return this.executeRequest(() => this.client.POST("/payments/resend-direct-otp", { body }));
3786
+ }
3787
+ };
3788
+
3599
3789
  //#endregion
3600
3790
  //#region src/lib/shipping.ts
3601
3791
  /**
@@ -4199,6 +4389,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4199
4389
  */
4200
4390
  order;
4201
4391
  /**
4392
+ * Client for payment-related endpoints
4393
+ */
4394
+ payments;
4395
+ /**
4202
4396
  * Client for store config-related endpoints
4203
4397
  */
4204
4398
  store;
@@ -4235,6 +4429,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4235
4429
  this.helpers = new HelpersClient(config);
4236
4430
  this.shipping = new ShippingClient(config);
4237
4431
  this.order = new OrderClient(config);
4432
+ this.payments = new PaymentsClient(config);
4238
4433
  this.store = new StoreConfigClient(config);
4239
4434
  }
4240
4435
  /**
@@ -4255,6 +4450,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4255
4450
  await this.helpers.setTokens(accessToken, refreshToken);
4256
4451
  await this.shipping.setTokens(accessToken, refreshToken);
4257
4452
  await this.order.setTokens(accessToken, refreshToken);
4453
+ await this.payments.setTokens(accessToken, refreshToken);
4258
4454
  await this.store.setTokens(accessToken, refreshToken);
4259
4455
  }
4260
4456
  /**
@@ -4272,6 +4468,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4272
4468
  await this.helpers.clearTokens();
4273
4469
  await this.shipping.clearTokens();
4274
4470
  await this.order.clearTokens();
4471
+ await this.payments.clearTokens();
4275
4472
  await this.store.clearTokens();
4276
4473
  }
4277
4474
  /**
@@ -4287,6 +4484,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4287
4484
  this.helpers.setApiKey(apiKey);
4288
4485
  this.shipping.setApiKey(apiKey);
4289
4486
  this.order.setApiKey(apiKey);
4487
+ this.payments.setApiKey(apiKey);
4290
4488
  this.store.setApiKey(apiKey);
4291
4489
  }
4292
4490
  /**
@@ -4300,6 +4498,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4300
4498
  this.helpers.clearApiKey();
4301
4499
  this.shipping.clearApiKey();
4302
4500
  this.order.clearApiKey();
4501
+ this.payments.clearApiKey();
4303
4502
  this.store.clearApiKey();
4304
4503
  }
4305
4504
  /**
@@ -4378,6 +4577,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4378
4577
  this.helpers.setDefaultHeaders(headers);
4379
4578
  this.shipping.setDefaultHeaders(headers);
4380
4579
  this.order.setDefaultHeaders(headers);
4580
+ this.payments.setDefaultHeaders(headers);
4381
4581
  this.store.setDefaultHeaders(headers);
4382
4582
  }
4383
4583
  /**
@@ -4402,6 +4602,7 @@ exports.Environment = Environment;
4402
4602
  exports.HelpersClient = HelpersClient;
4403
4603
  exports.MemoryTokenStorage = MemoryTokenStorage;
4404
4604
  exports.OrderClient = OrderClient;
4605
+ exports.PaymentsClient = PaymentsClient;
4405
4606
  exports.ResponseUtils = ResponseUtils;
4406
4607
  exports.ShippingClient = ShippingClient;
4407
4608
  exports.StoreConfigClient = StoreConfigClient;