@aloma.io/integration-sdk 3.3.83 → 3.3.85
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/internal/index.mjs +20 -20
- package/package.json +1 -1
- package/src/internal/index.mjs +24 -23
package/build/internal/index.mjs
CHANGED
@@ -1,18 +1,12 @@
|
|
1
|
-
// @ts-nocheck
|
2
|
-
import dotenv from "dotenv";
|
3
|
-
dotenv.config();
|
4
|
-
import fs from "node:fs";
|
5
|
-
import { Config } from "./websocket/config.mjs";
|
6
|
-
import { Connection } from "./websocket/connection/index.mjs";
|
7
|
-
import { Transport } from "./websocket/transport/index.mjs";
|
8
|
-
import { Dispatcher } from "./dispatcher/index.mjs";
|
9
|
-
import { WebsocketConnector } from "./websocket/index.mjs";
|
10
|
-
import JWE from "./util/jwe/index.mjs";
|
11
|
-
import fetch from "node-fetch";
|
12
1
|
import { init } from "@paralleldrive/cuid2";
|
13
|
-
const cuid = init({ length: 32 });
|
14
2
|
import express from "express";
|
3
|
+
import fetch from "node-fetch";
|
15
4
|
import PromClient from "prom-client";
|
5
|
+
import { Dispatcher } from "./dispatcher/index.mjs";
|
6
|
+
import JWE from "./util/jwe/index.mjs";
|
7
|
+
import { Config } from "./websocket/config.mjs";
|
8
|
+
import { WebsocketConnector } from "./websocket/index.mjs";
|
9
|
+
const cuid = init({ length: 32 });
|
16
10
|
// TODO fetch with retry
|
17
11
|
const handlePacketError = (packet, e, transport) => {
|
18
12
|
if (!packet.cb()) {
|
@@ -28,14 +22,22 @@ const reply = (arg, packet, transport) => {
|
|
28
22
|
}
|
29
23
|
transport.send(transport.newPacket({ c: packet.cb(), a: { ...arg } }));
|
30
24
|
};
|
25
|
+
const unwrap0 = (ret, body, options) => {
|
26
|
+
if (options?.bodyOnly) {
|
27
|
+
return body;
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
return { status: ret.status, headers: ret.headers, body };
|
31
|
+
}
|
32
|
+
};
|
31
33
|
const unwrap = async (ret, options) => {
|
32
34
|
if (options?.text)
|
33
|
-
return await ret.text();
|
35
|
+
return unwrap0(ret, await ret.text(), options);
|
34
36
|
if (options?.base64)
|
35
|
-
return (await ret.buffer()).toString("base64");
|
37
|
+
return unwrap0(ret, (await ret.buffer()).toString("base64"), options);
|
36
38
|
const text = await ret.text();
|
37
39
|
try {
|
38
|
-
return JSON.parse(text);
|
40
|
+
return unwrap0(ret, JSON.parse(text), options);
|
39
41
|
}
|
40
42
|
catch (e) {
|
41
43
|
throw e + " " + text;
|
@@ -70,12 +72,13 @@ class Fetcher {
|
|
70
72
|
var local = this, baseUrl = local.baseUrl;
|
71
73
|
if (retries == null)
|
72
74
|
retries = local.retry;
|
73
|
-
|
75
|
+
let theURL = `${baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"}${url}`.replace(/\/\/+/gi, "/");
|
74
76
|
try {
|
75
77
|
options.url = url;
|
76
78
|
await local.customize(options, args);
|
77
79
|
url = options.url;
|
78
80
|
delete (options.url);
|
81
|
+
theURL = `${baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"}${url}`.replace(/\/\/+/gi, "/");
|
79
82
|
if (!options?.headers || !options?.headers?.Accept) {
|
80
83
|
options.headers = {
|
81
84
|
...options.headers,
|
@@ -218,10 +221,7 @@ class OAuth {
|
|
218
221
|
async invalidate(err) {
|
219
222
|
if (true)
|
220
223
|
return;
|
221
|
-
if (this._data.access_token === "invalid")
|
222
|
-
return;
|
223
|
-
console.log("could not obtain access token, marking connector as disconnected", err);
|
224
|
-
await this.update("invalid", null);
|
224
|
+
//if (this._data.access_token === "invalid") return;
|
225
225
|
}
|
226
226
|
getClient(arg = {}) {
|
227
227
|
const client = new OAuthFetcher({ ...arg, oauth: this });
|
package/package.json
CHANGED
package/src/internal/index.mjs
CHANGED
@@ -1,18 +1,12 @@
|
|
1
|
-
// @ts-nocheck
|
2
|
-
import dotenv from "dotenv";
|
3
|
-
dotenv.config();
|
4
|
-
import fs from "node:fs";
|
5
|
-
import { Config } from "./websocket/config.mjs";
|
6
|
-
import { Connection } from "./websocket/connection/index.mjs";
|
7
|
-
import { Transport } from "./websocket/transport/index.mjs";
|
8
|
-
import { Dispatcher } from "./dispatcher/index.mjs";
|
9
|
-
import { WebsocketConnector } from "./websocket/index.mjs";
|
10
|
-
import JWE from "./util/jwe/index.mjs";
|
11
|
-
import fetch from "node-fetch";
|
12
1
|
import { init } from "@paralleldrive/cuid2";
|
13
|
-
const cuid = init({ length: 32 });
|
14
2
|
import express from "express";
|
3
|
+
import fetch from "node-fetch";
|
15
4
|
import PromClient from "prom-client";
|
5
|
+
import { Dispatcher } from "./dispatcher/index.mjs";
|
6
|
+
import JWE from "./util/jwe/index.mjs";
|
7
|
+
import { Config } from "./websocket/config.mjs";
|
8
|
+
import { WebsocketConnector } from "./websocket/index.mjs";
|
9
|
+
const cuid = init({ length: 32 });
|
16
10
|
|
17
11
|
// TODO fetch with retry
|
18
12
|
|
@@ -37,19 +31,28 @@ const reply = (arg, packet, transport) => {
|
|
37
31
|
transport.send(transport.newPacket({ c: packet.cb(), a: { ...arg } }));
|
38
32
|
};
|
39
33
|
|
34
|
+
const unwrap0 = (ret, body, options) => {
|
35
|
+
if (options?.bodyOnly) {
|
36
|
+
return body;
|
37
|
+
} else {
|
38
|
+
return {status: ret.status, headers: ret.headers, body};
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
40
42
|
const unwrap = async (ret, options) => {
|
41
|
-
if (options?.text) return await ret.text();
|
42
|
-
if (options?.base64) return (await ret.buffer()).toString("base64");
|
43
|
+
if (options?.text) return unwrap0(ret, await ret.text(), options);
|
44
|
+
if (options?.base64) return unwrap0(ret, (await ret.buffer()).toString("base64"), options);
|
43
45
|
|
44
46
|
const text = await ret.text();
|
45
47
|
|
46
48
|
try {
|
47
|
-
return JSON.parse(text);
|
49
|
+
return unwrap0(ret, JSON.parse(text), options);
|
48
50
|
} catch (e) {
|
49
51
|
throw e + " " + text;
|
50
52
|
}
|
51
53
|
};
|
52
54
|
|
55
|
+
|
53
56
|
class Fetcher {
|
54
57
|
constructor({ retry = 5, baseUrl, onResponse, customize }) {
|
55
58
|
this.retry = retry;
|
@@ -85,7 +88,7 @@ class Fetcher {
|
|
85
88
|
|
86
89
|
if (retries == null) retries = local.retry;
|
87
90
|
|
88
|
-
|
91
|
+
let theURL = `${
|
89
92
|
baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"
|
90
93
|
}${url}`.replace(/\/\/+/gi, "/");
|
91
94
|
|
@@ -96,6 +99,10 @@ class Fetcher {
|
|
96
99
|
url = options.url;
|
97
100
|
delete(options.url);
|
98
101
|
|
102
|
+
theURL = `${
|
103
|
+
baseUrl?.endsWith("/") ? baseUrl : baseUrl + "/"
|
104
|
+
}${url}`.replace(/\/\/+/gi, "/");
|
105
|
+
|
99
106
|
if (!options?.headers || !options?.headers?.Accept) {
|
100
107
|
options.headers = {
|
101
108
|
...options.headers,
|
@@ -280,14 +287,8 @@ class OAuth {
|
|
280
287
|
|
281
288
|
async invalidate(err) {
|
282
289
|
if (true) return;
|
283
|
-
if (this._data.access_token === "invalid") return;
|
284
|
-
|
285
|
-
console.log(
|
286
|
-
"could not obtain access token, marking connector as disconnected",
|
287
|
-
err,
|
288
|
-
);
|
290
|
+
//if (this._data.access_token === "invalid") return;
|
289
291
|
|
290
|
-
await this.update("invalid", null);
|
291
292
|
}
|
292
293
|
|
293
294
|
getClient(arg = {}) {
|