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,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ziteAuth = ziteAuth;
4
+ const better_auth_1 = require("better-auth");
5
+ const plugins_1 = require("better-auth/plugins");
6
+ function ziteAuth(config = {}) {
7
+ const methods = config.authSettings?.methods ?? {};
8
+ const signup = config.authSettings?.signup ?? 'open';
9
+ const allowedDomains = config.authSettings?.domains ?? [];
10
+ const plugins = [
11
+ (0, plugins_1.genericOAuth)({
12
+ config: [
13
+ {
14
+ providerId: 'zite',
15
+ clientId: process.env.ZITE_OAUTH_CLIENT_ID,
16
+ clientSecret: process.env.ZITE_OAUTH_CLIENT_SECRET,
17
+ discoveryUrl: process.env.ZITE_AUTH_URL +
18
+ '/.well-known/openid-configuration',
19
+ },
20
+ ...(methods.googleSignIn !== false
21
+ ? [
22
+ {
23
+ providerId: 'google',
24
+ clientId: process.env.ZITE_GOOGLE_PROXY_CLIENT_ID,
25
+ clientSecret: process.env.ZITE_GOOGLE_PROXY_CLIENT_SECRET,
26
+ authorizationUrl: process.env.ZITE_AUTH_URL + '/proxy/google/authorize',
27
+ tokenUrl: process.env.ZITE_AUTH_URL + '/proxy/google/token',
28
+ },
29
+ ]
30
+ : []),
31
+ ],
32
+ }),
33
+ ];
34
+ if (methods.magicLink !== false) {
35
+ const sendMagicLinkEmail = config.sendEmail
36
+ ? async ({ email, url }) => {
37
+ await config.sendEmail(email, 'Sign in to your app', `Click here to sign in: ${url}`);
38
+ }
39
+ : async ({ email, url }) => {
40
+ console.log(`[ziteAuth] Magic link for ${email}: ${url}`);
41
+ };
42
+ plugins.push((0, plugins_1.magicLink)({ sendMagicLink: sendMagicLinkEmail }));
43
+ }
44
+ const domainCheckHook = signup === 'domain-restricted' && allowedDomains.length > 0
45
+ ? async (email) => {
46
+ const domain = email.split('@')[1]?.toLowerCase();
47
+ if (!domain || !allowedDomains.some(d => d.toLowerCase() === domain)) {
48
+ return false;
49
+ }
50
+ return config.beforeSignup ? config.beforeSignup(email) : true;
51
+ }
52
+ : signup === 'disabled'
53
+ ? async (_email) => false
54
+ : config.beforeSignup;
55
+ return (0, better_auth_1.betterAuth)({
56
+ database: { url: process.env.DATABASE_URL },
57
+ secret: process.env.ZITE_AUTH_SECRET || 'zite-local-dev-secret',
58
+ baseURL: 'http://localhost',
59
+ advanced: { disableCSRFCheck: true },
60
+ rateLimit: { window: 60, max: 10 },
61
+ emailAndPassword: { enabled: methods.emailPassword !== false },
62
+ plugins,
63
+ user: {
64
+ modelName: 'zite_user',
65
+ additionalFields: {
66
+ firstName: { type: 'string', required: false },
67
+ lastName: { type: 'string', required: false },
68
+ },
69
+ },
70
+ session: { modelName: 'zite_session' },
71
+ account: { modelName: 'zite_account' },
72
+ verification: { modelName: 'zite_verification' },
73
+ databaseHooks: {
74
+ user: {
75
+ create: {
76
+ before: domainCheckHook
77
+ ? async (user) => {
78
+ const allowed = await domainCheckHook(user.email);
79
+ if (!allowed) {
80
+ throw new Error('Signup not allowed for this email');
81
+ }
82
+ return undefined;
83
+ }
84
+ : undefined,
85
+ after: config.onSignup
86
+ ? async (user) => {
87
+ await config.onSignup({
88
+ id: user.id,
89
+ email: user.email,
90
+ name: user.name,
91
+ firstName: user.firstName,
92
+ lastName: user.lastName,
93
+ });
94
+ }
95
+ : undefined,
96
+ },
97
+ },
98
+ session: {
99
+ create: {
100
+ after: config.onLogin
101
+ ? async (session) => {
102
+ await config.onLogin({
103
+ id: session.userId,
104
+ email: '',
105
+ name: '',
106
+ });
107
+ }
108
+ : undefined,
109
+ },
110
+ },
111
+ },
112
+ });
113
+ }
@@ -23,10 +23,17 @@ const ENVIRONMENTS = {
23
23
  local: "http://localhost:2506",
24
24
  };
25
25
  function getRunnerUrl() {
26
+ const explicit = (0, env_js_1.getEnv)("ZITE_RUNNER_URL", "VITE_ZITE_RUNNER_URL");
27
+ if (explicit)
28
+ return explicit;
29
+ // Published apps use same-origin proxy (/api/*) — the CF worker
30
+ // forwards to the workflow-runner. This ensures cookies work and
31
+ // the browser sees a single origin.
32
+ if (getMode() === "live")
33
+ return "";
34
+ // Preview/editor mode: call the workflow-runner directly
26
35
  const env = (0, env_js_1.getEnv)("ZITE_ENV", "VITE_ZITE_ENV") ?? "production";
27
- return ((0, env_js_1.getEnv)("ZITE_RUNNER_URL", "VITE_ZITE_RUNNER_URL") ??
28
- ENVIRONMENTS[env] ??
29
- ENVIRONMENTS.production);
36
+ return ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
30
37
  }
31
38
  /**
32
39
  * Get the user's usage token for endpoint auth.
@@ -49,12 +56,18 @@ function getUsageToken() {
49
56
  }
50
57
  function buildFetchOptions(name, input, extra) {
51
58
  const appId = (0, env_js_1.getEnv)("ZITE_FLOW_ID", "VITE_ZITE_FLOW_ID") ?? "";
59
+ const runnerUrl = getRunnerUrl();
52
60
  const token = getUsageToken();
53
61
  const ziteAuthToken = typeof localStorage !== "undefined"
54
62
  ? localStorage.getItem("zite.auth.token")
55
63
  : null;
64
+ // Same-origin mode (published apps): /api/{name}
65
+ // Direct mode (preview): {runnerUrl}/public/{appId}/api/{name}
66
+ const url = runnerUrl === ""
67
+ ? "/api/" + name
68
+ : runnerUrl + "/public/" + appId + "/api/" + name;
56
69
  return {
57
- url: getRunnerUrl() + "/public/" + appId + "/api/" + name,
70
+ url,
58
71
  init: {
59
72
  method: "POST",
60
73
  headers: {
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTableClient = void 0;
4
+ var index_js_1 = require("../runtime/index.js");
5
+ Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
@@ -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;
@@ -188,7 +188,7 @@ function fieldJsdoc(schemaField, table) {
188
188
  *
189
189
  * If `existingSchema` is provided, locked SDK names are preserved for
190
190
  * tables/fields that already exist (matched by ID). New tables/fields
191
- * get fresh camelCase SDK names. This is how `zitejs sync` preserves
191
+ * get fresh camelCase SDK names. This is how `zitejs generate` preserves
192
192
  * name stability across schema changes.
193
193
  */
194
194
  function generateSchema(database, existingSchema) {
@@ -417,7 +417,7 @@ function generateApiTs(endpointFiles) {
417
417
  }
418
418
  const hasStreaming = endpoints.some((e) => e.stream);
419
419
  const lines = [
420
- "// Auto-generated by zitejs sync. Do not edit manually.",
420
+ "// Auto-generated by zitejs generate. Do not edit manually.",
421
421
  "",
422
422
  hasStreaming
423
423
  ? "import { createCaller, createStreamingCaller } from 'zitejs/caller';"
@@ -460,7 +460,7 @@ function tsTypeForField(field) {
460
460
  }
461
461
  function generateUserTs(usersTableFields) {
462
462
  const lines = [
463
- "// Auto-generated by zitejs sync. Do not edit manually.",
463
+ "// Auto-generated by zitejs generate. Do not edit manually.",
464
464
  "",
465
465
  ];
466
466
  if (usersTableFields && usersTableFields.length > 0) {
@@ -492,17 +492,11 @@ function generateUserTs(usersTableFields) {
492
492
  }
493
493
  function generateAuthWrapperTs() {
494
494
  return [
495
- "// Auto-generated type-narrowing wrapper. Do not edit manually.",
495
+ "// Auto-generated auth re-exports. Do not edit manually.",
496
496
  "// The real auth logic lives in the zitejs npm package (zitejs/auth).",
497
497
  "",
498
- "import { useAuth as _useAuth } from 'zitejs/auth/base';",
499
- "import type { User } from './user';",
500
- "",
501
- "export type { User };",
502
- "",
503
- "export function useAuth() {",
504
- " return _useAuth() as ReturnType<typeof _useAuth> & { user: User | undefined };",
505
- "}",
498
+ "export { useSession, signIn, signOut, signUp, loginWithRedirect, logout } from 'zitejs/auth';",
499
+ "export type { User } from 'zitejs/auth';",
506
500
  "",
507
501
  ].join("\n");
508
502
  }
@@ -0,0 +1,2 @@
1
+ export { createCaller } from '../caller/index.js';
2
+ export type { EndpointConfig } from '../caller/index.js';
@@ -0,0 +1 @@
1
+ export { createCaller } from '../caller/index.js';