pyric-admin 0.1.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,216 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+ Copyright 2026 David East
205
+
206
+ Licensed under the Apache License, Version 2.0 (the "License");
207
+ you may not use this file except in compliance with the License.
208
+ You may obtain a copy of the License at
209
+
210
+ http://www.apache.org/licenses/LICENSE-2.0
211
+
212
+ Unless required by applicable law or agreed to in writing, software
213
+ distributed under the License is distributed on an "AS IS" BASIS,
214
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
215
+ See the License for the specific language governing permissions and
216
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ <p align="center">
2
+ <img src="https://pyric.dev/pyric-logo.svg" alt="Pyric" width="180" />
3
+ </p>
4
+
5
+ <h1 align="center">Build with Firebase without touching production</h1>
6
+
7
+ <p align="center">Keep the same <code>firebase/*</code> code. Pyric runs it against a local backend during development, then gets out of the way when the app ships to Firebase.</p>
8
+
9
+ <p align="center"><a href="https://pyric.dev">pyric.dev</a></p>
10
+
11
+ <br />
12
+
13
+ Pyric adds a development-only resolution layer to a Firebase application. Run the Vite development server and supported Firebase imports resolve to a browser-local backend. Run a normal production build and those imports resolve to Firebase again. The application source does not branch between the two.
14
+
15
+ The mirrored data services do not connect to a production Firebase project. Local writes cannot delete production data or create Firebase usage charges, and local rules changes do not deploy. Pyric owns the development sandbox and verification workflow. Firebase owns production, with `firebase-tools` or the Firebase Console handling deployment.
16
+
17
+ ## Start a new Firebase application locally
18
+
19
+ Create a Vite application with canonical Firebase imports, Firestore rules, and the Pyric development plugin already configured:
20
+
21
+ ```bash
22
+ npm create pyric my-app
23
+ cd my-app
24
+ npm install
25
+ npm run dev
26
+ ```
27
+
28
+ ## Run an existing Firebase application locally
29
+
30
+ Install the development plugin:
31
+
32
+ ```bash
33
+ npm install --save-dev @pyric/cli
34
+ ```
35
+
36
+ Add it to the existing Vite configuration:
37
+
38
+ ```ts
39
+ // vite.config.ts
40
+ import { defineConfig } from 'vite';
41
+ import { pyricSandbox } from '@pyric/cli/vite';
42
+
43
+ export default defineConfig({
44
+ plugins: [pyricSandbox()],
45
+ });
46
+ ```
47
+
48
+ Start the normal development server:
49
+
50
+ ```bash
51
+ npm run dev
52
+ ```
53
+
54
+ During `vite dev`, the plugin swaps supported `firebase/*` modules at resolution time. The backend runs in a SharedWorker, so tabs on the same development origin use one local backend. Browser-local persistence uses IndexedDB.
55
+
56
+ Pyric Studio is available on the Vite origin at `/__pyric/ui/`. It opens the same backend used by the application.
57
+
58
+ For a static application or a Node process, `pyric dev` provides the same development-only package swap without the Vite plugin. The [CLI reference](packages/cli/docs/reference/cli.md) documents those paths and every command.
59
+
60
+ ## Keep writing Firebase code
61
+
62
+ Application code continues to import Firebase:
63
+
64
+ ```ts
65
+ // src/firebase.ts
66
+ import { initializeApp } from 'firebase/app';
67
+ import { getAuth } from 'firebase/auth';
68
+ import { getFirestore } from 'firebase/firestore';
69
+
70
+ const app = initializeApp({
71
+ apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
72
+ authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
73
+ projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
74
+ });
75
+
76
+ export const auth = getAuth(app);
77
+ export const db = getFirestore(app);
78
+ ```
79
+
80
+ The Firebase configuration is accepted by the local mirror during development. The production build passes that same configuration to Firebase. Normal Auth, Firestore, Realtime Database, Storage, Messaging, and Firebase AI Logic usage still belongs in the [Firebase documentation](https://firebase.google.com/docs).
81
+
82
+ Pyric documents the parts that differ locally, including supported behavior, Security Rules, persistence, inspection, verification, and known gaps. See [use the Vite plugin](packages/cli/docs/how-to/use-the-vite-plugin.md) for the complete plugin contract.
83
+
84
+ ## Inspect and correct a failed operation
85
+
86
+ Pyric Studio shows local data, requests, authentication state, Security Rules verdicts, and denied operations. Open `/__pyric/ui/` on the development server and reproduce the failure. A denied request includes the path and verdict needed to correct the rule or the application code.
87
+
88
+ The Vite plugin discovers the Firestore rules path from `firebase.json`, or falls back to `firestore.rules`. Saving that file replaces the active local ruleset without a production deploy. A parse failure leaves the last valid ruleset active and reports the error in the development server.
89
+
90
+ State and test identities stay browser-local by default. Add `persist: true` to write a committable `.pyric/state/state.json`, or use `seed` to start from a known scenario:
91
+
92
+ ```ts
93
+ pyricSandbox({
94
+ persist: true,
95
+ seed: 'seed.json',
96
+ });
97
+ ```
98
+
99
+ See [persistence and multi-tab behavior](packages/cli/docs/how-to/serve-persistence-and-multi-tab.md) for reset and seed precedence.
100
+
101
+ ## Give coding agents the same local Firebase target
102
+
103
+ An agent can keep writing the same Firebase code while inspecting and changing the backend that the application is already using. Agent access is opt-in. Enable the MCP bridge in the Vite plugin:
104
+
105
+ ```ts
106
+ pyricSandbox({ bridge: true });
107
+ ```
108
+
109
+ The bridge mounts on the Vite development origin and routes agent operations to the same SharedWorker backend used by the application and Studio. The included [Claude Code plugin](pyric-plugin/README.md) discovers that bridge, while other MCP clients can connect to its HTTP endpoint.
110
+
111
+ This protects the local workflow, not an independently credentialed process. A coding agent with production Firebase credentials or deployment access can still affect production outside Pyric.
112
+
113
+ ## Verify the rules boundary
114
+
115
+ Development sessions capture Firestore and Realtime Database operations in `.pyric/last-session.json` by default. Replay those requests against candidate rules before deployment:
116
+
117
+ ```bash
118
+ npx pyric verify
119
+ ```
120
+
121
+ The default engine runs locally. The optional Firestore Rules Test API engine sends derived rule cases to Google's hosted evaluator when production-authority verification is needed. It verifies rules and does not deploy them. See [verify against a captured session](packages/cli/docs/how-to/verify-against-a-captured-session.md).
122
+
123
+ ## Ship the same application code
124
+
125
+ A standard Vite production build leaves the development swap inactive:
126
+
127
+ ```bash
128
+ npm run build
129
+ ```
130
+
131
+ The built application contains the real Firebase SDK and uses the Firebase configuration already present in the source. Deploy the build, rules, and indexes with `firebase-tools` or the Firebase Console. Pyric has no production deployment path.
132
+
133
+ ## Check what Pyric mirrors
134
+
135
+ Pyric is an independent implementation of observable Firebase behavior. Conformance evidence records what has been compared with Firebase and keeps five outcomes distinct: conforms, documented divergence, bug, unsupported, and unverified. The evidence is a floor, not a claim that every Firebase behavior has been measured.
136
+
137
+ Ask about a developer-facing feature without nesting discovery under rules verification:
138
+
139
+ ```bash
140
+ npx pyric can-i-use getAfter
141
+ npx pyric can-i-use firestore-rules/request.query --json
142
+ ```
143
+
144
+ The result reports availability, Firebase fidelity, and assurance eligibility as separate axes. Exact names succeed; a name shared by multiple surfaces asks you to qualify it, and fuzzy input prints labeled suggestions and exits nonzero instead of presenting a guess as a trust answer.
145
+
146
+ Documentation and other Node consumers can bind the same feature name to the
147
+ published import that exposes it, without maintaining a second surface map:
148
+
149
+ ```ts
150
+ import { canIUse, canIUseImport } from '@pyric/cli/conformance';
151
+
152
+ const result = canIUse('getDownloadURL', { importPath: 'pyric/storage' });
153
+ const evidence = canIUseImport('pyric/storage');
154
+ const evidencePage = evidence && `/docs/${evidence.evidenceSlug}/`;
155
+ ```
156
+
157
+ Each support result carries only census-proven `importPaths`; registry ownership
158
+ cannot invent package exports. `canIUseImport()` supplies the separate canonical
159
+ import-to-evidence join used by generated API documentation. An unrelated
160
+ import path returns no exact match rather than borrowing another surface's trust
161
+ claim.
162
+
163
+ Read the generated [conformance scores](https://pyric.dev/docs/conformance-scores/) and the service matrices in the site's Conformance section. They are built from the same canonical registry used by assurance and `canIUse`, without committing duplicate Markdown. The [versioning and compatibility policy](packages/pyric/docs/explanation/versioning-and-compatibility.md) explains the release boundary.
164
+
165
+ ## Stability
166
+
167
+ Pyric is alpha software, currently `0.1.0-alpha.8`. Firebase-shaped surfaces are tracked through the compatibility matrices. Pyric-specific development APIs may change between alpha releases. All packages are ESM-only and require Node 22.15 or later.
168
+
169
+ ## Develop Pyric
170
+
171
+ The repository is a Bun workspace:
172
+
173
+ ```bash
174
+ bun install
175
+ bun run build
176
+ bun run test
177
+ bun run compat:check
178
+ ```
179
+
180
+ See [CONTRIBUTING.md](CONTRIBUTING.md), [CONTEXT.md](CONTEXT.md), and [AGENTS.md](AGENTS.md) before changing the codebase.
package/README.md.orig ADDED
@@ -0,0 +1,48 @@
1
+ # `pyric-admin`
2
+
3
+ Firebase Admin-shaped adapters for a Pyric sandbox.
4
+
5
+ Use these subpaths when tests, development servers, or scripts need
6
+ `firebase-admin` ergonomics against local or browser-hosted sandbox state. In
7
+ activated development, `@pyric/cli/register` resolves canonical
8
+ `firebase-admin/*` imports here. With activation absent, production execution
9
+ loads `firebase-admin` directly.
10
+
11
+ > **Alpha.** These are best-effort mirror contracts of `firebase-admin`. Read
12
+ > the conformance matrices and service references for implemented behaviour and
13
+ > explicit gaps.
14
+
15
+ ## Subpaths
16
+
17
+ | Subpath | Sandbox surface |
18
+ |---|---|
19
+ | `pyric-admin/app` | Admin app registry and sandbox binding |
20
+ | `pyric-admin/firestore` | Admin Firestore shape |
21
+ | `pyric-admin/auth` | Admin Auth shape |
22
+ | `pyric-admin/database` | Admin Realtime Database shape |
23
+ | `pyric-admin/storage` | Admin Storage shape |
24
+
25
+ ## Explicit sandbox setup
26
+
27
+ ```ts
28
+ import { initializeApp } from 'pyric-admin/app';
29
+ import { initializeSandbox } from 'pyric/sandbox';
30
+ import { getFirestore } from 'pyric-admin/firestore';
31
+
32
+ const app = initializeApp({ sandbox: initializeSandbox() });
33
+ const db = getFirestore(app);
34
+
35
+ await db.collection('posts').doc('hello').set({ title: 'Hello' });
36
+ ```
37
+
38
+ For unchanged server source, keep `firebase-admin/*` imports and run the
39
+ development command through `pyric dev`. Production runs the same source
40
+ without sandbox activation and therefore resolves Firebase Admin directly.
41
+
42
+ ## Documentation
43
+
44
+ - [App registry and activation](docs/app/)
45
+ - [Firestore](docs/firestore/)
46
+ - [Auth API](https://pyric.dev/docs/pyric-admin-auth-reference-api/)
47
+ - [Realtime Database API](https://pyric.dev/docs/pyric-admin-database-reference-api/)
48
+ - [Storage API](https://pyric.dev/docs/pyric-admin-storage-reference-api/)
@@ -0,0 +1,47 @@
1
+ /**
2
+ * `pyric-admin/app` — sandbox-only admin app registry.
3
+ *
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.
7
+ */
8
+ import { type Sandbox } from 'pyric/sandbox';
9
+ /** Brand carried by every sandbox admin app. */
10
+ export declare const ADMIN_APP_TARGET: unique symbol;
11
+ export type PyricAdminAppTarget = 'sandbox';
12
+ /** firebase-admin's default app name. */
13
+ export declare const DEFAULT_APP_NAME = "[DEFAULT]";
14
+ export interface SandboxAdminApp {
15
+ readonly [ADMIN_APP_TARGET]: 'sandbox';
16
+ readonly sandbox: Sandbox;
17
+ readonly name: string;
18
+ }
19
+ export type PyricAdminApp = SandboxAdminApp;
20
+ export type InitializeAdminAppConfig = {
21
+ sandbox: Sandbox;
22
+ };
23
+ /**
24
+ * Firebase Functions' ESM runtime statically imports this credential factory
25
+ * while linking its database provider. Pyric initializes the sandbox app
26
+ * before that provider executes, so the factory is not used by supported
27
+ * Functions flows. Keep the named export link-compatible, but fail clearly if
28
+ * application code asks the development sandbox for production credentials.
29
+ */
30
+ export declare function applicationDefault(): never;
31
+ /**
32
+ * Initialize a sandbox admin app.
33
+ *
34
+ * An explicit `{ sandbox }` config binds an in-process or remote sandbox.
35
+ * A bare call resolves the remote sandbox factory installed by
36
+ * `@pyric/cli/register`. Production callers must import `firebase-admin/app`
37
+ * without Pyric activation instead of passing production options here.
38
+ */
39
+ export declare function initializeApp(config?: InitializeAdminAppConfig, name?: string): PyricAdminApp;
40
+ /** Return the registered app for `name`. */
41
+ export declare function getApp(name?: string): PyricAdminApp;
42
+ /** Return a copy of the app registry. */
43
+ export declare function getApps(): PyricAdminApp[];
44
+ /** Remove a sandbox app from the registry. */
45
+ export declare function deleteApp(app: PyricAdminApp): Promise<void>;
46
+ export declare function isSandboxAdminApp(app: PyricAdminApp): app is SandboxAdminApp;
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,eAAe,CAAC;AAGvB,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,eAAuC,CAAC;AACrE,MAAM,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE5C,yCAAyC;AACzC,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC;AAC5C,MAAM,MAAM,wBAAwB,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,KAAK,CAK1C;AA4CD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,MAAM,CAAC,EAAE,wBAAwB,EACjC,IAAI,GAAE,MAAyB,GAC9B,aAAa,CAqCf;AAED,4CAA4C;AAC5C,wBAAgB,MAAM,CAAC,IAAI,GAAE,MAAyB,GAAG,aAAa,CAarE;AAED,yCAAyC;AACzC,wBAAgB,OAAO,IAAI,aAAa,EAAE,CAEzC;AAED,8CAA8C;AAC9C,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAS3D;AAgED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,GAAG,IAAI,eAAe,CAE5E"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * `pyric-admin/app` — sandbox-only admin app registry.
3
+ *
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.
7
+ */
8
+ import { REMOTE_SANDBOX_FACTORY, } from 'pyric/sandbox';
9
+ import { assertAdminAppActive, markAdminAppDeleted } from './lifecycle.js';
10
+ /** Brand carried by every sandbox admin app. */
11
+ export const ADMIN_APP_TARGET = Symbol.for('pyric.admin.app.target');
12
+ /** firebase-admin's default app name. */
13
+ export const DEFAULT_APP_NAME = '[DEFAULT]';
14
+ /**
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.
20
+ */
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();
44
+ function validateAppName(name) {
45
+ if (typeof name !== 'string' || name === '') {
46
+ throw new FirebaseAppError('invalid-app-name', `Invalid Firebase app name "${String(name)}" provided. App name must be a non-empty string.`);
47
+ }
48
+ }
49
+ function alreadyExists(name, code) {
50
+ return new FirebaseAppError(code, `A Firebase app named "${name}" already exists with a different configuration.`);
51
+ }
52
+ /**
53
+ * Initialize a sandbox admin app.
54
+ *
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.
59
+ */
60
+ export function initializeApp(config, name = DEFAULT_APP_NAME) {
61
+ validateAppName(name);
62
+ const existing = appRegistry.get(name);
63
+ if (config === undefined) {
64
+ if (existing !== undefined) {
65
+ if (ambientApps.has(existing))
66
+ return existing;
67
+ throw alreadyExists(name, 'invalid-app-options');
68
+ }
69
+ const app = initializeAmbientApp(name);
70
+ appRegistry.set(name, app);
71
+ ambientApps.add(app);
72
+ return app;
73
+ }
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.');
77
+ }
78
+ if (existing !== undefined) {
79
+ if (!ambientApps.has(existing) && existing.sandbox === config.sandbox)
80
+ return existing;
81
+ throw alreadyExists(name, ambientApps.has(existing) ? 'invalid-app-options' : 'duplicate-app');
82
+ }
83
+ const app = {
84
+ [ADMIN_APP_TARGET]: 'sandbox',
85
+ sandbox: config.sandbox,
86
+ name,
87
+ };
88
+ appRegistry.set(name, app);
89
+ return app;
90
+ }
91
+ /** Return the registered app for `name`. */
92
+ export function getApp(name = DEFAULT_APP_NAME) {
93
+ validateAppName(name);
94
+ const app = appRegistry.get(name);
95
+ if (app === undefined) {
96
+ const lead = name === DEFAULT_APP_NAME
97
+ ? 'The default Firebase app does not exist. '
98
+ : `Firebase app named "${name}" does not exist. `;
99
+ throw new FirebaseAppError('no-app', lead + 'Make sure you call initializeApp() before using any of the Firebase services.');
100
+ }
101
+ return app;
102
+ }
103
+ /** Return a copy of the app registry. */
104
+ export function getApps() {
105
+ return Array.from(appRegistry.values());
106
+ }
107
+ /** Remove a sandbox app from the registry. */
108
+ export function deleteApp(app) {
109
+ if (typeof app !== 'object' || app === null || !(ADMIN_APP_TARGET in app)) {
110
+ throw new FirebaseAppError('invalid-argument', 'Invalid app argument.');
111
+ }
112
+ assertAdminAppActive(app);
113
+ const existing = getApp(app.name);
114
+ appRegistry.delete(existing.name);
115
+ markAdminAppDeleted(existing);
116
+ return Promise.resolve();
117
+ }
118
+ function initializeAmbientApp(name) {
119
+ const env = process.env.PYRIC_SANDBOX;
120
+ if (env === undefined || env.trim() === '') {
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.');
124
+ }
125
+ const opts = parsePyricSandboxEnv(env);
126
+ if (process.env.NODE_ENV === 'production' && process.env.PYRIC_SANDBOX_FORCE !== '1') {
127
+ throw new Error('pyric-admin: PYRIC_SANDBOX is set but NODE_ENV is "production" — ' +
128
+ 'refusing to route firebase-admin to a development sandbox. ' +
129
+ 'Unset PYRIC_SANDBOX in production, or set PYRIC_SANDBOX_FORCE=1 ' +
130
+ 'if this routing is intentional.');
131
+ }
132
+ const factory = globalThis[REMOTE_SANDBOX_FACTORY];
133
+ if (typeof factory !== 'function') {
134
+ throw new Error(`pyric-admin: PYRIC_SANDBOX=${env} is set but no remote sandbox ` +
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.');
137
+ }
138
+ const sandbox = factory(opts);
139
+ process.stderr.write(`pyric: firebase-admin routed to sandbox${opts.url !== undefined ? ` at ${opts.url}` : ''}\n`);
140
+ return { [ADMIN_APP_TARGET]: 'sandbox', sandbox, name };
141
+ }
142
+ function parsePyricSandboxEnv(env) {
143
+ const value = env.trim();
144
+ if (value === 'remote')
145
+ return {};
146
+ if (value.startsWith('remote:')) {
147
+ const url = value.slice('remote:'.length).trim();
148
+ if (url === '') {
149
+ throw new Error('pyric-admin: PYRIC_SANDBOX=remote: has an empty url. Use ' +
150
+ 'PYRIC_SANDBOX=remote to auto-discover the running `pyric dev`, ' +
151
+ 'or PYRIC_SANDBOX=remote:<url> with the host url.');
152
+ }
153
+ return { url };
154
+ }
155
+ throw new Error(`pyric-admin: unrecognized PYRIC_SANDBOX value "${env}". Supported ` +
156
+ 'values: "remote" (auto-discover the running `pyric dev`) or "remote:<url>".');
157
+ }
158
+ function isSandboxConfig(config) {
159
+ return typeof config === 'object' && config !== null && 'sandbox' in config;
160
+ }
161
+ export function isSandboxAdminApp(app) {
162
+ return app[ADMIN_APP_TARGET] === 'sandbox';
163
+ }
164
+ //# sourceMappingURL=index.js.map