|
1 | 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
2 | 2 |
|
3 | 3 | import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types'; |
4 | | -import type { HTTPMethod, PromiseOrValue, MergedRequestInit } from './internal/types'; |
| 4 | +import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types'; |
5 | 5 | import { uuid4 } from './internal/utils/uuid'; |
6 | | -import { validatePositiveInteger, isAbsoluteURL, hasOwn } from './internal/utils/values'; |
| 6 | +import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values'; |
7 | 7 | import { sleep } from './internal/utils/sleep'; |
| 8 | +import { type Logger, type LogLevel, parseLogLevel } from './internal/utils/log'; |
| 9 | +export type { Logger, LogLevel } from './internal/utils/log'; |
8 | 10 | import { castToError, isAbortError } from './internal/errors'; |
9 | 11 | import type { APIResponseProps } from './internal/parse'; |
10 | 12 | import { getPlatformHeaders } from './internal/detect-platform'; |
@@ -36,48 +38,6 @@ import { readEnv } from './internal/utils/env'; |
36 | 38 | import { formatRequestDetails, loggerFor } from './internal/utils/log'; |
37 | 39 | import { isEmptyObj } from './internal/utils/values'; |
38 | 40 |
|
39 | | -const safeJSON = (text: string) => { |
40 | | - try { |
41 | | - return JSON.parse(text); |
42 | | - } catch (err) { |
43 | | - return undefined; |
44 | | - } |
45 | | -}; |
46 | | - |
47 | | -type LogFn = (message: string, ...rest: unknown[]) => void; |
48 | | -export type Logger = { |
49 | | - error: LogFn; |
50 | | - warn: LogFn; |
51 | | - info: LogFn; |
52 | | - debug: LogFn; |
53 | | -}; |
54 | | -export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug'; |
55 | | -const parseLogLevel = ( |
56 | | - maybeLevel: string | undefined, |
57 | | - sourceName: string, |
58 | | - client: Grid, |
59 | | -): LogLevel | undefined => { |
60 | | - if (!maybeLevel) { |
61 | | - return undefined; |
62 | | - } |
63 | | - const levels: Record<LogLevel, true> = { |
64 | | - off: true, |
65 | | - error: true, |
66 | | - warn: true, |
67 | | - info: true, |
68 | | - debug: true, |
69 | | - }; |
70 | | - if (hasOwn(levels, maybeLevel)) { |
71 | | - return maybeLevel; |
72 | | - } |
73 | | - loggerFor(client).warn( |
74 | | - `${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify( |
75 | | - Object.keys(levels), |
76 | | - )}`, |
77 | | - ); |
78 | | - return undefined; |
79 | | -}; |
80 | | - |
81 | 41 | export interface ClientOptions { |
82 | 42 | /** |
83 | 43 | * Bearer token used for authentication with the API |
@@ -151,8 +111,6 @@ export interface ClientOptions { |
151 | 111 | logger?: Logger | undefined; |
152 | 112 | } |
153 | 113 |
|
154 | | -type FinalizedRequestInit = RequestInit & { headers: Headers }; |
155 | | - |
156 | 114 | /** |
157 | 115 | * API Client for interfacing with the Grid API. |
158 | 116 | */ |
|
0 commit comments