( method: string, date: Date, query: Record<string, string>, header: Record<string, string>, ak: string, sk: string, token: string | null, action: string, body: string, region?: string, version?: string, )
| 108 | * Sign and send HTTP request to Volcengine API |
| 109 | */ |
| 110 | export async function request( |
| 111 | method: string, |
| 112 | date: Date, |
| 113 | query: Record<string, string>, |
| 114 | header: Record<string, string>, |
| 115 | ak: string, |
| 116 | sk: string, |
| 117 | token: string | null, |
| 118 | action: string, |
| 119 | body: string, |
| 120 | region?: string, |
| 121 | version?: string, |
| 122 | ): Promise<any> { |
| 123 | // Get action configuration from map or use defaults |
| 124 | const actionConfig = ACTION_CONFIG_MAP.get(action) || { |
| 125 | service: DEFAULT_SERVICE, |
| 126 | version: DEFAULT_VERSION, |
| 127 | }; |
| 128 | |
| 129 | // Initialize credential |
| 130 | const credential: Credential = { |
| 131 | access_key_id: ak, |
| 132 | secret_access_key: sk, |
| 133 | service: actionConfig.service, |
| 134 | region: region || DEFAULT_REGION, |
| 135 | }; |
| 136 | |
| 137 | if (token) { |
| 138 | credential.session_token = token; |
| 139 | } |
| 140 | |
| 141 | // Determine content type |
| 142 | let contentType = actionConfig.contentType || ContentType; |
| 143 | if (method === 'POST') { |
| 144 | contentType = 'application/json'; |
| 145 | } |
| 146 | |
| 147 | const apiVersion = version || actionConfig.version; |
| 148 | |
| 149 | // Initialize request parameters |
| 150 | const requestParam: RequestParam = { |
| 151 | body: body || '', |
| 152 | host: Host, |
| 153 | path: '/', |
| 154 | method, |
| 155 | content_type: contentType, |
| 156 | date, |
| 157 | query: { Action: action, Version: apiVersion, ...query }, |
| 158 | }; |
| 159 | |
| 160 | // Calculate signature |
| 161 | const xDate = date |
| 162 | .toISOString() |
| 163 | .replace(/[-:]/g, '') |
| 164 | .replace(/\.\d{3}/, ''); |
| 165 | const shortXDate = xDate.slice(0, 8); |
| 166 | const xContentSha256 = hashSha256(requestParam.body); |
| 167 |
no test coverage detected
searching dependent graphs…