@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.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
- }
198
- if (!response.data) {
199
- throw new Error("No data in Shopify API response");
200
261
  }
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}`);
@@ -1275,20 +1348,23 @@ var GetLeanOrderByIdReturn = z3.object({
1275
1348
  fulfillmentStatus: z3.string().nullable(),
1276
1349
  shippingAddress: AddressSchema
1277
1350
  });
1278
- 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;
1279
1354
  const bigIntId = typeof id === "number" ? BigInt(id) : id;
1280
1355
  if (detailLevel === "lean") {
1281
- return getLeanOrderById(bigIntId);
1356
+ return getLeanOrderById(bigIntId, resolvedRetries);
1282
1357
  }
1283
- return getFullOrderById(bigIntId);
1358
+ return getFullOrderById(bigIntId, resolvedRetries);
1284
1359
  }
1285
- async function getLeanOrderById(id) {
1360
+ async function getLeanOrderById(id, retries = 3) {
1286
1361
  const variables = {
1287
1362
  id: convertIdIntoGid(id, "Order")
1288
1363
  };
1289
1364
  const response = await fetchShopifyGraphql({
1290
1365
  query: queryOrderById,
1291
- variables
1366
+ variables,
1367
+ retries
1292
1368
  });
1293
1369
  if (!response.order) {
1294
1370
  logger.debug(`No order found with ID: ${id}`);
@@ -1328,13 +1404,14 @@ async function getLeanOrderById(id) {
1328
1404
  };
1329
1405
  return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn);
1330
1406
  }
1331
- async function getFullOrderById(id) {
1407
+ async function getFullOrderById(id, retries = 3) {
1332
1408
  const variables = {
1333
1409
  id: convertIdIntoGid(id, "Order")
1334
1410
  };
1335
1411
  const response = await fetchShopifyGraphql({
1336
1412
  query: queryOrderByIdFull,
1337
- variables
1413
+ variables,
1414
+ retries
1338
1415
  });
1339
1416
  if (!response.order) {
1340
1417
  logger.debug(`No order found with ID: ${id}`);
@@ -1699,13 +1776,15 @@ var GetLeanOrderByNameReturn = z4.object({
1699
1776
  financialStatus: z4.string().nullable(),
1700
1777
  fulfillmentStatus: z4.string().nullable()
1701
1778
  });
1702
- 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;
1703
1782
  if (detailLevel === "lean") {
1704
- return getLeanOrderByName(orderName);
1783
+ return getLeanOrderByName(orderName, resolvedRetries);
1705
1784
  }
1706
- return getFullOrderByName(orderName);
1785
+ return getFullOrderByName(orderName, resolvedRetries);
1707
1786
  }
1708
- async function getLeanOrderByName(orderName) {
1787
+ async function getLeanOrderByName(orderName, retries = 3) {
1709
1788
  const variables = {
1710
1789
  first: 1,
1711
1790
  queryFilter: `name:${orderName}`
@@ -1726,7 +1805,8 @@ async function getLeanOrderByName(orderName) {
1726
1805
  nodes
1727
1806
  };
1728
1807
  },
1729
- fetchAllPages: false
1808
+ fetchAllPages: false,
1809
+ retries
1730
1810
  });
1731
1811
  const order = extractedNodes[0];
1732
1812
  if (!order) {
@@ -1752,7 +1832,7 @@ async function getLeanOrderByName(orderName) {
1752
1832
  };
1753
1833
  return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn);
1754
1834
  }
1755
- async function getFullOrderByName(orderName) {
1835
+ async function getFullOrderByName(orderName, retries = 3) {
1756
1836
  const variables = {
1757
1837
  first: 1,
1758
1838
  queryFilter: `name:${orderName}`
@@ -1773,7 +1853,8 @@ async function getFullOrderByName(orderName) {
1773
1853
  nodes
1774
1854
  };
1775
1855
  },
1776
- fetchAllPages: false
1856
+ fetchAllPages: false,
1857
+ retries
1777
1858
  });
1778
1859
  if (extractedNodes.length === 0) {
1779
1860
  logger.debug(`No order found with name: ${orderName}`);
@@ -1803,14 +1884,15 @@ var queryOrderCancellationInfoByName = gql`#graphql
1803
1884
  `;
1804
1885
 
1805
1886
  // src/queries/orders/getOrderCancellationInfo.ts
1806
- async function getOrderCancellationInfoByName(orderName) {
1887
+ async function getOrderCancellationInfoByName(orderName, retries = 3) {
1807
1888
  const variables = {
1808
1889
  first: 1,
1809
1890
  queryFilter: `name:${orderName}`
1810
1891
  };
1811
1892
  const response = await fetchShopifyGraphql({
1812
1893
  query: queryOrderCancellationInfoByName,
1813
- variables
1894
+ variables,
1895
+ retries
1814
1896
  });
1815
1897
  if (!response.orders) {
1816
1898
  throw new Error(
@@ -1843,7 +1925,7 @@ var GetLeanProductVariantsReturn = z5.array(
1843
1925
  status: z5.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
1844
1926
  })
1845
1927
  );
1846
- async function getLeanProductVariants(skus, options) {
1928
+ async function getLeanProductVariants(skus, options, retries = 3) {
1847
1929
  const queryGql = gql`#graphql
1848
1930
  query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {
1849
1931
  productVariants(first: $first, after: $after, query: $queryFilter) {
@@ -1896,7 +1978,8 @@ async function getLeanProductVariants(skus, options) {
1896
1978
  pageInfo: pageData.productVariants.pageInfo
1897
1979
  };
1898
1980
  },
1899
- fetchAllPages: true
1981
+ fetchAllPages: true,
1982
+ retries
1900
1983
  });
1901
1984
  const allVariants = extractedNodes.flatMap((v) => {
1902
1985
  if (v.sku) {
@@ -1931,7 +2014,7 @@ var GetProductVariantsBySkusReturn = z6.array(
1931
2014
  status: z6.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
1932
2015
  })
1933
2016
  );
1934
- async function getProductVariantsBySkus(skus, options) {
2017
+ async function getProductVariantsBySkus(skus, options, retries = 3) {
1935
2018
  if (skus.length === 0) {
1936
2019
  return [];
1937
2020
  }
@@ -1981,7 +2064,8 @@ async function getProductVariantsBySkus(skus, options) {
1981
2064
  pageInfo: pageData.productVariants.pageInfo
1982
2065
  };
1983
2066
  },
1984
- fetchAllPages: true
2067
+ fetchAllPages: true,
2068
+ retries
1985
2069
  });
1986
2070
  const allVariants = extractedNodes.flatMap((v) => {
1987
2071
  if (!v.sku) {
@@ -2056,7 +2140,7 @@ var ProductVariantSchema = z7.object({
2056
2140
  combinedListingRole: z7.enum(["PARENT", "CHILD"]).nullable()
2057
2141
  });
2058
2142
  var GetAllProductVariantsReturn = z7.array(ProductVariantSchema);
2059
- async function getAllProductVariants() {
2143
+ async function getAllProductVariants(retries = 3) {
2060
2144
  const initialVariables = { first: 250 };
2061
2145
  const extractedNodes = await fetchShopifyGraphql({
2062
2146
  query: queryAllProductVariants,
@@ -2075,7 +2159,8 @@ async function getAllProductVariants() {
2075
2159
  pageInfo: pageData.productVariants.pageInfo
2076
2160
  };
2077
2161
  },
2078
- fetchAllPages: true
2162
+ fetchAllPages: true,
2163
+ retries
2079
2164
  });
2080
2165
  logger.debug(`Fetched ${extractedNodes.length} product variants from Shopify`);
2081
2166
  const allVariants = extractedNodes.map((v) => {
@@ -2108,6 +2193,10 @@ var queryOrderPaymentDetails = gql`#graphql
2108
2193
  amount
2109
2194
  currencyCode
2110
2195
  }
2196
+ presentmentMoney {
2197
+ amount
2198
+ currencyCode
2199
+ }
2111
2200
  }
2112
2201
  createdAt
2113
2202
  gateway
@@ -2120,13 +2209,14 @@ var queryOrderPaymentDetails = gql`#graphql
2120
2209
  `;
2121
2210
 
2122
2211
  // src/queries/orders/getOrderPaymentDetails.ts
2123
- async function getOrderPaymentDetailsById(id) {
2212
+ async function getOrderPaymentDetailsById(id, retries = 3) {
2124
2213
  const variables = {
2125
2214
  id: convertIdIntoGid(id, "Order")
2126
2215
  };
2127
2216
  const response = await fetchShopifyGraphql({
2128
2217
  query: queryOrderPaymentDetails,
2129
- variables
2218
+ variables,
2219
+ retries
2130
2220
  });
2131
2221
  if (!response.order) {
2132
2222
  logger.debug(`No order found with ID: ${id}`);
@@ -2196,7 +2286,7 @@ var queryFulfillmentById = gql`#graphql
2196
2286
  `;
2197
2287
 
2198
2288
  // src/queries/fulfillments/getFulfillmentById.ts
2199
- async function getFulfillmentById(id) {
2289
+ async function getFulfillmentById(id, retries = 3) {
2200
2290
  const gid = typeof id === "string" ? id : convertIdIntoGid(
2201
2291
  typeof id === "number" ? BigInt(id) : id,
2202
2292
  "Fulfillment"
@@ -2204,7 +2294,8 @@ async function getFulfillmentById(id) {
2204
2294
  const variables = { id: gid };
2205
2295
  const response = await fetchShopifyGraphql({
2206
2296
  query: queryFulfillmentById,
2207
- variables
2297
+ variables,
2298
+ retries
2208
2299
  });
2209
2300
  if (!response.fulfillment) {
2210
2301
  logger.debug(`No fulfillment found with ID: ${id}`);
@@ -2242,7 +2333,7 @@ var queryFulfillmentOrdersByOrderId = gql`#graphql
2242
2333
  `;
2243
2334
 
2244
2335
  // src/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.ts
2245
- async function getFulfillmentOrdersByOrderId(orderId) {
2336
+ async function getFulfillmentOrdersByOrderId(orderId, retries = 3) {
2246
2337
  const gid = typeof orderId === "string" ? orderId : convertIdIntoGid(
2247
2338
  typeof orderId === "number" ? BigInt(orderId) : orderId,
2248
2339
  "Order"
@@ -2250,7 +2341,8 @@ async function getFulfillmentOrdersByOrderId(orderId) {
2250
2341
  const variables = { orderId: gid };
2251
2342
  const response = await fetchShopifyGraphql({
2252
2343
  query: queryFulfillmentOrdersByOrderId,
2253
- variables
2344
+ variables,
2345
+ retries
2254
2346
  });
2255
2347
  if (!response.order) {
2256
2348
  logger.debug(`No order found with ID: ${orderId}`);
@@ -2301,14 +2393,15 @@ var queryCustomersByEmail = gql`#graphql
2301
2393
  `;
2302
2394
 
2303
2395
  // src/queries/customers/getCustomersByEmail.ts
2304
- async function getCustomersByEmail(email, limit = 10) {
2396
+ async function getCustomersByEmail(email, limit = 10, retries = 3) {
2305
2397
  const variables = {
2306
2398
  query: `email:${email}`,
2307
2399
  first: limit
2308
2400
  };
2309
2401
  const response = await fetchShopifyGraphql({
2310
2402
  query: queryCustomersByEmail,
2311
- variables
2403
+ variables,
2404
+ retries
2312
2405
  });
2313
2406
  const customers = response.customers.edges.map((edge) => edge.node);
2314
2407
  logger.debug(`Found ${customers.length} customers for email: ${email}`);
@@ -2346,7 +2439,7 @@ var queryCustomerSegmentMembersWithStatistics = gql`#graphql
2346
2439
  `;
2347
2440
 
2348
2441
  // src/queries/customerSegments/getCustomerSegmentMembers.ts
2349
- async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250) {
2442
+ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250, retries = 3) {
2350
2443
  const variables = {
2351
2444
  query,
2352
2445
  first: limit,
@@ -2354,7 +2447,8 @@ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit =
2354
2447
  };
2355
2448
  const response = await fetchShopifyGraphql({
2356
2449
  query: queryCustomerSegmentMembersWithStatistics,
2357
- variables
2450
+ variables,
2451
+ retries
2358
2452
  });
2359
2453
  const members = response.customerSegmentMembers.edges.map((edge) => edge.node);
2360
2454
  logger.debug(`Found ${members.length} customer segment members`);
@@ -2407,7 +2501,7 @@ var queryOrdersByCustomerId = gql`#graphql
2407
2501
  `;
2408
2502
 
2409
2503
  // src/queries/orders/getOrdersByCustomerId.ts
2410
- async function getOrdersByCustomerId(customerId, limit = 250) {
2504
+ async function getOrdersByCustomerId(customerId, limit = 250, retries = 3) {
2411
2505
  const bigIntId = typeof customerId === "number" ? BigInt(customerId) : customerId;
2412
2506
  const gid = convertIdIntoGid(bigIntId, "Customer");
2413
2507
  const variables = {
@@ -2416,7 +2510,8 @@ async function getOrdersByCustomerId(customerId, limit = 250) {
2416
2510
  };
2417
2511
  const response = await fetchShopifyGraphql({
2418
2512
  query: queryOrdersByCustomerId,
2419
- variables
2513
+ variables,
2514
+ retries
2420
2515
  });
2421
2516
  if (!response.customer) {
2422
2517
  logger.debug(`No customer found with ID: ${customerId}`);
@@ -2452,11 +2547,12 @@ var queryMetaobjectByHandle = gql`#graphql
2452
2547
  `;
2453
2548
 
2454
2549
  // src/queries/metaobjects/getMetaobjectByHandle.ts
2455
- async function getMetaobjectByHandle(handle) {
2550
+ async function getMetaobjectByHandle(handle, retries = 3) {
2456
2551
  const variables = { handle };
2457
2552
  const response = await fetchShopifyGraphql({
2458
2553
  query: queryMetaobjectByHandle,
2459
- variables
2554
+ variables,
2555
+ retries
2460
2556
  });
2461
2557
  if (!response.metaobjectByHandle) {
2462
2558
  logger.debug(
@@ -2491,6 +2587,7 @@ export {
2491
2587
  getOrderPaymentDetailsById,
2492
2588
  getOrdersByCustomerId,
2493
2589
  getProductVariantsBySkus,
2590
+ isRetryableError,
2494
2591
  parseGid,
2495
2592
  updateFulfillmentTracking,
2496
2593
  upsertMetaobject