@unkey/api 0.5.0-canary.0 → 0.5.0-canary.1

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.
Files changed (2) hide show
  1. package/dist/index.d.mts +199 -0
  2. package/package.json +4 -4
@@ -0,0 +1,199 @@
1
+ type UnkeyOptions = {
2
+ /**
3
+ * @default https://api.unkey.dev
4
+ */
5
+ baseUrl?: string;
6
+ /**
7
+ * The workspace key from unkey.dev
8
+ */
9
+ token: string;
10
+ };
11
+ declare class Unkey {
12
+ readonly baseUrl: string;
13
+ private readonly token;
14
+ constructor(opts: UnkeyOptions);
15
+ private fetch;
16
+ get keys(): {
17
+ create: (req: {
18
+ /**
19
+ * Provide a name to this key if you want for later reference
20
+ */
21
+ name?: string;
22
+ /**
23
+ * Choose an API where this key should be created.
24
+ */
25
+ apiId: string;
26
+ /**
27
+ * To make it easier for your users to understand which product an api key belongs to, you can add prefix them.
28
+ *
29
+ * For example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.
30
+ *
31
+ * The underscore is automtically added if you are defining a prefix, for example: "prefix": "abc" will result in a key like abc_xxxxxxxxx
32
+ */
33
+ prefix?: string;
34
+ /**
35
+ * The bytelength used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle.
36
+ *
37
+ * The default is 16 bytes, or 2128 possible combinations
38
+ */
39
+ byteLength?: number;
40
+ /**
41
+ * Your user’s Id. This will provide a link between Unkey and your customer record.
42
+ *
43
+ * When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
44
+ */
45
+ ownerId?: string;
46
+ /**
47
+ * This is a place for dynamic meta data, anything that feels useful for you should go here
48
+ *
49
+ * Example:
50
+ *
51
+ * ```json
52
+ * {
53
+ * "billingTier":"PRO",
54
+ * "trialEnds": "2023-06-16T17:16:37.161Z"
55
+ * }
56
+ * ```
57
+ */
58
+ meta?: unknown;
59
+ /**
60
+ * You can auto expire keys by providing a unix timestamp in milliseconds.
61
+ *
62
+ * Once keys expire they will automatically be deleted and are no longer valid.
63
+ */
64
+ expires?: number;
65
+ /**
66
+ * Unkey comes with per-key ratelimiting out of the box.
67
+ *
68
+ * @see https://docs.unkey.dev/features/ratelimiting
69
+ */
70
+ ratelimit?: {
71
+ type: "fast" | "consistent";
72
+ /**
73
+ * The total amount of burstable requests.
74
+ */
75
+ limit: number;
76
+ /**
77
+ * How many tokens to refill during each refillInterval
78
+ */
79
+ refillRate: number;
80
+ /**
81
+ * Determines the speed at which tokens are refilled.
82
+ * In milliseconds.
83
+ */
84
+ refillInterval: number;
85
+ };
86
+ /**
87
+ * Unkey allows you to set/update usage limits on individual keys
88
+ *
89
+ * @see https://docs.unkey.dev/features/remaining
90
+ */
91
+ remaining?: number;
92
+ }) => Promise<{
93
+ key: string;
94
+ keyId: string;
95
+ }>;
96
+ update: (req: {
97
+ /**
98
+ * The id of the key to update.
99
+ */
100
+ keyId: string;
101
+ /**
102
+ * Update the name
103
+ */
104
+ name?: string | null;
105
+ /**
106
+ * Update the owner id
107
+ */
108
+ ownerId?: string | null;
109
+ /**
110
+ * This is a place for dynamic meta data, anything that feels useful for you should go here
111
+ *
112
+ * Example:
113
+ *
114
+ * ```json
115
+ * {
116
+ * "billingTier":"PRO",
117
+ * "trialEnds": "2023-06-16T17:16:37.161Z"
118
+ * }
119
+ * ```
120
+ */
121
+ meta?: unknown | null;
122
+ /**
123
+ * Update the expiration time, Unix timstamp in milliseconds
124
+ *
125
+ *
126
+ */
127
+ expires?: number | null;
128
+ /**
129
+ * Update the ratelimit
130
+ *
131
+ * @see https://docs.unkey.dev/features/ratelimiting
132
+ */
133
+ ratelimit?: {
134
+ type: "fast" | "consistent";
135
+ /**
136
+ * The total amount of burstable requests.
137
+ */
138
+ limit: number;
139
+ /**
140
+ * How many tokens to refill during each refillInterval
141
+ */
142
+ refillRate: number;
143
+ /**
144
+ * Determines the speed at which tokens are refilled.
145
+ * In milliseconds.
146
+ */
147
+ refillInterval: number;
148
+ } | null;
149
+ /**
150
+ * Update the remaining verifications.
151
+ *
152
+ * @see https://docs.unkey.dev/features/remaining
153
+ */
154
+ remaining?: number | null;
155
+ }) => Promise<{
156
+ key: string;
157
+ keyId: string;
158
+ }>;
159
+ verify: (req: {
160
+ key: string;
161
+ }) => Promise<{
162
+ /**
163
+ * Whether or not this key is valid and has passed the ratelimit. If false you should not grant access to whatever the user is requesting
164
+ */
165
+ valid: boolean;
166
+ /**
167
+ * If you have set an ownerId on this key it is returned here. You can use this to clearly authenticate a user in your system.
168
+ */
169
+ ownerId?: string;
170
+ meta?: unknown;
171
+ }>;
172
+ revoke: (req: {
173
+ keyId: string;
174
+ }) => Promise<void>;
175
+ };
176
+ /**
177
+ * Must be authenticated via app token
178
+ */
179
+ get _internal(): {
180
+ createRootKey: (req: {
181
+ /**
182
+ * Provide a name to this key if you want for later reference
183
+ */
184
+ name?: string;
185
+ /**
186
+ * You can auto expire keys by providing a unix timestamp in milliseconds.
187
+ *
188
+ * Once keys expire they will automatically be deleted and are no longer valid.
189
+ */
190
+ expires?: number;
191
+ forWorkspaceId: string;
192
+ }) => Promise<{
193
+ key: string;
194
+ keyId: string;
195
+ }>;
196
+ };
197
+ }
198
+
199
+ export { Unkey, UnkeyOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unkey/api",
3
- "version": "0.5.0-canary.0",
3
+ "version": "0.5.0-canary.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -19,10 +19,10 @@
19
19
  ],
20
20
  "author": "Andreas Thomas <andreas@chronark.com>",
21
21
  "devDependencies": {
22
- "@types/node": "^20.2.1",
23
- "tsup": "^7.0.0",
22
+ "@types/node": "^20.4.4",
23
+ "tsup": "^7.1.0",
24
24
  "tsx": "^3.12.7",
25
- "typescript": "^5.0.4"
25
+ "typescript": "^5.1.6"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup"