@unkey/api 0.17.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 +111 -112
- package/dist/index.d.ts +111 -112
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
package/LICENSE
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
GNU GENERAL PUBLIC LICENSE
|
|
2
|
-
Version 3,
|
|
1
|
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 19 November 2007
|
|
3
3
|
|
|
4
4
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
5
|
Everyone is permitted to copy and distribute verbatim copies
|
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
Preamble
|
|
9
9
|
|
|
10
|
-
The GNU General Public License is a free, copyleft license for
|
|
11
|
-
software and other kinds of works
|
|
10
|
+
The GNU Affero General Public License is a free, copyleft license for
|
|
11
|
+
software and other kinds of works, specifically designed to ensure
|
|
12
|
+
cooperation with the community in the case of network server software.
|
|
12
13
|
|
|
13
14
|
The licenses for most software and other practical works are designed
|
|
14
15
|
to take away your freedom to share and change the works. By contrast,
|
|
15
|
-
|
|
16
|
+
our General Public Licenses are intended to guarantee your freedom to
|
|
16
17
|
share and change all versions of a program--to make sure it remains free
|
|
17
|
-
software for all its users.
|
|
18
|
-
GNU General Public License for most of our software; it applies also to
|
|
19
|
-
any other work released this way by its authors. You can apply it to
|
|
20
|
-
your programs, too.
|
|
18
|
+
software for all its users.
|
|
21
19
|
|
|
22
20
|
When we speak of free software, we are referring to freedom, not
|
|
23
21
|
price. Our General Public Licenses are designed to make sure that you
|
|
@@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
|
|
|
26
24
|
want it, that you can change the software or use pieces of it in new
|
|
27
25
|
free programs, and that you know you can do these things.
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
that
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
products. If such problems arise substantially in other domains, we
|
|
58
|
-
stand ready to extend this provision to those domains in future versions
|
|
59
|
-
of the GPL, as needed to protect the freedom of users.
|
|
60
|
-
|
|
61
|
-
Finally, every program is threatened constantly by software patents.
|
|
62
|
-
States should not allow patents to restrict development and use of
|
|
63
|
-
software on general-purpose computers, but in those that do, we wish to
|
|
64
|
-
avoid the special danger that patents applied to a free program could
|
|
65
|
-
make it effectively proprietary. To prevent this, the GPL assures that
|
|
66
|
-
patents cannot be used to render the program non-free.
|
|
27
|
+
Developers that use our General Public Licenses protect your rights
|
|
28
|
+
with two steps: (1) assert copyright on the software, and (2) offer
|
|
29
|
+
you this License which gives you legal permission to copy, distribute
|
|
30
|
+
and/or modify the software.
|
|
31
|
+
|
|
32
|
+
A secondary benefit of defending all users' freedom is that
|
|
33
|
+
improvements made in alternate versions of the program, if they
|
|
34
|
+
receive widespread use, become available for other developers to
|
|
35
|
+
incorporate. Many developers of free software are heartened and
|
|
36
|
+
encouraged by the resulting cooperation. However, in the case of
|
|
37
|
+
software used on network servers, this result may fail to come about.
|
|
38
|
+
The GNU General Public License permits making a modified version and
|
|
39
|
+
letting the public access it on a server without ever releasing its
|
|
40
|
+
source code to the public.
|
|
41
|
+
|
|
42
|
+
The GNU Affero General Public License is designed specifically to
|
|
43
|
+
ensure that, in such cases, the modified source code becomes available
|
|
44
|
+
to the community. It requires the operator of a network server to
|
|
45
|
+
provide the source code of the modified version running there to the
|
|
46
|
+
users of that server. Therefore, public use of a modified version, on
|
|
47
|
+
a publicly accessible server, gives the public access to the source
|
|
48
|
+
code of the modified version.
|
|
49
|
+
|
|
50
|
+
An older license, called the Affero General Public License and
|
|
51
|
+
published by Affero, was designed to accomplish similar goals. This is
|
|
52
|
+
a different license, not a version of the Affero GPL, but Affero has
|
|
53
|
+
released a new version of the Affero GPL which permits relicensing under
|
|
54
|
+
this license.
|
|
67
55
|
|
|
68
56
|
The precise terms and conditions for copying, distribution and
|
|
69
57
|
modification follow.
|
|
@@ -72,7 +60,7 @@ modification follow.
|
|
|
72
60
|
|
|
73
61
|
0. Definitions.
|
|
74
62
|
|
|
75
|
-
"This License" refers to version 3 of the GNU General Public License.
|
|
63
|
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
|
76
64
|
|
|
77
65
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
78
66
|
works, such as semiconductor masks.
|
|
@@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
|
|
|
549
537
|
the Program, the only way you could satisfy both those terms and this
|
|
550
538
|
License would be to refrain entirely from conveying the Program.
|
|
551
539
|
|
|
552
|
-
13. Use with the GNU
|
|
540
|
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
|
541
|
+
|
|
542
|
+
Notwithstanding any other provision of this License, if you modify the
|
|
543
|
+
Program, your modified version must prominently offer all users
|
|
544
|
+
interacting with it remotely through a computer network (if your version
|
|
545
|
+
supports such interaction) an opportunity to receive the Corresponding
|
|
546
|
+
Source of your version by providing access to the Corresponding Source
|
|
547
|
+
from a network server at no charge, through some standard or customary
|
|
548
|
+
means of facilitating copying of software. This Corresponding Source
|
|
549
|
+
shall include the Corresponding Source for any work covered by version 3
|
|
550
|
+
of the GNU General Public License that is incorporated pursuant to the
|
|
551
|
+
following paragraph.
|
|
553
552
|
|
|
554
553
|
Notwithstanding any other provision of this License, you have
|
|
555
554
|
permission to link or combine any covered work with a work licensed
|
|
556
|
-
under version 3 of the GNU
|
|
555
|
+
under version 3 of the GNU General Public License into a single
|
|
557
556
|
combined work, and to convey the resulting work. The terms of this
|
|
558
557
|
License will continue to apply to the part which is the covered work,
|
|
559
|
-
but the
|
|
560
|
-
|
|
561
|
-
combination as such.
|
|
558
|
+
but the work with which it is combined will remain governed by version
|
|
559
|
+
3 of the GNU General Public License.
|
|
562
560
|
|
|
563
561
|
14. Revised Versions of this License.
|
|
564
562
|
|
|
565
563
|
The Free Software Foundation may publish revised and/or new versions of
|
|
566
|
-
the GNU General Public License from time to time. Such new versions
|
|
567
|
-
be similar in spirit to the present version, but may differ in detail to
|
|
564
|
+
the GNU Affero General Public License from time to time. Such new versions
|
|
565
|
+
will be similar in spirit to the present version, but may differ in detail to
|
|
568
566
|
address new problems or concerns.
|
|
569
567
|
|
|
570
568
|
Each version is given a distinguishing version number. If the
|
|
571
|
-
Program specifies that a certain numbered version of the GNU General
|
|
569
|
+
Program specifies that a certain numbered version of the GNU Affero General
|
|
572
570
|
Public License "or any later version" applies to it, you have the
|
|
573
571
|
option of following the terms and conditions either of that numbered
|
|
574
572
|
version or of any later version published by the Free Software
|
|
575
573
|
Foundation. If the Program does not specify a version number of the
|
|
576
|
-
GNU General Public License, you may choose any version ever published
|
|
574
|
+
GNU Affero General Public License, you may choose any version ever published
|
|
577
575
|
by the Free Software Foundation.
|
|
578
576
|
|
|
579
577
|
If the Program specifies that a proxy can decide which future
|
|
580
|
-
versions of the GNU General Public License can be used, that proxy's
|
|
578
|
+
versions of the GNU Affero General Public License can be used, that proxy's
|
|
581
579
|
public statement of acceptance of a version permanently authorizes you
|
|
582
580
|
to choose that version for the Program.
|
|
583
581
|
|
|
@@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
|
|
|
635
633
|
Copyright (C) <year> <name of author>
|
|
636
634
|
|
|
637
635
|
This program is free software: you can redistribute it and/or modify
|
|
638
|
-
it under the terms of the GNU General Public License as published
|
|
639
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
636
|
+
it under the terms of the GNU Affero General Public License as published
|
|
637
|
+
by the Free Software Foundation, either version 3 of the License, or
|
|
640
638
|
(at your option) any later version.
|
|
641
639
|
|
|
642
640
|
This program is distributed in the hope that it will be useful,
|
|
643
641
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
644
642
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
645
|
-
GNU General Public License for more details.
|
|
643
|
+
GNU Affero General Public License for more details.
|
|
646
644
|
|
|
647
|
-
You should have received a copy of the GNU General Public License
|
|
645
|
+
You should have received a copy of the GNU Affero General Public License
|
|
648
646
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
649
647
|
|
|
650
648
|
Also add information on how to contact you by electronic and paper mail.
|
|
651
649
|
|
|
652
|
-
If
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
661
|
-
parts of the General Public License. Of course, your program's commands
|
|
662
|
-
might be different; for a GUI interface, you would use an "about box".
|
|
650
|
+
If your software can interact with users remotely through a computer
|
|
651
|
+
network, you should also make sure that it provides a way for users to
|
|
652
|
+
get its source. For example, if your program is a web application, its
|
|
653
|
+
interface could display a "Source" link that leads users to an archive
|
|
654
|
+
of the code. There are many ways you could offer source, and different
|
|
655
|
+
solutions will be better for different programs; see section 13 for the
|
|
656
|
+
specific requirements.
|
|
663
657
|
|
|
664
658
|
You should also get your employer (if you work as a programmer) or school,
|
|
665
659
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
666
|
-
For more information on this, and how to apply and follow the GNU
|
|
660
|
+
For more information on this, and how to apply and follow the GNU AGPL, see
|
|
667
661
|
<https://www.gnu.org/licenses/>.
|
|
668
|
-
|
|
669
|
-
The GNU General Public License does not permit incorporating your program
|
|
670
|
-
into proprietary programs. If your program is a subroutine library, you
|
|
671
|
-
may consider it more useful to permit linking proprietary applications with
|
|
672
|
-
the library. If this is what you want to do, use the GNU Lesser General
|
|
673
|
-
Public License instead of this License. But first, please read
|
|
674
|
-
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
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.
|
|
@@ -249,7 +252,7 @@ interface paths {
|
|
|
249
252
|
[key: string]: unknown;
|
|
250
253
|
};
|
|
251
254
|
/**
|
|
252
|
-
* @description A list of roles that this key should have.
|
|
255
|
+
* @description A list of roles that this key should have. If the role does not exist, an error is thrown
|
|
253
256
|
* @example [
|
|
254
257
|
* "admin",
|
|
255
258
|
* "finance"
|
|
@@ -1146,112 +1149,6 @@ interface paths {
|
|
|
1146
1149
|
};
|
|
1147
1150
|
};
|
|
1148
1151
|
};
|
|
1149
|
-
"/v1/keys/:keyId": {
|
|
1150
|
-
get: {
|
|
1151
|
-
responses: {
|
|
1152
|
-
/** @description The configuration for a single key */
|
|
1153
|
-
200: {
|
|
1154
|
-
content: {
|
|
1155
|
-
"application/json": components["schemas"]["Key"];
|
|
1156
|
-
};
|
|
1157
|
-
};
|
|
1158
|
-
/** @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). */
|
|
1159
|
-
400: {
|
|
1160
|
-
content: {
|
|
1161
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1162
|
-
};
|
|
1163
|
-
};
|
|
1164
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1165
|
-
401: {
|
|
1166
|
-
content: {
|
|
1167
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1168
|
-
};
|
|
1169
|
-
};
|
|
1170
|
-
/** @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. */
|
|
1171
|
-
403: {
|
|
1172
|
-
content: {
|
|
1173
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1174
|
-
};
|
|
1175
|
-
};
|
|
1176
|
-
/** @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. */
|
|
1177
|
-
404: {
|
|
1178
|
-
content: {
|
|
1179
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1180
|
-
};
|
|
1181
|
-
};
|
|
1182
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1183
|
-
409: {
|
|
1184
|
-
content: {
|
|
1185
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1186
|
-
};
|
|
1187
|
-
};
|
|
1188
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1189
|
-
429: {
|
|
1190
|
-
content: {
|
|
1191
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1192
|
-
};
|
|
1193
|
-
};
|
|
1194
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1195
|
-
500: {
|
|
1196
|
-
content: {
|
|
1197
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1198
|
-
};
|
|
1199
|
-
};
|
|
1200
|
-
};
|
|
1201
|
-
};
|
|
1202
|
-
delete: {
|
|
1203
|
-
responses: {
|
|
1204
|
-
/** @description The key was successfully revoked, it may take up to 30s for this to take effect in all regions */
|
|
1205
|
-
200: {
|
|
1206
|
-
content: {
|
|
1207
|
-
"application/json": Record<string, never>;
|
|
1208
|
-
};
|
|
1209
|
-
};
|
|
1210
|
-
/** @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). */
|
|
1211
|
-
400: {
|
|
1212
|
-
content: {
|
|
1213
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1214
|
-
};
|
|
1215
|
-
};
|
|
1216
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1217
|
-
401: {
|
|
1218
|
-
content: {
|
|
1219
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1220
|
-
};
|
|
1221
|
-
};
|
|
1222
|
-
/** @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. */
|
|
1223
|
-
403: {
|
|
1224
|
-
content: {
|
|
1225
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1226
|
-
};
|
|
1227
|
-
};
|
|
1228
|
-
/** @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. */
|
|
1229
|
-
404: {
|
|
1230
|
-
content: {
|
|
1231
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1232
|
-
};
|
|
1233
|
-
};
|
|
1234
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1235
|
-
409: {
|
|
1236
|
-
content: {
|
|
1237
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1238
|
-
};
|
|
1239
|
-
};
|
|
1240
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1241
|
-
429: {
|
|
1242
|
-
content: {
|
|
1243
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1244
|
-
};
|
|
1245
|
-
};
|
|
1246
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1247
|
-
500: {
|
|
1248
|
-
content: {
|
|
1249
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1250
|
-
};
|
|
1251
|
-
};
|
|
1252
|
-
};
|
|
1253
|
-
};
|
|
1254
|
-
};
|
|
1255
1152
|
"/v1/keys": {
|
|
1256
1153
|
post: {
|
|
1257
1154
|
requestBody: {
|
|
@@ -1505,11 +1402,12 @@ interface paths {
|
|
|
1505
1402
|
* - FORBIDDEN: the key is not allowed to access the api
|
|
1506
1403
|
* - USAGE_EXCEEDED: the key has exceeded its request limit
|
|
1507
1404
|
* - RATE_LIMITED: the key has been ratelimited,
|
|
1405
|
+
* - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
|
|
1508
1406
|
*
|
|
1509
1407
|
* @example NOT_FOUND
|
|
1510
1408
|
* @enum {string}
|
|
1511
1409
|
*/
|
|
1512
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED";
|
|
1410
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS";
|
|
1513
1411
|
};
|
|
1514
1412
|
};
|
|
1515
1413
|
};
|
|
@@ -1558,6 +1456,60 @@ interface paths {
|
|
|
1558
1456
|
};
|
|
1559
1457
|
};
|
|
1560
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
|
+
};
|
|
1561
1513
|
"/v1/apis": {
|
|
1562
1514
|
post: {
|
|
1563
1515
|
requestBody: {
|
|
@@ -2107,6 +2059,14 @@ interface components {
|
|
|
2107
2059
|
* ]
|
|
2108
2060
|
*/
|
|
2109
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[];
|
|
2110
2070
|
/**
|
|
2111
2071
|
* @description Sets if key is enabled or disabled. Disabled keys are not valid.
|
|
2112
2072
|
* @example true
|
|
@@ -2192,11 +2152,21 @@ interface components {
|
|
|
2192
2152
|
* - RATE_LIMITED: the key has been ratelimited
|
|
2193
2153
|
* - UNAUTHORIZED: the key is not authorized
|
|
2194
2154
|
* - DISABLED: the key is disabled
|
|
2155
|
+
* - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
|
|
2156
|
+
*
|
|
2195
2157
|
* @enum {string}
|
|
2196
2158
|
*/
|
|
2197
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED";
|
|
2159
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS";
|
|
2198
2160
|
/** @description Sets the key to be enabled or disabled. Disabled keys will not verify. */
|
|
2199
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[];
|
|
2200
2170
|
};
|
|
2201
2171
|
V1KeysVerifyKeyRequest: {
|
|
2202
2172
|
/**
|
|
@@ -2210,6 +2180,24 @@ interface components {
|
|
|
2210
2180
|
* @example sk_1234
|
|
2211
2181
|
*/
|
|
2212
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
|
+
};
|
|
2213
2201
|
};
|
|
2214
2202
|
};
|
|
2215
2203
|
responses: never;
|
|
@@ -2306,7 +2294,17 @@ declare class Unkey {
|
|
|
2306
2294
|
get keys(): {
|
|
2307
2295
|
create: (req: paths["/v1/keys.createKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.createKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2308
2296
|
update: (req: paths["/v1/keys.updateKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.updateKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2309
|
-
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"]>>;
|
|
2310
2308
|
delete: (req: paths["/v1/keys.deleteKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.deleteKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2311
2309
|
updateRemaining: (req: paths["/v1/keys.updateRemaining"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.updateRemaining"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2312
2310
|
get: (req: paths["/v1/keys.getKey"]["get"]["parameters"]["query"]) => Promise<Result<paths["/v1/keys.getKey"]["get"]["responses"]["200"]["content"]["application/json"]>>;
|
|
@@ -2368,10 +2366,11 @@ declare function verifyKey(req: string | {
|
|
|
2368
2366
|
reset: number;
|
|
2369
2367
|
} | undefined;
|
|
2370
2368
|
remaining?: number | undefined;
|
|
2371
|
-
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;
|
|
2372
2370
|
enabled?: boolean | undefined;
|
|
2371
|
+
permissions?: string[] | undefined;
|
|
2373
2372
|
};
|
|
2374
2373
|
error?: undefined;
|
|
2375
2374
|
}>;
|
|
2376
2375
|
|
|
2377
|
-
export { ErrorResponse, Unkey, UnkeyOptions, verifyKey };
|
|
2376
|
+
export { type ErrorResponse, Unkey, type UnkeyOptions, verifyKey };
|
package/dist/index.d.ts
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.
|
|
@@ -249,7 +252,7 @@ interface paths {
|
|
|
249
252
|
[key: string]: unknown;
|
|
250
253
|
};
|
|
251
254
|
/**
|
|
252
|
-
* @description A list of roles that this key should have.
|
|
255
|
+
* @description A list of roles that this key should have. If the role does not exist, an error is thrown
|
|
253
256
|
* @example [
|
|
254
257
|
* "admin",
|
|
255
258
|
* "finance"
|
|
@@ -1146,112 +1149,6 @@ interface paths {
|
|
|
1146
1149
|
};
|
|
1147
1150
|
};
|
|
1148
1151
|
};
|
|
1149
|
-
"/v1/keys/:keyId": {
|
|
1150
|
-
get: {
|
|
1151
|
-
responses: {
|
|
1152
|
-
/** @description The configuration for a single key */
|
|
1153
|
-
200: {
|
|
1154
|
-
content: {
|
|
1155
|
-
"application/json": components["schemas"]["Key"];
|
|
1156
|
-
};
|
|
1157
|
-
};
|
|
1158
|
-
/** @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). */
|
|
1159
|
-
400: {
|
|
1160
|
-
content: {
|
|
1161
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1162
|
-
};
|
|
1163
|
-
};
|
|
1164
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1165
|
-
401: {
|
|
1166
|
-
content: {
|
|
1167
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1168
|
-
};
|
|
1169
|
-
};
|
|
1170
|
-
/** @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. */
|
|
1171
|
-
403: {
|
|
1172
|
-
content: {
|
|
1173
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1174
|
-
};
|
|
1175
|
-
};
|
|
1176
|
-
/** @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. */
|
|
1177
|
-
404: {
|
|
1178
|
-
content: {
|
|
1179
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1180
|
-
};
|
|
1181
|
-
};
|
|
1182
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1183
|
-
409: {
|
|
1184
|
-
content: {
|
|
1185
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1186
|
-
};
|
|
1187
|
-
};
|
|
1188
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1189
|
-
429: {
|
|
1190
|
-
content: {
|
|
1191
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1192
|
-
};
|
|
1193
|
-
};
|
|
1194
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1195
|
-
500: {
|
|
1196
|
-
content: {
|
|
1197
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1198
|
-
};
|
|
1199
|
-
};
|
|
1200
|
-
};
|
|
1201
|
-
};
|
|
1202
|
-
delete: {
|
|
1203
|
-
responses: {
|
|
1204
|
-
/** @description The key was successfully revoked, it may take up to 30s for this to take effect in all regions */
|
|
1205
|
-
200: {
|
|
1206
|
-
content: {
|
|
1207
|
-
"application/json": Record<string, never>;
|
|
1208
|
-
};
|
|
1209
|
-
};
|
|
1210
|
-
/** @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). */
|
|
1211
|
-
400: {
|
|
1212
|
-
content: {
|
|
1213
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1214
|
-
};
|
|
1215
|
-
};
|
|
1216
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1217
|
-
401: {
|
|
1218
|
-
content: {
|
|
1219
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1220
|
-
};
|
|
1221
|
-
};
|
|
1222
|
-
/** @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. */
|
|
1223
|
-
403: {
|
|
1224
|
-
content: {
|
|
1225
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1226
|
-
};
|
|
1227
|
-
};
|
|
1228
|
-
/** @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. */
|
|
1229
|
-
404: {
|
|
1230
|
-
content: {
|
|
1231
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1232
|
-
};
|
|
1233
|
-
};
|
|
1234
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1235
|
-
409: {
|
|
1236
|
-
content: {
|
|
1237
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1238
|
-
};
|
|
1239
|
-
};
|
|
1240
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1241
|
-
429: {
|
|
1242
|
-
content: {
|
|
1243
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1244
|
-
};
|
|
1245
|
-
};
|
|
1246
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1247
|
-
500: {
|
|
1248
|
-
content: {
|
|
1249
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1250
|
-
};
|
|
1251
|
-
};
|
|
1252
|
-
};
|
|
1253
|
-
};
|
|
1254
|
-
};
|
|
1255
1152
|
"/v1/keys": {
|
|
1256
1153
|
post: {
|
|
1257
1154
|
requestBody: {
|
|
@@ -1505,11 +1402,12 @@ interface paths {
|
|
|
1505
1402
|
* - FORBIDDEN: the key is not allowed to access the api
|
|
1506
1403
|
* - USAGE_EXCEEDED: the key has exceeded its request limit
|
|
1507
1404
|
* - RATE_LIMITED: the key has been ratelimited,
|
|
1405
|
+
* - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
|
|
1508
1406
|
*
|
|
1509
1407
|
* @example NOT_FOUND
|
|
1510
1408
|
* @enum {string}
|
|
1511
1409
|
*/
|
|
1512
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED";
|
|
1410
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS";
|
|
1513
1411
|
};
|
|
1514
1412
|
};
|
|
1515
1413
|
};
|
|
@@ -1558,6 +1456,60 @@ interface paths {
|
|
|
1558
1456
|
};
|
|
1559
1457
|
};
|
|
1560
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
|
+
};
|
|
1561
1513
|
"/v1/apis": {
|
|
1562
1514
|
post: {
|
|
1563
1515
|
requestBody: {
|
|
@@ -2107,6 +2059,14 @@ interface components {
|
|
|
2107
2059
|
* ]
|
|
2108
2060
|
*/
|
|
2109
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[];
|
|
2110
2070
|
/**
|
|
2111
2071
|
* @description Sets if key is enabled or disabled. Disabled keys are not valid.
|
|
2112
2072
|
* @example true
|
|
@@ -2192,11 +2152,21 @@ interface components {
|
|
|
2192
2152
|
* - RATE_LIMITED: the key has been ratelimited
|
|
2193
2153
|
* - UNAUTHORIZED: the key is not authorized
|
|
2194
2154
|
* - DISABLED: the key is disabled
|
|
2155
|
+
* - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
|
|
2156
|
+
*
|
|
2195
2157
|
* @enum {string}
|
|
2196
2158
|
*/
|
|
2197
|
-
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED";
|
|
2159
|
+
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS";
|
|
2198
2160
|
/** @description Sets the key to be enabled or disabled. Disabled keys will not verify. */
|
|
2199
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[];
|
|
2200
2170
|
};
|
|
2201
2171
|
V1KeysVerifyKeyRequest: {
|
|
2202
2172
|
/**
|
|
@@ -2210,6 +2180,24 @@ interface components {
|
|
|
2210
2180
|
* @example sk_1234
|
|
2211
2181
|
*/
|
|
2212
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
|
+
};
|
|
2213
2201
|
};
|
|
2214
2202
|
};
|
|
2215
2203
|
responses: never;
|
|
@@ -2306,7 +2294,17 @@ declare class Unkey {
|
|
|
2306
2294
|
get keys(): {
|
|
2307
2295
|
create: (req: paths["/v1/keys.createKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.createKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2308
2296
|
update: (req: paths["/v1/keys.updateKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.updateKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2309
|
-
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"]>>;
|
|
2310
2308
|
delete: (req: paths["/v1/keys.deleteKey"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.deleteKey"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2311
2309
|
updateRemaining: (req: paths["/v1/keys.updateRemaining"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/keys.updateRemaining"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2312
2310
|
get: (req: paths["/v1/keys.getKey"]["get"]["parameters"]["query"]) => Promise<Result<paths["/v1/keys.getKey"]["get"]["responses"]["200"]["content"]["application/json"]>>;
|
|
@@ -2368,10 +2366,11 @@ declare function verifyKey(req: string | {
|
|
|
2368
2366
|
reset: number;
|
|
2369
2367
|
} | undefined;
|
|
2370
2368
|
remaining?: number | undefined;
|
|
2371
|
-
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;
|
|
2372
2370
|
enabled?: boolean | undefined;
|
|
2371
|
+
permissions?: string[] | undefined;
|
|
2373
2372
|
};
|
|
2374
2373
|
error?: undefined;
|
|
2375
2374
|
}>;
|
|
2376
2375
|
|
|
2377
|
-
export { ErrorResponse, Unkey, UnkeyOptions, verifyKey };
|
|
2376
|
+
export { type ErrorResponse, Unkey, type UnkeyOptions, verifyKey };
|
package/dist/index.js
CHANGED
|
@@ -21,12 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Unkey: () => Unkey,
|
|
24
|
+
and: () => import_rbac.and,
|
|
25
|
+
or: () => import_rbac.or,
|
|
24
26
|
verifyKey: () => verifyKey
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(src_exports);
|
|
27
29
|
|
|
28
30
|
// package.json
|
|
29
|
-
var version = "0.
|
|
31
|
+
var version = "0.18.0";
|
|
30
32
|
|
|
31
33
|
// src/telemetry.ts
|
|
32
34
|
function getTelemetry(opts) {
|
|
@@ -236,9 +238,14 @@ function verifyKey(req) {
|
|
|
236
238
|
const unkey = new Unkey({ rootKey: "public" });
|
|
237
239
|
return unkey.keys.verify(typeof req === "string" ? { key: req } : req);
|
|
238
240
|
}
|
|
241
|
+
|
|
242
|
+
// src/index.ts
|
|
243
|
+
var import_rbac = require("@unkey/rbac");
|
|
239
244
|
// Annotate the CommonJS export names for ESM import in node:
|
|
240
245
|
0 && (module.exports = {
|
|
241
246
|
Unkey,
|
|
247
|
+
and,
|
|
248
|
+
or,
|
|
242
249
|
verifyKey
|
|
243
250
|
});
|
|
244
251
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../package.json","../src/telemetry.ts","../src/client.ts","../src/verify.ts"],"sourcesContent":["export * from \"./client\";\nexport * from \"./verify\";\nexport * from \"./errors\";\n","{\n \"name\": \"@unkey/api\",\n \"version\": \"0.17.0\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"keywords\": [\n \"unkey\",\n \"client\",\n \"api\"\n ],\n \"bugs\": {\n \"url\": \"https://github.com/unkeyed/unkey/issues\"\n },\n \"homepage\": \"https://github.com/unkeyed/unkey#readme\",\n \"files\": [\n \"./dist/**\"\n ],\n \"author\": \"Andreas Thomas <andreas@chronark.com>\",\n \"scripts\": {\n \"generate\": \"openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts\",\n \"build\": \"pnpm generate && tsup\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.11.5\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.2\",\n \"tsup\": \"^7.2.0\",\n \"typescript\": \"^5.2.2\"\n }\n}\n","import { version } from \"../package.json\";\nimport { UnkeyOptions } from \"./client\";\n\nexport type Telemetry = {\n /**\n * Unkey-Telemetry-Sdk\n * @example @unkey/api@v1.1.1\n */\n sdkVersions: string[];\n /**\n * Unkey-Telemetry-Platform\n * @example cloudflare\n */\n platform?: string;\n /**\n * Unkey-Telemetry-Runtime\n * @example node@v18\n */\n runtime?: string;\n};\n\nexport function getTelemetry(opts: UnkeyOptions): Telemetry | null {\n let platform: string | undefined;\n let runtime: string | undefined;\n const sdkVersions = [`@unkey/api@${version}`];\n\n try {\n if (typeof process !== \"undefined\") {\n if (process.env.UNKEY_DISABLE_TELEMETRY) {\n return null;\n }\n platform = process.env.VERCEL ? \"vercel\" : process.env.AWS_REGION ? \"aws\" : undefined;\n\n // @ts-ignore\n if (typeof EdgeRuntime !== \"undefined\") {\n runtime = \"edge-light\";\n } else {\n runtime = `node@${process.version}`;\n }\n }\n\n if (opts.wrapperSdkVersion) {\n sdkVersions.push(opts.wrapperSdkVersion);\n }\n } catch (_error) {}\n\n return { platform, runtime, sdkVersions };\n}\n","import { ErrorResponse } from \"./errors\";\nimport type { paths } from \"./openapi\";\n\nimport { type Telemetry, getTelemetry } from \"./telemetry\";\n\nexport type UnkeyOptions = (\n | {\n token?: never;\n\n /**\n * The root key from unkey.dev.\n *\n * You can create/manage your root keys here:\n * https://unkey.dev/app/settings/root-keys\n */\n rootKey: string;\n }\n | {\n /**\n * The workspace key from unkey.dev\n *\n * @deprecated Use `rootKey`\n */\n token: string;\n rootKey?: never;\n }\n) & {\n /**\n * @default https://api.unkey.dev\n */\n baseUrl?: string;\n\n /**\n *\n * By default telemetry data is enabled, and sends:\n * runtime (Node.js / Edge)\n * platform (Node.js / Vercel / AWS)\n * SDK version\n */\n disableTelemetry?: boolean;\n\n /**\n * Retry on network errors\n */\n retry?: {\n /**\n * How many attempts should be made\n * The maximum number of requests will be `attempts + 1`\n * `0` means no retries\n *\n * @default 5\n */\n attempts?: number;\n /**\n * Return how many milliseconds to wait until the next attempt is made\n *\n * @default `(retryCount) => Math.round(Math.exp(retryCount) * 10)),`\n */\n backoff?: (retryCount: number) => number;\n };\n /**\n * Customize the `fetch` cache behaviour\n */\n cache?: RequestCache;\n\n /**\n * The version of the SDK instantiating this client.\n *\n * This is used for internal metrics and is not covered by semver, and may change at any time.\n *\n * You can leave this blank unless you are building a wrapper around this SDK.\n */\n wrapperSdkVersion?: string;\n};\n\ntype ApiRequest = {\n path: string[];\n} & (\n | {\n method: \"GET\";\n body?: never;\n query?: Record<string, string | number | boolean | null>;\n }\n | {\n method: \"POST\";\n body?: unknown;\n query?: never;\n }\n);\n\ntype Result<R> =\n | {\n result: R;\n error?: never;\n }\n | {\n result?: never;\n error: ErrorResponse[\"error\"];\n };\n\nexport class Unkey {\n public readonly baseUrl: string;\n private readonly rootKey: string;\n private readonly cache?: RequestCache;\n private readonly telemetry?: Telemetry | null;\n\n public readonly retry: {\n attempts: number;\n backoff: (retryCount: number) => number;\n };\n\n constructor(opts: UnkeyOptions) {\n this.baseUrl = opts.baseUrl ?? \"https://api.unkey.dev\";\n this.rootKey = opts.rootKey ?? opts.token;\n if (!opts.disableTelemetry) {\n this.telemetry = getTelemetry(opts);\n }\n\n this.cache = opts.cache;\n /**\n * Even though typescript should prevent this, some people still pass undefined or empty strings\n */\n if (!this.rootKey) {\n throw new Error(\n \"Unkey root key must be set, maybe you passed in `undefined` or an empty string?\",\n );\n }\n\n this.retry = {\n attempts: opts.retry?.attempts ?? 5,\n backoff: opts.retry?.backoff ?? ((n) => Math.round(Math.exp(n) * 10)),\n };\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.rootKey}`,\n };\n if (this.telemetry?.sdkVersions) {\n headers[\"Unkey-Telemetry-SDK\"] = this.telemetry.sdkVersions.join(\",\");\n }\n if (this.telemetry?.platform) {\n headers[\"Unkey-Telemetry-Platform\"] = this.telemetry.platform;\n }\n if (this.telemetry?.runtime) {\n headers[\"Unkey-Telemetry-Runtime\"] = this.telemetry.runtime;\n }\n return headers;\n }\n\n private async fetch<TResult>(req: ApiRequest): Promise<Result<TResult>> {\n let res: Response | null = null;\n let err: Error | null = null;\n for (let i = 0; i <= this.retry.attempts; i++) {\n const url = new URL(`${this.baseUrl}/${req.path.join(\"/\")}`);\n if (req.query) {\n for (const [k, v] of Object.entries(req.query)) {\n if (v === null) {\n continue;\n }\n url.searchParams.set(k, v.toString());\n }\n }\n res = await fetch(url, {\n method: req.method,\n headers: this.getHeaders(),\n cache: this.cache,\n body: JSON.stringify(req.body),\n }).catch((e: Error) => {\n err = e;\n return null; // set `res` to `null`\n });\n if (res?.ok) {\n return { result: (await res.json()) as TResult };\n }\n const backoff = this.retry.backoff(i);\n console.debug(\n \"attempt %d of %d to reach %s failed, retrying in %d ms: %s\",\n i + 1,\n this.retry.attempts + 1,\n url,\n backoff,\n // @ts-ignore I don't understand why `err` is `never`\n err?.message,\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return { error: (await res.json()) as ErrorResponse[\"error\"] };\n }\n\n return {\n error: {\n // @ts-ignore\n code: \"FETCH_ERROR\",\n // @ts-ignore I don't understand why `err` is `never`\n message: err?.message ?? \"No response\",\n docs: \"https://developer.mozilla.org/en-US/docs/Web/API/fetch\",\n requestId: \"N/A\",\n },\n };\n }\n\n public get keys() {\n return {\n create: async (\n req: paths[\"/v1/keys.createKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.createKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.createKey\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/keys.updateKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateKey\"],\n method: \"POST\",\n body: req,\n });\n },\n verify: async (\n req: paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.verifyKey\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/keys.deleteKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.deleteKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.deleteKey\"],\n method: \"POST\",\n body: req,\n });\n },\n updateRemaining: async (\n req: paths[\"/v1/keys.updateRemaining\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateRemaining\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateRemaining\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/keys.getKey\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/keys.getKey\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getKey\"],\n method: \"GET\",\n query: req,\n });\n },\n getVerifications: async (\n req: paths[\"/v1/keys.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get apis() {\n return {\n create: async (\n req: paths[\"/v1/apis.createApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.createApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.createApi\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/apis.deleteApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.deleteApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.deleteApi\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/apis.getApi\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.getApi\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.getApi\"],\n method: \"GET\",\n query: req,\n });\n },\n listKeys: async (\n req: paths[\"/v1/apis.listKeys\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.listKeys\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.listKeys\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n}\n","import { Unkey } from \"./client\";\n\n/**\n * Verify a key\n *\n * @example\n * ```ts\n * const { result, error } = await verifyKey(\"key_123\")\n * if (error){\n * // handle potential network or bad request error\n * // a link to our docs will be in the `error.docs` field\n * console.error(error.message)\n * return\n * }\n * if (!result.valid) {\n * // do not grant access\n * return\n * }\n *\n * // process request\n * console.log(result)\n * ```\n */\nexport function verifyKey(req: string | { key: string; apiId: string }) {\n // yes this is empty to make typescript happy but we don't need a token for verifying keys\n // it's not the cleanest but it works for now :)\n const unkey = new Unkey({ rootKey: \"public\" });\n return unkey.keys.verify(typeof req === \"string\" ? { key: req } : req);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEE,cAAW;;;ACmBN,SAAS,aAAa,MAAsC;AACjE,MAAI;AACJ,MAAI;AACJ,QAAM,cAAc,CAAC,cAAc,OAAO,EAAE;AAE5C,MAAI;AACF,QAAI,OAAO,YAAY,aAAa;AAClC,UAAI,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,EACF;AAAA,EAEA,IAAW,OAAO;AAChB,WAAO;AAAA,MACL,QAAQ,OACN,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,gBAAgB;AAAA,UAC7B,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,MACA,QAAQ,OACN,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,gBAAgB;AAAA,UAC7B,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,MACA,KAAK,OACH,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,aAAa;AAAA,UAC1B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,MACA,UAAU,OACR,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,eAAe;AAAA,UAC5B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;ACxUO,SAAS,UAAU,KAA8C;AAGtE,QAAM,QAAQ,IAAI,MAAM,EAAE,SAAS,SAAS,CAAC;AAC7C,SAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../package.json","../src/telemetry.ts","../src/client.ts","../src/verify.ts"],"sourcesContent":["export * from \"./client\";\nexport * from \"./verify\";\nexport * from \"./errors\";\nexport { and, or, type Flatten } from \"@unkey/rbac\";\n","{\n \"name\": \"@unkey/api\",\n \"version\": \"0.18.0\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"keywords\": [\n \"unkey\",\n \"client\",\n \"api\"\n ],\n \"bugs\": {\n \"url\": \"https://github.com/unkeyed/unkey/issues\"\n },\n \"homepage\": \"https://github.com/unkeyed/unkey#readme\",\n \"files\": [\n \"./dist/**\"\n ],\n \"author\": \"Andreas Thomas <andreas@chronark.com>\",\n \"scripts\": {\n \"generate\": \"openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts\",\n \"build\": \"pnpm generate && tsup\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.11.19\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.4\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.3.3\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport { UnkeyOptions } from \"./client\";\n\nexport type Telemetry = {\n /**\n * Unkey-Telemetry-Sdk\n * @example @unkey/api@v1.1.1\n */\n sdkVersions: string[];\n /**\n * Unkey-Telemetry-Platform\n * @example cloudflare\n */\n platform?: string;\n /**\n * Unkey-Telemetry-Runtime\n * @example node@v18\n */\n runtime?: string;\n};\n\nexport function getTelemetry(opts: UnkeyOptions): Telemetry | null {\n let platform: string | undefined;\n let runtime: string | undefined;\n const sdkVersions = [`@unkey/api@${version}`];\n\n try {\n if (typeof process !== \"undefined\") {\n if (process.env.UNKEY_DISABLE_TELEMETRY) {\n return null;\n }\n platform = process.env.VERCEL ? \"vercel\" : process.env.AWS_REGION ? \"aws\" : undefined;\n\n // @ts-ignore\n if (typeof EdgeRuntime !== \"undefined\") {\n runtime = \"edge-light\";\n } else {\n runtime = `node@${process.version}`;\n }\n }\n\n if (opts.wrapperSdkVersion) {\n sdkVersions.push(opts.wrapperSdkVersion);\n }\n } catch (_error) {}\n\n return { platform, runtime, sdkVersions };\n}\n","import { PermissionQuery } from \"@unkey/rbac\";\nimport { ErrorResponse } from \"./errors\";\nimport type { paths } from \"./openapi\";\n\nimport { type Telemetry, getTelemetry } from \"./telemetry\";\n\nexport type UnkeyOptions = (\n | {\n token?: never;\n\n /**\n * The root key from unkey.dev.\n *\n * You can create/manage your root keys here:\n * https://unkey.dev/app/settings/root-keys\n */\n rootKey: string;\n }\n | {\n /**\n * The workspace key from unkey.dev\n *\n * @deprecated Use `rootKey`\n */\n token: string;\n rootKey?: never;\n }\n) & {\n /**\n * @default https://api.unkey.dev\n */\n baseUrl?: string;\n\n /**\n *\n * By default telemetry data is enabled, and sends:\n * runtime (Node.js / Edge)\n * platform (Node.js / Vercel / AWS)\n * SDK version\n */\n disableTelemetry?: boolean;\n\n /**\n * Retry on network errors\n */\n retry?: {\n /**\n * How many attempts should be made\n * The maximum number of requests will be `attempts + 1`\n * `0` means no retries\n *\n * @default 5\n */\n attempts?: number;\n /**\n * Return how many milliseconds to wait until the next attempt is made\n *\n * @default `(retryCount) => Math.round(Math.exp(retryCount) * 10)),`\n */\n backoff?: (retryCount: number) => number;\n };\n /**\n * Customize the `fetch` cache behaviour\n */\n cache?: RequestCache;\n\n /**\n * The version of the SDK instantiating this client.\n *\n * This is used for internal metrics and is not covered by semver, and may change at any time.\n *\n * You can leave this blank unless you are building a wrapper around this SDK.\n */\n wrapperSdkVersion?: string;\n};\n\ntype ApiRequest = {\n path: string[];\n} & (\n | {\n method: \"GET\";\n body?: never;\n query?: Record<string, string | number | boolean | null>;\n }\n | {\n method: \"POST\";\n body?: unknown;\n query?: never;\n }\n);\n\ntype Result<R> =\n | {\n result: R;\n error?: never;\n }\n | {\n result?: never;\n error: ErrorResponse[\"error\"];\n };\n\nexport class Unkey {\n public readonly baseUrl: string;\n private readonly rootKey: string;\n private readonly cache?: RequestCache;\n private readonly telemetry?: Telemetry | null;\n\n public readonly retry: {\n attempts: number;\n backoff: (retryCount: number) => number;\n };\n\n constructor(opts: UnkeyOptions) {\n this.baseUrl = opts.baseUrl ?? \"https://api.unkey.dev\";\n this.rootKey = opts.rootKey ?? opts.token;\n if (!opts.disableTelemetry) {\n this.telemetry = getTelemetry(opts);\n }\n\n this.cache = opts.cache;\n /**\n * Even though typescript should prevent this, some people still pass undefined or empty strings\n */\n if (!this.rootKey) {\n throw new Error(\n \"Unkey root key must be set, maybe you passed in `undefined` or an empty string?\",\n );\n }\n\n this.retry = {\n attempts: opts.retry?.attempts ?? 5,\n backoff: opts.retry?.backoff ?? ((n) => Math.round(Math.exp(n) * 10)),\n };\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.rootKey}`,\n };\n if (this.telemetry?.sdkVersions) {\n headers[\"Unkey-Telemetry-SDK\"] = this.telemetry.sdkVersions.join(\",\");\n }\n if (this.telemetry?.platform) {\n headers[\"Unkey-Telemetry-Platform\"] = this.telemetry.platform;\n }\n if (this.telemetry?.runtime) {\n headers[\"Unkey-Telemetry-Runtime\"] = this.telemetry.runtime;\n }\n return headers;\n }\n\n private async fetch<TResult>(req: ApiRequest): Promise<Result<TResult>> {\n let res: Response | null = null;\n let err: Error | null = null;\n for (let i = 0; i <= this.retry.attempts; i++) {\n const url = new URL(`${this.baseUrl}/${req.path.join(\"/\")}`);\n if (req.query) {\n for (const [k, v] of Object.entries(req.query)) {\n if (v === null) {\n continue;\n }\n url.searchParams.set(k, v.toString());\n }\n }\n res = await fetch(url, {\n method: req.method,\n headers: this.getHeaders(),\n cache: this.cache,\n body: JSON.stringify(req.body),\n }).catch((e: Error) => {\n err = e;\n return null; // set `res` to `null`\n });\n if (res?.ok) {\n return { result: (await res.json()) as TResult };\n }\n const backoff = this.retry.backoff(i);\n console.debug(\n \"attempt %d of %d to reach %s failed, retrying in %d ms: %s\",\n i + 1,\n this.retry.attempts + 1,\n url,\n backoff,\n // @ts-ignore I don't understand why `err` is `never`\n err?.message,\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return { error: (await res.json()) as ErrorResponse[\"error\"] };\n }\n\n return {\n error: {\n // @ts-ignore\n code: \"FETCH_ERROR\",\n // @ts-ignore I don't understand why `err` is `never`\n message: err?.message ?? \"No response\",\n docs: \"https://developer.mozilla.org/en-US/docs/Web/API/fetch\",\n requestId: \"N/A\",\n },\n };\n }\n\n public get keys() {\n return {\n create: async (\n req: paths[\"/v1/keys.createKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.createKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.createKey\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/keys.updateKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateKey\"],\n method: \"POST\",\n body: req,\n });\n },\n verify: async <TPermission extends string = string>(\n req: Omit<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n \"authorization\"\n > & { authorization?: { permissions: PermissionQuery<TPermission> } },\n ): Promise<\n Result<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.verifyKey\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/keys.deleteKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.deleteKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.deleteKey\"],\n method: \"POST\",\n body: req,\n });\n },\n updateRemaining: async (\n req: paths[\"/v1/keys.updateRemaining\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateRemaining\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateRemaining\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/keys.getKey\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/keys.getKey\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getKey\"],\n method: \"GET\",\n query: req,\n });\n },\n getVerifications: async (\n req: paths[\"/v1/keys.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get apis() {\n return {\n create: async (\n req: paths[\"/v1/apis.createApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.createApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.createApi\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/apis.deleteApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.deleteApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.deleteApi\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/apis.getApi\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.getApi\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.getApi\"],\n method: \"GET\",\n query: req,\n });\n },\n listKeys: async (\n req: paths[\"/v1/apis.listKeys\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.listKeys\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.listKeys\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n}\n","import { Unkey } from \"./client\";\n\n/**\n * Verify a key\n *\n * @example\n * ```ts\n * const { result, error } = await verifyKey(\"key_123\")\n * if (error){\n * // handle potential network or bad request error\n * // a link to our docs will be in the `error.docs` field\n * console.error(error.message)\n * return\n * }\n * if (!result.valid) {\n * // do not grant access\n * return\n * }\n *\n * // process request\n * console.log(result)\n * ```\n */\nexport function verifyKey(req: string | { key: string; apiId: string }) {\n // yes this is empty to make typescript happy but we don't need a token for verifying keys\n // it's not the cleanest but it works for now :)\n const unkey = new Unkey({ rootKey: \"public\" });\n return unkey.keys.verify(typeof req === \"string\" ? { key: req } : req);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEE,cAAW;;;ACmBN,SAAS,aAAa,MAAsC;AACjE,MAAI;AACJ,MAAI;AACJ,QAAM,cAAc,CAAC,cAAc,OAAO,EAAE;AAE5C,MAAI;AACF,QAAI,OAAO,YAAY,aAAa;AAClC,UAAI,QAAQ,IAAI,yBAAyB;AACvC,eAAO;AAAA,MACT;AACA,iBAAW,QAAQ,IAAI,SAAS,WAAW,QAAQ,IAAI,aAAa,QAAQ;AAG5E,UAAI,OAAO,gBAAgB,aAAa;AACtC,kBAAU;AAAA,MACZ,OAAO;AACL,kBAAU,QAAQ,QAAQ,OAAO;AAAA,MACnC;AAAA,IACF;AAEA,QAAI,KAAK,mBAAmB;AAC1B,kBAAY,KAAK,KAAK,iBAAiB;AAAA,IACzC;AAAA,EACF,SAAS,QAAQ;AAAA,EAAC;AAElB,SAAO,EAAE,UAAU,SA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AAAA,MACA,KAAK,OACH,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,aAAa;AAAA,UAC1B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,MACA,UAAU,OACR,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,eAAe;AAAA,UAC5B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;AC5UO,SAAS,UAAU,KAA8C;AAGtE,QAAM,QAAQ,IAAI,MAAM,EAAE,SAAS,SAAS,CAAC;AAC7C,SAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;;;AJzBA,kBAAsC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.18.0";
|
|
3
3
|
|
|
4
4
|
// src/telemetry.ts
|
|
5
5
|
function getTelemetry(opts) {
|
|
@@ -209,8 +209,13 @@ function verifyKey(req) {
|
|
|
209
209
|
const unkey = new Unkey({ rootKey: "public" });
|
|
210
210
|
return unkey.keys.verify(typeof req === "string" ? { key: req } : req);
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
// src/index.ts
|
|
214
|
+
import { and, or } from "@unkey/rbac";
|
|
212
215
|
export {
|
|
213
216
|
Unkey,
|
|
217
|
+
and,
|
|
218
|
+
or,
|
|
214
219
|
verifyKey
|
|
215
220
|
};
|
|
216
221
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/telemetry.ts","../src/client.ts","../src/verify.ts"],"sourcesContent":["{\n \"name\": \"@unkey/api\",\n \"version\": \"0.17.0\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"keywords\": [\n \"unkey\",\n \"client\",\n \"api\"\n ],\n \"bugs\": {\n \"url\": \"https://github.com/unkeyed/unkey/issues\"\n },\n \"homepage\": \"https://github.com/unkeyed/unkey#readme\",\n \"files\": [\n \"./dist/**\"\n ],\n \"author\": \"Andreas Thomas <andreas@chronark.com>\",\n \"scripts\": {\n \"generate\": \"openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts\",\n \"build\": \"pnpm generate && tsup\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.11.5\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.2\",\n \"tsup\": \"^7.2.0\",\n \"typescript\": \"^5.2.2\"\n }\n}\n","import { version } from \"../package.json\";\nimport { UnkeyOptions } from \"./client\";\n\nexport type Telemetry = {\n /**\n * Unkey-Telemetry-Sdk\n * @example @unkey/api@v1.1.1\n */\n sdkVersions: string[];\n /**\n * Unkey-Telemetry-Platform\n * @example cloudflare\n */\n platform?: string;\n /**\n * Unkey-Telemetry-Runtime\n * @example node@v18\n */\n runtime?: string;\n};\n\nexport function getTelemetry(opts: UnkeyOptions): Telemetry | null {\n let platform: string | undefined;\n let runtime: string | undefined;\n const sdkVersions = [`@unkey/api@${version}`];\n\n try {\n if (typeof process !== \"undefined\") {\n if (process.env.UNKEY_DISABLE_TELEMETRY) {\n return null;\n }\n platform = process.env.VERCEL ? \"vercel\" : process.env.AWS_REGION ? \"aws\" : undefined;\n\n // @ts-ignore\n if (typeof EdgeRuntime !== \"undefined\") {\n runtime = \"edge-light\";\n } else {\n runtime = `node@${process.version}`;\n }\n }\n\n if (opts.wrapperSdkVersion) {\n sdkVersions.push(opts.wrapperSdkVersion);\n }\n } catch (_error) {}\n\n return { platform, runtime, sdkVersions };\n}\n","import { ErrorResponse } from \"./errors\";\nimport type { paths } from \"./openapi\";\n\nimport { type Telemetry, getTelemetry } from \"./telemetry\";\n\nexport type UnkeyOptions = (\n | {\n token?: never;\n\n /**\n * The root key from unkey.dev.\n *\n * You can create/manage your root keys here:\n * https://unkey.dev/app/settings/root-keys\n */\n rootKey: string;\n }\n | {\n /**\n * The workspace key from unkey.dev\n *\n * @deprecated Use `rootKey`\n */\n token: string;\n rootKey?: never;\n }\n) & {\n /**\n * @default https://api.unkey.dev\n */\n baseUrl?: string;\n\n /**\n *\n * By default telemetry data is enabled, and sends:\n * runtime (Node.js / Edge)\n * platform (Node.js / Vercel / AWS)\n * SDK version\n */\n disableTelemetry?: boolean;\n\n /**\n * Retry on network errors\n */\n retry?: {\n /**\n * How many attempts should be made\n * The maximum number of requests will be `attempts + 1`\n * `0` means no retries\n *\n * @default 5\n */\n attempts?: number;\n /**\n * Return how many milliseconds to wait until the next attempt is made\n *\n * @default `(retryCount) => Math.round(Math.exp(retryCount) * 10)),`\n */\n backoff?: (retryCount: number) => number;\n };\n /**\n * Customize the `fetch` cache behaviour\n */\n cache?: RequestCache;\n\n /**\n * The version of the SDK instantiating this client.\n *\n * This is used for internal metrics and is not covered by semver, and may change at any time.\n *\n * You can leave this blank unless you are building a wrapper around this SDK.\n */\n wrapperSdkVersion?: string;\n};\n\ntype ApiRequest = {\n path: string[];\n} & (\n | {\n method: \"GET\";\n body?: never;\n query?: Record<string, string | number | boolean | null>;\n }\n | {\n method: \"POST\";\n body?: unknown;\n query?: never;\n }\n);\n\ntype Result<R> =\n | {\n result: R;\n error?: never;\n }\n | {\n result?: never;\n error: ErrorResponse[\"error\"];\n };\n\nexport class Unkey {\n public readonly baseUrl: string;\n private readonly rootKey: string;\n private readonly cache?: RequestCache;\n private readonly telemetry?: Telemetry | null;\n\n public readonly retry: {\n attempts: number;\n backoff: (retryCount: number) => number;\n };\n\n constructor(opts: UnkeyOptions) {\n this.baseUrl = opts.baseUrl ?? \"https://api.unkey.dev\";\n this.rootKey = opts.rootKey ?? opts.token;\n if (!opts.disableTelemetry) {\n this.telemetry = getTelemetry(opts);\n }\n\n this.cache = opts.cache;\n /**\n * Even though typescript should prevent this, some people still pass undefined or empty strings\n */\n if (!this.rootKey) {\n throw new Error(\n \"Unkey root key must be set, maybe you passed in `undefined` or an empty string?\",\n );\n }\n\n this.retry = {\n attempts: opts.retry?.attempts ?? 5,\n backoff: opts.retry?.backoff ?? ((n) => Math.round(Math.exp(n) * 10)),\n };\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.rootKey}`,\n };\n if (this.telemetry?.sdkVersions) {\n headers[\"Unkey-Telemetry-SDK\"] = this.telemetry.sdkVersions.join(\",\");\n }\n if (this.telemetry?.platform) {\n headers[\"Unkey-Telemetry-Platform\"] = this.telemetry.platform;\n }\n if (this.telemetry?.runtime) {\n headers[\"Unkey-Telemetry-Runtime\"] = this.telemetry.runtime;\n }\n return headers;\n }\n\n private async fetch<TResult>(req: ApiRequest): Promise<Result<TResult>> {\n let res: Response | null = null;\n let err: Error | null = null;\n for (let i = 0; i <= this.retry.attempts; i++) {\n const url = new URL(`${this.baseUrl}/${req.path.join(\"/\")}`);\n if (req.query) {\n for (const [k, v] of Object.entries(req.query)) {\n if (v === null) {\n continue;\n }\n url.searchParams.set(k, v.toString());\n }\n }\n res = await fetch(url, {\n method: req.method,\n headers: this.getHeaders(),\n cache: this.cache,\n body: JSON.stringify(req.body),\n }).catch((e: Error) => {\n err = e;\n return null; // set `res` to `null`\n });\n if (res?.ok) {\n return { result: (await res.json()) as TResult };\n }\n const backoff = this.retry.backoff(i);\n console.debug(\n \"attempt %d of %d to reach %s failed, retrying in %d ms: %s\",\n i + 1,\n this.retry.attempts + 1,\n url,\n backoff,\n // @ts-ignore I don't understand why `err` is `never`\n err?.message,\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return { error: (await res.json()) as ErrorResponse[\"error\"] };\n }\n\n return {\n error: {\n // @ts-ignore\n code: \"FETCH_ERROR\",\n // @ts-ignore I don't understand why `err` is `never`\n message: err?.message ?? \"No response\",\n docs: \"https://developer.mozilla.org/en-US/docs/Web/API/fetch\",\n requestId: \"N/A\",\n },\n };\n }\n\n public get keys() {\n return {\n create: async (\n req: paths[\"/v1/keys.createKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.createKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.createKey\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/keys.updateKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateKey\"],\n method: \"POST\",\n body: req,\n });\n },\n verify: async (\n req: paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.verifyKey\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/keys.deleteKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.deleteKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.deleteKey\"],\n method: \"POST\",\n body: req,\n });\n },\n updateRemaining: async (\n req: paths[\"/v1/keys.updateRemaining\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateRemaining\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateRemaining\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/keys.getKey\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/keys.getKey\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getKey\"],\n method: \"GET\",\n query: req,\n });\n },\n getVerifications: async (\n req: paths[\"/v1/keys.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get apis() {\n return {\n create: async (\n req: paths[\"/v1/apis.createApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.createApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.createApi\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/apis.deleteApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.deleteApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.deleteApi\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/apis.getApi\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.getApi\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.getApi\"],\n method: \"GET\",\n query: req,\n });\n },\n listKeys: async (\n req: paths[\"/v1/apis.listKeys\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.listKeys\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.listKeys\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n}\n","import { Unkey } from \"./client\";\n\n/**\n * Verify a key\n *\n * @example\n * ```ts\n * const { result, error } = await verifyKey(\"key_123\")\n * if (error){\n * // handle potential network or bad request error\n * // a link to our docs will be in the `error.docs` field\n * console.error(error.message)\n * return\n * }\n * if (!result.valid) {\n * // do not grant access\n * return\n * }\n *\n * // process request\n * console.log(result)\n * ```\n */\nexport function verifyKey(req: string | { key: string; apiId: string }) {\n // yes this is empty to make typescript happy but we don't need a token for verifying keys\n // it's not the cleanest but it works for now :)\n const unkey = new Unkey({ rootKey: \"public\" });\n return unkey.keys.verify(typeof req === \"string\" ? { key: req } : req);\n}\n"],"mappings":";AAEE,cAAW;;;ACmBN,SAAS,aAAa,MAAsC;AACjE,MAAI;AACJ,MAAI;AACJ,QAAM,cAAc,CAAC,cAAc,OAAO,EAAE;AAE5C,MAAI;AACF,QAAI,OAAO,YAAY,aAAa;AAClC,UAAI,QAAQ,IAAI,yBAAyB;AACvC,eAAO;AAAA,MACT;AACA,iBAAW,QAAQ,IAAI,SAAS,WAAW,QAAQ,IAAI,aAAa,QAAQ;AAG5E,UAAI,OAAO,gBAAgB,aAAa;AACtC,kBAAU;AAAA,MACZ,OAAO;AACL,kBAAU,QAAQ,QAAQ,OAAO;AAAA,MACnC;AAAA,IACF;AAEA,QAAI,KAAK,mBAAmB;AAC1B,kBAAY,KAAK,KAAK,iBAAiB;AAAA,IACzC;AAAA,EACF,SAAS,QAAQ;AAAA,EAAC;AAElB,SAAO,EAAE,UAAU,SAAS,YAAY;AAC1C;;;ACqDO,IAAM,QAAN,MAAY;AAAA,EACD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAED;AAAA,EAKhB,Y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AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,MACA,UAAU,OACR,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,eAAe;AAAA,UAC5B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;ACxUO,SAAS,UAAU,KAA8C;AAGtE,QAAM,QAAQ,IAAI,MAAM,EAAE,SAAS,SAAS,CAAC;AAC7C,SAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/telemetry.ts","../src/client.ts","../src/verify.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@unkey/api\",\n \"version\": \"0.18.0\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"keywords\": [\n \"unkey\",\n \"client\",\n \"api\"\n ],\n \"bugs\": {\n \"url\": \"https://github.com/unkeyed/unkey/issues\"\n },\n \"homepage\": \"https://github.com/unkeyed/unkey#readme\",\n \"files\": [\n \"./dist/**\"\n ],\n \"author\": \"Andreas Thomas <andreas@chronark.com>\",\n \"scripts\": {\n \"generate\": \"openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts\",\n \"build\": \"pnpm generate && tsup\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.11.19\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.4\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.3.3\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport { UnkeyOptions } from \"./client\";\n\nexport type Telemetry = {\n /**\n * Unkey-Telemetry-Sdk\n * @example @unkey/api@v1.1.1\n */\n sdkVersions: string[];\n /**\n * Unkey-Telemetry-Platform\n * @example cloudflare\n */\n platform?: string;\n /**\n * Unkey-Telemetry-Runtime\n * @example node@v18\n */\n runtime?: string;\n};\n\nexport function getTelemetry(opts: UnkeyOptions): Telemetry | null {\n let platform: string | undefined;\n let runtime: string | undefined;\n const sdkVersions = [`@unkey/api@${version}`];\n\n try {\n if (typeof process !== \"undefined\") {\n if (process.env.UNKEY_DISABLE_TELEMETRY) {\n return null;\n }\n platform = process.env.VERCEL ? \"vercel\" : process.env.AWS_REGION ? \"aws\" : undefined;\n\n // @ts-ignore\n if (typeof EdgeRuntime !== \"undefined\") {\n runtime = \"edge-light\";\n } else {\n runtime = `node@${process.version}`;\n }\n }\n\n if (opts.wrapperSdkVersion) {\n sdkVersions.push(opts.wrapperSdkVersion);\n }\n } catch (_error) {}\n\n return { platform, runtime, sdkVersions };\n}\n","import { PermissionQuery } from \"@unkey/rbac\";\nimport { ErrorResponse } from \"./errors\";\nimport type { paths } from \"./openapi\";\n\nimport { type Telemetry, getTelemetry } from \"./telemetry\";\n\nexport type UnkeyOptions = (\n | {\n token?: never;\n\n /**\n * The root key from unkey.dev.\n *\n * You can create/manage your root keys here:\n * https://unkey.dev/app/settings/root-keys\n */\n rootKey: string;\n }\n | {\n /**\n * The workspace key from unkey.dev\n *\n * @deprecated Use `rootKey`\n */\n token: string;\n rootKey?: never;\n }\n) & {\n /**\n * @default https://api.unkey.dev\n */\n baseUrl?: string;\n\n /**\n *\n * By default telemetry data is enabled, and sends:\n * runtime (Node.js / Edge)\n * platform (Node.js / Vercel / AWS)\n * SDK version\n */\n disableTelemetry?: boolean;\n\n /**\n * Retry on network errors\n */\n retry?: {\n /**\n * How many attempts should be made\n * The maximum number of requests will be `attempts + 1`\n * `0` means no retries\n *\n * @default 5\n */\n attempts?: number;\n /**\n * Return how many milliseconds to wait until the next attempt is made\n *\n * @default `(retryCount) => Math.round(Math.exp(retryCount) * 10)),`\n */\n backoff?: (retryCount: number) => number;\n };\n /**\n * Customize the `fetch` cache behaviour\n */\n cache?: RequestCache;\n\n /**\n * The version of the SDK instantiating this client.\n *\n * This is used for internal metrics and is not covered by semver, and may change at any time.\n *\n * You can leave this blank unless you are building a wrapper around this SDK.\n */\n wrapperSdkVersion?: string;\n};\n\ntype ApiRequest = {\n path: string[];\n} & (\n | {\n method: \"GET\";\n body?: never;\n query?: Record<string, string | number | boolean | null>;\n }\n | {\n method: \"POST\";\n body?: unknown;\n query?: never;\n }\n);\n\ntype Result<R> =\n | {\n result: R;\n error?: never;\n }\n | {\n result?: never;\n error: ErrorResponse[\"error\"];\n };\n\nexport class Unkey {\n public readonly baseUrl: string;\n private readonly rootKey: string;\n private readonly cache?: RequestCache;\n private readonly telemetry?: Telemetry | null;\n\n public readonly retry: {\n attempts: number;\n backoff: (retryCount: number) => number;\n };\n\n constructor(opts: UnkeyOptions) {\n this.baseUrl = opts.baseUrl ?? \"https://api.unkey.dev\";\n this.rootKey = opts.rootKey ?? opts.token;\n if (!opts.disableTelemetry) {\n this.telemetry = getTelemetry(opts);\n }\n\n this.cache = opts.cache;\n /**\n * Even though typescript should prevent this, some people still pass undefined or empty strings\n */\n if (!this.rootKey) {\n throw new Error(\n \"Unkey root key must be set, maybe you passed in `undefined` or an empty string?\",\n );\n }\n\n this.retry = {\n attempts: opts.retry?.attempts ?? 5,\n backoff: opts.retry?.backoff ?? ((n) => Math.round(Math.exp(n) * 10)),\n };\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.rootKey}`,\n };\n if (this.telemetry?.sdkVersions) {\n headers[\"Unkey-Telemetry-SDK\"] = this.telemetry.sdkVersions.join(\",\");\n }\n if (this.telemetry?.platform) {\n headers[\"Unkey-Telemetry-Platform\"] = this.telemetry.platform;\n }\n if (this.telemetry?.runtime) {\n headers[\"Unkey-Telemetry-Runtime\"] = this.telemetry.runtime;\n }\n return headers;\n }\n\n private async fetch<TResult>(req: ApiRequest): Promise<Result<TResult>> {\n let res: Response | null = null;\n let err: Error | null = null;\n for (let i = 0; i <= this.retry.attempts; i++) {\n const url = new URL(`${this.baseUrl}/${req.path.join(\"/\")}`);\n if (req.query) {\n for (const [k, v] of Object.entries(req.query)) {\n if (v === null) {\n continue;\n }\n url.searchParams.set(k, v.toString());\n }\n }\n res = await fetch(url, {\n method: req.method,\n headers: this.getHeaders(),\n cache: this.cache,\n body: JSON.stringify(req.body),\n }).catch((e: Error) => {\n err = e;\n return null; // set `res` to `null`\n });\n if (res?.ok) {\n return { result: (await res.json()) as TResult };\n }\n const backoff = this.retry.backoff(i);\n console.debug(\n \"attempt %d of %d to reach %s failed, retrying in %d ms: %s\",\n i + 1,\n this.retry.attempts + 1,\n url,\n backoff,\n // @ts-ignore I don't understand why `err` is `never`\n err?.message,\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return { error: (await res.json()) as ErrorResponse[\"error\"] };\n }\n\n return {\n error: {\n // @ts-ignore\n code: \"FETCH_ERROR\",\n // @ts-ignore I don't understand why `err` is `never`\n message: err?.message ?? \"No response\",\n docs: \"https://developer.mozilla.org/en-US/docs/Web/API/fetch\",\n requestId: \"N/A\",\n },\n };\n }\n\n public get keys() {\n return {\n create: async (\n req: paths[\"/v1/keys.createKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.createKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.createKey\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/keys.updateKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateKey\"],\n method: \"POST\",\n body: req,\n });\n },\n verify: async <TPermission extends string = string>(\n req: Omit<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n \"authorization\"\n > & { authorization?: { permissions: PermissionQuery<TPermission> } },\n ): Promise<\n Result<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.verifyKey\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/keys.deleteKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.deleteKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.deleteKey\"],\n method: \"POST\",\n body: req,\n });\n },\n updateRemaining: async (\n req: paths[\"/v1/keys.updateRemaining\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateRemaining\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateRemaining\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/keys.getKey\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/keys.getKey\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getKey\"],\n method: \"GET\",\n query: req,\n });\n },\n getVerifications: async (\n req: paths[\"/v1/keys.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get apis() {\n return {\n create: async (\n req: paths[\"/v1/apis.createApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.createApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.createApi\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/apis.deleteApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.deleteApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.deleteApi\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/apis.getApi\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.getApi\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.getApi\"],\n method: \"GET\",\n query: req,\n });\n },\n listKeys: async (\n req: paths[\"/v1/apis.listKeys\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.listKeys\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.listKeys\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n}\n","import { Unkey } from \"./client\";\n\n/**\n * Verify a key\n *\n * @example\n * ```ts\n * const { result, error } = await verifyKey(\"key_123\")\n * if (error){\n * // handle potential network or bad request error\n * // a link to our docs will be in the `error.docs` field\n * console.error(error.message)\n * return\n * }\n * if (!result.valid) {\n * // do not grant access\n * return\n * }\n *\n * // process request\n * console.log(result)\n * ```\n */\nexport function verifyKey(req: string | { key: string; apiId: string }) {\n // yes this is empty to make typescript happy but we don't need a token for verifying keys\n // it's not the cleanest but it works for now :)\n const unkey = new Unkey({ rootKey: \"public\" });\n return unkey.keys.verify(typeof req === \"string\" ? { key: req } : req);\n}\n","export * from \"./client\";\nexport * from \"./verify\";\nexport * from \"./errors\";\nexport { and, or, type Flatten } from \"@unkey/rbac\";\n"],"mappings":";AAEE,cAAW;;;ACmBN,SAAS,aAAa,MAAsC;AACjE,MAAI;AACJ,MAAI;AACJ,QAAM,cAAc,CAAC,cAAc,OAAO,EAAE;AAE5C,MAAI;AACF,QAAI,OAAO,YAAY,aAAa;AAClC,UAAI,QAAQ,IAAI,yBAAyB;AACvC,eAAO;AAAA,MACT;AACA,iBAAW,QAAQ,IAAI,SAAS,WAAW,QAAQ,IAAI,aAAa,QAAQ;AAG5E,UAAI,OAAO,gBAAgB,aAAa;AACtC,kBAAU;AAAA,MACZ,OAAO;AACL,kBAAU,QAAQ,QAAQ,OAAO;AAAA,MACnC;AAAA,IACF;AAEA,QAAI,KAAK,mBAAmB;AAC1B,kBAAY,KAAK,KAAK,iBAAiB;AAAA,IACzC;AAAA,EACF,SAAS,QAAQ;AAAA,EAAC;AAElB,SAAO,EAAE,UAAU,SAAS,YAAY;AAC1C;;;ACsDO,IAAM,QAAN,MAAY;AAAA,EACD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAED;AAAA,EAKhB,YAAY,MAAoB;AAC9B,SAAK,UAAU,KAAK,WAAW;AAC/B,SAAK,UAAU,KAAK,WAAW,KAAK;AACpC,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,YAAY,aAAa,IAAI;AAAA,IACpC;AAEA,SAAK,QAAQ,KAAK;AAIlB,QAAI,CAAC,KAAK,SAAS;AACjB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,QAAQ;AAAA,MACX,UAAU,KAAK,OAAO,YAAY;AAAA,MAClC,SAAS,KAAK,OAAO,YAAY,CAAC,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE;AAAA,IACrE;AAAA,EACF;AAAA,E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|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unkey/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
5
6
|
"types": "./dist/index.d.ts",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"private": false,
|
|
@@ -22,12 +23,15 @@
|
|
|
22
23
|
],
|
|
23
24
|
"author": "Andreas Thomas <andreas@chronark.com>",
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^20.11.
|
|
26
|
-
"openapi-typescript": "^6.7.
|
|
27
|
-
"tsup": "^
|
|
28
|
-
"typescript": "^5.
|
|
26
|
+
"@types/node": "^20.11.19",
|
|
27
|
+
"openapi-typescript": "^6.7.4",
|
|
28
|
+
"tsup": "^8.0.2",
|
|
29
|
+
"typescript": "^5.3.3",
|
|
29
30
|
"@unkey/tsconfig": "^0.0.0"
|
|
30
31
|
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@unkey/rbac": "^1.0.0"
|
|
34
|
+
},
|
|
31
35
|
"scripts": {
|
|
32
36
|
"generate": "openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts",
|
|
33
37
|
"build": "pnpm generate && tsup"
|