@gaganref/convex-api-keys 0.1.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.
Files changed (102) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +419 -0
  3. package/dist/client/_generated/_ignore.d.ts +1 -0
  4. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  5. package/dist/client/_generated/_ignore.js +3 -0
  6. package/dist/client/_generated/_ignore.js.map +1 -0
  7. package/dist/client/crypto.d.ts +4 -0
  8. package/dist/client/crypto.d.ts.map +1 -0
  9. package/dist/client/crypto.js +48 -0
  10. package/dist/client/crypto.js.map +1 -0
  11. package/dist/client/errors.d.ts +32 -0
  12. package/dist/client/errors.d.ts.map +1 -0
  13. package/dist/client/errors.js +43 -0
  14. package/dist/client/errors.js.map +1 -0
  15. package/dist/client/index.d.ts +7 -0
  16. package/dist/client/index.d.ts.map +1 -0
  17. package/dist/client/index.js +4 -0
  18. package/dist/client/index.js.map +1 -0
  19. package/dist/client/operations.d.ts +240 -0
  20. package/dist/client/operations.d.ts.map +1 -0
  21. package/dist/client/operations.js +700 -0
  22. package/dist/client/operations.js.map +1 -0
  23. package/dist/client/options.d.ts +79 -0
  24. package/dist/client/options.d.ts.map +1 -0
  25. package/dist/client/options.js +51 -0
  26. package/dist/client/options.js.map +1 -0
  27. package/dist/client/types.d.ts +269 -0
  28. package/dist/client/types.d.ts.map +1 -0
  29. package/dist/client/types.js +24 -0
  30. package/dist/client/types.js.map +1 -0
  31. package/dist/component/_generated/api.d.ts +40 -0
  32. package/dist/component/_generated/api.d.ts.map +1 -0
  33. package/dist/component/_generated/api.js +31 -0
  34. package/dist/component/_generated/api.js.map +1 -0
  35. package/dist/component/_generated/component.d.ts +253 -0
  36. package/dist/component/_generated/component.d.ts.map +1 -0
  37. package/dist/component/_generated/component.js +11 -0
  38. package/dist/component/_generated/component.js.map +1 -0
  39. package/dist/component/_generated/dataModel.d.ts +46 -0
  40. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  41. package/dist/component/_generated/dataModel.js +11 -0
  42. package/dist/component/_generated/dataModel.js.map +1 -0
  43. package/dist/component/_generated/server.d.ts +121 -0
  44. package/dist/component/_generated/server.d.ts.map +1 -0
  45. package/dist/component/_generated/server.js +78 -0
  46. package/dist/component/_generated/server.js.map +1 -0
  47. package/dist/component/cleanup.d.ts +29 -0
  48. package/dist/component/cleanup.d.ts.map +1 -0
  49. package/dist/component/cleanup.js +70 -0
  50. package/dist/component/cleanup.js.map +1 -0
  51. package/dist/component/convex.config.d.ts +3 -0
  52. package/dist/component/convex.config.d.ts.map +1 -0
  53. package/dist/component/convex.config.js +3 -0
  54. package/dist/component/convex.config.js.map +1 -0
  55. package/dist/component/crons.d.ts +3 -0
  56. package/dist/component/crons.d.ts.map +1 -0
  57. package/dist/component/crons.js +7 -0
  58. package/dist/component/crons.js.map +1 -0
  59. package/dist/component/lib.d.ts +323 -0
  60. package/dist/component/lib.d.ts.map +1 -0
  61. package/dist/component/lib.js +659 -0
  62. package/dist/component/lib.js.map +1 -0
  63. package/dist/component/schema.d.ts +82 -0
  64. package/dist/component/schema.d.ts.map +1 -0
  65. package/dist/component/schema.js +38 -0
  66. package/dist/component/schema.js.map +1 -0
  67. package/dist/component/sweep.d.ts +27 -0
  68. package/dist/component/sweep.d.ts.map +1 -0
  69. package/dist/component/sweep.js +94 -0
  70. package/dist/component/sweep.js.map +1 -0
  71. package/dist/shared.d.ts +11 -0
  72. package/dist/shared.d.ts.map +1 -0
  73. package/dist/shared.js +11 -0
  74. package/dist/shared.js.map +1 -0
  75. package/package.json +116 -0
  76. package/src/client/__tests__/contracts.test.ts +109 -0
  77. package/src/client/__tests__/errors.test.ts +133 -0
  78. package/src/client/__tests__/hooks.test.ts +154 -0
  79. package/src/client/__tests__/operations.test.ts +742 -0
  80. package/src/client/__tests__/setup.test.ts +31 -0
  81. package/src/client/_generated/_ignore.ts +1 -0
  82. package/src/client/crypto.ts +64 -0
  83. package/src/client/errors.ts +67 -0
  84. package/src/client/index.ts +44 -0
  85. package/src/client/operations.ts +881 -0
  86. package/src/client/options.ts +146 -0
  87. package/src/client/types.ts +313 -0
  88. package/src/component/__tests__/cleanup.test.ts +472 -0
  89. package/src/component/__tests__/lib.test.ts +676 -0
  90. package/src/component/__tests__/setup.test.ts +11 -0
  91. package/src/component/_generated/api.ts +56 -0
  92. package/src/component/_generated/component.ts +300 -0
  93. package/src/component/_generated/dataModel.ts +60 -0
  94. package/src/component/_generated/server.ts +156 -0
  95. package/src/component/cleanup.ts +85 -0
  96. package/src/component/convex.config.ts +3 -0
  97. package/src/component/crons.ts +20 -0
  98. package/src/component/lib.ts +843 -0
  99. package/src/component/schema.ts +49 -0
  100. package/src/component/sweep.ts +117 -0
  101. package/src/shared.ts +18 -0
  102. package/src/test.ts +18 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/client/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,cAAsB;IAClE,MAAM,KAAK,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;IAC1C,OAAO,GAAG,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;AAC9C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAa;IACjD,MAAM,IAAI,GAAG,MAAM,gBAAgB,EAAE,CAAC,MAAM,CAC1C,SAAS,EACT,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAC1B,CAAC;IACF,OAAO,eAAe,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACzB,C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ERATION_FAILED";
2
+ /**
3
+ * Structured runtime error thrown by client-side helpers.
4
+ *
5
+ * Chains the underlying error via `cause`, making it visible in
6
+ * stack traces and debuggers.
7
+ *
8
+ * ```ts
9
+ * try {
10
+ * await apiKeys.create(ctx, args);
11
+ * } catch (error) {
12
+ * if (isApiKeysClientError(error)) {
13
+ * console.error(error.code, error.message);
14
+ * if (error.cause) console.error("Caused by:", error.cause);
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export declare class ApiKeysClientError extends Error {
20
+ readonly name = "ApiKeysClientError";
21
+ readonly code: ApiKeysClientErrorCode;
22
+ readonly cause?: unknown;
23
+ constructor(code: ApiKeysClientErrorCode, message: string, cause?: unknown);
24
+ }
25
+ /**
26
+ * Type guard for structured API keys client errors.
27
+ */
28
+ export declare function isApiKeysClientError(error: unknown): error is ApiKeysClientError;
29
+ export declare function optionsError(message: string): ApiKeysClientError;
30
+ export declare function tokenRequiredError(): ApiKeysClientError;
31
+ export declare function runtimeUnavailableError(message: string): ApiKeysClientError;
32
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAE9B,iBAAiB,GAEjB,gBAAgB,GAEhB,qBAAqB,GACrB,kBAAkB,CAAC;AAEvB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,wBAAwB;IACrC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK3E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,kBAAkB,CAE7B;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,sBAK3C;AAED,wBAAgB,kBAAkB,uBAKjC;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,sBAKtD"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Structured runtime error thrown by client-side helpers.
3
+ *
4
+ * Chains the underlying error via `cause`, making it visible in
5
+ * stack traces and debuggers.
6
+ *
7
+ * ```ts
8
+ * try {
9
+ * await apiKeys.create(ctx, args);
10
+ * } catch (error) {
11
+ * if (isApiKeysClientError(error)) {
12
+ * console.error(error.code, error.message);
13
+ * if (error.cause) console.error("Caused by:", error.cause);
14
+ * }
15
+ * }
16
+ * ```
17
+ */
18
+ export class ApiKeysClientError extends Error {
19
+ name = "ApiKeysClientError";
20
+ code;
21
+ cause;
22
+ constructor(code, message, cause) {
23
+ super(message);
24
+ this.code = code;
25
+ this.cause = cause;
26
+ }
27
+ }
28
+ /**
29
+ * Type guard for structured API keys client errors.
30
+ */
31
+ export function isApiKeysClientError(error) {
32
+ return error instanceof ApiKeysClientError;
33
+ }
34
+ export function optionsError(message) {
35
+ return new ApiKeysClientError("INVALID_OPTIONS", `api-keys options: ${message}`);
36
+ }
37
+ export function tokenRequiredError() {
38
+ return new ApiKeysClientError("TOKEN_REQUIRED", "api-keys: token must not be empty");
39
+ }
40
+ export function runtimeUnavailableError(message) {
41
+ return new ApiKeysClientError("RUNTIME_UNAVAILABLE", `api-keys runtime: ${message}`);
42
+ }
43
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,IAAI,GAAG,oBAAoB,CAAC;IAC5B,IAAI,CAAyB;IAC7B,KAAK,CAAW;IAEzB,YAAY,IAA4B,EAAE,OAAe,EAAE,KAAe;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc;IAEd,OAAO,KAAK,YAAY,kBAAkB,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,kBAAkB,CAC3B,iBAAiB,EACjB,qBAAqB,OAAO,EAAE,CAC/B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,kBAAkB,CAC3B,gBAAgB,EAChB,mCAAmC,CACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,OAAO,IAAI,kBAAkB,CAC3B,qBAAqB,EACrB,qBAAqB,OAAO,EAAE,CAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { ApiKeys, ApiKeys as default } from "./operations.js";
2
+ export { ApiKeysClientError, isApiKeysClientError } from "./errors.js";
3
+ export type { ApiKeysClientErrorCode } from "./errors.js";
4
+ export type { ApiKeysOptions } from "./options.js";
5
+ export { onInvalidateHookPayloadValidator } from "./types.js";
6
+ export type { ApiKeyId, ApiKeyEventMetadata, ApiKeyMetadata, ApiKeyToken, ApiKeysTypeOptions, CleanupExpiredArgs, CleanupExpiredResult, CreateArgs, CreateResult, GetKeyArgs, GetKeyResult, InvalidateArgs, InvalidateAllArgs, InvalidateAllResult, InvalidateResult, ListEventsArgs, ListEventsResult, ListKeyEventsArgs, ListKeyEventsResult, ListKeysArgs, ListKeysResult, PaginationOptions, OnInvalidateHookPayload, RefreshArgs, RefreshResult, RunMutationCtx, RunQueryCtx, TouchArgs, TouchResult, UpdateArgs, UpdateResult, ValidateArgs, ValidateResult, } from "./types.js";
7
+ //# 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,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAE9D,YAAY,EACV,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,cAAc,EACd,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { ApiKeys, ApiKeys as default } from "./operations.js";
2
+ export { ApiKeysClientError, isApiKeysClientError } from "./errors.js";
3
+ export { onInvalidateHookPayloadValidator } from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKvE,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,240 @@
1
+ import type { ComponentApi } from "../component/_generated/component.js";
2
+ import { type ApiKeysOptions, type NormalizedApiKeysOptions } from "./options.js";
3
+ import type { FunctionReference, FunctionVisibility } from "convex/server";
4
+ import type { ApiKeysTypeOptions, CleanupExpiredArgs, CleanupExpiredResult, CreateArgs, CreateResult, GetKeyArgs, GetKeyResult, InvalidateArgs, InvalidateAllArgs, InvalidateAllResult, InvalidateResult, ListKeysArgs, ListEventsArgs, ListEventsResult, ListKeyEventsArgs, ListKeyEventsResult, ListKeysResult, OnInvalidateHookPayload, RefreshArgs, RefreshResult, RunMutationCtx, RunQueryCtx, TouchArgs, TouchResult, UpdateArgs, UpdateResult, ValidateArgs, ValidateResult } from "./types.js";
5
+ /**
6
+ * Client for managing API keys in a Convex application.
7
+ *
8
+ * Handles the full API key lifecycle: creation, validation, rotation,
9
+ * revocation, and cleanup. Tokens are hashed with SHA-256 before storage —
10
+ * plaintext tokens are only returned at creation and rotation time.
11
+ *
12
+ * Type-level configuration is passed via the generic parameter to narrow
13
+ * namespace literals, permission shapes, metadata types, and whether `name`
14
+ * is required on creation.
15
+ *
16
+ * ```ts
17
+ * import { ApiKeys } from "@gaganref/convex-api-keys";
18
+ * import { components } from "./_generated/api.js";
19
+ *
20
+ * export const apiKeys = new ApiKeys(components.apiKeys, {
21
+ * keyDefaults: { prefix: "myapp_", ttlMs: 90 * 24 * 60 * 60 * 1000 },
22
+ * logLevel: "debug",
23
+ * });
24
+ * ```
25
+ *
26
+ * @param component The API keys component. Like `components.apiKeys` from
27
+ * `./_generated/api.js`.
28
+ * @param options Configuration for key defaults, permissions, and logging.
29
+ * See {@link ApiKeysOptions} for details.
30
+ */
31
+ export declare class ApiKeys<TOptions extends ApiKeysTypeOptions = Record<never, never>> {
32
+ readonly component: ComponentApi;
33
+ readonly options: NormalizedApiKeysOptions;
34
+ private _onInvalidate;
35
+ constructor(component: ComponentApi, options?: ApiKeysOptions<TOptions>);
36
+ /**
37
+ * Attach lifecycle hooks.
38
+ *
39
+ * Call this after construction to avoid circular module type inference
40
+ * that occurs when `internal.*` references appear in the constructor call.
41
+ *
42
+ * @example
43
+ * export const apiKeys = new ApiKeys<TOptions>(components.apiKeys, { ... })
44
+ * .withHooks({ onInvalidate: internal.hooks.onInvalidate });
45
+ */
46
+ withHooks(hooks: {
47
+ onInvalidate?: FunctionReference<"mutation", FunctionVisibility, {
48
+ event: OnInvalidateHookPayload;
49
+ }, null>;
50
+ }): this;
51
+ /**
52
+ * Create a new API key.
53
+ *
54
+ * Generates a cryptographically random token, hashes it with SHA-256, and
55
+ * stores only the hash. The plaintext token is returned exactly once — it
56
+ * cannot be retrieved later.
57
+ *
58
+ * Per-key overrides for `prefix`, `ttlMs`, and `idleTimeoutMs` fall back to
59
+ * the defaults configured in {@link ApiKeysOptions.keyDefaults}. Permissions
60
+ * fall back to {@link ApiKeysOptions.permissionDefaults} when omitted.
61
+ *
62
+ * @param ctx Any context that can run a mutation.
63
+ * @param args Key configuration including namespace, name, permissions,
64
+ * metadata, and optional lifecycle overrides. See {@link CreateArgs}.
65
+ * @returns The plaintext token, key ID, and computed expiry timestamps.
66
+ * **Store or display the token immediately** — it will not be available again.
67
+ * @throws {ApiKeysClientError} With code `OPERATION_FAILED` if the mutation fails.
68
+ */
69
+ create(ctx: RunMutationCtx, args: CreateArgs<TOptions>): Promise<CreateResult>;
70
+ /**
71
+ * Validate a plaintext API key token.
72
+ *
73
+ * Hashes the token with SHA-256 and looks up the matching key. Returns the
74
+ * key's metadata and permissions on success (`ok: true`), or a failure
75
+ * reason on failure (`ok: false`).
76
+ *
77
+ * This method does **not** update `lastUsedAt` — call {@link touch} separately
78
+ * if you need idle-timeout tracking.
79
+ *
80
+ * @param ctx Any context that can run a query.
81
+ * @param args The plaintext token to validate. See {@link ValidateArgs}.
82
+ * @returns `{ ok: true, keyId, namespace, name, permissions, metadata }` on
83
+ * success, or `{ ok: false, reason }` with one of `"not_found"`,
84
+ * `"revoked"`, `"expired"`, or `"idle_timeout"`.
85
+ * @throws {ApiKeysClientError} With code `TOKEN_REQUIRED` if the token is empty.
86
+ * @throws {ApiKeysClientError} With code `OPERATION_FAILED` if the query fails.
87
+ */
88
+ validate(ctx: RunQueryCtx, args: ValidateArgs): Promise<ValidateResult<TOptions>>;
89
+ /**
90
+ * Get a single API key by ID.
91
+ *
92
+ * Returns the key's full metadata including its computed
93
+ * `effectiveStatus` (which accounts for expiry and idle timeout).
94
+ *
95
+ * @param ctx Any context that can run a query.
96
+ * @param args The key ID to look up. See {@link GetKeyArgs}.
97
+ * @returns `{ ok: true, ...keyData }` or `{ ok: false, reason: "not_found" }`.
98
+ */
99
+ getKey(ctx: RunQueryCtx, args: GetKeyArgs): Promise<GetKeyResult>;
100
+ /**
101
+ * List API keys with cursor-based pagination.
102
+ *
103
+ * Results include the computed `effectiveStatus` for each key. Supports
104
+ * optional filtering by namespace and/or stored status (`"active"` or
105
+ * `"revoked"`), and ordering by creation time.
106
+ *
107
+ * @param ctx Any context that can run a query.
108
+ * @param args Pagination options and optional filters. See {@link ListKeysArgs}.
109
+ * @returns `{ page, isDone, continueCursor }`.
110
+ */
111
+ listKeys(ctx: RunQueryCtx, args: ListKeysArgs<TOptions>): Promise<ListKeysResult>;
112
+ /**
113
+ * List audit events across all keys with cursor-based pagination.
114
+ *
115
+ * Events are immutable records of key lifecycle changes (`"created"`,
116
+ * `"revoked"`, `"rotated"`). Optionally filter by namespace.
117
+ *
118
+ * @param ctx Any context that can run a query.
119
+ * @param args Pagination options and optional namespace filter.
120
+ * See {@link ListEventsArgs}.
121
+ * @returns `{ page, isDone, continueCursor }`.
122
+ */
123
+ listEvents(ctx: RunQueryCtx, args: ListEventsArgs<TOptions>): Promise<ListEventsResult>;
124
+ /**
125
+ * List audit events for a specific key with cursor-based pagination.
126
+ *
127
+ * @param ctx Any context that can run a query.
128
+ * @param args The key ID, pagination options, and optional order.
129
+ * See {@link ListKeyEventsArgs}.
130
+ * @returns `{ page, isDone, continueCursor }`.
131
+ */
132
+ listKeyEvents(ctx: RunQueryCtx, args: ListKeyEventsArgs): Promise<ListKeyEventsResult>;
133
+ /**
134
+ * Touch an API key, updating `lastUsedAt` and resetting the idle timeout.
135
+ *
136
+ * If the key has a `maxIdleMs` configured, the idle expiry is derived from
137
+ * `lastUsedAt + maxIdleMs`. Call this during request handling to keep
138
+ * idle-timeout keys alive.
139
+ *
140
+ * @param ctx Any context that can run a mutation.
141
+ * @param args The key ID to touch. See {@link TouchArgs}.
142
+ * @returns `{ ok: true, keyId, touchedAt }` on success,
143
+ * or `{ ok: false, reason }` if the key is not found or inactive.
144
+ */
145
+ touch(ctx: RunMutationCtx, args: TouchArgs): Promise<TouchResult>;
146
+ /**
147
+ * Invalidate (revoke) a single API key.
148
+ *
149
+ * Sets the key's status to `"revoked"` and records a revocation audit event.
150
+ * If an `onInvalidate` hook is configured, it fires after the revocation
151
+ * succeeds (hook failures are swallowed and logged).
152
+ *
153
+ * @param ctx Any context that can run a mutation.
154
+ * @param args The key ID, optional reason, and optional event metadata.
155
+ * See {@link InvalidateArgs}.
156
+ * @returns `{ ok: true, keyId, revokedAt }` on success,
157
+ * or `{ ok: false, reason }` if the key is not found or already revoked.
158
+ */
159
+ invalidate(ctx: RunMutationCtx, args: InvalidateArgs): Promise<InvalidateResult>;
160
+ /**
161
+ * Bulk-invalidate API keys matching the given filters.
162
+ *
163
+ * Iterates through all matching active keys in paginated batches,
164
+ * revoking each one and recording audit events. Supports filtering by
165
+ * namespace and creation-time range (`before` / `after`).
166
+ *
167
+ * The `onInvalidate` hook fires once after all pages are processed with
168
+ * aggregated stats.
169
+ *
170
+ * @param ctx Any context that can run a mutation.
171
+ * @param args Filters, optional reason/metadata, and page size.
172
+ * See {@link InvalidateAllArgs}.
173
+ * @returns `{ processed, revoked, pages }` — total keys examined,
174
+ * total keys revoked, and number of pages processed.
175
+ */
176
+ invalidateAll(ctx: RunMutationCtx, args: InvalidateAllArgs<TOptions>): Promise<InvalidateAllResult>;
177
+ /**
178
+ * Rotate an API key: revoke the current key and issue a replacement.
179
+ *
180
+ * The new key inherits the old key's namespace, name, permissions, metadata,
181
+ * expiry configuration, and idle timeout. A `"rotated"` event is recorded on
182
+ * the old key and a `"created"` event on the new key.
183
+ *
184
+ * The `onInvalidate` hook fires with `trigger: "refresh"` after success.
185
+ *
186
+ * @param ctx Any context that can run a mutation.
187
+ * @param args The key ID to rotate, optional reason, and optional event
188
+ * metadata. See {@link RefreshArgs}.
189
+ * @returns On success: `{ ok: true, keyId, token, ... }` with the new
190
+ * plaintext token. On failure: `{ ok: false, reason }` if the key is
191
+ * not found or inactive.
192
+ */
193
+ refresh(ctx: RunMutationCtx, args: RefreshArgs): Promise<RefreshResult>;
194
+ /**
195
+ * Update a key's mutable properties: name, metadata, and/or expiry.
196
+ *
197
+ * Pass `expiresAt: null` to remove the absolute expiry entirely.
198
+ * Omitted fields are left unchanged.
199
+ *
200
+ * @param ctx Any context that can run a mutation.
201
+ * @param args The key ID and fields to update. See {@link UpdateArgs}.
202
+ * @returns `{ ok: true, keyId }` on success,
203
+ * or `{ ok: false, reason }` where reason is `"not_found"` or `"already_revoked"`.
204
+ */
205
+ update(ctx: RunMutationCtx, args: UpdateArgs): Promise<UpdateResult>;
206
+ /**
207
+ * Hard-delete revoked keys older than the retention period.
208
+ *
209
+ * Expired and idle keys are automatically swept to revoked status by the
210
+ * component's internal cron — this method only deletes revoked keys past
211
+ * the retention window. Processes up to 100 keys per run and automatically
212
+ * reschedules itself when a full batch is found.
213
+ *
214
+ * Call this from your app's cron job to control the schedule:
215
+ *
216
+ * ```ts
217
+ * // convex/crons.ts
218
+ * crons.interval("cleanup api keys", { hours: 24 }, internal.tasks.cleanupApiKeys);
219
+ *
220
+ * // convex/tasks.ts
221
+ * export const cleanupApiKeys = internalMutation({
222
+ * handler: (ctx) => apiKeys.cleanupExpired(ctx),
223
+ * });
224
+ * ```
225
+ *
226
+ * @param ctx Any context that can run a mutation.
227
+ * @param args Optional retention period override. Defaults to 30 days.
228
+ * See {@link CleanupExpiredArgs}.
229
+ * @returns `{ deleted, isDone }` — keys hard-deleted and whether all
230
+ * work was completed in this run.
231
+ */
232
+ cleanupExpired(ctx: RunMutationCtx, args?: CleanupExpiredArgs): Promise<CleanupExpiredResult>;
233
+ /**
234
+ * Executes the optional invalidation hook and reports hook failures without
235
+ * affecting the main API-key operation.
236
+ */
237
+ private runOnInvalidateHook;
238
+ private toThrownError;
239
+ }
240
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/client/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAMtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EACd,iBAAiB,EAEjB,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,cAAc,EACd,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EACf,MAAM,YAAY,CAAC;AAoHpB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,OAAO,CAClB,QAAQ,SAAS,kBAAkB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;IAE1D,SAAgB,SAAS,EAAE,YAAY,CAAC;IACxC,SAAgB,OAAO,EAAE,wBAAwB,CAAC;IAClD,OAAO,CAAC,aAAa,CAOP;gBAEF,SAAS,EAAE,Y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