@ehrenkind/shopify-lib 0.7.4 → 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.mjs CHANGED
@@ -264,7 +264,7 @@ async function makeRequest(query, variables, retries = 0) {
264
264
 
265
265
  // src/mutations/customers/deleteCustomerById.ts
266
266
  async function deleteCustomerById(customerId, retries = 1) {
267
- const mutation9 = gql`#graphql
267
+ const mutation15 = gql`#graphql
268
268
  mutation customerDelete($input: CustomerDeleteInput!) {
269
269
  customerDelete(input: $input) {
270
270
  deletedCustomerId
@@ -279,7 +279,7 @@ async function deleteCustomerById(customerId, retries = 1) {
279
279
  input: { id: customerId }
280
280
  };
281
281
  const response = await fetchShopifyGraphql({
282
- query: mutation9,
282
+ query: mutation15,
283
283
  variables,
284
284
  retries,
285
285
  dataExtractor: (data) => {
@@ -302,7 +302,7 @@ async function deleteFilesByIds(fileIds, retries = 1) {
302
302
  if (fileIds.length === 0) {
303
303
  return [];
304
304
  }
305
- const mutation9 = gql`#graphql
305
+ const mutation15 = gql`#graphql
306
306
  mutation fileDelete($fileIds: [ID!]!) {
307
307
  fileDelete(fileIds: $fileIds) {
308
308
  deletedFileIds
@@ -316,7 +316,7 @@ async function deleteFilesByIds(fileIds, retries = 1) {
316
316
  `;
317
317
  const variables = { fileIds };
318
318
  const response = await fetchShopifyGraphql({
319
- query: mutation9,
319
+ query: mutation15,
320
320
  variables,
321
321
  retries,
322
322
  dataExtractor: (data) => {
@@ -411,7 +411,9 @@ async function createMetaobjectDefinition(input, retries = 0) {
411
411
  name: input.name,
412
412
  description: input.description,
413
413
  displayNameKey: input.displayNameKey,
414
- fieldDefinitions: input.fieldDefinitions
414
+ fieldDefinitions: input.fieldDefinitions,
415
+ access: input.access,
416
+ capabilities: input.capabilities
415
417
  }
416
418
  };
417
419
  const result = await fetchShopifyGraphql({
@@ -1114,6 +1116,352 @@ async function calculateRefund(orderId, options = {}, retries = 3) {
1114
1116
  return response.order.suggestedRefund;
1115
1117
  }
1116
1118
 
1119
+ // src/mutations/metaobjects/setMetaobjectStatus.ts
1120
+ var mutation9 = gql`#graphql
1121
+ mutation setMetaobjectStatus($id: ID!, $metaobject: MetaobjectUpdateInput!) {
1122
+ metaobjectUpdate(id: $id, metaobject: $metaobject) {
1123
+ metaobject {
1124
+ id
1125
+ }
1126
+ userErrors {
1127
+ code
1128
+ field
1129
+ message
1130
+ }
1131
+ }
1132
+ }
1133
+ `;
1134
+ async function setMetaobjectStatus(id, status, retries = 1) {
1135
+ const variables = {
1136
+ id,
1137
+ metaobject: {
1138
+ capabilities: {
1139
+ publishable: { status }
1140
+ }
1141
+ }
1142
+ };
1143
+ await fetchShopifyGraphql({
1144
+ query: mutation9,
1145
+ variables,
1146
+ retries,
1147
+ dataExtractor: (data) => {
1148
+ if (!data.metaobjectUpdate) {
1149
+ throw new Error("GraphQL response missing 'metaobjectUpdate' field");
1150
+ }
1151
+ const { metaobject, userErrors } = data.metaobjectUpdate;
1152
+ return {
1153
+ nodes: metaobject ? [{ id: metaobject.id }] : [],
1154
+ userErrors
1155
+ };
1156
+ }
1157
+ });
1158
+ logger.debug(`Set metaobject ${id} status to ${status}`);
1159
+ }
1160
+
1161
+ // src/mutations/metaobjects/deleteMetaobject.ts
1162
+ var mutation10 = gql`#graphql
1163
+ mutation deleteMetaobject($id: ID!) {
1164
+ metaobjectDelete(id: $id) {
1165
+ deletedId
1166
+ userErrors {
1167
+ code
1168
+ field
1169
+ message
1170
+ }
1171
+ }
1172
+ }
1173
+ `;
1174
+ async function deleteMetaobject(id, retries = 0) {
1175
+ const variables = { id };
1176
+ const result = await fetchShopifyGraphql({
1177
+ query: mutation10,
1178
+ variables,
1179
+ retries,
1180
+ dataExtractor: (data) => {
1181
+ if (!data.metaobjectDelete) {
1182
+ throw new Error("GraphQL response missing 'metaobjectDelete' field");
1183
+ }
1184
+ const { deletedId: deletedId2, userErrors } = data.metaobjectDelete;
1185
+ return {
1186
+ nodes: [{ deletedId: deletedId2 ?? null }],
1187
+ userErrors
1188
+ };
1189
+ }
1190
+ });
1191
+ const deletedId = result[0]?.deletedId ?? void 0;
1192
+ if (deletedId) {
1193
+ logger.debug(`Deleted metaobject ${deletedId}`);
1194
+ }
1195
+ return deletedId;
1196
+ }
1197
+
1198
+ // src/mutations/metafields/metafieldsSet.ts
1199
+ var mutation11 = gql`#graphql
1200
+ mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
1201
+ metafieldsSet(metafields: $metafields) {
1202
+ metafields {
1203
+ id
1204
+ namespace
1205
+ key
1206
+ value
1207
+ }
1208
+ userErrors {
1209
+ code
1210
+ field
1211
+ message
1212
+ }
1213
+ }
1214
+ }
1215
+ `;
1216
+ async function metafieldsSet(metafields, retries = 1) {
1217
+ const variables = { metafields };
1218
+ const result = await fetchShopifyGraphql(
1219
+ {
1220
+ query: mutation11,
1221
+ variables,
1222
+ retries,
1223
+ dataExtractor: (data) => {
1224
+ if (!data.metafieldsSet) {
1225
+ throw new Error("GraphQL response missing 'metafieldsSet' field");
1226
+ }
1227
+ const { metafields: set, userErrors } = data.metafieldsSet;
1228
+ return {
1229
+ nodes: (set ?? []).map((m) => ({
1230
+ id: m.id,
1231
+ namespace: m.namespace,
1232
+ key: m.key,
1233
+ value: m.value
1234
+ })),
1235
+ userErrors
1236
+ };
1237
+ }
1238
+ }
1239
+ );
1240
+ logger.debug(`Set ${result.length} metafield(s)`);
1241
+ return result;
1242
+ }
1243
+
1244
+ // src/mutations/metafieldDefinitions/createMetafieldDefinition.ts
1245
+ var mutation12 = gql`#graphql
1246
+ mutation createMetafieldDefinition($definition: MetafieldDefinitionInput!) {
1247
+ metafieldDefinitionCreate(definition: $definition) {
1248
+ createdDefinition {
1249
+ id
1250
+ }
1251
+ userErrors {
1252
+ code
1253
+ field
1254
+ message
1255
+ }
1256
+ }
1257
+ }
1258
+ `;
1259
+ async function createMetafieldDefinition(definition, retries = 0) {
1260
+ const variables = { definition };
1261
+ const result = await fetchShopifyGraphql({
1262
+ query: mutation12,
1263
+ variables,
1264
+ retries,
1265
+ dataExtractor: (data) => {
1266
+ if (!data.metafieldDefinitionCreate) {
1267
+ throw new Error(
1268
+ "GraphQL response missing 'metafieldDefinitionCreate' field"
1269
+ );
1270
+ }
1271
+ const { createdDefinition, userErrors } = data.metafieldDefinitionCreate;
1272
+ return {
1273
+ nodes: createdDefinition ? [{ id: createdDefinition.id }] : [],
1274
+ userErrors
1275
+ };
1276
+ }
1277
+ });
1278
+ const created = result[0];
1279
+ if (!created) {
1280
+ throw new Error("Metafield definition creation returned no result");
1281
+ }
1282
+ logger.debug(`Created metafield definition ${created.id}`);
1283
+ return created.id;
1284
+ }
1285
+
1286
+ // src/mutations/metafieldDefinitions/updateMetafieldDefinition.ts
1287
+ var mutation13 = gql`#graphql
1288
+ mutation updateMetafieldDefinition(
1289
+ $definition: MetafieldDefinitionUpdateInput!
1290
+ ) {
1291
+ metafieldDefinitionUpdate(definition: $definition) {
1292
+ updatedDefinition {
1293
+ id
1294
+ }
1295
+ userErrors {
1296
+ code
1297
+ field
1298
+ message
1299
+ }
1300
+ }
1301
+ }
1302
+ `;
1303
+ async function updateMetafieldDefinition(definition, retries = 1) {
1304
+ const variables = { definition };
1305
+ const result = await fetchShopifyGraphql({
1306
+ query: mutation13,
1307
+ variables,
1308
+ retries,
1309
+ dataExtractor: (data) => {
1310
+ if (!data.metafieldDefinitionUpdate) {
1311
+ throw new Error(
1312
+ "GraphQL response missing 'metafieldDefinitionUpdate' field"
1313
+ );
1314
+ }
1315
+ const { updatedDefinition, userErrors } = data.metafieldDefinitionUpdate;
1316
+ return {
1317
+ nodes: updatedDefinition ? [{ id: updatedDefinition.id }] : [],
1318
+ userErrors
1319
+ };
1320
+ }
1321
+ });
1322
+ const updated = result[0]?.id;
1323
+ if (updated) {
1324
+ logger.debug(`Updated metafield definition ${updated}`);
1325
+ }
1326
+ return updated;
1327
+ }
1328
+
1329
+ // src/mutations/customers/updateCustomerEmailMarketingConsent.ts
1330
+ var mutation14 = gql`#graphql
1331
+ mutation updateCustomerEmailMarketingConsent(
1332
+ $input: CustomerEmailMarketingConsentUpdateInput!
1333
+ ) {
1334
+ customerEmailMarketingConsentUpdate(input: $input) {
1335
+ customer {
1336
+ id
1337
+ emailMarketingConsent {
1338
+ marketingState
1339
+ }
1340
+ }
1341
+ userErrors {
1342
+ field
1343
+ message
1344
+ }
1345
+ }
1346
+ }
1347
+ `;
1348
+ async function updateCustomerEmailMarketingConsent(input, retries = 1) {
1349
+ const variables = {
1350
+ input: {
1351
+ customerId: input.customerId,
1352
+ emailMarketingConsent: {
1353
+ marketingState: input.marketingState,
1354
+ marketingOptInLevel: input.marketingOptInLevel
1355
+ }
1356
+ }
1357
+ };
1358
+ const result = await fetchShopifyGraphql({
1359
+ query: mutation14,
1360
+ variables,
1361
+ retries,
1362
+ dataExtractor: (data) => {
1363
+ if (!data.customerEmailMarketingConsentUpdate) {
1364
+ throw new Error(
1365
+ "GraphQL response missing 'customerEmailMarketingConsentUpdate' field"
1366
+ );
1367
+ }
1368
+ const { customer, userErrors } = data.customerEmailMarketingConsentUpdate;
1369
+ return {
1370
+ nodes: customer ? [
1371
+ {
1372
+ id: customer.id,
1373
+ marketingState: customer.emailMarketingConsent?.marketingState ?? null
1374
+ }
1375
+ ] : [],
1376
+ userErrors
1377
+ };
1378
+ }
1379
+ });
1380
+ const updated = result[0];
1381
+ if (!updated) {
1382
+ throw new Error(
1383
+ "Customer email marketing consent update returned no result"
1384
+ );
1385
+ }
1386
+ logger.debug(
1387
+ `Updated customer ${updated.id} email marketing consent to ${updated.marketingState}`
1388
+ );
1389
+ return updated;
1390
+ }
1391
+
1392
+ // src/queries/metaobjects/getMetaobjectsByType.queries.ts
1393
+ var queryMetaobjectsByType = gql`#graphql
1394
+ query metaobjectsByType($type: String!, $first: Int!, $after: String) {
1395
+ metaobjects(type: $type, first: $first, after: $after) {
1396
+ nodes {
1397
+ id
1398
+ handle
1399
+ displayName
1400
+ type
1401
+ fields {
1402
+ key
1403
+ value
1404
+ }
1405
+ }
1406
+ pageInfo {
1407
+ hasNextPage
1408
+ endCursor
1409
+ }
1410
+ }
1411
+ }
1412
+ `;
1413
+
1414
+ // src/queries/metaobjects/getMetaobjectsByType.ts
1415
+ async function getMetaobjectsByType(type, options = {}, retries = 3) {
1416
+ const variables = {
1417
+ type,
1418
+ first: options.pageSize ?? 250
1419
+ };
1420
+ const nodes = await fetchShopifyGraphql({
1421
+ query: queryMetaobjectsByType,
1422
+ variables,
1423
+ fetchAllPages: true,
1424
+ retries,
1425
+ dataExtractor: (data) => {
1426
+ if (!data.metaobjects) {
1427
+ throw new Error("GraphQL response missing 'metaobjects' field");
1428
+ }
1429
+ return {
1430
+ nodes: data.metaobjects.nodes,
1431
+ pageInfo: data.metaobjects.pageInfo
1432
+ };
1433
+ }
1434
+ });
1435
+ logger.debug(`Fetched ${nodes.length} metaobject(s) of type "${type}"`);
1436
+ return nodes;
1437
+ }
1438
+
1439
+ // src/queries/metaobjectDefinitions/getMetaobjectDefinitionByType.queries.ts
1440
+ var queryMetaobjectDefinitionByType = gql`#graphql
1441
+ query metaobjectDefinitionByType($type: String!) {
1442
+ metaobjectDefinitionByType(type: $type) {
1443
+ id
1444
+ type
1445
+ name
1446
+ }
1447
+ }
1448
+ `;
1449
+
1450
+ // src/queries/metaobjectDefinitions/getMetaobjectDefinitionByType.ts
1451
+ async function getMetaobjectDefinitionByType(type, retries = 3) {
1452
+ const variables = { type };
1453
+ const response = await fetchShopifyGraphql({
1454
+ query: queryMetaobjectDefinitionByType,
1455
+ variables,
1456
+ retries
1457
+ });
1458
+ if (!response.metaobjectDefinitionByType) {
1459
+ logger.debug(`No metaobject definition found for type "${type}"`);
1460
+ return void 0;
1461
+ }
1462
+ return response.metaobjectDefinitionByType;
1463
+ }
1464
+
1117
1465
  // src/queries/orders/getOrderById.ts
1118
1466
  import z3 from "zod";
1119
1467
 
@@ -1238,6 +1586,14 @@ var queryOrderByIdFull = gql`#graphql
1238
1586
  currencyCode
1239
1587
  }
1240
1588
  }
1589
+ discountAllocations {
1590
+ allocatedAmountSet {
1591
+ shopMoney {
1592
+ amount
1593
+ currencyCode
1594
+ }
1595
+ }
1596
+ }
1241
1597
  vendor
1242
1598
  image {
1243
1599
  url
@@ -1254,6 +1610,25 @@ var queryOrderByIdFull = gql`#graphql
1254
1610
  }
1255
1611
  }
1256
1612
  }
1613
+ discountApplications(first: 20) {
1614
+ nodes {
1615
+ allocationMethod
1616
+ targetType
1617
+ value {
1618
+ __typename
1619
+ ... on PricingPercentageValue {
1620
+ percentage
1621
+ }
1622
+ ... on MoneyV2 {
1623
+ amount
1624
+ currencyCode
1625
+ }
1626
+ }
1627
+ ... on DiscountCodeApplication {
1628
+ code
1629
+ }
1630
+ }
1631
+ }
1257
1632
  fulfillments {
1258
1633
  id
1259
1634
  name
@@ -1310,6 +1685,17 @@ var queryOrderByIdFull = gql`#graphql
1310
1685
  currencyCode
1311
1686
  }
1312
1687
  }
1688
+ transactions(first: 50) {
1689
+ nodes {
1690
+ kind
1691
+ amountSet {
1692
+ shopMoney {
1693
+ amount
1694
+ currencyCode
1695
+ }
1696
+ }
1697
+ }
1698
+ }
1313
1699
  }
1314
1700
  }
1315
1701
  }
@@ -2202,6 +2588,7 @@ var queryOrderPaymentDetails = gql`#graphql
2202
2588
  gateway
2203
2589
  formattedGateway
2204
2590
  kind
2591
+ status
2205
2592
  paymentId
2206
2593
  }
2207
2594
  }
@@ -2569,10 +2956,12 @@ export {
2569
2956
  cancelOrderById,
2570
2957
  createFile,
2571
2958
  createFulfillment,
2959
+ createMetafieldDefinition,
2572
2960
  createMetaobjectDefinition,
2573
2961
  createRefund,
2574
2962
  deleteCustomerById,
2575
2963
  deleteFilesByIds,
2964
+ deleteMetaobject,
2576
2965
  getAllProductVariants,
2577
2966
  getCustomerSegmentMembers,
2578
2967
  getCustomersByEmail,
@@ -2581,6 +2970,8 @@ export {
2581
2970
  getFulfillmentTrackingIds,
2582
2971
  getLeanProductVariants,
2583
2972
  getMetaobjectByHandle,
2973
+ getMetaobjectDefinitionByType,
2974
+ getMetaobjectsByType,
2584
2975
  getOrderById,
2585
2976
  getOrderByName,
2586
2977
  getOrderCancellationInfoByName,
@@ -2588,8 +2979,13 @@ export {
2588
2979
  getOrdersByCustomerId,
2589
2980
  getProductVariantsBySkus,
2590
2981
  isRetryableError,
2982
+ metafieldsSet,
2591
2983
  parseGid,
2984
+ fetchShopifyGraphql as runShopifyGraphql,
2985
+ setMetaobjectStatus,
2986
+ updateCustomerEmailMarketingConsent,
2592
2987
  updateFulfillmentTracking,
2988
+ updateMetafieldDefinition,
2593
2989
  upsertMetaobject
2594
2990
  };
2595
2991
  //# sourceMappingURL=index.mjs.map