@commercengine/storefront-sdk 0.10.1 → 0.10.2
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.ts +428 -263
- package/dist/index.iife.js +74 -57
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +68 -51
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.iife.js
CHANGED
|
@@ -762,15 +762,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
762
762
|
getDefaultHeaders() {
|
|
763
763
|
return this.config.defaultHeaders;
|
|
764
764
|
}
|
|
765
|
-
/**
|
|
766
|
-
* Add middleware to the client
|
|
767
|
-
* This allows SDK extensions to add custom middleware like authentication
|
|
768
|
-
*
|
|
769
|
-
* @param middleware - Middleware to add to the client
|
|
770
|
-
*/
|
|
771
|
-
use(middleware) {
|
|
772
|
-
this.client.use(middleware);
|
|
773
|
-
}
|
|
774
765
|
};
|
|
775
766
|
/**
|
|
776
767
|
* Generic URL utility functions for any SDK
|
|
@@ -788,13 +779,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
788
779
|
}
|
|
789
780
|
|
|
790
781
|
//#endregion
|
|
791
|
-
//#region ../../node_modules/.pnpm/jose@6.0
|
|
782
|
+
//#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
792
783
|
const encoder = new TextEncoder();
|
|
793
784
|
const decoder = new TextDecoder();
|
|
794
785
|
const MAX_INT32 = 2 ** 32;
|
|
795
786
|
|
|
796
787
|
//#endregion
|
|
797
|
-
//#region ../../node_modules/.pnpm/jose@6.0
|
|
788
|
+
//#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/lib/base64.js
|
|
798
789
|
function decodeBase64(encoded) {
|
|
799
790
|
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
|
|
800
791
|
const binary = atob(encoded);
|
|
@@ -804,7 +795,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
804
795
|
}
|
|
805
796
|
|
|
806
797
|
//#endregion
|
|
807
|
-
//#region ../../node_modules/.pnpm/jose@6.0
|
|
798
|
+
//#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/util/base64url.js
|
|
808
799
|
function decode(input) {
|
|
809
800
|
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
810
801
|
let encoded = input;
|
|
@@ -818,7 +809,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
818
809
|
}
|
|
819
810
|
|
|
820
811
|
//#endregion
|
|
821
|
-
//#region ../../node_modules/.pnpm/jose@6.0
|
|
812
|
+
//#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/util/errors.js
|
|
822
813
|
var JOSEError = class extends Error {
|
|
823
814
|
static code = "ERR_JOSE_GENERIC";
|
|
824
815
|
code = "ERR_JOSE_GENERIC";
|
|
@@ -842,7 +833,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
842
833
|
};
|
|
843
834
|
|
|
844
835
|
//#endregion
|
|
845
|
-
//#region ../../node_modules/.pnpm/jose@6.0
|
|
836
|
+
//#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/lib/is_object.js
|
|
846
837
|
function isObjectLike(value) {
|
|
847
838
|
return typeof value === "object" && value !== null;
|
|
848
839
|
}
|
|
@@ -855,7 +846,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
855
846
|
};
|
|
856
847
|
|
|
857
848
|
//#endregion
|
|
858
|
-
//#region ../../node_modules/.pnpm/jose@6.0
|
|
849
|
+
//#region ../../node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
859
850
|
function decodeJwt(jwt) {
|
|
860
851
|
if (typeof jwt !== "string") throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
861
852
|
const { 1: payload, length } = jwt.split(".");
|
|
@@ -922,9 +913,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
922
913
|
try {
|
|
923
914
|
const payload = decodeJwt(token);
|
|
924
915
|
if (!payload.exp) return true;
|
|
925
|
-
|
|
926
|
-
const expiryTime = payload.exp;
|
|
927
|
-
return currentTime >= expiryTime - bufferSeconds;
|
|
916
|
+
return Math.floor(Date.now() / 1e3) >= payload.exp - bufferSeconds;
|
|
928
917
|
} catch (error) {
|
|
929
918
|
console.warn("Failed to decode JWT token:", error);
|
|
930
919
|
return true;
|
|
@@ -1260,9 +1249,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
1260
1249
|
* Helper function to create auth middleware with sensible defaults
|
|
1261
1250
|
*/
|
|
1262
1251
|
function createDefaultAuthMiddleware(options) {
|
|
1263
|
-
const tokenStorage = options.tokenStorage || (typeof localStorage !== "undefined" ? new BrowserTokenStorage() : new MemoryTokenStorage());
|
|
1264
1252
|
return createAuthMiddleware({
|
|
1265
|
-
tokenStorage,
|
|
1253
|
+
tokenStorage: options.tokenStorage || (typeof localStorage !== "undefined" ? new BrowserTokenStorage() : new MemoryTokenStorage()),
|
|
1266
1254
|
apiKey: options.apiKey,
|
|
1267
1255
|
baseUrl: options.baseUrl,
|
|
1268
1256
|
onTokensUpdated: options.onTokensUpdated,
|
|
@@ -1354,8 +1342,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
1354
1342
|
config.refreshToken = void 0;
|
|
1355
1343
|
}
|
|
1356
1344
|
} else this.client.use({ onRequest: async ({ request }) => {
|
|
1357
|
-
|
|
1358
|
-
if (isAnonymousAuthEndpoint(pathname)) {
|
|
1345
|
+
if (isAnonymousAuthEndpoint(getPathnameFromUrl(request.url))) {
|
|
1359
1346
|
if (config.apiKey) request.headers.set("X-Api-Key", config.apiKey);
|
|
1360
1347
|
if (config.accessToken) request.headers.set("Authorization", `Bearer ${config.accessToken}`);
|
|
1361
1348
|
return request;
|
|
@@ -2353,7 +2340,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2353
2340
|
}));
|
|
2354
2341
|
}
|
|
2355
2342
|
/**
|
|
2356
|
-
* Update
|
|
2343
|
+
* Update fulfillment preference
|
|
2357
2344
|
*
|
|
2358
2345
|
* @param cartId - The ID of the cart
|
|
2359
2346
|
* @param body - The body of the request
|
|
@@ -3615,40 +3602,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3615
3602
|
* Client for interacting with shipping endpoints
|
|
3616
3603
|
*/
|
|
3617
3604
|
var ShippingClient = class extends StorefrontAPIClient {
|
|
3618
|
-
/**
|
|
3619
|
-
* Get shipping options for an order
|
|
3620
|
-
*
|
|
3621
|
-
* @param body - Shipping methods body
|
|
3622
|
-
* @returns Promise with shipping options
|
|
3623
|
-
* @example
|
|
3624
|
-
* ```typescript
|
|
3625
|
-
* const { data, error } = await sdk.shipping.getShippingMethods({
|
|
3626
|
-
* delivery_pincode: "400001",
|
|
3627
|
-
* cart_id: "cart_01H9XYZ12345ABCDE"
|
|
3628
|
-
* });
|
|
3629
|
-
*
|
|
3630
|
-
* if (error) {
|
|
3631
|
-
* console.error("Failed to get shipping methods:", error.message);
|
|
3632
|
-
* } else {
|
|
3633
|
-
* console.log("Is serviceable:", data.is_serviceable);
|
|
3634
|
-
* console.log("Available shipping methods:", data.shipping_methods?.length || 0);
|
|
3635
|
-
*
|
|
3636
|
-
* data.shipping_methods?.forEach(method => {
|
|
3637
|
-
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
3638
|
-
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
3639
|
-
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
3640
|
-
*
|
|
3641
|
-
* method.courier_companies?.forEach(courier => {
|
|
3642
|
-
* console.log(` - ${courier.name}: ${courier.shipping_amount} (${courier.mode})`);
|
|
3643
|
-
* console.log(` Rating: ${courier.rating}/5, Recommended: ${courier.is_recommended}`);
|
|
3644
|
-
* });
|
|
3645
|
-
* });
|
|
3646
|
-
* }
|
|
3647
|
-
* ```
|
|
3648
|
-
*/
|
|
3649
|
-
async getShippingMethods(body) {
|
|
3650
|
-
return this.executeRequest(() => this.client.POST("/shipping/shipping-methods", { body }));
|
|
3651
|
-
}
|
|
3652
3605
|
/**
|
|
3653
3606
|
* Check pincode deliverability
|
|
3654
3607
|
*
|
|
@@ -3676,6 +3629,47 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3676
3629
|
async checkPincodeDeliverability(pathParams) {
|
|
3677
3630
|
return this.executeRequest(() => this.client.GET("/shipping/serviceability/{pincode}", { params: { path: pathParams } }));
|
|
3678
3631
|
}
|
|
3632
|
+
/**
|
|
3633
|
+
* Get fulfillment options for an order
|
|
3634
|
+
*
|
|
3635
|
+
* @param body - Fulfillment options body containing cart_id and delivery_pincode
|
|
3636
|
+
* @returns Promise with fulfillment options including collect and delivery methods
|
|
3637
|
+
* @example
|
|
3638
|
+
* ```typescript
|
|
3639
|
+
* const { data, error } = await sdk.shipping.getFulfillmentOptions({
|
|
3640
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3641
|
+
* delivery_pincode: "400001"
|
|
3642
|
+
* });
|
|
3643
|
+
*
|
|
3644
|
+
* if (error) {
|
|
3645
|
+
* console.error("Failed to get fulfillment options:", error.message);
|
|
3646
|
+
* } else {
|
|
3647
|
+
* // Check summary information
|
|
3648
|
+
* console.log("Collect available:", data.summary.collect_available);
|
|
3649
|
+
* console.log("Deliver available:", data.summary.deliver_available);
|
|
3650
|
+
* console.log("Recommended fulfillment type:", data.summary.recommended_fulfillment_type);
|
|
3651
|
+
*
|
|
3652
|
+
* // Access collect options
|
|
3653
|
+
* if (data.collect && data.collect.length > 0) {
|
|
3654
|
+
* console.log("Available stores for collection:");
|
|
3655
|
+
* data.collect.forEach(store => {
|
|
3656
|
+
* console.log(`${store.name} - ${store.distance_km}km away, ETA: ${store.collect_eta_minutes} minutes`);
|
|
3657
|
+
* });
|
|
3658
|
+
* }
|
|
3659
|
+
*
|
|
3660
|
+
* // Access delivery options
|
|
3661
|
+
* if (data.deliver && data.deliver.is_serviceable) {
|
|
3662
|
+
* console.log("Available shipping methods:");
|
|
3663
|
+
* data.deliver.shipping_methods.forEach(method => {
|
|
3664
|
+
* console.log(`${method.name} - ${method.shipping_amount}, ${method.estimated_delivery_days} days`);
|
|
3665
|
+
* });
|
|
3666
|
+
* }
|
|
3667
|
+
* }
|
|
3668
|
+
* ```
|
|
3669
|
+
*/
|
|
3670
|
+
async getFulfillmentOptions(body) {
|
|
3671
|
+
return this.executeRequest(() => this.client.POST("/shipping/fulfillment-options", { body }));
|
|
3672
|
+
}
|
|
3679
3673
|
};
|
|
3680
3674
|
|
|
3681
3675
|
//#endregion
|
|
@@ -4112,6 +4106,29 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4112
4106
|
async listCustomerReviews(pathParams) {
|
|
4113
4107
|
return this.executeRequest(() => this.client.GET("/customers/{user_id}/reviews", { params: { path: pathParams } }));
|
|
4114
4108
|
}
|
|
4109
|
+
/**
|
|
4110
|
+
* List all saved payment methods for a customer
|
|
4111
|
+
*
|
|
4112
|
+
* @param pathParams - Path parameters
|
|
4113
|
+
* @returns Promise with payment methods
|
|
4114
|
+
*
|
|
4115
|
+
* @example
|
|
4116
|
+
* ```typescript
|
|
4117
|
+
* const { data, error } = await sdk.customer.listSavedPaymentMethods({
|
|
4118
|
+
* customer_id: "customer_123"
|
|
4119
|
+
* });
|
|
4120
|
+
*
|
|
4121
|
+
* if (error) {
|
|
4122
|
+
* console.error("Failed to list saved payment methods:", error);
|
|
4123
|
+
* return;
|
|
4124
|
+
* }
|
|
4125
|
+
*
|
|
4126
|
+
* console.log("Saved payment methods:", data.saved_payment_methods);
|
|
4127
|
+
* ```
|
|
4128
|
+
*/
|
|
4129
|
+
async listSavedPaymentMethods(pathParams) {
|
|
4130
|
+
return this.executeRequest(() => this.client.GET("/customers/{customer_id}/payment-methods", { params: { path: pathParams } }));
|
|
4131
|
+
}
|
|
4115
4132
|
};
|
|
4116
4133
|
|
|
4117
4134
|
//#endregion
|