@foxtware/mineral 0.1.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/.creds.yml.sample +21 -0
- package/AGENTS.md +13 -0
- package/README.md +52 -0
- package/_build_scripts/copyCredsToEnv.js +45 -0
- package/_build_scripts/createNewFunction.js +361 -0
- package/_docs/standard_response_examples.md +67 -0
- package/api/_example.js +45 -0
- package/api/constants.js +3 -0
- package/api/linear/linear.constants.js +5 -0
- package/api/linear/linear.utils.js +43 -0
- package/api/linear/linearIssuesGet.js +106 -0
- package/api/peoplevox/.gitkeep +0 -0
- package/api/peoplevox/_example.js +49 -0
- package/api/peoplevox/peoplevox.constants.js +3 -0
- package/api/peoplevox/peoplevox.utils.js +191 -0
- package/api/peoplevox/peoplevoxAuthGet.js +99 -0
- package/api/peoplevox/peoplevoxGetSingle.js +119 -0
- package/api/peoplevox/peoplevoxOrderEdit.js +82 -0
- package/api/peoplevox/peoplevoxOrderGet.js +60 -0
- package/api/peoplevox/peoplevoxReportGet.js +76 -0
- package/api/shopify/.gitkeep +0 -0
- package/api/shopify/_example.create.js +69 -0
- package/api/shopify/_example.getsingle.js +55 -0
- package/api/shopify/_example.js +45 -0
- package/api/shopify/_example.mutation.js +58 -0
- package/api/shopify/shopify.constants.js +7 -0
- package/api/shopify/shopify.utils.js +123 -0
- package/api/shopify/shopifyCollectionGet.js +109 -0
- package/api/shopify/shopifyCustomerCreate.js +71 -0
- package/api/shopify/shopifyCustomerGet.js +112 -0
- package/api/shopify/shopifyCustomerMarketingConsentUpdateEmail.js +84 -0
- package/api/shopify/shopifyCustomerUpdate.js +75 -0
- package/api/shopify/shopifyCustomersGet.js +50 -0
- package/api/shopify/shopifyGet.js +309 -0
- package/api/shopify/shopifyGetSingle.js +106 -0
- package/api/shopify/shopifyGiftCardCreate.js +95 -0
- package/api/shopify/shopifyGiftCardDeactivate.js +58 -0
- package/api/shopify/shopifyMetafieldsSet.js +100 -0
- package/api/shopify/shopifyMutationDo.js +95 -0
- package/api/shopify/shopifyOrderGet.js +123 -0
- package/api/shopify/shopifyOrdersGet.js +80 -0
- package/api/shopify/shopifyPageDelete.js +59 -0
- package/api/shopify/shopifyPageGet.js +57 -0
- package/api/shopify/shopifyPageUpdate.js +79 -0
- package/api/shopify/shopifyTagsAdd.js +94 -0
- package/api/shopify/shopifyTagsRemove.js +94 -0
- package/api/shopify/shopifyThemeDelete.js +87 -0
- package/api/shopify/shopifyThemeDuplicate.js +70 -0
- package/api/shopify/shopifyThemeGet.js +59 -0
- package/api/shopify/shopifyThemeUpdate.js +71 -0
- package/api/shopify/shopifyThemesGet.js +63 -0
- package/api/utils.js +1166 -0
- package/api/validators.js +12 -0
- package/api/yotpo/yotpo.constants.js +7 -0
- package/api/yotpo/yotpo.utils.js +47 -0
- package/api/yotpo/yotpoCampaignsGet.js +75 -0
- package/api/yotpo/yotpoCustomerActionRecord.js +95 -0
- package/api/yotpo/yotpoCustomerAnniversaryGet.js +60 -0
- package/api/yotpo/yotpoCustomerAnniversarySet.js +78 -0
- package/api/yotpo/yotpoCustomerBirthdaySet.js +91 -0
- package/api/yotpo/yotpoCustomerGet.js +104 -0
- package/api/yotpo/yotpoCustomerPointsAdjust.js +89 -0
- package/api/yotpo/yotpoCustomerUpsert.js +91 -0
- package/api/yotpo/yotpoCustomersRecentGet.js +62 -0
- package/api/yotpo/yotpoRedemptionCreate.js +96 -0
- package/api/yotpo/yotpoRedemptionOptionsGet.js +78 -0
- package/api/yotpo/yotpoVipTiersGet.js +51 -0
- package/api/youtube/youtubeChannelVideosGet.js +249 -0
- package/bin/mineral.js +5 -0
- package/package.json +24 -0
- package/server.js +196 -0
- package/server.utils.js +228 -0
- package/test.js +19 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const { credsFromPayload, capitaliseString, ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { shopifyClient } = require('./shopify.utils');
|
|
4
|
+
|
|
5
|
+
const resourcesNotRequiringId = ['shop'];
|
|
6
|
+
|
|
7
|
+
const defaultAttrs = 'id';
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['resource'],
|
|
12
|
+
['id', (id, context) => resourcesNotRequiringId.includes(context.resource) || Boolean(id)],
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const shopifyGetSingle = async (
|
|
16
|
+
credsPayload,
|
|
17
|
+
resource,
|
|
18
|
+
id,
|
|
19
|
+
{
|
|
20
|
+
apiVersion,
|
|
21
|
+
attrs = defaultAttrs,
|
|
22
|
+
gidType,
|
|
23
|
+
} = {},
|
|
24
|
+
) => {
|
|
25
|
+
|
|
26
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs(
|
|
27
|
+
{
|
|
28
|
+
credsPayload,
|
|
29
|
+
resource,
|
|
30
|
+
id,
|
|
31
|
+
},
|
|
32
|
+
{ resource },
|
|
33
|
+
);
|
|
34
|
+
if (rejectResponse) {
|
|
35
|
+
return rejectResponse;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const creds = await credsFromPayload(credsPayload);
|
|
39
|
+
|
|
40
|
+
const Resource = capitaliseString(resource);
|
|
41
|
+
const usesId = !resourcesNotRequiringId.includes(resource);
|
|
42
|
+
|
|
43
|
+
const query = `
|
|
44
|
+
query Get${ Resource }${ usesId ? '($id: ID!)' : '' } {
|
|
45
|
+
${ resource }${ usesId ? '(id: $id)' : '' } {
|
|
46
|
+
${ attrs }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const response = await shopifyClient.fetch({
|
|
52
|
+
method: 'post',
|
|
53
|
+
body: {
|
|
54
|
+
query,
|
|
55
|
+
variables: {
|
|
56
|
+
...(usesId ? { id: `gid://shopify/${ gidType || Resource }/${ id }` } : {}),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
context: {
|
|
60
|
+
creds,
|
|
61
|
+
apiVersion,
|
|
62
|
+
resultPath: `data.${ resource }`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return response;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const funcApiConfig = {
|
|
70
|
+
argsWarden,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
shopifyGetSingle,
|
|
75
|
+
funcApiConfig,
|
|
76
|
+
};
|
|
77
|
+
/*
|
|
78
|
+
|
|
79
|
+
curl -X POST "http://localhost:8000/shopifyGetSingle" \
|
|
80
|
+
-H "Content-Type: application/json" \
|
|
81
|
+
-d '{
|
|
82
|
+
"credsPayload": {
|
|
83
|
+
"credsObject": {
|
|
84
|
+
"STORE_HANDLE": "arisawa-heavy-industries",
|
|
85
|
+
"API_KEY": "shpat_xxx"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"resource": "order",
|
|
89
|
+
"id": "1234567890",
|
|
90
|
+
"options": {
|
|
91
|
+
"attrs": "id name"
|
|
92
|
+
}
|
|
93
|
+
}'
|
|
94
|
+
|
|
95
|
+
curl -X POST "http://localhost:8000/shopifyGetSingle" \
|
|
96
|
+
-H "Content-Type: application/json" \
|
|
97
|
+
-d '{
|
|
98
|
+
"credsPayload": {
|
|
99
|
+
"credsPath": "shopify.au"
|
|
100
|
+
},
|
|
101
|
+
"resource": "shop",
|
|
102
|
+
"options": {
|
|
103
|
+
"attrs": "id name primaryDomain { url } myshopifyDomain"
|
|
104
|
+
}
|
|
105
|
+
}'
|
|
106
|
+
*/
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/giftCardCreate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const giftCardInputValidator = (giftCardInput) => {
|
|
8
|
+
if (!giftCardInput || typeof giftCardInput !== 'object') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const initialValue = parseFloat(giftCardInput.initialValue);
|
|
13
|
+
return !isNaN(initialValue) && initialValue > 0;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const argsWarden = new ArgsWarden([
|
|
17
|
+
['credsPayload', credsValidator],
|
|
18
|
+
['giftCardInput', giftCardInputValidator],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const defaultReturnGiftCardAttrs = 'id initialValue { amount } customer { id }';
|
|
22
|
+
|
|
23
|
+
const shopifyGiftCardCreate = async (
|
|
24
|
+
credsPayload,
|
|
25
|
+
giftCardInput,
|
|
26
|
+
{
|
|
27
|
+
apiVersion,
|
|
28
|
+
returnGiftCardAttrs = defaultReturnGiftCardAttrs,
|
|
29
|
+
} = {},
|
|
30
|
+
) => {
|
|
31
|
+
|
|
32
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, giftCardInput });
|
|
33
|
+
if (rejectResponse) {
|
|
34
|
+
return rejectResponse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return shopifyMutationDo(
|
|
38
|
+
credsPayload,
|
|
39
|
+
'giftCardCreate',
|
|
40
|
+
{
|
|
41
|
+
mutationVariables: {
|
|
42
|
+
input: {
|
|
43
|
+
type: 'GiftCardCreateInput!',
|
|
44
|
+
value: giftCardInput,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
returnSchema: `
|
|
48
|
+
giftCardCode
|
|
49
|
+
giftCard { ${ returnGiftCardAttrs } }
|
|
50
|
+
`.trim(),
|
|
51
|
+
apiVersion,
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const funcApiConfig = {
|
|
57
|
+
argsWarden,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
shopifyGiftCardCreate,
|
|
62
|
+
funcApiConfig,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
curl -X POST "http://localhost:8000/shopifyGiftCardCreate" \
|
|
67
|
+
-H "Content-Type: application/json" \
|
|
68
|
+
-d '{
|
|
69
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
70
|
+
"giftCardInput": {
|
|
71
|
+
"initialValue": "5",
|
|
72
|
+
"customerId": "gid://shopify/Customer/1234567890",
|
|
73
|
+
"note": "Pocket money"
|
|
74
|
+
}
|
|
75
|
+
}'
|
|
76
|
+
|
|
77
|
+
curl -X POST "http://localhost:8000/shopifyGiftCardCreate" \
|
|
78
|
+
-H "Content-Type: application/json" \
|
|
79
|
+
-d '{
|
|
80
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
81
|
+
"giftCardInput": {
|
|
82
|
+
"initialValue": "101.0",
|
|
83
|
+
"customerId": "gid://shopify/Customer/1234567890",
|
|
84
|
+
"recipientAttributes": {
|
|
85
|
+
"id": "gid://shopify/Customer/0987654321",
|
|
86
|
+
"message": "One dalmatian = one dollar",
|
|
87
|
+
"preferredName": "Cruella",
|
|
88
|
+
"sendNotificationAt": "2026-07-01T12:00:00Z"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"options": {
|
|
92
|
+
"returnGiftCardAttrs": "id initialValue { amount } customer { id } recipientAttributes { message preferredName sendNotificationAt recipient { id } }"
|
|
93
|
+
}
|
|
94
|
+
}'
|
|
95
|
+
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/giftCardDeactivate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['giftCardId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const shopifyGiftCardDeactivate = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
giftCardId,
|
|
15
|
+
{
|
|
16
|
+
apiVersion,
|
|
17
|
+
giftCardReturnAttrs = 'id deactivatedAt',
|
|
18
|
+
} = {},
|
|
19
|
+
) => {
|
|
20
|
+
|
|
21
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, giftCardId });
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return shopifyMutationDo(
|
|
27
|
+
credsPayload,
|
|
28
|
+
'giftCardDeactivate',
|
|
29
|
+
{
|
|
30
|
+
mutationVariables: {
|
|
31
|
+
id: {
|
|
32
|
+
type: 'ID!',
|
|
33
|
+
value: `gid://shopify/GiftCard/${ giftCardId }`,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
returnSchema: `giftCard { ${ giftCardReturnAttrs } }`,
|
|
37
|
+
apiVersion,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const funcApiConfig = {
|
|
43
|
+
argsWarden,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
shopifyGiftCardDeactivate,
|
|
48
|
+
funcApiConfig,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
curl -X POST "http://localhost:8000/shopifyGiftCardDeactivate" \
|
|
53
|
+
-H "Content-Type: application/json" \
|
|
54
|
+
-d '{
|
|
55
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
56
|
+
"giftCardId": "651526996040"
|
|
57
|
+
}'
|
|
58
|
+
*/
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/metafieldsset
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { actionSingleOrMultiple, arrayToChunks, ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
const { MAX_METAFIELDS_PER_SET } = require('../shopify/shopify.constants');
|
|
7
|
+
|
|
8
|
+
const metafieldsValidator = (metafields) => {
|
|
9
|
+
return Array.isArray(metafields) && metafields.length > 0;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const argsWarden = new ArgsWarden([
|
|
13
|
+
['credsPayload', credsValidator],
|
|
14
|
+
['metafields', metafieldsValidator],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const defaultAttrs = 'id namespace key type value';
|
|
18
|
+
|
|
19
|
+
const shopifyMetafieldsSetChunk = async (
|
|
20
|
+
credsPayload,
|
|
21
|
+
metafields,
|
|
22
|
+
{
|
|
23
|
+
apiVersion,
|
|
24
|
+
returnMetafieldAttrs = defaultAttrs,
|
|
25
|
+
} = {},
|
|
26
|
+
) => {
|
|
27
|
+
|
|
28
|
+
return shopifyMutationDo(
|
|
29
|
+
credsPayload,
|
|
30
|
+
'metafieldsSet',
|
|
31
|
+
{
|
|
32
|
+
mutationVariables: {
|
|
33
|
+
metafields: {
|
|
34
|
+
type: '[MetafieldsSetInput!]!',
|
|
35
|
+
value: metafields,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
returnSchema: `
|
|
39
|
+
metafields { ${ returnMetafieldAttrs } }
|
|
40
|
+
`.trim(),
|
|
41
|
+
apiVersion,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const shopifyMetafieldsSet = async (
|
|
47
|
+
credsPayload,
|
|
48
|
+
metafields,
|
|
49
|
+
{
|
|
50
|
+
queueRunOptions,
|
|
51
|
+
apiVersion,
|
|
52
|
+
returnMetafieldAttrs = defaultAttrs,
|
|
53
|
+
} = {},
|
|
54
|
+
) => {
|
|
55
|
+
|
|
56
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
57
|
+
credsPayload,
|
|
58
|
+
metafields,
|
|
59
|
+
});
|
|
60
|
+
if (rejectResponse) {
|
|
61
|
+
return rejectResponse;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const chunks = arrayToChunks(metafields, MAX_METAFIELDS_PER_SET);
|
|
65
|
+
|
|
66
|
+
return actionSingleOrMultiple(
|
|
67
|
+
chunks,
|
|
68
|
+
shopifyMetafieldsSetChunk,
|
|
69
|
+
(chunk) => ({
|
|
70
|
+
args: [credsPayload, chunk, { apiVersion, returnMetafieldAttrs }],
|
|
71
|
+
}),
|
|
72
|
+
{
|
|
73
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const funcApiConfig = {
|
|
79
|
+
argsWarden,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports = {
|
|
83
|
+
shopifyMetafieldsSet,
|
|
84
|
+
funcApiConfig,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
curl -X POST "http://localhost:8000/shopifyMetafieldsSet" \
|
|
89
|
+
-H "Content-Type: application/json" \
|
|
90
|
+
-d '{
|
|
91
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
92
|
+
"metafields": [{
|
|
93
|
+
"ownerId": "gid://shopify/Customer/2111702204488",
|
|
94
|
+
"namespace": "facts",
|
|
95
|
+
"key": "birth_date",
|
|
96
|
+
"type": "date",
|
|
97
|
+
"value": "1990-01-01"
|
|
98
|
+
}]
|
|
99
|
+
}'
|
|
100
|
+
*/
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const { credsFromPayload, logDeep, ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { shopifyClient } = require('./shopify.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['mutationName'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const shopifyMutationDo = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
mutationName,
|
|
13
|
+
{
|
|
14
|
+
mutationVariables = {},
|
|
15
|
+
returnSchema = '',
|
|
16
|
+
apiVersion,
|
|
17
|
+
...clientOptions
|
|
18
|
+
} = {},
|
|
19
|
+
) => {
|
|
20
|
+
|
|
21
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, mutationName });
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!returnSchema?.includes('userErrors')) {
|
|
27
|
+
returnSchema += ' userErrors { field message }';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const creds = await credsFromPayload(credsPayload);
|
|
31
|
+
|
|
32
|
+
const mutation = `
|
|
33
|
+
mutation ${ mutationName }(${ Object.entries(mutationVariables).map(([name, { type }]) => `$${ name }: ${ type }`).join(', ') }) {
|
|
34
|
+
${ mutationName }(${ Object.keys(mutationVariables).map(name => `${ name }: $${ name }`).join(', ') }) {
|
|
35
|
+
${ returnSchema }
|
|
36
|
+
userErrors {
|
|
37
|
+
field
|
|
38
|
+
message
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const variables = {};
|
|
45
|
+
for (const [name, { value }] of Object.entries(mutationVariables)) {
|
|
46
|
+
variables[name] = value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const response = await shopifyClient.fetch({
|
|
50
|
+
method: 'post',
|
|
51
|
+
body: { query: mutation, variables },
|
|
52
|
+
context: {
|
|
53
|
+
creds,
|
|
54
|
+
apiVersion,
|
|
55
|
+
resultPath: `data.${ mutationName }`,
|
|
56
|
+
},
|
|
57
|
+
...clientOptions,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
logDeep(response);
|
|
61
|
+
return response;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const funcApiConfig = {
|
|
65
|
+
argsWarden,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
shopifyMutationDo,
|
|
70
|
+
funcApiConfig,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
curl -X POST "http://localhost:8000/shopifyMutationDo" \
|
|
75
|
+
-H "Content-Type: application/json" \
|
|
76
|
+
-d '{
|
|
77
|
+
"credsPayload": {
|
|
78
|
+
"credsPath": "shopify.au"
|
|
79
|
+
},
|
|
80
|
+
"mutationName": "tagsAdd",
|
|
81
|
+
"options": {
|
|
82
|
+
"mutationVariables": {
|
|
83
|
+
"id": {
|
|
84
|
+
"value": "gid://shopify/Order/7693468893256",
|
|
85
|
+
"type": "ID!"
|
|
86
|
+
},
|
|
87
|
+
"tags": {
|
|
88
|
+
"value": ["test-tag"],
|
|
89
|
+
"type": "[String!]!"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"returnSchema": "order { id name }"
|
|
93
|
+
}
|
|
94
|
+
}'
|
|
95
|
+
*/
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const { credsValidator } = require('../validators');
|
|
2
|
+
const { actionSingleOrMultiple, everyIfArray, ArgsWarden } = require('../utils');
|
|
3
|
+
const { shopifyGetSingle } = require('../shopify/shopifyGetSingle');
|
|
4
|
+
|
|
5
|
+
const defaultAttrs = 'id name createdAt displayFinancialStatus displayFulfillmentStatus';
|
|
6
|
+
|
|
7
|
+
const orderIdentifierValidator = ({ orderId, orderName } = {}) => Boolean(orderId) || Boolean(orderName);
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['orderIdentifier', (i) => everyIfArray(orderIdentifierValidator, i)],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const shopifyOrderGetSingle = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
orderIdentifier,
|
|
17
|
+
{
|
|
18
|
+
apiVersion,
|
|
19
|
+
attrs = defaultAttrs,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const { orderId, orderName } = orderIdentifier;
|
|
24
|
+
|
|
25
|
+
if (orderId) {
|
|
26
|
+
return shopifyGetSingle(
|
|
27
|
+
credsPayload,
|
|
28
|
+
'order',
|
|
29
|
+
orderId,
|
|
30
|
+
{
|
|
31
|
+
apiVersion,
|
|
32
|
+
attrs,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* orderName */
|
|
38
|
+
// const response = await shopifyOrdersGet(credsPath, {
|
|
39
|
+
// apiVersion,
|
|
40
|
+
// attrs,
|
|
41
|
+
// queries: [`name:${ orderName }`],
|
|
42
|
+
// });
|
|
43
|
+
|
|
44
|
+
// const singleResponse = standardInterpreters.expectOne(response);
|
|
45
|
+
|
|
46
|
+
// return singleResponse;
|
|
47
|
+
/* /orderName */
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const shopifyOrderGet = async (
|
|
51
|
+
credsPayload,
|
|
52
|
+
orderIdentifier,
|
|
53
|
+
{
|
|
54
|
+
queueRunOptions,
|
|
55
|
+
apiVersion,
|
|
56
|
+
attrs = defaultAttrs,
|
|
57
|
+
} = {},
|
|
58
|
+
) => {
|
|
59
|
+
|
|
60
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, orderIdentifier });
|
|
61
|
+
if (rejectResponse) {
|
|
62
|
+
return rejectResponse;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return actionSingleOrMultiple(
|
|
66
|
+
orderIdentifier,
|
|
67
|
+
shopifyOrderGetSingle,
|
|
68
|
+
(identifier) => ({
|
|
69
|
+
args: [credsPayload, identifier, { apiVersion, attrs }],
|
|
70
|
+
}),
|
|
71
|
+
{
|
|
72
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const funcApiConfig = {
|
|
78
|
+
argsWarden,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
shopifyOrderGet,
|
|
83
|
+
funcApiConfig,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
curl -X POST "http://localhost:8000/shopifyOrderGet" \
|
|
88
|
+
-H "Content-Type: application/json" \
|
|
89
|
+
-d '{
|
|
90
|
+
"credsPayload": {
|
|
91
|
+
"credsObject": {
|
|
92
|
+
"STORE_HANDLE": "arisawa-heavy-industries",
|
|
93
|
+
"API_KEY": "shpat_xxx"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"orderIdentifier": {
|
|
97
|
+
"orderId": "1234567890"
|
|
98
|
+
}
|
|
99
|
+
}'
|
|
100
|
+
|
|
101
|
+
curl -X POST "http://localhost:8000/shopifyOrderGet" \
|
|
102
|
+
-H "Content-Type: application/json" \
|
|
103
|
+
-d '{
|
|
104
|
+
"credsPayload": {
|
|
105
|
+
"credsPath": "shopify.au"
|
|
106
|
+
},
|
|
107
|
+
"orderIdentifier": {
|
|
108
|
+
"orderId": "7015155466312"
|
|
109
|
+
}
|
|
110
|
+
}'
|
|
111
|
+
|
|
112
|
+
curl -X POST "http://localhost:8000/shopifyOrderGet" \
|
|
113
|
+
-H "Content-Type: application/json" \
|
|
114
|
+
-d '{
|
|
115
|
+
"credsPayload": {
|
|
116
|
+
"credsPath": "shopify.au"
|
|
117
|
+
},
|
|
118
|
+
"orderIdentifier": [
|
|
119
|
+
{ "orderId": "7015155466312" },
|
|
120
|
+
{ "orderId": "7697048109128" }
|
|
121
|
+
]
|
|
122
|
+
}'
|
|
123
|
+
*/
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const { credsFromPayload, logDeep, ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { shopifyClient } = require('./shopify.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
const shopifyOrdersGet = async (
|
|
10
|
+
credsPayload,
|
|
11
|
+
{
|
|
12
|
+
first = 50,
|
|
13
|
+
after,
|
|
14
|
+
query,
|
|
15
|
+
apiVersion,
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
|
|
20
|
+
if (rejectResponse) {
|
|
21
|
+
return rejectResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const creds = await credsFromPayload(credsPayload);
|
|
25
|
+
|
|
26
|
+
const response = await shopifyClient.fetch({
|
|
27
|
+
method: 'post',
|
|
28
|
+
body: {
|
|
29
|
+
query: `
|
|
30
|
+
query OrdersGet(
|
|
31
|
+
$first: Int!,
|
|
32
|
+
$after: String,
|
|
33
|
+
$query: String
|
|
34
|
+
) {
|
|
35
|
+
orders(
|
|
36
|
+
first: $first,
|
|
37
|
+
after: $after,
|
|
38
|
+
query: $query
|
|
39
|
+
) {
|
|
40
|
+
edges {
|
|
41
|
+
node {
|
|
42
|
+
id
|
|
43
|
+
name
|
|
44
|
+
createdAt
|
|
45
|
+
displayFinancialStatus
|
|
46
|
+
displayFulfillmentStatus
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
variables: {
|
|
53
|
+
first,
|
|
54
|
+
after,
|
|
55
|
+
query,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
context: {
|
|
59
|
+
creds,
|
|
60
|
+
apiVersion,
|
|
61
|
+
resultPath: 'data.orders',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
logDeep('response', response);
|
|
70
|
+
return response;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const funcApiConfig = {
|
|
74
|
+
argsWarden,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
shopifyOrdersGet,
|
|
79
|
+
funcApiConfig,
|
|
80
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/pageDelete
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['pageId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const shopifyPageDelete = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
pageId,
|
|
15
|
+
{
|
|
16
|
+
apiVersion,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const argsRejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, pageId });
|
|
21
|
+
if (argsRejectResponse) {
|
|
22
|
+
return argsRejectResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return shopifyMutationDo(
|
|
26
|
+
credsPayload,
|
|
27
|
+
'pageDelete',
|
|
28
|
+
{
|
|
29
|
+
mutationVariables: {
|
|
30
|
+
id: {
|
|
31
|
+
type: 'ID!',
|
|
32
|
+
value: `gid://shopify/Page/${ pageId }`,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
returnSchema: 'deletedPageId',
|
|
36
|
+
apiVersion,
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const funcApiConfig = {
|
|
42
|
+
argsWarden,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
shopifyPageDelete,
|
|
47
|
+
funcApiConfig,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
curl -X POST "http://localhost:8000/shopifyPageDelete" \
|
|
52
|
+
-H "Content-Type: application/json" \
|
|
53
|
+
-d '{
|
|
54
|
+
"credsPayload": {
|
|
55
|
+
"credsPath": "shopify.au"
|
|
56
|
+
},
|
|
57
|
+
"pageId": "104188477512"
|
|
58
|
+
}'
|
|
59
|
+
*/
|