@unkey/api 2.1.0 → 2.1.2
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/README.md +10 -6
- package/bin/mcp-server.js +806 -347
- package/bin/mcp-server.js.map +26 -13
- package/dist/commonjs/funcs/keysMigrateKeys.d.ts +23 -0
- package/dist/commonjs/funcs/keysMigrateKeys.d.ts.map +1 -0
- package/dist/commonjs/funcs/keysMigrateKeys.js +133 -0
- package/dist/commonjs/funcs/keysMigrateKeys.js.map +1 -0
- package/dist/commonjs/funcs/ratelimitLimit.d.ts +0 -4
- package/dist/commonjs/funcs/ratelimitLimit.d.ts.map +1 -1
- package/dist/commonjs/funcs/ratelimitLimit.js +0 -4
- package/dist/commonjs/funcs/ratelimitLimit.js.map +1 -1
- package/dist/commonjs/funcs/ratelimitMultiLimit.d.ts +28 -0
- package/dist/commonjs/funcs/ratelimitMultiLimit.d.ts.map +1 -0
- package/dist/commonjs/funcs/ratelimitMultiLimit.js +139 -0
- package/dist/commonjs/funcs/ratelimitMultiLimit.js.map +1 -0
- package/dist/commonjs/hooks/custom/vercel-edge-fetcher.d.ts +5 -0
- package/dist/commonjs/hooks/custom/vercel-edge-fetcher.d.ts.map +1 -0
- package/dist/commonjs/hooks/custom/vercel-edge-fetcher.js +63 -0
- package/dist/commonjs/hooks/custom/vercel-edge-fetcher.js.map +1 -0
- package/dist/commonjs/hooks/registration.d.ts.map +1 -1
- package/dist/commonjs/hooks/registration.js +3 -4
- package/dist/commonjs/hooks/registration.js.map +1 -1
- package/dist/commonjs/lib/config.d.ts +3 -3
- package/dist/commonjs/lib/config.js +3 -3
- package/dist/commonjs/mcp-server/mcp-server.js +1 -1
- package/dist/commonjs/mcp-server/server.d.ts.map +1 -1
- package/dist/commonjs/mcp-server/server.js +5 -1
- package/dist/commonjs/mcp-server/server.js.map +1 -1
- package/dist/commonjs/mcp-server/tools/keysMigrateKeys.d.ts +8 -0
- package/dist/commonjs/mcp-server/tools/keysMigrateKeys.d.ts.map +1 -0
- package/dist/commonjs/mcp-server/tools/keysMigrateKeys.js +70 -0
- package/dist/commonjs/mcp-server/tools/keysMigrateKeys.js.map +1 -0
- package/dist/commonjs/mcp-server/tools/ratelimitLimit.d.ts.map +1 -1
- package/dist/commonjs/mcp-server/tools/ratelimitLimit.js +0 -4
- package/dist/commonjs/mcp-server/tools/ratelimitLimit.js.map +1 -1
- package/dist/commonjs/mcp-server/tools/ratelimitMultiLimit.d.ts +9 -0
- package/dist/commonjs/mcp-server/tools/ratelimitMultiLimit.d.ts.map +1 -0
- package/dist/commonjs/mcp-server/tools/ratelimitMultiLimit.js +76 -0
- package/dist/commonjs/mcp-server/tools/ratelimitMultiLimit.js.map +1 -0
- package/dist/commonjs/models/components/index.d.ts +8 -0
- package/dist/commonjs/models/components/index.d.ts.map +1 -1
- package/dist/commonjs/models/components/index.js +8 -0
- package/dist/commonjs/models/components/index.js.map +1 -1
- package/dist/commonjs/models/components/v2keysmigratekeydata.d.ts +113 -0
- package/dist/commonjs/models/components/v2keysmigratekeydata.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeydata.js +78 -0
- package/dist/commonjs/models/components/v2keysmigratekeydata.js.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysmigration.d.ts +25 -0
- package/dist/commonjs/models/components/v2keysmigratekeysmigration.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysmigration.js +60 -0
- package/dist/commonjs/models/components/v2keysmigratekeysmigration.js.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysrequestbody.d.ts +28 -0
- package/dist/commonjs/models/components/v2keysmigratekeysrequestbody.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysrequestbody.js +63 -0
- package/dist/commonjs/models/components/v2keysmigratekeysrequestbody.js.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsebody.d.ts +24 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsebody.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsebody.js +62 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsebody.js.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsedata.d.ts +26 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsedata.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsedata.js +61 -0
- package/dist/commonjs/models/components/v2keysmigratekeysresponsedata.js.map +1 -0
- package/dist/commonjs/models/components/v2keysverifykeyrequestbody.d.ts +5 -0
- package/dist/commonjs/models/components/v2keysverifykeyrequestbody.d.ts.map +1 -1
- package/dist/commonjs/models/components/v2keysverifykeyrequestbody.js +2 -0
- package/dist/commonjs/models/components/v2keysverifykeyrequestbody.js.map +1 -1
- package/dist/commonjs/models/components/v2keysverifykeyresponsedata.d.ts +3 -3
- package/dist/commonjs/models/components/v2ratelimitmultilimitcheck.d.ts +84 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitcheck.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitcheck.js +70 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitcheck.js.map +1 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsebody.d.ts +27 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsebody.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsebody.js +62 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsebody.js.map +1 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsedata.d.ts +33 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsedata.d.ts.map +1 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsedata.js +61 -0
- package/dist/commonjs/models/components/v2ratelimitmultilimitresponsedata.js.map +1 -0
- package/dist/commonjs/sdk/keys.d.ts +12 -0
- package/dist/commonjs/sdk/keys.d.ts.map +1 -1
- package/dist/commonjs/sdk/keys.js +15 -0
- package/dist/commonjs/sdk/keys.js.map +1 -1
- package/dist/commonjs/sdk/ratelimit.d.ts +17 -4
- package/dist/commonjs/sdk/ratelimit.d.ts.map +1 -1
- package/dist/commonjs/sdk/ratelimit.js +20 -4
- package/dist/commonjs/sdk/ratelimit.js.map +1 -1
- package/dist/commonjs/types/enums.d.ts +10 -6
- package/dist/commonjs/types/enums.d.ts.map +1 -1
- package/dist/commonjs/types/enums.js +76 -2
- package/dist/commonjs/types/enums.js.map +1 -1
- package/dist/commonjs/types/index.d.ts +0 -1
- package/dist/commonjs/types/index.d.ts.map +1 -1
- package/dist/commonjs/types/index.js +1 -3
- package/dist/commonjs/types/index.js.map +1 -1
- package/dist/esm/funcs/keysMigrateKeys.d.ts +23 -0
- package/dist/esm/funcs/keysMigrateKeys.d.ts.map +1 -0
- package/dist/esm/funcs/keysMigrateKeys.js +97 -0
- package/dist/esm/funcs/keysMigrateKeys.js.map +1 -0
- package/dist/esm/funcs/ratelimitLimit.d.ts +0 -4
- package/dist/esm/funcs/ratelimitLimit.d.ts.map +1 -1
- package/dist/esm/funcs/ratelimitLimit.js +0 -4
- package/dist/esm/funcs/ratelimitLimit.js.map +1 -1
- package/dist/esm/funcs/ratelimitMultiLimit.d.ts +28 -0
- package/dist/esm/funcs/ratelimitMultiLimit.d.ts.map +1 -0
- package/dist/esm/funcs/ratelimitMultiLimit.js +103 -0
- package/dist/esm/funcs/ratelimitMultiLimit.js.map +1 -0
- package/dist/esm/hooks/custom/vercel-edge-fetcher.d.ts +5 -0
- package/dist/esm/hooks/custom/vercel-edge-fetcher.d.ts.map +1 -0
- package/dist/esm/hooks/custom/vercel-edge-fetcher.js +59 -0
- package/dist/esm/hooks/custom/vercel-edge-fetcher.js.map +1 -0
- package/dist/esm/hooks/registration.d.ts.map +1 -1
- package/dist/esm/hooks/registration.js +3 -4
- package/dist/esm/hooks/registration.js.map +1 -1
- package/dist/esm/lib/config.d.ts +3 -3
- package/dist/esm/lib/config.js +3 -3
- package/dist/esm/mcp-server/mcp-server.js +1 -1
- package/dist/esm/mcp-server/server.d.ts.map +1 -1
- package/dist/esm/mcp-server/server.js +5 -1
- package/dist/esm/mcp-server/server.js.map +1 -1
- package/dist/esm/mcp-server/tools/keysMigrateKeys.d.ts +8 -0
- package/dist/esm/mcp-server/tools/keysMigrateKeys.d.ts.map +1 -0
- package/dist/esm/mcp-server/tools/keysMigrateKeys.js +34 -0
- package/dist/esm/mcp-server/tools/keysMigrateKeys.js.map +1 -0
- package/dist/esm/mcp-server/tools/ratelimitLimit.d.ts.map +1 -1
- package/dist/esm/mcp-server/tools/ratelimitLimit.js +0 -4
- package/dist/esm/mcp-server/tools/ratelimitLimit.js.map +1 -1
- package/dist/esm/mcp-server/tools/ratelimitMultiLimit.d.ts +9 -0
- package/dist/esm/mcp-server/tools/ratelimitMultiLimit.d.ts.map +1 -0
- package/dist/esm/mcp-server/tools/ratelimitMultiLimit.js +40 -0
- package/dist/esm/mcp-server/tools/ratelimitMultiLimit.js.map +1 -0
- package/dist/esm/models/components/index.d.ts +8 -0
- package/dist/esm/models/components/index.d.ts.map +1 -1
- package/dist/esm/models/components/index.js +8 -0
- package/dist/esm/models/components/index.js.map +1 -1
- package/dist/esm/models/components/v2keysmigratekeydata.d.ts +113 -0
- package/dist/esm/models/components/v2keysmigratekeydata.d.ts.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeydata.js +40 -0
- package/dist/esm/models/components/v2keysmigratekeydata.js.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysmigration.d.ts +25 -0
- package/dist/esm/models/components/v2keysmigratekeysmigration.d.ts.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysmigration.js +22 -0
- package/dist/esm/models/components/v2keysmigratekeysmigration.js.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysrequestbody.d.ts +28 -0
- package/dist/esm/models/components/v2keysmigratekeysrequestbody.d.ts.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysrequestbody.js +25 -0
- package/dist/esm/models/components/v2keysmigratekeysrequestbody.js.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsebody.d.ts +24 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsebody.d.ts.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsebody.js +24 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsebody.js.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsedata.d.ts +26 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsedata.d.ts.map +1 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsedata.js +23 -0
- package/dist/esm/models/components/v2keysmigratekeysresponsedata.js.map +1 -0
- package/dist/esm/models/components/v2keysverifykeyrequestbody.d.ts +5 -0
- package/dist/esm/models/components/v2keysverifykeyrequestbody.d.ts.map +1 -1
- package/dist/esm/models/components/v2keysverifykeyrequestbody.js +2 -0
- package/dist/esm/models/components/v2keysverifykeyrequestbody.js.map +1 -1
- package/dist/esm/models/components/v2keysverifykeyresponsedata.d.ts +3 -3
- package/dist/esm/models/components/v2ratelimitmultilimitcheck.d.ts +84 -0
- package/dist/esm/models/components/v2ratelimitmultilimitcheck.d.ts.map +1 -0
- package/dist/esm/models/components/v2ratelimitmultilimitcheck.js +32 -0
- package/dist/esm/models/components/v2ratelimitmultilimitcheck.js.map +1 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsebody.d.ts +27 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsebody.d.ts.map +1 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsebody.js +24 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsebody.js.map +1 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsedata.d.ts +33 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsedata.d.ts.map +1 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsedata.js +23 -0
- package/dist/esm/models/components/v2ratelimitmultilimitresponsedata.js.map +1 -0
- package/dist/esm/sdk/keys.d.ts +12 -0
- package/dist/esm/sdk/keys.d.ts.map +1 -1
- package/dist/esm/sdk/keys.js +15 -0
- package/dist/esm/sdk/keys.js.map +1 -1
- package/dist/esm/sdk/ratelimit.d.ts +17 -4
- package/dist/esm/sdk/ratelimit.d.ts.map +1 -1
- package/dist/esm/sdk/ratelimit.js +20 -4
- package/dist/esm/sdk/ratelimit.js.map +1 -1
- package/dist/esm/types/enums.d.ts +10 -6
- package/dist/esm/types/enums.d.ts.map +1 -1
- package/dist/esm/types/enums.js +38 -1
- package/dist/esm/types/enums.js.map +1 -1
- package/dist/esm/types/index.d.ts +0 -1
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/types/index.js.map +1 -1
- package/examples/package-lock.json +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/funcs/keysMigrateKeys.ts +201 -0
- package/src/funcs/ratelimitLimit.ts +0 -4
- package/src/funcs/ratelimitMultiLimit.ts +213 -0
- package/src/hooks/custom/vercel-edge-fetcher.ts +64 -0
- package/src/hooks/registration.ts +3 -4
- package/src/lib/config.ts +3 -3
- package/src/mcp-server/mcp-server.ts +1 -1
- package/src/mcp-server/server.ts +5 -1
- package/src/mcp-server/tools/keysMigrateKeys.ts +43 -0
- package/src/mcp-server/tools/ratelimitLimit.ts +0 -4
- package/src/mcp-server/tools/ratelimitMultiLimit.ts +49 -0
- package/src/models/components/index.ts +8 -0
- package/src/models/components/v2keysmigratekeydata.ts +171 -0
- package/src/models/components/v2keysmigratekeysmigration.ts +61 -0
- package/src/models/components/v2keysmigratekeysrequestbody.ts +73 -0
- package/src/models/components/v2keysmigratekeysresponsebody.ts +72 -0
- package/src/models/components/v2keysmigratekeysresponsedata.ts +69 -0
- package/src/models/components/v2keysverifykeyrequestbody.ts +7 -0
- package/src/models/components/v2keysverifykeyresponsedata.ts +3 -3
- package/src/models/components/v2ratelimitmultilimitcheck.ts +130 -0
- package/src/models/components/v2ratelimitmultilimitresponsebody.ts +75 -0
- package/src/models/components/v2ratelimitmultilimitresponsedata.ts +76 -0
- package/src/sdk/keys.ts +23 -0
- package/src/sdk/ratelimit.ts +28 -4
- package/src/types/enums.ts +55 -6
- package/src/types/index.ts +0 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { UnkeyCore } from "../core.js";
|
|
6
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
7
|
+
import * as M from "../lib/matchers.js";
|
|
8
|
+
import { compactMap } from "../lib/primitives.js";
|
|
9
|
+
import { safeParse } from "../lib/schemas.js";
|
|
10
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
12
|
+
import { pathToFunc } from "../lib/url.js";
|
|
13
|
+
import * as components from "../models/components/index.js";
|
|
14
|
+
import {
|
|
15
|
+
ConnectionError,
|
|
16
|
+
InvalidRequestError,
|
|
17
|
+
RequestAbortedError,
|
|
18
|
+
RequestTimeoutError,
|
|
19
|
+
UnexpectedClientError,
|
|
20
|
+
} from "../models/errors/httpclienterrors.js";
|
|
21
|
+
import * as errors from "../models/errors/index.js";
|
|
22
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
23
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
24
|
+
import { UnkeyError } from "../models/errors/unkeyerror.js";
|
|
25
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
26
|
+
import { Result } from "../types/fp.js";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Migrate API key(s)
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Returns HTTP 200 even on partial success; hashes that could not be migrated are listed under `data.failed`.
|
|
33
|
+
*
|
|
34
|
+
* **Required Permissions**
|
|
35
|
+
* Your root key must have one of the following permissions for basic key information:
|
|
36
|
+
* - `api.*.create_key` (to migrate keys to any API)
|
|
37
|
+
* - `api.<api_id>.create_key` (to migrate keys to a specific API)
|
|
38
|
+
*/
|
|
39
|
+
export function keysMigrateKeys(
|
|
40
|
+
client: UnkeyCore,
|
|
41
|
+
request: components.V2KeysMigrateKeysRequestBody,
|
|
42
|
+
options?: RequestOptions,
|
|
43
|
+
): APIPromise<
|
|
44
|
+
Result<
|
|
45
|
+
components.V2KeysMigrateKeysResponseBody,
|
|
46
|
+
| errors.BadRequestErrorResponse
|
|
47
|
+
| errors.UnauthorizedErrorResponse
|
|
48
|
+
| errors.ForbiddenErrorResponse
|
|
49
|
+
| errors.NotFoundErrorResponse
|
|
50
|
+
| errors.InternalServerErrorResponse
|
|
51
|
+
| UnkeyError
|
|
52
|
+
| ResponseValidationError
|
|
53
|
+
| ConnectionError
|
|
54
|
+
| RequestAbortedError
|
|
55
|
+
| RequestTimeoutError
|
|
56
|
+
| InvalidRequestError
|
|
57
|
+
| UnexpectedClientError
|
|
58
|
+
| SDKValidationError
|
|
59
|
+
>
|
|
60
|
+
> {
|
|
61
|
+
return new APIPromise($do(
|
|
62
|
+
client,
|
|
63
|
+
request,
|
|
64
|
+
options,
|
|
65
|
+
));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function $do(
|
|
69
|
+
client: UnkeyCore,
|
|
70
|
+
request: components.V2KeysMigrateKeysRequestBody,
|
|
71
|
+
options?: RequestOptions,
|
|
72
|
+
): Promise<
|
|
73
|
+
[
|
|
74
|
+
Result<
|
|
75
|
+
components.V2KeysMigrateKeysResponseBody,
|
|
76
|
+
| errors.BadRequestErrorResponse
|
|
77
|
+
| errors.UnauthorizedErrorResponse
|
|
78
|
+
| errors.ForbiddenErrorResponse
|
|
79
|
+
| errors.NotFoundErrorResponse
|
|
80
|
+
| errors.InternalServerErrorResponse
|
|
81
|
+
| UnkeyError
|
|
82
|
+
| ResponseValidationError
|
|
83
|
+
| ConnectionError
|
|
84
|
+
| RequestAbortedError
|
|
85
|
+
| RequestTimeoutError
|
|
86
|
+
| InvalidRequestError
|
|
87
|
+
| UnexpectedClientError
|
|
88
|
+
| SDKValidationError
|
|
89
|
+
>,
|
|
90
|
+
APICall,
|
|
91
|
+
]
|
|
92
|
+
> {
|
|
93
|
+
const parsed = safeParse(
|
|
94
|
+
request,
|
|
95
|
+
(value) =>
|
|
96
|
+
components.V2KeysMigrateKeysRequestBody$outboundSchema.parse(value),
|
|
97
|
+
"Input validation failed",
|
|
98
|
+
);
|
|
99
|
+
if (!parsed.ok) {
|
|
100
|
+
return [parsed, { status: "invalid" }];
|
|
101
|
+
}
|
|
102
|
+
const payload = parsed.value;
|
|
103
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
104
|
+
|
|
105
|
+
const path = pathToFunc("/v2/keys.migrateKeys")();
|
|
106
|
+
|
|
107
|
+
const headers = new Headers(compactMap({
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
Accept: "application/json",
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
const secConfig = await extractSecurity(client._options.rootKey);
|
|
113
|
+
const securityInput = secConfig == null ? {} : { rootKey: secConfig };
|
|
114
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
115
|
+
|
|
116
|
+
const context = {
|
|
117
|
+
options: client._options,
|
|
118
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
119
|
+
operationID: "migrateKeys",
|
|
120
|
+
oAuth2Scopes: null,
|
|
121
|
+
|
|
122
|
+
resolvedSecurity: requestSecurity,
|
|
123
|
+
|
|
124
|
+
securitySource: client._options.rootKey,
|
|
125
|
+
retryConfig: options?.retries
|
|
126
|
+
|| client._options.retryConfig
|
|
127
|
+
|| {
|
|
128
|
+
strategy: "backoff",
|
|
129
|
+
backoff: {
|
|
130
|
+
initialInterval: 50,
|
|
131
|
+
maxInterval: 1000,
|
|
132
|
+
exponent: 1.5,
|
|
133
|
+
maxElapsedTime: 10000,
|
|
134
|
+
},
|
|
135
|
+
retryConnectionErrors: true,
|
|
136
|
+
}
|
|
137
|
+
|| { strategy: "none" },
|
|
138
|
+
retryCodes: options?.retryCodes || ["5XX"],
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const requestRes = client._createRequest(context, {
|
|
142
|
+
security: requestSecurity,
|
|
143
|
+
method: "POST",
|
|
144
|
+
baseURL: options?.serverURL,
|
|
145
|
+
path: path,
|
|
146
|
+
headers: headers,
|
|
147
|
+
body: body,
|
|
148
|
+
userAgent: client._options.userAgent,
|
|
149
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
150
|
+
}, options);
|
|
151
|
+
if (!requestRes.ok) {
|
|
152
|
+
return [requestRes, { status: "invalid" }];
|
|
153
|
+
}
|
|
154
|
+
const req = requestRes.value;
|
|
155
|
+
|
|
156
|
+
const doResult = await client._do(req, {
|
|
157
|
+
context,
|
|
158
|
+
errorCodes: ["400", "401", "403", "404", "4XX", "500", "5XX"],
|
|
159
|
+
retryConfig: context.retryConfig,
|
|
160
|
+
retryCodes: context.retryCodes,
|
|
161
|
+
});
|
|
162
|
+
if (!doResult.ok) {
|
|
163
|
+
return [doResult, { status: "request-error", request: req }];
|
|
164
|
+
}
|
|
165
|
+
const response = doResult.value;
|
|
166
|
+
|
|
167
|
+
const responseFields = {
|
|
168
|
+
HttpMeta: { Response: response, Request: req },
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const [result] = await M.match<
|
|
172
|
+
components.V2KeysMigrateKeysResponseBody,
|
|
173
|
+
| errors.BadRequestErrorResponse
|
|
174
|
+
| errors.UnauthorizedErrorResponse
|
|
175
|
+
| errors.ForbiddenErrorResponse
|
|
176
|
+
| errors.NotFoundErrorResponse
|
|
177
|
+
| errors.InternalServerErrorResponse
|
|
178
|
+
| UnkeyError
|
|
179
|
+
| ResponseValidationError
|
|
180
|
+
| ConnectionError
|
|
181
|
+
| RequestAbortedError
|
|
182
|
+
| RequestTimeoutError
|
|
183
|
+
| InvalidRequestError
|
|
184
|
+
| UnexpectedClientError
|
|
185
|
+
| SDKValidationError
|
|
186
|
+
>(
|
|
187
|
+
M.json(200, components.V2KeysMigrateKeysResponseBody$inboundSchema),
|
|
188
|
+
M.jsonErr(400, errors.BadRequestErrorResponse$inboundSchema),
|
|
189
|
+
M.jsonErr(401, errors.UnauthorizedErrorResponse$inboundSchema),
|
|
190
|
+
M.jsonErr(403, errors.ForbiddenErrorResponse$inboundSchema),
|
|
191
|
+
M.jsonErr(404, errors.NotFoundErrorResponse$inboundSchema),
|
|
192
|
+
M.jsonErr(500, errors.InternalServerErrorResponse$inboundSchema),
|
|
193
|
+
M.fail("4XX"),
|
|
194
|
+
M.fail("5XX"),
|
|
195
|
+
)(response, req, { extraFields: responseFields });
|
|
196
|
+
if (!result.ok) {
|
|
197
|
+
return [result, { status: "complete", request: req, response }];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return [result, { status: "complete", request: req, response }];
|
|
201
|
+
}
|
|
@@ -40,10 +40,6 @@ import { Result } from "../types/fp.js";
|
|
|
40
40
|
* Your root key must have one of the following permissions:
|
|
41
41
|
* - `ratelimit.*.limit` (to check limits in any namespace)
|
|
42
42
|
* - `ratelimit.<namespace_id>.limit` (to check limits in a specific namespace)
|
|
43
|
-
*
|
|
44
|
-
* **Side Effects**
|
|
45
|
-
*
|
|
46
|
-
* Records rate limit metrics for analytics and monitoring, updates rate limit counters with sliding window algorithm, and optionally triggers override matching for custom limits.
|
|
47
43
|
*/
|
|
48
44
|
export function ratelimitLimit(
|
|
49
45
|
client: UnkeyCore,
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { UnkeyCore } from "../core.js";
|
|
7
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
13
|
+
import { pathToFunc } from "../lib/url.js";
|
|
14
|
+
import * as components from "../models/components/index.js";
|
|
15
|
+
import {
|
|
16
|
+
ConnectionError,
|
|
17
|
+
InvalidRequestError,
|
|
18
|
+
RequestAbortedError,
|
|
19
|
+
RequestTimeoutError,
|
|
20
|
+
UnexpectedClientError,
|
|
21
|
+
} from "../models/errors/httpclienterrors.js";
|
|
22
|
+
import * as errors from "../models/errors/index.js";
|
|
23
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
24
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
25
|
+
import { UnkeyError } from "../models/errors/unkeyerror.js";
|
|
26
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
27
|
+
import { Result } from "../types/fp.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Apply multiple rate limit checks
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Check and enforce multiple rate limits in a single request for any identifiers (user IDs, IP addresses, API clients, etc.).
|
|
34
|
+
*
|
|
35
|
+
* Use this to efficiently check multiple rate limits at once. Each rate limit check is independent and returns its own result with a top-level `passed` indicator showing if all checks succeeded.
|
|
36
|
+
*
|
|
37
|
+
* **Response Codes**: Rate limit checks return HTTP 200 regardless of whether limits are exceeded - check the `passed` field to see if all limits passed, or the `success` field in each individual result. 4xx responses indicate auth, namespace existence/deletion, or validation errors (e.g., 410 Gone for deleted namespaces). 5xx responses indicate server errors.
|
|
38
|
+
*
|
|
39
|
+
* **Required Permissions**
|
|
40
|
+
*
|
|
41
|
+
* Your root key must have one of the following permissions:
|
|
42
|
+
* - `ratelimit.*.limit` (to check limits in any namespace)
|
|
43
|
+
* - `ratelimit.<namespace_id>.limit` (to check limits in all specific namespaces being checked)
|
|
44
|
+
*/
|
|
45
|
+
export function ratelimitMultiLimit(
|
|
46
|
+
client: UnkeyCore,
|
|
47
|
+
request: Array<components.V2RatelimitLimitRequestBody>,
|
|
48
|
+
options?: RequestOptions,
|
|
49
|
+
): APIPromise<
|
|
50
|
+
Result<
|
|
51
|
+
components.V2RatelimitMultiLimitResponseBody,
|
|
52
|
+
| errors.BadRequestErrorResponse
|
|
53
|
+
| errors.UnauthorizedErrorResponse
|
|
54
|
+
| errors.ForbiddenErrorResponse
|
|
55
|
+
| errors.NotFoundErrorResponse
|
|
56
|
+
| errors.GoneErrorResponse
|
|
57
|
+
| errors.InternalServerErrorResponse
|
|
58
|
+
| UnkeyError
|
|
59
|
+
| ResponseValidationError
|
|
60
|
+
| ConnectionError
|
|
61
|
+
| RequestAbortedError
|
|
62
|
+
| RequestTimeoutError
|
|
63
|
+
| InvalidRequestError
|
|
64
|
+
| UnexpectedClientError
|
|
65
|
+
| SDKValidationError
|
|
66
|
+
>
|
|
67
|
+
> {
|
|
68
|
+
return new APIPromise($do(
|
|
69
|
+
client,
|
|
70
|
+
request,
|
|
71
|
+
options,
|
|
72
|
+
));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function $do(
|
|
76
|
+
client: UnkeyCore,
|
|
77
|
+
request: Array<components.V2RatelimitLimitRequestBody>,
|
|
78
|
+
options?: RequestOptions,
|
|
79
|
+
): Promise<
|
|
80
|
+
[
|
|
81
|
+
Result<
|
|
82
|
+
components.V2RatelimitMultiLimitResponseBody,
|
|
83
|
+
| errors.BadRequestErrorResponse
|
|
84
|
+
| errors.UnauthorizedErrorResponse
|
|
85
|
+
| errors.ForbiddenErrorResponse
|
|
86
|
+
| errors.NotFoundErrorResponse
|
|
87
|
+
| errors.GoneErrorResponse
|
|
88
|
+
| errors.InternalServerErrorResponse
|
|
89
|
+
| UnkeyError
|
|
90
|
+
| ResponseValidationError
|
|
91
|
+
| ConnectionError
|
|
92
|
+
| RequestAbortedError
|
|
93
|
+
| RequestTimeoutError
|
|
94
|
+
| InvalidRequestError
|
|
95
|
+
| UnexpectedClientError
|
|
96
|
+
| SDKValidationError
|
|
97
|
+
>,
|
|
98
|
+
APICall,
|
|
99
|
+
]
|
|
100
|
+
> {
|
|
101
|
+
const parsed = safeParse(
|
|
102
|
+
request,
|
|
103
|
+
(value) =>
|
|
104
|
+
z.array(components.V2RatelimitLimitRequestBody$outboundSchema).parse(
|
|
105
|
+
value,
|
|
106
|
+
),
|
|
107
|
+
"Input validation failed",
|
|
108
|
+
);
|
|
109
|
+
if (!parsed.ok) {
|
|
110
|
+
return [parsed, { status: "invalid" }];
|
|
111
|
+
}
|
|
112
|
+
const payload = parsed.value;
|
|
113
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
114
|
+
|
|
115
|
+
const path = pathToFunc("/v2/ratelimit.multiLimit")();
|
|
116
|
+
|
|
117
|
+
const headers = new Headers(compactMap({
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
Accept: "application/json",
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
const secConfig = await extractSecurity(client._options.rootKey);
|
|
123
|
+
const securityInput = secConfig == null ? {} : { rootKey: secConfig };
|
|
124
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
125
|
+
|
|
126
|
+
const context = {
|
|
127
|
+
options: client._options,
|
|
128
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
129
|
+
operationID: "ratelimit.multiLimit",
|
|
130
|
+
oAuth2Scopes: null,
|
|
131
|
+
|
|
132
|
+
resolvedSecurity: requestSecurity,
|
|
133
|
+
|
|
134
|
+
securitySource: client._options.rootKey,
|
|
135
|
+
retryConfig: options?.retries
|
|
136
|
+
|| client._options.retryConfig
|
|
137
|
+
|| {
|
|
138
|
+
strategy: "backoff",
|
|
139
|
+
backoff: {
|
|
140
|
+
initialInterval: 50,
|
|
141
|
+
maxInterval: 1000,
|
|
142
|
+
exponent: 1.5,
|
|
143
|
+
maxElapsedTime: 10000,
|
|
144
|
+
},
|
|
145
|
+
retryConnectionErrors: true,
|
|
146
|
+
}
|
|
147
|
+
|| { strategy: "none" },
|
|
148
|
+
retryCodes: options?.retryCodes || ["5XX"],
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const requestRes = client._createRequest(context, {
|
|
152
|
+
security: requestSecurity,
|
|
153
|
+
method: "POST",
|
|
154
|
+
baseURL: options?.serverURL,
|
|
155
|
+
path: path,
|
|
156
|
+
headers: headers,
|
|
157
|
+
body: body,
|
|
158
|
+
userAgent: client._options.userAgent,
|
|
159
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
160
|
+
}, options);
|
|
161
|
+
if (!requestRes.ok) {
|
|
162
|
+
return [requestRes, { status: "invalid" }];
|
|
163
|
+
}
|
|
164
|
+
const req = requestRes.value;
|
|
165
|
+
|
|
166
|
+
const doResult = await client._do(req, {
|
|
167
|
+
context,
|
|
168
|
+
errorCodes: ["400", "401", "403", "404", "410", "4XX", "500", "5XX"],
|
|
169
|
+
retryConfig: context.retryConfig,
|
|
170
|
+
retryCodes: context.retryCodes,
|
|
171
|
+
});
|
|
172
|
+
if (!doResult.ok) {
|
|
173
|
+
return [doResult, { status: "request-error", request: req }];
|
|
174
|
+
}
|
|
175
|
+
const response = doResult.value;
|
|
176
|
+
|
|
177
|
+
const responseFields = {
|
|
178
|
+
HttpMeta: { Response: response, Request: req },
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const [result] = await M.match<
|
|
182
|
+
components.V2RatelimitMultiLimitResponseBody,
|
|
183
|
+
| errors.BadRequestErrorResponse
|
|
184
|
+
| errors.UnauthorizedErrorResponse
|
|
185
|
+
| errors.ForbiddenErrorResponse
|
|
186
|
+
| errors.NotFoundErrorResponse
|
|
187
|
+
| errors.GoneErrorResponse
|
|
188
|
+
| errors.InternalServerErrorResponse
|
|
189
|
+
| UnkeyError
|
|
190
|
+
| ResponseValidationError
|
|
191
|
+
| ConnectionError
|
|
192
|
+
| RequestAbortedError
|
|
193
|
+
| RequestTimeoutError
|
|
194
|
+
| InvalidRequestError
|
|
195
|
+
| UnexpectedClientError
|
|
196
|
+
| SDKValidationError
|
|
197
|
+
>(
|
|
198
|
+
M.json(200, components.V2RatelimitMultiLimitResponseBody$inboundSchema),
|
|
199
|
+
M.jsonErr(400, errors.BadRequestErrorResponse$inboundSchema),
|
|
200
|
+
M.jsonErr(401, errors.UnauthorizedErrorResponse$inboundSchema),
|
|
201
|
+
M.jsonErr(403, errors.ForbiddenErrorResponse$inboundSchema),
|
|
202
|
+
M.jsonErr(404, errors.NotFoundErrorResponse$inboundSchema),
|
|
203
|
+
M.jsonErr(410, errors.GoneErrorResponse$inboundSchema),
|
|
204
|
+
M.jsonErr(500, errors.InternalServerErrorResponse$inboundSchema),
|
|
205
|
+
M.fail("4XX"),
|
|
206
|
+
M.fail("5XX"),
|
|
207
|
+
)(response, req, { extraFields: responseFields });
|
|
208
|
+
if (!result.ok) {
|
|
209
|
+
return [result, { status: "complete", request: req, response }];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return [result, { status: "complete", request: req, response }];
|
|
213
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HTTPClient, type Fetcher } from "../../lib/http.js";
|
|
2
|
+
import type { SDKInitHook, SDKInitOptions } from "../types.js";
|
|
3
|
+
|
|
4
|
+
function isVercelEdgeRuntime(): boolean {
|
|
5
|
+
// https://vercel.com/docs/functions/runtimes/edge#check-if-you're-running-on-the-edge-runtime
|
|
6
|
+
if ("EdgeRuntime" in globalThis) return true;
|
|
7
|
+
if (process.env["NEXT_RUNTIME"] === "edge") return true;
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const vercelEdgeFetcher: Fetcher = (input, init?) => {
|
|
12
|
+
// Edge runtime fix: Request objects may not be recognized by instanceof
|
|
13
|
+
// Check if it's a Request-like object by checking for .url property
|
|
14
|
+
const isRequestLike =
|
|
15
|
+
typeof input === "object" &&
|
|
16
|
+
input !== null &&
|
|
17
|
+
"url" in input &&
|
|
18
|
+
"method" in input &&
|
|
19
|
+
"headers" in input;
|
|
20
|
+
|
|
21
|
+
if (isRequestLike && !init) {
|
|
22
|
+
// For Edge runtime: extract URL and reconstruct request
|
|
23
|
+
const req = input as Request;
|
|
24
|
+
return fetch(req.url, {
|
|
25
|
+
method: req.method,
|
|
26
|
+
headers: req.headers,
|
|
27
|
+
body: req.body,
|
|
28
|
+
mode: req.mode,
|
|
29
|
+
credentials: req.credentials,
|
|
30
|
+
cache: req.cache,
|
|
31
|
+
redirect: req.redirect,
|
|
32
|
+
referrer: req.referrer,
|
|
33
|
+
integrity: req.integrity,
|
|
34
|
+
signal: req.signal,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// If input is a Request and init is undefined, Bun will discard the method,
|
|
39
|
+
// headers, body and other options that were set on the request object.
|
|
40
|
+
// Node.js and browers would ignore an undefined init value. This check is
|
|
41
|
+
// therefore needed for interop with Bun.
|
|
42
|
+
if (init == null) {
|
|
43
|
+
return fetch(input);
|
|
44
|
+
} else {
|
|
45
|
+
return fetch(input, init);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export class FetcherOverrideForVercelEdgeHook implements SDKInitHook {
|
|
50
|
+
sdkInit(opts: SDKInitOptions) {
|
|
51
|
+
if (!isVercelEdgeRuntime()) {
|
|
52
|
+
return opts;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const client = new HTTPClient({
|
|
56
|
+
fetcher: vercelEdgeFetcher,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...opts,
|
|
61
|
+
client,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FetcherOverrideForVercelEdgeHook } from "./custom/vercel-edge-fetcher.js";
|
|
1
2
|
import { Hooks } from "./types.js";
|
|
2
3
|
|
|
3
4
|
/*
|
|
@@ -6,9 +7,7 @@ import { Hooks } from "./types.js";
|
|
|
6
7
|
* in this file or in separate files in the hooks folder.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
// @ts-expect-error remove this line when you add your first hook and hooks is used
|
|
10
10
|
export function initHooks(hooks: Hooks) {
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
11
|
+
// Use a fetcher that works in Vercel Edge Runtime environments
|
|
12
|
+
hooks.registerSDKInitHook(new FetcherOverrideForVercelEdgeHook());
|
|
14
13
|
}
|
package/src/lib/config.ts
CHANGED
|
@@ -58,7 +58,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
58
58
|
export const SDK_METADATA = {
|
|
59
59
|
language: "typescript",
|
|
60
60
|
openapiDocVersion: "2.0.0",
|
|
61
|
-
sdkVersion: "2.1.
|
|
62
|
-
genVersion: "2.
|
|
63
|
-
userAgent: "speakeasy-sdk/typescript 2.1.
|
|
61
|
+
sdkVersion: "2.1.2",
|
|
62
|
+
genVersion: "2.753.6",
|
|
63
|
+
userAgent: "speakeasy-sdk/typescript 2.1.2 2.753.6 2.0.0 @unkey/api",
|
|
64
64
|
} as const;
|
package/src/mcp-server/server.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { tool$keysAddRoles } from "./tools/keysAddRoles.js";
|
|
|
28
28
|
import { tool$keysCreateKey } from "./tools/keysCreateKey.js";
|
|
29
29
|
import { tool$keysDeleteKey } from "./tools/keysDeleteKey.js";
|
|
30
30
|
import { tool$keysGetKey } from "./tools/keysGetKey.js";
|
|
31
|
+
import { tool$keysMigrateKeys } from "./tools/keysMigrateKeys.js";
|
|
31
32
|
import { tool$keysRemovePermissions } from "./tools/keysRemovePermissions.js";
|
|
32
33
|
import { tool$keysRemoveRoles } from "./tools/keysRemoveRoles.js";
|
|
33
34
|
import { tool$keysRerollKey } from "./tools/keysRerollKey.js";
|
|
@@ -49,6 +50,7 @@ import { tool$ratelimitDeleteOverride } from "./tools/ratelimitDeleteOverride.js
|
|
|
49
50
|
import { tool$ratelimitGetOverride } from "./tools/ratelimitGetOverride.js";
|
|
50
51
|
import { tool$ratelimitLimit } from "./tools/ratelimitLimit.js";
|
|
51
52
|
import { tool$ratelimitListOverrides } from "./tools/ratelimitListOverrides.js";
|
|
53
|
+
import { tool$ratelimitMultiLimit } from "./tools/ratelimitMultiLimit.js";
|
|
52
54
|
import { tool$ratelimitSetOverride } from "./tools/ratelimitSetOverride.js";
|
|
53
55
|
|
|
54
56
|
export function createMCPServer(deps: {
|
|
@@ -61,7 +63,7 @@ export function createMCPServer(deps: {
|
|
|
61
63
|
}) {
|
|
62
64
|
const server = new McpServer({
|
|
63
65
|
name: "Unkey",
|
|
64
|
-
version: "2.1.
|
|
66
|
+
version: "2.1.2",
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
const client = new UnkeyCore({
|
|
@@ -106,6 +108,7 @@ export function createMCPServer(deps: {
|
|
|
106
108
|
tool(tool$keysCreateKey);
|
|
107
109
|
tool(tool$keysDeleteKey);
|
|
108
110
|
tool(tool$keysGetKey);
|
|
111
|
+
tool(tool$keysMigrateKeys);
|
|
109
112
|
tool(tool$keysRemovePermissions);
|
|
110
113
|
tool(tool$keysRemoveRoles);
|
|
111
114
|
tool(tool$keysRerollKey);
|
|
@@ -127,6 +130,7 @@ export function createMCPServer(deps: {
|
|
|
127
130
|
tool(tool$ratelimitGetOverride);
|
|
128
131
|
tool(tool$ratelimitLimit);
|
|
129
132
|
tool(tool$ratelimitListOverrides);
|
|
133
|
+
tool(tool$ratelimitMultiLimit);
|
|
130
134
|
tool(tool$ratelimitSetOverride);
|
|
131
135
|
|
|
132
136
|
return server;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { keysMigrateKeys } from "../../funcs/keysMigrateKeys.js";
|
|
6
|
+
import * as components from "../../models/components/index.js";
|
|
7
|
+
import { formatResult, ToolDefinition } from "../tools.js";
|
|
8
|
+
|
|
9
|
+
const args = {
|
|
10
|
+
request: components.V2KeysMigrateKeysRequestBody$inboundSchema,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const tool$keysMigrateKeys: ToolDefinition<typeof args> = {
|
|
14
|
+
name: "keys-migrate-keys",
|
|
15
|
+
description: `Migrate API key(s)
|
|
16
|
+
|
|
17
|
+
Returns HTTP 200 even on partial success; hashes that could not be migrated are listed under \`data.failed\`.
|
|
18
|
+
|
|
19
|
+
**Required Permissions**
|
|
20
|
+
Your root key must have one of the following permissions for basic key information:
|
|
21
|
+
- \`api.*.create_key\` (to migrate keys to any API)
|
|
22
|
+
- \`api.<api_id>.create_key\` (to migrate keys to a specific API)
|
|
23
|
+
`,
|
|
24
|
+
args,
|
|
25
|
+
tool: async (client, args, ctx) => {
|
|
26
|
+
const [result, apiCall] = await keysMigrateKeys(
|
|
27
|
+
client,
|
|
28
|
+
args.request,
|
|
29
|
+
{ fetchOptions: { signal: ctx.signal } },
|
|
30
|
+
).$inspect();
|
|
31
|
+
|
|
32
|
+
if (!result.ok) {
|
|
33
|
+
return {
|
|
34
|
+
content: [{ type: "text", text: result.error.message }],
|
|
35
|
+
isError: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const value = result.value;
|
|
40
|
+
|
|
41
|
+
return formatResult(value, apiCall);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -25,10 +25,6 @@ Use this for rate limiting beyond API keys - limit users by ID, IPs by address,
|
|
|
25
25
|
Your root key must have one of the following permissions:
|
|
26
26
|
- \`ratelimit.*.limit\` (to check limits in any namespace)
|
|
27
27
|
- \`ratelimit.<namespace_id>.limit\` (to check limits in a specific namespace)
|
|
28
|
-
|
|
29
|
-
**Side Effects**
|
|
30
|
-
|
|
31
|
-
Records rate limit metrics for analytics and monitoring, updates rate limit counters with sliding window algorithm, and optionally triggers override matching for custom limits.
|
|
32
28
|
`,
|
|
33
29
|
args,
|
|
34
30
|
tool: async (client, args, ctx) => {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { ratelimitMultiLimit } from "../../funcs/ratelimitMultiLimit.js";
|
|
7
|
+
import * as components from "../../models/components/index.js";
|
|
8
|
+
import { formatResult, ToolDefinition } from "../tools.js";
|
|
9
|
+
|
|
10
|
+
const args = {
|
|
11
|
+
request: z.array(components.V2RatelimitLimitRequestBody$inboundSchema),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const tool$ratelimitMultiLimit: ToolDefinition<typeof args> = {
|
|
15
|
+
name: "ratelimit-multi-limit",
|
|
16
|
+
description: `Apply multiple rate limit checks
|
|
17
|
+
|
|
18
|
+
Check and enforce multiple rate limits in a single request for any identifiers (user IDs, IP addresses, API clients, etc.).
|
|
19
|
+
|
|
20
|
+
Use this to efficiently check multiple rate limits at once. Each rate limit check is independent and returns its own result with a top-level \`passed\` indicator showing if all checks succeeded.
|
|
21
|
+
|
|
22
|
+
**Response Codes**: Rate limit checks return HTTP 200 regardless of whether limits are exceeded - check the \`passed\` field to see if all limits passed, or the \`success\` field in each individual result. 4xx responses indicate auth, namespace existence/deletion, or validation errors (e.g., 410 Gone for deleted namespaces). 5xx responses indicate server errors.
|
|
23
|
+
|
|
24
|
+
**Required Permissions**
|
|
25
|
+
|
|
26
|
+
Your root key must have one of the following permissions:
|
|
27
|
+
- \`ratelimit.*.limit\` (to check limits in any namespace)
|
|
28
|
+
- \`ratelimit.<namespace_id>.limit\` (to check limits in all specific namespaces being checked)
|
|
29
|
+
`,
|
|
30
|
+
args,
|
|
31
|
+
tool: async (client, args, ctx) => {
|
|
32
|
+
const [result, apiCall] = await ratelimitMultiLimit(
|
|
33
|
+
client,
|
|
34
|
+
args.request,
|
|
35
|
+
{ fetchOptions: { signal: ctx.signal } },
|
|
36
|
+
).$inspect();
|
|
37
|
+
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: "text", text: result.error.message }],
|
|
41
|
+
isError: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const value = result.value;
|
|
46
|
+
|
|
47
|
+
return formatResult(value, apiCall);
|
|
48
|
+
},
|
|
49
|
+
};
|