@smess/networking 1.0.25 → 1.0.26
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 +2 -0
- package/dist/index.js +2 -0
- package/dist/services/customer.service.d.ts +29 -1
- package/dist/services/customer.service.js +35 -0
- package/dist/services/customer.service.test.js +174 -0
- package/package.json +1 -1
- package/dist/scripts/dev-test.d.ts +0 -1
- package/dist/scripts/dev-test.js +0 -803
- package/dist/scripts/real-test.d.ts +0 -1
- package/dist/scripts/real-test.js +0 -341
- package/dist/src/core/axios.d.ts +0 -51
- package/dist/src/core/axios.js +0 -65
- package/dist/src/core/axios.observable.d.ts +0 -11
- package/dist/src/core/axios.observable.js +0 -58
- package/dist/src/core/base.provider.advanced.test.d.ts +0 -1
- package/dist/src/core/base.provider.advanced.test.js +0 -29
- package/dist/src/core/base.provider.d.ts +0 -15
- package/dist/src/core/base.provider.js +0 -13
- package/dist/src/core/base.provider.test.d.ts +0 -1
- package/dist/src/core/base.provider.test.js +0 -36
- package/dist/src/core/base.service.wrapper.advanced.test.d.ts +0 -1
- package/dist/src/core/base.service.wrapper.advanced.test.js +0 -39
- package/dist/src/core/base.service.wrapper.d.ts +0 -7
- package/dist/src/core/base.service.wrapper.js +0 -11
- package/dist/src/core/base.service.wrapper.test.d.ts +0 -1
- package/dist/src/core/base.service.wrapper.test.js +0 -25
- package/dist/src/core/rx.http.service.d.ts +0 -51
- package/dist/src/core/rx.http.service.js +0 -65
- package/dist/src/index.d.ts +0 -19
- package/dist/src/index.js +0 -23
- package/dist/src/services/auth.service.d.ts +0 -65
- package/dist/src/services/auth.service.js +0 -197
- package/dist/src/services/auth.service.test.d.ts +0 -1
- package/dist/src/services/auth.service.test.js +0 -334
- package/dist/src/services/cache.service.d.ts +0 -31
- package/dist/src/services/cache.service.js +0 -77
- package/dist/src/services/cache.service.test.d.ts +0 -1
- package/dist/src/services/cache.service.test.js +0 -88
- package/dist/src/services/customer.service.d.ts +0 -71
- package/dist/src/services/customer.service.js +0 -114
- package/dist/src/services/customer.service.test.d.ts +0 -1
- package/dist/src/services/customer.service.test.js +0 -274
- package/dist/src/services/logger.service.d.ts +0 -31
- package/dist/src/services/logger.service.js +0 -93
- package/dist/src/services/logger.service.test.d.ts +0 -1
- package/dist/src/services/logger.service.test.js +0 -31
- package/dist/src/services/order.service.d.ts +0 -73
- package/dist/src/services/order.service.js +0 -97
- package/dist/src/services/order.service.test.d.ts +0 -1
- package/dist/src/services/order.service.test.js +0 -163
- package/dist/src/services/product.service.d.ts +0 -21
- package/dist/src/services/product.service.js +0 -42
- package/dist/src/services/product.service.test.d.ts +0 -1
- package/dist/src/services/product.service.test.js +0 -61
- package/dist/src/services/smess.service.d.ts +0 -36
- package/dist/src/services/smess.service.js +0 -128
- package/dist/src/services/smess.service.test.d.ts +0 -1
- package/dist/src/services/smess.service.test.js +0 -103
- package/dist/src/services/store.cart.service.d.ts +0 -158
- package/dist/src/services/store.cart.service.js +0 -177
- package/dist/src/services/store.cart.service.test.d.ts +0 -1
- package/dist/src/services/store.cart.service.test.js +0 -394
- package/dist/src/services/store.product.service.d.ts +0 -123
- package/dist/src/services/store.product.service.js +0 -102
- package/dist/src/services/store.product.service.test.d.ts +0 -1
- package/dist/src/services/store.product.service.test.js +0 -319
- package/dist/src/services/store.service.d.ts +0 -79
- package/dist/src/services/store.service.js +0 -235
- package/dist/src/services/store.service.test.d.ts +0 -1
- package/dist/src/services/store.service.test.js +0 -274
- package/dist/src/services/user.service.d.ts +0 -16
- package/dist/src/services/user.service.js +0 -37
- package/dist/src/services/user.service.test.d.ts +0 -1
- package/dist/src/services/user.service.test.js +0 -52
- package/dist/src/types/types.d.ts +0 -93
- package/dist/src/types/types.js +0 -82
- package/dist/src/types/types.test.d.ts +0 -1
- package/dist/src/types/types.test.js +0 -25
- package/dist/src/utils/cache-import.d.ts +0 -3
- package/dist/src/utils/cache-import.js +0 -2
- package/dist/src/utils/networking-import.d.ts +0 -4
- package/dist/src/utils/networking-import.js +0 -3
- package/dist/src/utils/rxjs-import.d.ts +0 -5
- package/dist/src/utils/rxjs-import.js +0 -5
- /package/dist/{src/services → services}/employee.service.d.ts +0 -0
- /package/dist/{src/services → services}/employee.service.js +0 -0
- /package/dist/{src/services → services}/employee.service.test.d.ts +0 -0
- /package/dist/{src/services → services}/employee.service.test.js +0 -0
- /package/dist/{src/services → services}/utils/withAuthReset.d.ts +0 -0
- /package/dist/{src/services → services}/utils/withAuthReset.js +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "fake-indexeddb/auto";
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import "fake-indexeddb/auto";
|
|
2
|
-
import { UserService } from "../src/services/user.service";
|
|
3
|
-
import { timeout, catchError, of } from "rxjs";
|
|
4
|
-
import axios from "axios";
|
|
5
|
-
import { AuthService } from "../src/services/auth.service";
|
|
6
|
-
import { CustomerService, } from "../src/services/customer.service";
|
|
7
|
-
import { StoreProductService, } from "../src/services/store.product.service";
|
|
8
|
-
import { $logger } from "../src/services/logger.service";
|
|
9
|
-
function isNetworkingUIEventWrapped(val) {
|
|
10
|
-
return (typeof val === "object" &&
|
|
11
|
-
val !== null &&
|
|
12
|
-
"hasSuccess" in val &&
|
|
13
|
-
"hasFailed" in val &&
|
|
14
|
-
"response" in val);
|
|
15
|
-
}
|
|
16
|
-
async function testAuthService() {
|
|
17
|
-
const config = {
|
|
18
|
-
baseUrl: "https://api.smeservices.cloud",
|
|
19
|
-
version: "api/v1",
|
|
20
|
-
isProd: true,
|
|
21
|
-
clientId: "665e188a-cdb0-11ef-b5bd-470a5caf5cbc",
|
|
22
|
-
};
|
|
23
|
-
const authService = new AuthService(config);
|
|
24
|
-
let emitted = false;
|
|
25
|
-
try {
|
|
26
|
-
const obs$ = authService
|
|
27
|
-
.login({ identifier: "test@email.org", password: "PassWord123" })
|
|
28
|
-
.pipe(timeout({ first: 10000 }), catchError((err) => {
|
|
29
|
-
$logger.error("❌ AuthService observable error", err, "real-test");
|
|
30
|
-
return of(undefined);
|
|
31
|
-
}));
|
|
32
|
-
await new Promise((resolve, reject) => {
|
|
33
|
-
obs$.subscribe({
|
|
34
|
-
next: (val) => {
|
|
35
|
-
emitted = true;
|
|
36
|
-
$logger.info("AuthService emission", val, "real-test");
|
|
37
|
-
if (isNetworkingUIEventWrapped(val) &&
|
|
38
|
-
val.hasSuccess &&
|
|
39
|
-
val.response) {
|
|
40
|
-
$logger.info("✅ AuthService real API test succeeded", val.response, "real-test");
|
|
41
|
-
resolve(undefined);
|
|
42
|
-
}
|
|
43
|
-
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
44
|
-
$logger.error("❌ AuthService real API test failed", val.alertModel || val, "real-test");
|
|
45
|
-
reject(new Error("AuthService failed"));
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
error: (err) => {
|
|
49
|
-
$logger.error("❌ AuthService observable error", err, "real-test");
|
|
50
|
-
reject(err);
|
|
51
|
-
},
|
|
52
|
-
complete: () => {
|
|
53
|
-
if (!emitted) {
|
|
54
|
-
$logger.error("❌ AuthService observable completed without emission", undefined, "real-test");
|
|
55
|
-
reject(new Error("No emission"));
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
$logger.error("❌ AuthService test error", err, "real-test");
|
|
63
|
-
process.exit(2);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async function testUserService() {
|
|
67
|
-
const config = {
|
|
68
|
-
baseUrl: "https://jsonplaceholder.typicode.com",
|
|
69
|
-
isProd: false,
|
|
70
|
-
};
|
|
71
|
-
const userService = new UserService(config);
|
|
72
|
-
let emitted = false;
|
|
73
|
-
try {
|
|
74
|
-
const obs$ = userService.fetchUserById(1).pipe(timeout({ first: 10000 }), catchError((err) => {
|
|
75
|
-
$logger.error("❌ UserService observable error", err, "real-test");
|
|
76
|
-
return of(undefined);
|
|
77
|
-
}));
|
|
78
|
-
await new Promise((resolve, reject) => {
|
|
79
|
-
obs$.subscribe({
|
|
80
|
-
next: (val) => {
|
|
81
|
-
emitted = true;
|
|
82
|
-
$logger.info("UserService emission", val, "real-test");
|
|
83
|
-
if (isNetworkingUIEventWrapped(val) &&
|
|
84
|
-
val.hasSuccess &&
|
|
85
|
-
val.response) {
|
|
86
|
-
$logger.info("✅ UserService real API test succeeded", val.response, "real-test");
|
|
87
|
-
resolve(undefined);
|
|
88
|
-
}
|
|
89
|
-
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
90
|
-
$logger.error("❌ UserService real API test failed", val.alertModel || val, "real-test");
|
|
91
|
-
reject(new Error("UserService failed"));
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
error: (err) => {
|
|
95
|
-
$logger.error("❌ UserService observable error", err, "real-test");
|
|
96
|
-
reject(err);
|
|
97
|
-
},
|
|
98
|
-
complete: () => {
|
|
99
|
-
if (!emitted) {
|
|
100
|
-
$logger.error("❌ UserService observable completed without emission", undefined, "real-test");
|
|
101
|
-
reject(new Error("No emission"));
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
$logger.error("❌ UserService test error", err, "real-test");
|
|
109
|
-
process.exit(2);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async function testCustomerRegister() {
|
|
113
|
-
const config = {
|
|
114
|
-
baseUrl: "https://api.smeservices.cloud",
|
|
115
|
-
version: "api/v1",
|
|
116
|
-
isProd: true,
|
|
117
|
-
clientId: "665e188a-cdb0-11ef-b5bd-470a5caf5cbc",
|
|
118
|
-
};
|
|
119
|
-
// Create AuthService to get the authToken BehaviorSubject
|
|
120
|
-
const authService = new AuthService(config);
|
|
121
|
-
const customerService = new CustomerService(config, authService.$authToken);
|
|
122
|
-
const random = Math.floor(Math.random() * 1000000);
|
|
123
|
-
const payload = {
|
|
124
|
-
email: `realtest+${random}@email.org`,
|
|
125
|
-
password: `PassWord${random}`,
|
|
126
|
-
phone_number: `+83${random}`,
|
|
127
|
-
client_id: config.clientId,
|
|
128
|
-
};
|
|
129
|
-
let emitted = false;
|
|
130
|
-
try {
|
|
131
|
-
const obs$ = customerService.register(payload).pipe(timeout({ first: 10000 }), catchError((err) => {
|
|
132
|
-
$logger.error("❌ CustomerService observable error", err, "real-test");
|
|
133
|
-
return of(undefined);
|
|
134
|
-
}));
|
|
135
|
-
await new Promise((resolve, reject) => {
|
|
136
|
-
obs$.subscribe({
|
|
137
|
-
next: (val) => {
|
|
138
|
-
emitted = true;
|
|
139
|
-
$logger.info("CustomerService emission", val, "real-test");
|
|
140
|
-
if (isNetworkingUIEventWrapped(val) &&
|
|
141
|
-
val.hasSuccess &&
|
|
142
|
-
val.response) {
|
|
143
|
-
$logger.info("✅ CustomerService real API test succeeded", val.response, "real-test");
|
|
144
|
-
resolve(undefined);
|
|
145
|
-
}
|
|
146
|
-
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
147
|
-
$logger.error("❌ CustomerService real API test failed", val.alertModel || val, "real-test");
|
|
148
|
-
reject(new Error("CustomerService failed"));
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
error: (err) => {
|
|
152
|
-
$logger.error("❌ CustomerService observable error", err, "real-test");
|
|
153
|
-
reject(err);
|
|
154
|
-
},
|
|
155
|
-
complete: () => {
|
|
156
|
-
if (!emitted) {
|
|
157
|
-
$logger.error("❌ CustomerService observable completed without emission", undefined, "real-test");
|
|
158
|
-
reject(new Error("No emission"));
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
$logger.error("❌ CustomerService test error", err, "real-test");
|
|
166
|
-
process.exit(2);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async function testStoreProductCollection() {
|
|
170
|
-
const config = {
|
|
171
|
-
baseUrl: "https://api.smeservices.cloud",
|
|
172
|
-
version: "api/v1",
|
|
173
|
-
isProd: true,
|
|
174
|
-
clientId: "665e188a-cdb0-11ef-b5bd-470a5caf5cbc",
|
|
175
|
-
};
|
|
176
|
-
const storeProductService = new StoreProductService(config);
|
|
177
|
-
const storeId = "f1df6e9a-0160-11f0-82c2-6cac1a7e2953"; // Use a real or test store id as appropriate
|
|
178
|
-
const payload = {
|
|
179
|
-
page: 1,
|
|
180
|
-
per_page: 10,
|
|
181
|
-
search: "bia",
|
|
182
|
-
};
|
|
183
|
-
let emitted = false;
|
|
184
|
-
try {
|
|
185
|
-
const obs$ = storeProductService.getProductCollectionByStore(storeId, payload).pipe(timeout({ first: 10000 }), catchError((err) => {
|
|
186
|
-
$logger.error("❌ StoreProductService.getProductCollectionByStore observable error", err, "real-test");
|
|
187
|
-
return of(undefined);
|
|
188
|
-
}));
|
|
189
|
-
await new Promise((resolve, reject) => {
|
|
190
|
-
obs$.subscribe({
|
|
191
|
-
next: (val) => {
|
|
192
|
-
emitted = true;
|
|
193
|
-
$logger.info("StoreProductService.getProductCollectionByStore emission", val, "real-test");
|
|
194
|
-
if (isNetworkingUIEventWrapped(val) &&
|
|
195
|
-
val.hasSuccess &&
|
|
196
|
-
val.response) {
|
|
197
|
-
$logger.info("✅ StoreProductService.getProductCollectionByStore real API test succeeded", val.response, "real-test");
|
|
198
|
-
resolve(undefined);
|
|
199
|
-
}
|
|
200
|
-
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
201
|
-
$logger.error("❌ StoreProductService.getProductCollectionByStore real API test failed", val.alertModel || val, "real-test");
|
|
202
|
-
reject(new Error("StoreProductService.getProductCollectionByStore failed"));
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
error: (err) => {
|
|
206
|
-
$logger.error("❌ StoreProductService.getProductCollectionByStore observable error", err, "real-test");
|
|
207
|
-
reject(err);
|
|
208
|
-
},
|
|
209
|
-
complete: () => {
|
|
210
|
-
if (!emitted) {
|
|
211
|
-
$logger.error("❌ StoreProductService.getProductCollectionByStore observable completed without emission", undefined, "real-test");
|
|
212
|
-
reject(new Error("No emission"));
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
catch (err) {
|
|
219
|
-
$logger.error("❌ StoreProductService.getProductCollectionByStore test error", err, "real-test");
|
|
220
|
-
process.exit(2);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
async function testAuthServiceRememberMe() {
|
|
224
|
-
const config = {
|
|
225
|
-
baseUrl: "https://api.smeservices.cloud",
|
|
226
|
-
version: "api/v1",
|
|
227
|
-
isProd: true,
|
|
228
|
-
clientId: "665e188a-cdb0-11ef-b5bd-470a5caf5cbc",
|
|
229
|
-
};
|
|
230
|
-
// Clear localStorage before test
|
|
231
|
-
if (typeof localStorage !== 'undefined') {
|
|
232
|
-
localStorage.removeItem('smess_auth_token');
|
|
233
|
-
localStorage.removeItem('smess_auth_response');
|
|
234
|
-
localStorage.removeItem('smess_auth_response_stored_at');
|
|
235
|
-
}
|
|
236
|
-
const authService = new AuthService(config);
|
|
237
|
-
let emitted = false;
|
|
238
|
-
try {
|
|
239
|
-
const obs$ = authService
|
|
240
|
-
.login({
|
|
241
|
-
identifier: "test@email.org",
|
|
242
|
-
password: "PassWord123",
|
|
243
|
-
rememberMe: true
|
|
244
|
-
})
|
|
245
|
-
.pipe(timeout({ first: 10000 }), catchError((err) => {
|
|
246
|
-
$logger.error("❌ AuthService rememberMe observable error", err, "real-test");
|
|
247
|
-
return of(undefined);
|
|
248
|
-
}));
|
|
249
|
-
await new Promise((resolve, reject) => {
|
|
250
|
-
obs$.subscribe({
|
|
251
|
-
next: (val) => {
|
|
252
|
-
emitted = true;
|
|
253
|
-
$logger.info("AuthService rememberMe emission", val, "real-test");
|
|
254
|
-
if (isNetworkingUIEventWrapped(val) &&
|
|
255
|
-
val.hasSuccess &&
|
|
256
|
-
val.response) {
|
|
257
|
-
$logger.info("✅ AuthService rememberMe real API test succeeded", val.response, "real-test");
|
|
258
|
-
// Verify token is saved to localStorage
|
|
259
|
-
if (typeof localStorage !== 'undefined') {
|
|
260
|
-
const storedToken = localStorage.getItem('smess_auth_token');
|
|
261
|
-
const storedResponse = localStorage.getItem('smess_auth_response');
|
|
262
|
-
const storedAt = localStorage.getItem('smess_auth_response_stored_at');
|
|
263
|
-
if (storedToken && storedResponse && storedAt) {
|
|
264
|
-
$logger.info("✅ Token successfully saved to localStorage", { storedToken, storedResponse: JSON.parse(storedResponse), storedAt }, "real-test");
|
|
265
|
-
// Test loading from localStorage by creating a new AuthService instance
|
|
266
|
-
const newAuthService = new AuthService(config);
|
|
267
|
-
const loadedToken = newAuthService.currentAuthToken;
|
|
268
|
-
if (loadedToken && loadedToken === storedToken) {
|
|
269
|
-
$logger.info("✅ Token successfully loaded from localStorage", { loadedToken }, "real-test");
|
|
270
|
-
resolve(undefined);
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
$logger.error("❌ Token failed to load from localStorage", { expected: storedToken, actual: loadedToken }, "real-test");
|
|
274
|
-
reject(new Error("Token loading failed"));
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
$logger.error("❌ Token not saved to localStorage", { storedToken, storedResponse, storedAt }, "real-test");
|
|
279
|
-
reject(new Error("Token not saved to localStorage"));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
$logger.warn("localStorage not available, skipping verification", undefined, "real-test");
|
|
284
|
-
resolve(undefined);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
288
|
-
$logger.error("❌ AuthService rememberMe real API test failed", val.alertModel || val, "real-test");
|
|
289
|
-
reject(new Error("AuthService rememberMe failed"));
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
error: (err) => {
|
|
293
|
-
$logger.error("❌ AuthService rememberMe observable error", err, "real-test");
|
|
294
|
-
reject(err);
|
|
295
|
-
},
|
|
296
|
-
complete: () => {
|
|
297
|
-
if (!emitted) {
|
|
298
|
-
$logger.error("❌ AuthService rememberMe observable completed without emission", undefined, "real-test");
|
|
299
|
-
reject(new Error("No emission"));
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
catch (err) {
|
|
306
|
-
$logger.error("❌ AuthService rememberMe test error", err, "real-test");
|
|
307
|
-
process.exit(2);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
async function testAxiosDirect() {
|
|
311
|
-
try {
|
|
312
|
-
const response = await axios.get("https://jsonplaceholder.typicode.com/users/1");
|
|
313
|
-
if (response && response.data && response.data.id === 1) {
|
|
314
|
-
$logger.info("✅ Direct axios test succeeded", response.data, "real-test");
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
$logger.error("❌ Direct axios test failed", response.data, "real-test");
|
|
318
|
-
process.exit(3);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
catch (err) {
|
|
322
|
-
$logger.error("❌ Direct axios test error", err, "real-test");
|
|
323
|
-
process.exit(4);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
(async () => {
|
|
327
|
-
await testAxiosDirect();
|
|
328
|
-
$logger.info("✅ Direct axios test passed!", undefined, "real-test");
|
|
329
|
-
await testAuthService();
|
|
330
|
-
$logger.info("✅ AuthService real API tests passed!", undefined, "real-test");
|
|
331
|
-
await testAuthServiceRememberMe();
|
|
332
|
-
$logger.info("✅ AuthService rememberMe test passed!", undefined, "real-test");
|
|
333
|
-
await testUserService();
|
|
334
|
-
$logger.info("✅ UserService real API tests passed!", undefined, "real-test");
|
|
335
|
-
await testCustomerRegister();
|
|
336
|
-
$logger.info("✅ CustomerService real API register test passed!", undefined, "real-test");
|
|
337
|
-
await testStoreProductCollection();
|
|
338
|
-
$logger.info("✅ StoreProductService.getProductCollectionByStore real API test passed!", undefined, "real-test");
|
|
339
|
-
$logger.info("🎉 All real API tests passed!", undefined, "real-test");
|
|
340
|
-
process.exit(0);
|
|
341
|
-
})();
|
package/dist/src/core/axios.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "../utils/networking-import";
|
|
2
|
-
import type { AxiosInterceptorManager } from "axios";
|
|
3
|
-
import { AxiosObservable } from "./axios.observable";
|
|
4
|
-
export interface Axiosable {
|
|
5
|
-
request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
6
|
-
get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
7
|
-
head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
8
|
-
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
9
|
-
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
10
|
-
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
11
|
-
delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
12
|
-
}
|
|
13
|
-
declare class Axios implements Axiosable {
|
|
14
|
-
private axiosInstance;
|
|
15
|
-
static defaults: Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
16
|
-
headers: import("axios").HeadersDefaults & {
|
|
17
|
-
[key: string]: import("axios").AxiosHeaderValue;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
static interceptors: {
|
|
21
|
-
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
22
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
23
|
-
};
|
|
24
|
-
constructor(axiosInstance: AxiosInstance);
|
|
25
|
-
get defaults(): Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
26
|
-
headers: import("axios").HeadersDefaults & {
|
|
27
|
-
[key: string]: import("axios").AxiosHeaderValue;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
get interceptors(): {
|
|
31
|
-
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
32
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
33
|
-
};
|
|
34
|
-
static request<T = any>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
35
|
-
static get<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
36
|
-
static post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
37
|
-
static put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
38
|
-
static patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
39
|
-
static delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
40
|
-
static head<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
41
|
-
static create(config: AxiosRequestConfig): Axios;
|
|
42
|
-
request<T = any>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
43
|
-
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
44
|
-
head<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
45
|
-
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
46
|
-
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
47
|
-
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
48
|
-
delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
49
|
-
}
|
|
50
|
-
export default Axios;
|
|
51
|
-
export { Axios };
|
package/dist/src/core/axios.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
2
|
-
import { axios, } from "../utils/networking-import";
|
|
3
|
-
import { createObservable } from "./axios.observable";
|
|
4
|
-
class Axios {
|
|
5
|
-
constructor(axiosInstance) {
|
|
6
|
-
this.axiosInstance = axiosInstance;
|
|
7
|
-
}
|
|
8
|
-
get defaults() {
|
|
9
|
-
return this.axiosInstance.defaults;
|
|
10
|
-
}
|
|
11
|
-
get interceptors() {
|
|
12
|
-
return this.axiosInstance.interceptors;
|
|
13
|
-
}
|
|
14
|
-
// ----- Static Methods -----
|
|
15
|
-
static request(config) {
|
|
16
|
-
return createObservable(axios.request, [config]);
|
|
17
|
-
}
|
|
18
|
-
static get(url, config) {
|
|
19
|
-
return createObservable(axios.get, [url, config]);
|
|
20
|
-
}
|
|
21
|
-
static post(url, data, config) {
|
|
22
|
-
return createObservable(axios.post, [url, data, config]);
|
|
23
|
-
}
|
|
24
|
-
static put(url, data, config) {
|
|
25
|
-
return createObservable(axios.put, [url, data, config]);
|
|
26
|
-
}
|
|
27
|
-
static patch(url, data, config) {
|
|
28
|
-
return createObservable(axios.patch, [url, data, config]);
|
|
29
|
-
}
|
|
30
|
-
static delete(url, config) {
|
|
31
|
-
return createObservable(axios.delete, [url, config]);
|
|
32
|
-
}
|
|
33
|
-
static head(url, config) {
|
|
34
|
-
return createObservable(axios.head, [url, config]);
|
|
35
|
-
}
|
|
36
|
-
static create(config) {
|
|
37
|
-
return new Axios(axios.create(config));
|
|
38
|
-
}
|
|
39
|
-
// ----- Instance Methods -----
|
|
40
|
-
request(config) {
|
|
41
|
-
return createObservable(this.axiosInstance.request, [config]);
|
|
42
|
-
}
|
|
43
|
-
get(url, config) {
|
|
44
|
-
return createObservable(this.axiosInstance.get, [url, config]);
|
|
45
|
-
}
|
|
46
|
-
head(url, config) {
|
|
47
|
-
return createObservable(this.axiosInstance.head, [url, config]);
|
|
48
|
-
}
|
|
49
|
-
post(url, data, config) {
|
|
50
|
-
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
51
|
-
}
|
|
52
|
-
put(url, data, config) {
|
|
53
|
-
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
54
|
-
}
|
|
55
|
-
patch(url, data, config) {
|
|
56
|
-
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
57
|
-
}
|
|
58
|
-
delete(url, config) {
|
|
59
|
-
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
Axios.defaults = axios.defaults;
|
|
63
|
-
Axios.interceptors = axios.interceptors;
|
|
64
|
-
export default Axios;
|
|
65
|
-
export { Axios };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from "../utils/networking-import";
|
|
2
|
-
import type { AxiosPromise } from "axios";
|
|
3
|
-
import { Observable } from "../utils/rxjs-import";
|
|
4
|
-
export type AxiosObservable<T> = Observable<AxiosResponse<T>>;
|
|
5
|
-
interface ObservableOptions {
|
|
6
|
-
retry?: number;
|
|
7
|
-
timeoutMs?: number;
|
|
8
|
-
cache?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function createObservable<T>(promiseFactory: (...args: any[]) => AxiosPromise<T>, args: any[], options?: ObservableOptions): AxiosObservable<T>;
|
|
11
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
2
|
-
import { axios, } from "../utils/networking-import";
|
|
3
|
-
import { Observable, timeout as rxTimeout, retry as rxRetry, shareReplay, catchError, throwError, } from "../utils/rxjs-import";
|
|
4
|
-
import { $logger } from "../services/logger.service";
|
|
5
|
-
export function createObservable(promiseFactory, args, options = {}) {
|
|
6
|
-
let config = args[args.length - 1];
|
|
7
|
-
if (config && typeof config === "object" && !Array.isArray(config)) {
|
|
8
|
-
config = { ...config };
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
config = {};
|
|
12
|
-
args.push(config);
|
|
13
|
-
}
|
|
14
|
-
let cancelSource = null;
|
|
15
|
-
const hasCancelToken = !!config.cancelToken;
|
|
16
|
-
if (!hasCancelToken) {
|
|
17
|
-
$logger.warn("[Networking] You can omit cancelToken — unsubscribing cancels the request automatically.", undefined, "axios.observable");
|
|
18
|
-
}
|
|
19
|
-
let source$ = new Observable((subscriber) => {
|
|
20
|
-
if (!hasCancelToken) {
|
|
21
|
-
cancelSource = axios.CancelToken.source();
|
|
22
|
-
config.cancelToken = cancelSource.token;
|
|
23
|
-
}
|
|
24
|
-
promiseFactory(...args)
|
|
25
|
-
.then((response) => {
|
|
26
|
-
subscriber.next(response);
|
|
27
|
-
subscriber.complete();
|
|
28
|
-
})
|
|
29
|
-
.catch((error) => {
|
|
30
|
-
if (!subscriber.closed) {
|
|
31
|
-
subscriber.error(error);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return () => {
|
|
35
|
-
if (cancelSource) {
|
|
36
|
-
cancelSource.cancel("Request canceled via unsubscribe.");
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
// Add timeout if specified
|
|
41
|
-
if (options.timeoutMs) {
|
|
42
|
-
source$ = source$.pipe(rxTimeout(options.timeoutMs));
|
|
43
|
-
}
|
|
44
|
-
// Add retry logic
|
|
45
|
-
if (options.retry) {
|
|
46
|
-
source$ = source$.pipe(rxRetry(options.retry));
|
|
47
|
-
}
|
|
48
|
-
// Cache the response if needed
|
|
49
|
-
if (options.cache) {
|
|
50
|
-
source$ = source$.pipe(shareReplay({ bufferSize: 1, refCount: false }));
|
|
51
|
-
}
|
|
52
|
-
// Optional: Log or catch errors globally
|
|
53
|
-
source$ = source$.pipe(catchError((err) => {
|
|
54
|
-
$logger.error("[createObservable error]:", err, "axios.observable");
|
|
55
|
-
return throwError(() => err);
|
|
56
|
-
}));
|
|
57
|
-
return source$;
|
|
58
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from "./base.provider";
|
|
2
|
-
describe("BaseProvider Advanced", () => {
|
|
3
|
-
const config = {
|
|
4
|
-
baseUrl: "https://api.example.com",
|
|
5
|
-
isProd: false,
|
|
6
|
-
clientId: "test-client",
|
|
7
|
-
apiKey: "test-key",
|
|
8
|
-
};
|
|
9
|
-
it("should support dynamic getPath for multiple params", () => {
|
|
10
|
-
const provider = new BaseProvider({
|
|
11
|
-
config,
|
|
12
|
-
path: "/resource/:id/:action",
|
|
13
|
-
method: "GET",
|
|
14
|
-
headers: {},
|
|
15
|
-
getPath: (id, action) => `/resource/${id}/${action}`,
|
|
16
|
-
});
|
|
17
|
-
expect(provider.getPath("42", "edit")).toBe("/resource/42/edit");
|
|
18
|
-
});
|
|
19
|
-
it("should allow dynamic headers and method", () => {
|
|
20
|
-
const provider = new BaseProvider({
|
|
21
|
-
config,
|
|
22
|
-
path: "/resource",
|
|
23
|
-
method: "PATCH",
|
|
24
|
-
headers: { Authorization: "Bearer token" },
|
|
25
|
-
});
|
|
26
|
-
expect(provider.method).toBe("PATCH");
|
|
27
|
-
expect(provider.headers.Authorization).toBe("Bearer token");
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig } from "../types/types";
|
|
2
|
-
export declare class BaseProvider implements ProviderType {
|
|
3
|
-
baseURL: string;
|
|
4
|
-
path: string;
|
|
5
|
-
method: string;
|
|
6
|
-
headers: Record<string, string | undefined>;
|
|
7
|
-
getPath: (...queryParams: unknown[]) => string;
|
|
8
|
-
constructor({ config, path, method, headers, getPath, }: {
|
|
9
|
-
config: NetworkingConfig;
|
|
10
|
-
path: string;
|
|
11
|
-
method: string;
|
|
12
|
-
headers?: any;
|
|
13
|
-
getPath?: (...queryParams: any[]) => string;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export class BaseProvider {
|
|
2
|
-
constructor({ config, path, method, headers = {}, getPath = () => path, }) {
|
|
3
|
-
this.baseURL = config.baseUrl;
|
|
4
|
-
this.path = path;
|
|
5
|
-
this.method = method;
|
|
6
|
-
this.headers = {
|
|
7
|
-
...headers,
|
|
8
|
-
"X-Client-Id": config.clientId,
|
|
9
|
-
"X-Api-Key": config.apiKey,
|
|
10
|
-
};
|
|
11
|
-
this.getPath = getPath || (() => path);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from "./base.provider";
|
|
2
|
-
describe("BaseProvider", () => {
|
|
3
|
-
const config = {
|
|
4
|
-
baseUrl: "https://api.example.com",
|
|
5
|
-
isProd: false,
|
|
6
|
-
clientId: "test-client",
|
|
7
|
-
apiKey: "test-key",
|
|
8
|
-
};
|
|
9
|
-
it("should construct with required fields", () => {
|
|
10
|
-
const provider = new BaseProvider({
|
|
11
|
-
config,
|
|
12
|
-
path: "/resource",
|
|
13
|
-
method: "GET",
|
|
14
|
-
headers: { foo: "bar" },
|
|
15
|
-
});
|
|
16
|
-
expect(provider.baseURL).toBe("https://api.example.com");
|
|
17
|
-
expect(provider.path).toBe("/resource");
|
|
18
|
-
expect(provider.method).toBe("GET");
|
|
19
|
-
expect(provider.headers).toEqual({
|
|
20
|
-
foo: "bar",
|
|
21
|
-
"X-Client-Id": "test-client",
|
|
22
|
-
"X-Api-Key": "test-key",
|
|
23
|
-
});
|
|
24
|
-
expect(provider.getPath()).toBe("/resource");
|
|
25
|
-
});
|
|
26
|
-
it("should use custom getPath if provided", () => {
|
|
27
|
-
const provider = new BaseProvider({
|
|
28
|
-
config,
|
|
29
|
-
path: "/resource/:id",
|
|
30
|
-
method: "GET",
|
|
31
|
-
headers: {},
|
|
32
|
-
getPath: (id) => `/resource/${id}`,
|
|
33
|
-
});
|
|
34
|
-
expect(provider.getPath("123")).toBe("/resource/123");
|
|
35
|
-
});
|
|
36
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|