You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.0 KiB
84 lines
2.0 KiB
import {
|
|
LogLevel,
|
|
createCatalogDiagnostics,
|
|
type DiagnosticCatalog,
|
|
type DiagnosticEvent,
|
|
type Diagnostics
|
|
} from '$libs/logger';
|
|
import {
|
|
PERM_MODULE,
|
|
PERM_CLIENT_DIAGNOSTIC_EVENTS,
|
|
PERM_LOG_MSG_REMOTE_BATCH_FAILED,
|
|
PERM_LOG_MSG_REMOTE_CHECK_FAILED,
|
|
PERM_LOG_MSG_REMOTE_WHAT_FAILED
|
|
} from './consts.ts';
|
|
import type {
|
|
PermClientBatchInput,
|
|
PermClientCheckInput,
|
|
PermClientOptions
|
|
} from './types.ts';
|
|
|
|
export type PermClientDiagnosticType =
|
|
(typeof PERM_CLIENT_DIAGNOSTIC_EVENTS)[keyof typeof PERM_CLIENT_DIAGNOSTIC_EVENTS];
|
|
|
|
export type PermClientDiagnosticMeta =
|
|
| {
|
|
readonly error: unknown;
|
|
readonly input: PermClientCheckInput;
|
|
}
|
|
| {
|
|
readonly error: unknown;
|
|
readonly input: PermClientBatchInput;
|
|
}
|
|
| {
|
|
readonly error: unknown;
|
|
readonly input: {
|
|
readonly resource?: PermClientCheckInput['resource'];
|
|
readonly actions?: readonly string[];
|
|
readonly context?: PermClientCheckInput['context'];
|
|
};
|
|
};
|
|
|
|
export type PermClientDiagnosticEvent = DiagnosticEvent<
|
|
PermClientDiagnosticType,
|
|
PermClientDiagnosticMeta
|
|
>;
|
|
export type PermClientDiagnostics = Diagnostics<PermClientDiagnosticEvent>;
|
|
|
|
const PERM_CLIENT_DIAGNOSTIC_LOGS: DiagnosticCatalog<PermClientDiagnosticEvent> = {
|
|
[PERM_CLIENT_DIAGNOSTIC_EVENTS.REMOTE_BATCH_FAILED]: {
|
|
level: LogLevel.ERROR,
|
|
message: PERM_LOG_MSG_REMOTE_BATCH_FAILED
|
|
},
|
|
[PERM_CLIENT_DIAGNOSTIC_EVENTS.REMOTE_CHECK_FAILED]: {
|
|
level: LogLevel.ERROR,
|
|
message: PERM_LOG_MSG_REMOTE_CHECK_FAILED
|
|
},
|
|
[PERM_CLIENT_DIAGNOSTIC_EVENTS.REMOTE_WHAT_FAILED]: {
|
|
level: LogLevel.ERROR,
|
|
message: PERM_LOG_MSG_REMOTE_WHAT_FAILED
|
|
}
|
|
};
|
|
|
|
export function createPermClientDiagnostics(
|
|
logger?: PermClientOptions['logger']
|
|
): PermClientDiagnostics {
|
|
return createCatalogDiagnostics({
|
|
logger,
|
|
defaultCategory: PERM_MODULE,
|
|
catalog: PERM_CLIENT_DIAGNOSTIC_LOGS
|
|
});
|
|
}
|
|
|
|
export function emitPermClientDiagnostic(
|
|
diagnostics: PermClientDiagnostics,
|
|
type: PermClientDiagnosticType,
|
|
meta: PermClientDiagnosticMeta
|
|
): void {
|
|
diagnostics.emit({
|
|
artifact: PERM_MODULE,
|
|
type,
|
|
meta
|
|
});
|
|
}
|