@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,112 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/customer
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { objHasAny, credsFromPayload, ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyGetSingle } = require('../shopify/shopifyGetSingle');
|
|
6
|
+
const { shopifyClient } = require('../shopify/shopify.utils');
|
|
7
|
+
|
|
8
|
+
const defaultAttrs = 'id email';
|
|
9
|
+
|
|
10
|
+
const customerIdentifierValidator = (customerIdentifier) => {
|
|
11
|
+
return objHasAny(customerIdentifier, [
|
|
12
|
+
'customerId',
|
|
13
|
+
'customId',
|
|
14
|
+
'email',
|
|
15
|
+
'phone',
|
|
16
|
+
]);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const argsWarden = new ArgsWarden([
|
|
20
|
+
['credsPayload', credsValidator],
|
|
21
|
+
['customerIdentifier', customerIdentifierValidator],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const shopifyCustomerGet = async (
|
|
25
|
+
credsPayload,
|
|
26
|
+
customerIdentifier,
|
|
27
|
+
{
|
|
28
|
+
apiVersion,
|
|
29
|
+
attrs = defaultAttrs,
|
|
30
|
+
} = {},
|
|
31
|
+
) => {
|
|
32
|
+
|
|
33
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload, customerIdentifier });
|
|
34
|
+
if (rejectResponse) {
|
|
35
|
+
return rejectResponse;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
customerId,
|
|
40
|
+
customId,
|
|
41
|
+
email,
|
|
42
|
+
phone,
|
|
43
|
+
} = customerIdentifier;
|
|
44
|
+
|
|
45
|
+
if (!customerId) {
|
|
46
|
+
|
|
47
|
+
const creds = await credsFromPayload(credsPayload);
|
|
48
|
+
|
|
49
|
+
const query = `
|
|
50
|
+
query GetCustomerByIdentifier ($identifier: CustomerIdentifierInput!) {
|
|
51
|
+
customer: customerByIdentifier(identifier: $identifier) {
|
|
52
|
+
${ attrs }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
const variables = {
|
|
58
|
+
identifier: {
|
|
59
|
+
...customId && { customId },
|
|
60
|
+
...email && { emailAddress: email },
|
|
61
|
+
...phone && { phoneNumber: phone },
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const response = await shopifyClient.fetch({
|
|
66
|
+
method: 'post',
|
|
67
|
+
body: { query, variables },
|
|
68
|
+
context: {
|
|
69
|
+
creds,
|
|
70
|
+
apiVersion,
|
|
71
|
+
resultPath: 'data.customer',
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return response;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return shopifyGetSingle(
|
|
79
|
+
credsPayload,
|
|
80
|
+
'customer',
|
|
81
|
+
customerId,
|
|
82
|
+
{
|
|
83
|
+
apiVersion,
|
|
84
|
+
attrs,
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const funcApiConfig = {
|
|
90
|
+
argsWarden,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
shopifyCustomerGet,
|
|
95
|
+
funcApiConfig,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
curl -X POST "http://localhost:8000/shopifyCustomerGet" \
|
|
100
|
+
-H "Content-Type: application/json" \
|
|
101
|
+
-d '{
|
|
102
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
103
|
+
"customerIdentifier": { "customerId": "8575963103304" }
|
|
104
|
+
}'
|
|
105
|
+
|
|
106
|
+
curl -X POST "http://localhost:8000/shopifyCustomerGet" \
|
|
107
|
+
-H "Content-Type: application/json" \
|
|
108
|
+
-d '{
|
|
109
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
110
|
+
"customerIdentifier": { "email": "john+testing@whitefoxboutique.com" }
|
|
111
|
+
}'
|
|
112
|
+
*/
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/customeremailmarketingconsentupdate
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { objHasAny, ArgsWarden } = require('../utils');
|
|
5
|
+
const { shopifyMutationDo } = require('../shopify/shopifyMutationDo');
|
|
6
|
+
|
|
7
|
+
const consentPayloadValidator = (consentPayload) => {
|
|
8
|
+
return objHasAny(consentPayload, [
|
|
9
|
+
'consentUpdatedAt',
|
|
10
|
+
'marketingOptInLevel',
|
|
11
|
+
'marketingState',
|
|
12
|
+
'sourceLocationId',
|
|
13
|
+
]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const argsWarden = new ArgsWarden([
|
|
17
|
+
['credsPayload', credsValidator],
|
|
18
|
+
['customerId'],
|
|
19
|
+
['consentPayload', consentPayloadValidator],
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const defaultReturnCustomerAttrs = 'email emailMarketingConsent { marketingState consentUpdatedAt marketingOptInLevel }';
|
|
23
|
+
|
|
24
|
+
const shopifyCustomerMarketingConsentUpdateEmail = async (
|
|
25
|
+
credsPayload,
|
|
26
|
+
customerId,
|
|
27
|
+
consentPayload,
|
|
28
|
+
{
|
|
29
|
+
apiVersion,
|
|
30
|
+
returnCustomerAttrs = defaultReturnCustomerAttrs,
|
|
31
|
+
} = {},
|
|
32
|
+
) => {
|
|
33
|
+
|
|
34
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
35
|
+
credsPayload,
|
|
36
|
+
customerId,
|
|
37
|
+
consentPayload,
|
|
38
|
+
});
|
|
39
|
+
if (rejectResponse) {
|
|
40
|
+
return rejectResponse;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return shopifyMutationDo(
|
|
44
|
+
credsPayload,
|
|
45
|
+
'customerEmailMarketingConsentUpdate',
|
|
46
|
+
{
|
|
47
|
+
mutationVariables: {
|
|
48
|
+
input: {
|
|
49
|
+
type: 'CustomerEmailMarketingConsentUpdateInput!',
|
|
50
|
+
value: {
|
|
51
|
+
customerId: `gid://shopify/Customer/${ customerId }`,
|
|
52
|
+
emailMarketingConsent: consentPayload,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
returnSchema: `
|
|
57
|
+
customer { ${ returnCustomerAttrs } }
|
|
58
|
+
`.trim(),
|
|
59
|
+
apiVersion,
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const funcApiConfig = {
|
|
65
|
+
argsWarden,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
shopifyCustomerMarketingConsentUpdateEmail,
|
|
70
|
+
funcApiConfig,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
curl -X POST "http://localhost:8000/shopifyCustomerMarketingConsentUpdateEmail" \
|
|
75
|
+
-H "Content-Type: application/json" \
|
|
76
|
+
-d '{
|
|
77
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
78
|
+
"customerId": "8575963103304",
|
|
79
|
+
"consentPayload": {
|
|
80
|
+
"marketingState": "UNSUBSCRIBED",
|
|
81
|
+
"marketingOptInLevel": "SINGLE_OPT_IN"
|
|
82
|
+
}
|
|
83
|
+
}'
|
|
84
|
+
*/
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/mutations/customerUpdate
|
|
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
|
+
['customerId', Boolean],
|
|
10
|
+
['updatePayload', Boolean],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const defaultReturnCustomerAttrs = 'id email firstName lastName phone';
|
|
14
|
+
|
|
15
|
+
const shopifyCustomerUpdate = async (
|
|
16
|
+
credsPayload,
|
|
17
|
+
customerId,
|
|
18
|
+
updatePayload,
|
|
19
|
+
{
|
|
20
|
+
apiVersion,
|
|
21
|
+
returnCustomerAttrs = defaultReturnCustomerAttrs,
|
|
22
|
+
} = {},
|
|
23
|
+
) => {
|
|
24
|
+
|
|
25
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
27
|
+
customerId,
|
|
28
|
+
updatePayload,
|
|
29
|
+
});
|
|
30
|
+
if (rejectResponse) {
|
|
31
|
+
return rejectResponse;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return shopifyMutationDo(
|
|
35
|
+
credsPayload,
|
|
36
|
+
'customerUpdate',
|
|
37
|
+
{
|
|
38
|
+
mutationVariables: {
|
|
39
|
+
input: {
|
|
40
|
+
type: 'CustomerInput!',
|
|
41
|
+
value: {
|
|
42
|
+
id: `gid://shopify/Customer/${ customerId }`,
|
|
43
|
+
...updatePayload,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
returnSchema: `
|
|
48
|
+
customer { ${ returnCustomerAttrs } }
|
|
49
|
+
`.trim(),
|
|
50
|
+
apiVersion,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const funcApiConfig = {
|
|
56
|
+
argsWarden,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
shopifyCustomerUpdate,
|
|
61
|
+
funcApiConfig,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
curl -X POST "http://localhost:8000/shopifyCustomerUpdate" \
|
|
66
|
+
-H "Content-Type: application/json" \
|
|
67
|
+
-d '{
|
|
68
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
69
|
+
"customerId": "8575963103304",
|
|
70
|
+
"updatePayload": {
|
|
71
|
+
"firstName": "Winston",
|
|
72
|
+
"lastName": "Churchill"
|
|
73
|
+
}
|
|
74
|
+
}'
|
|
75
|
+
*/
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { credsFromPayload, Getter, ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { shopifyGet } = require('./shopifyGet');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
const shopifyCustomersGet = async (
|
|
10
|
+
credsPayload,
|
|
11
|
+
{
|
|
12
|
+
...getterOptions // e.g. limit
|
|
13
|
+
} = {},
|
|
14
|
+
) => {
|
|
15
|
+
|
|
16
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
17
|
+
credsPayload,
|
|
18
|
+
});
|
|
19
|
+
if (rejectResponse) {
|
|
20
|
+
return rejectResponse;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return await shopifyGet(credsPayload, 'customer', { ...getterOptions });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const funcApiConfig = {
|
|
27
|
+
argsWarden,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
shopifyCustomersGet,
|
|
32
|
+
funcApiConfig,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
curl -X POST "http://localhost:8000/shopifyCustomersGet" \
|
|
37
|
+
-H "Content-Type: application/json" \
|
|
38
|
+
-d '{
|
|
39
|
+
"credsPayload": { "credsPath": "shopify.au" }
|
|
40
|
+
}'
|
|
41
|
+
|
|
42
|
+
curl -X POST "http://localhost:8000/shopifyCustomersGet" \
|
|
43
|
+
-H "Content-Type: application/json" \
|
|
44
|
+
-d '{
|
|
45
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
46
|
+
"options": {
|
|
47
|
+
"limit": 10
|
|
48
|
+
}
|
|
49
|
+
}'
|
|
50
|
+
*/
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
const { credsFromPayload, Getter, capitaliseString, ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { shopifyClient } = require('./shopify.utils');
|
|
4
|
+
const { MAX_PER_PAGE } = require('./shopify.constants');
|
|
5
|
+
|
|
6
|
+
const argsWarden = new ArgsWarden([
|
|
7
|
+
['credsPayload', credsValidator],
|
|
8
|
+
['resource'],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const shopifyGetPacket = async (
|
|
12
|
+
// options on the main function can become args on the packet get if they have defaults
|
|
13
|
+
// TODO: Consider where defaults should lie
|
|
14
|
+
creds,
|
|
15
|
+
resource,
|
|
16
|
+
resources,
|
|
17
|
+
attrs,
|
|
18
|
+
{
|
|
19
|
+
apiVersion,
|
|
20
|
+
|
|
21
|
+
perPage = MAX_PER_PAGE,
|
|
22
|
+
cursor,
|
|
23
|
+
queries,
|
|
24
|
+
reverse,
|
|
25
|
+
savedSearchId,
|
|
26
|
+
sortKey,
|
|
27
|
+
roles,
|
|
28
|
+
names,
|
|
29
|
+
constraintStatus,
|
|
30
|
+
constraintSubtype,
|
|
31
|
+
namespace,
|
|
32
|
+
ownerType,
|
|
33
|
+
pinnedStatus,
|
|
34
|
+
ownerGid,
|
|
35
|
+
includeClosed,
|
|
36
|
+
includeLegacy,
|
|
37
|
+
type,
|
|
38
|
+
sku,
|
|
39
|
+
argumentTypeOverrides = {},
|
|
40
|
+
} = {},
|
|
41
|
+
) => {
|
|
42
|
+
|
|
43
|
+
// Forgive me, this is a capital for legibility
|
|
44
|
+
const Resource = capitaliseString(resource);
|
|
45
|
+
const Resources = capitaliseString(resources);
|
|
46
|
+
|
|
47
|
+
const queryTypeDeclaration = [
|
|
48
|
+
'$first: Int!',
|
|
49
|
+
'$cursor: String',
|
|
50
|
+
...queries ? ['$query: String,'] : [],
|
|
51
|
+
...reverse !== undefined ? ['$reverse: Boolean,'] : [],
|
|
52
|
+
...savedSearchId ? ['$savedSearchId: ID,'] : [],
|
|
53
|
+
...sortKey ? [`$sortKey: ${ Resource }SortKeys,`] : [],
|
|
54
|
+
...roles ? [`$roles: [${ Resource }Role!],`] : [],
|
|
55
|
+
...names ? ['$names: [String!],'] : [],
|
|
56
|
+
...constraintStatus ? ['$constraintStatus: MetafieldDefinitionConstraintStatus,'] : [],
|
|
57
|
+
...constraintSubtype ? ['$constraintSubtype: MetafieldDefinitionConstraintSubtypeIdentifier,'] : [],
|
|
58
|
+
...namespace ? ['$namespace: String,'] : [],
|
|
59
|
+
...ownerType ? ['$ownerType: MetafieldOwnerType!,'] : [],
|
|
60
|
+
...pinnedStatus ? ['$pinnedStatus: MetafieldDefinitionPinnedStatus,'] : [],
|
|
61
|
+
...ownerGid ? ['$owner: ID!,'] : [],
|
|
62
|
+
...includeClosed ? ['$includeClosed: Boolean,'] : [],
|
|
63
|
+
...includeLegacy ? ['$includeLegacy: Boolean,'] : [],
|
|
64
|
+
...type ? [`$type: ${ argumentTypeOverrides['type'] || 'String!' },`] : [],
|
|
65
|
+
...sku ? ['$sku: String,'] : [],
|
|
66
|
+
].join('\n');
|
|
67
|
+
|
|
68
|
+
const queryVariableDeclaration = [
|
|
69
|
+
'first: $first',
|
|
70
|
+
'after: $cursor',
|
|
71
|
+
...queries ? ['query: $query'] : [],
|
|
72
|
+
...reverse !== undefined ? ['reverse: $reverse'] : [],
|
|
73
|
+
...savedSearchId ? ['savedSearchId: $savedSearchId'] : [],
|
|
74
|
+
...sortKey ? ['sortKey: $sortKey'] : [],
|
|
75
|
+
...roles ? ['roles: $roles'] : [],
|
|
76
|
+
...names ? ['names: $names'] : [],
|
|
77
|
+
...constraintStatus ? ['constraintStatus: $constraintStatus'] : [],
|
|
78
|
+
...constraintSubtype ? ['constraintSubtype: $constraintSubtype'] : [],
|
|
79
|
+
...namespace ? ['namespace: $namespace'] : [],
|
|
80
|
+
...ownerType ? ['ownerType: $ownerType'] : [],
|
|
81
|
+
...pinnedStatus ? ['pinnedStatus: $pinnedStatus'] : [],
|
|
82
|
+
...ownerGid ? ['owner: $owner'] : [],
|
|
83
|
+
...includeClosed ? ['includeClosed: $includeClosed'] : [],
|
|
84
|
+
...includeLegacy ? ['includeLegacy: $includeLegacy'] : [],
|
|
85
|
+
...type ? ['type: $type'] : [],
|
|
86
|
+
...sku ? ['sku: $sku'] : [],
|
|
87
|
+
].join('\n');
|
|
88
|
+
|
|
89
|
+
const variables = {
|
|
90
|
+
first: perPage,
|
|
91
|
+
cursor,
|
|
92
|
+
...reverse !== undefined && { reverse },
|
|
93
|
+
...queries && { query: queries.join(' AND ') },
|
|
94
|
+
...savedSearchId && { savedSearchId: `gid://shopify/SavedSearch/${ savedSearchId }` },
|
|
95
|
+
...sortKey && { sortKey },
|
|
96
|
+
...roles && { roles },
|
|
97
|
+
...names && { names },
|
|
98
|
+
...constraintStatus && { constraintStatus },
|
|
99
|
+
...constraintSubtype && { constraintSubtype },
|
|
100
|
+
...namespace && { namespace },
|
|
101
|
+
...ownerType && { ownerType },
|
|
102
|
+
...pinnedStatus && { pinnedStatus },
|
|
103
|
+
...ownerGid && { owner: ownerGid },
|
|
104
|
+
...includeClosed && { includeClosed },
|
|
105
|
+
...includeLegacy && { includeLegacy },
|
|
106
|
+
...type && { type },
|
|
107
|
+
...sku && { sku },
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return await shopifyClient.fetch({
|
|
111
|
+
method: 'post',
|
|
112
|
+
body: {
|
|
113
|
+
query: `
|
|
114
|
+
query Get${ Resources } (
|
|
115
|
+
${ queryTypeDeclaration }
|
|
116
|
+
) {
|
|
117
|
+
${ resources }(
|
|
118
|
+
${ queryVariableDeclaration }
|
|
119
|
+
) {
|
|
120
|
+
edges {
|
|
121
|
+
node {
|
|
122
|
+
${ attrs }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
pageInfo {
|
|
126
|
+
hasNextPage
|
|
127
|
+
endCursor
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
variables,
|
|
133
|
+
},
|
|
134
|
+
context: {
|
|
135
|
+
creds,
|
|
136
|
+
apiVersion,
|
|
137
|
+
resultPath: `data.${ resources }`,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const shopifyGetPaginator = async (currentParams, response) => {
|
|
143
|
+
|
|
144
|
+
const { args, options } = currentParams;
|
|
145
|
+
|
|
146
|
+
// Extract pagination info
|
|
147
|
+
const { ok, meta } = response;
|
|
148
|
+
const { pageInfo } = meta || {};
|
|
149
|
+
const { hasNextPage, endCursor } = pageInfo || {};
|
|
150
|
+
|
|
151
|
+
if (!ok) {
|
|
152
|
+
return [true];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Check if done
|
|
156
|
+
if (!hasNextPage) {
|
|
157
|
+
return [true];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Supplement params with pagination info
|
|
161
|
+
const paginatedParams = {
|
|
162
|
+
args,
|
|
163
|
+
options: {
|
|
164
|
+
...options,
|
|
165
|
+
cursor: endCursor,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return [false, paginatedParams];
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const shopifyGetDigester = (response) => {
|
|
173
|
+
const { ok, data } = response;
|
|
174
|
+
|
|
175
|
+
if (!ok) {
|
|
176
|
+
return null; // TODO: Consider a way to break out as this is an error
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return data;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const shopifyGet = async (
|
|
183
|
+
returnGetter, // Always bound
|
|
184
|
+
|
|
185
|
+
credsPayload,
|
|
186
|
+
resource,
|
|
187
|
+
{
|
|
188
|
+
apiVersion,
|
|
189
|
+
|
|
190
|
+
// Related to the actual query
|
|
191
|
+
perPage = 250,
|
|
192
|
+
cursor,
|
|
193
|
+
attrs = 'id',
|
|
194
|
+
queries,
|
|
195
|
+
reverse,
|
|
196
|
+
savedSearchId,
|
|
197
|
+
sortKey,
|
|
198
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/themes#arguments-names
|
|
199
|
+
roles,
|
|
200
|
+
names,
|
|
201
|
+
// https://shopify.dev/docs/api/admin-graphql/unstable/queries/metafielddefinitions
|
|
202
|
+
constraintStatus,
|
|
203
|
+
constraintSubtype,
|
|
204
|
+
namespace,
|
|
205
|
+
ownerType,
|
|
206
|
+
pinnedStatus,
|
|
207
|
+
// https://shopify.dev/docs/api/admin-graphql/unstable/queries/metafields#arguments-owner
|
|
208
|
+
ownerGid,
|
|
209
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/objects/fulfillmentOrder#queries
|
|
210
|
+
includeClosed,
|
|
211
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/locations#arguments-includeLegacy
|
|
212
|
+
includeLegacy,
|
|
213
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/metaobjects
|
|
214
|
+
type,
|
|
215
|
+
// https://shopify.dev/docs/api/admin-graphql/latest/queries/inventoryItems
|
|
216
|
+
sku,
|
|
217
|
+
|
|
218
|
+
// Helpers
|
|
219
|
+
resources = `${ resource }s`, // for when plural of the resource isn't `${ resource }s`
|
|
220
|
+
argumentTypeOverrides = {}, // for when a commonly-named API option is not just a single type, e.g. type being String vs CatalogType
|
|
221
|
+
|
|
222
|
+
...getterOptions // e.g. limit
|
|
223
|
+
} = {},
|
|
224
|
+
) => {
|
|
225
|
+
|
|
226
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
227
|
+
credsPayload,
|
|
228
|
+
resource,
|
|
229
|
+
});
|
|
230
|
+
if (rejectResponse) {
|
|
231
|
+
return rejectResponse;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const creds = await credsFromPayload(credsPayload);
|
|
235
|
+
|
|
236
|
+
const getter = new Getter(
|
|
237
|
+
{
|
|
238
|
+
args: [
|
|
239
|
+
creds,
|
|
240
|
+
resource,
|
|
241
|
+
resources,
|
|
242
|
+
attrs,
|
|
243
|
+
],
|
|
244
|
+
options: {
|
|
245
|
+
apiVersion,
|
|
246
|
+
perPage,
|
|
247
|
+
cursor,
|
|
248
|
+
queries,
|
|
249
|
+
reverse,
|
|
250
|
+
savedSearchId,
|
|
251
|
+
sortKey,
|
|
252
|
+
roles,
|
|
253
|
+
names,
|
|
254
|
+
constraintStatus,
|
|
255
|
+
constraintSubtype,
|
|
256
|
+
namespace,
|
|
257
|
+
ownerType,
|
|
258
|
+
pinnedStatus,
|
|
259
|
+
ownerGid,
|
|
260
|
+
includeClosed,
|
|
261
|
+
includeLegacy,
|
|
262
|
+
type,
|
|
263
|
+
sku,
|
|
264
|
+
argumentTypeOverrides,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
func: shopifyGetPacket,
|
|
269
|
+
digester: shopifyGetDigester,
|
|
270
|
+
paginator: shopifyGetPaginator,
|
|
271
|
+
...getterOptions,
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
if (returnGetter) {
|
|
276
|
+
return getter;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return await getter.run({ returnAll: true });
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const funcApiConfig = {
|
|
283
|
+
argsWarden,
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
module.exports = {
|
|
287
|
+
shopifyGet: (...args) => shopifyGet(false, ...args),
|
|
288
|
+
shopifyGetter: (...args) => shopifyGet(true, ...args),
|
|
289
|
+
funcApiConfig,
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/*
|
|
293
|
+
curl -X POST "http://localhost:8000/shopifyGet" \
|
|
294
|
+
-H "Content-Type: application/json" \
|
|
295
|
+
-d '{
|
|
296
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
297
|
+
"resource": "customer"
|
|
298
|
+
}'
|
|
299
|
+
|
|
300
|
+
curl -X POST "http://localhost:8000/shopifyGet" \
|
|
301
|
+
-H "Content-Type: application/json" \
|
|
302
|
+
-d '{
|
|
303
|
+
"credsPayload": { "credsPath": "shopify.au" },
|
|
304
|
+
"resource": "customer",
|
|
305
|
+
"options": {
|
|
306
|
+
"limit": 10
|
|
307
|
+
}
|
|
308
|
+
}'
|
|
309
|
+
*/
|