@unkey/api 0.31.0 → 0.33.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 +145 -51
- package/dist/index.d.ts +145 -51
- 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
|
@@ -38,7 +38,7 @@ interface paths {
|
|
|
38
38
|
post: operations["updateRemaining"];
|
|
39
39
|
};
|
|
40
40
|
"/v1/keys.getVerifications": {
|
|
41
|
-
get: operations["getVerifications"];
|
|
41
|
+
get: operations["keys.getVerifications"];
|
|
42
42
|
};
|
|
43
43
|
"/v1/keys.addPermissions": {
|
|
44
44
|
post: operations["addPermissions"];
|
|
@@ -946,6 +946,11 @@ interface operations {
|
|
|
946
946
|
* @example key_1234
|
|
947
947
|
*/
|
|
948
948
|
keyId: string;
|
|
949
|
+
/**
|
|
950
|
+
* @description By default Unkey soft deletes keys, so they may be recovered later. If you want to permanently delete it, set permanent=true. This might be necessary if you run into NOT_UNIQUE errors during key migration.
|
|
951
|
+
* @default false
|
|
952
|
+
*/
|
|
953
|
+
permanent?: boolean;
|
|
949
954
|
};
|
|
950
955
|
};
|
|
951
956
|
};
|
|
@@ -1587,59 +1592,44 @@ interface operations {
|
|
|
1587
1592
|
};
|
|
1588
1593
|
};
|
|
1589
1594
|
};
|
|
1590
|
-
getVerifications: {
|
|
1595
|
+
"keys.getVerifications": {
|
|
1591
1596
|
parameters: {
|
|
1592
|
-
query
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
keyId?: string | string[];
|
|
1596
|
-
tag?: string | string[];
|
|
1597
|
+
query?: {
|
|
1598
|
+
keyId?: string;
|
|
1599
|
+
ownerId?: string;
|
|
1597
1600
|
start?: number | null;
|
|
1598
1601
|
end?: number | null;
|
|
1599
|
-
|
|
1600
|
-
limit?: number;
|
|
1601
|
-
orderBy?: "time" | "valid" | "notFound" | "forbidden" | "usageExceeded" | "rateLimited" | "unauthorized" | "disabled" | "insufficientPermissions" | "expired" | "total";
|
|
1602
|
-
order?: "asc" | "desc";
|
|
1602
|
+
granularity?: "day";
|
|
1603
1603
|
};
|
|
1604
1604
|
};
|
|
1605
1605
|
responses: {
|
|
1606
|
-
/** @description
|
|
1606
|
+
/** @description Usage numbers over time */
|
|
1607
1607
|
200: {
|
|
1608
1608
|
content: {
|
|
1609
1609
|
"application/json": {
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
/**
|
|
1634
|
-
* @description
|
|
1635
|
-
* Only available when specifying groupBy=identity in the query.
|
|
1636
|
-
* In this case there would be one datapoint per time and groupBy target.
|
|
1637
|
-
*/
|
|
1638
|
-
identity?: {
|
|
1639
|
-
id: string;
|
|
1640
|
-
externalId: string;
|
|
1641
|
-
};
|
|
1642
|
-
}[];
|
|
1610
|
+
verifications: {
|
|
1611
|
+
/**
|
|
1612
|
+
* @description The timestamp of the usage data
|
|
1613
|
+
* @example 1620000000000
|
|
1614
|
+
*/
|
|
1615
|
+
time: number;
|
|
1616
|
+
/**
|
|
1617
|
+
* @description The number of successful requests
|
|
1618
|
+
* @example 100
|
|
1619
|
+
*/
|
|
1620
|
+
success: number;
|
|
1621
|
+
/**
|
|
1622
|
+
* @description The number of requests that were rate limited
|
|
1623
|
+
* @example 10
|
|
1624
|
+
*/
|
|
1625
|
+
rateLimited: number;
|
|
1626
|
+
/**
|
|
1627
|
+
* @description The number of requests that exceeded the usage limit
|
|
1628
|
+
* @example 0
|
|
1629
|
+
*/
|
|
1630
|
+
usageExceeded: number;
|
|
1631
|
+
}[];
|
|
1632
|
+
};
|
|
1643
1633
|
};
|
|
1644
1634
|
};
|
|
1645
1635
|
/** @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). */
|
|
@@ -3060,11 +3050,17 @@ interface operations {
|
|
|
3060
3050
|
*/
|
|
3061
3051
|
start?: string;
|
|
3062
3052
|
/**
|
|
3063
|
-
* @
|
|
3064
|
-
*
|
|
3053
|
+
* @deprecated
|
|
3054
|
+
* @description Deprecated, use `externalId`
|
|
3065
3055
|
* @example team_123
|
|
3066
3056
|
*/
|
|
3067
3057
|
ownerId?: string;
|
|
3058
|
+
/**
|
|
3059
|
+
* @description Your user’s Id. This will provide a link between Unkey and your customer record.
|
|
3060
|
+
* When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
|
|
3061
|
+
* @example user_123
|
|
3062
|
+
*/
|
|
3063
|
+
externalId?: string;
|
|
3068
3064
|
/**
|
|
3069
3065
|
* @description This is a place for dynamic meta data, anything that feels useful for you should go here
|
|
3070
3066
|
* @example {
|
|
@@ -4490,6 +4486,103 @@ interface operations {
|
|
|
4490
4486
|
};
|
|
4491
4487
|
};
|
|
4492
4488
|
};
|
|
4489
|
+
getVerifications: {
|
|
4490
|
+
parameters: {
|
|
4491
|
+
query: {
|
|
4492
|
+
apiId: string;
|
|
4493
|
+
externalId?: string;
|
|
4494
|
+
keyId?: string | string[];
|
|
4495
|
+
tag?: string | string[];
|
|
4496
|
+
start?: number | null;
|
|
4497
|
+
end?: number | null;
|
|
4498
|
+
groupBy?: ("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour") | (("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour")[]);
|
|
4499
|
+
limit?: number;
|
|
4500
|
+
orderBy?: "time" | "valid" | "notFound" | "forbidden" | "usageExceeded" | "rateLimited" | "unauthorized" | "disabled" | "insufficientPermissions" | "expired" | "total";
|
|
4501
|
+
order?: "asc" | "desc";
|
|
4502
|
+
};
|
|
4503
|
+
};
|
|
4504
|
+
responses: {
|
|
4505
|
+
/** @description Retrieve all required data to build end-user facing dashboards and drive your usage-based billing. */
|
|
4506
|
+
200: {
|
|
4507
|
+
content: {
|
|
4508
|
+
"application/json": {
|
|
4509
|
+
/** @description Unix timestamp in milliseconds of the start of the current time slice. */
|
|
4510
|
+
time?: number;
|
|
4511
|
+
valid?: number;
|
|
4512
|
+
notFound?: number;
|
|
4513
|
+
forbidden?: number;
|
|
4514
|
+
usageExceeded?: number;
|
|
4515
|
+
rateLimited?: number;
|
|
4516
|
+
unauthorized?: number;
|
|
4517
|
+
disabled?: number;
|
|
4518
|
+
insufficientPermissions?: number;
|
|
4519
|
+
expired?: number;
|
|
4520
|
+
/** @description Total number of verifications in the current time slice, regardless of outcome. */
|
|
4521
|
+
total: number;
|
|
4522
|
+
/** @description Only available when grouping by tag. */
|
|
4523
|
+
tag?: string;
|
|
4524
|
+
/** @description Filter by one or multiple tags. If multiple tags are provided */
|
|
4525
|
+
tags?: string[];
|
|
4526
|
+
/**
|
|
4527
|
+
* @description Only available when specifying groupBy=key in the query.
|
|
4528
|
+
* In this case there would be one datapoint per time and groupBy target.
|
|
4529
|
+
*/
|
|
4530
|
+
keyId?: string;
|
|
4531
|
+
/**
|
|
4532
|
+
* @description Only available when specifying groupBy=identity in the query.
|
|
4533
|
+
* In this case there would be one datapoint per time and groupBy target.
|
|
4534
|
+
*/
|
|
4535
|
+
identity?: {
|
|
4536
|
+
id: string;
|
|
4537
|
+
externalId: string;
|
|
4538
|
+
};
|
|
4539
|
+
}[];
|
|
4540
|
+
};
|
|
4541
|
+
};
|
|
4542
|
+
/** @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). */
|
|
4543
|
+
400: {
|
|
4544
|
+
content: {
|
|
4545
|
+
"application/json": components["schemas"]["ErrBadRequest"];
|
|
4546
|
+
};
|
|
4547
|
+
};
|
|
4548
|
+
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
4549
|
+
401: {
|
|
4550
|
+
content: {
|
|
4551
|
+
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
4552
|
+
};
|
|
4553
|
+
};
|
|
4554
|
+
/** @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. */
|
|
4555
|
+
403: {
|
|
4556
|
+
content: {
|
|
4557
|
+
"application/json": components["schemas"]["ErrForbidden"];
|
|
4558
|
+
};
|
|
4559
|
+
};
|
|
4560
|
+
/** @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. */
|
|
4561
|
+
404: {
|
|
4562
|
+
content: {
|
|
4563
|
+
"application/json": components["schemas"]["ErrNotFound"];
|
|
4564
|
+
};
|
|
4565
|
+
};
|
|
4566
|
+
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
4567
|
+
409: {
|
|
4568
|
+
content: {
|
|
4569
|
+
"application/json": components["schemas"]["ErrConflict"];
|
|
4570
|
+
};
|
|
4571
|
+
};
|
|
4572
|
+
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
4573
|
+
429: {
|
|
4574
|
+
content: {
|
|
4575
|
+
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
4576
|
+
};
|
|
4577
|
+
};
|
|
4578
|
+
/** @description The server has encountered a situation it does not know how to handle. */
|
|
4579
|
+
500: {
|
|
4580
|
+
content: {
|
|
4581
|
+
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
4582
|
+
};
|
|
4583
|
+
};
|
|
4584
|
+
};
|
|
4585
|
+
};
|
|
4493
4586
|
"deprecated.createKey": {
|
|
4494
4587
|
requestBody: {
|
|
4495
4588
|
content: {
|
|
@@ -5008,10 +5101,11 @@ declare class Unkey {
|
|
|
5008
5101
|
* console.log(result)
|
|
5009
5102
|
* ```
|
|
5010
5103
|
*/
|
|
5011
|
-
declare function verifyKey(req: string | {
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
}
|
|
5104
|
+
declare function verifyKey<TPermission extends string = string>(req: string | (Omit<paths["/v1/keys.verifyKey"]["post"]["requestBody"]["content"]["application/json"], "authorization"> & {
|
|
5105
|
+
authorization?: {
|
|
5106
|
+
permissions: PermissionQuery<TPermission>;
|
|
5107
|
+
};
|
|
5108
|
+
})): Promise<{
|
|
5015
5109
|
result?: never;
|
|
5016
5110
|
error: {
|
|
5017
5111
|
code: ErrorResponse["error"]["code"];
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ interface paths {
|
|
|
38
38
|
post: operations["updateRemaining"];
|
|
39
39
|
};
|
|
40
40
|
"/v1/keys.getVerifications": {
|
|
41
|
-
get: operations["getVerifications"];
|
|
41
|
+
get: operations["keys.getVerifications"];
|
|
42
42
|
};
|
|
43
43
|
"/v1/keys.addPermissions": {
|
|
44
44
|
post: operations["addPermissions"];
|
|
@@ -946,6 +946,11 @@ interface operations {
|
|
|
946
946
|
* @example key_1234
|
|
947
947
|
*/
|
|
948
948
|
keyId: string;
|
|
949
|
+
/**
|
|
950
|
+
* @description By default Unkey soft deletes keys, so they may be recovered later. If you want to permanently delete it, set permanent=true. This might be necessary if you run into NOT_UNIQUE errors during key migration.
|
|
951
|
+
* @default false
|
|
952
|
+
*/
|
|
953
|
+
permanent?: boolean;
|
|
949
954
|
};
|
|
950
955
|
};
|
|
951
956
|
};
|
|
@@ -1587,59 +1592,44 @@ interface operations {
|
|
|
1587
1592
|
};
|
|
1588
1593
|
};
|
|
1589
1594
|
};
|
|
1590
|
-
getVerifications: {
|
|
1595
|
+
"keys.getVerifications": {
|
|
1591
1596
|
parameters: {
|
|
1592
|
-
query
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
keyId?: string | string[];
|
|
1596
|
-
tag?: string | string[];
|
|
1597
|
+
query?: {
|
|
1598
|
+
keyId?: string;
|
|
1599
|
+
ownerId?: string;
|
|
1597
1600
|
start?: number | null;
|
|
1598
1601
|
end?: number | null;
|
|
1599
|
-
|
|
1600
|
-
limit?: number;
|
|
1601
|
-
orderBy?: "time" | "valid" | "notFound" | "forbidden" | "usageExceeded" | "rateLimited" | "unauthorized" | "disabled" | "insufficientPermissions" | "expired" | "total";
|
|
1602
|
-
order?: "asc" | "desc";
|
|
1602
|
+
granularity?: "day";
|
|
1603
1603
|
};
|
|
1604
1604
|
};
|
|
1605
1605
|
responses: {
|
|
1606
|
-
/** @description
|
|
1606
|
+
/** @description Usage numbers over time */
|
|
1607
1607
|
200: {
|
|
1608
1608
|
content: {
|
|
1609
1609
|
"application/json": {
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
/**
|
|
1634
|
-
* @description
|
|
1635
|
-
* Only available when specifying groupBy=identity in the query.
|
|
1636
|
-
* In this case there would be one datapoint per time and groupBy target.
|
|
1637
|
-
*/
|
|
1638
|
-
identity?: {
|
|
1639
|
-
id: string;
|
|
1640
|
-
externalId: string;
|
|
1641
|
-
};
|
|
1642
|
-
}[];
|
|
1610
|
+
verifications: {
|
|
1611
|
+
/**
|
|
1612
|
+
* @description The timestamp of the usage data
|
|
1613
|
+
* @example 1620000000000
|
|
1614
|
+
*/
|
|
1615
|
+
time: number;
|
|
1616
|
+
/**
|
|
1617
|
+
* @description The number of successful requests
|
|
1618
|
+
* @example 100
|
|
1619
|
+
*/
|
|
1620
|
+
success: number;
|
|
1621
|
+
/**
|
|
1622
|
+
* @description The number of requests that were rate limited
|
|
1623
|
+
* @example 10
|
|
1624
|
+
*/
|
|
1625
|
+
rateLimited: number;
|
|
1626
|
+
/**
|
|
1627
|
+
* @description The number of requests that exceeded the usage limit
|
|
1628
|
+
* @example 0
|
|
1629
|
+
*/
|
|
1630
|
+
usageExceeded: number;
|
|
1631
|
+
}[];
|
|
1632
|
+
};
|
|
1643
1633
|
};
|
|
1644
1634
|
};
|
|
1645
1635
|
/** @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). */
|
|
@@ -3060,11 +3050,17 @@ interface operations {
|
|
|
3060
3050
|
*/
|
|
3061
3051
|
start?: string;
|
|
3062
3052
|
/**
|
|
3063
|
-
* @
|
|
3064
|
-
*
|
|
3053
|
+
* @deprecated
|
|
3054
|
+
* @description Deprecated, use `externalId`
|
|
3065
3055
|
* @example team_123
|
|
3066
3056
|
*/
|
|
3067
3057
|
ownerId?: string;
|
|
3058
|
+
/**
|
|
3059
|
+
* @description Your user’s Id. This will provide a link between Unkey and your customer record.
|
|
3060
|
+
* When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
|
|
3061
|
+
* @example user_123
|
|
3062
|
+
*/
|
|
3063
|
+
externalId?: string;
|
|
3068
3064
|
/**
|
|
3069
3065
|
* @description This is a place for dynamic meta data, anything that feels useful for you should go here
|
|
3070
3066
|
* @example {
|
|
@@ -4490,6 +4486,103 @@ interface operations {
|
|
|
4490
4486
|
};
|
|
4491
4487
|
};
|
|
4492
4488
|
};
|
|
4489
|
+
getVerifications: {
|
|
4490
|
+
parameters: {
|
|
4491
|
+
query: {
|
|
4492
|
+
apiId: string;
|
|
4493
|
+
externalId?: string;
|
|
4494
|
+
keyId?: string | string[];
|
|
4495
|
+
tag?: string | string[];
|
|
4496
|
+
start?: number | null;
|
|
4497
|
+
end?: number | null;
|
|
4498
|
+
groupBy?: ("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour") | (("key" | "identity" | "tags" | "tag" | "month" | "day" | "hour")[]);
|
|
4499
|
+
limit?: number;
|
|
4500
|
+
orderBy?: "time" | "valid" | "notFound" | "forbidden" | "usageExceeded" | "rateLimited" | "unauthorized" | "disabled" | "insufficientPermissions" | "expired" | "total";
|
|
4501
|
+
order?: "asc" | "desc";
|
|
4502
|
+
};
|
|
4503
|
+
};
|
|
4504
|
+
responses: {
|
|
4505
|
+
/** @description Retrieve all required data to build end-user facing dashboards and drive your usage-based billing. */
|
|
4506
|
+
200: {
|
|
4507
|
+
content: {
|
|
4508
|
+
"application/json": {
|
|
4509
|
+
/** @description Unix timestamp in milliseconds of the start of the current time slice. */
|
|
4510
|
+
time?: number;
|
|
4511
|
+
valid?: number;
|
|
4512
|
+
notFound?: number;
|
|
4513
|
+
forbidden?: number;
|
|
4514
|
+
usageExceeded?: number;
|
|
4515
|
+
rateLimited?: number;
|
|
4516
|
+
unauthorized?: number;
|
|
4517
|
+
disabled?: number;
|
|
4518
|
+
insufficientPermissions?: number;
|
|
4519
|
+
expired?: number;
|
|
4520
|
+
/** @description Total number of verifications in the current time slice, regardless of outcome. */
|
|
4521
|
+
total: number;
|
|
4522
|
+
/** @description Only available when grouping by tag. */
|
|
4523
|
+
tag?: string;
|
|
4524
|
+
/** @description Filter by one or multiple tags. If multiple tags are provided */
|
|
4525
|
+
tags?: string[];
|
|
4526
|
+
/**
|
|
4527
|
+
* @description Only available when specifying groupBy=key in the query.
|
|
4528
|
+
* In this case there would be one datapoint per time and groupBy target.
|
|
4529
|
+
*/
|
|
4530
|
+
keyId?: string;
|
|
4531
|
+
/**
|
|
4532
|
+
* @description Only available when specifying groupBy=identity in the query.
|
|
4533
|
+
* In this case there would be one datapoint per time and groupBy target.
|
|
4534
|
+
*/
|
|
4535
|
+
identity?: {
|
|
4536
|
+
id: string;
|
|
4537
|
+
externalId: string;
|
|
4538
|
+
};
|
|
4539
|
+
}[];
|
|
4540
|
+
};
|
|
4541
|
+
};
|
|
4542
|
+
/** @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). */
|
|
4543
|
+
400: {
|
|
4544
|
+
content: {
|
|
4545
|
+
"application/json": components["schemas"]["ErrBadRequest"];
|
|
4546
|
+
};
|
|
4547
|
+
};
|
|
4548
|
+
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
4549
|
+
401: {
|
|
4550
|
+
content: {
|
|
4551
|
+
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
4552
|
+
};
|
|
4553
|
+
};
|
|
4554
|
+
/** @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. */
|
|
4555
|
+
403: {
|
|
4556
|
+
content: {
|
|
4557
|
+
"application/json": components["schemas"]["ErrForbidden"];
|
|
4558
|
+
};
|
|
4559
|
+
};
|
|
4560
|
+
/** @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. */
|
|
4561
|
+
404: {
|
|
4562
|
+
content: {
|
|
4563
|
+
"application/json": components["schemas"]["ErrNotFound"];
|
|
4564
|
+
};
|
|
4565
|
+
};
|
|
4566
|
+
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
4567
|
+
409: {
|
|
4568
|
+
content: {
|
|
4569
|
+
"application/json": components["schemas"]["ErrConflict"];
|
|
4570
|
+
};
|
|
4571
|
+
};
|
|
4572
|
+
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
4573
|
+
429: {
|
|
4574
|
+
content: {
|
|
4575
|
+
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
4576
|
+
};
|
|
4577
|
+
};
|
|
4578
|
+
/** @description The server has encountered a situation it does not know how to handle. */
|
|
4579
|
+
500: {
|
|
4580
|
+
content: {
|
|
4581
|
+
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
4582
|
+
};
|
|
4583
|
+
};
|
|
4584
|
+
};
|
|
4585
|
+
};
|
|
4493
4586
|
"deprecated.createKey": {
|
|
4494
4587
|
requestBody: {
|
|
4495
4588
|
content: {
|
|
@@ -5008,10 +5101,11 @@ declare class Unkey {
|
|
|
5008
5101
|
* console.log(result)
|
|
5009
5102
|
* ```
|
|
5010
5103
|
*/
|
|
5011
|
-
declare function verifyKey(req: string | {
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
}
|
|
5104
|
+
declare function verifyKey<TPermission extends string = string>(req: string | (Omit<paths["/v1/keys.verifyKey"]["post"]["requestBody"]["content"]["application/json"], "authorization"> & {
|
|
5105
|
+
authorization?: {
|
|
5106
|
+
permissions: PermissionQuery<TPermission>;
|
|
5107
|
+
};
|
|
5108
|
+
})): Promise<{
|
|
5015
5109
|
result?: never;
|
|
5016
5110
|
error: {
|
|
5017
5111
|
code: ErrorResponse["error"]["code"];
|
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.31.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 \"README.md\"\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 \"test\": \"vitest run\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.14.9\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.5\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.5.3\",\n \"vitest\": \"^1.6.0\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport type { 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 type { PermissionQuery } from \"@unkey/rbac\";\nimport type { 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 | string[]>;\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: {\n code: ErrorResponse[\"error\"][\"code\"];\n message: ErrorResponse[\"error\"][\"message\"];\n docs: ErrorResponse[\"error\"][\"docs\"];\n requestId: string;\n };\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 (typeof v === \"undefined\" || 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 | %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 ?? `status=${res?.status}`,\n res?.headers.get(\"unkey-request-id\"),\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return (await res.json()) as ErrorResponse;\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 public get ratelimits() {\n return {\n limit: async (\n req: paths[\"/v1/ratelimits.limit\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.limit\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.limit\"],\n method: \"POST\",\n body: req,\n });\n },\n getOverride: async (\n req: paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.getOverride\"],\n method: \"GET\",\n query: req,\n });\n },\n listOverrides: async (\n req: paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.listOverrides\"],\n method: \"GET\",\n query: req,\n });\n },\n\n setOverride: async (\n req: paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.setOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n\n deleteOverride: async (\n req: paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.deleteOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n public get identities() {\n return {\n create: async (\n req: paths[\"/v1/identities.createIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.createIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.createIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/identities.getIdentity\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.getIdentity\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.getIdentity\"],\n method: \"GET\",\n query: req,\n });\n },\n list: async (\n req: paths[\"/v1/identities.listIdentities\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.listIdentities\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.listIdentities\"],\n method: \"GET\",\n query: req,\n });\n },\n delete: async (\n req: paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.deleteIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/identities.updateIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.updateIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.updateIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n\n public get analytics() {\n return {\n getVerifications: async (\n req: paths[\"/v1/analytics.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/analytics.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"analytics.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get migrations() {\n return {\n createKeys: async (\n req: paths[\"/v1/migrations.createKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.createKeys\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.createKeys\"],\n method: \"POST\",\n body: req,\n });\n },\n enqueueKeys: async (\n req: paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"responses\"][\"202\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.enqueueKeys\"],\n method: \"POST\",\n body: 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;;;AC2DO,IAAM,QAAN,MAAY;AAAA,EACD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAED;AAAA,EAKhB,YAAY,MAAoB;AAC9B,SAAK,UAAU,KAAK,WAAW;AAC/B,SAAK,UAAU,KAAK,WAAW,KAAK;AACpC,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,YAAY,aAAa,IAAI;AAAA,IACpC;AAEA,SAAK,QAAQ,KAAK;AAIlB,QAAI,CAAC,KAAK,SAAS;AACjB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,QAAQ;AAAA,MACX,UAAU,KAAK,OAAO,YAAY;AAAA,MAClC,SAAS,KAAK,OAAO,YAAY,C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,"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.33.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 \"README.md\"\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 \"test\": \"vitest run\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.14.9\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.5\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.5.3\",\n \"vitest\": \"^1.6.0\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport type { 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 type { PermissionQuery } from \"@unkey/rbac\";\nimport type { 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 | string[]>;\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: {\n code: ErrorResponse[\"error\"][\"code\"];\n message: ErrorResponse[\"error\"][\"message\"];\n docs: ErrorResponse[\"error\"][\"docs\"];\n requestId: string;\n };\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 (typeof v === \"undefined\" || 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 | %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 ?? `status=${res?.status}`,\n res?.headers.get(\"unkey-request-id\"),\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return (await res.json()) as ErrorResponse;\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 public get ratelimits() {\n return {\n limit: async (\n req: paths[\"/v1/ratelimits.limit\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.limit\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.limit\"],\n method: \"POST\",\n body: req,\n });\n },\n getOverride: async (\n req: paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.getOverride\"],\n method: \"GET\",\n query: req,\n });\n },\n listOverrides: async (\n req: paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.listOverrides\"],\n method: \"GET\",\n query: req,\n });\n },\n\n setOverride: async (\n req: paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.setOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n\n deleteOverride: async (\n req: paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.deleteOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n public get identities() {\n return {\n create: async (\n req: paths[\"/v1/identities.createIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.createIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.createIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/identities.getIdentity\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.getIdentity\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.getIdentity\"],\n method: \"GET\",\n query: req,\n });\n },\n list: async (\n req: paths[\"/v1/identities.listIdentities\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.listIdentities\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.listIdentities\"],\n method: \"GET\",\n query: req,\n });\n },\n delete: async (\n req: paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.deleteIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/identities.updateIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.updateIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.updateIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n\n public get analytics() {\n return {\n getVerifications: async (\n req: paths[\"/v1/analytics.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/analytics.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"analytics.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get migrations() {\n return {\n createKeys: async (\n req: paths[\"/v1/migrations.createKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.createKeys\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.createKeys\"],\n method: \"POST\",\n body: req,\n });\n },\n enqueueKeys: async (\n req: paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"responses\"][\"202\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.enqueueKeys\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n}\n","import type { PermissionQuery } from \"@unkey/rbac\";\nimport { Unkey } from \"./client\";\nimport type { paths } from \"./openapi\";\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<TPermission extends string = string>(\n req:\n | string\n | (Omit<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n \"authorization\"\n > & { authorization?: { permissions: PermissionQuery<TPermission> } }),\n) {\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;AA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ACF;AAAA,EACF;AAAA,EAEA,IAAW,aAAa;AACtB,WAAO;AAAA,MACL,YAAY,OACV,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,uBAAuB;AAAA,UACpC,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,MACA,aAAa,OACX,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,wBAAwB;AAAA,UACrC,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;AC7gBO,SAAS,UACd,KAMA;AAGA,QAAM,QAAQ,IAAI,MAAM,EAAE,SAAS,SAAS,CAAC;AAC7C,SAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;;;AJlCA,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.31.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 \"README.md\"\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 \"test\": \"vitest run\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.14.9\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.5\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.5.3\",\n \"vitest\": \"^1.6.0\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport type { 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 type { PermissionQuery } from \"@unkey/rbac\";\nimport type { 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 | string[]>;\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: {\n code: ErrorResponse[\"error\"][\"code\"];\n message: ErrorResponse[\"error\"][\"message\"];\n docs: ErrorResponse[\"error\"][\"docs\"];\n requestId: string;\n };\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 (typeof v === \"undefined\" || 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 | %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 ?? `status=${res?.status}`,\n res?.headers.get(\"unkey-request-id\"),\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return (await res.json()) as ErrorResponse;\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 public get ratelimits() {\n return {\n limit: async (\n req: paths[\"/v1/ratelimits.limit\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.limit\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.limit\"],\n method: \"POST\",\n body: req,\n });\n },\n getOverride: async (\n req: paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.getOverride\"],\n method: \"GET\",\n query: req,\n });\n },\n listOverrides: async (\n req: paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.listOverrides\"],\n method: \"GET\",\n query: req,\n });\n },\n\n setOverride: async (\n req: paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.setOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n\n deleteOverride: async (\n req: paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.deleteOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n public get identities() {\n return {\n create: async (\n req: paths[\"/v1/identities.createIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.createIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.createIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/identities.getIdentity\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.getIdentity\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.getIdentity\"],\n method: \"GET\",\n query: req,\n });\n },\n list: async (\n req: paths[\"/v1/identities.listIdentities\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.listIdentities\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.listIdentities\"],\n method: \"GET\",\n query: req,\n });\n },\n delete: async (\n req: paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.deleteIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/identities.updateIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.updateIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.updateIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n\n public get analytics() {\n return {\n getVerifications: async (\n req: paths[\"/v1/analytics.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/analytics.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"analytics.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get migrations() {\n return {\n createKeys: async (\n req: paths[\"/v1/migrations.createKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.createKeys\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.createKeys\"],\n method: \"POST\",\n body: req,\n });\n },\n enqueueKeys: async (\n req: paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"responses\"][\"202\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.enqueueKeys\"],\n method: \"POST\",\n body: 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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AAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,MACA,QAAQ,OACN,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,2BAA2B;AAAA,UACxC,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEA,IAAW,YAAY;AACrB,WAAO;AAAA,MACL,kBAAkB,OAChB,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,4BAA4B;AAAA,UACzC,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEA,IAAW,aAAa;AACtB,WAAO;AAAA,MACL,YAAY,OACV,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,uBAAuB;AAAA,UACpC,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,MACA,aAAa,OACX,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,wBAAwB;AAAA,UACrC,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;AC/gBO,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.33.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 \"README.md\"\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 \"test\": \"vitest run\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.14.9\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.5\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.5.3\",\n \"vitest\": \"^1.6.0\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport type { 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 type { PermissionQuery } from \"@unkey/rbac\";\nimport type { 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 | string[]>;\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: {\n code: ErrorResponse[\"error\"][\"code\"];\n message: ErrorResponse[\"error\"][\"message\"];\n docs: ErrorResponse[\"error\"][\"docs\"];\n requestId: string;\n };\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 (typeof v === \"undefined\" || 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 | %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 ?? `status=${res?.status}`,\n res?.headers.get(\"unkey-request-id\"),\n );\n await new Promise((r) => setTimeout(r, backoff));\n }\n\n if (res) {\n return (await res.json()) as ErrorResponse;\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 public get ratelimits() {\n return {\n limit: async (\n req: paths[\"/v1/ratelimits.limit\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.limit\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.limit\"],\n method: \"POST\",\n body: req,\n });\n },\n getOverride: async (\n req: paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.getOverride\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.getOverride\"],\n method: \"GET\",\n query: req,\n });\n },\n listOverrides: async (\n req: paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.listOverrides\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.listOverrides\"],\n method: \"GET\",\n query: req,\n });\n },\n\n setOverride: async (\n req: paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.setOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.setOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n\n deleteOverride: async (\n req: paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/ratelimits.deleteOverride\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"ratelimits.deleteOverride\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n public get identities() {\n return {\n create: async (\n req: paths[\"/v1/identities.createIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.createIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.createIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/identities.getIdentity\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.getIdentity\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.getIdentity\"],\n method: \"GET\",\n query: req,\n });\n },\n list: async (\n req: paths[\"/v1/identities.listIdentities\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.listIdentities\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.listIdentities\"],\n method: \"GET\",\n query: req,\n });\n },\n delete: async (\n req: paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.deleteIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.deleteIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/identities.updateIdentity\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/identities.updateIdentity\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"identities.updateIdentity\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n\n public get analytics() {\n return {\n getVerifications: async (\n req: paths[\"/v1/analytics.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/analytics.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"analytics.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get migrations() {\n return {\n createKeys: async (\n req: paths[\"/v1/migrations.createKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.createKeys\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.createKeys\"],\n method: \"POST\",\n body: req,\n });\n },\n enqueueKeys: async (\n req: paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/migrations.enqueueKeys\"][\"post\"][\"responses\"][\"202\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"migrations.enqueueKeys\"],\n method: \"POST\",\n body: req,\n });\n },\n };\n }\n}\n","import type { PermissionQuery } from \"@unkey/rbac\";\nimport { Unkey } from \"./client\";\nimport type { paths } from \"./openapi\";\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<TPermission extends string = string>(\n req:\n | string\n | (Omit<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n \"authorization\"\n > & { authorization?: { permissions: PermissionQuery<TPermission> } }),\n) {\n // yes this is empty to make typescript happy but we don't need a token for verifying keys\n // it's not the cleanest but it works for now :)\n const unkey = new Unkey({ rootKey: \"public\" });\n return unkey.keys.verify(typeof req === \"string\" ? { key: req } : req);\n}\n","export * from \"./client\";\nexport * from \"./verify\";\nexport * from \"./errors\";\nexport { and, or, type Flatten } from \"@unkey/rbac\";\n"],"mappings":";AAEE,cAAW;;;ACmBN,SAAS,aAAa,MAAsC;AACjE,MAAI;AACJ,MAAI;AACJ,QAAM,cAAc,CAAC,cAAc,OAAO,EAAE;AAE5C,MAAI;AACF,QAAI,OAAO,YAAY,aAAa;AAClC,UAAI,QAAQ,IAAI,yBAAyB;AACvC,eAAO;AAAA,MACT;AACA,iBAAW,QAAQ,IAAI,SAAS,WAAW,QAAQ,IAAI,aAAa,QAAQ;AAG5E,UAAI,OAAO,gBAAgB,aAAa;AACtC,kBAAU;AAAA,MACZ,OAAO;AACL,kBAAU,QAAQ,QAAQ,OAAO;AAAA,MACnC;AAAA,IACF;AAEA,QAAI,KAAK,mBAAmB;AAC1B,kBAAY,KAAK,KAAK,iBAAiB;AAAA,IACzC;AAAA,EACF,SAAS,QAAQ;AAAA,EAAC;AAElB,SAAO,EAAE,UAAU,SAAS,YAAY;AAC1C;;;AC2DO,IAAM,QAAN,MAAY;AAAA,EACD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAED;AAAA,EAKhB,YAAY,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