@blackbelt-technology/pi-dashboard-gmail-plugin 0.10.0 → 0.12.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 +22 -37
- package/package.json +9 -4
- package/src/bridge/gmail-api.ts +23 -0
- package/src/bridge/lease-client.ts +127 -7
- package/src/bridge/tools.ts +217 -9
- package/src/client/GmailSettings.tsx +51 -735
- package/src/configSchema.json +14 -1
- package/src/i18n.ts +9 -205
- package/src/server/accounts.ts +37 -0
- package/src/server/google-link.ts +81 -0
- package/src/server/google-oauth.ts +8 -3
- package/src/server/index.ts +31 -14
- package/src/server/lease.ts +8 -3
- package/src/server/routes.ts +36 -188
- package/src/shared/client-json.ts +5 -3
- package/src/shared/protocol.ts +20 -0
- package/src/shared/scopes.ts +22 -6
- package/src/shared/setup.ts +43 -0
- package/src/client/wizard.ts +0 -136
- package/src/server/gmail-rest.ts +0 -27
- package/src/shared/flow-codes.ts +0 -36
package/src/configSchema.json
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"properties": {
|
|
4
|
+
"projectId": {
|
|
5
|
+
"type": "string",
|
|
6
|
+
"description": "Google Cloud project id of the OAuth client (saved by the setup wizard)."
|
|
7
|
+
},
|
|
8
|
+
"ownerAccount": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Email of the Google account that owns the project; sets authuser on console links and --account on gcloud commands."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"additionalProperties": false
|
|
14
|
+
}
|
package/src/i18n.ts
CHANGED
|
@@ -2,216 +2,20 @@
|
|
|
2
2
|
* Gmail plugin i18n catalog — UNPREFIXED leaf keys, merged by the shell under
|
|
3
3
|
* `plugin.gmail.*`; components resolve via the scoped `useT()`. English lives
|
|
4
4
|
* at the call sites as the fallback. `zh-CN` and `hu` MUST keep identical key
|
|
5
|
-
* sets (scripts/i18n-parity).
|
|
5
|
+
* sets (scripts/i18n-parity). Account / client / setup management moved to the
|
|
6
|
+
* Google plugin, so only the pointer notice is left. See change: add-google-connect.
|
|
6
7
|
*/
|
|
7
8
|
export const catalog = {
|
|
8
9
|
"zh-CN": {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
aliasPlaceholder: "别名",
|
|
13
|
-
aliasSaved: "已保存",
|
|
14
|
-
audienceErrors:
|
|
15
|
-
"Google 错误页面:org_internal = 账户不属于该组织,请改为“外部”;access_denied = 将账户添加为测试用户;admin_policy_enforced = 该账户的 Workspace 管理员必须信任此 OAuth 客户端。",
|
|
16
|
-
audienceHelp:
|
|
17
|
-
"“内部”仅允许项目所属 Workspace 组织的账户:只有当你要连接的每个账户都属于该组织时才选择它。否则选择“外部”,并将要连接的每个地址添加为测试用户。测试模式下令牌 7 天后过期;“发布应用”可获得更长期的令牌,但会显示未验证应用警告。",
|
|
18
|
-
clientHelp: "应用类型:桌面应用。下载 JSON。若链接已变更:API 和服务 → 凭据。",
|
|
19
|
-
consentHint: "在 Google 同意屏幕上勾选每一项权限(全选)。Gmail 权限可能默认未勾选。",
|
|
20
|
-
copied: "已复制",
|
|
21
|
-
copy: "复制",
|
|
22
|
-
copyFailed: "复制失败",
|
|
23
|
-
createProject: "创建项目",
|
|
24
|
-
crossOrgHint: "项目 Workspace 组织之外的账户需要“外部”目标对象,并将每个账户添加为测试用户(第 3 步)。",
|
|
25
|
-
enableGmail: "启用 Gmail API",
|
|
26
|
-
errAborted: "登录已中止。",
|
|
27
|
-
errAccessDenied: "Google 拒绝了访问:该账户不是允许的测试用户,或拒绝了同意。请将账户添加为测试用户(第 3 步)后重试。",
|
|
28
|
-
errAccountMismatch: "你登录了另一个 Google 账户。请使用该行显示的账户重新验证。",
|
|
29
|
-
errAdminPolicy: "此账户的 Google Workspace 管理员阻止了该应用。请让该管理员信任 OAuth 客户端 {clientId}(管理控制台 → 安全 → API 控制 → 应用访问控制)。",
|
|
30
|
-
errAliasTaken: "该别名已被其他账户使用。",
|
|
31
|
-
errAuthorization: "Google 报告了登录错误。请重试;若反复出现,请检查上面的设置步骤。",
|
|
32
|
-
errBadClientId: "客户端 ID 不以 .apps.googleusercontent.com 结尾(第 4 步)。",
|
|
33
|
-
errCallbackFailed: "登录回调失败。请重试。",
|
|
34
|
-
errCancelled: "登录已取消。",
|
|
35
|
-
errClientInUse: "当前客户端下已连接账户。请先撤销它们,再上传其他客户端。",
|
|
36
|
-
errEmailUnverified: "Google 报告此账户的电子邮件未验证。请在 Google 完成验证后重试。",
|
|
37
|
-
errGeneric: "登录失败。请重试;若一直失败,请检查上面的设置步骤。",
|
|
38
|
-
errIdToken: "无法验证 Google 的登录响应。请重试。",
|
|
39
|
-
errInvalidAlias: "别名为 1–40 个字母、数字、“.”、“_”或“-”。",
|
|
40
|
-
errInvalidClient: "Google 无法识别该 OAuth 客户端。请重新下载其 JSON 并上传(第 5 步)。",
|
|
41
|
-
errInvalidRedirect: "粘贴的地址不是 Google 发送的重定向。请粘贴浏览器地址栏中的完整 URL。",
|
|
42
|
-
errLoginFailed: "无法开始登录。请重试。",
|
|
43
|
-
errMissingRefresh: "Google 未返回长期令牌。请在 myaccount.google.com/permissions 撤销该应用,然后重新添加账户。",
|
|
44
|
-
errMissingSecret: "文件中没有客户端密钥。请从客户端页面重新下载(第 5 步)。",
|
|
45
|
-
errNotInstalled: "此文件中没有桌面(installed)客户端。请创建桌面应用客户端(第 4 步)。",
|
|
46
|
-
errNotJson: "该文件不是有效的 JSON。请上传你下载的 client_secret_*.json(第 5 步)。",
|
|
47
|
-
errOrgInternal: "Google 阻止了此账户:OAuth 应用的目标对象为“内部”,仅允许项目所属 Workspace 组织的账户。请将目标对象改为“外部”,并将此账户添加为测试用户(第 3 步)。",
|
|
48
|
-
errRedirectMismatch: "Google 拒绝了重定向地址。请创建桌面应用客户端,而不是 Web 客户端(第 4 步)。",
|
|
49
|
-
errScopeMissing: "Google 未授予 Gmail 权限。请重新添加账户,并在 Google 同意屏幕上勾选每一项权限。",
|
|
50
|
-
errStartTimeout: "登录未能及时开始。请重试。",
|
|
51
|
-
errStateMismatch: "粘贴的重定向属于另一次登录。请重新开始,并粘贴本次登录的 URL。",
|
|
52
|
-
errTimeout: "等待 Google 超时。如果 Google 显示了错误页面,请通过登录链接下方的选项报告。",
|
|
53
|
-
errTokenExchange: "Google 拒绝交换登录代码。请检查上传的客户端(第 5 步)后重试。",
|
|
54
|
-
errWebClient: "这是 Web 应用客户端。请改为创建桌面应用客户端(第 4 步)。",
|
|
55
|
-
fallback2: "若链接已变更:API 和服务 → OAuth 同意屏幕。",
|
|
56
|
-
googleErrorHelp: "选择 Google 显示的错误代码:",
|
|
57
|
-
googleErrorSummary: "Google 显示了错误而没有返回这里?",
|
|
58
|
-
level: "级别",
|
|
59
|
-
levelHelp:
|
|
60
|
-
"级别由本插件执行,而非 Google:令牌带有 Google 授予的全部范围(draft 级的撰写权限理论上也能发送),因此级别限制的是代理工具可以做什么。此仪表盘上的任何会话都可以在级别范围内使用每个账户。",
|
|
61
|
-
loading: "加载中…",
|
|
62
|
-
newLevel: "新账户的级别",
|
|
63
|
-
noAccounts: "尚未连接账户。",
|
|
64
|
-
openAudience: "打开“目标对象”",
|
|
65
|
-
openBranding: "打开“品牌”",
|
|
66
|
-
openClients: "创建客户端",
|
|
67
|
-
projectId: "项目 ID",
|
|
68
|
-
reauth: "重新验证",
|
|
69
|
-
reportOther: "其他错误",
|
|
70
|
-
revoke: "撤销",
|
|
71
|
-
revokeConfirm: "撤销 {email}?仪表盘将忘记该账户,并请求 Google 撤销其访问权限。",
|
|
72
|
-
revokedOk: "{email} 已移除,并已在 Google 撤销访问权限。",
|
|
73
|
-
revokeManual: "{email} 已在本地移除,但无法连接 Google。请在 myaccount.google.com/permissions 撤销访问权限。",
|
|
74
|
-
setup: "Google Cloud 设置",
|
|
75
|
-
statusOk: "已连接",
|
|
76
|
-
statusReauth: "需要重新验证",
|
|
77
|
-
stepDone: "已完成",
|
|
78
|
-
aliasFor: "{email} 的别名",
|
|
79
|
-
levelFor: "{email} 的级别",
|
|
80
|
-
revokeFor: "撤销 {email}",
|
|
81
|
-
reauthFor: "重新验证 {email}",
|
|
82
|
-
addAccountDisabled: "上传 OAuth 客户端 JSON(上面第 5 步)后即可使用。",
|
|
83
|
-
step1: "1. Google Cloud 项目 + Gmail API",
|
|
84
|
-
step2: "2. 品牌",
|
|
85
|
-
step3: "3. 目标对象 + 测试用户",
|
|
86
|
-
step4: "4. 桌面 OAuth 客户端",
|
|
87
|
-
step5: "5. 上传 client_secret_*.json",
|
|
88
|
-
step6: "6. 测试登录",
|
|
89
|
-
step6Help: "在下方添加第一个账户 —— 这就是测试登录。",
|
|
90
|
-
summaryClient: "✓ {clientId}",
|
|
91
|
-
summaryNotConfigured: "未配置",
|
|
92
|
-
summaryProject: "✓ 项目 {projectId}",
|
|
93
|
-
testingBadge: "测试:7 天",
|
|
94
|
-
testingHint: "测试模式应用:Google 会在 7 天后使此授权过期。",
|
|
95
|
-
tierDraft: "读取 + 创建草稿",
|
|
96
|
-
tierReadonly: "读取邮件",
|
|
97
|
-
tierSend: "读取、草稿、发送、回复、标签、归档、删除",
|
|
10
|
+
googleOff: "请开启 Google 账户以管理 Gmail 账户",
|
|
11
|
+
movedLink: "打开 Google 账户",
|
|
12
|
+
movedNotice: "Gmail 账户现在在“设置 → Google 账户”中管理。无需重新连接。",
|
|
98
13
|
title: "Gmail",
|
|
99
|
-
uploadLabel: "上传 OAuth 客户端 JSON",
|
|
100
|
-
withGcloud: "使用 gcloud(请自行运行):",
|
|
101
|
-
withoutGcloud: "不使用 gcloud:",
|
|
102
14
|
},
|
|
103
15
|
hu: {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
aliasPlaceholder: "álnév",
|
|
108
|
-
aliasSaved: "Mentve",
|
|
109
|
-
audienceErrors:
|
|
110
|
-
"Google hibaoldalak: org_internal = a fiók a szervezeten kívül van, válts Külsőre; access_denied = vedd fel a fiókot tesztfelhasználóként; admin_policy_enforced = a fiók Workspace-adminisztrátorának meg kell bíznia ebben az OAuth-ügyfélben.",
|
|
111
|
-
audienceHelp:
|
|
112
|
-
"A Belső csak a projekt saját Workspace-szervezetének fiókjait engedi be: csak akkor válaszd, ha minden csatlakoztatandó fiók ehhez a szervezethez tartozik. Egyébként válaszd a Külsőt, és vedd fel tesztfelhasználóként minden csatlakoztatandó címet. Tesztelés módban a tokenek 7 nap után lejárnak; az „Alkalmazás közzététele” hosszabb életű tokeneket ad, nem ellenőrzött alkalmazás figyelmeztetéssel.",
|
|
113
|
-
clientHelp:
|
|
114
|
-
"Alkalmazástípus: Asztali alkalmazás. Töltsd le a JSON-t. Ha a link elköltözött: API-k és szolgáltatások → Hitelesítő adatok.",
|
|
115
|
-
consentHint:
|
|
116
|
-
"A Google hozzájárulási képernyőjén pipálj be minden engedélyt (Összes kijelölése). A Gmail-engedély kezdetben kipipálatlan lehet.",
|
|
117
|
-
copied: "Másolva",
|
|
118
|
-
copy: "Másolás",
|
|
119
|
-
copyFailed: "A másolás nem sikerült",
|
|
120
|
-
createProject: "Projekt létrehozása",
|
|
121
|
-
crossOrgHint:
|
|
122
|
-
"A projekt Workspace-szervezetén kívüli fiókokhoz Külső célközönség kell, minden fiókot tesztfelhasználóként felvéve (3. lépés).",
|
|
123
|
-
enableGmail: "Gmail API engedélyezése",
|
|
124
|
-
errAborted: "A bejelentkezés megszakadt.",
|
|
125
|
-
errAccessDenied:
|
|
126
|
-
"A Google megtagadta a hozzáférést: a fiók nem engedélyezett tesztfelhasználó, vagy elutasították a hozzájárulást. Vedd fel a fiókot tesztfelhasználóként (3. lépés), és próbáld újra.",
|
|
127
|
-
errAccountMismatch: "Másik Google-fiókkal jelentkeztél be. Hitelesíts újra a sorban látható fiókkal.",
|
|
128
|
-
errAdminPolicy:
|
|
129
|
-
"A fiók Google Workspace-adminisztrátora letiltja az alkalmazást. Kérd meg, hogy bízzon meg a(z) {clientId} OAuth-ügyfélben (Felügyeleti konzol → Biztonság → API-vezérlők → Alkalmazás-hozzáférés).",
|
|
130
|
-
errAliasTaken: "Ezt az álnevet már egy másik fiók használja.",
|
|
131
|
-
errAuthorization:
|
|
132
|
-
"A Google bejelentkezési hibát jelzett. Próbáld újra; ha ismétlődik, ellenőrizd a fenti beállítási lépéseket.",
|
|
133
|
-
errBadClientId: "Az ügyfél-azonosító nem .apps.googleusercontent.com végződésű (4. lépés).",
|
|
134
|
-
errCallbackFailed: "A bejelentkezési visszahívás sikertelen. Próbáld újra.",
|
|
135
|
-
errCancelled: "A bejelentkezés megszakítva.",
|
|
136
|
-
errClientInUse:
|
|
137
|
-
"A jelenlegi ügyféllel fiókok vannak csatlakoztatva. Előbb vond vissza őket, majd tölts fel másik ügyfelet.",
|
|
138
|
-
errEmailUnverified:
|
|
139
|
-
"A Google szerint a fiók e-mail-címe nincs ellenőrizve. Ellenőrizd a Google-nál, majd próbáld újra.",
|
|
140
|
-
errGeneric:
|
|
141
|
-
"A bejelentkezés sikertelen. Próbáld újra; ha továbbra is hibázik, ellenőrizd a fenti beállítási lépéseket.",
|
|
142
|
-
errIdToken: "A Google bejelentkezési válasza nem ellenőrizhető. Próbáld újra.",
|
|
143
|
-
errInvalidAlias: "Az álnév 1–40 betű, számjegy, '.', '_' vagy '-'.",
|
|
144
|
-
errInvalidClient: "A Google nem ismeri fel az OAuth-ügyfelet. Töltsd le újra a JSON-t, és töltsd fel (5. lépés).",
|
|
145
|
-
errInvalidRedirect:
|
|
146
|
-
"A beillesztett cím nem a Google által küldött átirányítás. Illeszd be a böngésző címsorából a teljes URL-t.",
|
|
147
|
-
errLoginFailed: "A bejelentkezés nem indult el. Próbáld újra.",
|
|
148
|
-
errMissingRefresh:
|
|
149
|
-
"A Google nem adott hosszú életű tokent. Vond vissza az alkalmazást a myaccount.google.com/permissions oldalon, majd add hozzá újra a fiókot.",
|
|
150
|
-
errMissingSecret: "A fájlban nincs ügyféltitok. Töltsd le újra az ügyfél oldaláról (5. lépés).",
|
|
151
|
-
errNotInstalled: "A fájlban nincs asztali (installed) ügyfél. Hozz létre asztali alkalmazás ügyfelet (4. lépés).",
|
|
152
|
-
errNotJson: "A fájl nem érvényes JSON. Töltsd fel a letöltött client_secret_*.json fájlt (5. lépés).",
|
|
153
|
-
errOrgInternal:
|
|
154
|
-
"A Google letiltotta ezt a fiókot: az OAuth-alkalmazás célközönsége Belső, amely csak a projekt saját Workspace-szervezetének fiókjait engedi be. Állítsd a célközönséget Külsőre, és vedd fel ezt a fiókot tesztfelhasználóként (3. lépés).",
|
|
155
|
-
errRedirectMismatch:
|
|
156
|
-
"A Google elutasította az átirányítási címet. Asztali alkalmazás ügyfelet hozz létre, ne webes ügyfelet (4. lépés).",
|
|
157
|
-
errScopeMissing:
|
|
158
|
-
"A Google nem adta meg a Gmail-engedélyt. Add hozzá újra a fiókot, és a Google hozzájárulási képernyőjén pipálj be minden engedélyt.",
|
|
159
|
-
errStartTimeout: "A bejelentkezés nem indult el időben. Próbáld újra.",
|
|
160
|
-
errStateMismatch:
|
|
161
|
-
"A beillesztett átirányítás egy másik bejelentkezéshez tartozik. Kezdd újra, és ennek a bejelentkezésnek az URL-jét illeszd be.",
|
|
162
|
-
errTimeout:
|
|
163
|
-
"Lejárt a várakozás a Google-ra. Ha a Google hibaoldalt mutatott, jelentsd a bejelentkezési link alatti lehetőséggel.",
|
|
164
|
-
errTokenExchange:
|
|
165
|
-
"A Google nem váltotta be a bejelentkezési kódot. Ellenőrizd a feltöltött ügyfelet (5. lépés), és próbáld újra.",
|
|
166
|
-
errWebClient: "Ez webalkalmazás-ügyfél. Hozz létre helyette asztali alkalmazás ügyfelet (4. lépés).",
|
|
167
|
-
fallback2: "Ha a link elköltözött: API-k és szolgáltatások → OAuth-hozzájárulási képernyő.",
|
|
168
|
-
googleErrorHelp: "Válaszd ki a Google által mutatott hibakódot:",
|
|
169
|
-
googleErrorSummary: "A Google hibát mutatott, ahelyett hogy visszairányított volna?",
|
|
170
|
-
level: "Szint",
|
|
171
|
-
levelHelp:
|
|
172
|
-
"A szinteket ez a bővítmény érvényesíti, nem a Google: a token a Google által megadott összes hatókört hordozza (a draft szintű írási jog technikailag küldhetne is), így a szint azt korlátozza, mit tehetnek az ügynök eszközei. A dashboard bármely munkamenete használhat minden fiókot a saját szintjén belül.",
|
|
173
|
-
loading: "Betöltés…",
|
|
174
|
-
newLevel: "Az új fiók szintje",
|
|
175
|
-
noAccounts: "Nincs csatlakoztatott fiók.",
|
|
176
|
-
openAudience: "Célközönség megnyitása",
|
|
177
|
-
openBranding: "Arculat megnyitása",
|
|
178
|
-
openClients: "Ügyfél létrehozása",
|
|
179
|
-
projectId: "Projektazonosító",
|
|
180
|
-
reauth: "Újrahitelesítés",
|
|
181
|
-
reportOther: "Valami más",
|
|
182
|
-
revoke: "Visszavonás",
|
|
183
|
-
revokeConfirm:
|
|
184
|
-
"Visszavonod: {email}? A dashboard elfelejti a fiókot, és kéri a Google-t a hozzáférés visszavonására.",
|
|
185
|
-
revokedOk: "{email} eltávolítva, a hozzáférés a Google-nál visszavonva.",
|
|
186
|
-
revokeManual:
|
|
187
|
-
"{email} helyben eltávolítva, de a Google nem volt elérhető. Vond vissza a hozzáférést a myaccount.google.com/permissions oldalon.",
|
|
188
|
-
setup: "Google Cloud beállítás",
|
|
189
|
-
statusOk: "Csatlakoztatva",
|
|
190
|
-
statusReauth: "Újrahitelesítés szükséges",
|
|
191
|
-
stepDone: "kész",
|
|
192
|
-
aliasFor: "{email} aliasa",
|
|
193
|
-
levelFor: "{email} szintje",
|
|
194
|
-
revokeFor: "{email} visszavonása",
|
|
195
|
-
reauthFor: "{email} újrahitelesítése",
|
|
196
|
-
addAccountDisabled: "Töltse fel az OAuth-kliens JSON-t (fent az 5. lépés), hogy ez elérhető legyen.",
|
|
197
|
-
step1: "1. Google Cloud projekt + Gmail API",
|
|
198
|
-
step2: "2. Arculat",
|
|
199
|
-
step3: "3. Célközönség + tesztfelhasználók",
|
|
200
|
-
step4: "4. Asztali OAuth-ügyfél",
|
|
201
|
-
step5: "5. client_secret_*.json feltöltése",
|
|
202
|
-
step6: "6. Próba-bejelentkezés",
|
|
203
|
-
step6Help: "Add hozzá lent az első fiókot — ez a próba-bejelentkezés.",
|
|
204
|
-
summaryClient: "✓ {clientId}",
|
|
205
|
-
summaryNotConfigured: "nincs beállítva",
|
|
206
|
-
summaryProject: "✓ projekt: {projectId}",
|
|
207
|
-
testingBadge: "teszt: 7 nap",
|
|
208
|
-
testingHint: "Tesztelés módú alkalmazás: a Google 7 nap után lejártatja ezt a hozzáférést.",
|
|
209
|
-
tierDraft: "olvasás + piszkozatok",
|
|
210
|
-
tierReadonly: "levelek olvasása",
|
|
211
|
-
tierSend: "olvasás, piszkozat, küldés, válasz, címkék, archiválás, kuka",
|
|
16
|
+
googleOff: "Kapcsold be a Google-fiókokat a Gmail-fiókok kezeléséhez",
|
|
17
|
+
movedLink: "Google-fiókok megnyitása",
|
|
18
|
+
movedNotice: "A Gmail-fiókok kezelése mostantól a Beállítások → Google-fiókok alatt történik. Nem kell újracsatlakoztatni.",
|
|
212
19
|
title: "Gmail",
|
|
213
|
-
uploadLabel: "OAuth-ügyfél JSON feltöltése",
|
|
214
|
-
withGcloud: "gcloud-dal (futtasd magad):",
|
|
215
|
-
withoutGcloud: "gcloud nélkül:",
|
|
216
20
|
},
|
|
217
|
-
};
|
|
21
|
+
} as const;
|
package/src/server/accounts.ts
CHANGED
|
@@ -13,6 +13,15 @@ import { isTier, type Tier } from "../shared/scopes.js";
|
|
|
13
13
|
|
|
14
14
|
export const CLIENT_KEY = "client";
|
|
15
15
|
const ACCT_PREFIX = "acct:";
|
|
16
|
+
/** Hand-off marker to Google Connect (add-google-connect D10); the legacy data itself is never deleted. */
|
|
17
|
+
const MIGRATED_KEY = "migrated";
|
|
18
|
+
|
|
19
|
+
export interface MigratedRecord {
|
|
20
|
+
at: number;
|
|
21
|
+
version: number;
|
|
22
|
+
/** Legacy subs already handed over — later legacy accounts (added while Google Connect was off) are not in it. */
|
|
23
|
+
subs: string[];
|
|
24
|
+
}
|
|
16
25
|
|
|
17
26
|
type AccountStatus = "ok" | "reauth_required";
|
|
18
27
|
|
|
@@ -33,6 +42,8 @@ export interface AccountRecord {
|
|
|
33
42
|
expires: number;
|
|
34
43
|
status: AccountStatus;
|
|
35
44
|
testingHint?: boolean;
|
|
45
|
+
/** Opt-in Gmail filter management (`gmail.settings.basic`); absent = off. */
|
|
46
|
+
filters?: boolean;
|
|
36
47
|
addedAt: number;
|
|
37
48
|
}
|
|
38
49
|
|
|
@@ -44,6 +55,7 @@ export interface AccountSummary {
|
|
|
44
55
|
tier: Tier;
|
|
45
56
|
status: AccountStatus;
|
|
46
57
|
testingHint?: boolean;
|
|
58
|
+
filters?: boolean;
|
|
47
59
|
addedAt: number;
|
|
48
60
|
}
|
|
49
61
|
|
|
@@ -84,6 +96,7 @@ export function summarize(a: AccountRecord): AccountSummary {
|
|
|
84
96
|
const s: AccountSummary = { sub: a.sub, email: a.email, tier: a.tier, status: a.status, addedAt: a.addedAt };
|
|
85
97
|
if (a.alias) s.alias = a.alias;
|
|
86
98
|
if (a.testingHint) s.testingHint = true;
|
|
99
|
+
if (a.filters) s.filters = true;
|
|
87
100
|
return s;
|
|
88
101
|
}
|
|
89
102
|
|
|
@@ -114,6 +127,16 @@ export class AccountStore {
|
|
|
114
127
|
await this.creds.set(CLIENT_KEY, { ...client });
|
|
115
128
|
}
|
|
116
129
|
|
|
130
|
+
async getMigrated(): Promise<MigratedRecord | undefined> {
|
|
131
|
+
const rec = await this.creds.get(MIGRATED_KEY);
|
|
132
|
+
if (!rec || typeof rec.at !== "number" || !Array.isArray(rec.subs)) return undefined;
|
|
133
|
+
return { at: rec.at, version: typeof rec.version === "number" ? rec.version : 1, subs: rec.subs.filter((s): s is string => typeof s === "string") };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async setMigrated(record: MigratedRecord): Promise<void> {
|
|
137
|
+
await this.creds.set(MIGRATED_KEY, { ...record, subs: [...record.subs] });
|
|
138
|
+
}
|
|
139
|
+
|
|
117
140
|
async list(): Promise<AccountRecord[]> {
|
|
118
141
|
const snap = await this.creds.snapshot();
|
|
119
142
|
return Object.entries(snap)
|
|
@@ -174,6 +197,16 @@ export class AccountStore {
|
|
|
174
197
|
return this.patch(sub, (prev) => ({ ...prev, tier }));
|
|
175
198
|
}
|
|
176
199
|
|
|
200
|
+
/** Turn the filters option on or off (off removes the key). */
|
|
201
|
+
async setFilters(sub: string, on: boolean): Promise<AccountRecord> {
|
|
202
|
+
return this.patch(sub, (prev) => {
|
|
203
|
+
const next = { ...prev };
|
|
204
|
+
if (on) next.filters = true;
|
|
205
|
+
else delete next.filters;
|
|
206
|
+
return next;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
177
210
|
/** Mark `reauth_required` ONLY while the record still holds the grant that failed (a concurrent re-auth wins). */
|
|
178
211
|
async markReauthIf(sub: string, failedRefresh: string): Promise<boolean> {
|
|
179
212
|
let marked = false;
|
|
@@ -220,6 +253,8 @@ export class AccountStore {
|
|
|
220
253
|
refresh?: string;
|
|
221
254
|
expires: number;
|
|
222
255
|
testingHint?: boolean;
|
|
256
|
+
/** Defined → written; undefined → the previous value is kept (Add account never changes it). */
|
|
257
|
+
filters?: boolean;
|
|
223
258
|
now?: number;
|
|
224
259
|
}): Promise<AccountRecord> {
|
|
225
260
|
let missingRefresh = false;
|
|
@@ -243,6 +278,8 @@ export class AccountStore {
|
|
|
243
278
|
};
|
|
244
279
|
if (input.testingHint) rec.testingHint = true;
|
|
245
280
|
else delete rec.testingHint;
|
|
281
|
+
if (input.filters === true) rec.filters = true;
|
|
282
|
+
else if (input.filters === false) delete rec.filters;
|
|
246
283
|
return rec;
|
|
247
284
|
});
|
|
248
285
|
if (missingRefresh) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gmail's soft link to Google Connect (add-google-connect D1/D10). Gmail declares no `dependsOn` on the
|
|
3
|
+
* `google` plugin: at the FIRST request after start it asks `consumeAll("google.connect")` for an entry whose
|
|
4
|
+
* provider is `google` (any other provider is ignored — nothing is handed over to it), hands the legacy
|
|
5
|
+
* client + accounts over once, and decides — for the life of the process — whether it delegates leases or
|
|
6
|
+
* keeps leasing from its own namespace. Enabling/disabling `google` therefore takes effect after a restart.
|
|
7
|
+
*
|
|
8
|
+
* - `usable` Google Connect is present: Gmail's management routes answer 410 `moved`.
|
|
9
|
+
* - `delegating` usable AND every legacy account is (now) in Google Connect: `gmail/lease` + `gmail/accounts`
|
|
10
|
+
* answer `{delegate:"google"}`; no fallback to legacy tokens (an imported account that was
|
|
11
|
+
* disconnected must stay disconnected).
|
|
12
|
+
* A failed / partial hand-off leaves Gmail leasing from the legacy data and is retried on the next start.
|
|
13
|
+
*/
|
|
14
|
+
import type { ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
15
|
+
import { GOOGLE_CONNECT_SERVICE, GOOGLE_PLUGIN_ID } from "../shared/protocol.js";
|
|
16
|
+
import type { AccountStore } from "./accounts.js";
|
|
17
|
+
|
|
18
|
+
const MIGRATION_VERSION = 1;
|
|
19
|
+
|
|
20
|
+
/** Structural mirror of the google plugin's `importLegacyGmail` (no import edge between the plugins). */
|
|
21
|
+
interface LegacyImporter {
|
|
22
|
+
importLegacyGmail(snapshot: { client?: unknown; accounts: unknown[] }): Promise<
|
|
23
|
+
{ ok: true; imported: number; skipped: number } | { ok: false; error: string }
|
|
24
|
+
>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface LinkState {
|
|
28
|
+
usable: boolean;
|
|
29
|
+
delegating: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface GoogleLink {
|
|
33
|
+
ensure(): Promise<LinkState>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createGoogleLink(deps: {
|
|
37
|
+
consumeAll?: ServerPluginContext["consumeAll"];
|
|
38
|
+
store: AccountStore;
|
|
39
|
+
logger: { info(m: string): void; warn(m: string): void };
|
|
40
|
+
now?: () => number;
|
|
41
|
+
}): GoogleLink {
|
|
42
|
+
const { store, logger } = deps;
|
|
43
|
+
|
|
44
|
+
function provider(): LegacyImporter | undefined {
|
|
45
|
+
for (const e of deps.consumeAll?.<LegacyImporter>(GOOGLE_CONNECT_SERVICE) ?? []) {
|
|
46
|
+
if (e.provider === GOOGLE_PLUGIN_ID && typeof e.value?.importLegacyGmail === "function") return e.value;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function migrate(importer: LegacyImporter): Promise<boolean> {
|
|
52
|
+
const accounts = await store.list();
|
|
53
|
+
const known = new Set((await store.getMigrated())?.subs ?? []);
|
|
54
|
+
// Nothing legacy, or nothing new since the last hand-off: no call, no marker for an empty namespace (B20).
|
|
55
|
+
if (accounts.every((a) => known.has(a.sub))) return true;
|
|
56
|
+
const client = await store.getClient();
|
|
57
|
+
const result = await importer.importLegacyGmail({ client, accounts });
|
|
58
|
+
if (!result.ok || result.skipped > 0) {
|
|
59
|
+
logger.warn(`[gmail] legacy import to Google accounts incomplete (${result.ok ? "skipped" : result.error}); using Gmail's own data`);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
await store.setMigrated({ at: (deps.now ?? Date.now)(), version: MIGRATION_VERSION, subs: accounts.map((a) => a.sub) });
|
|
63
|
+
logger.info(`[gmail] legacy import to Google accounts: ${result.imported} account(s)`);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let state: Promise<LinkState> | undefined;
|
|
68
|
+
async function compute(): Promise<LinkState> {
|
|
69
|
+
const importer = provider();
|
|
70
|
+
if (!importer) return { usable: false, delegating: false };
|
|
71
|
+
try {
|
|
72
|
+
return { usable: true, delegating: await migrate(importer) };
|
|
73
|
+
} catch {
|
|
74
|
+
// Store locked / importer threw: keep leasing from the legacy data; one attempt per process.
|
|
75
|
+
logger.warn("[gmail] legacy import to Google accounts failed; using Gmail's own data until the next start");
|
|
76
|
+
return { usable: true, delegating: false };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return { ensure: () => (state ??= compute()) };
|
|
81
|
+
}
|
|
@@ -24,7 +24,7 @@ import type { GoogleEndpoints } from "../shared/endpoints.js";
|
|
|
24
24
|
import { authScopeParam, type Tier } from "../shared/scopes.js";
|
|
25
25
|
import type { ClientRecord } from "./accounts.js";
|
|
26
26
|
|
|
27
|
-
/** Fixed, input-free error codes a flow can fail with (the wizard maps them to steps). */
|
|
27
|
+
/** Fixed, input-free error codes a flow can fail with (the Google accounts wizard maps them to steps). */
|
|
28
28
|
export class GmailFlowError extends Error {
|
|
29
29
|
readonly code: string;
|
|
30
30
|
|
|
@@ -39,7 +39,7 @@ const SAFE_CODE = /^[a-z_]{1,64}$/;
|
|
|
39
39
|
const safeCode = (v: unknown, fallback: string): string =>
|
|
40
40
|
typeof v === "string" && SAFE_CODE.test(v) ? v : fallback;
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
interface GoogleSignInResult extends PluginOAuthCredential {
|
|
43
43
|
sub: string;
|
|
44
44
|
email: string;
|
|
45
45
|
grantedScopes: string[];
|
|
@@ -53,6 +53,8 @@ export interface GoogleLoginOptions {
|
|
|
53
53
|
client: ClientRecord;
|
|
54
54
|
endpoints: GoogleEndpoints;
|
|
55
55
|
tier: Tier;
|
|
56
|
+
/** Also request `gmail.settings.basic` (filters option on). */
|
|
57
|
+
filters?: boolean;
|
|
56
58
|
/** Email of the account being re-authenticated (sets `login_hint`). */
|
|
57
59
|
loginHint?: string;
|
|
58
60
|
/** Test seam: fetch used for the token endpoint. */
|
|
@@ -89,6 +91,8 @@ export function buildAuthUrl(p: {
|
|
|
89
91
|
clientId: string;
|
|
90
92
|
redirectUri: string;
|
|
91
93
|
tier: Tier;
|
|
94
|
+
/** Also request `gmail.settings.basic` (Gmail filter management). */
|
|
95
|
+
filters?: boolean;
|
|
92
96
|
state: string;
|
|
93
97
|
nonce: string;
|
|
94
98
|
codeChallenge: string;
|
|
@@ -99,7 +103,7 @@ export function buildAuthUrl(p: {
|
|
|
99
103
|
q.set("client_id", p.clientId);
|
|
100
104
|
q.set("redirect_uri", p.redirectUri);
|
|
101
105
|
q.set("response_type", "code");
|
|
102
|
-
q.set("scope", authScopeParam(p.tier));
|
|
106
|
+
q.set("scope", authScopeParam(p.tier, { filters: p.filters }));
|
|
103
107
|
q.set("access_type", "offline");
|
|
104
108
|
q.set("prompt", "consent select_account");
|
|
105
109
|
q.set("state", p.state);
|
|
@@ -193,6 +197,7 @@ export function createGoogleLoginFlow(opts: GoogleLoginOptions): PluginOAuthLogi
|
|
|
193
197
|
clientId: opts.client.clientId,
|
|
194
198
|
redirectUri: cb.redirectUri,
|
|
195
199
|
tier: opts.tier,
|
|
200
|
+
filters: opts.filters,
|
|
196
201
|
state: cb.state,
|
|
197
202
|
nonce,
|
|
198
203
|
codeChallenge: await oauth.calculatePKCECodeChallenge(verifier),
|
package/src/server/index.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gmail plugin server entry (design D1). Wires the account store over
|
|
3
|
-
* `
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Gmail plugin server entry (design D1). Wires the legacy account store over `ctx.credentials` (namespace
|
|
3
|
+
* `gmail`), the `gmail/lease` + `gmail/accounts` request handlers and the moved-route stubs. Gmail links to
|
|
4
|
+
* Google Connect softly (`google-link.ts`): while it owns the accounts both lanes answer
|
|
5
|
+
* `{delegate:"google"}` and the bridge leases from `google/lease`; otherwise Gmail leases from its own data
|
|
6
|
+
* as before. Degrades to inactive when the host lacks the credential seam. See change: add-google-connect.
|
|
6
7
|
*/
|
|
7
8
|
import type { ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
8
9
|
import { resolveGoogleEndpoints } from "../shared/endpoints.js";
|
|
9
|
-
import { ACCOUNTS_TYPE, LEASE_TYPE } from "../shared/protocol.js";
|
|
10
|
+
import { ACCOUNTS_TYPE, type DelegateReply, GOOGLE_PLUGIN_ID, LEASE_TYPE } from "../shared/protocol.js";
|
|
11
|
+
import { isOp } from "../shared/scopes.js";
|
|
10
12
|
import { AccountStore, summarize } from "./accounts.js";
|
|
13
|
+
import { createGoogleLink } from "./google-link.js";
|
|
11
14
|
import { createLeaseHandler } from "./lease.js";
|
|
12
15
|
import { mountGmailRoutes } from "./routes.js";
|
|
13
16
|
|
|
17
|
+
const DELEGATE: DelegateReply = { delegate: GOOGLE_PLUGIN_ID };
|
|
18
|
+
|
|
14
19
|
export default async function registerPlugin(ctx: ServerPluginContext): Promise<void> {
|
|
15
20
|
if (!ctx.credentials) {
|
|
16
21
|
ctx.logger.warn("[gmail] host has no plugin credential store; plugin inactive");
|
|
@@ -18,14 +23,26 @@ export default async function registerPlugin(ctx: ServerPluginContext): Promise<
|
|
|
18
23
|
}
|
|
19
24
|
const endpoints = resolveGoogleEndpoints(process.env, (m) => ctx.logger.warn(m));
|
|
20
25
|
const store = new AccountStore(ctx.credentials);
|
|
21
|
-
|
|
26
|
+
const link = createGoogleLink({ consumeAll: ctx.consumeAll, store, logger: ctx.logger });
|
|
27
|
+
const legacyLease = createLeaseHandler({ store, endpoints, logger: ctx.logger });
|
|
28
|
+
// Both handlers are hub-local-only: `gmail/lease` returns a live OAuth access token (or the delegation to the
|
|
29
|
+
// lane that does) and `gmail/accounts` lists mailbox identities. The host refuses them (`origin_denied`) for a
|
|
30
|
+
// remote-origin session or a deprecated admission. See change: harden-bridge-session-claim (D3).
|
|
31
|
+
ctx.registerPiRequestHandler?.(
|
|
32
|
+
LEASE_TYPE,
|
|
33
|
+
async (payload: unknown) => {
|
|
34
|
+
if (!(await link.ensure()).delegating) return legacyLease(payload);
|
|
35
|
+
const p = (payload ?? {}) as { account?: unknown; op?: unknown };
|
|
36
|
+
if (typeof p.account !== "string" || !p.account.trim() || !isOp(p.op)) throw new Error("bad_request: expected {account, op}");
|
|
37
|
+
return DELEGATE;
|
|
38
|
+
},
|
|
39
|
+
{ hubLocalOnly: true },
|
|
40
|
+
);
|
|
22
41
|
// Secret-free account list for `gmail_accounts` and account-required errors.
|
|
23
|
-
ctx.registerPiRequestHandler?.(
|
|
24
|
-
|
|
25
|
-
store,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
logger: ctx.logger,
|
|
30
|
-
});
|
|
42
|
+
ctx.registerPiRequestHandler?.(
|
|
43
|
+
ACCOUNTS_TYPE,
|
|
44
|
+
async () => ((await link.ensure()).delegating ? DELEGATE : (await store.list()).map(summarize)),
|
|
45
|
+
{ hubLocalOnly: true },
|
|
46
|
+
);
|
|
47
|
+
await mountGmailRoutes(ctx.fastify, { networkGuard: ctx.networkGuard, link });
|
|
31
48
|
}
|
package/src/server/lease.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `gmail/lease` request handler (design D4/D5). Authorizes on the ACCOUNT LEVEL
|
|
3
|
-
* only
|
|
4
|
-
*
|
|
3
|
+
* only; WHO may call is the host lane's job: this handler registers `hubLocalOnly`, so a
|
|
4
|
+
* remote-origin or deprecated-admission session is refused (`origin_denied`) before it runs
|
|
5
|
+
* (change: harden-bridge-session-claim). Returns exactly
|
|
5
6
|
* `{accessToken, expiresAt, email, tier}` — the refresh token never leaves.
|
|
6
7
|
*
|
|
7
8
|
* - tier check (`tierAllows`) then granted-scope check (implication table);
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
import * as oauth from "oauth4webapi";
|
|
20
21
|
import type { GoogleEndpoints } from "../shared/endpoints.js";
|
|
21
22
|
import type { LeaseReply } from "../shared/protocol.js";
|
|
22
|
-
import { isOp, type Op, scopesCover, tierAllows } from "../shared/scopes.js";
|
|
23
|
+
import { isFilterOp, isOp, type Op, scopesCover, tierAllows } from "../shared/scopes.js";
|
|
23
24
|
import { AccountError, type AccountRecord, type AccountStore } from "./accounts.js";
|
|
24
25
|
import { oauthClient, oauthServer, requestOptions } from "./google-oauth.js";
|
|
25
26
|
|
|
@@ -32,6 +33,7 @@ type LeaseErrorCode =
|
|
|
32
33
|
| "not_found"
|
|
33
34
|
| "ambiguous"
|
|
34
35
|
| "no_client"
|
|
36
|
+
| "filters_disabled"
|
|
35
37
|
| "tier_denied"
|
|
36
38
|
| "scope_missing"
|
|
37
39
|
| "reauth_required"
|
|
@@ -140,6 +142,9 @@ export function createLeaseHandler(deps: LeaseDeps) {
|
|
|
140
142
|
|
|
141
143
|
/** Level + granted-scope + status gate. Returns the refusal, or null when allowed. */
|
|
142
144
|
function refusal(acct: AccountRecord, op: Op): LeaseError | null {
|
|
145
|
+
if (isFilterOp(op) && acct.filters !== true) {
|
|
146
|
+
return new LeaseError("filters_disabled", `filters are not enabled for ${acct.email}; turn them on in the Gmail settings`);
|
|
147
|
+
}
|
|
143
148
|
if (!tierAllows(acct.tier, op)) {
|
|
144
149
|
return new LeaseError("tier_denied", `${acct.email} is at level "${acct.tier}", which does not allow "${op}"`);
|
|
145
150
|
}
|