@aloma.io/integration-sdk 3.8.11 → 3.8.12
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/.prettierrc.cjs +8 -0
- package/build/builder/index.d.mts +7 -11
- package/build/builder/index.mjs +14 -15
- package/build/builder/runtime-context.d.mts +1 -1
- package/build/builder/runtime-context.mjs +11 -16
- package/build/cli.mjs +38 -38
- package/build/controller/index.d.mts +58 -2
- package/build/controller/index.mjs +68 -11
- package/build/index.d.mts +2 -2
- package/build/index.mjs +2 -2
- package/build/internal/connector/config.d.mts +2 -2
- package/build/internal/connector/config.mjs +10 -10
- package/build/internal/connector/index.d.mts +2 -2
- package/build/internal/connector/index.mjs +4 -4
- package/build/internal/connector/metrics.mjs +6 -6
- package/build/internal/connector/server/index.d.mts +3 -3
- package/build/internal/connector/server/index.mjs +7 -7
- package/build/internal/connector/server/on-connect/decrypt-config.mjs +3 -3
- package/build/internal/connector/server/on-connect/finish-oauth.d.mts +3 -3
- package/build/internal/connector/server/on-connect/finish-oauth.mjs +17 -23
- package/build/internal/connector/server/on-connect/index.d.mts +2 -2
- package/build/internal/connector/server/on-connect/index.mjs +13 -13
- package/build/internal/connector/server/on-connect/make-oauth.d.mts +3 -3
- package/build/internal/connector/server/on-connect/make-oauth.mjs +17 -25
- package/build/internal/connector/server/on-connect/start-oauth.mjs +6 -13
- package/build/internal/connector/server/on-message.mjs +1 -1
- package/build/internal/dispatcher/index.mjs +34 -45
- package/build/internal/fetcher/fetcher.d.mts +1 -1
- package/build/internal/fetcher/fetcher.mjs +11 -15
- package/build/internal/fetcher/oauth-fetcher.d.mts +1 -1
- package/build/internal/fetcher/oauth-fetcher.mjs +7 -7
- package/build/internal/index.d.mts +1 -1
- package/build/internal/index.mjs +1 -1
- package/build/internal/util/index.mjs +5 -5
- package/build/internal/util/jwe/cli.mjs +3 -3
- package/build/internal/util/jwe/index.d.mts +1 -1
- package/build/internal/util/jwe/index.mjs +10 -10
- package/build/internal/websocket/config.d.mts +1 -1
- package/build/internal/websocket/config.mjs +7 -7
- package/build/internal/websocket/connection/constants.mjs +3 -3
- package/build/internal/websocket/connection/index.mjs +8 -8
- package/build/internal/websocket/connection/registration.mjs +6 -6
- package/build/internal/websocket/index.d.mts +2 -2
- package/build/internal/websocket/index.mjs +3 -3
- package/build/internal/websocket/transport/durable.mjs +6 -6
- package/build/internal/websocket/transport/index.d.mts +2 -2
- package/build/internal/websocket/transport/index.mjs +19 -19
- package/build/internal/websocket/transport/packet.mjs +1 -1
- package/build/internal/websocket/transport/processor.mjs +5 -5
- package/build/transform/index.mjs +26 -26
- package/package.json +1 -1
- package/src/builder/index.mts +66 -66
- package/src/builder/runtime-context.mts +17 -43
- package/src/cli.mts +48 -53
- package/src/controller/index.mts +72 -12
- package/src/index.mts +2 -2
- package/src/internal/connector/config.mts +11 -19
- package/src/internal/connector/index.mts +8 -9
- package/src/internal/connector/metrics.mts +7 -7
- package/src/internal/connector/server/index.mts +10 -10
- package/src/internal/connector/server/on-connect/decrypt-config.mts +4 -4
- package/src/internal/connector/server/on-connect/finish-oauth.mts +22 -35
- package/src/internal/connector/server/on-connect/index.mts +27 -27
- package/src/internal/connector/server/on-connect/make-oauth.mts +22 -33
- package/src/internal/connector/server/on-connect/start-oauth.mts +7 -16
- package/src/internal/connector/server/on-message.mts +1 -1
- package/src/internal/dispatcher/index.mts +49 -70
- package/src/internal/fetcher/fetcher.mts +44 -49
- package/src/internal/fetcher/oauth-fetcher.mts +12 -13
- package/src/internal/index.mts +2 -2
- package/src/internal/util/index.mts +8 -11
- package/src/internal/util/jwe/cli.mts +3 -3
- package/src/internal/util/jwe/index.mts +17 -21
- package/src/internal/websocket/config.mjs +8 -12
- package/src/internal/websocket/connection/constants.mjs +3 -3
- package/src/internal/websocket/connection/index.mjs +14 -14
- package/src/internal/websocket/connection/registration.mjs +10 -10
- package/src/internal/websocket/index.mjs +6 -6
- package/src/internal/websocket/transport/durable.mjs +9 -9
- package/src/internal/websocket/transport/index.mjs +28 -32
- package/src/internal/websocket/transport/packet.mjs +4 -4
- package/src/internal/websocket/transport/processor.mjs +9 -12
- package/src/transform/index.mts +28 -41
@@ -1,19 +1,19 @@
|
|
1
|
-
import { parseFromFiles } from
|
1
|
+
import { parseFromFiles } from '@ts-ast-parser/core';
|
2
2
|
const transform = (meta) => {
|
3
3
|
if (!meta?.length)
|
4
|
-
throw new Error(
|
4
|
+
throw new Error('metadata is empty');
|
5
5
|
meta = meta[0];
|
6
6
|
if (meta.getDeclarations()?.length !== 1) {
|
7
|
-
throw new Error(
|
7
|
+
throw new Error('connector file needs to export default class');
|
8
8
|
}
|
9
9
|
const methods = {};
|
10
10
|
const decl = meta.getDeclarations()[0];
|
11
11
|
const members = decl.getMethods().filter((member) => {
|
12
12
|
return !(member.isStatic() ||
|
13
13
|
member.isInherited() ||
|
14
|
-
member.getKind() !==
|
15
|
-
member.getModifier() !==
|
16
|
-
member.getName().startsWith(
|
14
|
+
member.getKind() !== 'Method' ||
|
15
|
+
member.getModifier() !== 'public' ||
|
16
|
+
member.getName().startsWith('_'));
|
17
17
|
});
|
18
18
|
const text = members
|
19
19
|
.map((member) => {
|
@@ -22,17 +22,17 @@ 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 ===
|
26
|
-
const example = docs.find((what) => what.kind ===
|
27
|
-
const ns = docs.find((what) => what.kind ===
|
28
|
-
let space = ns ? `@namespace ${ns}` :
|
25
|
+
const desc = docs.find((what) => what.kind === 'description')?.value;
|
26
|
+
const example = docs.find((what) => what.kind === 'example')?.value;
|
27
|
+
const ns = docs.find((what) => what.kind === 'namespace')?.value;
|
28
|
+
let space = ns ? `@namespace ${ns}` : '';
|
29
29
|
let eg;
|
30
30
|
if (example) {
|
31
31
|
const parts = example.split(/```/);
|
32
|
-
const backticks =
|
33
|
-
eg = `@example ${parts[0] ||
|
32
|
+
const backticks = '```';
|
33
|
+
eg = `@example ${parts[0] || 'usage'}\n${backticks}${parts[1]}${backticks}`;
|
34
34
|
}
|
35
|
-
const paramDocs = docs.filter((what) => what.kind ===
|
35
|
+
const paramDocs = docs.filter((what) => what.kind === 'param');
|
36
36
|
const params = sig
|
37
37
|
.getParameters()
|
38
38
|
.filter((param) => param.isNamed())
|
@@ -41,42 +41,42 @@ const transform = (meta) => {
|
|
41
41
|
const prefix = param
|
42
42
|
.getNamedElements()
|
43
43
|
.map((p) => {
|
44
|
-
const defaultVal = p.getDefault() != null ?
|
44
|
+
const defaultVal = p.getDefault() != null ? ' = ' + p.getDefault() : '';
|
45
45
|
return `${p.getName()}${defaultVal}`;
|
46
46
|
})
|
47
|
-
.join(
|
47
|
+
.join('; ');
|
48
48
|
const suffix = serialized.type.properties
|
49
49
|
.map((p) => {
|
50
50
|
const comment = paramDocs.find((what) => what.value.name === p.name);
|
51
|
-
const desc = (comment?.value.description ||
|
51
|
+
const desc = (comment?.value.description || '').replace(/\\@/gi, '@');
|
52
52
|
return `\n/**\n${desc}\n */\n ${p.name}: ${p.type.text}`;
|
53
53
|
})
|
54
|
-
.join(
|
54
|
+
.join('; ');
|
55
55
|
return `{${prefix}}: {${suffix}}`;
|
56
56
|
})
|
57
|
-
.join(
|
57
|
+
.join(', ');
|
58
58
|
const retVal = sig
|
59
59
|
.serialize()
|
60
|
-
.return.type.text.replace(/^Promise</,
|
61
|
-
.replace(/>$/,
|
60
|
+
.return.type.text.replace(/^Promise</, '')
|
61
|
+
.replace(/>$/, '');
|
62
62
|
return `
|
63
63
|
/**
|
64
|
-
* ${desc ||
|
64
|
+
* ${desc || ''}
|
65
65
|
*
|
66
|
-
* ${space ||
|
67
|
-
* ${eg ||
|
66
|
+
* ${space || ''}
|
67
|
+
* ${eg || ''}
|
68
68
|
**/
|
69
69
|
declare function ${member.getName()}(${params}): ${retVal};
|
70
70
|
`;
|
71
71
|
})
|
72
|
-
.join(
|
72
|
+
.join('\n');
|
73
73
|
})
|
74
|
-
.join(
|
74
|
+
.join('');
|
75
75
|
return { text, methods: Object.keys(methods) };
|
76
76
|
};
|
77
77
|
export default async (path) => {
|
78
78
|
const parsed = await parseFromFiles([path]);
|
79
79
|
if (parsed.errors?.length)
|
80
|
-
throw new Error(path +
|
80
|
+
throw new Error(path + ' ' + JSON.stringify(parsed.errors));
|
81
81
|
return transform(parsed.project?.getModules() || []);
|
82
82
|
};
|
package/package.json
CHANGED
package/src/builder/index.mts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import
|
2
|
-
import fs from
|
3
|
-
import path from
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import RuntimeContext from
|
1
|
+
import 'dotenv/config';
|
2
|
+
import fs from 'node:fs';
|
3
|
+
import path from 'node:path';
|
4
|
+
import {fileURLToPath} from 'node:url';
|
5
|
+
import {notEmpty} from '../internal/util/index.mjs';
|
6
|
+
import RuntimeContext from './runtime-context.mjs';
|
7
7
|
|
8
|
-
const DIR_OFFSET =
|
8
|
+
const DIR_OFFSET = '/../../../../../';
|
9
9
|
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
11
11
|
|
@@ -14,50 +14,51 @@ export const TARGET_DIR = `${__dirname}${DIR_OFFSET}`;
|
|
14
14
|
/**
|
15
15
|
* a configuration field
|
16
16
|
*/
|
17
|
-
export type ConfigField =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}
|
17
|
+
export type ConfigField =
|
18
|
+
| {
|
19
|
+
/**
|
20
|
+
* the name of the field
|
21
|
+
*/
|
22
|
+
name: string;
|
23
|
+
/**
|
24
|
+
* a description about the field
|
25
|
+
*
|
26
|
+
* supports markdown
|
27
|
+
*/
|
28
|
+
description?: string;
|
29
|
+
/**
|
30
|
+
* a placeholder for the field
|
31
|
+
*/
|
32
|
+
placeholder?: string;
|
33
|
+
/**
|
34
|
+
* the type of the field
|
35
|
+
*/
|
36
|
+
type: /**
|
37
|
+
* a multiline text field
|
38
|
+
*/
|
39
|
+
| 'multiline'
|
40
|
+
/**
|
41
|
+
* a single line text field
|
42
|
+
*/
|
43
|
+
| 'line'
|
44
|
+
/**
|
45
|
+
* a number field
|
46
|
+
*/
|
47
|
+
| 'number'
|
48
|
+
/**
|
49
|
+
* a boolean text field
|
50
|
+
*/
|
51
|
+
| 'boolean';
|
52
|
+
/**
|
53
|
+
* if true, the field is optional, otherwise a value is required
|
54
|
+
*/
|
55
|
+
optional?: boolean;
|
56
|
+
/**
|
57
|
+
* if true, the field will NOT be encrypted
|
58
|
+
*/
|
59
|
+
plain?: boolean;
|
60
|
+
}
|
61
|
+
| undefined;
|
61
62
|
|
62
63
|
/**
|
63
64
|
* connector configuration
|
@@ -83,7 +84,7 @@ declare type Config = {
|
|
83
84
|
scope?: ConfigField;
|
84
85
|
clientId?: ConfigField;
|
85
86
|
clientSecret?: ConfigField;
|
86
|
-
[key: string]: ConfigField
|
87
|
+
[key: string]: ConfigField;
|
87
88
|
};
|
88
89
|
};
|
89
90
|
|
@@ -98,11 +99,11 @@ declare type Options = {
|
|
98
99
|
/**
|
99
100
|
* if the endpoint is enabled
|
100
101
|
*/
|
101
|
-
enabled: boolean
|
102
|
+
enabled: boolean;
|
102
103
|
/**
|
103
104
|
* if true, the endpoint is required to operate the connector and not visible in the ui
|
104
105
|
*/
|
105
|
-
required?: boolean
|
106
|
+
required?: boolean;
|
106
107
|
};
|
107
108
|
};
|
108
109
|
|
@@ -145,7 +146,7 @@ declare type OAuth = {
|
|
145
146
|
/**
|
146
147
|
* milliseconds to automatically refresh the token, if a refresh_token is available
|
147
148
|
*
|
148
|
-
|
149
|
+
* @default 4 * 60 * 60 * 1000 // 4 hours
|
149
150
|
*/
|
150
151
|
tokenRefreshPeriod?: number;
|
151
152
|
|
@@ -161,8 +162,8 @@ declare type OAuth = {
|
|
161
162
|
/**
|
162
163
|
* oauth2 grant type
|
163
164
|
*/
|
164
|
-
grant_type?: string
|
165
|
-
}
|
165
|
+
grant_type?: string;
|
166
|
+
};
|
166
167
|
};
|
167
168
|
|
168
169
|
/**
|
@@ -170,7 +171,7 @@ declare type OAuth = {
|
|
170
171
|
*/
|
171
172
|
export class Builder {
|
172
173
|
private data: any = {
|
173
|
-
controller:
|
174
|
+
controller: './build/.controller.json',
|
174
175
|
};
|
175
176
|
|
176
177
|
/**
|
@@ -214,8 +215,7 @@ export class Builder {
|
|
214
215
|
await this.checkIcon();
|
215
216
|
|
216
217
|
// @ts-ignore
|
217
|
-
const Controller = (await import(TARGET_DIR +
|
218
|
-
.default;
|
218
|
+
const Controller = (await import(TARGET_DIR + 'build/controller/index.mjs')).default;
|
219
219
|
|
220
220
|
return new RuntimeContext(new Controller(), this.data);
|
221
221
|
}
|
@@ -223,21 +223,21 @@ export class Builder {
|
|
223
223
|
private async checkIcon() {
|
224
224
|
const data = this.data;
|
225
225
|
|
226
|
-
data.icon = TARGET_DIR +
|
226
|
+
data.icon = TARGET_DIR + 'build/logo.png';
|
227
227
|
}
|
228
228
|
|
229
229
|
private async loadDescriptor() {
|
230
|
-
notEmpty(this.data.controller,
|
230
|
+
notEmpty(this.data.controller, 'controller');
|
231
231
|
|
232
232
|
const content = fs.readFileSync(this.data.controller, {
|
233
|
-
encoding:
|
233
|
+
encoding: 'utf-8',
|
234
234
|
});
|
235
|
-
const {
|
235
|
+
const {text, methods, connectorId, version} = JSON.parse(content);
|
236
236
|
|
237
237
|
this.data.types = text;
|
238
238
|
this.data.methods = methods;
|
239
239
|
|
240
|
-
notEmpty((this.data.id = connectorId),
|
241
|
-
notEmpty((this.data.version = version),
|
240
|
+
notEmpty((this.data.id = connectorId), 'id');
|
241
|
+
notEmpty((this.data.version = version), 'version');
|
242
242
|
}
|
243
243
|
}
|
@@ -1,18 +1,18 @@
|
|
1
|
-
import fs from
|
2
|
-
import { AbstractController } from
|
3
|
-
import { Connector } from
|
1
|
+
import fs from 'node:fs';
|
2
|
+
import { AbstractController } from '../controller/index.mjs';
|
3
|
+
import { Connector } from '../internal/index.mjs';
|
4
4
|
|
5
5
|
export default class RuntimeContext {
|
6
6
|
constructor(
|
7
7
|
private controller: AbstractController,
|
8
|
-
private data: any
|
8
|
+
private data: any
|
9
9
|
) {}
|
10
10
|
|
11
11
|
async start(): Promise<void> {
|
12
12
|
const controller = this.controller;
|
13
13
|
|
14
14
|
if (!(controller instanceof AbstractController)) {
|
15
|
-
throw new Error(
|
15
|
+
throw new Error('the controller needs to extend AbstractController');
|
16
16
|
}
|
17
17
|
|
18
18
|
const data: any = this.data;
|
@@ -21,7 +21,7 @@ export default class RuntimeContext {
|
|
21
21
|
|
22
22
|
try {
|
23
23
|
if (data.icon) {
|
24
|
-
icon = fs.readFileSync(data.icon).toString(
|
24
|
+
icon = fs.readFileSync(data.icon).toString('base64');
|
25
25
|
}
|
26
26
|
} catch (e) {
|
27
27
|
// blank
|
@@ -37,13 +37,7 @@ export default class RuntimeContext {
|
|
37
37
|
const configuration = connector.configure().config(data.config || {});
|
38
38
|
|
39
39
|
const resolvers: any = {};
|
40
|
-
const methods: string[] = [
|
41
|
-
...data.methods,
|
42
|
-
"__autocomplete",
|
43
|
-
"__endpoint",
|
44
|
-
"__configQuery",
|
45
|
-
"__default",
|
46
|
-
];
|
40
|
+
const methods: string[] = [...data.methods, '__autocomplete', '__endpoint', '__configQuery', '__default'];
|
47
41
|
|
48
42
|
methods.forEach((method) => {
|
49
43
|
resolvers[method] = async (args) => {
|
@@ -56,10 +50,7 @@ export default class RuntimeContext {
|
|
56
50
|
configuration.types(data.types).resolvers(resolvers);
|
57
51
|
|
58
52
|
if (data.options?.endpoint?.enabled) {
|
59
|
-
configuration.endpoint(
|
60
|
-
(arg) => controller.__endpoint(arg),
|
61
|
-
data.options?.endpoint?.required,
|
62
|
-
);
|
53
|
+
configuration.endpoint((arg) => controller.__endpoint(arg), data.options?.endpoint?.required);
|
63
54
|
}
|
64
55
|
|
65
56
|
if (data.auth?.oauth) {
|
@@ -69,37 +60,20 @@ export default class RuntimeContext {
|
|
69
60
|
let healthInterval;
|
70
61
|
|
71
62
|
configuration.main(
|
72
|
-
async ({
|
73
|
-
newTask,
|
74
|
-
updateTask,
|
75
|
-
config,
|
76
|
-
oauth,
|
77
|
-
getClient,
|
78
|
-
getBlob,
|
79
|
-
getBlobContent,
|
80
|
-
createBlob,
|
81
|
-
healthCheck,
|
82
|
-
}) => {
|
63
|
+
async ({newTask, updateTask, config, oauth, getClient, getBlob, getBlobContent, createBlob, healthCheck}) => {
|
83
64
|
try {
|
84
65
|
clearInterval(healthInterval);
|
85
66
|
|
86
67
|
await controller._doStop();
|
87
|
-
await controller._doStart(
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
getClient,
|
93
|
-
getBlob,
|
94
|
-
getBlobContent,
|
95
|
-
createBlob,
|
96
|
-
);
|
97
|
-
|
98
|
-
healthInterval = setInterval(() => healthCheck(controller), 30000);
|
68
|
+
await controller._doStart(config, oauth, newTask, updateTask, getClient, getBlob, getBlobContent, createBlob);
|
69
|
+
|
70
|
+
healthInterval = setInterval(() => healthCheck(controller), 30000).unref();
|
71
|
+
|
72
|
+
await healthCheck(controller);
|
99
73
|
} catch (e) {
|
100
74
|
console.log(e);
|
101
75
|
}
|
102
|
-
}
|
76
|
+
}
|
103
77
|
);
|
104
78
|
|
105
79
|
connector.run();
|
@@ -111,7 +85,7 @@ export default class RuntimeContext {
|
|
111
85
|
process.exit(0);
|
112
86
|
};
|
113
87
|
|
114
|
-
process.on(
|
115
|
-
process.on(
|
88
|
+
process.on('SIGTERM', term);
|
89
|
+
process.on('SIGINT', term);
|
116
90
|
}
|
117
91
|
}
|
package/src/cli.mts
CHANGED
@@ -1,50 +1,48 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
import {
|
4
|
-
import ChildProcess from
|
5
|
-
import fs from
|
6
|
-
import path from
|
7
|
-
import {
|
8
|
-
import util from
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import JWE from
|
12
|
-
import parseTypes from
|
3
|
+
import {Command} from 'commander';
|
4
|
+
import ChildProcess from 'node:child_process';
|
5
|
+
import fs from 'node:fs';
|
6
|
+
import path from 'node:path';
|
7
|
+
import {fileURLToPath} from 'node:url';
|
8
|
+
import util from 'node:util';
|
9
|
+
import {TARGET_DIR} from './builder/index.mjs';
|
10
|
+
import {notEmpty} from './internal/util/index.mjs';
|
11
|
+
import JWE from './internal/util/jwe/index.mjs';
|
12
|
+
import parseTypes from './transform/index.mjs';
|
13
13
|
|
14
14
|
const exec = util.promisify(ChildProcess.exec);
|
15
15
|
|
16
16
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
17
17
|
|
18
18
|
const files = [
|
19
|
-
{
|
20
|
-
{
|
21
|
-
{
|
22
|
-
{
|
23
|
-
{
|
24
|
-
{
|
19
|
+
{name: 'index.mts', dir: 'src/controller'},
|
20
|
+
{name: 'index.mts', dir: 'src'},
|
21
|
+
{name: 'package.json', dir: ''},
|
22
|
+
{name: 'Containerfile', dir: ''},
|
23
|
+
{name: 'entrypoint.sh', dir: ''},
|
24
|
+
{name: 'tsconfig.json', dir: ''},
|
25
25
|
];
|
26
26
|
|
27
|
-
const extract = ({
|
27
|
+
const extract = ({target, name, connectorId}) => {
|
28
28
|
const source = `${__dirname}/../template/connector/`;
|
29
29
|
|
30
30
|
if (!fs.existsSync(source)) {
|
31
31
|
throw new Error(`source ${source} does not exist`);
|
32
32
|
}
|
33
33
|
|
34
|
-
files.forEach(({
|
34
|
+
files.forEach(({name, dir}) => {
|
35
35
|
if (dir) {
|
36
|
-
fs.mkdirSync(`${target}/${dir}`, {
|
36
|
+
fs.mkdirSync(`${target}/${dir}`, {recursive: true});
|
37
37
|
}
|
38
38
|
|
39
39
|
const content = fs.readFileSync(`${source}/${dir}/${name}`, {
|
40
|
-
encoding:
|
40
|
+
encoding: 'utf-8',
|
41
41
|
});
|
42
42
|
fs.writeFileSync(`${target}/${dir}/${name}`, content);
|
43
43
|
});
|
44
44
|
|
45
|
-
const content = JSON.parse(
|
46
|
-
fs.readFileSync(`${target}/package.json`, { encoding: "utf-8" }),
|
47
|
-
);
|
45
|
+
const content = JSON.parse(fs.readFileSync(`${target}/package.json`, {encoding: 'utf-8'}));
|
48
46
|
|
49
47
|
content.name = name;
|
50
48
|
content.connectorId = connectorId;
|
@@ -56,11 +54,11 @@ const extract = ({ target, name, connectorId }) => {
|
|
56
54
|
node_modules
|
57
55
|
build
|
58
56
|
.env
|
59
|
-
yarn-error.log
|
57
|
+
yarn-error.log`
|
60
58
|
);
|
61
59
|
};
|
62
60
|
|
63
|
-
const generateKeys = async ({
|
61
|
+
const generateKeys = async ({target}) => {
|
64
62
|
const jwe = new JWE({});
|
65
63
|
await jwe.newPair();
|
66
64
|
|
@@ -78,34 +76,34 @@ PUBLIC_KEY=${pub}
|
|
78
76
|
const program = new Command();
|
79
77
|
|
80
78
|
program
|
81
|
-
.name(
|
82
|
-
.description(
|
83
|
-
.version(
|
79
|
+
.name('npx @aloma.io/integration-sdk')
|
80
|
+
.description('aloma.io integration sdk')
|
81
|
+
.version('0.8.0')
|
84
82
|
.showHelpAfterError();
|
85
83
|
|
86
84
|
program
|
87
|
-
.command(
|
88
|
-
.description(
|
89
|
-
.argument(
|
90
|
-
.requiredOption(
|
85
|
+
.command('create')
|
86
|
+
.description('Create a new connector project')
|
87
|
+
.argument('<name>', 'name of the project')
|
88
|
+
.requiredOption('--connector-id <id>', 'id of the connector')
|
91
89
|
.action(async (name, options) => {
|
92
|
-
name = name.replace(/[\/\.]/gi,
|
93
|
-
if (!name) throw new Error(
|
90
|
+
name = name.replace(/[\/\.]/gi, '');
|
91
|
+
if (!name) throw new Error('name is empty');
|
94
92
|
|
95
93
|
const target = `${process.cwd()}/${name}`;
|
96
94
|
|
97
95
|
fs.mkdirSync(target);
|
98
96
|
|
99
|
-
console.log(
|
100
|
-
extract({
|
97
|
+
console.log('Creating connector ...');
|
98
|
+
extract({...options, target, name});
|
101
99
|
|
102
|
-
console.log(
|
103
|
-
await generateKeys({
|
100
|
+
console.log('Generating keys ...');
|
101
|
+
await generateKeys({target});
|
104
102
|
|
105
|
-
console.log(
|
103
|
+
console.log('Installing dependencies ...');
|
106
104
|
await exec(`cd ${target}; yarn`);
|
107
105
|
|
108
|
-
console.log(
|
106
|
+
console.log('Building ...');
|
109
107
|
await exec(`cd ${target}; yarn build`);
|
110
108
|
|
111
109
|
console.log(`
|
@@ -117,10 +115,10 @@ Success!
|
|
117
115
|
});
|
118
116
|
|
119
117
|
program
|
120
|
-
.command(
|
121
|
-
.description(
|
118
|
+
.command('build')
|
119
|
+
.description('Build the current connector project')
|
122
120
|
.action(async (str, options) => {
|
123
|
-
const {
|
121
|
+
const {stdout, stderr} = await exec(`rm -rf build; mkdir -p build; `);
|
124
122
|
|
125
123
|
try {
|
126
124
|
fs.copyFileSync(`${TARGET_DIR}/logo.png`, `${TARGET_DIR}/build/logo.png`);
|
@@ -130,23 +128,20 @@ program
|
|
130
128
|
|
131
129
|
if (stdout) console.log(stdout);
|
132
130
|
|
133
|
-
new Extractor().extract(
|
134
|
-
"./src/controller/index.mts",
|
135
|
-
"./build/.controller.json",
|
136
|
-
);
|
131
|
+
new Extractor().extract('./src/controller/index.mts', './build/.controller.json');
|
137
132
|
});
|
138
133
|
|
139
134
|
class Extractor {
|
140
135
|
async extract(source, target) {
|
141
|
-
notEmpty(source,
|
136
|
+
notEmpty(source, 'source');
|
142
137
|
|
143
138
|
fs.readFileSync(source);
|
144
|
-
const {
|
139
|
+
const {text, methods} = await parseTypes(source);
|
145
140
|
|
146
141
|
const packageJson = JSON.parse(
|
147
|
-
fs.readFileSync(TARGET_DIR +
|
148
|
-
encoding:
|
149
|
-
})
|
142
|
+
fs.readFileSync(TARGET_DIR + 'package.json', {
|
143
|
+
encoding: 'utf-8',
|
144
|
+
})
|
150
145
|
);
|
151
146
|
|
152
147
|
fs.writeFileSync(
|
@@ -157,7 +152,7 @@ class Extractor {
|
|
157
152
|
connectorId: packageJson.connectorId,
|
158
153
|
version: packageJson.version,
|
159
154
|
}),
|
160
|
-
{
|
155
|
+
{encoding: 'utf-8'}
|
161
156
|
);
|
162
157
|
}
|
163
158
|
}
|