@aloma.io/integration-sdk 3.1.3 → 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloma.io/integration-sdk",
3
- "version": "3.1.3",
3
+ "version": "3.2.0",
4
4
  "description": "",
5
5
  "author": "aloma.io",
6
6
  "license": "Apache-2.0",
@@ -52,7 +52,7 @@ export class Builder {
52
52
  const packageJson = JSON.parse(
53
53
  fs.readFileSync(__dirname + "/../../../../../package.json", {
54
54
  encoding: "utf-8",
55
- })
55
+ }),
56
56
  );
57
57
 
58
58
  notEmpty((data.id = packageJson.connectorId), "id");
@@ -2,7 +2,10 @@ import { AbstractController } from "../controller/index.mjs";
2
2
  import { Connector } from "../internal/index.mjs";
3
3
 
4
4
  export default class RuntimeContext {
5
- constructor(private controller: AbstractController, private data: any) {}
5
+ constructor(
6
+ private controller: AbstractController,
7
+ private data: any,
8
+ ) {}
6
9
 
7
10
  async start(): Promise<void> {
8
11
  const controller = this.controller;
@@ -54,12 +57,12 @@ export default class RuntimeContext {
54
57
  oauth,
55
58
  newTask,
56
59
  updateTask,
57
- getClient
60
+ getClient,
58
61
  );
59
62
  } catch (e) {
60
63
  console.log(e);
61
64
  }
62
- }
65
+ },
63
66
  );
64
67
 
65
68
  connector.run();
@@ -29,9 +29,8 @@ const transform = (meta: any) => {
29
29
  .getSignatures()
30
30
  .map((sig: any) => {
31
31
  const docs = sig.getJSDoc().serialize() || [];
32
- const desc = docs.find(
33
- (what: any) => what.kind === "description"
34
- )?.value;
32
+ const desc = docs.find((what: any) => what.kind === "description")
33
+ ?.value;
35
34
 
36
35
  const paramDocs =
37
36
  docs
package/src/cli.mts CHANGED
@@ -4,9 +4,9 @@ import { Command } from "commander";
4
4
  import fs from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "node:path";
7
- import JWE from './internal/util/jwe/index.mjs'
8
- import util from 'node:util';
9
- import ChildProcess from 'node:child_process';
7
+ import JWE from "./internal/util/jwe/index.mjs";
8
+ import util from "node:util";
9
+ import ChildProcess from "node:child_process";
10
10
 
11
11
  const exec = util.promisify(ChildProcess.exec);
12
12
 
@@ -30,7 +30,7 @@ const extract = ({ target, name, connectorId }) => {
30
30
 
31
31
  files.forEach(({ name, dir }) => {
32
32
  if (dir) {
33
- fs.mkdirSync(`${target}/${dir}`, {recursive: true});
33
+ fs.mkdirSync(`${target}/${dir}`, { recursive: true });
34
34
  }
35
35
 
36
36
  const content = fs.readFileSync(`${source}/${dir}/${name}`, {
@@ -40,26 +40,28 @@ const extract = ({ target, name, connectorId }) => {
40
40
  });
41
41
 
42
42
  const content = JSON.parse(
43
- fs.readFileSync(`${target}/package.json`, { encoding: "utf-8" })
43
+ fs.readFileSync(`${target}/package.json`, { encoding: "utf-8" }),
44
44
  );
45
45
 
46
46
  content.name = name;
47
47
  content.connectorId = connectorId;
48
48
 
49
49
  fs.writeFileSync(`${target}/package.json`, JSON.stringify(content, null, 2));
50
- fs.writeFileSync(`${target}/.gitignore`, `.DS_Store
50
+ fs.writeFileSync(
51
+ `${target}/.gitignore`,
52
+ `.DS_Store
51
53
  node_modules
52
54
  build
53
- .env`);
55
+ .env`,
56
+ );
54
57
  };
55
58
 
56
- const generateKeys = async ({target}) =>
57
- {
59
+ const generateKeys = async ({ target }) => {
58
60
  const jwe = new JWE({});
59
61
  await jwe.newPair();
60
62
 
61
63
  const priv = await jwe.exportPrivateAsBase64();
62
- const pub = await jwe.exportPublicAsBase64();
64
+ const pub = await jwe.exportPublicAsBase64();
63
65
 
64
66
  const content = `REGISTRATION_TOKEN=
65
67
  PRIVATE_KEY=${priv}
@@ -90,32 +92,34 @@ program
90
92
 
91
93
  fs.mkdirSync(target);
92
94
 
93
- console.log('Creating connector ...');
95
+ console.log("Creating connector ...");
94
96
  extract({ ...options, target, name });
95
-
96
- console.log('Generating keys ...');
97
- await generateKeys({target});
98
-
99
- console.log('Installing dependencies ...');
97
+
98
+ console.log("Generating keys ...");
99
+ await generateKeys({ target });
100
+
101
+ console.log("Installing dependencies ...");
100
102
  await exec(`cd ${target}; yarn`);
101
-
102
- console.log('Building ...');
103
+
104
+ console.log("Building ...");
103
105
  await exec(`cd ${target}; yarn build`);
104
-
106
+
105
107
  console.log(`
106
108
  Success!
107
109
 
108
110
  1.) Add the connector to a workspace
109
111
  2.) Edit ./${name}/.env and insert the registration token
110
- 3.) Start the connector with cd ./${name}/; yarn start`)
112
+ 3.) Start the connector with cd ./${name}/; yarn start`);
111
113
  });
112
114
 
113
115
  program
114
116
  .command("build")
115
117
  .description("Build the current connector project")
116
118
  .action(async (str, options) => {
117
- const {stdout, stderr} = await exec(`rm -rf build; mkdir -p build/controller; cp ./src/controller/index.mts ./build/controller/.controller-for-types.mts;`);
118
-
119
+ const { stdout, stderr } = await exec(
120
+ `rm -rf build; mkdir -p build/controller; cp ./src/controller/index.mts ./build/controller/.controller-for-types.mts;`,
121
+ );
122
+
119
123
  if (stdout) console.log(stdout);
120
124
  });
121
125
 
@@ -47,7 +47,7 @@ export abstract class AbstractController {
47
47
  client: any,
48
48
  newTask: any,
49
49
  updateTask: any,
50
- getClient: any
50
+ getClient: any,
51
51
  ): Promise<void> {
52
52
  this.config = config;
53
53
  this.client = client;
@@ -144,7 +144,7 @@ class Dispatcher {
144
144
  "toString",
145
145
  "toSource",
146
146
  "prototype",
147
- ].includes(what)
147
+ ].includes(what),
148
148
  )
149
149
  .slice(0, 20);
150
150
 
@@ -155,7 +155,7 @@ class Dispatcher {
155
155
  return method
156
156
  ? method(variables)
157
157
  : _resolvers.__default(
158
- variables ? { ...variables, __method: query } : variables
158
+ variables ? { ...variables, __method: query } : variables,
159
159
  );
160
160
  };
161
161
 
@@ -202,4 +202,4 @@ class Dispatcher {
202
202
  }
203
203
  }
204
204
 
205
- export {Dispatcher};
205
+ export { Dispatcher };
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- import dotenv from 'dotenv';
2
+ import dotenv from "dotenv";
3
3
  dotenv.config();
4
4
  import fs from "node:fs";
5
5
  import { Config } from "./websocket/config.mjs";
@@ -11,8 +11,8 @@ import JWE from "./util/jwe/index.mjs";
11
11
  import fetch from "node-fetch";
12
12
  import { init } from "@paralleldrive/cuid2";
13
13
  const cuid = init({ length: 32 });
14
- import express from 'express';
15
- import PromClient from 'prom-client'
14
+ import express from "express";
15
+ import PromClient from "prom-client";
16
16
 
17
17
  // TODO fetch with retry
18
18
 
@@ -29,7 +29,7 @@ const reply = (arg, packet, transport) => {
29
29
  if (!packet.cb()) {
30
30
  console.dir(
31
31
  { msg: "cannot reply to packet without cb", arg, packet },
32
- { depth: null }
32
+ { depth: null },
33
33
  );
34
34
  return;
35
35
  }
@@ -79,25 +79,27 @@ class Fetcher {
79
79
  try {
80
80
  await local.customize(options, args);
81
81
 
82
- if (!options?.headers || !options?.headers?.Accept)
83
- {
82
+ if (!options?.headers || !options?.headers?.Accept) {
84
83
  options.headers = {
85
84
  ...options.headers,
86
- Accept: 'application/json'
87
- }
85
+ Accept: "application/json",
86
+ };
88
87
  }
89
-
90
- if (!options?.headers || !options?.headers?.['Content-type'])
91
- {
88
+
89
+ if (!options?.headers || !options?.headers?.["Content-type"]) {
92
90
  options.headers = {
93
91
  ...options.headers,
94
- 'Content-type': 'application/json'
95
- }
92
+ "Content-type": "application/json",
93
+ };
96
94
  }
97
-
98
- if (!(options?.method === 'GET' || options?.method === 'HEAD') && options?.body && !(typeof(options.body) === 'string') && options?.headers?.['Content-type'] === 'application/json')
99
- {
100
- options.body = JSON.stringify(options.body)
95
+
96
+ if (
97
+ !(options?.method === "GET" || options?.method === "HEAD") &&
98
+ options?.body &&
99
+ !(typeof options.body === "string") &&
100
+ options?.headers?.["Content-type"] === "application/json"
101
+ ) {
102
+ options.body = JSON.stringify(options.body);
101
103
  }
102
104
 
103
105
  const ret = await fetch(theURL, options);
@@ -164,7 +166,7 @@ class OAuthFetcher extends Fetcher {
164
166
  resolve(
165
167
  await local.fetch(url, options, retries, {
166
168
  forceTokenRefresh: e.status === 401,
167
- })
169
+ }),
168
170
  );
169
171
  } catch (e) {
170
172
  reject(e);
@@ -431,13 +433,13 @@ ${text}
431
433
  const ret = JSON.parse(text);
432
434
  if (ret.error) {
433
435
  throw new Error(
434
- `${status} ${ret.error} ${ret.error_description || ""}`
436
+ `${status} ${ret.error} ${ret.error_description || ""}`,
435
437
  );
436
438
  } else if (ret.access_token) {
437
439
  return { ...ret };
438
440
  } else {
439
441
  throw new Error(
440
- status + " response has no access_token - " + text
442
+ status + " response has no access_token - " + text,
441
443
  );
442
444
  }
443
445
  } else {
@@ -521,7 +523,7 @@ ${text}
521
523
  return JSON.parse(text);
522
524
  } else {
523
525
  throw new Error(
524
- "could not get refresh token " + status + " " + text
526
+ "could not get refresh token " + status + " " + text,
525
527
  );
526
528
  }
527
529
  };
@@ -539,7 +541,7 @@ ${text}
539
541
  const packet = transport.newPacket(
540
542
  {},
541
543
  (ret) => (ret?.error ? reject(ret.error) : resolve(ret)),
542
- `_req-${cuid()}`
544
+ `_req-${cuid()}`,
543
545
  );
544
546
 
545
547
  packet.method("connector.task.new");
@@ -556,7 +558,7 @@ ${text}
556
558
  const packet = transport.newPacket(
557
559
  {},
558
560
  (ret) => (ret?.error ? reject(ret.error) : resolve(ret)),
559
- `_req-${cuid()}`
561
+ `_req-${cuid()}`,
560
562
  );
561
563
 
562
564
  packet.method("connector.task.update");
@@ -610,4 +612,4 @@ ${text}
610
612
  }
611
613
  }
612
614
 
613
- export {Connector};
615
+ export { Connector };
@@ -63,7 +63,7 @@ class JWE {
63
63
  {
64
64
  issuer: this.issuer,
65
65
  audience,
66
- }
66
+ },
67
67
  );
68
68
 
69
69
  return payload._data;
@@ -21,8 +21,8 @@ class Connection {
21
21
  body: JSON.stringify({}),
22
22
  headers: { "Content-Type": "application/json" },
23
23
  },
24
- config
25
- )
24
+ config,
25
+ ),
26
26
  );
27
27
 
28
28
  if (response.status === 401) {
@@ -58,8 +58,8 @@ class Connection {
58
58
  body: JSON.stringify({}),
59
59
  headers: { "Content-Type": "application/json" },
60
60
  },
61
- this.config
62
- )
61
+ this.config,
62
+ ),
63
63
  );
64
64
  } catch (e) {
65
65
  // blank
@@ -27,8 +27,8 @@ class Registration {
27
27
  }),
28
28
  headers: { "Content-Type": "application/json" },
29
29
  },
30
- config
31
- )
30
+ config,
31
+ ),
32
32
  );
33
33
 
34
34
  if (response.status === 200) return (await response.json()).key;
@@ -65,7 +65,7 @@ class Transport {
65
65
  const ws = (local.ws = new WebSocket(
66
66
  config.wsUrl(),
67
67
  ["connector"],
68
- C.augmentRequest({ headers: {} }, config)
68
+ C.augmentRequest({ headers: {} }, config),
69
69
  ));
70
70
 
71
71
  ws.on("open", () => {
@@ -28,7 +28,7 @@ class Processor {
28
28
  if (packet.args().packet) {
29
29
  await local.processPacket0(
30
30
  local.transport.newPacket(packet.args().packet),
31
- packet
31
+ packet,
32
32
  );
33
33
  } else {
34
34
  await local.processPacket0(packet, packet);