diff --git a/generator/typescript/index.d.tstemplate b/generator/typescript/index.d.tstemplate index f3517f9b..9e449484 100644 --- a/generator/typescript/index.d.tstemplate +++ b/generator/typescript/index.d.tstemplate @@ -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 { @@ -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 { diff --git a/package-lock.json b/package-lock.json index 81fccb02..ee1635e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dropbox", - "version": "9.8.0", + "version": "9.8.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index bc2d4efb..63995074 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/auth.js b/src/auth.js index 3de1925e..6ea9b414 100644 --- a/src/auth.js +++ b/src/auth.js @@ -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) { @@ -64,6 +66,7 @@ export default class DropboxAuth { this.clientSecret = options.clientSecret; this.domain = options.domain; + this.domainDelimiter = options.domainDelimiter; } /** @@ -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}`; @@ -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(); diff --git a/src/dropbox.js b/src/dropbox.js index a18d65d9..57972e7f 100644 --- a/src/dropbox.js +++ b/src/dropbox.js @@ -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) { @@ -65,6 +67,7 @@ export default class Dropbox { this.pathRoot = options.pathRoot; this.domain = options.domain; + this.domainDelimiter = options.domainDelimiter; Object.assign(this, routes); } @@ -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)); } @@ -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)); } @@ -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)); } diff --git a/types/index.d.ts b/types/index.d.ts index f7d177df..2a048fdd 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 { @@ -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 {