@sambath999/localize-token 19.1.7 → 19.1.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.
@@ -1,88 +0,0 @@
1
- import { HttpErrorResponse } from "@angular/common/http";
2
- /**
3
- * Http method options
4
- */
5
- export declare enum EMethod {
6
- POST = "post",
7
- GET = "get",
8
- PUT = "put",
9
- DELETE = "delete",
10
- PATCH = "patch"
11
- }
12
- export interface IOnConnectionError {
13
- /**
14
- * Callback function to execute when a connection error occurs.
15
- * This function should return a Promise or any value.
16
- */
17
- callback?: (error: HttpErrorResponse) => Promise<void> | any;
18
- /**
19
- * If true, the request will block the screen with overlay on connection errors.
20
- * Default is false.
21
- */
22
- blockScreen?: boolean;
23
- /** Optional z-index for the block screen overlay.
24
- * Default is 10000.
25
- */
26
- blockScreenZIndex?: number;
27
- /**
28
- * Optional message to display when a connection error occurs.
29
- */
30
- message?: string;
31
- suggestionMessage?: string;
32
- }
33
- interface IRetryOptions {
34
- /**
35
- * Maximum number of retries for a failed request.
36
- * Default is 100.
37
- */
38
- maxRetries?: number;
39
- /**
40
- * Delay in milliseconds before retrying a failed request.
41
- * Default is 500ms.
42
- */
43
- delay?: number;
44
- /**
45
- * Function to determine if a request should be retried based on the error.
46
- * If not provided, the default function will retry for network errors and server errors (status 500-599).
47
- * @param error - The error object from the failed request.
48
- * @returns true if the request should be retried, false otherwise.
49
- */
50
- retryFunction?: (error: HttpErrorResponse) => Promise<boolean> | any;
51
- /**
52
- * Function to execute when a connection error occurs.
53
- * This function should return a Promise or any value.
54
- */
55
- onConnectionError?: IOnConnectionError;
56
- }
57
- export interface ILocalizeApiConfigs {
58
- onPrepareRequest?: () => Promise<void> | any;
59
- onAutoLogout?: () => Promise<void> | any;
60
- onRevokeUnauthorized?: () => Promise<void> | any;
61
- onResponseBodyInvalid?: (body: any) => void;
62
- waitEachRequest?: {
63
- milliseconds: number;
64
- };
65
- enableRequestCancellation?: boolean;
66
- /**
67
- * Config for retrying failed requests.
68
- * If not provided, the default retry options will be used.
69
- */
70
- retryOptions?: IRetryOptions;
71
- }
72
- export interface IApiOptions {
73
- headers?: {
74
- [key: string]: string;
75
- };
76
- method: EMethod;
77
- requestUrl: string;
78
- requestBody?: any;
79
- isFormData?: boolean;
80
- /**
81
- * If true, the request will use the refresh token for authorization.
82
- */
83
- refreshToken?: boolean;
84
- }
85
- export interface IHeader {
86
- [key: string]: string;
87
- }
88
- export {};
@@ -1,11 +0,0 @@
1
- export declare class InvalidResponseBodyError extends Error {
2
- raw: string;
3
- constructor(raw: string);
4
- }
5
- export declare class TruncatedResponseError extends Error {
6
- raw: string;
7
- expectedLength?: number;
8
- actualLength?: number;
9
- constructor(raw: string, expectedLength?: number, actualLength?: number);
10
- }
11
- export declare function extractJsonFromResponse(body: any, onError?: (body: any) => void): any;
@@ -1,5 +0,0 @@
1
- export declare const LOCALIZE_API_ASSETS: {
2
- network: {
3
- noConnection: string;
4
- };
5
- };
@@ -1,33 +0,0 @@
1
- import { HttpClient, HttpErrorResponse, HttpHeaders } from "@angular/common/http";
2
- import { IApiOptions, ILocalizeApiConfigs, IOnConnectionError } from "./interfaces";
3
- import { Subject } from "rxjs";
4
- interface IRequestInstance {
5
- client: HttpClient;
6
- destroy$: () => Subject<void>;
7
- }
8
- interface IRetryOptions {
9
- maxRetries: () => number;
10
- delay: number;
11
- callback: () => Promise<any> | any;
12
- retryUnless?: (error: any) => boolean;
13
- onError?: (error: any) => Promise<void> | any;
14
- connectionError?: IOnConnectionError;
15
- }
16
- declare class LocalizeApiHelper {
17
- readonly defaultRetryOptions: Partial<IRetryOptions>;
18
- performRetry<T = any>(options: IRetryOptions): Promise<T>;
19
- performRequestWithRetry<T = any>(options: IApiOptions, config: ILocalizeApiConfigs, performRequest: <T = any>(options: IApiOptions) => Promise<T>): Promise<T>;
20
- buildUrl(baseUrl: string, path: string): string;
21
- invokeHook(callback?: () => Promise<any> | any): Promise<any>;
22
- createRequest<T = any>(instance: Required<IRequestInstance>, method: string, url: string, body: any, options: {
23
- headers: HttpHeaders;
24
- }, onInvalidResponseBody?: (body: any) => void): import("rxjs").Observable<T>;
25
- defaultRetryFunction(error: HttpErrorResponse): boolean;
26
- isConnectionError(error: any): boolean;
27
- isRetriableError(error: any): boolean;
28
- onConnectionError(options: IRetryOptions, error: any): Promise<Promise<void> | any>;
29
- screenBlocker(optons: IRetryOptions, error?: HttpErrorResponse, add?: boolean): HTMLStyleElement | undefined;
30
- private removeBlocker;
31
- }
32
- export declare const ApiHelper: LocalizeApiHelper;
33
- export {};
@@ -1,54 +0,0 @@
1
- import { OnDestroy } from "@angular/core";
2
- import { LocalizeTokenService } from "./localize.token.service";
3
- import { HttpClient } from "@angular/common/http";
4
- import { BehaviorSubject } from "rxjs";
5
- import { ILocalizeApiConfigs, EMethod, IHeader } from "./helpers/interfaces";
6
- import * as i0 from "@angular/core";
7
- export declare class LocalizeApiService implements OnDestroy {
8
- readonly httpClient: HttpClient;
9
- private readonly localizeTokenService;
10
- private readonly destroy$;
11
- private readonly configSubject;
12
- readonly isRequestingSubject: BehaviorSubject<boolean>;
13
- readonly isResolvingStartupSubject: BehaviorSubject<boolean>;
14
- get isResolvingStartup(): boolean;
15
- get needTenant(): boolean;
16
- get isRequesting(): boolean;
17
- get isRevokingToken(): boolean;
18
- set isRevokingToken(value: boolean);
19
- get accessToken(): string | undefined;
20
- set accessToken(value: string | undefined);
21
- get refreshToken(): string | undefined;
22
- get tenantToken(): string | undefined;
23
- private defaultConfig;
24
- private get config();
25
- private apiOptions;
26
- constructor(httpClient: HttpClient, localizeTokenService: LocalizeTokenService);
27
- /**
28
- * Initialize the API service.
29
- * @param apiConfigs - The API configurations.
30
- */
31
- init(apiConfigs: ILocalizeApiConfigs): void;
32
- cancelPendingRequests(): void;
33
- ngOnDestroy(): void;
34
- /**
35
- * A higher-order function that returns a curried function for making API requests.
36
- *
37
- * @param baseUrl - The base URL of the API.
38
- * @returns A curried function that can be used to make API requests.
39
- */
40
- func: (baseUrl: string) => <T = any>(path: string, method?: EMethod, reqBody?: any, reqHeaders?: IHeader) => Promise<T>;
41
- request<T = any>(baseUrl: string, path: string, method?: EMethod, reqBody?: any, reqHeaders?: IHeader): Promise<T>;
42
- private handleOnRequestError;
43
- private performRequest;
44
- private revokeToken;
45
- /** default http request options */
46
- private buildHeaderOptions;
47
- private buildApiOptions;
48
- private toWaitForPreviousRequest;
49
- private handleOnTokenRevoked;
50
- private interceptRevokeToken;
51
- validateConfig(): void;
52
- static ɵfac: i0.ɵɵFactoryDeclaration<LocalizeApiService, never>;
53
- static ɵprov: i0.ɵɵInjectableDeclaration<LocalizeApiService>;
54
- }
@@ -1,42 +0,0 @@
1
- import { LocalizeTokenStorage } from "./localize.token.storage";
2
- interface ILocalizeTokenTokens {
3
- name: string;
4
- requestUrl?: string;
5
- }
6
- export interface ILocalizeTokenConfig {
7
- /**
8
- * The main domain of the application to set the cookies to be available for cross application with subdomains.
9
- *
10
- * Default is location.hostname (current domain) and automatically set extracted main domain if it is subdomain.
11
- */
12
- mainDomain?: string;
13
- isProduction: boolean;
14
- authToken?: ILocalizeTokenTokens;
15
- refreshToken?: ILocalizeTokenTokens;
16
- tenantToken?: ILocalizeTokenTokens;
17
- requiredTenant?: boolean;
18
- }
19
- export declare class LocalizeToken {
20
- static readonly storage: LocalizeTokenStorage;
21
- static readonly httpHeaders: {
22
- AUTHORIZATION: string;
23
- X_TENANT: string;
24
- X_REFRESH_TOKEN: string;
25
- CONTENT_TYPE: string;
26
- };
27
- }
28
- /**
29
- * Waits for a specified amount of time.
30
- * @param milliseconds - The milliseconds to wait.
31
- * @param when - The condition to wait for. Default is true.
32
- * @returns - Promise<void>
33
- */
34
- export declare function waitFor(milliseconds: number, when?: boolean): Promise<void>;
35
- /**
36
- * Waits until the condition is met.
37
- * @param when - The condition to wait for.
38
- * @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.
39
- */
40
- export declare function waitUntil(when: () => any, intervalNumber?: number): Promise<void>;
41
- export declare function extractMainDomain(subdomain?: string): string;
42
- export {};
@@ -1,6 +0,0 @@
1
- import * as i0 from "@angular/core";
2
- export declare class LocalizeTokenModule {
3
- static ɵfac: i0.ɵɵFactoryDeclaration<LocalizeTokenModule, never>;
4
- static ɵmod: i0.ɵɵNgModuleDeclaration<LocalizeTokenModule, never, never, never>;
5
- static ɵinj: i0.ɵɵInjectorDeclaration<LocalizeTokenModule>;
6
- }
@@ -1,37 +0,0 @@
1
- import { OnDestroy } from '@angular/core';
2
- import { ILocalizeTokenConfig } from './localize.token';
3
- import { BehaviorSubject } from 'rxjs';
4
- import * as jwt_decode from 'jwt-decode';
5
- import * as i0 from "@angular/core";
6
- export interface JwtPayload extends jwt_decode.JwtPayload {
7
- email: string;
8
- sub: string;
9
- name: string;
10
- iat: number;
11
- exp: number;
12
- }
13
- export declare class LocalizeTokenService implements OnDestroy {
14
- private readonly configSubject;
15
- readonly isRevokingTokenSubject: BehaviorSubject<boolean>;
16
- private readonly defaultConfig;
17
- get config(): ILocalizeTokenConfig;
18
- private isInitialized;
19
- init(config: ILocalizeTokenConfig): void;
20
- ngOnDestroy(): void;
21
- private get authToken();
22
- private set authToken(value);
23
- get tenantToken(): string;
24
- get refreshToken(): string;
25
- get accessToken(): string | undefined;
26
- set accessToken(value: string | undefined);
27
- get isRevokingToken(): boolean;
28
- set isRevokingToken(value: boolean);
29
- private storageGet;
30
- private storageSet;
31
- tokensValid(): boolean | undefined;
32
- decodeToken: (token: string) => JwtPayload;
33
- get decodeRefreshToken(): JwtPayload;
34
- private throwIfNotInitialized;
35
- static ɵfac: i0.ɵɵFactoryDeclaration<LocalizeTokenService, never>;
36
- static ɵprov: i0.ɵɵInjectableDeclaration<LocalizeTokenService>;
37
- }
@@ -1,61 +0,0 @@
1
- export interface ICookieOptions {
2
- /**
3
- * Cookie expiration date in days from now. If not provided the cookie is a session cookie
4
- */
5
- expires?: number | Date;
6
- path?: string;
7
- domain?: string;
8
- secure?: boolean;
9
- samesite?: "strict" | "lax" | "none";
10
- }
11
- /**
12
- * Assembly of @package ng2-cookies @see https://www.npmjs.com/package/ng2-cookies
13
- *
14
- * Reassembled by
15
- * @author sambath999
16
- * @date_29_09_2021
17
- * Updated from raw parameters to
18
- * @param {ICookieOptions} options and added another newer cookie flag
19
- * @param {string} samesite
20
- * @param {constant} SameSiteTypes, @param {string} strict "strict", @param {string} lax "lax", @param {string} none "none"
21
- *
22
- * @enum
23
- */
24
- export declare class LocalizeTokenStorage {
25
- private get getDefaultOptions();
26
- private readonly defaultOptions;
27
- constructor(_defaultOptions?: ICookieOptions);
28
- /**
29
- * Checks the existence of a single cookie by it's name
30
- *
31
- * @param {string} name Identification of the cookie
32
- * @returns existence of the cookie
33
- */
34
- check(name: string): boolean;
35
- /**
36
- * Retrieves a single cookie by it's name
37
- *
38
- * @param {string} name Identification of the Cookie
39
- * @returns The Cookie's value
40
- */
41
- get(name: string): string | undefined;
42
- /**
43
- * Retrieves a a list of all cookie avaiable
44
- *
45
- * @returns Object with all Cookies
46
- */
47
- getAll(): any;
48
- set(name: string, value: string, options?: ICookieOptions): void;
49
- /**
50
- * Removes specified Cookie
51
- *
52
- * @param {string} name Cookie's identification
53
- * @param {string} path Path relative to the domain where the cookie should be avaiable. Default /
54
- * @param {string} domain Domain where the cookie should be avaiable. Default current domain
55
- */
56
- delete(name: string, path?: string, domain?: string): void;
57
- /**
58
- * Delete all cookie avaiable
59
- */
60
- deleteAll(path?: string, domain?: string): void;
61
- }