@vllnt/convex-api-keys 0.1.0 → 0.1.1-canary.61796d1

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 (67) hide show
  1. package/README.md +44 -55
  2. package/dist/client/_generated/_ignore.d.ts +1 -0
  3. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  4. package/dist/client/_generated/_ignore.js +3 -0
  5. package/dist/client/_generated/_ignore.js.map +1 -0
  6. package/dist/client/index.d.ts +69 -0
  7. package/dist/client/index.d.ts.map +1 -0
  8. package/dist/client/index.js +82 -0
  9. package/dist/client/index.js.map +1 -0
  10. package/dist/client/types.d.ts +59 -0
  11. package/dist/client/types.d.ts.map +1 -0
  12. package/dist/client/types.js +2 -0
  13. package/dist/client/types.js.map +1 -0
  14. package/dist/component/_generated/api.d.ts +38 -0
  15. package/dist/component/_generated/api.d.ts.map +1 -0
  16. package/dist/component/_generated/api.js +31 -0
  17. package/dist/component/_generated/api.js.map +1 -0
  18. package/dist/component/_generated/component.d.ts +141 -0
  19. package/dist/component/_generated/component.d.ts.map +1 -0
  20. package/dist/component/_generated/component.js +11 -0
  21. package/dist/component/_generated/component.js.map +1 -0
  22. package/dist/component/_generated/dataModel.d.ts +46 -0
  23. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  24. package/dist/component/_generated/dataModel.js +11 -0
  25. package/dist/component/_generated/dataModel.js.map +1 -0
  26. package/dist/component/_generated/server.d.ts +121 -0
  27. package/dist/component/_generated/server.d.ts.map +1 -0
  28. package/dist/component/_generated/server.js +78 -0
  29. package/dist/component/_generated/server.js.map +1 -0
  30. package/dist/component/convex.config.d.ts +3 -0
  31. package/dist/component/convex.config.d.ts.map +1 -0
  32. package/dist/component/convex.config.js +6 -0
  33. package/dist/component/convex.config.js.map +1 -0
  34. package/dist/component/mutations.d.ts +80 -0
  35. package/dist/component/mutations.d.ts.map +1 -0
  36. package/dist/component/mutations.js +422 -0
  37. package/dist/component/mutations.js.map +1 -0
  38. package/dist/component/queries.d.ts +47 -0
  39. package/dist/component/queries.d.ts.map +1 -0
  40. package/dist/component/queries.js +117 -0
  41. package/dist/component/queries.js.map +1 -0
  42. package/dist/component/schema.d.ts +52 -0
  43. package/dist/component/schema.d.ts.map +1 -0
  44. package/dist/component/schema.js +33 -0
  45. package/dist/component/schema.js.map +1 -0
  46. package/dist/component/validators.d.ts +3 -0
  47. package/dist/component/validators.d.ts.map +1 -0
  48. package/dist/component/validators.js +4 -0
  49. package/dist/component/validators.js.map +1 -0
  50. package/dist/log.d.ts +11 -0
  51. package/dist/log.d.ts.map +1 -0
  52. package/dist/log.js +15 -0
  53. package/dist/log.js.map +1 -0
  54. package/dist/shared.d.ts +38 -0
  55. package/dist/shared.d.ts.map +1 -0
  56. package/dist/shared.js +98 -0
  57. package/dist/shared.js.map +1 -0
  58. package/package.json +21 -23
  59. package/src/client/index.ts +23 -38
  60. package/src/client/types.ts +2 -12
  61. package/src/component/_generated/api.ts +0 -3
  62. package/src/component/_generated/component.ts +8 -11
  63. package/src/component/convex.config.ts +0 -6
  64. package/src/component/mutations.ts +130 -154
  65. package/src/component/queries.ts +56 -91
  66. package/src/component/schema.ts +0 -11
  67. package/src/shared.ts +53 -25
package/README.md CHANGED
@@ -4,32 +4,33 @@
4
4
 
5
5
  # @vllnt/convex-api-keys
6
6
 
7
- Secure API key management as a [Convex component](https://docs.convex.dev/components). Create, validate, revoke, rotate, rate-limit, and track usage — all backed by battle-tested `@convex-dev/*` ecosystem components.
7
+ Secure API key management as a [Convex component](https://docs.convex.dev/components). Create, validate, revoke, rotate, and track usage — all with built-in auth boundaries and structured audit logging.
8
8
 
9
9
  ## Features
10
10
 
11
- - **Secure by default** — SHA-256 hashed storage, constant-time comparison, prefix-indexed O(1) lookup
11
+ - **Secure by default** — SHA-256 hashed storage, constant-time comparison, prefix-indexed O(1) lookup, server-side secret generation
12
+ - **Auth boundary** — `ownerId` required on all admin mutations — prevents cross-tenant access
12
13
  - **Key types** — `secret` and `publishable` keys with type-encoded prefixes
13
14
  - **Finite-use keys** — `remaining` counter with atomic decrement (verification tokens, one-time-use)
14
15
  - **Disable / Enable** — reversible pause without revoking
15
- - **Rotation** — configurable grace period where both old and new keys are valid
16
- - **Bulk revoke** — revoke all keys matching a tag in one call
16
+ - **Rotation** — configurable grace period (60s–30d) where both old and new keys are valid
17
+ - **Bulk revoke** — revoke all keys matching a tag (active, rotating, and disabled)
17
18
  - **Tags & environments** — filter keys by tags and environment strings
18
19
  - **Multi-tenant** — every query scoped by `ownerId`, no cross-tenant leakage
19
- - **Usage tracking** — audit event log + per-key usage analytics
20
- - **Extensible** — custom metadata, configurable prefix, event callbacks
20
+ - **Usage tracking** — per-key usage counter via `@convex-dev/sharded-counter`
21
+ - **Input validation** — keyPrefix/env charset, metadata size (4KB), scopes (50), tags (20)
22
+ - **Structured logging** — audit trail via structured logs (Convex dashboard)
21
23
 
22
24
  ## Architecture
23
25
 
24
26
  ```
25
27
  Your App → @vllnt/convex-api-keys
26
- ├── @convex-dev/rate-limiter (per-key rate limiting)
27
- ├── @convex-dev/sharded-counter (high-throughput counters)
28
- ├── @convex-dev/aggregate (O(log n) analytics)
29
- └── @convex-dev/crons (scheduled cleanup)
28
+ └── @convex-dev/sharded-counter (high-throughput usage counters)
30
29
  ```
31
30
 
32
- You install one package. Child components are internal — they don't appear in your `convex.config.ts`.
31
+ You install one package. The child component is internal — it doesn't appear in your `convex.config.ts`.
32
+
33
+ > **Rate limiting** is your responsibility. Add `@convex-dev/rate-limiter` at your HTTP action/mutation layer where you have real caller context (IP, auth, plan tier). The component has zero caller context and cannot make informed rate-limit decisions.
33
34
 
34
35
  ## Installation
35
36
 
@@ -46,9 +47,6 @@ import apiKeys from "@vllnt/convex-api-keys/convex.config";
46
47
  const app = defineApp();
47
48
  app.use(apiKeys);
48
49
 
49
- // Optional: multiple isolated instances
50
- app.use(apiKeys, { name: "serviceKeys" });
51
-
52
50
  export default app;
53
51
  ```
54
52
 
@@ -72,15 +70,16 @@ const apiKeys = new ApiKeys(components.apiKeys, {
72
70
  const { key, keyId } = await apiKeys.create(ctx, {
73
71
  name: "Production SDK Key",
74
72
  ownerId: orgId,
75
- type: "secret", // "secret" | "publishable"
73
+ type: "secret",
76
74
  scopes: ["read:users", "write:orders"],
77
75
  tags: ["sdk", "v2"],
78
- env: "live", // any string
76
+ env: "live",
79
77
  metadata: { plan: "enterprise" },
80
78
  expiresAt: Date.now() + 90 * 24 * 60 * 60 * 1000,
81
- remaining: 100000, // optional: finite-use
79
+ remaining: 100000,
82
80
  });
83
81
  // key = "myapp_secret_live_a1b2c3d4_<64-char-hex>"
82
+ // Secret material is generated server-side — never passed from client
84
83
  ```
85
84
 
86
85
  ### Validate a key
@@ -90,18 +89,17 @@ const result = await apiKeys.validate(ctx, { key: bearerToken });
90
89
 
91
90
  if (!result.valid) {
92
91
  // result.reason: "malformed" | "not_found" | "revoked" | "expired"
93
- // | "exhausted" | "disabled" | "rate_limited"
92
+ // | "exhausted" | "disabled"
94
93
  return new Response("Unauthorized", { status: 401 });
95
94
  }
96
95
 
97
- // result.valid === true
98
96
  const { keyId, ownerId, scopes, tags, env, type, metadata, remaining } = result;
99
97
  ```
100
98
 
101
99
  ### List keys
102
100
 
103
101
  ```ts
104
- const allKeys = await apiKeys.list(ctx, { ownerId: orgId });
102
+ const keys = await apiKeys.list(ctx, { ownerId: orgId });
105
103
  const prodKeys = await apiKeys.list(ctx, { ownerId: orgId, env: "live" });
106
104
  const taggedKeys = await apiKeys.listByTag(ctx, { ownerId: orgId, tag: "sdk" });
107
105
  ```
@@ -111,6 +109,7 @@ const taggedKeys = await apiKeys.listByTag(ctx, { ownerId: orgId, tag: "sdk" });
111
109
  ```ts
112
110
  await apiKeys.update(ctx, {
113
111
  keyId,
112
+ ownerId: orgId, // required — auth boundary
114
113
  name: "Renamed Key",
115
114
  scopes: ["read:users"],
116
115
  tags: ["sdk", "v3"],
@@ -121,19 +120,16 @@ await apiKeys.update(ctx, {
121
120
  ### Disable / Enable
122
121
 
123
122
  ```ts
124
- await apiKeys.disable(ctx, { keyId });
125
- // validate() → { valid: false, reason: "disabled" }
126
-
127
- await apiKeys.enable(ctx, { keyId });
128
- // validate() → { valid: true, ... }
123
+ await apiKeys.disable(ctx, { keyId, ownerId: orgId });
124
+ await apiKeys.enable(ctx, { keyId, ownerId: orgId });
129
125
  ```
130
126
 
131
127
  ### Revoke
132
128
 
133
129
  ```ts
134
- await apiKeys.revoke(ctx, { keyId });
130
+ await apiKeys.revoke(ctx, { keyId, ownerId: orgId });
135
131
 
136
- // Bulk revoke by tag
132
+ // Bulk revoke by tag (catches active, rotating, and disabled keys)
137
133
  await apiKeys.revokeByTag(ctx, { ownerId: orgId, tag: "compromised" });
138
134
  ```
139
135
 
@@ -142,31 +138,16 @@ await apiKeys.revokeByTag(ctx, { ownerId: orgId, tag: "compromised" });
142
138
  ```ts
143
139
  const { newKey, newKeyId, oldKeyExpiresAt } = await apiKeys.rotate(ctx, {
144
140
  keyId,
145
- gracePeriodMs: 3600000, // 1 hour — both keys valid
141
+ ownerId: orgId, // required — auth boundary
142
+ gracePeriodMs: 3600000, // 1 hour — both keys valid (min 60s, max 30d)
146
143
  });
147
144
  ```
148
145
 
149
146
  ### Usage analytics
150
147
 
151
148
  ```ts
152
- const usage = await apiKeys.getUsage(ctx, {
153
- keyId,
154
- period: { start: startOfMonth, end: Date.now() },
155
- });
156
- // { total: 42000, remaining: 58000, lastUsedAt: 1711036800000 }
157
- ```
158
-
159
- ### Finite-use keys (verification tokens)
160
-
161
- ```ts
162
- const { key } = await apiKeys.create(ctx, {
163
- name: "Email Verification",
164
- ownerId: userId,
165
- remaining: 1,
166
- expiresAt: Date.now() + 24 * 60 * 60 * 1000,
167
- });
168
- // First validate: { valid: true, remaining: 0 }
169
- // Second validate: { valid: false, reason: "exhausted" }
149
+ const usage = await apiKeys.getUsage(ctx, { keyId, ownerId: orgId });
150
+ // { total: 42000, remaining: 58000 }
170
151
  ```
171
152
 
172
153
  ## Key Format
@@ -195,16 +176,22 @@ create() → ACTIVE ──→ DISABLED (reversible via enable())
195
176
  |--------|-----|-------------|
196
177
  | `create(ctx, options)` | mutation | Create a new API key |
197
178
  | `validate(ctx, { key })` | mutation | Validate and track usage |
198
- | `revoke(ctx, { keyId })` | mutation | Permanently revoke a key |
179
+ | `revoke(ctx, { keyId, ownerId })` | mutation | Permanently revoke a key |
199
180
  | `revokeByTag(ctx, { ownerId, tag })` | mutation | Bulk revoke by tag |
200
- | `rotate(ctx, { keyId, gracePeriodMs? })` | mutation | Rotate with grace period |
201
- | `list(ctx, { ownerId, env?, status? })` | query | List keys (no secrets exposed) |
202
- | `listByTag(ctx, { ownerId, tag })` | query | Filter by tag |
203
- | `update(ctx, { keyId, name?, scopes?, tags?, metadata? })` | mutation | Update metadata in-place |
204
- | `disable(ctx, { keyId })` | mutation | Temporarily disable |
205
- | `enable(ctx, { keyId })` | mutation | Re-enable disabled key |
206
- | `getUsage(ctx, { keyId, period? })` | query | Usage analytics |
207
- | `configure(ctx, { ... })` | mutation | Runtime config |
181
+ | `rotate(ctx, { keyId, ownerId, gracePeriodMs? })` | mutation | Rotate with grace period |
182
+ | `list(ctx, { ownerId, env?, status?, limit? })` | query | List keys (paginated, default 100) |
183
+ | `listByTag(ctx, { ownerId, tag, limit? })` | query | Filter by tag |
184
+ | `update(ctx, { keyId, ownerId, name?, ... })` | mutation | Update metadata in-place |
185
+ | `disable(ctx, { keyId, ownerId })` | mutation | Temporarily disable |
186
+ | `enable(ctx, { keyId, ownerId })` | mutation | Re-enable disabled key |
187
+ | `getUsage(ctx, { keyId, ownerId })` | query | Usage counter (O(1)) |
188
+ | `configure(ctx, { ... })` | mutation | Runtime config (admin-only) |
189
+
190
+ ## Security Model
191
+
192
+ This component protects against **accidental cross-tenant bugs in honest host apps**. The `ownerId` check prevents a bug from operating on another tenant's keys — it does NOT prevent a compromised host app from passing a forged `ownerId`.
193
+
194
+ Integrators must derive `ownerId` from their own auth layer (e.g., `ctx.auth.getUserIdentity()`) before passing it to the component.
208
195
 
209
196
  ## Testing
210
197
 
@@ -213,9 +200,11 @@ For testing with `convex-test`:
213
200
  ```ts
214
201
  import { convexTest } from "convex-test";
215
202
  import { register } from "@vllnt/convex-api-keys/test";
203
+ import shardedCounterTest from "@convex-dev/sharded-counter/test";
216
204
 
217
205
  const t = convexTest(schema, modules);
218
206
  register(t, "apiKeys");
207
+ shardedCounterTest.register(t, "apiKeys/shardedCounter");
219
208
  ```
220
209
 
221
210
  ## Contributing
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=_ignore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This is only here so convex-test can detect a _generated folder
3
+ //# sourceMappingURL=_ignore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ignore.js","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":";AAAA,kEAAkE"}
@@ -0,0 +1,69 @@
1
+ import type { GenericMutationCtx, GenericQueryCtx, GenericDataModel } from "convex/server";
2
+ import type { ComponentApi } from "../component/_generated/component.js";
3
+ import type { CreateKeyOptions, CreateKeyResult, ValidationResult, KeyMetadata, UsageStats, RotateResult, KeyType, KeyStatus } from "./types.js";
4
+ export type { CreateKeyOptions, CreateKeyResult, ValidationResult, KeyMetadata, UsageStats, RotateResult, KeyType, KeyStatus, };
5
+ export type RunMutationCtx = Pick<GenericMutationCtx<GenericDataModel>, "runMutation">;
6
+ export type RunQueryCtx = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
7
+ export interface ApiKeysConfig {
8
+ prefix?: string;
9
+ defaultType?: KeyType;
10
+ }
11
+ export declare class ApiKeys {
12
+ component: ComponentApi;
13
+ private prefix;
14
+ private defaultType;
15
+ constructor(component: ComponentApi, config?: ApiKeysConfig);
16
+ create(ctx: RunMutationCtx, options: CreateKeyOptions): Promise<CreateKeyResult>;
17
+ validate(ctx: RunMutationCtx, args: {
18
+ key: string;
19
+ }): Promise<ValidationResult>;
20
+ revoke(ctx: RunMutationCtx, args: {
21
+ keyId: string;
22
+ ownerId: string;
23
+ }): Promise<void>;
24
+ revokeByTag(ctx: RunMutationCtx, args: {
25
+ ownerId: string;
26
+ tag: string;
27
+ }): Promise<{
28
+ revokedCount: number;
29
+ }>;
30
+ rotate(ctx: RunMutationCtx, args: {
31
+ keyId: string;
32
+ ownerId: string;
33
+ gracePeriodMs?: number;
34
+ }): Promise<RotateResult>;
35
+ list(ctx: RunQueryCtx, args: {
36
+ ownerId: string;
37
+ env?: string;
38
+ status?: KeyStatus;
39
+ }): Promise<KeyMetadata[]>;
40
+ listByTag(ctx: RunQueryCtx, args: {
41
+ ownerId: string;
42
+ tag: string;
43
+ }): Promise<KeyMetadata[]>;
44
+ update(ctx: RunMutationCtx, args: {
45
+ keyId: string;
46
+ ownerId: string;
47
+ name?: string;
48
+ scopes?: string[];
49
+ tags?: string[];
50
+ metadata?: Record<string, unknown>;
51
+ }): Promise<void>;
52
+ disable(ctx: RunMutationCtx, args: {
53
+ keyId: string;
54
+ ownerId: string;
55
+ }): Promise<void>;
56
+ enable(ctx: RunMutationCtx, args: {
57
+ keyId: string;
58
+ ownerId: string;
59
+ }): Promise<void>;
60
+ getUsage(ctx: RunQueryCtx, args: {
61
+ keyId: string;
62
+ ownerId: string;
63
+ }): Promise<UsageStats>;
64
+ configure(ctx: RunMutationCtx, args: {
65
+ cleanupIntervalMs?: number;
66
+ defaultExpiryMs?: number;
67
+ }): Promise<void>;
68
+ }
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,KAA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O,CAAC,IAAI,CAAC;IAOpF,QAAQ,CACZ,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GACvC,OAAO,CAAC,UAAU,CAAC;IAOhB,SAAS,CACb,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7D,OAAO,CAAC,IAAI,CAAC;CAGjB"}
@@ -0,0 +1,82 @@
1
+ export class ApiKeys {
2
+ component;
3
+ prefix;
4
+ defaultType;
5
+ constructor(component, config) {
6
+ this.component = component;
7
+ this.prefix = config?.prefix ?? "vk";
8
+ this.defaultType = config?.defaultType ?? "secret";
9
+ }
10
+ async create(ctx, options) {
11
+ const result = await ctx.runMutation(this.component.mutations.create, {
12
+ name: options.name,
13
+ ownerId: options.ownerId,
14
+ type: options.type ?? this.defaultType,
15
+ scopes: options.scopes,
16
+ tags: options.tags,
17
+ env: options.env ?? "live",
18
+ metadata: options.metadata,
19
+ remaining: options.remaining,
20
+ expiresAt: options.expiresAt,
21
+ keyPrefix: this.prefix,
22
+ });
23
+ return { keyId: result.keyId, key: result.key };
24
+ }
25
+ async validate(ctx, args) {
26
+ return await ctx.runMutation(this.component.mutations.validate, { key: args.key });
27
+ }
28
+ async revoke(ctx, args) {
29
+ await ctx.runMutation(this.component.mutations.revoke, {
30
+ keyId: args.keyId,
31
+ ownerId: args.ownerId,
32
+ });
33
+ }
34
+ async revokeByTag(ctx, args) {
35
+ return await ctx.runMutation(this.component.mutations.revokeByTag, args);
36
+ }
37
+ async rotate(ctx, args) {
38
+ return await ctx.runMutation(this.component.mutations.rotate, {
39
+ keyId: args.keyId,
40
+ ownerId: args.ownerId,
41
+ gracePeriodMs: args.gracePeriodMs,
42
+ });
43
+ }
44
+ async list(ctx, args) {
45
+ return await ctx.runQuery(this.component.queries.list, args);
46
+ }
47
+ async listByTag(ctx, args) {
48
+ return await ctx.runQuery(this.component.queries.listByTag, args);
49
+ }
50
+ async update(ctx, args) {
51
+ await ctx.runMutation(this.component.mutations.update, {
52
+ keyId: args.keyId,
53
+ ownerId: args.ownerId,
54
+ name: args.name,
55
+ scopes: args.scopes,
56
+ tags: args.tags,
57
+ metadata: args.metadata,
58
+ });
59
+ }
60
+ async disable(ctx, args) {
61
+ await ctx.runMutation(this.component.mutations.disable, {
62
+ keyId: args.keyId,
63
+ ownerId: args.ownerId,
64
+ });
65
+ }
66
+ async enable(ctx, args) {
67
+ await ctx.runMutation(this.component.mutations.enable, {
68
+ keyId: args.keyId,
69
+ ownerId: args.ownerId,
70
+ });
71
+ }
72
+ async getUsage(ctx, args) {
73
+ return await ctx.runQuery(this.component.queries.getUsage, {
74
+ keyId: args.keyId,
75
+ ownerId: args.ownerId,
76
+ });
77
+ }
78
+ async configure(ctx, args) {
79
+ await ctx.runMutation(this.component.mutations.configure, args);
80
+ }
81
+ }
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgCA,MAAM,OAAO,OAAO;IACX,SAAS,CAAe;IACvB,MAAM,CAAS;IACf,WAAW,CAAU;IAE7B,YAAY,SAAuB,EAAE,MAAsB;QACzD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,QAAQ,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,MAAM,CACV,GAAmB,EACnB,OAAyB;QAEzB,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE;YACpE,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAA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E;YACrD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,GAAgB,EAChB,IAAwC;QAExC,OAAO,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE;YACzD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAe,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,SAAS,CACb,GAAmB,EACnB,IAA8D;QAE9D,MAAM,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ import type { KeyType, KeyStatus } from "../shared.js";
2
+ export type { KeyType, KeyStatus };
3
+ export interface CreateKeyOptions {
4
+ name: string;
5
+ ownerId: string;
6
+ type?: KeyType;
7
+ scopes?: string[];
8
+ tags?: string[];
9
+ env?: string;
10
+ metadata?: Record<string, unknown>;
11
+ remaining?: number;
12
+ expiresAt?: number;
13
+ }
14
+ export interface CreateKeyResult {
15
+ keyId: string;
16
+ key: string;
17
+ }
18
+ export interface ValidationSuccess {
19
+ valid: true;
20
+ keyId: string;
21
+ ownerId: string;
22
+ type: KeyType;
23
+ env: string;
24
+ scopes: string[];
25
+ tags: string[];
26
+ metadata?: Record<string, unknown>;
27
+ remaining?: number;
28
+ }
29
+ export interface ValidationFailure {
30
+ valid: false;
31
+ reason: string;
32
+ retryAfter?: number;
33
+ }
34
+ export type ValidationResult = ValidationSuccess | ValidationFailure;
35
+ export interface KeyMetadata {
36
+ keyId: string;
37
+ name: string;
38
+ lookupPrefix: string;
39
+ type: KeyType;
40
+ env: string;
41
+ scopes: string[];
42
+ tags: string[];
43
+ status: KeyStatus;
44
+ metadata?: Record<string, unknown>;
45
+ remaining?: number;
46
+ expiresAt?: number;
47
+ createdAt: number;
48
+ lastUsedAt?: number;
49
+ }
50
+ export interface UsageStats {
51
+ total: number;
52
+ remaining?: number;
53
+ }
54
+ export interface RotateResult {
55
+ newKeyId: string;
56
+ newKey: string;
57
+ oldKeyExpiresAt: number;
58
+ }
59
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEvD,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Generated `api` utility.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type * as mutations from "../mutations.js";
10
+ import type * as queries from "../queries.js";
11
+ import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
12
+ declare const fullApi: ApiFromModules<{
13
+ mutations: typeof mutations;
14
+ queries: typeof queries;
15
+ }>;
16
+ /**
17
+ * A utility for referencing Convex functions in your app's public API.
18
+ *
19
+ * Usage:
20
+ * ```js
21
+ * const myFunctionReference = api.myModule.myFunction;
22
+ * ```
23
+ */
24
+ export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
25
+ /**
26
+ * A utility for referencing Convex functions in your app's internal API.
27
+ *
28
+ * Usage:
29
+ * ```js
30
+ * const myFunctionReference = internal.myModule.myFunction;
31
+ * ```
32
+ */
33
+ export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
34
+ export declare const components: {
35
+ shardedCounter: import("@convex-dev/sharded-counter/_generated/component.js").ComponentApi<"shardedCounter">;
36
+ };
37
+ export {};
38
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;CACzB,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC;IAC1D,cAAc,EAAE,OAAO,qDAAqD,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC;CAC9G,CAAC"}
@@ -0,0 +1,31 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+ import { anyApi, componentsGeneric } from "convex/server";
11
+ const fullApi = anyApi;
12
+ /**
13
+ * A utility for referencing Convex functions in your app's public API.
14
+ *
15
+ * Usage:
16
+ * ```js
17
+ * const myFunctionReference = api.myModule.myFunction;
18
+ * ```
19
+ */
20
+ export const api = anyApi;
21
+ /**
22
+ * A utility for referencing Convex functions in your app's internal API.
23
+ *
24
+ * Usage:
25
+ * ```js
26
+ * const myFunctionReference = internal.myModule.myFunction;
27
+ * ```
28
+ */
29
+ export const internal = anyApi;
30
+ export const components = componentsGeneric();
31
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAUH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAGR,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAE1C,CAAC"}