@flow-industries/id 0.11.0 → 0.13.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/dist/sdk/client/create-flow.d.ts +3 -3
- package/dist/sdk/client/create-flow.js +131 -114
- package/dist/sdk/client/index.d.ts +2 -1
- package/dist/sdk/client/index.js +1 -0
- package/dist/sdk/client/profile-button.js +2 -2
- package/dist/sdk/client/refresh-store.d.ts +13 -14
- package/dist/sdk/client/refresh-store.js +48 -58
- package/dist/sdk/client/session.js +2 -1
- package/dist/sdk/client/static-flow.js +2 -2
- package/dist/sdk/cookies.d.ts +8 -19
- package/dist/sdk/cookies.js +9 -25
- package/dist/sdk/id-host.d.ts +36 -0
- package/dist/sdk/id-host.js +57 -0
- package/dist/sdk/server.d.ts +8 -18
- package/dist/sdk/server.js +17 -173
- package/dist/sdk/session-core.d.ts +49 -0
- package/dist/sdk/session-core.js +176 -0
- package/dist/sdk/session-route.d.ts +33 -0
- package/dist/sdk/session-route.js +127 -0
- package/dist/sdk/start/index.d.ts +52 -0
- package/dist/sdk/start/index.js +58 -0
- package/dist/sdk/start/server.d.ts +33 -0
- package/dist/sdk/start/server.js +35 -0
- package/dist/sdk/types/auth.d.ts +13 -0
- package/dist/sdk/types/events.d.ts +1 -1
- package/dist/sdk/types/index.d.ts +3 -3
- package/dist/sdk/types/protocol.d.ts +12 -2
- package/dist/sdk/types/sdk.d.ts +25 -12
- package/dist/sdk/types/server.d.ts +30 -2
- package/package.json +15 -2
- package/dist/sdk/client/refresh-store.test.d.ts +0 -1
- package/dist/sdk/client/refresh-store.test.js +0 -90
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import { makeRefreshStore } from "./refresh-store";
|
|
3
|
-
const HOST = "https://id.flow.industries";
|
|
4
|
-
const KEY = `flow.id.refresh:${HOST}`;
|
|
5
|
-
const COOKIE = { name: "flow_id.refresh_p5173", secure: false };
|
|
6
|
-
let local;
|
|
7
|
-
let jar;
|
|
8
|
-
function installBrowserStubs() {
|
|
9
|
-
local = new Map();
|
|
10
|
-
jar = new Map();
|
|
11
|
-
globalThis.localStorage = {
|
|
12
|
-
getItem: (k) => local.get(k) ?? null,
|
|
13
|
-
setItem: (k, v) => void local.set(k, String(v)),
|
|
14
|
-
removeItem: (k) => void local.delete(k),
|
|
15
|
-
};
|
|
16
|
-
globalThis.document = {
|
|
17
|
-
get cookie() {
|
|
18
|
-
return [...jar.entries()].map(([n, v]) => `${n}=${v}`).join("; ");
|
|
19
|
-
},
|
|
20
|
-
set cookie(str) {
|
|
21
|
-
const [pair = "", ...attrs] = str.split(";");
|
|
22
|
-
const eq = pair.indexOf("=");
|
|
23
|
-
const name = pair.slice(0, eq).trim();
|
|
24
|
-
const value = pair.slice(eq + 1).trim();
|
|
25
|
-
if (attrs.some((a) => a.trim() === "Max-Age=0"))
|
|
26
|
-
jar.delete(name);
|
|
27
|
-
else
|
|
28
|
-
jar.set(name, value);
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
beforeEach(installBrowserStubs);
|
|
33
|
-
describe("localStorage mode (no cookie config)", () => {
|
|
34
|
-
test("round-trips through localStorage", () => {
|
|
35
|
-
const store = makeRefreshStore(HOST);
|
|
36
|
-
expect(store.get()).toBeNull();
|
|
37
|
-
store.set("tok_a");
|
|
38
|
-
expect(local.get(KEY)).toBe("tok_a");
|
|
39
|
-
expect(store.get()).toBe("tok_a");
|
|
40
|
-
store.clear();
|
|
41
|
-
expect(store.get()).toBeNull();
|
|
42
|
-
});
|
|
43
|
-
test("ignores a missing token instead of persisting a bogus value", () => {
|
|
44
|
-
const store = makeRefreshStore(HOST);
|
|
45
|
-
store.set(undefined);
|
|
46
|
-
expect(store.get()).toBeNull();
|
|
47
|
-
});
|
|
48
|
-
test("never touches cookies", () => {
|
|
49
|
-
const store = makeRefreshStore(HOST);
|
|
50
|
-
store.set("tok_a");
|
|
51
|
-
expect(jar.size).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("cookie mode", () => {
|
|
55
|
-
test("promotes a legacy localStorage token into the cookie and drops the key", () => {
|
|
56
|
-
local.set(KEY, "tok_legacy");
|
|
57
|
-
const store = makeRefreshStore(HOST, COOKIE);
|
|
58
|
-
expect(store.get()).toBe("tok_legacy");
|
|
59
|
-
expect(jar.get(COOKIE.name)).toBe("tok_legacy");
|
|
60
|
-
expect(local.has(KEY)).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
test("an existing cookie wins over a stale localStorage copy", () => {
|
|
63
|
-
local.set(KEY, "tok_stale");
|
|
64
|
-
jar.set(COOKIE.name, "tok_rotated");
|
|
65
|
-
const store = makeRefreshStore(HOST, COOKIE);
|
|
66
|
-
expect(store.get()).toBe("tok_rotated");
|
|
67
|
-
expect(local.has(KEY)).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
test("reads and writes only the cookie", () => {
|
|
70
|
-
const store = makeRefreshStore(HOST, COOKIE);
|
|
71
|
-
store.set("tok_b");
|
|
72
|
-
expect(jar.get(COOKIE.name)).toBe("tok_b");
|
|
73
|
-
expect(local.size).toBe(0);
|
|
74
|
-
local.set(KEY, "tok_planted_later");
|
|
75
|
-
jar.delete(COOKIE.name);
|
|
76
|
-
expect(store.get()).toBeNull();
|
|
77
|
-
});
|
|
78
|
-
test("clear deletes the cookie", () => {
|
|
79
|
-
const store = makeRefreshStore(HOST, COOKIE);
|
|
80
|
-
store.set("tok_c");
|
|
81
|
-
store.clear();
|
|
82
|
-
expect(store.get()).toBeNull();
|
|
83
|
-
expect(jar.has(COOKIE.name)).toBe(false);
|
|
84
|
-
});
|
|
85
|
-
test("ignores a missing token instead of persisting a bogus value", () => {
|
|
86
|
-
const store = makeRefreshStore(HOST, COOKIE);
|
|
87
|
-
store.set(undefined);
|
|
88
|
-
expect(store.get()).toBeNull();
|
|
89
|
-
});
|
|
90
|
-
});
|