@unkey/api 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +18 -446
- package/dist/index.d.ts +18 -446
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -314,6 +314,17 @@ interface paths {
|
|
|
314
314
|
* @example false
|
|
315
315
|
*/
|
|
316
316
|
enabled?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* @description Environments allow you to divide your keyspace.
|
|
319
|
+
*
|
|
320
|
+
* Some applications like Stripe, Clerk, WorkOS and others have a concept of "live" and "test" keys to
|
|
321
|
+
* give the developer a way to develop their own application without the risk of modifying real world
|
|
322
|
+
* resources.
|
|
323
|
+
*
|
|
324
|
+
* When you set an environment, we will return it back to you when validating the key, so you can
|
|
325
|
+
* handle it correctly.
|
|
326
|
+
*/
|
|
327
|
+
environment?: string;
|
|
317
328
|
};
|
|
318
329
|
};
|
|
319
330
|
};
|
|
@@ -673,7 +684,7 @@ interface paths {
|
|
|
673
684
|
};
|
|
674
685
|
};
|
|
675
686
|
responses: {
|
|
676
|
-
/** @description
|
|
687
|
+
/** @description Usage numbers over time */
|
|
677
688
|
200: {
|
|
678
689
|
content: {
|
|
679
690
|
"application/json": {
|
|
@@ -1029,126 +1040,6 @@ interface paths {
|
|
|
1029
1040
|
};
|
|
1030
1041
|
};
|
|
1031
1042
|
};
|
|
1032
|
-
"/v1/keys/{keyId}": {
|
|
1033
|
-
put: {
|
|
1034
|
-
parameters: {
|
|
1035
|
-
path: {
|
|
1036
|
-
keyId: string;
|
|
1037
|
-
};
|
|
1038
|
-
};
|
|
1039
|
-
requestBody: {
|
|
1040
|
-
content: {
|
|
1041
|
-
"application/json": {
|
|
1042
|
-
/**
|
|
1043
|
-
* @description The name of the key
|
|
1044
|
-
* @example Customer X
|
|
1045
|
-
*/
|
|
1046
|
-
name?: string | null;
|
|
1047
|
-
/**
|
|
1048
|
-
* @description The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API.
|
|
1049
|
-
* @example user_123
|
|
1050
|
-
*/
|
|
1051
|
-
ownerId?: string | null;
|
|
1052
|
-
/**
|
|
1053
|
-
* @description Any additional metadata you want to store with the key
|
|
1054
|
-
* @example {
|
|
1055
|
-
* "roles": [
|
|
1056
|
-
* "admin",
|
|
1057
|
-
* "user"
|
|
1058
|
-
* ],
|
|
1059
|
-
* "stripeCustomerId": "cus_1234"
|
|
1060
|
-
* }
|
|
1061
|
-
*/
|
|
1062
|
-
meta?: {
|
|
1063
|
-
[key: string]: unknown;
|
|
1064
|
-
} | null;
|
|
1065
|
-
/**
|
|
1066
|
-
* @description The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring.
|
|
1067
|
-
* @example 0
|
|
1068
|
-
*/
|
|
1069
|
-
expires?: number | null;
|
|
1070
|
-
/**
|
|
1071
|
-
* @description Unkey comes with per-key ratelimiting out of the box. Set `null` to disable.
|
|
1072
|
-
* @example {
|
|
1073
|
-
* "type": "fast",
|
|
1074
|
-
* "limit": 10,
|
|
1075
|
-
* "refillRate": 1,
|
|
1076
|
-
* "refillInterval": 60
|
|
1077
|
-
* }
|
|
1078
|
-
*/
|
|
1079
|
-
ratelimit?: ({
|
|
1080
|
-
/**
|
|
1081
|
-
* @description Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.
|
|
1082
|
-
* @enum {string}
|
|
1083
|
-
*/
|
|
1084
|
-
type: "fast" | "consistent";
|
|
1085
|
-
/** @description The total amount of burstable requests. */
|
|
1086
|
-
limit: number;
|
|
1087
|
-
/** @description How many tokens to refill during each refillInterval. */
|
|
1088
|
-
refillRate: number;
|
|
1089
|
-
/** @description Determines the speed at which tokens are refilled, in milliseconds. */
|
|
1090
|
-
refillInterval: number;
|
|
1091
|
-
}) | null;
|
|
1092
|
-
/**
|
|
1093
|
-
* @description The number of requests that can be made with this key before it becomes invalid. Set `null` to disable.
|
|
1094
|
-
* @example 1000
|
|
1095
|
-
*/
|
|
1096
|
-
remaining?: number | null;
|
|
1097
|
-
};
|
|
1098
|
-
};
|
|
1099
|
-
};
|
|
1100
|
-
responses: {
|
|
1101
|
-
/** @description The key was successfully updated, it may take up to 30s for this to take effect in all regions */
|
|
1102
|
-
200: {
|
|
1103
|
-
content: {
|
|
1104
|
-
"application/json": Record<string, never>;
|
|
1105
|
-
};
|
|
1106
|
-
};
|
|
1107
|
-
/** @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). */
|
|
1108
|
-
400: {
|
|
1109
|
-
content: {
|
|
1110
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1111
|
-
};
|
|
1112
|
-
};
|
|
1113
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1114
|
-
401: {
|
|
1115
|
-
content: {
|
|
1116
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1117
|
-
};
|
|
1118
|
-
};
|
|
1119
|
-
/** @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. */
|
|
1120
|
-
403: {
|
|
1121
|
-
content: {
|
|
1122
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1123
|
-
};
|
|
1124
|
-
};
|
|
1125
|
-
/** @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. */
|
|
1126
|
-
404: {
|
|
1127
|
-
content: {
|
|
1128
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1129
|
-
};
|
|
1130
|
-
};
|
|
1131
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1132
|
-
409: {
|
|
1133
|
-
content: {
|
|
1134
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1135
|
-
};
|
|
1136
|
-
};
|
|
1137
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1138
|
-
429: {
|
|
1139
|
-
content: {
|
|
1140
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1141
|
-
};
|
|
1142
|
-
};
|
|
1143
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1144
|
-
500: {
|
|
1145
|
-
content: {
|
|
1146
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1147
|
-
};
|
|
1148
|
-
};
|
|
1149
|
-
};
|
|
1150
|
-
};
|
|
1151
|
-
};
|
|
1152
1043
|
"/v1/keys": {
|
|
1153
1044
|
post: {
|
|
1154
1045
|
requestBody: {
|
|
@@ -1456,331 +1347,6 @@ interface paths {
|
|
|
1456
1347
|
};
|
|
1457
1348
|
};
|
|
1458
1349
|
};
|
|
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
|
-
};
|
|
1513
|
-
"/v1/apis": {
|
|
1514
|
-
post: {
|
|
1515
|
-
requestBody: {
|
|
1516
|
-
content: {
|
|
1517
|
-
"application/json": {
|
|
1518
|
-
/**
|
|
1519
|
-
* @description The name for your API. This is not customer facing.
|
|
1520
|
-
* @example my-api
|
|
1521
|
-
*/
|
|
1522
|
-
name: string;
|
|
1523
|
-
};
|
|
1524
|
-
};
|
|
1525
|
-
};
|
|
1526
|
-
responses: {
|
|
1527
|
-
/** @description The configuration for an api */
|
|
1528
|
-
200: {
|
|
1529
|
-
content: {
|
|
1530
|
-
"application/json": {
|
|
1531
|
-
/**
|
|
1532
|
-
* @description The id of the api
|
|
1533
|
-
* @example api_134
|
|
1534
|
-
*/
|
|
1535
|
-
apiId: string;
|
|
1536
|
-
};
|
|
1537
|
-
};
|
|
1538
|
-
};
|
|
1539
|
-
/** @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). */
|
|
1540
|
-
400: {
|
|
1541
|
-
content: {
|
|
1542
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1543
|
-
};
|
|
1544
|
-
};
|
|
1545
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1546
|
-
401: {
|
|
1547
|
-
content: {
|
|
1548
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1549
|
-
};
|
|
1550
|
-
};
|
|
1551
|
-
/** @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. */
|
|
1552
|
-
403: {
|
|
1553
|
-
content: {
|
|
1554
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1555
|
-
};
|
|
1556
|
-
};
|
|
1557
|
-
/** @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. */
|
|
1558
|
-
404: {
|
|
1559
|
-
content: {
|
|
1560
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1561
|
-
};
|
|
1562
|
-
};
|
|
1563
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1564
|
-
409: {
|
|
1565
|
-
content: {
|
|
1566
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1567
|
-
};
|
|
1568
|
-
};
|
|
1569
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1570
|
-
429: {
|
|
1571
|
-
content: {
|
|
1572
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1573
|
-
};
|
|
1574
|
-
};
|
|
1575
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1576
|
-
500: {
|
|
1577
|
-
content: {
|
|
1578
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1579
|
-
};
|
|
1580
|
-
};
|
|
1581
|
-
};
|
|
1582
|
-
};
|
|
1583
|
-
};
|
|
1584
|
-
"/v1/apis/{apiId}": {
|
|
1585
|
-
get: {
|
|
1586
|
-
parameters: {
|
|
1587
|
-
path: {
|
|
1588
|
-
apiId: string;
|
|
1589
|
-
};
|
|
1590
|
-
};
|
|
1591
|
-
responses: {
|
|
1592
|
-
/** @description The configuration for an api */
|
|
1593
|
-
200: {
|
|
1594
|
-
content: {
|
|
1595
|
-
"application/json": {
|
|
1596
|
-
/**
|
|
1597
|
-
* @description The id of the key
|
|
1598
|
-
* @example key_1234
|
|
1599
|
-
*/
|
|
1600
|
-
id: string;
|
|
1601
|
-
/**
|
|
1602
|
-
* @description The id of the workspace that owns the api
|
|
1603
|
-
* @example ws_1234
|
|
1604
|
-
*/
|
|
1605
|
-
workspaceId: string;
|
|
1606
|
-
/**
|
|
1607
|
-
* @description The name of the api. This is internal and your users will not see this.
|
|
1608
|
-
* @example Unkey - Production
|
|
1609
|
-
*/
|
|
1610
|
-
name?: string;
|
|
1611
|
-
};
|
|
1612
|
-
};
|
|
1613
|
-
};
|
|
1614
|
-
/** @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). */
|
|
1615
|
-
400: {
|
|
1616
|
-
content: {
|
|
1617
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1618
|
-
};
|
|
1619
|
-
};
|
|
1620
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1621
|
-
401: {
|
|
1622
|
-
content: {
|
|
1623
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1624
|
-
};
|
|
1625
|
-
};
|
|
1626
|
-
/** @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. */
|
|
1627
|
-
403: {
|
|
1628
|
-
content: {
|
|
1629
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1630
|
-
};
|
|
1631
|
-
};
|
|
1632
|
-
/** @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. */
|
|
1633
|
-
404: {
|
|
1634
|
-
content: {
|
|
1635
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1636
|
-
};
|
|
1637
|
-
};
|
|
1638
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1639
|
-
409: {
|
|
1640
|
-
content: {
|
|
1641
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1642
|
-
};
|
|
1643
|
-
};
|
|
1644
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1645
|
-
429: {
|
|
1646
|
-
content: {
|
|
1647
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1648
|
-
};
|
|
1649
|
-
};
|
|
1650
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1651
|
-
500: {
|
|
1652
|
-
content: {
|
|
1653
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1654
|
-
};
|
|
1655
|
-
};
|
|
1656
|
-
};
|
|
1657
|
-
};
|
|
1658
|
-
delete: {
|
|
1659
|
-
parameters: {
|
|
1660
|
-
path: {
|
|
1661
|
-
apiId: string;
|
|
1662
|
-
};
|
|
1663
|
-
};
|
|
1664
|
-
responses: {
|
|
1665
|
-
/** @description The api was successfully deleted, it may take up to 30s for this to take effect in all regions */
|
|
1666
|
-
200: {
|
|
1667
|
-
content: {
|
|
1668
|
-
"application/json": Record<string, never>;
|
|
1669
|
-
};
|
|
1670
|
-
};
|
|
1671
|
-
/** @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). */
|
|
1672
|
-
400: {
|
|
1673
|
-
content: {
|
|
1674
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1675
|
-
};
|
|
1676
|
-
};
|
|
1677
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1678
|
-
401: {
|
|
1679
|
-
content: {
|
|
1680
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1681
|
-
};
|
|
1682
|
-
};
|
|
1683
|
-
/** @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. */
|
|
1684
|
-
403: {
|
|
1685
|
-
content: {
|
|
1686
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1687
|
-
};
|
|
1688
|
-
};
|
|
1689
|
-
/** @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. */
|
|
1690
|
-
404: {
|
|
1691
|
-
content: {
|
|
1692
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1693
|
-
};
|
|
1694
|
-
};
|
|
1695
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1696
|
-
409: {
|
|
1697
|
-
content: {
|
|
1698
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1699
|
-
};
|
|
1700
|
-
};
|
|
1701
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1702
|
-
429: {
|
|
1703
|
-
content: {
|
|
1704
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1705
|
-
};
|
|
1706
|
-
};
|
|
1707
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1708
|
-
500: {
|
|
1709
|
-
content: {
|
|
1710
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1711
|
-
};
|
|
1712
|
-
};
|
|
1713
|
-
};
|
|
1714
|
-
};
|
|
1715
|
-
};
|
|
1716
|
-
"/v1/apis/{apiId}/keys": {
|
|
1717
|
-
get: {
|
|
1718
|
-
parameters: {
|
|
1719
|
-
query?: {
|
|
1720
|
-
limit?: number;
|
|
1721
|
-
offset?: number | null;
|
|
1722
|
-
ownerId?: string;
|
|
1723
|
-
};
|
|
1724
|
-
path: {
|
|
1725
|
-
apiId: string;
|
|
1726
|
-
};
|
|
1727
|
-
};
|
|
1728
|
-
responses: {
|
|
1729
|
-
/** @description Keys belonging to the api */
|
|
1730
|
-
200: {
|
|
1731
|
-
content: {
|
|
1732
|
-
"application/json": {
|
|
1733
|
-
keys: components["schemas"]["Key"][];
|
|
1734
|
-
/** @description The total number of keys for this api */
|
|
1735
|
-
total: number;
|
|
1736
|
-
};
|
|
1737
|
-
};
|
|
1738
|
-
};
|
|
1739
|
-
/** @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). */
|
|
1740
|
-
400: {
|
|
1741
|
-
content: {
|
|
1742
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1743
|
-
};
|
|
1744
|
-
};
|
|
1745
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1746
|
-
401: {
|
|
1747
|
-
content: {
|
|
1748
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1749
|
-
};
|
|
1750
|
-
};
|
|
1751
|
-
/** @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. */
|
|
1752
|
-
403: {
|
|
1753
|
-
content: {
|
|
1754
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1755
|
-
};
|
|
1756
|
-
};
|
|
1757
|
-
/** @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. */
|
|
1758
|
-
404: {
|
|
1759
|
-
content: {
|
|
1760
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1761
|
-
};
|
|
1762
|
-
};
|
|
1763
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1764
|
-
409: {
|
|
1765
|
-
content: {
|
|
1766
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1767
|
-
};
|
|
1768
|
-
};
|
|
1769
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1770
|
-
429: {
|
|
1771
|
-
content: {
|
|
1772
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1773
|
-
};
|
|
1774
|
-
};
|
|
1775
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1776
|
-
500: {
|
|
1777
|
-
content: {
|
|
1778
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1779
|
-
};
|
|
1780
|
-
};
|
|
1781
|
-
};
|
|
1782
|
-
};
|
|
1783
|
-
};
|
|
1784
1350
|
}
|
|
1785
1351
|
|
|
1786
1352
|
interface components {
|
|
@@ -2167,6 +1733,11 @@ interface components {
|
|
|
2167
1733
|
* ]
|
|
2168
1734
|
*/
|
|
2169
1735
|
permissions?: string[];
|
|
1736
|
+
/**
|
|
1737
|
+
* @description The environment of the key, this is what what you set when you crated the key
|
|
1738
|
+
* @example test
|
|
1739
|
+
*/
|
|
1740
|
+
environment?: string;
|
|
2170
1741
|
};
|
|
2171
1742
|
V1KeysVerifyKeyRequest: {
|
|
2172
1743
|
/**
|
|
@@ -2369,6 +1940,7 @@ declare function verifyKey(req: string | {
|
|
|
2369
1940
|
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS" | undefined;
|
|
2370
1941
|
enabled?: boolean | undefined;
|
|
2371
1942
|
permissions?: string[] | undefined;
|
|
1943
|
+
environment?: string | undefined;
|
|
2372
1944
|
};
|
|
2373
1945
|
error?: undefined;
|
|
2374
1946
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -314,6 +314,17 @@ interface paths {
|
|
|
314
314
|
* @example false
|
|
315
315
|
*/
|
|
316
316
|
enabled?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* @description Environments allow you to divide your keyspace.
|
|
319
|
+
*
|
|
320
|
+
* Some applications like Stripe, Clerk, WorkOS and others have a concept of "live" and "test" keys to
|
|
321
|
+
* give the developer a way to develop their own application without the risk of modifying real world
|
|
322
|
+
* resources.
|
|
323
|
+
*
|
|
324
|
+
* When you set an environment, we will return it back to you when validating the key, so you can
|
|
325
|
+
* handle it correctly.
|
|
326
|
+
*/
|
|
327
|
+
environment?: string;
|
|
317
328
|
};
|
|
318
329
|
};
|
|
319
330
|
};
|
|
@@ -673,7 +684,7 @@ interface paths {
|
|
|
673
684
|
};
|
|
674
685
|
};
|
|
675
686
|
responses: {
|
|
676
|
-
/** @description
|
|
687
|
+
/** @description Usage numbers over time */
|
|
677
688
|
200: {
|
|
678
689
|
content: {
|
|
679
690
|
"application/json": {
|
|
@@ -1029,126 +1040,6 @@ interface paths {
|
|
|
1029
1040
|
};
|
|
1030
1041
|
};
|
|
1031
1042
|
};
|
|
1032
|
-
"/v1/keys/{keyId}": {
|
|
1033
|
-
put: {
|
|
1034
|
-
parameters: {
|
|
1035
|
-
path: {
|
|
1036
|
-
keyId: string;
|
|
1037
|
-
};
|
|
1038
|
-
};
|
|
1039
|
-
requestBody: {
|
|
1040
|
-
content: {
|
|
1041
|
-
"application/json": {
|
|
1042
|
-
/**
|
|
1043
|
-
* @description The name of the key
|
|
1044
|
-
* @example Customer X
|
|
1045
|
-
*/
|
|
1046
|
-
name?: string | null;
|
|
1047
|
-
/**
|
|
1048
|
-
* @description The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API.
|
|
1049
|
-
* @example user_123
|
|
1050
|
-
*/
|
|
1051
|
-
ownerId?: string | null;
|
|
1052
|
-
/**
|
|
1053
|
-
* @description Any additional metadata you want to store with the key
|
|
1054
|
-
* @example {
|
|
1055
|
-
* "roles": [
|
|
1056
|
-
* "admin",
|
|
1057
|
-
* "user"
|
|
1058
|
-
* ],
|
|
1059
|
-
* "stripeCustomerId": "cus_1234"
|
|
1060
|
-
* }
|
|
1061
|
-
*/
|
|
1062
|
-
meta?: {
|
|
1063
|
-
[key: string]: unknown;
|
|
1064
|
-
} | null;
|
|
1065
|
-
/**
|
|
1066
|
-
* @description The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring.
|
|
1067
|
-
* @example 0
|
|
1068
|
-
*/
|
|
1069
|
-
expires?: number | null;
|
|
1070
|
-
/**
|
|
1071
|
-
* @description Unkey comes with per-key ratelimiting out of the box. Set `null` to disable.
|
|
1072
|
-
* @example {
|
|
1073
|
-
* "type": "fast",
|
|
1074
|
-
* "limit": 10,
|
|
1075
|
-
* "refillRate": 1,
|
|
1076
|
-
* "refillInterval": 60
|
|
1077
|
-
* }
|
|
1078
|
-
*/
|
|
1079
|
-
ratelimit?: ({
|
|
1080
|
-
/**
|
|
1081
|
-
* @description Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.
|
|
1082
|
-
* @enum {string}
|
|
1083
|
-
*/
|
|
1084
|
-
type: "fast" | "consistent";
|
|
1085
|
-
/** @description The total amount of burstable requests. */
|
|
1086
|
-
limit: number;
|
|
1087
|
-
/** @description How many tokens to refill during each refillInterval. */
|
|
1088
|
-
refillRate: number;
|
|
1089
|
-
/** @description Determines the speed at which tokens are refilled, in milliseconds. */
|
|
1090
|
-
refillInterval: number;
|
|
1091
|
-
}) | null;
|
|
1092
|
-
/**
|
|
1093
|
-
* @description The number of requests that can be made with this key before it becomes invalid. Set `null` to disable.
|
|
1094
|
-
* @example 1000
|
|
1095
|
-
*/
|
|
1096
|
-
remaining?: number | null;
|
|
1097
|
-
};
|
|
1098
|
-
};
|
|
1099
|
-
};
|
|
1100
|
-
responses: {
|
|
1101
|
-
/** @description The key was successfully updated, it may take up to 30s for this to take effect in all regions */
|
|
1102
|
-
200: {
|
|
1103
|
-
content: {
|
|
1104
|
-
"application/json": Record<string, never>;
|
|
1105
|
-
};
|
|
1106
|
-
};
|
|
1107
|
-
/** @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). */
|
|
1108
|
-
400: {
|
|
1109
|
-
content: {
|
|
1110
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1111
|
-
};
|
|
1112
|
-
};
|
|
1113
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1114
|
-
401: {
|
|
1115
|
-
content: {
|
|
1116
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1117
|
-
};
|
|
1118
|
-
};
|
|
1119
|
-
/** @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. */
|
|
1120
|
-
403: {
|
|
1121
|
-
content: {
|
|
1122
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1123
|
-
};
|
|
1124
|
-
};
|
|
1125
|
-
/** @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. */
|
|
1126
|
-
404: {
|
|
1127
|
-
content: {
|
|
1128
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1129
|
-
};
|
|
1130
|
-
};
|
|
1131
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1132
|
-
409: {
|
|
1133
|
-
content: {
|
|
1134
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1135
|
-
};
|
|
1136
|
-
};
|
|
1137
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1138
|
-
429: {
|
|
1139
|
-
content: {
|
|
1140
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1141
|
-
};
|
|
1142
|
-
};
|
|
1143
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1144
|
-
500: {
|
|
1145
|
-
content: {
|
|
1146
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1147
|
-
};
|
|
1148
|
-
};
|
|
1149
|
-
};
|
|
1150
|
-
};
|
|
1151
|
-
};
|
|
1152
1043
|
"/v1/keys": {
|
|
1153
1044
|
post: {
|
|
1154
1045
|
requestBody: {
|
|
@@ -1456,331 +1347,6 @@ interface paths {
|
|
|
1456
1347
|
};
|
|
1457
1348
|
};
|
|
1458
1349
|
};
|
|
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
|
-
};
|
|
1513
|
-
"/v1/apis": {
|
|
1514
|
-
post: {
|
|
1515
|
-
requestBody: {
|
|
1516
|
-
content: {
|
|
1517
|
-
"application/json": {
|
|
1518
|
-
/**
|
|
1519
|
-
* @description The name for your API. This is not customer facing.
|
|
1520
|
-
* @example my-api
|
|
1521
|
-
*/
|
|
1522
|
-
name: string;
|
|
1523
|
-
};
|
|
1524
|
-
};
|
|
1525
|
-
};
|
|
1526
|
-
responses: {
|
|
1527
|
-
/** @description The configuration for an api */
|
|
1528
|
-
200: {
|
|
1529
|
-
content: {
|
|
1530
|
-
"application/json": {
|
|
1531
|
-
/**
|
|
1532
|
-
* @description The id of the api
|
|
1533
|
-
* @example api_134
|
|
1534
|
-
*/
|
|
1535
|
-
apiId: string;
|
|
1536
|
-
};
|
|
1537
|
-
};
|
|
1538
|
-
};
|
|
1539
|
-
/** @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). */
|
|
1540
|
-
400: {
|
|
1541
|
-
content: {
|
|
1542
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1543
|
-
};
|
|
1544
|
-
};
|
|
1545
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1546
|
-
401: {
|
|
1547
|
-
content: {
|
|
1548
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1549
|
-
};
|
|
1550
|
-
};
|
|
1551
|
-
/** @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. */
|
|
1552
|
-
403: {
|
|
1553
|
-
content: {
|
|
1554
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1555
|
-
};
|
|
1556
|
-
};
|
|
1557
|
-
/** @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. */
|
|
1558
|
-
404: {
|
|
1559
|
-
content: {
|
|
1560
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1561
|
-
};
|
|
1562
|
-
};
|
|
1563
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1564
|
-
409: {
|
|
1565
|
-
content: {
|
|
1566
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1567
|
-
};
|
|
1568
|
-
};
|
|
1569
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1570
|
-
429: {
|
|
1571
|
-
content: {
|
|
1572
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1573
|
-
};
|
|
1574
|
-
};
|
|
1575
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1576
|
-
500: {
|
|
1577
|
-
content: {
|
|
1578
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1579
|
-
};
|
|
1580
|
-
};
|
|
1581
|
-
};
|
|
1582
|
-
};
|
|
1583
|
-
};
|
|
1584
|
-
"/v1/apis/{apiId}": {
|
|
1585
|
-
get: {
|
|
1586
|
-
parameters: {
|
|
1587
|
-
path: {
|
|
1588
|
-
apiId: string;
|
|
1589
|
-
};
|
|
1590
|
-
};
|
|
1591
|
-
responses: {
|
|
1592
|
-
/** @description The configuration for an api */
|
|
1593
|
-
200: {
|
|
1594
|
-
content: {
|
|
1595
|
-
"application/json": {
|
|
1596
|
-
/**
|
|
1597
|
-
* @description The id of the key
|
|
1598
|
-
* @example key_1234
|
|
1599
|
-
*/
|
|
1600
|
-
id: string;
|
|
1601
|
-
/**
|
|
1602
|
-
* @description The id of the workspace that owns the api
|
|
1603
|
-
* @example ws_1234
|
|
1604
|
-
*/
|
|
1605
|
-
workspaceId: string;
|
|
1606
|
-
/**
|
|
1607
|
-
* @description The name of the api. This is internal and your users will not see this.
|
|
1608
|
-
* @example Unkey - Production
|
|
1609
|
-
*/
|
|
1610
|
-
name?: string;
|
|
1611
|
-
};
|
|
1612
|
-
};
|
|
1613
|
-
};
|
|
1614
|
-
/** @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). */
|
|
1615
|
-
400: {
|
|
1616
|
-
content: {
|
|
1617
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1618
|
-
};
|
|
1619
|
-
};
|
|
1620
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1621
|
-
401: {
|
|
1622
|
-
content: {
|
|
1623
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1624
|
-
};
|
|
1625
|
-
};
|
|
1626
|
-
/** @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. */
|
|
1627
|
-
403: {
|
|
1628
|
-
content: {
|
|
1629
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1630
|
-
};
|
|
1631
|
-
};
|
|
1632
|
-
/** @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. */
|
|
1633
|
-
404: {
|
|
1634
|
-
content: {
|
|
1635
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1636
|
-
};
|
|
1637
|
-
};
|
|
1638
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1639
|
-
409: {
|
|
1640
|
-
content: {
|
|
1641
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1642
|
-
};
|
|
1643
|
-
};
|
|
1644
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1645
|
-
429: {
|
|
1646
|
-
content: {
|
|
1647
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1648
|
-
};
|
|
1649
|
-
};
|
|
1650
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1651
|
-
500: {
|
|
1652
|
-
content: {
|
|
1653
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1654
|
-
};
|
|
1655
|
-
};
|
|
1656
|
-
};
|
|
1657
|
-
};
|
|
1658
|
-
delete: {
|
|
1659
|
-
parameters: {
|
|
1660
|
-
path: {
|
|
1661
|
-
apiId: string;
|
|
1662
|
-
};
|
|
1663
|
-
};
|
|
1664
|
-
responses: {
|
|
1665
|
-
/** @description The api was successfully deleted, it may take up to 30s for this to take effect in all regions */
|
|
1666
|
-
200: {
|
|
1667
|
-
content: {
|
|
1668
|
-
"application/json": Record<string, never>;
|
|
1669
|
-
};
|
|
1670
|
-
};
|
|
1671
|
-
/** @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). */
|
|
1672
|
-
400: {
|
|
1673
|
-
content: {
|
|
1674
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1675
|
-
};
|
|
1676
|
-
};
|
|
1677
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1678
|
-
401: {
|
|
1679
|
-
content: {
|
|
1680
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1681
|
-
};
|
|
1682
|
-
};
|
|
1683
|
-
/** @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. */
|
|
1684
|
-
403: {
|
|
1685
|
-
content: {
|
|
1686
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1687
|
-
};
|
|
1688
|
-
};
|
|
1689
|
-
/** @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. */
|
|
1690
|
-
404: {
|
|
1691
|
-
content: {
|
|
1692
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1693
|
-
};
|
|
1694
|
-
};
|
|
1695
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1696
|
-
409: {
|
|
1697
|
-
content: {
|
|
1698
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1699
|
-
};
|
|
1700
|
-
};
|
|
1701
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1702
|
-
429: {
|
|
1703
|
-
content: {
|
|
1704
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1705
|
-
};
|
|
1706
|
-
};
|
|
1707
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1708
|
-
500: {
|
|
1709
|
-
content: {
|
|
1710
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1711
|
-
};
|
|
1712
|
-
};
|
|
1713
|
-
};
|
|
1714
|
-
};
|
|
1715
|
-
};
|
|
1716
|
-
"/v1/apis/{apiId}/keys": {
|
|
1717
|
-
get: {
|
|
1718
|
-
parameters: {
|
|
1719
|
-
query?: {
|
|
1720
|
-
limit?: number;
|
|
1721
|
-
offset?: number | null;
|
|
1722
|
-
ownerId?: string;
|
|
1723
|
-
};
|
|
1724
|
-
path: {
|
|
1725
|
-
apiId: string;
|
|
1726
|
-
};
|
|
1727
|
-
};
|
|
1728
|
-
responses: {
|
|
1729
|
-
/** @description Keys belonging to the api */
|
|
1730
|
-
200: {
|
|
1731
|
-
content: {
|
|
1732
|
-
"application/json": {
|
|
1733
|
-
keys: components["schemas"]["Key"][];
|
|
1734
|
-
/** @description The total number of keys for this api */
|
|
1735
|
-
total: number;
|
|
1736
|
-
};
|
|
1737
|
-
};
|
|
1738
|
-
};
|
|
1739
|
-
/** @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). */
|
|
1740
|
-
400: {
|
|
1741
|
-
content: {
|
|
1742
|
-
"application/json": components["schemas"]["ErrBadRequest"];
|
|
1743
|
-
};
|
|
1744
|
-
};
|
|
1745
|
-
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
1746
|
-
401: {
|
|
1747
|
-
content: {
|
|
1748
|
-
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
1749
|
-
};
|
|
1750
|
-
};
|
|
1751
|
-
/** @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. */
|
|
1752
|
-
403: {
|
|
1753
|
-
content: {
|
|
1754
|
-
"application/json": components["schemas"]["ErrForbidden"];
|
|
1755
|
-
};
|
|
1756
|
-
};
|
|
1757
|
-
/** @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. */
|
|
1758
|
-
404: {
|
|
1759
|
-
content: {
|
|
1760
|
-
"application/json": components["schemas"]["ErrNotFound"];
|
|
1761
|
-
};
|
|
1762
|
-
};
|
|
1763
|
-
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
1764
|
-
409: {
|
|
1765
|
-
content: {
|
|
1766
|
-
"application/json": components["schemas"]["ErrConflict"];
|
|
1767
|
-
};
|
|
1768
|
-
};
|
|
1769
|
-
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
1770
|
-
429: {
|
|
1771
|
-
content: {
|
|
1772
|
-
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
1773
|
-
};
|
|
1774
|
-
};
|
|
1775
|
-
/** @description The server has encountered a situation it does not know how to handle. */
|
|
1776
|
-
500: {
|
|
1777
|
-
content: {
|
|
1778
|
-
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
1779
|
-
};
|
|
1780
|
-
};
|
|
1781
|
-
};
|
|
1782
|
-
};
|
|
1783
|
-
};
|
|
1784
1350
|
}
|
|
1785
1351
|
|
|
1786
1352
|
interface components {
|
|
@@ -2167,6 +1733,11 @@ interface components {
|
|
|
2167
1733
|
* ]
|
|
2168
1734
|
*/
|
|
2169
1735
|
permissions?: string[];
|
|
1736
|
+
/**
|
|
1737
|
+
* @description The environment of the key, this is what what you set when you crated the key
|
|
1738
|
+
* @example test
|
|
1739
|
+
*/
|
|
1740
|
+
environment?: string;
|
|
2170
1741
|
};
|
|
2171
1742
|
V1KeysVerifyKeyRequest: {
|
|
2172
1743
|
/**
|
|
@@ -2369,6 +1940,7 @@ declare function verifyKey(req: string | {
|
|
|
2369
1940
|
code?: "NOT_FOUND" | "FORBIDDEN" | "USAGE_EXCEEDED" | "RATE_LIMITED" | "UNAUTHORIZED" | "DISABLED" | "INSUFFICIENT_PERMISSIONS" | undefined;
|
|
2370
1941
|
enabled?: boolean | undefined;
|
|
2371
1942
|
permissions?: string[] | undefined;
|
|
1943
|
+
environment?: string | undefined;
|
|
2372
1944
|
};
|
|
2373
1945
|
error?: undefined;
|
|
2374
1946
|
}>;
|
package/dist/index.js
CHANGED
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\";\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,SAAS,YAAY;AAC1C;;;ACsDO,IAAM,QAAN,MAAY;AAAA,EACD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAED;AAA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1B,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":[]}
|
|
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.19.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,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,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AK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;;;AJzBA,kBAAsC;","names":[]}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,OA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Q;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,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;;;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;;;ACzBA,SAAS,KAAK,UAAwB;","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.19.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,S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