@vllnt/convex-invitations 0.1.0-canary.01d468e

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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +139 -0
  3. package/dist/client/index.d.ts +196 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +181 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +93 -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 +148 -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 +133 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +80 -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 +19 -0
  32. package/dist/component/crons.d.ts.map +1 -0
  33. package/dist/component/crons.js +22 -0
  34. package/dist/component/crons.js.map +1 -0
  35. package/dist/component/mutations.d.ts +118 -0
  36. package/dist/component/mutations.d.ts.map +1 -0
  37. package/dist/component/mutations.js +272 -0
  38. package/dist/component/mutations.js.map +1 -0
  39. package/dist/component/queries.d.ts +98 -0
  40. package/dist/component/queries.d.ts.map +1 -0
  41. package/dist/component/queries.js +93 -0
  42. package/dist/component/queries.js.map +1 -0
  43. package/dist/component/schema.d.ts +56 -0
  44. package/dist/component/schema.d.ts.map +1 -0
  45. package/dist/component/schema.js +44 -0
  46. package/dist/component/schema.js.map +1 -0
  47. package/dist/component/validators.d.ts +49 -0
  48. package/dist/component/validators.d.ts.map +1 -0
  49. package/dist/component/validators.js +37 -0
  50. package/dist/component/validators.js.map +1 -0
  51. package/dist/shared.d.ts +33 -0
  52. package/dist/shared.d.ts.map +1 -0
  53. package/dist/shared.js +40 -0
  54. package/dist/shared.js.map +1 -0
  55. package/package.json +101 -0
  56. package/src/client/index.ts +357 -0
  57. package/src/client/types.ts +98 -0
  58. package/src/component/_generated/api.ts +56 -0
  59. package/src/component/_generated/component.ts +179 -0
  60. package/src/component/_generated/dataModel.ts +60 -0
  61. package/src/component/_generated/server.ts +169 -0
  62. package/src/component/convex.config.ts +9 -0
  63. package/src/component/crons.ts +26 -0
  64. package/src/component/mutations.ts +307 -0
  65. package/src/component/queries.ts +113 -0
  66. package/src/component/schema.ts +44 -0
  67. package/src/component/validators.ts +44 -0
  68. package/src/shared.ts +48 -0
  69. package/src/test.ts +12 -0
@@ -0,0 +1,357 @@
1
+ import type {
2
+ FunctionArgs,
3
+ FunctionReference,
4
+ FunctionReturnType,
5
+ PaginationOptions,
6
+ PaginationResult,
7
+ } from "convex/server";
8
+ import type {
9
+ InvitationGrant,
10
+ InvitationState,
11
+ InvitationView,
12
+ InvitationsOptions,
13
+ IssueOptions,
14
+ Parser,
15
+ } from "./types.js";
16
+ import { DEFAULT_PRUNE_BATCH, DEFAULT_TTL_MS } from "../shared.js";
17
+
18
+ /**
19
+ * The component's raw invitation view, before the client narrows opaque host
20
+ * data. `role` and `payload` are `unknown` here; the {@link Invitations} client
21
+ * runs the host validators over them at its typed boundary.
22
+ */
23
+ type RawView = {
24
+ token: string;
25
+ resourceRef: string;
26
+ role?: unknown;
27
+ inviterRef?: string;
28
+ inviteeRef?: string;
29
+ payload?: unknown;
30
+ state: InvitationState;
31
+ createdAt: number;
32
+ expiresAt: number;
33
+ acceptedAt?: number;
34
+ acceptedBy?: string;
35
+ revokedAt?: number;
36
+ };
37
+
38
+ /** The component's raw accept grant, before the client narrows opaque host data. */
39
+ type RawGrant = { resourceRef: string; role?: unknown; payload?: unknown };
40
+
41
+ /**
42
+ * The invitations component's function references, as exposed on the host via
43
+ * `components.invitations`. The host's stored `role`/`payload` are opaque here
44
+ * (`unknown`); the {@link Invitations} client narrows them at its own typed
45
+ * boundary.
46
+ */
47
+ export interface InvitationsComponent {
48
+ mutations: {
49
+ issue: FunctionReference<
50
+ "mutation",
51
+ "internal",
52
+ {
53
+ token: string;
54
+ resourceRef: string;
55
+ role?: unknown;
56
+ inviterRef?: string;
57
+ inviteeRef?: string;
58
+ payload?: unknown;
59
+ expiresAt: number;
60
+ },
61
+ { token: string; expiresAt: number }
62
+ >;
63
+ accept: FunctionReference<
64
+ "mutation",
65
+ "internal",
66
+ { token: string; acceptedBy: string },
67
+ RawGrant
68
+ >;
69
+ revoke: FunctionReference<
70
+ "mutation",
71
+ "internal",
72
+ { token: string },
73
+ null
74
+ >;
75
+ peek: FunctionReference<
76
+ "mutation",
77
+ "internal",
78
+ { token: string },
79
+ RawView | null
80
+ >;
81
+ prune: FunctionReference<
82
+ "mutation",
83
+ "internal",
84
+ { before?: number; retentionBefore?: number; batch: number },
85
+ number
86
+ >;
87
+ };
88
+ queries: {
89
+ getByToken: FunctionReference<
90
+ "query",
91
+ "internal",
92
+ { token: string },
93
+ RawView | null
94
+ >;
95
+ listPending: FunctionReference<
96
+ "query",
97
+ "internal",
98
+ { resourceRef: string; paginationOpts: PaginationOptions },
99
+ PaginationResult<RawView>
100
+ >;
101
+ listByResourceState: FunctionReference<
102
+ "query",
103
+ "internal",
104
+ {
105
+ resourceRef: string;
106
+ state: InvitationState;
107
+ paginationOpts: PaginationOptions;
108
+ },
109
+ PaginationResult<RawView>
110
+ >;
111
+ };
112
+ }
113
+
114
+ interface RunQueryCtx {
115
+ runQuery<Q extends FunctionReference<"query", "internal">>(
116
+ reference: Q,
117
+ args: FunctionArgs<Q>,
118
+ ): Promise<FunctionReturnType<Q>>;
119
+ }
120
+
121
+ interface RunMutationCtx {
122
+ runMutation<M extends FunctionReference<"mutation", "internal">>(
123
+ reference: M,
124
+ args: FunctionArgs<M>,
125
+ ): Promise<FunctionReturnType<M>>;
126
+ }
127
+
128
+ /**
129
+ * Consumer-facing client for the invitation flow — issue → accept → expire. A
130
+ * host mutation `issue`s an invitation to an opaque `resourceRef` (an org, a
131
+ * team, a workspace) and gets back a single-use `token` to hand to the invitee
132
+ * out of band (an email, a link); the invitee redeems it with `accept`, which
133
+ * consumes the invite (single-use) and returns the grant the host applies. A
134
+ * still-open invite can be `revoke`d, and an unaccepted invite `expire`s when
135
+ * its TTL elapses (enforced on read and by a daily cron). The host owns meaning
136
+ * and auth — it resolves identity, decides who may issue/accept, and passes
137
+ * opaque `resourceRef`/`inviterRef`/`inviteeRef` refs plus arbitrary
138
+ * `role`/`payload` data the component stores without inspecting. Pass
139
+ * `roleValidator` / `payloadValidator` to narrow that opaque data to
140
+ * `TRole` / `TPayload` at the boundary — there is no unchecked cast.
141
+ *
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
144
+ * `@vllnt/convex-tokens` and write the granted membership via
145
+ * `@vllnt/convex-memberships`, with `accept` composing the two.
146
+ *
147
+ * @typeParam TRole - The host's role type to grant on accept (defaults to `unknown`).
148
+ * @typeParam TPayload - The host's opaque invite payload type (defaults to `unknown`).
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * const invites = new Invitations(components.invitations, {
153
+ * ttlMs: 1000 * 60 * 60 * 24 * 3, // 3-day links
154
+ * roleValidator: v.union(v.literal("admin"), v.literal("member")).parse,
155
+ * });
156
+ * const { token } = await invites.issue(ctx, "org_42", { role: "member", inviterRef: me });
157
+ * // ... invitee later redeems the link:
158
+ * const grant = await invites.accept(ctx, token, invitee);
159
+ * // host applies grant.resourceRef + grant.role (writes a membership)
160
+ * ```
161
+ */
162
+ export class Invitations<TRole = unknown, TPayload = unknown> {
163
+ private readonly ttlMs: number;
164
+ private readonly generateToken: () => string;
165
+ private readonly roleValidator: Parser<TRole> | undefined;
166
+ private readonly payloadValidator: Parser<TPayload> | undefined;
167
+
168
+ constructor(
169
+ private readonly component: InvitationsComponent,
170
+ options: InvitationsOptions<TRole, TPayload> = {},
171
+ ) {
172
+ this.ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
173
+ this.generateToken = options.generateToken ?? (() => crypto.randomUUID());
174
+ this.roleValidator = options.roleValidator;
175
+ this.payloadValidator = options.payloadValidator;
176
+ }
177
+
178
+ /** Narrow an opaque value through a host parser; pass `undefined` and unset parsers through. */
179
+ private parse<T>(value: unknown, parser: Parser<T> | undefined): T | undefined {
180
+ if (value === undefined) {
181
+ return undefined;
182
+ }
183
+ if (parser === undefined) {
184
+ return value as T;
185
+ }
186
+ return parser(value);
187
+ }
188
+
189
+ /** Project a raw component view into the typed, validated client view. */
190
+ private view(raw: RawView): InvitationView<TRole, TPayload> {
191
+ return {
192
+ token: raw.token,
193
+ resourceRef: raw.resourceRef,
194
+ role: this.parse(raw.role, this.roleValidator),
195
+ inviterRef: raw.inviterRef,
196
+ inviteeRef: raw.inviteeRef,
197
+ payload: this.parse(raw.payload, this.payloadValidator),
198
+ state: raw.state,
199
+ createdAt: raw.createdAt,
200
+ expiresAt: raw.expiresAt,
201
+ acceptedAt: raw.acceptedAt,
202
+ acceptedBy: raw.acceptedBy,
203
+ revokedAt: raw.revokedAt,
204
+ };
205
+ }
206
+
207
+ /** Project a raw accept grant into the typed, validated grant. */
208
+ private grant(raw: RawGrant): InvitationGrant<TRole, TPayload> {
209
+ return {
210
+ resourceRef: raw.resourceRef,
211
+ role: this.parse(raw.role, this.roleValidator),
212
+ payload: this.parse(raw.payload, this.payloadValidator),
213
+ };
214
+ }
215
+
216
+ /**
217
+ * Issue an invitation to `resourceRef` and return the single-use `token` (to
218
+ * hand to the invitee out of band) plus its absolute `expiresAt`. The token is
219
+ * minted by `generateToken` (a UUID by default). Expiry resolves to
220
+ * `opts.expiresAt` if given, else `now + (opts.ttlMs ?? the client default)`.
221
+ * `role`/`payload` are validated against the host validators before storage.
222
+ */
223
+ async issue(
224
+ ctx: RunMutationCtx,
225
+ resourceRef: string,
226
+ opts: IssueOptions<TRole, TPayload> = {},
227
+ ): Promise<{ token: string; expiresAt: number }> {
228
+ const token = this.generateToken();
229
+ const expiresAt = opts.expiresAt ?? Date.now() + (opts.ttlMs ?? this.ttlMs);
230
+ return ctx.runMutation(this.component.mutations.issue, {
231
+ token,
232
+ resourceRef,
233
+ role: this.parse(opts.role, this.roleValidator),
234
+ inviterRef: opts.inviterRef,
235
+ inviteeRef: opts.inviteeRef,
236
+ payload: this.parse(opts.payload, this.payloadValidator),
237
+ expiresAt,
238
+ });
239
+ }
240
+
241
+ /**
242
+ * Redeem an invitation by its `token` for the opaque `acceptedBy` subject —
243
+ * the single-use accept. Consumes the invite (transitions it to `accepted`)
244
+ * and returns the grant the host applies (`resourceRef` + narrowed
245
+ * `role`/`payload`). Rejects a missing, expired, or already-terminal invite
246
+ * (the component throws a coded `ConvexError`); two racing accepts yield
247
+ * exactly one winner.
248
+ */
249
+ async accept(
250
+ ctx: RunMutationCtx,
251
+ token: string,
252
+ acceptedBy: string,
253
+ ): Promise<InvitationGrant<TRole, TPayload>> {
254
+ const raw = await ctx.runMutation(this.component.mutations.accept, {
255
+ token,
256
+ acceptedBy,
257
+ });
258
+ return this.grant(raw);
259
+ }
260
+
261
+ /** Revoke a still-`pending` invitation by its `token`. Rejects an already-terminal invite. */
262
+ revoke(ctx: RunMutationCtx, token: string): Promise<null> {
263
+ return ctx.runMutation(this.component.mutations.revoke, { token });
264
+ }
265
+
266
+ /**
267
+ * The current view of one invitation by its `token`, or `null` if no such
268
+ * invite is held — with read-time TTL enforcement: a `pending` invite found
269
+ * past its `expiresAt` is flipped to `expired` and returned as such. Runs as a
270
+ * mutation (it may write that one transition); use {@link getByToken} for a
271
+ * pure reactive read.
272
+ */
273
+ async peek(
274
+ ctx: RunMutationCtx,
275
+ token: string,
276
+ ): Promise<InvitationView<TRole, TPayload> | null> {
277
+ const raw = await ctx.runMutation(this.component.mutations.peek, { token });
278
+ return raw === null ? null : this.view(raw);
279
+ }
280
+
281
+ /**
282
+ * Sweep stale `pending` invites to `expired` and delete terminal invites past
283
+ * retention, in bounded batches oldest-first. `before` (the TTL cutoff) and
284
+ * `retentionBefore` (the deletion cutoff) default to the server clock; `batch`
285
+ * caps each pass and the sweep self-reschedules until the tail is clean.
286
+ * Returns the count touched in the first pass. The built-in daily cron drives
287
+ * this automatically.
288
+ */
289
+ prune(
290
+ ctx: RunMutationCtx,
291
+ opts: { before?: number; retentionBefore?: number; batch?: number } = {},
292
+ ): Promise<number> {
293
+ return ctx.runMutation(this.component.mutations.prune, {
294
+ before: opts.before,
295
+ retentionBefore: opts.retentionBefore,
296
+ batch: opts.batch ?? DEFAULT_PRUNE_BATCH,
297
+ });
298
+ }
299
+
300
+ /**
301
+ * The current view of one invitation by its `token`, or `null` — a pure
302
+ * reactive read (no write). Reports the stored `state` as-is, so a past-TTL
303
+ * invite may still read `pending` until a `peek`/`accept`/cron sweep flips it;
304
+ * compare `expiresAt` against the clock, or use {@link peek} for read-time TTL.
305
+ */
306
+ async getByToken(
307
+ ctx: RunQueryCtx,
308
+ token: string,
309
+ ): Promise<InvitationView<TRole, TPayload> | null> {
310
+ const raw = await ctx.runQuery(this.component.queries.getByToken, { token });
311
+ return raw === null ? null : this.view(raw);
312
+ }
313
+
314
+ /**
315
+ * Page the still-`pending` invitations for one `resourceRef`, oldest first.
316
+ * Returns the standard Convex pagination envelope with each row narrowed to
317
+ * the typed view.
318
+ */
319
+ async listPending(
320
+ ctx: RunQueryCtx,
321
+ resourceRef: string,
322
+ paginationOpts: PaginationOptions,
323
+ ): Promise<PaginationResult<InvitationView<TRole, TPayload>>> {
324
+ const result = await ctx.runQuery(this.component.queries.listPending, {
325
+ resourceRef,
326
+ paginationOpts,
327
+ });
328
+ return { ...result, page: result.page.map((raw) => this.view(raw)) };
329
+ }
330
+
331
+ /**
332
+ * Page invitations for one `resourceRef` in a given `state`, oldest first —
333
+ * for an accepted/revoked/expired audit surface. Returns the standard Convex
334
+ * pagination envelope with each row narrowed to the typed view.
335
+ */
336
+ async listByResourceState(
337
+ ctx: RunQueryCtx,
338
+ resourceRef: string,
339
+ state: InvitationState,
340
+ paginationOpts: PaginationOptions,
341
+ ): Promise<PaginationResult<InvitationView<TRole, TPayload>>> {
342
+ const result = await ctx.runQuery(
343
+ this.component.queries.listByResourceState,
344
+ { resourceRef, state, paginationOpts },
345
+ );
346
+ return { ...result, page: result.page.map((raw) => this.view(raw)) };
347
+ }
348
+ }
349
+
350
+ export type {
351
+ InvitationGrant,
352
+ InvitationState,
353
+ InvitationView,
354
+ InvitationsOptions,
355
+ IssueOptions,
356
+ Parser,
357
+ };
@@ -0,0 +1,98 @@
1
+ /** Public TypeScript surface for the invitations client. */
2
+
3
+ /** The four lifecycle states an invitation moves through. */
4
+ export type InvitationState = "pending" | "accepted" | "revoked" | "expired";
5
+
6
+ /**
7
+ * Validates and narrows an opaque stored value to a host type `T` at the client
8
+ * boundary. Receives the raw value the component returned (`unknown`) and MUST
9
+ * return a typed `T` or throw. A `convex/values` validator's `.parse` (or a Zod
10
+ * `.parse`) fits directly; omit it to keep the value unvalidated.
11
+ *
12
+ * @typeParam T - The host's stored type (invitation `role` or `payload`).
13
+ */
14
+ export type Parser<T> = (value: unknown) => T;
15
+
16
+ /** The public view of one invitation returned by {@link Invitations.getByToken}. */
17
+ export interface InvitationView<TRole = unknown, TPayload = unknown> {
18
+ /** The single-use secret naming this invitation. */
19
+ token: string;
20
+ /** The opaque host resource the invite grants access to (an org/team/workspace). */
21
+ resourceRef: string;
22
+ /** The opaque host role to grant on accept (narrowed if a `roleValidator` is set). */
23
+ role?: TRole;
24
+ /** The opaque host subject who issued the invite. */
25
+ inviterRef?: string;
26
+ /** The opaque host subject the invite is addressed to (open link when omitted). */
27
+ inviteeRef?: string;
28
+ /** Arbitrary opaque host data carried through to accept (narrowed if a `payloadValidator` is set). */
29
+ payload?: TPayload;
30
+ /** The current lifecycle state. */
31
+ state: InvitationState;
32
+ /** Absolute ms timestamp the invite was issued. */
33
+ createdAt: number;
34
+ /** Absolute ms timestamp the invite stops being acceptable. */
35
+ expiresAt: number;
36
+ /** Absolute ms timestamp of acceptance, present once `accepted`. */
37
+ acceptedAt?: number;
38
+ /** The opaque host subject who accepted, present once `accepted`. */
39
+ acceptedBy?: string;
40
+ /** Absolute ms timestamp of revocation, present once `revoked`. */
41
+ revokedAt?: number;
42
+ }
43
+
44
+ /**
45
+ * The grant {@link Invitations.accept} returns — what the host applies (writes a
46
+ * membership, grants a role) once an invite is consumed. `role`/`payload` are
47
+ * narrowed by the host validators when set.
48
+ */
49
+ export interface InvitationGrant<TRole = unknown, TPayload = unknown> {
50
+ /** The opaque host resource the accepted invite grants access to. */
51
+ resourceRef: string;
52
+ /** The opaque host role to grant (narrowed if a `roleValidator` is set). */
53
+ role?: TRole;
54
+ /** Arbitrary opaque host data carried from `issue` (narrowed if a `payloadValidator` is set). */
55
+ payload?: TPayload;
56
+ }
57
+
58
+ /** Per-call options for {@link Invitations.issue}. */
59
+ export interface IssueOptions<TRole, TPayload> {
60
+ /** The opaque host role to grant on accept (validated against `roleValidator` before storage). */
61
+ role?: TRole;
62
+ /** The opaque host subject issuing the invite. */
63
+ inviterRef?: string;
64
+ /** The opaque host subject the invite is addressed to; omit for an open link. */
65
+ inviteeRef?: string;
66
+ /** Arbitrary opaque host data carried through to accept (validated against `payloadValidator`). */
67
+ payload?: TPayload;
68
+ /** Override the client's default TTL for this invite (ms from issue). Ignored when `expiresAt` is set. */
69
+ ttlMs?: number;
70
+ /** An absolute expiry (ms epoch). Takes precedence over `ttlMs` and the default TTL. */
71
+ expiresAt?: number;
72
+ }
73
+
74
+ /** Construction options for the {@link Invitations} client. */
75
+ export interface InvitationsOptions<TRole, TPayload> {
76
+ /**
77
+ * Default time-to-live (ms from issue) applied when an `issue` call passes
78
+ * neither `ttlMs` nor an absolute `expiresAt`. Defaults to 7 days.
79
+ */
80
+ ttlMs?: number;
81
+ /**
82
+ * Mints the single-use token for a new invite. Defaults to `crypto.randomUUID`.
83
+ * Supply a host generator for a different shape (a longer secret, a prefix).
84
+ */
85
+ generateToken?: () => string;
86
+ /**
87
+ * Validates/narrows a stored `role` to `TRole` at the boundary — applied to the
88
+ * `role` passed into `issue` (before storage) and the `role` returned by
89
+ * `getByToken`/`accept`. Throws on a mismatch. Omit to leave roles unvalidated.
90
+ */
91
+ roleValidator?: Parser<TRole>;
92
+ /**
93
+ * Validates/narrows a stored `payload` to `TPayload` at the boundary — applied
94
+ * to the `payload` passed into `issue` and returned by `getByToken`/`accept`.
95
+ * Throws on a mismatch. Omit to leave payloads unvalidated.
96
+ */
97
+ payloadValidator?: Parser<TPayload>;
98
+ }
@@ -0,0 +1,56 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as crons from "../crons.js";
12
+ import type * as mutations from "../mutations.js";
13
+ import type * as queries from "../queries.js";
14
+ import type * as validators from "../validators.js";
15
+
16
+ import type {
17
+ ApiFromModules,
18
+ FilterApi,
19
+ FunctionReference,
20
+ } from "convex/server";
21
+ import { anyApi, componentsGeneric } from "convex/server";
22
+
23
+ const fullApi: ApiFromModules<{
24
+ crons: typeof crons;
25
+ mutations: typeof mutations;
26
+ queries: typeof queries;
27
+ validators: typeof validators;
28
+ }> = anyApi as any;
29
+
30
+ /**
31
+ * A utility for referencing Convex functions in your app's public API.
32
+ *
33
+ * Usage:
34
+ * ```js
35
+ * const myFunctionReference = api.myModule.myFunction;
36
+ * ```
37
+ */
38
+ export const api: FilterApi<
39
+ typeof fullApi,
40
+ FunctionReference<any, "public">
41
+ > = anyApi as any;
42
+
43
+ /**
44
+ * A utility for referencing Convex functions in your app's internal API.
45
+ *
46
+ * Usage:
47
+ * ```js
48
+ * const myFunctionReference = internal.myModule.myFunction;
49
+ * ```
50
+ */
51
+ export const internal: FilterApi<
52
+ typeof fullApi,
53
+ FunctionReference<any, "internal">
54
+ > = anyApi as any;
55
+
56
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,179 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `ComponentApi` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { FunctionReference } from "convex/server";
12
+
13
+ /**
14
+ * A utility for referencing a Convex component's exposed API.
15
+ *
16
+ * Useful when expecting a parameter like `components.myComponent`.
17
+ * Usage:
18
+ * ```ts
19
+ * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
20
+ * return ctx.runQuery(component.someFile.someQuery, { ...args });
21
+ * }
22
+ * ```
23
+ */
24
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
25
+ {
26
+ mutations: {
27
+ accept: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ { acceptedBy: string; token: string },
31
+ { payload?: any; resourceRef: string; role?: any },
32
+ Name
33
+ >;
34
+ issue: FunctionReference<
35
+ "mutation",
36
+ "internal",
37
+ {
38
+ expiresAt: number;
39
+ inviteeRef?: string;
40
+ inviterRef?: string;
41
+ payload?: any;
42
+ resourceRef: string;
43
+ role?: any;
44
+ token: string;
45
+ },
46
+ { expiresAt: number; token: string },
47
+ Name
48
+ >;
49
+ peek: FunctionReference<
50
+ "mutation",
51
+ "internal",
52
+ { token: string },
53
+ null | {
54
+ acceptedAt?: number;
55
+ acceptedBy?: string;
56
+ createdAt: number;
57
+ expiresAt: number;
58
+ inviteeRef?: string;
59
+ inviterRef?: string;
60
+ payload?: any;
61
+ resourceRef: string;
62
+ revokedAt?: number;
63
+ role?: any;
64
+ state: "pending" | "accepted" | "revoked" | "expired";
65
+ token: string;
66
+ },
67
+ Name
68
+ >;
69
+ prune: FunctionReference<
70
+ "mutation",
71
+ "internal",
72
+ { batch: number; before?: number; retentionBefore?: number },
73
+ number,
74
+ Name
75
+ >;
76
+ revoke: FunctionReference<
77
+ "mutation",
78
+ "internal",
79
+ { token: string },
80
+ null,
81
+ Name
82
+ >;
83
+ };
84
+ queries: {
85
+ getByToken: FunctionReference<
86
+ "query",
87
+ "internal",
88
+ { token: string },
89
+ null | {
90
+ acceptedAt?: number;
91
+ acceptedBy?: string;
92
+ createdAt: number;
93
+ expiresAt: number;
94
+ inviteeRef?: string;
95
+ inviterRef?: string;
96
+ payload?: any;
97
+ resourceRef: string;
98
+ revokedAt?: number;
99
+ role?: any;
100
+ state: "pending" | "accepted" | "revoked" | "expired";
101
+ token: string;
102
+ },
103
+ Name
104
+ >;
105
+ listByResourceState: FunctionReference<
106
+ "query",
107
+ "internal",
108
+ {
109
+ paginationOpts: {
110
+ cursor: string | null;
111
+ endCursor?: string | null;
112
+ id?: number;
113
+ maximumBytesRead?: number;
114
+ maximumRowsRead?: number;
115
+ numItems: number;
116
+ };
117
+ resourceRef: string;
118
+ state: "pending" | "accepted" | "revoked" | "expired";
119
+ },
120
+ {
121
+ continueCursor: string;
122
+ isDone: boolean;
123
+ page: Array<{
124
+ acceptedAt?: number;
125
+ acceptedBy?: string;
126
+ createdAt: number;
127
+ expiresAt: number;
128
+ inviteeRef?: string;
129
+ inviterRef?: string;
130
+ payload?: any;
131
+ resourceRef: string;
132
+ revokedAt?: number;
133
+ role?: any;
134
+ state: "pending" | "accepted" | "revoked" | "expired";
135
+ token: string;
136
+ }>;
137
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
138
+ splitCursor?: string | null;
139
+ },
140
+ Name
141
+ >;
142
+ listPending: FunctionReference<
143
+ "query",
144
+ "internal",
145
+ {
146
+ paginationOpts: {
147
+ cursor: string | null;
148
+ endCursor?: string | null;
149
+ id?: number;
150
+ maximumBytesRead?: number;
151
+ maximumRowsRead?: number;
152
+ numItems: number;
153
+ };
154
+ resourceRef: string;
155
+ },
156
+ {
157
+ continueCursor: string;
158
+ isDone: boolean;
159
+ page: Array<{
160
+ acceptedAt?: number;
161
+ acceptedBy?: string;
162
+ createdAt: number;
163
+ expiresAt: number;
164
+ inviteeRef?: string;
165
+ inviterRef?: string;
166
+ payload?: any;
167
+ resourceRef: string;
168
+ revokedAt?: number;
169
+ role?: any;
170
+ state: "pending" | "accepted" | "revoked" | "expired";
171
+ token: string;
172
+ }>;
173
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
174
+ splitCursor?: string | null;
175
+ },
176
+ Name
177
+ >;
178
+ };
179
+ };