@supatype/client 0.8.0 → 0.9.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.
Files changed (126) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +73 -69
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/CHANGELOG.md +110 -0
  5. package/bin/supatype-prepare.js +68 -0
  6. package/dist/auth.d.ts +50 -6
  7. package/dist/auth.d.ts.map +1 -1
  8. package/dist/auth.js +132 -40
  9. package/dist/auth.js.map +1 -1
  10. package/dist/bindings.d.ts +4 -1
  11. package/dist/bindings.d.ts.map +1 -1
  12. package/dist/bindings.js +2 -0
  13. package/dist/bindings.js.map +1 -1
  14. package/dist/error-codes-doc.d.ts +1 -1
  15. package/dist/error-codes-doc.d.ts.map +1 -1
  16. package/dist/error-codes-doc.js +7 -0
  17. package/dist/error-codes-doc.js.map +1 -1
  18. package/dist/errors.d.ts +81 -21
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/errors.js +133 -46
  21. package/dist/errors.js.map +1 -1
  22. package/dist/graphql-transport.d.ts +10 -3
  23. package/dist/graphql-transport.d.ts.map +1 -1
  24. package/dist/graphql-transport.js +5 -5
  25. package/dist/graphql-transport.js.map +1 -1
  26. package/dist/index.d.ts +23 -16
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +66 -48
  29. package/dist/index.js.map +1 -1
  30. package/dist/latest-rows.d.ts +29 -0
  31. package/dist/latest-rows.d.ts.map +1 -0
  32. package/dist/latest-rows.js +51 -0
  33. package/dist/latest-rows.js.map +1 -0
  34. package/dist/mutation-request.d.ts +19 -5
  35. package/dist/mutation-request.d.ts.map +1 -1
  36. package/dist/mutation-request.js +18 -15
  37. package/dist/mutation-request.js.map +1 -1
  38. package/dist/page-env-script.d.ts +12 -0
  39. package/dist/page-env-script.d.ts.map +1 -0
  40. package/dist/page-env-script.js +30 -0
  41. package/dist/page-env-script.js.map +1 -0
  42. package/dist/preview.d.ts +2 -1
  43. package/dist/preview.d.ts.map +1 -1
  44. package/dist/preview.js +7 -3
  45. package/dist/preview.js.map +1 -1
  46. package/dist/query.d.ts +49 -19
  47. package/dist/query.d.ts.map +1 -1
  48. package/dist/query.js +102 -33
  49. package/dist/query.js.map +1 -1
  50. package/dist/realtime.d.ts +5 -2
  51. package/dist/realtime.d.ts.map +1 -1
  52. package/dist/realtime.js +13 -6
  53. package/dist/realtime.js.map +1 -1
  54. package/dist/runtime-env.d.ts +59 -0
  55. package/dist/runtime-env.d.ts.map +1 -0
  56. package/dist/runtime-env.js +167 -0
  57. package/dist/runtime-env.js.map +1 -0
  58. package/dist/setup-fault.d.ts +13 -0
  59. package/dist/setup-fault.d.ts.map +1 -0
  60. package/dist/setup-fault.js +17 -0
  61. package/dist/setup-fault.js.map +1 -0
  62. package/dist/storage.d.ts +10 -5
  63. package/dist/storage.d.ts.map +1 -1
  64. package/dist/storage.js +22 -13
  65. package/dist/storage.js.map +1 -1
  66. package/dist/table-subscription.d.ts +1 -1
  67. package/dist/table-subscription.d.ts.map +1 -1
  68. package/dist/table-subscription.js +3 -2
  69. package/dist/table-subscription.js.map +1 -1
  70. package/dist/thrown-error.d.ts +16 -0
  71. package/dist/thrown-error.d.ts.map +1 -0
  72. package/dist/thrown-error.js +31 -0
  73. package/dist/thrown-error.js.map +1 -0
  74. package/dist/types.d.ts +59 -15
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/types.js.map +1 -1
  77. package/package.json +6 -2
  78. package/src/auth.ts +135 -44
  79. package/src/bindings.ts +4 -1
  80. package/src/error-codes-doc.ts +9 -1
  81. package/src/errors.ts +155 -57
  82. package/src/graphql-transport.ts +7 -8
  83. package/src/index.ts +82 -60
  84. package/src/latest-rows.ts +78 -0
  85. package/src/mutation-request.ts +34 -19
  86. package/src/page-env-script.ts +27 -0
  87. package/src/preview.ts +8 -4
  88. package/src/query.ts +128 -52
  89. package/src/realtime.ts +15 -6
  90. package/src/runtime-env.ts +220 -0
  91. package/src/setup-fault.ts +18 -0
  92. package/src/storage.ts +26 -16
  93. package/src/table-subscription.ts +3 -3
  94. package/src/thrown-error.ts +31 -0
  95. package/src/types.ts +65 -14
  96. package/tests/auth-errors.test.ts +3 -3
  97. package/tests/auth-events.test.ts +3 -7
  98. package/tests/auth-sso.test.ts +260 -0
  99. package/tests/auth-url-session.test.ts +6 -25
  100. package/tests/data-plane-auth.test.ts +1 -6
  101. package/tests/draft-insert.test.ts +9 -9
  102. package/tests/draft-update.test.ts +5 -5
  103. package/tests/entry-points.test.ts +9 -0
  104. package/tests/error-family.test.ts +79 -0
  105. package/tests/helpers/auth-unmount-binding.ts +63 -0
  106. package/tests/helpers/oauth-binding.ts +4 -3
  107. package/tests/helpers/stale-read-binding.ts +113 -0
  108. package/tests/helpers/thrown-error-binding.ts +127 -0
  109. package/tests/minimal-writes.test.ts +118 -0
  110. package/tests/postgrest-error-codes.test.ts +5 -5
  111. package/tests/query.test.ts +3 -3
  112. package/tests/rate-limit-integration.test.ts +1 -1
  113. package/tests/realtime-session-auth.test.ts +1 -4
  114. package/tests/result-error-class.test.ts +107 -0
  115. package/tests/retry-policy.test.ts +1 -1
  116. package/tests/rpc-resend.test.ts +33 -8
  117. package/tests/runtime-env-bundle.test.ts +121 -0
  118. package/tests/runtime-env-page-script.test.ts +174 -0
  119. package/tests/runtime-env.test.ts +224 -0
  120. package/tests/server-bodies.test.ts +3 -3
  121. package/tests/supatype-prepare.test.ts +139 -0
  122. package/tests/support/browser.ts +28 -0
  123. package/tests/support/jwt.ts +9 -0
  124. package/tests/thrown-error.test.ts +59 -0
  125. package/tests/unauthorized-resend.test.ts +107 -0
  126. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,139 @@
1
+ import { afterEach, describe, expect, it } from "vitest"
2
+ import { spawnSync } from "node:child_process"
3
+ import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs"
4
+ import { tmpdir } from "node:os"
5
+ import { join } from "node:path"
6
+
7
+ const BIN = join(import.meta.dirname, "..", "bin", "supatype-prepare.js")
8
+
9
+ /**
10
+ * `supatype-prepare`, a project's `prepare`, run in the project as npm runs it. A production
11
+ * install leaves out development dependencies, the CLI with them, and still runs `prepare`, where
12
+ * a bare `supatype generate` failed the install with `supatype: not found`.
13
+ */
14
+ describe("supatype-prepare", () => {
15
+ const dirs: string[] = []
16
+ afterEach(() => {
17
+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
18
+ })
19
+
20
+ function project(): string {
21
+ const dir = mkdtempSync(join(tmpdir(), "supatype-prepare-"))
22
+ dirs.push(dir)
23
+ writeFileSync(join(dir, "package.json"), '{ "type": "module" }\n')
24
+ return dir
25
+ }
26
+
27
+ /** A workspace member under `root`, with no node_modules of its own. */
28
+ function member(root: string): string {
29
+ const pkg = join(root, "packages", "app")
30
+ mkdirSync(pkg, { recursive: true })
31
+ writeFileSync(join(pkg, "package.json"), '{ "type": "module" }\n')
32
+ return pkg
33
+ }
34
+
35
+ /**
36
+ * A stand-in CLI whose `generate` records that it ran, and exits with `status`. Its `exports` do
37
+ * not name its package.json, as no release's do: it is found all the same.
38
+ */
39
+ function installCli(dir: string, status: number, folder = "node_modules", bin: string | object = { supatype: "./bin/supatype.js" }): void {
40
+ const cli = join(dir, folder, "@supatype", "cli")
41
+ mkdirSync(join(cli, "bin"), { recursive: true })
42
+ const manifest = { name: "@supatype/cli", bin, exports: { ".": "./index.js" } }
43
+ writeFileSync(join(cli, "package.json"), JSON.stringify(manifest))
44
+ const script = `require("node:fs").writeFileSync("generated", process.argv[2]); process.exit(${status})`
45
+ writeFileSync(join(cli, "bin", "supatype.js"), `${script}\n`)
46
+ }
47
+
48
+ const prepare = (cwd: string, env: NodeJS.ProcessEnv = {}) =>
49
+ spawnSync(process.execPath, [BIN], { cwd, encoding: "utf8", env: { ...process.env, ...env } })
50
+
51
+ const generated = (dir: string): boolean => existsSync(join(dir, "generated"))
52
+
53
+ it("succeeds, and generates nothing, where the CLI is not installed", () => {
54
+ const dir = project()
55
+ const result = prepare(dir)
56
+ expect(result.status, result.stderr).toBe(0)
57
+ expect(generated(dir)).toBe(false)
58
+ })
59
+
60
+ // pnpm's bin shims point NODE_PATH at pnpm's store, and Node's global folders include
61
+ // ~/.node_modules: neither is this project's, and a production install that left the CLI out
62
+ // must not run some other copy.
63
+ it.each([
64
+ ["on NODE_PATH", "node_modules", (dir: string) => ({ NODE_PATH: join(dir, "node_modules") })],
65
+ ["in the home folder's .node_modules", ".node_modules", (dir: string) => ({ HOME: dir, USERPROFILE: dir })],
66
+ ] as const)("ignores a CLI %s", (_, folder, env) => {
67
+ const elsewhere = project()
68
+ installCli(elsewhere, 0, folder)
69
+ const dir = project()
70
+ const result = prepare(dir, env(elsewhere))
71
+ expect(result.status, result.stderr).toBe(0)
72
+ expect(generated(dir)).toBe(false)
73
+ })
74
+
75
+ // npm reads `bin` given as a string as the package's one command.
76
+ it.each([
77
+ ["named", { supatype: "./bin/supatype.js" }],
78
+ ["given as a string", "./bin/supatype.js"],
79
+ ] as const)("runs supatype generate where the CLI is installed, its bin %s", (_, bin) => {
80
+ const dir = project()
81
+ installCli(dir, 0, "node_modules", bin)
82
+ const result = prepare(dir)
83
+ expect(result.status, result.stderr).toBe(0)
84
+ expect(generated(dir)).toBe(true)
85
+ })
86
+
87
+ // A workspace hoists the CLI to the root's node_modules, above the package that runs prepare.
88
+ it("finds a CLI hoisted into a parent directory", () => {
89
+ const root = project()
90
+ installCli(root, 0)
91
+ const pkg = member(root)
92
+ const result = prepare(pkg)
93
+ expect(result.status, result.stderr).toBe(0)
94
+ expect(generated(pkg)).toBe(true)
95
+ })
96
+
97
+ // A workspace member can pin a CLI of its own beside the one the root hoists.
98
+ it("runs the nearest CLI", () => {
99
+ const root = project()
100
+ installCli(root, 4)
101
+ const pkg = member(root)
102
+ installCli(pkg, 0)
103
+ const result = prepare(pkg)
104
+ expect(result.status, result.stderr).toBe(0)
105
+ expect(generated(pkg)).toBe(true)
106
+ })
107
+
108
+ // A node_modules above the project that is a file, or one the user may not read, holds no CLI.
109
+ // Node's own lookup passes over it. Only Linux and macOS report a file there as ENOTDIR.
110
+ it("passes over a node_modules it cannot look inside", () => {
111
+ const root = project()
112
+ writeFileSync(join(root, "node_modules"), "")
113
+ const pkg = member(root)
114
+ const result = prepare(pkg)
115
+ expect(result.status, result.stderr).toBe(0)
116
+ })
117
+
118
+ // A link into a pruned pnpm store, an empty folder, a package.json naming no command: skipping
119
+ // any of them would pass the install and fail the build later, on files never generated.
120
+ it.each([
121
+ ["a link to nothing", (cli: string) => symlinkSync(join(cli, "..", "gone"), cli, "junction")],
122
+ ["an empty folder", (cli: string) => mkdirSync(cli)],
123
+ ["a CLI naming no supatype command", (cli: string) => installCli(join(cli, "..", "..", ".."), 0, "node_modules", { other: "./x.js" })],
124
+ ] as const)("fails the install when the CLI folder is %s", (_, make) => {
125
+ const dir = project()
126
+ const cli = join(dir, "node_modules", "@supatype", "cli")
127
+ mkdirSync(join(cli, ".."), { recursive: true })
128
+ make(cli)
129
+ const result = prepare(dir)
130
+ expect(result.status).toBe(1)
131
+ expect(result.stderr).toContain("cannot read the Supatype CLI")
132
+ })
133
+
134
+ it("fails the install when generate fails", () => {
135
+ const dir = project()
136
+ installCli(dir, 3)
137
+ expect(prepare(dir).status).toBe(3)
138
+ })
139
+ })
@@ -0,0 +1,28 @@
1
+ import { vi, type Mock } from "vitest"
2
+
3
+ /** What a stubbed browser records: navigations, address-bar rewrites, and its localStorage. */
4
+ export interface StubbedBrowser {
5
+ assign: Mock<(url: string) => void>
6
+ replaceState: Mock<(state: unknown, unused: string, url: string) => void>
7
+ store: Map<string, string>
8
+ }
9
+
10
+ /**
11
+ * A browser at `href`, with a localStorage holding `stored`. Not named `*.test.ts`, so vitest's
12
+ * default include does not collect it as a suite.
13
+ */
14
+ export function stubBrowser(href: string, stored: Record<string, string> = {}): StubbedBrowser {
15
+ const store = new Map(Object.entries(stored))
16
+ const assign = vi.fn<(url: string) => void>()
17
+ const replaceState = vi.fn<(state: unknown, unused: string, url: string) => void>()
18
+ vi.stubGlobal("window", {
19
+ location: { href, protocol: "https:", assign },
20
+ history: { state: null, replaceState },
21
+ localStorage: {
22
+ getItem: (k: string) => store.get(k) ?? null,
23
+ setItem: (k: string, v: string) => { store.set(k, v) },
24
+ removeItem: (k: string) => { store.delete(k) },
25
+ },
26
+ })
27
+ return { assign, replaceState, store }
28
+ }
@@ -0,0 +1,9 @@
1
+ /** An unsigned JWT carrying `payload`: the client only ever decodes the payload, never checks the signature. */
2
+ export function fakeJwt(payload: Record<string, unknown>): string {
3
+ return `${btoa(JSON.stringify({ alg: "HS256", typ: "JWT" }))}.${btoa(JSON.stringify(payload))}.sig`
4
+ }
5
+
6
+ /** A fake access token that expires in an hour. */
7
+ export function liveAccessToken(): string {
8
+ return fakeJwt({ exp: Math.floor(Date.now() / 1000) + 3600 })
9
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * `reportThrown`: what a binding holds as `error` for a request that threw, and the one console
3
+ * line that says so.
4
+ */
5
+
6
+ import { afterEach, describe, expect, it, vi } from "vitest"
7
+ import { reportThrown } from "../src/thrown-error.js"
8
+ import { MissingClientValuesError, NetworkError, RateLimitError, SupatypeError } from "../src/errors.js"
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks()
12
+ })
13
+
14
+ function quietly(thrown: unknown): ReturnType<typeof reportThrown> {
15
+ vi.spyOn(console, "error").mockImplementation(() => undefined)
16
+ return reportThrown("useQuery(\"posts\")", thrown)
17
+ }
18
+
19
+ describe("reportThrown", () => {
20
+ it("names the hook and carries the thrown value on one console line", () => {
21
+ const logged = vi.spyOn(console, "error").mockImplementation(() => undefined)
22
+ const thrown = new Error("no address")
23
+ reportThrown("useQuery(\"posts\")", thrown)
24
+ expect(logged).toHaveBeenCalledTimes(1)
25
+ expect(logged).toHaveBeenCalledWith("[supatype] useQuery(\"posts\"): the request threw.", thrown)
26
+ })
27
+
28
+ it("keeps one of the SDK's own errors as it is, so instanceof still names it", () => {
29
+ const thrown = new MissingClientValuesError("no address", ["url"])
30
+ expect(quietly(thrown)).toBe(thrown)
31
+ })
32
+
33
+ it("holds any other Error as the cause of a SupatypeError with its message", () => {
34
+ const thrown = new Error("no address")
35
+ const held = quietly(thrown)
36
+ expect(held).toBeInstanceOf(SupatypeError)
37
+ expect((held as Error).cause).toBe(thrown)
38
+ expect({ ...(held as object) }).toEqual({ message: "no address" })
39
+ })
40
+
41
+ it("gives the SDK's own errors the JSON a failed request answers with", () => {
42
+ expect(JSON.parse(JSON.stringify(quietly(new RateLimitError(3))))).toEqual({
43
+ message: "Rate limited. Retry after 3 seconds.",
44
+ code: "RATE_LIMITED",
45
+ status: 429,
46
+ })
47
+ expect({ ...quietly(new NetworkError("offline")) }).toEqual({ message: "offline", code: "NETWORK_ERROR" })
48
+ })
49
+
50
+ it("wraps an Error whose fields do not fit, keeping its message", () => {
51
+ const thrown = Object.assign(new Error("socket hang up"), { code: 104 })
52
+ expect({ ...quietly(thrown) }).toEqual({ message: "socket hang up" })
53
+ })
54
+
55
+ it("wraps a thrown string or anything else", () => {
56
+ expect({ ...quietly("bad thing") }).toEqual({ message: "bad thing" })
57
+ expect({ ...quietly({ nope: true }) }).toEqual({ message: "Unknown error" })
58
+ })
59
+ })
@@ -0,0 +1,107 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest"
2
+ import { createClient, type AnyDatabase, type Session } from "../src/index.js"
3
+ import { fetchCalls, header, jsonResponse, mockFetch, requestUrl, type FetchMock } from "./support/fetch-mock.js"
4
+ import { fakeJwt } from "./support/jwt.js"
5
+
6
+ // A 401 is resent only when the server said the token was expired or invalid, a session was there to
7
+ // refresh, and the refresh produced a different token. Anything else (a row rule refusing an anon
8
+ // write, above all) goes out once: sending it again only repeats the refusal, and a write twice.
9
+
10
+ const BASE = "http://localhost:18473"
11
+ const ANON_KEY = "anon-key"
12
+ const NOW = Math.floor(Date.now() / 1000)
13
+
14
+ const STALE = fakeJwt({ role: "authenticated", sub: "user-1", exp: NOW + 3600, n: 1 })
15
+ const FRESH = fakeJwt({ role: "authenticated", sub: "user-1", exp: NOW + 7200, n: 2 })
16
+
17
+ /** A session the local clock still calls valid, which the server has nonetheless refused. */
18
+ const SESSION: Session = {
19
+ accessToken: STALE,
20
+ tokenType: "bearer",
21
+ expiresIn: 3600,
22
+ expiresAt: NOW + 3600,
23
+ refreshToken: "rt-1",
24
+ user: { id: "user-1", appMetadata: {}, userMetadata: {}, createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z" },
25
+ }
26
+
27
+ const RAW_USER = { id: "user-1", app_metadata: {}, user_metadata: {}, created_at: "2026-01-01T00:00:00Z", updated_at: "2026-01-01T00:00:00Z" }
28
+
29
+ /** PostgREST refusing an anon write a row rule does not allow. */
30
+ const RLS_REFUSAL = { code: "42501", details: null, hint: null, message: 'new row violates row-level security policy for table "orders"' }
31
+ /** PostgREST 14 refusing an expired token. */
32
+ const EXPIRED = { code: "PGRST303", details: null, hint: null, message: "JWT expired" }
33
+
34
+ /** Answers the table with `refusal` until a request carries FRESH, and the refresh with `refreshed`. */
35
+ function server(refusal: Record<string, unknown>, refreshed: string): FetchMock {
36
+ return mockFetch((input, init) => {
37
+ if (requestUrl(input).includes("/auth/v1/token")) {
38
+ return Promise.resolve(
39
+ jsonResponse({ access_token: refreshed, refresh_token: "rt-2", token_type: "bearer", expires_in: 3600, user: RAW_USER }),
40
+ )
41
+ }
42
+ const fresh = header(init ?? {}, "Authorization") === `Bearer ${FRESH}`
43
+ return Promise.resolve(fresh ? jsonResponse(null, 201) : jsonResponse(refusal, 401))
44
+ })
45
+ }
46
+
47
+ function serve(fetch: FetchMock): FetchMock {
48
+ vi.stubGlobal("fetch", fetch)
49
+ return fetch
50
+ }
51
+
52
+ const tableCalls = (fetch: FetchMock) => fetchCalls(fetch).filter(({ url }) => url.includes("/rest/v1/orders"))
53
+ const refreshCalls = (fetch: FetchMock) => fetchCalls(fetch).filter(({ url }) => url.includes("/auth/v1/token"))
54
+
55
+ function signedIn() {
56
+ return createClient<AnyDatabase>({
57
+ url: BASE,
58
+ anonKey: ANON_KEY,
59
+ auth: { persistSession: false, autoRefreshToken: false },
60
+ initialSession: SESSION,
61
+ })
62
+ }
63
+
64
+ describe("the resend after a 401", () => {
65
+ afterEach(() => vi.unstubAllGlobals())
66
+
67
+ it("is not made for an anon write a row rule refused", async () => {
68
+ const fetch = serve(server(RLS_REFUSAL, FRESH))
69
+ const client = createClient<AnyDatabase>({ url: BASE, anonKey: ANON_KEY, auth: { persistSession: false } })
70
+ const { error } = await client.from("orders").insert({ item: "latte" })
71
+ expect(error).toMatchObject({ code: "42501", status: 401 })
72
+ expect(tableCalls(fetch)).toHaveLength(1)
73
+ expect(refreshCalls(fetch)).toHaveLength(0)
74
+ })
75
+
76
+ it("is not made for a signed-in write a row rule refused, and nothing is refreshed", async () => {
77
+ const fetch = serve(server(RLS_REFUSAL, FRESH))
78
+ const { error } = await signedIn().from("orders").insert({ item: "latte" })
79
+ expect(error).toMatchObject({ code: "42501" })
80
+ expect(tableCalls(fetch)).toHaveLength(1)
81
+ expect(refreshCalls(fetch)).toHaveLength(0)
82
+ })
83
+
84
+ it("refreshes an expired token the local clock calls valid, and sends again with the new one", async () => {
85
+ const fetch = serve(server(EXPIRED, FRESH))
86
+ const { error } = await signedIn().from("orders").insert({ item: "latte" })
87
+ expect(error).toBeNull()
88
+ expect(refreshCalls(fetch)).toHaveLength(1)
89
+ expect(tableCalls(fetch).map(({ init }) => header(init, "Authorization"))).toEqual([`Bearer ${STALE}`, `Bearer ${FRESH}`])
90
+ })
91
+
92
+ it("is not made when the refresh hands back the token the server refused", async () => {
93
+ const fetch = serve(server(EXPIRED, STALE))
94
+ const { error } = await signedIn().from("orders").insert({ item: "latte" })
95
+ expect(error).toMatchObject({ code: "PGRST303" })
96
+ expect(refreshCalls(fetch)).toHaveLength(1)
97
+ expect(tableCalls(fetch)).toHaveLength(1)
98
+ })
99
+
100
+ it("is not made for an anon caller whose token the server called expired, there being no session", async () => {
101
+ const fetch = serve(server(EXPIRED, FRESH))
102
+ const client = createClient<AnyDatabase>({ url: BASE, anonKey: ANON_KEY, auth: { persistSession: false } })
103
+ await client.from("orders").select("id")
104
+ expect(tableCalls(fetch)).toHaveLength(1)
105
+ expect(refreshCalls(fetch)).toHaveLength(0)
106
+ })
107
+ })