@palbase/backend 5.1.0 → 6.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.
@@ -82,7 +82,34 @@ var Cache = makeServiceProxy("Cache");
82
82
  var Queue = makeServiceProxy("Queue");
83
83
  var Log = makeServiceProxy("Log");
84
84
  var Notifications = makeServiceProxy("Notifications");
85
- var Flags = makeServiceProxy("Flags");
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
+ );
86
113
 
87
114
  export {
88
115
  __requestALS,
@@ -98,4 +125,4 @@ export {
98
125
  Notifications,
99
126
  Flags
100
127
  };
101
- //# sourceMappingURL=chunk-WUQO76NW.js.map
128
+ //# sourceMappingURL=chunk-HAVXYTDJ.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} 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 * EXCLUDED on purpose: Realtime, Functions, CMS, Links, Analytics, Auth. They\n * are not exposed as backend handler singletons (auth lives on the client SDK;\n * the rest 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}\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"],"mappings":"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","names":[]}
@@ -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-mr3Co63T.cjs';
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-DvhjkX6F.cjs';
2
2
  import './env.cjs';
3
- import '../endpoint-BEHjfvFH.cjs';
3
+ import '../endpoint-CfdiQbVC.cjs';
4
4
  import 'zod';
@@ -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-BTVdhfsb.js';
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-BVnIdFpa.js';
2
2
  import './env.js';
3
- import '../endpoint-BEHjfvFH.js';
3
+ import '../endpoint-CfdiQbVC.js';
4
4
  import 'zod';
@@ -245,6 +245,46 @@ interface PalbaseFlag {
245
245
  enabled: boolean;
246
246
  variant?: PalbaseFlagVariant;
247
247
  }
248
+ /**
249
+ * Any JSON value a feature flag (or per-user override) can hold once resolved.
250
+ * Mirrors the wire shape the user-flags module stores and returns.
251
+ */
252
+ type PalbaseFlagValue = boolean | number | string | null | PalbaseFlagValue[] | {
253
+ [key: string]: PalbaseFlagValue;
254
+ };
255
+ /** Where a resolved flag value came from. */
256
+ type PalbaseFlagSource = "system" | "user";
257
+ /** Result of {@link PalbaseFlagsClient.setOverride} /
258
+ * {@link PalbaseFlagsServiceClient.setOverrideForUser}. */
259
+ interface PalbaseSetOverrideResult {
260
+ key: string;
261
+ value: PalbaseFlagValue;
262
+ source: PalbaseFlagSource;
263
+ }
264
+ /** Result of {@link PalbaseFlagsServiceClient.setOverridesForUser}. */
265
+ interface PalbaseSetOverridesResult {
266
+ values: Record<string, PalbaseFlagValue>;
267
+ }
268
+ /** Result of {@link PalbaseFlagsServiceClient.clearOverrideForUser} — `value`
269
+ * is the system default the user falls back to. */
270
+ interface PalbaseClearOverrideResult {
271
+ key: string;
272
+ value: PalbaseFlagValue;
273
+ source: PalbaseFlagSource;
274
+ }
275
+ /** Result of {@link PalbaseFlagsServiceClient.clearAllOverridesForUser}. */
276
+ interface PalbaseClearAllOverridesResult {
277
+ deleted: number;
278
+ }
279
+ /** One cross-user operation for {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
280
+ interface PalbaseBatchOverrideOperation {
281
+ userId: string;
282
+ values: Record<string, PalbaseFlagValue>;
283
+ }
284
+ /** Result of {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
285
+ interface PalbaseBatchSetOverridesResult {
286
+ applied: number;
287
+ }
248
288
  /** File object returned by storage operations. */
249
289
  interface PalbaseFileObject {
250
290
  name: string;
@@ -966,9 +1006,49 @@ interface PalbaseFunctionsClient {
966
1006
  invoke<T = unknown>(fnName: string, options?: PalbaseInvokeOptions): Promise<PalbaseResult<T>>;
967
1007
  }
968
1008
  /**
969
- * Flags client available on `ctx.flags`.
1009
+ * Cross-user admin write surface, reached via `Flags.asService()`.
1010
+ *
1011
+ * These five methods set/clear overrides for an ARBITRARY user (named
1012
+ * explicitly), so they bypass the current-request-user scope that `Flags.*`
1013
+ * reads and `Flags.setOverride(...)` are bound to. Mirrors the
1014
+ * `Database` / `Database.asService()` split: the privileged, cross-user path
1015
+ * is moved OFF the default surface so it is greppable and intentional — a
1016
+ * handler that calls `Flags.setOverrideForUser(...)` on the default surface is
1017
+ * a compile error and must reach for `Flags.asService()` first.
1018
+ *
1019
+ * @example
1020
+ * await Flags.asService().setOverrideForUser("user_123", "new_checkout", true);
1021
+ */
1022
+ interface PalbaseFlagsServiceClient {
1023
+ /**
1024
+ * Set (or replace) a single feature-flag override for one user. The override
1025
+ * shadows the project (system) default for that user until cleared.
1026
+ */
1027
+ setOverrideForUser(userId: string, key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
1028
+ /** Set multiple overrides for one user in a single call. */
1029
+ setOverridesForUser(userId: string, values: Record<string, PalbaseFlagValue>): Promise<PalbaseResult<PalbaseSetOverridesResult>>;
1030
+ /** Clear one override for a user, restoring the project (system) default. */
1031
+ clearOverrideForUser(userId: string, key: string): Promise<PalbaseResult<PalbaseClearOverrideResult>>;
1032
+ /** Clear all overrides for a user, restoring project (system) defaults. */
1033
+ clearAllOverridesForUser(userId: string): Promise<PalbaseResult<PalbaseClearAllOverridesResult>>;
1034
+ /** Apply override writes across many users in one request (max 1000 ops). */
1035
+ batchSetOverrides(operations: ReadonlyArray<PalbaseBatchOverrideOperation>): Promise<PalbaseResult<PalbaseBatchSetOverridesResult>>;
1036
+ }
1037
+ /**
1038
+ * Flags client available as the `Flags` singleton (and on `ctx.flags`).
970
1039
  * Evaluate feature flags server-side (managed-runtime key — user targeting
971
1040
  * is optional via context).
1041
+ *
1042
+ * Writes follow the `Database` model:
1043
+ * — `setOverride(key, value)` (default) overrides the flag for the CURRENT
1044
+ * request user; no userId argument, no admin power required. It errors when
1045
+ * there is no signed-in user (an anonymous request).
1046
+ * — `asService()` returns the {@link PalbaseFlagsServiceClient} carrying the
1047
+ * cross-user admin writes (`setOverrideForUser`, …) for an arbitrary target
1048
+ * user. Greppable + explicit, exactly like `Database.asService()`.
1049
+ *
1050
+ * Reads (`isEnabled`/`getVariant`/`get`/`getAll`) stay on this default surface
1051
+ * and are already current-user-scoped via the request identity.
972
1052
  */
973
1053
  interface PalbaseFlagsClient {
974
1054
  /** Is a flag enabled for the given context? */
@@ -977,6 +1057,28 @@ interface PalbaseFlagsClient {
977
1057
  getVariant(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlagVariant>>;
978
1058
  /** Get all flags for the project. */
979
1059
  getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>>;
1060
+ /**
1061
+ * Set (or replace) a single feature-flag override for the CURRENT REQUEST
1062
+ * USER. No userId argument — the override is bound to the signed-in user the
1063
+ * handler is serving, so a handler can flip a flag for that user without
1064
+ * admin power. The override shadows the project (system) default for that
1065
+ * user until cleared.
1066
+ *
1067
+ * Errors when there is no signed-in user (an anonymous request); reach for
1068
+ * `Flags.asService().setOverrideForUser(userId, key, value)` to write a flag
1069
+ * for an arbitrary (cross-user) target.
1070
+ *
1071
+ * @example
1072
+ * await Flags.setOverride("new_checkout", true);
1073
+ */
1074
+ setOverride(key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
1075
+ /**
1076
+ * Return the cross-user admin write surface ({@link PalbaseFlagsServiceClient}).
1077
+ * Use sparingly and explicitly — the default `Flags.setOverride(...)` path is
1078
+ * bound to the current request user; `asService()` is how you write a flag
1079
+ * override for an ARBITRARY user. Mirrors `Database.asService()`.
1080
+ */
1081
+ asService(): PalbaseFlagsServiceClient;
980
1082
  }
981
1083
  /**
982
1084
  * Push sub-client surface (server-only: fan-out to users / topics).
@@ -1471,4 +1573,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
1471
1573
  */
1472
1574
  type AuthSpec = boolean | Partial<AuthConfig>;
1473
1575
 
1474
- export { type PalbaseDocumentSnapshot 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 PalbaseBucketClient as G, HttpError as H, type PalbaseCmsClient as I, type PalbaseCmsFindOneOptions as J, type PalbaseCmsFindOptions as K, type Logger as L, type Middleware as M, NotFound as N, type PalbaseCohortQueryInput as O, type PBRequest as P, type QueueClient as Q, type RateLimitConfig as R, type PalbaseCohortResult as S, type PalbaseCollectionRef as T, type User as U, type PalbaseCountQueryInput as V, type PalbaseCountResult as W, type PalbaseCreateLinkParams as X, type PalbaseDeviceInfo as Y, type PalbaseDeviceTokenView as Z, type PalbaseDocumentRef as _, type PalbaseModuleClients as a, Unauthorized as a$, type PalbaseEmailClient as a0, type PalbaseEmailSendParams as a1, type PalbaseEmailSendResponse as a2, type PalbaseEventNamesResult as a3, type PalbaseEventsQueryInput as a4, type PalbaseEventsResult as a5, type PalbaseFileObject as a6, type PalbaseFlag as a7, type PalbaseFlagContext as a8, type PalbaseFlagVariant as a9, type PalbasePushSendParams as aA, type PalbasePushSendResponse as aB, type PalbaseQrCodeOptions as aC, type PalbaseQuerySnapshot as aD, type PalbaseRealtimeChannel as aE, type PalbaseRealtimeClient as aF, type PalbaseRealtimeMessage as aG, type PalbaseRegisterDeviceParams as aH, type PalbaseResult as aI, type PalbaseRetentionQueryInput as aJ, type PalbaseRetentionResult as aK, type PalbaseSession as aL, type PalbaseSignedUrlResponse as aM, type PalbaseSmsClient as aN, type PalbaseSmsSendParams as aO, type PalbaseSmsSendResponse as aP, type PalbaseTransformOptions as aQ, type PalbaseUpdateLinkParams as aR, type PalbaseUploadOptions as aS, type PalbaseUser as aT, type PalbaseUserDetailResult as aU, type PalbaseUsersQueryInput as aV, type PalbaseUsersResult as aW, type PalbaseVerifyRequestSignatureParams as aX, type PalbaseWhereOperator as aY, TooManyRequests as aZ, type TxClient as a_, type PalbaseFunctionsClient as aa, type PalbaseFunnelQueryInput as ab, type PalbaseFunnelResult as ac, type PalbaseIdentifyTraits as ad, type PalbaseInboxClient as ae, type PalbaseInboxListOptions as af, type PalbaseInboxListResult as ag, type PalbaseInboxMessage as ah, type PalbaseInboxSendParams as ai, type PalbaseInboxSendResponse as aj, type PalbaseInitialLink as ak, type PalbaseInvokeOptions as al, type PalbaseLink as am, type PalbaseLinkAnalytics as an, type PalbaseLinkDetails as ao, type PalbaseLinksClient as ap, type PalbaseListLinksOptions as aq, type PalbaseListLinksResult as ar, type PalbaseListOptions as as, type PalbaseMatchParams as at, type PalbaseMultiChannelResponse as au, type PalbaseOverviewResult as av, type PalbasePreferences as aw, type PalbasePreferencesClient as ax, type PalbasePublicUrlResponse as ay, type PalbasePushClient as az, type PalbaseDocsClient as b, defineMiddleware as b0, type PalbaseFlagsClient as c, type PalbaseNotificationsClient as d, type PalbaseStorageClient as e, type AuthConfig as f, type ClientInfo as g, Conflict as h, type DBOps as i, type ErrorMap as j, type ErrorThrowers as k, Forbidden as l, type HttpMethod as m, type MiddlewareContext as n, type MiddlewareHandler as o, PalError as p, type PalbaseAnalyticsClient as q, type PalbaseAnalyticsManagementNamespace as r, type PalbaseAnalyticsProperties as s, type PalbaseAnalyticsQueryNamespace as t, type PalbaseAttestAndroidParams as u, type PalbaseAttestAndroidResult as v, type PalbaseAttestiOSParams as w, type PalbaseAttestiOSResult as x, type PalbaseAuthClient as y, type PalbaseBindDeviceParams as z };
1576
+ export { type PalbaseCreateLinkParams 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 PalbaseBatchSetOverridesResult as G, HttpError as H, type PalbaseBindDeviceParams as I, type PalbaseBucketClient as J, type PalbaseClearAllOverridesResult as K, type Logger as L, type Middleware as M, NotFound as N, type PalbaseClearOverrideResult as O, type PBRequest as P, type QueueClient as Q, type RateLimitConfig as R, type PalbaseCmsClient as S, type PalbaseCmsFindOneOptions as T, type User as U, type PalbaseCmsFindOptions as V, type PalbaseCohortQueryInput as W, type PalbaseCohortResult as X, type PalbaseCollectionRef as Y, type PalbaseCountQueryInput as Z, type PalbaseCountResult as _, type PalbaseModuleClients as a, type PalbaseUploadOptions as a$, type PalbaseDeviceInfo as a0, type PalbaseDeviceTokenView as a1, type PalbaseDocumentRef as a2, type PalbaseDocumentSnapshot as a3, type PalbaseEmailClient as a4, type PalbaseEmailSendParams as a5, type PalbaseEmailSendResponse as a6, type PalbaseEventNamesResult as a7, type PalbaseEventsQueryInput as a8, type PalbaseEventsResult as a9, type PalbaseMatchParams as aA, type PalbaseMultiChannelResponse as aB, type PalbaseOverviewResult as aC, type PalbasePreferences as aD, type PalbasePreferencesClient as aE, type PalbasePublicUrlResponse as aF, type PalbasePushClient as aG, type PalbasePushSendParams as aH, type PalbasePushSendResponse as aI, type PalbaseQrCodeOptions as aJ, type PalbaseQuerySnapshot as aK, type PalbaseRealtimeChannel as aL, type PalbaseRealtimeClient as aM, type PalbaseRealtimeMessage as aN, type PalbaseRegisterDeviceParams as aO, type PalbaseResult as aP, type PalbaseRetentionQueryInput as aQ, type PalbaseRetentionResult as aR, type PalbaseSession as aS, type PalbaseSetOverrideResult as aT, type PalbaseSetOverridesResult as aU, type PalbaseSignedUrlResponse as aV, type PalbaseSmsClient as aW, type PalbaseSmsSendParams as aX, type PalbaseSmsSendResponse as aY, type PalbaseTransformOptions as aZ, type PalbaseUpdateLinkParams as a_, type PalbaseFileObject as aa, type PalbaseFlag as ab, type PalbaseFlagContext as ac, type PalbaseFlagSource as ad, type PalbaseFlagValue as ae, type PalbaseFlagVariant as af, type PalbaseFlagsServiceClient as ag, type PalbaseFunctionsClient as ah, type PalbaseFunnelQueryInput as ai, type PalbaseFunnelResult as aj, type PalbaseIdentifyTraits as ak, type PalbaseInboxClient as al, type PalbaseInboxListOptions as am, type PalbaseInboxListResult as an, type PalbaseInboxMessage as ao, type PalbaseInboxSendParams as ap, type PalbaseInboxSendResponse as aq, type PalbaseInitialLink as ar, type PalbaseInvokeOptions as as, type PalbaseLink as at, type PalbaseLinkAnalytics as au, type PalbaseLinkDetails as av, type PalbaseLinksClient as aw, type PalbaseListLinksOptions as ax, type PalbaseListLinksResult as ay, type PalbaseListOptions as az, type PalbaseDocsClient as b, type PalbaseUser as b0, type PalbaseUserDetailResult as b1, type PalbaseUsersQueryInput as b2, type PalbaseUsersResult as b3, type PalbaseVerifyRequestSignatureParams as b4, type PalbaseWhereOperator as b5, TooManyRequests as b6, type TxClient as b7, Unauthorized as b8, defineMiddleware as b9, type PalbaseFlagsClient as c, type PalbaseNotificationsClient as d, type PalbaseStorageClient as e, type AuthConfig as f, type ClientInfo as g, Conflict as h, type DBOps as i, type ErrorMap as j, type ErrorThrowers as k, Forbidden as l, type HttpMethod as m, type MiddlewareContext as n, type MiddlewareHandler as o, PalError as p, type PalbaseAnalyticsClient as q, type PalbaseAnalyticsManagementNamespace as r, type PalbaseAnalyticsProperties as s, type PalbaseAnalyticsQueryNamespace as t, type PalbaseAttestAndroidParams as u, type PalbaseAttestAndroidResult as v, type PalbaseAttestiOSParams as w, type PalbaseAttestiOSResult as x, type PalbaseAuthClient as y, type PalbaseBatchOverrideOperation as z };
@@ -245,6 +245,46 @@ interface PalbaseFlag {
245
245
  enabled: boolean;
246
246
  variant?: PalbaseFlagVariant;
247
247
  }
248
+ /**
249
+ * Any JSON value a feature flag (or per-user override) can hold once resolved.
250
+ * Mirrors the wire shape the user-flags module stores and returns.
251
+ */
252
+ type PalbaseFlagValue = boolean | number | string | null | PalbaseFlagValue[] | {
253
+ [key: string]: PalbaseFlagValue;
254
+ };
255
+ /** Where a resolved flag value came from. */
256
+ type PalbaseFlagSource = "system" | "user";
257
+ /** Result of {@link PalbaseFlagsClient.setOverride} /
258
+ * {@link PalbaseFlagsServiceClient.setOverrideForUser}. */
259
+ interface PalbaseSetOverrideResult {
260
+ key: string;
261
+ value: PalbaseFlagValue;
262
+ source: PalbaseFlagSource;
263
+ }
264
+ /** Result of {@link PalbaseFlagsServiceClient.setOverridesForUser}. */
265
+ interface PalbaseSetOverridesResult {
266
+ values: Record<string, PalbaseFlagValue>;
267
+ }
268
+ /** Result of {@link PalbaseFlagsServiceClient.clearOverrideForUser} — `value`
269
+ * is the system default the user falls back to. */
270
+ interface PalbaseClearOverrideResult {
271
+ key: string;
272
+ value: PalbaseFlagValue;
273
+ source: PalbaseFlagSource;
274
+ }
275
+ /** Result of {@link PalbaseFlagsServiceClient.clearAllOverridesForUser}. */
276
+ interface PalbaseClearAllOverridesResult {
277
+ deleted: number;
278
+ }
279
+ /** One cross-user operation for {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
280
+ interface PalbaseBatchOverrideOperation {
281
+ userId: string;
282
+ values: Record<string, PalbaseFlagValue>;
283
+ }
284
+ /** Result of {@link PalbaseFlagsServiceClient.batchSetOverrides}. */
285
+ interface PalbaseBatchSetOverridesResult {
286
+ applied: number;
287
+ }
248
288
  /** File object returned by storage operations. */
249
289
  interface PalbaseFileObject {
250
290
  name: string;
@@ -966,9 +1006,49 @@ interface PalbaseFunctionsClient {
966
1006
  invoke<T = unknown>(fnName: string, options?: PalbaseInvokeOptions): Promise<PalbaseResult<T>>;
967
1007
  }
968
1008
  /**
969
- * Flags client available on `ctx.flags`.
1009
+ * Cross-user admin write surface, reached via `Flags.asService()`.
1010
+ *
1011
+ * These five methods set/clear overrides for an ARBITRARY user (named
1012
+ * explicitly), so they bypass the current-request-user scope that `Flags.*`
1013
+ * reads and `Flags.setOverride(...)` are bound to. Mirrors the
1014
+ * `Database` / `Database.asService()` split: the privileged, cross-user path
1015
+ * is moved OFF the default surface so it is greppable and intentional — a
1016
+ * handler that calls `Flags.setOverrideForUser(...)` on the default surface is
1017
+ * a compile error and must reach for `Flags.asService()` first.
1018
+ *
1019
+ * @example
1020
+ * await Flags.asService().setOverrideForUser("user_123", "new_checkout", true);
1021
+ */
1022
+ interface PalbaseFlagsServiceClient {
1023
+ /**
1024
+ * Set (or replace) a single feature-flag override for one user. The override
1025
+ * shadows the project (system) default for that user until cleared.
1026
+ */
1027
+ setOverrideForUser(userId: string, key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
1028
+ /** Set multiple overrides for one user in a single call. */
1029
+ setOverridesForUser(userId: string, values: Record<string, PalbaseFlagValue>): Promise<PalbaseResult<PalbaseSetOverridesResult>>;
1030
+ /** Clear one override for a user, restoring the project (system) default. */
1031
+ clearOverrideForUser(userId: string, key: string): Promise<PalbaseResult<PalbaseClearOverrideResult>>;
1032
+ /** Clear all overrides for a user, restoring project (system) defaults. */
1033
+ clearAllOverridesForUser(userId: string): Promise<PalbaseResult<PalbaseClearAllOverridesResult>>;
1034
+ /** Apply override writes across many users in one request (max 1000 ops). */
1035
+ batchSetOverrides(operations: ReadonlyArray<PalbaseBatchOverrideOperation>): Promise<PalbaseResult<PalbaseBatchSetOverridesResult>>;
1036
+ }
1037
+ /**
1038
+ * Flags client available as the `Flags` singleton (and on `ctx.flags`).
970
1039
  * Evaluate feature flags server-side (managed-runtime key — user targeting
971
1040
  * is optional via context).
1041
+ *
1042
+ * Writes follow the `Database` model:
1043
+ * — `setOverride(key, value)` (default) overrides the flag for the CURRENT
1044
+ * request user; no userId argument, no admin power required. It errors when
1045
+ * there is no signed-in user (an anonymous request).
1046
+ * — `asService()` returns the {@link PalbaseFlagsServiceClient} carrying the
1047
+ * cross-user admin writes (`setOverrideForUser`, …) for an arbitrary target
1048
+ * user. Greppable + explicit, exactly like `Database.asService()`.
1049
+ *
1050
+ * Reads (`isEnabled`/`getVariant`/`get`/`getAll`) stay on this default surface
1051
+ * and are already current-user-scoped via the request identity.
972
1052
  */
973
1053
  interface PalbaseFlagsClient {
974
1054
  /** Is a flag enabled for the given context? */
@@ -977,6 +1057,28 @@ interface PalbaseFlagsClient {
977
1057
  getVariant(flagName: string, context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlagVariant>>;
978
1058
  /** Get all flags for the project. */
979
1059
  getAll(context?: PalbaseFlagContext): Promise<PalbaseResult<PalbaseFlag[]>>;
1060
+ /**
1061
+ * Set (or replace) a single feature-flag override for the CURRENT REQUEST
1062
+ * USER. No userId argument — the override is bound to the signed-in user the
1063
+ * handler is serving, so a handler can flip a flag for that user without
1064
+ * admin power. The override shadows the project (system) default for that
1065
+ * user until cleared.
1066
+ *
1067
+ * Errors when there is no signed-in user (an anonymous request); reach for
1068
+ * `Flags.asService().setOverrideForUser(userId, key, value)` to write a flag
1069
+ * for an arbitrary (cross-user) target.
1070
+ *
1071
+ * @example
1072
+ * await Flags.setOverride("new_checkout", true);
1073
+ */
1074
+ setOverride(key: string, value: PalbaseFlagValue): Promise<PalbaseResult<PalbaseSetOverrideResult>>;
1075
+ /**
1076
+ * Return the cross-user admin write surface ({@link PalbaseFlagsServiceClient}).
1077
+ * Use sparingly and explicitly — the default `Flags.setOverride(...)` path is
1078
+ * bound to the current request user; `asService()` is how you write a flag
1079
+ * override for an ARBITRARY user. Mirrors `Database.asService()`.
1080
+ */
1081
+ asService(): PalbaseFlagsServiceClient;
980
1082
  }
981
1083
  /**
982
1084
  * Push sub-client surface (server-only: fan-out to users / topics).
@@ -1471,4 +1573,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
1471
1573
  */
1472
1574
  type AuthSpec = boolean | Partial<AuthConfig>;
1473
1575
 
1474
- export { type PalbaseDocumentSnapshot 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 PalbaseBucketClient as G, HttpError as H, type PalbaseCmsClient as I, type PalbaseCmsFindOneOptions as J, type PalbaseCmsFindOptions as K, type Logger as L, type Middleware as M, NotFound as N, type PalbaseCohortQueryInput as O, type PBRequest as P, type QueueClient as Q, type RateLimitConfig as R, type PalbaseCohortResult as S, type PalbaseCollectionRef as T, type User as U, type PalbaseCountQueryInput as V, type PalbaseCountResult as W, type PalbaseCreateLinkParams as X, type PalbaseDeviceInfo as Y, type PalbaseDeviceTokenView as Z, type PalbaseDocumentRef as _, type PalbaseModuleClients as a, Unauthorized as a$, type PalbaseEmailClient as a0, type PalbaseEmailSendParams as a1, type PalbaseEmailSendResponse as a2, type PalbaseEventNamesResult as a3, type PalbaseEventsQueryInput as a4, type PalbaseEventsResult as a5, type PalbaseFileObject as a6, type PalbaseFlag as a7, type PalbaseFlagContext as a8, type PalbaseFlagVariant as a9, type PalbasePushSendParams as aA, type PalbasePushSendResponse as aB, type PalbaseQrCodeOptions as aC, type PalbaseQuerySnapshot as aD, type PalbaseRealtimeChannel as aE, type PalbaseRealtimeClient as aF, type PalbaseRealtimeMessage as aG, type PalbaseRegisterDeviceParams as aH, type PalbaseResult as aI, type PalbaseRetentionQueryInput as aJ, type PalbaseRetentionResult as aK, type PalbaseSession as aL, type PalbaseSignedUrlResponse as aM, type PalbaseSmsClient as aN, type PalbaseSmsSendParams as aO, type PalbaseSmsSendResponse as aP, type PalbaseTransformOptions as aQ, type PalbaseUpdateLinkParams as aR, type PalbaseUploadOptions as aS, type PalbaseUser as aT, type PalbaseUserDetailResult as aU, type PalbaseUsersQueryInput as aV, type PalbaseUsersResult as aW, type PalbaseVerifyRequestSignatureParams as aX, type PalbaseWhereOperator as aY, TooManyRequests as aZ, type TxClient as a_, type PalbaseFunctionsClient as aa, type PalbaseFunnelQueryInput as ab, type PalbaseFunnelResult as ac, type PalbaseIdentifyTraits as ad, type PalbaseInboxClient as ae, type PalbaseInboxListOptions as af, type PalbaseInboxListResult as ag, type PalbaseInboxMessage as ah, type PalbaseInboxSendParams as ai, type PalbaseInboxSendResponse as aj, type PalbaseInitialLink as ak, type PalbaseInvokeOptions as al, type PalbaseLink as am, type PalbaseLinkAnalytics as an, type PalbaseLinkDetails as ao, type PalbaseLinksClient as ap, type PalbaseListLinksOptions as aq, type PalbaseListLinksResult as ar, type PalbaseListOptions as as, type PalbaseMatchParams as at, type PalbaseMultiChannelResponse as au, type PalbaseOverviewResult as av, type PalbasePreferences as aw, type PalbasePreferencesClient as ax, type PalbasePublicUrlResponse as ay, type PalbasePushClient as az, type PalbaseDocsClient as b, defineMiddleware as b0, type PalbaseFlagsClient as c, type PalbaseNotificationsClient as d, type PalbaseStorageClient as e, type AuthConfig as f, type ClientInfo as g, Conflict as h, type DBOps as i, type ErrorMap as j, type ErrorThrowers as k, Forbidden as l, type HttpMethod as m, type MiddlewareContext as n, type MiddlewareHandler as o, PalError as p, type PalbaseAnalyticsClient as q, type PalbaseAnalyticsManagementNamespace as r, type PalbaseAnalyticsProperties as s, type PalbaseAnalyticsQueryNamespace as t, type PalbaseAttestAndroidParams as u, type PalbaseAttestAndroidResult as v, type PalbaseAttestiOSParams as w, type PalbaseAttestiOSResult as x, type PalbaseAuthClient as y, type PalbaseBindDeviceParams as z };
1576
+ export { type PalbaseCreateLinkParams 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 PalbaseBatchSetOverridesResult as G, HttpError as H, type PalbaseBindDeviceParams as I, type PalbaseBucketClient as J, type PalbaseClearAllOverridesResult as K, type Logger as L, type Middleware as M, NotFound as N, type PalbaseClearOverrideResult as O, type PBRequest as P, type QueueClient as Q, type RateLimitConfig as R, type PalbaseCmsClient as S, type PalbaseCmsFindOneOptions as T, type User as U, type PalbaseCmsFindOptions as V, type PalbaseCohortQueryInput as W, type PalbaseCohortResult as X, type PalbaseCollectionRef as Y, type PalbaseCountQueryInput as Z, type PalbaseCountResult as _, type PalbaseModuleClients as a, type PalbaseUploadOptions as a$, type PalbaseDeviceInfo as a0, type PalbaseDeviceTokenView as a1, type PalbaseDocumentRef as a2, type PalbaseDocumentSnapshot as a3, type PalbaseEmailClient as a4, type PalbaseEmailSendParams as a5, type PalbaseEmailSendResponse as a6, type PalbaseEventNamesResult as a7, type PalbaseEventsQueryInput as a8, type PalbaseEventsResult as a9, type PalbaseMatchParams as aA, type PalbaseMultiChannelResponse as aB, type PalbaseOverviewResult as aC, type PalbasePreferences as aD, type PalbasePreferencesClient as aE, type PalbasePublicUrlResponse as aF, type PalbasePushClient as aG, type PalbasePushSendParams as aH, type PalbasePushSendResponse as aI, type PalbaseQrCodeOptions as aJ, type PalbaseQuerySnapshot as aK, type PalbaseRealtimeChannel as aL, type PalbaseRealtimeClient as aM, type PalbaseRealtimeMessage as aN, type PalbaseRegisterDeviceParams as aO, type PalbaseResult as aP, type PalbaseRetentionQueryInput as aQ, type PalbaseRetentionResult as aR, type PalbaseSession as aS, type PalbaseSetOverrideResult as aT, type PalbaseSetOverridesResult as aU, type PalbaseSignedUrlResponse as aV, type PalbaseSmsClient as aW, type PalbaseSmsSendParams as aX, type PalbaseSmsSendResponse as aY, type PalbaseTransformOptions as aZ, type PalbaseUpdateLinkParams as a_, type PalbaseFileObject as aa, type PalbaseFlag as ab, type PalbaseFlagContext as ac, type PalbaseFlagSource as ad, type PalbaseFlagValue as ae, type PalbaseFlagVariant as af, type PalbaseFlagsServiceClient as ag, type PalbaseFunctionsClient as ah, type PalbaseFunnelQueryInput as ai, type PalbaseFunnelResult as aj, type PalbaseIdentifyTraits as ak, type PalbaseInboxClient as al, type PalbaseInboxListOptions as am, type PalbaseInboxListResult as an, type PalbaseInboxMessage as ao, type PalbaseInboxSendParams as ap, type PalbaseInboxSendResponse as aq, type PalbaseInitialLink as ar, type PalbaseInvokeOptions as as, type PalbaseLink as at, type PalbaseLinkAnalytics as au, type PalbaseLinkDetails as av, type PalbaseLinksClient as aw, type PalbaseListLinksOptions as ax, type PalbaseListLinksResult as ay, type PalbaseListOptions as az, type PalbaseDocsClient as b, type PalbaseUser as b0, type PalbaseUserDetailResult as b1, type PalbaseUsersQueryInput as b2, type PalbaseUsersResult as b3, type PalbaseVerifyRequestSignatureParams as b4, type PalbaseWhereOperator as b5, TooManyRequests as b6, type TxClient as b7, Unauthorized as b8, defineMiddleware as b9, type PalbaseFlagsClient as c, type PalbaseNotificationsClient as d, type PalbaseStorageClient as e, type AuthConfig as f, type ClientInfo as g, Conflict as h, type DBOps as i, type ErrorMap as j, type ErrorThrowers as k, Forbidden as l, type HttpMethod as m, type MiddlewareContext as n, type MiddlewareHandler as o, PalError as p, type PalbaseAnalyticsClient as q, type PalbaseAnalyticsManagementNamespace as r, type PalbaseAnalyticsProperties as s, type PalbaseAnalyticsQueryNamespace as t, type PalbaseAttestAndroidParams as u, type PalbaseAttestAndroidResult as v, type PalbaseAttestiOSParams as w, type PalbaseAttestiOSResult as x, type PalbaseAuthClient as y, type PalbaseBatchOverrideOperation as z };
@@ -1,5 +1,5 @@
1
1
  import { Tables, TableTypes } from './db/env.js';
2
- import { D as DBClient } from './endpoint-BEHjfvFH.js';
2
+ import { D as DBClient } from './endpoint-CfdiQbVC.js';
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.cjs';
2
- import { D as DBClient } from './endpoint-BEHjfvFH.cjs';
2
+ import { D as DBClient } from './endpoint-CfdiQbVC.cjs';
3
3
 
4
4
  /** On delete action for foreign key references. */
5
5
  type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
package/dist/index.cjs CHANGED
@@ -183,7 +183,34 @@ var Cache = makeServiceProxy("Cache");
183
183
  var Queue = makeServiceProxy("Queue");
184
184
  var Log = makeServiceProxy("Log");
185
185
  var Notifications = makeServiceProxy("Notifications");
186
- var Flags = makeServiceProxy("Flags");
186
+ var rawFlags = makeServiceProxy("Flags");
187
+ var Flags = Object.assign(
188
+ {
189
+ isEnabled(flagName, context) {
190
+ return rawFlags.isEnabled(flagName, context);
191
+ },
192
+ getVariant(flagName, context) {
193
+ return rawFlags.getVariant(flagName, context);
194
+ },
195
+ getAll(context) {
196
+ return rawFlags.getAll(context);
197
+ },
198
+ setOverride(key, value) {
199
+ return rawFlags.setOverride(key, value);
200
+ }
201
+ },
202
+ {
203
+ /**
204
+ * Lazily resolve the runtime's cross-user sibling on each call. We do NOT
205
+ * cache it: `rawFlags.asService()` reads the CURRENT request scope through
206
+ * the runtime proxy, so caching would leak one request's sibling into
207
+ * another concurrent request. Mirrors `Database.asService()`.
208
+ */
209
+ asService() {
210
+ return rawFlags.asService();
211
+ }
212
+ }
213
+ );
187
214
 
188
215
  // src/db/policy.ts
189
216
  var PolicyBuilder = class {