zitejs 0.9.74 → 0.9.76

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.
@@ -0,0 +1,265 @@
1
+ export interface ZiteAuthUser {
2
+ id: string;
3
+ email: string;
4
+ name: string;
5
+ firstName?: string;
6
+ lastName?: string;
7
+ }
8
+ export interface ZiteAuthMethods {
9
+ emailPassword?: boolean;
10
+ magicLink?: boolean;
11
+ googleSignIn?: boolean;
12
+ sso?: boolean;
13
+ }
14
+ export interface ZiteAuthSettings {
15
+ methods?: ZiteAuthMethods;
16
+ signup?: 'disabled' | 'open' | 'domain-restricted';
17
+ domains?: string[];
18
+ }
19
+ export interface ZiteAuthConfig {
20
+ flowPublicId?: string;
21
+ authSettings?: ZiteAuthSettings;
22
+ onSignup?: (user: ZiteAuthUser) => Promise<void>;
23
+ onLogin?: (user: ZiteAuthUser) => Promise<void>;
24
+ beforeSignup?: (email: string) => Promise<boolean>;
25
+ sendEmail?: (to: string, subject: string, body: string) => Promise<void>;
26
+ }
27
+ export declare function ziteAuth(config?: ZiteAuthConfig): import("better-auth").Auth<{
28
+ database: {
29
+ url: string;
30
+ };
31
+ secret: string;
32
+ baseURL: string;
33
+ advanced: {
34
+ disableCSRFCheck: true;
35
+ };
36
+ rateLimit: {
37
+ window: number;
38
+ max: number;
39
+ };
40
+ emailAndPassword: {
41
+ enabled: boolean;
42
+ };
43
+ plugins: {
44
+ id: "generic-oauth";
45
+ version: string;
46
+ init: (ctx: import("better-auth").AuthContext) => {
47
+ context: {
48
+ socialProviders: import("better-auth").OAuthProvider<Record<string, any>, Partial<import("better-auth").ProviderOptions<any>>>[];
49
+ };
50
+ };
51
+ endpoints: {
52
+ signInWithOAuth2: import("better-auth").StrictEndpoint<"/sign-in/oauth2", {
53
+ method: "POST";
54
+ body: import("better-auth").ZodObject<{
55
+ providerId: import("better-auth").ZodString;
56
+ callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
57
+ errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
58
+ newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
59
+ disableRedirect: import("better-auth").ZodOptional<import("better-auth").ZodBoolean>;
60
+ scopes: import("better-auth").ZodOptional<import("better-auth").ZodArray<import("better-auth").ZodString>>;
61
+ requestSignUp: import("better-auth").ZodOptional<import("better-auth").ZodBoolean>;
62
+ additionalData: import("better-auth").ZodOptional<import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
63
+ }, import("zod/v4/core").$strip>;
64
+ metadata: {
65
+ openapi: {
66
+ description: string;
67
+ responses: {
68
+ 200: {
69
+ description: string;
70
+ content: {
71
+ "application/json": {
72
+ schema: {
73
+ type: "object";
74
+ properties: {
75
+ url: {
76
+ type: string;
77
+ };
78
+ redirect: {
79
+ type: string;
80
+ };
81
+ };
82
+ };
83
+ };
84
+ };
85
+ };
86
+ };
87
+ };
88
+ };
89
+ }, {
90
+ url: string;
91
+ redirect: boolean;
92
+ }>;
93
+ oAuth2Callback: import("better-auth").StrictEndpoint<"/oauth2/callback/:providerId", {
94
+ method: "GET";
95
+ query: import("better-auth").ZodObject<{
96
+ code: import("better-auth").ZodOptional<import("better-auth").ZodString>;
97
+ error: import("better-auth").ZodOptional<import("better-auth").ZodString>;
98
+ error_description: import("better-auth").ZodOptional<import("better-auth").ZodString>;
99
+ state: import("better-auth").ZodOptional<import("better-auth").ZodString>;
100
+ iss: import("better-auth").ZodOptional<import("better-auth").ZodString>;
101
+ }, import("zod/v4/core").$strip>;
102
+ metadata: {
103
+ allowedMediaTypes: string[];
104
+ openapi: {
105
+ description: string;
106
+ responses: {
107
+ 200: {
108
+ description: string;
109
+ content: {
110
+ "application/json": {
111
+ schema: {
112
+ type: "object";
113
+ properties: {
114
+ url: {
115
+ type: string;
116
+ };
117
+ };
118
+ };
119
+ };
120
+ };
121
+ };
122
+ };
123
+ };
124
+ scope: "server";
125
+ };
126
+ }, never>;
127
+ oAuth2LinkAccount: import("better-auth").StrictEndpoint<"/oauth2/link", {
128
+ method: "POST";
129
+ body: import("better-auth").ZodObject<{
130
+ providerId: import("better-auth").ZodString;
131
+ callbackURL: import("better-auth").ZodString;
132
+ scopes: import("better-auth").ZodOptional<import("better-auth").ZodArray<import("better-auth").ZodString>>;
133
+ errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
134
+ }, import("zod/v4/core").$strip>;
135
+ use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
136
+ session: {
137
+ session: Record<string, any> & {
138
+ id: string;
139
+ createdAt: Date;
140
+ updatedAt: Date;
141
+ userId: string;
142
+ expiresAt: Date;
143
+ token: string;
144
+ ipAddress?: string | null | undefined;
145
+ userAgent?: string | null | undefined;
146
+ };
147
+ user: Record<string, any> & {
148
+ id: string;
149
+ createdAt: Date;
150
+ updatedAt: Date;
151
+ email: string;
152
+ emailVerified: boolean;
153
+ name: string;
154
+ image?: string | null | undefined;
155
+ };
156
+ };
157
+ }>)[];
158
+ metadata: {
159
+ openapi: {
160
+ description: string;
161
+ responses: {
162
+ "200": {
163
+ description: string;
164
+ content: {
165
+ "application/json": {
166
+ schema: {
167
+ type: "object";
168
+ properties: {
169
+ url: {
170
+ type: string;
171
+ format: string;
172
+ description: string;
173
+ };
174
+ redirect: {
175
+ type: string;
176
+ description: string;
177
+ enum: boolean[];
178
+ };
179
+ };
180
+ required: string[];
181
+ };
182
+ };
183
+ };
184
+ };
185
+ };
186
+ };
187
+ };
188
+ }, {
189
+ url: string;
190
+ redirect: boolean;
191
+ }>;
192
+ };
193
+ options: import("better-auth/plugins").GenericOAuthOptions;
194
+ $ERROR_CODES: {
195
+ INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
196
+ TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
197
+ PROVIDER_CONFIG_NOT_FOUND: import("better-auth").RawError<"PROVIDER_CONFIG_NOT_FOUND">;
198
+ PROVIDER_ID_REQUIRED: import("better-auth").RawError<"PROVIDER_ID_REQUIRED">;
199
+ INVALID_OAUTH_CONFIG: import("better-auth").RawError<"INVALID_OAUTH_CONFIG">;
200
+ SESSION_REQUIRED: import("better-auth").RawError<"SESSION_REQUIRED">;
201
+ ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
202
+ ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
203
+ };
204
+ }[];
205
+ user: {
206
+ modelName: "zite_user";
207
+ additionalFields: {
208
+ firstName: {
209
+ type: "string";
210
+ required: false;
211
+ };
212
+ lastName: {
213
+ type: "string";
214
+ required: false;
215
+ };
216
+ };
217
+ };
218
+ session: {
219
+ modelName: "zite_session";
220
+ };
221
+ account: {
222
+ modelName: "zite_account";
223
+ };
224
+ verification: {
225
+ modelName: "zite_verification";
226
+ };
227
+ databaseHooks: {
228
+ user: {
229
+ create: {
230
+ before: ((user: {
231
+ id: string;
232
+ createdAt: Date;
233
+ updatedAt: Date;
234
+ email: string;
235
+ emailVerified: boolean;
236
+ name: string;
237
+ image?: string | null | undefined;
238
+ } & Record<string, unknown>) => Promise<undefined>) | undefined;
239
+ after: ((user: {
240
+ id: string;
241
+ createdAt: Date;
242
+ updatedAt: Date;
243
+ email: string;
244
+ emailVerified: boolean;
245
+ name: string;
246
+ image?: string | null | undefined;
247
+ } & Record<string, unknown>) => Promise<void>) | undefined;
248
+ };
249
+ };
250
+ session: {
251
+ create: {
252
+ after: ((session: {
253
+ id: string;
254
+ createdAt: Date;
255
+ updatedAt: Date;
256
+ userId: string;
257
+ expiresAt: Date;
258
+ token: string;
259
+ ipAddress?: string | null | undefined;
260
+ userAgent?: string | null | undefined;
261
+ } & Record<string, unknown>) => Promise<void>) | undefined;
262
+ };
263
+ };
264
+ };
265
+ }>;
@@ -0,0 +1,110 @@
1
+ import { betterAuth } from 'better-auth';
2
+ import { genericOAuth, magicLink } from 'better-auth/plugins';
3
+ export function ziteAuth(config = {}) {
4
+ const methods = config.authSettings?.methods ?? {};
5
+ const signup = config.authSettings?.signup ?? 'open';
6
+ const allowedDomains = config.authSettings?.domains ?? [];
7
+ const plugins = [
8
+ genericOAuth({
9
+ config: [
10
+ {
11
+ providerId: 'zite',
12
+ clientId: process.env.ZITE_OAUTH_CLIENT_ID,
13
+ clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
14
+ discoveryUrl: process.env.ZITE_AUTH_URL +
15
+ '/.well-known/openid-configuration',
16
+ },
17
+ ...(methods.googleSignIn !== false
18
+ ? [
19
+ {
20
+ providerId: 'google',
21
+ clientId: process.env.ZITE_GOOGLE_PROXY_CLIENT_ID,
22
+ clientSecret: process.env.ZITE_GOOGLE_PROXY_CLIENT_SECRET,
23
+ authorizationUrl: process.env.ZITE_AUTH_URL + '/proxy/google/authorize',
24
+ tokenUrl: process.env.ZITE_AUTH_URL + '/proxy/google/token',
25
+ },
26
+ ]
27
+ : []),
28
+ ],
29
+ }),
30
+ ];
31
+ if (methods.magicLink !== false) {
32
+ const sendMagicLinkEmail = config.sendEmail
33
+ ? async ({ email, url }) => {
34
+ await config.sendEmail(email, 'Sign in to your app', `Click here to sign in: ${url}`);
35
+ }
36
+ : async ({ email, url }) => {
37
+ console.log(`[ziteAuth] Magic link for ${email}: ${url}`);
38
+ };
39
+ plugins.push(magicLink({ sendMagicLink: sendMagicLinkEmail }));
40
+ }
41
+ const domainCheckHook = signup === 'domain-restricted' && allowedDomains.length > 0
42
+ ? async (email) => {
43
+ const domain = email.split('@')[1]?.toLowerCase();
44
+ if (!domain || !allowedDomains.some(d => d.toLowerCase() === domain)) {
45
+ return false;
46
+ }
47
+ return config.beforeSignup ? config.beforeSignup(email) : true;
48
+ }
49
+ : signup === 'disabled'
50
+ ? async (_email) => false
51
+ : config.beforeSignup;
52
+ return betterAuth({
53
+ database: { url: process.env.DATABASE_URL },
54
+ secret: process.env.ZITE_AUTH_SECRET || 'zite-local-dev-secret',
55
+ baseURL: 'http://localhost',
56
+ advanced: { disableCSRFCheck: true },
57
+ rateLimit: { window: 60, max: 10 },
58
+ emailAndPassword: { enabled: methods.emailPassword !== false },
59
+ plugins,
60
+ user: {
61
+ modelName: 'zite_user',
62
+ additionalFields: {
63
+ firstName: { type: 'string', required: false },
64
+ lastName: { type: 'string', required: false },
65
+ },
66
+ },
67
+ session: { modelName: 'zite_session' },
68
+ account: { modelName: 'zite_account' },
69
+ verification: { modelName: 'zite_verification' },
70
+ databaseHooks: {
71
+ user: {
72
+ create: {
73
+ before: domainCheckHook
74
+ ? async (user) => {
75
+ const allowed = await domainCheckHook(user.email);
76
+ if (!allowed) {
77
+ throw new Error('Signup not allowed for this email');
78
+ }
79
+ return undefined;
80
+ }
81
+ : undefined,
82
+ after: config.onSignup
83
+ ? async (user) => {
84
+ await config.onSignup({
85
+ id: user.id,
86
+ email: user.email,
87
+ name: user.name,
88
+ firstName: user.firstName,
89
+ lastName: user.lastName,
90
+ });
91
+ }
92
+ : undefined,
93
+ },
94
+ },
95
+ session: {
96
+ create: {
97
+ after: config.onLogin
98
+ ? async (session) => {
99
+ await config.onLogin({
100
+ id: session.userId,
101
+ email: '',
102
+ name: '',
103
+ });
104
+ }
105
+ : undefined,
106
+ },
107
+ },
108
+ },
109
+ });
110
+ }
@@ -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 (getEnv("ZITE_RUNNER_URL", "VITE_ZITE_RUNNER_URL") ??
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: getRunnerUrl() + "/public/" + appId + "/api/" + name,
66
+ url,
54
67
  init: {
55
68
  method: "POST",
56
69
  headers: {
package/dist/esm/cli.js CHANGED
File without changes
@@ -0,0 +1,2 @@
1
+ export { createTableClient } from '../runtime/index.js';
2
+ export type { TableClient } from '../runtime/index.js';
@@ -0,0 +1 @@
1
+ export { createTableClient } from '../runtime/index.js';
@@ -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 sync` preserves
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;
@@ -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 sync` preserves
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 sync. Do not edit manually.",
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 sync. Do not edit manually.",
451
+ "// Auto-generated by zitejs generate. Do not edit manually.",
452
452
  "",
453
453
  ];
454
454
  if (usersTableFields && usersTableFields.length > 0) {
@@ -480,17 +480,11 @@ export function generateUserTs(usersTableFields) {
480
480
  }
481
481
  export function generateAuthWrapperTs() {
482
482
  return [
483
- "// Auto-generated type-narrowing wrapper. Do not edit manually.",
483
+ "// Auto-generated auth re-exports. Do not edit manually.",
484
484
  "// The real auth logic lives in the zitejs npm package (zitejs/auth).",
485
485
  "",
486
- "import { useAuth as _useAuth } from 'zitejs/auth/base';",
487
- "import type { User } from './user';",
488
- "",
489
- "export type { User };",
490
- "",
491
- "export function useAuth() {",
492
- " return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };",
493
- "}",
486
+ "export { useSession, signIn, signOut, signUp, loginWithRedirect, logout } from 'zitejs/auth';",
487
+ "export type { User } from 'zitejs/auth';",
494
488
  "",
495
489
  ].join("\n");
496
490
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.74",
3
+ "version": "0.9.76",
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",