(key: string | undefined)
| 158 | * @param key The raw flag value, or `undefined` when the key is auto-minted. |
| 159 | */ |
| 160 | export function assertIdempotencyKey(key: string | undefined): void { |
| 161 | if (key === undefined) return; |
| 162 | // ASCII-printable check: every codepoint must be in U+0020–U+007E (space through tilde). |
| 163 | // Non-ASCII chars (codepoint > 127) trigger a TypeError in Node's fetch ByteString header. |
| 164 | if (key.length === 0 || !/^[ -~]+$/.test(key)) { |
| 165 | throw localValidationError( |
| 166 | 'idempotencyKey', |
| 167 | 'must be 1–256 printable ASCII characters (no non-ASCII, control chars, or empty string)', |
| 168 | undefined, |
| 169 | 'flag', |
| 170 | ); |
| 171 | } |
| 172 | if (key.length > 256) { |
| 173 | throw localValidationError( |
| 174 | 'idempotencyKey', |
| 175 | 'must be at most 256 characters', |
| 176 | undefined, |
| 177 | 'flag', |
| 178 | ); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Assert that `arr` is an Array and that its length is within the given |
no test coverage detected