@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.js
CHANGED
|
@@ -392,15 +392,6 @@ var BaseAPIClient = class {
|
|
|
392
392
|
getDefaultHeaders() {
|
|
393
393
|
return this.config.defaultHeaders;
|
|
394
394
|
}
|
|
395
|
-
/**
|
|
396
|
-
* Add middleware to the client
|
|
397
|
-
* This allows SDK extensions to add custom middleware like authentication
|
|
398
|
-
*
|
|
399
|
-
* @param middleware - Middleware to add to the client
|
|
400
|
-
*/
|
|
401
|
-
use(middleware) {
|
|
402
|
-
this.client.use(middleware);
|
|
403
|
-
}
|
|
404
395
|
};
|
|
405
396
|
/**
|
|
406
397
|
* Generic URL utility functions for any SDK
|
|
@@ -461,9 +452,7 @@ function isTokenExpired(token, bufferSeconds = 30) {
|
|
|
461
452
|
try {
|
|
462
453
|
const payload = decodeJwt(token);
|
|
463
454
|
if (!payload.exp) return true;
|
|
464
|
-
|
|
465
|
-
const expiryTime = payload.exp;
|
|
466
|
-
return currentTime >= expiryTime - bufferSeconds;
|
|
455
|
+
return Math.floor(Date.now() / 1e3) >= payload.exp - bufferSeconds;
|
|
467
456
|
} catch (error) {
|
|
468
457
|
console.warn("Failed to decode JWT token:", error);
|
|
469
458
|
return true;
|
|
@@ -799,9 +788,8 @@ function createAuthMiddleware(config) {
|
|
|
799
788
|
* Helper function to create auth middleware with sensible defaults
|
|
800
789
|
*/
|
|
801
790
|
function createDefaultAuthMiddleware(options) {
|
|
802
|
-
const tokenStorage = options.tokenStorage || (typeof localStorage !== "undefined" ? new BrowserTokenStorage() : new MemoryTokenStorage());
|
|
803
791
|
return createAuthMiddleware({
|
|
804
|
-
tokenStorage,
|
|
792
|
+
tokenStorage: options.tokenStorage || (typeof localStorage !== "undefined" ? new BrowserTokenStorage() : new MemoryTokenStorage()),
|
|
805
793
|
apiKey: options.apiKey,
|
|
806
794
|
baseUrl: options.baseUrl,
|
|
807
795
|
onTokensUpdated: options.onTokensUpdated,
|
|
@@ -893,8 +881,7 @@ var StorefrontAPIClient = class extends BaseAPIClient {
|
|
|
893
881
|
config.refreshToken = void 0;
|
|
894
882
|
}
|
|
895
883
|
} else this.client.use({ onRequest: async ({ request }) => {
|
|
896
|
-
|
|
897
|
-
if (isAnonymousAuthEndpoint(pathname)) {
|
|
884
|
+
if (isAnonymousAuthEndpoint(getPathnameFromUrl(request.url))) {
|
|
898
885
|
if (config.apiKey) request.headers.set("X-Api-Key", config.apiKey);
|
|
899
886
|
if (config.accessToken) request.headers.set("Authorization", `Bearer ${config.accessToken}`);
|
|
900
887
|
return request;
|
|
@@ -1892,7 +1879,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1892
1879
|
}));
|
|
1893
1880
|
}
|
|
1894
1881
|
/**
|
|
1895
|
-
* Update
|
|
1882
|
+
* Update fulfillment preference
|
|
1896
1883
|
*
|
|
1897
1884
|
* @param cartId - The ID of the cart
|
|
1898
1885
|
* @param body - The body of the request
|
|
@@ -3154,40 +3141,6 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3154
3141
|
* Client for interacting with shipping endpoints
|
|
3155
3142
|
*/
|
|
3156
3143
|
var ShippingClient = class extends StorefrontAPIClient {
|
|
3157
|
-
/**
|
|
3158
|
-
* Get shipping options for an order
|
|
3159
|
-
*
|
|
3160
|
-
* @param body - Shipping methods body
|
|
3161
|
-
* @returns Promise with shipping options
|
|
3162
|
-
* @example
|
|
3163
|
-
* ```typescript
|
|
3164
|
-
* const { data, error } = await sdk.shipping.getShippingMethods({
|
|
3165
|
-
* delivery_pincode: "400001",
|
|
3166
|
-
* cart_id: "cart_01H9XYZ12345ABCDE"
|
|
3167
|
-
* });
|
|
3168
|
-
*
|
|
3169
|
-
* if (error) {
|
|
3170
|
-
* console.error("Failed to get shipping methods:", error.message);
|
|
3171
|
-
* } else {
|
|
3172
|
-
* console.log("Is serviceable:", data.is_serviceable);
|
|
3173
|
-
* console.log("Available shipping methods:", data.shipping_methods?.length || 0);
|
|
3174
|
-
*
|
|
3175
|
-
* data.shipping_methods?.forEach(method => {
|
|
3176
|
-
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
3177
|
-
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
3178
|
-
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
3179
|
-
*
|
|
3180
|
-
* method.courier_companies?.forEach(courier => {
|
|
3181
|
-
* console.log(` - ${courier.name}: ${courier.shipping_amount} (${courier.mode})`);
|
|
3182
|
-
* console.log(` Rating: ${courier.rating}/5, Recommended: ${courier.is_recommended}`);
|
|
3183
|
-
* });
|
|
3184
|
-
* });
|
|
3185
|
-
* }
|
|
3186
|
-
* ```
|
|
3187
|
-
*/
|
|
3188
|
-
async getShippingMethods(body) {
|
|
3189
|
-
return this.executeRequest(() => this.client.POST("/shipping/shipping-methods", { body }));
|
|
3190
|
-
}
|
|
3191
3144
|
/**
|
|
3192
3145
|
* Check pincode deliverability
|
|
3193
3146
|
*
|
|
@@ -3215,6 +3168,47 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
3215
3168
|
async checkPincodeDeliverability(pathParams) {
|
|
3216
3169
|
return this.executeRequest(() => this.client.GET("/shipping/serviceability/{pincode}", { params: { path: pathParams } }));
|
|
3217
3170
|
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Get fulfillment options for an order
|
|
3173
|
+
*
|
|
3174
|
+
* @param body - Fulfillment options body containing cart_id and delivery_pincode
|
|
3175
|
+
* @returns Promise with fulfillment options including collect and delivery methods
|
|
3176
|
+
* @example
|
|
3177
|
+
* ```typescript
|
|
3178
|
+
* const { data, error } = await sdk.shipping.getFulfillmentOptions({
|
|
3179
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3180
|
+
* delivery_pincode: "400001"
|
|
3181
|
+
* });
|
|
3182
|
+
*
|
|
3183
|
+
* if (error) {
|
|
3184
|
+
* console.error("Failed to get fulfillment options:", error.message);
|
|
3185
|
+
* } else {
|
|
3186
|
+
* // Check summary information
|
|
3187
|
+
* console.log("Collect available:", data.summary.collect_available);
|
|
3188
|
+
* console.log("Deliver available:", data.summary.deliver_available);
|
|
3189
|
+
* console.log("Recommended fulfillment type:", data.summary.recommended_fulfillment_type);
|
|
3190
|
+
*
|
|
3191
|
+
* // Access collect options
|
|
3192
|
+
* if (data.collect && data.collect.length > 0) {
|
|
3193
|
+
* console.log("Available stores for collection:");
|
|
3194
|
+
* data.collect.forEach(store => {
|
|
3195
|
+
* console.log(`${store.name} - ${store.distance_km}km away, ETA: ${store.collect_eta_minutes} minutes`);
|
|
3196
|
+
* });
|
|
3197
|
+
* }
|
|
3198
|
+
*
|
|
3199
|
+
* // Access delivery options
|
|
3200
|
+
* if (data.deliver && data.deliver.is_serviceable) {
|
|
3201
|
+
* console.log("Available shipping methods:");
|
|
3202
|
+
* data.deliver.shipping_methods.forEach(method => {
|
|
3203
|
+
* console.log(`${method.name} - ${method.shipping_amount}, ${method.estimated_delivery_days} days`);
|
|
3204
|
+
* });
|
|
3205
|
+
* }
|
|
3206
|
+
* }
|
|
3207
|
+
* ```
|
|
3208
|
+
*/
|
|
3209
|
+
async getFulfillmentOptions(body) {
|
|
3210
|
+
return this.executeRequest(() => this.client.POST("/shipping/fulfillment-options", { body }));
|
|
3211
|
+
}
|
|
3218
3212
|
};
|
|
3219
3213
|
|
|
3220
3214
|
//#endregion
|
|
@@ -3651,6 +3645,29 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
3651
3645
|
async listCustomerReviews(pathParams) {
|
|
3652
3646
|
return this.executeRequest(() => this.client.GET("/customers/{user_id}/reviews", { params: { path: pathParams } }));
|
|
3653
3647
|
}
|
|
3648
|
+
/**
|
|
3649
|
+
* List all saved payment methods for a customer
|
|
3650
|
+
*
|
|
3651
|
+
* @param pathParams - Path parameters
|
|
3652
|
+
* @returns Promise with payment methods
|
|
3653
|
+
*
|
|
3654
|
+
* @example
|
|
3655
|
+
* ```typescript
|
|
3656
|
+
* const { data, error } = await sdk.customer.listSavedPaymentMethods({
|
|
3657
|
+
* customer_id: "customer_123"
|
|
3658
|
+
* });
|
|
3659
|
+
*
|
|
3660
|
+
* if (error) {
|
|
3661
|
+
* console.error("Failed to list saved payment methods:", error);
|
|
3662
|
+
* return;
|
|
3663
|
+
* }
|
|
3664
|
+
*
|
|
3665
|
+
* console.log("Saved payment methods:", data.saved_payment_methods);
|
|
3666
|
+
* ```
|
|
3667
|
+
*/
|
|
3668
|
+
async listSavedPaymentMethods(pathParams) {
|
|
3669
|
+
return this.executeRequest(() => this.client.GET("/customers/{customer_id}/payment-methods", { params: { path: pathParams } }));
|
|
3670
|
+
}
|
|
3654
3671
|
};
|
|
3655
3672
|
|
|
3656
3673
|
//#endregion
|