zitejs 0.9.92 → 0.9.94
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/api/index.js +5 -0
- package/dist/cjs/auth/server.d.ts +66 -0
- package/dist/cjs/auth/server.js +16 -0
- package/dist/cjs/bundle/index.js +86 -12
- package/dist/cjs/db/index.js +5 -0
- package/dist/cjs/dev/index.js +9 -0
- package/dist/cjs/meta/index.d.ts +14 -0
- package/dist/cjs/meta/index.js +12 -0
- package/dist/cjs/runtime/index.d.ts +7 -0
- package/dist/cjs/sync/index.js +5 -0
- package/dist/cjs/sync/lib.js +3 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/api/index.js +1 -0
- package/dist/esm/auth/server.d.ts +66 -0
- package/dist/esm/auth/server.js +12 -0
- package/dist/esm/bundle/index.js +86 -12
- package/dist/esm/cli.js +0 -0
- package/dist/esm/db/index.d.ts +2 -0
- package/dist/esm/db/index.js +1 -0
- package/dist/esm/dev/index.js +9 -0
- package/dist/esm/meta/index.d.ts +14 -0
- package/dist/esm/meta/index.js +8 -0
- package/dist/esm/runtime/index.d.ts +7 -0
- package/dist/esm/sync/index.js +5 -0
- package/dist/esm/sync/lib.js +3 -0
- package/package.json +7 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCaller = void 0;
|
|
4
|
+
var index_js_1 = require("../caller/index.js");
|
|
5
|
+
Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side auth hooks — the `ziteAuth({ hooks })` config an app
|
|
3
|
+
* default-exports from `zite.auth.ts` (app root). The platform bundles that
|
|
4
|
+
* file at build time and invokes the hooks at auth lifecycle moments
|
|
5
|
+
* (sign-up, sign-in, session checks). Hooks run like backend app code, so
|
|
6
|
+
* they can use the app's integrations and `zitejs/db`.
|
|
7
|
+
*
|
|
8
|
+
* All hooks fail open on error/timeout — a broken hook never locks users
|
|
9
|
+
* out. Gate hooks return allow / deny / defer; `verifySession` returns an
|
|
10
|
+
* active verdict and may enrich the app-visible user.
|
|
11
|
+
*/
|
|
12
|
+
export interface ZiteAuthHookUser {
|
|
13
|
+
id: string;
|
|
14
|
+
email: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* allow admits past disabled/domain-restricted signup; deny blocks with an
|
|
19
|
+
* optional reason; anything else (empty object / no return) defers to the
|
|
20
|
+
* platform rules.
|
|
21
|
+
*/
|
|
22
|
+
export type ZiteAuthGateDecision = {
|
|
23
|
+
allow: true;
|
|
24
|
+
} | {
|
|
25
|
+
deny: true;
|
|
26
|
+
reason?: string;
|
|
27
|
+
} | {
|
|
28
|
+
allow?: undefined;
|
|
29
|
+
deny?: undefined;
|
|
30
|
+
} | void;
|
|
31
|
+
/**
|
|
32
|
+
* active: false revokes the session; active: true keeps it, and `user`
|
|
33
|
+
* merges extra fields into the app-visible user.
|
|
34
|
+
*/
|
|
35
|
+
export type ZiteAuthSessionVerdict = {
|
|
36
|
+
active: false;
|
|
37
|
+
reason?: string;
|
|
38
|
+
} | {
|
|
39
|
+
active: true;
|
|
40
|
+
user?: Record<string, unknown>;
|
|
41
|
+
} | {
|
|
42
|
+
active?: undefined;
|
|
43
|
+
} | void;
|
|
44
|
+
export interface ZiteAuthHooks {
|
|
45
|
+
beforeSignUp?(input: {
|
|
46
|
+
email: string;
|
|
47
|
+
firstName?: string;
|
|
48
|
+
lastName?: string;
|
|
49
|
+
}): Promise<ZiteAuthGateDecision> | ZiteAuthGateDecision;
|
|
50
|
+
beforeSignIn?(input: {
|
|
51
|
+
email: string;
|
|
52
|
+
}): Promise<ZiteAuthGateDecision> | ZiteAuthGateDecision;
|
|
53
|
+
afterSignUp?(input: {
|
|
54
|
+
user: ZiteAuthHookUser;
|
|
55
|
+
}): Promise<unknown> | unknown;
|
|
56
|
+
afterSignIn?(input: {
|
|
57
|
+
user: ZiteAuthHookUser;
|
|
58
|
+
}): Promise<unknown> | unknown;
|
|
59
|
+
verifySession?(input: {
|
|
60
|
+
user: ZiteAuthHookUser;
|
|
61
|
+
}): Promise<ZiteAuthSessionVerdict> | ZiteAuthSessionVerdict;
|
|
62
|
+
}
|
|
63
|
+
export interface ZiteAuthConfig {
|
|
64
|
+
hooks?: ZiteAuthHooks;
|
|
65
|
+
}
|
|
66
|
+
export declare const ziteAuth: (config: ZiteAuthConfig) => ZiteAuthConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Server-side auth hooks — the `ziteAuth({ hooks })` config an app
|
|
4
|
+
* default-exports from `zite.auth.ts` (app root). The platform bundles that
|
|
5
|
+
* file at build time and invokes the hooks at auth lifecycle moments
|
|
6
|
+
* (sign-up, sign-in, session checks). Hooks run like backend app code, so
|
|
7
|
+
* they can use the app's integrations and `zitejs/db`.
|
|
8
|
+
*
|
|
9
|
+
* All hooks fail open on error/timeout — a broken hook never locks users
|
|
10
|
+
* out. Gate hooks return allow / deny / defer; `verifySession` returns an
|
|
11
|
+
* active verdict and may enrich the app-visible user.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.ziteAuth = void 0;
|
|
15
|
+
const ziteAuth = (config) => config;
|
|
16
|
+
exports.ziteAuth = ziteAuth;
|
package/dist/cjs/bundle/index.js
CHANGED
|
@@ -268,6 +268,16 @@ function createAliasPlugin(opts) {
|
|
|
268
268
|
}
|
|
269
269
|
return { path: 'zitejs/email', external: true };
|
|
270
270
|
});
|
|
271
|
+
// zitejs/auth/server is types + an identity wrapper — inline a shim so
|
|
272
|
+
// zite.auth.ts bundles without resolving the installed package.
|
|
273
|
+
build.onResolve({ filter: /^zitejs\/auth\/server$/ }, () => ({
|
|
274
|
+
path: 'zitejs-auth-server-shim',
|
|
275
|
+
namespace: 'zite-virtual',
|
|
276
|
+
}));
|
|
277
|
+
build.onLoad({ filter: /.*/, namespace: 'zite-virtual' }, () => ({
|
|
278
|
+
contents: 'export const ziteAuth = (config) => config;',
|
|
279
|
+
loader: 'js',
|
|
280
|
+
}));
|
|
271
281
|
// zitejs/runtime is NOT in PREBUNDLED_LIBS — it's a thin fetch()
|
|
272
282
|
// wrapper that gets bundled inline by esbuild (no special handling).
|
|
273
283
|
for (const [pkgName, modulePath] of Object.entries(PREBUNDLED_LIBS)) {
|
|
@@ -392,9 +402,78 @@ async function bundleEndpointsImpl(baseDir, endpointNames) {
|
|
|
392
402
|
}
|
|
393
403
|
}
|
|
394
404
|
}
|
|
405
|
+
let bundledAuthHooks;
|
|
406
|
+
let authHooksError;
|
|
407
|
+
if (fs.existsSync(path.join(baseDir, 'zite.auth.ts'))) {
|
|
408
|
+
const runtimeInit = `import { __wrapSdkCall, initRuntime } from '@zite/endpoints-runtime-sdk';
|
|
409
|
+
globalThis.__wrapSdkCall = __wrapSdkCall;
|
|
410
|
+
initRuntime();`;
|
|
411
|
+
const dispatcherCode = `
|
|
412
|
+
${runtimeInit}
|
|
413
|
+
import { z } from 'zod';
|
|
414
|
+
import { createEndpoint } from '${sdkSource}';
|
|
415
|
+
import auth from '../zite.auth';
|
|
416
|
+
|
|
417
|
+
const endpoint = createEndpoint({
|
|
418
|
+
description: 'Runs the auth lifecycle hooks defined in zite.auth.ts',
|
|
419
|
+
inputSchema: z.object({
|
|
420
|
+
hook: z.enum([
|
|
421
|
+
'beforeSignUp',
|
|
422
|
+
'afterSignUp',
|
|
423
|
+
'beforeSignIn',
|
|
424
|
+
'afterSignIn',
|
|
425
|
+
'verifySession',
|
|
426
|
+
]),
|
|
427
|
+
payload: z.record(z.unknown()).default({}),
|
|
428
|
+
}),
|
|
429
|
+
execute: async ({ input }) => {
|
|
430
|
+
const hook = auth.hooks?.[input.hook];
|
|
431
|
+
if (!hook) return {};
|
|
432
|
+
return (await hook(input.payload as never)) ?? {};
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
globalThis.__endpoint = endpoint;
|
|
436
|
+
`;
|
|
437
|
+
try {
|
|
438
|
+
const result = await esbuild.build({
|
|
439
|
+
...BASE_BUILD_OPTIONS,
|
|
440
|
+
stdin: {
|
|
441
|
+
contents: dispatcherCode,
|
|
442
|
+
resolveDir: `${baseDir}/src`,
|
|
443
|
+
loader: 'ts',
|
|
444
|
+
},
|
|
445
|
+
logLevel: 'warning',
|
|
446
|
+
plugins: [aliasPlugin],
|
|
447
|
+
});
|
|
448
|
+
if (result.outputFiles && result.outputFiles.length > 0) {
|
|
449
|
+
bundledAuthHooks = result.outputFiles[0].text;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
authHooksError = 'No output generated';
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
catch (err) {
|
|
456
|
+
const e = err;
|
|
457
|
+
if (e.errors && Array.isArray(e.errors)) {
|
|
458
|
+
authHooksError = e.errors
|
|
459
|
+
.map(er => {
|
|
460
|
+
const loc = er.location
|
|
461
|
+
? `${er.location.file || 'unknown'}:${er.location.line || '?'}:${er.location.column || '?'}`
|
|
462
|
+
: 'unknown';
|
|
463
|
+
return `${loc} - ${er.text}`;
|
|
464
|
+
})
|
|
465
|
+
.join('\n');
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
authHooksError = e.message || String(err);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
395
472
|
const output = JSON.stringify({
|
|
396
473
|
bundledEndpoints,
|
|
397
474
|
endpointErrors: Object.keys(endpointErrors).length > 0 ? endpointErrors : undefined,
|
|
475
|
+
bundledAuthHooks,
|
|
476
|
+
authHooksError,
|
|
398
477
|
});
|
|
399
478
|
fs.writeFileSync('/tmp/zitejs-bundle-result.json', output);
|
|
400
479
|
console.log(output);
|
|
@@ -504,18 +583,13 @@ async function runBundle() {
|
|
|
504
583
|
}
|
|
505
584
|
else {
|
|
506
585
|
const apiDir = path.join(baseDir, 'src', 'api');
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
.filter(f => f.endsWith('.ts'))
|
|
514
|
-
.map(f => f.replace('.ts', ''));
|
|
515
|
-
}
|
|
516
|
-
if (endpointNames.length === 0) {
|
|
517
|
-
console.log(JSON.stringify({ bundledEndpoints: {} }));
|
|
518
|
-
return;
|
|
586
|
+
endpointNames = fs.existsSync(apiDir)
|
|
587
|
+
? fs
|
|
588
|
+
.readdirSync(apiDir)
|
|
589
|
+
.filter(f => f.endsWith('.ts'))
|
|
590
|
+
.map(f => f.replace('.ts', ''))
|
|
591
|
+
: [];
|
|
519
592
|
}
|
|
593
|
+
// Even with no endpoints, zite.auth.ts may still need bundling.
|
|
520
594
|
return bundleEndpointsImpl(baseDir, endpointNames);
|
|
521
595
|
}
|
|
@@ -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; } });
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -83,8 +83,17 @@ function regenerateAppApiTs(appDir) {
|
|
|
83
83
|
const apiDir = (0, path_1.join)("apps", appDir, "src", "api");
|
|
84
84
|
if (!(0, fs_2.existsSync)(apiDir))
|
|
85
85
|
return;
|
|
86
|
+
// Sorted because `readdir` order is unspecified — it is whatever the
|
|
87
|
+
// filesystem returns. `generateApiTs` emits one import, one type block and
|
|
88
|
+
// one `api` key per endpoint IN THIS ORDER, and those declarations are
|
|
89
|
+
// order-independent, so a reshuffle produces a byte-different file that
|
|
90
|
+
// compiles to an identical program. Git cannot tell that apart from a real
|
|
91
|
+
// change: the app lands in the rebuild set and rebuilds for nothing, and a
|
|
92
|
+
// genuine one-endpoint addition shows up as a rewrite of the whole file
|
|
93
|
+
// instead of a few added lines.
|
|
86
94
|
const endpointFiles = (0, fs_2.readdirSync)(apiDir)
|
|
87
95
|
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
|
|
96
|
+
.sort()
|
|
88
97
|
.map((f) => ({
|
|
89
98
|
fileName: f,
|
|
90
99
|
content: (0, fs_2.readFileSync)((0, path_1.join)(apiDir, f), "utf-8"),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ZiteProjectUser = {
|
|
2
|
+
uuid: string;
|
|
3
|
+
firstName: string | null;
|
|
4
|
+
lastName: string | null;
|
|
5
|
+
email: string;
|
|
6
|
+
profilePictureUrl: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type MetaListUsersResult = {
|
|
9
|
+
users: ZiteProjectUser[];
|
|
10
|
+
};
|
|
11
|
+
export declare class ZiteMeta {
|
|
12
|
+
static listUsers(): Promise<MetaListUsersResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare const Meta: typeof ZiteMeta;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Meta = exports.ZiteMeta = void 0;
|
|
4
|
+
const sdkCall_js_1 = require("../internal/sdkCall.js");
|
|
5
|
+
const META_SDK_INTEGRATION_ID = '__meta__';
|
|
6
|
+
class ZiteMeta {
|
|
7
|
+
static listUsers() {
|
|
8
|
+
return (0, sdkCall_js_1.getSdkCall)()(META_SDK_INTEGRATION_ID, 'ZiteMeta', 'listUsers', {});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ZiteMeta = ZiteMeta;
|
|
12
|
+
exports.Meta = ZiteMeta;
|
|
@@ -146,6 +146,13 @@ export interface SendEmailParams {
|
|
|
146
146
|
replyTo?: string;
|
|
147
147
|
/** 'formatted' (default) for styled HTML, 'plain' for text-only. */
|
|
148
148
|
layout?: "formatted" | "plain";
|
|
149
|
+
/**
|
|
150
|
+
* Text direction of the email. Use 'rtl' for right-to-left languages
|
|
151
|
+
* (Hebrew, Arabic) — sets dir="rtl" on the email wrapper and right-aligns
|
|
152
|
+
* text blocks. HTML like `<div dir="rtl">` inside text blocks is stripped
|
|
153
|
+
* by the sanitizer and will NOT work. Defaults to 'ltr'.
|
|
154
|
+
*/
|
|
155
|
+
direction?: "ltr" | "rtl";
|
|
149
156
|
/** Custom logo shown above the email content (header area), for branding. */
|
|
150
157
|
logo?: {
|
|
151
158
|
url: string;
|
package/dist/cjs/sync/index.js
CHANGED
|
@@ -86,8 +86,13 @@ function regenerateApiTs() {
|
|
|
86
86
|
const apiDir = (0, path_1.join)("src", "api");
|
|
87
87
|
if (!(0, fs_1.existsSync)(apiDir))
|
|
88
88
|
return;
|
|
89
|
+
// Sorted for the same reason as the `generate` path: `generateApiTs` emits
|
|
90
|
+
// per-endpoint declarations in list order, `readdir` order is unspecified,
|
|
91
|
+
// and a reshuffle rewrites the file without changing the program. Both
|
|
92
|
+
// writers must agree, or `sync` and `generate` reorder each other's output.
|
|
89
93
|
const endpointFiles = (0, fs_1.readdirSync)(apiDir)
|
|
90
94
|
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
|
|
95
|
+
.sort()
|
|
91
96
|
.map((f) => ({
|
|
92
97
|
fileName: f,
|
|
93
98
|
content: (0, fs_1.readFileSync)((0, path_1.join)(apiDir, f), "utf-8"),
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -738,6 +738,9 @@ function generateEmailSdk(integrationId) {
|
|
|
738
738
|
"//",
|
|
739
739
|
"// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
|
|
740
740
|
"// => { success: boolean; messageId: string }",
|
|
741
|
+
"//",
|
|
742
|
+
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl' — dir attributes",
|
|
743
|
+
"// inside body text are stripped by the sanitizer and will not work.",
|
|
741
744
|
"",
|
|
742
745
|
"import { createEmailClient } from 'zitejs/runtime';",
|
|
743
746
|
"",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createCaller } from '../caller/index.js';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side auth hooks — the `ziteAuth({ hooks })` config an app
|
|
3
|
+
* default-exports from `zite.auth.ts` (app root). The platform bundles that
|
|
4
|
+
* file at build time and invokes the hooks at auth lifecycle moments
|
|
5
|
+
* (sign-up, sign-in, session checks). Hooks run like backend app code, so
|
|
6
|
+
* they can use the app's integrations and `zitejs/db`.
|
|
7
|
+
*
|
|
8
|
+
* All hooks fail open on error/timeout — a broken hook never locks users
|
|
9
|
+
* out. Gate hooks return allow / deny / defer; `verifySession` returns an
|
|
10
|
+
* active verdict and may enrich the app-visible user.
|
|
11
|
+
*/
|
|
12
|
+
export interface ZiteAuthHookUser {
|
|
13
|
+
id: string;
|
|
14
|
+
email: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* allow admits past disabled/domain-restricted signup; deny blocks with an
|
|
19
|
+
* optional reason; anything else (empty object / no return) defers to the
|
|
20
|
+
* platform rules.
|
|
21
|
+
*/
|
|
22
|
+
export type ZiteAuthGateDecision = {
|
|
23
|
+
allow: true;
|
|
24
|
+
} | {
|
|
25
|
+
deny: true;
|
|
26
|
+
reason?: string;
|
|
27
|
+
} | {
|
|
28
|
+
allow?: undefined;
|
|
29
|
+
deny?: undefined;
|
|
30
|
+
} | void;
|
|
31
|
+
/**
|
|
32
|
+
* active: false revokes the session; active: true keeps it, and `user`
|
|
33
|
+
* merges extra fields into the app-visible user.
|
|
34
|
+
*/
|
|
35
|
+
export type ZiteAuthSessionVerdict = {
|
|
36
|
+
active: false;
|
|
37
|
+
reason?: string;
|
|
38
|
+
} | {
|
|
39
|
+
active: true;
|
|
40
|
+
user?: Record<string, unknown>;
|
|
41
|
+
} | {
|
|
42
|
+
active?: undefined;
|
|
43
|
+
} | void;
|
|
44
|
+
export interface ZiteAuthHooks {
|
|
45
|
+
beforeSignUp?(input: {
|
|
46
|
+
email: string;
|
|
47
|
+
firstName?: string;
|
|
48
|
+
lastName?: string;
|
|
49
|
+
}): Promise<ZiteAuthGateDecision> | ZiteAuthGateDecision;
|
|
50
|
+
beforeSignIn?(input: {
|
|
51
|
+
email: string;
|
|
52
|
+
}): Promise<ZiteAuthGateDecision> | ZiteAuthGateDecision;
|
|
53
|
+
afterSignUp?(input: {
|
|
54
|
+
user: ZiteAuthHookUser;
|
|
55
|
+
}): Promise<unknown> | unknown;
|
|
56
|
+
afterSignIn?(input: {
|
|
57
|
+
user: ZiteAuthHookUser;
|
|
58
|
+
}): Promise<unknown> | unknown;
|
|
59
|
+
verifySession?(input: {
|
|
60
|
+
user: ZiteAuthHookUser;
|
|
61
|
+
}): Promise<ZiteAuthSessionVerdict> | ZiteAuthSessionVerdict;
|
|
62
|
+
}
|
|
63
|
+
export interface ZiteAuthConfig {
|
|
64
|
+
hooks?: ZiteAuthHooks;
|
|
65
|
+
}
|
|
66
|
+
export declare const ziteAuth: (config: ZiteAuthConfig) => ZiteAuthConfig;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side auth hooks — the `ziteAuth({ hooks })` config an app
|
|
3
|
+
* default-exports from `zite.auth.ts` (app root). The platform bundles that
|
|
4
|
+
* file at build time and invokes the hooks at auth lifecycle moments
|
|
5
|
+
* (sign-up, sign-in, session checks). Hooks run like backend app code, so
|
|
6
|
+
* they can use the app's integrations and `zitejs/db`.
|
|
7
|
+
*
|
|
8
|
+
* All hooks fail open on error/timeout — a broken hook never locks users
|
|
9
|
+
* out. Gate hooks return allow / deny / defer; `verifySession` returns an
|
|
10
|
+
* active verdict and may enrich the app-visible user.
|
|
11
|
+
*/
|
|
12
|
+
export const ziteAuth = (config) => config;
|
package/dist/esm/bundle/index.js
CHANGED
|
@@ -232,6 +232,16 @@ function createAliasPlugin(opts) {
|
|
|
232
232
|
}
|
|
233
233
|
return { path: 'zitejs/email', external: true };
|
|
234
234
|
});
|
|
235
|
+
// zitejs/auth/server is types + an identity wrapper — inline a shim so
|
|
236
|
+
// zite.auth.ts bundles without resolving the installed package.
|
|
237
|
+
build.onResolve({ filter: /^zitejs\/auth\/server$/ }, () => ({
|
|
238
|
+
path: 'zitejs-auth-server-shim',
|
|
239
|
+
namespace: 'zite-virtual',
|
|
240
|
+
}));
|
|
241
|
+
build.onLoad({ filter: /.*/, namespace: 'zite-virtual' }, () => ({
|
|
242
|
+
contents: 'export const ziteAuth = (config) => config;',
|
|
243
|
+
loader: 'js',
|
|
244
|
+
}));
|
|
235
245
|
// zitejs/runtime is NOT in PREBUNDLED_LIBS — it's a thin fetch()
|
|
236
246
|
// wrapper that gets bundled inline by esbuild (no special handling).
|
|
237
247
|
for (const [pkgName, modulePath] of Object.entries(PREBUNDLED_LIBS)) {
|
|
@@ -356,9 +366,78 @@ async function bundleEndpointsImpl(baseDir, endpointNames) {
|
|
|
356
366
|
}
|
|
357
367
|
}
|
|
358
368
|
}
|
|
369
|
+
let bundledAuthHooks;
|
|
370
|
+
let authHooksError;
|
|
371
|
+
if (fs.existsSync(path.join(baseDir, 'zite.auth.ts'))) {
|
|
372
|
+
const runtimeInit = `import { __wrapSdkCall, initRuntime } from '@zite/endpoints-runtime-sdk';
|
|
373
|
+
globalThis.__wrapSdkCall = __wrapSdkCall;
|
|
374
|
+
initRuntime();`;
|
|
375
|
+
const dispatcherCode = `
|
|
376
|
+
${runtimeInit}
|
|
377
|
+
import { z } from 'zod';
|
|
378
|
+
import { createEndpoint } from '${sdkSource}';
|
|
379
|
+
import auth from '../zite.auth';
|
|
380
|
+
|
|
381
|
+
const endpoint = createEndpoint({
|
|
382
|
+
description: 'Runs the auth lifecycle hooks defined in zite.auth.ts',
|
|
383
|
+
inputSchema: z.object({
|
|
384
|
+
hook: z.enum([
|
|
385
|
+
'beforeSignUp',
|
|
386
|
+
'afterSignUp',
|
|
387
|
+
'beforeSignIn',
|
|
388
|
+
'afterSignIn',
|
|
389
|
+
'verifySession',
|
|
390
|
+
]),
|
|
391
|
+
payload: z.record(z.unknown()).default({}),
|
|
392
|
+
}),
|
|
393
|
+
execute: async ({ input }) => {
|
|
394
|
+
const hook = auth.hooks?.[input.hook];
|
|
395
|
+
if (!hook) return {};
|
|
396
|
+
return (await hook(input.payload as never)) ?? {};
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
globalThis.__endpoint = endpoint;
|
|
400
|
+
`;
|
|
401
|
+
try {
|
|
402
|
+
const result = await esbuild.build({
|
|
403
|
+
...BASE_BUILD_OPTIONS,
|
|
404
|
+
stdin: {
|
|
405
|
+
contents: dispatcherCode,
|
|
406
|
+
resolveDir: `${baseDir}/src`,
|
|
407
|
+
loader: 'ts',
|
|
408
|
+
},
|
|
409
|
+
logLevel: 'warning',
|
|
410
|
+
plugins: [aliasPlugin],
|
|
411
|
+
});
|
|
412
|
+
if (result.outputFiles && result.outputFiles.length > 0) {
|
|
413
|
+
bundledAuthHooks = result.outputFiles[0].text;
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
authHooksError = 'No output generated';
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
catch (err) {
|
|
420
|
+
const e = err;
|
|
421
|
+
if (e.errors && Array.isArray(e.errors)) {
|
|
422
|
+
authHooksError = e.errors
|
|
423
|
+
.map(er => {
|
|
424
|
+
const loc = er.location
|
|
425
|
+
? `${er.location.file || 'unknown'}:${er.location.line || '?'}:${er.location.column || '?'}`
|
|
426
|
+
: 'unknown';
|
|
427
|
+
return `${loc} - ${er.text}`;
|
|
428
|
+
})
|
|
429
|
+
.join('\n');
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
authHooksError = e.message || String(err);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
359
436
|
const output = JSON.stringify({
|
|
360
437
|
bundledEndpoints,
|
|
361
438
|
endpointErrors: Object.keys(endpointErrors).length > 0 ? endpointErrors : undefined,
|
|
439
|
+
bundledAuthHooks,
|
|
440
|
+
authHooksError,
|
|
362
441
|
});
|
|
363
442
|
fs.writeFileSync('/tmp/zitejs-bundle-result.json', output);
|
|
364
443
|
console.log(output);
|
|
@@ -468,18 +547,13 @@ export async function runBundle() {
|
|
|
468
547
|
}
|
|
469
548
|
else {
|
|
470
549
|
const apiDir = path.join(baseDir, 'src', 'api');
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
.filter(f => f.endsWith('.ts'))
|
|
478
|
-
.map(f => f.replace('.ts', ''));
|
|
479
|
-
}
|
|
480
|
-
if (endpointNames.length === 0) {
|
|
481
|
-
console.log(JSON.stringify({ bundledEndpoints: {} }));
|
|
482
|
-
return;
|
|
550
|
+
endpointNames = fs.existsSync(apiDir)
|
|
551
|
+
? fs
|
|
552
|
+
.readdirSync(apiDir)
|
|
553
|
+
.filter(f => f.endsWith('.ts'))
|
|
554
|
+
.map(f => f.replace('.ts', ''))
|
|
555
|
+
: [];
|
|
483
556
|
}
|
|
557
|
+
// Even with no endpoints, zite.auth.ts may still need bundling.
|
|
484
558
|
return bundleEndpointsImpl(baseDir, endpointNames);
|
|
485
559
|
}
|
package/dist/esm/cli.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTableClient } from '../runtime/index.js';
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -79,8 +79,17 @@ function regenerateAppApiTs(appDir) {
|
|
|
79
79
|
const apiDir = join("apps", appDir, "src", "api");
|
|
80
80
|
if (!existsSync(apiDir))
|
|
81
81
|
return;
|
|
82
|
+
// Sorted because `readdir` order is unspecified — it is whatever the
|
|
83
|
+
// filesystem returns. `generateApiTs` emits one import, one type block and
|
|
84
|
+
// one `api` key per endpoint IN THIS ORDER, and those declarations are
|
|
85
|
+
// order-independent, so a reshuffle produces a byte-different file that
|
|
86
|
+
// compiles to an identical program. Git cannot tell that apart from a real
|
|
87
|
+
// change: the app lands in the rebuild set and rebuilds for nothing, and a
|
|
88
|
+
// genuine one-endpoint addition shows up as a rewrite of the whole file
|
|
89
|
+
// instead of a few added lines.
|
|
82
90
|
const endpointFiles = readdirSync(apiDir)
|
|
83
91
|
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
|
|
92
|
+
.sort()
|
|
84
93
|
.map((f) => ({
|
|
85
94
|
fileName: f,
|
|
86
95
|
content: readFileSync(join(apiDir, f), "utf-8"),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ZiteProjectUser = {
|
|
2
|
+
uuid: string;
|
|
3
|
+
firstName: string | null;
|
|
4
|
+
lastName: string | null;
|
|
5
|
+
email: string;
|
|
6
|
+
profilePictureUrl: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type MetaListUsersResult = {
|
|
9
|
+
users: ZiteProjectUser[];
|
|
10
|
+
};
|
|
11
|
+
export declare class ZiteMeta {
|
|
12
|
+
static listUsers(): Promise<MetaListUsersResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare const Meta: typeof ZiteMeta;
|
|
@@ -146,6 +146,13 @@ export interface SendEmailParams {
|
|
|
146
146
|
replyTo?: string;
|
|
147
147
|
/** 'formatted' (default) for styled HTML, 'plain' for text-only. */
|
|
148
148
|
layout?: "formatted" | "plain";
|
|
149
|
+
/**
|
|
150
|
+
* Text direction of the email. Use 'rtl' for right-to-left languages
|
|
151
|
+
* (Hebrew, Arabic) — sets dir="rtl" on the email wrapper and right-aligns
|
|
152
|
+
* text blocks. HTML like `<div dir="rtl">` inside text blocks is stripped
|
|
153
|
+
* by the sanitizer and will NOT work. Defaults to 'ltr'.
|
|
154
|
+
*/
|
|
155
|
+
direction?: "ltr" | "rtl";
|
|
149
156
|
/** Custom logo shown above the email content (header area), for branding. */
|
|
150
157
|
logo?: {
|
|
151
158
|
url: string;
|
package/dist/esm/sync/index.js
CHANGED
|
@@ -68,8 +68,13 @@ export function regenerateApiTs() {
|
|
|
68
68
|
const apiDir = join("src", "api");
|
|
69
69
|
if (!existsSync(apiDir))
|
|
70
70
|
return;
|
|
71
|
+
// Sorted for the same reason as the `generate` path: `generateApiTs` emits
|
|
72
|
+
// per-endpoint declarations in list order, `readdir` order is unspecified,
|
|
73
|
+
// and a reshuffle rewrites the file without changing the program. Both
|
|
74
|
+
// writers must agree, or `sync` and `generate` reorder each other's output.
|
|
71
75
|
const endpointFiles = readdirSync(apiDir)
|
|
72
76
|
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
|
|
77
|
+
.sort()
|
|
73
78
|
.map((f) => ({
|
|
74
79
|
fileName: f,
|
|
75
80
|
content: readFileSync(join(apiDir, f), "utf-8"),
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -728,6 +728,9 @@ export function generateEmailSdk(integrationId) {
|
|
|
728
728
|
"//",
|
|
729
729
|
"// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
|
|
730
730
|
"// => { success: boolean; messageId: string }",
|
|
731
|
+
"//",
|
|
732
|
+
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl' — dir attributes",
|
|
733
|
+
"// inside body text are stripped by the sanitizer and will not work.",
|
|
731
734
|
"",
|
|
732
735
|
"import { createEmailClient } from 'zitejs/runtime';",
|
|
733
736
|
"",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.94",
|
|
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.d.ts",
|
|
52
|
+
"import": "./dist/esm/auth/server.js",
|
|
53
|
+
"require": "./dist/cjs/auth/server.js",
|
|
54
|
+
"default": "./dist/esm/auth/server.js"
|
|
55
|
+
},
|
|
50
56
|
"./auth-server": {
|
|
51
57
|
"types": "./dist/esm/auth-server/index.d.ts",
|
|
52
58
|
"import": "./dist/esm/auth-server/index.js",
|