@supatype/client 0.3.6 → 0.7.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +58 -31
- package/.turbo/turbo-typecheck.log +2 -2
- package/LICENSE +1 -1
- package/dist/auth-redirect.d.ts +48 -0
- package/dist/auth-redirect.d.ts.map +1 -0
- package/dist/auth-redirect.js +70 -0
- package/dist/auth-redirect.js.map +1 -0
- package/dist/auth.d.ts +78 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +373 -274
- package/dist/auth.js.map +1 -1
- package/dist/bindings.d.ts +16 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +13 -0
- package/dist/bindings.js.map +1 -0
- package/dist/caller-types.d.ts +18 -0
- package/dist/caller-types.d.ts.map +1 -0
- package/dist/caller-types.js +22 -0
- package/dist/caller-types.js.map +1 -0
- package/dist/draft-create.d.ts +12 -0
- package/dist/draft-create.d.ts.map +1 -0
- package/dist/draft-create.js +47 -0
- package/dist/draft-create.js.map +1 -0
- package/dist/draft-models-registry.d.ts +27 -0
- package/dist/draft-models-registry.d.ts.map +1 -0
- package/dist/draft-models-registry.js +61 -0
- package/dist/draft-models-registry.js.map +1 -0
- package/dist/error-codes-doc.d.ts +1 -1
- package/dist/error-codes-doc.d.ts.map +1 -1
- package/dist/error-codes-doc.js +42 -34
- package/dist/error-codes-doc.js.map +1 -1
- package/dist/errors.d.ts +102 -60
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +69 -28
- package/dist/errors.js.map +1 -1
- package/dist/exact-response.d.ts.map +1 -1
- package/dist/exact-response.js +2 -1
- package/dist/exact-response.js.map +1 -1
- package/dist/exact-values.d.ts +2 -0
- package/dist/exact-values.d.ts.map +1 -1
- package/dist/exact-values.js +12 -10
- package/dist/exact-values.js.map +1 -1
- package/dist/fetch-with-retry.d.ts +21 -6
- package/dist/fetch-with-retry.d.ts.map +1 -1
- package/dist/fetch-with-retry.js +67 -53
- package/dist/fetch-with-retry.js.map +1 -1
- package/dist/field-kinds-registry.d.ts +11 -3
- package/dist/field-kinds-registry.d.ts.map +1 -1
- package/dist/field-kinds-registry.js +10 -6
- package/dist/field-kinds-registry.js.map +1 -1
- package/dist/filters.d.ts +51 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +117 -0
- package/dist/filters.js.map +1 -0
- package/dist/generated-client.d.ts +7 -0
- package/dist/generated-client.d.ts.map +1 -0
- package/dist/generated-client.js +7 -0
- package/dist/generated-client.js.map +1 -0
- package/dist/graphql-document.d.ts +39 -0
- package/dist/graphql-document.d.ts.map +1 -0
- package/dist/graphql-document.js +228 -0
- package/dist/graphql-document.js.map +1 -0
- package/dist/graphql-json.d.ts +56 -0
- package/dist/graphql-json.d.ts.map +1 -0
- package/dist/graphql-json.js +220 -0
- package/dist/graphql-json.js.map +1 -0
- package/dist/graphql-transport.d.ts +28 -0
- package/dist/graphql-transport.d.ts.map +1 -0
- package/dist/graphql-transport.js +77 -0
- package/dist/graphql-transport.js.map +1 -0
- package/dist/index.d.ts +103 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -157
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +61 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +83 -0
- package/dist/json.js.map +1 -0
- package/dist/jwt.d.ts +16 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +37 -0
- package/dist/jwt.js.map +1 -0
- package/dist/live-preview.d.ts +23 -0
- package/dist/live-preview.d.ts.map +1 -0
- package/dist/live-preview.js +28 -0
- package/dist/live-preview.js.map +1 -0
- package/dist/mutation-request.d.ts +17 -0
- package/dist/mutation-request.d.ts.map +1 -0
- package/dist/mutation-request.js +41 -0
- package/dist/mutation-request.js.map +1 -0
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +8 -6
- package/dist/preview.js.map +1 -1
- package/dist/query-cache.d.ts.map +1 -1
- package/dist/query-cache.js +19 -13
- package/dist/query-cache.js.map +1 -1
- package/dist/query.d.ts +108 -29
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +294 -224
- package/dist/query.js.map +1 -1
- package/dist/realtime.d.ts +20 -2
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +105 -12
- package/dist/realtime.js.map +1 -1
- package/dist/select-types.d.ts +99 -0
- package/dist/select-types.d.ts.map +1 -0
- package/dist/select-types.js +2 -0
- package/dist/select-types.js.map +1 -0
- package/dist/storage.d.ts +81 -11
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +129 -37
- package/dist/storage.js.map +1 -1
- package/dist/table-subscription.d.ts +69 -0
- package/dist/table-subscription.d.ts.map +1 -0
- package/dist/table-subscription.js +93 -0
- package/dist/table-subscription.js.map +1 -0
- package/dist/types.d.ts +84 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/package.json +6 -2
- package/src/auth-redirect.ts +90 -0
- package/src/auth.ts +421 -280
- package/src/bindings.ts +22 -0
- package/src/caller-types.ts +27 -0
- package/src/draft-create.ts +51 -0
- package/src/draft-models-registry.ts +81 -0
- package/src/error-codes-doc.ts +44 -35
- package/src/errors.ts +72 -28
- package/src/exact-response.ts +2 -1
- package/src/exact-values.ts +16 -9
- package/src/fetch-with-retry.ts +80 -70
- package/src/field-kinds-registry.ts +22 -9
- package/src/filters.ts +133 -0
- package/src/generated-client.ts +6 -0
- package/src/graphql-document.ts +234 -0
- package/src/graphql-json.ts +243 -0
- package/src/graphql-transport.ts +97 -0
- package/src/index.ts +272 -201
- package/src/json.ts +117 -0
- package/src/jwt.ts +37 -0
- package/src/live-preview.ts +37 -0
- package/src/mutation-request.ts +66 -0
- package/src/preview.ts +9 -11
- package/src/query-cache.ts +19 -16
- package/src/query.ts +389 -270
- package/src/realtime.ts +116 -13
- package/src/select-types.ts +184 -0
- package/src/storage.ts +214 -43
- package/src/table-subscription.ts +160 -0
- package/src/types.ts +90 -5
- package/tests/auth-error-codes.test.ts +53 -0
- package/tests/auth-errors.test.ts +84 -0
- package/tests/auth-events.test.ts +136 -0
- package/tests/auth-url-session.test.ts +204 -0
- package/tests/auth.test.ts +122 -26
- package/tests/count.test.ts +60 -0
- package/tests/data-plane-auth.test.ts +21 -46
- package/tests/draft-insert.integration.test.ts +118 -0
- package/tests/draft-insert.test.ts +225 -0
- package/tests/draft-profile.test.ts +55 -84
- package/tests/draft-update.integration.test.ts +122 -0
- package/tests/draft-update.test.ts +174 -0
- package/tests/dynamic-headers.test.ts +45 -0
- package/tests/entry-points.test.ts +42 -0
- package/tests/exact-response.test.ts +4 -4
- package/tests/exact-values.test.ts +14 -25
- package/tests/field-kinds-registry.test.ts +3 -3
- package/tests/filters.test.ts +146 -0
- package/tests/graphql-json.test.ts +199 -0
- package/tests/helpers/mock-websocket.ts +44 -11
- package/tests/helpers/oauth-binding.ts +92 -0
- package/tests/helpers/signup-binding.ts +73 -0
- package/tests/helpers/socket-swap.ts +139 -0
- package/tests/mfa-totp-integration.test.ts +13 -20
- package/tests/postgrest-error-codes.test.ts +85 -0
- package/tests/query-cache.test.ts +116 -117
- package/tests/query.test.ts +29 -31
- package/tests/rate-limit-integration.test.ts +4 -12
- package/tests/realtime-exact-values.test.ts +2 -4
- package/tests/realtime-presence.test.ts +75 -0
- package/tests/realtime-session-auth.test.ts +2 -4
- package/tests/realtime-swap-status.test.ts +62 -0
- package/tests/retry-integration.test.ts +3 -8
- package/tests/retry-policy.test.ts +166 -0
- package/tests/rpc-resend.test.ts +24 -0
- package/tests/server-bodies.test.ts +139 -0
- package/tests/serverless.test.ts +2 -2
- package/tests/signed-url-absolute.test.ts +2 -5
- package/tests/storage-object-shape.test.ts +101 -0
- package/tests/storage-quota-integration.test.ts +3 -2
- package/tests/storage-reference-url.test.ts +51 -0
- package/tests/storage-upload-browser.test.ts +71 -0
- package/tests/storage-upload-limit-integration.test.ts +12 -22
- package/tests/subscribe-frame.test.ts +5 -11
- package/tests/support/fetch-mock.ts +64 -0
- package/tests/support/storage-object.ts +37 -0
- package/tests/table-subscribe.test.ts +13 -13
- package/tests/table-subscription.test.ts +105 -0
- package/tests/table-transport.test.ts +94 -0
- package/tests/tsconfig.json +1 -1
- package/tests/types.test.ts +153 -1
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TableRelationship } from "./select-types.js";
|
|
1
2
|
export interface UserIdentity {
|
|
2
3
|
id: string;
|
|
3
4
|
userId: string;
|
|
@@ -106,6 +107,27 @@ export interface SupatypeError {
|
|
|
106
107
|
* you.
|
|
107
108
|
*/
|
|
108
109
|
field?: string | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* What the server suggests doing instead, when it said. PostgREST passes a Postgres `HINT`
|
|
112
|
+
* through, and the gateway adds one to an insert into a drafts model that is refused for asking
|
|
113
|
+
* for its row back, naming `supatype.create_record` and `supatype.create_records`.
|
|
114
|
+
*/
|
|
115
|
+
hint?: string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* The detail line Postgres attached, when it gave one. A unique violation names its columns and
|
|
118
|
+
* values here (`Key (slug)=(intro) already exists.`), which is how a caller learns which of the
|
|
119
|
+
* values it sent collided without parsing the message.
|
|
120
|
+
*/
|
|
121
|
+
details?: string | undefined;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A sign-in the auth server refused and reported back in the redirect URL.
|
|
125
|
+
*
|
|
126
|
+
* `provider` names the OAuth provider this browser started the sign-in with, when the client
|
|
127
|
+
* remembers one, so an app showing one button per provider can put the message by the right one.
|
|
128
|
+
*/
|
|
129
|
+
export interface AuthRedirectError extends SupatypeError {
|
|
130
|
+
provider?: string | undefined;
|
|
109
131
|
}
|
|
110
132
|
/**
|
|
111
133
|
* A column in the response that carries a read restriction.
|
|
@@ -154,6 +176,14 @@ export interface RpcOptions {
|
|
|
154
176
|
count?: "exact" | "planned" | "estimated" | undefined;
|
|
155
177
|
/** Postgres schema holding the function, sent as `Content-Profile`. */
|
|
156
178
|
schema?: string | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Retry this call on a transient failure (a dropped connection, a 5xx, a 429). Default: false.
|
|
181
|
+
*
|
|
182
|
+
* An RPC is a POST, and the client cannot tell a read from a write: a call that failed in flight
|
|
183
|
+
* may already have run, and running it again could apply its writes twice. Set this for a
|
|
184
|
+
* function that only reads, or whose writes are safe to repeat. A `head` call is always retried.
|
|
185
|
+
*/
|
|
186
|
+
idempotent?: boolean | undefined;
|
|
157
187
|
}
|
|
158
188
|
export interface RpcResult<TData> {
|
|
159
189
|
data: TData | null;
|
|
@@ -167,7 +197,34 @@ export interface TableDef {
|
|
|
167
197
|
*/
|
|
168
198
|
Insert: Record<string, unknown>;
|
|
169
199
|
Update: Record<string, unknown>;
|
|
200
|
+
/**
|
|
201
|
+
* The foreign keys this table holds, which an embedded select is resolved through. Generated for
|
|
202
|
+
* every table; a hand-written definition without them can still select its own columns.
|
|
203
|
+
*/
|
|
204
|
+
Relationships?: readonly TableRelationship[] | undefined;
|
|
205
|
+
/**
|
|
206
|
+
* `true` on a model that keeps drafts, where `update` saves a new draft of each record and
|
|
207
|
+
* `{ publish: true }` publishes it in the same call. Generated; absent on every other table. A
|
|
208
|
+
* hand-written definition that leaves it unsaid is offered the option, and the client refuses it
|
|
209
|
+
* at run time on a table it does not know keeps drafts.
|
|
210
|
+
*/
|
|
211
|
+
Drafts?: boolean | undefined;
|
|
170
212
|
}
|
|
213
|
+
/** What `update` takes beyond the changes, on a model that keeps drafts. */
|
|
214
|
+
export interface DraftUpdateOptions {
|
|
215
|
+
/**
|
|
216
|
+
* Publish each new draft in the same call, so the live rows change and the history records the
|
|
217
|
+
* version that went live. Without it the live rows stay as they are until a version is published.
|
|
218
|
+
*/
|
|
219
|
+
publish?: boolean | undefined;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The options `update` takes on `TDef`: {@link DraftUpdateOptions} on a model that keeps drafts, or
|
|
223
|
+
* one whose definition does not say; nothing on a generated table that keeps none.
|
|
224
|
+
*/
|
|
225
|
+
export type UpdateOptions<TDef extends TableDef> = TDef extends {
|
|
226
|
+
Drafts: true;
|
|
227
|
+
} ? DraftUpdateOptions : "Drafts" extends keyof TDef ? (TDef["Drafts"] extends false | undefined ? never : DraftUpdateOptions) : never;
|
|
171
228
|
/**
|
|
172
229
|
* Module augmentation anchors used by generated `supatype` types output.
|
|
173
230
|
*
|
|
@@ -264,6 +321,12 @@ export interface AuthStorage {
|
|
|
264
321
|
* Changing it means changing all three, the same as `api` for the field-masking views.
|
|
265
322
|
*/
|
|
266
323
|
export declare const DRAFT_SCHEMA = "draft";
|
|
324
|
+
/**
|
|
325
|
+
* The schema holding the generated publishing functions: `create_record`, `create_draft`, `publish`
|
|
326
|
+
* and the rest. PostgREST resolves `/rpc/<name>` against the default profile, so every call to one
|
|
327
|
+
* names this schema with `Content-Profile`.
|
|
328
|
+
*/
|
|
329
|
+
export declare const PUBLISHING_SCHEMA = "supatype";
|
|
267
330
|
export interface SelectQueryOptions {
|
|
268
331
|
count?: "exact" | "planned" | "estimated" | undefined;
|
|
269
332
|
head?: boolean | undefined;
|
|
@@ -303,15 +366,30 @@ export interface SupatypeClientConfig {
|
|
|
303
366
|
* React Native: pass an AsyncStorage or expo-secure-store adapter.
|
|
304
367
|
*/
|
|
305
368
|
storage?: AuthStorage | undefined;
|
|
369
|
+
/**
|
|
370
|
+
* Finish a sign-in the auth server has just redirected back with (OAuth, magic link, recovery
|
|
371
|
+
* link): tokens in the URL fragment or a PKCE `code` in the query become the session, `SIGNED_IN`
|
|
372
|
+
* is emitted, and the parameters are removed from the address bar. Browser only. Default: true,
|
|
373
|
+
* as supabase-js's option of the same name. `auth.initialize()` reports a refusal in the URL.
|
|
374
|
+
*/
|
|
375
|
+
detectSessionInUrl?: boolean | undefined;
|
|
306
376
|
} | undefined;
|
|
307
377
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
378
|
+
* Retry a transient failure (a dropped connection, a 5xx, a 429). Default: true.
|
|
379
|
+
*
|
|
380
|
+
* Only reads are retried: GET and HEAD requests (table selects, storage downloads, `getUser`), and
|
|
381
|
+
* the few reads sent as POST (storage `list`, signed URLs). Every other request is sent once,
|
|
382
|
+
* whatever this says: a write that failed in flight may still have been applied, and sending it
|
|
383
|
+
* again could apply it twice. `rpc`, `graphql` and `functions.invoke` take `idempotent: true` per
|
|
384
|
+
* call to opt in.
|
|
310
385
|
*/
|
|
311
386
|
retry?: boolean | undefined;
|
|
312
387
|
/**
|
|
313
388
|
* Request timeout in milliseconds. Default: 30000 (30 seconds).
|
|
314
|
-
*
|
|
389
|
+
*
|
|
390
|
+
* Applies to every HTTP request the client makes: tables, `rpc`, `graphql`, `functions`, auth and
|
|
391
|
+
* storage, uploads included, so raise it for large uploads on slow links. The realtime socket is
|
|
392
|
+
* not an HTTP request and is not covered.
|
|
315
393
|
*/
|
|
316
394
|
timeout?: number | undefined;
|
|
317
395
|
/**
|
|
@@ -342,9 +420,10 @@ export interface SupatypeClientConfig {
|
|
|
342
420
|
*/
|
|
343
421
|
previewCode?: string | undefined;
|
|
344
422
|
/**
|
|
345
|
-
* Extra headers merged into every request (e.g. Studio `X-Supatype-Environment`).
|
|
423
|
+
* Extra headers merged into every request (e.g. Studio `X-Supatype-Environment`). A function is
|
|
424
|
+
* read on every request, for a header that changes for the life of the client.
|
|
346
425
|
*/
|
|
347
|
-
headers?: Record<string, string> | undefined;
|
|
426
|
+
headers?: Record<string, string> | (() => Record<string, string>) | undefined;
|
|
348
427
|
}
|
|
349
428
|
export {};
|
|
350
429
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts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;;;;;WAKG;QACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KACzC,GAAG,SAAS,CAAA;IACb;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,kBAAkB,EAAE,UAAU,GAAG,SAAS,CAAA;IAC9D;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;CAC9E"}
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// ─── Auth types ───────────────────────────────────────────────────────────────
|
|
2
1
|
/**
|
|
3
2
|
* The schema holding one draft view per versioned model, selected by `Accept-Profile`.
|
|
4
3
|
*
|
|
@@ -8,4 +7,10 @@
|
|
|
8
7
|
* Changing it means changing all three, the same as `api` for the field-masking views.
|
|
9
8
|
*/
|
|
10
9
|
export const DRAFT_SCHEMA = "draft";
|
|
10
|
+
/**
|
|
11
|
+
* The schema holding the generated publishing functions: `create_record`, `create_draft`, `publish`
|
|
12
|
+
* and the rest. PostgREST resolves `/rpc/<name>` against the default profile, so every call to one
|
|
13
|
+
* names this schema with `Content-Profile`.
|
|
14
|
+
*/
|
|
15
|
+
export const PUBLISHING_SCHEMA = "supatype";
|
|
11
16
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAiYA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supatype/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Supatype client SDK: typed REST, auth, storage, realtime",
|
|
6
6
|
"type": "module",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./bindings": {
|
|
15
|
+
"types": "./dist/bindings.d.ts",
|
|
16
|
+
"import": "./dist/bindings.js"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
"devDependencies": {
|
|
@@ -23,7 +27,7 @@
|
|
|
23
27
|
"scripts": {
|
|
24
28
|
"build": "tsc --project tsconfig.json",
|
|
25
29
|
"dev": "tsc --project tsconfig.json --watch",
|
|
26
|
-
"typecheck": "tsc --project
|
|
30
|
+
"typecheck": "tsc --project tests/tsconfig.json --noEmit",
|
|
27
31
|
"test": "vitest run",
|
|
28
32
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
29
33
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the auth server's redirect back to the app.
|
|
3
|
+
*
|
|
4
|
+
* The server returns a browser with the outcome in the URL: implicit-grant tokens in the fragment
|
|
5
|
+
* (`#access_token=...&refresh_token=...`), a PKCE `code` in the query, or a refusal as `error`,
|
|
6
|
+
* `error_code` and `error_description` in both. These helpers follow supabase-js: a URL is an auth
|
|
7
|
+
* redirect when it carries `access_token` or `error_description`, or a `code` this client is
|
|
8
|
+
* waiting for, and once read it loses those parameters so a reload or a shared link does not replay
|
|
9
|
+
* them.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { SupatypeError } from "./types.js"
|
|
13
|
+
|
|
14
|
+
/** Query parameters the server adds to the redirect; anything else is the app's own and is kept. */
|
|
15
|
+
const QUERY_KEYS = ["code", "error", "error_code", "error_description", "sb"] as const
|
|
16
|
+
|
|
17
|
+
/** Fragment parameters that mark the fragment as the server's rather than the app's (a hash route). */
|
|
18
|
+
const FRAGMENT_KEYS = ["access_token", "refresh_token", "error", "error_description", "sb"] as const
|
|
19
|
+
|
|
20
|
+
export interface RedirectParams {
|
|
21
|
+
query: URLSearchParams
|
|
22
|
+
fragment: URLSearchParams
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The redirect's query and fragment parameters, or null when `href` is not a URL. */
|
|
26
|
+
export function redirectParams(href: string): RedirectParams | null {
|
|
27
|
+
let url: URL
|
|
28
|
+
try {
|
|
29
|
+
url = new URL(href)
|
|
30
|
+
} catch {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
const hash = url.hash.startsWith("#") ? url.hash.slice(1) : url.hash
|
|
34
|
+
return { query: url.searchParams, fragment: new URLSearchParams(hash) }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A parameter from the fragment or the query, as the server may put it in either. */
|
|
38
|
+
export function redirectParam(params: RedirectParams, key: string): string | null {
|
|
39
|
+
const value = params.fragment.get(key) ?? params.query.get(key)
|
|
40
|
+
return value === null || value === "" ? null : value
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** True when the URL carries implicit-grant tokens or the server's refusal. */
|
|
44
|
+
export function carriesImplicitResult(params: RedirectParams): boolean {
|
|
45
|
+
return redirectParam(params, "access_token") !== null || redirectParam(params, "error_description") !== null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `href` without the parameters the server added, ready for `history.replaceState`. */
|
|
49
|
+
export function withoutAuthParams(href: string): string {
|
|
50
|
+
const url = new URL(href)
|
|
51
|
+
for (const key of QUERY_KEYS) url.searchParams.delete(key)
|
|
52
|
+
const fragment = new URLSearchParams(url.hash.slice(1))
|
|
53
|
+
if (FRAGMENT_KEYS.some((key) => fragment.has(key))) url.hash = ""
|
|
54
|
+
return url.toString()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The page's URL when running in a browser, else null (a server, a worker, React Native). */
|
|
58
|
+
export function browserHref(): string | null {
|
|
59
|
+
if (typeof window === "undefined") return null
|
|
60
|
+
const href: unknown = window.location?.href
|
|
61
|
+
return typeof href === "string" ? href : null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Take the auth parameters out of the address bar without a navigation. */
|
|
65
|
+
export function cleanBrowserUrl(href: string): void {
|
|
66
|
+
if (typeof window === "undefined" || typeof window.history?.replaceState !== "function") return
|
|
67
|
+
window.history.replaceState(window.history.state, "", withoutAuthParams(href))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The part of `AuthClient` a binding starts an OAuth sign-in through. */
|
|
71
|
+
interface OAuthStarter {
|
|
72
|
+
signInWithOAuth(opts: { provider: string }): Promise<{
|
|
73
|
+
data: { url: string }
|
|
74
|
+
error: SupatypeError | null
|
|
75
|
+
}>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Start an OAuth sign-in for a framework binding: ask the client for the provider's URL and send
|
|
80
|
+
* the browser there, as supabase-js's `signInWithOAuth` does. A refusal (a provider the project has
|
|
81
|
+
* not enabled) is returned and the page stays put.
|
|
82
|
+
*/
|
|
83
|
+
export async function startOAuthRedirect(
|
|
84
|
+
auth: OAuthStarter,
|
|
85
|
+
provider: string,
|
|
86
|
+
): Promise<{ error: SupatypeError | null }> {
|
|
87
|
+
const { data, error } = await auth.signInWithOAuth({ provider })
|
|
88
|
+
if (error === null && data.url !== "" && typeof window !== "undefined") window.location.assign(data.url)
|
|
89
|
+
return { error }
|
|
90
|
+
}
|