@descope/angular-sdk 0.0.0-next-cc7eda17-20231228 → 0.0.0-next-8c050e76-20231228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +11 -450
  2. package/environment.d.ts +3 -0
  3. package/esm2022/descope-angular-sdk.mjs +5 -0
  4. package/esm2022/environment.mjs +4 -0
  5. package/esm2022/lib/components/descope/descope.component.mjs +106 -0
  6. package/esm2022/lib/components/sign-in-flow/sign-in-flow.component.mjs +40 -0
  7. package/esm2022/lib/components/sign-up-flow/sign-up-flow.component.mjs +40 -0
  8. package/esm2022/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.mjs +40 -0
  9. package/esm2022/lib/descope-auth.module.mjs +52 -0
  10. package/esm2022/lib/services/descope-auth.guard.mjs +15 -0
  11. package/esm2022/lib/services/descope-auth.service.mjs +139 -0
  12. package/esm2022/lib/services/descope.interceptor.mjs +51 -0
  13. package/esm2022/lib/types/types.mjs +6 -0
  14. package/esm2022/lib/utils/constants.mjs +7 -0
  15. package/esm2022/lib/utils/helpers.mjs +27 -0
  16. package/esm2022/public-api.mjs +13 -0
  17. package/fesm2022/descope-angular-sdk.mjs +500 -0
  18. package/fesm2022/descope-angular-sdk.mjs.map +1 -0
  19. package/index.d.ts +5 -0
  20. package/lib/components/descope/descope.component.d.ts +32 -0
  21. package/lib/components/sign-in-flow/sign-in-flow.component.d.ts +24 -0
  22. package/lib/components/sign-up-flow/sign-up-flow.component.d.ts +24 -0
  23. package/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.d.ts +24 -0
  24. package/lib/descope-auth.module.d.ts +14 -0
  25. package/lib/services/descope-auth.guard.d.ts +2 -0
  26. package/lib/services/descope-auth.service.d.ts +38 -0
  27. package/lib/services/descope.interceptor.d.ts +2 -0
  28. package/lib/types/types.d.ts +8 -0
  29. package/lib/utils/constants.d.ts +5 -0
  30. package/lib/utils/helpers.d.ts +5 -0
  31. package/package.json +38 -77
  32. package/{projects/angular-sdk/src/public-api.ts → public-api.d.ts} +0 -4
  33. package/.editorconfig +0 -16
  34. package/.eslintrc.json +0 -40
  35. package/.github/workflows/ci.yml +0 -98
  36. package/.github/workflows/publish-next.yml +0 -43
  37. package/.github/workflows/publish.yml +0 -31
  38. package/.github/workflows/release.yml +0 -41
  39. package/.husky/pre-commit +0 -4
  40. package/.prettierrc +0 -8
  41. package/.vscode/extensions.json +0 -4
  42. package/.vscode/launch.json +0 -20
  43. package/.vscode/settings.json +0 -3
  44. package/.vscode/tasks.json +0 -42
  45. package/LICENSE +0 -21
  46. package/angular.json +0 -154
  47. package/jest.config.js +0 -17
  48. package/projects/angular-sdk/.eslintrc.json +0 -32
  49. package/projects/angular-sdk/README.md +0 -21
  50. package/projects/angular-sdk/ng-package.json +0 -8
  51. package/projects/angular-sdk/src/environment.ts +0 -3
  52. package/projects/angular-sdk/src/lib/components/descope/descope.component.spec.ts +0 -104
  53. package/projects/angular-sdk/src/lib/components/descope/descope.component.ts +0 -114
  54. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.html +0 -15
  55. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.spec.ts +0 -53
  56. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.ts +0 -32
  57. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.html +0 -15
  58. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.spec.ts +0 -51
  59. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.ts +0 -32
  60. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.html +0 -15
  61. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.spec.ts +0 -53
  62. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.ts +0 -32
  63. package/projects/angular-sdk/src/lib/descope-auth.module.ts +0 -46
  64. package/projects/angular-sdk/src/lib/services/descope-auth.guard.spec.ts +0 -76
  65. package/projects/angular-sdk/src/lib/services/descope-auth.guard.ts +0 -16
  66. package/projects/angular-sdk/src/lib/services/descope-auth.service.spec.ts +0 -264
  67. package/projects/angular-sdk/src/lib/services/descope-auth.service.ts +0 -176
  68. package/projects/angular-sdk/src/lib/services/descope.interceptor.spec.ts +0 -102
  69. package/projects/angular-sdk/src/lib/services/descope.interceptor.ts +0 -76
  70. package/projects/angular-sdk/src/lib/types/types.ts +0 -10
  71. package/projects/angular-sdk/src/lib/utils/constants.ts +0 -8
  72. package/projects/angular-sdk/src/lib/utils/helpers.spec.ts +0 -103
  73. package/projects/angular-sdk/src/lib/utils/helpers.ts +0 -36
  74. package/projects/angular-sdk/tsconfig.lib.json +0 -12
  75. package/projects/angular-sdk/tsconfig.lib.prod.json +0 -10
  76. package/projects/angular-sdk/tsconfig.spec.json +0 -11
  77. package/projects/demo-app/.eslintrc.json +0 -31
  78. package/projects/demo-app/src/app/app-routing.module.ts +0 -23
  79. package/projects/demo-app/src/app/app.component.html +0 -3
  80. package/projects/demo-app/src/app/app.component.scss +0 -16
  81. package/projects/demo-app/src/app/app.component.spec.ts +0 -37
  82. package/projects/demo-app/src/app/app.component.ts +0 -8
  83. package/projects/demo-app/src/app/app.module.ts +0 -52
  84. package/projects/demo-app/src/app/home/home.component.html +0 -23
  85. package/projects/demo-app/src/app/home/home.component.scss +0 -15
  86. package/projects/demo-app/src/app/home/home.component.spec.ts +0 -44
  87. package/projects/demo-app/src/app/home/home.component.ts +0 -61
  88. package/projects/demo-app/src/app/interceptor/auth.interceptor.ts +0 -20
  89. package/projects/demo-app/src/app/login/login.component.html +0 -12
  90. package/projects/demo-app/src/app/login/login.component.spec.ts +0 -42
  91. package/projects/demo-app/src/app/login/login.component.ts +0 -35
  92. package/projects/demo-app/src/app/protected/protected.component.html +0 -18
  93. package/projects/demo-app/src/app/protected/protected.component.scss +0 -8
  94. package/projects/demo-app/src/app/protected/protected.component.spec.ts +0 -42
  95. package/projects/demo-app/src/app/protected/protected.component.ts +0 -40
  96. package/projects/demo-app/src/assets/.gitkeep +0 -0
  97. package/projects/demo-app/src/environments/conifg.ts +0 -13
  98. package/projects/demo-app/src/environments/environment.ts +0 -19
  99. package/projects/demo-app/src/favicon.ico +0 -0
  100. package/projects/demo-app/src/index.html +0 -17
  101. package/projects/demo-app/src/main.ts +0 -7
  102. package/projects/demo-app/src/styles.scss +0 -21
  103. package/projects/demo-app/tsconfig.app.json +0 -10
  104. package/projects/demo-app/tsconfig.spec.json +0 -10
  105. package/renovate.json +0 -4
  106. package/scripts/gitleaks/.gitleaks.toml +0 -653
  107. package/scripts/gitleaks/gitleaks.sh +0 -34
  108. package/scripts/setversion/setversion.js +0 -20
  109. package/setup-jest.ts +0 -1
  110. package/thirdPartyLicenseCollector_linux_amd64 +0 -0
  111. package/tsconfig.json +0 -35
@@ -1,102 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import {
3
- HttpTestingController,
4
- provideHttpClientTesting
5
- } from '@angular/common/http/testing';
6
- import {
7
- HttpClient,
8
- provideHttpClient,
9
- withInterceptors
10
- } from '@angular/common/http';
11
- import { of } from 'rxjs';
12
- import { DescopeAuthService } from './descope-auth.service';
13
- import { DescopeAuthConfig } from '../types/types';
14
- import createSdk from '@descope/web-js-sdk';
15
- import { descopeInterceptor } from './descope.interceptor';
16
- import mocked = jest.mocked;
17
-
18
- jest.mock('@descope/web-js-sdk');
19
-
20
- describe('DescopeInterceptor', () => {
21
- let authService: DescopeAuthService;
22
- let httpTestingController: HttpTestingController;
23
- let httpClient: HttpClient;
24
- let mockedCreateSdk: jest.Mock;
25
-
26
- beforeEach(() => {
27
- mockedCreateSdk = mocked(createSdk);
28
- mockedCreateSdk.mockReturnValue({
29
- onSessionTokenChange: jest.fn(),
30
- onUserChange: jest.fn()
31
- });
32
-
33
- TestBed.configureTestingModule({
34
- providers: [
35
- DescopeAuthService,
36
- {
37
- provide: DescopeAuthConfig,
38
- useValue: { pathsToIntercept: ['/api'], projectId: 'test' }
39
- },
40
- provideHttpClient(withInterceptors([descopeInterceptor])),
41
- provideHttpClientTesting()
42
- ]
43
- });
44
-
45
- authService = TestBed.inject(DescopeAuthService);
46
- httpTestingController = TestBed.inject(HttpTestingController);
47
- httpClient = TestBed.inject(HttpClient);
48
- });
49
-
50
- afterEach(() => {
51
- httpTestingController.verify();
52
- });
53
-
54
- it('should intercept requests for specified paths', () => {
55
- jest.spyOn(authService, 'getSessionToken').mockReturnValue('fakeToken');
56
-
57
- httpClient.get('/api/data').subscribe();
58
- httpClient.get('/other').subscribe();
59
-
60
- const req1 = httpTestingController.expectOne('/api/data');
61
- const req2 = httpTestingController.expectOne('/other');
62
-
63
- expect(req1.request.headers.get('Authorization')).toEqual(
64
- 'Bearer fakeToken'
65
- );
66
- expect(req2.request.headers.get('Authorization')).toEqual(null);
67
- req1.flush({});
68
- req2.flush({});
69
- });
70
-
71
- it('should refresh token and retry request on 401 or 403 error', () => {
72
- jest.spyOn(authService, 'getSessionToken').mockReturnValue(null);
73
- const refreshSessionSpy = jest
74
- .spyOn(authService, 'refreshSession')
75
- .mockReturnValue(of({ ok: true, data: { sessionJwt: 'newToken' } }));
76
-
77
- httpClient.get('/api/data').subscribe();
78
-
79
- const req = httpTestingController.expectOne('/api/data');
80
-
81
- expect(req.request.headers.get('Authorization')).toEqual('Bearer newToken');
82
- expect(refreshSessionSpy).toHaveBeenCalled();
83
- req.flush({}, { status: 401, statusText: 'Not authorized' });
84
- });
85
-
86
- it('should throw an error if refreshing the session fails', () => {
87
- jest.spyOn(authService, 'getSessionToken').mockReturnValue(null);
88
- jest
89
- .spyOn(authService, 'refreshSession')
90
- .mockReturnValue(of({ ok: false, data: undefined }));
91
-
92
- httpClient.get('/api/data').subscribe({
93
- next: () => {},
94
- error: (error) => {
95
- expect(error.message).toEqual('Could not refresh session!');
96
- },
97
- complete: () => {}
98
- });
99
-
100
- httpTestingController.expectNone('/api/data');
101
- });
102
- });
@@ -1,76 +0,0 @@
1
- import { inject } from '@angular/core';
2
- import {
3
- HttpErrorResponse,
4
- HttpHandlerFn,
5
- HttpInterceptorFn,
6
- HttpRequest
7
- } from '@angular/common/http';
8
- import { throwError } from 'rxjs';
9
- import { catchError, switchMap } from 'rxjs/operators';
10
- import { DescopeAuthService } from './descope-auth.service';
11
- import { DescopeAuthConfig } from '../types/types';
12
-
13
- export const descopeInterceptor: HttpInterceptorFn = (request, next) => {
14
- const config = inject(DescopeAuthConfig);
15
- const authService = inject(DescopeAuthService);
16
-
17
- function refreshAndRetry(
18
- request: HttpRequest<unknown>,
19
- next: HttpHandlerFn,
20
- error?: HttpErrorResponse
21
- ) {
22
- return authService.refreshSession().pipe(
23
- switchMap((refreshed) => {
24
- if (refreshed.ok && refreshed.data) {
25
- const requestWithRefreshedToken = addTokenToRequest(
26
- request,
27
- refreshed.data?.sessionJwt
28
- );
29
- return next(requestWithRefreshedToken);
30
- } else {
31
- return throwError(
32
- () => error ?? new Error('Could not refresh session!')
33
- );
34
- }
35
- })
36
- );
37
- }
38
-
39
- function shouldIntercept(request: HttpRequest<unknown>): boolean {
40
- return (
41
- (config.pathsToIntercept?.length === 0 ||
42
- config.pathsToIntercept?.some((path) => request.url.includes(path))) ??
43
- true
44
- );
45
- }
46
-
47
- function addTokenToRequest(
48
- request: HttpRequest<unknown>,
49
- token: string
50
- ): HttpRequest<unknown> {
51
- return request.clone({
52
- setHeaders: {
53
- Authorization: `Bearer ${token}`
54
- }
55
- });
56
- }
57
-
58
- if (shouldIntercept(request)) {
59
- const token = authService.getSessionToken();
60
- if (!token) {
61
- return refreshAndRetry(request, next);
62
- }
63
- const requestWithToken = addTokenToRequest(request, token);
64
- return next(requestWithToken).pipe(
65
- catchError((error: HttpErrorResponse) => {
66
- if (error.status === 401 || error.status === 403) {
67
- return refreshAndRetry(request, next, error);
68
- } else {
69
- return throwError(() => error);
70
- }
71
- })
72
- );
73
- } else {
74
- return next(request);
75
- }
76
- };
@@ -1,10 +0,0 @@
1
- import { ILogger } from '@descope/web-component';
2
-
3
- export class DescopeAuthConfig {
4
- projectId = '';
5
- baseUrl?: string;
6
- sessionTokenViaCookie?: boolean;
7
- pathsToIntercept?: string[];
8
- }
9
-
10
- export type { ILogger };
@@ -1,8 +0,0 @@
1
- import { environment } from '../../environment';
2
-
3
- export const baseHeaders = {
4
- 'x-descope-sdk-name': 'angular',
5
- 'x-descope-sdk-version': environment.buildVersion
6
- };
7
-
8
- export const isBrowser = () => typeof window !== 'undefined';
@@ -1,103 +0,0 @@
1
- import { observabilify, Observablefied } from './helpers';
2
- import { lastValueFrom, Observable } from 'rxjs';
3
-
4
- describe('Helpers', () => {
5
- describe('Observabilify', () => {
6
- it('should not affect simple object', () => {
7
- //GIVEN
8
- const obj = {
9
- field1: 'string',
10
- field2: 123,
11
- nested: {
12
- field1: 'string',
13
- field2: 123
14
- }
15
- };
16
- type TestType = typeof obj;
17
-
18
- //WHEN
19
- const result: Observablefied<TestType> = observabilify<TestType>(obj);
20
-
21
- //THEN
22
- expect(result).toStrictEqual(obj);
23
- });
24
-
25
- it('should not affect simple object with non async functions', () => {
26
- //GIVEN
27
- const obj = {
28
- field1: 'string',
29
- field2: 123,
30
- fn: (arg1: string, arg2: number): string => {
31
- return arg1 + arg2.toString();
32
- },
33
- nested: {
34
- fn2: (arg: string): string => {
35
- return arg;
36
- },
37
- field1: 'string',
38
- field2: 123
39
- }
40
- };
41
- type TestType = typeof obj;
42
- const expected1 = obj.fn('Test', 1);
43
- const expected2 = obj.nested.fn2('Test');
44
-
45
- //WHEN
46
- const transformed: Observablefied<TestType> =
47
- observabilify<TestType>(obj);
48
- const actual1 = transformed.fn('Test', 1);
49
- const actual2 = transformed.nested.fn2('Test');
50
-
51
- //THEN
52
- expect(expected1).toStrictEqual(actual1);
53
- expect(expected2).toStrictEqual(actual2);
54
- });
55
-
56
- it('should transform async functions', async () => {
57
- //GIVEN
58
- const obj = {
59
- field1: 'string',
60
- field2: 123,
61
- fn: (arg1: string, arg2: number): string => {
62
- return arg1 + arg2.toString();
63
- },
64
- asyncFn: (arg1: string, arg2: number): Promise<string> => {
65
- return Promise.resolve(arg1 + arg2.toString());
66
- },
67
- nested: {
68
- fn2: (arg: string) => {
69
- return arg;
70
- },
71
- asyncFn: (arg: string): Promise<string> => {
72
- return Promise.resolve(arg);
73
- },
74
- field1: 'string',
75
- field2: 123
76
- }
77
- };
78
- type TestType = typeof obj;
79
- const expected1 = obj.fn('Test', 1);
80
- const expected2 = obj.nested.fn2('Test');
81
- const expected3 = await obj.asyncFn('Test', 1);
82
- const expected4 = await obj.nested.asyncFn('Test');
83
-
84
- //WHEN
85
- const transformed: Observablefied<TestType> =
86
- observabilify<TestType>(obj);
87
- const actual1 = transformed.fn('Test', 1);
88
- const actual2 = transformed.nested.fn2('Test');
89
- const actual3Async = transformed.asyncFn('Test', 1);
90
- const actual3 = await lastValueFrom(actual3Async);
91
- const actual4Async = transformed.nested.asyncFn('Test');
92
- const actual4 = await lastValueFrom(actual4Async);
93
-
94
- //THEN
95
- expect(expected1).toStrictEqual(actual1);
96
- expect(expected2).toStrictEqual(actual2);
97
- expect(actual3Async).toBeInstanceOf(Observable);
98
- expect(actual4Async).toBeInstanceOf(Observable);
99
- expect(expected3).toStrictEqual(actual3);
100
- expect(expected4).toStrictEqual(actual4);
101
- });
102
- });
103
- });
@@ -1,36 +0,0 @@
1
- import { from, Observable } from 'rxjs';
2
-
3
- export type Observablefied<T> = {
4
- [K in keyof T]: T[K] extends (...args: infer Args) => Promise<infer R>
5
- ? (...args: Args) => Observable<R>
6
- : T[K] extends (...args: infer Args) => infer R
7
- ? (...args: Args) => R
8
- : T[K] extends object
9
- ? Observablefied<T[K]>
10
- : T[K];
11
- };
12
-
13
- export function observabilify<T>(value: T): Observablefied<T> {
14
- /* eslint-disable @typescript-eslint/no-explicit-any */
15
- const observableValue: any = {};
16
-
17
- for (const key in value) {
18
- if (typeof value[key] === 'function') {
19
- const fn = value[key] as (...args: unknown[]) => unknown;
20
- observableValue[key] = (...args: unknown[]) => {
21
- const fnResult = fn(...args);
22
- if (fnResult instanceof Promise) {
23
- return from(fnResult);
24
- } else {
25
- return fnResult;
26
- }
27
- };
28
- } else if (typeof value[key] === 'object' && value[key] !== null) {
29
- observableValue[key] = observabilify(value[key]);
30
- } else {
31
- observableValue[key] = value[key];
32
- }
33
- }
34
-
35
- return observableValue as Observablefied<T>;
36
- }
@@ -1,12 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/lib",
6
- "declaration": true,
7
- "declarationMap": true,
8
- "inlineSources": true,
9
- "types": []
10
- },
11
- "exclude": ["**/*.spec.ts"]
12
- }
@@ -1,10 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "./tsconfig.lib.json",
4
- "compilerOptions": {
5
- "declarationMap": false
6
- },
7
- "angularCompilerOptions": {
8
- "compilationMode": "partial"
9
- }
10
- }
@@ -1,11 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/spec",
6
- "types": ["jest"],
7
- "esModuleInterop": true,
8
- "emitDecoratorMetadata": true
9
- },
10
- "include": ["**/*.spec.ts", "**/*.d.ts"]
11
- }
@@ -1,31 +0,0 @@
1
- {
2
- "extends": "../../.eslintrc.json",
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts"],
7
- "rules": {
8
- "@angular-eslint/directive-selector": [
9
- "error",
10
- {
11
- "type": "attribute",
12
- "prefix": "app",
13
- "style": "camelCase"
14
- }
15
- ],
16
- "@angular-eslint/component-selector": [
17
- "error",
18
- {
19
- "type": "element",
20
- "prefix": "app",
21
- "style": "kebab-case"
22
- }
23
- ]
24
- }
25
- },
26
- {
27
- "files": ["*.html"],
28
- "rules": {}
29
- }
30
- ]
31
- }
@@ -1,23 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { RouterModule, Routes } from '@angular/router';
3
- import { HomeComponent } from './home/home.component';
4
- import { ProtectedComponent } from './protected/protected.component';
5
- import { descopeAuthGuard } from '../../../angular-sdk/src/lib/services/descope-auth.guard';
6
- import { LoginComponent } from './login/login.component';
7
-
8
- const routes: Routes = [
9
- {
10
- path: 'step-up',
11
- component: ProtectedComponent,
12
- canActivate: [descopeAuthGuard],
13
- data: { descopeFallbackUrl: '/' }
14
- },
15
- { path: 'login', component: LoginComponent },
16
- { path: '**', component: HomeComponent }
17
- ];
18
-
19
- @NgModule({
20
- imports: [RouterModule.forRoot(routes, { enableTracing: false })],
21
- exports: [RouterModule]
22
- })
23
- export class AppRoutingModule {}
@@ -1,3 +0,0 @@
1
- <main>
2
- <router-outlet></router-outlet>
3
- </main>
@@ -1,16 +0,0 @@
1
- :host {
2
- height: 100vh;
3
- position: relative;
4
- }
5
- main {
6
- border-radius: 10px;
7
- margin: auto;
8
- border: 1px solid lightgray;
9
- padding: 20px;
10
- max-width: 400px;
11
- box-shadow: 13px 13px 20px #cbced1, -13px -13px 20px #fff;
12
- background: #ecf0f3;
13
- position: relative;
14
- top: 50%;
15
- transform: translateY(-50%);
16
- }
@@ -1,37 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import { RouterTestingModule } from '@angular/router/testing';
3
- import { AppComponent } from './app.component';
4
- import createSdk from '@descope/web-js-sdk';
5
- import mocked = jest.mocked;
6
- import { DescopeAuthConfig } from '../../../angular-sdk/src/lib/types/types';
7
-
8
- jest.mock('@descope/web-js-sdk');
9
-
10
- describe('AppComponent', () => {
11
- let mockedCreateSdk: jest.Mock;
12
- const onSessionTokenChangeSpy = jest.fn();
13
- const onUserChangeSpy = jest.fn();
14
-
15
- beforeEach(() => {
16
- mockedCreateSdk = mocked(createSdk);
17
- mockedCreateSdk.mockReturnValue({
18
- onSessionTokenChange: onSessionTokenChangeSpy,
19
- onUserChange: onUserChangeSpy
20
- });
21
-
22
- TestBed.configureTestingModule({
23
- imports: [RouterTestingModule],
24
- providers: [
25
- DescopeAuthConfig,
26
- { provide: DescopeAuthConfig, useValue: { projectId: 'test' } }
27
- ],
28
- declarations: [AppComponent]
29
- });
30
- });
31
-
32
- it('should create the app', () => {
33
- const fixture = TestBed.createComponent(AppComponent);
34
- const app = fixture.componentInstance;
35
- expect(app).toBeTruthy();
36
- });
37
- });
@@ -1,8 +0,0 @@
1
- import { Component } from '@angular/core';
2
-
3
- @Component({
4
- selector: 'app-root',
5
- templateUrl: './app.component.html',
6
- styleUrls: ['./app.component.scss']
7
- })
8
- export class AppComponent {}
@@ -1,52 +0,0 @@
1
- import { APP_INITIALIZER, NgModule } from '@angular/core';
2
- import { BrowserModule } from '@angular/platform-browser';
3
-
4
- import { AppRoutingModule } from './app-routing.module';
5
- import { AppComponent } from './app.component';
6
- import { DescopeAuthModule } from '../../../angular-sdk/src/lib/descope-auth.module';
7
- import { HomeComponent } from './home/home.component';
8
- import { ProtectedComponent } from './protected/protected.component';
9
- import { environment } from '../environments/environment';
10
- import { DescopeAuthService } from 'projects/angular-sdk/src/public-api';
11
- import { zip } from 'rxjs';
12
- import { LoginComponent } from './login/login.component';
13
- import {
14
- HttpClientModule,
15
- provideHttpClient,
16
- withInterceptors
17
- } from '@angular/common/http';
18
- import { descopeInterceptor } from '../../../angular-sdk/src/lib/services/descope.interceptor';
19
-
20
- export function initializeApp(authService: DescopeAuthService) {
21
- return () => zip([authService.refreshSession(), authService.refreshUser()]);
22
- }
23
-
24
- @NgModule({
25
- declarations: [
26
- AppComponent,
27
- HomeComponent,
28
- ProtectedComponent,
29
- LoginComponent
30
- ],
31
- imports: [
32
- BrowserModule,
33
- AppRoutingModule,
34
- HttpClientModule,
35
- DescopeAuthModule.forRoot({
36
- projectId: environment.descopeProjectId,
37
- baseUrl: environment.descopeBaseUrl || '',
38
- sessionTokenViaCookie: false
39
- })
40
- ],
41
- providers: [
42
- {
43
- provide: APP_INITIALIZER,
44
- useFactory: initializeApp,
45
- deps: [DescopeAuthService],
46
- multi: true
47
- },
48
- provideHttpClient(withInterceptors([descopeInterceptor]))
49
- ],
50
- bootstrap: [AppComponent]
51
- })
52
- export class AppModule {}
@@ -1,23 +0,0 @@
1
- <h2>ANGULAR SDK DEMO APP</h2>
2
- <button *ngIf="!isAuthenticated" (click)="login()">LOGIN</button>
3
- <ng-container *ngIf="isAuthenticated">
4
- <h3>Hello {{ userName }}</h3>
5
- <div>
6
- Roles:
7
- <ng-container *ngIf="roles && roles.length; else noRoles">
8
- {{ roles }}
9
- </ng-container>
10
- <ng-template #noRoles>N/A</ng-template>
11
- </div>
12
- <button
13
- *ngIf="backendUrl.length > 0"
14
- class="action-button"
15
- (click)="fetchData()"
16
- >
17
- FETCH DATA
18
- </button>
19
- <button *ngIf="stepUpConfigured" class="action-button" (click)="stepUp()">
20
- STEP UP
21
- </button>
22
- <button class="logout-button" (click)="logout()">LOGOUT</button>
23
- </ng-container>
@@ -1,15 +0,0 @@
1
- :host {
2
- display: flex;
3
- justify-content: center;
4
- align-items: center;
5
- flex-direction: column;
6
- }
7
- .action-button {
8
- border: 1px solid #00ace1;
9
- background-color: white;
10
- color: #00ace1;
11
- margin-bottom: 1rem;
12
- &:first-of-type {
13
- margin-top: 1rem;
14
- }
15
- }
@@ -1,44 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
-
3
- import { HomeComponent } from './home.component';
4
- import createSdk from '@descope/web-js-sdk';
5
- import mocked = jest.mocked;
6
- import { NO_ERRORS_SCHEMA } from '@angular/core';
7
- import { DescopeAuthConfig } from '../../../../angular-sdk/src/lib/types/types';
8
- import { HttpClientTestingModule } from '@angular/common/http/testing';
9
-
10
- jest.mock('@descope/web-js-sdk');
11
-
12
- describe('HomeComponent', () => {
13
- let component: HomeComponent;
14
- let fixture: ComponentFixture<HomeComponent>;
15
-
16
- let mockedCreateSdk: jest.Mock;
17
- const onSessionTokenChangeSpy = jest.fn();
18
- const onUserChangeSpy = jest.fn();
19
-
20
- beforeEach(() => {
21
- mockedCreateSdk = mocked(createSdk);
22
- mockedCreateSdk.mockReturnValue({
23
- onSessionTokenChange: onSessionTokenChangeSpy,
24
- onUserChange: onUserChangeSpy
25
- });
26
-
27
- TestBed.configureTestingModule({
28
- imports: [HttpClientTestingModule],
29
- schemas: [NO_ERRORS_SCHEMA],
30
- declarations: [HomeComponent],
31
- providers: [
32
- DescopeAuthConfig,
33
- { provide: DescopeAuthConfig, useValue: { projectId: 'test' } }
34
- ]
35
- });
36
- fixture = TestBed.createComponent(HomeComponent);
37
- component = fixture.componentInstance;
38
- fixture.detectChanges();
39
- });
40
-
41
- it('should create', () => {
42
- expect(component).toBeTruthy();
43
- });
44
- });