zitejs 0.9.14 → 0.9.15

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.
@@ -11,19 +11,36 @@ function getRunnerUrl() {
11
11
  const env = (0, env_js_1.getEnv)('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
12
12
  return (0, env_js_1.getEnv)('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
13
13
  }
14
- function getToken() {
15
- return (0, env_js_1.getEnv)('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
14
+ /**
15
+ * Get the user's usage token for endpoint auth.
16
+ * In internal mode: injected by app-runtime as window._ziteUsageToken
17
+ * In external mode: stored in localStorage by the auth flow
18
+ */
19
+ function getUsageToken() {
20
+ if (typeof window !== 'undefined') {
21
+ const win = window;
22
+ if (typeof win._ziteUsageToken === 'string')
23
+ return win._ziteUsageToken;
24
+ }
25
+ // Fallback to stored auth token (external mode)
26
+ if (typeof localStorage !== 'undefined') {
27
+ const stored = localStorage.getItem('zite.auth.token');
28
+ if (stored)
29
+ return stored;
30
+ }
31
+ return '';
16
32
  }
17
33
  function createCaller(endpoint, name, flowId) {
18
34
  return async (input) => {
19
35
  const appId = flowId ?? (0, env_js_1.getEnv)('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
36
+ const token = getUsageToken();
20
37
  const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
21
38
  method: 'POST',
22
39
  headers: {
23
- Authorization: `Bearer ${getToken()}`,
40
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
24
41
  'Content-Type': 'application/json',
25
42
  },
26
- body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
43
+ body: JSON.stringify({ ...input, mode: 'preview', usageToken: token }),
27
44
  });
28
45
  if (!res.ok) {
29
46
  const text = await res.text().catch(() => '');
@@ -8,19 +8,36 @@ function getRunnerUrl() {
8
8
  const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
9
9
  return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
10
10
  }
11
- function getToken() {
12
- return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
11
+ /**
12
+ * Get the user's usage token for endpoint auth.
13
+ * In internal mode: injected by app-runtime as window._ziteUsageToken
14
+ * In external mode: stored in localStorage by the auth flow
15
+ */
16
+ function getUsageToken() {
17
+ if (typeof window !== 'undefined') {
18
+ const win = window;
19
+ if (typeof win._ziteUsageToken === 'string')
20
+ return win._ziteUsageToken;
21
+ }
22
+ // Fallback to stored auth token (external mode)
23
+ if (typeof localStorage !== 'undefined') {
24
+ const stored = localStorage.getItem('zite.auth.token');
25
+ if (stored)
26
+ return stored;
27
+ }
28
+ return '';
13
29
  }
14
30
  export function createCaller(endpoint, name, flowId) {
15
31
  return async (input) => {
16
32
  const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
33
+ const token = getUsageToken();
17
34
  const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
18
35
  method: 'POST',
19
36
  headers: {
20
- Authorization: `Bearer ${getToken()}`,
37
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
21
38
  'Content-Type': 'application/json',
22
39
  },
23
- body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
40
+ body: JSON.stringify({ ...input, mode: 'preview', usageToken: token }),
24
41
  });
25
42
  if (!res.ok) {
26
43
  const text = await res.text().catch(() => '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.14",
3
+ "version": "0.9.15",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",