@commercengine/storefront-sdk 0.3.10 → 0.3.11
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.js +1 -1
- package/dist/lib/catalog.d.ts +2 -2
- package/dist/lib/catalog.js +3 -1
- package/dist/lib/client.d.ts +1 -1
- package/dist/lib/client.js +3 -25
- package/dist/lib/header-utils.d.ts +26 -0
- package/dist/lib/header-utils.js +66 -0
- package/dist/types/storefront-api-types.d.ts +1 -0
- package/dist/types/storefront.d.ts +25 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { HelpersClient } from "./lib/helper";
|
|
|
8
8
|
import { CustomerClient } from "./lib/customer";
|
|
9
9
|
import { MemoryTokenStorage, BrowserTokenStorage, CookieTokenStorage, } from "./lib/middleware";
|
|
10
10
|
import { extractUserInfoFromToken, getUserIdFromToken, isUserLoggedIn, isUserAnonymous, } from "./lib/jwt-utils";
|
|
11
|
-
import { ResponseUtils
|
|
11
|
+
import { ResponseUtils } from "./lib/logger-utils";
|
|
12
12
|
/**
|
|
13
13
|
* Main SDK class for the Storefront API
|
|
14
14
|
*/
|
package/dist/lib/catalog.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StorefrontAPIClient } from "./client";
|
|
2
|
-
import type { ApiResult, GetProductDetailContent, GetProductDetailPathParams, GetProductDetailHeaderParams, GetVariantDetailContent, GetVariantDetailPathParams, GetVariantDetailHeaderParams, ListProductsContent, ListProductsQuery, ListProductsHeaderParams, ListProductVariantsContent, ListProductVariantsPathParams, ListProductVariantsHeaderParams, ListCategoriesQuery, ListCategoriesContent, ListProductReviewsQuery, ListProductReviewsPathParams, ListProductReviewsContent, CreateProductReviewPathParams, CreateProductReviewFormData, CreateProductReviewResponse, SearchProductsBody, SearchProductsContent, ListSkusQuery, ListSkusContent, ListSkusHeaderParams, ListCrosssellProductsContent, ListCrosssellProductsQuery, ListCrosssellProductsHeaderParams, ListUpsellProductsQuery, ListUpsellProductsContent, ListUpsellProductsHeaderParams, ListSimilarProductsQuery, ListSimilarProductsContent, ListSimilarProductsHeaderParams } from "../types/storefront-api-types";
|
|
2
|
+
import type { ApiResult, GetProductDetailContent, GetProductDetailPathParams, GetProductDetailHeaderParams, GetVariantDetailContent, GetVariantDetailPathParams, GetVariantDetailHeaderParams, ListProductsContent, ListProductsQuery, ListProductsHeaderParams, ListProductVariantsContent, ListProductVariantsPathParams, ListProductVariantsHeaderParams, ListCategoriesQuery, ListCategoriesContent, ListProductReviewsQuery, ListProductReviewsPathParams, ListProductReviewsContent, CreateProductReviewPathParams, CreateProductReviewFormData, CreateProductReviewResponse, SearchProductsBody, SearchProductsContent, ListSkusQuery, ListSkusContent, ListSkusHeaderParams, ListCrosssellProductsContent, ListCrosssellProductsQuery, ListCrosssellProductsHeaderParams, ListUpsellProductsQuery, ListUpsellProductsContent, ListUpsellProductsHeaderParams, ListSimilarProductsQuery, ListSimilarProductsContent, ListSimilarProductsHeaderParams, SearchProductsHeaderParams } from "../types/storefront-api-types";
|
|
3
3
|
/**
|
|
4
4
|
* Client for interacting with catalog endpoints
|
|
5
5
|
*/
|
|
@@ -73,7 +73,7 @@ export declare class CatalogClient extends StorefrontAPIClient {
|
|
|
73
73
|
* @param searchData - The search parameters
|
|
74
74
|
* @returns Promise with search results, facet distribution, facet stats, and pagination
|
|
75
75
|
*/
|
|
76
|
-
searchProducts(searchData: SearchProductsBody): Promise<ApiResult<SearchProductsContent>>;
|
|
76
|
+
searchProducts(searchData: SearchProductsBody, headers?: SearchProductsHeaderParams): Promise<ApiResult<SearchProductsContent>>;
|
|
77
77
|
/**
|
|
78
78
|
* List cross-sell products
|
|
79
79
|
*
|
package/dist/lib/catalog.js
CHANGED
|
@@ -146,9 +146,11 @@ export class CatalogClient extends StorefrontAPIClient {
|
|
|
146
146
|
* @param searchData - The search parameters
|
|
147
147
|
* @returns Promise with search results, facet distribution, facet stats, and pagination
|
|
148
148
|
*/
|
|
149
|
-
async searchProducts(searchData) {
|
|
149
|
+
async searchProducts(searchData, headers) {
|
|
150
|
+
const mergedHeaders = this.mergeHeaders(headers);
|
|
150
151
|
return this.executeRequest(() => this.client.POST("/catalog/products/search", {
|
|
151
152
|
body: searchData,
|
|
153
|
+
header: mergedHeaders,
|
|
152
154
|
}));
|
|
153
155
|
}
|
|
154
156
|
/**
|
package/dist/lib/client.d.ts
CHANGED
|
@@ -107,7 +107,7 @@ export declare class StorefrontAPIClient {
|
|
|
107
107
|
* Method-level headers take precedence over default headers
|
|
108
108
|
*
|
|
109
109
|
* @param methodHeaders - Headers passed to the specific method call
|
|
110
|
-
* @returns Merged headers object
|
|
110
|
+
* @returns Merged headers object with proper HTTP header names
|
|
111
111
|
*/
|
|
112
112
|
protected mergeHeaders<T extends Record<string, any> = Record<string, any>>(methodHeaders?: T): T;
|
|
113
113
|
}
|
package/dist/lib/client.js
CHANGED
|
@@ -2,6 +2,7 @@ import createClient from "openapi-fetch";
|
|
|
2
2
|
import { createDefaultAuthMiddleware } from "./middleware";
|
|
3
3
|
import { getPathnameFromUrl, isAnonymousAuthEndpoint } from "./auth-utils";
|
|
4
4
|
import { createDebugMiddleware } from "./logger-utils";
|
|
5
|
+
import { mergeHeaders } from "./header-utils";
|
|
5
6
|
/**
|
|
6
7
|
* Available API environments
|
|
7
8
|
*/
|
|
@@ -288,32 +289,9 @@ export class StorefrontAPIClient {
|
|
|
288
289
|
* Method-level headers take precedence over default headers
|
|
289
290
|
*
|
|
290
291
|
* @param methodHeaders - Headers passed to the specific method call
|
|
291
|
-
* @returns Merged headers object
|
|
292
|
+
* @returns Merged headers object with proper HTTP header names
|
|
292
293
|
*/
|
|
293
294
|
mergeHeaders(methodHeaders) {
|
|
294
|
-
|
|
295
|
-
return {};
|
|
296
|
-
}
|
|
297
|
-
// Start with default headers, but only include supported ones
|
|
298
|
-
const merged = {};
|
|
299
|
-
// Add default headers if they exist
|
|
300
|
-
if (this.config.defaultHeaders) {
|
|
301
|
-
if (this.config.defaultHeaders.customer_group_id !== undefined) {
|
|
302
|
-
merged.customer_group_id =
|
|
303
|
-
this.config.defaultHeaders.customer_group_id;
|
|
304
|
-
}
|
|
305
|
-
// Future: Add other supported headers here as they become available
|
|
306
|
-
}
|
|
307
|
-
if (methodHeaders) {
|
|
308
|
-
// Method headers override default headers
|
|
309
|
-
Object.assign(merged, methodHeaders);
|
|
310
|
-
}
|
|
311
|
-
// Remove undefined values
|
|
312
|
-
Object.keys(merged).forEach((key) => {
|
|
313
|
-
if (merged[key] === undefined) {
|
|
314
|
-
delete merged[key];
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
return merged;
|
|
295
|
+
return mergeHeaders(this.config.defaultHeaders, methodHeaders);
|
|
318
296
|
}
|
|
319
297
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SupportedDefaultHeaders } from "../index";
|
|
2
|
+
/**
|
|
3
|
+
* Transform SDK header parameters to actual HTTP header names
|
|
4
|
+
* Headers not in the transformation map are passed through unchanged
|
|
5
|
+
*
|
|
6
|
+
* @param headers - Headers object with SDK parameter names
|
|
7
|
+
* @returns Headers object with actual HTTP header names
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformHeaders(headers: SupportedDefaultHeaders): Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Merge default headers with method-level headers
|
|
12
|
+
* Method-level headers take precedence over default headers
|
|
13
|
+
* Automatically transforms SDK parameter names to HTTP header names
|
|
14
|
+
*
|
|
15
|
+
* @param defaultHeaders - Default headers from SDK configuration
|
|
16
|
+
* @param methodHeaders - Headers passed to the specific method call
|
|
17
|
+
* @returns Merged headers object with proper HTTP header names
|
|
18
|
+
*/
|
|
19
|
+
export declare function mergeHeaders<T extends Record<string, any> = Record<string, any>>(defaultHeaders?: SupportedDefaultHeaders, methodHeaders?: T): T;
|
|
20
|
+
/**
|
|
21
|
+
* Get the list of supported header transformations
|
|
22
|
+
* Useful for debugging or documentation purposes
|
|
23
|
+
*
|
|
24
|
+
* @returns Copy of the header transformations mapping
|
|
25
|
+
*/
|
|
26
|
+
export declare function getHeaderTransformations(): Record<string, string>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping of SDK header parameter names to actual HTTP header names
|
|
3
|
+
* Only include headers that need transformation - others pass through as-is
|
|
4
|
+
*/
|
|
5
|
+
const HEADER_TRANSFORMATIONS = {
|
|
6
|
+
customer_group_id: "x-customer-group-id",
|
|
7
|
+
// Future transformations can be added here:
|
|
8
|
+
// some_param: "X-Some-Header",
|
|
9
|
+
// another_param: "X-Another-Header",
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Transform SDK header parameters to actual HTTP header names
|
|
13
|
+
* Headers not in the transformation map are passed through unchanged
|
|
14
|
+
*
|
|
15
|
+
* @param headers - Headers object with SDK parameter names
|
|
16
|
+
* @returns Headers object with actual HTTP header names
|
|
17
|
+
*/
|
|
18
|
+
export function transformHeaders(headers) {
|
|
19
|
+
const transformed = {};
|
|
20
|
+
// Iterate through all headers in the input
|
|
21
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
22
|
+
if (value !== undefined) {
|
|
23
|
+
// Use transformation if available, otherwise use the original key
|
|
24
|
+
const headerName = HEADER_TRANSFORMATIONS[key] || key;
|
|
25
|
+
transformed[headerName] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return transformed;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Merge default headers with method-level headers
|
|
32
|
+
* Method-level headers take precedence over default headers
|
|
33
|
+
* Automatically transforms SDK parameter names to HTTP header names
|
|
34
|
+
*
|
|
35
|
+
* @param defaultHeaders - Default headers from SDK configuration
|
|
36
|
+
* @param methodHeaders - Headers passed to the specific method call
|
|
37
|
+
* @returns Merged headers object with proper HTTP header names
|
|
38
|
+
*/
|
|
39
|
+
export function mergeHeaders(defaultHeaders, methodHeaders) {
|
|
40
|
+
const merged = {};
|
|
41
|
+
// Transform and add default headers if they exist
|
|
42
|
+
if (defaultHeaders) {
|
|
43
|
+
const transformedDefaults = transformHeaders(defaultHeaders);
|
|
44
|
+
Object.assign(merged, transformedDefaults);
|
|
45
|
+
}
|
|
46
|
+
// Method headers override default headers
|
|
47
|
+
if (methodHeaders) {
|
|
48
|
+
Object.assign(merged, methodHeaders);
|
|
49
|
+
}
|
|
50
|
+
// Remove undefined values
|
|
51
|
+
Object.keys(merged).forEach((key) => {
|
|
52
|
+
if (merged[key] === undefined) {
|
|
53
|
+
delete merged[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return merged;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the list of supported header transformations
|
|
60
|
+
* Useful for debugging or documentation purposes
|
|
61
|
+
*
|
|
62
|
+
* @returns Copy of the header transformations mapping
|
|
63
|
+
*/
|
|
64
|
+
export function getHeaderTransformations() {
|
|
65
|
+
return { ...HEADER_TRANSFORMATIONS };
|
|
66
|
+
}
|
|
@@ -58,6 +58,7 @@ export type ListCrosssellProductsQuery = paths['/catalog/products/cross-sell']['
|
|
|
58
58
|
export type ListCrosssellProductsHeaderParams = paths['/catalog/products/cross-sell']['get']['parameters']['header'];
|
|
59
59
|
export type SearchProductsResponse = paths['/catalog/products/search']['post']['responses'][200]['content']['application/json'];
|
|
60
60
|
export type SearchProductsContent = SearchProductsResponse['content'];
|
|
61
|
+
export type SearchProductsHeaderParams = paths['/catalog/products/search']['post']['parameters']['header'];
|
|
61
62
|
export type SearchProductsBody = NonNullable<paths['/catalog/products/search']['post']['requestBody']>['content']['application/json'];
|
|
62
63
|
export type CreateCartResponse = paths['/carts']['post']['responses'][200]['content']['application/json'];
|
|
63
64
|
export type CreateCartContent = CreateCartResponse['content'];
|
|
@@ -2426,8 +2426,6 @@ export interface components {
|
|
|
2426
2426
|
* @default 25
|
|
2427
2427
|
*/
|
|
2428
2428
|
limit: number;
|
|
2429
|
-
/** @description to return pricing, promotion and subscriptions data for a specific customer group. Otherwise it will return data as per default customer group. */
|
|
2430
|
-
customer_group_id?: string;
|
|
2431
2429
|
/** @description provide list of attributes for specific facets or * for all facets.
|
|
2432
2430
|
* ```json
|
|
2433
2431
|
* For specific facets: ["size", "color", "brand"]
|
|
@@ -4540,7 +4538,7 @@ export interface components {
|
|
|
4540
4538
|
sortingParam: string;
|
|
4541
4539
|
/** @description search keyword */
|
|
4542
4540
|
searchKeyword: string;
|
|
4543
|
-
/** @description
|
|
4541
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4544
4542
|
CustomerGroupId: string;
|
|
4545
4543
|
};
|
|
4546
4544
|
requestBodies: never;
|
|
@@ -4564,8 +4562,8 @@ export interface operations {
|
|
|
4564
4562
|
category_slug?: string[];
|
|
4565
4563
|
};
|
|
4566
4564
|
header?: {
|
|
4567
|
-
/** @description
|
|
4568
|
-
|
|
4565
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4566
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4569
4567
|
};
|
|
4570
4568
|
path?: never;
|
|
4571
4569
|
cookie?: never;
|
|
@@ -4607,8 +4605,8 @@ export interface operations {
|
|
|
4607
4605
|
sku?: string[];
|
|
4608
4606
|
};
|
|
4609
4607
|
header?: {
|
|
4610
|
-
/** @description
|
|
4611
|
-
|
|
4608
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4609
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4612
4610
|
};
|
|
4613
4611
|
path?: never;
|
|
4614
4612
|
cookie?: never;
|
|
@@ -4639,8 +4637,8 @@ export interface operations {
|
|
|
4639
4637
|
parameters: {
|
|
4640
4638
|
query?: never;
|
|
4641
4639
|
header?: {
|
|
4642
|
-
/** @description
|
|
4643
|
-
|
|
4640
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4641
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4644
4642
|
};
|
|
4645
4643
|
path: {
|
|
4646
4644
|
/** @description The unique identifier of the product. Can be either the product ID or the slug. */
|
|
@@ -4673,8 +4671,8 @@ export interface operations {
|
|
|
4673
4671
|
parameters: {
|
|
4674
4672
|
query?: never;
|
|
4675
4673
|
header?: {
|
|
4676
|
-
/** @description
|
|
4677
|
-
|
|
4674
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4675
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4678
4676
|
};
|
|
4679
4677
|
path: {
|
|
4680
4678
|
/** @description ID of a particular product */
|
|
@@ -4707,8 +4705,8 @@ export interface operations {
|
|
|
4707
4705
|
parameters: {
|
|
4708
4706
|
query?: never;
|
|
4709
4707
|
header?: {
|
|
4710
|
-
/** @description
|
|
4711
|
-
|
|
4708
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4709
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4712
4710
|
};
|
|
4713
4711
|
path: {
|
|
4714
4712
|
/** @description product id */
|
|
@@ -4870,8 +4868,8 @@ export interface operations {
|
|
|
4870
4868
|
sort_by?: string;
|
|
4871
4869
|
};
|
|
4872
4870
|
header?: {
|
|
4873
|
-
/** @description
|
|
4874
|
-
|
|
4871
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4872
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4875
4873
|
};
|
|
4876
4874
|
path?: never;
|
|
4877
4875
|
cookie?: never;
|
|
@@ -4911,8 +4909,8 @@ export interface operations {
|
|
|
4911
4909
|
sort_by?: string;
|
|
4912
4910
|
};
|
|
4913
4911
|
header?: {
|
|
4914
|
-
/** @description
|
|
4915
|
-
|
|
4912
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4913
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4916
4914
|
};
|
|
4917
4915
|
path?: never;
|
|
4918
4916
|
cookie?: never;
|
|
@@ -4953,8 +4951,8 @@ export interface operations {
|
|
|
4953
4951
|
sort_by?: string;
|
|
4954
4952
|
};
|
|
4955
4953
|
header?: {
|
|
4956
|
-
/** @description
|
|
4957
|
-
|
|
4954
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4955
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4958
4956
|
};
|
|
4959
4957
|
path?: never;
|
|
4960
4958
|
cookie?: never;
|
|
@@ -4984,7 +4982,10 @@ export interface operations {
|
|
|
4984
4982
|
"search-products": {
|
|
4985
4983
|
parameters: {
|
|
4986
4984
|
query?: never;
|
|
4987
|
-
header?:
|
|
4985
|
+
header?: {
|
|
4986
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
4987
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
4988
|
+
};
|
|
4988
4989
|
path?: never;
|
|
4989
4990
|
cookie?: never;
|
|
4990
4991
|
};
|
|
@@ -5608,8 +5609,8 @@ export interface operations {
|
|
|
5608
5609
|
parameters: {
|
|
5609
5610
|
query?: never;
|
|
5610
5611
|
header?: {
|
|
5611
|
-
/** @description
|
|
5612
|
-
|
|
5612
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
5613
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
5613
5614
|
};
|
|
5614
5615
|
path?: never;
|
|
5615
5616
|
cookie?: never;
|
|
@@ -5640,8 +5641,8 @@ export interface operations {
|
|
|
5640
5641
|
parameters: {
|
|
5641
5642
|
query?: never;
|
|
5642
5643
|
header?: {
|
|
5643
|
-
/** @description
|
|
5644
|
-
|
|
5644
|
+
/** @description This param is used to determine product pricing, promotions, and subscription rates. If a valid customer group id is provided, pricing details will be retrieved accordingly. If no matching data is found for the specified customer group id, the system will fall back to the default customer group id. If no data is found for the default group either, the highest applicable price will be returned. */
|
|
5645
|
+
"x-customer-group-id"?: components["parameters"]["CustomerGroupId"];
|
|
5645
5646
|
};
|
|
5646
5647
|
path?: never;
|
|
5647
5648
|
cookie?: never;
|