@vllnt/convex-api-keys 0.4.0-canary.efaba72 → 0.4.0-canary.f0d8da1
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/CHANGELOG.md +41 -44
- package/README.md +33 -7
- package/docs/API.md +45 -7
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [
|
|
4
|
-
|
|
5
|
-
## [0.4.0] - 2026-11-27
|
|
3
|
+
## [0.4.0] - 2026-11-28
|
|
6
4
|
|
|
7
5
|
### Added
|
|
8
6
|
|
|
9
7
|
- The npm package now ships `docs/API.md`, `CHANGELOG.md` and `llms.txt`, so
|
|
10
8
|
coding agents can read docs that match the installed version from
|
|
11
9
|
`node_modules/@vllnt/convex-api-keys/`. `llms.txt` links shipped files by
|
|
12
|
-
relative path.
|
|
13
|
-
`pnpm test:coverage`) fails when one of them is missing from the tarball.
|
|
10
|
+
relative path.
|
|
14
11
|
- `docs/API.md` documents the package entry points and exported types.
|
|
15
12
|
- Every public export and `ApiKeys` method has a TSDoc summary, shipped in the
|
|
16
13
|
`.d.ts` files; `ApiKeys` links its package page with `@see`.
|
|
17
|
-
- `pnpm test:package` runs `scripts/check-docs.mjs`. It fails when a README
|
|
18
|
-
section is missing or out of order, a code block has no language, a relative
|
|
19
|
-
link or anchor breaks, an export or error message is undocumented, a README
|
|
20
|
-
or `docs/API.md` TypeScript example does not type-check against the built
|
|
21
|
-
package, or the vllnt footer, `llms.txt` ecosystem block or package metadata
|
|
22
|
-
drift.
|
|
23
14
|
|
|
24
15
|
### Changed
|
|
25
16
|
|
|
17
|
+
- **Breaking: `engines.node` is now `>=20`**, matching the lowest supported
|
|
18
|
+
`convex` (1.45.0, which declares `node >=20.0.0`). Node 18 users must
|
|
19
|
+
upgrade.
|
|
26
20
|
- **Behaviour change: `revoke()` keeps a final status final.** On a key whose
|
|
27
21
|
stored status is `expired` or `exhausted` it now does nothing, as it already
|
|
28
22
|
did for a `revoked` key: the status and `revokedAt` stay as they are and no
|
|
@@ -46,42 +40,48 @@
|
|
|
46
40
|
- README Related packages lists only packages this one uses in code; it is now
|
|
47
41
|
"None.".
|
|
48
42
|
- The `llms.txt` Ecosystem block links the release feed and package search.
|
|
49
|
-
- `
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
`
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
- Docs: `list()` and `listByTag()` never had a cursor; they return at most
|
|
44
|
+
`limit` keys (default 100). The 0.2.0 entry called this pagination. The
|
|
45
|
+
0.2.0 `ownerId` check covers the key-level admin calls only; `configure`
|
|
46
|
+
takes no `ownerId`.
|
|
47
|
+
- The README and `docs/API.md` document that `list` and `listByTag` return keys
|
|
48
|
+
in index order (status, then creation time), so the order and which keys a
|
|
49
|
+
`limit` returns change when a key is created, rotated or changes status.
|
|
50
|
+
- They document that `rotate` copies `name`, `scopes`, `tags`, `metadata`,
|
|
51
|
+
`expiresAt`, `env`, type and prefix to the new key, so a later `revokeByTag`
|
|
52
|
+
also revokes the replacement; and that keys with `remaining` cannot be
|
|
53
|
+
rotated.
|
|
54
|
+
- They document that `listByTag` accepts any `tag` (an invalid one matches
|
|
55
|
+
nothing) while `revokeByTag` throws `Invalid tag`.
|
|
56
|
+
- They document read limits: `revokeByTag` reads every active, rotating and
|
|
57
|
+
disabled key of the owner and `listByTag` scans until it finds `limit`
|
|
58
|
+
matches, so an owner with very many keys can hit Convex read limits; and
|
|
59
|
+
that `scopes` entries, `tags` entries and `ownerId` have no length limit.
|
|
60
|
+
- The README Testing section says `vite` must be a direct devDependency under
|
|
61
|
+
pnpm for `/// <reference types="vite/client" />`; `tsc` fails with `TS2688`
|
|
62
|
+
otherwise.
|
|
63
|
+
- The docs describe `metadata`'s limit as 4096 of the JSON's JavaScript string
|
|
64
|
+
length (UTF-16 code units; the error message still says bytes), the
|
|
65
|
+
`ApiKeys.component` property, the `./package.json` export, calling component
|
|
66
|
+
functions directly, and that the component's own `validate` returns
|
|
67
|
+
`reason: string`.
|
|
68
|
+
- Internal: a docs check (`scripts/check-docs.mjs`), a packed-tarball consumer
|
|
69
|
+
test (`scripts/test-consumer.mjs`), a tarball check that the shipped docs are
|
|
70
|
+
present and that `npm pkg fix` would rewrite no field, CI type-checking of
|
|
71
|
+
tests and `example/convex/`, `.spec.mts`/`.spec.cts` blocking in the
|
|
72
|
+
package-contents check, the 7-day dependency release age moved to
|
|
73
|
+
`pnpm-workspace.yaml` (Renovate matches it), and tests for every documented
|
|
74
|
+
API behaviour.
|
|
69
75
|
|
|
70
76
|
### Fixed
|
|
71
77
|
|
|
72
|
-
- `scripts/check-package-contents.sh` also blocks `.spec.mts` and `.spec.cts`
|
|
73
|
-
files, and CI runs its test harness.
|
|
74
78
|
- `package.json` `repository.url` uses the form npm expects, so publishing no
|
|
75
|
-
longer prints an auto-correction warning.
|
|
76
|
-
`npm pkg fix` would rewrite any field.
|
|
79
|
+
longer prints an auto-correction warning.
|
|
77
80
|
- `RunMutationCtx` and `RunQueryCtx` accept action and HTTP action contexts.
|
|
78
81
|
They were `Pick`s of the mutation and query context types, which an action
|
|
79
82
|
`ctx` does not satisfy, so calling `ApiKeys` methods from an action or HTTP
|
|
80
83
|
action failed to type-check. They are now interfaces with only the
|
|
81
84
|
`runMutation` / `runQuery` call, for public and internal function references.
|
|
82
|
-
- The 7-day minimum release age now lives in `pnpm-workspace.yaml`, where
|
|
83
|
-
pnpm 10 reads it; pnpm ignored it in the `package.json` `pnpm` field.
|
|
84
|
-
Renovate uses the same rule, with `@vllnt` packages exempt.
|
|
85
85
|
|
|
86
86
|
## [0.3.0] - 2026-11-26
|
|
87
87
|
|
|
@@ -148,8 +148,7 @@
|
|
|
148
148
|
from return type.
|
|
149
149
|
- **`validate()`**: `retryAfter` removed from failure response (no internal rate
|
|
150
150
|
limiting).
|
|
151
|
-
- **`list()` / `listByTag()`**: Now
|
|
152
|
-
There is no cursor.
|
|
151
|
+
- **`list()` / `listByTag()`**: Now paginated with `limit` param (default 100).
|
|
153
152
|
|
|
154
153
|
### Migration Guide
|
|
155
154
|
|
|
@@ -198,9 +197,7 @@ shardedCounterTest.register(t, "apiKeys/shardedCounter");
|
|
|
198
197
|
- Public client wrapper now forwards optional `limit` to `list()` and
|
|
199
198
|
`listByTag()`
|
|
200
199
|
- `ValidationFailure` no longer advertises the removed `retryAfter` field
|
|
201
|
-
- Auth boundary: `ownerId` cross-check on
|
|
202
|
-
(`revoke`, `rotate`, `update`, `disable`, `enable`, `getUsage`); `configure`
|
|
203
|
-
takes no `ownerId`
|
|
200
|
+
- Auth boundary: `ownerId` cross-check on all admin mutations
|
|
204
201
|
- Server-side secret generation for `create()` and `rotate()`
|
|
205
202
|
- Input validation: keyPrefix charset, env charset, gracePeriodMs bounds
|
|
206
203
|
(60s–30d), metadata size (4KB), scopes (50), tags (20)
|
|
@@ -209,7 +206,7 @@ shardedCounterTest.register(t, "apiKeys/shardedCounter");
|
|
|
209
206
|
- lastUsedAt throttled to 60s (reduces OCC contention)
|
|
210
207
|
- Remaining decrement decoupled from lastUsedAt write (single merged patch)
|
|
211
208
|
- revokeByTag expanded to include `rotating` and `disabled` statuses
|
|
212
|
-
-
|
|
209
|
+
- Paginated list/listByTag with configurable limit
|
|
213
210
|
|
|
214
211
|
## 0.1.1
|
|
215
212
|
|
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ Full reference: [docs/API.md](./docs/API.md).
|
|
|
92
92
|
| Export | Import path | What it is |
|
|
93
93
|
| ----------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------- |
|
|
94
94
|
| [`ApiKeys`](./docs/API.md#apikeys-class) | `@vllnt/convex-api-keys` | Client class; `new ApiKeys(components.apiKeys, config?)` |
|
|
95
|
+
| [`apiKeys.component`](./docs/API.md#apikeys-class) | property | The mounted `ComponentApi` the client calls |
|
|
95
96
|
| [`create(ctx, options)`](./docs/API.md#createctx-options) | method | Mutation: new key, returns `{ keyId, key }` once |
|
|
96
97
|
| [`validate(ctx, { key })`](./docs/API.md#validatectx--key-) | method | Mutation: check a key, count one use, return `ValidationResult` |
|
|
97
98
|
| [`matchStatus(ctx, { key })`](./docs/API.md#matchstatusctx--key-) | method | Query: stored status or `null`; writes nothing |
|
|
@@ -121,6 +122,8 @@ Full reference: [docs/API.md](./docs/API.md).
|
|
|
121
122
|
| [`register(t, name?)`](./docs/API.md#package-exports) | `@vllnt/convex-api-keys/test` | Mount the component in `convex-test` |
|
|
122
123
|
| [default export](./docs/API.md#package-exports) | `@vllnt/convex-api-keys/test` | `{ register, schema, modules }` |
|
|
123
124
|
| [`ComponentApi`](./docs/API.md#package-exports) | `@vllnt/convex-api-keys/_generated/component` | Type of `components.apiKeys` |
|
|
125
|
+
| [`package.json`](./docs/API.md#package-exports) | `@vllnt/convex-api-keys/package.json` | The package manifest (for tools that read the version) |
|
|
126
|
+
| [Component functions](./docs/API.md#component-functions) | `components.apiKeys.mutations.*` / `queries.*` | Call directly from your Convex functions; the client is the documented interface |
|
|
124
127
|
|
|
125
128
|
## Common tasks
|
|
126
129
|
|
|
@@ -198,6 +201,8 @@ export const listKeys = query({
|
|
|
198
201
|
await apiKeys.list(ctx, { ownerId: await ownerOf(ctx), status: "active" }),
|
|
199
202
|
});
|
|
200
203
|
|
|
204
|
+
// Keys with `remaining` (like createLimitedKey's) cannot be rotated:
|
|
205
|
+
// rotate throws `cannot rotate finite-use keys`.
|
|
201
206
|
export const rotateKey = mutation({
|
|
202
207
|
args: { keyId: v.string() },
|
|
203
208
|
handler: async (ctx, { keyId }) =>
|
|
@@ -298,7 +303,7 @@ not `ConvexError`s (see
|
|
|
298
303
|
| `Invalid tag "<tag>": must be alphanumeric with hyphens, starting with alphanumeric` | A tag (or `revokeByTag`'s `tag`) is empty or has other characters | Use letters, digits and `-`, starting with a letter or digit |
|
|
299
304
|
| `tags must have <= 20 entries (got <n>)` | More than 20 tags | Pass at most 20 |
|
|
300
305
|
| `scopes must have <= 50 entries (got <n>)` | More than 50 scopes | Pass at most 50 |
|
|
301
|
-
| `metadata must be <= 4096 bytes (got <n>)` | `JSON.stringify(metadata)` is
|
|
306
|
+
| `metadata must be <= 4096 bytes (got <n>)` | `JSON.stringify(metadata).length` is over 4096 (JavaScript string length, in UTF-16 code units; the message says bytes) | Store less, or keep a reference to your own table |
|
|
302
307
|
| `expiresAt must be in the future (finite timestamp)` | `expiresAt` is in the past, `NaN` or `Infinity` | Pass a future `Date.now()`-style timestamp in ms |
|
|
303
308
|
| `remaining must be > 0 (finite integer)` | `remaining` is 0, negative, fractional, `NaN` or `Infinity` | Pass a positive integer, or leave it out for unlimited use |
|
|
304
309
|
| `limit must be a positive integer` | `list` / `listByTag` got `limit` ≤ 0, fractional, `NaN` or `Infinity` | Pass a positive integer, or leave it out (default 100) |
|
|
@@ -320,8 +325,9 @@ not `ConvexError`s (see
|
|
|
320
325
|
is stored; a lost key cannot be recovered.
|
|
321
326
|
- Defaults: `prefix` `"vk"`, `type` `"secret"`, `env` `"live"`, `gracePeriodMs`
|
|
322
327
|
1 hour, `limit` 100.
|
|
323
|
-
- Limits: `name`, `prefix` and `env` 256 characters; `metadata` 4096
|
|
324
|
-
|
|
328
|
+
- Limits: `name`, `prefix` and `env` 256 characters; `metadata` 4096 of
|
|
329
|
+
`JSON.stringify(metadata).length` (JavaScript string length, in UTF-16 code
|
|
330
|
+
units); 50 `scopes`; 20 `tags`; `gracePeriodMs` 60 seconds to 30 days.
|
|
325
331
|
- Key format: `{prefix}_{secret|pub}_{env}_{8 chars}_{64 chars}`. Keys are
|
|
326
332
|
generated with a hex secret, but parsing checks only the secret's length: a
|
|
327
333
|
64-character secret that is not hex returns `not_found`. `prefix` and `env` cannot
|
|
@@ -338,10 +344,27 @@ not `ConvexError`s (see
|
|
|
338
344
|
- `configure` only stores `cleanupIntervalMs` and `defaultExpiryMs`. No cleanup
|
|
339
345
|
job runs and `create` does not apply `defaultExpiryMs`; pass `expiresAt`
|
|
340
346
|
instead.
|
|
341
|
-
- `list` and `listByTag` return at most `limit` keys and have no cursor
|
|
342
|
-
|
|
347
|
+
- `list` and `listByTag` return at most `limit` keys and have no cursor.
|
|
348
|
+
Results come in index order: `(ownerId, status)` (with `env`:
|
|
349
|
+
`(ownerId, env, status)`), statuses sorted as strings (`active`, `disabled`,
|
|
350
|
+
`exhausted`, `expired`, `revoked`, `rotating`), then creation time, oldest
|
|
351
|
+
first within a status. When a key's status changes, the order changes and so
|
|
352
|
+
do the keys a `limit` returns; calling again returns the same keys only while
|
|
353
|
+
no key is created, rotated or changes status, or (for `listByTag`) has its
|
|
354
|
+
tags changed.
|
|
355
|
+
- `listByTag` does not check `tag`: any string is accepted, and a tag that
|
|
356
|
+
could never be stored simply matches nothing. `revokeByTag` throws
|
|
357
|
+
`Invalid tag` for the same string.
|
|
343
358
|
- Rotation only works on `active` keys without `remaining` that are not past
|
|
344
359
|
`expiresAt`.
|
|
360
|
+
- `rotate` copies `name`, `scopes`, `tags`, `metadata`, `expiresAt`, `env`, type
|
|
361
|
+
and prefix to the new key, so a later `revokeByTag` also revokes the
|
|
362
|
+
replacement.
|
|
363
|
+
- Read limits: `revokeByTag` reads every `active`, `rotating` and `disabled` key
|
|
364
|
+
of the owner, and `listByTag` reads the owner's keys until it finds `limit`
|
|
365
|
+
matches. An owner with very many keys can hit Convex transaction read limits.
|
|
366
|
+
- There is no length limit on each `scopes` entry, each `tags` entry (beyond
|
|
367
|
+
the tag pattern) or `ownerId`.
|
|
345
368
|
- The component has no rate limiting and does not enforce scopes: `validate`
|
|
346
369
|
returns `scopes`, and your code decides.
|
|
347
370
|
- `ownerId` is an opaque string you pass in. The component checks that it
|
|
@@ -357,14 +380,17 @@ not `ConvexError`s (see
|
|
|
357
380
|
runtime.
|
|
358
381
|
- `@vllnt/convex-api-keys/test` is TypeScript source that needs `convex-test`,
|
|
359
382
|
`vitest` with Vite's `import.meta.glob`, and `@convex-dev/sharded-counter`.
|
|
360
|
-
- ESM only. `engines.node`: `>=
|
|
383
|
+
- ESM only. `engines.node`: `>=20`, the same as the lowest supported `convex`
|
|
384
|
+
(1.45.0).
|
|
361
385
|
|
|
362
386
|
## Testing
|
|
363
387
|
|
|
364
388
|
`@vllnt/convex-api-keys/test` exports `register(t, name = "apiKeys")` to mount
|
|
365
389
|
the component in a `convex-test` instance. It needs `convex-test`, `vitest`
|
|
366
390
|
(with Vite's `import.meta.glob`) and `@convex-dev/sharded-counter` (for its
|
|
367
|
-
`/test` helper) installed in the consuming app
|
|
391
|
+
`/test` helper) installed in the consuming app. Under pnpm, also add `vite` as
|
|
392
|
+
a direct devDependency: `/// <reference types="vite/client" />` needs it, and
|
|
393
|
+
`tsc` fails with `TS2688` (cannot find type definition file) without it.
|
|
368
394
|
|
|
369
395
|
```ts
|
|
370
396
|
// convex/keys.test.ts
|
package/docs/API.md
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
| `@vllnt/convex-api-keys/convex.config` (`.js`) | default: the component definition, passed to `app.use()` |
|
|
12
12
|
| `@vllnt/convex-api-keys/test` | `register(t, name = "apiKeys")` to mount the component in `convex-test`, plus a default export `{ register, schema, modules }` (TypeScript source; needs Vite's `import.meta.glob`) |
|
|
13
13
|
| `@vllnt/convex-api-keys/_generated/component` (`.js`) | type `ComponentApi` (the type of `components.apiKeys`) |
|
|
14
|
+
| `@vllnt/convex-api-keys/package.json` | the package manifest, for tools that read the installed version |
|
|
14
15
|
|
|
15
16
|
`RunMutationCtx` is any context with `runMutation` (mutation, action or HTTP
|
|
16
17
|
action); `RunQueryCtx` is any context with `runQuery` (query, mutation, action
|
|
@@ -28,6 +29,9 @@ const apiKeys = new ApiKeys(components.apiKeys, {
|
|
|
28
29
|
});
|
|
29
30
|
```
|
|
30
31
|
|
|
32
|
+
`apiKeys.component` is the mounted `ComponentApi` passed to the constructor
|
|
33
|
+
(`components.apiKeys`).
|
|
34
|
+
|
|
31
35
|
## Methods
|
|
32
36
|
|
|
33
37
|
### create(ctx, options)
|
|
@@ -43,7 +47,7 @@ key once — only the hash is stored.
|
|
|
43
47
|
| `scopes` | `string[]` | no | Permission scopes (max 50) |
|
|
44
48
|
| `tags` | `string[]` | no | Filterable tags (max 20) |
|
|
45
49
|
| `env` | `string` | no | Environment (default: `"live"`, must match `^[a-zA-Z0-9-]+$`) |
|
|
46
|
-
| `metadata` | `Record<string, unknown>` | no | Arbitrary JSON (max
|
|
50
|
+
| `metadata` | `Record<string, unknown>` | no | Arbitrary JSON; `JSON.stringify(metadata).length` max 4096 (JavaScript string length, UTF-16 code units) |
|
|
47
51
|
| `remaining` | `number` | no | Finite-use counter |
|
|
48
52
|
| `expiresAt` | `number` | no | Expiry timestamp (ms) |
|
|
49
53
|
|
|
@@ -73,7 +77,9 @@ does nothing and does not throw. It checks the stored status: a key past
|
|
|
73
77
|
### revokeByTag(ctx, { ownerId, tag })
|
|
74
78
|
|
|
75
79
|
Bulk revoke all keys matching a tag. Covers `active`, `rotating`, and `disabled`
|
|
76
|
-
statuses
|
|
80
|
+
statuses; it reads every key of the owner in those statuses, so an owner with
|
|
81
|
+
very many keys can hit Convex read limits. `revoked`, `expired` and `exhausted`
|
|
82
|
+
keys are not counted. Like `revoke()`, it checks the stored status, so a key past its expiry
|
|
77
83
|
that `validate()` has not marked `expired` yet is revoked.
|
|
78
84
|
|
|
79
85
|
**Returns:** `{ revokedCount: number }`
|
|
@@ -85,6 +91,10 @@ the grace period, capped by the old key's absolute expiry. Rotation requires an
|
|
|
85
91
|
active unlimited-use key; finite-use keys must be replaced explicitly so their
|
|
86
92
|
quota cannot be duplicated. Secret material is generated server-side.
|
|
87
93
|
|
|
94
|
+
The new key gets the old key's `name`, `scopes`, `tags`, `metadata`,
|
|
95
|
+
`expiresAt`, `env`, type and prefix, so a later `revokeByTag` with one of those
|
|
96
|
+
tags also revokes the replacement.
|
|
97
|
+
|
|
88
98
|
| Param | Type | Default | Description |
|
|
89
99
|
| --------------- | -------- | -------------- | ----------------------------------- |
|
|
90
100
|
| `gracePeriodMs` | `number` | `3600000` (1h) | Grace period (min 60s, max 30 days) |
|
|
@@ -96,13 +106,26 @@ quota cannot be duplicated. Secret material is generated server-side.
|
|
|
96
106
|
Return a bounded array of keys for an owner (default limit 100), with no raw
|
|
97
107
|
keys or hashes. There is no cursor or continuation token.
|
|
98
108
|
|
|
109
|
+
Results come in index order: `(ownerId, status)` (with `env`:
|
|
110
|
+
`(ownerId, env, status)`), statuses sorted as strings (`active`, `disabled`,
|
|
111
|
+
`exhausted`, `expired`, `revoked`, `rotating`), then creation time, oldest
|
|
112
|
+
first within a status. A status change moves a key, so the order and the keys
|
|
113
|
+
a `limit` returns change; repeating the call returns the same keys only while
|
|
114
|
+
no key is created, rotated or changes status, or (for `listByTag`) has its
|
|
115
|
+
tags changed.
|
|
116
|
+
|
|
99
117
|
**Returns:** `KeyMetadata[]` —
|
|
100
118
|
`{ keyId, name, lookupPrefix, type, env, scopes, tags, status, metadata?, remaining?, expiresAt?, createdAt, lastUsedAt? }`
|
|
101
119
|
|
|
102
120
|
### listByTag(ctx, { ownerId, tag, limit? })
|
|
103
121
|
|
|
104
122
|
Return a bounded array of keys matching a tag (default limit 100). There is no
|
|
105
|
-
cursor or continuation token; repeating the call does not advance a page.
|
|
123
|
+
cursor or continuation token; repeating the call does not advance a page. Same
|
|
124
|
+
order as `list` without `env`. It scans the owner's keys until it finds `limit`
|
|
125
|
+
matches.
|
|
126
|
+
|
|
127
|
+
`tag` is not validated: any string is accepted, and a tag no key can have
|
|
128
|
+
matches nothing. `revokeByTag` throws `Invalid tag` for the same string.
|
|
106
129
|
|
|
107
130
|
**Returns:** `KeyMetadata[]` (same shape as `list`)
|
|
108
131
|
|
|
@@ -147,6 +170,17 @@ must be finite and > 0. In this version the values are only stored: no cleanup
|
|
|
147
170
|
job runs and `create()` does not apply `defaultExpiryMs`; pass `expiresAt` to
|
|
148
171
|
`create()` to set an expiry.
|
|
149
172
|
|
|
173
|
+
## Component functions
|
|
174
|
+
|
|
175
|
+
The component's functions can be called directly through
|
|
176
|
+
`components.apiKeys.mutations.*` (`create`, `validate`, `revoke`,
|
|
177
|
+
`revokeByTag`, `rotate`, `update`, `disable`, `enable`, `configure`) and
|
|
178
|
+
`components.apiKeys.queries.*` (`list`, `listByTag`, `matchStatus`,
|
|
179
|
+
`getUsage`). The `ApiKeys` client is the documented interface; the direct
|
|
180
|
+
calls take the same arguments, except that the direct `create` also takes
|
|
181
|
+
`keyPrefix` (the client passes its `prefix`). The direct `validate` returns
|
|
182
|
+
`reason: string` (see [Types](#types)).
|
|
183
|
+
|
|
150
184
|
## Types
|
|
151
185
|
|
|
152
186
|
All exported from `@vllnt/convex-api-keys`.
|
|
@@ -166,6 +200,9 @@ All exported from `@vllnt/convex-api-keys`.
|
|
|
166
200
|
| `RunMutationCtx` | `{ runMutation(ref, args) }`: the `ctx` of a mutation, action or HTTP action |
|
|
167
201
|
| `RunQueryCtx` | `{ runQuery(ref, args) }`: the `ctx` of a query, mutation, action or HTTP action |
|
|
168
202
|
|
|
203
|
+
The component's own `validate` mutation returns `reason: string`; the client's
|
|
204
|
+
`validate()` narrows it to `ValidationFailureReason`.
|
|
205
|
+
|
|
169
206
|
## Errors
|
|
170
207
|
|
|
171
208
|
Every thrown message, its cause and its fix are listed in the README's
|
|
@@ -191,13 +228,14 @@ Status rules:
|
|
|
191
228
|
| ------------------- | -------------------------------------------------------------------------------- |
|
|
192
229
|
| `keyPrefix` | `^[a-zA-Z0-9]+$` (no underscores), max 256 characters |
|
|
193
230
|
| `env` | `^[a-zA-Z0-9-]+$` (no underscores — would break key parsing), max 256 characters |
|
|
194
|
-
| `ownerId` (create) | must not be empty (`ownerId must not be empty`)
|
|
231
|
+
| `ownerId` (create) | must not be empty (`ownerId must not be empty`); no length limit |
|
|
195
232
|
| `name` | must not be empty, max 256 characters |
|
|
196
|
-
| `metadata` | max 4096
|
|
197
|
-
| `scopes` | max 50 entries
|
|
198
|
-
| `tags` | max 20 entries, each matching `^[a-zA-Z0-9][a-zA-Z0-9-]
|
|
233
|
+
| `metadata` | `JSON.stringify(metadata).length` max 4096: JavaScript string length, in UTF-16 code units (the error says `bytes`) |
|
|
234
|
+
| `scopes` | max 50 entries; no length limit per entry |
|
|
235
|
+
| `tags` | max 20 entries, each matching `^[a-zA-Z0-9][a-zA-Z0-9-]*$`; no length limit |
|
|
199
236
|
| `gracePeriodMs` | min 60,000 (60s), max 2,592,000,000 (30 days); NaN rejected |
|
|
200
237
|
| `tag` (revokeByTag) | same pattern as `tags`; empty is rejected (`Invalid tag`) |
|
|
238
|
+
| `tag` (listByTag) | not validated; a string no key can have matches nothing |
|
|
201
239
|
| `remaining` | finite integer > 0 |
|
|
202
240
|
| `expiresAt` | finite timestamp in the future (NaN/Infinity rejected) |
|
|
203
241
|
| `limit` (queries) | positive integer (`limit must be a positive integer`) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-api-keys",
|
|
3
|
-
"version": "0.4.0-canary.
|
|
3
|
+
"version": "0.4.0-canary.f0d8da1",
|
|
4
4
|
"description": "Convex component to create, validate, revoke and rotate API keys, stored as SHA-256 hashes, with owner scoping, scopes, expiry, use limits and usage counts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"url": "git+https://github.com/vllnt/convex-api-keys.git"
|
|
92
92
|
},
|
|
93
93
|
"engines": {
|
|
94
|
-
"node": ">=
|
|
94
|
+
"node": ">=20"
|
|
95
95
|
},
|
|
96
96
|
"publishConfig": {
|
|
97
97
|
"access": "public"
|