@prabhask5/stellar-engine 1.1.7 → 1.1.8
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/README.md +4 -1
- package/dist/actions/remoteChange.d.ts +143 -18
- package/dist/actions/remoteChange.d.ts.map +1 -1
- package/dist/actions/remoteChange.js +182 -58
- package/dist/actions/remoteChange.js.map +1 -1
- package/dist/actions/truncateTooltip.d.ts +26 -12
- package/dist/actions/truncateTooltip.d.ts.map +1 -1
- package/dist/actions/truncateTooltip.js +89 -34
- package/dist/actions/truncateTooltip.js.map +1 -1
- package/dist/auth/admin.d.ts +40 -3
- package/dist/auth/admin.d.ts.map +1 -1
- package/dist/auth/admin.js +45 -5
- package/dist/auth/admin.js.map +1 -1
- package/dist/auth/crypto.d.ts +55 -5
- package/dist/auth/crypto.d.ts.map +1 -1
- package/dist/auth/crypto.js +58 -5
- package/dist/auth/crypto.js.map +1 -1
- package/dist/auth/deviceVerification.d.ts +236 -20
- package/dist/auth/deviceVerification.d.ts.map +1 -1
- package/dist/auth/deviceVerification.js +293 -40
- package/dist/auth/deviceVerification.js.map +1 -1
- package/dist/auth/displayUtils.d.ts +98 -0
- package/dist/auth/displayUtils.d.ts.map +1 -0
- package/dist/auth/displayUtils.js +133 -0
- package/dist/auth/displayUtils.js.map +1 -0
- package/dist/auth/loginGuard.d.ts +108 -14
- package/dist/auth/loginGuard.d.ts.map +1 -1
- package/dist/auth/loginGuard.js +153 -31
- package/dist/auth/loginGuard.js.map +1 -1
- package/dist/auth/offlineCredentials.d.ts +132 -15
- package/dist/auth/offlineCredentials.d.ts.map +1 -1
- package/dist/auth/offlineCredentials.js +167 -23
- package/dist/auth/offlineCredentials.js.map +1 -1
- package/dist/auth/offlineLogin.d.ts +96 -10
- package/dist/auth/offlineLogin.d.ts.map +1 -1
- package/dist/auth/offlineLogin.js +82 -15
- package/dist/auth/offlineLogin.js.map +1 -1
- package/dist/auth/offlineSession.d.ts +83 -9
- package/dist/auth/offlineSession.d.ts.map +1 -1
- package/dist/auth/offlineSession.js +104 -13
- package/dist/auth/offlineSession.js.map +1 -1
- package/dist/auth/resolveAuthState.d.ts +70 -8
- package/dist/auth/resolveAuthState.d.ts.map +1 -1
- package/dist/auth/resolveAuthState.js +142 -46
- package/dist/auth/resolveAuthState.js.map +1 -1
- package/dist/auth/singleUser.d.ts +390 -37
- package/dist/auth/singleUser.d.ts.map +1 -1
- package/dist/auth/singleUser.js +500 -99
- package/dist/auth/singleUser.js.map +1 -1
- package/dist/bin/install-pwa.d.ts +18 -2
- package/dist/bin/install-pwa.d.ts.map +1 -1
- package/dist/bin/install-pwa.js +801 -25
- package/dist/bin/install-pwa.js.map +1 -1
- package/dist/config.d.ts +132 -12
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +87 -9
- package/dist/config.js.map +1 -1
- package/dist/conflicts.d.ts +246 -23
- package/dist/conflicts.d.ts.map +1 -1
- package/dist/conflicts.js +495 -46
- package/dist/conflicts.js.map +1 -1
- package/dist/data.d.ts +338 -18
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +385 -34
- package/dist/data.js.map +1 -1
- package/dist/database.d.ts +72 -14
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +120 -29
- package/dist/database.js.map +1 -1
- package/dist/debug.d.ts +77 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/debug.js +88 -1
- package/dist/debug.js.map +1 -1
- package/dist/deviceId.d.ts +38 -7
- package/dist/deviceId.d.ts.map +1 -1
- package/dist/deviceId.js +68 -10
- package/dist/deviceId.js.map +1 -1
- package/dist/engine.d.ts +175 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +756 -109
- package/dist/engine.js.map +1 -1
- package/dist/entries/actions.d.ts +13 -0
- package/dist/entries/actions.d.ts.map +1 -1
- package/dist/entries/actions.js +26 -1
- package/dist/entries/actions.js.map +1 -1
- package/dist/entries/auth.d.ts +16 -0
- package/dist/entries/auth.d.ts.map +1 -1
- package/dist/entries/auth.js +73 -1
- package/dist/entries/auth.js.map +1 -1
- package/dist/entries/config.d.ts +12 -0
- package/dist/entries/config.d.ts.map +1 -1
- package/dist/entries/config.js +18 -1
- package/dist/entries/config.js.map +1 -1
- package/dist/entries/kit.d.ts +11 -0
- package/dist/entries/kit.d.ts.map +1 -1
- package/dist/entries/kit.js +52 -2
- package/dist/entries/kit.js.map +1 -1
- package/dist/entries/stores.d.ts +11 -0
- package/dist/entries/stores.d.ts.map +1 -1
- package/dist/entries/stores.js +43 -2
- package/dist/entries/stores.js.map +1 -1
- package/dist/entries/types.d.ts +10 -0
- package/dist/entries/types.d.ts.map +1 -1
- package/dist/entries/types.js +10 -0
- package/dist/entries/types.js.map +1 -1
- package/dist/entries/utils.d.ts +6 -0
- package/dist/entries/utils.d.ts.map +1 -1
- package/dist/entries/utils.js +22 -1
- package/dist/entries/utils.js.map +1 -1
- package/dist/entries/vite.d.ts +17 -0
- package/dist/entries/vite.d.ts.map +1 -1
- package/dist/entries/vite.js +24 -1
- package/dist/entries/vite.js.map +1 -1
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -20
- package/dist/index.js.map +1 -1
- package/dist/kit/auth.d.ts +60 -5
- package/dist/kit/auth.d.ts.map +1 -1
- package/dist/kit/auth.js +45 -4
- package/dist/kit/auth.js.map +1 -1
- package/dist/kit/confirm.d.ts +93 -12
- package/dist/kit/confirm.d.ts.map +1 -1
- package/dist/kit/confirm.js +103 -16
- package/dist/kit/confirm.js.map +1 -1
- package/dist/kit/loads.d.ts +150 -23
- package/dist/kit/loads.d.ts.map +1 -1
- package/dist/kit/loads.js +140 -24
- package/dist/kit/loads.js.map +1 -1
- package/dist/kit/server.d.ts +142 -10
- package/dist/kit/server.d.ts.map +1 -1
- package/dist/kit/server.js +158 -15
- package/dist/kit/server.js.map +1 -1
- package/dist/kit/sw.d.ts +152 -23
- package/dist/kit/sw.d.ts.map +1 -1
- package/dist/kit/sw.js +182 -26
- package/dist/kit/sw.js.map +1 -1
- package/dist/queue.d.ts +274 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +556 -38
- package/dist/queue.js.map +1 -1
- package/dist/realtime.d.ts +241 -27
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +633 -109
- package/dist/realtime.js.map +1 -1
- package/dist/runtime/runtimeConfig.d.ts +91 -8
- package/dist/runtime/runtimeConfig.d.ts.map +1 -1
- package/dist/runtime/runtimeConfig.js +146 -19
- package/dist/runtime/runtimeConfig.js.map +1 -1
- package/dist/stores/authState.d.ts +150 -11
- package/dist/stores/authState.d.ts.map +1 -1
- package/dist/stores/authState.js +169 -17
- package/dist/stores/authState.js.map +1 -1
- package/dist/stores/network.d.ts +39 -0
- package/dist/stores/network.d.ts.map +1 -1
- package/dist/stores/network.js +169 -16
- package/dist/stores/network.js.map +1 -1
- package/dist/stores/remoteChanges.d.ts +327 -52
- package/dist/stores/remoteChanges.d.ts.map +1 -1
- package/dist/stores/remoteChanges.js +337 -75
- package/dist/stores/remoteChanges.js.map +1 -1
- package/dist/stores/sync.d.ts +130 -0
- package/dist/stores/sync.d.ts.map +1 -1
- package/dist/stores/sync.js +167 -7
- package/dist/stores/sync.js.map +1 -1
- package/dist/supabase/auth.d.ts +325 -18
- package/dist/supabase/auth.d.ts.map +1 -1
- package/dist/supabase/auth.js +374 -26
- package/dist/supabase/auth.js.map +1 -1
- package/dist/supabase/client.d.ts +79 -6
- package/dist/supabase/client.d.ts.map +1 -1
- package/dist/supabase/client.js +158 -15
- package/dist/supabase/client.js.map +1 -1
- package/dist/supabase/validate.d.ts +101 -7
- package/dist/supabase/validate.d.ts.map +1 -1
- package/dist/supabase/validate.js +117 -8
- package/dist/supabase/validate.js.map +1 -1
- package/dist/sw/build/vite-plugin.d.ts +55 -10
- package/dist/sw/build/vite-plugin.d.ts.map +1 -1
- package/dist/sw/build/vite-plugin.js +77 -18
- package/dist/sw/build/vite-plugin.js.map +1 -1
- package/dist/sw/sw.js +99 -44
- package/dist/types.d.ts +150 -26
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +12 -10
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +55 -13
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +83 -22
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/kit/loads.d.ts
CHANGED
|
@@ -1,46 +1,147 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview SvelteKit load function helpers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* scaffolded routes can be thin wrappers around these helpers.
|
|
4
|
+
* This module extracts orchestration logic from layout and page load functions
|
|
5
|
+
* so that scaffolded routes can be thin wrappers around these helpers. Each
|
|
6
|
+
* exported function encapsulates a specific load concern:
|
|
7
|
+
*
|
|
8
|
+
* - `resolveRootLayout` — full app initialization sequence (config,
|
|
9
|
+
* auth, sync engine startup)
|
|
10
|
+
* - `resolveProtectedLayout` — auth guard for protected route groups
|
|
11
|
+
* - `resolveSetupAccess` — access control for the `/setup` wizard
|
|
12
|
+
*
|
|
13
|
+
* By centralizing this logic in the engine, consuming apps avoid duplicating
|
|
14
|
+
* the initialization ordering and redirect logic across their route tree.
|
|
15
|
+
*
|
|
16
|
+
* @module kit/loads
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // In +layout.ts (root)
|
|
21
|
+
* import { resolveRootLayout } from 'stellar-engine/kit/loads';
|
|
22
|
+
* export async function load({ url }) {
|
|
23
|
+
* return resolveRootLayout(url);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see {@link initConfig} for runtime configuration bootstrap
|
|
28
|
+
* @see {@link resolveAuthState} for auth mode determination
|
|
29
|
+
* @see {@link startSyncEngine} for offline-first sync initialization
|
|
6
30
|
*/
|
|
7
31
|
import type { AuthStateResult } from '../auth/resolveAuthState.js';
|
|
8
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Data returned by `resolveRootLayout`.
|
|
34
|
+
*
|
|
35
|
+
* Extends the base auth state with an optional `singleUserSetUp` flag
|
|
36
|
+
* indicating whether the app has completed initial configuration.
|
|
37
|
+
*/
|
|
9
38
|
export interface RootLayoutData extends AuthStateResult {
|
|
39
|
+
/**
|
|
40
|
+
* Indicates whether the single-user setup wizard has been completed.
|
|
41
|
+
* When `false` and no config exists, the app should redirect to `/setup`.
|
|
42
|
+
*/
|
|
10
43
|
singleUserSetUp?: boolean;
|
|
11
44
|
}
|
|
12
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Data returned by `resolveProtectedLayout`.
|
|
47
|
+
*
|
|
48
|
+
* A narrowed subset of auth state fields needed by protected route groups
|
|
49
|
+
* to render authenticated content.
|
|
50
|
+
*/
|
|
13
51
|
export interface ProtectedLayoutData {
|
|
52
|
+
/** The Supabase session, or `null` if using offline/no auth. */
|
|
14
53
|
session: AuthStateResult['session'];
|
|
54
|
+
/** The active authentication mode discriminator. */
|
|
15
55
|
authMode: AuthStateResult['authMode'];
|
|
56
|
+
/** The offline profile credentials, if in offline mode. */
|
|
16
57
|
offlineProfile: AuthStateResult['offlineProfile'];
|
|
17
58
|
}
|
|
18
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Data returned by `resolveSetupAccess`.
|
|
61
|
+
*
|
|
62
|
+
* Tells the setup page whether this is a first-time configuration
|
|
63
|
+
* (public access) or a reconfiguration (admin-only).
|
|
64
|
+
*/
|
|
19
65
|
export interface SetupAccessData {
|
|
66
|
+
/**
|
|
67
|
+
* `true` when no configuration exists yet — the setup page should
|
|
68
|
+
* render the full first-time wizard without requiring authentication.
|
|
69
|
+
*/
|
|
20
70
|
isFirstSetup: boolean;
|
|
21
71
|
}
|
|
22
72
|
/**
|
|
23
|
-
* Orchestrates the root layout load sequence
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
73
|
+
* Orchestrates the root layout load sequence, which is the critical
|
|
74
|
+
* initialization path that runs on every page load:
|
|
75
|
+
*
|
|
76
|
+
* 1. Calls the app's `initEngine` function (for database schema setup)
|
|
77
|
+
* 2. Runs `initConfig()` — loads runtime config from storage; if no
|
|
78
|
+
* config exists and the user is not already on `/setup`, returns a
|
|
79
|
+
* blank state so the layout can redirect to the setup wizard
|
|
80
|
+
* 3. Resolves auth state — determines whether the user is authenticated
|
|
81
|
+
* via Supabase, offline credentials, or not at all
|
|
82
|
+
* 4. Starts the sync engine if the user is authenticated, enabling
|
|
83
|
+
* offline-first data synchronization
|
|
84
|
+
*
|
|
85
|
+
* @param url - The current page URL object. Only `pathname` is
|
|
86
|
+
* inspected, to detect whether the user is already
|
|
87
|
+
* on the `/setup` page.
|
|
88
|
+
* @param _initEngineFn - (Optional) The app's `initEngine()` call, executed
|
|
89
|
+
* before config init. Typically already called at
|
|
90
|
+
* module scope in the browser; this parameter exists
|
|
91
|
+
* for explicit invocation in SSR contexts.
|
|
92
|
+
*
|
|
93
|
+
* @returns Layout data containing session, auth mode, offline profile,
|
|
94
|
+
* and setup status. The consuming layout uses these to hydrate
|
|
95
|
+
* the auth store and conditionally render the app shell.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // +layout.ts
|
|
100
|
+
* export async function load({ url }) {
|
|
101
|
+
* return resolveRootLayout(url);
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @see {@link RootLayoutData} for the return type shape
|
|
106
|
+
* @see {@link initConfig} for config bootstrapping details
|
|
107
|
+
* @see {@link resolveAuthState} for auth resolution logic
|
|
33
108
|
*/
|
|
34
109
|
export declare function resolveRootLayout(url: {
|
|
35
110
|
pathname: string;
|
|
36
111
|
}, _initEngineFn?: () => void): Promise<RootLayoutData>;
|
|
37
112
|
/**
|
|
38
|
-
* Auth guard for protected routes. Resolves auth state and
|
|
39
|
-
* redirect
|
|
113
|
+
* Auth guard for protected routes. Resolves auth state and, if the user
|
|
114
|
+
* is unauthenticated, computes a redirect URL to the login page with a
|
|
115
|
+
* `redirect` query parameter so the user can be sent back after login.
|
|
116
|
+
*
|
|
117
|
+
* The caller is responsible for performing the actual redirect (typically
|
|
118
|
+
* via SvelteKit's `throw redirect(302, redirectUrl)`), since this helper
|
|
119
|
+
* is framework-agnostic in its return value.
|
|
120
|
+
*
|
|
121
|
+
* @param url - The current page URL object with `pathname` and `search`
|
|
122
|
+
* properties, used to construct the post-login return URL.
|
|
40
123
|
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
*
|
|
124
|
+
* @returns An object containing:
|
|
125
|
+
* - `data` — the auth state payload for the layout
|
|
126
|
+
* - `redirectUrl` — a login URL string if unauthenticated, or `null`
|
|
127
|
+
* if the user is authenticated and should proceed normally.
|
|
128
|
+
* When non-null, the caller should `throw redirect(302, redirectUrl)`.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* // /(protected)/+layout.ts
|
|
133
|
+
* import { redirect } from '@sveltejs/kit';
|
|
134
|
+
* import { resolveProtectedLayout } from 'stellar-engine/kit/loads';
|
|
135
|
+
*
|
|
136
|
+
* export async function load({ url }) {
|
|
137
|
+
* const { data, redirectUrl } = await resolveProtectedLayout(url);
|
|
138
|
+
* if (redirectUrl) throw redirect(302, redirectUrl);
|
|
139
|
+
* return data;
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @see {@link ProtectedLayoutData} for the return data shape
|
|
144
|
+
* @see {@link resolveAuthState} for the underlying auth resolution
|
|
44
145
|
*/
|
|
45
146
|
export declare function resolveProtectedLayout(url: {
|
|
46
147
|
pathname: string;
|
|
@@ -50,10 +151,36 @@ export declare function resolveProtectedLayout(url: {
|
|
|
50
151
|
redirectUrl: string | null;
|
|
51
152
|
}>;
|
|
52
153
|
/**
|
|
53
|
-
* Setup page guard
|
|
154
|
+
* Setup page guard implementing a two-tier access model:
|
|
155
|
+
*
|
|
156
|
+
* - **Unconfigured app** (first-time setup): public access, no auth required.
|
|
157
|
+
* Returns `{ isFirstSetup: true }`.
|
|
158
|
+
* - **Configured app** (reconfiguration): only authenticated admin users
|
|
159
|
+
* may access. Non-admins are redirected to `/`, unauthenticated users
|
|
160
|
+
* to `/login`.
|
|
161
|
+
*
|
|
162
|
+
* @returns An object containing:
|
|
163
|
+
* - `data` — setup access info (`{ isFirstSetup }`)
|
|
164
|
+
* - `redirectUrl` — a redirect path if the user lacks access, or `null`
|
|
165
|
+
* if access is granted. When non-null, the caller should
|
|
166
|
+
* `throw redirect(302, redirectUrl)`.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* // /setup/+page.ts
|
|
171
|
+
* import { redirect } from '@sveltejs/kit';
|
|
172
|
+
* import { resolveSetupAccess } from 'stellar-engine/kit/loads';
|
|
173
|
+
*
|
|
174
|
+
* export async function load() {
|
|
175
|
+
* const { data, redirectUrl } = await resolveSetupAccess();
|
|
176
|
+
* if (redirectUrl) throw redirect(302, redirectUrl);
|
|
177
|
+
* return data;
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
54
180
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
181
|
+
* @see {@link SetupAccessData} for the return data shape
|
|
182
|
+
* @see {@link getConfig} for checking whether config exists
|
|
183
|
+
* @see {@link isAdmin} for admin role verification
|
|
57
184
|
*/
|
|
58
185
|
export declare function resolveSetupAccess(): Promise<{
|
|
59
186
|
data: SetupAccessData;
|
package/dist/kit/loads.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loads.d.ts","sourceRoot":"","sources":["../../src/kit/loads.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loads.d.ts","sourceRoot":"","sources":["../../src/kit/loads.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAOH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAMnE;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAEpC,oDAAoD;IACpD,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;IAEtC,2DAA2D;IAC3D,cAAc,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,YAAY,EAAE,OAAO,CAAC;CACvB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EACzB,aAAa,CAAC,EAAE,MAAM,IAAI,GACzB,OAAO,CAAC,cAAc,CAAC,CA4BzB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAgBrE;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC;IAClD,IAAI,EAAE,eAAe,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC,CAsBD"}
|
package/dist/kit/loads.js
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview SvelteKit load function helpers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* scaffolded routes can be thin wrappers around these helpers.
|
|
4
|
+
* This module extracts orchestration logic from layout and page load functions
|
|
5
|
+
* so that scaffolded routes can be thin wrappers around these helpers. Each
|
|
6
|
+
* exported function encapsulates a specific load concern:
|
|
7
|
+
*
|
|
8
|
+
* - `resolveRootLayout` — full app initialization sequence (config,
|
|
9
|
+
* auth, sync engine startup)
|
|
10
|
+
* - `resolveProtectedLayout` — auth guard for protected route groups
|
|
11
|
+
* - `resolveSetupAccess` — access control for the `/setup` wizard
|
|
12
|
+
*
|
|
13
|
+
* By centralizing this logic in the engine, consuming apps avoid duplicating
|
|
14
|
+
* the initialization ordering and redirect logic across their route tree.
|
|
15
|
+
*
|
|
16
|
+
* @module kit/loads
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // In +layout.ts (root)
|
|
21
|
+
* import { resolveRootLayout } from 'stellar-engine/kit/loads';
|
|
22
|
+
* export async function load({ url }) {
|
|
23
|
+
* return resolveRootLayout(url);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see {@link initConfig} for runtime configuration bootstrap
|
|
28
|
+
* @see {@link resolveAuthState} for auth mode determination
|
|
29
|
+
* @see {@link startSyncEngine} for offline-first sync initialization
|
|
6
30
|
*/
|
|
7
31
|
import { initConfig, getConfig } from '../runtime/runtimeConfig.js';
|
|
8
32
|
import { resolveAuthState } from '../auth/resolveAuthState.js';
|
|
@@ -13,30 +37,61 @@ import { isAdmin } from '../auth/admin.js';
|
|
|
13
37
|
// ROOT LAYOUT
|
|
14
38
|
// =============================================================================
|
|
15
39
|
/**
|
|
16
|
-
* Orchestrates the root layout load sequence
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
40
|
+
* Orchestrates the root layout load sequence, which is the critical
|
|
41
|
+
* initialization path that runs on every page load:
|
|
42
|
+
*
|
|
43
|
+
* 1. Calls the app's `initEngine` function (for database schema setup)
|
|
44
|
+
* 2. Runs `initConfig()` — loads runtime config from storage; if no
|
|
45
|
+
* config exists and the user is not already on `/setup`, returns a
|
|
46
|
+
* blank state so the layout can redirect to the setup wizard
|
|
47
|
+
* 3. Resolves auth state — determines whether the user is authenticated
|
|
48
|
+
* via Supabase, offline credentials, or not at all
|
|
49
|
+
* 4. Starts the sync engine if the user is authenticated, enabling
|
|
50
|
+
* offline-first data synchronization
|
|
51
|
+
*
|
|
52
|
+
* @param url - The current page URL object. Only `pathname` is
|
|
53
|
+
* inspected, to detect whether the user is already
|
|
54
|
+
* on the `/setup` page.
|
|
55
|
+
* @param _initEngineFn - (Optional) The app's `initEngine()` call, executed
|
|
56
|
+
* before config init. Typically already called at
|
|
57
|
+
* module scope in the browser; this parameter exists
|
|
58
|
+
* for explicit invocation in SSR contexts.
|
|
59
|
+
*
|
|
60
|
+
* @returns Layout data containing session, auth mode, offline profile,
|
|
61
|
+
* and setup status. The consuming layout uses these to hydrate
|
|
62
|
+
* the auth store and conditionally render the app shell.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* // +layout.ts
|
|
67
|
+
* export async function load({ url }) {
|
|
68
|
+
* return resolveRootLayout(url);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @see {@link RootLayoutData} for the return type shape
|
|
73
|
+
* @see {@link initConfig} for config bootstrapping details
|
|
74
|
+
* @see {@link resolveAuthState} for auth resolution logic
|
|
26
75
|
*/
|
|
27
76
|
export async function resolveRootLayout(url, _initEngineFn) {
|
|
28
77
|
const config = await initConfig();
|
|
29
|
-
|
|
78
|
+
/* No config yet — this is a first-time user. Return blank state so the
|
|
79
|
+
layout can detect `singleUserSetUp === false` and redirect to /setup.
|
|
80
|
+
We skip the redirect if already on /setup to avoid an infinite loop. */
|
|
30
81
|
if (!config && url.pathname !== '/setup') {
|
|
31
82
|
return { session: null, authMode: 'none', offlineProfile: null, singleUserSetUp: false };
|
|
32
83
|
}
|
|
33
|
-
|
|
84
|
+
/* Still on setup page with no config — return blank state without
|
|
85
|
+
redirecting, allowing the setup wizard to render normally. */
|
|
34
86
|
if (!config) {
|
|
35
87
|
return { session: null, authMode: 'none', offlineProfile: null, singleUserSetUp: false };
|
|
36
88
|
}
|
|
37
|
-
|
|
89
|
+
/* Resolve auth — determines Supabase / offline / none based on the
|
|
90
|
+
stored runtime config and available credentials. */
|
|
38
91
|
const result = await resolveAuthState();
|
|
39
|
-
|
|
92
|
+
/* Start sync engine only when the user is actually authenticated;
|
|
93
|
+
the engine requires auth context to connect to the remote database
|
|
94
|
+
or initialize the local-first storage layer. */
|
|
40
95
|
if (result.authMode !== 'none') {
|
|
41
96
|
await startSyncEngine();
|
|
42
97
|
}
|
|
@@ -46,16 +101,45 @@ export async function resolveRootLayout(url, _initEngineFn) {
|
|
|
46
101
|
// PROTECTED LAYOUT
|
|
47
102
|
// =============================================================================
|
|
48
103
|
/**
|
|
49
|
-
* Auth guard for protected routes. Resolves auth state and
|
|
50
|
-
* redirect
|
|
104
|
+
* Auth guard for protected routes. Resolves auth state and, if the user
|
|
105
|
+
* is unauthenticated, computes a redirect URL to the login page with a
|
|
106
|
+
* `redirect` query parameter so the user can be sent back after login.
|
|
51
107
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
108
|
+
* The caller is responsible for performing the actual redirect (typically
|
|
109
|
+
* via SvelteKit's `throw redirect(302, redirectUrl)`), since this helper
|
|
110
|
+
* is framework-agnostic in its return value.
|
|
111
|
+
*
|
|
112
|
+
* @param url - The current page URL object with `pathname` and `search`
|
|
113
|
+
* properties, used to construct the post-login return URL.
|
|
114
|
+
*
|
|
115
|
+
* @returns An object containing:
|
|
116
|
+
* - `data` — the auth state payload for the layout
|
|
117
|
+
* - `redirectUrl` — a login URL string if unauthenticated, or `null`
|
|
118
|
+
* if the user is authenticated and should proceed normally.
|
|
119
|
+
* When non-null, the caller should `throw redirect(302, redirectUrl)`.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* // /(protected)/+layout.ts
|
|
124
|
+
* import { redirect } from '@sveltejs/kit';
|
|
125
|
+
* import { resolveProtectedLayout } from 'stellar-engine/kit/loads';
|
|
126
|
+
*
|
|
127
|
+
* export async function load({ url }) {
|
|
128
|
+
* const { data, redirectUrl } = await resolveProtectedLayout(url);
|
|
129
|
+
* if (redirectUrl) throw redirect(302, redirectUrl);
|
|
130
|
+
* return data;
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @see {@link ProtectedLayoutData} for the return data shape
|
|
135
|
+
* @see {@link resolveAuthState} for the underlying auth resolution
|
|
55
136
|
*/
|
|
56
137
|
export async function resolveProtectedLayout(url) {
|
|
57
138
|
const result = await resolveAuthState();
|
|
58
139
|
if (result.authMode === 'none') {
|
|
140
|
+
/* Build a return URL so the login page can redirect back after
|
|
141
|
+
successful authentication. Skip the redirect param if the user
|
|
142
|
+
is at the root — there's no meaningful "return to" destination. */
|
|
59
143
|
const returnUrl = url.pathname + url.search;
|
|
60
144
|
const loginUrl = returnUrl && returnUrl !== '/'
|
|
61
145
|
? `/login?redirect=${encodeURIComponent(returnUrl)}`
|
|
@@ -68,20 +152,52 @@ export async function resolveProtectedLayout(url) {
|
|
|
68
152
|
// SETUP ACCESS
|
|
69
153
|
// =============================================================================
|
|
70
154
|
/**
|
|
71
|
-
* Setup page guard
|
|
155
|
+
* Setup page guard implementing a two-tier access model:
|
|
156
|
+
*
|
|
157
|
+
* - **Unconfigured app** (first-time setup): public access, no auth required.
|
|
158
|
+
* Returns `{ isFirstSetup: true }`.
|
|
159
|
+
* - **Configured app** (reconfiguration): only authenticated admin users
|
|
160
|
+
* may access. Non-admins are redirected to `/`, unauthenticated users
|
|
161
|
+
* to `/login`.
|
|
162
|
+
*
|
|
163
|
+
* @returns An object containing:
|
|
164
|
+
* - `data` — setup access info (`{ isFirstSetup }`)
|
|
165
|
+
* - `redirectUrl` — a redirect path if the user lacks access, or `null`
|
|
166
|
+
* if access is granted. When non-null, the caller should
|
|
167
|
+
* `throw redirect(302, redirectUrl)`.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* // /setup/+page.ts
|
|
172
|
+
* import { redirect } from '@sveltejs/kit';
|
|
173
|
+
* import { resolveSetupAccess } from 'stellar-engine/kit/loads';
|
|
174
|
+
*
|
|
175
|
+
* export async function load() {
|
|
176
|
+
* const { data, redirectUrl } = await resolveSetupAccess();
|
|
177
|
+
* if (redirectUrl) throw redirect(302, redirectUrl);
|
|
178
|
+
* return data;
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
72
181
|
*
|
|
73
|
-
* @
|
|
74
|
-
*
|
|
182
|
+
* @see {@link SetupAccessData} for the return data shape
|
|
183
|
+
* @see {@link getConfig} for checking whether config exists
|
|
184
|
+
* @see {@link isAdmin} for admin role verification
|
|
75
185
|
*/
|
|
76
186
|
export async function resolveSetupAccess() {
|
|
187
|
+
/* No config exists — this is the first-time setup, grant public access
|
|
188
|
+
so the wizard can run without requiring authentication. */
|
|
77
189
|
if (!getConfig()) {
|
|
78
190
|
return { data: { isFirstSetup: true }, redirectUrl: null };
|
|
79
191
|
}
|
|
192
|
+
/* Config exists — this is a reconfiguration. Require a valid session. */
|
|
80
193
|
const session = await getValidSession();
|
|
81
194
|
if (!session?.user) {
|
|
195
|
+
/* No session — redirect to login so the user can authenticate first. */
|
|
82
196
|
return { data: { isFirstSetup: false }, redirectUrl: '/login' };
|
|
83
197
|
}
|
|
84
198
|
if (!isAdmin(session.user)) {
|
|
199
|
+
/* Authenticated but not an admin — redirect to home. Only admins
|
|
200
|
+
should be able to change the app's configuration. */
|
|
85
201
|
return { data: { isFirstSetup: false }, redirectUrl: '/' };
|
|
86
202
|
}
|
|
87
203
|
return { data: { isFirstSetup: false }, redirectUrl: null };
|
package/dist/kit/loads.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loads.js","sourceRoot":"","sources":["../../src/kit/loads.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loads.js","sourceRoot":"","sources":["../../src/kit/loads.ts"],"names":[],"mappings":"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"}
|
package/dist/kit/server.d.ts
CHANGED
|
@@ -1,41 +1,173 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Server-side API helpers for SvelteKit route handlers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This module extracts reusable backend logic so scaffolded API routes can be
|
|
5
|
+
* thin wrappers around these helpers. It provides three main capabilities:
|
|
6
|
+
*
|
|
7
|
+
* - **Server config reading** — reads Supabase credentials from environment
|
|
8
|
+
* variables at runtime (`getServerConfig`)
|
|
9
|
+
* - **Vercel deployment** — upserts env vars and triggers production
|
|
10
|
+
* redeployments via the Vercel REST API (`deployToVercel`)
|
|
11
|
+
* - **Credential validation** — factory for a SvelteKit POST handler that
|
|
12
|
+
* validates Supabase credentials (`createValidateHandler`)
|
|
13
|
+
*
|
|
14
|
+
* All Vercel API interactions use a create-or-update (upsert) strategy for
|
|
15
|
+
* environment variables, and support both git-based and clone-based
|
|
16
|
+
* redeployment strategies for maximum compatibility.
|
|
17
|
+
*
|
|
18
|
+
* @module kit/server
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // In /api/config/+server.ts
|
|
23
|
+
* import { getServerConfig } from 'stellar-engine/kit/server';
|
|
24
|
+
* export function GET() {
|
|
25
|
+
* return new Response(JSON.stringify(getServerConfig()));
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://vercel.com/docs/rest-api} for Vercel API reference
|
|
30
|
+
* @see {@link validateSupabaseCredentials} in `supabase/validate.ts`
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for deploying Supabase credentials to Vercel.
|
|
34
|
+
*
|
|
35
|
+
* Contains all the information needed to authenticate with Vercel,
|
|
36
|
+
* identify the target project, and set the Supabase connection values.
|
|
5
37
|
*/
|
|
6
|
-
/** Configuration for deploying Supabase credentials to Vercel. */
|
|
7
38
|
export interface DeployConfig {
|
|
39
|
+
/** Vercel personal access token or team token for API authentication. */
|
|
8
40
|
vercelToken: string;
|
|
41
|
+
/** The Vercel project ID (found in project settings). */
|
|
9
42
|
projectId: string;
|
|
43
|
+
/** The Supabase project URL (e.g. `https://abc.supabase.co`). */
|
|
10
44
|
supabaseUrl: string;
|
|
45
|
+
/** The Supabase anonymous/public key for client-side access. */
|
|
11
46
|
supabaseAnonKey: string;
|
|
12
47
|
}
|
|
13
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Result of a Vercel deployment attempt.
|
|
50
|
+
*
|
|
51
|
+
* On success, includes the deployment URL. On failure, includes
|
|
52
|
+
* the error message from the Vercel API or internal exception.
|
|
53
|
+
*/
|
|
14
54
|
export interface DeployResult {
|
|
55
|
+
/** Whether the env var upsert and redeployment completed without errors. */
|
|
15
56
|
success: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The Vercel deployment URL for the triggered build.
|
|
59
|
+
* Only present when `success` is `true` and Vercel returns a URL.
|
|
60
|
+
*/
|
|
16
61
|
deploymentUrl?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Error message describing what went wrong.
|
|
64
|
+
* Only present when `success` is `false`.
|
|
65
|
+
*/
|
|
17
66
|
error?: string;
|
|
18
67
|
}
|
|
19
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Server config status returned by `getServerConfig()`.
|
|
70
|
+
*
|
|
71
|
+
* Indicates whether the required Supabase environment variables are
|
|
72
|
+
* present in the server's runtime environment.
|
|
73
|
+
*/
|
|
20
74
|
export interface ServerConfig {
|
|
75
|
+
/** `true` when both `PUBLIC_SUPABASE_URL` and `PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY` are set. */
|
|
21
76
|
configured: boolean;
|
|
77
|
+
/** The Supabase project URL, if configured. */
|
|
22
78
|
supabaseUrl?: string;
|
|
79
|
+
/** The Supabase anonymous key, if configured. */
|
|
23
80
|
supabaseAnonKey?: string;
|
|
24
81
|
}
|
|
25
82
|
/**
|
|
26
83
|
* Reads Supabase configuration from `process.env` at runtime.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
84
|
+
*
|
|
85
|
+
* Checks for the presence of both `PUBLIC_SUPABASE_URL` and
|
|
86
|
+
* `PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY` environment variables.
|
|
87
|
+
* Returns `{ configured: true }` with the values when both exist,
|
|
88
|
+
* or `{ configured: false }` otherwise.
|
|
89
|
+
*
|
|
90
|
+
* This is intended for use in SvelteKit server routes (e.g. `+server.ts`)
|
|
91
|
+
* to report configuration status to the client during the setup flow.
|
|
92
|
+
*
|
|
93
|
+
* @returns The server config status with optional Supabase credentials.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* // In /api/config/+server.ts
|
|
98
|
+
* import { getServerConfig } from 'stellar-engine/kit/server';
|
|
99
|
+
* export function GET() {
|
|
100
|
+
* return new Response(JSON.stringify(getServerConfig()), {
|
|
101
|
+
* headers: { 'Content-Type': 'application/json' }
|
|
102
|
+
* });
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @see {@link ServerConfig} for the return type shape
|
|
29
107
|
*/
|
|
30
108
|
export declare function getServerConfig(): ServerConfig;
|
|
31
109
|
/**
|
|
32
|
-
* Full Vercel deployment flow:
|
|
33
|
-
*
|
|
110
|
+
* Full Vercel deployment flow: upserts Supabase environment variables,
|
|
111
|
+
* then triggers a production redeployment.
|
|
112
|
+
*
|
|
113
|
+
* The deployment uses a two-strategy approach:
|
|
114
|
+
* - **Strategy A (preferred)**: Git-based redeployment using the repo
|
|
115
|
+
* metadata from Vercel's environment (`VERCEL_GIT_REPO_SLUG`, etc.).
|
|
116
|
+
* This triggers a fresh build from the source branch.
|
|
117
|
+
* - **Strategy B (fallback)**: Clone-based redeployment using an existing
|
|
118
|
+
* deployment ID (`VERCEL_DEPLOYMENT_ID` or `VERCEL_URL`). This
|
|
119
|
+
* reuses the last build artifacts with updated env vars.
|
|
120
|
+
*
|
|
121
|
+
* Both strategies target the `production` environment.
|
|
122
|
+
*
|
|
123
|
+
* @param config - The deployment configuration containing Vercel auth
|
|
124
|
+
* credentials, project ID, and Supabase connection values.
|
|
125
|
+
*
|
|
126
|
+
* @returns A result object indicating success/failure with an optional
|
|
127
|
+
* deployment URL or error message.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const result = await deployToVercel({
|
|
132
|
+
* vercelToken: 'tok_...',
|
|
133
|
+
* projectId: 'prj_...',
|
|
134
|
+
* supabaseUrl: 'https://abc.supabase.co',
|
|
135
|
+
* supabaseAnonKey: 'eyJ...'
|
|
136
|
+
* });
|
|
137
|
+
* if (!result.success) console.error(result.error);
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @see {@link DeployConfig} for the input configuration shape
|
|
141
|
+
* @see {@link DeployResult} for the return type shape
|
|
142
|
+
* @see {@link setEnvVar} for the upsert strategy used for env vars
|
|
34
143
|
*/
|
|
35
144
|
export declare function deployToVercel(config: DeployConfig): Promise<DeployResult>;
|
|
36
145
|
/**
|
|
37
|
-
* Factory returning a SvelteKit POST handler that validates Supabase
|
|
38
|
-
*
|
|
146
|
+
* Factory returning a SvelteKit POST handler that validates Supabase
|
|
147
|
+
* credentials by attempting to connect to the provided Supabase instance.
|
|
148
|
+
*
|
|
149
|
+
* The returned handler:
|
|
150
|
+
* 1. Parses the JSON request body for `supabaseUrl` and `supabaseAnonKey`
|
|
151
|
+
* 2. Validates that both fields are present (returns 400 if not)
|
|
152
|
+
* 3. Delegates to `validateSupabaseCredentials` for the actual check
|
|
153
|
+
* 4. Returns a JSON response with the validation result
|
|
154
|
+
*
|
|
155
|
+
* The `validateSupabaseCredentials` import is dynamic (`await import(...)`)
|
|
156
|
+
* to keep this module's dependency footprint minimal — the validation logic
|
|
157
|
+
* and its Supabase client dependency are only loaded when the endpoint is
|
|
158
|
+
* actually called.
|
|
159
|
+
*
|
|
160
|
+
* @returns An async handler function compatible with SvelteKit's
|
|
161
|
+
* `RequestHandler` signature for POST endpoints.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* // In /api/validate-supabase/+server.ts
|
|
166
|
+
* import { createValidateHandler } from 'stellar-engine/kit/server';
|
|
167
|
+
* export const POST = createValidateHandler();
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @see {@link validateSupabaseCredentials} in `supabase/validate.ts`
|
|
39
171
|
*/
|
|
40
172
|
export declare function createValidateHandler(): ({ request }: {
|
|
41
173
|
request: Request;
|
package/dist/kit/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/kit/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/kit/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AA6BH;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IAEpB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAElB,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IAEpB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,oGAAoG;IACpG,UAAU,EAAE,OAAO,CAAC;IAEpB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA6GD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAQ9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAwEhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,KACrB,aAAa;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,KAAG,OAAO,CAAC,QAAQ,CAAC,CA2BpE"}
|