@mis-wis/common 0.2.0 → 0.2.1

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.
@@ -13,3 +13,19 @@ export declare class SessionClaimNotFoundError extends SessionError {
13
13
  readonly claim: string;
14
14
  constructor(claim: string);
15
15
  }
16
+ export declare type SessionClaimFailureReason = 'absent' | 'blank';
17
+ export interface ISessionClaimFailure {
18
+ claim: string;
19
+ reason: SessionClaimFailureReason;
20
+ }
21
+ /** Renders failures as `claim (reason), claim (reason)` for error messages. */
22
+ export declare function describeClaimFailures(failures: ISessionClaimFailure[]): string;
23
+ /**
24
+ * Every claim `run`'s `next` failed to read, reported once after the block has finished.
25
+ * Extends `SessionClaimNotFoundError` — and reports the first failure as `claim` — so handlers
26
+ * written against the single-claim error keep working.
27
+ */
28
+ export declare class SessionClaimsMissingError extends SessionClaimNotFoundError {
29
+ readonly failures: ISessionClaimFailure[];
30
+ constructor(failures: ISessionClaimFailure[]);
31
+ }
@@ -1,10 +1,21 @@
1
1
  import { NsSession } from '../models/session.model';
2
2
  import { SessionError } from './session.errors';
3
3
  import * as i0 from "@angular/core";
4
+ /** The accessors that read a single claim, and so can come back `undefined` inside `run`. */
5
+ declare type ClaimAccessor = 'sub' | 'empGuid' | 'employeeId' | 'internalSsoRole' | 'roles' | 'sessionId' | 'loggedInUser' | 'exp' | 'iat' | 'businessUnitId' | 'allowedBuids' | 'vetUserEmailId' | 'vetUserId' | 'source' | 'roleId';
6
+ /**
7
+ * The session as seen inside `run`'s `next`. `run` collects missing claims instead of throwing
8
+ * so the block always completes, which means any claim accessor may yield `undefined`.
9
+ * Outside `run` — direct access, or `read` — the accessors still throw and stay non-optional.
10
+ */
11
+ export declare type PartialSession = Omit<SessionService, ClaimAccessor> & {
12
+ readonly [K in ClaimAccessor]: SessionService[K] | undefined;
13
+ };
4
14
  export declare class SessionService {
5
15
  private config;
6
16
  private cachedToken;
7
17
  private cachedState;
18
+ private collecting;
8
19
  init(config: NsSession.IInitConfig): void;
9
20
  /**
10
21
  * Runs `handlers.next` and returns its result, or `handlers.error(error)` if it throws a `SessionError`.
@@ -16,14 +27,27 @@ export declare class SessionService {
16
27
  }): T;
17
28
  /**
18
29
  * Statement-style variant of `read` for blocks of assignments/side effects with no return value.
30
+ *
31
+ * `next` always runs to completion: a claim that is absent or blank yields `undefined` instead of
32
+ * throwing, and every such failure is reported once afterwards via `handlers.error`, as a
33
+ * `SessionClaimsMissingError` listing all of them. An unusable token (missing, expired,
34
+ * undecodable) still aborts `next` immediately with the matching `SessionError`.
35
+ *
36
+ * Collecting covers the synchronous body of `next` only — claim reads deferred into a subscription,
37
+ * timeout or promise run after it has returned and throw as usual.
38
+ *
39
+ * An error `next` throws for any other reason propagates untouched, except that any claims missing
40
+ * at the time are appended to its message and attached as `sessionClaimFailures` — a collected
41
+ * `undefined` reaching the block is the usual cause, and that is the part worth knowing.
19
42
  */
20
43
  run(handlers: {
21
- next: (session: SessionService) => void;
44
+ next: (session: PartialSession) => void;
22
45
  error: (error: SessionError) => void;
23
46
  }): void;
24
47
  get isVET(): boolean;
25
48
  get sub(): string;
26
49
  get empGuid(): string;
50
+ get employeeId(): string;
27
51
  get internalSsoRole(): string;
28
52
  get roles(): string[];
29
53
  get sessionId(): string;
@@ -36,8 +60,13 @@ export declare class SessionService {
36
60
  get vetUserId(): number;
37
61
  get source(): string;
38
62
  get roleId(): number;
63
+ /** First numeric role in `internal_sso_role` then `roles`, or `''` when the token carries none. */
64
+ private resolveRole;
65
+ private isDigitsOnly;
39
66
  private getClaims;
40
67
  private getClaim;
68
+ /** Records the failure and yields `undefined` while `run` is collecting; throws otherwise. */
69
+ private missingClaim;
41
70
  private get state();
42
71
  private build;
43
72
  private isExpired;
@@ -47,3 +76,4 @@ export declare class SessionService {
47
76
  static ɵfac: i0.ɵɵFactoryDeclaration<SessionService, never>;
48
77
  static ɵprov: i0.ɵɵInjectableDeclaration<SessionService>;
49
78
  }
79
+ export {};
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@mis-wis/common",
3
3
  "main": "src/public-api.ts",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "peerDependencies": {
6
+ "@angular/cdk": "*",
6
7
  "@angular/common": "*",
7
8
  "@angular/core": "*",
8
- "mis-crystal-design-system": "*"
9
+ "@angular/forms": "*",
10
+ "@angular/router": "*",
11
+ "dayjs": "^1.11.0",
12
+ "mis-crystal-design-system": "*",
13
+ "rxjs": "*"
9
14
  },
10
15
  "dependencies": {
11
16
  "tslib": "^2.0.0",
Binary file