zitejs 0.10.0-start.20 → 0.10.0-start.21
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/dist/cjs/auth/actions.d.ts +28 -0
- package/dist/cjs/auth/actions.js +93 -0
- package/dist/cjs/auth/client.d.ts +357 -0
- package/dist/cjs/auth/client.js +66 -0
- package/dist/cjs/auth/index.d.ts +2 -249
- package/dist/cjs/auth/index.js +11 -114
- package/dist/cjs/auth/index.test.js +18 -0
- package/dist/cjs/auth/profileUpdates.d.ts +9 -0
- package/dist/cjs/auth/profileUpdates.js +11 -0
- package/dist/cjs/check/start/sourceRules.js +70 -21
- package/dist/cjs/integrations/rules.js +5 -3
- package/dist/cjs/runtime/index.d.ts +54 -15
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +33 -0
- package/dist/cjs/sync/lib.js +10 -5
- package/dist/cjs/sync/lib.test.js +10 -0
- package/dist/esm/auth/actions.d.ts +28 -0
- package/dist/esm/auth/actions.js +55 -0
- package/dist/esm/auth/client.d.ts +357 -0
- package/dist/esm/auth/client.js +62 -0
- package/dist/esm/auth/index.d.ts +2 -249
- package/dist/esm/auth/index.js +2 -109
- package/dist/esm/auth/index.test.js +18 -0
- package/dist/esm/auth/profileUpdates.d.ts +9 -0
- package/dist/esm/auth/profileUpdates.js +6 -0
- package/dist/esm/check/start/sourceRules.js +70 -21
- package/dist/esm/integrations/rules.js +5 -3
- package/dist/esm/runtime/index.d.ts +54 -15
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +31 -0
- package/dist/esm/start/airtable/dispatch.js +3 -3
- package/dist/esm/start/airtable/formulas.d.ts +1 -1
- package/dist/esm/start/airtable/formulas.js +12 -10
- package/dist/esm/start/airtable/index.d.ts +2 -2
- package/dist/esm/start/describe.d.ts +8 -1
- package/dist/esm/start/describe.js +5 -3
- package/dist/esm/start/factories.test-d.d.ts +2 -1
- package/dist/esm/start/host.d.ts +2 -2
- package/dist/esm/start/index.d.ts +1 -1
- package/dist/esm/start/index.js +4 -2
- package/dist/esm/start/outbound.d.ts +2 -2
- package/dist/esm/start/outbound.js +3 -1
- package/dist/esm/start/router.d.ts +7 -0
- package/dist/esm/start/router.js +35 -0
- package/dist/esm/start/runLog.d.ts +2 -2
- package/dist/esm/start/scope.d.ts +3 -3
- package/dist/esm/start/server.d.ts +3 -3
- package/dist/esm/start/server.js +2 -1
- package/dist/esm/start/types.d.ts +1 -1
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/start/vite.js +3 -3
- package/dist/esm/start/workflow.d.ts +6 -2
- package/dist/esm/start/workflow.js +9 -2
- package/dist/esm/start/workflow.test-d.js +10 -1
- package/dist/esm/start/workflowRun.d.ts +5 -0
- package/dist/esm/start/workflowRun.js +11 -1
- package/dist/esm/sync/lib.js +10 -5
- package/dist/esm/sync/lib.test.js +10 -0
- package/package.json +1 -1
package/dist/cjs/auth/index.d.ts
CHANGED
|
@@ -1,252 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
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
|
package/dist/cjs/auth/index.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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"
|
|
695
|
+
if (["every", "events"].some((key) => readProperty(file, trigger, key) !== undefined))
|
|
685
696
|
return;
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
|
701
|
-
if (!name || !
|
|
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,
|
|
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
|
|
720
|
-
if (
|
|
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 = [
|
|
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
|
|
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
|
-
|
|
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,6 +958,11 @@ 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
|
}
|
|
@@ -75,8 +75,8 @@ const FIELDS_BY_TYPE = {
|
|
|
75
75
|
// one host to call.
|
|
76
76
|
pipedrive: extras("apiBaseUrl"),
|
|
77
77
|
// Shopify has no global API host: every call goes to the store's own domain
|
|
78
|
-
// under a pinned API version. The storefront pair is the shopper-facing API
|
|
79
|
-
//
|
|
78
|
+
// under a pinned API version. The storefront pair is the shopper-facing API;
|
|
79
|
+
// its URL comes from the store domain, so only the token can be missing.
|
|
80
80
|
shopify: extras("shopDomain", "apiBaseUrl", "storefrontApiUrl", "storefrontAccessToken"),
|
|
81
81
|
sharepoint: extras(),
|
|
82
82
|
excel: extras(),
|
|
@@ -96,7 +96,9 @@ exports.OPTIONAL_CREDENTIAL_FIELDS = {
|
|
|
96
96
|
// Only S3-compatible providers set an endpoint, and a prefix is opt-in.
|
|
97
97
|
amazonS3: ["endpoint", "pathPrefix"],
|
|
98
98
|
snowflake: ["warehouse"],
|
|
99
|
-
|
|
99
|
+
// A store that didn't grant the storefront scopes gets no token, and
|
|
100
|
+
// Shopify then serves the Storefront API tokenless.
|
|
101
|
+
shopify: ["storefrontAccessToken"],
|
|
100
102
|
};
|
|
101
103
|
/**
|
|
102
104
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|