@agent-native/dispatch 0.27.8 → 0.27.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/dispatch",
3
- "version": "0.27.8",
3
+ "version": "0.27.9",
4
4
  "description": "Dispatch — workspace control plane for agent-native apps. Vault, integrations, destinations, scheduled jobs, and cross-app delegation, shipped as a single drop-in package.",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -101,7 +101,7 @@
101
101
  "typescript-7": "npm:typescript@^7.0.2",
102
102
  "vite": "8.1.0",
103
103
  "vitest": "^4.1.5",
104
- "@agent-native/core": "0.157.19"
104
+ "@agent-native/core": "0.157.20"
105
105
  },
106
106
  "peerDependencies": {
107
107
  "@agent-native/core": ">=0.8.0",
@@ -0,0 +1,94 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ const server = vi.hoisted(() => ({
4
+ getRequestContext: vi.fn(),
5
+ }));
6
+ const apps = vi.hoisted(() => ({
7
+ listWorkspaceApps: vi.fn(),
8
+ }));
9
+
10
+ vi.mock("@agent-native/core/server", () => ({
11
+ getRequestContext: server.getRequestContext,
12
+ }));
13
+ vi.mock("../server/lib/app-creation-store.js", () => ({
14
+ listWorkspaceApps: apps.listWorkspaceApps,
15
+ }));
16
+ vi.mock("../server/lib/mcp-gateway.js", () => ({
17
+ createWorkspaceSsoEmbedSession: vi.fn(),
18
+ }));
19
+
20
+ import { assertWorkspaceEmbedSessionCaller } from "./create_workspace_app_embed_session.js";
21
+
22
+ describe("assertWorkspaceEmbedSessionCaller", () => {
23
+ beforeEach(() => {
24
+ server.getRequestContext.mockReturnValue({
25
+ requestOrigin: "https://dispatch.agent-native.com",
26
+ });
27
+ apps.listWorkspaceApps.mockResolvedValue([
28
+ {
29
+ id: "custom-app",
30
+ path: "/apps/custom-app",
31
+ isDispatch: false,
32
+ },
33
+ ]);
34
+ });
35
+
36
+ it("allows direct in-process calls and native parent bearer calls", async () => {
37
+ await expect(
38
+ assertWorkspaceEmbedSessionCaller(undefined),
39
+ ).resolves.toBeUndefined();
40
+ await expect(
41
+ assertWorkspaceEmbedSessionCaller(
42
+ new Headers({
43
+ Authorization: "Bearer parent-session",
44
+ "Sec-Fetch-Site": "cross-site",
45
+ }),
46
+ ),
47
+ ).resolves.toBeUndefined();
48
+ expect(apps.listWorkspaceApps).not.toHaveBeenCalled();
49
+ });
50
+
51
+ it("allows a same-origin Dispatch browser caller", async () => {
52
+ await expect(
53
+ assertWorkspaceEmbedSessionCaller(
54
+ new Headers({
55
+ Referer: "https://dispatch.agent-native.com/",
56
+ "Sec-Fetch-Site": "same-origin",
57
+ }),
58
+ ),
59
+ ).resolves.toBeUndefined();
60
+ expect(apps.listWorkspaceApps).toHaveBeenCalledWith({
61
+ includeAgentCards: false,
62
+ audience: "all",
63
+ });
64
+ });
65
+
66
+ it("rejects cross-site and child-app browser callers", async () => {
67
+ await expect(
68
+ assertWorkspaceEmbedSessionCaller(
69
+ new Headers({
70
+ Referer: "https://evil.example/",
71
+ "Sec-Fetch-Site": "cross-site",
72
+ }),
73
+ ),
74
+ ).rejects.toThrow("requested by Dispatch");
75
+
76
+ await expect(
77
+ assertWorkspaceEmbedSessionCaller(
78
+ new Headers({
79
+ Referer: "https://dispatch.agent-native.com/apps/custom-app/",
80
+ "Sec-Fetch-Site": "same-origin",
81
+ }),
82
+ ),
83
+ ).rejects.toThrow("cannot mint sessions for themselves");
84
+ });
85
+
86
+ it("fails closed when the browser caller has no trustworthy parent context", async () => {
87
+ server.getRequestContext.mockReturnValue(undefined);
88
+ await expect(
89
+ assertWorkspaceEmbedSessionCaller(
90
+ new Headers({ Referer: "https://dispatch.agent-native.com/" }),
91
+ ),
92
+ ).rejects.toThrow("requested by Dispatch");
93
+ });
94
+ });