@ehrenkind/shopify-lib 0.7.1 → 0.7.4

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.cjs CHANGED
@@ -54,6 +54,7 @@ __export(index_exports, {
54
54
  getOrderPaymentDetailsById: () => getOrderPaymentDetailsById,
55
55
  getOrdersByCustomerId: () => getOrdersByCustomerId,
56
56
  getProductVariantsBySkus: () => getProductVariantsBySkus,
57
+ isRetryableError: () => isRetryableError,
57
58
  parseGid: () => parseGid,
58
59
  updateFulfillmentTracking: () => updateFulfillmentTracking,
59
60
  upsertMetaobject: () => upsertMetaobject
@@ -115,7 +116,7 @@ var import_zod = require("zod");
115
116
 
116
117
  // src/utils/apiVersion.ts
117
118
  var import_shopify_api = require("@shopify/shopify-api");
118
- var SHOPIFY_API_VERSION = import_shopify_api.ApiVersion.April25;
119
+ var SHOPIFY_API_VERSION = import_shopify_api.ApiVersion.July25;
119
120
 
120
121
  // src/utils/shopifyClient.ts
121
122
  import_dotenv.default.config();
@@ -188,6 +189,38 @@ try {
188
189
  }
189
190
 
190
191
  // src/utils/shopifyFetch.ts
192
+ var RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
193
+ "ECONNRESET",
194
+ "ETIMEDOUT",
195
+ "ECONNREFUSED",
196
+ "ENOTFOUND",
197
+ "EPIPE",
198
+ "EAI_AGAIN",
199
+ "EHOSTUNREACH",
200
+ "ENETUNREACH",
201
+ // undici (Node 18+ fetch) error codes
202
+ "UND_ERR_SOCKET",
203
+ "UND_ERR_CONNECT_TIMEOUT",
204
+ "UND_ERR_HEADERS_TIMEOUT",
205
+ "UND_ERR_BODY_TIMEOUT"
206
+ ]);
207
+ function hasRetryableCode(value) {
208
+ if (!value || typeof value !== "object") return false;
209
+ const code = value.code;
210
+ return typeof code === "string" && RETRYABLE_ERROR_CODES.has(code);
211
+ }
212
+ function isRetryableError(error) {
213
+ if (!(error instanceof Error)) return false;
214
+ if (hasRetryableCode(error)) return true;
215
+ if (error instanceof TypeError && error.message.includes("fetch failed")) {
216
+ return true;
217
+ }
218
+ if (hasRetryableCode(error.cause)) return true;
219
+ return false;
220
+ }
221
+ function sleep(ms) {
222
+ return new Promise((resolve) => setTimeout(resolve, ms));
223
+ }
191
224
  function convertIdIntoGid(id, type) {
192
225
  return `gid://shopify/${type}/${id}`;
193
226
  }
@@ -204,16 +237,25 @@ async function fetchShopifyGraphql(params) {
204
237
  query,
205
238
  variables: initialVariables,
206
239
  dataExtractor,
207
- fetchAllPages = false
240
+ fetchAllPages = false,
241
+ retries = 0
208
242
  } = params;
209
243
  let currentVariables = { ...initialVariables };
210
244
  if (!dataExtractor) {
211
- return makeRequest(query, currentVariables);
245
+ return makeRequest(
246
+ query,
247
+ currentVariables,
248
+ retries
249
+ );
212
250
  }
213
251
  const allNodes = [];
214
252
  let hasNextLoop = true;
215
253
  do {
216
- const response = await makeRequest(query, currentVariables);
254
+ const response = await makeRequest(
255
+ query,
256
+ currentVariables,
257
+ retries
258
+ );
217
259
  const { nodes, pageInfo, userErrors } = dataExtractor(response);
218
260
  if (Array.isArray(userErrors) && userErrors.length > 0) {
219
261
  const errorMessages = userErrors.map((e) => e.message || JSON.stringify(e)).join("\n");
@@ -234,33 +276,53 @@ async function fetchShopifyGraphql(params) {
234
276
  } while (hasNextLoop);
235
277
  return allNodes;
236
278
  }
237
- async function makeRequest(query, variables) {
238
- const response = await shopifyGraphqlClient.request(query, {
239
- variables
240
- });
241
- if (response.errors) {
242
- let errorMessages = "GraphQL query failed.";
243
- const errors = response.errors;
244
- if (Array.isArray(errors)) {
245
- errorMessages = errors.map((e) => e.message || JSON.stringify(e)).join("\n");
246
- } else if (typeof errors === "object" && errors !== null && "message" in errors) {
247
- errorMessages = errors.message || JSON.stringify(errors);
248
- } else if (typeof errors === "string") {
249
- errorMessages = errors;
250
- } else {
251
- errorMessages = JSON.stringify(errors);
279
+ async function makeRequest(query, variables, retries = 0) {
280
+ const maxRetries = Number.isFinite(retries) ? Math.max(0, Math.floor(retries)) : 0;
281
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
282
+ try {
283
+ const response = await shopifyGraphqlClient.request(query, {
284
+ variables
285
+ });
286
+ if (response.errors) {
287
+ let errorMessages = "GraphQL query failed.";
288
+ const errors = response.errors;
289
+ if (Array.isArray(errors)) {
290
+ errorMessages = errors.map((e) => e.message || JSON.stringify(e)).join("\n");
291
+ } else if (typeof errors === "object" && errors !== null && "message" in errors) {
292
+ errorMessages = errors.message || JSON.stringify(errors);
293
+ } else if (typeof errors === "string") {
294
+ errorMessages = errors;
295
+ } else {
296
+ errorMessages = JSON.stringify(errors);
297
+ }
298
+ logger.error("GraphQL query failed:", errorMessages);
299
+ throw new Error(`GraphQL errors: ${errorMessages}`);
300
+ }
301
+ if (!response.data) {
302
+ throw new Error("No data in Shopify API response");
303
+ }
304
+ return response.data;
305
+ } catch (error) {
306
+ if (attempt < maxRetries && isRetryableError(error)) {
307
+ const base = Math.min(1e3 * 2 ** attempt, 1e4);
308
+ const jitter = base * 0.2 * (Math.random() * 2 - 1);
309
+ const delay = Math.max(0, Math.round(base + jitter));
310
+ const totalAttempts = maxRetries + 1;
311
+ logger.warn(
312
+ `Transient error (attempt ${attempt + 1}/${totalAttempts}), retrying in ${delay}ms:`,
313
+ error.message
314
+ );
315
+ await sleep(delay);
316
+ continue;
317
+ }
318
+ throw error;
252
319
  }
253
- logger.error("GraphQL query failed:", errorMessages);
254
- throw new Error(`GraphQL errors: ${errorMessages}`);
255
- }
256
- if (!response.data) {
257
- throw new Error("No data in Shopify API response");
258
320
  }
259
- return response.data;
321
+ throw new Error("Unexpected: retry loop exited without result");
260
322
  }
261
323
 
262
324
  // src/mutations/customers/deleteCustomerById.ts
263
- async function deleteCustomerById(customerId) {
325
+ async function deleteCustomerById(customerId, retries = 1) {
264
326
  const mutation9 = gql`#graphql
265
327
  mutation customerDelete($input: CustomerDeleteInput!) {
266
328
  customerDelete(input: $input) {
@@ -278,6 +340,7 @@ async function deleteCustomerById(customerId) {
278
340
  const response = await fetchShopifyGraphql({
279
341
  query: mutation9,
280
342
  variables,
343
+ retries,
281
344
  dataExtractor: (data) => {
282
345
  if (!data.customerDelete) {
283
346
  throw new Error("GraphQL response missing 'customerDelete' field");
@@ -294,7 +357,7 @@ async function deleteCustomerById(customerId) {
294
357
  }
295
358
 
296
359
  // src/mutations/files/deleteFilesByIds.ts
297
- async function deleteFilesByIds(fileIds) {
360
+ async function deleteFilesByIds(fileIds, retries = 1) {
298
361
  if (fileIds.length === 0) {
299
362
  return [];
300
363
  }
@@ -314,6 +377,7 @@ async function deleteFilesByIds(fileIds) {
314
377
  const response = await fetchShopifyGraphql({
315
378
  query: mutation9,
316
379
  variables,
380
+ retries,
317
381
  dataExtractor: (data) => {
318
382
  if (!data.fileDelete) {
319
383
  throw new Error("GraphQL response missing 'fileDelete' field");
@@ -342,7 +406,7 @@ var mutation = gql`#graphql
342
406
  }
343
407
  }
344
408
  `;
345
- async function createFile(url, altText, filename) {
409
+ async function createFile(url, altText, filename, retries = 0) {
346
410
  if (!url.startsWith("https://")) {
347
411
  throw new Error(
348
412
  `Not a valid public URL (https://) provided for file (url: ${url}).`
@@ -361,6 +425,7 @@ async function createFile(url, altText, filename) {
361
425
  const result = await fetchShopifyGraphql({
362
426
  query: mutation,
363
427
  variables,
428
+ retries,
364
429
  dataExtractor: (data) => {
365
430
  if (!data.fileCreate) {
366
431
  throw new Error("GraphQL response missing 'fileCreate' field");
@@ -397,7 +462,7 @@ var mutation2 = gql`#graphql
397
462
  }
398
463
  }
399
464
  `;
400
- async function createMetaobjectDefinition(input) {
465
+ async function createMetaobjectDefinition(input, retries = 0) {
401
466
  logger.debug(`Creating metaobject definition with type: ${input.type}`);
402
467
  const variables = {
403
468
  definition: {
@@ -411,6 +476,7 @@ async function createMetaobjectDefinition(input) {
411
476
  const result = await fetchShopifyGraphql({
412
477
  query: mutation2,
413
478
  variables,
479
+ retries,
414
480
  dataExtractor: (data) => {
415
481
  if (!data.metaobjectDefinitionCreate) {
416
482
  throw new Error(
@@ -471,7 +537,7 @@ function toGid(id, type) {
471
537
  }
472
538
  return `gid://shopify/${type}/${id}`;
473
539
  }
474
- async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}) {
540
+ async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}, retries = 0) {
475
541
  const {
476
542
  trackingNumber,
477
543
  carrier,
@@ -505,6 +571,7 @@ async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems,
505
571
  const result = await fetchShopifyGraphql({
506
572
  query: mutation3,
507
573
  variables,
574
+ retries,
508
575
  dataExtractor: (data) => {
509
576
  if (!data.fulfillmentCreate) {
510
577
  throw new Error("GraphQL response missing 'fulfillmentCreate' field");
@@ -553,7 +620,7 @@ var queryFulfillmentTrackingIds = gql`#graphql
553
620
  `;
554
621
 
555
622
  // src/queries/fulfillments/getFulfillmentTrackingIds.ts
556
- async function getFulfillmentTrackingIds(id) {
623
+ async function getFulfillmentTrackingIds(id, retries = 3) {
557
624
  const gid = typeof id === "string" ? id : convertIdIntoGid(
558
625
  typeof id === "number" ? BigInt(id) : id,
559
626
  "Fulfillment"
@@ -561,7 +628,8 @@ async function getFulfillmentTrackingIds(id) {
561
628
  const variables = { id: gid };
562
629
  const response = await fetchShopifyGraphql({
563
630
  query: queryFulfillmentTrackingIds,
564
- variables
631
+ variables,
632
+ retries
565
633
  });
566
634
  if (!response.fulfillment) {
567
635
  logger.debug(`No fulfillment found with ID: ${id}`);
@@ -602,7 +670,7 @@ var mutation4 = gql`#graphql
602
670
  }
603
671
  }
604
672
  `;
605
- async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false) {
673
+ async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false, retries = 1) {
606
674
  const fulfillmentGid = typeof fulfillmentId === "string" ? fulfillmentId : convertIdIntoGid(
607
675
  typeof fulfillmentId === "number" ? BigInt(fulfillmentId) : fulfillmentId,
608
676
  "Fulfillment"
@@ -624,6 +692,7 @@ async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCu
624
692
  const result = await fetchShopifyGraphql({
625
693
  query: mutation4,
626
694
  variables,
695
+ retries,
627
696
  dataExtractor: (data) => {
628
697
  if (!data.fulfillmentTrackingInfoUpdate) {
629
698
  throw new Error(
@@ -655,7 +724,7 @@ var mutation5 = gql`#graphql
655
724
  mutation orderCancel($orderId: ID!) {
656
725
  orderCancel(
657
726
  orderId: $orderId
658
- refund: true
727
+ refundMethod: { originalPaymentMethodsRefund: true }
659
728
  restock: false
660
729
  reason: CUSTOMER
661
730
  notifyCustomer: true
@@ -668,7 +737,7 @@ var mutation5 = gql`#graphql
668
737
  }
669
738
  }
670
739
  `;
671
- async function cancelOrderById(orderId) {
740
+ async function cancelOrderById(orderId, retries = 0) {
672
741
  const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
673
742
  typeof orderId === "number" ? BigInt(orderId) : orderId,
674
743
  "Order"
@@ -678,6 +747,7 @@ async function cancelOrderById(orderId) {
678
747
  await fetchShopifyGraphql({
679
748
  query: mutation5,
680
749
  variables,
750
+ retries,
681
751
  dataExtractor: (data) => {
682
752
  if (!data.orderCancel) {
683
753
  throw new Error("GraphQL response missing 'orderCancel' field");
@@ -722,7 +792,7 @@ function toGid2(id, type) {
722
792
  }
723
793
  return `gid://shopify/${type}/${id}`;
724
794
  }
725
- async function createRefund(orderId, options = {}) {
795
+ async function createRefund(orderId, options = {}, retries = 0) {
726
796
  const { currency, note, notify, refundLineItems, shipping, transactions } = options;
727
797
  const orderGid = toGid2(orderId, "Order");
728
798
  logger.debug(`Creating refund for order ${orderGid}`);
@@ -760,6 +830,7 @@ async function createRefund(orderId, options = {}) {
760
830
  const result = await fetchShopifyGraphql({
761
831
  query: mutation6,
762
832
  variables,
833
+ retries,
763
834
  dataExtractor: (data) => {
764
835
  if (!data.refundCreate) {
765
836
  throw new Error("GraphQL response missing 'refundCreate' field");
@@ -821,7 +892,7 @@ var mutation7 = gql`#graphql
821
892
  }
822
893
  }
823
894
  `;
824
- async function bulkUpdateProductVariants(productId, variants) {
895
+ async function bulkUpdateProductVariants(productId, variants, retries = 1) {
825
896
  logger.debug(
826
897
  `Bulk updating ${variants.length} variants for product ${productId}`
827
898
  );
@@ -832,6 +903,7 @@ async function bulkUpdateProductVariants(productId, variants) {
832
903
  const result = await fetchShopifyGraphql({
833
904
  query: mutation7,
834
905
  variables,
906
+ retries,
835
907
  dataExtractor: (data) => {
836
908
  if (!data.productVariantsBulkUpdate) {
837
909
  throw new Error(
@@ -877,7 +949,7 @@ var mutation8 = gql`#graphql
877
949
  }
878
950
  }
879
951
  `;
880
- async function upsertMetaobject(input) {
952
+ async function upsertMetaobject(input, retries = 1) {
881
953
  const { type, handle, fields } = input;
882
954
  logger.debug(`Upserting metaobject type=${type} handle=${handle}`);
883
955
  const variables = {
@@ -887,6 +959,7 @@ async function upsertMetaobject(input) {
887
959
  const response = await fetchShopifyGraphql({
888
960
  query: mutation8,
889
961
  variables,
962
+ retries,
890
963
  dataExtractor: (data) => {
891
964
  if (!data.metaobjectUpsert) {
892
965
  throw new Error("GraphQL response missing 'metaobjectUpsert' field");
@@ -1071,7 +1144,7 @@ function mapRestockType(restockType) {
1071
1144
  return "NO_RESTOCK" /* NoRestock */;
1072
1145
  }
1073
1146
  }
1074
- async function calculateRefund(orderId, options = {}) {
1147
+ async function calculateRefund(orderId, options = {}, retries = 3) {
1075
1148
  const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
1076
1149
  typeof orderId === "number" ? BigInt(orderId) : orderId,
1077
1150
  "Order"
@@ -1090,7 +1163,8 @@ async function calculateRefund(orderId, options = {}) {
1090
1163
  };
1091
1164
  const response = await fetchShopifyGraphql({
1092
1165
  query: querySuggestedRefund,
1093
- variables
1166
+ variables,
1167
+ retries
1094
1168
  });
1095
1169
  if (!response.order?.suggestedRefund) {
1096
1170
  logger.debug(`No refund suggestion available for order: ${orderId}`);
@@ -1333,20 +1407,23 @@ var GetLeanOrderByIdReturn = import_zod3.default.object({
1333
1407
  fulfillmentStatus: import_zod3.default.string().nullable(),
1334
1408
  shippingAddress: AddressSchema
1335
1409
  });
1336
- async function getOrderById(id, detailLevel = "lean") {
1410
+ async function getOrderById(id, detailLevelOrRetries, retries) {
1411
+ const detailLevel = typeof detailLevelOrRetries === "string" ? detailLevelOrRetries : "lean";
1412
+ const resolvedRetries = typeof detailLevelOrRetries === "number" ? detailLevelOrRetries : retries ?? 3;
1337
1413
  const bigIntId = typeof id === "number" ? BigInt(id) : id;
1338
1414
  if (detailLevel === "lean") {
1339
- return getLeanOrderById(bigIntId);
1415
+ return getLeanOrderById(bigIntId, resolvedRetries);
1340
1416
  }
1341
- return getFullOrderById(bigIntId);
1417
+ return getFullOrderById(bigIntId, resolvedRetries);
1342
1418
  }
1343
- async function getLeanOrderById(id) {
1419
+ async function getLeanOrderById(id, retries = 3) {
1344
1420
  const variables = {
1345
1421
  id: convertIdIntoGid(id, "Order")
1346
1422
  };
1347
1423
  const response = await fetchShopifyGraphql({
1348
1424
  query: queryOrderById,
1349
- variables
1425
+ variables,
1426
+ retries
1350
1427
  });
1351
1428
  if (!response.order) {
1352
1429
  logger.debug(`No order found with ID: ${id}`);
@@ -1386,13 +1463,14 @@ async function getLeanOrderById(id) {
1386
1463
  };
1387
1464
  return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn);
1388
1465
  }
1389
- async function getFullOrderById(id) {
1466
+ async function getFullOrderById(id, retries = 3) {
1390
1467
  const variables = {
1391
1468
  id: convertIdIntoGid(id, "Order")
1392
1469
  };
1393
1470
  const response = await fetchShopifyGraphql({
1394
1471
  query: queryOrderByIdFull,
1395
- variables
1472
+ variables,
1473
+ retries
1396
1474
  });
1397
1475
  if (!response.order) {
1398
1476
  logger.debug(`No order found with ID: ${id}`);
@@ -1757,13 +1835,15 @@ var GetLeanOrderByNameReturn = import_zod5.default.object({
1757
1835
  financialStatus: import_zod5.default.string().nullable(),
1758
1836
  fulfillmentStatus: import_zod5.default.string().nullable()
1759
1837
  });
1760
- async function getOrderByName(orderName, detailLevel = "lean") {
1838
+ async function getOrderByName(orderName, detailLevelOrRetries, retries) {
1839
+ const detailLevel = typeof detailLevelOrRetries === "string" ? detailLevelOrRetries : "lean";
1840
+ const resolvedRetries = typeof detailLevelOrRetries === "number" ? detailLevelOrRetries : retries ?? 3;
1761
1841
  if (detailLevel === "lean") {
1762
- return getLeanOrderByName(orderName);
1842
+ return getLeanOrderByName(orderName, resolvedRetries);
1763
1843
  }
1764
- return getFullOrderByName(orderName);
1844
+ return getFullOrderByName(orderName, resolvedRetries);
1765
1845
  }
1766
- async function getLeanOrderByName(orderName) {
1846
+ async function getLeanOrderByName(orderName, retries = 3) {
1767
1847
  const variables = {
1768
1848
  first: 1,
1769
1849
  queryFilter: `name:${orderName}`
@@ -1784,7 +1864,8 @@ async function getLeanOrderByName(orderName) {
1784
1864
  nodes
1785
1865
  };
1786
1866
  },
1787
- fetchAllPages: false
1867
+ fetchAllPages: false,
1868
+ retries
1788
1869
  });
1789
1870
  const order = extractedNodes[0];
1790
1871
  if (!order) {
@@ -1810,7 +1891,7 @@ async function getLeanOrderByName(orderName) {
1810
1891
  };
1811
1892
  return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn);
1812
1893
  }
1813
- async function getFullOrderByName(orderName) {
1894
+ async function getFullOrderByName(orderName, retries = 3) {
1814
1895
  const variables = {
1815
1896
  first: 1,
1816
1897
  queryFilter: `name:${orderName}`
@@ -1831,7 +1912,8 @@ async function getFullOrderByName(orderName) {
1831
1912
  nodes
1832
1913
  };
1833
1914
  },
1834
- fetchAllPages: false
1915
+ fetchAllPages: false,
1916
+ retries
1835
1917
  });
1836
1918
  if (extractedNodes.length === 0) {
1837
1919
  logger.debug(`No order found with name: ${orderName}`);
@@ -1861,14 +1943,15 @@ var queryOrderCancellationInfoByName = gql`#graphql
1861
1943
  `;
1862
1944
 
1863
1945
  // src/queries/orders/getOrderCancellationInfo.ts
1864
- async function getOrderCancellationInfoByName(orderName) {
1946
+ async function getOrderCancellationInfoByName(orderName, retries = 3) {
1865
1947
  const variables = {
1866
1948
  first: 1,
1867
1949
  queryFilter: `name:${orderName}`
1868
1950
  };
1869
1951
  const response = await fetchShopifyGraphql({
1870
1952
  query: queryOrderCancellationInfoByName,
1871
- variables
1953
+ variables,
1954
+ retries
1872
1955
  });
1873
1956
  if (!response.orders) {
1874
1957
  throw new Error(
@@ -1901,7 +1984,7 @@ var GetLeanProductVariantsReturn = import_zod7.default.array(
1901
1984
  status: import_zod7.default.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
1902
1985
  })
1903
1986
  );
1904
- async function getLeanProductVariants(skus, options) {
1987
+ async function getLeanProductVariants(skus, options, retries = 3) {
1905
1988
  const queryGql = gql`#graphql
1906
1989
  query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {
1907
1990
  productVariants(first: $first, after: $after, query: $queryFilter) {
@@ -1954,7 +2037,8 @@ async function getLeanProductVariants(skus, options) {
1954
2037
  pageInfo: pageData.productVariants.pageInfo
1955
2038
  };
1956
2039
  },
1957
- fetchAllPages: true
2040
+ fetchAllPages: true,
2041
+ retries
1958
2042
  });
1959
2043
  const allVariants = extractedNodes.flatMap((v) => {
1960
2044
  if (v.sku) {
@@ -1989,7 +2073,7 @@ var GetProductVariantsBySkusReturn = import_zod9.default.array(
1989
2073
  status: import_zod9.default.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
1990
2074
  })
1991
2075
  );
1992
- async function getProductVariantsBySkus(skus, options) {
2076
+ async function getProductVariantsBySkus(skus, options, retries = 3) {
1993
2077
  if (skus.length === 0) {
1994
2078
  return [];
1995
2079
  }
@@ -2039,7 +2123,8 @@ async function getProductVariantsBySkus(skus, options) {
2039
2123
  pageInfo: pageData.productVariants.pageInfo
2040
2124
  };
2041
2125
  },
2042
- fetchAllPages: true
2126
+ fetchAllPages: true,
2127
+ retries
2043
2128
  });
2044
2129
  const allVariants = extractedNodes.flatMap((v) => {
2045
2130
  if (!v.sku) {
@@ -2114,7 +2199,7 @@ var ProductVariantSchema = import_zod11.default.object({
2114
2199
  combinedListingRole: import_zod11.default.enum(["PARENT", "CHILD"]).nullable()
2115
2200
  });
2116
2201
  var GetAllProductVariantsReturn = import_zod11.default.array(ProductVariantSchema);
2117
- async function getAllProductVariants() {
2202
+ async function getAllProductVariants(retries = 3) {
2118
2203
  const initialVariables = { first: 250 };
2119
2204
  const extractedNodes = await fetchShopifyGraphql({
2120
2205
  query: queryAllProductVariants,
@@ -2133,7 +2218,8 @@ async function getAllProductVariants() {
2133
2218
  pageInfo: pageData.productVariants.pageInfo
2134
2219
  };
2135
2220
  },
2136
- fetchAllPages: true
2221
+ fetchAllPages: true,
2222
+ retries
2137
2223
  });
2138
2224
  logger.debug(`Fetched ${extractedNodes.length} product variants from Shopify`);
2139
2225
  const allVariants = extractedNodes.map((v) => {
@@ -2166,6 +2252,10 @@ var queryOrderPaymentDetails = gql`#graphql
2166
2252
  amount
2167
2253
  currencyCode
2168
2254
  }
2255
+ presentmentMoney {
2256
+ amount
2257
+ currencyCode
2258
+ }
2169
2259
  }
2170
2260
  createdAt
2171
2261
  gateway
@@ -2178,13 +2268,14 @@ var queryOrderPaymentDetails = gql`#graphql
2178
2268
  `;
2179
2269
 
2180
2270
  // src/queries/orders/getOrderPaymentDetails.ts
2181
- async function getOrderPaymentDetailsById(id) {
2271
+ async function getOrderPaymentDetailsById(id, retries = 3) {
2182
2272
  const variables = {
2183
2273
  id: convertIdIntoGid(id, "Order")
2184
2274
  };
2185
2275
  const response = await fetchShopifyGraphql({
2186
2276
  query: queryOrderPaymentDetails,
2187
- variables
2277
+ variables,
2278
+ retries
2188
2279
  });
2189
2280
  if (!response.order) {
2190
2281
  logger.debug(`No order found with ID: ${id}`);
@@ -2254,7 +2345,7 @@ var queryFulfillmentById = gql`#graphql
2254
2345
  `;
2255
2346
 
2256
2347
  // src/queries/fulfillments/getFulfillmentById.ts
2257
- async function getFulfillmentById(id) {
2348
+ async function getFulfillmentById(id, retries = 3) {
2258
2349
  const gid = typeof id === "string" ? id : convertIdIntoGid(
2259
2350
  typeof id === "number" ? BigInt(id) : id,
2260
2351
  "Fulfillment"
@@ -2262,7 +2353,8 @@ async function getFulfillmentById(id) {
2262
2353
  const variables = { id: gid };
2263
2354
  const response = await fetchShopifyGraphql({
2264
2355
  query: queryFulfillmentById,
2265
- variables
2356
+ variables,
2357
+ retries
2266
2358
  });
2267
2359
  if (!response.fulfillment) {
2268
2360
  logger.debug(`No fulfillment found with ID: ${id}`);
@@ -2300,7 +2392,7 @@ var queryFulfillmentOrdersByOrderId = gql`#graphql
2300
2392
  `;
2301
2393
 
2302
2394
  // src/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.ts
2303
- async function getFulfillmentOrdersByOrderId(orderId) {
2395
+ async function getFulfillmentOrdersByOrderId(orderId, retries = 3) {
2304
2396
  const gid = typeof orderId === "string" ? orderId : convertIdIntoGid(
2305
2397
  typeof orderId === "number" ? BigInt(orderId) : orderId,
2306
2398
  "Order"
@@ -2308,7 +2400,8 @@ async function getFulfillmentOrdersByOrderId(orderId) {
2308
2400
  const variables = { orderId: gid };
2309
2401
  const response = await fetchShopifyGraphql({
2310
2402
  query: queryFulfillmentOrdersByOrderId,
2311
- variables
2403
+ variables,
2404
+ retries
2312
2405
  });
2313
2406
  if (!response.order) {
2314
2407
  logger.debug(`No order found with ID: ${orderId}`);
@@ -2359,14 +2452,15 @@ var queryCustomersByEmail = gql`#graphql
2359
2452
  `;
2360
2453
 
2361
2454
  // src/queries/customers/getCustomersByEmail.ts
2362
- async function getCustomersByEmail(email, limit = 10) {
2455
+ async function getCustomersByEmail(email, limit = 10, retries = 3) {
2363
2456
  const variables = {
2364
2457
  query: `email:${email}`,
2365
2458
  first: limit
2366
2459
  };
2367
2460
  const response = await fetchShopifyGraphql({
2368
2461
  query: queryCustomersByEmail,
2369
- variables
2462
+ variables,
2463
+ retries
2370
2464
  });
2371
2465
  const customers = response.customers.edges.map((edge) => edge.node);
2372
2466
  logger.debug(`Found ${customers.length} customers for email: ${email}`);
@@ -2404,7 +2498,7 @@ var queryCustomerSegmentMembersWithStatistics = gql`#graphql
2404
2498
  `;
2405
2499
 
2406
2500
  // src/queries/customerSegments/getCustomerSegmentMembers.ts
2407
- async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250) {
2501
+ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250, retries = 3) {
2408
2502
  const variables = {
2409
2503
  query,
2410
2504
  first: limit,
@@ -2412,7 +2506,8 @@ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit =
2412
2506
  };
2413
2507
  const response = await fetchShopifyGraphql({
2414
2508
  query: queryCustomerSegmentMembersWithStatistics,
2415
- variables
2509
+ variables,
2510
+ retries
2416
2511
  });
2417
2512
  const members = response.customerSegmentMembers.edges.map((edge) => edge.node);
2418
2513
  logger.debug(`Found ${members.length} customer segment members`);
@@ -2465,7 +2560,7 @@ var queryOrdersByCustomerId = gql`#graphql
2465
2560
  `;
2466
2561
 
2467
2562
  // src/queries/orders/getOrdersByCustomerId.ts
2468
- async function getOrdersByCustomerId(customerId, limit = 250) {
2563
+ async function getOrdersByCustomerId(customerId, limit = 250, retries = 3) {
2469
2564
  const bigIntId = typeof customerId === "number" ? BigInt(customerId) : customerId;
2470
2565
  const gid = convertIdIntoGid(bigIntId, "Customer");
2471
2566
  const variables = {
@@ -2474,7 +2569,8 @@ async function getOrdersByCustomerId(customerId, limit = 250) {
2474
2569
  };
2475
2570
  const response = await fetchShopifyGraphql({
2476
2571
  query: queryOrdersByCustomerId,
2477
- variables
2572
+ variables,
2573
+ retries
2478
2574
  });
2479
2575
  if (!response.customer) {
2480
2576
  logger.debug(`No customer found with ID: ${customerId}`);
@@ -2510,11 +2606,12 @@ var queryMetaobjectByHandle = gql`#graphql
2510
2606
  `;
2511
2607
 
2512
2608
  // src/queries/metaobjects/getMetaobjectByHandle.ts
2513
- async function getMetaobjectByHandle(handle) {
2609
+ async function getMetaobjectByHandle(handle, retries = 3) {
2514
2610
  const variables = { handle };
2515
2611
  const response = await fetchShopifyGraphql({
2516
2612
  query: queryMetaobjectByHandle,
2517
- variables
2613
+ variables,
2614
+ retries
2518
2615
  });
2519
2616
  if (!response.metaobjectByHandle) {
2520
2617
  logger.debug(
@@ -2550,6 +2647,7 @@ async function getMetaobjectByHandle(handle) {
2550
2647
  getOrderPaymentDetailsById,
2551
2648
  getOrdersByCustomerId,
2552
2649
  getProductVariantsBySkus,
2650
+ isRetryableError,
2553
2651
  parseGid,
2554
2652
  updateFulfillmentTracking,
2555
2653
  upsertMetaobject