@sambath999/localize-token 12.2.8 → 18.0.1

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 (41) hide show
  1. package/esm2022/lib/index.mjs +6 -0
  2. package/esm2022/lib/localize.api.service.mjs +137 -0
  3. package/esm2022/lib/localize.token.mjs +54 -0
  4. package/esm2022/lib/localize.token.module.mjs +22 -0
  5. package/esm2022/lib/localize.token.service.mjs +61 -0
  6. package/esm2022/lib/localize.token.storage.mjs +101 -0
  7. package/esm2022/public-api.mjs +2 -0
  8. package/{esm2015/sambath999-localize-token.js → esm2022/sambath999-localize-token.mjs} +4 -4
  9. package/fesm2022/sambath999-localize-token.mjs +370 -0
  10. package/fesm2022/sambath999-localize-token.mjs.map +1 -0
  11. package/{sambath999-localize-token.d.ts → index.d.ts} +5 -4
  12. package/lib/index.d.ts +5 -0
  13. package/{localize-token → lib}/localize.api.service.d.ts +62 -67
  14. package/{localize-token → lib}/localize.token.d.ts +35 -42
  15. package/lib/localize.token.module.d.ts +6 -0
  16. package/{localize-token → lib}/localize.token.service.d.ts +29 -26
  17. package/{localize-token → lib}/localize.token.storage.d.ts +61 -61
  18. package/package.json +24 -15
  19. package/public-api.d.ts +1 -2
  20. package/bundles/sambath999-localize-token.umd.js +0 -1123
  21. package/bundles/sambath999-localize-token.umd.js.map +0 -1
  22. package/esm2015/localize-logindlg/localize-logindlg.component.js +0 -389
  23. package/esm2015/localize-logindlg/localize-logindlg.module.js +0 -28
  24. package/esm2015/localize-logindlg/localize-logindlg.service.js +0 -37
  25. package/esm2015/localize-logindlg/public-api.js +0 -4
  26. package/esm2015/localize-token/localize.api.service.js +0 -155
  27. package/esm2015/localize-token/localize.token.js +0 -60
  28. package/esm2015/localize-token/localize.token.module.js +0 -14
  29. package/esm2015/localize-token/localize.token.service.js +0 -64
  30. package/esm2015/localize-token/localize.token.storage.js +0 -107
  31. package/esm2015/localize-token/public-api.js +0 -6
  32. package/esm2015/public-api.js +0 -3
  33. package/fesm2015/sambath999-localize-token.js +0 -835
  34. package/fesm2015/sambath999-localize-token.js.map +0 -1
  35. package/localize-logindlg/localize-logindlg.component.d.ts +0 -31
  36. package/localize-logindlg/localize-logindlg.module.d.ts +0 -2
  37. package/localize-logindlg/localize-logindlg.service.d.ts +0 -17
  38. package/localize-logindlg/public-api.d.ts +0 -3
  39. package/localize-token/localize.token.module.d.ts +0 -2
  40. package/localize-token/public-api.d.ts +0 -5
  41. package/sambath999-localize-token.metadata.json +0 -1
@@ -0,0 +1,370 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, NgModule } from '@angular/core';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ import * as jwt_decode from 'jwt-decode';
5
+ import { HttpHeaders } from '@angular/common/http';
6
+
7
+ /**
8
+ * Assembly of @package ng2-cookies @see https://www.npmjs.com/package/ng2-cookies
9
+ *
10
+ * Reassembled by
11
+ * @author sambath999
12
+ * @date_29_09_2021
13
+ * Updated from raw parameters to
14
+ * @param {ICookieOptions} options and added another newer cookie flag
15
+ * @param {string} samesite
16
+ * @param {constant} SameSiteTypes, @param {string} strict "strict", @param {string} lax "lax", @param {string} none "none"
17
+ *
18
+ * @enum
19
+ */
20
+ class LocalizeTokenStorageHelper {
21
+ /**
22
+ * Checks the existence of a single cookie by it's name
23
+ *
24
+ * @param {string} name Identification of the cookie
25
+ * @returns existence of the cookie
26
+ */
27
+ check(name) {
28
+ if (typeof document === "undefined")
29
+ return false;
30
+ name = encodeURIComponent(name);
31
+ const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
32
+ return regexp.test(document.cookie);
33
+ }
34
+ /**
35
+ * Retrieves a single cookie by it's name
36
+ *
37
+ * @param {string} name Identification of the Cookie
38
+ * @returns The Cookie's value
39
+ */
40
+ get(name) {
41
+ if (!this.check(name))
42
+ return undefined;
43
+ name = encodeURIComponent(name);
44
+ const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
45
+ const result = regexp.exec(document.cookie);
46
+ return result ? decodeURIComponent(result[1]) : undefined;
47
+ }
48
+ /**
49
+ * Retrieves a a list of all cookie avaiable
50
+ *
51
+ * @returns Object with all Cookies
52
+ */
53
+ getAll() {
54
+ const cookies = {};
55
+ if (document.cookie) {
56
+ const split = document.cookie.split(';');
57
+ for (const s of split) {
58
+ const currCookie = s.split('=');
59
+ currCookie[0] = currCookie[0].trim();
60
+ cookies[decodeURIComponent(currCookie[0])] = decodeURIComponent(currCookie[1]);
61
+ }
62
+ }
63
+ return cookies;
64
+ }
65
+ get defaultOptions() { return LocalizeToken.cookieOptions; }
66
+ set(name, value, options) {
67
+ options ??= this.defaultOptions;
68
+ const { expires, path, domain, secure, samesite } = options;
69
+ let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)};`;
70
+ if (expires) {
71
+ const dtExpires = typeof expires === 'number' ? new Date(Date.now() + expires * 864e5) : expires;
72
+ cookieStr += `expires=${dtExpires.toUTCString()};`;
73
+ }
74
+ cookieStr += path ? `path=${path};` : '';
75
+ cookieStr += domain ? `domain=${domain};` : '';
76
+ cookieStr += secure ? 'secure;' : '';
77
+ cookieStr += samesite ? `samesite=${samesite};` : '';
78
+ document.cookie = cookieStr;
79
+ }
80
+ /**
81
+ * Removes specified Cookie
82
+ *
83
+ * @param {string} name Cookie's identification
84
+ * @param {string} path Path relative to the domain where the cookie should be avaiable. Default /
85
+ * @param {string} domain Domain where the cookie should be avaiable. Default current domain
86
+ */
87
+ delete(name, path = '/', domain = window.location.hostname) {
88
+ this.set(name, '', { path, domain, expires: -1 });
89
+ }
90
+ /**
91
+ * Delete all cookie avaiable
92
+ */
93
+ deleteAll(path, domain) {
94
+ const cookies = this.getAll();
95
+ for (const cookieName of Object.keys(cookies)) {
96
+ this.delete(cookieName, path, domain);
97
+ }
98
+ }
99
+ }
100
+ var ISameSiteType;
101
+ (function (ISameSiteType) {
102
+ ISameSiteType["strict"] = "strict";
103
+ ISameSiteType["lax"] = "lax";
104
+ ISameSiteType["none"] = "none";
105
+ })(ISameSiteType || (ISameSiteType = {}));
106
+
107
+ class LocalizeToken {
108
+ static config = {
109
+ mainDomain: location.hostname,
110
+ authTokenName: 'auth-token',
111
+ tenantTokenName: 'tenant-token',
112
+ refreshTokenName: 'refresh-token',
113
+ needTenant: false,
114
+ isProduction: false,
115
+ };
116
+ static cookieOptions = {
117
+ path: '/',
118
+ domain: LocalizeToken.config.mainDomain,
119
+ secure: true,
120
+ // samesite: SameSiteType.strict,
121
+ expires: 1
122
+ };
123
+ static storage = new LocalizeTokenStorageHelper();
124
+ static httpHeaders = {
125
+ AUTHORIZATION: 'Authorization',
126
+ X_TENANT: 'X-Tenant',
127
+ X_REFRESH_TOKEN: 'X-RefreshToken',
128
+ CONTENT_TYPE: 'Content-Type',
129
+ };
130
+ }
131
+ /**
132
+ * Waits for a specified amount of time.
133
+ * @param milliseconds - The milliseconds to wait.
134
+ * @param when - The condition to wait for. Default is true.
135
+ * @returns - Promise<void>
136
+ */
137
+ async function waitFor(milliseconds, when = true) {
138
+ if (!when)
139
+ return;
140
+ await new Promise(resolve => setTimeout(resolve, milliseconds));
141
+ }
142
+ /**
143
+ * Waits until the condition is met.
144
+ * @param when - The condition to wait for.
145
+ * @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.
146
+ */
147
+ async function waitUntil(when, intervalNumber = 50) {
148
+ await new Promise(resolve => {
149
+ const interval = setInterval(async () => {
150
+ const cond = when();
151
+ const result = cond instanceof Promise ? await cond : cond;
152
+ if (result) {
153
+ clearInterval(interval);
154
+ resolve(true);
155
+ }
156
+ }, intervalNumber);
157
+ });
158
+ }
159
+
160
+ class LocalizeTokenService {
161
+ isRevokingTokenSubject = new BehaviorSubject(false);
162
+ get authToken() { return this.storageGet(); }
163
+ set authToken(value) {
164
+ value
165
+ ? this.storageSet(value)
166
+ : LocalizeToken.storage.delete(LocalizeToken.config.authTokenName);
167
+ }
168
+ get refreshToken() { return LocalizeToken.storage.get(LocalizeToken.config.refreshTokenName); }
169
+ get accessToken() { return this.authToken?.token; }
170
+ set accessToken(value) {
171
+ if (value) {
172
+ this.authToken = { token: value, revoke: false };
173
+ }
174
+ }
175
+ get isRevokingToken() { return this.isRevokingTokenSubject.value; /* this.authToken?.revoke ?? false */ }
176
+ set isRevokingToken(value) {
177
+ this.isRevokingTokenSubject.next(value);
178
+ if (this.authToken) {
179
+ this.authToken = { ...this.authToken, revoke: value };
180
+ }
181
+ }
182
+ get tenantToken() { return LocalizeToken.storage.get(LocalizeToken.config.tenantTokenName); }
183
+ constructor() { }
184
+ storageGet() {
185
+ try {
186
+ const encoded = LocalizeToken.storage.get(LocalizeToken.config.authTokenName);
187
+ const decoded = atob(encoded || '');
188
+ return JSON.parse(decoded);
189
+ }
190
+ catch {
191
+ return undefined;
192
+ }
193
+ }
194
+ storageSet(value) {
195
+ const base64 = btoa(JSON.stringify(value));
196
+ LocalizeToken.storage.set(LocalizeToken.config.authTokenName, base64);
197
+ }
198
+ tokensValid() {
199
+ return this.refreshToken?.length && (!LocalizeToken.config.needTenant || this.tenantToken?.length);
200
+ }
201
+ decodeToken = (token) => jwt_decode.jwtDecode(token);
202
+ get decodeRefreshToken() {
203
+ const token = LocalizeToken.storage.get(LocalizeToken.config.refreshTokenName);
204
+ if (!token)
205
+ return null;
206
+ return this.decodeToken(token);
207
+ }
208
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
209
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenService, providedIn: 'root' });
210
+ }
211
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenService, decorators: [{
212
+ type: Injectable,
213
+ args: [{ providedIn: 'root' }]
214
+ }], ctorParameters: () => [] });
215
+
216
+ /**
217
+ * Http method options
218
+ */
219
+ var EMethod;
220
+ (function (EMethod) {
221
+ EMethod[EMethod["POST"] = 1] = "POST";
222
+ EMethod[EMethod["GET"] = 2] = "GET";
223
+ EMethod[EMethod["PUT"] = 3] = "PUT";
224
+ EMethod[EMethod["DELETE"] = 4] = "DELETE";
225
+ EMethod[EMethod["PATCH"] = 5] = "PATCH";
226
+ })(EMethod || (EMethod = {}));
227
+ class LocalizeApiService {
228
+ localizeTokenService;
229
+ httpClient;
230
+ isRequestingSubject = new BehaviorSubject(false);
231
+ isResolvedStartupSubject = new BehaviorSubject(false);
232
+ get isRequesting() { return this.isRequestingSubject.value; }
233
+ get isResolvedStartup() { return this.isResolvedStartupSubject.value; }
234
+ apiConfigs = {};
235
+ constructor(localizeTokenService) {
236
+ this.localizeTokenService = localizeTokenService;
237
+ }
238
+ /**
239
+ * Initialize the API service.
240
+ * @param apiConfigs - The API configurations.
241
+ */
242
+ init(httpClient, apiConfigs) {
243
+ this.httpClient = httpClient;
244
+ this.apiConfigs = apiConfigs;
245
+ }
246
+ /**
247
+ * A higher-order function that returns a curried function for making API requests.
248
+ *
249
+ * @param baseUrl - The base URL of the API.
250
+ * @returns A curried function that can be used to make API requests.
251
+ */
252
+ func = (baseUrl) => (path, method = EMethod.GET, value = null, isFormData = false, headers) => this.base(baseUrl, path, method, value, isFormData, headers);
253
+ async base(baseUrl, path, method = EMethod.GET, value = null, isFormData = false, headers) {
254
+ await this.ifPromise(this.apiConfigs.onPrepareRequest);
255
+ const url = `${baseUrl.trim().replace(/\/?$/, '/')}${path.trim().replace(/^\//, '')}`;
256
+ const httpMethod = EMethod[method].toLowerCase();
257
+ const request = () => { return { body: value, headers: this.options(isFormData, headers) }; };
258
+ // Wait for previous request to complete
259
+ await this.toWaitForPreviousRequest();
260
+ // Process request
261
+ try {
262
+ return await this.processRequest(httpMethod, url, request());
263
+ }
264
+ // Handle unauthorized error if any
265
+ catch (error) {
266
+ if (error.status !== 401) {
267
+ throw error;
268
+ }
269
+ return await this.onUnauthorizedError(httpMethod, url, request);
270
+ }
271
+ }
272
+ async onUnauthorizedError(httpMethod, url, request) {
273
+ await this.revokeToken();
274
+ if (!this.isResolvedStartup) {
275
+ return await this.processRequest(httpMethod, url, request());
276
+ }
277
+ }
278
+ async toWaitForPreviousRequest() {
279
+ if (this.localizeTokenService.isRevokingToken) {
280
+ await waitUntil(() => !this.localizeTokenService.isRevokingToken);
281
+ }
282
+ // to wait for each request in 50ms, even if the request is not completed
283
+ await waitFor(50, this.isRequesting);
284
+ }
285
+ async processRequest(method, url, options) {
286
+ this.isRequestingSubject.next(true);
287
+ const result = await new Promise((resolve, reject) => this.httpClient?.request(method, url, options).subscribe({ next: resolve, error: reject }));
288
+ this.isRequestingSubject.next(false);
289
+ return result;
290
+ }
291
+ async revokeToken(force = false) {
292
+ if (this.localizeTokenService.isRevokingToken && !force) {
293
+ await waitUntil(() => !this.localizeTokenService.isRevokingToken);
294
+ return;
295
+ }
296
+ try {
297
+ this.localizeTokenService.isRevokingToken = true;
298
+ const reqUrl = LocalizeToken.config.revokeTokenUrl;
299
+ const reqHeaders = this.options().append(LocalizeToken.httpHeaders.X_REFRESH_TOKEN, `${this.localizeTokenService.refreshToken}`);
300
+ const revokeToken = await new Promise((resolve, reject) => this.httpClient?.get(reqUrl, { headers: reqHeaders }).subscribe({ next: resolve, error: reject }));
301
+ if (revokeToken?.status) {
302
+ this.localizeTokenService.accessToken = revokeToken.message;
303
+ }
304
+ else if (!this.localizeTokenService.refreshToken) {
305
+ await this.ifPromise(this.apiConfigs.onAutoLogout);
306
+ }
307
+ else {
308
+ if (this.apiConfigs.onRevokeUnauthorized) {
309
+ await this.ifPromise(this.apiConfigs.onRevokeUnauthorized);
310
+ await this.revokeToken(true);
311
+ }
312
+ }
313
+ }
314
+ finally {
315
+ this.localizeTokenService.isRevokingToken = false;
316
+ }
317
+ }
318
+ /** default http request options */
319
+ options(isFormData = false, headers = {}) {
320
+ const defaultHeaders = { [LocalizeToken.httpHeaders.AUTHORIZATION]: `Bearer ${this.localizeTokenService.accessToken}`, };
321
+ if (LocalizeToken.config.needTenant) {
322
+ defaultHeaders[LocalizeToken.httpHeaders.X_TENANT] = `${this.localizeTokenService.tenantToken}`;
323
+ }
324
+ if (!isFormData) {
325
+ defaultHeaders[LocalizeToken.httpHeaders.CONTENT_TYPE] = 'application/json';
326
+ }
327
+ const filteredHeaders = Object.keys(defaultHeaders).filter(key => !Object.keys(headers).includes(key))
328
+ .reduce((acc, key) => ({ ...acc, [key]: defaultHeaders[key] }), {});
329
+ const mergedHeaders = { ...filteredHeaders, ...headers };
330
+ return new HttpHeaders(mergedHeaders);
331
+ }
332
+ async ifPromise(fn) {
333
+ if (!fn)
334
+ return;
335
+ return fn instanceof Promise ? await fn() : fn();
336
+ }
337
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeApiService, deps: [{ token: LocalizeTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
338
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeApiService, providedIn: 'root' });
339
+ } //class
340
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeApiService, decorators: [{
341
+ type: Injectable,
342
+ args: [{
343
+ providedIn: 'root'
344
+ }]
345
+ }], ctorParameters: () => [{ type: LocalizeTokenService }] });
346
+
347
+ class LocalizeTokenModule {
348
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
349
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenModule });
350
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenModule, providers: [
351
+ LocalizeTokenService,
352
+ LocalizeApiService
353
+ ] });
354
+ }
355
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: LocalizeTokenModule, decorators: [{
356
+ type: NgModule,
357
+ args: [{
358
+ providers: [
359
+ LocalizeTokenService,
360
+ LocalizeApiService
361
+ ],
362
+ }]
363
+ }] });
364
+
365
+ /**
366
+ * Generated bundle index. Do not edit.
367
+ */
368
+
369
+ export { EMethod, ISameSiteType, LocalizeApiService, LocalizeToken, LocalizeTokenModule, LocalizeTokenService, LocalizeTokenStorageHelper, waitFor, waitUntil };
370
+ //# sourceMappingURL=sambath999-localize-token.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sambath999-localize-token.mjs","sources":["../../src/lib/localize.token.storage.ts","../../src/lib/localize.token.ts","../../src/lib/localize.token.service.ts","../../src/lib/localize.api.service.ts","../../src/lib/localize.token.module.ts","../../src/sambath999-localize-token.ts"],"sourcesContent":["import { LocalizeToken } from \"./localize.token\";\r\n\r\n\r\n/**\r\n* Assembly of @package ng2-cookies @see https://www.npmjs.com/package/ng2-cookies\r\n*\r\n* Reassembled by\r\n* @author sambath999\r\n* @date_29_09_2021\r\n* Updated from raw parameters to\r\n* @param {ICookieOptions} options and added another newer cookie flag\r\n* @param {string} samesite\r\n* @param {constant} SameSiteTypes, @param {string} strict \"strict\", @param {string} lax \"lax\", @param {string} none \"none\"\r\n*\r\n* @enum\r\n*/\r\nexport class LocalizeTokenStorageHelper {\r\n\r\n /**\r\n * Checks the existence of a single cookie by it's name\r\n *\r\n * @param {string} name Identification of the cookie\r\n * @returns existence of the cookie\r\n */\r\n check(name: string): boolean {\r\n if (typeof document === \"undefined\") return false;\r\n name = encodeURIComponent(name);\r\n const regexp = new RegExp('(?:^' + name + '|;\\\\s*' + name + ')=(.*?)(?:;|$)', 'g');\r\n return regexp.test(document.cookie);\r\n }\r\n\r\n /**\r\n * Retrieves a single cookie by it's name\r\n *\r\n * @param {string} name Identification of the Cookie\r\n * @returns The Cookie's value\r\n */\r\n get(name: string): string | undefined {\r\n if (!this.check(name)) return undefined;\r\n\r\n name = encodeURIComponent(name);\r\n const regexp = new RegExp('(?:^' + name + '|;\\\\s*' + name + ')=(.*?)(?:;|$)', 'g');\r\n const result = regexp.exec(document.cookie);\r\n return result ? decodeURIComponent(result[1]) : undefined;\r\n }\r\n\r\n /**\r\n * Retrieves a a list of all cookie avaiable\r\n *\r\n * @returns Object with all Cookies\r\n */\r\n getAll(): any {\r\n const cookies: any = {};\r\n\r\n if (document.cookie) {\r\n const split = document.cookie.split(';');\r\n for (const s of split) {\r\n const currCookie = s.split('=');\r\n currCookie[0] = currCookie[0].trim();\r\n cookies[decodeURIComponent(currCookie[0])] = decodeURIComponent(currCookie[1]);\r\n }\r\n }\r\n\r\n return cookies;\r\n }\r\n\r\n get defaultOptions(): ICookieOptions { return LocalizeToken.cookieOptions }\r\n\r\n\r\n set(name: string, value: string, options?: ICookieOptions) {\r\n options ??= this.defaultOptions;\r\n const { expires, path, domain, secure, samesite } = options;\r\n let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)};`;\r\n\r\n if (expires) {\r\n const dtExpires = typeof expires === 'number' ? new Date(Date.now() + expires * 864e5) : expires;\r\n cookieStr += `expires=${dtExpires.toUTCString()};`;\r\n }\r\n\r\n cookieStr += path ? `path=${path};` : '';\r\n cookieStr += domain ? `domain=${domain};` : '';\r\n cookieStr += secure ? 'secure;' : '';\r\n cookieStr += samesite ? `samesite=${samesite};` : '';\r\n\r\n document.cookie = cookieStr;\r\n }\r\n\r\n /**\r\n * Removes specified Cookie\r\n *\r\n * @param {string} name Cookie's identification\r\n * @param {string} path Path relative to the domain where the cookie should be avaiable. Default /\r\n * @param {string} domain Domain where the cookie should be avaiable. Default current domain\r\n */\r\n delete(name: string, path: string = '/', domain: string = window.location.hostname): void {\r\n this.set(name, '', { path, domain, expires: -1 });\r\n }\r\n\r\n /**\r\n * Delete all cookie avaiable\r\n */\r\n deleteAll(path?: string, domain?: string): void {\r\n const cookies = this.getAll();\r\n\r\n for (const cookieName of Object.keys(cookies)) {\r\n this.delete(cookieName, path, domain);\r\n }\r\n }\r\n\r\n}\r\n\r\nexport enum ISameSiteType {\r\n strict = \"strict\",\r\n lax = \"lax\",\r\n none = \"none\"\r\n}\r\n\r\nexport interface ICookieOptions {\r\n expires?: number | Date;\r\n path?: string;\r\n domain?: string;\r\n secure?: boolean;\r\n samesite?: string\r\n}\r\n","import { ICookieOptions, LocalizeTokenStorageHelper } from \"./localize.token.storage\";\r\ninterface ILocalizeTokenConfig {\r\n mainDomain: string;\r\n authTokenName: string;\r\n tenantTokenName: string;\r\n refreshTokenName: string;\r\n needTenant: boolean;\r\n isProduction: boolean;\r\n revokeTokenUrl?: string;\r\n}\r\nexport class LocalizeToken {\r\n static config: ILocalizeTokenConfig = {\r\n mainDomain: location.hostname,\r\n authTokenName: 'auth-token',\r\n tenantTokenName: 'tenant-token',\r\n refreshTokenName: 'refresh-token',\r\n needTenant: false,\r\n isProduction: false,\r\n }\r\n\r\n static cookieOptions: ICookieOptions = {\r\n path: '/',\r\n domain: LocalizeToken.config.mainDomain,\r\n secure: true,\r\n // samesite: SameSiteType.strict,\r\n expires: 1\r\n }\r\n static readonly storage = new LocalizeTokenStorageHelper();\r\n\r\n static readonly httpHeaders = {\r\n AUTHORIZATION: 'Authorization',\r\n X_TENANT: 'X-Tenant',\r\n X_REFRESH_TOKEN: 'X-RefreshToken',\r\n CONTENT_TYPE: 'Content-Type',\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Waits for a specified amount of time.\r\n * @param milliseconds - The milliseconds to wait.\r\n * @param when - The condition to wait for. Default is true.\r\n * @returns - Promise<void>\r\n */\r\nexport async function waitFor(milliseconds: number, when: boolean = true) {\r\n if (!when) return;\r\n await new Promise(resolve => setTimeout(resolve, milliseconds));\r\n }\r\n \r\n /**\r\n * Waits until the condition is met.\r\n * @param when - The condition to wait for.\r\n * @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.\r\n */\r\n export async function waitUntil(when: () => any, intervalNumber: number = 50) {\r\n await new Promise(resolve => {\r\n const interval = setInterval(async () => {\r\n const cond = when();\r\n const result = cond instanceof Promise ? await cond : cond;\r\n if (result) {\r\n clearInterval(interval);\r\n resolve(true);\r\n }\r\n }, intervalNumber);\r\n });\r\n }","import { Injectable } from '@angular/core';\r\nimport { LocalizeToken } from './localize.token';\r\nimport { BehaviorSubject } from 'rxjs';\r\nimport * as jwt_decode from 'jwt-decode';\r\nexport interface JwtPayload extends jwt_decode.JwtPayload {\r\n // Define the structure of your JWT payload here\r\n email: string;\r\n sub: string;\r\n name: string;\r\n iat: number;\r\n exp: number;\r\n // Add other fields as needed\r\n}\r\n\r\ninterface IAuthToken {\r\n token: string;\r\n revoke: boolean;\r\n}\r\n\r\n@Injectable({ providedIn: 'root' })\r\nexport class LocalizeTokenService {\r\n readonly isRevokingTokenSubject = new BehaviorSubject<boolean>(false);\r\n\r\n private get authToken() { return this.storageGet() }\r\n private set authToken(value: IAuthToken | undefined) {\r\n value\r\n ? this.storageSet(value)\r\n : LocalizeToken.storage.delete(LocalizeToken.config.authTokenName);\r\n }\r\n\r\n get refreshToken() { return LocalizeToken.storage.get(LocalizeToken.config.refreshTokenName) }\r\n get accessToken() { return this.authToken?.token }\r\n\r\n set accessToken(value: string | undefined) {\r\n if (value) {\r\n this.authToken = { token: value, revoke: false }\r\n }\r\n }\r\n\r\n get isRevokingToken() { return this.isRevokingTokenSubject.value /* this.authToken?.revoke ?? false */ }\r\n set isRevokingToken(value: boolean) {\r\n this.isRevokingTokenSubject.next(value);\r\n if (this.authToken) {\r\n this.authToken = { ...this.authToken, revoke: value };\r\n }\r\n }\r\n\r\n get tenantToken() { return LocalizeToken.storage.get(LocalizeToken.config.tenantTokenName) }\r\n\r\n constructor() { }\r\n\r\n private storageGet() {\r\n try {\r\n const encoded = LocalizeToken.storage.get(LocalizeToken.config.authTokenName);\r\n const decoded = atob(encoded || '');\r\n return JSON.parse(decoded) as IAuthToken;\r\n } catch {\r\n return undefined\r\n }\r\n }\r\n\r\n private storageSet(value: IAuthToken) {\r\n const base64 = btoa(JSON.stringify(value));\r\n LocalizeToken.storage.set(LocalizeToken.config.authTokenName, base64);\r\n }\r\n\r\n tokensValid() {\r\n return this.refreshToken?.length && (!LocalizeToken.config.needTenant || this.tenantToken?.length);\r\n }\r\n\r\n decodeToken = (token: string) => jwt_decode.jwtDecode<JwtPayload>(token);\r\n get decodeRefreshToken() {\r\n const token = LocalizeToken.storage.get(LocalizeToken.config.refreshTokenName);\r\n if (!token) return null;\r\n return this.decodeToken(token);\r\n }\r\n\r\n}\r\n","import { Injectable } from \"@angular/core\";\r\nimport { LocalizeTokenService } from \"./localize.token.service\";\r\nimport { HttpClient, HttpHeaders } from \"@angular/common/http\";\r\nimport { LocalizeToken, waitFor, waitUntil } from \"./localize.token\";\r\nimport { BehaviorSubject } from \"rxjs\";\r\n\r\n/**\r\n * Http method options\r\n */\r\nexport enum EMethod {\r\n POST = 1,\r\n GET = 2,\r\n PUT = 3,\r\n DELETE = 4,\r\n PATCH = 5\r\n}\r\n\r\ninterface ILocalizeApiConfigs {\r\n onPrepareRequest?: () => any;\r\n /**\r\n * A function that is called when refresh token is missing then perform the auto logout.\r\n * @returns - The base URL of the API.\r\n */\r\n onAutoLogout?: () => any;\r\n /**\r\n * A function that is called when request revoking token unauthorized.\r\n * @returns - The login dialog service.\r\n */\r\n onRevokeUnauthorized?: () => any;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class LocalizeApiService {\r\n\r\n private httpClient?: HttpClient;\r\n readonly isRequestingSubject = new BehaviorSubject<boolean>(false);\r\n readonly isResolvedStartupSubject = new BehaviorSubject<boolean>(false);\r\n get isRequesting() { return this.isRequestingSubject.value; }\r\n get isResolvedStartup() { return this.isResolvedStartupSubject.value; }\r\n\r\n private apiConfigs: ILocalizeApiConfigs = {};\r\n\r\n constructor(private readonly localizeTokenService: LocalizeTokenService) { }\r\n\r\n /**\r\n * Initialize the API service.\r\n * @param apiConfigs - The API configurations.\r\n */\r\n init(httpClient: HttpClient, apiConfigs: ILocalizeApiConfigs) {\r\n this.httpClient = httpClient;\r\n this.apiConfigs = apiConfigs;\r\n }\r\n\r\n\r\n /**\r\n * A higher-order function that returns a curried function for making API requests.\r\n *\r\n * @param baseUrl - The base URL of the API.\r\n * @returns A curried function that can be used to make API requests.\r\n */\r\n func = (baseUrl: string) =>\r\n (path: string, method: EMethod = EMethod.GET, value: any = null, isFormData: boolean = false, headers?: { [x: string]: string }) =>\r\n this.base(baseUrl, path, method, value, isFormData, headers)\r\n\r\n private async base(baseUrl: string,\r\n path: string,\r\n method: EMethod = EMethod.GET,\r\n value: any = null,\r\n isFormData: boolean = false,\r\n headers?: { [x: string]: string }) {\r\n\r\n await this.ifPromise(this.apiConfigs.onPrepareRequest);\r\n\r\n const url = `${baseUrl.trim().replace(/\\/?$/, '/')}${path.trim().replace(/^\\//, '')}`;\r\n const httpMethod = EMethod[method].toLowerCase();\r\n const request = () => { return { body: value, headers: this.options(isFormData, headers) } };\r\n\r\n // Wait for previous request to complete\r\n await this.toWaitForPreviousRequest();\r\n\r\n // Process request\r\n try { return await this.processRequest(httpMethod, url, request()) }\r\n // Handle unauthorized error if any\r\n catch (error) {\r\n if ((error as any).status !== 401) { throw error; }\r\n return await this.onUnauthorizedError(httpMethod, url, request);\r\n }\r\n }\r\n\r\n private async onUnauthorizedError(httpMethod: string, url: string, request: Function) {\r\n await this.revokeToken();\r\n if (!this.isResolvedStartup) {\r\n return await this.processRequest(httpMethod, url, request());\r\n }\r\n }\r\n\r\n private async toWaitForPreviousRequest() {\r\n if (this.localizeTokenService.isRevokingToken) {\r\n await waitUntil(() => !this.localizeTokenService.isRevokingToken);\r\n }\r\n // to wait for each request in 50ms, even if the request is not completed\r\n await waitFor(50, this.isRequesting);\r\n }\r\n\r\n private async processRequest(method: string, url: string, options: any): Promise<any> {\r\n this.isRequestingSubject.next(true);\r\n const result = await new Promise((resolve, reject) =>\r\n this.httpClient?.request<any>(method, url, options).subscribe({ next: resolve, error: reject }))\r\n this.isRequestingSubject.next(false);\r\n return result;\r\n }\r\n\r\n private async revokeToken(force: boolean = false): Promise<void> {\r\n\r\n if (this.localizeTokenService.isRevokingToken && !force) {\r\n await waitUntil(() => !this.localizeTokenService.isRevokingToken)\r\n return;\r\n }\r\n\r\n try {\r\n this.localizeTokenService.isRevokingToken = true;\r\n const reqUrl = LocalizeToken.config.revokeTokenUrl;\r\n const reqHeaders = this.options().append(LocalizeToken.httpHeaders.X_REFRESH_TOKEN, `${this.localizeTokenService.refreshToken}`);\r\n const revokeToken: any = await new Promise((resolve, reject) =>\r\n this.httpClient?.get<any>(reqUrl!, { headers: reqHeaders }).subscribe({ next: resolve, error: reject }))\r\n\r\n if (revokeToken?.status) {\r\n this.localizeTokenService.accessToken = revokeToken.message;\r\n } else if (!this.localizeTokenService.refreshToken) {\r\n await this.ifPromise(this.apiConfigs.onAutoLogout)\r\n } else {\r\n if (this.apiConfigs.onRevokeUnauthorized) {\r\n await this.ifPromise(this.apiConfigs.onRevokeUnauthorized);\r\n await this.revokeToken(true);\r\n }\r\n }\r\n } finally {\r\n this.localizeTokenService.isRevokingToken = false;\r\n }\r\n }\r\n\r\n /** default http request options */\r\n private options(isFormData: boolean = false, headers: { [key: string]: string } = {}): HttpHeaders {\r\n const defaultHeaders = { [LocalizeToken.httpHeaders.AUTHORIZATION]: `Bearer ${this.localizeTokenService.accessToken}`, };\r\n if (LocalizeToken.config.needTenant) {\r\n defaultHeaders[LocalizeToken.httpHeaders.X_TENANT] = `${this.localizeTokenService.tenantToken}`;\r\n }\r\n\r\n if (!isFormData) {\r\n defaultHeaders[LocalizeToken.httpHeaders.CONTENT_TYPE] = 'application/json';\r\n }\r\n\r\n const filteredHeaders = Object.keys(defaultHeaders).filter(key => !Object.keys(headers).includes(key))\r\n .reduce((acc, key) => ({ ...acc, [key]: defaultHeaders[key] }), {})\r\n const mergedHeaders = { ...filteredHeaders, ...headers };\r\n return new HttpHeaders(mergedHeaders);\r\n }\r\n\r\n private async ifPromise(fn?: Function) {\r\n if (!fn) return;\r\n return fn instanceof Promise ? await fn() : fn();\r\n }\r\n\r\n}//class\r\n","import { NgModule } from '@angular/core';\r\nimport { LocalizeTokenService } from './localize.token.service';\r\nimport { LocalizeApiService } from './localize.api.service';\r\n\r\n@NgModule({\r\n providers: [\r\n LocalizeTokenService,\r\n LocalizeApiService\r\n ],\r\n})\r\nexport class LocalizeTokenModule { }","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.LocalizeTokenService"],"mappings":";;;;;;AAGA;;;;;;;;;;;;AAYE;MACW,0BAA0B,CAAA;AAErC;;;;;AAKG;AACH,IAAA,KAAK,CAAC,IAAY,EAAA;QAChB,IAAI,OAAO,QAAQ,KAAK,WAAW;AAAE,YAAA,OAAO,KAAK;AACjD,QAAA,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC;AAC/B,QAAA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,gBAAgB,EAAE,GAAG,CAAC;QAClF,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;;AAGrC;;;;;AAKG;AACH,IAAA,GAAG,CAAC,IAAY,EAAA;AACd,QAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO,SAAS;AAEvC,QAAA,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC;AAC/B,QAAA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,gBAAgB,EAAE,GAAG,CAAC;QAClF,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AAC3C,QAAA,OA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A;AAAnB,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,EALjB,SAAA,EAAA;YACP,oBAAoB;YACpB;AACH,SAAA,EAAA,CAAA;;4FAEQ,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAN/B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACN,oBAAA,SAAS,EAAE;wBACP,oBAAoB;wBACpB;AACH,qBAAA;AACJ,iBAAA;;;ACTD;;AAEG;;;;"}
@@ -1,4 +1,5 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './public-api';
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@sambath999/localize-token" />
5
+ export * from './public-api';
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './localize.token.service';
2
+ export * from './localize.token';
3
+ export * from './localize.token.storage';
4
+ export * from './localize.token.module';
5
+ export * from './localize.api.service';
@@ -1,67 +1,62 @@
1
- import { LocalizeTokenService } from "./localize.token.service";
2
- import { HttpClient } from "@angular/common/http";
3
- import { BehaviorSubject } from "rxjs";
4
- /**
5
- * Http method options
6
- */
7
- export declare enum EMethod {
8
- POST = 1,
9
- GET = 2,
10
- PUT = 3,
11
- DELETE = 4,
12
- PATCH = 5
13
- }
14
- interface ILocalizeApiConfigs {
15
- tenantTokenName?: string;
16
- onPrepareRequest?: () => any;
17
- /**
18
- * A function that is called when refresh token is missing then perform the auto logout.
19
- * @returns - The base URL of the API.
20
- */
21
- onAutoLogout?: () => any;
22
- /**
23
- * A function that is called when request revoking token unauthorized.
24
- * @returns - The login dialog service.
25
- */
26
- onRevokeUnauthorized?: () => any;
27
- /**
28
- * The time to wait for each request to complete in milliseconds.
29
- * Be careful with this option, it may cause the application to hang if the request is not completed.
30
- */
31
- waitEachRequest?: {
32
- milliseconds: number;
33
- };
34
- }
35
- export declare class LocalizeApiService {
36
- readonly httpClient: HttpClient;
37
- private readonly localizeTokenService;
38
- readonly isRequestingSubject: BehaviorSubject<boolean>;
39
- readonly isResolvedStartupSubject: BehaviorSubject<boolean>;
40
- get isRequesting(): boolean;
41
- get isResolvedStartup(): boolean;
42
- private apiConfigs;
43
- constructor(httpClient: HttpClient, localizeTokenService: LocalizeTokenService);
44
- /**
45
- * Initialize the API service.
46
- * @param apiConfigs - The API configurations.
47
- */
48
- init(apiConfigs: ILocalizeApiConfigs): void;
49
- /**
50
- * A higher-order function that returns a curried function for making API requests.
51
- *
52
- * @param baseUrl - The base URL of the API.
53
- * @returns A curried function that can be used to make API requests.
54
- */
55
- func: (baseUrl: string) => (path: string, method?: EMethod, value?: any, isFormData?: boolean, headers?: {
56
- [x: string]: string;
57
- }) => Promise<any>;
58
- private base;
59
- private onUnauthorizedError;
60
- private toWaitForPreviousRequest;
61
- private processRequest;
62
- private revokeToken;
63
- /** default http request options */
64
- private options;
65
- private ifPromise;
66
- }
67
- export {};
1
+ import { LocalizeTokenService } from "./localize.token.service";
2
+ import { HttpClient } from "@angular/common/http";
3
+ import { BehaviorSubject } from "rxjs";
4
+ import * as i0 from "@angular/core";
5
+ /**
6
+ * Http method options
7
+ */
8
+ export declare enum EMethod {
9
+ POST = 1,
10
+ GET = 2,
11
+ PUT = 3,
12
+ DELETE = 4,
13
+ PATCH = 5
14
+ }
15
+ interface ILocalizeApiConfigs {
16
+ onPrepareRequest?: () => any;
17
+ /**
18
+ * A function that is called when refresh token is missing then perform the auto logout.
19
+ * @returns - The base URL of the API.
20
+ */
21
+ onAutoLogout?: () => any;
22
+ /**
23
+ * A function that is called when request revoking token unauthorized.
24
+ * @returns - The login dialog service.
25
+ */
26
+ onRevokeUnauthorized?: () => any;
27
+ }
28
+ export declare class LocalizeApiService {
29
+ private readonly localizeTokenService;
30
+ private httpClient?;
31
+ readonly isRequestingSubject: BehaviorSubject<boolean>;
32
+ readonly isResolvedStartupSubject: BehaviorSubject<boolean>;
33
+ get isRequesting(): boolean;
34
+ get isResolvedStartup(): boolean;
35
+ private apiConfigs;
36
+ constructor(localizeTokenService: LocalizeTokenService);
37
+ /**
38
+ * Initialize the API service.
39
+ * @param apiConfigs - The API configurations.
40
+ */
41
+ init(httpClient: HttpClient, apiConfigs: ILocalizeApiConfigs): void;
42
+ /**
43
+ * A higher-order function that returns a curried function for making API requests.
44
+ *
45
+ * @param baseUrl - The base URL of the API.
46
+ * @returns A curried function that can be used to make API requests.
47
+ */
48
+ func: (baseUrl: string) => (path: string, method?: EMethod, value?: any, isFormData?: boolean, headers?: {
49
+ [x: string]: string;
50
+ }) => Promise<any>;
51
+ private base;
52
+ private onUnauthorizedError;
53
+ private toWaitForPreviousRequest;
54
+ private processRequest;
55
+ private revokeToken;
56
+ /** default http request options */
57
+ private options;
58
+ private ifPromise;
59
+ static ɵfac: i0.ɵɵFactoryDeclaration<LocalizeApiService, never>;
60
+ static ɵprov: i0.ɵɵInjectableDeclaration<LocalizeApiService>;
61
+ }
62
+ export {};
@@ -1,42 +1,35 @@
1
- import { LocalizeTokenStorage } from "./localize.token.storage";
2
- export interface ILocalizeTokenConfig {
3
- /**
4
- * The main domain of the application to set the cookies to be available for cross application with subdomains.
5
- *
6
- * Default is location.hostname (current domain) and automatically set extracted main domain if it is subdomain.
7
- */
8
- mainDomain?: string;
9
- authTokenName?: string;
10
- refreshTokenName?: string;
11
- /**
12
- * Flag to determine if the tenant token is required.
13
- */
14
- needTenant: boolean;
15
- isProduction: boolean;
16
- revokeTokenUrl: string;
17
- }
18
- export declare class LocalizeToken {
19
- static init(config: ILocalizeTokenConfig): void;
20
- static config: ILocalizeTokenConfig;
21
- static readonly storage: LocalizeTokenStorage;
22
- static readonly httpHeaders: {
23
- AUTHORIZATION: string;
24
- X_TENANT: string;
25
- X_REFRESH_TOKEN: string;
26
- CONTENT_TYPE: string;
27
- };
28
- }
29
- /**
30
- * Waits for a specified amount of time.
31
- * @param milliseconds - The milliseconds to wait.
32
- * @param when - The condition to wait for. Default is true.
33
- * @returns - Promise<void>
34
- */
35
- export declare function waitFor(milliseconds: number, when?: boolean): Promise<void>;
36
- /**
37
- * Waits until the condition is met.
38
- * @param when - The condition to wait for.
39
- * @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.
40
- */
41
- export declare function waitUntil(when: () => any, intervalNumber?: number): Promise<void>;
42
- export declare function extractMainDomain(subdomain?: string): string;
1
+ import { ICookieOptions, LocalizeTokenStorageHelper } from "./localize.token.storage";
2
+ interface ILocalizeTokenConfig {
3
+ mainDomain: string;
4
+ authTokenName: string;
5
+ tenantTokenName: string;
6
+ refreshTokenName: string;
7
+ needTenant: boolean;
8
+ isProduction: boolean;
9
+ revokeTokenUrl?: string;
10
+ }
11
+ export declare class LocalizeToken {
12
+ static config: ILocalizeTokenConfig;
13
+ static cookieOptions: ICookieOptions;
14
+ static readonly storage: LocalizeTokenStorageHelper;
15
+ static readonly httpHeaders: {
16
+ AUTHORIZATION: string;
17
+ X_TENANT: string;
18
+ X_REFRESH_TOKEN: string;
19
+ CONTENT_TYPE: string;
20
+ };
21
+ }
22
+ /**
23
+ * Waits for a specified amount of time.
24
+ * @param milliseconds - The milliseconds to wait.
25
+ * @param when - The condition to wait for. Default is true.
26
+ * @returns - Promise<void>
27
+ */
28
+ export declare function waitFor(milliseconds: number, when?: boolean): Promise<void>;
29
+ /**
30
+ * Waits until the condition is met.
31
+ * @param when - The condition to wait for.
32
+ * @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.
33
+ */
34
+ export declare function waitUntil(when: () => any, intervalNumber?: number): Promise<void>;
35
+ export {};