zitejs 0.8.2 → 0.9.0

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.
@@ -8,14 +8,20 @@ const ENVIRONMENTS = {
8
8
  staging: 'https://workflows.zitestaging.com',
9
9
  local: 'http://localhost:2506',
10
10
  };
11
- const env = process.env.ZITE_ENV ?? 'production';
12
- const RUNNER_URL = process.env.ZITE_RUNNER_URL ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
13
- const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
11
+ function getRunnerUrl() {
12
+ const env = (typeof process !== 'undefined' && process.env?.ZITE_ENV) || 'production';
13
+ return ((typeof process !== 'undefined' && process.env?.ZITE_RUNNER_URL) ||
14
+ ENVIRONMENTS[env] ||
15
+ ENVIRONMENTS.production);
16
+ }
17
+ function getToken() {
18
+ return (typeof process !== 'undefined' && process.env?.ZITE_DB_TOKEN) || '';
19
+ }
14
20
  async function wrapSdkCall(integrationId, className, methodName, params) {
15
- const res = await fetch(`${RUNNER_URL}/sdk/execute`, {
21
+ const res = await fetch(`${getRunnerUrl()}/sdk/execute`, {
16
22
  method: 'POST',
17
23
  headers: {
18
- Authorization: `Bearer ${TOKEN}`,
24
+ Authorization: `Bearer ${getToken()}`,
19
25
  'Content-Type': 'application/json',
20
26
  },
21
27
  body: JSON.stringify({ integrationId, className, methodName, params }),
@@ -46,13 +52,11 @@ function createTableClient(integrationId, className) {
46
52
  };
47
53
  }
48
54
  function createCaller(endpoint) {
49
- const runnerUrl = process.env.ZITE_RUNNER_URL ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
50
- const token = process.env.ZITE_DB_TOKEN ?? '';
51
55
  return async (input) => {
52
- const res = await fetch(runnerUrl + '/api/' + endpoint._name, {
56
+ const res = await fetch(getRunnerUrl() + '/api/' + endpoint._name, {
53
57
  method: 'POST',
54
58
  headers: {
55
- Authorization: `Bearer ${token}`,
59
+ Authorization: `Bearer ${getToken()}`,
56
60
  'Content-Type': 'application/json',
57
61
  },
58
62
  body: JSON.stringify(input),
@@ -136,9 +136,15 @@ function generateApiTs(endpointFiles) {
136
136
  endpointNames.push(camelName);
137
137
  }
138
138
  lines.push('');
139
+ // Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
140
+ for (const name of endpointNames) {
141
+ lines.push(`export const ${name} = createCaller(${name}Endpoint);`);
142
+ }
143
+ lines.push('');
144
+ // Also export as a single api object
139
145
  lines.push('export const api = {');
140
146
  for (const name of endpointNames) {
141
- lines.push(` ${name}: createCaller(${name}Endpoint),`);
147
+ lines.push(` ${name},`);
142
148
  }
143
149
  lines.push('};');
144
150
  lines.push('');
@@ -3,14 +3,20 @@ const ENVIRONMENTS = {
3
3
  staging: 'https://workflows.zitestaging.com',
4
4
  local: 'http://localhost:2506',
5
5
  };
6
- const env = process.env.ZITE_ENV ?? 'production';
7
- const RUNNER_URL = process.env.ZITE_RUNNER_URL ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
8
- const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
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
+ }
9
15
  export async function wrapSdkCall(integrationId, className, methodName, params) {
10
- const res = await fetch(`${RUNNER_URL}/sdk/execute`, {
16
+ const res = await fetch(`${getRunnerUrl()}/sdk/execute`, {
11
17
  method: 'POST',
12
18
  headers: {
13
- Authorization: `Bearer ${TOKEN}`,
19
+ Authorization: `Bearer ${getToken()}`,
14
20
  'Content-Type': 'application/json',
15
21
  },
16
22
  body: JSON.stringify({ integrationId, className, methodName, params }),
@@ -41,13 +47,11 @@ export function createTableClient(integrationId, className) {
41
47
  };
42
48
  }
43
49
  export function createCaller(endpoint) {
44
- const runnerUrl = process.env.ZITE_RUNNER_URL ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
45
- const token = process.env.ZITE_DB_TOKEN ?? '';
46
50
  return async (input) => {
47
- const res = await fetch(runnerUrl + '/api/' + endpoint._name, {
51
+ const res = await fetch(getRunnerUrl() + '/api/' + endpoint._name, {
48
52
  method: 'POST',
49
53
  headers: {
50
- Authorization: `Bearer ${token}`,
54
+ Authorization: `Bearer ${getToken()}`,
51
55
  'Content-Type': 'application/json',
52
56
  },
53
57
  body: JSON.stringify(input),
@@ -128,9 +128,15 @@ export function generateApiTs(endpointFiles) {
128
128
  endpointNames.push(camelName);
129
129
  }
130
130
  lines.push('');
131
+ // Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
132
+ for (const name of endpointNames) {
133
+ lines.push(`export const ${name} = createCaller(${name}Endpoint);`);
134
+ }
135
+ lines.push('');
136
+ // Also export as a single api object
131
137
  lines.push('export const api = {');
132
138
  for (const name of endpointNames) {
133
- lines.push(` ${name}: createCaller(${name}Endpoint),`);
139
+ lines.push(` ${name},`);
134
140
  }
135
141
  lines.push('};');
136
142
  lines.push('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",