@smess/networking 1.0.5 → 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
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
2
|
-
import { axios } from '../utils/networking-import.js';
|
|
3
|
-
import { createObservable } from './axios.observable.js';
|
|
4
|
-
class HttpService {
|
|
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 HttpService(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
|
-
post(url, data, config) {
|
|
47
|
-
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
48
|
-
}
|
|
49
|
-
put(url, data, config) {
|
|
50
|
-
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
51
|
-
}
|
|
52
|
-
patch(url, data, config) {
|
|
53
|
-
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
54
|
-
}
|
|
55
|
-
delete(url, config) {
|
|
56
|
-
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
57
|
-
}
|
|
58
|
-
head(url, config) {
|
|
59
|
-
return createObservable(this.axiosInstance.head, [url, config]);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
HttpService.defaults = axios.defaults;
|
|
63
|
-
HttpService.interceptors = axios.interceptors;
|
|
64
|
-
export default HttpService;
|
|
65
|
-
export { HttpService };
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthProvider = void 0;
|
|
4
|
-
const smess_service_1 = require("./smess.service");
|
|
5
|
-
class AuthProvider {
|
|
6
|
-
constructor(config, target) {
|
|
7
|
-
this.config = config;
|
|
8
|
-
this.target = target;
|
|
9
|
-
}
|
|
10
|
-
get baseURL() {
|
|
11
|
-
return `${this.config.baseUrl}/api/v1`;
|
|
12
|
-
}
|
|
13
|
-
get path() {
|
|
14
|
-
switch (this.target) {
|
|
15
|
-
case 'login':
|
|
16
|
-
return '/authentication/login_check';
|
|
17
|
-
case 'logout':
|
|
18
|
-
return '/authentication/logout';
|
|
19
|
-
case 'register':
|
|
20
|
-
return '/authentication/customer/register';
|
|
21
|
-
case 'get-profile':
|
|
22
|
-
return '/authentication/customer/get-profile';
|
|
23
|
-
case 'update-profile':
|
|
24
|
-
return '/authentication/customer/update';
|
|
25
|
-
case 'password-forgot':
|
|
26
|
-
return '/authentication/forgot-password';
|
|
27
|
-
case 'change-password':
|
|
28
|
-
return '/authentication/change-password';
|
|
29
|
-
case 'reset-password':
|
|
30
|
-
return '/authentication/reset-password';
|
|
31
|
-
default:
|
|
32
|
-
return '/authentication';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
get method() {
|
|
36
|
-
switch (this.target) {
|
|
37
|
-
case 'get-profile':
|
|
38
|
-
return 'GET';
|
|
39
|
-
case 'update-profile':
|
|
40
|
-
return 'PUT';
|
|
41
|
-
default:
|
|
42
|
-
return 'POST';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
get headers() {
|
|
46
|
-
switch (this.target) {
|
|
47
|
-
case 'login':
|
|
48
|
-
return smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1);
|
|
49
|
-
case 'register':
|
|
50
|
-
return smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, null, {
|
|
51
|
-
shouldAddClientIdHeader: false,
|
|
52
|
-
});
|
|
53
|
-
default:
|
|
54
|
-
// Replace with your own auth logic as needed
|
|
55
|
-
return smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, this.config.clientId);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
getPath(...queryParams) {
|
|
59
|
-
let definedPath = this.path;
|
|
60
|
-
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
61
|
-
params === null || params === void 0 ? void 0 : params.forEach((value, index) => {
|
|
62
|
-
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
63
|
-
});
|
|
64
|
-
return definedPath;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.AuthProvider = AuthProvider;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProductService = exports.ProductProvider = void 0;
|
|
4
|
-
const base_provider_1 = require("../core/base.provider");
|
|
5
|
-
const base_service_wrapper_1 = require("../core/base.service.wrapper");
|
|
6
|
-
// ProductProvider implements ProviderType for product endpoints
|
|
7
|
-
class ProductProvider extends base_provider_1.BaseProvider {
|
|
8
|
-
constructor(config, { productId, method } = {}) {
|
|
9
|
-
super({
|
|
10
|
-
config,
|
|
11
|
-
path: productId ? `/products/${productId}` : '/products',
|
|
12
|
-
method: method || 'GET',
|
|
13
|
-
headers: { 'Content-Type': 'application/json' },
|
|
14
|
-
getPath: () => (productId ? `/products/${productId}` : '/products'),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ProductProvider = ProductProvider;
|
|
19
|
-
// ProductService provides high-level methods for product API
|
|
20
|
-
class ProductService extends base_service_wrapper_1.BaseServiceWrapper {
|
|
21
|
-
constructor(config, productId, method) {
|
|
22
|
-
super(new ProductProvider(config, { productId, method }));
|
|
23
|
-
this.config = config;
|
|
24
|
-
}
|
|
25
|
-
// Fetch a product by ID
|
|
26
|
-
fetchProductById(id) {
|
|
27
|
-
this.provider = new ProductProvider(this.config, { productId: id });
|
|
28
|
-
return this.request();
|
|
29
|
-
}
|
|
30
|
-
// Fetch all products
|
|
31
|
-
fetchAllProducts() {
|
|
32
|
-
this.provider = new ProductProvider(this.config);
|
|
33
|
-
return this.request();
|
|
34
|
-
}
|
|
35
|
-
// Create a new product (POST)
|
|
36
|
-
createProduct(product) {
|
|
37
|
-
this.provider = new ProductProvider(this.config, { method: 'POST' });
|
|
38
|
-
return this.request(product);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.ProductService = ProductService;
|
|
42
|
-
// Example usage:
|
|
43
|
-
// setNetworkingConfig({ baseUrl: 'https://fakestoreapi.com', isProd: false });
|
|
44
|
-
// const productService = new ProductService();
|
|
45
|
-
// productService.fetchProductById(1).subscribe(result => console.log(result));
|
|
46
|
-
// productService.fetchAllProducts().subscribe(result => console.log(result));
|
|
47
|
-
// productService.createProduct({ name: 'New Product', price: 99.99 }).subscribe(result => console.log(result));
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { HeaderType, NetworkingUIEventWrapped, ProviderType } from '../types/types';
|
|
2
|
-
import { Observable } from '../utils/rxjs-import';
|
|
3
|
-
export declare enum SMESSHeader {
|
|
4
|
-
ContentType = "Content-Type",
|
|
5
|
-
Authorization = "Authorization",
|
|
6
|
-
Accept = "Accept",
|
|
7
|
-
ApiKey = "X-Api-Key",
|
|
8
|
-
ClientId = "X-Client-Id"
|
|
9
|
-
}
|
|
10
|
-
export declare enum ContentType {
|
|
11
|
-
Json = "application/json",
|
|
12
|
-
FormURLEncoded = "application/x-www-form-urlencoded"
|
|
13
|
-
}
|
|
14
|
-
export declare enum Accept {
|
|
15
|
-
V1 = "application/json",
|
|
16
|
-
V2 = "application/vnd.smess.v2+json",
|
|
17
|
-
V3 = "application/vnd.smess.v3+json",
|
|
18
|
-
V4 = "application/vnd.smess.v4+json",
|
|
19
|
-
V5 = "application/vnd.smess.v5+json",
|
|
20
|
-
V6 = "application/vnd.smess.v6+json",
|
|
21
|
-
V7 = "application/vnd.smess.v7+json",
|
|
22
|
-
V8 = "application/vnd.smess.v8+json",
|
|
23
|
-
V9 = "application/vnd.smess.v9+json",
|
|
24
|
-
V10 = "application/vnd.smess.v10+json"
|
|
25
|
-
}
|
|
26
|
-
export declare class SmessService<T extends ProviderType> {
|
|
27
|
-
private httpService;
|
|
28
|
-
private target;
|
|
29
|
-
constructor(target: T);
|
|
30
|
-
static getHeaders(version: Accept, authorization?: string | null, options?: HeaderType): Partial<Record<SMESSHeader, string | undefined>>;
|
|
31
|
-
private static commonHeaders;
|
|
32
|
-
request<R = unknown>(request?: unknown, mockResponse?: R, ...queryParams: unknown[]): Observable<NetworkingUIEventWrapped<R>>;
|
|
33
|
-
private transformAxiosError;
|
|
34
|
-
private transformAxiosResponse;
|
|
35
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SmessService = exports.Accept = exports.ContentType = exports.SMESSHeader = void 0;
|
|
7
|
-
const types_1 = require("../types/types");
|
|
8
|
-
const rxjs_import_1 = require("../utils/rxjs-import");
|
|
9
|
-
const rx_http_service_1 = __importDefault(require("../core/rx.http.service"));
|
|
10
|
-
const logger_service_1 = require("../services/logger.service");
|
|
11
|
-
var SMESSHeader;
|
|
12
|
-
(function (SMESSHeader) {
|
|
13
|
-
SMESSHeader["ContentType"] = "Content-Type";
|
|
14
|
-
SMESSHeader["Authorization"] = "Authorization";
|
|
15
|
-
SMESSHeader["Accept"] = "Accept";
|
|
16
|
-
SMESSHeader["ApiKey"] = "X-Api-Key";
|
|
17
|
-
SMESSHeader["ClientId"] = "X-Client-Id";
|
|
18
|
-
})(SMESSHeader || (exports.SMESSHeader = SMESSHeader = {}));
|
|
19
|
-
var ContentType;
|
|
20
|
-
(function (ContentType) {
|
|
21
|
-
ContentType["Json"] = "application/json";
|
|
22
|
-
ContentType["FormURLEncoded"] = "application/x-www-form-urlencoded";
|
|
23
|
-
})(ContentType || (exports.ContentType = ContentType = {}));
|
|
24
|
-
var Accept;
|
|
25
|
-
(function (Accept) {
|
|
26
|
-
Accept["V1"] = "application/json";
|
|
27
|
-
Accept["V2"] = "application/vnd.smess.v2+json";
|
|
28
|
-
Accept["V3"] = "application/vnd.smess.v3+json";
|
|
29
|
-
Accept["V4"] = "application/vnd.smess.v4+json";
|
|
30
|
-
Accept["V5"] = "application/vnd.smess.v5+json";
|
|
31
|
-
Accept["V6"] = "application/vnd.smess.v6+json";
|
|
32
|
-
Accept["V7"] = "application/vnd.smess.v7+json";
|
|
33
|
-
Accept["V8"] = "application/vnd.smess.v8+json";
|
|
34
|
-
Accept["V9"] = "application/vnd.smess.v9+json";
|
|
35
|
-
Accept["V10"] = "application/vnd.smess.v10+json";
|
|
36
|
-
})(Accept || (exports.Accept = Accept = {}));
|
|
37
|
-
class SmessService {
|
|
38
|
-
constructor(target) {
|
|
39
|
-
this.target = target;
|
|
40
|
-
// Set default headers
|
|
41
|
-
logger_service_1.$logger.info('SmessService initialized', {
|
|
42
|
-
target: this.target,
|
|
43
|
-
baseURL: this.target.baseURL,
|
|
44
|
-
method: this.target.method,
|
|
45
|
-
headers: this.target.headers,
|
|
46
|
-
}, 'SmessService');
|
|
47
|
-
this.httpService = rx_http_service_1.default.create({
|
|
48
|
-
baseURL: this.target.baseURL,
|
|
49
|
-
headers: this.target.headers,
|
|
50
|
-
method: this.target.method,
|
|
51
|
-
});
|
|
52
|
-
this.httpService.interceptors.response.use((response) => response, async (error) => {
|
|
53
|
-
var _a;
|
|
54
|
-
const originalRequest = error.config;
|
|
55
|
-
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 && !originalRequest._retry) {
|
|
56
|
-
originalRequest._retry = true;
|
|
57
|
-
logger_service_1.$logger.info('SmessService constructor - 401 retry', originalRequest, 'SmessService');
|
|
58
|
-
// Implement token refresh logic here
|
|
59
|
-
// Then retry the original request
|
|
60
|
-
// return httpService.request(originalRequest);
|
|
61
|
-
}
|
|
62
|
-
return Promise.reject(error);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
static getHeaders(version, authorization = null, options) {
|
|
66
|
-
const headers = this.commonHeaders(version, options);
|
|
67
|
-
if (authorization) {
|
|
68
|
-
headers['Authorization'] = authorization;
|
|
69
|
-
}
|
|
70
|
-
return headers;
|
|
71
|
-
}
|
|
72
|
-
static commonHeaders(version, options) {
|
|
73
|
-
const { shouldAddClientIdHeader = true, } = options !== null && options !== void 0 ? options : {};
|
|
74
|
-
const headers = {
|
|
75
|
-
Accept: version,
|
|
76
|
-
Authorization: '',
|
|
77
|
-
'Content-Type': ContentType.Json,
|
|
78
|
-
'X-Api-Key': ''
|
|
79
|
-
};
|
|
80
|
-
return headers;
|
|
81
|
-
}
|
|
82
|
-
// MARK: - Public
|
|
83
|
-
request(request, mockResponse, ...queryParams) {
|
|
84
|
-
if (mockResponse !== undefined) {
|
|
85
|
-
return (0, rxjs_import_1.of)(types_1.NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
86
|
-
}
|
|
87
|
-
const url = queryParams.length
|
|
88
|
-
? this.target.getPath(...queryParams)
|
|
89
|
-
: this.target.path;
|
|
90
|
-
const config = { url };
|
|
91
|
-
let observable;
|
|
92
|
-
if (this.target.method === 'GET') {
|
|
93
|
-
if (request) {
|
|
94
|
-
config.data = request;
|
|
95
|
-
config.params = request;
|
|
96
|
-
}
|
|
97
|
-
// Note: HttpService.get expects (url, config)
|
|
98
|
-
observable = this.httpService.get(url, config);
|
|
99
|
-
}
|
|
100
|
-
else if (this.target.method === 'POST') {
|
|
101
|
-
// HttpService.post expects (url, data, config)
|
|
102
|
-
observable = this.httpService.post(url, request, config);
|
|
103
|
-
}
|
|
104
|
-
else if (this.target.method === 'PATCH') {
|
|
105
|
-
observable = this.httpService.patch(url, request, config);
|
|
106
|
-
}
|
|
107
|
-
else if (this.target.method === 'PUT') {
|
|
108
|
-
observable = this.httpService.put(url, request, config);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
observable = this.httpService.request(config);
|
|
112
|
-
}
|
|
113
|
-
return observable.pipe((0, rxjs_import_1.catchError)((error) => this.transformAxiosError(error, mockResponse)), (0, rxjs_import_1.mergeMap)((data) => this.transformAxiosResponse(data)), (0, rxjs_import_1.startWith)(types_1.NetworkingUIEventWrapped.waiting()));
|
|
114
|
-
}
|
|
115
|
-
// MARK: - Private
|
|
116
|
-
transformAxiosError(error, mockResponse) {
|
|
117
|
-
logger_service_1.$logger.error('transformAxiosError', error, 'SmessService');
|
|
118
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for axios compatibility
|
|
120
|
-
const response = error.response;
|
|
121
|
-
const httpErrorCode = response ? response.status : 0;
|
|
122
|
-
const title = response === null || response === void 0 ? void 0 : response.statusText;
|
|
123
|
-
const alertModel = new types_1.AlertModel(message, httpErrorCode, true, title, response === null || response === void 0 ? void 0 : response.data, [types_1.AlertButtonModel.buttonYes()]);
|
|
124
|
-
if (mockResponse) {
|
|
125
|
-
return (0, rxjs_import_1.of)(types_1.NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
126
|
-
}
|
|
127
|
-
return (0, rxjs_import_1.of)(types_1.NetworkingUIEventWrapped.failed(alertModel));
|
|
128
|
-
}
|
|
129
|
-
transformAxiosResponse(response) {
|
|
130
|
-
logger_service_1.$logger.info('transformAxiosResponse', response, 'SmessService');
|
|
131
|
-
if (response instanceof types_1.NetworkingUIEventWrapped) {
|
|
132
|
-
return (0, rxjs_import_1.of)(response);
|
|
133
|
-
}
|
|
134
|
-
return (0, rxjs_import_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response.data));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.SmessService = SmessService;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const auth_provider_1 = require("../auth.provider");
|
|
4
|
-
const smess_service_1 = require("../smess.service");
|
|
5
|
-
describe('AuthProvider', () => {
|
|
6
|
-
const config = {
|
|
7
|
-
baseUrl: 'https://api.example.com',
|
|
8
|
-
isProd: false,
|
|
9
|
-
clientId: 'test-client-id',
|
|
10
|
-
};
|
|
11
|
-
const targets = [
|
|
12
|
-
'get-profile',
|
|
13
|
-
'login',
|
|
14
|
-
'logout',
|
|
15
|
-
'register',
|
|
16
|
-
'update-profile',
|
|
17
|
-
'change-password',
|
|
18
|
-
'password-forgot',
|
|
19
|
-
'reset-password',
|
|
20
|
-
];
|
|
21
|
-
it('should construct with config and target', () => {
|
|
22
|
-
const provider = new auth_provider_1.AuthProvider(config, 'login');
|
|
23
|
-
expect(provider).toBeInstanceOf(auth_provider_1.AuthProvider);
|
|
24
|
-
expect(provider.baseURL).toBe('https://api.example.com/api/v1');
|
|
25
|
-
});
|
|
26
|
-
it('should return correct path for each target', () => {
|
|
27
|
-
const expectedPaths = {
|
|
28
|
-
'login': '/authentication/login_check',
|
|
29
|
-
'logout': '/authentication/logout',
|
|
30
|
-
'register': '/authentication/customer/register',
|
|
31
|
-
'get-profile': '/authentication/customer/get-profile',
|
|
32
|
-
'update-profile': '/authentication/customer/update',
|
|
33
|
-
'change-password': '/authentication/change-password',
|
|
34
|
-
'password-forgot': '/authentication/forgot-password',
|
|
35
|
-
'reset-password': '/authentication/reset-password',
|
|
36
|
-
};
|
|
37
|
-
targets.forEach(target => {
|
|
38
|
-
const provider = new auth_provider_1.AuthProvider(config, target);
|
|
39
|
-
expect(provider.path).toBe(expectedPaths[target]);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it('should return correct method for each target', () => {
|
|
43
|
-
const expectedMethods = {
|
|
44
|
-
'get-profile': 'GET',
|
|
45
|
-
'update-profile': 'PUT',
|
|
46
|
-
'login': 'POST',
|
|
47
|
-
'logout': 'POST',
|
|
48
|
-
'register': 'POST',
|
|
49
|
-
'change-password': 'POST',
|
|
50
|
-
'password-forgot': 'POST',
|
|
51
|
-
'reset-password': 'POST',
|
|
52
|
-
};
|
|
53
|
-
targets.forEach(target => {
|
|
54
|
-
const provider = new auth_provider_1.AuthProvider(config, target);
|
|
55
|
-
expect(provider.method).toBe(expectedMethods[target]);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
it('should return correct headers for login', () => {
|
|
59
|
-
const provider = new auth_provider_1.AuthProvider(config, 'login');
|
|
60
|
-
expect(provider.headers).toEqual(smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1));
|
|
61
|
-
});
|
|
62
|
-
it('should return correct headers for register', () => {
|
|
63
|
-
const provider = new auth_provider_1.AuthProvider(config, 'register');
|
|
64
|
-
expect(provider.headers).toEqual(smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, null, { shouldAddClientIdHeader: false }));
|
|
65
|
-
});
|
|
66
|
-
it('should return correct headers for other targets', () => {
|
|
67
|
-
const provider = new auth_provider_1.AuthProvider(config, 'logout');
|
|
68
|
-
expect(provider.headers).toEqual(smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, config.clientId));
|
|
69
|
-
});
|
|
70
|
-
it('should replace params in getPath', () => {
|
|
71
|
-
// Subclass to override the path getter for testing param replacement
|
|
72
|
-
class TestAuthProvider extends auth_provider_1.AuthProvider {
|
|
73
|
-
get path() {
|
|
74
|
-
return '/authentication/user/${userId}';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const provider = new TestAuthProvider(config, 'login');
|
|
78
|
-
expect(provider.getPath('123')).toBe('/authentication/user/123');
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const product_service_1 = require("../product.service");
|
|
4
|
-
const types_1 = require("../../types/types");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
|
-
jest.mock('../../core/base.service.wrapper', () => {
|
|
7
|
-
const actual = jest.requireActual('../../core/base.service.wrapper');
|
|
8
|
-
return Object.assign(Object.assign({}, actual), { BaseServiceWrapper: class {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.request = jest.fn((payload) => {
|
|
11
|
-
if (payload === 'error') {
|
|
12
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
13
|
-
}
|
|
14
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ id: 1, name: 'Product', price: 10 }));
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
} });
|
|
18
|
-
});
|
|
19
|
-
describe('ProductService', () => {
|
|
20
|
-
const config = {
|
|
21
|
-
baseUrl: 'https://fakestoreapi.com',
|
|
22
|
-
isProd: false,
|
|
23
|
-
clientId: 'test-client',
|
|
24
|
-
apiKey: 'test-key',
|
|
25
|
-
};
|
|
26
|
-
it('should fetch product by id', done => {
|
|
27
|
-
const service = new product_service_1.ProductService(config, 1);
|
|
28
|
-
service.fetchProductById(1).subscribe(result => {
|
|
29
|
-
expect(result.response).toEqual({ id: 1, name: 'Product', price: 10 });
|
|
30
|
-
done();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
it('should fetch all products', done => {
|
|
34
|
-
const service = new product_service_1.ProductService(config);
|
|
35
|
-
service.fetchAllProducts().subscribe(result => {
|
|
36
|
-
expect(result.response).toEqual({ id: 1, name: 'Product', price: 10 });
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
it('should create a product', done => {
|
|
41
|
-
const service = new product_service_1.ProductService(config);
|
|
42
|
-
service.createProduct({ name: 'New Product', price: 99.99 }).subscribe(result => {
|
|
43
|
-
expect(result.response).toEqual({ id: 1, name: 'Product', price: 10 });
|
|
44
|
-
done();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for test mocks */
|
|
4
|
-
const smess_service_1 = require("../smess.service");
|
|
5
|
-
const types_1 = require("../../types/types");
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
describe('SmessService', () => {
|
|
8
|
-
const config = {
|
|
9
|
-
baseUrl: 'https://api.example.com',
|
|
10
|
-
isProd: false,
|
|
11
|
-
clientId: 'test-client',
|
|
12
|
-
apiKey: 'test-key',
|
|
13
|
-
};
|
|
14
|
-
const provider = {
|
|
15
|
-
baseURL: config.baseUrl,
|
|
16
|
-
path: '/resource',
|
|
17
|
-
method: 'GET',
|
|
18
|
-
headers: {},
|
|
19
|
-
getPath: () => '/resource',
|
|
20
|
-
};
|
|
21
|
-
it('should return succeeded for GET', done => {
|
|
22
|
-
const service = new smess_service_1.SmessService(provider);
|
|
23
|
-
service['httpService'] = {
|
|
24
|
-
get: jest.fn(() => (0, rxjs_1.of)({ data: { foo: 'bar' } })),
|
|
25
|
-
post: jest.fn(),
|
|
26
|
-
patch: jest.fn(),
|
|
27
|
-
put: jest.fn(),
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
|
|
29
|
-
request: jest.fn((payload) => {
|
|
30
|
-
if (payload === 'error') {
|
|
31
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
32
|
-
}
|
|
33
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 'bar' }));
|
|
34
|
-
}),
|
|
35
|
-
interceptors: { response: { use: jest.fn() } },
|
|
36
|
-
};
|
|
37
|
-
service.request().subscribe(result => {
|
|
38
|
-
expect(result).toBeInstanceOf(types_1.NetworkingUIEventWrapped);
|
|
39
|
-
expect(result.response).toEqual({ foo: 'bar' });
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
it('should return succeeded for POST', done => {
|
|
44
|
-
const postProvider = Object.assign(Object.assign({}, provider), { method: 'POST' });
|
|
45
|
-
const service = new smess_service_1.SmessService(postProvider);
|
|
46
|
-
service['httpService'] = {
|
|
47
|
-
get: jest.fn(),
|
|
48
|
-
post: jest.fn((payload) => {
|
|
49
|
-
if (payload === 'error') {
|
|
50
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
51
|
-
}
|
|
52
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 'baz' }));
|
|
53
|
-
}),
|
|
54
|
-
patch: jest.fn(),
|
|
55
|
-
put: jest.fn(),
|
|
56
|
-
request: jest.fn(),
|
|
57
|
-
interceptors: { response: { use: jest.fn() } },
|
|
58
|
-
};
|
|
59
|
-
service.request({ some: 'data' }).subscribe(result => {
|
|
60
|
-
expect(result.response).toEqual({ foo: 'baz' });
|
|
61
|
-
done();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it('should handle error', done => {
|
|
65
|
-
const service = new smess_service_1.SmessService(provider);
|
|
66
|
-
service['httpService'] = {
|
|
67
|
-
get: jest.fn(() => (0, rxjs_1.throwError)(() => new Error('Test error'))),
|
|
68
|
-
post: jest.fn(),
|
|
69
|
-
patch: jest.fn(),
|
|
70
|
-
put: jest.fn(),
|
|
71
|
-
request: jest.fn(),
|
|
72
|
-
interceptors: { response: { use: jest.fn() } },
|
|
73
|
-
};
|
|
74
|
-
service.request().subscribe(result => {
|
|
75
|
-
var _a;
|
|
76
|
-
expect(result).toBeInstanceOf(types_1.NetworkingUIEventWrapped);
|
|
77
|
-
expect(result.hasFailed).toBe(true);
|
|
78
|
-
expect(result.alertModel).toBeTruthy();
|
|
79
|
-
expect((_a = result.alertModel) === null || _a === void 0 ? void 0 : _a.message).toBe('Test error');
|
|
80
|
-
done();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
it('should return mock response if provided', done => {
|
|
84
|
-
const service = new smess_service_1.SmessService(provider);
|
|
85
|
-
service['httpService'] = {
|
|
86
|
-
get: jest.fn(() => (0, rxjs_1.throwError)(() => new Error('Test error'))),
|
|
87
|
-
post: jest.fn(),
|
|
88
|
-
patch: jest.fn(),
|
|
89
|
-
put: jest.fn(),
|
|
90
|
-
request: jest.fn((payload, mockResponse) => {
|
|
91
|
-
if (payload === 'error') {
|
|
92
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
93
|
-
}
|
|
94
|
-
if (mockResponse !== undefined) {
|
|
95
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
96
|
-
}
|
|
97
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 'mock' }));
|
|
98
|
-
}),
|
|
99
|
-
interceptors: { response: { use: jest.fn() } },
|
|
100
|
-
};
|
|
101
|
-
service.request(undefined, { foo: 'mock' }).subscribe(result => {
|
|
102
|
-
expect(result.response).toEqual({ foo: 'mock' });
|
|
103
|
-
done();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const user_service_1 = require("../user.service");
|
|
4
|
-
const types_1 = require("../../types/types");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
|
-
jest.mock('../../core/base.service.wrapper', () => {
|
|
7
|
-
const actual = jest.requireActual('../../core/base.service.wrapper');
|
|
8
|
-
return Object.assign(Object.assign({}, actual), { BaseServiceWrapper: class {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.request = jest.fn((payload) => {
|
|
11
|
-
if (payload === 'error') {
|
|
12
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
13
|
-
}
|
|
14
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ id: 1, name: 'Test', email: 'test@example.com' }));
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
} });
|
|
18
|
-
});
|
|
19
|
-
describe('UserService', () => {
|
|
20
|
-
const config = {
|
|
21
|
-
baseUrl: 'https://jsonplaceholder.typicode.com',
|
|
22
|
-
isProd: false,
|
|
23
|
-
clientId: 'test-client',
|
|
24
|
-
apiKey: 'test-key',
|
|
25
|
-
};
|
|
26
|
-
it('fetchUserById should return user (success)', done => {
|
|
27
|
-
const service = new user_service_1.UserService(config);
|
|
28
|
-
service.fetchUserById(1).subscribe(result => {
|
|
29
|
-
expect(result.response).toEqual({ id: 1, name: 'Test', email: 'test@example.com' });
|
|
30
|
-
done();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
it('fetchAllUsers should return users (success)', done => {
|
|
34
|
-
const service = new user_service_1.UserService(config);
|
|
35
|
-
service.fetchAllUsers().subscribe(result => {
|
|
36
|
-
expect(result.response).toEqual({ id: 1, name: 'Test', email: 'test@example.com' });
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
it('request should handle error', done => {
|
|
41
|
-
const service = new user_service_1.UserService(config);
|
|
42
|
-
service.request = jest.fn(() => (0, rxjs_1.throwError)(() => new Error('Test error')));
|
|
43
|
-
service.request('error').subscribe({
|
|
44
|
-
error: err => {
|
|
45
|
-
expect(err).toBeInstanceOf(Error);
|
|
46
|
-
expect(err.message).toBe('Test error');
|
|
47
|
-
done();
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|