@ehrenkind/shopify-lib 0.7.5 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -30,16 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ CurrencyCode: () => CurrencyCode,
33
34
  ShopifyUserError: () => ShopifyUserError,
34
35
  bulkUpdateProductVariants: () => bulkUpdateProductVariants,
35
36
  calculateRefund: () => calculateRefund,
36
37
  cancelOrderById: () => cancelOrderById,
37
38
  createFile: () => createFile,
38
39
  createFulfillment: () => createFulfillment,
40
+ createMetafieldDefinition: () => createMetafieldDefinition,
39
41
  createMetaobjectDefinition: () => createMetaobjectDefinition,
40
42
  createRefund: () => createRefund,
41
43
  deleteCustomerById: () => deleteCustomerById,
42
44
  deleteFilesByIds: () => deleteFilesByIds,
45
+ deleteMetaobject: () => deleteMetaobject,
43
46
  getAllProductVariants: () => getAllProductVariants,
44
47
  getCustomerSegmentMembers: () => getCustomerSegmentMembers,
45
48
  getCustomersByEmail: () => getCustomersByEmail,
@@ -48,6 +51,8 @@ __export(index_exports, {
48
51
  getFulfillmentTrackingIds: () => getFulfillmentTrackingIds,
49
52
  getLeanProductVariants: () => getLeanProductVariants,
50
53
  getMetaobjectByHandle: () => getMetaobjectByHandle,
54
+ getMetaobjectDefinitionByType: () => getMetaobjectDefinitionByType,
55
+ getMetaobjectsByType: () => getMetaobjectsByType,
51
56
  getOrderById: () => getOrderById,
52
57
  getOrderByName: () => getOrderByName,
53
58
  getOrderCancellationInfoByName: () => getOrderCancellationInfoByName,
@@ -55,8 +60,13 @@ __export(index_exports, {
55
60
  getOrdersByCustomerId: () => getOrdersByCustomerId,
56
61
  getProductVariantsBySkus: () => getProductVariantsBySkus,
57
62
  isRetryableError: () => isRetryableError,
63
+ metafieldsSet: () => metafieldsSet,
58
64
  parseGid: () => parseGid,
65
+ runShopifyGraphql: () => fetchShopifyGraphql,
66
+ setMetaobjectStatus: () => setMetaobjectStatus,
67
+ updateCustomerEmailMarketingConsent: () => updateCustomerEmailMarketingConsent,
59
68
  updateFulfillmentTracking: () => updateFulfillmentTracking,
69
+ updateMetafieldDefinition: () => updateMetafieldDefinition,
60
70
  upsertMetaobject: () => upsertMetaobject
61
71
  });
62
72
  module.exports = __toCommonJS(index_exports);
@@ -323,7 +333,7 @@ async function makeRequest(query, variables, retries = 0) {
323
333
 
324
334
  // src/mutations/customers/deleteCustomerById.ts
325
335
  async function deleteCustomerById(customerId, retries = 1) {
326
- const mutation9 = gql`#graphql
336
+ const mutation15 = gql`#graphql
327
337
  mutation customerDelete($input: CustomerDeleteInput!) {
328
338
  customerDelete(input: $input) {
329
339
  deletedCustomerId
@@ -338,7 +348,7 @@ async function deleteCustomerById(customerId, retries = 1) {
338
348
  input: { id: customerId }
339
349
  };
340
350
  const response = await fetchShopifyGraphql({
341
- query: mutation9,
351
+ query: mutation15,
342
352
  variables,
343
353
  retries,
344
354
  dataExtractor: (data) => {
@@ -361,7 +371,7 @@ async function deleteFilesByIds(fileIds, retries = 1) {
361
371
  if (fileIds.length === 0) {
362
372
  return [];
363
373
  }
364
- const mutation9 = gql`#graphql
374
+ const mutation15 = gql`#graphql
365
375
  mutation fileDelete($fileIds: [ID!]!) {
366
376
  fileDelete(fileIds: $fileIds) {
367
377
  deletedFileIds
@@ -375,7 +385,7 @@ async function deleteFilesByIds(fileIds, retries = 1) {
375
385
  `;
376
386
  const variables = { fileIds };
377
387
  const response = await fetchShopifyGraphql({
378
- query: mutation9,
388
+ query: mutation15,
379
389
  variables,
380
390
  retries,
381
391
  dataExtractor: (data) => {
@@ -470,7 +480,9 @@ async function createMetaobjectDefinition(input, retries = 0) {
470
480
  name: input.name,
471
481
  description: input.description,
472
482
  displayNameKey: input.displayNameKey,
473
- fieldDefinitions: input.fieldDefinitions
483
+ fieldDefinitions: input.fieldDefinitions,
484
+ access: input.access,
485
+ capabilities: input.capabilities
474
486
  }
475
487
  };
476
488
  const result = await fetchShopifyGraphql({
@@ -762,6 +774,173 @@ async function cancelOrderById(orderId, retries = 0) {
762
774
  return true;
763
775
  }
764
776
 
777
+ // src/generated-api-types/admin.types.ts
778
+ var CurrencyCode = /* @__PURE__ */ ((CurrencyCode2) => {
779
+ CurrencyCode2["Aed"] = "AED";
780
+ CurrencyCode2["Afn"] = "AFN";
781
+ CurrencyCode2["All"] = "ALL";
782
+ CurrencyCode2["Amd"] = "AMD";
783
+ CurrencyCode2["Ang"] = "ANG";
784
+ CurrencyCode2["Aoa"] = "AOA";
785
+ CurrencyCode2["Ars"] = "ARS";
786
+ CurrencyCode2["Aud"] = "AUD";
787
+ CurrencyCode2["Awg"] = "AWG";
788
+ CurrencyCode2["Azn"] = "AZN";
789
+ CurrencyCode2["Bam"] = "BAM";
790
+ CurrencyCode2["Bbd"] = "BBD";
791
+ CurrencyCode2["Bdt"] = "BDT";
792
+ CurrencyCode2["Bgn"] = "BGN";
793
+ CurrencyCode2["Bhd"] = "BHD";
794
+ CurrencyCode2["Bif"] = "BIF";
795
+ CurrencyCode2["Bmd"] = "BMD";
796
+ CurrencyCode2["Bnd"] = "BND";
797
+ CurrencyCode2["Bob"] = "BOB";
798
+ CurrencyCode2["Brl"] = "BRL";
799
+ CurrencyCode2["Bsd"] = "BSD";
800
+ CurrencyCode2["Btn"] = "BTN";
801
+ CurrencyCode2["Bwp"] = "BWP";
802
+ CurrencyCode2["Byn"] = "BYN";
803
+ CurrencyCode2["Byr"] = "BYR";
804
+ CurrencyCode2["Bzd"] = "BZD";
805
+ CurrencyCode2["Cad"] = "CAD";
806
+ CurrencyCode2["Cdf"] = "CDF";
807
+ CurrencyCode2["Chf"] = "CHF";
808
+ CurrencyCode2["Clp"] = "CLP";
809
+ CurrencyCode2["Cny"] = "CNY";
810
+ CurrencyCode2["Cop"] = "COP";
811
+ CurrencyCode2["Crc"] = "CRC";
812
+ CurrencyCode2["Cve"] = "CVE";
813
+ CurrencyCode2["Czk"] = "CZK";
814
+ CurrencyCode2["Djf"] = "DJF";
815
+ CurrencyCode2["Dkk"] = "DKK";
816
+ CurrencyCode2["Dop"] = "DOP";
817
+ CurrencyCode2["Dzd"] = "DZD";
818
+ CurrencyCode2["Egp"] = "EGP";
819
+ CurrencyCode2["Ern"] = "ERN";
820
+ CurrencyCode2["Etb"] = "ETB";
821
+ CurrencyCode2["Eur"] = "EUR";
822
+ CurrencyCode2["Fjd"] = "FJD";
823
+ CurrencyCode2["Fkp"] = "FKP";
824
+ CurrencyCode2["Gbp"] = "GBP";
825
+ CurrencyCode2["Gel"] = "GEL";
826
+ CurrencyCode2["Ghs"] = "GHS";
827
+ CurrencyCode2["Gip"] = "GIP";
828
+ CurrencyCode2["Gmd"] = "GMD";
829
+ CurrencyCode2["Gnf"] = "GNF";
830
+ CurrencyCode2["Gtq"] = "GTQ";
831
+ CurrencyCode2["Gyd"] = "GYD";
832
+ CurrencyCode2["Hkd"] = "HKD";
833
+ CurrencyCode2["Hnl"] = "HNL";
834
+ CurrencyCode2["Hrk"] = "HRK";
835
+ CurrencyCode2["Htg"] = "HTG";
836
+ CurrencyCode2["Huf"] = "HUF";
837
+ CurrencyCode2["Idr"] = "IDR";
838
+ CurrencyCode2["Ils"] = "ILS";
839
+ CurrencyCode2["Inr"] = "INR";
840
+ CurrencyCode2["Iqd"] = "IQD";
841
+ CurrencyCode2["Irr"] = "IRR";
842
+ CurrencyCode2["Isk"] = "ISK";
843
+ CurrencyCode2["Jep"] = "JEP";
844
+ CurrencyCode2["Jmd"] = "JMD";
845
+ CurrencyCode2["Jod"] = "JOD";
846
+ CurrencyCode2["Jpy"] = "JPY";
847
+ CurrencyCode2["Kes"] = "KES";
848
+ CurrencyCode2["Kgs"] = "KGS";
849
+ CurrencyCode2["Khr"] = "KHR";
850
+ CurrencyCode2["Kid"] = "KID";
851
+ CurrencyCode2["Kmf"] = "KMF";
852
+ CurrencyCode2["Krw"] = "KRW";
853
+ CurrencyCode2["Kwd"] = "KWD";
854
+ CurrencyCode2["Kyd"] = "KYD";
855
+ CurrencyCode2["Kzt"] = "KZT";
856
+ CurrencyCode2["Lak"] = "LAK";
857
+ CurrencyCode2["Lbp"] = "LBP";
858
+ CurrencyCode2["Lkr"] = "LKR";
859
+ CurrencyCode2["Lrd"] = "LRD";
860
+ CurrencyCode2["Lsl"] = "LSL";
861
+ CurrencyCode2["Ltl"] = "LTL";
862
+ CurrencyCode2["Lvl"] = "LVL";
863
+ CurrencyCode2["Lyd"] = "LYD";
864
+ CurrencyCode2["Mad"] = "MAD";
865
+ CurrencyCode2["Mdl"] = "MDL";
866
+ CurrencyCode2["Mga"] = "MGA";
867
+ CurrencyCode2["Mkd"] = "MKD";
868
+ CurrencyCode2["Mmk"] = "MMK";
869
+ CurrencyCode2["Mnt"] = "MNT";
870
+ CurrencyCode2["Mop"] = "MOP";
871
+ CurrencyCode2["Mru"] = "MRU";
872
+ CurrencyCode2["Mur"] = "MUR";
873
+ CurrencyCode2["Mvr"] = "MVR";
874
+ CurrencyCode2["Mwk"] = "MWK";
875
+ CurrencyCode2["Mxn"] = "MXN";
876
+ CurrencyCode2["Myr"] = "MYR";
877
+ CurrencyCode2["Mzn"] = "MZN";
878
+ CurrencyCode2["Nad"] = "NAD";
879
+ CurrencyCode2["Ngn"] = "NGN";
880
+ CurrencyCode2["Nio"] = "NIO";
881
+ CurrencyCode2["Nok"] = "NOK";
882
+ CurrencyCode2["Npr"] = "NPR";
883
+ CurrencyCode2["Nzd"] = "NZD";
884
+ CurrencyCode2["Omr"] = "OMR";
885
+ CurrencyCode2["Pab"] = "PAB";
886
+ CurrencyCode2["Pen"] = "PEN";
887
+ CurrencyCode2["Pgk"] = "PGK";
888
+ CurrencyCode2["Php"] = "PHP";
889
+ CurrencyCode2["Pkr"] = "PKR";
890
+ CurrencyCode2["Pln"] = "PLN";
891
+ CurrencyCode2["Pyg"] = "PYG";
892
+ CurrencyCode2["Qar"] = "QAR";
893
+ CurrencyCode2["Ron"] = "RON";
894
+ CurrencyCode2["Rsd"] = "RSD";
895
+ CurrencyCode2["Rub"] = "RUB";
896
+ CurrencyCode2["Rwf"] = "RWF";
897
+ CurrencyCode2["Sar"] = "SAR";
898
+ CurrencyCode2["Sbd"] = "SBD";
899
+ CurrencyCode2["Scr"] = "SCR";
900
+ CurrencyCode2["Sdg"] = "SDG";
901
+ CurrencyCode2["Sek"] = "SEK";
902
+ CurrencyCode2["Sgd"] = "SGD";
903
+ CurrencyCode2["Shp"] = "SHP";
904
+ CurrencyCode2["Sll"] = "SLL";
905
+ CurrencyCode2["Sos"] = "SOS";
906
+ CurrencyCode2["Srd"] = "SRD";
907
+ CurrencyCode2["Ssp"] = "SSP";
908
+ CurrencyCode2["Std"] = "STD";
909
+ CurrencyCode2["Stn"] = "STN";
910
+ CurrencyCode2["Syp"] = "SYP";
911
+ CurrencyCode2["Szl"] = "SZL";
912
+ CurrencyCode2["Thb"] = "THB";
913
+ CurrencyCode2["Tjs"] = "TJS";
914
+ CurrencyCode2["Tmt"] = "TMT";
915
+ CurrencyCode2["Tnd"] = "TND";
916
+ CurrencyCode2["Top"] = "TOP";
917
+ CurrencyCode2["Try"] = "TRY";
918
+ CurrencyCode2["Ttd"] = "TTD";
919
+ CurrencyCode2["Twd"] = "TWD";
920
+ CurrencyCode2["Tzs"] = "TZS";
921
+ CurrencyCode2["Uah"] = "UAH";
922
+ CurrencyCode2["Ugx"] = "UGX";
923
+ CurrencyCode2["Usd"] = "USD";
924
+ CurrencyCode2["Usdc"] = "USDC";
925
+ CurrencyCode2["Uyu"] = "UYU";
926
+ CurrencyCode2["Uzs"] = "UZS";
927
+ CurrencyCode2["Ved"] = "VED";
928
+ CurrencyCode2["Vef"] = "VEF";
929
+ CurrencyCode2["Ves"] = "VES";
930
+ CurrencyCode2["Vnd"] = "VND";
931
+ CurrencyCode2["Vuv"] = "VUV";
932
+ CurrencyCode2["Wst"] = "WST";
933
+ CurrencyCode2["Xaf"] = "XAF";
934
+ CurrencyCode2["Xcd"] = "XCD";
935
+ CurrencyCode2["Xof"] = "XOF";
936
+ CurrencyCode2["Xpf"] = "XPF";
937
+ CurrencyCode2["Xxx"] = "XXX";
938
+ CurrencyCode2["Yer"] = "YER";
939
+ CurrencyCode2["Zar"] = "ZAR";
940
+ CurrencyCode2["Zmw"] = "ZMW";
941
+ return CurrencyCode2;
942
+ })(CurrencyCode || {});
943
+
765
944
  // src/mutations/refunds/createRefund.ts
766
945
  var mutation6 = gql`#graphql
767
946
  mutation createRefund($input: RefundInput!) {
@@ -1012,36 +1191,60 @@ var querySuggestedRefund = gql`#graphql
1012
1191
  amount
1013
1192
  currencyCode
1014
1193
  }
1194
+ presentmentMoney {
1195
+ amount
1196
+ currencyCode
1197
+ }
1015
1198
  }
1016
1199
  maximumRefundableSet {
1017
1200
  shopMoney {
1018
1201
  amount
1019
1202
  currencyCode
1020
1203
  }
1204
+ presentmentMoney {
1205
+ amount
1206
+ currencyCode
1207
+ }
1021
1208
  }
1022
1209
  subtotalSet {
1023
1210
  shopMoney {
1024
1211
  amount
1025
1212
  currencyCode
1026
1213
  }
1214
+ presentmentMoney {
1215
+ amount
1216
+ currencyCode
1217
+ }
1027
1218
  }
1028
1219
  totalTaxSet {
1029
1220
  shopMoney {
1030
1221
  amount
1031
1222
  currencyCode
1032
1223
  }
1224
+ presentmentMoney {
1225
+ amount
1226
+ currencyCode
1227
+ }
1033
1228
  }
1034
1229
  discountedSubtotalSet {
1035
1230
  shopMoney {
1036
1231
  amount
1037
1232
  currencyCode
1038
1233
  }
1234
+ presentmentMoney {
1235
+ amount
1236
+ currencyCode
1237
+ }
1039
1238
  }
1040
1239
  totalCartDiscountAmountSet {
1041
1240
  shopMoney {
1042
1241
  amount
1043
1242
  currencyCode
1044
1243
  }
1244
+ presentmentMoney {
1245
+ amount
1246
+ currencyCode
1247
+ }
1045
1248
  }
1046
1249
  shipping {
1047
1250
  amountSet {
@@ -1049,18 +1252,30 @@ var querySuggestedRefund = gql`#graphql
1049
1252
  amount
1050
1253
  currencyCode
1051
1254
  }
1255
+ presentmentMoney {
1256
+ amount
1257
+ currencyCode
1258
+ }
1052
1259
  }
1053
1260
  maximumRefundableSet {
1054
1261
  shopMoney {
1055
1262
  amount
1056
1263
  currencyCode
1057
1264
  }
1265
+ presentmentMoney {
1266
+ amount
1267
+ currencyCode
1268
+ }
1058
1269
  }
1059
1270
  taxSet {
1060
1271
  shopMoney {
1061
1272
  amount
1062
1273
  currencyCode
1063
1274
  }
1275
+ presentmentMoney {
1276
+ amount
1277
+ currencyCode
1278
+ }
1064
1279
  }
1065
1280
  }
1066
1281
  refundLineItems {
@@ -1074,12 +1289,20 @@ var querySuggestedRefund = gql`#graphql
1074
1289
  amount
1075
1290
  currencyCode
1076
1291
  }
1292
+ presentmentMoney {
1293
+ amount
1294
+ currencyCode
1295
+ }
1077
1296
  }
1078
1297
  totalDiscountSet {
1079
1298
  shopMoney {
1080
1299
  amount
1081
1300
  currencyCode
1082
1301
  }
1302
+ presentmentMoney {
1303
+ amount
1304
+ currencyCode
1305
+ }
1083
1306
  }
1084
1307
  }
1085
1308
  quantity
@@ -1088,18 +1311,30 @@ var querySuggestedRefund = gql`#graphql
1088
1311
  amount
1089
1312
  currencyCode
1090
1313
  }
1314
+ presentmentMoney {
1315
+ amount
1316
+ currencyCode
1317
+ }
1091
1318
  }
1092
1319
  subtotalSet {
1093
1320
  shopMoney {
1094
1321
  amount
1095
1322
  currencyCode
1096
1323
  }
1324
+ presentmentMoney {
1325
+ amount
1326
+ currencyCode
1327
+ }
1097
1328
  }
1098
1329
  totalTaxSet {
1099
1330
  shopMoney {
1100
1331
  amount
1101
1332
  currencyCode
1102
1333
  }
1334
+ presentmentMoney {
1335
+ amount
1336
+ currencyCode
1337
+ }
1103
1338
  }
1104
1339
  restockType
1105
1340
  }
@@ -1111,12 +1346,20 @@ var querySuggestedRefund = gql`#graphql
1111
1346
  amount
1112
1347
  currencyCode
1113
1348
  }
1349
+ presentmentMoney {
1350
+ amount
1351
+ currencyCode
1352
+ }
1114
1353
  }
1115
1354
  maximumRefundableSet {
1116
1355
  shopMoney {
1117
1356
  amount
1118
1357
  currencyCode
1119
1358
  }
1359
+ presentmentMoney {
1360
+ amount
1361
+ currencyCode
1362
+ }
1120
1363
  }
1121
1364
  parentTransaction {
1122
1365
  id
@@ -1173,6 +1416,352 @@ async function calculateRefund(orderId, options = {}, retries = 3) {
1173
1416
  return response.order.suggestedRefund;
1174
1417
  }
1175
1418
 
1419
+ // src/mutations/metaobjects/setMetaobjectStatus.ts
1420
+ var mutation9 = gql`#graphql
1421
+ mutation setMetaobjectStatus($id: ID!, $metaobject: MetaobjectUpdateInput!) {
1422
+ metaobjectUpdate(id: $id, metaobject: $metaobject) {
1423
+ metaobject {
1424
+ id
1425
+ }
1426
+ userErrors {
1427
+ code
1428
+ field
1429
+ message
1430
+ }
1431
+ }
1432
+ }
1433
+ `;
1434
+ async function setMetaobjectStatus(id, status, retries = 1) {
1435
+ const variables = {
1436
+ id,
1437
+ metaobject: {
1438
+ capabilities: {
1439
+ publishable: { status }
1440
+ }
1441
+ }
1442
+ };
1443
+ await fetchShopifyGraphql({
1444
+ query: mutation9,
1445
+ variables,
1446
+ retries,
1447
+ dataExtractor: (data) => {
1448
+ if (!data.metaobjectUpdate) {
1449
+ throw new Error("GraphQL response missing 'metaobjectUpdate' field");
1450
+ }
1451
+ const { metaobject, userErrors } = data.metaobjectUpdate;
1452
+ return {
1453
+ nodes: metaobject ? [{ id: metaobject.id }] : [],
1454
+ userErrors
1455
+ };
1456
+ }
1457
+ });
1458
+ logger.debug(`Set metaobject ${id} status to ${status}`);
1459
+ }
1460
+
1461
+ // src/mutations/metaobjects/deleteMetaobject.ts
1462
+ var mutation10 = gql`#graphql
1463
+ mutation deleteMetaobject($id: ID!) {
1464
+ metaobjectDelete(id: $id) {
1465
+ deletedId
1466
+ userErrors {
1467
+ code
1468
+ field
1469
+ message
1470
+ }
1471
+ }
1472
+ }
1473
+ `;
1474
+ async function deleteMetaobject(id, retries = 0) {
1475
+ const variables = { id };
1476
+ const result = await fetchShopifyGraphql({
1477
+ query: mutation10,
1478
+ variables,
1479
+ retries,
1480
+ dataExtractor: (data) => {
1481
+ if (!data.metaobjectDelete) {
1482
+ throw new Error("GraphQL response missing 'metaobjectDelete' field");
1483
+ }
1484
+ const { deletedId: deletedId2, userErrors } = data.metaobjectDelete;
1485
+ return {
1486
+ nodes: [{ deletedId: deletedId2 ?? null }],
1487
+ userErrors
1488
+ };
1489
+ }
1490
+ });
1491
+ const deletedId = result[0]?.deletedId ?? void 0;
1492
+ if (deletedId) {
1493
+ logger.debug(`Deleted metaobject ${deletedId}`);
1494
+ }
1495
+ return deletedId;
1496
+ }
1497
+
1498
+ // src/mutations/metafields/metafieldsSet.ts
1499
+ var mutation11 = gql`#graphql
1500
+ mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
1501
+ metafieldsSet(metafields: $metafields) {
1502
+ metafields {
1503
+ id
1504
+ namespace
1505
+ key
1506
+ value
1507
+ }
1508
+ userErrors {
1509
+ code
1510
+ field
1511
+ message
1512
+ }
1513
+ }
1514
+ }
1515
+ `;
1516
+ async function metafieldsSet(metafields, retries = 1) {
1517
+ const variables = { metafields };
1518
+ const result = await fetchShopifyGraphql(
1519
+ {
1520
+ query: mutation11,
1521
+ variables,
1522
+ retries,
1523
+ dataExtractor: (data) => {
1524
+ if (!data.metafieldsSet) {
1525
+ throw new Error("GraphQL response missing 'metafieldsSet' field");
1526
+ }
1527
+ const { metafields: set, userErrors } = data.metafieldsSet;
1528
+ return {
1529
+ nodes: (set ?? []).map((m) => ({
1530
+ id: m.id,
1531
+ namespace: m.namespace,
1532
+ key: m.key,
1533
+ value: m.value
1534
+ })),
1535
+ userErrors
1536
+ };
1537
+ }
1538
+ }
1539
+ );
1540
+ logger.debug(`Set ${result.length} metafield(s)`);
1541
+ return result;
1542
+ }
1543
+
1544
+ // src/mutations/metafieldDefinitions/createMetafieldDefinition.ts
1545
+ var mutation12 = gql`#graphql
1546
+ mutation createMetafieldDefinition($definition: MetafieldDefinitionInput!) {
1547
+ metafieldDefinitionCreate(definition: $definition) {
1548
+ createdDefinition {
1549
+ id
1550
+ }
1551
+ userErrors {
1552
+ code
1553
+ field
1554
+ message
1555
+ }
1556
+ }
1557
+ }
1558
+ `;
1559
+ async function createMetafieldDefinition(definition, retries = 0) {
1560
+ const variables = { definition };
1561
+ const result = await fetchShopifyGraphql({
1562
+ query: mutation12,
1563
+ variables,
1564
+ retries,
1565
+ dataExtractor: (data) => {
1566
+ if (!data.metafieldDefinitionCreate) {
1567
+ throw new Error(
1568
+ "GraphQL response missing 'metafieldDefinitionCreate' field"
1569
+ );
1570
+ }
1571
+ const { createdDefinition, userErrors } = data.metafieldDefinitionCreate;
1572
+ return {
1573
+ nodes: createdDefinition ? [{ id: createdDefinition.id }] : [],
1574
+ userErrors
1575
+ };
1576
+ }
1577
+ });
1578
+ const created = result[0];
1579
+ if (!created) {
1580
+ throw new Error("Metafield definition creation returned no result");
1581
+ }
1582
+ logger.debug(`Created metafield definition ${created.id}`);
1583
+ return created.id;
1584
+ }
1585
+
1586
+ // src/mutations/metafieldDefinitions/updateMetafieldDefinition.ts
1587
+ var mutation13 = gql`#graphql
1588
+ mutation updateMetafieldDefinition(
1589
+ $definition: MetafieldDefinitionUpdateInput!
1590
+ ) {
1591
+ metafieldDefinitionUpdate(definition: $definition) {
1592
+ updatedDefinition {
1593
+ id
1594
+ }
1595
+ userErrors {
1596
+ code
1597
+ field
1598
+ message
1599
+ }
1600
+ }
1601
+ }
1602
+ `;
1603
+ async function updateMetafieldDefinition(definition, retries = 1) {
1604
+ const variables = { definition };
1605
+ const result = await fetchShopifyGraphql({
1606
+ query: mutation13,
1607
+ variables,
1608
+ retries,
1609
+ dataExtractor: (data) => {
1610
+ if (!data.metafieldDefinitionUpdate) {
1611
+ throw new Error(
1612
+ "GraphQL response missing 'metafieldDefinitionUpdate' field"
1613
+ );
1614
+ }
1615
+ const { updatedDefinition, userErrors } = data.metafieldDefinitionUpdate;
1616
+ return {
1617
+ nodes: updatedDefinition ? [{ id: updatedDefinition.id }] : [],
1618
+ userErrors
1619
+ };
1620
+ }
1621
+ });
1622
+ const updated = result[0]?.id;
1623
+ if (updated) {
1624
+ logger.debug(`Updated metafield definition ${updated}`);
1625
+ }
1626
+ return updated;
1627
+ }
1628
+
1629
+ // src/mutations/customers/updateCustomerEmailMarketingConsent.ts
1630
+ var mutation14 = gql`#graphql
1631
+ mutation updateCustomerEmailMarketingConsent(
1632
+ $input: CustomerEmailMarketingConsentUpdateInput!
1633
+ ) {
1634
+ customerEmailMarketingConsentUpdate(input: $input) {
1635
+ customer {
1636
+ id
1637
+ emailMarketingConsent {
1638
+ marketingState
1639
+ }
1640
+ }
1641
+ userErrors {
1642
+ field
1643
+ message
1644
+ }
1645
+ }
1646
+ }
1647
+ `;
1648
+ async function updateCustomerEmailMarketingConsent(input, retries = 1) {
1649
+ const variables = {
1650
+ input: {
1651
+ customerId: input.customerId,
1652
+ emailMarketingConsent: {
1653
+ marketingState: input.marketingState,
1654
+ marketingOptInLevel: input.marketingOptInLevel
1655
+ }
1656
+ }
1657
+ };
1658
+ const result = await fetchShopifyGraphql({
1659
+ query: mutation14,
1660
+ variables,
1661
+ retries,
1662
+ dataExtractor: (data) => {
1663
+ if (!data.customerEmailMarketingConsentUpdate) {
1664
+ throw new Error(
1665
+ "GraphQL response missing 'customerEmailMarketingConsentUpdate' field"
1666
+ );
1667
+ }
1668
+ const { customer, userErrors } = data.customerEmailMarketingConsentUpdate;
1669
+ return {
1670
+ nodes: customer ? [
1671
+ {
1672
+ id: customer.id,
1673
+ marketingState: customer.emailMarketingConsent?.marketingState ?? null
1674
+ }
1675
+ ] : [],
1676
+ userErrors
1677
+ };
1678
+ }
1679
+ });
1680
+ const updated = result[0];
1681
+ if (!updated) {
1682
+ throw new Error(
1683
+ "Customer email marketing consent update returned no result"
1684
+ );
1685
+ }
1686
+ logger.debug(
1687
+ `Updated customer ${updated.id} email marketing consent to ${updated.marketingState}`
1688
+ );
1689
+ return updated;
1690
+ }
1691
+
1692
+ // src/queries/metaobjects/getMetaobjectsByType.queries.ts
1693
+ var queryMetaobjectsByType = gql`#graphql
1694
+ query metaobjectsByType($type: String!, $first: Int!, $after: String) {
1695
+ metaobjects(type: $type, first: $first, after: $after) {
1696
+ nodes {
1697
+ id
1698
+ handle
1699
+ displayName
1700
+ type
1701
+ fields {
1702
+ key
1703
+ value
1704
+ }
1705
+ }
1706
+ pageInfo {
1707
+ hasNextPage
1708
+ endCursor
1709
+ }
1710
+ }
1711
+ }
1712
+ `;
1713
+
1714
+ // src/queries/metaobjects/getMetaobjectsByType.ts
1715
+ async function getMetaobjectsByType(type, options = {}, retries = 3) {
1716
+ const variables = {
1717
+ type,
1718
+ first: options.pageSize ?? 250
1719
+ };
1720
+ const nodes = await fetchShopifyGraphql({
1721
+ query: queryMetaobjectsByType,
1722
+ variables,
1723
+ fetchAllPages: true,
1724
+ retries,
1725
+ dataExtractor: (data) => {
1726
+ if (!data.metaobjects) {
1727
+ throw new Error("GraphQL response missing 'metaobjects' field");
1728
+ }
1729
+ return {
1730
+ nodes: data.metaobjects.nodes,
1731
+ pageInfo: data.metaobjects.pageInfo
1732
+ };
1733
+ }
1734
+ });
1735
+ logger.debug(`Fetched ${nodes.length} metaobject(s) of type "${type}"`);
1736
+ return nodes;
1737
+ }
1738
+
1739
+ // src/queries/metaobjectDefinitions/getMetaobjectDefinitionByType.queries.ts
1740
+ var queryMetaobjectDefinitionByType = gql`#graphql
1741
+ query metaobjectDefinitionByType($type: String!) {
1742
+ metaobjectDefinitionByType(type: $type) {
1743
+ id
1744
+ type
1745
+ name
1746
+ }
1747
+ }
1748
+ `;
1749
+
1750
+ // src/queries/metaobjectDefinitions/getMetaobjectDefinitionByType.ts
1751
+ async function getMetaobjectDefinitionByType(type, retries = 3) {
1752
+ const variables = { type };
1753
+ const response = await fetchShopifyGraphql({
1754
+ query: queryMetaobjectDefinitionByType,
1755
+ variables,
1756
+ retries
1757
+ });
1758
+ if (!response.metaobjectDefinitionByType) {
1759
+ logger.debug(`No metaobject definition found for type "${type}"`);
1760
+ return void 0;
1761
+ }
1762
+ return response.metaobjectDefinitionByType;
1763
+ }
1764
+
1176
1765
  // src/queries/orders/getOrderById.ts
1177
1766
  var import_zod3 = __toESM(require("zod"), 1);
1178
1767
 
@@ -1297,6 +1886,14 @@ var queryOrderByIdFull = gql`#graphql
1297
1886
  currencyCode
1298
1887
  }
1299
1888
  }
1889
+ discountAllocations {
1890
+ allocatedAmountSet {
1891
+ shopMoney {
1892
+ amount
1893
+ currencyCode
1894
+ }
1895
+ }
1896
+ }
1300
1897
  vendor
1301
1898
  image {
1302
1899
  url
@@ -1313,6 +1910,25 @@ var queryOrderByIdFull = gql`#graphql
1313
1910
  }
1314
1911
  }
1315
1912
  }
1913
+ discountApplications(first: 20) {
1914
+ nodes {
1915
+ allocationMethod
1916
+ targetType
1917
+ value {
1918
+ __typename
1919
+ ... on PricingPercentageValue {
1920
+ percentage
1921
+ }
1922
+ ... on MoneyV2 {
1923
+ amount
1924
+ currencyCode
1925
+ }
1926
+ }
1927
+ ... on DiscountCodeApplication {
1928
+ code
1929
+ }
1930
+ }
1931
+ }
1316
1932
  fulfillments {
1317
1933
  id
1318
1934
  name
@@ -1369,6 +1985,17 @@ var queryOrderByIdFull = gql`#graphql
1369
1985
  currencyCode
1370
1986
  }
1371
1987
  }
1988
+ transactions(first: 50) {
1989
+ nodes {
1990
+ kind
1991
+ amountSet {
1992
+ shopMoney {
1993
+ amount
1994
+ currencyCode
1995
+ }
1996
+ }
1997
+ }
1998
+ }
1372
1999
  }
1373
2000
  }
1374
2001
  }
@@ -2624,16 +3251,19 @@ async function getMetaobjectByHandle(handle, retries = 3) {
2624
3251
  }
2625
3252
  // Annotate the CommonJS export names for ESM import in node:
2626
3253
  0 && (module.exports = {
3254
+ CurrencyCode,
2627
3255
  ShopifyUserError,
2628
3256
  bulkUpdateProductVariants,
2629
3257
  calculateRefund,
2630
3258
  cancelOrderById,
2631
3259
  createFile,
2632
3260
  createFulfillment,
3261
+ createMetafieldDefinition,
2633
3262
  createMetaobjectDefinition,
2634
3263
  createRefund,
2635
3264
  deleteCustomerById,
2636
3265
  deleteFilesByIds,
3266
+ deleteMetaobject,
2637
3267
  getAllProductVariants,
2638
3268
  getCustomerSegmentMembers,
2639
3269
  getCustomersByEmail,
@@ -2642,6 +3272,8 @@ async function getMetaobjectByHandle(handle, retries = 3) {
2642
3272
  getFulfillmentTrackingIds,
2643
3273
  getLeanProductVariants,
2644
3274
  getMetaobjectByHandle,
3275
+ getMetaobjectDefinitionByType,
3276
+ getMetaobjectsByType,
2645
3277
  getOrderById,
2646
3278
  getOrderByName,
2647
3279
  getOrderCancellationInfoByName,
@@ -2649,8 +3281,13 @@ async function getMetaobjectByHandle(handle, retries = 3) {
2649
3281
  getOrdersByCustomerId,
2650
3282
  getProductVariantsBySkus,
2651
3283
  isRetryableError,
3284
+ metafieldsSet,
2652
3285
  parseGid,
3286
+ runShopifyGraphql,
3287
+ setMetaobjectStatus,
3288
+ updateCustomerEmailMarketingConsent,
2653
3289
  updateFulfillmentTracking,
3290
+ updateMetafieldDefinition,
2654
3291
  upsertMetaobject
2655
3292
  });
2656
3293
  //# sourceMappingURL=index.cjs.map