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

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 (66) 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 +41 -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 +20 -18
  59. package/src/client/index.ts +23 -38
  60. package/src/client/types.ts +2 -12
  61. package/src/component/_generated/component.ts +8 -11
  62. package/src/component/convex.config.ts +0 -6
  63. package/src/component/mutations.ts +130 -154
  64. package/src/component/queries.ts +56 -91
  65. package/src/component/schema.ts +0 -11
  66. package/src/shared.ts +53 -25
@@ -0,0 +1,52 @@
1
+ declare const _default: import("convex/server").SchemaDefinition<{
2
+ apiKeys: import("convex/server").TableDefinition<import("convex/values").VObject<{
3
+ expiresAt?: number | undefined;
4
+ metadata?: any;
5
+ remaining?: number | undefined;
6
+ gracePeriodEnd?: number | undefined;
7
+ rotatedFromId?: import("convex/values").GenericId<"apiKeys"> | undefined;
8
+ lastUsedAt?: number | undefined;
9
+ revokedAt?: number | undefined;
10
+ type: "secret" | "publishable";
11
+ env: string;
12
+ lookupPrefix: string;
13
+ keyPrefix: string;
14
+ name: string;
15
+ ownerId: string;
16
+ scopes: string[];
17
+ tags: string[];
18
+ status: "active" | "disabled" | "revoked" | "rotating" | "expired" | "exhausted";
19
+ hash: string;
20
+ }, {
21
+ hash: import("convex/values").VString<string, "required">;
22
+ lookupPrefix: import("convex/values").VString<string, "required">;
23
+ keyPrefix: import("convex/values").VString<string, "required">;
24
+ type: import("convex/values").VUnion<"secret" | "publishable", [import("convex/values").VLiteral<"secret", "required">, import("convex/values").VLiteral<"publishable", "required">], "required", never>;
25
+ env: import("convex/values").VString<string, "required">;
26
+ ownerId: import("convex/values").VString<string, "required">;
27
+ name: import("convex/values").VString<string, "required">;
28
+ scopes: import("convex/values").VArray<string[], import("convex/values").VString<string, "required">, "required">;
29
+ tags: import("convex/values").VArray<string[], import("convex/values").VString<string, "required">, "required">;
30
+ status: import("convex/values").VUnion<"active" | "disabled" | "revoked" | "rotating" | "expired" | "exhausted", [import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"disabled", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"rotating", "required">, import("convex/values").VLiteral<"expired", "required">, import("convex/values").VLiteral<"exhausted", "required">], "required", never>;
31
+ metadata: import("convex/values").VAny<any, "optional", string>;
32
+ remaining: import("convex/values").VFloat64<number | undefined, "optional">;
33
+ expiresAt: import("convex/values").VFloat64<number | undefined, "optional">;
34
+ gracePeriodEnd: import("convex/values").VFloat64<number | undefined, "optional">;
35
+ rotatedFromId: import("convex/values").VId<import("convex/values").GenericId<"apiKeys"> | undefined, "optional">;
36
+ lastUsedAt: import("convex/values").VFloat64<number | undefined, "optional">;
37
+ revokedAt: import("convex/values").VFloat64<number | undefined, "optional">;
38
+ }, "required", "type" | "env" | "lookupPrefix" | "expiresAt" | "keyPrefix" | "metadata" | "name" | "ownerId" | "remaining" | "scopes" | "tags" | "status" | "hash" | "gracePeriodEnd" | "rotatedFromId" | "lastUsedAt" | "revokedAt" | `metadata.${string}`>, {
39
+ by_lookup_prefix: ["lookupPrefix", "_creationTime"];
40
+ by_owner_status: ["ownerId", "status", "_creationTime"];
41
+ by_owner_env: ["ownerId", "env", "status", "_creationTime"];
42
+ }, {}, {}>;
43
+ config: import("convex/server").TableDefinition<import("convex/values").VObject<{
44
+ cleanupIntervalMs?: number | undefined;
45
+ defaultExpiryMs?: number | undefined;
46
+ }, {
47
+ cleanupIntervalMs: import("convex/values").VFloat64<number | undefined, "optional">;
48
+ defaultExpiryMs: import("convex/values").VFloat64<number | undefined, "optional">;
49
+ }, "required", "cleanupIntervalMs" | "defaultExpiryMs">, {}, {}, {}>;
50
+ }, true>;
51
+ export default _default;
52
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBA4BG"}
@@ -0,0 +1,33 @@
1
+ import { defineSchema, defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { KEY_TYPE, KEY_STATUS } from "../shared.js";
4
+ import { jsonValue } from "./validators.js";
5
+ export default defineSchema({
6
+ apiKeys: defineTable({
7
+ hash: v.string(),
8
+ lookupPrefix: v.string(),
9
+ keyPrefix: v.string(),
10
+ type: KEY_TYPE,
11
+ env: v.string(),
12
+ ownerId: v.string(),
13
+ name: v.string(),
14
+ scopes: v.array(v.string()),
15
+ tags: v.array(v.string()),
16
+ status: KEY_STATUS,
17
+ metadata: v.optional(jsonValue),
18
+ remaining: v.optional(v.number()),
19
+ expiresAt: v.optional(v.number()),
20
+ gracePeriodEnd: v.optional(v.number()),
21
+ rotatedFromId: v.optional(v.id("apiKeys")),
22
+ lastUsedAt: v.optional(v.number()),
23
+ revokedAt: v.optional(v.number()),
24
+ })
25
+ .index("by_lookup_prefix", ["lookupPrefix"])
26
+ .index("by_owner_status", ["ownerId", "status"])
27
+ .index("by_owner_env", ["ownerId", "env", "status"]),
28
+ config: defineTable({
29
+ cleanupIntervalMs: v.optional(v.number()),
30
+ defaultExpiryMs: v.optional(v.number()),
31
+ }),
32
+ });
33
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema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,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KAClC,CAAC;SACC,KAAK,CAAC,kBAAkB,EAAE,CAAC,cAAc,CAAC,CAAC;SAC3C,KAAK,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC/C,KAAK,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAEtD,MAAM,EAAE,WAAW,CAAC;QAClB,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACzC,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KACxC,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Arbitrary JSON metadata attached to keys, events, or config. */
2
+ export declare const jsonValue: import("convex/values").VAny<any, "required", string>;
3
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,eAAO,MAAM,SAAS,uDAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { v } from "convex/values";
2
+ /** Arbitrary JSON metadata attached to keys, events, or config. */
3
+ export const jsonValue = v.any();
4
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,mEAAmE;AACnE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC"}
package/dist/log.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Minimal structured logger. Convex-safe (no process.env, no Node APIs).
3
+ * Replace with your own logger by wrapping this module.
4
+ */
5
+ export interface Logger {
6
+ info(message: string, data?: Record<string, unknown>): void;
7
+ warn(message: string, data?: Record<string, unknown>): void;
8
+ error(message: string, data?: Record<string, unknown>): void;
9
+ }
10
+ export declare function createLogger(scope: string): Logger;
11
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC9D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAalD"}
package/dist/log.js ADDED
@@ -0,0 +1,15 @@
1
+ export function createLogger(scope) {
2
+ const prefix = `[${scope}]`;
3
+ return {
4
+ info(message, data) {
5
+ console.log(prefix, message, data ?? "");
6
+ },
7
+ warn(message, data) {
8
+ console.warn(prefix, message, data ?? "");
9
+ },
10
+ error(message, data) {
11
+ console.error(prefix, message, data ?? "");
12
+ },
13
+ };
14
+ }
15
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,MAAM,GAAG,IAAI,KAAK,GAAG,CAAC;IAC5B,OAAO;QACL,IAAI,CAAC,OAAO,EAAE,IAAI;YAChB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,IAAI;YAChB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,IAAI;YACjB,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ export declare const KEY_TYPE: import("convex/values").VUnion<"secret" | "publishable", [import("convex/values").VLiteral<"secret", "required">, import("convex/values").VLiteral<"publishable", "required">], "required", never>;
2
+ export type KeyType = "secret" | "publishable";
3
+ export declare const KEY_STATUS: import("convex/values").VUnion<"active" | "disabled" | "revoked" | "rotating" | "expired" | "exhausted", [import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"disabled", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"rotating", "required">, import("convex/values").VLiteral<"expired", "required">, import("convex/values").VLiteral<"exhausted", "required">], "required", never>;
4
+ export type KeyStatus = "active" | "disabled" | "revoked" | "rotating" | "expired" | "exhausted";
5
+ export declare const TERMINAL_STATUSES: ReadonlySet<KeyStatus>;
6
+ export declare const TAG_PATTERN: RegExp;
7
+ export declare const KEY_PREFIX_PATTERN: RegExp;
8
+ export declare const ENV_PATTERN: RegExp;
9
+ export declare const MAX_METADATA_SIZE = 4096;
10
+ export declare const MAX_SCOPES = 50;
11
+ export declare const MAX_TAGS = 20;
12
+ export declare const MAX_STRING_LENGTH = 256;
13
+ export declare function validateKeyPrefix(prefix: string): void;
14
+ export declare function validateEnv(env: string): void;
15
+ export declare function validateSizeLimits(args: {
16
+ metadata?: unknown;
17
+ scopes?: string[];
18
+ tags?: string[];
19
+ name?: string;
20
+ }): void;
21
+ export declare function validateTag(tag: string): void;
22
+ export declare function validateTags(tags: string[]): void;
23
+ export declare const KEY_PREFIX_SEPARATOR = "_";
24
+ export declare function parseKeyString(key: string): {
25
+ valid: false;
26
+ reason: "malformed";
27
+ } | {
28
+ valid: true;
29
+ prefix: string;
30
+ type: string;
31
+ env: string;
32
+ lookupPrefix: string;
33
+ secret: string;
34
+ };
35
+ export declare function timingSafeEqual(a: string, b: string): boolean;
36
+ /** Compute SHA-256 hash of input, returned as lowercase hex string. */
37
+ export declare function sha256Hex(input: string): Promise<string>;
38
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,oMAAyD,CAAC;AAC/E,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE/C,eAAO,MAAM,UAAU,wdAOtB,CAAC;AACF,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,UAAU,GACV,SAAS,GACT,UAAU,GACV,SAAS,GACT,WAAW,CAAC;AAEhB,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,SAAS,CAInD,CAAC;AAEH,eAAO,MAAM,WAAW,QAA+B,CAAC;AACxD,eAAO,MAAM,kBAAkB,QAAmB,CAAC;AACnD,eAAO,MAAM,WAAW,QAAoB,CAAC;AAE7C,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,QAAQ,KAAK,CAAC;AAC3B,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAStD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAS7C;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CAgBP;AAGD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7C;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAIjD;AAED,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;IAC3C,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;CACrB,GAAG;IACF,KAAK,EAAE,IAAI,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAmBA;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAS7D;AAED,uEAAuE;AACvE,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAM9D"}
package/dist/shared.js ADDED
@@ -0,0 +1,98 @@
1
+ import { v } from "convex/values";
2
+ export const KEY_TYPE = v.union(v.literal("secret"), v.literal("publishable"));
3
+ export const KEY_STATUS = v.union(v.literal("active"), v.literal("disabled"), v.literal("revoked"), v.literal("rotating"), v.literal("expired"), v.literal("exhausted"));
4
+ export const TERMINAL_STATUSES = new Set([
5
+ "revoked",
6
+ "expired",
7
+ "exhausted",
8
+ ]);
9
+ export const TAG_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9-]*$/;
10
+ export const KEY_PREFIX_PATTERN = /^[a-zA-Z0-9]+$/;
11
+ export const ENV_PATTERN = /^[a-zA-Z0-9-]+$/;
12
+ export const MAX_METADATA_SIZE = 4096;
13
+ export const MAX_SCOPES = 50;
14
+ export const MAX_TAGS = 20;
15
+ export const MAX_STRING_LENGTH = 256;
16
+ export function validateKeyPrefix(prefix) {
17
+ if (!KEY_PREFIX_PATTERN.test(prefix)) {
18
+ throw new Error(`Invalid keyPrefix "${prefix}": must match ^[a-zA-Z0-9]+$ (alphanumeric only, no underscores)`);
19
+ }
20
+ if (prefix.length > MAX_STRING_LENGTH) {
21
+ throw new Error(`keyPrefix must be <= ${MAX_STRING_LENGTH} characters`);
22
+ }
23
+ }
24
+ export function validateEnv(env) {
25
+ if (!ENV_PATTERN.test(env)) {
26
+ throw new Error(`Invalid env "${env}": must match ^[a-zA-Z0-9-]+$ (no underscores — would break key parsing)`);
27
+ }
28
+ if (env.length > MAX_STRING_LENGTH) {
29
+ throw new Error(`env must be <= ${MAX_STRING_LENGTH} characters`);
30
+ }
31
+ }
32
+ export function validateSizeLimits(args) {
33
+ if (args.metadata !== undefined) {
34
+ const size = JSON.stringify(args.metadata).length;
35
+ if (size > MAX_METADATA_SIZE) {
36
+ throw new Error(`metadata must be <= ${MAX_METADATA_SIZE} bytes (got ${size})`);
37
+ }
38
+ }
39
+ if (args.scopes && args.scopes.length > MAX_SCOPES) {
40
+ throw new Error(`scopes must have <= ${MAX_SCOPES} entries (got ${args.scopes.length})`);
41
+ }
42
+ if (args.tags && args.tags.length > MAX_TAGS) {
43
+ throw new Error(`tags must have <= ${MAX_TAGS} entries (got ${args.tags.length})`);
44
+ }
45
+ if (args.name && args.name.length > MAX_STRING_LENGTH) {
46
+ throw new Error(`name must be <= ${MAX_STRING_LENGTH} characters`);
47
+ }
48
+ }
49
+ export function validateTag(tag) {
50
+ if (!TAG_PATTERN.test(tag)) {
51
+ throw new Error(`Invalid tag "${tag}": must be alphanumeric with hyphens, starting with alphanumeric`);
52
+ }
53
+ }
54
+ export function validateTags(tags) {
55
+ for (const tag of tags) {
56
+ validateTag(tag);
57
+ }
58
+ }
59
+ export const KEY_PREFIX_SEPARATOR = "_";
60
+ export function parseKeyString(key) {
61
+ const parts = key.split(KEY_PREFIX_SEPARATOR);
62
+ if (parts.length !== 5) {
63
+ return { valid: false, reason: "malformed" };
64
+ }
65
+ const [prefix, type, env, lookupPrefix, secret] = parts;
66
+ if (!prefix || !type || !env || !lookupPrefix || !secret) {
67
+ return { valid: false, reason: "malformed" };
68
+ }
69
+ if (type !== "secret" && type !== "pub") {
70
+ return { valid: false, reason: "malformed" };
71
+ }
72
+ if (lookupPrefix.length !== 8) {
73
+ return { valid: false, reason: "malformed" };
74
+ }
75
+ if (secret.length !== 64) {
76
+ return { valid: false, reason: "malformed" };
77
+ }
78
+ return { valid: true, prefix, type, env, lookupPrefix, secret };
79
+ }
80
+ export function timingSafeEqual(a, b) {
81
+ if (a.length !== b.length) {
82
+ return false;
83
+ }
84
+ let result = 0;
85
+ for (let i = 0; i < a.length; i++) {
86
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
87
+ }
88
+ return result === 0;
89
+ }
90
+ /** Compute SHA-256 hash of input, returned as lowercase hex string. */
91
+ export async function sha256Hex(input) {
92
+ const encoder = new TextEncoder();
93
+ const data = encoder.encode(input);
94
+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);
95
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
96
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
97
+ }
98
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AAG/E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAC/B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnB,CAAC,CAAC,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ClE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS;IAClD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAa;IAC3C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IACzD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@vllnt/convex-api-keys",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-canary.f11443e",
4
4
  "description": "Convex component for secure API key management — create, validate, revoke, rotate, rate-limit, track usage",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
+ "packageManager": "pnpm@9.15.4",
7
8
  "files": [
8
9
  "dist",
9
10
  "src"
@@ -32,6 +33,22 @@
32
33
  },
33
34
  "types": "./dist/client/index.d.ts",
34
35
  "module": "./dist/client/index.js",
36
+ "scripts": {
37
+ "build": "tsc --project ./tsconfig.build.json",
38
+ "build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
39
+ "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
40
+ "typecheck": "tsc --noEmit",
41
+ "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
42
+ "lint": "eslint .",
43
+ "test": "vitest run --passWithNoTests",
44
+ "test:watch": "vitest --typecheck --clearScreen false",
45
+ "test:coverage": "vitest run --coverage --coverage.reporter=text",
46
+ "generate:llms": "node -e \"const{execSync:e}=require('child_process');const fs=require('fs');const files=['README.md','src/shared.ts','src/client/types.ts','src/client/index.ts','src/component/schema.ts','src/component/validators.ts','src/component/mutations.ts','src/component/queries.ts','src/test.ts'];let out='# @vllnt/convex-api-keys — Full Source\\n\\nAuto-generated. Do not edit manually.\\n';for(const f of files){out+='\\n---\\n\\n## '+f+'\\n\\n';if(f.endsWith('.md')){out+=fs.readFileSync(f,'utf8')}else{out+='\\`\\`\\`ts\\n'+fs.readFileSync(f,'utf8')+'\\`\\`\\`'}out+='\\n'}fs.writeFileSync('llms-full.txt',out)\"",
47
+ "preversion": "pnpm install --frozen-lockfile && pnpm build:clean && pnpm test && pnpm typecheck && pnpm generate:llms",
48
+ "prepublishOnly": "npm whoami || npm login",
49
+ "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
50
+ "release": "npm version patch && npm publish && git push --follow-tags"
51
+ },
35
52
  "dependencies": {
36
53
  "@convex-dev/rate-limiter": "^0.3.0",
37
54
  "@convex-dev/sharded-counter": "^0.2.0",
@@ -75,20 +92,5 @@
75
92
  "rate-limiting",
76
93
  "multi-tenant",
77
94
  "convex-component"
78
- ],
79
- "scripts": {
80
- "build": "tsc --project ./tsconfig.build.json",
81
- "build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
82
- "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
83
- "typecheck": "tsc --noEmit",
84
- "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
85
- "lint": "eslint .",
86
- "test": "vitest run --passWithNoTests",
87
- "test:watch": "vitest --typecheck --clearScreen false",
88
- "test:coverage": "vitest run --coverage --coverage.reporter=text",
89
- "generate:llms": "node -e \"const{execSync:e}=require('child_process');const fs=require('fs');const files=['README.md','src/shared.ts','src/client/types.ts','src/client/index.ts','src/component/schema.ts','src/component/validators.ts','src/component/mutations.ts','src/component/queries.ts','src/test.ts'];let out='# @vllnt/convex-api-keys — Full Source\\n\\nAuto-generated. Do not edit manually.\\n';for(const f of files){out+='\\n---\\n\\n## '+f+'\\n\\n';if(f.endsWith('.md')){out+=fs.readFileSync(f,'utf8')}else{out+='\\`\\`\\`ts\\n'+fs.readFileSync(f,'utf8')+'\\`\\`\\`'}out+='\\n'}fs.writeFileSync('llms-full.txt',out)\"",
90
- "preversion": "pnpm install --frozen-lockfile && pnpm build:clean && pnpm test && pnpm typecheck && pnpm generate:llms",
91
- "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
92
- "release": "npm version patch && npm publish && git push --follow-tags"
93
- }
94
- }
95
+ ]
96
+ }
@@ -1,6 +1,5 @@
1
1
  import type { GenericMutationCtx, GenericQueryCtx, GenericDataModel } from "convex/server";
2
2
  import type { ComponentApi } from "../component/_generated/component.js";
3
- import { sha256Hex } from "../shared.js";
4
3
  import type {
5
4
  CreateKeyOptions,
6
5
  CreateKeyResult,
@@ -31,14 +30,6 @@ export interface ApiKeysConfig {
31
30
  defaultType?: KeyType;
32
31
  }
33
32
 
34
- function generateRandomHex(length: number): string {
35
- const bytes = new Uint8Array(length / 2);
36
- crypto.getRandomValues(bytes);
37
- return Array.from(bytes)
38
- .map((b) => b.toString(16).padStart(2, "0"))
39
- .join("");
40
- }
41
-
42
33
  export class ApiKeys {
43
34
  public component: ComponentApi;
44
35
  private prefix: string;
@@ -54,30 +45,17 @@ export class ApiKeys {
54
45
  ctx: RunMutationCtx,
55
46
  options: CreateKeyOptions,
56
47
  ): Promise<CreateKeyResult> {
57
- const type = options.type ?? this.defaultType;
58
- const typeShort = type === "publishable" ? "pub" : "secret";
59
- const env = options.env ?? "live";
60
-
61
- const lookupPrefix = generateRandomHex(8);
62
- const secretHex = generateRandomHex(64);
63
-
64
- const rawKey = [this.prefix, typeShort, env, lookupPrefix, secretHex].join("_");
65
- const hash = await sha256Hex(rawKey);
66
-
67
48
  const result = await ctx.runMutation(this.component.mutations.create, {
68
49
  name: options.name,
69
50
  ownerId: options.ownerId,
70
- type,
51
+ type: options.type ?? this.defaultType,
71
52
  scopes: options.scopes,
72
53
  tags: options.tags,
73
- env,
54
+ env: options.env ?? "live",
74
55
  metadata: options.metadata,
75
56
  remaining: options.remaining,
76
57
  expiresAt: options.expiresAt,
77
58
  keyPrefix: this.prefix,
78
- lookupPrefix,
79
- secretHex,
80
- hash,
81
59
  });
82
60
 
83
61
  return { keyId: result.keyId as string, key: result.key };
@@ -93,8 +71,11 @@ export class ApiKeys {
93
71
  ) as ValidationResult;
94
72
  }
95
73
 
96
- async revoke(ctx: RunMutationCtx, args: { keyId: string }): Promise<void> {
97
- await ctx.runMutation(this.component.mutations.revoke, { keyId: args.keyId });
74
+ async revoke(ctx: RunMutationCtx, args: { keyId: string; ownerId: string }): Promise<void> {
75
+ await ctx.runMutation(this.component.mutations.revoke, {
76
+ keyId: args.keyId,
77
+ ownerId: args.ownerId,
78
+ });
98
79
  }
99
80
 
100
81
  async revokeByTag(
@@ -106,16 +87,12 @@ export class ApiKeys {
106
87
 
107
88
  async rotate(
108
89
  ctx: RunMutationCtx,
109
- args: { keyId: string; gracePeriodMs?: number },
90
+ args: { keyId: string; ownerId: string; gracePeriodMs?: number },
110
91
  ): Promise<RotateResult> {
111
- const lookupPrefix = generateRandomHex(8);
112
- const secretHex = generateRandomHex(64);
113
-
114
92
  return await ctx.runMutation(this.component.mutations.rotate, {
115
93
  keyId: args.keyId,
94
+ ownerId: args.ownerId,
116
95
  gracePeriodMs: args.gracePeriodMs,
117
- lookupPrefix,
118
- secretHex,
119
96
  }) as RotateResult;
120
97
  }
121
98
 
@@ -143,6 +120,7 @@ export class ApiKeys {
143
120
  ctx: RunMutationCtx,
144
121
  args: {
145
122
  keyId: string;
123
+ ownerId: string;
146
124
  name?: string;
147
125
  scopes?: string[];
148
126
  tags?: string[];
@@ -151,6 +129,7 @@ export class ApiKeys {
151
129
  ): Promise<void> {
152
130
  await ctx.runMutation(this.component.mutations.update, {
153
131
  keyId: args.keyId,
132
+ ownerId: args.ownerId,
154
133
  name: args.name,
155
134
  scopes: args.scopes,
156
135
  tags: args.tags,
@@ -158,21 +137,27 @@ export class ApiKeys {
158
137
  });
159
138
  }
160
139
 
161
- async disable(ctx: RunMutationCtx, args: { keyId: string }): Promise<void> {
162
- await ctx.runMutation(this.component.mutations.disable, { keyId: args.keyId });
140
+ async disable(ctx: RunMutationCtx, args: { keyId: string; ownerId: string }): Promise<void> {
141
+ await ctx.runMutation(this.component.mutations.disable, {
142
+ keyId: args.keyId,
143
+ ownerId: args.ownerId,
144
+ });
163
145
  }
164
146
 
165
- async enable(ctx: RunMutationCtx, args: { keyId: string }): Promise<void> {
166
- await ctx.runMutation(this.component.mutations.enable, { keyId: args.keyId });
147
+ async enable(ctx: RunMutationCtx, args: { keyId: string; ownerId: string }): Promise<void> {
148
+ await ctx.runMutation(this.component.mutations.enable, {
149
+ keyId: args.keyId,
150
+ ownerId: args.ownerId,
151
+ });
167
152
  }
168
153
 
169
154
  async getUsage(
170
155
  ctx: RunQueryCtx,
171
- args: { keyId: string; period?: { start: number; end: number } },
156
+ args: { keyId: string; ownerId: string },
172
157
  ): Promise<UsageStats> {
173
158
  return await ctx.runQuery(this.component.queries.getUsage, {
174
159
  keyId: args.keyId,
175
- period: args.period,
160
+ ownerId: args.ownerId,
176
161
  }) as UsageStats;
177
162
  }
178
163
 
@@ -1,6 +1,6 @@
1
- import type { KeyType, KeyStatus, EventType } from "../shared.js";
1
+ import type { KeyType, KeyStatus } from "../shared.js";
2
2
 
3
- export type { KeyType, KeyStatus, EventType };
3
+ export type { KeyType, KeyStatus };
4
4
 
5
5
  export interface CreateKeyOptions {
6
6
  name: string;
@@ -58,7 +58,6 @@ export interface KeyMetadata {
58
58
  export interface UsageStats {
59
59
  total: number;
60
60
  remaining?: number;
61
- lastUsedAt?: number;
62
61
  }
63
62
 
64
63
  export interface RotateResult {
@@ -66,12 +65,3 @@ export interface RotateResult {
66
65
  newKey: string;
67
66
  oldKeyExpiresAt: number;
68
67
  }
69
-
70
- export interface KeyEvent {
71
- keyId: string;
72
- ownerId: string;
73
- eventType: EventType;
74
- reason?: string;
75
- metadata?: Record<string, unknown>;
76
- timestamp: number;
77
- }
@@ -37,15 +37,12 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
37
37
  {
38
38
  env?: string;
39
39
  expiresAt?: number;
40
- hash: string;
41
40
  keyPrefix?: string;
42
- lookupPrefix: string;
43
41
  metadata?: any;
44
42
  name: string;
45
43
  ownerId: string;
46
44
  remaining?: number;
47
45
  scopes?: Array<string>;
48
- secretHex: string;
49
46
  tags?: Array<string>;
50
47
  type?: "secret" | "publishable";
51
48
  },
@@ -55,21 +52,21 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
55
52
  disable: FunctionReference<
56
53
  "mutation",
57
54
  "internal",
58
- { keyId: string },
55
+ { keyId: string; ownerId: string },
59
56
  null,
60
57
  Name
61
58
  >;
62
59
  enable: FunctionReference<
63
60
  "mutation",
64
61
  "internal",
65
- { keyId: string },
62
+ { keyId: string; ownerId: string },
66
63
  null,
67
64
  Name
68
65
  >;
69
66
  revoke: FunctionReference<
70
67
  "mutation",
71
68
  "internal",
72
- { keyId: string },
69
+ { keyId: string; ownerId: string },
73
70
  null,
74
71
  Name
75
72
  >;
@@ -86,8 +83,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
86
83
  {
87
84
  gracePeriodMs?: number;
88
85
  keyId: string;
89
- lookupPrefix: string;
90
- secretHex: string;
86
+ ownerId: string;
91
87
  },
92
88
  { newKey: string; newKeyId: string; oldKeyExpiresAt: number },
93
89
  Name
@@ -99,6 +95,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
99
95
  keyId: string;
100
96
  metadata?: any;
101
97
  name?: string;
98
+ ownerId: string;
102
99
  scopes?: Array<string>;
103
100
  tags?: Array<string>;
104
101
  },
@@ -120,7 +117,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
120
117
  type: "secret" | "publishable";
121
118
  valid: true;
122
119
  }
123
- | { reason: string; retryAfter?: number; valid: false },
120
+ | { reason: string; valid: false },
124
121
  Name
125
122
  >;
126
123
  };
@@ -128,8 +125,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
128
125
  getUsage: FunctionReference<
129
126
  "query",
130
127
  "internal",
131
- { keyId: string; period?: { end: number; start: number } },
132
- { lastUsedAt?: number; remaining?: number; total: number },
128
+ { keyId: string; ownerId: string },
129
+ { remaining?: number; total: number },
133
130
  Name
134
131
  >;
135
132
  list: FunctionReference<
@@ -1,14 +1,8 @@
1
1
  import { defineComponent } from "convex/server";
2
- import rateLimiter from "@convex-dev/rate-limiter/convex.config.js";
3
2
  import shardedCounter from "@convex-dev/sharded-counter/convex.config.js";
4
- import aggregate from "@convex-dev/aggregate/convex.config.js";
5
- import crons from "@convex-dev/crons/convex.config.js";
6
3
 
7
4
  const component = defineComponent("apiKeys");
8
5
 
9
- component.use(rateLimiter);
10
6
  component.use(shardedCounter);
11
- component.use(aggregate, { name: "usageAggregate" });
12
- component.use(crons);
13
7
 
14
8
  export default component;