@protobase/server 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/aggregate-service.js +135 -0
- package/dist/audit/console-queue.d.ts +5 -0
- package/dist/audit/console-queue.js +5 -0
- package/dist/auth/jwt.d.ts +21 -0
- package/dist/auth/jwt.js +49 -0
- package/dist/batch/refs.js +31 -0
- package/dist/batch/reorder.js +79 -0
- package/dist/batch/run-batch.js +105 -0
- package/dist/batch/schema.js +51 -0
- package/dist/better-auth/authenticator.d.ts +22 -0
- package/dist/better-auth/authenticator.js +21 -0
- package/dist/better-auth/create-auth.d.ts +1244 -0
- package/dist/better-auth/create-auth.js +93 -0
- package/dist/better-auth/jwks-cache.d.ts +9 -0
- package/dist/better-auth/jwks-cache.js +31 -0
- package/dist/better-auth/password-reset.js +32 -0
- package/dist/better-auth/status-route.js +17 -0
- package/dist/better-auth/tokens.d.ts +18 -0
- package/dist/better-auth/tokens.js +37 -0
- package/dist/better-auth/users.d.ts +50 -0
- package/dist/better-auth/users.js +111 -0
- package/dist/check-shell.js +17 -0
- package/dist/check-views.js +45 -0
- package/dist/create-admin.d.ts +23 -0
- package/dist/create-admin.js +85 -0
- package/dist/error-handler.js +44 -0
- package/dist/etag.js +22 -0
- package/dist/filter-input.js +28 -0
- package/dist/filter-shape.js +25 -0
- package/dist/hash.js +10 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/key.js +22 -0
- package/dist/list-service.js +96 -0
- package/dist/mail/mail-settings.js +26 -0
- package/dist/mail/smtp-mailer.d.ts +11 -0
- package/dist/mail/smtp-mailer.js +17 -0
- package/dist/meta.js +63 -0
- package/dist/openapi/components.js +331 -0
- package/dist/openapi/document.js +74 -0
- package/dist/openapi/naming.js +4 -0
- package/dist/openapi/resource-paths.js +417 -0
- package/dist/openapi/schemas.js +93 -0
- package/dist/params.js +48 -0
- package/dist/problem.d.ts +17 -0
- package/dist/problem.js +43 -0
- package/dist/read-service.js +65 -0
- package/dist/records.js +66 -0
- package/dist/registry.js +44 -0
- package/dist/request-access.js +97 -0
- package/dist/resource-source.d.ts +35 -0
- package/dist/resource-source.js +22 -0
- package/dist/reveal-service.js +43 -0
- package/dist/routes/batch.js +21 -0
- package/dist/routes/collection.js +63 -0
- package/dist/routes/docs.js +20 -0
- package/dist/routes/meta.js +22 -0
- package/dist/routes/preferences.js +12 -0
- package/dist/routes/record.js +97 -0
- package/dist/routes/target.js +18 -0
- package/dist/row-permissions.js +69 -0
- package/dist/rows.js +12 -0
- package/dist/scan-guard.js +72 -0
- package/dist/sql-parts.js +32 -0
- package/dist/tenant.js +10 -0
- package/dist/transactions.js +14 -0
- package/dist/types.d.ts +97 -0
- package/dist/validate-body.js +73 -0
- package/dist/view-access.js +54 -0
- package/dist/view-related.js +59 -0
- package/dist/write-pipeline.js +94 -0
- package/dist/write-shared.js +52 -0
- package/dist/write-update.js +45 -0
- package/package.json +39 -3
- package/README.md +0 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ref = z.object({
|
|
3
|
+
$ref: z.string().min(1),
|
|
4
|
+
field: z.string().optional()
|
|
5
|
+
}).strict();
|
|
6
|
+
const part = z.union([
|
|
7
|
+
z.string(),
|
|
8
|
+
z.number(),
|
|
9
|
+
ref
|
|
10
|
+
]);
|
|
11
|
+
/** A key: its URL text (`a,b` when composite), a scalar, a list of parts, or a reference to a record created earlier. */
|
|
12
|
+
const key = z.union([
|
|
13
|
+
z.string(),
|
|
14
|
+
z.number(),
|
|
15
|
+
z.array(part),
|
|
16
|
+
ref
|
|
17
|
+
]);
|
|
18
|
+
const data = z.record(z.string(), z.unknown());
|
|
19
|
+
const resource = z.string().min(1);
|
|
20
|
+
const operations = z.array(z.discriminatedUnion("op", [
|
|
21
|
+
z.object({
|
|
22
|
+
op: z.literal("create"),
|
|
23
|
+
resource,
|
|
24
|
+
data,
|
|
25
|
+
ref: z.string().min(1).optional()
|
|
26
|
+
}),
|
|
27
|
+
z.object({
|
|
28
|
+
op: z.literal("update"),
|
|
29
|
+
resource,
|
|
30
|
+
key,
|
|
31
|
+
etag: z.string().optional(),
|
|
32
|
+
data
|
|
33
|
+
}),
|
|
34
|
+
z.object({
|
|
35
|
+
op: z.literal("delete"),
|
|
36
|
+
resource,
|
|
37
|
+
key,
|
|
38
|
+
etag: z.string().optional()
|
|
39
|
+
}),
|
|
40
|
+
z.object({
|
|
41
|
+
op: z.literal("reorder"),
|
|
42
|
+
resource,
|
|
43
|
+
field: z.string().min(1),
|
|
44
|
+
keys: z.array(key).min(1),
|
|
45
|
+
etags: z.record(z.string(), z.string()).optional()
|
|
46
|
+
})
|
|
47
|
+
])).min(1).max(500);
|
|
48
|
+
/** `{ ops: [...] }`; `{ operations: [...] }` is accepted too, for clients written against that name. */
|
|
49
|
+
const batchBody = z.union([z.object({ ops: operations }), z.object({ operations })]).transform((body) => ({ ops: "ops" in body ? body.ops : body.operations }));
|
|
50
|
+
//#endregion
|
|
51
|
+
export { batchBody };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AdminAuth } from "./create-auth.js";
|
|
2
|
+
import { Authenticator, TenantValue } from "../types.js";
|
|
3
|
+
import { JwksCacheOptions } from "./jwks-cache.js";
|
|
4
|
+
//#region src/better-auth/authenticator.d.ts
|
|
5
|
+
export type BetterAuthAuthenticatorOptions = {
|
|
6
|
+
/** The Better Auth instance of this process: keys are read from it directly, no HTTP round trip. */
|
|
7
|
+
auth?: AdminAuth;
|
|
8
|
+
/** Or its JWKS endpoint, for an API that runs apart from the auth server. Needs `issuer`. */
|
|
9
|
+
jwksUrl?: string | URL;
|
|
10
|
+
/** Defaults to the auth instance's `baseURL`; it is both issuer and audience of its tokens. */
|
|
11
|
+
issuer?: string;
|
|
12
|
+
/** The one tenant everyone works in (organizations are not used yet); never read from the token. */
|
|
13
|
+
tenant?: TenantValue | (() => Promise<TenantValue | undefined>);
|
|
14
|
+
/** How long the key set is cached; see `cachedKeys`. */
|
|
15
|
+
cache?: JwksCacheOptions;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Verifies the bearer JWT that Better Auth's jwt plugin issues. `sub` is the user id, the `role` claim
|
|
19
|
+
* (a comma separated string from the admin plugin) becomes `roles`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const betterAuthAuthenticator: (options: BetterAuthAuthenticatorOptions) => Authenticator;
|
|
22
|
+
//#endregion
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jwtAuthenticator } from "../auth/jwt.js";
|
|
2
|
+
import { cachedKeys } from "./jwks-cache.js";
|
|
3
|
+
//#region src/better-auth/authenticator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Verifies the bearer JWT that Better Auth's jwt plugin issues. `sub` is the user id, the `role` claim
|
|
6
|
+
* (a comma separated string from the admin plugin) becomes `roles`.
|
|
7
|
+
*/
|
|
8
|
+
const betterAuthAuthenticator = (options) => {
|
|
9
|
+
const issuer = options.issuer ?? options.auth?.options.baseURL;
|
|
10
|
+
if (!issuer) throw new Error("betterAuthAuthenticator needs `issuer` (or an `auth` instance with a baseURL)");
|
|
11
|
+
if (!options.auth && !options.jwksUrl) throw new Error("betterAuthAuthenticator needs `auth` or `jwksUrl`");
|
|
12
|
+
return jwtAuthenticator({
|
|
13
|
+
...options.auth ? { keys: cachedKeys(() => options.auth.api.getJwks(), options.cache) } : { jwksUrl: options.jwksUrl },
|
|
14
|
+
issuer,
|
|
15
|
+
audience: issuer,
|
|
16
|
+
rolesClaim: "role",
|
|
17
|
+
...options.tenant !== void 0 && { tenant: options.tenant }
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { betterAuthAuthenticator };
|