@tool-bridge/server 0.16.0 → 0.19.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/dist/{airtable-S3T4TAN7.js → airtable-23JBIM6X.js} +106 -114
- package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-ADWBTCIH.js} +25 -16
- package/dist/{amap-LGVGNPML.js → amap-CYQCYW2Z.js} +114 -123
- package/dist/{anthropic-27RFZO35.js → anthropic-5P62HDNR.js} +34 -56
- package/dist/{apify-6WLYAIAS.js → apify-54RZUAGW.js} +31 -49
- package/dist/{brave_search-K2SVJ66F.js → brave_search-AHJ6FTD5.js} +52 -77
- package/dist/{chunk-VK3V2WTY.js → chunk-B4P6YZFS.js} +4 -6
- package/dist/{chunk-BB6ZLMTU.js → chunk-CLEZ6YQ6.js} +2600 -481
- package/dist/chunk-JXHMDBAY.js +45 -0
- package/dist/chunk-LMLX3DJF.js +50 -0
- package/dist/{chunk-YB2FLNWI.js → chunk-OKRZPQ3R.js} +2558 -1926
- package/dist/chunk-SWBNHIO4.js +977 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-VLOIDU5U.js +283 -0
- package/dist/{circleci-WV3ITU7Q.js → circleci-UM3NSQJ3.js} +36 -55
- package/dist/{clerk-NFQEFKS4.js → clerk-FE5LQ2CZ.js} +60 -80
- package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-KEZABKUT.js} +90 -113
- package/dist/{cohere-5KEW7LWT.js → cohere-4IPJADXP.js} +33 -49
- package/dist/{confluence-SZE63S46.js → confluence-56QEKNQI.js} +79 -115
- package/dist/{convertapi-QPG2JC5K.js → convertapi-3QRM5K5T.js} +13 -16
- package/dist/{currencyapi-UO2APQRY.js → currencyapi-L6G4OND5.js} +30 -53
- package/dist/{deepseek-LJELIMM3.js → deepseek-LGC6HBFG.js} +30 -38
- package/dist/{docker_hub-2MFXSBOF.js → docker_hub-XDMK3BIU.js} +141 -157
- package/dist/{dropbox-GQYNTTVA.js → dropbox-4QARMFZU.js} +134 -141
- package/dist/{dub-KI2LHXST.js → dub-C6JSJKOT.js} +61 -93
- package/dist/{e2b-WO6ISY3C.js → e2b-6A6TVACJ.js} +39 -69
- package/dist/{exa-IZ7B3BPT.js → exa-SIWWW6AA.js} +49 -77
- package/dist/{fal_ai-LTMF36GJ.js → fal_ai-3IJXOKSP.js} +37 -44
- package/dist/{feishu-WM7SLSFD.js → feishu-L4KDA4DC.js} +4 -6
- package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-SDM75H4P.js} +4 -5
- package/dist/{figma-2Z274VQZ.js → figma-6DD436DN.js} +56 -81
- package/dist/{firehydrant-IFI4R65V.js → firehydrant-SYSGYB3R.js} +40 -53
- package/dist/{fixer-BCCZEB3D.js → fixer-FZG7ASTF.js} +31 -43
- package/dist/{fly-755FXYB5.js → fly-HMRCZBUC.js} +50 -66
- package/dist/{front-4FZKKXXK.js → front-FAFSD7I3.js} +43 -66
- package/dist/{geocodio-WYKDJ3DP.js → geocodio-4D3TWENM.js} +37 -63
- package/dist/{ghost-5BNQTCOH.js → ghost-OSO2FOZS.js} +51 -57
- package/dist/{github-ULELF5VX.js → github-OR4I4RHE.js} +48 -41
- package/dist/{gmail-G34WT64J.js → gmail-5AOPJ63E.js} +26 -36
- package/dist/{googlecalendar-BQU255SC.js → googlecalendar-SOJIJUWH.js} +57 -78
- package/dist/{googledocs-HPCNQXYJ.js → googledocs-QSKN5TLN.js} +14 -22
- package/dist/{grafana-VOV24FIC.js → grafana-R3AIZM7M.js} +95 -122
- package/dist/{graphhopper-D5RXW6AP.js → graphhopper-4CR3QOAX.js} +32 -46
- package/dist/index.d.ts +108 -56
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-OBCG6X6J.js} +35 -42
- package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-NHH3DTQW.js} +40 -60
- package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-7POMCBEC.js} +30 -42
- package/dist/{jina_ai-E6UXFV2P.js → jina_ai-YXVKROV4.js} +32 -58
- package/dist/{jira-ZDSXGQ6W.js → jira-LADO3VJU.js} +116 -126
- package/dist/{langsmith-TIFJRREW.js → langsmith-XZ6UAQFU.js} +101 -121
- package/dist/{lemlist-DASEMJMA.js → lemlist-P74GLNE7.js} +57 -68
- package/dist/{linear-KE6UP4SP.js → linear-CXJ7D37A.js} +109 -118
- package/dist/{logsnag-IMNDN4R5.js → logsnag-EVVHWFLK.js} +31 -48
- package/dist/main.js +103 -102
- package/dist/{mattermost-HHHMUXQA.js → mattermost-WG2MRGBD.js} +45 -62
- package/dist/{mem0-D2FGGOIY.js → mem0-HQWUKG6U.js} +72 -98
- package/dist/{memos-4OVIGFPH.js → memos-SQMJIFOE.js} +68 -122
- package/dist/{metabase-33WCX5YD.js → metabase-E27G2DZI.js} +47 -60
- package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-MIL63NIT.js} +35 -40
- package/dist/{mother_duck-M6VWS2VH.js → mother_duck-AIZVCBNR.js} +42 -62
- package/dist/{ngrok-Z2PKQBHH.js → ngrok-XS4DVIQS.js} +42 -58
- package/dist/{notes-SS4RPC4K.js → notes-JEOUSL2Y.js} +3 -5
- package/dist/{notion-FJCNQ6I7.js → notion-U4EZVDW2.js} +83 -97
- package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-AZSQEYEJ.js} +35 -39
- package/dist/{openai-JODZ4GKT.js → openai-HW3SYMTQ.js} +51 -55
- package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-QX74MAEL.js} +61 -79
- package/dist/{openrouter-Q5XXEJZ7.js → openrouter-OXSKYL6N.js} +41 -55
- package/dist/{outline-RT2EHJ2X.js → outline-CCQAPDSW.js} +89 -104
- package/dist/{paddle-OF2V7GAC.js → paddle-6KQPSSCK.js} +34 -49
- package/dist/{perplexity-LNZEWLHG.js → perplexity-2TXO7IQE.js} +33 -50
- package/dist/{pinecone-JSJIXZYN.js → pinecone-YOO7NULI.js} +65 -91
- package/dist/{pipedrive-D4CKVUXR.js → pipedrive-Q6RIFIFP.js} +37 -59
- package/dist/{polar-M7ZYP6UR.js → polar-KUMGCES3.js} +43 -53
- package/dist/{posthog-YV7CZOH4.js → posthog-VXQHBSMB.js} +58 -77
- package/dist/{postmark-KYHLECRG.js → postmark-YLIPF52S.js} +52 -71
- package/dist/{prerender-HCMHBKV2.js → prerender-CRY7UJN5.js} +32 -50
- package/dist/{pubmed-WYVLCCN3.js → pubmed-3Z4T5AM7.js} +28 -60
- package/dist/{railway-TWIRD5KR.js → railway-BP37IGFL.js} +32 -39
- package/dist/{readwise-UZ467IQ7.js → readwise-HTKICF4K.js} +62 -78
- package/dist/{render-MECUC5CC.js → render-WIVTUXJH.js} +48 -64
- package/dist/{replicate-A5MEK3SW.js → replicate-JJYPA43D.js} +41 -58
- package/dist/{resend-BC6EAWJQ.js → resend-TKHZVG7A.js} +27 -37
- package/dist/{rootly-ZM3QDUIS.js → rootly-FRSZLG5U.js} +64 -76
- package/dist/{scrapfly-WAML42QJ.js → scrapfly-M5WXGQWE.js} +45 -51
- package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-PMXNLLBK.js} +25 -33
- package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-HFW4TAOH.js} +29 -47
- package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-KXVH2VZQ.js} +37 -56
- package/dist/{sentry-OKBPSTDM.js → sentry-WWOT2LRX.js} +66 -85
- package/dist/{shodan-PPC6DYU4.js → shodan-FY635H35.js} +42 -53
- package/dist/{shopify-EWGUHBXO.js → shopify-HQLBVSA5.js} +32 -49
- package/dist/{stripe-6RPDPC5W.js → stripe-GJN2GOHB.js} +4 -5
- package/dist/{supabase-SK7DQ42N.js → supabase-BBNZGQU6.js} +69 -88
- package/dist/{tavily-YCG5VQMH.js → tavily-DPENIBOG.js} +37 -62
- package/dist/{telegram-2OES5FYB.js → telegram-L4NONG6H.js} +168 -177
- package/dist/{telnyx-POOSBBR4.js → telnyx-H67MAEZS.js} +30 -50
- package/dist/{todoist-M7YD6YSS.js → todoist-G2BSP4DX.js} +77 -89
- package/dist/{trello-IS6V5W3E.js → trello-7WMVFDG2.js} +108 -122
- package/dist/{turso-RCFHUFVH.js → turso-ZUAESFC2.js} +52 -64
- package/dist/{twilio-OS2RXFGO.js → twilio-EYFYIX3B.js} +48 -55
- package/dist/{umami-PQ2SJ2LN.js → umami-AXAUDUVF.js} +49 -69
- package/dist/{unsplash-C6BPZO4E.js → unsplash-UCQAWPLR.js} +35 -52
- package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-ZPZ4ASU6.js} +28 -40
- package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-4QVKKUD5.js} +11 -12
- package/dist/{v2ex-R4JWTEHN.js → v2ex-VGEFJTYC.js} +36 -61
- package/dist/{vercel-FZVYUOQD.js → vercel-JME4TSCN.js} +124 -150
- package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
- package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-TRGU2MDG.js} +26 -34
- package/dist/{wordpress-XRWGO6LG.js → wordpress-WRUKLCZR.js} +87 -104
- package/dist/{workos-WR4NKOYL.js → workos-ZDW4EHS4.js} +37 -56
- package/dist/{zhihu-BKZIB3WA.js → zhihu-4VI67CWU.js} +35 -57
- package/package.json +3 -3
- package/dist/chunk-2O27H4Y2.js +0 -183
- package/dist/chunk-GKX72JMJ.js +0 -378
- package/dist/chunk-MLKGABMK.js +0 -9
|
@@ -1,48 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-VLOIDU5U.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
trimmedText
|
|
7
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
8
|
import {
|
|
2
9
|
createProviderPlugin,
|
|
3
10
|
requireApiKey,
|
|
4
11
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
12
|
+
} from "./chunk-B4P6YZFS.js";
|
|
13
|
+
import "./chunk-SWBNHIO4.js";
|
|
10
14
|
import {
|
|
11
15
|
TBError,
|
|
12
16
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-OKRZPQ3R.js";
|
|
18
|
+
import "./chunk-U67V476Y.js";
|
|
15
19
|
|
|
16
20
|
// ../plugins/src/v2ex/api.ts
|
|
17
21
|
var SERVICE = "v2ex";
|
|
18
22
|
var API_BASE = "https://www.v2ex.com/api/v2";
|
|
19
23
|
var LEGACY_API_BASE = "https://www.v2ex.com/api";
|
|
20
24
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
function text(value) {
|
|
25
|
-
if (typeof value !== "string") return void 0;
|
|
26
|
-
const trimmed = value.trim();
|
|
27
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
28
|
-
}
|
|
25
|
+
var v2Http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
26
|
+
var legacyHttp = createProviderHttpClient({ baseUrl: `${LEGACY_API_BASE}/`, service: SERVICE });
|
|
29
27
|
function invalidResponse(message) {
|
|
30
28
|
return new TBError("unavailable", message, { retryable: true });
|
|
31
29
|
}
|
|
32
30
|
function requireRecord(value, label) {
|
|
33
|
-
const result =
|
|
31
|
+
const result = asJsonObject(value);
|
|
34
32
|
if (result === void 0) throw invalidResponse(`${label} must be an object`);
|
|
35
33
|
return result;
|
|
36
34
|
}
|
|
37
35
|
function errorMessage(payload) {
|
|
38
|
-
if (typeof payload === "string") return
|
|
39
|
-
const body =
|
|
36
|
+
if (typeof payload === "string") return trimmedText(payload);
|
|
37
|
+
const body = asJsonObject(payload);
|
|
40
38
|
if (body === void 0) return void 0;
|
|
41
|
-
const direct =
|
|
39
|
+
const direct = trimmedText(body.message) ?? trimmedText(body.error);
|
|
42
40
|
if (direct !== void 0) return direct;
|
|
43
41
|
if (Array.isArray(body.errors)) {
|
|
44
42
|
for (const item of body.errors) {
|
|
45
|
-
const detail =
|
|
43
|
+
const detail = trimmedText(asJsonObject(item)?.detail) ?? trimmedText(asJsonObject(item)?.message);
|
|
46
44
|
if (detail !== void 0) return detail;
|
|
47
45
|
}
|
|
48
46
|
}
|
|
@@ -51,58 +49,35 @@ function errorMessage(payload) {
|
|
|
51
49
|
function envelopeError(payload) {
|
|
52
50
|
return new TBError("invalid_argument", errorMessage(payload) ?? "V2EX request failed");
|
|
53
51
|
}
|
|
54
|
-
async function
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function send(url, init, label) {
|
|
64
|
-
let response;
|
|
65
|
-
try {
|
|
66
|
-
response = await guardedFetch(url.toString(), {
|
|
67
|
-
...init,
|
|
68
|
-
// 不设超时会让一个挂死的端点拖住整个调用;上游同样给了 30s 的独立预算。
|
|
69
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
70
|
-
});
|
|
71
|
-
} catch (error) {
|
|
72
|
-
if (error instanceof TBError) throw error;
|
|
73
|
-
if (error instanceof Error && error.name === "TimeoutError") {
|
|
74
|
-
throw upstreamError(504, `${label} request timed out after ${REQUEST_TIMEOUT_MS / 1e3} seconds`);
|
|
75
|
-
}
|
|
76
|
-
throw upstreamError(
|
|
77
|
-
502,
|
|
78
|
-
error instanceof Error ? `${label} request failed: ${error.message}` : `${label} request failed`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const payload = await readPayload(response);
|
|
82
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(payload) ?? "V2EX request failed");
|
|
83
|
-
return payload;
|
|
52
|
+
async function send(client, request2, label) {
|
|
53
|
+
const response = await client.request({
|
|
54
|
+
...request2,
|
|
55
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
56
|
+
invalidJson: "text",
|
|
57
|
+
mapError: ({ data, status }) => upstreamError(status, errorMessage(data) ?? "V2EX request failed"),
|
|
58
|
+
mapTransportError: ({ kind, message }) => kind === "timeout" ? upstreamError(504, `${label} request timed out after ${REQUEST_TIMEOUT_MS / 1e3} seconds`) : upstreamError(502, message === void 0 ? `${label} request failed` : `${label} request failed: ${message}`)
|
|
59
|
+
});
|
|
60
|
+
return response.bodyKind === "empty" ? null : response.data;
|
|
84
61
|
}
|
|
85
62
|
async function request(ctx, options) {
|
|
86
|
-
const url = new URL(`${API_BASE}${options.path}`);
|
|
87
|
-
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
88
|
-
if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
89
|
-
}
|
|
90
63
|
const headers = {
|
|
91
64
|
accept: "application/json",
|
|
92
65
|
authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
|
|
93
66
|
};
|
|
94
|
-
|
|
95
|
-
return send(url, {
|
|
67
|
+
return send(v2Http, {
|
|
96
68
|
method: options.method,
|
|
69
|
+
path: options.path,
|
|
70
|
+
// 上游连**空串**也当作"没给",不只是 undefined/null。
|
|
71
|
+
query: Object.entries(options.query ?? {}).filter(([, value]) => value !== void 0 && value !== ""),
|
|
97
72
|
headers,
|
|
98
|
-
...options.body === void 0 ? {} : {
|
|
73
|
+
...options.body === void 0 ? {} : { json: options.body }
|
|
99
74
|
}, `V2EX ${options.path}`);
|
|
100
75
|
}
|
|
101
76
|
async function legacyRequest(ctx, path) {
|
|
102
77
|
requireApiKey(ctx, SERVICE);
|
|
103
78
|
const payload = await send(
|
|
104
|
-
|
|
105
|
-
{ method: "GET", headers: { accept: "application/json" } },
|
|
79
|
+
legacyHttp,
|
|
80
|
+
{ method: "GET", path, headers: { accept: "application/json" } },
|
|
106
81
|
`V2EX legacy ${path}`
|
|
107
82
|
);
|
|
108
83
|
if (!Array.isArray(payload)) {
|
|
@@ -116,7 +91,7 @@ function unwrapEnvelope(payload, label) {
|
|
|
116
91
|
if (!("result" in envelope)) {
|
|
117
92
|
throw invalidResponse(`V2EX ${label} response missing result`);
|
|
118
93
|
}
|
|
119
|
-
return { message:
|
|
94
|
+
return { message: trimmedText(envelope.message), result: envelope.result };
|
|
120
95
|
}
|
|
121
96
|
function ensureAccepted(payload, label) {
|
|
122
97
|
if (payload === null) return;
|
|
@@ -185,7 +160,7 @@ async function createToken(input, ctx) {
|
|
|
185
160
|
}),
|
|
186
161
|
"token creation"
|
|
187
162
|
);
|
|
188
|
-
const token =
|
|
163
|
+
const token = trimmedText(objectResult(envelope, "token creation").token);
|
|
189
164
|
if (token === void 0) {
|
|
190
165
|
throw invalidResponse("V2EX token creation response missing token");
|
|
191
166
|
}
|
|
@@ -1,40 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-VLOIDU5U.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
booleanValue,
|
|
7
|
+
compactDefined,
|
|
8
|
+
finiteNumber,
|
|
9
|
+
trimmedText
|
|
10
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
11
|
import {
|
|
2
12
|
createProviderPlugin,
|
|
3
13
|
requireApiKey,
|
|
4
14
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
15
|
+
} from "./chunk-B4P6YZFS.js";
|
|
16
|
+
import "./chunk-SWBNHIO4.js";
|
|
10
17
|
import {
|
|
11
18
|
TBError,
|
|
12
19
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-OKRZPQ3R.js";
|
|
21
|
+
import "./chunk-U67V476Y.js";
|
|
15
22
|
|
|
16
23
|
// ../plugins/src/vercel/api.ts
|
|
17
24
|
var SERVICE = "vercel";
|
|
18
25
|
var API_BASE = "https://api.vercel.com";
|
|
19
|
-
|
|
20
|
-
if (typeof value !== "string") return void 0;
|
|
21
|
-
const trimmed = value.trim();
|
|
22
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
23
|
-
}
|
|
24
|
-
function num(value) {
|
|
25
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
26
|
-
}
|
|
27
|
-
function bool(value) {
|
|
28
|
-
return typeof value === "boolean" ? value : void 0;
|
|
29
|
-
}
|
|
30
|
-
function record(value) {
|
|
31
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
32
|
-
}
|
|
33
|
-
function compact(input) {
|
|
34
|
-
return Object.fromEntries(
|
|
35
|
-
Object.entries(input).filter(([, value]) => value !== void 0)
|
|
36
|
-
);
|
|
37
|
-
}
|
|
26
|
+
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
38
27
|
function stringArray(value) {
|
|
39
28
|
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : void 0;
|
|
40
29
|
}
|
|
@@ -45,111 +34,96 @@ function contractError(label) {
|
|
|
45
34
|
return new TBError("unavailable", `Vercel \u54CD\u5E94\u7F3A\u5C11\u6216\u7C7B\u578B\u4E0D\u7B26:${label}`, { retryable: true });
|
|
46
35
|
}
|
|
47
36
|
function requiredText(value, label) {
|
|
48
|
-
const result =
|
|
37
|
+
const result = trimmedText(value);
|
|
49
38
|
if (result === void 0) throw contractError(label);
|
|
50
39
|
return result;
|
|
51
40
|
}
|
|
52
41
|
function requiredNumber(value, label) {
|
|
53
|
-
const result =
|
|
42
|
+
const result = finiteNumber(value);
|
|
54
43
|
if (result === void 0) throw contractError(label);
|
|
55
44
|
return result;
|
|
56
45
|
}
|
|
57
46
|
function requiredRecord(value, label) {
|
|
58
|
-
const result =
|
|
47
|
+
const result = asJsonObject(value);
|
|
59
48
|
if (result === void 0) throw contractError(label);
|
|
60
49
|
return result;
|
|
61
50
|
}
|
|
62
51
|
function arrayPayload(payload, key) {
|
|
63
52
|
if (Array.isArray(payload)) return payload;
|
|
64
|
-
const value =
|
|
53
|
+
const value = asJsonObject(payload)?.[key];
|
|
65
54
|
return Array.isArray(value) ? value : [];
|
|
66
55
|
}
|
|
67
56
|
async function request(ctx, input) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
url.searchParams.set(key, String(value));
|
|
72
|
-
}
|
|
73
|
-
const headers = {
|
|
74
|
-
authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
|
|
75
|
-
};
|
|
76
|
-
if (input.body !== void 0) headers["content-type"] = "application/json";
|
|
77
|
-
const response = await guardedFetch(url.toString(), {
|
|
57
|
+
const hasBody = input.body !== void 0;
|
|
58
|
+
const { data } = await http.request({
|
|
59
|
+
path: input.path,
|
|
78
60
|
method: input.method ?? "GET",
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
isJson = false;
|
|
61
|
+
// 上游 `queryParams` 连空串一起跳过。
|
|
62
|
+
query: Object.entries(input.query ?? {}).filter(([, value]) => value !== void 0 && value !== ""),
|
|
63
|
+
headers: { authorization: `Bearer ${requireApiKey(ctx, SERVICE)}` },
|
|
64
|
+
...hasBody ? { json: input.body } : {},
|
|
65
|
+
invalidJsonMessage: "Vercel \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
|
|
66
|
+
mapError: ({ bodyKind, data: payload, status }) => {
|
|
67
|
+
const body = asJsonObject(payload) ?? {};
|
|
68
|
+
const error = asJsonObject(body.error) ?? {};
|
|
69
|
+
const message = trimmedText(error.message) ?? trimmedText(body.message) ?? (bodyKind === "invalid-json" || bodyKind === "text" ? trimmedText(payload) : void 0) ?? `Vercel \u8FD4\u56DE HTTP ${status}`;
|
|
70
|
+
return upstreamError(status, message);
|
|
90
71
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const body = record(payload) ?? {};
|
|
94
|
-
const error = record(body.error) ?? {};
|
|
95
|
-
const message = text(error.message) ?? text(body.message) ?? (isJson ? void 0 : text(raw)) ?? `Vercel \u8FD4\u56DE HTTP ${response.status}`;
|
|
96
|
-
throw upstreamError(response.status, message);
|
|
97
|
-
}
|
|
98
|
-
if (!isJson) throw new TBError("unavailable", "Vercel \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
|
|
99
|
-
return payload;
|
|
72
|
+
});
|
|
73
|
+
return data ?? {};
|
|
100
74
|
}
|
|
101
75
|
function unwrap(payload, key) {
|
|
102
76
|
const body = requiredRecord(payload, key);
|
|
103
|
-
return
|
|
77
|
+
return asJsonObject(body[key]) ?? body;
|
|
104
78
|
}
|
|
105
79
|
function mapUser(payload) {
|
|
106
80
|
const user = unwrap(payload, "user");
|
|
107
|
-
return
|
|
81
|
+
return compactDefined({
|
|
108
82
|
// 上游在 id 缺失时报 502:没有 id 的 user 响应不能算成功。
|
|
109
83
|
id: requiredText(user.id, "user.id"),
|
|
110
|
-
username:
|
|
111
|
-
email:
|
|
112
|
-
name:
|
|
84
|
+
username: trimmedText(user.username),
|
|
85
|
+
email: trimmedText(user.email),
|
|
86
|
+
name: trimmedText(user.name)
|
|
113
87
|
});
|
|
114
88
|
}
|
|
115
89
|
function mapTeam(payload) {
|
|
116
90
|
const team = unwrap(payload, "team");
|
|
117
|
-
return
|
|
91
|
+
return compactDefined({
|
|
118
92
|
id: requiredText(team.id, "team.id"),
|
|
119
|
-
slug:
|
|
120
|
-
name:
|
|
121
|
-
createdAt:
|
|
122
|
-
updatedAt:
|
|
93
|
+
slug: trimmedText(team.slug),
|
|
94
|
+
name: trimmedText(team.name),
|
|
95
|
+
createdAt: finiteNumber(team.createdAt),
|
|
96
|
+
updatedAt: finiteNumber(team.updatedAt)
|
|
123
97
|
});
|
|
124
98
|
}
|
|
125
99
|
function mapDeployment(value) {
|
|
126
100
|
const deployment = requiredRecord(value, "deployment");
|
|
127
|
-
return
|
|
101
|
+
return compactDefined({
|
|
128
102
|
id: requiredText(deployment.id, "deployment.id"),
|
|
129
|
-
name:
|
|
130
|
-
url:
|
|
131
|
-
state:
|
|
132
|
-
readyState:
|
|
133
|
-
target:
|
|
134
|
-
createdAt:
|
|
135
|
-
ready:
|
|
136
|
-
projectId:
|
|
137
|
-
creator:
|
|
138
|
-
meta:
|
|
103
|
+
name: trimmedText(deployment.name),
|
|
104
|
+
url: trimmedText(deployment.url),
|
|
105
|
+
state: trimmedText(deployment.state),
|
|
106
|
+
readyState: trimmedText(deployment.readyState),
|
|
107
|
+
target: trimmedText(deployment.target),
|
|
108
|
+
createdAt: finiteNumber(deployment.createdAt),
|
|
109
|
+
ready: finiteNumber(deployment.ready),
|
|
110
|
+
projectId: trimmedText(deployment.projectId),
|
|
111
|
+
creator: asJsonObject(deployment.creator),
|
|
112
|
+
meta: asJsonObject(deployment.meta),
|
|
139
113
|
alias: stringArray(deployment.alias)
|
|
140
114
|
});
|
|
141
115
|
}
|
|
142
116
|
function mapProject(value) {
|
|
143
117
|
const project = requiredRecord(value, "project");
|
|
144
|
-
return
|
|
118
|
+
return compactDefined({
|
|
145
119
|
id: requiredText(project.id, "project.id"),
|
|
146
120
|
name: requiredText(project.name, "project.name"),
|
|
147
|
-
accountId:
|
|
148
|
-
framework:
|
|
149
|
-
nodeVersion:
|
|
150
|
-
createdAt:
|
|
151
|
-
updatedAt:
|
|
152
|
-
link:
|
|
121
|
+
accountId: trimmedText(project.accountId),
|
|
122
|
+
framework: trimmedText(project.framework),
|
|
123
|
+
nodeVersion: trimmedText(project.nodeVersion),
|
|
124
|
+
createdAt: finiteNumber(project.createdAt),
|
|
125
|
+
updatedAt: finiteNumber(project.updatedAt),
|
|
126
|
+
link: asJsonObject(project.link),
|
|
153
127
|
latestDeployments: Array.isArray(project.latestDeployments) ? project.latestDeployments.map((deployment) => mapDeployment(deployment)) : void 0
|
|
154
128
|
});
|
|
155
129
|
}
|
|
@@ -163,80 +137,80 @@ function mapDeploymentEvent(value) {
|
|
|
163
137
|
}
|
|
164
138
|
function mapRuntimeLog(value) {
|
|
165
139
|
const log = requiredRecord(value, "runtime log");
|
|
166
|
-
return
|
|
140
|
+
return compactDefined({
|
|
167
141
|
timestampInMs: requiredNumber(log.timestampInMs, "log.timestampInMs"),
|
|
168
142
|
level: requiredText(log.level, "log.level"),
|
|
169
143
|
message: requiredText(log.message, "log.message"),
|
|
170
144
|
source: requiredText(log.source, "log.source"),
|
|
171
|
-
requestMethod:
|
|
172
|
-
requestPath:
|
|
173
|
-
responseStatusCode:
|
|
145
|
+
requestMethod: trimmedText(log.requestMethod),
|
|
146
|
+
requestPath: trimmedText(log.requestPath),
|
|
147
|
+
responseStatusCode: finiteNumber(log.responseStatusCode)
|
|
174
148
|
});
|
|
175
149
|
}
|
|
176
150
|
function mapEnv(value) {
|
|
177
151
|
const env = requiredRecord(value, "env");
|
|
178
|
-
return
|
|
152
|
+
return compactDefined({
|
|
179
153
|
id: requiredText(env.id, "env.id"),
|
|
180
154
|
key: requiredText(env.key, "env.key"),
|
|
181
155
|
type: requiredText(env.type, "env.type"),
|
|
182
156
|
target: stringArray(env.target),
|
|
183
|
-
gitBranch:
|
|
184
|
-
createdAt:
|
|
185
|
-
updatedAt:
|
|
186
|
-
comment:
|
|
157
|
+
gitBranch: trimmedText(env.gitBranch),
|
|
158
|
+
createdAt: finiteNumber(env.createdAt),
|
|
159
|
+
updatedAt: finiteNumber(env.updatedAt),
|
|
160
|
+
comment: trimmedText(env.comment)
|
|
187
161
|
});
|
|
188
162
|
}
|
|
189
163
|
function mapDomain(value) {
|
|
190
164
|
const domain = requiredRecord(value, "domain");
|
|
191
|
-
return
|
|
165
|
+
return compactDefined({
|
|
192
166
|
name: requiredText(domain.name, "domain.name"),
|
|
193
|
-
apexName:
|
|
194
|
-
verified:
|
|
195
|
-
verification: Array.isArray(domain.verification) ? domain.verification.map((item) =>
|
|
167
|
+
apexName: trimmedText(domain.apexName),
|
|
168
|
+
verified: booleanValue(domain.verified),
|
|
169
|
+
verification: Array.isArray(domain.verification) ? domain.verification.map((item) => asJsonObject(item)).filter((item) => item !== void 0) : void 0,
|
|
196
170
|
// null 是"明确没有重定向",与"字段缺席"不是一回事。
|
|
197
|
-
redirect: domain.redirect === null ? null :
|
|
198
|
-
gitBranch:
|
|
199
|
-
customEnvironmentId:
|
|
171
|
+
redirect: domain.redirect === null ? null : trimmedText(domain.redirect),
|
|
172
|
+
gitBranch: trimmedText(domain.gitBranch),
|
|
173
|
+
customEnvironmentId: trimmedText(domain.customEnvironmentId)
|
|
200
174
|
});
|
|
201
175
|
}
|
|
202
176
|
function mapWebhook(value) {
|
|
203
177
|
const webhook = requiredRecord(value, "webhook");
|
|
204
|
-
return
|
|
178
|
+
return compactDefined({
|
|
205
179
|
id: requiredText(webhook.id, "webhook.id"),
|
|
206
180
|
url: requiredText(webhook.url, "webhook.url"),
|
|
207
181
|
events: stringArray(webhook.events),
|
|
208
182
|
projectIds: stringArray(webhook.projectIds),
|
|
209
|
-
teamId:
|
|
210
|
-
createdAt:
|
|
211
|
-
updatedAt:
|
|
183
|
+
teamId: trimmedText(webhook.teamId),
|
|
184
|
+
createdAt: finiteNumber(webhook.createdAt),
|
|
185
|
+
updatedAt: finiteNumber(webhook.updatedAt)
|
|
212
186
|
});
|
|
213
187
|
}
|
|
214
188
|
function pagination(payload) {
|
|
215
|
-
return
|
|
189
|
+
return asJsonObject(asJsonObject(payload)?.pagination);
|
|
216
190
|
}
|
|
217
191
|
function projectBody(input) {
|
|
218
|
-
return
|
|
219
|
-
name:
|
|
220
|
-
framework:
|
|
221
|
-
rootDirectory:
|
|
222
|
-
nodeVersion:
|
|
223
|
-
buildCommand:
|
|
224
|
-
devCommand:
|
|
225
|
-
installCommand:
|
|
226
|
-
outputDirectory:
|
|
227
|
-
directoryListing:
|
|
228
|
-
publicSource:
|
|
229
|
-
gitForkProtection:
|
|
192
|
+
return compactDefined({
|
|
193
|
+
name: trimmedText(input.name),
|
|
194
|
+
framework: trimmedText(input.framework),
|
|
195
|
+
rootDirectory: trimmedText(input.rootDirectory),
|
|
196
|
+
nodeVersion: trimmedText(input.nodeVersion),
|
|
197
|
+
buildCommand: trimmedText(input.buildCommand),
|
|
198
|
+
devCommand: trimmedText(input.devCommand),
|
|
199
|
+
installCommand: trimmedText(input.installCommand),
|
|
200
|
+
outputDirectory: trimmedText(input.outputDirectory),
|
|
201
|
+
directoryListing: booleanValue(input.directoryListing),
|
|
202
|
+
publicSource: booleanValue(input.publicSource),
|
|
203
|
+
gitForkProtection: booleanValue(input.gitForkProtection)
|
|
230
204
|
});
|
|
231
205
|
}
|
|
232
206
|
function envBody(input) {
|
|
233
|
-
return
|
|
234
|
-
key:
|
|
235
|
-
value:
|
|
236
|
-
type:
|
|
207
|
+
return compactDefined({
|
|
208
|
+
key: trimmedText(input.key),
|
|
209
|
+
value: trimmedText(input.value),
|
|
210
|
+
type: trimmedText(input.type),
|
|
237
211
|
target: stringArray(input.target),
|
|
238
|
-
gitBranch:
|
|
239
|
-
comment:
|
|
212
|
+
gitBranch: trimmedText(input.gitBranch),
|
|
213
|
+
comment: trimmedText(input.comment),
|
|
240
214
|
customEnvironmentIds: stringArray(input.customEnvironmentIds)
|
|
241
215
|
});
|
|
242
216
|
}
|
|
@@ -256,7 +230,7 @@ async function listTeams(input, ctx) {
|
|
|
256
230
|
path: "/v2/teams",
|
|
257
231
|
query: { limit: input.limit, since: input.since }
|
|
258
232
|
});
|
|
259
|
-
return
|
|
233
|
+
return compactDefined({
|
|
260
234
|
teams: arrayPayload(payload, "teams").map((team) => mapTeam(team)),
|
|
261
235
|
pagination: pagination(payload)
|
|
262
236
|
});
|
|
@@ -271,10 +245,10 @@ async function listProjects(input, ctx) {
|
|
|
271
245
|
limit: input.limit,
|
|
272
246
|
since: input.since,
|
|
273
247
|
until: input.until,
|
|
274
|
-
repoUrl:
|
|
248
|
+
repoUrl: trimmedText(input.repoUrl)
|
|
275
249
|
}
|
|
276
250
|
});
|
|
277
|
-
return
|
|
251
|
+
return compactDefined({
|
|
278
252
|
projects: arrayPayload(payload, "projects").map((project) => mapProject(project)),
|
|
279
253
|
pagination: pagination(payload)
|
|
280
254
|
});
|
|
@@ -303,14 +277,14 @@ async function listDeployments(input, ctx) {
|
|
|
303
277
|
path: "/v6/deployments",
|
|
304
278
|
query: {
|
|
305
279
|
limit: input.limit,
|
|
306
|
-
projectId:
|
|
280
|
+
projectId: trimmedText(input.projectId),
|
|
307
281
|
since: input.since,
|
|
308
282
|
until: input.until,
|
|
309
|
-
target:
|
|
310
|
-
state:
|
|
283
|
+
target: trimmedText(input.target),
|
|
284
|
+
state: trimmedText(input.state)
|
|
311
285
|
}
|
|
312
286
|
});
|
|
313
|
-
return
|
|
287
|
+
return compactDefined({
|
|
314
288
|
deployments: arrayPayload(payload, "deployments").map((deployment) => mapDeployment(deployment)),
|
|
315
289
|
pagination: pagination(payload)
|
|
316
290
|
});
|
|
@@ -329,7 +303,7 @@ async function getDeploymentEvents(input, ctx) {
|
|
|
329
303
|
query: {
|
|
330
304
|
// 这个端点的布尔用 1/0 编码,与 get_deployment 不同。
|
|
331
305
|
builds: flag(input.builds),
|
|
332
|
-
direction:
|
|
306
|
+
direction: trimmedText(input.direction),
|
|
333
307
|
limit: input.limit,
|
|
334
308
|
since: input.since,
|
|
335
309
|
until: input.until
|
|
@@ -347,8 +321,8 @@ async function listProjectEnvs(input, ctx) {
|
|
|
347
321
|
const payload = await request(ctx, {
|
|
348
322
|
path: `/v10/projects/${seg(input.idOrName)}/env`,
|
|
349
323
|
query: {
|
|
350
|
-
customEnvironmentId:
|
|
351
|
-
gitBranch:
|
|
324
|
+
customEnvironmentId: trimmedText(input.customEnvironmentId),
|
|
325
|
+
gitBranch: trimmedText(input.gitBranch)
|
|
352
326
|
}
|
|
353
327
|
});
|
|
354
328
|
return { envs: arrayPayload(payload, "envs").map((env) => mapEnv(env)) };
|
|
@@ -385,11 +359,11 @@ async function listProjectDomains(input, ctx) {
|
|
|
385
359
|
limit: input.limit,
|
|
386
360
|
since: input.since,
|
|
387
361
|
until: input.until,
|
|
388
|
-
gitBranch:
|
|
389
|
-
customEnvironmentId:
|
|
362
|
+
gitBranch: trimmedText(input.gitBranch),
|
|
363
|
+
customEnvironmentId: trimmedText(input.customEnvironmentId)
|
|
390
364
|
}
|
|
391
365
|
});
|
|
392
|
-
return
|
|
366
|
+
return compactDefined({
|
|
393
367
|
domains: arrayPayload(payload, "domains").map((domain) => mapDomain(domain)),
|
|
394
368
|
pagination: pagination(payload)
|
|
395
369
|
});
|
|
@@ -404,11 +378,11 @@ async function addProjectDomain(input, ctx) {
|
|
|
404
378
|
const payload = await request(ctx, {
|
|
405
379
|
method: "POST",
|
|
406
380
|
path: `/v10/projects/${seg(input.idOrName)}/domains`,
|
|
407
|
-
body:
|
|
408
|
-
name:
|
|
409
|
-
redirect:
|
|
410
|
-
gitBranch:
|
|
411
|
-
customEnvironmentId:
|
|
381
|
+
body: compactDefined({
|
|
382
|
+
name: trimmedText(input.name),
|
|
383
|
+
redirect: trimmedText(input.redirect),
|
|
384
|
+
gitBranch: trimmedText(input.gitBranch),
|
|
385
|
+
customEnvironmentId: trimmedText(input.customEnvironmentId)
|
|
412
386
|
})
|
|
413
387
|
});
|
|
414
388
|
return { domain: mapDomain(payload) };
|
|
@@ -425,10 +399,10 @@ async function getDomainConfig(input, ctx) {
|
|
|
425
399
|
await request(ctx, { path: `/v6/domains/${seg(input.domain)}/config` }),
|
|
426
400
|
"domain config"
|
|
427
401
|
);
|
|
428
|
-
return
|
|
429
|
-
configuredBy:
|
|
402
|
+
return compactDefined({
|
|
403
|
+
configuredBy: trimmedText(payload.configuredBy),
|
|
430
404
|
acceptedChallenges: stringArray(payload.acceptedChallenges),
|
|
431
|
-
misconfigured:
|
|
405
|
+
misconfigured: booleanValue(payload.misconfigured),
|
|
432
406
|
recommendedNameServers: stringArray(payload.recommendedNameServers)
|
|
433
407
|
});
|
|
434
408
|
}
|
|
@@ -443,8 +417,8 @@ async function createWebhook(input, ctx) {
|
|
|
443
417
|
const payload = await request(ctx, {
|
|
444
418
|
method: "POST",
|
|
445
419
|
path: "/v1/webhooks",
|
|
446
|
-
body:
|
|
447
|
-
url:
|
|
420
|
+
body: compactDefined({
|
|
421
|
+
url: trimmedText(input.url),
|
|
448
422
|
events: stringArray(input.events),
|
|
449
423
|
projectIds: stringArray(input.projectIds)
|
|
450
424
|
})
|