@structured-id/ui-core 4.7.1 → 4.7.2

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": "@structured-id/ui-core",
3
- "version": "4.7.1",
3
+ "version": "4.7.2",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -6,6 +6,16 @@ import { GrantOutcome } from "@structured-id/proto/sid/v1/authn/application_sess
6
6
  const host = vi.hoisted(() => ({
7
7
  getApplicationSession: vi.fn(),
8
8
  endApplicationSession: vi.fn(),
9
+ /** The base URL of the transport last made. */
10
+ transportBase: undefined as string | undefined,
11
+ }));
12
+
13
+ vi.mock("@protobuf-ts/grpcweb-transport", () => ({
14
+ GrpcWebFetchTransport: class {
15
+ constructor(options: { baseUrl: string }) {
16
+ host.transportBase = options.baseUrl;
17
+ }
18
+ },
9
19
  }));
10
20
 
11
21
  vi.mock("@structured-id/proto/sid/v1/authn/application_session.client", () => ({
@@ -40,6 +50,27 @@ const LIVE = {
40
50
  csrfToken: "token-1",
41
51
  };
42
52
 
53
+ describe("the session service's address", () => {
54
+ // The host serves a page's calls only under its API mount: a call at the
55
+ // root is refused, and the page cannot read a session it has.
56
+ it("is the API mount of the page's own origin", () => {
57
+ initBff("");
58
+ expect(host.transportBase).toBe("/api");
59
+ });
60
+
61
+ it("is the API mount of a configured host", () => {
62
+ initBff("https://host.sid.example.com");
63
+ expect(host.transportBase).toBe("https://host.sid.example.com/api");
64
+ });
65
+
66
+ it("is the API mount of a host named for one call", async () => {
67
+ initBff("");
68
+ host.getApplicationSession.mockReturnValue(answers(LIVE));
69
+ await checkBffSession("https://other.sid.example.com");
70
+ expect(host.transportBase).toBe("https://other.sid.example.com/api");
71
+ });
72
+ });
73
+
43
74
  describe("checkBffSession", () => {
44
75
  beforeEach(() => {
45
76
  vi.clearAllMocks();
@@ -43,10 +43,13 @@ let _session: ApplicationSessionServiceClient | null = null;
43
43
  */
44
44
  let _csrfToken: string | null = null;
45
45
 
46
- /** The session service at `baseUrl`; the cookie never travels to another origin. */
46
+ /**
47
+ * The session service of the host at `baseUrl`, under the `/api` mount that
48
+ * serves a page's calls; the cookie never travels to another origin.
49
+ */
47
50
  function sessionClient(baseUrl: string): ApplicationSessionServiceClient {
48
51
  const transport: RpcTransport = new GrpcWebFetchTransport({
49
- baseUrl,
52
+ baseUrl: `${baseUrl}/api`,
50
53
  fetchInit: { credentials: "same-origin" },
51
54
  });
52
55
  return new ApplicationSessionServiceClient(transport);