@sambath999/localize-token 12.4.11 → 12.4.13
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.
- package/bundles/sambath999-localize-token.umd.js +400 -1125
- package/bundles/sambath999-localize-token.umd.js.map +1 -1
- package/{localize-logindlg/localize-logindlg.component.d.ts → components/localize-token-login-dialog.component.d.ts} +14 -17
- package/esm2015/components/localize-token-login-dialog.component.js +395 -0
- package/esm2015/models/localize-token-models.js +2 -0
- package/esm2015/models/localize-token.module.js +26 -0
- package/esm2015/public-api.js +6 -15
- package/esm2015/sambath999-localize-token.js +1 -1
- package/esm2015/services/localize-token-configure.service.js +32 -0
- package/esm2015/services/localize-token-dialog.service.js +64 -0
- package/fesm2015/sambath999-localize-token.js +64 -906
- package/fesm2015/sambath999-localize-token.js.map +1 -1
- package/{localize-logindlg/localize-logindlg.service.d.ts → models/localize-token-models.d.ts} +1 -10
- package/package.json +2 -2
- package/public-api.d.ts +5 -13
- package/sambath999-localize-token.metadata.json +1 -1
- package/services/localize-token-configure.service.d.ts +9 -0
- package/services/localize-token-dialog.service.d.ts +10 -0
- package/README.md +0 -57
- package/esm2015/localize-api-token/localize-api-token.module.js +0 -21
- package/esm2015/localize-api-token/localize-api-token.service.js +0 -34
- package/esm2015/localize-logindlg/localize-logindlg.component.js +0 -423
- package/esm2015/localize-logindlg/localize-logindlg.module.js +0 -28
- package/esm2015/localize-logindlg/localize-logindlg.service.js +0 -64
- package/esm2015/localize-token/helpers/interfaces.js +0 -19
- package/esm2015/localize-token/helpers/localize.api.assets.js +0 -20
- package/esm2015/localize-token/helpers/loccalize.api.helper.js +0 -267
- package/esm2015/localize-token/localize.api.service.js +0 -242
- package/esm2015/localize-token/localize.token.js +0 -60
- package/esm2015/localize-token/localize.token.module.js +0 -14
- package/esm2015/localize-token/localize.token.service.js +0 -94
- package/esm2015/localize-token/localize.token.storage.js +0 -107
- package/localize-api-token/localize-api-token.module.d.ts +0 -2
- package/localize-api-token/localize-api-token.service.d.ts +0 -12
- package/localize-logindlg/localize-logindlg.module.d.ts +0 -2
- package/localize-token/helpers/interfaces.d.ts +0 -89
- package/localize-token/helpers/localize.api.assets.d.ts +0 -5
- package/localize-token/helpers/loccalize.api.helper.d.ts +0 -32
- package/localize-token/localize.api.service.d.ts +0 -55
- package/localize-token/localize.token.d.ts +0 -55
- package/localize-token/localize.token.service.d.ts +0 -36
- package/localize-token/localize.token.storage.d.ts +0 -61
- /package/{localize-token/localize.token.module.d.ts → models/localize-token.module.d.ts} +0 -0
|
@@ -1,367 +1,87 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import * as i1 from '@angular/common/http';
|
|
3
|
-
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
4
2
|
import * as i0 from '@angular/core';
|
|
5
|
-
import {
|
|
3
|
+
import { Component, ViewEncapsulation, ChangeDetectorRef, Injector, Injectable, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
6
4
|
import { MessageService } from 'primeng/api';
|
|
7
5
|
import { DynamicDialogRef, DynamicDialogConfig, DialogService } from 'primeng/dynamicdialog';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
6
|
+
import { DomSanitizer } from '@angular/platform-browser';
|
|
7
|
+
import * as i1 from '@sambath999/localize-api';
|
|
8
|
+
import { LocalizeApiLoginService, waitFor, LocalizeApiTokenService, LocalizeApiService } from '@sambath999/localize-api';
|
|
11
9
|
import { CommonModule } from '@angular/common';
|
|
12
10
|
import { ToastModule } from 'primeng/toast';
|
|
13
11
|
import { InputTextModule } from 'primeng/inputtext';
|
|
14
12
|
import { ButtonModule } from 'primeng/button';
|
|
15
13
|
import { FormsModule } from '@angular/forms';
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* Reassembled by
|
|
21
|
-
* @author sambath999
|
|
22
|
-
* @date_29_09_2021
|
|
23
|
-
* Updated from raw parameters to
|
|
24
|
-
* @param {ICookieOptions} options and added another newer cookie flag
|
|
25
|
-
* @param {string} samesite
|
|
26
|
-
* @param {constant} SameSiteTypes, @param {string} strict "strict", @param {string} lax "lax", @param {string} none "none"
|
|
27
|
-
*
|
|
28
|
-
* @enum
|
|
29
|
-
*/
|
|
30
|
-
class LocalizeTokenStorage {
|
|
31
|
-
constructor(_defaultOptions) {
|
|
32
|
-
this.defaultOptions = _defaultOptions !== null && _defaultOptions !== void 0 ? _defaultOptions : this.getDefaultOptions;
|
|
33
|
-
}
|
|
34
|
-
get getDefaultOptions() {
|
|
35
|
-
const mainDomain = extractMainDomain(window.location.hostname);
|
|
36
|
-
return {
|
|
37
|
-
path: '/',
|
|
38
|
-
domain: mainDomain,
|
|
39
|
-
secure: true,
|
|
40
|
-
// samesite: SameSiteType.strict,
|
|
41
|
-
expires: 1
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Checks the existence of a single cookie by it's name
|
|
46
|
-
*
|
|
47
|
-
* @param {string} name Identification of the cookie
|
|
48
|
-
* @returns existence of the cookie
|
|
49
|
-
*/
|
|
50
|
-
check(name) {
|
|
51
|
-
if (typeof document === "undefined")
|
|
52
|
-
return false;
|
|
53
|
-
name = encodeURIComponent(name);
|
|
54
|
-
const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
|
|
55
|
-
return regexp.test(document.cookie);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Retrieves a single cookie by it's name
|
|
59
|
-
*
|
|
60
|
-
* @param {string} name Identification of the Cookie
|
|
61
|
-
* @returns The Cookie's value
|
|
62
|
-
*/
|
|
63
|
-
get(name) {
|
|
64
|
-
if (!this.check(name))
|
|
65
|
-
return undefined;
|
|
66
|
-
name = encodeURIComponent(name);
|
|
67
|
-
const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
|
|
68
|
-
const result = regexp.exec(document.cookie);
|
|
69
|
-
return result ? decodeURIComponent(result[1]) : undefined;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Retrieves a a list of all cookie avaiable
|
|
73
|
-
*
|
|
74
|
-
* @returns Object with all Cookies
|
|
75
|
-
*/
|
|
76
|
-
getAll() {
|
|
77
|
-
const cookies = {};
|
|
78
|
-
if (document.cookie) {
|
|
79
|
-
const split = document.cookie.split(';');
|
|
80
|
-
for (const s of split) {
|
|
81
|
-
const currCookie = s.split('=');
|
|
82
|
-
currCookie[0] = currCookie[0].trim();
|
|
83
|
-
cookies[decodeURIComponent(currCookie[0])] = decodeURIComponent(currCookie[1]);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return cookies;
|
|
87
|
-
}
|
|
88
|
-
set(name, value, options) {
|
|
89
|
-
options !== null && options !== void 0 ? options : (options = this.defaultOptions);
|
|
90
|
-
const { expires, path, domain, secure, samesite } = Object.assign(Object.assign({}, this.defaultOptions), options);
|
|
91
|
-
let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)};`;
|
|
92
|
-
if (expires) {
|
|
93
|
-
const dtExpires = typeof expires === 'number' ? new Date(Date.now() + expires * 864e5) : expires;
|
|
94
|
-
cookieStr += `expires=${dtExpires.toUTCString()};`;
|
|
95
|
-
}
|
|
96
|
-
cookieStr += path ? `path=${path};` : '';
|
|
97
|
-
cookieStr += domain ? `domain=${domain};` : '';
|
|
98
|
-
cookieStr += secure ? 'secure;' : '';
|
|
99
|
-
cookieStr += samesite ? `samesite=${samesite};` : '';
|
|
100
|
-
document.cookie = cookieStr;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Removes specified Cookie
|
|
104
|
-
*
|
|
105
|
-
* @param {string} name Cookie's identification
|
|
106
|
-
* @param {string} path Path relative to the domain where the cookie should be avaiable. Default /
|
|
107
|
-
* @param {string} domain Domain where the cookie should be avaiable. Default current domain
|
|
108
|
-
*/
|
|
109
|
-
delete(name, path = '/', domain = window.location.hostname) {
|
|
110
|
-
this.set(name, '', { path, domain, expires: -1 });
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Delete all cookie avaiable
|
|
114
|
-
*/
|
|
115
|
-
deleteAll(path, domain) {
|
|
116
|
-
const cookies = this.getAll();
|
|
117
|
-
for (const cookieName of Object.keys(cookies)) {
|
|
118
|
-
this.delete(cookieName, path, domain);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
class LocalizeToken {
|
|
124
|
-
}
|
|
125
|
-
LocalizeToken.storage = new LocalizeTokenStorage();
|
|
126
|
-
LocalizeToken.httpHeaders = {
|
|
127
|
-
AUTHORIZATION: 'Authorization',
|
|
128
|
-
X_TENANT: 'X-Tenant',
|
|
129
|
-
X_REFRESH_TOKEN: 'X-RefreshToken',
|
|
130
|
-
CONTENT_TYPE: 'Content-Type',
|
|
131
|
-
X_CLIENT: 'X-Client',
|
|
132
|
-
X_SECRET: 'X-Secret'
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Waits for a specified amount of time.
|
|
136
|
-
* @param milliseconds - The milliseconds to wait.
|
|
137
|
-
* @param when - The condition to wait for. Default is true.
|
|
138
|
-
* @returns - Promise<void>
|
|
139
|
-
*/
|
|
140
|
-
function waitFor(milliseconds, when = true) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
if (!when)
|
|
143
|
-
return;
|
|
144
|
-
yield new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Waits until the condition is met.
|
|
149
|
-
* @param when - The condition to wait for.
|
|
150
|
-
* @param intervalNumber - The interval number in milliseconds to check the condition. Default is 50.
|
|
151
|
-
*/
|
|
152
|
-
function waitUntil(when, intervalNumber = 50) {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
function isConditionMet() {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
const cond = when();
|
|
157
|
-
const result = cond instanceof Promise
|
|
158
|
-
? yield cond
|
|
159
|
-
: cond;
|
|
160
|
-
return result;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (yield isConditionMet())
|
|
164
|
-
return;
|
|
165
|
-
yield new Promise(resolve => {
|
|
166
|
-
const interval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
if (yield isConditionMet()) {
|
|
168
|
-
clearInterval(interval);
|
|
169
|
-
resolve(true);
|
|
170
|
-
}
|
|
171
|
-
}), intervalNumber);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function extractMainDomain(subdomain) {
|
|
176
|
-
subdomain !== null && subdomain !== void 0 ? subdomain : (subdomain = window.location.hostname);
|
|
177
|
-
const parts = subdomain.split('.');
|
|
178
|
-
return parts.length > 2 ? parts.slice(-2).join('.') : subdomain;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
class LocalizeTokenService {
|
|
182
|
-
constructor() {
|
|
183
|
-
this.configSubject = new BehaviorSubject({});
|
|
184
|
-
this.isRevokingTokenSubject = new BehaviorSubject(false);
|
|
185
|
-
this.defaultConfig = {
|
|
186
|
-
mainDomain: extractMainDomain(),
|
|
187
|
-
authToken: {
|
|
188
|
-
name: 'auth-token',
|
|
189
|
-
},
|
|
190
|
-
refreshToken: {
|
|
191
|
-
name: 'refresh-token',
|
|
192
|
-
requestUrl: '/api/token/revoke'
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
this.isInitialized = false;
|
|
196
|
-
this.decodeToken = (token) => jwt_decode.jwtDecode(token);
|
|
197
|
-
}
|
|
198
|
-
get config() {
|
|
199
|
-
this.throwIfNotInitialized();
|
|
200
|
-
return this.configSubject.value;
|
|
201
|
-
}
|
|
202
|
-
init(config) {
|
|
203
|
-
console.log('LocalizeTokenService is initialized.');
|
|
204
|
-
this.configSubject.next(Object.assign(Object.assign({}, this.defaultConfig), config));
|
|
205
|
-
this.isInitialized = true;
|
|
206
|
-
}
|
|
207
|
-
ngOnDestroy() {
|
|
208
|
-
// this.configSubject.complete();
|
|
209
|
-
// this.isRevokingTokenSubject.complete();
|
|
210
|
-
}
|
|
211
|
-
get authToken() { return this.storageGet(); }
|
|
212
|
-
set authToken(value) {
|
|
213
|
-
var _a;
|
|
214
|
-
value
|
|
215
|
-
? this.storageSet(value)
|
|
216
|
-
: LocalizeToken.storage.delete((_a = this.config.authToken) === null || _a === void 0 ? void 0 : _a.name);
|
|
217
|
-
}
|
|
218
|
-
get tenantToken() { var _a; return LocalizeToken.storage.get(((_a = this.config.tenantToken) === null || _a === void 0 ? void 0 : _a.name) || ''); }
|
|
219
|
-
get refreshToken() { var _a; return LocalizeToken.storage.get(((_a = this.config.refreshToken) === null || _a === void 0 ? void 0 : _a.name) || ''); }
|
|
220
|
-
get accessToken() { var _a; return (_a = this.authToken) === null || _a === void 0 ? void 0 : _a.token; }
|
|
221
|
-
set accessToken(value) {
|
|
222
|
-
value && (this.authToken = { token: value, revoke: false });
|
|
223
|
-
}
|
|
224
|
-
get isRevokingToken() { return this.isRevokingTokenSubject.value; /* this.authToken?.revoke ?? false */ }
|
|
225
|
-
set isRevokingToken(value) {
|
|
226
|
-
this.isRevokingTokenSubject.next(value);
|
|
227
|
-
this.authToken && (this.authToken = Object.assign(Object.assign({}, this.authToken), { revoke: value }));
|
|
228
|
-
}
|
|
229
|
-
get clientId() { var _a; return LocalizeToken.storage.get(((_a = this.config.thirdPartyConfig) === null || _a === void 0 ? void 0 : _a.clientId) || ''); }
|
|
230
|
-
get clientSecret() { var _a; return LocalizeToken.storage.get(((_a = this.config.thirdPartyConfig) === null || _a === void 0 ? void 0 : _a.clientSecret) || ''); }
|
|
231
|
-
storageGet() {
|
|
232
|
-
var _a;
|
|
233
|
-
try {
|
|
234
|
-
const encoded = LocalizeToken.storage.get(((_a = this.config.authToken) === null || _a === void 0 ? void 0 : _a.name) || '');
|
|
235
|
-
const decoded = atob(encoded || '');
|
|
236
|
-
return JSON.parse(decoded);
|
|
237
|
-
}
|
|
238
|
-
catch (_b) {
|
|
239
|
-
return undefined;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
storageSet(value) {
|
|
243
|
-
var _a;
|
|
244
|
-
const base64 = btoa(JSON.stringify(value));
|
|
245
|
-
LocalizeToken.storage.set(((_a = this.config.authToken) === null || _a === void 0 ? void 0 : _a.name) || '', base64);
|
|
246
|
-
}
|
|
247
|
-
tokensValid() {
|
|
248
|
-
var _a, _b;
|
|
249
|
-
if (!((_a = this.refreshToken) === null || _a === void 0 ? void 0 : _a.length))
|
|
250
|
-
return false;
|
|
251
|
-
if (this.config.requiredTenant && !((_b = this.tenantToken) === null || _b === void 0 ? void 0 : _b.length))
|
|
252
|
-
return false;
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
get decodeRefreshToken() {
|
|
256
|
-
const token = this.refreshToken;
|
|
257
|
-
return !token ? null : this.decodeToken(token);
|
|
258
|
-
}
|
|
259
|
-
throwIfNotInitialized() {
|
|
260
|
-
if (!this.isInitialized) {
|
|
261
|
-
throw new Error('LocalizeTokenService is not initialized. Call init() method before using it.');
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
LocalizeTokenService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeTokenService_Factory() { return new LocalizeTokenService(); }, token: LocalizeTokenService, providedIn: "root" });
|
|
266
|
-
LocalizeTokenService.decorators = [
|
|
267
|
-
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
|
268
|
-
];
|
|
269
|
-
|
|
270
|
-
class LocalizeLogindlgComponent {
|
|
271
|
-
constructor(messageService, cdt, dlgRef, dlgConfig, tokenService, httpClient, sanitizer) {
|
|
15
|
+
class LocalizeTokenLoginDialogComponent {
|
|
16
|
+
constructor(messageService, cdt, dlgRef, dlgConfig, sanitizer, injector) {
|
|
272
17
|
this.messageService = messageService;
|
|
273
18
|
this.cdt = cdt;
|
|
274
19
|
this.dlgRef = dlgRef;
|
|
275
20
|
this.dlgConfig = dlgConfig;
|
|
276
|
-
this.tokenService = tokenService;
|
|
277
|
-
this.httpClient = httpClient;
|
|
278
21
|
this.sanitizer = sanitizer;
|
|
22
|
+
this.injector = injector;
|
|
279
23
|
this.messageKey = "$login-dlg";
|
|
280
|
-
this.loading = false;
|
|
281
|
-
this.success = false;
|
|
282
|
-
this.clickLogout = () => { var _a; return (_a = this.logout) === null || _a === void 0 ? void 0 : _a.call(this); };
|
|
283
|
-
this.decodeToken = this.tokenService.decodeRefreshToken;
|
|
284
24
|
this.loginConfig = this.dlgConfig.data.loginConfig;
|
|
25
|
+
this.apiLoginService = this.injector.get(LocalizeApiLoginService);
|
|
285
26
|
this.properties = this.loginConfig.properties;
|
|
27
|
+
this.decodeToken = this.apiLoginService.decodedToken;
|
|
28
|
+
this.logout = this.loginConfig.logoutFunc;
|
|
29
|
+
this.configure();
|
|
286
30
|
}
|
|
287
|
-
get
|
|
288
|
-
|
|
31
|
+
get loading() { return this.apiLoginService.isLoading; }
|
|
32
|
+
get success() { return this.apiLoginService.isSuccess; }
|
|
33
|
+
configure() {
|
|
34
|
+
var _a, _b;
|
|
289
35
|
this.dlgConfig.closable = false;
|
|
290
|
-
this.
|
|
291
|
-
this.
|
|
36
|
+
this.dlgConfig.dismissableMask = false;
|
|
37
|
+
this.dlgConfig.modal = true;
|
|
38
|
+
this.apiLoginService.configure({
|
|
39
|
+
loginUrl: this.loginConfig.loginUrl,
|
|
40
|
+
onSuccess: this.loginSuccess.bind(this),
|
|
41
|
+
onFailure: (msg) => this.showMessage("error", msg),
|
|
42
|
+
onError: (msg) => this.showMessage("error", msg),
|
|
43
|
+
loginFunction: this.loginConfig.loginFunction,
|
|
44
|
+
refreshTokenTtl: this.loginConfig.expire,
|
|
45
|
+
passwordResolver: () => this.password,
|
|
46
|
+
passwordValidator: (_b = (_a = this.loginConfig.properties) === null || _a === void 0 ? void 0 : _a.passwordValidator) === null || _b === void 0 ? void 0 : _b.bind(this),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
ngOnInit() {
|
|
292
50
|
if (!this.decodeToken) {
|
|
293
|
-
this.showMessage("error", "Token
|
|
51
|
+
this.showMessage("error", "Invalid Token. Please login again.");
|
|
294
52
|
setTimeout(() => { var _a; return (_a = this.logout) === null || _a === void 0 ? void 0 : _a.call(this); }, 2000);
|
|
295
53
|
}
|
|
296
54
|
}
|
|
297
55
|
ngAfterViewInit() {
|
|
298
56
|
this.cdt.detectChanges();
|
|
299
57
|
}
|
|
300
|
-
|
|
301
|
-
var _a, _b, _c;
|
|
58
|
+
loginSuccess() {
|
|
302
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
this.loading = true;
|
|
307
|
-
const loginRes = yield this.login();
|
|
308
|
-
if (!(loginRes === null || loginRes === void 0 ? void 0 : loginRes.status)) {
|
|
309
|
-
return this.showMessage("error", (_a = loginRes.message) !== null && _a !== void 0 ? _a : "An error occurred");
|
|
310
|
-
}
|
|
311
|
-
this.tokenService.accessToken = loginRes.tokens.accessToken;
|
|
312
|
-
const cookieOptions = { expires: (_b = this.loginConfig.expire) !== null && _b !== void 0 ? _b : 365 };
|
|
313
|
-
LocalizeToken.storage.set(((_c = this.config.refreshToken) === null || _c === void 0 ? void 0 : _c.name) || '', loginRes.tokens.refreshToken, cookieOptions);
|
|
314
|
-
this.success = true;
|
|
315
|
-
setTimeout(() => {
|
|
316
|
-
this.dlgConfig.dismissableMask = true;
|
|
317
|
-
this.dlgConfig.modal = false;
|
|
318
|
-
this.dlgRef.close(true);
|
|
319
|
-
}, 2000);
|
|
60
|
+
yield waitFor(2000);
|
|
61
|
+
this.dlgRef.close(true);
|
|
320
62
|
});
|
|
321
63
|
}
|
|
322
|
-
|
|
323
|
-
var _a, _b, _c;
|
|
64
|
+
clickLogin() {
|
|
324
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
-
|
|
326
|
-
this.showMessage("error", "Login url is required");
|
|
327
|
-
throw new Error("Login url is required");
|
|
328
|
-
}
|
|
329
|
-
try {
|
|
330
|
-
if (this.loginConfig.loginFunction) {
|
|
331
|
-
console.log("Using custom login function");
|
|
332
|
-
return yield this.loginConfig.loginFunction((_c = (_b = this.decodeToken) === null || _b === void 0 ? void 0 : _b.email) !== null && _c !== void 0 ? _c : '', this.password.trim(), this.getHeaders());
|
|
333
|
-
}
|
|
334
|
-
return yield new Promise((resolve, reject) => this.httpClient.post(this.loginUrl, { password: this.password.trim() }, { headers: this.getHeaders() }).subscribe({ next: resolve, error: reject }));
|
|
335
|
-
}
|
|
336
|
-
catch (e) {
|
|
337
|
-
this.showMessage("error", e.message);
|
|
338
|
-
return null;
|
|
339
|
-
}
|
|
66
|
+
yield this.apiLoginService.clickLogin();
|
|
340
67
|
});
|
|
341
68
|
}
|
|
342
|
-
|
|
343
|
-
var _a
|
|
344
|
-
|
|
345
|
-
[LocalizeToken.httpHeaders.X_REFRESH_TOKEN]: (_a = this.tokenService.refreshToken) !== null && _a !== void 0 ? _a : "",
|
|
346
|
-
[LocalizeToken.httpHeaders.X_TENANT]: (_b = this.tokenService.tenantToken) !== null && _b !== void 0 ? _b : "",
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
get isValidPassword() {
|
|
350
|
-
this.loading = false;
|
|
351
|
-
return this.properties.passwordValidator
|
|
352
|
-
? this.properties.passwordValidator(this.password)
|
|
353
|
-
: this.password && this.password.trim().length >= 6 && this.password.trim().length <= 50;
|
|
69
|
+
clickLogout() {
|
|
70
|
+
var _a;
|
|
71
|
+
(_a = this.logout) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
354
72
|
}
|
|
355
73
|
showMessage(severity, summary) {
|
|
356
74
|
this.messageService.add({ key: this.messageKey, severity, summary });
|
|
357
|
-
this.loading = false;
|
|
358
75
|
}
|
|
359
76
|
get sanitizedTitle() {
|
|
360
77
|
var _a;
|
|
361
78
|
return this.sanitizer.bypassSecurityTrustHtml((_a = this.properties.title) !== null && _a !== void 0 ? _a : '');
|
|
362
79
|
}
|
|
80
|
+
ngOnDestroy() {
|
|
81
|
+
this.apiLoginService.unConfigure();
|
|
82
|
+
}
|
|
363
83
|
}
|
|
364
|
-
|
|
84
|
+
LocalizeTokenLoginDialogComponent.decorators = [
|
|
365
85
|
{ type: Component, args: [{
|
|
366
86
|
template: `<p-toast key="$login-dlg" position="top-center"></p-toast>
|
|
367
87
|
<div id="login-dlg-wrap">
|
|
@@ -672,17 +392,16 @@ LocalizeLogindlgComponent.decorators = [
|
|
|
672
392
|
`]
|
|
673
393
|
},] }
|
|
674
394
|
];
|
|
675
|
-
|
|
395
|
+
LocalizeTokenLoginDialogComponent.ctorParameters = () => [
|
|
676
396
|
{ type: MessageService },
|
|
677
397
|
{ type: ChangeDetectorRef },
|
|
678
398
|
{ type: DynamicDialogRef },
|
|
679
399
|
{ type: DynamicDialogConfig },
|
|
680
|
-
{ type:
|
|
681
|
-
{ type:
|
|
682
|
-
{ type: DomSanitizer }
|
|
400
|
+
{ type: DomSanitizer },
|
|
401
|
+
{ type: Injector }
|
|
683
402
|
];
|
|
684
403
|
|
|
685
|
-
class
|
|
404
|
+
class LocalizeTokenDialogService {
|
|
686
405
|
constructor(injector) {
|
|
687
406
|
this.injector = injector;
|
|
688
407
|
}
|
|
@@ -692,7 +411,7 @@ class LocalizeLogindlgService {
|
|
|
692
411
|
this.initConfig(loginConfig);
|
|
693
412
|
config.data = Object.assign(Object.assign({}, (config.data || {})), { loginConfig });
|
|
694
413
|
const dialogService = this.injector.get(DialogService);
|
|
695
|
-
const dialog = dialogService.open(
|
|
414
|
+
const dialog = dialogService.open(LocalizeTokenLoginDialogComponent, config);
|
|
696
415
|
yield new Promise((resolve) => dialog.onClose.subscribe(res => {
|
|
697
416
|
if (res) {
|
|
698
417
|
resolve();
|
|
@@ -731,619 +450,58 @@ class LocalizeLogindlgService {
|
|
|
731
450
|
});
|
|
732
451
|
}
|
|
733
452
|
}
|
|
734
|
-
|
|
735
|
-
|
|
453
|
+
LocalizeTokenDialogService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeTokenDialogService_Factory() { return new LocalizeTokenDialogService(i0.ɵɵinject(i0.INJECTOR)); }, token: LocalizeTokenDialogService, providedIn: "root" });
|
|
454
|
+
LocalizeTokenDialogService.decorators = [
|
|
736
455
|
{ type: Injectable, args: [{
|
|
737
456
|
providedIn: 'root'
|
|
738
457
|
},] }
|
|
739
458
|
];
|
|
740
|
-
|
|
459
|
+
LocalizeTokenDialogService.ctorParameters = () => [
|
|
741
460
|
{ type: Injector }
|
|
742
461
|
];
|
|
743
462
|
|
|
744
|
-
class
|
|
463
|
+
class LocalizeTokenModule {
|
|
745
464
|
}
|
|
746
|
-
|
|
465
|
+
LocalizeTokenModule.decorators = [
|
|
747
466
|
{ type: NgModule, args: [{
|
|
748
|
-
declarations: [
|
|
749
|
-
exports: [
|
|
467
|
+
declarations: [LocalizeTokenLoginDialogComponent],
|
|
468
|
+
exports: [LocalizeTokenLoginDialogComponent],
|
|
750
469
|
imports: [
|
|
751
470
|
CommonModule,
|
|
752
471
|
ToastModule,
|
|
753
472
|
InputTextModule,
|
|
754
|
-
BrowserModule,
|
|
755
473
|
FormsModule,
|
|
756
474
|
ButtonModule,
|
|
757
475
|
],
|
|
758
|
-
providers: [
|
|
476
|
+
providers: [LocalizeTokenDialogService],
|
|
759
477
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
760
478
|
},] }
|
|
761
479
|
];
|
|
762
480
|
|
|
763
|
-
|
|
764
|
-
network: {
|
|
765
|
-
noConnection: `<?xml version="1.0" encoding="UTF-8"?>
|
|
766
|
-
<svg id="lze-no-connection" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 77.29 70.98">
|
|
767
|
-
<defs>
|
|
768
|
-
<style> .cls-1 { fill: #fff; } .cls-2, .cls-3 { fill: #e30613; } .cls-3 { stroke: #e30613; stroke-miterlimit: 10; stroke-width: .25px; } </style>
|
|
769
|
-
</defs>
|
|
770
|
-
<g id="Layer_3" data-name="Layer 3">
|
|
771
|
-
<g>
|
|
772
|
-
<path class="cls-1" d="m73.29,35c-1.2,0-2.33-.53-3.09-1.46-.48-.57-11.23-13.2-31.55-13.2s-31.11,12.66-31.56,13.2c-1.4,1.71-3.92,1.95-5.63.55-1.71-1.4-1.95-3.92-.55-5.63.54-.66,13.47-16.12,37.74-16.12s37.2,15.46,37.74,16.12c1.4,1.71,1.15,4.23-.56,5.62-.71.58-1.61.9-2.53.9Z"/>
|
|
773
|
-
<path class="cls-1" d="m63.96,45.66c-1.19,0-2.32-.53-3.08-1.44-5.79-6.05-13.86-9.39-22.24-9.21-8.38-.18-16.45,3.16-22.24,9.22-1.46,1.65-3.99,1.81-5.64.35-1.57-1.39-1.8-3.77-.52-5.43,7.32-7.89,17.64-12.29,28.4-12.12,10.76-.17,21.08,4.24,28.4,12.12,1.4,1.71,1.15,4.23-.56,5.62-.71.58-1.6.9-2.53.9Z"/>
|
|
774
|
-
<path class="cls-1" d="m53.3,56.32c-1.24,0-2.41-.57-3.16-1.55-5.73-6.35-15.52-6.85-21.87-1.13-.4.36-.77.73-1.13,1.13-1.36,1.73-3.88,2.03-5.61.67-1.71-1.34-2.03-3.8-.73-5.54,8.39-9.85,23.18-11.04,33.03-2.65.95.81,1.84,1.69,2.65,2.65,1.34,1.75,1,4.26-.75,5.6-.7.53-1.55.82-2.43.82Z"/>
|
|
775
|
-
</g>
|
|
776
|
-
<path class="cls-2" d="m47.21,9.45l-4.06,41.36c-.64,5.42-8.39,5.39-9.01,0,0,0-4.06-41.36-4.06-41.36-.46-4.73,2.99-8.94,7.72-9.4,5.33-.58,9.97,4.09,9.4,9.4h0Z"/>
|
|
777
|
-
<circle class="cls-3" cx="38.64" cy="64.79" r="6.07"/>
|
|
778
|
-
</g>
|
|
779
|
-
</svg>`
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* Http method options
|
|
785
|
-
*/
|
|
786
|
-
var EMethod;
|
|
787
|
-
(function (EMethod) {
|
|
788
|
-
EMethod["POST"] = "post";
|
|
789
|
-
EMethod["GET"] = "get";
|
|
790
|
-
EMethod["PUT"] = "put";
|
|
791
|
-
EMethod["DELETE"] = "delete";
|
|
792
|
-
EMethod["PATCH"] = "patch";
|
|
793
|
-
})(EMethod || (EMethod = {}));
|
|
794
|
-
// export interface INormalizedError {
|
|
795
|
-
// error: any;
|
|
796
|
-
// code: string;
|
|
797
|
-
// message: string;
|
|
798
|
-
// details?: any;
|
|
799
|
-
// status: number;
|
|
800
|
-
// }
|
|
801
|
-
|
|
802
|
-
class LocalizeApiHelper {
|
|
803
|
-
constructor() {
|
|
804
|
-
this.defaultRetryOptions = {
|
|
805
|
-
connectionError: {
|
|
806
|
-
message: 'Connection error occurred. Please wait',
|
|
807
|
-
blockScreen: true,
|
|
808
|
-
blockScreenZIndex: 10000
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
performRetry(options) {
|
|
813
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
814
|
-
let attempts = 0;
|
|
815
|
-
let lastError;
|
|
816
|
-
let consoleCount = 0;
|
|
817
|
-
// Merge default retry options with provided options
|
|
818
|
-
options = Object.assign(Object.assign({}, this.defaultRetryOptions), options);
|
|
819
|
-
let styleElement;
|
|
820
|
-
while (attempts < options.maxRetries()) {
|
|
821
|
-
try {
|
|
822
|
-
const result = yield options.callback();
|
|
823
|
-
this.removeBlocker(styleElement);
|
|
824
|
-
return result;
|
|
825
|
-
}
|
|
826
|
-
catch (error) {
|
|
827
|
-
lastError = error;
|
|
828
|
-
if (consoleCount >= 7) {
|
|
829
|
-
console.clear();
|
|
830
|
-
consoleCount = 0;
|
|
831
|
-
}
|
|
832
|
-
if (options.retryUnless && !options.retryUnless(error))
|
|
833
|
-
throw error; // If the error should not be retried, rethrow it
|
|
834
|
-
// Handle connection error
|
|
835
|
-
styleElement = yield this.onConnectionError(options, error);
|
|
836
|
-
if (options.onError)
|
|
837
|
-
yield this.invokeHook(options.onError.bind(this, error));
|
|
838
|
-
if (attempts >= options.maxRetries() - 1)
|
|
839
|
-
throw error;
|
|
840
|
-
attempts++;
|
|
841
|
-
consoleCount++;
|
|
842
|
-
console.warn(`Attempt ${attempts} failed. Retrying...`, error);
|
|
843
|
-
yield waitFor(options.delay);
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
console.warn(`Failed after ${options.maxRetries()} attempts`);
|
|
847
|
-
throw lastError;
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
performRequestWithRetry(options, config, performRequest) {
|
|
851
|
-
var _a, _b, _c, _d;
|
|
852
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
853
|
-
const retryUnless = ((_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.retryFunction)
|
|
854
|
-
|| this.isConnectionError;
|
|
855
|
-
return yield this.performRetry({
|
|
856
|
-
connectionError: (_b = config.retryOptions) === null || _b === void 0 ? void 0 : _b.onConnectionError,
|
|
857
|
-
maxRetries: () => { var _a, _b; return (_b = (_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.maxRetries) !== null && _b !== void 0 ? _b : 1000; },
|
|
858
|
-
delay: (_d = (_c = config.retryOptions) === null || _c === void 0 ? void 0 : _c.delay) !== null && _d !== void 0 ? _d : 500,
|
|
859
|
-
callback: () => performRequest(options),
|
|
860
|
-
retryUnless: retryUnless,
|
|
861
|
-
});
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
buildUrl(baseUrl, path) {
|
|
865
|
-
const normalizedUrl = `${baseUrl.trim().replace(/\/?$/, '/')}${path.trim().replace(/^\//, '')}`;
|
|
866
|
-
return normalizedUrl.endsWith('/')
|
|
867
|
-
? normalizedUrl.slice(0, -1)
|
|
868
|
-
: normalizedUrl;
|
|
869
|
-
}
|
|
870
|
-
invokeHook(callback) {
|
|
871
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
872
|
-
if (!callback)
|
|
873
|
-
return;
|
|
874
|
-
const result = callback();
|
|
875
|
-
if (result instanceof Promise) {
|
|
876
|
-
yield result;
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
}
|
|
880
|
-
createRequest(instance, method, url, body, options, onInvalidResponseBody) {
|
|
881
|
-
const request$ = instance.client.request(method, url, Object.assign(Object.assign({}, options), { body })).pipe(takeUntil(instance.destroy$()), map((body) => extractJsonFromResponse(body, onInvalidResponseBody)), catchError((error) => {
|
|
882
|
-
// Convert to a non-observable error to handle in the promise
|
|
883
|
-
return throwError(() => error);
|
|
884
|
-
}));
|
|
885
|
-
return request$;
|
|
886
|
-
}
|
|
887
|
-
defaultRetryFunction(error) {
|
|
888
|
-
// Don't retry for other errors (like 400, 401, 403, etc.)
|
|
889
|
-
if (!this.isConnectionError(error))
|
|
890
|
-
throw error;
|
|
891
|
-
return true;
|
|
892
|
-
}
|
|
893
|
-
isConnectionError(error) {
|
|
894
|
-
const isNetworkError = error.status === 0;
|
|
895
|
-
const isServerError = error.status >= 1000 && error.status < 600;
|
|
896
|
-
return isNetworkError || isServerError;
|
|
897
|
-
}
|
|
898
|
-
onConnectionError(options, error) {
|
|
899
|
-
var _a;
|
|
900
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
901
|
-
if (!options.connectionError)
|
|
902
|
-
return;
|
|
903
|
-
let styleElement;
|
|
904
|
-
if (this.isConnectionError(error)) {
|
|
905
|
-
styleElement = this.screenBlocker(options, error, true);
|
|
906
|
-
yield this.invokeHook((_a = options.connectionError.callback) === null || _a === void 0 ? void 0 : _a.bind(this, error));
|
|
907
|
-
return styleElement;
|
|
908
|
-
}
|
|
909
|
-
else {
|
|
910
|
-
this.screenBlocker(options, error, false);
|
|
911
|
-
styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
|
|
912
|
-
}
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
screenBlocker(optons, error, add = true) {
|
|
916
|
-
var _a, _b, _c, _d, _e;
|
|
917
|
-
if (!((_a = optons.connectionError) === null || _a === void 0 ? void 0 : _a.blockScreen))
|
|
918
|
-
return;
|
|
919
|
-
const message = ((_b = optons.connectionError) === null || _b === void 0 ? void 0 : _b.message)
|
|
920
|
-
|| 'Connection error occurred. Please wait';
|
|
921
|
-
const errorMessage = ((_c = error === null || error === void 0 ? void 0 : error.error) === null || _c === void 0 ? void 0 : _c.message) || 'An error occurred';
|
|
922
|
-
const suggestinMessage = ((_d = optons.connectionError) === null || _d === void 0 ? void 0 : _d.suggestionMessage)
|
|
923
|
-
|| 'Please check your internet connection or the server status.';
|
|
924
|
-
const zIndex = ((_e = optons.connectionError) === null || _e === void 0 ? void 0 : _e.blockScreenZIndex) || 10000;
|
|
925
|
-
const body = document.body;
|
|
926
|
-
const blcokerHtml = `
|
|
927
|
-
<div class="lze-blocker">
|
|
928
|
-
${LOCALIZE_API_ASSETS.network.noConnection}
|
|
929
|
-
<div class="lze-blocker__message">
|
|
930
|
-
${message}
|
|
931
|
-
<span class="lze-blocker__dotting">
|
|
932
|
-
<span class="lze-blocker__dot"></span>
|
|
933
|
-
<span class="lze-blocker__dot"></span>
|
|
934
|
-
<span class="lze-blocker__dot"></span>
|
|
935
|
-
</span>
|
|
936
|
-
</div>
|
|
937
|
-
<div class="lze-blocker__error">${errorMessage}</div>
|
|
938
|
-
<div class="lze-blocker__error_suggestion">${suggestinMessage}</div>
|
|
939
|
-
</div>
|
|
940
|
-
`;
|
|
941
|
-
const style = `
|
|
942
|
-
div.lze-blocker {
|
|
943
|
-
position: fixed;
|
|
944
|
-
top: 0;
|
|
945
|
-
left: 0;
|
|
946
|
-
width: 100%;
|
|
947
|
-
height: 100%;
|
|
948
|
-
background: rgba(0, 0, 0, 0.85) !important;
|
|
949
|
-
z-index: ${zIndex};
|
|
950
|
-
display: flex;
|
|
951
|
-
align-items: center;
|
|
952
|
-
justify-content: center;
|
|
953
|
-
flex-direction: column;
|
|
954
|
-
color: #fff !important;
|
|
955
|
-
font-family: Arial, sans-serif;
|
|
956
|
-
text-align: center;
|
|
957
|
-
padding: 20px;
|
|
958
|
-
box-sizing: border-box;
|
|
959
|
-
overflow: hidden;
|
|
960
|
-
user-select: none;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
svg#lze-no-connection {
|
|
964
|
-
width: 75px;
|
|
965
|
-
height: 75px;
|
|
966
|
-
margin-bottom: 20px;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
div.lze-blocker__message {
|
|
970
|
-
color: #fff !important;
|
|
971
|
-
font-size: 18px !important;
|
|
972
|
-
margin-bottom: 10px;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
.lze-blocker__dotting {
|
|
976
|
-
display: inline-block;
|
|
977
|
-
vertical-align: middle;
|
|
978
|
-
}
|
|
979
|
-
span.lze-blocker__dot {
|
|
980
|
-
display: inline-block;
|
|
981
|
-
width: 7px;
|
|
982
|
-
height: 7px;
|
|
983
|
-
background-color: #ffffff !important;
|
|
984
|
-
border-radius: 50%;
|
|
985
|
-
margin-left: 3px;
|
|
986
|
-
opacity: 0.3;
|
|
987
|
-
animation: dotting 1s infinite;
|
|
988
|
-
}
|
|
989
|
-
.lze-blocker__dot:nth-child(1) {
|
|
990
|
-
animation-delay: 0s;
|
|
991
|
-
opacity: 1;
|
|
992
|
-
}
|
|
993
|
-
.lze-blocker__dot:nth-child(2) {
|
|
994
|
-
animation-delay: 0.2s;
|
|
995
|
-
}
|
|
996
|
-
.lze-blocker__dot:nth-child(3) {
|
|
997
|
-
animation-delay: 0.4s;
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
@keyframes dotting {
|
|
1001
|
-
0%, 80%, 100% { opacity: 0.3; }
|
|
1002
|
-
40% { opacity: 1; }
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
div.lze-blocker__error {
|
|
1006
|
-
color: #f00;
|
|
1007
|
-
font-size: 14px !important;
|
|
1008
|
-
margin-bottom: 10px;
|
|
1009
|
-
text-shadow: 0 0 1px #ff5f5f !important;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
div.lze-blocker__error_suggestion {
|
|
1013
|
-
color: #ccc !important;
|
|
1014
|
-
font-size: 14px !important;
|
|
1015
|
-
margin-top: 10px;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
@keyframes spin {
|
|
1019
|
-
0% { transform: rotate(0deg); }
|
|
1020
|
-
100% { transform: rotate(360deg); }
|
|
1021
|
-
}
|
|
1022
|
-
`;
|
|
1023
|
-
const styleElement = document.createElement('style');
|
|
1024
|
-
if (add) {
|
|
1025
|
-
if (!document.querySelector('.lze-blocker')) {
|
|
1026
|
-
styleElement.innerHTML = style;
|
|
1027
|
-
document.head.appendChild(styleElement);
|
|
1028
|
-
body.insertAdjacentHTML('beforeend', blcokerHtml);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
else {
|
|
1032
|
-
this.removeBlocker(styleElement);
|
|
1033
|
-
}
|
|
1034
|
-
return styleElement;
|
|
1035
|
-
}
|
|
1036
|
-
removeBlocker(styleElement) {
|
|
1037
|
-
const blocker = document.querySelector('.lze-blocker');
|
|
1038
|
-
blocker === null || blocker === void 0 ? void 0 : blocker.remove();
|
|
1039
|
-
styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
function extractJsonFromResponse(body, onError) {
|
|
1043
|
-
// If already an object, just return
|
|
1044
|
-
if (typeof body === 'object' && body !== null)
|
|
1045
|
-
return body;
|
|
1046
|
-
// If it's a string, try to extract JSON portion
|
|
1047
|
-
if (typeof body === 'string') {
|
|
1048
|
-
const firstBrace = body.indexOf('{');
|
|
1049
|
-
if (firstBrace !== -1) {
|
|
1050
|
-
const jsonString = body.substring(firstBrace);
|
|
1051
|
-
try {
|
|
1052
|
-
return JSON.parse(jsonString);
|
|
1053
|
-
}
|
|
1054
|
-
catch (e) {
|
|
1055
|
-
// If parsing fails, return original string
|
|
1056
|
-
onError === null || onError === void 0 ? void 0 : onError(body);
|
|
1057
|
-
return body;
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
return body;
|
|
1062
|
-
}
|
|
1063
|
-
const ApiHelper = new LocalizeApiHelper();
|
|
1064
|
-
|
|
1065
|
-
const SCHEMES = LocalizeToken.httpHeaders;
|
|
1066
|
-
class LocalizeApiService {
|
|
1067
|
-
constructor(httpClient, localizeTokenService) {
|
|
1068
|
-
this.httpClient = httpClient;
|
|
1069
|
-
this.localizeTokenService = localizeTokenService;
|
|
1070
|
-
this.destroy$ = new Subject();
|
|
1071
|
-
this.configSubject = new BehaviorSubject({});
|
|
1072
|
-
this.isRequestingSubject = new BehaviorSubject(false);
|
|
1073
|
-
this.isResolvingStartupSubject = new BehaviorSubject(false);
|
|
1074
|
-
this.defaultConfig = {
|
|
1075
|
-
waitEachRequest: { milliseconds: 0 },
|
|
1076
|
-
enableRequestCancellation: true,
|
|
1077
|
-
retryOptions: {
|
|
1078
|
-
maxRetries: 1000,
|
|
1079
|
-
delay: 1000,
|
|
1080
|
-
retryFunction: ApiHelper.defaultRetryFunction.bind(this),
|
|
1081
|
-
},
|
|
1082
|
-
};
|
|
1083
|
-
this.apiOptions = {
|
|
1084
|
-
method: EMethod.GET,
|
|
1085
|
-
requestBody: null,
|
|
1086
|
-
};
|
|
1087
|
-
/**
|
|
1088
|
-
* A higher-order function that returns a curried function for making API requests.
|
|
1089
|
-
*
|
|
1090
|
-
* @param baseUrl - The base URL of the API.
|
|
1091
|
-
* @returns A curried function that can be used to make API requests.
|
|
1092
|
-
*/
|
|
1093
|
-
this.func = (baseUrl) => (path, method = EMethod.GET, reqBody = null, reqHeaders) => this.request(baseUrl, path, method, reqBody, reqHeaders);
|
|
1094
|
-
}
|
|
1095
|
-
get isResolvingStartup() { return this.isResolvingStartupSubject.value; }
|
|
1096
|
-
get needTenant() { return this.localizeTokenService.config.tenantToken !== undefined; }
|
|
1097
|
-
get isRequesting() { return this.isRequestingSubject.value; }
|
|
1098
|
-
get isRevokingToken() { return this.localizeTokenService.isRevokingToken; }
|
|
1099
|
-
set isRevokingToken(value) { this.localizeTokenService.isRevokingToken = value; }
|
|
1100
|
-
get accessToken() { return this.localizeTokenService.accessToken; }
|
|
1101
|
-
set accessToken(value) { this.localizeTokenService.accessToken = value; }
|
|
1102
|
-
get refreshToken() { return this.localizeTokenService.refreshToken; }
|
|
1103
|
-
get tenantToken() { return this.localizeTokenService.tenantToken; }
|
|
1104
|
-
get thirdPartyConfig() { var _a; return (_a = this.localizeTokenService.config) === null || _a === void 0 ? void 0 : _a.thirdPartyConfig; }
|
|
1105
|
-
get config() {
|
|
1106
|
-
this.validateConfig();
|
|
1107
|
-
return this.configSubject.value;
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Initialize the API service.
|
|
1111
|
-
* @param apiConfigs - The API configurations.
|
|
1112
|
-
*/
|
|
1113
|
-
init(apiConfigs) {
|
|
1114
|
-
console.log('LocalizeApiService is initialized.');
|
|
1115
|
-
this.configSubject.next(Object.assign(Object.assign({}, this.defaultConfig), apiConfigs));
|
|
1116
|
-
}
|
|
1117
|
-
cancelPendingRequests() {
|
|
1118
|
-
this.config.enableRequestCancellation
|
|
1119
|
-
&& this.destroy$.next();
|
|
1120
|
-
}
|
|
1121
|
-
ngOnDestroy() {
|
|
1122
|
-
this.destroy$.next();
|
|
1123
|
-
this.destroy$.complete();
|
|
1124
|
-
}
|
|
1125
|
-
request(baseUrl, path, method = EMethod.GET, reqBody = null, reqHeaders) {
|
|
1126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1127
|
-
yield waitUntil(() => !this.isResolvingStartup, 500);
|
|
1128
|
-
yield ApiHelper.invokeHook(this.config.onPrepareRequest);
|
|
1129
|
-
const apiOptions = this.buildApiOptions(baseUrl, path, method, reqBody, reqHeaders);
|
|
1130
|
-
try {
|
|
1131
|
-
yield this.toWaitForPreviousRequest();
|
|
1132
|
-
return yield ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this));
|
|
1133
|
-
}
|
|
1134
|
-
catch (error) {
|
|
1135
|
-
return yield this.handleOnRequestError(error, apiOptions);
|
|
1136
|
-
}
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
handleOnRequestError(error, options) {
|
|
1140
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1141
|
-
if (error.status !== 401)
|
|
1142
|
-
throw error;
|
|
1143
|
-
yield waitUntil(() => !this.isResolvingStartup, 50);
|
|
1144
|
-
return yield ApiHelper.performRetry({
|
|
1145
|
-
maxRetries: () => 1000,
|
|
1146
|
-
delay: 10,
|
|
1147
|
-
retryUnless: (error) => error.status === 401 || ApiHelper.isConnectionError(error),
|
|
1148
|
-
callback: () => __awaiter(this, void 0, void 0, function* () {
|
|
1149
|
-
// Handle third party API unauthorized error when request
|
|
1150
|
-
this.handleThirdPartyAuthError(error, options.requestUrl);
|
|
1151
|
-
// Only handle 401 Unauthorized errors
|
|
1152
|
-
yield this.revokeToken();
|
|
1153
|
-
// Retry the request with the new access token
|
|
1154
|
-
return yield this.performRequest(options);
|
|
1155
|
-
})
|
|
1156
|
-
});
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
handleThirdPartyAuthError(error, requestUrl) {
|
|
1160
|
-
var _a, _b, _c;
|
|
1161
|
-
if (!((_a = this.thirdPartyConfig) === null || _a === void 0 ? void 0 : _a.isThirdPartyMode))
|
|
1162
|
-
return;
|
|
1163
|
-
if (error.status === 401) {
|
|
1164
|
-
if (this.thirdPartyConfig.lastUnauthorizedUrl === requestUrl) {
|
|
1165
|
-
this.thirdPartyConfig.lastUnauthorizedUrl = "";
|
|
1166
|
-
throw (_c = (_b = this.config).onException) === null || _c === void 0 ? void 0 : _c.call(_b, Object.assign(Object.assign({}, error), { status: 405, message: `Unauthorized request url ${requestUrl}. Please contact administrator.` }));
|
|
1167
|
-
}
|
|
1168
|
-
this.thirdPartyConfig.lastUnauthorizedUrl = requestUrl;
|
|
1169
|
-
}
|
|
1170
|
-
else {
|
|
1171
|
-
this.thirdPartyConfig.lastUnauthorizedUrl = "";
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
performRequest(options) {
|
|
1175
|
-
var _a;
|
|
1176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1177
|
-
// Build the request options
|
|
1178
|
-
const buildOptions = { headers: this.buildHeaderOptions(options) };
|
|
1179
|
-
// Create the request observable
|
|
1180
|
-
const request$ = ApiHelper.createRequest({
|
|
1181
|
-
client: this.httpClient,
|
|
1182
|
-
destroy$: () => this.destroy$
|
|
1183
|
-
}, options.method, options.requestUrl, options.requestBody, buildOptions, (_a = this.config.onResponseBodyInvalid) === null || _a === void 0 ? void 0 : _a.bind(this));
|
|
1184
|
-
// Set the isRequesting state to true before making the request
|
|
1185
|
-
this.isRequestingSubject.next(true);
|
|
1186
|
-
const response = yield new Promise((resolve, reject) => request$.subscribe({ next: resolve, error: reject }));
|
|
1187
|
-
// Reset the isRequesting state after the request completes
|
|
1188
|
-
this.isRequestingSubject.next(false);
|
|
1189
|
-
return response;
|
|
1190
|
-
});
|
|
1191
|
-
}
|
|
1192
|
-
revokeToken() {
|
|
1193
|
-
var _a, _b;
|
|
1194
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1195
|
-
try {
|
|
1196
|
-
if (yield this.interceptRevokeToken())
|
|
1197
|
-
return;
|
|
1198
|
-
this.isRevokingToken = true;
|
|
1199
|
-
const defaultApiOptions = Object.assign(Object.assign({}, this.buildApiOptions(((_a = this.localizeTokenService.config.refreshToken) === null || _a === void 0 ? void 0 : _a.requestUrl) || '')), { refreshToken: true });
|
|
1200
|
-
// If in third party mode need override the default API options with third party API options
|
|
1201
|
-
const thirdParyApiOptions = this.buildThirdPartyApiOption(defaultApiOptions);
|
|
1202
|
-
const apiOptions = ((_b = this.thirdPartyConfig) === null || _b === void 0 ? void 0 : _b.isThirdPartyMode) ? thirdParyApiOptions : defaultApiOptions;
|
|
1203
|
-
// const revokeToken = await this.performRequest(apiOptions);
|
|
1204
|
-
const revokeToken = yield ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this));
|
|
1205
|
-
yield this.handleOnTokenRevoked(revokeToken);
|
|
1206
|
-
}
|
|
1207
|
-
catch (error) {
|
|
1208
|
-
// Handle the error, log it
|
|
1209
|
-
yield ApiHelper.invokeHook(this.config.onAutoLogout);
|
|
1210
|
-
throw error;
|
|
1211
|
-
}
|
|
1212
|
-
finally {
|
|
1213
|
-
// Reset the revoking token state
|
|
1214
|
-
this.isRevokingToken = false;
|
|
1215
|
-
}
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
buildThirdPartyApiOption(apiOptions) {
|
|
1219
|
-
var _a, _b, _c;
|
|
1220
|
-
return Object.assign(Object.assign({}, apiOptions), { requestUrl: ((_a = this.thirdPartyConfig) === null || _a === void 0 ? void 0 : _a.refreshToken.requestUrl) || '', method: ((_b = this.thirdPartyConfig) === null || _b === void 0 ? void 0 : _b.refreshToken.method) || EMethod.GET, requestBody: ((_c = this.thirdPartyConfig) === null || _c === void 0 ? void 0 : _c.refreshToken.body) || {}, headers: Object.assign(Object.assign({}, apiOptions.headers), { [SCHEMES.X_SECRET]: `${this.localizeTokenService.clientSecret}` }) });
|
|
1221
|
-
}
|
|
1222
|
-
/** default http request options */
|
|
1223
|
-
buildHeaderOptions(options) {
|
|
1224
|
-
var _a;
|
|
1225
|
-
const headers = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (options.refreshToken && { [SCHEMES.X_REFRESH_TOKEN]: `${this.refreshToken}` })), (!options.isFormData && { [SCHEMES.CONTENT_TYPE]: 'application/json' })), { [SCHEMES.AUTHORIZATION]: `Bearer ${this.accessToken}` }), (this.needTenant && { [SCHEMES.X_TENANT]: `${this.tenantToken}` })), (((_a = this.thirdPartyConfig) === null || _a === void 0 ? void 0 : _a.isThirdPartyMode) && { [SCHEMES.X_CLIENT]: `${this.localizeTokenService.clientId}` }));
|
|
1226
|
-
return new HttpHeaders(Object.assign(Object.assign({}, headers), options.headers));
|
|
1227
|
-
}
|
|
1228
|
-
buildApiOptions(baseUrl, path = '', method = EMethod.GET, requestBody = null, headers) {
|
|
1229
|
-
const requestUrl = ApiHelper.buildUrl(baseUrl, path);
|
|
1230
|
-
const isFormData = requestBody && requestBody instanceof FormData;
|
|
1231
|
-
return Object.assign(Object.assign({}, this.apiOptions), { headers, method, requestUrl, requestBody, isFormData });
|
|
1232
|
-
}
|
|
1233
|
-
toWaitForPreviousRequest() {
|
|
1234
|
-
var _a;
|
|
1235
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1236
|
-
if (this.isRevokingToken) {
|
|
1237
|
-
yield waitUntil(() => !this.isRevokingToken);
|
|
1238
|
-
}
|
|
1239
|
-
// to wait for each request in 50ms, even if the request is not completed
|
|
1240
|
-
const waitMilliseconds = (_a = this.config.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds;
|
|
1241
|
-
if (waitMilliseconds && this.isRequesting) {
|
|
1242
|
-
// console.warn(`Request throttling: Another request is in progress. Waiting for ${waitMilliseconds}ms.`);
|
|
1243
|
-
yield waitFor(waitMilliseconds, this.isRequesting);
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
handleOnTokenRevoked(response) {
|
|
1248
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1249
|
-
if ((response === null || response === void 0 ? void 0 : response.status) || (response === null || response === void 0 ? void 0 : response.token)) {
|
|
1250
|
-
// If the response is successful, update the access token
|
|
1251
|
-
this.accessToken = response.message || response.token; // response.token for third party revoke
|
|
1252
|
-
}
|
|
1253
|
-
else {
|
|
1254
|
-
// If the response indicates an error, invoke the onRevokeUnauthorized hook
|
|
1255
|
-
console.warn('Token revocation failed, refresh token is expired.', response.message);
|
|
1256
|
-
yield ApiHelper.invokeHook(this.config.onRevokeUnauthorized);
|
|
1257
|
-
}
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
interceptRevokeToken() {
|
|
1261
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1262
|
-
if (this.isRevokingToken) {
|
|
1263
|
-
console.warn('Token is already being revoked. Waiting for the current operation to complete...');
|
|
1264
|
-
yield waitUntil(() => !this.isRevokingToken);
|
|
1265
|
-
return true;
|
|
1266
|
-
}
|
|
1267
|
-
if (!this.refreshToken) {
|
|
1268
|
-
// await ApiHelper.invokeHook(this.apiConfigs.onAutoLogout);
|
|
1269
|
-
throw new Error('Refresh token is missing. Please login again.');
|
|
1270
|
-
}
|
|
1271
|
-
return false;
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
validateConfig() {
|
|
1275
|
-
var _a, _b, _c, _d;
|
|
1276
|
-
if (this.localizeTokenService.config.requiredTenant
|
|
1277
|
-
&& !((_b = (_a = this.localizeTokenService.config.tenantToken) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.trim().length)) {
|
|
1278
|
-
throw Error('Tenant token is required but tenantTokenName is not configured');
|
|
1279
|
-
}
|
|
1280
|
-
if (!((_d = (_c = this.localizeTokenService.config.refreshToken) === null || _c === void 0 ? void 0 : _c.requestUrl) === null || _d === void 0 ? void 0 : _d.trim().length)) {
|
|
1281
|
-
throw Error('Revoke token URL is not configured - token refresh will not work');
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
LocalizeApiService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeApiService_Factory() { return new LocalizeApiService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(LocalizeTokenService)); }, token: LocalizeApiService, providedIn: "root" });
|
|
1286
|
-
LocalizeApiService.decorators = [
|
|
1287
|
-
{ type: Injectable, args: [{
|
|
1288
|
-
providedIn: 'root'
|
|
1289
|
-
},] }
|
|
1290
|
-
];
|
|
1291
|
-
LocalizeApiService.ctorParameters = () => [
|
|
1292
|
-
{ type: HttpClient },
|
|
1293
|
-
{ type: LocalizeTokenService }
|
|
1294
|
-
];
|
|
1295
|
-
|
|
1296
|
-
class LocalizeTokenModule {
|
|
1297
|
-
}
|
|
1298
|
-
LocalizeTokenModule.decorators = [
|
|
1299
|
-
{ type: NgModule, args: [{
|
|
1300
|
-
providers: [
|
|
1301
|
-
LocalizeTokenService,
|
|
1302
|
-
LocalizeApiService
|
|
1303
|
-
]
|
|
1304
|
-
},] }
|
|
1305
|
-
];
|
|
1306
|
-
|
|
1307
|
-
class LocalizeApiTokenService {
|
|
481
|
+
class LocalizeTokenConfigureService {
|
|
1308
482
|
constructor(tokenService, apiService, loginDialogService) {
|
|
1309
483
|
this.api = apiService;
|
|
1310
484
|
this.token = tokenService;
|
|
1311
485
|
this.loginDialog = loginDialogService;
|
|
1312
486
|
}
|
|
1313
487
|
initialize(tokenConfig, apiConfig) {
|
|
1314
|
-
// Initialize the
|
|
488
|
+
// Initialize the LocalizeApiTokenService with the provided token configuration
|
|
1315
489
|
this.token.init(tokenConfig);
|
|
1316
490
|
// Initialize the LocalizeApiService with the provided API configuration
|
|
1317
491
|
this.api.init(apiConfig);
|
|
1318
|
-
console.log('
|
|
492
|
+
console.log('LocalizeTokenConfigureService initialized with token and API configurations.');
|
|
1319
493
|
}
|
|
1320
494
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
495
|
+
LocalizeTokenConfigureService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeTokenConfigureService_Factory() { return new LocalizeTokenConfigureService(i0.ɵɵinject(i1.LocalizeApiTokenService), i0.ɵɵinject(i1.LocalizeApiService), i0.ɵɵinject(LocalizeTokenDialogService)); }, token: LocalizeTokenConfigureService, providedIn: "root" });
|
|
496
|
+
LocalizeTokenConfigureService.decorators = [
|
|
1323
497
|
{ type: Injectable, args: [{
|
|
1324
498
|
providedIn: 'root'
|
|
1325
499
|
},] }
|
|
1326
500
|
];
|
|
1327
|
-
|
|
1328
|
-
{ type:
|
|
501
|
+
LocalizeTokenConfigureService.ctorParameters = () => [
|
|
502
|
+
{ type: LocalizeApiTokenService },
|
|
1329
503
|
{ type: LocalizeApiService },
|
|
1330
|
-
{ type:
|
|
1331
|
-
];
|
|
1332
|
-
|
|
1333
|
-
class LocalizeApiTokenModule {
|
|
1334
|
-
}
|
|
1335
|
-
LocalizeApiTokenModule.decorators = [
|
|
1336
|
-
{ type: NgModule, args: [{
|
|
1337
|
-
declarations: [],
|
|
1338
|
-
imports: [
|
|
1339
|
-
CommonModule,
|
|
1340
|
-
LocalizeTokenModule,
|
|
1341
|
-
LocalizeLogindlgModule
|
|
1342
|
-
],
|
|
1343
|
-
providers: [
|
|
1344
|
-
LocalizeApiTokenService
|
|
1345
|
-
]
|
|
1346
|
-
},] }
|
|
504
|
+
{ type: LocalizeTokenDialogService }
|
|
1347
505
|
];
|
|
1348
506
|
|
|
1349
507
|
//#region login dialog
|
|
@@ -1352,5 +510,5 @@ LocalizeApiTokenModule.decorators = [
|
|
|
1352
510
|
* Generated bundle index. Do not edit.
|
|
1353
511
|
*/
|
|
1354
512
|
|
|
1355
|
-
export {
|
|
513
|
+
export { LocalizeTokenConfigureService, LocalizeTokenDialogService, LocalizeTokenLoginDialogComponent, LocalizeTokenModule };
|
|
1356
514
|
//# sourceMappingURL=sambath999-localize-token.js.map
|