@smess/networking 1.0.6 → 1.0.7
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/README.md +58 -0
- package/dist/core/axios.d.ts +6 -6
- package/dist/core/axios.js +22 -24
- package/dist/core/axios.observable.js +15 -17
- package/dist/core/base.provider.advanced.test.js +11 -7
- package/dist/core/base.provider.d.ts +6 -6
- package/dist/core/base.provider.js +8 -8
- package/dist/core/base.provider.test.js +12 -8
- package/dist/core/base.service.wrapper.advanced.test.js +14 -22
- package/dist/core/base.service.wrapper.js +4 -7
- package/dist/core/base.service.wrapper.test.js +5 -7
- package/dist/core/rx.http.service.d.ts +21 -21
- package/dist/core/rx.http.service.js +22 -24
- package/dist/index.d.ts +9 -9
- package/dist/index.js +9 -9
- package/dist/{src/services → services}/auth.service.d.ts +2 -2
- package/dist/{src/services → services}/auth.service.js +1 -1
- package/dist/{src/services → services}/auth.service.test.js +2 -2
- package/dist/{src/services → services}/customer.service.d.ts +2 -2
- package/dist/{src/services → services}/customer.service.js +1 -1
- package/dist/{src/services → services}/customer.service.test.js +2 -2
- package/dist/services/logger.service.d.ts +5 -5
- package/dist/services/logger.service.js +4 -8
- package/dist/services/logger.service.test.js +16 -18
- package/dist/{src/services → services}/order.service.d.ts +2 -2
- package/dist/{src/services → services}/order.service.js +1 -1
- package/dist/{src/services → services}/order.service.test.js +2 -2
- package/dist/{src/services → services}/product.service.js +2 -2
- package/dist/{src/services → services}/product.service.test.js +3 -3
- package/dist/services/smess.service.d.ts +10 -3
- package/dist/services/smess.service.js +40 -48
- package/dist/services/smess.service.test.js +52 -33
- package/dist/{src/services → services}/store.service.d.ts +2 -2
- package/dist/{src/services → services}/store.service.js +1 -1
- package/dist/{src/services → services}/store.service.test.js +2 -2
- package/dist/{src/services → services}/user.service.js +2 -2
- package/dist/{src/services → services}/user.service.test.js +3 -3
- package/dist/types/types.d.ts +12 -8
- package/dist/types/types.js +6 -13
- package/dist/types/types.test.js +5 -7
- package/dist/utils/networking-import.js +3 -43
- package/dist/utils/rxjs-import.js +5 -34
- package/package.json +7 -1
- package/dist/core/product.service.d.ts +0 -19
- package/dist/core/product.service.js +0 -46
- package/dist/core/product.service.test.js +0 -63
- package/dist/core/user.service.d.ts +0 -15
- package/dist/core/user.service.js +0 -39
- package/dist/core/user.service.test.js +0 -45
- package/dist/scripts/real-test.d.ts +0 -1
- package/dist/scripts/real-test.js +0 -242
- package/dist/src/core/axios.d.ts +0 -44
- 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 -32
- package/dist/src/core/base.service.wrapper.advanced.test.d.ts +0 -1
- package/dist/src/core/base.service.wrapper.advanced.test.js +0 -36
- 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 -44
- package/dist/src/core/rx.http.service.js +0 -65
- package/dist/src/domain/auth.provider.d.ts +0 -12
- package/dist/src/domain/auth.provider.js +0 -67
- package/dist/src/domain/product.service.js +0 -47
- package/dist/src/domain/smess.service.d.ts +0 -35
- package/dist/src/domain/smess.service.js +0 -137
- package/dist/src/domain/tests/auth.service.test.js +0 -80
- package/dist/src/domain/tests/product.service.test.d.ts +0 -1
- package/dist/src/domain/tests/product.service.test.js +0 -47
- package/dist/src/domain/tests/smess.service.test.d.ts +0 -1
- package/dist/src/domain/tests/smess.service.test.js +0 -106
- package/dist/src/domain/tests/user.service.test.d.ts +0 -1
- package/dist/src/domain/tests/user.service.test.js +0 -51
- package/dist/src/domain/user.service.js +0 -39
- package/dist/src/services/auth.service.test.d.ts +0 -1
- 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/product.service.d.ts +0 -21
- package/dist/src/services/product.service.test.d.ts +0 -1
- 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 -99
- package/dist/src/services/user.service.d.ts +0 -16
- package/dist/src/services/user.service.test.d.ts +0 -1
- 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/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/utils/networking-settings.d.ts +0 -6
- package/dist/utils/networking-settings.js +0 -19
- package/dist/utils/networking-settings.test.d.ts +0 -1
- package/dist/utils/networking-settings.test.js +0 -21
- /package/dist/{src/domain/tests → services}/auth.service.test.d.ts +0 -0
- /package/dist/{src/services → services}/customer.service.test.d.ts +0 -0
- /package/dist/{src/services → services}/order.service.test.d.ts +0 -0
- /package/dist/{src/domain → services}/product.service.d.ts +0 -0
- /package/dist/{core → services}/product.service.test.d.ts +0 -0
- /package/dist/{src/services → services}/store.service.test.d.ts +0 -0
- /package/dist/{src/domain → services}/user.service.d.ts +0 -0
- /package/dist/{core → services}/user.service.test.d.ts +0 -0
package/README.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
- RxJS-based HTTP services
|
|
6
6
|
- Extensible provider/service architecture
|
|
7
7
|
- TypeScript-first
|
|
8
|
+
- **Bundler-friendly** (Webpack, Vite, Rollup compatible)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @smess/networking
|
|
14
|
+
```
|
|
8
15
|
|
|
9
16
|
## Usage
|
|
10
17
|
|
|
@@ -36,10 +43,15 @@ const authServiceA = new AuthService(configA);
|
|
|
36
43
|
|
|
37
44
|
### 3. Use services independently
|
|
38
45
|
```typescript
|
|
46
|
+
// Using RxJS Observables
|
|
39
47
|
productServiceA.fetchAllProducts().subscribe(...);
|
|
40
48
|
productServiceB.createProduct({ name: 'X', price: 10 }).subscribe(...);
|
|
41
49
|
userServiceA.fetchUserById(1).subscribe(...);
|
|
42
50
|
authServiceA.login({ identifier: 'user', password: 'pass' }).subscribe(...);
|
|
51
|
+
|
|
52
|
+
// Or convert to Promises for async/await
|
|
53
|
+
const user = await userServiceA.fetchUserById(1).toPromise();
|
|
54
|
+
const products = await productServiceA.fetchAllProducts().toPromise();
|
|
43
55
|
```
|
|
44
56
|
|
|
45
57
|
### 4. Example: Custom Provider
|
|
@@ -72,6 +84,52 @@ service.request().subscribe(result => {
|
|
|
72
84
|
});
|
|
73
85
|
```
|
|
74
86
|
|
|
87
|
+
## Bundler Compatibility
|
|
88
|
+
|
|
89
|
+
This package is designed to work seamlessly with modern bundlers:
|
|
90
|
+
|
|
91
|
+
- **Webpack** ✅
|
|
92
|
+
- **Vite** ✅
|
|
93
|
+
- **Rollup** ✅
|
|
94
|
+
- **Parcel** ✅
|
|
95
|
+
|
|
96
|
+
The package uses **extensionless imports** in TypeScript source code, which bundlers handle automatically. No `.js` extensions needed in your imports!
|
|
97
|
+
|
|
98
|
+
### Example with Webpack/Vite
|
|
99
|
+
```typescript
|
|
100
|
+
// ✅ This works perfectly with bundlers
|
|
101
|
+
import { UserService, ProductService } from '@smess/networking';
|
|
102
|
+
|
|
103
|
+
const config = { baseUrl: 'https://api.example.com', isProd: false };
|
|
104
|
+
const userService = new UserService(config);
|
|
105
|
+
const productService = new ProductService(config);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Available Services
|
|
109
|
+
|
|
110
|
+
- `UserService` - User management operations
|
|
111
|
+
- `ProductService` - Product CRUD operations
|
|
112
|
+
- `AuthService` - Authentication (login, logout, password reset)
|
|
113
|
+
- `CustomerService` - Customer registration and profile management
|
|
114
|
+
- `OrderService` - Order management
|
|
115
|
+
- `StoreService` - Store and product catalog operations
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Install dependencies
|
|
121
|
+
npm install
|
|
122
|
+
|
|
123
|
+
# Build the package
|
|
124
|
+
npm run build
|
|
125
|
+
|
|
126
|
+
# Run tests
|
|
127
|
+
npm test
|
|
128
|
+
|
|
129
|
+
# Clean build artifacts
|
|
130
|
+
npm run clean
|
|
131
|
+
```
|
|
132
|
+
|
|
75
133
|
---
|
|
76
134
|
|
|
77
135
|
## Private Package Usage
|
package/dist/core/axios.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import type { AxiosInterceptorManager } from 'axios';
|
|
|
3
3
|
import { AxiosObservable } from './axios.observable';
|
|
4
4
|
export interface Axiosable {
|
|
5
5
|
request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
6
|
-
get<T =
|
|
7
|
-
head<T =
|
|
8
|
-
post<T =
|
|
9
|
-
put<T =
|
|
10
|
-
patch<T =
|
|
11
|
-
delete<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
12
|
}
|
|
13
13
|
declare class Axios implements Axiosable {
|
|
14
14
|
private axiosInstance;
|
package/dist/core/axios.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const networking_import_1 = require("../utils/networking-import");
|
|
5
|
-
const axios_observable_1 = require("./axios.observable");
|
|
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';
|
|
6
4
|
class Axios {
|
|
7
5
|
constructor(axiosInstance) {
|
|
8
6
|
this.axiosInstance = axiosInstance;
|
|
@@ -15,53 +13,53 @@ class Axios {
|
|
|
15
13
|
}
|
|
16
14
|
// ----- Static Methods -----
|
|
17
15
|
static request(config) {
|
|
18
|
-
return
|
|
16
|
+
return createObservable(axios.request, [config]);
|
|
19
17
|
}
|
|
20
18
|
static get(url, config) {
|
|
21
|
-
return
|
|
19
|
+
return createObservable(axios.get, [url, config]);
|
|
22
20
|
}
|
|
23
21
|
static post(url, data, config) {
|
|
24
|
-
return
|
|
22
|
+
return createObservable(axios.post, [url, data, config]);
|
|
25
23
|
}
|
|
26
24
|
static put(url, data, config) {
|
|
27
|
-
return
|
|
25
|
+
return createObservable(axios.put, [url, data, config]);
|
|
28
26
|
}
|
|
29
27
|
static patch(url, data, config) {
|
|
30
|
-
return
|
|
28
|
+
return createObservable(axios.patch, [url, data, config]);
|
|
31
29
|
}
|
|
32
30
|
static delete(url, config) {
|
|
33
|
-
return
|
|
31
|
+
return createObservable(axios.delete, [url, config]);
|
|
34
32
|
}
|
|
35
33
|
static head(url, config) {
|
|
36
|
-
return
|
|
34
|
+
return createObservable(axios.head, [url, config]);
|
|
37
35
|
}
|
|
38
36
|
static create(config) {
|
|
39
|
-
return new Axios(
|
|
37
|
+
return new Axios(axios.create(config));
|
|
40
38
|
}
|
|
41
39
|
// ----- Instance Methods -----
|
|
42
40
|
request(config) {
|
|
43
|
-
return
|
|
41
|
+
return createObservable(this.axiosInstance.request, [config]);
|
|
44
42
|
}
|
|
45
43
|
get(url, config) {
|
|
46
|
-
return
|
|
44
|
+
return createObservable(this.axiosInstance.get, [url, config]);
|
|
47
45
|
}
|
|
48
46
|
head(url, config) {
|
|
49
|
-
return
|
|
47
|
+
return createObservable(this.axiosInstance.head, [url, config]);
|
|
50
48
|
}
|
|
51
49
|
post(url, data, config) {
|
|
52
|
-
return
|
|
50
|
+
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
53
51
|
}
|
|
54
52
|
put(url, data, config) {
|
|
55
|
-
return
|
|
53
|
+
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
56
54
|
}
|
|
57
55
|
patch(url, data, config) {
|
|
58
|
-
return
|
|
56
|
+
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
59
57
|
}
|
|
60
58
|
delete(url, config) {
|
|
61
|
-
return
|
|
59
|
+
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
Axios.
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
Axios.defaults = axios.defaults;
|
|
63
|
+
Axios.interceptors = axios.interceptors;
|
|
64
|
+
export default Axios;
|
|
65
|
+
export { Axios };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const logger_service_1 = require("../services/logger.service");
|
|
7
|
-
function createObservable(promiseFactory, args, options = {}) {
|
|
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 = {}) {
|
|
8
6
|
let config = args[args.length - 1];
|
|
9
7
|
if (config && typeof config === 'object' && !Array.isArray(config)) {
|
|
10
|
-
config =
|
|
8
|
+
config = { ...config };
|
|
11
9
|
}
|
|
12
10
|
else {
|
|
13
11
|
config = {};
|
|
@@ -16,11 +14,11 @@ function createObservable(promiseFactory, args, options = {}) {
|
|
|
16
14
|
let cancelSource = null;
|
|
17
15
|
const hasCancelToken = !!config.cancelToken;
|
|
18
16
|
if (!hasCancelToken) {
|
|
19
|
-
|
|
17
|
+
$logger.warn('[Networking] You can omit cancelToken — unsubscribing cancels the request automatically.', undefined, 'axios.observable');
|
|
20
18
|
}
|
|
21
|
-
let source$ = new
|
|
19
|
+
let source$ = new Observable((subscriber) => {
|
|
22
20
|
if (!hasCancelToken) {
|
|
23
|
-
cancelSource =
|
|
21
|
+
cancelSource = axios.CancelToken.source();
|
|
24
22
|
config.cancelToken = cancelSource.token;
|
|
25
23
|
}
|
|
26
24
|
promiseFactory(...args)
|
|
@@ -41,20 +39,20 @@ function createObservable(promiseFactory, args, options = {}) {
|
|
|
41
39
|
});
|
|
42
40
|
// Add timeout if specified
|
|
43
41
|
if (options.timeoutMs) {
|
|
44
|
-
source$ = source$.pipe((
|
|
42
|
+
source$ = source$.pipe(rxTimeout(options.timeoutMs));
|
|
45
43
|
}
|
|
46
44
|
// Add retry logic
|
|
47
45
|
if (options.retry) {
|
|
48
|
-
source$ = source$.pipe((
|
|
46
|
+
source$ = source$.pipe(rxRetry(options.retry));
|
|
49
47
|
}
|
|
50
48
|
// Cache the response if needed
|
|
51
49
|
if (options.cache) {
|
|
52
|
-
source$ = source$.pipe(
|
|
50
|
+
source$ = source$.pipe(shareReplay({ bufferSize: 1, refCount: false }));
|
|
53
51
|
}
|
|
54
52
|
// Optional: Log or catch errors globally
|
|
55
|
-
source$ = source$.pipe(
|
|
56
|
-
|
|
57
|
-
return
|
|
53
|
+
source$ = source$.pipe(catchError((err) => {
|
|
54
|
+
$logger.error('[createObservable error]:', err, 'axios.observable');
|
|
55
|
+
return throwError(() => err);
|
|
58
56
|
}));
|
|
59
57
|
return source$;
|
|
60
58
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_provider_1 = require("./base.provider");
|
|
1
|
+
import { BaseProvider } from './base.provider';
|
|
4
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
|
+
};
|
|
5
9
|
it('should support dynamic getPath for multiple params', () => {
|
|
6
|
-
const provider = new
|
|
7
|
-
|
|
10
|
+
const provider = new BaseProvider({
|
|
11
|
+
config,
|
|
8
12
|
path: '/resource/:id/:action',
|
|
9
13
|
method: 'GET',
|
|
10
14
|
headers: {},
|
|
@@ -13,8 +17,8 @@ describe('BaseProvider Advanced', () => {
|
|
|
13
17
|
expect(provider.getPath('42', 'edit')).toBe('/resource/42/edit');
|
|
14
18
|
});
|
|
15
19
|
it('should allow dynamic headers and method', () => {
|
|
16
|
-
const provider = new
|
|
17
|
-
|
|
20
|
+
const provider = new BaseProvider({
|
|
21
|
+
config,
|
|
18
22
|
path: '/resource',
|
|
19
23
|
method: 'PATCH',
|
|
20
24
|
headers: { Authorization: 'Bearer token' },
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ProviderType } from '../types/types';
|
|
1
|
+
import { ProviderType, NetworkingConfig } from '../types/types';
|
|
2
2
|
export declare class BaseProvider implements ProviderType {
|
|
3
3
|
baseURL: string;
|
|
4
4
|
path: string;
|
|
5
5
|
method: string;
|
|
6
|
-
headers:
|
|
7
|
-
getPath: (...queryParams:
|
|
8
|
-
constructor({
|
|
9
|
-
|
|
6
|
+
headers: Record<string, string | undefined>;
|
|
7
|
+
getPath: (...queryParams: unknown[]) => string;
|
|
8
|
+
constructor({ config, path, method, headers, getPath, }: {
|
|
9
|
+
config: NetworkingConfig;
|
|
10
10
|
path: string;
|
|
11
11
|
method: string;
|
|
12
|
-
headers
|
|
12
|
+
headers?: any;
|
|
13
13
|
getPath?: (...queryParams: any[]) => string;
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class BaseProvider {
|
|
5
|
-
constructor({ baseURL, path, method, headers, getPath, }) {
|
|
6
|
-
this.baseURL = baseURL;
|
|
1
|
+
export class BaseProvider {
|
|
2
|
+
constructor({ config, path, method, headers = {}, getPath = () => path, }) {
|
|
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,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_provider_1 = require("./base.provider");
|
|
1
|
+
import { BaseProvider } from './base.provider';
|
|
4
2
|
describe('BaseProvider', () => {
|
|
3
|
+
const config = {
|
|
4
|
+
baseUrl: 'https://api.example.com',
|
|
5
|
+
isProd: false,
|
|
6
|
+
clientId: 'test-client',
|
|
7
|
+
apiKey: 'test-key',
|
|
8
|
+
};
|
|
5
9
|
it('should construct with required fields', () => {
|
|
6
|
-
const provider = new
|
|
7
|
-
|
|
10
|
+
const provider = new BaseProvider({
|
|
11
|
+
config,
|
|
8
12
|
path: '/resource',
|
|
9
13
|
method: 'GET',
|
|
10
14
|
headers: { foo: 'bar' },
|
|
@@ -12,12 +16,12 @@ describe('BaseProvider', () => {
|
|
|
12
16
|
expect(provider.baseURL).toBe('https://api.example.com');
|
|
13
17
|
expect(provider.path).toBe('/resource');
|
|
14
18
|
expect(provider.method).toBe('GET');
|
|
15
|
-
expect(provider.headers).toEqual({ foo: 'bar' });
|
|
19
|
+
expect(provider.headers).toEqual({ foo: 'bar', 'X-Client-Id': 'test-client', 'X-Api-Key': 'test-key' });
|
|
16
20
|
expect(provider.getPath()).toBe('/resource');
|
|
17
21
|
});
|
|
18
22
|
it('should use custom getPath if provided', () => {
|
|
19
|
-
const provider = new
|
|
20
|
-
|
|
23
|
+
const provider = new BaseProvider({
|
|
24
|
+
config,
|
|
21
25
|
path: '/resource/:id',
|
|
22
26
|
method: 'GET',
|
|
23
27
|
headers: {},
|
|
@@ -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';
|
|
2
|
+
import { NetworkingUIEventWrapped } from '../types/types';
|
|
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,30 +11,24 @@ describe('BaseServiceWrapper Advanced', () => {
|
|
|
13
11
|
getPath: () => '/resource',
|
|
14
12
|
};
|
|
15
13
|
it('should allow use of RxJS operators', done => {
|
|
16
|
-
const wrapper = new
|
|
17
|
-
|
|
18
|
-
wrapper.request(
|
|
14
|
+
const wrapper = new BaseServiceWrapper(mockProvider);
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
16
|
+
wrapper.request = (() => of(NetworkingUIEventWrapped.succeeded({ foo: 1 })));
|
|
17
|
+
wrapper.request().pipe(map(r => r.response)).subscribe(val => {
|
|
19
18
|
expect(val).toEqual({ foo: 1 });
|
|
20
19
|
done();
|
|
21
20
|
});
|
|
22
21
|
});
|
|
23
22
|
it('should handle multiple concurrent requests', done => {
|
|
24
|
-
const wrapper = new
|
|
25
|
-
|
|
23
|
+
const wrapper = new BaseServiceWrapper(mockProvider);
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
25
|
+
wrapper.request = ((payload) => of(NetworkingUIEventWrapped.succeeded({ foo: payload })));
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
26
27
|
const results = [];
|
|
27
28
|
wrapper.request(1).subscribe(r => {
|
|
28
29
|
results.push(r.response);
|
|
29
|
-
if (results.length ===
|
|
30
|
-
expect(results).
|
|
31
|
-
expect(results).toContainEqual({ foo: 2 });
|
|
32
|
-
done();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
wrapper.request(2).subscribe(r => {
|
|
36
|
-
results.push(r.response);
|
|
37
|
-
if (results.length === 2) {
|
|
38
|
-
expect(results).toContainEqual({ foo: 1 });
|
|
39
|
-
expect(results).toContainEqual({ foo: 2 });
|
|
30
|
+
if (results.length === 1) {
|
|
31
|
+
expect(results[0]).toEqual({ foo: 1 });
|
|
40
32
|
done();
|
|
41
33
|
}
|
|
42
34
|
});
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BaseServiceWrapper = void 0;
|
|
4
|
-
const smess_service_1 = require("../services/smess.service");
|
|
5
|
-
class BaseServiceWrapper {
|
|
1
|
+
import { SmessService } from '../services/smess.service';
|
|
2
|
+
export class BaseServiceWrapper {
|
|
6
3
|
constructor(provider) {
|
|
7
4
|
this.provider = provider;
|
|
8
5
|
}
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for base service wrapper compatibility
|
|
9
7
|
request(payload) {
|
|
10
|
-
const service = new
|
|
8
|
+
const service = new SmessService(this.provider);
|
|
11
9
|
return service.request(payload);
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
exports.BaseServiceWrapper = BaseServiceWrapper;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const types_1 = require("../types/types");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
1
|
+
import { BaseServiceWrapper } from './base.service.wrapper';
|
|
2
|
+
import { NetworkingUIEventWrapped } from '../types/types';
|
|
3
|
+
import { of } from 'rxjs';
|
|
6
4
|
// Mock SmessService for testing
|
|
7
5
|
jest.mock('../services/smess.service', () => ({
|
|
8
6
|
SmessService: jest.fn().mockImplementation(() => ({
|
|
9
|
-
request: jest.fn(() =>
|
|
7
|
+
request: jest.fn(() => of(NetworkingUIEventWrapped.succeeded({ foo: 'bar' })))
|
|
10
8
|
}))
|
|
11
9
|
}));
|
|
12
10
|
describe('BaseServiceWrapper', () => {
|
|
@@ -18,7 +16,7 @@ describe('BaseServiceWrapper', () => {
|
|
|
18
16
|
getPath: () => '/resource',
|
|
19
17
|
};
|
|
20
18
|
it('should delegate request to SmessService', done => {
|
|
21
|
-
const wrapper = new
|
|
19
|
+
const wrapper = new BaseServiceWrapper(mockProvider);
|
|
22
20
|
wrapper.request().subscribe(result => {
|
|
23
21
|
expect(result.response).toEqual({ foo: 'bar' });
|
|
24
22
|
done();
|
|
@@ -2,13 +2,13 @@ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from '../utils/netwo
|
|
|
2
2
|
import type { AxiosInterceptorManager } from 'axios';
|
|
3
3
|
import { AxiosObservable } from './axios.observable';
|
|
4
4
|
export interface Axiosable {
|
|
5
|
-
request<T =
|
|
6
|
-
get<T =
|
|
7
|
-
head<T =
|
|
8
|
-
post<T =
|
|
9
|
-
put<T =
|
|
10
|
-
patch<T =
|
|
11
|
-
delete<T =
|
|
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
12
|
}
|
|
13
13
|
declare class HttpService implements Axiosable {
|
|
14
14
|
private axiosInstance;
|
|
@@ -31,21 +31,21 @@ declare class HttpService implements Axiosable {
|
|
|
31
31
|
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
32
32
|
response: AxiosInterceptorManager<AxiosResponse>;
|
|
33
33
|
};
|
|
34
|
-
static request<T =
|
|
35
|
-
static get<T =
|
|
36
|
-
static post<T =
|
|
37
|
-
static put<T =
|
|
38
|
-
static patch<T =
|
|
39
|
-
static delete<T =
|
|
40
|
-
static head<T =
|
|
34
|
+
static request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
35
|
+
static get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
36
|
+
static post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
37
|
+
static put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
38
|
+
static patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
39
|
+
static delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
40
|
+
static head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
41
41
|
static create(config: AxiosRequestConfig): HttpService;
|
|
42
|
-
request<T =
|
|
43
|
-
get<T =
|
|
44
|
-
post<T =
|
|
45
|
-
put<T =
|
|
46
|
-
patch<T =
|
|
47
|
-
delete<T =
|
|
48
|
-
head<T =
|
|
42
|
+
request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
43
|
+
get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
44
|
+
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
45
|
+
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
46
|
+
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
47
|
+
delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
48
|
+
head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
49
49
|
}
|
|
50
50
|
export default HttpService;
|
|
51
51
|
export { HttpService };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const networking_import_1 = require("../utils/networking-import");
|
|
5
|
-
const axios_observable_1 = require("./axios.observable");
|
|
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';
|
|
6
4
|
class HttpService {
|
|
7
5
|
constructor(axiosInstance) {
|
|
8
6
|
this.axiosInstance = axiosInstance;
|
|
@@ -15,53 +13,53 @@ class HttpService {
|
|
|
15
13
|
}
|
|
16
14
|
// Static methods
|
|
17
15
|
static request(config) {
|
|
18
|
-
return
|
|
16
|
+
return createObservable(axios.request, [config]);
|
|
19
17
|
}
|
|
20
18
|
static get(url, config) {
|
|
21
|
-
return
|
|
19
|
+
return createObservable(axios.get, [url, config]);
|
|
22
20
|
}
|
|
23
21
|
static post(url, data, config) {
|
|
24
|
-
return
|
|
22
|
+
return createObservable(axios.post, [url, data, config]);
|
|
25
23
|
}
|
|
26
24
|
static put(url, data, config) {
|
|
27
|
-
return
|
|
25
|
+
return createObservable(axios.put, [url, data, config]);
|
|
28
26
|
}
|
|
29
27
|
static patch(url, data, config) {
|
|
30
|
-
return
|
|
28
|
+
return createObservable(axios.patch, [url, data, config]);
|
|
31
29
|
}
|
|
32
30
|
static delete(url, config) {
|
|
33
|
-
return
|
|
31
|
+
return createObservable(axios.delete, [url, config]);
|
|
34
32
|
}
|
|
35
33
|
static head(url, config) {
|
|
36
|
-
return
|
|
34
|
+
return createObservable(axios.head, [url, config]);
|
|
37
35
|
}
|
|
38
36
|
static create(config) {
|
|
39
|
-
return new HttpService(
|
|
37
|
+
return new HttpService(axios.create(config));
|
|
40
38
|
}
|
|
41
39
|
// Instance methods
|
|
42
40
|
request(config) {
|
|
43
|
-
return
|
|
41
|
+
return createObservable(this.axiosInstance.request, [config]);
|
|
44
42
|
}
|
|
45
43
|
get(url, config) {
|
|
46
|
-
return
|
|
44
|
+
return createObservable(this.axiosInstance.get, [url, config]);
|
|
47
45
|
}
|
|
48
46
|
post(url, data, config) {
|
|
49
|
-
return
|
|
47
|
+
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
50
48
|
}
|
|
51
49
|
put(url, data, config) {
|
|
52
|
-
return
|
|
50
|
+
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
53
51
|
}
|
|
54
52
|
patch(url, data, config) {
|
|
55
|
-
return
|
|
53
|
+
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
56
54
|
}
|
|
57
55
|
delete(url, config) {
|
|
58
|
-
return
|
|
56
|
+
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
59
57
|
}
|
|
60
58
|
head(url, config) {
|
|
61
|
-
return
|
|
59
|
+
return createObservable(this.axiosInstance.head, [url, config]);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
HttpService.
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
HttpService.defaults = axios.defaults;
|
|
63
|
+
HttpService.interceptors = axios.interceptors;
|
|
64
|
+
export default HttpService;
|
|
65
|
+
export { HttpService };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export { $logger } from './
|
|
1
|
+
export * from './services/user.service';
|
|
2
|
+
export * from './services/product.service';
|
|
3
|
+
export * from './services/auth.service';
|
|
4
|
+
export * from './services/smess.service';
|
|
5
|
+
export * from './core/base.provider';
|
|
6
|
+
export * from './core/base.service.wrapper';
|
|
7
|
+
export * from './core/axios.observable';
|
|
8
|
+
export * from './types/types';
|
|
9
|
+
export { $logger } from './services/logger.service';
|
|
10
10
|
export declare const baseURL: () => string;
|
|
11
11
|
export declare const apiVersion: () => string;
|