@goat-bravos/shared-lib-client 1.0.1 → 1.0.2

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 (45) hide show
  1. package/LICENSE.txt +21 -21
  2. package/README.md +145 -579
  3. package/dist/enums/error-code.enum.d.ts +2 -1
  4. package/dist/enums/error-code.enum.d.ts.map +1 -1
  5. package/dist/enums/error-code.enum.js +3 -5
  6. package/dist/enums/http-status.enum.js +2 -5
  7. package/dist/enums/language.enum.d.ts +5 -0
  8. package/dist/enums/language.enum.d.ts.map +1 -0
  9. package/dist/enums/language.enum.js +5 -0
  10. package/dist/enums/localstorage-key.enum.d.ts +3 -1
  11. package/dist/enums/localstorage-key.enum.d.ts.map +1 -1
  12. package/dist/enums/localstorage-key.enum.js +4 -5
  13. package/dist/index.d.ts +10 -10
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +14 -29
  16. package/dist/interceptors/auth.interceptor.d.ts +12 -0
  17. package/dist/interceptors/auth.interceptor.d.ts.map +1 -0
  18. package/dist/interceptors/auth.interceptor.js +78 -0
  19. package/dist/interfaces/api-response.interface.d.ts +0 -10
  20. package/dist/interfaces/api-response.interface.d.ts.map +1 -1
  21. package/dist/interfaces/api-response.interface.js +1 -2
  22. package/dist/interfaces/http-heades.interface.js +1 -2
  23. package/dist/interfaces/pagination.interface.js +1 -2
  24. package/dist/store/global-store.service.d.ts +35 -0
  25. package/dist/store/global-store.service.d.ts.map +1 -0
  26. package/dist/store/global-store.service.js +55 -0
  27. package/dist/utils/storage.util.d.ts +20 -0
  28. package/dist/utils/storage.util.d.ts.map +1 -0
  29. package/dist/utils/storage.util.js +62 -0
  30. package/package.json +45 -43
  31. package/dist/enums/error-code.enum.js.map +0 -1
  32. package/dist/enums/http-status.enum.js.map +0 -1
  33. package/dist/enums/localstorage-key.enum.js.map +0 -1
  34. package/dist/index.js.map +0 -1
  35. package/dist/interfaces/api-response.interface.js.map +0 -1
  36. package/dist/interfaces/http-heades.interface.js.map +0 -1
  37. package/dist/interfaces/pagination.interface.js.map +0 -1
  38. package/dist/services/rest/rest.config.d.ts +0 -12
  39. package/dist/services/rest/rest.config.d.ts.map +0 -1
  40. package/dist/services/rest/rest.config.js +0 -5
  41. package/dist/services/rest/rest.config.js.map +0 -1
  42. package/dist/services/rest/rest.service.d.ts +0 -64
  43. package/dist/services/rest/rest.service.d.ts.map +0 -1
  44. package/dist/services/rest/rest.service.js +0 -112
  45. package/dist/services/rest/rest.service.js.map +0 -1
@@ -6,6 +6,7 @@ export declare enum ErrorCode {
6
6
  INTERNAL_SERVER_ERROR = "internal.server.error",
7
7
  VALIDATION_ERROR = "validation.error",
8
8
  CONFLICT = "conflict",
9
- SERVICE_UNAVAILABLE = "service.unavailable"
9
+ SERVICE_UNAVAILABLE = "service.unavailable",
10
+ REFRESH_TOKEN_INVALID = "auth.exception.refresh_token_invalid"
10
11
  }
11
12
  //# sourceMappingURL=error-code.enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-code.enum.d.ts","sourceRoot":"","sources":["../../src/enums/error-code.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACjB,kBAAkB,uBAAuB;IACzC,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,qBAAqB,0BAA0B;IAC/C,gBAAgB,qBAAqB;IACrC,QAAQ,aAAa;IACrB,mBAAmB,wBAAwB;CAC9C"}
1
+ {"version":3,"file":"error-code.enum.d.ts","sourceRoot":"","sources":["../../src/enums/error-code.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,kBAAkB,uBAAuB;IACzC,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,qBAAqB,0BAA0B;IAC/C,gBAAgB,qBAAqB;IACrC,QAAQ,aAAa;IACrB,mBAAmB,wBAAwB;IAC3C,qBAAqB,yCAAyC;CAC/D"}
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorCode = void 0;
4
- var ErrorCode;
1
+ export var ErrorCode;
5
2
  (function (ErrorCode) {
6
3
  ErrorCode["RESOURCE_NOT_FOUND"] = "resource.not.found";
7
4
  ErrorCode["UNAUTHORIZED"] = "unauthorized";
@@ -11,4 +8,5 @@ var ErrorCode;
11
8
  ErrorCode["VALIDATION_ERROR"] = "validation.error";
12
9
  ErrorCode["CONFLICT"] = "conflict";
13
10
  ErrorCode["SERVICE_UNAVAILABLE"] = "service.unavailable";
14
- })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
11
+ ErrorCode["REFRESH_TOKEN_INVALID"] = "auth.exception.refresh_token_invalid";
12
+ })(ErrorCode || (ErrorCode = {}));
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpStatus = void 0;
4
- var HttpStatus;
1
+ export var HttpStatus;
5
2
  (function (HttpStatus) {
6
3
  HttpStatus[HttpStatus["OK"] = 200] = "OK";
7
4
  HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
@@ -13,4 +10,4 @@ var HttpStatus;
13
10
  HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
14
11
  HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
15
12
  HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
16
- })(HttpStatus || (exports.HttpStatus = HttpStatus = {}));
13
+ })(HttpStatus || (HttpStatus = {}));
@@ -0,0 +1,5 @@
1
+ export declare enum Language {
2
+ VI = "vi",
3
+ EN = "en"
4
+ }
5
+ //# sourceMappingURL=language.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language.enum.d.ts","sourceRoot":"","sources":["../../src/enums/language.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,EAAE,OAAO;IACT,EAAE,OAAO;CACV"}
@@ -0,0 +1,5 @@
1
+ export var Language;
2
+ (function (Language) {
3
+ Language["VI"] = "vi";
4
+ Language["EN"] = "en";
5
+ })(Language || (Language = {}));
@@ -1,5 +1,7 @@
1
1
  export declare enum StorageKey {
2
2
  ACCESS_TOKEN = "accessToken",
3
- CONTENT_TYPE = "application/json"
3
+ REFRESH_TOKEN = "refreshToken",
4
+ CONTENT_TYPE = "application/json",
5
+ LANGUAGE = "lang"
4
6
  }
5
7
  //# sourceMappingURL=localstorage-key.enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localstorage-key.enum.d.ts","sourceRoot":"","sources":["../../src/enums/localstorage-key.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IAClB,YAAY,gBAAgB;IAC5B,YAAY,qBAAqB;CACpC"}
1
+ {"version":3,"file":"localstorage-key.enum.d.ts","sourceRoot":"","sources":["../../src/enums/localstorage-key.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,YAAY,gBAAgB;IAC5B,aAAa,iBAAiB;IAC9B,YAAY,qBAAqB;IACjC,QAAQ,SAAS;CAClB"}
@@ -1,8 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StorageKey = void 0;
4
- var StorageKey;
1
+ export var StorageKey;
5
2
  (function (StorageKey) {
6
3
  StorageKey["ACCESS_TOKEN"] = "accessToken";
4
+ StorageKey["REFRESH_TOKEN"] = "refreshToken";
7
5
  StorageKey["CONTENT_TYPE"] = "application/json";
8
- })(StorageKey || (exports.StorageKey = StorageKey = {}));
6
+ StorageKey["LANGUAGE"] = "lang";
7
+ })(StorageKey || (StorageKey = {}));
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from './enums/error-code.enum';
2
- export * from './enums/http-status.enum';
3
- export * from './interfaces/api-response.interface';
4
- export * from './interfaces/http-heades.interface';
5
- export * from './interfaces/pagination.interface';
6
- export * from './services/rest/rest.config';
7
- export * from './services/rest/rest.service';
8
- export * from './enums/http-status.enum';
9
- export * from './enums/error-code.enum';
10
- export * from './enums/localstorage-key.enum';
1
+ export * from "./enums/error-code.enum";
2
+ export * from "./enums/http-status.enum";
3
+ export * from "./enums/localstorage-key.enum";
4
+ export * from "./enums/language.enum";
5
+ export * from "./interfaces/api-response.interface";
6
+ export * from "./interfaces/http-heades.interface";
7
+ export * from "./interfaces/pagination.interface";
8
+ export * from "./utils/storage.util";
9
+ export * from "./store/global-store.service";
10
+ export * from "./interceptors/auth.interceptor";
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AAGzC,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAGlD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAG5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AAGtC,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAGlD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,8BAA8B,CAAC;AAG7C,cAAc,iCAAiC,CAAC"}
package/dist/index.js CHANGED
@@ -1,30 +1,15 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
1
  // Export các enums
18
- __exportStar(require("./enums/error-code.enum"), exports);
19
- __exportStar(require("./enums/http-status.enum"), exports);
20
- // Export các interface (HttpClientHeaders, ApiResponse)
21
- __exportStar(require("./interfaces/api-response.interface"), exports);
22
- __exportStar(require("./interfaces/http-heades.interface"), exports);
23
- __exportStar(require("./interfaces/pagination.interface"), exports);
24
- // Export Service
25
- __exportStar(require("./services/rest/rest.config"), exports);
26
- __exportStar(require("./services/rest/rest.service"), exports);
27
- // Export ENUM
28
- __exportStar(require("./enums/http-status.enum"), exports);
29
- __exportStar(require("./enums/error-code.enum"), exports);
30
- __exportStar(require("./enums/localstorage-key.enum"), exports);
2
+ export * from "./enums/error-code.enum";
3
+ export * from "./enums/http-status.enum";
4
+ export * from "./enums/localstorage-key.enum";
5
+ export * from "./enums/language.enum";
6
+ // Export các interface (HttpClientHeaders, ApiResponse, Pagination)
7
+ export * from "./interfaces/api-response.interface";
8
+ export * from "./interfaces/http-heades.interface";
9
+ export * from "./interfaces/pagination.interface";
10
+ // Export Utils
11
+ export * from "./utils/storage.util";
12
+ // Export Global State (Angular Signals)
13
+ export * from "./store/global-store.service";
14
+ // Export Interceptors
15
+ export * from "./interceptors/auth.interceptor";
@@ -0,0 +1,12 @@
1
+ import { HttpInterceptorFn } from "@angular/common/http";
2
+ /**
3
+ * Shared Auth Interceptor
4
+ * - Injects Authorization header
5
+ * - Handles 401 errors with synchronized token refresh
6
+ */
7
+ export declare const authInterceptor: HttpInterceptorFn;
8
+ /**
9
+ * Utility to be called by the Shell/Auth MFE when a new token is received
10
+ */
11
+ export declare function notifyTokenRefreshed(newToken: string): void;
12
+ //# sourceMappingURL=auth.interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/auth.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAY9B;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,iBAoC7B,CAAC;AAqDF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAG3D"}
@@ -0,0 +1,78 @@
1
+ import { throwError, BehaviorSubject } from "rxjs";
2
+ import { catchError, filter, take, switchMap, finalize } from "rxjs/operators";
3
+ import { StorageUtil } from "../utils/storage.util";
4
+ import { ErrorCode } from "../enums/error-code.enum";
5
+ // Flag and Subject to manage token refreshing state globally
6
+ let isRefreshing = false;
7
+ const refreshTokenSubject = new BehaviorSubject(null);
8
+ /**
9
+ * Shared Auth Interceptor
10
+ * - Injects Authorization header
11
+ * - Handles 401 errors with synchronized token refresh
12
+ */
13
+ export const authInterceptor = (req, next) => {
14
+ // 1. Get token from StorageUtil
15
+ const token = StorageUtil.getAccessToken();
16
+ let authReq = req;
17
+ // 2. Add Authorization header if token exists
18
+ if (token) {
19
+ authReq = req.clone({
20
+ setHeaders: {
21
+ Authorization: `Bearer ${token}`,
22
+ },
23
+ });
24
+ }
25
+ // 3. Process the request
26
+ return next(authReq).pipe(catchError((error) => {
27
+ const responseBody = error.error;
28
+ const errorCode = responseBody?.status?.code;
29
+ // Check if it's an Authentication error
30
+ // 401 is standard, but the backend also uses REFRESH_TOKEN_INVALID in some contexts
31
+ const isAuthError = error.status === 401 || errorCode === ErrorCode.REFRESH_TOKEN_INVALID;
32
+ // Handle Auth error if not on login or refresh endpoints
33
+ if (isAuthError &&
34
+ !authReq.url.includes("/auth/login") &&
35
+ !authReq.url.includes("/auth/refresh")) {
36
+ return handle401Error(authReq, next);
37
+ }
38
+ return throwError(() => error);
39
+ }));
40
+ };
41
+ /**
42
+ * Handle 401 errors by attempting to refresh the token
43
+ */
44
+ function handle401Error(request, next) {
45
+ if (!isRefreshing) {
46
+ isRefreshing = true;
47
+ refreshTokenSubject.next(null);
48
+ const refreshToken = StorageUtil.getRefreshToken();
49
+ // Here we assume the Shell/App environment has a way to call refresh token
50
+ // For a library, we might need to pass a callback or use a known endpoint
51
+ // Let's assume a standard endpoint or dispatch a CustomEvent for the Shell to handle
52
+ // Dispatch event so the Shell/Auth MFE can perform the actual API call
53
+ window.dispatchEvent(new CustomEvent("AUTH_TOKEN_EXPIRED"));
54
+ // We wait for the new token to be emitted through the subject
55
+ return refreshTokenSubject.pipe(filter((token) => token !== null), take(1), switchMap((token) => {
56
+ return next(request.clone({
57
+ setHeaders: { Authorization: `Bearer ${token}` },
58
+ }));
59
+ }), finalize(() => {
60
+ isRefreshing = false;
61
+ }));
62
+ }
63
+ else {
64
+ // Other requests wait in queue
65
+ return refreshTokenSubject.pipe(filter((token) => token !== null), take(1), switchMap((token) => {
66
+ return next(request.clone({
67
+ setHeaders: { Authorization: `Bearer ${token}` },
68
+ }));
69
+ }));
70
+ }
71
+ }
72
+ /**
73
+ * Utility to be called by the Shell/Auth MFE when a new token is received
74
+ */
75
+ export function notifyTokenRefreshed(newToken) {
76
+ refreshTokenSubject.next(newToken);
77
+ isRefreshing = false;
78
+ }
@@ -16,16 +16,6 @@ export interface ApiMetadata {
16
16
  timestamp?: number;
17
17
  [key: string]: any;
18
18
  }
19
- /**
20
- * API Metadata Interface
21
- */
22
- export interface ApiMetadata {
23
- requestId?: string;
24
- traceId?: string;
25
- signature?: string | null;
26
- timestamp?: number;
27
- [key: string]: any;
28
- }
29
19
  /**
30
20
  * Base Response API Interface
31
21
  */
@@ -1 +1 @@
1
- {"version":3,"file":"api-response.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/api-response.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAChC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAC5D,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,WAAW,CAAC,IAAI,CAAC;IACpD,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,WAAW,CAAC;CACzB"}
1
+ {"version":3,"file":"api-response.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/api-response.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAC9D,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,WAAW,CAAC,IAAI,CAAC;IACtD,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,WAAW,CAAC;CACvB"}
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import { Language } from "../enums/language.enum";
2
+ export interface UserInfo {
3
+ userId: string;
4
+ userName: string;
5
+ userEmail: string;
6
+ userRole: string;
7
+ [key: string]: any;
8
+ }
9
+ export declare class GlobalStoreService {
10
+ readonly user: import("@angular/core").WritableSignal<UserInfo | null>;
11
+ readonly isLoading: import("@angular/core").WritableSignal<boolean>;
12
+ readonly theme: import("@angular/core").WritableSignal<"light" | "dark">;
13
+ readonly language: import("@angular/core").WritableSignal<Language>;
14
+ /**
15
+ * Update user info across all apps
16
+ */
17
+ setUser(userInfo: UserInfo | null): void;
18
+ /**
19
+ * Update loading state
20
+ */
21
+ setLoading(loading: boolean): void;
22
+ /**
23
+ * Toggle global theme
24
+ */
25
+ setTheme(theme: "light" | "dark"): void;
26
+ /**
27
+ * Update application language
28
+ */
29
+ setLanguage(lang: Language): void;
30
+ /**
31
+ * Clear all global state (useful on logout)
32
+ */
33
+ clearState(): void;
34
+ }
35
+ //# sourceMappingURL=global-store.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-store.service.d.ts","sourceRoot":"","sources":["../../src/store/global-store.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,qBAGa,kBAAkB;IAE7B,QAAQ,CAAC,IAAI,0DAAiC;IAC9C,QAAQ,CAAC,SAAS,kDAA0B;IAC5C,QAAQ,CAAC,KAAK,2DAAqC;IACnD,QAAQ,CAAC,QAAQ,mDAEf;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI;IAIxC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAIvC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAMjC;;OAEG;IACH,UAAU,IAAI,IAAI;CAInB"}
@@ -0,0 +1,55 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Injectable, signal } from "@angular/core";
8
+ import { Language } from "../enums/language.enum";
9
+ import { StorageUtil } from "../utils/storage.util";
10
+ let GlobalStoreService = class GlobalStoreService {
11
+ // Global signals for all MFEs
12
+ user = signal(null);
13
+ isLoading = signal(false);
14
+ theme = signal("light");
15
+ language = signal(StorageUtil.getLanguage() || Language.VI);
16
+ /**
17
+ * Update user info across all apps
18
+ */
19
+ setUser(userInfo) {
20
+ this.user.set(userInfo);
21
+ }
22
+ /**
23
+ * Update loading state
24
+ */
25
+ setLoading(loading) {
26
+ this.isLoading.set(loading);
27
+ }
28
+ /**
29
+ * Toggle global theme
30
+ */
31
+ setTheme(theme) {
32
+ this.theme.set(theme);
33
+ }
34
+ /**
35
+ * Update application language
36
+ */
37
+ setLanguage(lang) {
38
+ StorageUtil.setLanguage(lang);
39
+ this.language.set(lang);
40
+ // Reload if needed or let components react to signal
41
+ }
42
+ /**
43
+ * Clear all global state (useful on logout)
44
+ */
45
+ clearState() {
46
+ this.user.set(null);
47
+ this.isLoading.set(false);
48
+ }
49
+ };
50
+ GlobalStoreService = __decorate([
51
+ Injectable({
52
+ providedIn: "root",
53
+ })
54
+ ], GlobalStoreService);
55
+ export { GlobalStoreService };
@@ -0,0 +1,20 @@
1
+ import { Language } from "../enums/language.enum";
2
+ export declare class StorageUtil {
3
+ private static readonly DEVICE_ID_KEY;
4
+ static getDeviceId(): string | null;
5
+ static setDeviceId(id: string): void;
6
+ static getAccessToken(): string | null;
7
+ static setAccessToken(token: string): void;
8
+ static removeAccessToken(): void;
9
+ static getRefreshToken(): string | null;
10
+ static setRefreshToken(token: string): void;
11
+ static removeRefreshToken(): void;
12
+ static getUserId(): string | null;
13
+ static setUserId(id: string): void;
14
+ static removeUserId(): void;
15
+ static getLanguage(): Language | null;
16
+ static setLanguage(lang: Language): void;
17
+ static clearAuthData(): void;
18
+ static clearAll(): void;
19
+ }
20
+ //# sourceMappingURL=storage.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.util.d.ts","sourceRoot":"","sources":["../../src/utils/storage.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAGtD,MAAM,CAAC,WAAW,IAAI,MAAM,GAAG,IAAI;IAInC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKpC,MAAM,CAAC,cAAc,IAAI,MAAM,GAAG,IAAI;IAItC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI1C,MAAM,CAAC,iBAAiB,IAAI,IAAI;IAKhC,MAAM,CAAC,eAAe,IAAI,MAAM,GAAG,IAAI;IAIvC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3C,MAAM,CAAC,kBAAkB,IAAI,IAAI;IAKjC,MAAM,CAAC,SAAS,IAAI,MAAM,GAAG,IAAI;IAIjC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIlC,MAAM,CAAC,YAAY,IAAI,IAAI;IAK3B,MAAM,CAAC,WAAW,IAAI,QAAQ,GAAG,IAAI;IAIrC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAKxC,MAAM,CAAC,aAAa,IAAI,IAAI;IAO5B,MAAM,CAAC,QAAQ,IAAI,IAAI;CAOxB"}
@@ -0,0 +1,62 @@
1
+ import { StorageKey } from "../enums/localstorage-key.enum";
2
+ export class StorageUtil {
3
+ static DEVICE_ID_KEY = "X-Device-ID";
4
+ // Device ID
5
+ static getDeviceId() {
6
+ return localStorage.getItem(this.DEVICE_ID_KEY);
7
+ }
8
+ static setDeviceId(id) {
9
+ localStorage.setItem(this.DEVICE_ID_KEY, id);
10
+ }
11
+ // Access Token
12
+ static getAccessToken() {
13
+ return localStorage.getItem(StorageKey.ACCESS_TOKEN);
14
+ }
15
+ static setAccessToken(token) {
16
+ localStorage.setItem(StorageKey.ACCESS_TOKEN, token);
17
+ }
18
+ static removeAccessToken() {
19
+ localStorage.removeItem(StorageKey.ACCESS_TOKEN);
20
+ }
21
+ // Refresh Token
22
+ static getRefreshToken() {
23
+ return localStorage.getItem(StorageKey.REFRESH_TOKEN);
24
+ }
25
+ static setRefreshToken(token) {
26
+ localStorage.setItem(StorageKey.REFRESH_TOKEN, token);
27
+ }
28
+ static removeRefreshToken() {
29
+ localStorage.removeItem(StorageKey.REFRESH_TOKEN);
30
+ }
31
+ // User ID
32
+ static getUserId() {
33
+ return localStorage.getItem("userId");
34
+ }
35
+ static setUserId(id) {
36
+ localStorage.setItem("userId", id);
37
+ }
38
+ static removeUserId() {
39
+ localStorage.removeItem("userId");
40
+ }
41
+ // Language
42
+ static getLanguage() {
43
+ return localStorage.getItem(StorageKey.LANGUAGE);
44
+ }
45
+ static setLanguage(lang) {
46
+ localStorage.setItem(StorageKey.LANGUAGE, lang);
47
+ }
48
+ // Clear all Auth data
49
+ static clearAuthData() {
50
+ localStorage.removeItem(StorageKey.ACCESS_TOKEN);
51
+ localStorage.removeItem(StorageKey.REFRESH_TOKEN);
52
+ localStorage.removeItem("userId");
53
+ }
54
+ // Clear everything including Device ID and Language
55
+ static clearAll() {
56
+ localStorage.removeItem(StorageKey.ACCESS_TOKEN);
57
+ localStorage.removeItem(StorageKey.REFRESH_TOKEN);
58
+ localStorage.removeItem("userId");
59
+ localStorage.removeItem(this.DEVICE_ID_KEY);
60
+ localStorage.removeItem(StorageKey.LANGUAGE);
61
+ }
62
+ }
package/package.json CHANGED
@@ -1,46 +1,48 @@
1
- {
2
- "name": "@goat-bravos/shared-lib-client",
3
- "version": "1.0.1",
4
- "peerDependencies": {
5
- "@angular/common": "21.0.1",
6
- "@angular/core": "21.1.0-rc.0",
7
- "@angular/router": "21.0.1"
8
- },
9
- "licenses": [
10
- {
11
- "type": "MIT",
12
- "url": "https://opensource.org/licenses/MIT"
13
- }
14
- ],
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/Bravos-World/intern-shared-lib"
18
- },
19
- "description": "Library containing shared HttpClientHeaders and ApiResponse formats",
20
- "main": "dist/index.js",
21
- "types": "dist/index.d.ts",
22
- "files": [
23
- "dist",
24
- "README.md"
25
- ],
1
+ {
2
+ "name": "@goat-bravos/shared-lib-client",
3
+ "version": "1.0.2",
4
+ "type": "module",
5
+ "peerDependencies": {
6
+ "@angular/common": "21.0.1",
7
+ "@angular/core": "21.1.0-rc.0",
8
+ "@angular/router": "21.0.1"
9
+ },
10
+ "licenses": [
11
+ {
12
+ "type": "MIT",
13
+ "url": "https://opensource.org/licenses/MIT"
14
+ }
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/Bravos-World/intern-shared-lib"
19
+ },
20
+ "description": "Library containing shared HttpClientHeaders and ApiResponse formats",
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
26
27
  "scripts": {
27
28
  "build": "tsc",
28
- "prepublishOnly": "npm run build"
29
+ "prepublishOnly": "npm run build",
30
+ "publish:lib": "npm --cache .npm-cache publish"
29
31
  },
30
- "keywords": [
31
- "typescript",
32
- "api",
33
- "http",
34
- "response",
35
- "shared"
36
- ],
37
- "author": "intern-hub",
38
- "license": "ISC",
39
- "devDependencies": {
40
- "@angular/common": "^21.1.1",
41
- "@angular/core": "^21.1.1",
42
- "@angular/router": "^21.1.1",
43
- "rxjs": "^7.8.2",
44
- "typescript": "^5.9.3"
45
- }
46
- }
32
+ "keywords": [
33
+ "typescript",
34
+ "api",
35
+ "http",
36
+ "response",
37
+ "shared"
38
+ ],
39
+ "author": "intern-hub",
40
+ "license": "ISC",
41
+ "devDependencies": {
42
+ "@angular/common": "^21.1.1",
43
+ "@angular/core": "^21.1.1",
44
+ "@angular/router": "^21.1.1",
45
+ "rxjs": "^7.8.2",
46
+ "typescript": "^5.9.3"
47
+ }
48
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-code.enum.js","sourceRoot":"","sources":["../../src/enums/error-code.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,SASX;AATD,WAAY,SAAS;IACjB,sDAAyC,CAAA;IACzC,0CAA6B,CAAA;IAC7B,oCAAuB,CAAA;IACvB,wCAA2B,CAAA;IAC3B,4DAA+C,CAAA;IAC/C,kDAAqC,CAAA;IACrC,kCAAqB,CAAA;IACrB,wDAA2C,CAAA;AAC/C,CAAC,EATW,SAAS,yBAAT,SAAS,QASpB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-status.enum.js","sourceRoot":"","sources":["../../src/enums/http-status.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAWX;AAXD,WAAY,UAAU;IAClB,yCAAQ,CAAA;IACR,mDAAa,CAAA;IACb,yDAAgB,CAAA;IAChB,2DAAiB,CAAA;IACjB,6DAAkB,CAAA;IAClB,uDAAe,CAAA;IACf,uDAAe,CAAA;IACf,qDAAc,CAAA;IACd,+EAA2B,CAAA;IAC3B,2EAAyB,CAAA;AAC7B,CAAC,EAXW,UAAU,0BAAV,UAAU,QAWrB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"localstorage-key.enum.js","sourceRoot":"","sources":["../../src/enums/localstorage-key.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IAClB,0CAA4B,CAAA;IAC5B,+CAAiC,CAAA;AACrC,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mBAAmB;AACnB,0DAAwC;AACxC,2DAAyC;AAEzC,wDAAwD;AACxD,sEAAoD;AACpD,qEAAmD;AACnD,oEAAkD;AAElD,iBAAiB;AACjB,8DAA2C;AAC3C,+DAA4C;AAE5C,cAAc;AACd,2DAAyC;AACzC,0DAAwC;AACxC,gEAA8C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"api-response.interface.js","sourceRoot":"","sources":["../../src/interfaces/api-response.interface.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-heades.interface.js","sourceRoot":"","sources":["../../src/interfaces/http-heades.interface.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pagination.interface.js","sourceRoot":"","sources":["../../src/interfaces/pagination.interface.ts"],"names":[],"mappings":""}
@@ -1,12 +0,0 @@
1
- import { InjectionToken } from "@angular/core";
2
- export interface RestConfig {
3
- apiBaseUrl: string;
4
- enableLogging: boolean;
5
- internalAutoRetry: boolean;
6
- retryAttempts: number;
7
- retryIntervalMs: number;
8
- loginPath: string;
9
- tokenKey: string;
10
- }
11
- export declare const REST_CONFIG: InjectionToken<RestConfig>;
12
- //# sourceMappingURL=rest.config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rest.config.d.ts","sourceRoot":"","sources":["../../../src/services/rest/rest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,WAAW,4BAAgD,CAAC"}