@aloma.io/integration-sdk 3.6.5 → 3.7.0

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.
Files changed (32) hide show
  1. package/build/builder/index.d.mts +1 -1
  2. package/build/builder/index.mjs +13 -16
  3. package/build/builder/runtime-context.mjs +3 -2
  4. package/build/cli.mjs +15 -4
  5. package/build/internal/dispatcher/index.d.mts +11 -17
  6. package/build/internal/dispatcher/index.mjs +12 -1
  7. package/build/internal/fetcher/fetcher.d.mts +15 -0
  8. package/build/internal/fetcher/fetcher.mjs +97 -0
  9. package/build/internal/fetcher/index.d.mts +1 -0
  10. package/build/internal/fetcher/index.mjs +1 -0
  11. package/build/internal/fetcher/oauth-fetcher.d.mts +32 -0
  12. package/build/internal/fetcher/oauth-fetcher.mjs +114 -0
  13. package/build/internal/index.d.mts +8 -7
  14. package/build/internal/index.mjs +14 -241
  15. package/build/internal/util/index.d.mts +5 -0
  16. package/build/internal/util/index.mjs +45 -0
  17. package/build/internal/util/jwe/index.d.mts +5 -8
  18. package/build/internal/util/jwe/index.mjs +3 -0
  19. package/build/transform/index.d.mts +5 -0
  20. package/build/transform/index.mjs +79 -0
  21. package/package.json +1 -1
  22. package/src/builder/index.mts +14 -17
  23. package/src/builder/runtime-context.mts +4 -1
  24. package/src/cli.mts +19 -4
  25. package/src/internal/dispatcher/{index.mjs → index.mts} +14 -2
  26. package/src/internal/fetcher/fetcher.mts +126 -0
  27. package/src/internal/fetcher/oauth-fetcher.mts +147 -0
  28. package/src/internal/{index.mjs → index.mts} +18 -317
  29. package/src/internal/util/index.mts +57 -0
  30. package/src/internal/util/jwe/{index.mjs → index.mts} +7 -4
  31. /package/src/internal/util/jwe/{cli.mjs → cli.mts} +0 -0
  32. /package/src/{builder/transform → transform}/index.mts +0 -0
@@ -2,251 +2,19 @@ import { init } from "@paralleldrive/cuid2";
2
2
  import express from "express";
3
3
  import PromClient from "prom-client";
4
4
  import { Dispatcher } from "./dispatcher/index.mjs";
5
+ import Fetcher from "./fetcher/fetcher.mjs";
6
+ import { OAuth } from "./fetcher/oauth-fetcher.mjs";
7
+ import { handlePacketError, reply } from "./util/index.mjs";
5
8
  import JWE from "./util/jwe/index.mjs";
6
9
  import { Config } from "./websocket/config.mjs";
7
10
  import { WebsocketConnector } from "./websocket/index.mjs";
8
11
  const cuid = init({ length: 32 });
9
- const handlePacketError = (packet, e, transport) => {
10
- if (!packet.cb()) {
11
- console.dir({ msg: "packet error", e, packet }, { depth: null });
12
- return;
13
- }
14
- transport.send(transport.newPacket({ c: packet.cb(), a: { error: "" + e } }));
15
- };
16
- const reply = (arg, packet, transport) => {
17
- if (!packet.cb()) {
18
- console.dir({ msg: "cannot reply to packet without cb", arg, packet }, { depth: null });
19
- return;
20
- }
21
- transport.send(transport.newPacket({ c: packet.cb(), a: { ...arg } }));
22
- };
23
- const unwrap0 = (ret, body, options) => {
24
- if (options?.bodyOnly === false) {
25
- return { status: ret.status, headers: ret.headers, body };
26
- }
27
- else {
28
- return body;
29
- }
30
- };
31
- const unwrap = async (ret, options) => {
32
- if (options?.text)
33
- return unwrap0(ret, await ret.text(), options);
34
- if (options?.base64) {
35
- const base64 = Buffer.from(await ret.arrayBuffer()).toString("base64");
36
- return unwrap0(ret, base64, options);
37
- }
38
- if (options?.skipResponseBody) {
39
- return { status: ret.status, headers: ret.headers };
40
- }
41
- const text = await ret.text();
42
- try {
43
- return unwrap0(ret, JSON.parse(text), options);
44
- }
45
- catch (e) {
46
- throw e + " " + text;
47
- }
48
- };
49
- class Fetcher {
50
- constructor({ retry = 5, baseUrl, onResponse, customize }) {
51
- this.retry = retry;
52
- this.baseUrl = baseUrl;
53
- this.onResponse = onResponse;
54
- if (customize)
55
- this.customize0 = customize;
56
- }
57
- async customize(options = {}, args = {}) {
58
- if (this.customize0)
59
- await this.customize0(options, args);
60
- }
61
- async onError(e, url, options, retries, args, rateLimit) {
62
- var local = this;
63
- return new Promise((resolve, reject) => {
64
- setTimeout(async () => {
65
- try {
66
- resolve(await local.fetch(url, options, retries, args));
67
- }
68
- catch (e) {
69
- reject(e);
70
- }
71
- }, rateLimit ? 10000 : 500);
72
- });
73
- }
74
- async fetch(url, options = {}, retries, args = {}) {
75
- var local = this, baseUrl = local.baseUrl;
76
- if (retries == null)
77
- retries = local.retry;
78
- let theURL = !baseUrl
79
- ? url
80
- : `${baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"}${url}`.replace(/\/\/+/gi, "/");
81
- try {
82
- options.url = url;
83
- await local.customize(options, args);
84
- url = options.url;
85
- delete options.url;
86
- theURL = !baseUrl
87
- ? url
88
- : `${baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"}${url}`.replace(/\/\/+/gi, "/");
89
- if (!options?.headers || !options?.headers?.Accept) {
90
- options.headers = {
91
- ...options.headers,
92
- Accept: "application/json",
93
- };
94
- }
95
- if (!options?.headers || !options?.headers?.["Content-type"]) {
96
- options.headers = {
97
- ...options.headers,
98
- "Content-type": "application/json",
99
- };
100
- }
101
- if (!(options?.method === "GET" || options?.method === "HEAD") &&
102
- options?.body &&
103
- !(typeof options.body === "string") &&
104
- options?.headers?.["Content-type"] === "application/json") {
105
- options.body = JSON.stringify(options.body);
106
- }
107
- const timeout = Math.min(options?.timeout || 30 * 60 * 1000, 30 * 60 * 1000);
108
- const ret = await fetch(theURL, {
109
- ...options,
110
- signal: AbortSignal.timeout(timeout),
111
- });
112
- const status = await ret.status;
113
- if (status > 399) {
114
- const text = await ret.text();
115
- const e = new Error(status + " " + text);
116
- e.status = status;
117
- throw e;
118
- }
119
- if (local.onResponse) {
120
- await local.onResponse(ret);
121
- }
122
- return unwrap(ret, options);
123
- }
124
- catch (e) {
125
- // too many requests
126
- if (e.status === 429) {
127
- return local.onError(e, url, options, retries, args, true);
128
- }
129
- // bad request
130
- if (e.status === 400 || e.status === 422) {
131
- throw e;
132
- }
133
- --retries;
134
- console.log(theURL, e);
135
- if (retries <= 0)
136
- throw e;
137
- return local.onError(e, url, options, retries, args);
138
- }
139
- }
140
- }
141
- class OAuthFetcher extends Fetcher {
142
- constructor({ oauth, retry = 5, getToken, baseUrl, onResponse, customize }) {
143
- super({ retry, baseUrl, onResponse, customize });
144
- this.oauth = oauth;
145
- this._getToken = getToken;
146
- }
147
- async getToken(force) {
148
- var local = this, oauth = local.oauth;
149
- if (local._getToken)
150
- return local._getToken(force);
151
- if (!force && oauth.accessToken())
152
- return oauth.accessToken();
153
- const refreshToken = oauth.refreshToken();
154
- try {
155
- if (!refreshToken) {
156
- throw new Error("have no access_token and no refresh_token");
157
- }
158
- const ret = await oauth.obtainViaRefreshToken(oauth.refreshToken());
159
- if (ret.access_token) {
160
- oauth.update(ret.access_token, ret.refresh_token);
161
- return ret.access_token;
162
- }
163
- else {
164
- throw new Error("could not obtain access token via refresh token");
165
- }
166
- }
167
- catch (e) {
168
- oauth.invalidate(e);
169
- throw e;
170
- }
171
- }
172
- async onError(e, url, options, retries, args, rateLimit) {
173
- var local = this;
174
- return new Promise((resolve, reject) => {
175
- setTimeout(async () => {
176
- try {
177
- resolve(await local.fetch(url, options, retries, {
178
- forceTokenRefresh: e.status === 401,
179
- }));
180
- }
181
- catch (e) {
182
- reject(e);
183
- }
184
- }, rateLimit ? 10000 : 500);
185
- });
186
- }
187
- async periodicRefresh() {
188
- const local = this, oauth = local.oauth;
189
- console.log("refreshing oauth token, have token", !!oauth.refreshToken());
190
- if (!oauth.refreshToken())
191
- return;
192
- await local.getToken(true);
193
- console.log("refreshed oauth token");
194
- }
195
- async customize(options, args = {}) {
196
- const local = this;
197
- if (this.customize0)
198
- await this.customize0(options, args);
199
- const token = await local.getToken(args.forceTokenRefresh);
200
- options.headers = {
201
- ...options.headers,
202
- Authorization: `Bearer ${token}`,
203
- };
204
- }
205
- }
206
- class OAuth {
207
- constructor(data, saveOAuthResult, getRefreshToken) {
208
- var local = this;
209
- this._data = data || {};
210
- this.saveOAuthResult = saveOAuthResult;
211
- this.obtainViaRefreshToken = getRefreshToken;
212
- this.clients = [];
213
- }
214
- data() {
215
- return this._data;
216
- }
217
- accessToken() {
218
- return this._data.access_token;
219
- }
220
- refreshToken() {
221
- return this._data.refresh_token;
222
- }
223
- async update(accessToken, refreshToken) {
224
- this._data.access_token = accessToken;
225
- if (refreshToken) {
226
- this._data.refresh_token = refreshToken;
227
- }
228
- await this.saveOAuthResult(this._data);
229
- }
230
- async periodicRefresh() {
231
- const clients = this.clients;
232
- console.log("refreshing oauth clients", clients.length);
233
- for (let i = 0; i < clients.length; ++i) {
234
- const client = clients[0];
235
- await client.periodicRefresh();
236
- }
237
- }
238
- async invalidate(err) {
239
- if (true)
240
- return;
241
- //if (this._data.access_token === "invalid") return;
242
- }
243
- getClient(arg = {}) {
244
- const client = new OAuthFetcher({ ...arg, oauth: this });
245
- this.clients.push(client);
246
- return client;
247
- }
248
- }
249
12
  class Connector {
13
+ id;
14
+ version;
15
+ name;
16
+ icon;
17
+ dispatcher;
250
18
  constructor({ version, id, name, icon }) {
251
19
  this.id = id;
252
20
  this.version = version;
@@ -325,6 +93,7 @@ ${text}
325
93
  const server = new WebsocketConnector({
326
94
  config,
327
95
  onConnect: (transport) => {
96
+ // @ts-ignore
328
97
  local.dispatcher.onConfig = async function (secrets) {
329
98
  const decrypted = {};
330
99
  const fields = configSchema().fields;
@@ -347,6 +116,7 @@ ${text}
347
116
  }
348
117
  }
349
118
  }
119
+ // @ts-ignore
350
120
  this.startOAuth = async function (args) {
351
121
  if (!this._oauth)
352
122
  throw new Error("oauth not configured");
@@ -367,6 +137,7 @@ ${text}
367
137
  useCodeChallenge,
368
138
  };
369
139
  };
140
+ // @ts-ignore
370
141
  this.finishOAuth = async function (arg) {
371
142
  var that = this;
372
143
  if (!this._oauth)
@@ -511,8 +282,10 @@ ${text}
511
282
  ? new OAuth(decrypted.oauthResult, saveOAuthResult, getRefreshToken)
512
283
  : null;
513
284
  if (theOAuth) {
285
+ // @ts-ignore
514
286
  clearInterval(this._refreshOAuthToken);
515
287
  if (!(this._oauth.noPeriodicTokenRefresh === false)) {
288
+ // @ts-ignore
516
289
  this._refreshOAuthToken = setInterval(async () => {
517
290
  try {
518
291
  console.log("refreshing oauth token");
@@ -601,7 +374,7 @@ ${text}
601
374
  await new Promise((resolve) => {
602
375
  setTimeout(async () => {
603
376
  await server.close();
604
- resolve();
377
+ resolve(null);
605
378
  }, 10000);
606
379
  });
607
380
  process.exit(0);
@@ -0,0 +1,5 @@
1
+ export declare const handlePacketError: (packet: any, e: any, transport: any) => void;
2
+ export declare const reply: (arg: any, packet: any, transport: any) => void;
3
+ export declare const unwrap0: (ret: any, body: any, options: any) => any;
4
+ export declare const unwrap: (ret: any, options: any) => Promise<any>;
5
+ export declare const notEmpty: (what: any, name: any) => any;
@@ -0,0 +1,45 @@
1
+ export const handlePacketError = (packet, e, transport) => {
2
+ if (!packet.cb()) {
3
+ console.dir({ msg: "packet error", e, packet }, { depth: null });
4
+ return;
5
+ }
6
+ transport.send(transport.newPacket({ c: packet.cb(), a: { error: "" + e } }));
7
+ };
8
+ export const reply = (arg, packet, transport) => {
9
+ if (!packet.cb()) {
10
+ console.dir({ msg: "cannot reply to packet without cb", arg, packet }, { depth: null });
11
+ return;
12
+ }
13
+ transport.send(transport.newPacket({ c: packet.cb(), a: { ...arg } }));
14
+ };
15
+ export const unwrap0 = (ret, body, options) => {
16
+ if (options?.bodyOnly === false) {
17
+ return { status: ret.status, headers: ret.headers, body };
18
+ }
19
+ else {
20
+ return body;
21
+ }
22
+ };
23
+ export const unwrap = async (ret, options) => {
24
+ if (options?.text)
25
+ return unwrap0(ret, await ret.text(), options);
26
+ if (options?.base64) {
27
+ const base64 = Buffer.from(await ret.arrayBuffer()).toString("base64");
28
+ return unwrap0(ret, base64, options);
29
+ }
30
+ if (options?.skipResponseBody) {
31
+ return { status: ret.status, headers: ret.headers };
32
+ }
33
+ const text = await ret.text();
34
+ try {
35
+ return unwrap0(ret, JSON.parse(text), options);
36
+ }
37
+ catch (e) {
38
+ throw e + " " + text;
39
+ }
40
+ };
41
+ export const notEmpty = (what, name) => {
42
+ if (!what?.trim())
43
+ throw new Error(`${name} cannot be empty`);
44
+ return what;
45
+ };
@@ -1,15 +1,12 @@
1
- export default JWE;
1
+ import * as jose from "jose";
2
2
  declare class JWE {
3
+ issuer: string;
4
+ algorithm: string;
5
+ pair?: jose.GenerateKeyPairResult<jose.KeyLike>;
3
6
  constructor({ algorithm }: {
4
7
  algorithm?: string | undefined;
5
8
  });
6
- issuer: string;
7
- algorithm: string;
8
9
  newPair(): Promise<void>;
9
- pair: jose.GenerateKeyPairResult<jose.KeyLike> | {
10
- publicKey: jose.KeyLike;
11
- privateKey: jose.KeyLike;
12
- } | undefined;
13
10
  exportPair(): Promise<{
14
11
  publicKey: string;
15
12
  privateKey: string;
@@ -29,4 +26,4 @@ declare class JWE {
29
26
  encrypt(what: any, expiration: string | undefined, audience: any, algorithm?: string): Promise<string>;
30
27
  decrypt(what: any, audience: any): Promise<unknown>;
31
28
  }
32
- import * as jose from "jose";
29
+ export default JWE;
@@ -1,5 +1,8 @@
1
1
  import * as jose from "jose";
2
2
  class JWE {
3
+ issuer;
4
+ algorithm;
5
+ pair;
3
6
  constructor({ algorithm = "PS256" }) {
4
7
  this.issuer = "home.aloma.io";
5
8
  this.algorithm = algorithm;
@@ -0,0 +1,5 @@
1
+ declare const _default: (path: string) => Promise<{
2
+ text: any;
3
+ methods: string[];
4
+ }>;
5
+ export default _default;
@@ -0,0 +1,79 @@
1
+ import { parseFromFiles } from "@ts-ast-parser/core";
2
+ const transform = (meta) => {
3
+ if (!meta?.length)
4
+ throw new Error("metadata is empty");
5
+ meta = meta[0];
6
+ if (meta.getDeclarations()?.length !== 1) {
7
+ throw new Error("connector file needs to export default class");
8
+ }
9
+ const methods = {};
10
+ const decl = meta.getDeclarations()[0];
11
+ const members = decl.getMethods().filter((member) => {
12
+ return !(member.isStatic() ||
13
+ member.isInherited() ||
14
+ member.getKind() !== "Method" ||
15
+ member.getModifier() !== "public" ||
16
+ member.getName().startsWith("_"));
17
+ });
18
+ const text = members
19
+ .map((member) => {
20
+ methods[member.getName()] = true;
21
+ return member
22
+ .getSignatures()
23
+ .map((sig) => {
24
+ const docs = sig.getJSDoc().serialize() || [];
25
+ const desc = docs.find((what) => what.kind === "description")?.value;
26
+ const example = docs.find((what) => what.kind === "example")?.value;
27
+ let eg;
28
+ if (example) {
29
+ const parts = example.split(/```/);
30
+ const backticks = "```";
31
+ eg = `@example ${parts[0] || "usage"}\n${backticks}${parts[1]}${backticks}`;
32
+ }
33
+ const paramDocs = docs.filter((what) => what.kind === "param");
34
+ const params = sig
35
+ .getParameters()
36
+ .filter((param) => param.isNamed())
37
+ .map((param) => {
38
+ const serialized = param.serialize();
39
+ const prefix = param
40
+ .getNamedElements()
41
+ .map((p) => {
42
+ const defaultVal = p.getDefault() != null ? " = " + p.getDefault() : "";
43
+ return `${p.getName()}${defaultVal}`;
44
+ })
45
+ .join("; ");
46
+ const suffix = serialized.type.properties
47
+ .map((p) => {
48
+ const comment = paramDocs.find((what) => what.value.name === p.name);
49
+ const desc = (comment?.value.description || "").replace(/\\@/gi, "@");
50
+ return `\n/**\n${desc}\n */\n ${p.name}: ${p.type.text}`;
51
+ })
52
+ .join("; ");
53
+ return `{${prefix}}: {${suffix}}`;
54
+ })
55
+ .join(", ");
56
+ const retVal = sig
57
+ .serialize()
58
+ .return.type.text.replace(/^Promise</, "")
59
+ .replace(/>$/, "");
60
+ return `
61
+ /**
62
+ * ${desc || ""}
63
+ *
64
+ * ${eg || ""}
65
+ **/
66
+ declare function ${member.getName()}(${params}): ${retVal};
67
+ `;
68
+ })
69
+ .join("\n");
70
+ })
71
+ .join("");
72
+ return { text, methods: Object.keys(methods) };
73
+ };
74
+ export default async (path) => {
75
+ const parsed = await parseFromFiles([path]);
76
+ if (parsed.errors?.length)
77
+ throw new Error(path + " " + JSON.stringify(parsed.errors));
78
+ return transform(parsed.project?.getModules() || []);
79
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloma.io/integration-sdk",
3
- "version": "3.6.5",
3
+ "version": "3.7.0",
4
4
  "description": "",
5
5
  "author": "aloma.io",
6
6
  "license": "Apache-2.0",
@@ -1,20 +1,17 @@
1
1
  import fs from "node:fs";
2
- import parseTypes from "./transform/index.mjs";
3
- import RuntimeContext from "./runtime-context.mjs";
4
- import { fileURLToPath } from "node:url";
5
2
  import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { notEmpty } from "../internal/util/index.mjs";
5
+ import RuntimeContext from "./runtime-context.mjs";
6
6
 
7
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
-
9
- const notEmpty = (what, name) => {
10
- if (!what?.trim()) throw new Error(`${name} cannot be empty`);
7
+ //const offset = '/../../../../../';
8
+ const offset = '/../../../..//../../../..//../../../..//../../../..//../../../..//Users/xg04123/NetBeansProjects/automation/connector-google-drive/';
11
9
 
12
- return what;
13
- };
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
11
 
15
12
  export class Builder {
16
13
  private data: any = {
17
- controller: "./build/controller/.controller-for-types.mts",
14
+ controller: "./build/.controller.json",
18
15
  };
19
16
 
20
17
  config(arg: any): Builder {
@@ -36,12 +33,12 @@ export class Builder {
36
33
 
37
34
  async build(): Promise<RuntimeContext> {
38
35
  await this.parsePackageJson();
39
- await this.discoverTypes();
36
+ await this.loadTypes();
40
37
  await this.checkIcon();
41
38
 
42
39
  // @ts-ignore
43
40
  const Controller = (
44
- await import(__dirname + "/../../../../../build/controller/index.mjs")
41
+ await import(__dirname + offset + "build/controller/index.mjs")
45
42
  ).default;
46
43
 
47
44
  return new RuntimeContext(new Controller(), this.data);
@@ -49,7 +46,7 @@ export class Builder {
49
46
 
50
47
  private async checkIcon() {
51
48
  const data = this.data;
52
- const root = __dirname + "/../../../../../";
49
+ const root = __dirname + offset;
53
50
 
54
51
  data.icon = `${root}/logo.png`;
55
52
  }
@@ -58,7 +55,7 @@ export class Builder {
58
55
  const data = this.data;
59
56
 
60
57
  const packageJson = JSON.parse(
61
- fs.readFileSync(__dirname + "/../../../../../package.json", {
58
+ fs.readFileSync(__dirname + offset + "package.json", {
62
59
  encoding: "utf-8",
63
60
  }),
64
61
  );
@@ -67,11 +64,11 @@ export class Builder {
67
64
  notEmpty((data.version = packageJson.version), "version");
68
65
  }
69
66
 
70
- private async discoverTypes() {
67
+ private async loadTypes() {
71
68
  notEmpty(this.data.controller, "controller");
72
69
 
73
- const content = fs.readFileSync(this.data.controller);
74
- const { text, methods } = await parseTypes(this.data.controller);
70
+ const content = fs.readFileSync(this.data.controller, {encoding: 'utf-8'});
71
+ const {text, methods} = JSON.parse(content);
75
72
 
76
73
  this.data.types = text;
77
74
  this.data.methods = methods;
@@ -1,6 +1,6 @@
1
+ import fs from "node:fs";
1
2
  import { AbstractController } from "../controller/index.mjs";
2
3
  import { Connector } from "../internal/index.mjs";
3
- import fs from "node:fs";
4
4
 
5
5
  export default class RuntimeContext {
6
6
  constructor(
@@ -12,7 +12,10 @@ export default class RuntimeContext {
12
12
  const controller = this.controller;
13
13
 
14
14
  if (!(controller instanceof AbstractController))
15
+ {
15
16
  throw new Error("the controller needs to extend AbstractController");
17
+ }
18
+
16
19
  const data: any = this.data;
17
20
 
18
21
  let icon;
package/src/cli.mts CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Command } from "commander";
4
+ import ChildProcess from "node:child_process";
4
5
  import fs from "node:fs";
5
- import { fileURLToPath } from "node:url";
6
6
  import path from "node:path";
7
- import JWE from "./internal/util/jwe/index.mjs";
7
+ import { fileURLToPath } from "node:url";
8
8
  import util from "node:util";
9
- import ChildProcess from "node:child_process";
9
+ import { notEmpty } from "./internal/util/index.mjs";
10
+ import JWE from "./internal/util/jwe/index.mjs";
11
+ import parseTypes from "./transform/index.mjs";
10
12
 
11
13
  const exec = util.promisify(ChildProcess.exec);
12
14
 
@@ -118,10 +120,23 @@ program
118
120
  .description("Build the current connector project")
119
121
  .action(async (str, options) => {
120
122
  const { stdout, stderr } = await exec(
121
- `rm -rf build; mkdir -p build/controller; cp ./src/controller/index.mts ./build/controller/.controller-for-types.mts;`,
123
+ `rm -rf build; mkdir -p build`,
122
124
  );
123
125
 
124
126
  if (stdout) console.log(stdout);
127
+
128
+ new Extractor().extract('./src/controller/index.mts', './build/.controller.json')
125
129
  });
126
130
 
131
+ class Extractor {
132
+ async extract(source, target) {
133
+ notEmpty(source, "source");
134
+
135
+ fs.readFileSync(source);
136
+ const { text, methods } = await parseTypes(source);
137
+
138
+ fs.writeFileSync(target, JSON.stringify({text, methods}), {encoding: 'utf-8'})
139
+ }
140
+ }
141
+
127
142
  program.parse();
@@ -1,4 +1,10 @@
1
- class Dispatcher {
1
+ export default class Dispatcher {
2
+ private _config: any;
3
+ private _main: any;
4
+ _oauth: any;
5
+ private _types: any;
6
+ private _resolvers: any;
7
+
2
8
  constructor() {
3
9
  this._config = { fields: {} };
4
10
  }
@@ -90,7 +96,7 @@ ${arg.configurableClientScope}
90
96
  return this;
91
97
  }
92
98
 
93
- config({ fields, oauth, description, summary }) {
99
+ config({ fields, oauth, description, summary }: any) {
94
100
  this._config.oauth = this._config.oauth || oauth;
95
101
  this._config.description = this._config.description || description;
96
102
  this._config.summary = this._config.summary || summary;
@@ -189,14 +195,17 @@ ${arg.configurableClientScope}
189
195
  const processPacket = async (packet) => {
190
196
  switch (packet.method()) {
191
197
  case "connector.introspect":
198
+ // @ts-ignore
192
199
  const intro = await introspect({});
193
200
 
194
201
  return { configSchema: local._config, introspect: intro };
195
202
 
196
203
  case "connector.start-oauth":
204
+ // @ts-ignore
197
205
  return await local.startOAuth(packet.args());
198
206
 
199
207
  case "connector.finish-oauth":
208
+ // @ts-ignore
200
209
  return await local.finishOAuth(packet.args());
201
210
 
202
211
  case "connector.query":
@@ -224,6 +233,9 @@ ${arg.configurableClientScope}
224
233
  start,
225
234
  };
226
235
  }
236
+ onConfig(arg0: any) {
237
+ throw new Error("Method not implemented.");
238
+ }
227
239
  }
228
240
 
229
241
  export { Dispatcher };