@smess/networking 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/dist/core/axios.d.ts +51 -0
- package/dist/core/axios.js +67 -0
- package/dist/core/axios.observable.d.ts +11 -0
- package/dist/core/axios.observable.js +60 -0
- package/dist/core/base.provider.advanced.test.d.ts +1 -0
- package/dist/core/base.provider.advanced.test.js +25 -0
- package/dist/core/base.provider.d.ts +15 -0
- package/dist/core/base.provider.js +13 -0
- package/dist/core/base.provider.test.d.ts +1 -0
- package/dist/core/base.provider.test.js +28 -0
- package/dist/core/base.service.wrapper.advanced.test.d.ts +1 -0
- package/dist/core/base.service.wrapper.advanced.test.js +44 -0
- package/dist/core/base.service.wrapper.d.ts +7 -0
- package/dist/core/base.service.wrapper.js +14 -0
- package/dist/core/base.service.wrapper.test.d.ts +1 -0
- package/dist/core/base.service.wrapper.test.js +27 -0
- package/dist/core/product.service.d.ts +19 -0
- package/dist/core/product.service.js +46 -0
- package/dist/core/product.service.test.d.ts +1 -0
- package/dist/core/product.service.test.js +63 -0
- package/dist/core/rx.http.service.d.ts +51 -0
- package/dist/core/rx.http.service.js +67 -0
- package/dist/core/user.service.d.ts +15 -0
- package/dist/core/user.service.js +39 -0
- package/dist/core/user.service.test.d.ts +1 -0
- package/dist/core/user.service.test.js +45 -0
- package/dist/scripts/real-test.d.ts +1 -0
- package/dist/scripts/real-test.js +74 -0
- package/dist/services/logger.service.d.ts +31 -0
- package/dist/services/logger.service.js +97 -0
- package/dist/services/logger.service.test.d.ts +1 -0
- package/dist/services/logger.service.test.js +33 -0
- package/dist/services/smess.service.d.ts +29 -0
- package/dist/services/smess.service.js +136 -0
- package/dist/services/smess.service.test.d.ts +1 -0
- package/dist/services/smess.service.test.js +80 -0
- package/dist/src/core/axios.d.ts +51 -0
- package/dist/src/core/axios.js +68 -0
- package/dist/src/core/axios.observable.d.ts +11 -0
- package/dist/src/core/axios.observable.js +61 -0
- package/dist/src/core/base.provider.advanced.test.d.ts +1 -0
- package/dist/src/core/base.provider.advanced.test.js +31 -0
- package/dist/src/core/base.provider.d.ts +15 -0
- package/dist/src/core/base.provider.js +13 -0
- package/dist/src/core/base.provider.test.d.ts +1 -0
- package/dist/src/core/base.provider.test.js +34 -0
- package/dist/src/core/base.service.wrapper.advanced.test.d.ts +1 -0
- package/dist/src/core/base.service.wrapper.advanced.test.js +38 -0
- package/dist/src/core/base.service.wrapper.d.ts +7 -0
- package/dist/src/core/base.service.wrapper.js +15 -0
- package/dist/src/core/base.service.wrapper.test.d.ts +1 -0
- package/dist/src/core/base.service.wrapper.test.js +27 -0
- package/dist/src/core/rx.http.service.d.ts +51 -0
- package/dist/src/core/rx.http.service.js +68 -0
- package/dist/src/domain/auth.provider.d.ts +12 -0
- package/dist/src/domain/auth.provider.js +67 -0
- package/dist/src/domain/product.service.d.ts +21 -0
- package/dist/src/domain/product.service.js +47 -0
- package/dist/src/domain/smess.service.d.ts +35 -0
- package/dist/src/domain/smess.service.js +137 -0
- package/dist/src/domain/tests/auth.service.test.d.ts +1 -0
- package/dist/src/domain/tests/auth.service.test.js +80 -0
- package/dist/src/domain/tests/product.service.test.d.ts +1 -0
- package/dist/src/domain/tests/product.service.test.js +47 -0
- package/dist/src/domain/tests/smess.service.test.d.ts +1 -0
- package/dist/src/domain/tests/smess.service.test.js +106 -0
- package/dist/src/domain/tests/user.service.test.d.ts +1 -0
- package/dist/src/domain/tests/user.service.test.js +51 -0
- package/dist/src/domain/user.service.d.ts +16 -0
- package/dist/src/domain/user.service.js +39 -0
- package/dist/src/services/logger.service.d.ts +31 -0
- package/dist/src/services/logger.service.js +97 -0
- package/dist/src/services/logger.service.test.d.ts +1 -0
- package/dist/src/services/logger.service.test.js +33 -0
- package/dist/src/types/types.d.ts +95 -0
- package/dist/src/types/types.js +89 -0
- package/dist/src/types/types.test.d.ts +1 -0
- package/dist/src/types/types.test.js +27 -0
- package/dist/src/utils/networking-import.d.ts +4 -0
- package/dist/src/utils/networking-import.js +43 -0
- package/dist/src/utils/rxjs-import.d.ts +5 -0
- package/dist/src/utils/rxjs-import.js +34 -0
- package/dist/types/types.d.ts +89 -0
- package/dist/types/types.js +89 -0
- package/dist/types/types.test.d.ts +1 -0
- package/dist/types/types.test.js +27 -0
- package/dist/utils/networking-import.d.ts +4 -0
- package/dist/utils/networking-import.js +43 -0
- package/dist/utils/networking-settings.d.ts +6 -0
- package/dist/utils/networking-settings.js +19 -0
- package/dist/utils/networking-settings.test.d.ts +1 -0
- package/dist/utils/networking-settings.test.js +21 -0
- package/dist/utils/rxjs-import.d.ts +5 -0
- package/dist/utils/rxjs-import.js +34 -0
- package/package.json +33 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const smess_service_1 = require("./smess.service");
|
|
4
|
+
const types_1 = require("../types/types");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
describe('SmessService', () => {
|
|
7
|
+
const provider = {
|
|
8
|
+
baseURL: 'https://api.example.com',
|
|
9
|
+
path: '/resource',
|
|
10
|
+
method: 'GET',
|
|
11
|
+
headers: {},
|
|
12
|
+
getPath: () => '/resource',
|
|
13
|
+
};
|
|
14
|
+
it('should return succeeded for GET', done => {
|
|
15
|
+
const service = new smess_service_1.SmessService(provider);
|
|
16
|
+
service['httpService'] = {
|
|
17
|
+
get: jest.fn(() => (0, rxjs_1.of)({ data: { foo: 'bar' } })),
|
|
18
|
+
post: jest.fn(),
|
|
19
|
+
patch: jest.fn(),
|
|
20
|
+
put: jest.fn(),
|
|
21
|
+
request: jest.fn(),
|
|
22
|
+
interceptors: { response: { use: jest.fn() } },
|
|
23
|
+
};
|
|
24
|
+
service.request().subscribe(result => {
|
|
25
|
+
expect(result).toBeInstanceOf(types_1.NetworkingUIEventWrapped);
|
|
26
|
+
expect(result.response).toEqual({ foo: 'bar' });
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('should return succeeded for POST', done => {
|
|
31
|
+
const postProvider = Object.assign(Object.assign({}, provider), { method: 'POST' });
|
|
32
|
+
const service = new smess_service_1.SmessService(postProvider);
|
|
33
|
+
service['httpService'] = {
|
|
34
|
+
get: jest.fn(),
|
|
35
|
+
post: jest.fn(() => (0, rxjs_1.of)({ data: { foo: 'baz' } })),
|
|
36
|
+
patch: jest.fn(),
|
|
37
|
+
put: jest.fn(),
|
|
38
|
+
request: jest.fn(),
|
|
39
|
+
interceptors: { response: { use: jest.fn() } },
|
|
40
|
+
};
|
|
41
|
+
service.request({ some: 'data' }).subscribe(result => {
|
|
42
|
+
expect(result.response).toEqual({ foo: 'baz' });
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it('should handle error', done => {
|
|
47
|
+
const service = new smess_service_1.SmessService(provider);
|
|
48
|
+
service['httpService'] = {
|
|
49
|
+
get: jest.fn(() => (0, rxjs_1.throwError)(() => new Error('Test error'))),
|
|
50
|
+
post: jest.fn(),
|
|
51
|
+
patch: jest.fn(),
|
|
52
|
+
put: jest.fn(),
|
|
53
|
+
request: jest.fn(),
|
|
54
|
+
interceptors: { response: { use: jest.fn() } },
|
|
55
|
+
};
|
|
56
|
+
service.request().subscribe(result => {
|
|
57
|
+
var _a;
|
|
58
|
+
expect(result).toBeInstanceOf(types_1.NetworkingUIEventWrapped);
|
|
59
|
+
expect(result.hasFailed).toBe(true);
|
|
60
|
+
expect(result.alertModel).toBeTruthy();
|
|
61
|
+
expect((_a = result.alertModel) === null || _a === void 0 ? void 0 : _a.message).toBe('Test error');
|
|
62
|
+
done();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('should return mock response if provided', done => {
|
|
66
|
+
const service = new smess_service_1.SmessService(provider);
|
|
67
|
+
service['httpService'] = {
|
|
68
|
+
get: jest.fn(() => (0, rxjs_1.throwError)(() => new Error('Test error'))),
|
|
69
|
+
post: jest.fn(),
|
|
70
|
+
patch: jest.fn(),
|
|
71
|
+
put: jest.fn(),
|
|
72
|
+
request: jest.fn(),
|
|
73
|
+
interceptors: { response: { use: jest.fn() } },
|
|
74
|
+
};
|
|
75
|
+
service.request(undefined, { foo: 'mock' }).subscribe(result => {
|
|
76
|
+
expect(result.response).toEqual({ foo: 'mock' });
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
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 };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Axios = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
5
|
+
const networking_import_1 = require("../utils/networking-import");
|
|
6
|
+
const axios_observable_1 = require("./axios.observable");
|
|
7
|
+
class Axios {
|
|
8
|
+
constructor(axiosInstance) {
|
|
9
|
+
this.axiosInstance = axiosInstance;
|
|
10
|
+
}
|
|
11
|
+
get defaults() {
|
|
12
|
+
return this.axiosInstance.defaults;
|
|
13
|
+
}
|
|
14
|
+
get interceptors() {
|
|
15
|
+
return this.axiosInstance.interceptors;
|
|
16
|
+
}
|
|
17
|
+
// ----- Static Methods -----
|
|
18
|
+
static request(config) {
|
|
19
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.request, [config]);
|
|
20
|
+
}
|
|
21
|
+
static get(url, config) {
|
|
22
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.get, [url, config]);
|
|
23
|
+
}
|
|
24
|
+
static post(url, data, config) {
|
|
25
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.post, [url, data, config]);
|
|
26
|
+
}
|
|
27
|
+
static put(url, data, config) {
|
|
28
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.put, [url, data, config]);
|
|
29
|
+
}
|
|
30
|
+
static patch(url, data, config) {
|
|
31
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.patch, [url, data, config]);
|
|
32
|
+
}
|
|
33
|
+
static delete(url, config) {
|
|
34
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.delete, [url, config]);
|
|
35
|
+
}
|
|
36
|
+
static head(url, config) {
|
|
37
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.head, [url, config]);
|
|
38
|
+
}
|
|
39
|
+
static create(config) {
|
|
40
|
+
return new Axios(networking_import_1.axios.create(config));
|
|
41
|
+
}
|
|
42
|
+
// ----- Instance Methods -----
|
|
43
|
+
request(config) {
|
|
44
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.request, [config]);
|
|
45
|
+
}
|
|
46
|
+
get(url, config) {
|
|
47
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.get, [url, config]);
|
|
48
|
+
}
|
|
49
|
+
head(url, config) {
|
|
50
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.head, [url, config]);
|
|
51
|
+
}
|
|
52
|
+
post(url, data, config) {
|
|
53
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.post, [url, data, config]);
|
|
54
|
+
}
|
|
55
|
+
put(url, data, config) {
|
|
56
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.put, [url, data, config]);
|
|
57
|
+
}
|
|
58
|
+
patch(url, data, config) {
|
|
59
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.patch, [url, data, config]);
|
|
60
|
+
}
|
|
61
|
+
delete(url, config) {
|
|
62
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.delete, [url, config]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.Axios = Axios;
|
|
66
|
+
Axios.defaults = networking_import_1.axios.defaults;
|
|
67
|
+
Axios.interceptors = networking_import_1.axios.interceptors;
|
|
68
|
+
exports.default = Axios;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createObservable = createObservable;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
5
|
+
const networking_import_1 = require("../utils/networking-import");
|
|
6
|
+
const rxjs_import_1 = require("../utils/rxjs-import");
|
|
7
|
+
const logger_service_1 = require("../services/logger.service");
|
|
8
|
+
function createObservable(promiseFactory, args, options = {}) {
|
|
9
|
+
let config = args[args.length - 1];
|
|
10
|
+
if (config && typeof config === 'object' && !Array.isArray(config)) {
|
|
11
|
+
config = Object.assign({}, config);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
config = {};
|
|
15
|
+
args.push(config);
|
|
16
|
+
}
|
|
17
|
+
let cancelSource = null;
|
|
18
|
+
const hasCancelToken = !!config.cancelToken;
|
|
19
|
+
if (!hasCancelToken) {
|
|
20
|
+
logger_service_1.$logger.warn('[Networking] You can omit cancelToken — unsubscribing cancels the request automatically.', undefined, 'axios.observable');
|
|
21
|
+
}
|
|
22
|
+
let source$ = new rxjs_import_1.Observable((subscriber) => {
|
|
23
|
+
if (!hasCancelToken) {
|
|
24
|
+
cancelSource = networking_import_1.axios.CancelToken.source();
|
|
25
|
+
config.cancelToken = cancelSource.token;
|
|
26
|
+
}
|
|
27
|
+
promiseFactory(...args)
|
|
28
|
+
.then((response) => {
|
|
29
|
+
subscriber.next(response);
|
|
30
|
+
subscriber.complete();
|
|
31
|
+
})
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
if (!subscriber.closed) {
|
|
34
|
+
subscriber.error(error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
if (cancelSource) {
|
|
39
|
+
cancelSource.cancel('Request canceled via unsubscribe.');
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
// Add timeout if specified
|
|
44
|
+
if (options.timeoutMs) {
|
|
45
|
+
source$ = source$.pipe((0, rxjs_import_1.timeout)(options.timeoutMs));
|
|
46
|
+
}
|
|
47
|
+
// Add retry logic
|
|
48
|
+
if (options.retry) {
|
|
49
|
+
source$ = source$.pipe((0, rxjs_import_1.retry)(options.retry));
|
|
50
|
+
}
|
|
51
|
+
// Cache the response if needed
|
|
52
|
+
if (options.cache) {
|
|
53
|
+
source$ = source$.pipe((0, rxjs_import_1.shareReplay)({ bufferSize: 1, refCount: false }));
|
|
54
|
+
}
|
|
55
|
+
// Optional: Log or catch errors globally
|
|
56
|
+
source$ = source$.pipe((0, rxjs_import_1.catchError)((err) => {
|
|
57
|
+
logger_service_1.$logger.error('[createObservable error]:', err, 'axios.observable');
|
|
58
|
+
return (0, rxjs_import_1.throwError)(() => err);
|
|
59
|
+
}));
|
|
60
|
+
return source$;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_provider_1 = require("./base.provider");
|
|
4
|
+
describe('BaseProvider Advanced', () => {
|
|
5
|
+
const config = {
|
|
6
|
+
baseUrl: 'https://api.example.com',
|
|
7
|
+
isProd: false,
|
|
8
|
+
clientId: 'test-client',
|
|
9
|
+
apiKey: 'test-key',
|
|
10
|
+
};
|
|
11
|
+
it('should support dynamic getPath for multiple params', () => {
|
|
12
|
+
const provider = new base_provider_1.BaseProvider({
|
|
13
|
+
config,
|
|
14
|
+
path: '/resource/:id/:action',
|
|
15
|
+
method: 'GET',
|
|
16
|
+
headers: {},
|
|
17
|
+
getPath: (id, action) => `/resource/${id}/${action}`,
|
|
18
|
+
});
|
|
19
|
+
expect(provider.getPath('42', 'edit')).toBe('/resource/42/edit');
|
|
20
|
+
});
|
|
21
|
+
it('should allow dynamic headers and method', () => {
|
|
22
|
+
const provider = new base_provider_1.BaseProvider({
|
|
23
|
+
config,
|
|
24
|
+
path: '/resource',
|
|
25
|
+
method: 'PATCH',
|
|
26
|
+
headers: { Authorization: 'Bearer token' },
|
|
27
|
+
});
|
|
28
|
+
expect(provider.method).toBe('PATCH');
|
|
29
|
+
expect(provider.headers.Authorization).toBe('Bearer token');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseProvider = void 0;
|
|
4
|
+
class BaseProvider {
|
|
5
|
+
constructor({ config, path, method, headers = {}, getPath = () => path, }) {
|
|
6
|
+
this.baseURL = config.baseUrl;
|
|
7
|
+
this.path = path;
|
|
8
|
+
this.method = method;
|
|
9
|
+
this.headers = Object.assign(Object.assign({}, headers), { 'X-Client-Id': config.clientId, 'X-Api-Key': config.apiKey });
|
|
10
|
+
this.getPath = getPath || (() => path);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BaseProvider = BaseProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_provider_1 = require("./base.provider");
|
|
4
|
+
describe('BaseProvider', () => {
|
|
5
|
+
const config = {
|
|
6
|
+
baseUrl: 'https://api.example.com',
|
|
7
|
+
isProd: false,
|
|
8
|
+
clientId: 'test-client',
|
|
9
|
+
apiKey: 'test-key',
|
|
10
|
+
};
|
|
11
|
+
it('should construct with required fields', () => {
|
|
12
|
+
const provider = new base_provider_1.BaseProvider({
|
|
13
|
+
config,
|
|
14
|
+
path: '/resource',
|
|
15
|
+
method: 'GET',
|
|
16
|
+
headers: { foo: 'bar' },
|
|
17
|
+
});
|
|
18
|
+
expect(provider.baseURL).toBe('https://api.example.com');
|
|
19
|
+
expect(provider.path).toBe('/resource');
|
|
20
|
+
expect(provider.method).toBe('GET');
|
|
21
|
+
expect(provider.headers).toEqual({ foo: 'bar', 'X-Client-Id': 'test-client', 'X-Api-Key': 'test-key' });
|
|
22
|
+
expect(provider.getPath()).toBe('/resource');
|
|
23
|
+
});
|
|
24
|
+
it('should use custom getPath if provided', () => {
|
|
25
|
+
const provider = new base_provider_1.BaseProvider({
|
|
26
|
+
config,
|
|
27
|
+
path: '/resource/:id',
|
|
28
|
+
method: 'GET',
|
|
29
|
+
headers: {},
|
|
30
|
+
getPath: (id) => `/resource/${id}`,
|
|
31
|
+
});
|
|
32
|
+
expect(provider.getPath('123')).toBe('/resource/123');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_service_wrapper_1 = require("./base.service.wrapper");
|
|
4
|
+
const types_1 = require("../types/types");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const operators_1 = require("rxjs/operators");
|
|
7
|
+
describe('BaseServiceWrapper Advanced', () => {
|
|
8
|
+
const mockProvider = {
|
|
9
|
+
baseURL: 'https://api.example.com',
|
|
10
|
+
path: '/resource',
|
|
11
|
+
method: 'GET',
|
|
12
|
+
headers: {},
|
|
13
|
+
getPath: () => '/resource',
|
|
14
|
+
};
|
|
15
|
+
it('should allow use of RxJS operators', done => {
|
|
16
|
+
const wrapper = new base_service_wrapper_1.BaseServiceWrapper(mockProvider);
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
18
|
+
wrapper.request = (() => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 1 })));
|
|
19
|
+
wrapper.request().pipe((0, operators_1.map)(r => r.response)).subscribe(val => {
|
|
20
|
+
expect(val).toEqual({ foo: 1 });
|
|
21
|
+
done();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('should handle multiple concurrent requests', done => {
|
|
25
|
+
const wrapper = new base_service_wrapper_1.BaseServiceWrapper(mockProvider);
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
27
|
+
wrapper.request = ((payload) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: payload })));
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
29
|
+
const results = [];
|
|
30
|
+
wrapper.request(1).subscribe(r => {
|
|
31
|
+
results.push(r.response);
|
|
32
|
+
if (results.length === 1) {
|
|
33
|
+
expect(results[0]).toEqual({ foo: 1 });
|
|
34
|
+
done();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProviderType, NetworkingUIEventWrapped } from '../types/types';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class BaseServiceWrapper<T extends ProviderType> {
|
|
4
|
+
protected provider: T;
|
|
5
|
+
constructor(provider: T);
|
|
6
|
+
request<R = any>(payload?: any): Observable<NetworkingUIEventWrapped<R>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseServiceWrapper = void 0;
|
|
4
|
+
const smess_service_1 = require("../domain/smess.service");
|
|
5
|
+
class BaseServiceWrapper {
|
|
6
|
+
constructor(provider) {
|
|
7
|
+
this.provider = provider;
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for base service wrapper compatibility
|
|
10
|
+
request(payload) {
|
|
11
|
+
const service = new smess_service_1.SmessService(this.provider);
|
|
12
|
+
return service.request(payload);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.BaseServiceWrapper = BaseServiceWrapper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_service_wrapper_1 = require("./base.service.wrapper");
|
|
4
|
+
const types_1 = require("../types/types");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
// Mock SmessService for testing
|
|
7
|
+
jest.mock('../domain/smess.service', () => ({
|
|
8
|
+
SmessService: jest.fn().mockImplementation(() => ({
|
|
9
|
+
request: jest.fn(() => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 'bar' })))
|
|
10
|
+
}))
|
|
11
|
+
}));
|
|
12
|
+
describe('BaseServiceWrapper', () => {
|
|
13
|
+
const mockProvider = {
|
|
14
|
+
baseURL: 'https://api.example.com',
|
|
15
|
+
path: '/resource',
|
|
16
|
+
method: 'GET',
|
|
17
|
+
headers: {},
|
|
18
|
+
getPath: () => '/resource',
|
|
19
|
+
};
|
|
20
|
+
it('should delegate request to SmessService', done => {
|
|
21
|
+
const wrapper = new base_service_wrapper_1.BaseServiceWrapper(mockProvider);
|
|
22
|
+
wrapper.request().subscribe(result => {
|
|
23
|
+
expect(result.response).toEqual({ foo: 'bar' });
|
|
24
|
+
done();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
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 HttpService 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 = 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
|
+
static create(config: AxiosRequestConfig): HttpService;
|
|
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
|
+
}
|
|
50
|
+
export default HttpService;
|
|
51
|
+
export { HttpService };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpService = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
5
|
+
const networking_import_1 = require("../utils/networking-import");
|
|
6
|
+
const axios_observable_1 = require("./axios.observable");
|
|
7
|
+
class HttpService {
|
|
8
|
+
constructor(axiosInstance) {
|
|
9
|
+
this.axiosInstance = axiosInstance;
|
|
10
|
+
}
|
|
11
|
+
get defaults() {
|
|
12
|
+
return this.axiosInstance.defaults;
|
|
13
|
+
}
|
|
14
|
+
get interceptors() {
|
|
15
|
+
return this.axiosInstance.interceptors;
|
|
16
|
+
}
|
|
17
|
+
// Static methods
|
|
18
|
+
static request(config) {
|
|
19
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.request, [config]);
|
|
20
|
+
}
|
|
21
|
+
static get(url, config) {
|
|
22
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.get, [url, config]);
|
|
23
|
+
}
|
|
24
|
+
static post(url, data, config) {
|
|
25
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.post, [url, data, config]);
|
|
26
|
+
}
|
|
27
|
+
static put(url, data, config) {
|
|
28
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.put, [url, data, config]);
|
|
29
|
+
}
|
|
30
|
+
static patch(url, data, config) {
|
|
31
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.patch, [url, data, config]);
|
|
32
|
+
}
|
|
33
|
+
static delete(url, config) {
|
|
34
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.delete, [url, config]);
|
|
35
|
+
}
|
|
36
|
+
static head(url, config) {
|
|
37
|
+
return (0, axios_observable_1.createObservable)(networking_import_1.axios.head, [url, config]);
|
|
38
|
+
}
|
|
39
|
+
static create(config) {
|
|
40
|
+
return new HttpService(networking_import_1.axios.create(config));
|
|
41
|
+
}
|
|
42
|
+
// Instance methods
|
|
43
|
+
request(config) {
|
|
44
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.request, [config]);
|
|
45
|
+
}
|
|
46
|
+
get(url, config) {
|
|
47
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.get, [url, config]);
|
|
48
|
+
}
|
|
49
|
+
post(url, data, config) {
|
|
50
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.post, [url, data, config]);
|
|
51
|
+
}
|
|
52
|
+
put(url, data, config) {
|
|
53
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.put, [url, data, config]);
|
|
54
|
+
}
|
|
55
|
+
patch(url, data, config) {
|
|
56
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.patch, [url, data, config]);
|
|
57
|
+
}
|
|
58
|
+
delete(url, config) {
|
|
59
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.delete, [url, config]);
|
|
60
|
+
}
|
|
61
|
+
head(url, config) {
|
|
62
|
+
return (0, axios_observable_1.createObservable)(this.axiosInstance.head, [url, config]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.HttpService = HttpService;
|
|
66
|
+
HttpService.defaults = networking_import_1.axios.defaults;
|
|
67
|
+
HttpService.interceptors = networking_import_1.axios.interceptors;
|
|
68
|
+
exports.default = HttpService;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig } from '../types/types';
|
|
2
|
+
export type AuthTarget = 'get-profile' | 'login' | 'logout' | 'register' | 'update-profile' | 'change-password' | 'password-forgot' | 'reset-password';
|
|
3
|
+
export declare class AuthProvider implements ProviderType {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly target;
|
|
6
|
+
constructor(config: NetworkingConfig, target: AuthTarget);
|
|
7
|
+
get baseURL(): string;
|
|
8
|
+
get path(): string;
|
|
9
|
+
get method(): string;
|
|
10
|
+
get headers(): Record<string, string | undefined>;
|
|
11
|
+
getPath(...queryParams: unknown[]): string;
|
|
12
|
+
}
|