@almadar/shell-web 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundling.d.mts +18 -0
- package/bundling.mjs +28 -0
- package/dist/ArbitraryClassCompiler-CO_iASBn.d.ts +195 -0
- package/dist/AvlGlyph-EPJKFEO3.js +6 -0
- package/dist/AvlStateMachine-RKZIKNGC.js +9 -0
- package/dist/AvlTransitionDetail-63SD6GZF.js +11 -0
- package/dist/AvlTransitionExplainer-ZBTLOM3T.js +12 -0
- package/dist/BehaviorView-YS5G4GNB.js +11 -0
- package/dist/Canvas3DHost-BkZQB5l2.d.ts +552 -0
- package/dist/EventBusProvider-BFFHfN4O.d.ts +296 -0
- package/dist/FileTree-BCFnBEuQ.d.ts +254 -0
- package/dist/FlowCanvas-3JRMNJLV.css +1756 -0
- package/dist/FlowCanvas-AUMTWMNG.js +26 -0
- package/dist/GameAudioProvider-ceM_n0ey.d.ts +90 -0
- package/dist/KaTeX_AMS-Regular-CYEKBG2K.woff +0 -0
- package/dist/KaTeX_AMS-Regular-JKX5W2C4.ttf +0 -0
- package/dist/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
- package/dist/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
- package/dist/KaTeX_Caligraphic-Bold-WZ3QSGD3.woff +0 -0
- package/dist/KaTeX_Caligraphic-Bold-ZTS3R3HK.ttf +0 -0
- package/dist/KaTeX_Caligraphic-Regular-3LKEU76G.woff +0 -0
- package/dist/KaTeX_Caligraphic-Regular-A7XRTZ5Q.ttf +0 -0
- package/dist/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
- package/dist/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
- package/dist/KaTeX_Fraktur-Bold-T4SWXBMT.woff +0 -0
- package/dist/KaTeX_Fraktur-Bold-WGHVTYOR.ttf +0 -0
- package/dist/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
- package/dist/KaTeX_Fraktur-Regular-5U4OPH2X.ttf +0 -0
- package/dist/KaTeX_Fraktur-Regular-PQMHCIK6.woff +0 -0
- package/dist/KaTeX_Main-Bold-2GA4IZIN.woff +0 -0
- package/dist/KaTeX_Main-Bold-W5FBVCZM.ttf +0 -0
- package/dist/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
- package/dist/KaTeX_Main-BoldItalic-4P4C7HJH.woff +0 -0
- package/dist/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
- package/dist/KaTeX_Main-BoldItalic-ODMLBJJQ.ttf +0 -0
- package/dist/KaTeX_Main-Italic-I43T2HSR.ttf +0 -0
- package/dist/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
- package/dist/KaTeX_Main-Italic-SASNQFN2.woff +0 -0
- package/dist/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
- package/dist/KaTeX_Main-Regular-P5I74A2A.woff +0 -0
- package/dist/KaTeX_Main-Regular-W74P5G27.ttf +0 -0
- package/dist/KaTeX_Math-BoldItalic-6EBV3DK5.woff +0 -0
- package/dist/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
- package/dist/KaTeX_Math-BoldItalic-VB447A4D.ttf +0 -0
- package/dist/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
- package/dist/KaTeX_Math-Italic-KKK3USB2.woff +0 -0
- package/dist/KaTeX_Math-Italic-SON4MRCA.ttf +0 -0
- package/dist/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
- package/dist/KaTeX_SansSerif-Bold-STQ6RXC7.ttf +0 -0
- package/dist/KaTeX_SansSerif-Bold-X5M5EMOD.woff +0 -0
- package/dist/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
- package/dist/KaTeX_SansSerif-Italic-PSN4QKYX.woff +0 -0
- package/dist/KaTeX_SansSerif-Italic-WTBAZBGY.ttf +0 -0
- package/dist/KaTeX_SansSerif-Regular-2TL3USAE.ttf +0 -0
- package/dist/KaTeX_SansSerif-Regular-OQCII6EP.woff +0 -0
- package/dist/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
- package/dist/KaTeX_Script-Regular-72OLXYNA.ttf +0 -0
- package/dist/KaTeX_Script-Regular-A5IFOEBS.woff +0 -0
- package/dist/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
- package/dist/KaTeX_Size1-Regular-4HRHTS65.woff +0 -0
- package/dist/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
- package/dist/KaTeX_Size1-Regular-7K6AASVL.ttf +0 -0
- package/dist/KaTeX_Size2-Regular-222HN3GT.ttf +0 -0
- package/dist/KaTeX_Size2-Regular-K5ZHAIS6.woff +0 -0
- package/dist/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
- package/dist/KaTeX_Size3-Regular-TLFPAHDE.woff +0 -0
- package/dist/KaTeX_Size3-Regular-UFCO6WCA.ttf +0 -0
- package/dist/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
- package/dist/KaTeX_Size4-Regular-7PGNVPQK.ttf +0 -0
- package/dist/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
- package/dist/KaTeX_Size4-Regular-PKMWZHNC.woff +0 -0
- package/dist/KaTeX_Typewriter-Regular-3F5K6SQ6.ttf +0 -0
- package/dist/KaTeX_Typewriter-Regular-MJMFSK64.woff +0 -0
- package/dist/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
- package/dist/KernelEngineContext-CcxGYtlr.d.ts +33 -0
- package/dist/LayersPanel-M2LHWUFF.js +6 -0
- package/dist/ModuleCard-QHDGK5XK.js +7 -0
- package/dist/OrbInspector-MHLJ6OEE.css +1756 -0
- package/dist/OrbInspector-QCPEPUPH.js +26 -0
- package/dist/Select-B-iDdnvE.d.ts +185 -0
- package/dist/ServerBridge-Bqsj-lOU.d.ts +124 -0
- package/dist/ThemeContext-DJmO59xd.d.ts +147 -0
- package/dist/UISlotContext-Dl_ewwCI.d.ts +79 -0
- package/dist/UISlotRenderer-C7WWOK43.js +26 -0
- package/dist/UISlotRenderer-KVFO6J7R.css +1756 -0
- package/dist/auth/browser/index.d.ts +2 -0
- package/dist/auth/browser/index.js +2 -0
- package/dist/auth/react/index.d.ts +56 -0
- package/dist/auth/react/index.js +157 -0
- package/dist/avl/index.css +1756 -0
- package/dist/avl/index.d.ts +2248 -0
- package/dist/avl/index.js +2693 -0
- package/dist/avl-3d-context-BycmO6tG.d.ts +201 -0
- package/dist/avl-schema-parser-CtJxJ9KU.d.ts +132 -0
- package/dist/avl-zoom-state-CKMVuBFg.d.ts +17 -0
- package/dist/chunk-3BBUBJFF.js +339 -0
- package/dist/chunk-3S54FWRC.js +131 -0
- package/dist/chunk-3VZ36ZKO.js +775 -0
- package/dist/chunk-4T3P43NS.js +1133 -0
- package/dist/chunk-4YXBKHHM.js +11488 -0
- package/dist/chunk-57DC34LY.js +525 -0
- package/dist/chunk-5QTYQTPS.js +15 -0
- package/dist/chunk-A2LR6VQQ.js +349 -0
- package/dist/chunk-AB3X7QTE.js +505 -0
- package/dist/chunk-AE7VCQB6.js +561 -0
- package/dist/chunk-AGXD77SL.js +98 -0
- package/dist/chunk-AU7O65OX.js +66 -0
- package/dist/chunk-CPLN6NBQ.js +701 -0
- package/dist/chunk-DZBQA2OW.js +176 -0
- package/dist/chunk-E6KA4J6N.js +227 -0
- package/dist/chunk-EOWMARUB.js +16 -0
- package/dist/chunk-G7DCAZ22.js +19 -0
- package/dist/chunk-GFXCPUMX.js +1334 -0
- package/dist/chunk-HH5KSMH5.js +311 -0
- package/dist/chunk-ILQXJ2AR.js +280 -0
- package/dist/chunk-ILZ7ORX7.js +432 -0
- package/dist/chunk-K4MOPSEL.js +674 -0
- package/dist/chunk-LHP2TK7O.js +47587 -0
- package/dist/chunk-P4ZFUQFF.js +93 -0
- package/dist/chunk-PCR37T3U.js +296 -0
- package/dist/chunk-PRXQGGCO.js +580 -0
- package/dist/chunk-REXYVBUO.js +191 -0
- package/dist/chunk-ROICKAU7.js +24 -0
- package/dist/chunk-SP5CDJ6K.js +338 -0
- package/dist/chunk-TUPZWTRE.js +1051 -0
- package/dist/chunk-TXAUOLWZ.js +490 -0
- package/dist/chunk-TZZBINQY.js +82 -0
- package/dist/chunk-UTDC2NEA.js +14 -0
- package/dist/chunk-UU57VNS2.js +1053 -0
- package/dist/chunk-UXLE3IPR.js +421 -0
- package/dist/chunk-VO2TTLS5.js +94 -0
- package/dist/chunk-X3DMMX27.js +11 -0
- package/dist/chunk-YHMRX6YA.js +455 -0
- package/dist/components/index.css +1756 -0
- package/dist/components/index.d.ts +11299 -0
- package/dist/components/index.js +1110 -0
- package/dist/context/index.d.ts +8 -0
- package/dist/context/index.js +8 -0
- package/dist/core.d.ts +2599 -0
- package/dist/core.js +3 -0
- package/dist/design-classes/index.cjs +431 -0
- package/dist/design-classes/index.d.cts +165 -0
- package/dist/design-classes/index.d.ts +165 -0
- package/dist/design-classes/index.js +399 -0
- package/dist/emojiItems-QGSNAABW.js +20 -0
- package/dist/fx-CmQjnHmT.d.ts +371 -0
- package/dist/hooks/index.d.ts +971 -0
- package/dist/hooks/index.js +8 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +178 -0
- package/dist/katexPlugin-FA7NX4PE.css +1161 -0
- package/dist/katexPlugin-NCDKOOQY.js +2 -0
- package/dist/kernel-client-TZKGHJRY.js +516 -0
- package/dist/kernel-wire-wNdAPfhJ.d.ts +88 -0
- package/dist/lib/index.d.ts +602 -0
- package/dist/lib/index.js +1289 -0
- package/dist/paintDispatch-CuJLsr9Y.d.ts +688 -0
- package/dist/parseLessonSegments-GpCeMrb2.d.ts +334 -0
- package/dist/perf-CKiBKbkw.d.ts +22 -0
- package/dist/perf-Dr28-AgT.d.ts +57 -0
- package/dist/prism-X5YWKXO5.js +136 -0
- package/dist/providers/index.css +1756 -0
- package/dist/providers/index.d.ts +355 -0
- package/dist/providers/index.js +29 -0
- package/dist/renderer/index.d.ts +465 -0
- package/dist/renderer/index.js +4 -0
- package/dist/runtime/index.css +1756 -0
- package/dist/runtime/index.d.ts +239 -0
- package/dist/runtime/index.js +28 -0
- package/dist/slot-host-CPzrxLo9.d.ts +48 -0
- package/dist/ssr/index.cjs +9739 -0
- package/dist/ssr/index.d.cts +464 -0
- package/dist/ssr/index.d.ts +464 -0
- package/dist/ssr/index.js +9703 -0
- package/dist/storage/browser/index.d.ts +1 -0
- package/dist/storage/browser/index.js +2 -0
- package/dist/test-support.d.ts +42 -0
- package/dist/test-support.js +181 -0
- package/dist/themeTokens-CRd8AEDF.d.ts +125 -0
- package/dist/three/index.css +503 -0
- package/dist/three/index.d.ts +1185 -0
- package/dist/three/index.js +3908 -0
- package/dist/useUISlots-CiobNFGb.d.ts +211 -0
- package/dist/verification-C5pTeMJv.d.ts +66 -0
- package/dist/verificationRegistry-CVrcxG1s.d.ts +122 -0
- package/dist/wrapCallbackForEvent-B9QLbhxX.d.ts +19 -0
- package/index.css +199 -0
- package/package.json +273 -3
- package/src/core/lib/band-shapes.json +7 -0
- package/src/core/locales/ar.json +1276 -0
- package/src/core/locales/en.json +1276 -0
- package/src/core/locales/index.ts +54 -0
- package/src/core/locales/sl.json +1276 -0
- package/src/core/tokens/native-tokens.json +369 -0
- package/tailwind-compile.cjs +29 -0
- package/tailwind-preset.cjs +1020 -0
- package/themes/_base.css +451 -0
- package/themes/_contract.md +307 -0
- package/themes/_fonts-kenney.css +11 -0
- package/themes/_fonts.css +12 -0
- package/themes/_foundation.css +105 -0
- package/themes/_head.css +22 -0
- package/themes/_presets.css +67 -0
- package/themes/almadar-heritage.css +455 -0
- package/themes/almadar-website.css +269 -0
- package/themes/almadar.css +269 -0
- package/themes/aqua.css +455 -0
- package/themes/arabesque.css +459 -0
- package/themes/art-deco.css +457 -0
- package/themes/art-nouveau.css +459 -0
- package/themes/atelier.css +463 -0
- package/themes/bauhaus.css +461 -0
- package/themes/bloomberg-dense.css +463 -0
- package/themes/blueprint.css +457 -0
- package/themes/clay.css +449 -0
- package/themes/comic.css +453 -0
- package/themes/constructivist.css +457 -0
- package/themes/corporate.css +449 -0
- package/themes/cyberpunk.css +453 -0
- package/themes/frutiger-aero.css +458 -0
- package/themes/game-adventure.css +201 -0
- package/themes/game-rpg.css +203 -0
- package/themes/game-sci-fi.css +201 -0
- package/themes/game-ui-pack.css +200 -0
- package/themes/gazette.css +449 -0
- package/themes/glass.css +457 -0
- package/themes/gothic.css +453 -0
- package/themes/index.css +21 -0
- package/themes/ink-wash.css +459 -0
- package/themes/kawaii.css +459 -0
- package/themes/kflow.css +310 -0
- package/themes/kiosk.css +449 -0
- package/themes/linear-clean.css +463 -0
- package/themes/luxury.css +451 -0
- package/themes/mac-classic.css +455 -0
- package/themes/material.css +463 -0
- package/themes/memphis.css +453 -0
- package/themes/mid-century.css +455 -0
- package/themes/minimalist.css +449 -0
- package/themes/mudcloth.css +459 -0
- package/themes/nata.css +310 -0
- package/themes/neon.css +453 -0
- package/themes/neumorphic.css +451 -0
- package/themes/newsprint.css +455 -0
- package/themes/notion-editorial.css +463 -0
- package/themes/orb.css +465 -0
- package/themes/pixel.css +449 -0
- package/themes/prism.css +309 -0
- package/themes/rawi.css +310 -0
- package/themes/retro.css +452 -0
- package/themes/risograph.css +463 -0
- package/themes/scandi.css +469 -0
- package/themes/sketch.css +455 -0
- package/themes/solarpunk.css +469 -0
- package/themes/steampunk.css +451 -0
- package/themes/swiss.css +455 -0
- package/themes/terminal.css +466 -0
- package/themes/trait-wars.css +487 -0
- package/themes/ukiyo-e.css +459 -0
- package/themes/vaporwave.css +455 -0
- package/themes/victorian.css +453 -0
- package/themes/wabi-sabi.css +459 -0
- package/themes/win95.css +455 -0
- package/themes/wireframe.css +439 -0
- package/themes/zine.css +455 -0
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
import { ViewerAuthority, UserContext } from '@almadar/core';
|
|
3
|
+
import { BrowserAuth, SignedInUser } from '@almadar/shell-browser/auth';
|
|
4
|
+
export { BrowserAuth, SignedInUser } from '@almadar/shell-browser/auth';
|
|
5
|
+
import { HostSignInRequest, HostSignInAnswer } from '@almadar/shell-runtime/kernel/host';
|
|
6
|
+
|
|
7
|
+
/** The provider's resolved viewer authority — `@almadar/core`'s {@link ViewerAuthority}. */
|
|
8
|
+
type AuthAuthority = ViewerAuthority;
|
|
9
|
+
interface AuthContextValue {
|
|
10
|
+
/** The sign-in surface, or null when the app has no auth configured. */
|
|
11
|
+
auth: BrowserAuth | null;
|
|
12
|
+
user: SignedInUser | null;
|
|
13
|
+
authority: AuthAuthority;
|
|
14
|
+
/** An interactive auth action (or the initial connect) is in flight. */
|
|
15
|
+
loading: boolean;
|
|
16
|
+
/** The last interactive action's failure; a valid session survives it. */
|
|
17
|
+
error: string | null;
|
|
18
|
+
clearError(): void;
|
|
19
|
+
signInWithGoogle(): Promise<void>;
|
|
20
|
+
signInWithEmail(email: string, password: string): Promise<void>;
|
|
21
|
+
signUpWithEmail(email: string, password: string, displayName?: string): Promise<void>;
|
|
22
|
+
sendSignInLinkToEmail(email: string, returnUrl: string): Promise<void>;
|
|
23
|
+
isSignInWithEmailLink(link: string): boolean;
|
|
24
|
+
signInWithEmailLink(email: string, link: string): Promise<void>;
|
|
25
|
+
signInWithCustomToken(customToken: string): Promise<void>;
|
|
26
|
+
signOut(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
interface AuthProviderProps {
|
|
29
|
+
/** Connects the app's sign-in surface; resolves null when the app has no auth configured. */
|
|
30
|
+
connect: () => Promise<BrowserAuth | null>;
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
declare function AuthProvider({ connect, children }: AuthProviderProps): ReactElement;
|
|
34
|
+
/** The provider's value, or undefined outside an AuthProvider (an app with no sign-in surface). */
|
|
35
|
+
declare function useOptionalAuth(): AuthContextValue | undefined;
|
|
36
|
+
declare function useAuth(): AuthContextValue;
|
|
37
|
+
interface DevPersonas {
|
|
38
|
+
/** The app's `[identity]` rows; empty when the server offers no dev personas (no Auth emulator). */
|
|
39
|
+
personas: UserContext[];
|
|
40
|
+
signInAs(id: string): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The dev persona roster a program's `std-dev-personas` hooks offer (`personas`, `persona-sign-in`; they
|
|
44
|
+
* answer only while the server runs on the Auth emulator), and sign-in as one of them: a real emulated
|
|
45
|
+
* user, so `@user` resolves as in production.
|
|
46
|
+
*/
|
|
47
|
+
declare function useDevPersonas(apiBase: string): DevPersonas;
|
|
48
|
+
/**
|
|
49
|
+
* The host's `auth/sign-in` action over a connected Firebase auth: each method of the request is the one call the
|
|
50
|
+
* auth surface offers for it. A provider failure keeps the kind its code names (`FIREBASE_FAILURE_KIND`); a code the
|
|
51
|
+
* table does not list is `unavailable`.
|
|
52
|
+
*/
|
|
53
|
+
declare function hostSignIn(auth: BrowserAuth): (request: HostSignInRequest) => Promise<HostSignInAnswer>;
|
|
54
|
+
|
|
55
|
+
export { AuthProvider, hostSignIn, useAuth, useDevPersonas, useOptionalAuth };
|
|
56
|
+
export type { AuthAuthority, AuthContextValue, AuthProviderProps, DevPersonas };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import '../../chunk-G7DCAZ22.js';
|
|
3
|
+
import { createContext, useState, useEffect, useCallback, useMemo, useContext } from 'react';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { FieldValueSchema } from '@almadar/core';
|
|
6
|
+
import { HostAskError } from '@almadar/shell-runtime/kernel/host';
|
|
7
|
+
import { jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
var AuthContext = createContext(void 0);
|
|
10
|
+
var NOT_CONFIGURED = "Sign-in is not configured for this app";
|
|
11
|
+
function AuthProvider({ connect, children }) {
|
|
12
|
+
const [auth, setAuth] = useState(null);
|
|
13
|
+
const [user, setUser] = useState(null);
|
|
14
|
+
const [authority, setAuthority] = useState("pending");
|
|
15
|
+
const [loading, setLoading] = useState(true);
|
|
16
|
+
const [error, setError] = useState(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let unsubscribe;
|
|
19
|
+
let cancelled = false;
|
|
20
|
+
connect().then((connected) => {
|
|
21
|
+
if (cancelled) return;
|
|
22
|
+
setAuth(connected);
|
|
23
|
+
if (connected === null) {
|
|
24
|
+
setAuthority("unavailable");
|
|
25
|
+
setLoading(false);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
unsubscribe = connected.onUserChanged(
|
|
29
|
+
(next) => {
|
|
30
|
+
setUser(next);
|
|
31
|
+
setAuthority(next === null ? "anonymous" : "authenticated");
|
|
32
|
+
setLoading(false);
|
|
33
|
+
},
|
|
34
|
+
(err) => {
|
|
35
|
+
setUser(null);
|
|
36
|
+
setAuthority("failed");
|
|
37
|
+
setError(err.message);
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
if (cancelled) return;
|
|
43
|
+
setAuthority("failed");
|
|
44
|
+
setError(err.message);
|
|
45
|
+
setLoading(false);
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
cancelled = true;
|
|
49
|
+
unsubscribe?.();
|
|
50
|
+
};
|
|
51
|
+
}, [connect]);
|
|
52
|
+
const run = useCallback(async (action) => {
|
|
53
|
+
if (auth === null) {
|
|
54
|
+
setError(NOT_CONFIGURED);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setLoading(true);
|
|
58
|
+
setError(null);
|
|
59
|
+
try {
|
|
60
|
+
await action(auth);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
63
|
+
} finally {
|
|
64
|
+
setLoading(false);
|
|
65
|
+
}
|
|
66
|
+
}, [auth]);
|
|
67
|
+
const value = useMemo(() => ({
|
|
68
|
+
auth,
|
|
69
|
+
user,
|
|
70
|
+
authority,
|
|
71
|
+
loading,
|
|
72
|
+
error,
|
|
73
|
+
clearError: () => setError(null),
|
|
74
|
+
signInWithGoogle: () => run((a) => a.signInWithGoogle()),
|
|
75
|
+
signInWithEmail: (email, password) => run((a) => a.signInWithEmail(email, password)),
|
|
76
|
+
signUpWithEmail: (email, password, displayName) => run((a) => a.signUpWithEmail(email, password, displayName)),
|
|
77
|
+
sendSignInLinkToEmail: (email, returnUrl) => run((a) => a.sendSignInLinkToEmail(email, returnUrl)),
|
|
78
|
+
isSignInWithEmailLink: (link) => auth?.isSignInWithEmailLink(link) ?? false,
|
|
79
|
+
signInWithEmailLink: (email, link) => run((a) => a.signInWithEmailLink(email, link)),
|
|
80
|
+
signInWithCustomToken: (customToken) => run((a) => a.signInWithCustomToken(customToken)),
|
|
81
|
+
signOut: () => run((a) => a.signOut())
|
|
82
|
+
}), [auth, user, authority, loading, error, run]);
|
|
83
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
|
|
84
|
+
}
|
|
85
|
+
function useOptionalAuth() {
|
|
86
|
+
return useContext(AuthContext);
|
|
87
|
+
}
|
|
88
|
+
function useAuth() {
|
|
89
|
+
const value = useContext(AuthContext);
|
|
90
|
+
if (value === void 0) throw new Error("useAuth must be used within an AuthProvider");
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
var PersonasSchema = z.object({
|
|
94
|
+
success: z.literal(true),
|
|
95
|
+
personas: z.array(z.object({ id: z.string() }).catchall(FieldValueSchema))
|
|
96
|
+
});
|
|
97
|
+
var SignInSchema = z.object({ success: z.literal(true), customToken: z.string() });
|
|
98
|
+
function useDevPersonas(apiBase) {
|
|
99
|
+
const { signInWithCustomToken } = useAuth();
|
|
100
|
+
const [personas, setPersonas] = useState([]);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
let cancelled = false;
|
|
103
|
+
void fetch(`${apiBase}/api/hooks/personas`, { method: "POST", headers: { "Content-Type": "application/json" }, body: "{}" }).then(async (res) => res.ok ? PersonasSchema.parse(await res.json()).personas : []).then((list) => {
|
|
104
|
+
if (!cancelled) setPersonas(list);
|
|
105
|
+
});
|
|
106
|
+
return () => {
|
|
107
|
+
cancelled = true;
|
|
108
|
+
};
|
|
109
|
+
}, [apiBase]);
|
|
110
|
+
const signInAs = useCallback(async (id) => {
|
|
111
|
+
const res = await fetch(`${apiBase}/api/hooks/persona-sign-in`, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
114
|
+
body: JSON.stringify({ id })
|
|
115
|
+
});
|
|
116
|
+
await signInWithCustomToken(SignInSchema.parse(await res.json()).customToken);
|
|
117
|
+
}, [apiBase, signInWithCustomToken]);
|
|
118
|
+
return { personas, signInAs };
|
|
119
|
+
}
|
|
120
|
+
var FIREBASE_FAILURE_KIND = {
|
|
121
|
+
"auth/popup-closed-by-user": "cancelled",
|
|
122
|
+
"auth/cancelled-popup-request": "cancelled",
|
|
123
|
+
"auth/user-cancelled": "cancelled",
|
|
124
|
+
"auth/wrong-password": "denied",
|
|
125
|
+
"auth/invalid-credential": "denied",
|
|
126
|
+
"auth/user-not-found": "denied",
|
|
127
|
+
"auth/user-disabled": "denied",
|
|
128
|
+
"auth/popup-blocked": "denied",
|
|
129
|
+
"auth/invalid-email": "invalid",
|
|
130
|
+
"auth/invalid-custom-token": "invalid",
|
|
131
|
+
"auth/invalid-action-code": "invalid",
|
|
132
|
+
"auth/expired-action-code": "invalid",
|
|
133
|
+
"auth/network-request-failed": "unavailable",
|
|
134
|
+
"auth/operation-not-allowed": "unavailable"
|
|
135
|
+
};
|
|
136
|
+
function userAnswer(user) {
|
|
137
|
+
return { uid: user.uid, ...user.email !== void 0 ? { email: user.email } : {}, ...user.name !== void 0 ? { displayName: user.name } : {} };
|
|
138
|
+
}
|
|
139
|
+
function hostSignIn(auth) {
|
|
140
|
+
return async (request) => {
|
|
141
|
+
try {
|
|
142
|
+
if (request.method === "google") return userAnswer(await auth.signInWithGoogle());
|
|
143
|
+
if (request.method === "email") return userAnswer(await auth.signInWithEmail(request.email, request.password));
|
|
144
|
+
if (request.method === "customToken") return userAnswer(await auth.signInWithCustomToken(request.token));
|
|
145
|
+
if ("continueUrl" in request) {
|
|
146
|
+
await auth.sendSignInLinkToEmail(request.email, request.continueUrl);
|
|
147
|
+
return { sent: true };
|
|
148
|
+
}
|
|
149
|
+
return userAnswer(await auth.signInWithEmailLink(request.email, request.link));
|
|
150
|
+
} catch (error) {
|
|
151
|
+
const code = typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
152
|
+
throw new HostAskError(code !== void 0 ? FIREBASE_FAILURE_KIND[code] ?? "unavailable" : "unavailable", error instanceof Error ? error.message : String(error));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { AuthProvider, hostSignIn, useAuth, useDevPersonas, useOptionalAuth };
|