@smess/networking 1.0.6 → 1.0.8
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 +12 -9
- package/dist/index.js +12 -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/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
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
|
|
1
|
+
export * from './services/user.service';
|
|
2
|
+
export * from './services/product.service';
|
|
3
|
+
export * from './services/auth.service';
|
|
4
|
+
export * from './services/store.service';
|
|
5
|
+
export * from './services/customer.service';
|
|
6
|
+
export * from './services/product.service';
|
|
7
|
+
export * from './services/smess.service';
|
|
8
|
+
export * from './core/base.provider';
|
|
9
|
+
export * from './core/base.service.wrapper';
|
|
10
|
+
export * from './core/axios.observable';
|
|
11
|
+
export * from './types/types';
|
|
12
|
+
export { $logger } from './services/logger.service';
|
|
10
13
|
export const baseURL = () => {
|
|
11
14
|
return '';
|
|
12
15
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types
|
|
2
|
-
import { SmessService } from './smess.service
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
3
|
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
4
|
export interface AuthLoginRequest {
|
|
5
5
|
identifier: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthService } from './auth.service
|
|
2
|
-
import { NetworkingUIEventWrapped, AlertModel } from '../types/types
|
|
1
|
+
import { AuthService } from './auth.service';
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel } from '../types/types';
|
|
3
3
|
import { of, BehaviorSubject } from 'rxjs';
|
|
4
4
|
describe('AuthService', () => {
|
|
5
5
|
const config = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types
|
|
2
|
-
import { SmessService } from './smess.service
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
3
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
4
|
export type CustomerTarget = 'register' | 'get-profile' | 'update-profile';
|
|
5
5
|
export interface CustomerRegisterRequest {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomerService } from './customer.service
|
|
2
|
-
import { NetworkingUIEventWrapped, AlertModel } from '../types/types
|
|
1
|
+
import { CustomerService } from './customer.service';
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel } from '../types/types';
|
|
3
3
|
import { of, BehaviorSubject } from 'rxjs';
|
|
4
4
|
describe('CustomerService', () => {
|
|
5
5
|
const config = {
|
|
@@ -8,7 +8,7 @@ export declare enum LogLevel {
|
|
|
8
8
|
export interface LogEntry {
|
|
9
9
|
level: LogLevel;
|
|
10
10
|
message: string;
|
|
11
|
-
data?:
|
|
11
|
+
data?: unknown;
|
|
12
12
|
timestamp: number;
|
|
13
13
|
context?: string;
|
|
14
14
|
}
|
|
@@ -21,10 +21,10 @@ export declare class LoggerService {
|
|
|
21
21
|
private formatMessage;
|
|
22
22
|
private getEmojiForLevel;
|
|
23
23
|
private log;
|
|
24
|
-
debug(message: string, data?:
|
|
25
|
-
info(message: string, data?:
|
|
26
|
-
warn(message: string, data?:
|
|
27
|
-
error(message: string, data?:
|
|
24
|
+
debug(message: string, data?: unknown, context?: string): void;
|
|
25
|
+
info(message: string, data?: unknown, context?: string): void;
|
|
26
|
+
warn(message: string, data?: unknown, context?: string): void;
|
|
27
|
+
error(message: string, data?: unknown, context?: string): void;
|
|
28
28
|
getLogs(): LogEntry[];
|
|
29
29
|
clearLogs(): void;
|
|
30
30
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.$logger = exports.LoggerService = exports.LogLevel = void 0;
|
|
4
|
-
var LogLevel;
|
|
1
|
+
export var LogLevel;
|
|
5
2
|
(function (LogLevel) {
|
|
6
3
|
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
7
4
|
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
8
5
|
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
9
6
|
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
10
7
|
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
11
|
-
})(LogLevel || (
|
|
12
|
-
class LoggerService {
|
|
8
|
+
})(LogLevel || (LogLevel = {}));
|
|
9
|
+
export class LoggerService {
|
|
13
10
|
constructor() {
|
|
14
11
|
this.currentLevel = LogLevel.DEBUG;
|
|
15
12
|
this.logs = [];
|
|
@@ -92,6 +89,5 @@ class LoggerService {
|
|
|
92
89
|
this.logs = [];
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
|
-
exports.LoggerService = LoggerService;
|
|
96
92
|
// Export singleton instance
|
|
97
|
-
|
|
93
|
+
export const $logger = new LoggerService();
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const logger_service_1 = require("./logger.service");
|
|
1
|
+
import { $logger, LogLevel } from './logger.service';
|
|
4
2
|
describe('LoggerService', () => {
|
|
5
3
|
beforeEach(() => {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
$logger.clearLogs();
|
|
5
|
+
$logger.setLogLevel(LogLevel.DEBUG);
|
|
8
6
|
});
|
|
9
7
|
it('should log info', () => {
|
|
10
|
-
|
|
11
|
-
const logs =
|
|
12
|
-
expect(logs[0].level).toBe(
|
|
8
|
+
$logger.info('info message', { foo: 1 }, 'test');
|
|
9
|
+
const logs = $logger.getLogs();
|
|
10
|
+
expect(logs[0].level).toBe(LogLevel.INFO);
|
|
13
11
|
expect(logs[0].message).toBe('info message');
|
|
14
12
|
expect(logs[0].data).toEqual({ foo: 1 });
|
|
15
13
|
expect(logs[0].context).toBe('test');
|
|
16
14
|
});
|
|
17
15
|
it('should log warn and error', () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const logs =
|
|
21
|
-
expect(logs[0].level).toBe(
|
|
22
|
-
expect(logs[1].level).toBe(
|
|
16
|
+
$logger.warn('warn message');
|
|
17
|
+
$logger.error('error message', { bar: 2 });
|
|
18
|
+
const logs = $logger.getLogs();
|
|
19
|
+
expect(logs[0].level).toBe(LogLevel.WARN);
|
|
20
|
+
expect(logs[1].level).toBe(LogLevel.ERROR);
|
|
23
21
|
expect(logs[1].data).toEqual({ bar: 2 });
|
|
24
22
|
});
|
|
25
23
|
it('should respect log level', () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const logs =
|
|
24
|
+
$logger.setLogLevel(LogLevel.ERROR);
|
|
25
|
+
$logger.info('should not log');
|
|
26
|
+
$logger.error('should log');
|
|
27
|
+
const logs = $logger.getLogs();
|
|
30
28
|
expect(logs.length).toBe(1);
|
|
31
|
-
expect(logs[0].level).toBe(
|
|
29
|
+
expect(logs[0].level).toBe(LogLevel.ERROR);
|
|
32
30
|
});
|
|
33
31
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types
|
|
2
|
-
import { SmessService } from './smess.service
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
3
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
4
|
export type OrderTarget = 'order-list' | 'order-create' | 'order-delete' | 'order-get-draft' | 'order-update' | 'order-get';
|
|
5
5
|
export interface CreateOrderRequest extends UpdateOrderRequest {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OrderService } from './order.service
|
|
2
|
-
import { NetworkingUIEventWrapped, AlertModel } from '../types/types
|
|
1
|
+
import { OrderService } from './order.service';
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel } from '../types/types';
|
|
3
3
|
import { of, BehaviorSubject } from 'rxjs';
|
|
4
4
|
describe('OrderService', () => {
|
|
5
5
|
const config = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseProvider } from '../core/base.provider
|
|
2
|
-
import { BaseServiceWrapper } from '../core/base.service.wrapper
|
|
1
|
+
import { BaseProvider } from '../core/base.provider';
|
|
2
|
+
import { BaseServiceWrapper } from '../core/base.service.wrapper';
|
|
3
3
|
// ProductProvider implements ProviderType for product endpoints
|
|
4
4
|
export class ProductProvider extends BaseProvider {
|
|
5
5
|
constructor(config, { productId, method } = {}) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ProductService } from './product.service
|
|
2
|
-
import { NetworkingUIEventWrapped } from '../types/types
|
|
1
|
+
import { ProductService } from './product.service';
|
|
2
|
+
import { NetworkingUIEventWrapped } from '../types/types';
|
|
3
3
|
import { of, throwError } from 'rxjs';
|
|
4
|
-
import { BaseServiceWrapper } from '../core/base.service.wrapper
|
|
4
|
+
import { BaseServiceWrapper } from '../core/base.service.wrapper';
|
|
5
5
|
describe('ProductService', () => {
|
|
6
6
|
const config = {
|
|
7
7
|
baseUrl: 'https://jsonplaceholder.typicode.com',
|
|
@@ -15,15 +15,22 @@ export declare enum Accept {
|
|
|
15
15
|
V1 = "application/json",
|
|
16
16
|
V2 = "application/vnd.smess.v2+json",
|
|
17
17
|
V3 = "application/vnd.smess.v3+json",
|
|
18
|
-
V4 = "application/vnd.smess.v4+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"
|
|
19
25
|
}
|
|
20
26
|
export declare class SmessService<T extends ProviderType> {
|
|
21
27
|
private httpService;
|
|
22
28
|
private target;
|
|
23
29
|
constructor(target: T);
|
|
24
|
-
static getHeaders(version: Accept, authorization?: string | null, options?: HeaderType): Record<SMESSHeader,
|
|
30
|
+
static getHeaders(version: Accept, authorization?: string | null, options?: HeaderType): Partial<Record<SMESSHeader, string | undefined>>;
|
|
31
|
+
static filterHeaders(headers: Partial<Record<SMESSHeader, string | undefined>>): Record<string, string>;
|
|
25
32
|
private static commonHeaders;
|
|
26
|
-
request<R =
|
|
33
|
+
request<R = unknown>(request?: unknown, mockResponse?: R, ...queryParams: unknown[]): Observable<NetworkingUIEventWrapped<R>>;
|
|
27
34
|
private transformAxiosError;
|
|
28
35
|
private transformAxiosResponse;
|
|
29
36
|
}
|
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
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("./logger.service");
|
|
11
|
-
// import { LOG_SERVICES_CONTEXT } from '@/services';
|
|
12
|
-
var SMESSHeader;
|
|
1
|
+
import { AlertButtonModel, AlertModel, NetworkingUIEventWrapped, } from '../types/types';
|
|
2
|
+
import { catchError, mergeMap, of, startWith, } from '../utils/rxjs-import';
|
|
3
|
+
import HttpService from '../core/rx.http.service';
|
|
4
|
+
import { $logger } from '../services/logger.service';
|
|
5
|
+
export var SMESSHeader;
|
|
13
6
|
(function (SMESSHeader) {
|
|
14
7
|
SMESSHeader["ContentType"] = "Content-Type";
|
|
15
8
|
SMESSHeader["Authorization"] = "Authorization";
|
|
16
9
|
SMESSHeader["Accept"] = "Accept";
|
|
17
10
|
SMESSHeader["ApiKey"] = "X-Api-Key";
|
|
18
11
|
SMESSHeader["ClientId"] = "X-Client-Id";
|
|
19
|
-
})(SMESSHeader || (
|
|
20
|
-
var ContentType;
|
|
12
|
+
})(SMESSHeader || (SMESSHeader = {}));
|
|
13
|
+
export var ContentType;
|
|
21
14
|
(function (ContentType) {
|
|
22
15
|
ContentType["Json"] = "application/json";
|
|
23
16
|
ContentType["FormURLEncoded"] = "application/x-www-form-urlencoded";
|
|
24
|
-
})(ContentType || (
|
|
25
|
-
var Accept;
|
|
17
|
+
})(ContentType || (ContentType = {}));
|
|
18
|
+
export var Accept;
|
|
26
19
|
(function (Accept) {
|
|
27
20
|
Accept["V1"] = "application/json";
|
|
28
21
|
Accept["V2"] = "application/vnd.smess.v2+json";
|
|
29
22
|
Accept["V3"] = "application/vnd.smess.v3+json";
|
|
30
23
|
Accept["V4"] = "application/vnd.smess.v4+json";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
Accept["V5"] = "application/vnd.smess.v5+json";
|
|
25
|
+
Accept["V6"] = "application/vnd.smess.v6+json";
|
|
26
|
+
Accept["V7"] = "application/vnd.smess.v7+json";
|
|
27
|
+
Accept["V8"] = "application/vnd.smess.v8+json";
|
|
28
|
+
Accept["V9"] = "application/vnd.smess.v9+json";
|
|
29
|
+
Accept["V10"] = "application/vnd.smess.v10+json";
|
|
30
|
+
})(Accept || (Accept = {}));
|
|
31
|
+
export class SmessService {
|
|
34
32
|
constructor(target) {
|
|
35
33
|
this.target = target;
|
|
36
34
|
// Set default headers
|
|
37
|
-
|
|
35
|
+
$logger.info('SmessService initialized', {
|
|
38
36
|
target: this.target,
|
|
39
37
|
baseURL: this.target.baseURL,
|
|
40
38
|
method: this.target.method,
|
|
41
39
|
headers: this.target.headers,
|
|
42
40
|
}, 'SmessService');
|
|
43
|
-
this.httpService =
|
|
41
|
+
this.httpService = HttpService.create({
|
|
44
42
|
baseURL: this.target.baseURL,
|
|
45
43
|
headers: this.target.headers,
|
|
46
44
|
method: this.target.method,
|
|
47
45
|
});
|
|
48
46
|
this.httpService.interceptors.response.use((response) => response, async (error) => {
|
|
49
|
-
var _a;
|
|
50
47
|
const originalRequest = error.config;
|
|
51
|
-
if (
|
|
48
|
+
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
52
49
|
originalRequest._retry = true;
|
|
53
|
-
|
|
50
|
+
$logger.info('SmessService constructor - 401 retry', originalRequest, 'SmessService');
|
|
54
51
|
// Implement token refresh logic here
|
|
55
52
|
// Then retry the original request
|
|
56
53
|
// return httpService.request(originalRequest);
|
|
@@ -65,27 +62,24 @@ class SmessService {
|
|
|
65
62
|
}
|
|
66
63
|
return headers;
|
|
67
64
|
}
|
|
65
|
+
static filterHeaders(headers) {
|
|
66
|
+
const filteredHeaders = Object.fromEntries(Object.entries(headers).filter(([_, value]) => value !== undefined && value !== null && value !== ''));
|
|
67
|
+
return filteredHeaders;
|
|
68
|
+
}
|
|
68
69
|
static commonHeaders(version, options) {
|
|
69
|
-
const { shouldAddClientIdHeader = true, } = options
|
|
70
|
+
const { shouldAddClientIdHeader = true, } = options ?? {};
|
|
70
71
|
const headers = {
|
|
71
72
|
Accept: version,
|
|
72
73
|
Authorization: '',
|
|
73
74
|
'Content-Type': ContentType.Json,
|
|
74
|
-
'X-Api-Key': ''
|
|
75
|
-
'X-Client-Id': '',
|
|
75
|
+
'X-Api-Key': ''
|
|
76
76
|
};
|
|
77
|
-
if (shouldAddClientIdHeader) {
|
|
78
|
-
// headers[SMESSHeader.ClientId] = clientId; // Removed clientId usage
|
|
79
|
-
}
|
|
80
77
|
return headers;
|
|
81
78
|
}
|
|
82
79
|
// MARK: - Public
|
|
83
80
|
request(request, mockResponse, ...queryParams) {
|
|
84
|
-
if (mockResponse !== undefined) {
|
|
85
|
-
return (0, rxjs_import_1.of)(types_1.NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
86
|
-
}
|
|
87
81
|
const url = queryParams.length
|
|
88
|
-
? this.target.getPath(queryParams)
|
|
82
|
+
? this.target.getPath(...queryParams)
|
|
89
83
|
: this.target.path;
|
|
90
84
|
const config = { url };
|
|
91
85
|
let observable;
|
|
@@ -94,11 +88,9 @@ class SmessService {
|
|
|
94
88
|
config.data = request;
|
|
95
89
|
config.params = request;
|
|
96
90
|
}
|
|
97
|
-
// Note: HttpService.get expects (url, config)
|
|
98
91
|
observable = this.httpService.get(url, config);
|
|
99
92
|
}
|
|
100
93
|
else if (this.target.method === 'POST') {
|
|
101
|
-
// HttpService.post expects (url, data, config)
|
|
102
94
|
observable = this.httpService.post(url, request, config);
|
|
103
95
|
}
|
|
104
96
|
else if (this.target.method === 'PATCH') {
|
|
@@ -110,27 +102,27 @@ class SmessService {
|
|
|
110
102
|
else {
|
|
111
103
|
observable = this.httpService.request(config);
|
|
112
104
|
}
|
|
113
|
-
return observable.pipe(
|
|
105
|
+
return observable.pipe(catchError((error) => this.transformAxiosError(error, mockResponse)), mergeMap((data) => this.transformAxiosResponse(data)), startWith(NetworkingUIEventWrapped.waiting()));
|
|
114
106
|
}
|
|
115
107
|
// MARK: - Private
|
|
116
108
|
transformAxiosError(error, mockResponse) {
|
|
117
|
-
|
|
118
|
-
const message = error.message;
|
|
109
|
+
$logger.error('transformAxiosError', error, 'SmessService');
|
|
110
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for axios compatibility
|
|
119
112
|
const response = error.response;
|
|
120
113
|
const httpErrorCode = response ? response.status : 0;
|
|
121
|
-
const title = response
|
|
122
|
-
const alertModel = new
|
|
114
|
+
const title = response?.statusText;
|
|
115
|
+
const alertModel = new AlertModel(message, httpErrorCode, true, title, response?.data, [AlertButtonModel.buttonYes()]);
|
|
123
116
|
if (mockResponse) {
|
|
124
|
-
return
|
|
117
|
+
return of(NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
125
118
|
}
|
|
126
|
-
return
|
|
119
|
+
return of(NetworkingUIEventWrapped.failed(alertModel));
|
|
127
120
|
}
|
|
128
121
|
transformAxiosResponse(response) {
|
|
129
|
-
|
|
130
|
-
if (response instanceof
|
|
131
|
-
return
|
|
122
|
+
$logger.info('transformAxiosResponse', response, 'SmessService');
|
|
123
|
+
if (response instanceof NetworkingUIEventWrapped) {
|
|
124
|
+
return of(response);
|
|
132
125
|
}
|
|
133
|
-
return
|
|
126
|
+
return of(NetworkingUIEventWrapped.succeeded(response.data));
|
|
134
127
|
}
|
|
135
128
|
}
|
|
136
|
-
exports.SmessService = SmessService;
|
|
@@ -1,80 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for test mocks */
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
|
+
import { NetworkingUIEventWrapped } from '../types/types';
|
|
4
|
+
import { of, throwError } from 'rxjs';
|
|
6
5
|
describe('SmessService', () => {
|
|
6
|
+
const config = {
|
|
7
|
+
baseUrl: 'https://api.example.com',
|
|
8
|
+
isProd: false,
|
|
9
|
+
clientId: 'test-client',
|
|
10
|
+
apiKey: 'test-key',
|
|
11
|
+
};
|
|
7
12
|
const provider = {
|
|
8
|
-
baseURL:
|
|
13
|
+
baseURL: config.baseUrl,
|
|
9
14
|
path: '/resource',
|
|
10
15
|
method: 'GET',
|
|
11
16
|
headers: {},
|
|
12
17
|
getPath: () => '/resource',
|
|
13
18
|
};
|
|
14
19
|
it('should return succeeded for GET', done => {
|
|
15
|
-
const service = new
|
|
20
|
+
const service = new SmessService(provider);
|
|
16
21
|
service['httpService'] = {
|
|
17
|
-
get: jest.fn(() =>
|
|
22
|
+
get: jest.fn(() => of({ data: { foo: 'bar' } })),
|
|
18
23
|
post: jest.fn(),
|
|
19
24
|
patch: jest.fn(),
|
|
20
25
|
put: jest.fn(),
|
|
21
26
|
request: jest.fn(),
|
|
22
27
|
interceptors: { response: { use: jest.fn() } },
|
|
23
28
|
};
|
|
24
|
-
service.request().subscribe(result => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
service.request().subscribe((result) => {
|
|
30
|
+
if (result.hasSuccess) {
|
|
31
|
+
expect(result.response).toEqual({ foo: 'bar' });
|
|
32
|
+
done();
|
|
33
|
+
}
|
|
28
34
|
});
|
|
29
35
|
});
|
|
30
36
|
it('should return succeeded for POST', done => {
|
|
31
|
-
const postProvider =
|
|
32
|
-
const service = new
|
|
37
|
+
const postProvider = { ...provider, method: 'POST' };
|
|
38
|
+
const service = new SmessService(postProvider);
|
|
33
39
|
service['httpService'] = {
|
|
34
40
|
get: jest.fn(),
|
|
35
|
-
post: jest.fn(() =>
|
|
41
|
+
post: jest.fn(() => of({ data: { foo: 'baz' } })),
|
|
36
42
|
patch: jest.fn(),
|
|
37
43
|
put: jest.fn(),
|
|
38
44
|
request: jest.fn(),
|
|
39
45
|
interceptors: { response: { use: jest.fn() } },
|
|
40
46
|
};
|
|
41
|
-
service.request({ some: 'data' }).subscribe(result => {
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
service.request({ some: 'data' }).subscribe((result) => {
|
|
48
|
+
if (result.hasSuccess) {
|
|
49
|
+
expect(result.response).toEqual({ foo: 'baz' });
|
|
50
|
+
done();
|
|
51
|
+
}
|
|
44
52
|
});
|
|
45
53
|
});
|
|
46
54
|
it('should handle error', done => {
|
|
47
|
-
const service = new
|
|
55
|
+
const service = new SmessService(provider);
|
|
48
56
|
service['httpService'] = {
|
|
49
|
-
get: jest.fn(() =>
|
|
57
|
+
get: jest.fn(() => throwError(() => new Error('Test error'))),
|
|
50
58
|
post: jest.fn(),
|
|
51
59
|
patch: jest.fn(),
|
|
52
60
|
put: jest.fn(),
|
|
53
61
|
request: jest.fn(),
|
|
54
62
|
interceptors: { response: { use: jest.fn() } },
|
|
55
63
|
};
|
|
56
|
-
service.request().subscribe(result => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
service.request().subscribe((result) => {
|
|
65
|
+
if (result.hasFailed) {
|
|
66
|
+
expect(result).toBeInstanceOf(NetworkingUIEventWrapped);
|
|
67
|
+
expect(result.hasFailed).toBe(true);
|
|
68
|
+
expect(result.alertModel).toBeTruthy();
|
|
69
|
+
expect(result.alertModel?.message).toBe('Test error');
|
|
70
|
+
done();
|
|
71
|
+
}
|
|
63
72
|
});
|
|
64
73
|
});
|
|
65
74
|
it('should return mock response if provided', done => {
|
|
66
|
-
const service = new
|
|
75
|
+
const service = new SmessService(provider);
|
|
67
76
|
service['httpService'] = {
|
|
68
|
-
get: jest.fn(() =>
|
|
77
|
+
get: jest.fn(() => throwError(() => new Error('Test error'))),
|
|
69
78
|
post: jest.fn(),
|
|
70
79
|
patch: jest.fn(),
|
|
71
80
|
put: jest.fn(),
|
|
72
|
-
request: jest.fn()
|
|
81
|
+
request: jest.fn((payload, mockResponse) => {
|
|
82
|
+
if (payload === 'error') {
|
|
83
|
+
return throwError(() => new Error('Test error'));
|
|
84
|
+
}
|
|
85
|
+
if (mockResponse !== undefined) {
|
|
86
|
+
return of(NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
87
|
+
}
|
|
88
|
+
return of({ data: { foo: 'mock' } });
|
|
89
|
+
}),
|
|
73
90
|
interceptors: { response: { use: jest.fn() } },
|
|
74
91
|
};
|
|
75
|
-
service.request(undefined, { foo: 'mock' }).subscribe(result => {
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
service.request(undefined, { foo: 'mock' }).subscribe((result) => {
|
|
93
|
+
if (result.hasSuccess) {
|
|
94
|
+
expect(result.response).toEqual({ foo: 'mock' });
|
|
95
|
+
done();
|
|
96
|
+
}
|
|
78
97
|
});
|
|
79
98
|
});
|
|
80
99
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types
|
|
2
|
-
import { SmessService } from './smess.service
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
3
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
4
|
export type StoreTarget = 'store-get' | 'store-list' | 'store-product-category-list' | 'store-product-collection' | 'store-featured-product-list';
|
|
5
5
|
export interface ProductCollectionRequest {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StoreService } from './store.service
|
|
2
|
-
import { NetworkingUIEventWrapped, AlertModel } from '../types/types
|
|
1
|
+
import { StoreService } from './store.service';
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel } from '../types/types';
|
|
3
3
|
import { of, BehaviorSubject } from 'rxjs';
|
|
4
4
|
describe('StoreService', () => {
|
|
5
5
|
const config = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseProvider } from '../core/base.provider
|
|
2
|
-
import { BaseServiceWrapper } from '../core/base.service.wrapper
|
|
1
|
+
import { BaseProvider } from '../core/base.provider';
|
|
2
|
+
import { BaseServiceWrapper } from '../core/base.service.wrapper';
|
|
3
3
|
// UserProvider implements ProviderType for user endpoints
|
|
4
4
|
export class UserProvider extends BaseProvider {
|
|
5
5
|
constructor(config, userId) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { UserService } from './user.service
|
|
2
|
-
import { NetworkingUIEventWrapped } from '../types/types
|
|
1
|
+
import { UserService } from './user.service';
|
|
2
|
+
import { NetworkingUIEventWrapped } from '../types/types';
|
|
3
3
|
import { of, throwError } from 'rxjs';
|
|
4
|
-
import { BaseServiceWrapper } from '../core/base.service.wrapper
|
|
4
|
+
import { BaseServiceWrapper } from '../core/base.service.wrapper';
|
|
5
5
|
describe('UserService', () => {
|
|
6
6
|
const config = {
|
|
7
7
|
baseUrl: 'https://jsonplaceholder.typicode.com',
|