@bobfrankston/mailx-imap 0.1.49 → 0.1.50

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.
Files changed (2) hide show
  1. package/index.js +12 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4309,16 +4309,20 @@ export class ImapManager extends EventEmitter {
4309
4309
  const res = await fetch(url, {
4310
4310
  headers: { Authorization: `Bearer ${token}` },
4311
4311
  });
4312
- if (res.status === 410) {
4313
- // Sync token expired (Google retains tokens for ~7 days).
4314
- // Drop the stored token and recurse for a full sync — the
4315
- // in-flight guard is on syncGoogleContacts (the public
4316
- // wrapper), not Impl, so recursion is safe.
4317
- this.db.setKv("contacts", accountId, null);
4318
- return this.syncGoogleContactsImpl(accountId);
4319
- }
4320
4312
  if (!res.ok) {
4321
4313
  const err = await res.text();
4314
+ // Expired sync token. The People API returns HTTP 400
4315
+ // FAILED_PRECONDITION with reason EXPIRED_SYNC_TOKEN
4316
+ // (older docs / older behavior said 410 — handle both
4317
+ // by inspecting the body). The documented recovery is:
4318
+ // drop the token and re-call WITHOUT it (full sync).
4319
+ // The `syncToken` guard prevents infinite recursion if a
4320
+ // tokenless full sync itself somehow returns this.
4321
+ if (syncToken && /EXPIRED_SYNC_TOKEN|sync token is expired/i.test(err)) {
4322
+ console.log(` [contacts] ${accountId}: sync token expired — clearing for full resync`);
4323
+ this.db.setKv("contacts", accountId, null);
4324
+ return this.syncGoogleContactsImpl(accountId);
4325
+ }
4322
4326
  console.error(` [contacts] API error for ${accountId}: ${res.status} ${err}`);
4323
4327
  return changed;
4324
4328
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-imap",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",