@descope/angular-sdk 0.5.11 → 0.5.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/dist/lib/services/descope-auth.service.d.ts +0 -1
- package/package.json +21 -17
- package/.eslintrc.json +0 -41
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -5
- package/angular.json +0 -154
- package/jest.config.js +0 -17
- package/project.json +0 -17
- package/projects/angular-sdk/.eslintrc.json +0 -32
- package/projects/angular-sdk/ng-package.json +0 -17
- package/projects/angular-sdk/package.json +0 -87
- package/projects/angular-sdk/src/environment.ts +0 -3
- package/projects/angular-sdk/src/lib/components/access-key-management/access-key-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/access-key-management/access-key-management.component.ts +0 -63
- package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.ts +0 -63
- package/projects/angular-sdk/src/lib/components/descope/descope.component.spec.ts +0 -142
- package/projects/angular-sdk/src/lib/components/descope/descope.component.ts +0 -171
- package/projects/angular-sdk/src/lib/components/role-management/role-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/role-management/role-management.component.ts +0 -63
- package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.html +0 -17
- package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.spec.ts +0 -53
- package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.ts +0 -35
- package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.html +0 -17
- package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.spec.ts +0 -51
- package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.ts +0 -35
- package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.html +0 -17
- package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.spec.ts +0 -53
- package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.ts +0 -35
- package/projects/angular-sdk/src/lib/components/user-management/user-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/user-management/user-management.component.ts +0 -64
- package/projects/angular-sdk/src/lib/components/user-profile/user-profile.component.spec.ts +0 -93
- package/projects/angular-sdk/src/lib/components/user-profile/user-profile.component.ts +0 -77
- package/projects/angular-sdk/src/lib/descope-auth.module.ts +0 -61
- package/projects/angular-sdk/src/lib/services/descope-auth.guard.spec.ts +0 -76
- package/projects/angular-sdk/src/lib/services/descope-auth.guard.ts +0 -16
- package/projects/angular-sdk/src/lib/services/descope-auth.service.spec.ts +0 -309
- package/projects/angular-sdk/src/lib/services/descope-auth.service.ts +0 -200
- package/projects/angular-sdk/src/lib/services/descope.interceptor.spec.ts +0 -102
- package/projects/angular-sdk/src/lib/services/descope.interceptor.ts +0 -76
- package/projects/angular-sdk/src/lib/types/types.ts +0 -15
- package/projects/angular-sdk/src/lib/utils/constants.ts +0 -8
- package/projects/angular-sdk/src/lib/utils/helpers.spec.ts +0 -103
- package/projects/angular-sdk/src/lib/utils/helpers.ts +0 -36
- package/projects/angular-sdk/src/public-api.ts +0 -18
- package/projects/angular-sdk/tsconfig.lib.json +0 -12
- package/projects/angular-sdk/tsconfig.lib.prod.json +0 -10
- package/projects/angular-sdk/tsconfig.spec.json +0 -11
- package/projects/demo-app/.eslintrc.json +0 -31
- package/projects/demo-app/src/app/app-routing.module.ts +0 -33
- package/projects/demo-app/src/app/app.component.html +0 -3
- package/projects/demo-app/src/app/app.component.scss +0 -18
- package/projects/demo-app/src/app/app.component.spec.ts +0 -37
- package/projects/demo-app/src/app/app.component.ts +0 -8
- package/projects/demo-app/src/app/app.module.ts +0 -63
- package/projects/demo-app/src/app/home/home.component.html +0 -32
- package/projects/demo-app/src/app/home/home.component.scss +0 -15
- package/projects/demo-app/src/app/home/home.component.spec.ts +0 -44
- package/projects/demo-app/src/app/home/home.component.ts +0 -85
- package/projects/demo-app/src/app/interceptor/auth.interceptor.ts +0 -20
- package/projects/demo-app/src/app/login/login.component.html +0 -20
- package/projects/demo-app/src/app/login/login.component.spec.ts +0 -42
- package/projects/demo-app/src/app/login/login.component.ts +0 -41
- package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.html +0 -12
- package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.ts +0 -15
- package/projects/demo-app/src/app/manage-audit/manage-audit.component.html +0 -6
- package/projects/demo-app/src/app/manage-audit/manage-audit.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-audit/manage-audit.component.ts +0 -15
- package/projects/demo-app/src/app/manage-roles/manage-roles.component.html +0 -6
- package/projects/demo-app/src/app/manage-roles/manage-roles.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-roles/manage-roles.component.ts +0 -15
- package/projects/demo-app/src/app/manage-users/manage-users.component.html +0 -6
- package/projects/demo-app/src/app/manage-users/manage-users.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-users/manage-users.component.ts +0 -15
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.html +0 -6
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.spec.ts +0 -36
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.ts +0 -20
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.scss +0 -18
- package/projects/demo-app/src/app/protected/protected.component.html +0 -18
- package/projects/demo-app/src/app/protected/protected.component.scss +0 -8
- package/projects/demo-app/src/app/protected/protected.component.spec.ts +0 -42
- package/projects/demo-app/src/app/protected/protected.component.ts +0 -41
- package/projects/demo-app/src/assets/.gitkeep +0 -0
- package/projects/demo-app/src/environments/conifg.ts +0 -14
- package/projects/demo-app/src/environments/environment.ts +0 -20
- package/projects/demo-app/src/favicon.ico +0 -0
- package/projects/demo-app/src/index.html +0 -17
- package/projects/demo-app/src/main.ts +0 -7
- package/projects/demo-app/src/styles.scss +0 -21
- package/projects/demo-app/tsconfig.app.json +0 -11
- package/projects/demo-app/tsconfig.spec.json +0 -10
- package/scripts/setversion/setversion.js +0 -20
- package/setup-jest.ts +0 -1
- package/tsconfig.json +0 -36
package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.spec.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
import { AuditManagementComponent } from './audit-management.component';
|
|
3
|
-
import createSdk from '@descope/web-js-sdk';
|
|
4
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
5
|
-
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
6
|
-
import mocked = jest.mocked;
|
|
7
|
-
|
|
8
|
-
jest.mock('@descope/web-js-sdk');
|
|
9
|
-
//Mock DescopeAuditManagementWidget
|
|
10
|
-
jest.mock('@descope/audit-management-widget', () => {
|
|
11
|
-
return jest.fn(() => {
|
|
12
|
-
// Create a mock DOM element
|
|
13
|
-
return document.createElement('descope-audit-management-widget');
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('DescopeAuditManagementComponent', () => {
|
|
18
|
-
let component: AuditManagementComponent;
|
|
19
|
-
let fixture: ComponentFixture<AuditManagementComponent>;
|
|
20
|
-
let mockedCreateSdk: jest.Mock;
|
|
21
|
-
const onSessionTokenChangeSpy = jest.fn();
|
|
22
|
-
const onAuditChangeSpy = jest.fn();
|
|
23
|
-
const afterRequestHooksSpy = jest.fn();
|
|
24
|
-
const mockConfig: DescopeAuthConfig = {
|
|
25
|
-
projectId: 'someProject'
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
mockedCreateSdk = mocked(createSdk);
|
|
30
|
-
|
|
31
|
-
mockedCreateSdk.mockReturnValue({
|
|
32
|
-
onSessionTokenChange: onSessionTokenChangeSpy,
|
|
33
|
-
onAuditChange: onAuditChangeSpy,
|
|
34
|
-
httpClient: {
|
|
35
|
-
hooks: {
|
|
36
|
-
afterRequest: afterRequestHooksSpy
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
TestBed.configureTestingModule({
|
|
42
|
-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
43
|
-
providers: [
|
|
44
|
-
DescopeAuthConfig,
|
|
45
|
-
{ provide: DescopeAuthConfig, useValue: mockConfig }
|
|
46
|
-
]
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
fixture = TestBed.createComponent(AuditManagementComponent);
|
|
50
|
-
component = fixture.componentInstance;
|
|
51
|
-
component.projectId = '123';
|
|
52
|
-
component.tenant = 'tenant-1';
|
|
53
|
-
component.widgetId = 'widget-1';
|
|
54
|
-
component.logger = {
|
|
55
|
-
info: jest.fn(),
|
|
56
|
-
error: jest.fn(),
|
|
57
|
-
warn: jest.fn(),
|
|
58
|
-
debug: jest.fn()
|
|
59
|
-
};
|
|
60
|
-
fixture.detectChanges();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should create', () => {
|
|
64
|
-
expect(component).toBeTruthy();
|
|
65
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
66
|
-
const webComponentHtml = html.querySelector(
|
|
67
|
-
'descope-audit-management-widget'
|
|
68
|
-
);
|
|
69
|
-
expect(webComponentHtml).toBeDefined();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should correctly setup attributes based on inputs', () => {
|
|
73
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
74
|
-
const webComponentHtml = html.querySelector(
|
|
75
|
-
'descope-audit-management-widget'
|
|
76
|
-
)!;
|
|
77
|
-
expect(webComponentHtml.getAttribute('project-id')).toStrictEqual('123');
|
|
78
|
-
expect(webComponentHtml.getAttribute('tenant')).toStrictEqual('tenant-1');
|
|
79
|
-
expect(webComponentHtml.getAttribute('widget-id')).toStrictEqual(
|
|
80
|
-
'widget-1'
|
|
81
|
-
);
|
|
82
|
-
expect(webComponentHtml.getAttribute('logger')).toBeDefined();
|
|
83
|
-
});
|
|
84
|
-
});
|
package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Component, ElementRef, Input, OnChanges, OnInit } from '@angular/core';
|
|
2
|
-
import DescopeAuditManagementWidget from '@descope/audit-management-widget';
|
|
3
|
-
import { ILogger } from '@descope/web-component';
|
|
4
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
5
|
-
|
|
6
|
-
@Component({
|
|
7
|
-
selector: 'audit-management[tenant]',
|
|
8
|
-
standalone: true,
|
|
9
|
-
template: ''
|
|
10
|
-
})
|
|
11
|
-
export class AuditManagementComponent implements OnInit, OnChanges {
|
|
12
|
-
projectId: string;
|
|
13
|
-
baseUrl?: string;
|
|
14
|
-
baseStaticUrl?: string;
|
|
15
|
-
@Input() tenant: string;
|
|
16
|
-
@Input() widgetId: string;
|
|
17
|
-
|
|
18
|
-
@Input() theme: 'light' | 'dark' | 'os';
|
|
19
|
-
@Input() debug: boolean;
|
|
20
|
-
@Input() logger: ILogger;
|
|
21
|
-
|
|
22
|
-
private readonly webComponent = new DescopeAuditManagementWidget();
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
private elementRef: ElementRef,
|
|
26
|
-
descopeConfig: DescopeAuthConfig
|
|
27
|
-
) {
|
|
28
|
-
this.projectId = descopeConfig.projectId;
|
|
29
|
-
this.baseUrl = descopeConfig.baseUrl;
|
|
30
|
-
this.baseStaticUrl = descopeConfig.baseStaticUrl;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ngOnInit() {
|
|
34
|
-
this.setupWebComponent();
|
|
35
|
-
this.elementRef.nativeElement.appendChild(this.webComponent);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
ngOnChanges(): void {
|
|
39
|
-
this.setupWebComponent();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private setupWebComponent() {
|
|
43
|
-
this.webComponent.setAttribute('project-id', this.projectId);
|
|
44
|
-
this.webComponent.setAttribute('tenant', this.tenant);
|
|
45
|
-
this.webComponent.setAttribute('widget-id', this.widgetId);
|
|
46
|
-
if (this.baseUrl) {
|
|
47
|
-
this.webComponent.setAttribute('base-url', this.baseUrl);
|
|
48
|
-
}
|
|
49
|
-
if (this.baseStaticUrl) {
|
|
50
|
-
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
|
|
51
|
-
}
|
|
52
|
-
if (this.theme) {
|
|
53
|
-
this.webComponent.setAttribute('theme', this.theme);
|
|
54
|
-
}
|
|
55
|
-
if (this.debug) {
|
|
56
|
-
this.webComponent.setAttribute('debug', this.debug.toString());
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.logger) {
|
|
60
|
-
(this.webComponent as any).logger = this.logger;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
import { default as DescopeWC } from '@descope/web-component';
|
|
3
|
-
import { DescopeComponent } from './descope.component';
|
|
4
|
-
import createSdk from '@descope/web-js-sdk';
|
|
5
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
6
|
-
import { CUSTOM_ELEMENTS_SCHEMA, EventEmitter } from '@angular/core';
|
|
7
|
-
import mocked = jest.mocked;
|
|
8
|
-
|
|
9
|
-
jest.mock('@descope/web-js-sdk');
|
|
10
|
-
//Mock DescopeWebComponent
|
|
11
|
-
jest.mock('@descope/web-component', () => {
|
|
12
|
-
return jest.fn(() => {
|
|
13
|
-
// Create a mock DOM element
|
|
14
|
-
return document.createElement('descope-wc');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('DescopeComponent', () => {
|
|
19
|
-
let component: DescopeComponent;
|
|
20
|
-
let fixture: ComponentFixture<DescopeComponent>;
|
|
21
|
-
let mockedCreateSdk: jest.Mock;
|
|
22
|
-
const onSessionTokenChangeSpy = jest.fn();
|
|
23
|
-
const onUserChangeSpy = jest.fn();
|
|
24
|
-
const afterRequestHooksSpy = jest.fn();
|
|
25
|
-
const mockConfig: DescopeAuthConfig = {
|
|
26
|
-
projectId: 'someProject'
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
mockedCreateSdk = mocked(createSdk);
|
|
31
|
-
|
|
32
|
-
mockedCreateSdk.mockReturnValue({
|
|
33
|
-
onSessionTokenChange: onSessionTokenChangeSpy,
|
|
34
|
-
onUserChange: onUserChangeSpy,
|
|
35
|
-
httpClient: {
|
|
36
|
-
hooks: {
|
|
37
|
-
afterRequest: afterRequestHooksSpy
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
TestBed.configureTestingModule({
|
|
43
|
-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
44
|
-
providers: [
|
|
45
|
-
DescopeAuthConfig,
|
|
46
|
-
{ provide: DescopeAuthConfig, useValue: mockConfig }
|
|
47
|
-
]
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
fixture = TestBed.createComponent(DescopeComponent);
|
|
51
|
-
component = fixture.componentInstance;
|
|
52
|
-
component.projectId = '123';
|
|
53
|
-
component.flowId = 'sign-in';
|
|
54
|
-
component.locale = 'en-US';
|
|
55
|
-
component.success = new EventEmitter<CustomEvent>();
|
|
56
|
-
component.error = new EventEmitter<CustomEvent>();
|
|
57
|
-
component.logger = {
|
|
58
|
-
info: jest.fn(),
|
|
59
|
-
error: jest.fn(),
|
|
60
|
-
warn: jest.fn(),
|
|
61
|
-
debug: jest.fn()
|
|
62
|
-
};
|
|
63
|
-
component.errorTransformer = jest.fn();
|
|
64
|
-
component.client = {};
|
|
65
|
-
component.form = {};
|
|
66
|
-
component.storeLastAuthenticatedUser = true;
|
|
67
|
-
fixture.detectChanges();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should create', () => {
|
|
71
|
-
expect(component).toBeTruthy();
|
|
72
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
73
|
-
const webComponentHtml = html.querySelector('descope-wc');
|
|
74
|
-
expect(webComponentHtml).toBeDefined();
|
|
75
|
-
|
|
76
|
-
expect(DescopeWC.sdkConfigOverrides).toEqual({
|
|
77
|
-
baseHeaders: {
|
|
78
|
-
'x-descope-sdk-name': 'angular',
|
|
79
|
-
'x-descope-sdk-version': expect.stringMatching(/^\d+\.\d+\.\d+$/)
|
|
80
|
-
},
|
|
81
|
-
persistTokens: false,
|
|
82
|
-
hooks: {
|
|
83
|
-
beforeRequest: undefined
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should correctly setup attributes based on inputs', () => {
|
|
89
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
90
|
-
const webComponentHtml = html.querySelector('descope-wc')!;
|
|
91
|
-
expect(webComponentHtml.getAttribute('project-id')).toStrictEqual('123');
|
|
92
|
-
expect(webComponentHtml.getAttribute('flow-id')).toStrictEqual('sign-in');
|
|
93
|
-
expect(webComponentHtml.getAttribute('locale')).toStrictEqual('en-US');
|
|
94
|
-
expect(webComponentHtml.getAttribute('logger')).toBeDefined();
|
|
95
|
-
expect(webComponentHtml.getAttribute('error-transformer')).toBeDefined();
|
|
96
|
-
expect(webComponentHtml.getAttribute('redirect-url')).toBeNull();
|
|
97
|
-
expect(
|
|
98
|
-
webComponentHtml?.getAttribute('store-last-authenticated-user')
|
|
99
|
-
).toEqual('true');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should emit success when web component emits success', () => {
|
|
103
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
104
|
-
const webComponentHtml = html.querySelector('descope-wc')!;
|
|
105
|
-
|
|
106
|
-
const event = {
|
|
107
|
-
detail: { user: { name: 'user1' }, sessionJwt: 'session1' }
|
|
108
|
-
};
|
|
109
|
-
component.success.subscribe((e) => {
|
|
110
|
-
expect(afterRequestHooksSpy).toHaveBeenCalled();
|
|
111
|
-
expect(e.detail).toHaveBeenCalledWith(event.detail);
|
|
112
|
-
});
|
|
113
|
-
webComponentHtml.dispatchEvent(new CustomEvent('success', event));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should emit error when web component emits error', () => {
|
|
117
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
118
|
-
const webComponentHtml = html.querySelector('descope-wc')!;
|
|
119
|
-
|
|
120
|
-
const event = {
|
|
121
|
-
detail: {
|
|
122
|
-
errorCode: 'someError',
|
|
123
|
-
errorDescription: 'someErrorDescription'
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
component.error.subscribe((e) => {
|
|
127
|
-
expect(e.detail).toEqual(event.detail);
|
|
128
|
-
});
|
|
129
|
-
webComponentHtml.dispatchEvent(new CustomEvent('error', event));
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should emit ready when web component emits ready', () => {
|
|
133
|
-
const spy = jest.spyOn(component.ready, 'emit');
|
|
134
|
-
|
|
135
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
136
|
-
const webComponentHtml = html.querySelector('descope-wc')!;
|
|
137
|
-
|
|
138
|
-
webComponentHtml.dispatchEvent(new CustomEvent('ready', {}));
|
|
139
|
-
|
|
140
|
-
expect(spy).toHaveBeenCalled();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Component,
|
|
3
|
-
ElementRef,
|
|
4
|
-
EventEmitter,
|
|
5
|
-
Input,
|
|
6
|
-
OnChanges,
|
|
7
|
-
OnInit,
|
|
8
|
-
Output
|
|
9
|
-
} from '@angular/core';
|
|
10
|
-
import DescopeWebComponent from '@descope/web-component';
|
|
11
|
-
import DescopeWc, { ILogger } from '@descope/web-component';
|
|
12
|
-
import { DescopeAuthService } from '../../services/descope-auth.service';
|
|
13
|
-
import { from } from 'rxjs';
|
|
14
|
-
import { baseHeaders } from '../../utils/constants';
|
|
15
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
16
|
-
|
|
17
|
-
@Component({
|
|
18
|
-
selector: 'descope[flowId]',
|
|
19
|
-
standalone: true,
|
|
20
|
-
template: ''
|
|
21
|
-
})
|
|
22
|
-
export class DescopeComponent implements OnInit, OnChanges {
|
|
23
|
-
projectId: string;
|
|
24
|
-
baseUrl?: string;
|
|
25
|
-
baseStaticUrl?: string;
|
|
26
|
-
storeLastAuthenticatedUser?: boolean;
|
|
27
|
-
@Input() flowId: string;
|
|
28
|
-
|
|
29
|
-
@Input() locale: string;
|
|
30
|
-
@Input() theme: 'light' | 'dark' | 'os';
|
|
31
|
-
@Input() tenant: string;
|
|
32
|
-
@Input() telemetryKey: string;
|
|
33
|
-
@Input() redirectUrl: string;
|
|
34
|
-
@Input() autoFocus: true | false | 'skipFirstScreen';
|
|
35
|
-
|
|
36
|
-
@Input() debug: boolean;
|
|
37
|
-
@Input() errorTransformer: (error: { text: string; type: string }) => string;
|
|
38
|
-
@Input() client: Record<string, any>;
|
|
39
|
-
@Input() form: Record<string, any>;
|
|
40
|
-
@Input() logger: ILogger;
|
|
41
|
-
|
|
42
|
-
@Output() success: EventEmitter<CustomEvent> =
|
|
43
|
-
new EventEmitter<CustomEvent>();
|
|
44
|
-
@Output() error: EventEmitter<CustomEvent> = new EventEmitter<CustomEvent>();
|
|
45
|
-
@Output() ready: EventEmitter<void> = new EventEmitter<void>();
|
|
46
|
-
|
|
47
|
-
private readonly webComponent: DescopeWebComponent =
|
|
48
|
-
new DescopeWebComponent();
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
private elementRef: ElementRef,
|
|
52
|
-
private authService: DescopeAuthService,
|
|
53
|
-
descopeConfig: DescopeAuthConfig
|
|
54
|
-
) {
|
|
55
|
-
this.projectId = descopeConfig.projectId;
|
|
56
|
-
this.baseUrl = descopeConfig.baseUrl;
|
|
57
|
-
this.baseStaticUrl = descopeConfig.baseStaticUrl;
|
|
58
|
-
this.storeLastAuthenticatedUser = descopeConfig.storeLastAuthenticatedUser;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
ngOnInit() {
|
|
62
|
-
const sdk = this.authService.descopeSdk; // Capture the class context in a variable
|
|
63
|
-
DescopeWc.sdkConfigOverrides = {
|
|
64
|
-
// Overrides the web-component's base headers to indicate usage via the React SDK
|
|
65
|
-
baseHeaders,
|
|
66
|
-
// Disables token persistence within the web-component to delegate token management
|
|
67
|
-
// to the global SDK hooks. This ensures token handling aligns with the SDK's configuration,
|
|
68
|
-
// and web-component requests leverage the global SDK's beforeRequest hooks for consistency
|
|
69
|
-
persistTokens: false,
|
|
70
|
-
hooks: {
|
|
71
|
-
get beforeRequest() {
|
|
72
|
-
// Retrieves the beforeRequest hook from the global SDK, which is initialized
|
|
73
|
-
// within the AuthProvider using the desired configuration. This approach ensures
|
|
74
|
-
// the web-component utilizes the same beforeRequest hooks as the global SDK
|
|
75
|
-
return sdk.httpClient.hooks?.beforeRequest;
|
|
76
|
-
},
|
|
77
|
-
set beforeRequest(_) {
|
|
78
|
-
// The empty setter prevents runtime errors when attempts are made to assign a value to 'beforeRequest'.
|
|
79
|
-
// JavaScript objects default to having both getters and setters
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
this.setupWebComponent();
|
|
84
|
-
this.elementRef.nativeElement.appendChild(this.webComponent);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
ngOnChanges(): void {
|
|
88
|
-
this.setupWebComponent();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private setupWebComponent() {
|
|
92
|
-
this.webComponent.setAttribute('project-id', this.projectId);
|
|
93
|
-
this.webComponent.setAttribute('flow-id', this.flowId);
|
|
94
|
-
|
|
95
|
-
if (this.baseUrl) {
|
|
96
|
-
this.webComponent.setAttribute('base-url', this.baseUrl);
|
|
97
|
-
}
|
|
98
|
-
if (this.baseStaticUrl) {
|
|
99
|
-
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
|
|
100
|
-
}
|
|
101
|
-
if (this.storeLastAuthenticatedUser) {
|
|
102
|
-
this.webComponent.setAttribute(
|
|
103
|
-
'store-last-authenticated-user',
|
|
104
|
-
this.storeLastAuthenticatedUser.toString()
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
if (this.locale) {
|
|
108
|
-
this.webComponent.setAttribute('locale', this.locale);
|
|
109
|
-
}
|
|
110
|
-
if (this.theme) {
|
|
111
|
-
this.webComponent.setAttribute('theme', this.theme);
|
|
112
|
-
}
|
|
113
|
-
if (this.tenant) {
|
|
114
|
-
this.webComponent.setAttribute('tenant', this.tenant);
|
|
115
|
-
}
|
|
116
|
-
if (this.telemetryKey) {
|
|
117
|
-
this.webComponent.setAttribute('telemetryKey', this.telemetryKey);
|
|
118
|
-
}
|
|
119
|
-
if (this.redirectUrl) {
|
|
120
|
-
this.webComponent.setAttribute('redirect-url', this.redirectUrl);
|
|
121
|
-
}
|
|
122
|
-
if (this.autoFocus) {
|
|
123
|
-
this.webComponent.setAttribute('auto-focus', this.autoFocus.toString());
|
|
124
|
-
}
|
|
125
|
-
if (this.debug) {
|
|
126
|
-
this.webComponent.setAttribute('debug', this.debug.toString());
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (this.errorTransformer) {
|
|
130
|
-
this.webComponent.errorTransformer = this.errorTransformer;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (this.client) {
|
|
134
|
-
this.webComponent.setAttribute('client', JSON.stringify(this.client));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (this.form) {
|
|
138
|
-
this.webComponent.setAttribute('form', JSON.stringify(this.form));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (this.logger) {
|
|
142
|
-
this.webComponent.logger = this.logger;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
this.webComponent.addEventListener('success', (e: Event) => {
|
|
146
|
-
from(
|
|
147
|
-
this.authService.descopeSdk.httpClient.hooks?.afterRequest!(
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
|
-
{} as any,
|
|
150
|
-
new Response(JSON.stringify((e as CustomEvent).detail))
|
|
151
|
-
) as Promise<unknown>
|
|
152
|
-
).subscribe(() => {
|
|
153
|
-
if (this.success) {
|
|
154
|
-
this.success?.emit(e as CustomEvent);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
if (this.error) {
|
|
160
|
-
this.webComponent.addEventListener('error', (e: Event) => {
|
|
161
|
-
this.error?.emit(e as CustomEvent);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (this.ready) {
|
|
166
|
-
this.webComponent.addEventListener('ready', () => {
|
|
167
|
-
this.ready?.emit();
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
package/projects/angular-sdk/src/lib/components/role-management/role-management.component.spec.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
import { RoleManagementComponent } from './role-management.component';
|
|
3
|
-
import createSdk from '@descope/web-js-sdk';
|
|
4
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
5
|
-
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
6
|
-
import mocked = jest.mocked;
|
|
7
|
-
|
|
8
|
-
jest.mock('@descope/web-js-sdk');
|
|
9
|
-
//Mock DescopeRoleManagementWidget
|
|
10
|
-
jest.mock('@descope/role-management-widget', () => {
|
|
11
|
-
return jest.fn(() => {
|
|
12
|
-
// Create a mock DOM element
|
|
13
|
-
return document.createElement('descope-role-management-widget');
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('DescopeRoleManagementComponent', () => {
|
|
18
|
-
let component: RoleManagementComponent;
|
|
19
|
-
let fixture: ComponentFixture<RoleManagementComponent>;
|
|
20
|
-
let mockedCreateSdk: jest.Mock;
|
|
21
|
-
const onSessionTokenChangeSpy = jest.fn();
|
|
22
|
-
const onRoleChangeSpy = jest.fn();
|
|
23
|
-
const afterRequestHooksSpy = jest.fn();
|
|
24
|
-
const mockConfig: DescopeAuthConfig = {
|
|
25
|
-
projectId: 'someProject'
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
mockedCreateSdk = mocked(createSdk);
|
|
30
|
-
|
|
31
|
-
mockedCreateSdk.mockReturnValue({
|
|
32
|
-
onSessionTokenChange: onSessionTokenChangeSpy,
|
|
33
|
-
onRoleChange: onRoleChangeSpy,
|
|
34
|
-
httpClient: {
|
|
35
|
-
hooks: {
|
|
36
|
-
afterRequest: afterRequestHooksSpy
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
TestBed.configureTestingModule({
|
|
42
|
-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
43
|
-
providers: [
|
|
44
|
-
DescopeAuthConfig,
|
|
45
|
-
{ provide: DescopeAuthConfig, useValue: mockConfig }
|
|
46
|
-
]
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
fixture = TestBed.createComponent(RoleManagementComponent);
|
|
50
|
-
component = fixture.componentInstance;
|
|
51
|
-
component.projectId = '123';
|
|
52
|
-
component.tenant = 'tenant-1';
|
|
53
|
-
component.widgetId = 'widget-1';
|
|
54
|
-
component.logger = {
|
|
55
|
-
info: jest.fn(),
|
|
56
|
-
error: jest.fn(),
|
|
57
|
-
warn: jest.fn(),
|
|
58
|
-
debug: jest.fn()
|
|
59
|
-
};
|
|
60
|
-
fixture.detectChanges();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should create', () => {
|
|
64
|
-
expect(component).toBeTruthy();
|
|
65
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
66
|
-
const webComponentHtml = html.querySelector(
|
|
67
|
-
'descope-role-management-widget'
|
|
68
|
-
);
|
|
69
|
-
expect(webComponentHtml).toBeDefined();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should correctly setup attributes based on inputs', () => {
|
|
73
|
-
const html: HTMLElement = fixture.nativeElement;
|
|
74
|
-
const webComponentHtml = html.querySelector(
|
|
75
|
-
'descope-role-management-widget'
|
|
76
|
-
)!;
|
|
77
|
-
expect(webComponentHtml.getAttribute('project-id')).toStrictEqual('123');
|
|
78
|
-
expect(webComponentHtml.getAttribute('tenant')).toStrictEqual('tenant-1');
|
|
79
|
-
expect(webComponentHtml.getAttribute('widget-id')).toStrictEqual(
|
|
80
|
-
'widget-1'
|
|
81
|
-
);
|
|
82
|
-
expect(webComponentHtml.getAttribute('logger')).toBeDefined();
|
|
83
|
-
});
|
|
84
|
-
});
|
package/projects/angular-sdk/src/lib/components/role-management/role-management.component.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Component, ElementRef, Input, OnChanges, OnInit } from '@angular/core';
|
|
2
|
-
import DescopeRoleManagementWidget from '@descope/role-management-widget';
|
|
3
|
-
import { ILogger } from '@descope/web-component';
|
|
4
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
5
|
-
|
|
6
|
-
@Component({
|
|
7
|
-
selector: 'role-management[tenant]',
|
|
8
|
-
standalone: true,
|
|
9
|
-
template: ''
|
|
10
|
-
})
|
|
11
|
-
export class RoleManagementComponent implements OnInit, OnChanges {
|
|
12
|
-
projectId: string;
|
|
13
|
-
baseUrl?: string;
|
|
14
|
-
baseStaticUrl?: string;
|
|
15
|
-
@Input() tenant: string;
|
|
16
|
-
@Input() widgetId: string;
|
|
17
|
-
|
|
18
|
-
@Input() theme: 'light' | 'dark' | 'os';
|
|
19
|
-
@Input() debug: boolean;
|
|
20
|
-
@Input() logger: ILogger;
|
|
21
|
-
|
|
22
|
-
private readonly webComponent = new DescopeRoleManagementWidget();
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
private elementRef: ElementRef,
|
|
26
|
-
descopeConfig: DescopeAuthConfig
|
|
27
|
-
) {
|
|
28
|
-
this.projectId = descopeConfig.projectId;
|
|
29
|
-
this.baseUrl = descopeConfig.baseUrl;
|
|
30
|
-
this.baseStaticUrl = descopeConfig.baseStaticUrl;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ngOnInit() {
|
|
34
|
-
this.setupWebComponent();
|
|
35
|
-
this.elementRef.nativeElement.appendChild(this.webComponent);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
ngOnChanges(): void {
|
|
39
|
-
this.setupWebComponent();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private setupWebComponent() {
|
|
43
|
-
this.webComponent.setAttribute('project-id', this.projectId);
|
|
44
|
-
this.webComponent.setAttribute('tenant', this.tenant);
|
|
45
|
-
this.webComponent.setAttribute('widget-id', this.widgetId);
|
|
46
|
-
if (this.baseUrl) {
|
|
47
|
-
this.webComponent.setAttribute('base-url', this.baseUrl);
|
|
48
|
-
}
|
|
49
|
-
if (this.baseStaticUrl) {
|
|
50
|
-
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
|
|
51
|
-
}
|
|
52
|
-
if (this.theme) {
|
|
53
|
-
this.webComponent.setAttribute('theme', this.theme);
|
|
54
|
-
}
|
|
55
|
-
if (this.debug) {
|
|
56
|
-
this.webComponent.setAttribute('debug', this.debug.toString());
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.logger) {
|
|
60
|
-
(this.webComponent as any).logger = this.logger;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<descope
|
|
2
|
-
(success)="success.emit($event)"
|
|
3
|
-
(error)="error.emit($event)"
|
|
4
|
-
flowId="sign-in"
|
|
5
|
-
[locale]="locale"
|
|
6
|
-
[theme]="theme"
|
|
7
|
-
[tenant]="tenant"
|
|
8
|
-
[telemetryKey]="telemetryKey"
|
|
9
|
-
[redirectUrl]="redirectUrl"
|
|
10
|
-
[autoFocus]="autoFocus"
|
|
11
|
-
[debug]="debug"
|
|
12
|
-
[errorTransformer]="errorTransformer"
|
|
13
|
-
[client]="client"
|
|
14
|
-
[form]="form"
|
|
15
|
-
[logger]="logger"
|
|
16
|
-
>
|
|
17
|
-
</descope>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
import { SignInFlowComponent } from './sign-in-flow.component';
|
|
3
|
-
import { ngMocks } from 'ng-mocks';
|
|
4
|
-
import { DescopeComponent } from '../descope/descope.component';
|
|
5
|
-
import { DescopeAuthConfig } from '../../types/types';
|
|
6
|
-
import createSdk from '@descope/web-js-sdk';
|
|
7
|
-
import mocked = jest.mocked;
|
|
8
|
-
|
|
9
|
-
jest.mock('@descope/web-js-sdk');
|
|
10
|
-
jest.mock('@descope/web-component', () => {
|
|
11
|
-
return jest.fn(() => {
|
|
12
|
-
// Create a mock DOM element
|
|
13
|
-
return document.createElement('descope-wc');
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('SignInFlowComponent', () => {
|
|
18
|
-
let component: SignInFlowComponent;
|
|
19
|
-
let fixture: ComponentFixture<SignInFlowComponent>;
|
|
20
|
-
let mockedCreateSdk: jest.Mock;
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
mockedCreateSdk = mocked(createSdk);
|
|
24
|
-
|
|
25
|
-
mockedCreateSdk.mockReturnValue({
|
|
26
|
-
onSessionTokenChange: jest.fn(),
|
|
27
|
-
onUserChange: jest.fn()
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
TestBed.configureTestingModule({
|
|
31
|
-
providers: [
|
|
32
|
-
DescopeAuthConfig,
|
|
33
|
-
{
|
|
34
|
-
provide: DescopeAuthConfig,
|
|
35
|
-
useValue: {
|
|
36
|
-
projectId: 'someProject'
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
fixture = TestBed.createComponent(SignInFlowComponent);
|
|
43
|
-
component = fixture.componentInstance;
|
|
44
|
-
fixture.detectChanges();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should create and be correctly configured', () => {
|
|
48
|
-
expect(component).toBeTruthy();
|
|
49
|
-
const mockComponent =
|
|
50
|
-
ngMocks.find<DescopeComponent>('[flowId=sign-in]').componentInstance;
|
|
51
|
-
expect(mockComponent.flowId).toStrictEqual('sign-in');
|
|
52
|
-
});
|
|
53
|
-
});
|