@foxtware/mineral 0.1.14 → 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');
|
|
@@ -106,14 +105,14 @@ const shopifyBulkMutationDo = async (
|
|
|
106
105
|
const { url, parameters } = stagedUploadResponse.data.stagedTargets[0];
|
|
107
106
|
const stagedUploadPath = parameters.find(({ name }) => name === 'key')?.value;
|
|
108
107
|
|
|
109
|
-
const
|
|
108
|
+
const fileBlob = await openAsBlob(filepath, { type: 'text/jsonl' });
|
|
110
109
|
|
|
111
110
|
const formData = objectToFormData(
|
|
112
111
|
Object.fromEntries(parameters.map(({ name, value }) => [name, value])),
|
|
113
112
|
);
|
|
114
113
|
formData.append(
|
|
115
114
|
'file',
|
|
116
|
-
|
|
115
|
+
fileBlob,
|
|
117
116
|
filepath.split('/').pop(),
|
|
118
117
|
);
|
|
119
118
|
|
|
@@ -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
|
+
*/
|