(options: OAuthManagerOptions)
| 119 | private inFlightRefresh: { promise: Promise<string>; force: boolean } | undefined; |
| 120 | |
| 121 | constructor(options: OAuthManagerOptions) { |
| 122 | this.config = options.config; |
| 123 | this.storage = options.storage; |
| 124 | this.refreshThresholdFn = options.refreshThreshold ?? defaultRefreshThreshold; |
| 125 | this.deviceCodeTimeoutMs = options.deviceCodeTimeoutMs ?? DEFAULT_DEVICE_CODE_TIMEOUT_MS; |
| 126 | this.now = options.now ?? (() => Math.floor(Date.now() / 1000)); |
| 127 | this.sleep = options.sleep ?? defaultSleep; |
| 128 | this.deviceHeaders = options.deviceHeaders; |
| 129 | this.onRefresh = options.onRefresh; |
| 130 | this.refreshImpl = |
| 131 | options.refreshTokenImpl ?? |
| 132 | ((config, refreshToken, refreshOptions) => |
| 133 | refreshAccessToken(config, refreshToken, { |
| 134 | ...refreshOptions, |
| 135 | deviceHeaders: this.resolveDeviceHeaders(), |
| 136 | })); |
| 137 | this.requestImpl = |
| 138 | options.requestDeviceImpl ?? |
| 139 | ((config) => |
| 140 | requestDeviceAuthorization(config, { |
| 141 | deviceHeaders: this.resolveDeviceHeaders(), |
| 142 | })); |
| 143 | this.pollImpl = |
| 144 | options.pollDeviceImpl ?? |
| 145 | ((config, deviceCode) => |
| 146 | pollDeviceToken(config, deviceCode, { |
| 147 | deviceHeaders: this.resolveDeviceHeaders(), |
| 148 | })); |
| 149 | // The `KIMI_CODE_HOME` fallback MUST stay test-only so production |
| 150 | // entry points can't silently run without a lock just because the |
| 151 | // env happens to be unset. vitest sets `NODE_ENV='test'` by default, |
| 152 | // so multi-process test workers still pick up the test home path. |
| 153 | const envConfigDir = |
| 154 | process.env['NODE_ENV'] === 'test' ? process.env['KIMI_CODE_HOME'] : undefined; |
| 155 | this.configDir = options.configDir ?? envConfigDir; |
| 156 | } |
| 157 | |
| 158 | private resolveDeviceHeaders(): DeviceHeaders | undefined { |
| 159 | return this.deviceHeaders?.(); |
nothing calls this directly
no test coverage detected