@vllnt/convex-tokens 0.1.0-canary.4bc4600

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +127 -0
  3. package/dist/client/index.d.ts +116 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +92 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +59 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +3 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +40 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +71 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +121 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +78 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +7 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/crons.d.ts +10 -0
  32. package/dist/component/crons.d.ts.map +1 -0
  33. package/dist/component/crons.js +13 -0
  34. package/dist/component/crons.js.map +1 -0
  35. package/dist/component/mutations.d.ts +49 -0
  36. package/dist/component/mutations.d.ts.map +1 -0
  37. package/dist/component/mutations.js +141 -0
  38. package/dist/component/mutations.js.map +1 -0
  39. package/dist/component/queries.d.ts +51 -0
  40. package/dist/component/queries.d.ts.map +1 -0
  41. package/dist/component/queries.js +84 -0
  42. package/dist/component/queries.js.map +1 -0
  43. package/dist/component/schema.d.ts +30 -0
  44. package/dist/component/schema.d.ts.map +1 -0
  45. package/dist/component/schema.js +23 -0
  46. package/dist/component/schema.js.map +1 -0
  47. package/dist/component/validators.d.ts +45 -0
  48. package/dist/component/validators.d.ts.map +1 -0
  49. package/dist/component/validators.js +24 -0
  50. package/dist/component/validators.js.map +1 -0
  51. package/dist/react/index.d.ts +35 -0
  52. package/dist/react/index.d.ts.map +1 -0
  53. package/dist/react/index.js +30 -0
  54. package/dist/react/index.js.map +1 -0
  55. package/dist/shared.d.ts +60 -0
  56. package/dist/shared.d.ts.map +1 -0
  57. package/dist/shared.js +69 -0
  58. package/dist/shared.js.map +1 -0
  59. package/package.json +112 -0
  60. package/src/client/index.ts +220 -0
  61. package/src/client/types.ts +60 -0
  62. package/src/component/_generated/api.ts +56 -0
  63. package/src/component/_generated/component.ts +93 -0
  64. package/src/component/_generated/dataModel.ts +60 -0
  65. package/src/component/_generated/server.ts +156 -0
  66. package/src/component/convex.config.ts +9 -0
  67. package/src/component/crons.ts +19 -0
  68. package/src/component/mutations.ts +158 -0
  69. package/src/component/queries.ts +90 -0
  70. package/src/component/schema.ts +23 -0
  71. package/src/component/validators.ts +28 -0
  72. package/src/react/index.test.tsx +86 -0
  73. package/src/react/index.tsx +41 -0
  74. package/src/shared.ts +98 -0
  75. package/src/test.ts +12 -0
  76. package/src/unit.test.ts +48 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataModel.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,6BAA6B,EAC7B,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,UAAU,IAAI,cAAc,CAC5D,SAAS,EACT,SAAS,CACV,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,EAAE,CAAC,SAAS,SAAS,UAAU,GAAG,gBAAgB,IAC5D,SAAS,CAAC,SAAS,CAAC,CAAC;AAEvB;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,6BAA6B,CAAC,OAAO,MAAM,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=dataModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataModel.js","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Generated utilities for implementing server-side Convex query and mutation functions.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type { ActionBuilder, HttpActionBuilder, MutationBuilder, QueryBuilder, GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
10
+ import type { DataModel } from "./dataModel.js";
11
+ /**
12
+ * Define a query in this Convex app's public API.
13
+ *
14
+ * This function will be allowed to read your Convex database and will be accessible from the client.
15
+ *
16
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
17
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
18
+ */
19
+ export declare const query: QueryBuilder<DataModel, "public">;
20
+ /**
21
+ * Define a query that is only accessible from other Convex functions (but not from the client).
22
+ *
23
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
24
+ *
25
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
26
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
27
+ */
28
+ export declare const internalQuery: QueryBuilder<DataModel, "internal">;
29
+ /**
30
+ * Define a mutation in this Convex app's public API.
31
+ *
32
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
33
+ *
34
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
35
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
36
+ */
37
+ export declare const mutation: MutationBuilder<DataModel, "public">;
38
+ /**
39
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
40
+ *
41
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
42
+ *
43
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
44
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
45
+ */
46
+ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
47
+ /**
48
+ * Define an action in this Convex app's public API.
49
+ *
50
+ * An action is a function which can execute any JavaScript code, including non-deterministic
51
+ * code and code with side-effects, like calling third-party services.
52
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
53
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
54
+ *
55
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
56
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
57
+ */
58
+ export declare const action: ActionBuilder<DataModel, "public">;
59
+ /**
60
+ * Define an action that is only accessible from other Convex functions (but not from the client).
61
+ *
62
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
63
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
64
+ */
65
+ export declare const internalAction: ActionBuilder<DataModel, "internal">;
66
+ /**
67
+ * Define an HTTP action.
68
+ *
69
+ * The wrapped function will be used to respond to HTTP requests received
70
+ * by a Convex deployment if the requests matches the path and method where
71
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
72
+ *
73
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
74
+ * and a Fetch API `Request` object as its second.
75
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
76
+ */
77
+ export declare const httpAction: HttpActionBuilder;
78
+ /**
79
+ * A set of services for use within Convex query functions.
80
+ *
81
+ * The query context is passed as the first argument to any Convex query
82
+ * function run on the server.
83
+ *
84
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
85
+ */
86
+ export type QueryCtx = GenericQueryCtx<DataModel>;
87
+ /**
88
+ * A set of services for use within Convex mutation functions.
89
+ *
90
+ * The mutation context is passed as the first argument to any Convex mutation
91
+ * function run on the server.
92
+ *
93
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
94
+ */
95
+ export type MutationCtx = GenericMutationCtx<DataModel>;
96
+ /**
97
+ * A set of services for use within Convex action functions.
98
+ *
99
+ * The action context is passed as the first argument to any Convex action
100
+ * function run on the server.
101
+ */
102
+ export type ActionCtx = GenericActionCtx<DataModel>;
103
+ /**
104
+ * An interface to read from the database within Convex query functions.
105
+ *
106
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
107
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
108
+ * building a query.
109
+ */
110
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
111
+ /**
112
+ * An interface to read from and write to the database within Convex mutation
113
+ * functions.
114
+ *
115
+ * Convex guarantees that all writes within a single mutation are
116
+ * executed atomically, so you never have to worry about partial writes leaving
117
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
118
+ * for the guarantees Convex provides your functions.
119
+ */
120
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
121
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAUvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAgB,CAAC;AAErE;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,SAAS,EAAE,UAAU,CACxC,CAAC;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAmB,CAAC;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,SAAS,EAAE,UAAU,CAC3C,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,MAAM,EAAE,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAiB,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,SAAS,EAAE,UAAU,CACzC,CAAC;AAExB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,iBAAqC,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAExD;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,78 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+ import { actionGeneric, httpActionGeneric, queryGeneric, mutationGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, } from "convex/server";
11
+ /**
12
+ * Define a query in this Convex app's public API.
13
+ *
14
+ * This function will be allowed to read your Convex database and will be accessible from the client.
15
+ *
16
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
17
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
18
+ */
19
+ export const query = queryGeneric;
20
+ /**
21
+ * Define a query that is only accessible from other Convex functions (but not from the client).
22
+ *
23
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
24
+ *
25
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
26
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
27
+ */
28
+ export const internalQuery = internalQueryGeneric;
29
+ /**
30
+ * Define a mutation in this Convex app's public API.
31
+ *
32
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
33
+ *
34
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
35
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
36
+ */
37
+ export const mutation = mutationGeneric;
38
+ /**
39
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
40
+ *
41
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
42
+ *
43
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
44
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
45
+ */
46
+ export const internalMutation = internalMutationGeneric;
47
+ /**
48
+ * Define an action in this Convex app's public API.
49
+ *
50
+ * An action is a function which can execute any JavaScript code, including non-deterministic
51
+ * code and code with side-effects, like calling third-party services.
52
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
53
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
54
+ *
55
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
56
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
57
+ */
58
+ export const action = actionGeneric;
59
+ /**
60
+ * Define an action that is only accessible from other Convex functions (but not from the client).
61
+ *
62
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
63
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
64
+ */
65
+ export const internalAction = internalActionGeneric;
66
+ /**
67
+ * Define an HTTP action.
68
+ *
69
+ * The wrapped function will be used to respond to HTTP requests received
70
+ * by a Convex deployment if the requests matches the path and method where
71
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
72
+ *
73
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
74
+ * and a Fetch API `Request` object as its second.
75
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
76
+ */
77
+ export const httpAction = httpActionGeneric;
78
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAGvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAsC,YAAY,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,oBAAoB,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAyC,eAAe,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,uBAAuB,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAuC,aAAa,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,qBAAqB,CAAC;AAExB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAsB,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const component: import("convex/server").ComponentDefinition<any, {}>;
2
+ export default component;
3
+ //# sourceMappingURL=convex.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,SAAS,sDAA4B,CAAC;AAM5C,eAAe,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { defineComponent } from "convex/server";
2
+ const component = defineComponent("tokens");
3
+ // Nest official child components here, e.g.:
4
+ // import sharded from "@convex-dev/sharded-counter/convex.config";
5
+ // component.use(sharded);
6
+ export default component;
7
+ //# sourceMappingURL=convex.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convex.config.js","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAE5C,6CAA6C;AAC7C,mEAAmE;AACnE,0BAA0B;AAE1B,eAAe,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Internal cron that sweeps expired and stale-revoked tokens daily. The cadence
3
+ * is fixed at the component layer (Convex crons are static); a mount that needs
4
+ * a different sweep frequency can also call `prune` from its own schedule. The
5
+ * sweep is bounded + self-rescheduling, so a daily tick safely drains any
6
+ * backlog. See `pruneExpired` in `mutations.ts`.
7
+ */
8
+ declare const crons: import("convex/server").Crons;
9
+ export default crons;
10
+ //# sourceMappingURL=crons.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crons.d.ts","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,QAAA,MAAM,KAAK,+BAAa,CAAC;AAQzB,eAAe,KAAK,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { cronJobs } from "convex/server";
2
+ import { internal } from "./_generated/api";
3
+ /**
4
+ * Internal cron that sweeps expired and stale-revoked tokens daily. The cadence
5
+ * is fixed at the component layer (Convex crons are static); a mount that needs
6
+ * a different sweep frequency can also call `prune` from its own schedule. The
7
+ * sweep is bounded + self-rescheduling, so a daily tick safely drains any
8
+ * backlog. See `pruneExpired` in `mutations.ts`.
9
+ */
10
+ const crons = cronJobs();
11
+ crons.interval("tokens: prune expired and stale-revoked", { hours: 24 }, internal.mutations.pruneExpired);
12
+ export default crons;
13
+ //# sourceMappingURL=crons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;AAEzB,KAAK,CAAC,QAAQ,CACZ,yCAAyC,EACzC,EAAE,KAAK,EAAE,EAAE,EAAE,EACb,QAAQ,CAAC,SAAS,CAAC,YAAY,CAChC,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Mint a token. The component computes `expiresAt` itself from a requested
3
+ * `ttlMs` — it never trusts a client-supplied timestamp. `ttlMs` is clamped into
4
+ * `[MIN_TTL_MS, maxTtlMs]`; a non-finite `ttlMs` (NaN / Infinity) falls back to
5
+ * `defaultTtlMs`. This guarantees a minted token always outlives a `Date.now()`
6
+ * validate (the floor is `MIN_TTL_MS`).
7
+ */
8
+ export declare const mint: import("convex/server").RegisteredMutation<"public", {
9
+ resourceRef?: string | undefined;
10
+ tokenHash: string;
11
+ scope: string;
12
+ ttlMs: number;
13
+ defaultTtlMs: number;
14
+ maxTtlMs: number;
15
+ }, Promise<import("convex/values").GenericId<"tokens">>>;
16
+ /**
17
+ * Revoke the token with `tokenHash` in `scope`.
18
+ *
19
+ * Returns `true` **only if this call transitioned the token from active to
20
+ * revoked** (i.e. it existed in the given scope and was not already revoked).
21
+ * Returns `false` for an unknown token, a wrong-scope token, or a token that
22
+ * is already in the revoked state — the caller can distinguish "nothing to
23
+ * revoke" from "successfully revoked".
24
+ *
25
+ * @remarks This is the "true = transition" contract, not "true = now revoked".
26
+ * Calling revoke twice on the same token returns `true` the first time and
27
+ * `false` the second time. Use `getMetadata` to check the current state
28
+ * without side effects.
29
+ */
30
+ export declare const revoke: import("convex/server").RegisteredMutation<"public", {
31
+ tokenHash: string;
32
+ scope: string;
33
+ }, Promise<boolean>>;
34
+ /**
35
+ * Delete up to `PRUNE_BATCH` tokens that expired before `before` (bounded read
36
+ * via `by_expires`). Returns the count deleted in this batch. Idempotent and
37
+ * bounded — safe to schedule; callers loop until it returns < `PRUNE_BATCH`.
38
+ */
39
+ export declare const prune: import("convex/server").RegisteredMutation<"public", {
40
+ before: number;
41
+ }, Promise<number>>;
42
+ /**
43
+ * Cron-driven sweep. Deletes, in bounded batches, (1) expired tokens and (2)
44
+ * revoked tokens older than `revokedRetentionMs` (so an early-revoked token does
45
+ * not linger for its full TTL). Self-reschedules while a batch fills, so an
46
+ * unbounded backlog is drained without exceeding read limits.
47
+ */
48
+ export declare const pruneExpired: import("convex/server").RegisteredMutation<"internal", {}, Promise<null>>;
49
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAwBA;;;;;;GAMG;AACH,eAAO,MAAM,IAAI;;;;;;;wDAiCf,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM;;;oBAcjB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,KAAK;;mBAahB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,YAAY,2EAmCvB,CAAC"}
@@ -0,0 +1,141 @@
1
+ import { v } from "convex/values";
2
+ import { ConvexError } from "convex/values";
3
+ import { internalMutation, mutation } from "./_generated/server";
4
+ import { internal } from "./_generated/api";
5
+ import { clampTtl, DEFAULT_REVOKED_RETENTION_MS, MIN_TTL_MS, PRUNE_BATCH, } from "../shared";
6
+ /**
7
+ * Minimum length of a valid hex digest (SHA-256 = 64 hex chars).
8
+ *
9
+ * The component only stores hashes — a `tokenHash` shorter than this or
10
+ * containing non-hex characters is not a plausible digest and is rejected. This
11
+ * guards against a misconfigured or adversarial host calling the component
12
+ * mutation directly and persisting a raw secret or garbage string.
13
+ */
14
+ const MIN_HASH_LENGTH = 64;
15
+ /** Pattern that a plausible hex digest must satisfy (lowercase hex only). */
16
+ const HASH_PATTERN = /^[0-9a-f]+$/;
17
+ /**
18
+ * Mint a token. The component computes `expiresAt` itself from a requested
19
+ * `ttlMs` — it never trusts a client-supplied timestamp. `ttlMs` is clamped into
20
+ * `[MIN_TTL_MS, maxTtlMs]`; a non-finite `ttlMs` (NaN / Infinity) falls back to
21
+ * `defaultTtlMs`. This guarantees a minted token always outlives a `Date.now()`
22
+ * validate (the floor is `MIN_TTL_MS`).
23
+ */
24
+ export const mint = mutation({
25
+ args: {
26
+ tokenHash: v.string(),
27
+ scope: v.string(),
28
+ resourceRef: v.optional(v.string()),
29
+ ttlMs: v.number(),
30
+ defaultTtlMs: v.number(),
31
+ maxTtlMs: v.number(),
32
+ },
33
+ returns: v.id("tokens"),
34
+ handler: async (ctx, args) => {
35
+ const isPlausibleHash = args.tokenHash.length >= MIN_HASH_LENGTH &&
36
+ HASH_PATTERN.test(args.tokenHash);
37
+ if (!isPlausibleHash) {
38
+ throw new ConvexError({
39
+ code: "INVALID_TOKEN_HASH",
40
+ message: "tokenHash must be a lowercase hex digest of at least 64 characters (SHA-256 minimum). " +
41
+ "Use client.hashToken() to produce a valid hash.",
42
+ });
43
+ }
44
+ const ttl = clampTtl(args.ttlMs, MIN_TTL_MS, args.maxTtlMs, args.defaultTtlMs);
45
+ const now = Date.now();
46
+ return await ctx.db.insert("tokens", {
47
+ tokenHash: args.tokenHash,
48
+ scope: args.scope,
49
+ resourceRef: args.resourceRef,
50
+ revoked: false,
51
+ expiresAt: now + ttl,
52
+ createdAt: now,
53
+ });
54
+ },
55
+ });
56
+ /**
57
+ * Revoke the token with `tokenHash` in `scope`.
58
+ *
59
+ * Returns `true` **only if this call transitioned the token from active to
60
+ * revoked** (i.e. it existed in the given scope and was not already revoked).
61
+ * Returns `false` for an unknown token, a wrong-scope token, or a token that
62
+ * is already in the revoked state — the caller can distinguish "nothing to
63
+ * revoke" from "successfully revoked".
64
+ *
65
+ * @remarks This is the "true = transition" contract, not "true = now revoked".
66
+ * Calling revoke twice on the same token returns `true` the first time and
67
+ * `false` the second time. Use `getMetadata` to check the current state
68
+ * without side effects.
69
+ */
70
+ export const revoke = mutation({
71
+ args: { tokenHash: v.string(), scope: v.string() },
72
+ returns: v.boolean(),
73
+ handler: async (ctx, args) => {
74
+ const row = await ctx.db
75
+ .query("tokens")
76
+ .withIndex("by_hash", (q) => q.eq("tokenHash", args.tokenHash))
77
+ .unique();
78
+ if (row === null || row.scope !== args.scope || row.revoked) {
79
+ return false;
80
+ }
81
+ await ctx.db.patch(row._id, { revoked: true });
82
+ return true;
83
+ },
84
+ });
85
+ /**
86
+ * Delete up to `PRUNE_BATCH` tokens that expired before `before` (bounded read
87
+ * via `by_expires`). Returns the count deleted in this batch. Idempotent and
88
+ * bounded — safe to schedule; callers loop until it returns < `PRUNE_BATCH`.
89
+ */
90
+ export const prune = mutation({
91
+ args: { before: v.number() },
92
+ returns: v.number(),
93
+ handler: async (ctx, args) => {
94
+ const expired = await ctx.db
95
+ .query("tokens")
96
+ .withIndex("by_expires", (q) => q.lt("expiresAt", args.before))
97
+ .take(PRUNE_BATCH);
98
+ for (const row of expired) {
99
+ await ctx.db.delete(row._id);
100
+ }
101
+ return expired.length;
102
+ },
103
+ });
104
+ /**
105
+ * Cron-driven sweep. Deletes, in bounded batches, (1) expired tokens and (2)
106
+ * revoked tokens older than `revokedRetentionMs` (so an early-revoked token does
107
+ * not linger for its full TTL). Self-reschedules while a batch fills, so an
108
+ * unbounded backlog is drained without exceeding read limits.
109
+ */
110
+ export const pruneExpired = internalMutation({
111
+ args: {},
112
+ returns: v.null(),
113
+ handler: async (ctx) => {
114
+ const now = Date.now();
115
+ const expired = await ctx.db
116
+ .query("tokens")
117
+ .withIndex("by_expires", (q) => q.lt("expiresAt", now))
118
+ .take(PRUNE_BATCH);
119
+ for (const row of expired) {
120
+ await ctx.db.delete(row._id);
121
+ }
122
+ let revokedDeleted = 0;
123
+ const remaining = PRUNE_BATCH - expired.length;
124
+ if (remaining > 0) {
125
+ const revokedCutoff = now - DEFAULT_REVOKED_RETENTION_MS;
126
+ const staleRevoked = await ctx.db
127
+ .query("tokens")
128
+ .withIndex("by_revoked_created", (q) => q.eq("revoked", true).lt("createdAt", revokedCutoff))
129
+ .take(remaining);
130
+ for (const row of staleRevoked) {
131
+ await ctx.db.delete(row._id);
132
+ }
133
+ revokedDeleted = staleRevoked.length;
134
+ }
135
+ if (expired.length + revokedDeleted === PRUNE_BATCH) {
136
+ await ctx.scheduler.runAfter(0, internal.mutations.pruneExpired, {});
137
+ }
138
+ return null;
139
+ },
140
+ });
141
+ //# sourceMappingURL=mutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE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GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,MAAM,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/C,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,aAAa,GAAG,GAAG,GAAG,4BAA4B,CAAC;YACzD,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,EAAE;iBAC9B,KAAK,CAAC,QAAQ,CAAC;iBACf,SAAS,CAAC,oBAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,CACrC,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC,CACrD;iBACA,IAAI,CAAC,SAAS,CAAC,CAAC;YACnB,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;gBAC/B,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;YACD,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC;QACvC,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,GAAG,cAAc,KAAK,WAAW,EAAE,CAAC;YACpD,MAAM,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Validate a token by its hash. Reads the current time from `Date.now()` INSIDE
3
+ * the handler — there is no client-supplied `now`, so an expired token cannot be
4
+ * revived by passing a stale timestamp. Returns `{ valid: false }` for unknown,
5
+ * wrong-scope, revoked, or expired tokens.
6
+ */
7
+ export declare const validate: import("convex/server").RegisteredQuery<"public", {
8
+ tokenHash: string;
9
+ scope: string;
10
+ }, Promise<{
11
+ valid: boolean;
12
+ resourceRef?: undefined;
13
+ } | {
14
+ valid: boolean;
15
+ resourceRef: string | undefined;
16
+ }>>;
17
+ /**
18
+ * List token METADATA for a management surface, projecting only non-secret
19
+ * lifecycle fields — NEVER `tokenHash`. Filters by `scope` and optional
20
+ * `resourceRef` via the `by_scope_resource` index (a bounded lookup, not a
21
+ * table scan). Returns up to `limit` (default 100, ceiling {@link LIST_LIMIT_MAX})
22
+ * rows. A `limit` above the ceiling is silently clamped; `limit: 0` returns an
23
+ * empty array.
24
+ */
25
+ export declare const list: import("convex/server").RegisteredQuery<"public", {
26
+ resourceRef?: string | undefined;
27
+ limit?: number | undefined;
28
+ scope: string;
29
+ }, Promise<{
30
+ id: import("convex/values").GenericId<"tokens">;
31
+ scope: string;
32
+ resourceRef: string | undefined;
33
+ revoked: boolean;
34
+ expiresAt: number;
35
+ createdAt: number;
36
+ }[]>>;
37
+ /**
38
+ * Fetch the safe METADATA of a single token by its component id — no
39
+ * `tokenHash`. Returns `null` if no such row.
40
+ */
41
+ export declare const getMetadata: import("convex/server").RegisteredQuery<"public", {
42
+ id: import("convex/values").GenericId<"tokens">;
43
+ }, Promise<{
44
+ id: import("convex/values").GenericId<"tokens">;
45
+ scope: string;
46
+ resourceRef: string | undefined;
47
+ revoked: boolean;
48
+ expiresAt: number;
49
+ createdAt: number;
50
+ } | null>>;
51
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;GAmBnB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;KA0Bf,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;;UAiBtB,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { v } from "convex/values";
2
+ import { query } from "./_generated/server";
3
+ import { tokenMetadata, validateResult } from "./validators";
4
+ import { LIST_LIMIT_MAX } from "../shared.js";
5
+ /**
6
+ * Validate a token by its hash. Reads the current time from `Date.now()` INSIDE
7
+ * the handler — there is no client-supplied `now`, so an expired token cannot be
8
+ * revived by passing a stale timestamp. Returns `{ valid: false }` for unknown,
9
+ * wrong-scope, revoked, or expired tokens.
10
+ */
11
+ export const validate = query({
12
+ args: { tokenHash: v.string(), scope: v.string() },
13
+ returns: validateResult,
14
+ handler: async (ctx, args) => {
15
+ const now = Date.now();
16
+ const row = await ctx.db
17
+ .query("tokens")
18
+ .withIndex("by_hash", (q) => q.eq("tokenHash", args.tokenHash))
19
+ .unique();
20
+ if (row === null ||
21
+ row.scope !== args.scope ||
22
+ row.revoked ||
23
+ row.expiresAt <= now) {
24
+ return { valid: false };
25
+ }
26
+ return { valid: true, resourceRef: row.resourceRef };
27
+ },
28
+ });
29
+ /**
30
+ * List token METADATA for a management surface, projecting only non-secret
31
+ * lifecycle fields — NEVER `tokenHash`. Filters by `scope` and optional
32
+ * `resourceRef` via the `by_scope_resource` index (a bounded lookup, not a
33
+ * table scan). Returns up to `limit` (default 100, ceiling {@link LIST_LIMIT_MAX})
34
+ * rows. A `limit` above the ceiling is silently clamped; `limit: 0` returns an
35
+ * empty array.
36
+ */
37
+ export const list = query({
38
+ args: {
39
+ scope: v.string(),
40
+ resourceRef: v.optional(v.string()),
41
+ limit: v.optional(v.number()),
42
+ },
43
+ returns: v.array(tokenMetadata),
44
+ handler: async (ctx, args) => {
45
+ const limit = Math.min(args.limit ?? 100, LIST_LIMIT_MAX);
46
+ const rows = await ctx.db
47
+ .query("tokens")
48
+ .withIndex("by_scope_resource", (q) => args.resourceRef === undefined
49
+ ? q.eq("scope", args.scope)
50
+ : q.eq("scope", args.scope).eq("resourceRef", args.resourceRef))
51
+ .take(limit);
52
+ return rows.map((row) => ({
53
+ id: row._id,
54
+ scope: row.scope,
55
+ resourceRef: row.resourceRef,
56
+ revoked: row.revoked,
57
+ expiresAt: row.expiresAt,
58
+ createdAt: row.createdAt,
59
+ }));
60
+ },
61
+ });
62
+ /**
63
+ * Fetch the safe METADATA of a single token by its component id — no
64
+ * `tokenHash`. Returns `null` if no such row.
65
+ */
66
+ export const getMetadata = query({
67
+ args: { id: v.id("tokens") },
68
+ returns: v.union(tokenMetadata, v.null()),
69
+ handler: async (ctx, args) => {
70
+ const row = await ctx.db.get(args.id);
71
+ if (row === null) {
72
+ return null;
73
+ }
74
+ return {
75
+ id: row._id,
76
+ scope: row.scope,
77
+ resourceRef: row.resourceRef,
78
+ revoked: row.revoked,
79
+ expiresAt: row.expiresAt,
80
+ createdAt: row.createdAt,
81
+ };
82
+ },
83
+ });
84
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC;IAC5B,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IAClD,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE;aACrB,KAAK,CAAC,QAAQ,CAAC;aACf,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC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