@unkey/api 0.16.0 → 0.18.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/LICENSE +68 -81
- package/dist/index.d.mts +235 -316
- package/dist/index.d.ts +235 -316
- package/dist/index.js +53 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { PermissionQuery } from '@unkey/rbac';
|
|
2
|
+
export { Flatten, and, or } from '@unkey/rbac';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* This file was auto-generated by openapi-typescript.
|
|
3
6
|
* Do not make direct changes to the file.
|
|
@@ -248,6 +251,14 @@ interface paths {
|
|
|
248
251
|
meta?: {
|
|
249
252
|
[key: string]: unknown;
|
|
250
253
|
};
|
|
254
|
+
/**
|
|
255
|
+
* @description A list of roles that this key should have. If the role does not exist, an error is thrown
|
|
256
|
+
* @example [
|
|
257
|
+
* "admin",
|
|
258
|
+
* "finance"
|
|
259
|
+
* ]
|
|
260
|
+
*/
|
|
261
|
+
roles?: string[];
|
|
251
262
|
/**
|
|
252
263
|
* @description You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again.
|
|
253
264
|
* @example 1623869797161
|
|
@@ -373,110 +384,14 @@ interface paths {
|
|
|
373
384
|
post: {
|
|
374
385
|
requestBody: {
|
|
375
386
|
content: {
|
|
376
|
-
"application/json":
|
|
377
|
-
/**
|
|
378
|
-
* @description The id of the api where the key belongs to. This is optional for now but will be required soon.
|
|
379
|
-
* The key will be verified against the api's configuration. If the key does not belong to the api, the verification will fail.
|
|
380
|
-
* @example api_1234
|
|
381
|
-
*/
|
|
382
|
-
apiId?: string;
|
|
383
|
-
/**
|
|
384
|
-
* @description The key to verify
|
|
385
|
-
* @example sk_1234
|
|
386
|
-
*/
|
|
387
|
-
key: string;
|
|
388
|
-
};
|
|
387
|
+
"application/json": components["schemas"]["V1KeysVerifyKeyRequest"];
|
|
389
388
|
};
|
|
390
389
|
};
|
|
391
390
|
responses: {
|
|
392
391
|
/** @description The verification result */
|
|
393
392
|
200: {
|
|
394
393
|
content: {
|
|
395
|
-
"application/json":
|
|
396
|
-
/**
|
|
397
|
-
* @description The id of the key
|
|
398
|
-
* @example key_1234
|
|
399
|
-
*/
|
|
400
|
-
keyId?: string;
|
|
401
|
-
/**
|
|
402
|
-
* @description Whether the key is valid or not.
|
|
403
|
-
* A key could be invalid for a number of reasons, for example if it has expired, has no more verifications left or if it has been deleted.
|
|
404
|
-
* @example true
|
|
405
|
-
*/
|
|
406
|
-
valid: boolean;
|
|
407
|
-
/**
|
|
408
|
-
* @description The name of the key, give keys a name to easily identifiy their purpose
|
|
409
|
-
* @example Customer X
|
|
410
|
-
*/
|
|
411
|
-
name?: string;
|
|
412
|
-
/**
|
|
413
|
-
* @description The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API.
|
|
414
|
-
* @example user_123
|
|
415
|
-
*/
|
|
416
|
-
ownerId?: string;
|
|
417
|
-
/**
|
|
418
|
-
* @description Any additional metadata you want to store with the key
|
|
419
|
-
* @example {
|
|
420
|
-
* "roles": [
|
|
421
|
-
* "admin",
|
|
422
|
-
* "user"
|
|
423
|
-
* ],
|
|
424
|
-
* "stripeCustomerId": "cus_1234"
|
|
425
|
-
* }
|
|
426
|
-
*/
|
|
427
|
-
meta?: {
|
|
428
|
-
[key: string]: unknown;
|
|
429
|
-
};
|
|
430
|
-
/**
|
|
431
|
-
* @description The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring.
|
|
432
|
-
* @example 123
|
|
433
|
-
*/
|
|
434
|
-
expires?: number;
|
|
435
|
-
/**
|
|
436
|
-
* @description The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.
|
|
437
|
-
* @example {
|
|
438
|
-
* "limit": 10,
|
|
439
|
-
* "remaining": 9,
|
|
440
|
-
* "reset": 3600000
|
|
441
|
-
* }
|
|
442
|
-
*/
|
|
443
|
-
ratelimit?: {
|
|
444
|
-
/**
|
|
445
|
-
* @description Maximum number of requests that can be made inside a window
|
|
446
|
-
* @example 10
|
|
447
|
-
*/
|
|
448
|
-
limit: number;
|
|
449
|
-
/**
|
|
450
|
-
* @description Remaining requests after this verification
|
|
451
|
-
* @example 9
|
|
452
|
-
*/
|
|
453
|
-
remaining: number;
|
|
454
|
-
/**
|
|
455
|
-
* @description Unix timestamp in milliseconds when the ratelimit will reset
|
|
456
|
-
* @example 3600000
|
|
457
|
-
*/
|
|
458
|
-
reset: number;
|
|
459
|
-
};
|
|
460
|
-
/**
|
|
461
|
-
* @description The number of requests that can be made with this key before it becomes invalid. If this field is null or undefined, the key has no request limit.
|
|
462
|
-
* @example 1000
|
|
463
|
-
*/
|
|
464
|
-
remaining?: number;
|
|
465
|
-
/**
|
|
466
|
-
* @description If the key is invalid this field will be set to the reason why it is invalid.
|
|
467
|
-
* Possible values are:
|
|
468
|
-
* - NOT_FOUND: the key does not exist or has expired
|
|
469
|
-
* - FORBIDDEN: the key is not allowed to access the api
|
|
470
|
-
* - USAGE_EXCEEDED: the key has exceeded its request limit
|
|
471
|
-
* - RATE_LIMITED: the key has been ratelimited
|
|
472
|
-
* - UNAUTHORIZED: the key is not authorized
|
|
473
|
-
* - DISABLED: the key is disabled
|
|
474
|
-
* @enum {string}
|
|
475
|
-
*/
|
|
476
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED";
|
|
477
|
-
/** @description Sets the key to be enabled or disabled. Disabled keys will not verify. */
|
|
478
|
-
enabled?: boolean;
|
|
479
|
-
};
|
|
394
|
+
"application/json": components["schemas"]["V1KeysVerifyKeyResponse"];
|
|
480
395
|
};
|
|
481
396
|
};
|
|
482
397
|
/** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */
|
|
@@ -832,92 +747,6 @@ interface paths {
|
|
|
832
747
|
};
|
|
833
748
|
};
|
|
834
749
|
};
|
|
835
|
-
"/vx/keys.getVerifications": {
|
|
836
|
-
get: {
|
|
837
|
-
parameters: {
|
|
838
|
-
query?: {
|
|
839
|
-
keyId?: string;
|
|
840
|
-
ownerId?: string;
|
|
841
|
-
start?: number | null;
|
|
842
|
-
end?: number | null;
|
|
843
|
-
granularity?: "day";
|
|
844
|
-
};
|
|
845
|
-
};
|
|
846
|
-
responses: {
|
|
847
|
-
/** @description The configuration for a single key */
|
|
848
|
-
200: {
|
|
849
|
-
content: {
|
|
850
|
-
"application/json": {
|
|
851
|
-
verifications: {
|
|
852
|
-
/**
|
|
853
|
-
* @description The timestamp of the usage data
|
|
854
|
-
* @example 1620000000000
|
|
855
|
-
*/
|
|
856
|
-
time: number;
|
|
857
|
-
/**
|
|
858
|
-
* @description The number of successful requests
|
|
859
|
-
* @example 100
|
|
860
|
-
*/
|
|
861
|
-
success: number;
|
|
862
|
-
/**
|
|
863
|
-
* @description The number of requests that were rate limited
|
|
864
|
-
* @example 10
|
|
865
|
-
*/
|
|
866
|
-
rateLimited: number;
|
|
867
|
-
/**
|
|
868
|
-
* @description The number of requests that exceeded the usage limit
|
|
869
|
-
* @example 0
|
|
870
|
-
*/
|
|
871
|
-
usageExceeded: number;
|
|
872
|
-
}[];
|
|
873
|
-
};
|
|
874
|
-
};
|
|
875
|
-
};
|
|
876
|
-
/** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */
|
|
877
|
-
400: {
|
|
878
|
-
content: {
|
|
879
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
880
|
-
};
|
|
881
|
-
};
|
|
882
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
883
|
-
401: {
|
|
884
|
-
content: {
|
|
885
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
886
|
-
};
|
|
887
|
-
};
|
|
888
|
-
/** @description The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */
|
|
889
|
-
403: {
|
|
890
|
-
content: {
|
|
891
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
892
|
-
};
|
|
893
|
-
};
|
|
894
|
-
/** @description The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. */
|
|
895
|
-
404: {
|
|
896
|
-
content: {
|
|
897
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
898
|
-
};
|
|
899
|
-
};
|
|
900
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
901
|
-
409: {
|
|
902
|
-
content: {
|
|
903
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
904
|
-
};
|
|
905
|
-
};
|
|
906
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
907
|
-
429: {
|
|
908
|
-
content: {
|
|
909
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
910
|
-
};
|
|
911
|
-
};
|
|
912
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
913
|
-
500: {
|
|
914
|
-
content: {
|
|
915
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
916
|
-
};
|
|
917
|
-
};
|
|
918
|
-
};
|
|
919
|
-
};
|
|
920
|
-
};
|
|
921
750
|
"/v1/apis.getApi": {
|
|
922
751
|
get: {
|
|
923
752
|
parameters: {
|
|
@@ -1203,9 +1032,6 @@ interface paths {
|
|
|
1203
1032
|
"/v1/keys/{keyId}": {
|
|
1204
1033
|
put: {
|
|
1205
1034
|
parameters: {
|
|
1206
|
-
header: {
|
|
1207
|
-
authorization: string;
|
|
1208
|
-
};
|
|
1209
1035
|
path: {
|
|
1210
1036
|
keyId: string;
|
|
1211
1037
|
};
|
|
@@ -1323,129 +1149,8 @@ interface paths {
|
|
|
1323
1149
|
};
|
|
1324
1150
|
};
|
|
1325
1151
|
};
|
|
1326
|
-
"/v1/keys/:keyId": {
|
|
1327
|
-
get: {
|
|
1328
|
-
parameters: {
|
|
1329
|
-
header: {
|
|
1330
|
-
authorization: string;
|
|
1331
|
-
};
|
|
1332
|
-
};
|
|
1333
|
-
responses: {
|
|
1334
|
-
/** @description The configuration for a single key */
|
|
1335
|
-
200: {
|
|
1336
|
-
content: {
|
|
1337
|
-
"application/json": components["schemas"]["Key"];
|
|
1338
|
-
};
|
|
1339
|
-
};
|
|
1340
|
-
/** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */
|
|
1341
|
-
400: {
|
|
1342
|
-
content: {
|
|
1343
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1344
|
-
};
|
|
1345
|
-
};
|
|
1346
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1347
|
-
401: {
|
|
1348
|
-
content: {
|
|
1349
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1350
|
-
};
|
|
1351
|
-
};
|
|
1352
|
-
/** @description The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */
|
|
1353
|
-
403: {
|
|
1354
|
-
content: {
|
|
1355
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1356
|
-
};
|
|
1357
|
-
};
|
|
1358
|
-
/** @description The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. */
|
|
1359
|
-
404: {
|
|
1360
|
-
content: {
|
|
1361
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1362
|
-
};
|
|
1363
|
-
};
|
|
1364
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1365
|
-
409: {
|
|
1366
|
-
content: {
|
|
1367
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1368
|
-
};
|
|
1369
|
-
};
|
|
1370
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1371
|
-
429: {
|
|
1372
|
-
content: {
|
|
1373
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1374
|
-
};
|
|
1375
|
-
};
|
|
1376
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1377
|
-
500: {
|
|
1378
|
-
content: {
|
|
1379
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1380
|
-
};
|
|
1381
|
-
};
|
|
1382
|
-
};
|
|
1383
|
-
};
|
|
1384
|
-
delete: {
|
|
1385
|
-
parameters: {
|
|
1386
|
-
header: {
|
|
1387
|
-
authorization: string;
|
|
1388
|
-
};
|
|
1389
|
-
};
|
|
1390
|
-
responses: {
|
|
1391
|
-
/** @description The key was successfully revoked, it may take up to 30s for this to take effect in all regions */
|
|
1392
|
-
200: {
|
|
1393
|
-
content: {
|
|
1394
|
-
"application/json": Record<string, never>;
|
|
1395
|
-
};
|
|
1396
|
-
};
|
|
1397
|
-
/** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */
|
|
1398
|
-
400: {
|
|
1399
|
-
content: {
|
|
1400
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1401
|
-
};
|
|
1402
|
-
};
|
|
1403
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1404
|
-
401: {
|
|
1405
|
-
content: {
|
|
1406
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1407
|
-
};
|
|
1408
|
-
};
|
|
1409
|
-
/** @description The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */
|
|
1410
|
-
403: {
|
|
1411
|
-
content: {
|
|
1412
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1413
|
-
};
|
|
1414
|
-
};
|
|
1415
|
-
/** @description The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. */
|
|
1416
|
-
404: {
|
|
1417
|
-
content: {
|
|
1418
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1419
|
-
};
|
|
1420
|
-
};
|
|
1421
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1422
|
-
409: {
|
|
1423
|
-
content: {
|
|
1424
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1425
|
-
};
|
|
1426
|
-
};
|
|
1427
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1428
|
-
429: {
|
|
1429
|
-
content: {
|
|
1430
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1431
|
-
};
|
|
1432
|
-
};
|
|
1433
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1434
|
-
500: {
|
|
1435
|
-
content: {
|
|
1436
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1437
|
-
};
|
|
1438
|
-
};
|
|
1439
|
-
};
|
|
1440
|
-
};
|
|
1441
|
-
};
|
|
1442
1152
|
"/v1/keys": {
|
|
1443
1153
|
post: {
|
|
1444
|
-
parameters: {
|
|
1445
|
-
header: {
|
|
1446
|
-
authorization: string;
|
|
1447
|
-
};
|
|
1448
|
-
};
|
|
1449
1154
|
requestBody: {
|
|
1450
1155
|
content: {
|
|
1451
1156
|
"application/json": {
|
|
@@ -1697,11 +1402,12 @@ interface paths {
|
|
|
1697
1402
|
* - FORBIDDEN: the key is not allowed to access the api
|
|
1698
1403
|
* - USAGE_EXCEEDED: the key has exceeded its request limit
|
|
1699
1404
|
* - RATE_LIMITED: the key has been ratelimited,
|
|
1405
|
+
* - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
|
|
1700
1406
|
*
|
|
1701
1407
|
* @example NOT_FOUND
|
|
1702
1408
|
* @enum {string}
|
|
1703
1409
|
*/
|
|
1704
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED";
|
|
1410
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS";
|
|
1705
1411
|
};
|
|
1706
1412
|
};
|
|
1707
1413
|
};
|
|
@@ -1750,6 +1456,60 @@ interface paths {
|
|
|
1750
1456
|
};
|
|
1751
1457
|
};
|
|
1752
1458
|
};
|
|
1459
|
+
"/v1/keys/:keyId": {
|
|
1460
|
+
delete: {
|
|
1461
|
+
responses: {
|
|
1462
|
+
/** @description The key was successfully revoked, it may take up to 30s for this to take effect in all regions */
|
|
1463
|
+
200: {
|
|
1464
|
+
content: {
|
|
1465
|
+
"application/json": Record<string, never>;
|
|
1466
|
+
};
|
|
1467
|
+
};
|
|
1468
|
+
/** @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */
|
|
1469
|
+
400: {
|
|
1470
|
+
content: {
|
|
1471
|
+
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1472
|
+
};
|
|
1473
|
+
};
|
|
1474
|
+
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1475
|
+
401: {
|
|
1476
|
+
content: {
|
|
1477
|
+
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1478
|
+
};
|
|
1479
|
+
};
|
|
1480
|
+
/** @description The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */
|
|
1481
|
+
403: {
|
|
1482
|
+
content: {
|
|
1483
|
+
"application/json": components["schemas"]["ErrForbidden"];
|
|
1484
|
+
};
|
|
1485
|
+
};
|
|
1486
|
+
/** @description The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. */
|
|
1487
|
+
404: {
|
|
1488
|
+
content: {
|
|
1489
|
+
"application/json": components["schemas"]["ErrNotFound"];
|
|
1490
|
+
};
|
|
1491
|
+
};
|
|
1492
|
+
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1493
|
+
409: {
|
|
1494
|
+
content: {
|
|
1495
|
+
"application/json": components["schemas"]["ErrConflict"];
|
|
1496
|
+
};
|
|
1497
|
+
};
|
|
1498
|
+
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1499
|
+
429: {
|
|
1500
|
+
content: {
|
|
1501
|
+
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1502
|
+
};
|
|
1503
|
+
};
|
|
1504
|
+
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1505
|
+
500: {
|
|
1506
|
+
content: {
|
|
1507
|
+
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1508
|
+
};
|
|
1509
|
+
};
|
|
1510
|
+
};
|
|
1511
|
+
};
|
|
1512
|
+
};
|
|
1753
1513
|
"/v1/apis": {
|
|
1754
1514
|
post: {
|
|
1755
1515
|
requestBody: {
|
|
@@ -1897,9 +1657,6 @@ interface paths {
|
|
|
1897
1657
|
};
|
|
1898
1658
|
delete: {
|
|
1899
1659
|
parameters: {
|
|
1900
|
-
header: {
|
|
1901
|
-
authorization: string;
|
|
1902
|
-
};
|
|
1903
1660
|
path: {
|
|
1904
1661
|
apiId: string;
|
|
1905
1662
|
};
|
|
@@ -2294,12 +2051,154 @@ interface components {
|
|
|
2294
2051
|
/** @description Determines the speed at which tokens are refilled, in milliseconds. */
|
|
2295
2052
|
refillInterval: number;
|
|
2296
2053
|
};
|
|
2054
|
+
/**
|
|
2055
|
+
* @description All roles this key belongs to
|
|
2056
|
+
* @example [
|
|
2057
|
+
* "admin",
|
|
2058
|
+
* "finance"
|
|
2059
|
+
* ]
|
|
2060
|
+
*/
|
|
2061
|
+
roles?: string[];
|
|
2062
|
+
/**
|
|
2063
|
+
* @description All permissions this key has
|
|
2064
|
+
* @example [
|
|
2065
|
+
* "domain.dns.create_record",
|
|
2066
|
+
* "finance.read_receipt"
|
|
2067
|
+
* ]
|
|
2068
|
+
*/
|
|
2069
|
+
permissions?: string[];
|
|
2297
2070
|
/**
|
|
2298
2071
|
* @description Sets if key is enabled or disabled. Disabled keys are not valid.
|
|
2299
2072
|
* @example true
|
|
2300
2073
|
*/
|
|
2301
2074
|
enabled?: boolean;
|
|
2302
2075
|
};
|
|
2076
|
+
V1KeysVerifyKeyResponse: {
|
|
2077
|
+
/**
|
|
2078
|
+
* @description The id of the key
|
|
2079
|
+
* @example key_1234
|
|
2080
|
+
*/
|
|
2081
|
+
keyId?: string;
|
|
2082
|
+
/**
|
|
2083
|
+
* @description Whether the key is valid or not.
|
|
2084
|
+
* A key could be invalid for a number of reasons, for example if it has expired, has no more verifications left or if it has been deleted.
|
|
2085
|
+
* @example true
|
|
2086
|
+
*/
|
|
2087
|
+
valid: boolean;
|
|
2088
|
+
/**
|
|
2089
|
+
* @description The name of the key, give keys a name to easily identifiy their purpose
|
|
2090
|
+
* @example Customer X
|
|
2091
|
+
*/
|
|
2092
|
+
name?: string;
|
|
2093
|
+
/**
|
|
2094
|
+
* @description The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API.
|
|
2095
|
+
* @example user_123
|
|
2096
|
+
*/
|
|
2097
|
+
ownerId?: string;
|
|
2098
|
+
/**
|
|
2099
|
+
* @description Any additional metadata you want to store with the key
|
|
2100
|
+
* @example {
|
|
2101
|
+
* "roles": [
|
|
2102
|
+
* "admin",
|
|
2103
|
+
* "user"
|
|
2104
|
+
* ],
|
|
2105
|
+
* "stripeCustomerId": "cus_1234"
|
|
2106
|
+
* }
|
|
2107
|
+
*/
|
|
2108
|
+
meta?: {
|
|
2109
|
+
[key: string]: unknown;
|
|
2110
|
+
};
|
|
2111
|
+
/**
|
|
2112
|
+
* @description The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring.
|
|
2113
|
+
* @example 123
|
|
2114
|
+
*/
|
|
2115
|
+
expires?: number;
|
|
2116
|
+
/**
|
|
2117
|
+
* @description The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.
|
|
2118
|
+
* @example {
|
|
2119
|
+
* "limit": 10,
|
|
2120
|
+
* "remaining": 9,
|
|
2121
|
+
* "reset": 3600000
|
|
2122
|
+
* }
|
|
2123
|
+
*/
|
|
2124
|
+
ratelimit?: {
|
|
2125
|
+
/**
|
|
2126
|
+
* @description Maximum number of requests that can be made inside a window
|
|
2127
|
+
* @example 10
|
|
2128
|
+
*/
|
|
2129
|
+
limit: number;
|
|
2130
|
+
/**
|
|
2131
|
+
* @description Remaining requests after this verification
|
|
2132
|
+
* @example 9
|
|
2133
|
+
*/
|
|
2134
|
+
remaining: number;
|
|
2135
|
+
/**
|
|
2136
|
+
* @description Unix timestamp in milliseconds when the ratelimit will reset
|
|
2137
|
+
* @example 3600000
|
|
2138
|
+
*/
|
|
2139
|
+
reset: number;
|
|
2140
|
+
};
|
|
2141
|
+
/**
|
|
2142
|
+
* @description The number of requests that can be made with this key before it becomes invalid. If this field is null or undefined, the key has no request limit.
|
|
2143
|
+
* @example 1000
|
|
2144
|
+
*/
|
|
2145
|
+
remaining?: number;
|
|
2146
|
+
/**
|
|
2147
|
+
* @description If the key is invalid this field will be set to the reason why it is invalid.
|
|
2148
|
+
* Possible values are:
|
|
2149
|
+
* - NOT_FOUND: the key does not exist or has expired
|
|
2150
|
+
* - FORBIDDEN: the key is not allowed to access the api
|
|
2151
|
+
* - USAGE_EXCEEDED: the key has exceeded its request limit
|
|
2152
|
+
* - RATE_LIMITED: the key has been ratelimited
|
|
2153
|
+
* - UNAUTHORIZED: the key is not authorized
|
|
2154
|
+
* - DISABLED: the key is disabled
|
|
2155
|
+
* - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
|
|
2156
|
+
*
|
|
2157
|
+
* @enum {string}
|
|
2158
|
+
*/
|
|
2159
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS";
|
|
2160
|
+
/** @description Sets the key to be enabled or disabled. Disabled keys will not verify. */
|
|
2161
|
+
enabled?: boolean;
|
|
2162
|
+
/**
|
|
2163
|
+
* @description A list of all the permissions this key is connected to.
|
|
2164
|
+
* @example [
|
|
2165
|
+
* "dns.record.update",
|
|
2166
|
+
* "dns.record.delete"
|
|
2167
|
+
* ]
|
|
2168
|
+
*/
|
|
2169
|
+
permissions?: string[];
|
|
2170
|
+
};
|
|
2171
|
+
V1KeysVerifyKeyRequest: {
|
|
2172
|
+
/**
|
|
2173
|
+
* @description The id of the api where the key belongs to. This is optional for now but will be required soon.
|
|
2174
|
+
* The key will be verified against the api's configuration. If the key does not belong to the api, the verification will fail.
|
|
2175
|
+
* @example api_1234
|
|
2176
|
+
*/
|
|
2177
|
+
apiId?: string;
|
|
2178
|
+
/**
|
|
2179
|
+
* @description The key to verify
|
|
2180
|
+
* @example sk_1234
|
|
2181
|
+
*/
|
|
2182
|
+
key: string;
|
|
2183
|
+
/** @description Perform RBAC checks */
|
|
2184
|
+
authorization?: {
|
|
2185
|
+
/**
|
|
2186
|
+
* @description A query for which permissions you require
|
|
2187
|
+
* @example {
|
|
2188
|
+
* "or": [
|
|
2189
|
+
* {
|
|
2190
|
+
* "and": [
|
|
2191
|
+
* "dns.record.read",
|
|
2192
|
+
* "dns.record.update"
|
|
2193
|
+
* ]
|
|
2194
|
+
* },
|
|
2195
|
+
* "admin"
|
|
2196
|
+
* ]
|
|
2197
|
+
* }
|
|
2198
|
+
*/
|
|
2199
|
+
permissions: Record<string, never>;
|
|
2200
|
+
};
|
|
2201
|
+
};
|
|
2303
2202
|
};
|
|
2304
2203
|
responses: never;
|
|
2305
2204
|
parameters: {
|
|
@@ -2333,6 +2232,14 @@ type UnkeyOptions = ({
|
|
|
2333
2232
|
* @default https://api.unkey.dev
|
|
2334
2233
|
*/
|
|
2335
2234
|
baseUrl?: string;
|
|
2235
|
+
/**
|
|
2236
|
+
*
|
|
2237
|
+
* By default telemetry data is enabled, and sends:
|
|
2238
|
+
* runtime (Node.js / Edge)
|
|
2239
|
+
* platform (Node.js / Vercel / AWS)
|
|
2240
|
+
* SDK version
|
|
2241
|
+
*/
|
|
2242
|
+
disableTelemetry?: boolean;
|
|
2336
2243
|
/**
|
|
2337
2244
|
* Retry on network errors
|
|
2338
2245
|
*/
|
|
@@ -2363,7 +2270,7 @@ type UnkeyOptions = ({
|
|
|
2363
2270
|
*
|
|
2364
2271
|
* You can leave this blank unless you are building a wrapper around this SDK.
|
|
2365
2272
|
*/
|
|
2366
|
-
wrapperSdkVersion?:
|
|
2273
|
+
wrapperSdkVersion?: string;
|
|
2367
2274
|
};
|
|
2368
2275
|
type Result<R> = {
|
|
2369
2276
|
result: R;
|
|
@@ -2376,17 +2283,28 @@ declare class Unkey {
|
|
|
2376
2283
|
readonly baseUrl: string;
|
|
2377
2284
|
private readonly rootKey;
|
|
2378
2285
|
private readonly cache?;
|
|
2379
|
-
private readonly
|
|
2286
|
+
private readonly telemetry?;
|
|
2380
2287
|
readonly retry: {
|
|
2381
2288
|
attempts: number;
|
|
2382
2289
|
backoff: (retryCount: number) => number;
|
|
2383
2290
|
};
|
|
2384
2291
|
constructor(opts: UnkeyOptions);
|
|
2292
|
+
private getHeaders;
|
|
2385
2293
|
private fetch;
|
|
2386
2294
|
get keys(): {
|
|
2387
2295
|
create: (req: paths["/v1/keys.createKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.createKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2388
2296
|
update: (req: paths["/v1/keys.updateKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.updateKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2389
|
-
verify: (req:
|
|
2297
|
+
verify: <TPermission extends string = string>(req: Omit<{
|
|
2298
|
+
apiId?: string | undefined;
|
|
2299
|
+
key: string;
|
|
2300
|
+
authorization?: {
|
|
2301
|
+
permissions: Record<string, never>;
|
|
2302
|
+
} | undefined;
|
|
2303
|
+
}, "authorization"> & {
|
|
2304
|
+
authorization?: {
|
|
2305
|
+
permissions: PermissionQuery<TPermission>;
|
|
2306
|
+
} | undefined;
|
|
2307
|
+
}) => Promise<Result<paths["/v1/keys.verifyKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2390
2308
|
delete: (req: paths["/v1/keys.deleteKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.deleteKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2391
2309
|
updateRemaining: (req: paths["/v1/keys.updateRemaining"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.updateRemaining"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2392
2310
|
get: (req: paths["/v1/keys.getKey"]["get"]["parameters"]["query"]) => Promise<Result<paths["/v1/keys.getKey"]["get"]["responses"]["200"]["content"]["application/json"]>>;
|
|
@@ -2448,8 +2366,9 @@ declare function verifyKey(req: string | {
|
|
|
2448
2366
|
reset: number;
|
|
2449
2367
|
} | undefined;
|
|
2450
2368
|
remaining?: number | undefined;
|
|
2451
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | undefined;
|
|
2369
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS" | undefined;
|
|
2452
2370
|
enabled?: boolean | undefined;
|
|
2371
|
+
permissions?: string[] | undefined;
|
|
2453
2372
|
};
|
|
2454
2373
|
error?: undefined;
|
|
2455
2374
|
}>;
|