@smess/networking 1.0.3 → 1.0.5
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 +184 -23
- 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 +10 -8
- package/dist/src/services/auth.service.js +31 -35
- package/dist/src/services/auth.service.test.js +38 -38
- package/dist/src/services/customer.service.d.ts +43 -0
- package/dist/src/services/customer.service.js +70 -0
- package/dist/src/services/customer.service.test.d.ts +1 -0
- package/dist/src/services/customer.service.test.js +96 -0
- 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 +60 -0
- package/dist/src/services/order.service.js +89 -0
- package/dist/src/services/order.service.test.d.ts +1 -0
- package/dist/src/services/order.service.test.js +135 -0
- 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 +3 -2
- package/dist/src/services/smess.service.js +30 -39
- package/dist/src/services/smess.service.test.js +39 -46
- package/dist/src/services/store.service.d.ts +39 -0
- package/dist/src/services/store.service.js +73 -0
- package/dist/src/services/store.service.test.d.ts +1 -0
- package/dist/src/services/store.service.test.js +104 -0
- 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.d.ts +1 -3
- 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,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
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';
|
|
9
8
|
function isNetworkingUIEventWrapped(val) {
|
|
10
9
|
return (typeof val === 'object' &&
|
|
11
10
|
val !== null &&
|
|
@@ -13,39 +12,193 @@ function isNetworkingUIEventWrapped(val) {
|
|
|
13
12
|
'hasFailed' in val &&
|
|
14
13
|
'response' in val);
|
|
15
14
|
}
|
|
15
|
+
async function testAuthService() {
|
|
16
|
+
const config = {
|
|
17
|
+
baseUrl: 'https://api.smeservices.cloud',
|
|
18
|
+
version: 'api/v1',
|
|
19
|
+
isProd: true,
|
|
20
|
+
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
21
|
+
};
|
|
22
|
+
const $authToken = new BehaviorSubject(null);
|
|
23
|
+
const authService = new AuthService(config, $authToken);
|
|
24
|
+
let emitted = false;
|
|
25
|
+
try {
|
|
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);
|
|
29
|
+
}));
|
|
30
|
+
await new Promise((resolve, reject) => {
|
|
31
|
+
obs$.subscribe({
|
|
32
|
+
next: (val) => {
|
|
33
|
+
emitted = true;
|
|
34
|
+
$logger.info('AuthService emission', val, 'real-test');
|
|
35
|
+
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
36
|
+
$logger.info('✅ AuthService real API test succeeded', val.response, 'real-test');
|
|
37
|
+
resolve(undefined);
|
|
38
|
+
}
|
|
39
|
+
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
40
|
+
$logger.error('❌ AuthService real API test failed', val.alertModel || val, 'real-test');
|
|
41
|
+
reject(new Error('AuthService failed'));
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
error: (err) => {
|
|
45
|
+
$logger.error('❌ AuthService observable error', err, 'real-test');
|
|
46
|
+
reject(err);
|
|
47
|
+
},
|
|
48
|
+
complete: () => {
|
|
49
|
+
if (!emitted) {
|
|
50
|
+
$logger.error('❌ AuthService observable completed without emission', undefined, 'real-test');
|
|
51
|
+
reject(new Error('No emission'));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
$logger.error('❌ AuthService test error', err, 'real-test');
|
|
59
|
+
process.exit(2);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
16
62
|
async function testUserService() {
|
|
17
63
|
const config = {
|
|
18
64
|
baseUrl: 'https://jsonplaceholder.typicode.com',
|
|
19
65
|
isProd: false,
|
|
20
66
|
};
|
|
21
|
-
const userService = new
|
|
67
|
+
const userService = new UserService(config);
|
|
22
68
|
let emitted = false;
|
|
23
69
|
try {
|
|
24
|
-
const obs$ = userService.fetchUserById(1).pipe(
|
|
25
|
-
|
|
26
|
-
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);
|
|
27
73
|
}));
|
|
28
74
|
await new Promise((resolve, reject) => {
|
|
29
75
|
obs$.subscribe({
|
|
30
76
|
next: (val) => {
|
|
31
77
|
emitted = true;
|
|
32
|
-
|
|
78
|
+
$logger.info('UserService emission', val, 'real-test');
|
|
33
79
|
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
34
|
-
|
|
80
|
+
$logger.info('✅ UserService real API test succeeded', val.response, 'real-test');
|
|
35
81
|
resolve(undefined);
|
|
36
82
|
}
|
|
37
83
|
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
38
|
-
|
|
84
|
+
$logger.error('❌ UserService real API test failed', val.alertModel || val, 'real-test');
|
|
39
85
|
reject(new Error('UserService failed'));
|
|
40
86
|
}
|
|
41
87
|
},
|
|
42
88
|
error: (err) => {
|
|
43
|
-
|
|
89
|
+
$logger.error('❌ UserService observable error', err, 'real-test');
|
|
90
|
+
reject(err);
|
|
91
|
+
},
|
|
92
|
+
complete: () => {
|
|
93
|
+
if (!emitted) {
|
|
94
|
+
$logger.error('❌ UserService observable completed without emission', undefined, 'real-test');
|
|
95
|
+
reject(new Error('No emission'));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
$logger.error('❌ UserService test error', err, 'real-test');
|
|
103
|
+
process.exit(2);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function testCustomerRegister() {
|
|
107
|
+
const config = {
|
|
108
|
+
baseUrl: 'https://api.smeservices.cloud',
|
|
109
|
+
version: 'api/v1',
|
|
110
|
+
isProd: true,
|
|
111
|
+
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
112
|
+
};
|
|
113
|
+
const $authToken = new BehaviorSubject(null);
|
|
114
|
+
const customerService = new CustomerService(config, $authToken);
|
|
115
|
+
const random = Math.floor(Math.random() * 1000000);
|
|
116
|
+
const payload = {
|
|
117
|
+
email: `realtest+${random}@email.org`,
|
|
118
|
+
password: `PassWord${random}`,
|
|
119
|
+
phone_number: `+83${random}`,
|
|
120
|
+
client_id: config.clientId,
|
|
121
|
+
};
|
|
122
|
+
let emitted = false;
|
|
123
|
+
try {
|
|
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);
|
|
127
|
+
}));
|
|
128
|
+
await new Promise((resolve, reject) => {
|
|
129
|
+
obs$.subscribe({
|
|
130
|
+
next: (val) => {
|
|
131
|
+
emitted = true;
|
|
132
|
+
$logger.info('CustomerService emission', val, 'real-test');
|
|
133
|
+
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
134
|
+
$logger.info('✅ CustomerService real API test succeeded', val.response, 'real-test');
|
|
135
|
+
resolve(undefined);
|
|
136
|
+
}
|
|
137
|
+
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
138
|
+
$logger.error('❌ CustomerService real API test failed', val.alertModel || val, 'real-test');
|
|
139
|
+
reject(new Error('CustomerService failed'));
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
error: (err) => {
|
|
143
|
+
$logger.error('❌ CustomerService observable error', err, 'real-test');
|
|
144
|
+
reject(err);
|
|
145
|
+
},
|
|
146
|
+
complete: () => {
|
|
147
|
+
if (!emitted) {
|
|
148
|
+
$logger.error('❌ CustomerService observable completed without emission', undefined, 'real-test');
|
|
149
|
+
reject(new Error('No emission'));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
$logger.error('❌ CustomerService test error', err, 'real-test');
|
|
157
|
+
process.exit(2);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function testStoreProductCollection() {
|
|
161
|
+
const config = {
|
|
162
|
+
baseUrl: 'https://api.smeservices.cloud',
|
|
163
|
+
version: 'api/v1',
|
|
164
|
+
isProd: true,
|
|
165
|
+
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
166
|
+
};
|
|
167
|
+
const $authToken = new BehaviorSubject(null);
|
|
168
|
+
const storeService = new StoreService(config, $authToken);
|
|
169
|
+
const storeId = 'f1df6e9a-0160-11f0-82c2-6cac1a7e2953'; // Use a real or test store id as appropriate
|
|
170
|
+
const payload = {
|
|
171
|
+
page: 1,
|
|
172
|
+
per_page: 10,
|
|
173
|
+
search: 'bia',
|
|
174
|
+
};
|
|
175
|
+
let emitted = false;
|
|
176
|
+
try {
|
|
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);
|
|
180
|
+
}));
|
|
181
|
+
await new Promise((resolve, reject) => {
|
|
182
|
+
obs$.subscribe({
|
|
183
|
+
next: (val) => {
|
|
184
|
+
emitted = true;
|
|
185
|
+
$logger.info('StoreService.productCollection emission', val, 'real-test');
|
|
186
|
+
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
187
|
+
$logger.info('✅ StoreService.productCollection real API test succeeded', val.response, 'real-test');
|
|
188
|
+
resolve(undefined);
|
|
189
|
+
}
|
|
190
|
+
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
191
|
+
$logger.error('❌ StoreService.productCollection real API test failed', val.alertModel || val, 'real-test');
|
|
192
|
+
reject(new Error('StoreService.productCollection failed'));
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
error: (err) => {
|
|
196
|
+
$logger.error('❌ StoreService.productCollection observable error', err, 'real-test');
|
|
44
197
|
reject(err);
|
|
45
198
|
},
|
|
46
199
|
complete: () => {
|
|
47
200
|
if (!emitted) {
|
|
48
|
-
|
|
201
|
+
$logger.error('❌ StoreService.productCollection observable completed without emission', undefined, 'real-test');
|
|
49
202
|
reject(new Error('No emission'));
|
|
50
203
|
}
|
|
51
204
|
}
|
|
@@ -53,29 +206,37 @@ async function testUserService() {
|
|
|
53
206
|
});
|
|
54
207
|
}
|
|
55
208
|
catch (err) {
|
|
56
|
-
|
|
209
|
+
$logger.error('❌ StoreService.productCollection test error', err, 'real-test');
|
|
57
210
|
process.exit(2);
|
|
58
211
|
}
|
|
59
212
|
}
|
|
60
213
|
async function testAxiosDirect() {
|
|
61
214
|
try {
|
|
62
|
-
const response = await
|
|
215
|
+
const response = await axios.get('https://jsonplaceholder.typicode.com/users/1');
|
|
63
216
|
if (response && response.data && response.data.id === 1) {
|
|
64
|
-
|
|
217
|
+
$logger.info('✅ Direct axios test succeeded', response.data, 'real-test');
|
|
65
218
|
}
|
|
66
219
|
else {
|
|
67
|
-
|
|
220
|
+
$logger.error('❌ Direct axios test failed', response.data, 'real-test');
|
|
68
221
|
process.exit(3);
|
|
69
222
|
}
|
|
70
223
|
}
|
|
71
224
|
catch (err) {
|
|
72
|
-
|
|
225
|
+
$logger.error('❌ Direct axios test error', err, 'real-test');
|
|
73
226
|
process.exit(4);
|
|
74
227
|
}
|
|
75
228
|
}
|
|
76
229
|
(async () => {
|
|
77
230
|
await testAxiosDirect();
|
|
231
|
+
$logger.info('✅ Direct axios test passed!', undefined, 'real-test');
|
|
232
|
+
await testAuthService();
|
|
233
|
+
$logger.info('✅ AuthService real API tests passed!', undefined, 'real-test');
|
|
78
234
|
await testUserService();
|
|
79
|
-
|
|
235
|
+
$logger.info('✅ UserService real API tests passed!', undefined, 'real-test');
|
|
236
|
+
await testCustomerRegister();
|
|
237
|
+
$logger.info('✅ CustomerService real API register test passed!', undefined, 'real-test');
|
|
238
|
+
await testStoreProductCollection();
|
|
239
|
+
$logger.info('✅ StoreService.productCollection real API test passed!', undefined, 'real-test');
|
|
240
|
+
$logger.info('🎉 All real API tests passed!', undefined, 'real-test');
|
|
80
241
|
process.exit(0);
|
|
81
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',
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
|
-
const operators_1 = require("rxjs/operators");
|
|
1
|
+
import { BaseServiceWrapper } from './base.service.wrapper.js';
|
|
2
|
+
import { NetworkingUIEventWrapped } from '../types/types.js';
|
|
3
|
+
import { of } from 'rxjs';
|
|
4
|
+
import { map } from 'rxjs/operators';
|
|
7
5
|
describe('BaseServiceWrapper Advanced', () => {
|
|
8
6
|
const mockProvider = {
|
|
9
7
|
baseURL: 'https://api.example.com',
|
|
@@ -13,18 +11,18 @@ describe('BaseServiceWrapper Advanced', () => {
|
|
|
13
11
|
getPath: () => '/resource',
|
|
14
12
|
};
|
|
15
13
|
it('should allow use of RxJS operators', done => {
|
|
16
|
-
const wrapper = new
|
|
14
|
+
const wrapper = new BaseServiceWrapper(mockProvider);
|
|
17
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
18
|
-
wrapper.request = (() =>
|
|
19
|
-
wrapper.request().pipe(
|
|
16
|
+
wrapper.request = (() => of(NetworkingUIEventWrapped.succeeded({ foo: 1 })));
|
|
17
|
+
wrapper.request().pipe(map(r => r.response)).subscribe(val => {
|
|
20
18
|
expect(val).toEqual({ foo: 1 });
|
|
21
19
|
done();
|
|
22
20
|
});
|
|
23
21
|
});
|
|
24
22
|
it('should handle multiple concurrent requests', done => {
|
|
25
|
-
const wrapper = new
|
|
23
|
+
const wrapper = new BaseServiceWrapper(mockProvider);
|
|
26
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
27
|
-
wrapper.request = ((payload) =>
|
|
25
|
+
wrapper.request = ((payload) => of(NetworkingUIEventWrapped.succeeded({ foo: payload })));
|
|
28
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
29
27
|
const results = [];
|
|
30
28
|
wrapper.request(1).subscribe(r => {
|