@anker-in/shopify-sdk 1.2.0-beta.13 → 1.2.0-beta.14

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/dist/index.mjs CHANGED
@@ -31,10 +31,7 @@ function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafiel
31
31
  queryInput[`${key}MetafieldIdentifiers`] = uniqueIdentifiers;
32
32
  return queryInput;
33
33
  },
34
- {
35
- productMetafieldIdentifiers: [],
36
- variantMetafieldIdentifiers: []
37
- }
34
+ {}
38
35
  );
39
36
  return identifiers;
40
37
  }
@@ -1409,11 +1406,13 @@ async function getProduct(client, options) {
1409
1406
  const { handle, graphqlQuery, metafieldIdentifiers } = options;
1410
1407
  const query = graphqlQuery || getProductQuery2;
1411
1408
  const variables = { handle };
1412
- if (metafieldIdentifiers) {
1413
- variables.productMetafieldIdentifiers = metafieldIdentifiers;
1414
- variables.variantMetafieldIdentifiers = metafieldIdentifiers;
1415
- }
1416
- const data = await client.query(query, variables);
1409
+ const data = await client.query(query, {
1410
+ ...variables,
1411
+ ...constructMetafieldIdentifiersQueryParams(
1412
+ metafieldIdentifiers,
1413
+ client.getConfig().getMetafieldNamespacePrefix()
1414
+ )
1415
+ });
1417
1416
  if (!data?.product) {
1418
1417
  return void 0;
1419
1418
  }
@@ -1467,7 +1466,7 @@ var getAllProductsQuery = (
1467
1466
  ${imageFragment}
1468
1467
  `
1469
1468
  );
1470
- async function fetchAllPages(client, options, afterCursor) {
1469
+ async function fetchAllProducts(client, options, afterCursor) {
1471
1470
  const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
1472
1471
  const queryString = graphqlQuery || getAllProductsQuery;
1473
1472
  const variables = {
@@ -1477,26 +1476,36 @@ async function fetchAllPages(client, options, afterCursor) {
1477
1476
  sortKey,
1478
1477
  reverse
1479
1478
  };
1480
- if (metafieldIdentifiers) {
1481
- variables.productMetafieldIdentifiers = metafieldIdentifiers;
1482
- variables.variantMetafieldIdentifiers = metafieldIdentifiers;
1483
- }
1484
- const data = await client.query(queryString, variables);
1479
+ const data = await client.query(queryString, {
1480
+ ...variables,
1481
+ ...constructMetafieldIdentifiersQueryParams(
1482
+ metafieldIdentifiers,
1483
+ client.getConfig().getMetafieldNamespacePrefix()
1484
+ )
1485
+ });
1485
1486
  if (!data || !data.products) {
1486
1487
  return [];
1487
1488
  }
1488
1489
  const products = data.products.edges.map((edge) => normalizeProduct(edge.node));
1489
1490
  if (data.products.pageInfo.hasNextPage) {
1490
- const nextProducts = await fetchAllPages(client, options, data.products.pageInfo.endCursor);
1491
+ const nextProducts = await fetchAllProducts(client, options, data.products.pageInfo.endCursor);
1491
1492
  return [...products, ...nextProducts];
1492
1493
  }
1493
1494
  return products;
1494
1495
  }
1495
1496
  async function getAllProducts(client, options) {
1496
- return fetchAllPages(client, options);
1497
+ return fetchAllProducts(client, options);
1497
1498
  }
1498
1499
  async function getProducts(client, options) {
1499
- const { first = 250, after, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
1500
+ const {
1501
+ first = 250,
1502
+ after,
1503
+ query,
1504
+ graphqlQuery,
1505
+ sortKey,
1506
+ reverse,
1507
+ metafieldIdentifiers
1508
+ } = options;
1500
1509
  const queryString = graphqlQuery || getAllProductsQuery;
1501
1510
  const variables = {
1502
1511
  first,
@@ -2069,10 +2078,13 @@ async function getCollection(client, options) {
2069
2078
  const { handle, graphqlQuery, metafieldIdentifiers } = options;
2070
2079
  const query = graphqlQuery || getCollectionQuery;
2071
2080
  const variables = { handle };
2072
- if (metafieldIdentifiers) {
2073
- variables.metafieldIdentifiers = metafieldIdentifiers;
2074
- }
2075
- const data = await client.query(query, variables);
2081
+ const data = await client.query(query, {
2082
+ ...variables,
2083
+ ...constructMetafieldIdentifiersQueryParams(
2084
+ metafieldIdentifiers,
2085
+ client.getConfig().getMetafieldNamespacePrefix()
2086
+ )
2087
+ });
2076
2088
  if (!data?.collection) {
2077
2089
  return void 0;
2078
2090
  }
@@ -2114,7 +2126,7 @@ var getAllCollectionsQuery = (
2114
2126
  ${imageFragment}
2115
2127
  `
2116
2128
  );
2117
- async function fetchAllPages2(client, options, afterCursor) {
2129
+ async function fetchAllPages(client, options, afterCursor) {
2118
2130
  const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
2119
2131
  const queryString = graphqlQuery || getAllCollectionsQuery;
2120
2132
  const variables = {
@@ -2124,25 +2136,40 @@ async function fetchAllPages2(client, options, afterCursor) {
2124
2136
  sortKey,
2125
2137
  reverse
2126
2138
  };
2127
- if (metafieldIdentifiers) {
2128
- variables.metafieldIdentifiers = metafieldIdentifiers;
2129
- }
2130
- const data = await client.query(queryString, variables);
2139
+ const data = await client.query(queryString, {
2140
+ ...variables,
2141
+ ...constructMetafieldIdentifiersQueryParams(
2142
+ metafieldIdentifiers,
2143
+ client.getConfig().getMetafieldNamespacePrefix()
2144
+ )
2145
+ });
2131
2146
  if (!data || !data.collections) {
2132
2147
  return [];
2133
2148
  }
2134
2149
  const collections = data.collections.edges.map((edge) => normalizeCollection(edge.node));
2135
2150
  if (data.collections.pageInfo.hasNextPage) {
2136
- const nextCollections = await fetchAllPages2(client, options, data.collections.pageInfo.endCursor);
2151
+ const nextCollections = await fetchAllPages(
2152
+ client,
2153
+ options,
2154
+ data.collections.pageInfo.endCursor
2155
+ );
2137
2156
  return [...collections, ...nextCollections];
2138
2157
  }
2139
2158
  return collections;
2140
2159
  }
2141
2160
  async function getAllCollections(client, options) {
2142
- return fetchAllPages2(client, options);
2161
+ return fetchAllPages(client, options);
2143
2162
  }
2144
2163
  async function getCollections(client, options) {
2145
- const { first = 250, after, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
2164
+ const {
2165
+ first = 250,
2166
+ after,
2167
+ query,
2168
+ graphqlQuery,
2169
+ sortKey,
2170
+ reverse,
2171
+ metafieldIdentifiers
2172
+ } = options;
2146
2173
  const queryString = graphqlQuery || getAllCollectionsQuery;
2147
2174
  const variables = {
2148
2175
  first,
@@ -2151,10 +2178,13 @@ async function getCollections(client, options) {
2151
2178
  sortKey,
2152
2179
  reverse
2153
2180
  };
2154
- if (metafieldIdentifiers) {
2155
- variables.metafieldIdentifiers = metafieldIdentifiers;
2156
- }
2157
- const data = await client.query(queryString, variables);
2181
+ const data = await client.query(queryString, {
2182
+ ...variables,
2183
+ ...constructMetafieldIdentifiersQueryParams(
2184
+ metafieldIdentifiers,
2185
+ client.getConfig().getMetafieldNamespacePrefix()
2186
+ )
2187
+ });
2158
2188
  if (!data || !data.collections) {
2159
2189
  return {
2160
2190
  collections: [],
@@ -2243,7 +2273,7 @@ function normalizeMetafields2(metafields) {
2243
2273
  // src/api/blog/get-blog.ts
2244
2274
  async function getBlog(client, options) {
2245
2275
  const { handle, graphqlQuery, metafieldIdentifiers } = options;
2246
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2276
+ const hasMetafields = metafieldIdentifiers?.blog?.length;
2247
2277
  const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2248
2278
  const defaultQuery = (
2249
2279
  /* GraphQL */
@@ -2261,10 +2291,13 @@ async function getBlog(client, options) {
2261
2291
  );
2262
2292
  const query = graphqlQuery || defaultQuery;
2263
2293
  const variables = { handle };
2264
- if (hasMetafields) {
2265
- variables.blogMetafieldIdentifiers = metafieldIdentifiers;
2266
- }
2267
- const data = await client.query(query, variables);
2294
+ const data = await client.query(query, {
2295
+ ...variables,
2296
+ ...constructMetafieldIdentifiersQueryParams(
2297
+ metafieldIdentifiers,
2298
+ client.getConfig().getMetafieldNamespacePrefix()
2299
+ )
2300
+ });
2268
2301
  if (!data || !data.blog) {
2269
2302
  return void 0;
2270
2303
  }
@@ -2272,9 +2305,9 @@ async function getBlog(client, options) {
2272
2305
  }
2273
2306
 
2274
2307
  // src/api/blog/get-all-blogs.ts
2275
- async function fetchAllPages3(client, options, afterCursor) {
2308
+ async function fetchAllPages2(client, options, afterCursor) {
2276
2309
  const { first = 250, query, graphqlQuery, metafieldIdentifiers } = options;
2277
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2310
+ const hasMetafields = !!metafieldIdentifiers?.blog?.length;
2278
2311
  const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2279
2312
  const defaultQueryString = (
2280
2313
  /* GraphQL */
@@ -2309,45 +2342,49 @@ async function fetchAllPages3(client, options, afterCursor) {
2309
2342
  if (query) {
2310
2343
  variables.query = query;
2311
2344
  }
2312
- if (hasMetafields) {
2313
- variables.blogMetafieldIdentifiers = metafieldIdentifiers;
2314
- }
2315
- const data = await client.query(queryString, variables);
2345
+ const data = await client.query(queryString, {
2346
+ ...variables,
2347
+ ...constructMetafieldIdentifiersQueryParams(
2348
+ metafieldIdentifiers,
2349
+ client.getConfig().getMetafieldNamespacePrefix()
2350
+ )
2351
+ });
2316
2352
  if (!data || !data.blogs) {
2317
2353
  return [];
2318
2354
  }
2319
2355
  const blogs = data.blogs.edges?.map((edge) => normalizeBlog(edge.node)) || [];
2320
2356
  if (data.blogs.pageInfo.hasNextPage) {
2321
- const nextBlogs = await fetchAllPages3(client, options, data.blogs.pageInfo.endCursor);
2357
+ const nextBlogs = await fetchAllPages2(client, options, data.blogs.pageInfo.endCursor);
2322
2358
  return [...blogs, ...nextBlogs];
2323
2359
  }
2324
2360
  return blogs;
2325
2361
  }
2326
2362
  async function getAllBlogs(client, options) {
2327
- return fetchAllPages3(client, options);
2363
+ return fetchAllPages2(client, options);
2328
2364
  }
2329
2365
 
2330
2366
  // src/api/blog/get-article.ts
2331
2367
  async function getArticle(client, options) {
2332
2368
  const { blogHandle, articleHandle, graphqlQuery, metafieldIdentifiers } = options;
2333
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2334
- const articleFrag = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
2335
- const blogFrag = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2369
+ const hasArticleMetafields = !!metafieldIdentifiers?.article?.length;
2370
+ const hasBlogMetafields = !!metafieldIdentifiers?.blog?.length;
2371
+ const articleFrag = hasArticleMetafields ? articleWithMetafieldsFragment : articleFragment;
2372
+ const blogFrag = hasBlogMetafields ? blogWithMetafieldsFragment : blogFragment;
2336
2373
  const defaultQuery = (
2337
2374
  /* GraphQL */
2338
2375
  `
2339
2376
  query getArticle(
2340
2377
  $blogHandle: String!
2341
2378
  $articleHandle: String!
2342
- ${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2343
- ${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2379
+ ${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2380
+ ${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2344
2381
  ) {
2345
2382
  blog(handle: $blogHandle) {
2346
- ...${hasMetafields ? "blogWithMetafields" : "blog"}
2383
+ ...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
2347
2384
  articleByHandle(handle: $articleHandle) {
2348
- ...${hasMetafields ? "articleWithMetafields" : "article"}
2385
+ ...${hasArticleMetafields ? "articleWithMetafields" : "article"}
2349
2386
  blog {
2350
- ...${hasMetafields ? "blogWithMetafields" : "blog"}
2387
+ ...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
2351
2388
  }
2352
2389
  }
2353
2390
  }
@@ -2358,11 +2395,13 @@ async function getArticle(client, options) {
2358
2395
  );
2359
2396
  const query = graphqlQuery || defaultQuery;
2360
2397
  const variables = { blogHandle, articleHandle };
2361
- if (hasMetafields) {
2362
- variables.blogMetafieldIdentifiers = metafieldIdentifiers;
2363
- variables.articleMetafieldIdentifiers = metafieldIdentifiers;
2364
- }
2365
- const data = await client.query(query, variables);
2398
+ const data = await client.query(query, {
2399
+ ...variables,
2400
+ ...constructMetafieldIdentifiersQueryParams(
2401
+ metafieldIdentifiers,
2402
+ client.getConfig().getMetafieldNamespacePrefix()
2403
+ )
2404
+ });
2366
2405
  if (!data || !data.blog || !data.blog.articleByHandle) {
2367
2406
  return void 0;
2368
2407
  }
@@ -2370,7 +2409,7 @@ async function getArticle(client, options) {
2370
2409
  }
2371
2410
 
2372
2411
  // src/api/blog/get-articles.ts
2373
- async function fetchAllPages4(client, options, afterCursor) {
2412
+ async function fetchAllArticles(client, options, afterCursor) {
2374
2413
  const {
2375
2414
  first = 250,
2376
2415
  query,
@@ -2379,7 +2418,7 @@ async function fetchAllPages4(client, options, afterCursor) {
2379
2418
  reverse = false,
2380
2419
  metafieldIdentifiers
2381
2420
  } = options;
2382
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2421
+ const hasMetafields = !!metafieldIdentifiers?.article?.length;
2383
2422
  const fragment = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
2384
2423
  const defaultQueryString = (
2385
2424
  /* GraphQL */
@@ -2423,26 +2462,29 @@ async function fetchAllPages4(client, options, afterCursor) {
2423
2462
  if (query) {
2424
2463
  variables.query = query;
2425
2464
  }
2426
- if (hasMetafields) {
2427
- variables.articleMetafieldIdentifiers = metafieldIdentifiers;
2428
- }
2429
- const data = await client.query(queryString, variables);
2465
+ const data = await client.query(queryString, {
2466
+ ...variables,
2467
+ ...constructMetafieldIdentifiersQueryParams(
2468
+ metafieldIdentifiers,
2469
+ client.getConfig().getMetafieldNamespacePrefix()
2470
+ )
2471
+ });
2430
2472
  if (!data || !data.articles) {
2431
2473
  return [];
2432
2474
  }
2433
2475
  const articles = data.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
2434
2476
  if (data.articles.pageInfo.hasNextPage) {
2435
- const nextArticles = await fetchAllPages4(client, options, data.articles.pageInfo.endCursor);
2477
+ const nextArticles = await fetchAllArticles(client, options, data.articles.pageInfo.endCursor);
2436
2478
  return [...articles, ...nextArticles];
2437
2479
  }
2438
2480
  return articles;
2439
2481
  }
2440
2482
  async function getArticles(client, options) {
2441
- return fetchAllPages4(client, options);
2483
+ return fetchAllArticles(client, options);
2442
2484
  }
2443
2485
 
2444
2486
  // src/api/blog/get-articles-in-blog.ts
2445
- async function fetchAllPages5(client, options, afterCursor) {
2487
+ async function fetchAllPages3(client, options, afterCursor) {
2446
2488
  const {
2447
2489
  blogHandle,
2448
2490
  first = 250,
@@ -2451,9 +2493,10 @@ async function fetchAllPages5(client, options, afterCursor) {
2451
2493
  reverse = false,
2452
2494
  metafieldIdentifiers
2453
2495
  } = options;
2454
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2455
- const articleFrag = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
2456
- const blogFrag = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2496
+ const hasArticleMetafields = !!metafieldIdentifiers?.article?.length;
2497
+ const hasBlogMetafields = !!metafieldIdentifiers?.blog?.length;
2498
+ const articleFrag = hasArticleMetafields ? articleWithMetafieldsFragment : articleFragment;
2499
+ const blogFrag = hasBlogMetafields ? blogWithMetafieldsFragment : blogFragment;
2457
2500
  const defaultQuery = (
2458
2501
  /* GraphQL */
2459
2502
  `
@@ -2463,11 +2506,11 @@ async function fetchAllPages5(client, options, afterCursor) {
2463
2506
  $after: String
2464
2507
  $sortKey: ArticleSortKeys!
2465
2508
  $reverse: Boolean!
2466
- ${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2467
- ${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2509
+ ${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2510
+ ${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2468
2511
  ) {
2469
2512
  blog(handle: $blogHandle) {
2470
- ...${hasMetafields ? "blogWithMetafields" : "blog"}
2513
+ ...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
2471
2514
  articles(
2472
2515
  first: $first
2473
2516
  after: $after
@@ -2476,7 +2519,7 @@ async function fetchAllPages5(client, options, afterCursor) {
2476
2519
  ) {
2477
2520
  edges {
2478
2521
  node {
2479
- ...${hasMetafields ? "articleWithMetafields" : "article"}
2522
+ ...${hasArticleMetafields ? "articleWithMetafields" : "article"}
2480
2523
  }
2481
2524
  }
2482
2525
  pageInfo {
@@ -2498,23 +2541,25 @@ async function fetchAllPages5(client, options, afterCursor) {
2498
2541
  sortKey,
2499
2542
  reverse
2500
2543
  };
2501
- if (hasMetafields) {
2502
- variables.blogMetafieldIdentifiers = metafieldIdentifiers;
2503
- variables.articleMetafieldIdentifiers = metafieldIdentifiers;
2504
- }
2505
- const data = await client.query(query, variables);
2544
+ const data = await client.query(query, {
2545
+ ...variables,
2546
+ ...constructMetafieldIdentifiersQueryParams(
2547
+ metafieldIdentifiers,
2548
+ client.getConfig().getMetafieldNamespacePrefix()
2549
+ )
2550
+ });
2506
2551
  if (!data || !data.blog || !data.blog.articles) {
2507
2552
  return [];
2508
2553
  }
2509
2554
  const articles = data.blog.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
2510
2555
  if (data.blog.articles.pageInfo.hasNextPage) {
2511
- const nextArticles = await fetchAllPages5(client, options, data.blog.articles.pageInfo.endCursor);
2556
+ const nextArticles = await fetchAllPages3(client, options, data.blog.articles.pageInfo.endCursor);
2512
2557
  return [...articles, ...nextArticles];
2513
2558
  }
2514
2559
  return articles;
2515
2560
  }
2516
2561
  async function getArticlesInBlog(client, options) {
2517
- return fetchAllPages5(client, options);
2562
+ return fetchAllPages3(client, options);
2518
2563
  }
2519
2564
 
2520
2565
  // src/api/page/normalize.ts
@@ -2537,7 +2582,7 @@ function normalizePage(page) {
2537
2582
  // src/api/page/get-page.ts
2538
2583
  async function getPage(client, options) {
2539
2584
  const { handle, graphqlQuery, metafieldIdentifiers } = options;
2540
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2585
+ const hasMetafields = !!metafieldIdentifiers?.page?.length;
2541
2586
  const fragment = hasMetafields ? pageWithMetafieldsFragment : pageFragment;
2542
2587
  const defaultQuery = (
2543
2588
  /* GraphQL */
@@ -2558,7 +2603,13 @@ async function getPage(client, options) {
2558
2603
  if (hasMetafields) {
2559
2604
  variables.pageMetafieldIdentifiers = metafieldIdentifiers;
2560
2605
  }
2561
- const data = await client.query(query, variables);
2606
+ const data = await client.query(query, {
2607
+ ...variables,
2608
+ ...constructMetafieldIdentifiersQueryParams(
2609
+ metafieldIdentifiers,
2610
+ client.getConfig().getMetafieldNamespacePrefix()
2611
+ )
2612
+ });
2562
2613
  if (!data || !data.page) {
2563
2614
  return void 0;
2564
2615
  }
@@ -2579,7 +2630,7 @@ function normalizeShop(shop) {
2579
2630
  // src/api/shop/get-shop.ts
2580
2631
  async function getShop(client, options) {
2581
2632
  const { graphqlQuery, metafieldIdentifiers } = options;
2582
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2633
+ const hasMetafields = !!metafieldIdentifiers?.shop?.length;
2583
2634
  const fragment = hasMetafields ? shopWithMetafieldsFragment : shopFragment;
2584
2635
  const defaultQuery = (
2585
2636
  /* GraphQL */
@@ -2596,10 +2647,13 @@ async function getShop(client, options) {
2596
2647
  );
2597
2648
  const query = graphqlQuery || defaultQuery;
2598
2649
  const variables = {};
2599
- if (hasMetafields) {
2600
- variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2601
- }
2602
- const data = await client.query(query, variables);
2650
+ const data = await client.query(query, {
2651
+ ...variables,
2652
+ ...constructMetafieldIdentifiersQueryParams(
2653
+ metafieldIdentifiers,
2654
+ client.getConfig().getMetafieldNamespacePrefix()
2655
+ )
2656
+ });
2603
2657
  if (!data || !data.shop) {
2604
2658
  return void 0;
2605
2659
  }