zitejs 0.9.0 → 0.9.2

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.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCaller = void 0;
4
- var index_js_1 = require("../runtime/index.js");
4
+ var index_js_1 = require("../caller/index.js");
5
5
  Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
@@ -2,9 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuth = useAuth;
4
4
  exports.getCurrentUser = getCurrentUser;
5
+ const react_1 = require("react");
5
6
  function useAuth() {
6
- throw new Error('useAuth() is only available in the Zite runtime.');
7
+ const [user, setUser] = (0, react_1.useState)(null);
8
+ const [isLoading, setIsLoading] = (0, react_1.useState)(true);
9
+ (0, react_1.useEffect)(() => {
10
+ // Check if running inside the Zite sandbox (app-runtime provides auth)
11
+ const win = window;
12
+ if (typeof win._ziteGetUser === 'function') {
13
+ try {
14
+ const u = win._ziteGetUser();
15
+ setUser(u);
16
+ }
17
+ catch {
18
+ // Fall through to local dev mode
19
+ }
20
+ }
21
+ else {
22
+ // Local dev mode — return anonymous user
23
+ setUser({
24
+ id: 'local-dev',
25
+ email: 'dev@localhost',
26
+ name: 'Local Developer',
27
+ });
28
+ }
29
+ setIsLoading(false);
30
+ }, []);
31
+ return {
32
+ user,
33
+ isLoading,
34
+ authLoading: isLoading,
35
+ logout: () => {
36
+ setUser(null);
37
+ },
38
+ };
7
39
  }
8
40
  function getCurrentUser() {
9
- throw new Error('getCurrentUser() is only available in the Zite runtime.');
41
+ const win = window;
42
+ if (typeof win._ziteGetUser === 'function') {
43
+ return win._ziteGetUser();
44
+ }
45
+ return { id: 'local-dev', email: 'dev@localhost', name: 'Local Developer' };
10
46
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCaller = createCaller;
4
+ const ENVIRONMENTS = {
5
+ production: 'https://workflows.zite.com',
6
+ staging: 'https://workflows.zitestaging.com',
7
+ local: 'http://localhost:2506',
8
+ };
9
+ function getRunnerUrl() {
10
+ const env = (typeof process !== 'undefined' && process.env?.ZITE_ENV) || 'production';
11
+ return ((typeof process !== 'undefined' && process.env?.ZITE_RUNNER_URL) ||
12
+ ENVIRONMENTS[env] ||
13
+ ENVIRONMENTS.production);
14
+ }
15
+ function getToken() {
16
+ return (typeof process !== 'undefined' && process.env?.ZITE_DB_TOKEN) || '';
17
+ }
18
+ function createCaller(endpoint) {
19
+ return async (input) => {
20
+ const res = await fetch(getRunnerUrl() + '/api/' + endpoint._name, {
21
+ method: 'POST',
22
+ headers: {
23
+ Authorization: `Bearer ${getToken()}`,
24
+ 'Content-Type': 'application/json',
25
+ },
26
+ body: JSON.stringify(input),
27
+ });
28
+ if (!res.ok) {
29
+ const text = await res.text().catch(() => '');
30
+ throw new Error(`API call failed (${res.status}): ${text}`);
31
+ }
32
+ return res.json();
33
+ };
34
+ }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCaller = void 0;
3
4
  exports.wrapSdkCall = wrapSdkCall;
4
5
  exports.createTableClient = createTableClient;
5
- exports.createCaller = createCaller;
6
6
  const ENVIRONMENTS = {
7
7
  production: 'https://workflows.zite.com',
8
8
  staging: 'https://workflows.zitestaging.com',
@@ -51,20 +51,5 @@ function createTableClient(integrationId, className) {
51
51
  }),
52
52
  };
53
53
  }
54
- function createCaller(endpoint) {
55
- return async (input) => {
56
- const res = await fetch(getRunnerUrl() + '/api/' + endpoint._name, {
57
- method: 'POST',
58
- headers: {
59
- Authorization: `Bearer ${getToken()}`,
60
- 'Content-Type': 'application/json',
61
- },
62
- body: JSON.stringify(input),
63
- });
64
- if (!res.ok) {
65
- const text = await res.text().catch(() => '');
66
- throw new Error(`API call failed (${res.status}): ${text}`);
67
- }
68
- return res.json();
69
- };
70
- }
54
+ var index_js_1 = require("../caller/index.js");
55
+ Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
@@ -125,7 +125,7 @@ function generateApiTs(endpointFiles) {
125
125
  const lines = [
126
126
  '// Auto-generated by zitejs sync. Do not edit manually.',
127
127
  '',
128
- "import { createCaller } from 'zitejs/runtime';",
128
+ "import { createCaller } from 'zitejs/caller';",
129
129
  '',
130
130
  ];
131
131
  const endpointNames = [];
@@ -1,2 +1,2 @@
1
- export { createCaller } from '../runtime/index.js';
2
- export type { EndpointConfig } from '../runtime/index.js';
1
+ export { createCaller } from '../caller/index.js';
2
+ export type { EndpointConfig } from '../caller/index.js';
@@ -1 +1 @@
1
- export { createCaller } from '../runtime/index.js';
1
+ export { createCaller } from '../caller/index.js';
@@ -1,6 +1,42 @@
1
+ import { useState, useEffect } from 'react';
1
2
  export function useAuth() {
2
- throw new Error('useAuth() is only available in the Zite runtime.');
3
+ const [user, setUser] = useState(null);
4
+ const [isLoading, setIsLoading] = useState(true);
5
+ useEffect(() => {
6
+ // Check if running inside the Zite sandbox (app-runtime provides auth)
7
+ const win = window;
8
+ if (typeof win._ziteGetUser === 'function') {
9
+ try {
10
+ const u = win._ziteGetUser();
11
+ setUser(u);
12
+ }
13
+ catch {
14
+ // Fall through to local dev mode
15
+ }
16
+ }
17
+ else {
18
+ // Local dev mode — return anonymous user
19
+ setUser({
20
+ id: 'local-dev',
21
+ email: 'dev@localhost',
22
+ name: 'Local Developer',
23
+ });
24
+ }
25
+ setIsLoading(false);
26
+ }, []);
27
+ return {
28
+ user,
29
+ isLoading,
30
+ authLoading: isLoading,
31
+ logout: () => {
32
+ setUser(null);
33
+ },
34
+ };
3
35
  }
4
36
  export function getCurrentUser() {
5
- throw new Error('getCurrentUser() is only available in the Zite runtime.');
37
+ const win = window;
38
+ if (typeof win._ziteGetUser === 'function') {
39
+ return win._ziteGetUser();
40
+ }
41
+ return { id: 'local-dev', email: 'dev@localhost', name: 'Local Developer' };
6
42
  }
@@ -0,0 +1,8 @@
1
+ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
2
+ _name?: string;
3
+ execute: (params: {
4
+ input: TInput;
5
+ context: unknown;
6
+ }) => Promise<TOutput> | TOutput;
7
+ }
8
+ export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>): (input: TInput) => Promise<TOutput>;
@@ -0,0 +1,31 @@
1
+ const ENVIRONMENTS = {
2
+ production: 'https://workflows.zite.com',
3
+ staging: 'https://workflows.zitestaging.com',
4
+ local: 'http://localhost:2506',
5
+ };
6
+ function getRunnerUrl() {
7
+ const env = (typeof process !== 'undefined' && process.env?.ZITE_ENV) || 'production';
8
+ return ((typeof process !== 'undefined' && process.env?.ZITE_RUNNER_URL) ||
9
+ ENVIRONMENTS[env] ||
10
+ ENVIRONMENTS.production);
11
+ }
12
+ function getToken() {
13
+ return (typeof process !== 'undefined' && process.env?.ZITE_DB_TOKEN) || '';
14
+ }
15
+ export function createCaller(endpoint) {
16
+ return async (input) => {
17
+ const res = await fetch(getRunnerUrl() + '/api/' + endpoint._name, {
18
+ method: 'POST',
19
+ headers: {
20
+ Authorization: `Bearer ${getToken()}`,
21
+ 'Content-Type': 'application/json',
22
+ },
23
+ body: JSON.stringify(input),
24
+ });
25
+ if (!res.ok) {
26
+ const text = await res.text().catch(() => '');
27
+ throw new Error(`API call failed (${res.status}): ${text}`);
28
+ }
29
+ return res.json();
30
+ };
31
+ }
@@ -19,11 +19,5 @@ export interface TableClient<T> {
19
19
  bulkCreate(records: Partial<T>[]): Promise<T[]>;
20
20
  }
21
21
  export declare function createTableClient<T>(integrationId: string, className: string): TableClient<T>;
22
- export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
23
- _name?: string;
24
- execute: (params: {
25
- input: TInput;
26
- context: unknown;
27
- }) => Promise<TOutput> | TOutput;
28
- }
29
- export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>): (input: TInput) => Promise<TOutput>;
22
+ export { createCaller } from '../caller/index.js';
23
+ export type { EndpointConfig } from '../caller/index.js';
@@ -46,20 +46,4 @@ export function createTableClient(integrationId, className) {
46
46
  }),
47
47
  };
48
48
  }
49
- export function createCaller(endpoint) {
50
- return async (input) => {
51
- const res = await fetch(getRunnerUrl() + '/api/' + endpoint._name, {
52
- method: 'POST',
53
- headers: {
54
- Authorization: `Bearer ${getToken()}`,
55
- 'Content-Type': 'application/json',
56
- },
57
- body: JSON.stringify(input),
58
- });
59
- if (!res.ok) {
60
- const text = await res.text().catch(() => '');
61
- throw new Error(`API call failed (${res.status}): ${text}`);
62
- }
63
- return res.json();
64
- };
65
- }
49
+ export { createCaller } from '../caller/index.js';
@@ -117,7 +117,7 @@ export function generateApiTs(endpointFiles) {
117
117
  const lines = [
118
118
  '// Auto-generated by zitejs sync. Do not edit manually.',
119
119
  '',
120
- "import { createCaller } from 'zitejs/runtime';",
120
+ "import { createCaller } from 'zitejs/caller';",
121
121
  '',
122
122
  ];
123
123
  const endpointNames = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",
@@ -16,6 +16,12 @@
16
16
  "require": "./dist/cjs/runtime/index.js",
17
17
  "default": "./dist/esm/runtime/index.js"
18
18
  },
19
+ "./caller": {
20
+ "types": "./dist/esm/caller/index.d.ts",
21
+ "import": "./dist/esm/caller/index.js",
22
+ "require": "./dist/cjs/caller/index.js",
23
+ "default": "./dist/esm/caller/index.js"
24
+ },
19
25
  "./db": {
20
26
  "types": "./dist/esm/db/index.d.ts",
21
27
  "import": "./dist/esm/db/index.js",
@@ -72,8 +78,16 @@
72
78
  "files": [
73
79
  "dist"
74
80
  ],
81
+ "peerDependencies": {
82
+ "react": ">=18"
83
+ },
84
+ "peerDependenciesMeta": {
85
+ "react": { "optional": true }
86
+ },
75
87
  "devDependencies": {
76
88
  "@types/node": "^25.9.1",
89
+ "@types/react": "^19.0.0",
90
+ "react": "^19.0.0",
77
91
  "typescript": "^5.4.0",
78
92
  "vitest": "^3.0.0"
79
93
  },