style: lint
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
export const ServerErrorMessages = {
|
||||
invalidEventFormat: 'invalid event format',
|
||||
invalidToken: 'invalid token',
|
||||
mustAuthenticateBeforeAnnouncing: 'must authenticate before announcing',
|
||||
moduleAnnounceIdentityInvalid: 'extension module identity must include an extension id for event \'extension:module:announce\'',
|
||||
moduleAnnounceIndexInvalid: 'the field \'index\' must be a non-negative integer for event \'extension:module:announce\'',
|
||||
moduleAnnounceNameInvalid: 'the field \'name\' must be a non-empty string for event \'extension:module:announce\'',
|
||||
moduleConsumerEventInvalid: 'the field \'event\' must be a non-empty string for event consumer registration',
|
||||
moduleNotFound: 'module not found, it hasn\'t announced itself or the name is incorrect',
|
||||
mustAuthenticateBeforeAnnouncing: 'must authenticate before announcing',
|
||||
noConsumerRegistered: 'no consumer registered for requested event delivery',
|
||||
notAuthenticated: 'not authenticated',
|
||||
uiConfigureModuleIndexInvalid: 'the field \'moduleIndex\' must be a non-negative integer for event \'ui:configure\'',
|
||||
uiConfigureModuleNameInvalid: 'the field \'moduleName\' can\'t be empty for event \'ui:configure\'',
|
||||
} as const
|
||||
|
||||
export interface ParsedServerErrorMessage {
|
||||
authentication: boolean
|
||||
code: ServerErrorCode
|
||||
message: string
|
||||
recoverable: boolean
|
||||
terminal: boolean
|
||||
}
|
||||
|
||||
export type ServerErrorCode
|
||||
= | 'invalid-event-format'
|
||||
| 'invalid-json'
|
||||
@@ -29,14 +37,6 @@ export type ServerErrorCode
|
||||
| 'ui-configure-module-name-invalid'
|
||||
| 'unknown'
|
||||
|
||||
export interface ParsedServerErrorMessage {
|
||||
authentication: boolean
|
||||
code: ServerErrorCode
|
||||
message: string
|
||||
recoverable: boolean
|
||||
terminal: boolean
|
||||
}
|
||||
|
||||
export function createInvalidJsonServerErrorMessage(errorMessage: string) {
|
||||
return `invalid JSON, error: ${errorMessage}`
|
||||
}
|
||||
@@ -47,33 +47,21 @@ export function createInvalidJsonServerErrorMessage(errorMessage: string) {
|
||||
* @internal
|
||||
*/
|
||||
const errorMetadataRegistry: Record<string, Omit<ParsedServerErrorMessage, 'message'>> = {
|
||||
[ServerErrorMessages.invalidToken]: {
|
||||
authentication: true,
|
||||
code: 'invalid-token',
|
||||
recoverable: false,
|
||||
terminal: true,
|
||||
},
|
||||
[ServerErrorMessages.notAuthenticated]: {
|
||||
authentication: true,
|
||||
code: 'not-authenticated',
|
||||
recoverable: true,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.mustAuthenticateBeforeAnnouncing]: {
|
||||
authentication: true,
|
||||
code: 'must-authenticate-before-announcing',
|
||||
recoverable: true,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.invalidEventFormat]: {
|
||||
authentication: false,
|
||||
code: 'invalid-event-format',
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.moduleAnnounceNameInvalid]: {
|
||||
[ServerErrorMessages.invalidToken]: {
|
||||
authentication: true,
|
||||
code: 'invalid-token',
|
||||
recoverable: false,
|
||||
terminal: true,
|
||||
},
|
||||
[ServerErrorMessages.moduleAnnounceIdentityInvalid]: {
|
||||
authentication: false,
|
||||
code: 'module-announce-name-invalid',
|
||||
code: 'module-announce-identity-invalid',
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
@@ -83,15 +71,9 @@ const errorMetadataRegistry: Record<string, Omit<ParsedServerErrorMessage, 'mess
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.moduleAnnounceIdentityInvalid]: {
|
||||
[ServerErrorMessages.moduleAnnounceNameInvalid]: {
|
||||
authentication: false,
|
||||
code: 'module-announce-identity-invalid',
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.moduleNotFound]: {
|
||||
authentication: false,
|
||||
code: 'module-not-found',
|
||||
code: 'module-announce-name-invalid',
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
@@ -101,16 +83,28 @@ const errorMetadataRegistry: Record<string, Omit<ParsedServerErrorMessage, 'mess
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.moduleNotFound]: {
|
||||
authentication: false,
|
||||
code: 'module-not-found',
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.mustAuthenticateBeforeAnnouncing]: {
|
||||
authentication: true,
|
||||
code: 'must-authenticate-before-announcing',
|
||||
recoverable: true,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.noConsumerRegistered]: {
|
||||
authentication: false,
|
||||
code: 'no-consumer-registered',
|
||||
recoverable: true,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.uiConfigureModuleNameInvalid]: {
|
||||
authentication: false,
|
||||
code: 'ui-configure-module-name-invalid',
|
||||
recoverable: false,
|
||||
[ServerErrorMessages.notAuthenticated]: {
|
||||
authentication: true,
|
||||
code: 'not-authenticated',
|
||||
recoverable: true,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.uiConfigureModuleIndexInvalid]: {
|
||||
@@ -119,6 +113,28 @@ const errorMetadataRegistry: Record<string, Omit<ParsedServerErrorMessage, 'mess
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
[ServerErrorMessages.uiConfigureModuleNameInvalid]: {
|
||||
authentication: false,
|
||||
code: 'ui-configure-module-name-invalid',
|
||||
recoverable: false,
|
||||
terminal: false,
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a server error message is authentication-related.
|
||||
*/
|
||||
export function isAuthenticationServerErrorMessage(message: string) {
|
||||
return parseServerErrorMessage(message).authentication
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a server error message is a terminal authentication error.
|
||||
* Terminal errors should not be retried.
|
||||
*/
|
||||
export function isTerminalAuthenticationServerErrorMessage(message: string) {
|
||||
const parsed = parseServerErrorMessage(message)
|
||||
return parsed.authentication && parsed.terminal
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,19 +177,3 @@ export function parseServerErrorMessage(message: string): ParsedServerErrorMessa
|
||||
terminal: false,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a server error message is authentication-related.
|
||||
*/
|
||||
export function isAuthenticationServerErrorMessage(message: string) {
|
||||
return parseServerErrorMessage(message).authentication
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a server error message is a terminal authentication error.
|
||||
* Terminal errors should not be retried.
|
||||
*/
|
||||
export function isTerminalAuthenticationServerErrorMessage(message: string) {
|
||||
const parsed = parseServerErrorMessage(message)
|
||||
return parsed.authentication && parsed.terminal
|
||||
}
|
||||
|
||||
@@ -2,51 +2,51 @@ import type { MetadataEventSource, ProtocolEvents, RouteConfig, WebSocketEventSo
|
||||
|
||||
export * from '@proj-airi/plugin-protocol/types'
|
||||
|
||||
export interface WebSocketEventBaseMetadata {
|
||||
source?: MetadataEventSource
|
||||
event?: {
|
||||
id?: string
|
||||
parentId?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface WebSocketBaseEvent<T, D, S extends string = string> {
|
||||
type: T
|
||||
data: D
|
||||
/**
|
||||
* @deprecated Prefer metadata.source.
|
||||
*/
|
||||
source?: WebSocketEventSource | S
|
||||
metadata: {
|
||||
source: MetadataEventSource
|
||||
event: {
|
||||
id: string
|
||||
parentId?: string
|
||||
}
|
||||
source: MetadataEventSource
|
||||
}
|
||||
route?: RouteConfig
|
||||
/**
|
||||
* @deprecated Prefer metadata.source.
|
||||
*/
|
||||
source?: S | WebSocketEventSource
|
||||
type: T
|
||||
}
|
||||
|
||||
export interface WebSocketEvents<C = undefined> extends ProtocolEvents<C> {}
|
||||
export type WebSocketEvent<C = undefined> = {
|
||||
[K in keyof WebSocketEvents<C>]: WebSocketBaseEvent<K, WebSocketEvents<C>[K]>;
|
||||
}[keyof WebSocketEvents<C>]
|
||||
|
||||
export interface WebSocketEventBaseMetadata {
|
||||
event?: {
|
||||
id?: string
|
||||
parentId?: string
|
||||
}
|
||||
source?: MetadataEventSource
|
||||
}
|
||||
|
||||
export type WebSocketEventDataInputs
|
||||
= | WebSocketEvents['input:text']
|
||||
| WebSocketEvents['input:text:voice']
|
||||
| WebSocketEvents['input:voice']
|
||||
|
||||
export type WebSocketEvent<C = undefined> = {
|
||||
[K in keyof WebSocketEvents<C>]: WebSocketBaseEvent<K, WebSocketEvents<C>[K]>;
|
||||
}[keyof WebSocketEvents<C>]
|
||||
|
||||
export type WebSocketEventOptionalSource<C = undefined> = {
|
||||
[K in keyof WebSocketEvents<C>]: Omit<WebSocketBaseEvent<K, WebSocketEvents<C>[K]>, 'metadata'> & { metadata?: WebSocketEventBaseMetadata };
|
||||
}[keyof WebSocketEvents<C>]
|
||||
export type WebSocketEventInputs
|
||||
= | WebSocketEventOf<'input:text'>
|
||||
| WebSocketEventOf<'input:text:voice'>
|
||||
| WebSocketEventOf<'input:voice'>
|
||||
|
||||
export type WebSocketEventOf<E, C = undefined> = E extends keyof WebSocketEvents<C>
|
||||
? Omit<WebSocketBaseEvent<E, WebSocketEvents<C>[E]>, 'metadata'> & { metadata?: WebSocketEventBaseMetadata }
|
||||
: never
|
||||
|
||||
export type WebSocketEventInputs
|
||||
= | WebSocketEventOf<'input:text'>
|
||||
| WebSocketEventOf<'input:text:voice'>
|
||||
| WebSocketEventOf<'input:voice'>
|
||||
export type WebSocketEventOptionalSource<C = undefined> = {
|
||||
[K in keyof WebSocketEvents<C>]: Omit<WebSocketBaseEvent<K, WebSocketEvents<C>[K]>, 'metadata'> & { metadata?: WebSocketEventBaseMetadata };
|
||||
}[keyof WebSocketEvents<C>]
|
||||
|
||||
export interface WebSocketEvents<C = undefined> extends ProtocolEvents<C> {}
|
||||
|
||||
@@ -5,7 +5,7 @@ export default defineConfig({
|
||||
'index': 'src/index.ts',
|
||||
'types/index': 'src/types/index.ts',
|
||||
},
|
||||
inlineOnly: false,
|
||||
sourcemap: true,
|
||||
unused: true,
|
||||
inlineOnly: false,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user