@sambath999/localize-token 12.2.7 → 18.0.0

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