@protobase/server 0.7.0 → 0.8.1
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/assistant/conversations.d.ts +1 -1
- package/dist/assistant/tools.d.ts +1 -1
- package/dist/assistant/turn.d.ts +2 -2
- package/dist/audit/origin.js +12 -0
- package/dist/auth/jwt.d.ts +2 -0
- package/dist/auth/jwt.js +5 -3
- package/dist/batch/reorder.js +1 -1
- package/dist/batch/run-batch.js +2 -1
- package/dist/better-auth/authenticator.d.ts +7 -3
- package/dist/better-auth/authenticator.js +24 -3
- package/dist/better-auth/create-auth.d.ts +619 -81
- package/dist/better-auth/create-auth.js +64 -27
- package/dist/better-auth/organizations/accept-invitation.js +80 -0
- package/dist/better-auth/organizations/active-organization.js +12 -0
- package/dist/better-auth/organizations/admin-routes.js +83 -0
- package/dist/better-auth/organizations/app-roles.js +43 -0
- package/dist/better-auth/organizations/host.d.ts +53 -0
- package/dist/better-auth/organizations/host.js +251 -0
- package/dist/better-auth/organizations/invitation-endpoints.js +133 -0
- package/dist/better-auth/organizations/invitation-mail.js +17 -0
- package/dist/better-auth/organizations/invitation-token.js +27 -0
- package/dist/better-auth/organizations/member-endpoints.js +182 -0
- package/dist/better-auth/organizations/options.d.ts +48 -0
- package/dist/better-auth/organizations/options.js +23 -0
- package/dist/better-auth/organizations/organization-plugin.js +128 -0
- package/dist/better-auth/organizations/protobase-plugin.js +21 -0
- package/dist/better-auth/organizations/role-definitions.d.ts +15 -0
- package/dist/better-auth/organizations/role-definitions.js +56 -0
- package/dist/better-auth/organizations/session-organization.js +68 -0
- package/dist/better-auth/organizations/store.d.ts +19 -0
- package/dist/better-auth/organizations/store.js +73 -0
- package/dist/better-auth/staff-checks.js +5 -1
- package/dist/better-auth/staff-sign-in-endpoints.js +1 -1
- package/dist/better-auth/status-route.js +14 -3
- package/dist/better-auth/users.d.ts +2 -1
- package/dist/better-auth/users.js +4 -1
- package/dist/changes/actor.js +12 -0
- package/dist/changes/capture-plan.js +62 -0
- package/dist/changes/capture-schema.d.ts +18 -0
- package/dist/changes/capture-schema.js +65 -0
- package/dist/changes/capture-sql.js +108 -0
- package/dist/changes/coalesce.d.ts +38 -0
- package/dist/changes/coalesce.js +69 -0
- package/dist/changes/events-options.d.ts +10 -0
- package/dist/changes/events-options.js +10 -0
- package/dist/changes/match-events.d.ts +9 -0
- package/dist/changes/match-events.js +55 -0
- package/dist/changes/resource-change.d.ts +27 -0
- package/dist/changes/resource-change.js +43 -0
- package/dist/create-admin.d.ts +11 -2
- package/dist/create-admin.js +33 -2
- package/dist/deps.d.ts +1 -0
- package/dist/files/attach.js +80 -0
- package/dist/files/cleanup-runner.d.ts +8 -0
- package/dist/files/cleanup-runner.js +58 -0
- package/dist/files/cleanup-schedule.d.ts +28 -0
- package/dist/files/cleanup-schedule.js +48 -0
- package/dist/files/detect.js +51 -0
- package/dist/files/download-url.js +43 -0
- package/dist/files/download.js +90 -0
- package/dist/files/duration.js +35 -0
- package/dist/files/file-cleanup.d.ts +18 -0
- package/dist/files/file-cleanup.js +17 -0
- package/dist/files/local-files.d.ts +17 -0
- package/dist/files/local-files.js +101 -0
- package/dist/files/media-types.js +99 -0
- package/dist/files/options.d.ts +15 -0
- package/dist/files/present.d.ts +15 -0
- package/dist/files/present.js +59 -0
- package/dist/files/processors.d.ts +15 -0
- package/dist/files/processors.js +39 -0
- package/dist/files/providers.js +70 -0
- package/dist/files/routes.js +26 -0
- package/dist/files/runtime.d.ts +3 -0
- package/dist/files/runtime.js +37 -0
- package/dist/files/signer.js +32 -0
- package/dist/files/store.d.ts +37 -0
- package/dist/files/ticket.js +87 -0
- package/dist/files/upload-body.js +85 -0
- package/dist/files/upload.js +124 -0
- package/dist/files/uri.js +47 -0
- package/dist/functions/define-function.d.ts +71 -0
- package/dist/functions/define-function.js +36 -0
- package/dist/functions/function-app.d.ts +17 -0
- package/dist/functions/function-app.js +19 -0
- package/dist/functions/read-json.d.ts +35 -0
- package/dist/functions/read-json.js +24 -0
- package/dist/functions/records.d.ts +43 -0
- package/dist/functions/records.js +31 -0
- package/dist/functions/require-env.d.ts +7 -0
- package/dist/functions/require-env.js +12 -0
- package/dist/functions/routes.js +60 -0
- package/dist/functions/verify-signature.d.ts +32 -0
- package/dist/functions/verify-signature.js +49 -0
- package/dist/index.d.ts +26 -3
- package/dist/index.js +17 -3
- package/dist/list-service.js +4 -2
- package/dist/openapi/resource-paths.js +78 -1
- package/dist/openapi/schemas.js +28 -3
- package/dist/project-config.d.ts +10 -1
- package/dist/project-config.js +41 -3
- package/dist/read-service.js +5 -1
- package/dist/request-access.d.ts +5 -0
- package/dist/request-access.js +9 -4
- package/dist/resource-source.d.ts +4 -1
- package/dist/routes/batch.js +1 -1
- package/dist/routes/collection.js +3 -1
- package/dist/routes/record.js +2 -5
- package/dist/transactions.js +10 -3
- package/dist/types.d.ts +25 -5
- package/dist/write-pipeline.js +4 -2
- package/dist/write-shared.js +6 -3
- package/dist/write-update.js +2 -1
- package/package.json +6 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChatMessage } from "./chat-completions.js";
|
|
2
1
|
import { Session } from "../types.js";
|
|
2
|
+
import { ChatMessage } from "./chat-completions.js";
|
|
3
3
|
import { ConversationStore } from "./conversation-store.js";
|
|
4
4
|
import { AssistantEvent, AssistantState } from "@protobase/schema";
|
|
5
5
|
//#region src/assistant/conversations.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Session } from "../types.js";
|
|
2
|
+
import { ToolRecords } from "./records.js";
|
|
2
3
|
import { Conversation } from "./conversations.js";
|
|
3
4
|
import { ApprovalAnswer, ApprovalRequest } from "./approval.js";
|
|
4
|
-
import { ToolRecords } from "./records.js";
|
|
5
5
|
import { AssistantPart } from "@protobase/schema";
|
|
6
6
|
//#region src/assistant/tools.d.ts
|
|
7
7
|
export type ToolContext = {
|
package/dist/assistant/turn.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ModelSettings, ReasoningEffort } from "./chat-completions.js";
|
|
2
1
|
import { Session } from "../types.js";
|
|
3
|
-
import { Conversation } from "./conversations.js";
|
|
4
2
|
import { ToolRecords } from "./records.js";
|
|
3
|
+
import { ModelSettings, ReasoningEffort } from "./chat-completions.js";
|
|
4
|
+
import { Conversation } from "./conversations.js";
|
|
5
5
|
import { AssistantTool } from "./tools.js";
|
|
6
6
|
//#region src/assistant/turn.d.ts
|
|
7
7
|
export type TurnOptions = {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/audit/origin.ts
|
|
2
|
+
/** Where a request came from, for an audit event: its user agent and the proxies' `X-Forwarded-For`, when sent. */
|
|
3
|
+
const auditOrigin = (headers) => {
|
|
4
|
+
const userAgent = headers.get("user-agent");
|
|
5
|
+
const forwardedFor = headers.get("x-forwarded-for");
|
|
6
|
+
return {
|
|
7
|
+
...userAgent !== null && { userAgent },
|
|
8
|
+
...forwardedFor !== null && { forwardedFor }
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { auditOrigin };
|
package/dist/auth/jwt.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type JwtOptions = {
|
|
|
9
9
|
audience?: string;
|
|
10
10
|
/** Claim holding the roles, an array, or a string separated by spaces or commas. Default `roles`. */
|
|
11
11
|
rolesClaim?: string;
|
|
12
|
+
/** A second claim whose roles are added to those of `rolesClaim`, such as an organization membership's. */
|
|
13
|
+
extraRolesClaim?: string;
|
|
12
14
|
/** Claim holding the tenant. Default `tenant`. */
|
|
13
15
|
tenantClaim?: string;
|
|
14
16
|
/** Accepted signature algorithms. Default: asymmetric ones only, so a token can never be "verified" with a public key used as an HMAC secret. */
|
package/dist/auth/jwt.js
CHANGED
|
@@ -25,21 +25,23 @@ const jwtAuthenticator = (options) => {
|
|
|
25
25
|
return async (request) => {
|
|
26
26
|
const [scheme, token] = (request.headers.get("authorization") ?? "").split(" ");
|
|
27
27
|
if (scheme?.toLowerCase() !== "bearer" || !token) throw unauthorized("Send a bearer token in the Authorization header");
|
|
28
|
-
const
|
|
28
|
+
const verified = await jwtVerify(token, keys, {
|
|
29
29
|
algorithms: options.algorithms ?? asymmetric,
|
|
30
30
|
...options.issuer && { issuer: options.issuer },
|
|
31
31
|
...options.audience && { audience: options.audience }
|
|
32
32
|
}).catch((error) => {
|
|
33
33
|
if (error instanceof errors.JOSEError) throw unauthorized("The bearer token is invalid or expired");
|
|
34
34
|
throw error;
|
|
35
|
-
})
|
|
35
|
+
});
|
|
36
|
+
const { sub, [tenantClaim]: tenant, [rolesClaim]: roles } = verified.payload;
|
|
37
|
+
const extraRoles = options.extraRolesClaim === void 0 ? [] : rolesOf(verified.payload[options.extraRolesClaim]);
|
|
36
38
|
if (!sub) throw unauthorized("The bearer token has no subject");
|
|
37
39
|
const claimed = typeof tenant === "string" || typeof tenant === "number" ? tenant : void 0;
|
|
38
40
|
const tenantValue = options.tenant === void 0 ? claimed : typeof options.tenant === "function" ? await options.tenant() : options.tenant;
|
|
39
41
|
return {
|
|
40
42
|
user: {
|
|
41
43
|
id: sub,
|
|
42
|
-
roles: rolesOf(roles)
|
|
44
|
+
roles: [.../* @__PURE__ */ new Set([...rolesOf(roles), ...extraRoles])]
|
|
43
45
|
},
|
|
44
46
|
...tenantValue !== void 0 && { tenant: tenantValue }
|
|
45
47
|
};
|
package/dist/batch/reorder.js
CHANGED
|
@@ -71,7 +71,7 @@ const reorderIn = async (trx, deps, access, input) => {
|
|
|
71
71
|
const results = [];
|
|
72
72
|
for (const [i, key] of input.keys.entries()) {
|
|
73
73
|
const plan = plans.get(i);
|
|
74
|
-
results.push(shown(access, plan ? await applyUpdate(trx, deps, access, key, plan) : current[i]));
|
|
74
|
+
results.push(await shown(access, plan ? await applyUpdate(trx, deps, access, key, plan) : current[i]));
|
|
75
75
|
}
|
|
76
76
|
return results;
|
|
77
77
|
};
|
package/dist/batch/run-batch.js
CHANGED
|
@@ -2,6 +2,7 @@ import { HttpProblem, badRequest, notFound } from "../problem.js";
|
|
|
2
2
|
import { problemOf } from "../error-handler.js";
|
|
3
3
|
import { requestAccess } from "../request-access.js";
|
|
4
4
|
import { writeTransaction } from "../transactions.js";
|
|
5
|
+
import { actorSettings } from "../changes/actor.js";
|
|
5
6
|
import { keyOf } from "../write-shared.js";
|
|
6
7
|
import { writeIn } from "../write-pipeline.js";
|
|
7
8
|
import { resolveData, resolveKey } from "./refs.js";
|
|
@@ -99,7 +100,7 @@ const runBatch = async (deps, session, operations) => {
|
|
|
99
100
|
throw atOperation(error, index, operation);
|
|
100
101
|
}
|
|
101
102
|
return results;
|
|
102
|
-
});
|
|
103
|
+
}, actorSettings(deps, session));
|
|
103
104
|
};
|
|
104
105
|
//#endregion
|
|
105
106
|
export { runBatch };
|
|
@@ -9,14 +9,18 @@ export type BetterAuthAuthenticatorOptions = {
|
|
|
9
9
|
jwksUrl?: string | URL;
|
|
10
10
|
/** Defaults to the auth instance's `baseURL`; it is both issuer and audience of its tokens. */
|
|
11
11
|
issuer?: string;
|
|
12
|
-
/** The one tenant everyone works in
|
|
12
|
+
/** The one tenant everyone works in, for an app without organizations; never read from the token. */
|
|
13
13
|
tenant?: TenantValue | (() => Promise<TenantValue | undefined>);
|
|
14
|
+
/** Whether the tokens carry organizations; read from `auth` when given. Needed with `jwksUrl` only. */
|
|
15
|
+
organizations?: boolean;
|
|
14
16
|
/** How long the key set is cached; see `cachedKeys`. */
|
|
15
17
|
cache?: JwksCacheOptions;
|
|
16
18
|
};
|
|
17
19
|
/**
|
|
18
|
-
* Verifies the bearer JWT that Better Auth's jwt plugin issues. `sub` is the user id, the `role` claim
|
|
19
|
-
*
|
|
20
|
+
* Verifies the bearer JWT that Better Auth's jwt plugin issues. `sub` is the user id, the `role` claim (a comma
|
|
21
|
+
* separated string from the admin plugin) becomes `roles`. With organizations, the `org` claim is the tenant and the
|
|
22
|
+
* organization, and the membership's `app_roles` are added to the global roles; `user`, which stands for no global
|
|
23
|
+
* role, is left out.
|
|
20
24
|
*/
|
|
21
25
|
export declare const betterAuthAuthenticator: (options: BetterAuthAuthenticatorOptions) => Authenticator;
|
|
22
26
|
//#endregion
|
|
@@ -1,21 +1,42 @@
|
|
|
1
|
+
import { noGlobalRole } from "./organizations/role-definitions.js";
|
|
1
2
|
import { jwtAuthenticator } from "../auth/jwt.js";
|
|
2
3
|
import { cachedKeys } from "./jwks-cache.js";
|
|
3
4
|
//#region src/better-auth/authenticator.ts
|
|
4
5
|
/**
|
|
5
|
-
* Verifies the bearer JWT that Better Auth's jwt plugin issues. `sub` is the user id, the `role` claim
|
|
6
|
-
*
|
|
6
|
+
* Verifies the bearer JWT that Better Auth's jwt plugin issues. `sub` is the user id, the `role` claim (a comma
|
|
7
|
+
* separated string from the admin plugin) becomes `roles`. With organizations, the `org` claim is the tenant and the
|
|
8
|
+
* organization, and the membership's `app_roles` are added to the global roles; `user`, which stands for no global
|
|
9
|
+
* role, is left out.
|
|
7
10
|
*/
|
|
8
11
|
const betterAuthAuthenticator = (options) => {
|
|
9
12
|
const issuer = options.issuer ?? options.auth?.options.baseURL;
|
|
10
13
|
if (!issuer) throw new Error("betterAuthAuthenticator needs `issuer` (or an `auth` instance with a baseURL)");
|
|
11
14
|
if (!options.auth && !options.jwksUrl) throw new Error("betterAuthAuthenticator needs `auth` or `jwksUrl`");
|
|
12
|
-
|
|
15
|
+
const organizations = options.organizations ?? Boolean(options.auth?.organizations);
|
|
16
|
+
const verify = jwtAuthenticator({
|
|
13
17
|
...options.auth ? { keys: cachedKeys(() => options.auth.api.getJwks(), options.cache) } : { jwksUrl: options.jwksUrl },
|
|
14
18
|
issuer,
|
|
15
19
|
audience: issuer,
|
|
16
20
|
rolesClaim: "role",
|
|
21
|
+
...organizations && {
|
|
22
|
+
tenantClaim: "org",
|
|
23
|
+
extraRolesClaim: "app_roles"
|
|
24
|
+
},
|
|
17
25
|
...options.tenant !== void 0 && { tenant: options.tenant }
|
|
18
26
|
});
|
|
27
|
+
if (!organizations) return verify;
|
|
28
|
+
return async (request) => {
|
|
29
|
+
const session = await verify(request);
|
|
30
|
+
const user = {
|
|
31
|
+
...session.user,
|
|
32
|
+
roles: session.user.roles.filter((role) => role !== noGlobalRole)
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
...session,
|
|
36
|
+
user,
|
|
37
|
+
...session.tenant !== void 0 && { organization: { id: session.tenant } }
|
|
38
|
+
};
|
|
39
|
+
};
|
|
19
40
|
};
|
|
20
41
|
//#endregion
|
|
21
42
|
export { betterAuthAuthenticator };
|