@supatype/client 0.1.6 → 0.1.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +21 -20
- package/.turbo/turbo-typecheck.log +1 -1
- package/LICENSE +21 -0
- package/dist/auth.js +2 -2
- package/dist/auth.js.map +1 -1
- package/dist/error-codes-doc.d.ts +1 -1
- package/dist/error-codes-doc.js +1 -1
- package/dist/errors.d.ts +6 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/query-cache.d.ts +1 -1
- package/dist/query-cache.d.ts.map +1 -1
- package/dist/query-cache.js +1 -1
- package/dist/query-cache.js.map +1 -1
- package/dist/query.d.ts +10 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +47 -10
- package/dist/query.js.map +1 -1
- package/dist/realtime.js +1 -1
- package/dist/realtime.js.map +1 -1
- package/dist/serverless-docs.d.ts +1 -1
- package/dist/serverless-docs.js +4 -4
- package/dist/serverless-docs.js.map +1 -1
- package/dist/types.d.ts +31 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/auth.ts +2 -2
- package/src/error-codes-doc.ts +1 -1
- package/src/errors.ts +3 -3
- package/src/index.ts +6 -2
- package/src/query-cache.ts +1 -1
- package/src/query.ts +50 -13
- package/src/realtime.ts +1 -1
- package/src/serverless-docs.ts +4 -4
- package/src/types.ts +32 -3
- package/tests/masked-fields.test.ts +51 -0
- package/tests/mfa-totp-integration.test.ts +9 -9
- package/tests/query.test.ts +4 -4
- package/tests/rate-limit-integration.test.ts +3 -3
- package/tests/realtime-multi-tenant-integration.test.ts +4 -4
- package/tests/retry-integration.test.ts +3 -3
- package/tests/serverless.test.ts +1 -1
- package/tests/storage-quota-integration.test.ts +2 -2
- package/tests/storage-upload-limit-integration.test.ts +4 -4
- package/tests/types.test.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/src/query.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { QueryCache, QueryCacheOptions, CacheStatus } from "./query-cache.js"
|
|
2
2
|
import { buildCacheKey, defaultQueryCache } from "./query-cache.js"
|
|
3
|
-
import type { QueryResult, SelectQueryOptions, SupatypeError } from "./types.js"
|
|
3
|
+
import type { MaskedField, QueryResult, SelectQueryOptions, SupatypeError } from "./types.js"
|
|
4
4
|
|
|
5
5
|
const DEBUG_AUTH =
|
|
6
6
|
(typeof process !== "undefined" && process.env["NEXT_PUBLIC_SUPATYPE_DEBUG_AUTH"] === "1") ||
|
|
@@ -24,14 +24,40 @@ function decodeJwtRoleFromAuthHeader(headers: Record<string, string>): string |
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Parse `X-Supatype-Masked-Fields: salary=row, ssn=identity`.
|
|
29
|
+
*
|
|
30
|
+
* Unrecognised entries are dropped rather than guessed at: this is advisory decoration, so
|
|
31
|
+
* a header from a newer server saying something this client does not understand should
|
|
32
|
+
* degrade to silence, never to a wrong claim about which columns are masked.
|
|
33
|
+
*/
|
|
34
|
+
export function parseMaskedFields(header: string | null): MaskedField[] | undefined {
|
|
35
|
+
if (header === null || header.trim() === "") return undefined
|
|
36
|
+
|
|
37
|
+
const fields: MaskedField[] = []
|
|
38
|
+
for (const entry of header.split(",")) {
|
|
39
|
+
const [column, scope] = entry.split("=", 2).map((part) => part.trim())
|
|
40
|
+
if (column === undefined || column === "") continue
|
|
41
|
+
if (scope !== "identity" && scope !== "row") continue
|
|
42
|
+
fields.push({ column, scope })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return fields.length > 0 ? fields : undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function withMeta<T>(
|
|
28
49
|
result: QueryResult<T>,
|
|
29
|
-
cacheStatus?: CacheStatus,
|
|
50
|
+
meta: { cacheStatus?: CacheStatus; maskedFields?: MaskedField[] | undefined },
|
|
30
51
|
): QueryResult<T> {
|
|
31
|
-
|
|
52
|
+
const { cacheStatus, maskedFields } = meta
|
|
53
|
+
if (cacheStatus === undefined && maskedFields === undefined) return result
|
|
32
54
|
return {
|
|
33
55
|
...result,
|
|
34
|
-
meta: {
|
|
56
|
+
meta: {
|
|
57
|
+
...(result.meta ?? {}),
|
|
58
|
+
...(cacheStatus !== undefined && { cacheStatus }),
|
|
59
|
+
...(maskedFields !== undefined && { maskedFields }),
|
|
60
|
+
},
|
|
35
61
|
}
|
|
36
62
|
}
|
|
37
63
|
|
|
@@ -177,7 +203,7 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
177
203
|
return this
|
|
178
204
|
}
|
|
179
205
|
|
|
180
|
-
/** PostgREST OR filter
|
|
206
|
+
/** PostgREST OR filter: pass conditions in PostgREST syntax, e.g. `"status.eq.active,owner_id.eq.123"`. */
|
|
181
207
|
or(filters: string): this {
|
|
182
208
|
this.params.append("or", `(${filters})`)
|
|
183
209
|
return this
|
|
@@ -216,7 +242,17 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
216
242
|
Accept: "application/vnd.pgrst.object+json",
|
|
217
243
|
})
|
|
218
244
|
if (error !== null) return { data: null, error, count: null, ...(meta && { meta }) }
|
|
219
|
-
|
|
245
|
+
// Some proxies drop Accept and return a one-element array, unwrap.
|
|
246
|
+
const row = (Array.isArray(data) ? data[0] : data) as TRow | undefined
|
|
247
|
+
if (row === undefined) {
|
|
248
|
+
return {
|
|
249
|
+
data: null,
|
|
250
|
+
error: { message: "JSON object requested, multiple (or no) rows returned", code: "PGRST116" },
|
|
251
|
+
count: null,
|
|
252
|
+
...(meta && { meta }),
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { data: row, error: null, count: 1, ...(meta && { meta }) }
|
|
220
256
|
}
|
|
221
257
|
|
|
222
258
|
/** Return a single row or null (errors if many found). */
|
|
@@ -282,7 +318,7 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
282
318
|
})
|
|
283
319
|
const cached = this.queryCache.get<TRow[]>(cacheKey)
|
|
284
320
|
if (cached) {
|
|
285
|
-
return
|
|
321
|
+
return withMeta(cached, { cacheStatus: "HIT" })
|
|
286
322
|
}
|
|
287
323
|
}
|
|
288
324
|
|
|
@@ -308,6 +344,7 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
308
344
|
? parseInt(contentRange.split("/")[1] ?? "0", 10)
|
|
309
345
|
: null
|
|
310
346
|
|
|
347
|
+
const maskedFields = parseMaskedFields(res.headers.get("X-Supatype-Masked-Fields"))
|
|
311
348
|
const serverCacheStatus = res.headers.get("X-Supatype-Cache-Status") as CacheStatus | null
|
|
312
349
|
const cacheStatus: CacheStatus =
|
|
313
350
|
serverCacheStatus === "HIT" || serverCacheStatus === "MISS" || serverCacheStatus === "BYPASS"
|
|
@@ -328,7 +365,7 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
328
365
|
code: typeof err["code"] === "string" ? err["code"] : null,
|
|
329
366
|
})
|
|
330
367
|
}
|
|
331
|
-
return
|
|
368
|
+
return withMeta<TRow[]>(
|
|
332
369
|
{
|
|
333
370
|
data: null,
|
|
334
371
|
error: {
|
|
@@ -338,14 +375,14 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
338
375
|
},
|
|
339
376
|
count: null,
|
|
340
377
|
},
|
|
341
|
-
cacheStatus,
|
|
378
|
+
{ cacheStatus, maskedFields },
|
|
342
379
|
)
|
|
343
380
|
}
|
|
344
381
|
|
|
345
382
|
if (method === "HEAD" || res.status === 204) {
|
|
346
|
-
return
|
|
383
|
+
return withMeta<TRow[]>(
|
|
347
384
|
{ data: null, error: null, count },
|
|
348
|
-
cacheStatus,
|
|
385
|
+
{ cacheStatus, maskedFields },
|
|
349
386
|
)
|
|
350
387
|
}
|
|
351
388
|
|
|
@@ -360,7 +397,7 @@ export class QueryBuilder<TRow> implements PromiseLike<QueryResult<TRow[]>> {
|
|
|
360
397
|
this.queryCache.set(cacheKey, result, this.cacheOptions.ttl)
|
|
361
398
|
}
|
|
362
399
|
|
|
363
|
-
return
|
|
400
|
+
return withMeta(result, { cacheStatus, maskedFields })
|
|
364
401
|
}
|
|
365
402
|
}
|
|
366
403
|
|
package/src/realtime.ts
CHANGED
|
@@ -311,7 +311,7 @@ export class RealtimeClient {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
if (msg.status === "error") {
|
|
314
|
-
// Find which channel this error relates to
|
|
314
|
+
// Find which channel this error relates to, broadcast to all as fallback
|
|
315
315
|
for (const state of this.channels.values()) {
|
|
316
316
|
state.statusCallback?.("CHANNEL_ERROR")
|
|
317
317
|
}
|
package/src/serverless-docs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Serverless connection documentation
|
|
2
|
+
* Serverless connection documentation: Gap Appendices task 84
|
|
3
3
|
*
|
|
4
4
|
* Code-accessible documentation for connection modes.
|
|
5
5
|
* Rendered in Studio's getting-started view and available to CLI help output.
|
|
@@ -39,7 +39,7 @@ export const CONNECTION_MODES: readonly ConnectionModeDoc[] = [
|
|
|
39
39
|
"",
|
|
40
40
|
"const client = createClient(process.env.SUPATYPE_URL!, process.env.SUPATYPE_ANON_KEY!)",
|
|
41
41
|
"",
|
|
42
|
-
"// Safe in serverless
|
|
42
|
+
"// Safe in serverless, each call is an HTTP request, not a new DB connection",
|
|
43
43
|
"const users = await client.from(\"users\").select()",
|
|
44
44
|
].join("\n"),
|
|
45
45
|
},
|
|
@@ -54,7 +54,7 @@ export const CONNECTION_MODES: readonly ConnectionModeDoc[] = [
|
|
|
54
54
|
"within seconds under load. Direct connections are only appropriate for long-lived " +
|
|
55
55
|
"server processes that open a connection once and reuse it across many requests.",
|
|
56
56
|
example: [
|
|
57
|
-
'// ONLY for long-lived servers
|
|
57
|
+
'// ONLY for long-lived servers, NOT for serverless',
|
|
58
58
|
'import pg from "pg"',
|
|
59
59
|
"",
|
|
60
60
|
"const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })",
|
|
@@ -72,7 +72,7 @@ export const CONNECTION_MODES: readonly ConnectionModeDoc[] = [
|
|
|
72
72
|
export const SERVERLESS_CONNECTION_WARNING =
|
|
73
73
|
"Use the Supatype SDK (via PostgREST) in serverless environments (Next.js API routes, " +
|
|
74
74
|
"Vercel Edge Functions, AWS Lambda). PostgREST handles connection pooling for you. " +
|
|
75
|
-
"Do NOT use direct database connections from serverless
|
|
75
|
+
"Do NOT use direct database connections from serverless, each invocation opens a new " +
|
|
76
76
|
"connection, which will exhaust your connection pool within seconds under load."
|
|
77
77
|
|
|
78
78
|
/**
|
package/src/types.ts
CHANGED
|
@@ -54,8 +54,8 @@ export type AuthChangeEvent =
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* OAuth / magic-link redirect flow.
|
|
57
|
-
* - `pkce
|
|
58
|
-
* - `implicit
|
|
57
|
+
* - `pkce`: authorize with code_challenge; app exchanges `?code=` via `exchangeCodeForSession`.
|
|
58
|
+
* - `implicit`: tokens returned in the URL hash (`#access_token=…`).
|
|
59
59
|
*
|
|
60
60
|
* Web `signInWithOAuth` defaults to `implicit` for backward compatibility.
|
|
61
61
|
* React Native helpers should pass `pkce` (recommended default for mobile).
|
|
@@ -132,12 +132,37 @@ export interface SupatypeError {
|
|
|
132
132
|
|
|
133
133
|
// ─── Query result ─────────────────────────────────────────────────────────────
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* A column in the response that carries a read restriction.
|
|
137
|
+
*
|
|
138
|
+
* Postgres cannot omit a column, the result-set shape is fixed and identical for every row
|
|
139
|
+
*- so a column you may not read comes back as `null`, indistinguishable on the wire from a
|
|
140
|
+
* value that is genuinely null. This says which nulls are explicable by masking.
|
|
141
|
+
*
|
|
142
|
+
* Advisory. It describes the schema's restrictions, not a decision: what you can actually
|
|
143
|
+
* read is enforced in the database, and ignoring or tampering with this changes nothing.
|
|
144
|
+
*/
|
|
145
|
+
export interface MaskedField {
|
|
146
|
+
column: string
|
|
147
|
+
/**
|
|
148
|
+
* `identity`: the verdict is the same for every row in this response, so a `null` in the
|
|
149
|
+
* column is explicable by masking for the whole result set.
|
|
150
|
+
*
|
|
151
|
+
* `row`: the rule reads the row, so only *some* nulls are masked values and the rest are
|
|
152
|
+
* genuinely null. Deliberately not narrowed further: the header is computed before the
|
|
153
|
+
* query runs, so claiming more would be a guess.
|
|
154
|
+
*/
|
|
155
|
+
scope: "identity" | "row"
|
|
156
|
+
}
|
|
157
|
+
|
|
135
158
|
export interface QueryResult<TData> {
|
|
136
159
|
data: TData | null
|
|
137
160
|
error: SupatypeError | null
|
|
138
161
|
count: number | null
|
|
139
162
|
meta?: {
|
|
140
163
|
cacheStatus?: "HIT" | "MISS" | "BYPASS" | undefined
|
|
164
|
+
/** Present only when the response named restricted columns. Absent means "not stated". */
|
|
165
|
+
maskedFields?: MaskedField[] | undefined
|
|
141
166
|
} | undefined
|
|
142
167
|
}
|
|
143
168
|
|
|
@@ -253,7 +278,7 @@ export interface SupatypeClientConfig {
|
|
|
253
278
|
/** Anon JWT key */
|
|
254
279
|
anonKey: string
|
|
255
280
|
/**
|
|
256
|
-
* Service role key
|
|
281
|
+
* Service role key: bypasses row-level security.
|
|
257
282
|
* Only set this in trusted server-side or developer-tool contexts.
|
|
258
283
|
* Never expose to end-user clients.
|
|
259
284
|
*/
|
|
@@ -295,4 +320,8 @@ export interface SupatypeClientConfig {
|
|
|
295
320
|
* before any requests are made.
|
|
296
321
|
*/
|
|
297
322
|
initialSession?: Session | undefined
|
|
323
|
+
/**
|
|
324
|
+
* Extra headers merged into every request (e.g. Studio `X-Supatype-Environment`).
|
|
325
|
+
*/
|
|
326
|
+
headers?: Record<string, string> | undefined
|
|
298
327
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { parseMaskedFields } from "../src/query.js"
|
|
3
|
+
|
|
4
|
+
// A column you may not read comes back as `null`, because Postgres cannot omit a column from
|
|
5
|
+
// a result set. On the wire that is indistinguishable from a value that is genuinely null.
|
|
6
|
+
// This header is what tells the two apart, advisory only, so parsing it must fail towards
|
|
7
|
+
// saying nothing rather than towards saying something wrong.
|
|
8
|
+
|
|
9
|
+
describe("parseMaskedFields", () => {
|
|
10
|
+
it("reads a single entry", () => {
|
|
11
|
+
expect(parseMaskedFields("salary=identity")).toEqual([
|
|
12
|
+
{ column: "salary", scope: "identity" },
|
|
13
|
+
])
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it("reads several entries and tolerates the spacing the server sends", () => {
|
|
17
|
+
expect(parseMaskedFields("salary=row, ssn=identity")).toEqual([
|
|
18
|
+
{ column: "salary", scope: "row" },
|
|
19
|
+
{ column: "ssn", scope: "identity" },
|
|
20
|
+
])
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it("is undefined when nothing is restricted", () => {
|
|
24
|
+
expect(parseMaskedFields(null)).toBeUndefined()
|
|
25
|
+
expect(parseMaskedFields("")).toBeUndefined()
|
|
26
|
+
expect(parseMaskedFields(" ")).toBeUndefined()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// A newer server may describe a scope this client does not know. Dropping the entry
|
|
30
|
+
// degrades to silence; keeping it would let app code branch on a value it cannot interpret.
|
|
31
|
+
it("drops entries it does not understand rather than guessing", () => {
|
|
32
|
+
expect(parseMaskedFields("salary=someFutureScope")).toBeUndefined()
|
|
33
|
+
expect(parseMaskedFields("salary=row, ssn=someFutureScope")).toEqual([
|
|
34
|
+
{ column: "salary", scope: "row" },
|
|
35
|
+
])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it("drops malformed entries", () => {
|
|
39
|
+
expect(parseMaskedFields("salary")).toBeUndefined()
|
|
40
|
+
expect(parseMaskedFields("=row")).toBeUndefined()
|
|
41
|
+
expect(parseMaskedFields(",,")).toBeUndefined()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// `scope` is the whole point of the distinction: `identity` means every null in that column
|
|
45
|
+
// is explicable by masking, `row` means only some are.
|
|
46
|
+
it("keeps the scope distinction intact", () => {
|
|
47
|
+
const fields = parseMaskedFields("a=identity, b=row")
|
|
48
|
+
expect(fields?.find((f) => f.column === "a")?.scope).toBe("identity")
|
|
49
|
+
expect(fields?.find((f) => f.column === "b")?.scope).toBe("row")
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Integration test
|
|
2
|
+
* Integration test: Task 89: MFA TOTP flow
|
|
3
3
|
*
|
|
4
4
|
* Tests: enroll -> QR code -> verify code -> login requires 2 steps ->
|
|
5
5
|
* JWT aal2 -> unenroll -> single step.
|
|
@@ -74,10 +74,10 @@ function freshClient(): AuthClient {
|
|
|
74
74
|
|
|
75
75
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
76
76
|
|
|
77
|
-
describe("Task 89
|
|
77
|
+
describe("Task 89: MFA TOTP integration", () => {
|
|
78
78
|
beforeEach(() => vi.restoreAllMocks())
|
|
79
79
|
|
|
80
|
-
describe("Step 1
|
|
80
|
+
describe("Step 1: Enroll TOTP factor", () => {
|
|
81
81
|
it("calls POST /factors with factor_type=totp", async () => {
|
|
82
82
|
// First sign in to have a session
|
|
83
83
|
const client = freshClient()
|
|
@@ -151,7 +151,7 @@ describe("Task 89 — MFA TOTP integration", () => {
|
|
|
151
151
|
})
|
|
152
152
|
})
|
|
153
153
|
|
|
154
|
-
describe("Step 2
|
|
154
|
+
describe("Step 2: Verify TOTP code (challenge + verify)", () => {
|
|
155
155
|
it("creates a challenge and verifies the TOTP code", async () => {
|
|
156
156
|
const client = freshClient()
|
|
157
157
|
vi.stubGlobal("fetch", mockFetch(makeTokenResponse()))
|
|
@@ -169,7 +169,7 @@ describe("Task 89 — MFA TOTP integration", () => {
|
|
|
169
169
|
expect(challengeResult.error).toBeNull()
|
|
170
170
|
expect(challengeResult.data!.id).toBe(CHALLENGE_ID)
|
|
171
171
|
|
|
172
|
-
// Mock verify
|
|
172
|
+
// Mock verify: returns AAL2 token
|
|
173
173
|
const aal2Response = makeTokenResponse({
|
|
174
174
|
access_token: makeAal2Token(),
|
|
175
175
|
})
|
|
@@ -232,7 +232,7 @@ describe("Task 89 — MFA TOTP integration", () => {
|
|
|
232
232
|
})
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
describe("Step 3
|
|
235
|
+
describe("Step 3: Login requires two steps with MFA enrolled", () => {
|
|
236
236
|
it("first step: password login returns AAL1 session", async () => {
|
|
237
237
|
const client = freshClient()
|
|
238
238
|
const aal1Response = makeTokenResponse()
|
|
@@ -260,7 +260,7 @@ describe("Task 89 — MFA TOTP integration", () => {
|
|
|
260
260
|
}))
|
|
261
261
|
await client.mfa.challenge({ factorId: FACTOR_ID })
|
|
262
262
|
|
|
263
|
-
// Verify
|
|
263
|
+
// Verify: AAL2
|
|
264
264
|
const aal2Token = makeAal2Token()
|
|
265
265
|
vi.stubGlobal("fetch", mockFetch(makeTokenResponse({ access_token: aal2Token })))
|
|
266
266
|
const { data } = await client.mfa.verify({
|
|
@@ -279,7 +279,7 @@ describe("Task 89 — MFA TOTP integration", () => {
|
|
|
279
279
|
})
|
|
280
280
|
})
|
|
281
281
|
|
|
282
|
-
describe("Step 4
|
|
282
|
+
describe("Step 4: getAuthenticatorAssuranceLevel", () => {
|
|
283
283
|
it("returns aal1 before TOTP verification", async () => {
|
|
284
284
|
const client = freshClient()
|
|
285
285
|
vi.stubGlobal("fetch", mockFetch(makeTokenResponse()))
|
|
@@ -321,7 +321,7 @@ describe("Task 89 — MFA TOTP integration", () => {
|
|
|
321
321
|
})
|
|
322
322
|
})
|
|
323
323
|
|
|
324
|
-
describe("Step 5
|
|
324
|
+
describe("Step 5: Unenroll factor, back to single step", () => {
|
|
325
325
|
it("calls DELETE /factors/:id to unenroll", async () => {
|
|
326
326
|
const client = freshClient()
|
|
327
327
|
vi.stubGlobal("fetch", mockFetch(makeTokenResponse({ access_token: makeAal2Token() })))
|
package/tests/query.test.ts
CHANGED
|
@@ -35,7 +35,7 @@ function captureUrl(): { url: () => string; fetch: ReturnType<typeof vi.fn> } {
|
|
|
35
35
|
|
|
36
36
|
// ─── QueryBuilder ─────────────────────────────────────────────────────────────
|
|
37
37
|
|
|
38
|
-
describe("QueryBuilder
|
|
38
|
+
describe("QueryBuilder: URL construction", () => {
|
|
39
39
|
beforeEach(() => vi.restoreAllMocks())
|
|
40
40
|
|
|
41
41
|
it("sends request to base + path with no params", async () => {
|
|
@@ -189,7 +189,7 @@ describe("QueryBuilder — URL construction", () => {
|
|
|
189
189
|
})
|
|
190
190
|
})
|
|
191
191
|
|
|
192
|
-
describe("QueryBuilder
|
|
192
|
+
describe("QueryBuilder: results", () => {
|
|
193
193
|
beforeEach(() => vi.restoreAllMocks())
|
|
194
194
|
|
|
195
195
|
it("returns data array on success", async () => {
|
|
@@ -261,7 +261,7 @@ describe("QueryBuilder.maybeSingle()", () => {
|
|
|
261
261
|
|
|
262
262
|
// ─── MutationBuilder ──────────────────────────────────────────────────────────
|
|
263
263
|
|
|
264
|
-
describe("MutationBuilder
|
|
264
|
+
describe("MutationBuilder: insert", () => {
|
|
265
265
|
beforeEach(() => vi.restoreAllMocks())
|
|
266
266
|
|
|
267
267
|
it("sends POST with body", async () => {
|
|
@@ -283,7 +283,7 @@ describe("MutationBuilder — insert", () => {
|
|
|
283
283
|
})
|
|
284
284
|
})
|
|
285
285
|
|
|
286
|
-
describe("MutationBuilder
|
|
286
|
+
describe("MutationBuilder: update / delete", () => {
|
|
287
287
|
beforeEach(() => vi.restoreAllMocks())
|
|
288
288
|
|
|
289
289
|
it("update sends PATCH with eq filter in URL", async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Integration test
|
|
2
|
+
* Integration test: Task 91: SDK rate limit handling
|
|
3
3
|
*
|
|
4
4
|
* Simulates 429 with Retry-After: 2 -> SDK waits -> retries -> succeeds.
|
|
5
5
|
*/
|
|
@@ -23,7 +23,7 @@ function mockResponse(status: number, body: unknown = {}, headers?: Record<strin
|
|
|
23
23
|
|
|
24
24
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
25
25
|
|
|
26
|
-
describe("Task 91
|
|
26
|
+
describe("Task 91: SDK rate limit integration", () => {
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
vi.restoreAllMocks()
|
|
29
29
|
vi.useFakeTimers()
|
|
@@ -144,7 +144,7 @@ describe("Task 91 — SDK rate limit integration", () => {
|
|
|
144
144
|
|
|
145
145
|
// Wait for 429 retry (1s)
|
|
146
146
|
await vi.advanceTimersByTimeAsync(1100)
|
|
147
|
-
// Wait for 503 retry (1000ms
|
|
147
|
+
// Wait for 503 retry (1000ms, second retry delay)
|
|
148
148
|
await vi.advanceTimersByTimeAsync(1100)
|
|
149
149
|
|
|
150
150
|
const res = await promise
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Integration test
|
|
2
|
+
* Integration test: Task 94: Realtime multi-tenant isolation
|
|
3
3
|
*
|
|
4
4
|
* Tests: subscribe to project A -> insert in A -> event received ->
|
|
5
5
|
* insert in B -> no event on A's subscription.
|
|
@@ -60,7 +60,7 @@ function simulateServerMessage(ws: MockWebSocketInstance, msg: Record<string, un
|
|
|
60
60
|
|
|
61
61
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
62
62
|
|
|
63
|
-
describe("Task 94
|
|
63
|
+
describe("Task 94: Realtime multi-tenant isolation", () => {
|
|
64
64
|
let MockWS: ReturnType<typeof createMockWebSocketClass>
|
|
65
65
|
|
|
66
66
|
beforeEach(() => {
|
|
@@ -151,14 +151,14 @@ describe("Task 94 — Realtime multi-tenant isolation", () => {
|
|
|
151
151
|
})
|
|
152
152
|
|
|
153
153
|
// Now simulate a message from project B arriving on the same WebSocket
|
|
154
|
-
// (this would be the server-side routing
|
|
154
|
+
// (this would be the server-side routing, in a real system, the server
|
|
155
155
|
// would NOT route project B events to project A's connection)
|
|
156
156
|
simulateServerMessage(wsA, {
|
|
157
157
|
type: "change",
|
|
158
158
|
channel: "projectB:posts", // Different channel
|
|
159
159
|
event: "INSERT",
|
|
160
160
|
payload: {
|
|
161
|
-
new: { id: 99, title: "Project B post
|
|
161
|
+
new: { id: 99, title: "Project B post, should not be received" },
|
|
162
162
|
old: null,
|
|
163
163
|
},
|
|
164
164
|
timestamp: "2024-01-01T00:00:02Z",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Integration test
|
|
2
|
+
* Integration test: Task 90: SDK retry behaviour
|
|
3
3
|
*
|
|
4
4
|
* Simulates 503 -> SDK retries 3x with backoff -> succeeds or throws after max retries.
|
|
5
5
|
*/
|
|
@@ -22,7 +22,7 @@ function mockResponse(status: number, body: unknown = {}): Response {
|
|
|
22
22
|
|
|
23
23
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
24
24
|
|
|
25
|
-
describe("Task 90
|
|
25
|
+
describe("Task 90: SDK retry integration", () => {
|
|
26
26
|
beforeEach(() => {
|
|
27
27
|
vi.restoreAllMocks()
|
|
28
28
|
vi.useFakeTimers()
|
|
@@ -159,7 +159,7 @@ describe("Task 90 — SDK retry integration", () => {
|
|
|
159
159
|
vi.useFakeTimers()
|
|
160
160
|
})
|
|
161
161
|
|
|
162
|
-
it("respects retry: false option
|
|
162
|
+
it("respects retry: false option, no retries attempted", async () => {
|
|
163
163
|
const fetchSpy = vi.fn().mockResolvedValue(mockResponse(503))
|
|
164
164
|
vi.stubGlobal("fetch", fetchSpy)
|
|
165
165
|
|
package/tests/serverless.test.ts
CHANGED
|
@@ -81,7 +81,7 @@ describe("warnIfServerlessDirectConnection", () => {
|
|
|
81
81
|
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
|
|
82
82
|
// Reset the one-time guard between tests by re-importing.
|
|
83
83
|
// Since the guard is module-level state, we need to reset it.
|
|
84
|
-
// We do this by directly resetting via a dynamic import trick
|
|
84
|
+
// We do this by directly resetting via a dynamic import trick, but
|
|
85
85
|
// the simplest approach is to just accept the guard fires once per
|
|
86
86
|
// describe block. Instead, let's reset it manually.
|
|
87
87
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Integration test
|
|
2
|
+
* Integration test: Task 93: Storage quota exceeded
|
|
3
3
|
*
|
|
4
4
|
* Tests: quota exceeded -> 507 with clear message.
|
|
5
5
|
*/
|
|
@@ -35,7 +35,7 @@ function mockFetchResponse(
|
|
|
35
35
|
|
|
36
36
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
37
37
|
|
|
38
|
-
describe("Task 93
|
|
38
|
+
describe("Task 93: Storage quota integration", () => {
|
|
39
39
|
beforeEach(() => vi.restoreAllMocks())
|
|
40
40
|
|
|
41
41
|
describe("Quota exceeded on upload", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Integration test
|
|
2
|
+
* Integration test: Task 92: File upload size limit
|
|
3
3
|
*
|
|
4
4
|
* Tests: upload exceeding limit -> 413 with clear message.
|
|
5
5
|
*/
|
|
@@ -36,7 +36,7 @@ function mockFetchResponse(
|
|
|
36
36
|
|
|
37
37
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
38
38
|
|
|
39
|
-
describe("Task 92
|
|
39
|
+
describe("Task 92: File upload size limit integration", () => {
|
|
40
40
|
beforeEach(() => vi.restoreAllMocks())
|
|
41
41
|
|
|
42
42
|
describe("Upload within size limit", () => {
|
|
@@ -56,7 +56,7 @@ describe("Task 92 — File upload size limit integration", () => {
|
|
|
56
56
|
vi.stubGlobal("fetch", mockFetchResponse(200, { Key: "docs/file.pdf" }))
|
|
57
57
|
|
|
58
58
|
const client = freshClient()
|
|
59
|
-
const blob = createMockBlob(50 * 1024 * 1024) // 50 MB
|
|
59
|
+
const blob = createMockBlob(50 * 1024 * 1024) // 50 MB, right at limit
|
|
60
60
|
const { data, error } = await client.from("docs").upload("file.pdf", blob, {
|
|
61
61
|
contentType: "application/pdf",
|
|
62
62
|
})
|
|
@@ -176,7 +176,7 @@ describe("Task 92 — File upload size limit integration", () => {
|
|
|
176
176
|
|
|
177
177
|
const client = freshClient()
|
|
178
178
|
|
|
179
|
-
// StorageClient.upload does not wrap fetch errors
|
|
179
|
+
// StorageClient.upload does not wrap fetch errors, they propagate
|
|
180
180
|
await expect(
|
|
181
181
|
client.from("bucket").upload("file.txt", createMockBlob(100)),
|
|
182
182
|
).rejects.toThrow("Network error")
|
package/tests/types.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type inference tests
|
|
2
|
+
* Type inference tests: verify that TypeScript generics produce the correct
|
|
3
3
|
* types throughout the client API. These assertions are checked at compile
|
|
4
4
|
* time by tsc and at runtime via vitest's expectTypeOf.
|
|
5
5
|
*/
|
|
@@ -103,7 +103,7 @@ describe("QueryBuilder chaining preserves type", () => {
|
|
|
103
103
|
})
|
|
104
104
|
|
|
105
105
|
it(".single() resolves to QueryResult<Row>", async () => {
|
|
106
|
-
// Just type checking
|
|
106
|
+
// Just type checking: no network call
|
|
107
107
|
const q = client.from("posts").select().single()
|
|
108
108
|
expectTypeOf(q).resolves.toMatchTypeOf<QueryResult<Post>>()
|
|
109
109
|
})
|