@mcinteerj/openclaw-gmail 1.5.0 → 1.5.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.
- package/package.json +1 -1
- package/src/accounts.ts +25 -1
package/package.json
CHANGED
package/src/accounts.ts
CHANGED
|
@@ -18,12 +18,36 @@ export interface ResolvedGmailAccount extends ResolvedChannelAccount {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Normalize an account key the same way the gateway's routing layer does
|
|
23
|
+
* (replace non-alphanumeric chars with hyphens). This allows matching
|
|
24
|
+
* "honk-keithy-gmail-com" back to "honk.keithy@gmail.com".
|
|
25
|
+
*/
|
|
26
|
+
function canonicalizeKey(value: string): string {
|
|
27
|
+
return value.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
export function resolveGmailAccount(
|
|
22
31
|
cfg: ChannelConfig<GmailConfig>,
|
|
23
32
|
accountId?: string,
|
|
24
33
|
): ResolvedGmailAccount {
|
|
25
34
|
const resolvedId = accountId || DEFAULT_ACCOUNT_ID;
|
|
26
|
-
const
|
|
35
|
+
const accounts = cfg.channels?.['openclaw-gmail']?.accounts;
|
|
36
|
+
let account = accounts?.[resolvedId];
|
|
37
|
+
|
|
38
|
+
// If direct lookup fails, try matching against canonicalized account keys.
|
|
39
|
+
// The gateway's routing layer normalizes email-format accountIds (e.g.
|
|
40
|
+
// "honk.keithy@gmail.com" -> "honk-keithy-gmail-com"), so we need to
|
|
41
|
+
// reverse-match by canonicalizing each config key the same way.
|
|
42
|
+
if (!account && accounts && resolvedId !== DEFAULT_ACCOUNT_ID) {
|
|
43
|
+
const canonicalizedId = canonicalizeKey(resolvedId);
|
|
44
|
+
for (const key of Object.keys(accounts)) {
|
|
45
|
+
if (canonicalizeKey(key) === canonicalizedId) {
|
|
46
|
+
account = accounts[key];
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
27
51
|
|
|
28
52
|
if (!account) {
|
|
29
53
|
// Graceful fallback for UI logic that queries 'default' on unconfigured channels
|