@ehrenkind/shopify-lib 0.7.0 → 0.7.2

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
@@ -57,7 +57,7 @@ import { z } from "zod";
57
57
 
58
58
  // src/utils/apiVersion.ts
59
59
  import { ApiVersion } from "@shopify/shopify-api";
60
- var SHOPIFY_API_VERSION = ApiVersion.April25;
60
+ var SHOPIFY_API_VERSION = ApiVersion.July25;
61
61
 
62
62
  // src/utils/shopifyClient.ts
63
63
  dotenv.config();
@@ -130,6 +130,38 @@ try {
130
130
  }
131
131
 
132
132
  // src/utils/shopifyFetch.ts
133
+ var RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
134
+ "ECONNRESET",
135
+ "ETIMEDOUT",
136
+ "ECONNREFUSED",
137
+ "ENOTFOUND",
138
+ "EPIPE",
139
+ "EAI_AGAIN",
140
+ "EHOSTUNREACH",
141
+ "ENETUNREACH",
142
+ // undici (Node 18+ fetch) error codes
143
+ "UND_ERR_SOCKET",
144
+ "UND_ERR_CONNECT_TIMEOUT",
145
+ "UND_ERR_HEADERS_TIMEOUT",
146
+ "UND_ERR_BODY_TIMEOUT"
147
+ ]);
148
+ function hasRetryableCode(value) {
149
+ if (!value || typeof value !== "object") return false;
150
+ const code = value.code;
151
+ return typeof code === "string" && RETRYABLE_ERROR_CODES.has(code);
152
+ }
153
+ function isRetryableError(error) {
154
+ if (!(error instanceof Error)) return false;
155
+ if (hasRetryableCode(error)) return true;
156
+ if (error instanceof TypeError && error.message.includes("fetch failed")) {
157
+ return true;
158
+ }
159
+ if (hasRetryableCode(error.cause)) return true;
160
+ return false;
161
+ }
162
+ function sleep(ms) {
163
+ return new Promise((resolve) => setTimeout(resolve, ms));
164
+ }
133
165
  function convertIdIntoGid(id, type) {
134
166
  return `gid://shopify/${type}/${id}`;
135
167
  }
@@ -146,16 +178,25 @@ async function fetchShopifyGraphql(params) {
146
178
  query,
147
179
  variables: initialVariables,
148
180
  dataExtractor,
149
- fetchAllPages = false
181
+ fetchAllPages = false,
182
+ retries = 0
150
183
  } = params;
151
184
  let currentVariables = { ...initialVariables };
152
185
  if (!dataExtractor) {
153
- return makeRequest(query, currentVariables);
186
+ return makeRequest(
187
+ query,
188
+ currentVariables,
189
+ retries
190
+ );
154
191
  }
155
192
  const allNodes = [];
156
193
  let hasNextLoop = true;
157
194
  do {
158
- const response = await makeRequest(query, currentVariables);
195
+ const response = await makeRequest(
196
+ query,
197
+ currentVariables,
198
+ retries
199
+ );
159
200
  const { nodes, pageInfo, userErrors } = dataExtractor(response);
160
201
  if (Array.isArray(userErrors) && userErrors.length > 0) {
161
202
  const errorMessages = userErrors.map((e) => e.message || JSON.stringify(e)).join("\n");
@@ -176,33 +217,53 @@ async function fetchShopifyGraphql(params) {
176
217
  } while (hasNextLoop);
177
218
  return allNodes;
178
219
  }
179
- async function makeRequest(query, variables) {
180
- const response = await shopifyGraphqlClient.request(query, {
181
- variables
182
- });
183
- if (response.errors) {
184
- let errorMessages = "GraphQL query failed.";
185
- const errors = response.errors;
186
- if (Array.isArray(errors)) {
187
- errorMessages = errors.map((e) => e.message || JSON.stringify(e)).join("\n");
188
- } else if (typeof errors === "object" && errors !== null && "message" in errors) {
189
- errorMessages = errors.message || JSON.stringify(errors);
190
- } else if (typeof errors === "string") {
191
- errorMessages = errors;
192
- } else {
193
- errorMessages = JSON.stringify(errors);
220
+ async function makeRequest(query, variables, retries = 0) {
221
+ const maxRetries = Number.isFinite(retries) ? Math.max(0, Math.floor(retries)) : 0;
222
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
223
+ try {
224
+ const response = await shopifyGraphqlClient.request(query, {
225
+ variables
226
+ });
227
+ if (response.errors) {
228
+ let errorMessages = "GraphQL query failed.";
229
+ const errors = response.errors;
230
+ if (Array.isArray(errors)) {
231
+ errorMessages = errors.map((e) => e.message || JSON.stringify(e)).join("\n");
232
+ } else if (typeof errors === "object" && errors !== null && "message" in errors) {
233
+ errorMessages = errors.message || JSON.stringify(errors);
234
+ } else if (typeof errors === "string") {
235
+ errorMessages = errors;
236
+ } else {
237
+ errorMessages = JSON.stringify(errors);
238
+ }
239
+ logger.error("GraphQL query failed:", errorMessages);
240
+ throw new Error(`GraphQL errors: ${errorMessages}`);
241
+ }
242
+ if (!response.data) {
243
+ throw new Error("No data in Shopify API response");
244
+ }
245
+ return response.data;
246
+ } catch (error) {
247
+ if (attempt < maxRetries && isRetryableError(error)) {
248
+ const base = Math.min(1e3 * 2 ** attempt, 1e4);
249
+ const jitter = base * 0.2 * (Math.random() * 2 - 1);
250
+ const delay = Math.max(0, Math.round(base + jitter));
251
+ const totalAttempts = maxRetries + 1;
252
+ logger.warn(
253
+ `Transient error (attempt ${attempt + 1}/${totalAttempts}), retrying in ${delay}ms:`,
254
+ error.message
255
+ );
256
+ await sleep(delay);
257
+ continue;
258
+ }
259
+ throw error;
194
260
  }
195
- logger.error("GraphQL query failed:", errorMessages);
196
- throw new Error(`GraphQL errors: ${errorMessages}`);
197
261
  }
198
- if (!response.data) {
199
- throw new Error("No data in Shopify API response");
200
- }
201
- return response.data;
262
+ throw new Error("Unexpected: retry loop exited without result");
202
263
  }
203
264
 
204
265
  // src/mutations/customers/deleteCustomerById.ts
205
- async function deleteCustomerById(customerId) {
266
+ async function deleteCustomerById(customerId, retries = 1) {
206
267
  const mutation9 = gql`#graphql
207
268
  mutation customerDelete($input: CustomerDeleteInput!) {
208
269
  customerDelete(input: $input) {
@@ -220,6 +281,7 @@ async function deleteCustomerById(customerId) {
220
281
  const response = await fetchShopifyGraphql({
221
282
  query: mutation9,
222
283
  variables,
284
+ retries,
223
285
  dataExtractor: (data) => {
224
286
  if (!data.customerDelete) {
225
287
  throw new Error("GraphQL response missing 'customerDelete' field");
@@ -236,7 +298,7 @@ async function deleteCustomerById(customerId) {
236
298
  }
237
299
 
238
300
  // src/mutations/files/deleteFilesByIds.ts
239
- async function deleteFilesByIds(fileIds) {
301
+ async function deleteFilesByIds(fileIds, retries = 1) {
240
302
  if (fileIds.length === 0) {
241
303
  return [];
242
304
  }
@@ -256,6 +318,7 @@ async function deleteFilesByIds(fileIds) {
256
318
  const response = await fetchShopifyGraphql({
257
319
  query: mutation9,
258
320
  variables,
321
+ retries,
259
322
  dataExtractor: (data) => {
260
323
  if (!data.fileDelete) {
261
324
  throw new Error("GraphQL response missing 'fileDelete' field");
@@ -284,7 +347,7 @@ var mutation = gql`#graphql
284
347
  }
285
348
  }
286
349
  `;
287
- async function createFile(url, altText, filename) {
350
+ async function createFile(url, altText, filename, retries = 0) {
288
351
  if (!url.startsWith("https://")) {
289
352
  throw new Error(
290
353
  `Not a valid public URL (https://) provided for file (url: ${url}).`
@@ -303,6 +366,7 @@ async function createFile(url, altText, filename) {
303
366
  const result = await fetchShopifyGraphql({
304
367
  query: mutation,
305
368
  variables,
369
+ retries,
306
370
  dataExtractor: (data) => {
307
371
  if (!data.fileCreate) {
308
372
  throw new Error("GraphQL response missing 'fileCreate' field");
@@ -339,7 +403,7 @@ var mutation2 = gql`#graphql
339
403
  }
340
404
  }
341
405
  `;
342
- async function createMetaobjectDefinition(input) {
406
+ async function createMetaobjectDefinition(input, retries = 0) {
343
407
  logger.debug(`Creating metaobject definition with type: ${input.type}`);
344
408
  const variables = {
345
409
  definition: {
@@ -353,6 +417,7 @@ async function createMetaobjectDefinition(input) {
353
417
  const result = await fetchShopifyGraphql({
354
418
  query: mutation2,
355
419
  variables,
420
+ retries,
356
421
  dataExtractor: (data) => {
357
422
  if (!data.metaobjectDefinitionCreate) {
358
423
  throw new Error(
@@ -413,7 +478,7 @@ function toGid(id, type) {
413
478
  }
414
479
  return `gid://shopify/${type}/${id}`;
415
480
  }
416
- async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}) {
481
+ async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}, retries = 0) {
417
482
  const {
418
483
  trackingNumber,
419
484
  carrier,
@@ -447,6 +512,7 @@ async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems,
447
512
  const result = await fetchShopifyGraphql({
448
513
  query: mutation3,
449
514
  variables,
515
+ retries,
450
516
  dataExtractor: (data) => {
451
517
  if (!data.fulfillmentCreate) {
452
518
  throw new Error("GraphQL response missing 'fulfillmentCreate' field");
@@ -495,7 +561,7 @@ var queryFulfillmentTrackingIds = gql`#graphql
495
561
  `;
496
562
 
497
563
  // src/queries/fulfillments/getFulfillmentTrackingIds.ts
498
- async function getFulfillmentTrackingIds(id) {
564
+ async function getFulfillmentTrackingIds(id, retries = 3) {
499
565
  const gid = typeof id === "string" ? id : convertIdIntoGid(
500
566
  typeof id === "number" ? BigInt(id) : id,
501
567
  "Fulfillment"
@@ -503,7 +569,8 @@ async function getFulfillmentTrackingIds(id) {
503
569
  const variables = { id: gid };
504
570
  const response = await fetchShopifyGraphql({
505
571
  query: queryFulfillmentTrackingIds,
506
- variables
572
+ variables,
573
+ retries
507
574
  });
508
575
  if (!response.fulfillment) {
509
576
  logger.debug(`No fulfillment found with ID: ${id}`);
@@ -544,7 +611,7 @@ var mutation4 = gql`#graphql
544
611
  }
545
612
  }
546
613
  `;
547
- async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false) {
614
+ async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false, retries = 1) {
548
615
  const fulfillmentGid = typeof fulfillmentId === "string" ? fulfillmentId : convertIdIntoGid(
549
616
  typeof fulfillmentId === "number" ? BigInt(fulfillmentId) : fulfillmentId,
550
617
  "Fulfillment"
@@ -566,6 +633,7 @@ async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCu
566
633
  const result = await fetchShopifyGraphql({
567
634
  query: mutation4,
568
635
  variables,
636
+ retries,
569
637
  dataExtractor: (data) => {
570
638
  if (!data.fulfillmentTrackingInfoUpdate) {
571
639
  throw new Error(
@@ -597,7 +665,7 @@ var mutation5 = gql`#graphql
597
665
  mutation orderCancel($orderId: ID!) {
598
666
  orderCancel(
599
667
  orderId: $orderId
600
- refund: true
668
+ refundMethod: { originalPaymentMethodsRefund: true }
601
669
  restock: false
602
670
  reason: CUSTOMER
603
671
  notifyCustomer: true
@@ -610,7 +678,7 @@ var mutation5 = gql`#graphql
610
678
  }
611
679
  }
612
680
  `;
613
- async function cancelOrderById(orderId) {
681
+ async function cancelOrderById(orderId, retries = 0) {
614
682
  const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
615
683
  typeof orderId === "number" ? BigInt(orderId) : orderId,
616
684
  "Order"
@@ -620,6 +688,7 @@ async function cancelOrderById(orderId) {
620
688
  await fetchShopifyGraphql({
621
689
  query: mutation5,
622
690
  variables,
691
+ retries,
623
692
  dataExtractor: (data) => {
624
693
  if (!data.orderCancel) {
625
694
  throw new Error("GraphQL response missing 'orderCancel' field");
@@ -664,7 +733,7 @@ function toGid2(id, type) {
664
733
  }
665
734
  return `gid://shopify/${type}/${id}`;
666
735
  }
667
- async function createRefund(orderId, options = {}) {
736
+ async function createRefund(orderId, options = {}, retries = 0) {
668
737
  const { currency, note, notify, refundLineItems, shipping, transactions } = options;
669
738
  const orderGid = toGid2(orderId, "Order");
670
739
  logger.debug(`Creating refund for order ${orderGid}`);
@@ -702,6 +771,7 @@ async function createRefund(orderId, options = {}) {
702
771
  const result = await fetchShopifyGraphql({
703
772
  query: mutation6,
704
773
  variables,
774
+ retries,
705
775
  dataExtractor: (data) => {
706
776
  if (!data.refundCreate) {
707
777
  throw new Error("GraphQL response missing 'refundCreate' field");
@@ -763,7 +833,7 @@ var mutation7 = gql`#graphql
763
833
  }
764
834
  }
765
835
  `;
766
- async function bulkUpdateProductVariants(productId, variants) {
836
+ async function bulkUpdateProductVariants(productId, variants, retries = 1) {
767
837
  logger.debug(
768
838
  `Bulk updating ${variants.length} variants for product ${productId}`
769
839
  );
@@ -774,6 +844,7 @@ async function bulkUpdateProductVariants(productId, variants) {
774
844
  const result = await fetchShopifyGraphql({
775
845
  query: mutation7,
776
846
  variables,
847
+ retries,
777
848
  dataExtractor: (data) => {
778
849
  if (!data.productVariantsBulkUpdate) {
779
850
  throw new Error(
@@ -819,7 +890,7 @@ var mutation8 = gql`#graphql
819
890
  }
820
891
  }
821
892
  `;
822
- async function upsertMetaobject(input) {
893
+ async function upsertMetaobject(input, retries = 1) {
823
894
  const { type, handle, fields } = input;
824
895
  logger.debug(`Upserting metaobject type=${type} handle=${handle}`);
825
896
  const variables = {
@@ -829,6 +900,7 @@ async function upsertMetaobject(input) {
829
900
  const response = await fetchShopifyGraphql({
830
901
  query: mutation8,
831
902
  variables,
903
+ retries,
832
904
  dataExtractor: (data) => {
833
905
  if (!data.metaobjectUpsert) {
834
906
  throw new Error("GraphQL response missing 'metaobjectUpsert' field");
@@ -1013,7 +1085,7 @@ function mapRestockType(restockType) {
1013
1085
  return "NO_RESTOCK" /* NoRestock */;
1014
1086
  }
1015
1087
  }
1016
- async function calculateRefund(orderId, options = {}) {
1088
+ async function calculateRefund(orderId, options = {}, retries = 3) {
1017
1089
  const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
1018
1090
  typeof orderId === "number" ? BigInt(orderId) : orderId,
1019
1091
  "Order"
@@ -1032,7 +1104,8 @@ async function calculateRefund(orderId, options = {}) {
1032
1104
  };
1033
1105
  const response = await fetchShopifyGraphql({
1034
1106
  query: querySuggestedRefund,
1035
- variables
1107
+ variables,
1108
+ retries
1036
1109
  });
1037
1110
  if (!response.order?.suggestedRefund) {
1038
1111
  logger.debug(`No refund suggestion available for order: ${orderId}`);
@@ -1172,6 +1245,12 @@ var queryOrderByIdFull = gql`#graphql
1172
1245
  height
1173
1246
  altText
1174
1247
  }
1248
+ lineItemGroup {
1249
+ id
1250
+ title
1251
+ quantity
1252
+ variantSku
1253
+ }
1175
1254
  }
1176
1255
  }
1177
1256
  }
@@ -1269,20 +1348,23 @@ var GetLeanOrderByIdReturn = z3.object({
1269
1348
  fulfillmentStatus: z3.string().nullable(),
1270
1349
  shippingAddress: AddressSchema
1271
1350
  });
1272
- async function getOrderById(id, detailLevel = "lean") {
1351
+ async function getOrderById(id, detailLevelOrRetries, retries) {
1352
+ const detailLevel = typeof detailLevelOrRetries === "string" ? detailLevelOrRetries : "lean";
1353
+ const resolvedRetries = typeof detailLevelOrRetries === "number" ? detailLevelOrRetries : retries ?? 3;
1273
1354
  const bigIntId = typeof id === "number" ? BigInt(id) : id;
1274
1355
  if (detailLevel === "lean") {
1275
- return getLeanOrderById(bigIntId);
1356
+ return getLeanOrderById(bigIntId, resolvedRetries);
1276
1357
  }
1277
- return getFullOrderById(bigIntId);
1358
+ return getFullOrderById(bigIntId, resolvedRetries);
1278
1359
  }
1279
- async function getLeanOrderById(id) {
1360
+ async function getLeanOrderById(id, retries = 3) {
1280
1361
  const variables = {
1281
1362
  id: convertIdIntoGid(id, "Order")
1282
1363
  };
1283
1364
  const response = await fetchShopifyGraphql({
1284
1365
  query: queryOrderById,
1285
- variables
1366
+ variables,
1367
+ retries
1286
1368
  });
1287
1369
  if (!response.order) {
1288
1370
  logger.debug(`No order found with ID: ${id}`);
@@ -1322,13 +1404,14 @@ async function getLeanOrderById(id) {
1322
1404
  };
1323
1405
  return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn);
1324
1406
  }
1325
- async function getFullOrderById(id) {
1407
+ async function getFullOrderById(id, retries = 3) {
1326
1408
  const variables = {
1327
1409
  id: convertIdIntoGid(id, "Order")
1328
1410
  };
1329
1411
  const response = await fetchShopifyGraphql({
1330
1412
  query: queryOrderByIdFull,
1331
- variables
1413
+ variables,
1414
+ retries
1332
1415
  });
1333
1416
  if (!response.order) {
1334
1417
  logger.debug(`No order found with ID: ${id}`);
@@ -1693,13 +1776,15 @@ var GetLeanOrderByNameReturn = z4.object({
1693
1776
  financialStatus: z4.string().nullable(),
1694
1777
  fulfillmentStatus: z4.string().nullable()
1695
1778
  });
1696
- async function getOrderByName(orderName, detailLevel = "lean") {
1779
+ async function getOrderByName(orderName, detailLevelOrRetries, retries) {
1780
+ const detailLevel = typeof detailLevelOrRetries === "string" ? detailLevelOrRetries : "lean";
1781
+ const resolvedRetries = typeof detailLevelOrRetries === "number" ? detailLevelOrRetries : retries ?? 3;
1697
1782
  if (detailLevel === "lean") {
1698
- return getLeanOrderByName(orderName);
1783
+ return getLeanOrderByName(orderName, resolvedRetries);
1699
1784
  }
1700
- return getFullOrderByName(orderName);
1785
+ return getFullOrderByName(orderName, resolvedRetries);
1701
1786
  }
1702
- async function getLeanOrderByName(orderName) {
1787
+ async function getLeanOrderByName(orderName, retries = 3) {
1703
1788
  const variables = {
1704
1789
  first: 1,
1705
1790
  queryFilter: `name:${orderName}`
@@ -1720,7 +1805,8 @@ async function getLeanOrderByName(orderName) {
1720
1805
  nodes
1721
1806
  };
1722
1807
  },
1723
- fetchAllPages: false
1808
+ fetchAllPages: false,
1809
+ retries
1724
1810
  });
1725
1811
  const order = extractedNodes[0];
1726
1812
  if (!order) {
@@ -1746,7 +1832,7 @@ async function getLeanOrderByName(orderName) {
1746
1832
  };
1747
1833
  return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn);
1748
1834
  }
1749
- async function getFullOrderByName(orderName) {
1835
+ async function getFullOrderByName(orderName, retries = 3) {
1750
1836
  const variables = {
1751
1837
  first: 1,
1752
1838
  queryFilter: `name:${orderName}`
@@ -1767,7 +1853,8 @@ async function getFullOrderByName(orderName) {
1767
1853
  nodes
1768
1854
  };
1769
1855
  },
1770
- fetchAllPages: false
1856
+ fetchAllPages: false,
1857
+ retries
1771
1858
  });
1772
1859
  if (extractedNodes.length === 0) {
1773
1860
  logger.debug(`No order found with name: ${orderName}`);
@@ -1797,14 +1884,15 @@ var queryOrderCancellationInfoByName = gql`#graphql
1797
1884
  `;
1798
1885
 
1799
1886
  // src/queries/orders/getOrderCancellationInfo.ts
1800
- async function getOrderCancellationInfoByName(orderName) {
1887
+ async function getOrderCancellationInfoByName(orderName, retries = 3) {
1801
1888
  const variables = {
1802
1889
  first: 1,
1803
1890
  queryFilter: `name:${orderName}`
1804
1891
  };
1805
1892
  const response = await fetchShopifyGraphql({
1806
1893
  query: queryOrderCancellationInfoByName,
1807
- variables
1894
+ variables,
1895
+ retries
1808
1896
  });
1809
1897
  if (!response.orders) {
1810
1898
  throw new Error(
@@ -1837,7 +1925,7 @@ var GetLeanProductVariantsReturn = z5.array(
1837
1925
  status: z5.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
1838
1926
  })
1839
1927
  );
1840
- async function getLeanProductVariants(skus, options) {
1928
+ async function getLeanProductVariants(skus, options, retries = 3) {
1841
1929
  const queryGql = gql`#graphql
1842
1930
  query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {
1843
1931
  productVariants(first: $first, after: $after, query: $queryFilter) {
@@ -1890,7 +1978,8 @@ async function getLeanProductVariants(skus, options) {
1890
1978
  pageInfo: pageData.productVariants.pageInfo
1891
1979
  };
1892
1980
  },
1893
- fetchAllPages: true
1981
+ fetchAllPages: true,
1982
+ retries
1894
1983
  });
1895
1984
  const allVariants = extractedNodes.flatMap((v) => {
1896
1985
  if (v.sku) {
@@ -1925,7 +2014,7 @@ var GetProductVariantsBySkusReturn = z6.array(
1925
2014
  status: z6.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
1926
2015
  })
1927
2016
  );
1928
- async function getProductVariantsBySkus(skus, options) {
2017
+ async function getProductVariantsBySkus(skus, options, retries = 3) {
1929
2018
  if (skus.length === 0) {
1930
2019
  return [];
1931
2020
  }
@@ -1975,7 +2064,8 @@ async function getProductVariantsBySkus(skus, options) {
1975
2064
  pageInfo: pageData.productVariants.pageInfo
1976
2065
  };
1977
2066
  },
1978
- fetchAllPages: true
2067
+ fetchAllPages: true,
2068
+ retries
1979
2069
  });
1980
2070
  const allVariants = extractedNodes.flatMap((v) => {
1981
2071
  if (!v.sku) {
@@ -2050,7 +2140,7 @@ var ProductVariantSchema = z7.object({
2050
2140
  combinedListingRole: z7.enum(["PARENT", "CHILD"]).nullable()
2051
2141
  });
2052
2142
  var GetAllProductVariantsReturn = z7.array(ProductVariantSchema);
2053
- async function getAllProductVariants() {
2143
+ async function getAllProductVariants(retries = 3) {
2054
2144
  const initialVariables = { first: 250 };
2055
2145
  const extractedNodes = await fetchShopifyGraphql({
2056
2146
  query: queryAllProductVariants,
@@ -2069,7 +2159,8 @@ async function getAllProductVariants() {
2069
2159
  pageInfo: pageData.productVariants.pageInfo
2070
2160
  };
2071
2161
  },
2072
- fetchAllPages: true
2162
+ fetchAllPages: true,
2163
+ retries
2073
2164
  });
2074
2165
  logger.debug(`Fetched ${extractedNodes.length} product variants from Shopify`);
2075
2166
  const allVariants = extractedNodes.map((v) => {
@@ -2102,6 +2193,10 @@ var queryOrderPaymentDetails = gql`#graphql
2102
2193
  amount
2103
2194
  currencyCode
2104
2195
  }
2196
+ presentmentMoney {
2197
+ amount
2198
+ currencyCode
2199
+ }
2105
2200
  }
2106
2201
  createdAt
2107
2202
  gateway
@@ -2114,13 +2209,14 @@ var queryOrderPaymentDetails = gql`#graphql
2114
2209
  `;
2115
2210
 
2116
2211
  // src/queries/orders/getOrderPaymentDetails.ts
2117
- async function getOrderPaymentDetailsById(id) {
2212
+ async function getOrderPaymentDetailsById(id, retries = 3) {
2118
2213
  const variables = {
2119
2214
  id: convertIdIntoGid(id, "Order")
2120
2215
  };
2121
2216
  const response = await fetchShopifyGraphql({
2122
2217
  query: queryOrderPaymentDetails,
2123
- variables
2218
+ variables,
2219
+ retries
2124
2220
  });
2125
2221
  if (!response.order) {
2126
2222
  logger.debug(`No order found with ID: ${id}`);
@@ -2190,7 +2286,7 @@ var queryFulfillmentById = gql`#graphql
2190
2286
  `;
2191
2287
 
2192
2288
  // src/queries/fulfillments/getFulfillmentById.ts
2193
- async function getFulfillmentById(id) {
2289
+ async function getFulfillmentById(id, retries = 3) {
2194
2290
  const gid = typeof id === "string" ? id : convertIdIntoGid(
2195
2291
  typeof id === "number" ? BigInt(id) : id,
2196
2292
  "Fulfillment"
@@ -2198,7 +2294,8 @@ async function getFulfillmentById(id) {
2198
2294
  const variables = { id: gid };
2199
2295
  const response = await fetchShopifyGraphql({
2200
2296
  query: queryFulfillmentById,
2201
- variables
2297
+ variables,
2298
+ retries
2202
2299
  });
2203
2300
  if (!response.fulfillment) {
2204
2301
  logger.debug(`No fulfillment found with ID: ${id}`);
@@ -2236,7 +2333,7 @@ var queryFulfillmentOrdersByOrderId = gql`#graphql
2236
2333
  `;
2237
2334
 
2238
2335
  // src/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.ts
2239
- async function getFulfillmentOrdersByOrderId(orderId) {
2336
+ async function getFulfillmentOrdersByOrderId(orderId, retries = 3) {
2240
2337
  const gid = typeof orderId === "string" ? orderId : convertIdIntoGid(
2241
2338
  typeof orderId === "number" ? BigInt(orderId) : orderId,
2242
2339
  "Order"
@@ -2244,7 +2341,8 @@ async function getFulfillmentOrdersByOrderId(orderId) {
2244
2341
  const variables = { orderId: gid };
2245
2342
  const response = await fetchShopifyGraphql({
2246
2343
  query: queryFulfillmentOrdersByOrderId,
2247
- variables
2344
+ variables,
2345
+ retries
2248
2346
  });
2249
2347
  if (!response.order) {
2250
2348
  logger.debug(`No order found with ID: ${orderId}`);
@@ -2295,14 +2393,15 @@ var queryCustomersByEmail = gql`#graphql
2295
2393
  `;
2296
2394
 
2297
2395
  // src/queries/customers/getCustomersByEmail.ts
2298
- async function getCustomersByEmail(email, limit = 10) {
2396
+ async function getCustomersByEmail(email, limit = 10, retries = 3) {
2299
2397
  const variables = {
2300
2398
  query: `email:${email}`,
2301
2399
  first: limit
2302
2400
  };
2303
2401
  const response = await fetchShopifyGraphql({
2304
2402
  query: queryCustomersByEmail,
2305
- variables
2403
+ variables,
2404
+ retries
2306
2405
  });
2307
2406
  const customers = response.customers.edges.map((edge) => edge.node);
2308
2407
  logger.debug(`Found ${customers.length} customers for email: ${email}`);
@@ -2340,7 +2439,7 @@ var queryCustomerSegmentMembersWithStatistics = gql`#graphql
2340
2439
  `;
2341
2440
 
2342
2441
  // src/queries/customerSegments/getCustomerSegmentMembers.ts
2343
- async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250) {
2442
+ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250, retries = 3) {
2344
2443
  const variables = {
2345
2444
  query,
2346
2445
  first: limit,
@@ -2348,7 +2447,8 @@ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit =
2348
2447
  };
2349
2448
  const response = await fetchShopifyGraphql({
2350
2449
  query: queryCustomerSegmentMembersWithStatistics,
2351
- variables
2450
+ variables,
2451
+ retries
2352
2452
  });
2353
2453
  const members = response.customerSegmentMembers.edges.map((edge) => edge.node);
2354
2454
  logger.debug(`Found ${members.length} customer segment members`);
@@ -2401,7 +2501,7 @@ var queryOrdersByCustomerId = gql`#graphql
2401
2501
  `;
2402
2502
 
2403
2503
  // src/queries/orders/getOrdersByCustomerId.ts
2404
- async function getOrdersByCustomerId(customerId, limit = 250) {
2504
+ async function getOrdersByCustomerId(customerId, limit = 250, retries = 3) {
2405
2505
  const bigIntId = typeof customerId === "number" ? BigInt(customerId) : customerId;
2406
2506
  const gid = convertIdIntoGid(bigIntId, "Customer");
2407
2507
  const variables = {
@@ -2410,7 +2510,8 @@ async function getOrdersByCustomerId(customerId, limit = 250) {
2410
2510
  };
2411
2511
  const response = await fetchShopifyGraphql({
2412
2512
  query: queryOrdersByCustomerId,
2413
- variables
2513
+ variables,
2514
+ retries
2414
2515
  });
2415
2516
  if (!response.customer) {
2416
2517
  logger.debug(`No customer found with ID: ${customerId}`);
@@ -2446,11 +2547,12 @@ var queryMetaobjectByHandle = gql`#graphql
2446
2547
  `;
2447
2548
 
2448
2549
  // src/queries/metaobjects/getMetaobjectByHandle.ts
2449
- async function getMetaobjectByHandle(handle) {
2550
+ async function getMetaobjectByHandle(handle, retries = 3) {
2450
2551
  const variables = { handle };
2451
2552
  const response = await fetchShopifyGraphql({
2452
2553
  query: queryMetaobjectByHandle,
2453
- variables
2554
+ variables,
2555
+ retries
2454
2556
  });
2455
2557
  if (!response.metaobjectByHandle) {
2456
2558
  logger.debug(
@@ -2485,6 +2587,7 @@ export {
2485
2587
  getOrderPaymentDetailsById,
2486
2588
  getOrdersByCustomerId,
2487
2589
  getProductVariantsBySkus,
2590
+ isRetryableError,
2488
2591
  parseGid,
2489
2592
  updateFulfillmentTracking,
2490
2593
  upsertMetaobject