@smess/networking 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -9
- package/dist/index.js +11 -31
- package/dist/scripts/real-test.js +184 -23
- package/dist/src/core/axios.d.ts +5 -12
- package/dist/src/core/axios.js +21 -24
- package/dist/src/core/axios.observable.d.ts +2 -2
- package/dist/src/core/axios.observable.js +14 -17
- package/dist/src/core/base.provider.advanced.test.js +3 -5
- package/dist/src/core/base.provider.d.ts +1 -1
- package/dist/src/core/base.provider.js +6 -6
- package/dist/src/core/base.provider.test.js +3 -5
- package/dist/src/core/base.service.wrapper.advanced.test.js +9 -11
- package/dist/src/core/base.service.wrapper.d.ts +1 -1
- package/dist/src/core/base.service.wrapper.js +3 -7
- package/dist/src/core/base.service.wrapper.test.js +6 -8
- package/dist/src/core/rx.http.service.d.ts +5 -12
- package/dist/src/core/rx.http.service.js +21 -24
- package/dist/src/services/auth.service.d.ts +10 -8
- package/dist/src/services/auth.service.js +31 -35
- package/dist/src/services/auth.service.test.js +38 -38
- package/dist/src/services/customer.service.d.ts +43 -0
- package/dist/src/services/customer.service.js +70 -0
- package/dist/src/services/customer.service.test.d.ts +1 -0
- package/dist/src/services/customer.service.test.js +96 -0
- package/dist/src/services/logger.service.js +4 -8
- package/dist/src/services/logger.service.test.js +16 -18
- package/dist/src/services/order.service.d.ts +60 -0
- package/dist/src/services/order.service.js +89 -0
- package/dist/src/services/order.service.test.d.ts +1 -0
- package/dist/src/services/order.service.test.js +135 -0
- package/dist/src/services/product.service.d.ts +6 -6
- package/dist/src/services/product.service.js +4 -9
- package/dist/src/services/product.service.test.js +20 -21
- package/dist/src/services/smess.service.d.ts +3 -2
- package/dist/src/services/smess.service.js +30 -39
- package/dist/src/services/smess.service.test.js +39 -46
- package/dist/src/services/store.service.d.ts +39 -0
- package/dist/src/services/store.service.js +73 -0
- package/dist/src/services/store.service.test.d.ts +1 -0
- package/dist/src/services/store.service.test.js +104 -0
- package/dist/src/services/user.service.d.ts +5 -5
- package/dist/src/services/user.service.js +4 -9
- package/dist/src/services/user.service.test.js +17 -18
- package/dist/src/types/types.d.ts +1 -3
- package/dist/src/types/types.js +6 -13
- package/dist/src/types/types.test.js +5 -7
- package/dist/src/utils/networking-import.js +3 -43
- package/dist/src/utils/rxjs-import.js +5 -34
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderType, NetworkingUIEventWrapped } from '../types/types';
|
|
1
|
+
import { ProviderType, NetworkingUIEventWrapped } from '../types/types.js';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
export declare class BaseServiceWrapper<T extends ProviderType> {
|
|
4
4
|
protected provider: T;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BaseServiceWrapper = void 0;
|
|
4
|
-
const smess_service_1 = require("../services/smess.service");
|
|
5
|
-
class BaseServiceWrapper {
|
|
1
|
+
import { SmessService } from '../services/smess.service.js';
|
|
2
|
+
export class BaseServiceWrapper {
|
|
6
3
|
constructor(provider) {
|
|
7
4
|
this.provider = provider;
|
|
8
5
|
}
|
|
9
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for base service wrapper compatibility
|
|
10
7
|
request(payload) {
|
|
11
|
-
const service = new
|
|
8
|
+
const service = new SmessService(this.provider);
|
|
12
9
|
return service.request(payload);
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
|
-
exports.BaseServiceWrapper = BaseServiceWrapper;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const types_1 = require("../types/types");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
1
|
+
import { BaseServiceWrapper } from './base.service.wrapper.js';
|
|
2
|
+
import { NetworkingUIEventWrapped } from '../types/types.js';
|
|
3
|
+
import { of } from 'rxjs';
|
|
6
4
|
// Mock SmessService for testing
|
|
7
|
-
jest.mock('../services/smess.service', () => ({
|
|
5
|
+
jest.mock('../services/smess.service.js', () => ({
|
|
8
6
|
SmessService: jest.fn().mockImplementation(() => ({
|
|
9
|
-
request: jest.fn(() =>
|
|
7
|
+
request: jest.fn(() => of(NetworkingUIEventWrapped.succeeded({ foo: 'bar' })))
|
|
10
8
|
}))
|
|
11
9
|
}));
|
|
12
10
|
describe('BaseServiceWrapper', () => {
|
|
@@ -18,7 +16,7 @@ describe('BaseServiceWrapper', () => {
|
|
|
18
16
|
getPath: () => '/resource',
|
|
19
17
|
};
|
|
20
18
|
it('should delegate request to SmessService', done => {
|
|
21
|
-
const wrapper = new
|
|
19
|
+
const wrapper = new BaseServiceWrapper(mockProvider);
|
|
22
20
|
wrapper.request().subscribe(result => {
|
|
23
21
|
expect(result.response).toEqual({ foo: 'bar' });
|
|
24
22
|
done();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from '../utils/networking-import.js';
|
|
2
2
|
import type { AxiosInterceptorManager } from 'axios';
|
|
3
|
-
import { AxiosObservable } from './axios.observable';
|
|
3
|
+
import { AxiosObservable } from './axios.observable.js';
|
|
4
4
|
export interface Axiosable {
|
|
5
5
|
request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
6
6
|
get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
@@ -21,16 +21,9 @@ declare class HttpService implements Axiosable {
|
|
|
21
21
|
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
22
22
|
response: AxiosInterceptorManager<AxiosResponse>;
|
|
23
23
|
};
|
|
24
|
-
constructor(axiosInstance:
|
|
25
|
-
get defaults():
|
|
26
|
-
|
|
27
|
-
[key: string]: import("axios").AxiosHeaderValue;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
get interceptors(): {
|
|
31
|
-
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
32
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
33
|
-
};
|
|
24
|
+
constructor(axiosInstance: any);
|
|
25
|
+
get defaults(): any;
|
|
26
|
+
get interceptors(): any;
|
|
34
27
|
static request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
35
28
|
static get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
36
29
|
static post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpService = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { axios } from '../utils/networking-import.js';
|
|
3
|
+
import { createObservable } from './axios.observable.js';
|
|
7
4
|
class HttpService {
|
|
8
5
|
constructor(axiosInstance) {
|
|
9
6
|
this.axiosInstance = axiosInstance;
|
|
@@ -16,53 +13,53 @@ class HttpService {
|
|
|
16
13
|
}
|
|
17
14
|
// Static methods
|
|
18
15
|
static request(config) {
|
|
19
|
-
return
|
|
16
|
+
return createObservable(axios.request, [config]);
|
|
20
17
|
}
|
|
21
18
|
static get(url, config) {
|
|
22
|
-
return
|
|
19
|
+
return createObservable(axios.get, [url, config]);
|
|
23
20
|
}
|
|
24
21
|
static post(url, data, config) {
|
|
25
|
-
return
|
|
22
|
+
return createObservable(axios.post, [url, data, config]);
|
|
26
23
|
}
|
|
27
24
|
static put(url, data, config) {
|
|
28
|
-
return
|
|
25
|
+
return createObservable(axios.put, [url, data, config]);
|
|
29
26
|
}
|
|
30
27
|
static patch(url, data, config) {
|
|
31
|
-
return
|
|
28
|
+
return createObservable(axios.patch, [url, data, config]);
|
|
32
29
|
}
|
|
33
30
|
static delete(url, config) {
|
|
34
|
-
return
|
|
31
|
+
return createObservable(axios.delete, [url, config]);
|
|
35
32
|
}
|
|
36
33
|
static head(url, config) {
|
|
37
|
-
return
|
|
34
|
+
return createObservable(axios.head, [url, config]);
|
|
38
35
|
}
|
|
39
36
|
static create(config) {
|
|
40
|
-
return new HttpService(
|
|
37
|
+
return new HttpService(axios.create(config));
|
|
41
38
|
}
|
|
42
39
|
// Instance methods
|
|
43
40
|
request(config) {
|
|
44
|
-
return
|
|
41
|
+
return createObservable(this.axiosInstance.request, [config]);
|
|
45
42
|
}
|
|
46
43
|
get(url, config) {
|
|
47
|
-
return
|
|
44
|
+
return createObservable(this.axiosInstance.get, [url, config]);
|
|
48
45
|
}
|
|
49
46
|
post(url, data, config) {
|
|
50
|
-
return
|
|
47
|
+
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
51
48
|
}
|
|
52
49
|
put(url, data, config) {
|
|
53
|
-
return
|
|
50
|
+
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
54
51
|
}
|
|
55
52
|
patch(url, data, config) {
|
|
56
|
-
return
|
|
53
|
+
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
57
54
|
}
|
|
58
55
|
delete(url, config) {
|
|
59
|
-
return
|
|
56
|
+
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
60
57
|
}
|
|
61
58
|
head(url, config) {
|
|
62
|
-
return
|
|
59
|
+
return createObservable(this.axiosInstance.head, [url, config]);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
HttpService.
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
HttpService.defaults = axios.defaults;
|
|
63
|
+
HttpService.interceptors = axios.interceptors;
|
|
64
|
+
export default HttpService;
|
|
65
|
+
export { HttpService };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
-
import { SmessService } from './smess.service';
|
|
3
|
-
import { Observable } from "rxjs";
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types.js';
|
|
2
|
+
import { SmessService } from './smess.service.js';
|
|
3
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
4
|
export interface AuthLoginRequest {
|
|
5
5
|
identifier: string;
|
|
6
6
|
password: string;
|
|
@@ -22,15 +22,16 @@ export type AuthLoginResponse = {
|
|
|
22
22
|
token: unknown;
|
|
23
23
|
refresh_token: unknown;
|
|
24
24
|
};
|
|
25
|
-
export type AuthTarget = '
|
|
25
|
+
export type AuthTarget = 'login' | 'logout' | 'change-password' | 'password-forgot' | 'reset-password' | 'verify-reset-password-token';
|
|
26
26
|
export declare class AuthProvider implements ProviderType {
|
|
27
27
|
private readonly config;
|
|
28
28
|
private readonly target;
|
|
29
|
-
|
|
29
|
+
private readonly $authToken;
|
|
30
|
+
constructor(config: NetworkingConfig, target: AuthTarget, $authToken: BehaviorSubject<string | null>);
|
|
30
31
|
get baseURL(): string;
|
|
31
32
|
get path(): string;
|
|
32
33
|
get method(): string;
|
|
33
|
-
get headers(): Record<string, string
|
|
34
|
+
get headers(): Record<string, string>;
|
|
34
35
|
getPath(...queryParams: unknown[]): string;
|
|
35
36
|
}
|
|
36
37
|
export interface AuthServiceType {
|
|
@@ -43,8 +44,9 @@ export interface AuthServiceType {
|
|
|
43
44
|
verifyResetPasswordToken(token: string): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
|
|
44
45
|
}
|
|
45
46
|
export declare class AuthService implements AuthServiceType {
|
|
46
|
-
private config;
|
|
47
|
-
|
|
47
|
+
private readonly config;
|
|
48
|
+
private readonly $authToken;
|
|
49
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
48
50
|
provider(target: AuthTarget): SmessService<AuthProvider>;
|
|
49
51
|
login(payload: AuthLoginRequest): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
|
|
50
52
|
logout(): Observable<NetworkingUIEventWrapped<void>>;
|
|
@@ -1,77 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const smess_service_1 = require("./smess.service");
|
|
5
|
-
class AuthProvider {
|
|
6
|
-
constructor(config, target) {
|
|
1
|
+
import { Accept, SMESSHeader, SmessService } from './smess.service.js';
|
|
2
|
+
export class AuthProvider {
|
|
3
|
+
constructor(config, target, $authToken) {
|
|
7
4
|
this.config = config;
|
|
8
5
|
this.target = target;
|
|
6
|
+
this.$authToken = $authToken;
|
|
9
7
|
}
|
|
10
8
|
get baseURL() {
|
|
11
|
-
return `${this.config.baseUrl}
|
|
9
|
+
return this.config.version ? `${this.config.baseUrl}/${this.config.version}` : this.config.baseUrl;
|
|
12
10
|
}
|
|
13
11
|
get path() {
|
|
14
12
|
switch (this.target) {
|
|
15
13
|
case 'login':
|
|
16
14
|
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
15
|
case 'password-forgot':
|
|
26
16
|
return '/authentication/forgot-password';
|
|
27
|
-
case 'change-password':
|
|
28
|
-
return '/authentication/change-password';
|
|
29
17
|
case 'reset-password':
|
|
30
18
|
return '/authentication/reset-password';
|
|
19
|
+
case 'verify-reset-password-token':
|
|
20
|
+
return '/authentication/verify-reset-password-token';
|
|
21
|
+
case 'logout':
|
|
22
|
+
return '/authentication/logout';
|
|
23
|
+
case 'change-password':
|
|
24
|
+
return '/authentication/change-password';
|
|
31
25
|
default:
|
|
32
26
|
return '/authentication';
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
29
|
get method() {
|
|
36
30
|
switch (this.target) {
|
|
37
|
-
case 'get-profile':
|
|
38
|
-
return 'GET';
|
|
39
|
-
case 'update-profile':
|
|
40
|
-
return 'PUT';
|
|
41
31
|
default:
|
|
42
32
|
return 'POST';
|
|
43
33
|
}
|
|
44
34
|
}
|
|
45
35
|
get headers() {
|
|
36
|
+
let authHeaders = {};
|
|
46
37
|
switch (this.target) {
|
|
47
38
|
case 'login':
|
|
48
|
-
|
|
49
|
-
case '
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
case 'password-forgot':
|
|
40
|
+
case 'reset-password':
|
|
41
|
+
case 'verify-reset-password-token':
|
|
42
|
+
authHeaders = SmessService.getHeaders(Accept.V1);
|
|
43
|
+
break;
|
|
53
44
|
default:
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
authHeaders = SmessService.getHeaders(Accept.V1, this.$authToken.value);
|
|
46
|
+
}
|
|
47
|
+
if (this.config.clientId) {
|
|
48
|
+
authHeaders[SMESSHeader.ClientId] = this.config.clientId;
|
|
49
|
+
}
|
|
50
|
+
if (this.config.apiKey) {
|
|
51
|
+
authHeaders[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
56
52
|
}
|
|
53
|
+
return SmessService.filterHeaders(authHeaders);
|
|
57
54
|
}
|
|
58
55
|
getPath(...queryParams) {
|
|
59
56
|
let definedPath = this.path;
|
|
60
57
|
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
61
|
-
params
|
|
58
|
+
params?.forEach((value, index) => {
|
|
62
59
|
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
63
60
|
});
|
|
64
61
|
return definedPath;
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
constructor(config) {
|
|
64
|
+
export class AuthService {
|
|
65
|
+
constructor(config, $authToken) {
|
|
70
66
|
this.config = config;
|
|
67
|
+
this.$authToken = $authToken;
|
|
71
68
|
}
|
|
72
69
|
provider(target) {
|
|
73
|
-
const targetWrapper = new AuthProvider(this.config, target);
|
|
74
|
-
return new
|
|
70
|
+
const targetWrapper = new AuthProvider(this.config, target, this.$authToken);
|
|
71
|
+
return new SmessService(targetWrapper);
|
|
75
72
|
}
|
|
76
73
|
login(payload) {
|
|
77
74
|
return this.provider('login').request(payload);
|
|
@@ -92,4 +89,3 @@ class AuthService {
|
|
|
92
89
|
return this.provider('verify-reset-password-token').request({ token });
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
|
-
exports.AuthService = AuthService;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const types_1 = require("../types/types");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
1
|
+
import { AuthService } from './auth.service.js';
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel } from '../types/types.js';
|
|
3
|
+
import { of, BehaviorSubject } from 'rxjs';
|
|
6
4
|
describe('AuthService', () => {
|
|
7
5
|
const config = {
|
|
8
6
|
baseUrl: 'https://api.example.com',
|
|
@@ -11,8 +9,10 @@ describe('AuthService', () => {
|
|
|
11
9
|
apiKey: 'test-api-key',
|
|
12
10
|
};
|
|
13
11
|
let service;
|
|
12
|
+
let $authToken;
|
|
14
13
|
beforeEach(() => {
|
|
15
|
-
|
|
14
|
+
$authToken = new BehaviorSubject(null);
|
|
15
|
+
service = new AuthService(config, $authToken);
|
|
16
16
|
});
|
|
17
17
|
it('login success', async () => {
|
|
18
18
|
const payload = { identifier: 'user', password: 'pass' };
|
|
@@ -23,57 +23,57 @@ describe('AuthService', () => {
|
|
|
23
23
|
refresh_token: 'refresh',
|
|
24
24
|
};
|
|
25
25
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
26
|
-
request: () =>
|
|
26
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
27
27
|
});
|
|
28
28
|
const result = await service.login(payload).toPromise();
|
|
29
|
-
expect(result
|
|
30
|
-
expect(result
|
|
29
|
+
expect(result?.hasSuccess).toBe(true);
|
|
30
|
+
expect(result?.response).toEqual(response);
|
|
31
31
|
});
|
|
32
32
|
it('login error', async () => {
|
|
33
33
|
const payload = { identifier: 'user', password: 'wrong' };
|
|
34
34
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
35
|
-
request: () =>
|
|
35
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
36
36
|
});
|
|
37
37
|
const result = await service.login(payload).toPromise();
|
|
38
|
-
expect(result
|
|
39
|
-
expect(result
|
|
38
|
+
expect(result?.hasFailed).toBe(true);
|
|
39
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
40
40
|
});
|
|
41
41
|
it('logout success', async () => {
|
|
42
42
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
43
|
-
request: () =>
|
|
43
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(undefined)),
|
|
44
44
|
});
|
|
45
45
|
const result = await service.logout().toPromise();
|
|
46
|
-
expect(result
|
|
46
|
+
expect(result?.hasSuccess).toBe(true);
|
|
47
47
|
});
|
|
48
48
|
it('forgotPassword success', async () => {
|
|
49
49
|
const payload = { identifier: 'user' };
|
|
50
50
|
const response = { data: 'ok' };
|
|
51
51
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
52
|
-
request: () =>
|
|
52
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
53
53
|
});
|
|
54
54
|
const result = await service.forgotPassword(payload).toPromise();
|
|
55
|
-
expect(result
|
|
56
|
-
expect(result
|
|
55
|
+
expect(result?.hasSuccess).toBe(true);
|
|
56
|
+
expect(result?.response).toEqual(response);
|
|
57
57
|
});
|
|
58
58
|
it('changePassword success', async () => {
|
|
59
59
|
const payload = { old_password: 'old', password: 'new' };
|
|
60
60
|
const response = { data: 'changed' };
|
|
61
61
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
62
|
-
request: () =>
|
|
62
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
63
63
|
});
|
|
64
64
|
const result = await service.changePassword(payload).toPromise();
|
|
65
|
-
expect(result
|
|
66
|
-
expect(result
|
|
65
|
+
expect(result?.hasSuccess).toBe(true);
|
|
66
|
+
expect(result?.response).toEqual(response);
|
|
67
67
|
});
|
|
68
68
|
it('resetPassword success', async () => {
|
|
69
69
|
const payload = { token: 'token', password: 'newpass' };
|
|
70
70
|
const response = { data: 'reset' };
|
|
71
71
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
72
|
-
request: () =>
|
|
72
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
73
73
|
});
|
|
74
74
|
const result = await service.resetPassword(payload).toPromise();
|
|
75
|
-
expect(result
|
|
76
|
-
expect(result
|
|
75
|
+
expect(result?.hasSuccess).toBe(true);
|
|
76
|
+
expect(result?.response).toEqual(response);
|
|
77
77
|
});
|
|
78
78
|
it('verifyResetPasswordToken success', async () => {
|
|
79
79
|
const token = 'token';
|
|
@@ -84,46 +84,46 @@ describe('AuthService', () => {
|
|
|
84
84
|
refresh_token: 'refresh',
|
|
85
85
|
};
|
|
86
86
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
87
|
-
request: () =>
|
|
87
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
88
88
|
});
|
|
89
89
|
const result = await service.verifyResetPasswordToken(token).toPromise();
|
|
90
|
-
expect(result
|
|
91
|
-
expect(result
|
|
90
|
+
expect(result?.hasSuccess).toBe(true);
|
|
91
|
+
expect(result?.response).toEqual(response);
|
|
92
92
|
});
|
|
93
93
|
it('forgotPassword error', async () => {
|
|
94
94
|
const payload = { identifier: 'user' };
|
|
95
95
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
96
|
-
request: () =>
|
|
96
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
97
97
|
});
|
|
98
98
|
const result = await service.forgotPassword(payload).toPromise();
|
|
99
|
-
expect(result
|
|
100
|
-
expect(result
|
|
99
|
+
expect(result?.hasFailed).toBe(true);
|
|
100
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
101
101
|
});
|
|
102
102
|
it('changePassword error', async () => {
|
|
103
103
|
const payload = { old_password: 'old', password: 'bad' };
|
|
104
104
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
105
|
-
request: () =>
|
|
105
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
106
106
|
});
|
|
107
107
|
const result = await service.changePassword(payload).toPromise();
|
|
108
|
-
expect(result
|
|
109
|
-
expect(result
|
|
108
|
+
expect(result?.hasFailed).toBe(true);
|
|
109
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
110
110
|
});
|
|
111
111
|
it('resetPassword error', async () => {
|
|
112
112
|
const payload = { token: 'bad', password: 'bad' };
|
|
113
113
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
114
|
-
request: () =>
|
|
114
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
115
115
|
});
|
|
116
116
|
const result = await service.resetPassword(payload).toPromise();
|
|
117
|
-
expect(result
|
|
118
|
-
expect(result
|
|
117
|
+
expect(result?.hasFailed).toBe(true);
|
|
118
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
119
119
|
});
|
|
120
120
|
it('verifyResetPasswordToken error', async () => {
|
|
121
121
|
const token = 'bad';
|
|
122
122
|
jest.spyOn(service, 'provider').mockReturnValue({
|
|
123
|
-
request: () =>
|
|
123
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
124
124
|
});
|
|
125
125
|
const result = await service.verifyResetPasswordToken(token).toPromise();
|
|
126
|
-
expect(result
|
|
127
|
-
expect(result
|
|
126
|
+
expect(result?.hasFailed).toBe(true);
|
|
127
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
128
128
|
});
|
|
129
129
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types.js';
|
|
2
|
+
import { SmessService } from './smess.service.js';
|
|
3
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
|
+
export type CustomerTarget = 'register' | 'get-profile' | 'update-profile';
|
|
5
|
+
export interface CustomerRegisterRequest {
|
|
6
|
+
client_id?: string;
|
|
7
|
+
email: string;
|
|
8
|
+
password: string;
|
|
9
|
+
phone_number?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
address?: string;
|
|
12
|
+
tax_identification_number?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface CustomerUpdateRequest {
|
|
15
|
+
name: string;
|
|
16
|
+
address: string;
|
|
17
|
+
postal_code: string;
|
|
18
|
+
city: string;
|
|
19
|
+
state: string | null;
|
|
20
|
+
country: string | null;
|
|
21
|
+
contact_email: string | null;
|
|
22
|
+
phone_number: string | null;
|
|
23
|
+
}
|
|
24
|
+
export declare class CustomerProvider implements ProviderType {
|
|
25
|
+
private readonly config;
|
|
26
|
+
private readonly target;
|
|
27
|
+
private readonly $authToken;
|
|
28
|
+
constructor(config: NetworkingConfig, target: CustomerTarget, $authToken: BehaviorSubject<string | null>);
|
|
29
|
+
get baseURL(): string;
|
|
30
|
+
get path(): string;
|
|
31
|
+
get method(): string;
|
|
32
|
+
get headers(): Record<string, string>;
|
|
33
|
+
getPath(...queryParams: unknown[]): string;
|
|
34
|
+
}
|
|
35
|
+
export declare class CustomerService {
|
|
36
|
+
private readonly config;
|
|
37
|
+
private readonly $authToken;
|
|
38
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
39
|
+
provider(target: CustomerTarget): SmessService<CustomerProvider>;
|
|
40
|
+
register(payload: CustomerRegisterRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
41
|
+
getProfile(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
42
|
+
updateProfile(payload: CustomerUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Accept, SMESSHeader, SmessService } from './smess.service.js';
|
|
2
|
+
export class CustomerProvider {
|
|
3
|
+
constructor(config, target, $authToken) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
this.target = target;
|
|
6
|
+
this.$authToken = $authToken;
|
|
7
|
+
}
|
|
8
|
+
get baseURL() {
|
|
9
|
+
return this.config.version ? `${this.config.baseUrl}/${this.config.version}` : this.config.baseUrl;
|
|
10
|
+
}
|
|
11
|
+
get path() {
|
|
12
|
+
switch (this.target) {
|
|
13
|
+
case 'register':
|
|
14
|
+
return '/authentication/customer/register';
|
|
15
|
+
case 'get-profile':
|
|
16
|
+
return '/authentication/customer/get-profile';
|
|
17
|
+
case 'update-profile':
|
|
18
|
+
return '/authentication/customer/update';
|
|
19
|
+
default:
|
|
20
|
+
return '/authentication/customer';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get method() {
|
|
24
|
+
switch (this.target) {
|
|
25
|
+
case 'get-profile':
|
|
26
|
+
return 'GET';
|
|
27
|
+
case 'update-profile':
|
|
28
|
+
return 'PUT';
|
|
29
|
+
default:
|
|
30
|
+
return 'POST';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
get headers() {
|
|
34
|
+
let headers = SmessService.getHeaders(Accept.V1, this.$authToken.value);
|
|
35
|
+
if (this.config.clientId) {
|
|
36
|
+
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
37
|
+
}
|
|
38
|
+
if (this.config.apiKey) {
|
|
39
|
+
headers[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
40
|
+
}
|
|
41
|
+
return SmessService.filterHeaders(headers);
|
|
42
|
+
}
|
|
43
|
+
getPath(...queryParams) {
|
|
44
|
+
let definedPath = this.path;
|
|
45
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
46
|
+
params?.forEach((value, index) => {
|
|
47
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
48
|
+
});
|
|
49
|
+
return definedPath;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class CustomerService {
|
|
53
|
+
constructor(config, $authToken) {
|
|
54
|
+
this.config = config;
|
|
55
|
+
this.$authToken = $authToken;
|
|
56
|
+
}
|
|
57
|
+
provider(target) {
|
|
58
|
+
const targetWrapper = new CustomerProvider(this.config, target, this.$authToken);
|
|
59
|
+
return new SmessService(targetWrapper);
|
|
60
|
+
}
|
|
61
|
+
register(payload) {
|
|
62
|
+
return this.provider('register').request(payload);
|
|
63
|
+
}
|
|
64
|
+
getProfile() {
|
|
65
|
+
return this.provider('get-profile').request();
|
|
66
|
+
}
|
|
67
|
+
updateProfile(payload) {
|
|
68
|
+
return this.provider('update-profile').request(payload);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|