@epcc-sdk/sdks-shopper 0.0.27 → 0.0.29
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/README.md +4 -0
- package/dist/client/@tanstack/react-query.gen.cjs +49 -0
- package/dist/client/@tanstack/react-query.gen.cjs.map +1 -1
- package/dist/client/@tanstack/react-query.gen.d.cts +25 -2
- package/dist/client/@tanstack/react-query.gen.d.ts +25 -2
- package/dist/client/@tanstack/react-query.gen.mjs +50 -1
- package/dist/client/@tanstack/react-query.gen.mjs.map +1 -1
- package/dist/client/index.d.cts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/sdk.gen.cjs +36 -0
- package/dist/client/sdk.gen.cjs.map +1 -1
- package/dist/client/sdk.gen.d.cts +10 -2
- package/dist/client/sdk.gen.d.ts +10 -2
- package/dist/client/sdk.gen.mjs +34 -0
- package/dist/client/sdk.gen.mjs.map +1 -1
- package/dist/client/transformers.gen.cjs +20 -0
- package/dist/client/transformers.gen.cjs.map +1 -1
- package/dist/client/transformers.gen.d.cts +3 -2
- package/dist/client/transformers.gen.d.ts +3 -2
- package/dist/client/transformers.gen.mjs +19 -0
- package/dist/client/transformers.gen.mjs.map +1 -1
- package/dist/client/types.gen.cjs.map +1 -1
- package/dist/client/types.gen.d.cts +271 -1
- package/dist/client/types.gen.d.ts +271 -1
- package/dist/constants/credentials.cjs +32 -0
- package/dist/constants/credentials.cjs.map +1 -0
- package/dist/constants/credentials.d.cts +4 -0
- package/dist/constants/credentials.d.ts +4 -0
- package/dist/constants/credentials.mjs +7 -0
- package/dist/constants/credentials.mjs.map +1 -0
- package/dist/index.cjs +8 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.mjs +5 -2
- package/dist/index.mjs.map +1 -1
- package/dist/interceptors/auth-local-storage-interceptor.cjs +69 -0
- package/dist/interceptors/auth-local-storage-interceptor.cjs.map +1 -0
- package/dist/interceptors/auth-local-storage-interceptor.d.cts +10 -0
- package/dist/interceptors/auth-local-storage-interceptor.d.ts +10 -0
- package/dist/interceptors/auth-local-storage-interceptor.mjs +45 -0
- package/dist/interceptors/auth-local-storage-interceptor.mjs.map +1 -0
- package/dist/interceptors/index.cjs +23 -0
- package/dist/interceptors/index.cjs.map +1 -0
- package/dist/interceptors/index.d.cts +2 -0
- package/dist/interceptors/index.d.ts +2 -0
- package/dist/interceptors/index.mjs +2 -0
- package/dist/interceptors/index.mjs.map +1 -0
- package/dist/test/setup.cjs +27 -0
- package/dist/test/setup.cjs.map +1 -0
- package/dist/test/setup.d.cts +2 -0
- package/dist/test/setup.d.ts +2 -0
- package/dist/test/setup.mjs +26 -0
- package/dist/test/setup.mjs.map +1 -0
- package/dist/utils/get-cart-id.cjs +32 -0
- package/dist/utils/get-cart-id.cjs.map +1 -0
- package/dist/utils/get-cart-id.d.cts +3 -0
- package/dist/utils/get-cart-id.d.ts +3 -0
- package/dist/utils/get-cart-id.mjs +8 -0
- package/dist/utils/get-cart-id.mjs.map +1 -0
- package/dist/utils/index.cjs +8 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.mjs +5 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/initialize-cart.cjs +53 -0
- package/dist/utils/initialize-cart.cjs.map +1 -0
- package/dist/utils/initialize-cart.d.cts +10 -0
- package/dist/utils/initialize-cart.d.ts +10 -0
- package/dist/utils/initialize-cart.mjs +28 -0
- package/dist/utils/initialize-cart.mjs.map +1 -0
- package/dist/utils/token-expired.cjs +31 -0
- package/dist/utils/token-expired.cjs.map +1 -0
- package/dist/utils/token-expired.d.cts +3 -0
- package/dist/utils/token-expired.d.ts +3 -0
- package/dist/utils/token-expired.mjs +7 -0
- package/dist/utils/token-expired.mjs.map +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_jest_dom = require("@testing-library/jest-dom");
|
|
3
|
+
var import_vitest = require("vitest");
|
|
4
|
+
const localStorageMock = (() => {
|
|
5
|
+
let store = {};
|
|
6
|
+
return {
|
|
7
|
+
getItem: import_vitest.vi.fn((key) => store[key] || null),
|
|
8
|
+
setItem: import_vitest.vi.fn((key, value) => {
|
|
9
|
+
store[key] = value;
|
|
10
|
+
}),
|
|
11
|
+
clear: import_vitest.vi.fn(() => {
|
|
12
|
+
store = {};
|
|
13
|
+
}),
|
|
14
|
+
removeItem: import_vitest.vi.fn((key) => {
|
|
15
|
+
delete store[key];
|
|
16
|
+
}),
|
|
17
|
+
key: import_vitest.vi.fn((idx) => Object.keys(store)[idx] || null),
|
|
18
|
+
length: 0
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
import_vitest.vi.resetAllMocks();
|
|
23
|
+
Object.defineProperty(window, "localStorage", { value: localStorageMock });
|
|
24
|
+
localStorageMock.clear();
|
|
25
|
+
});
|
|
26
|
+
import_vitest.vi.stubGlobal("localStorage", localStorageMock);
|
|
27
|
+
//# sourceMappingURL=setup.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/test/setup.ts"],"sourcesContent":["import \"@testing-library/jest-dom\"\nimport { vi } from \"vitest\"\n\n// Setup global localStorage mock\nconst localStorageMock = (() => {\n let store: Record<string, string> = {}\n return {\n getItem: vi.fn((key: string) => store[key] || null),\n setItem: vi.fn((key: string, value: string) => {\n store[key] = value\n }),\n clear: vi.fn(() => {\n store = {}\n }),\n removeItem: vi.fn((key: string) => {\n delete store[key]\n }),\n key: vi.fn((idx: number) => Object.keys(store)[idx] || null),\n length: 0,\n }\n})()\n\nbeforeEach(() => {\n vi.resetAllMocks()\n // Setup localStorage mock\n Object.defineProperty(window, \"localStorage\", { value: localStorageMock })\n localStorageMock.clear()\n})\n\n// Make localStorage mock available globally for tests\nvi.stubGlobal(\"localStorage\", localStorageMock)\n"],"mappings":";AAAA,sBAAO;AACP,oBAAmB;AAGnB,MAAM,oBAAoB,MAAM;AAC9B,MAAI,QAAgC,CAAC;AACrC,SAAO;AAAA,IACL,SAAS,iBAAG,GAAG,CAAC,QAAgB,MAAM,GAAG,KAAK,IAAI;AAAA,IAClD,SAAS,iBAAG,GAAG,CAAC,KAAa,UAAkB;AAC7C,YAAM,GAAG,IAAI;AAAA,IACf,CAAC;AAAA,IACD,OAAO,iBAAG,GAAG,MAAM;AACjB,cAAQ,CAAC;AAAA,IACX,CAAC;AAAA,IACD,YAAY,iBAAG,GAAG,CAAC,QAAgB;AACjC,aAAO,MAAM,GAAG;AAAA,IAClB,CAAC;AAAA,IACD,KAAK,iBAAG,GAAG,CAAC,QAAgB,OAAO,KAAK,KAAK,EAAE,GAAG,KAAK,IAAI;AAAA,IAC3D,QAAQ;AAAA,EACV;AACF,GAAG;AAEH,WAAW,MAAM;AACf,mBAAG,cAAc;AAEjB,SAAO,eAAe,QAAQ,gBAAgB,EAAE,OAAO,iBAAiB,CAAC;AACzE,mBAAiB,MAAM;AACzB,CAAC;AAGD,iBAAG,WAAW,gBAAgB,gBAAgB;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import { vi } from "vitest";
|
|
3
|
+
const localStorageMock = (() => {
|
|
4
|
+
let store = {};
|
|
5
|
+
return {
|
|
6
|
+
getItem: vi.fn((key) => store[key] || null),
|
|
7
|
+
setItem: vi.fn((key, value) => {
|
|
8
|
+
store[key] = value;
|
|
9
|
+
}),
|
|
10
|
+
clear: vi.fn(() => {
|
|
11
|
+
store = {};
|
|
12
|
+
}),
|
|
13
|
+
removeItem: vi.fn((key) => {
|
|
14
|
+
delete store[key];
|
|
15
|
+
}),
|
|
16
|
+
key: vi.fn((idx) => Object.keys(store)[idx] || null),
|
|
17
|
+
length: 0
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
vi.resetAllMocks();
|
|
22
|
+
Object.defineProperty(window, "localStorage", { value: localStorageMock });
|
|
23
|
+
localStorageMock.clear();
|
|
24
|
+
});
|
|
25
|
+
vi.stubGlobal("localStorage", localStorageMock);
|
|
26
|
+
//# sourceMappingURL=setup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/test/setup.ts"],"sourcesContent":["import \"@testing-library/jest-dom\"\nimport { vi } from \"vitest\"\n\n// Setup global localStorage mock\nconst localStorageMock = (() => {\n let store: Record<string, string> = {}\n return {\n getItem: vi.fn((key: string) => store[key] || null),\n setItem: vi.fn((key: string, value: string) => {\n store[key] = value\n }),\n clear: vi.fn(() => {\n store = {}\n }),\n removeItem: vi.fn((key: string) => {\n delete store[key]\n }),\n key: vi.fn((idx: number) => Object.keys(store)[idx] || null),\n length: 0,\n }\n})()\n\nbeforeEach(() => {\n vi.resetAllMocks()\n // Setup localStorage mock\n Object.defineProperty(window, \"localStorage\", { value: localStorageMock })\n localStorageMock.clear()\n})\n\n// Make localStorage mock available globally for tests\nvi.stubGlobal(\"localStorage\", localStorageMock)\n"],"mappings":"AAAA,OAAO;AACP,SAAS,UAAU;AAGnB,MAAM,oBAAoB,MAAM;AAC9B,MAAI,QAAgC,CAAC;AACrC,SAAO;AAAA,IACL,SAAS,GAAG,GAAG,CAAC,QAAgB,MAAM,GAAG,KAAK,IAAI;AAAA,IAClD,SAAS,GAAG,GAAG,CAAC,KAAa,UAAkB;AAC7C,YAAM,GAAG,IAAI;AAAA,IACf,CAAC;AAAA,IACD,OAAO,GAAG,GAAG,MAAM;AACjB,cAAQ,CAAC;AAAA,IACX,CAAC;AAAA,IACD,YAAY,GAAG,GAAG,CAAC,QAAgB;AACjC,aAAO,MAAM,GAAG;AAAA,IAClB,CAAC;AAAA,IACD,KAAK,GAAG,GAAG,CAAC,QAAgB,OAAO,KAAK,KAAK,EAAE,GAAG,KAAK,IAAI;AAAA,IAC3D,QAAQ;AAAA,EACV;AACF,GAAG;AAEH,WAAW,MAAM;AACf,KAAG,cAAc;AAEjB,SAAO,eAAe,QAAQ,gBAAgB,EAAE,OAAO,iBAAiB,CAAC;AACzE,mBAAiB,MAAM;AACzB,CAAC;AAGD,GAAG,WAAW,gBAAgB,gBAAgB;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_cart_id_exports = {};
|
|
20
|
+
__export(get_cart_id_exports, {
|
|
21
|
+
getCartId: () => getCartId
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_cart_id_exports);
|
|
24
|
+
var import_initialize_cart = require('./initialize-cart.cjs');
|
|
25
|
+
function getCartId() {
|
|
26
|
+
return localStorage.getItem(import_initialize_cart.PERSISTED_CART_STORAGE_KEY);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
getCartId
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=get-cart-id.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-cart-id.ts"],"sourcesContent":["import { PERSISTED_CART_STORAGE_KEY } from \"./initialize-cart\"\n\nexport function getCartId() {\n return localStorage.getItem(PERSISTED_CART_STORAGE_KEY)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA2C;AAEpC,SAAS,YAAY;AAC1B,SAAO,aAAa,QAAQ,iDAA0B;AACxD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-cart-id.ts"],"sourcesContent":["import { PERSISTED_CART_STORAGE_KEY } from \"./initialize-cart\"\n\nexport function getCartId() {\n return localStorage.getItem(PERSISTED_CART_STORAGE_KEY)\n}\n"],"mappings":"AAAA,SAAS,kCAAkC;AAEpC,SAAS,YAAY;AAC1B,SAAO,aAAa,QAAQ,0BAA0B;AACxD;","names":[]}
|
package/dist/utils/index.cjs
CHANGED
|
@@ -19,14 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
extractProductImage: () => import_extract_product_image.extractProductImage,
|
|
22
|
-
extractProductMedia: () => import_extract_media.extractProductMedia
|
|
22
|
+
extractProductMedia: () => import_extract_media.extractProductMedia,
|
|
23
|
+
getCartId: () => import_get_cart_id.getCartId,
|
|
24
|
+
initializeCart: () => import_initialize_cart.initializeCart
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(utils_exports);
|
|
25
27
|
var import_extract_product_image = require('./extract-product-image.cjs');
|
|
26
28
|
var import_extract_media = require('./extract-media.cjs');
|
|
29
|
+
var import_initialize_cart = require('./initialize-cart.cjs');
|
|
30
|
+
var import_get_cart_id = require('./get-cart-id.cjs');
|
|
27
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
32
|
0 && (module.exports = {
|
|
29
33
|
extractProductImage,
|
|
30
|
-
extractProductMedia
|
|
34
|
+
extractProductMedia,
|
|
35
|
+
getCartId,
|
|
36
|
+
initializeCart
|
|
31
37
|
});
|
|
32
38
|
//# sourceMappingURL=index.cjs.map
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export { extractProductImage } from \"./extract-product-image\"\nexport { extractProductMedia } from \"./extract-media\"\nexport type { ExtractedMedia } from \"./extract-media\"\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mCAAoC;AACpC,2BAAoC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export { extractProductImage } from \"./extract-product-image\"\nexport { extractProductMedia } from \"./extract-media\"\nexport type { ExtractedMedia } from \"./extract-media\"\nexport { initializeCart } from \"./initialize-cart\"\nexport { getCartId } from \"./get-cart-id\"\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mCAAoC;AACpC,2BAAoC;AAEpC,6BAA+B;AAC/B,yBAA0B;","names":[]}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { extractProductImage } from './extract-product-image.cjs';
|
|
2
2
|
export { ExtractedMedia, extractProductMedia } from './extract-media.cjs';
|
|
3
|
+
export { initializeCart } from './initialize-cart.cjs';
|
|
4
|
+
export { getCartId } from './get-cart-id.cjs';
|
|
3
5
|
import '../client/types.gen.cjs';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { extractProductImage } from './extract-product-image.js';
|
|
2
2
|
export { ExtractedMedia, extractProductMedia } from './extract-media.js';
|
|
3
|
+
export { initializeCart } from './initialize-cart.js';
|
|
4
|
+
export { getCartId } from './get-cart-id.js';
|
|
3
5
|
import '../client/types.gen.js';
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { extractProductImage } from "./extract-product-image.mjs";
|
|
2
2
|
import { extractProductMedia } from "./extract-media.mjs";
|
|
3
|
+
import { initializeCart } from "./initialize-cart.mjs";
|
|
4
|
+
import { getCartId } from "./get-cart-id.mjs";
|
|
3
5
|
export {
|
|
4
6
|
extractProductImage,
|
|
5
|
-
extractProductMedia
|
|
7
|
+
extractProductMedia,
|
|
8
|
+
getCartId,
|
|
9
|
+
initializeCart
|
|
6
10
|
};
|
|
7
11
|
//# sourceMappingURL=index.mjs.map
|
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export { extractProductImage } from \"./extract-product-image\"\nexport { extractProductMedia } from \"./extract-media\"\nexport type { ExtractedMedia } from \"./extract-media\"\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export { extractProductImage } from \"./extract-product-image\"\nexport { extractProductMedia } from \"./extract-media\"\nexport type { ExtractedMedia } from \"./extract-media\"\nexport { initializeCart } from \"./initialize-cart\"\nexport { getCartId } from \"./get-cart-id\"\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AAEpC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var initialize_cart_exports = {};
|
|
20
|
+
__export(initialize_cart_exports, {
|
|
21
|
+
PERSISTED_CART_STORAGE_KEY: () => PERSISTED_CART_STORAGE_KEY,
|
|
22
|
+
initializeCart: () => initializeCart
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(initialize_cart_exports);
|
|
25
|
+
var import_client = require('../client/index.cjs');
|
|
26
|
+
var import_credentials = require('../constants/credentials.cjs');
|
|
27
|
+
let PERSISTED_CART_STORAGE_KEY = import_credentials.CART_STORAGE_KEY;
|
|
28
|
+
async function initializeCart(options) {
|
|
29
|
+
PERSISTED_CART_STORAGE_KEY = options?.storageKey ?? PERSISTED_CART_STORAGE_KEY;
|
|
30
|
+
let cartId = localStorage.getItem(PERSISTED_CART_STORAGE_KEY);
|
|
31
|
+
if (!cartId) {
|
|
32
|
+
const cartResponse = await (0, import_client.createACart)({
|
|
33
|
+
body: {
|
|
34
|
+
data: {
|
|
35
|
+
name: "Storefront cart",
|
|
36
|
+
description: "Standard cart created by the Storefront SDK"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (!cartResponse.data?.data?.id) {
|
|
41
|
+
throw new Error("Failed to create cart");
|
|
42
|
+
}
|
|
43
|
+
cartId = cartResponse.data.data.id;
|
|
44
|
+
localStorage.setItem(PERSISTED_CART_STORAGE_KEY, cartId);
|
|
45
|
+
}
|
|
46
|
+
return cartId;
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
PERSISTED_CART_STORAGE_KEY,
|
|
51
|
+
initializeCart
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=initialize-cart.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/initialize-cart.ts"],"sourcesContent":["import { createACart } from \"../client\"\nimport { CART_STORAGE_KEY } from \"../constants/credentials\"\n\nexport let PERSISTED_CART_STORAGE_KEY = CART_STORAGE_KEY\n\n/**\n * Initialize a cart and return the cartId\n * @returns {Promise<string>} The cartId\n */\nexport async function initializeCart(options?: {\n storageKey?: string\n}): Promise<string> {\n PERSISTED_CART_STORAGE_KEY = options?.storageKey ?? PERSISTED_CART_STORAGE_KEY\n let cartId = localStorage.getItem(PERSISTED_CART_STORAGE_KEY)\n\n // check if cartId is missing\n if (!cartId) {\n // Create a new cart\n const cartResponse = await createACart({\n body: {\n data: {\n name: \"Storefront cart\",\n description: \"Standard cart created by the Storefront SDK\",\n },\n },\n })\n\n if (!cartResponse.data?.data?.id) {\n throw new Error(\"Failed to create cart\")\n }\n\n cartId = cartResponse.data.data.id\n // Store the cartId in localStorage\n localStorage.setItem(PERSISTED_CART_STORAGE_KEY, cartId)\n }\n\n return cartId\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4B;AAC5B,yBAAiC;AAE1B,IAAI,6BAA6B;AAMxC,eAAsB,eAAe,SAEjB;AAClB,+BAA6B,SAAS,cAAc;AACpD,MAAI,SAAS,aAAa,QAAQ,0BAA0B;AAG5D,MAAI,CAAC,QAAQ;AAEX,UAAM,eAAe,UAAM,2BAAY;AAAA,MACrC,MAAM;AAAA,QACJ,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC,aAAa,MAAM,MAAM,IAAI;AAChC,YAAM,IAAI,MAAM,uBAAuB;AAAA,IACzC;AAEA,aAAS,aAAa,KAAK,KAAK;AAEhC,iBAAa,QAAQ,4BAA4B,MAAM;AAAA,EACzD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare let PERSISTED_CART_STORAGE_KEY: string;
|
|
2
|
+
/**
|
|
3
|
+
* Initialize a cart and return the cartId
|
|
4
|
+
* @returns {Promise<string>} The cartId
|
|
5
|
+
*/
|
|
6
|
+
declare function initializeCart(options?: {
|
|
7
|
+
storageKey?: string;
|
|
8
|
+
}): Promise<string>;
|
|
9
|
+
|
|
10
|
+
export { PERSISTED_CART_STORAGE_KEY, initializeCart };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare let PERSISTED_CART_STORAGE_KEY: string;
|
|
2
|
+
/**
|
|
3
|
+
* Initialize a cart and return the cartId
|
|
4
|
+
* @returns {Promise<string>} The cartId
|
|
5
|
+
*/
|
|
6
|
+
declare function initializeCart(options?: {
|
|
7
|
+
storageKey?: string;
|
|
8
|
+
}): Promise<string>;
|
|
9
|
+
|
|
10
|
+
export { PERSISTED_CART_STORAGE_KEY, initializeCart };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createACart } from "../client/index.mjs";
|
|
2
|
+
import { CART_STORAGE_KEY } from "../constants/credentials.mjs";
|
|
3
|
+
let PERSISTED_CART_STORAGE_KEY = CART_STORAGE_KEY;
|
|
4
|
+
async function initializeCart(options) {
|
|
5
|
+
PERSISTED_CART_STORAGE_KEY = options?.storageKey ?? PERSISTED_CART_STORAGE_KEY;
|
|
6
|
+
let cartId = localStorage.getItem(PERSISTED_CART_STORAGE_KEY);
|
|
7
|
+
if (!cartId) {
|
|
8
|
+
const cartResponse = await createACart({
|
|
9
|
+
body: {
|
|
10
|
+
data: {
|
|
11
|
+
name: "Storefront cart",
|
|
12
|
+
description: "Standard cart created by the Storefront SDK"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!cartResponse.data?.data?.id) {
|
|
17
|
+
throw new Error("Failed to create cart");
|
|
18
|
+
}
|
|
19
|
+
cartId = cartResponse.data.data.id;
|
|
20
|
+
localStorage.setItem(PERSISTED_CART_STORAGE_KEY, cartId);
|
|
21
|
+
}
|
|
22
|
+
return cartId;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
PERSISTED_CART_STORAGE_KEY,
|
|
26
|
+
initializeCart
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=initialize-cart.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/initialize-cart.ts"],"sourcesContent":["import { createACart } from \"../client\"\nimport { CART_STORAGE_KEY } from \"../constants/credentials\"\n\nexport let PERSISTED_CART_STORAGE_KEY = CART_STORAGE_KEY\n\n/**\n * Initialize a cart and return the cartId\n * @returns {Promise<string>} The cartId\n */\nexport async function initializeCart(options?: {\n storageKey?: string\n}): Promise<string> {\n PERSISTED_CART_STORAGE_KEY = options?.storageKey ?? PERSISTED_CART_STORAGE_KEY\n let cartId = localStorage.getItem(PERSISTED_CART_STORAGE_KEY)\n\n // check if cartId is missing\n if (!cartId) {\n // Create a new cart\n const cartResponse = await createACart({\n body: {\n data: {\n name: \"Storefront cart\",\n description: \"Standard cart created by the Storefront SDK\",\n },\n },\n })\n\n if (!cartResponse.data?.data?.id) {\n throw new Error(\"Failed to create cart\")\n }\n\n cartId = cartResponse.data.data.id\n // Store the cartId in localStorage\n localStorage.setItem(PERSISTED_CART_STORAGE_KEY, cartId)\n }\n\n return cartId\n}\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AAE1B,IAAI,6BAA6B;AAMxC,eAAsB,eAAe,SAEjB;AAClB,+BAA6B,SAAS,cAAc;AACpD,MAAI,SAAS,aAAa,QAAQ,0BAA0B;AAG5D,MAAI,CAAC,QAAQ;AAEX,UAAM,eAAe,MAAM,YAAY;AAAA,MACrC,MAAM;AAAA,QACJ,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC,aAAa,MAAM,MAAM,IAAI;AAChC,YAAM,IAAI,MAAM,uBAAuB;AAAA,IACzC;AAEA,aAAS,aAAa,KAAK,KAAK;AAEhC,iBAAa,QAAQ,4BAA4B,MAAM;AAAA,EACzD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var token_expired_exports = {};
|
|
20
|
+
__export(token_expired_exports, {
|
|
21
|
+
tokenExpired: () => tokenExpired
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(token_expired_exports);
|
|
24
|
+
function tokenExpired(expires) {
|
|
25
|
+
return Math.floor(Date.now() / 1e3) >= expires;
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
tokenExpired
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=token-expired.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/token-expired.ts"],"sourcesContent":["export function tokenExpired(expires: number): boolean {\n return Math.floor(Date.now() / 1000) >= expires\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,aAAa,SAA0B;AACrD,SAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,KAAK;AAC1C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/token-expired.ts"],"sourcesContent":["export function tokenExpired(expires: number): boolean {\n return Math.floor(Date.now() / 1000) >= expires\n}\n"],"mappings":"AAAO,SAAS,aAAa,SAA0B;AACrD,SAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,KAAK;AAC1C;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epcc-sdk/sdks-shopper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -28,13 +28,16 @@
|
|
|
28
28
|
"@redocly/cli": "^1.21.0",
|
|
29
29
|
"@redocly/openapi-core": "^1.21.0",
|
|
30
30
|
"@tanstack/react-query": "^5.69.0",
|
|
31
|
+
"@testing-library/jest-dom": "6.6.3",
|
|
31
32
|
"@types/ejs": "^3.1.5",
|
|
32
33
|
"ejs": "^3.1.10",
|
|
33
34
|
"esbuild-fix-imports-plugin": "^1.0.19",
|
|
34
35
|
"esbuild-plugin-file-path-extensions": "^1.0.0",
|
|
36
|
+
"jsdom": "26.1.0",
|
|
35
37
|
"lodash": "^4.17.21",
|
|
36
38
|
"tsup": "^8.4.0",
|
|
37
|
-
"typescript": "^5.5.3"
|
|
39
|
+
"typescript": "^5.5.3",
|
|
40
|
+
"vitest": "3.1.4"
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
43
|
"@hey-api/client-fetch": "0.6.0"
|
|
@@ -57,8 +60,11 @@
|
|
|
57
60
|
"oas:openapi-ts": "openapi-ts",
|
|
58
61
|
"oas:redocly": "redocly --config ./redocly.json",
|
|
59
62
|
"oas:redocly:lint": "redocly lint --config ../specs/config/redocly.yaml",
|
|
60
|
-
"oas:redocly:join:shopper": "redocly join --config ../specs/config/redocly.yaml --output ../specs/shopper.yaml ../specs/bundled/catalog_view_3.1.yaml ../specs/bundled/cart_checkout.yaml ../specs/bundled/subscriptions_3.1.yaml ../specs/bundled/inventories_3.1.yaml ../specs/bundled/authentication.yaml ../specs/bundled/account-addresses.yaml ../specs/bundled/account_management.yaml ../specs/bundled/currencies.yaml ../specs/bundled/files.yaml",
|
|
63
|
+
"oas:redocly:join:shopper": "redocly join --config ../specs/config/redocly.yaml --output ../specs/shopper.yaml ../specs/bundled/catalog_view_3.1.yaml ../specs/bundled/cart_checkout.yaml ../specs/bundled/subscriptions_3.1.yaml ../specs/bundled/inventories_3.1.yaml ../specs/bundled/authentication.yaml ../specs/bundled/account-addresses.yaml ../specs/bundled/account_management.yaml ../specs/bundled/authentication-realms.yaml ../specs/bundled/currencies.yaml ../specs/bundled/files.yaml",
|
|
61
64
|
"oas:redocly:bundle": "redocly bundle --config ../specs/config/redocly.yaml",
|
|
62
|
-
"oas:openapi-format:convert": "pnpm dlx openapi-format ../specs/bundled/catalog_view.yaml -o ../specs/bundled/catalog_view_3.1.yaml --convertTo \"3.1\" && pnpm dlx openapi-format ../specs/bundled/subscriptions.yaml -o ../specs/bundled/subscriptions_3.1.yaml --convertTo \"3.1\" && pnpm dlx openapi-format ../specs/bundled/inventories.yaml -o ../specs/bundled/inventories_3.1.yaml --convertTo \"3.1\""
|
|
65
|
+
"oas:openapi-format:convert": "pnpm dlx openapi-format ../specs/bundled/catalog_view.yaml -o ../specs/bundled/catalog_view_3.1.yaml --convertTo \"3.1\" && pnpm dlx openapi-format ../specs/bundled/subscriptions.yaml -o ../specs/bundled/subscriptions_3.1.yaml --convertTo \"3.1\" && pnpm dlx openapi-format ../specs/bundled/inventories.yaml -o ../specs/bundled/inventories_3.1.yaml --convertTo \"3.1\"",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"test:watch": "vitest",
|
|
68
|
+
"test:coverage": "vitest run --coverage"
|
|
63
69
|
}
|
|
64
70
|
}
|