@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/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
|
|
@@ -156,6 +269,36 @@ Resolution order per key: `messages` prop → `config.messages` → `translate(k
|
|
|
156
269
|
rendering blank. `translate` is called with the i18n key where one exists
|
|
157
270
|
(`cart.added` → `toast.added_to_cart`), otherwise the message key itself.
|
|
158
271
|
|
|
272
|
+
### Reading the panel from the Live Layer
|
|
273
|
+
|
|
274
|
+
The editor publishes these fields into the app's Live Layer tree. The SDK owns
|
|
275
|
+
where each one lives, so an app only reads two values and passes its toast:
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
import { ALERT_SETTINGS_PATH, MAX_LINE_ITEMS_SETTING_PATH, useAlertSettings } from '@tiledev/sdk-shopify';
|
|
279
|
+
|
|
280
|
+
const alerts = useLL(ALERT_SETTINGS_PATH); // settings.alerts
|
|
281
|
+
const maxLineItems = useLL(MAX_LINE_ITEMS_SETTING_PATH); // settings.cart.maxLineItems
|
|
282
|
+
const props = useAlertSettings({ alerts, maxLineItems, show: showToast });
|
|
283
|
+
|
|
284
|
+
<ShopifyProvider config={config} {...props}> // messages, cartPolicy, onEvent
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
| Published value | Result |
|
|
288
|
+
| --- | --- |
|
|
289
|
+
| A string | That alert's copy, cut to 200 characters |
|
|
290
|
+
| `''` (the merchant cleared the field) | That alert is **silenced**: `onEvent` shows nothing |
|
|
291
|
+
| Absent, or not a string | The default copy |
|
|
292
|
+
| `maxLineItems` 1–100 (number or numeric string) | The cart limit |
|
|
293
|
+
| `maxLineItems` anything else | No limit |
|
|
294
|
+
|
|
295
|
+
Note the one difference from the `messages` prop: there an empty string falls
|
|
296
|
+
back to the default, here it silences. The panel publishes `''` only when the
|
|
297
|
+
merchant clears a field on purpose. Without React, `readAlertSettings(tree)`
|
|
298
|
+
and `readCartPolicy(value)` return the same values, and
|
|
299
|
+
`ALERT_SETTING_FIELDS` is the path table (`cart.outOfStock` sits in the
|
|
300
|
+
Checkout group, where the panel shows it).
|
|
301
|
+
|
|
159
302
|
### Cart line limit
|
|
160
303
|
|
|
161
304
|
`cartPolicy.maxLineItems` is the panel's "Cart Line Item Maximum Limit". It counts
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AlertMessageKey, AlertMessages, CartPolicy } from './types';
|
|
2
|
+
/** The Live Layer subtree holding every alert's copy. */
|
|
3
|
+
export declare const ALERT_SETTINGS_PATH: readonly ["settings", "alerts"];
|
|
4
|
+
/** The panel's "Max Different Products in Cart". */
|
|
5
|
+
export declare const MAX_LINE_ITEMS_SETTING_PATH: readonly ["settings", "cart", "maxLineItems"];
|
|
6
|
+
/**
|
|
7
|
+
* Where each alert's copy lives, as `[group, field]` under `ALERT_SETTINGS_PATH`.
|
|
8
|
+
* `cart.outOfStock` sits in the Checkout group: that is where the panel shows it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ALERT_SETTING_FIELDS: Readonly<Record<AlertMessageKey, readonly [group: string, field: string]>>;
|
|
11
|
+
/** The panel caps every alert at this; a longer published value is cut, not refused. */
|
|
12
|
+
export declare const MAX_ALERT_LENGTH = 200;
|
|
13
|
+
/** The panel's bounds for the line limit. Outside them the value is ignored (no limit). */
|
|
14
|
+
export declare const MAX_LINE_ITEMS_RANGE: {
|
|
15
|
+
readonly min: 1;
|
|
16
|
+
readonly max: 100;
|
|
17
|
+
};
|
|
18
|
+
export interface AlertSettings {
|
|
19
|
+
/** Published copy, ready for `<ShopifyProvider messages>`. */
|
|
20
|
+
messages: AlertMessages;
|
|
21
|
+
/** Alerts the merchant cleared: raise no toast for these. */
|
|
22
|
+
silenced: ReadonlySet<AlertMessageKey>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The alert copy and the silenced set from the `settings.alerts` subtree.
|
|
26
|
+
* Anything that isn't a string (unpublished, a stray number) keeps the default.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readAlertSettings(alerts: unknown): AlertSettings;
|
|
29
|
+
/**
|
|
30
|
+
* The cart policy from `settings.cart.maxLineItems`. The panel's number field may
|
|
31
|
+
* publish a string; a value outside 1–100 would either block every add or mean
|
|
32
|
+
* nothing, so it is ignored.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readCartPolicy(maxLineItems: unknown): CartPolicy;
|
|
35
|
+
/** Whether an event's alert was cleared in the panel. Events with no alert are never silenced. */
|
|
36
|
+
export declare function isAlertSilenced(event: {
|
|
37
|
+
messageKey?: AlertMessageKey;
|
|
38
|
+
}, silenced: ReadonlySet<AlertMessageKey>): boolean;
|
|
39
|
+
//# sourceMappingURL=alertSettings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alertSettings.d.ts","sourceRoot":"","sources":["../src/alertSettings.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1E,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,iCAAkC,CAAC;AAEnE,oDAAoD;AACpD,eAAO,MAAM,2BAA2B,+CAAgD,CAAC;AAEzF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAc3G,CAAC;AAEF,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB;;;CAAgC,CAAC;AAElE,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,QAAQ,EAAE,aAAa,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;CACxC;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAahE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,OAAO,GAAG,UAAU,CAKhE;AAED,kGAAkG;AAClG,wBAAgB,eAAe,CAC7B,KAAK,EAAE;IAAE,UAAU,CAAC,EAAE,eAAe,CAAA;CAAE,EACvC,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,GACrC,OAAO,CAET"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_LINE_ITEMS_RANGE = exports.MAX_ALERT_LENGTH = exports.ALERT_SETTING_FIELDS = exports.MAX_LINE_ITEMS_SETTING_PATH = exports.ALERT_SETTINGS_PATH = void 0;
|
|
4
|
+
exports.readAlertSettings = readAlertSettings;
|
|
5
|
+
exports.readCartPolicy = readCartPolicy;
|
|
6
|
+
exports.isAlertSilenced = isAlertSilenced;
|
|
7
|
+
/** The Live Layer subtree holding every alert's copy. */
|
|
8
|
+
exports.ALERT_SETTINGS_PATH = ['settings', 'alerts'];
|
|
9
|
+
/** The panel's "Max Different Products in Cart". */
|
|
10
|
+
exports.MAX_LINE_ITEMS_SETTING_PATH = ['settings', 'cart', 'maxLineItems'];
|
|
11
|
+
/**
|
|
12
|
+
* Where each alert's copy lives, as `[group, field]` under `ALERT_SETTINGS_PATH`.
|
|
13
|
+
* `cart.outOfStock` sits in the Checkout group: that is where the panel shows it.
|
|
14
|
+
*/
|
|
15
|
+
exports.ALERT_SETTING_FIELDS = {
|
|
16
|
+
'cart.added': ['cart', 'added'],
|
|
17
|
+
'cart.removed': ['cart', 'removed'],
|
|
18
|
+
'cart.limitExceeded': ['cart', 'limitExceeded'],
|
|
19
|
+
'cart.outOfStock': ['checkout', 'outOfStock'],
|
|
20
|
+
'wishlist.added': ['wishlist', 'added'],
|
|
21
|
+
'wishlist.removed': ['wishlist', 'removed'],
|
|
22
|
+
'wishlist.empty': ['wishlist', 'empty'],
|
|
23
|
+
'auth.loginSuccess': ['auth', 'loginSuccess'],
|
|
24
|
+
'auth.loginFailed': ['auth', 'loginFailed'],
|
|
25
|
+
'auth.loggedOut': ['auth', 'loggedOut'],
|
|
26
|
+
'auth.resetLinkSent': ['auth', 'resetLinkSent'],
|
|
27
|
+
'checkout.orderPlaced': ['checkout', 'orderPlaced'],
|
|
28
|
+
'checkout.paymentFailed': ['checkout', 'paymentFailed'],
|
|
29
|
+
};
|
|
30
|
+
/** The panel caps every alert at this; a longer published value is cut, not refused. */
|
|
31
|
+
exports.MAX_ALERT_LENGTH = 200;
|
|
32
|
+
/** The panel's bounds for the line limit. Outside them the value is ignored (no limit). */
|
|
33
|
+
exports.MAX_LINE_ITEMS_RANGE = { min: 1, max: 100 };
|
|
34
|
+
const ALERT_KEYS = Object.keys(exports.ALERT_SETTING_FIELDS);
|
|
35
|
+
/**
|
|
36
|
+
* The alert copy and the silenced set from the `settings.alerts` subtree.
|
|
37
|
+
* Anything that isn't a string (unpublished, a stray number) keeps the default.
|
|
38
|
+
*/
|
|
39
|
+
function readAlertSettings(alerts) {
|
|
40
|
+
const messages = {};
|
|
41
|
+
const silenced = new Set();
|
|
42
|
+
const tree = isRecord(alerts) ? alerts : {};
|
|
43
|
+
for (const key of ALERT_KEYS) {
|
|
44
|
+
const [group, field] = exports.ALERT_SETTING_FIELDS[key];
|
|
45
|
+
const section = tree[group];
|
|
46
|
+
const value = isRecord(section) ? section[field] : undefined;
|
|
47
|
+
if (typeof value !== 'string')
|
|
48
|
+
continue;
|
|
49
|
+
if (value.trim() === '')
|
|
50
|
+
silenced.add(key);
|
|
51
|
+
else
|
|
52
|
+
messages[key] = value.slice(0, exports.MAX_ALERT_LENGTH);
|
|
53
|
+
}
|
|
54
|
+
return { messages, silenced };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The cart policy from `settings.cart.maxLineItems`. The panel's number field may
|
|
58
|
+
* publish a string; a value outside 1–100 would either block every add or mean
|
|
59
|
+
* nothing, so it is ignored.
|
|
60
|
+
*/
|
|
61
|
+
function readCartPolicy(maxLineItems) {
|
|
62
|
+
const n = typeof maxLineItems === 'string' ? Number.parseInt(maxLineItems, 10) : maxLineItems;
|
|
63
|
+
if (typeof n !== 'number' || !Number.isFinite(n))
|
|
64
|
+
return {};
|
|
65
|
+
if (n < exports.MAX_LINE_ITEMS_RANGE.min || n > exports.MAX_LINE_ITEMS_RANGE.max)
|
|
66
|
+
return {};
|
|
67
|
+
return { maxLineItems: Math.round(n) };
|
|
68
|
+
}
|
|
69
|
+
/** Whether an event's alert was cleared in the panel. Events with no alert are never silenced. */
|
|
70
|
+
function isAlertSilenced(event, silenced) {
|
|
71
|
+
return !!event.messageKey && silenced.has(event.messageKey);
|
|
72
|
+
}
|
|
73
|
+
function isRecord(value) {
|
|
74
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=alertSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alertSettings.js","sourceRoot":"","sources":["../src/alertSettings.ts"],"names":[],"mappings":";;;AA4DA,8CAaC;AAOD,wCAKC;AAGD,0CAKC;AA9ED,yDAAyD;AAC5C,QAAA,mBAAmB,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAU,CAAC;AAEnE,oDAAoD;AACvC,QAAA,2BAA2B,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,CAAU,CAAC;AAEzF;;;GAGG;AACU,QAAA,oBAAoB,GAA+E;IAC9G,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/B,cAAc,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;IACnC,oBAAoB,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC;IAC/C,iBAAiB,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC;IAC7C,gBAAgB,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;IACvC,kBAAkB,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC;IAC3C,gBAAgB,EAAE,CAAC,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ogs.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.js","sourceRoot":"","sources":["../src/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AC;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,EAAE;QACR,WAAW,EAAE,CAA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AAE,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"}
|