杂务:新增声明级注释覆盖率

This commit is contained in:
xiaowang
2026-05-23 18:44:57 +08:00
parent 8f038894e7
commit 844516988b
234 changed files with 8356 additions and 0 deletions
@@ -1,37 +1,89 @@
import type { InternalAxiosRequestConfig } from 'axios'
/**
* Purpose: HEADER_TIMESTAMP supports request-signature.ts by holding or executing the header timestamp page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const HEADER_TIMESTAMP = 'X-Timestamp'
/**
* Purpose: HEADER_NONCE supports request-signature.ts by holding or executing the header nonce page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const HEADER_NONCE = 'X-Nonce'
/**
* Purpose: HEADER_SIGNATURE supports request-signature.ts by holding or executing the header signature page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const HEADER_SIGNATURE = 'X-Signature'
/**
* Purpose: HEADER_SIGNATURE_VERSION supports request-signature.ts by holding or executing the header signature version page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const HEADER_SIGNATURE_VERSION = 'X-Sign-Version'
/**
* Purpose: DEVICE_ID_HEADER supports request-signature.ts by holding or executing the device id header page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const DEVICE_ID_HEADER = 'X-Device-Id'
/**
* Purpose: DEVICE_ID_STORAGE_KEY supports request-signature.ts by holding or executing the device id storage key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const DEVICE_ID_STORAGE_KEY = 'yuminail-device-id'
/**
* Purpose: SIGNATURE_VERSION supports request-signature.ts by holding or executing the signature version page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const SIGNATURE_VERSION = 'v1'
/**
* Purpose: HeaderContainer supports request-signature.ts by holding or executing the header container page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
type HeaderContainer = Record<string, unknown> & {
set?: (name: string, value: string) => void
get?: (name: string) => unknown
}
/**
* Purpose: RequestSignatureOptions supports request-signature.ts by holding or executing the request signature options page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface RequestSignatureOptions {
authFree?: boolean
}
/**
* Purpose: isSafeMethod supports request-signature.ts by holding or executing the is safe method page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function isSafeMethod(method?: string) {
return ['GET', 'HEAD', 'OPTIONS'].includes(String(method || 'GET').toUpperCase())
}
/**
* Purpose: toHex supports request-signature.ts by holding or executing the to hex page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function toHex(bytes: ArrayBuffer) {
return Array.from(new Uint8Array(bytes))
.map(byte => byte.toString(16).padStart(2, '0'))
.join('')
}
/**
* Purpose: sha256Hex supports request-signature.ts by holding or executing the sha256 hex page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function sha256Hex(text: string) {
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
return toHex(digest)
}
/**
* Purpose: hmacSha256Hex supports request-signature.ts by holding or executing the hmac sha256 hex page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function hmacSha256Hex(secret: string, message: string) {
const key = await crypto.subtle.importKey(
'raw',
@@ -44,6 +96,10 @@ async function hmacSha256Hex(secret: string, message: string) {
return toHex(signature)
}
/**
* Purpose: randomNonce supports request-signature.ts by holding or executing the random nonce page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function randomNonce() {
if (typeof crypto.randomUUID === 'function') {
return `${Date.now()}-${crypto.randomUUID()}`
@@ -51,6 +107,10 @@ function randomNonce() {
return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`
}
/**
* Purpose: getDeviceId supports request-signature.ts by holding or executing the get device id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
export function getDeviceId() {
try {
const stored = localStorage.getItem(DEVICE_ID_STORAGE_KEY)
@@ -65,6 +125,10 @@ export function getDeviceId() {
}
}
/**
* Purpose: setHeader supports request-signature.ts by holding or executing the set header page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function setHeader(config: InternalAxiosRequestConfig, name: string, value: string) {
const headers = config.headers as HeaderContainer | undefined
if (headers && typeof headers.set === 'function') {
@@ -77,6 +141,10 @@ function setHeader(config: InternalAxiosRequestConfig, name: string, value: stri
} as InternalAxiosRequestConfig['headers']
}
/**
* Purpose: getHeader supports request-signature.ts by holding or executing the get header page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getHeader(config: InternalAxiosRequestConfig, name: string) {
const headers = config.headers as HeaderContainer | undefined
if (!headers) {
@@ -91,6 +159,10 @@ function getHeader(config: InternalAxiosRequestConfig, name: string) {
return String(headers[name] || headers[name.toLowerCase()] || '')
}
/**
* Purpose: extractPath supports request-signature.ts by holding or executing the extract path page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function extractPath(value?: string) {
if (!value) {
return ''
@@ -102,6 +174,10 @@ function extractPath(value?: string) {
}
}
/**
* Purpose: joinAxiosPath supports request-signature.ts by holding or executing the join axios path page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function joinAxiosPath(baseUrl?: string, requestUrl?: string) {
if (requestUrl && /^[a-z][a-z\d+\-.]*:\/\//i.test(requestUrl)) {
return extractPath(requestUrl)
@@ -113,6 +189,10 @@ function joinAxiosPath(baseUrl?: string, requestUrl?: string) {
return joined ? `/${joined}` : '/'
}
/**
* Purpose: toBackendRequestPath supports request-signature.ts by holding or executing the to backend request path page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function toBackendRequestPath(baseUrl?: string, requestUrl?: string) {
const path = joinAxiosPath(baseUrl, requestUrl)
if (path === '/admin/api') {
@@ -136,6 +216,10 @@ function toBackendRequestPath(baseUrl?: string, requestUrl?: string) {
return path
}
/**
* Purpose: appendParam supports request-signature.ts by holding or executing the append param page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function appendParam(target: Record<string, unknown[]>, key: string, value: unknown) {
if (value === undefined || value === null || value === '') {
return
@@ -150,6 +234,10 @@ function appendParam(target: Record<string, unknown[]>, key: string, value: unkn
target[key].push(value)
}
/**
* Purpose: collectParams supports request-signature.ts by holding or executing the collect params page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function collectParams(source: unknown, target: Record<string, unknown[]>) {
if (!source) {
return
@@ -171,6 +259,10 @@ function collectParams(source: unknown, target: Record<string, unknown[]>) {
}
}
/**
* Purpose: buildCanonicalParams supports request-signature.ts by holding or executing the build canonical params page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildCanonicalParams(...sources: unknown[]) {
const params: Record<string, unknown[]> = {}
sources.forEach(source => collectParams(source, params))
@@ -186,6 +278,10 @@ function buildCanonicalParams(...sources: unknown[]) {
.join('&')
}
/**
* Purpose: buildJsonPayload supports request-signature.ts by holding or executing the build json payload page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildJsonPayload(data: unknown) {
if (data === undefined || data === null || data === '') {
return ''
@@ -196,6 +292,10 @@ function buildJsonPayload(data: unknown) {
return JSON.stringify(data)
}
/**
* Purpose: resolvePayload supports request-signature.ts by holding or executing the resolve payload page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function resolvePayload(config: InternalAxiosRequestConfig) {
const contentType = getHeader(config, 'Content-Type').toLowerCase()
const jsonPayload = contentType.includes('application/json') ? buildJsonPayload(config.data) : ''
@@ -205,6 +305,10 @@ function resolvePayload(config: InternalAxiosRequestConfig) {
return buildCanonicalParams(config.params, config.data)
}
/**
* Purpose: attachRequestSignature supports request-signature.ts by holding or executing the attach request signature page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
export async function attachRequestSignature(
config: InternalAxiosRequestConfig,
accessToken?: string | null,