zitejs 0.9.73 → 0.9.75
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/index.d.ts +224 -12
- package/dist/cjs/auth/index.js +5 -280
- package/dist/cjs/auth-server/index.d.ts +345 -0
- package/dist/cjs/auth-server/index.js +72 -0
- package/dist/cjs/backend/index.d.ts +7 -1
- package/dist/cjs/caller/index.js +17 -4
- package/dist/cjs/dev/index.js +13 -1
- package/dist/cjs/sync/lib.d.ts +2 -2
- package/dist/cjs/sync/lib.js +24 -5
- package/dist/esm/auth/index.d.ts +224 -12
- package/dist/esm/auth/index.js +4 -279
- package/dist/esm/auth-server/index.d.ts +345 -0
- package/dist/esm/auth-server/index.js +69 -0
- package/dist/esm/backend/index.d.ts +7 -1
- package/dist/esm/caller/index.js +17 -4
- package/dist/esm/dev/index.js +13 -1
- package/dist/esm/sync/lib.d.ts +2 -2
- package/dist/esm/sync/lib.js +24 -5
- package/package.json +11 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
export interface ZiteAuthUser {
|
|
2
|
+
id: string;
|
|
3
|
+
email: string;
|
|
4
|
+
name: string;
|
|
5
|
+
firstName?: string;
|
|
6
|
+
lastName?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ZiteAuthConfig {
|
|
9
|
+
flowPublicId?: string;
|
|
10
|
+
onSignup?: (user: ZiteAuthUser) => Promise<void>;
|
|
11
|
+
onLogin?: (user: ZiteAuthUser) => Promise<void>;
|
|
12
|
+
beforeSignup?: (email: string) => Promise<boolean>;
|
|
13
|
+
sendEmail?: (to: string, subject: string, body: string) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth").Auth<{
|
|
16
|
+
database: {
|
|
17
|
+
url: string;
|
|
18
|
+
};
|
|
19
|
+
secret: string;
|
|
20
|
+
baseURL: string;
|
|
21
|
+
advanced: {
|
|
22
|
+
disableCSRFCheck: true;
|
|
23
|
+
};
|
|
24
|
+
rateLimit: {
|
|
25
|
+
window: number;
|
|
26
|
+
max: number;
|
|
27
|
+
};
|
|
28
|
+
emailAndPassword: {
|
|
29
|
+
enabled: true;
|
|
30
|
+
};
|
|
31
|
+
plugins: [{
|
|
32
|
+
id: "generic-oauth";
|
|
33
|
+
version: string;
|
|
34
|
+
init: (ctx: import("better-auth").AuthContext) => {
|
|
35
|
+
context: {
|
|
36
|
+
socialProviders: import("better-auth").OAuthProvider<Record<string, any>, Partial<import("better-auth").ProviderOptions<any>>>[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
endpoints: {
|
|
40
|
+
signInWithOAuth2: import("better-auth").StrictEndpoint<"/sign-in/oauth2", {
|
|
41
|
+
method: "POST";
|
|
42
|
+
body: import("better-auth").ZodObject<{
|
|
43
|
+
providerId: import("better-auth").ZodString;
|
|
44
|
+
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
45
|
+
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
46
|
+
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
47
|
+
disableRedirect: import("better-auth").ZodOptional<import("better-auth").ZodBoolean>;
|
|
48
|
+
scopes: import("better-auth").ZodOptional<import("better-auth").ZodArray<import("better-auth").ZodString>>;
|
|
49
|
+
requestSignUp: import("better-auth").ZodOptional<import("better-auth").ZodBoolean>;
|
|
50
|
+
additionalData: import("better-auth").ZodOptional<import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
|
|
51
|
+
}, import("zod/v4/core").$strip>;
|
|
52
|
+
metadata: {
|
|
53
|
+
openapi: {
|
|
54
|
+
description: string;
|
|
55
|
+
responses: {
|
|
56
|
+
200: {
|
|
57
|
+
description: string;
|
|
58
|
+
content: {
|
|
59
|
+
"application/json": {
|
|
60
|
+
schema: {
|
|
61
|
+
type: "object";
|
|
62
|
+
properties: {
|
|
63
|
+
url: {
|
|
64
|
+
type: string;
|
|
65
|
+
};
|
|
66
|
+
redirect: {
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}, {
|
|
78
|
+
url: string;
|
|
79
|
+
redirect: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
oAuth2Callback: import("better-auth").StrictEndpoint<"/oauth2/callback/:providerId", {
|
|
82
|
+
method: "GET";
|
|
83
|
+
query: import("better-auth").ZodObject<{
|
|
84
|
+
code: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
85
|
+
error: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
86
|
+
error_description: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
87
|
+
state: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
88
|
+
iss: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
89
|
+
}, import("zod/v4/core").$strip>;
|
|
90
|
+
metadata: {
|
|
91
|
+
allowedMediaTypes: string[];
|
|
92
|
+
openapi: {
|
|
93
|
+
description: string;
|
|
94
|
+
responses: {
|
|
95
|
+
200: {
|
|
96
|
+
description: string;
|
|
97
|
+
content: {
|
|
98
|
+
"application/json": {
|
|
99
|
+
schema: {
|
|
100
|
+
type: "object";
|
|
101
|
+
properties: {
|
|
102
|
+
url: {
|
|
103
|
+
type: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
scope: "server";
|
|
113
|
+
};
|
|
114
|
+
}, never>;
|
|
115
|
+
oAuth2LinkAccount: import("better-auth").StrictEndpoint<"/oauth2/link", {
|
|
116
|
+
method: "POST";
|
|
117
|
+
body: import("better-auth").ZodObject<{
|
|
118
|
+
providerId: import("better-auth").ZodString;
|
|
119
|
+
callbackURL: import("better-auth").ZodString;
|
|
120
|
+
scopes: import("better-auth").ZodOptional<import("better-auth").ZodArray<import("better-auth").ZodString>>;
|
|
121
|
+
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
122
|
+
}, import("zod/v4/core").$strip>;
|
|
123
|
+
use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
124
|
+
session: {
|
|
125
|
+
session: Record<string, any> & {
|
|
126
|
+
id: string;
|
|
127
|
+
createdAt: Date;
|
|
128
|
+
updatedAt: Date;
|
|
129
|
+
userId: string;
|
|
130
|
+
expiresAt: Date;
|
|
131
|
+
token: string;
|
|
132
|
+
ipAddress?: string | null | undefined;
|
|
133
|
+
userAgent?: string | null | undefined;
|
|
134
|
+
};
|
|
135
|
+
user: Record<string, any> & {
|
|
136
|
+
id: string;
|
|
137
|
+
createdAt: Date;
|
|
138
|
+
updatedAt: Date;
|
|
139
|
+
email: string;
|
|
140
|
+
emailVerified: boolean;
|
|
141
|
+
name: string;
|
|
142
|
+
image?: string | null | undefined;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
}>)[];
|
|
146
|
+
metadata: {
|
|
147
|
+
openapi: {
|
|
148
|
+
description: string;
|
|
149
|
+
responses: {
|
|
150
|
+
"200": {
|
|
151
|
+
description: string;
|
|
152
|
+
content: {
|
|
153
|
+
"application/json": {
|
|
154
|
+
schema: {
|
|
155
|
+
type: "object";
|
|
156
|
+
properties: {
|
|
157
|
+
url: {
|
|
158
|
+
type: string;
|
|
159
|
+
format: string;
|
|
160
|
+
description: string;
|
|
161
|
+
};
|
|
162
|
+
redirect: {
|
|
163
|
+
type: string;
|
|
164
|
+
description: string;
|
|
165
|
+
enum: boolean[];
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
required: string[];
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
}, {
|
|
177
|
+
url: string;
|
|
178
|
+
redirect: boolean;
|
|
179
|
+
}>;
|
|
180
|
+
};
|
|
181
|
+
options: import("better-auth/plugins").GenericOAuthOptions;
|
|
182
|
+
$ERROR_CODES: {
|
|
183
|
+
INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
|
|
184
|
+
TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
|
|
185
|
+
PROVIDER_CONFIG_NOT_FOUND: import("better-auth").RawError<"PROVIDER_CONFIG_NOT_FOUND">;
|
|
186
|
+
PROVIDER_ID_REQUIRED: import("better-auth").RawError<"PROVIDER_ID_REQUIRED">;
|
|
187
|
+
INVALID_OAUTH_CONFIG: import("better-auth").RawError<"INVALID_OAUTH_CONFIG">;
|
|
188
|
+
SESSION_REQUIRED: import("better-auth").RawError<"SESSION_REQUIRED">;
|
|
189
|
+
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
190
|
+
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
191
|
+
};
|
|
192
|
+
}, {
|
|
193
|
+
id: "magic-link";
|
|
194
|
+
version: string;
|
|
195
|
+
endpoints: {
|
|
196
|
+
signInMagicLink: import("better-auth").StrictEndpoint<"/sign-in/magic-link", {
|
|
197
|
+
method: "POST";
|
|
198
|
+
requireHeaders: true;
|
|
199
|
+
body: import("better-auth").ZodObject<{
|
|
200
|
+
email: import("better-auth").ZodEmail;
|
|
201
|
+
name: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
202
|
+
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
203
|
+
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
204
|
+
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
205
|
+
metadata: import("better-auth").ZodOptional<import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
|
|
206
|
+
}, import("zod/v4/core").$strip>;
|
|
207
|
+
metadata: {
|
|
208
|
+
openapi: {
|
|
209
|
+
operationId: string;
|
|
210
|
+
description: string;
|
|
211
|
+
responses: {
|
|
212
|
+
200: {
|
|
213
|
+
description: string;
|
|
214
|
+
content: {
|
|
215
|
+
"application/json": {
|
|
216
|
+
schema: {
|
|
217
|
+
type: "object";
|
|
218
|
+
properties: {
|
|
219
|
+
status: {
|
|
220
|
+
type: string;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
}, {
|
|
231
|
+
status: boolean;
|
|
232
|
+
}>;
|
|
233
|
+
magicLinkVerify: import("better-auth").StrictEndpoint<"/magic-link/verify", {
|
|
234
|
+
method: "GET";
|
|
235
|
+
query: import("better-auth").ZodObject<{
|
|
236
|
+
token: import("better-auth").ZodString;
|
|
237
|
+
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
238
|
+
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
239
|
+
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
240
|
+
}, import("zod/v4/core").$strip>;
|
|
241
|
+
use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>)[];
|
|
242
|
+
requireHeaders: true;
|
|
243
|
+
metadata: {
|
|
244
|
+
openapi: {
|
|
245
|
+
operationId: string;
|
|
246
|
+
description: string;
|
|
247
|
+
responses: {
|
|
248
|
+
200: {
|
|
249
|
+
description: string;
|
|
250
|
+
content: {
|
|
251
|
+
"application/json": {
|
|
252
|
+
schema: {
|
|
253
|
+
type: "object";
|
|
254
|
+
properties: {
|
|
255
|
+
session: {
|
|
256
|
+
$ref: string;
|
|
257
|
+
};
|
|
258
|
+
user: {
|
|
259
|
+
$ref: string;
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
}, {
|
|
270
|
+
token: string;
|
|
271
|
+
user: {
|
|
272
|
+
id: string;
|
|
273
|
+
createdAt: Date;
|
|
274
|
+
updatedAt: Date;
|
|
275
|
+
email: string;
|
|
276
|
+
emailVerified: boolean;
|
|
277
|
+
name: string;
|
|
278
|
+
image?: string | null | undefined;
|
|
279
|
+
};
|
|
280
|
+
session: {
|
|
281
|
+
id: string;
|
|
282
|
+
createdAt: Date;
|
|
283
|
+
updatedAt: Date;
|
|
284
|
+
userId: string;
|
|
285
|
+
expiresAt: Date;
|
|
286
|
+
token: string;
|
|
287
|
+
ipAddress?: string | null | undefined;
|
|
288
|
+
userAgent?: string | null | undefined;
|
|
289
|
+
};
|
|
290
|
+
}>;
|
|
291
|
+
};
|
|
292
|
+
rateLimit: {
|
|
293
|
+
pathMatcher(path: string): boolean;
|
|
294
|
+
window: number;
|
|
295
|
+
max: number;
|
|
296
|
+
}[];
|
|
297
|
+
options: import("better-auth/plugins").MagicLinkOptions;
|
|
298
|
+
}];
|
|
299
|
+
user: {
|
|
300
|
+
modelName: "zite_user";
|
|
301
|
+
additionalFields: {
|
|
302
|
+
firstName: {
|
|
303
|
+
type: "string";
|
|
304
|
+
required: false;
|
|
305
|
+
};
|
|
306
|
+
lastName: {
|
|
307
|
+
type: "string";
|
|
308
|
+
required: false;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
session: {
|
|
313
|
+
modelName: "zite_session";
|
|
314
|
+
};
|
|
315
|
+
account: {
|
|
316
|
+
modelName: "zite_account";
|
|
317
|
+
};
|
|
318
|
+
verification: {
|
|
319
|
+
modelName: "zite_verification";
|
|
320
|
+
};
|
|
321
|
+
databaseHooks: {
|
|
322
|
+
user: {
|
|
323
|
+
create: {
|
|
324
|
+
before: ((user: {
|
|
325
|
+
id: string;
|
|
326
|
+
createdAt: Date;
|
|
327
|
+
updatedAt: Date;
|
|
328
|
+
email: string;
|
|
329
|
+
emailVerified: boolean;
|
|
330
|
+
name: string;
|
|
331
|
+
image?: string | null | undefined;
|
|
332
|
+
} & Record<string, unknown>) => Promise<undefined>) | undefined;
|
|
333
|
+
after: ((user: {
|
|
334
|
+
id: string;
|
|
335
|
+
createdAt: Date;
|
|
336
|
+
updatedAt: Date;
|
|
337
|
+
email: string;
|
|
338
|
+
emailVerified: boolean;
|
|
339
|
+
name: string;
|
|
340
|
+
image?: string | null | undefined;
|
|
341
|
+
} & Record<string, unknown>) => Promise<void>) | undefined;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
}>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { betterAuth } from 'better-auth';
|
|
2
|
+
import { genericOAuth, magicLink } from 'better-auth/plugins';
|
|
3
|
+
export function ziteAuth(config = {}) {
|
|
4
|
+
const sendMagicLinkEmail = config.sendEmail
|
|
5
|
+
? async ({ email, url }) => {
|
|
6
|
+
await config.sendEmail(email, 'Sign in to your app', `Click here to sign in: ${url}`);
|
|
7
|
+
}
|
|
8
|
+
: async ({ email, url }) => {
|
|
9
|
+
console.log(`[ziteAuth] Magic link for ${email}: ${url}`);
|
|
10
|
+
};
|
|
11
|
+
return betterAuth({
|
|
12
|
+
database: { url: process.env.DATABASE_URL },
|
|
13
|
+
secret: process.env.ZITE_AUTH_SECRET || 'zite-local-dev-secret',
|
|
14
|
+
baseURL: 'http://localhost',
|
|
15
|
+
advanced: { disableCSRFCheck: true },
|
|
16
|
+
rateLimit: { window: 60, max: 10 },
|
|
17
|
+
emailAndPassword: { enabled: true },
|
|
18
|
+
plugins: [
|
|
19
|
+
genericOAuth({
|
|
20
|
+
config: [
|
|
21
|
+
{
|
|
22
|
+
providerId: 'zite',
|
|
23
|
+
clientId: process.env.ZITE_OAUTH_CLIENT_ID,
|
|
24
|
+
clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
|
|
25
|
+
discoveryUrl: process.env.ZITE_AUTH_URL +
|
|
26
|
+
'/.well-known/openid-configuration',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
magicLink({ sendMagicLink: sendMagicLinkEmail }),
|
|
31
|
+
],
|
|
32
|
+
user: {
|
|
33
|
+
modelName: 'zite_user',
|
|
34
|
+
additionalFields: {
|
|
35
|
+
firstName: { type: 'string', required: false },
|
|
36
|
+
lastName: { type: 'string', required: false },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
session: { modelName: 'zite_session' },
|
|
40
|
+
account: { modelName: 'zite_account' },
|
|
41
|
+
verification: { modelName: 'zite_verification' },
|
|
42
|
+
databaseHooks: {
|
|
43
|
+
user: {
|
|
44
|
+
create: {
|
|
45
|
+
before: config.beforeSignup
|
|
46
|
+
? async (user) => {
|
|
47
|
+
const allowed = await config.beforeSignup(user.email);
|
|
48
|
+
if (!allowed) {
|
|
49
|
+
throw new Error('Signup not allowed for this email');
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
after: config.onSignup
|
|
55
|
+
? async (user) => {
|
|
56
|
+
await config.onSignup({
|
|
57
|
+
id: user.id,
|
|
58
|
+
email: user.email,
|
|
59
|
+
name: user.name,
|
|
60
|
+
firstName: user.firstName,
|
|
61
|
+
lastName: user.lastName,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
: undefined,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type { ZiteSchedule } from "../schedules/index.js";
|
|
2
|
+
export type { ZiteSchedule };
|
|
3
|
+
export type ZiteWebhook = {
|
|
4
|
+
paused?: boolean;
|
|
5
|
+
};
|
|
1
6
|
export interface ZiteRequestContext {
|
|
2
7
|
user: {
|
|
3
8
|
id: string;
|
|
@@ -31,6 +36,8 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
|
|
|
31
36
|
outputSchema?: SchemaLike<TOutput>;
|
|
32
37
|
stream?: TStream;
|
|
33
38
|
authenticated?: boolean;
|
|
39
|
+
schedule?: ZiteSchedule;
|
|
40
|
+
webhook?: ZiteWebhook;
|
|
34
41
|
execute: (params: {
|
|
35
42
|
input: TInput;
|
|
36
43
|
context: ZiteRequestContext | ZiteScheduledContext;
|
|
@@ -39,4 +46,3 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
|
|
|
39
46
|
} : {})) => Promise<TOutput> | TOutput;
|
|
40
47
|
}
|
|
41
48
|
export declare function createEndpoint<TInput = unknown, TOutput = unknown, TStream extends boolean = false>(config: EndpointConfig<TInput, TOutput, TStream>): EndpointConfig<TInput, TOutput, TStream>;
|
|
42
|
-
export {};
|
package/dist/esm/caller/index.js
CHANGED
|
@@ -19,10 +19,17 @@ const ENVIRONMENTS = {
|
|
|
19
19
|
local: "http://localhost:2506",
|
|
20
20
|
};
|
|
21
21
|
function getRunnerUrl() {
|
|
22
|
+
const explicit = getEnv("ZITE_RUNNER_URL", "VITE_ZITE_RUNNER_URL");
|
|
23
|
+
if (explicit)
|
|
24
|
+
return explicit;
|
|
25
|
+
// Published apps use same-origin proxy (/api/*) — the CF worker
|
|
26
|
+
// forwards to the workflow-runner. This ensures cookies work and
|
|
27
|
+
// the browser sees a single origin.
|
|
28
|
+
if (getMode() === "live")
|
|
29
|
+
return "";
|
|
30
|
+
// Preview/editor mode: call the workflow-runner directly
|
|
22
31
|
const env = getEnv("ZITE_ENV", "VITE_ZITE_ENV") ?? "production";
|
|
23
|
-
return
|
|
24
|
-
ENVIRONMENTS[env] ??
|
|
25
|
-
ENVIRONMENTS.production);
|
|
32
|
+
return ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
26
33
|
}
|
|
27
34
|
/**
|
|
28
35
|
* Get the user's usage token for endpoint auth.
|
|
@@ -45,12 +52,18 @@ function getUsageToken() {
|
|
|
45
52
|
}
|
|
46
53
|
function buildFetchOptions(name, input, extra) {
|
|
47
54
|
const appId = getEnv("ZITE_FLOW_ID", "VITE_ZITE_FLOW_ID") ?? "";
|
|
55
|
+
const runnerUrl = getRunnerUrl();
|
|
48
56
|
const token = getUsageToken();
|
|
49
57
|
const ziteAuthToken = typeof localStorage !== "undefined"
|
|
50
58
|
? localStorage.getItem("zite.auth.token")
|
|
51
59
|
: null;
|
|
60
|
+
// Same-origin mode (published apps): /api/{name}
|
|
61
|
+
// Direct mode (preview): {runnerUrl}/public/{appId}/api/{name}
|
|
62
|
+
const url = runnerUrl === ""
|
|
63
|
+
? "/api/" + name
|
|
64
|
+
: runnerUrl + "/public/" + appId + "/api/" + name;
|
|
52
65
|
return {
|
|
53
|
-
url
|
|
66
|
+
url,
|
|
54
67
|
init: {
|
|
55
68
|
method: "POST",
|
|
56
69
|
headers: {
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -48,6 +48,18 @@ function getEmailIntegrationId(appDir) {
|
|
|
48
48
|
catch { }
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
|
+
function getDeclaredEnvVarNames(appDir) {
|
|
52
|
+
try {
|
|
53
|
+
const configPath = join("apps", appDir, "zite.config.json");
|
|
54
|
+
if (!existsSync(configPath))
|
|
55
|
+
return [];
|
|
56
|
+
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
57
|
+
return Object.keys(config.envVars ?? {});
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
51
63
|
function regenerateAppTypedWrappers(appDir) {
|
|
52
64
|
const outDir = join("apps", appDir, ".zite");
|
|
53
65
|
mkdirSync(outDir, { recursive: true });
|
|
@@ -62,7 +74,7 @@ function regenerateAppTypedWrappers(appDir) {
|
|
|
62
74
|
mkdirSync(intDir, { recursive: true });
|
|
63
75
|
writeFileSync(join(intDir, "email.ts"), generateEmailSdk(emailIntegrationId));
|
|
64
76
|
}
|
|
65
|
-
writeFileSync(join(outDir, "backend.ts"), generateBackendWrapperTs());
|
|
77
|
+
writeFileSync(join(outDir, "backend.ts"), generateBackendWrapperTs(getDeclaredEnvVarNames(appDir)));
|
|
66
78
|
}
|
|
67
79
|
function regenerateAppApiTs(appDir) {
|
|
68
80
|
const apiDir = join("apps", appDir, "src", "api");
|
package/dist/esm/sync/lib.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare function toCamelCase(name: string): string;
|
|
|
21
21
|
*
|
|
22
22
|
* If `existingSchema` is provided, locked SDK names are preserved for
|
|
23
23
|
* tables/fields that already exist (matched by ID). New tables/fields
|
|
24
|
-
* get fresh camelCase SDK names. This is how `zitejs
|
|
24
|
+
* get fresh camelCase SDK names. This is how `zitejs generate` preserves
|
|
25
25
|
* name stability across schema changes.
|
|
26
26
|
*/
|
|
27
27
|
export declare function generateSchema(database: Database, existingSchema?: ZiteSchema): ZiteSchema;
|
|
@@ -58,7 +58,7 @@ export type AirtableLock = {
|
|
|
58
58
|
tables: AirtableLockTable[];
|
|
59
59
|
};
|
|
60
60
|
export declare function generateAirtableTs(lock: AirtableLock): string | null;
|
|
61
|
-
export declare function generateBackendWrapperTs(): string;
|
|
61
|
+
export declare function generateBackendWrapperTs(envVarNames?: string[]): string;
|
|
62
62
|
/**
|
|
63
63
|
* Generate `.zite/integrations/email.ts` — the `Email` client for an app with
|
|
64
64
|
* an email integration connected. Mirrors the airtable SDK generation: a thin
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -176,7 +176,7 @@ function fieldJsdoc(schemaField, table) {
|
|
|
176
176
|
*
|
|
177
177
|
* If `existingSchema` is provided, locked SDK names are preserved for
|
|
178
178
|
* tables/fields that already exist (matched by ID). New tables/fields
|
|
179
|
-
* get fresh camelCase SDK names. This is how `zitejs
|
|
179
|
+
* get fresh camelCase SDK names. This is how `zitejs generate` preserves
|
|
180
180
|
* name stability across schema changes.
|
|
181
181
|
*/
|
|
182
182
|
export function generateSchema(database, existingSchema) {
|
|
@@ -405,7 +405,7 @@ export function generateApiTs(endpointFiles) {
|
|
|
405
405
|
}
|
|
406
406
|
const hasStreaming = endpoints.some((e) => e.stream);
|
|
407
407
|
const lines = [
|
|
408
|
-
"// Auto-generated by zitejs
|
|
408
|
+
"// Auto-generated by zitejs generate. Do not edit manually.",
|
|
409
409
|
"",
|
|
410
410
|
hasStreaming
|
|
411
411
|
? "import { createCaller, createStreamingCaller } from 'zitejs/caller';"
|
|
@@ -448,7 +448,7 @@ function tsTypeForField(field) {
|
|
|
448
448
|
}
|
|
449
449
|
export function generateUserTs(usersTableFields) {
|
|
450
450
|
const lines = [
|
|
451
|
-
"// Auto-generated by zitejs
|
|
451
|
+
"// Auto-generated by zitejs generate. Do not edit manually.",
|
|
452
452
|
"",
|
|
453
453
|
];
|
|
454
454
|
if (usersTableFields && usersTableFields.length > 0) {
|
|
@@ -688,14 +688,20 @@ export function generateAirtableTs(lock) {
|
|
|
688
688
|
}
|
|
689
689
|
return lines.join("\n");
|
|
690
690
|
}
|
|
691
|
-
export function generateBackendWrapperTs() {
|
|
691
|
+
export function generateBackendWrapperTs(envVarNames = []) {
|
|
692
|
+
const names = [
|
|
693
|
+
"ZITE_APP_URL",
|
|
694
|
+
...envVarNames.filter((n) => n !== "ZITE_APP_URL"),
|
|
695
|
+
];
|
|
692
696
|
return [
|
|
693
697
|
"// Auto-generated type-narrowing wrapper. Do not edit manually.",
|
|
694
698
|
"// Re-exports createEndpoint with context.user typed to the app User.",
|
|
695
699
|
"",
|
|
696
|
-
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext as _ZiteScheduledContext } from 'zitejs/backend/base';",
|
|
700
|
+
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext as _ZiteScheduledContext, ZiteSchedule, ZiteWebhook } from 'zitejs/backend/base';",
|
|
697
701
|
"import type { User } from './user';",
|
|
698
702
|
"",
|
|
703
|
+
"export type { ZiteSchedule, ZiteWebhook };",
|
|
704
|
+
"",
|
|
699
705
|
"export class ZiteError extends Error {",
|
|
700
706
|
" statusCode: number;",
|
|
701
707
|
" constructor(message: string, options?: { statusCode?: number }) {",
|
|
@@ -722,6 +728,8 @@ export function generateBackendWrapperTs() {
|
|
|
722
728
|
" outputSchema?: SchemaLike<TOutput>;",
|
|
723
729
|
" stream?: boolean;",
|
|
724
730
|
" authenticated?: boolean;",
|
|
731
|
+
" schedule?: ZiteSchedule;",
|
|
732
|
+
" webhook?: ZiteWebhook;",
|
|
725
733
|
" execute: (params: { input: TInput; context: ZiteRequestContext | ZiteScheduledContext }) => Promise<TOutput> | TOutput;",
|
|
726
734
|
"}",
|
|
727
735
|
"",
|
|
@@ -731,6 +739,17 @@ export function generateBackendWrapperTs() {
|
|
|
731
739
|
" return config;",
|
|
732
740
|
"}",
|
|
733
741
|
"",
|
|
742
|
+
// Declared in the wrapper (not a standalone .d.ts) so the merge is
|
|
743
|
+
// guaranteed to be in the program — every endpoint imports this file,
|
|
744
|
+
// while tsconfig `include` does not reliably pick up dot-directories.
|
|
745
|
+
"declare global {",
|
|
746
|
+
" namespace NodeJS {",
|
|
747
|
+
" interface ProcessEnv {",
|
|
748
|
+
...names.map((name) => ` ${JSON.stringify(name)}: string;`),
|
|
749
|
+
" }",
|
|
750
|
+
" }",
|
|
751
|
+
"}",
|
|
752
|
+
"",
|
|
734
753
|
].join("\n");
|
|
735
754
|
}
|
|
736
755
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.75",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
"import": "./dist/esm/auth/index.js",
|
|
48
48
|
"require": "./dist/cjs/auth/index.js"
|
|
49
49
|
},
|
|
50
|
+
"./auth-server": {
|
|
51
|
+
"types": "./dist/esm/auth-server/index.d.ts",
|
|
52
|
+
"import": "./dist/esm/auth-server/index.js",
|
|
53
|
+
"require": "./dist/cjs/auth-server/index.js",
|
|
54
|
+
"default": "./dist/esm/auth-server/index.js"
|
|
55
|
+
},
|
|
50
56
|
"./upload": {
|
|
51
57
|
"types": "./dist/esm/upload/index.d.ts",
|
|
52
58
|
"import": "./dist/esm/upload/index.js",
|
|
@@ -105,6 +111,9 @@
|
|
|
105
111
|
"caller": [
|
|
106
112
|
"dist/esm/caller/index.d.ts"
|
|
107
113
|
],
|
|
114
|
+
"auth-server": [
|
|
115
|
+
"dist/esm/auth-server/index.d.ts"
|
|
116
|
+
],
|
|
108
117
|
"backend": [
|
|
109
118
|
"dist/esm/backend/index.d.ts"
|
|
110
119
|
],
|
|
@@ -175,6 +184,7 @@
|
|
|
175
184
|
},
|
|
176
185
|
"dependencies": {
|
|
177
186
|
"@babel/parser": "^7.29.7",
|
|
187
|
+
"better-auth": "1.6.23",
|
|
178
188
|
"dotenv": "^17.4.2",
|
|
179
189
|
"esbuild": "^0.28.0",
|
|
180
190
|
"estree-walker": "^3.0.3",
|