@aloma.io/integration-sdk 3.3.92 → 3.4.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.
@@ -50,10 +50,10 @@ export default class RuntimeContext {
50
50
  if (data.auth?.oauth) {
51
51
  configuration.oauth(data.auth?.oauth);
52
52
  }
53
- configuration.main(async ({ newTask, updateTask, config, oauth, getClient }) => {
53
+ configuration.main(async ({ newTask, updateTask, config, oauth, getClient, getBlob, getBlobContent, putBlob, }) => {
54
54
  try {
55
55
  await controller._doStop();
56
- await controller._doStart(config, oauth, newTask, updateTask, getClient);
56
+ await controller._doStart(config, oauth, newTask, updateTask, getClient, getBlob, getBlobContent, putBlob);
57
57
  }
58
58
  catch (e) {
59
59
  console.log(e);
@@ -7,15 +7,31 @@ export declare abstract class AbstractController {
7
7
  protected fallback(arg: any): Promise<any>;
8
8
  protected endpoint(arg: any): Promise<any>;
9
9
  protected newTask(name: string, data: any): Promise<string>;
10
- protected getClient({ baseUrl, onResponse, customize }: {
10
+ protected getClient({ baseUrl, onResponse, customize, }: {
11
11
  baseUrl: string;
12
12
  onResponse?: (response: any) => void;
13
13
  customize?: (request: any) => void;
14
14
  }): Promise<any>;
15
15
  protected updateTask(name: string, data: any): Promise<string>;
16
+ protected newBlob({ content, name, size, mimetype, meta, taskId, }: {
17
+ content: string;
18
+ name?: string;
19
+ size?: number;
20
+ mimetype?: string;
21
+ meta?: any;
22
+ taskId?: string;
23
+ }): Promise<string>;
24
+ protected getBlob(id: string): Promise<{
25
+ name?: string;
26
+ id: any;
27
+ size?: number;
28
+ mimetype?: string;
29
+ meta?: any;
30
+ }>;
31
+ protected getBlobContent(id: string): Promise<string>;
16
32
  __endpoint(arg: any): Promise<any | null>;
17
33
  __configQuery(arg: any): Promise<any | null>;
18
34
  __default(arg: any): Promise<any | null>;
19
- _doStart(config: any, client: any, newTask: any, updateTask: any, getClient: any): Promise<void>;
35
+ _doStart(config: any, client: any, newTask: any, updateTask: any, getBlob: any, getBlobContent: any, putBlob: any, getClient: any): Promise<void>;
20
36
  _doStop(isShutdown?: boolean): Promise<void>;
21
37
  }
@@ -15,12 +15,21 @@ export class AbstractController {
15
15
  async newTask(name, data) {
16
16
  throw new Error("not implemented");
17
17
  }
18
- getClient({ baseUrl, onResponse, customize }) {
18
+ getClient({ baseUrl, onResponse, customize, }) {
19
19
  throw new Error("not implemented");
20
20
  }
21
21
  async updateTask(name, data) {
22
22
  throw new Error("not implemented");
23
23
  }
24
+ async newBlob({ content, name, size, mimetype, meta, taskId, }) {
25
+ throw new Error("not implemented");
26
+ }
27
+ async getBlob(id) {
28
+ throw new Error("not implemented");
29
+ }
30
+ async getBlobContent(id) {
31
+ throw new Error("not implemented");
32
+ }
24
33
  async __endpoint(arg) {
25
34
  return this.endpoint(arg);
26
35
  }
@@ -30,12 +39,15 @@ export class AbstractController {
30
39
  async __default(arg) {
31
40
  return this.fallback(arg);
32
41
  }
33
- async _doStart(config, client, newTask, updateTask, getClient) {
42
+ async _doStart(config, client, newTask, updateTask, getBlob, getBlobContent, putBlob, getClient) {
34
43
  this.config = config;
35
44
  this.client = client;
36
45
  this.newTask = newTask;
37
46
  this.updateTask = updateTask;
38
47
  this.getClient = getClient;
48
+ this.newBlob = putBlob;
49
+ this.getBlob = getBlob;
50
+ this.getBlobContent = getBlobContent;
39
51
  await this.start();
40
52
  }
41
53
  async _doStop(isShutdown = false) {
@@ -77,7 +77,7 @@ class Fetcher {
77
77
  options.url = url;
78
78
  await local.customize(options, args);
79
79
  url = options.url;
80
- delete (options.url);
80
+ delete options.url;
81
81
  theURL = `${baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"}${url}`.replace(/\/\/+/gi, "/");
82
82
  if (!options?.headers || !options?.headers?.Accept) {
83
83
  options.headers = {
@@ -117,7 +117,7 @@ class Fetcher {
117
117
  }
118
118
  // bad request
119
119
  if (e.status === 400 || e.status === 422) {
120
- throw (e);
120
+ throw e;
121
121
  }
122
122
  --retries;
123
123
  console.log(theURL, e);
@@ -508,9 +508,40 @@ ${text}
508
508
  }, 4 * 60 * 60 * 15000);
509
509
  }
510
510
  }
511
+ const getBlob = (id) => {
512
+ return new Promise((resolve, reject) => {
513
+ const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret)), `_req-${cuid()}`);
514
+ packet.method("connector.blob.get");
515
+ packet.args({
516
+ id,
517
+ });
518
+ transport.send(packet);
519
+ });
520
+ };
521
+ const getBlobContent = (id) => {
522
+ return new Promise((resolve, reject) => {
523
+ const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret)), `_req-${cuid()}`);
524
+ packet.method("connector.blob.get-content");
525
+ packet.args({
526
+ id,
527
+ });
528
+ transport.send(packet);
529
+ });
530
+ };
531
+ const putBlob = (args = {}) => {
532
+ return new Promise((resolve, reject) => {
533
+ const packet = transport.newPacket({}, (ret) => (ret?.error ? reject(ret.error) : resolve(ret)), `_req-${cuid()}`);
534
+ packet.method("connector.blob.put");
535
+ packet.args(args);
536
+ transport.send(packet);
537
+ });
538
+ };
511
539
  start({
512
540
  config: decrypted,
513
541
  oauth: theOAuth,
542
+ getBlob,
543
+ getBlobContent,
544
+ putBlob,
514
545
  getClient: (arg) => theOAuth ? theOAuth.getClient(arg) : new Fetcher(arg),
515
546
  newTask: (name, data) => {
516
547
  return new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloma.io/integration-sdk",
3
- "version": "3.3.92",
3
+ "version": "3.4.0",
4
4
  "description": "",
5
5
  "author": "aloma.io",
6
6
  "license": "Apache-2.0",
@@ -64,7 +64,16 @@ export default class RuntimeContext {
64
64
  }
65
65
 
66
66
  configuration.main(
67
- async ({ newTask, updateTask, config, oauth, getClient }) => {
67
+ async ({
68
+ newTask,
69
+ updateTask,
70
+ config,
71
+ oauth,
72
+ getClient,
73
+ getBlob,
74
+ getBlobContent,
75
+ putBlob,
76
+ }) => {
68
77
  try {
69
78
  await controller._doStop();
70
79
  await controller._doStart(
@@ -73,6 +82,9 @@ export default class RuntimeContext {
73
82
  newTask,
74
83
  updateTask,
75
84
  getClient,
85
+ getBlob,
86
+ getBlobContent,
87
+ putBlob,
76
88
  );
77
89
  } catch (e) {
78
90
  console.log(e);
@@ -25,7 +25,7 @@ export abstract class AbstractController {
25
25
  protected getClient({
26
26
  baseUrl,
27
27
  onResponse,
28
- customize
28
+ customize,
29
29
  }: {
30
30
  baseUrl: string;
31
31
  onResponse?: (response: any) => void;
@@ -38,6 +38,38 @@ export abstract class AbstractController {
38
38
  throw new Error("not implemented");
39
39
  }
40
40
 
41
+ protected async newBlob({
42
+ content,
43
+ name,
44
+ size,
45
+ mimetype,
46
+ meta,
47
+ taskId,
48
+ }: {
49
+ content: string;
50
+ name?: string;
51
+ size?: number;
52
+ mimetype?: string;
53
+ meta?: any;
54
+ taskId?: string;
55
+ }): Promise<string> {
56
+ throw new Error("not implemented");
57
+ }
58
+
59
+ protected async getBlob(id: string): Promise<{
60
+ name?: string;
61
+ id;
62
+ size?: number;
63
+ mimetype?: string;
64
+ meta?: any;
65
+ }> {
66
+ throw new Error("not implemented");
67
+ }
68
+
69
+ protected async getBlobContent(id: string): Promise<string> {
70
+ throw new Error("not implemented");
71
+ }
72
+
41
73
  async __endpoint(arg: any): Promise<any | null> {
42
74
  return this.endpoint(arg);
43
75
  }
@@ -55,6 +87,9 @@ export abstract class AbstractController {
55
87
  client: any,
56
88
  newTask: any,
57
89
  updateTask: any,
90
+ getBlob: any,
91
+ getBlobContent: any,
92
+ putBlob: any,
58
93
  getClient: any,
59
94
  ): Promise<void> {
60
95
  this.config = config;
@@ -62,6 +97,9 @@ export abstract class AbstractController {
62
97
  this.newTask = newTask;
63
98
  this.updateTask = updateTask;
64
99
  this.getClient = getClient;
100
+ this.newBlob = putBlob;
101
+ this.getBlob = getBlob;
102
+ this.getBlobContent = getBlobContent;
65
103
 
66
104
  await this.start();
67
105
  }
@@ -33,15 +33,16 @@ const reply = (arg, packet, transport) => {
33
33
 
34
34
  const unwrap0 = (ret, body, options) => {
35
35
  if (options?.bodyOnly === false) {
36
- return {status: ret.status, headers: ret.headers, body};
36
+ return { status: ret.status, headers: ret.headers, body };
37
37
  } else {
38
- return body;
38
+ return body;
39
39
  }
40
- }
40
+ };
41
41
 
42
42
  const unwrap = async (ret, options) => {
43
43
  if (options?.text) return unwrap0(ret, await ret.text(), options);
44
- if (options?.base64) return unwrap0(ret, (await ret.buffer()).toString("base64"), options);
44
+ if (options?.base64)
45
+ return unwrap0(ret, (await ret.buffer()).toString("base64"), options);
45
46
 
46
47
  const text = await ret.text();
47
48
 
@@ -52,7 +53,6 @@ const unwrap = async (ret, options) => {
52
53
  }
53
54
  };
54
55
 
55
-
56
56
  class Fetcher {
57
57
  constructor({ retry = 5, baseUrl, onResponse, customize }) {
58
58
  this.retry = retry;
@@ -95,9 +95,9 @@ class Fetcher {
95
95
  try {
96
96
  options.url = url;
97
97
  await local.customize(options, args);
98
-
98
+
99
99
  url = options.url;
100
- delete(options.url);
100
+ delete options.url;
101
101
 
102
102
  theURL = `${
103
103
  baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"
@@ -147,10 +147,10 @@ class Fetcher {
147
147
  if (e.status === 429) {
148
148
  return local.onError(e, url, options, retries, args, true);
149
149
  }
150
-
150
+
151
151
  // bad request
152
152
  if (e.status === 400 || e.status === 422) {
153
- throw(e);
153
+ throw e;
154
154
  }
155
155
 
156
156
  --retries;
@@ -165,7 +165,7 @@ class Fetcher {
165
165
  }
166
166
 
167
167
  class OAuthFetcher extends Fetcher {
168
- constructor({ oauth, retry = 5, getToken, baseUrl, onResponse, customize}) {
168
+ constructor({ oauth, retry = 5, getToken, baseUrl, onResponse, customize }) {
169
169
  super({ retry, baseUrl, onResponse, customize });
170
170
 
171
171
  this.oauth = oauth;
@@ -235,9 +235,9 @@ class OAuthFetcher extends Fetcher {
235
235
 
236
236
  async customize(options, args = {}) {
237
237
  const local = this;
238
-
238
+
239
239
  if (this.customize0) await this.customize0(options, args);
240
-
240
+
241
241
  const token = await local.getToken(args.forceTokenRefresh);
242
242
 
243
243
  options.headers = {
@@ -293,7 +293,6 @@ class OAuth {
293
293
  async invalidate(err) {
294
294
  if (true) return;
295
295
  //if (this._data.access_token === "invalid") return;
296
-
297
296
  }
298
297
 
299
298
  getClient(arg = {}) {
@@ -638,9 +637,61 @@ ${text}
638
637
  }
639
638
  }
640
639
 
640
+ const getBlob = (id) => {
641
+ return new Promise((resolve, reject) => {
642
+ const packet = transport.newPacket(
643
+ {},
644
+ (ret) => (ret?.error ? reject(ret.error) : resolve(ret)),
645
+ `_req-${cuid()}`,
646
+ );
647
+
648
+ packet.method("connector.blob.get");
649
+ packet.args({
650
+ id,
651
+ });
652
+
653
+ transport.send(packet);
654
+ });
655
+ };
656
+
657
+ const getBlobContent = (id) => {
658
+ return new Promise((resolve, reject) => {
659
+ const packet = transport.newPacket(
660
+ {},
661
+ (ret) => (ret?.error ? reject(ret.error) : resolve(ret)),
662
+ `_req-${cuid()}`,
663
+ );
664
+
665
+ packet.method("connector.blob.get-content");
666
+ packet.args({
667
+ id,
668
+ });
669
+
670
+ transport.send(packet);
671
+ });
672
+ };
673
+
674
+ const putBlob = (args = {}) => {
675
+ return new Promise((resolve, reject) => {
676
+ const packet = transport.newPacket(
677
+ {},
678
+ (ret) => (ret?.error ? reject(ret.error) : resolve(ret)),
679
+ `_req-${cuid()}`,
680
+ );
681
+
682
+ packet.method("connector.blob.put");
683
+ packet.args(args);
684
+
685
+ transport.send(packet);
686
+ });
687
+ };
688
+
641
689
  start({
642
690
  config: decrypted,
643
691
  oauth: theOAuth,
692
+ getBlob,
693
+ getBlobContent,
694
+ putBlob,
644
695
  getClient: (arg) =>
645
696
  theOAuth ? theOAuth.getClient(arg) : new Fetcher(arg),
646
697
  newTask: (name, data) => {