@grandlinex/base-con 1.0.3 → 2.0.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.
- package/dist/cjs/AxiosCon.js +4 -4
- package/dist/cjs/BaseCon.d.ts +1 -5
- package/dist/cjs/BaseCon.js +4 -7
- package/dist/cjs/ConMerger.js +1 -1
- package/dist/cjs/NodeCon.js +10 -11
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.js +0 -4
- package/dist/mjs/AxiosCon.js +4 -4
- package/dist/mjs/BaseCon.d.ts +1 -5
- package/dist/mjs/BaseCon.js +4 -7
- package/dist/mjs/ConMerger.js +1 -1
- package/dist/mjs/NodeCon.js +10 -11
- package/dist/mjs/index.d.ts +0 -4
- package/dist/mjs/index.js +0 -4
- package/package.json +3 -3
package/dist/cjs/AxiosCon.js
CHANGED
|
@@ -16,25 +16,25 @@ const AxiosCon = {
|
|
|
16
16
|
get: async (url, config) => {
|
|
17
17
|
return acTransform(axios_1.default.get(url, {
|
|
18
18
|
headers: config?.headers,
|
|
19
|
-
validateStatus: (
|
|
19
|
+
validateStatus: () => true,
|
|
20
20
|
}));
|
|
21
21
|
},
|
|
22
22
|
post: async (url, body, config) => {
|
|
23
23
|
return acTransform(axios_1.default.post(url, body, {
|
|
24
24
|
headers: config?.headers,
|
|
25
|
-
validateStatus: (
|
|
25
|
+
validateStatus: () => true,
|
|
26
26
|
}));
|
|
27
27
|
},
|
|
28
28
|
patch: async (url, body, config) => {
|
|
29
29
|
return acTransform(axios_1.default.patch(url, body, {
|
|
30
30
|
headers: config?.headers,
|
|
31
|
-
validateStatus: (
|
|
31
|
+
validateStatus: () => true,
|
|
32
32
|
}));
|
|
33
33
|
},
|
|
34
34
|
delete: async (url, config) => {
|
|
35
35
|
return acTransform(axios_1.default.delete(url, {
|
|
36
36
|
headers: config?.headers,
|
|
37
|
-
validateStatus: (
|
|
37
|
+
validateStatus: () => true,
|
|
38
38
|
}));
|
|
39
39
|
},
|
|
40
40
|
};
|
package/dist/cjs/BaseCon.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THIS FILE IS AUTOMATICALLY GENERATED
|
|
3
|
-
* DO NOT EDIT THIS FILE
|
|
4
|
-
*/
|
|
5
1
|
export type ErrorType = {
|
|
6
2
|
type: string;
|
|
7
3
|
global?: string[];
|
|
@@ -139,7 +135,7 @@ export default class BaseCon {
|
|
|
139
135
|
* @returns {void}
|
|
140
136
|
*/
|
|
141
137
|
forceConnect(token: string | null): void;
|
|
142
|
-
|
|
138
|
+
copyFrom(con: BaseCon): void;
|
|
143
139
|
/**
|
|
144
140
|
* Establishes a connection to the backend using the supplied credentials.
|
|
145
141
|
* Performs a health‑check ping first; if successful, it requests an authentication
|
package/dist/cjs/BaseCon.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* THIS FILE IS AUTOMATICALLY GENERATED
|
|
4
|
-
* DO NOT EDIT THIS FILE
|
|
5
|
-
*/
|
|
6
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
4
|
};
|
|
@@ -88,7 +84,7 @@ class BaseCon {
|
|
|
88
84
|
if (config?.param) {
|
|
89
85
|
const e = Object.keys(config.param);
|
|
90
86
|
for (const d of e) {
|
|
91
|
-
pp = pp.replace(`{${d}}`, `${config.param[d]}`);
|
|
87
|
+
pp = pp.replace(`{${d}}`, encodeURIComponent(`${config.param[d]}`));
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
if (config?.query) {
|
|
@@ -96,7 +92,7 @@ class BaseCon {
|
|
|
96
92
|
const slices = [];
|
|
97
93
|
for (const d of e) {
|
|
98
94
|
if (config.query[d]) {
|
|
99
|
-
slices.push(`${d}=${config.query[d]}`);
|
|
95
|
+
slices.push(`${encodeURIComponent(d)}=${encodeURIComponent(`${config.query[d]}`)}`);
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
if (slices.length > 0) {
|
|
@@ -202,7 +198,7 @@ class BaseCon {
|
|
|
202
198
|
this.disconnected = false;
|
|
203
199
|
this.noAuth = token === null;
|
|
204
200
|
}
|
|
205
|
-
|
|
201
|
+
copyFrom(con) {
|
|
206
202
|
this.authorization = con.authorization;
|
|
207
203
|
this.disconnected = con.disconnected;
|
|
208
204
|
this.noAuth = con.noAuth;
|
|
@@ -363,6 +359,7 @@ class BaseCon {
|
|
|
363
359
|
case 498:
|
|
364
360
|
x = await this.reconnect();
|
|
365
361
|
if (x) {
|
|
362
|
+
// onReconnect is intentionally fire-and-forget; the retry proceeds immediately
|
|
366
363
|
this.onReconnect(this).catch((dx) => {
|
|
367
364
|
this.logger(dx);
|
|
368
365
|
});
|
package/dist/cjs/ConMerger.js
CHANGED
|
@@ -5,7 +5,7 @@ function ConMerger(conA, conB) {
|
|
|
5
5
|
const prop = Object.getPrototypeOf(conB);
|
|
6
6
|
const propertyNames = Object.getOwnPropertyNames(prop);
|
|
7
7
|
for (const key of propertyNames) {
|
|
8
|
-
if (key !== 'constructor' && !conA
|
|
8
|
+
if (key !== 'constructor' && !(key in conA)) {
|
|
9
9
|
conA[key] = prop[key];
|
|
10
10
|
}
|
|
11
11
|
}
|
package/dist/cjs/NodeCon.js
CHANGED
|
@@ -48,16 +48,17 @@ function selectClient(url) {
|
|
|
48
48
|
async function fcTransform(message, raw) {
|
|
49
49
|
let data = null;
|
|
50
50
|
if (message.headers['content-type']?.includes('application/json')) {
|
|
51
|
-
data = JSON.parse(raw);
|
|
51
|
+
data = JSON.parse(raw.toString('utf8'));
|
|
52
52
|
}
|
|
53
53
|
else if (message.headers['content-type']?.includes('form-data')) {
|
|
54
|
-
data
|
|
54
|
+
// form-data response parsing is not supported in NodeCon
|
|
55
|
+
data = null;
|
|
55
56
|
}
|
|
56
57
|
else if (message.headers['content-type']?.includes('octet-stream')) {
|
|
57
|
-
data =
|
|
58
|
+
data = raw;
|
|
58
59
|
}
|
|
59
60
|
else if (message.headers['content-type']?.startsWith('text/')) {
|
|
60
|
-
data =
|
|
61
|
+
data = raw.toString('utf8');
|
|
61
62
|
}
|
|
62
63
|
return {
|
|
63
64
|
code: message.statusCode || -1,
|
|
@@ -77,7 +78,7 @@ function bodyTransform(r, headers) {
|
|
|
77
78
|
body: r,
|
|
78
79
|
headers: {
|
|
79
80
|
...headers,
|
|
80
|
-
|
|
81
|
+
...r.getHeaders(),
|
|
81
82
|
},
|
|
82
83
|
};
|
|
83
84
|
}
|
|
@@ -111,18 +112,16 @@ async function makeRequest(url, option, body, config) {
|
|
|
111
112
|
headers,
|
|
112
113
|
...option,
|
|
113
114
|
}, (res) => {
|
|
114
|
-
|
|
115
|
-
// A chunk of data has been received.
|
|
115
|
+
const chunks = [];
|
|
116
116
|
res.on('data', (chunk) => {
|
|
117
|
-
|
|
117
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
118
118
|
});
|
|
119
|
-
// The whole response has been received. Print out the result.
|
|
120
119
|
res.on('end', () => {
|
|
121
|
-
resolve(fcTransform(res,
|
|
120
|
+
resolve(fcTransform(res, Buffer.concat(chunks)));
|
|
122
121
|
});
|
|
123
122
|
})
|
|
124
123
|
.on('error', (err) => {
|
|
125
|
-
console.
|
|
124
|
+
console.error(`NodeCon request error: ${err.message}`);
|
|
126
125
|
resolve({
|
|
127
126
|
code: -1,
|
|
128
127
|
data: null,
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -18,10 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.ConMerger = exports.NodeCon = exports.AxiosCon = exports.FetchCon = exports.FormData = exports.BaseCon = void 0;
|
|
21
|
-
/**
|
|
22
|
-
* THIS FILE IS AUTOMATICALLY GENERATED
|
|
23
|
-
* DO NOT EDIT THIS FILE
|
|
24
|
-
*/
|
|
25
21
|
const form_data_1 = __importDefault(require("form-data"));
|
|
26
22
|
exports.FormData = form_data_1.default;
|
|
27
23
|
const BaseCon_js_1 = __importDefault(require("./BaseCon.js"));
|
package/dist/mjs/AxiosCon.js
CHANGED
|
@@ -11,25 +11,25 @@ const AxiosCon = {
|
|
|
11
11
|
get: async (url, config) => {
|
|
12
12
|
return acTransform(axios.get(url, {
|
|
13
13
|
headers: config?.headers,
|
|
14
|
-
validateStatus: (
|
|
14
|
+
validateStatus: () => true,
|
|
15
15
|
}));
|
|
16
16
|
},
|
|
17
17
|
post: async (url, body, config) => {
|
|
18
18
|
return acTransform(axios.post(url, body, {
|
|
19
19
|
headers: config?.headers,
|
|
20
|
-
validateStatus: (
|
|
20
|
+
validateStatus: () => true,
|
|
21
21
|
}));
|
|
22
22
|
},
|
|
23
23
|
patch: async (url, body, config) => {
|
|
24
24
|
return acTransform(axios.patch(url, body, {
|
|
25
25
|
headers: config?.headers,
|
|
26
|
-
validateStatus: (
|
|
26
|
+
validateStatus: () => true,
|
|
27
27
|
}));
|
|
28
28
|
},
|
|
29
29
|
delete: async (url, config) => {
|
|
30
30
|
return acTransform(axios.delete(url, {
|
|
31
31
|
headers: config?.headers,
|
|
32
|
-
validateStatus: (
|
|
32
|
+
validateStatus: () => true,
|
|
33
33
|
}));
|
|
34
34
|
},
|
|
35
35
|
};
|
package/dist/mjs/BaseCon.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THIS FILE IS AUTOMATICALLY GENERATED
|
|
3
|
-
* DO NOT EDIT THIS FILE
|
|
4
|
-
*/
|
|
5
1
|
export type ErrorType = {
|
|
6
2
|
type: string;
|
|
7
3
|
global?: string[];
|
|
@@ -139,7 +135,7 @@ export default class BaseCon {
|
|
|
139
135
|
* @returns {void}
|
|
140
136
|
*/
|
|
141
137
|
forceConnect(token: string | null): void;
|
|
142
|
-
|
|
138
|
+
copyFrom(con: BaseCon): void;
|
|
143
139
|
/**
|
|
144
140
|
* Establishes a connection to the backend using the supplied credentials.
|
|
145
141
|
* Performs a health‑check ping first; if successful, it requests an authentication
|
package/dist/mjs/BaseCon.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THIS FILE IS AUTOMATICALLY GENERATED
|
|
3
|
-
* DO NOT EDIT THIS FILE
|
|
4
|
-
*/
|
|
5
1
|
import FormData from 'form-data';
|
|
6
2
|
export function isErrorType(x) {
|
|
7
3
|
return x && typeof x === 'object' && x.type === 'error';
|
|
@@ -82,7 +78,7 @@ export default class BaseCon {
|
|
|
82
78
|
if (config?.param) {
|
|
83
79
|
const e = Object.keys(config.param);
|
|
84
80
|
for (const d of e) {
|
|
85
|
-
pp = pp.replace(`{${d}}`, `${config.param[d]}`);
|
|
81
|
+
pp = pp.replace(`{${d}}`, encodeURIComponent(`${config.param[d]}`));
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
if (config?.query) {
|
|
@@ -90,7 +86,7 @@ export default class BaseCon {
|
|
|
90
86
|
const slices = [];
|
|
91
87
|
for (const d of e) {
|
|
92
88
|
if (config.query[d]) {
|
|
93
|
-
slices.push(`${d}=${config.query[d]}`);
|
|
89
|
+
slices.push(`${encodeURIComponent(d)}=${encodeURIComponent(`${config.query[d]}`)}`);
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
92
|
if (slices.length > 0) {
|
|
@@ -196,7 +192,7 @@ export default class BaseCon {
|
|
|
196
192
|
this.disconnected = false;
|
|
197
193
|
this.noAuth = token === null;
|
|
198
194
|
}
|
|
199
|
-
|
|
195
|
+
copyFrom(con) {
|
|
200
196
|
this.authorization = con.authorization;
|
|
201
197
|
this.disconnected = con.disconnected;
|
|
202
198
|
this.noAuth = con.noAuth;
|
|
@@ -357,6 +353,7 @@ export default class BaseCon {
|
|
|
357
353
|
case 498:
|
|
358
354
|
x = await this.reconnect();
|
|
359
355
|
if (x) {
|
|
356
|
+
// onReconnect is intentionally fire-and-forget; the retry proceeds immediately
|
|
360
357
|
this.onReconnect(this).catch((dx) => {
|
|
361
358
|
this.logger(dx);
|
|
362
359
|
});
|
package/dist/mjs/ConMerger.js
CHANGED
|
@@ -2,7 +2,7 @@ export default function ConMerger(conA, conB) {
|
|
|
2
2
|
const prop = Object.getPrototypeOf(conB);
|
|
3
3
|
const propertyNames = Object.getOwnPropertyNames(prop);
|
|
4
4
|
for (const key of propertyNames) {
|
|
5
|
-
if (key !== 'constructor' && !conA
|
|
5
|
+
if (key !== 'constructor' && !(key in conA)) {
|
|
6
6
|
conA[key] = prop[key];
|
|
7
7
|
}
|
|
8
8
|
}
|
package/dist/mjs/NodeCon.js
CHANGED
|
@@ -10,16 +10,17 @@ function selectClient(url) {
|
|
|
10
10
|
async function fcTransform(message, raw) {
|
|
11
11
|
let data = null;
|
|
12
12
|
if (message.headers['content-type']?.includes('application/json')) {
|
|
13
|
-
data = JSON.parse(raw);
|
|
13
|
+
data = JSON.parse(raw.toString('utf8'));
|
|
14
14
|
}
|
|
15
15
|
else if (message.headers['content-type']?.includes('form-data')) {
|
|
16
|
-
data
|
|
16
|
+
// form-data response parsing is not supported in NodeCon
|
|
17
|
+
data = null;
|
|
17
18
|
}
|
|
18
19
|
else if (message.headers['content-type']?.includes('octet-stream')) {
|
|
19
|
-
data =
|
|
20
|
+
data = raw;
|
|
20
21
|
}
|
|
21
22
|
else if (message.headers['content-type']?.startsWith('text/')) {
|
|
22
|
-
data =
|
|
23
|
+
data = raw.toString('utf8');
|
|
23
24
|
}
|
|
24
25
|
return {
|
|
25
26
|
code: message.statusCode || -1,
|
|
@@ -39,7 +40,7 @@ function bodyTransform(r, headers) {
|
|
|
39
40
|
body: r,
|
|
40
41
|
headers: {
|
|
41
42
|
...headers,
|
|
42
|
-
|
|
43
|
+
...r.getHeaders(),
|
|
43
44
|
},
|
|
44
45
|
};
|
|
45
46
|
}
|
|
@@ -73,18 +74,16 @@ async function makeRequest(url, option, body, config) {
|
|
|
73
74
|
headers,
|
|
74
75
|
...option,
|
|
75
76
|
}, (res) => {
|
|
76
|
-
|
|
77
|
-
// A chunk of data has been received.
|
|
77
|
+
const chunks = [];
|
|
78
78
|
res.on('data', (chunk) => {
|
|
79
|
-
|
|
79
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
80
80
|
});
|
|
81
|
-
// The whole response has been received. Print out the result.
|
|
82
81
|
res.on('end', () => {
|
|
83
|
-
resolve(fcTransform(res,
|
|
82
|
+
resolve(fcTransform(res, Buffer.concat(chunks)));
|
|
84
83
|
});
|
|
85
84
|
})
|
|
86
85
|
.on('error', (err) => {
|
|
87
|
-
console.
|
|
86
|
+
console.error(`NodeCon request error: ${err.message}`);
|
|
88
87
|
resolve({
|
|
89
88
|
code: -1,
|
|
90
89
|
data: null,
|
package/dist/mjs/index.d.ts
CHANGED
package/dist/mjs/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/base-con",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"lint": "eslint src"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"axios": ">=1.
|
|
30
|
+
"axios": ">=1.16.1",
|
|
31
31
|
"form-data": ">=4.0.5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@grandlinex/core": "1.3.1",
|
|
35
|
-
"axios": "1.
|
|
35
|
+
"axios": "1.16.1",
|
|
36
36
|
"node-fetch": "3.3.2",
|
|
37
37
|
"cross-env": "10.0.0",
|
|
38
38
|
"@types/express": "5.0.6",
|