@vllnt/convex-invitations 0.1.0-canary.d3aaf07 → 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 (58) hide show
  1. package/dist/client/index.d.ts +19 -10
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/index.js +14 -7
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/client/types.d.ts +2 -0
  6. package/dist/client/types.d.ts.map +1 -1
  7. package/dist/component/_generated/api.d.ts +4 -0
  8. package/dist/component/_generated/api.d.ts.map +1 -1
  9. package/dist/component/_generated/api.js.map +1 -1
  10. package/dist/component/_generated/component.d.ts +17 -16
  11. package/dist/component/_generated/component.d.ts.map +1 -1
  12. package/dist/component/_generated/server.d.ts +12 -0
  13. package/dist/component/_generated/server.d.ts.map +1 -1
  14. package/dist/component/_generated/server.js +2 -0
  15. package/dist/component/_generated/server.js.map +1 -1
  16. package/dist/component/convex.config.d.ts.map +1 -1
  17. package/dist/component/crons.d.ts.map +1 -1
  18. package/dist/component/crons.js +1 -0
  19. package/dist/component/crons.js.map +1 -1
  20. package/dist/component/legacyToken.d.ts +5 -0
  21. package/dist/component/legacyToken.d.ts.map +1 -0
  22. package/dist/component/legacyToken.js +15 -0
  23. package/dist/component/legacyToken.js.map +1 -0
  24. package/dist/component/mutations.d.ts +11 -7
  25. package/dist/component/mutations.d.ts.map +1 -1
  26. package/dist/component/mutations.js +89 -22
  27. package/dist/component/mutations.js.map +1 -1
  28. package/dist/component/queries.d.ts +14 -16
  29. package/dist/component/queries.d.ts.map +1 -1
  30. package/dist/component/queries.js +30 -10
  31. package/dist/component/queries.js.map +1 -1
  32. package/dist/component/schema.d.ts +23 -22
  33. package/dist/component/schema.d.ts.map +1 -1
  34. package/dist/component/schema.js +9 -9
  35. package/dist/component/schema.js.map +1 -1
  36. package/dist/component/token.d.ts +4 -0
  37. package/dist/component/token.d.ts.map +1 -0
  38. package/dist/component/token.js +17 -0
  39. package/dist/component/token.js.map +1 -0
  40. package/dist/component/validators.d.ts +36 -11
  41. package/dist/component/validators.d.ts.map +1 -1
  42. package/dist/component/validators.js +13 -0
  43. package/dist/component/validators.js.map +1 -1
  44. package/dist/shared.d.ts.map +1 -1
  45. package/package.json +18 -15
  46. package/src/client/index.ts +31 -13
  47. package/src/client/types.ts +6 -0
  48. package/src/component/_generated/api.ts +4 -0
  49. package/src/component/_generated/component.ts +20 -15
  50. package/src/component/_generated/server.ts +13 -0
  51. package/src/component/crons.ts +7 -0
  52. package/src/component/legacyToken.ts +24 -0
  53. package/src/component/migration.test.ts +110 -0
  54. package/src/component/mutations.ts +95 -23
  55. package/src/component/queries.ts +31 -10
  56. package/src/component/schema.ts +9 -9
  57. package/src/component/token.ts +19 -0
  58. package/src/component/validators.ts +14 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/component/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,gBAAgB,EAAE,CAAC;QAC1D,MAAM,IAAI,WAAW,CAAC;YACpB,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,+BAA+B,gBAAgB,aAAa;SACtE,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAa;IAC7C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3F,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClF,CAAC"}
@@ -11,7 +11,7 @@
11
11
  */
12
12
  export declare const jsonValue: import("convex/values").VAny<any, "required", string>;
13
13
  /** The four lifecycle states an invitation moves through. */
14
- export declare const invitationState: import("convex/values").VUnion<"pending" | "accepted" | "revoked" | "expired", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"accepted", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"expired", "required">], "required", never>;
14
+ export declare const invitationState: import("convex/values").VUnion<"accepted" | "expired" | "pending" | "revoked", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"accepted", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"expired", "required">], "required", never>;
15
15
  /**
16
16
  * Public projection of an invitation returned by {@link getByToken} and
17
17
  * {@link listPending}. `resourceRef`, `inviterRef`, `inviteeRef`, `role`, and
@@ -19,19 +19,44 @@ export declare const invitationState: import("convex/values").VUnion<"pending" |
19
19
  * interpreting them. `token` is the single-use secret the host hands to the
20
20
  * invitee; the host gates who may read it.
21
21
  */
22
- export declare const invitationView: import("convex/values").VObject<{
23
- role?: any;
24
- inviterRef?: string | undefined;
22
+ export declare const invitationMetadataView: import("convex/values").VObject<{
23
+ acceptedAt?: number | undefined;
24
+ acceptedBy?: string | undefined;
25
+ createdAt: number;
26
+ expiresAt: number;
25
27
  inviteeRef?: string | undefined;
28
+ inviterRef?: string | undefined;
26
29
  payload?: any;
27
- acceptedBy?: string | undefined;
30
+ resourceRef: string;
31
+ revokedAt?: number | undefined;
32
+ role?: any;
33
+ state: "accepted" | "expired" | "pending" | "revoked";
34
+ }, {
35
+ resourceRef: import("convex/values").VString<string, "required">;
36
+ role: import("convex/values").VAny<any, "optional", string>;
37
+ inviterRef: import("convex/values").VString<string | undefined, "optional">;
38
+ inviteeRef: import("convex/values").VString<string | undefined, "optional">;
39
+ payload: import("convex/values").VAny<any, "optional", string>;
40
+ state: import("convex/values").VUnion<"accepted" | "expired" | "pending" | "revoked", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"accepted", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"expired", "required">], "required", never>;
41
+ createdAt: import("convex/values").VFloat64<number, "required">;
42
+ expiresAt: import("convex/values").VFloat64<number, "required">;
43
+ acceptedAt: import("convex/values").VFloat64<number | undefined, "optional">;
44
+ acceptedBy: import("convex/values").VString<string | undefined, "optional">;
45
+ revokedAt: import("convex/values").VFloat64<number | undefined, "optional">;
46
+ }, "required", "acceptedAt" | "acceptedBy" | "createdAt" | "expiresAt" | "inviteeRef" | "inviterRef" | "payload" | "resourceRef" | "revokedAt" | "role" | "state" | `payload.${string}` | `role.${string}`>;
47
+ export declare const invitationView: import("convex/values").VObject<{
28
48
  acceptedAt?: number | undefined;
49
+ acceptedBy?: string | undefined;
50
+ createdAt: number;
51
+ expiresAt: number;
52
+ inviteeRef?: string | undefined;
53
+ inviterRef?: string | undefined;
54
+ payload?: any;
55
+ resourceRef: string;
29
56
  revokedAt?: number | undefined;
57
+ role?: any;
58
+ state: "accepted" | "expired" | "pending" | "revoked";
30
59
  token: string;
31
- resourceRef: string;
32
- expiresAt: number;
33
- state: "pending" | "accepted" | "revoked" | "expired";
34
- createdAt: number;
35
60
  }, {
36
61
  token: import("convex/values").VString<string, "required">;
37
62
  resourceRef: import("convex/values").VString<string, "required">;
@@ -39,11 +64,11 @@ export declare const invitationView: import("convex/values").VObject<{
39
64
  inviterRef: import("convex/values").VString<string | undefined, "optional">;
40
65
  inviteeRef: import("convex/values").VString<string | undefined, "optional">;
41
66
  payload: import("convex/values").VAny<any, "optional", string>;
42
- state: import("convex/values").VUnion<"pending" | "accepted" | "revoked" | "expired", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"accepted", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"expired", "required">], "required", never>;
67
+ state: import("convex/values").VUnion<"accepted" | "expired" | "pending" | "revoked", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"accepted", "required">, import("convex/values").VLiteral<"revoked", "required">, import("convex/values").VLiteral<"expired", "required">], "required", never>;
43
68
  createdAt: import("convex/values").VFloat64<number, "required">;
44
69
  expiresAt: import("convex/values").VFloat64<number, "required">;
45
70
  acceptedAt: import("convex/values").VFloat64<number | undefined, "optional">;
46
71
  acceptedBy: import("convex/values").VString<string | undefined, "optional">;
47
72
  revokedAt: import("convex/values").VFloat64<number | undefined, "optional">;
48
- }, "required", "token" | "resourceRef" | "role" | "inviterRef" | "inviteeRef" | "payload" | "expiresAt" | "acceptedBy" | "state" | "createdAt" | "acceptedAt" | "revokedAt" | `role.${string}` | `payload.${string}`>;
73
+ }, "required", "acceptedAt" | "acceptedBy" | "createdAt" | "expiresAt" | "inviteeRef" | "inviterRef" | "payload" | "resourceRef" | "revokedAt" | "role" | "state" | "token" | `payload.${string}` | `role.${string}`>;
49
74
  //# sourceMappingURL=validators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,uDAAU,CAAC;AAEjC,6DAA6D;AAC7D,eAAO,MAAM,eAAe,0UAK3B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;qNAazB,CAAC"}
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,uDAAU,CAAC;AAEjC,6DAA6D;AAC7D,eAAO,MAAM,eAAe,0UAK3B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;2MAYjC,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;qNAazB,CAAC"}
@@ -20,6 +20,19 @@ export const invitationState = v.union(v.literal("pending"), v.literal("accepted
20
20
  * interpreting them. `token` is the single-use secret the host hands to the
21
21
  * invitee; the host gates who may read it.
22
22
  */
23
+ export const invitationMetadataView = v.object({
24
+ resourceRef: v.string(),
25
+ role: v.optional(jsonValue),
26
+ inviterRef: v.optional(v.string()),
27
+ inviteeRef: v.optional(v.string()),
28
+ payload: v.optional(jsonValue),
29
+ state: invitationState,
30
+ createdAt: v.number(),
31
+ expiresAt: v.number(),
32
+ acceptedAt: v.optional(v.number()),
33
+ acceptedBy: v.optional(v.string()),
34
+ revokedAt: v.optional(v.number()),
35
+ });
23
36
  export const invitationView = v.object({
24
37
  token: v.string(),
25
38
  resourceRef: v.string(),
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AAEjC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CACpC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EACrB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CACrB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,WAAW,EAAE,CAAC,CAAC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;IAClC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAClC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,wDAKpB,CAAC;AAEX,2CAA2C;AAC3C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,uFAAuF;AACvF,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,eAAe,CAIvD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,YAAc,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,aAAgB,CAAC;AAElD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,YAC5B,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,CACD,CAAC;AAEX,2CAA2C;AAC3C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,uFAAuF;AACvF,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,eAAe,CAIvD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,YAAc,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,aAAgB,CAAC;AAElD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vllnt/convex-invitations",
3
- "version": "0.1.0-canary.d3aaf07",
3
+ "version": "0.1.0",
4
4
  "description": "Invite → accept → expire flow — issue a single-use, expiring invitation to a resource and consume it, as a Convex component",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,11 +35,11 @@
35
35
  "module": "./dist/client/index.js",
36
36
  "scripts": {
37
37
  "build": "tsc --project ./tsconfig.build.json",
38
- "build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
38
+ "build:codegen": "pnpm codegen && pnpm build",
39
39
  "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
40
40
  "typecheck": "tsc --noEmit",
41
41
  "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
42
- "lint": "eslint .",
42
+ "lint": "pnpm check:agents && eslint .",
43
43
  "test": "vitest run --passWithNoTests",
44
44
  "test:watch": "vitest --typecheck --clearScreen false",
45
45
  "test:coverage": "vitest run --coverage --coverage.reporter=text",
@@ -47,23 +47,26 @@
47
47
  "preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
48
48
  "prepublishOnly": "npm whoami || npm login",
49
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"
50
+ "release": "npm version patch && npm publish && git push --follow-tags",
51
+ "check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\"",
52
+ "codegen": "pnpm convex codegen --component-dir ./src/component"
51
53
  },
52
- "dependencies": {},
53
54
  "peerDependencies": {
54
- "convex": "^1.41.0"
55
+ "convex": "^1.45.0"
55
56
  },
56
57
  "devDependencies": {
57
58
  "@edge-runtime/vm": "^5.0.0",
58
- "@vitest/coverage-v8": "^4.1.8",
59
- "@vllnt/eslint-config": "^1.0.0",
60
- "@vllnt/typescript": "^1.0.0",
61
- "convex": "^1.41.0",
62
- "convex-test": "^0.0.53",
63
- "eslint": "^9.0.0",
64
- "prettier": "^3.4.0",
65
- "typescript": "^5.7.0",
66
- "vitest": "^4.1.8"
59
+ "@typescript/native": "npm:typescript@7.0.2",
60
+ "@vitest/coverage-v8": "^4.1.11",
61
+ "@vllnt/eslint-config": "2.0.0",
62
+ "@vllnt/typescript": "2.0.0",
63
+ "convex": "^1.45.0",
64
+ "convex-test": "^0.0.56",
65
+ "eslint": "^9.39.5",
66
+ "prettier": "^3.9.6",
67
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
68
+ "vite": "^8.2.2",
69
+ "vitest": "^4.1.11"
67
70
  },
68
71
  "homepage": "https://github.com/vllnt/convex-invitations#readme",
69
72
  "bugs": {
@@ -7,6 +7,7 @@ import type {
7
7
  } from "convex/server";
8
8
  import type {
9
9
  InvitationGrant,
10
+ InvitationMetadata,
10
11
  InvitationState,
11
12
  InvitationView,
12
13
  InvitationsOptions,
@@ -20,8 +21,7 @@ import { DEFAULT_PRUNE_BATCH, DEFAULT_TTL_MS } from "../shared.js";
20
21
  * data. `role` and `payload` are `unknown` here; the {@link Invitations} client
21
22
  * runs the host validators over them at its typed boundary.
22
23
  */
23
- type RawView = {
24
- token: string;
24
+ type RawMetadata = {
25
25
  resourceRef: string;
26
26
  role?: unknown;
27
27
  inviterRef?: string;
@@ -35,6 +35,8 @@ type RawView = {
35
35
  revokedAt?: number;
36
36
  };
37
37
 
38
+ type RawView = RawMetadata & { token: string };
39
+
38
40
  /** The component's raw accept grant, before the client narrows opaque host data. */
39
41
  type RawGrant = { resourceRef: string; role?: unknown; payload?: unknown };
40
42
 
@@ -78,6 +80,12 @@ export interface InvitationsComponent {
78
80
  { token: string },
79
81
  RawView | null
80
82
  >;
83
+ migrateLegacyTokens: FunctionReference<
84
+ "mutation",
85
+ "internal",
86
+ { batch?: number },
87
+ number
88
+ >;
81
89
  prune: FunctionReference<
82
90
  "mutation",
83
91
  "internal",
@@ -96,7 +104,7 @@ export interface InvitationsComponent {
96
104
  "query",
97
105
  "internal",
98
106
  { resourceRef: string; paginationOpts: PaginationOptions },
99
- PaginationResult<RawView>
107
+ PaginationResult<RawMetadata>
100
108
  >;
101
109
  listByResourceState: FunctionReference<
102
110
  "query",
@@ -106,7 +114,7 @@ export interface InvitationsComponent {
106
114
  state: InvitationState;
107
115
  paginationOpts: PaginationOptions;
108
116
  },
109
- PaginationResult<RawView>
117
+ PaginationResult<RawMetadata>
110
118
  >;
111
119
  };
112
120
  }
@@ -139,8 +147,9 @@ interface RunMutationCtx {
139
147
  * `roleValidator` / `payloadValidator` to narrow that opaque data to
140
148
  * `TRole` / `TPayload` at the boundary — there is no unchecked cast.
141
149
  *
142
- * At this minimal stage the invite (including its token) is modelled
143
- * self-contained; a later version would delegate the hashed/revocable token to
150
+ * Invitation state is self-contained, but only a SHA-256 token digest is persisted;
151
+ * the raw bearer token is returned once by `issue`. A later version could delegate
152
+ * the hashed/revocable token to
144
153
  * `@vllnt/convex-tokens` and write the granted membership via
145
154
  * `@vllnt/convex-memberships`, with `accept` composing the two.
146
155
  *
@@ -186,10 +195,8 @@ export class Invitations<TRole = unknown, TPayload = unknown> {
186
195
  return parser(value);
187
196
  }
188
197
 
189
- /** Project a raw component view into the typed, validated client view. */
190
- private view(raw: RawView): InvitationView<TRole, TPayload> {
198
+ private metadata(raw: RawMetadata): InvitationMetadata<TRole, TPayload> {
191
199
  return {
192
- token: raw.token,
193
200
  resourceRef: raw.resourceRef,
194
201
  role: this.parse(raw.role, this.roleValidator),
195
202
  inviterRef: raw.inviterRef,
@@ -204,6 +211,11 @@ export class Invitations<TRole = unknown, TPayload = unknown> {
204
211
  };
205
212
  }
206
213
 
214
+ /** Project a raw component view into the typed, validated client view. */
215
+ private view(raw: RawView): InvitationView<TRole, TPayload> {
216
+ return { token: raw.token, ...this.metadata(raw) };
217
+ }
218
+
207
219
  /** Project a raw accept grant into the typed, validated grant. */
208
220
  private grant(raw: RawGrant): InvitationGrant<TRole, TPayload> {
209
221
  return {
@@ -278,6 +290,11 @@ export class Invitations<TRole = unknown, TPayload = unknown> {
278
290
  return raw === null ? null : this.view(raw);
279
291
  }
280
292
 
293
+ /** Migrate raw pre-upgrade bearer tokens to hashed storage in bounded batches. */
294
+ migrateLegacyTokens(ctx: RunMutationCtx, batch?: number): Promise<number> {
295
+ return ctx.runMutation(this.component.mutations.migrateLegacyTokens, { batch });
296
+ }
297
+
281
298
  /**
282
299
  * Sweep stale `pending` invites to `expired` and delete terminal invites past
283
300
  * retention, in bounded batches oldest-first. `before` (the TTL cutoff) and
@@ -320,12 +337,12 @@ export class Invitations<TRole = unknown, TPayload = unknown> {
320
337
  ctx: RunQueryCtx,
321
338
  resourceRef: string,
322
339
  paginationOpts: PaginationOptions,
323
- ): Promise<PaginationResult<InvitationView<TRole, TPayload>>> {
340
+ ): Promise<PaginationResult<InvitationMetadata<TRole, TPayload>>> {
324
341
  const result = await ctx.runQuery(this.component.queries.listPending, {
325
342
  resourceRef,
326
343
  paginationOpts,
327
344
  });
328
- return { ...result, page: result.page.map((raw) => this.view(raw)) };
345
+ return { ...result, page: result.page.map((raw) => this.metadata(raw)) };
329
346
  }
330
347
 
331
348
  /**
@@ -338,17 +355,18 @@ export class Invitations<TRole = unknown, TPayload = unknown> {
338
355
  resourceRef: string,
339
356
  state: InvitationState,
340
357
  paginationOpts: PaginationOptions,
341
- ): Promise<PaginationResult<InvitationView<TRole, TPayload>>> {
358
+ ): Promise<PaginationResult<InvitationMetadata<TRole, TPayload>>> {
342
359
  const result = await ctx.runQuery(
343
360
  this.component.queries.listByResourceState,
344
361
  { resourceRef, state, paginationOpts },
345
362
  );
346
- return { ...result, page: result.page.map((raw) => this.view(raw)) };
363
+ return { ...result, page: result.page.map((raw) => this.metadata(raw)) };
347
364
  }
348
365
  }
349
366
 
350
367
  export type {
351
368
  InvitationGrant,
369
+ InvitationMetadata,
352
370
  InvitationState,
353
371
  InvitationView,
354
372
  InvitationsOptions,
@@ -41,6 +41,12 @@ export interface InvitationView<TRole = unknown, TPayload = unknown> {
41
41
  revokedAt?: number;
42
42
  }
43
43
 
44
+ /** Metadata-safe list projection that never exposes the bearer token. */
45
+ export type InvitationMetadata<TRole = unknown, TPayload = unknown> = Omit<
46
+ InvitationView<TRole, TPayload>,
47
+ "token"
48
+ >;
49
+
44
50
  /**
45
51
  * The grant {@link Invitations.accept} returns — what the host applies (writes a
46
52
  * membership, grants a role) once an invite is consumed. `role`/`payload` are
@@ -9,8 +9,10 @@
9
9
  */
10
10
 
11
11
  import type * as crons from "../crons.js";
12
+ import type * as legacyToken from "../legacyToken.js";
12
13
  import type * as mutations from "../mutations.js";
13
14
  import type * as queries from "../queries.js";
15
+ import type * as token from "../token.js";
14
16
  import type * as validators from "../validators.js";
15
17
 
16
18
  import type {
@@ -22,8 +24,10 @@ import { anyApi, componentsGeneric } from "convex/server";
22
24
 
23
25
  const fullApi: ApiFromModules<{
24
26
  crons: typeof crons;
27
+ legacyToken: typeof legacyToken;
25
28
  mutations: typeof mutations;
26
29
  queries: typeof queries;
30
+ token: typeof token;
27
31
  validators: typeof validators;
28
32
  }> = anyApi as any;
29
33
 
@@ -24,6 +24,13 @@ import type { FunctionReference } from "convex/server";
24
24
  export type ComponentApi<Name extends string | undefined = string | undefined> =
25
25
  {
26
26
  mutations: {
27
+ accept: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ { acceptedBy: string; token: string },
31
+ { payload?: any; resourceRef: string; role?: any },
32
+ Name
33
+ >;
27
34
  issue: FunctionReference<
28
35
  "mutation",
29
36
  "internal",
@@ -39,18 +46,11 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
39
46
  { expiresAt: number; token: string },
40
47
  Name
41
48
  >;
42
- accept: FunctionReference<
43
- "mutation",
44
- "internal",
45
- { acceptedBy: string; token: string },
46
- { payload?: any; resourceRef: string; role?: any },
47
- Name
48
- >;
49
- revoke: FunctionReference<
49
+ migrateLegacyTokens: FunctionReference<
50
50
  "mutation",
51
51
  "internal",
52
- { token: string },
53
- null,
52
+ { batch?: number },
53
+ number,
54
54
  Name
55
55
  >;
56
56
  peek: FunctionReference<
@@ -80,6 +80,13 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
80
80
  number,
81
81
  Name
82
82
  >;
83
+ revoke: FunctionReference<
84
+ "mutation",
85
+ "internal",
86
+ { token: string },
87
+ null,
88
+ Name
89
+ >;
83
90
  };
84
91
  queries: {
85
92
  getByToken: FunctionReference<
@@ -102,7 +109,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
102
109
  },
103
110
  Name
104
111
  >;
105
- listPending: FunctionReference<
112
+ listByResourceState: FunctionReference<
106
113
  "query",
107
114
  "internal",
108
115
  {
@@ -115,6 +122,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
115
122
  numItems: number;
116
123
  };
117
124
  resourceRef: string;
125
+ state: "pending" | "accepted" | "revoked" | "expired";
118
126
  },
119
127
  {
120
128
  continueCursor: string;
@@ -131,14 +139,13 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
131
139
  revokedAt?: number;
132
140
  role?: any;
133
141
  state: "pending" | "accepted" | "revoked" | "expired";
134
- token: string;
135
142
  }>;
136
143
  pageStatus?: "SplitRecommended" | "SplitRequired" | null;
137
144
  splitCursor?: string | null;
138
145
  },
139
146
  Name
140
147
  >;
141
- listByResourceState: FunctionReference<
148
+ listPending: FunctionReference<
142
149
  "query",
143
150
  "internal",
144
151
  {
@@ -151,7 +158,6 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
151
158
  numItems: number;
152
159
  };
153
160
  resourceRef: string;
154
- state: "pending" | "accepted" | "revoked" | "expired";
155
161
  },
156
162
  {
157
163
  continueCursor: string;
@@ -168,7 +174,6 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
168
174
  revokedAt?: number;
169
175
  role?: any;
170
176
  state: "pending" | "accepted" | "revoked" | "expired";
171
- token: string;
172
177
  }>;
173
178
  pageStatus?: "SplitRecommended" | "SplitRequired" | null;
174
179
  splitCursor?: string | null;
@@ -30,6 +30,17 @@ import {
30
30
  } from "convex/server";
31
31
  import type { DataModel } from "./dataModel.js";
32
32
 
33
+ /**
34
+ * Typesafe environment variables.
35
+ *
36
+ * This includes platform-provided env vars and any variables declared in
37
+ * `convex.config.ts`.
38
+ */
39
+ type Env = {
40
+ readonly CONVEX_CLOUD_URL: string;
41
+ readonly CONVEX_SITE_URL: string;
42
+ };
43
+
33
44
  /**
34
45
  * Define a query in this Convex app's public API.
35
46
  *
@@ -106,6 +117,8 @@ export const internalAction: ActionBuilder<DataModel, "internal"> =
106
117
  * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
107
118
  */
108
119
  export const httpAction: HttpActionBuilder = httpActionGeneric;
120
+ export const env: Env = (globalThis as unknown as { process: { env: Env } })
121
+ .process.env;
109
122
 
110
123
  /**
111
124
  * A set of services for use within Convex query functions.
@@ -19,6 +19,13 @@ export const PRUNE_BATCH = 200;
19
19
 
20
20
  const crons = cronJobs();
21
21
 
22
+ crons.interval(
23
+ "invitations:migrate-legacy-tokens",
24
+ PRUNE_INTERVAL,
25
+ api.mutations.migrateLegacyTokens,
26
+ {},
27
+ );
28
+
22
29
  crons.interval("invitations:prune", PRUNE_INTERVAL, api.mutations.prune, {
23
30
  batch: PRUNE_BATCH,
24
31
  });
@@ -0,0 +1,24 @@
1
+ import type { Doc } from "./_generated/dataModel";
2
+ import type { MutationCtx, QueryCtx } from "./_generated/server";
3
+
4
+ export async function migrateLegacyToken(
5
+ db: MutationCtx["db"],
6
+ invite: Doc<"invitations">,
7
+ tokenHash: string,
8
+ ): Promise<Doc<"invitations">> {
9
+ if (invite.token === undefined) return invite;
10
+ await db.patch("invitations", invite._id, { tokenHash, token: undefined });
11
+ return { ...invite, tokenHash, token: undefined };
12
+ }
13
+
14
+ export async function withLegacyTokenFallback(
15
+ db: QueryCtx["db"],
16
+ hashed: Doc<"invitations"> | null,
17
+ token: string,
18
+ ): Promise<Doc<"invitations"> | null> {
19
+ if (hashed !== null) return hashed;
20
+ return db
21
+ .query("invitations")
22
+ .withIndex("by_token", (query) => query.eq("token", token))
23
+ .unique();
24
+ }
@@ -0,0 +1,110 @@
1
+ /// <reference types="vite/client" />
2
+ import { convexTest } from "convex-test";
3
+ import { expect, test, vi } from "vitest";
4
+ import { api } from "./_generated/api";
5
+ import schema from "./schema";
6
+ import { tokenDigest } from "./token";
7
+
8
+ const modules = import.meta.glob("./**/*.ts");
9
+
10
+ function setup() {
11
+ return convexTest(schema, modules);
12
+ }
13
+
14
+ async function seedLegacy(t: ReturnType<typeof setup>, token: string) {
15
+ return t.run((ctx) =>
16
+ ctx.db.insert("invitations", {
17
+ token,
18
+ resourceRef: "resource",
19
+ state: "pending",
20
+ createdAt: Date.now(),
21
+ expiresAt: Date.now() + 60_000,
22
+ }),
23
+ );
24
+ }
25
+
26
+ test("new invitations persist only a token digest", async () => {
27
+ const t = setup();
28
+ const token = "new-secret";
29
+ await t.mutation(api.mutations.issue, {
30
+ token,
31
+ resourceRef: "resource",
32
+ expiresAt: Date.now() + 60_000,
33
+ });
34
+ const digest = await tokenDigest(token);
35
+ const stored = await t.run((ctx) =>
36
+ ctx.db
37
+ .query("invitations")
38
+ .withIndex("by_token_hash", (q) => q.eq("tokenHash", digest))
39
+ .unique(),
40
+ );
41
+ expect(stored?.tokenHash).toBe(digest);
42
+ expect(stored?.token).toBeUndefined();
43
+ });
44
+
45
+ test("accepting a legacy invitation removes the raw bearer token", async () => {
46
+ const t = setup();
47
+ const token = "legacy-accept";
48
+ const id = await seedLegacy(t, token);
49
+ await t.mutation(api.mutations.accept, { token, acceptedBy: "subject" });
50
+ const stored = await t.run((ctx) => ctx.db.get("invitations", id));
51
+ expect(stored?.token).toBeUndefined();
52
+ expect(stored?.tokenHash).toBe(await tokenDigest(token));
53
+ expect(stored?.state).toBe("accepted");
54
+ });
55
+
56
+ test("legacy lookup and duplicate detection work before background migration", async () => {
57
+ const t = setup();
58
+ const token = "legacy-lookup";
59
+ await seedLegacy(t, token);
60
+ expect((await t.query(api.queries.getByToken, { token }))?.resourceRef).toBe("resource");
61
+ await expect(
62
+ t.mutation(api.mutations.issue, {
63
+ token,
64
+ resourceRef: "other",
65
+ expiresAt: Date.now() + 60_000,
66
+ }),
67
+ ).rejects.toThrow(/DUPLICATE_TOKEN|already exists/);
68
+ });
69
+
70
+ test("bounded migration hashes legacy tokens and self-drains", async () => {
71
+ vi.useFakeTimers();
72
+ try {
73
+ const t = setup();
74
+ const first = await seedLegacy(t, "");
75
+ const second = await seedLegacy(t, "legacy-two");
76
+ expect(await t.mutation(api.mutations.migrateLegacyTokens, { batch: 1 })).toBe(1);
77
+ await t.finishAllScheduledFunctions(vi.runAllTimers);
78
+ for (const id of [first, second]) {
79
+ const stored = await t.run((ctx) => ctx.db.get("invitations", id));
80
+ expect(stored?.token).toBeUndefined();
81
+ expect(stored?.tokenHash).toMatch(/^[a-f0-9]{64}$/);
82
+ }
83
+ } finally {
84
+ vi.useRealTimers();
85
+ }
86
+ });
87
+
88
+ test.each(["", "x".repeat(513)])("rejects invalid bearer token length", async (token) => {
89
+ const t = setup();
90
+ await expect(
91
+ t.mutation(api.mutations.issue, {
92
+ token,
93
+ resourceRef: "resource",
94
+ expiresAt: Date.now() + 60_000,
95
+ }),
96
+ ).rejects.toThrow(/INVALID_TOKEN|between 1 and 512/);
97
+ await expect(t.query(api.queries.getByToken, { token })).rejects.toThrow(
98
+ /INVALID_TOKEN|between 1 and 512/,
99
+ );
100
+ });
101
+
102
+ test.each([Number.NaN, 0, -1, 1.5, 101])(
103
+ "legacy migration rejects invalid batch %s",
104
+ async (batch) => {
105
+ const t = setup();
106
+ await expect(
107
+ t.mutation(api.mutations.migrateLegacyTokens, { batch }),
108
+ ).rejects.toThrow(/INVALID_BATCH|integer between/);
109
+ },
110
+ );