* Keep the session alive. * @param isWait Indicates if the method should wait for the session to be fully renewed before returning.
(isWait?: boolean)
| 171 | * @param isWait Indicates if the method should wait for the session to be fully renewed before returning. |
| 172 | */ |
| 173 | public async keepAlive(isWait?: boolean): Promise<void> { |
| 174 | if (!this.sid) { |
| 175 | throw new Error('Session ID is not set. Cannot renew token.'); |
| 176 | } |
| 177 | // URL to renew session token |
| 178 | const renewUrl = `${SunoApi.CLERK_BASE_URL}/v1/client/sessions/${this.sid}/tokens?__clerk_api_version=2025-11-10&_clerk_js_version=${SunoApi.CLERK_VERSION}`; |
| 179 | // Renew session token |
| 180 | logger.info('KeepAlive...\n'); |
| 181 | const renewResponse = await this.client.post(renewUrl, {}, { |
| 182 | headers: { Authorization: this.cookies.__client } |
| 183 | }); |
| 184 | if (isWait) { |
| 185 | await sleep(1, 2); |
| 186 | } |
| 187 | const newToken = renewResponse.data.jwt; |
| 188 | // Update Authorization field in request header with the new JWT token |
| 189 | this.currentToken = newToken; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Get the session token (not to be confused with session ID) and save it for later use. |
no test coverage detected