@foxtware/mineral 0.1.33 → 0.1.35
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/api/shopify/shopifyInventoryItemUpdate.js +116 -0
- package/api/utils.js +21 -0
- package/package.json +1 -1
|
@@ -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/api/utils.js
CHANGED
|
@@ -1494,6 +1494,26 @@ const randomArrayItem = (array) => {
|
|
|
1494
1494
|
return array[Math.floor(Math.random() * array.length)];
|
|
1495
1495
|
};
|
|
1496
1496
|
|
|
1497
|
+
const oneTrickProcessor = (
|
|
1498
|
+
func,
|
|
1499
|
+
pile,
|
|
1500
|
+
{
|
|
1501
|
+
responseHandler,
|
|
1502
|
+
...processorOptions
|
|
1503
|
+
} = {},
|
|
1504
|
+
) => {
|
|
1505
|
+
// Runs a single function, going through a pile that is args as an array
|
|
1506
|
+
const processor = new Processor(
|
|
1507
|
+
pile,
|
|
1508
|
+
async (pile) => {
|
|
1509
|
+
const args = pile.shift();
|
|
1510
|
+
const response = await func(...args);
|
|
1511
|
+
return responseHandler ? await responseHandler(response) : response;
|
|
1512
|
+
},
|
|
1513
|
+
processorOptions,
|
|
1514
|
+
);
|
|
1515
|
+
};
|
|
1516
|
+
|
|
1497
1517
|
module.exports = {
|
|
1498
1518
|
wait,
|
|
1499
1519
|
timeMs,
|
|
@@ -1539,4 +1559,5 @@ module.exports = {
|
|
|
1539
1559
|
diffObjects,
|
|
1540
1560
|
objectPropsTranslate,
|
|
1541
1561
|
randomArrayItem,
|
|
1562
|
+
oneTrickProcessor,
|
|
1542
1563
|
};
|