Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/addressBook.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ export declare const makeAddressBook: (params: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<DAVResponse[]>;
1 change: 1 addition & 0 deletions dist/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export declare const createDAVClient: (params: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<DAVResponse[]>;
fetchVCards: (params: {
addressBook: DAVAddressBook;
Expand Down
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ declare const _default: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<import("./types/DAVTypes").DAVResponse[]>;
serviceDiscovery: (params: {
account: import("./types/models").DAVAccount;
Expand Down Expand Up @@ -614,6 +615,7 @@ declare const _default: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<import("./types/DAVTypes").DAVResponse[]>;
fetchVCards: (params: {
addressBook: import("./types/models").DAVAddressBook;
Expand Down
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsdav",
"version": "2.3.1",
"version": "2.3.2",
"description": "WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser",
"keywords": [
"dav",
Expand Down
9 changes: 7 additions & 2 deletions dist/tsdav.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ const deleteVCard = async (params) => {
});
};
const makeAddressBook = async (params) => {
const { url, props, depth, headers, headersToExclude, fetchOptions = {} } = params;
const { url, props, depth, headers, headersToExclude, fetchOptions = {}, fetch: fetchOverride, } = params;
return davRequest({
url,
init: {
Expand All @@ -835,6 +835,7 @@ const makeAddressBook = async (params) => {
: undefined,
},
fetchOptions,
fetch: fetchOverride,
});
};

Expand Down Expand Up @@ -2357,7 +2358,11 @@ class DAVClient {
})(params[0]);
}
async makeAddressBook(...params) {
return defaultParam(makeAddressBook, { headers: this.authHeaders, fetchOptions: this.fetchOptions })(params[0]);
return defaultParam(makeAddressBook, {
headers: this.authHeaders,
fetchOptions: this.fetchOptions,
fetch: this.fetchOverride,
})(params[0]);
}
async fetchAddressBooks(...params) {
return defaultParam(fetchAddressBooks, {
Expand Down
9 changes: 7 additions & 2 deletions dist/tsdav.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ const deleteVCard = async (params) => {
});
};
const makeAddressBook = async (params) => {
const { url, props, depth, headers, headersToExclude, fetchOptions = {} } = params;
const { url, props, depth, headers, headersToExclude, fetchOptions = {}, fetch: fetchOverride, } = params;
return davRequest({
url,
init: {
Expand All @@ -835,6 +835,7 @@ const makeAddressBook = async (params) => {
: undefined,
},
fetchOptions,
fetch: fetchOverride,
});
};

Expand Down Expand Up @@ -2357,7 +2358,11 @@ class DAVClient {
})(params[0]);
}
async makeAddressBook(...params) {
return defaultParam(makeAddressBook, { headers: this.authHeaders, fetchOptions: this.fetchOptions })(params[0]);
return defaultParam(makeAddressBook, {
headers: this.authHeaders,
fetchOptions: this.fetchOptions,
fetch: this.fetchOverride,
})(params[0]);
}
async fetchAddressBooks(...params) {
return defaultParam(fetchAddressBooks, {
Expand Down
4 changes: 4 additions & 0 deletions dist/tsdav.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ declare const makeAddressBook: (params: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<DAVResponse[]>;

declare const fetchCalendarUserAddresses: (params: {
Expand Down Expand Up @@ -812,6 +813,7 @@ declare const createDAVClient: (params: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<DAVResponse[]>;
fetchVCards: (params: {
addressBook: DAVAddressBook;
Expand Down Expand Up @@ -1291,6 +1293,7 @@ declare const _default: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<DAVResponse[]>;
serviceDiscovery: (params: {
account: DAVAccount;
Expand Down Expand Up @@ -1637,6 +1640,7 @@ declare const _default: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}) => Promise<DAVResponse[]>;
fetchVCards: (params: {
addressBook: DAVAddressBook;
Expand Down
9 changes: 7 additions & 2 deletions dist/tsdav.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ const deleteVCard = async (params) => {
});
};
const makeAddressBook = async (params) => {
const { url, props, depth, headers, headersToExclude, fetchOptions = {} } = params;
const { url, props, depth, headers, headersToExclude, fetchOptions = {}, fetch: fetchOverride, } = params;
return davRequest({
url,
init: {
Expand All @@ -831,6 +831,7 @@ const makeAddressBook = async (params) => {
: undefined,
},
fetchOptions,
fetch: fetchOverride,
});
};

Expand Down Expand Up @@ -2353,7 +2354,11 @@ class DAVClient {
})(params[0]);
}
async makeAddressBook(...params) {
return defaultParam(makeAddressBook, { headers: this.authHeaders, fetchOptions: this.fetchOptions })(params[0]);
return defaultParam(makeAddressBook, {
headers: this.authHeaders,
fetchOptions: this.fetchOptions,
fetch: this.fetchOverride,
})(params[0]);
}
async fetchAddressBooks(...params) {
return defaultParam(fetchAddressBooks, {
Expand Down
9 changes: 7 additions & 2 deletions dist/tsdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -10003,7 +10003,7 @@ const deleteVCard = async (params) => {
});
};
const makeAddressBook = async (params) => {
const { url, props, depth, headers, headersToExclude, fetchOptions = {} } = params;
const { url, props, depth, headers, headersToExclude, fetchOptions = {}, fetch: fetchOverride, } = params;
return davRequest({
url,
init: {
Expand All @@ -10025,6 +10025,7 @@ const makeAddressBook = async (params) => {
: undefined,
},
fetchOptions,
fetch: fetchOverride,
});
};

Expand Down Expand Up @@ -11719,7 +11720,11 @@ class DAVClient {
})(params[0]);
}
async makeAddressBook(...params) {
return defaultParam(makeAddressBook, { headers: this.authHeaders, fetchOptions: this.fetchOptions })(params[0]);
return defaultParam(makeAddressBook, {
headers: this.authHeaders,
fetchOptions: this.fetchOptions,
fetch: this.fetchOverride,
})(params[0]);
}
async fetchAddressBooks(...params) {
return defaultParam(fetchAddressBooks, {
Expand Down
2 changes: 1 addition & 1 deletion dist/tsdav.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tsdav.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tsdav.min.mjs

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions dist/tsdav.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ const deleteVCard = async (params) => {
});
};
const makeAddressBook = async (params) => {
const { url, props, depth, headers, headersToExclude, fetchOptions = {} } = params;
const { url, props, depth, headers, headersToExclude, fetchOptions = {}, fetch: fetchOverride, } = params;
return davRequest({
url,
init: {
Expand All @@ -831,6 +831,7 @@ const makeAddressBook = async (params) => {
: undefined,
},
fetchOptions,
fetch: fetchOverride,
});
};

Expand Down Expand Up @@ -2353,7 +2354,11 @@ class DAVClient {
})(params[0]);
}
async makeAddressBook(...params) {
return defaultParam(makeAddressBook, { headers: this.authHeaders, fetchOptions: this.fetchOptions })(params[0]);
return defaultParam(makeAddressBook, {
headers: this.authHeaders,
fetchOptions: this.fetchOptions,
fetch: this.fetchOverride,
})(params[0]);
}
async fetchAddressBooks(...params) {
return defaultParam(fetchAddressBooks, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsdav",
"version": "2.3.1",
"version": "2.3.2",
"description": "WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser",
"keywords": [
"dav",
Expand Down
31 changes: 30 additions & 1 deletion src/__tests__/unit/addressBook.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchVCards } from '../../addressBook';
import { fetchVCards, makeAddressBook } from '../../addressBook';
import * as request from '../../request';

jest.mock('../../request');
Expand Down Expand Up @@ -103,3 +103,32 @@ describe('fetchVCards', () => {
expect(hrefs).toEqual(['/user/addr/card1.vcf']);
});
});

describe('makeAddressBook', () => {
beforeEach(() => {
jest.clearAllMocks();
mockedDavRequest.mockResolvedValue([]);
});

it('should forward a custom fetch to davRequest', async () => {
const customFetch = jest.fn() as unknown as typeof fetch;

await makeAddressBook({
url: 'http://example.com/user/addr/',
props: {},
fetch: customFetch,
});

expect(mockedDavRequest).toHaveBeenCalledTimes(1);
expect(mockedDavRequest.mock.calls[0][0].fetch).toBe(customFetch);
});

it('should leave fetch undefined when no override is given', async () => {
await makeAddressBook({
url: 'http://example.com/user/addr/',
props: {},
});

expect(mockedDavRequest.mock.calls[0][0].fetch).toBeUndefined();
});
});
45 changes: 45 additions & 0 deletions src/__tests__/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,49 @@ describe('DAVClient fetch override', () => {

expect(mockFetch).toHaveBeenCalled();
});

it('DAVClient should use fetch override in makeAddressBook', async () => {
const mockFetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
text: jest.fn().mockResolvedValue(''),
headers: new Map(),
});

const client = new DAVClient({
serverUrl: 'http://example.com',
credentials: mockCredentials,
fetch: mockFetch,
});

await client.makeAddressBook({
url: 'http://example.com/user/addr/',
props: {},
});

expect(mockFetch).toHaveBeenCalled();
});

it('createDAVClient should use fetch override in makeAddressBook', async () => {
const mockFetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
text: jest.fn().mockResolvedValue(''),
headers: new Map(),
});

const client = await createDAVClient({
serverUrl: 'http://example.com',
credentials: mockCredentials,
authMethod: 'Basic',
fetch: mockFetch,
});

await client.makeAddressBook({
url: 'http://example.com/user/addr/',
props: {},
});

expect(mockFetch).toHaveBeenCalled();
});
});
12 changes: 11 additions & 1 deletion src/addressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,17 @@ export const makeAddressBook = async (params: {
headers?: Record<string, string>;
headersToExclude?: string[];
fetchOptions?: RequestInit;
fetch?: typeof fetch;
}): Promise<DAVResponse[]> => {
const { url, props, depth, headers, headersToExclude, fetchOptions = {} } = params;
const {
url,
props,
depth,
headers,
headersToExclude,
fetchOptions = {},
fetch: fetchOverride,
} = params;
return davRequest({
url,
init: {
Expand All @@ -355,5 +364,6 @@ export const makeAddressBook = async (params: {
: undefined,
},
fetchOptions,
fetch: fetchOverride,
});
};
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,11 @@ export class DAVClient {
async makeAddressBook(
...params: Parameters<typeof rawMakeAddressBook>
): Promise<DAVResponse[]> {
return defaultParam(rawMakeAddressBook, { headers: this.authHeaders, fetchOptions: this.fetchOptions })(params[0]);
return defaultParam(rawMakeAddressBook, {
headers: this.authHeaders,
fetchOptions: this.fetchOptions,
fetch: this.fetchOverride,
})(params[0]);
}

async fetchAddressBooks(
Expand Down
Loading