Skip to content

Commit 5eb64c0

Browse files
committed
feat: add RestSdkAngularService and RestSdkService
1 parent 3d59381 commit 5eb64c0

File tree

26 files changed

+600
-488
lines changed

26 files changed

+600
-488
lines changed

.github/workflows/kubernetes.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ jobs:
2525
if: ${{ !contains(github.event.head_commit.message, '[skip release]') }}
2626
- run: echo '' > .env && npm run generate -- --verbose
2727
if: ${{ !contains(github.event.head_commit.message, '[skip release]') }}
28-
- run: npm run nx -- run-many --target=semantic-release -p server client --parallel=1 --excludeTaskDependencies=true
28+
- run: npm run nx -- run-many --target=semantic-release -p server client rest-sdk rest-sdk-angular --parallel=1 --excludeTaskDependencies=true
2929
if: ${{ !contains(github.event.head_commit.message, '[skip release]') }}
3030
env:
3131
GITHUB_TOKEN: ${{ secrets.NESTJS_MOD_ACCESS_TOKEN_DOCKER }}
32+
NPM_TOKEN: ${{ secrets.NESTJS_MOD_ACCESS_TOKEN_DOCKER }}
3233
- name: Set root_version
3334
id: root_version
3435
run: |

apps/client/src/app/app-initializer.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import { HttpHeaders } from '@angular/common/http';
21
import { Injectable } from '@angular/core';
3-
import { ActivatedRoute } from '@angular/router';
42
import { TranslocoService } from '@jsverse/transloco';
5-
import {
6-
FilesRestService,
7-
SsoRestService,
8-
TimeRestService,
9-
WebhookRestService,
10-
} from '@nestjs-mod-sso/rest-sdk-angular';
3+
import { RestSdkAngularService } from '@nestjs-mod-sso/rest-sdk-angular';
114
import {
125
SsoActiveLangService,
136
SsoActiveProjectService,
@@ -21,16 +14,12 @@ export class AppInitializer {
2114
private subscribeToTokenUpdatesSubscription?: Subscription;
2215

2316
constructor(
24-
private readonly webhookRestService: WebhookRestService,
25-
private readonly timeRestService: TimeRestService,
2617
private readonly ssoService: SsoService,
27-
private readonly filesRestService: FilesRestService,
28-
private readonly ssoRestService: SsoRestService,
2918
private readonly translocoService: TranslocoService,
3019
private readonly tokensService: TokensService,
3120
private readonly ssoActiveLangService: SsoActiveLangService,
3221
private readonly ssoActiveProjectService: SsoActiveProjectService,
33-
private readonly activatedRoute: ActivatedRoute
22+
private readonly restSdkAngularService: RestSdkAngularService
3423
) {}
3524

3625
resolve() {
@@ -63,18 +52,7 @@ export class AppInitializer {
6352
private updateHeaders() {
6453
const authorizationHeaders = this.ssoService.getAuthorizationHeaders();
6554
if (authorizationHeaders) {
66-
this.webhookRestService.defaultHeaders = new HttpHeaders(
67-
authorizationHeaders
68-
);
69-
this.filesRestService.defaultHeaders = new HttpHeaders(
70-
authorizationHeaders
71-
);
72-
this.timeRestService.defaultHeaders = new HttpHeaders(
73-
authorizationHeaders
74-
);
75-
this.ssoRestService.defaultHeaders = new HttpHeaders(
76-
authorizationHeaders
77-
);
55+
this.restSdkAngularService.updateHeaders(authorizationHeaders);
7856
}
7957
}
8058
}

apps/client/src/app/app.component.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ import {
88
TranslocoService,
99
} from '@jsverse/transloco';
1010
import { TranslocoDatePipe } from '@jsverse/transloco-locale';
11+
import { BROWSER_TIMEZONE_OFFSET } from '@nestjs-mod-sso/common-angular';
1112
import {
1213
SsoRoleInterface,
1314
TimeRestService,
1415
} from '@nestjs-mod-sso/rest-sdk-angular';
15-
import {
16-
BROWSER_TIMEZONE_OFFSET,
17-
webSocket,
18-
} from '@nestjs-mod-sso/common-angular';
1916
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
2017
import { addHours } from 'date-fns';
2118
import { NzIconModule } from 'ng-zorro-antd/icon';
2219
import { NzLayoutModule } from 'ng-zorro-antd/layout';
2320

2421
import { Title } from '@angular/platform-browser';
22+
import { FilesService } from '@nestjs-mod-sso/files-angular';
2523
import {
2624
CheckUserRolesPipe,
2725
SsoActiveLangService,
@@ -31,6 +29,7 @@ import {
3129
TokensService,
3230
UserPipe,
3331
} from '@nestjs-mod-sso/sso-angular';
32+
import { NzAvatarModule } from 'ng-zorro-antd/avatar';
3433
import { NzMenuModule } from 'ng-zorro-antd/menu';
3534
import { NzTypographyModule } from 'ng-zorro-antd/typography';
3635
import {
@@ -43,9 +42,8 @@ import {
4342
tap,
4443
} from 'rxjs';
4544
import { APP_TITLE } from './app.constants';
46-
import { NzAvatarModule } from 'ng-zorro-antd/avatar';
47-
import { FilesService } from '@nestjs-mod-sso/files-angular';
4845

46+
import { RestSdkAngularService } from '@nestjs-mod-sso/rest-sdk-angular';
4947
@UntilDestroy()
5048
@Component({
5149
imports: [
@@ -79,7 +77,7 @@ export class AppComponent implements OnInit {
7977
activePublicProject$?: Observable<SsoProjectModel | undefined>;
8078

8179
constructor(
82-
private readonly timeRestService: TimeRestService,
80+
private readonly restSdkAngularService: RestSdkAngularService,
8381
private readonly ssoService: SsoService,
8482
private readonly router: Router,
8583
private readonly translocoService: TranslocoService,
@@ -176,17 +174,15 @@ export class AppComponent implements OnInit {
176174

177175
private fillServerTime() {
178176
return merge(
179-
this.timeRestService.timeControllerTime(),
177+
this.restSdkAngularService.getTimeApi().timeControllerTime(),
180178
this.tokensService
181179
.getStream()
182180
.pipe(
183181
switchMap((token) =>
184-
webSocket<string>({
185-
address:
186-
this.timeRestService.configuration.basePath +
187-
(token?.access_token
188-
? `/ws/time?token=${token?.access_token}`
189-
: '/ws/time'),
182+
this.restSdkAngularService.webSocket<string>({
183+
path: token?.access_token
184+
? `/ws/time?token=${token?.access_token}`
185+
: '/ws/time',
190186
eventName: 'ChangeTimeStream',
191187
})
192188
)

apps/client/src/app/integrations/sso.configuration.ts

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Provider } from '@angular/core';
22
import { TranslocoService } from '@jsverse/transloco';
3+
import { FilesService } from '@nestjs-mod-sso/files-angular';
34
import {
4-
SsoRestService,
5+
RestSdkAngularService,
56
SsoUserDtoInterface,
67
TokensResponseInterface,
78
} from '@nestjs-mod-sso/rest-sdk-angular';
8-
import { FilesService } from '@nestjs-mod-sso/files-angular';
99
import {
1010
FingerprintService,
1111
OAuthProvider,
@@ -28,16 +28,14 @@ import { catchError, map, mergeMap, Observable, of } from 'rxjs';
2828

2929
export class SsoIntegrationConfiguration implements SsoConfiguration {
3030
constructor(
31-
private readonly ssoRestService: SsoRestService,
31+
private readonly restSdkAngularService: RestSdkAngularService,
3232
private readonly filesService: FilesService,
3333
private readonly translocoService: TranslocoService,
3434
private readonly tokensService: TokensService,
3535
private readonly ssoActiveProjectService: SsoActiveProjectService,
3636
private readonly fingerprintService: FingerprintService,
3737
private readonly nzMessageService: NzMessageService
38-
) {
39-
ssoRestService.configuration.withCredentials = true;
40-
}
38+
) {}
4139

4240
getAuthorizationHeaders(): Record<string, string> {
4341
const lang = this.translocoService.getActiveLang();
@@ -58,7 +56,9 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
5856
}
5957

6058
oAuthProviders(): Observable<OAuthProvider[]> {
61-
return this.ssoRestService.ssoOAuthControllerOauthProviders();
59+
return this.restSdkAngularService
60+
.getSsoApi()
61+
.ssoOAuthControllerOauthProviders();
6262
}
6363

6464
oAuthVerification({
@@ -67,7 +67,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
6767
}: OAuthVerificationInput): Observable<SsoUserAndTokens> {
6868
return this.fingerprintService.getFingerprint().pipe(
6969
mergeMap((fingerprint) =>
70-
this.ssoRestService
70+
this.restSdkAngularService
71+
.getSsoApi()
7172
.ssoOAuthControllerOauthVerification({
7273
fingerprint,
7374
verificationCode,
@@ -84,7 +85,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
8485

8586
logout(): Observable<void | null> {
8687
const refreshToken = this.tokensService.getRefreshToken();
87-
return this.ssoRestService
88+
return this.restSdkAngularService
89+
.getSsoApi()
8890
.ssoControllerSignOut(
8991
refreshToken
9092
? {
@@ -100,11 +102,14 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
100102
}
101103

102104
getProfile(): Observable<SsoUser | undefined> {
103-
return this.ssoRestService.ssoControllerProfile().pipe(
104-
map((result) => {
105-
return this.mapToSsoUser(result);
106-
})
107-
);
105+
return this.restSdkAngularService
106+
.getSsoApi()
107+
.ssoControllerProfile()
108+
.pipe(
109+
map((result) => {
110+
return this.mapToSsoUser(result);
111+
})
112+
);
108113
}
109114

110115
private mapToSsoTokens(tokens: TokensResponseInterface) {
@@ -149,19 +154,23 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
149154
return of(undefined);
150155
}),
151156
mergeMap((picture) => {
152-
return this.ssoRestService.ssoControllerUpdateProfile({
153-
birthdate: data.birthdate,
154-
firstname: data.givenName,
155-
gender: data.gender,
156-
lastname: data.familyName,
157-
picture,
158-
password: data.newPassword,
159-
confirmPassword: data.confirmNewPassword,
160-
oldPassword: data.oldPassword,
161-
timezone: data.timezone,
162-
});
157+
return this.restSdkAngularService
158+
.getSsoApi()
159+
.ssoControllerUpdateProfile({
160+
birthdate: data.birthdate,
161+
firstname: data.givenName,
162+
gender: data.gender,
163+
lastname: data.familyName,
164+
picture,
165+
password: data.newPassword,
166+
confirmPassword: data.confirmNewPassword,
167+
oldPassword: data.oldPassword,
168+
timezone: data.timezone,
169+
});
163170
}),
164-
mergeMap(() => this.ssoRestService.ssoControllerProfile()),
171+
mergeMap(() =>
172+
this.restSdkAngularService.getSsoApi().ssoControllerProfile()
173+
),
165174
mergeMap((newData) => {
166175
if (
167176
oldData?.picture &&
@@ -182,7 +191,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
182191
const refreshToken = this.tokensService.getRefreshToken();
183192
return this.fingerprintService.getFingerprint().pipe(
184193
mergeMap((fingerprint) =>
185-
this.ssoRestService
194+
this.restSdkAngularService
195+
.getSsoApi()
186196
.ssoControllerRefreshTokens({
187197
...(refreshToken
188198
? {
@@ -214,7 +224,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
214224
}
215225
return this.fingerprintService.getFingerprint().pipe(
216226
mergeMap((fingerprint) =>
217-
this.ssoRestService
227+
this.restSdkAngularService
228+
.getSsoApi()
218229
.ssoControllerSignUp({
219230
email,
220231
fingerprint,
@@ -239,7 +250,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
239250
}
240251
return this.fingerprintService.getFingerprint().pipe(
241252
mergeMap((fingerprint) =>
242-
this.ssoRestService
253+
this.restSdkAngularService
254+
.getSsoApi()
243255
.ssoControllerSignIn({
244256
email,
245257
fingerprint,
@@ -262,7 +274,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
262274
}
263275
return this.fingerprintService.getFingerprint().pipe(
264276
mergeMap((fingerprint) =>
265-
this.ssoRestService
277+
this.restSdkAngularService
278+
.getSsoApi()
266279
.ssoControllerCompleteSignUp({
267280
code,
268281
fingerprint,
@@ -292,7 +305,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
292305
}
293306
return this.fingerprintService.getFingerprint().pipe(
294307
mergeMap((fingerprint) =>
295-
this.ssoRestService
308+
this.restSdkAngularService
309+
.getSsoApi()
296310
.ssoControllerCompleteForgotPassword({
297311
password,
298312
confirmPassword,
@@ -314,7 +328,8 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
314328
if (!email) {
315329
throw new Error('email not set');
316330
}
317-
return this.ssoRestService
331+
return this.restSdkAngularService
332+
.getSsoApi()
318333
.ssoControllerForgotPassword({
319334
email,
320335
redirectUri,
@@ -328,7 +343,7 @@ export function provideSsoConfiguration(): Provider {
328343
provide: SSO_CONFIGURATION_TOKEN,
329344
useClass: SsoIntegrationConfiguration,
330345
deps: [
331-
SsoRestService,
346+
RestSdkAngularService,
332347
FilesService,
333348
TranslocoService,
334349
TokensService,

0 commit comments

Comments
 (0)