@aloma.io/integration-sdk 3.3.16 → 3.3.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.
@@ -5,6 +5,7 @@ export declare class Builder {
5
5
  options(arg: any): Builder;
6
6
  auth(arg: any): Builder;
7
7
  build(): Promise<RuntimeContext>;
8
+ private checkLogo;
8
9
  private parsePackageJson;
9
10
  private discoverTypes;
10
11
  }
@@ -28,10 +28,25 @@ export class Builder {
28
28
  async build() {
29
29
  await this.parsePackageJson();
30
30
  await this.discoverTypes();
31
+ await this.checkLogo();
31
32
  // @ts-ignore
32
33
  const Controller = (await import(__dirname + "/../../../../../build/controller/index.mjs")).default;
33
34
  return new RuntimeContext(new Controller(), this.data);
34
35
  }
36
+ async checkLogo() {
37
+ const data = this.data;
38
+ const root = __dirname + "/../../../../../";
39
+ const logo = ['logo.png'].find((name) => {
40
+ try {
41
+ fs.readFileSync(`${root}/${name}`);
42
+ return `${root}/${name}`;
43
+ }
44
+ catch (e) {
45
+ // blank
46
+ }
47
+ });
48
+ data.logo = logo;
49
+ }
35
50
  async parsePackageJson() {
36
51
  const data = this.data;
37
52
  const packageJson = JSON.parse(fs.readFileSync(__dirname + "/../../../../../package.json", {
@@ -16,6 +16,7 @@ export default class RuntimeContext {
16
16
  id: data.id,
17
17
  version: data.version,
18
18
  name: `${data.id}/${data.version}`,
19
+ icon: data.icon
19
20
  });
20
21
  const configuration = connector.configure().config(data.config || {});
21
22
  const resolvers = {};
@@ -30,31 +30,32 @@ const transform = (meta) => {
30
30
  if (example) {
31
31
  const parts = example.split(/```/);
32
32
  const backticks = '```';
33
- eg = `@example ${parts[0]}\n${backticks}${parts[1]}${backticks}`;
33
+ eg = `@example ${parts[0] || 'usage'}\n${backticks}${parts[1]}${backticks}`;
34
34
  }
35
35
  const paramDocs = docs
36
- .filter((what) => what.kind === "param")
37
- .map((what) => {
38
- return ` * @param {${what.value.type}} ${what.value.name} - ${what.value.description || ""}`;
39
- })
40
- .join("\n") || " *";
36
+ .filter((what) => what.kind === "param");
41
37
  const params = sig
42
38
  .getParameters()
39
+ .filter((param) => param.isNamed())
43
40
  .map((param) => {
44
41
  const serialized = param.serialize();
45
- switch (!!param.isNamed()) {
46
- case true:
47
- const tmp = param
48
- .getNamedElements()
49
- .map((p) => {
50
- const defaultVal = p.default != null ? " = " + p.default : "";
51
- return `${p.name}${defaultVal}`;
52
- })
53
- .join("; ");
54
- return `{${tmp}}: ${serialized.type.text}`;
55
- case false:
56
- return `${serialized.name}: ${serialized.type.text}`;
57
- }
42
+ const prefix = param
43
+ .getNamedElements()
44
+ .map((p) => {
45
+ const defaultVal = p.getDefault() != null ? " = " + p.getDefault() : "";
46
+ return `${p.getName()}${defaultVal}`;
47
+ })
48
+ .join("; ");
49
+ const suffix = serialized
50
+ .type
51
+ .properties
52
+ .map((p) => {
53
+ const comment = paramDocs.find((what) => what.value.name === p.name);
54
+ const desc = (comment?.value.description || '').replace(/\\@/gi, '@');
55
+ return `\n/**\n${desc}\n */\n ${p.name}: ${p.type.text}`;
56
+ })
57
+ .join("; ");
58
+ return `{${prefix}}: {${suffix}}`;
58
59
  })
59
60
  .join(", ");
60
61
  const retVal = sig
@@ -65,8 +66,6 @@ const transform = (meta) => {
65
66
  /**
66
67
  * ${desc || ""}
67
68
  *
68
- ${paramDocs}
69
- *
70
69
  * ${eg || ''}
71
70
  **/
72
71
  declare function ${member.getName()}(${params}): ${retVal};
@@ -79,5 +78,5 @@ declare function ${member.getName()}(${params}): ${retVal};
79
78
  };
80
79
  export default async (path) => {
81
80
  const parsed = await parseFromFiles([path]);
82
- return transform(parsed?.result || []);
81
+ return transform(parsed.project?.getModules() || []);
83
82
  };
package/build/cli.mjs CHANGED
@@ -37,7 +37,8 @@ const extract = ({ target, name, connectorId }) => {
37
37
  fs.writeFileSync(`${target}/.gitignore`, `.DS_Store
38
38
  node_modules
39
39
  build
40
- .env`);
40
+ .env
41
+ yarn-error.log`);
41
42
  };
42
43
  const generateKeys = async ({ target }) => {
43
44
  const jwe = new JWE({});
@@ -1,12 +1,14 @@
1
1
  export class Connector {
2
- constructor({ version, id, name }: {
2
+ constructor({ version, id, name, icon }: {
3
3
  version: any;
4
4
  id: any;
5
5
  name: any;
6
+ icon: any;
6
7
  });
7
8
  id: any;
8
9
  version: any;
9
10
  name: any;
11
+ icon: any;
10
12
  configure(): Dispatcher;
11
13
  dispatcher: Dispatcher | undefined;
12
14
  run(): Promise<void>;
@@ -184,10 +184,11 @@ class OAuth {
184
184
  }
185
185
  }
186
186
  class Connector {
187
- constructor({ version, id, name }) {
187
+ constructor({ version, id, name, icon }) {
188
188
  this.id = id;
189
189
  this.version = version;
190
190
  this.name = name;
191
+ this.icon = icon;
191
192
  }
192
193
  configure() {
193
194
  return (this.dispatcher = new Dispatcher());
@@ -229,6 +230,7 @@ class Connector {
229
230
  publicKey: process.env.PUBLIC_KEY,
230
231
  introspect,
231
232
  configSchema,
233
+ icon
232
234
  });
233
235
  if (Object.keys(configSchema().fields).length) {
234
236
  try {
@@ -1,5 +1,5 @@
1
1
  export class Config {
2
- constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, }: {
2
+ constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, icon }: {
3
3
  registrationToken: any;
4
4
  version: any;
5
5
  name: any;
@@ -10,6 +10,7 @@ export class Config {
10
10
  publicKey: any;
11
11
  introspect: any;
12
12
  configSchema: any;
13
+ icon: any;
13
14
  });
14
15
  _token: any;
15
16
  _registrationToken: any;
@@ -24,6 +25,7 @@ export class Config {
24
25
  _jwe: JWE;
25
26
  _introspect: any;
26
27
  _configSchema: any;
28
+ _icon: any;
27
29
  validateKeys(algorithm: any): Promise<JWE>;
28
30
  data(what: any): {};
29
31
  introspect(): any;
@@ -36,6 +38,7 @@ export class Config {
36
38
  wsUrl(): any;
37
39
  registrationToken(): any;
38
40
  token(): any;
41
+ icon(): any;
39
42
  setToken(what: any): void;
40
43
  }
41
44
  import JWE from "../util/jwe/index.mjs";
@@ -1,7 +1,7 @@
1
1
  import C from "./connection/constants.mjs";
2
2
  import JWE from "../util/jwe/index.mjs";
3
3
  class Config {
4
- constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, }) {
4
+ constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, icon }) {
5
5
  this._token = null;
6
6
  this._registrationToken = registrationToken;
7
7
  this._version = version;
@@ -15,6 +15,7 @@ class Config {
15
15
  this._jwe = new JWE({});
16
16
  this._introspect = introspect;
17
17
  this._configSchema = configSchema;
18
+ this._icon = icon;
18
19
  if (!registrationToken)
19
20
  throw new Error("empty registration token (set env.REGISTRATION_TOKEN)");
20
21
  if (!endpoint)
@@ -70,6 +71,9 @@ class Config {
70
71
  token() {
71
72
  return this._token;
72
73
  }
74
+ icon() {
75
+ return this._icon;
76
+ }
73
77
  setToken(what) {
74
78
  this._token = what;
75
79
  }
@@ -9,6 +9,7 @@ class Registration {
9
9
  const config = this.config;
10
10
  const configSchema = config.configSchema();
11
11
  const intro = await config.introspect();
12
+ const icon = config.icon();
12
13
  const response = await fetch(config.url() + "register", C.augmentRegistration({
13
14
  method: "POST",
14
15
  body: JSON.stringify({
@@ -18,6 +19,7 @@ class Registration {
18
19
  id: config.id(),
19
20
  publicKey: config.publicKey(),
20
21
  schema: { configSchema, introspect: intro },
22
+ icon
21
23
  }),
22
24
  headers: { "Content-Type": "application/json" },
23
25
  }, config));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloma.io/integration-sdk",
3
- "version": "3.3.16",
3
+ "version": "3.3.18",
4
4
  "description": "",
5
5
  "author": "aloma.io",
6
6
  "license": "Apache-2.0",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@paralleldrive/cuid2": "^2",
29
- "@ts-ast-parser/core": "^0.4.0",
29
+ "@ts-ast-parser/core": "^0.5",
30
30
  "@types/node": "^16",
31
31
  "commander": "^11",
32
32
  "dotenv": "*",
@@ -37,7 +37,8 @@ export class Builder {
37
37
  async build(): Promise<RuntimeContext> {
38
38
  await this.parsePackageJson();
39
39
  await this.discoverTypes();
40
-
40
+ await this.checkLogo();
41
+
41
42
  // @ts-ignore
42
43
  const Controller = (
43
44
  await import(__dirname + "/../../../../../build/controller/index.mjs")
@@ -45,6 +46,24 @@ export class Builder {
45
46
 
46
47
  return new RuntimeContext(new Controller(), this.data);
47
48
  }
49
+
50
+ private async checkLogo() {
51
+ const data = this.data;
52
+ const root = __dirname + "/../../../../../"
53
+
54
+ const logo = ['logo.png'].find((name) =>
55
+ {
56
+ try
57
+ {
58
+ fs.readFileSync(`${root}/${name}`);
59
+ return `${root}/${name}`;
60
+ } catch(e) {
61
+ // blank
62
+ }
63
+ })
64
+
65
+ data.logo = logo;
66
+ }
48
67
 
49
68
  private async parsePackageJson() {
50
69
  const data = this.data;
@@ -18,6 +18,7 @@ export default class RuntimeContext {
18
18
  id: data.id,
19
19
  version: data.version,
20
20
  name: `${data.id}/${data.version}`,
21
+ icon: data.icon
21
22
  });
22
23
 
23
24
  const configuration = connector.configure().config(data.config || {});
@@ -40,41 +40,44 @@ const transform = (meta: any) => {
40
40
  {
41
41
  const parts = example.split(/```/);
42
42
  const backticks = '```';
43
- eg = `@example ${parts[0]}\n${backticks}${parts[1]}${backticks}`;
43
+ eg = `@example ${parts[0] || 'usage'}\n${backticks}${parts[1]}${backticks}`;
44
44
  }
45
45
 
46
46
  const paramDocs =
47
47
  docs
48
48
  .filter((what: any) => what.kind === "param")
49
- .map((what: any) => {
50
- return ` * @param {${what.value.type}} ${what.value.name} - ${
51
- what.value.description || ""
52
- }`;
53
- })
54
- .join("\n") || " *";
55
49
 
56
50
  const params = sig
57
51
  .getParameters()
52
+ .filter((param) => param.isNamed())
58
53
  .map((param: any) => {
59
54
  const serialized = param.serialize();
60
-
61
- switch (!!param.isNamed()) {
62
- case true:
63
- const tmp = param
64
- .getNamedElements()
65
- .map((p) => {
66
- const defaultVal =
67
- p.default != null ? " = " + p.default : "";
68
55
 
69
- return `${p.name}${defaultVal}`;
70
- })
71
- .join("; ");
72
- return `{${tmp}}: ${serialized.type.text}`;
73
- case false:
74
- return `${serialized.name}: ${serialized.type.text}`;
75
- }
56
+ const prefix = param
57
+ .getNamedElements()
58
+ .map((p) => {
59
+ const defaultVal =
60
+ p.getDefault() != null ? " = " + p.getDefault() : "";
61
+
62
+ return `${p.getName()}${defaultVal}`;
63
+ })
64
+ .join("; ");
65
+
66
+ const suffix = serialized
67
+ .type
68
+ .properties
69
+ .map((p) => {
70
+ const comment = paramDocs.find((what) => what.value.name === p.name);
71
+ const desc = (comment?.value.description || '').replace(/\\@/gi, '@');
72
+
73
+ return `\n/**\n${desc}\n */\n ${p.name}: ${p.type.text}`;
74
+ })
75
+ .join("; ");
76
+
77
+ return `{${prefix}}: {${suffix}}`;
76
78
  })
77
79
  .join(", ");
80
+
78
81
  const retVal = sig
79
82
  .serialize()
80
83
  .return.type.text.replace(/^Promise</, "")
@@ -84,8 +87,6 @@ const transform = (meta: any) => {
84
87
  /**
85
88
  * ${desc || ""}
86
89
  *
87
- ${paramDocs}
88
- *
89
90
  * ${eg || ''}
90
91
  **/
91
92
  declare function ${member.getName()}(${params}): ${retVal};
@@ -100,5 +101,5 @@ declare function ${member.getName()}(${params}): ${retVal};
100
101
 
101
102
  export default async (path: string) => {
102
103
  const parsed = await parseFromFiles([path]);
103
- return transform(parsed?.result || []);
104
+ return transform(parsed.project?.getModules() || []);
104
105
  };
package/src/cli.mts CHANGED
@@ -52,7 +52,8 @@ const extract = ({ target, name, connectorId }) => {
52
52
  `.DS_Store
53
53
  node_modules
54
54
  build
55
- .env`,
55
+ .env
56
+ yarn-error.log`,
56
57
  );
57
58
  };
58
59
 
@@ -235,10 +235,11 @@ class OAuth {
235
235
  }
236
236
 
237
237
  class Connector {
238
- constructor({ version, id, name }) {
238
+ constructor({ version, id, name, icon }) {
239
239
  this.id = id;
240
240
  this.version = version;
241
241
  this.name = name;
242
+ this.icon = icon;
242
243
  }
243
244
 
244
245
  configure() {
@@ -293,6 +294,7 @@ class Connector {
293
294
  publicKey: process.env.PUBLIC_KEY,
294
295
  introspect,
295
296
  configSchema,
297
+ icon
296
298
  });
297
299
 
298
300
  if (Object.keys(configSchema().fields).length) {
@@ -13,6 +13,7 @@ class Config {
13
13
  publicKey,
14
14
  introspect,
15
15
  configSchema,
16
+ icon
16
17
  }) {
17
18
  this._token = null;
18
19
  this._registrationToken = registrationToken;
@@ -27,6 +28,7 @@ class Config {
27
28
  this._jwe = new JWE({});
28
29
  this._introspect = introspect;
29
30
  this._configSchema = configSchema;
31
+ this._icon = icon;
30
32
 
31
33
  if (!registrationToken)
32
34
  throw new Error("empty registration token (set env.REGISTRATION_TOKEN)");
@@ -98,6 +100,10 @@ class Config {
98
100
  token() {
99
101
  return this._token;
100
102
  }
103
+
104
+ icon() {
105
+ return this._icon;
106
+ }
101
107
 
102
108
  setToken(what) {
103
109
  this._token = what;
@@ -11,6 +11,7 @@ class Registration {
11
11
  const config = this.config;
12
12
  const configSchema = config.configSchema();
13
13
  const intro = await config.introspect();
14
+ const icon = config.icon();
14
15
 
15
16
  const response = await fetch(
16
17
  config.url() + "register",
@@ -24,6 +25,7 @@ class Registration {
24
25
  id: config.id(),
25
26
  publicKey: config.publicKey(),
26
27
  schema: { configSchema, introspect: intro },
28
+ icon
27
29
  }),
28
30
  headers: { "Content-Type": "application/json" },
29
31
  },