@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.
Files changed (191) hide show
  1. package/README.md +4 -1
  2. package/dist/actions/remoteChange.d.ts +143 -18
  3. package/dist/actions/remoteChange.d.ts.map +1 -1
  4. package/dist/actions/remoteChange.js +182 -58
  5. package/dist/actions/remoteChange.js.map +1 -1
  6. package/dist/actions/truncateTooltip.d.ts +26 -12
  7. package/dist/actions/truncateTooltip.d.ts.map +1 -1
  8. package/dist/actions/truncateTooltip.js +89 -34
  9. package/dist/actions/truncateTooltip.js.map +1 -1
  10. package/dist/auth/admin.d.ts +40 -3
  11. package/dist/auth/admin.d.ts.map +1 -1
  12. package/dist/auth/admin.js +45 -5
  13. package/dist/auth/admin.js.map +1 -1
  14. package/dist/auth/crypto.d.ts +55 -5
  15. package/dist/auth/crypto.d.ts.map +1 -1
  16. package/dist/auth/crypto.js +58 -5
  17. package/dist/auth/crypto.js.map +1 -1
  18. package/dist/auth/deviceVerification.d.ts +236 -20
  19. package/dist/auth/deviceVerification.d.ts.map +1 -1
  20. package/dist/auth/deviceVerification.js +293 -40
  21. package/dist/auth/deviceVerification.js.map +1 -1
  22. package/dist/auth/displayUtils.d.ts +98 -0
  23. package/dist/auth/displayUtils.d.ts.map +1 -0
  24. package/dist/auth/displayUtils.js +133 -0
  25. package/dist/auth/displayUtils.js.map +1 -0
  26. package/dist/auth/loginGuard.d.ts +108 -14
  27. package/dist/auth/loginGuard.d.ts.map +1 -1
  28. package/dist/auth/loginGuard.js +153 -31
  29. package/dist/auth/loginGuard.js.map +1 -1
  30. package/dist/auth/offlineCredentials.d.ts +132 -15
  31. package/dist/auth/offlineCredentials.d.ts.map +1 -1
  32. package/dist/auth/offlineCredentials.js +167 -23
  33. package/dist/auth/offlineCredentials.js.map +1 -1
  34. package/dist/auth/offlineLogin.d.ts +96 -10
  35. package/dist/auth/offlineLogin.d.ts.map +1 -1
  36. package/dist/auth/offlineLogin.js +82 -15
  37. package/dist/auth/offlineLogin.js.map +1 -1
  38. package/dist/auth/offlineSession.d.ts +83 -9
  39. package/dist/auth/offlineSession.d.ts.map +1 -1
  40. package/dist/auth/offlineSession.js +104 -13
  41. package/dist/auth/offlineSession.js.map +1 -1
  42. package/dist/auth/resolveAuthState.d.ts +70 -8
  43. package/dist/auth/resolveAuthState.d.ts.map +1 -1
  44. package/dist/auth/resolveAuthState.js +142 -46
  45. package/dist/auth/resolveAuthState.js.map +1 -1
  46. package/dist/auth/singleUser.d.ts +390 -37
  47. package/dist/auth/singleUser.d.ts.map +1 -1
  48. package/dist/auth/singleUser.js +500 -99
  49. package/dist/auth/singleUser.js.map +1 -1
  50. package/dist/bin/install-pwa.d.ts +18 -2
  51. package/dist/bin/install-pwa.d.ts.map +1 -1
  52. package/dist/bin/install-pwa.js +801 -25
  53. package/dist/bin/install-pwa.js.map +1 -1
  54. package/dist/config.d.ts +132 -12
  55. package/dist/config.d.ts.map +1 -1
  56. package/dist/config.js +87 -9
  57. package/dist/config.js.map +1 -1
  58. package/dist/conflicts.d.ts +246 -23
  59. package/dist/conflicts.d.ts.map +1 -1
  60. package/dist/conflicts.js +495 -46
  61. package/dist/conflicts.js.map +1 -1
  62. package/dist/data.d.ts +338 -18
  63. package/dist/data.d.ts.map +1 -1
  64. package/dist/data.js +385 -34
  65. package/dist/data.js.map +1 -1
  66. package/dist/database.d.ts +72 -14
  67. package/dist/database.d.ts.map +1 -1
  68. package/dist/database.js +120 -29
  69. package/dist/database.js.map +1 -1
  70. package/dist/debug.d.ts +77 -1
  71. package/dist/debug.d.ts.map +1 -1
  72. package/dist/debug.js +88 -1
  73. package/dist/debug.js.map +1 -1
  74. package/dist/deviceId.d.ts +38 -7
  75. package/dist/deviceId.d.ts.map +1 -1
  76. package/dist/deviceId.js +68 -10
  77. package/dist/deviceId.js.map +1 -1
  78. package/dist/engine.d.ts +175 -3
  79. package/dist/engine.d.ts.map +1 -1
  80. package/dist/engine.js +756 -109
  81. package/dist/engine.js.map +1 -1
  82. package/dist/entries/actions.d.ts +13 -0
  83. package/dist/entries/actions.d.ts.map +1 -1
  84. package/dist/entries/actions.js +26 -1
  85. package/dist/entries/actions.js.map +1 -1
  86. package/dist/entries/auth.d.ts +16 -0
  87. package/dist/entries/auth.d.ts.map +1 -1
  88. package/dist/entries/auth.js +73 -1
  89. package/dist/entries/auth.js.map +1 -1
  90. package/dist/entries/config.d.ts +12 -0
  91. package/dist/entries/config.d.ts.map +1 -1
  92. package/dist/entries/config.js +18 -1
  93. package/dist/entries/config.js.map +1 -1
  94. package/dist/entries/kit.d.ts +11 -0
  95. package/dist/entries/kit.d.ts.map +1 -1
  96. package/dist/entries/kit.js +52 -2
  97. package/dist/entries/kit.js.map +1 -1
  98. package/dist/entries/stores.d.ts +11 -0
  99. package/dist/entries/stores.d.ts.map +1 -1
  100. package/dist/entries/stores.js +43 -2
  101. package/dist/entries/stores.js.map +1 -1
  102. package/dist/entries/types.d.ts +10 -0
  103. package/dist/entries/types.d.ts.map +1 -1
  104. package/dist/entries/types.js +10 -0
  105. package/dist/entries/types.js.map +1 -1
  106. package/dist/entries/utils.d.ts +6 -0
  107. package/dist/entries/utils.d.ts.map +1 -1
  108. package/dist/entries/utils.js +22 -1
  109. package/dist/entries/utils.js.map +1 -1
  110. package/dist/entries/vite.d.ts +17 -0
  111. package/dist/entries/vite.d.ts.map +1 -1
  112. package/dist/entries/vite.js +24 -1
  113. package/dist/entries/vite.js.map +1 -1
  114. package/dist/index.d.ts +31 -0
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +175 -20
  117. package/dist/index.js.map +1 -1
  118. package/dist/kit/auth.d.ts +60 -5
  119. package/dist/kit/auth.d.ts.map +1 -1
  120. package/dist/kit/auth.js +45 -4
  121. package/dist/kit/auth.js.map +1 -1
  122. package/dist/kit/confirm.d.ts +93 -12
  123. package/dist/kit/confirm.d.ts.map +1 -1
  124. package/dist/kit/confirm.js +103 -16
  125. package/dist/kit/confirm.js.map +1 -1
  126. package/dist/kit/loads.d.ts +150 -23
  127. package/dist/kit/loads.d.ts.map +1 -1
  128. package/dist/kit/loads.js +140 -24
  129. package/dist/kit/loads.js.map +1 -1
  130. package/dist/kit/server.d.ts +142 -10
  131. package/dist/kit/server.d.ts.map +1 -1
  132. package/dist/kit/server.js +158 -15
  133. package/dist/kit/server.js.map +1 -1
  134. package/dist/kit/sw.d.ts +152 -23
  135. package/dist/kit/sw.d.ts.map +1 -1
  136. package/dist/kit/sw.js +182 -26
  137. package/dist/kit/sw.js.map +1 -1
  138. package/dist/queue.d.ts +274 -0
  139. package/dist/queue.d.ts.map +1 -1
  140. package/dist/queue.js +556 -38
  141. package/dist/queue.js.map +1 -1
  142. package/dist/realtime.d.ts +241 -27
  143. package/dist/realtime.d.ts.map +1 -1
  144. package/dist/realtime.js +633 -109
  145. package/dist/realtime.js.map +1 -1
  146. package/dist/runtime/runtimeConfig.d.ts +91 -8
  147. package/dist/runtime/runtimeConfig.d.ts.map +1 -1
  148. package/dist/runtime/runtimeConfig.js +146 -19
  149. package/dist/runtime/runtimeConfig.js.map +1 -1
  150. package/dist/stores/authState.d.ts +150 -11
  151. package/dist/stores/authState.d.ts.map +1 -1
  152. package/dist/stores/authState.js +169 -17
  153. package/dist/stores/authState.js.map +1 -1
  154. package/dist/stores/network.d.ts +39 -0
  155. package/dist/stores/network.d.ts.map +1 -1
  156. package/dist/stores/network.js +169 -16
  157. package/dist/stores/network.js.map +1 -1
  158. package/dist/stores/remoteChanges.d.ts +327 -52
  159. package/dist/stores/remoteChanges.d.ts.map +1 -1
  160. package/dist/stores/remoteChanges.js +337 -75
  161. package/dist/stores/remoteChanges.js.map +1 -1
  162. package/dist/stores/sync.d.ts +130 -0
  163. package/dist/stores/sync.d.ts.map +1 -1
  164. package/dist/stores/sync.js +167 -7
  165. package/dist/stores/sync.js.map +1 -1
  166. package/dist/supabase/auth.d.ts +325 -18
  167. package/dist/supabase/auth.d.ts.map +1 -1
  168. package/dist/supabase/auth.js +374 -26
  169. package/dist/supabase/auth.js.map +1 -1
  170. package/dist/supabase/client.d.ts +79 -6
  171. package/dist/supabase/client.d.ts.map +1 -1
  172. package/dist/supabase/client.js +158 -15
  173. package/dist/supabase/client.js.map +1 -1
  174. package/dist/supabase/validate.d.ts +101 -7
  175. package/dist/supabase/validate.d.ts.map +1 -1
  176. package/dist/supabase/validate.js +117 -8
  177. package/dist/supabase/validate.js.map +1 -1
  178. package/dist/sw/build/vite-plugin.d.ts +55 -10
  179. package/dist/sw/build/vite-plugin.d.ts.map +1 -1
  180. package/dist/sw/build/vite-plugin.js +77 -18
  181. package/dist/sw/build/vite-plugin.js.map +1 -1
  182. package/dist/sw/sw.js +99 -44
  183. package/dist/types.d.ts +150 -26
  184. package/dist/types.d.ts.map +1 -1
  185. package/dist/types.js +12 -10
  186. package/dist/types.js.map +1 -1
  187. package/dist/utils.d.ts +55 -13
  188. package/dist/utils.d.ts.map +1 -1
  189. package/dist/utils.js +83 -22
  190. package/dist/utils.js.map +1 -1
  191. package/package.json +1 -1
@@ -1,46 +1,147 @@
1
1
  /**
2
2
  * @fileoverview SvelteKit load function helpers.
3
3
  *
4
- * Extracts orchestration logic from layout/page load functions so
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
- /** Data returned by `resolveRootLayout`. */
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
- /** Data returned by `resolveProtectedLayout`. */
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
- /** Data returned by `resolveSetupAccess`. */
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
- * 1. Calls the app's `initEngine` function (for database schema setup)
25
- * 2. Runs `initConfig()` — redirects to `/setup` if unconfigured
26
- * 3. Resolves auth state
27
- * 4. Starts sync engine if authenticated
28
- *
29
- * @param initEngineFn - The app's `initEngine()` call (executed before config init).
30
- * Should already have been called at module scope in the browser.
31
- * @param url - The current page URL (for setup redirect check).
32
- * @returns Layout data with session, auth mode, offline profile, and setup status.
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 returns
39
- * redirect info if unauthenticated.
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
- * @param url - The current page URL (for building redirect parameter).
42
- * @returns Auth data, or `null` if a redirect to `/login` is needed.
43
- * When null, caller should `throw redirect(302, loginUrl)`.
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: if unconfigured public access; if configured → admin-only.
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
- * @returns `{ isFirstSetup }` with access info, or `null` with a redirectUrl
56
- * if the user should be redirected away.
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;
@@ -1 +1 @@
1
- {"version":3,"file":"loads.d.ts","sourceRoot":"","sources":["../../src/kit/loads.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAMnE,4CAA4C;AAC5C,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACpC,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;IACtC,cAAc,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC;CACnD;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,OAAO,CAAC;CACvB;AAMD;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EACzB,aAAa,CAAC,EAAE,MAAM,IAAI,GACzB,OAAO,CAAC,cAAc,CAAC,CAsBzB;AAMD;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,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,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
- * Extracts orchestration logic from layout/page load functions so
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
- * 1. Calls the app's `initEngine` function (for database schema setup)
18
- * 2. Runs `initConfig()` — redirects to `/setup` if unconfigured
19
- * 3. Resolves auth state
20
- * 4. Starts sync engine if authenticated
21
- *
22
- * @param initEngineFn - The app's `initEngine()` call (executed before config init).
23
- * Should already have been called at module scope in the browser.
24
- * @param url - The current page URL (for setup redirect check).
25
- * @returns Layout data with session, auth mode, offline profile, and setup status.
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
- // No config yet first-time user, redirect to setup wizard
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
- // Still on setup page with no config — return blank state
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
- // Resolve auth — determines Supabase / offline / none
89
+ /* Resolve auth — determines Supabase / offline / none based on the
90
+ stored runtime config and available credentials. */
38
91
  const result = await resolveAuthState();
39
- // Start sync engine only when the user is actually authenticated
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 returns
50
- * redirect info if unauthenticated.
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
- * @param url - The current page URL (for building redirect parameter).
53
- * @returns Auth data, or `null` if a redirect to `/login` is needed.
54
- * When null, caller should `throw redirect(302, loginUrl)`.
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: if unconfigured public access; if configured → admin-only.
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
- * @returns `{ isFirstSetup }` with access info, or `null` with a redirectUrl
74
- * if the user should be redirected away.
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 };
@@ -1 +1 @@
1
- {"version":3,"file":"loads.js","sourceRoot":"","sources":["../../src/kit/loads.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAwB3C,gFAAgF;AAChF,eAAe;AACf,gFAAgF;AAEhF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAyB,EACzB,aAA0B;IAE1B,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAElC,4DAA4D;IAC5D,IAA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W,EAAE,QAAQ,EAAE,CAAC;IACjD,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC7C,CAAC;AAED,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IAItC;iEAC6D;IAC7D,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,OAAO,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC7D,CAAC;IAED,yEAAyE;IACzE,MAAM,OAAO,GAAG,MAAM,eAAe,EAAE,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;QACnB,wEAAwE;QACxE,OAAO,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IAClE,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B;+DACuD;QACvD,OAAO,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC9D,CAAC"}
@@ -1,41 +1,173 @@
1
1
  /**
2
2
  * @fileoverview Server-side API helpers for SvelteKit route handlers.
3
3
  *
4
- * Extracts reusable backend logic so scaffolded API routes can be thin wrappers.
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
- /** Result of a Vercel deployment attempt. */
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
- /** Server config status returned by `getServerConfig()`. */
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
- * Returns `{ configured: true, supabaseUrl, supabaseAnonKey }` when both
28
- * env vars exist, or `{ configured: false }` otherwise.
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: upsert env vars, then trigger a production
33
- * redeployment via git-based or clone-based strategy.
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 credentials.
38
- * The handler parses the request body and delegates to `validateSupabaseCredentials`.
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;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/kit/server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA+ED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAQ9C;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CA+DhF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,KACrB,aAAa;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,KAAG,OAAO,CAAC,QAAQ,CAAC,CAwBpE"}
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;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