opencode-next 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,560 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import {
3
+ resolveCredential,
4
+ resolveFromLocalOpenCodeDb,
5
+ resolveLocalOrgId,
6
+ saveDshTokenFile,
7
+ loadAccounts,
8
+ saveAccounts,
9
+ defaultAccountsPath,
10
+ describeMissingCredential
11
+ } from './store.js';
12
+ import { refreshAccessToken } from './device-flow.js';
13
+
14
+ /** 憑證剩餘壽命低於這個秒數就視為「該換了」,與 getValidToken 共用。 */
15
+ const REFRESH_THRESHOLD_SECONDS = 300;
16
+
17
+ /** expires 可能是秒或毫秒(舊資料兩種都出現過),統一成正規化成秒。 */
18
+ function normalizeExpiry(expires) {
19
+ const value = Number(expires);
20
+ if (!Number.isFinite(value) || value <= 0) return 0;
21
+ return value > 2000000000 ? Math.floor(value / 1000) : Math.floor(value);
22
+ }
23
+
24
+ function needsRefresh(expires) {
25
+ const normalized = normalizeExpiry(expires);
26
+ if (normalized <= 0) return false;
27
+ return normalized - Math.floor(Date.now() / 1000) < REFRESH_THRESHOLD_SECONDS;
28
+ }
29
+
30
+ export class TokenManager {
31
+ #storePath;
32
+ #accountsPath;
33
+ #cachedCredential = null;
34
+ /** 憑證快照的單調版本號。每次更換目前憑證就 +1,供 CAS 判斷「還是不是同一個」。 */
35
+ #version = 0;
36
+ /**
37
+ * 逐帳號的 refresh 單飛(single-flight)。
38
+ *
39
+ * 舊版用一個全域 #refreshPromise:A 帳號正在 refresh 時切到 B,B 的請求會
40
+ * 直接拿到 A 的 promise,於是 A 的新 token 被當成 B 的 token 用。以帳號 id
41
+ * 當 key 後,兩個帳號各自等待自己的結果,不可能互相冒充。
42
+ */
43
+ #accountRefreshes = new Map();
44
+ /** 非帳號來源(DSH token 檔/本機 DB)的單飛;key 是當下的憑證物件本身。 */
45
+ #credentialRefreshes = new Map();
46
+ #refreshAccessToken;
47
+
48
+ constructor(storePath, accountsPath, options = {}) {
49
+ this.#storePath = storePath;
50
+ this.#accountsPath = accountsPath || defaultAccountsPath();
51
+ this.#refreshAccessToken =
52
+ typeof options.refreshAccessToken === 'function' ? options.refreshAccessToken : refreshAccessToken;
53
+ }
54
+
55
+ #ensureImportedAccounts() {
56
+ let data = loadAccounts(this.#accountsPath);
57
+ if (data) return data;
58
+ const legacy = resolveFromLocalOpenCodeDb();
59
+ if (!legacy?.access?.startsWith('st_')) return null;
60
+ const now = Date.now();
61
+ const account = {
62
+ id: `acc-${Math.random().toString(16).slice(2, 8)}`,
63
+ label: 'OpenCode Desktop',
64
+ access: legacy.access,
65
+ refresh: legacy.refresh,
66
+ expires: legacy.expires || 0,
67
+ addedAt: now,
68
+ lastUsedAt: now
69
+ };
70
+ data = { version: 1, activeId: account.id, accounts: [account] };
71
+ saveAccounts(data, this.#accountsPath);
72
+ return data;
73
+ }
74
+
75
+ /** 更換目前快取憑證,並推進版本號。所有寫入 #cachedCredential 的地方都走這裡。 */
76
+ #setCached(credential) {
77
+ this.#cachedCredential = credential;
78
+ this.#version += 1;
79
+ return credential;
80
+ }
81
+
82
+ /**
83
+ * 目前憑證的不透明身分:只有版本/帳號/來源,**不含任何 token 值**。
84
+ * adapter 用它來確認「重試的請求與當初送出的請求仍是同一個帳號」。
85
+ */
86
+ credentialSnapshot() {
87
+ const credential = this.#cachedCredential;
88
+ const isLocalDb = credential?.source === 'local-db' || credential?.label === 'OpenCode Desktop';
89
+ return {
90
+ version: this.#version,
91
+ accountId: credential?.accountId ?? null,
92
+ source: credential?.source ?? null,
93
+ orgId: credential?.orgId || (isLocalDb ? resolveLocalOrgId() : null)
94
+ };
95
+ }
96
+
97
+ /**
98
+ * 找出已存在相同 access token 的帳號 id,供匯入去重使用。
99
+ * 只回傳 id,不把 token 本身交給呼叫端或前端。
100
+ */
101
+ findAccountIdByAccess(access) {
102
+ if (typeof access !== 'string' || access === '') return null;
103
+ const data = this.#ensureImportedAccounts();
104
+ return data?.accounts.find((a) => a.access === access)?.id ?? null;
105
+ }
106
+
107
+ listAccounts() {
108
+ const data = this.#ensureImportedAccounts();
109
+ const now = Math.floor(Date.now() / 1000);
110
+ return (data?.accounts ?? []).map(({ id, label, expires }) => {
111
+ const normalized = normalizeExpiry(expires);
112
+ const expiresInSeconds = normalized ? normalized - now : null;
113
+ return {
114
+ id,
115
+ label: label || '未命名',
116
+ expires: normalized || null,
117
+ expiresInSeconds,
118
+ expired: expiresInSeconds !== null && expiresInSeconds <= 0,
119
+ isActive: data.activeId === id,
120
+ source: 'accounts'
121
+ };
122
+ });
123
+ }
124
+
125
+ /**
126
+ * 切換目前帳號。
127
+ *
128
+ * 原子性原則:**先把目標帳號的憑證準備好,才提交 activeId**。
129
+ * 舊版先寫 activeId 再 refresh;refresh 失敗時檔案已指向一個沒有可用 token
130
+ * 的帳號,而且快取仍留著前一帳號的 token,下一次請求就會用錯身分。
131
+ */
132
+ async switchTo(id, { expectedVersion } = {}) {
133
+ const data = this.#ensureImportedAccounts();
134
+ const startingVersion = this.#version;
135
+ const startingActiveId = data?.activeId ?? null;
136
+ if (Number.isInteger(expectedVersion) && expectedVersion !== startingVersion) return null;
137
+ const selected = data?.accounts.find((a) => a.id === id);
138
+ if (!selected) throw new Error('Account not found');
139
+
140
+ let credential = {
141
+ access: selected.access,
142
+ refresh: selected.refresh,
143
+ expires: selected.expires,
144
+ source: 'accounts',
145
+ accountId: id,
146
+ label: selected.label,
147
+ ...(selected.orgId ? { orgId: selected.orgId } : {})
148
+ };
149
+
150
+ if (needsRefresh(selected.expires)) {
151
+ if (!selected.refresh) {
152
+ // 已過期又沒有 refresh token:切過去只會拿到一個必定被上游拒絕的
153
+ // 憑證,不如直接說明,不要讓使用者以為切換成功。
154
+ throw new Error('Account expired and has no refresh token; sign in again');
155
+ }
156
+ // 只 refresh 這個帳號;結果只寫回這個帳號自己的紀錄(見 #refreshAccount)。
157
+ credential = await this.#refreshAccount(selected);
158
+ }
159
+
160
+ // refresh 期間檔案可能被別的登入/切換改寫,提交前重讀一次,避免把舊資料
161
+ // 連同 activeId 一起蓋回去,也確保目標帳號還存在。
162
+ const latest = loadAccounts(this.#accountsPath);
163
+ const target = latest?.accounts.find((a) => a.id === id);
164
+ if (!target) throw new Error('Account not found');
165
+ // Refresh may have yielded to a manual switch, another auto-switch, or an
166
+ // external store update. Never overwrite that newer active choice.
167
+ if (this.#version !== startingVersion || (Number.isInteger(expectedVersion) && this.#version !== expectedVersion)) return null;
168
+ if ((latest?.activeId ?? null) !== startingActiveId) return null;
169
+
170
+ target.lastUsedAt = Date.now();
171
+ latest.activeId = id;
172
+ saveAccounts(latest, this.#accountsPath);
173
+ this.#setCached({
174
+ access: target.access,
175
+ refresh: target.refresh,
176
+ expires: target.expires,
177
+ source: 'accounts',
178
+ accountId: id,
179
+ label: target.label,
180
+ ...(target.orgId || credential.orgId ? { orgId: target.orgId || credential.orgId } : {})
181
+ });
182
+ return this.#cachedCredential;
183
+ }
184
+
185
+ /**
186
+ * 憑證失效後切到下一個可用帳號(自動切換專用)。
187
+ *
188
+ * 回傳新憑證的快照(不含 token)或 null。只有「目標帳號的憑證已準備成功」
189
+ * 才會提交 activeId;任何一步失敗都維持原本的 active account 不變。
190
+ */
191
+ async switchToNextAccount(currentAccountId, { version } = {}) {
192
+ const data = this.#ensureImportedAccounts();
193
+ if (!data || !Array.isArray(data.accounts) || data.accounts.length < 2) return null;
194
+
195
+ // 呼叫端送出 401 的那個憑證若已經被換掉(手動切換或另一個自動切換),
196
+ // 就不要再用舊事實去輪替,免得把使用者剛選的帳號又換走。
197
+ if (Number.isInteger(version) && version !== this.#version) return null;
198
+
199
+ const candidates = data.accounts.filter(
200
+ (account) => account.id !== currentAccountId && typeof account.access === 'string' && account.access.startsWith('st_')
201
+ );
202
+
203
+ for (const candidate of candidates) {
204
+ try {
205
+ const switched = await this.switchTo(candidate.id, { expectedVersion: version });
206
+ if (!switched) return null;
207
+ return this.credentialSnapshot();
208
+ } catch {
209
+ // 目標帳號 refresh 失敗就試下一個;全部失敗則維持原帳號。
210
+ }
211
+ }
212
+ return null;
213
+ }
214
+
215
+ addAccount(cred, label) {
216
+ if (!cred?.access?.startsWith('st_')) throw new Error('An OpenCode OAuth token is required');
217
+ const data = this.#ensureImportedAccounts() || { version: 1, activeId: null, accounts: [] };
218
+ const n = data.accounts.length + 1;
219
+ let id;
220
+ do {
221
+ id = `acc-${randomBytes(4).toString('hex')}`;
222
+ } while (data.accounts.some((a) => a.id === id));
223
+
224
+ const account = {
225
+ id,
226
+ label: String(label || `帳號 ${n}`).trim(),
227
+ access: cred.access,
228
+ refresh: cred.refresh,
229
+ expires: cred.expires || 0,
230
+ addedAt: Date.now(),
231
+ lastUsedAt: Date.now(),
232
+ ...(cred.orgId ? { orgId: cred.orgId } : {})
233
+ };
234
+ data.accounts.push(account);
235
+ if (!data.activeId) data.activeId = id;
236
+ saveAccounts(data, this.#accountsPath);
237
+ if (data.activeId === id) {
238
+ this.#setCached({ ...cred, source: 'accounts', accountId: id, label: account.label });
239
+ }
240
+ return id;
241
+ }
242
+
243
+ clearCache() {
244
+ this.#setCached(null);
245
+ }
246
+
247
+ removeAccount(id) {
248
+ const data = loadAccounts(this.#accountsPath);
249
+ if (!data || data.accounts.length <= 1) throw new Error('At least one account must remain');
250
+ data.accounts = data.accounts.filter((a) => a.id !== id);
251
+ if (data.accounts.length === (loadAccounts(this.#accountsPath)?.accounts.length ?? 0)) {
252
+ throw new Error('Account not found');
253
+ }
254
+ if (data.activeId === id) data.activeId = data.accounts[0].id;
255
+ saveAccounts(data, this.#accountsPath);
256
+ if (this.#cachedCredential?.accountId === id) this.#setCached(null);
257
+ return true;
258
+ }
259
+
260
+ #resolveCached() {
261
+ for (let attempt = 0; attempt < 2; attempt++) {
262
+ const credential = resolveCredential(this.#storePath, this.#accountsPath);
263
+ if (credential?.access) return this.#setCached(credential);
264
+ }
265
+ return null;
266
+ }
267
+
268
+ /**
269
+ * Returns a valid OpenCode OAuth access token.
270
+ * Automatically resolves from local OpenCode Desktop or DSH token file,
271
+ * and refreshes if expired or near expiration (< 5 mins).
272
+ */
273
+ async getValidToken() {
274
+ if (!this.#cachedCredential?.access) {
275
+ // resolveCredential 本身會先讀 accounts 檔;失敗再退回本機來源。
276
+ this.#resolveCached();
277
+ }
278
+
279
+ if (!this.#cachedCredential?.access) {
280
+ // Try once more in case of late file write
281
+ this.#resolveCached();
282
+ }
283
+
284
+ if (!this.#cachedCredential?.access) {
285
+ throw new Error(describeMissingCredential());
286
+ }
287
+
288
+ if (needsRefresh(this.#cachedCredential.expires) && this.#cachedCredential.refresh) {
289
+ const captured = this.#cachedCredential;
290
+ try {
291
+ await this.refresh();
292
+ } catch (err) {
293
+ // 若期間已被切換到別的帳號,就不要用前一個帳號的 DB 結果蓋掉新選擇。
294
+ if (this.#cachedCredential !== captured) {
295
+ return this.#cachedCredential?.access ?? captured.access;
296
+ }
297
+ // If refresh fails, try re-reading local DB in case Desktop app already refreshed it
298
+ const dbFresh = captured.source === 'accounts' ? null : resolveFromLocalOpenCodeDb();
299
+ if (dbFresh?.access && dbFresh.access !== captured.access) {
300
+ this.#setCached(dbFresh);
301
+ } else {
302
+ // Log and continue with existing access token as last resort
303
+ console.warn('[opencode-next] Token refresh failed, trying existing token:', err.message);
304
+ }
305
+ }
306
+ }
307
+
308
+ return this.#cachedCredential.access;
309
+ }
310
+
311
+ /**
312
+ * 取得「送出請求當下」的憑證與身分快照。adapter 用它把 401、refresh、
313
+ * 切換三者綁在同一個帳號上,避免跨帳號歸因。
314
+ */
315
+ async acquireCredential() {
316
+ const token = await this.getValidToken();
317
+ return { token, ...this.credentialSnapshot() };
318
+ }
319
+
320
+ /**
321
+ * 明確刷新目前憑證(公開 API,回傳 token 字串)。
322
+ */
323
+ async refresh() {
324
+ let captured = this.#cachedCredential;
325
+ if (!captured?.access) captured = this.#resolveCached();
326
+ if (!captured?.access) throw new Error(describeMissingCredential());
327
+ return this.#refreshCaptured(captured);
328
+ }
329
+
330
+ /**
331
+ * 只刷新「送出請求時所使用」的那個憑證。
332
+ *
333
+ * 回傳 `{ stale: true }` 代表等待期間目前帳號已被換掉,呼叫端不該把這次
334
+ * 刷新結果或隨後的切換歸因給原本的請求。成功時回傳新的 token 與版本,
335
+ * 讓 adapter 能用新版本做下一次 CAS。
336
+ */
337
+ async refreshCredential(snapshot) {
338
+ const captured = this.#cachedCredential;
339
+ if (!captured?.access) throw new Error(describeMissingCredential());
340
+
341
+ if (
342
+ snapshot &&
343
+ Number.isInteger(snapshot.version) &&
344
+ snapshot.version !== this.#version
345
+ ) {
346
+ return { stale: true };
347
+ }
348
+ if (snapshot?.accountId && captured.accountId !== snapshot.accountId) {
349
+ return { stale: true };
350
+ }
351
+
352
+ const token = await this.#refreshCaptured(captured);
353
+ const current = this.#cachedCredential;
354
+ if (!current?.access) return { stale: true };
355
+
356
+ // 帳號來源比 accountId;非帳號來源(DB/token 檔)只能比來源。
357
+ const sameIdentity = snapshot?.accountId
358
+ ? current.accountId === snapshot.accountId
359
+ : current.source === captured.source;
360
+ if (!sameIdentity) return { stale: true };
361
+
362
+ return {
363
+ token,
364
+ version: this.#version,
365
+ accountId: current.accountId ?? null,
366
+ source: current.source ?? null
367
+ };
368
+ }
369
+
370
+ #refreshCaptured(captured) {
371
+ if (captured.source === 'accounts' && captured.accountId) {
372
+ return this.#refreshAccount(captured).then((credential) => credential.access);
373
+ }
374
+
375
+ const inFlight = this.#credentialRefreshes.get(captured);
376
+ if (inFlight) return inFlight.then((credential) => credential.access);
377
+
378
+ const entry = { promise: null };
379
+ entry.promise = (async () => {
380
+ // 先看看本機 DB 是不是已經有新 token(Desktop 可能已自行刷新)。
381
+ const dbFresh = resolveFromLocalOpenCodeDb();
382
+ if (dbFresh?.access && dbFresh.access !== captured.access) {
383
+ if (this.#cachedCredential === captured) this.#setCached(dbFresh);
384
+ return dbFresh;
385
+ }
386
+
387
+ if (!captured.refresh) throw new Error('Cannot refresh token: no refresh token available');
388
+ const refreshed = await this.#refreshAccessToken(captured.refresh);
389
+ const next = {
390
+ access: refreshed.access_token,
391
+ refresh: refreshed.refresh_token ?? captured.refresh,
392
+ expires: Math.floor(Date.now() / 1000) + (refreshed.expires_in || 3600),
393
+ source: captured.source
394
+ };
395
+ if (captured.source === 'dsh-token-file') saveDshTokenFile(next, this.#storePath);
396
+ // CAS:只有目前快取仍是「我刷的那一個」才替換;期間被切換就只回傳 token
397
+ // 給原本的請求,不覆蓋新的 active 帳號。
398
+ if (this.#cachedCredential === captured) this.#setCached(next);
399
+ return next;
400
+ })();
401
+
402
+ this.#credentialRefreshes.set(captured, entry.promise);
403
+ entry.promise
404
+ .catch(() => {})
405
+ .finally(() => {
406
+ if (this.#credentialRefreshes.get(captured) === entry.promise) {
407
+ this.#credentialRefreshes.delete(captured);
408
+ }
409
+ });
410
+ return entry.promise.then((credential) => credential.access);
411
+ }
412
+
413
+ /**
414
+ * 刷新單一帳號。以 account.id 做單飛,並只把結果寫回該帳號自己的紀錄。
415
+ * 回傳完整憑證物件(含新 access/refresh/expires 與身分)。
416
+ */
417
+ #refreshAccount(account) {
418
+ if (!account.refresh) {
419
+ return Promise.reject(new Error('Cannot refresh token: no refresh token available'));
420
+ }
421
+
422
+ // 呼叫端可能傳入快取憑證(身分鍵是 accountId)或帳號紀錄(身分鍵是 id)。
423
+ // 兩者必須先正規化成同一個帳號 id,否則寫回時永遠找不到紀錄。
424
+ const accountKey = account.id || account.accountId;
425
+ if (!accountKey) {
426
+ return Promise.reject(new Error('Cannot refresh token: account identity is missing'));
427
+ }
428
+
429
+ const inFlight = this.#accountRefreshes.get(accountKey);
430
+ if (inFlight) return inFlight;
431
+
432
+ const entry = { promise: null };
433
+ entry.promise = (async () => {
434
+ // accounts 帳號一律用自己的 refresh token 換,不採用本機 DB 的 token:
435
+ // DB 的 token 不屬於任何已綁定帳號,拿來寫進特定帳號就是跨帳號污染。
436
+ const refreshed = await this.#refreshAccessToken(account.refresh);
437
+ const next = {
438
+ access: refreshed.access_token,
439
+ refresh: refreshed.refresh_token ?? account.refresh,
440
+ expires: Math.floor(Date.now() / 1000) + (refreshed.expires_in || 3600),
441
+ ...(refreshed.org_id ? { orgId: refreshed.org_id } : {})
442
+ };
443
+
444
+ // 只寫回這個 id 的紀錄。若等待期間帳號被刪除,什麼都不寫。
445
+ const latest = loadAccounts(this.#accountsPath);
446
+ const target = latest?.accounts.find((a) => a.id === accountKey);
447
+ if (!target) throw new Error('Account not found');
448
+ // If another writer refreshed/replaced this account while the network call
449
+ // was pending, retain that newer record instead of overwriting it.
450
+ if (target.access !== account.access || target.refresh !== account.refresh) {
451
+ const newer = {
452
+ access: target.access,
453
+ refresh: target.refresh,
454
+ expires: target.expires,
455
+ source: 'accounts',
456
+ accountId: target.id,
457
+ label: target.label,
458
+ ...(target.orgId ? { orgId: target.orgId } : {})
459
+ };
460
+ if (this.#cachedCredential === account
461
+ || this.#cachedCredential?.accountId === accountKey) this.#setCached(newer);
462
+ return newer;
463
+ }
464
+ target.access = next.access;
465
+ target.refresh = next.refresh;
466
+ target.expires = next.expires;
467
+ target.lastUsedAt = Date.now();
468
+ if (next.orgId) target.orgId = next.orgId;
469
+ saveAccounts(latest, this.#accountsPath);
470
+
471
+ const credential = {
472
+ access: target.access,
473
+ refresh: target.refresh,
474
+ expires: target.expires,
475
+ source: 'accounts',
476
+ accountId: target.id,
477
+ label: target.label,
478
+ ...(target.orgId ? { orgId: target.orgId } : {})
479
+ };
480
+
481
+ // 只有這個帳號仍是目前帳號時才更新快取;否則保持別人的 active 不變。
482
+ if (this.#cachedCredential === account
483
+ || this.#cachedCredential?.accountId === accountKey) this.#setCached(credential);
484
+ return credential;
485
+ })();
486
+
487
+ this.#accountRefreshes.set(accountKey, entry.promise);
488
+ entry.promise
489
+ .catch(() => {})
490
+ .finally(() => {
491
+ if (this.#accountRefreshes.get(accountKey) === entry.promise) {
492
+ this.#accountRefreshes.delete(accountKey);
493
+ }
494
+ });
495
+ return entry.promise;
496
+ }
497
+
498
+ setCredential(cred) {
499
+ this.#setCached(cred);
500
+ if (cred.source === 'dsh-token-file') {
501
+ saveDshTokenFile(cred, this.#storePath);
502
+ }
503
+ }
504
+
505
+ getCached() {
506
+ return this.#cachedCredential;
507
+ }
508
+
509
+ /**
510
+ * 描述目前憑證的狀態,**刻意不含 token 本身**。
511
+ *
512
+ * 狀態頁是在瀏覽器裡渲染的:任何它讀得到的東西都可能經由截圖或 devtools
513
+ * 外流。所以這裡只回答「有沒有憑證、從哪裡來、什麼時候過期」,
514
+ * 絕不回傳 access/refresh 的值。畫面要顯示「已登入」不需要看見密鑰。
515
+ *
516
+ * 順便重新解析一次來源,這樣使用者在 OpenCode Desktop 登入後打開狀態頁,
517
+ * 看到的就是現在的事實,而不是外掛啟動當下的舊快取。
518
+ */
519
+ describeCredential() {
520
+ let credential = this.#cachedCredential;
521
+
522
+ if (!credential?.access) {
523
+ try {
524
+ credential = resolveCredential(this.#storePath);
525
+ } catch {
526
+ credential = null;
527
+ }
528
+ }
529
+
530
+ if (!credential?.access) {
531
+ return {
532
+ present: false,
533
+ source: null,
534
+ hasRefresh: false,
535
+ expiresAt: null,
536
+ expiresInSeconds: null,
537
+ expiringSoon: false,
538
+ expired: false
539
+ };
540
+ }
541
+
542
+ const normalized = normalizeExpiry(credential.expires);
543
+ const nowSec = Math.floor(Date.now() / 1000);
544
+ const expiresInSeconds = normalized > 0 ? normalized - nowSec : null;
545
+
546
+ return {
547
+ present: true,
548
+ source: credential.source ?? null,
549
+ accountLabel: credential.label ?? null,
550
+ accountCount: loadAccounts(this.#accountsPath)?.accounts.length ?? 0,
551
+ hasRefresh: Boolean(credential.refresh),
552
+ expiresAt: normalized > 0 ? normalized : null,
553
+ expiresInSeconds,
554
+ // 與 getValidToken 的門檻一致(5 分鐘),避免狀態頁顯示「正常」
555
+ // 但下一次請求其實已經觸發刷新。
556
+ expiringSoon: expiresInSeconds !== null && expiresInSeconds < REFRESH_THRESHOLD_SECONDS,
557
+ expired: expiresInSeconds !== null && expiresInSeconds <= 0
558
+ };
559
+ }
560
+ }