@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,76 @@
|
|
|
1
|
+
const { credsValidator } = require('../validators');
|
|
2
|
+
const { ArgsWarden } = require('../utils');
|
|
3
|
+
const { peoplevoxClient } = require('../peoplevox/peoplevox.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['reportName'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const peoplevoxReportGet = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
reportName,
|
|
13
|
+
{
|
|
14
|
+
searchClause,
|
|
15
|
+
perPage,
|
|
16
|
+
filter,
|
|
17
|
+
orderBy,
|
|
18
|
+
columns,
|
|
19
|
+
} = {},
|
|
20
|
+
) => {
|
|
21
|
+
|
|
22
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, reportName });
|
|
23
|
+
if (rejectResponse) {
|
|
24
|
+
return rejectResponse;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const reportGetResponse = await peoplevoxClient.fetch({
|
|
28
|
+
method: 'post',
|
|
29
|
+
body: {
|
|
30
|
+
getReportRequest: {
|
|
31
|
+
TemplateName: reportName,
|
|
32
|
+
...(searchClause ? { SearchClause: searchClause } : {}),
|
|
33
|
+
...(perPage ? { ItemsPerPage: perPage } : {}),
|
|
34
|
+
...(filter ? { FilterClause: filter } : {}),
|
|
35
|
+
...(orderBy ? { OrderBy: orderBy } : {}),
|
|
36
|
+
...(columns ? { Columns: columns.join(',') } : {}),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
context: {
|
|
40
|
+
credsPayload,
|
|
41
|
+
action: 'GetReportData',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return reportGetResponse;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const funcApiConfig = {
|
|
49
|
+
argsWarden,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
peoplevoxReportGet,
|
|
54
|
+
funcApiConfig,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
curl -X POST "http://localhost:8000/peoplevoxReportGet" \
|
|
59
|
+
-H "Content-Type: application/json" \
|
|
60
|
+
-d '{
|
|
61
|
+
"credsPayload": { "credsPath": "peoplevox" },
|
|
62
|
+
"reportName": "Item inventory summary"
|
|
63
|
+
}'
|
|
64
|
+
|
|
65
|
+
curl -X POST "http://localhost:8000/peoplevoxReportGet" \
|
|
66
|
+
-H "Content-Type: application/json" \
|
|
67
|
+
-d '{
|
|
68
|
+
"credsPayload": { "credsPath": "peoplevox" },
|
|
69
|
+
"reportName": "Despatch summary",
|
|
70
|
+
"options": {
|
|
71
|
+
"searchClause": "([Salesorder number].Equals(\"11221660500337\"))",
|
|
72
|
+
"perPage": 50,
|
|
73
|
+
"columns": ["Salesorder number", "Despatch number", "Tracking number"]
|
|
74
|
+
}
|
|
75
|
+
}'
|
|
76
|
+
*/
|
|
File without changes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/customerCreate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const thingInputValidator = (thingInput) => thingInput?.email;
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['thingInput', thingInputValidator],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const defaultReturnThingAttrs = 'id';
|
|
15
|
+
|
|
16
|
+
const shopifyThingCreate = async (
|
|
17
|
+
credsPayload,
|
|
18
|
+
thingInput,
|
|
19
|
+
{
|
|
20
|
+
apiVersion,
|
|
21
|
+
returnThingAttrs = defaultReturnThingAttrs,
|
|
22
|
+
} = {},
|
|
23
|
+
) => {
|
|
24
|
+
|
|
25
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
27
|
+
thingInput,
|
|
28
|
+
});
|
|
29
|
+
if (rejectResponse) {
|
|
30
|
+
return rejectResponse;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return shopifyMutationDo(
|
|
34
|
+
credsPayload,
|
|
35
|
+
'thingCreate',
|
|
36
|
+
{
|
|
37
|
+
mutationVariables: {
|
|
38
|
+
input: {
|
|
39
|
+
type: 'ThingInput!',
|
|
40
|
+
value: thingInput,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
returnSchema: `
|
|
44
|
+
thing { ${ returnThingAttrs } }
|
|
45
|
+
`.trim(),
|
|
46
|
+
apiVersion,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const funcApiConfig = {
|
|
52
|
+
argsWarden,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
shopifyThingCreate,
|
|
57
|
+
funcApiConfig,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
curl -X POST "http://localhost:8000/shopifyThingCreate" \
|
|
62
|
+
-H "Content-Type: application/json" \
|
|
63
|
+
-d '{
|
|
64
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
65
|
+
"thingInput": {
|
|
66
|
+
...
|
|
67
|
+
}
|
|
68
|
+
}'
|
|
69
|
+
*/
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/page
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyGetSingle } = require('../shopify/shopifyGetSingle');
|
|
6
|
+
|
|
7
|
+
const defaultAttrs = 'id title handle';
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['thingId'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const FUNC = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
thingId,
|
|
17
|
+
{
|
|
18
|
+
apiVersion,
|
|
19
|
+
attrs = defaultAttrs,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, thingId });
|
|
24
|
+
if (rejectResponse) {
|
|
25
|
+
return rejectResponse;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return shopifyGetSingle(
|
|
29
|
+
credsPayload,
|
|
30
|
+
'thing',
|
|
31
|
+
thingId,
|
|
32
|
+
{
|
|
33
|
+
apiVersion,
|
|
34
|
+
attrs,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const funcApiConfig = {
|
|
40
|
+
argsWarden,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
FUNC,
|
|
45
|
+
funcApiConfig,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
curl -X POST "http://localhost:8000/FUNC" \
|
|
50
|
+
-H "Content-Type: application/json" \
|
|
51
|
+
-d '{
|
|
52
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
53
|
+
"thingId": "104188477512"
|
|
54
|
+
}'
|
|
55
|
+
*/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { credsValidator } = require('../validators');
|
|
2
|
+
const { ArgsWarden } = require('../utils');
|
|
3
|
+
|
|
4
|
+
const argsWarden = new ArgsWarden([
|
|
5
|
+
['credsPayload', credsValidator],
|
|
6
|
+
['arg', Boolean],
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
const FUNC = async (
|
|
10
|
+
credsPayload,
|
|
11
|
+
arg,
|
|
12
|
+
options = {},
|
|
13
|
+
) => {
|
|
14
|
+
|
|
15
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, arg });
|
|
16
|
+
if (rejectResponse) {
|
|
17
|
+
return rejectResponse;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
ok: true,
|
|
22
|
+
data: {
|
|
23
|
+
arg,
|
|
24
|
+
options,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const funcApiConfig = {
|
|
30
|
+
argsWarden,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
FUNC,
|
|
35
|
+
funcApiConfig,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
curl -X POST "http://localhost:8000/FUNC" \
|
|
40
|
+
-H "Content-Type: application/json" \
|
|
41
|
+
-d '{
|
|
42
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
43
|
+
"arg": "1234"
|
|
44
|
+
}'
|
|
45
|
+
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
['thingId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const FUNC = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
thingId,
|
|
15
|
+
{
|
|
16
|
+
apiVersion,
|
|
17
|
+
returnSchema = 'deletedThingId',
|
|
18
|
+
} = {},
|
|
19
|
+
) => {
|
|
20
|
+
|
|
21
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, thingId });
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return shopifyMutationDo(
|
|
27
|
+
credsPayload,
|
|
28
|
+
'thingDelete',
|
|
29
|
+
{
|
|
30
|
+
mutationVariables: {
|
|
31
|
+
id: {
|
|
32
|
+
type: 'ID!',
|
|
33
|
+
value: `gid://shopify/Thing/${ thingId }`,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
returnSchema,
|
|
37
|
+
apiVersion,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const funcApiConfig = {
|
|
43
|
+
argsWarden,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
FUNC,
|
|
48
|
+
funcApiConfig,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
curl -X POST "http://localhost:8000/FUNC" \
|
|
53
|
+
-H "Content-Type: application/json" \
|
|
54
|
+
-d '{
|
|
55
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
56
|
+
"thingId": "104188477512"
|
|
57
|
+
}'
|
|
58
|
+
*/
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const { DEFAULT_API_VERSION } = require('../shopify/shopify.constants');
|
|
2
|
+
const {
|
|
3
|
+
FetchClient,
|
|
4
|
+
Chain,
|
|
5
|
+
appendUrlToBase,
|
|
6
|
+
fetchClientCommonSteps,
|
|
7
|
+
pathAsArray,
|
|
8
|
+
objectDigNodeAtPath,
|
|
9
|
+
} = require('../utils');
|
|
10
|
+
|
|
11
|
+
const handleMutationUserErrors = async (state) => {
|
|
12
|
+
const { response } = state;
|
|
13
|
+
const mutationPayload = response?.data;
|
|
14
|
+
|
|
15
|
+
if (!response?.ok || !mutationPayload || typeof mutationPayload !== 'object') {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { userErrors, ...mutationResult } = mutationPayload;
|
|
20
|
+
|
|
21
|
+
if (!Array.isArray(userErrors)) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (userErrors.length) {
|
|
26
|
+
const message = userErrors
|
|
27
|
+
.map((userError) => userError?.message)
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
.join('; ');
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
response: {
|
|
33
|
+
ok: false,
|
|
34
|
+
error: {
|
|
35
|
+
code: 'USER_ERROR',
|
|
36
|
+
message: message || 'Mutation failed',
|
|
37
|
+
details: userErrors,
|
|
38
|
+
},
|
|
39
|
+
...(Object.keys(mutationResult).length ? { data: mutationResult } : {}),
|
|
40
|
+
},
|
|
41
|
+
breakChain: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
response: {
|
|
47
|
+
data: mutationResult,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const addUrlAndAuthHeaders = async (state) => {
|
|
53
|
+
const { requestPayload, context } = state;
|
|
54
|
+
const {
|
|
55
|
+
creds,
|
|
56
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
57
|
+
} = context;
|
|
58
|
+
const {
|
|
59
|
+
STORE_HANDLE,
|
|
60
|
+
API_KEY,
|
|
61
|
+
} = creds;
|
|
62
|
+
|
|
63
|
+
const baseUrl = `https://${ STORE_HANDLE }.myshopify.com/admin/api/${ apiVersion }/graphql.json`;
|
|
64
|
+
const baseHeaders = {
|
|
65
|
+
'X-Shopify-Access-Token': API_KEY,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
requestPayload: {
|
|
70
|
+
url: appendUrlToBase(baseUrl, requestPayload.url),
|
|
71
|
+
headers: {
|
|
72
|
+
...baseHeaders,
|
|
73
|
+
...requestPayload.headers,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const movePageInfoToMeta = async (state) => {
|
|
80
|
+
const { response, context } = state;
|
|
81
|
+
const { resultPath } = context ?? {};
|
|
82
|
+
|
|
83
|
+
if (!response?.ok || !response?.data || !resultPath) {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const connection = objectDigNodeAtPath(response.data, pathAsArray(resultPath));
|
|
88
|
+
|
|
89
|
+
if (!connection?.pageInfo) {
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
response: {
|
|
95
|
+
meta: {
|
|
96
|
+
pageInfo: connection.pageInfo,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const shopifyClientRequestPreparer = new Chain([
|
|
103
|
+
addUrlAndAuthHeaders,
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
const shopifyClientResponseInterpreter = new Chain([
|
|
107
|
+
movePageInfoToMeta,
|
|
108
|
+
fetchClientCommonSteps.stripEdgesAndNodes,
|
|
109
|
+
fetchClientCommonSteps.collapseDataWithOneValue,
|
|
110
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
111
|
+
fetchClientCommonSteps.exitEarlyOnGraphqlErrors,
|
|
112
|
+
fetchClientCommonSteps.digToPath,
|
|
113
|
+
handleMutationUserErrors,
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
const shopifyClient = new FetchClient({
|
|
117
|
+
requestPreparer: shopifyClientRequestPreparer,
|
|
118
|
+
responseInterpreter: shopifyClientResponseInterpreter,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
module.exports = {
|
|
122
|
+
shopifyClient,
|
|
123
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/collection
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden, objHasAny, credsFromPayload } = require('../utils');
|
|
5
|
+
const { shopifyGetSingle } = require('../shopify/shopifyGetSingle');
|
|
6
|
+
const { shopifyClient } = require('../shopify/shopify.utils');
|
|
7
|
+
|
|
8
|
+
const defaultAttrs = 'id title handle';
|
|
9
|
+
|
|
10
|
+
const collectionIdentifierValidator = (collectionIdentifier) => {
|
|
11
|
+
return objHasAny(collectionIdentifier, [
|
|
12
|
+
'customId',
|
|
13
|
+
'id',
|
|
14
|
+
'handle',
|
|
15
|
+
]);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const argsWarden = new ArgsWarden([
|
|
19
|
+
['credsPayload', credsValidator],
|
|
20
|
+
['collectionIdentifier', collectionIdentifierValidator],
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const shopifyCollectionGet = async (
|
|
24
|
+
credsPayload,
|
|
25
|
+
collectionIdentifier,
|
|
26
|
+
{
|
|
27
|
+
apiVersion,
|
|
28
|
+
attrs = defaultAttrs,
|
|
29
|
+
} = {},
|
|
30
|
+
) => {
|
|
31
|
+
|
|
32
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, collectionIdentifier });
|
|
33
|
+
if (rejectResponse) {
|
|
34
|
+
return rejectResponse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
customId,
|
|
39
|
+
id,
|
|
40
|
+
handle,
|
|
41
|
+
} = collectionIdentifier;
|
|
42
|
+
|
|
43
|
+
if (!id) {
|
|
44
|
+
|
|
45
|
+
const creds = await credsFromPayload(credsPayload);
|
|
46
|
+
|
|
47
|
+
const query = `
|
|
48
|
+
query GetCollectionByIdentifier ($identifier: CollectionIdentifierInput!) {
|
|
49
|
+
collection: collectionByIdentifier(identifier: $identifier) {
|
|
50
|
+
${ attrs }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const variables = {
|
|
56
|
+
identifier: {
|
|
57
|
+
...customId && { customId },
|
|
58
|
+
...handle && { handle },
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const response = await shopifyClient.fetch({
|
|
63
|
+
method: 'post',
|
|
64
|
+
body: { query, variables },
|
|
65
|
+
context: {
|
|
66
|
+
creds,
|
|
67
|
+
apiVersion,
|
|
68
|
+
resultPath: 'data.collection',
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return response;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return shopifyGetSingle(
|
|
76
|
+
credsPayload,
|
|
77
|
+
'collection',
|
|
78
|
+
collectionIdentifier,
|
|
79
|
+
{
|
|
80
|
+
apiVersion,
|
|
81
|
+
attrs,
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const funcApiConfig = {
|
|
87
|
+
argsWarden,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
shopifyCollectionGet,
|
|
92
|
+
funcApiConfig,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
curl -X POST "http://localhost:8000/shopifyCollectionGet" \
|
|
97
|
+
-H "Content-Type: application/json" \
|
|
98
|
+
-d '{
|
|
99
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
100
|
+
"collectionIdentifier": { "id": "279980277832" }
|
|
101
|
+
}'
|
|
102
|
+
|
|
103
|
+
curl -X POST "http://localhost:8000/shopifyCollectionGet" \
|
|
104
|
+
-H "Content-Type: application/json" \
|
|
105
|
+
-d '{
|
|
106
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
107
|
+
"collectionIdentifier": { "handle": "new-arrivals" }
|
|
108
|
+
}'
|
|
109
|
+
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/customerCreate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const customerInputValidator = (customerInput) => customerInput?.email;
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['customerInput', customerInputValidator],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const defaultReturnCustomerAttrs = 'id email';
|
|
15
|
+
|
|
16
|
+
const shopifyCustomerCreate = async (
|
|
17
|
+
credsPayload,
|
|
18
|
+
customerInput,
|
|
19
|
+
{
|
|
20
|
+
apiVersion,
|
|
21
|
+
returnCustomerAttrs = defaultReturnCustomerAttrs,
|
|
22
|
+
} = {},
|
|
23
|
+
) => {
|
|
24
|
+
|
|
25
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
27
|
+
customerInput,
|
|
28
|
+
});
|
|
29
|
+
if (rejectResponse) {
|
|
30
|
+
return rejectResponse;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return shopifyMutationDo(
|
|
34
|
+
credsPayload,
|
|
35
|
+
'customerCreate',
|
|
36
|
+
{
|
|
37
|
+
mutationVariables: {
|
|
38
|
+
input: {
|
|
39
|
+
type: 'CustomerInput!',
|
|
40
|
+
value: customerInput,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
returnSchema: `
|
|
44
|
+
customer { ${ returnCustomerAttrs } }
|
|
45
|
+
`.trim(),
|
|
46
|
+
apiVersion,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const funcApiConfig = {
|
|
52
|
+
argsWarden,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
shopifyCustomerCreate,
|
|
57
|
+
funcApiConfig,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
curl -X POST "http://localhost:8000/shopifyCustomerCreate" \
|
|
62
|
+
-H "Content-Type: application/json" \
|
|
63
|
+
-d '{
|
|
64
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
65
|
+
"customerInput": {
|
|
66
|
+
"email": "john+shopifyCustomerCreate@whitefoxboutique.com",
|
|
67
|
+
"firstName": "Doctor",
|
|
68
|
+
"lastName": "Manhattan"
|
|
69
|
+
}
|
|
70
|
+
}'
|
|
71
|
+
*/
|