@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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/package.json +1 -1
  3. 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sola-air-ui/relay",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "Sola Relay — local data proxy that keeps credentials on-device and streams live data to Sola components",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -149,18 +149,18 @@ class GoogleSheetsConnector {
149
149
  async disconnect() {}
150
150
  }
151
151
 
152
- class ServiceNowConnector {
152
+ class RestTableConnector {
153
153
  constructor(config) {
154
- this.instance = config.instance || config.host || process.env.SN_INSTANCE || '';
155
- this.username = config.username || config.user || process.env.SN_USERNAME || '';
156
- this.password = config.password || process.env.SN_PASSWORD || '';
157
- this.token = config.token || config.bearerToken || process.env.SN_BEARER_TOKEN || '';
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("ServiceNow instance URL or domain is required (e.g. 'dev12345.service-now.com')");
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}.service-now.com`;
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(`ServiceNow API error (${res.status} ${res.statusText}): ${errText}`);
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 ServiceNow record");
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}.service-now.com`;
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(`ServiceNow mutation error (${res.status} ${res.statusText}): ${errText}`);
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 'servicenow':
330
- case 'now':
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 === 'servicenow' ||
492
- conn.type === 'now';
490
+ conn.type === 'rest-table';
493
491
 
494
492
  let result;
495
493
  if (isNonSql) {