@aloma.io/integration-sdk 3.0.0-5 → 3.0.0-6
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.d.mts +0 -2
- package/build/builder/index.mjs +5 -12
- package/build/builder/runtime-context.mjs +14 -10
- package/build/controller/index.mjs +1 -1
- package/package.json +1 -1
- package/src/builder/index.mts +9 -18
- package/src/builder/runtime-context.mts +19 -13
- package/src/controller/index.mts +1 -1
package/build/builder/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import fs from 'fs';
|
1
|
+
import fs from 'node:fs';
|
2
2
|
import parseTypes from './transform/index.mjs';
|
3
3
|
import RuntimeContext from './runtime-context.mjs';
|
4
4
|
import { fileURLToPath } from 'node:url';
|
@@ -11,18 +11,11 @@ const notEmpty = (what, name) => {
|
|
11
11
|
};
|
12
12
|
export class Builder {
|
13
13
|
data = { controller: './build/controller/.controller-for-types.mts' };
|
14
|
-
id(what) {
|
15
|
-
this.data.id = notEmpty(what, 'id');
|
16
|
-
return this;
|
17
|
-
}
|
18
|
-
version(what) {
|
19
|
-
this.data.version = notEmpty(what, 'version');
|
20
|
-
return this;
|
21
|
-
}
|
22
14
|
config(arg) {
|
23
15
|
return this;
|
24
16
|
}
|
25
17
|
options(arg) {
|
18
|
+
this.data.options = arg;
|
26
19
|
return this;
|
27
20
|
}
|
28
21
|
auth(arg) {
|
@@ -30,13 +23,13 @@ export class Builder {
|
|
30
23
|
}
|
31
24
|
async build() {
|
32
25
|
const data = this.data;
|
33
|
-
notEmpty(data.id, 'id');
|
34
|
-
notEmpty(data.version, 'version');
|
35
26
|
await this.discoverTypes();
|
36
27
|
// validate config
|
37
28
|
// validate options
|
38
29
|
// validate auth
|
39
|
-
|
30
|
+
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/../../../../../package.json', { encoding: 'utf-8' }));
|
31
|
+
notEmpty(data.id = packageJson.connectorId, 'id');
|
32
|
+
notEmpty(data.version = packageJson.version, 'version');
|
40
33
|
// @ts-ignore
|
41
34
|
const Controller = (await import(__dirname + '/../../../../../build/controller/index.mjs')).default;
|
42
35
|
return new RuntimeContext(new Controller(), this.data);
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { AbstractController } from '../controller/index.mjs';
|
1
2
|
import { Connector } from '../internal/index.cjs';
|
2
3
|
export default class RuntimeContext {
|
3
4
|
controller;
|
@@ -8,13 +9,17 @@ export default class RuntimeContext {
|
|
8
9
|
}
|
9
10
|
async start() {
|
10
11
|
const controller = this.controller;
|
12
|
+
if (!(controller instanceof AbstractController))
|
13
|
+
throw new Error('the controller needs to extend AbstractController');
|
14
|
+
const data = this.data;
|
11
15
|
const connector = new Connector({
|
12
|
-
id:
|
13
|
-
version:
|
14
|
-
name: `${
|
16
|
+
id: data.id,
|
17
|
+
version: data.version,
|
18
|
+
name: `${data.id}/${data.version}`,
|
15
19
|
});
|
20
|
+
const configuration = connector.configure();
|
16
21
|
const resolvers = {};
|
17
|
-
const methods = [...
|
22
|
+
const methods = [...data.methods, '__endpoint', '__configQuery', '__default'];
|
18
23
|
methods.forEach((method) => {
|
19
24
|
resolvers[method] = async (args) => {
|
20
25
|
console.log('call', method, args);
|
@@ -23,12 +28,11 @@ export default class RuntimeContext {
|
|
23
28
|
return controller[method](args);
|
24
29
|
};
|
25
30
|
});
|
26
|
-
|
27
|
-
|
28
|
-
.
|
29
|
-
|
30
|
-
|
31
|
-
.main(async ({ newTask, updateTask, config, oauth, getClient }) => {
|
31
|
+
configuration.types(data.types).resolvers(resolvers);
|
32
|
+
if (data.options?.endpoint) {
|
33
|
+
configuration.endpoint((arg) => controller.__endpoint(arg));
|
34
|
+
}
|
35
|
+
configuration.main(async ({ newTask, updateTask, config, oauth, getClient }) => {
|
32
36
|
try {
|
33
37
|
await controller._doStop();
|
34
38
|
await controller._doStart(config, oauth, newTask, updateTask, getClient);
|
package/package.json
CHANGED
package/src/builder/index.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import fs from 'fs';
|
1
|
+
import fs from 'node:fs';
|
2
2
|
import parseTypes from './transform/index.mjs';
|
3
3
|
import RuntimeContext from './runtime-context.mjs';
|
4
4
|
import {fileURLToPath} from 'node:url';
|
@@ -15,23 +15,12 @@ const notEmpty = (what, name) => {
|
|
15
15
|
export class Builder {
|
16
16
|
private data: any = {controller: './build/controller/.controller-for-types.mts'};
|
17
17
|
|
18
|
-
id(what: string): Builder {
|
19
|
-
this.data.id = notEmpty(what, 'id');
|
20
|
-
|
21
|
-
return this;
|
22
|
-
}
|
23
|
-
|
24
|
-
version(what: string): Builder {
|
25
|
-
this.data.version = notEmpty(what, 'version');
|
26
|
-
|
27
|
-
return this;
|
28
|
-
}
|
29
|
-
|
30
18
|
config(arg: any): Builder {
|
31
19
|
return this;
|
32
20
|
}
|
33
21
|
|
34
22
|
options(arg: any): Builder {
|
23
|
+
this.data.options = arg;
|
35
24
|
return this;
|
36
25
|
}
|
37
26
|
|
@@ -42,16 +31,18 @@ export class Builder {
|
|
42
31
|
async build(): Promise<RuntimeContext> {
|
43
32
|
const data = this.data;
|
44
33
|
|
45
|
-
notEmpty(data.id, 'id');
|
46
|
-
notEmpty(data.version, 'version');
|
47
|
-
|
48
34
|
await this.discoverTypes();
|
49
35
|
|
50
36
|
// validate config
|
51
37
|
// validate options
|
52
38
|
// validate auth
|
53
39
|
|
54
|
-
|
40
|
+
|
41
|
+
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/../../../../../package.json', {encoding: 'utf-8'}));
|
42
|
+
|
43
|
+
notEmpty(data.id = packageJson.connectorId, 'id');
|
44
|
+
notEmpty(data.version= packageJson.version, 'version');
|
45
|
+
|
55
46
|
// @ts-ignore
|
56
47
|
const Controller = (await import(__dirname + '/../../../../../build/controller/index.mjs')).default;
|
57
48
|
|
@@ -64,7 +55,7 @@ export class Builder {
|
|
64
55
|
const content = fs.readFileSync(this.data.controller);
|
65
56
|
const {text, methods} = parseTypes(this.data.controller);
|
66
57
|
|
67
|
-
this.data.types
|
58
|
+
this.data.types = text;
|
68
59
|
this.data.methods = methods;
|
69
60
|
}
|
70
61
|
}
|
@@ -6,15 +6,20 @@ export default class RuntimeContext {
|
|
6
6
|
|
7
7
|
async start(): Promise<void> {
|
8
8
|
const controller = this.controller;
|
9
|
-
|
9
|
+
|
10
|
+
if (!(controller instanceof AbstractController)) throw new Error('the controller needs to extend AbstractController');
|
11
|
+
const data:any = this.data;
|
12
|
+
|
10
13
|
const connector = new Connector({
|
11
|
-
id:
|
12
|
-
version:
|
13
|
-
name: `${
|
14
|
+
id: data.id,
|
15
|
+
version: data.version,
|
16
|
+
name: `${data.id}/${data.version}`,
|
14
17
|
});
|
15
18
|
|
19
|
+
const configuration = connector.configure();
|
20
|
+
|
16
21
|
const resolvers: any = {};
|
17
|
-
const methods: string[] = [...
|
22
|
+
const methods: string[] = [...data.methods, '__endpoint', '__configQuery', '__default'];
|
18
23
|
|
19
24
|
methods.forEach((method) => {
|
20
25
|
resolvers[method] = async (args) => {
|
@@ -24,14 +29,15 @@ export default class RuntimeContext {
|
|
24
29
|
return controller[method](args);
|
25
30
|
};
|
26
31
|
});
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
.
|
33
|
-
|
34
|
-
|
32
|
+
|
33
|
+
configuration.types(data.types).resolvers(resolvers);
|
34
|
+
|
35
|
+
if (data.options?.endpoint)
|
36
|
+
{
|
37
|
+
configuration.endpoint((arg) => controller.__endpoint(arg));
|
38
|
+
}
|
39
|
+
|
40
|
+
configuration.main(async ({newTask, updateTask, config, oauth, getClient}) => {
|
35
41
|
try {
|
36
42
|
await controller._doStop();
|
37
43
|
await controller._doStart(config, oauth, newTask, updateTask, getClient);
|
package/src/controller/index.mts
CHANGED