@palbase/backend 5.2.0 → 7.0.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/dist/{chunk-WUQO76NW.js → chunk-SWT2QR5F.js} +32 -3
- package/dist/chunk-SWT2QR5F.js.map +1 -0
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.ts +2 -2
- package/dist/{endpoint-B3uVK6OL.d.cts → endpoint-BFgsOTiL.d.cts} +103 -60
- package/dist/{endpoint-B3uVK6OL.d.ts → endpoint-BFgsOTiL.d.ts} +103 -60
- package/dist/{index-BAEWl60b.d.cts → index-CE31P7Dt.d.cts} +1 -1
- package/dist/{index-D9uLjEhB.d.ts → index-E7CMoir3.d.ts} +1 -1
- package/dist/index.cjs +149 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -10
- package/dist/index.d.ts +100 -10
- package/dist/index.js +122 -3
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +40 -10
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +12 -10
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +11 -10
- package/docs/llms-full.txt +93 -19
- package/docs/routing.md +9 -5
- package/docs/services.md +73 -4
- package/package.json +5 -2
- package/dist/chunk-WUQO76NW.js.map +0 -1
|
@@ -82,7 +82,35 @@ var Cache = makeServiceProxy("Cache");
|
|
|
82
82
|
var Queue = makeServiceProxy("Queue");
|
|
83
83
|
var Log = makeServiceProxy("Log");
|
|
84
84
|
var Notifications = makeServiceProxy("Notifications");
|
|
85
|
-
var
|
|
85
|
+
var rawFlags = makeServiceProxy("Flags");
|
|
86
|
+
var Flags = Object.assign(
|
|
87
|
+
{
|
|
88
|
+
isEnabled(flagName, context) {
|
|
89
|
+
return rawFlags.isEnabled(flagName, context);
|
|
90
|
+
},
|
|
91
|
+
getVariant(flagName, context) {
|
|
92
|
+
return rawFlags.getVariant(flagName, context);
|
|
93
|
+
},
|
|
94
|
+
getAll(context) {
|
|
95
|
+
return rawFlags.getAll(context);
|
|
96
|
+
},
|
|
97
|
+
setOverride(key, value) {
|
|
98
|
+
return rawFlags.setOverride(key, value);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
/**
|
|
103
|
+
* Lazily resolve the runtime's cross-user sibling on each call. We do NOT
|
|
104
|
+
* cache it: `rawFlags.asService()` reads the CURRENT request scope through
|
|
105
|
+
* the runtime proxy, so caching would leak one request's sibling into
|
|
106
|
+
* another concurrent request. Mirrors `Database.asService()`.
|
|
107
|
+
*/
|
|
108
|
+
asService() {
|
|
109
|
+
return rawFlags.asService();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
var Realtime = makeServiceProxy("Realtime");
|
|
86
114
|
|
|
87
115
|
export {
|
|
88
116
|
__requestALS,
|
|
@@ -96,6 +124,7 @@ export {
|
|
|
96
124
|
Queue,
|
|
97
125
|
Log,
|
|
98
126
|
Notifications,
|
|
99
|
-
Flags
|
|
127
|
+
Flags,
|
|
128
|
+
Realtime
|
|
100
129
|
};
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
130
|
+
//# sourceMappingURL=chunk-SWT2QR5F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts"],"sourcesContent":["/**\n * runtime.ts — request-scoped service singletons.\n *\n * The backend SDK no longer threads a `ctx` god-object through every handler.\n * Instead, controller methods import PascalCase service singletons directly:\n *\n * import { Controller, Post, Body, Database } from \"@palbase/backend\";\n *\n * \\@Controller(\"/todos\")\n * export default class TodosController {\n * \\@Post(\"\") create(\\@Body(CreateTodoBody) body: CreateTodoBody): unknown {\n * return Database.insert(\"todos\", { title: body.title });\n * }\n * }\n *\n * The singletons are thin Proxies. Every property access forwards to the live\n * client for the CURRENT request scope, resolved through {@link __getRuntime}.\n *\n * # Request-scope resolution (persistent app-server)\n *\n * The runtime is a long-running Node process that serves many concurrent\n * requests on one event loop (NOT a fresh subprocess per request). A single\n * module-global slot would let one in-flight request's services bleed into\n * another's. So the services are carried in an {@link AsyncLocalStorage} store\n * ({@link __requestALS}) that the runtime sets per request with\n * {@link __runWithRuntime}; every async continuation of that request reads its\n * own store. `__getRuntime` reads the ALS store first; the module-global slot\n * (set by {@link __setRuntime}) is only a fallback for callers that run OUTSIDE\n * an ALS scope (dev-server, unit tests, the legacy single-shot path). Because\n * each `br-<ref>` pod is single-tenant, there is no cross-tenant leakage; the\n * ALS store is what prevents cross-REQUEST leakage within the shared process.\n *\n * The seam that makes `import { Database } from \"@palbase/backend\"` resolve to\n * the runtime-injected client: `@palbase/backend` is marked esbuild-EXTERNAL\n * when the tenant bundle is built, and the package is installed globally in the\n * pod (NODE_PATH=/usr/local/lib/node_modules). So worker.js's\n * `require('@palbase/backend')` and the bundle's `import` resolve to ONE shared\n * module instance — the ALS store and `__setRuntime` slot on that instance are\n * visible to the singletons the bundle imported.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type {\n DBClient,\n DBOps,\n TxClient,\n CacheClient,\n QueueClient,\n Logger,\n PalbaseDocsClient,\n} from \"./endpoint.js\";\nimport type {\n PalbaseStorageClient,\n PalbaseNotificationsClient,\n PalbaseFlagsClient,\n PalbaseFlagsServiceClient,\n PalbaseFlagContext,\n PalbaseFlagVariant,\n PalbaseFlag,\n PalbaseFlagValue,\n PalbaseSetOverrideResult,\n PalbaseRealtimeClient,\n} from \"./clients.js\";\nimport type { PalbaseResult } from \"./endpoint.js\";\nimport type {\n EnvTypedDatabase,\n EnvServiceDatabase,\n EnvTypedTx,\n EnvTables,\n} from \"./db/typed-db.js\";\n\n/** The set of live clients the runtime injects per request scope.\n *\n * Realtime is BROADCAST-ONLY here (a stateless handler can push an event but\n * cannot hold a subscription socket — `subscribe()` lives on the client SDK).\n *\n * EXCLUDED on purpose: Functions, CMS, Links, Analytics, Auth. They are not\n * exposed as backend handler singletons (auth lives on the client SDK; the rest\n * are out of scope for backend endpoints). */\nexport interface RuntimeServices {\n Database: DBClient;\n Documents: PalbaseDocsClient;\n Storage: PalbaseStorageClient;\n Cache: CacheClient;\n Queue: QueueClient;\n Log: Logger;\n Notifications: PalbaseNotificationsClient;\n Flags: PalbaseFlagsClient;\n Realtime: PalbaseRealtimeClient;\n}\n\n/**\n * Per-request store. The persistent runtime runs each request inside\n * {@link __runWithRuntime}, so every async continuation of that request reads\n * its OWN `runtime` (and any other request-scoped fields the runtime adds).\n *\n * Exported with a `__` prefix so the runtime (worker.js) shares the SAME ALS\n * instance across the one module instance — two ALS instances would silently\n * not see each other's stores. NOT part of the public author-facing API.\n */\nexport const __requestALS = new AsyncLocalStorage<{ runtime: RuntimeServices }>();\n\n/** Process-global fallback slot. Used only OUTSIDE an ALS scope (dev-server,\n * unit tests, legacy single-shot worker). Inside the persistent server every\n * request runs in {@link __requestALS}, which takes precedence. */\nlet runtime: RuntimeServices | null = null;\n\n/** Install the live clients in the process-global fallback slot.\n *\n * Persistent-server requests should use {@link __runWithRuntime} instead; this\n * remains for dev-server / tests / the legacy single-shot path that run without\n * an ALS scope. NOT part of the public author-facing API. */\nexport function __setRuntime(services: RuntimeServices): void {\n runtime = services;\n}\n\n/** Run `fn` with `services` bound as the request-scoped runtime.\n *\n * The persistent worker calls this once per request so concurrent requests\n * never share a services slot. NOT part of the public author-facing API. */\nexport function __runWithRuntime<T>(services: RuntimeServices, fn: () => T): T {\n return __requestALS.run({ runtime: services }, fn);\n}\n\n/** Read the live clients, throwing if accessed outside a request scope.\n *\n * Resolves the ALS store first (persistent server, per-request), then the\n * process-global fallback (dev-server / tests). NOT part of the public\n * author-facing API — used by the runtime and the singleton Proxies. */\nexport function __getRuntime(): RuntimeServices {\n const scoped = __requestALS.getStore();\n if (scoped) return scoped.runtime;\n if (runtime === null) {\n throw new Error(\n \"Palbase services accessed outside a request scope. The Database/Documents/… \" +\n \"singletons are only available inside an endpoint handler (or after the \" +\n \"runtime has called __runWithRuntime / __setRuntime).\",\n );\n }\n return runtime;\n}\n\n/**\n * Build a Proxy singleton that forwards every property access to the live\n * client named `key` on the current runtime.\n *\n * The single `as RuntimeServices[K]` is the only contained cast in the surface:\n * `Reflect.get` on a typed object returns `unknown` for a `string | symbol`\n * key, but `prop` is constrained to keys of the client interface at the call\n * sites (the exported singletons are typed below), so the forward is sound.\n */\nfunction makeServiceProxy<K extends keyof RuntimeServices>(key: K): RuntimeServices[K] {\n const handler: ProxyHandler<RuntimeServices[K]> = {\n get(_target, prop, receiver) {\n const client = __getRuntime()[key];\n const value = Reflect.get(client as object, prop, receiver) as unknown;\n // Bind methods to their owning client so `this` stays correct when the\n // author destructures or calls `Database.query(...)`.\n return typeof value === \"function\" ? value.bind(client) : value;\n },\n };\n // The Proxy target is irrelevant (all access goes through `get`); the cast\n // names the surface type the singleton presents to authors.\n return new Proxy({} as RuntimeServices[K], handler);\n}\n\n/**\n * Build the `.tables` accessor for an op-bearing client (the top-level\n * `Database` or a transaction-scoped `tx`). Each `tables.<name>` access\n * returns a small object that forwards the five CRUD ops to the underlying\n * client using `name` as the string table identifier. The shapes are typed\n * against the generated `palbase-env.d.ts` (`EnvTables`); at runtime they are\n * plain string-keyed calls, so no schema value is needed here.\n *\n * Returns `EnvTables` — TS cannot infer the mapped type through the Proxy, so\n * a single structural narrowing names the surface (the proxy returns a\n * correctly-shaped accessor for whatever string member is read).\n */\nfunction makeTablesAccessor(ops: () => TxClient): EnvTables {\n const tablesProxy = new Proxy(\n {},\n {\n get(_t, prop: string | symbol) {\n if (typeof prop !== \"string\") return undefined;\n const name = prop;\n return {\n insert: (data: Record<string, unknown>) => ops().insert(name, data),\n update: (id: string, data: Record<string, unknown>) => ops().update(name, id, data),\n delete: (id: string) => ops().delete(name, id),\n findById: (id: string) => ops().findById(name, id),\n findMany: (query?: Record<string, unknown>) => ops().findMany(name, query),\n };\n },\n },\n );\n return tablesProxy as EnvTables;\n}\n\n/** The raw string-keyed `DBClient` for the current request scope. */\nconst rawDatabase: DBClient = makeServiceProxy(\"Database\");\n\n/**\n * Wrap a raw `DBClient` into the typed `{ ...ops, tables, transaction }`\n * surface. The five string ops forward straight through; `tables` is the\n * env-typed accessor; `transaction` yields typed tables. Reused for both the\n * default (RLS-enforced) `Database` and the `asService()` sibling — each is\n * fed its own raw client (the default proxy vs `rawDatabase.asService()`).\n *\n * The `satisfies` pins the op surface so a missing/renamed op is a compile\n * error; the assembled object carries `tables`/`transaction` alongside.\n */\nfunction makeTypedSurface(raw: Omit<DBClient, \"asService\">): EnvServiceDatabase {\n const ops = {\n query: (sql: string, params?: unknown[]) => raw.query(sql, params),\n insert: (table: string, data: Record<string, unknown>) => raw.insert(table, data),\n update: (table: string, id: string, data: Record<string, unknown>) =>\n raw.update(table, id, data),\n delete: (table: string, id: string) => raw.delete(table, id),\n findById: (table: string, id: string) => raw.findById(table, id),\n findMany: (table: string, query?: Record<string, unknown>) => raw.findMany(table, query),\n } satisfies DBOps;\n return Object.assign(ops, {\n tables: makeTablesAccessor(() => raw),\n transaction<T>(fn: (tx: EnvTypedTx) => Promise<T>): Promise<T> {\n return raw.transaction((rawTx) => fn({ tables: makeTablesAccessor(() => rawTx) }));\n },\n });\n}\n\n/**\n * The project's own Postgres (pgx, schema `env_<envId>`).\n *\n * Typed by default: `Database.tables.<name>.insert({...})` is typed against\n * the project's generated `palbase-env.d.ts` with NO import and NO generic.\n * The raw string ops (`query`/`insert`/`update`/`delete`/`findById`/`findMany`)\n * are also available for dynamic table names and read-only SQL.\n *\n * RLS is enforced by default (the runtime runs each op as `authenticated` with\n * the verified user's claims). To bypass RLS, call `Database.asService()` —\n * explicit and greppable — which runs as the `service_role` (BYPASSRLS).\n *\n * @example\n * import { Database } from \"@palbase/backend\";\n *\n * const todo = await Database.tables.todos.insert({ title: req.input.title });\n * todo.id; // string ✓\n * const rows = await Database.query(\"SELECT id FROM todos WHERE done = $1\", [false]);\n * const all = await Database.asService().tables.todos.findMany({}); // RLS bypass\n */\nexport const Database: EnvTypedDatabase = Object.assign(makeTypedSurface(rawDatabase), {\n /**\n * Lazily resolve the runtime's service-role sibling on each call. We do NOT\n * cache it: `rawDatabase.asService()` reads the CURRENT request scope through\n * the runtime proxy, and the per-request runtime injects a service client\n * bound to that request's identity headers — caching would leak one request's\n * sibling into another concurrent request.\n */\n asService(): EnvServiceDatabase {\n return makeTypedSurface(rawDatabase.asService());\n },\n});\n\n/** Firestore-like document client (PalDocs). */\nexport const Documents: PalbaseDocsClient = makeServiceProxy(\"Documents\");\n\n/** Object storage client (buckets, signed URLs). */\nexport const Storage: PalbaseStorageClient = makeServiceProxy(\"Storage\");\n\n/** JSON-typed cache (get/set/incr/getOrSet). */\nexport const Cache: CacheClient = makeServiceProxy(\"Cache\");\n\n/** Background job queue. */\nexport const Queue: QueueClient = makeServiceProxy(\"Queue\");\n\n/** Structured logger. */\nexport const Log: Logger = makeServiceProxy(\"Log\");\n\n/** Push / email / SMS / in-app notifications. */\nexport const Notifications: PalbaseNotificationsClient = makeServiceProxy(\"Notifications\");\n\n/**\n * The raw runtime Flags client for the current request scope. Carries the\n * default-surface reads + `setOverride` AND the runtime's `asService()` sibling\n * (the br-pod's `buildFlagsClient` returns both). The default `Flags` singleton\n * below forwards reads + `setOverride` through here; `Flags.asService()`\n * forwards to this client's own `asService()`.\n */\nconst rawFlags: PalbaseFlagsClient = makeServiceProxy(\"Flags\");\n\n/**\n * Feature flags.\n *\n * Mirrors the `Database` / `Database.asService()` model. The default surface is\n * RLS-equivalent for flags: reads resolve against the CURRENT request user and\n * `Flags.setOverride(key, value)` writes an override for that same signed-in\n * user (no userId argument, no admin power). Cross-user admin writes\n * (`setOverrideForUser`, …) live behind `Flags.asService()` — explicit and\n * greppable, just like `Database.asService()`.\n *\n * @example\n * import { Flags } from \"@palbase/backend\";\n *\n * if (await Flags.isEnabled(\"new_checkout\")) { ... } // current user\n * await Flags.setOverride(\"new_checkout\", true); // current user\n * await Flags.asService().setOverrideForUser(\"u_9\", \"x\", true); // cross-user\n */\nexport const Flags: PalbaseFlagsClient = Object.assign(\n {\n isEnabled(\n flagName: string,\n context?: PalbaseFlagContext,\n ): Promise<PalbaseResult<boolean>> {\n return rawFlags.isEnabled(flagName, context);\n },\n getVariant(\n flagName: string,\n context?: PalbaseFlagContext,\n ): Promise<PalbaseResult<PalbaseFlagVariant>> {\n return rawFlags.getVariant(flagName, context);\n },\n getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>> {\n return rawFlags.getAll(context);\n },\n setOverride(\n key: string,\n value: PalbaseFlagValue,\n ): Promise<PalbaseResult<PalbaseSetOverrideResult>> {\n return rawFlags.setOverride(key, value);\n },\n },\n {\n /**\n * Lazily resolve the runtime's cross-user sibling on each call. We do NOT\n * cache it: `rawFlags.asService()` reads the CURRENT request scope through\n * the runtime proxy, so caching would leak one request's sibling into\n * another concurrent request. Mirrors `Database.asService()`.\n */\n asService(): PalbaseFlagsServiceClient {\n return rawFlags.asService();\n },\n },\n);\n\n/**\n * The Realtime broadcast singleton for the current request scope. Backend-side\n * Realtime is BROADCAST-ONLY (a stateless handler can push but not subscribe —\n * `subscribe()` lives on the client SDK's `pb.realtime`). Fire-and-forget:\n * `broadcast` resolves once accepted (or with an `error`), never blocking the\n * handler on subscribers.\n *\n * @example\n * import { Realtime } from \"@palbase/backend\";\n *\n * await Realtime.broadcast(\"room:42\", \"message\", { text, from: user.id });\n */\nexport const Realtime: PalbaseRealtimeClient = makeServiceProxy(\"Realtime\");\n"],"mappings":"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","names":[]}
|
package/dist/db/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RowShape, S as SchemaDef, n as SchemaInput, T as TableDef, o as TableInput, p as TypedDB, q as TypedTable, r as TypedTx, s as boolean, t as defineSchema, u as enumType, v as integer, w as isPalbaseExtension, x as jsonb, y as makeTypedDB, z as policy, A as text, B as timestamp, D as uuid } from '../index-
|
|
1
|
+
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RowShape, S as SchemaDef, n as SchemaInput, T as TableDef, o as TableInput, p as TypedDB, q as TypedTable, r as TypedTx, s as boolean, t as defineSchema, u as enumType, v as integer, w as isPalbaseExtension, x as jsonb, y as makeTypedDB, z as policy, A as text, B as timestamp, D as uuid } from '../index-CE31P7Dt.cjs';
|
|
2
2
|
import './env.cjs';
|
|
3
|
-
import '../endpoint-
|
|
3
|
+
import '../endpoint-BFgsOTiL.cjs';
|
|
4
4
|
import 'zod';
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RowShape, S as SchemaDef, n as SchemaInput, T as TableDef, o as TableInput, p as TypedDB, q as TypedTable, r as TypedTx, s as boolean, t as defineSchema, u as enumType, v as integer, w as isPalbaseExtension, x as jsonb, y as makeTypedDB, z as policy, A as text, B as timestamp, D as uuid } from '../index-
|
|
1
|
+
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, E as EnvTypedDatabase, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, i as PalbaseExtension, j as PolicyBuilder, k as PolicyCommand, l as PolicyDef, m as PolicyMode, R as RowShape, S as SchemaDef, n as SchemaInput, T as TableDef, o as TableInput, p as TypedDB, q as TypedTable, r as TypedTx, s as boolean, t as defineSchema, u as enumType, v as integer, w as isPalbaseExtension, x as jsonb, y as makeTypedDB, z as policy, A as text, B as timestamp, D as uuid } from '../index-E7CMoir3.js';
|
|
2
2
|
import './env.js';
|
|
3
|
-
import '../endpoint-
|
|
3
|
+
import '../endpoint-BFgsOTiL.js';
|
|
4
4
|
import 'zod';
|
|
@@ -254,33 +254,34 @@ type PalbaseFlagValue = boolean | number | string | null | PalbaseFlagValue[] |
|
|
|
254
254
|
};
|
|
255
255
|
/** Where a resolved flag value came from. */
|
|
256
256
|
type PalbaseFlagSource = "system" | "user";
|
|
257
|
-
/** Result of {@link PalbaseFlagsClient.
|
|
257
|
+
/** Result of {@link PalbaseFlagsClient.setOverride} /
|
|
258
|
+
* {@link PalbaseFlagsServiceClient.setOverrideForUser}. */
|
|
258
259
|
interface PalbaseSetOverrideResult {
|
|
259
260
|
key: string;
|
|
260
261
|
value: PalbaseFlagValue;
|
|
261
262
|
source: PalbaseFlagSource;
|
|
262
263
|
}
|
|
263
|
-
/** Result of {@link
|
|
264
|
+
/** Result of {@link PalbaseFlagsServiceClient.setOverridesForUser}. */
|
|
264
265
|
interface PalbaseSetOverridesResult {
|
|
265
266
|
values: Record<string, PalbaseFlagValue>;
|
|
266
267
|
}
|
|
267
|
-
/** Result of {@link
|
|
268
|
-
* system default the user falls back to. */
|
|
268
|
+
/** Result of {@link PalbaseFlagsServiceClient.clearOverrideForUser} — `value`
|
|
269
|
+
* is the system default the user falls back to. */
|
|
269
270
|
interface PalbaseClearOverrideResult {
|
|
270
271
|
key: string;
|
|
271
272
|
value: PalbaseFlagValue;
|
|
272
273
|
source: PalbaseFlagSource;
|
|
273
274
|
}
|
|
274
|
-
/** Result of {@link
|
|
275
|
+
/** Result of {@link PalbaseFlagsServiceClient.clearAllOverridesForUser}. */
|
|
275
276
|
interface PalbaseClearAllOverridesResult {
|
|
276
277
|
deleted: number;
|
|
277
278
|
}
|
|
278
|
-
/** One cross-user operation for {@link
|
|
279
|
+
/** One cross-user operation for {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
|
|
279
280
|
interface PalbaseBatchOverrideOperation {
|
|
280
281
|
userId: string;
|
|
281
282
|
values: Record<string, PalbaseFlagValue>;
|
|
282
283
|
}
|
|
283
|
-
/** Result of {@link
|
|
284
|
+
/** Result of {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
|
|
284
285
|
interface PalbaseBatchSetOverridesResult {
|
|
285
286
|
applied: number;
|
|
286
287
|
}
|
|
@@ -323,12 +324,6 @@ interface PalbaseListOptions {
|
|
|
323
324
|
order: "asc" | "desc";
|
|
324
325
|
};
|
|
325
326
|
}
|
|
326
|
-
/** Realtime message shape for server-side publish. */
|
|
327
|
-
interface PalbaseRealtimeMessage {
|
|
328
|
-
type: "broadcast" | "presence" | "postgres_changes";
|
|
329
|
-
event?: string;
|
|
330
|
-
payload?: Record<string, unknown>;
|
|
331
|
-
}
|
|
332
327
|
/** Edge-function invoke options. */
|
|
333
328
|
interface PalbaseInvokeOptions {
|
|
334
329
|
body?: unknown;
|
|
@@ -963,39 +958,6 @@ interface PalbaseStorageClient {
|
|
|
963
958
|
/** Get a bucket-scoped client for file operations. */
|
|
964
959
|
bucket(name: string): PalbaseBucketClient;
|
|
965
960
|
}
|
|
966
|
-
/**
|
|
967
|
-
* Channel reference for server-side realtime publish.
|
|
968
|
-
* Omits browser subscription patterns (on(), presenceState()) and
|
|
969
|
-
* internal test helpers (_injectWebSocket). All send operations are
|
|
970
|
-
* synchronous — they throw if the channel is not subscribed.
|
|
971
|
-
*/
|
|
972
|
-
interface PalbaseRealtimeChannel {
|
|
973
|
-
/** The channel name. */
|
|
974
|
-
readonly name: string;
|
|
975
|
-
/** Send a message to all channel subscribers. */
|
|
976
|
-
send(message: PalbaseRealtimeMessage): void;
|
|
977
|
-
/** Track server presence state. */
|
|
978
|
-
track(state: Record<string, unknown>): void;
|
|
979
|
-
/** Remove server presence state. */
|
|
980
|
-
untrack(): void;
|
|
981
|
-
/** Subscribe (connect WebSocket). Returns `this` for chaining. */
|
|
982
|
-
subscribe(): PalbaseRealtimeChannel;
|
|
983
|
-
/** Unsubscribe (close WebSocket). */
|
|
984
|
-
unsubscribe(): void;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Realtime client available on `ctx.realtime`.
|
|
988
|
-
* Server-side usage: get a channel, call send() to publish broadcasts.
|
|
989
|
-
* Omits browser subscription patterns (onSnapshot, subscribe listeners).
|
|
990
|
-
*/
|
|
991
|
-
interface PalbaseRealtimeClient {
|
|
992
|
-
/** Get (or create) a named channel. */
|
|
993
|
-
channel(name: string): PalbaseRealtimeChannel;
|
|
994
|
-
/** Remove a channel and close its WebSocket. */
|
|
995
|
-
removeChannel(name: string): void;
|
|
996
|
-
/** Remove all channels and close all WebSockets. */
|
|
997
|
-
removeAllChannels(): void;
|
|
998
|
-
}
|
|
999
961
|
/**
|
|
1000
962
|
* Functions client available on `ctx.functions`.
|
|
1001
963
|
* Invoke edge functions from a backend endpoint.
|
|
@@ -1005,23 +967,23 @@ interface PalbaseFunctionsClient {
|
|
|
1005
967
|
invoke<T = unknown>(fnName: string, options?: PalbaseInvokeOptions): Promise<PalbaseResult<T>>;
|
|
1006
968
|
}
|
|
1007
969
|
/**
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
970
|
+
* Cross-user admin write surface, reached via `Flags.asService()`.
|
|
971
|
+
*
|
|
972
|
+
* These five methods set/clear overrides for an ARBITRARY user (named
|
|
973
|
+
* explicitly), so they bypass the current-request-user scope that `Flags.*`
|
|
974
|
+
* reads and `Flags.setOverride(...)` are bound to. Mirrors the
|
|
975
|
+
* `Database` / `Database.asService()` split: the privileged, cross-user path
|
|
976
|
+
* is moved OFF the default surface so it is greppable and intentional — a
|
|
977
|
+
* handler that calls `Flags.setOverrideForUser(...)` on the default surface is
|
|
978
|
+
* a compile error and must reach for `Flags.asService()` first.
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* await Flags.asService().setOverrideForUser("user_123", "new_checkout", true);
|
|
1011
982
|
*/
|
|
1012
|
-
interface
|
|
1013
|
-
/** Is a flag enabled for the given context? */
|
|
1014
|
-
isEnabled(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<boolean>>;
|
|
1015
|
-
/** Get the active variant of a multivariate flag. */
|
|
1016
|
-
getVariant(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlagVariant>>;
|
|
1017
|
-
/** Get all flags for the project. */
|
|
1018
|
-
getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>>;
|
|
983
|
+
interface PalbaseFlagsServiceClient {
|
|
1019
984
|
/**
|
|
1020
985
|
* Set (or replace) a single feature-flag override for one user. The override
|
|
1021
986
|
* shadows the project (system) default for that user until cleared.
|
|
1022
|
-
*
|
|
1023
|
-
* @example
|
|
1024
|
-
* await Flags.setOverrideForUser("user_123", "new_checkout", true);
|
|
1025
987
|
*/
|
|
1026
988
|
setOverrideForUser(userId: string, key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
|
|
1027
989
|
/** Set multiple overrides for one user in a single call. */
|
|
@@ -1033,6 +995,87 @@ interface PalbaseFlagsClient {
|
|
|
1033
995
|
/** Apply override writes across many users in one request (max 1000 ops). */
|
|
1034
996
|
batchSetOverrides(operations: ReadonlyArray<PalbaseBatchOverrideOperation>): Promise<PalbaseResult<PalbaseBatchSetOverridesResult>>;
|
|
1035
997
|
}
|
|
998
|
+
/**
|
|
999
|
+
* Flags client available as the `Flags` singleton (and on `ctx.flags`).
|
|
1000
|
+
* Evaluate feature flags server-side (managed-runtime key — user targeting
|
|
1001
|
+
* is optional via context).
|
|
1002
|
+
*
|
|
1003
|
+
* Writes follow the `Database` model:
|
|
1004
|
+
* — `setOverride(key, value)` (default) overrides the flag for the CURRENT
|
|
1005
|
+
* request user; no userId argument, no admin power required. It errors when
|
|
1006
|
+
* there is no signed-in user (an anonymous request).
|
|
1007
|
+
* — `asService()` returns the {@link PalbaseFlagsServiceClient} carrying the
|
|
1008
|
+
* cross-user admin writes (`setOverrideForUser`, …) for an arbitrary target
|
|
1009
|
+
* user. Greppable + explicit, exactly like `Database.asService()`.
|
|
1010
|
+
*
|
|
1011
|
+
* Reads (`isEnabled`/`getVariant`/`get`/`getAll`) stay on this default surface
|
|
1012
|
+
* and are already current-user-scoped via the request identity.
|
|
1013
|
+
*/
|
|
1014
|
+
interface PalbaseFlagsClient {
|
|
1015
|
+
/** Is a flag enabled for the given context? */
|
|
1016
|
+
isEnabled(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<boolean>>;
|
|
1017
|
+
/** Get the active variant of a multivariate flag. */
|
|
1018
|
+
getVariant(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlagVariant>>;
|
|
1019
|
+
/** Get all flags for the project. */
|
|
1020
|
+
getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Set (or replace) a single feature-flag override for the CURRENT REQUEST
|
|
1023
|
+
* USER. No userId argument — the override is bound to the signed-in user the
|
|
1024
|
+
* handler is serving, so a handler can flip a flag for that user without
|
|
1025
|
+
* admin power. The override shadows the project (system) default for that
|
|
1026
|
+
* user until cleared.
|
|
1027
|
+
*
|
|
1028
|
+
* Errors when there is no signed-in user (an anonymous request); reach for
|
|
1029
|
+
* `Flags.asService().setOverrideForUser(userId, key, value)` to write a flag
|
|
1030
|
+
* for an arbitrary (cross-user) target.
|
|
1031
|
+
*
|
|
1032
|
+
* @example
|
|
1033
|
+
* await Flags.setOverride("new_checkout", true);
|
|
1034
|
+
*/
|
|
1035
|
+
setOverride(key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Return the cross-user admin write surface ({@link PalbaseFlagsServiceClient}).
|
|
1038
|
+
* Use sparingly and explicitly — the default `Flags.setOverride(...)` path is
|
|
1039
|
+
* bound to the current request user; `asService()` is how you write a flag
|
|
1040
|
+
* override for an ARBITRARY user. Mirrors `Database.asService()`.
|
|
1041
|
+
*/
|
|
1042
|
+
asService(): PalbaseFlagsServiceClient;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Realtime broadcast surface (backend handler → subscribed clients).
|
|
1046
|
+
*
|
|
1047
|
+
* Backend-side this is BROADCAST-ONLY: a handler pushes an event to a channel
|
|
1048
|
+
* and every client subscribed to that channel (via the client SDK's
|
|
1049
|
+
* `pb.realtime.channel(...).on(...)`) receives it. There is no `subscribe()` on
|
|
1050
|
+
* the backend — a stateless request handler can't hold a socket; it fires an
|
|
1051
|
+
* HTTP broadcast and returns. Delivery is fire-and-forget: `broadcast` resolves
|
|
1052
|
+
* once the broadcast is accepted (or with an `error` if it could not be sent),
|
|
1053
|
+
* but it never blocks the handler waiting on subscribers.
|
|
1054
|
+
*
|
|
1055
|
+
* Channel naming is app-defined and arbitrary (e.g. `"room:42"`, `"orders"`).
|
|
1056
|
+
* The Palbase-managed `flags:<ref>` channels are internal — author channels for
|
|
1057
|
+
* your own features.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* // Notify everyone in a chat room that a message landed:
|
|
1061
|
+
* await Realtime.broadcast("room:42", "message", { text, from: user.id });
|
|
1062
|
+
*/
|
|
1063
|
+
interface PalbaseRealtimeClient {
|
|
1064
|
+
/**
|
|
1065
|
+
* Broadcast `event` with `payload` to everyone subscribed to `channel`.
|
|
1066
|
+
*
|
|
1067
|
+
* Fire-and-forget: resolves `{ data: undefined, error: null }` when the
|
|
1068
|
+
* broadcast was accepted, or `{ data: null, error }` when it could not be
|
|
1069
|
+
* sent (e.g. realtime not provisioned). A failed broadcast never throws and
|
|
1070
|
+
* never fails the handler.
|
|
1071
|
+
*
|
|
1072
|
+
* @param channel App-defined channel name (e.g. `"room:42"`). Do NOT prefix
|
|
1073
|
+
* with `"realtime:"` — that prefix is internal to the transport.
|
|
1074
|
+
* @param event Event name subscribers filter on (e.g. `"message"`).
|
|
1075
|
+
* @param payload JSON-serializable event body.
|
|
1076
|
+
*/
|
|
1077
|
+
broadcast(channel: string, event: string, payload?: Record<string, unknown>): Promise<PalbaseResult<void>>;
|
|
1078
|
+
}
|
|
1036
1079
|
/**
|
|
1037
1080
|
* Push sub-client surface (server-only: fan-out to users / topics).
|
|
1038
1081
|
*/
|
|
@@ -1526,4 +1569,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
|
|
|
1526
1569
|
*/
|
|
1527
1570
|
type AuthSpec = boolean | Partial<AuthConfig>;
|
|
1528
1571
|
|
|
1529
|
-
export { type
|
|
1572
|
+
export { type PalbaseCountResult as $, type AuthSpec as A, BadRequest as B, type CacheClient as C, type DBClient as D, type ErrorDef as E, type FileContext as F, type PalbaseBatchOverrideOperation as G, HttpError as H, type PalbaseBatchSetOverridesResult as I, type PalbaseBindDeviceParams as J, type PalbaseBucketClient as K, type Logger as L, type Middleware as M, NotFound as N, type PalbaseClearAllOverridesResult as O, type PBRequest as P, type QueueClient as Q, type RateLimitConfig as R, type PalbaseClearOverrideResult as S, type PalbaseCmsClient as T, type User as U, type PalbaseCmsFindOneOptions as V, type PalbaseCmsFindOptions as W, type PalbaseCohortQueryInput as X, type PalbaseCohortResult as Y, type PalbaseCollectionRef as Z, type PalbaseCountQueryInput as _, type PalbaseModuleClients as a, type PalbaseUserDetailResult as a$, type PalbaseCreateLinkParams as a0, type PalbaseDeviceInfo as a1, type PalbaseDeviceTokenView as a2, type PalbaseDocumentRef as a3, type PalbaseDocumentSnapshot as a4, type PalbaseEmailClient as a5, type PalbaseEmailSendParams as a6, type PalbaseEmailSendResponse as a7, type PalbaseEventNamesResult as a8, type PalbaseEventsQueryInput as a9, type PalbaseListOptions as aA, type PalbaseMatchParams as aB, type PalbaseMultiChannelResponse as aC, type PalbaseOverviewResult as aD, type PalbasePreferences as aE, type PalbasePreferencesClient as aF, type PalbasePublicUrlResponse as aG, type PalbasePushClient as aH, type PalbasePushSendParams as aI, type PalbasePushSendResponse as aJ, type PalbaseQrCodeOptions as aK, type PalbaseQuerySnapshot as aL, type PalbaseRegisterDeviceParams as aM, type PalbaseResult as aN, type PalbaseRetentionQueryInput as aO, type PalbaseRetentionResult as aP, type PalbaseSession as aQ, type PalbaseSetOverrideResult as aR, type PalbaseSetOverridesResult as aS, type PalbaseSignedUrlResponse as aT, type PalbaseSmsClient as aU, type PalbaseSmsSendParams as aV, type PalbaseSmsSendResponse as aW, type PalbaseTransformOptions as aX, type PalbaseUpdateLinkParams as aY, type PalbaseUploadOptions as aZ, type PalbaseUser as a_, type PalbaseEventsResult as aa, type PalbaseFileObject as ab, type PalbaseFlag as ac, type PalbaseFlagContext as ad, type PalbaseFlagSource as ae, type PalbaseFlagValue as af, type PalbaseFlagVariant as ag, type PalbaseFlagsServiceClient as ah, type PalbaseFunctionsClient as ai, type PalbaseFunnelQueryInput as aj, type PalbaseFunnelResult as ak, type PalbaseIdentifyTraits as al, type PalbaseInboxClient as am, type PalbaseInboxListOptions as an, type PalbaseInboxListResult as ao, type PalbaseInboxMessage as ap, type PalbaseInboxSendParams as aq, type PalbaseInboxSendResponse as ar, type PalbaseInitialLink as as, type PalbaseInvokeOptions as at, type PalbaseLink as au, type PalbaseLinkAnalytics as av, type PalbaseLinkDetails as aw, type PalbaseLinksClient as ax, type PalbaseListLinksOptions as ay, type PalbaseListLinksResult as az, type PalbaseDocsClient as b, type PalbaseUsersQueryInput as b0, type PalbaseUsersResult as b1, type PalbaseVerifyRequestSignatureParams as b2, type PalbaseWhereOperator as b3, TooManyRequests as b4, type TxClient as b5, Unauthorized as b6, defineMiddleware as b7, type PalbaseFlagsClient as c, type PalbaseNotificationsClient as d, type PalbaseRealtimeClient as e, type PalbaseStorageClient as f, type AuthConfig as g, type ClientInfo as h, Conflict as i, type DBOps as j, type ErrorMap as k, type ErrorThrowers as l, Forbidden as m, type HttpMethod as n, type MiddlewareContext as o, type MiddlewareHandler as p, PalError as q, type PalbaseAnalyticsClient as r, type PalbaseAnalyticsManagementNamespace as s, type PalbaseAnalyticsProperties as t, type PalbaseAnalyticsQueryNamespace as u, type PalbaseAttestAndroidParams as v, type PalbaseAttestAndroidResult as w, type PalbaseAttestiOSParams as x, type PalbaseAttestiOSResult as y, type PalbaseAuthClient as z };
|
|
@@ -254,33 +254,34 @@ type PalbaseFlagValue = boolean | number | string | null | PalbaseFlagValue[] |
|
|
|
254
254
|
};
|
|
255
255
|
/** Where a resolved flag value came from. */
|
|
256
256
|
type PalbaseFlagSource = "system" | "user";
|
|
257
|
-
/** Result of {@link PalbaseFlagsClient.
|
|
257
|
+
/** Result of {@link PalbaseFlagsClient.setOverride} /
|
|
258
|
+
* {@link PalbaseFlagsServiceClient.setOverrideForUser}. */
|
|
258
259
|
interface PalbaseSetOverrideResult {
|
|
259
260
|
key: string;
|
|
260
261
|
value: PalbaseFlagValue;
|
|
261
262
|
source: PalbaseFlagSource;
|
|
262
263
|
}
|
|
263
|
-
/** Result of {@link
|
|
264
|
+
/** Result of {@link PalbaseFlagsServiceClient.setOverridesForUser}. */
|
|
264
265
|
interface PalbaseSetOverridesResult {
|
|
265
266
|
values: Record<string, PalbaseFlagValue>;
|
|
266
267
|
}
|
|
267
|
-
/** Result of {@link
|
|
268
|
-
* system default the user falls back to. */
|
|
268
|
+
/** Result of {@link PalbaseFlagsServiceClient.clearOverrideForUser} — `value`
|
|
269
|
+
* is the system default the user falls back to. */
|
|
269
270
|
interface PalbaseClearOverrideResult {
|
|
270
271
|
key: string;
|
|
271
272
|
value: PalbaseFlagValue;
|
|
272
273
|
source: PalbaseFlagSource;
|
|
273
274
|
}
|
|
274
|
-
/** Result of {@link
|
|
275
|
+
/** Result of {@link PalbaseFlagsServiceClient.clearAllOverridesForUser}. */
|
|
275
276
|
interface PalbaseClearAllOverridesResult {
|
|
276
277
|
deleted: number;
|
|
277
278
|
}
|
|
278
|
-
/** One cross-user operation for {@link
|
|
279
|
+
/** One cross-user operation for {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
|
|
279
280
|
interface PalbaseBatchOverrideOperation {
|
|
280
281
|
userId: string;
|
|
281
282
|
values: Record<string, PalbaseFlagValue>;
|
|
282
283
|
}
|
|
283
|
-
/** Result of {@link
|
|
284
|
+
/** Result of {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
|
|
284
285
|
interface PalbaseBatchSetOverridesResult {
|
|
285
286
|
applied: number;
|
|
286
287
|
}
|
|
@@ -323,12 +324,6 @@ interface PalbaseListOptions {
|
|
|
323
324
|
order: "asc" | "desc";
|
|
324
325
|
};
|
|
325
326
|
}
|
|
326
|
-
/** Realtime message shape for server-side publish. */
|
|
327
|
-
interface PalbaseRealtimeMessage {
|
|
328
|
-
type: "broadcast" | "presence" | "postgres_changes";
|
|
329
|
-
event?: string;
|
|
330
|
-
payload?: Record<string, unknown>;
|
|
331
|
-
}
|
|
332
327
|
/** Edge-function invoke options. */
|
|
333
328
|
interface PalbaseInvokeOptions {
|
|
334
329
|
body?: unknown;
|
|
@@ -963,39 +958,6 @@ interface PalbaseStorageClient {
|
|
|
963
958
|
/** Get a bucket-scoped client for file operations. */
|
|
964
959
|
bucket(name: string): PalbaseBucketClient;
|
|
965
960
|
}
|
|
966
|
-
/**
|
|
967
|
-
* Channel reference for server-side realtime publish.
|
|
968
|
-
* Omits browser subscription patterns (on(), presenceState()) and
|
|
969
|
-
* internal test helpers (_injectWebSocket). All send operations are
|
|
970
|
-
* synchronous — they throw if the channel is not subscribed.
|
|
971
|
-
*/
|
|
972
|
-
interface PalbaseRealtimeChannel {
|
|
973
|
-
/** The channel name. */
|
|
974
|
-
readonly name: string;
|
|
975
|
-
/** Send a message to all channel subscribers. */
|
|
976
|
-
send(message: PalbaseRealtimeMessage): void;
|
|
977
|
-
/** Track server presence state. */
|
|
978
|
-
track(state: Record<string, unknown>): void;
|
|
979
|
-
/** Remove server presence state. */
|
|
980
|
-
untrack(): void;
|
|
981
|
-
/** Subscribe (connect WebSocket). Returns `this` for chaining. */
|
|
982
|
-
subscribe(): PalbaseRealtimeChannel;
|
|
983
|
-
/** Unsubscribe (close WebSocket). */
|
|
984
|
-
unsubscribe(): void;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Realtime client available on `ctx.realtime`.
|
|
988
|
-
* Server-side usage: get a channel, call send() to publish broadcasts.
|
|
989
|
-
* Omits browser subscription patterns (onSnapshot, subscribe listeners).
|
|
990
|
-
*/
|
|
991
|
-
interface PalbaseRealtimeClient {
|
|
992
|
-
/** Get (or create) a named channel. */
|
|
993
|
-
channel(name: string): PalbaseRealtimeChannel;
|
|
994
|
-
/** Remove a channel and close its WebSocket. */
|
|
995
|
-
removeChannel(name: string): void;
|
|
996
|
-
/** Remove all channels and close all WebSockets. */
|
|
997
|
-
removeAllChannels(): void;
|
|
998
|
-
}
|
|
999
961
|
/**
|
|
1000
962
|
* Functions client available on `ctx.functions`.
|
|
1001
963
|
* Invoke edge functions from a backend endpoint.
|
|
@@ -1005,23 +967,23 @@ interface PalbaseFunctionsClient {
|
|
|
1005
967
|
invoke<T = unknown>(fnName: string, options?: PalbaseInvokeOptions): Promise<PalbaseResult<T>>;
|
|
1006
968
|
}
|
|
1007
969
|
/**
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
970
|
+
* Cross-user admin write surface, reached via `Flags.asService()`.
|
|
971
|
+
*
|
|
972
|
+
* These five methods set/clear overrides for an ARBITRARY user (named
|
|
973
|
+
* explicitly), so they bypass the current-request-user scope that `Flags.*`
|
|
974
|
+
* reads and `Flags.setOverride(...)` are bound to. Mirrors the
|
|
975
|
+
* `Database` / `Database.asService()` split: the privileged, cross-user path
|
|
976
|
+
* is moved OFF the default surface so it is greppable and intentional — a
|
|
977
|
+
* handler that calls `Flags.setOverrideForUser(...)` on the default surface is
|
|
978
|
+
* a compile error and must reach for `Flags.asService()` first.
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* await Flags.asService().setOverrideForUser("user_123", "new_checkout", true);
|
|
1011
982
|
*/
|
|
1012
|
-
interface
|
|
1013
|
-
/** Is a flag enabled for the given context? */
|
|
1014
|
-
isEnabled(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<boolean>>;
|
|
1015
|
-
/** Get the active variant of a multivariate flag. */
|
|
1016
|
-
getVariant(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlagVariant>>;
|
|
1017
|
-
/** Get all flags for the project. */
|
|
1018
|
-
getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>>;
|
|
983
|
+
interface PalbaseFlagsServiceClient {
|
|
1019
984
|
/**
|
|
1020
985
|
* Set (or replace) a single feature-flag override for one user. The override
|
|
1021
986
|
* shadows the project (system) default for that user until cleared.
|
|
1022
|
-
*
|
|
1023
|
-
* @example
|
|
1024
|
-
* await Flags.setOverrideForUser("user_123", "new_checkout", true);
|
|
1025
987
|
*/
|
|
1026
988
|
setOverrideForUser(userId: string, key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
|
|
1027
989
|
/** Set multiple overrides for one user in a single call. */
|
|
@@ -1033,6 +995,87 @@ interface PalbaseFlagsClient {
|
|
|
1033
995
|
/** Apply override writes across many users in one request (max 1000 ops). */
|
|
1034
996
|
batchSetOverrides(operations: ReadonlyArray<PalbaseBatchOverrideOperation>): Promise<PalbaseResult<PalbaseBatchSetOverridesResult>>;
|
|
1035
997
|
}
|
|
998
|
+
/**
|
|
999
|
+
* Flags client available as the `Flags` singleton (and on `ctx.flags`).
|
|
1000
|
+
* Evaluate feature flags server-side (managed-runtime key — user targeting
|
|
1001
|
+
* is optional via context).
|
|
1002
|
+
*
|
|
1003
|
+
* Writes follow the `Database` model:
|
|
1004
|
+
* — `setOverride(key, value)` (default) overrides the flag for the CURRENT
|
|
1005
|
+
* request user; no userId argument, no admin power required. It errors when
|
|
1006
|
+
* there is no signed-in user (an anonymous request).
|
|
1007
|
+
* — `asService()` returns the {@link PalbaseFlagsServiceClient} carrying the
|
|
1008
|
+
* cross-user admin writes (`setOverrideForUser`, …) for an arbitrary target
|
|
1009
|
+
* user. Greppable + explicit, exactly like `Database.asService()`.
|
|
1010
|
+
*
|
|
1011
|
+
* Reads (`isEnabled`/`getVariant`/`get`/`getAll`) stay on this default surface
|
|
1012
|
+
* and are already current-user-scoped via the request identity.
|
|
1013
|
+
*/
|
|
1014
|
+
interface PalbaseFlagsClient {
|
|
1015
|
+
/** Is a flag enabled for the given context? */
|
|
1016
|
+
isEnabled(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<boolean>>;
|
|
1017
|
+
/** Get the active variant of a multivariate flag. */
|
|
1018
|
+
getVariant(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlagVariant>>;
|
|
1019
|
+
/** Get all flags for the project. */
|
|
1020
|
+
getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Set (or replace) a single feature-flag override for the CURRENT REQUEST
|
|
1023
|
+
* USER. No userId argument — the override is bound to the signed-in user the
|
|
1024
|
+
* handler is serving, so a handler can flip a flag for that user without
|
|
1025
|
+
* admin power. The override shadows the project (system) default for that
|
|
1026
|
+
* user until cleared.
|
|
1027
|
+
*
|
|
1028
|
+
* Errors when there is no signed-in user (an anonymous request); reach for
|
|
1029
|
+
* `Flags.asService().setOverrideForUser(userId, key, value)` to write a flag
|
|
1030
|
+
* for an arbitrary (cross-user) target.
|
|
1031
|
+
*
|
|
1032
|
+
* @example
|
|
1033
|
+
* await Flags.setOverride("new_checkout", true);
|
|
1034
|
+
*/
|
|
1035
|
+
setOverride(key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Return the cross-user admin write surface ({@link PalbaseFlagsServiceClient}).
|
|
1038
|
+
* Use sparingly and explicitly — the default `Flags.setOverride(...)` path is
|
|
1039
|
+
* bound to the current request user; `asService()` is how you write a flag
|
|
1040
|
+
* override for an ARBITRARY user. Mirrors `Database.asService()`.
|
|
1041
|
+
*/
|
|
1042
|
+
asService(): PalbaseFlagsServiceClient;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Realtime broadcast surface (backend handler → subscribed clients).
|
|
1046
|
+
*
|
|
1047
|
+
* Backend-side this is BROADCAST-ONLY: a handler pushes an event to a channel
|
|
1048
|
+
* and every client subscribed to that channel (via the client SDK's
|
|
1049
|
+
* `pb.realtime.channel(...).on(...)`) receives it. There is no `subscribe()` on
|
|
1050
|
+
* the backend — a stateless request handler can't hold a socket; it fires an
|
|
1051
|
+
* HTTP broadcast and returns. Delivery is fire-and-forget: `broadcast` resolves
|
|
1052
|
+
* once the broadcast is accepted (or with an `error` if it could not be sent),
|
|
1053
|
+
* but it never blocks the handler waiting on subscribers.
|
|
1054
|
+
*
|
|
1055
|
+
* Channel naming is app-defined and arbitrary (e.g. `"room:42"`, `"orders"`).
|
|
1056
|
+
* The Palbase-managed `flags:<ref>` channels are internal — author channels for
|
|
1057
|
+
* your own features.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* // Notify everyone in a chat room that a message landed:
|
|
1061
|
+
* await Realtime.broadcast("room:42", "message", { text, from: user.id });
|
|
1062
|
+
*/
|
|
1063
|
+
interface PalbaseRealtimeClient {
|
|
1064
|
+
/**
|
|
1065
|
+
* Broadcast `event` with `payload` to everyone subscribed to `channel`.
|
|
1066
|
+
*
|
|
1067
|
+
* Fire-and-forget: resolves `{ data: undefined, error: null }` when the
|
|
1068
|
+
* broadcast was accepted, or `{ data: null, error }` when it could not be
|
|
1069
|
+
* sent (e.g. realtime not provisioned). A failed broadcast never throws and
|
|
1070
|
+
* never fails the handler.
|
|
1071
|
+
*
|
|
1072
|
+
* @param channel App-defined channel name (e.g. `"room:42"`). Do NOT prefix
|
|
1073
|
+
* with `"realtime:"` — that prefix is internal to the transport.
|
|
1074
|
+
* @param event Event name subscribers filter on (e.g. `"message"`).
|
|
1075
|
+
* @param payload JSON-serializable event body.
|
|
1076
|
+
*/
|
|
1077
|
+
broadcast(channel: string, event: string, payload?: Record<string, unknown>): Promise<PalbaseResult<void>>;
|
|
1078
|
+
}
|
|
1036
1079
|
/**
|
|
1037
1080
|
* Push sub-client surface (server-only: fan-out to users / topics).
|
|
1038
1081
|
*/
|
|
@@ -1526,4 +1569,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
|
|
|
1526
1569
|
*/
|
|
1527
1570
|
type AuthSpec = boolean | Partial<AuthConfig>;
|
|
1528
1571
|
|
|
1529
|
-
export { type
|
|
1572
|
+
export { type PalbaseCountResult as $, type AuthSpec as A, BadRequest as B, type CacheClient as C, type DBClient as D, type ErrorDef as E, type FileContext as F, type PalbaseBatchOverrideOperation as G, HttpError as H, type PalbaseBatchSetOverridesResult as I, type PalbaseBindDeviceParams as J, type PalbaseBucketClient as K, type Logger as L, type Middleware as M, NotFound as N, type PalbaseClearAllOverridesResult as O, type PBRequest as P, type QueueClient as Q, type RateLimitConfig as R, type PalbaseClearOverrideResult as S, type PalbaseCmsClient as T, type User as U, type PalbaseCmsFindOneOptions as V, type PalbaseCmsFindOptions as W, type PalbaseCohortQueryInput as X, type PalbaseCohortResult as Y, type PalbaseCollectionRef as Z, type PalbaseCountQueryInput as _, type PalbaseModuleClients as a, type PalbaseUserDetailResult as a$, type PalbaseCreateLinkParams as a0, type PalbaseDeviceInfo as a1, type PalbaseDeviceTokenView as a2, type PalbaseDocumentRef as a3, type PalbaseDocumentSnapshot as a4, type PalbaseEmailClient as a5, type PalbaseEmailSendParams as a6, type PalbaseEmailSendResponse as a7, type PalbaseEventNamesResult as a8, type PalbaseEventsQueryInput as a9, type PalbaseListOptions as aA, type PalbaseMatchParams as aB, type PalbaseMultiChannelResponse as aC, type PalbaseOverviewResult as aD, type PalbasePreferences as aE, type PalbasePreferencesClient as aF, type PalbasePublicUrlResponse as aG, type PalbasePushClient as aH, type PalbasePushSendParams as aI, type PalbasePushSendResponse as aJ, type PalbaseQrCodeOptions as aK, type PalbaseQuerySnapshot as aL, type PalbaseRegisterDeviceParams as aM, type PalbaseResult as aN, type PalbaseRetentionQueryInput as aO, type PalbaseRetentionResult as aP, type PalbaseSession as aQ, type PalbaseSetOverrideResult as aR, type PalbaseSetOverridesResult as aS, type PalbaseSignedUrlResponse as aT, type PalbaseSmsClient as aU, type PalbaseSmsSendParams as aV, type PalbaseSmsSendResponse as aW, type PalbaseTransformOptions as aX, type PalbaseUpdateLinkParams as aY, type PalbaseUploadOptions as aZ, type PalbaseUser as a_, type PalbaseEventsResult as aa, type PalbaseFileObject as ab, type PalbaseFlag as ac, type PalbaseFlagContext as ad, type PalbaseFlagSource as ae, type PalbaseFlagValue as af, type PalbaseFlagVariant as ag, type PalbaseFlagsServiceClient as ah, type PalbaseFunctionsClient as ai, type PalbaseFunnelQueryInput as aj, type PalbaseFunnelResult as ak, type PalbaseIdentifyTraits as al, type PalbaseInboxClient as am, type PalbaseInboxListOptions as an, type PalbaseInboxListResult as ao, type PalbaseInboxMessage as ap, type PalbaseInboxSendParams as aq, type PalbaseInboxSendResponse as ar, type PalbaseInitialLink as as, type PalbaseInvokeOptions as at, type PalbaseLink as au, type PalbaseLinkAnalytics as av, type PalbaseLinkDetails as aw, type PalbaseLinksClient as ax, type PalbaseListLinksOptions as ay, type PalbaseListLinksResult as az, type PalbaseDocsClient as b, type PalbaseUsersQueryInput as b0, type PalbaseUsersResult as b1, type PalbaseVerifyRequestSignatureParams as b2, type PalbaseWhereOperator as b3, TooManyRequests as b4, type TxClient as b5, Unauthorized as b6, defineMiddleware as b7, type PalbaseFlagsClient as c, type PalbaseNotificationsClient as d, type PalbaseRealtimeClient as e, type PalbaseStorageClient as f, type AuthConfig as g, type ClientInfo as h, Conflict as i, type DBOps as j, type ErrorMap as k, type ErrorThrowers as l, Forbidden as m, type HttpMethod as n, type MiddlewareContext as o, type MiddlewareHandler as p, PalError as q, type PalbaseAnalyticsClient as r, type PalbaseAnalyticsManagementNamespace as s, type PalbaseAnalyticsProperties as t, type PalbaseAnalyticsQueryNamespace as u, type PalbaseAttestAndroidParams as v, type PalbaseAttestAndroidResult as w, type PalbaseAttestiOSParams as x, type PalbaseAttestiOSResult as y, type PalbaseAuthClient as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tables, TableTypes } from './db/env.cjs';
|
|
2
|
-
import { D as DBClient } from './endpoint-
|
|
2
|
+
import { D as DBClient } from './endpoint-BFgsOTiL.cjs';
|
|
3
3
|
|
|
4
4
|
/** On delete action for foreign key references. */
|
|
5
5
|
type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tables, TableTypes } from './db/env.js';
|
|
2
|
-
import { D as DBClient } from './endpoint-
|
|
2
|
+
import { D as DBClient } from './endpoint-BFgsOTiL.js';
|
|
3
3
|
|
|
4
4
|
/** On delete action for foreign key references. */
|
|
5
5
|
type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
|