@openclaw/googlechat 2026.5.2-beta.1 → 2026.5.3-beta.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/dist/api-C67jv0ow.js +627 -0
- package/dist/api.js +3 -0
- package/dist/channel-DE2hroMn.js +682 -0
- package/dist/channel-config-api.js +5 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-CoSLc-4R.js +920 -0
- package/dist/contract-api.js +3 -0
- package/dist/doctor-contract-CG1sLToP.js +151 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/index.js +22 -0
- package/dist/runtime-api-wkIdfwqY.js +30 -0
- package/dist/runtime-api.js +2 -0
- package/dist/secret-contract-DtQ_IO7J.js +99 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +75 -0
- package/dist/setup-surface-CofP-Gg9.js +309 -0
- package/dist/test-api.js +3 -0
- package/package.json +14 -6
- package/api.ts +0 -3
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -5
- package/doctor-contract-api.ts +0 -1
- package/index.ts +0 -20
- package/runtime-api.ts +0 -60
- package/secret-contract-api.ts +0 -5
- package/setup-entry.ts +0 -13
- package/setup-plugin-api.ts +0 -3
- package/src/accounts.ts +0 -169
- package/src/actions.test.ts +0 -265
- package/src/actions.ts +0 -227
- package/src/api.ts +0 -322
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -32
- package/src/auth.ts +0 -209
- package/src/channel-config.test.ts +0 -39
- package/src/channel.adapters.ts +0 -293
- package/src/channel.deps.runtime.ts +0 -28
- package/src/channel.runtime.ts +0 -17
- package/src/channel.setup.ts +0 -98
- package/src/channel.test.ts +0 -695
- package/src/channel.ts +0 -256
- package/src/config-schema.test.ts +0 -16
- package/src/config-schema.ts +0 -3
- package/src/doctor-contract.test.ts +0 -75
- package/src/doctor-contract.ts +0 -182
- package/src/doctor.ts +0 -57
- package/src/gateway.ts +0 -63
- package/src/google-auth.runtime.test.ts +0 -462
- package/src/google-auth.runtime.ts +0 -539
- package/src/group-policy.ts +0 -17
- package/src/monitor-access.test.ts +0 -443
- package/src/monitor-access.ts +0 -405
- package/src/monitor-reply-delivery.ts +0 -156
- package/src/monitor-routing.ts +0 -55
- package/src/monitor-types.ts +0 -33
- package/src/monitor-webhook.test.ts +0 -446
- package/src/monitor-webhook.ts +0 -285
- package/src/monitor.reply-delivery.test.ts +0 -139
- package/src/monitor.ts +0 -428
- package/src/monitor.webhook-routing.test.ts +0 -252
- package/src/runtime.ts +0 -9
- package/src/secret-contract.test.ts +0 -60
- package/src/secret-contract.ts +0 -161
- package/src/sender-allow.ts +0 -46
- package/src/setup-core.ts +0 -40
- package/src/setup-surface.ts +0 -236
- package/src/setup.test.ts +0 -560
- package/src/targets.test.ts +0 -421
- package/src/targets.ts +0 -66
- package/src/types.config.ts +0 -3
- package/src/types.ts +0 -73
- package/test-api.ts +0 -2
- package/tsconfig.json +0 -16
package/src/targets.test.ts
DELETED
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { ResolvedGoogleChatAccount } from "./accounts.js";
|
|
3
|
-
import { downloadGoogleChatMedia, sendGoogleChatMessage } from "./api.js";
|
|
4
|
-
import { resolveGoogleChatGroupRequireMention } from "./group-policy.js";
|
|
5
|
-
import { isSenderAllowed } from "./sender-allow.js";
|
|
6
|
-
import {
|
|
7
|
-
isGoogleChatSpaceTarget,
|
|
8
|
-
isGoogleChatUserTarget,
|
|
9
|
-
normalizeGoogleChatTarget,
|
|
10
|
-
} from "./targets.js";
|
|
11
|
-
|
|
12
|
-
const mocks = vi.hoisted(() => ({
|
|
13
|
-
buildHostnameAllowlistPolicyFromSuffixAllowlist: vi.fn((hosts: string[]) => ({
|
|
14
|
-
hostnameAllowlist: hosts,
|
|
15
|
-
})),
|
|
16
|
-
fetchWithSsrFGuard: vi.fn(async (params: { url: string; init?: RequestInit }) => ({
|
|
17
|
-
response: await fetch(params.url, params.init),
|
|
18
|
-
release: async () => {},
|
|
19
|
-
})),
|
|
20
|
-
googleAuthCtor: vi.fn(),
|
|
21
|
-
gaxiosCtor: vi.fn(),
|
|
22
|
-
getAccessToken: vi.fn().mockResolvedValue({ token: "access-token" }),
|
|
23
|
-
oauthCtor: vi.fn(),
|
|
24
|
-
verifySignedJwtWithCertsAsync: vi.fn(),
|
|
25
|
-
verifyIdToken: vi.fn(),
|
|
26
|
-
getGoogleChatAccessToken: vi.fn().mockResolvedValue("token"),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => {
|
|
30
|
-
return {
|
|
31
|
-
buildHostnameAllowlistPolicyFromSuffixAllowlist:
|
|
32
|
-
mocks.buildHostnameAllowlistPolicyFromSuffixAllowlist,
|
|
33
|
-
fetchWithSsrFGuard: mocks.fetchWithSsrFGuard,
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
vi.mock("gaxios", () => ({
|
|
38
|
-
Gaxios: class {
|
|
39
|
-
defaults: unknown;
|
|
40
|
-
|
|
41
|
-
constructor(defaults?: unknown) {
|
|
42
|
-
this.defaults = defaults;
|
|
43
|
-
mocks.gaxiosCtor(defaults);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
vi.mock("google-auth-library", () => ({
|
|
49
|
-
GoogleAuth: class {
|
|
50
|
-
constructor(options?: unknown) {
|
|
51
|
-
mocks.googleAuthCtor(options);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getClient = vi.fn().mockResolvedValue({
|
|
55
|
-
getAccessToken: mocks.getAccessToken,
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
OAuth2Client: class {
|
|
59
|
-
constructor(options?: unknown) {
|
|
60
|
-
mocks.oauthCtor(options);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
verifyIdToken = mocks.verifyIdToken;
|
|
64
|
-
verifySignedJwtWithCertsAsync = mocks.verifySignedJwtWithCertsAsync;
|
|
65
|
-
},
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
vi.mock("./auth.js", async () => {
|
|
69
|
-
const actual = await vi.importActual<typeof import("./auth.js")>("./auth.js");
|
|
70
|
-
return {
|
|
71
|
-
...actual,
|
|
72
|
-
getGoogleChatAccessToken: mocks.getGoogleChatAccessToken,
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const authActual = await vi.importActual<typeof import("./auth.js")>("./auth.js");
|
|
77
|
-
const { __testing: authTesting, getGoogleChatAccessToken, verifyGoogleChatRequest } = authActual;
|
|
78
|
-
|
|
79
|
-
const account = {
|
|
80
|
-
accountId: "default",
|
|
81
|
-
enabled: true,
|
|
82
|
-
credentialSource: "inline",
|
|
83
|
-
config: {},
|
|
84
|
-
} as ResolvedGoogleChatAccount;
|
|
85
|
-
|
|
86
|
-
function stubSuccessfulSend(name: string) {
|
|
87
|
-
const fetchMock = vi
|
|
88
|
-
.fn()
|
|
89
|
-
.mockResolvedValue(new Response(JSON.stringify({ name }), { status: 200 }));
|
|
90
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
91
|
-
return fetchMock;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function expectDownloadToRejectForResponse(response: Response) {
|
|
95
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(response));
|
|
96
|
-
await expect(
|
|
97
|
-
downloadGoogleChatMedia({ account, resourceName: "media/123", maxBytes: 10 }),
|
|
98
|
-
).rejects.toThrow(/max bytes/i);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
describe("normalizeGoogleChatTarget", () => {
|
|
102
|
-
it("normalizes provider prefixes", () => {
|
|
103
|
-
expect(normalizeGoogleChatTarget("googlechat:users/123")).toBe("users/123");
|
|
104
|
-
expect(normalizeGoogleChatTarget("google-chat:spaces/AAA")).toBe("spaces/AAA");
|
|
105
|
-
expect(normalizeGoogleChatTarget("gchat:user:User@Example.com")).toBe("users/user@example.com");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("normalizes email targets to users/<email>", () => {
|
|
109
|
-
expect(normalizeGoogleChatTarget("User@Example.com")).toBe("users/user@example.com");
|
|
110
|
-
expect(normalizeGoogleChatTarget("users/User@Example.com")).toBe("users/user@example.com");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("preserves space targets", () => {
|
|
114
|
-
expect(normalizeGoogleChatTarget("space:spaces/BBB")).toBe("spaces/BBB");
|
|
115
|
-
expect(normalizeGoogleChatTarget("spaces/CCC")).toBe("spaces/CCC");
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("target helpers", () => {
|
|
120
|
-
it("detects user and space targets", () => {
|
|
121
|
-
expect(isGoogleChatUserTarget("users/abc")).toBe(true);
|
|
122
|
-
expect(isGoogleChatSpaceTarget("spaces/abc")).toBe(true);
|
|
123
|
-
expect(isGoogleChatUserTarget("spaces/abc")).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("googlechat group policy", () => {
|
|
128
|
-
it("uses generic channel group policy helpers", () => {
|
|
129
|
-
const cfg = {
|
|
130
|
-
channels: {
|
|
131
|
-
googlechat: {
|
|
132
|
-
groups: {
|
|
133
|
-
"spaces/AAA": {
|
|
134
|
-
requireMention: false,
|
|
135
|
-
},
|
|
136
|
-
"*": {
|
|
137
|
-
requireMention: true,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
} as any;
|
|
143
|
-
|
|
144
|
-
expect(resolveGoogleChatGroupRequireMention({ cfg, groupId: "spaces/AAA" })).toBe(false);
|
|
145
|
-
expect(resolveGoogleChatGroupRequireMention({ cfg, groupId: "spaces/BBB" })).toBe(true);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe("isSenderAllowed", () => {
|
|
150
|
-
it("matches raw email entries only when dangerous name matching is enabled", () => {
|
|
151
|
-
expect(isSenderAllowed("users/123", "Jane@Example.com", ["jane@example.com"])).toBe(false);
|
|
152
|
-
expect(isSenderAllowed("users/123", "Jane@Example.com", ["jane@example.com"], true)).toBe(true);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("does not treat users/<email> entries as email allowlist (deprecated form)", () => {
|
|
156
|
-
expect(isSenderAllowed("users/123", "Jane@Example.com", ["users/jane@example.com"])).toBe(
|
|
157
|
-
false,
|
|
158
|
-
);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("still matches user id entries", () => {
|
|
162
|
-
expect(isSenderAllowed("users/abc", "jane@example.com", ["users/abc"])).toBe(true);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("rejects non-matching raw email entries", () => {
|
|
166
|
-
expect(isSenderAllowed("users/123", "jane@example.com", ["other@example.com"], true)).toBe(
|
|
167
|
-
false,
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
describe("downloadGoogleChatMedia", () => {
|
|
173
|
-
afterEach(() => {
|
|
174
|
-
authTesting.resetGoogleChatAuthForTests();
|
|
175
|
-
mocks.fetchWithSsrFGuard.mockClear();
|
|
176
|
-
vi.unstubAllGlobals();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("rejects when content-length exceeds max bytes", async () => {
|
|
180
|
-
const body = new ReadableStream({
|
|
181
|
-
start(controller) {
|
|
182
|
-
controller.enqueue(new Uint8Array([1, 2, 3]));
|
|
183
|
-
controller.close();
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
const response = new Response(body, {
|
|
187
|
-
status: 200,
|
|
188
|
-
headers: { "content-length": "50", "content-type": "application/octet-stream" },
|
|
189
|
-
});
|
|
190
|
-
await expectDownloadToRejectForResponse(response);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("rejects when streamed payload exceeds max bytes", async () => {
|
|
194
|
-
const chunks = [new Uint8Array(6), new Uint8Array(6)];
|
|
195
|
-
let index = 0;
|
|
196
|
-
const body = new ReadableStream({
|
|
197
|
-
pull(controller) {
|
|
198
|
-
if (index < chunks.length) {
|
|
199
|
-
controller.enqueue(chunks[index++]);
|
|
200
|
-
} else {
|
|
201
|
-
controller.close();
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
const response = new Response(body, {
|
|
206
|
-
status: 200,
|
|
207
|
-
headers: { "content-type": "application/octet-stream" },
|
|
208
|
-
});
|
|
209
|
-
await expectDownloadToRejectForResponse(response);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("sendGoogleChatMessage", () => {
|
|
214
|
-
afterEach(() => {
|
|
215
|
-
authTesting.resetGoogleChatAuthForTests();
|
|
216
|
-
mocks.fetchWithSsrFGuard.mockClear();
|
|
217
|
-
vi.unstubAllGlobals();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("adds messageReplyOption when sending to an existing thread", async () => {
|
|
221
|
-
const fetchMock = stubSuccessfulSend("spaces/AAA/messages/123");
|
|
222
|
-
|
|
223
|
-
await sendGoogleChatMessage({
|
|
224
|
-
account,
|
|
225
|
-
space: "spaces/AAA",
|
|
226
|
-
text: "hello",
|
|
227
|
-
thread: "spaces/AAA/threads/xyz",
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const [url, init] = fetchMock.mock.calls[0] ?? [];
|
|
231
|
-
expect(String(url)).toContain("messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD");
|
|
232
|
-
expect(JSON.parse(String(init?.body))).toMatchObject({
|
|
233
|
-
text: "hello",
|
|
234
|
-
thread: { name: "spaces/AAA/threads/xyz" },
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("does not set messageReplyOption for non-thread sends", async () => {
|
|
239
|
-
const fetchMock = stubSuccessfulSend("spaces/AAA/messages/124");
|
|
240
|
-
|
|
241
|
-
await sendGoogleChatMessage({
|
|
242
|
-
account,
|
|
243
|
-
space: "spaces/AAA",
|
|
244
|
-
text: "hello",
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
const [url] = fetchMock.mock.calls[0] ?? [];
|
|
248
|
-
expect(String(url)).not.toContain("messageReplyOption=");
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
function mockTicket(payload: Record<string, unknown>) {
|
|
253
|
-
mocks.verifyIdToken.mockResolvedValue({
|
|
254
|
-
getPayload: () => payload,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
describe("verifyGoogleChatRequest", () => {
|
|
259
|
-
afterEach(() => {
|
|
260
|
-
authTesting.resetGoogleChatAuthForTests();
|
|
261
|
-
mocks.getAccessToken.mockClear();
|
|
262
|
-
mocks.gaxiosCtor.mockClear();
|
|
263
|
-
mocks.googleAuthCtor.mockClear();
|
|
264
|
-
mocks.oauthCtor.mockClear();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it("injects a scoped transporter into GoogleAuth access-token clients", async () => {
|
|
268
|
-
await expect(
|
|
269
|
-
getGoogleChatAccessToken({
|
|
270
|
-
...account,
|
|
271
|
-
credentials: {
|
|
272
|
-
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
|
|
273
|
-
auth_uri: "https://accounts.google.com/o/oauth2/auth",
|
|
274
|
-
client_email: "bot@example.iam.gserviceaccount.com",
|
|
275
|
-
private_key: "key",
|
|
276
|
-
token_uri: "https://oauth2.googleapis.com/token",
|
|
277
|
-
type: "service_account",
|
|
278
|
-
universe_domain: "googleapis.com",
|
|
279
|
-
},
|
|
280
|
-
}),
|
|
281
|
-
).resolves.toBe("access-token");
|
|
282
|
-
|
|
283
|
-
const googleAuthOptions = mocks.googleAuthCtor.mock.calls[0]?.[0] as {
|
|
284
|
-
clientOptions?: { transporter?: { defaults?: { fetchImplementation?: unknown } } };
|
|
285
|
-
credentials?: { client_email?: string; token_uri?: string };
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
expect(mocks.gaxiosCtor).toHaveBeenCalledOnce();
|
|
289
|
-
expect(googleAuthOptions).toMatchObject({
|
|
290
|
-
clientOptions: {
|
|
291
|
-
transporter: {
|
|
292
|
-
defaults: {
|
|
293
|
-
fetchImplementation: expect.any(Function),
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
credentials: {
|
|
298
|
-
client_email: "bot@example.iam.gserviceaccount.com",
|
|
299
|
-
token_uri: "https://oauth2.googleapis.com/token",
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
expect(mocks.getAccessToken).toHaveBeenCalledOnce();
|
|
303
|
-
expect("window" in globalThis).toBe(false);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it("accepts Google Chat app-url tokens from the Chat issuer", async () => {
|
|
307
|
-
mocks.verifyIdToken.mockReset();
|
|
308
|
-
mockTicket({
|
|
309
|
-
email: "chat@system.gserviceaccount.com",
|
|
310
|
-
email_verified: true,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
await expect(
|
|
314
|
-
verifyGoogleChatRequest({
|
|
315
|
-
bearer: "token",
|
|
316
|
-
audienceType: "app-url",
|
|
317
|
-
audience: "https://example.com/googlechat",
|
|
318
|
-
}),
|
|
319
|
-
).resolves.toEqual({ ok: true });
|
|
320
|
-
|
|
321
|
-
const oauthOptions = mocks.oauthCtor.mock.calls[0]?.[0] as {
|
|
322
|
-
transporter?: { defaults?: { fetchImplementation?: unknown } };
|
|
323
|
-
};
|
|
324
|
-
expect(oauthOptions).toMatchObject({
|
|
325
|
-
transporter: {
|
|
326
|
-
defaults: {
|
|
327
|
-
fetchImplementation: expect.any(Function),
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it("rejects add-on tokens when no principal binding is configured", async () => {
|
|
334
|
-
mocks.verifyIdToken.mockReset();
|
|
335
|
-
mockTicket({
|
|
336
|
-
email: "service-123@gcp-sa-gsuiteaddons.iam.gserviceaccount.com",
|
|
337
|
-
email_verified: true,
|
|
338
|
-
sub: "principal-1",
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
await expect(
|
|
342
|
-
verifyGoogleChatRequest({
|
|
343
|
-
bearer: "token",
|
|
344
|
-
audienceType: "app-url",
|
|
345
|
-
audience: "https://example.com/googlechat",
|
|
346
|
-
}),
|
|
347
|
-
).resolves.toEqual({
|
|
348
|
-
ok: false,
|
|
349
|
-
reason: "missing add-on principal binding",
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it("accepts add-on tokens only when the bound principal matches", async () => {
|
|
354
|
-
mocks.verifyIdToken.mockReset();
|
|
355
|
-
mockTicket({
|
|
356
|
-
email: "service-123@gcp-sa-gsuiteaddons.iam.gserviceaccount.com",
|
|
357
|
-
email_verified: true,
|
|
358
|
-
sub: "principal-1",
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
await expect(
|
|
362
|
-
verifyGoogleChatRequest({
|
|
363
|
-
bearer: "token",
|
|
364
|
-
audienceType: "app-url",
|
|
365
|
-
audience: "https://example.com/googlechat",
|
|
366
|
-
expectedAddOnPrincipal: "principal-1",
|
|
367
|
-
}),
|
|
368
|
-
).resolves.toEqual({ ok: true });
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it("rejects add-on tokens when the bound principal does not match", async () => {
|
|
372
|
-
mocks.verifyIdToken.mockReset();
|
|
373
|
-
mockTicket({
|
|
374
|
-
email: "service-123@gcp-sa-gsuiteaddons.iam.gserviceaccount.com",
|
|
375
|
-
email_verified: true,
|
|
376
|
-
sub: "principal-2",
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
await expect(
|
|
380
|
-
verifyGoogleChatRequest({
|
|
381
|
-
bearer: "token",
|
|
382
|
-
audienceType: "app-url",
|
|
383
|
-
audience: "https://example.com/googlechat",
|
|
384
|
-
expectedAddOnPrincipal: "principal-1",
|
|
385
|
-
}),
|
|
386
|
-
).resolves.toEqual({
|
|
387
|
-
ok: false,
|
|
388
|
-
reason: "unexpected add-on principal: principal-2",
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it("fetches Chat certs through the guarded fetch for project-number tokens", async () => {
|
|
393
|
-
const release = vi.fn();
|
|
394
|
-
mocks.fetchWithSsrFGuard.mockClear();
|
|
395
|
-
mocks.fetchWithSsrFGuard.mockResolvedValueOnce({
|
|
396
|
-
response: new Response(JSON.stringify({ "kid-1": "cert-body" }), { status: 200 }),
|
|
397
|
-
release,
|
|
398
|
-
});
|
|
399
|
-
mocks.verifySignedJwtWithCertsAsync.mockReset().mockResolvedValue(undefined);
|
|
400
|
-
|
|
401
|
-
await expect(
|
|
402
|
-
verifyGoogleChatRequest({
|
|
403
|
-
bearer: "token",
|
|
404
|
-
audienceType: "project-number",
|
|
405
|
-
audience: "123456789",
|
|
406
|
-
}),
|
|
407
|
-
).resolves.toEqual({ ok: true });
|
|
408
|
-
|
|
409
|
-
expect(mocks.fetchWithSsrFGuard).toHaveBeenCalledWith({
|
|
410
|
-
url: "https://www.googleapis.com/service_accounts/v1/metadata/x509/chat@system.gserviceaccount.com",
|
|
411
|
-
auditContext: "googlechat.auth.certs",
|
|
412
|
-
});
|
|
413
|
-
expect(mocks.verifySignedJwtWithCertsAsync).toHaveBeenCalledWith(
|
|
414
|
-
"token",
|
|
415
|
-
{ "kid-1": "cert-body" },
|
|
416
|
-
"123456789",
|
|
417
|
-
["chat@system.gserviceaccount.com"],
|
|
418
|
-
);
|
|
419
|
-
expect(release).toHaveBeenCalledOnce();
|
|
420
|
-
});
|
|
421
|
-
});
|
package/src/targets.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
-
import type { ResolvedGoogleChatAccount } from "./accounts.js";
|
|
3
|
-
import { findGoogleChatDirectMessage } from "./api.js";
|
|
4
|
-
|
|
5
|
-
export function normalizeGoogleChatTarget(raw?: string | null): string | undefined {
|
|
6
|
-
const trimmed = raw?.trim();
|
|
7
|
-
if (!trimmed) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
const withoutPrefix = trimmed.replace(/^(googlechat|google-chat|gchat):/i, "");
|
|
11
|
-
const normalized = withoutPrefix
|
|
12
|
-
.replace(/^user:(users\/)?/i, "users/")
|
|
13
|
-
.replace(/^space:(spaces\/)?/i, "spaces/");
|
|
14
|
-
if (isGoogleChatUserTarget(normalized)) {
|
|
15
|
-
const suffix = normalized.slice("users/".length);
|
|
16
|
-
return suffix.includes("@") ? `users/${normalizeLowercaseStringOrEmpty(suffix)}` : normalized;
|
|
17
|
-
}
|
|
18
|
-
if (isGoogleChatSpaceTarget(normalized)) {
|
|
19
|
-
return normalized;
|
|
20
|
-
}
|
|
21
|
-
if (normalized.includes("@")) {
|
|
22
|
-
return `users/${normalizeLowercaseStringOrEmpty(normalized)}`;
|
|
23
|
-
}
|
|
24
|
-
return normalized;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function isGoogleChatUserTarget(value: string): boolean {
|
|
28
|
-
return normalizeLowercaseStringOrEmpty(value).startsWith("users/");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function isGoogleChatSpaceTarget(value: string): boolean {
|
|
32
|
-
return normalizeLowercaseStringOrEmpty(value).startsWith("spaces/");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function stripMessageSuffix(target: string): string {
|
|
36
|
-
const index = target.indexOf("/messages/");
|
|
37
|
-
if (index === -1) {
|
|
38
|
-
return target;
|
|
39
|
-
}
|
|
40
|
-
return target.slice(0, index);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function resolveGoogleChatOutboundSpace(params: {
|
|
44
|
-
account: ResolvedGoogleChatAccount;
|
|
45
|
-
target: string;
|
|
46
|
-
}): Promise<string> {
|
|
47
|
-
const normalized = normalizeGoogleChatTarget(params.target);
|
|
48
|
-
if (!normalized) {
|
|
49
|
-
throw new Error("Missing Google Chat target.");
|
|
50
|
-
}
|
|
51
|
-
const base = stripMessageSuffix(normalized);
|
|
52
|
-
if (isGoogleChatSpaceTarget(base)) {
|
|
53
|
-
return base;
|
|
54
|
-
}
|
|
55
|
-
if (isGoogleChatUserTarget(base)) {
|
|
56
|
-
const dm = await findGoogleChatDirectMessage({
|
|
57
|
-
account: params.account,
|
|
58
|
-
userName: base,
|
|
59
|
-
});
|
|
60
|
-
if (!dm?.name) {
|
|
61
|
-
throw new Error(`No Google Chat DM found for ${base}`);
|
|
62
|
-
}
|
|
63
|
-
return dm.name;
|
|
64
|
-
}
|
|
65
|
-
return base;
|
|
66
|
-
}
|
package/src/types.config.ts
DELETED
package/src/types.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export type GoogleChatSpace = {
|
|
2
|
-
name?: string;
|
|
3
|
-
displayName?: string;
|
|
4
|
-
type?: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type GoogleChatUser = {
|
|
8
|
-
name?: string;
|
|
9
|
-
displayName?: string;
|
|
10
|
-
email?: string;
|
|
11
|
-
type?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type GoogleChatThread = {
|
|
15
|
-
name?: string;
|
|
16
|
-
threadKey?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type GoogleChatAttachmentDataRef = {
|
|
20
|
-
resourceName?: string;
|
|
21
|
-
attachmentUploadToken?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type GoogleChatAttachment = {
|
|
25
|
-
name?: string;
|
|
26
|
-
contentName?: string;
|
|
27
|
-
contentType?: string;
|
|
28
|
-
thumbnailUri?: string;
|
|
29
|
-
downloadUri?: string;
|
|
30
|
-
source?: string;
|
|
31
|
-
attachmentDataRef?: GoogleChatAttachmentDataRef;
|
|
32
|
-
driveDataRef?: Record<string, unknown>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type GoogleChatUserMention = {
|
|
36
|
-
user?: GoogleChatUser;
|
|
37
|
-
type?: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type GoogleChatAnnotation = {
|
|
41
|
-
type?: string;
|
|
42
|
-
startIndex?: number;
|
|
43
|
-
length?: number;
|
|
44
|
-
userMention?: GoogleChatUserMention;
|
|
45
|
-
slashCommand?: Record<string, unknown>;
|
|
46
|
-
richLinkMetadata?: Record<string, unknown>;
|
|
47
|
-
customEmojiMetadata?: Record<string, unknown>;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type GoogleChatMessage = {
|
|
51
|
-
name?: string;
|
|
52
|
-
text?: string;
|
|
53
|
-
argumentText?: string;
|
|
54
|
-
sender?: GoogleChatUser;
|
|
55
|
-
thread?: GoogleChatThread;
|
|
56
|
-
attachment?: GoogleChatAttachment[];
|
|
57
|
-
annotations?: GoogleChatAnnotation[];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type GoogleChatEvent = {
|
|
61
|
-
type?: string;
|
|
62
|
-
eventType?: string;
|
|
63
|
-
eventTime?: string;
|
|
64
|
-
space?: GoogleChatSpace;
|
|
65
|
-
user?: GoogleChatUser;
|
|
66
|
-
message?: GoogleChatMessage;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type GoogleChatReaction = {
|
|
70
|
-
name?: string;
|
|
71
|
-
user?: GoogleChatUser;
|
|
72
|
-
emoji?: { unicode?: string };
|
|
73
|
-
};
|
package/test-api.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.package-boundary.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "."
|
|
5
|
-
},
|
|
6
|
-
"include": ["./*.ts", "./src/**/*.ts"],
|
|
7
|
-
"exclude": [
|
|
8
|
-
"./**/*.test.ts",
|
|
9
|
-
"./dist/**",
|
|
10
|
-
"./node_modules/**",
|
|
11
|
-
"./src/test-support/**",
|
|
12
|
-
"./src/**/*test-helpers.ts",
|
|
13
|
-
"./src/**/*test-harness.ts",
|
|
14
|
-
"./src/**/*test-support.ts"
|
|
15
|
-
]
|
|
16
|
-
}
|