@smess/networking 1.0.29 → 1.0.30

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.
Files changed (131) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.js +6 -0
  3. package/dist/services/storefront.cart.service.d.ts +73 -0
  4. package/dist/services/storefront.cart.service.js +167 -0
  5. package/dist/services/storefront.cart.service.test.d.ts +1 -0
  6. package/dist/services/storefront.cart.service.test.js +211 -0
  7. package/dist/services/storefront.checkout.service.d.ts +62 -0
  8. package/dist/services/storefront.checkout.service.js +75 -0
  9. package/dist/services/storefront.checkout.service.test.d.ts +1 -0
  10. package/dist/services/storefront.checkout.service.test.js +158 -0
  11. package/dist/services/storefront.customer.metadata.service.d.ts +91 -0
  12. package/dist/services/storefront.customer.metadata.service.js +225 -0
  13. package/dist/services/storefront.customer.metadata.service.test.d.ts +1 -0
  14. package/dist/services/storefront.customer.metadata.service.test.js +271 -0
  15. package/dist/services/storefront.order.service.d.ts +45 -0
  16. package/dist/services/storefront.order.service.js +99 -0
  17. package/dist/services/storefront.order.service.test.d.ts +1 -0
  18. package/dist/services/storefront.order.service.test.js +158 -0
  19. package/dist/services/storefront.product.service.d.ts +52 -0
  20. package/dist/services/storefront.product.service.js +75 -0
  21. package/dist/services/storefront.product.service.test.d.ts +1 -0
  22. package/dist/services/storefront.product.service.test.js +120 -0
  23. package/dist/services/storefront.store.service.d.ts +52 -0
  24. package/dist/services/storefront.store.service.js +140 -0
  25. package/dist/services/storefront.store.service.test.d.ts +1 -0
  26. package/dist/services/storefront.store.service.test.js +90 -0
  27. package/dist/src/core/axios.d.ts +51 -0
  28. package/dist/src/core/axios.js +65 -0
  29. package/dist/src/core/axios.observable.d.ts +11 -0
  30. package/dist/src/core/axios.observable.js +58 -0
  31. package/dist/src/core/base.provider.advanced.test.d.ts +1 -0
  32. package/dist/src/core/base.provider.advanced.test.js +29 -0
  33. package/dist/src/core/base.provider.d.ts +15 -0
  34. package/dist/src/core/base.provider.js +13 -0
  35. package/dist/src/core/base.provider.test.d.ts +1 -0
  36. package/dist/src/core/base.provider.test.js +36 -0
  37. package/dist/src/core/base.service.wrapper.advanced.test.d.ts +1 -0
  38. package/dist/src/core/base.service.wrapper.advanced.test.js +39 -0
  39. package/dist/src/core/base.service.wrapper.d.ts +7 -0
  40. package/dist/src/core/base.service.wrapper.js +11 -0
  41. package/dist/src/core/base.service.wrapper.test.d.ts +1 -0
  42. package/dist/src/core/base.service.wrapper.test.js +25 -0
  43. package/dist/src/core/rx.http.service.d.ts +51 -0
  44. package/dist/src/core/rx.http.service.js +65 -0
  45. package/dist/src/index.d.ts +25 -0
  46. package/dist/src/index.js +29 -0
  47. package/dist/src/services/auth.service.d.ts +65 -0
  48. package/dist/src/services/auth.service.js +197 -0
  49. package/dist/src/services/auth.service.test.d.ts +1 -0
  50. package/dist/src/services/auth.service.test.js +334 -0
  51. package/dist/src/services/cache.service.d.ts +31 -0
  52. package/dist/src/services/cache.service.js +77 -0
  53. package/dist/src/services/cache.service.test.d.ts +1 -0
  54. package/dist/src/services/cache.service.test.js +88 -0
  55. package/dist/src/services/customer.service.d.ts +199 -0
  56. package/dist/src/services/customer.service.js +114 -0
  57. package/dist/src/services/customer.service.test.d.ts +1 -0
  58. package/dist/src/services/customer.service.test.js +430 -0
  59. package/dist/src/services/employee.service.d.ts +73 -0
  60. package/dist/src/services/employee.service.js +74 -0
  61. package/dist/src/services/employee.service.test.d.ts +1 -0
  62. package/dist/src/services/employee.service.test.js +127 -0
  63. package/dist/src/services/logger.service.d.ts +31 -0
  64. package/dist/src/services/logger.service.js +93 -0
  65. package/dist/src/services/logger.service.test.d.ts +1 -0
  66. package/dist/src/services/logger.service.test.js +31 -0
  67. package/dist/src/services/order.service.d.ts +73 -0
  68. package/dist/src/services/order.service.js +97 -0
  69. package/dist/src/services/order.service.test.d.ts +1 -0
  70. package/dist/src/services/order.service.test.js +163 -0
  71. package/dist/src/services/product.service.d.ts +21 -0
  72. package/dist/src/services/product.service.js +42 -0
  73. package/dist/src/services/product.service.test.d.ts +1 -0
  74. package/dist/src/services/product.service.test.js +61 -0
  75. package/dist/src/services/smess.service.d.ts +36 -0
  76. package/dist/src/services/smess.service.js +128 -0
  77. package/dist/src/services/smess.service.test.d.ts +1 -0
  78. package/dist/src/services/smess.service.test.js +103 -0
  79. package/dist/src/services/store.cart.service.d.ts +158 -0
  80. package/dist/src/services/store.cart.service.js +177 -0
  81. package/dist/src/services/store.cart.service.test.d.ts +1 -0
  82. package/dist/src/services/store.cart.service.test.js +394 -0
  83. package/dist/src/services/store.product.service.d.ts +124 -0
  84. package/dist/src/services/store.product.service.js +102 -0
  85. package/dist/src/services/store.product.service.test.d.ts +1 -0
  86. package/dist/src/services/store.product.service.test.js +319 -0
  87. package/dist/src/services/store.service.d.ts +79 -0
  88. package/dist/src/services/store.service.js +235 -0
  89. package/dist/src/services/store.service.test.d.ts +1 -0
  90. package/dist/src/services/store.service.test.js +274 -0
  91. package/dist/src/services/storefront.cart.service.d.ts +73 -0
  92. package/dist/src/services/storefront.cart.service.js +167 -0
  93. package/dist/src/services/storefront.cart.service.test.d.ts +1 -0
  94. package/dist/src/services/storefront.cart.service.test.js +211 -0
  95. package/dist/src/services/storefront.checkout.service.d.ts +62 -0
  96. package/dist/src/services/storefront.checkout.service.js +75 -0
  97. package/dist/src/services/storefront.checkout.service.test.d.ts +1 -0
  98. package/dist/src/services/storefront.checkout.service.test.js +158 -0
  99. package/dist/src/services/storefront.customer.metadata.service.d.ts +91 -0
  100. package/dist/src/services/storefront.customer.metadata.service.js +225 -0
  101. package/dist/src/services/storefront.customer.metadata.service.test.d.ts +1 -0
  102. package/dist/src/services/storefront.customer.metadata.service.test.js +271 -0
  103. package/dist/src/services/storefront.order.service.d.ts +45 -0
  104. package/dist/src/services/storefront.order.service.js +99 -0
  105. package/dist/src/services/storefront.order.service.test.d.ts +1 -0
  106. package/dist/src/services/storefront.order.service.test.js +158 -0
  107. package/dist/src/services/storefront.product.service.d.ts +52 -0
  108. package/dist/src/services/storefront.product.service.js +75 -0
  109. package/dist/src/services/storefront.product.service.test.d.ts +1 -0
  110. package/dist/src/services/storefront.product.service.test.js +120 -0
  111. package/dist/src/services/storefront.store.service.d.ts +52 -0
  112. package/dist/src/services/storefront.store.service.js +140 -0
  113. package/dist/src/services/storefront.store.service.test.d.ts +1 -0
  114. package/dist/src/services/storefront.store.service.test.js +90 -0
  115. package/dist/src/services/user.service.d.ts +16 -0
  116. package/dist/src/services/user.service.js +37 -0
  117. package/dist/src/services/user.service.test.d.ts +1 -0
  118. package/dist/src/services/user.service.test.js +52 -0
  119. package/dist/src/services/utils/withAuthReset.d.ts +3 -0
  120. package/dist/src/services/utils/withAuthReset.js +8 -0
  121. package/dist/src/types/types.d.ts +93 -0
  122. package/dist/src/types/types.js +82 -0
  123. package/dist/src/types/types.test.d.ts +1 -0
  124. package/dist/src/types/types.test.js +25 -0
  125. package/dist/src/utils/cache-import.d.ts +3 -0
  126. package/dist/src/utils/cache-import.js +2 -0
  127. package/dist/src/utils/networking-import.d.ts +4 -0
  128. package/dist/src/utils/networking-import.js +3 -0
  129. package/dist/src/utils/rxjs-import.d.ts +5 -0
  130. package/dist/src/utils/rxjs-import.js +5 -0
  131. package/package.json +1 -1
@@ -0,0 +1,29 @@
1
+ import { BaseProvider } from "./base.provider";
2
+ describe("BaseProvider Advanced", () => {
3
+ const config = {
4
+ baseUrl: "https://api.example.com",
5
+ isProd: false,
6
+ clientId: "test-client",
7
+ apiKey: "test-key",
8
+ };
9
+ it("should support dynamic getPath for multiple params", () => {
10
+ const provider = new BaseProvider({
11
+ config,
12
+ path: "/resource/:id/:action",
13
+ method: "GET",
14
+ headers: {},
15
+ getPath: (id, action) => `/resource/${id}/${action}`,
16
+ });
17
+ expect(provider.getPath("42", "edit")).toBe("/resource/42/edit");
18
+ });
19
+ it("should allow dynamic headers and method", () => {
20
+ const provider = new BaseProvider({
21
+ config,
22
+ path: "/resource",
23
+ method: "PATCH",
24
+ headers: { Authorization: "Bearer token" },
25
+ });
26
+ expect(provider.method).toBe("PATCH");
27
+ expect(provider.headers.Authorization).toBe("Bearer token");
28
+ });
29
+ });
@@ -0,0 +1,15 @@
1
+ import { ProviderType, NetworkingConfig } from "../types/types";
2
+ export declare class BaseProvider implements ProviderType {
3
+ baseURL: string;
4
+ path: string;
5
+ method: string;
6
+ headers: Record<string, string | undefined>;
7
+ getPath: (...queryParams: unknown[]) => string;
8
+ constructor({ config, path, method, headers, getPath, }: {
9
+ config: NetworkingConfig;
10
+ path: string;
11
+ method: string;
12
+ headers?: any;
13
+ getPath?: (...queryParams: any[]) => string;
14
+ });
15
+ }
@@ -0,0 +1,13 @@
1
+ export class BaseProvider {
2
+ constructor({ config, path, method, headers = {}, getPath = () => path, }) {
3
+ this.baseURL = config.baseUrl;
4
+ this.path = path;
5
+ this.method = method;
6
+ this.headers = {
7
+ ...headers,
8
+ "X-Client-Id": config.clientId,
9
+ "X-Api-Key": config.apiKey,
10
+ };
11
+ this.getPath = getPath || (() => path);
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { BaseProvider } from "./base.provider";
2
+ describe("BaseProvider", () => {
3
+ const config = {
4
+ baseUrl: "https://api.example.com",
5
+ isProd: false,
6
+ clientId: "test-client",
7
+ apiKey: "test-key",
8
+ };
9
+ it("should construct with required fields", () => {
10
+ const provider = new BaseProvider({
11
+ config,
12
+ path: "/resource",
13
+ method: "GET",
14
+ headers: { foo: "bar" },
15
+ });
16
+ expect(provider.baseURL).toBe("https://api.example.com");
17
+ expect(provider.path).toBe("/resource");
18
+ expect(provider.method).toBe("GET");
19
+ expect(provider.headers).toEqual({
20
+ foo: "bar",
21
+ "X-Client-Id": "test-client",
22
+ "X-Api-Key": "test-key",
23
+ });
24
+ expect(provider.getPath()).toBe("/resource");
25
+ });
26
+ it("should use custom getPath if provided", () => {
27
+ const provider = new BaseProvider({
28
+ config,
29
+ path: "/resource/:id",
30
+ method: "GET",
31
+ headers: {},
32
+ getPath: (id) => `/resource/${id}`,
33
+ });
34
+ expect(provider.getPath("123")).toBe("/resource/123");
35
+ });
36
+ });
@@ -0,0 +1,39 @@
1
+ import { BaseServiceWrapper } from "./base.service.wrapper";
2
+ import { NetworkingUIEventWrapped } from "../types/types";
3
+ import { of } from "rxjs";
4
+ import { map } from "rxjs/operators";
5
+ describe("BaseServiceWrapper Advanced", () => {
6
+ const mockProvider = {
7
+ baseURL: "https://api.example.com",
8
+ path: "/resource",
9
+ method: "GET",
10
+ headers: {},
11
+ getPath: () => "/resource",
12
+ };
13
+ it("should allow use of RxJS operators", (done) => {
14
+ const wrapper = new BaseServiceWrapper(mockProvider);
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
16
+ wrapper.request = (() => of(NetworkingUIEventWrapped.succeeded({ foo: 1 })));
17
+ wrapper
18
+ .request()
19
+ .pipe(map((r) => r.response))
20
+ .subscribe((val) => {
21
+ expect(val).toEqual({ foo: 1 });
22
+ done();
23
+ });
24
+ });
25
+ it("should handle multiple concurrent requests", (done) => {
26
+ const wrapper = new BaseServiceWrapper(mockProvider);
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
28
+ wrapper.request = ((payload) => of(NetworkingUIEventWrapped.succeeded({ foo: payload })));
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for test compatibility
30
+ const results = [];
31
+ wrapper.request(1).subscribe((r) => {
32
+ results.push(r.response);
33
+ if (results.length === 1) {
34
+ expect(results[0]).toEqual({ foo: 1 });
35
+ done();
36
+ }
37
+ });
38
+ });
39
+ });
@@ -0,0 +1,7 @@
1
+ import { ProviderType, NetworkingUIEventWrapped } from "../types/types";
2
+ import { Observable } from "rxjs";
3
+ export declare class BaseServiceWrapper<T extends ProviderType> {
4
+ protected provider: T;
5
+ constructor(provider: T);
6
+ request<R = any>(payload?: any): Observable<NetworkingUIEventWrapped<R>>;
7
+ }
@@ -0,0 +1,11 @@
1
+ import { SmessService } from "../services/smess.service";
2
+ export class BaseServiceWrapper {
3
+ constructor(provider) {
4
+ this.provider = provider;
5
+ }
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for base service wrapper compatibility
7
+ request(payload) {
8
+ const service = new SmessService(this.provider);
9
+ return service.request(payload);
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { BaseServiceWrapper } from "./base.service.wrapper";
2
+ import { NetworkingUIEventWrapped } from "../types/types";
3
+ import { of } from "rxjs";
4
+ // Mock SmessService for testing
5
+ jest.mock("../services/smess.service", () => ({
6
+ SmessService: jest.fn().mockImplementation(() => ({
7
+ request: jest.fn(() => of(NetworkingUIEventWrapped.succeeded({ foo: "bar" }))),
8
+ })),
9
+ }));
10
+ describe("BaseServiceWrapper", () => {
11
+ const mockProvider = {
12
+ baseURL: "https://api.example.com",
13
+ path: "/resource",
14
+ method: "GET",
15
+ headers: {},
16
+ getPath: () => "/resource",
17
+ };
18
+ it("should delegate request to SmessService", (done) => {
19
+ const wrapper = new BaseServiceWrapper(mockProvider);
20
+ wrapper.request().subscribe((result) => {
21
+ expect(result.response).toEqual({ foo: "bar" });
22
+ done();
23
+ });
24
+ });
25
+ });
@@ -0,0 +1,51 @@
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "../utils/networking-import";
2
+ import type { AxiosInterceptorManager } from "axios";
3
+ import { AxiosObservable } from "./axios.observable";
4
+ export interface Axiosable {
5
+ request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
6
+ get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
7
+ head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
8
+ post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
9
+ put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
10
+ patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
11
+ delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
12
+ }
13
+ declare class HttpService implements Axiosable {
14
+ private axiosInstance;
15
+ static defaults: Omit<import("axios").AxiosDefaults<any>, "headers"> & {
16
+ headers: import("axios").HeadersDefaults & {
17
+ [key: string]: import("axios").AxiosHeaderValue;
18
+ };
19
+ };
20
+ static interceptors: {
21
+ request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
22
+ response: AxiosInterceptorManager<AxiosResponse>;
23
+ };
24
+ constructor(axiosInstance: AxiosInstance);
25
+ get defaults(): Omit<import("axios").AxiosDefaults<any>, "headers"> & {
26
+ headers: import("axios").HeadersDefaults & {
27
+ [key: string]: import("axios").AxiosHeaderValue;
28
+ };
29
+ };
30
+ get interceptors(): {
31
+ request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
32
+ response: AxiosInterceptorManager<AxiosResponse>;
33
+ };
34
+ static request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
35
+ static get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
36
+ static post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
37
+ static put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
38
+ static patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
39
+ static delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
40
+ static head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
41
+ static create(config: AxiosRequestConfig): HttpService;
42
+ request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
43
+ get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
44
+ post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
45
+ put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
46
+ patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
47
+ delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
48
+ head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
49
+ }
50
+ export default HttpService;
51
+ export { HttpService };
@@ -0,0 +1,65 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
2
+ import { axios, } from "../utils/networking-import";
3
+ import { createObservable } from "./axios.observable";
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 };
@@ -0,0 +1,25 @@
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/store.cart.service";
6
+ export * from "./services/store.product.service";
7
+ export * from "./services/customer.service";
8
+ export * from "./services/employee.service";
9
+ export * from "./services/order.service";
10
+ export * from "./services/cache.service";
11
+ export * from "./services/smess.service";
12
+ export * from "./services/utils/withAuthReset";
13
+ export * from "./services/storefront.product.service";
14
+ export * from "./services/storefront.store.service";
15
+ export * from "./services/storefront.cart.service";
16
+ export * from "./services/storefront.checkout.service";
17
+ export * from "./services/storefront.order.service";
18
+ export * from "./services/storefront.customer.metadata.service";
19
+ export * from "./core/base.provider";
20
+ export * from "./core/base.service.wrapper";
21
+ export * from "./core/axios.observable";
22
+ export * from "./types/types";
23
+ export { $logger } from "./services/logger.service";
24
+ export declare const baseURL: () => string;
25
+ export declare const apiVersion: () => string;
@@ -0,0 +1,29 @@
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/store.cart.service";
6
+ export * from "./services/store.product.service";
7
+ export * from "./services/customer.service";
8
+ export * from "./services/employee.service";
9
+ export * from "./services/order.service";
10
+ export * from "./services/cache.service";
11
+ export * from "./services/smess.service";
12
+ export * from "./services/utils/withAuthReset";
13
+ export * from "./services/storefront.product.service";
14
+ export * from "./services/storefront.store.service";
15
+ export * from "./services/storefront.cart.service";
16
+ export * from "./services/storefront.checkout.service";
17
+ export * from "./services/storefront.order.service";
18
+ export * from "./services/storefront.customer.metadata.service";
19
+ export * from "./core/base.provider";
20
+ export * from "./core/base.service.wrapper";
21
+ export * from "./core/axios.observable";
22
+ export * from "./types/types";
23
+ export { $logger } from "./services/logger.service";
24
+ export const baseURL = () => {
25
+ return "";
26
+ };
27
+ export const apiVersion = () => {
28
+ return "api/v1";
29
+ };
@@ -0,0 +1,65 @@
1
+ import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
2
+ import { SmessService } from "./smess.service";
3
+ import { BehaviorSubject, Observable } from "rxjs";
4
+ export interface AuthLoginRequest {
5
+ identifier: string;
6
+ password: string;
7
+ rememberMe?: boolean;
8
+ }
9
+ export interface ForgotPasswordRequest {
10
+ identifier: string;
11
+ }
12
+ export interface AuthChangePasswordRequest {
13
+ old_password: string;
14
+ password: string;
15
+ }
16
+ export interface ResetPasswordRequest {
17
+ token: string;
18
+ password: string;
19
+ }
20
+ export type AuthLoginResponse = {
21
+ token_type: unknown;
22
+ expires_in: unknown;
23
+ token: unknown;
24
+ refresh_token: unknown;
25
+ };
26
+ export type AuthTarget = "login" | "logout" | "change-password" | "password-forgot" | "reset-password" | "verify-reset-password-token";
27
+ export declare class AuthProvider implements ProviderType {
28
+ private readonly config;
29
+ private readonly target;
30
+ private readonly $authToken;
31
+ constructor(config: NetworkingConfig, target: AuthTarget, $authToken: BehaviorSubject<string | null>);
32
+ get baseURL(): string;
33
+ get path(): string;
34
+ get method(): string;
35
+ get headers(): Record<string, string>;
36
+ getPath(...queryParams: unknown[]): string;
37
+ }
38
+ export interface AuthServiceType {
39
+ provider(target: AuthTarget): SmessService<AuthProvider>;
40
+ login(payload: AuthLoginRequest): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
41
+ logout(): Observable<NetworkingUIEventWrapped<void>>;
42
+ forgotPassword(payload: ForgotPasswordRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
43
+ changePassword(payload: AuthChangePasswordRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
44
+ resetPassword(payload: ResetPasswordRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
45
+ verifyResetPasswordToken(token: string): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
46
+ }
47
+ export declare class AuthService implements AuthServiceType {
48
+ private readonly config;
49
+ private readonly $_authToken;
50
+ constructor(config: NetworkingConfig);
51
+ get $authToken(): BehaviorSubject<string | null>;
52
+ get currentAuthToken(): string | null;
53
+ private getValidToken;
54
+ private loadFromStorage;
55
+ private loadAuthFromStorage;
56
+ private saveAuthToStorage;
57
+ private clearAuthFromStorage;
58
+ provider(target: AuthTarget): SmessService<AuthProvider>;
59
+ login(payload: AuthLoginRequest): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
60
+ logout(): Observable<NetworkingUIEventWrapped<void>>;
61
+ forgotPassword(payload: ForgotPasswordRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
62
+ changePassword(payload: AuthChangePasswordRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
63
+ resetPassword(payload: ResetPasswordRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
64
+ verifyResetPasswordToken(token: string): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
65
+ }
@@ -0,0 +1,197 @@
1
+ import { Accept, SMESSHeader, SmessService } from "./smess.service";
2
+ import { BehaviorSubject } from "rxjs";
3
+ import { tap } from "rxjs/operators";
4
+ // LocalStorage keys for auth persistence
5
+ const AUTH_TOKEN_KEY = 'smess_auth_token';
6
+ const AUTH_RESPONSE_KEY = 'smess_auth_response';
7
+ export class AuthProvider {
8
+ constructor(config, target, $authToken) {
9
+ this.config = config;
10
+ this.target = target;
11
+ this.$authToken = $authToken;
12
+ }
13
+ get baseURL() {
14
+ return this.config.version
15
+ ? `${this.config.baseUrl}/${this.config.version}`
16
+ : this.config.baseUrl;
17
+ }
18
+ get path() {
19
+ switch (this.target) {
20
+ case "login":
21
+ return "/authentication/login_check";
22
+ case "password-forgot":
23
+ return "/authentication/forgot-password";
24
+ case "reset-password":
25
+ return "/authentication/reset-password";
26
+ case "verify-reset-password-token":
27
+ return "/authentication/verify-reset-password-token";
28
+ case "logout":
29
+ return "/authentication/logout";
30
+ case "change-password":
31
+ return "/authentication/change-password";
32
+ default:
33
+ return "/authentication";
34
+ }
35
+ }
36
+ get method() {
37
+ switch (this.target) {
38
+ default:
39
+ return "POST";
40
+ }
41
+ }
42
+ get headers() {
43
+ let authHeaders = {};
44
+ switch (this.target) {
45
+ case "login":
46
+ case "password-forgot":
47
+ case "reset-password":
48
+ case "verify-reset-password-token":
49
+ authHeaders = SmessService.getHeaders(Accept.V1);
50
+ break;
51
+ default:
52
+ authHeaders = SmessService.getHeaders(Accept.V1, this.$authToken.value);
53
+ }
54
+ if (this.config.clientId) {
55
+ authHeaders[SMESSHeader.ClientId] = this.config.clientId;
56
+ }
57
+ if (this.config.apiKey) {
58
+ authHeaders[SMESSHeader.ApiKey] = this.config.apiKey;
59
+ }
60
+ return SmessService.filterHeaders(authHeaders);
61
+ }
62
+ getPath(...queryParams) {
63
+ let definedPath = this.path;
64
+ const params = definedPath.match(/\$\{(.+?)\}/g);
65
+ params?.forEach((value, index) => {
66
+ definedPath = definedPath.replace(value, String(queryParams[index]));
67
+ });
68
+ return definedPath;
69
+ }
70
+ }
71
+ export class AuthService {
72
+ constructor(config) {
73
+ this.config = config;
74
+ this.$_authToken = new BehaviorSubject(null);
75
+ this.loadAuthFromStorage();
76
+ }
77
+ // Getter that returns BehaviorSubject with token validation
78
+ get $authToken() {
79
+ const currentToken = this.getValidToken();
80
+ if (currentToken !== this.$_authToken.value) {
81
+ this.$_authToken.next(currentToken);
82
+ }
83
+ return this.$_authToken;
84
+ }
85
+ // Get current auth token value
86
+ get currentAuthToken() {
87
+ return this.getValidToken();
88
+ }
89
+ // Get valid token from memory or localStorage
90
+ getValidToken() {
91
+ // If we have a token in memory, return it (assume it's valid)
92
+ if (this.$_authToken.value) {
93
+ return this.$_authToken.value;
94
+ }
95
+ // Otherwise, try to load from localStorage
96
+ return this.loadFromStorage();
97
+ }
98
+ // Load token from localStorage and check expiration
99
+ loadFromStorage() {
100
+ try {
101
+ const storedResponse = localStorage.getItem(AUTH_RESPONSE_KEY);
102
+ const storedAt = localStorage.getItem(`${AUTH_RESPONSE_KEY}_stored_at`);
103
+ if (storedResponse && storedAt) {
104
+ const authResponse = JSON.parse(storedResponse);
105
+ const storedTime = parseInt(storedAt, 10);
106
+ // Check if token is expired
107
+ if (authResponse.expires_in && typeof authResponse.expires_in === 'number') {
108
+ const expirationTime = storedTime + (authResponse.expires_in * 1000);
109
+ if (Date.now() >= expirationTime) {
110
+ // Token expired, clear storage
111
+ this.clearAuthFromStorage();
112
+ return null;
113
+ }
114
+ }
115
+ // Token is valid, store in memory and return
116
+ const token = String(authResponse.token);
117
+ this.$_authToken.next(token);
118
+ return token;
119
+ }
120
+ }
121
+ catch (error) {
122
+ console.warn('Failed to load token from localStorage:', error);
123
+ this.clearAuthFromStorage();
124
+ }
125
+ return null;
126
+ }
127
+ // Load auth token from localStorage on initialization
128
+ loadAuthFromStorage() {
129
+ this.loadFromStorage();
130
+ }
131
+ // Save auth response to localStorage
132
+ saveAuthToStorage(authResponse) {
133
+ try {
134
+ localStorage.setItem(AUTH_TOKEN_KEY, String(authResponse.token));
135
+ localStorage.setItem(AUTH_RESPONSE_KEY, JSON.stringify(authResponse));
136
+ localStorage.setItem(`${AUTH_RESPONSE_KEY}_stored_at`, Date.now().toString());
137
+ // Update memory
138
+ this.$_authToken.next(String(authResponse.token));
139
+ }
140
+ catch (error) {
141
+ console.warn('Failed to save auth to localStorage:', error);
142
+ }
143
+ }
144
+ // Clear auth from localStorage
145
+ clearAuthFromStorage() {
146
+ try {
147
+ localStorage.removeItem(AUTH_TOKEN_KEY);
148
+ localStorage.removeItem(AUTH_RESPONSE_KEY);
149
+ localStorage.removeItem(`${AUTH_RESPONSE_KEY}_stored_at`);
150
+ // Clear memory
151
+ this.$_authToken.next(null);
152
+ }
153
+ catch (error) {
154
+ console.warn('Failed to clear auth from localStorage:', error);
155
+ }
156
+ }
157
+ provider(target) {
158
+ const targetWrapper = new AuthProvider(this.config, target, this.$authToken);
159
+ return new SmessService(targetWrapper);
160
+ }
161
+ login(payload) {
162
+ return this.provider("login")
163
+ .request(payload)
164
+ .pipe(tap((result) => {
165
+ if (result.hasSuccess && result.response?.token) {
166
+ // Set the auth token when login is successful
167
+ this.$_authToken.next(String(result.response.token));
168
+ // Save to localStorage if rememberMe is true
169
+ if (payload.rememberMe && result.response) {
170
+ this.saveAuthToStorage(result.response);
171
+ }
172
+ }
173
+ }));
174
+ }
175
+ logout() {
176
+ return this.provider("logout")
177
+ .request()
178
+ .pipe(tap((result) => {
179
+ if (result.hasSuccess) {
180
+ // Clear from localStorage (this will also clear memory)
181
+ this.clearAuthFromStorage();
182
+ }
183
+ }));
184
+ }
185
+ forgotPassword(payload) {
186
+ return this.provider("password-forgot").request(payload);
187
+ }
188
+ changePassword(payload) {
189
+ return this.provider("change-password").request(payload);
190
+ }
191
+ resetPassword(payload) {
192
+ return this.provider("reset-password").request(payload);
193
+ }
194
+ verifyResetPasswordToken(token) {
195
+ return this.provider("verify-reset-password-token").request({ token });
196
+ }
197
+ }
@@ -0,0 +1 @@
1
+ export {};