(opts: Omit<CreateTokenOptions, 'clientId'> & { clientId?: string })
| 248 | * Setup keys expire in 5 minutes and can only be exchanged once. |
| 249 | */ |
| 250 | export function createSetupKey(opts: Omit<CreateTokenOptions, 'clientId'> & { clientId?: string }): TokenInfo { |
| 251 | const token = generateToken('gsk_setup_'); |
| 252 | const now = new Date(); |
| 253 | const expiresAt = new Date(now.getTime() + 5 * 60 * 1000).toISOString(); // 5 min |
| 254 | |
| 255 | const info: TokenInfo = { |
| 256 | token, |
| 257 | clientId: opts.clientId || `remote-${Date.now()}`, |
| 258 | type: 'setup', |
| 259 | scopes: opts.scopes || ['read', 'write'], |
| 260 | domains: opts.domains, |
| 261 | tabPolicy: opts.tabPolicy || 'own-only', |
| 262 | rateLimit: opts.rateLimit || 10, |
| 263 | expiresAt, |
| 264 | createdAt: now.toISOString(), |
| 265 | usesRemaining: 1, |
| 266 | commandCount: 0, |
| 267 | }; |
| 268 | |
| 269 | tokens.set(token, info); |
| 270 | return info; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Exchange a setup key for a session token. |
no test coverage detected