zitejs 0.10.1-device.0 → 0.10.1

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.
Files changed (62) hide show
  1. package/dist/cjs/auth/actions.js +0 -2
  2. package/dist/cjs/auth/client.js +0 -5
  3. package/dist/cjs/auth/useAuth.test.js +0 -1
  4. package/dist/cjs/caller/index.js +16 -5
  5. package/dist/cjs/check/index.js +10 -4
  6. package/dist/cjs/start/build/entries.d.ts +5 -0
  7. package/dist/cjs/start/build/entries.js +16 -8
  8. package/dist/cjs/start/build/roleIds.d.ts +11 -0
  9. package/dist/cjs/start/build/roleIds.js +59 -0
  10. package/dist/cjs/start/describe/schema.d.ts +574 -0
  11. package/dist/cjs/start/describe/schema.js +178 -0
  12. package/dist/cjs/start/protocol.d.ts +7 -0
  13. package/dist/cjs/start/protocol.js +27 -3
  14. package/dist/cjs/start/serve/authHookNames.d.ts +3 -0
  15. package/dist/cjs/start/serve/authHookNames.js +13 -0
  16. package/dist/cjs/vite/index.js +0 -41
  17. package/dist/cjs/vite/index.test.js +0 -36
  18. package/dist/esm/auth/actions.js +0 -2
  19. package/dist/esm/auth/client.js +0 -5
  20. package/dist/esm/auth/useAuth.test.js +0 -1
  21. package/dist/esm/caller/index.js +15 -4
  22. package/dist/esm/check/index.js +10 -4
  23. package/dist/esm/start/build/entries.d.ts +5 -0
  24. package/dist/esm/start/build/entries.js +15 -8
  25. package/dist/esm/start/build/roleIds.d.ts +11 -0
  26. package/dist/esm/start/build/roleIds.js +54 -0
  27. package/dist/esm/start/build/vite.js +0 -4
  28. package/dist/esm/start/classicOnly.js +3 -3
  29. package/dist/esm/start/describe/schema.d.ts +574 -0
  30. package/dist/esm/start/describe/schema.js +175 -0
  31. package/dist/esm/start/describe/schema.test-d.d.ts +1 -0
  32. package/dist/esm/start/describe/schema.test-d.js +23 -0
  33. package/dist/esm/start/index.d.ts +1 -1
  34. package/dist/esm/start/protocol.d.ts +7 -0
  35. package/dist/esm/start/protocol.js +17 -2
  36. package/dist/esm/start/roles.d.ts +10 -2
  37. package/dist/esm/start/serve/authHookNames.d.ts +3 -0
  38. package/dist/esm/start/serve/authHookNames.js +9 -0
  39. package/dist/esm/start/serve/authHooks.d.ts +2 -4
  40. package/dist/esm/start/serve/authHooks.js +2 -8
  41. package/dist/esm/start/version.d.ts +1 -1
  42. package/dist/esm/start/version.js +1 -1
  43. package/dist/esm/vite/index.js +0 -41
  44. package/dist/esm/vite/index.test.js +0 -36
  45. package/package.json +5 -13
  46. package/tsconfig/start.json +40 -0
  47. package/dist/cjs/internal/browserMode.d.ts +0 -2
  48. package/dist/cjs/internal/browserMode.js +0 -18
  49. package/dist/cjs/internal/deviceCache.d.ts +0 -11
  50. package/dist/cjs/internal/deviceCache.js +0 -29
  51. package/dist/cjs/query/deviceCache.d.ts +0 -14
  52. package/dist/cjs/query/deviceCache.js +0 -304
  53. package/dist/cjs/query/index.d.ts +0 -19
  54. package/dist/cjs/query/index.js +0 -369
  55. package/dist/esm/internal/browserMode.d.ts +0 -2
  56. package/dist/esm/internal/browserMode.js +0 -15
  57. package/dist/esm/internal/deviceCache.d.ts +0 -11
  58. package/dist/esm/internal/deviceCache.js +0 -24
  59. package/dist/esm/query/deviceCache.d.ts +0 -14
  60. package/dist/esm/query/deviceCache.js +0 -301
  61. package/dist/esm/query/index.d.ts +0 -19
  62. package/dist/esm/query/index.js +0 -366
@@ -39,7 +39,6 @@ exports.updateProfile = updateProfile;
39
39
  const constants_js_1 = require("./constants.js");
40
40
  const previewClaim_js_1 = require("./previewClaim.js");
41
41
  const profileUpdates_js_1 = require("./profileUpdates.js");
42
- const deviceCache_js_1 = require("../internal/deviceCache.js");
43
42
  function loginWithRedirect(opts) {
44
43
  if (window.location.pathname.startsWith('/auth/'))
45
44
  return;
@@ -81,7 +80,6 @@ function loginWithRedirect(opts) {
81
80
  window.location.href = query ? `/auth/login?${query}` : '/auth/login';
82
81
  }
83
82
  function logout(opts) {
84
- (0, deviceCache_js_1.forgetDeviceCache)();
85
83
  void Promise.resolve().then(() => __importStar(require('./client.js'))).then(({ signOut }) => signOut().then(() => {
86
84
  window.location.href = opts?.returnTo || '/';
87
85
  }));
@@ -7,7 +7,6 @@ const react_2 = require("better-auth/react");
7
7
  const plugins_1 = require("better-auth/client/plugins");
8
8
  const config_js_1 = require("./config.js");
9
9
  const actions_js_1 = require("./actions.js");
10
- const deviceCache_js_1 = require("../internal/deviceCache.js");
11
10
  // Apart from the actions, so an app that never reads the session here (a Start
12
11
  // app reads its user from the router) never ships better-auth's client.
13
12
  exports.authClient = (0, react_2.createAuthClient)({
@@ -23,10 +22,6 @@ exports.authClient = (0, react_2.createAuthClient)({
23
22
  ],
24
23
  });
25
24
  exports.useSession = exports.authClient.useSession;
26
- // better-auth flips this after any call that changes who's signed in (sign-in,
27
- // sign-up, sign-out) or what's known about them. What the app kept on the
28
- // device may belong to someone else now.
29
- exports.authClient.$store.atoms.$sessionSignal?.listen(deviceCache_js_1.sessionChanged);
30
25
  /**
31
26
  * An internal app has no signed-out state — SSO runs before the bundle — so an
32
27
  * empty session means it died underneath the app. Only `internal`: elsewhere a
@@ -11,7 +11,6 @@ vitest_1.vi.mock('better-auth/react', () => ({
11
11
  signUp: {},
12
12
  signOut: vitest_1.vi.fn(),
13
13
  updateUser: vitest_1.vi.fn(),
14
- $store: { atoms: { $sessionSignal: { listen: vitest_1.vi.fn() } } },
15
14
  }),
16
15
  }));
17
16
  vitest_1.vi.mock('better-auth/client/plugins', () => ({
@@ -3,7 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCaller = createCaller;
4
4
  exports.createStreamingCaller = createStreamingCaller;
5
5
  const env_js_1 = require("../internal/env.js");
6
- const browserMode_js_1 = require("../internal/browserMode.js");
6
+ function getMode() {
7
+ if (typeof window === 'undefined')
8
+ return 'preview';
9
+ const host = window.location.host;
10
+ return host.startsWith('zite-editor') ||
11
+ host.startsWith('zite-action-') ||
12
+ host.startsWith('zite-snapshot-') ||
13
+ host.endsWith('.zite-dev-sandbox.com') ||
14
+ host.endsWith('.zite-sandbox.com') ||
15
+ host.endsWith('.zite-dev-app.com') ||
16
+ host.endsWith('.zite-app.com')
17
+ ? 'preview'
18
+ : 'live';
19
+ }
7
20
  const ENVIRONMENTS = {
8
21
  production: 'https://workflows.zite.com',
9
22
  staging: 'https://workflows.zitestaging.com',
@@ -64,7 +77,7 @@ function buildFetchOptions(name, input, extra) {
64
77
  },
65
78
  body: JSON.stringify({
66
79
  inputs: input,
67
- mode: (0, browserMode_js_1.getMode)(),
80
+ mode: getMode(),
68
81
  usageToken: token,
69
82
  ...(ziteAuthToken ? { ziteAuthToken } : {}),
70
83
  ...(typeof window !== 'undefined' && window.__ziteSnapshotId
@@ -82,9 +95,7 @@ function createCaller(endpointOrName, nameOrFlowId, flowId) {
82
95
  const res = await fetch(url, init);
83
96
  if (!res.ok) {
84
97
  const text = await res.text().catch(() => '');
85
- throw Object.assign(new Error(`API call failed (${res.status}): ${text}`), {
86
- status: res.status,
87
- });
98
+ throw new Error(`API call failed (${res.status}): ${text}`);
88
99
  }
89
100
  return res.json();
90
101
  };
@@ -170,14 +170,20 @@ function runTool(file, args, cwd) {
170
170
  }
171
171
  const isMissingModule = (err) => err?.code === 'MODULE_NOT_FOUND';
172
172
  /**
173
- * A Start app, in about a second: its route tree regenerated as `vite build`
174
- * writes it, then a tsgo typecheck, which reads that tree. Everything else is
175
- * the platform build's and its describe's to refuse.
173
+ * A Start app, in about a second: its `.zite/` entries and role ids, and its
174
+ * route tree, written as `vite build` writes them, then a tsgo typecheck, which
175
+ * reads them. Everything else is the platform build's and its describe's to
176
+ * refuse.
176
177
  */
177
178
  async function checkStartApp(reporter, app, appPath) {
178
- const { regenerateRouteTree } = await Promise.resolve().then(() => __importStar(require('./start/routeTree.js')));
179
+ const [{ regenerateRouteTree }, { writeStartFiles }] = await Promise.all([
180
+ Promise.resolve().then(() => __importStar(require('./start/routeTree.js'))),
181
+ Promise.resolve().then(() => __importStar(require('../start/build/entries.js'))),
182
+ ]);
179
183
  let routeTree = { ok: true };
180
184
  try {
185
+ // First: the route tree's footer types the start instance only when .zite/start.ts is there.
186
+ writeStartFiles(appPath);
181
187
  await regenerateRouteTree(appPath);
182
188
  }
183
189
  catch (err) {
@@ -15,6 +15,11 @@ export declare const hasAppStart: (appDir: string) => boolean;
15
15
  export declare const writeIfChanged: (appDir: string, file: string, content: string) => boolean;
16
16
  export declare const isStartAppDir: (appPath: string) => boolean;
17
17
  export declare const workspaceHasStartApps: () => boolean;
18
+ /**
19
+ * The `.zite/` files a Start app's typecheck reads, its entries as `vite build` writes them: `check`, `generate` and
20
+ * `dev` all write them. Returns the ones that changed.
21
+ */
22
+ export declare function writeStartFiles(appDir: string): string[];
18
23
  export declare function regenerateStartEntries(app: SourceDir): void;
19
24
  /**
20
25
  * App modules that mention createAutomation or createProviderTrigger: what the workflow registry imports. Describe
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderWorkflowModules = exports.workspaceHasStartApps = exports.isStartAppDir = exports.writeIfChanged = exports.hasAppStart = exports.renderStartInstance = exports.renderStartServerEntry = exports.START_INSTANCE_ENTRY = exports.START_SERVER_ENTRY = void 0;
4
+ exports.writeStartFiles = writeStartFiles;
4
5
  exports.regenerateStartEntries = regenerateStartEntries;
5
6
  exports.workflowFiles = workflowFiles;
6
7
  const node_fs_1 = require("node:fs");
7
8
  const node_path_1 = require("node:path");
8
9
  const sourceRoots_js_1 = require("../../sourceRoots.js");
10
+ const roleIds_js_1 = require("./roleIds.js");
9
11
  exports.START_SERVER_ENTRY = '.zite/server.ts';
10
12
  exports.START_INSTANCE_ENTRY = '.zite/start.ts';
11
13
  const APP_START_FILES = ['src/start.ts', 'src/start.tsx'];
@@ -75,17 +77,23 @@ exports.isStartAppDir = isStartAppDir;
75
77
  const isStartApp = (app) => (0, exports.isStartAppDir)(app.path);
76
78
  const workspaceHasStartApps = () => (0, sourceRoots_js_1.listSourceDirs)().some(isStartApp);
77
79
  exports.workspaceHasStartApps = workspaceHasStartApps;
80
+ /**
81
+ * The `.zite/` files a Start app's typecheck reads, its entries as `vite build` writes them: `check`, `generate` and
82
+ * `dev` all write them. Returns the ones that changed.
83
+ */
84
+ function writeStartFiles(appDir) {
85
+ const files = [
86
+ [exports.START_SERVER_ENTRY, (0, exports.renderStartServerEntry)()],
87
+ [exports.START_INSTANCE_ENTRY, (0, exports.renderStartInstance)((0, exports.hasAppStart)(appDir))],
88
+ [roleIds_js_1.START_ROLES_FILE, (0, roleIds_js_1.renderRoleIds)((0, roleIds_js_1.workspaceRoleIds)(appDir))],
89
+ ];
90
+ return files.flatMap(([file, content]) => (0, exports.writeIfChanged)(appDir, file, content) ? [file] : []);
91
+ }
78
92
  function regenerateStartEntries(app) {
79
93
  if (!isStartApp(app))
80
94
  return;
81
- const entries = [
82
- [exports.START_SERVER_ENTRY, (0, exports.renderStartServerEntry)()],
83
- [exports.START_INSTANCE_ENTRY, (0, exports.renderStartInstance)((0, exports.hasAppStart)(app.path))],
84
- ];
85
- for (const [file, content] of entries) {
86
- if ((0, exports.writeIfChanged)(app.path, file, content))
87
- console.log(`Wrote ${(0, node_path_1.join)(app.path, file)}`);
88
- }
95
+ for (const file of writeStartFiles(app.path))
96
+ console.log(`Wrote ${(0, node_path_1.join)(app.path, file)}`);
89
97
  }
90
98
  const SOURCE_FILE = /\.[mc]?[jt]sx?$/;
91
99
  const NOT_APP_CODE = /(\.(test|spec)\.[^.]+|\.d\.ts|routeTree\.gen\.ts)$/;
@@ -0,0 +1,11 @@
1
+ export declare const START_ROLES_FILE = ".zite/roles.d.ts";
2
+ /** The roles every workspace has without defining them, as the platform names them. */
3
+ export declare const BUILTIN_ROLE_IDS: readonly ["builtin:all-team-members", "builtin:all-users"];
4
+ /**
5
+ * The built-ins, then the roles the nearest `zite.permissions.json` defines. None at all when there's no readable
6
+ * file, so role ids stay plain strings: a missing or broken file would otherwise type every role the app names as a
7
+ * typo, and the nearest id that compiles is a built-in that admits everyone.
8
+ */
9
+ export declare const workspaceRoleIds: (appDir: string) => string[];
10
+ /** `.zite/roles.d.ts`, which types `role()` and `hasRole` to these ids. Its `export {}` makes it an augmentation. */
11
+ export declare const renderRoleIds: (ids: readonly string[]) => string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderRoleIds = exports.workspaceRoleIds = exports.BUILTIN_ROLE_IDS = exports.START_ROLES_FILE = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ exports.START_ROLES_FILE = '.zite/roles.d.ts';
7
+ /** The roles every workspace has without defining them, as the platform names them. */
8
+ exports.BUILTIN_ROLE_IDS = [
9
+ 'builtin:all-team-members',
10
+ 'builtin:all-users',
11
+ ];
12
+ const PERMISSIONS_FILE = 'zite.permissions.json';
13
+ // The workspace root's in a monorepo, above apps/<dir>/.
14
+ const findPermissionsFile = (appDir) => {
15
+ for (let dir = (0, node_path_1.resolve)(appDir);; dir = (0, node_path_1.dirname)(dir)) {
16
+ const file = (0, node_path_1.join)(dir, PERMISSIONS_FILE);
17
+ if ((0, node_fs_1.existsSync)(file))
18
+ return file;
19
+ if ((0, node_path_1.dirname)(dir) === dir)
20
+ return undefined;
21
+ }
22
+ };
23
+ // Undefined for a file that isn't a permissions file: its roles can't be known.
24
+ const definedRoleIds = (file) => {
25
+ try {
26
+ const { roles } = (JSON.parse((0, node_fs_1.readFileSync)(file, 'utf-8')) ?? {});
27
+ if (!Array.isArray(roles))
28
+ return undefined;
29
+ return roles.flatMap(role => {
30
+ const id = role?.id;
31
+ return typeof id === 'string' && id ? [id] : [];
32
+ });
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ };
38
+ /**
39
+ * The built-ins, then the roles the nearest `zite.permissions.json` defines. None at all when there's no readable
40
+ * file, so role ids stay plain strings: a missing or broken file would otherwise type every role the app names as a
41
+ * typo, and the nearest id that compiles is a built-in that admits everyone.
42
+ */
43
+ const workspaceRoleIds = (appDir) => {
44
+ const file = findPermissionsFile(appDir);
45
+ const defined = file ? definedRoleIds(file) : undefined;
46
+ return defined ? [...new Set([...exports.BUILTIN_ROLE_IDS, ...defined])] : [];
47
+ };
48
+ exports.workspaceRoleIds = workspaceRoleIds;
49
+ /** `.zite/roles.d.ts`, which types `role()` and `hasRole` to these ids. Its `export {}` makes it an augmentation. */
50
+ const renderRoleIds = (ids) => `// Generated by zitejs from the built-in roles and zite.permissions.json. The platform owns this file.
51
+ export {};
52
+
53
+ declare module 'zitejs/start' {
54
+ interface ZiteRoles {
55
+ ${ids.map(id => ` ${JSON.stringify(id)}: true;`).join('\n')}
56
+ }
57
+ }
58
+ `;
59
+ exports.renderRoleIds = renderRoleIds;