pyric 0.0.1 → 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.
Files changed (1204) hide show
  1. package/LICENSE +216 -0
  2. package/README.md +179 -2
  3. package/README.md.orig +54 -0
  4. package/dist/ai/backend.d.ts +35 -0
  5. package/dist/ai/backend.d.ts.map +1 -0
  6. package/dist/ai/backend.js +42 -0
  7. package/dist/ai/backend.js.map +1 -0
  8. package/dist/ai/broker/broker.d.ts +65 -0
  9. package/dist/ai/broker/broker.d.ts.map +1 -0
  10. package/dist/ai/broker/broker.js +184 -0
  11. package/dist/ai/broker/broker.js.map +1 -0
  12. package/dist/ai/broker/index.d.ts +12 -0
  13. package/dist/ai/broker/index.d.ts.map +1 -0
  14. package/dist/ai/broker/index.js +11 -0
  15. package/dist/ai/broker/index.js.map +1 -0
  16. package/dist/ai/broker/openai-engine.d.ts +175 -0
  17. package/dist/ai/broker/openai-engine.d.ts.map +1 -0
  18. package/dist/ai/broker/openai-engine.js +502 -0
  19. package/dist/ai/broker/openai-engine.js.map +1 -0
  20. package/dist/ai/broker/scripted-engine.d.ts +44 -0
  21. package/dist/ai/broker/scripted-engine.d.ts.map +1 -0
  22. package/dist/ai/broker/scripted-engine.js +218 -0
  23. package/dist/ai/broker/scripted-engine.js.map +1 -0
  24. package/dist/ai/broker/synthesizer.d.ts +100 -0
  25. package/dist/ai/broker/synthesizer.d.ts.map +1 -0
  26. package/dist/ai/broker/synthesizer.js +278 -0
  27. package/dist/ai/broker/synthesizer.js.map +1 -0
  28. package/dist/ai/broker/types.d.ts +210 -0
  29. package/dist/ai/broker/types.d.ts.map +1 -0
  30. package/dist/ai/broker/types.js +20 -0
  31. package/dist/ai/broker/types.js.map +1 -0
  32. package/dist/ai/enums.d.ts +174 -0
  33. package/dist/ai/enums.d.ts.map +1 -0
  34. package/dist/ai/enums.js +155 -0
  35. package/dist/ai/enums.js.map +1 -0
  36. package/dist/ai/errors.d.ts +66 -0
  37. package/dist/ai/errors.d.ts.map +1 -0
  38. package/dist/ai/errors.js +100 -0
  39. package/dist/ai/errors.js.map +1 -0
  40. package/dist/ai/index.d.ts +31 -0
  41. package/dist/ai/index.d.ts.map +1 -0
  42. package/dist/ai/index.js +27 -0
  43. package/dist/ai/index.js.map +1 -0
  44. package/dist/ai/instances.d.ts +15 -0
  45. package/dist/ai/instances.d.ts.map +1 -0
  46. package/dist/ai/instances.js +69 -0
  47. package/dist/ai/instances.js.map +1 -0
  48. package/dist/ai/internal.d.ts +13 -0
  49. package/dist/ai/internal.d.ts.map +1 -0
  50. package/dist/ai/internal.js +45 -0
  51. package/dist/ai/internal.js.map +1 -0
  52. package/dist/ai/models.d.ts +116 -0
  53. package/dist/ai/models.d.ts.map +1 -0
  54. package/dist/ai/models.js +213 -0
  55. package/dist/ai/models.js.map +1 -0
  56. package/dist/ai/request-helpers.d.ts +59 -0
  57. package/dist/ai/request-helpers.d.ts.map +1 -0
  58. package/dist/ai/request-helpers.js +157 -0
  59. package/dist/ai/request-helpers.js.map +1 -0
  60. package/dist/ai/response-helpers.d.ts +41 -0
  61. package/dist/ai/response-helpers.d.ts.map +1 -0
  62. package/dist/ai/response-helpers.js +204 -0
  63. package/dist/ai/response-helpers.js.map +1 -0
  64. package/dist/ai/sandbox-plane.d.ts +41 -0
  65. package/dist/ai/sandbox-plane.d.ts.map +1 -0
  66. package/dist/ai/sandbox-plane.js +159 -0
  67. package/dist/ai/sandbox-plane.js.map +1 -0
  68. package/dist/ai/schema.d.ts +105 -0
  69. package/dist/ai/schema.d.ts.map +1 -0
  70. package/dist/ai/schema.js +174 -0
  71. package/dist/ai/schema.js.map +1 -0
  72. package/dist/ai/scripting.d.ts +53 -0
  73. package/dist/ai/scripting.d.ts.map +1 -0
  74. package/dist/ai/scripting.js +73 -0
  75. package/dist/ai/scripting.js.map +1 -0
  76. package/dist/ai/target.d.ts +20 -0
  77. package/dist/ai/target.d.ts.map +1 -0
  78. package/dist/ai/target.js +29 -0
  79. package/dist/ai/target.js.map +1 -0
  80. package/dist/ai/types.d.ts +400 -0
  81. package/dist/ai/types.d.ts.map +1 -0
  82. package/dist/ai/types.js +10 -0
  83. package/dist/ai/types.js.map +1 -0
  84. package/dist/app/diagnostics.d.ts +29 -0
  85. package/dist/app/diagnostics.d.ts.map +1 -0
  86. package/dist/app/diagnostics.js +88 -0
  87. package/dist/app/diagnostics.js.map +1 -0
  88. package/dist/app/index.d.ts +7 -0
  89. package/dist/app/index.d.ts.map +1 -0
  90. package/dist/app/index.js +5 -0
  91. package/dist/app/index.js.map +1 -0
  92. package/dist/app/internal.d.ts +11 -0
  93. package/dist/app/internal.d.ts.map +1 -0
  94. package/dist/app/internal.js +18 -0
  95. package/dist/app/internal.js.map +1 -0
  96. package/dist/app/options.d.ts +3 -0
  97. package/dist/app/options.d.ts.map +1 -0
  98. package/dist/app/options.js +19 -0
  99. package/dist/app/options.js.map +1 -0
  100. package/dist/app/register.d.ts +4 -0
  101. package/dist/app/register.d.ts.map +1 -0
  102. package/dist/app/register.js +35 -0
  103. package/dist/app/register.js.map +1 -0
  104. package/dist/app/registry.d.ts +12 -0
  105. package/dist/app/registry.d.ts.map +1 -0
  106. package/dist/app/registry.js +147 -0
  107. package/dist/app/registry.js.map +1 -0
  108. package/dist/app/runtime.d.ts +18 -0
  109. package/dist/app/runtime.d.ts.map +1 -0
  110. package/dist/app/runtime.js +119 -0
  111. package/dist/app/runtime.js.map +1 -0
  112. package/dist/app/types.d.ts +21 -0
  113. package/dist/app/types.d.ts.map +1 -0
  114. package/dist/app/types.js +2 -0
  115. package/dist/app/types.js.map +1 -0
  116. package/dist/auth/action-code-url.d.ts +70 -0
  117. package/dist/auth/action-code-url.d.ts.map +1 -0
  118. package/dist/auth/action-code-url.js +124 -0
  119. package/dist/auth/action-code-url.js.map +1 -0
  120. package/dist/auth/action-codes.d.ts +201 -0
  121. package/dist/auth/action-codes.d.ts.map +1 -0
  122. package/dist/auth/action-codes.js +355 -0
  123. package/dist/auth/action-codes.js.map +1 -0
  124. package/dist/auth/auth-errors.d.ts +21 -0
  125. package/dist/auth/auth-errors.d.ts.map +1 -0
  126. package/dist/auth/auth-errors.js +23 -0
  127. package/dist/auth/auth-errors.js.map +1 -0
  128. package/dist/auth/config-tokens.d.ts +90 -0
  129. package/dist/auth/config-tokens.d.ts.map +1 -0
  130. package/dist/auth/config-tokens.js +86 -0
  131. package/dist/auth/config-tokens.js.map +1 -0
  132. package/dist/auth/credentials.d.ts +140 -0
  133. package/dist/auth/credentials.d.ts.map +1 -0
  134. package/dist/auth/credentials.js +194 -0
  135. package/dist/auth/credentials.js.map +1 -0
  136. package/dist/auth/email-link.d.ts +91 -0
  137. package/dist/auth/email-link.d.ts.map +1 -0
  138. package/dist/auth/email-link.js +172 -0
  139. package/dist/auth/email-link.js.map +1 -0
  140. package/dist/auth/enums.d.ts +210 -0
  141. package/dist/auth/enums.d.ts.map +1 -0
  142. package/dist/auth/enums.js +206 -0
  143. package/dist/auth/enums.js.map +1 -0
  144. package/dist/auth/index.d.ts +3 -0
  145. package/dist/auth/index.d.ts.map +1 -0
  146. package/dist/auth/index.js +3 -0
  147. package/dist/auth/index.js.map +1 -0
  148. package/dist/auth/instances.d.ts +14 -0
  149. package/dist/auth/instances.d.ts.map +1 -0
  150. package/dist/auth/instances.js +95 -0
  151. package/dist/auth/instances.js.map +1 -0
  152. package/dist/auth/linking.d.ts +93 -0
  153. package/dist/auth/linking.d.ts.map +1 -0
  154. package/dist/auth/linking.js +189 -0
  155. package/dist/auth/linking.js.map +1 -0
  156. package/dist/auth/modular.d.ts +22 -0
  157. package/dist/auth/modular.d.ts.map +1 -0
  158. package/dist/auth/modular.js +18 -0
  159. package/dist/auth/modular.js.map +1 -0
  160. package/dist/auth/password-policy.d.ts +60 -0
  161. package/dist/auth/password-policy.d.ts.map +1 -0
  162. package/dist/auth/password-policy.js +68 -0
  163. package/dist/auth/password-policy.js.map +1 -0
  164. package/dist/auth/providers.d.ts +153 -0
  165. package/dist/auth/providers.d.ts.map +1 -0
  166. package/dist/auth/providers.js +207 -0
  167. package/dist/auth/providers.js.map +1 -0
  168. package/dist/auth/reauth.d.ts +73 -0
  169. package/dist/auth/reauth.d.ts.map +1 -0
  170. package/dist/auth/reauth.js +148 -0
  171. package/dist/auth/reauth.js.map +1 -0
  172. package/dist/auth/sandbox/driver.d.ts +51 -0
  173. package/dist/auth/sandbox/driver.d.ts.map +1 -0
  174. package/dist/auth/sandbox/driver.js +88 -0
  175. package/dist/auth/sandbox/driver.js.map +1 -0
  176. package/dist/auth/sandbox/persistence.d.ts +7 -0
  177. package/dist/auth/sandbox/persistence.d.ts.map +1 -0
  178. package/dist/auth/sandbox/persistence.js +121 -0
  179. package/dist/auth/sandbox/persistence.js.map +1 -0
  180. package/dist/auth/sandbox/project-store.d.ts +15 -0
  181. package/dist/auth/sandbox/project-store.d.ts.map +1 -0
  182. package/dist/auth/sandbox/project-store.js +17 -0
  183. package/dist/auth/sandbox/project-store.js.map +1 -0
  184. package/dist/auth/sandbox-auth-flow.d.ts +173 -0
  185. package/dist/auth/sandbox-auth-flow.d.ts.map +1 -0
  186. package/dist/auth/sandbox-auth-flow.js +165 -0
  187. package/dist/auth/sandbox-auth-flow.js.map +1 -0
  188. package/dist/auth/sandbox-backend-types.d.ts +197 -0
  189. package/dist/auth/sandbox-backend-types.d.ts.map +1 -0
  190. package/dist/auth/sandbox-backend-types.js +18 -0
  191. package/dist/auth/sandbox-backend-types.js.map +1 -0
  192. package/dist/auth/sandbox-backend.d.ts +811 -0
  193. package/dist/auth/sandbox-backend.d.ts.map +1 -0
  194. package/dist/auth/sandbox-backend.js +2007 -0
  195. package/dist/auth/sandbox-backend.js.map +1 -0
  196. package/dist/auth/sandbox-credential-validators.d.ts +30 -0
  197. package/dist/auth/sandbox-credential-validators.d.ts.map +1 -0
  198. package/dist/auth/sandbox-credential-validators.js +47 -0
  199. package/dist/auth/sandbox-credential-validators.js.map +1 -0
  200. package/dist/auth/sandbox-token.d.ts +24 -0
  201. package/dist/auth/sandbox-token.d.ts.map +1 -0
  202. package/dist/auth/sandbox-token.js +32 -0
  203. package/dist/auth/sandbox-token.js.map +1 -0
  204. package/dist/auth/sign-in.d.ts +14 -0
  205. package/dist/auth/sign-in.d.ts.map +1 -0
  206. package/dist/auth/sign-in.js +140 -0
  207. package/dist/auth/sign-in.js.map +1 -0
  208. package/dist/auth/target.d.ts +29 -0
  209. package/dist/auth/target.d.ts.map +1 -0
  210. package/dist/auth/target.js +23 -0
  211. package/dist/auth/target.js.map +1 -0
  212. package/dist/auth/tokens.d.ts +54 -0
  213. package/dist/auth/tokens.d.ts.map +1 -0
  214. package/dist/auth/tokens.js +142 -0
  215. package/dist/auth/tokens.js.map +1 -0
  216. package/dist/auth/types.d.ts +283 -0
  217. package/dist/auth/types.d.ts.map +1 -0
  218. package/dist/auth/types.js +24 -0
  219. package/dist/auth/types.js.map +1 -0
  220. package/dist/auth/user-lifecycle.d.ts +17 -0
  221. package/dist/auth/user-lifecycle.d.ts.map +1 -0
  222. package/dist/auth/user-lifecycle.js +60 -0
  223. package/dist/auth/user-lifecycle.js.map +1 -0
  224. package/dist/database/index.d.ts +9 -0
  225. package/dist/database/index.d.ts.map +1 -0
  226. package/dist/database/index.js +9 -0
  227. package/dist/database/index.js.map +1 -0
  228. package/dist/database/listener-registry.d.ts +16 -0
  229. package/dist/database/listener-registry.d.ts.map +1 -0
  230. package/dist/database/listener-registry.js +68 -0
  231. package/dist/database/listener-registry.js.map +1 -0
  232. package/dist/database/modular.d.ts +632 -0
  233. package/dist/database/modular.d.ts.map +1 -0
  234. package/dist/database/modular.js +1071 -0
  235. package/dist/database/modular.js.map +1 -0
  236. package/dist/database/replay.d.ts +32 -0
  237. package/dist/database/replay.d.ts.map +1 -0
  238. package/dist/database/replay.js +124 -0
  239. package/dist/database/replay.js.map +1 -0
  240. package/dist/database/sandbox/backend-for.d.ts +10 -0
  241. package/dist/database/sandbox/backend-for.d.ts.map +1 -0
  242. package/dist/database/sandbox/backend-for.js +19 -0
  243. package/dist/database/sandbox/backend-for.js.map +1 -0
  244. package/dist/database/sandbox/backend.d.ts +407 -0
  245. package/dist/database/sandbox/backend.d.ts.map +1 -0
  246. package/dist/database/sandbox/backend.js +1495 -0
  247. package/dist/database/sandbox/backend.js.map +1 -0
  248. package/dist/database/sandbox/data-tree.d.ts +123 -0
  249. package/dist/database/sandbox/data-tree.d.ts.map +1 -0
  250. package/dist/database/sandbox/data-tree.js +310 -0
  251. package/dist/database/sandbox/data-tree.js.map +1 -0
  252. package/dist/database/sandbox/normalize.d.ts +77 -0
  253. package/dist/database/sandbox/normalize.d.ts.map +1 -0
  254. package/dist/database/sandbox/normalize.js +165 -0
  255. package/dist/database/sandbox/normalize.js.map +1 -0
  256. package/dist/database/sandbox/push-id.d.ts +32 -0
  257. package/dist/database/sandbox/push-id.d.ts.map +1 -0
  258. package/dist/database/sandbox/push-id.js +82 -0
  259. package/dist/database/sandbox/push-id.js.map +1 -0
  260. package/dist/database/sandbox/query.d.ts +175 -0
  261. package/dist/database/sandbox/query.d.ts.map +1 -0
  262. package/dist/database/sandbox/query.js +269 -0
  263. package/dist/database/sandbox/query.js.map +1 -0
  264. package/dist/database/sandbox/rules-eval.d.ts +87 -0
  265. package/dist/database/sandbox/rules-eval.d.ts.map +1 -0
  266. package/dist/database/sandbox/rules-eval.js +131 -0
  267. package/dist/database/sandbox/rules-eval.js.map +1 -0
  268. package/dist/database/sandbox/sentinels.d.ts +71 -0
  269. package/dist/database/sandbox/sentinels.d.ts.map +1 -0
  270. package/dist/database/sandbox/sentinels.js +92 -0
  271. package/dist/database/sandbox/sentinels.js.map +1 -0
  272. package/dist/database/sandbox-controls.d.ts +15 -0
  273. package/dist/database/sandbox-controls.d.ts.map +1 -0
  274. package/dist/database/sandbox-controls.js +18 -0
  275. package/dist/database/sandbox-controls.js.map +1 -0
  276. package/dist/firestore/aggregates.d.ts +50 -0
  277. package/dist/firestore/aggregates.d.ts.map +1 -0
  278. package/dist/firestore/aggregates.js +40 -0
  279. package/dist/firestore/aggregates.js.map +1 -0
  280. package/dist/firestore/equality.d.ts +5 -0
  281. package/dist/firestore/equality.d.ts.map +1 -0
  282. package/dist/firestore/equality.js +20 -0
  283. package/dist/firestore/equality.js.map +1 -0
  284. package/dist/firestore/field-values.d.ts +61 -0
  285. package/dist/firestore/field-values.d.ts.map +1 -0
  286. package/dist/firestore/field-values.js +167 -0
  287. package/dist/firestore/field-values.js.map +1 -0
  288. package/dist/firestore/index.d.ts +54 -0
  289. package/dist/firestore/index.d.ts.map +1 -0
  290. package/dist/firestore/index.js +54 -0
  291. package/dist/firestore/index.js.map +1 -0
  292. package/dist/firestore/instances.d.ts +123 -0
  293. package/dist/firestore/instances.d.ts.map +1 -0
  294. package/dist/firestore/instances.js +177 -0
  295. package/dist/firestore/instances.js.map +1 -0
  296. package/dist/firestore/internal/index.d.ts +2 -0
  297. package/dist/firestore/internal/index.d.ts.map +1 -0
  298. package/dist/firestore/internal/index.js +2 -0
  299. package/dist/firestore/internal/index.js.map +1 -0
  300. package/dist/firestore/internal/listener-routing.d.ts +4 -0
  301. package/dist/firestore/internal/listener-routing.d.ts.map +1 -0
  302. package/dist/firestore/internal/listener-routing.js +4 -0
  303. package/dist/firestore/internal/listener-routing.js.map +1 -0
  304. package/dist/firestore/listeners.d.ts +12 -0
  305. package/dist/firestore/listeners.d.ts.map +1 -0
  306. package/dist/firestore/listeners.js +200 -0
  307. package/dist/firestore/listeners.js.map +1 -0
  308. package/dist/firestore/persistence.d.ts +227 -0
  309. package/dist/firestore/persistence.d.ts.map +1 -0
  310. package/dist/firestore/persistence.js +245 -0
  311. package/dist/firestore/persistence.js.map +1 -0
  312. package/dist/firestore/query-constraints.d.ts +72 -0
  313. package/dist/firestore/query-constraints.d.ts.map +1 -0
  314. package/dist/firestore/query-constraints.js +168 -0
  315. package/dist/firestore/query-constraints.js.map +1 -0
  316. package/dist/firestore/reads.d.ts +12 -0
  317. package/dist/firestore/reads.d.ts.map +1 -0
  318. package/dist/firestore/reads.js +32 -0
  319. package/dist/firestore/reads.js.map +1 -0
  320. package/dist/firestore/refs.d.ts +27 -0
  321. package/dist/firestore/refs.d.ts.map +1 -0
  322. package/dist/firestore/refs.js +74 -0
  323. package/dist/firestore/refs.js.map +1 -0
  324. package/dist/firestore/sandbox-controls.d.ts +60 -0
  325. package/dist/firestore/sandbox-controls.d.ts.map +1 -0
  326. package/dist/firestore/sandbox-controls.js +77 -0
  327. package/dist/firestore/sandbox-controls.js.map +1 -0
  328. package/dist/firestore/snapshots.d.ts +71 -0
  329. package/dist/firestore/snapshots.d.ts.map +1 -0
  330. package/dist/firestore/snapshots.js +160 -0
  331. package/dist/firestore/snapshots.js.map +1 -0
  332. package/dist/firestore/state.d.ts +168 -0
  333. package/dist/firestore/state.d.ts.map +1 -0
  334. package/dist/firestore/state.js +260 -0
  335. package/dist/firestore/state.js.map +1 -0
  336. package/dist/firestore/tools.d.ts +71 -0
  337. package/dist/firestore/tools.d.ts.map +1 -0
  338. package/dist/firestore/tools.js +320 -0
  339. package/dist/firestore/tools.js.map +1 -0
  340. package/dist/firestore/transactions.d.ts +4 -0
  341. package/dist/firestore/transactions.d.ts.map +1 -0
  342. package/dist/firestore/transactions.js +14 -0
  343. package/dist/firestore/transactions.js.map +1 -0
  344. package/dist/firestore/types.d.ts +82 -0
  345. package/dist/firestore/types.d.ts.map +1 -0
  346. package/dist/firestore/types.js +15 -0
  347. package/dist/firestore/types.js.map +1 -0
  348. package/dist/firestore/writes.d.ts +43 -0
  349. package/dist/firestore/writes.d.ts.map +1 -0
  350. package/dist/firestore/writes.js +40 -0
  351. package/dist/firestore/writes.js.map +1 -0
  352. package/dist/firestore-values/index.d.ts +63 -0
  353. package/dist/firestore-values/index.d.ts.map +1 -0
  354. package/dist/firestore-values/index.js +148 -0
  355. package/dist/firestore-values/index.js.map +1 -0
  356. package/dist/messaging/broker/broker.d.ts +171 -0
  357. package/dist/messaging/broker/broker.d.ts.map +1 -0
  358. package/dist/messaging/broker/broker.js +400 -0
  359. package/dist/messaging/broker/broker.js.map +1 -0
  360. package/dist/messaging/broker/envelopes.d.ts +96 -0
  361. package/dist/messaging/broker/envelopes.d.ts.map +1 -0
  362. package/dist/messaging/broker/envelopes.js +132 -0
  363. package/dist/messaging/broker/envelopes.js.map +1 -0
  364. package/dist/messaging/broker/index.d.ts +27 -0
  365. package/dist/messaging/broker/index.d.ts.map +1 -0
  366. package/dist/messaging/broker/index.js +21 -0
  367. package/dist/messaging/broker/index.js.map +1 -0
  368. package/dist/messaging/broker/tokens.d.ts +22 -0
  369. package/dist/messaging/broker/tokens.d.ts.map +1 -0
  370. package/dist/messaging/broker/tokens.js +37 -0
  371. package/dist/messaging/broker/tokens.js.map +1 -0
  372. package/dist/messaging/broker/types.d.ts +117 -0
  373. package/dist/messaging/broker/types.d.ts.map +1 -0
  374. package/dist/messaging/broker/types.js +12 -0
  375. package/dist/messaging/broker/types.js.map +1 -0
  376. package/dist/messaging/broker/validate.d.ts +58 -0
  377. package/dist/messaging/broker/validate.d.ts.map +1 -0
  378. package/dist/messaging/broker/validate.js +196 -0
  379. package/dist/messaging/broker/validate.js.map +1 -0
  380. package/dist/messaging/client.d.ts +108 -0
  381. package/dist/messaging/client.d.ts.map +1 -0
  382. package/dist/messaging/client.js +65 -0
  383. package/dist/messaging/client.js.map +1 -0
  384. package/dist/messaging/index.d.ts +3 -0
  385. package/dist/messaging/index.d.ts.map +1 -0
  386. package/dist/messaging/index.js +3 -0
  387. package/dist/messaging/index.js.map +1 -0
  388. package/dist/messaging/instance.d.ts +72 -0
  389. package/dist/messaging/instance.d.ts.map +1 -0
  390. package/dist/messaging/instance.js +93 -0
  391. package/dist/messaging/instance.js.map +1 -0
  392. package/dist/messaging/internal.d.ts +12 -0
  393. package/dist/messaging/internal.d.ts.map +1 -0
  394. package/dist/messaging/internal.js +12 -0
  395. package/dist/messaging/internal.js.map +1 -0
  396. package/dist/messaging/sw.d.ts +49 -0
  397. package/dist/messaging/sw.d.ts.map +1 -0
  398. package/dist/messaging/sw.js +49 -0
  399. package/dist/messaging/sw.js.map +1 -0
  400. package/dist/project-scope.d.ts +5 -0
  401. package/dist/project-scope.d.ts.map +1 -0
  402. package/dist/project-scope.js +2 -0
  403. package/dist/project-scope.js.map +1 -0
  404. package/dist/rules/api/assert.d.ts +39 -0
  405. package/dist/rules/api/assert.d.ts.map +1 -0
  406. package/dist/rules/api/assert.js +93 -0
  407. package/dist/rules/api/assert.js.map +1 -0
  408. package/dist/rules/api/case-types.d.ts +141 -0
  409. package/dist/rules/api/case-types.d.ts.map +1 -0
  410. package/dist/rules/api/case-types.js +13 -0
  411. package/dist/rules/api/case-types.js.map +1 -0
  412. package/dist/rules/api/errors.d.ts +38 -0
  413. package/dist/rules/api/errors.d.ts.map +1 -0
  414. package/dist/rules/api/errors.js +47 -0
  415. package/dist/rules/api/errors.js.map +1 -0
  416. package/dist/rules/api/firestore.d.ts +34 -0
  417. package/dist/rules/api/firestore.d.ts.map +1 -0
  418. package/dist/rules/api/firestore.js +137 -0
  419. package/dist/rules/api/firestore.js.map +1 -0
  420. package/dist/rules/api/issue.d.ts +50 -0
  421. package/dist/rules/api/issue.d.ts.map +1 -0
  422. package/dist/rules/api/issue.js +66 -0
  423. package/dist/rules/api/issue.js.map +1 -0
  424. package/dist/rules/api/lint.d.ts +16 -0
  425. package/dist/rules/api/lint.d.ts.map +1 -0
  426. package/dist/rules/api/lint.js +60 -0
  427. package/dist/rules/api/lint.js.map +1 -0
  428. package/dist/rules/api/rtdb.d.ts +33 -0
  429. package/dist/rules/api/rtdb.d.ts.map +1 -0
  430. package/dist/rules/api/rtdb.js +166 -0
  431. package/dist/rules/api/rtdb.js.map +1 -0
  432. package/dist/rules/api/values.d.ts +51 -0
  433. package/dist/rules/api/values.d.ts.map +1 -0
  434. package/dist/rules/api/values.js +66 -0
  435. package/dist/rules/api/values.js.map +1 -0
  436. package/dist/rules/generators/assembler.d.ts +19 -0
  437. package/dist/rules/generators/assembler.d.ts.map +1 -0
  438. package/dist/rules/generators/assembler.js +292 -0
  439. package/dist/rules/generators/assembler.js.map +1 -0
  440. package/dist/rules/generators/expressions.d.ts +52 -0
  441. package/dist/rules/generators/expressions.d.ts.map +1 -0
  442. package/dist/rules/generators/expressions.js +117 -0
  443. package/dist/rules/generators/expressions.js.map +1 -0
  444. package/dist/rules/generators/grid.d.ts +22 -0
  445. package/dist/rules/generators/grid.d.ts.map +1 -0
  446. package/dist/rules/generators/grid.js +52 -0
  447. package/dist/rules/generators/grid.js.map +1 -0
  448. package/dist/rules/grammar/FirestoreAST.d.ts +129 -0
  449. package/dist/rules/grammar/FirestoreAST.d.ts.map +1 -0
  450. package/dist/rules/grammar/FirestoreAST.js +3 -0
  451. package/dist/rules/grammar/FirestoreAST.js.map +1 -0
  452. package/dist/rules/grammar/FirestoreAssembler.d.ts +5 -0
  453. package/dist/rules/grammar/FirestoreAssembler.d.ts.map +1 -0
  454. package/dist/rules/grammar/FirestoreAssembler.js +158 -0
  455. package/dist/rules/grammar/FirestoreAssembler.js.map +1 -0
  456. package/dist/rules/grammar/FirestoreParser.d.ts +46 -0
  457. package/dist/rules/grammar/FirestoreParser.d.ts.map +1 -0
  458. package/dist/rules/grammar/FirestoreParser.js +409 -0
  459. package/dist/rules/grammar/FirestoreParser.js.map +1 -0
  460. package/dist/rules/grammar/FirestoreRules.ohm +229 -0
  461. package/dist/rules/grammar/FirestoreRules.ohm.generated.d.ts +2 -0
  462. package/dist/rules/grammar/FirestoreRules.ohm.generated.d.ts.map +1 -0
  463. package/dist/rules/grammar/FirestoreRules.ohm.generated.js +234 -0
  464. package/dist/rules/grammar/FirestoreRules.ohm.generated.js.map +1 -0
  465. package/dist/rules/grammar/FirestoreValidator.d.ts +10 -0
  466. package/dist/rules/grammar/FirestoreValidator.d.ts.map +1 -0
  467. package/dist/rules/grammar/FirestoreValidator.js +482 -0
  468. package/dist/rules/grammar/FirestoreValidator.js.map +1 -0
  469. package/dist/rules/index.d.ts +41 -0
  470. package/dist/rules/index.d.ts.map +1 -0
  471. package/dist/rules/index.js +40 -0
  472. package/dist/rules/index.js.map +1 -0
  473. package/dist/rules/indexes/extract/annotation-collect.d.ts +42 -0
  474. package/dist/rules/indexes/extract/annotation-collect.d.ts.map +1 -0
  475. package/dist/rules/indexes/extract/annotation-collect.js +69 -0
  476. package/dist/rules/indexes/extract/annotation-collect.js.map +1 -0
  477. package/dist/rules/indexes/extract/annotations.d.ts +50 -0
  478. package/dist/rules/indexes/extract/annotations.d.ts.map +1 -0
  479. package/dist/rules/indexes/extract/annotations.js +144 -0
  480. package/dist/rules/indexes/extract/annotations.js.map +1 -0
  481. package/dist/rules/indexes/extract/ast.d.ts +54 -0
  482. package/dist/rules/indexes/extract/ast.d.ts.map +1 -0
  483. package/dist/rules/indexes/extract/ast.js +119 -0
  484. package/dist/rules/indexes/extract/ast.js.map +1 -0
  485. package/dist/rules/indexes/extract/classify.d.ts +41 -0
  486. package/dist/rules/indexes/extract/classify.d.ts.map +1 -0
  487. package/dist/rules/indexes/extract/classify.js +138 -0
  488. package/dist/rules/indexes/extract/classify.js.map +1 -0
  489. package/dist/rules/indexes/extract/composite.d.ts +38 -0
  490. package/dist/rules/indexes/extract/composite.d.ts.map +1 -0
  491. package/dist/rules/indexes/extract/composite.js +85 -0
  492. package/dist/rules/indexes/extract/composite.js.map +1 -0
  493. package/dist/rules/indexes/extract/dataflow.d.ts +45 -0
  494. package/dist/rules/indexes/extract/dataflow.d.ts.map +1 -0
  495. package/dist/rules/indexes/extract/dataflow.js +200 -0
  496. package/dist/rules/indexes/extract/dataflow.js.map +1 -0
  497. package/dist/rules/indexes/extract/enumerate.d.ts +41 -0
  498. package/dist/rules/indexes/extract/enumerate.d.ts.map +1 -0
  499. package/dist/rules/indexes/extract/enumerate.js +163 -0
  500. package/dist/rules/indexes/extract/enumerate.js.map +1 -0
  501. package/dist/rules/indexes/extract/extractor.d.ts +3 -0
  502. package/dist/rules/indexes/extract/extractor.d.ts.map +1 -0
  503. package/dist/rules/indexes/extract/extractor.js +274 -0
  504. package/dist/rules/indexes/extract/extractor.js.map +1 -0
  505. package/dist/rules/indexes/extract/types.d.ts +211 -0
  506. package/dist/rules/indexes/extract/types.d.ts.map +1 -0
  507. package/dist/rules/indexes/extract/types.js +14 -0
  508. package/dist/rules/indexes/extract/types.js.map +1 -0
  509. package/dist/rules/indexes/extractHandler.d.ts +16 -0
  510. package/dist/rules/indexes/extractHandler.d.ts.map +1 -0
  511. package/dist/rules/indexes/extractHandler.js +100 -0
  512. package/dist/rules/indexes/extractHandler.js.map +1 -0
  513. package/dist/rules/indexes/extractTool.d.ts +15 -0
  514. package/dist/rules/indexes/extractTool.d.ts.map +1 -0
  515. package/dist/rules/indexes/extractTool.js +55 -0
  516. package/dist/rules/indexes/extractTool.js.map +1 -0
  517. package/dist/rules/indexes/types.d.ts +71 -0
  518. package/dist/rules/indexes/types.d.ts.map +1 -0
  519. package/dist/rules/indexes/types.js +15 -0
  520. package/dist/rules/indexes/types.js.map +1 -0
  521. package/dist/rules/inspect/handler.d.ts +6 -0
  522. package/dist/rules/inspect/handler.d.ts.map +1 -0
  523. package/dist/rules/inspect/handler.js +144 -0
  524. package/dist/rules/inspect/handler.js.map +1 -0
  525. package/dist/rules/inspect/spec.d.ts +37 -0
  526. package/dist/rules/inspect/spec.d.ts.map +1 -0
  527. package/dist/rules/inspect/spec.js +2 -0
  528. package/dist/rules/inspect/spec.js.map +1 -0
  529. package/dist/rules/inspect/tools.d.ts +21 -0
  530. package/dist/rules/inspect/tools.d.ts.map +1 -0
  531. package/dist/rules/inspect/tools.js +21 -0
  532. package/dist/rules/inspect/tools.js.map +1 -0
  533. package/dist/rules/internal/extract.d.ts +28 -0
  534. package/dist/rules/internal/extract.d.ts.map +1 -0
  535. package/dist/rules/internal/extract.js +25 -0
  536. package/dist/rules/internal/extract.js.map +1 -0
  537. package/dist/rules/internal/index.d.ts +82 -0
  538. package/dist/rules/internal/index.d.ts.map +1 -0
  539. package/dist/rules/internal/index.js +103 -0
  540. package/dist/rules/internal/index.js.map +1 -0
  541. package/dist/rules/internal/node.d.ts +18 -0
  542. package/dist/rules/internal/node.d.ts.map +1 -0
  543. package/dist/rules/internal/node.js +27 -0
  544. package/dist/rules/internal/node.js.map +1 -0
  545. package/dist/rules/internal/rtdb.d.ts +20 -0
  546. package/dist/rules/internal/rtdb.d.ts.map +1 -0
  547. package/dist/rules/internal/rtdb.js +15 -0
  548. package/dist/rules/internal/rtdb.js.map +1 -0
  549. package/dist/rules/linter/ast-utils.d.ts +97 -0
  550. package/dist/rules/linter/ast-utils.d.ts.map +1 -0
  551. package/dist/rules/linter/ast-utils.js +491 -0
  552. package/dist/rules/linter/ast-utils.js.map +1 -0
  553. package/dist/rules/linter/hallucinations.d.ts +34 -0
  554. package/dist/rules/linter/hallucinations.d.ts.map +1 -0
  555. package/dist/rules/linter/hallucinations.js +334 -0
  556. package/dist/rules/linter/hallucinations.js.map +1 -0
  557. package/dist/rules/linter/linter.d.ts +84 -0
  558. package/dist/rules/linter/linter.d.ts.map +1 -0
  559. package/dist/rules/linter/linter.js +783 -0
  560. package/dist/rules/linter/linter.js.map +1 -0
  561. package/dist/rules/modules/resolver-browser.d.ts +41 -0
  562. package/dist/rules/modules/resolver-browser.d.ts.map +1 -0
  563. package/dist/rules/modules/resolver-browser.js +63 -0
  564. package/dist/rules/modules/resolver-browser.js.map +1 -0
  565. package/dist/rules/modules/resolver-core.d.ts +51 -0
  566. package/dist/rules/modules/resolver-core.d.ts.map +1 -0
  567. package/dist/rules/modules/resolver-core.js +338 -0
  568. package/dist/rules/modules/resolver-core.js.map +1 -0
  569. package/dist/rules/modules/resolver.d.ts +17 -0
  570. package/dist/rules/modules/resolver.d.ts.map +1 -0
  571. package/dist/rules/modules/resolver.js +49 -0
  572. package/dist/rules/modules/resolver.js.map +1 -0
  573. package/dist/rules/modules/stdlib/atomic.rules +52 -0
  574. package/dist/rules/modules/stdlib/atomic.test.json +152 -0
  575. package/dist/rules/modules/stdlib/auth.rules +7 -0
  576. package/dist/rules/modules/stdlib/auth.test.json +53 -0
  577. package/dist/rules/modules/stdlib/content.rules +50 -0
  578. package/dist/rules/modules/stdlib/content.test.json +238 -0
  579. package/dist/rules/modules/stdlib/counters.rules +41 -0
  580. package/dist/rules/modules/stdlib/counters.test.json +254 -0
  581. package/dist/rules/modules/stdlib/geometry.rules +43 -0
  582. package/dist/rules/modules/stdlib/geometry.test.json +200 -0
  583. package/dist/rules/modules/stdlib/joining.rules +49 -0
  584. package/dist/rules/modules/stdlib/joining.test.json +287 -0
  585. package/dist/rules/modules/stdlib/lifecycle.rules +51 -0
  586. package/dist/rules/modules/stdlib/lifecycle.test.json +288 -0
  587. package/dist/rules/modules/stdlib/lobby.rules +44 -0
  588. package/dist/rules/modules/stdlib/lobby.test.json +32 -0
  589. package/dist/rules/modules/stdlib/membership.rules +40 -0
  590. package/dist/rules/modules/stdlib/membership.test.json +107 -0
  591. package/dist/rules/modules/stdlib/spaces.rules +46 -0
  592. package/dist/rules/modules/stdlib/spaces.test.json +392 -0
  593. package/dist/rules/modules/stdlib/state.rules +28 -0
  594. package/dist/rules/modules/stdlib/state.test.json +55 -0
  595. package/dist/rules/modules/stdlib/timing.rules +20 -0
  596. package/dist/rules/modules/stdlib/timing.test.json +106 -0
  597. package/dist/rules/modules/stdlib/transitions.rules +34 -0
  598. package/dist/rules/modules/stdlib/transitions.test.json +86 -0
  599. package/dist/rules/modules/stdlib/turns.rules +27 -0
  600. package/dist/rules/modules/stdlib/turns.test.json +64 -0
  601. package/dist/rules/modules/stdlib/validation.rules +31 -0
  602. package/dist/rules/modules/stdlib/validation.test.json +184 -0
  603. package/dist/rules/modules/stdlib-content.d.ts +11 -0
  604. package/dist/rules/modules/stdlib-content.d.ts.map +1 -0
  605. package/dist/rules/modules/stdlib-content.js +590 -0
  606. package/dist/rules/modules/stdlib-content.js.map +1 -0
  607. package/dist/rules/rtdb/compiled-rules.d.ts +11 -0
  608. package/dist/rules/rtdb/compiled-rules.d.ts.map +1 -0
  609. package/dist/rules/rtdb/compiled-rules.js +95 -0
  610. package/dist/rules/rtdb/compiled-rules.js.map +1 -0
  611. package/dist/rules/rtdb/constraints/atoms.d.ts +29 -0
  612. package/dist/rules/rtdb/constraints/atoms.d.ts.map +1 -0
  613. package/dist/rules/rtdb/constraints/atoms.js +43 -0
  614. package/dist/rules/rtdb/constraints/atoms.js.map +1 -0
  615. package/dist/rules/rtdb/constraints/compose.d.ts +16 -0
  616. package/dist/rules/rtdb/constraints/compose.d.ts.map +1 -0
  617. package/dist/rules/rtdb/constraints/compose.js +15 -0
  618. package/dist/rules/rtdb/constraints/compose.js.map +1 -0
  619. package/dist/rules/rtdb/constraints/data.d.ts +30 -0
  620. package/dist/rules/rtdb/constraints/data.d.ts.map +1 -0
  621. package/dist/rules/rtdb/constraints/data.js +46 -0
  622. package/dist/rules/rtdb/constraints/data.js.map +1 -0
  623. package/dist/rules/rtdb/constraints/document.d.ts +57 -0
  624. package/dist/rules/rtdb/constraints/document.d.ts.map +1 -0
  625. package/dist/rules/rtdb/constraints/document.js +85 -0
  626. package/dist/rules/rtdb/constraints/document.js.map +1 -0
  627. package/dist/rules/rtdb/constraints/game.d.ts +30 -0
  628. package/dist/rules/rtdb/constraints/game.d.ts.map +1 -0
  629. package/dist/rules/rtdb/constraints/game.js +49 -0
  630. package/dist/rules/rtdb/constraints/game.js.map +1 -0
  631. package/dist/rules/rtdb/constraints/index.d.ts +12 -0
  632. package/dist/rules/rtdb/constraints/index.d.ts.map +1 -0
  633. package/dist/rules/rtdb/constraints/index.js +9 -0
  634. package/dist/rules/rtdb/constraints/index.js.map +1 -0
  635. package/dist/rules/rtdb/constraints/policies.d.ts +16 -0
  636. package/dist/rules/rtdb/constraints/policies.d.ts.map +1 -0
  637. package/dist/rules/rtdb/constraints/policies.js +17 -0
  638. package/dist/rules/rtdb/constraints/policies.js.map +1 -0
  639. package/dist/rules/rtdb/constraints/ruleset.d.ts +5 -0
  640. package/dist/rules/rtdb/constraints/ruleset.d.ts.map +1 -0
  641. package/dist/rules/rtdb/constraints/ruleset.js +132 -0
  642. package/dist/rules/rtdb/constraints/ruleset.js.map +1 -0
  643. package/dist/rules/rtdb/constraints/schema.d.ts +17 -0
  644. package/dist/rules/rtdb/constraints/schema.d.ts.map +1 -0
  645. package/dist/rules/rtdb/constraints/schema.js +74 -0
  646. package/dist/rules/rtdb/constraints/schema.js.map +1 -0
  647. package/dist/rules/rtdb/constraints/types.d.ts +22 -0
  648. package/dist/rules/rtdb/constraints/types.d.ts.map +1 -0
  649. package/dist/rules/rtdb/constraints/types.js +2 -0
  650. package/dist/rules/rtdb/constraints/types.js.map +1 -0
  651. package/dist/rules/rtdb/constraints/write-rules-file.d.ts +24 -0
  652. package/dist/rules/rtdb/constraints/write-rules-file.d.ts.map +1 -0
  653. package/dist/rules/rtdb/constraints/write-rules-file.js +30 -0
  654. package/dist/rules/rtdb/constraints/write-rules-file.js.map +1 -0
  655. package/dist/rules/rtdb/expression-engine.d.ts +8 -0
  656. package/dist/rules/rtdb/expression-engine.d.ts.map +1 -0
  657. package/dist/rules/rtdb/expression-engine.js +20 -0
  658. package/dist/rules/rtdb/expression-engine.js.map +1 -0
  659. package/dist/rules/rtdb/grammar/RtdbExpr.ohm +98 -0
  660. package/dist/rules/rtdb/grammar/RtdbExpr.ohm.generated.d.ts +2 -0
  661. package/dist/rules/rtdb/grammar/RtdbExpr.ohm.generated.d.ts.map +1 -0
  662. package/dist/rules/rtdb/grammar/RtdbExpr.ohm.generated.js +103 -0
  663. package/dist/rules/rtdb/grammar/RtdbExpr.ohm.generated.js.map +1 -0
  664. package/dist/rules/rtdb/grammar/RtdbExprParser.d.ts +3 -0
  665. package/dist/rules/rtdb/grammar/RtdbExprParser.d.ts.map +1 -0
  666. package/dist/rules/rtdb/grammar/RtdbExprParser.js +56 -0
  667. package/dist/rules/rtdb/grammar/RtdbExprParser.js.map +1 -0
  668. package/dist/rules/rtdb/grammar/linter.d.ts +3 -0
  669. package/dist/rules/rtdb/grammar/linter.d.ts.map +1 -0
  670. package/dist/rules/rtdb/grammar/linter.js +73 -0
  671. package/dist/rules/rtdb/grammar/linter.js.map +1 -0
  672. package/dist/rules/rtdb/grammar/simulator.d.ts +30 -0
  673. package/dist/rules/rtdb/grammar/simulator.d.ts.map +1 -0
  674. package/dist/rules/rtdb/grammar/simulator.js +282 -0
  675. package/dist/rules/rtdb/grammar/simulator.js.map +1 -0
  676. package/dist/rules/rtdb/grammar/validator.d.ts +3 -0
  677. package/dist/rules/rtdb/grammar/validator.d.ts.map +1 -0
  678. package/dist/rules/rtdb/grammar/validator.js +91 -0
  679. package/dist/rules/rtdb/grammar/validator.js.map +1 -0
  680. package/dist/rules/rtdb/simulation/handler.d.ts +6 -0
  681. package/dist/rules/rtdb/simulation/handler.d.ts.map +1 -0
  682. package/dist/rules/rtdb/simulation/handler.js +325 -0
  683. package/dist/rules/rtdb/simulation/handler.js.map +1 -0
  684. package/dist/rules/rtdb/simulation/spec.d.ts +102 -0
  685. package/dist/rules/rtdb/simulation/spec.d.ts.map +1 -0
  686. package/dist/rules/rtdb/simulation/spec.js +40 -0
  687. package/dist/rules/rtdb/simulation/spec.js.map +1 -0
  688. package/dist/rules/rtdb/types.d.ts +166 -0
  689. package/dist/rules/rtdb/types.d.ts.map +1 -0
  690. package/dist/rules/rtdb/types.js +21 -0
  691. package/dist/rules/rtdb/types.js.map +1 -0
  692. package/dist/rules/simulator/evaluator.d.ts +206 -0
  693. package/dist/rules/simulator/evaluator.d.ts.map +1 -0
  694. package/dist/rules/simulator/evaluator.js +1251 -0
  695. package/dist/rules/simulator/evaluator.js.map +1 -0
  696. package/dist/rules/simulator/expression/eval-errors.d.ts +86 -0
  697. package/dist/rules/simulator/expression/eval-errors.d.ts.map +1 -0
  698. package/dist/rules/simulator/expression/eval-errors.js +68 -0
  699. package/dist/rules/simulator/expression/eval-errors.js.map +1 -0
  700. package/dist/rules/simulator/expression/evaluator.d.ts +43 -0
  701. package/dist/rules/simulator/expression/evaluator.d.ts.map +1 -0
  702. package/dist/rules/simulator/expression/evaluator.js +298 -0
  703. package/dist/rules/simulator/expression/evaluator.js.map +1 -0
  704. package/dist/rules/simulator/expression/lexer.d.ts +36 -0
  705. package/dist/rules/simulator/expression/lexer.d.ts.map +1 -0
  706. package/dist/rules/simulator/expression/lexer.js +318 -0
  707. package/dist/rules/simulator/expression/lexer.js.map +1 -0
  708. package/dist/rules/simulator/expression/parser.d.ts +39 -0
  709. package/dist/rules/simulator/expression/parser.d.ts.map +1 -0
  710. package/dist/rules/simulator/expression/parser.js +329 -0
  711. package/dist/rules/simulator/expression/parser.js.map +1 -0
  712. package/dist/rules/simulator/expression/types.d.ts +137 -0
  713. package/dist/rules/simulator/expression/types.d.ts.map +1 -0
  714. package/dist/rules/simulator/expression/types.js +90 -0
  715. package/dist/rules/simulator/expression/types.js.map +1 -0
  716. package/dist/rules/simulator/expression/walk-data.d.ts +52 -0
  717. package/dist/rules/simulator/expression/walk-data.d.ts.map +1 -0
  718. package/dist/rules/simulator/expression/walk-data.js +167 -0
  719. package/dist/rules/simulator/expression/walk-data.js.map +1 -0
  720. package/dist/rules/simulator/firestore-set.d.ts +25 -0
  721. package/dist/rules/simulator/firestore-set.d.ts.map +1 -0
  722. package/dist/rules/simulator/firestore-set.js +89 -0
  723. package/dist/rules/simulator/firestore-set.js.map +1 -0
  724. package/dist/rules/simulator/handler.d.ts +47 -0
  725. package/dist/rules/simulator/handler.d.ts.map +1 -0
  726. package/dist/rules/simulator/handler.js +644 -0
  727. package/dist/rules/simulator/handler.js.map +1 -0
  728. package/dist/rules/simulator/mapdiff.d.ts +29 -0
  729. package/dist/rules/simulator/mapdiff.d.ts.map +1 -0
  730. package/dist/rules/simulator/mapdiff.js +72 -0
  731. package/dist/rules/simulator/mapdiff.js.map +1 -0
  732. package/dist/rules/simulator/project-after-state.d.ts +33 -0
  733. package/dist/rules/simulator/project-after-state.d.ts.map +1 -0
  734. package/dist/rules/simulator/project-after-state.js +88 -0
  735. package/dist/rules/simulator/project-after-state.js.map +1 -0
  736. package/dist/rules/simulator/query-proof.d.ts +80 -0
  737. package/dist/rules/simulator/query-proof.d.ts.map +1 -0
  738. package/dist/rules/simulator/query-proof.js +142 -0
  739. package/dist/rules/simulator/query-proof.js.map +1 -0
  740. package/dist/rules/simulator/value-equality.d.ts +8 -0
  741. package/dist/rules/simulator/value-equality.d.ts.map +1 -0
  742. package/dist/rules/simulator/value-equality.js +40 -0
  743. package/dist/rules/simulator/value-equality.js.map +1 -0
  744. package/dist/rules/simulator/wrappers/base.d.ts +129 -0
  745. package/dist/rules/simulator/wrappers/base.d.ts.map +1 -0
  746. package/dist/rules/simulator/wrappers/base.js +90 -0
  747. package/dist/rules/simulator/wrappers/base.js.map +1 -0
  748. package/dist/rules/simulator/wrappers/bytes.d.ts +45 -0
  749. package/dist/rules/simulator/wrappers/bytes.d.ts.map +1 -0
  750. package/dist/rules/simulator/wrappers/bytes.js +130 -0
  751. package/dist/rules/simulator/wrappers/bytes.js.map +1 -0
  752. package/dist/rules/simulator/wrappers/duration.d.ts +76 -0
  753. package/dist/rules/simulator/wrappers/duration.d.ts.map +1 -0
  754. package/dist/rules/simulator/wrappers/duration.js +176 -0
  755. package/dist/rules/simulator/wrappers/duration.js.map +1 -0
  756. package/dist/rules/simulator/wrappers/float.d.ts +52 -0
  757. package/dist/rules/simulator/wrappers/float.d.ts.map +1 -0
  758. package/dist/rules/simulator/wrappers/float.js +88 -0
  759. package/dist/rules/simulator/wrappers/float.js.map +1 -0
  760. package/dist/rules/simulator/wrappers/latlng.d.ts +40 -0
  761. package/dist/rules/simulator/wrappers/latlng.d.ts.map +1 -0
  762. package/dist/rules/simulator/wrappers/latlng.js +100 -0
  763. package/dist/rules/simulator/wrappers/latlng.js.map +1 -0
  764. package/dist/rules/simulator/wrappers/path.d.ts +75 -0
  765. package/dist/rules/simulator/wrappers/path.d.ts.map +1 -0
  766. package/dist/rules/simulator/wrappers/path.js +158 -0
  767. package/dist/rules/simulator/wrappers/path.js.map +1 -0
  768. package/dist/rules/simulator/wrappers/reference.d.ts +82 -0
  769. package/dist/rules/simulator/wrappers/reference.d.ts.map +1 -0
  770. package/dist/rules/simulator/wrappers/reference.js +145 -0
  771. package/dist/rules/simulator/wrappers/reference.js.map +1 -0
  772. package/dist/rules/simulator/wrappers/timestamp.d.ts +86 -0
  773. package/dist/rules/simulator/wrappers/timestamp.d.ts.map +1 -0
  774. package/dist/rules/simulator/wrappers/timestamp.js +207 -0
  775. package/dist/rules/simulator/wrappers/timestamp.js.map +1 -0
  776. package/dist/rules/simulator/wrappers/vector.d.ts +43 -0
  777. package/dist/rules/simulator/wrappers/vector.d.ts.map +1 -0
  778. package/dist/rules/simulator/wrappers/vector.js +80 -0
  779. package/dist/rules/simulator/wrappers/vector.js.map +1 -0
  780. package/dist/rules/simulator-tools-impl.d.ts +64 -0
  781. package/dist/rules/simulator-tools-impl.d.ts.map +1 -0
  782. package/dist/rules/simulator-tools-impl.js +462 -0
  783. package/dist/rules/simulator-tools-impl.js.map +1 -0
  784. package/dist/rules/simulator.d.ts +20 -0
  785. package/dist/rules/simulator.d.ts.map +1 -0
  786. package/dist/rules/simulator.js +24 -0
  787. package/dist/rules/simulator.js.map +1 -0
  788. package/dist/rules/stdlib-modules.d.ts +73 -0
  789. package/dist/rules/stdlib-modules.d.ts.map +1 -0
  790. package/dist/rules/stdlib-modules.js +837 -0
  791. package/dist/rules/stdlib-modules.js.map +1 -0
  792. package/dist/rules/stdlib-tools.d.ts +19 -0
  793. package/dist/rules/stdlib-tools.d.ts.map +1 -0
  794. package/dist/rules/stdlib-tools.js +164 -0
  795. package/dist/rules/stdlib-tools.js.map +1 -0
  796. package/dist/rules/test/handler.d.ts +21 -0
  797. package/dist/rules/test/handler.d.ts.map +1 -0
  798. package/dist/rules/test/handler.js +214 -0
  799. package/dist/rules/test/handler.js.map +1 -0
  800. package/dist/rules/test/spec.d.ts +677 -0
  801. package/dist/rules/test/spec.d.ts.map +1 -0
  802. package/dist/rules/test/spec.js +327 -0
  803. package/dist/rules/test/spec.js.map +1 -0
  804. package/dist/rules/tools.d.ts +41 -0
  805. package/dist/rules/tools.d.ts.map +1 -0
  806. package/dist/rules/tools.js +120 -0
  807. package/dist/rules/tools.js.map +1 -0
  808. package/dist/rules/write/handler.d.ts +6 -0
  809. package/dist/rules/write/handler.d.ts.map +1 -0
  810. package/dist/rules/write/handler.js +126 -0
  811. package/dist/rules/write/handler.js.map +1 -0
  812. package/dist/rules/write/spec.d.ts +28 -0
  813. package/dist/rules/write/spec.d.ts.map +1 -0
  814. package/dist/rules/write/spec.js +2 -0
  815. package/dist/rules/write/spec.js.map +1 -0
  816. package/dist/sandbox/admin-compat.d.ts +20 -0
  817. package/dist/sandbox/admin-compat.d.ts.map +1 -0
  818. package/dist/sandbox/admin-compat.js +19 -0
  819. package/dist/sandbox/admin-compat.js.map +1 -0
  820. package/dist/sandbox/admin-firestore/error-translation.d.ts +90 -0
  821. package/dist/sandbox/admin-firestore/error-translation.d.ts.map +1 -0
  822. package/dist/sandbox/admin-firestore/error-translation.js +214 -0
  823. package/dist/sandbox/admin-firestore/error-translation.js.map +1 -0
  824. package/dist/sandbox/admin-firestore/get-admin-firestore.d.ts +44 -0
  825. package/dist/sandbox/admin-firestore/get-admin-firestore.d.ts.map +1 -0
  826. package/dist/sandbox/admin-firestore/get-admin-firestore.js +62 -0
  827. package/dist/sandbox/admin-firestore/get-admin-firestore.js.map +1 -0
  828. package/dist/sandbox/admin-firestore/get-firestore.d.ts +34 -0
  829. package/dist/sandbox/admin-firestore/get-firestore.d.ts.map +1 -0
  830. package/dist/sandbox/admin-firestore/get-firestore.js +71 -0
  831. package/dist/sandbox/admin-firestore/get-firestore.js.map +1 -0
  832. package/dist/sandbox/admin-firestore/index.d.ts +36 -0
  833. package/dist/sandbox/admin-firestore/index.d.ts.map +1 -0
  834. package/dist/sandbox/admin-firestore/index.js +33 -0
  835. package/dist/sandbox/admin-firestore/index.js.map +1 -0
  836. package/dist/sandbox/admin-firestore/listeners.d.ts +46 -0
  837. package/dist/sandbox/admin-firestore/listeners.d.ts.map +1 -0
  838. package/dist/sandbox/admin-firestore/listeners.js +290 -0
  839. package/dist/sandbox/admin-firestore/listeners.js.map +1 -0
  840. package/dist/sandbox/admin-firestore/local-handle.d.ts +23 -0
  841. package/dist/sandbox/admin-firestore/local-handle.d.ts.map +1 -0
  842. package/dist/sandbox/admin-firestore/local-handle.js +74 -0
  843. package/dist/sandbox/admin-firestore/local-handle.js.map +1 -0
  844. package/dist/sandbox/admin-firestore/remote/batch.d.ts +6 -0
  845. package/dist/sandbox/admin-firestore/remote/batch.d.ts.map +1 -0
  846. package/dist/sandbox/admin-firestore/remote/batch.js +38 -0
  847. package/dist/sandbox/admin-firestore/remote/batch.js.map +1 -0
  848. package/dist/sandbox/admin-firestore/remote/channel.d.ts +22 -0
  849. package/dist/sandbox/admin-firestore/remote/channel.d.ts.map +1 -0
  850. package/dist/sandbox/admin-firestore/remote/channel.js +27 -0
  851. package/dist/sandbox/admin-firestore/remote/channel.js.map +1 -0
  852. package/dist/sandbox/admin-firestore/remote/doc-ref.d.ts +10 -0
  853. package/dist/sandbox/admin-firestore/remote/doc-ref.d.ts.map +1 -0
  854. package/dist/sandbox/admin-firestore/remote/doc-ref.js +88 -0
  855. package/dist/sandbox/admin-firestore/remote/doc-ref.js.map +1 -0
  856. package/dist/sandbox/admin-firestore/remote/errors.d.ts +17 -0
  857. package/dist/sandbox/admin-firestore/remote/errors.d.ts.map +1 -0
  858. package/dist/sandbox/admin-firestore/remote/errors.js +32 -0
  859. package/dist/sandbox/admin-firestore/remote/errors.js.map +1 -0
  860. package/dist/sandbox/admin-firestore/remote/listeners.d.ts +43 -0
  861. package/dist/sandbox/admin-firestore/remote/listeners.d.ts.map +1 -0
  862. package/dist/sandbox/admin-firestore/remote/listeners.js +89 -0
  863. package/dist/sandbox/admin-firestore/remote/listeners.js.map +1 -0
  864. package/dist/sandbox/admin-firestore/remote/query.d.ts +47 -0
  865. package/dist/sandbox/admin-firestore/remote/query.d.ts.map +1 -0
  866. package/dist/sandbox/admin-firestore/remote/query.js +186 -0
  867. package/dist/sandbox/admin-firestore/remote/query.js.map +1 -0
  868. package/dist/sandbox/admin-firestore/remote/remote-firestore.d.ts +55 -0
  869. package/dist/sandbox/admin-firestore/remote/remote-firestore.d.ts.map +1 -0
  870. package/dist/sandbox/admin-firestore/remote/remote-firestore.js +111 -0
  871. package/dist/sandbox/admin-firestore/remote/remote-firestore.js.map +1 -0
  872. package/dist/sandbox/admin-firestore/remote/snapshots.d.ts +10 -0
  873. package/dist/sandbox/admin-firestore/remote/snapshots.d.ts.map +1 -0
  874. package/dist/sandbox/admin-firestore/remote/snapshots.js +37 -0
  875. package/dist/sandbox/admin-firestore/remote/snapshots.js.map +1 -0
  876. package/dist/sandbox/admin-firestore/remote/transaction.d.ts +19 -0
  877. package/dist/sandbox/admin-firestore/remote/transaction.d.ts.map +1 -0
  878. package/dist/sandbox/admin-firestore/remote/transaction.js +105 -0
  879. package/dist/sandbox/admin-firestore/remote/transaction.js.map +1 -0
  880. package/dist/sandbox/admin-firestore/remote/value-codec.d.ts +52 -0
  881. package/dist/sandbox/admin-firestore/remote/value-codec.d.ts.map +1 -0
  882. package/dist/sandbox/admin-firestore/remote/value-codec.js +120 -0
  883. package/dist/sandbox/admin-firestore/remote/value-codec.js.map +1 -0
  884. package/dist/sandbox/admin-firestore/remote/wire-types.d.ts +111 -0
  885. package/dist/sandbox/admin-firestore/remote/wire-types.d.ts.map +1 -0
  886. package/dist/sandbox/admin-firestore/remote/wire-types.js +8 -0
  887. package/dist/sandbox/admin-firestore/remote/wire-types.js.map +1 -0
  888. package/dist/sandbox/admin-firestore/types.d.ts +59 -0
  889. package/dist/sandbox/admin-firestore/types.d.ts.map +1 -0
  890. package/dist/sandbox/admin-firestore/types.js +6 -0
  891. package/dist/sandbox/admin-firestore/types.js.map +1 -0
  892. package/dist/sandbox/branches/index.d.ts +141 -0
  893. package/dist/sandbox/branches/index.d.ts.map +1 -0
  894. package/dist/sandbox/branches/index.js +327 -0
  895. package/dist/sandbox/branches/index.js.map +1 -0
  896. package/dist/sandbox/firestore/admin-compat/batch.d.ts +34 -0
  897. package/dist/sandbox/firestore/admin-compat/batch.d.ts.map +1 -0
  898. package/dist/sandbox/firestore/admin-compat/batch.js +73 -0
  899. package/dist/sandbox/firestore/admin-compat/batch.js.map +1 -0
  900. package/dist/sandbox/firestore/admin-compat/doc-ref.d.ts +38 -0
  901. package/dist/sandbox/firestore/admin-compat/doc-ref.d.ts.map +1 -0
  902. package/dist/sandbox/firestore/admin-compat/doc-ref.js +154 -0
  903. package/dist/sandbox/firestore/admin-compat/doc-ref.js.map +1 -0
  904. package/dist/sandbox/firestore/admin-compat/firestore.d.ts +47 -0
  905. package/dist/sandbox/firestore/admin-compat/firestore.d.ts.map +1 -0
  906. package/dist/sandbox/firestore/admin-compat/firestore.js +117 -0
  907. package/dist/sandbox/firestore/admin-compat/firestore.js.map +1 -0
  908. package/dist/sandbox/firestore/admin-compat/index.d.ts +49 -0
  909. package/dist/sandbox/firestore/admin-compat/index.d.ts.map +1 -0
  910. package/dist/sandbox/firestore/admin-compat/index.js +27 -0
  911. package/dist/sandbox/firestore/admin-compat/index.js.map +1 -0
  912. package/dist/sandbox/firestore/admin-compat/paths.d.ts +37 -0
  913. package/dist/sandbox/firestore/admin-compat/paths.d.ts.map +1 -0
  914. package/dist/sandbox/firestore/admin-compat/paths.js +49 -0
  915. package/dist/sandbox/firestore/admin-compat/paths.js.map +1 -0
  916. package/dist/sandbox/firestore/admin-compat/query.d.ts +261 -0
  917. package/dist/sandbox/firestore/admin-compat/query.d.ts.map +1 -0
  918. package/dist/sandbox/firestore/admin-compat/query.js +758 -0
  919. package/dist/sandbox/firestore/admin-compat/query.js.map +1 -0
  920. package/dist/sandbox/firestore/admin-compat/read-translation.d.ts +8 -0
  921. package/dist/sandbox/firestore/admin-compat/read-translation.d.ts.map +1 -0
  922. package/dist/sandbox/firestore/admin-compat/read-translation.js +59 -0
  923. package/dist/sandbox/firestore/admin-compat/read-translation.js.map +1 -0
  924. package/dist/sandbox/firestore/admin-compat/snapshots.d.ts +39 -0
  925. package/dist/sandbox/firestore/admin-compat/snapshots.d.ts.map +1 -0
  926. package/dist/sandbox/firestore/admin-compat/snapshots.js +50 -0
  927. package/dist/sandbox/firestore/admin-compat/snapshots.js.map +1 -0
  928. package/dist/sandbox/firestore/admin-compat/transaction.d.ts +35 -0
  929. package/dist/sandbox/firestore/admin-compat/transaction.d.ts.map +1 -0
  930. package/dist/sandbox/firestore/admin-compat/transaction.js +88 -0
  931. package/dist/sandbox/firestore/admin-compat/transaction.js.map +1 -0
  932. package/dist/sandbox/firestore/admin-compat/types.d.ts +297 -0
  933. package/dist/sandbox/firestore/admin-compat/types.d.ts.map +1 -0
  934. package/dist/sandbox/firestore/admin-compat/types.js +127 -0
  935. package/dist/sandbox/firestore/admin-compat/types.js.map +1 -0
  936. package/dist/sandbox/firestore/admin-compat/value-order.d.ts +49 -0
  937. package/dist/sandbox/firestore/admin-compat/value-order.d.ts.map +1 -0
  938. package/dist/sandbox/firestore/admin-compat/value-order.js +172 -0
  939. package/dist/sandbox/firestore/admin-compat/value-order.js.map +1 -0
  940. package/dist/sandbox/firestore/auto-id.d.ts +26 -0
  941. package/dist/sandbox/firestore/auto-id.d.ts.map +1 -0
  942. package/dist/sandbox/firestore/auto-id.js +36 -0
  943. package/dist/sandbox/firestore/auto-id.js.map +1 -0
  944. package/dist/sandbox/firestore/converters/bytes-geopoint.d.ts +48 -0
  945. package/dist/sandbox/firestore/converters/bytes-geopoint.d.ts.map +1 -0
  946. package/dist/sandbox/firestore/converters/bytes-geopoint.js +85 -0
  947. package/dist/sandbox/firestore/converters/bytes-geopoint.js.map +1 -0
  948. package/dist/sandbox/firestore/converters/fieldvalue.d.ts +69 -0
  949. package/dist/sandbox/firestore/converters/fieldvalue.d.ts.map +1 -0
  950. package/dist/sandbox/firestore/converters/fieldvalue.js +166 -0
  951. package/dist/sandbox/firestore/converters/fieldvalue.js.map +1 -0
  952. package/dist/sandbox/firestore/converters/reference.d.ts +31 -0
  953. package/dist/sandbox/firestore/converters/reference.d.ts.map +1 -0
  954. package/dist/sandbox/firestore/converters/reference.js +51 -0
  955. package/dist/sandbox/firestore/converters/reference.js.map +1 -0
  956. package/dist/sandbox/firestore/converters/timestamp.d.ts +32 -0
  957. package/dist/sandbox/firestore/converters/timestamp.d.ts.map +1 -0
  958. package/dist/sandbox/firestore/converters/timestamp.js +63 -0
  959. package/dist/sandbox/firestore/converters/timestamp.js.map +1 -0
  960. package/dist/sandbox/firestore/converters/user-timestamp.d.ts +46 -0
  961. package/dist/sandbox/firestore/converters/user-timestamp.d.ts.map +1 -0
  962. package/dist/sandbox/firestore/converters/user-timestamp.js +65 -0
  963. package/dist/sandbox/firestore/converters/user-timestamp.js.map +1 -0
  964. package/dist/sandbox/firestore/converters/vector.d.ts +24 -0
  965. package/dist/sandbox/firestore/converters/vector.d.ts.map +1 -0
  966. package/dist/sandbox/firestore/converters/vector.js +53 -0
  967. package/dist/sandbox/firestore/converters/vector.js.map +1 -0
  968. package/dist/sandbox/firestore/errors.d.ts +82 -0
  969. package/dist/sandbox/firestore/errors.d.ts.map +1 -0
  970. package/dist/sandbox/firestore/errors.js +54 -0
  971. package/dist/sandbox/firestore/errors.js.map +1 -0
  972. package/dist/sandbox/firestore/event-log.d.ts +99 -0
  973. package/dist/sandbox/firestore/event-log.d.ts.map +1 -0
  974. package/dist/sandbox/firestore/event-log.js +67 -0
  975. package/dist/sandbox/firestore/event-log.js.map +1 -0
  976. package/dist/sandbox/firestore/field-merge.d.ts +64 -0
  977. package/dist/sandbox/firestore/field-merge.d.ts.map +1 -0
  978. package/dist/sandbox/firestore/field-merge.js +221 -0
  979. package/dist/sandbox/firestore/field-merge.js.map +1 -0
  980. package/dist/sandbox/firestore/list-query-proof.d.ts +77 -0
  981. package/dist/sandbox/firestore/list-query-proof.d.ts.map +1 -0
  982. package/dist/sandbox/firestore/list-query-proof.js +170 -0
  983. package/dist/sandbox/firestore/list-query-proof.js.map +1 -0
  984. package/dist/sandbox/firestore/local-environment.d.ts +825 -0
  985. package/dist/sandbox/firestore/local-environment.d.ts.map +1 -0
  986. package/dist/sandbox/firestore/local-environment.js +3129 -0
  987. package/dist/sandbox/firestore/local-environment.js.map +1 -0
  988. package/dist/sandbox/firestore/local-state.d.ts +196 -0
  989. package/dist/sandbox/firestore/local-state.d.ts.map +1 -0
  990. package/dist/sandbox/firestore/local-state.js +413 -0
  991. package/dist/sandbox/firestore/local-state.js.map +1 -0
  992. package/dist/sandbox/firestore/overlay-backing.d.ts +44 -0
  993. package/dist/sandbox/firestore/overlay-backing.d.ts.map +1 -0
  994. package/dist/sandbox/firestore/overlay-backing.js +82 -0
  995. package/dist/sandbox/firestore/overlay-backing.js.map +1 -0
  996. package/dist/sandbox/firestore/sentinel-capture.d.ts +30 -0
  997. package/dist/sandbox/firestore/sentinel-capture.d.ts.map +1 -0
  998. package/dist/sandbox/firestore/sentinel-capture.js +61 -0
  999. package/dist/sandbox/firestore/sentinel-capture.js.map +1 -0
  1000. package/dist/sandbox/firestore/snapshot-listeners.d.ts +290 -0
  1001. package/dist/sandbox/firestore/snapshot-listeners.d.ts.map +1 -0
  1002. package/dist/sandbox/firestore/snapshot-listeners.js +194 -0
  1003. package/dist/sandbox/firestore/snapshot-listeners.js.map +1 -0
  1004. package/dist/sandbox/firestore/topk.d.ts +12 -0
  1005. package/dist/sandbox/firestore/topk.d.ts.map +1 -0
  1006. package/dist/sandbox/firestore/topk.js +42 -0
  1007. package/dist/sandbox/firestore/topk.js.map +1 -0
  1008. package/dist/sandbox/firestore/transaction-merge.d.ts +55 -0
  1009. package/dist/sandbox/firestore/transaction-merge.d.ts.map +1 -0
  1010. package/dist/sandbox/firestore/transaction-merge.js +107 -0
  1011. package/dist/sandbox/firestore/transaction-merge.js.map +1 -0
  1012. package/dist/sandbox/firestore/transaction-types.d.ts +155 -0
  1013. package/dist/sandbox/firestore/transaction-types.d.ts.map +1 -0
  1014. package/dist/sandbox/firestore/transaction-types.js +10 -0
  1015. package/dist/sandbox/firestore/transaction-types.js.map +1 -0
  1016. package/dist/sandbox/firestore/transaction.d.ts +79 -0
  1017. package/dist/sandbox/firestore/transaction.d.ts.map +1 -0
  1018. package/dist/sandbox/firestore/transaction.js +95 -0
  1019. package/dist/sandbox/firestore/transaction.js.map +1 -0
  1020. package/dist/sandbox/firestore/value-equality.d.ts +2 -0
  1021. package/dist/sandbox/firestore/value-equality.d.ts.map +1 -0
  1022. package/dist/sandbox/firestore/value-equality.js +35 -0
  1023. package/dist/sandbox/firestore/value-equality.js.map +1 -0
  1024. package/dist/sandbox/firestore/value-resolver.d.ts +172 -0
  1025. package/dist/sandbox/firestore/value-resolver.d.ts.map +1 -0
  1026. package/dist/sandbox/firestore/value-resolver.js +221 -0
  1027. package/dist/sandbox/firestore/value-resolver.js.map +1 -0
  1028. package/dist/sandbox/firestore/wire-encoder.d.ts +14 -0
  1029. package/dist/sandbox/firestore/wire-encoder.d.ts.map +1 -0
  1030. package/dist/sandbox/firestore/wire-encoder.js +130 -0
  1031. package/dist/sandbox/firestore/wire-encoder.js.map +1 -0
  1032. package/dist/sandbox/index.d.ts +53 -0
  1033. package/dist/sandbox/index.d.ts.map +1 -0
  1034. package/dist/sandbox/index.js +65 -0
  1035. package/dist/sandbox/index.js.map +1 -0
  1036. package/dist/sandbox/internal/client-app.d.ts +29 -0
  1037. package/dist/sandbox/internal/client-app.d.ts.map +1 -0
  1038. package/dist/sandbox/internal/client-app.js +18 -0
  1039. package/dist/sandbox/internal/client-app.js.map +1 -0
  1040. package/dist/sandbox/internal/firebase-error.d.ts +14 -0
  1041. package/dist/sandbox/internal/firebase-error.d.ts.map +1 -0
  1042. package/dist/sandbox/internal/firebase-error.js +22 -0
  1043. package/dist/sandbox/internal/firebase-error.js.map +1 -0
  1044. package/dist/sandbox/internal/index.d.ts +39 -0
  1045. package/dist/sandbox/internal/index.d.ts.map +1 -0
  1046. package/dist/sandbox/internal/index.js +75 -0
  1047. package/dist/sandbox/internal/index.js.map +1 -0
  1048. package/dist/sandbox/internal/local-brand.d.ts +3 -0
  1049. package/dist/sandbox/internal/local-brand.d.ts.map +1 -0
  1050. package/dist/sandbox/internal/local-brand.js +3 -0
  1051. package/dist/sandbox/internal/local-brand.js.map +1 -0
  1052. package/dist/sandbox/internal/provenance.d.ts +16 -0
  1053. package/dist/sandbox/internal/provenance.d.ts.map +1 -0
  1054. package/dist/sandbox/internal/provenance.js +139 -0
  1055. package/dist/sandbox/internal/provenance.js.map +1 -0
  1056. package/dist/sandbox/internal/sandbox-impl.d.ts +328 -0
  1057. package/dist/sandbox/internal/sandbox-impl.d.ts.map +1 -0
  1058. package/dist/sandbox/internal/sandbox-impl.js +695 -0
  1059. package/dist/sandbox/internal/sandbox-impl.js.map +1 -0
  1060. package/dist/sandbox/operation-record.d.ts +48 -0
  1061. package/dist/sandbox/operation-record.d.ts.map +1 -0
  1062. package/dist/sandbox/operation-record.js +143 -0
  1063. package/dist/sandbox/operation-record.js.map +1 -0
  1064. package/dist/sandbox/persistence/backends.d.ts +37 -0
  1065. package/dist/sandbox/persistence/backends.d.ts.map +1 -0
  1066. package/dist/sandbox/persistence/backends.js +202 -0
  1067. package/dist/sandbox/persistence/backends.js.map +1 -0
  1068. package/dist/sandbox/persistence/chunk-format.d.ts +58 -0
  1069. package/dist/sandbox/persistence/chunk-format.d.ts.map +1 -0
  1070. package/dist/sandbox/persistence/chunk-format.js +163 -0
  1071. package/dist/sandbox/persistence/chunk-format.js.map +1 -0
  1072. package/dist/sandbox/persistence/controller.d.ts +39 -0
  1073. package/dist/sandbox/persistence/controller.d.ts.map +1 -0
  1074. package/dist/sandbox/persistence/controller.js +505 -0
  1075. package/dist/sandbox/persistence/controller.js.map +1 -0
  1076. package/dist/sandbox/persistence/index.d.ts +13 -0
  1077. package/dist/sandbox/persistence/index.d.ts.map +1 -0
  1078. package/dist/sandbox/persistence/index.js +5 -0
  1079. package/dist/sandbox/persistence/index.js.map +1 -0
  1080. package/dist/sandbox/persistence/serialize.d.ts +53 -0
  1081. package/dist/sandbox/persistence/serialize.d.ts.map +1 -0
  1082. package/dist/sandbox/persistence/serialize.js +98 -0
  1083. package/dist/sandbox/persistence/serialize.js.map +1 -0
  1084. package/dist/sandbox/persistence/types.d.ts +118 -0
  1085. package/dist/sandbox/persistence/types.d.ts.map +1 -0
  1086. package/dist/sandbox/persistence/types.js +15 -0
  1087. package/dist/sandbox/persistence/types.js.map +1 -0
  1088. package/dist/sandbox/remote.d.ts +118 -0
  1089. package/dist/sandbox/remote.d.ts.map +1 -0
  1090. package/dist/sandbox/remote.js +60 -0
  1091. package/dist/sandbox/remote.js.map +1 -0
  1092. package/dist/sandbox/replay/index.d.ts +106 -0
  1093. package/dist/sandbox/replay/index.d.ts.map +1 -0
  1094. package/dist/sandbox/replay/index.js +246 -0
  1095. package/dist/sandbox/replay/index.js.map +1 -0
  1096. package/dist/sandbox/sandbox-context.d.ts +48 -0
  1097. package/dist/sandbox/sandbox-context.d.ts.map +1 -0
  1098. package/dist/sandbox/sandbox-context.js +97 -0
  1099. package/dist/sandbox/sandbox-context.js.map +1 -0
  1100. package/dist/sandbox/tab-sync/index.d.ts +120 -0
  1101. package/dist/sandbox/tab-sync/index.d.ts.map +1 -0
  1102. package/dist/sandbox/tab-sync/index.js +273 -0
  1103. package/dist/sandbox/tab-sync/index.js.map +1 -0
  1104. package/dist/sandbox/types/auth-state.d.ts +23 -0
  1105. package/dist/sandbox/types/auth-state.d.ts.map +1 -0
  1106. package/dist/sandbox/types/auth-state.js +8 -0
  1107. package/dist/sandbox/types/auth-state.js.map +1 -0
  1108. package/dist/sandbox/types/context.d.ts +33 -0
  1109. package/dist/sandbox/types/context.d.ts.map +1 -0
  1110. package/dist/sandbox/types/context.js +5 -0
  1111. package/dist/sandbox/types/context.js.map +1 -0
  1112. package/dist/sandbox/types/errors.d.ts +109 -0
  1113. package/dist/sandbox/types/errors.d.ts.map +1 -0
  1114. package/dist/sandbox/types/errors.js +41 -0
  1115. package/dist/sandbox/types/errors.js.map +1 -0
  1116. package/dist/sandbox/types/events.d.ts +577 -0
  1117. package/dist/sandbox/types/events.d.ts.map +1 -0
  1118. package/dist/sandbox/types/events.js +7 -0
  1119. package/dist/sandbox/types/events.js.map +1 -0
  1120. package/dist/sandbox/types/index.d.ts +24 -0
  1121. package/dist/sandbox/types/index.d.ts.map +1 -0
  1122. package/dist/sandbox/types/index.js +17 -0
  1123. package/dist/sandbox/types/index.js.map +1 -0
  1124. package/dist/sandbox/types/operation.d.ts +60 -0
  1125. package/dist/sandbox/types/operation.d.ts.map +1 -0
  1126. package/dist/sandbox/types/operation.js +3 -0
  1127. package/dist/sandbox/types/operation.js.map +1 -0
  1128. package/dist/sandbox/types/persistence.d.ts +130 -0
  1129. package/dist/sandbox/types/persistence.d.ts.map +1 -0
  1130. package/dist/sandbox/types/persistence.js +7 -0
  1131. package/dist/sandbox/types/persistence.js.map +1 -0
  1132. package/dist/sandbox/types/service.d.ts +357 -0
  1133. package/dist/sandbox/types/service.d.ts.map +1 -0
  1134. package/dist/sandbox/types/service.js +6 -0
  1135. package/dist/sandbox/types/service.js.map +1 -0
  1136. package/dist/storage/admin/api.d.ts +206 -0
  1137. package/dist/storage/admin/api.d.ts.map +1 -0
  1138. package/dist/storage/admin/api.js +349 -0
  1139. package/dist/storage/admin/api.js.map +1 -0
  1140. package/dist/storage/admin/handler.d.ts +28 -0
  1141. package/dist/storage/admin/handler.d.ts.map +1 -0
  1142. package/dist/storage/admin/handler.js +82 -0
  1143. package/dist/storage/admin/handler.js.map +1 -0
  1144. package/dist/storage/admin/spec.d.ts +64 -0
  1145. package/dist/storage/admin/spec.d.ts.map +1 -0
  1146. package/dist/storage/admin/spec.js +8 -0
  1147. package/dist/storage/admin/spec.js.map +1 -0
  1148. package/dist/storage/admin/tools.d.ts +22 -0
  1149. package/dist/storage/admin/tools.d.ts.map +1 -0
  1150. package/dist/storage/admin/tools.js +90 -0
  1151. package/dist/storage/admin/tools.js.map +1 -0
  1152. package/dist/storage/download.d.ts +41 -0
  1153. package/dist/storage/download.d.ts.map +1 -0
  1154. package/dist/storage/download.js +137 -0
  1155. package/dist/storage/download.js.map +1 -0
  1156. package/dist/storage/enforce.d.ts +5 -0
  1157. package/dist/storage/enforce.d.ts.map +1 -0
  1158. package/dist/storage/enforce.js +147 -0
  1159. package/dist/storage/enforce.js.map +1 -0
  1160. package/dist/storage/errors.d.ts +44 -0
  1161. package/dist/storage/errors.d.ts.map +1 -0
  1162. package/dist/storage/errors.js +64 -0
  1163. package/dist/storage/errors.js.map +1 -0
  1164. package/dist/storage/index.d.ts +45 -0
  1165. package/dist/storage/index.d.ts.map +1 -0
  1166. package/dist/storage/index.js +39 -0
  1167. package/dist/storage/index.js.map +1 -0
  1168. package/dist/storage/instances.d.ts +9 -0
  1169. package/dist/storage/instances.d.ts.map +1 -0
  1170. package/dist/storage/instances.js +24 -0
  1171. package/dist/storage/instances.js.map +1 -0
  1172. package/dist/storage/internal.d.ts +18 -0
  1173. package/dist/storage/internal.d.ts.map +1 -0
  1174. package/dist/storage/internal.js +18 -0
  1175. package/dist/storage/internal.js.map +1 -0
  1176. package/dist/storage/list.d.ts +42 -0
  1177. package/dist/storage/list.d.ts.map +1 -0
  1178. package/dist/storage/list.js +83 -0
  1179. package/dist/storage/list.js.map +1 -0
  1180. package/dist/storage/metadata.d.ts +92 -0
  1181. package/dist/storage/metadata.d.ts.map +1 -0
  1182. package/dist/storage/metadata.js +164 -0
  1183. package/dist/storage/metadata.js.map +1 -0
  1184. package/dist/storage/persistence.d.ts +134 -0
  1185. package/dist/storage/persistence.d.ts.map +1 -0
  1186. package/dist/storage/persistence.js +132 -0
  1187. package/dist/storage/persistence.js.map +1 -0
  1188. package/dist/storage/reference.d.ts +57 -0
  1189. package/dist/storage/reference.d.ts.map +1 -0
  1190. package/dist/storage/reference.js +105 -0
  1191. package/dist/storage/reference.js.map +1 -0
  1192. package/dist/storage/rules.d.ts +339 -0
  1193. package/dist/storage/rules.d.ts.map +1 -0
  1194. package/dist/storage/rules.js +1334 -0
  1195. package/dist/storage/rules.js.map +1 -0
  1196. package/dist/storage/service.d.ts +122 -0
  1197. package/dist/storage/service.d.ts.map +1 -0
  1198. package/dist/storage/service.js +247 -0
  1199. package/dist/storage/service.js.map +1 -0
  1200. package/dist/storage/upload.d.ts +50 -0
  1201. package/dist/storage/upload.d.ts.map +1 -0
  1202. package/dist/storage/upload.js +246 -0
  1203. package/dist/storage/upload.js.map +1 -0
  1204. package/package.json +156 -3
@@ -0,0 +1,2007 @@
1
+ /**
2
+ * Sandbox backend for `pyric/auth`.
3
+ *
4
+ * Owns app-session state over a sandbox-shared project store:
5
+ * 1. In-memory user database — emails / passwords / customClaims
6
+ * seeded via `sandbox.seedUsers(auth, …)` plus accounts created
7
+ * through `createUserWithEmailAndPassword`.
8
+ * 2. Listener registries — one for `onAuthStateChanged`, one for
9
+ * `onIdTokenChanged`. Both fire on user change; the
10
+ * `onIdTokenChanged` registry ALSO fires on a forced ID-token
11
+ * refresh (matches prod — see oracle observation
12
+ * `auth-onidtokenchanged-force-refresh.json`).
13
+ * 3. Auth-flow staging — the pre-staged `UserCredential` mock
14
+ * registry (consumed by `signInWithPopup` /
15
+ * `signInWithCredential`), the injected popup/redirect resolver,
16
+ * and the pending redirect-result slot. Delegated to
17
+ * {@link AuthFlowRegistry} (`sandbox-auth-flow.ts`); the backend
18
+ * holds one `flow` field and the accessor methods forward to it.
19
+ * 4. Token cache — current ID token string + IdTokenResult per uid.
20
+ * A fresh token is minted on each setCurrentUser transition into
21
+ * a non-null user (new session = new token) and on each
22
+ * `getIdToken(forceRefresh=true)`. Subsequent
23
+ * `getIdToken(false)` reads return the cached token (matches
24
+ * prod — see `auth-getidtoken-force-refresh.json`).
25
+ *
26
+ * The current user lives on the injected session host. The default app and
27
+ * bare-sandbox API use `sandbox.currentUser`; named apps inject independent
28
+ * session hosts, while Firestore/RTDB/Storage read that app session per call.
29
+ *
30
+ * `signInAnonymously` / `signInWithEmailAndPassword` / `signOut` /
31
+ * `sandbox.setUser` all flow through {@link setCurrentUser}, which
32
+ * writes the session's `currentUser` and fans out to both listener
33
+ * registries. The session setter is idempotent,
34
+ * so calling it with the same identity twice is a no-op.
35
+ */
36
+ import { makeAuthError } from './auth-errors.js';
37
+ import { AuthFlowRegistry, } from './sandbox-auth-flow.js';
38
+ import { sandboxTokenFor } from './sandbox-token.js';
39
+ import { validateEmailFormat, validatePasswordStrength } from './sandbox-credential-validators.js';
40
+ import { createAuthProjectStore, } from './sandbox/project-store.js';
41
+ import { emitSandboxEvent, makeServiceMutationEvent } from 'pyric/sandbox/internal';
42
+ import { USER_INTERNAL, } from './types.js';
43
+ import { NO_PASSWORD_SENTINEL, } from './sandbox-backend-types.js';
44
+ // Re-export the public backend types + the sentinel value from the
45
+ // barrel so consumers importing them from './sandbox-backend.js' are
46
+ // unchanged.
47
+ export { NO_PASSWORD_SENTINEL } from './sandbox-backend-types.js';
48
+ /**
49
+ * Per-app-session backend state. Repeated `getAuth(app)` calls are memoized;
50
+ * sibling app backends share account/provider maps but not currentUser,
51
+ * listeners, tokens, flow staging, or persistence mode.
52
+ */
53
+ export class SandboxBackend {
54
+ /** Email → stored user. Lowercase keys so lookups are case-
55
+ * insensitive (matches upstream). */
56
+ usersByEmail;
57
+ /** UID → stored user. Lets `setUser` resolve customClaims for an
58
+ * arbitrary uid without scanning the email index. */
59
+ usersByUid;
60
+ /** onAuthStateChanged registrations. Array, NOT a Set, so duplicate
61
+ * observer functions register independently — upstream backs each
62
+ * registry with an array (`util/src/subscribe.ts:191` pushes; dups
63
+ * allowed) and `unsubscribeOne(i)` removes by *index*, so the same
64
+ * fn subscribed twice fires twice and one unsubscribe removes one
65
+ * registration (AUTH-B4). Each record carries its own initial-fire
66
+ * bookkeeping so a shared per-observer dedup can't suppress a
67
+ * resubscribe or a second registration of the same fn (AUTH-B3). */
68
+ authStateSubs = [];
69
+ /** onIdTokenChanged registrations. Same array semantics. */
70
+ idTokenSubs = [];
71
+ /** `subscribeUsers` subscribers — coarse "user DB changed"
72
+ * callbacks; listeners re-list via `listUsers`. */
73
+ userDbSubs;
74
+ /** `beforeAuthStateChanged` registrations, in registration order.
75
+ * Mirrors upstream's `AuthMiddlewareQueue` (`auth_impl.ts`): an
76
+ * array (NOT a Set) so duplicate callback fns register
77
+ * independently, and unregistering swaps the slot for a no-op
78
+ * instead of splicing — splicing would shift later indices and
79
+ * disturb an in-flight `runBeforeStateChange` iteration. */
80
+ beforeStateSubs = [];
81
+ /** Monotonic uid counter for `createUser` calls without a uid. */
82
+ sharedCounters;
83
+ /** Popup / redirect / credential flow-staging machinery — the
84
+ * one-shot mock registry, the injected resolver, and the pending
85
+ * redirect-result slot. Kept in {@link AuthFlowRegistry} (see
86
+ * `sandbox-auth-flow.ts`) because that state is independent of the
87
+ * coupled auth state machine, and it is the seam the email-link /
88
+ * linking / reauth climbs extend. The six accessor methods below
89
+ * delegate here verbatim. */
90
+ flow = new AuthFlowRegistry();
91
+ /** Underlying sandbox — written to on every sign-in/out. */
92
+ sandbox;
93
+ /** App-local session state. Bare-sandbox callers use the sandbox itself. */
94
+ session;
95
+ /** Cached `User` for `auth.currentUser` snapshots. Recomputed when
96
+ * the sandbox's currentUser changes; null on signed-out. */
97
+ cachedUser = null;
98
+ /** The uid `onAuthStateChanged` was last notified with. Mirrors
99
+ * upstream's `lastNotifiedUid` (`auth_impl.ts:720`): auth-state only
100
+ * re-fires when this changes, so a same-uid profile-shape change or a
101
+ * same-uid re-sign-in does NOT re-fire auth-state (AUTH-B7). */
102
+ lastNotifiedUid = null;
103
+ /** True while {@link setCurrentUser} is driving a transition through
104
+ * the sandbox setter. The synchronous `onCurrentUserChanged`
105
+ * subscriber checks this so it doesn't double-notify — setCurrentUser
106
+ * owns the fan-out decision (id-token always, auth-state on uid
107
+ * change). The subscriber only notifies for EXTERNAL mutations
108
+ * (direct sandbox writes, `reset()`, another handle). */
109
+ applyingTransition = false;
110
+ /** Per-uid current ID token + result. Refreshed on each
111
+ * `getIdToken(forceRefresh=true)` and on each new sign-in
112
+ * transition (so a sign-out / sign-in round-trip mints a fresh
113
+ * token, matching prod's "new session = new token" semantics).
114
+ * Subsequent `getIdToken(false)` reads return the cached value. */
115
+ tokenCache = new Map();
116
+ /** Monotonic counter used to disambiguate freshly-minted tokens
117
+ * for the same uid + claims map. Without this, two refreshes that
118
+ * happen within the same millisecond would hash to the same
119
+ * string (claims map + iat tie-breaker not enough). */
120
+ nextTokenSerial = 1;
121
+ /**
122
+ * Current persistence mode — mirrors the real Firebase SDK's
123
+ * `setPersistence` semantics. Default is `'LOCAL'` (Firebase default:
124
+ * `browserLocalPersistence` keeps you signed in across reloads and
125
+ * browser restarts).
126
+ *
127
+ * Stored here on the backend so the persistence controller can read it
128
+ * without knowing about auth internals. The `auth/modular.ts` top-level
129
+ * `setPersistence` function writes this via `setPersistenceMode`; the
130
+ * controller reads it via `getPersistenceMode` on every session save.
131
+ *
132
+ * Subscribers to persistence-mode changes (the set holding the
133
+ * controller's session-save callback) are notified by `setPersistenceMode`
134
+ * so a `setPersistence` call that changes the mode immediately migrates
135
+ * the session to the new store without waiting for the next sign-in.
136
+ */
137
+ persistenceMode = 'LOCAL';
138
+ /** Per-uid provider of the *current/most-recent* sign-in session —
139
+ * backs `IdTokenResult.signInProvider` and the synthesized
140
+ * `firebase.sign_in_provider` token claim. Written by each
141
+ * sign-in path via {@link setCurrentUser}'s `signInProvider`
142
+ * argument; `null` for identities driven directly through the
143
+ * test driver (`sandbox.setUser`), which has no prod analog. */
144
+ signInProviderByUid = new Map();
145
+ /**
146
+ * Sign-in provider enablement — mirrors a real Firebase project's
147
+ * Authentication → Sign-in method toggles. GATED at every provider
148
+ * entry point OF THE ENFORCING BACKEND (owner decision — full
149
+ * fidelity): `resolveFlow` (`signInWithPopup`/`signInWithRedirect`),
150
+ * `signInWithCredential`, `createUserWithEmailAndPassword`/
151
+ * `signInWithEmailAndPassword` (the `'password'` provider), and
152
+ * `signInAnonymously` (the `'anonymous'` provider). A disabled
153
+ * provider throws the same `auth/operation-not-allowed` prod throws
154
+ * — a code deliberately distinct from `auth/argument-error` (which
155
+ * keeps meaning "no resolver/mock wired" for an ENABLED-but-unmocked
156
+ * OAuth provider).
157
+ *
158
+ * DELEGATION ESCAPE HATCH ({@link providerEnforcementDelegated}): a
159
+ * backend that is merely a UI vehicle for a REMOTE authority — the
160
+ * served worker path's page-local sandbox, whose popup picker
161
+ * resolves identities that a SharedWorker then gates + signs in —
162
+ * can delegate enforcement to that authority. With delegation on,
163
+ * {@link assertProviderEnabled} is a no-op HERE and the authority's
164
+ * own (undelegated) backend gate is the one that decides.
165
+ *
166
+ * DEFAULTS DIVERGE FROM A FRESH REAL PROJECT (owner decision,
167
+ * documented): prod ships every provider OFF until an admin flips it
168
+ * on in the console. The sandbox ships `'password'` and `'anonymous'`
169
+ * ON — everything else (`google.com`, `github.com`, `apple.com`,
170
+ * `microsoft.com`, custom OAuth ids, …) OFF — so the enforcement is
171
+ * identical to prod but the DEFAULTS are friendlier: every existing
172
+ * sandbox flow that never called `sandbox.setAuthProviderConfig`
173
+ * keeps signing in via email/password and anonymous auth unchanged
174
+ * after this landed.
175
+ */
176
+ providerConfig;
177
+ /** Subscribers to provider-config changes — the config analog of
178
+ * {@link userDbSubs}. Same coarse contract: no payload, re-read via
179
+ * {@link listProviderConfig} on each callback. */
180
+ providerConfigSubs;
181
+ /** When true, THIS backend's provider gate is delegated to a remote
182
+ * authority (see the {@link providerConfig} docstring's delegation
183
+ * section) — {@link assertProviderEnabled} becomes a no-op. Not
184
+ * persisted: a runtime wiring decision, not project config. */
185
+ providerEnforcementDelegated = false;
186
+ constructor(sandbox, session = sandbox, projectStore = createAuthProjectStore(), ownCleanup) {
187
+ this.sandbox = sandbox;
188
+ this.session = session;
189
+ this.usersByEmail = projectStore.usersByEmail;
190
+ this.usersByUid = projectStore.usersByUid;
191
+ this.userDbSubs = projectStore.userDbSubscribers;
192
+ this.providerConfig = projectStore.providerConfig;
193
+ this.providerConfigSubs = projectStore.providerConfigSubscribers;
194
+ this.sharedCounters = projectStore.counters;
195
+ // Initialize cachedUser from the injected session host.
196
+ this.cachedUser = this.buildUserFromState(session.currentUser);
197
+ this.lastNotifiedUid = this.cachedUser?.uid ?? null;
198
+ // Subscribe to session-level changes, including direct sandbox mutations
199
+ // for the default/bare-sandbox session host.
200
+ //
201
+ // Critically, this must NOT clobber a richer `User` that
202
+ // `setCurrentUser` already cached for the SAME identity. Sign-in
203
+ // strategies (popup / redirect / credential / `setUser`) hand us a
204
+ // full `User` (email, displayName, anonymous flag) and stash it on
205
+ // `cachedUser` *before* writing `sandbox.currentUser`; that write
206
+ // fires this subscriber synchronously. Rebuilding from the bare
207
+ // `AuthState` here would drop every field `AuthState` can't carry
208
+ // (it only holds uid + claims) and mint a fresh object, breaking
209
+ // `cred.user === auth.currentUser`. So we only rebuild when the
210
+ // change came from *outside* this backend — i.e. the cached user's
211
+ // uid no longer matches the new state (a direct sandbox mutation,
212
+ // `reset()`, or another handle's sign-in). Matches upstream, where
213
+ // `_updateCurrentUser(userCredential.user)` makes the credential's
214
+ // user the live `currentUser` — same fields, same reference
215
+ // (`core/strategies/anonymous.ts:60-68`, `auth_impl.ts:714-719`).
216
+ const unsubscribeSession = session.onCurrentUserChanged((state) => {
217
+ // `setCurrentUser` owns the fan-out for transitions it drives (it
218
+ // calls `notifyAuthListeners` itself with the right id-token /
219
+ // auth-state split). Skip here so we don't double-notify.
220
+ if (this.applyingTransition)
221
+ return;
222
+ const stateUid = state === null ? null : state.uid;
223
+ const cachedUid = this.cachedUser?.uid ?? null;
224
+ if (stateUid !== cachedUid) {
225
+ this.cachedUser = this.buildUserFromState(state);
226
+ }
227
+ // External mutation (direct sandbox write / `reset()` / another
228
+ // handle): notify with the same id-token-always / auth-state-on-
229
+ // uid-change rule.
230
+ this.notifyAuthListeners();
231
+ });
232
+ ownCleanup?.(() => {
233
+ unsubscribeSession();
234
+ this.authStateSubs.length = 0;
235
+ this.idTokenSubs.length = 0;
236
+ this.beforeStateSubs.length = 0;
237
+ });
238
+ }
239
+ /** Snapshot of the current user — backs `auth.currentUser`. */
240
+ getCurrentUser() {
241
+ return this.cachedUser;
242
+ }
243
+ // ─── Listener registries ────────────────────────────────────────────
244
+ /**
245
+ * Subscribe to user change. Fires *immediately* on subscribe with
246
+ * the current value (mirrors `firebase/auth`'s
247
+ * `onAuthStateChanged` semantics).
248
+ *
249
+ * `kind: 'auth-state'` and `kind: 'id-token'` share the identity-
250
+ * transition fan-out path; additionally, `getIdToken(true)` fans
251
+ * out to the `'id-token'` registry only (without re-firing
252
+ * `'auth-state'`). Matches prod: `onIdTokenChanged` sees both
253
+ * identity changes AND forced token refreshes.
254
+ */
255
+ subscribe(kind, observer) {
256
+ const list = kind === 'auth-state' ? this.authStateSubs : this.idTokenSubs;
257
+ // One record per subscribe() — duplicate fns register independently
258
+ // (AUTH-B4). Each carries its own initial-fire bookkeeping, so a
259
+ // resubscribe or a second registration of the same fn is NOT
260
+ // suppressed by a sibling's delivery (AUTH-B3).
261
+ const reg = { observer, hasFired: false, lastValue: null };
262
+ list.push(reg);
263
+ // Fire immediately with the current value — upstream semantics
264
+ // (`auth_impl.ts:728-742`: each registration schedules its own
265
+ // `promise.then(() => cb(currentUser))`). Use a microtask so a
266
+ // synchronous unsubscribe from inside the observer doesn't race with
267
+ // fanOut's iteration, AND so a setCurrentUser that fires
268
+ // synchronously between subscribe and this microtask can deliver
269
+ // first; we then skip the replay only when THIS registration already
270
+ // saw the current value (avoids the same-value double-fire in the
271
+ // mount-time `onAuthStateChanged(auth, fn); signInAnonymously(auth)`
272
+ // pattern — a sandbox-only race prod can't exhibit, COMPAT row 31).
273
+ queueMicrotask(() => {
274
+ if (!list.includes(reg))
275
+ return;
276
+ if (reg.hasFired && reg.lastValue === this.cachedUser)
277
+ return;
278
+ this.deliverOne(reg, this.cachedUser);
279
+ });
280
+ return () => {
281
+ const i = list.indexOf(reg);
282
+ if (i !== -1)
283
+ list.splice(i, 1);
284
+ };
285
+ }
286
+ /**
287
+ * Notify the requested registries of the current user. Snapshots
288
+ * the registration list before iteration so unsubscribes during
289
+ * emission don't skip remaining subscribers (upstream semantics).
290
+ *
291
+ * `kind: 'both'` (default) fires both auth-state and id-token
292
+ * registries — used for identity transitions.
293
+ * `kind: 'id-token'` fires ONLY the id-token registry — used for
294
+ * forced token refreshes, where the user identity hasn't changed
295
+ * but the token has. Matches prod: `onIdTokenChanged` sees refresh
296
+ * events; `onAuthStateChanged` does not.
297
+ */
298
+ fanOut(kind = 'both') {
299
+ const user = this.cachedUser;
300
+ if (kind === 'both' || kind === 'auth-state') {
301
+ for (const reg of [...this.authStateSubs])
302
+ this.deliverOne(reg, user);
303
+ }
304
+ if (kind === 'both' || kind === 'id-token') {
305
+ for (const reg of [...this.idTokenSubs])
306
+ this.deliverOne(reg, user);
307
+ }
308
+ }
309
+ /**
310
+ * Mirror of upstream `notifyAuthListeners` (`auth_impl.ts:714-723`):
311
+ * - `onIdTokenChanged` fires on EVERY notify (every identity update,
312
+ * including a same-uid re-sign-in that mints a fresh token —
313
+ * AUTH-B8);
314
+ * - `onAuthStateChanged` fires ONLY when the uid changed vs the last
315
+ * notification (`lastNotifiedUid`) — a same-uid profile-shape
316
+ * change does NOT re-fire auth-state (AUTH-B7).
317
+ * Call this after `cachedUser` is updated.
318
+ */
319
+ notifyAuthListeners() {
320
+ this.fanOut('id-token');
321
+ const currentUid = this.cachedUser?.uid ?? null;
322
+ if (this.lastNotifiedUid !== currentUid) {
323
+ this.lastNotifiedUid = currentUid;
324
+ this.fanOut('auth-state');
325
+ }
326
+ }
327
+ deliverOne(reg, user) {
328
+ reg.hasFired = true;
329
+ reg.lastValue = user;
330
+ const observer = reg.observer;
331
+ try {
332
+ if (typeof observer === 'function') {
333
+ observer(user);
334
+ }
335
+ else if (observer.next) {
336
+ observer.next(user);
337
+ }
338
+ }
339
+ catch {
340
+ // Observational — swallow so a faulty subscriber can't
341
+ // destabilize the auth state machine.
342
+ }
343
+ }
344
+ // ─── User DB ────────────────────────────────────────────────────────
345
+ /** Build a fresh {@link StoredUser} with admin-field defaults. */
346
+ makeStored(init) {
347
+ return {
348
+ email: null,
349
+ password: null,
350
+ displayName: null,
351
+ phoneNumber: null,
352
+ photoUrl: null,
353
+ customClaims: {},
354
+ isAnonymous: false,
355
+ providerUserInfo: [],
356
+ disabled: false,
357
+ emailVerified: false,
358
+ createdAt: new Date().toISOString(),
359
+ lastLoginAt: null,
360
+ ...init,
361
+ };
362
+ }
363
+ /** Fan a coarse "user DB changed" notification out to
364
+ * `subscribeUsers` listeners. Snapshotted iteration; throwing
365
+ * listeners are isolated (same policy as the auth observers). */
366
+ notifyUsersChanged() {
367
+ for (const cb of [...this.userDbSubs]) {
368
+ try {
369
+ cb();
370
+ }
371
+ catch {
372
+ // Observational — swallow.
373
+ }
374
+ }
375
+ }
376
+ /**
377
+ * Emit an auth {@link ServiceMutationEvent} onto the sandbox's unified
378
+ * `onEvent`/`history()` stream (Pyric Studio keystone). Best-effort and
379
+ * fully isolated — a throw from the emit path (or a sandbox that somehow
380
+ * isn't a real `SandboxImpl`) must NOT break the auth operation that
381
+ * triggered it, so we swallow. `auth` defaults to the current sandbox
382
+ * identity; admin ops (createUser/updateUser/deleteUser) pass `null`
383
+ * since they have no acting session. `actor` defaults to `{ kind: 'app' }`
384
+ * via `stampProvenance`.
385
+ */
386
+ emitAuthEvent(op, fields = {}) {
387
+ try {
388
+ emitSandboxEvent(this.sandbox, makeServiceMutationEvent({
389
+ service: 'auth',
390
+ op,
391
+ path: fields.path,
392
+ auth: fields.auth ?? this.session.currentUser,
393
+ before: fields.before,
394
+ after: fields.after,
395
+ detail: fields.detail,
396
+ }), { service: 'auth' });
397
+ }
398
+ catch {
399
+ // Observational — never let event emission destabilize auth.
400
+ }
401
+ }
402
+ /** Subscribe to user-DB mutations (seed/create/update/delete/clear,
403
+ * provider links, lastLoginAt bumps). Coarse: no payload, no
404
+ * initial fire — re-list via `listUsers` on each callback. */
405
+ subscribeUsers(cb) {
406
+ this.userDbSubs.add(cb);
407
+ return () => { this.userDbSubs.delete(cb); };
408
+ }
409
+ // ─── Provider config (sign-in method enablement) ─────────────────────
410
+ /** Whether `providerId` is currently enabled. Unknown providers
411
+ * (never toggled) default to `true` — every sign-in method works out
412
+ * of the box until the sandbox grows a provider-enablement API and
413
+ * UI. An explicit `false` entry still disables. */
414
+ isProviderEnabled(providerId) {
415
+ return this.providerConfig.get(providerId) ?? true;
416
+ }
417
+ /** Every provider this backend has an explicit enablement for —
418
+ * seeded defaults (`password`, `anonymous`) plus anything a host
419
+ * toggled via {@link setProviderConfig}. */
420
+ listProviderConfig() {
421
+ return [...this.providerConfig.entries()].map(([providerId, enabled]) => ({ providerId, enabled }));
422
+ }
423
+ /** Toggle a provider on/off. No-op (no notify) when the value is
424
+ * already what was requested — mirrors {@link setPersistenceMode}'s
425
+ * dedup so a redundant toggle doesn't churn subscribers / flushes. */
426
+ setProviderConfig(providerId, enabled) {
427
+ const before = this.providerConfig.get(providerId) ?? true;
428
+ if (before === enabled)
429
+ return;
430
+ this.providerConfig.set(providerId, enabled);
431
+ this.notifyProviderConfigChanged();
432
+ // No acting session for a config toggle (an admin-console-equivalent
433
+ // action) — same rationale as the user-admin ops (createUser/
434
+ // updateUser/…), which also pass `auth: null`. Rides the sandbox's
435
+ // unified event stream so a host subscribed to `onEvent`/`history()`
436
+ // (Pyric Studio's Action Center, and the worker's event feed that
437
+ // `subscribeUsers` already rides) sees provider-config changes too.
438
+ this.emitAuthEvent('provider_config_update', {
439
+ path: providerId,
440
+ auth: null,
441
+ before: { providerId, enabled: before },
442
+ after: { providerId, enabled },
443
+ });
444
+ }
445
+ notifyProviderConfigChanged() {
446
+ for (const cb of [...this.providerConfigSubs]) {
447
+ try {
448
+ cb();
449
+ }
450
+ catch {
451
+ // Observational — swallow.
452
+ }
453
+ }
454
+ }
455
+ /** Subscribe to provider-config mutations. Coarse: no payload, no
456
+ * initial fire — re-read via {@link listProviderConfig} on each
457
+ * callback (same contract as {@link subscribeUsers}). */
458
+ subscribeProviderConfig(cb) {
459
+ this.providerConfigSubs.add(cb);
460
+ return () => { this.providerConfigSubs.delete(cb); };
461
+ }
462
+ /**
463
+ * Mark this backend's provider gate as delegated to (or reclaimed
464
+ * from) a remote authority. See the {@link providerConfig} docstring:
465
+ * the served worker path sets this on the PAGE-LOCAL sandbox so the
466
+ * popup picker opens regardless of local toggles — the SharedWorker's
467
+ * `auth.acceptIdentity` gate (against the worker's own, undelegated
468
+ * backend) is the enforcement point.
469
+ */
470
+ setProviderEnforcementDelegated(delegated) {
471
+ this.providerEnforcementDelegated = delegated;
472
+ }
473
+ /**
474
+ * Gate a provider entry point. Throws real Firebase's
475
+ * `auth/operation-not-allowed` (exactly the code/shape prod throws
476
+ * for a disabled sign-in method) when `providerId` is off. Called by
477
+ * every provider-flow entry point in `index.ts` BEFORE any other
478
+ * work, so a disabled provider never touches the user DB / mock
479
+ * registry / resolver. A no-op when enforcement is delegated to a
480
+ * remote authority ({@link setProviderEnforcementDelegated}).
481
+ */
482
+ assertProviderEnabled(providerId) {
483
+ if (this.providerEnforcementDelegated)
484
+ return;
485
+ if (!this.isProviderEnabled(providerId)) {
486
+ throw makeAuthError('auth/operation-not-allowed', `${providerId} sign-in is disabled for this sandbox project. Enable it with ` +
487
+ `sandbox.setAuthProviderConfig(auth, '${providerId}', true).`);
488
+ }
489
+ }
490
+ /** Snapshot the full provider-config map for the persistable-service
491
+ * `snapshot()` hook — plain JSON, ready to embed under the `auth`
492
+ * service's `providers` key. */
493
+ exportProviderConfig() {
494
+ return Object.fromEntries(this.providerConfig);
495
+ }
496
+ /**
497
+ * Restore provider config from a persisted blob — a REPLACE, not a
498
+ * merge (same policy as `seedUsers`'s persistence path: the map
499
+ * becomes EXACTLY what `data` holds). When `data` is missing/invalid
500
+ * — including every blob written BEFORE this feature landed, which
501
+ * has no `providers` key at all — falls back to the documented
502
+ * defaults (`password`/`anonymous` enabled) rather than leaving the
503
+ * map empty, so an old `--persist` file doesn't silently lock
504
+ * existing sandbox flows out of email/password + anonymous sign-in.
505
+ */
506
+ restoreProviderConfig(data) {
507
+ this.providerConfig.clear();
508
+ if (data && typeof data === 'object') {
509
+ for (const [providerId, enabled] of Object.entries(data)) {
510
+ if (typeof enabled === 'boolean')
511
+ this.providerConfig.set(providerId, enabled);
512
+ }
513
+ }
514
+ else {
515
+ this.providerConfig.set('password', true);
516
+ this.providerConfig.set('anonymous', true);
517
+ }
518
+ this.notifyProviderConfigChanged();
519
+ }
520
+ // ─── Persistence mode ───────────────────────────────────────────────
521
+ /**
522
+ * Read the current persistence mode. Used by the session-persistence
523
+ * controller to decide which web-storage slot (local / session) to
524
+ * write the signed-in uid into.
525
+ *
526
+ * The default value is `'LOCAL'` — matches Firebase's default of
527
+ * `browserLocalPersistence` (you stay signed in across page reloads
528
+ * and browser restarts unless you explicitly call `setPersistence`).
529
+ */
530
+ getPersistenceMode() {
531
+ return this.persistenceMode;
532
+ }
533
+ /**
534
+ * Record the new persistence mode. Called by the auth `setPersistence`
535
+ * function when the sandbox target receives a mode change.
536
+ *
537
+ * Changing the mode notifies the session-change subscribers so the
538
+ * persistence controller can IMMEDIATELY migrate the stored uid to
539
+ * the new web-storage slot — matching the real SDK's behavior where
540
+ * `setPersistence` carries the active session across modes before
541
+ * returning.
542
+ *
543
+ * Why notify on mode change (not just on sign-in/out): the session
544
+ * controller subscribes to "something about this session changed"
545
+ * events and re-reads both `currentUid()` and `mode()` on each fire.
546
+ * Notifying here lets the controller react to a mode change with the
547
+ * same code path as a sign-in/out, rather than a separate migration
548
+ * hook.
549
+ */
550
+ setPersistenceMode(mode) {
551
+ if (this.persistenceMode === mode)
552
+ return; // no-op — nothing to migrate
553
+ this.persistenceMode = mode;
554
+ // Notify session-change subscribers so the controller migrates the
555
+ // stored uid to the new store immediately. The controller reads
556
+ // mode() on the fire, so it will see the already-updated value.
557
+ this.notifySessionChanged();
558
+ }
559
+ /**
560
+ * Subscribers that need to react to ANY session state change —
561
+ * sign-in, sign-out, or persistence-mode change. The controller
562
+ * installs one subscriber here to drive session saves.
563
+ *
564
+ * Separate from `currentUserSubs` (on the sandbox) because we need
565
+ * to fire on mode changes (which don't change the currentUser) and
566
+ * because the backend owns the mode — it's cleaner to keep both
567
+ * signals on the same object.
568
+ */
569
+ sessionChangeSubs = new Set();
570
+ /** Notify all session-change subscribers. Used by `setCurrentUser`
571
+ * (sign-in / sign-out) and by `setPersistenceMode` (mode change). */
572
+ notifySessionChanged() {
573
+ for (const cb of [...this.sessionChangeSubs]) {
574
+ try {
575
+ cb();
576
+ }
577
+ catch {
578
+ // Observational — swallow.
579
+ }
580
+ }
581
+ }
582
+ /**
583
+ * Subscribe to session-level changes: sign-in, sign-out, and
584
+ * persistence-mode changes. The persistence controller installs one
585
+ * subscription here and re-saves the session on every fire.
586
+ *
587
+ * This is the mechanism the `PersistableService.session.subscribe`
588
+ * hook exposes — the controller doesn't need to know it's subscribing
589
+ * to two separate event sources (sign-in/out AND mode); they both
590
+ * flow through this one subscription.
591
+ */
592
+ subscribeSession(cb) {
593
+ this.sessionChangeSubs.add(cb);
594
+ return () => { this.sessionChangeSubs.delete(cb); };
595
+ }
596
+ seedUsers(users) {
597
+ for (const u of users) {
598
+ // Re-seeding an existing uid OVERWRITES it (documented idempotency,
599
+ // `index.ts` seedUsers docstring). If the new email differs, drop
600
+ // the stale email→record mapping so the old email no longer signs
601
+ // in (AUTH-B9) — otherwise both emails would resolve, the old one
602
+ // to a now-orphaned record.
603
+ const prior = this.usersByUid.get(u.uid);
604
+ if (prior?.email && prior.email.toLowerCase() !== u.email.toLowerCase()) {
605
+ this.usersByEmail.delete(prior.email.toLowerCase());
606
+ }
607
+ const record = this.makeStored({
608
+ uid: u.uid,
609
+ email: u.email,
610
+ password: u.password,
611
+ displayName: u.displayName ?? null,
612
+ customClaims: u.customClaims ?? {},
613
+ providerUserInfo: [{ providerId: u.providerId ?? 'password' }],
614
+ });
615
+ this.usersByEmail.set(u.email.toLowerCase(), record);
616
+ this.usersByUid.set(u.uid, record);
617
+ }
618
+ if (users.length > 0)
619
+ this.notifyUsersChanged();
620
+ }
621
+ /**
622
+ * Export the user DB as `SeedUser`s — the exact shape `seedUsers`
623
+ * accepts, so export → seed round-trips (the persistence substrate,
624
+ * the design rationale section 3c). Identities with an email but no
625
+ * password (provider-flow users created via `createSignInCredential`)
626
+ * export with {@link NO_PASSWORD_SENTINEL} so they survive the
627
+ * round-trip (same trick hosts already use when seeding popup
628
+ * identities). Anonymous users (no email) are NOT exported — they are
629
+ * ephemeral by design; documented divergence from prod's persisted
630
+ * anonymous sessions.
631
+ */
632
+ exportUsers() {
633
+ const out = [];
634
+ for (const u of this.usersByUid.values()) {
635
+ if (u.email === null)
636
+ continue; // anonymous — not round-trippable
637
+ const seed = {
638
+ uid: u.uid,
639
+ email: u.email,
640
+ password: u.password ?? NO_PASSWORD_SENTINEL,
641
+ providerId: u.providerUserInfo[0]?.providerId ?? 'password',
642
+ };
643
+ if (u.displayName !== null)
644
+ seed.displayName = u.displayName;
645
+ if (Object.keys(u.customClaims).length > 0)
646
+ seed.customClaims = u.customClaims;
647
+ out.push(seed);
648
+ }
649
+ return out;
650
+ }
651
+ /**
652
+ * Re-establish a signed-in session for an EXISTING identity — the
653
+ * substrate behind web-storage session persistence (`setPersistence`
654
+ * parity at the serve layer). Fires the auth-state listeners exactly
655
+ * like a real restored session. Throws `auth/user-not-found` for
656
+ * unknown uids and `auth/user-disabled` for disabled accounts (a
657
+ * restore is a sign-in).
658
+ */
659
+ restoreSession(uid) {
660
+ const stored = this.usersByUid.get(uid);
661
+ if (!stored) {
662
+ throw makeAuthError('auth/user-not-found', `restoreSession: no identity with uid ${uid}.`);
663
+ }
664
+ if (stored.disabled) {
665
+ throw makeAuthError('auth/user-disabled', `restoreSession: user ${uid} is disabled.`);
666
+ }
667
+ const providerId = stored.isAnonymous
668
+ ? 'anonymous'
669
+ : (stored.providerUserInfo[0]?.providerId ?? 'password');
670
+ const user = this.buildUserFromStored(stored);
671
+ this.setCurrentUser(user, providerId);
672
+ return user;
673
+ }
674
+ findByEmail(email) {
675
+ return this.usersByEmail.get(email.toLowerCase());
676
+ }
677
+ findByUid(uid) {
678
+ return this.usersByUid.get(uid);
679
+ }
680
+ // ─── Email family: action codes + the mail outbox ───────────────────
681
+ //
682
+ // Pure delegation to {@link AuthFlowRegistry} — the staging state lives
683
+ // there (it is independent of the coupled auth state machine); the
684
+ // IDENTITY MUTATION each redeemed code drives lives here, on the
685
+ // backend that owns the user DB. That split is the seam's whole design.
686
+ mintActionCode(spec) {
687
+ return this.flow.mintActionCode(spec);
688
+ }
689
+ stageActionCode(code, spec) {
690
+ this.flow.stageActionCode(code, spec);
691
+ }
692
+ peekActionCode(code) {
693
+ return this.flow.peekActionCode(code);
694
+ }
695
+ consumeActionCode(code) {
696
+ return this.flow.consumeActionCode(code);
697
+ }
698
+ deliverMail(mail) {
699
+ this.flow.deliverMail(mail);
700
+ }
701
+ takeMail(email) {
702
+ return this.flow.takeMail(email);
703
+ }
704
+ listMail() {
705
+ return this.flow.listMail();
706
+ }
707
+ setMailResolver(resolver) {
708
+ this.flow.setMailResolver(resolver);
709
+ }
710
+ // ─── Identity mutations the redeemed codes drive ────────────────────
711
+ /**
712
+ * Mark an account's email verified — what a redeemed `VERIFY_EMAIL`
713
+ * code does. This is the state change the whole verification flow
714
+ * exists to produce, and the one that (in prod) only happens when a
715
+ * human clicks the link. Idempotent.
716
+ */
717
+ setEmailVerified(email, verified) {
718
+ const stored = this.requireByEmail(email);
719
+ if (stored.emailVerified !== verified) {
720
+ stored.emailVerified = verified;
721
+ this.notifyUsersChanged();
722
+ this.emitAuthEvent('user_update', {
723
+ path: stored.uid,
724
+ after: this.toRecord(stored),
725
+ detail: { emailVerified: verified },
726
+ });
727
+ }
728
+ return stored;
729
+ }
730
+ /**
731
+ * Set an account's password by email — what a redeemed
732
+ * `PASSWORD_RESET` code does (`confirmPasswordReset`). Runs the same
733
+ * strength check `createUserWithEmailAndPassword` does, so a reset
734
+ * cannot install a password the create path would have rejected.
735
+ */
736
+ setPasswordByEmail(email, newPassword) {
737
+ validatePasswordStrength(newPassword);
738
+ const stored = this.requireByEmail(email);
739
+ stored.password = newPassword;
740
+ this.notifyUsersChanged();
741
+ this.emitAuthEvent('user_update', {
742
+ path: stored.uid,
743
+ after: this.toRecord(stored),
744
+ detail: { passwordReset: true },
745
+ });
746
+ return stored;
747
+ }
748
+ /**
749
+ * Move an account to a new address — what a redeemed
750
+ * `VERIFY_AND_CHANGE_EMAIL` code does (`verifyBeforeUpdateEmail`). The
751
+ * new address arrives already verified: the user just proved they
752
+ * control it by redeeming a code sent TO it. That is the entire
753
+ * difference between this flow and a bare `updateEmail`.
754
+ */
755
+ changeEmail(fromEmail, toEmail) {
756
+ validateEmailFormat(toEmail);
757
+ const stored = this.requireByEmail(fromEmail);
758
+ const toKey = toEmail.toLowerCase();
759
+ const existing = this.usersByEmail.get(toKey);
760
+ if (existing && existing.uid !== stored.uid) {
761
+ throw makeAuthError('auth/email-already-in-use', `An account already exists for ${toEmail}.`);
762
+ }
763
+ if (stored.email)
764
+ this.usersByEmail.delete(stored.email.toLowerCase());
765
+ stored.email = toEmail;
766
+ stored.emailVerified = true;
767
+ this.usersByEmail.set(toKey, stored);
768
+ this.notifyUsersChanged();
769
+ this.emitAuthEvent('user_update', {
770
+ path: stored.uid,
771
+ after: this.toRecord(stored),
772
+ detail: { emailChanged: toEmail },
773
+ });
774
+ return stored;
775
+ }
776
+ /**
777
+ * Get-or-create the account an email-link sign-in resolves to.
778
+ * A first-time email-link sign-in CREATES the account (that is the
779
+ * passwordless flow's whole point) — and it arrives verified, because
780
+ * redeeming a code mailed to that address is proof of control.
781
+ *
782
+ * Returns `isNewUser` so the credential can carry an honest
783
+ * `getAdditionalUserInfo().isNewUser`.
784
+ */
785
+ upsertEmailLinkUser(email) {
786
+ validateEmailFormat(email);
787
+ const key = email.toLowerCase();
788
+ const existing = this.usersByEmail.get(key);
789
+ if (existing) {
790
+ if (!existing.providerUserInfo.some((p) => p.providerId === 'password')) {
791
+ existing.providerUserInfo.push({ providerId: 'password' });
792
+ }
793
+ // Redeeming a link mailed to this address proves control of it.
794
+ existing.emailVerified = true;
795
+ this.notifyUsersChanged();
796
+ return { stored: existing, isNewUser: false };
797
+ }
798
+ const uid = `email-${key}-${this.usersByEmail.size + 1}`;
799
+ const record = this.makeStored({
800
+ uid,
801
+ email,
802
+ // No password: an account born from an email link has never had
803
+ // one set. `signInWithEmailAndPassword` for it fails, exactly as it
804
+ // would in prod, until the user sets a password.
805
+ providerUserInfo: [{ providerId: 'password' }],
806
+ });
807
+ record.emailVerified = true;
808
+ this.usersByEmail.set(key, record);
809
+ this.usersByUid.set(uid, record);
810
+ this.notifyUsersChanged();
811
+ this.emitAuthEvent('user_create', { path: uid, after: this.toRecord(record), detail: { emailLink: true } });
812
+ return { stored: record, isNewUser: true };
813
+ }
814
+ // ─── Account linking / unlinking ────────────────────────────────────
815
+ /**
816
+ * Link a provider onto an existing identity. The mutation behind
817
+ * `linkWithCredential` / `linkWithPopup` / `linkWithRedirect`.
818
+ *
819
+ * Enforces the two conflict codes prod enforces:
820
+ * - `auth/provider-already-linked` when the account already carries
821
+ * this provider;
822
+ * - `auth/email-already-in-use` when the email credential being
823
+ * linked belongs to a DIFFERENT account (an email can only ever
824
+ * back one identity).
825
+ *
826
+ * Linking a credential onto an ANONYMOUS account upgrades it in place:
827
+ * same uid, `isAnonymous` flips false. That upgrade is the single most
828
+ * common reason this API exists (the "let them try it, then let them
829
+ * keep it" onboarding flow), and preserving the uid is what makes the
830
+ * data they created while anonymous still theirs afterward.
831
+ */
832
+ linkProvider(uid, providerId, identity) {
833
+ const stored = this.usersByUid.get(uid);
834
+ if (!stored) {
835
+ throw makeAuthError('auth/user-not-found', `linkWithCredential: no identity with uid ${uid}.`);
836
+ }
837
+ if (stored.providerUserInfo.some((p) => p.providerId === providerId)) {
838
+ throw makeAuthError('auth/provider-already-linked', `User can only be linked to one identity for the given provider (${providerId}).`);
839
+ }
840
+ const email = identity?.email;
841
+ if (email) {
842
+ validateEmailFormat(email);
843
+ const key = email.toLowerCase();
844
+ const owner = this.usersByEmail.get(key);
845
+ if (owner && owner.uid !== uid) {
846
+ throw makeAuthError('auth/email-already-in-use', `An account already exists for ${email}.`);
847
+ }
848
+ if (identity.password !== undefined && identity.password !== null) {
849
+ validatePasswordStrength(identity.password);
850
+ stored.password = identity.password;
851
+ }
852
+ if (stored.email && stored.email.toLowerCase() !== key) {
853
+ this.usersByEmail.delete(stored.email.toLowerCase());
854
+ }
855
+ stored.email = email;
856
+ this.usersByEmail.set(key, stored);
857
+ if (identity.emailVerified !== undefined)
858
+ stored.emailVerified = identity.emailVerified;
859
+ }
860
+ stored.providerUserInfo.push({ providerId });
861
+ // The upgrade: an identity that now carries a real provider is no
862
+ // longer anonymous, and it keeps its uid.
863
+ if (stored.isAnonymous)
864
+ stored.isAnonymous = false;
865
+ this.notifyUsersChanged();
866
+ this.emitAuthEvent('user_update', {
867
+ path: uid,
868
+ after: this.toRecord(stored),
869
+ detail: { linked: providerId },
870
+ });
871
+ return stored;
872
+ }
873
+ /**
874
+ * Remove a provider from an identity — the mutation behind `unlink`.
875
+ * Throws `auth/no-such-provider` when it was never linked (oracle:
876
+ * `observations/auth/auth-unlink-provider.json` confirms prod emits
877
+ * exactly that code for an unlinked provider).
878
+ *
879
+ * Unlinking the LAST provider does NOT re-anonymize the account: the
880
+ * identity stays, credential-less. Matches prod — `isAnonymous` is
881
+ * about how the account was born, not what it currently carries.
882
+ */
883
+ unlinkProvider(uid, providerId) {
884
+ const stored = this.usersByUid.get(uid);
885
+ if (!stored) {
886
+ throw makeAuthError('auth/user-not-found', `unlink: no identity with uid ${uid}.`);
887
+ }
888
+ const i = stored.providerUserInfo.findIndex((p) => p.providerId === providerId);
889
+ if (i < 0) {
890
+ throw makeAuthError('auth/no-such-provider', `User was not linked to an account with the given provider (${providerId}).`);
891
+ }
892
+ stored.providerUserInfo.splice(i, 1);
893
+ if (providerId === 'password') {
894
+ // The password provider carried the secret; unlinking it takes the
895
+ // secret with it, so `signInWithEmailAndPassword` stops working —
896
+ // which is the observable point of unlinking it.
897
+ stored.password = null;
898
+ }
899
+ this.notifyUsersChanged();
900
+ this.emitAuthEvent('user_update', {
901
+ path: uid,
902
+ after: this.toRecord(stored),
903
+ detail: { unlinked: providerId },
904
+ });
905
+ return stored;
906
+ }
907
+ /** Shared lookup-or-throw behind the by-email mutations above. */
908
+ requireByEmail(email) {
909
+ const stored = this.usersByEmail.get(email.toLowerCase());
910
+ if (!stored) {
911
+ throw makeAuthError('auth/user-not-found', `No user found for ${email}.`);
912
+ }
913
+ return stored;
914
+ }
915
+ createEmailPasswordUser(email, password) {
916
+ // Validate format BEFORE checking duplicates so an attacker can't
917
+ // enumerate seeded emails by varying the malformed-vs-valid shape.
918
+ // Matches prod's order — the format error fires before any lookup
919
+ // against the user DB.
920
+ validateEmailFormat(email);
921
+ validatePasswordStrength(password);
922
+ const key = email.toLowerCase();
923
+ if (this.usersByEmail.has(key)) {
924
+ throw makeAuthError('auth/email-already-in-use', `An account already exists for ${email}.`);
925
+ }
926
+ const uid = `email-${key}-${this.usersByEmail.size + 1}`;
927
+ const record = this.makeStored({
928
+ uid,
929
+ email,
930
+ password,
931
+ providerUserInfo: [{ providerId: 'password' }],
932
+ });
933
+ this.usersByEmail.set(key, record);
934
+ this.usersByUid.set(uid, record);
935
+ this.notifyUsersChanged();
936
+ // App-driven create (createUserWithEmailAndPassword) — the acting
937
+ // identity is whoever is currently signed in (usually null/anonymous).
938
+ this.emitAuthEvent('user_create', { path: uid, after: this.toRecord(record) });
939
+ return record;
940
+ }
941
+ // ─── beforeAuthStateChanged (blocking gate) ─────────────────────────
942
+ /**
943
+ * Register a `beforeAuthStateChanged` callback. Mirrors upstream's
944
+ * `AuthMiddlewareQueue.pushCallback` (`auth_impl.ts`): callbacks run
945
+ * in registration order, before any REAL sign-in/sign-out transition
946
+ * commits — see {@link runBeforeStateChange}. Unregistering swaps the
947
+ * slot to inactive rather than removing it, so later indices stay
948
+ * stable if unsubscribe happens from inside a running pass.
949
+ */
950
+ beforeAuthStateChanged(callback, onAbort) {
951
+ const reg = { callback, onAbort, active: true };
952
+ this.beforeStateSubs.push(reg);
953
+ return () => {
954
+ reg.active = false;
955
+ };
956
+ }
957
+ /**
958
+ * Run every registered `beforeAuthStateChanged` callback, in
959
+ * registration order, BEFORE a real identity transition commits.
960
+ * Mirrors upstream `AuthMiddlewareQueue.runMiddleware`
961
+ * (`auth_impl.ts`):
962
+ * - skip entirely if `nextUser` is reference-identical to the
963
+ * current cached user (no-op transition);
964
+ * - `await` each active callback in order;
965
+ * - on success, push its `onAbort` (if any) onto a rollback stack;
966
+ * - if any callback throws/rejects, run the ENTIRE rollback stack
967
+ * in REVERSE registration order (swallowing each `onAbort`'s own
968
+ * errors), then throw `auth/login-blocked` wrapping the original
969
+ * message. The caller (a `signInWith…` / `signOut` call site)
970
+ * must NOT commit the transition when this rejects — the
971
+ * sandbox's `currentUser` / listeners are left untouched.
972
+ *
973
+ * Fires for BOTH directions: `nextUser` non-null (sign-in) and
974
+ * `nextUser === null` (sign-out) — matches prod, where the same
975
+ * queue gates `_updateCurrentUser` and `signOut`.
976
+ */
977
+ async runBeforeStateChange(nextUser) {
978
+ if (nextUser === this.cachedUser)
979
+ return;
980
+ const onAbortStack = [];
981
+ try {
982
+ for (const reg of this.beforeStateSubs) {
983
+ if (!reg.active)
984
+ continue;
985
+ await reg.callback(nextUser);
986
+ if (reg.onAbort)
987
+ onAbortStack.push(reg.onAbort);
988
+ }
989
+ }
990
+ catch (e) {
991
+ onAbortStack.reverse();
992
+ for (const onAbort of onAbortStack) {
993
+ try {
994
+ onAbort();
995
+ }
996
+ catch {
997
+ // Swallow — matches upstream, which ignores onAbort errors so
998
+ // one bad rollback doesn't mask the original block reason.
999
+ }
1000
+ }
1001
+ const originalMessage = e instanceof Error ? e.message : String(e);
1002
+ throw makeAuthError('auth/login-blocked', originalMessage);
1003
+ }
1004
+ }
1005
+ /**
1006
+ * The gated entry point for REAL sign-in / sign-out transitions —
1007
+ * runs {@link runBeforeStateChange} first, and only calls
1008
+ * {@link setCurrentUser} (committing the transition + firing
1009
+ * `onAuthStateChanged` / `onIdTokenChanged`) if every before-callback
1010
+ * allows it. If a before-callback throws, this rejects and
1011
+ * `setCurrentUser` is never called — the sign-in call site's promise
1012
+ * rejects, `currentUser` is unchanged, and no listener fires.
1013
+ *
1014
+ * NOT used by the `sandbox.setUser` test driver — that bypass has no
1015
+ * prod analog (documented on {@link setCurrentUser}) and stays a raw,
1016
+ * ungated identity force, same as before this hook existed.
1017
+ *
1018
+ * FAST PATH (deliberate, documented divergence): when NO
1019
+ * `beforeAuthStateChanged` callback is registered, this commits
1020
+ * `setCurrentUser` SYNCHRONOUSLY — before returning the resolved
1021
+ * promise — rather than unconditionally going through an async
1022
+ * `await`. Every JS `await` (even of an already-resolved value)
1023
+ * defers to a microtask; unconditionally awaiting here would push the
1024
+ * commit at least one microtask later for every sign-in, even ones
1025
+ * nobody gates, and would break the existing sandbox-only
1026
+ * same-tick-dedup guarantee `onAuthStateChanged` callers rely on
1027
+ * (COMPAT row 31: subscribe(); signInAnonymously(); with no
1028
+ * await-gap between them must not double-fire). Once a caller
1029
+ * registers a `beforeAuthStateChanged` callback, the transition
1030
+ * genuinely becomes async (an unavoidable consequence of "blocking,
1031
+ * awaitable middleware"), matching prod's own async gate — this
1032
+ * method is NOT declared `async` for that reason; it returns a
1033
+ * pre-resolved promise on the fast path instead of ever suspending.
1034
+ */
1035
+ transitionCurrentUser(user, signInProvider) {
1036
+ const hasActiveGate = this.beforeStateSubs.some((reg) => reg.active);
1037
+ if (!hasActiveGate || user === this.cachedUser) {
1038
+ this.setCurrentUser(user, signInProvider);
1039
+ return Promise.resolve();
1040
+ }
1041
+ return this.runBeforeStateChange(user).then(() => {
1042
+ this.setCurrentUser(user, signInProvider);
1043
+ });
1044
+ }
1045
+ // ─── Identity mutation ──────────────────────────────────────────────
1046
+ /**
1047
+ * Set the active user. Owns the fan-out decision directly (rather than
1048
+ * leaning on the sandbox setter's structural-equality dedup), so it can
1049
+ * mirror upstream `notifyAuthListeners`: `onIdTokenChanged` fires on
1050
+ * every sign-in (incl. a same-uid re-sign-in that mints a fresh token —
1051
+ * AUTH-B8), while `onAuthStateChanged` fires only on a uid change
1052
+ * (AUTH-B7). The `applyingTransition` guard suppresses the synchronous
1053
+ * `onCurrentUserChanged` subscriber so we don't double-notify.
1054
+ *
1055
+ * `signInProvider` (when passed) records the provider of THIS
1056
+ * sign-in session — it feeds `IdTokenResult.signInProvider` and the
1057
+ * synthesized `firebase.sign_in_provider` claim. Omitted by the
1058
+ * test driver (`sandbox.setUser`), which leaves any previous value
1059
+ * in place.
1060
+ */
1061
+ setCurrentUser(user, signInProvider) {
1062
+ if (user === null) {
1063
+ // Sign-out. Drop the cached token so a later re-sign-in for the
1064
+ // same uid mints a fresh one ("new session = new token"). Fire
1065
+ // listeners only if we were actually signed in (signing out an
1066
+ // already-null session is a no-op, matching prod).
1067
+ const previousUser = this.cachedUser;
1068
+ this.cachedUser = null;
1069
+ this.applyingTransition = true;
1070
+ try {
1071
+ this.session.currentUser = null;
1072
+ }
1073
+ finally {
1074
+ this.applyingTransition = false;
1075
+ }
1076
+ if (previousUser) {
1077
+ this.tokenCache.delete(previousUser.uid);
1078
+ this.notifyAuthListeners();
1079
+ this.notifySessionChanged();
1080
+ // Sign-out: the acting identity WAS the user that just left; no
1081
+ // `after` state (signed out). Only emit on a real transition
1082
+ // (signing out an already-null session is a prod no-op above).
1083
+ this.emitAuthEvent('sign_out', {
1084
+ path: previousUser.uid,
1085
+ auth: { uid: previousUser.uid },
1086
+ });
1087
+ }
1088
+ return;
1089
+ }
1090
+ // Record this session's provider BEFORE any token mint below so
1091
+ // the freshly-minted token carries the right sign_in_provider.
1092
+ if (signInProvider !== undefined) {
1093
+ this.signInProviderByUid.set(user.uid, signInProvider);
1094
+ }
1095
+ // Look up custom claims for this uid (if we know them). Falls
1096
+ // back to the empty claims map for anonymous / freshly-minted
1097
+ // users.
1098
+ const stored = this.usersByUid.get(user.uid);
1099
+ const claims = stored?.customClaims ?? {};
1100
+ // A `signInProvider` argument marks an actual sign-in (the test
1101
+ // driver omits it) — bump the record's lastLoginAt.
1102
+ if (signInProvider !== undefined && stored) {
1103
+ stored.lastLoginAt = new Date().toISOString();
1104
+ this.notifyUsersChanged();
1105
+ }
1106
+ // Stash the (possibly richer) User snapshot so listeners fire with
1107
+ // the full display name / email, not just the AuthState round-trip.
1108
+ this.cachedUser = user;
1109
+ // Every sign-in mints a fresh token — a new session, even if the uid
1110
+ // is unchanged (AUTH-B8: a same-uid re-sign-in still rotates the
1111
+ // token, which `onIdTokenChanged` then observes). Matches prod's
1112
+ // "new session = new token".
1113
+ this.tokenCache.set(user.uid, this.mintToken(user.uid, claims));
1114
+ // Push to the sandbox under the guard so the synchronous subscriber
1115
+ // doesn't notify — we drive the fan-out below with the correct
1116
+ // id-token / auth-state split.
1117
+ const nextState = { uid: user.uid, token: claims };
1118
+ this.applyingTransition = true;
1119
+ try {
1120
+ this.session.currentUser = nextState;
1121
+ }
1122
+ finally {
1123
+ this.applyingTransition = false;
1124
+ }
1125
+ this.notifyAuthListeners();
1126
+ // Notify session-change subscribers so the persistence controller
1127
+ // can save the new signed-in uid to the appropriate web-storage
1128
+ // slot. This fires AFTER notifyAuthListeners so the auth state is
1129
+ // fully settled before the controller reads currentUid() + mode().
1130
+ this.notifySessionChanged();
1131
+ // Sign-in state change. `signInProvider !== undefined` marks a REAL
1132
+ // sign-in (anonymous / email-password / popup / redirect / restore) —
1133
+ // the test driver (`sandbox.setUser`) omits it and is not a sign-in
1134
+ // worth surfacing on the activity stream. The acting identity IS the
1135
+ // user that just signed in.
1136
+ if (signInProvider !== undefined) {
1137
+ this.emitAuthEvent('sign_in', {
1138
+ path: user.uid,
1139
+ auth: nextState,
1140
+ after: { uid: user.uid, isAnonymous: user.isAnonymous, email: user.email },
1141
+ detail: { providerId: signInProvider ?? 'anonymous' },
1142
+ });
1143
+ }
1144
+ }
1145
+ // ─── Auth-flow registry (delegated to AuthFlowRegistry) ─────────────
1146
+ // The popup/redirect/credential flow-staging seam. Behavior lives in
1147
+ // `sandbox-auth-flow.ts`; these methods delegate so the backend's
1148
+ // public surface is unchanged. See the AuthFlowRegistry header.
1149
+ setMockResult(providerId, result) {
1150
+ this.flow.setMockResult(providerId, result);
1151
+ }
1152
+ consumeMockResult(providerId) {
1153
+ return this.flow.consumeMockResult(providerId);
1154
+ }
1155
+ setResolver(resolver) {
1156
+ this.flow.setResolver(resolver);
1157
+ }
1158
+ getResolver() {
1159
+ return this.flow.getResolver();
1160
+ }
1161
+ setRedirectResult(result) {
1162
+ this.flow.setRedirectResult(result);
1163
+ }
1164
+ takeRedirectResult() {
1165
+ return this.flow.takeRedirectResult();
1166
+ }
1167
+ /**
1168
+ * Record a provider-flow sign-in (popup / redirect / credential)
1169
+ * against the user DB so the identity shows up in `listIdentities`
1170
+ * with its real provider. Upserts: unknown uids get a fresh record
1171
+ * (no password — these identities can't sign in via
1172
+ * `signInWithEmailAndPassword`); known uids get the provider
1173
+ * appended to `providerUserInfo` if it isn't already linked.
1174
+ */
1175
+ recordProviderSignIn(user, providerId) {
1176
+ let changed = false;
1177
+ let stored = this.usersByUid.get(user.uid);
1178
+ if (!stored) {
1179
+ stored = this.makeStored({
1180
+ uid: user.uid,
1181
+ email: user.email,
1182
+ displayName: user.displayName,
1183
+ isAnonymous: user.isAnonymous,
1184
+ });
1185
+ this.usersByUid.set(user.uid, stored);
1186
+ if (user.email)
1187
+ this.usersByEmail.set(user.email.toLowerCase(), stored);
1188
+ changed = true;
1189
+ }
1190
+ if (!stored.providerUserInfo.some((p) => p.providerId === providerId)) {
1191
+ stored.providerUserInfo.push({ providerId });
1192
+ changed = true;
1193
+ }
1194
+ if (changed)
1195
+ this.notifyUsersChanged();
1196
+ }
1197
+ /**
1198
+ * Mint a sign-in credential for a host-driven flow (the account
1199
+ * picker behind `AuthFlowResolver`). Token + claims synthesis is
1200
+ * backend-owned: the returned `User`'s `getIdToken` /
1201
+ * `getIdTokenResult` route through this backend's token cache, so
1202
+ * helper-driven sign-ins get real (cached, refreshable,
1203
+ * provider-labeled) sandbox tokens instead of host-synthesized
1204
+ * strings.
1205
+ *
1206
+ * Two request shapes:
1207
+ * - `{providerId, uid}` — credential for an EXISTING identity
1208
+ * (the picker's "pick" action). Throws `invalid-argument` for
1209
+ * unknown uids.
1210
+ * - `{providerId, spec}` — upsert a new identity (the picker's
1211
+ * "add account"). If `spec.email` already belongs to a stored
1212
+ * user, that identity is reused and the provider linked
1213
+ * (Google-style same-email account reuse); otherwise a fresh
1214
+ * record is created with uid `spec.uid ?? '<providerId>:<email>'`
1215
+ * and NO password (provider identities can't sign in via
1216
+ * `signInWithEmailAndPassword`).
1217
+ *
1218
+ * In both shapes the provider is linked into `providerUserInfo`.
1219
+ * The credential does NOT sign the user in — hand it to the
1220
+ * resolver's promise; `signInWithPopup`/`signInWithRedirect`
1221
+ * complete the sign-in.
1222
+ */
1223
+ createSignInCredential(req) {
1224
+ const { providerId } = req;
1225
+ let stored;
1226
+ if ('uid' in req) {
1227
+ const found = this.usersByUid.get(req.uid);
1228
+ if (!found) {
1229
+ throw makeAuthError('auth/user-not-found', `createSignInCredential: no identity with uid ${req.uid}. Use the {spec} shape to create one.`);
1230
+ }
1231
+ stored = found;
1232
+ }
1233
+ else {
1234
+ const { spec } = req;
1235
+ const byEmail = this.usersByEmail.get(spec.email.toLowerCase());
1236
+ if (byEmail) {
1237
+ stored = byEmail;
1238
+ }
1239
+ else {
1240
+ stored = this.makeStored({
1241
+ uid: spec.uid ?? `${providerId}:${spec.email}`,
1242
+ email: spec.email,
1243
+ displayName: spec.displayName ?? null,
1244
+ customClaims: spec.customClaims ?? {},
1245
+ });
1246
+ this.usersByUid.set(stored.uid, stored);
1247
+ this.usersByEmail.set(spec.email.toLowerCase(), stored);
1248
+ this.notifyUsersChanged();
1249
+ }
1250
+ }
1251
+ if (!stored.providerUserInfo.some((p) => p.providerId === providerId)) {
1252
+ stored.providerUserInfo.push({ providerId });
1253
+ this.notifyUsersChanged();
1254
+ }
1255
+ return {
1256
+ user: this.buildUserFromStored(stored),
1257
+ providerId,
1258
+ operationType: 'signIn',
1259
+ };
1260
+ }
1261
+ /** Snapshot of every known identity (seeded + created), for a host
1262
+ * account-picker UI. No `firebase/auth` equivalent — sandbox-only.
1263
+ *
1264
+ * `providerId` is the primary provider label (first linked
1265
+ * provider, or `'anonymous'` for anonymous users);
1266
+ * `providerUserInfo` is the full emulator-shaped array. */
1267
+ listIdentities() {
1268
+ return [...this.usersByUid.values()].map((u) => ({
1269
+ uid: u.uid,
1270
+ email: u.email,
1271
+ displayName: u.displayName,
1272
+ providerId: u.isAnonymous
1273
+ ? 'anonymous'
1274
+ : u.providerUserInfo[0]?.providerId ?? 'password',
1275
+ providerUserInfo: [...u.providerUserInfo],
1276
+ isAnonymous: u.isAnonymous,
1277
+ customClaims: u.customClaims,
1278
+ }));
1279
+ }
1280
+ // ─── User-admin surface (emulator-REST-shaped) ──────────────────────
1281
+ /** Public snapshot of a stored user. Defensive copies — mutating a
1282
+ * returned record never touches the DB. */
1283
+ toRecord(u) {
1284
+ return {
1285
+ uid: u.uid,
1286
+ email: u.email,
1287
+ displayName: u.displayName,
1288
+ phoneNumber: u.phoneNumber,
1289
+ photoUrl: u.photoUrl,
1290
+ customClaims: { ...u.customClaims },
1291
+ providerUserInfo: u.providerUserInfo.map((p) => ({ ...p })),
1292
+ isAnonymous: u.isAnonymous,
1293
+ disabled: u.disabled,
1294
+ emailVerified: u.emailVerified,
1295
+ createdAt: u.createdAt,
1296
+ lastLoginAt: u.lastLoginAt,
1297
+ };
1298
+ }
1299
+ /** Every user in the DB (seeded, created, signed-in-via-provider,
1300
+ * anonymous), as admin records. */
1301
+ listUsers() {
1302
+ return [...this.usersByUid.values()].map((u) => this.toRecord(u));
1303
+ }
1304
+ /** Sanitize an admin-supplied linked-provider list (create + update):
1305
+ * dedup by providerId, reject empty ids, and refuse the two ids that
1306
+ * are NOT linkable entries — `password` is credential-derived (a
1307
+ * password on the account links it; it leads the list when present)
1308
+ * and `anonymous` surfaces on the token, never on the record. */
1309
+ sanitizeLinkedProviders(entries, hasPassword, op) {
1310
+ const seen = new Set();
1311
+ const next = [];
1312
+ for (const entry of entries) {
1313
+ const providerId = entry?.providerId?.trim();
1314
+ if (!providerId) {
1315
+ throw makeAuthError('auth/argument-error', `${op}: providerUserInfo entries need a non-empty providerId.`);
1316
+ }
1317
+ if (providerId === 'password' || providerId === 'anonymous')
1318
+ continue;
1319
+ if (seen.has(providerId))
1320
+ continue;
1321
+ seen.add(providerId);
1322
+ next.push({ providerId });
1323
+ }
1324
+ if (hasPassword)
1325
+ next.unshift({ providerId: 'password' });
1326
+ return next;
1327
+ }
1328
+ /** Admin user creation. Does NOT sign the user in (unlike
1329
+ * `createUserWithEmailAndPassword`) — matches the emulator's
1330
+ * add-user flow / admin SDK semantics. */
1331
+ createUser(req) {
1332
+ const uid = req.uid ?? `user-${this.sharedCounters.nextAdminUserId++}`;
1333
+ if (this.usersByUid.has(uid)) {
1334
+ throw makeAuthError('auth/uid-already-exists', `createUser: a user with uid ${uid} already exists.`);
1335
+ }
1336
+ if (req.email !== undefined) {
1337
+ validateEmailFormat(req.email);
1338
+ if (this.usersByEmail.has(req.email.toLowerCase())) {
1339
+ throw makeAuthError('auth/email-already-in-use', `An account already exists for ${req.email}.`);
1340
+ }
1341
+ }
1342
+ if (req.password !== undefined) {
1343
+ validatePasswordStrength(req.password);
1344
+ if (req.email === undefined) {
1345
+ throw makeAuthError('auth/invalid-email', 'createUser: a password requires an email.');
1346
+ }
1347
+ }
1348
+ const record = this.makeStored({
1349
+ uid,
1350
+ email: req.email ?? null,
1351
+ password: req.password ?? null,
1352
+ displayName: req.displayName ?? null,
1353
+ phoneNumber: req.phoneNumber ?? null,
1354
+ photoUrl: req.photoUrl ?? null,
1355
+ customClaims: req.customClaims ?? {},
1356
+ disabled: req.disabled ?? false,
1357
+ emailVerified: req.emailVerified ?? false,
1358
+ providerUserInfo: this.sanitizeLinkedProviders(req.providerUserInfo ?? [], req.password !== undefined, 'createUser'),
1359
+ });
1360
+ this.usersByUid.set(uid, record);
1361
+ if (record.email)
1362
+ this.usersByEmail.set(record.email.toLowerCase(), record);
1363
+ this.notifyUsersChanged();
1364
+ const created = this.toRecord(record);
1365
+ this.emitAuthEvent('user_create', { path: uid, auth: null, after: created });
1366
+ return created;
1367
+ }
1368
+ /** Admin user update. `undefined` fields untouched; `customClaims`
1369
+ * replaces the whole map (admin `setCustomUserClaims` semantics).
1370
+ * Claims changes reach an ACTIVE session only on the next token
1371
+ * refresh / sign-in — same propagation story as prod. */
1372
+ updateUser(uid, update) {
1373
+ const stored = this.usersByUid.get(uid);
1374
+ if (!stored) {
1375
+ throw makeAuthError('auth/user-not-found', `No user found for uid ${uid}.`);
1376
+ }
1377
+ const before = this.toRecord(stored);
1378
+ if (update.email !== undefined) {
1379
+ validateEmailFormat(update.email);
1380
+ const key = update.email.toLowerCase();
1381
+ const existing = this.usersByEmail.get(key);
1382
+ if (existing && existing !== stored) {
1383
+ throw makeAuthError('auth/email-already-in-use', `An account already exists for ${update.email}.`);
1384
+ }
1385
+ if (stored.email)
1386
+ this.usersByEmail.delete(stored.email.toLowerCase());
1387
+ stored.email = update.email;
1388
+ this.usersByEmail.set(key, stored);
1389
+ }
1390
+ if (update.password !== undefined) {
1391
+ validatePasswordStrength(update.password);
1392
+ stored.password = update.password;
1393
+ // Setting a password links the password provider — matches the
1394
+ // Identity Toolkit (an account gains providerUserInfo entry
1395
+ // when a password is set on it).
1396
+ if (!stored.providerUserInfo.some((p) => p.providerId === 'password')) {
1397
+ stored.providerUserInfo.push({ providerId: 'password' });
1398
+ }
1399
+ }
1400
+ if (update.providerUserInfo !== undefined) {
1401
+ stored.providerUserInfo = this.sanitizeLinkedProviders(update.providerUserInfo, stored.password !== null, 'updateUser');
1402
+ }
1403
+ if (update.displayName !== undefined)
1404
+ stored.displayName = update.displayName;
1405
+ if (update.customClaims !== undefined) {
1406
+ stored.customClaims = { ...update.customClaims };
1407
+ }
1408
+ if (update.disabled !== undefined)
1409
+ stored.disabled = update.disabled;
1410
+ if (update.emailVerified !== undefined)
1411
+ stored.emailVerified = update.emailVerified;
1412
+ this.notifyUsersChanged();
1413
+ const after = this.toRecord(stored);
1414
+ this.emitAuthEvent('user_update', { path: uid, auth: null, before, after });
1415
+ return after;
1416
+ }
1417
+ /** Admin user deletion. The active session (if it's this user) is
1418
+ * NOT terminated — matches prod, where admin deletion doesn't kill
1419
+ * live client sessions until the token is revoked/refreshed. */
1420
+ deleteUser(uid) {
1421
+ const stored = this.usersByUid.get(uid);
1422
+ if (!stored) {
1423
+ throw makeAuthError('auth/user-not-found', `No user found for uid ${uid}.`);
1424
+ }
1425
+ const before = this.toRecord(stored);
1426
+ this.usersByUid.delete(uid);
1427
+ if (stored.email && this.usersByEmail.get(stored.email.toLowerCase()) === stored) {
1428
+ this.usersByEmail.delete(stored.email.toLowerCase());
1429
+ }
1430
+ this.tokenCache.delete(uid);
1431
+ this.signInProviderByUid.delete(uid);
1432
+ this.notifyUsersChanged();
1433
+ this.emitAuthEvent('user_delete', { path: uid, auth: null, before });
1434
+ }
1435
+ /** Drop every user record (the emulator's "delete all accounts").
1436
+ * Active sessions are untouched, like {@link deleteUser}. */
1437
+ clearUsers() {
1438
+ if (this.usersByUid.size === 0 && this.usersByEmail.size === 0)
1439
+ return;
1440
+ const count = this.usersByUid.size;
1441
+ this.usersByUid.clear();
1442
+ this.usersByEmail.clear();
1443
+ this.notifyUsersChanged();
1444
+ this.emitAuthEvent('users_clear', { path: '*', auth: null, detail: { count } });
1445
+ }
1446
+ /** Throw `auth/user-disabled` if the uid resolves to a disabled
1447
+ * record. Called by every provider-flow sign-in path; the
1448
+ * email/password path runs the same check inside
1449
+ * {@link validatePassword}. */
1450
+ assertSignInAllowed(uid) {
1451
+ if (this.usersByUid.get(uid)?.disabled) {
1452
+ throw makeAuthError('auth/user-disabled', 'The user account has been disabled by an administrator.');
1453
+ }
1454
+ }
1455
+ // ─── User factories ─────────────────────────────────────────────────
1456
+ /**
1457
+ * Mint a `User` shell for the given stored record. Used by all
1458
+ * email/password and popup sign-in paths.
1459
+ */
1460
+ buildUserFromStored(stored) {
1461
+ return this.makeUser({
1462
+ uid: stored.uid,
1463
+ email: stored.email,
1464
+ displayName: stored.displayName,
1465
+ isAnonymous: stored.isAnonymous,
1466
+ claims: stored.customClaims,
1467
+ // Carry the profile fields through so a rebuilt/restored user (session
1468
+ // restore, snapshot round-trip) keeps its photoURL / emailVerified /
1469
+ // phoneNumber. Additive: these were null/undefined before this landed.
1470
+ photoURL: stored.photoUrl,
1471
+ emailVerified: stored.emailVerified,
1472
+ phoneNumber: stored.phoneNumber,
1473
+ providers: stored.providerUserInfo,
1474
+ });
1475
+ }
1476
+ /** Mint a fresh anonymous user with an auto-generated uid. Records
1477
+ * the identity in the user DB (empty `providerUserInfo`, matching
1478
+ * the emulator) so `listIdentities` / future user-admin surfaces
1479
+ * see anonymous accounts too. */
1480
+ mintAnonymousUser() {
1481
+ const uid = `anonymous-${this.sharedCounters.nextAnonymousId++}`;
1482
+ const record = this.makeStored({ uid, isAnonymous: true });
1483
+ this.usersByUid.set(uid, record);
1484
+ this.notifyUsersChanged();
1485
+ this.emitAuthEvent('user_create', { path: uid, after: this.toRecord(record), detail: { isAnonymous: true } });
1486
+ return this.makeUser({
1487
+ uid,
1488
+ email: null,
1489
+ displayName: null,
1490
+ isAnonymous: true,
1491
+ claims: {},
1492
+ });
1493
+ }
1494
+ // ─── Detached sessions (per-connection identity substrate) ──────────
1495
+ /**
1496
+ * Mint a session identity WITHOUT making it the global current user —
1497
+ * the substrate for per-connection identity at the serve layer (one
1498
+ * SharedWorker sandbox, N tab sessions; issue #754). Performs a real
1499
+ * sign-in's bookkeeping — provider record, `lastLoginAt` bump, a fresh
1500
+ * token (new session = new token), the `sign_in` activity event — but
1501
+ * leaves `sandbox.currentUser`, the auth-state listeners, and the
1502
+ * session-change subscribers untouched.
1503
+ *
1504
+ * Returns the `User` plus the {@link AuthState} a data context should
1505
+ * carry (`sandbox.withAuth(state)`) so rules evaluate exactly as they
1506
+ * would for a globally signed-in user (`request.auth.uid` + custom
1507
+ * claims on `request.auth.token`).
1508
+ *
1509
+ * GATING: `'anonymous'` / `'password'` / `'createPassword'` run through
1510
+ * {@link assertProviderEnabled} — this is the path the served worker's
1511
+ * per-port sessions actually use (`sandbox.mintSession`, NOT the
1512
+ * `index.ts` free functions), so without this the provider toggle would
1513
+ * have zero effect in `pyric dev`/Studio's served mode, the primary
1514
+ * product surface. `'uid'` (session RESTORE for an existing identity —
1515
+ * a page reload re-establishing a previously-valid session) is
1516
+ * deliberately NOT gated, matching {@link restoreSession}: disabling a
1517
+ * provider after the fact doesn't retroactively invalidate an already-
1518
+ * authenticated session, same as real Firebase.
1519
+ */
1520
+ mintDetachedSession(request) {
1521
+ switch (request.kind) {
1522
+ case 'anonymous':
1523
+ this.assertProviderEnabled('anonymous');
1524
+ return this.establishDetachedSession(this.mintAnonymousUser(), 'anonymous');
1525
+ case 'password':
1526
+ this.assertProviderEnabled('password');
1527
+ return this.establishDetachedSession(this.buildUserFromStored(this.validatePassword(request.email, request.password)), 'password');
1528
+ case 'createPassword':
1529
+ this.assertProviderEnabled('password');
1530
+ return this.establishDetachedSession(this.buildUserFromStored(this.createEmailPasswordUser(request.email, request.password)), 'password');
1531
+ case 'uid': {
1532
+ // restoreSession semantics minus the global set: an EXISTING
1533
+ // identity (per-tab session restore / provider-bridge accept).
1534
+ const stored = this.usersByUid.get(request.uid);
1535
+ if (!stored) {
1536
+ throw makeAuthError('auth/user-not-found', `mintSession: no identity with uid ${request.uid}.`);
1537
+ }
1538
+ if (stored.disabled) {
1539
+ throw makeAuthError('auth/user-disabled', `mintSession: user ${request.uid} is disabled.`);
1540
+ }
1541
+ const providerId = stored.isAnonymous
1542
+ ? 'anonymous'
1543
+ : (stored.providerUserInfo[0]?.providerId ?? 'password');
1544
+ return this.establishDetachedSession(this.buildUserFromStored(stored), providerId);
1545
+ }
1546
+ }
1547
+ }
1548
+ /** The shared sign-in bookkeeping behind {@link mintDetachedSession} —
1549
+ * everything {@link setCurrentUser} does for a real sign-in EXCEPT the
1550
+ * global-session parts. */
1551
+ establishDetachedSession(user, signInProvider) {
1552
+ this.signInProviderByUid.set(user.uid, signInProvider);
1553
+ const stored = this.usersByUid.get(user.uid);
1554
+ const claims = stored?.customClaims ?? {};
1555
+ if (stored) {
1556
+ stored.lastLoginAt = new Date().toISOString();
1557
+ this.notifyUsersChanged();
1558
+ }
1559
+ this.tokenCache.set(user.uid, this.mintToken(user.uid, claims));
1560
+ const state = { uid: user.uid, token: claims };
1561
+ this.emitAuthEvent('sign_in', {
1562
+ path: user.uid,
1563
+ auth: state,
1564
+ after: { uid: user.uid, isAnonymous: user.isAnonymous, email: user.email },
1565
+ // `session: 'connection'` marks a per-connection (detached) session so
1566
+ // observability can tell it from a global sign-in.
1567
+ detail: { providerId: signInProvider, session: 'connection' },
1568
+ });
1569
+ return { user, state };
1570
+ }
1571
+ /** Reconstruct a `User` object from an {@link AuthState}. Returns
1572
+ * `null` for `null` input. Used to mirror sandbox-level state
1573
+ * changes that didn't originate from this backend. */
1574
+ buildUserFromState(state) {
1575
+ if (state === null)
1576
+ return null;
1577
+ // Look up DB-stored attrs (email, displayName) by uid; fall back
1578
+ // to anonymous shape if unknown.
1579
+ const stored = this.usersByUid.get(state.uid);
1580
+ if (stored) {
1581
+ return this.buildUserFromStored({
1582
+ ...stored,
1583
+ customClaims: state.token ?? stored.customClaims,
1584
+ });
1585
+ }
1586
+ return this.makeUser({
1587
+ uid: state.uid,
1588
+ email: null,
1589
+ displayName: null,
1590
+ isAnonymous: state.uid.startsWith('anonymous-'),
1591
+ claims: state.token ?? {},
1592
+ });
1593
+ }
1594
+ // ─── Token cache / refresh ──────────────────────────────────────────
1595
+ /**
1596
+ * Mint a fresh `{ token, result }` for the given uid + claims. Used
1597
+ * both on initial `getIdToken` (cache miss) and on a forced
1598
+ * refresh. Each call advances {@link nextTokenSerial} so two
1599
+ * refreshes inside the same millisecond still produce distinct
1600
+ * token strings.
1601
+ */
1602
+ mintToken(uid, claims) {
1603
+ const issuedAt = new Date();
1604
+ // 100 years out — sandbox tokens never expire.
1605
+ const expires = new Date(issuedAt.getTime() + 100 * 365 * 24 * 60 * 60 * 1000);
1606
+ const serial = this.nextTokenSerial++;
1607
+ const token = sandboxTokenFor(uid, claims, serial);
1608
+ // The provider of the current sign-in session for this uid —
1609
+ // recorded by setCurrentUser at sign-in time. Null for identities
1610
+ // driven via the test driver (no prod analog for that path).
1611
+ const signInProvider = this.signInProviderByUid.get(uid) ?? null;
1612
+ const fullClaims = {
1613
+ sub: uid,
1614
+ aud: 'pyric-sandbox',
1615
+ iss: 'https://sandbox.pyric.dev',
1616
+ auth_time: Math.floor(issuedAt.getTime() / 1000),
1617
+ iat: Math.floor(issuedAt.getTime() / 1000),
1618
+ exp: Math.floor(expires.getTime() / 1000),
1619
+ ...claims,
1620
+ // Synthesized AFTER the custom-claims spread: `firebase` is a
1621
+ // reserved claim namespace in prod (custom claims can't shadow
1622
+ // it), so ours always wins. Mirrors the real JWT's
1623
+ // `firebase.sign_in_provider`.
1624
+ firebase: { sign_in_provider: signInProvider },
1625
+ };
1626
+ const result = {
1627
+ token,
1628
+ claims: fullClaims,
1629
+ expirationTime: expires.toISOString(),
1630
+ issuedAtTime: issuedAt.toISOString(),
1631
+ authTime: issuedAt.toISOString(),
1632
+ signInProvider,
1633
+ };
1634
+ return { token, result };
1635
+ }
1636
+ /**
1637
+ * Get-or-mint the ID token entry for a uid. `forceRefresh: true`
1638
+ * always mints a fresh token, overwrites the cache, and fires the
1639
+ * `onIdTokenChanged` listeners (NOT `onAuthStateChanged` — the
1640
+ * user identity didn't change). Matches prod oracle observations:
1641
+ *
1642
+ * - `auth-getidtoken-force-refresh.json` — forceRefresh returns a
1643
+ * different string than the previous read; a subsequent
1644
+ * getIdToken(false) returns the new (cached) token.
1645
+ * - `auth-onidtokenchanged-force-refresh.json` — onIdTokenChanged
1646
+ * fires after a forced refresh.
1647
+ */
1648
+ getIdTokenFor(uid, claims, forceRefresh) {
1649
+ if (forceRefresh) {
1650
+ const fresh = this.mintToken(uid, claims);
1651
+ this.tokenCache.set(uid, fresh);
1652
+ // Fan out to onIdTokenChanged listeners only — identity is
1653
+ // unchanged, so onAuthStateChanged stays silent.
1654
+ this.fanOut('id-token');
1655
+ return fresh.token;
1656
+ }
1657
+ const cached = this.tokenCache.get(uid);
1658
+ if (cached)
1659
+ return cached.token;
1660
+ const fresh = this.mintToken(uid, claims);
1661
+ this.tokenCache.set(uid, fresh);
1662
+ return fresh.token;
1663
+ }
1664
+ /** {@link getIdTokenFor} variant returning the full IdTokenResult.
1665
+ * Same cache + fan-out semantics. */
1666
+ getIdTokenResultFor(uid, claims, forceRefresh) {
1667
+ if (forceRefresh) {
1668
+ const fresh = this.mintToken(uid, claims);
1669
+ this.tokenCache.set(uid, fresh);
1670
+ this.fanOut('id-token');
1671
+ return fresh.result;
1672
+ }
1673
+ const cached = this.tokenCache.get(uid);
1674
+ if (cached)
1675
+ return cached.result;
1676
+ const fresh = this.mintToken(uid, claims);
1677
+ this.tokenCache.set(uid, fresh);
1678
+ return fresh.result;
1679
+ }
1680
+ /**
1681
+ * Build a `User` shell whose `getIdToken` / `getIdTokenResult`
1682
+ * route through the backend's token cache. The User object closes
1683
+ * over its uid + claims; the cache is owned by the backend so all
1684
+ * User instances for the same uid agree on the current token.
1685
+ */
1686
+ makeUser(args) {
1687
+ const photoURL = args.photoURL ?? null;
1688
+ const phoneNumber = args.phoneNumber ?? null;
1689
+ // Sandbox has no email-verification flow; default to false unless the
1690
+ // caller explicitly supplied it (AUTH-GAP).
1691
+ const emailVerified = args.emailVerified ?? false;
1692
+ const providerId = 'firebase';
1693
+ // `providerData` is one entry PER LINKED PROVIDER, read from the stored
1694
+ // record. It used to be a synthesized single `{providerId: 'password'}`
1695
+ // entry for every non-anonymous user, which was wrong the moment an
1696
+ // identity carried anything else: a Google popup sign-in reported its
1697
+ // provider as `'password'`, and after the linking climb an account with
1698
+ // two providers would still have reported one. Consumer code branches on
1699
+ // this array (that is what it is FOR — "is this account linked to
1700
+ // Google?"), so the synthesized version was actively misleading.
1701
+ //
1702
+ // ABSENT vs EMPTY is the distinction that matters, and conflating them is
1703
+ // a real bug: `undefined` means "no stored record to read" (a popup/mock
1704
+ // user the backend never saw) and falls back to the old single-entry
1705
+ // synthesis so nothing that worked before regresses; `[]` means "this
1706
+ // identity genuinely has no linked providers", which is exactly what
1707
+ // `unlink` of the last provider produces. Falling back on `[]` would
1708
+ // resurrect the very provider the user just removed.
1709
+ const linked = args.providers ?? [{ providerId: 'password' }];
1710
+ const providerData = args.isAnonymous
1711
+ ? []
1712
+ : linked.map((p) => ({
1713
+ uid: args.uid,
1714
+ displayName: args.displayName,
1715
+ email: args.email,
1716
+ phoneNumber,
1717
+ photoURL,
1718
+ providerId: p.providerId,
1719
+ }));
1720
+ const user = {
1721
+ uid: args.uid,
1722
+ email: args.email,
1723
+ emailVerified,
1724
+ displayName: args.displayName,
1725
+ photoURL,
1726
+ phoneNumber,
1727
+ isAnonymous: args.isAnonymous,
1728
+ providerId,
1729
+ providerData,
1730
+ // Read LIVE claims by uid on each token call (not the claims frozen
1731
+ // at mint time) so a `seedUsers` re-seed or an `updateUser` claims
1732
+ // change for this uid is reflected in a held user's
1733
+ // `getIdToken(true)` (AUTH-B10) — same propagation story as prod.
1734
+ // Falls back to the closed-over claims for users not in the DB
1735
+ // (anonymous / popup), matching how they were minted.
1736
+ getIdToken: async (forceRefresh) => this.getIdTokenFor(args.uid, this.liveClaims(args.uid, args.claims), forceRefresh === true),
1737
+ getIdTokenResult: async (forceRefresh) => this.getIdTokenResultFor(args.uid, this.liveClaims(args.uid, args.claims), forceRefresh === true),
1738
+ };
1739
+ // Stamp the backend-dispatch hook non-enumerably so the top-level
1740
+ // `updateProfile(user, …)` free function can update THIS user (and the
1741
+ // stored record) without an `auth` handle in scope, matching
1742
+ // `firebase/auth`'s `updateProfile(user, profile)` signature. Hidden
1743
+ // from enumeration/serialization so it never leaks into snapshots.
1744
+ Object.defineProperty(user, USER_INTERNAL, {
1745
+ value: {
1746
+ updateProfile: (p) => {
1747
+ this.updateProfileFor(user, p);
1748
+ return Promise.resolve();
1749
+ },
1750
+ delete: () => {
1751
+ this.deleteFor(user);
1752
+ return Promise.resolve();
1753
+ },
1754
+ updateEmail: (newEmail) => {
1755
+ this.updateEmailFor(user, newEmail);
1756
+ return Promise.resolve();
1757
+ },
1758
+ updatePassword: (newPassword) => {
1759
+ this.updatePasswordFor(user, newPassword);
1760
+ return Promise.resolve();
1761
+ },
1762
+ reload: () => {
1763
+ this.reloadFor(user);
1764
+ return Promise.resolve();
1765
+ },
1766
+ // Routing rides on the user — see UserInternal.target. Built here
1767
+ // rather than injected because the backend predates the target
1768
+ // object that wraps it (`getAuth` constructs the target FROM the
1769
+ // backend), and every field of that target is already ours.
1770
+ target: this.selfTarget(),
1771
+ },
1772
+ enumerable: false,
1773
+ });
1774
+ return user;
1775
+ }
1776
+ /** This backend's dispatch target — the same shape `getAuth` builds. */
1777
+ selfTarget() {
1778
+ return { kind: 'sandbox', sandbox: this.sandbox, backend: this };
1779
+ }
1780
+ /**
1781
+ * Update a signed-in user's profile (`displayName` / `photoURL`) — the
1782
+ * backend behind the top-level `updateProfile(user, profile)`.
1783
+ *
1784
+ * Updates the stored record, then mutates the passed `user` AND
1785
+ * `this.cachedUser` IN PLACE when their uid matches (the `User` fields are
1786
+ * TS-`readonly` but runtime-mutable, so held references — including
1787
+ * `auth.currentUser` — reflect the change without a re-read). Only a field
1788
+ * whose `profile.<field> !== undefined` is applied, so `null` clears and
1789
+ * `undefined` leaves the field untouched.
1790
+ *
1791
+ * Fires the coarse user-DB change (`notifyUsersChanged`) + a `user_update`
1792
+ * activity event, but does NOT fan out auth-state / id-token listeners:
1793
+ * real `firebase/auth.updateProfile` does not fire `onAuthStateChanged` /
1794
+ * `onIdTokenChanged`.
1795
+ */
1796
+ updateProfileFor(user, profile) {
1797
+ const stored = this.usersByUid.get(user.uid);
1798
+ const before = stored ? this.toRecord(stored) : undefined;
1799
+ if (stored) {
1800
+ if (profile.displayName !== undefined)
1801
+ stored.displayName = profile.displayName;
1802
+ if (profile.photoURL !== undefined)
1803
+ stored.photoUrl = profile.photoURL;
1804
+ }
1805
+ this.applyProfileToUser(user, profile);
1806
+ if (this.cachedUser && this.cachedUser.uid === user.uid && this.cachedUser !== user) {
1807
+ this.applyProfileToUser(this.cachedUser, profile);
1808
+ }
1809
+ this.notifyUsersChanged();
1810
+ this.emitAuthEvent('user_update', {
1811
+ path: user.uid,
1812
+ auth: { uid: user.uid },
1813
+ before,
1814
+ after: stored ? this.toRecord(stored) : undefined,
1815
+ detail: {
1816
+ displayName: profile.displayName,
1817
+ photoURL: profile.photoURL,
1818
+ },
1819
+ });
1820
+ }
1821
+ /** Mutate a `User`'s `displayName` / `photoURL` (and the first
1822
+ * `providerData` entry's, when present) in place. `readonly` at the type
1823
+ * level, mutable at runtime — cast through a Mutable helper. Only applies a
1824
+ * field when it was explicitly provided (`!== undefined`). */
1825
+ applyProfileToUser(user, profile) {
1826
+ const mutable = user;
1827
+ if (profile.displayName !== undefined)
1828
+ mutable.displayName = profile.displayName;
1829
+ if (profile.photoURL !== undefined)
1830
+ mutable.photoURL = profile.photoURL;
1831
+ const provider0 = user.providerData?.[0];
1832
+ if (provider0) {
1833
+ if (profile.displayName !== undefined)
1834
+ provider0.displayName = profile.displayName;
1835
+ if (profile.photoURL !== undefined)
1836
+ provider0.photoURL = profile.photoURL;
1837
+ }
1838
+ }
1839
+ /**
1840
+ * Worker-path `updateProfile`: update the stored record for `uid`
1841
+ * (+ mutate `this.cachedUser` in place if it matches), then return the
1842
+ * refreshed {@link AuthUserRecord}. The worker holds the real per-port
1843
+ * session `User` and mutates it separately (host-auth.ts). Throws
1844
+ * `auth/user-not-found` for an unknown uid.
1845
+ */
1846
+ updateProfileByUid(uid, profile) {
1847
+ const stored = this.usersByUid.get(uid);
1848
+ if (!stored) {
1849
+ throw makeAuthError('auth/user-not-found', `updateProfile: no identity with uid ${uid}.`);
1850
+ }
1851
+ const before = this.toRecord(stored);
1852
+ if (profile.displayName !== undefined)
1853
+ stored.displayName = profile.displayName;
1854
+ if (profile.photoURL !== undefined)
1855
+ stored.photoUrl = profile.photoURL;
1856
+ if (this.cachedUser && this.cachedUser.uid === uid) {
1857
+ this.applyProfileToUser(this.cachedUser, profile);
1858
+ }
1859
+ this.notifyUsersChanged();
1860
+ const after = this.toRecord(stored);
1861
+ this.emitAuthEvent('user_update', {
1862
+ path: uid,
1863
+ auth: { uid },
1864
+ before,
1865
+ after,
1866
+ detail: { displayName: profile.displayName, photoURL: profile.photoURL },
1867
+ });
1868
+ return after;
1869
+ }
1870
+ /**
1871
+ * Backend for the top-level `deleteUser(user)` free function. Removes the
1872
+ * account from the store (via the same path admin {@link deleteUser} uses)
1873
+ * AND — unlike admin deletion — signs the user out if they are the current
1874
+ * user, matching `firebase/auth`'s `user.delete()` / `deleteUser(user)`,
1875
+ * which clears `auth.currentUser` and fans out `onAuthStateChanged(null)`.
1876
+ */
1877
+ deleteFor(user) {
1878
+ if (this.usersByUid.has(user.uid)) {
1879
+ this.deleteUser(user.uid);
1880
+ }
1881
+ if (this.cachedUser && this.cachedUser.uid === user.uid) {
1882
+ this.setCurrentUser(null);
1883
+ }
1884
+ }
1885
+ /**
1886
+ * Backend for the top-level `updateEmail(user, newEmail)`. Re-keys the
1887
+ * stored record's email (via {@link updateUser}, which validates format +
1888
+ * rejects `auth/email-already-in-use`) so a subsequent sign-in resolves
1889
+ * against the NEW email, then mutates the passed `user` (and
1890
+ * `this.cachedUser`) in place so held references reflect the change.
1891
+ *
1892
+ * Divergence: the sandbox applies the change directly. Real
1893
+ * `firebase/auth.updateEmail` may require a recent login
1894
+ * (`auth/requires-recent-login`) and, with email-enumeration protection
1895
+ * on, is superseded by `verifyBeforeUpdateEmail`; the sandbox enforces
1896
+ * neither.
1897
+ */
1898
+ updateEmailFor(user, newEmail) {
1899
+ this.updateUser(user.uid, { email: newEmail });
1900
+ this.applyEmailToUser(user, newEmail);
1901
+ if (this.cachedUser && this.cachedUser.uid === user.uid && this.cachedUser !== user) {
1902
+ this.applyEmailToUser(this.cachedUser, newEmail);
1903
+ }
1904
+ }
1905
+ /** Mutate a `User`'s `email` (and its first `providerData` entry) in
1906
+ * place — `readonly` at the type level, runtime-mutable. */
1907
+ applyEmailToUser(user, email) {
1908
+ user.email = email;
1909
+ const provider0 = user.providerData?.[0];
1910
+ if (provider0)
1911
+ provider0.email = email;
1912
+ }
1913
+ /**
1914
+ * Backend for the top-level `updatePassword(user, newPassword)`. Sets the
1915
+ * stored password (via {@link updateUser}, which validates strength and
1916
+ * links the `password` provider). The sandbox DOES store + verify
1917
+ * passwords, so a subsequent `signInWithEmailAndPassword` with the new
1918
+ * password succeeds and the old one throws `auth/wrong-password`.
1919
+ *
1920
+ * Divergence: real `firebase/auth.updatePassword` may require a recent
1921
+ * login (`auth/requires-recent-login`); the sandbox does not enforce it.
1922
+ */
1923
+ updatePasswordFor(user, newPassword) {
1924
+ this.updateUser(user.uid, { password: newPassword });
1925
+ }
1926
+ /**
1927
+ * Backend for the top-level `reload(user)`. Re-reads the stored record
1928
+ * into the passed `user` (and `this.cachedUser`) in place so a change
1929
+ * made out of band (e.g. `sandbox.updateUser`) is reflected — matching
1930
+ * `firebase/auth.reload`, which refreshes the user from the server.
1931
+ *
1932
+ * If the identity is gone from the store (e.g. after `deleteUser`),
1933
+ * throws `auth/user-token-expired` — matching upstream integration
1934
+ * flows (`email.test.ts` / `custom.local.test.ts`: delete then reload).
1935
+ */
1936
+ reloadFor(user) {
1937
+ const stored = this.usersByUid.get(user.uid);
1938
+ if (!stored) {
1939
+ throw makeAuthError('auth/user-token-expired', "The user's credential is no longer valid. The user must sign in again.");
1940
+ }
1941
+ this.applyStoredToUser(user, stored);
1942
+ if (this.cachedUser && this.cachedUser.uid === user.uid && this.cachedUser !== user) {
1943
+ this.applyStoredToUser(this.cachedUser, stored);
1944
+ }
1945
+ }
1946
+ /** Copy a stored record's mutable profile fields onto a live `User`
1947
+ * object in place. */
1948
+ applyStoredToUser(user, stored) {
1949
+ const m = user;
1950
+ m.email = stored.email;
1951
+ m.displayName = stored.displayName;
1952
+ m.photoURL = stored.photoUrl;
1953
+ m.emailVerified = stored.emailVerified;
1954
+ m.phoneNumber = stored.phoneNumber;
1955
+ }
1956
+ /** Live customClaims for a uid — the current value in the user DB,
1957
+ * falling back to `fallback` for uids the DB doesn't track (anonymous
1958
+ * / popup users). Used so a re-seed / `updateUser` is reflected in
1959
+ * held users' forced-refresh tokens (AUTH-B10). */
1960
+ liveClaims(uid, fallback) {
1961
+ return this.usersByUid.get(uid)?.customClaims ?? fallback;
1962
+ }
1963
+ /** Internal validator for email/password — checks the password
1964
+ * matches the stored record. Throws `auth/invalid-email` on a
1965
+ * malformed email, `auth/wrong-password` on mismatch,
1966
+ * `auth/user-not-found` if the email isn't seeded.
1967
+ *
1968
+ * Format validation fires BEFORE the user-DB lookup so callers
1969
+ * shipping malformed inputs see the same `auth/invalid-email`
1970
+ * prod returns — they wouldn't reach the missing-user path in
1971
+ * production either. Password-strength is NOT enforced on sign-in
1972
+ * (a previously-weak seeded password should still let the user
1973
+ * in); only `createUserWithEmailAndPassword` runs the strength
1974
+ * check, mirroring prod. */
1975
+ validatePassword(email, password) {
1976
+ validateEmailFormat(email);
1977
+ // Empty password → `auth/missing-password`, fired BEFORE the user-DB
1978
+ // lookup (same anti-enumeration ordering as the email check). Prod's
1979
+ // signInWithPassword returns the MISSING_PASSWORD server error, mapped
1980
+ // to `auth/missing-password` with message "A non-empty password must
1981
+ // be provided" (`core/errors.ts:92,282,563`) — NOT wrong-password /
1982
+ // user-not-found (AUTH-B11).
1983
+ if (typeof password !== 'string' || password.length === 0) {
1984
+ throw makeAuthError('auth/missing-password', 'A non-empty password must be provided');
1985
+ }
1986
+ const stored = this.findByEmail(email);
1987
+ if (!stored) {
1988
+ throw makeAuthError('auth/user-not-found', `No user found for ${email}.`);
1989
+ }
1990
+ // Disabled check BEFORE the password compare so a disabled
1991
+ // account can't be password-probed. Best-known semantics — the
1992
+ // exact prod ordering (disabled-vs-wrong-password) is flagged for
1993
+ // an oracle capture; the code (`auth/user-disabled`) and message
1994
+ // match prod's documented shape.
1995
+ if (stored.disabled) {
1996
+ throw makeAuthError('auth/user-disabled', 'The user account has been disabled by an administrator.');
1997
+ }
1998
+ if (stored.password !== password) {
1999
+ throw makeAuthError('auth/wrong-password', 'Invalid password.');
2000
+ }
2001
+ return stored;
2002
+ }
2003
+ }
2004
+ /** Re-exported from {@link ./auth-errors.ts} so consumers importing
2005
+ * `makeAuthError` from the `sandbox-backend` barrel keep working. */
2006
+ export { makeAuthError } from './auth-errors.js';
2007
+ //# sourceMappingURL=sandbox-backend.js.map