@sola-air-ui/relay 1.0.4 → 2.0.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.
- package/README.md +5 -0
- package/package.json +1 -1
- package/src/index.js +14 -16
package/README.md
CHANGED
|
@@ -36,6 +36,11 @@ npx sola-relay --port 4040
|
|
|
36
36
|
- **PostgreSQL** (via `pg`)
|
|
37
37
|
- **MySQL** (via `mysql2`)
|
|
38
38
|
- **Google Sheets** (`type: "sheet"` with a `sheetId`): reads a sheet that is shared publicly, as CSV.
|
|
39
|
+
- **REST table API** (`type: "rest-table"`): reads, and can update, records through a table-style JSON API. Settings: `host` (a hostname such as `records.example.com`, or a full URL), `table` (default table name), and either `token` or `username` and `password`. Each can come from the environment instead: `REST_TABLE_HOST`, `REST_TABLE_BEARER_TOKEN`, `REST_TABLE_USERNAME`, `REST_TABLE_PASSWORD`. Queries pass `table`, `query`, `fields` and `limit` options.
|
|
40
|
+
|
|
41
|
+
### Upgrading from 1.x
|
|
42
|
+
|
|
43
|
+
2.0.0 renames the table connector. Change `type` from the old vendor-named type (or its short alias) to `rest-table`, put a full hostname or URL in `host`, and rename the `SN_*` environment variables to the `REST_TABLE_*` names above. A bare instance name no longer gets a vendor domain added. SQL and Google Sheets connections are unchanged.
|
|
39
44
|
|
|
40
45
|
## Usage from a component
|
|
41
46
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -149,18 +149,18 @@ class GoogleSheetsConnector {
|
|
|
149
149
|
async disconnect() {}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
class
|
|
152
|
+
class RestTableConnector {
|
|
153
153
|
constructor(config) {
|
|
154
|
-
this.instance = config.instance || config.host || process.env.
|
|
155
|
-
this.username = config.username || config.user || process.env.
|
|
156
|
-
this.password = config.password || process.env.
|
|
157
|
-
this.token = config.token || config.bearerToken || process.env.
|
|
154
|
+
this.instance = config.instance || config.host || process.env.REST_TABLE_HOST || '';
|
|
155
|
+
this.username = config.username || config.user || process.env.REST_TABLE_USERNAME || '';
|
|
156
|
+
this.password = config.password || process.env.REST_TABLE_PASSWORD || '';
|
|
157
|
+
this.token = config.token || config.bearerToken || process.env.REST_TABLE_BEARER_TOKEN || '';
|
|
158
158
|
this.defaultTable = config.table || 'incident';
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
async connect() {
|
|
162
162
|
if (!this.instance) {
|
|
163
|
-
throw new Error("
|
|
163
|
+
throw new Error("REST table host (a hostname or full URL) is required (e.g. 'records.example.com')");
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -170,7 +170,7 @@ class ServiceNowConnector {
|
|
|
170
170
|
const limit = options.limit || options.sysparm_limit || 20;
|
|
171
171
|
const fields = options.fields || 'number,short_description,priority,state,assigned_to,assignment_group,sys_created_on';
|
|
172
172
|
|
|
173
|
-
const baseUrl = this.instance.startsWith('http') ? this.instance : `https://${this.instance}
|
|
173
|
+
const baseUrl = this.instance.startsWith('http') ? this.instance : `https://${this.instance}`;
|
|
174
174
|
const endpoint = `${baseUrl}/api/now/table/${table}?sysparm_query=${encodeURIComponent(query)}&sysparm_limit=${limit}&sysparm_display_value=true&sysparm_fields=${encodeURIComponent(fields)}`;
|
|
175
175
|
|
|
176
176
|
const headers = {
|
|
@@ -188,7 +188,7 @@ class ServiceNowConnector {
|
|
|
188
188
|
const res = await fetch(endpoint, { headers });
|
|
189
189
|
if (!res.ok) {
|
|
190
190
|
const errText = await res.text();
|
|
191
|
-
throw new Error(`
|
|
191
|
+
throw new Error(`Table API error (${res.status} ${res.statusText}): ${errText}`);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
const data = await res.json();
|
|
@@ -199,9 +199,9 @@ class ServiceNowConnector {
|
|
|
199
199
|
async mutate(action, payload = {}) {
|
|
200
200
|
const table = payload.table || this.defaultTable;
|
|
201
201
|
const sysId = payload.sys_id || payload.id;
|
|
202
|
-
if (!sysId) throw new Error("sys_id is required to mutate
|
|
202
|
+
if (!sysId) throw new Error("sys_id is required to mutate record");
|
|
203
203
|
|
|
204
|
-
const baseUrl = this.instance.startsWith('http') ? this.instance : `https://${this.instance}
|
|
204
|
+
const baseUrl = this.instance.startsWith('http') ? this.instance : `https://${this.instance}`;
|
|
205
205
|
const endpoint = `${baseUrl}/api/now/table/${table}/${sysId}`;
|
|
206
206
|
|
|
207
207
|
const headers = {
|
|
@@ -225,7 +225,7 @@ class ServiceNowConnector {
|
|
|
225
225
|
|
|
226
226
|
if (!res.ok) {
|
|
227
227
|
const errText = await res.text();
|
|
228
|
-
throw new Error(`
|
|
228
|
+
throw new Error(`Table mutation error (${res.status} ${res.statusText}): ${errText}`);
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
const data = await res.json();
|
|
@@ -326,9 +326,8 @@ export function addConnection(name, type, config) {
|
|
|
326
326
|
case 'googlesheets':
|
|
327
327
|
connector = new GoogleSheetsConnector(config);
|
|
328
328
|
break;
|
|
329
|
-
case '
|
|
330
|
-
|
|
331
|
-
connector = new ServiceNowConnector(config);
|
|
329
|
+
case 'rest-table':
|
|
330
|
+
connector = new RestTableConnector(config);
|
|
332
331
|
break;
|
|
333
332
|
default:
|
|
334
333
|
throw new Error(`Unsupported connector type: ${type}`);
|
|
@@ -488,8 +487,7 @@ export class RelayServer {
|
|
|
488
487
|
const isNonSql =
|
|
489
488
|
conn.type === 'sheet' ||
|
|
490
489
|
conn.type === 'googlesheets' ||
|
|
491
|
-
conn.type === '
|
|
492
|
-
conn.type === 'now';
|
|
490
|
+
conn.type === 'rest-table';
|
|
493
491
|
|
|
494
492
|
let result;
|
|
495
493
|
if (isNonSql) {
|