@securitydept/session-context-client 0.3.0-beta.3 → 0.3.0-beta.5

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
@@ -2,4 +2,10 @@
2
2
 
3
3
  Session Context Client of the SecurityDept TypeScript SDK, a layered authentication and authorization toolkit built as reusable Rust crates, a TypeScript client SDK workspace, and reference server/web apps.
4
4
 
5
+ ## Documentation
6
+
7
+ - [Package documentation](https://www.npmjs.com/package/@securitydept/session-context-client)
8
+ - [SecurityDept TypeScript SDK guide](https://github.com/ethaxon/securitydept/blob/main/docs/en/007-CLIENT_SDK_GUIDE.md)
9
+ - [SecurityDept architecture](https://github.com/ethaxon/securitydept/blob/main/docs/en/001-ARCHITECTURE.md)
10
+
5
11
  Repository: [ethaxon/securitydept](https://github.com/ethaxon/securitydept)
package/dist/index.d.mts CHANGED
@@ -1,56 +1,167 @@
1
- import { a as SessionPrincipal, i as SessionInfo, n as SessionContextClientConfig, r as SessionContextSource, t as SessionContextClient } from "./client-BRqKhOuj.mjs";
2
- import { HttpTransport, ReadableSignalTrait } from "@securitydept/client";
1
+ import { CancellationTokenOptions, DisposableTrait, ErrorSummary, EventStreamTrait, FoundationEnvironment, IdentityPrincipal, OperationSpanTrait, ReadableSignalTrait, ResourceSnapshot, ResourceTrait, SYMBOL_DISPOSE, SecuritydeptInjectorTrait, SecuritydeptProvider, SpanTrait } from "@securitydept/client";
2
+ import * as _$arktype from "arktype";
3
+ import * as _$arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
3
4
 
4
- //#region src/controller.d.ts
5
- declare const SessionContextControllerStatus: {
6
- readonly Idle: "idle";
7
- readonly Loading: "loading";
8
- readonly Authenticated: "authenticated";
9
- readonly Unauthenticated: "unauthenticated";
10
- readonly Error: "error";
5
+ //#region src/types.d.ts
6
+ declare const SessionContextErrorCode: {
7
+ readonly OperationFailed: "session.operation_failed";
8
+ readonly ClientDisposed: "session.client_disposed";
9
+ readonly RouterUnavailable: "session.router_unavailable";
10
+ readonly InvalidSessionPayload: "session.invalid_user_info_payload";
11
11
  };
12
- type SessionContextControllerStatus = (typeof SessionContextControllerStatus)[keyof typeof SessionContextControllerStatus];
13
- interface SessionContextControllerState {
14
- status: SessionContextControllerStatus;
15
- session: SessionInfo | null;
16
- error: unknown | null;
17
- }
18
- interface SessionContextControllerOptions {
19
- client: SessionContextClient;
20
- transport: HttpTransport;
21
- }
22
- declare class SessionContextController {
23
- readonly client: SessionContextClient;
24
- readonly state: ReadableSignalTrait<SessionContextControllerState>;
25
- private readonly transport;
26
- private readonly stateSignal;
27
- private refreshPromise;
28
- private disposed;
29
- constructor(options: SessionContextControllerOptions);
30
- getState(): SessionContextControllerState;
31
- subscribe(listener: () => void): () => void;
32
- refresh(): Promise<SessionInfo | null>;
33
- rememberPostAuthRedirect(uri: string): Promise<void>;
34
- clearPostAuthRedirect(): Promise<void>;
35
- resolveLoginUrl(): Promise<string>;
36
- logout(): Promise<void>;
37
- dispose(): void;
12
+ type SessionContextErrorCode = (typeof SessionContextErrorCode)[keyof typeof SessionContextErrorCode];
13
+ declare const SessionContextSource: {
14
+ readonly SessionContext: "session-context";
15
+ };
16
+ type SessionContextSource = (typeof SessionContextSource)[keyof typeof SessionContextSource];
17
+ /** Session principal — shared authenticated principal semantics via @securitydept/client. */
18
+ type SessionPrincipal = IdentityPrincipal;
19
+ /** Session info returned from the server. */
20
+ interface SessionInfo {
21
+ principal: SessionPrincipal;
22
+ attributes?: Record<string, unknown>;
23
+ extra?: Record<string, unknown>;
24
+ }
25
+ interface SessionContextClientTracingOptions {
26
+ target?: string;
27
+ prefix?: string;
28
+ }
29
+ interface SessionContextOperationOptions extends CancellationTokenOptions {}
30
+ interface SessionLoginWithRedirectOptions extends CancellationTokenOptions {
31
+ postAuthRedirectUri?: string;
32
+ }
33
+ /** Configuration for the Session Context Client. */
34
+ interface SessionContextClientConfig {
35
+ id?: string;
36
+ /** Base URL of the SecurityDept server. */
37
+ baseUrl: string;
38
+ /** Login path (default: "/auth/session/login"). */
39
+ loginPath?: string;
40
+ /** Logout path (default: "/auth/session/logout"). */
41
+ logoutPath?: string;
42
+ /** User info endpoint path (default: "/auth/session/user-info"). */
43
+ userInfoPath?: string;
44
+ autoStart?: boolean;
45
+ tracing?: SessionContextClientTracingOptions;
46
+ }
47
+ interface ResolvedSessionContextClientConfig {
48
+ id: string;
49
+ baseUrl: string;
50
+ loginPath: string;
51
+ logoutPath: string;
52
+ userInfoPath: string;
53
+ tracing: Required<SessionContextClientTracingOptions>;
54
+ }
55
+ declare const SessionContextEventType: {
56
+ readonly SessionRefreshStarted: "session.refresh.started";
57
+ readonly SessionRefreshSucceeded: "session.refresh.succeeded";
58
+ readonly SessionRefreshFailed: "session.refresh.failed";
59
+ readonly SessionLogoutStarted: "session.logout.started";
60
+ readonly SessionLogoutSucceeded: "session.logout.succeeded";
61
+ readonly SessionLogoutFailed: "session.logout.failed";
62
+ };
63
+ type SessionContextEventType = (typeof SessionContextEventType)[keyof typeof SessionContextEventType];
64
+ interface SessionContextEvent {
65
+ type: SessionContextEventType;
66
+ at: number;
67
+ client: {
68
+ id: string;
69
+ };
70
+ session?: SessionInfo | null;
71
+ errorSummary?: ErrorSummary;
38
72
  }
39
73
  //#endregion
40
- //#region src/schemas.d.ts
41
- /**
42
- * Schema for the canonical SessionInfo shape (camelCase principal).
43
- *
44
- * This is the preferred shape once normalized.
45
- */
46
- declare const SessionInfoSchema: any;
74
+ //#region src/client.d.ts
75
+ interface SessionContextOperationSignals {
76
+ readonly startPending: ReadableSignalTrait<boolean>;
77
+ readonly refreshPending: ReadableSignalTrait<boolean>;
78
+ readonly logoutPending: ReadableSignalTrait<boolean>;
79
+ readonly loginRedirectPending: ReadableSignalTrait<boolean>;
80
+ }
47
81
  /**
48
- * Schema for the Rust server session user-info response shape.
82
+ * Session Context Client.
49
83
  *
50
- * Validates the real `/auth/session/user-info` wire payload and normalizes it
51
- * into SessionInfo in one step.
84
+ * Owns session state, lifecycle, login/logout navigation, and tracing.
85
+ * Host capabilities are resolved once through FoundationEnvironment at
86
+ * construction time.
52
87
  */
88
+ declare class SessionContextClient implements DisposableTrait {
89
+ [SYMBOL_DISPOSE]: () => void;
90
+ static defaultOptions: {
91
+ readonly loginPath: "/auth/session/login";
92
+ readonly logoutPath: "/auth/session/logout";
93
+ readonly userInfoPath: "/auth/session/user-info";
94
+ readonly tracing: {
95
+ readonly target: "session-context-client";
96
+ readonly prefix: "session_context";
97
+ };
98
+ };
99
+ private readonly _environment;
100
+ private readonly _config;
101
+ private readonly _span;
102
+ private readonly _rootCancellation;
103
+ private readonly _destroyed;
104
+ private readonly destroyed$;
105
+ private readonly _sessionSnapshotSignal;
106
+ private readonly _operationSignals;
107
+ private readonly _eventSubject;
108
+ private readonly _refreshCommandSubject;
109
+ private readonly _refreshResponseSubject;
110
+ private readonly _logoutCommandSubject;
111
+ private readonly _logoutResponseSubject;
112
+ private readonly _startOnce;
113
+ readonly id: string;
114
+ readonly sessionSnapshot: ReadableSignalTrait<ResourceSnapshot<SessionInfo | null>>;
115
+ readonly sessionResource: ResourceTrait<SessionInfo | null>;
116
+ readonly isAuthenticated: ResourceTrait<boolean>;
117
+ readonly sessionOperations: SessionContextOperationSignals;
118
+ readonly events: EventStreamTrait<SessionContextEvent>;
119
+ protected get environment(): FoundationEnvironment;
120
+ protected get span(): SpanTrait;
121
+ protected get config(): ResolvedSessionContextClientConfig;
122
+ static fromEnvironmentConfig(options: {
123
+ readonly config: SessionContextClientConfig;
124
+ readonly environment: FoundationEnvironment;
125
+ }): SessionContextClient;
126
+ static fromInjector(injector: SecuritydeptInjectorTrait): SessionContextClient;
127
+ protected constructor(config: SessionContextClientConfig, environment: FoundationEnvironment);
128
+ start(operationSpan?: OperationSpanTrait): Promise<SessionInfo | null>;
129
+ refresh(options?: SessionContextOperationOptions): Promise<SessionInfo | null>;
130
+ private _refresh;
131
+ logout(options?: SessionContextOperationOptions): Promise<void>;
132
+ private _logout;
133
+ loginWithRedirect(options?: SessionLoginWithRedirectOptions): Promise<void>;
134
+ private _loginWithRedirect;
135
+ dispose(): void;
136
+ private _dispatchRefresh;
137
+ private _dispatchLogout;
138
+ private _executeRefresh;
139
+ private _executeLogout;
140
+ private _fetchSessionInfo;
141
+ private _createLoginRedirectUrl;
142
+ private _createLogoutUrl;
143
+ private _readCurrentSession;
144
+ private _emitSessionEvent;
145
+ }
146
+ //#endregion
147
+ //#region src/contracts/parsers.d.ts
148
+ declare function parseSessionInfoPayload(body: unknown): SessionInfo;
149
+ //#endregion
150
+ //#region src/contracts/schemas.d.ts
151
+ declare const SessionInfoSchema: _$arktype_internal_variants_object_ts0.ObjectType<(In: {
152
+ [x: string]: any;
153
+ }) => _$arktype.Out<SessionInfo>, {}>;
53
154
  declare const SessionUserInfoResponseSchema: any;
54
155
  //#endregion
55
- export { SessionContextClient, type SessionContextClientConfig, SessionContextController, type SessionContextControllerOptions, type SessionContextControllerState, SessionContextControllerStatus, type SessionContextControllerStatus as SessionContextControllerStatusType, SessionContextSource, type SessionInfo, SessionInfoSchema, type SessionPrincipal, SessionUserInfoResponseSchema };
156
+ //#region src/providers.d.ts
157
+ interface ProvideSessionContextOptions {
158
+ readonly config: SessionContextClientConfig;
159
+ }
160
+ declare function provideSessionContext(options: ProvideSessionContextOptions): readonly SecuritydeptProvider[];
161
+ //#endregion
162
+ //#region src/tokens.d.ts
163
+ declare const SESSION_CONTEXT_CLIENT: any;
164
+ declare const SESSION_CONTEXT_CLIENT_CONFIG: any;
165
+ //#endregion
166
+ export { type ProvideSessionContextOptions, SESSION_CONTEXT_CLIENT, SESSION_CONTEXT_CLIENT_CONFIG, SessionContextClient, type SessionContextClientConfig, type SessionContextClientTracingOptions, SessionContextErrorCode, type SessionContextEvent, SessionContextEventType, type SessionContextOperationOptions, SessionContextSource, type SessionInfo, SessionInfoSchema, type SessionLoginWithRedirectOptions, type SessionPrincipal, SessionUserInfoResponseSchema, parseSessionInfoPayload, provideSessionContext };
56
167
  //# sourceMappingURL=index.d.mts.map