@foxtware/mineral 0.1.9 → 0.1.11
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 +93 -22
- package/api/shopify/shopifyBulkMutationDo.js +211 -0
- package/api/shopify/shopifyBulkOperationGet.js +86 -0
- package/api/shopify/shopifyBulkOperationRunMutation.js +83 -0
- package/api/shopify/shopifyBulkOperationRunQuery.js +70 -0
- package/api/shopify/shopifyBulkQueryDo.js +127 -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 +77 -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/.creds.yml.sample
CHANGED
|
@@ -25,11 +25,14 @@ yotpo:
|
|
|
25
25
|
linear:
|
|
26
26
|
API_KEY: _______________________________
|
|
27
27
|
|
|
28
|
+
github:
|
|
29
|
+
ACCESS_TOKEN: ghp_______________________
|
|
30
|
+
|
|
28
31
|
slack:
|
|
29
32
|
BOT_TOKEN: xoxb_________________________
|
|
30
33
|
|
|
31
34
|
workable:
|
|
32
|
-
BASE_URL: https://
|
|
35
|
+
BASE_URL: https://__.workable.com/spi/v3
|
|
33
36
|
ACCESS_TOKEN: __________________________
|
|
34
37
|
|
|
35
38
|
loop:
|
|
@@ -37,14 +40,32 @@ loop:
|
|
|
37
40
|
API_KEY: _____________________________
|
|
38
41
|
|
|
39
42
|
upstash:
|
|
40
|
-
BASE_URL: https://
|
|
41
|
-
TOKEN:
|
|
43
|
+
BASE_URL: https://___________.upstash.io
|
|
44
|
+
TOKEN: _________________________________
|
|
42
45
|
|
|
43
46
|
supabase:
|
|
44
47
|
project:
|
|
45
|
-
BASE_URL: https://
|
|
46
|
-
API_KEY:
|
|
48
|
+
BASE_URL: https://________.supabase.co
|
|
49
|
+
API_KEY: _____________________________
|
|
47
50
|
|
|
48
51
|
stripe:
|
|
49
|
-
API_KEY:
|
|
52
|
+
API_KEY: sk_____________________________
|
|
53
|
+
|
|
54
|
+
starshipit:
|
|
55
|
+
acc:
|
|
56
|
+
API_KEY: _____________________________
|
|
57
|
+
SUB_KEY: _____________________________
|
|
58
|
+
WEBHOOK_SECRET: ______________________
|
|
50
59
|
|
|
60
|
+
bleckmann:
|
|
61
|
+
PRIMARY_KEY: ___________________________
|
|
62
|
+
SECONDARY_KEY: _________________________
|
|
63
|
+
|
|
64
|
+
stylearcade:
|
|
65
|
+
BASE_URL: https://api.stylearcade.com/range-plan/v1/tenants/________
|
|
66
|
+
API_KEY: _______________________________
|
|
67
|
+
|
|
68
|
+
threeclicks:
|
|
69
|
+
API_KEY: _______________________________
|
|
70
|
+
API_SECRET: ____________________________
|
|
71
|
+
API_DOMAIN: g40-server.instance.3clickscloud.com
|
package/AGENTS.md
CHANGED
|
@@ -10,4 +10,9 @@ Notes for AI assistants working in this directory. **Read this file at the start
|
|
|
10
10
|
- Use snake_case for package.json commands, with colon if appropriate.
|
|
11
11
|
- Use newlines and trailing commas where appropriate to minimise future diffs, e.g. in function args.
|
|
12
12
|
- If you make a new .env or .creds.yml variable, update the correlating .sample file.
|
|
13
|
-
- In Shopify, don't normalise and take gids as inputs if you can just take the id - the non-gid number - instead.
|
|
13
|
+
- In Shopify, don't normalise and take gids as inputs if you can just take the id - the non-gid number - instead.
|
|
14
|
+
- Use trailing commas wherever possible, for future git diff readability.
|
|
15
|
+
|
|
16
|
+
## API clients
|
|
17
|
+
- Base URLs for platform clients should live in `{platform}.constants.js`, not creds, if they are static for all users of the API.
|
|
18
|
+
- Don't explicitly set `Content-Type: application/json` on the client — `customFetch` already adds it when there is a request body.
|
package/README.md
CHANGED
|
@@ -56,4 +56,4 @@ For cloud deploy, workspaces use `hosting/.hosting.yml` and `npm run host` (same
|
|
|
56
56
|
## What the thang do
|
|
57
57
|
- Server makes functions available from the api/ route, where an export matches the filename. Run `npm run serve`, and they're all curlable.
|
|
58
58
|
- .creds.yml is copied into .env when deploying, so creds can be accessed while hosted. Locally, it reads from the file directly.
|
|
59
|
-
- Cloud deploy reads `hosting/.hosting.yml` for per-function config — `before_wrappers` / `after_wrappers` like `requireHostedApiKey`, `max_instances`, schedules — and deploys each function to Google Cloud.
|
|
59
|
+
- Cloud deploy reads `hosting/.hosting.yml` for per-function config — `before_wrappers` / `after_wrappers` like `requireHostedApiKey`, `max_instances`, schedules — and deploys each function to Google Cloud.
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { BASE_URL } = require('../bleckmann/bleckmann.constants');
|
|
2
|
+
const { resolveCreds, useBaseUrl } = require('../pipelineSteps');
|
|
3
|
+
const { FetchClient } = require('../utils');
|
|
4
|
+
|
|
5
|
+
const useAuthHeaders = async (state) => {
|
|
6
|
+
const { requestPayload, context } = state;
|
|
7
|
+
const { creds } = context;
|
|
8
|
+
const { PRIMARY_KEY } = creds;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
requestPayload: {
|
|
12
|
+
...requestPayload,
|
|
13
|
+
headers: {
|
|
14
|
+
'x-api-key': PRIMARY_KEY,
|
|
15
|
+
...requestPayload.headers,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const bleckmannClient = new FetchClient({
|
|
22
|
+
pipeline: [
|
|
23
|
+
resolveCreds,
|
|
24
|
+
useAuthHeaders,
|
|
25
|
+
useBaseUrl(BASE_URL),
|
|
26
|
+
'fetch',
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
bleckmannClient,
|
|
32
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { credsValidator } = require('../validators');
|
|
2
|
+
const { ArgsWarden } = require('../utils');
|
|
3
|
+
const { bleckmannClient } = require('../bleckmann/bleckmann.utils');
|
|
4
|
+
|
|
5
|
+
const argsWarden = new ArgsWarden([
|
|
6
|
+
['credsPayload', credsValidator],
|
|
7
|
+
['asnId'],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const bleckmannAsnGet = async (
|
|
11
|
+
credsPayload,
|
|
12
|
+
asnId,
|
|
13
|
+
options = {},
|
|
14
|
+
) => {
|
|
15
|
+
|
|
16
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
17
|
+
credsPayload,
|
|
18
|
+
asnId,
|
|
19
|
+
});
|
|
20
|
+
if (rejectResponse) {
|
|
21
|
+
return rejectResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const response = await bleckmannClient.fetch({
|
|
25
|
+
requestPayload: {
|
|
26
|
+
url: `/warehousing/asns/${ asnId }`,
|
|
27
|
+
},
|
|
28
|
+
context: {
|
|
29
|
+
credsPayload,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return response;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const funcApiConfig = {
|
|
37
|
+
argsWarden,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
bleckmannAsnGet,
|
|
42
|
+
funcApiConfig,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
curl -X POST "http://localhost:8000/bleckmannAsnGet" \
|
|
47
|
+
-H "Content-Type: application/json" \
|
|
48
|
+
-d '{
|
|
49
|
+
"credsPayload": { "credsPath": "bleckmann" },
|
|
50
|
+
"asnId": "UK-AG002594"
|
|
51
|
+
}'
|
|
52
|
+
*/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// https://app.swaggerhub.com/apis-docs/Bleckmann/warehousing/1.5.2#/ASN/getAsns
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden } = require('../utils');
|
|
5
|
+
const { MAX_PER_PAGE } = require('../bleckmann/bleckmann.constants');
|
|
6
|
+
const { bleckmannClient } = require('../bleckmann/bleckmann.utils');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const bleckmannAsnsGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
{
|
|
15
|
+
createdFrom,
|
|
16
|
+
createdTo,
|
|
17
|
+
receivedFrom,
|
|
18
|
+
receivedTo,
|
|
19
|
+
status,
|
|
20
|
+
perPage = MAX_PER_PAGE,
|
|
21
|
+
} = {},
|
|
22
|
+
) => {
|
|
23
|
+
|
|
24
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({ credsPayload });
|
|
25
|
+
if (rejectResponse) {
|
|
26
|
+
return rejectResponse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const response = await bleckmannClient.fetch({
|
|
30
|
+
requestPayload: {
|
|
31
|
+
url: '/warehousing/asns',
|
|
32
|
+
params: {
|
|
33
|
+
limit: perPage,
|
|
34
|
+
...(createdFrom && { createdFrom }),
|
|
35
|
+
...(createdTo && { createdTo }),
|
|
36
|
+
...(receivedFrom && { receivedFrom }),
|
|
37
|
+
...(receivedTo && { receivedTo }),
|
|
38
|
+
...(status && { status }),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
context: {
|
|
42
|
+
credsPayload,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return response;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const funcApiConfig = {
|
|
50
|
+
argsWarden,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
bleckmannAsnsGet,
|
|
55
|
+
funcApiConfig,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
curl -X POST "http://localhost:8000/bleckmannAsnsGet" \
|
|
60
|
+
-H "Content-Type: application/json" \
|
|
61
|
+
-d '{
|
|
62
|
+
"credsPayload": { "credsPath": "bleckmann" },
|
|
63
|
+
"options": { "perPage": 20 }
|
|
64
|
+
}'
|
|
65
|
+
*/
|
package/api/constants.js
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const {
|
|
2
|
+
BASE_URL,
|
|
3
|
+
DEFAULT_API_VERSION,
|
|
4
|
+
DEFAULT_USER_AGENT,
|
|
5
|
+
} = require('../github/github.constants');
|
|
6
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
7
|
+
const {
|
|
8
|
+
FetchClient,
|
|
9
|
+
appendUrlToBase,
|
|
10
|
+
fetchClientCommonSteps,
|
|
11
|
+
} = require('../utils');
|
|
12
|
+
|
|
13
|
+
const useGithubUrl = async (state) => {
|
|
14
|
+
const { requestPayload, context } = state;
|
|
15
|
+
const { creds } = context;
|
|
16
|
+
const baseUrl = creds?.BASE_URL ?? BASE_URL;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
requestPayload: {
|
|
20
|
+
...requestPayload,
|
|
21
|
+
url: appendUrlToBase(baseUrl, requestPayload.url),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const useAuthHeaders = async (state) => {
|
|
27
|
+
const { requestPayload, context } = state;
|
|
28
|
+
const { creds } = context;
|
|
29
|
+
const {
|
|
30
|
+
ACCESS_TOKEN,
|
|
31
|
+
GITHUB_TOKEN,
|
|
32
|
+
API_VERSION,
|
|
33
|
+
USER_AGENT,
|
|
34
|
+
} = creds ?? {};
|
|
35
|
+
const token = ACCESS_TOKEN ?? GITHUB_TOKEN;
|
|
36
|
+
const apiVersion = API_VERSION ?? context.apiVersion ?? DEFAULT_API_VERSION;
|
|
37
|
+
const userAgent = USER_AGENT ?? DEFAULT_USER_AGENT;
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
requestPayload: {
|
|
41
|
+
...requestPayload,
|
|
42
|
+
headers: {
|
|
43
|
+
Accept: 'application/vnd.github+json',
|
|
44
|
+
'X-GitHub-Api-Version': apiVersion,
|
|
45
|
+
Authorization: `Bearer ${ token }`,
|
|
46
|
+
'User-Agent': userAgent,
|
|
47
|
+
...requestPayload.headers,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const githubClient = new FetchClient({
|
|
54
|
+
pipeline: [
|
|
55
|
+
resolveCreds,
|
|
56
|
+
useGithubUrl,
|
|
57
|
+
useAuthHeaders,
|
|
58
|
+
'fetch',
|
|
59
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
githubClient,
|
|
65
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, Getter } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { githubClient } = require('../github/github.utils');
|
|
6
|
+
const { MAX_PER_PAGE } = require('../github/github.constants');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['url'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const githubGetPacket = async (
|
|
14
|
+
credsPayload,
|
|
15
|
+
url,
|
|
16
|
+
{
|
|
17
|
+
params,
|
|
18
|
+
perPage = MAX_PER_PAGE,
|
|
19
|
+
} = {},
|
|
20
|
+
) => {
|
|
21
|
+
const {
|
|
22
|
+
page = 1,
|
|
23
|
+
...restParams
|
|
24
|
+
} = params ?? {};
|
|
25
|
+
|
|
26
|
+
return githubClient.fetch({
|
|
27
|
+
requestPayload: {
|
|
28
|
+
url,
|
|
29
|
+
params: {
|
|
30
|
+
per_page: Math.min(perPage, MAX_PER_PAGE),
|
|
31
|
+
page,
|
|
32
|
+
...restParams,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
context: {
|
|
36
|
+
credsPayload,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const githubGetPaginator = async (currentParams, response) => {
|
|
42
|
+
const { args, options } = currentParams;
|
|
43
|
+
|
|
44
|
+
if (!response?.ok) {
|
|
45
|
+
return [true];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const items = Array.isArray(response.data) ? response.data : [];
|
|
49
|
+
const { perPage = MAX_PER_PAGE, params = {} } = options;
|
|
50
|
+
|
|
51
|
+
if (items.length < Math.min(perPage, MAX_PER_PAGE)) {
|
|
52
|
+
return [true];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { page = 1, ...restParams } = params;
|
|
56
|
+
|
|
57
|
+
return [false, {
|
|
58
|
+
args,
|
|
59
|
+
options: {
|
|
60
|
+
...options,
|
|
61
|
+
params: {
|
|
62
|
+
...restParams,
|
|
63
|
+
page: page + 1,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const githubGet = async (
|
|
70
|
+
returnGetter,
|
|
71
|
+
|
|
72
|
+
credsPayload,
|
|
73
|
+
url,
|
|
74
|
+
{
|
|
75
|
+
params,
|
|
76
|
+
perPage = MAX_PER_PAGE,
|
|
77
|
+
...getterOptions
|
|
78
|
+
} = {},
|
|
79
|
+
) => {
|
|
80
|
+
|
|
81
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
82
|
+
credsPayload,
|
|
83
|
+
url,
|
|
84
|
+
});
|
|
85
|
+
if (rejectResponse) {
|
|
86
|
+
return rejectResponse;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const getter = new Getter(
|
|
90
|
+
{
|
|
91
|
+
args: [credsPayload, url],
|
|
92
|
+
options: {
|
|
93
|
+
params,
|
|
94
|
+
perPage,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
func: githubGetPacket,
|
|
99
|
+
digester: (response) => {
|
|
100
|
+
if (!response?.ok) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Array.isArray(response.data) ? response.data : [];
|
|
105
|
+
},
|
|
106
|
+
paginator: githubGetPaginator,
|
|
107
|
+
...getterOptions,
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (returnGetter) {
|
|
112
|
+
return getter;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const data = await getter.run({ returnAll: true });
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
data,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const funcApiConfig = {
|
|
124
|
+
argsWarden,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
githubGet: (...args) => githubGet(false, ...args),
|
|
129
|
+
githubGetter: (...args) => githubGet(true, ...args),
|
|
130
|
+
funcApiConfig,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
curl -X POST "http://localhost:8000/githubGet" \
|
|
135
|
+
-H "Content-Type: application/json" \
|
|
136
|
+
-d '{
|
|
137
|
+
"credsPayload": { "credsPath": "github" },
|
|
138
|
+
"url": "/user/repos",
|
|
139
|
+
"options": {
|
|
140
|
+
"params": { "sort": "updated" },
|
|
141
|
+
"limit": 10
|
|
142
|
+
}
|
|
143
|
+
}'
|
|
144
|
+
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// https://docs.github.com/en/rest/issues/issues#create-an-issue
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { githubClient } = require('../github/github.utils');
|
|
6
|
+
|
|
7
|
+
const issuePayloadValidator = (issuePayload) => Boolean(issuePayload?.title);
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['owner'],
|
|
12
|
+
['repo'],
|
|
13
|
+
['issuePayload', issuePayloadValidator],
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const githubIssueCreate = async (
|
|
17
|
+
credsPayload,
|
|
18
|
+
owner,
|
|
19
|
+
repo,
|
|
20
|
+
issuePayload,
|
|
21
|
+
{
|
|
22
|
+
apiVersion,
|
|
23
|
+
} = {},
|
|
24
|
+
) => {
|
|
25
|
+
|
|
26
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
27
|
+
credsPayload,
|
|
28
|
+
owner,
|
|
29
|
+
repo,
|
|
30
|
+
issuePayload,
|
|
31
|
+
});
|
|
32
|
+
if (rejectResponse) {
|
|
33
|
+
return rejectResponse;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return githubClient.fetch({
|
|
37
|
+
requestPayload: {
|
|
38
|
+
method: 'post',
|
|
39
|
+
url: `/repos/${ owner }/${ repo }/issues`,
|
|
40
|
+
body: issuePayload,
|
|
41
|
+
},
|
|
42
|
+
context: {
|
|
43
|
+
credsPayload,
|
|
44
|
+
apiVersion,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const funcApiConfig = {
|
|
50
|
+
argsWarden,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
githubIssueCreate,
|
|
55
|
+
funcApiConfig,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
curl -X POST "http://localhost:8000/githubIssueCreate" \
|
|
60
|
+
-H "Content-Type: application/json" \
|
|
61
|
+
-d '{
|
|
62
|
+
"credsPayload": { "credsPath": "github" },
|
|
63
|
+
"owner": "GorgonFreeman",
|
|
64
|
+
"repo": "mineral",
|
|
65
|
+
"issuePayload": {
|
|
66
|
+
"title": "Found a bug",
|
|
67
|
+
"body": "Details here",
|
|
68
|
+
"labels": ["bug"]
|
|
69
|
+
}
|
|
70
|
+
}'
|
|
71
|
+
*/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// https://docs.github.com/en/rest/issues/issues#get-an-issue
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { githubClient } = require('../github/github.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['owner'],
|
|
10
|
+
['repo'],
|
|
11
|
+
['issueNumber'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const githubIssueGet = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
owner,
|
|
17
|
+
repo,
|
|
18
|
+
issueNumber,
|
|
19
|
+
{
|
|
20
|
+
params,
|
|
21
|
+
apiVersion,
|
|
22
|
+
} = {},
|
|
23
|
+
) => {
|
|
24
|
+
|
|
25
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
27
|
+
owner,
|
|
28
|
+
repo,
|
|
29
|
+
issueNumber,
|
|
30
|
+
});
|
|
31
|
+
if (rejectResponse) {
|
|
32
|
+
return rejectResponse;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return githubClient.fetch({
|
|
36
|
+
requestPayload: {
|
|
37
|
+
url: `/repos/${ owner }/${ repo }/issues/${ issueNumber }`,
|
|
38
|
+
params,
|
|
39
|
+
},
|
|
40
|
+
context: {
|
|
41
|
+
credsPayload,
|
|
42
|
+
apiVersion,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const funcApiConfig = {
|
|
48
|
+
argsWarden,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
githubIssueGet,
|
|
53
|
+
funcApiConfig,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
curl -X POST "http://localhost:8000/githubIssueGet" \
|
|
58
|
+
-H "Content-Type: application/json" \
|
|
59
|
+
-d '{
|
|
60
|
+
"credsPayload": { "credsPath": "github" },
|
|
61
|
+
"owner": "GorgonFreeman",
|
|
62
|
+
"repo": "mineral",
|
|
63
|
+
"issueNumber": 1
|
|
64
|
+
}'
|
|
65
|
+
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// https://docs.github.com/en/rest/issues/issues#update-an-issue
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { githubClient } = require('../github/github.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['owner'],
|
|
10
|
+
['repo'],
|
|
11
|
+
['issueNumber'],
|
|
12
|
+
['updatePayload', Boolean],
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const githubIssueUpdate = async (
|
|
16
|
+
credsPayload,
|
|
17
|
+
owner,
|
|
18
|
+
repo,
|
|
19
|
+
issueNumber,
|
|
20
|
+
updatePayload,
|
|
21
|
+
{
|
|
22
|
+
apiVersion,
|
|
23
|
+
} = {},
|
|
24
|
+
) => {
|
|
25
|
+
|
|
26
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
27
|
+
credsPayload,
|
|
28
|
+
owner,
|
|
29
|
+
repo,
|
|
30
|
+
issueNumber,
|
|
31
|
+
updatePayload,
|
|
32
|
+
});
|
|
33
|
+
if (rejectResponse) {
|
|
34
|
+
return rejectResponse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return githubClient.fetch({
|
|
38
|
+
requestPayload: {
|
|
39
|
+
method: 'patch',
|
|
40
|
+
url: `/repos/${ owner }/${ repo }/issues/${ issueNumber }`,
|
|
41
|
+
body: updatePayload,
|
|
42
|
+
},
|
|
43
|
+
context: {
|
|
44
|
+
credsPayload,
|
|
45
|
+
apiVersion,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const funcApiConfig = {
|
|
51
|
+
argsWarden,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
githubIssueUpdate,
|
|
56
|
+
funcApiConfig,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
curl -X POST "http://localhost:8000/githubIssueUpdate" \
|
|
61
|
+
-H "Content-Type: application/json" \
|
|
62
|
+
-d '{
|
|
63
|
+
"credsPayload": { "credsPath": "github" },
|
|
64
|
+
"owner": "GorgonFreeman",
|
|
65
|
+
"repo": "mineral",
|
|
66
|
+
"issueNumber": 1,
|
|
67
|
+
"updatePayload": {
|
|
68
|
+
"state": "closed"
|
|
69
|
+
}
|
|
70
|
+
}'
|
|
71
|
+
*/
|