@smess/networking 1.0.4 → 1.0.6
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/index.d.ts +9 -9
- package/dist/index.js +11 -31
- package/dist/scripts/real-test.js +60 -65
- package/dist/src/core/axios.d.ts +5 -12
- package/dist/src/core/axios.js +21 -24
- package/dist/src/core/axios.observable.d.ts +2 -2
- package/dist/src/core/axios.observable.js +14 -17
- package/dist/src/core/base.provider.advanced.test.js +3 -5
- package/dist/src/core/base.provider.d.ts +1 -1
- package/dist/src/core/base.provider.js +6 -6
- package/dist/src/core/base.provider.test.js +3 -5
- package/dist/src/core/base.service.wrapper.advanced.test.js +9 -11
- package/dist/src/core/base.service.wrapper.d.ts +1 -1
- package/dist/src/core/base.service.wrapper.js +3 -7
- package/dist/src/core/base.service.wrapper.test.js +6 -8
- package/dist/src/core/rx.http.service.d.ts +5 -12
- package/dist/src/core/rx.http.service.js +21 -24
- package/dist/src/services/auth.service.d.ts +2 -2
- package/dist/src/services/auth.service.js +10 -15
- package/dist/src/services/auth.service.test.js +37 -39
- package/dist/src/services/customer.service.d.ts +2 -2
- package/dist/src/services/customer.service.js +9 -14
- package/dist/src/services/customer.service.test.js +23 -25
- package/dist/src/services/logger.service.js +4 -8
- package/dist/src/services/logger.service.test.js +16 -18
- package/dist/src/services/order.service.d.ts +2 -2
- package/dist/src/services/order.service.js +9 -14
- package/dist/src/services/order.service.test.js +41 -43
- package/dist/src/services/product.service.d.ts +6 -6
- package/dist/src/services/product.service.js +4 -9
- package/dist/src/services/product.service.test.js +20 -21
- package/dist/src/services/smess.service.d.ts +2 -2
- package/dist/src/services/smess.service.js +26 -34
- package/dist/src/services/smess.service.test.js +21 -24
- package/dist/src/services/store.service.d.ts +2 -2
- package/dist/src/services/store.service.js +9 -14
- package/dist/src/services/store.service.test.js +35 -37
- package/dist/src/services/user.service.d.ts +5 -5
- package/dist/src/services/user.service.js +4 -9
- package/dist/src/services/user.service.test.js +17 -18
- package/dist/src/types/types.js +6 -13
- package/dist/src/types/types.test.js +5 -7
- package/dist/src/utils/networking-import.js +3 -43
- package/dist/src/utils/rxjs-import.js +5 -34
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './src/services/user.service';
|
|
2
|
-
export * from './src/services/product.service';
|
|
3
|
-
export * from './src/services/auth.service';
|
|
4
|
-
export * from './src/services/smess.service';
|
|
5
|
-
export * from './src/core/base.provider';
|
|
6
|
-
export * from './src/core/base.service.wrapper';
|
|
7
|
-
export * from './src/core/axios.observable';
|
|
8
|
-
export * from './src/types/types';
|
|
9
|
-
export { $logger } from './src/services/logger.service';
|
|
1
|
+
export * from './src/services/user.service.js';
|
|
2
|
+
export * from './src/services/product.service.js';
|
|
3
|
+
export * from './src/services/auth.service.js';
|
|
4
|
+
export * from './src/services/smess.service.js';
|
|
5
|
+
export * from './src/core/base.provider.js';
|
|
6
|
+
export * from './src/core/base.service.wrapper.js';
|
|
7
|
+
export * from './src/core/axios.observable.js';
|
|
8
|
+
export * from './src/types/types.js';
|
|
9
|
+
export { $logger } from './src/services/logger.service.js';
|
|
10
10
|
export declare const baseURL: () => string;
|
|
11
11
|
export declare const apiVersion: () => string;
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.apiVersion = exports.baseURL = exports.$logger = void 0;
|
|
18
|
-
__exportStar(require("./src/services/user.service"), exports);
|
|
19
|
-
__exportStar(require("./src/services/product.service"), exports);
|
|
20
|
-
__exportStar(require("./src/services/auth.service"), exports);
|
|
21
|
-
__exportStar(require("./src/services/smess.service"), exports);
|
|
22
|
-
__exportStar(require("./src/core/base.provider"), exports);
|
|
23
|
-
__exportStar(require("./src/core/base.service.wrapper"), exports);
|
|
24
|
-
__exportStar(require("./src/core/axios.observable"), exports);
|
|
25
|
-
__exportStar(require("./src/types/types"), exports);
|
|
26
|
-
var logger_service_1 = require("./src/services/logger.service");
|
|
27
|
-
Object.defineProperty(exports, "$logger", { enumerable: true, get: function () { return logger_service_1.$logger; } });
|
|
28
|
-
const baseURL = () => {
|
|
1
|
+
export * from './src/services/user.service.js';
|
|
2
|
+
export * from './src/services/product.service.js';
|
|
3
|
+
export * from './src/services/auth.service.js';
|
|
4
|
+
export * from './src/services/smess.service.js';
|
|
5
|
+
export * from './src/core/base.provider.js';
|
|
6
|
+
export * from './src/core/base.service.wrapper.js';
|
|
7
|
+
export * from './src/core/axios.observable.js';
|
|
8
|
+
export * from './src/types/types.js';
|
|
9
|
+
export { $logger } from './src/services/logger.service.js';
|
|
10
|
+
export const baseURL = () => {
|
|
29
11
|
return '';
|
|
30
12
|
};
|
|
31
|
-
|
|
32
|
-
const apiVersion = () => {
|
|
13
|
+
export const apiVersion = () => {
|
|
33
14
|
return 'api/v1';
|
|
34
15
|
};
|
|
35
|
-
exports.apiVersion = apiVersion;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const auth_service_1 = require("../src/services/auth.service");
|
|
10
|
-
const customer_service_1 = require("../src/services/customer.service");
|
|
11
|
-
const store_service_1 = require("../src/services/store.service");
|
|
12
|
-
const logger_service_1 = require("../src/services/logger.service");
|
|
1
|
+
import { UserService } from '../src/services/user.service.js';
|
|
2
|
+
import { timeout, catchError, of, BehaviorSubject } from 'rxjs';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { AuthService } from "../src/services/auth.service.js";
|
|
5
|
+
import { CustomerService } from "../src/services/customer.service.js";
|
|
6
|
+
import { StoreService } from "../src/services/store.service.js";
|
|
7
|
+
import { $logger } from '../src/services/logger.service.js';
|
|
13
8
|
function isNetworkingUIEventWrapped(val) {
|
|
14
9
|
return (typeof val === 'object' &&
|
|
15
10
|
val !== null &&
|
|
@@ -24,35 +19,35 @@ async function testAuthService() {
|
|
|
24
19
|
isProd: true,
|
|
25
20
|
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
26
21
|
};
|
|
27
|
-
const $authToken = new
|
|
28
|
-
const authService = new
|
|
22
|
+
const $authToken = new BehaviorSubject(null);
|
|
23
|
+
const authService = new AuthService(config, $authToken);
|
|
29
24
|
let emitted = false;
|
|
30
25
|
try {
|
|
31
|
-
const obs$ = authService.login({ identifier: 'test@email.org', password: 'PassWord123' }).pipe(
|
|
32
|
-
|
|
33
|
-
return
|
|
26
|
+
const obs$ = authService.login({ identifier: 'test@email.org', password: 'PassWord123' }).pipe(timeout({ first: 10000 }), catchError(err => {
|
|
27
|
+
$logger.error('❌ AuthService observable error', err, 'real-test');
|
|
28
|
+
return of(undefined);
|
|
34
29
|
}));
|
|
35
30
|
await new Promise((resolve, reject) => {
|
|
36
31
|
obs$.subscribe({
|
|
37
32
|
next: (val) => {
|
|
38
33
|
emitted = true;
|
|
39
|
-
|
|
34
|
+
$logger.info('AuthService emission', val, 'real-test');
|
|
40
35
|
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
41
|
-
|
|
36
|
+
$logger.info('✅ AuthService real API test succeeded', val.response, 'real-test');
|
|
42
37
|
resolve(undefined);
|
|
43
38
|
}
|
|
44
39
|
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
45
|
-
|
|
40
|
+
$logger.error('❌ AuthService real API test failed', val.alertModel || val, 'real-test');
|
|
46
41
|
reject(new Error('AuthService failed'));
|
|
47
42
|
}
|
|
48
43
|
},
|
|
49
44
|
error: (err) => {
|
|
50
|
-
|
|
45
|
+
$logger.error('❌ AuthService observable error', err, 'real-test');
|
|
51
46
|
reject(err);
|
|
52
47
|
},
|
|
53
48
|
complete: () => {
|
|
54
49
|
if (!emitted) {
|
|
55
|
-
|
|
50
|
+
$logger.error('❌ AuthService observable completed without emission', undefined, 'real-test');
|
|
56
51
|
reject(new Error('No emission'));
|
|
57
52
|
}
|
|
58
53
|
}
|
|
@@ -60,7 +55,7 @@ async function testAuthService() {
|
|
|
60
55
|
});
|
|
61
56
|
}
|
|
62
57
|
catch (err) {
|
|
63
|
-
|
|
58
|
+
$logger.error('❌ AuthService test error', err, 'real-test');
|
|
64
59
|
process.exit(2);
|
|
65
60
|
}
|
|
66
61
|
}
|
|
@@ -69,34 +64,34 @@ async function testUserService() {
|
|
|
69
64
|
baseUrl: 'https://jsonplaceholder.typicode.com',
|
|
70
65
|
isProd: false,
|
|
71
66
|
};
|
|
72
|
-
const userService = new
|
|
67
|
+
const userService = new UserService(config);
|
|
73
68
|
let emitted = false;
|
|
74
69
|
try {
|
|
75
|
-
const obs$ = userService.fetchUserById(1).pipe(
|
|
76
|
-
|
|
77
|
-
return
|
|
70
|
+
const obs$ = userService.fetchUserById(1).pipe(timeout({ first: 10000 }), catchError(err => {
|
|
71
|
+
$logger.error('❌ UserService observable error', err, 'real-test');
|
|
72
|
+
return of(undefined);
|
|
78
73
|
}));
|
|
79
74
|
await new Promise((resolve, reject) => {
|
|
80
75
|
obs$.subscribe({
|
|
81
76
|
next: (val) => {
|
|
82
77
|
emitted = true;
|
|
83
|
-
|
|
78
|
+
$logger.info('UserService emission', val, 'real-test');
|
|
84
79
|
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
85
|
-
|
|
80
|
+
$logger.info('✅ UserService real API test succeeded', val.response, 'real-test');
|
|
86
81
|
resolve(undefined);
|
|
87
82
|
}
|
|
88
83
|
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
89
|
-
|
|
84
|
+
$logger.error('❌ UserService real API test failed', val.alertModel || val, 'real-test');
|
|
90
85
|
reject(new Error('UserService failed'));
|
|
91
86
|
}
|
|
92
87
|
},
|
|
93
88
|
error: (err) => {
|
|
94
|
-
|
|
89
|
+
$logger.error('❌ UserService observable error', err, 'real-test');
|
|
95
90
|
reject(err);
|
|
96
91
|
},
|
|
97
92
|
complete: () => {
|
|
98
93
|
if (!emitted) {
|
|
99
|
-
|
|
94
|
+
$logger.error('❌ UserService observable completed without emission', undefined, 'real-test');
|
|
100
95
|
reject(new Error('No emission'));
|
|
101
96
|
}
|
|
102
97
|
}
|
|
@@ -104,7 +99,7 @@ async function testUserService() {
|
|
|
104
99
|
});
|
|
105
100
|
}
|
|
106
101
|
catch (err) {
|
|
107
|
-
|
|
102
|
+
$logger.error('❌ UserService test error', err, 'real-test');
|
|
108
103
|
process.exit(2);
|
|
109
104
|
}
|
|
110
105
|
}
|
|
@@ -115,8 +110,8 @@ async function testCustomerRegister() {
|
|
|
115
110
|
isProd: true,
|
|
116
111
|
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
117
112
|
};
|
|
118
|
-
const $authToken = new
|
|
119
|
-
const customerService = new
|
|
113
|
+
const $authToken = new BehaviorSubject(null);
|
|
114
|
+
const customerService = new CustomerService(config, $authToken);
|
|
120
115
|
const random = Math.floor(Math.random() * 1000000);
|
|
121
116
|
const payload = {
|
|
122
117
|
email: `realtest+${random}@email.org`,
|
|
@@ -126,31 +121,31 @@ async function testCustomerRegister() {
|
|
|
126
121
|
};
|
|
127
122
|
let emitted = false;
|
|
128
123
|
try {
|
|
129
|
-
const obs$ = customerService.register(payload).pipe(
|
|
130
|
-
|
|
131
|
-
return
|
|
124
|
+
const obs$ = customerService.register(payload).pipe(timeout({ first: 10000 }), catchError(err => {
|
|
125
|
+
$logger.error('❌ CustomerService observable error', err, 'real-test');
|
|
126
|
+
return of(undefined);
|
|
132
127
|
}));
|
|
133
128
|
await new Promise((resolve, reject) => {
|
|
134
129
|
obs$.subscribe({
|
|
135
130
|
next: (val) => {
|
|
136
131
|
emitted = true;
|
|
137
|
-
|
|
132
|
+
$logger.info('CustomerService emission', val, 'real-test');
|
|
138
133
|
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
139
|
-
|
|
134
|
+
$logger.info('✅ CustomerService real API test succeeded', val.response, 'real-test');
|
|
140
135
|
resolve(undefined);
|
|
141
136
|
}
|
|
142
137
|
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
143
|
-
|
|
138
|
+
$logger.error('❌ CustomerService real API test failed', val.alertModel || val, 'real-test');
|
|
144
139
|
reject(new Error('CustomerService failed'));
|
|
145
140
|
}
|
|
146
141
|
},
|
|
147
142
|
error: (err) => {
|
|
148
|
-
|
|
143
|
+
$logger.error('❌ CustomerService observable error', err, 'real-test');
|
|
149
144
|
reject(err);
|
|
150
145
|
},
|
|
151
146
|
complete: () => {
|
|
152
147
|
if (!emitted) {
|
|
153
|
-
|
|
148
|
+
$logger.error('❌ CustomerService observable completed without emission', undefined, 'real-test');
|
|
154
149
|
reject(new Error('No emission'));
|
|
155
150
|
}
|
|
156
151
|
}
|
|
@@ -158,7 +153,7 @@ async function testCustomerRegister() {
|
|
|
158
153
|
});
|
|
159
154
|
}
|
|
160
155
|
catch (err) {
|
|
161
|
-
|
|
156
|
+
$logger.error('❌ CustomerService test error', err, 'real-test');
|
|
162
157
|
process.exit(2);
|
|
163
158
|
}
|
|
164
159
|
}
|
|
@@ -169,8 +164,8 @@ async function testStoreProductCollection() {
|
|
|
169
164
|
isProd: true,
|
|
170
165
|
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
171
166
|
};
|
|
172
|
-
const $authToken = new
|
|
173
|
-
const storeService = new
|
|
167
|
+
const $authToken = new BehaviorSubject(null);
|
|
168
|
+
const storeService = new StoreService(config, $authToken);
|
|
174
169
|
const storeId = 'f1df6e9a-0160-11f0-82c2-6cac1a7e2953'; // Use a real or test store id as appropriate
|
|
175
170
|
const payload = {
|
|
176
171
|
page: 1,
|
|
@@ -179,31 +174,31 @@ async function testStoreProductCollection() {
|
|
|
179
174
|
};
|
|
180
175
|
let emitted = false;
|
|
181
176
|
try {
|
|
182
|
-
const obs$ = storeService.productCollection(storeId, payload).pipe(
|
|
183
|
-
|
|
184
|
-
return
|
|
177
|
+
const obs$ = storeService.productCollection(storeId, payload).pipe(timeout({ first: 10000 }), catchError(err => {
|
|
178
|
+
$logger.error('❌ StoreService.productCollection observable error', err, 'real-test');
|
|
179
|
+
return of(undefined);
|
|
185
180
|
}));
|
|
186
181
|
await new Promise((resolve, reject) => {
|
|
187
182
|
obs$.subscribe({
|
|
188
183
|
next: (val) => {
|
|
189
184
|
emitted = true;
|
|
190
|
-
|
|
185
|
+
$logger.info('StoreService.productCollection emission', val, 'real-test');
|
|
191
186
|
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
192
|
-
|
|
187
|
+
$logger.info('✅ StoreService.productCollection real API test succeeded', val.response, 'real-test');
|
|
193
188
|
resolve(undefined);
|
|
194
189
|
}
|
|
195
190
|
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
196
|
-
|
|
191
|
+
$logger.error('❌ StoreService.productCollection real API test failed', val.alertModel || val, 'real-test');
|
|
197
192
|
reject(new Error('StoreService.productCollection failed'));
|
|
198
193
|
}
|
|
199
194
|
},
|
|
200
195
|
error: (err) => {
|
|
201
|
-
|
|
196
|
+
$logger.error('❌ StoreService.productCollection observable error', err, 'real-test');
|
|
202
197
|
reject(err);
|
|
203
198
|
},
|
|
204
199
|
complete: () => {
|
|
205
200
|
if (!emitted) {
|
|
206
|
-
|
|
201
|
+
$logger.error('❌ StoreService.productCollection observable completed without emission', undefined, 'real-test');
|
|
207
202
|
reject(new Error('No emission'));
|
|
208
203
|
}
|
|
209
204
|
}
|
|
@@ -211,37 +206,37 @@ async function testStoreProductCollection() {
|
|
|
211
206
|
});
|
|
212
207
|
}
|
|
213
208
|
catch (err) {
|
|
214
|
-
|
|
209
|
+
$logger.error('❌ StoreService.productCollection test error', err, 'real-test');
|
|
215
210
|
process.exit(2);
|
|
216
211
|
}
|
|
217
212
|
}
|
|
218
213
|
async function testAxiosDirect() {
|
|
219
214
|
try {
|
|
220
|
-
const response = await
|
|
215
|
+
const response = await axios.get('https://jsonplaceholder.typicode.com/users/1');
|
|
221
216
|
if (response && response.data && response.data.id === 1) {
|
|
222
|
-
|
|
217
|
+
$logger.info('✅ Direct axios test succeeded', response.data, 'real-test');
|
|
223
218
|
}
|
|
224
219
|
else {
|
|
225
|
-
|
|
220
|
+
$logger.error('❌ Direct axios test failed', response.data, 'real-test');
|
|
226
221
|
process.exit(3);
|
|
227
222
|
}
|
|
228
223
|
}
|
|
229
224
|
catch (err) {
|
|
230
|
-
|
|
225
|
+
$logger.error('❌ Direct axios test error', err, 'real-test');
|
|
231
226
|
process.exit(4);
|
|
232
227
|
}
|
|
233
228
|
}
|
|
234
229
|
(async () => {
|
|
235
230
|
await testAxiosDirect();
|
|
236
|
-
|
|
231
|
+
$logger.info('✅ Direct axios test passed!', undefined, 'real-test');
|
|
237
232
|
await testAuthService();
|
|
238
|
-
|
|
233
|
+
$logger.info('✅ AuthService real API tests passed!', undefined, 'real-test');
|
|
239
234
|
await testUserService();
|
|
240
|
-
|
|
235
|
+
$logger.info('✅ UserService real API tests passed!', undefined, 'real-test');
|
|
241
236
|
await testCustomerRegister();
|
|
242
|
-
|
|
237
|
+
$logger.info('✅ CustomerService real API register test passed!', undefined, 'real-test');
|
|
243
238
|
await testStoreProductCollection();
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
$logger.info('✅ StoreService.productCollection real API test passed!', undefined, 'real-test');
|
|
240
|
+
$logger.info('🎉 All real API tests passed!', undefined, 'real-test');
|
|
246
241
|
process.exit(0);
|
|
247
242
|
})();
|
package/dist/src/core/axios.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from '../utils/networking-import.js';
|
|
2
2
|
import type { AxiosInterceptorManager } from 'axios';
|
|
3
|
-
import { AxiosObservable } from './axios.observable';
|
|
3
|
+
import { AxiosObservable } from './axios.observable.js';
|
|
4
4
|
export interface Axiosable {
|
|
5
5
|
request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
6
6
|
get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
@@ -21,16 +21,9 @@ declare class Axios implements Axiosable {
|
|
|
21
21
|
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
22
22
|
response: AxiosInterceptorManager<AxiosResponse>;
|
|
23
23
|
};
|
|
24
|
-
constructor(axiosInstance:
|
|
25
|
-
get defaults():
|
|
26
|
-
|
|
27
|
-
[key: string]: import("axios").AxiosHeaderValue;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
get interceptors(): {
|
|
31
|
-
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
32
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
33
|
-
};
|
|
24
|
+
constructor(axiosInstance: any);
|
|
25
|
+
get defaults(): any;
|
|
26
|
+
get interceptors(): any;
|
|
34
27
|
static request<T = any>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
35
28
|
static get<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
36
29
|
static post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
package/dist/src/core/axios.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Axios = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { axios } from '../utils/networking-import.js';
|
|
3
|
+
import { createObservable } from './axios.observable.js';
|
|
7
4
|
class Axios {
|
|
8
5
|
constructor(axiosInstance) {
|
|
9
6
|
this.axiosInstance = axiosInstance;
|
|
@@ -16,53 +13,53 @@ class Axios {
|
|
|
16
13
|
}
|
|
17
14
|
// ----- Static Methods -----
|
|
18
15
|
static request(config) {
|
|
19
|
-
return
|
|
16
|
+
return createObservable(axios.request, [config]);
|
|
20
17
|
}
|
|
21
18
|
static get(url, config) {
|
|
22
|
-
return
|
|
19
|
+
return createObservable(axios.get, [url, config]);
|
|
23
20
|
}
|
|
24
21
|
static post(url, data, config) {
|
|
25
|
-
return
|
|
22
|
+
return createObservable(axios.post, [url, data, config]);
|
|
26
23
|
}
|
|
27
24
|
static put(url, data, config) {
|
|
28
|
-
return
|
|
25
|
+
return createObservable(axios.put, [url, data, config]);
|
|
29
26
|
}
|
|
30
27
|
static patch(url, data, config) {
|
|
31
|
-
return
|
|
28
|
+
return createObservable(axios.patch, [url, data, config]);
|
|
32
29
|
}
|
|
33
30
|
static delete(url, config) {
|
|
34
|
-
return
|
|
31
|
+
return createObservable(axios.delete, [url, config]);
|
|
35
32
|
}
|
|
36
33
|
static head(url, config) {
|
|
37
|
-
return
|
|
34
|
+
return createObservable(axios.head, [url, config]);
|
|
38
35
|
}
|
|
39
36
|
static create(config) {
|
|
40
|
-
return new Axios(
|
|
37
|
+
return new Axios(axios.create(config));
|
|
41
38
|
}
|
|
42
39
|
// ----- Instance Methods -----
|
|
43
40
|
request(config) {
|
|
44
|
-
return
|
|
41
|
+
return createObservable(this.axiosInstance.request, [config]);
|
|
45
42
|
}
|
|
46
43
|
get(url, config) {
|
|
47
|
-
return
|
|
44
|
+
return createObservable(this.axiosInstance.get, [url, config]);
|
|
48
45
|
}
|
|
49
46
|
head(url, config) {
|
|
50
|
-
return
|
|
47
|
+
return createObservable(this.axiosInstance.head, [url, config]);
|
|
51
48
|
}
|
|
52
49
|
post(url, data, config) {
|
|
53
|
-
return
|
|
50
|
+
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
54
51
|
}
|
|
55
52
|
put(url, data, config) {
|
|
56
|
-
return
|
|
53
|
+
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
57
54
|
}
|
|
58
55
|
patch(url, data, config) {
|
|
59
|
-
return
|
|
56
|
+
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
60
57
|
}
|
|
61
58
|
delete(url, config) {
|
|
62
|
-
return
|
|
59
|
+
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
Axios.
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
Axios.defaults = axios.defaults;
|
|
63
|
+
Axios.interceptors = axios.interceptors;
|
|
64
|
+
export default Axios;
|
|
65
|
+
export { Axios };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxiosResponse } from '../utils/networking-import';
|
|
1
|
+
import { AxiosResponse } from '../utils/networking-import.js';
|
|
2
2
|
import type { AxiosPromise } from 'axios';
|
|
3
|
-
import { Observable } from '../utils/rxjs-import';
|
|
3
|
+
import { Observable } from '../utils/rxjs-import.js';
|
|
4
4
|
export type AxiosObservable<T> = Observable<AxiosResponse<T>>;
|
|
5
5
|
interface ObservableOptions {
|
|
6
6
|
retry?: number;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createObservable = createObservable;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function createObservable(promiseFactory, args, options = {}) {
|
|
2
|
+
import { axios, } from '../utils/networking-import.js';
|
|
3
|
+
import { Observable, timeout as rxTimeout, retry as rxRetry, shareReplay, catchError, throwError, } from '../utils/rxjs-import.js';
|
|
4
|
+
import { $logger } from '../services/logger.service.js';
|
|
5
|
+
export function createObservable(promiseFactory, args, options = {}) {
|
|
9
6
|
let config = args[args.length - 1];
|
|
10
7
|
if (config && typeof config === 'object' && !Array.isArray(config)) {
|
|
11
|
-
config =
|
|
8
|
+
config = { ...config };
|
|
12
9
|
}
|
|
13
10
|
else {
|
|
14
11
|
config = {};
|
|
@@ -17,11 +14,11 @@ function createObservable(promiseFactory, args, options = {}) {
|
|
|
17
14
|
let cancelSource = null;
|
|
18
15
|
const hasCancelToken = !!config.cancelToken;
|
|
19
16
|
if (!hasCancelToken) {
|
|
20
|
-
|
|
17
|
+
$logger.warn('[Networking] You can omit cancelToken — unsubscribing cancels the request automatically.', undefined, 'axios.observable');
|
|
21
18
|
}
|
|
22
|
-
let source$ = new
|
|
19
|
+
let source$ = new Observable((subscriber) => {
|
|
23
20
|
if (!hasCancelToken) {
|
|
24
|
-
cancelSource =
|
|
21
|
+
cancelSource = axios.CancelToken.source();
|
|
25
22
|
config.cancelToken = cancelSource.token;
|
|
26
23
|
}
|
|
27
24
|
promiseFactory(...args)
|
|
@@ -42,20 +39,20 @@ function createObservable(promiseFactory, args, options = {}) {
|
|
|
42
39
|
});
|
|
43
40
|
// Add timeout if specified
|
|
44
41
|
if (options.timeoutMs) {
|
|
45
|
-
source$ = source$.pipe((
|
|
42
|
+
source$ = source$.pipe(rxTimeout(options.timeoutMs));
|
|
46
43
|
}
|
|
47
44
|
// Add retry logic
|
|
48
45
|
if (options.retry) {
|
|
49
|
-
source$ = source$.pipe((
|
|
46
|
+
source$ = source$.pipe(rxRetry(options.retry));
|
|
50
47
|
}
|
|
51
48
|
// Cache the response if needed
|
|
52
49
|
if (options.cache) {
|
|
53
|
-
source$ = source$.pipe(
|
|
50
|
+
source$ = source$.pipe(shareReplay({ bufferSize: 1, refCount: false }));
|
|
54
51
|
}
|
|
55
52
|
// Optional: Log or catch errors globally
|
|
56
|
-
source$ = source$.pipe(
|
|
57
|
-
|
|
58
|
-
return
|
|
53
|
+
source$ = source$.pipe(catchError((err) => {
|
|
54
|
+
$logger.error('[createObservable error]:', err, 'axios.observable');
|
|
55
|
+
return throwError(() => err);
|
|
59
56
|
}));
|
|
60
57
|
return source$;
|
|
61
58
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_provider_1 = require("./base.provider");
|
|
1
|
+
import { BaseProvider } from './base.provider.js';
|
|
4
2
|
describe('BaseProvider Advanced', () => {
|
|
5
3
|
const config = {
|
|
6
4
|
baseUrl: 'https://api.example.com',
|
|
@@ -9,7 +7,7 @@ describe('BaseProvider Advanced', () => {
|
|
|
9
7
|
apiKey: 'test-key',
|
|
10
8
|
};
|
|
11
9
|
it('should support dynamic getPath for multiple params', () => {
|
|
12
|
-
const provider = new
|
|
10
|
+
const provider = new BaseProvider({
|
|
13
11
|
config,
|
|
14
12
|
path: '/resource/:id/:action',
|
|
15
13
|
method: 'GET',
|
|
@@ -19,7 +17,7 @@ describe('BaseProvider Advanced', () => {
|
|
|
19
17
|
expect(provider.getPath('42', 'edit')).toBe('/resource/42/edit');
|
|
20
18
|
});
|
|
21
19
|
it('should allow dynamic headers and method', () => {
|
|
22
|
-
const provider = new
|
|
20
|
+
const provider = new BaseProvider({
|
|
23
21
|
config,
|
|
24
22
|
path: '/resource',
|
|
25
23
|
method: 'PATCH',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseProvider = void 0;
|
|
4
|
-
class BaseProvider {
|
|
1
|
+
export class BaseProvider {
|
|
5
2
|
constructor({ config, path, method, headers = {}, getPath = () => path, }) {
|
|
6
3
|
this.baseURL = config.baseUrl;
|
|
7
4
|
this.path = path;
|
|
8
5
|
this.method = method;
|
|
9
|
-
this.headers =
|
|
6
|
+
this.headers = {
|
|
7
|
+
...headers,
|
|
8
|
+
'X-Client-Id': config.clientId,
|
|
9
|
+
'X-Api-Key': config.apiKey,
|
|
10
|
+
};
|
|
10
11
|
this.getPath = getPath || (() => path);
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
exports.BaseProvider = BaseProvider;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_provider_1 = require("./base.provider");
|
|
1
|
+
import { BaseProvider } from './base.provider.js';
|
|
4
2
|
describe('BaseProvider', () => {
|
|
5
3
|
const config = {
|
|
6
4
|
baseUrl: 'https://api.example.com',
|
|
@@ -9,7 +7,7 @@ describe('BaseProvider', () => {
|
|
|
9
7
|
apiKey: 'test-key',
|
|
10
8
|
};
|
|
11
9
|
it('should construct with required fields', () => {
|
|
12
|
-
const provider = new
|
|
10
|
+
const provider = new BaseProvider({
|
|
13
11
|
config,
|
|
14
12
|
path: '/resource',
|
|
15
13
|
method: 'GET',
|
|
@@ -22,7 +20,7 @@ describe('BaseProvider', () => {
|
|
|
22
20
|
expect(provider.getPath()).toBe('/resource');
|
|
23
21
|
});
|
|
24
22
|
it('should use custom getPath if provided', () => {
|
|
25
|
-
const provider = new
|
|
23
|
+
const provider = new BaseProvider({
|
|
26
24
|
config,
|
|
27
25
|
path: '/resource/:id',
|
|
28
26
|
method: 'GET',
|