@sambath999/localize-token 12.2.3 → 12.2.4

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 (57) hide show
  1. package/bundles/sambath999-localize-token.umd.js +1150 -0
  2. package/bundles/sambath999-localize-token.umd.js.map +1 -0
  3. package/esm2015/localize-logindlg/localize-logindlg.component.js +391 -0
  4. package/esm2015/localize-logindlg/localize-logindlg.module.js +28 -0
  5. package/esm2015/localize-logindlg/localize-logindlg.service.js +37 -0
  6. package/esm2015/localize-logindlg/public-api.js +4 -0
  7. package/esm2015/localize-token/localize.api.service.js +159 -0
  8. package/esm2015/localize-token/localize.token.js +67 -0
  9. package/esm2015/localize-token/localize.token.module.js +16 -0
  10. package/esm2015/localize-token/localize.token.service.js +70 -0
  11. package/esm2015/localize-token/localize.token.storage.js +107 -0
  12. package/esm2015/localize-token/public-api.js +6 -0
  13. package/esm2015/public-api.js +3 -0
  14. package/esm2015/sambath999-localize-token.js +5 -0
  15. package/fesm2015/sambath999-localize-token.js +852 -0
  16. package/fesm2015/sambath999-localize-token.js.map +1 -0
  17. package/localize-logindlg/localize-logindlg.component.d.ts +33 -0
  18. package/localize-logindlg/localize-logindlg.module.d.ts +2 -0
  19. package/localize-logindlg/localize-logindlg.service.d.ts +16 -0
  20. package/localize-logindlg/public-api.d.ts +3 -0
  21. package/localize-token/localize.api.service.d.ts +69 -0
  22. package/localize-token/localize.token.d.ts +46 -0
  23. package/localize-token/localize.token.module.d.ts +2 -0
  24. package/localize-token/localize.token.service.d.ts +29 -0
  25. package/localize-token/localize.token.storage.d.ts +61 -0
  26. package/{src/localize-token/public-api.ts → localize-token/public-api.d.ts} +1 -1
  27. package/package.json +38 -49
  28. package/sambath999-localize-token.d.ts +4 -0
  29. package/sambath999-localize-token.metadata.json +1 -0
  30. package/angular.json +0 -119
  31. package/ng-package.json +0 -19
  32. package/release.ps1 +0 -30
  33. package/release.sh +0 -26
  34. package/src/app/app.component.html +0 -11
  35. package/src/app/app.component.scss +0 -0
  36. package/src/app/app.component.ts +0 -26
  37. package/src/app/app.module.ts +0 -32
  38. package/src/assets/.gitkeep +0 -0
  39. package/src/assets/images/logo-300px.png +0 -0
  40. package/src/index.html +0 -103
  41. package/src/localize-logindlg/localize-logindlg.component.ts +0 -400
  42. package/src/localize-logindlg/localize-logindlg.module.ts +0 -25
  43. package/src/localize-logindlg/localize-logindlg.service.ts +0 -38
  44. package/src/localize-logindlg/public-api.ts +0 -3
  45. package/src/localize-token/localize.api.service.ts +0 -177
  46. package/src/localize-token/localize.token.module.ts +0 -13
  47. package/src/localize-token/localize.token.service.ts +0 -84
  48. package/src/localize-token/localize.token.storage.ts +0 -132
  49. package/src/localize-token/localize.token.ts +0 -86
  50. package/src/main.ts +0 -7
  51. package/src/polyfills.ts +0 -53
  52. package/src/styles.css +0 -0
  53. package/src/types/index.ts +0 -0
  54. package/tsconfig.app.json +0 -14
  55. package/tsconfig.json +0 -38
  56. /package/{README.MD → README.md} +0 -0
  57. /package/{src/public-api.ts → public-api.d.ts} +0 -0
@@ -1,84 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { ILocalizeTokenConfig, LocalizeToken } from './localize.token';
3
- import { BehaviorSubject } from 'rxjs';
4
- import * as jwt_decode from 'jwt-decode';
5
- export interface JwtPayload extends jwt_decode.JwtPayload {
6
- // Define the structure of your JWT payload here
7
- email: string;
8
- sub: string;
9
- name: string;
10
- iat: number;
11
- exp: number;
12
- // Add other fields as needed
13
- }
14
-
15
- interface IAuthToken {
16
- token: string;
17
- revoke: boolean;
18
- }
19
-
20
- @Injectable({ providedIn: 'root' })
21
- export class LocalizeTokenService {
22
- private readonly config: ILocalizeTokenConfig
23
- constructor(private readonly tokenConfig: LocalizeToken) {
24
- if (!this.tokenConfig.getConfig.authTokenName || !this.tokenConfig.getConfig.refreshTokenName || !this.tokenConfig.getConfig.tenantTokenName) {
25
- throw new Error('authTokenName, refreshTokenName, and tenantTokenName must be defined in LocalizeToken.config')
26
- }
27
- this.config = this.tokenConfig.getConfig;
28
- }
29
- readonly isRevokingTokenSubject = new BehaviorSubject<boolean>(false);
30
-
31
- private get authToken() { return this.storageGet() }
32
- private set authToken(value: IAuthToken | undefined) {
33
- value
34
- ? this.storageSet(value)
35
- : LocalizeToken.storage.delete(this.config.authTokenName!);
36
- }
37
-
38
- get refreshToken() { return LocalizeToken.storage.get(this.config.refreshTokenName!) }
39
- get accessToken() { return this.authToken?.token }
40
-
41
- set accessToken(value: string | undefined) {
42
- if (value) {
43
- this.authToken = { token: value, revoke: false }
44
- }
45
- }
46
-
47
- get isRevokingToken() { return this.isRevokingTokenSubject.value /* this.authToken?.revoke ?? false */ }
48
- set isRevokingToken(value: boolean) {
49
- this.isRevokingTokenSubject.next(value);
50
- if (this.authToken) {
51
- this.authToken = { ...this.authToken, revoke: value };
52
- }
53
- }
54
-
55
-
56
- tenantToken() { return LocalizeToken.storage.get(this.config.tenantTokenName!) }
57
-
58
- private storageGet() {
59
- try {
60
- const encoded = LocalizeToken.storage.get(this.config.authTokenName!);
61
- const decoded = atob(encoded || '');
62
- return JSON.parse(decoded) as IAuthToken;
63
- } catch {
64
- return undefined
65
- }
66
- }
67
-
68
- private storageSet(value: IAuthToken) {
69
- const base64 = btoa(JSON.stringify(value));
70
- LocalizeToken.storage.set(this.config.authTokenName!, base64);
71
- }
72
-
73
- tokensValid() {
74
- return this.refreshToken?.length && (!this.config.needTenant || this.tenantToken()?.length);
75
- }
76
-
77
- decodeToken = (token: string) => jwt_decode.jwtDecode<JwtPayload>(token);
78
- get decodeRefreshToken() {
79
- const token = LocalizeToken.storage.get(this.config.refreshTokenName!);
80
- if (!token) return null;
81
- return this.decodeToken(token);
82
- }
83
-
84
- }
@@ -1,132 +0,0 @@
1
- import { extractMainDomain } from "./localize.token";
2
-
3
- export interface ICookieOptions {
4
- /**
5
- * Cookie expiration date in days from now. If not provided the cookie is a session cookie
6
- */
7
- expires?: number | Date;
8
- path?: string;
9
- domain?: string;
10
- secure?: boolean;
11
- samesite?: "strict" | "lax" | "none";
12
- }
13
-
14
- /**
15
- * Assembly of @package ng2-cookies @see https://www.npmjs.com/package/ng2-cookies
16
- *
17
- * Reassembled by
18
- * @author sambath999
19
- * @date_29_09_2021
20
- * Updated from raw parameters to
21
- * @param {ICookieOptions} options and added another newer cookie flag
22
- * @param {string} samesite
23
- * @param {constant} SameSiteTypes, @param {string} strict "strict", @param {string} lax "lax", @param {string} none "none"
24
- *
25
- * @enum
26
- */
27
- export class LocalizeTokenStorage {
28
-
29
- private get getDefaultOptions(): ICookieOptions {
30
- const mainDomain = extractMainDomain(window.location.hostname);
31
- return {
32
- path: '/',
33
- domain: mainDomain,
34
- secure: true,
35
- // samesite: SameSiteType.strict,
36
- expires: 1
37
- }
38
- }
39
-
40
- private readonly defaultOptions: ICookieOptions;
41
- constructor(_defaultOptions?: ICookieOptions) {
42
- this.defaultOptions = _defaultOptions ?? this.getDefaultOptions;
43
- }
44
-
45
- /**
46
- * Checks the existence of a single cookie by it's name
47
- *
48
- * @param {string} name Identification of the cookie
49
- * @returns existence of the cookie
50
- */
51
- check(name: string): boolean {
52
- if (typeof document === "undefined") return false;
53
- name = encodeURIComponent(name);
54
- const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
55
- return regexp.test(document.cookie);
56
- }
57
-
58
- /**
59
- * Retrieves a single cookie by it's name
60
- *
61
- * @param {string} name Identification of the Cookie
62
- * @returns The Cookie's value
63
- */
64
- get(name: string): string | undefined {
65
- if (!this.check(name)) return undefined;
66
-
67
- name = encodeURIComponent(name);
68
- const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
69
- const result = regexp.exec(document.cookie);
70
- return result ? decodeURIComponent(result[1]) : undefined;
71
- }
72
-
73
- /**
74
- * Retrieves a a list of all cookie avaiable
75
- *
76
- * @returns Object with all Cookies
77
- */
78
- getAll(): any {
79
- const cookies: any = {};
80
- if (document.cookie) {
81
- const split = document.cookie.split(';');
82
- for (const s of split) {
83
- const currCookie = s.split('=');
84
- currCookie[0] = currCookie[0].trim();
85
- cookies[decodeURIComponent(currCookie[0])] = decodeURIComponent(currCookie[1]);
86
- }
87
- }
88
-
89
- return cookies;
90
- }
91
-
92
- set(name: string, value: string, options?: ICookieOptions) {
93
- options ??= this.defaultOptions;
94
- const { expires, path, domain, secure, samesite } = { ...this.defaultOptions, ...options };
95
- let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)};`;
96
-
97
- if (expires) {
98
- const dtExpires = typeof expires === 'number' ? new Date(Date.now() + expires * 864e5) : expires;
99
- cookieStr += `expires=${dtExpires.toUTCString()};`;
100
- }
101
-
102
- cookieStr += path ? `path=${path};` : '';
103
- cookieStr += domain ? `domain=${domain};` : '';
104
- cookieStr += secure ? 'secure;' : '';
105
- cookieStr += samesite ? `samesite=${samesite};` : '';
106
-
107
- document.cookie = cookieStr;
108
- }
109
-
110
- /**
111
- * Removes specified Cookie
112
- *
113
- * @param {string} name Cookie's identification
114
- * @param {string} path Path relative to the domain where the cookie should be avaiable. Default /
115
- * @param {string} domain Domain where the cookie should be avaiable. Default current domain
116
- */
117
- delete(name: string, path: string = '/', domain: string = window.location.hostname): void {
118
- this.set(name, '', { path, domain, expires: -1 });
119
- }
120
-
121
- /**
122
- * Delete all cookie avaiable
123
- */
124
- deleteAll(path?: string, domain?: string): void {
125
- const cookies = this.getAll();
126
-
127
- for (const cookieName of Object.keys(cookies)) {
128
- this.delete(cookieName, path, domain);
129
- }
130
- }
131
-
132
- }
@@ -1,86 +0,0 @@
1
- import { BehaviorSubject } from "rxjs";
2
- import { LocalizeTokenStorage } from "./localize.token.storage";
3
- export interface ILocalizeTokenConfig {
4
- /**
5
- * The main domain of the application to set the cookies to be available for cross application with subdomains.
6
- *
7
- * Default is location.hostname (current domain) and automatically set extracted main domain if it is subdomain.
8
- */
9
- mainDomain?: string;
10
- authTokenName?: string;
11
- tenantTokenName?: string;
12
- refreshTokenName?: string;
13
- /**
14
- * Flag to determine if the tenant token is required.
15
- */
16
- needTenant: boolean;
17
- isProduction: boolean;
18
- revokeTokenUrl: string;
19
- }
20
-
21
-
22
- export class LocalizeToken {
23
-
24
- readonly configSubject = new BehaviorSubject<ILocalizeTokenConfig>(LocalizeToken.config);
25
- get getConfig() { return this.configSubject.value; }
26
-
27
- static init(config: ILocalizeTokenConfig) {
28
- const lConfig = new LocalizeToken();
29
- LocalizeToken.config = { ...LocalizeToken.config, ...config };
30
- lConfig.configSubject.next(LocalizeToken.config);
31
- }
32
-
33
- private static config: ILocalizeTokenConfig = {
34
- mainDomain: extractMainDomain(),
35
- authTokenName: 'auth-token',
36
- refreshTokenName: '_lze_rftkp_',
37
- needTenant: false,
38
- isProduction: false,
39
- revokeTokenUrl: ''
40
- }
41
-
42
- static readonly storage = new LocalizeTokenStorage();
43
-
44
- static readonly httpHeaders = {
45
- AUTHORIZATION: 'Authorization',
46
- X_TENANT: 'X-Tenant',
47
- X_REFRESH_TOKEN: 'X-RefreshToken',
48
- CONTENT_TYPE: 'Content-Type',
49
- }
50
- }
51
-
52
-
53
- /**
54
- * Waits for a specified amount of time.
55
- * @param milliseconds - The milliseconds to wait.
56
- * @param when - The condition to wait for. Default is true.
57
- * @returns - Promise<void>
58
- */
59
- export async function waitFor(milliseconds: number, when: boolean = true) {
60
- if (!when) return;
61
- await new Promise(resolve => setTimeout(resolve, milliseconds));
62
- }
63
-
64
- /**
65
- * Waits until the condition is met.
66
- * @param when - The condition to wait for.
67
- * @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.
68
- */
69
- export async function waitUntil(when: () => any, intervalNumber: number = 50) {
70
- await new Promise(resolve => {
71
- const interval = setInterval(async () => {
72
- const cond = when();
73
- const result = cond instanceof Promise ? await cond : cond;
74
- if (result) {
75
- clearInterval(interval);
76
- resolve(true);
77
- }
78
- }, intervalNumber);
79
- });
80
- }
81
-
82
- export function extractMainDomain(subdomain?: string): string {
83
- subdomain ??= window.location.hostname;
84
- const parts = subdomain.split('.');
85
- return parts.length > 2 ? parts.slice(-2).join('.') : subdomain;
86
- }
package/src/main.ts DELETED
@@ -1,7 +0,0 @@
1
- import { AppModule } from './app/app.module';
2
- import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3
- import "src/types/index";
4
-
5
-
6
- platformBrowserDynamic().bootstrapModule(AppModule)
7
- .catch(err => console.error(err));
package/src/polyfills.ts DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * This file includes polyfills needed by Angular and is loaded before the app.
3
- * You can add your own extra polyfills to this file.
4
- *
5
- * This file is divided into 2 sections:
6
- * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7
- * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8
- * file.
9
- *
10
- * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11
- * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12
- * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13
- *
14
- * Learn more in https://angular.io/guide/browser-support
15
- */
16
-
17
- /***************************************************************************************************
18
- * BROWSER POLYFILLS
19
- */
20
-
21
- /**
22
- * By default, zone.js will patch all possible macroTask and DomEvents
23
- * user can disable parts of macroTask/DomEvents patch by setting following flags
24
- * because those flags need to be set before `zone.js` being loaded, and webpack
25
- * will put import in the top of bundle, so user need to create a separate file
26
- * in this directory (for example: zone-flags.ts), and put the following flags
27
- * into that file, and then add the following code before importing zone.js.
28
- * import './zone-flags';
29
- *
30
- * The flags allowed in zone-flags.ts are listed here.
31
- *
32
- * The following flags will work for all browsers.
33
- *
34
- * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
35
- * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
36
- * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
37
- *
38
- * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
39
- * with the following flag, it will bypass `zone.js` patch for IE/Edge
40
- *
41
- * (window as any).__Zone_enable_cross_context_check = true;
42
- *
43
- */
44
-
45
- /***************************************************************************************************
46
- * Zone JS is required by default for Angular itself.
47
- */
48
- import 'zone.js'; // Included with Angular CLI.
49
-
50
-
51
- /***************************************************************************************************
52
- * APPLICATION IMPORTS
53
- */
package/src/styles.css DELETED
File without changes
File without changes
package/tsconfig.app.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./out-tsc/app",
5
- "types": []
6
- },
7
- "files": [
8
- "src/main.ts",
9
- "src/polyfills.ts"
10
- ],
11
- "include": [
12
- "src/**/*.d.ts"
13
- ]
14
- }
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "rootDir": "./src",
4
- "outDir": "./out-tsc",
5
- "sourceMap": true,
6
- "declaration": true,
7
- "module": "es2015",
8
- "moduleResolution": "node",
9
- "target": "es5",
10
- "baseUrl": "./",
11
- "paths": {
12
- "@sambath999/localize-token": [
13
- "src/localize-token/src/public-api",
14
- "src/localize-logindlg/public-api"
15
- ],
16
- },
17
- "lib": [
18
- "es2018",
19
- "dom"
20
- ],
21
- "types": [],
22
- "experimentalDecorators": true,
23
- "emitDecoratorMetadata": true,
24
- "skipLibCheck": true,
25
- "strict": true
26
- },
27
- "angularCompilerOptions": {
28
- "skipTemplateCodegen": false,
29
- "strictMetadataEmit": true,
30
- "fullTemplateTypeCheck": true,
31
- "strictInjectionParameters": true,
32
- "enableIvy": true,
33
- "generateNgTypeCheckFiles": true
34
- },
35
- "include": [
36
- "src/**/*.ts"
37
- ]
38
- }
File without changes
File without changes