1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-11 05:53:42 +00:00

format refinement; delete dead code

This commit is contained in:
✨ Audrey ✨
2025-03-11 12:45:11 -04:00
parent 1db2acb29e
commit ed735dc74c
6 changed files with 43 additions and 97 deletions

View File

@@ -1,13 +1,13 @@
import { RequireAtLeastOne } from "type-fest";
import { Tagged } from "type-fest/source/opaque";
import { EcsFormat, EventFormat } from "../log/ecs-format";
import { EventFormat, ServiceFormat } from "../log/ecs-format";
export type AchievementId = string & Tagged<"achievement">;
type Progress = { type: "progress"; name: AchievementId; value: number };
type Earned = { type: "earned"; name: AchievementId };
export type AchievementFormat = EcsFormat & EventFormat & { achievement: Progress | Earned };
export type AchievementFormat = EventFormat & ServiceFormat & { achievement: Progress | Earned };
// consumed by validator and achievement list (should this include a "toast-alerter"?)
export type Achievement = {

View File

@@ -3,7 +3,7 @@ import { Primitive } from "type-fest";
/** Elastic Common Schema log format - core fields.
*/
export interface EcsFormat {
"@timestamp": Date;
"@timestamp": number;
/** custom key/value pairs */
labels?: Record<string, Primitive>;

View File

@@ -4,26 +4,27 @@ import { EcsFormat } from "./core";
/** extends core event logs with additional information */
export type EventFormat = EcsFormat & {
event: Partial<ProcessEvent> & Partial<ApplicationEvent> & {
/** event severity as a number */
severity?: LogLevelType,
},
}
action?: string;
event: Partial<ProcessEvent> &
Partial<ApplicationEvent> & {
/** event severity as a number */
severity?: LogLevelType;
};
};
export type ProcessEvent = {
start: Date,
duration: number,
end: Date,
start: Date;
duration: number;
end: Date;
};
export type ApplicationEvent = {
/** source of the event; this is usually a client type or service name */
provider: string,
/** source of the event; this is usually a client type or service name */
provider: string;
/** reason why the event occurred, according to the source */
reason: string,
/** reason why the event occurred, according to the source */
reason: string;
/** reference URL for the event */
reference: string,
/** reference URL for the event */
reference: string;
};

View File

@@ -2,4 +2,5 @@ export { EcsFormat } from "./core";
export { ErrorFormat } from "./error";
export { EventFormat } from "./event";
export { LogFormat } from "./log";
export { ServiceFormat } from "./service";
export { UserFormat } from "./user";

View File

@@ -0,0 +1,23 @@
import { EcsFormat } from "./core";
export type ServiceFormat = EcsFormat & {
/** documents the program providing the log */
service: {
/** Which kind of client is it? */
name: "android" | "cli" | "desktop" | "extension" | "ios" | "web";
/** identifies the service as a type of client device */
type: "client";
/** Information about the instance of the service providing the log */
node: {
/** a unique identifier(s) for this client installation */
name: string;
};
/** The environment to which the client was connected */
environment: "production" | "testing" | "development" | "local";
/** the unique identifier(s) for this client installation */
version: "2025.3.1-innovation-sprint";
};
};

View File

@@ -1,79 +0,0 @@
import { Observable, Observer, ReplaySubject, SubjectLike, Subscription, Unsubscribable, map } from "rxjs";
import { EcsFormat } from "./ecs-format";
import { LogKey } from "./log-key";
import { LogSubjectDependencyProvider } from "./log-subject-dependency-provider";
/** A subject that captures the last N values it observes.
* Subscribers use one of several endpoints to retrieve values.
*
* `LogSubject$`: monitoring the LogSubject directly emits all captured
* values individually (like `ReplaySubject`).
* `LogSubject.window$(size:number)`: emit captured values in blocks less than or equal
* to the size of the capture buffer.
* `LogSubject.new$`: emit values received after the subscription occurs
*/
export class LogSubject<LogFormat extends EcsFormat>
extends Observable<LogFormat>
implements SubjectLike<LogFormat>
{
constructor(
private key: LogKey<LogFormat>,
private providers: LogSubjectDependencyProvider
) {
super();
}
// window$(size:number) : Observable<LogFormat[]>;
// new$(size:number) : Observable<LogFormat>;
next(value: LogFormat) {
this.input?.next(value);
}
error(err: any) {
this.input?.error(err);
}
complete() {
this.input?.complete();
}
/** Subscribe to the subject's event stream
* @param observer listening for events
* @returns the subscription
*/
subscribe(observer?: Partial<Observer<LogFormat>> | ((value: LogFormat) => void) | null): Subscription {
return this.output.pipe(map((log) => log)).subscribe(observer);
}
// using subjects to ensure the right semantics are followed;
// if greater efficiency becomes desirable, consider implementing
// `SubjectLike` directly
private input? = new ReplaySubject<LogFormat>(this.key.size);
private readonly output = new ReplaySubject<LogFormat>(this.key.size);
private inputSubscription?: Unsubscribable;
private outputSubscription?: Unsubscribable;
private get isDisposed() {
return this.input === null;
}
private dispose() {
if (!this.isDisposed) {
this.providers.log.debug("disposing LogSubject");
// clean up internal subscriptions
this.inputSubscription?.unsubscribe();
this.outputSubscription?.unsubscribe();
this.inputSubscription = undefined;
this.outputSubscription = undefined;
// drop input to ensure its value is removed from memory
this.input = undefined;
this.providers.log.debug("disposed LogSubject");
}
}
}