@foxtware/mineral 0.1.9 → 0.1.10
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 +27 -6
- package/AGENTS.md +6 -1
- package/README.md +1 -1
- package/api/bleckmann/.gitkeep +0 -0
- package/api/bleckmann/bleckmann.constants.js +8 -0
- package/api/bleckmann/bleckmann.utils.js +32 -0
- package/api/bleckmann/bleckmannAsnGet.js +52 -0
- package/api/bleckmann/bleckmannAsnsGet.js +65 -0
- package/api/constants.js +2 -1
- package/api/github/github.constants.js +11 -0
- package/api/github/github.utils.js +65 -0
- package/api/github/githubGet.js +144 -0
- package/api/github/githubIssueCreate.js +71 -0
- package/api/github/githubIssueGet.js +65 -0
- package/api/github/githubIssueUpdate.js +71 -0
- package/api/github/githubIssuesGet.js +74 -0
- package/api/github/githubPullRequestCreate.js +74 -0
- package/api/github/githubPullRequestGet.js +65 -0
- package/api/github/githubPullRequestMerge.js +77 -0
- package/api/github/githubPullRequestUpdate.js +72 -0
- package/api/github/githubPullRequestsGet.js +74 -0
- package/api/github/githubRepoCreate.js +80 -0
- package/api/github/githubRepoDelete.js +60 -0
- package/api/github/githubRepoGet.js +61 -0
- package/api/github/githubRepoUpdate.js +68 -0
- package/api/github/githubReposGet.js +69 -0
- package/api/github/githubUserGet.js +64 -0
- package/api/linear/linear.utils.js +9 -14
- package/api/linear/linearIssuesGet.js +9 -9
- package/api/logiwa/logiwa.utils.js +27 -25
- package/api/logiwa/logiwaInventoriesGet.js +5 -3
- package/api/logiwa/logiwaOrderGet.js +4 -2
- package/api/logiwa/logiwaOrdersGet.js +5 -3
- package/api/logiwa/logiwaProductGet.js +4 -2
- package/api/logiwa/logiwaProductsGet.js +5 -3
- package/api/logiwa/logiwaReportGetAvailableToPromise.js +5 -3
- package/api/logiwa/logiwaReportGetInventoryCalculation.js +5 -3
- package/api/logiwa/logiwaReportGetInventorySnapshot.js +5 -3
- package/api/logiwa/logiwaReportGetTotalInventory.js +5 -3
- package/api/logiwa/logiwaWebhookStatusGet.js +4 -2
- package/api/logiwa/logiwaWebhookSubscribe.js +8 -6
- package/api/logiwa/logiwaWebhookUnsubscribe.js +4 -2
- package/api/logiwa/logiwaWebhooksGet.js +4 -2
- package/api/loop/loop.utils.js +9 -15
- package/api/loop/loopGet.js +20 -24
- package/api/loop/loopReturnGet.js +6 -6
- package/api/peoplevox/peoplevox.constants.js +1 -1
- package/api/peoplevox/peoplevox.sessions.js +0 -33
- package/api/peoplevox/peoplevox.utils.js +63 -19
- package/api/peoplevox/peoplevoxGetSingle.js +7 -5
- package/api/peoplevox/peoplevoxOrderEdit.js +7 -5
- package/api/peoplevox/peoplevoxReportGet.js +11 -9
- package/api/pipelineSteps.js +49 -0
- package/api/shopify/shopify.utils.js +18 -24
- package/api/shopify/shopifyBulkMutationDo.js +211 -0
- package/api/shopify/shopifyBulkOperationGet.js +86 -0
- package/api/shopify/shopifyBulkOperationRunMutation.js +83 -0
- package/api/shopify/shopifyCheckoutAndAccountsConfigurationUpdate.js +79 -0
- package/api/shopify/shopifyCollectionGet.js +6 -6
- package/api/shopify/shopifyCustomerGet.js +6 -6
- package/api/shopify/shopifyGet.js +18 -13
- package/api/shopify/shopifyGetSingle.js +9 -9
- package/api/shopify/shopifyMutationDo.js +6 -6
- package/api/shopify/shopifyOrdersGet.js +11 -11
- package/api/shopify/shopifyStagedUploadCreate.js +96 -0
- package/api/shopify/shopifyTagsAddBulk.js +90 -0
- package/api/slack/slack.utils.js +10 -19
- package/api/slack/slackMessagePost.js +11 -11
- package/api/starshipit/starshipit.constants.js +8 -0
- package/api/starshipit/starshipit.utils.js +71 -0
- package/api/starshipit/starshipitAddressCreate.js +77 -0
- package/api/starshipit/starshipitAddressDelete.js +55 -0
- package/api/starshipit/starshipitAddressUpdate.js +69 -0
- package/api/starshipit/starshipitAddressesGet.js +52 -0
- package/api/starshipit/starshipitGet.js +146 -0
- package/api/starshipit/starshipitOrderDelete.js +102 -0
- package/api/starshipit/starshipitOrderGet.js +74 -0
- package/api/starshipit/starshipitOrderUpdate.js +109 -0
- package/api/starshipit/starshipitOrdersListShipped.js +64 -0
- package/api/starshipit/starshipitProductAdd.js +100 -0
- package/api/starshipit/starshipitProductsDelete.js +57 -0
- package/api/starshipit/starshipitProductsGet.js +49 -0
- package/api/starshipit/starshipitTrackingGet.js +69 -0
- package/api/stripe/_example.js +7 -7
- package/api/stripe/stripe.utils.js +9 -14
- package/api/stripe/stripeCardTokenCreate.js +11 -11
- package/api/stripe/stripeChargeCapture.js +11 -11
- package/api/stripe/stripeChargeCreate.js +11 -11
- package/api/stripe/stripeChargeGet.js +5 -5
- package/api/stripe/stripeChargesGet.js +6 -6
- package/api/stripe/stripeRefundCreate.js +10 -10
- package/api/stripe/stripeRefundGet.js +5 -5
- package/api/stripe/stripeRefundsGet.js +6 -6
- package/api/stripe/stripeTokenGet.js +5 -5
- package/api/stylearcade/stylearcade.constants.js +5 -0
- package/api/stylearcade/stylearcade.utils.js +40 -0
- package/api/stylearcade/stylearcadeDataGet.js +62 -0
- package/api/stylearcade/stylearcadeGet.js +133 -0
- package/api/stylearcade/stylearcadeMetadataGet.js +47 -0
- package/api/threeclicks/threeclicks.constants.js +8 -0
- package/api/threeclicks/threeclicks.utils.js +119 -0
- package/api/threeclicks/threeclicksCollectionsGet.js +40 -0
- package/api/threeclicks/threeclicksGet.js +138 -0
- package/api/threeclicks/threeclicksKeycodeCreate.js +55 -0
- package/api/threeclicks/threeclicksKeycodeGet.js +47 -0
- package/api/threeclicks/threeclicksPurchaseOrderCreate.js +34 -0
- package/api/threeclicks/threeclicksPurchaseOrderCreateBulk.js +34 -0
- package/api/threeclicks/threeclicksPurchaseOrderGet.js +33 -0
- package/api/threeclicks/threeclicksPurchaseOrderQuantitiesGet.js +33 -0
- package/api/threeclicks/threeclicksPurchaseOrderQuantityCreate.js +34 -0
- package/api/threeclicks/threeclicksPurchaseOrderQuantityCreateBulk.js +34 -0
- package/api/threeclicks/threeclicksPurchaseOrderQuantityUpdate.js +46 -0
- package/api/threeclicks/threeclicksPurchaseOrderQuantityUpdateBulk.js +46 -0
- package/api/threeclicks/threeclicksPurchaseOrderUpdate.js +35 -0
- package/api/threeclicks/threeclicksPurchaseOrdersGet.js +30 -0
- package/api/threeclicks/threeclicksShipmentCreate.js +34 -0
- package/api/threeclicks/threeclicksShipmentGet.js +33 -0
- package/api/threeclicks/threeclicksShipmentOrderAdd.js +38 -0
- package/api/threeclicks/threeclicksShipmentOrderQuantityCreate.js +35 -0
- package/api/threeclicks/threeclicksShipmentQuantityUpdate.js +35 -0
- package/api/threeclicks/threeclicksShipmentStatusUpdate.js +45 -0
- package/api/threeclicks/threeclicksShipmentsGet.js +52 -0
- package/api/threeclicks/threeclicksSignatureCalculate.js +73 -0
- package/api/threeclicks/threeclicksStyleCodesGet.js +46 -0
- package/api/threeclicks/threeclicksStyleColourCreate.js +47 -0
- package/api/threeclicks/threeclicksStyleColourDelete.js +34 -0
- package/api/threeclicks/threeclicksStyleCreate.js +44 -0
- package/api/threeclicks/threeclicksStyleDelete.js +33 -0
- package/api/threeclicks/threeclicksStyleGet.js +43 -0
- package/api/threeclicks/threeclicksStylePriceUpdate.js +70 -0
- package/api/threeclicks/threeclicksStyleUpdate.js +47 -0
- package/api/threeclicks/threeclicksStylesGet.js +45 -0
- package/api/utils.js +85 -117
- package/api/validators.js +1 -1
- package/api/workable/workable.utils.js +8 -13
- package/api/workable/workableGet.js +16 -11
- package/api/workable/workableJobCandidateCreate.js +10 -10
- package/api/workable/workableJobGet.js +5 -5
- package/api/workable/workableJobMembersGet.js +5 -5
- package/api/workable/workableJobStagesGet.js +5 -5
- package/api/yotpo/yotpo.utils.js +17 -22
- package/api/yotpo/yotpoCampaignsGet.js +6 -6
- package/api/yotpo/yotpoCustomerActionRecord.js +7 -7
- package/api/yotpo/yotpoCustomerAnniversaryGet.js +7 -7
- package/api/yotpo/yotpoCustomerAnniversarySet.js +7 -7
- package/api/yotpo/yotpoCustomerBirthdaySet.js +7 -7
- package/api/yotpo/yotpoCustomerGet.js +6 -6
- package/api/yotpo/yotpoCustomerPointsAdjust.js +7 -7
- package/api/yotpo/yotpoCustomerUpsert.js +7 -7
- package/api/yotpo/yotpoCustomersRecentGet.js +6 -6
- package/api/yotpo/yotpoRedemptionCreate.js +7 -7
- package/api/yotpo/yotpoRedemptionOptionsGet.js +6 -6
- package/api/yotpo/yotpoVipTiersGet.js +5 -5
- package/api/youtube/youtube.constants.js +5 -0
- package/api/youtube/youtube.utils.js +77 -0
- package/api/youtube/youtubeChannelVideosGet.js +25 -70
- package/package.json +1 -1
package/api/utils.js
CHANGED
|
@@ -108,6 +108,30 @@ const getResponseParser = (contentType) => {
|
|
|
108
108
|
return (res) => res.text(); // safe default
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
const objectToFormData = (object) => {
|
|
112
|
+
const formData = new FormData();
|
|
113
|
+
for (const [key, value] of Object.entries(object)) {
|
|
114
|
+
formData.append(key, value);
|
|
115
|
+
}
|
|
116
|
+
return formData;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const bodyPassesThrough = (body) => {
|
|
120
|
+
if (body == null) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (typeof body === 'string') {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (body instanceof FormData) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return typeof body.getHeaders === 'function';
|
|
133
|
+
};
|
|
134
|
+
|
|
111
135
|
const customFetch = async (url, {
|
|
112
136
|
method = 'get',
|
|
113
137
|
headers = {},
|
|
@@ -123,7 +147,11 @@ const customFetch = async (url, {
|
|
|
123
147
|
headers['x-request-id'] = String(Date.now());
|
|
124
148
|
}
|
|
125
149
|
|
|
126
|
-
if (body
|
|
150
|
+
if (body?.getHeaders) {
|
|
151
|
+
Object.assign(headers, body.getHeaders());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (body && !headers['Content-Type'] && !bodyPassesThrough(body)) {
|
|
127
155
|
headers['Content-Type'] = 'application/json';
|
|
128
156
|
}
|
|
129
157
|
|
|
@@ -142,11 +170,11 @@ const customFetch = async (url, {
|
|
|
142
170
|
const response = await fetch(url, {
|
|
143
171
|
method,
|
|
144
172
|
headers,
|
|
145
|
-
...body
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
...body && {
|
|
174
|
+
body: bodyPassesThrough(body)
|
|
175
|
+
? body
|
|
176
|
+
: JSON.stringify(body),
|
|
177
|
+
},
|
|
150
178
|
});
|
|
151
179
|
|
|
152
180
|
const responseContentType = response.headers.get('content-type');
|
|
@@ -416,132 +444,58 @@ class Chain {
|
|
|
416
444
|
}
|
|
417
445
|
}
|
|
418
446
|
|
|
419
|
-
// TODO: client wrapper enabling auth and retrying with different auth
|
|
420
|
-
|
|
421
447
|
class FetchClient {
|
|
422
448
|
constructor({
|
|
423
|
-
|
|
424
|
-
requestPreparer, // a function that updates requests before sending
|
|
425
|
-
responseInterpreter, // a function that transforms responses to report back
|
|
449
|
+
pipeline = ['fetch'], // an array of functions that transform the request and response, including a string 'fetch' step.
|
|
426
450
|
} = {}) {
|
|
427
|
-
this.
|
|
428
|
-
|
|
429
|
-
this.responseInterpreter = responseInterpreter; // can be a Chain
|
|
430
|
-
this.layers = [];
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
async #fetch({
|
|
434
|
-
url,
|
|
435
|
-
|
|
436
|
-
// customFetch payload
|
|
437
|
-
method,
|
|
438
|
-
headers,
|
|
439
|
-
params,
|
|
440
|
-
body,
|
|
441
|
-
|
|
442
|
-
responseInterpreter,
|
|
443
|
-
|
|
444
|
-
context = {},
|
|
445
|
-
inspect = false,
|
|
446
|
-
} = {}) {
|
|
447
|
-
|
|
448
|
-
let mergedContext = {
|
|
449
|
-
...(this.context ?? {}),
|
|
450
|
-
...(context ?? {}),
|
|
451
|
-
};
|
|
452
|
-
inspect && logDeep({ mergedContext });
|
|
453
|
-
inspect && await askQuestion('?');
|
|
454
|
-
|
|
455
|
-
let requestPayload = {
|
|
456
|
-
url,
|
|
457
|
-
...(method ? { method } : {}),
|
|
458
|
-
...(headers ? { headers } : {}),
|
|
459
|
-
...(params ? { params } : {}),
|
|
460
|
-
...(body ? { body } : {}),
|
|
461
|
-
};
|
|
462
|
-
inspect && logDeep({ requestPayload });
|
|
463
|
-
inspect && await askQuestion('?');
|
|
464
|
-
|
|
465
|
-
if (this.requestPreparer) {
|
|
466
|
-
if (this.requestPreparer.run) {
|
|
467
|
-
({ requestPayload, context: mergedContext } = await this.requestPreparer.run(
|
|
468
|
-
{ requestPayload, context: mergedContext },
|
|
469
|
-
{ inspect },
|
|
470
|
-
));
|
|
471
|
-
} else {
|
|
472
|
-
const result = await this.requestPreparer(requestPayload, mergedContext);
|
|
473
|
-
if (result) {
|
|
474
|
-
requestPayload = result;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
inspect && logDeep({ requestPayload, mergedContext });
|
|
479
|
-
inspect && await askQuestion('?');
|
|
480
|
-
|
|
481
|
-
let response = await customFetch(
|
|
482
|
-
requestPayload.url,
|
|
483
|
-
requestPayload,
|
|
484
|
-
);
|
|
485
|
-
inspect && logDeep({ response });
|
|
486
|
-
inspect && await askQuestion('?');
|
|
487
|
-
|
|
488
|
-
const usedResponseInterpreter = responseInterpreter || this.responseInterpreter;
|
|
489
|
-
if (usedResponseInterpreter) {
|
|
490
|
-
if (usedResponseInterpreter.run) {
|
|
491
|
-
({ response, context: mergedContext } = await usedResponseInterpreter.run(
|
|
492
|
-
{ response, context: mergedContext },
|
|
493
|
-
{ inspect },
|
|
494
|
-
));
|
|
495
|
-
} else {
|
|
496
|
-
response = await usedResponseInterpreter(response, mergedContext);
|
|
497
|
-
}
|
|
451
|
+
if (!this.pipelineHasFetchStep(pipeline)) {
|
|
452
|
+
throw new Error('Pipeline must have a fetch step');
|
|
498
453
|
}
|
|
499
|
-
|
|
500
|
-
inspect && await askQuestion('?');
|
|
501
|
-
|
|
502
|
-
return response;
|
|
454
|
+
this.pipeline = pipeline;
|
|
503
455
|
}
|
|
504
456
|
|
|
505
|
-
|
|
506
|
-
|
|
457
|
+
pipelineHasFetchStep = (pipeline) => {
|
|
458
|
+
return pipeline.find(step => step === 'fetch');
|
|
507
459
|
}
|
|
508
460
|
|
|
509
|
-
async fetch(
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
let layeredFetch = coreFetch;
|
|
513
|
-
for (const layer of [...this.layers].reverse()) {
|
|
514
|
-
const currentNext = layeredFetch; // capture this iteration's `next`
|
|
515
|
-
layeredFetch = (payload) => layer(payload, currentNext);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
return await layeredFetch(fetchPayload);
|
|
519
|
-
}
|
|
461
|
+
async #fetch(state) {
|
|
462
|
+
const { requestPayload } = state;
|
|
520
463
|
|
|
521
|
-
|
|
464
|
+
return {
|
|
465
|
+
response: await customFetch(
|
|
466
|
+
requestPayload.url,
|
|
467
|
+
requestPayload,
|
|
468
|
+
),
|
|
469
|
+
};
|
|
470
|
+
}
|
|
522
471
|
|
|
523
|
-
|
|
472
|
+
async fetch({
|
|
473
|
+
// url, body, etc.
|
|
474
|
+
requestPayload,
|
|
524
475
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
headers: { ...payload.headers, dress: 'blue/white' },
|
|
528
|
-
});
|
|
476
|
+
// additional information to inform behaviour
|
|
477
|
+
context,
|
|
529
478
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
...payload,
|
|
534
|
-
headers: { ...payload.headers, dress: 'black/gold' },
|
|
535
|
-
});
|
|
536
|
-
}
|
|
479
|
+
// options for the fetch itself, as opposed to data it uses
|
|
480
|
+
inspect = false,
|
|
481
|
+
} = {}) {
|
|
537
482
|
|
|
538
|
-
|
|
483
|
+
const { pipeline } = this;
|
|
539
484
|
|
|
540
|
-
|
|
485
|
+
const pipelineChain = new Chain(pipeline.map(step => {
|
|
486
|
+
return step === 'fetch'
|
|
487
|
+
? this.#fetch
|
|
488
|
+
: step;
|
|
489
|
+
}));
|
|
541
490
|
|
|
542
|
-
|
|
491
|
+
// fetch step will add response to this, for subsequent steps
|
|
492
|
+
const state = await pipelineChain.run({
|
|
493
|
+
requestPayload,
|
|
494
|
+
context,
|
|
495
|
+
}, { inspect });
|
|
543
496
|
|
|
544
|
-
|
|
497
|
+
return state.response;
|
|
498
|
+
}
|
|
545
499
|
}
|
|
546
500
|
|
|
547
501
|
const fetchClientCommonSteps = {
|
|
@@ -652,6 +606,17 @@ const ensureArray = (value) => {
|
|
|
652
606
|
return [value];
|
|
653
607
|
};
|
|
654
608
|
|
|
609
|
+
const objectArrayToJsonl = (objects) => {
|
|
610
|
+
return objects.map((object) => JSON.stringify(object)).join('\n');
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
const jsonlToObjectArray = (jsonl) => {
|
|
614
|
+
return jsonl
|
|
615
|
+
.split('\n')
|
|
616
|
+
.filter((line) => line.trim())
|
|
617
|
+
.map((line) => JSON.parse(line));
|
|
618
|
+
};
|
|
619
|
+
|
|
655
620
|
const everyIfArray = (func, value) => {
|
|
656
621
|
if (Array.isArray(value)) {
|
|
657
622
|
if (value.length === 0) {
|
|
@@ -1199,7 +1164,10 @@ module.exports = {
|
|
|
1199
1164
|
Chain,
|
|
1200
1165
|
FetchClient,
|
|
1201
1166
|
fetchClientCommonSteps,
|
|
1167
|
+
objectToFormData,
|
|
1202
1168
|
ensureArray,
|
|
1169
|
+
objectArrayToJsonl,
|
|
1170
|
+
jsonlToObjectArray,
|
|
1203
1171
|
everyIfArray,
|
|
1204
1172
|
simpleSort,
|
|
1205
1173
|
arrayToChunks,
|
|
@@ -1213,4 +1181,4 @@ module.exports = {
|
|
|
1213
1181
|
sentenceCaseString,
|
|
1214
1182
|
ArgsWarden,
|
|
1215
1183
|
gidToId,
|
|
1216
|
-
};
|
|
1184
|
+
};
|
package/api/validators.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
1
2
|
const {
|
|
2
3
|
FetchClient,
|
|
3
|
-
Chain,
|
|
4
4
|
appendUrlToBase,
|
|
5
5
|
fetchClientCommonSteps,
|
|
6
6
|
} = require('../utils');
|
|
7
7
|
|
|
8
8
|
// TODO: Allow creds failure (e.g. missing BASE_URL / ACCESS_TOKEN → INVALID_CREDS before fetch)
|
|
9
|
-
const
|
|
9
|
+
const useAuthHeaders = async (state) => {
|
|
10
10
|
const { requestPayload, context } = state;
|
|
11
11
|
const { creds } = context;
|
|
12
12
|
const {
|
|
@@ -19,7 +19,6 @@ const addUrlAndAuthHeaders = async (state) => {
|
|
|
19
19
|
...requestPayload,
|
|
20
20
|
url: appendUrlToBase(BASE_URL, requestPayload.url),
|
|
21
21
|
headers: {
|
|
22
|
-
'Content-Type': 'application/json',
|
|
23
22
|
Accept: 'application/json',
|
|
24
23
|
Authorization: `Bearer ${ ACCESS_TOKEN }`,
|
|
25
24
|
...requestPayload.headers,
|
|
@@ -28,17 +27,13 @@ const addUrlAndAuthHeaders = async (state) => {
|
|
|
28
27
|
};
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
const workableClientRequestPreparer = new Chain([
|
|
32
|
-
addUrlAndAuthHeaders,
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
const workableClientResponseInterpreter = new Chain([
|
|
36
|
-
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
30
|
const workableClient = new FetchClient({
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
pipeline: [
|
|
32
|
+
resolveCreds,
|
|
33
|
+
useAuthHeaders,
|
|
34
|
+
'fetch',
|
|
35
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
36
|
+
],
|
|
42
37
|
});
|
|
43
38
|
|
|
44
39
|
module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://workable.readme.io/reference/jobs
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden, Getter } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { workableClient } = require('../workable/workable.utils');
|
|
6
6
|
const { MAX_PER_PAGE } = require('../workable/workable.constants');
|
|
@@ -20,7 +20,7 @@ const digResults = (data, resultsKey) => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const workableGetPacket = async (
|
|
23
|
-
|
|
23
|
+
credsPayload,
|
|
24
24
|
url,
|
|
25
25
|
{
|
|
26
26
|
params,
|
|
@@ -28,13 +28,15 @@ const workableGetPacket = async (
|
|
|
28
28
|
} = {},
|
|
29
29
|
) => {
|
|
30
30
|
return workableClient.fetch({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
requestPayload: {
|
|
32
|
+
url,
|
|
33
|
+
params: {
|
|
34
|
+
limit: Math.min(perPage, MAX_PER_PAGE),
|
|
35
|
+
...params,
|
|
36
|
+
},
|
|
35
37
|
},
|
|
36
38
|
context: {
|
|
37
|
-
|
|
39
|
+
credsPayload,
|
|
38
40
|
},
|
|
39
41
|
});
|
|
40
42
|
};
|
|
@@ -83,11 +85,9 @@ const workableGet = async (
|
|
|
83
85
|
return rejectResponse;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
const creds = await credsFromPayload(credsPayload);
|
|
87
|
-
|
|
88
88
|
const getter = new Getter(
|
|
89
89
|
{
|
|
90
|
-
args: [
|
|
90
|
+
args: [credsPayload, url],
|
|
91
91
|
options: {
|
|
92
92
|
params,
|
|
93
93
|
perPage,
|
|
@@ -111,7 +111,12 @@ const workableGet = async (
|
|
|
111
111
|
return getter;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
const data = await getter.run({ returnAll: true });
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
data,
|
|
119
|
+
};
|
|
115
120
|
};
|
|
116
121
|
|
|
117
122
|
const funcApiConfig = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://workable.readme.io/reference/job-candidates-create
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { workableClient } = require('../workable/workable.utils');
|
|
6
6
|
|
|
@@ -33,18 +33,18 @@ const workableJobCandidateCreate = async (
|
|
|
33
33
|
return rejectResponse;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const creds = await credsFromPayload(credsPayload);
|
|
37
|
-
|
|
38
36
|
return workableClient.fetch({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
requestPayload: {
|
|
38
|
+
url: `/jobs/${ shortcode }/candidates`,
|
|
39
|
+
method: 'post',
|
|
40
|
+
body: {
|
|
41
|
+
sourced,
|
|
42
|
+
...stage !== undefined && { stage },
|
|
43
|
+
candidate,
|
|
44
|
+
},
|
|
45
45
|
},
|
|
46
46
|
context: {
|
|
47
|
-
|
|
47
|
+
credsPayload,
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://workable.readme.io/reference/jobsshortcode
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { workableClient } = require('../workable/workable.utils');
|
|
6
6
|
|
|
@@ -23,12 +23,12 @@ const workableJobGet = async (
|
|
|
23
23
|
return rejectResponse;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const creds = await credsFromPayload(credsPayload);
|
|
27
|
-
|
|
28
26
|
return workableClient.fetch({
|
|
29
|
-
|
|
27
|
+
requestPayload: {
|
|
28
|
+
url: `/jobs/${ shortcode }`,
|
|
29
|
+
},
|
|
30
30
|
context: {
|
|
31
|
-
|
|
31
|
+
credsPayload,
|
|
32
32
|
},
|
|
33
33
|
});
|
|
34
34
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://workable.readme.io/reference/job-members
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { workableClient } = require('../workable/workable.utils');
|
|
6
6
|
|
|
@@ -23,12 +23,12 @@ const workableJobMembersGet = async (
|
|
|
23
23
|
return rejectResponse;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const creds = await credsFromPayload(credsPayload);
|
|
27
|
-
|
|
28
26
|
return workableClient.fetch({
|
|
29
|
-
|
|
27
|
+
requestPayload: {
|
|
28
|
+
url: `/jobs/${ shortcode }/members`,
|
|
29
|
+
},
|
|
30
30
|
context: {
|
|
31
|
-
|
|
31
|
+
credsPayload,
|
|
32
32
|
},
|
|
33
33
|
});
|
|
34
34
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://workable.readme.io/reference/job-stages
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { workableClient } = require('../workable/workable.utils');
|
|
6
6
|
|
|
@@ -23,12 +23,12 @@ const workableJobStagesGet = async (
|
|
|
23
23
|
return rejectResponse;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const creds = await credsFromPayload(credsPayload);
|
|
27
|
-
|
|
28
26
|
return workableClient.fetch({
|
|
29
|
-
|
|
27
|
+
requestPayload: {
|
|
28
|
+
url: `/jobs/${ shortcode }/stages`,
|
|
29
|
+
},
|
|
30
30
|
context: {
|
|
31
|
-
|
|
31
|
+
credsPayload,
|
|
32
32
|
},
|
|
33
33
|
});
|
|
34
34
|
};
|
package/api/yotpo/yotpo.utils.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const {
|
|
2
|
-
BASE_URL,
|
|
3
|
-
DEFAULT_API_VERSION,
|
|
1
|
+
const {
|
|
2
|
+
BASE_URL,
|
|
3
|
+
DEFAULT_API_VERSION,
|
|
4
4
|
} = require('../yotpo/yotpo.constants');
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
appendUrlToBase,
|
|
9
|
-
fetchClientCommonSteps,
|
|
5
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
6
|
+
const {
|
|
7
|
+
FetchClient,
|
|
8
|
+
appendUrlToBase,
|
|
9
|
+
fetchClientCommonSteps,
|
|
10
10
|
} = require('../utils');
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const useUrlAndAuthHeaders = async (state) => {
|
|
13
13
|
const { requestPayload, context } = state;
|
|
14
|
-
const {
|
|
14
|
+
const { apiVersion = DEFAULT_API_VERSION, creds } = context;
|
|
15
15
|
const { API_KEY, GUID } = creds;
|
|
16
16
|
|
|
17
17
|
return {
|
|
@@ -19,7 +19,6 @@ const addUrlAndAuthHeaders = async (state) => {
|
|
|
19
19
|
...requestPayload,
|
|
20
20
|
url: appendUrlToBase(`${ BASE_URL }/${ apiVersion }`, requestPayload.url),
|
|
21
21
|
headers: {
|
|
22
|
-
'Content-Type': 'application/json',
|
|
23
22
|
'x-api-key': API_KEY,
|
|
24
23
|
'x-guid': GUID,
|
|
25
24
|
...requestPayload.headers,
|
|
@@ -28,18 +27,14 @@ const addUrlAndAuthHeaders = async (state) => {
|
|
|
28
27
|
};
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
const yotpoClientRequestPreparer = new Chain([
|
|
32
|
-
addUrlAndAuthHeaders,
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
const yotpoClientResponseInterpreter = new Chain([
|
|
36
|
-
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
37
|
-
fetchClientCommonSteps.digToPath,
|
|
38
|
-
]);
|
|
39
|
-
|
|
40
30
|
const yotpoClient = new FetchClient({
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
pipeline: [
|
|
32
|
+
resolveCreds,
|
|
33
|
+
useUrlAndAuthHeaders,
|
|
34
|
+
'fetch',
|
|
35
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
36
|
+
fetchClientCommonSteps.digToPath,
|
|
37
|
+
],
|
|
43
38
|
});
|
|
44
39
|
|
|
45
40
|
module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://loyaltyapi.yotpo.com/reference/get-active-campaigns
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
6
|
|
|
@@ -22,8 +22,6 @@ const yotpoCampaignsGet = async (
|
|
|
22
22
|
return rejectResponse;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const creds = await credsFromPayload(credsPayload);
|
|
26
|
-
|
|
27
25
|
const {
|
|
28
26
|
customerId,
|
|
29
27
|
customerEmail,
|
|
@@ -36,10 +34,12 @@ const yotpoCampaignsGet = async (
|
|
|
36
34
|
};
|
|
37
35
|
|
|
38
36
|
const response = await yotpoClient.fetch({
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
requestPayload: {
|
|
38
|
+
url: '/campaigns',
|
|
39
|
+
params,
|
|
40
|
+
},
|
|
41
41
|
context: {
|
|
42
|
-
|
|
42
|
+
credsPayload,
|
|
43
43
|
apiVersion,
|
|
44
44
|
},
|
|
45
45
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://loyaltyapi.yotpo.com/reference/record-a-customer-action
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { objHasAny, ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
6
|
|
|
@@ -43,8 +43,6 @@ const yotpoCustomerActionRecord = async (
|
|
|
43
43
|
return rejectResponse;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const creds = await credsFromPayload(credsPayload);
|
|
47
|
-
|
|
48
46
|
const {
|
|
49
47
|
customerId,
|
|
50
48
|
customerEmail,
|
|
@@ -63,11 +61,13 @@ const yotpoCustomerActionRecord = async (
|
|
|
63
61
|
};
|
|
64
62
|
|
|
65
63
|
const response = await yotpoClient.fetch({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
requestPayload: {
|
|
65
|
+
url: '/actions',
|
|
66
|
+
method: 'post',
|
|
67
|
+
body,
|
|
68
|
+
},
|
|
69
69
|
context: {
|
|
70
|
-
|
|
70
|
+
credsPayload,
|
|
71
71
|
apiVersion,
|
|
72
72
|
},
|
|
73
73
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://loyaltyapi.yotpo.com/reference/get-customer-anniversary
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
6
|
|
|
@@ -25,15 +25,15 @@ const yotpoCustomerAnniversaryGet = async (
|
|
|
25
25
|
return rejectResponse;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const creds = await credsFromPayload(credsPayload);
|
|
29
|
-
|
|
30
28
|
const response = await yotpoClient.fetch({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
requestPayload: {
|
|
30
|
+
url: '/customer_anniversary',
|
|
31
|
+
params: {
|
|
32
|
+
customer_email: customerEmail,
|
|
33
|
+
},
|
|
34
34
|
},
|
|
35
35
|
context: {
|
|
36
|
-
|
|
36
|
+
credsPayload,
|
|
37
37
|
apiVersion,
|
|
38
38
|
},
|
|
39
39
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// https://loyaltyapi.yotpo.com/reference/createupdate-customer-anniversary
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
4
|
const { credsValidator } = require('../validators');
|
|
5
5
|
const { yotpoClient } = require('../yotpo/yotpo.utils');
|
|
6
6
|
|
|
@@ -35,8 +35,6 @@ const yotpoCustomerAnniversarySet = async (
|
|
|
35
35
|
return rejectResponse;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const creds = await credsFromPayload(credsPayload);
|
|
39
|
-
|
|
40
38
|
const body = {
|
|
41
39
|
customer_email: customerEmail,
|
|
42
40
|
day: Number(day),
|
|
@@ -45,11 +43,13 @@ const yotpoCustomerAnniversarySet = async (
|
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
const response = await yotpoClient.fetch({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
requestPayload: {
|
|
47
|
+
url: '/customer_anniversary',
|
|
48
|
+
method: 'post',
|
|
49
|
+
body,
|
|
50
|
+
},
|
|
51
51
|
context: {
|
|
52
|
-
|
|
52
|
+
credsPayload,
|
|
53
53
|
apiVersion,
|
|
54
54
|
},
|
|
55
55
|
});
|