@foxtware/mineral 0.1.17 → 0.1.18
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 +16 -7
- package/AGENTS.md +3 -0
- package/_build_scripts/publish.js +15 -1
- package/api/backblaze/backblaze.constants.js +11 -0
- package/api/backblaze/backblaze.utils.js +322 -0
- package/api/backblaze/backblazeBucketsGet.js +68 -0
- package/api/backblaze/backblazeFileDelete.js +62 -0
- package/api/backblaze/backblazeFileHide.js +62 -0
- package/api/backblaze/backblazeFileUpload.js +142 -0
- package/api/backblaze/backblazeFilesGet.js +85 -0
- package/api/backblaze/backblazeGet.js +139 -0
- package/api/backblaze/docs.md +6 -0
- package/api/etsy/etsyListingUpdate.js +1 -1
- package/api/gorgias/gorgias.constants.js +8 -0
- package/api/gorgias/gorgias.utils.js +46 -0
- package/api/gorgias/gorgiasAccountGet.js +51 -0
- package/api/gorgias/gorgiasCustomerGet.js +70 -0
- package/api/gorgias/gorgiasCustomersGet.js +56 -0
- package/api/gorgias/gorgiasGet.js +150 -0
- package/api/gorgias/gorgiasGetSingle.js +26 -0
- package/api/gorgias/gorgiasMessagesGet.js +56 -0
- package/api/gorgias/gorgiasTagsGet.js +52 -0
- package/api/gorgias/gorgiasTicketCreate.js +66 -0
- package/api/gorgias/gorgiasTicketGet.js +70 -0
- package/api/gorgias/gorgiasTicketMessageCreate.js +65 -0
- package/api/gorgias/gorgiasTicketMessagesGet.js +66 -0
- package/api/gorgias/gorgiasTicketUpdate.js +62 -0
- package/api/gorgias/gorgiasTicketsGet.js +58 -0
- package/api/gorgias/gorgiasUsersGet.js +52 -0
- package/api/gorgias/gorgiasViewItemsGet.js +57 -0
- package/api/gorgias/gorgiasViewsGet.js +72 -0
- package/api/linear/docs.md +6 -0
- package/api/linear/linear.constants.js +3 -0
- package/api/linear/linear.utils.js +59 -0
- package/api/linear/linearAttachmentCreate.js +77 -0
- package/api/linear/linearAttachmentDelete.js +68 -0
- package/api/linear/linearCommentCreate.js +77 -0
- package/api/linear/linearCommentDelete.js +68 -0
- package/api/linear/linearCommentGet.js +77 -0
- package/api/linear/linearCommentUpdate.js +87 -0
- package/api/linear/linearCommentsGet.js +70 -0
- package/api/linear/linearCyclesGet.js +67 -0
- package/api/linear/linearGet.js +218 -0
- package/api/linear/linearIssueAddLabel.js +77 -0
- package/api/linear/linearIssueArchive.js +74 -0
- package/api/linear/linearIssueCreate.js +94 -0
- package/api/linear/linearIssueDelete.js +74 -0
- package/api/linear/linearIssueGet.js +87 -0
- package/api/linear/linearIssueLabelCreate.js +81 -0
- package/api/linear/linearIssueLabelsGet.js +66 -0
- package/api/linear/linearIssueRemoveLabel.js +77 -0
- package/api/linear/linearIssueUpdate.js +96 -0
- package/api/linear/linearIssuesGet.js +39 -63
- package/api/linear/linearOrganizationGet.js +64 -0
- package/api/linear/linearProjectCreate.js +92 -0
- package/api/linear/linearProjectGet.js +74 -0
- package/api/linear/linearProjectUpdate.js +80 -0
- package/api/linear/linearProjectsGet.js +71 -0
- package/api/linear/linearTeamGet.js +71 -0
- package/api/linear/linearTeamsGet.js +66 -0
- package/api/linear/linearUserGet.js +72 -0
- package/api/linear/linearUsersGet.js +71 -0
- package/api/linear/linearViewerGet.js +65 -0
- package/api/linear/linearWebhookCreate.js +77 -0
- package/api/linear/linearWebhookDelete.js +68 -0
- package/api/linear/linearWebhooksGet.js +67 -0
- package/api/linear/linearWorkflowStatesGet.js +73 -0
- package/api/pipe17/pipe17.utils.js +7 -20
- package/api/pipe17/pipe17ArrivalGet.js +1 -1
- package/api/pipe17/pipe17FulfillmentGet.js +1 -1
- package/api/pipe17/pipe17InventoryItemGet.js +1 -1
- package/api/pipe17/pipe17JobGet.js +11 -24
- package/api/pipe17/pipe17LocationGet.js +1 -1
- package/api/pipe17/pipe17OrderGet.js +1 -1
- package/api/pipe17/pipe17ProductGet.js +1 -1
- package/api/pipe17/pipe17PurchaseGet.js +1 -1
- package/api/pipe17/pipe17ReceiptGet.js +1 -1
- package/api/pipe17/pipe17ReturnGet.js +1 -1
- package/api/shopify/shopifyFileCreate.js +107 -0
- package/api/shopify/shopifyMetafieldDefinitionCreate.js +2 -0
- package/api/shopify/shopifyMetafieldDefinitionGet.js +108 -0
- package/api/shopify/shopifyMetafieldDefinitionPropagate.js +27 -71
- package/api/shopify/shopifyThemeFileGet.js +112 -0
- package/api/shopify/shopifyThemeFilePropagate.js +410 -0
- package/api/shopify/shopifyThemeFilesUpsert.js +88 -0
- package/api/starshipit/starshipit.utils.js +1 -0
- package/api/starshipit/starshipitOrderGet.js +2 -10
- package/api/utils.js +12 -4
- package/package.json +1 -1
- package/server.utils.js +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// https://www.backblaze.com/apidocs/b2-upload-file
|
|
2
|
+
|
|
3
|
+
const fs = require('fs').promises;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const { ArgsWarden, valueProvided } = require('../utils');
|
|
7
|
+
const { credsValidator } = require('../validators');
|
|
8
|
+
const {
|
|
9
|
+
backblazeUploadFileBytes,
|
|
10
|
+
bucketIdentifierValidator,
|
|
11
|
+
getBackblazeSession,
|
|
12
|
+
publicFileUrlForBucketName,
|
|
13
|
+
resolveBucketIdFromIdentifier,
|
|
14
|
+
} = require('../backblaze/backblaze.utils');
|
|
15
|
+
|
|
16
|
+
const fileDataValidator = (fileData) => {
|
|
17
|
+
const { filePath, fileName, fileSource } = fileData;
|
|
18
|
+
return valueProvided(filePath)
|
|
19
|
+
|| (valueProvided(fileName) && valueProvided(fileSource))
|
|
20
|
+
;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const argsWarden = new ArgsWarden([
|
|
24
|
+
['credsPayload', credsValidator],
|
|
25
|
+
['bucketIdentifier', bucketIdentifierValidator],
|
|
26
|
+
['fileData', fileDataValidator],
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const backblazeFileUpload = async (
|
|
30
|
+
credsPayload,
|
|
31
|
+
bucketIdentifier,
|
|
32
|
+
fileData,
|
|
33
|
+
{
|
|
34
|
+
contentType = 'b2/x-auto',
|
|
35
|
+
} = {},
|
|
36
|
+
) => {
|
|
37
|
+
|
|
38
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
39
|
+
credsPayload,
|
|
40
|
+
bucketIdentifier,
|
|
41
|
+
fileData,
|
|
42
|
+
});
|
|
43
|
+
if (rejectResponse) {
|
|
44
|
+
return rejectResponse;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
bucketName,
|
|
49
|
+
} = bucketIdentifier;
|
|
50
|
+
|
|
51
|
+
const bucketIdResponse = await resolveBucketIdFromIdentifier(
|
|
52
|
+
credsPayload,
|
|
53
|
+
bucketIdentifier,
|
|
54
|
+
);
|
|
55
|
+
if (!bucketIdResponse.ok) {
|
|
56
|
+
return bucketIdResponse;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { data: bucketId } = bucketIdResponse;
|
|
60
|
+
|
|
61
|
+
let {
|
|
62
|
+
filePath,
|
|
63
|
+
fileName,
|
|
64
|
+
fileSource,
|
|
65
|
+
} = fileData;
|
|
66
|
+
|
|
67
|
+
if (filePath) {
|
|
68
|
+
fileName = path.basename(filePath);
|
|
69
|
+
fileSource = await fs.readFile(filePath);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!(fileName && fileSource !== undefined)) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
error: {
|
|
76
|
+
code: 'INVALID_FILE_DATA',
|
|
77
|
+
message: 'Provide filePath or fileName with fileSource',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const fileBytes = Buffer.isBuffer(fileSource)
|
|
83
|
+
? fileSource
|
|
84
|
+
: Buffer.from(String(fileSource));
|
|
85
|
+
|
|
86
|
+
const uploadResponse = await backblazeUploadFileBytes({
|
|
87
|
+
credsPayload,
|
|
88
|
+
bucketId,
|
|
89
|
+
fileName,
|
|
90
|
+
fileBytes,
|
|
91
|
+
contentType,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (!uploadResponse.ok) {
|
|
95
|
+
return uploadResponse;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let publicFileUrl;
|
|
99
|
+
|
|
100
|
+
if (bucketName) {
|
|
101
|
+
const sessionResponse = await getBackblazeSession(credsPayload);
|
|
102
|
+
|
|
103
|
+
if (sessionResponse.ok) {
|
|
104
|
+
publicFileUrl = publicFileUrlForBucketName({
|
|
105
|
+
downloadUrl: sessionResponse.data.downloadUrl,
|
|
106
|
+
bucketName,
|
|
107
|
+
fileName: uploadResponse.data?.fileName ?? fileName,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
ok: true,
|
|
114
|
+
data: {
|
|
115
|
+
...uploadResponse.data,
|
|
116
|
+
...publicFileUrl && {
|
|
117
|
+
customData: {
|
|
118
|
+
publicFileUrl,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const funcApiConfig = {
|
|
126
|
+
argsWarden,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
module.exports = {
|
|
130
|
+
backblazeFileUpload,
|
|
131
|
+
funcApiConfig,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
curl -X POST "http://localhost:8000/backblazeFileUpload" \
|
|
136
|
+
-H "Content-Type: application/json" \
|
|
137
|
+
-d '{
|
|
138
|
+
"credsPayload": { "credsPath": "backblaze" },
|
|
139
|
+
"bucketIdentifier": { "bucketName": "crabs" },
|
|
140
|
+
"fileData": { "fileName": "crab.txt", "fileSource": "one big claw, one small" }
|
|
141
|
+
}'
|
|
142
|
+
*/
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// https://www.backblaze.com/apidocs/b2-list-file-names
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { B2_API_VERSION_PATH } = require('../backblaze/backblaze.constants');
|
|
6
|
+
const {
|
|
7
|
+
bucketIdentifierValidator,
|
|
8
|
+
resolveBucketIdFromIdentifier,
|
|
9
|
+
} = require('../backblaze/backblaze.utils');
|
|
10
|
+
const { backblazeGet, backblazeGetter } = require('../backblaze/backblazeGet');
|
|
11
|
+
|
|
12
|
+
const argsWarden = new ArgsWarden([
|
|
13
|
+
['credsPayload', credsValidator],
|
|
14
|
+
['bucketIdentifier', bucketIdentifierValidator],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const backblazeFilesGet = async (
|
|
18
|
+
returnGetter,
|
|
19
|
+
|
|
20
|
+
credsPayload,
|
|
21
|
+
bucketIdentifier,
|
|
22
|
+
{
|
|
23
|
+
prefix,
|
|
24
|
+
maxFileCount,
|
|
25
|
+
fetchClient,
|
|
26
|
+
...getterOptions
|
|
27
|
+
} = {},
|
|
28
|
+
) => {
|
|
29
|
+
|
|
30
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
31
|
+
credsPayload,
|
|
32
|
+
bucketIdentifier,
|
|
33
|
+
});
|
|
34
|
+
if (rejectResponse) {
|
|
35
|
+
return rejectResponse;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const bucketIdResponse = await resolveBucketIdFromIdentifier(
|
|
39
|
+
credsPayload,
|
|
40
|
+
bucketIdentifier,
|
|
41
|
+
{ fetchClient },
|
|
42
|
+
);
|
|
43
|
+
if (!bucketIdResponse.ok) {
|
|
44
|
+
return bucketIdResponse;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { data: bucketId } = bucketIdResponse;
|
|
48
|
+
|
|
49
|
+
const getterArgs = [
|
|
50
|
+
credsPayload,
|
|
51
|
+
`${ B2_API_VERSION_PATH }/b2_list_file_names`,
|
|
52
|
+
{
|
|
53
|
+
params: {
|
|
54
|
+
bucketId,
|
|
55
|
+
...prefix && { prefix },
|
|
56
|
+
},
|
|
57
|
+
...maxFileCount && { maxFileCount },
|
|
58
|
+
...fetchClient && { fetchClient },
|
|
59
|
+
...getterOptions,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
return returnGetter
|
|
64
|
+
? backblazeGetter(...getterArgs)
|
|
65
|
+
: backblazeGet(...getterArgs);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const funcApiConfig = {
|
|
69
|
+
argsWarden,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
backblazeFilesGet: (...args) => backblazeFilesGet(false, ...args),
|
|
74
|
+
backblazeFilesGetter: (...args) => backblazeFilesGet(true, ...args),
|
|
75
|
+
funcApiConfig,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
curl -X POST "http://localhost:8000/backblazeFilesGet" \
|
|
80
|
+
-H "Content-Type: application/json" \
|
|
81
|
+
-d '{
|
|
82
|
+
"credsPayload": { "credsPath": "backblaze" },
|
|
83
|
+
"bucketIdentifier": { "bucketName": "crabs" }
|
|
84
|
+
}'
|
|
85
|
+
*/
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// https://www.backblaze.com/apidocs/b2-list-file-names
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, Getter } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { B2_API_VERSION_PATH, MAX_FILES_PER_PAGE } = require('../backblaze/backblaze.constants');
|
|
6
|
+
const { backblazeClient } = require('../backblaze/backblaze.utils');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['url'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const backblazeGetPacket = async (
|
|
14
|
+
credsPayload,
|
|
15
|
+
url,
|
|
16
|
+
{
|
|
17
|
+
params,
|
|
18
|
+
maxFileCount = MAX_FILES_PER_PAGE,
|
|
19
|
+
fetchClient = backblazeClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
return fetchClient.fetch({
|
|
24
|
+
requestPayload: {
|
|
25
|
+
method: 'get',
|
|
26
|
+
url,
|
|
27
|
+
params: {
|
|
28
|
+
maxFileCount,
|
|
29
|
+
...params,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
context: { credsPayload },
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const backblazeGetPaginator = async (currentParams, response) => {
|
|
37
|
+
if (!response?.ok) {
|
|
38
|
+
return [true];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { nextFileName } = response.data ?? {};
|
|
42
|
+
|
|
43
|
+
if (!nextFileName) {
|
|
44
|
+
return [true];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { args, options } = currentParams;
|
|
48
|
+
|
|
49
|
+
return [false, {
|
|
50
|
+
args,
|
|
51
|
+
options: {
|
|
52
|
+
...options,
|
|
53
|
+
params: {
|
|
54
|
+
...options.params,
|
|
55
|
+
startFileName: nextFileName,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const backblazeGetDigester = (response) => {
|
|
62
|
+
if (!response?.ok) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return response.data?.files ?? [];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const backblazeGet = async (
|
|
70
|
+
returnGetter,
|
|
71
|
+
|
|
72
|
+
credsPayload,
|
|
73
|
+
url,
|
|
74
|
+
{
|
|
75
|
+
params,
|
|
76
|
+
maxFileCount = MAX_FILES_PER_PAGE,
|
|
77
|
+
fetchClient,
|
|
78
|
+
...getterOptions
|
|
79
|
+
} = {},
|
|
80
|
+
) => {
|
|
81
|
+
|
|
82
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
83
|
+
credsPayload,
|
|
84
|
+
url,
|
|
85
|
+
});
|
|
86
|
+
if (rejectResponse) {
|
|
87
|
+
return rejectResponse;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const getter = new Getter(
|
|
91
|
+
{
|
|
92
|
+
args: [credsPayload, url],
|
|
93
|
+
options: {
|
|
94
|
+
params,
|
|
95
|
+
maxFileCount,
|
|
96
|
+
fetchClient,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
func: backblazeGetPacket,
|
|
101
|
+
digester: backblazeGetDigester,
|
|
102
|
+
paginator: backblazeGetPaginator,
|
|
103
|
+
...getterOptions,
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
if (returnGetter) {
|
|
108
|
+
return getter;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const data = await getter.run({ returnAll: true });
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
ok: true,
|
|
115
|
+
data,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const funcApiConfig = {
|
|
120
|
+
argsWarden,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
backblazeGet: (...args) => backblazeGet(false, ...args),
|
|
125
|
+
backblazeGetter: (...args) => backblazeGet(true, ...args),
|
|
126
|
+
funcApiConfig,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/*
|
|
130
|
+
curl -X POST "http://localhost:8000/backblazeGet" \
|
|
131
|
+
-H "Content-Type: application/json" \
|
|
132
|
+
-d '{
|
|
133
|
+
"credsPayload": { "credsPath": "backblaze" },
|
|
134
|
+
"url": "/b2api/v2/b2_list_file_names",
|
|
135
|
+
"options": {
|
|
136
|
+
"params": { "bucketId": "REPLACE_BUCKET_ID" }
|
|
137
|
+
}
|
|
138
|
+
}'
|
|
139
|
+
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Backblaze B2
|
|
2
|
+
|
|
3
|
+
- [B2 Native API](https://www.backblaze.com/apidocs/introduction-to-the-b2-native-api)
|
|
4
|
+
- [Authorize account](https://www.backblaze.com/apidocs/b2-authorize-account)
|
|
5
|
+
|
|
6
|
+
REST JSON. Application keys authenticate via HTTP Basic on `b2_authorize_account` at `https://api.backblazeb2.com`; the response supplies an account-specific `apiUrl` and bearer token for other `b2_*` calls. Uploads use a dedicated upload URL and token from `b2_get_upload_url`, not the account authorization token.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { apiBaseUrlForDomain } = require('../gorgias/gorgias.constants');
|
|
2
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
3
|
+
const {
|
|
4
|
+
appendUrlToBase,
|
|
5
|
+
FetchClient,
|
|
6
|
+
fetchClientCommonSteps,
|
|
7
|
+
} = require('../utils');
|
|
8
|
+
|
|
9
|
+
const useUrlAndAuthHeaders = async (state) => {
|
|
10
|
+
const { requestPayload, context } = state;
|
|
11
|
+
const { creds } = context;
|
|
12
|
+
const {
|
|
13
|
+
API_KEY,
|
|
14
|
+
DOMAIN,
|
|
15
|
+
EMAIL,
|
|
16
|
+
} = creds;
|
|
17
|
+
|
|
18
|
+
const basicToken = Buffer
|
|
19
|
+
.from(`${ EMAIL }:${ API_KEY }`)
|
|
20
|
+
.toString('base64');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
requestPayload: {
|
|
24
|
+
...requestPayload,
|
|
25
|
+
url: appendUrlToBase(apiBaseUrlForDomain(DOMAIN), requestPayload.url),
|
|
26
|
+
headers: {
|
|
27
|
+
Accept: 'application/json',
|
|
28
|
+
Authorization: `Basic ${ basicToken }`,
|
|
29
|
+
...requestPayload.headers,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const gorgiasClient = new FetchClient({
|
|
36
|
+
pipeline: [
|
|
37
|
+
resolveCreds,
|
|
38
|
+
useUrlAndAuthHeaders,
|
|
39
|
+
'fetch',
|
|
40
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
gorgiasClient,
|
|
46
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// https://developers.gorgias.com/reference/get-account
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { gorgiasClient } = require('../gorgias/gorgias.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const gorgiasAccountGet = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
inspect = false,
|
|
15
|
+
fetchClient = gorgiasClient,
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
});
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return fetchClient.fetch({
|
|
27
|
+
requestPayload: {
|
|
28
|
+
method: 'get',
|
|
29
|
+
url: '/account',
|
|
30
|
+
},
|
|
31
|
+
context: { credsPayload },
|
|
32
|
+
inspect,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const funcApiConfig = {
|
|
37
|
+
argsWarden,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
gorgiasAccountGet,
|
|
42
|
+
funcApiConfig,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
curl -X POST "http://localhost:8000/gorgiasAccountGet" \
|
|
47
|
+
-H "Content-Type: application/json" \
|
|
48
|
+
-d '{
|
|
49
|
+
"credsPayload": { "credsPath": "gorgias" }
|
|
50
|
+
}'
|
|
51
|
+
*/
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// https://developers.gorgias.com/reference/get-customer
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, actionSingleOrMultiple } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { gorgiasGetSingle } = require('../gorgias/gorgiasGetSingle');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['customerId'],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const gorgiasCustomerGetSingle = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
customerId,
|
|
15
|
+
options = {},
|
|
16
|
+
) => {
|
|
17
|
+
return gorgiasGetSingle(
|
|
18
|
+
credsPayload,
|
|
19
|
+
'/customers',
|
|
20
|
+
customerId,
|
|
21
|
+
options,
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const gorgiasCustomerGet = async (
|
|
26
|
+
credsPayload,
|
|
27
|
+
customerId,
|
|
28
|
+
{
|
|
29
|
+
queueRunOptions,
|
|
30
|
+
...options
|
|
31
|
+
} = {},
|
|
32
|
+
) => {
|
|
33
|
+
|
|
34
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
35
|
+
credsPayload,
|
|
36
|
+
customerId,
|
|
37
|
+
});
|
|
38
|
+
if (rejectResponse) {
|
|
39
|
+
return rejectResponse;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return actionSingleOrMultiple(
|
|
43
|
+
customerId,
|
|
44
|
+
gorgiasCustomerGetSingle,
|
|
45
|
+
(customerIdItem) => ({
|
|
46
|
+
args: [credsPayload, customerIdItem, options],
|
|
47
|
+
}),
|
|
48
|
+
{
|
|
49
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const funcApiConfig = {
|
|
55
|
+
argsWarden,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
gorgiasCustomerGet,
|
|
60
|
+
funcApiConfig,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
curl -X POST "http://localhost:8000/gorgiasCustomerGet" \
|
|
65
|
+
-H "Content-Type: application/json" \
|
|
66
|
+
-d '{
|
|
67
|
+
"credsPayload": { "credsPath": "gorgias" },
|
|
68
|
+
"customerId": "123456789"
|
|
69
|
+
}'
|
|
70
|
+
*/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// https://developers.gorgias.com/reference/list-customers
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { gorgiasGet, gorgiasGetter } = require('../gorgias/gorgiasGet');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const gorgiasCustomersGet = async (
|
|
12
|
+
returnGetter,
|
|
13
|
+
|
|
14
|
+
credsPayload,
|
|
15
|
+
getterOptions = {},
|
|
16
|
+
) => {
|
|
17
|
+
|
|
18
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
19
|
+
credsPayload,
|
|
20
|
+
});
|
|
21
|
+
if (rejectResponse) {
|
|
22
|
+
return rejectResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const getterArgs = [
|
|
26
|
+
credsPayload,
|
|
27
|
+
'/customers',
|
|
28
|
+
getterOptions,
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
return returnGetter
|
|
32
|
+
? gorgiasGetter(...getterArgs)
|
|
33
|
+
: gorgiasGet(...getterArgs);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const funcApiConfig = {
|
|
37
|
+
argsWarden,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
gorgiasCustomersGet: (...args) => gorgiasCustomersGet(false, ...args),
|
|
42
|
+
gorgiasCustomersGetter: (...args) => gorgiasCustomersGet(true, ...args),
|
|
43
|
+
funcApiConfig,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
curl -X POST "http://localhost:8000/gorgiasCustomersGet" \
|
|
48
|
+
-H "Content-Type: application/json" \
|
|
49
|
+
-d '{
|
|
50
|
+
"credsPayload": { "credsPath": "gorgias" },
|
|
51
|
+
"options": {
|
|
52
|
+
"params": { "email": "customer@example.com" },
|
|
53
|
+
"limit": 10
|
|
54
|
+
}
|
|
55
|
+
}'
|
|
56
|
+
*/
|