@amenophis1er/mailcore 0.2.0 → 0.3.0
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.
- package/README.md +1 -1
- package/index.d.ts +2 -2
- package/package.json +6 -3
- package/src/google-auth.js +9 -2
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ mailboxes signed in with OAuth. Push (EWS streaming notifications, IMAP IDLE, JM
|
|
|
6
6
|
local cache (SQLCipher), search, plain-text reads, threads, attachments, drafts and send, calendars (list, events,
|
|
7
7
|
free/busy, free slots, create/update/delete/respond), and MCP-ready tools for agents.
|
|
8
8
|
|
|
9
|
-
Plain JS ESM, with types in `index.d.ts`. Node
|
|
9
|
+
Plain JS ESM, with types in `index.d.ts`. Node 22 or later.
|
|
10
10
|
|
|
11
11
|
**mailcore never reads a config file, a keychain, a password manager or the environment.** The caller hands in
|
|
12
12
|
the accounts, a credentials provider, the cache key and a data directory.
|
package/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export interface GoogleTokens {
|
|
|
95
95
|
/** the scopes granted, space-separated (the token response's `scope`) */
|
|
96
96
|
scope?: string;
|
|
97
97
|
signed_in_at?: string;
|
|
98
|
-
/** when Google refused to renew it (invalid_grant) */
|
|
98
|
+
/** when Google refused to renew it (invalid_grant, or unauthorized_client: a sign-in of another OAuth client) */
|
|
99
99
|
refused_at?: string;
|
|
100
100
|
[extra: string]: unknown;
|
|
101
101
|
}
|
|
@@ -725,7 +725,7 @@ export class Mailcore {
|
|
|
725
725
|
beginLogin(account: string, opts?: GoogleSignInOptions): Promise<GoogleSignIn>;
|
|
726
726
|
signedIn(account: string): Promise<boolean>;
|
|
727
727
|
/** What is known of the account's sign-in, without a secret (null: not signed in). */
|
|
728
|
-
tokens(account: string): Promise<{ scopes: string[]; signedInAt?: string; /** Google refused its renewal (invalid_grant) since */ refusedAt?: string } | null>;
|
|
728
|
+
tokens(account: string): Promise<{ scopes: string[]; signedInAt?: string; /** Google refused its renewal (invalid_grant or unauthorized_client) since */ refusedAt?: string } | null>;
|
|
729
729
|
/** What a Google auth error of this account tells the user to do. */
|
|
730
730
|
signInHint(account: string): string;
|
|
731
731
|
/** The account's Google contacts (People API: its own, and its "other contacts"), over its tokens. See googleContacts. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amenophis1er/mailcore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Mail and calendar accounts for Node: Exchange (EWS), IMAP/SMTP, JMAP, CalDAV, Google and Microsoft 365, with push, an encrypted cache, drafts and MCP-ready tools. The caller supplies accounts and secrets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/amenophis1er/mailcore/issues"
|
|
21
21
|
},
|
|
22
|
-
"repository":
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/amenophis1er/mailcore.git"
|
|
25
|
+
},
|
|
23
26
|
"license": "MIT",
|
|
24
27
|
"author": "908 Studio <hello@sideora.com>",
|
|
25
28
|
"type": "module",
|
|
@@ -42,7 +45,7 @@
|
|
|
42
45
|
"README.md"
|
|
43
46
|
],
|
|
44
47
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
48
|
+
"node": ">=22"
|
|
46
49
|
},
|
|
47
50
|
"scripts": {
|
|
48
51
|
"test": "node --test",
|
package/src/google-auth.js
CHANGED
|
@@ -128,7 +128,8 @@ export function googleAuth({ store, clientId, clientSecret, client: clientOf, si
|
|
|
128
128
|
/**
|
|
129
129
|
* What is known of an account's sign-in, without a secret: whether it holds
|
|
130
130
|
* a refresh token, the scopes granted, when it signed in, and whether Google
|
|
131
|
-
* refused it since (`refusedAt`: an invalid_grant
|
|
131
|
+
* refused it since (`refusedAt`: an invalid_grant, or an unauthorized_client — a sign-in of another OAuth
|
|
132
|
+
* client — on renewal). null: none.
|
|
132
133
|
*/
|
|
133
134
|
async function tokens(account) {
|
|
134
135
|
let t;
|
|
@@ -276,7 +277,13 @@ export function googleAuth({ store, clientId, clientSecret, client: clientOf, si
|
|
|
276
277
|
try {
|
|
277
278
|
fresh = await tokenRequest({ client_id: clientId, client_secret: clientSecret, refresh_token: t.refresh_token, grant_type: 'refresh_token' });
|
|
278
279
|
} catch (err) {
|
|
279
|
-
|
|
280
|
+
// invalid_client: the app's own OAuth client is wrong (its id or secret): no sign-in can help, and no account
|
|
281
|
+
// is marked for it; once the client is right, the next renewal works as before.
|
|
282
|
+
if (/invalid_client/.test(err.message)) throw new Error(`Google refused the app's OAuth client (invalid_client): check its client id and secret. ${err.message}`);
|
|
283
|
+
// invalid_grant: the sign-in was revoked or expired; unauthorized_client: it belongs to another OAuth client
|
|
284
|
+
// than the one asked with now (an app that changed its client). Either way only a new sign-in helps, and the
|
|
285
|
+
// account says so rather than failing on every call.
|
|
286
|
+
if (/invalid_grant|unauthorized_client/.test(err.message)) {
|
|
280
287
|
// a sign-in since replaced the tokens that were refused: those are the account's now
|
|
281
288
|
const now = await load(account);
|
|
282
289
|
if (now?.refresh_token && now.refresh_token !== t.refresh_token) return accessToken(account, { force: false });
|