zitejs 0.10.0-start.20 → 0.10.0-start.22

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 (154) hide show
  1. package/dist/cjs/auth/actions.d.ts +28 -0
  2. package/dist/cjs/auth/actions.js +93 -0
  3. package/dist/cjs/auth/client.d.ts +357 -0
  4. package/dist/cjs/auth/client.js +66 -0
  5. package/dist/cjs/auth/index.d.ts +2 -249
  6. package/dist/cjs/auth/index.js +11 -114
  7. package/dist/cjs/auth/index.test.js +18 -0
  8. package/dist/cjs/auth/profileUpdates.d.ts +9 -0
  9. package/dist/cjs/auth/profileUpdates.js +11 -0
  10. package/dist/cjs/check/start/sourceRules.js +73 -21
  11. package/dist/cjs/cli.js +6 -0
  12. package/dist/cjs/dev/index.js +15 -0
  13. package/dist/cjs/dev/signin.d.ts +16 -0
  14. package/dist/cjs/dev/signin.js +76 -0
  15. package/dist/cjs/integrations/rules.js +5 -3
  16. package/dist/cjs/internal/appMode.d.ts +11 -0
  17. package/dist/cjs/internal/appMode.js +4 -1
  18. package/dist/cjs/internal/appToken.d.ts +17 -0
  19. package/dist/cjs/internal/appToken.js +26 -0
  20. package/dist/cjs/internal/platformFetch.d.ts +2 -0
  21. package/dist/cjs/internal/platformFetch.js +13 -0
  22. package/dist/cjs/internal/serviceUrls.d.ts +7 -0
  23. package/dist/cjs/internal/serviceUrls.js +16 -0
  24. package/dist/cjs/runtime/index.d.ts +55 -16
  25. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  26. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +33 -0
  27. package/dist/cjs/start/aiUsage.d.ts +23 -0
  28. package/dist/cjs/start/aiUsage.js +151 -0
  29. package/dist/cjs/start/devApp.d.ts +1 -0
  30. package/dist/cjs/start/devApp.js +6 -0
  31. package/dist/cjs/start/entries.js +4 -0
  32. package/dist/cjs/start/provider.d.ts +24 -0
  33. package/dist/cjs/start/provider.js +159 -0
  34. package/dist/cjs/start/types.d.ts +320 -0
  35. package/dist/cjs/start/types.js +2 -0
  36. package/dist/cjs/sync/lib.js +10 -5
  37. package/dist/cjs/sync/lib.test.js +10 -0
  38. package/dist/cjs/upload/index.js +73 -22
  39. package/dist/cjs/upload/index.test.js +35 -2
  40. package/dist/esm/auth/actions.d.ts +28 -0
  41. package/dist/esm/auth/actions.js +55 -0
  42. package/dist/esm/auth/client.d.ts +357 -0
  43. package/dist/esm/auth/client.js +62 -0
  44. package/dist/esm/auth/index.d.ts +2 -249
  45. package/dist/esm/auth/index.js +2 -109
  46. package/dist/esm/auth/index.test.js +18 -0
  47. package/dist/esm/auth/profileUpdates.d.ts +9 -0
  48. package/dist/esm/auth/profileUpdates.js +6 -0
  49. package/dist/esm/check/start/sourceRules.js +73 -21
  50. package/dist/esm/cli.js +6 -0
  51. package/dist/esm/dev/index.js +15 -0
  52. package/dist/esm/dev/signin.d.ts +16 -0
  53. package/dist/esm/dev/signin.js +72 -0
  54. package/dist/esm/integrations/rules.js +5 -3
  55. package/dist/esm/internal/appMode.d.ts +11 -0
  56. package/dist/esm/internal/appMode.js +2 -0
  57. package/dist/esm/internal/appToken.d.ts +17 -0
  58. package/dist/esm/internal/appToken.js +22 -0
  59. package/dist/esm/internal/platformFetch.d.ts +2 -0
  60. package/dist/esm/internal/platformFetch.js +8 -0
  61. package/dist/esm/internal/serviceUrls.d.ts +7 -0
  62. package/dist/esm/internal/serviceUrls.js +12 -0
  63. package/dist/esm/runtime/index.d.ts +55 -16
  64. package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  65. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +31 -0
  66. package/dist/esm/signin/conformance.d.ts +100 -0
  67. package/dist/esm/signin/conformance.js +471 -0
  68. package/dist/esm/signin/cookies.d.ts +28 -0
  69. package/dist/esm/signin/cookies.js +59 -0
  70. package/dist/esm/signin/encoding.d.ts +9 -0
  71. package/dist/esm/signin/encoding.js +39 -0
  72. package/dist/esm/signin/endpoints.d.ts +12 -0
  73. package/dist/esm/signin/endpoints.js +29 -0
  74. package/dist/esm/signin/http.d.ts +25 -0
  75. package/dist/esm/signin/http.js +69 -0
  76. package/dist/esm/signin/index.d.ts +8 -0
  77. package/dist/esm/signin/index.js +9 -0
  78. package/dist/esm/signin/keys.d.ts +39 -0
  79. package/dist/esm/signin/keys.js +80 -0
  80. package/dist/esm/signin/paths.d.ts +2 -0
  81. package/dist/esm/signin/paths.js +2 -0
  82. package/dist/esm/signin/seal.d.ts +8 -0
  83. package/dist/esm/signin/seal.js +35 -0
  84. package/dist/esm/signin/signin.d.ts +60 -0
  85. package/dist/esm/signin/signin.js +340 -0
  86. package/dist/esm/signin/transport.d.ts +111 -0
  87. package/dist/esm/signin/transport.js +1 -0
  88. package/dist/esm/signin/verify.d.ts +77 -0
  89. package/dist/esm/signin/verify.js +155 -0
  90. package/dist/esm/start/airtable/dispatch.js +3 -3
  91. package/dist/esm/start/airtable/formulas.d.ts +1 -1
  92. package/dist/esm/start/airtable/formulas.js +12 -10
  93. package/dist/esm/start/airtable/index.d.ts +3 -3
  94. package/dist/esm/start/analytics.d.ts +5 -0
  95. package/dist/esm/start/analytics.js +77 -0
  96. package/dist/esm/start/data/index.d.ts +3 -3
  97. package/dist/esm/start/data/index.js +1 -1
  98. package/dist/esm/start/describe.d.ts +8 -1
  99. package/dist/esm/start/describe.js +5 -3
  100. package/dist/esm/start/devApp.d.ts +1 -0
  101. package/dist/esm/start/devApp.js +3 -0
  102. package/dist/esm/start/devSignIn.d.ts +1 -0
  103. package/dist/esm/start/devSignIn.js +3 -0
  104. package/dist/esm/start/direct.d.ts +40 -0
  105. package/dist/esm/start/direct.js +313 -0
  106. package/dist/esm/start/entries.js +4 -0
  107. package/dist/esm/start/factories.test-d.d.ts +2 -1
  108. package/dist/esm/start/fetch.d.ts +1 -0
  109. package/dist/esm/start/fetch.js +4 -0
  110. package/dist/esm/start/host.d.ts +2 -2
  111. package/dist/esm/start/index.d.ts +1 -1
  112. package/dist/esm/start/index.js +4 -2
  113. package/dist/esm/start/instance.js +6 -2
  114. package/dist/esm/start/localSignIn.d.ts +18 -0
  115. package/dist/esm/start/localSignIn.js +73 -0
  116. package/dist/esm/start/outbound.d.ts +12 -3
  117. package/dist/esm/start/outbound.js +135 -23
  118. package/dist/esm/start/pageHead.d.ts +36 -0
  119. package/dist/esm/start/pageHead.js +178 -0
  120. package/dist/esm/start/provider.d.ts +24 -0
  121. package/dist/esm/start/provider.js +150 -0
  122. package/dist/esm/start/router.d.ts +13 -2
  123. package/dist/esm/start/router.js +76 -2
  124. package/dist/esm/start/runLog.d.ts +2 -2
  125. package/dist/esm/start/scope.d.ts +3 -3
  126. package/dist/esm/start/server.d.ts +15 -8
  127. package/dist/esm/start/server.js +175 -43
  128. package/dist/esm/start/telemetry.d.ts +10 -0
  129. package/dist/esm/start/telemetry.js +74 -0
  130. package/dist/esm/start/types.d.ts +118 -3
  131. package/dist/esm/start/uploads.d.ts +2 -0
  132. package/dist/esm/start/uploads.js +52 -0
  133. package/dist/esm/start/version.d.ts +1 -1
  134. package/dist/esm/start/version.js +1 -1
  135. package/dist/esm/start/vite.d.ts +12 -1
  136. package/dist/esm/start/vite.js +119 -7
  137. package/dist/esm/start/workflow.d.ts +6 -2
  138. package/dist/esm/start/workflow.js +9 -2
  139. package/dist/esm/start/workflow.test-d.js +10 -1
  140. package/dist/esm/start/workflowRun.d.ts +5 -0
  141. package/dist/esm/start/workflowRun.js +11 -1
  142. package/dist/esm/start/workspaceSchema.d.ts +1 -0
  143. package/dist/esm/start/workspaceSchema.js +3 -0
  144. package/dist/esm/sync/lib.js +10 -5
  145. package/dist/esm/sync/lib.test.js +10 -0
  146. package/dist/esm/upload/index.js +74 -23
  147. package/dist/esm/upload/index.test.js +35 -2
  148. package/package.json +21 -11
  149. package/dist/cjs/auth-server/index.d.ts +0 -369
  150. package/dist/cjs/auth-server/index.js +0 -119
  151. package/dist/esm/auth-server/index.d.ts +0 -369
  152. package/dist/esm/auth-server/index.js +0 -116
  153. package/dist/esm/start/problems.d.ts +0 -19
  154. package/dist/esm/start/problems.js +0 -8
@@ -1,252 +1,5 @@
1
- export declare const useSession: () => {
2
- data: {
3
- user: import("better-auth/react").StripEmptyObjects<{
4
- id: string;
5
- createdAt: Date;
6
- updatedAt: Date;
7
- email: string;
8
- emailVerified: boolean;
9
- name: string;
10
- image?: string | null | undefined;
11
- } & {} & {
12
- firstName?: string | null | undefined;
13
- lastName?: string | null | undefined;
14
- }>;
15
- session: import("better-auth/react").StripEmptyObjects<{
16
- id: string;
17
- createdAt: Date;
18
- updatedAt: Date;
19
- userId: string;
20
- expiresAt: Date;
21
- token: string;
22
- ipAddress?: string | null | undefined;
23
- userAgent?: string | null | undefined;
24
- } & {} & {}>;
25
- } | null;
26
- isPending: boolean;
27
- isRefetching: boolean;
28
- error: import("@better-fetch/fetch").BetterFetchError | null;
29
- refetch: (queryParams?: {
30
- query?: import("better-auth/types").SessionQueryParams;
31
- } | undefined) => Promise<void>;
32
- };
33
- /**
34
- * `loginWithRedirect` and `logout` are returned as well as exported. The
35
- * pre-monorepo `useAuth()` returned them, so app code that destructures them
36
- * from the hook is common — and returning them here means the legacy compat
37
- * shim is the only thing that has to know that, not every migrated app.
38
- */
39
- export declare function useAuth(): {
40
- user: User | null;
41
- isLoading: boolean;
42
- loginWithRedirect: typeof loginWithRedirect;
43
- logout: typeof logout;
44
- };
45
- export declare const signIn: {
46
- magicLink: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
47
- email: string;
48
- name?: string | undefined;
49
- callbackURL?: string | undefined;
50
- newUserCallbackURL?: string | undefined;
51
- errorCallbackURL?: string | undefined;
52
- metadata?: Record<string, any> | undefined;
53
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
54
- email: string;
55
- name?: string | undefined;
56
- callbackURL?: string | undefined;
57
- newUserCallbackURL?: string | undefined;
58
- errorCallbackURL?: string | undefined;
59
- metadata?: Record<string, any> | undefined;
60
- } & {
61
- fetchOptions?: FetchOptions | undefined;
62
- }>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
63
- status: boolean;
64
- }, {
65
- code?: string | undefined;
66
- message?: string | undefined;
67
- }, FetchOptions["throw"] extends true ? true : false>>;
68
- } & {
69
- social: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
70
- provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | "line" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
71
- callbackURL?: string | undefined;
72
- newUserCallbackURL?: string | undefined;
73
- errorCallbackURL?: string | undefined;
74
- disableRedirect?: boolean | undefined;
75
- idToken?: {
76
- token: string;
77
- nonce?: string | undefined;
78
- accessToken?: string | undefined;
79
- refreshToken?: string | undefined;
80
- expiresAt?: number | undefined;
81
- user?: {
82
- name?: {
83
- firstName?: string | undefined;
84
- lastName?: string | undefined;
85
- } | undefined;
86
- email?: string | undefined;
87
- } | undefined;
88
- } | undefined;
89
- scopes?: string[] | undefined;
90
- requestSignUp?: boolean | undefined;
91
- loginHint?: string | undefined;
92
- additionalData?: Record<string, any> | undefined;
93
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
94
- provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | "line" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
95
- callbackURL?: string | undefined;
96
- newUserCallbackURL?: string | undefined;
97
- errorCallbackURL?: string | undefined;
98
- disableRedirect?: boolean | undefined;
99
- idToken?: {
100
- token: string;
101
- nonce?: string | undefined;
102
- accessToken?: string | undefined;
103
- refreshToken?: string | undefined;
104
- expiresAt?: number | undefined;
105
- user?: {
106
- name?: {
107
- firstName?: string | undefined;
108
- lastName?: string | undefined;
109
- } | undefined;
110
- email?: string | undefined;
111
- } | undefined;
112
- } | undefined;
113
- scopes?: string[] | undefined;
114
- requestSignUp?: boolean | undefined;
115
- loginHint?: string | undefined;
116
- additionalData?: Record<string, any> | undefined;
117
- } & {
118
- fetchOptions?: FetchOptions | undefined;
119
- }>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
120
- redirect: boolean;
121
- url: string;
122
- } | (Omit<{
123
- redirect: boolean;
124
- token: string;
125
- url: undefined;
126
- user: {
127
- id: string;
128
- createdAt: Date;
129
- updatedAt: Date;
130
- email: string;
131
- emailVerified: boolean;
132
- name: string;
133
- image?: string | null | undefined | undefined;
134
- };
135
- }, "user"> & {
136
- user: import("better-auth/react").StripEmptyObjects<{
137
- id: string;
138
- createdAt: Date;
139
- updatedAt: Date;
140
- email: string;
141
- emailVerified: boolean;
142
- name: string;
143
- image?: string | null | undefined;
144
- } & {} & {
145
- firstName?: string | null | undefined;
146
- lastName?: string | null | undefined;
147
- }>;
148
- }), {
149
- code?: string | undefined;
150
- message?: string | undefined;
151
- }, FetchOptions["throw"] extends true ? true : false>>;
152
- } & {
153
- email: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
154
- email: string;
155
- password: string;
156
- callbackURL?: string | undefined;
157
- rememberMe?: boolean | undefined;
158
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
159
- email: string;
160
- password: string;
161
- callbackURL?: string | undefined;
162
- rememberMe?: boolean | undefined;
163
- } & {
164
- fetchOptions?: FetchOptions | undefined;
165
- }>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<Omit<{
166
- redirect: boolean;
167
- token: string;
168
- url?: string | undefined;
169
- user: {
170
- id: string;
171
- createdAt: Date;
172
- updatedAt: Date;
173
- email: string;
174
- emailVerified: boolean;
175
- name: string;
176
- image?: string | null | undefined | undefined;
177
- };
178
- }, "user"> & {
179
- user: import("better-auth/react").StripEmptyObjects<{
180
- id: string;
181
- createdAt: Date;
182
- updatedAt: Date;
183
- email: string;
184
- emailVerified: boolean;
185
- name: string;
186
- image?: string | null | undefined;
187
- } & {} & {
188
- firstName?: string | null | undefined;
189
- lastName?: string | null | undefined;
190
- }>;
191
- }, {
192
- code?: string | undefined;
193
- message?: string | undefined;
194
- }, FetchOptions["throw"] extends true ? true : false>>;
195
- };
196
- export declare const signOut: <FetchOptions extends import("@better-auth/core").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
197
- query?: Record<string, any> | undefined;
198
- fetchOptions?: FetchOptions | undefined;
199
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
200
- success: boolean;
201
- }, {
202
- code?: string | undefined;
203
- message?: string | undefined;
204
- }, FetchOptions["throw"] extends true ? true : false>>;
205
- export declare const signUp: {
206
- email: (data: {
207
- email: string;
208
- password: string;
209
- name: string;
210
- [key: string]: unknown;
211
- }) => Promise<{
212
- error?: {
213
- message?: string;
214
- } | null;
215
- data?: unknown;
216
- }>;
217
- };
218
- export declare function loginWithRedirect(opts?: {
219
- redirectUrl?: string;
220
- /**
221
- * @deprecated Ignored. There is one sign-in screen now — the server works out
222
- * from the email whether it's a sign-in or a sign-up. Still accepted, because
223
- * app source written before that change would otherwise stop typechecking on
224
- * its next build, and a typecheck error fails the build outright.
225
- */
226
- initialView?: 'login' | 'signup';
227
- }): void;
228
- export declare function logout(opts?: {
229
- returnTo?: string;
230
- }): void;
231
- export declare function updateProfile(data: {
232
- name?: string;
233
- firstName?: string;
234
- lastName?: string;
235
- image?: string;
236
- }): Promise<{
237
- data: {
238
- status: boolean;
239
- };
240
- error: null;
241
- } | {
242
- data: null;
243
- error: {
244
- code?: string | undefined | undefined;
245
- message?: string | undefined | undefined;
246
- status: number;
247
- statusText: string;
248
- };
249
- }>;
1
+ export { useSession, useAuth, signIn, signOut, signUp, } from './client.js';
2
+ export { loginWithRedirect, logout, updateProfile } from './actions.js';
250
3
  /**
251
4
  * An `interface`, not a type alias, so a migrated app can widen it by
252
5
  * declaration merging (`.zite/user-extensions.d.ts`). A legacy user-sync app's
@@ -1,116 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.signUp = exports.signOut = exports.signIn = exports.useSession = void 0;
4
- exports.useAuth = useAuth;
5
- exports.loginWithRedirect = loginWithRedirect;
6
- exports.logout = logout;
7
- exports.updateProfile = updateProfile;
8
- const react_1 = require("react");
9
- const react_2 = require("better-auth/react");
10
- const plugins_1 = require("better-auth/client/plugins");
11
- const constants_js_1 = require("./constants.js");
12
- const previewClaim_js_1 = require("./previewClaim.js");
13
- const config_js_1 = require("./config.js");
14
- const authClient = (0, react_2.createAuthClient)({
15
- baseURL: '',
16
- plugins: [
17
- (0, plugins_1.magicLinkClient)(),
18
- (0, plugins_1.inferAdditionalFields)({
19
- user: {
20
- firstName: { type: 'string', required: false },
21
- lastName: { type: 'string', required: false },
22
- },
23
- }),
24
- ],
25
- });
26
- exports.useSession = authClient.useSession;
27
- /**
28
- * An internal app has no signed-out state — SSO runs before the bundle — so an
29
- * empty session means it died underneath the app. Only `internal`: elsewhere a
30
- * signed-out visitor is legitimate.
31
- */
32
- function shouldRedirectSignedOut(isPending, hasUser) {
33
- if (isPending || hasUser)
34
- return false;
35
- if ((0, config_js_1.getAccessMode)() !== 'internal')
36
- return false;
37
- if (typeof window === 'undefined')
38
- return false;
39
- // `loginWithRedirect` won't navigate from an auth page, so claiming a
40
- // redirect here would hang `isLoading` forever.
41
- return !window.location.pathname.startsWith('/auth/');
42
- }
43
- /**
44
- * `loginWithRedirect` and `logout` are returned as well as exported. The
45
- * pre-monorepo `useAuth()` returned them, so app code that destructures them
46
- * from the hook is common — and returning them here means the legacy compat
47
- * shim is the only thing that has to know that, not every migrated app.
48
- */
49
- function useAuth() {
50
- const { data, isPending } = (0, exports.useSession)();
51
- const user = data?.user ?? null;
52
- const redirecting = shouldRedirectSignedOut(isPending, user !== null);
53
- (0, react_1.useEffect)(() => {
54
- if (redirecting)
55
- loginWithRedirect();
56
- }, [redirecting]);
57
- return {
58
- user,
59
- // Loading, not signed out: the signed-out branch is the empty screen this
60
- // exists to prevent.
61
- isLoading: isPending || redirecting,
62
- loginWithRedirect,
63
- logout,
64
- };
65
- }
66
- exports.signIn = authClient.signIn;
67
- exports.signOut = authClient.signOut;
68
- exports.signUp = authClient.signUp;
69
- function loginWithRedirect(opts) {
70
- if (window.location.pathname.startsWith('/auth/'))
71
- return;
72
- // Default to wherever the user already is, so a deep link survives the round
73
- // trip through login without every app having to remember to pass it. Pass
74
- // `redirectUrl` only to send them somewhere else instead.
75
- //
76
- // Resolved to an absolute URL either way, on purpose: better-auth
77
- // character-checks a *relative* callbackURL — an encoded space, a fragment or
78
- // any non-ASCII in the path fails its regex and the destination is dropped —
79
- // but never inspects the path of an absolute one. Normalising here means a
80
- // caller can pass whichever form reads best without having to know that.
81
- const target = new URL(opts?.redirectUrl ?? window.location.href, window.location.href);
82
- // Say nothing when there's nothing to say. The sign-in page already returns
83
- // people to the app root when it isn't told otherwise, so naming the root
84
- // spells out the default — and puts an encoded copy of the app's own URL in
85
- // the address bar of every logged-out visitor to the front page, which is the
86
- // common case. Only pass a destination when it IS one.
87
- const isRoot = target.pathname === '/' && target.search === '' && target.hash === '';
88
- const params = new URLSearchParams();
89
- if (!isRoot)
90
- params.set('redirectUrl', target.toString());
91
- // The editor preview rides its usageToken on the app URL; the sign-in page
92
- // only shows its editor surface ("Preview as" picker) when that token reaches
93
- // it. Capturing the current URL carries it implicitly — but an explicit
94
- // `redirectUrl` names a bare path, and would silently drop it. Forward it
95
- // top-level either way, so how the app phrases its redirect can't decide
96
- // whether the editor gets a preview. Published visitors never have one.
97
- const usageToken = new URL(window.location.href).searchParams.get(constants_js_1.USAGE_TOKEN_QUERY_PARAM) ??
98
- window._ziteUsageToken;
99
- if (usageToken)
100
- params.set(constants_js_1.USAGE_TOKEN_QUERY_PARAM, usageToken);
101
- // A Start app's preview also needs its claim where the editor's frame dropped
102
- // the cookie, as `loginHref()` sends it. Classic previews never have one.
103
- const claim = (0, previewClaim_js_1.browserPreviewClaim)();
104
- if (claim)
105
- params.set(previewClaim_js_1.PREVIEW_CLAIM_PARAM, claim);
106
- const query = params.toString();
107
- window.location.href = query ? `/auth/login?${query}` : '/auth/login';
108
- }
109
- function logout(opts) {
110
- (0, exports.signOut)().then(() => {
111
- window.location.href = opts?.returnTo || '/';
112
- });
113
- }
114
- function updateProfile(data) {
115
- return authClient.updateUser(data);
116
- }
3
+ exports.updateProfile = exports.logout = exports.loginWithRedirect = exports.signUp = exports.signOut = exports.signIn = exports.useAuth = exports.useSession = void 0;
4
+ var client_js_1 = require("./client.js");
5
+ Object.defineProperty(exports, "useSession", { enumerable: true, get: function () { return client_js_1.useSession; } });
6
+ Object.defineProperty(exports, "useAuth", { enumerable: true, get: function () { return client_js_1.useAuth; } });
7
+ Object.defineProperty(exports, "signIn", { enumerable: true, get: function () { return client_js_1.signIn; } });
8
+ Object.defineProperty(exports, "signOut", { enumerable: true, get: function () { return client_js_1.signOut; } });
9
+ Object.defineProperty(exports, "signUp", { enumerable: true, get: function () { return client_js_1.signUp; } });
10
+ var actions_js_1 = require("./actions.js");
11
+ Object.defineProperty(exports, "loginWithRedirect", { enumerable: true, get: function () { return actions_js_1.loginWithRedirect; } });
12
+ Object.defineProperty(exports, "logout", { enumerable: true, get: function () { return actions_js_1.logout; } });
13
+ Object.defineProperty(exports, "updateProfile", { enumerable: true, get: function () { return actions_js_1.updateProfile; } });
@@ -217,3 +217,21 @@ function redirectParamOf(href) {
217
217
  ]);
218
218
  });
219
219
  });
220
+ (0, vitest_1.describe)('a profile edit', () => {
221
+ (0, vitest_1.afterEach)(() => vitest_1.vi.unstubAllGlobals());
222
+ (0, vitest_1.it)("tells a Start app's router once the platform saved it, and not when it refused", async () => {
223
+ let status = 400;
224
+ vitest_1.vi.stubGlobal('fetch', vitest_1.vi.fn(async () => Response.json(status === 200 ? { status: true } : { message: 'no' }, { status })));
225
+ // The client takes its fetch when the module loads.
226
+ vitest_1.vi.resetModules();
227
+ const { updateProfile } = await Promise.resolve().then(() => __importStar(require('./index.js')));
228
+ const { onProfileUpdated } = await Promise.resolve().then(() => __importStar(require('./profileUpdates.js')));
229
+ const told = vitest_1.vi.fn();
230
+ onProfileUpdated(told);
231
+ (0, vitest_1.expect)((await updateProfile({ firstName: 'Ada' })).error).not.toBeNull();
232
+ (0, vitest_1.expect)(told).not.toHaveBeenCalled();
233
+ status = 200;
234
+ (0, vitest_1.expect)((await updateProfile({ firstName: 'Ada' })).error).toBeNull();
235
+ (0, vitest_1.expect)(told).toHaveBeenCalledWith({ firstName: 'Ada' });
236
+ });
237
+ });
@@ -0,0 +1,9 @@
1
+ export type ProfileChanges = {
2
+ name?: string;
3
+ firstName?: string;
4
+ lastName?: string;
5
+ image?: string;
6
+ };
7
+ /** @internal A Start app's router, in the browser, so a profile edit shows without a reload. */
8
+ export declare const onProfileUpdated: (next: (changes: ProfileChanges) => void) => void;
9
+ export declare const profileUpdated: (changes: ProfileChanges) => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.profileUpdated = exports.onProfileUpdated = void 0;
4
+ let listener;
5
+ /** @internal A Start app's router, in the browser, so a profile edit shows without a reload. */
6
+ const onProfileUpdated = (next) => {
7
+ listener = next;
8
+ };
9
+ exports.onProfileUpdated = onProfileUpdated;
10
+ const profileUpdated = (changes) => listener?.(changes);
11
+ exports.profileUpdated = profileUpdated;
@@ -444,6 +444,8 @@ const CLASSIC_IMPORTS = {
444
444
  "react-router-dom": "routing is file routes, with Link and useNavigate from @tanstack/react-router",
445
445
  "react-router": "routing is file routes, with Link and useNavigate from @tanstack/react-router",
446
446
  };
447
+ // A Start app reads its user from the router; zitejs/auth's actions work in both runtimes.
448
+ const CLASSIC_AUTH_READS = new Set(["useAuth", "useSession"]);
447
449
  const importsModule = (source, module) => source === module || source.startsWith(`${module}/`);
448
450
  const containsTypeofWindow = (node) => {
449
451
  let found = false;
@@ -662,11 +664,20 @@ const workflowProblems = (files, kind) => {
662
664
  const { root, calls } = chainOf(init);
663
665
  const innermost = calls.at(-1);
664
666
  return root && file.imports.get(root)?.imported === "createAutomation" && innermost && nameOf(innermost.callee) === root
665
- ? innermost
667
+ ? { call: innermost, finished: isHandlerCall(calls[0]) }
666
668
  : undefined;
667
669
  };
668
- const workflow = (id, node, call) => {
670
+ const workflow = (id, node, call, finished) => {
669
671
  exported.push({ id, file: file.path, node });
672
+ if (!finished) {
673
+ problems.push({
674
+ rule: "workflow-handler-missing",
675
+ severity: "error",
676
+ file: file.path,
677
+ ...(lineOf(node) && { line: lineOf(node) }),
678
+ message: `automation ${id}: give createAutomation its function with .handler(async (args) => { ... }), not in its config`,
679
+ });
680
+ }
670
681
  const config = resolveConst(file, call.arguments[0]);
671
682
  const trigger = config?.type === "ObjectExpression" ? readProperty(file, config, "trigger") : undefined;
672
683
  if (trigger?.type !== "ObjectExpression")
@@ -681,15 +692,26 @@ const workflowProblems = (files, kind) => {
681
692
  });
682
693
  return;
683
694
  }
684
- if (["every", "events", "subscribe"].some((key) => readProperty(file, trigger, key) !== undefined))
695
+ if (["every", "events"].some((key) => readProperty(file, trigger, key) !== undefined))
685
696
  return;
686
- problems.push({
687
- rule: "workflow-trigger-unregistered",
688
- severity: "error",
689
- file: file.path,
690
- ...(lineOf(node) && { line: lineOf(node) }),
691
- message: `automation ${id}: a provider trigger needs \`subscribe\` to register it with the provider`,
692
- });
697
+ if (readProperty(file, trigger, "subscribe") === undefined) {
698
+ problems.push({
699
+ rule: "workflow-trigger-unregistered",
700
+ severity: "error",
701
+ file: file.path,
702
+ ...(lineOf(node) && { line: lineOf(node) }),
703
+ message: `automation ${id}: a provider trigger needs \`subscribe\` to register it with the provider`,
704
+ });
705
+ }
706
+ else if (readProperty(file, trigger, "unsubscribe") === undefined) {
707
+ problems.push({
708
+ rule: "workflow-trigger-unsubscribe-missing",
709
+ severity: "error",
710
+ file: file.path,
711
+ ...(lineOf(node) && { line: lineOf(node) }),
712
+ message: `automation ${id}: a provider trigger needs \`unsubscribe\` too, or its registration outlives it`,
713
+ });
714
+ }
693
715
  };
694
716
  const locals = new Map();
695
717
  for (const statement of file.program.body) {
@@ -697,13 +719,13 @@ const workflowProblems = (files, kind) => {
697
719
  if (declaration?.type === "VariableDeclaration") {
698
720
  for (const declarator of declaration.declarations) {
699
721
  const name = nameOf(declarator.id);
700
- const call = createCall(declarator.init);
701
- if (!name || !call)
722
+ const created = createCall(declarator.init);
723
+ if (!name || !created)
702
724
  continue;
703
725
  if (statement.type === "ExportNamedDeclaration")
704
- workflow(name, declarator, call);
726
+ workflow(name, declarator, created.call, created.finished);
705
727
  else
706
- locals.set(name, { node: declarator, call });
728
+ locals.set(name, { node: declarator, ...created });
707
729
  }
708
730
  }
709
731
  if (statement.type === "ExportNamedDeclaration" && !statement.source) {
@@ -711,13 +733,13 @@ const workflowProblems = (files, kind) => {
711
733
  const local = locals.get(nameOf(specifier.local) ?? "");
712
734
  const id = nameOf(specifier.exported);
713
735
  if (local && id)
714
- workflow(id, specifier, local.call);
736
+ workflow(id, specifier, local.call, local.finished);
715
737
  }
716
738
  }
717
739
  if (statement.type === "ExportDefaultDeclaration") {
718
740
  const declared = statement.declaration;
719
- const call = createCall(declared) ?? (declared.type === "Identifier" ? locals.get(declared.name)?.call : undefined);
720
- if (call) {
741
+ const created = createCall(declared) ?? (declared.type === "Identifier" ? locals.get(declared.name) : undefined);
742
+ if (created) {
721
743
  problems.push({
722
744
  rule: "workflow-default-export",
723
745
  severity: "error",
@@ -765,7 +787,15 @@ const workflowProblems = (files, kind) => {
765
787
  return problems;
766
788
  };
767
789
  // What the build keeps out of the browser (zite()'s importProtection), by the specifier an app writes.
768
- const SERVER_ONLY_IMPORTS = [/^zitejs\/db$/, /^zitejs\/integrations(\/|$)/, /^zitejs\/email$/, /(^|\/)\.zite\/db(\.ts)?$/, /(^|\/)\.zite\/integrations(\/|$)/];
790
+ const SERVER_ONLY_IMPORTS = [
791
+ /^zitejs\/db$/,
792
+ /^zitejs\/integrations(\/|$)/,
793
+ /^zitejs\/email$/,
794
+ /^zitejs\/meta$/,
795
+ /(^|\/)\.zite\/db(\.ts)?$/,
796
+ /(^|\/)\.zite\/integrations(\/|$)/,
797
+ /(^|\/)\.zite\/meta(\.ts)?$/,
798
+ ];
769
799
  const isServerOnlyFile = (path) => /\.server(\.[^/]*)?$/.test(path.split("/").pop() ?? "");
770
800
  const SOURCE_EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", "/index.ts", "/index.tsx", "/index.js"];
771
801
  // As TypeScript and Vite read a .js specifier: the TypeScript file it compiles from.
@@ -849,14 +879,23 @@ const serverImportProblems = (files, factories, routerPath) => {
849
879
  pageRoots.forEach(visit);
850
880
  return problems;
851
881
  };
852
- const callsCreateZiteRouter = (file) => callsAny(file.program, (callee) => {
882
+ const isCreateZiteRouter = (file, callee) => {
853
883
  if (callee.type === "Identifier")
854
884
  return (file.imports.get(callee.name)?.imported ?? callee.name) === "createZiteRouter";
855
885
  const namespace = callee.type === "MemberExpression" && !callee.computed && nameOf(callee.property) === "createZiteRouter"
856
886
  ? file.imports.get(nameOf(callee.object) ?? "")
857
887
  : undefined;
858
888
  return namespace?.imported === "*" && namespace.source === "zitejs/start";
859
- });
889
+ };
890
+ const createZiteRouterCalls = (file) => {
891
+ const calls = [];
892
+ walk(file.program, (node, ancestors) => {
893
+ if (node.type === "CallExpression" && isNode(node.callee) && isCreateZiteRouter(file, node.callee)) {
894
+ calls.push({ node, atModuleScope: atModuleScope(ancestors) });
895
+ }
896
+ });
897
+ return calls;
898
+ };
860
899
  /** Every source hint for one Start app, given its files by app-relative path. */
861
900
  function sourceProblems(sources, { internal = false, kind } = {}) {
862
901
  const files = Object.entries(sources)
@@ -872,7 +911,8 @@ function sourceProblems(sources, { internal = false, kind } = {}) {
872
911
  // As Start finds it. One that doesn't parse is the typecheck's to report.
873
912
  const routerPath = routeTree_js_1.ENTRY_EXTENSIONS.map((extension) => `src/router${extension}`).find((path) => sources[path] !== undefined);
874
913
  const router = files.find((file) => file.path === routerPath);
875
- if (!routerPath || (router && !callsCreateZiteRouter(router))) {
914
+ const routerCalls = router ? createZiteRouterCalls(router) : [];
915
+ if (!routerPath || (router && routerCalls.length === 0)) {
876
916
  problems.push({
877
917
  rule: "router-file",
878
918
  severity: "error",
@@ -880,6 +920,10 @@ function sourceProblems(sources, { internal = false, kind } = {}) {
880
920
  message: `export getRouter from ${routerPath ?? "src/router.tsx"}, built with createZiteRouter from zitejs/start, which gives pages the signed-in user`,
881
921
  });
882
922
  }
923
+ const shared = routerCalls.find((call) => call.atModuleScope);
924
+ if (routerPath && shared) {
925
+ report("router-file", "error", routerPath, shared.node, `${routerPath} builds one router for every visitor, which shows each the first one's user and data; call createZiteRouter inside getRouter`);
926
+ }
883
927
  for (const file of files) {
884
928
  const { path, program } = file;
885
929
  const callsWorkflow = callsCreateWorkflow(program);
@@ -914,9 +958,17 @@ function sourceProblems(sources, { internal = false, kind } = {}) {
914
958
  report("classic-construct", "error", path, statement, `${module} is classic's; in a Start app, ${instead}`);
915
959
  }
916
960
  }
961
+ if (source === "zitejs/auth" && values !== "all") {
962
+ for (const name of values.filter((imported) => CLASSIC_AUTH_READS.has(imported))) {
963
+ report("classic-construct", "error", path, statement, `${name} is classic's; in a Start app, read the user from the router: context.user in beforeLoad and loaders, Route.useRouteContext() in a page, useRouteContext({ from: '__root__' }) in shared components`);
964
+ }
965
+ }
917
966
  if (source === "cloudflare:workers") {
918
967
  report("cloudflare-env", "error", path, statement, "read the app's environment from process.env, not cloudflare:workers");
919
968
  }
969
+ if (importsModule(source, "zitejs/signin")) {
970
+ report("platform-import", "error", path, statement, "zitejs/signin is the platform's sign-in client, which runs for you; send people to sign in with loginWithRedirect() from zitejs/auth, or a link to loginHref() from zitejs/start");
971
+ }
920
972
  const typeOnly = values !== "all" && values.length === 0;
921
973
  // Loading a module is fine without a request; only calling one of its server functions isn't.
922
974
  const target = callsWorkflow ? resolveImport(path, source, paths) : undefined;
package/dist/cjs/cli.js CHANGED
@@ -83,6 +83,12 @@ async function main() {
83
83
  console.error(' check Typecheck and build every app and automation; a Start app is typechecked with tsgo against its regenerated route tree and its source checked by rule (--json for a report)');
84
84
  console.error(' bundle Bundle endpoints (src/api/*.ts, or an automation\'s src/index.ts) for cloudflare-lambda');
85
85
  console.error(' describe Print what a built TanStack Start app declares: functions, routes, access');
86
+ console.error('');
87
+ console.error("A Start app under `vite dev` reaches Zite's data and services with these, from the app's .env:");
88
+ console.error(" ZITE_DEV_API_KEY Your Zite API key, as the MCP takes it: mints dev tokens for the app zite.config.json's id names; each lasts 15 minutes and is renewed before it expires");
89
+ console.error(' ZITE_DEV_TOKEN A dev token to use as it is instead, never renewed');
90
+ console.error(' ZITE_URLS JSON naming the platform: {"baseRunner","backend","aiGateway"?,"runs"?,"email"?,"pdf"?,"uploads"?,"steps"?}; a service it doesn\'t name is the backend\'s');
91
+ console.error(' ZITE_DEV_USER JSON of the signed-in stand-in: {"id","email","name"?,"roles"?,"isInternal"?}; unset, nobody is');
86
92
  process.exit(1);
87
93
  }
88
94
  }
@@ -9,6 +9,7 @@ const path_1 = require("path");
9
9
  const sourceRoots_js_1 = require("../sourceRoots.js");
10
10
  const entries_js_1 = require("../start/entries.js");
11
11
  const index_js_1 = require("../sync/index.js");
12
+ const signin_js_1 = require("./signin.js");
12
13
  const lib_js_1 = require("../sync/lib.js");
13
14
  const rules_js_1 = require("../integrations/rules.js");
14
15
  const debounceTimers = new Map();
@@ -240,6 +241,20 @@ async function runDev() {
240
241
  regenerateAppIntegrationsIndex(app);
241
242
  (0, entries_js_1.regenerateStartEntries)(app);
242
243
  }
244
+ // Sign-in under `vite dev`: each Start app's issuer, dev client and session secret.
245
+ for (const app of appDirs) {
246
+ if (!(0, entries_js_1.isStartAppDir)(app.path))
247
+ continue;
248
+ try {
249
+ const result = await (0, signin_js_1.writeDevSignIn)(app.path);
250
+ console.log(result.written
251
+ ? `Sign-in for ${app.path} under vite dev: ${result.clientId} at ${result.issuer}`
252
+ : `No sign-in for ${app.path} under vite dev: ${result.reason}`);
253
+ }
254
+ catch (err) {
255
+ console.warn(`Couldn't set up sign-in for ${app.path}:`, err instanceof Error ? err.message : err);
256
+ }
257
+ }
243
258
  // 3. Watch each dir's src/api/ for endpoint changes
244
259
  let watchingAny = false;
245
260
  for (const app of appDirs) {