@aloma.io/integration-sdk 3.7.17 → 3.7.18
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/index.mjs +6 -3
- package/build/cli.mjs +7 -2
- package/package.json +1 -1
- package/src/builder/index.mts +8 -7
- package/src/builder/runtime-context.mts +2 -3
- package/src/cli.mts +17 -8
- package/src/internal/dispatcher/index.mts +1 -1
- package/src/internal/fetcher/fetcher.mts +12 -2
- package/src/internal/fetcher/oauth-fetcher.mts +1 -1
- package/src/internal/index.mts +14 -10
- package/src/internal/util/index.mts +2 -4
package/build/builder/index.mjs
CHANGED
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
4
4
|
import { notEmpty } from "../internal/util/index.mjs";
|
5
5
|
import RuntimeContext from "./runtime-context.mjs";
|
6
|
-
const DIR_OFFSET =
|
6
|
+
const DIR_OFFSET = "/../../../../../";
|
7
7
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
8
8
|
export const TARGET_DIR = `${__dirname}${DIR_OFFSET}`;
|
9
9
|
export class Builder {
|
@@ -26,7 +26,8 @@ export class Builder {
|
|
26
26
|
await this.loadDescriptor();
|
27
27
|
await this.checkIcon();
|
28
28
|
// @ts-ignore
|
29
|
-
const Controller = (await import(TARGET_DIR + "build/controller/index.mjs"))
|
29
|
+
const Controller = (await import(TARGET_DIR + "build/controller/index.mjs"))
|
30
|
+
.default;
|
30
31
|
return new RuntimeContext(new Controller(), this.data);
|
31
32
|
}
|
32
33
|
async checkIcon() {
|
@@ -35,7 +36,9 @@ export class Builder {
|
|
35
36
|
}
|
36
37
|
async loadDescriptor() {
|
37
38
|
notEmpty(this.data.controller, "controller");
|
38
|
-
const content = fs.readFileSync(this.data.controller, {
|
39
|
+
const content = fs.readFileSync(this.data.controller, {
|
40
|
+
encoding: "utf-8",
|
41
|
+
});
|
39
42
|
const { text, methods, connectorId, version } = JSON.parse(content);
|
40
43
|
this.data.types = text;
|
41
44
|
this.data.methods = methods;
|
package/build/cli.mjs
CHANGED
@@ -99,7 +99,7 @@ program
|
|
99
99
|
}
|
100
100
|
if (stdout)
|
101
101
|
console.log(stdout);
|
102
|
-
new Extractor().extract(
|
102
|
+
new Extractor().extract("./src/controller/index.mts", "./build/.controller.json");
|
103
103
|
});
|
104
104
|
class Extractor {
|
105
105
|
async extract(source, target) {
|
@@ -109,7 +109,12 @@ class Extractor {
|
|
109
109
|
const packageJson = JSON.parse(fs.readFileSync(TARGET_DIR + "package.json", {
|
110
110
|
encoding: "utf-8",
|
111
111
|
}));
|
112
|
-
fs.writeFileSync(target, JSON.stringify({
|
112
|
+
fs.writeFileSync(target, JSON.stringify({
|
113
|
+
text,
|
114
|
+
methods,
|
115
|
+
connectorId: packageJson.connectorId,
|
116
|
+
version: packageJson.version,
|
117
|
+
}), { encoding: "utf-8" });
|
113
118
|
}
|
114
119
|
}
|
115
120
|
program.parse();
|
package/package.json
CHANGED
package/src/builder/index.mts
CHANGED
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
4
4
|
import { notEmpty } from "../internal/util/index.mjs";
|
5
5
|
import RuntimeContext from "./runtime-context.mjs";
|
6
6
|
|
7
|
-
const DIR_OFFSET =
|
7
|
+
const DIR_OFFSET = "/../../../../../";
|
8
8
|
|
9
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
10
10
|
|
@@ -37,9 +37,8 @@ export class Builder {
|
|
37
37
|
await this.checkIcon();
|
38
38
|
|
39
39
|
// @ts-ignore
|
40
|
-
const Controller = (
|
41
|
-
|
42
|
-
).default;
|
40
|
+
const Controller = (await import(TARGET_DIR + "build/controller/index.mjs"))
|
41
|
+
.default;
|
43
42
|
|
44
43
|
return new RuntimeContext(new Controller(), this.data);
|
45
44
|
}
|
@@ -53,8 +52,10 @@ export class Builder {
|
|
53
52
|
private async loadDescriptor() {
|
54
53
|
notEmpty(this.data.controller, "controller");
|
55
54
|
|
56
|
-
const content = fs.readFileSync(this.data.controller, {
|
57
|
-
|
55
|
+
const content = fs.readFileSync(this.data.controller, {
|
56
|
+
encoding: "utf-8",
|
57
|
+
});
|
58
|
+
const { text, methods, connectorId, version } = JSON.parse(content);
|
58
59
|
|
59
60
|
this.data.types = text;
|
60
61
|
this.data.methods = methods;
|
@@ -62,4 +63,4 @@ export class Builder {
|
|
62
63
|
notEmpty((this.data.id = connectorId), "id");
|
63
64
|
notEmpty((this.data.version = version), "version");
|
64
65
|
}
|
65
|
-
}
|
66
|
+
}
|
@@ -11,11 +11,10 @@ export default class RuntimeContext {
|
|
11
11
|
async start(): Promise<void> {
|
12
12
|
const controller = this.controller;
|
13
13
|
|
14
|
-
if (!(controller instanceof AbstractController))
|
15
|
-
{
|
14
|
+
if (!(controller instanceof AbstractController)) {
|
16
15
|
throw new Error("the controller needs to extend AbstractController");
|
17
16
|
}
|
18
|
-
|
17
|
+
|
19
18
|
const data: any = this.data;
|
20
19
|
|
21
20
|
let icon;
|
package/src/cli.mts
CHANGED
@@ -120,20 +120,20 @@ program
|
|
120
120
|
.command("build")
|
121
121
|
.description("Build the current connector project")
|
122
122
|
.action(async (str, options) => {
|
123
|
-
const { stdout, stderr } = await exec(
|
124
|
-
`rm -rf build; mkdir -p build; `,
|
125
|
-
);
|
123
|
+
const { stdout, stderr } = await exec(`rm -rf build; mkdir -p build; `);
|
126
124
|
|
127
|
-
try
|
128
|
-
{
|
125
|
+
try {
|
129
126
|
fs.copyFileSync(`${TARGET_DIR}/logo.png`, `${TARGET_DIR}/build/logo.png`);
|
130
|
-
} catch(e) {
|
127
|
+
} catch (e) {
|
131
128
|
// blank
|
132
129
|
}
|
133
130
|
|
134
131
|
if (stdout) console.log(stdout);
|
135
132
|
|
136
|
-
new Extractor().extract(
|
133
|
+
new Extractor().extract(
|
134
|
+
"./src/controller/index.mts",
|
135
|
+
"./build/.controller.json",
|
136
|
+
);
|
137
137
|
});
|
138
138
|
|
139
139
|
class Extractor {
|
@@ -149,7 +149,16 @@ class Extractor {
|
|
149
149
|
}),
|
150
150
|
);
|
151
151
|
|
152
|
-
fs.writeFileSync(
|
152
|
+
fs.writeFileSync(
|
153
|
+
target,
|
154
|
+
JSON.stringify({
|
155
|
+
text,
|
156
|
+
methods,
|
157
|
+
connectorId: packageJson.connectorId,
|
158
|
+
version: packageJson.version,
|
159
|
+
}),
|
160
|
+
{ encoding: "utf-8" },
|
161
|
+
);
|
153
162
|
}
|
154
163
|
}
|
155
164
|
|
@@ -16,7 +16,14 @@ export default class Fetcher {
|
|
16
16
|
if (this.customize0) await this.customize0(options, args);
|
17
17
|
}
|
18
18
|
|
19
|
-
async onError(
|
19
|
+
async onError(
|
20
|
+
e: any,
|
21
|
+
url: string,
|
22
|
+
options: any,
|
23
|
+
retries: number,
|
24
|
+
args: any,
|
25
|
+
rateLimit?,
|
26
|
+
) {
|
20
27
|
var local = this;
|
21
28
|
|
22
29
|
return new Promise((resolve, reject) => {
|
@@ -83,7 +90,10 @@ export default class Fetcher {
|
|
83
90
|
options.body = JSON.stringify(options.body);
|
84
91
|
}
|
85
92
|
|
86
|
-
const timeout = Math.min(
|
93
|
+
const timeout = Math.min(
|
94
|
+
options?.timeout || 30 * 60 * 1000,
|
95
|
+
30 * 60 * 1000,
|
96
|
+
);
|
87
97
|
const ret = await fetch(theURL, {
|
88
98
|
...options,
|
89
99
|
signal: AbortSignal.timeout(timeout),
|
package/src/internal/index.mts
CHANGED
@@ -139,11 +139,13 @@ ${text}
|
|
139
139
|
this.startOAuth = async function (args) {
|
140
140
|
if (!this._oauth) throw new Error("oauth not configured");
|
141
141
|
|
142
|
-
const authorizationURL =
|
143
|
-
|
144
|
-
|
142
|
+
const authorizationURL =
|
143
|
+
process.env.OAUTH_AUTHORIZATION_URL ||
|
144
|
+
decrypted.authorizationURL ||
|
145
|
+
that._oauth.authorizationURL;
|
145
146
|
|
146
|
-
if (!authorizationURL)
|
147
|
+
if (!authorizationURL)
|
148
|
+
throw new Error("authorizationURL not configured");
|
147
149
|
|
148
150
|
const clientId =
|
149
151
|
process.env.OAUTH_CLIENT_ID ||
|
@@ -171,9 +173,10 @@ ${text}
|
|
171
173
|
this.finishOAuth = async function (arg) {
|
172
174
|
var that = this;
|
173
175
|
|
174
|
-
const tokenURL =
|
175
|
-
|
176
|
-
|
176
|
+
const tokenURL =
|
177
|
+
process.env.OAUTH_TOKEN_URL ||
|
178
|
+
decrypted.tokenURL ||
|
179
|
+
that._oauth.tokenURL;
|
177
180
|
|
178
181
|
if (!this._oauth) throw new Error("oauth not configured");
|
179
182
|
if (!tokenURL && !this._oauth.finishOAuth)
|
@@ -292,9 +295,10 @@ ${text}
|
|
292
295
|
const that = this;
|
293
296
|
|
294
297
|
const getRefreshToken = async (refreshToken) => {
|
295
|
-
const tokenURL =
|
296
|
-
|
297
|
-
|
298
|
+
const tokenURL =
|
299
|
+
process.env.OAUTH_TOKEN_URL ||
|
300
|
+
decrypted.tokenURL ||
|
301
|
+
that._oauth.tokenURL;
|
298
302
|
|
299
303
|
const clientId =
|
300
304
|
process.env.OAUTH_CLIENT_ID ||
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
export const handlePacketError = (packet, e, transport) => {
|
3
2
|
if (!packet.cb()) {
|
4
3
|
console.dir({ msg: "packet error", e, packet }, { depth: null });
|
@@ -35,9 +34,9 @@ export const unwrap = async (ret, options) => {
|
|
35
34
|
|
36
35
|
return unwrap0(ret, base64, options);
|
37
36
|
}
|
38
|
-
|
37
|
+
|
39
38
|
if (options?.skipResponseBody) {
|
40
|
-
return { status: ret.status, headers: ret.headers};
|
39
|
+
return { status: ret.status, headers: ret.headers };
|
41
40
|
}
|
42
41
|
|
43
42
|
const text = await ret.text();
|
@@ -49,7 +48,6 @@ export const unwrap = async (ret, options) => {
|
|
49
48
|
}
|
50
49
|
};
|
51
50
|
|
52
|
-
|
53
51
|
export const notEmpty = (what, name) => {
|
54
52
|
if (!what?.trim()) throw new Error(`${name} cannot be empty`);
|
55
53
|
|