pyric-admin 0.1.0-alpha.7 → 0.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app/index.js CHANGED
@@ -1,192 +1,94 @@
1
1
  /**
2
- * `pyric-admin/app` — Phase 3 initializeApp surface (ADR-001 D6) plus the
3
- * default-app registry and AMBIENT INIT (adoption experience, layer 3).
2
+ * `pyric-admin/app` — sandbox-only admin app registry.
4
3
  *
5
- * Mirror shape: at cutover this becomes `pyric-admin/app` and is the
6
- * single entry point where the sandbox-vs-prod choice is made for the
7
- * admin surface. Every `pyric-admin/*` subpath inspects the handle's
8
- * brand for backend dispatch.
9
- *
10
- * Current shadow scope:
11
- * - `initializeApp({ credential, ... })` — prod-backed (live;
12
- * delegates to `firebase-admin/app.initializeApp`).
13
- * - `initializeApp({ sandbox })` — sandbox-backed (live).
14
- * - `initializeApp()` — BARE, zero pyric identifiers in app code. The
15
- * environment decides the backend (see "Ambient init" below).
16
- * - Per-subpath adapter dispatch via the brand: implemented in
17
- * `pyric-admin/{auth,database,storage}` via structural
18
- * checks on the `app` argument. Phase 4 commits use property
19
- * probing today; cutover swaps to brand-symbol reads.
20
- *
21
- * ── Default-app registry ──────────────────────────────────────────────
22
- *
23
- * Mirrors `firebase-admin/app`'s lifecycle exactly (oracle:
24
- * `firebase-admin/lib/app/lifecycle.js`):
25
- *
26
- * - `initializeApp(config?, name?)` registers under `'[DEFAULT]'` when
27
- * unnamed; `getApp(name?)` / `getApps()` / `deleteApp(app)` read it.
28
- * - Duplicate-name errors carry firebase-admin's codes and message
29
- * text: `app/duplicate-app` for a config'd re-init with a different
30
- * configuration, `app/invalid-app-options` for a bare-vs-config'd
31
- * mismatch (firebase-admin's autoInit mismatch), `app/no-app` from
32
- * `getApp` on a missing name, `app/invalid-app-name` for a
33
- * non-string/empty name. Errors reuse firebase-admin's own
34
- * `FirebaseAppError` class, so `instanceof`, `constructor.name`,
35
- * `.code`, and message text match production byte-for-byte
36
- * (oracle: `admin-app-*` observations).
37
- * - Idempotency mirror: a bare `initializeApp()` repeated for the same
38
- * name returns the existing auto-initialized app (firebase-admin's
39
- * autoInit path); `initializeApp({ sandbox })` repeated with the
40
- * SAME `Sandbox` reference returns the existing app (the reference
41
- * is our deep-equal analog — sandboxes have identity, not value
42
- * equality); prod re-inits delegate the equality decision to
43
- * firebase-admin itself (deep-equal options → same app; credential /
44
- * httpAgent present → `app/invalid-app-options`, exactly upstream).
45
- *
46
- * ── Ambient init (bare `initializeApp()`) ─────────────────────────────
47
- *
48
- * The user's server code contains ZERO pyric identifiers — bare
49
- * `initializeApp()` + no-arg `getDatabase()` / `getAuth()`. The
50
- * environment picks the backend:
51
- *
52
- * - `PYRIC_SANDBOX` unset → exactly firebase-admin's behavior:
53
- * delegate to `firebase-admin/app.initializeApp()` (FIREBASE_CONFIG
54
- * env + application-default credentials), register the prod arm.
55
- * - `PYRIC_SANDBOX=remote` or `remote:<url>` → obtain a remote sandbox
56
- * handle from the factory installed by `pyric-tools/register` at
57
- * `globalThis[REMOTE_SANDBOX_FACTORY]`
58
- * (`Symbol.for('pyric.remote.sandboxFactory')`) and register the
59
- * sandbox arm. One activation line is logged to stderr. If the env
60
- * is set but no factory is installed, throw with remediation (run
61
- * under `pyric dev`, or add `--import pyric-tools/register` to
62
- * NODE_OPTIONS).
63
- * - Production guard: refuses to route to a sandbox when
64
- * `NODE_ENV === 'production'`, unless `PYRIC_SANDBOX_FORCE=1`.
65
- *
66
- * Ambient resolution happens ONLY on the bare call — any explicit
67
- * config (`{ sandbox }` or prod `AppOptions`, even `{}`) bypasses the
68
- * env entirely, so pyric-aware code keeps full control.
4
+ * Production selection happens before this module loads: activated Node
5
+ * processes resolve `firebase-admin/app` here, while inactive applications
6
+ * continue resolving their own `firebase-admin/app` package unchanged.
69
7
  */
70
8
  import { REMOTE_SANDBOX_FACTORY, } from 'pyric/sandbox';
71
- import { initializeApp as initializeFirebaseAdminApp, deleteApp as deleteFirebaseAdminApp, FirebaseAppError, } from 'firebase-admin/app';
72
- /**
73
- * Brand on every PyricAdminApp. Matches the symbol used in
74
- * `pyric/app` so a future shared `pyric/runtime` package can
75
- * unify dispatch helpers across both packages.
76
- */
9
+ import { assertAdminAppActive, markAdminAppDeleted } from './lifecycle.js';
10
+ /** Brand carried by every sandbox admin app. */
77
11
  export const ADMIN_APP_TARGET = Symbol.for('pyric.admin.app.target');
78
- /** firebase-admin's default app name — `'[DEFAULT]'`. */
12
+ /** firebase-admin's default app name. */
79
13
  export const DEFAULT_APP_NAME = '[DEFAULT]';
80
14
  /**
81
- * App-lifecycle errors reuse `firebase-admin`'s own exported
82
- * `FirebaseAppError` so the thrown error's class, `constructor.name`,
83
- * `.code` (`app/no-app`, `app/duplicate-app`, `app/invalid-app-options`,
84
- * `app/invalid-app-name`, `app/invalid-argument`), and message text match
85
- * production byte-for-byte (oracle: `admin-app-*` observations assert
86
- * `errorName: "FirebaseAppError"`). The published typings declare only the
87
- * base `Error` constructor, but the real runtime class is
88
- * `new FirebaseAppError(code, message)` where `code` becomes `app/<code>` —
89
- * the typed cast recovers it.
15
+ * Firebase Functions' ESM runtime statically imports this credential factory
16
+ * while linking its database provider. Pyric initializes the sandbox app
17
+ * before that provider executes, so the factory is not used by supported
18
+ * Functions flows. Keep the named export link-compatible, but fail clearly if
19
+ * application code asks the development sandbox for production credentials.
90
20
  */
91
- const AdminAppError = FirebaseAppError;
92
- /** @deprecated Alias kept for pre-merge call sites; errors ARE `FirebaseAppError`. */
93
- export const PyricAdminAppError = AdminAppError;
94
- // ─── Registry ───────────────────────────────────────────────────────────
95
- //
96
- // Module-level, matching firebase-admin's `defaultAppStore` (one store per
97
- // module instance). `autoInitApps` tracks which registered apps came from a
98
- // BARE `initializeApp()` — firebase-admin's `autoInit` flag — so the
99
- // bare-vs-config'd mismatch throws exactly like upstream.
100
- const appRegistry = new Map();
101
- const autoInitApps = new WeakSet();
102
- /** firebase-admin's app-name validation, verbatim message. */
21
+ export function applicationDefault() {
22
+ throw new Error('pyric-admin/app: applicationDefault() is unavailable in the sandbox. ' +
23
+ 'Pyric development does not use production credentials.');
24
+ }
25
+ /** Local error with the observable firebase-admin app-error shape. */
26
+ class FirebaseAppError extends Error {
27
+ code;
28
+ constructor(code, message) {
29
+ super(message);
30
+ this.name = 'FirebaseAppError';
31
+ this.code = `app/${code}`;
32
+ }
33
+ }
34
+ // Node may evaluate this ESM-only mirror through distinct require(esm) and
35
+ // import module records when the register hook rewrites both CJS and ESM
36
+ // Firebase consumers. Firebase Admin's app registry is process-wide, so keep
37
+ // the mirror registry behind Symbol.for as well: both module records must see
38
+ // the same default app and sandbox handle.
39
+ const APP_REGISTRY = Symbol.for('pyric.admin.app.registry');
40
+ const AMBIENT_APPS = Symbol.for('pyric.admin.app.ambientApps');
41
+ const globalRegistry = globalThis;
42
+ const appRegistry = globalRegistry[APP_REGISTRY] ??= new Map();
43
+ const ambientApps = globalRegistry[AMBIENT_APPS] ??= new WeakSet();
103
44
  function validateAppName(name) {
104
45
  if (typeof name !== 'string' || name === '') {
105
- throw new AdminAppError('invalid-app-name', `Invalid Firebase app name "${String(name)}" provided. App name must be a non-empty string.`);
46
+ throw new FirebaseAppError('invalid-app-name', `Invalid Firebase app name "${String(name)}" provided. App name must be a non-empty string.`);
106
47
  }
107
48
  }
108
- /** firebase-admin's message for every same-name/different-config case. */
109
49
  function alreadyExists(name, code) {
110
- return new AdminAppError(code, `A Firebase app named "${name}" already exists with a different configuration.`);
50
+ return new FirebaseAppError(code, `A Firebase app named "${name}" already exists with a different configuration.`);
111
51
  }
112
52
  /**
113
- * Initialize a Pyric admin app and register it under `name`
114
- * (default `'[DEFAULT]'`), mirroring `firebase-admin/app.initializeApp`.
115
- *
116
- * @example
117
- * ```ts
118
- * // Ambient (zero pyric identifiers — environment decides)
119
- * import { initializeApp } from 'pyric-admin/app';
120
- * const app = initializeApp();
53
+ * Initialize a sandbox admin app.
121
54
  *
122
- * // Prod-backed
123
- * import { applicationDefault } from 'firebase-admin/app';
124
- * const app = initializeApp({ credential: applicationDefault() });
125
- *
126
- * // Sandbox-backed
127
- * import { initializeSandbox } from 'pyric/sandbox';
128
- * const app = initializeApp({ sandbox: initializeSandbox() });
129
- * ```
55
+ * An explicit `{ sandbox }` config binds an in-process or remote sandbox.
56
+ * A bare call resolves the remote sandbox factory installed by
57
+ * `@pyric/cli/register`. Production callers must import `firebase-admin/app`
58
+ * without Pyric activation instead of passing production options here.
130
59
  */
131
60
  export function initializeApp(config, name = DEFAULT_APP_NAME) {
132
61
  validateAppName(name);
133
62
  const existing = appRegistry.get(name);
134
- // ── Bare call: ambient resolution ────────────────────────────────────
135
63
  if (config === undefined) {
136
64
  if (existing !== undefined) {
137
- // firebase-admin: two autoInit calls return the same app; an
138
- // autoInit call against a config'd app is an options mismatch.
139
- if (autoInitApps.has(existing))
65
+ if (ambientApps.has(existing))
140
66
  return existing;
141
67
  throw alreadyExists(name, 'invalid-app-options');
142
68
  }
143
69
  const app = initializeAmbientApp(name);
144
70
  appRegistry.set(name, app);
145
- autoInitApps.add(app);
71
+ ambientApps.add(app);
146
72
  return app;
147
73
  }
148
- // ── Explicit sandbox config ──────────────────────────────────────────
149
- if (isSandboxConfig(config)) {
150
- if (existing !== undefined) {
151
- // Reference identity is the deep-equal analog for sandboxes.
152
- if (!autoInitApps.has(existing) &&
153
- existing[ADMIN_APP_TARGET] === 'sandbox' &&
154
- existing.sandbox === config.sandbox) {
155
- return existing;
156
- }
157
- throw alreadyExists(name, autoInitApps.has(existing) ? 'invalid-app-options' : 'duplicate-app');
158
- }
159
- const app = {
160
- [ADMIN_APP_TARGET]: 'sandbox',
161
- sandbox: config.sandbox,
162
- name,
163
- };
164
- appRegistry.set(name, app);
165
- return app;
74
+ if (!isSandboxConfig(config)) {
75
+ throw new TypeError('pyric-admin/app is a sandbox-only mirror. Production applications must ' +
76
+ 'load firebase-admin/app without Pyric activation.');
166
77
  }
167
- // ── Explicit prod options ────────────────────────────────────────────
168
78
  if (existing !== undefined) {
169
- if (existing[ADMIN_APP_TARGET] === 'prod' && !autoInitApps.has(existing)) {
170
- // Delegate the equality decision to firebase-admin itself: deep-
171
- // equal options return the same AdminApp; credential / httpAgent
172
- // re-inits throw app/invalid-app-options; different options throw
173
- // app/duplicate-app — all with upstream's exact messages.
174
- const adminApp = initializeFirebaseAdminApp(config, name);
175
- if (adminApp === existing.adminApp)
176
- return existing;
177
- }
178
- throw alreadyExists(name, autoInitApps.has(existing) ? 'invalid-app-options' : 'duplicate-app');
79
+ if (!ambientApps.has(existing) && existing.sandbox === config.sandbox)
80
+ return existing;
81
+ throw alreadyExists(name, ambientApps.has(existing) ? 'invalid-app-options' : 'duplicate-app');
179
82
  }
180
- const adminApp = initializeFirebaseAdminApp(config, name);
181
- const app = { [ADMIN_APP_TARGET]: 'prod', adminApp, name };
83
+ const app = {
84
+ [ADMIN_APP_TARGET]: 'sandbox',
85
+ sandbox: config.sandbox,
86
+ name,
87
+ };
182
88
  appRegistry.set(name, app);
183
89
  return app;
184
90
  }
185
- /**
186
- * Return the registered app for `name` (default `'[DEFAULT]'`).
187
- * Mirrors `firebase-admin/app.getApp` — including the exact `app/no-app`
188
- * error text on a miss.
189
- */
91
+ /** Return the registered app for `name`. */
190
92
  export function getApp(name = DEFAULT_APP_NAME) {
191
93
  validateAppName(name);
192
94
  const app = appRegistry.get(name);
@@ -194,52 +96,34 @@ export function getApp(name = DEFAULT_APP_NAME) {
194
96
  const lead = name === DEFAULT_APP_NAME
195
97
  ? 'The default Firebase app does not exist. '
196
98
  : `Firebase app named "${name}" does not exist. `;
197
- throw new AdminAppError('no-app', lead + 'Make sure you call initializeApp() before using any of the Firebase services.');
99
+ throw new FirebaseAppError('no-app', lead + 'Make sure you call initializeApp() before using any of the Firebase services.');
198
100
  }
199
101
  return app;
200
102
  }
201
- /**
202
- * A copy of the list of all registered apps.
203
- * Mirrors `firebase-admin/app.getApps`.
204
- */
103
+ /** Return a copy of the app registry. */
205
104
  export function getApps() {
206
105
  return Array.from(appRegistry.values());
207
106
  }
208
- /**
209
- * Remove `app` from the registry, mirroring `firebase-admin/app.deleteApp`.
210
- * Prod-backed apps also delete the underlying firebase-admin app (freeing
211
- * its resources and its slot in firebase-admin's own registry, so the
212
- * name can be re-initialized). Sandbox-backed apps only deregister — the
213
- * `Sandbox` handle's lifetime belongs to its creator.
214
- */
107
+ /** Remove a sandbox app from the registry. */
215
108
  export function deleteApp(app) {
216
109
  if (typeof app !== 'object' || app === null || !(ADMIN_APP_TARGET in app)) {
217
- throw new AdminAppError('invalid-argument', 'Invalid app argument.');
110
+ throw new FirebaseAppError('invalid-argument', 'Invalid app argument.');
218
111
  }
219
- // Make sure the given app is actually registered (throws app/no-app).
112
+ assertAdminAppActive(app);
220
113
  const existing = getApp(app.name);
221
114
  appRegistry.delete(existing.name);
222
- if (existing[ADMIN_APP_TARGET] === 'prod') {
223
- return deleteFirebaseAdminApp(existing.adminApp);
224
- }
115
+ markAdminAppDeleted(existing);
225
116
  return Promise.resolve();
226
117
  }
227
- // ─── Ambient init ───────────────────────────────────────────────────────
228
- /**
229
- * Resolve a bare `initializeApp()` from the environment. See the
230
- * module-level "Ambient init" docs for the full contract.
231
- */
232
118
  function initializeAmbientApp(name) {
233
119
  const env = process.env.PYRIC_SANDBOX;
234
120
  if (env === undefined || env.trim() === '') {
235
- // Unset → exactly today's prod behavior: firebase-admin's autoInit
236
- // (FIREBASE_CONFIG env options + application-default credentials).
237
- const adminApp = initializeFirebaseAdminApp(undefined, name);
238
- return { [ADMIN_APP_TARGET]: 'prod', adminApp, name };
121
+ throw new Error('pyric-admin/app is a sandbox-only mirror and no sandbox is active. ' +
122
+ 'Run under `pyric dev`, set PYRIC_SANDBOX with @pyric/cli/register, ' +
123
+ 'or load firebase-admin/app without Pyric activation for production.');
239
124
  }
240
125
  const opts = parsePyricSandboxEnv(env);
241
- if (process.env.NODE_ENV === 'production' &&
242
- process.env.PYRIC_SANDBOX_FORCE !== '1') {
126
+ if (process.env.NODE_ENV === 'production' && process.env.PYRIC_SANDBOX_FORCE !== '1') {
243
127
  throw new Error('pyric-admin: PYRIC_SANDBOX is set but NODE_ENV is "production" — ' +
244
128
  'refusing to route firebase-admin to a development sandbox. ' +
245
129
  'Unset PYRIC_SANDBOX in production, or set PYRIC_SANDBOX_FORCE=1 ' +
@@ -248,25 +132,13 @@ function initializeAmbientApp(name) {
248
132
  const factory = globalThis[REMOTE_SANDBOX_FACTORY];
249
133
  if (typeof factory !== 'function') {
250
134
  throw new Error(`pyric-admin: PYRIC_SANDBOX=${env} is set but no remote sandbox ` +
251
- 'factory is installed (globalThis[Symbol.for(' +
252
- "'pyric.remote.sandboxFactory')] is absent). Run your server " +
253
- 'under `pyric dev`, or add `--import pyric-tools/register` to ' +
254
- 'NODE_OPTIONS.');
135
+ "factory is installed (globalThis[Symbol.for('pyric.remote.sandboxFactory')] is absent). " +
136
+ 'Run your server under `pyric dev`, or add `--import @pyric/cli/register` to NODE_OPTIONS.');
255
137
  }
256
138
  const sandbox = factory(opts);
257
139
  process.stderr.write(`pyric: firebase-admin routed to sandbox${opts.url !== undefined ? ` at ${opts.url}` : ''}\n`);
258
140
  return { [ADMIN_APP_TARGET]: 'sandbox', sandbox, name };
259
141
  }
260
- /**
261
- * Parse the `PYRIC_SANDBOX` activator value.
262
- *
263
- * - `remote` → `{}` (factory discovers the running `pyric dev`)
264
- * - `remote:<url>` → `{ url }` (everything after the FIRST colon —
265
- * URLs contain colons, so only the mode prefix is split off)
266
- *
267
- * Anything else throws: an unrecognized activator must never silently
268
- * fall through to prod (mode-by-side-effect in the failure direction).
269
- */
270
142
  function parsePyricSandboxEnv(env) {
271
143
  const value = env.trim();
272
144
  if (value === 'remote')
@@ -281,17 +153,12 @@ function parsePyricSandboxEnv(env) {
281
153
  return { url };
282
154
  }
283
155
  throw new Error(`pyric-admin: unrecognized PYRIC_SANDBOX value "${env}". Supported ` +
284
- 'values: "remote" (auto-discover the running `pyric dev`) or ' +
285
- '"remote:<url>".');
156
+ 'values: "remote" (auto-discover the running `pyric dev`) or "remote:<url>".');
286
157
  }
287
- // ─── Guards ─────────────────────────────────────────────────────────────
288
158
  function isSandboxConfig(config) {
289
159
  return typeof config === 'object' && config !== null && 'sandbox' in config;
290
160
  }
291
161
  export function isSandboxAdminApp(app) {
292
162
  return app[ADMIN_APP_TARGET] === 'sandbox';
293
163
  }
294
- export function isProdAdminApp(app) {
295
- return app[ADMIN_APP_TARGET] === 'prod';
296
- }
297
164
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,OAAO,EACL,sBAAsB,GAIvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,aAAa,IAAI,0BAA0B,EAC3C,SAAS,IAAI,sBAAsB,EACnC,gBAAgB,GAGjB,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAIrE,yDAAyD;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAoB5C;;;;;;;;;;GAUG;AACH,MAAM,aAAa,GAAG,gBAGgB,CAAC;AAEvC,sFAAsF;AACtF,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAGhD,2EAA2E;AAC3E,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,qEAAqE;AACrE,0DAA0D;AAE1D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;AACrD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAiB,CAAC;AAElD,8DAA8D;AAC9D,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EA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EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,2DAA2D;gBACzD,iEAAiE;gBACjE,kDAAkD,CACrD,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,KAAK,CACb,kDAAkD,GAAG,eAAe;QAClE,6EAA6E,CAChF,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,MAAgC;IACvD,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,SAAS,IAAI,MAAM,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAkB;IAClD,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,SAAS,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** Internal lifecycle guard shared by every pyric-admin service factory. */
2
+ export declare function assertAdminAppActive(app: object & {
3
+ readonly name: string;
4
+ }): void;
5
+ /** Tombstone a wrapper while leaving the caller-owned Sandbox alive. */
6
+ export declare function markAdminAppDeleted(app: object): void;
7
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/app/lifecycle.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQlF;AAED,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAErD"}
@@ -0,0 +1,15 @@
1
+ const deletedApps = new WeakSet();
2
+ /** Internal lifecycle guard shared by every pyric-admin service factory. */
3
+ export function assertAdminAppActive(app) {
4
+ if (!deletedApps.has(app))
5
+ return;
6
+ const error = new Error(`Firebase app named "${app.name}" has already been deleted.`);
7
+ error.name = 'FirebaseAppError';
8
+ error.code = 'app/app-deleted';
9
+ throw error;
10
+ }
11
+ /** Tombstone a wrapper while leaving the caller-owned Sandbox alive. */
12
+ export function markAdminAppDeleted(app) {
13
+ deletedApps.add(app);
14
+ }
15
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/app/lifecycle.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,IAAI,OAAO,EAAU,CAAC;AAE1C,4EAA4E;AAC5E,MAAM,UAAU,oBAAoB,CAAC,GAAuC;IAC1E,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO;IAClC,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,uBAAuB,GAAG,CAAC,IAAI,6BAA6B,CACjC,CAAC;IAC9B,KAAK,CAAC,IAAI,GAAG,kBAAkB,CAAC;IAChC,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,MAAM,KAAK,CAAC;AACd,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
@@ -1,90 +1,78 @@
1
- /**
2
- * `pyric-admin/auth` — Phase 3 (branded-app dispatch) + Phase 4b
3
- * (minimal in-memory sandbox backend).
4
- *
5
- * Mirrors `firebase-admin/auth` for a useful subset of methods. The
6
- * `app` argument is the branded handle from `pyric-admin/app`
7
- * ({@link PyricAdminApp}); the brand symbol picks the backend:
8
- *
9
- * - **Prod path** (`app[ADMIN_APP_TARGET] === 'prod'`) — delegates to
10
- * `firebase-admin/auth`'s `getAuth(app.adminApp)` and returns the
11
- * production `Auth` instance unchanged. Drop-in replacement for
12
- * `firebase-admin/auth` so agents already calling it keep their
13
- * exact behavior (tenants, providers, MFA, session cookies, action
14
- * codes, all present on the returned handle).
15
- *
16
- * - **Sandbox path** (`app[ADMIN_APP_TARGET] === 'sandbox'`) — backed
17
- * by an in-memory store keyed off `app.sandbox`. Implements the
18
- * core user-management subset listed below. Tokens are NOT real
19
- * JWTs — they're deterministic strings the same sandbox backend
20
- * parses on `verifyIdToken`. The sandbox backend is intentionally
21
- * minimal: enough to exercise agent code paths that use
22
- * `createUser` / `getUser` / `setCustomUserClaims` /
23
- * `createCustomToken` / `verifyIdToken`, not enough to model a
24
- * real identity platform.
25
- *
26
- * - **Remote sandbox arm** — when the sandbox carries `pyric/sandbox`'s
27
- * remote brand (a Node-side handle onto the browser-hosted
28
- * SharedWorker sandbox from `pyric-tools`' `connectRemoteSandbox()`),
29
- * user CRUD relays over the handle's worker channel instead of the
30
- * in-memory store, so server-created users land in the ONE user pool
31
- * the browser app + Studio share. See the "Remote sandbox arm"
32
- * section below for the details (including the extra methods it
33
- * supports: `updateUser`, `listUsers`).
34
- *
35
- * Surface scope on the sandbox backend (what works):
36
- *
37
- * - {@link getAuth}
38
- * - `Auth.createCustomToken(uid, claims?)` — returns a deterministic
39
- * `pyric-sandbox-custom:${uid}:${json}` string; no signing.
40
- * - `Auth.verifyIdToken(token)` — parses tokens minted by
41
- * `createCustomToken`; returns a {@link DecodedIdToken}-shaped
42
- * object.
43
- * - `Auth.createUser(properties)` — stores a {@link UserRecord}
44
- * in an in-memory `Map<uid, UserRecord>`. Auto-generates a `uid`
45
- * when one is not supplied.
46
- * - `Auth.getUser(uid)` — Map lookup.
47
- * - `Auth.getUserByEmail(email)` — linear scan.
48
- * - `Auth.deleteUser(uid)` — Map delete.
49
- * - `Auth.setCustomUserClaims(uid, claims)` — updates the stored
50
- * `UserRecord.customClaims`.
51
- *
52
- * Sandbox backend — explicitly NOT implemented (throws
53
- * `'not implemented in pyric-admin/auth sandbox backend'` so callers
54
- * get a clear remediation message):
55
- *
56
- * - Tenancy: `tenantManager` and any per-tenant call.
57
- * - Identity providers: `createProviderConfig`, `getProviderConfig`,
58
- * `listProviderConfigs`, `updateProviderConfig`,
59
- * `deleteProviderConfig`.
60
- * - Multi-factor: `MultiFactorSettings` on UserRecord is always
61
- * `undefined`; MFA enrollment is unsupported.
62
- * - Session cookies: `createSessionCookie`, `verifySessionCookie`.
63
- * - Action codes / password reset / email link sign-in:
64
- * `generatePasswordResetLink`, `generateEmailVerificationLink`,
65
- * `generateSignInWithEmailLink`, `generateVerifyAndChangeEmailLink`.
66
- * - Bulk operations: `listUsers`, `getUsers`, `deleteUsers`,
67
- * `importUsers`.
68
- * - Revocation: `revokeRefreshTokens`.
69
- * - `getUserByPhoneNumber`, `getUserByProviderUid`.
70
- * - `updateUser` — not required by the brief.
71
- *
72
- * Real `firebase-admin` types are imported with `import type` so
73
- * signatures stay identical to upstream — there's no shape drift to
74
- * keep in sync.
75
- */
76
- import type { Auth as AdminAuth, CreateRequest, DecodedIdToken, UserRecord } from 'firebase-admin/auth';
77
1
  import { type PyricAdminApp } from '../app/index.js';
78
- /**
79
- * The handle returned by {@link getAuth}. On the prod path this is
80
- * literally `firebase-admin/auth`'s `Auth` — every method, every
81
- * tenant/project manager, every shape detail. On the sandbox path it is
82
- * a structurally-compatible `Auth` whose method set is the explicit
83
- * subset documented above; non-implemented methods throw a clear
84
- * remediation error rather than silently returning bad data.
85
- */
86
- export type Auth = AdminAuth;
87
- export type { CreateRequest, DecodedIdToken, UserRecord };
2
+ export interface CreateRequest {
3
+ uid?: string;
4
+ email?: string;
5
+ emailVerified?: boolean;
6
+ displayName?: string | null;
7
+ photoURL?: string | null;
8
+ phoneNumber?: string | null;
9
+ disabled?: boolean;
10
+ password?: string;
11
+ }
12
+ export interface UpdateRequest extends Omit<CreateRequest, 'uid'> {
13
+ multiFactor?: unknown;
14
+ providerToLink?: unknown;
15
+ providersToUnlink?: unknown;
16
+ }
17
+ export interface DecodedIdToken extends Record<string, unknown> {
18
+ aud: string;
19
+ auth_time: number;
20
+ exp: number;
21
+ firebase: {
22
+ identities: Record<string, unknown>;
23
+ sign_in_provider: string;
24
+ };
25
+ iat: number;
26
+ iss: string;
27
+ sub: string;
28
+ uid: string;
29
+ }
30
+ export interface UserMetadata {
31
+ creationTime: string;
32
+ lastSignInTime: string;
33
+ toJSON(): Record<string, unknown>;
34
+ }
35
+ export interface UserInfo {
36
+ providerId: string;
37
+ uid: string;
38
+ displayName?: string;
39
+ email?: string;
40
+ photoURL?: string;
41
+ phoneNumber?: string;
42
+ toJSON(): Record<string, unknown>;
43
+ }
44
+ export interface UserRecord {
45
+ readonly uid: string;
46
+ readonly email?: string;
47
+ readonly emailVerified: boolean;
48
+ readonly displayName?: string;
49
+ readonly photoURL?: string;
50
+ readonly phoneNumber?: string;
51
+ readonly disabled: boolean;
52
+ readonly metadata: UserMetadata;
53
+ readonly providerData: UserInfo[];
54
+ readonly customClaims?: Record<string, unknown>;
55
+ readonly tenantId: string | null;
56
+ toJSON(): Record<string, unknown>;
57
+ }
58
+ export interface ListUsersResult {
59
+ users: UserRecord[];
60
+ pageToken?: string;
61
+ }
62
+ /** Sandbox Auth interface intentionally limited to implemented behavior. */
63
+ export interface Auth {
64
+ readonly app: PyricAdminApp;
65
+ createCustomToken(uid: string, developerClaims?: object): Promise<string>;
66
+ verifyIdToken(idToken: string, checkRevoked?: boolean): Promise<DecodedIdToken>;
67
+ createUser(properties: CreateRequest): Promise<UserRecord>;
68
+ getUser(uid: string): Promise<UserRecord>;
69
+ getUserByEmail(email: string): Promise<UserRecord>;
70
+ deleteUser(uid: string): Promise<void>;
71
+ setCustomUserClaims(uid: string, customUserClaims: object | null): Promise<void>;
72
+ updateUser(uid: string, properties: UpdateRequest): Promise<UserRecord>;
73
+ listUsers(maxResults?: number, pageToken?: string): Promise<ListUsersResult>;
74
+ [key: string]: unknown;
75
+ }
88
76
  /**
89
77
  * Token format minted by `createCustomToken` and parsed by
90
78
  * `verifyIdToken`. Exported as a constant so tests can lock the shape.
@@ -106,25 +94,8 @@ export declare const SANDBOX_TOKEN_PREFIX = "pyric-sandbox-custom";
106
94
  * Return an `Auth` handle for the given app — or for the DEFAULT app when
107
95
  * called with no argument (mirrors firebase-admin's no-arg `getAuth()`:
108
96
  * resolves `'[DEFAULT]'` through `pyric-admin/app`'s registry and throws
109
- * `app/no-app` when nothing has been initialized). Works on all three
110
- * arms — local sandbox, remote sandbox, prod — since dispatch happens on
111
- * whatever brand the resolved app carries.
112
- *
113
- * Dispatches on the brand symbol set by `pyric-admin/app`'s
114
- * `initializeApp`:
115
- * - `'prod'` → delegates to `firebase-admin/auth`'s `getAuth` against
116
- * `app.adminApp`. The returned `Auth` is the production object,
117
- * unmodified.
118
- * - `'sandbox'` → returns an in-memory `Auth` handle backed by an
119
- * {@link AuthStore} keyed off `app.sandbox`. Repeat calls for the
120
- * same sandbox share the store, so writes are visible across
121
- * handles (matches upstream `getAuth(app)` idempotency).
122
- *
123
- * The firebase-admin import is dynamic (`require` at call time) so the
124
- * module's top-level evaluation stays cheap and so sandbox-only
125
- * consumers do not pay the firebase-admin initialization cost. Mirrors
126
- * how `pyric/firestore` defers its firebase init: backends are
127
- * pay-for-what-you-use.
97
+ * `app/no-app` when nothing has been initialized). Local sandboxes use the
98
+ * in-memory store; remote sandboxes relay to the browser-hosted worker.
128
99
  *
129
100
  * @example
130
101
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AAEH,OAAO,KAAK,EACV,IAAI,IAAI,SAAS,EACjB,aAAa,EACb,cAAc,EAGd,UAAU,EACX,MAAM,qBAAqB,CAAC;AAa7B,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG,SAAS,CAAC;AAK7B,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC;AAkF1D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,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