@ouroboros/body 1.0.5 → 1.1.1
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/{src → build}/index.d.ts +14 -3
- package/{src → build}/index.js +20 -6
- package/package.json +12 -11
- package/src/index.ts +20 -4
- package/src/types/xhr2.d.ts +3 -0
- /package/{src → build}/Service.d.ts +0 -0
- /package/{src → build}/Service.js +0 -0
- /package/{src → build}/constants.d.ts +0 -0
- /package/{src → build}/constants.js +0 -0
- /package/{src → build}/errors.d.ts +0 -0
- /package/{src → build}/errors.js +0 -0
- /package/{src → build}/regex.d.ts +0 -0
- /package/{src → build}/regex.js +0 -0
package/{src → build}/index.d.ts
RENAMED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @copyright Ouroboros Coding Inc.
|
|
8
8
|
* @created 2023-03-03
|
|
9
9
|
*/
|
|
10
|
+
import XMLHttpRequest from 'xhr2';
|
|
10
11
|
import * as constants from './constants';
|
|
11
12
|
import * as errors from './errors';
|
|
12
13
|
import * as regex from './regex';
|
|
@@ -60,7 +61,7 @@ export type responseReject = (error: responseErrorStruct) => boolean;
|
|
|
60
61
|
* @name Body
|
|
61
62
|
*/
|
|
62
63
|
declare class Body {
|
|
63
|
-
|
|
64
|
+
private _domain;
|
|
64
65
|
private error;
|
|
65
66
|
private errorCode;
|
|
66
67
|
private noSession;
|
|
@@ -69,6 +70,16 @@ declare class Body {
|
|
|
69
70
|
private token;
|
|
70
71
|
private verbose;
|
|
71
72
|
private warning;
|
|
73
|
+
/**
|
|
74
|
+
* Domain
|
|
75
|
+
*
|
|
76
|
+
* Set the domain
|
|
77
|
+
*
|
|
78
|
+
* @name domain
|
|
79
|
+
* @access public
|
|
80
|
+
* @param domain The name of the domain to connect to
|
|
81
|
+
*/
|
|
82
|
+
domain(domain: string): void;
|
|
72
83
|
/**
|
|
73
84
|
* Request
|
|
74
85
|
*
|
|
@@ -126,9 +137,9 @@ declare class Body {
|
|
|
126
137
|
*/
|
|
127
138
|
onError(callback: onError): void;
|
|
128
139
|
/**
|
|
129
|
-
* On
|
|
140
|
+
* On Error Code
|
|
130
141
|
*
|
|
131
|
-
* Sets callback for whenever a request gets
|
|
142
|
+
* Sets callback for whenever a request gets an error back
|
|
132
143
|
*
|
|
133
144
|
* @name onNoSession
|
|
134
145
|
* @access public
|
package/{src → build}/index.js
RENAMED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* @copyright Ouroboros Coding Inc.
|
|
8
8
|
* @created 2023-03-03
|
|
9
9
|
*/
|
|
10
|
+
// NPM modules
|
|
11
|
+
import XMLHttpRequest from 'xhr2';
|
|
10
12
|
// Import const files
|
|
11
13
|
import * as constants from './constants';
|
|
12
14
|
import * as errors from './errors';
|
|
@@ -31,7 +33,7 @@ const ACTIONS_TO_METHODS = {
|
|
|
31
33
|
*/
|
|
32
34
|
class Body {
|
|
33
35
|
// The domain used to make requests to
|
|
34
|
-
|
|
36
|
+
_domain = '';
|
|
35
37
|
// The function to call for http and related errors that need to be reported
|
|
36
38
|
error = null;
|
|
37
39
|
// The function to call if we get body errors
|
|
@@ -49,6 +51,18 @@ class Body {
|
|
|
49
51
|
verbose = false;
|
|
50
52
|
// The function to call if we get body warnings
|
|
51
53
|
warning = null;
|
|
54
|
+
/**
|
|
55
|
+
* Domain
|
|
56
|
+
*
|
|
57
|
+
* Set the domain
|
|
58
|
+
*
|
|
59
|
+
* @name domain
|
|
60
|
+
* @access public
|
|
61
|
+
* @param domain The name of the domain to connect to
|
|
62
|
+
*/
|
|
63
|
+
domain(domain) {
|
|
64
|
+
this._domain = domain;
|
|
65
|
+
}
|
|
52
66
|
/**
|
|
53
67
|
* Request
|
|
54
68
|
*
|
|
@@ -62,7 +76,7 @@ class Body {
|
|
|
62
76
|
*/
|
|
63
77
|
request(action, service, noun, data) {
|
|
64
78
|
// Generate the URL for the request
|
|
65
|
-
let url = `https://${this.
|
|
79
|
+
let url = `https://${this._domain}/${service}/${noun}`;
|
|
66
80
|
// Init the response object
|
|
67
81
|
let res;
|
|
68
82
|
// Set this
|
|
@@ -95,7 +109,7 @@ class Body {
|
|
|
95
109
|
handleError(`${ACTIONS_TO_METHODS[action]} ${url} failed to connect`);
|
|
96
110
|
});
|
|
97
111
|
// Handle successful request
|
|
98
|
-
xhr.addEventListener('load',
|
|
112
|
+
xhr.addEventListener('load', event => {
|
|
99
113
|
if (this.verbose) {
|
|
100
114
|
console.log(`xhr.load:\n\t${ACTIONS_TO_METHODS[action]} ${url}\n\t`, event);
|
|
101
115
|
}
|
|
@@ -144,7 +158,7 @@ class Body {
|
|
|
144
158
|
}
|
|
145
159
|
});
|
|
146
160
|
// Handle the request being finished
|
|
147
|
-
xhr.addEventListener('loadend',
|
|
161
|
+
xhr.addEventListener('loadend', event => {
|
|
148
162
|
if (this.verbose) {
|
|
149
163
|
console.log(`xhr.loadend:\n\t${ACTIONS_TO_METHODS[action]} ${url}\n\t`, event);
|
|
150
164
|
}
|
|
@@ -259,9 +273,9 @@ class Body {
|
|
|
259
273
|
this.error = callback;
|
|
260
274
|
}
|
|
261
275
|
/**
|
|
262
|
-
* On
|
|
276
|
+
* On Error Code
|
|
263
277
|
*
|
|
264
|
-
* Sets callback for whenever a request gets
|
|
278
|
+
* Sets callback for whenever a request gets an error back
|
|
265
279
|
*
|
|
266
280
|
* @name onNoSession
|
|
267
281
|
* @access public
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouroboros/body",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Classes to communicate with Ouroboros Coding Inc. body services",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
"build": "tslint -p tsconfig.json && tsc",
|
|
9
|
+
"clean": "rm build/*",
|
|
10
|
+
"for_local": "npm install; tslint -p tsconfig.json && tsc; rm -Rf node_modules",
|
|
11
|
+
"test": "echo \"Error: no test specified.\" && exit 1"
|
|
12
|
+
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/ouroboroscoding/body-js.git"
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"tslint-config-prettier": "^1.18.0",
|
|
29
29
|
"typescript": "^4.8.3"
|
|
30
30
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
|
|
33
|
-
}
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"xhr2": "^0.2.1"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* @created 2023-03-03
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
// NPM modules
|
|
12
|
+
import XMLHttpRequest from 'xhr2';
|
|
13
|
+
|
|
11
14
|
// Import const files
|
|
12
15
|
import * as constants from './constants';
|
|
13
16
|
import * as errors from './errors';
|
|
@@ -77,7 +80,7 @@ const ACTIONS_TO_METHODS = {
|
|
|
77
80
|
class Body {
|
|
78
81
|
|
|
79
82
|
// The domain used to make requests to
|
|
80
|
-
|
|
83
|
+
private _domain: string = '';
|
|
81
84
|
|
|
82
85
|
// The function to call for http and related errors that need to be reported
|
|
83
86
|
private error: onError | null = null;
|
|
@@ -104,6 +107,19 @@ class Body {
|
|
|
104
107
|
// The function to call if we get body warnings
|
|
105
108
|
private warning: onWarning | null = null;
|
|
106
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Domain
|
|
112
|
+
*
|
|
113
|
+
* Set the domain
|
|
114
|
+
*
|
|
115
|
+
* @name domain
|
|
116
|
+
* @access public
|
|
117
|
+
* @param domain The name of the domain to connect to
|
|
118
|
+
*/
|
|
119
|
+
domain(domain: string): void {
|
|
120
|
+
this._domain = domain;
|
|
121
|
+
}
|
|
122
|
+
|
|
107
123
|
/**
|
|
108
124
|
* Request
|
|
109
125
|
*
|
|
@@ -118,7 +134,7 @@ class Body {
|
|
|
118
134
|
request(action: actionOptions, service: string, noun: string, data: any): Promise<any> {
|
|
119
135
|
|
|
120
136
|
// Generate the URL for the request
|
|
121
|
-
let url = `https://${this.
|
|
137
|
+
let url = `https://${this._domain}/${service}/${noun}`;
|
|
122
138
|
|
|
123
139
|
// Init the response object
|
|
124
140
|
let res: responseStruct;
|
|
@@ -158,7 +174,7 @@ class Body {
|
|
|
158
174
|
});
|
|
159
175
|
|
|
160
176
|
// Handle successful request
|
|
161
|
-
xhr.addEventListener('load',
|
|
177
|
+
xhr.addEventListener('load', event => {
|
|
162
178
|
if(this.verbose) {
|
|
163
179
|
console.log(`xhr.load:\n\t${ACTIONS_TO_METHODS[action]} ${url}\n\t`, event);
|
|
164
180
|
}
|
|
@@ -219,7 +235,7 @@ class Body {
|
|
|
219
235
|
});
|
|
220
236
|
|
|
221
237
|
// Handle the request being finished
|
|
222
|
-
xhr.addEventListener('loadend',
|
|
238
|
+
xhr.addEventListener('loadend', event => {
|
|
223
239
|
if(this.verbose) {
|
|
224
240
|
console.log(`xhr.loadend:\n\t${ACTIONS_TO_METHODS[action]} ${url}\n\t`, event);
|
|
225
241
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → build}/errors.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/{src → build}/regex.js
RENAMED
|
File without changes
|