@feltdb/feltkit 0.3.17 → 0.3.18

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 (107) hide show
  1. package/dist/app.d.ts +195 -5
  2. package/dist/app.js +150 -3
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.d.ts +45 -0
  5. package/dist/appboundry/build.js +52 -1
  6. package/dist/appboundry/build.js.map +1 -1
  7. package/dist/appboundry/guest.js +39 -1
  8. package/dist/appboundry/guest.js.map +1 -1
  9. package/dist/appboundry/host.js +4 -0
  10. package/dist/appboundry/host.js.map +1 -1
  11. package/dist/authorize.js +1 -0
  12. package/dist/authorize.js.map +1 -1
  13. package/dist/cli/deploy-appboundry-self-hosted.d.ts +2 -0
  14. package/dist/cli/deploy-appboundry-self-hosted.js +1 -1
  15. package/dist/cli/deploy-appboundry-self-hosted.js.map +1 -1
  16. package/dist/cli/deploy-appboundry.js +3 -0
  17. package/dist/cli/deploy-appboundry.js.map +1 -1
  18. package/dist/cli/main.js +6 -1
  19. package/dist/cli/main.js.map +1 -1
  20. package/dist/client/index.d.ts +192 -5
  21. package/dist/client/index.js +301 -28
  22. package/dist/client/index.js.map +1 -1
  23. package/dist/docs.d.ts +1 -1
  24. package/dist/docs.js +1 -0
  25. package/dist/docs.js.map +1 -1
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js.map +1 -1
  28. package/dist/react/auth.d.ts +131 -0
  29. package/dist/react/auth.js +830 -0
  30. package/dist/react/auth.js.map +1 -0
  31. package/dist/react/context.d.ts +8 -0
  32. package/dist/react/context.js +14 -0
  33. package/dist/react/context.js.map +1 -0
  34. package/dist/react/index.d.ts +3 -18
  35. package/dist/react/index.js +5 -13
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/runtime/accounts.d.ts +33 -2
  38. package/dist/runtime/accounts.js +167 -27
  39. package/dist/runtime/accounts.js.map +1 -1
  40. package/dist/runtime/authority.d.ts +8 -1
  41. package/dist/runtime/authority.js +11 -2
  42. package/dist/runtime/authority.js.map +1 -1
  43. package/dist/runtime/challenges.d.ts +51 -0
  44. package/dist/runtime/challenges.js +121 -0
  45. package/dist/runtime/challenges.js.map +1 -0
  46. package/dist/runtime/changes.d.ts +22 -0
  47. package/dist/runtime/changes.js +51 -3
  48. package/dist/runtime/changes.js.map +1 -1
  49. package/dist/runtime/context.d.ts +41 -0
  50. package/dist/runtime/contract.js +14 -3
  51. package/dist/runtime/contract.js.map +1 -1
  52. package/dist/runtime/data.d.ts +36 -2
  53. package/dist/runtime/data.js +56 -17
  54. package/dist/runtime/data.js.map +1 -1
  55. package/dist/runtime/live.d.ts +48 -0
  56. package/dist/runtime/live.js +154 -0
  57. package/dist/runtime/live.js.map +1 -0
  58. package/dist/runtime/outbox.js +3 -0
  59. package/dist/runtime/outbox.js.map +1 -1
  60. package/dist/runtime/runtime.d.ts +70 -5
  61. package/dist/runtime/runtime.js +290 -35
  62. package/dist/runtime/runtime.js.map +1 -1
  63. package/dist/runtime/search.d.ts +54 -0
  64. package/dist/runtime/search.js +66 -0
  65. package/dist/runtime/search.js.map +1 -0
  66. package/dist/runtime/sessions.d.ts +16 -2
  67. package/dist/runtime/sessions.js +40 -4
  68. package/dist/runtime/sessions.js.map +1 -1
  69. package/dist/runtime/tenancy.d.ts +189 -0
  70. package/dist/runtime/tenancy.js +376 -0
  71. package/dist/runtime/tenancy.js.map +1 -0
  72. package/dist/runtime/tenant-scope.d.ts +9 -0
  73. package/dist/runtime/tenant-scope.js +127 -0
  74. package/dist/runtime/tenant-scope.js.map +1 -0
  75. package/dist/runtime/transactions.d.ts +45 -2
  76. package/dist/runtime/transactions.js +36 -9
  77. package/dist/runtime/transactions.js.map +1 -1
  78. package/dist/server/index.d.ts +2 -1
  79. package/dist/server/index.js +300 -58
  80. package/dist/server/index.js.map +1 -1
  81. package/dist/server/mcp.js +6 -3
  82. package/dist/server/mcp.js.map +1 -1
  83. package/dist/server/session-http.d.ts +48 -0
  84. package/dist/server/session-http.js +116 -0
  85. package/dist/server/session-http.js.map +1 -0
  86. package/dist/server/tenancy.d.ts +40 -0
  87. package/dist/server/tenancy.js +191 -0
  88. package/dist/server/tenancy.js.map +1 -0
  89. package/dist/testing/index.d.ts +7 -0
  90. package/dist/testing/index.js +7 -2
  91. package/dist/testing/index.js.map +1 -1
  92. package/docs/AGENT-OPERATIONS.md +1 -0
  93. package/docs/APPBOUNDRY.md +11 -1
  94. package/docs/ARCHITECTURE.md +4 -2
  95. package/docs/AUTH.md +262 -0
  96. package/docs/GUARANTEES.md +50 -3
  97. package/docs/README.md +3 -2
  98. package/docs/SECURITY.md +3 -2
  99. package/docs/TRANSACTIONS.md +98 -1
  100. package/docs/UPSTREAM-GAPS.md +2 -0
  101. package/package.json +11 -10
  102. package/skills/.claude-plugin/marketplace.json +1 -1
  103. package/skills/.claude-plugin/plugin.json +1 -1
  104. package/skills/feltkit-data/SKILL.md +6 -0
  105. package/dist/runtime/account-links.d.ts +0 -19
  106. package/dist/runtime/account-links.js +0 -45
  107. package/dist/runtime/account-links.js.map +0 -1
@@ -9,10 +9,14 @@
9
9
  * import type * as tasks from "../tasks.js";
10
10
  * export const api = createApi<{ tasks: typeof tasks }>();
11
11
  *
12
- * Reactivity: the server returns the collections each query read. The client keeps
13
- * one change stream open and re-runs a watched query when a collection it read
14
- * changes. The stream only says *which collections changed*; the re-run goes through
15
- * the normal authorized query endpoint.
12
+ * Reactivity: the server returns the collections each query read, and for a collection read
13
+ * only through equality predicates (`get` by id, `find({ channelId })`, …) an opaque key per
14
+ * predicate (`"messages#<key>"`). The client keeps one change stream open; each change names the
15
+ * collections that changed and, when the server could describe them record by record, the opaque
16
+ * keys of the changed records' keyed values, before and after. A watched query re-runs when a
17
+ * collection it read wholly changed, or when a change's keys meet its predicates (a change
18
+ * without keys re-runs every query that read the collection). Keys are server-side HMACs: the
19
+ * client only compares them. The re-run goes through the normal authorized query endpoint.
16
20
  */
17
21
  export interface FunctionReference<Kind extends "query" | "mutation" = "query" | "mutation", Args = any, Result = any> {
18
22
  readonly name: string;
@@ -85,6 +89,8 @@ export interface SessionInfo {
85
89
  */
86
90
  accounts?: {
87
91
  signUp: boolean;
92
+ password?: boolean;
93
+ magicLink?: boolean;
88
94
  email?: boolean;
89
95
  verify?: "required" | "optional" | null;
90
96
  providers?: Array<{
@@ -97,11 +103,33 @@ export interface SessionInfo {
97
103
  email: string;
98
104
  emailVerified: boolean;
99
105
  hasPassword: boolean;
106
+ providers?: string[];
107
+ } | null;
108
+ /** How this session is held: "cookie" (browser), "bearer", or null when signed out. */
109
+ transport?: "cookie" | "bearer" | null;
110
+ /** The tenant this session works in (`auth.tenant`), or null. */
111
+ tenant?: TenantInfo | null;
112
+ /** The app's tenancy, or null when it has none: what it calls a tenant, and its roles (highest first). */
113
+ tenancy?: {
114
+ name: string;
115
+ roles: string[];
100
116
  } | null;
101
117
  }
102
118
  /** What a link back into the app carried (`client.handleRedirect()`). */
103
119
  export type AuthRedirect = {
104
120
  kind: "signed-in";
121
+ } | {
122
+ kind: "magic-link-failed";
123
+ message: string;
124
+ } | {
125
+ kind: "email-changed";
126
+ email: string;
127
+ } | {
128
+ kind: "email-change-failed";
129
+ message: string;
130
+ } | {
131
+ kind: "invitation";
132
+ token: string;
105
133
  } | {
106
134
  kind: "error";
107
135
  message: string;
@@ -115,6 +143,78 @@ export type AuthRedirect = {
115
143
  kind: "verify-failed";
116
144
  message: string;
117
145
  };
146
+ export interface TenantInfo {
147
+ id: string;
148
+ name: string;
149
+ role: string;
150
+ claims?: Record<string, unknown>;
151
+ }
152
+ export interface TenantsInfo {
153
+ tenants: Array<{
154
+ id: string;
155
+ name: string;
156
+ role: string;
157
+ lastUsedAt?: string;
158
+ }>;
159
+ current: TenantInfo | null;
160
+ settings: {
161
+ name: string;
162
+ roles: string[];
163
+ create: "anyone" | "none";
164
+ invitations: boolean;
165
+ switching: boolean;
166
+ can: {
167
+ manageMembers: boolean;
168
+ update: boolean;
169
+ assign: string[];
170
+ } | null;
171
+ };
172
+ }
173
+ export interface TenantMember {
174
+ principalId: string;
175
+ type: string;
176
+ role: string;
177
+ claims: Record<string, unknown>;
178
+ displayName: string;
179
+ email: string | null;
180
+ joinedAt: string;
181
+ you: boolean;
182
+ }
183
+ export interface InvitationInfo {
184
+ id: string;
185
+ email: string;
186
+ role: string;
187
+ status: "open" | "accepted" | "revoked" | "expired";
188
+ invitedBy: string;
189
+ inviterName?: string;
190
+ createdAt: string;
191
+ expiresAt: string;
192
+ acceptedBy?: string;
193
+ }
194
+ export interface InvitationPreview {
195
+ tenantName: string;
196
+ role: string;
197
+ inviterName?: string;
198
+ email: string;
199
+ status: "open" | "accepted" | "revoked" | "expired";
200
+ expiresAt: string;
201
+ }
202
+ export interface AccountInfo {
203
+ email: string;
204
+ name: string | null;
205
+ emailVerified: boolean;
206
+ hasPassword: boolean;
207
+ /** Connected sign-in providers (ids). */
208
+ providers: string[];
209
+ }
210
+ export interface SessionListing {
211
+ ref: string;
212
+ kind: string;
213
+ label?: string;
214
+ createdAt: string;
215
+ expiresAt?: string;
216
+ current: boolean;
217
+ }
118
218
  export interface TokenStore {
119
219
  get(): string | null;
120
220
  set(token: string | null): void;
@@ -123,14 +223,34 @@ export declare function browserTokenStore(key?: string): TokenStore;
123
223
  export interface ClientOptions {
124
224
  /** Origin of the FeltKit server. Defaults to the page's origin. */
125
225
  url?: string;
226
+ /**
227
+ * How this client holds its session.
228
+ * "cookie" (default in a browser) the server keeps it in an HttpOnly cookie; the page never sees
229
+ * the token, and sends a CSRF token the server issues. The app must be same-origin.
230
+ * "bearer" (default elsewhere, and when `tokens` is given) a token sent as Authorization: Bearer,
231
+ * kept by `tokens` (localStorage in a browser: readable by any script on the page).
232
+ */
233
+ session?: "cookie" | "bearer";
126
234
  tokens?: TokenStore;
127
235
  fetch?: typeof fetch;
128
236
  }
129
- type ChangeListener = (collections: string[]) => void;
237
+ /** `keys`: per collection, opaque keys of the changed records (absent: the whole collection may have changed). */
238
+ type ChangeListener = (collections: string[], keys?: Record<string, string[]>) => void;
239
+ /** A query's read set: collections read wholly, and opaque predicate keys by collection. */
240
+ export interface LiveReads {
241
+ collections: Set<string>;
242
+ predicates: Map<string, Set<string>>;
243
+ }
244
+ /** Parse a query result's `reads` (names, then `collection#key` entries). */
245
+ export declare function parseReads(reads: readonly string[]): LiveReads;
246
+ /** Whether a change can affect a query that read `reads`. When in doubt: yes. */
247
+ export declare function changeAffects(reads: LiveReads, collections: readonly string[], keys?: Record<string, string[]>): boolean;
130
248
  export declare class FeltKitClient {
131
249
  #private;
132
250
  readonly url: string;
133
251
  readonly tokens: TokenStore;
252
+ /** "cookie" or "bearer": see ClientOptions.session. */
253
+ readonly mode: "cookie" | "bearer";
134
254
  constructor(options?: ClientOptions);
135
255
  get connected(): boolean;
136
256
  /** The absolute URL of a file link (`ctx.services.files.link`), for `<a href>` or `<img src>`. */
@@ -189,6 +309,73 @@ export declare class FeltKitClient {
189
309
  verifyEmail(token: string): Promise<{
190
310
  email: string;
191
311
  }>;
312
+ /** Your account: address, verification, name, whether a password is set, connected providers. */
313
+ account(): Promise<AccountInfo>;
314
+ updateProfile(input: {
315
+ name: string;
316
+ }): Promise<void>;
317
+ /** Change your password. Every other session ends; this one continues with a new token. */
318
+ changePassword(input: {
319
+ current?: string;
320
+ password: string;
321
+ }): Promise<void>;
322
+ /** Ask to move your account to a new address: it changes when the link sent there is opened. */
323
+ requestEmailChange(email: string): Promise<{
324
+ message: string;
325
+ }>;
326
+ /** Confirm a new address with the token from its link (handleRedirect does this for you). */
327
+ confirmEmailChange(token: string): Promise<{
328
+ email: string;
329
+ }>;
330
+ unlinkProvider(provider: string): Promise<void>;
331
+ /** Your active sessions. `current` is this one. */
332
+ sessions(): Promise<SessionListing[]>;
333
+ /** End one of your sessions by ref. Ending this one signs you out. */
334
+ revokeSession(ref: string): Promise<void>;
335
+ /** End your other sessions (`keepCurrent`, the default), or all of them (and sign out here). */
336
+ signOutEverywhere(options?: {
337
+ keepCurrent?: boolean;
338
+ }): Promise<number>;
339
+ /** Your tenants, the one this session works in, and what you may do there. */
340
+ tenants(): Promise<TenantsInfo>;
341
+ /** Create a tenant (you hold its top role) and switch to it. */
342
+ createTenant(name: string): Promise<TenantInfo>;
343
+ /** Work in another of your tenants (null: none). Every live query re-runs for it. */
344
+ switchTenant(tenantId: string | null): Promise<TenantInfo | null>;
345
+ members(): Promise<TenantMember[]>;
346
+ setMemberRole(principalId: string, role: string): Promise<void>;
347
+ /** Add an agent or service (an operator-issued identity) to the current tenant. People are invited instead. */
348
+ addMember(principalId: string, role: string): Promise<void>;
349
+ setMemberClaims(principalId: string, claims: Record<string, unknown>): Promise<void>;
350
+ removeMember(principalId: string): Promise<void>;
351
+ /** Leave the current tenant; the session moves to your next one (or none). */
352
+ leaveTenant(): Promise<TenantInfo | null>;
353
+ renameTenant(name: string): Promise<void>;
354
+ invitations(): Promise<InvitationInfo[]>;
355
+ /** Invite an address with a role. `link` is the invitation link (to share yourself); `sent` says whether it was e-mailed. */
356
+ invite(input: {
357
+ email: string;
358
+ role: string;
359
+ claims?: Record<string, unknown>;
360
+ send?: boolean;
361
+ }): Promise<{
362
+ invitation: InvitationInfo;
363
+ link: string;
364
+ sent: boolean;
365
+ }>;
366
+ revokeInvitation(id: string): Promise<void>;
367
+ /** What an invitation link is for, before accepting it (no sign-in needed). */
368
+ previewInvitation(token: string): Promise<InvitationPreview>;
369
+ /** Accept an invitation (signed in with the invited address) and switch to its tenant. */
370
+ acceptInvitation(token: string): Promise<TenantInfo | null>;
371
+ /** Magic link: e-mail a sign-in link and code to this address (same answer whether or not it can sign in). */
372
+ requestMagicLink(email: string): Promise<{
373
+ message: string;
374
+ }>;
375
+ /** Magic link: sign in with the 8-digit code from the e-mail (typed on another device than the one that opened it). */
376
+ signInWithCode(email: string, code: string): Promise<SessionInfo["principal"]>;
377
+ /** Magic link: sign in with the token from the link (handleRedirect does this for you). */
378
+ signInWithLink(token: string): Promise<SessionInfo["principal"]>;
192
379
  /** Sign in with a provider from `session().accounts.providers`: leaves the page for its consent screen. */
193
380
  signInWith(provider: string, returnPath?: string): void;
194
381
  /**