@feltdb/feltkit 0.3.16 → 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.
- package/dist/app.d.ts +222 -5
- package/dist/app.js +178 -3
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +57 -0
- package/dist/appboundry/build.js +54 -2
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +73 -1
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +15 -0
- package/dist/appboundry/host.js +45 -1
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.d.ts +3 -2
- package/dist/authorize.js +5 -3
- package/dist/authorize.js.map +1 -1
- package/dist/cli/deploy-appboundry-self-hosted.d.ts +2 -0
- package/dist/cli/deploy-appboundry-self-hosted.js +1 -1
- package/dist/cli/deploy-appboundry-self-hosted.js.map +1 -1
- package/dist/cli/deploy-appboundry.js +3 -0
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/main.js +6 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +242 -5
- package/dist/client/index.js +413 -29
- package/dist/client/index.js.map +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -0
- package/dist/docs.js.map +1 -1
- package/dist/event-stage.d.ts +13 -0
- package/dist/event-stage.js +15 -0
- package/dist/event-stage.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js.map +1 -1
- package/dist/react/auth.d.ts +131 -0
- package/dist/react/auth.js +830 -0
- package/dist/react/auth.js.map +1 -0
- package/dist/react/context.d.ts +8 -0
- package/dist/react/context.js +14 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/index.d.ts +17 -18
- package/dist/react/index.js +21 -13
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/accounts.d.ts +33 -2
- package/dist/runtime/accounts.js +167 -27
- package/dist/runtime/accounts.js.map +1 -1
- package/dist/runtime/authority.d.ts +9 -1
- package/dist/runtime/authority.js +14 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/challenges.d.ts +51 -0
- package/dist/runtime/challenges.js +121 -0
- package/dist/runtime/challenges.js.map +1 -0
- package/dist/runtime/changes.d.ts +22 -0
- package/dist/runtime/changes.js +51 -3
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/content.d.ts +32 -0
- package/dist/runtime/content.js +42 -1
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +50 -0
- package/dist/runtime/contract.js +14 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/data.d.ts +36 -2
- package/dist/runtime/data.js +56 -17
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/events.d.ts +21 -0
- package/dist/runtime/events.js +65 -0
- package/dist/runtime/events.js.map +1 -0
- package/dist/runtime/live.d.ts +48 -0
- package/dist/runtime/live.js +154 -0
- package/dist/runtime/live.js.map +1 -0
- package/dist/runtime/outbox.js +3 -0
- package/dist/runtime/outbox.js.map +1 -1
- package/dist/runtime/runtime.d.ts +70 -5
- package/dist/runtime/runtime.js +307 -36
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/search.d.ts +54 -0
- package/dist/runtime/search.js +66 -0
- package/dist/runtime/search.js.map +1 -0
- package/dist/runtime/services.d.ts +45 -0
- package/dist/runtime/services.js +90 -0
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.d.ts +16 -2
- package/dist/runtime/sessions.js +40 -4
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +189 -0
- package/dist/runtime/tenancy.js +376 -0
- package/dist/runtime/tenancy.js.map +1 -0
- package/dist/runtime/tenant-scope.d.ts +9 -0
- package/dist/runtime/tenant-scope.js +127 -0
- package/dist/runtime/tenant-scope.js.map +1 -0
- package/dist/runtime/transactions.d.ts +45 -2
- package/dist/runtime/transactions.js +36 -9
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/schema.d.ts +2 -1
- package/dist/schema.js +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/server/http.d.ts +1 -0
- package/dist/server/http.js +14 -0
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +325 -59
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.js +6 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/session-http.d.ts +48 -0
- package/dist/server/session-http.js +116 -0
- package/dist/server/session-http.js.map +1 -0
- package/dist/server/tenancy.d.ts +40 -0
- package/dist/server/tenancy.js +191 -0
- package/dist/server/tenancy.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +7 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +1 -0
- package/docs/APPBOUNDRY.md +11 -1
- package/docs/ARCHITECTURE.md +4 -2
- package/docs/AUTH.md +262 -0
- package/docs/GUARANTEES.md +58 -4
- package/docs/README.md +3 -2
- package/docs/SECURITY.md +3 -2
- package/docs/TRANSACTIONS.md +98 -1
- package/docs/UPSTREAM-GAPS.md +3 -0
- package/package.json +11 -9
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-data/SKILL.md +6 -0
- package/dist/runtime/account-links.d.ts +0 -19
- package/dist/runtime/account-links.js +0 -45
- package/dist/runtime/account-links.js.map +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenancy (`feltkit({ auth: { tenant } })`): tenants, memberships, invitations, and the tenant a
|
|
3
|
+
* session is working in. One authorization model: a membership's role is one of the app's declared
|
|
4
|
+
* `roles`, and in a session working in that tenant the principal holds it, beside the roles its
|
|
5
|
+
* account (or session) already has. So what a role may do is decided where it always is: `roles`,
|
|
6
|
+
* `access`, and the app's `authorize` hook. Tenancy adds which tenant, never a second policy.
|
|
7
|
+
*
|
|
8
|
+
* tenant `_feltkit_tenants`
|
|
9
|
+
* membership `_feltkit_memberships`, one per tenant and principal (id derived from both)
|
|
10
|
+
* invitation `_feltkit_invitations`, keyed by the digest of its token; the token is
|
|
11
|
+
* HMAC(FELTKIT_AUTH_SECRET, nonce), computed when the invitation is sent or shown to
|
|
12
|
+
* the inviter, never stored
|
|
13
|
+
*
|
|
14
|
+
* Roles are ranked by their order in `auth.tenant.roles` (first = highest). Managing members needs
|
|
15
|
+
* the permission `tenant.members.manage` (granted by your `roles`); a manager assigns and changes
|
|
16
|
+
* only roles below their own, and only the top role assigns the top role. A tenant always keeps one
|
|
17
|
+
* holder of the top role. Nobody changes their own role except to step down from the top while
|
|
18
|
+
* another holder remains.
|
|
19
|
+
*/
|
|
20
|
+
import type { StateFirstDB } from "@feltdb/core";
|
|
21
|
+
import type { Schema } from "@appport/sdk";
|
|
22
|
+
import type { Principal } from "./authority.js";
|
|
23
|
+
export declare const TENANTS_COLLECTION = "_feltkit_tenants";
|
|
24
|
+
export declare const MEMBERSHIPS_COLLECTION = "_feltkit_memberships";
|
|
25
|
+
export declare const INVITATIONS_COLLECTION = "_feltkit_invitations";
|
|
26
|
+
export declare const MANAGE_MEMBERS = "tenant.members.manage";
|
|
27
|
+
export declare const UPDATE_TENANT = "tenant.update";
|
|
28
|
+
/** The tenant a call works in, as the server resolved it from the session and the live membership. */
|
|
29
|
+
export interface TenantContext<Claims extends Record<string, unknown> = Record<string, unknown>> {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly role: string;
|
|
33
|
+
/** The membership's typed claims (`auth.tenant.claims`), plus `role`. Never read from a request. */
|
|
34
|
+
readonly claims: Readonly<Claims & {
|
|
35
|
+
role: string;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export interface TenantConfig {
|
|
39
|
+
roles: readonly string[];
|
|
40
|
+
claims?: Record<string, Schema>;
|
|
41
|
+
create?: "anyone" | "none";
|
|
42
|
+
invitations?: boolean | {
|
|
43
|
+
ttlMs?: number;
|
|
44
|
+
};
|
|
45
|
+
switching?: boolean;
|
|
46
|
+
name?: string;
|
|
47
|
+
}
|
|
48
|
+
interface TenantRecord {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
createdBy: string;
|
|
52
|
+
createdAt: string;
|
|
53
|
+
updatedAt: string;
|
|
54
|
+
__version?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface Membership {
|
|
57
|
+
tenantId: string;
|
|
58
|
+
principalId: string;
|
|
59
|
+
principalType: string;
|
|
60
|
+
role: string;
|
|
61
|
+
claims: Record<string, unknown>;
|
|
62
|
+
status: "active" | "removed";
|
|
63
|
+
displayName?: string;
|
|
64
|
+
email?: string;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
}
|
|
68
|
+
export interface InvitationView {
|
|
69
|
+
id: string;
|
|
70
|
+
email: string;
|
|
71
|
+
role: string;
|
|
72
|
+
status: "open" | "accepted" | "revoked" | "expired";
|
|
73
|
+
invitedBy: string;
|
|
74
|
+
inviterName?: string;
|
|
75
|
+
createdAt: string;
|
|
76
|
+
expiresAt: string;
|
|
77
|
+
acceptedBy?: string;
|
|
78
|
+
}
|
|
79
|
+
export declare class TenancyStore {
|
|
80
|
+
#private;
|
|
81
|
+
readonly config: TenantConfig;
|
|
82
|
+
constructor(db: StateFirstDB, config: TenantConfig, secret: () => string);
|
|
83
|
+
/**
|
|
84
|
+
* Called after a membership (or tenant) changes, with the tenant and the principal it concerns
|
|
85
|
+
* ("*": every member, e.g. a rename). The server tells only that tenant's subscribers and that
|
|
86
|
+
* principal, never anyone else, so a change in one tenant is not visible from another.
|
|
87
|
+
*/
|
|
88
|
+
onChange(listener: (tenantId: string, principalId: string) => void): () => void;
|
|
89
|
+
get roles(): readonly string[];
|
|
90
|
+
get top(): string;
|
|
91
|
+
/** Higher is more authority. Unknown roles rank below every declared one. */
|
|
92
|
+
rank(role: string): number;
|
|
93
|
+
tenant(id: string): Promise<TenantRecord | null>;
|
|
94
|
+
/** The principal's active membership in a tenant, or null. */
|
|
95
|
+
membership(tenantId: string, principalId: string): Promise<Membership | null>;
|
|
96
|
+
/** The tenant context for a principal in a tenant, from the live membership. Null: not (or no longer) a member. */
|
|
97
|
+
context(tenantId: string | undefined, principalId: string): Promise<TenantContext | null>;
|
|
98
|
+
/** The tenants a principal belongs to, most recently used first. */
|
|
99
|
+
tenantsFor(principalId: string): Promise<Array<{
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
role: string;
|
|
103
|
+
lastUsedAt?: string;
|
|
104
|
+
}>>;
|
|
105
|
+
/** Record that a principal switched to a tenant (it becomes their default at the next sign-in). */
|
|
106
|
+
touch(tenantId: string, principalId: string): Promise<void>;
|
|
107
|
+
/** Create a tenant; its creator becomes its first holder of the top role. */
|
|
108
|
+
create(name: unknown, creator: Principal & {
|
|
109
|
+
email?: string;
|
|
110
|
+
}): Promise<TenantRecord>;
|
|
111
|
+
rename(actor: TenantContext, name: unknown): Promise<TenantRecord>;
|
|
112
|
+
/** The tenant's active members. */
|
|
113
|
+
members(tenantId: string): Promise<Membership[]>;
|
|
114
|
+
/** Whether `actorRole` may give someone `role`. */
|
|
115
|
+
canAssign(actorRole: string, role: string): boolean;
|
|
116
|
+
/** Whether `actorRole` may change or remove someone who holds `memberRole`. */
|
|
117
|
+
canManage(actorRole: string, memberRole: string): boolean;
|
|
118
|
+
/** Change a member's role. `actor` already holds tenant.members.manage in this tenant (checked by the caller). */
|
|
119
|
+
setRole(actor: TenantContext & {
|
|
120
|
+
principalId: string;
|
|
121
|
+
}, principalId: string, role: unknown): Promise<Membership>;
|
|
122
|
+
/**
|
|
123
|
+
* Add a non-person principal (an agent or a service, whose identity an operator issued) to the
|
|
124
|
+
* tenant with a role the actor may assign. People join only by invitation (their consent); the
|
|
125
|
+
* caller checks that `principal` is an agent or service identity that exists.
|
|
126
|
+
*/
|
|
127
|
+
addPrincipal(actor: TenantContext & {
|
|
128
|
+
principalId: string;
|
|
129
|
+
}, principal: {
|
|
130
|
+
id: string;
|
|
131
|
+
type: string;
|
|
132
|
+
displayName?: string;
|
|
133
|
+
}, role: unknown): Promise<Membership>;
|
|
134
|
+
/** Set a member's typed claims (`auth.tenant.claims`). Validated; `role` is not a claim you set here. */
|
|
135
|
+
setClaims(actor: TenantContext & {
|
|
136
|
+
principalId: string;
|
|
137
|
+
}, principalId: string, claims: unknown): Promise<Membership>;
|
|
138
|
+
/** Validate claims against `auth.tenant.claims`; unknown names and `role` are refused. */
|
|
139
|
+
validateClaims(input: unknown, base?: Record<string, unknown>): Record<string, unknown>;
|
|
140
|
+
/** Remove a member (or yourself: leave). The last holder of the top role can do neither. */
|
|
141
|
+
remove(actor: TenantContext & {
|
|
142
|
+
principalId: string;
|
|
143
|
+
}, principalId: string): Promise<void>;
|
|
144
|
+
get invitationTtlMs(): number;
|
|
145
|
+
/** Invite an address with a role (and claims). Returns the invitation and its token (for the link). */
|
|
146
|
+
invite(actor: TenantContext & {
|
|
147
|
+
principalId: string;
|
|
148
|
+
displayName?: string;
|
|
149
|
+
}, input: {
|
|
150
|
+
email: string;
|
|
151
|
+
role: unknown;
|
|
152
|
+
claims?: unknown;
|
|
153
|
+
}): Promise<{
|
|
154
|
+
invitation: InvitationView;
|
|
155
|
+
token: string;
|
|
156
|
+
}>;
|
|
157
|
+
/** The token for a live invitation (to deliver it); null once accepted, revoked or expired. */
|
|
158
|
+
tokenFor(invitationId: string): Promise<{
|
|
159
|
+
token: string;
|
|
160
|
+
invitation: InvitationView;
|
|
161
|
+
tenantName: string;
|
|
162
|
+
} | null>;
|
|
163
|
+
/** What an invitation link shows before it is accepted: workspace, role, inviter, status. Only for its holder. */
|
|
164
|
+
preview(token: unknown): Promise<{
|
|
165
|
+
tenantName: string;
|
|
166
|
+
role: string;
|
|
167
|
+
inviterName?: string;
|
|
168
|
+
email: string;
|
|
169
|
+
status: InvitationView["status"];
|
|
170
|
+
expiresAt: string;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Accept an invitation as `principal`, whose verified address must be the one invited
|
|
174
|
+
* (`allowAnyAddress` only for development identities). Single use: concurrent acceptances
|
|
175
|
+
* cannot both win. An existing member keeps the higher of their role and the invited one.
|
|
176
|
+
*/
|
|
177
|
+
accept(token: unknown, principal: Principal & {
|
|
178
|
+
email?: string;
|
|
179
|
+
emailVerified?: boolean;
|
|
180
|
+
}, options?: {
|
|
181
|
+
allowAnyAddress?: boolean;
|
|
182
|
+
}): Promise<{
|
|
183
|
+
tenantId: string;
|
|
184
|
+
membership: Membership;
|
|
185
|
+
}>;
|
|
186
|
+
invitations(tenantId: string): Promise<InvitationView[]>;
|
|
187
|
+
revokeInvitation(actor: TenantContext, invitationId: unknown): Promise<void>;
|
|
188
|
+
}
|
|
189
|
+
export {};
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { FeltKitError } from "../errors.js";
|
|
3
|
+
import { readAll } from "./data.js";
|
|
4
|
+
export const TENANTS_COLLECTION = "_feltkit_tenants";
|
|
5
|
+
export const MEMBERSHIPS_COLLECTION = "_feltkit_memberships";
|
|
6
|
+
export const INVITATIONS_COLLECTION = "_feltkit_invitations";
|
|
7
|
+
export const MANAGE_MEMBERS = "tenant.members.manage";
|
|
8
|
+
export const UPDATE_TENANT = "tenant.update";
|
|
9
|
+
const INVITE_PREFIX = "fki_";
|
|
10
|
+
const sha = (value) => createHash("sha256").update(value).digest("hex");
|
|
11
|
+
const membershipId = (tenantId, principalId) => `mbr_${sha(`${tenantId}\n${principalId}`).slice(0, 40)}`;
|
|
12
|
+
const strip = (record) => {
|
|
13
|
+
const copy = { ...record };
|
|
14
|
+
delete copy.__version;
|
|
15
|
+
return copy;
|
|
16
|
+
};
|
|
17
|
+
const membershipView = (r) => {
|
|
18
|
+
const { id: _id, lastUsedAt: _last, invitedBy: _by, ...rest } = strip(r);
|
|
19
|
+
return rest;
|
|
20
|
+
};
|
|
21
|
+
export class TenancyStore {
|
|
22
|
+
#db;
|
|
23
|
+
config;
|
|
24
|
+
#secret;
|
|
25
|
+
#listeners = new Set();
|
|
26
|
+
constructor(db, config, secret) {
|
|
27
|
+
this.#db = db;
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.#secret = secret;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Called after a membership (or tenant) changes, with the tenant and the principal it concerns
|
|
33
|
+
* ("*": every member, e.g. a rename). The server tells only that tenant's subscribers and that
|
|
34
|
+
* principal, never anyone else, so a change in one tenant is not visible from another.
|
|
35
|
+
*/
|
|
36
|
+
onChange(listener) {
|
|
37
|
+
this.#listeners.add(listener);
|
|
38
|
+
return () => void this.#listeners.delete(listener);
|
|
39
|
+
}
|
|
40
|
+
#changed(tenantId, principalId) {
|
|
41
|
+
for (const listener of [...this.#listeners]) {
|
|
42
|
+
try {
|
|
43
|
+
listener(tenantId, principalId);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* a listener's failure is its own */
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
get roles() {
|
|
51
|
+
return this.config.roles;
|
|
52
|
+
}
|
|
53
|
+
get top() {
|
|
54
|
+
return this.config.roles[0];
|
|
55
|
+
}
|
|
56
|
+
/** Higher is more authority. Unknown roles rank below every declared one. */
|
|
57
|
+
rank(role) {
|
|
58
|
+
const index = this.config.roles.indexOf(role);
|
|
59
|
+
return index < 0 ? -1 : this.config.roles.length - index;
|
|
60
|
+
}
|
|
61
|
+
#write(operations) {
|
|
62
|
+
return this.#db.transaction({ operations: operations });
|
|
63
|
+
}
|
|
64
|
+
async tenant(id) {
|
|
65
|
+
if (typeof id !== "string" || !id.startsWith("tnt_"))
|
|
66
|
+
return null;
|
|
67
|
+
return (await this.#db.collection(TENANTS_COLLECTION).get(id)) ?? null;
|
|
68
|
+
}
|
|
69
|
+
async #membership(tenantId, principalId) {
|
|
70
|
+
return (await this.#db.collection(MEMBERSHIPS_COLLECTION).get(membershipId(tenantId, principalId))) ?? null;
|
|
71
|
+
}
|
|
72
|
+
/** The principal's active membership in a tenant, or null. */
|
|
73
|
+
async membership(tenantId, principalId) {
|
|
74
|
+
const record = await this.#membership(tenantId, principalId);
|
|
75
|
+
return record && record.status === "active" ? membershipView(record) : null;
|
|
76
|
+
}
|
|
77
|
+
/** The tenant context for a principal in a tenant, from the live membership. Null: not (or no longer) a member. */
|
|
78
|
+
async context(tenantId, principalId) {
|
|
79
|
+
if (!tenantId)
|
|
80
|
+
return null;
|
|
81
|
+
const [tenant, membership] = await Promise.all([this.tenant(tenantId), this.#membership(tenantId, principalId)]);
|
|
82
|
+
if (!tenant || !membership || membership.status !== "active" || this.rank(membership.role) < 0)
|
|
83
|
+
return null;
|
|
84
|
+
return Object.freeze({ id: tenant.id, name: tenant.name, role: membership.role, claims: Object.freeze({ ...membership.claims, role: membership.role }) });
|
|
85
|
+
}
|
|
86
|
+
/** The tenants a principal belongs to, most recently used first. */
|
|
87
|
+
async tenantsFor(principalId) {
|
|
88
|
+
const memberships = (await readAll(this.#db, { collection: MEMBERSHIPS_COLLECTION, where: [{ field: "principalId", eq: principalId }] })).filter((m) => m.status === "active");
|
|
89
|
+
const out = [];
|
|
90
|
+
for (const m of memberships) {
|
|
91
|
+
const tenant = await this.tenant(m.tenantId);
|
|
92
|
+
if (tenant)
|
|
93
|
+
out.push({ id: tenant.id, name: tenant.name, role: m.role, ...(m.lastUsedAt ? { lastUsedAt: m.lastUsedAt } : {}) });
|
|
94
|
+
}
|
|
95
|
+
return out.sort((a, b) => (b.lastUsedAt ?? "").localeCompare(a.lastUsedAt ?? "") || a.name.localeCompare(b.name));
|
|
96
|
+
}
|
|
97
|
+
/** Record that a principal switched to a tenant (it becomes their default at the next sign-in). */
|
|
98
|
+
async touch(tenantId, principalId) {
|
|
99
|
+
const record = await this.#membership(tenantId, principalId);
|
|
100
|
+
if (!record || record.status !== "active")
|
|
101
|
+
return;
|
|
102
|
+
await this.#write([{ collection: MEMBERSHIPS_COLLECTION, id: record.id, ifVersion: record.__version, value: { ...strip(record), lastUsedAt: new Date().toISOString() } }]).catch(() => undefined);
|
|
103
|
+
}
|
|
104
|
+
/** Create a tenant; its creator becomes its first holder of the top role. */
|
|
105
|
+
async create(name, creator) {
|
|
106
|
+
if (this.config.create === "none")
|
|
107
|
+
throw new FeltKitError("FORBIDDEN", `Creating a ${this.config.name ?? "workspace"} is not open to users in this app.`);
|
|
108
|
+
const clean = typeof name === "string" ? name.trim().slice(0, 80) : "";
|
|
109
|
+
if (!clean)
|
|
110
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Give the ${this.config.name ?? "workspace"} a name.`);
|
|
111
|
+
const now = new Date().toISOString();
|
|
112
|
+
const tenant = { id: `tnt_${randomBytes(12).toString("hex")}`, name: clean, createdBy: creator.id, createdAt: now, updatedAt: now };
|
|
113
|
+
const membership = {
|
|
114
|
+
id: membershipId(tenant.id, creator.id), tenantId: tenant.id, principalId: creator.id, principalType: creator.type, role: this.top, claims: {}, status: "active",
|
|
115
|
+
...(creator.displayName ? { displayName: creator.displayName } : {}), ...(creator.email ? { email: creator.email } : {}), createdAt: now, updatedAt: now, lastUsedAt: now,
|
|
116
|
+
};
|
|
117
|
+
await this.#write([
|
|
118
|
+
{ collection: TENANTS_COLLECTION, id: tenant.id, requireAbsent: true, value: tenant },
|
|
119
|
+
{ collection: MEMBERSHIPS_COLLECTION, id: membership.id, requireAbsent: true, value: membership },
|
|
120
|
+
]);
|
|
121
|
+
this.#changed(tenant.id, creator.id);
|
|
122
|
+
return tenant;
|
|
123
|
+
}
|
|
124
|
+
async rename(actor, name) {
|
|
125
|
+
const tenant = await this.tenant(actor.id);
|
|
126
|
+
if (!tenant)
|
|
127
|
+
throw new FeltKitError("NOT_FOUND", "No such workspace.");
|
|
128
|
+
const clean = typeof name === "string" ? name.trim().slice(0, 80) : "";
|
|
129
|
+
if (!clean)
|
|
130
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Give it a name.");
|
|
131
|
+
const next = { ...strip(tenant), name: clean, updatedAt: new Date().toISOString() };
|
|
132
|
+
await this.#write([{ collection: TENANTS_COLLECTION, id: tenant.id, ifVersion: tenant.__version, value: next }]);
|
|
133
|
+
this.#changed(tenant.id, "*");
|
|
134
|
+
return next;
|
|
135
|
+
}
|
|
136
|
+
/** The tenant's active members. */
|
|
137
|
+
async members(tenantId) {
|
|
138
|
+
const all = (await readAll(this.#db, { collection: MEMBERSHIPS_COLLECTION, where: [{ field: "tenantId", eq: tenantId }] }));
|
|
139
|
+
return all.filter((m) => m.status === "active").map(membershipView).sort((a, b) => this.rank(b.role) - this.rank(a.role) || (a.displayName ?? a.principalId).localeCompare(b.displayName ?? b.principalId));
|
|
140
|
+
}
|
|
141
|
+
async #owners(tenantId) {
|
|
142
|
+
return (await this.members(tenantId)).filter((m) => m.role === this.top).length;
|
|
143
|
+
}
|
|
144
|
+
/** Whether `actorRole` may give someone `role`. */
|
|
145
|
+
canAssign(actorRole, role) {
|
|
146
|
+
if (this.rank(role) < 0)
|
|
147
|
+
return false;
|
|
148
|
+
if (actorRole === this.top)
|
|
149
|
+
return true;
|
|
150
|
+
return role !== this.top && this.rank(role) < this.rank(actorRole);
|
|
151
|
+
}
|
|
152
|
+
/** Whether `actorRole` may change or remove someone who holds `memberRole`. */
|
|
153
|
+
canManage(actorRole, memberRole) {
|
|
154
|
+
return actorRole === this.top || this.rank(memberRole) < this.rank(actorRole);
|
|
155
|
+
}
|
|
156
|
+
/** Change a member's role. `actor` already holds tenant.members.manage in this tenant (checked by the caller). */
|
|
157
|
+
async setRole(actor, principalId, role) {
|
|
158
|
+
if (typeof role !== "string" || this.rank(role) < 0)
|
|
159
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Unknown role. Roles: ${this.roles.join(", ")}.`);
|
|
160
|
+
const record = await this.#membership(actor.id, principalId);
|
|
161
|
+
if (!record || record.status !== "active")
|
|
162
|
+
throw new FeltKitError("NOT_FOUND", "Not a member of this workspace.");
|
|
163
|
+
if (principalId === actor.principalId) {
|
|
164
|
+
// Only stepping down from the top role, and only while another holder remains.
|
|
165
|
+
if (!(record.role === this.top && role !== this.top))
|
|
166
|
+
throw new FeltKitError("FORBIDDEN", "You cannot change your own role.");
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (!this.canManage(actor.role, record.role))
|
|
170
|
+
throw new FeltKitError("FORBIDDEN", `Only a higher role can change a ${record.role}'s role.`);
|
|
171
|
+
if (!this.canAssign(actor.role, role))
|
|
172
|
+
throw new FeltKitError("FORBIDDEN", `You cannot give the ${role} role.`);
|
|
173
|
+
}
|
|
174
|
+
if (record.role === this.top && role !== this.top && (await this.#owners(actor.id)) <= 1) {
|
|
175
|
+
throw new FeltKitError("FAILED_PRECONDITION", `A workspace needs at least one ${this.top}. Make someone else ${this.top} first.`);
|
|
176
|
+
}
|
|
177
|
+
const next = { ...strip(record), role, updatedAt: new Date().toISOString() };
|
|
178
|
+
await this.#write([{ collection: MEMBERSHIPS_COLLECTION, id: record.id, ifVersion: record.__version, value: next }]);
|
|
179
|
+
this.#changed(actor.id, principalId);
|
|
180
|
+
return membershipView(next);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Add a non-person principal (an agent or a service, whose identity an operator issued) to the
|
|
184
|
+
* tenant with a role the actor may assign. People join only by invitation (their consent); the
|
|
185
|
+
* caller checks that `principal` is an agent or service identity that exists.
|
|
186
|
+
*/
|
|
187
|
+
async addPrincipal(actor, principal, role) {
|
|
188
|
+
if (principal.type !== "agent" && principal.type !== "service")
|
|
189
|
+
throw new FeltKitError("FORBIDDEN", "Only agents and services are added directly; people join by invitation.");
|
|
190
|
+
if (typeof role !== "string" || this.rank(role) < 0)
|
|
191
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Unknown role. Roles: ${this.roles.join(", ")}.`);
|
|
192
|
+
if (!this.canAssign(actor.role, role))
|
|
193
|
+
throw new FeltKitError("FORBIDDEN", `You cannot give the ${role} role.`);
|
|
194
|
+
const existing = await this.#membership(actor.id, principal.id);
|
|
195
|
+
if (existing && existing.status === "active")
|
|
196
|
+
throw new FeltKitError("CONFLICT", "Already a member.");
|
|
197
|
+
const now = new Date().toISOString();
|
|
198
|
+
const membership = {
|
|
199
|
+
id: membershipId(actor.id, principal.id), tenantId: actor.id, principalId: principal.id, principalType: principal.type, role, claims: {}, status: "active",
|
|
200
|
+
...(principal.displayName ? { displayName: principal.displayName } : {}), invitedBy: actor.principalId, createdAt: existing?.createdAt ?? now, updatedAt: now,
|
|
201
|
+
};
|
|
202
|
+
await this.#write([
|
|
203
|
+
existing
|
|
204
|
+
? { collection: MEMBERSHIPS_COLLECTION, id: membership.id, ifVersion: existing.__version, value: membership }
|
|
205
|
+
: { collection: MEMBERSHIPS_COLLECTION, id: membership.id, requireAbsent: true, value: membership },
|
|
206
|
+
]);
|
|
207
|
+
this.#changed(actor.id, principal.id);
|
|
208
|
+
return membershipView(membership);
|
|
209
|
+
}
|
|
210
|
+
/** Set a member's typed claims (`auth.tenant.claims`). Validated; `role` is not a claim you set here. */
|
|
211
|
+
async setClaims(actor, principalId, claims) {
|
|
212
|
+
const record = await this.#membership(actor.id, principalId);
|
|
213
|
+
if (!record || record.status !== "active")
|
|
214
|
+
throw new FeltKitError("NOT_FOUND", "Not a member of this workspace.");
|
|
215
|
+
if (principalId !== actor.principalId && !this.canManage(actor.role, record.role))
|
|
216
|
+
throw new FeltKitError("FORBIDDEN", `Only a higher role can change a ${record.role}'s claims.`);
|
|
217
|
+
const next = { ...strip(record), claims: this.validateClaims(claims, record.claims), updatedAt: new Date().toISOString() };
|
|
218
|
+
await this.#write([{ collection: MEMBERSHIPS_COLLECTION, id: record.id, ifVersion: record.__version, value: next }]);
|
|
219
|
+
this.#changed(actor.id, principalId);
|
|
220
|
+
return membershipView(next);
|
|
221
|
+
}
|
|
222
|
+
/** Validate claims against `auth.tenant.claims`; unknown names and `role` are refused. */
|
|
223
|
+
validateClaims(input, base = {}) {
|
|
224
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
225
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Claims are an object.");
|
|
226
|
+
const schemas = this.config.claims ?? {};
|
|
227
|
+
const out = { ...base };
|
|
228
|
+
for (const [name, value] of Object.entries(input)) {
|
|
229
|
+
if (name === "role")
|
|
230
|
+
throw new FeltKitError("INVALID_ARGUMENT", "role is set with the member's role, not as a claim.");
|
|
231
|
+
const schema = schemas[name];
|
|
232
|
+
if (!schema)
|
|
233
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Unknown claim "${name}". Declared claims: ${Object.keys(schemas).join(", ") || "(none)"}.`);
|
|
234
|
+
const result = schema.validate(value);
|
|
235
|
+
if (!result.ok)
|
|
236
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Claim "${name}": ${result.issues?.[0]?.message ?? "invalid"}.`);
|
|
237
|
+
if (value === undefined)
|
|
238
|
+
delete out[name];
|
|
239
|
+
else
|
|
240
|
+
out[name] = "value" in result ? result.value : value;
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
/** Remove a member (or yourself: leave). The last holder of the top role can do neither. */
|
|
245
|
+
async remove(actor, principalId) {
|
|
246
|
+
const record = await this.#membership(actor.id, principalId);
|
|
247
|
+
if (!record || record.status !== "active")
|
|
248
|
+
throw new FeltKitError("NOT_FOUND", "Not a member of this workspace.");
|
|
249
|
+
if (principalId !== actor.principalId && !this.canManage(actor.role, record.role))
|
|
250
|
+
throw new FeltKitError("FORBIDDEN", `Only a higher role can remove a ${record.role}.`);
|
|
251
|
+
if (record.role === this.top && (await this.#owners(actor.id)) <= 1) {
|
|
252
|
+
throw new FeltKitError("FAILED_PRECONDITION", `A workspace needs at least one ${this.top}. Make someone else ${this.top} first.`);
|
|
253
|
+
}
|
|
254
|
+
const next = { ...strip(record), status: "removed", updatedAt: new Date().toISOString() };
|
|
255
|
+
await this.#write([{ collection: MEMBERSHIPS_COLLECTION, id: record.id, ifVersion: record.__version, value: next }]);
|
|
256
|
+
this.#changed(actor.id, principalId);
|
|
257
|
+
}
|
|
258
|
+
// ── Invitations ──────────────────────────────────────────────────────────────
|
|
259
|
+
get invitationTtlMs() {
|
|
260
|
+
const option = this.config.invitations;
|
|
261
|
+
return typeof option === "object" && option.ttlMs ? Math.min(option.ttlMs, 30 * 24 * 3_600_000) : 7 * 24 * 3_600_000;
|
|
262
|
+
}
|
|
263
|
+
#token(nonce) {
|
|
264
|
+
return INVITE_PREFIX + createHmac("sha256", this.#secret()).update(`feltkit.invitation.v1\n${nonce}`).digest("base64url");
|
|
265
|
+
}
|
|
266
|
+
/** Invite an address with a role (and claims). Returns the invitation and its token (for the link). */
|
|
267
|
+
async invite(actor, input) {
|
|
268
|
+
if (this.config.invitations === false)
|
|
269
|
+
throw new FeltKitError("NOT_FOUND", "Invitations are not enabled for this app.");
|
|
270
|
+
if (typeof input.role !== "string" || this.rank(input.role) < 0)
|
|
271
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Unknown role. Roles: ${this.roles.join(", ")}.`);
|
|
272
|
+
if (!this.canAssign(actor.role, input.role))
|
|
273
|
+
throw new FeltKitError("FORBIDDEN", `You cannot invite someone as ${input.role}.`);
|
|
274
|
+
const claims = input.claims === undefined ? {} : this.validateClaims(input.claims);
|
|
275
|
+
const nonce = randomBytes(32).toString("base64url");
|
|
276
|
+
const token = this.#token(nonce);
|
|
277
|
+
const now = Date.now();
|
|
278
|
+
const record = {
|
|
279
|
+
id: sha(token), tenantId: actor.id, email: input.email, role: input.role, claims, nonce, invitedBy: actor.principalId,
|
|
280
|
+
...(actor.displayName ? { inviterName: actor.displayName } : {}), createdAt: new Date(now).toISOString(), expiresAt: now + this.invitationTtlMs, status: "open",
|
|
281
|
+
};
|
|
282
|
+
await this.#write([{ collection: INVITATIONS_COLLECTION, id: record.id, requireAbsent: true, value: record }]);
|
|
283
|
+
return { invitation: this.#invitationView(record), token };
|
|
284
|
+
}
|
|
285
|
+
/** The token for a live invitation (to deliver it); null once accepted, revoked or expired. */
|
|
286
|
+
async tokenFor(invitationId) {
|
|
287
|
+
const record = (await this.#db.collection(INVITATIONS_COLLECTION).get(invitationId)) ?? null;
|
|
288
|
+
if (!record || record.status !== "open" || record.expiresAt <= Date.now())
|
|
289
|
+
return null;
|
|
290
|
+
const tenant = await this.tenant(record.tenantId);
|
|
291
|
+
return tenant ? { token: this.#token(record.nonce), invitation: this.#invitationView(record), tenantName: tenant.name } : null;
|
|
292
|
+
}
|
|
293
|
+
#invitationView(r) {
|
|
294
|
+
return {
|
|
295
|
+
id: r.id, email: r.email, role: r.role, status: r.status === "open" && r.expiresAt <= Date.now() ? "expired" : r.status, invitedBy: r.invitedBy,
|
|
296
|
+
...(r.inviterName ? { inviterName: r.inviterName } : {}), createdAt: r.createdAt, expiresAt: new Date(r.expiresAt).toISOString(), ...(r.acceptedBy ? { acceptedBy: r.acceptedBy } : {}),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async #byToken(token) {
|
|
300
|
+
if (typeof token !== "string" || !token.startsWith(INVITE_PREFIX) || token.length > 100)
|
|
301
|
+
return null;
|
|
302
|
+
return (await this.#db.collection(INVITATIONS_COLLECTION).get(sha(token))) ?? null;
|
|
303
|
+
}
|
|
304
|
+
/** What an invitation link shows before it is accepted: workspace, role, inviter, status. Only for its holder. */
|
|
305
|
+
async preview(token) {
|
|
306
|
+
const record = await this.#byToken(token);
|
|
307
|
+
const tenant = record ? await this.tenant(record.tenantId) : null;
|
|
308
|
+
if (!record || !tenant)
|
|
309
|
+
throw new FeltKitError("NOT_FOUND", "This invitation link is not valid.", { hint: "INVITATION_INVALID" });
|
|
310
|
+
const view = this.#invitationView(record);
|
|
311
|
+
return { tenantName: tenant.name, role: record.role, ...(record.inviterName ? { inviterName: record.inviterName } : {}), email: record.email, status: view.status, expiresAt: view.expiresAt };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Accept an invitation as `principal`, whose verified address must be the one invited
|
|
315
|
+
* (`allowAnyAddress` only for development identities). Single use: concurrent acceptances
|
|
316
|
+
* cannot both win. An existing member keeps the higher of their role and the invited one.
|
|
317
|
+
*/
|
|
318
|
+
async accept(token, principal, options = {}) {
|
|
319
|
+
const record = await this.#byToken(token);
|
|
320
|
+
if (!record)
|
|
321
|
+
throw new FeltKitError("NOT_FOUND", "This invitation link is not valid.", { hint: "INVITATION_INVALID" });
|
|
322
|
+
if (record.status === "revoked")
|
|
323
|
+
throw new FeltKitError("FAILED_PRECONDITION", "This invitation was withdrawn. Ask for a new one.", { hint: "INVITATION_REVOKED" });
|
|
324
|
+
if (record.status === "accepted") {
|
|
325
|
+
if (record.acceptedBy === principal.id) {
|
|
326
|
+
const existing = await this.membership(record.tenantId, principal.id);
|
|
327
|
+
if (existing)
|
|
328
|
+
return { tenantId: record.tenantId, membership: existing };
|
|
329
|
+
}
|
|
330
|
+
throw new FeltKitError("FAILED_PRECONDITION", "This invitation was already used.", { hint: "INVITATION_ACCEPTED" });
|
|
331
|
+
}
|
|
332
|
+
if (record.expiresAt <= Date.now())
|
|
333
|
+
throw new FeltKitError("FAILED_PRECONDITION", "This invitation has expired. Ask for a new one.", { hint: "INVITATION_EXPIRED" });
|
|
334
|
+
if (!options.allowAnyAddress && !(principal.email === record.email && principal.emailVerified)) {
|
|
335
|
+
throw new FeltKitError("FORBIDDEN", "This invitation is for a different e-mail address. Sign in with the invited address (verify it first if needed).", { hint: "INVITATION_WRONG_ACCOUNT" });
|
|
336
|
+
}
|
|
337
|
+
const now = new Date().toISOString();
|
|
338
|
+
const existing = await this.#membership(record.tenantId, principal.id);
|
|
339
|
+
const keepRole = existing && existing.status === "active" && this.rank(existing.role) >= this.rank(record.role);
|
|
340
|
+
const membership = {
|
|
341
|
+
id: membershipId(record.tenantId, principal.id), tenantId: record.tenantId, principalId: principal.id, principalType: principal.type,
|
|
342
|
+
role: keepRole ? existing.role : record.role, claims: { ...(existing?.status === "active" ? existing.claims : {}), ...record.claims }, status: "active",
|
|
343
|
+
...(principal.displayName ? { displayName: principal.displayName } : {}), ...(principal.email ? { email: principal.email } : {}),
|
|
344
|
+
invitedBy: record.invitedBy, createdAt: existing?.createdAt ?? now, updatedAt: now, lastUsedAt: now,
|
|
345
|
+
};
|
|
346
|
+
const accepted = { ...strip(record), status: "accepted", acceptedBy: principal.id, acceptedAt: now };
|
|
347
|
+
try {
|
|
348
|
+
await this.#write([
|
|
349
|
+
{ collection: INVITATIONS_COLLECTION, id: record.id, ifVersion: record.__version, value: accepted },
|
|
350
|
+
existing
|
|
351
|
+
? { collection: MEMBERSHIPS_COLLECTION, id: membership.id, ifVersion: existing.__version, value: membership }
|
|
352
|
+
: { collection: MEMBERSHIPS_COLLECTION, id: membership.id, requireAbsent: true, value: membership },
|
|
353
|
+
]);
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
throw new FeltKitError("FAILED_PRECONDITION", "This invitation was already used.", { hint: "INVITATION_ACCEPTED" });
|
|
357
|
+
}
|
|
358
|
+
this.#changed(record.tenantId, principal.id);
|
|
359
|
+
return { tenantId: record.tenantId, membership: membershipView(membership) };
|
|
360
|
+
}
|
|
361
|
+
async invitations(tenantId) {
|
|
362
|
+
const all = (await readAll(this.#db, { collection: INVITATIONS_COLLECTION, where: [{ field: "tenantId", eq: tenantId }] }));
|
|
363
|
+
return all.map((r) => this.#invitationView(r)).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
364
|
+
}
|
|
365
|
+
async revokeInvitation(actor, invitationId) {
|
|
366
|
+
const record = typeof invitationId === "string" ? ((await this.#db.collection(INVITATIONS_COLLECTION).get(invitationId)) ?? null) : null;
|
|
367
|
+
if (!record || record.tenantId !== actor.id)
|
|
368
|
+
throw new FeltKitError("NOT_FOUND", "No such invitation.");
|
|
369
|
+
if (record.status !== "open")
|
|
370
|
+
throw new FeltKitError("FAILED_PRECONDITION", `This invitation is already ${record.status}.`);
|
|
371
|
+
if (!this.canAssign(actor.role, record.role))
|
|
372
|
+
throw new FeltKitError("FORBIDDEN", `You cannot withdraw an invitation as ${record.role}.`);
|
|
373
|
+
await this.#write([{ collection: INVITATIONS_COLLECTION, id: record.id, ifVersion: record.__version, value: { ...strip(record), status: "revoked" } }]);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
//# sourceMappingURL=tenancy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenancy.js","sourceRoot":"","sources":["../../src/runtime/tenancy.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,MAAM,aAAa,GAAG,MAAM,CAAC;AAwF7B,MAAM,GAAG,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChF,MAAM,YAAY,GAAG,CAAC,QAAgB,EAAE,WAAmB,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,GAAG,QAAQ,KAAK,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACzH,MAAM,KAAK,GAAG,CAAmC,MAAS,EAAwB,EAAE;IAClF,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC3B,OAAO,IAAI,CAAC,SAAS,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CAAC,qBAAqB,EAAE,8BAA8B,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5H,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,wCAAwC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QAC1I,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1J,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CollectionDefinition } from "../app.js";
|
|
2
|
+
import type { DatabaseReader } from "./data.js";
|
|
3
|
+
type Ref = Parameters<DatabaseReader["get"]>[0];
|
|
4
|
+
type Resolve = (ref: Ref) => CollectionDefinition;
|
|
5
|
+
/** Wrap a reader (or writer) so tenant-scoped collections only ever see `tenantId`'s records. */
|
|
6
|
+
export declare function scopeToTenant<D extends DatabaseReader>(inner: D, resolve: Resolve, tenantId: string | null): D;
|
|
7
|
+
/** Whether any collection of the app is tenant-scoped (so the scope wrapper is needed at all). */
|
|
8
|
+
export declare function hasTenantCollections(collections: Iterable<CollectionDefinition>): boolean;
|
|
9
|
+
export {};
|