sanity-plugin-shopify-assets 1.0.0 → 1.0.1

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 CHANGED
@@ -28,7 +28,7 @@ Add it as a plugin in sanity.config.ts (or .js):
28
28
  })
29
29
  ```
30
30
 
31
- Simply update the `shopifyDomain` to your store URL. You'll need to install the [Sanity Connect](https://www.sanity.io/docs/sanity-connect-for-shopify) app on your store to handle authorisation.
31
+ Simply update the `shopifyDomain` to your store URL. You'll need to install the [Sanity Connect](https://www.sanity.io/docs/sanity-connect-for-shopify) app on your store to handle authorisation. You'll need to ensure the Liquid sync option is enabled within the Sanity Connect app.
32
32
 
33
33
  Then you can enable the asset selector on a field:
34
34
 
package/dist/index.esm.js CHANGED
@@ -2,7 +2,7 @@ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _temp
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
4
  import { Card, Box, useTheme, Text, Flex, Button, Stack, Dialog, Inline, TextInput, Spinner, Grid } from '@sanity/ui';
5
- import { useProjectId, PatchEvent, set, unset, DiffFromTo, defineType, defineField, definePlugin } from 'sanity';
5
+ import { useProjectId, useDataset, PatchEvent, set, unset, DiffFromTo, defineType, defineField, definePlugin } from 'sanity';
6
6
  import r, { useRef, useDebugValue, useContext, createElement, useEffect, useCallback, useState, useMemo } from 'react';
7
7
  import videojs from 'video.js';
8
8
  import prettyBytes from 'pretty-bytes';
@@ -2203,21 +2203,63 @@ function File(props) {
2203
2203
  }
2204
2204
  const Search = styled(Stack)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: sticky;\n top: 0;\n z-index: 1;\n"])));
2205
2205
  styled.div(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n overflow-y: auto;\n max-height: 80vh;\n"])));
2206
- const fetchSearch = (projectId, shop, query, cursor, perPage) => defer(() => axios.get("https://".concat(projectId, ".api.sanity.io/v1/shopify/assets/production?shop=").concat(shop, "&query=").concat(encodeURIComponent(query)).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(perPage), {
2207
- withCredentials: true,
2208
- method: "GET"
2209
- })).pipe(map(result => result.data));
2210
- const fetchList = (projectId, shop, cursor, perPage) => defer(() => axios.get("https://".concat(projectId, ".api.sanity.io/v1/shopify/assets/production?shop=").concat(shop).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(perPage), {
2211
- withCredentials: true,
2212
- method: "GET"
2213
- })).pipe(map(result => result.data));
2214
- const search = (projectId, shop, query, cursor, resultsPerPage) => {
2206
+ const fetchSearch = props => {
2207
+ const {
2208
+ projectId,
2209
+ dataset,
2210
+ shop,
2211
+ query,
2212
+ cursor,
2213
+ resultsPerPage
2214
+ } = props;
2215
+ return defer(() => {
2216
+ return axios.get("https://".concat(projectId, ".api.sanity.work/v1/shopify/assets/").concat(dataset, "?shop=").concat(shop, "&query=").concat(encodeURIComponent(query)).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(resultsPerPage), {
2217
+ withCredentials: true,
2218
+ method: "GET"
2219
+ });
2220
+ }).pipe(map(result => result.data));
2221
+ };
2222
+ const fetchList = props => {
2223
+ const {
2224
+ projectId,
2225
+ dataset,
2226
+ shop,
2227
+ cursor,
2228
+ resultsPerPage
2229
+ } = props;
2230
+ return defer(() => axios.get("https://".concat(projectId, ".api.sanity.work/v1/shopify/assets/").concat(dataset, "?shop=").concat(shop).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(resultsPerPage), {
2231
+ withCredentials: true,
2232
+ method: "GET"
2233
+ })).pipe(map(result => result.data));
2234
+ };
2235
+ const search = props => {
2236
+ const {
2237
+ projectId,
2238
+ dataset,
2239
+ shop,
2240
+ query,
2241
+ cursor,
2242
+ resultsPerPage
2243
+ } = props;
2215
2244
  return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(_ref11 => {
2216
2245
  let [q, c] = _ref11;
2217
2246
  if (q) {
2218
- return fetchSearch(projectId, shop, q, c, resultsPerPage).pipe(distinctUntilChanged());
2247
+ return fetchSearch({
2248
+ projectId,
2249
+ dataset,
2250
+ shop,
2251
+ query: q,
2252
+ cursor: c,
2253
+ resultsPerPage
2254
+ }).pipe(distinctUntilChanged());
2219
2255
  }
2220
- return fetchList(projectId, shop, c, resultsPerPage);
2256
+ return fetchList({
2257
+ projectId,
2258
+ dataset,
2259
+ shop,
2260
+ cursor: c,
2261
+ resultsPerPage
2262
+ });
2221
2263
  })));
2222
2264
  };
2223
2265
  const RESULTS_PER_PAGE = 42;
@@ -2233,6 +2275,7 @@ function ShopifyAssetPicker(props) {
2233
2275
  value
2234
2276
  } = props;
2235
2277
  const projectId = useProjectId();
2278
+ const dataset = useDataset();
2236
2279
  const [error, setError] = useState("");
2237
2280
  const [query, setQuery] = useState("");
2238
2281
  const [searchResults, setSearchResults] = useState([]);
@@ -2244,7 +2287,14 @@ function ShopifyAssetPicker(props) {
2244
2287
  if (!shopifyDomain) setError("Please configure your Shopify domain in the plugin config");
2245
2288
  }, [shopifyDomain]);
2246
2289
  useEffect(() => {
2247
- const searchSubscription = search(projectId, shopifyDomain, searchSubject$, cursorSubject$, RESULTS_PER_PAGE).subscribe({
2290
+ const searchSubscription = search({
2291
+ projectId,
2292
+ dataset,
2293
+ shop: shopifyDomain,
2294
+ query: searchSubject$,
2295
+ cursor: cursorSubject$,
2296
+ resultsPerPage: RESULTS_PER_PAGE
2297
+ }).subscribe({
2248
2298
  next: results => {
2249
2299
  setSearchResults(prevResults => [...prevResults, ...results.assets]);
2250
2300
  setPageInfo(results.pageInfo);
@@ -2255,7 +2305,7 @@ function ShopifyAssetPicker(props) {
2255
2305
  }
2256
2306
  });
2257
2307
  return () => searchSubscription.unsubscribe();
2258
- }, [searchSubject$, cursorSubject$, shopifyDomain, projectId]);
2308
+ }, [searchSubject$, cursorSubject$, shopifyDomain, projectId, dataset]);
2259
2309
  const handleSearchTermChanged = useCallback(event => {
2260
2310
  const newQuery = event.currentTarget.value;
2261
2311
  setQuery(newQuery);