@rebasepro/client 0.28.2 → 0.29.0-canary.g0e3a0e7
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/index.es.js +46 -7
- package/dist/index.es.js.map +1 -1
- package/package.json +4 -4
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as invalidBulkBody, d as RebaseApiError, h as parseRebaseJson, i as isOfflineError, l as SDKQueryBuilder, m as defaultCodeForStatus, n as MemoryOfflineStore, o as createCollectionClient, p as createTransport, s as etagOf, u as RebaseClientError } from "./offline-store-Cxhh99Q-.js";
|
|
2
|
-
import { DEFAULT_STORAGE_SOURCE_KEY, PUBLIC_STORAGE_PREFIX, RebaseApiError as RebaseApiError$1, RebaseClientError as RebaseClientError$1, STORAGE_REFERENCE_SCHEME, isPublicStoragePath, isStorageReference, isUnsupported, parseStorageReference, resolveStorageReferences, simulationHeaders, storageObjectPath, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText } from "@rebasepro/types";
|
|
2
|
+
import { AUTH_FLOW_HEADER, DEFAULT_STORAGE_SOURCE_KEY, PUBLIC_STORAGE_PREFIX, RebaseApiError as RebaseApiError$1, RebaseClientError as RebaseClientError$1, STORAGE_REFERENCE_SCHEME, isPublicStoragePath, isStorageReference, isUnsupported, parseStorageReference, resolveStorageReferences, simulationHeaders, storageObjectPath, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText } from "@rebasepro/types";
|
|
3
3
|
import { COMPOSITE_ID_SEPARATOR, DOWNLOAD_URL_CONCURRENCY, RESUMABLE_UPLOAD_THRESHOLD, RebasePaginationError, and, buildCompositeId, cond, createBatchLoader, createConcurrencyLimit, createDownloadUrlCache, not, or, warnDeprecated, withETag } from "@rebasepro/common";
|
|
4
4
|
import { toSnakeCase, unref } from "@rebasepro/utils";
|
|
5
5
|
//#region src/apple-sign-in.ts
|
|
@@ -188,6 +188,8 @@ function createAuth(transport, options) {
|
|
|
188
188
|
const autoRefresh = opts.autoRefresh !== false;
|
|
189
189
|
const persistSession = opts.persistSession !== false;
|
|
190
190
|
const authFlowMode = resolveAuthFlowMode(opts);
|
|
191
|
+
/** Whether the app passed the storage this client keeps its session in. */
|
|
192
|
+
const ownStorage = opts.storage !== void 0;
|
|
191
193
|
const STORAGE_KEY = "rebase_auth";
|
|
192
194
|
const REFRESH_BUFFER_MS = 12e4;
|
|
193
195
|
/**
|
|
@@ -229,8 +231,39 @@ function createAuth(transport, options) {
|
|
|
229
231
|
function authUrl(endpoint) {
|
|
230
232
|
return transport.baseUrl + transport.apiPath + authPath + endpoint;
|
|
231
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* What a json-mode client says on every auth request — through
|
|
236
|
+
* {@link getFetch}, and on the session upgrades sent through the
|
|
237
|
+
* transport: {@link AUTH_FLOW_HEADER}. A server with `cookieAuth` then
|
|
238
|
+
* hands it the refresh token in the body and reads the one it presents
|
|
239
|
+
* from there, as a server without `cookieAuth` does, so it can renew. Told
|
|
240
|
+
* nothing, that server answers `refreshToken: ""` and keeps the token in a
|
|
241
|
+
* cookie this client never sends — a Node or React Native client, or a
|
|
242
|
+
* second client in a browser that keeps its own sign-in apart from the
|
|
243
|
+
* page's cookie session — and the session ends with its first access
|
|
244
|
+
* token.
|
|
245
|
+
*/
|
|
246
|
+
const flowHeaders = authFlowMode === "json" ? { [AUTH_FLOW_HEADER]: "json" } : {};
|
|
247
|
+
function withFlowHeaders(headers) {
|
|
248
|
+
if (typeof Headers !== "undefined" && headers instanceof Headers) {
|
|
249
|
+
const merged = new Headers(headers);
|
|
250
|
+
merged.set(AUTH_FLOW_HEADER, "json");
|
|
251
|
+
return merged;
|
|
252
|
+
}
|
|
253
|
+
if (Array.isArray(headers)) return [...headers, [AUTH_FLOW_HEADER, "json"]];
|
|
254
|
+
return {
|
|
255
|
+
...flowHeaders,
|
|
256
|
+
...headers
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/** `fetch` for the auth routes: the transport's, carrying {@link flowHeaders}. */
|
|
232
260
|
function getFetch() {
|
|
233
|
-
|
|
261
|
+
const fetchFn = transport.fetchFn || globalThis.fetch;
|
|
262
|
+
if (authFlowMode !== "json") return fetchFn;
|
|
263
|
+
return (input, init) => fetchFn(input, {
|
|
264
|
+
...init,
|
|
265
|
+
headers: withFlowHeaders(init?.headers)
|
|
266
|
+
});
|
|
234
267
|
}
|
|
235
268
|
/**
|
|
236
269
|
* The body of a request that presents the refresh token — `/refresh` and
|
|
@@ -265,18 +298,21 @@ function createAuth(transport, options) {
|
|
|
265
298
|
* cannot renew the session it is starting.
|
|
266
299
|
*
|
|
267
300
|
* A server with `cookieAuth` answers `refreshToken: ""` and puts the token
|
|
268
|
-
* in the cookie; one without it puts the token in the body. A client
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
301
|
+
* in the cookie; one without it puts the token in the body. A json client
|
|
302
|
+
* says so with {@link AUTH_FLOW_HEADER}, and a server that honours it puts
|
|
303
|
+
* its token in the body either way. A client in the other mode holds
|
|
304
|
+
* nothing it can renew with, and finds out when the access token expires —
|
|
305
|
+
* in json mode by dropping the session without a word. The answer to the
|
|
306
|
+
* sign-in is the first moment it is known.
|
|
272
307
|
*/
|
|
273
308
|
function reportFlowMismatch(received, expiresAt) {
|
|
274
309
|
if (flowMismatchReported || received === void 0) return;
|
|
275
310
|
const serverUsesCookie = received === "";
|
|
276
311
|
if (serverUsesCookie === (authFlowMode === "cookie")) return;
|
|
312
|
+
if (serverUsesCookie && ownStorage) return;
|
|
277
313
|
flowMismatchReported = true;
|
|
278
314
|
const ends = Number.isFinite(expiresAt) ? `in about ${Math.max(1, Math.round((expiresAt - Date.now()) / 6e4))} minutes` : "when its access token expires";
|
|
279
|
-
console.error(serverUsesCookie ? `[rebase] This server keeps the refresh token in an HttpOnly cookie (its \`auth.cookieAuth\`), but this client is in json mode and was handed none, so the session it just started cannot be renewed and ends ${ends}.
|
|
315
|
+
console.error(serverUsesCookie ? `[rebase] This server keeps the refresh token in an HttpOnly cookie (its \`auth.cookieAuth\`), but this client is in json mode and was handed none, so the session it just started cannot be renewed and ends ${ends}. The server is older than the release that hands a json client its refresh token: update it, or, in a browser, create the client with \`auth: { authFlowMode: "cookie" }\`.` : `[rebase] This server returned the refresh token in the response body, so it does not use \`auth.cookieAuth\`, and this client, in cookie mode, cannot renew the session it just started: it ends ${ends}. Turn on \`auth.cookieAuth\` on the server, or create the client with \`auth: { authFlowMode: "json" }\`.`);
|
|
280
316
|
}
|
|
281
317
|
/**
|
|
282
318
|
* Whether the server refused a refresh as malformed: a 400, which says the
|
|
@@ -1030,6 +1066,7 @@ function createAuth(transport, options) {
|
|
|
1030
1066
|
const result = await transport.request(authPath + "/link/" + providerId, {
|
|
1031
1067
|
method: "POST",
|
|
1032
1068
|
body: JSON.stringify(payload),
|
|
1069
|
+
headers: flowHeaders,
|
|
1033
1070
|
credentials: authFlowMode === "cookie" ? "include" : void 0
|
|
1034
1071
|
});
|
|
1035
1072
|
if (result.tokens && result.user) handleAuthResponse({
|
|
@@ -1262,6 +1299,7 @@ function createAuth(transport, options) {
|
|
|
1262
1299
|
email,
|
|
1263
1300
|
password
|
|
1264
1301
|
}),
|
|
1302
|
+
headers: flowHeaders,
|
|
1265
1303
|
credentials: authFlowMode === "cookie" ? "include" : void 0
|
|
1266
1304
|
}), "USER_UPDATED");
|
|
1267
1305
|
return {
|
|
@@ -1365,6 +1403,7 @@ function createAuth(transport, options) {
|
|
|
1365
1403
|
const session = handleAuthResponse(options?.mfaToken ? await withPendingToken("/mfa/challenge/verify", payload, options.mfaToken) : await transport.request(authPath + "/mfa/challenge/verify", {
|
|
1366
1404
|
method: "POST",
|
|
1367
1405
|
body: payload,
|
|
1406
|
+
headers: flowHeaders,
|
|
1368
1407
|
credentials: authFlowMode === "cookie" ? "include" : void 0
|
|
1369
1408
|
}), "SIGNED_IN");
|
|
1370
1409
|
return {
|