@genesislcap/foundation-auth 14.71.1-auth-mf.16 → 14.71.1-auth-mf.18

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 (63) hide show
  1. package/README.md +22 -16
  2. package/dist/dts/index.d.ts +0 -1
  3. package/dist/dts/index.d.ts.map +1 -1
  4. package/dist/dts/machine/machine.d.ts +3 -1
  5. package/dist/dts/machine/machine.d.ts.map +1 -1
  6. package/dist/dts/main/config.d.ts +15 -53
  7. package/dist/dts/main/config.d.ts.map +1 -1
  8. package/dist/dts/routes/base.d.ts +3 -3
  9. package/dist/dts/routes/base.d.ts.map +1 -1
  10. package/dist/dts/routes/index.d.ts +2 -0
  11. package/dist/dts/routes/index.d.ts.map +1 -1
  12. package/dist/dts/routes/logout/logout.d.ts.map +1 -1
  13. package/dist/dts/routes/routing.d.ts +66 -0
  14. package/dist/dts/routes/routing.d.ts.map +1 -0
  15. package/dist/dts/routes/types.d.ts +17 -0
  16. package/dist/dts/routes/types.d.ts.map +1 -1
  17. package/dist/dts/routes/utils.d.ts +30 -0
  18. package/dist/dts/routes/utils.d.ts.map +1 -0
  19. package/dist/esm/index.js +0 -1
  20. package/dist/esm/machine/machine.js +14 -11
  21. package/dist/esm/main/config.js +9 -53
  22. package/dist/esm/routes/base.js +5 -6
  23. package/dist/esm/routes/index.js +2 -0
  24. package/dist/esm/routes/login/login.template.js +3 -3
  25. package/dist/esm/routes/logout/logout.js +1 -3
  26. package/dist/esm/routes/protected/protected.js +1 -1
  27. package/dist/esm/routes/routing.js +51 -0
  28. package/dist/esm/routes/types.js +13 -1
  29. package/dist/esm/routes/utils.js +39 -0
  30. package/dist/foundation-auth.api.json +413 -285
  31. package/dist/foundation-auth.d.ts +110 -100
  32. package/docs/api/foundation-auth.authconfig.md +3 -3
  33. package/docs/api/foundation-auth.authconfig.omitroutes.md +1 -1
  34. package/docs/api/foundation-auth.authconfig.postloginredirect.md +16 -0
  35. package/docs/api/foundation-auth.authconfig.postlogoutredirect.md +16 -0
  36. package/docs/api/{foundation-auth.routes.md → foundation-auth.authroutes.md} +4 -3
  37. package/docs/api/foundation-auth.authrouting.getroutepath.md +13 -0
  38. package/docs/api/foundation-auth.authrouting.md +37 -0
  39. package/docs/api/foundation-auth.authrouting.navigateto.md +16 -0
  40. package/docs/api/foundation-auth.configure.md +5 -2
  41. package/docs/api/foundation-auth.defaultauthmachine._constructor_.md +2 -1
  42. package/docs/api/foundation-auth.defaultauthmachine.md +1 -1
  43. package/docs/api/foundation-auth.defaultauthrouting.getroutepath.md +24 -0
  44. package/docs/api/foundation-auth.defaultauthrouting.md +22 -0
  45. package/docs/api/foundation-auth.defaultauthrouting.navigateto.md +26 -0
  46. package/docs/api/foundation-auth.getauthrouting.md +32 -0
  47. package/docs/api/{foundation-auth.getsubroutepath.md → foundation-auth.getroutepath.md} +4 -4
  48. package/docs/api/foundation-auth.md +6 -6
  49. package/docs/api-report.md +57 -44
  50. package/package.json +31 -30
  51. package/dist/dts/logout/index.d.ts +0 -2
  52. package/dist/dts/logout/index.d.ts.map +0 -1
  53. package/dist/dts/logout/logout.d.ts +0 -61
  54. package/dist/dts/logout/logout.d.ts.map +0 -1
  55. package/dist/esm/logout/index.js +0 -1
  56. package/dist/esm/logout/logout.js +0 -52
  57. package/docs/api/foundation-auth.authconfig.defaultredirecturl.md +0 -18
  58. package/docs/api/foundation-auth.authconfig.routetourl.md +0 -18
  59. package/docs/api/foundation-auth.defaultlogoututility.md +0 -21
  60. package/docs/api/foundation-auth.defaultlogoututility.run.md +0 -16
  61. package/docs/api/foundation-auth.getlogoututility.md +0 -32
  62. package/docs/api/foundation-auth.logoututility.md +0 -36
  63. package/docs/api/foundation-auth.logoututility.run.md +0 -15
@@ -3,13 +3,13 @@ import { createInputEmitter, createSelectEmitter, EventEmitter, targetChecked, }
3
3
  import { SecondaryRapidColorHEX } from '@genesislcap/foundation-zero';
4
4
  import { attr, css, customElement, FASTElement, html, observable, when, } from '@microsoft/fast-element';
5
5
  import { Container } from '@microsoft/fast-foundation';
6
- import { Route } from '@microsoft/fast-router';
7
6
  import { classNames } from '@microsoft/fast-web-utilities';
8
7
  import { CredentialManager } from '../credential';
9
8
  import { AuthConfig, defaultAuthConfig } from '../main/config';
10
9
  import { AuthStore } from '../store';
11
10
  import { User } from '../user';
12
11
  import { logger } from '../utils';
12
+ import { AuthRouting } from './routing';
13
13
  /**
14
14
  * @internal
15
15
  */
@@ -49,8 +49,7 @@ export class BaseRoute extends ConfigHostElement {
49
49
  */
50
50
  this.message = '';
51
51
  this.hasErrors = false;
52
- this.onBack = () => this.onNavigate('/');
53
- this.onNavigate = (path) => Route.path.push(path);
52
+ this.onBack = () => this.routing.navigateTo('/');
54
53
  }
55
54
  connectedCallback() {
56
55
  super.connectedCallback();
@@ -64,9 +63,6 @@ export class BaseRoute extends ConfigHostElement {
64
63
  clearError() {
65
64
  logger.warn('base clearError callers need updating...');
66
65
  }
67
- getSubRoutePath(routeName) {
68
- return this.config.hostPath !== '' ? `${this.config.hostPath}/${routeName}` : routeName;
69
- }
70
66
  attemptAutofill() {
71
67
  if (!this.store.formEntry.ssoToggled &&
72
68
  !this.store.formEntry.username &&
@@ -78,6 +74,9 @@ export class BaseRoute extends ConfigHostElement {
78
74
  __decorate([
79
75
  AuthStore
80
76
  ], BaseRoute.prototype, "store", void 0);
77
+ __decorate([
78
+ AuthRouting
79
+ ], BaseRoute.prototype, "routing", void 0);
81
80
  __decorate([
82
81
  User
83
82
  ], BaseRoute.prototype, "user", void 0);
@@ -1,3 +1,5 @@
1
1
  export * from './base';
2
2
  export * from './config';
3
+ export * from './routing';
3
4
  export * from './types';
5
+ export * from './utils';
@@ -13,7 +13,7 @@ const regularLogin = html `
13
13
  ${when((x) => !x.config.omitRoutes.includes('forgot-password'), html `
14
14
  <a
15
15
  class="link-url"
16
- @click=${(x) => x.onNavigate(x.getSubRoutePath(`forgot-password`))}
16
+ @click=${(x) => x.routing.navigateTo(`forgot-password`)}
17
17
  data-test-id="forgot-password"
18
18
  >
19
19
  Forgot Password?
@@ -22,7 +22,7 @@ const regularLogin = html `
22
22
  ${when((x) => !x.config.omitRoutes.includes('reset-password'), html `
23
23
  <a
24
24
  class="link-url"
25
- @click=${(x) => x.onNavigate(x.getSubRoutePath(`reset-password`))}
25
+ @click=${(x) => x.routing.navigateTo(`reset-password`)}
26
26
  data-test-id="reset-password"
27
27
  >
28
28
  Change Password
@@ -33,7 +33,7 @@ const regularLogin = html `
33
33
  ${when((x) => !x.config.omitRoutes.includes('request-account'), html `
34
34
  <a
35
35
  class="link-url"
36
- @click=${(x) => x.onNavigate(x.getSubRoutePath(`request-account`))}
36
+ @click=${(x) => x.routing.navigateTo(`request-account`)}
37
37
  data-test-id="request-account"
38
38
  >
39
39
  Request Account
@@ -5,9 +5,7 @@ import { LogoutStyles as styles } from './logout.styles';
5
5
  import { LogoutTemplate as template } from './logout.template';
6
6
  let Logout = class Logout extends BaseRoute {
7
7
  enter() {
8
- if (this.user.isAuthenticated) {
9
- this.logout();
10
- }
8
+ this.logout();
11
9
  }
12
10
  logout() {
13
11
  this.$emit('auth-logout');
@@ -7,7 +7,7 @@ import { BaseRoute } from '../base';
7
7
  import { ProtectedTemplate as template } from './protected.template';
8
8
  let Protected = class Protected extends BaseRoute {
9
9
  onLogout() {
10
- this.$emit('auth-logout');
10
+ this.routing.navigateTo('logout');
11
11
  }
12
12
  onOpenSocketTest() {
13
13
  this.connect.connect(SOCKET_URL);
@@ -0,0 +1,51 @@
1
+ import { __decorate } from "tslib";
2
+ import { DI } from '@microsoft/fast-foundation';
3
+ import { AuthConfig } from '../main/config';
4
+ import { getRoutePath, navigateTo } from './utils';
5
+ /**
6
+ * Default AuthRouting.
7
+ *
8
+ * @public
9
+ */
10
+ export class DefaultAuthRouting {
11
+ /** {@inheritDoc AuthRouting.navigateTo} */
12
+ navigateTo(route) {
13
+ navigateTo(this.getRoutePath(route));
14
+ }
15
+ /** {@inheritDoc AuthRouting.getRoutePath} */
16
+ getRoutePath(route) {
17
+ return getRoutePath(route, this.config.hostPath);
18
+ }
19
+ }
20
+ __decorate([
21
+ AuthConfig
22
+ ], DefaultAuthRouting.prototype, "config", void 0);
23
+ /**
24
+ * AuthRouting DI key.
25
+ *
26
+ * @privateRemarks
27
+ * Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
28
+ *
29
+ * @internal
30
+ */
31
+ export const AuthRouting = DI.createInterface((x) => x.singleton(DefaultAuthRouting));
32
+ /**
33
+ * Gets AuthRouting from the DI container.
34
+ *
35
+ * @remarks
36
+ * A utility method for host applications that are not using decorators or the DI container.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { getAuthRouting } from '@genesislcap/foundation-auth';
41
+ * ...
42
+ * private authRouting = getAuthRouting();
43
+ * ...
44
+ * this.authRouting.navigateTo('logout');
45
+ * ```
46
+ *
47
+ * @public
48
+ */
49
+ export function getAuthRouting() {
50
+ return DI.getOrCreateDOMContainer().get(AuthRouting);
51
+ }
@@ -1 +1,13 @@
1
- export {};
1
+ /**
2
+ * @public
3
+ */
4
+ export const AuthRoutes = {
5
+ login: 'login',
6
+ logout: 'logout',
7
+ 'request-account': 'request-account',
8
+ 'reset-password': 'reset-password',
9
+ 'forgot-password': 'forgot-password',
10
+ verify: 'verify',
11
+ protected: 'protected',
12
+ 'not-found': 'not-found',
13
+ };
@@ -0,0 +1,39 @@
1
+ import { Route } from '@microsoft/fast-router';
2
+ import { AuthRoutes } from './types';
3
+ /**
4
+ * A utility to check if a pathname is a route of this micro frontend.
5
+ *
6
+ * @param pathname - A pathname string to check, typically location.pathname, which is used when a value is omitted.
7
+ *
8
+ * @public
9
+ * @privateRemarks
10
+ * I've just put this util in for now given there's some app level direction code in place which needs review.
11
+ */
12
+ export function isMFRoute(pathname = location.pathname) {
13
+ const valueParts = pathname.split('/');
14
+ const routeIdx = pathname.charAt(0) === '/' ? 1 : 0;
15
+ const route = valueParts[routeIdx];
16
+ return !!AuthRoutes[route];
17
+ }
18
+ /**
19
+ * @remarks
20
+ * Uses the `FASTRouter`.
21
+ *
22
+ * @param route - An auth route including query params if required, ie. `reset-password?expired`.
23
+ *
24
+ * @internal
25
+ */
26
+ export function navigateTo(route) {
27
+ Route.path.push(route);
28
+ }
29
+ /**
30
+ * A utility to get a sub route path taking the host path into account.
31
+ *
32
+ * @param route - An auth route.
33
+ * @param hostPath - The host path.
34
+ *
35
+ * @public
36
+ */
37
+ export function getRoutePath(route, hostPath = '') {
38
+ return hostPath ? `${hostPath}/${route}` : route;
39
+ }