@foxtware/mineral 0.1.13 → 0.1.15
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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { randomUUID } = require('crypto');
|
|
2
|
-
const {
|
|
3
|
-
const fs = require('fs').promises;
|
|
2
|
+
const { openAsBlob, promises: fs } = require('fs');
|
|
4
3
|
|
|
5
4
|
const { HOSTED, TEMP_DIR } = require('../constants');
|
|
6
5
|
const { credsValidator } = require('../validators');
|
|
@@ -61,7 +60,7 @@ const shopifyBulkMutationDo = async (
|
|
|
61
60
|
return rejectResponse;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
let {
|
|
65
64
|
mutation,
|
|
66
65
|
input,
|
|
67
66
|
bulkOperationId,
|
|
@@ -104,11 +103,18 @@ const shopifyBulkMutationDo = async (
|
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
const { url, parameters } = stagedUploadResponse.data.stagedTargets[0];
|
|
106
|
+
const stagedUploadPath = parameters.find(({ name }) => name === 'key')?.value;
|
|
107
|
+
|
|
108
|
+
const fileBlob = await openAsBlob(filepath, { type: 'text/jsonl' });
|
|
107
109
|
|
|
108
110
|
const formData = objectToFormData(
|
|
109
111
|
Object.fromEntries(parameters.map(({ name, value }) => [name, value])),
|
|
110
112
|
);
|
|
111
|
-
formData.append(
|
|
113
|
+
formData.append(
|
|
114
|
+
'file',
|
|
115
|
+
fileBlob,
|
|
116
|
+
filepath.split('/').pop(),
|
|
117
|
+
);
|
|
112
118
|
|
|
113
119
|
const uploadResponse = await customFetch(url, {
|
|
114
120
|
method: 'post',
|
|
@@ -118,8 +124,6 @@ const shopifyBulkMutationDo = async (
|
|
|
118
124
|
return uploadResponse;
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
const stagedUploadPath = uploadResponse.data?.PostResponse?.Key;
|
|
122
|
-
|
|
123
127
|
const mutationRunResponse = await shopifyBulkOperationRunMutation(
|
|
124
128
|
credsPayload,
|
|
125
129
|
mutation,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/tagsRemove
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyBulkMutationDo } = require('./shopifyBulkMutationDo');
|
|
6
|
+
|
|
7
|
+
const tagsRemoveBulkMutation = `
|
|
8
|
+
mutation call($id: ID!, $tags: [String!]!) {
|
|
9
|
+
tagsRemove(id: $id, tags: $tags) {
|
|
10
|
+
node {
|
|
11
|
+
id
|
|
12
|
+
}
|
|
13
|
+
userErrors {
|
|
14
|
+
field
|
|
15
|
+
message
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`.trim();
|
|
20
|
+
|
|
21
|
+
const argsWarden = new ArgsWarden([
|
|
22
|
+
['credsPayload', credsValidator],
|
|
23
|
+
['gids', Array.isArray],
|
|
24
|
+
['tags', Array.isArray],
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const shopifyTagsRemoveBulk = async (
|
|
28
|
+
credsPayload,
|
|
29
|
+
gids,
|
|
30
|
+
tags,
|
|
31
|
+
{
|
|
32
|
+
...bulkMutationOptions
|
|
33
|
+
} = {},
|
|
34
|
+
) => {
|
|
35
|
+
|
|
36
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
37
|
+
credsPayload,
|
|
38
|
+
gids,
|
|
39
|
+
tags,
|
|
40
|
+
});
|
|
41
|
+
if (rejectResponse) {
|
|
42
|
+
return rejectResponse;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return shopifyBulkMutationDo(
|
|
46
|
+
credsPayload,
|
|
47
|
+
{
|
|
48
|
+
mutation: tagsRemoveBulkMutation,
|
|
49
|
+
input: {
|
|
50
|
+
data: gids.map((gid) => ({
|
|
51
|
+
id: gid,
|
|
52
|
+
tags,
|
|
53
|
+
})),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
bulkMutationOptions,
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const funcApiConfig = {
|
|
61
|
+
argsWarden,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
shopifyTagsRemoveBulk,
|
|
66
|
+
funcApiConfig,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
curl -X POST "http://localhost:8000/shopifyTagsRemoveBulk" \
|
|
71
|
+
-H "Content-Type: application/json" \
|
|
72
|
+
-d '{
|
|
73
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
74
|
+
"gids": ["gid://shopify/Customer/123", "gid://shopify/Customer/456"],
|
|
75
|
+
"tags": ["martian_sympathisers"]
|
|
76
|
+
}'
|
|
77
|
+
*/
|
package/api/utils.js
CHANGED