@unkey/api 0.20.6 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/index.d.mts +276 -22
- package/dist/index.d.ts +276 -22
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/LICENSE +0 -661
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export { Flatten, and, or } from '@unkey/rbac';
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
/** OneOf type helpers */
|
|
11
|
+
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
12
|
+
type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
13
|
+
type OneOf<T extends any[]> = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR<A, B>, ...Rest]> : never;
|
|
14
|
+
|
|
10
15
|
interface paths {
|
|
11
16
|
"/v1/liveness": {
|
|
12
17
|
get: operations["v1.liveness"];
|
|
@@ -53,6 +58,9 @@ interface paths {
|
|
|
53
58
|
"/v1/migrations.createKeys": {
|
|
54
59
|
post: operations["v1.migrations.createKeys"];
|
|
55
60
|
};
|
|
61
|
+
"/v1/migrations.enqueueKeys": {
|
|
62
|
+
post: operations["v1.migrations.enqueueKeys"];
|
|
63
|
+
};
|
|
56
64
|
"/v1/keys": {
|
|
57
65
|
post: operations["deprecated.createKey"];
|
|
58
66
|
};
|
|
@@ -404,7 +412,7 @@ interface components {
|
|
|
404
412
|
*/
|
|
405
413
|
expires?: number;
|
|
406
414
|
/**
|
|
407
|
-
* @description
|
|
415
|
+
* @description Multi ratelimits TODO:
|
|
408
416
|
* @example {
|
|
409
417
|
* "limit": 10,
|
|
410
418
|
* "remaining": 9,
|
|
@@ -464,6 +472,12 @@ interface components {
|
|
|
464
472
|
*/
|
|
465
473
|
environment?: string;
|
|
466
474
|
};
|
|
475
|
+
/** @description A query for which permissions you require */
|
|
476
|
+
PermissionQuery: OneOf<[string, {
|
|
477
|
+
and: components["schemas"]["PermissionQuery"][];
|
|
478
|
+
}, {
|
|
479
|
+
or: components["schemas"]["PermissionQuery"][];
|
|
480
|
+
}, null]>;
|
|
467
481
|
V1KeysVerifyKeyRequest: {
|
|
468
482
|
/**
|
|
469
483
|
* @description The id of the api where the key belongs to. This is optional for now but will be required soon.
|
|
@@ -478,21 +492,7 @@ interface components {
|
|
|
478
492
|
key: string;
|
|
479
493
|
/** @description Perform RBAC checks */
|
|
480
494
|
authorization?: {
|
|
481
|
-
|
|
482
|
-
* @description A query for which permissions you require
|
|
483
|
-
* @example {
|
|
484
|
-
* "or": [
|
|
485
|
-
* {
|
|
486
|
-
* "and": [
|
|
487
|
-
* "dns.record.read",
|
|
488
|
-
* "dns.record.update"
|
|
489
|
-
* ]
|
|
490
|
-
* },
|
|
491
|
-
* "admin"
|
|
492
|
-
* ]
|
|
493
|
-
* }
|
|
494
|
-
*/
|
|
495
|
-
permissions?: Record<string, never>;
|
|
495
|
+
permissions?: components["schemas"]["PermissionQuery"];
|
|
496
496
|
};
|
|
497
497
|
ratelimit?: {
|
|
498
498
|
/**
|
|
@@ -501,6 +501,27 @@ interface components {
|
|
|
501
501
|
*/
|
|
502
502
|
cost?: number;
|
|
503
503
|
};
|
|
504
|
+
ratelimits?: {
|
|
505
|
+
/**
|
|
506
|
+
* @description The name of the ratelimit
|
|
507
|
+
* @example tokens
|
|
508
|
+
*/
|
|
509
|
+
name: string;
|
|
510
|
+
/**
|
|
511
|
+
* @description Optionally override how expensive this operation is and how many tokens are deducted from the current limit.
|
|
512
|
+
* @default 1
|
|
513
|
+
*/
|
|
514
|
+
cost?: number;
|
|
515
|
+
/**
|
|
516
|
+
* @description The identifier used for ratelimiting. If omitted, we use the key's id.
|
|
517
|
+
* @default key id
|
|
518
|
+
*/
|
|
519
|
+
identifier?: string;
|
|
520
|
+
/** @description Optionally override the limit. */
|
|
521
|
+
limit?: number;
|
|
522
|
+
/** @description Optionally override the ratelimit window duration. */
|
|
523
|
+
duration?: number;
|
|
524
|
+
}[];
|
|
504
525
|
};
|
|
505
526
|
};
|
|
506
527
|
responses: never;
|
|
@@ -802,8 +823,8 @@ interface operations {
|
|
|
802
823
|
*/
|
|
803
824
|
ratelimit?: {
|
|
804
825
|
/**
|
|
805
|
-
* @description Async will return a response immediately, lowering latency at the cost of accuracy.
|
|
806
|
-
* @default
|
|
826
|
+
* @description Async will return a response immediately, lowering latency at the cost of accuracy. Will be required soon.
|
|
827
|
+
* @default true
|
|
807
828
|
*/
|
|
808
829
|
async?: boolean;
|
|
809
830
|
/**
|
|
@@ -816,10 +837,10 @@ interface operations {
|
|
|
816
837
|
/** @description The total amount of requests in a given interval. */
|
|
817
838
|
limit: number;
|
|
818
839
|
/**
|
|
819
|
-
* @description The window duration in milliseconds
|
|
840
|
+
* @description The window duration in milliseconds. Will be required soon.
|
|
820
841
|
* @example 60000
|
|
821
842
|
*/
|
|
822
|
-
duration
|
|
843
|
+
duration?: number;
|
|
823
844
|
/**
|
|
824
845
|
* @deprecated
|
|
825
846
|
* @description How many tokens to refill during each refillInterval.
|
|
@@ -1655,7 +1676,10 @@ interface operations {
|
|
|
1655
1676
|
*/
|
|
1656
1677
|
duration: number;
|
|
1657
1678
|
/**
|
|
1658
|
-
* @description Expensive requests may use up more tokens. You can specify a cost to the request here and we'll deduct this many tokens in the current window.
|
|
1679
|
+
* @description Expensive requests may use up more tokens. You can specify a cost to the request here and we'll deduct this many tokens in the current window.
|
|
1680
|
+
* If there are not enough tokens left, the request is denied.
|
|
1681
|
+
*
|
|
1682
|
+
* Set it to 0 to receive the current limit without changing anything.
|
|
1659
1683
|
* @default 1
|
|
1660
1684
|
* @example 2
|
|
1661
1685
|
*/
|
|
@@ -1837,6 +1861,14 @@ interface operations {
|
|
|
1837
1861
|
* ]
|
|
1838
1862
|
*/
|
|
1839
1863
|
roles?: string[];
|
|
1864
|
+
/**
|
|
1865
|
+
* @description A list of permissions that this key should have. If the permission does not exist, an error is thrown
|
|
1866
|
+
* @example [
|
|
1867
|
+
* "domains.create_record",
|
|
1868
|
+
* "say_hello"
|
|
1869
|
+
* ]
|
|
1870
|
+
*/
|
|
1871
|
+
permissions?: string[];
|
|
1840
1872
|
/**
|
|
1841
1873
|
* @description You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again.
|
|
1842
1874
|
* @example 1623869797161
|
|
@@ -1978,6 +2010,214 @@ interface operations {
|
|
|
1978
2010
|
};
|
|
1979
2011
|
};
|
|
1980
2012
|
};
|
|
2013
|
+
"v1.migrations.enqueueKeys": {
|
|
2014
|
+
requestBody: {
|
|
2015
|
+
content: {
|
|
2016
|
+
"application/json": {
|
|
2017
|
+
/** @description Contact support@unkey.dev to receive your migration id. */
|
|
2018
|
+
migrationId: string;
|
|
2019
|
+
/** @description The id of the api, you want to migrate keys to */
|
|
2020
|
+
apiId: string;
|
|
2021
|
+
keys: ({
|
|
2022
|
+
/**
|
|
2023
|
+
* @description To make it easier for your users to understand which product an api key belongs to, you can add prefix them.
|
|
2024
|
+
*
|
|
2025
|
+
* For example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.
|
|
2026
|
+
*
|
|
2027
|
+
* The underscore is automatically added if you are defining a prefix, for example: "prefix": "abc" will result in a key like abc_xxxxxxxxx
|
|
2028
|
+
*/
|
|
2029
|
+
prefix?: string;
|
|
2030
|
+
/**
|
|
2031
|
+
* @description The name for your Key. This is not customer facing.
|
|
2032
|
+
* @example my key
|
|
2033
|
+
*/
|
|
2034
|
+
name?: string;
|
|
2035
|
+
/** @description The raw key in plaintext. If provided, unkey encrypts this value and stores it securely. Provide either `hash` or `plaintext` */
|
|
2036
|
+
plaintext?: string;
|
|
2037
|
+
/** @description Provide either `hash` or `plaintext` */
|
|
2038
|
+
hash?: {
|
|
2039
|
+
/** @description The hashed and encoded key */
|
|
2040
|
+
value: string;
|
|
2041
|
+
/**
|
|
2042
|
+
* @description The algorithm for hashing and encoding, currently only sha256 and base64 are supported
|
|
2043
|
+
* @enum {string}
|
|
2044
|
+
*/
|
|
2045
|
+
variant: "sha256_base64";
|
|
2046
|
+
};
|
|
2047
|
+
/**
|
|
2048
|
+
* @description The first 4 characters of the key. If a prefix is used, it should be the prefix plus 4 characters.
|
|
2049
|
+
* @example unkey_32kq
|
|
2050
|
+
*/
|
|
2051
|
+
start?: string;
|
|
2052
|
+
/**
|
|
2053
|
+
* @description Your user’s Id. This will provide a link between Unkey and your customer record.
|
|
2054
|
+
* When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
|
|
2055
|
+
* @example team_123
|
|
2056
|
+
*/
|
|
2057
|
+
ownerId?: string;
|
|
2058
|
+
/**
|
|
2059
|
+
* @description This is a place for dynamic meta data, anything that feels useful for you should go here
|
|
2060
|
+
* @example {
|
|
2061
|
+
* "billingTier": "PRO",
|
|
2062
|
+
* "trialEnds": "2023-06-16T17:16:37.161Z"
|
|
2063
|
+
* }
|
|
2064
|
+
*/
|
|
2065
|
+
meta?: {
|
|
2066
|
+
[key: string]: unknown;
|
|
2067
|
+
};
|
|
2068
|
+
/**
|
|
2069
|
+
* @description A list of roles that this key should have. If the role does not exist, an error is thrown
|
|
2070
|
+
* @example [
|
|
2071
|
+
* "admin",
|
|
2072
|
+
* "finance"
|
|
2073
|
+
* ]
|
|
2074
|
+
*/
|
|
2075
|
+
roles?: string[];
|
|
2076
|
+
/**
|
|
2077
|
+
* @description A list of permissions that this key should have. If the permission does not exist, an error is thrown
|
|
2078
|
+
* @example [
|
|
2079
|
+
* "domains.create_record",
|
|
2080
|
+
* "say_hello"
|
|
2081
|
+
* ]
|
|
2082
|
+
*/
|
|
2083
|
+
permissions?: string[];
|
|
2084
|
+
/**
|
|
2085
|
+
* @description You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again.
|
|
2086
|
+
* @example 1623869797161
|
|
2087
|
+
*/
|
|
2088
|
+
expires?: number;
|
|
2089
|
+
/**
|
|
2090
|
+
* @description You can limit the number of requests a key can make. Once a key reaches 0 remaining requests, it will automatically be disabled and is no longer valid unless you update it.
|
|
2091
|
+
* @example 1000
|
|
2092
|
+
*/
|
|
2093
|
+
remaining?: number;
|
|
2094
|
+
/**
|
|
2095
|
+
* @description Unkey enables you to refill verifications for each key at regular intervals.
|
|
2096
|
+
* @example {
|
|
2097
|
+
* "interval": "daily",
|
|
2098
|
+
* "amount": 100
|
|
2099
|
+
* }
|
|
2100
|
+
*/
|
|
2101
|
+
refill?: {
|
|
2102
|
+
/**
|
|
2103
|
+
* @description Unkey will automatically refill verifications at the set interval.
|
|
2104
|
+
* @enum {string}
|
|
2105
|
+
*/
|
|
2106
|
+
interval: "daily" | "monthly";
|
|
2107
|
+
/** @description The number of verifications to refill for each occurrence is determined individually for each key. */
|
|
2108
|
+
amount: number;
|
|
2109
|
+
};
|
|
2110
|
+
/**
|
|
2111
|
+
* @description Unkey comes with per-key fixed-window ratelimiting out of the box.
|
|
2112
|
+
* @example {
|
|
2113
|
+
* "type": "fast",
|
|
2114
|
+
* "limit": 10,
|
|
2115
|
+
* "duration": 60000
|
|
2116
|
+
* }
|
|
2117
|
+
*/
|
|
2118
|
+
ratelimit?: {
|
|
2119
|
+
/**
|
|
2120
|
+
* @description Async will return a response immediately, lowering latency at the cost of accuracy.
|
|
2121
|
+
* @default true
|
|
2122
|
+
*/
|
|
2123
|
+
async?: boolean;
|
|
2124
|
+
/**
|
|
2125
|
+
* @deprecated
|
|
2126
|
+
* @description Deprecated, use `async`. Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.
|
|
2127
|
+
* @default fast
|
|
2128
|
+
* @enum {string}
|
|
2129
|
+
*/
|
|
2130
|
+
type?: "fast" | "consistent";
|
|
2131
|
+
/** @description The total amount of requests in a given interval. */
|
|
2132
|
+
limit: number;
|
|
2133
|
+
/**
|
|
2134
|
+
* @description The window duration in milliseconds
|
|
2135
|
+
* @example 60000
|
|
2136
|
+
*/
|
|
2137
|
+
duration: number;
|
|
2138
|
+
/**
|
|
2139
|
+
* @deprecated
|
|
2140
|
+
* @description How many tokens to refill during each refillInterval.
|
|
2141
|
+
*/
|
|
2142
|
+
refillRate?: number;
|
|
2143
|
+
/**
|
|
2144
|
+
* @deprecated
|
|
2145
|
+
* @description The refill timeframe, in milliseconds.
|
|
2146
|
+
*/
|
|
2147
|
+
refillInterval?: number;
|
|
2148
|
+
};
|
|
2149
|
+
/**
|
|
2150
|
+
* @description Sets if key is enabled or disabled. Disabled keys are not valid.
|
|
2151
|
+
* @default true
|
|
2152
|
+
* @example false
|
|
2153
|
+
*/
|
|
2154
|
+
enabled?: boolean;
|
|
2155
|
+
/**
|
|
2156
|
+
* @description Environments allow you to divide your keyspace.
|
|
2157
|
+
*
|
|
2158
|
+
* Some applications like Stripe, Clerk, WorkOS and others have a concept of "live" and "test" keys to
|
|
2159
|
+
* give the developer a way to develop their own application without the risk of modifying real world
|
|
2160
|
+
* resources.
|
|
2161
|
+
*
|
|
2162
|
+
* When you set an environment, we will return it back to you when validating the key, so you can
|
|
2163
|
+
* handle it correctly.
|
|
2164
|
+
*/
|
|
2165
|
+
environment?: string;
|
|
2166
|
+
})[];
|
|
2167
|
+
};
|
|
2168
|
+
};
|
|
2169
|
+
};
|
|
2170
|
+
responses: {
|
|
2171
|
+
/** @description The key ids of all created keys */
|
|
2172
|
+
202: {
|
|
2173
|
+
content: {
|
|
2174
|
+
"application/json": Record<string, never>;
|
|
2175
|
+
};
|
|
2176
|
+
};
|
|
2177
|
+
/** @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). */
|
|
2178
|
+
400: {
|
|
2179
|
+
content: {
|
|
2180
|
+
"application/json": components["schemas"]["ErrBadRequest"];
|
|
2181
|
+
};
|
|
2182
|
+
};
|
|
2183
|
+
/** @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. */
|
|
2184
|
+
401: {
|
|
2185
|
+
content: {
|
|
2186
|
+
"application/json": components["schemas"]["ErrUnauthorized"];
|
|
2187
|
+
};
|
|
2188
|
+
};
|
|
2189
|
+
/** @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. */
|
|
2190
|
+
403: {
|
|
2191
|
+
content: {
|
|
2192
|
+
"application/json": components["schemas"]["ErrForbidden"];
|
|
2193
|
+
};
|
|
2194
|
+
};
|
|
2195
|
+
/** @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. */
|
|
2196
|
+
404: {
|
|
2197
|
+
content: {
|
|
2198
|
+
"application/json": components["schemas"]["ErrNotFound"];
|
|
2199
|
+
};
|
|
2200
|
+
};
|
|
2201
|
+
/** @description This response is sent when a request conflicts with the current state of the server. */
|
|
2202
|
+
409: {
|
|
2203
|
+
content: {
|
|
2204
|
+
"application/json": components["schemas"]["ErrConflict"];
|
|
2205
|
+
};
|
|
2206
|
+
};
|
|
2207
|
+
/** @description The user has sent too many requests in a given amount of time ("rate limiting") */
|
|
2208
|
+
429: {
|
|
2209
|
+
content: {
|
|
2210
|
+
"application/json": components["schemas"]["ErrTooManyRequests"];
|
|
2211
|
+
};
|
|
2212
|
+
};
|
|
2213
|
+
/** @description The server has encountered a situation it does not know how to handle. */
|
|
2214
|
+
500: {
|
|
2215
|
+
content: {
|
|
2216
|
+
"application/json": components["schemas"]["ErrInternalServerError"];
|
|
2217
|
+
};
|
|
2218
|
+
};
|
|
2219
|
+
};
|
|
2220
|
+
};
|
|
1981
2221
|
"deprecated.createKey": {
|
|
1982
2222
|
requestBody: {
|
|
1983
2223
|
content: {
|
|
@@ -2440,11 +2680,24 @@ declare class Unkey {
|
|
|
2440
2680
|
apiId?: string | undefined;
|
|
2441
2681
|
key: string;
|
|
2442
2682
|
authorization?: {
|
|
2443
|
-
permissions?:
|
|
2683
|
+
permissions?: string | {
|
|
2684
|
+
and: (string | any | {
|
|
2685
|
+
or: (string | any | any | null)[];
|
|
2686
|
+
} | null)[];
|
|
2687
|
+
} | {
|
|
2688
|
+
or: (string | any | any | null)[];
|
|
2689
|
+
} | null | undefined;
|
|
2444
2690
|
} | undefined;
|
|
2445
2691
|
ratelimit?: {
|
|
2446
2692
|
cost?: number | undefined;
|
|
2447
2693
|
} | undefined;
|
|
2694
|
+
ratelimits?: {
|
|
2695
|
+
name: string;
|
|
2696
|
+
cost?: number | undefined;
|
|
2697
|
+
identifier?: string | undefined;
|
|
2698
|
+
limit?: number | undefined;
|
|
2699
|
+
duration?: number | undefined;
|
|
2700
|
+
}[] | undefined;
|
|
2448
2701
|
}, "authorization"> & {
|
|
2449
2702
|
authorization?: {
|
|
2450
2703
|
permissions: PermissionQuery<TPermission>;
|
|
@@ -2466,6 +2719,7 @@ declare class Unkey {
|
|
|
2466
2719
|
};
|
|
2467
2720
|
get migrations(): {
|
|
2468
2721
|
createKeys: (req: paths["/v1/migrations.createKeys"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/migrations.createKeys"]["post"]["responses"]["200"]["content"]["application/json"]>>;
|
|
2722
|
+
enqueueKeys: (req: paths["/v1/migrations.enqueueKeys"]["post"]["requestBody"]["content"]["application/json"]) => Promise<Result<paths["/v1/migrations.enqueueKeys"]["post"]["responses"]["202"]["content"]["application/json"]>>;
|
|
2469
2723
|
};
|
|
2470
2724
|
}
|
|
2471
2725
|
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ __export(src_exports, {
|
|
|
28
28
|
module.exports = __toCommonJS(src_exports);
|
|
29
29
|
|
|
30
30
|
// package.json
|
|
31
|
-
var version = "0.
|
|
31
|
+
var version = "0.21.0";
|
|
32
32
|
|
|
33
33
|
// src/telemetry.ts
|
|
34
34
|
function getTelemetry(opts) {
|
|
@@ -251,6 +251,13 @@ var Unkey = class {
|
|
|
251
251
|
method: "POST",
|
|
252
252
|
body: req
|
|
253
253
|
});
|
|
254
|
+
},
|
|
255
|
+
enqueueKeys: async (req) => {
|
|
256
|
+
return await this.fetch({
|
|
257
|
+
path: ["v1", "migrations.enqueueKeys"],
|
|
258
|
+
method: "POST",
|
|
259
|
+
body: req
|
|
260
|
+
});
|
|
254
261
|
}
|
|
255
262
|
};
|
|
256
263
|
}
|
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.20.6\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"AGPL-3.0\",\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"keywords\": [\n \"unkey\",\n \"client\",\n \"api\"\n ],\n \"bugs\": {\n \"url\": \"https://github.com/unkeyed/unkey/issues\"\n },\n \"homepage\": \"https://github.com/unkeyed/unkey#readme\",\n \"files\": [\n \"./dist/**\"\n ],\n \"author\": \"Andreas Thomas <andreas@chronark.com>\",\n \"scripts\": {\n \"generate\": \"openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts\",\n \"build\": \"pnpm generate && tsup\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.12.7\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.5\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.3.3\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport 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>;\n }\n | {\n method: \"POST\";\n body?: unknown;\n query?: never;\n }\n);\n\ntype Result<R> =\n | {\n result: R;\n error?: never;\n }\n | {\n result?: never;\n error: ErrorResponse[\"error\"];\n };\n\nexport class Unkey {\n public readonly baseUrl: string;\n private readonly rootKey: string;\n private readonly cache?: RequestCache;\n private readonly telemetry?: Telemetry | null;\n\n public readonly retry: {\n attempts: number;\n backoff: (retryCount: number) => number;\n };\n\n constructor(opts: UnkeyOptions) {\n this.baseUrl = opts.baseUrl ?? \"https://api.unkey.dev\";\n this.rootKey = opts.rootKey ?? opts.token;\n if (!opts.disableTelemetry) {\n this.telemetry = getTelemetry(opts);\n }\n\n this.cache = opts.cache;\n /**\n * Even though typescript should prevent this, some people still pass undefined or empty strings\n */\n if (!this.rootKey) {\n throw new Error(\n \"Unkey root key must be set, maybe you passed in `undefined` or an empty string?\",\n );\n }\n\n this.retry = {\n attempts: opts.retry?.attempts ?? 5,\n backoff: opts.retry?.backoff ?? ((n) => Math.round(Math.exp(n) * 10)),\n };\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.rootKey}`,\n };\n if (this.telemetry?.sdkVersions) {\n headers[\"Unkey-Telemetry-SDK\"] = this.telemetry.sdkVersions.join(\",\");\n }\n if (this.telemetry?.platform) {\n headers[\"Unkey-Telemetry-Platform\"] = this.telemetry.platform;\n }\n if (this.telemetry?.runtime) {\n headers[\"Unkey-Telemetry-Runtime\"] = this.telemetry.runtime;\n }\n return headers;\n }\n\n private async fetch<TResult>(req: ApiRequest): Promise<Result<TResult>> {\n let res: Response | null = null;\n let err: Error | null = null;\n for (let i = 0; i <= this.retry.attempts; i++) {\n const url = new URL(`${this.baseUrl}/${req.path.join(\"/\")}`);\n if (req.query) {\n for (const [k, v] of Object.entries(req.query)) {\n if (v === null) {\n continue;\n }\n url.searchParams.set(k, v.toString());\n }\n }\n res = await fetch(url, {\n method: req.method,\n headers: this.getHeaders(),\n cache: this.cache,\n body: JSON.stringify(req.body),\n }).catch((e: Error) => {\n err = e;\n return null; // set `res` to `null`\n });\n if (res?.ok) {\n return { result: (await res.json()) as TResult };\n }\n const backoff = this.retry.backoff(i);\n console.debug(\n \"attempt %d of %d to reach %s failed, retrying in %d ms: %s | %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 { error: (await res.json()) as ErrorResponse[\"error\"] };\n }\n\n return {\n error: {\n // @ts-ignore\n code: \"FETCH_ERROR\",\n // @ts-ignore I don't understand why `err` is `never`\n message: err?.message ?? \"No response\",\n docs: \"https://developer.mozilla.org/en-US/docs/Web/API/fetch\",\n requestId: \"N/A\",\n },\n };\n }\n\n public get keys() {\n return {\n create: async (\n req: paths[\"/v1/keys.createKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.createKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.createKey\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/keys.updateKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateKey\"],\n method: \"POST\",\n body: req,\n });\n },\n verify: async <TPermission extends string = string>(\n req: Omit<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n \"authorization\"\n > & { authorization?: { permissions: PermissionQuery<TPermission> } },\n ): Promise<\n Result<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.verifyKey\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/keys.deleteKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.deleteKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.deleteKey\"],\n method: \"POST\",\n body: req,\n });\n },\n updateRemaining: async (\n req: paths[\"/v1/keys.updateRemaining\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateRemaining\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateRemaining\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/keys.getKey\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/keys.getKey\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getKey\"],\n method: \"GET\",\n query: req,\n });\n },\n getVerifications: async (\n req: paths[\"/v1/keys.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get apis() {\n return {\n create: async (\n req: paths[\"/v1/apis.createApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.createApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.createApi\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/apis.deleteApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.deleteApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.deleteApi\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/apis.getApi\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.getApi\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.getApi\"],\n method: \"GET\",\n query: req,\n });\n },\n listKeys: async (\n req: paths[\"/v1/apis.listKeys\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.listKeys\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.listKeys\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n 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 };\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 };\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,KA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,QAAQ,OACN,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,gBAAgB;AAAA,UAC7B,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,MACA,KAAK,OACH,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,aAAa;AAAA,UAC1B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,MACA,UAAU,OACR,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,eAAe;AAAA,UAC5B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EACA,IAAW,aAAa;AACtB,WAAO;AAAA,MACL,OAAO,OACL,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,kBAAkB;AAAA,UAC/B,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EACA,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,IACF;AAAA,EACF;AACF;;;AC/WO,SAAS,UAAU,KAA8C;AAGtE,QAAM,QAAQ,IAAI,MAAM,EAAE,SAAS,SAAS,CAAC;AAC7C,SAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;;;AJzBA,kBAAsC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../package.json","../src/telemetry.ts","../src/client.ts","../src/verify.ts"],"sourcesContent":["export * from \"./client\";\nexport * from \"./verify\";\nexport * from \"./errors\";\nexport { and, or, type Flatten } from \"@unkey/rbac\";\n","{\n \"name\": \"@unkey/api\",\n \"version\": \"0.21.0\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"AGPL-3.0\",\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"keywords\": [\n \"unkey\",\n \"client\",\n \"api\"\n ],\n \"bugs\": {\n \"url\": \"https://github.com/unkeyed/unkey/issues\"\n },\n \"homepage\": \"https://github.com/unkeyed/unkey#readme\",\n \"files\": [\n \"./dist/**\"\n ],\n \"author\": \"Andreas Thomas <andreas@chronark.com>\",\n \"scripts\": {\n \"generate\": \"openapi-typescript https://api.unkey.dev/openapi.json -o ./src/openapi.d.ts\",\n \"build\": \"pnpm generate && tsup\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^20.14.9\",\n \"@unkey/tsconfig\": \"workspace:^\",\n \"openapi-typescript\": \"^6.7.5\",\n \"tsup\": \"^8.0.2\",\n \"typescript\": \"^5.3.3\"\n },\n \"dependencies\": {\n \"@unkey/rbac\": \"workspace:^\"\n }\n}\n","import { version } from \"../package.json\";\nimport 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>;\n }\n | {\n method: \"POST\";\n body?: unknown;\n query?: never;\n }\n);\n\ntype Result<R> =\n | {\n result: R;\n error?: never;\n }\n | {\n result?: never;\n error: ErrorResponse[\"error\"];\n };\n\nexport class Unkey {\n public readonly baseUrl: string;\n private readonly rootKey: string;\n private readonly cache?: RequestCache;\n private readonly telemetry?: Telemetry | null;\n\n public readonly retry: {\n attempts: number;\n backoff: (retryCount: number) => number;\n };\n\n constructor(opts: UnkeyOptions) {\n this.baseUrl = opts.baseUrl ?? \"https://api.unkey.dev\";\n this.rootKey = opts.rootKey ?? opts.token;\n if (!opts.disableTelemetry) {\n this.telemetry = getTelemetry(opts);\n }\n\n this.cache = opts.cache;\n /**\n * Even though typescript should prevent this, some people still pass undefined or empty strings\n */\n if (!this.rootKey) {\n throw new Error(\n \"Unkey root key must be set, maybe you passed in `undefined` or an empty string?\",\n );\n }\n\n this.retry = {\n attempts: opts.retry?.attempts ?? 5,\n backoff: opts.retry?.backoff ?? ((n) => Math.round(Math.exp(n) * 10)),\n };\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.rootKey}`,\n };\n if (this.telemetry?.sdkVersions) {\n headers[\"Unkey-Telemetry-SDK\"] = this.telemetry.sdkVersions.join(\",\");\n }\n if (this.telemetry?.platform) {\n headers[\"Unkey-Telemetry-Platform\"] = this.telemetry.platform;\n }\n if (this.telemetry?.runtime) {\n headers[\"Unkey-Telemetry-Runtime\"] = this.telemetry.runtime;\n }\n return headers;\n }\n\n private async fetch<TResult>(req: ApiRequest): Promise<Result<TResult>> {\n let res: Response | null = null;\n let err: Error | null = null;\n for (let i = 0; i <= this.retry.attempts; i++) {\n const url = new URL(`${this.baseUrl}/${req.path.join(\"/\")}`);\n if (req.query) {\n for (const [k, v] of Object.entries(req.query)) {\n if (v === null) {\n continue;\n }\n url.searchParams.set(k, v.toString());\n }\n }\n res = await fetch(url, {\n method: req.method,\n headers: this.getHeaders(),\n cache: this.cache,\n body: JSON.stringify(req.body),\n }).catch((e: Error) => {\n err = e;\n return null; // set `res` to `null`\n });\n if (res?.ok) {\n return { result: (await res.json()) as TResult };\n }\n const backoff = this.retry.backoff(i);\n console.debug(\n \"attempt %d of %d to reach %s failed, retrying in %d ms: %s | %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 { error: (await res.json()) as ErrorResponse[\"error\"] };\n }\n\n return {\n error: {\n // @ts-ignore\n code: \"FETCH_ERROR\",\n // @ts-ignore I don't understand why `err` is `never`\n message: err?.message ?? \"No response\",\n docs: \"https://developer.mozilla.org/en-US/docs/Web/API/fetch\",\n requestId: \"N/A\",\n },\n };\n }\n\n public get keys() {\n return {\n create: async (\n req: paths[\"/v1/keys.createKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.createKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.createKey\"],\n method: \"POST\",\n body: req,\n });\n },\n update: async (\n req: paths[\"/v1/keys.updateKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateKey\"],\n method: \"POST\",\n body: req,\n });\n },\n verify: async <TPermission extends string = string>(\n req: Omit<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n \"authorization\"\n > & { authorization?: { permissions: PermissionQuery<TPermission> } },\n ): Promise<\n Result<\n paths[\"/v1/keys.verifyKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.verifyKey\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/keys.deleteKey\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.deleteKey\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.deleteKey\"],\n method: \"POST\",\n body: req,\n });\n },\n updateRemaining: async (\n req: paths[\"/v1/keys.updateRemaining\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.updateRemaining\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.updateRemaining\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/keys.getKey\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/keys.getKey\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getKey\"],\n method: \"GET\",\n query: req,\n });\n },\n getVerifications: async (\n req: paths[\"/v1/keys.getVerifications\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<\n paths[\"/v1/keys.getVerifications\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"keys.getVerifications\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n\n public get apis() {\n return {\n create: async (\n req: paths[\"/v1/apis.createApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.createApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.createApi\"],\n method: \"POST\",\n body: req,\n });\n },\n delete: async (\n req: paths[\"/v1/apis.deleteApi\"][\"post\"][\"requestBody\"][\"content\"][\"application/json\"],\n ): Promise<\n Result<\n paths[\"/v1/apis.deleteApi\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.deleteApi\"],\n method: \"POST\",\n body: req,\n });\n },\n get: async (\n req: paths[\"/v1/apis.getApi\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.getApi\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.getApi\"],\n method: \"GET\",\n query: req,\n });\n },\n listKeys: async (\n req: paths[\"/v1/apis.listKeys\"][\"get\"][\"parameters\"][\"query\"],\n ): Promise<\n Result<paths[\"/v1/apis.listKeys\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]>\n > => {\n return await this.fetch({\n path: [\"v1\", \"apis.listKeys\"],\n method: \"GET\",\n query: req,\n });\n },\n };\n }\n 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 };\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;;;ACsDO,IAAM,QAAN,MAAY;AAAA,EACD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAED;AAAA,EAKhB,YAAY,MAAoB;AAC9B,SAAK,UAAU,KAAK,WAAW;AAC/B,SAAK,UAAU,KAA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AAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,MACA,UAAU,OACR,QAGG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,eAAe;AAAA,UAC5B,QAAQ;AAAA,UACR,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EACA,IAAW,aAAa;AACtB,WAAO;AAAA,MACL,OAAO,OACL,QAKG;AACH,eAAO,MAAM,KAAK,MAAM;AAAA,UACtB,MAAM,CAAC,MAAM,kBAAkB;AAAA,UAC/B,QAAQ;AAAA,UACR,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EACA,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;;;AC5XO,SAAS,UAAU,KAA8C;AAGtE,QAAM,QAAQ,IAAI,MAAM,EAAE,SAAS,SAAS,CAAC;AAC7C,SAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,IAAI,IAAI,GAAG;AACvE;;;AJzBA,kBAAsC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.21.0";
|
|
3
3
|
|
|
4
4
|
// src/telemetry.ts
|
|
5
5
|
function getTelemetry(opts) {
|
|
@@ -222,6 +222,13 @@ var Unkey = class {
|
|
|
222
222
|
method: "POST",
|
|
223
223
|
body: req
|
|
224
224
|
});
|
|
225
|
+
},
|
|
226
|
+
enqueueKeys: async (req) => {
|
|
227
|
+
return await this.fetch({
|
|
228
|
+
path: ["v1", "migrations.enqueueKeys"],
|
|
229
|
+
method: "POST",
|
|
230
|
+
body: req
|
|
231
|
+
});
|
|
225
232
|
}
|
|
226
233
|
};
|
|
227
234
|
}
|