@tiledev/sdk-shopify 0.5.0 → 0.7.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 +114 -1
- 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 +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -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 +3 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +9 -1
- package/dist/react/index.js.map +1 -1
- 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/README.md
CHANGED
|
@@ -107,12 +107,125 @@ Then read from the context:
|
|
|
107
107
|
```tsx
|
|
108
108
|
const { ready, error, cart, wishlist, customer, checkout } = useShopify();
|
|
109
109
|
const { addLine, itemCount, cart } = useCart();
|
|
110
|
-
const { items, count, toggle, has } = useWishlist();
|
|
110
|
+
const { items, ids, count, toggle, has } = useWishlist(); // ids: product ids, e.g. a grid's favourites
|
|
111
111
|
const { loggedIn, login, logout } = useCustomer();
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
`react` is an **optional** peer dep — install it only if you use the `/react` subpath.
|
|
115
115
|
|
|
116
|
+
### Collection feed with filters
|
|
117
|
+
|
|
118
|
+
`useCollectionProducts` pages one collection by cursor and holds the shopper's filter selection:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
const feed = useCollectionProducts({ handle: 'new-arrivals', pageSize: 12 });
|
|
122
|
+
|
|
123
|
+
feed.products; // appended page by page; feed.loadMore() when the list nears its end
|
|
124
|
+
feed.availableFilters; // Shopify's facets for this collection, values carry an `input` string
|
|
125
|
+
feed.setFilters(inputs); // the `input` strings the shopper picked; the hook parses and refetches
|
|
126
|
+
feed.selectedFilters; // those inputs, for the sheet's checkboxes
|
|
127
|
+
feed.filterActive; // at least one selected
|
|
128
|
+
feed.clearFilters();
|
|
129
|
+
feed.refresh(); // pull-to-refresh (retry is the same call, for an error state)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- Pass `filters` for anything the app always applies (e.g. in stock only). The shopper's selection
|
|
133
|
+
goes on top.
|
|
134
|
+
- A selection belongs to its collection: a new `handle` starts with none, and its first read never
|
|
135
|
+
carries the old filters.
|
|
136
|
+
- An input that isn't a Shopify filter (unparseable JSON) is dropped rather than sent.
|
|
137
|
+
- **Price** is the one facet whose input the app builds. `priceRange(facet)` reads a
|
|
138
|
+
`PRICE_RANGE` facet's bounds, and `priceFilterInput(min, max, range)` encodes the shopper's range
|
|
139
|
+
(`{"price":{"min":20,"max":100}}`), or returns null when it wouldn't narrow anything. Pass it to
|
|
140
|
+
`setFilters` with the other inputs; `parsePriceFilterInput` reads one back to pre-fill fields.
|
|
141
|
+
- Scrolling, navigation and the sheet's open state stay in the app; the hook only knows Shopify.
|
|
142
|
+
|
|
143
|
+
### One network call per identical read
|
|
144
|
+
|
|
145
|
+
Every Storefront read goes through one `request()`, which now shares work:
|
|
146
|
+
|
|
147
|
+
- **In flight:** identical queries fired together share one call. Six grids on the same collection
|
|
148
|
+
make one request, not six. This covers every query, including cart and customer ones.
|
|
149
|
+
Mutations are never shared.
|
|
150
|
+
- **Recent answers:** catalogue reads are reused from memory for a short time (`DEFAULT_CACHE_TTL_MS`):
|
|
151
|
+
shop info 30 min, collections and blogs 10 min, recommendations 5 min, collection pages, products
|
|
152
|
+
and wishlist items 1 min, search 30 s. Cart, customer, orders and variant stock are never reused.
|
|
153
|
+
- Each caller gets its own parsed copy, so mutating a result can't change another caller's.
|
|
154
|
+
Failed calls and GraphQL errors are never kept.
|
|
155
|
+
- The key includes the store, token, market (`@inContext`), metafields and variables, so markets
|
|
156
|
+
and stores never mix. Memory only: nothing is persisted, and `init` starts it empty.
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
shopify.init({ ...config, cache: { ttl: { CollectionProducts: 0 }, maxEntries: 50 } }); // tune
|
|
160
|
+
shopify.init({ ...config, cache: false }); // no reuse; in-flight sharing stays
|
|
161
|
+
shopify.collections.products(handle, { fresh: true }); // skip a recent answer
|
|
162
|
+
clearRequestCache(); // forget everything
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`useCollectionProducts`' `refresh()` and `retry()` read fresh; other grids on the same collection
|
|
166
|
+
keep what they have.
|
|
167
|
+
|
|
168
|
+
### Image transforms
|
|
169
|
+
|
|
170
|
+
Every call that returns images takes an optional `imageTransform`, Shopify's server-side
|
|
171
|
+
`Image.url(transform:)`: the CDN resizes, crops and converts, so each screen downloads the size it
|
|
172
|
+
shows. **Omitted, URLs are the originals, exactly as before.**
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
shopify.collections.products(handle, { first: 12, imageTransform: { maxWidth: 330, scale: 2, preferredContentType: 'WEBP' } });
|
|
176
|
+
shopify.products.byHandle(handle, { imageTransform: { maxWidth: 1080 } });
|
|
177
|
+
useCollectionProducts({ handle, imageTransform: { maxWidth: 330, scale: 2 } });
|
|
178
|
+
useSearch(term, { imageTransform: { maxWidth: 200, scale: 2 } });
|
|
179
|
+
useProduct(handle, { imageTransform: { maxWidth: 1080 } });
|
|
180
|
+
// e.g. …/photo_330x@2x.jpg.webp, …/photo_100x100_crop_center.jpg
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- Fields: `maxWidth`, `maxHeight`, `crop` (`CENTER` | `TOP` | `BOTTOM` | `LEFT` | `RIGHT`),
|
|
184
|
+
`scale` (1–3), `preferredContentType` (`WEBP` | `JPG` | `PNG`). Never upscales past the original.
|
|
185
|
+
`width`/`height` on an image stay the original's.
|
|
186
|
+
- Applies to every image in the answer: product images, featured image, media, variant images,
|
|
187
|
+
collection images, cart line images, order line images, article images.
|
|
188
|
+
- **Provider-run reads** (the cart `ShopifyProvider` keeps, the wishlist it rehydrates) take a default
|
|
189
|
+
from the config: `imageTransforms: { cart: { maxWidth: 160, scale: 2 }, wishlist: … }`. A
|
|
190
|
+
transform passed to a call directly wins.
|
|
191
|
+
- Each transform is its own cache entry. A product page's first-render `preview` uses the image the
|
|
192
|
+
grid fetched, so the image on screen is already in the image cache.
|
|
193
|
+
|
|
194
|
+
### Cache-first pages: `useProduct`, `useCollectionProducts`, `useSearch`
|
|
195
|
+
|
|
196
|
+
Each hook renders what this device already knows **on its first render**, then reads the network in
|
|
197
|
+
the background and updates in place (`refreshing` is true meanwhile; no spinner needed). A copy
|
|
198
|
+
younger than a minute (`REVALIDATE_AFTER_MS`) isn't re-read. `refresh()` always goes to the network.
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
// Product page: opens with title, image and price from whichever grid or search showed it.
|
|
202
|
+
const { preview, product, level, loading, refreshing, notFound, refresh } = useProduct(handle);
|
|
203
|
+
// preview: the base keys, render now. product: full (variants, media), render the picker when set.
|
|
204
|
+
|
|
205
|
+
// Listing page / search page: the last first page paints immediately, even after a cold start.
|
|
206
|
+
const feed = useCollectionProducts({ handle, pageSize: 12 });
|
|
207
|
+
const results = useSearch(term, { debounceMs: 300 }); // results.query is the debounced term
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- **Every product read records its base keys** (`PRODUCT_BASE_KEYS`: `id`, `handle`, `title`,
|
|
211
|
+
`featuredImage`, `priceRange`, `compareAtPriceRange`): collections, search, recommendations, lists,
|
|
212
|
+
`byIds`, the wishlist. `byHandle`/`byId` record the full product. So a product tapped anywhere
|
|
213
|
+
opens instantly, and a product page seen before opens complete.
|
|
214
|
+
- **Kept on the device** across cold starts, one small key per product, read only when something
|
|
215
|
+
asks (nothing is loaded in bulk at launch). Caps: 2,500 base entries, 30 full products, 20 first
|
|
216
|
+
pages; anything older than 7 days is dropped. Keys carry a schema version and the store, market,
|
|
217
|
+
API version and metafields, so nothing mismatched is ever shown. Catalogue data only: never cart,
|
|
218
|
+
customer, orders or wallet.
|
|
219
|
+
- **Storage:** on iOS/Android, **MMKV 3** (synchronous, read in microseconds inside a render). List
|
|
220
|
+
it in the app so its native code is compiled in: `npm i react-native-mmkv@^3` (needs the New
|
|
221
|
+
Architecture, on by default from RN 0.76 / Expo 52). Without it in the binary the SDK keeps
|
|
222
|
+
everything in memory only and nothing breaks. On web and the editor preview: `localStorage`.
|
|
223
|
+
- `peekProduct(handleOrId)` reads the store directly (e.g. to prefetch on `onPressIn`);
|
|
224
|
+
`forgetProduct(id)` drops one (e.g. after `cart:outOfStock`); `clearProductStore()` drops all.
|
|
225
|
+
- `cache: false` in the config turns all of this off, along with the request cache.
|
|
226
|
+
- The provider sets the config on its first render, so these reads start at once instead of waiting
|
|
227
|
+
for its own startup (cart, wishlist, customer).
|
|
228
|
+
|
|
116
229
|
## Alerts & Toasts
|
|
117
230
|
|
|
118
231
|
The editor's Settings panel configures the copy for 13 shopper-facing alerts. The
|
package/dist/blogs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blogs.d.ts","sourceRoot":"","sources":["../src/blogs.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAMV,eAAe,
|
|
1
|
+
{"version":3,"file":"blogs.d.ts","sourceRoot":"","sources":["../src/blogs.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAMV,eAAe,EAEhB,MAAM,SAAS,CAAC;AAsCjB,eAAO,MAAM,KAAK,EAAE,eA0CnB,CAAC"}
|
package/dist/blogs.js
CHANGED
|
@@ -50,7 +50,7 @@ exports.blogs = {
|
|
|
50
50
|
after: opts === null || opts === void 0 ? void 0 : opts.after,
|
|
51
51
|
sortKey: opts === null || opts === void 0 ? void 0 : opts.sortKey,
|
|
52
52
|
reverse: (_b = opts === null || opts === void 0 ? void 0 : opts.reverse) !== null && _b !== void 0 ? _b : false,
|
|
53
|
-
});
|
|
53
|
+
}, { imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
54
54
|
if (!data.blog) {
|
|
55
55
|
return { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false, startCursor: null, endCursor: null } };
|
|
56
56
|
}
|
|
@@ -59,11 +59,11 @@ exports.blogs = {
|
|
|
59
59
|
pageInfo: data.blog.articles.pageInfo,
|
|
60
60
|
};
|
|
61
61
|
},
|
|
62
|
-
async articleByHandle(blogHandle, articleHandle) {
|
|
62
|
+
async articleByHandle(blogHandle, articleHandle, opts) {
|
|
63
63
|
const data = await (0, client_1.request)(queries_1.BLOG_ARTICLE_BY_HANDLE_QUERY, {
|
|
64
64
|
blogHandle,
|
|
65
65
|
articleHandle,
|
|
66
|
-
});
|
|
66
|
+
}, { imageTransform: opts === null || opts === void 0 ? void 0 : opts.imageTransform });
|
|
67
67
|
if (!data.blog || !data.blog.articleByHandle)
|
|
68
68
|
return null;
|
|
69
69
|
return normalizeArticle(data.blog.articleByHandle);
|
package/dist/blogs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blogs.js","sourceRoot":"","sources":["../src/blogs.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,uCAKmB;
|
|
1
|
+
{"version":3,"file":"blogs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GAAG,CAAC,gBAAgB,CAAC;YACrD,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ;SACtC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,UAAkB,EAAE,aAAqB,EAAE,IAAmB;QAClF,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAiB,sCAA4B,EAAE;YACvE,UAAU;YACV,aAAa;SACd,EAAE,EAAE,cAAc,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe;YAAE,OAAO,IAAI,CAAC;QAC1D,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACrD,CAAC;CACF,CAAC"}
|
package/dist/cart.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../src/cart.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,IAAI,EAEJ,gBAAgB,EAEhB,cAAc,
|
|
1
|
+
{"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../src/cart.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,IAAI,EAEJ,gBAAgB,EAEhB,cAAc,EAIf,MAAM,SAAS,CAAC;AA6CjB;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,gBAAgB,EAAE,CAS7D;AAOD,eAAO,MAAM,IAAI,EAAE,cAyGlB,CAAC"}
|
package/dist/cart.js
CHANGED
|
@@ -56,8 +56,13 @@ function toLineSnapshot(cart) {
|
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
+
/** A cart's line-image transform: the call's own, else the provider-wide `imageTransforms.cart`. */
|
|
60
|
+
function cartImages(opts) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return { imageTransform: (_a = opts === null || opts === void 0 ? void 0 : opts.imageTransform) !== null && _a !== void 0 ? _a : (_b = (0, client_1.getConfig)().imageTransforms) === null || _b === void 0 ? void 0 : _b.cart };
|
|
63
|
+
}
|
|
59
64
|
exports.cart = {
|
|
60
|
-
async create(input) {
|
|
65
|
+
async create(input, opts) {
|
|
61
66
|
/**
|
|
62
67
|
* Built key by key rather than spreading `input`, so an unknown field cannot reach Shopify and
|
|
63
68
|
* fail the whole mutation — but every key `CartInput` accepts and a caller can set belongs
|
|
@@ -72,38 +77,38 @@ exports.cart = {
|
|
|
72
77
|
attributes: input === null || input === void 0 ? void 0 : input.attributes,
|
|
73
78
|
buyerIdentity: input === null || input === void 0 ? void 0 : input.buyerIdentity,
|
|
74
79
|
};
|
|
75
|
-
const data = await (0, client_1.request)(queries_1.CART_CREATE_MUTATION, { input: payload });
|
|
80
|
+
const data = await (0, client_1.request)(queries_1.CART_CREATE_MUTATION, { input: payload }, cartImages(opts));
|
|
76
81
|
(0, client_1.assertNoUserErrors)('cartCreate', data.cartCreate.userErrors);
|
|
77
82
|
return normalize(data.cartCreate.cart);
|
|
78
83
|
},
|
|
79
|
-
async get(cartId) {
|
|
80
|
-
const data = await (0, client_1.request)(queries_1.CART_GET_QUERY, { id: cartId });
|
|
84
|
+
async get(cartId, opts) {
|
|
85
|
+
const data = await (0, client_1.request)(queries_1.CART_GET_QUERY, { id: cartId }, cartImages(opts));
|
|
81
86
|
return data.cart ? normalize(data.cart) : null;
|
|
82
87
|
},
|
|
83
|
-
async addLines(cartId, lines) {
|
|
84
|
-
const data = await (0, client_1.request)(queries_1.CART_LINES_ADD_MUTATION, { cartId, lines });
|
|
88
|
+
async addLines(cartId, lines, opts) {
|
|
89
|
+
const data = await (0, client_1.request)(queries_1.CART_LINES_ADD_MUTATION, { cartId, lines }, cartImages(opts));
|
|
85
90
|
(0, client_1.assertNoUserErrors)('cartLinesAdd', data.cartLinesAdd.userErrors);
|
|
86
91
|
return normalize(data.cartLinesAdd.cart);
|
|
87
92
|
},
|
|
88
|
-
async updateLines(cartId, lines) {
|
|
89
|
-
const data = await (0, client_1.request)(queries_1.CART_LINES_UPDATE_MUTATION, { cartId, lines });
|
|
93
|
+
async updateLines(cartId, lines, opts) {
|
|
94
|
+
const data = await (0, client_1.request)(queries_1.CART_LINES_UPDATE_MUTATION, { cartId, lines }, cartImages(opts));
|
|
90
95
|
(0, client_1.assertNoUserErrors)('cartLinesUpdate', data.cartLinesUpdate.userErrors);
|
|
91
96
|
return normalize(data.cartLinesUpdate.cart);
|
|
92
97
|
},
|
|
93
|
-
async removeLines(cartId, lineIds) {
|
|
94
|
-
const data = await (0, client_1.request)(queries_1.CART_LINES_REMOVE_MUTATION, { cartId, lineIds });
|
|
98
|
+
async removeLines(cartId, lineIds, opts) {
|
|
99
|
+
const data = await (0, client_1.request)(queries_1.CART_LINES_REMOVE_MUTATION, { cartId, lineIds }, cartImages(opts));
|
|
95
100
|
(0, client_1.assertNoUserErrors)('cartLinesRemove', data.cartLinesRemove.userErrors);
|
|
96
101
|
return normalize(data.cartLinesRemove.cart);
|
|
97
102
|
},
|
|
98
|
-
async applyDiscountCodes(cartId, codes) {
|
|
103
|
+
async applyDiscountCodes(cartId, codes, opts) {
|
|
99
104
|
const data = await (0, client_1.request)(queries_1.CART_DISCOUNT_CODES_UPDATE_MUTATION, {
|
|
100
105
|
cartId,
|
|
101
106
|
discountCodes: codes,
|
|
102
|
-
});
|
|
107
|
+
}, cartImages(opts));
|
|
103
108
|
(0, client_1.assertNoUserErrors)('cartDiscountCodesUpdate', data.cartDiscountCodesUpdate.userErrors);
|
|
104
109
|
return normalize(data.cartDiscountCodesUpdate.cart);
|
|
105
110
|
},
|
|
106
|
-
async setBuyerIdentity(cartId, identity) {
|
|
111
|
+
async setBuyerIdentity(cartId, identity, opts) {
|
|
107
112
|
const data = await (0, client_1.request)(queries_1.CART_BUYER_IDENTITY_UPDATE_MUTATION, {
|
|
108
113
|
cartId,
|
|
109
114
|
buyerIdentity: {
|
|
@@ -111,15 +116,15 @@ exports.cart = {
|
|
|
111
116
|
countryCode: identity.countryCode,
|
|
112
117
|
customerAccessToken: identity.customerAccessToken,
|
|
113
118
|
},
|
|
114
|
-
});
|
|
119
|
+
}, cartImages(opts));
|
|
115
120
|
(0, client_1.assertNoUserErrors)('cartBuyerIdentityUpdate', data.cartBuyerIdentityUpdate.userErrors);
|
|
116
121
|
return normalize(data.cartBuyerIdentityUpdate.cart);
|
|
117
122
|
},
|
|
118
|
-
async applyGiftCardCodes(cartId, codes) {
|
|
123
|
+
async applyGiftCardCodes(cartId, codes, opts) {
|
|
119
124
|
const data = await (0, client_1.request)(queries_1.CART_GIFT_CARD_CODES_UPDATE_MUTATION, {
|
|
120
125
|
cartId,
|
|
121
126
|
giftCardCodes: codes,
|
|
122
|
-
});
|
|
127
|
+
}, cartImages(opts));
|
|
123
128
|
(0, client_1.assertNoUserErrors)('cartGiftCardCodesUpdate', data.cartGiftCardCodesUpdate.userErrors);
|
|
124
129
|
return normalize(data.cartGiftCardCodesUpdate.cart);
|
|
125
130
|
},
|
|
@@ -129,25 +134,25 @@ exports.cart = {
|
|
|
129
134
|
* Its own mutation rather than a cart attribute: attributes are key/value metadata for the app's
|
|
130
135
|
* own bookkeeping (Cart Hold's expiry stamp is one), while the note is content the shopper wrote.
|
|
131
136
|
*/
|
|
132
|
-
async updateNote(cartId, note) {
|
|
137
|
+
async updateNote(cartId, note, opts) {
|
|
133
138
|
// `?? ''` is load-bearing: the argument is `String!`, so a null variable fails the whole
|
|
134
139
|
// mutation rather than clearing the note.
|
|
135
|
-
const data = await (0, client_1.request)(queries_1.CART_NOTE_UPDATE_MUTATION, { cartId, note: note !== null && note !== void 0 ? note : '' });
|
|
140
|
+
const data = await (0, client_1.request)(queries_1.CART_NOTE_UPDATE_MUTATION, { cartId, note: note !== null && note !== void 0 ? note : '' }, cartImages(opts));
|
|
136
141
|
(0, client_1.assertNoUserErrors)('cartNoteUpdate', data.cartNoteUpdate.userErrors);
|
|
137
142
|
return normalize(data.cartNoteUpdate.cart);
|
|
138
143
|
},
|
|
139
|
-
async updateAttributes(cartId, attributes) {
|
|
144
|
+
async updateAttributes(cartId, attributes, opts) {
|
|
140
145
|
// Shopify replaces the set wholesale, so this is a write of the final list, not a merge into
|
|
141
146
|
// the existing one. Callers holding a cart should send its current attributes plus theirs.
|
|
142
|
-
const data = await (0, client_1.request)(queries_1.CART_ATTRIBUTES_UPDATE_MUTATION, { cartId, attributes });
|
|
147
|
+
const data = await (0, client_1.request)(queries_1.CART_ATTRIBUTES_UPDATE_MUTATION, { cartId, attributes }, cartImages(opts));
|
|
143
148
|
(0, client_1.assertNoUserErrors)('cartAttributesUpdate', data.cartAttributesUpdate.userErrors);
|
|
144
149
|
return normalize(data.cartAttributesUpdate.cart);
|
|
145
150
|
},
|
|
146
|
-
async removeGiftCardCodes(cartId, appliedGiftCardIds) {
|
|
151
|
+
async removeGiftCardCodes(cartId, appliedGiftCardIds, opts) {
|
|
147
152
|
const data = await (0, client_1.request)(queries_1.CART_GIFT_CARD_CODES_REMOVE_MUTATION, {
|
|
148
153
|
cartId,
|
|
149
154
|
appliedGiftCardIds,
|
|
150
|
-
});
|
|
155
|
+
}, cartImages(opts));
|
|
151
156
|
(0, client_1.assertNoUserErrors)('cartGiftCardCodesRemove', data.cartGiftCardCodesRemove.userErrors);
|
|
152
157
|
return normalize(data.cartGiftCardCodesRemove.cart);
|
|
153
158
|
},
|
package/dist/cart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.js","sourceRoot":"","sources":["../src/cart.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cart.js","sourceRoot":"","sources":["../src/cart.ts"],"names":[],"mappings":";;;AAyEA,wCASC;AAlFD,qCAAkE;AAClE,uCAYmB;AAwBnB,SAAS,SAAS,CAAC,CAAM;;IACvB,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAA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BAAkB,EAAC,sBAAsB,EAAE,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACjF,OAAO,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,MAAc,EAAE,kBAA4B,EAAE,IAAmB;QACzF,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAkB,8CAAoC,EAAE;YAChF,MAAM;YACN,kBAAkB;SACnB,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QACrB,IAAA,2BAAkB,EAAC,yBAAyB,EAAE,IAAI,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QACvF,OAAO,SAAS,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ShopifyConfig, UserError } from './types';
|
|
1
|
+
import { ImageTransform, ShopifyConfig, UserError } from './types';
|
|
2
2
|
export declare function setShopInfo(info: {
|
|
3
3
|
moneyFormat?: string | null;
|
|
4
4
|
currencyCode?: string | null;
|
|
@@ -9,7 +9,25 @@ export declare function getCurrencyCode(): string | null;
|
|
|
9
9
|
export declare function setConfig(config: ShopifyConfig): void;
|
|
10
10
|
export declare function getConfig(): ShopifyConfig;
|
|
11
11
|
export declare function isConfigured(): boolean;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Declares `$imageTransform` on an operation whose fragments use it (`ImageFields`, media URLs).
|
|
14
|
+
* GraphQL requires every operation to declare the variables its fragments use; doing it here means
|
|
15
|
+
* no query can forget, and any operation that returns images accepts a transform. An operation that
|
|
16
|
+
* uses no image URL is returned untouched. Runs before `withContext`, while the operation's
|
|
17
|
+
* argument list still directly follows its name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function withImageTransform(operation: string): string;
|
|
20
|
+
export interface RequestOptions {
|
|
21
|
+
/** Skip a recent cached answer and go to the network (pull-to-refresh). */
|
|
22
|
+
fresh?: boolean;
|
|
23
|
+
/** Resize/convert the answer's images on Shopify's CDN. Omitted or null: original URLs. */
|
|
24
|
+
imageTransform?: ImageTransform | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One Storefront call. Identical queries share one network request, and catalogue reads reuse a
|
|
28
|
+
* recent answer (see `requestCache.ts`); mutations always go to the network.
|
|
29
|
+
*/
|
|
30
|
+
export declare function request<T>(operation: string, variables?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
|
|
13
31
|
/** Throws if a Shopify mutation payload contains userErrors. */
|
|
14
32
|
export declare function assertNoUserErrors(label: string, errors: UserError[] | null | undefined): void;
|
|
15
33
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAgB,SAAS,EAAE,MAAM,SAAS,CAAC;AAajF,wBAAgB,WAAW,CAAC,IAAI,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAGrG;AAED,0CAA0C;AAC1C,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAE/C;AAID,wBAAgB,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CASrD;AAeD,wBAAgB,SAAS,IAAI,aAAa,CAGzC;AAED,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAyGD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS5D;AAED,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2FAA2F;IAC3F,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACxC;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC,CAgDZ;AAED,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAO9F"}
|
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"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D,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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
@@ -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
|
};
|