@cccteam/ccc-lib 0.0.23 → 0.0.24

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/README.md CHANGED
@@ -47,3 +47,7 @@ To run the library's tests, use the following command:
47
47
  ```bash
48
48
  ng test ccc-lib
49
49
  ```
50
+
51
+ ### Known Issues
52
+
53
+ - **Contentful Dependency**: The library currently has a hard dependency on `@contentful/rich-text-types` due to the `CustomTypes.ContentfulDocument` type definition in the resource metadata. This means consumers of the library must have this package installed, even if they are not using this custom type.
@@ -1,10 +1,18 @@
1
1
  import { inject } from '@angular/core';
2
+ import { Router } from '@angular/router';
2
3
  import { AuthService } from '@cccteam/ccc-lib/auth-service';
3
4
  import { BASE_URL, API_URL } from '@cccteam/ccc-lib/types';
4
5
  import { of } from 'rxjs';
5
6
  import { map, catchError } from 'rxjs/operators';
6
7
 
7
- const AuthenticationGuard = (route, routerState) => {
8
+ /**
9
+ * Route guard that protects routes using OIDC (OpenID Connect) authentication.
10
+ *
11
+ * If the user is not authenticated, they are redirected to the external OIDC
12
+ * login endpoint with the current URL encoded as a return URL parameter.
13
+ *
14
+ */
15
+ const OIDCAuthenticationGuard = (_, routerState) => {
8
16
  const authService = inject(AuthService);
9
17
  const baseUrl = inject(BASE_URL);
10
18
  const apiUrl = inject(API_URL);
@@ -28,10 +36,39 @@ const AuthenticationGuard = (route, routerState) => {
28
36
  return of(false);
29
37
  }));
30
38
  };
39
+ /**
40
+ * Route guard that protects routes using internal login-based authentication.
41
+ *
42
+ * If the user is not authenticated, they are redirected to the application's
43
+ * internal FRONTEND_LOGIN_PATH route. The attempted URL is stored in the AuthService so the
44
+ * user can be redirected back after successful login.
45
+ *
46
+ */
47
+ const LoginAuthenticationGuard = (_, routerState) => {
48
+ const router = inject(Router);
49
+ const authService = inject(AuthService);
50
+ const authenticate = () => {
51
+ authService.redirectUrl.set(routerState.url);
52
+ router.navigate([authService.loginRoute()]);
53
+ };
54
+ if (authService.authenticated()) {
55
+ return of(true);
56
+ }
57
+ return authService.checkUserSession().pipe(map((sessionInfo) => {
58
+ if (sessionInfo?.authenticated) {
59
+ return true;
60
+ }
61
+ authenticate();
62
+ return false;
63
+ }), catchError(() => {
64
+ authenticate();
65
+ return of(false);
66
+ }));
67
+ };
31
68
 
32
69
  /**
33
70
  * Generated bundle index. Do not edit.
34
71
  */
35
72
 
36
- export { AuthenticationGuard };
73
+ export { LoginAuthenticationGuard, OIDCAuthenticationGuard };
37
74
  //# sourceMappingURL=cccteam-ccc-lib-auth-authentication-guard.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cccteam-ccc-lib-auth-authentication-guard.mjs","sources":["../../../projects/ccc-lib/auth-authentication-guard/authentication.guard.ts","../../../projects/ccc-lib/auth-authentication-guard/cccteam-ccc-lib-auth-authentication-guard.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { API_URL, BASE_URL } from '@cccteam/ccc-lib/types';\nimport { Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nexport const AuthenticationGuard = (\n route: ActivatedRouteSnapshot,\n routerState: RouterStateSnapshot,\n): Observable<boolean> => {\n const authService = inject(AuthService);\n const baseUrl = inject(BASE_URL);\n const apiUrl = inject(API_URL);\n\n const authenticate = (): void => {\n const url = routerState.url;\n const absoluteUrl = baseUrl + (!url.toString().startsWith('/') ? '/' + url : url);\n const encodedUrl = encodeURIComponent(absoluteUrl);\n window.location.href = `${apiUrl}/user/login?returnUrl=${encodedUrl}`;\n };\n\n if (authService.authenticated()) {\n return of(true);\n }\n\n return authService.checkUserSession().pipe(\n map((sessionInfo) => {\n if (sessionInfo?.authenticated) {\n return true;\n }\n\n authenticate();\n return false;\n }),\n catchError(() => {\n authenticate();\n return of(false);\n }),\n );\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAOa,mBAAmB,GAAG,CACjC,KAA6B,EAC7B,WAAgC,KACT;AACvB,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACvC,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC;AAChC,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAE9B,MAAM,YAAY,GAAG,MAAW;AAC9B,QAAA,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG;QAC3B,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACjF,QAAA,MAAM,UAAU,GAAG,kBAAkB,CAAC,WAAW,CAAC;QAClD,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,MAAM,CAAA,sBAAA,EAAyB,UAAU,CAAA,CAAE;AACvE,IAAA,CAAC;AAED,IAAA,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE;AAC/B,QAAA,OAAO,EAAE,CAAC,IAAI,CAAC;IACjB;AAEA,IAAA,OAAO,WAAW,CAAC,gBAAgB,EAAE,CAAC,IAAI,CACxC,GAAG,CAAC,CAAC,WAAW,KAAI;AAClB,QAAA,IAAI,WAAW,EAAE,aAAa,EAAE;AAC9B,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,KAAK;AACd,IAAA,CAAC,CAAC,EACF,UAAU,CAAC,MAAK;AACd,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,EAAE,CAAC,KAAK,CAAC;IAClB,CAAC,CAAC,CACH;AACH;;ACxCA;;AAEG;;;;"}
1
+ {"version":3,"file":"cccteam-ccc-lib-auth-authentication-guard.mjs","sources":["../../../projects/ccc-lib/auth-authentication-guard/authentication.guard.ts","../../../projects/ccc-lib/auth-authentication-guard/cccteam-ccc-lib-auth-authentication-guard.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { API_URL, BASE_URL } from '@cccteam/ccc-lib/types';\nimport { Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\n/**\n * Route guard that protects routes using OIDC (OpenID Connect) authentication.\n *\n * If the user is not authenticated, they are redirected to the external OIDC\n * login endpoint with the current URL encoded as a return URL parameter.\n *\n */\nexport const OIDCAuthenticationGuard = (\n _: ActivatedRouteSnapshot,\n routerState: RouterStateSnapshot,\n): Observable<boolean> => {\n const authService = inject(AuthService);\n const baseUrl = inject(BASE_URL);\n const apiUrl = inject(API_URL);\n\n const authenticate = (): void => {\n const url = routerState.url;\n const absoluteUrl = baseUrl + (!url.toString().startsWith('/') ? '/' + url : url);\n const encodedUrl = encodeURIComponent(absoluteUrl);\n window.location.href = `${apiUrl}/user/login?returnUrl=${encodedUrl}`;\n };\n\n if (authService.authenticated()) {\n return of(true);\n }\n\n return authService.checkUserSession().pipe(\n map((sessionInfo) => {\n if (sessionInfo?.authenticated) {\n return true;\n }\n\n authenticate();\n return false;\n }),\n catchError(() => {\n authenticate();\n return of(false);\n }),\n );\n};\n\n/**\n * Route guard that protects routes using internal login-based authentication.\n *\n * If the user is not authenticated, they are redirected to the application's\n * internal FRONTEND_LOGIN_PATH route. The attempted URL is stored in the AuthService so the\n * user can be redirected back after successful login.\n *\n */\nexport const LoginAuthenticationGuard = (\n _: ActivatedRouteSnapshot,\n routerState: RouterStateSnapshot,\n): Observable<boolean> => {\n const router = inject(Router);\n const authService = inject(AuthService);\n\n const authenticate = (): void => {\n authService.redirectUrl.set(routerState.url);\n router.navigate([authService.loginRoute()]);\n };\n\n if (authService.authenticated()) {\n return of(true);\n }\n\n return authService.checkUserSession().pipe(\n map((sessionInfo) => {\n if (sessionInfo?.authenticated) {\n return true;\n }\n\n authenticate();\n return false;\n }),\n catchError(() => {\n authenticate();\n return of(false);\n }),\n );\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAOA;;;;;;AAMG;MACU,uBAAuB,GAAG,CACrC,CAAyB,EACzB,WAAgC,KACT;AACvB,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACvC,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC;AAChC,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAE9B,MAAM,YAAY,GAAG,MAAW;AAC9B,QAAA,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG;QAC3B,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACjF,QAAA,MAAM,UAAU,GAAG,kBAAkB,CAAC,WAAW,CAAC;QAClD,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,MAAM,CAAA,sBAAA,EAAyB,UAAU,CAAA,CAAE;AACvE,IAAA,CAAC;AAED,IAAA,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE;AAC/B,QAAA,OAAO,EAAE,CAAC,IAAI,CAAC;IACjB;AAEA,IAAA,OAAO,WAAW,CAAC,gBAAgB,EAAE,CAAC,IAAI,CACxC,GAAG,CAAC,CAAC,WAAW,KAAI;AAClB,QAAA,IAAI,WAAW,EAAE,aAAa,EAAE;AAC9B,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,KAAK;AACd,IAAA,CAAC,CAAC,EACF,UAAU,CAAC,MAAK;AACd,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,EAAE,CAAC,KAAK,CAAC;IAClB,CAAC,CAAC,CACH;AACH;AAEA;;;;;;;AAOG;MACU,wBAAwB,GAAG,CACtC,CAAyB,EACzB,WAAgC,KACT;AACvB,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAC7B,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IAEvC,MAAM,YAAY,GAAG,MAAW;QAC9B,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC;QAC5C,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC;AAC7C,IAAA,CAAC;AAED,IAAA,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE;AAC/B,QAAA,OAAO,EAAE,CAAC,IAAI,CAAC;IACjB;AAEA,IAAA,OAAO,WAAW,CAAC,gBAAgB,EAAE,CAAC,IAAI,CACxC,GAAG,CAAC,CAAC,WAAW,KAAI;AAClB,QAAA,IAAI,WAAW,EAAE,aAAa,EAAE;AAC9B,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,KAAK;AACd,IAAA,CAAC,CAAC,EACF,UAAU,CAAC,MAAK;AACd,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,EAAE,CAAC,KAAK,CAAC;IAClB,CAAC,CAAC,CACH;AACH;;ACvFA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@cccteam/ccc-lib",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git://github.com/cccteam/ccc-lib.git"
7
7
  },
8
8
  "peerDependencies": {
9
9
  "@angular/common": "^21.0.0",
10
- "@angular/core": "^21.0.0"
10
+ "@angular/core": "^21.0.0",
11
+ "@contentful/rich-text-types": "^17.2.5"
11
12
  },
12
13
  "dependencies": {
13
14
  "date-fns": "^4.1.0",
@@ -1,6 +1,22 @@
1
1
  import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
2
2
  import { Observable } from 'rxjs';
3
3
 
4
- declare const AuthenticationGuard: (route: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) => Observable<boolean>;
4
+ /**
5
+ * Route guard that protects routes using OIDC (OpenID Connect) authentication.
6
+ *
7
+ * If the user is not authenticated, they are redirected to the external OIDC
8
+ * login endpoint with the current URL encoded as a return URL parameter.
9
+ *
10
+ */
11
+ declare const OIDCAuthenticationGuard: (_: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) => Observable<boolean>;
12
+ /**
13
+ * Route guard that protects routes using internal login-based authentication.
14
+ *
15
+ * If the user is not authenticated, they are redirected to the application's
16
+ * internal FRONTEND_LOGIN_PATH route. The attempted URL is stored in the AuthService so the
17
+ * user can be redirected back after successful login.
18
+ *
19
+ */
20
+ declare const LoginAuthenticationGuard: (_: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) => Observable<boolean>;
5
21
 
6
- export { AuthenticationGuard };
22
+ export { LoginAuthenticationGuard, OIDCAuthenticationGuard };
@@ -1,6 +1,7 @@
1
1
  import * as _angular_core from '@angular/core';
2
2
  import { Type, InjectionToken } from '@angular/core';
3
3
  import { TooltipPosition } from '@angular/material/tooltip';
4
+ import { Document } from '@contentful/rich-text-types';
4
5
  import { ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms';
5
6
 
6
7
  type Brand<K, T> = K & {
@@ -20,7 +21,7 @@ interface PermissionScope {
20
21
  declare const ReadPermission: Permission;
21
22
  declare const UpdatePermission: Permission;
22
23
 
23
- type ValidDisplayTypes = 'boolean' | 'nullboolean' | 'number' | 'string' | 'date' | 'enumerated' | 'link' | 'uuid' | 'civildate' | 'string[]' | 'customtypes.document';
24
+ type ValidDisplayTypes = 'boolean' | 'nullboolean' | 'number' | 'string' | 'date' | 'enumerated' | 'link' | 'uuid' | 'civildate' | 'string[]' | 'customtypes.contentfuldocument';
24
25
  type ValidRPCTypes = ValidDisplayTypes | `${Exclude<ValidDisplayTypes, 'string[]'>}[]`;
25
26
  interface RPCFieldMeta {
26
27
  fieldName: string;
@@ -57,9 +58,7 @@ interface ResourceMeta {
57
58
  }
58
59
  type Meta = MethodMeta | ResourceMeta;
59
60
  declare namespace CustomTypes {
60
- interface Document {
61
- placeholder: string;
62
- }
61
+ type ContentfulDocument = Document;
63
62
  }
64
63
 
65
64
  declare const defaultEmptyFieldValue = "-";