@ehrenkind/shopify-lib 0.7.5 → 0.8.0

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
@@ -36,10 +36,12 @@ __export(index_exports, {
36
36
  cancelOrderById: () => cancelOrderById,
37
37
  createFile: () => createFile,
38
38
  createFulfillment: () => createFulfillment,
39
+ createMetafieldDefinition: () => createMetafieldDefinition,
39
40
  createMetaobjectDefinition: () => createMetaobjectDefinition,
40
41
  createRefund: () => createRefund,
41
42
  deleteCustomerById: () => deleteCustomerById,
42
43
  deleteFilesByIds: () => deleteFilesByIds,
44
+ deleteMetaobject: () => deleteMetaobject,
43
45
  getAllProductVariants: () => getAllProductVariants,
44
46
  getCustomerSegmentMembers: () => getCustomerSegmentMembers,
45
47
  getCustomersByEmail: () => getCustomersByEmail,
@@ -48,6 +50,8 @@ __export(index_exports, {
48
50
  getFulfillmentTrackingIds: () => getFulfillmentTrackingIds,
49
51
  getLeanProductVariants: () => getLeanProductVariants,
50
52
  getMetaobjectByHandle: () => getMetaobjectByHandle,
53
+ getMetaobjectDefinitionByType: () => getMetaobjectDefinitionByType,
54
+ getMetaobjectsByType: () => getMetaobjectsByType,
51
55
  getOrderById: () => getOrderById,
52
56
  getOrderByName: () => getOrderByName,
53
57
  getOrderCancellationInfoByName: () => getOrderCancellationInfoByName,
@@ -55,8 +59,13 @@ __export(index_exports, {
55
59
  getOrdersByCustomerId: () => getOrdersByCustomerId,
56
60
  getProductVariantsBySkus: () => getProductVariantsBySkus,
57
61
  isRetryableError: () => isRetryableError,
62
+ metafieldsSet: () => metafieldsSet,
58
63
  parseGid: () => parseGid,
64
+ runShopifyGraphql: () => fetchShopifyGraphql,
65
+ setMetaobjectStatus: () => setMetaobjectStatus,
66
+ updateCustomerEmailMarketingConsent: () => updateCustomerEmailMarketingConsent,
59
67
  updateFulfillmentTracking: () => updateFulfillmentTracking,
68
+ updateMetafieldDefinition: () => updateMetafieldDefinition,
60
69
  upsertMetaobject: () => upsertMetaobject
61
70
  });
62
71
  module.exports = __toCommonJS(index_exports);
@@ -323,7 +332,7 @@ async function makeRequest(query, variables, retries = 0) {
323
332
 
324
333
  // src/mutations/customers/deleteCustomerById.ts
325
334
  async function deleteCustomerById(customerId, retries = 1) {
326
- const mutation9 = gql`#graphql
335
+ const mutation15 = gql`#graphql
327
336
  mutation customerDelete($input: CustomerDeleteInput!) {
328
337
  customerDelete(input: $input) {
329
338
  deletedCustomerId
@@ -338,7 +347,7 @@ async function deleteCustomerById(customerId, retries = 1) {
338
347
  input: { id: customerId }
339
348
  };
340
349
  const response = await fetchShopifyGraphql({
341
- query: mutation9,
350
+ query: mutation15,
342
351
  variables,
343
352
  retries,
344
353
  dataExtractor: (data) => {
@@ -361,7 +370,7 @@ async function deleteFilesByIds(fileIds, retries = 1) {
361
370
  if (fileIds.length === 0) {
362
371
  return [];
363
372
  }
364
- const mutation9 = gql`#graphql
373
+ const mutation15 = gql`#graphql
365
374
  mutation fileDelete($fileIds: [ID!]!) {
366
375
  fileDelete(fileIds: $fileIds) {
367
376
  deletedFileIds
@@ -375,7 +384,7 @@ async function deleteFilesByIds(fileIds, retries = 1) {
375
384
  `;
376
385
  const variables = { fileIds };
377
386
  const response = await fetchShopifyGraphql({
378
- query: mutation9,
387
+ query: mutation15,
379
388
  variables,
380
389
  retries,
381
390
  dataExtractor: (data) => {
@@ -470,7 +479,9 @@ async function createMetaobjectDefinition(input, retries = 0) {
470
479
  name: input.name,
471
480
  description: input.description,
472
481
  displayNameKey: input.displayNameKey,
473
- fieldDefinitions: input.fieldDefinitions
482
+ fieldDefinitions: input.fieldDefinitions,
483
+ access: input.access,
484
+ capabilities: input.capabilities
474
485
  }
475
486
  };
476
487
  const result = await fetchShopifyGraphql({
@@ -1173,6 +1184,352 @@ async function calculateRefund(orderId, options = {}, retries = 3) {
1173
1184
  return response.order.suggestedRefund;
1174
1185
  }
1175
1186
 
1187
+ // src/mutations/metaobjects/setMetaobjectStatus.ts
1188
+ var mutation9 = gql`#graphql
1189
+ mutation setMetaobjectStatus($id: ID!, $metaobject: MetaobjectUpdateInput!) {
1190
+ metaobjectUpdate(id: $id, metaobject: $metaobject) {
1191
+ metaobject {
1192
+ id
1193
+ }
1194
+ userErrors {
1195
+ code
1196
+ field
1197
+ message
1198
+ }
1199
+ }
1200
+ }
1201
+ `;
1202
+ async function setMetaobjectStatus(id, status, retries = 1) {
1203
+ const variables = {
1204
+ id,
1205
+ metaobject: {
1206
+ capabilities: {
1207
+ publishable: { status }
1208
+ }
1209
+ }
1210
+ };
1211
+ await fetchShopifyGraphql({
1212
+ query: mutation9,
1213
+ variables,
1214
+ retries,
1215
+ dataExtractor: (data) => {
1216
+ if (!data.metaobjectUpdate) {
1217
+ throw new Error("GraphQL response missing 'metaobjectUpdate' field");
1218
+ }
1219
+ const { metaobject, userErrors } = data.metaobjectUpdate;
1220
+ return {
1221
+ nodes: metaobject ? [{ id: metaobject.id }] : [],
1222
+ userErrors
1223
+ };
1224
+ }
1225
+ });
1226
+ logger.debug(`Set metaobject ${id} status to ${status}`);
1227
+ }
1228
+
1229
+ // src/mutations/metaobjects/deleteMetaobject.ts
1230
+ var mutation10 = gql`#graphql
1231
+ mutation deleteMetaobject($id: ID!) {
1232
+ metaobjectDelete(id: $id) {
1233
+ deletedId
1234
+ userErrors {
1235
+ code
1236
+ field
1237
+ message
1238
+ }
1239
+ }
1240
+ }
1241
+ `;
1242
+ async function deleteMetaobject(id, retries = 0) {
1243
+ const variables = { id };
1244
+ const result = await fetchShopifyGraphql({
1245
+ query: mutation10,
1246
+ variables,
1247
+ retries,
1248
+ dataExtractor: (data) => {
1249
+ if (!data.metaobjectDelete) {
1250
+ throw new Error("GraphQL response missing 'metaobjectDelete' field");
1251
+ }
1252
+ const { deletedId: deletedId2, userErrors } = data.metaobjectDelete;
1253
+ return {
1254
+ nodes: [{ deletedId: deletedId2 ?? null }],
1255
+ userErrors
1256
+ };
1257
+ }
1258
+ });
1259
+ const deletedId = result[0]?.deletedId ?? void 0;
1260
+ if (deletedId) {
1261
+ logger.debug(`Deleted metaobject ${deletedId}`);
1262
+ }
1263
+ return deletedId;
1264
+ }
1265
+
1266
+ // src/mutations/metafields/metafieldsSet.ts
1267
+ var mutation11 = gql`#graphql
1268
+ mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
1269
+ metafieldsSet(metafields: $metafields) {
1270
+ metafields {
1271
+ id
1272
+ namespace
1273
+ key
1274
+ value
1275
+ }
1276
+ userErrors {
1277
+ code
1278
+ field
1279
+ message
1280
+ }
1281
+ }
1282
+ }
1283
+ `;
1284
+ async function metafieldsSet(metafields, retries = 1) {
1285
+ const variables = { metafields };
1286
+ const result = await fetchShopifyGraphql(
1287
+ {
1288
+ query: mutation11,
1289
+ variables,
1290
+ retries,
1291
+ dataExtractor: (data) => {
1292
+ if (!data.metafieldsSet) {
1293
+ throw new Error("GraphQL response missing 'metafieldsSet' field");
1294
+ }
1295
+ const { metafields: set, userErrors } = data.metafieldsSet;
1296
+ return {
1297
+ nodes: (set ?? []).map((m) => ({
1298
+ id: m.id,
1299
+ namespace: m.namespace,
1300
+ key: m.key,
1301
+ value: m.value
1302
+ })),
1303
+ userErrors
1304
+ };
1305
+ }
1306
+ }
1307
+ );
1308
+ logger.debug(`Set ${result.length} metafield(s)`);
1309
+ return result;
1310
+ }
1311
+
1312
+ // src/mutations/metafieldDefinitions/createMetafieldDefinition.ts
1313
+ var mutation12 = gql`#graphql
1314
+ mutation createMetafieldDefinition($definition: MetafieldDefinitionInput!) {
1315
+ metafieldDefinitionCreate(definition: $definition) {
1316
+ createdDefinition {
1317
+ id
1318
+ }
1319
+ userErrors {
1320
+ code
1321
+ field
1322
+ message
1323
+ }
1324
+ }
1325
+ }
1326
+ `;
1327
+ async function createMetafieldDefinition(definition, retries = 0) {
1328
+ const variables = { definition };
1329
+ const result = await fetchShopifyGraphql({
1330
+ query: mutation12,
1331
+ variables,
1332
+ retries,
1333
+ dataExtractor: (data) => {
1334
+ if (!data.metafieldDefinitionCreate) {
1335
+ throw new Error(
1336
+ "GraphQL response missing 'metafieldDefinitionCreate' field"
1337
+ );
1338
+ }
1339
+ const { createdDefinition, userErrors } = data.metafieldDefinitionCreate;
1340
+ return {
1341
+ nodes: createdDefinition ? [{ id: createdDefinition.id }] : [],
1342
+ userErrors
1343
+ };
1344
+ }
1345
+ });
1346
+ const created = result[0];
1347
+ if (!created) {
1348
+ throw new Error("Metafield definition creation returned no result");
1349
+ }
1350
+ logger.debug(`Created metafield definition ${created.id}`);
1351
+ return created.id;
1352
+ }
1353
+
1354
+ // src/mutations/metafieldDefinitions/updateMetafieldDefinition.ts
1355
+ var mutation13 = gql`#graphql
1356
+ mutation updateMetafieldDefinition(
1357
+ $definition: MetafieldDefinitionUpdateInput!
1358
+ ) {
1359
+ metafieldDefinitionUpdate(definition: $definition) {
1360
+ updatedDefinition {
1361
+ id
1362
+ }
1363
+ userErrors {
1364
+ code
1365
+ field
1366
+ message
1367
+ }
1368
+ }
1369
+ }
1370
+ `;
1371
+ async function updateMetafieldDefinition(definition, retries = 1) {
1372
+ const variables = { definition };
1373
+ const result = await fetchShopifyGraphql({
1374
+ query: mutation13,
1375
+ variables,
1376
+ retries,
1377
+ dataExtractor: (data) => {
1378
+ if (!data.metafieldDefinitionUpdate) {
1379
+ throw new Error(
1380
+ "GraphQL response missing 'metafieldDefinitionUpdate' field"
1381
+ );
1382
+ }
1383
+ const { updatedDefinition, userErrors } = data.metafieldDefinitionUpdate;
1384
+ return {
1385
+ nodes: updatedDefinition ? [{ id: updatedDefinition.id }] : [],
1386
+ userErrors
1387
+ };
1388
+ }
1389
+ });
1390
+ const updated = result[0]?.id;
1391
+ if (updated) {
1392
+ logger.debug(`Updated metafield definition ${updated}`);
1393
+ }
1394
+ return updated;
1395
+ }
1396
+
1397
+ // src/mutations/customers/updateCustomerEmailMarketingConsent.ts
1398
+ var mutation14 = gql`#graphql
1399
+ mutation updateCustomerEmailMarketingConsent(
1400
+ $input: CustomerEmailMarketingConsentUpdateInput!
1401
+ ) {
1402
+ customerEmailMarketingConsentUpdate(input: $input) {
1403
+ customer {
1404
+ id
1405
+ emailMarketingConsent {
1406
+ marketingState
1407
+ }
1408
+ }
1409
+ userErrors {
1410
+ field
1411
+ message
1412
+ }
1413
+ }
1414
+ }
1415
+ `;
1416
+ async function updateCustomerEmailMarketingConsent(input, retries = 1) {
1417
+ const variables = {
1418
+ input: {
1419
+ customerId: input.customerId,
1420
+ emailMarketingConsent: {
1421
+ marketingState: input.marketingState,
1422
+ marketingOptInLevel: input.marketingOptInLevel
1423
+ }
1424
+ }
1425
+ };
1426
+ const result = await fetchShopifyGraphql({
1427
+ query: mutation14,
1428
+ variables,
1429
+ retries,
1430
+ dataExtractor: (data) => {
1431
+ if (!data.customerEmailMarketingConsentUpdate) {
1432
+ throw new Error(
1433
+ "GraphQL response missing 'customerEmailMarketingConsentUpdate' field"
1434
+ );
1435
+ }
1436
+ const { customer, userErrors } = data.customerEmailMarketingConsentUpdate;
1437
+ return {
1438
+ nodes: customer ? [
1439
+ {
1440
+ id: customer.id,
1441
+ marketingState: customer.emailMarketingConsent?.marketingState ?? null
1442
+ }
1443
+ ] : [],
1444
+ userErrors
1445
+ };
1446
+ }
1447
+ });
1448
+ const updated = result[0];
1449
+ if (!updated) {
1450
+ throw new Error(
1451
+ "Customer email marketing consent update returned no result"
1452
+ );
1453
+ }
1454
+ logger.debug(
1455
+ `Updated customer ${updated.id} email marketing consent to ${updated.marketingState}`
1456
+ );
1457
+ return updated;
1458
+ }
1459
+
1460
+ // src/queries/metaobjects/getMetaobjectsByType.queries.ts
1461
+ var queryMetaobjectsByType = gql`#graphql
1462
+ query metaobjectsByType($type: String!, $first: Int!, $after: String) {
1463
+ metaobjects(type: $type, first: $first, after: $after) {
1464
+ nodes {
1465
+ id
1466
+ handle
1467
+ displayName
1468
+ type
1469
+ fields {
1470
+ key
1471
+ value
1472
+ }
1473
+ }
1474
+ pageInfo {
1475
+ hasNextPage
1476
+ endCursor
1477
+ }
1478
+ }
1479
+ }
1480
+ `;
1481
+
1482
+ // src/queries/metaobjects/getMetaobjectsByType.ts
1483
+ async function getMetaobjectsByType(type, options = {}, retries = 3) {
1484
+ const variables = {
1485
+ type,
1486
+ first: options.pageSize ?? 250
1487
+ };
1488
+ const nodes = await fetchShopifyGraphql({
1489
+ query: queryMetaobjectsByType,
1490
+ variables,
1491
+ fetchAllPages: true,
1492
+ retries,
1493
+ dataExtractor: (data) => {
1494
+ if (!data.metaobjects) {
1495
+ throw new Error("GraphQL response missing 'metaobjects' field");
1496
+ }
1497
+ return {
1498
+ nodes: data.metaobjects.nodes,
1499
+ pageInfo: data.metaobjects.pageInfo
1500
+ };
1501
+ }
1502
+ });
1503
+ logger.debug(`Fetched ${nodes.length} metaobject(s) of type "${type}"`);
1504
+ return nodes;
1505
+ }
1506
+
1507
+ // src/queries/metaobjectDefinitions/getMetaobjectDefinitionByType.queries.ts
1508
+ var queryMetaobjectDefinitionByType = gql`#graphql
1509
+ query metaobjectDefinitionByType($type: String!) {
1510
+ metaobjectDefinitionByType(type: $type) {
1511
+ id
1512
+ type
1513
+ name
1514
+ }
1515
+ }
1516
+ `;
1517
+
1518
+ // src/queries/metaobjectDefinitions/getMetaobjectDefinitionByType.ts
1519
+ async function getMetaobjectDefinitionByType(type, retries = 3) {
1520
+ const variables = { type };
1521
+ const response = await fetchShopifyGraphql({
1522
+ query: queryMetaobjectDefinitionByType,
1523
+ variables,
1524
+ retries
1525
+ });
1526
+ if (!response.metaobjectDefinitionByType) {
1527
+ logger.debug(`No metaobject definition found for type "${type}"`);
1528
+ return void 0;
1529
+ }
1530
+ return response.metaobjectDefinitionByType;
1531
+ }
1532
+
1176
1533
  // src/queries/orders/getOrderById.ts
1177
1534
  var import_zod3 = __toESM(require("zod"), 1);
1178
1535
 
@@ -1297,6 +1654,14 @@ var queryOrderByIdFull = gql`#graphql
1297
1654
  currencyCode
1298
1655
  }
1299
1656
  }
1657
+ discountAllocations {
1658
+ allocatedAmountSet {
1659
+ shopMoney {
1660
+ amount
1661
+ currencyCode
1662
+ }
1663
+ }
1664
+ }
1300
1665
  vendor
1301
1666
  image {
1302
1667
  url
@@ -1313,6 +1678,25 @@ var queryOrderByIdFull = gql`#graphql
1313
1678
  }
1314
1679
  }
1315
1680
  }
1681
+ discountApplications(first: 20) {
1682
+ nodes {
1683
+ allocationMethod
1684
+ targetType
1685
+ value {
1686
+ __typename
1687
+ ... on PricingPercentageValue {
1688
+ percentage
1689
+ }
1690
+ ... on MoneyV2 {
1691
+ amount
1692
+ currencyCode
1693
+ }
1694
+ }
1695
+ ... on DiscountCodeApplication {
1696
+ code
1697
+ }
1698
+ }
1699
+ }
1316
1700
  fulfillments {
1317
1701
  id
1318
1702
  name
@@ -1369,6 +1753,17 @@ var queryOrderByIdFull = gql`#graphql
1369
1753
  currencyCode
1370
1754
  }
1371
1755
  }
1756
+ transactions(first: 50) {
1757
+ nodes {
1758
+ kind
1759
+ amountSet {
1760
+ shopMoney {
1761
+ amount
1762
+ currencyCode
1763
+ }
1764
+ }
1765
+ }
1766
+ }
1372
1767
  }
1373
1768
  }
1374
1769
  }
@@ -2630,10 +3025,12 @@ async function getMetaobjectByHandle(handle, retries = 3) {
2630
3025
  cancelOrderById,
2631
3026
  createFile,
2632
3027
  createFulfillment,
3028
+ createMetafieldDefinition,
2633
3029
  createMetaobjectDefinition,
2634
3030
  createRefund,
2635
3031
  deleteCustomerById,
2636
3032
  deleteFilesByIds,
3033
+ deleteMetaobject,
2637
3034
  getAllProductVariants,
2638
3035
  getCustomerSegmentMembers,
2639
3036
  getCustomersByEmail,
@@ -2642,6 +3039,8 @@ async function getMetaobjectByHandle(handle, retries = 3) {
2642
3039
  getFulfillmentTrackingIds,
2643
3040
  getLeanProductVariants,
2644
3041
  getMetaobjectByHandle,
3042
+ getMetaobjectDefinitionByType,
3043
+ getMetaobjectsByType,
2645
3044
  getOrderById,
2646
3045
  getOrderByName,
2647
3046
  getOrderCancellationInfoByName,
@@ -2649,8 +3048,13 @@ async function getMetaobjectByHandle(handle, retries = 3) {
2649
3048
  getOrdersByCustomerId,
2650
3049
  getProductVariantsBySkus,
2651
3050
  isRetryableError,
3051
+ metafieldsSet,
2652
3052
  parseGid,
3053
+ runShopifyGraphql,
3054
+ setMetaobjectStatus,
3055
+ updateCustomerEmailMarketingConsent,
2653
3056
  updateFulfillmentTracking,
3057
+ updateMetafieldDefinition,
2654
3058
  upsertMetaobject
2655
3059
  });
2656
3060
  //# sourceMappingURL=index.cjs.map