Skip to content

Commit

Permalink
Expose domain delimiter via main clients (#659)
Browse files Browse the repository at this point in the history
* Expose domain delimiter via main clients

* Fix typo and linter
  • Loading branch information
rogebrd authored May 18, 2021
1 parent bbcd16c commit 660d657
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions generator/typescript/index.d.tstemplate
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface DropboxAuthOptions {
fetch?: Function;
// A custom domain to use when making api requests. This should only be used for testing as scaffolding to avoid making network requests.
domain?: string;
// A custom delimiter to use when separating domain from subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
}

export class DropboxAuth {
Expand Down Expand Up @@ -173,6 +175,8 @@ export interface DropboxOptions {
fetch?: Function;
// A custom domain to use when making api requests. This should only be used for testing as scaffolding to avoid making network requests.
domain?: string;
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
}

export class DropboxResponseError<T> {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dropbox",
"version": "9.8.4",
"version": "9.8.5",
"registry": "npm",
"description": "The Dropbox JavaScript SDK is a lightweight, promise based interface to the Dropbox v2 API that works in both nodejs and browser environments.",
"main": "cjs/index.js",
Expand Down
7 changes: 5 additions & 2 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const IncludeGrantedScopes = ['none', 'user', 'team'];
* authentication URL and refresh access tokens.
* @arg {String} [options.domain] - A custom domain to use when making api requests. This
* should only be used for testing as scaffolding to avoid making network requests.
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from
* subdomain. This should only be used for testing as scaffolding.
*/
export default class DropboxAuth {
constructor(options) {
Expand All @@ -64,6 +66,7 @@ export default class DropboxAuth {
this.clientSecret = options.clientSecret;

this.domain = options.domain;
this.domainDelimiter = options.domainDelimiter;
}

/**
Expand Down Expand Up @@ -293,7 +296,7 @@ export default class DropboxAuth {
if (!clientId) {
throw new Error('A client id is required. You can set the client id using .setClientId().');
}
let path = OAuth2TokenUrl(this.domain);
let path = OAuth2TokenUrl(this.domain, this.domainDelimiter);
path += '?grant_type=authorization_code';
path += `&code=${code}`;
path += `&client_id=${clientId}`;
Expand Down Expand Up @@ -343,7 +346,7 @@ export default class DropboxAuth {
* @returns {Promise<*>}
*/
refreshAccessToken(scope = null) {
let refreshUrl = OAuth2TokenUrl(this.domain);
let refreshUrl = OAuth2TokenUrl(this.domain, this.domainDelimiter);
const clientId = this.getClientId();
const clientSecret = this.getClientSecret();

Expand Down
18 changes: 15 additions & 3 deletions src/dropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const b64 = typeof btoa === 'undefined'
* authentication URL and refresh access tokens.
* @arg {String} [options.domain] - A custom domain to use when making api requests. This
* should only be used for testing as scaffolding to avoid making network requests.
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from
* subdomain. This should only be used for testing as scaffolding.
*/
export default class Dropbox {
constructor(options) {
Expand All @@ -65,6 +67,7 @@ export default class Dropbox {
this.pathRoot = options.pathRoot;

this.domain = options.domain;
this.domainDelimiter = options.domainDelimiter;

Object.assign(this, routes);
}
Expand Down Expand Up @@ -129,7 +132,10 @@ export default class Dropbox {
this.setCommonHeaders(fetchOptions);
return fetchOptions;
})
.then((fetchOptions) => this.fetch(baseApiUrl(host, this.domain) + path, fetchOptions))
.then((fetchOptions) => this.fetch(
baseApiUrl(host, this.domain, this.domainDelimiter) + path,
fetchOptions,
))
.then((res) => parseResponse(res));
}

Expand All @@ -152,7 +158,10 @@ export default class Dropbox {

return fetchOptions;
})
.then((fetchOptions) => this.fetch(baseApiUrl(host, this.domain) + path, fetchOptions))
.then((fetchOptions) => this.fetch(
baseApiUrl(host, this.domain, this.domainDelimiter) + path,
fetchOptions,
))
.then((res) => parseDownloadResponse(res));
}

Expand Down Expand Up @@ -180,7 +189,10 @@ export default class Dropbox {

return fetchOptions;
})
.then((fetchOptions) => this.fetch(baseApiUrl(host, this.domain) + path, fetchOptions))
.then((fetchOptions) => this.fetch(
baseApiUrl(host, this.domain, this.domainDelimiter) + path,
fetchOptions,
))
.then((res) => parseResponse(res));
}

Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface DropboxAuthOptions {
fetch?: Function;
// A custom domain to use when making api requests. This should only be used for testing as scaffolding to avoid making network requests.
domain?: string;
// A custom delimiter to use when separating domain from subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
}

export class DropboxAuth {
Expand Down Expand Up @@ -174,6 +176,8 @@ export interface DropboxOptions {
fetch?: Function;
// A custom domain to use when making api requests. This should only be used for testing as scaffolding to avoid making network requests.
domain?: string;
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
}

export class DropboxResponseError<T> {
Expand Down

0 comments on commit 660d657

Please sign in to comment.