@descope/angular-sdk 0.0.0-next-a14bbb42-20231227 → 0.0.0-next-32627c0f-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 (31) hide show
  1. package/package.json +16 -7
  2. package/environment.d.ts +0 -3
  3. package/esm2022/descope-angular-sdk.mjs +0 -5
  4. package/esm2022/environment.mjs +0 -4
  5. package/esm2022/lib/components/descope/descope.component.mjs +0 -106
  6. package/esm2022/lib/components/sign-in-flow/sign-in-flow.component.mjs +0 -40
  7. package/esm2022/lib/components/sign-up-flow/sign-up-flow.component.mjs +0 -40
  8. package/esm2022/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.mjs +0 -40
  9. package/esm2022/lib/descope-auth.module.mjs +0 -52
  10. package/esm2022/lib/services/descope-auth.guard.mjs +0 -15
  11. package/esm2022/lib/services/descope-auth.service.mjs +0 -139
  12. package/esm2022/lib/services/descope.interceptor.mjs +0 -51
  13. package/esm2022/lib/types/types.mjs +0 -6
  14. package/esm2022/lib/utils/constants.mjs +0 -7
  15. package/esm2022/lib/utils/helpers.mjs +0 -27
  16. package/esm2022/public-api.mjs +0 -13
  17. package/fesm2022/descope-angular-sdk.mjs +0 -500
  18. package/fesm2022/descope-angular-sdk.mjs.map +0 -1
  19. package/index.d.ts +0 -5
  20. package/lib/components/descope/descope.component.d.ts +0 -32
  21. package/lib/components/sign-in-flow/sign-in-flow.component.d.ts +0 -24
  22. package/lib/components/sign-up-flow/sign-up-flow.component.d.ts +0 -24
  23. package/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.d.ts +0 -24
  24. package/lib/descope-auth.module.d.ts +0 -14
  25. package/lib/services/descope-auth.guard.d.ts +0 -2
  26. package/lib/services/descope-auth.service.d.ts +0 -38
  27. package/lib/services/descope.interceptor.d.ts +0 -2
  28. package/lib/types/types.d.ts +0 -8
  29. package/lib/utils/constants.d.ts +0 -5
  30. package/lib/utils/helpers.d.ts +0 -5
  31. package/public-api.d.ts +0 -9
@@ -1,6 +0,0 @@
1
- export class DescopeAuthConfig {
2
- constructor() {
3
- this.projectId = '';
4
- }
5
- }
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9hbmd1bGFyLXNkay9zcmMvbGliL3R5cGVzL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE1BQU0sT0FBTyxpQkFBaUI7SUFBOUI7UUFDQyxjQUFTLEdBQUcsRUFBRSxDQUFDO0lBSWhCLENBQUM7Q0FBQSIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IElMb2dnZXIgfSBmcm9tICdAZGVzY29wZS93ZWItY29tcG9uZW50JztcblxuZXhwb3J0IGNsYXNzIERlc2NvcGVBdXRoQ29uZmlnIHtcblx0cHJvamVjdElkID0gJyc7XG5cdGJhc2VVcmw/OiBzdHJpbmc7XG5cdHNlc3Npb25Ub2tlblZpYUNvb2tpZT86IGJvb2xlYW47XG5cdHBhdGhzVG9JbnRlcmNlcHQ/OiBzdHJpbmdbXTtcbn1cblxuZXhwb3J0IHR5cGUgeyBJTG9nZ2VyIH07XG4iXX0=
@@ -1,7 +0,0 @@
1
- import { environment } from '../../environment';
2
- export const baseHeaders = {
3
- 'x-descope-sdk-name': 'angular',
4
- 'x-descope-sdk-version': environment.buildVersion
5
- };
6
- export const isBrowser = () => typeof window !== 'undefined';
7
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvYW5ndWxhci1zZGsvc3JjL2xpYi91dGlscy9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWhELE1BQU0sQ0FBQyxNQUFNLFdBQVcsR0FBRztJQUMxQixvQkFBb0IsRUFBRSxTQUFTO0lBQy9CLHVCQUF1QixFQUFFLFdBQVcsQ0FBQyxZQUFZO0NBQ2pELENBQUM7QUFFRixNQUFNLENBQUMsTUFBTSxTQUFTLEdBQUcsR0FBRyxFQUFFLENBQUMsT0FBTyxNQUFNLEtBQUssV0FBVyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgZW52aXJvbm1lbnQgfSBmcm9tICcuLi8uLi9lbnZpcm9ubWVudCc7XG5cbmV4cG9ydCBjb25zdCBiYXNlSGVhZGVycyA9IHtcblx0J3gtZGVzY29wZS1zZGstbmFtZSc6ICdhbmd1bGFyJyxcblx0J3gtZGVzY29wZS1zZGstdmVyc2lvbic6IGVudmlyb25tZW50LmJ1aWxkVmVyc2lvblxufTtcblxuZXhwb3J0IGNvbnN0IGlzQnJvd3NlciA9ICgpID0+IHR5cGVvZiB3aW5kb3cgIT09ICd1bmRlZmluZWQnO1xuIl19
@@ -1,27 +0,0 @@
1
- import { from } from 'rxjs';
2
- export function observabilify(value) {
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- const observableValue = {};
5
- for (const key in value) {
6
- if (typeof value[key] === 'function') {
7
- const fn = value[key];
8
- observableValue[key] = (...args) => {
9
- const fnResult = fn(...args);
10
- if (fnResult instanceof Promise) {
11
- return from(fnResult);
12
- }
13
- else {
14
- return fnResult;
15
- }
16
- };
17
- }
18
- else if (typeof value[key] === 'object' && value[key] !== null) {
19
- observableValue[key] = observabilify(value[key]);
20
- }
21
- else {
22
- observableValue[key] = value[key];
23
- }
24
- }
25
- return observableValue;
26
- }
27
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2V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x0ID0gZm4oLi4uYXJncyk7XG5cdFx0XHRcdGlmIChmblJlc3VsdCBpbnN0YW5jZW9mIFByb21pc2UpIHtcblx0XHRcdFx0XHRyZXR1cm4gZnJvbShmblJlc3VsdCk7XG5cdFx0XHRcdH0gZWxzZSB7XG5cdFx0XHRcdFx0cmV0dXJuIGZuUmVzdWx0O1xuXHRcdFx0XHR9XG5cdFx0XHR9O1xuXHRcdH0gZWxzZSBpZiAodHlwZW9mIHZhbHVlW2tleV0gPT09ICdvYmplY3QnICYmIHZhbHVlW2tleV0gIT09IG51bGwpIHtcblx0XHRcdG9ic2VydmFibGVWYWx1ZVtrZXldID0gb2JzZXJ2YWJpbGlmeSh2YWx1ZVtrZXldKTtcblx0XHR9IGVsc2Uge1xuXHRcdFx0b2JzZXJ2YWJsZVZhbHVlW2tleV0gPSB2YWx1ZVtrZXldO1xuXHRcdH1cblx0fVxuXG5cdHJldHVybiBvYnNlcnZhYmxlVmFsdWUgYXMgT2JzZXJ2YWJsZWZpZWQ8VD47XG59XG4iXX0=
@@ -1,13 +0,0 @@
1
- /*
2
- * Public API Surface of angular-sdk
3
- */
4
- export * from './lib/services/descope-auth.service';
5
- export * from './lib/services/descope-auth.guard';
6
- export * from './lib/services/descope.interceptor';
7
- export * from './lib/descope-auth.module';
8
- export * from './lib/components/descope/descope.component';
9
- export * from './lib/components/sign-in-flow/sign-in-flow.component';
10
- export * from './lib/components/sign-up-flow/sign-up-flow.component';
11
- export * from './lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component';
12
- export * from './lib/types/types';
13
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3Byb2plY3RzL2FuZ3VsYXItc2RrL3NyYy9wdWJsaWMtYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYy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@angular/core';
2
- import { Injectable, inject, EventEmitter, Component, Input, Output, NgModule, CUSTOM_ELEMENTS_SCHEMA, Optional, SkipSelf } from '@angular/core';
3
- import createSdk from '@descope/web-js-sdk';
4
- import { from, BehaviorSubject, tap, finalize, of, throwError } from 'rxjs';
5
- import { Router } from '@angular/router';
6
- import { switchMap, catchError } from 'rxjs/operators';
7
- import DescopeWebComponent from '@descope/web-component';
8
-
9
- function observabilify(value) {
10
- /* eslint-disable @typescript-eslint/no-explicit-any */
11
- const observableValue = {};
12
- for (const key in value) {
13
- if (typeof value[key] === 'function') {
14
- const fn = value[key];
15
- observableValue[key] = (...args) => {
16
- const fnResult = fn(...args);
17
- if (fnResult instanceof Promise) {
18
- return from(fnResult);
19
- }
20
- else {
21
- return fnResult;
22
- }
23
- };
24
- }
25
- else if (typeof value[key] === 'object' && value[key] !== null) {
26
- observableValue[key] = observabilify(value[key]);
27
- }
28
- else {
29
- observableValue[key] = value[key];
30
- }
31
- }
32
- return observableValue;
33
- }
34
-
35
- const environment = {
36
- buildVersion: '0.0.0-next-a14bbb42-20231227'
37
- };
38
-
39
- const baseHeaders = {
40
- 'x-descope-sdk-name': 'angular',
41
- 'x-descope-sdk-version': environment.buildVersion
42
- };
43
- const isBrowser = () => typeof window !== 'undefined';
44
-
45
- class DescopeAuthConfig {
46
- constructor() {
47
- this.projectId = '';
48
- }
49
- }
50
-
51
- class DescopeAuthService {
52
- constructor(config) {
53
- this.descopeSdk = observabilify(createSdk({
54
- ...config,
55
- persistTokens: isBrowser(),
56
- autoRefresh: isBrowser(),
57
- baseHeaders
58
- }));
59
- this.sessionSubject = new BehaviorSubject({
60
- isAuthenticated: false,
61
- isSessionLoading: false,
62
- sessionToken: ''
63
- });
64
- this.session$ = this.sessionSubject.asObservable();
65
- this.userSubject = new BehaviorSubject({
66
- isUserLoading: false
67
- });
68
- this.user$ = this.userSubject.asObservable();
69
- this.descopeSdk.onSessionTokenChange(this.setSession.bind(this));
70
- this.descopeSdk.onUserChange(this.setUser.bind(this));
71
- }
72
- refreshSession() {
73
- const beforeRefreshSession = this.sessionSubject.value;
74
- this.sessionSubject.next({
75
- ...beforeRefreshSession,
76
- isSessionLoading: true
77
- });
78
- return this.descopeSdk.refresh().pipe(tap((data) => {
79
- const afterRequestSession = this.sessionSubject.value;
80
- if (data.ok && data.data) {
81
- this.sessionSubject.next({
82
- ...afterRequestSession,
83
- sessionToken: data.data.sessionJwt,
84
- isAuthenticated: !!data.data.sessionJwt
85
- });
86
- }
87
- else {
88
- this.sessionSubject.next({
89
- ...afterRequestSession,
90
- sessionToken: '',
91
- isAuthenticated: false
92
- });
93
- }
94
- }), finalize(() => {
95
- const afterRefreshSession = this.sessionSubject.value;
96
- this.sessionSubject.next({
97
- ...afterRefreshSession,
98
- isSessionLoading: false
99
- });
100
- }));
101
- }
102
- refreshUser() {
103
- const beforeRefreshUser = this.userSubject.value;
104
- this.userSubject.next({
105
- ...beforeRefreshUser,
106
- isUserLoading: true
107
- });
108
- return this.descopeSdk.me().pipe(tap((data) => {
109
- const afterRequestUser = this.userSubject.value;
110
- if (data.data) {
111
- this.userSubject.next({
112
- ...afterRequestUser,
113
- user: {
114
- ...data.data
115
- }
116
- });
117
- }
118
- }), finalize(() => {
119
- const afterRefreshUser = this.userSubject.value;
120
- this.userSubject.next({
121
- ...afterRefreshUser,
122
- isUserLoading: false
123
- });
124
- }));
125
- }
126
- getSessionToken() {
127
- if (isBrowser()) {
128
- return this.descopeSdk.getSessionToken();
129
- }
130
- console.warn('Get session token is not supported in SSR');
131
- return '';
132
- }
133
- getRefreshToken() {
134
- if (isBrowser()) {
135
- return this.descopeSdk.getRefreshToken();
136
- }
137
- this.descopeSdk.getJwtPermissions;
138
- console.warn('Get refresh token is not supported in SSR');
139
- return '';
140
- }
141
- getJwtPermissions(token = this.getSessionToken(), tenant) {
142
- if (token === null) {
143
- console.error('Could not get JWT Permissions - not authenticated');
144
- return [];
145
- }
146
- return this.descopeSdk.getJwtPermissions(token, tenant);
147
- }
148
- getJwtRoles(token = this.getSessionToken(), tenant) {
149
- if (token === null) {
150
- console.error('Could not get JWT Roles - not authenticated');
151
- return [];
152
- }
153
- return this.descopeSdk.getJwtRoles(token, tenant);
154
- }
155
- isAuthenticated() {
156
- return this.sessionSubject.value.isAuthenticated;
157
- }
158
- setSession(sessionToken) {
159
- const currentSession = this.sessionSubject.value;
160
- this.sessionSubject.next({
161
- sessionToken,
162
- isAuthenticated: !!sessionToken,
163
- isSessionLoading: currentSession.isSessionLoading
164
- });
165
- }
166
- setUser(user) {
167
- const currentUser = this.userSubject.value;
168
- this.userSubject.next({
169
- isUserLoading: currentUser.isUserLoading,
170
- user
171
- });
172
- }
173
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthService, deps: [{ token: DescopeAuthConfig }], target: i0.ɵɵFactoryTarget.Injectable }); }
174
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthService, providedIn: 'root' }); }
175
- }
176
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthService, decorators: [{
177
- type: Injectable,
178
- args: [{
179
- providedIn: 'root'
180
- }]
181
- }], ctorParameters: function () { return [{ type: DescopeAuthConfig }]; } });
182
-
183
- const descopeAuthGuard = (route) => {
184
- const authService = inject(DescopeAuthService);
185
- const router = inject(Router);
186
- const fallbackUrl = route.data['descopeFallbackUrl'];
187
- const isAuthenticated = authService.isAuthenticated();
188
- if (!isAuthenticated && !!fallbackUrl) {
189
- return from(router.navigate([fallbackUrl]));
190
- }
191
- return of(isAuthenticated);
192
- };
193
-
194
- const descopeInterceptor = (request, next) => {
195
- const config = inject(DescopeAuthConfig);
196
- const authService = inject(DescopeAuthService);
197
- function refreshAndRetry(request, next, error) {
198
- return authService.refreshSession().pipe(switchMap((refreshed) => {
199
- if (refreshed.ok && refreshed.data) {
200
- const requestWithRefreshedToken = addTokenToRequest(request, refreshed.data?.sessionJwt);
201
- return next(requestWithRefreshedToken);
202
- }
203
- else {
204
- return throwError(() => error ?? new Error('Could not refresh session!'));
205
- }
206
- }));
207
- }
208
- function shouldIntercept(request) {
209
- return ((config.pathsToIntercept?.length === 0 ||
210
- config.pathsToIntercept?.some((path) => request.url.includes(path))) ??
211
- true);
212
- }
213
- function addTokenToRequest(request, token) {
214
- return request.clone({
215
- setHeaders: {
216
- Authorization: `Bearer ${token}`
217
- }
218
- });
219
- }
220
- if (shouldIntercept(request)) {
221
- const token = authService.getSessionToken();
222
- if (!token) {
223
- return refreshAndRetry(request, next);
224
- }
225
- const requestWithToken = addTokenToRequest(request, token);
226
- return next(requestWithToken).pipe(catchError((error) => {
227
- if (error.status === 401 || error.status === 403) {
228
- return refreshAndRetry(request, next, error);
229
- }
230
- else {
231
- return throwError(() => error);
232
- }
233
- }));
234
- }
235
- else {
236
- return next(request);
237
- }
238
- };
239
-
240
- class DescopeComponent {
241
- constructor(elementRef, authService, descopeConfig) {
242
- this.elementRef = elementRef;
243
- this.authService = authService;
244
- this.success = new EventEmitter();
245
- this.error = new EventEmitter();
246
- this.webComponent = new DescopeWebComponent();
247
- this.projectId = descopeConfig.projectId;
248
- }
249
- ngOnInit() {
250
- DescopeWebComponent.sdkConfigOverrides = { baseHeaders };
251
- this.setupWebComponent();
252
- this.elementRef.nativeElement.appendChild(this.webComponent);
253
- }
254
- ngOnChanges() {
255
- this.setupWebComponent();
256
- }
257
- setupWebComponent() {
258
- this.webComponent.setAttribute('project-id', this.projectId);
259
- this.webComponent.setAttribute('flow-id', this.flowId);
260
- if (this.locale) {
261
- this.webComponent.setAttribute('locale', this.locale);
262
- }
263
- if (this.theme) {
264
- this.webComponent.setAttribute('theme', this.theme);
265
- }
266
- if (this.tenant) {
267
- this.webComponent.setAttribute('tenant', this.tenant);
268
- }
269
- if (this.telemetryKey) {
270
- this.webComponent.setAttribute('telemetryKey', this.telemetryKey);
271
- }
272
- if (this.redirectUrl) {
273
- this.webComponent.setAttribute('redirect-url', this.redirectUrl);
274
- }
275
- if (this.autoFocus) {
276
- this.webComponent.setAttribute('auto-focus', this.autoFocus.toString());
277
- }
278
- if (this.debug) {
279
- this.webComponent.setAttribute('debug', this.debug.toString());
280
- }
281
- if (this.errorTransformer) {
282
- this.webComponent.errorTransformer = this.errorTransformer;
283
- }
284
- if (this.logger) {
285
- this.webComponent.logger = this.logger;
286
- }
287
- if (this.success) {
288
- this.webComponent.addEventListener('success', (e) => {
289
- from(this.authService.descopeSdk.httpClient.hooks?.afterRequest(
290
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
291
- {}, new Response(JSON.stringify(e.detail)))).subscribe(() => {
292
- this.success?.emit();
293
- });
294
- });
295
- }
296
- if (this.error) {
297
- this.webComponent.addEventListener('error', () => {
298
- this.error?.emit();
299
- });
300
- }
301
- }
302
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeComponent, deps: [{ token: i0.ElementRef }, { token: DescopeAuthService }, { token: DescopeAuthConfig }], target: i0.ɵɵFactoryTarget.Component }); }
303
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.9", type: DescopeComponent, isStandalone: true, selector: "descope[flowId]", inputs: { flowId: "flowId", locale: "locale", theme: "theme", tenant: "tenant", telemetryKey: "telemetryKey", redirectUrl: "redirectUrl", autoFocus: "autoFocus", debug: "debug", errorTransformer: "errorTransformer", logger: "logger" }, outputs: { success: "success", error: "error" }, usesOnChanges: true, ngImport: i0, template: '', isInline: true }); }
304
- }
305
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeComponent, decorators: [{
306
- type: Component,
307
- args: [{
308
- selector: 'descope[flowId]',
309
- standalone: true,
310
- template: ''
311
- }]
312
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: DescopeAuthService }, { type: DescopeAuthConfig }]; }, propDecorators: { flowId: [{
313
- type: Input
314
- }], locale: [{
315
- type: Input
316
- }], theme: [{
317
- type: Input
318
- }], tenant: [{
319
- type: Input
320
- }], telemetryKey: [{
321
- type: Input
322
- }], redirectUrl: [{
323
- type: Input
324
- }], autoFocus: [{
325
- type: Input
326
- }], debug: [{
327
- type: Input
328
- }], errorTransformer: [{
329
- type: Input
330
- }], logger: [{
331
- type: Input
332
- }], success: [{
333
- type: Output
334
- }], error: [{
335
- type: Output
336
- }] } });
337
-
338
- class SignInFlowComponent {
339
- constructor(descopeConfig) {
340
- this.success = new EventEmitter();
341
- this.error = new EventEmitter();
342
- this.projectId = descopeConfig.projectId;
343
- }
344
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SignInFlowComponent, deps: [{ token: DescopeAuthConfig }], target: i0.ɵɵFactoryTarget.Component }); }
345
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.9", type: SignInFlowComponent, isStandalone: true, selector: "descope-sign-in-flow", inputs: { locale: "locale", theme: "theme", tenant: "tenant", telemetryKey: "telemetryKey", redirectUrl: "redirectUrl", autoFocus: "autoFocus", debug: "debug", errorTransformer: "errorTransformer", logger: "logger" }, outputs: { success: "success", error: "error" }, ngImport: i0, template: "<descope\n\t(success)=\"success.emit()\"\n\t(error)=\"error.emit()\"\n\tflowId=\"sign-in\"\n\t[locale]=\"locale\"\n\t[theme]=\"theme\"\n\t[tenant]=\"tenant\"\n\t[telemetryKey]=\"telemetryKey\"\n\t[redirectUrl]=\"redirectUrl\"\n\t[autoFocus]=\"autoFocus\"\n\t[debug]=\"debug\"\n\t[errorTransformer]=\"errorTransformer\"\n\t[logger]=\"logger\"\n>\n</descope>\n", dependencies: [{ kind: "component", type: DescopeComponent, selector: "descope[flowId]", inputs: ["flowId", "locale", "theme", "tenant", "telemetryKey", "redirectUrl", "autoFocus", "debug", "errorTransformer", "logger"], outputs: ["success", "error"] }] }); }
346
- }
347
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SignInFlowComponent, decorators: [{
348
- type: Component,
349
- args: [{ selector: 'descope-sign-in-flow', standalone: true, imports: [DescopeComponent], template: "<descope\n\t(success)=\"success.emit()\"\n\t(error)=\"error.emit()\"\n\tflowId=\"sign-in\"\n\t[locale]=\"locale\"\n\t[theme]=\"theme\"\n\t[tenant]=\"tenant\"\n\t[telemetryKey]=\"telemetryKey\"\n\t[redirectUrl]=\"redirectUrl\"\n\t[autoFocus]=\"autoFocus\"\n\t[debug]=\"debug\"\n\t[errorTransformer]=\"errorTransformer\"\n\t[logger]=\"logger\"\n>\n</descope>\n" }]
350
- }], ctorParameters: function () { return [{ type: DescopeAuthConfig }]; }, propDecorators: { locale: [{
351
- type: Input
352
- }], theme: [{
353
- type: Input
354
- }], tenant: [{
355
- type: Input
356
- }], telemetryKey: [{
357
- type: Input
358
- }], redirectUrl: [{
359
- type: Input
360
- }], autoFocus: [{
361
- type: Input
362
- }], debug: [{
363
- type: Input
364
- }], errorTransformer: [{
365
- type: Input
366
- }], logger: [{
367
- type: Input
368
- }], success: [{
369
- type: Output
370
- }], error: [{
371
- type: Output
372
- }] } });
373
-
374
- class SignUpFlowComponent {
375
- constructor(descopeConfig) {
376
- this.success = new EventEmitter();
377
- this.error = new EventEmitter();
378
- this.projectId = descopeConfig.projectId;
379
- }
380
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SignUpFlowComponent, deps: [{ token: DescopeAuthConfig }], target: i0.ɵɵFactoryTarget.Component }); }
381
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.9", type: SignUpFlowComponent, isStandalone: true, selector: "descope-sign-up-flow", inputs: { locale: "locale", theme: "theme", tenant: "tenant", telemetryKey: "telemetryKey", redirectUrl: "redirectUrl", autoFocus: "autoFocus", debug: "debug", errorTransformer: "errorTransformer", logger: "logger" }, outputs: { success: "success", error: "error" }, ngImport: i0, template: "<descope\n\t(success)=\"success.emit()\"\n\t(error)=\"error.emit()\"\n\tflowId=\"sign-up\"\n\t[locale]=\"locale\"\n\t[theme]=\"theme\"\n\t[tenant]=\"tenant\"\n\t[telemetryKey]=\"telemetryKey\"\n\t[redirectUrl]=\"redirectUrl\"\n\t[autoFocus]=\"autoFocus\"\n\t[debug]=\"debug\"\n\t[errorTransformer]=\"errorTransformer\"\n\t[logger]=\"logger\"\n>\n</descope>\n", dependencies: [{ kind: "component", type: DescopeComponent, selector: "descope[flowId]", inputs: ["flowId", "locale", "theme", "tenant", "telemetryKey", "redirectUrl", "autoFocus", "debug", "errorTransformer", "logger"], outputs: ["success", "error"] }] }); }
382
- }
383
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SignUpFlowComponent, decorators: [{
384
- type: Component,
385
- args: [{ selector: 'descope-sign-up-flow', standalone: true, imports: [DescopeComponent], template: "<descope\n\t(success)=\"success.emit()\"\n\t(error)=\"error.emit()\"\n\tflowId=\"sign-up\"\n\t[locale]=\"locale\"\n\t[theme]=\"theme\"\n\t[tenant]=\"tenant\"\n\t[telemetryKey]=\"telemetryKey\"\n\t[redirectUrl]=\"redirectUrl\"\n\t[autoFocus]=\"autoFocus\"\n\t[debug]=\"debug\"\n\t[errorTransformer]=\"errorTransformer\"\n\t[logger]=\"logger\"\n>\n</descope>\n" }]
386
- }], ctorParameters: function () { return [{ type: DescopeAuthConfig }]; }, propDecorators: { locale: [{
387
- type: Input
388
- }], theme: [{
389
- type: Input
390
- }], tenant: [{
391
- type: Input
392
- }], telemetryKey: [{
393
- type: Input
394
- }], redirectUrl: [{
395
- type: Input
396
- }], autoFocus: [{
397
- type: Input
398
- }], debug: [{
399
- type: Input
400
- }], errorTransformer: [{
401
- type: Input
402
- }], logger: [{
403
- type: Input
404
- }], success: [{
405
- type: Output
406
- }], error: [{
407
- type: Output
408
- }] } });
409
-
410
- class SignUpOrInFlowComponent {
411
- constructor(descopeConfig) {
412
- this.success = new EventEmitter();
413
- this.error = new EventEmitter();
414
- this.projectId = descopeConfig.projectId;
415
- }
416
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SignUpOrInFlowComponent, deps: [{ token: DescopeAuthConfig }], target: i0.ɵɵFactoryTarget.Component }); }
417
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.9", type: SignUpOrInFlowComponent, isStandalone: true, selector: "descope-sign-up-or-in-flow", inputs: { locale: "locale", theme: "theme", tenant: "tenant", telemetryKey: "telemetryKey", redirectUrl: "redirectUrl", autoFocus: "autoFocus", debug: "debug", errorTransformer: "errorTransformer", logger: "logger" }, outputs: { success: "success", error: "error" }, ngImport: i0, template: "<descope\n\t(success)=\"success.emit()\"\n\t(error)=\"error.emit()\"\n\tflowId=\"sign-up-or-in\"\n\t[locale]=\"locale\"\n\t[theme]=\"theme\"\n\t[tenant]=\"tenant\"\n\t[telemetryKey]=\"telemetryKey\"\n\t[redirectUrl]=\"redirectUrl\"\n\t[autoFocus]=\"autoFocus\"\n\t[debug]=\"debug\"\n\t[errorTransformer]=\"errorTransformer\"\n\t[logger]=\"logger\"\n>\n</descope>\n", dependencies: [{ kind: "component", type: DescopeComponent, selector: "descope[flowId]", inputs: ["flowId", "locale", "theme", "tenant", "telemetryKey", "redirectUrl", "autoFocus", "debug", "errorTransformer", "logger"], outputs: ["success", "error"] }] }); }
418
- }
419
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SignUpOrInFlowComponent, decorators: [{
420
- type: Component,
421
- args: [{ selector: 'descope-sign-up-or-in-flow', standalone: true, imports: [DescopeComponent], template: "<descope\n\t(success)=\"success.emit()\"\n\t(error)=\"error.emit()\"\n\tflowId=\"sign-up-or-in\"\n\t[locale]=\"locale\"\n\t[theme]=\"theme\"\n\t[tenant]=\"tenant\"\n\t[telemetryKey]=\"telemetryKey\"\n\t[redirectUrl]=\"redirectUrl\"\n\t[autoFocus]=\"autoFocus\"\n\t[debug]=\"debug\"\n\t[errorTransformer]=\"errorTransformer\"\n\t[logger]=\"logger\"\n>\n</descope>\n" }]
422
- }], ctorParameters: function () { return [{ type: DescopeAuthConfig }]; }, propDecorators: { locale: [{
423
- type: Input
424
- }], theme: [{
425
- type: Input
426
- }], tenant: [{
427
- type: Input
428
- }], telemetryKey: [{
429
- type: Input
430
- }], redirectUrl: [{
431
- type: Input
432
- }], autoFocus: [{
433
- type: Input
434
- }], debug: [{
435
- type: Input
436
- }], errorTransformer: [{
437
- type: Input
438
- }], logger: [{
439
- type: Input
440
- }], success: [{
441
- type: Output
442
- }], error: [{
443
- type: Output
444
- }] } });
445
-
446
- class DescopeAuthModule {
447
- constructor(parentModule) {
448
- if (parentModule) {
449
- throw new Error('DescopeAuthModule is already loaded. Import it only once');
450
- }
451
- }
452
- static forRoot(config) {
453
- return {
454
- ngModule: DescopeAuthModule,
455
- providers: [{ provide: DescopeAuthConfig, useValue: config }]
456
- };
457
- }
458
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthModule, deps: [{ token: DescopeAuthModule, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.NgModule }); }
459
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthModule, imports: [DescopeComponent,
460
- SignInFlowComponent,
461
- SignUpFlowComponent,
462
- SignUpOrInFlowComponent], exports: [DescopeComponent,
463
- SignInFlowComponent,
464
- SignUpFlowComponent,
465
- SignUpOrInFlowComponent] }); }
466
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthModule }); }
467
- }
468
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: DescopeAuthModule, decorators: [{
469
- type: NgModule,
470
- args: [{
471
- schemas: [CUSTOM_ELEMENTS_SCHEMA],
472
- imports: [
473
- DescopeComponent,
474
- SignInFlowComponent,
475
- SignUpFlowComponent,
476
- SignUpOrInFlowComponent
477
- ],
478
- exports: [
479
- DescopeComponent,
480
- SignInFlowComponent,
481
- SignUpFlowComponent,
482
- SignUpOrInFlowComponent
483
- ]
484
- }]
485
- }], ctorParameters: function () { return [{ type: DescopeAuthModule, decorators: [{
486
- type: Optional
487
- }, {
488
- type: SkipSelf
489
- }] }]; } });
490
-
491
- /*
492
- * Public API Surface of angular-sdk
493
- */
494
-
495
- /**
496
- * Generated bundle index. Do not edit.
497
- */
498
-
499
- export { DescopeAuthConfig, DescopeAuthModule, DescopeAuthService, DescopeComponent, SignInFlowComponent, SignUpFlowComponent, SignUpOrInFlowComponent, descopeAuthGuard, descopeInterceptor };
500
- //# sourceMappingURL=descope-angular-sdk.mjs.map