diff --git a/package.json b/package.json index 0194380..25eb078 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "predocs-test": "npm run docs" }, "dependencies": { - "@google-cloud/common": "^1.0.0", + "@google-cloud/common": "^2.0.0", "@google-cloud/paginator": "^1.0.0", "@google-cloud/promisify": "^1.0.0", "arrify": "^2.0.0", diff --git a/src/index.ts b/src/index.ts index a90f10a..5b7743f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,6 +59,14 @@ export interface CreateZoneRequest { export type CreateZoneResponse = [Zone, Metadata]; +export interface DNSOptions extends GoogleAuthOptions { + /** + * The API endpoint of the service used to make requests. + * Defaults to `www.googleapis.com`. + */ + apiEndpoint?: string; +} + /** * @typedef {object} ClientConfig * @property {string} [projectId] The project ID from the Google Developer's @@ -118,10 +126,11 @@ export type CreateZoneResponse = [Zone, Metadata]; */ class DNS extends Service { getZonesStream: (query: GetZonesRequest) => Stream; - constructor(options?: GoogleAuthOptions) { - options = options || {}; + constructor(options: DNSOptions = {}) { + options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com'; const config = { - baseUrl: 'https://www.googleapis.com/dns/v1', + apiEndpoint: options.apiEndpoint, + baseUrl: `https://${options.apiEndpoint}/dns/v1`, scopes: [ 'https://www.googleapis.com/auth/ndev.clouddns.readwrite', 'https://www.googleapis.com/auth/cloud-platform', diff --git a/test/index.ts b/test/index.ts index b0c89a2..0852ed1 100644 --- a/test/index.ts +++ b/test/index.ts @@ -135,6 +135,17 @@ describe('DNS', () => { require('../../package.json') ); }); + + it('should enable apiEndpoint override', () => { + const apiEndpoint = 'fake.endpoint'; + dns = new DNS({ + projectId: PROJECT_ID, + apiEndpoint, + }); + const calledWith = dns.calledWith_[0]; + assert.strictEqual(calledWith.apiEndpoint, apiEndpoint); + assert.strictEqual(calledWith.baseUrl, `https://${apiEndpoint}/dns/v1`); + }); }); describe('createZone', () => {