@tiledev/sdk-shopify 0.5.0 → 0.8.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.
- package/README.md +144 -1
- package/dist/alertSettings.d.ts +39 -0
- package/dist/alertSettings.d.ts.map +1 -0
- package/dist/alertSettings.js +76 -0
- package/dist/alertSettings.js.map +1 -0
- package/dist/blogs.d.ts.map +1 -1
- package/dist/blogs.js +3 -3
- package/dist/blogs.js.map +1 -1
- package/dist/cart.d.ts.map +1 -1
- package/dist/cart.js +27 -22
- package/dist/cart.js.map +1 -1
- package/dist/client.d.ts +20 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +80 -19
- package/dist/client.js.map +1 -1
- package/dist/collections.d.ts.map +1 -1
- package/dist/collections.js +8 -5
- package/dist/collections.js.map +1 -1
- package/dist/customer.d.ts.map +1 -1
- package/dist/customer.js +3 -3
- package/dist/customer.js.map +1 -1
- package/dist/deviceStore.d.ts +9 -0
- package/dist/deviceStore.d.ts.map +1 -0
- package/dist/deviceStore.js +77 -0
- package/dist/deviceStore.js.map +1 -0
- package/dist/deviceStore.native.d.ts +14 -0
- package/dist/deviceStore.native.d.ts.map +1 -0
- package/dist/deviceStore.native.js +47 -0
- package/dist/deviceStore.native.js.map +1 -0
- package/dist/deviceStoreCore.d.ts +24 -0
- package/dist/deviceStoreCore.d.ts.map +1 -0
- package/dist/deviceStoreCore.js +40 -0
- package/dist/deviceStoreCore.js.map +1 -0
- package/dist/filters.d.ts +32 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +67 -0
- package/dist/filters.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1
- package/dist/index.js.map +1 -1
- package/dist/productStore.d.ts +43 -0
- package/dist/productStore.d.ts.map +1 -0
- package/dist/productStore.js +309 -0
- package/dist/productStore.js.map +1 -0
- package/dist/products.d.ts.map +1 -1
- package/dist/products.js +28 -19
- package/dist/products.js.map +1 -1
- package/dist/queries.d.ts +24 -24
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +4 -3
- package/dist/queries.js.map +1 -1
- package/dist/react/ShopifyProvider.d.ts +2 -0
- package/dist/react/ShopifyProvider.d.ts.map +1 -1
- package/dist/react/ShopifyProvider.js +18 -1
- package/dist/react/ShopifyProvider.js.map +1 -1
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +11 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/useAlertSettings.d.ts +32 -0
- package/dist/react/useAlertSettings.d.ts.map +1 -0
- package/dist/react/useAlertSettings.js +35 -0
- package/dist/react/useAlertSettings.js.map +1 -0
- package/dist/react/useCollectionProducts.d.ts +12 -20
- package/dist/react/useCollectionProducts.d.ts.map +1 -1
- package/dist/react/useCollectionProducts.js +36 -137
- package/dist/react/useCollectionProducts.js.map +1 -1
- package/dist/react/useProduct.d.ts +36 -0
- package/dist/react/useProduct.d.ts.map +1 -0
- package/dist/react/useProduct.js +126 -0
- package/dist/react/useProduct.js.map +1 -0
- package/dist/react/useProductFeed.d.ts +57 -0
- package/dist/react/useProductFeed.d.ts.map +1 -0
- package/dist/react/useProductFeed.js +231 -0
- package/dist/react/useProductFeed.js.map +1 -0
- package/dist/react/useSearch.d.ts +30 -0
- package/dist/react/useSearch.d.ts.map +1 -0
- package/dist/react/useSearch.js +61 -0
- package/dist/react/useSearch.js.map +1 -0
- package/dist/requestCache.d.ts +48 -0
- package/dist/requestCache.d.ts.map +1 -0
- package/dist/requestCache.js +173 -0
- package/dist/requestCache.js.map +1 -0
- package/dist/types.d.ts +67 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/dist/variants.js +1 -1
- package/dist/variants.js.map +1 -1
- package/dist/wishlist.d.ts.map +1 -1
- package/dist/wishlist.js +4 -1
- package/dist/wishlist.js.map +1 -1
- package/package.json +9 -3
package/dist/client.js
CHANGED
|
@@ -6,10 +6,12 @@ exports.getCurrencyCode = getCurrencyCode;
|
|
|
6
6
|
exports.setConfig = setConfig;
|
|
7
7
|
exports.getConfig = getConfig;
|
|
8
8
|
exports.isConfigured = isConfigured;
|
|
9
|
+
exports.withImageTransform = withImageTransform;
|
|
9
10
|
exports.request = request;
|
|
10
11
|
exports.assertNoUserErrors = assertNoUserErrors;
|
|
11
12
|
const types_1 = require("./types");
|
|
12
13
|
const metafields_1 = require("./metafields");
|
|
14
|
+
const requestCache_1 = require("./requestCache");
|
|
13
15
|
const state = { config: null, moneyFormat: null, currencyCode: null };
|
|
14
16
|
function setShopInfo(info) {
|
|
15
17
|
if (info.moneyFormat)
|
|
@@ -30,8 +32,26 @@ function setConfig(config) {
|
|
|
30
32
|
throw new Error('shopify.init: storeDomain is required');
|
|
31
33
|
if (!config.storefrontAccessToken)
|
|
32
34
|
throw new Error('shopify.init: storefrontAccessToken is required');
|
|
35
|
+
const changed = !state.config || signature(state.config) !== signature(config);
|
|
33
36
|
state.config = config;
|
|
34
37
|
(0, metafields_1.setProductMetafields)(config.productMetafields);
|
|
38
|
+
// Only a real change resets the request cache: `ShopifyProvider` sets the config on its first
|
|
39
|
+
// render and `init` sets it again, and that second call must not drop requests already started.
|
|
40
|
+
if (changed)
|
|
41
|
+
(0, requestCache_1.configureRequestCache)(config.cache);
|
|
42
|
+
}
|
|
43
|
+
/** Everything in a config that changes what a request returns, or how the cache behaves. */
|
|
44
|
+
function signature(c) {
|
|
45
|
+
var _a, _b, _c, _d, _e;
|
|
46
|
+
return JSON.stringify([
|
|
47
|
+
c.storeDomain,
|
|
48
|
+
c.storefrontAccessToken,
|
|
49
|
+
(_a = c.apiVersion) !== null && _a !== void 0 ? _a : null,
|
|
50
|
+
(_b = c.country) !== null && _b !== void 0 ? _b : null,
|
|
51
|
+
(_c = c.language) !== null && _c !== void 0 ? _c : null,
|
|
52
|
+
(_d = c.productMetafields) !== null && _d !== void 0 ? _d : null,
|
|
53
|
+
(_e = c.cache) !== null && _e !== void 0 ? _e : null,
|
|
54
|
+
]);
|
|
35
55
|
}
|
|
36
56
|
function getConfig() {
|
|
37
57
|
if (!state.config)
|
|
@@ -136,28 +156,69 @@ function withContext(operation) {
|
|
|
136
156
|
return operation;
|
|
137
157
|
return `${operation.slice(0, braceAt)}query ${directive} ${operation.slice(braceAt)}`;
|
|
138
158
|
}
|
|
139
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Declares `$imageTransform` on an operation whose fragments use it (`ImageFields`, media URLs).
|
|
161
|
+
* GraphQL requires every operation to declare the variables its fragments use; doing it here means
|
|
162
|
+
* no query can forget, and any operation that returns images accepts a transform. An operation that
|
|
163
|
+
* uses no image URL is returned untouched. Runs before `withContext`, while the operation's
|
|
164
|
+
* argument list still directly follows its name.
|
|
165
|
+
*/
|
|
166
|
+
function withImageTransform(operation) {
|
|
167
|
+
var _a, _b;
|
|
168
|
+
if (!/\$imageTransform\b/.test(operation) || /\$imageTransform\s*:/.test(operation))
|
|
169
|
+
return operation;
|
|
170
|
+
const decl = '$imageTransform: ImageTransformInput';
|
|
171
|
+
const opMatch = operation.match(/(^|\n)([ \t]*(?:query|mutation)\b[ \t]*[A-Za-z_][A-Za-z0-9_]*[ \t]*)(\(([\s\S]*?)\))?/);
|
|
172
|
+
if (!opMatch)
|
|
173
|
+
return operation;
|
|
174
|
+
const at = opMatch.index + opMatch[1].length;
|
|
175
|
+
const head = opMatch[2];
|
|
176
|
+
const replaced = opMatch[3] !== undefined ? `${head}(${opMatch[4].replace(/\s*$/, '')}, ${decl})` : `${head.replace(/\s*$/, '')}(${decl}) `;
|
|
177
|
+
return operation.slice(0, at) + replaced + operation.slice(at + head.length + ((_b = (_a = opMatch[3]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* One Storefront call. Identical queries share one network request, and catalogue reads reuse a
|
|
181
|
+
* recent answer (see `requestCache.ts`); mutations always go to the network.
|
|
182
|
+
*/
|
|
183
|
+
async function request(operation, variables, options) {
|
|
140
184
|
const c = getConfig();
|
|
141
|
-
const query = withContext(deduplicateFragments(operation));
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
185
|
+
const query = withContext(withImageTransform(deduplicateFragments(operation)));
|
|
186
|
+
// Sent only when set: an absent variable is a null transform, and keeping it out of the variables
|
|
187
|
+
// keeps the cache key of an untransformed read what it always was.
|
|
188
|
+
const vars = (options === null || options === void 0 ? void 0 : options.imageTransform) && /\$imageTransform\s*:/.test(query)
|
|
189
|
+
? { ...(variables !== null && variables !== void 0 ? variables : {}), imageTransform: options.imageTransform }
|
|
190
|
+
: variables;
|
|
191
|
+
const url = endpoint();
|
|
192
|
+
const text = await (0, requestCache_1.readThrough)(`${url}\n${c.storefrontAccessToken}`, query, vars, (options === null || options === void 0 ? void 0 : options.fresh) === true, async () => {
|
|
193
|
+
const res = await fetch(url, {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
headers: {
|
|
196
|
+
'Content-Type': 'application/json',
|
|
197
|
+
'X-Shopify-Storefront-Access-Token': c.storefrontAccessToken,
|
|
198
|
+
'Accept': 'application/json',
|
|
199
|
+
'Accept-Language': c.language || 'en',
|
|
200
|
+
},
|
|
201
|
+
body: JSON.stringify({ query, variables: vars !== null && vars !== void 0 ? vars : {} }),
|
|
202
|
+
});
|
|
203
|
+
if (!res.ok) {
|
|
204
|
+
let bodyText = '';
|
|
205
|
+
try {
|
|
206
|
+
bodyText = await res.text();
|
|
207
|
+
}
|
|
208
|
+
catch { /* ignore */ }
|
|
209
|
+
throw new types_1.ShopifyError(`Shopify Storefront API HTTP ${res.status}: ${res.statusText}${bodyText ? ` — ${bodyText.slice(0, 200)}` : ''}`);
|
|
156
210
|
}
|
|
157
|
-
|
|
158
|
-
|
|
211
|
+
// Real responses have text(); some test mocks of fetch only implement json().
|
|
212
|
+
return typeof res.text === 'function' ? res.text() : JSON.stringify(await res.json());
|
|
213
|
+
});
|
|
214
|
+
// Parsed per caller: callers sharing one response each get their own objects.
|
|
215
|
+
let json;
|
|
216
|
+
try {
|
|
217
|
+
json = JSON.parse(text);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
throw new types_1.ShopifyError('Shopify Storefront API returned a response that is not JSON');
|
|
159
221
|
}
|
|
160
|
-
const json = (await res.json());
|
|
161
222
|
if (json.errors && json.errors.length > 0) {
|
|
162
223
|
throw new types_1.ShopifyError(`GraphQL error: ${json.errors.map((e) => e.message).join('; ')}`);
|
|
163
224
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;AAaA,kCAGC;AAGD,wCAEC;AAED,0CAEC;AAID,8BASC;AAeD,8BAGC;AAED,oCAEC;AAgHD,gDASC;AAaD,0BAoDC;AAGD,gDAOC;AAhQD,mCAAiF;AACjF,6CAAoD;AACpD,iDAAoE;AASpE,MAAM,KAAK,GAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAErF,SAAgB,WAAW,CAAC,IAAmE;IAC7F,IAAI,IAAI,CAAC,WAAW;QAAE,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IAC3D,IAAI,IAAI,CAAC,YAAY;QAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;AAChE,CAAC;AAED,0CAA0C;AAC1C,SAAgB,cAAc;IAC5B,OAAO,KAAK,CAAC,WAAW,CAAC;AAC3B,CAAC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M,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IAEH,8EAA8E;IAC9E,IAAI,IAAwB,CAAC;IAC7B,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAuB,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,oBAAY,CAAC,6DAA6D,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,oBAAY,CACpB,kBAAkB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACjE,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,oBAAY,CAAC,sCAAsC,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC;AAED,gEAAgE;AAChE,SAAgB,kBAAkB,CAAC,KAAa,EAAE,MAAsC;IACtF,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,oBAAY,CACpB,GAAG,KAAK,YAAY,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAC7D,MAAM,CACP,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAOV,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAcjB,eAAO,MAAM,WAAW,EAAE,qBAsCzB,CAAC"}
|
package/dist/collections.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.collections = void 0;
|
|
4
4
|
const client_1 = require("./client");
|
|
5
5
|
const products_1 = require("./products");
|
|
6
|
+
const productStore_1 = require("./productStore");
|
|
6
7
|
const queries_1 = require("./queries");
|
|
7
8
|
exports.collections = {
|
|
8
9
|
async list(opts) {
|
|
@@ -13,11 +14,11 @@ exports.collections = {
|
|
|
13
14
|
query: opts === null || opts === void 0 ? void 0 : opts.query,
|
|
14
15
|
sortKey: opts === null || opts === void 0 ? void 0 : opts.sortKey,
|
|
15
16
|
reverse: (_b = opts === null || opts === void 0 ? void 0 : opts.reverse) !== null && _b !== void 0 ? _b : false,
|
|
16
|
-
});
|
|
17
|
+
}, { imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
17
18
|
return data.collections;
|
|
18
19
|
},
|
|
19
|
-
async byHandle(handle) {
|
|
20
|
-
const data = await (0, client_1.request)(queries_1.COLLECTION_BY_HANDLE_QUERY, { handle });
|
|
20
|
+
async byHandle(handle, opts) {
|
|
21
|
+
const data = await (0, client_1.request)(queries_1.COLLECTION_BY_HANDLE_QUERY, { handle }, { imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
21
22
|
return data.collection;
|
|
22
23
|
},
|
|
23
24
|
async products(handle, opts) {
|
|
@@ -29,12 +30,14 @@ exports.collections = {
|
|
|
29
30
|
sortKey: opts === null || opts === void 0 ? void 0 : opts.sortKey,
|
|
30
31
|
reverse: (_b = opts === null || opts === void 0 ? void 0 : opts.reverse) !== null && _b !== void 0 ? _b : false,
|
|
31
32
|
filters: opts === null || opts === void 0 ? void 0 : opts.filters,
|
|
32
|
-
});
|
|
33
|
+
}, { fresh: opts === null || opts === void 0 ? void 0 : opts.fresh, imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
33
34
|
if (!data.collection) {
|
|
34
35
|
return { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false, startCursor: null, endCursor: null }, filters: [] };
|
|
35
36
|
}
|
|
37
|
+
const nodes = data.collection.products.nodes.map(products_1.normalizeProduct);
|
|
38
|
+
(0, productStore_1.rememberProducts)(nodes, 'base');
|
|
36
39
|
return {
|
|
37
|
-
nodes
|
|
40
|
+
nodes,
|
|
38
41
|
pageInfo: data.collection.products.pageInfo,
|
|
39
42
|
filters: (_c = data.collection.products.filters) !== null && _c !== void 0 ? _c : [],
|
|
40
43
|
collection: { handle: data.collection.handle, title: data.collection.title },
|
package/dist/collections.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,yCAA8C;AAC9C,uCAImB;
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,yCAA8C;AAC9C,iDAAkD;AAClD,uCAImB;AAwBN,QAAA,WAAW,GAA0B;IAChD,KAAK,CAAC,IAAI,CAAC,IAAkB;;QAC3B,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAiB,gCAAsB,EAAE;YACjE,KAAK,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,EAAE;YACxB,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK;YAClB,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK;YAClB,OAAO,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO;YACtB,OAAO,EAAE,MAAA,IAAI,aAAJ,IAAI,u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AAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAClI,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,2BAAgB,CAAC,CAAC;QACnE,IAAA,+BAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO;YACL,KAAK;YACL,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ;YAC3C,OAAO,EAAE,MAAA,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,mCAAI,EAAE;YAC/C,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;SAC7E,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/customer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../src/customer.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAOV,kBAAkB,
|
|
1
|
+
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../src/customer.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAOV,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAmDjB,eAAO,MAAM,QAAQ,EAAE,kBA0FtB,CAAC"}
|
package/dist/customer.js
CHANGED
|
@@ -105,7 +105,7 @@ exports.customer = {
|
|
|
105
105
|
accessToken,
|
|
106
106
|
first: (_a = opts === null || opts === void 0 ? void 0 : opts.first) !== null && _a !== void 0 ? _a : 20,
|
|
107
107
|
after: opts === null || opts === void 0 ? void 0 : opts.after,
|
|
108
|
-
});
|
|
108
|
+
}, { imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
109
109
|
if (!data.customer) {
|
|
110
110
|
return { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false, startCursor: null, endCursor: null } };
|
|
111
111
|
}
|
|
@@ -114,10 +114,10 @@ exports.customer = {
|
|
|
114
114
|
pageInfo: data.customer.orders.pageInfo,
|
|
115
115
|
};
|
|
116
116
|
},
|
|
117
|
-
async orderById(accessToken, orderId) {
|
|
117
|
+
async orderById(accessToken, orderId, opts) {
|
|
118
118
|
var _a;
|
|
119
119
|
// Storefront API does not expose an order-by-id query; fetch list and filter.
|
|
120
|
-
const list = await this.orders(accessToken, { first: 250 });
|
|
120
|
+
const list = await this.orders(accessToken, { first: 250, imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
121
121
|
return (_a = list.nodes.find((o) => o.id === orderId)) !== null && _a !== void 0 ? _a : null;
|
|
122
122
|
},
|
|
123
123
|
};
|
package/dist/customer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../src/customer.ts"],"names":[],"mappings":";;;AAAA,qCAAuD;AACvD,uCAQmB;
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../src/customer.ts"],"names":[],"mappings":";;;AAAA,qCAAuD;AACvD,uCAQmB;AAkCnB,SAAS,cAAc,CAAC,CAAM;;IAC5B,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,iBAAiB,EAAE,MAAA,CAAC,CAAC,iBAAiB,mCAAI,IAAI;QAC9C,eAAe,EAAE,MAAA,CAAC,CAAC,eAAe,mCAAI,IAAI;QAC1C,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,YAAY,EAAE,CAAC,CAAC,YAAY;QAC5B,KAAK,EAAE,MAAA,CAAC,CAAC,KAAK,mCAAI,IAAI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AAI,EAAE;YACxB,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK;SACnB,EAAE,EAAE,cAAc,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;QACrH,CAAC;QACD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC;YACrD,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ;SACxC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,WAAmB,EAAE,OAAe,EAAE,IAAmB;;QACvE,8EAA8E;QAC9E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,EAAE,CAAC,CAAC;QAClG,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,mCAAI,IAAI,CAAC;IAC1D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device storage — WEB build (the editor preview, browsers, tests): `localStorage`, which is
|
|
3
|
+
* synchronous like MMKV. See `deviceStoreCore.ts`; the native build is `deviceStore.native.ts`.
|
|
4
|
+
*/
|
|
5
|
+
import { type DeviceStore } from './deviceStoreCore';
|
|
6
|
+
export declare function deviceStore(): DeviceStore;
|
|
7
|
+
/** Tests only: swap the backend (null re-opens the default on next use). */
|
|
8
|
+
export declare function setDeviceStore(next: DeviceStore | null): void;
|
|
9
|
+
//# sourceMappingURL=deviceStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStore.d.ts","sourceRoot":"","sources":["../src/deviceStore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsDlE,wBAAgB,WAAW,IAAI,WAAW,CAGzC;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAE7D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deviceStore = deviceStore;
|
|
4
|
+
exports.setDeviceStore = setDeviceStore;
|
|
5
|
+
/**
|
|
6
|
+
* Device storage — WEB build (the editor preview, browsers, tests): `localStorage`, which is
|
|
7
|
+
* synchronous like MMKV. See `deviceStoreCore.ts`; the native build is `deviceStore.native.ts`.
|
|
8
|
+
*/
|
|
9
|
+
const deviceStoreCore_1 = require("./deviceStoreCore");
|
|
10
|
+
const PREFIX = 'tiledev.sdk-shopify:';
|
|
11
|
+
function openLocalStorage() {
|
|
12
|
+
try {
|
|
13
|
+
const ls = globalThis.localStorage;
|
|
14
|
+
if (!ls)
|
|
15
|
+
return null;
|
|
16
|
+
// Private modes and blocked storage throw on write, not on access.
|
|
17
|
+
ls.setItem(`${PREFIX}probe`, '1');
|
|
18
|
+
ls.removeItem(`${PREFIX}probe`);
|
|
19
|
+
return {
|
|
20
|
+
kind: 'localStorage',
|
|
21
|
+
get: (key) => {
|
|
22
|
+
var _a;
|
|
23
|
+
try {
|
|
24
|
+
return (_a = ls.getItem(PREFIX + key)) !== null && _a !== void 0 ? _a : undefined;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
set: (key, value) => {
|
|
31
|
+
try {
|
|
32
|
+
ls.setItem(PREFIX + key, value);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Quota exceeded: the entry is simply not kept. Caps upstream keep this rare.
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
remove: (key) => {
|
|
39
|
+
try {
|
|
40
|
+
ls.removeItem(PREFIX + key);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* ignore */
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
keys: () => {
|
|
47
|
+
const out = [];
|
|
48
|
+
try {
|
|
49
|
+
for (let i = 0; i < ls.length; i++) {
|
|
50
|
+
const k = ls.key(i);
|
|
51
|
+
if (k && k.startsWith(PREFIX))
|
|
52
|
+
out.push(k.slice(PREFIX.length));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
/* ignore */
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let store = null;
|
|
67
|
+
function deviceStore() {
|
|
68
|
+
var _a;
|
|
69
|
+
if (!store)
|
|
70
|
+
store = (_a = openLocalStorage()) !== null && _a !== void 0 ? _a : (0, deviceStoreCore_1.memoryStore)();
|
|
71
|
+
return store;
|
|
72
|
+
}
|
|
73
|
+
/** Tests only: swap the backend (null re-opens the default on next use). */
|
|
74
|
+
function setDeviceStore(next) {
|
|
75
|
+
store = next;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=deviceStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStore.js","sourceRoot":"","sources":["../src/deviceStore.ts"],"names":[],"mappings":";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BACnC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;wBACpB,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;4BAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;oBAClE,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,IAAI,KAAK,GAAuB,IAAI,CAAC;AAErC,SAAgB,WAAW;;IACzB,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,MAAA,gBAAgB,EAAE,mCAAI,IAAA,6BAAW,GAAE,CAAC;IACxD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,4EAA4E;AAC5E,SAAgB,cAAc,CAAC,IAAwB;IACrD,KAAK,GAAG,IAAI,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device storage — NATIVE build (iOS/Android): MMKV 3, synchronous and memory-mapped, so reading a
|
|
3
|
+
* product by key costs microseconds inside a render. See `deviceStoreCore.ts`.
|
|
4
|
+
*
|
|
5
|
+
* `react-native-mmkv` is an optional peer: required lazily inside `try`, which Expo's Metro config
|
|
6
|
+
* (`allowOptionalDependencies: true`) bundles as optional. An app without it in its binary (Expo
|
|
7
|
+
* Go, or a build from before it was added) gets the memory fallback instead of a crash. The app
|
|
8
|
+
* lists it in its own dependencies only so the native module is compiled in.
|
|
9
|
+
*/
|
|
10
|
+
import { type DeviceStore } from './deviceStoreCore';
|
|
11
|
+
export declare function deviceStore(): DeviceStore;
|
|
12
|
+
/** Tests only: swap the backend (null re-opens the default on next use). */
|
|
13
|
+
export declare function setDeviceStore(next: DeviceStore | null): void;
|
|
14
|
+
//# sourceMappingURL=deviceStore.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStore.native.d.ts","sourceRoot":"","sources":["../src/deviceStore.native.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAiClE,wBAAgB,WAAW,IAAI,WAAW,CAGzC;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAE7D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deviceStore = deviceStore;
|
|
4
|
+
exports.setDeviceStore = setDeviceStore;
|
|
5
|
+
/**
|
|
6
|
+
* Device storage — NATIVE build (iOS/Android): MMKV 3, synchronous and memory-mapped, so reading a
|
|
7
|
+
* product by key costs microseconds inside a render. See `deviceStoreCore.ts`.
|
|
8
|
+
*
|
|
9
|
+
* `react-native-mmkv` is an optional peer: required lazily inside `try`, which Expo's Metro config
|
|
10
|
+
* (`allowOptionalDependencies: true`) bundles as optional. An app without it in its binary (Expo
|
|
11
|
+
* Go, or a build from before it was added) gets the memory fallback instead of a crash. The app
|
|
12
|
+
* lists it in its own dependencies only so the native module is compiled in.
|
|
13
|
+
*/
|
|
14
|
+
const deviceStoreCore_1 = require("./deviceStoreCore");
|
|
15
|
+
/** Its own instance id, so the SDK's keys never mix with an app's own MMKV data. */
|
|
16
|
+
const INSTANCE_ID = 'tiledev.sdk-shopify';
|
|
17
|
+
function openMmkv() {
|
|
18
|
+
try {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
20
|
+
const mod = require('react-native-mmkv');
|
|
21
|
+
if (!(mod === null || mod === void 0 ? void 0 : mod.MMKV))
|
|
22
|
+
return null;
|
|
23
|
+
const mmkv = new mod.MMKV({ id: INSTANCE_ID });
|
|
24
|
+
return {
|
|
25
|
+
kind: 'mmkv',
|
|
26
|
+
get: (key) => mmkv.getString(key),
|
|
27
|
+
set: (key, value) => mmkv.set(key, value),
|
|
28
|
+
remove: (key) => mmkv.delete(key),
|
|
29
|
+
keys: () => mmkv.getAllKeys(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let store = null;
|
|
37
|
+
function deviceStore() {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!store)
|
|
40
|
+
store = (_a = openMmkv()) !== null && _a !== void 0 ? _a : (0, deviceStoreCore_1.memoryStore)();
|
|
41
|
+
return store;
|
|
42
|
+
}
|
|
43
|
+
/** Tests only: swap the backend (null re-opens the default on next use). */
|
|
44
|
+
function setDeviceStore(next) {
|
|
45
|
+
store = next;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=deviceStore.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStore.native.js","sourceRoot":"","sources":["../src/deviceStore.native.ts"],"names":[],"mappings":";;AA0CA,kCAGC;AAGD,wCAEC;AAlDD;;;;;;;;GAQG;AACH,uDAAkE;AAUlE,oFAAoF;AACpF,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,SAAS,QAAQ;IACf,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,mBAAmB,CAA4D,CAAC;QACpG,IAAI,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAA;YAAE,OAAO,IAAI,CAAC;QAC5B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/C,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;YACjC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;YACzC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACjC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE;SAC9B,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,IAAI,KAAK,GAAuB,IAAI,CAAC;AAErC,SAAgB,WAAW;;IACzB,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,MAAA,QAAQ,EAAE,mCAAI,IAAA,6BAAW,GAAE,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,4EAA4E;AAC5E,SAAgB,cAAc,CAAC,IAAwB;IACrD,KAAK,GAAG,IAAI,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's own device storage: synchronous, so a hook can read it during render and a product page
|
|
3
|
+
* can open with data on its first frame.
|
|
4
|
+
*
|
|
5
|
+
* Two builds pick the backend. `deviceStore.native.ts` (iOS/Android) uses MMKV; `deviceStore.ts`
|
|
6
|
+
* (web, the editor preview, tests) uses `localStorage`. Metro resolves the right file per platform,
|
|
7
|
+
* so a web bundle never sees MMKV. Either falls back to memory when its backend is missing, so the
|
|
8
|
+
* cache only ever gets slower, never breaks the app.
|
|
9
|
+
*
|
|
10
|
+
* Only public catalogue data goes here: no cart, customer, order or wallet data, ever.
|
|
11
|
+
*/
|
|
12
|
+
export interface DeviceStore {
|
|
13
|
+
readonly kind: 'mmkv' | 'localStorage' | 'memory';
|
|
14
|
+
get(key: string): string | undefined;
|
|
15
|
+
set(key: string, value: string): void;
|
|
16
|
+
remove(key: string): void;
|
|
17
|
+
/** Every key this store holds (its own namespace only). */
|
|
18
|
+
keys(): string[];
|
|
19
|
+
}
|
|
20
|
+
/** A store that lives as long as the JS process: the fallback when the device has none. */
|
|
21
|
+
export declare function memoryStore(): DeviceStore;
|
|
22
|
+
/** FNV-1a 32-bit as 8 hex digits: short, stable keys for long inputs. */
|
|
23
|
+
export declare function hashKey(input: string): string;
|
|
24
|
+
//# sourceMappingURL=deviceStoreCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStoreCore.d.ts","sourceRoot":"","sources":["../src/deviceStoreCore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,QAAQ,CAAC;IAClD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACrC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,2DAA2D;IAC3D,IAAI,IAAI,MAAM,EAAE,CAAC;CAClB;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,IAAI,WAAW,CAazC;AAED,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO7C"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The SDK's own device storage: synchronous, so a hook can read it during render and a product page
|
|
4
|
+
* can open with data on its first frame.
|
|
5
|
+
*
|
|
6
|
+
* Two builds pick the backend. `deviceStore.native.ts` (iOS/Android) uses MMKV; `deviceStore.ts`
|
|
7
|
+
* (web, the editor preview, tests) uses `localStorage`. Metro resolves the right file per platform,
|
|
8
|
+
* so a web bundle never sees MMKV. Either falls back to memory when its backend is missing, so the
|
|
9
|
+
* cache only ever gets slower, never breaks the app.
|
|
10
|
+
*
|
|
11
|
+
* Only public catalogue data goes here: no cart, customer, order or wallet data, ever.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.memoryStore = memoryStore;
|
|
15
|
+
exports.hashKey = hashKey;
|
|
16
|
+
/** A store that lives as long as the JS process: the fallback when the device has none. */
|
|
17
|
+
function memoryStore() {
|
|
18
|
+
const map = new Map();
|
|
19
|
+
return {
|
|
20
|
+
kind: 'memory',
|
|
21
|
+
get: (key) => map.get(key),
|
|
22
|
+
set: (key, value) => {
|
|
23
|
+
map.set(key, value);
|
|
24
|
+
},
|
|
25
|
+
remove: (key) => {
|
|
26
|
+
map.delete(key);
|
|
27
|
+
},
|
|
28
|
+
keys: () => Array.from(map.keys()),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** FNV-1a 32-bit as 8 hex digits: short, stable keys for long inputs. */
|
|
32
|
+
function hashKey(input) {
|
|
33
|
+
let h = 0x811c9dc5;
|
|
34
|
+
for (let i = 0; i < input.length; i++) {
|
|
35
|
+
h ^= input.charCodeAt(i);
|
|
36
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
37
|
+
}
|
|
38
|
+
return h.toString(16).padStart(8, '0');
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=deviceStoreCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceStoreCore.js","sourceRoot":"","sources":["../src/deviceStoreCore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAYH,kCAaC;AAGD,0BAOC;AAxBD,2FAA2F;AAC3F,SAAgB,WAAW;IACzB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAClB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;YACd,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;KACnC,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,SAAgB,OAAO,CAAC,KAAa;IACnC,IAAI,CAAC,GAAG,UAAU,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Price filters: the one Shopify facet whose input the app builds itself.
|
|
3
|
+
*
|
|
4
|
+
* Every other facet value arrives with a ready `FilterValue.input` the shopper just picks. A
|
|
5
|
+
* `PRICE_RANGE` facet instead carries one value whose input is the collection's whole range
|
|
6
|
+
* (`{"price":{"min":0,"max":3132.99}}`), and the shopper's own range has to be encoded in that
|
|
7
|
+
* shape to be sent back. These helpers keep that format in one place.
|
|
8
|
+
*/
|
|
9
|
+
import type { Filter } from './types';
|
|
10
|
+
export interface PriceRange {
|
|
11
|
+
min: number;
|
|
12
|
+
max: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The `{ min, max }` a price input encodes, or null when the input isn't a price filter. Either
|
|
16
|
+
* bound may be missing: Shopify reads an absent `min` as 0 and an absent `max` as no ceiling.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parsePriceFilterInput(input: string): {
|
|
19
|
+
min?: number;
|
|
20
|
+
max?: number;
|
|
21
|
+
} | null;
|
|
22
|
+
/** True for a `FilterValue.input` (or a built one) that is a price filter. */
|
|
23
|
+
export declare function isPriceFilterInput(input: string): boolean;
|
|
24
|
+
/** The bounds of a `PRICE_RANGE` facet, from its one value. Null for any other facet. */
|
|
25
|
+
export declare function priceRange(filter: Filter): PriceRange | null;
|
|
26
|
+
/**
|
|
27
|
+
* The input for a range the shopper chose, to pass to `setFilters` with the other inputs. Null
|
|
28
|
+
* when it wouldn't narrow anything: no bounds, or bounds covering the whole `range`. Bounds given
|
|
29
|
+
* the wrong way round are swapped rather than sent as an empty range.
|
|
30
|
+
*/
|
|
31
|
+
export declare function priceFilterInput(min: number | null | undefined, max: number | null | undefined, range?: PriceRange | null): string | null;
|
|
32
|
+
//# sourceMappingURL=filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../src/filters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAOD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQ1F;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAK5D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI,GACxB,MAAM,GAAG,IAAI,CAcf"}
|
package/dist/filters.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePriceFilterInput = parsePriceFilterInput;
|
|
4
|
+
exports.isPriceFilterInput = isPriceFilterInput;
|
|
5
|
+
exports.priceRange = priceRange;
|
|
6
|
+
exports.priceFilterInput = priceFilterInput;
|
|
7
|
+
function finite(value) {
|
|
8
|
+
const n = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
|
|
9
|
+
return typeof n === 'number' && Number.isFinite(n) ? n : undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The `{ min, max }` a price input encodes, or null when the input isn't a price filter. Either
|
|
13
|
+
* bound may be missing: Shopify reads an absent `min` as 0 and an absent `max` as no ceiling.
|
|
14
|
+
*/
|
|
15
|
+
function parsePriceFilterInput(input) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(input);
|
|
18
|
+
if (!parsed || typeof parsed !== 'object' || !parsed.price || typeof parsed.price !== 'object')
|
|
19
|
+
return null;
|
|
20
|
+
return { min: finite(parsed.price.min), max: finite(parsed.price.max) };
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** True for a `FilterValue.input` (or a built one) that is a price filter. */
|
|
27
|
+
function isPriceFilterInput(input) {
|
|
28
|
+
return parsePriceFilterInput(input) !== null;
|
|
29
|
+
}
|
|
30
|
+
/** The bounds of a `PRICE_RANGE` facet, from its one value. Null for any other facet. */
|
|
31
|
+
function priceRange(filter) {
|
|
32
|
+
var _a;
|
|
33
|
+
if (filter.type !== 'PRICE_RANGE')
|
|
34
|
+
return null;
|
|
35
|
+
const bounds = filter.values.length ? parsePriceFilterInput(filter.values[0].input) : null;
|
|
36
|
+
if (!bounds || bounds.max === undefined)
|
|
37
|
+
return null;
|
|
38
|
+
return { min: (_a = bounds.min) !== null && _a !== void 0 ? _a : 0, max: bounds.max };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The input for a range the shopper chose, to pass to `setFilters` with the other inputs. Null
|
|
42
|
+
* when it wouldn't narrow anything: no bounds, or bounds covering the whole `range`. Bounds given
|
|
43
|
+
* the wrong way round are swapped rather than sent as an empty range.
|
|
44
|
+
*/
|
|
45
|
+
function priceFilterInput(min, max, range) {
|
|
46
|
+
let lo = finite(min);
|
|
47
|
+
let hi = finite(max);
|
|
48
|
+
if (lo !== undefined && lo < 0)
|
|
49
|
+
lo = 0;
|
|
50
|
+
if (lo !== undefined && hi !== undefined && lo > hi)
|
|
51
|
+
[lo, hi] = [hi, lo];
|
|
52
|
+
if (range) {
|
|
53
|
+
if (lo !== undefined && lo <= range.min)
|
|
54
|
+
lo = undefined;
|
|
55
|
+
if (hi !== undefined && hi >= range.max)
|
|
56
|
+
hi = undefined;
|
|
57
|
+
}
|
|
58
|
+
if (lo === undefined && hi === undefined)
|
|
59
|
+
return null;
|
|
60
|
+
const price = {};
|
|
61
|
+
if (lo !== undefined)
|
|
62
|
+
price.min = lo;
|
|
63
|
+
if (hi !== undefined)
|
|
64
|
+
price.max = hi;
|
|
65
|
+
return JSON.stringify({ price });
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../src/filters.ts"],"names":[],"mappings":";;AAwBA,sDAQC;AAGD,gDAEC;AAGD,gCAKC;AAOD,4CAkBC;AAvD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