@securitydept/basic-auth-context-client 0.3.0-beta.1 → 0.3.0-beta.10

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
  Basic Auth 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/basic-auth-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,16 +1,285 @@
1
- import { a as AuthGuardResultKind, c as BasicAuthContextClientConfig, i as AuthGuardResult, l as BasicAuthZoneConfig, n as readBasicAuthBoundaryKind, o as BasicAuthBoundaryKind, r as AuthGuardRedirectStatus, s as BasicAuthBoundaryObservation, t as BasicAuthContextClient, u as ResolvedBasicAuthZone } from "./client-DU98lpa_.mjs";
2
-
3
- //#region src/schemas.d.ts
1
+ import { CancellationTokenOptions, ClientError, DisposableTrait, EventStreamTrait, FoundationEnvironment, ReadableSignalTrait, ResourceSnapshot, ResourceTrait, SYMBOL_DISPOSE, SecuritydeptInjectorTrait, SecuritydeptProvider, SpanTrait } from "@securitydept/client";
2
+ //#region src/authorization-header.d.ts
3
+ interface CreateBasicAuthorizationHeaderValueOptions {
4
+ readonly username: string;
5
+ readonly password: string;
6
+ }
7
+ declare function createBasicAuthorizationHeaderValue(options: CreateBasicAuthorizationHeaderValueOptions): string;
8
+ //#endregion
9
+ //#region src/types.d.ts
10
+ interface BasicAuthZoneConfig {
11
+ /** URL path prefix for this zone (e.g. "/basic"). */
12
+ zonePrefix: string;
13
+ /** Login subpath relative to zone prefix (default: "/login"). */
14
+ loginSubpath?: string;
15
+ }
16
+ /** Configuration for the Basic Auth Context Client. */
17
+ interface BasicAuthContextClientConfig {
18
+ id?: string;
19
+ /** Base URL of the SecurityDept server. */
20
+ baseUrl: string;
21
+ /** One or more Basic Auth zones to manage. */
22
+ zones: BasicAuthZoneConfig[];
23
+ /** Protected endpoint used by start()/refresh() to observe the boundary. */
24
+ probePath?: string;
25
+ autoStart?: boolean;
26
+ tracing?: BasicAuthContextClientTracingOptions;
27
+ }
28
+ interface BasicAuthContextClientTracingOptions {
29
+ target?: string;
30
+ prefix?: string;
31
+ }
32
+ interface ResolvedBasicAuthContextClientConfig {
33
+ id: string;
34
+ baseUrl: string;
35
+ zones: readonly ResolvedBasicAuthZone[];
36
+ probePath?: string;
37
+ tracing: Required<BasicAuthContextClientTracingOptions>;
38
+ }
39
+ declare const BasicAuthBoundaryKind: {
40
+ readonly Authenticated: "authenticated";
41
+ readonly Challenge: "challenge";
42
+ readonly Unauthorized: "unauthorized";
43
+ };
44
+ type BasicAuthBoundaryKind = (typeof BasicAuthBoundaryKind)[keyof typeof BasicAuthBoundaryKind];
45
+ interface BasicAuthBoundaryObservation {
46
+ status: number;
47
+ challengeHeader?: string | null;
48
+ requestPath?: string;
49
+ }
50
+ interface BasicAuthBoundarySnapshot {
51
+ authenticated: boolean;
52
+ boundaryKind: BasicAuthBoundaryKind;
53
+ status: number;
54
+ path: string;
55
+ challengeHeader: string | null;
56
+ zone?: ResolvedBasicAuthZone;
57
+ }
58
+ declare const BasicAuthContextEventType: {
59
+ readonly BoundaryRefreshStarted: "basic_auth.boundary.refresh.started";
60
+ readonly BoundaryRefreshSucceeded: "basic_auth.boundary.refresh.succeeded";
61
+ readonly BoundaryRefreshFailed: "basic_auth.boundary.refresh.failed";
62
+ /** These logout events describe local boundary-projection clearing only. */
63
+ readonly LogoutStarted: "basic_auth.logout.started";
64
+ readonly LogoutSucceeded: "basic_auth.logout.succeeded";
65
+ readonly LogoutFailed: "basic_auth.logout.failed";
66
+ readonly LoginRedirectStarted: "basic_auth.login.redirect.started";
67
+ readonly LoginRedirectSucceeded: "basic_auth.login.redirect.succeeded";
68
+ readonly LoginRedirectFailed: "basic_auth.login.redirect.failed";
69
+ };
70
+ type BasicAuthContextEventType = (typeof BasicAuthContextEventType)[keyof typeof BasicAuthContextEventType];
71
+ interface BasicAuthContextEventBase {
72
+ readonly at: number;
73
+ readonly client: {
74
+ readonly id: string;
75
+ };
76
+ }
77
+ type BasicAuthContextEventData = {
78
+ readonly type: typeof BasicAuthContextEventType.BoundaryRefreshStarted;
79
+ readonly snapshot: BasicAuthBoundarySnapshot | null;
80
+ } | {
81
+ readonly type: typeof BasicAuthContextEventType.BoundaryRefreshSucceeded;
82
+ readonly snapshot: BasicAuthBoundarySnapshot;
83
+ readonly zone?: ResolvedBasicAuthZone;
84
+ } | {
85
+ readonly type: typeof BasicAuthContextEventType.BoundaryRefreshFailed;
86
+ readonly snapshot: BasicAuthBoundarySnapshot | null;
87
+ readonly error: ClientError;
88
+ } | {
89
+ readonly type: typeof BasicAuthContextEventType.LogoutStarted;
90
+ readonly snapshot: BasicAuthBoundarySnapshot | null;
91
+ } | {
92
+ readonly type: typeof BasicAuthContextEventType.LogoutSucceeded;
93
+ readonly snapshot: null;
94
+ } | {
95
+ readonly type: typeof BasicAuthContextEventType.LogoutFailed;
96
+ readonly snapshot: BasicAuthBoundarySnapshot | null;
97
+ readonly error: ClientError;
98
+ } | {
99
+ readonly type: typeof BasicAuthContextEventType.LoginRedirectStarted | typeof BasicAuthContextEventType.LoginRedirectSucceeded;
100
+ readonly zone: ResolvedBasicAuthZone;
101
+ } | {
102
+ readonly type: typeof BasicAuthContextEventType.LoginRedirectFailed;
103
+ readonly zone: ResolvedBasicAuthZone;
104
+ readonly error: ClientError;
105
+ };
106
+ type BasicAuthContextEvent = BasicAuthContextEventBase & BasicAuthContextEventData;
107
+ interface BasicAuthContextOperationSignals {
108
+ readonly startPending: ReadableSignalTrait<boolean>;
109
+ readonly refreshPending: ReadableSignalTrait<boolean>;
110
+ readonly logoutPending: ReadableSignalTrait<boolean>;
111
+ readonly loginRedirectPending: ReadableSignalTrait<boolean>;
112
+ }
113
+ interface BasicAuthRefreshOptions extends CancellationTokenOptions {
114
+ path?: string;
115
+ }
116
+ type BasicAuthZoneSelectionOptions = {
117
+ currentPath: string;
118
+ zonePrefix?: never;
119
+ } | {
120
+ zonePrefix: string;
121
+ currentPath?: never;
122
+ };
123
+ /** Options for clearing the client's in-memory boundary projection. */
124
+ interface BasicAuthLogoutOptions extends CancellationTokenOptions {}
125
+ type BasicAuthLoginWithRedirectOptions = BasicAuthZoneSelectionOptions & CancellationTokenOptions & {
126
+ postAuthRedirectUri?: string;
127
+ };
128
+ declare const AuthGuardResultKind: {
129
+ readonly Ok: "ok";
130
+ readonly Redirect: "redirect";
131
+ };
132
+ type AuthGuardResultKind = (typeof AuthGuardResultKind)[keyof typeof AuthGuardResultKind];
133
+ declare const AuthGuardRedirectStatus: {
134
+ readonly Found: 302;
135
+ readonly SeeOther: 303;
136
+ readonly TemporaryRedirect: 307;
137
+ };
138
+ type AuthGuardRedirectStatus = (typeof AuthGuardRedirectStatus)[keyof typeof AuthGuardRedirectStatus];
139
+ /** Redirect instruction — framework-neutral result. */
140
+ type AuthGuardResult<T> = {
141
+ kind: typeof AuthGuardResultKind.Ok;
142
+ value: T;
143
+ } | {
144
+ kind: typeof AuthGuardResultKind.Redirect;
145
+ status: AuthGuardRedirectStatus;
146
+ location: string;
147
+ };
148
+ /** Resolved zone with computed paths. */
149
+ interface ResolvedBasicAuthZone {
150
+ zonePrefix: string;
151
+ loginPath: string;
152
+ }
153
+ interface BasicAuthContextClientStateSignals {
154
+ readonly boundarySnapshot: ReadableSignalTrait<ResourceSnapshot<BasicAuthBoundarySnapshot | null>>;
155
+ readonly boundaryResource: ResourceTrait<BasicAuthBoundarySnapshot | null>;
156
+ readonly isAuthenticated: ResourceTrait<boolean>;
157
+ }
158
+ //#endregion
159
+ //#region src/client.d.ts
160
+ declare function readBasicAuthBoundaryKind(options: BasicAuthBoundaryObservation): BasicAuthBoundaryKind;
4
161
  /**
5
- * Schema for validating BasicAuthContextClientConfig.
162
+ * Basic Auth Context Client.
6
163
  *
7
- * Validates:
8
- * - `baseUrl` is a non-empty string
9
- * - `zones` is a non-empty array of valid zone configs
10
- * - each zone has a non-empty `zonePrefix`
11
- * - optional fields have correct types when provided
164
+ * Owns zone-aware Basic Auth boundary observations and login navigation.
165
+ * It does not manage browser credentials or principal data.
12
166
  */
13
- declare const BasicAuthContextClientConfigSchema: any;
167
+ declare class BasicAuthContextClient implements DisposableTrait {
168
+ [SYMBOL_DISPOSE]: () => void;
169
+ static defaultOptions: {
170
+ readonly loginSubpath: "/login";
171
+ readonly tracing: {
172
+ readonly target: "basic-auth-context-client";
173
+ readonly prefix: "basic_auth_context";
174
+ };
175
+ };
176
+ private readonly _environment;
177
+ private readonly _config;
178
+ private readonly _span;
179
+ private readonly _rootCancellation;
180
+ private readonly _destroyed;
181
+ private readonly destroyed$;
182
+ private readonly _boundarySnapshotSignal;
183
+ private readonly _operationSignals;
184
+ private readonly _eventSubject;
185
+ private readonly _refreshCommandSubject;
186
+ private readonly _refreshResponseSubject;
187
+ private readonly _startOnce;
188
+ readonly id: string;
189
+ readonly zones: readonly ResolvedBasicAuthZone[];
190
+ readonly boundarySnapshot: ReadableSignalTrait<ResourceSnapshot<BasicAuthBoundarySnapshot | null>>;
191
+ readonly boundaryResource: ResourceTrait<BasicAuthBoundarySnapshot | null>;
192
+ readonly isAuthenticated: ResourceTrait<boolean>;
193
+ readonly operations: BasicAuthContextOperationSignals;
194
+ readonly events: EventStreamTrait<BasicAuthContextEvent>;
195
+ protected get environment(): FoundationEnvironment;
196
+ protected get span(): SpanTrait;
197
+ protected get config(): ResolvedBasicAuthContextClientConfig;
198
+ static fromEnvironmentConfig(options: {
199
+ readonly config: BasicAuthContextClientConfig;
200
+ readonly environment: FoundationEnvironment;
201
+ }): BasicAuthContextClient;
202
+ static fromInjector(injector: SecuritydeptInjectorTrait): BasicAuthContextClient;
203
+ protected constructor(config: BasicAuthContextClientConfig, environment: FoundationEnvironment);
204
+ start(): Promise<BasicAuthBoundarySnapshot>;
205
+ private _start;
206
+ refresh(options?: BasicAuthRefreshOptions): Promise<BasicAuthBoundarySnapshot>;
207
+ private _refresh;
208
+ /**
209
+ * Clears only this client's in-memory Basic Auth boundary projection.
210
+ *
211
+ * Browsers own HTTP Basic credentials. This method cannot revoke or clear
212
+ * those credentials, and a later probe may observe an authenticated state
213
+ * again when the browser continues sending them.
214
+ */
215
+ logout(options?: BasicAuthLogoutOptions): Promise<void>;
216
+ private _logout;
217
+ loginWithRedirect(options: BasicAuthLoginWithRedirectOptions): Promise<void>;
218
+ private _loginWithRedirect;
219
+ /** Find the zone that contains the given path. */
220
+ zoneForPath(path: string): ResolvedBasicAuthZone | undefined;
221
+ zoneForPrefix(zonePrefix: string): ResolvedBasicAuthZone | undefined;
222
+ /** Check whether a path falls inside any configured zone. */
223
+ isInZone(path: string): boolean;
224
+ /** Build the full login URL for a zone, optionally with a post-auth redirect. */
225
+ loginUrl(zone: ResolvedBasicAuthZone, postAuthRedirectUri?: string): string;
226
+ loginUrlForZonePrefix(zonePrefix: string, postAuthRedirectUri?: string): string | null;
227
+ /**
228
+ * Handle a 401 response: if the current path is inside a zone,
229
+ * return a redirect instruction to the zone's login URL.
230
+ */
231
+ handleUnauthorized(currentPath: string, responseStatus: number): AuthGuardResult<null>;
232
+ dispose(): void;
233
+ private _resolveRefreshOptions;
234
+ private _resolveZoneForAction;
235
+ private _dispatchRefresh;
236
+ private _executeRefresh;
237
+ private _snapshotFromResponse;
238
+ private _readCurrentSnapshot;
239
+ private _emitEvent;
240
+ }
241
+ //#endregion
242
+ //#region src/error.d.ts
243
+ declare const BasicAuthContextErrorCode: {
244
+ readonly OperationFailed: "basic_auth.operation_failed";
245
+ readonly InvalidConfig: "basic_auth.invalid_config";
246
+ readonly ClientDisposed: "basic_auth.client_disposed";
247
+ readonly RouterUnavailable: "basic_auth.router_unavailable";
248
+ readonly ProbePathRequired: "basic_auth.probe_path_required";
249
+ readonly ZoneNotFound: "basic_auth.zone_not_found";
250
+ readonly ZoneRequired: "basic_auth.zone_required";
251
+ };
252
+ type BasicAuthContextErrorCode = (typeof BasicAuthContextErrorCode)[keyof typeof BasicAuthContextErrorCode];
253
+ declare const BasicAuthContextSource: {
254
+ readonly BasicAuthContext: "basic-auth-context";
255
+ };
256
+ type BasicAuthContextSource = (typeof BasicAuthContextSource)[keyof typeof BasicAuthContextSource];
257
+ //#endregion
258
+ //#region src/providers.d.ts
259
+ interface ProvideBasicAuthContextOptions {
260
+ readonly config: BasicAuthContextClientConfig;
261
+ }
262
+ declare function provideBasicAuthContext(options: ProvideBasicAuthContextOptions): readonly SecuritydeptProvider[];
263
+ //#endregion
264
+ //#region src/schemas.d.ts
265
+ declare const BasicAuthContextClientConfigSchema: import("arktype/internal/variants/object.ts").ObjectType<{
266
+ baseUrl: string;
267
+ zones: {
268
+ zonePrefix: string;
269
+ loginSubpath?: string | undefined;
270
+ }[];
271
+ id?: string | undefined;
272
+ probePath?: string | undefined;
273
+ autoStart?: boolean | undefined;
274
+ tracing?: {
275
+ target?: string | undefined;
276
+ prefix?: string | undefined;
277
+ } | undefined;
278
+ }, {}>;
279
+ //#endregion
280
+ //#region src/tokens.d.ts
281
+ declare const BASIC_AUTH_CONTEXT_CLIENT: any;
282
+ declare const BASIC_AUTH_CONTEXT_CLIENT_CONFIG: any;
14
283
  //#endregion
15
- export { AuthGuardRedirectStatus, type AuthGuardResult, AuthGuardResultKind, BasicAuthBoundaryKind, type BasicAuthBoundaryObservation, BasicAuthContextClient, type BasicAuthContextClientConfig, BasicAuthContextClientConfigSchema, type BasicAuthZoneConfig, type ResolvedBasicAuthZone, readBasicAuthBoundaryKind };
284
+ export { AuthGuardRedirectStatus, type AuthGuardResult, AuthGuardResultKind, BASIC_AUTH_CONTEXT_CLIENT, BASIC_AUTH_CONTEXT_CLIENT_CONFIG, BasicAuthBoundaryKind, type BasicAuthBoundaryObservation, type BasicAuthBoundarySnapshot, BasicAuthContextClient, type BasicAuthContextClientConfig, BasicAuthContextClientConfigSchema, type BasicAuthContextClientStateSignals, type BasicAuthContextClientTracingOptions, BasicAuthContextErrorCode, type BasicAuthContextEvent, BasicAuthContextEventType, type BasicAuthContextOperationSignals, BasicAuthContextSource, type BasicAuthLoginWithRedirectOptions, type BasicAuthLogoutOptions, type BasicAuthRefreshOptions, type BasicAuthZoneConfig, type CreateBasicAuthorizationHeaderValueOptions, type ProvideBasicAuthContextOptions, type ResolvedBasicAuthContextClientConfig, type ResolvedBasicAuthZone, createBasicAuthorizationHeaderValue, provideBasicAuthContext, readBasicAuthBoundaryKind };
16
285
  //# sourceMappingURL=index.d.mts.map