@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,33 +1,30 @@
|
|
|
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/wolfram_alpha_api/api.ts
|
|
17
21
|
var SERVICE = "wolfram_alpha_api";
|
|
18
22
|
var API_BASE = "https://api.wolframalpha.com";
|
|
19
23
|
var RECOGNIZER_URL = "https://www.wolframalpha.com/queryrecognizer/query.jsp";
|
|
20
24
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
21
|
-
|
|
22
|
-
if (typeof value !== "string") return void 0;
|
|
23
|
-
const trimmed = value.trim();
|
|
24
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
25
|
-
}
|
|
26
|
-
function record(value) {
|
|
27
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
28
|
-
}
|
|
25
|
+
var http = createProviderHttpClient({ service: SERVICE });
|
|
29
26
|
function nullableText(value) {
|
|
30
|
-
return
|
|
27
|
+
return trimmedText(value) ?? null;
|
|
31
28
|
}
|
|
32
29
|
function nullableNumber(value) {
|
|
33
30
|
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
@@ -43,7 +40,7 @@ function booleanLike(value) {
|
|
|
43
40
|
return false;
|
|
44
41
|
}
|
|
45
42
|
function searchTerm(value) {
|
|
46
|
-
const query =
|
|
43
|
+
const query = trimmedText(value);
|
|
47
44
|
if (query === void 0) throw new TBError("invalid_argument", "query \u4E0D\u80FD\u662F\u7A7A\u767D");
|
|
48
45
|
return query;
|
|
49
46
|
}
|
|
@@ -58,20 +55,15 @@ function wolframError(status, body) {
|
|
|
58
55
|
return upstreamError(status, message);
|
|
59
56
|
}
|
|
60
57
|
async function requestText(url) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
const body = await response.text();
|
|
74
|
-
if (!response.ok) throw wolframError(response.status, body);
|
|
58
|
+
const result = await http.request({
|
|
59
|
+
baseUrl: url.origin,
|
|
60
|
+
path: url.toString(),
|
|
61
|
+
responseType: "text",
|
|
62
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
63
|
+
mapError: ({ data, status }) => wolframError(status, typeof data === "string" ? data : ""),
|
|
64
|
+
mapTransportError: ({ kind }) => kind === "timeout" ? upstreamError(504, `Wolfram|Alpha ${REQUEST_TIMEOUT_MS / 1e3} \u79D2\u5185\u6CA1\u6709\u8FD4\u56DE`) : upstreamError(502, "Wolfram|Alpha request failed")
|
|
65
|
+
});
|
|
66
|
+
const body = result.data ?? "";
|
|
75
67
|
if (looksLikeCredentialError(body)) throw upstreamError(401, body.trim());
|
|
76
68
|
return body;
|
|
77
69
|
}
|
|
@@ -101,9 +93,9 @@ async function validateQuery(input, ctx) {
|
|
|
101
93
|
} catch {
|
|
102
94
|
throw new TBError("unavailable", "Wolfram|Alpha \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
|
|
103
95
|
}
|
|
104
|
-
const result =
|
|
96
|
+
const result = asJsonObject(payload);
|
|
105
97
|
const queries = result?.query;
|
|
106
|
-
const first = Array.isArray(queries) ?
|
|
98
|
+
const first = Array.isArray(queries) ? asJsonObject(queries[0]) : void 0;
|
|
107
99
|
if (first === void 0) {
|
|
108
100
|
throw new TBError("unavailable", "Wolfram|Alpha recognizer \u6CA1\u6709\u8FD4\u56DE\u67E5\u8BE2\u7ED3\u679C", { retryable: true });
|
|
109
101
|
}
|
|
@@ -116,7 +108,7 @@ async function validateQuery(input, ctx) {
|
|
|
116
108
|
timingMs: nullableNumber(result?.timing),
|
|
117
109
|
resultSignificanceScore: nullableNumber(first.resultsignificancescore),
|
|
118
110
|
spellingCorrection: nullableText(first.spellingCorrection),
|
|
119
|
-
summaryBoxPath: nullableText(
|
|
111
|
+
summaryBoxPath: nullableText(asJsonObject(first.summarybox)?.path)
|
|
120
112
|
};
|
|
121
113
|
}
|
|
122
114
|
async function getShortAnswer(input, ctx) {
|
|
@@ -1,39 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-VLOIDU5U.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined,
|
|
7
|
+
trimmedText
|
|
8
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
9
|
import {
|
|
2
10
|
createProviderPlugin,
|
|
3
11
|
requireCredential,
|
|
4
12
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-B4P6YZFS.js";
|
|
6
14
|
import {
|
|
7
|
-
assertPublicHttpUrl
|
|
8
|
-
|
|
9
|
-
} from "./chunk-2O27H4Y2.js";
|
|
10
|
-
import "./chunk-GKX72JMJ.js";
|
|
15
|
+
assertPublicHttpUrl
|
|
16
|
+
} from "./chunk-SWBNHIO4.js";
|
|
11
17
|
import {
|
|
12
18
|
TBError,
|
|
13
19
|
external_exports
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-OKRZPQ3R.js";
|
|
21
|
+
import "./chunk-U67V476Y.js";
|
|
16
22
|
|
|
17
23
|
// ../plugins/src/wordpress/api.ts
|
|
18
24
|
var SERVICE = "wordpress";
|
|
19
25
|
var API_PATH = "wp-json/wp/v2";
|
|
20
26
|
var REST_ROOT_SUFFIXES = ["/wp-json/wp/v2", "/wp-json"];
|
|
21
27
|
var CURRENT_USER_PATH = "/users/me";
|
|
22
|
-
|
|
23
|
-
if (typeof value !== "string") return void 0;
|
|
24
|
-
const trimmed = value.trim();
|
|
25
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
26
|
-
}
|
|
27
|
-
function record(value) {
|
|
28
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
29
|
-
}
|
|
30
|
-
function compact(input) {
|
|
31
|
-
return Object.fromEntries(
|
|
32
|
-
Object.entries(input).filter(([, value]) => value !== void 0)
|
|
33
|
-
);
|
|
34
|
-
}
|
|
28
|
+
var http = createProviderHttpClient({ service: SERVICE });
|
|
35
29
|
function requireRecord(value, message) {
|
|
36
|
-
const result =
|
|
30
|
+
const result = asJsonObject(value);
|
|
37
31
|
if (result === void 0) throw upstreamError(502, message);
|
|
38
32
|
return result;
|
|
39
33
|
}
|
|
@@ -84,52 +78,41 @@ function basicAuthHeader(ctx) {
|
|
|
84
78
|
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
85
79
|
return `Basic ${btoa(binary)}`;
|
|
86
80
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
return url.toString();
|
|
81
|
+
function queryPairs(query = {}) {
|
|
82
|
+
return Object.entries(query).map(([key, value]) => [
|
|
83
|
+
key,
|
|
84
|
+
Array.isArray(value) ? value.map(String).join(",") : value
|
|
85
|
+
]);
|
|
94
86
|
}
|
|
95
|
-
function errorMessage(payload,
|
|
96
|
-
return
|
|
87
|
+
function errorMessage(payload, context) {
|
|
88
|
+
return trimmedText(asJsonObject(payload)?.message) ?? (trimmedText(context.statusText) === void 0 ? "WordPress request failed" : `WordPress request failed: ${context.statusText}`);
|
|
89
|
+
}
|
|
90
|
+
function jsonPayload(data, bodyKind) {
|
|
91
|
+
return bodyKind === "json" ? data : null;
|
|
97
92
|
}
|
|
98
93
|
async function requestResponse(ctx, options) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
94
|
+
return http.request({
|
|
95
|
+
baseUrl: `${apiBaseUrl(ctx)}/`,
|
|
96
|
+
path: options.path,
|
|
97
|
+
method: options.method ?? "GET",
|
|
98
|
+
query: queryPairs(options.query),
|
|
99
|
+
headers: { accept: "application/json", authorization: basicAuthHeader(ctx) },
|
|
100
|
+
...options.body === void 0 ? {} : { json: options.body },
|
|
101
|
+
// 上游 response.json().catch(() => null):成功或错误上的非 JSON 都按 null。
|
|
102
|
+
invalidJson: "text",
|
|
103
|
+
mapError: (context) => upstreamError(
|
|
104
|
+
context.status || 502,
|
|
105
|
+
errorMessage(jsonPayload(context.data, context.bodyKind), context)
|
|
106
|
+
),
|
|
107
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
113
108
|
502,
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async function readJson(response) {
|
|
119
|
-
const raw = await response.text().catch(() => "");
|
|
120
|
-
let payload = null;
|
|
121
|
-
if (raw.trim() !== "") {
|
|
122
|
-
try {
|
|
123
|
-
payload = JSON.parse(raw);
|
|
124
|
-
} catch {
|
|
125
|
-
payload = null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (!response.ok) throw upstreamError(response.status || 502, errorMessage(payload, response));
|
|
129
|
-
return payload;
|
|
109
|
+
message === void 0 ? "WordPress request failed" : `WordPress request failed: ${message}`
|
|
110
|
+
)
|
|
111
|
+
});
|
|
130
112
|
}
|
|
131
113
|
async function requestObject(ctx, options) {
|
|
132
|
-
const
|
|
114
|
+
const result = await requestResponse(ctx, options);
|
|
115
|
+
const payload = jsonPayload(result.data, result.bodyKind);
|
|
133
116
|
return requireRecord(payload, "WordPress response must be a JSON object");
|
|
134
117
|
}
|
|
135
118
|
function headerInteger(headers, name) {
|
|
@@ -159,7 +142,7 @@ function assertNoIncludeExcludeOverlap(input) {
|
|
|
159
142
|
async function listCollection(ctx, input, path, outputKey, query) {
|
|
160
143
|
assertNoIncludeExcludeOverlap(input);
|
|
161
144
|
const response = await requestResponse(ctx, { path, query });
|
|
162
|
-
const payload =
|
|
145
|
+
const payload = jsonPayload(response.data, response.bodyKind);
|
|
163
146
|
if (!Array.isArray(payload)) {
|
|
164
147
|
throw upstreamError(502, "WordPress list response must be an array");
|
|
165
148
|
}
|
|
@@ -194,15 +177,15 @@ async function deleteResource(ctx, input, collectionPath) {
|
|
|
194
177
|
return {
|
|
195
178
|
// 上游只认 `deleted === true`:少了这一步,"移入回收站"会被当成删除成功。
|
|
196
179
|
deleted: payload.deleted === true,
|
|
197
|
-
previous:
|
|
180
|
+
previous: asJsonObject(payload.previous) ?? null
|
|
198
181
|
};
|
|
199
182
|
}
|
|
200
183
|
function getCurrentUser(_input, ctx) {
|
|
201
184
|
return requestObject(ctx, { path: CURRENT_USER_PATH, query: { context: "edit" } }).then((user) => ({ user }));
|
|
202
185
|
}
|
|
203
186
|
function listPosts(input, ctx) {
|
|
204
|
-
return listCollection(ctx, input, "/posts", "posts",
|
|
205
|
-
search:
|
|
187
|
+
return listCollection(ctx, input, "/posts", "posts", compactDefined({
|
|
188
|
+
search: trimmedText(input.search),
|
|
206
189
|
status: list(input.status),
|
|
207
190
|
categories: list(input.categories),
|
|
208
191
|
tags: list(input.tags),
|
|
@@ -212,24 +195,24 @@ function listPosts(input, ctx) {
|
|
|
212
195
|
slug: list(input.slug),
|
|
213
196
|
per_page: input.perPage,
|
|
214
197
|
page: input.page,
|
|
215
|
-
order:
|
|
216
|
-
orderby:
|
|
198
|
+
order: trimmedText(input.order),
|
|
199
|
+
orderby: trimmedText(input.orderby)
|
|
217
200
|
}));
|
|
218
201
|
}
|
|
219
202
|
function getPost(input, ctx) {
|
|
220
203
|
return getResource(ctx, input, "/posts", "post");
|
|
221
204
|
}
|
|
222
205
|
function postBody(input) {
|
|
223
|
-
return
|
|
224
|
-
title:
|
|
225
|
-
content:
|
|
226
|
-
excerpt:
|
|
227
|
-
slug:
|
|
228
|
-
status:
|
|
206
|
+
return compactDefined({
|
|
207
|
+
title: trimmedText(input.title),
|
|
208
|
+
content: trimmedText(input.content),
|
|
209
|
+
excerpt: trimmedText(input.excerpt),
|
|
210
|
+
slug: trimmedText(input.slug),
|
|
211
|
+
status: trimmedText(input.status),
|
|
229
212
|
categories: list(input.categories),
|
|
230
213
|
tags: list(input.tags),
|
|
231
214
|
featured_media: input.featuredMedia,
|
|
232
|
-
meta:
|
|
215
|
+
meta: asJsonObject(input.meta)
|
|
233
216
|
});
|
|
234
217
|
}
|
|
235
218
|
function createPost(input, ctx) {
|
|
@@ -242,8 +225,8 @@ function deletePost(input, ctx) {
|
|
|
242
225
|
return deleteResource(ctx, input, "/posts");
|
|
243
226
|
}
|
|
244
227
|
function listPages(input, ctx) {
|
|
245
|
-
return listCollection(ctx, input, "/pages", "pages",
|
|
246
|
-
search:
|
|
228
|
+
return listCollection(ctx, input, "/pages", "pages", compactDefined({
|
|
229
|
+
search: trimmedText(input.search),
|
|
247
230
|
status: list(input.status),
|
|
248
231
|
include: list(input.include),
|
|
249
232
|
exclude: list(input.exclude),
|
|
@@ -252,24 +235,24 @@ function listPages(input, ctx) {
|
|
|
252
235
|
slug: list(input.slug),
|
|
253
236
|
per_page: input.perPage,
|
|
254
237
|
page: input.page,
|
|
255
|
-
order:
|
|
256
|
-
orderby:
|
|
238
|
+
order: trimmedText(input.order),
|
|
239
|
+
orderby: trimmedText(input.orderby)
|
|
257
240
|
}));
|
|
258
241
|
}
|
|
259
242
|
function getPage(input, ctx) {
|
|
260
243
|
return getResource(ctx, input, "/pages", "page");
|
|
261
244
|
}
|
|
262
245
|
function pageBody(input) {
|
|
263
|
-
return
|
|
264
|
-
title:
|
|
265
|
-
content:
|
|
266
|
-
excerpt:
|
|
267
|
-
slug:
|
|
268
|
-
status:
|
|
246
|
+
return compactDefined({
|
|
247
|
+
title: trimmedText(input.title),
|
|
248
|
+
content: trimmedText(input.content),
|
|
249
|
+
excerpt: trimmedText(input.excerpt),
|
|
250
|
+
slug: trimmedText(input.slug),
|
|
251
|
+
status: trimmedText(input.status),
|
|
269
252
|
parent: input.parent,
|
|
270
253
|
featured_media: input.featuredMedia,
|
|
271
254
|
menu_order: input.menuOrder,
|
|
272
|
-
meta:
|
|
255
|
+
meta: asJsonObject(input.meta)
|
|
273
256
|
});
|
|
274
257
|
}
|
|
275
258
|
function createPage(input, ctx) {
|
|
@@ -282,8 +265,8 @@ function deletePage(input, ctx) {
|
|
|
282
265
|
return deleteResource(ctx, input, "/pages");
|
|
283
266
|
}
|
|
284
267
|
function termListQuery(input) {
|
|
285
|
-
return
|
|
286
|
-
search:
|
|
268
|
+
return compactDefined({
|
|
269
|
+
search: trimmedText(input.search),
|
|
287
270
|
include: list(input.include),
|
|
288
271
|
exclude: list(input.exclude),
|
|
289
272
|
// term 的 parent 是**单个** ID(post/page/comment 那边才是数组)。
|
|
@@ -292,17 +275,17 @@ function termListQuery(input) {
|
|
|
292
275
|
hide_empty: input.hideEmpty,
|
|
293
276
|
per_page: input.perPage,
|
|
294
277
|
page: input.page,
|
|
295
|
-
order:
|
|
296
|
-
orderby:
|
|
278
|
+
order: trimmedText(input.order),
|
|
279
|
+
orderby: trimmedText(input.orderby)
|
|
297
280
|
});
|
|
298
281
|
}
|
|
299
282
|
function termBody(input) {
|
|
300
|
-
return
|
|
301
|
-
name:
|
|
302
|
-
slug:
|
|
303
|
-
description:
|
|
283
|
+
return compactDefined({
|
|
284
|
+
name: trimmedText(input.name),
|
|
285
|
+
slug: trimmedText(input.slug),
|
|
286
|
+
description: trimmedText(input.description),
|
|
304
287
|
parent: input.parent,
|
|
305
|
-
meta:
|
|
288
|
+
meta: asJsonObject(input.meta)
|
|
306
289
|
});
|
|
307
290
|
}
|
|
308
291
|
function listCategories(input, ctx) {
|
|
@@ -318,8 +301,8 @@ function createTag(input, ctx) {
|
|
|
318
301
|
return createResource(ctx, "/tags", "tag", termBody(input));
|
|
319
302
|
}
|
|
320
303
|
function listComments(input, ctx) {
|
|
321
|
-
return listCollection(ctx, input, "/comments", "comments",
|
|
322
|
-
search:
|
|
304
|
+
return listCollection(ctx, input, "/comments", "comments", compactDefined({
|
|
305
|
+
search: trimmedText(input.search),
|
|
323
306
|
status: list(input.status),
|
|
324
307
|
post: list(input.post),
|
|
325
308
|
author: list(input.author),
|
|
@@ -328,17 +311,17 @@ function listComments(input, ctx) {
|
|
|
328
311
|
exclude: list(input.exclude),
|
|
329
312
|
per_page: input.perPage,
|
|
330
313
|
page: input.page,
|
|
331
|
-
order:
|
|
332
|
-
orderby:
|
|
314
|
+
order: trimmedText(input.order),
|
|
315
|
+
orderby: trimmedText(input.orderby)
|
|
333
316
|
}));
|
|
334
317
|
}
|
|
335
318
|
function updateComment(input, ctx) {
|
|
336
|
-
return updateResource(ctx, input, "/comments", "comment",
|
|
337
|
-
content:
|
|
338
|
-
status:
|
|
339
|
-
author_name:
|
|
340
|
-
author_email:
|
|
341
|
-
author_url:
|
|
319
|
+
return updateResource(ctx, input, "/comments", "comment", compactDefined({
|
|
320
|
+
content: trimmedText(input.content),
|
|
321
|
+
status: trimmedText(input.status),
|
|
322
|
+
author_name: trimmedText(input.authorName),
|
|
323
|
+
author_email: trimmedText(input.authorEmail),
|
|
324
|
+
author_url: trimmedText(input.authorUrl)
|
|
342
325
|
}));
|
|
343
326
|
}
|
|
344
327
|
function deleteComment(input, ctx) {
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-VLOIDU5U.js";
|
|
4
|
+
import {
|
|
5
|
+
compactDefined
|
|
6
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
7
|
import {
|
|
2
8
|
createProviderPlugin,
|
|
3
9
|
requireApiKey,
|
|
4
10
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
11
|
+
} from "./chunk-B4P6YZFS.js";
|
|
12
|
+
import "./chunk-SWBNHIO4.js";
|
|
10
13
|
import {
|
|
11
14
|
TBError,
|
|
12
15
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-OKRZPQ3R.js";
|
|
17
|
+
import "./chunk-U67V476Y.js";
|
|
15
18
|
|
|
16
19
|
// ../plugins/src/workos/api.ts
|
|
17
20
|
var SERVICE = "workos";
|
|
18
21
|
var API_BASE = "https://api.workos.com";
|
|
22
|
+
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
19
23
|
function errorMessage(payload, status) {
|
|
20
24
|
const error = payload.error;
|
|
21
25
|
if (error !== null && typeof error === "object" && !Array.isArray(error)) {
|
|
@@ -29,51 +33,35 @@ function errorMessage(payload, status) {
|
|
|
29
33
|
}
|
|
30
34
|
async function request(ctx, input) {
|
|
31
35
|
const apiKey = requireApiKey(ctx, SERVICE);
|
|
32
|
-
const url = new URL(input.path, API_BASE);
|
|
33
|
-
for (const [key, value] of Object.entries(input.query ?? {})) {
|
|
34
|
-
if (value === void 0) continue;
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
for (const item of value) url.searchParams.append(key, item);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
url.searchParams.set(key, String(value));
|
|
40
|
-
}
|
|
41
36
|
const headers = {
|
|
42
37
|
accept: "application/json",
|
|
43
38
|
authorization: `Bearer ${apiKey}`
|
|
44
39
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
40
|
+
const response = await http.request({
|
|
41
|
+
method: input.method,
|
|
42
|
+
path: input.path,
|
|
43
|
+
// 多值过滤是重复同名键(与 Render 的逗号拼接不同)。
|
|
44
|
+
query: Object.entries(input.query ?? {}),
|
|
45
|
+
headers,
|
|
46
|
+
...input.body === void 0 ? {} : { json: input.body },
|
|
47
|
+
invalidJsonMessage: "WorkOS \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON",
|
|
48
|
+
mapError: ({ bodyKind, data, status }) => {
|
|
49
|
+
if (bodyKind === "invalid-json") {
|
|
50
|
+
return new TBError("unavailable", "WorkOS \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON", { retryable: true });
|
|
51
|
+
}
|
|
52
|
+
const payload2 = bodyKind === "empty" ? {} : data !== null && typeof data === "object" && !Array.isArray(data) ? data : void 0;
|
|
53
|
+
return payload2 === void 0 ? new TBError("unavailable", "WorkOS \u8FD4\u56DE\u7684\u4E0D\u662F JSON \u5BF9\u8C61", { retryable: true }) : upstreamError(status, errorMessage(payload2, status));
|
|
54
|
+
},
|
|
55
|
+
mapTransportError: ({ message }) => new TBError(
|
|
58
56
|
"unavailable",
|
|
59
|
-
|
|
57
|
+
message === void 0 ? "WorkOS \u8BF7\u6C42\u5931\u8D25" : `WorkOS \u8BF7\u6C42\u5931\u8D25: ${message}`,
|
|
60
58
|
{ retryable: true }
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
parsed = JSON.parse(text);
|
|
68
|
-
} catch {
|
|
69
|
-
throw new TBError("unavailable", "WorkOS \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON", { retryable: true });
|
|
70
|
-
}
|
|
71
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
72
|
-
throw new TBError("unavailable", "WorkOS \u8FD4\u56DE\u7684\u4E0D\u662F JSON \u5BF9\u8C61", { retryable: true });
|
|
73
|
-
}
|
|
74
|
-
payload = parsed;
|
|
59
|
+
)
|
|
60
|
+
});
|
|
61
|
+
const payload = response.bodyKind === "empty" ? {} : response.data !== null && typeof response.data === "object" && !Array.isArray(response.data) ? response.data : void 0;
|
|
62
|
+
if (payload === void 0) {
|
|
63
|
+
throw new TBError("unavailable", "WorkOS \u8FD4\u56DE\u7684\u4E0D\u662F JSON \u5BF9\u8C61", { retryable: true });
|
|
75
64
|
}
|
|
76
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
|
|
77
65
|
return payload;
|
|
78
66
|
}
|
|
79
67
|
function unwrap(payload, key) {
|
|
@@ -97,15 +85,8 @@ async function wrappedAction(ctx, input, wrapperKey) {
|
|
|
97
85
|
const payload = await request(ctx, input);
|
|
98
86
|
return { [wrapperKey]: unwrap(payload, wrapperKey), raw: payload };
|
|
99
87
|
}
|
|
100
|
-
function compact(input) {
|
|
101
|
-
const output = {};
|
|
102
|
-
for (const [key, value] of Object.entries(input)) {
|
|
103
|
-
if (value !== void 0) output[key] = value;
|
|
104
|
-
}
|
|
105
|
-
return output;
|
|
106
|
-
}
|
|
107
88
|
function userBody(input) {
|
|
108
|
-
return
|
|
89
|
+
return compactDefined({
|
|
109
90
|
email: input.email,
|
|
110
91
|
first_name: input.first_name,
|
|
111
92
|
last_name: input.last_name,
|
|
@@ -117,7 +98,7 @@ function userBody(input) {
|
|
|
117
98
|
});
|
|
118
99
|
}
|
|
119
100
|
function organizationBody(input) {
|
|
120
|
-
return
|
|
101
|
+
return compactDefined({
|
|
121
102
|
name: input.name,
|
|
122
103
|
allow_profiles_outside_organization: input.allow_profiles_outside_organization,
|
|
123
104
|
domain_data: input.domain_data,
|
|
@@ -222,7 +203,7 @@ async function createOrganizationMembership(input, ctx) {
|
|
|
222
203
|
{
|
|
223
204
|
method: "POST",
|
|
224
205
|
path: "/user_management/organization_memberships",
|
|
225
|
-
body:
|
|
206
|
+
body: compactDefined({
|
|
226
207
|
user_id: input.user_id,
|
|
227
208
|
organization_id: input.organization_id,
|
|
228
209
|
role_slug: input.role_slug,
|
|
@@ -238,7 +219,7 @@ async function updateOrganizationMembership(input, ctx) {
|
|
|
238
219
|
{
|
|
239
220
|
method: "PUT",
|
|
240
221
|
path: `/user_management/organization_memberships/${encodeURIComponent(input.id)}`,
|
|
241
|
-
body:
|
|
222
|
+
body: compactDefined({ role_slug: input.role_slug, role_slugs: input.role_slugs })
|
|
242
223
|
},
|
|
243
224
|
"organization_membership"
|
|
244
225
|
);
|