@acorex/connectivity 20.2.0-next.2 → 20.2.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { AXP_ROOT_CONFIG_TOKEN, AXPFilterOperatorMiddlewareService, AXPRegionalService, AXPFileStorageService, AXPFileStorageStatus } from '@acorex/platform/common';
1
+ import { AXP_ROOT_CONFIG_TOKEN, AXPFilterOperatorMiddlewareService, AXPFileStorageService, AXPFileStorageStatus } from '@acorex/platform/common';
2
2
  import { AXPEntityResolver, AXPEntityStorageService } from '@acorex/platform/layout/entity';
3
3
  import * as i1 from '@angular/common/http';
4
4
  import { HttpParams, HttpClient, HttpHeaders } from '@angular/common/http';
@@ -11,10 +11,9 @@ import { AXPAuthStrategy, AXPSessionService, JwtUtil, TimeUtil, PkceUtil, AXPAut
11
11
  import { STRATEGY_CONFIG_TOKEN } from '@acorex/platform/widgets';
12
12
  import * as i1$1 from 'angular-oauth2-oidc';
13
13
  import { OAuthService, OAuthModule } from 'angular-oauth2-oidc';
14
- import { AXUSLocaleProfile, AXIRLocaleProfile } from '@acorex/core/locale';
15
- import { AXTranslationService } from '@acorex/core/translation';
16
14
  import { AXM_AUTH_CONFIG_TOKEN } from '@acorex/modules/auth';
17
15
  import { Router } from '@angular/router';
16
+ import { AXCUtilsModule, AXCExternalAuthorizationService } from '@acorex/connectivity/utils';
18
17
 
19
18
  class AXCApiEntityStorageService {
20
19
  constructor(http) {
@@ -132,260 +131,13 @@ class AXCApiEntityStorageService {
132
131
  };
133
132
  });
134
133
  }
135
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCApiEntityStorageService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
136
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCApiEntityStorageService }); }
134
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCApiEntityStorageService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
135
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCApiEntityStorageService }); }
137
136
  }
138
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCApiEntityStorageService, decorators: [{
137
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCApiEntityStorageService, decorators: [{
139
138
  type: Injectable
140
139
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
141
140
 
142
- class AXCRegionalApiService extends AXPRegionalService {
143
- constructor() {
144
- super(...arguments);
145
- this.http = inject(HttpClient);
146
- this.languageService = inject(AXTranslationService);
147
- //#region ---- API Endpoints ----
148
- this.baseUrl = '/api/regional';
149
- //#endregion
150
- //#region ---- Fallback Data ----
151
- this.fallbackCountries = [
152
- {
153
- code: 'US',
154
- title: 'United States',
155
- native: 'United States',
156
- regional: 'en',
157
- timezone: 'America/New_York'
158
- },
159
- {
160
- code: 'CA',
161
- title: 'Canada',
162
- native: 'Canada',
163
- regional: 'en',
164
- timezone: 'America/Toronto'
165
- },
166
- {
167
- code: 'GB',
168
- title: 'United Kingdom',
169
- native: 'United Kingdom',
170
- regional: 'en',
171
- timezone: 'Europe/London'
172
- }
173
- ];
174
- this.fallbackProvinces = [
175
- {
176
- code: 'CA',
177
- title: 'California',
178
- native: 'California',
179
- timezone: 'America/Los_Angeles'
180
- },
181
- {
182
- code: 'NY',
183
- title: 'New York',
184
- native: 'New York',
185
- timezone: 'America/New_York'
186
- },
187
- {
188
- code: 'ON',
189
- title: 'Ontario',
190
- native: 'Ontario',
191
- timezone: 'America/Toronto'
192
- }
193
- ];
194
- this.fallbackCities = [
195
- {
196
- code: 'NYC',
197
- title: 'New York City',
198
- native: 'New York City',
199
- timezone: 'America/New_York'
200
- },
201
- {
202
- code: 'LA',
203
- title: 'Los Angeles',
204
- native: 'Los Angeles',
205
- timezone: 'America/Los_Angeles'
206
- },
207
- {
208
- code: 'TOR',
209
- title: 'Toronto',
210
- native: 'Toronto',
211
- timezone: 'America/Toronto'
212
- }
213
- ];
214
- this.fallbackCurrencies = [
215
- {
216
- code: 'USD',
217
- title: 'United States Dollar',
218
- symbol: '$',
219
- format: '${amount}'
220
- },
221
- {
222
- code: 'CAD',
223
- title: 'Canadian Dollar',
224
- symbol: 'CA$',
225
- format: 'CA${amount}'
226
- },
227
- {
228
- code: 'GBP',
229
- title: 'British Pound',
230
- symbol: '£',
231
- format: '£{amount}'
232
- }
233
- ];
234
- this.fallbackLocaleProfiles = [
235
- {
236
- ...AXUSLocaleProfile,
237
- code: 'en-US',
238
- title: 'English (United States)',
239
- nativeTitle: 'English (United States)',
240
- },
241
- {
242
- ...AXIRLocaleProfile,
243
- code: 'fa-IR',
244
- title: 'Persian (Iran)',
245
- nativeTitle: 'فارسی (ایران)',
246
- }
247
- ];
248
- this.fallbackLanguages = [
249
- {
250
- code: 'en',
251
- title: 'English'
252
- },
253
- {
254
- code: 'fa',
255
- title: 'Persian'
256
- },
257
- {
258
- code: 'es',
259
- title: 'Spanish'
260
- }
261
- ];
262
- this.fallbackTimeZones = [
263
- {
264
- code: 'America/New_York',
265
- title: 'Eastern Time (US & Canada)',
266
- offset: '-05:00',
267
- iana: 'America/New_York',
268
- abbr: 'EST'
269
- },
270
- {
271
- code: 'America/Los_Angeles',
272
- title: 'Pacific Time (US & Canada)',
273
- offset: '-08:00',
274
- iana: 'America/Los_Angeles',
275
- abbr: 'PST'
276
- },
277
- {
278
- code: 'Europe/London',
279
- title: 'Greenwich Mean Time',
280
- offset: '+00:00',
281
- iana: 'Europe/London',
282
- abbr: 'GMT'
283
- }
284
- ];
285
- }
286
- //#endregion
287
- async getCountries() {
288
- const lang = await firstValueFrom(this.languageService.langChanges$);
289
- try {
290
- const countries = await firstValueFrom(this.http.get(`${this.baseUrl}/countries`).pipe(catchError(() => of(this.fallbackCountries))));
291
- return countries.map((country) => {
292
- if (lang == country.regional) {
293
- return {
294
- ...country,
295
- title: country.native,
296
- };
297
- }
298
- else {
299
- return country;
300
- }
301
- });
302
- }
303
- catch {
304
- return this.fallbackCountries.map((country) => {
305
- if (lang == country.regional) {
306
- return {
307
- ...country,
308
- title: country.native,
309
- };
310
- }
311
- else {
312
- return country;
313
- }
314
- });
315
- }
316
- }
317
- async getProvinces(countryId) {
318
- let params = new HttpParams();
319
- if (countryId) {
320
- params = params.set('countryId', countryId);
321
- }
322
- try {
323
- return await firstValueFrom(this.http.get(`${this.baseUrl}/provinces`, { params }).pipe(catchError(() => of(this.fallbackProvinces))));
324
- }
325
- catch {
326
- return this.fallbackProvinces;
327
- }
328
- }
329
- async getCities(filter) {
330
- let params = new HttpParams();
331
- if (filter?.countryId) {
332
- params = params.set('countryId', filter.countryId);
333
- }
334
- if (filter?.provinceId) {
335
- params = params.set('provinceId', filter.provinceId);
336
- }
337
- try {
338
- return await firstValueFrom(this.http.get(`${this.baseUrl}/cities`, { params }).pipe(catchError(() => of(this.fallbackCities))));
339
- }
340
- catch {
341
- return this.fallbackCities;
342
- }
343
- }
344
- async getCurrencies() {
345
- try {
346
- return await firstValueFrom(this.http.get(`${this.baseUrl}/currencies`).pipe(catchError(() => of(this.fallbackCurrencies))));
347
- }
348
- catch {
349
- return this.fallbackCurrencies;
350
- }
351
- }
352
- async getLocaleProfiles() {
353
- try {
354
- return await firstValueFrom(this.http.get(`${this.baseUrl}/locale-profiles`).pipe(catchError(() => of(this.fallbackLocaleProfiles))));
355
- }
356
- catch {
357
- return this.fallbackLocaleProfiles;
358
- }
359
- }
360
- async getLanguages() {
361
- try {
362
- return await firstValueFrom(this.http.get(`${this.baseUrl}/languages`).pipe(catchError(() => of(this.fallbackLanguages))));
363
- }
364
- catch {
365
- return this.fallbackLanguages;
366
- }
367
- }
368
- async getAvailableLanguages() {
369
- try {
370
- return await firstValueFrom(this.http.get(`${this.baseUrl}/available-languages`).pipe(catchError(() => of(this.fallbackLanguages))));
371
- }
372
- catch {
373
- return this.fallbackLanguages;
374
- }
375
- }
376
- async getBrowserTimeZoneCode() {
377
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
378
- }
379
- async getTimeZones() {
380
- try {
381
- return await firstValueFrom(this.http.get(`${this.baseUrl}/timezones`).pipe(catchError(() => of(this.fallbackTimeZones))));
382
- }
383
- catch {
384
- return this.fallbackTimeZones;
385
- }
386
- }
387
- }
388
-
389
141
  class AXCFileStorageApiService extends AXPFileStorageService {
390
142
  constructor() {
391
143
  super(...arguments);
@@ -518,10 +270,10 @@ class AXCFileStorageApiService extends AXPFileStorageService {
518
270
  // Silently fail in fallback mode
519
271
  }
520
272
  }
521
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCFileStorageApiService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
522
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCFileStorageApiService }); }
273
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCFileStorageApiService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
274
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCFileStorageApiService }); }
523
275
  }
524
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCFileStorageApiService, decorators: [{
276
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCFileStorageApiService, decorators: [{
525
277
  type: Injectable
526
278
  }] });
527
279
 
@@ -566,10 +318,10 @@ class AXMOidcApplicationLoader {
566
318
  // features: item.features || [],
567
319
  };
568
320
  }
569
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcApplicationLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
570
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcApplicationLoader }); }
321
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcApplicationLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
322
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcApplicationLoader }); }
571
323
  }
572
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcApplicationLoader, decorators: [{
324
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcApplicationLoader, decorators: [{
573
325
  type: Injectable
574
326
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
575
327
 
@@ -609,10 +361,10 @@ class AXMConfigurationService {
609
361
  switchMap(() => of(this.applicationConfig)));
610
362
  }
611
363
  }
612
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMConfigurationService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
613
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMConfigurationService, providedIn: 'root' }); }
364
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMConfigurationService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
365
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMConfigurationService, providedIn: 'root' }); }
614
366
  }
615
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMConfigurationService, decorators: [{
367
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMConfigurationService, decorators: [{
616
368
  type: Injectable,
617
369
  args: [{
618
370
  providedIn: 'root',
@@ -652,13 +404,11 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
652
404
  async configureOAuth() {
653
405
  if (this.openidConfigurationInfo)
654
406
  return;
655
- if (!this.authConfig) {
656
- if (!this.aXMAuthConfigs.authConfig) {
657
- throw new Error('authConfig is missing');
658
- }
659
- this.authConfig = this.aXMAuthConfigs.authConfig;
407
+ // Validation: اطمینان از وجود authConfig
408
+ if (!this.aXMAuthConfigs.authConfig) {
409
+ throw new Error('authConfig is missing. Please check your environment configuration.');
660
410
  }
661
- this.oauthService.configure(this.authConfig);
411
+ this.oauthService.configure(this.aXMAuthConfigs.authConfig);
662
412
  this.oauthService.setStorage(localStorage);
663
413
  this.openidConfigurationInfo = await this.oauthService.loadDiscoveryDocument();
664
414
  if (!this.openidConfigurationInfo) {
@@ -699,7 +449,13 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
699
449
  }
700
450
  async handleOidcPasswordSignin(credentials) {
701
451
  await this.configureOAuth();
702
- const loginRes = await fetch(this.authConfig.issuer + '/api/auth/manual-login', {
452
+ // Validation: اطمینان از وجود baseUrl
453
+ if (!this.aXMAuthConfigs.baseUrl) {
454
+ throw new Error('baseUrl is missing. Please check your environment configuration.');
455
+ }
456
+ // استفاده از baseUrl از configuration
457
+ const baseUrl = this.aXMAuthConfigs.baseUrl;
458
+ const loginRes = await fetch(baseUrl + '/auth/manual-login', {
703
459
  method: 'POST',
704
460
  headers: { 'Content-Type': 'application/json' },
705
461
  body: JSON.stringify({ username: credentials.username, password: credentials.password }),
@@ -743,12 +499,16 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
743
499
  if (!this.openidConfigurationInfo) {
744
500
  await this.configureOAuth();
745
501
  }
502
+ // Validation: اطمینان از وجود authConfig
503
+ if (!this.aXMAuthConfigs.authConfig) {
504
+ throw new Error('authConfig is missing. Please check your environment configuration.');
505
+ }
746
506
  // get Token Code
747
507
  if (params['code']) {
748
508
  // If params contains 'code', exchange it for tokens using the OpenIddict token endpoint
749
509
  const code = params['code'];
750
- const redirectUri = params['redirectUri'] || this.authConfig.redirectUri;
751
- const clientId = params['clientId'] || this.authConfig.clientId;
510
+ const redirectUri = params['redirectUri'] || this.aXMAuthConfigs.authConfig.redirectUri;
511
+ const clientId = params['clientId'] || this.aXMAuthConfigs.authConfig.clientId;
752
512
  const tokenEndpoint = params['tokenEndpoint'] ||
753
513
  this.openidConfigurationInfo?.info?.discoveryDocument?.token_endpoint ||
754
514
  `${this.aXMAuthConfigs?.authConfig?.issuer}/connect/token`;
@@ -819,23 +579,25 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
819
579
  }
820
580
  // get Authorizeation Code
821
581
  else {
582
+ // Validation: اطمینان از وجود authConfig
583
+ if (!this.aXMAuthConfigs.authConfig) {
584
+ throw new Error('authConfig is missing. Please check your environment configuration.');
585
+ }
822
586
  // Extract parameters
823
587
  // Support both direct id fields and nested tenant/application objects
824
588
  const tenantId = params['tenantId'] ?? params['tenant']?.id ?? null;
825
589
  const applicationId = params['applicationId'] ?? params['application']?.id ?? null;
826
- const redirectUri = params['redirectUri'] || this.authConfig.redirectUri;
827
- const scope = params['scope'] || this.authConfig.scope;
590
+ const redirectUri = params['redirectUri'] || this.aXMAuthConfigs.authConfig.redirectUri;
591
+ const scope = params['scope'] || this.aXMAuthConfigs.authConfig.scope;
828
592
  // Generate PKCE code verifier and challenge
829
593
  const codeVerifier = PkceUtil.generateRandomString(128);
830
594
  localStorage.setItem('pkce_code_verifier', codeVerifier);
831
595
  const codeChallenge = await PkceUtil.generateCodeChallenge(codeVerifier);
832
596
  // Build authorization URL
833
597
  const authorizeEndpoint = this.openidConfigurationInfo.info.discoveryDocument.authorization_endpoint;
834
- const clientId = this.authConfig.clientId;
598
+ const clientId = this.aXMAuthConfigs.authConfig.clientId;
835
599
  const responseType = 'code';
836
600
  const state = Math.random().toString(36).substring(2);
837
- // const authorizeUrl = `${authorizeEndpoint}?response_type=${encodeURIComponent(responseType)}&client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scope)}&state=${encodeURIComponent(state)}&tenant_id=${encodeURIComponent(tenantId)}&application_id=${encodeURIComponent(applicationId)}&code_challenge=${encodeURIComponent(codeChallenge)}&code_challenge_method=S256`;
838
- // Build query params dynamically, only add tenant_id and application_id if they have values
839
601
  const queryParams = [
840
602
  `response_type=${encodeURIComponent(responseType)}`,
841
603
  `client_id=${encodeURIComponent(clientId)}`,
@@ -850,7 +612,6 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
850
612
  .filter(Boolean)
851
613
  .join('&');
852
614
  const authorizeUrl = `${authorizeEndpoint}?${queryParams}`;
853
- // Step 1: Redirect to authorization endpoint
854
615
  window.location.href = authorizeUrl;
855
616
  }
856
617
  }
@@ -859,19 +620,16 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
859
620
  }
860
621
  }
861
622
  async signout() {
862
- debugger;
863
623
  localStorage.removeItem('pkce_code_verifier');
864
624
  localStorage.removeItem('oauth_provider');
865
- debugger;
866
625
  console.log(this.openidConfigurationInfo?.info?.discoveryDocument);
867
626
  const logoutUrl = `${this.aXMAuthConfigs?.authConfig?.issuer}/connect/logout`;
868
- // Use GET instead of POST to avoid Content-Type header issues
869
- await firstValueFrom(this.http.get(logoutUrl, { withCredentials: true }));
627
+ window.location.href = logoutUrl;
870
628
  }
871
629
  async refreshToken(context) {
872
630
  try {
873
631
  await this.configureOAuth();
874
- if (!this.authConfig || !this.authConfig.clientId) {
632
+ if (!this.aXMAuthConfigs.authConfig || !this.aXMAuthConfigs.authConfig.clientId) {
875
633
  throw new Error('authConfig or clientId is missing');
876
634
  }
877
635
  const authData = this.loadAuthData();
@@ -884,7 +642,7 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
884
642
  }
885
643
  const body = new HttpParams()
886
644
  .set('grant_type', 'refresh_token')
887
- .set('client_id', this.authConfig.clientId)
645
+ .set('client_id', this.aXMAuthConfigs.authConfig.clientId)
888
646
  .set('refresh_token', refreshToken);
889
647
  const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
890
648
  const response = await firstValueFrom(this.http.post(this.openidConfigurationInfo.info.discoveryDocument.token_endpoint, body.toString(), { headers }));
@@ -949,10 +707,10 @@ class AXCAPIOidcStrategy extends AXPAuthStrategy {
949
707
  get name() {
950
708
  return 'oidc';
951
709
  }
952
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCAPIOidcStrategy, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
953
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCAPIOidcStrategy }); }
710
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCAPIOidcStrategy, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
711
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCAPIOidcStrategy }); }
954
712
  }
955
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCAPIOidcStrategy, decorators: [{
713
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCAPIOidcStrategy, decorators: [{
956
714
  type: Injectable
957
715
  }] });
958
716
 
@@ -977,10 +735,10 @@ class AXMOidcPermissionLoader {
977
735
  const truePolicies = Object.keys(policies).filter((key) => policies[key] === true);
978
736
  return truePolicies;
979
737
  }
980
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcPermissionLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
981
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcPermissionLoader }); }
738
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcPermissionLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
739
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcPermissionLoader }); }
982
740
  }
983
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcPermissionLoader, decorators: [{
741
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcPermissionLoader, decorators: [{
984
742
  type: Injectable
985
743
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
986
744
 
@@ -1006,25 +764,21 @@ class AXMOidcTenantLoader {
1006
764
  // Add other fields and defaults as needed, and handle the logo if applicable
1007
765
  };
1008
766
  }
1009
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcTenantLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
1010
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcTenantLoader }); }
767
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcTenantLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
768
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcTenantLoader }); }
1011
769
  }
1012
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXMOidcTenantLoader, decorators: [{
770
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXMOidcTenantLoader, decorators: [{
1013
771
  type: Injectable
1014
772
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
1015
773
 
1016
774
  class AXCApiModule {
1017
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCApiModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1018
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.3", ngImport: i0, type: AXCApiModule, imports: [i1$1.OAuthModule, i2.AXPAuthModule] }); }
1019
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCApiModule, providers: [
775
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCApiModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
776
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.4", ngImport: i0, type: AXCApiModule, imports: [i1$1.OAuthModule, i2.AXPAuthModule, AXCUtilsModule] }); }
777
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCApiModule, providers: [
1020
778
  {
1021
779
  provide: AXPEntityStorageService,
1022
780
  useClass: AXCApiEntityStorageService,
1023
781
  },
1024
- {
1025
- provide: AXPRegionalService,
1026
- useClass: AXCRegionalApiService,
1027
- },
1028
782
  {
1029
783
  provide: AXPFileStorageService,
1030
784
  useClass: AXCFileStorageApiService,
@@ -1055,9 +809,10 @@ class AXCApiModule {
1055
809
  ], imports: [OAuthModule.forRoot(),
1056
810
  AXPAuthModule.forRoot({
1057
811
  strategies: [AXCAPIOidcStrategy],
1058
- })] }); }
812
+ }),
813
+ AXCUtilsModule] }); }
1059
814
  }
1060
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AXCApiModule, decorators: [{
815
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AXCApiModule, decorators: [{
1061
816
  type: NgModule,
1062
817
  args: [{
1063
818
  imports: [
@@ -1065,16 +820,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImpor
1065
820
  AXPAuthModule.forRoot({
1066
821
  strategies: [AXCAPIOidcStrategy],
1067
822
  }),
823
+ AXCUtilsModule,
1068
824
  ],
1069
825
  providers: [
1070
826
  {
1071
827
  provide: AXPEntityStorageService,
1072
828
  useClass: AXCApiEntityStorageService,
1073
829
  },
1074
- {
1075
- provide: AXPRegionalService,
1076
- useClass: AXCRegionalApiService,
1077
- },
1078
830
  {
1079
831
  provide: AXPFileStorageService,
1080
832
  useClass: AXCFileStorageApiService,
@@ -1106,9 +858,280 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImpor
1106
858
  }]
1107
859
  }] });
1108
860
 
861
+ //#region ---- Class Definition ----
862
+ class APIGoogleStrategy extends AXPAuthStrategy {
863
+ constructor() {
864
+ super();
865
+ this.aXMAuthConfigs = inject(AXM_AUTH_CONFIG_TOKEN);
866
+ this.oauthService = inject(OAuthService);
867
+ this.http = inject(HttpClient);
868
+ this.sessionService = inject(AXPSessionService);
869
+ this.router = inject(Router);
870
+ this.externalAuthorizationService = inject(AXCExternalAuthorizationService);
871
+ this.tenantLoader = inject(AXP_TENANT_LOADER);
872
+ this.applicationLoader = inject(AXP_APPLICATION_LOADER);
873
+ }
874
+ get name() {
875
+ return 'google';
876
+ }
877
+ async configureOAuth() {
878
+ if (this.openidConfigurationInfo)
879
+ return;
880
+ if (!this.authConfig) {
881
+ if (!this.aXMAuthConfigs.authConfig) {
882
+ throw new Error('authConfig is missing');
883
+ }
884
+ this.authConfig = this.aXMAuthConfigs.authConfig;
885
+ }
886
+ this.oauthService.configure(this.authConfig);
887
+ this.oauthService.setStorage(localStorage);
888
+ this.openidConfigurationInfo = await this.oauthService.loadDiscoveryDocument();
889
+ if (!this.openidConfigurationInfo) {
890
+ throw new Error('openidConfigurationInfo is missing');
891
+ }
892
+ this.oauthService.events.subscribe(async (event) => {
893
+ // console.log('event', event);
894
+ // if (event.type === 'token_received') {
895
+ // console.log('Token has been refreshed');
896
+ // }
897
+ // if (event.type === 'token_expires') {
898
+ // console.log('Token is about to expire. Triggering silent refresh...');
899
+ // }
900
+ });
901
+ const oidcJson = localStorage.getItem(AXPSessionService.SESSION_KEY);
902
+ if (oidcJson) {
903
+ const authData = JSON.parse(oidcJson);
904
+ if (authData) {
905
+ this.sessionService.setSession(authData);
906
+ if (authData.expiresIn && new Date(authData.expiresIn) < new Date()) {
907
+ if (authData.expiresIn) {
908
+ this.sessionService.refreshToken();
909
+ }
910
+ else {
911
+ this.signout();
912
+ }
913
+ }
914
+ }
915
+ }
916
+ }
917
+ async signin(credentials) {
918
+ const providerName = credentials['strategy'];
919
+ await this.externalAuthorizationService.signin(providerName);
920
+ }
921
+ async signout() {
922
+ localStorage.removeItem('pkce_code_verifier');
923
+ localStorage.removeItem('oauth_provider');
924
+ console.log('User signed out');
925
+ }
926
+ async refreshToken(context) {
927
+ try {
928
+ await this.configureOAuth();
929
+ if (!this.authConfig || !this.authConfig.clientId) {
930
+ throw new Error('authConfig or clientId is missing');
931
+ }
932
+ const authData = this.loadAuthData();
933
+ if (!authData) {
934
+ return { succeed: false };
935
+ }
936
+ const refreshToken = authData.refreshToken;
937
+ if (!refreshToken) {
938
+ return { succeed: false };
939
+ }
940
+ const body = new URLSearchParams({
941
+ grant_type: 'refresh_token',
942
+ client_id: this.authConfig.clientId,
943
+ refresh_token: refreshToken,
944
+ });
945
+ const response = await fetch(this.openidConfigurationInfo.info.discoveryDocument.token_endpoint, {
946
+ method: 'POST',
947
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
948
+ body: body.toString(),
949
+ });
950
+ if (!response.ok) {
951
+ throw new Error(`Token refresh failed: ${response.status} ${response.statusText}`);
952
+ }
953
+ const tokenData = await response.json();
954
+ // Extract user information from the refreshed token
955
+ const payload = JwtUtil.parseJwt(tokenData.id_token);
956
+ const user = {
957
+ id: payload['sub'] || '',
958
+ title: payload['name'] || payload['email'] || '',
959
+ name: payload['name'] || payload['email'] || '',
960
+ avatar: payload['picture'] || '',
961
+ };
962
+ const tenant = payload['tenantid'] || payload['tenant']
963
+ ? {
964
+ id: payload['tenantid'] || payload['tenant'] || '',
965
+ name: payload['tenantname'] || '',
966
+ title: payload['tenanttitle'] || '',
967
+ }
968
+ : undefined;
969
+ const application = payload['applicationid'] || payload['application']
970
+ ? {
971
+ id: payload['applicationid'] || payload['application'] || '',
972
+ name: payload['applicationname'] || '',
973
+ title: payload['applicationtitle'] || '',
974
+ }
975
+ : undefined;
976
+ const sessionData = {
977
+ accessToken: tokenData.access_token,
978
+ refreshToken: tokenData.refresh_token,
979
+ idToken: tokenData.id_token,
980
+ strategy: 'google',
981
+ expiresIn: TimeUtil.calculateExpireInDate(tokenData.expires_in || 0),
982
+ user,
983
+ tenant,
984
+ application,
985
+ };
986
+ return {
987
+ succeed: true,
988
+ data: {
989
+ ...sessionData,
990
+ user: sessionData.user,
991
+ },
992
+ };
993
+ }
994
+ catch (error) {
995
+ console.error('Error refreshing token', error);
996
+ return { succeed: false };
997
+ }
998
+ }
999
+ async updateToken(params) {
1000
+ try {
1001
+ // Ensure OAuth is configured first
1002
+ if (!this.openidConfigurationInfo) {
1003
+ await this.configureOAuth();
1004
+ }
1005
+ // If params contains 'code', exchange it for tokens
1006
+ if (params['code']) {
1007
+ const code = params['code'];
1008
+ const redirectUri = params['redirectUri'] || this.authConfig.redirectUri;
1009
+ const clientId = params['clientId'] || this.authConfig.clientId;
1010
+ const tokenEndpoint = this.openidConfigurationInfo.info.discoveryDocument.token_endpoint;
1011
+ // Get code_verifier from localStorage (PKCE)
1012
+ const codeVerifier = localStorage.getItem('pkce_code_verifier');
1013
+ localStorage.removeItem('pkce_code_verifier');
1014
+ if (!codeVerifier) {
1015
+ throw new Error('Code verifier not found. Please try signing in again.');
1016
+ }
1017
+ // Prepare body for token request
1018
+ const body = new URLSearchParams({
1019
+ grant_type: 'authorization_code',
1020
+ client_id: clientId,
1021
+ code_verifier: codeVerifier,
1022
+ code: code,
1023
+ redirect_uri: redirectUri,
1024
+ });
1025
+ // Call the token endpoint
1026
+ const response = await fetch(tokenEndpoint, {
1027
+ method: 'POST',
1028
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1029
+ body: body.toString(),
1030
+ });
1031
+ if (!response.ok) {
1032
+ throw new Error(`Token exchange failed: ${response.status} ${response.statusText}`);
1033
+ }
1034
+ const tokenData = await response.json();
1035
+ if (!tokenData) {
1036
+ throw new Error('Token data not found');
1037
+ }
1038
+ // Parse the ID token to extract user information
1039
+ const payload = JwtUtil.parseJwt(tokenData.id_token);
1040
+ if (!payload) {
1041
+ throw new Error('Payload not found');
1042
+ }
1043
+ const user = {
1044
+ id: payload['sub'] || '',
1045
+ title: payload['name'] || payload['email'] || '',
1046
+ name: payload['name'] || payload['email'] || '',
1047
+ avatar: payload['picture'] || '',
1048
+ };
1049
+ const tenant = payload['tenantid'] || payload['tenant']
1050
+ ? {
1051
+ id: payload['tenantid'] || payload['tenant'] || '',
1052
+ name: payload['tenantname'] || '',
1053
+ title: payload['tenanttitle'] || '',
1054
+ }
1055
+ : undefined;
1056
+ const application = payload['applicationid'] || payload['application']
1057
+ ? {
1058
+ id: payload['applicationid'] || payload['application'] || '',
1059
+ name: payload['applicationname'] || '',
1060
+ title: payload['applicationtitle'] || '',
1061
+ }
1062
+ : undefined;
1063
+ return {
1064
+ succeed: true,
1065
+ data: {
1066
+ accessToken: tokenData.access_token,
1067
+ refreshToken: tokenData.refresh_token,
1068
+ idToken: tokenData.id_token,
1069
+ expiresIn: TimeUtil.calculateExpireInDate(tokenData.expires_in || 0),
1070
+ user,
1071
+ tenant,
1072
+ application,
1073
+ },
1074
+ };
1075
+ }
1076
+ // get Authorizeation Code
1077
+ else {
1078
+ // Extract parameters
1079
+ // Support both direct id fields and nested tenant/application objects
1080
+ const tenantId = params['tenantId'] ?? params['tenant']?.id ?? null;
1081
+ const applicationId = params['applicationId'] ?? params['application']?.id ?? null;
1082
+ const redirectUri = params['redirectUri'] || this.authConfig.redirectUri;
1083
+ const scope = params['scope'] || this.authConfig.scope;
1084
+ // Generate PKCE code verifier and challenge
1085
+ const codeVerifier = PkceUtil.generateRandomString(128);
1086
+ localStorage.setItem('pkce_code_verifier', codeVerifier);
1087
+ const codeChallenge = await PkceUtil.generateCodeChallenge(codeVerifier);
1088
+ // Build authorization URL
1089
+ const authorizeEndpoint = this.openidConfigurationInfo.info.discoveryDocument.authorization_endpoint;
1090
+ const clientId = this.authConfig.clientId;
1091
+ const responseType = 'code';
1092
+ const state = Math.random().toString(36).substring(2);
1093
+ const queryParams = [
1094
+ `response_type=${encodeURIComponent(responseType)}`,
1095
+ `client_id=${encodeURIComponent(clientId)}`,
1096
+ `redirect_uri=${encodeURIComponent(redirectUri)}`,
1097
+ `scope=${encodeURIComponent(scope)}`,
1098
+ `state=${encodeURIComponent(state)}`,
1099
+ tenantId ? `tenant_id=${encodeURIComponent(tenantId)}` : null,
1100
+ applicationId ? `application_id=${encodeURIComponent(applicationId)}` : null,
1101
+ `code_challenge=${encodeURIComponent(codeChallenge)}`,
1102
+ `code_challenge_method=S256`,
1103
+ ]
1104
+ .filter(Boolean)
1105
+ .join('&');
1106
+ const authorizeUrl = `${authorizeEndpoint}?${queryParams}`;
1107
+ window.location.href = authorizeUrl;
1108
+ await new Promise(() => { });
1109
+ return;
1110
+ }
1111
+ }
1112
+ catch (error) {
1113
+ console.error('Error in updateToken:', error);
1114
+ throw error;
1115
+ }
1116
+ }
1117
+ loadAuthData() {
1118
+ const sessionData = this.sessionService.getSessionData();
1119
+ return sessionData || undefined;
1120
+ }
1121
+ handleError(error) {
1122
+ console.error('Authentication error:', error);
1123
+ throw error;
1124
+ }
1125
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: APIGoogleStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1126
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: APIGoogleStrategy }); }
1127
+ }
1128
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: APIGoogleStrategy, decorators: [{
1129
+ type: Injectable
1130
+ }], ctorParameters: () => [] });
1131
+
1109
1132
  /**
1110
1133
  * Generated bundle index. Do not edit.
1111
1134
  */
1112
1135
 
1113
- export { AXCAPIOidcStrategy, AXCApiEntityStorageService, AXCApiModule, AXMConfigurationService, AXMOidcApplicationLoader, AXMOidcFeatureLoader, AXMOidcPermissionLoader, AXMOidcTenantLoader };
1136
+ export { APIGoogleStrategy, AXCAPIOidcStrategy, AXCApiEntityStorageService, AXCApiModule, AXMConfigurationService, AXMOidcApplicationLoader, AXMOidcFeatureLoader, AXMOidcPermissionLoader, AXMOidcTenantLoader };
1114
1137
  //# sourceMappingURL=acorex-connectivity-api.mjs.map