@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,12 @@
|
|
|
1
|
+
const { objHasAny } = require('./utils');
|
|
2
|
+
|
|
3
|
+
const credsValidator = (creds) => {
|
|
4
|
+
if (!objHasAny(creds, ['credsPath', 'credsObject', 'credsProvider'])) {
|
|
5
|
+
return false; // TODO: Consider returning [false, message]
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
credsValidator,
|
|
12
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const {
|
|
2
|
+
BASE_URL,
|
|
3
|
+
DEFAULT_API_VERSION,
|
|
4
|
+
} = require('../yotpo/yotpo.constants');
|
|
5
|
+
const {
|
|
6
|
+
FetchClient,
|
|
7
|
+
Chain,
|
|
8
|
+
appendUrlToBase,
|
|
9
|
+
fetchClientCommonSteps,
|
|
10
|
+
} = require('../utils');
|
|
11
|
+
|
|
12
|
+
const addUrlAndAuthHeaders = async (state) => {
|
|
13
|
+
const { requestPayload, context } = state;
|
|
14
|
+
const { creds, apiVersion = DEFAULT_API_VERSION } = context;
|
|
15
|
+
const { API_KEY, GUID } = creds;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
requestPayload: {
|
|
19
|
+
...requestPayload,
|
|
20
|
+
url: appendUrlToBase(`${ BASE_URL }/${ apiVersion }`, requestPayload.url),
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
'x-api-key': API_KEY,
|
|
24
|
+
'x-guid': GUID,
|
|
25
|
+
...requestPayload.headers,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const yotpoClientRequestPreparer = new Chain([
|
|
32
|
+
addUrlAndAuthHeaders,
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const yotpoClientResponseInterpreter = new Chain([
|
|
36
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
37
|
+
fetchClientCommonSteps.digToPath,
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
const yotpoClient = new FetchClient({
|
|
41
|
+
requestPreparer: yotpoClientRequestPreparer,
|
|
42
|
+
responseInterpreter: yotpoClientResponseInterpreter,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
yotpoClient,
|
|
47
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/get-active-campaigns
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const yotpoCampaignsGet = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
apiVersion,
|
|
15
|
+
withStatus,
|
|
16
|
+
customerIdentifier,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
|
|
21
|
+
if (rejectResponse) {
|
|
22
|
+
return rejectResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const creds = await credsFromPayload(credsPayload);
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
customerId,
|
|
29
|
+
customerEmail,
|
|
30
|
+
} = customerIdentifier ?? {};
|
|
31
|
+
|
|
32
|
+
const params = {
|
|
33
|
+
...(withStatus !== undefined && { with_status: withStatus }),
|
|
34
|
+
...(customerId && { customer_id: customerId }),
|
|
35
|
+
...(customerEmail && { customer_email: customerEmail }),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const response = await yotpoClient.fetch({
|
|
39
|
+
url: '/campaigns',
|
|
40
|
+
params,
|
|
41
|
+
context: {
|
|
42
|
+
creds,
|
|
43
|
+
apiVersion,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return response;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const funcApiConfig = {
|
|
51
|
+
argsWarden,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
yotpoCampaignsGet,
|
|
56
|
+
funcApiConfig,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
curl -X POST "http://localhost:8000/yotpoCampaignsGet" \
|
|
61
|
+
-H "Content-Type: application/json" \
|
|
62
|
+
-d '{
|
|
63
|
+
"credsPayload": { "credsPath": "yotpo.au" }
|
|
64
|
+
}'
|
|
65
|
+
|
|
66
|
+
curl -X POST "http://localhost:8000/yotpoCampaignsGet" \
|
|
67
|
+
-H "Content-Type: application/json" \
|
|
68
|
+
-d '{
|
|
69
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
70
|
+
"options": {
|
|
71
|
+
"withStatus": true,
|
|
72
|
+
"customerIdentifier": { "customerEmail": "john@whitefoxboutique.com" }
|
|
73
|
+
}
|
|
74
|
+
}'
|
|
75
|
+
*/
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/record-a-customer-action
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, objHasAny, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const customerIdentifierValidator = (customerIdentifier) => {
|
|
8
|
+
return objHasAny(customerIdentifier, [
|
|
9
|
+
'customerId',
|
|
10
|
+
'customerEmail',
|
|
11
|
+
]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const actionNameValidator = Boolean;
|
|
15
|
+
|
|
16
|
+
const argsWarden = new ArgsWarden([
|
|
17
|
+
['credsPayload', credsValidator],
|
|
18
|
+
['customerIdentifier', customerIdentifierValidator],
|
|
19
|
+
['actionName', actionNameValidator],
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const yotpoCustomerActionRecord = async (
|
|
23
|
+
credsPayload,
|
|
24
|
+
customerIdentifier,
|
|
25
|
+
actionName,
|
|
26
|
+
{
|
|
27
|
+
apiVersion,
|
|
28
|
+
type = 'CustomAction',
|
|
29
|
+
ipAddress,
|
|
30
|
+
userAgent,
|
|
31
|
+
createdAt,
|
|
32
|
+
rewardPoints,
|
|
33
|
+
historyTitle,
|
|
34
|
+
} = {},
|
|
35
|
+
) => {
|
|
36
|
+
|
|
37
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
38
|
+
credsPayload,
|
|
39
|
+
customerIdentifier,
|
|
40
|
+
actionName,
|
|
41
|
+
});
|
|
42
|
+
if (rejectResponse) {
|
|
43
|
+
return rejectResponse;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const creds = await credsFromPayload(credsPayload);
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
customerId,
|
|
50
|
+
customerEmail,
|
|
51
|
+
} = customerIdentifier;
|
|
52
|
+
|
|
53
|
+
const body = {
|
|
54
|
+
type,
|
|
55
|
+
action_name: actionName,
|
|
56
|
+
...(customerId && { customer_id: customerId }),
|
|
57
|
+
...(customerEmail && { customer_email: customerEmail }),
|
|
58
|
+
...(ipAddress && { ip_address: ipAddress }),
|
|
59
|
+
...(userAgent && { user_agent: userAgent }),
|
|
60
|
+
...(createdAt && { created_at: createdAt }),
|
|
61
|
+
...(rewardPoints !== undefined && { reward_points: Number(rewardPoints) }),
|
|
62
|
+
...(historyTitle && { history_title: historyTitle }),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const response = await yotpoClient.fetch({
|
|
66
|
+
url: '/actions',
|
|
67
|
+
method: 'post',
|
|
68
|
+
body,
|
|
69
|
+
context: {
|
|
70
|
+
creds,
|
|
71
|
+
apiVersion,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return response;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const funcApiConfig = {
|
|
79
|
+
argsWarden,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports = {
|
|
83
|
+
yotpoCustomerActionRecord,
|
|
84
|
+
funcApiConfig,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
curl -X POST "http://localhost:8000/yotpoCustomerActionRecord" \
|
|
89
|
+
-H "Content-Type: application/json" \
|
|
90
|
+
-d '{
|
|
91
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
92
|
+
"customerIdentifier": { "customerEmail": "john@whitefoxboutique.com" },
|
|
93
|
+
"actionName": "completed_survey"
|
|
94
|
+
}'
|
|
95
|
+
*/
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/get-customer-anniversary
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['customerEmail'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const yotpoCustomerAnniversaryGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
customerEmail,
|
|
15
|
+
{
|
|
16
|
+
apiVersion,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
21
|
+
credsPayload,
|
|
22
|
+
customerEmail,
|
|
23
|
+
});
|
|
24
|
+
if (rejectResponse) {
|
|
25
|
+
return rejectResponse;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const creds = await credsFromPayload(credsPayload);
|
|
29
|
+
|
|
30
|
+
const response = await yotpoClient.fetch({
|
|
31
|
+
url: '/customer_anniversary',
|
|
32
|
+
params: {
|
|
33
|
+
customer_email: customerEmail,
|
|
34
|
+
},
|
|
35
|
+
context: {
|
|
36
|
+
creds,
|
|
37
|
+
apiVersion,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return response;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const funcApiConfig = {
|
|
45
|
+
argsWarden,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
yotpoCustomerAnniversaryGet,
|
|
50
|
+
funcApiConfig,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
curl -X POST "http://localhost:8000/yotpoCustomerAnniversaryGet" \
|
|
55
|
+
-H "Content-Type: application/json" \
|
|
56
|
+
-d '{
|
|
57
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
58
|
+
"customerEmail": "john@whitefoxboutique.com"
|
|
59
|
+
}'
|
|
60
|
+
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/createupdate-customer-anniversary
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const dayValidator = Number;
|
|
8
|
+
const monthValidator = Number;
|
|
9
|
+
|
|
10
|
+
const argsWarden = new ArgsWarden([
|
|
11
|
+
['credsPayload', credsValidator],
|
|
12
|
+
['customerEmail'],
|
|
13
|
+
['day', dayValidator],
|
|
14
|
+
['month', monthValidator],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const yotpoCustomerAnniversarySet = async (
|
|
18
|
+
credsPayload,
|
|
19
|
+
customerEmail,
|
|
20
|
+
day,
|
|
21
|
+
month,
|
|
22
|
+
{
|
|
23
|
+
apiVersion,
|
|
24
|
+
year,
|
|
25
|
+
} = {},
|
|
26
|
+
) => {
|
|
27
|
+
|
|
28
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
29
|
+
credsPayload,
|
|
30
|
+
customerEmail,
|
|
31
|
+
day,
|
|
32
|
+
month,
|
|
33
|
+
});
|
|
34
|
+
if (rejectResponse) {
|
|
35
|
+
return rejectResponse;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const creds = await credsFromPayload(credsPayload);
|
|
39
|
+
|
|
40
|
+
const body = {
|
|
41
|
+
customer_email: customerEmail,
|
|
42
|
+
day: Number(day),
|
|
43
|
+
month: Number(month),
|
|
44
|
+
...(year !== undefined && { year: Number(year) }),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const response = await yotpoClient.fetch({
|
|
48
|
+
url: '/customer_anniversary',
|
|
49
|
+
method: 'post',
|
|
50
|
+
body,
|
|
51
|
+
context: {
|
|
52
|
+
creds,
|
|
53
|
+
apiVersion,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return response;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const funcApiConfig = {
|
|
61
|
+
argsWarden,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
yotpoCustomerAnniversarySet,
|
|
66
|
+
funcApiConfig,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
curl -X POST "http://localhost:8000/yotpoCustomerAnniversarySet" \
|
|
71
|
+
-H "Content-Type: application/json" \
|
|
72
|
+
-d '{
|
|
73
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
74
|
+
"customerEmail": "john@whitefoxboutique.com",
|
|
75
|
+
"day": 1,
|
|
76
|
+
"month": 7
|
|
77
|
+
}'
|
|
78
|
+
*/
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/set-customer-birthday
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, objHasAny, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const customerIdentifierValidator = (customerIdentifier) => {
|
|
8
|
+
return objHasAny(customerIdentifier, [
|
|
9
|
+
'customerId',
|
|
10
|
+
'customerEmail',
|
|
11
|
+
]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const dayValidator = Number;
|
|
15
|
+
const monthValidator = Number;
|
|
16
|
+
|
|
17
|
+
const argsWarden = new ArgsWarden([
|
|
18
|
+
['credsPayload', credsValidator],
|
|
19
|
+
['customerIdentifier', customerIdentifierValidator],
|
|
20
|
+
['day', dayValidator],
|
|
21
|
+
['month', monthValidator],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const yotpoCustomerBirthdaySet = async (
|
|
25
|
+
credsPayload,
|
|
26
|
+
customerIdentifier,
|
|
27
|
+
day,
|
|
28
|
+
month,
|
|
29
|
+
{
|
|
30
|
+
apiVersion,
|
|
31
|
+
year,
|
|
32
|
+
} = {},
|
|
33
|
+
) => {
|
|
34
|
+
|
|
35
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
36
|
+
credsPayload,
|
|
37
|
+
customerIdentifier,
|
|
38
|
+
day,
|
|
39
|
+
month,
|
|
40
|
+
});
|
|
41
|
+
if (rejectResponse) {
|
|
42
|
+
return rejectResponse;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const creds = await credsFromPayload(credsPayload);
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
customerId,
|
|
49
|
+
customerEmail,
|
|
50
|
+
} = customerIdentifier;
|
|
51
|
+
|
|
52
|
+
const body = {
|
|
53
|
+
day: Number(day),
|
|
54
|
+
month: Number(month),
|
|
55
|
+
...(customerId && { customer_id: customerId }),
|
|
56
|
+
...(customerEmail && { customer_email: customerEmail }),
|
|
57
|
+
...(year !== undefined && { year: Number(year) }),
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const response = await yotpoClient.fetch({
|
|
61
|
+
url: '/customer_birthdays',
|
|
62
|
+
method: 'post',
|
|
63
|
+
body,
|
|
64
|
+
context: {
|
|
65
|
+
creds,
|
|
66
|
+
apiVersion,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return response;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const funcApiConfig = {
|
|
74
|
+
argsWarden,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
yotpoCustomerBirthdaySet,
|
|
79
|
+
funcApiConfig,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
curl -X POST "http://localhost:8000/yotpoCustomerBirthdaySet" \
|
|
84
|
+
-H "Content-Type: application/json" \
|
|
85
|
+
-d '{
|
|
86
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
87
|
+
"customerIdentifier": { "customerEmail": "john@whitefoxboutique.com" },
|
|
88
|
+
"day": 1,
|
|
89
|
+
"month": 7
|
|
90
|
+
}'
|
|
91
|
+
*/
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/fetch-customer-details
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, objHasAny, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const customerIdentifierValidator = (customerIdentifier) => {
|
|
8
|
+
return objHasAny(customerIdentifier, [
|
|
9
|
+
'customerId',
|
|
10
|
+
'customerEmail',
|
|
11
|
+
'customerPhone',
|
|
12
|
+
'posAccountId',
|
|
13
|
+
]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const argsWarden = new ArgsWarden([
|
|
17
|
+
['credsPayload', credsValidator],
|
|
18
|
+
['customerIdentifier', customerIdentifierValidator],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const yotpoCustomerGet = async (
|
|
22
|
+
credsPayload,
|
|
23
|
+
customerIdentifier,
|
|
24
|
+
{
|
|
25
|
+
apiVersion,
|
|
26
|
+
countryCodeIso,
|
|
27
|
+
withReferralCode,
|
|
28
|
+
withHistory,
|
|
29
|
+
} = {},
|
|
30
|
+
) => {
|
|
31
|
+
|
|
32
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
33
|
+
credsPayload,
|
|
34
|
+
customerIdentifier,
|
|
35
|
+
});
|
|
36
|
+
if (rejectResponse) {
|
|
37
|
+
return rejectResponse;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const creds = await credsFromPayload(credsPayload);
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
customerId,
|
|
44
|
+
customerEmail,
|
|
45
|
+
customerPhone,
|
|
46
|
+
posAccountId,
|
|
47
|
+
} = customerIdentifier;
|
|
48
|
+
|
|
49
|
+
const params = {
|
|
50
|
+
...(customerId && { customer_id: customerId }),
|
|
51
|
+
...(customerEmail && { customer_email: customerEmail }),
|
|
52
|
+
...(customerPhone && { phone_number: customerPhone }),
|
|
53
|
+
...(posAccountId && { pos_account_id: posAccountId }),
|
|
54
|
+
...(countryCodeIso && { country_code_iso: countryCodeIso }),
|
|
55
|
+
...(withReferralCode !== undefined && { with_referral_code: withReferralCode }),
|
|
56
|
+
...(withHistory !== undefined && { with_history: withHistory }),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const response = await yotpoClient.fetch({
|
|
60
|
+
url: '/customers',
|
|
61
|
+
params,
|
|
62
|
+
context: {
|
|
63
|
+
creds,
|
|
64
|
+
apiVersion,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return response;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const funcApiConfig = {
|
|
72
|
+
argsWarden,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
yotpoCustomerGet,
|
|
77
|
+
funcApiConfig,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
curl -X POST "http://localhost:8000/yotpoCustomerGet" \
|
|
82
|
+
-H "Content-Type: application/json" \
|
|
83
|
+
-d '{
|
|
84
|
+
"credsPayload": {
|
|
85
|
+
"credsObject": {
|
|
86
|
+
"API_KEY": "xxx",
|
|
87
|
+
"GUID": "xxx"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"customerIdentifier": {
|
|
91
|
+
"customerEmail": "john@example.com"
|
|
92
|
+
},
|
|
93
|
+
"options": {
|
|
94
|
+
"withHistory": true
|
|
95
|
+
}
|
|
96
|
+
}'
|
|
97
|
+
|
|
98
|
+
curl -X POST "http://localhost:8000/yotpoCustomerGet" \
|
|
99
|
+
-H "Content-Type: application/json" \
|
|
100
|
+
-d '{
|
|
101
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
102
|
+
"customerIdentifier": { "customerEmail": "john@whitefoxboutique.com" }
|
|
103
|
+
}'
|
|
104
|
+
*/
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// https://loyaltyapi.yotpo.com/reference/adjust-a-customers-point-balance
|
|
2
|
+
|
|
3
|
+
const { credsFromPayload, objHasAny, ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
|
+
|
|
7
|
+
const customerIdentifierValidator = (customerIdentifier) => {
|
|
8
|
+
return objHasAny(customerIdentifier, [
|
|
9
|
+
'customerId',
|
|
10
|
+
'customerEmail',
|
|
11
|
+
]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const pointsAmountValidator = Number;
|
|
15
|
+
|
|
16
|
+
const argsWarden = new ArgsWarden([
|
|
17
|
+
['credsPayload', credsValidator],
|
|
18
|
+
['customerIdentifier', customerIdentifierValidator],
|
|
19
|
+
['pointsAmount', pointsAmountValidator],
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const yotpoCustomerPointsAdjust = async (
|
|
23
|
+
credsPayload,
|
|
24
|
+
customerIdentifier,
|
|
25
|
+
pointsAmount,
|
|
26
|
+
{
|
|
27
|
+
apiVersion,
|
|
28
|
+
applyAdjustmentToPointsEarned,
|
|
29
|
+
historyTitle,
|
|
30
|
+
visibleToCustomer = true,
|
|
31
|
+
} = {},
|
|
32
|
+
) => {
|
|
33
|
+
|
|
34
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
35
|
+
credsPayload,
|
|
36
|
+
customerIdentifier,
|
|
37
|
+
pointsAmount,
|
|
38
|
+
});
|
|
39
|
+
if (rejectResponse) {
|
|
40
|
+
return rejectResponse;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const creds = await credsFromPayload(credsPayload);
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
customerId,
|
|
47
|
+
customerEmail,
|
|
48
|
+
} = customerIdentifier;
|
|
49
|
+
|
|
50
|
+
const body = {
|
|
51
|
+
point_adjustment_amount: Number(pointsAmount),
|
|
52
|
+
...(customerId && { customer_id: customerId }),
|
|
53
|
+
...(customerEmail && { customer_email: customerEmail }),
|
|
54
|
+
...(historyTitle && { history_title: historyTitle }),
|
|
55
|
+
...(applyAdjustmentToPointsEarned !== undefined && { apply_adjustment_to_points_earned: applyAdjustmentToPointsEarned }),
|
|
56
|
+
visible_to_customer: visibleToCustomer,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const response = await yotpoClient.fetch({
|
|
60
|
+
url: '/points/adjust',
|
|
61
|
+
method: 'post',
|
|
62
|
+
body,
|
|
63
|
+
context: {
|
|
64
|
+
creds,
|
|
65
|
+
apiVersion,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return response;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const funcApiConfig = {
|
|
73
|
+
argsWarden,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
yotpoCustomerPointsAdjust,
|
|
78
|
+
funcApiConfig,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
curl -X POST "http://localhost:8000/yotpoCustomerPointsAdjust" \
|
|
83
|
+
-H "Content-Type: application/json" \
|
|
84
|
+
-d '{
|
|
85
|
+
"credsPayload": { "credsPath": "yotpo.au" },
|
|
86
|
+
"customerIdentifier": { "customerEmail": "john@whitefoxboutique.com" },
|
|
87
|
+
"pointsAmount": 100
|
|
88
|
+
}'
|
|
89
|
+
*/
|