@foxtware/mineral 0.1.33 → 0.1.34

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.
@@ -0,0 +1,116 @@
1
+ // https://shopify.dev/docs/api/admin-graphql/latest/mutations/inventoryitemupdate
2
+
3
+ const { credsValidator } = require('../validators');
4
+ const {
5
+ actionSingleOrMultiple,
6
+ everyIfArray,
7
+ ArgsWarden,
8
+ valueProvided,
9
+ } = require('../utils');
10
+ const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
11
+
12
+ const inventoryItemUpdatePayloadValidator = (updatePayload) => {
13
+ return valueProvided(updatePayload)
14
+ && typeof updatePayload === 'object'
15
+ && !Array.isArray(updatePayload);
16
+ };
17
+
18
+ const argsWarden = new ArgsWarden([
19
+ ['credsPayload', credsValidator],
20
+ ['inventoryItemId', (id) => everyIfArray(valueProvided, id)],
21
+ ['updatePayload', (payload) => everyIfArray(inventoryItemUpdatePayloadValidator, payload)],
22
+ ]);
23
+
24
+ const defaultReturnInventoryItemAttrs = 'id countryCodeOfOrigin harmonizedSystemCode';
25
+
26
+ const shopifyInventoryItemUpdateSingle = async (
27
+ credsPayload,
28
+ inventoryItemId,
29
+ updatePayload,
30
+ {
31
+ apiVersion,
32
+ returnInventoryItemAttrs = defaultReturnInventoryItemAttrs,
33
+ } = {},
34
+ ) => {
35
+
36
+ return shopifyMutationDo(
37
+ credsPayload,
38
+ 'inventoryItemUpdate',
39
+ {
40
+ mutationVariables: {
41
+ id: {
42
+ type: 'ID!',
43
+ value: `gid://shopify/InventoryItem/${ inventoryItemId }`,
44
+ },
45
+ input: {
46
+ type: 'InventoryItemInput!',
47
+ value: updatePayload,
48
+ },
49
+ },
50
+ returnSchema: `inventoryItem { ${ returnInventoryItemAttrs } }`,
51
+ apiVersion,
52
+ },
53
+ );
54
+ };
55
+
56
+ const shopifyInventoryItemUpdate = async (
57
+ credsPayload,
58
+ inventoryItemId,
59
+ updatePayload,
60
+ {
61
+ queueRunOptions,
62
+ apiVersion,
63
+ returnInventoryItemAttrs = defaultReturnInventoryItemAttrs,
64
+ } = {},
65
+ ) => {
66
+
67
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
68
+ credsPayload,
69
+ inventoryItemId,
70
+ updatePayload,
71
+ });
72
+ if (rejectResponse) {
73
+ return rejectResponse;
74
+ }
75
+
76
+ return actionSingleOrMultiple(
77
+ [inventoryItemId, updatePayload],
78
+ shopifyInventoryItemUpdateSingle,
79
+ (inventoryItemIdItem, updatePayloadItem) => ({
80
+ args: [
81
+ credsPayload,
82
+ inventoryItemIdItem,
83
+ updatePayloadItem,
84
+ {
85
+ apiVersion,
86
+ returnInventoryItemAttrs,
87
+ },
88
+ ],
89
+ }),
90
+ {
91
+ ...(queueRunOptions ? { queueRunOptions } : {}),
92
+ },
93
+ );
94
+ };
95
+
96
+ const funcApiConfig = {
97
+ argsWarden,
98
+ };
99
+
100
+ module.exports = {
101
+ shopifyInventoryItemUpdate,
102
+ funcApiConfig,
103
+ };
104
+
105
+ /*
106
+ curl -X POST "http://localhost:8000/shopifyInventoryItemUpdate" \
107
+ -H "Content-Type: application/json" \
108
+ -d '{
109
+ "credsPayload": { "credsPath": "shopify.au" },
110
+ "inventoryItemId": "43729076",
111
+ "updatePayload": {
112
+ "countryCodeOfOrigin": "US",
113
+ "harmonizedSystemCode": "621710"
114
+ }
115
+ }'
116
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxtware/mineral",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "bin": {
5
5
  "mineral": "bin/mineral.js"
6
6
  },