Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keeperapi/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ export class Auth {
} catch (e: any) {
if (e?.message && e.message == 'push_declined') {
handleError(e.message, loginResponse, e)
} else if (e?.message === 'Canceled') {
return { result: LoginV3ResultEnum.NOT_LOGGED_IN }
}
}
break
Expand Down
29 changes: 24 additions & 5 deletions keeperapi/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ function convertBytesDeep(value: unknown): unknown {
return value
}

function protoTypeName(ctor: { getTypeUrl?: (prefix?: string) => string } | undefined): string | undefined {
if (typeof ctor?.getTypeUrl !== 'function') return undefined
try {
const url = ctor.getTypeUrl('')
// `getTypeUrl('')` returns `/Fully.Qualified.Name`; strip the leading slash.
return url.startsWith('/') ? url.slice(1) : url
} catch {
return undefined
}
}

/**
* Formats a protobufjs message for logging as `prefix TypeName:` plus its JSON body.
* Spread into `logger.debug(...)` so the prefix stays a string and the body renders
Expand All @@ -73,18 +84,26 @@ export function formatProto(prefix: string, msg: unknown): [string, unknown] {
if (msg == null || typeof msg !== 'object') return [prefix, msg]
const m = msg as {
toJSON?: () => unknown
constructor?: { name?: string; toObject?: (m: unknown, opts: unknown) => unknown }
constructor?: {
name?: string
toObject?: (m: unknown, opts: unknown) => unknown
getTypeUrl?: (prefix?: string) => string
}
}
const ctor = m.constructor
// Prefer the type name embedded in `getTypeUrl()` over `ctor.name`. Static-module
// protobufjs generates `getTypeUrl` with a bundled string literal like
// `"type.googleapis.com/Authentication.LoginResponse"`, which survives minification —
// whereas `ctor.name` is the JS class identifier and gets mangled in prod builds
// (yielding labels like `e:` instead of `LoginResponse:`).
const protoName = protoTypeName(ctor) ?? ctor?.name ?? 'proto'
if (typeof ctor?.toObject !== 'function') {
if (typeof m.toJSON !== 'function') return [prefix, msg]
const name = ctor?.name ?? 'proto'
const label = prefix ? `${prefix} ${name}:` : `${name}:`
const label = prefix ? `${prefix} ${protoName}:` : `${protoName}:`
return [label, m.toJSON()]
}
const obj = ctor.toObject(m, { longs: String, enums: String, bytes: Uint8Array })
const name = ctor.name ?? 'proto'
const label = prefix ? `${prefix} ${name}:` : `${name}:`
const label = prefix ? `${prefix} ${protoName}:` : `${protoName}:`
return [label, convertBytesDeep(obj)]
}

Expand Down
8 changes: 4 additions & 4 deletions keeperapi/src/restMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type decoderClass<T> = {
decode: (reader: Uint8Array, length?: number) => T
}

const createInMessage = <TIn>(
export const createInMessage = <TIn>(
data: TIn,
path: string,
encoder: encoderClass<TIn>,
Expand All @@ -68,7 +68,7 @@ const createInMessage = <TIn>(
}
}

const createOutMessage = <TOut>(
export const createOutMessage = <TOut>(
path: string,
decoder: decoderClass<TOut>,
apiVersion?: number
Expand All @@ -80,7 +80,7 @@ const createOutMessage = <TOut>(
apiVersion,
})

const createMessage = <TIn, TOut>(
export const createMessage = <TIn, TOut>(
data: TIn,
path: string,
encoder: encoderClass<TIn>,
Expand All @@ -101,7 +101,7 @@ const createMessage = <TIn, TOut>(
}
}

const createActionMessage = (path: string, apiVersion?: number): RestActionMessage => ({
export const createActionMessage = (path: string, apiVersion?: number): RestActionMessage => ({
path: path,
apiVersion,
})
Expand Down
Loading