Skip to content

Commit f121491

Browse files
authored
Add customHeaders option to DropboxAuth (#854)
1 parent 423ae06 commit f121491

File tree

7 files changed

+66
-5
lines changed

7 files changed

+66
-5
lines changed

generator/typescript/index.d.tstemplate

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface DropboxAuthOptions {
2020
domain?: string;
2121
// A custom delimiter to use when separating domain from subdomain. This should only be used for testing as scaffolding.
2222
domainDelimiter?: string;
23+
// An object (in the form of header: value) designed to set custom headers to use during a request.
24+
customHeaders?: object;
2325
}
2426

2527
export class DropboxAuth {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dropbox",
3-
"version": "10.18.0",
3+
"version": "10.19.0",
44
"registry": "npm",
55
"description": "The Dropbox JavaScript SDK is a lightweight, promise based interface to the Dropbox v2 API that works in both nodejs and browser environments.",
66
"main": "cjs/index.js",

src/auth.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ const IncludeGrantedScopes = ['none', 'user', 'team'];
5353
* should only be used for testing as scaffolding to avoid making network requests.
5454
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from
5555
* subdomain. This should only be used for testing as scaffolding.
56-
*/
56+
* @arg {Object} [options.customHeaders] - An object (in the form of header: value) designed to set
57+
* custom headers to use during a request.
58+
*/
5759
export default class DropboxAuth {
5860
constructor(options) {
5961
options = options || {};
@@ -67,6 +69,7 @@ export default class DropboxAuth {
6769

6870
this.domain = options.domain;
6971
this.domainDelimiter = options.domainDelimiter;
72+
this.customHeaders = options.customHeaders;
7073
}
7174

7275
/**

src/dropbox.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export default class Dropbox {
6969
this.selectAdmin = options.selectAdmin;
7070
this.pathRoot = options.pathRoot;
7171

72-
this.domain = options.domain;
73-
this.domainDelimiter = options.domainDelimiter;
74-
this.customHeaders = options.customHeaders;
72+
this.domain = options.domain || this.auth.domain;
73+
this.domainDelimiter = options.domainDelimiter || this.auth.domainDelimiter;
74+
this.customHeaders = options.customHeaders || this.auth.customHeaders;
7575

7676
Object.assign(this, routes);
7777
}

test/unit/auth.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ describe('DropboxAuth', () => {
4141
});
4242
});
4343

44+
describe('customHeaders', () => {
45+
it('can be set in the constructor', () => {
46+
const dbx = new DropboxAuth({ customHeaders: { foo: 'bar' } });
47+
chai.assert.equal(dbx.customHeaders.foo, 'bar');
48+
});
49+
50+
it('is undefined if not set in constructor', () => {
51+
const dbx = new DropboxAuth();
52+
chai.assert.equal(dbx.customHeaders, undefined);
53+
});
54+
});
55+
4456
describe('getAuthenticationUrl()', () => {
4557
it('throws an error if the client id isn\'t set', () => {
4658
const dbx = new DropboxAuth();

test/unit/dropbox.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,42 @@ describe('Dropbox', () => {
2929
});
3030
});
3131

32+
describe('domain', () => {
33+
it('can be set in the constructor', () => {
34+
const dbx = new Dropbox({ domain: 'mydomain.com' });
35+
chai.assert.equal(dbx.domain, 'mydomain.com');
36+
});
37+
38+
it('is undefined if not set in constructor', () => {
39+
const dbx = new Dropbox();
40+
chai.assert.equal(dbx.domain, undefined);
41+
});
42+
43+
it('is set by auth.domain if not set in constructor', () => {
44+
const auth = new DropboxAuth({ domain: 'mydomain.com' });
45+
const dbx = new Dropbox({ auth });
46+
chai.assert.equal(dbx.domain, 'mydomain.com');
47+
});
48+
});
49+
50+
describe('domainDelimiter', () => {
51+
it('can be set in the constructor', () => {
52+
const dbx = new Dropbox({ domainDelimiter: '-' });
53+
chai.assert.equal(dbx.domainDelimiter, '-');
54+
});
55+
56+
it('is undefined if not set in constructor', () => {
57+
const dbx = new Dropbox();
58+
chai.assert.equal(dbx.domainDelimiter, undefined);
59+
});
60+
61+
it('is set by auth.domainDelimiter if not set in constructor', () => {
62+
const auth = new DropboxAuth({ domainDelimiter: '-' });
63+
const dbx = new Dropbox({ auth });
64+
chai.assert.equal(dbx.domainDelimiter, '-');
65+
});
66+
});
67+
3268
describe('customHeaders', () => {
3369
it('can be set in the constructor', () => {
3470
const dbx = new Dropbox({ customHeaders: { foo: 'bar' } });
@@ -39,6 +75,12 @@ describe('Dropbox', () => {
3975
const dbx = new Dropbox();
4076
chai.assert.equal(dbx.customHeaders, undefined);
4177
});
78+
79+
it('is set by auth.customHeaders if not set in constructor', () => {
80+
const auth = new DropboxAuth({ customHeaders: { foo: 'bar' } });
81+
const dbx = new Dropbox({ auth });
82+
chai.assert.equal(dbx.customHeaders.foo, 'bar');
83+
});
4284
});
4385

4486
describe('RPC requests', () => {

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface DropboxAuthOptions {
2020
domain?: string;
2121
// A custom delimiter to use when separating domain from subdomain. This should only be used for testing as scaffolding.
2222
domainDelimiter?: string;
23+
// An object (in the form of header: value) designed to set custom headers to use during a request.
24+
customHeaders?: object;
2325
}
2426

2527
export class DropboxAuth {

0 commit comments

Comments
 (0)