@aloma.io/integration-sdk 3.1.3 → 3.2.1
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/build/builder/transform/index.mjs +2 -1
- package/build/cli.mjs +7 -7
- package/build/internal/index.mjs +10 -7
- package/package.json +2 -2
- package/src/builder/index.mts +1 -1
- package/src/builder/runtime-context.mts +6 -3
- package/src/builder/transform/index.mts +2 -3
- package/src/cli.mts +26 -22
- package/src/controller/index.mts +1 -1
- package/src/internal/dispatcher/index.mjs +3 -3
- package/src/internal/index.mjs +26 -24
- package/src/internal/util/jwe/index.mjs +1 -1
- package/src/internal/websocket/connection/index.mjs +4 -4
- package/src/internal/websocket/connection/registration.mjs +2 -2
- package/src/internal/websocket/transport/index.mjs +1 -1
- package/src/internal/websocket/transport/processor.mjs +1 -1
- package/template/connector/package.json +1 -1
@@ -22,7 +22,8 @@ const transform = (meta) => {
|
|
22
22
|
.getSignatures()
|
23
23
|
.map((sig) => {
|
24
24
|
const docs = sig.getJSDoc().serialize() || [];
|
25
|
-
const desc = docs.find((what) => what.kind === "description")
|
25
|
+
const desc = docs.find((what) => what.kind === "description")
|
26
|
+
?.value;
|
26
27
|
const paramDocs = docs
|
27
28
|
.filter((what) => what.kind === "param")
|
28
29
|
.map((what) => {
|
package/build/cli.mjs
CHANGED
@@ -3,9 +3,9 @@ import { Command } from "commander";
|
|
3
3
|
import fs from "node:fs";
|
4
4
|
import { fileURLToPath } from "node:url";
|
5
5
|
import path from "node:path";
|
6
|
-
import JWE from
|
7
|
-
import util from
|
8
|
-
import ChildProcess from
|
6
|
+
import JWE from "./internal/util/jwe/index.mjs";
|
7
|
+
import util from "node:util";
|
8
|
+
import ChildProcess from "node:child_process";
|
9
9
|
const exec = util.promisify(ChildProcess.exec);
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
11
11
|
const files = [
|
@@ -67,13 +67,13 @@ program
|
|
67
67
|
throw new Error("name is empty");
|
68
68
|
const target = `${process.cwd()}/${name}`;
|
69
69
|
fs.mkdirSync(target);
|
70
|
-
console.log(
|
70
|
+
console.log("Creating connector ...");
|
71
71
|
extract({ ...options, target, name });
|
72
|
-
console.log(
|
72
|
+
console.log("Generating keys ...");
|
73
73
|
await generateKeys({ target });
|
74
|
-
console.log(
|
74
|
+
console.log("Installing dependencies ...");
|
75
75
|
await exec(`cd ${target}; yarn`);
|
76
|
-
console.log(
|
76
|
+
console.log("Building ...");
|
77
77
|
await exec(`cd ${target}; yarn build`);
|
78
78
|
console.log(`
|
79
79
|
Success!
|
package/build/internal/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
// @ts-nocheck
|
2
|
-
import dotenv from
|
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
|
15
|
-
import PromClient from
|
14
|
+
import express from "express";
|
15
|
+
import PromClient from "prom-client";
|
16
16
|
// TODO fetch with retry
|
17
17
|
const handlePacketError = (packet, e, transport) => {
|
18
18
|
if (!packet.cb()) {
|
@@ -64,16 +64,19 @@ class Fetcher {
|
|
64
64
|
if (!options?.headers || !options?.headers?.Accept) {
|
65
65
|
options.headers = {
|
66
66
|
...options.headers,
|
67
|
-
Accept:
|
67
|
+
Accept: "application/json",
|
68
68
|
};
|
69
69
|
}
|
70
|
-
if (!options?.headers || !options?.headers?.[
|
70
|
+
if (!options?.headers || !options?.headers?.["Content-type"]) {
|
71
71
|
options.headers = {
|
72
72
|
...options.headers,
|
73
|
-
|
73
|
+
"Content-type": "application/json",
|
74
74
|
};
|
75
75
|
}
|
76
|
-
if (!(options?.method ===
|
76
|
+
if (!(options?.method === "GET" || options?.method === "HEAD") &&
|
77
|
+
options?.body &&
|
78
|
+
!(typeof options.body === "string") &&
|
79
|
+
options?.headers?.["Content-type"] === "application/json") {
|
77
80
|
options.body = JSON.stringify(options.body);
|
78
81
|
}
|
79
82
|
const ret = await fetch(theURL, options);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@aloma.io/integration-sdk",
|
3
|
-
"version": "3.1
|
3
|
+
"version": "3.2.1",
|
4
4
|
"description": "",
|
5
5
|
"author": "aloma.io",
|
6
6
|
"license": "Apache-2.0",
|
@@ -27,7 +27,7 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"@paralleldrive/cuid2": "^2",
|
29
29
|
"@ts-ast-parser/core": "^0",
|
30
|
-
"@types/node": "^
|
30
|
+
"@types/node": "^16",
|
31
31
|
"commander": "^11",
|
32
32
|
"dotenv": "*",
|
33
33
|
"express": "^4",
|
package/src/builder/index.mts
CHANGED
@@ -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(
|
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
|
-
|
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
|
8
|
-
import util from
|
9
|
-
import ChildProcess from
|
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(
|
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
|
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(
|
95
|
+
console.log("Creating connector ...");
|
94
96
|
extract({ ...options, target, name });
|
95
|
-
|
96
|
-
console.log(
|
97
|
-
await generateKeys({target});
|
98
|
-
|
99
|
-
console.log(
|
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(
|
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(
|
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
|
|
package/src/controller/index.mts
CHANGED
@@ -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 };
|
package/src/internal/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
// @ts-nocheck
|
2
|
-
import dotenv from
|
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
|
15
|
-
import PromClient from
|
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:
|
87
|
-
}
|
85
|
+
Accept: "application/json",
|
86
|
+
};
|
88
87
|
}
|
89
|
-
|
90
|
-
if (!options?.headers || !options?.headers?.[
|
91
|
-
{
|
88
|
+
|
89
|
+
if (!options?.headers || !options?.headers?.["Content-type"]) {
|
92
90
|
options.headers = {
|
93
91
|
...options.headers,
|
94
|
-
|
95
|
-
}
|
92
|
+
"Content-type": "application/json",
|
93
|
+
};
|
96
94
|
}
|
97
|
-
|
98
|
-
if (
|
99
|
-
|
100
|
-
options
|
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 };
|
@@ -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
|