@vrtmrz/livesync-commonlib 0.1.8 → 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.
@@ -46,8 +46,10 @@ export type FetchChangesForInitialSyncProgress = {
46
46
  * Fetches initial data from CouchDB as a stream and writes it into PouchDB.
47
47
  * @param downloadToDB PouchDB instance.
48
48
  * @param remoteDbUrl CouchDB database URL (for example: 'https://xxx.com/mydb').
49
+ * @param authHeader Value of the `Authorization` header for CouchDB.
49
50
  * @param decryptFunction Function to decrypt each document.
50
51
  * @param since Sequence ID to start fetching changes from (default is '0').
52
+ * @param customHeaders Additional request headers required by the CouchDB endpoint or its reverse proxy.
51
53
  */
52
- export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<AnyEntry | EntryLeaf>, since?: number | string, onProgress?: (progress: FetchChangesForInitialSyncProgress) => void, onCheckpoint?: (sequence: DBSequence) => void | Promise<void>): Promise<void>;
54
+ export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<AnyEntry | EntryLeaf>, since?: number | string, onProgress?: (progress: FetchChangesForInitialSyncProgress) => void, onCheckpoint?: (sequence: DBSequence) => void | Promise<void>, customHeaders?: Record<string, string>): Promise<void>;
53
55
  export {};
@@ -227,7 +227,7 @@ function parseChangesFeedLine(line) {
227
227
  }
228
228
  return { type: "change", change };
229
229
  }
230
- async function fetchChangesForInitialSync(downloadToDB, remoteDbUrl, authHeader, decryptFunction, since = "0", onProgress, onCheckpoint) {
230
+ async function fetchChangesForInitialSync(downloadToDB, remoteDbUrl, authHeader, decryptFunction, since = "0", onProgress, onCheckpoint, customHeaders) {
231
231
  let totalFetched = 0;
232
232
  let totalValidFetched = 0;
233
233
  let totalBytes = 0;
@@ -239,10 +239,9 @@ async function fetchChangesForInitialSync(downloadToDB, remoteDbUrl, authHeader,
239
239
  revs: "true",
240
240
  since: since.toString()
241
241
  };
242
- const fetchHeaders = {
243
- Accept: "application/json",
244
- Authorization: authHeader
245
- };
242
+ const fetchHeaders = new Headers(customHeaders);
243
+ fetchHeaders.set("Accept", "application/json");
244
+ fetchHeaders.set("Authorization", authHeader);
246
245
  const targetURL = setParamsToURL(new URL(`${remoteDbUrl}/_changes`), {
247
246
  ...changesBaseParams,
248
247
  feed: "normal",
@@ -8,6 +8,7 @@ import { ServiceModuleBase } from "./ServiceModuleBase.js";
8
8
  import { fetchChangesForInitialSync, isRetryableStreamingFetchFailure } from "../pouchdb/StreamingFetch.js";
9
9
  import { getConfiguredFunctionsForEncryption } from "../pouchdb/encryption.js";
10
10
  import { AuthorizationHeaderGenerator, generateCredentialObject } from "../replication/httplib.js";
11
+ import { parseHeaderValues } from "../common/utils.js";
11
12
  import { sizeToHumanReadable } from "octagonal-wheels/number";
12
13
  const FAST_FETCH_CHECKPOINT_KEY = "fast-fetch-checkpoint";
13
14
  const FAST_FETCH_RETRY_DELAYS = [2e3, 5e3, 1e4, 2e4];
@@ -356,6 +357,7 @@ Are you sure you wish to proceed?`;
356
357
  const authHeader = await new AuthorizationHeaderGenerator().getAuthorizationHeader(
357
358
  generateCredentialObject(settings)
358
359
  );
360
+ const customHeaders = parseHeaderValues(settings.couchDB_CustomHeaders);
359
361
  for (let attempt = 0; ; attempt++) {
360
362
  try {
361
363
  await fetchChangesForInitialSync(
@@ -372,7 +374,8 @@ Total bytes fetched: ${sizeToHumanReadable(progress.totalBytes)}`,
372
374
  "fetch-init-progress"
373
375
  );
374
376
  },
375
- (sequence) => this.saveFastFetchCheckpoint(remote, sequence)
377
+ (sequence) => this.saveFastFetchCheckpoint(remote, sequence),
378
+ customHeaders
376
379
  );
377
380
  break;
378
381
  } catch (ex) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrtmrz/livesync-commonlib",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Shared data, storage, and replication primitives for Self-hosted LiveSync clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",