diff --git a/docs/services.md b/docs/services.md index ffc8a43..8ed8bab 100644 --- a/docs/services.md +++ b/docs/services.md @@ -604,7 +604,7 @@ staticClient.getStaticImage({ position: { // position as a bounding box bbox: [-77.04,38.8,-77.02,38.91], - }, + }, padding: '4' }) .send() @@ -2041,6 +2041,7 @@ See the [corresponding HTTP service documentation][253]. * `config.scopes` **[Array][216]<[string][208]>?** * `config.resources` **[Array][216]<[string][208]>?** * `config.allowedUrls` **[Array][216]<[string][208]>?** + * `config.allowedApis` **[Array][216]<[string][208]>?** * `config.allowedApplications` **[Array][216]<{platform: [string][208], bundleId: [string][208]}>?** This option restricts tokens with an Application Bundle ID. The feature is in beta and is only available to our selected customers. For more information, please contact sales. #### Examples @@ -2100,6 +2101,7 @@ See the [corresponding HTTP service documentation][255]. * `config.scopes` **[Array][216]<[string][208]>?** * `config.resources` **[Array][216]<[string][208]>?** * `config.allowedUrls` **([Array][216]<[string][208]> | null)?** + * `config.allowedApis` **([Array][216]<[string][208]> | null)?** * `config.allowedApplications` **([Array][216]<{platform: [string][208], bundleId: [string][208]}> | null)?** This option restricts tokens with an Application Bundle ID. The feature is in beta and is only available to our selected customers. For more information, please contact sales. #### Examples diff --git a/services/__tests__/tokens.test.js b/services/__tests__/tokens.test.js index fbedbba..d5d1d1a 100644 --- a/services/__tests__/tokens.test.js +++ b/services/__tests__/tokens.test.js @@ -73,6 +73,21 @@ describe('createToken', () => { }); }); + test('with allowedApis', () => { + tokens.createToken({ + allowedApis: ['api-directions', 'api-geocoder'], + }); + expect(tu.requestConfig(tokens)).toEqual({ + path: '/tokens/v2/:ownerId', + method: 'POST', + params: {}, + body: { + allowedApis: ['api-directions', 'api-geocoder'], + scopes: [] + } + }); + }); + test('with allowedApplications', () => { tokens.createToken({ allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] @@ -104,6 +119,7 @@ describe('createToken', () => { note: 'horseleg', resources: ['one', 'two'], allowedUrls: ['boba.com', 'coffee.ca'], + allowedApis: ['api-styles', 'api-tilesets'], allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] }); expect(tu.requestConfig(tokens)).toEqual({ @@ -115,6 +131,7 @@ describe('createToken', () => { note: 'horseleg', resources: ['one', 'two'], allowedUrls: ['boba.com', 'coffee.ca'], + allowedApis: ['api-styles', 'api-tilesets'], allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] } }); @@ -232,6 +249,32 @@ describe('updateToken', () => { }); }); + test('with allowedApis', () => { + tokens.updateToken({ + tokenId: 'foo', + allowedApis: ['api-styles', 'api-coffee'] + }); + expect(tu.requestConfig(tokens)).toEqual({ + path: '/tokens/v2/:ownerId/:tokenId', + params: { tokenId: 'foo' }, + method: 'PATCH', + body: { allowedApis: ['api-styles', 'api-coffee'] } + }); + }); + + test('allowedApis can be null', () => { + tokens.updateToken({ + tokenId: 'foo', + allowedApis: null + }); + expect(tu.requestConfig(tokens)).toEqual({ + path: '/tokens/v2/:ownerId/:tokenId', + params: { tokenId: 'foo' }, + method: 'PATCH', + body: { allowedApis: null } + }); + }); + test('with allowedApplications', () => { tokens.updateToken({ tokenId: 'foo', diff --git a/services/tokens.js b/services/tokens.js index 40e77e1..6571df1 100644 --- a/services/tokens.js +++ b/services/tokens.js @@ -44,6 +44,7 @@ Tokens.listTokens = function() { * @param {Array} [config.resources] * @param {Array} [config.allowedUrls] * @param {Array<{ platform: string, bundleId: string }>} [config.allowedApplications] This option restricts tokens with an Application Bundle ID. The feature is in beta and is only available to our selected customers. For more information, please contact sales. + * @param {Array} [config.allowedApis] * @return {MapiRequest} * * @example @@ -68,7 +69,8 @@ Tokens.createToken = function(config) { bundleId: v.string, platform: v.string }) - ) + ), + allowedApis: v.arrayOf(v.string), })(config); var body = {}; @@ -86,6 +88,9 @@ Tokens.createToken = function(config) { if (config.allowedApplications) { body.allowedApplications = config.allowedApplications; } + if (config.allowedApis) { + body.allowedApis = config.allowedApis; + } return this.client.createRequest({ method: 'POST', @@ -143,6 +148,7 @@ Tokens.createTemporaryToken = function(config) { * @param {Array} [config.resources] * @param {Array | null} [config.allowedUrls] * @param {Array<{ platform: string, bundleId: string }> | null} [config.allowedApplications] This option restricts tokens with an Application Bundle ID. The feature is in beta and is only available to our selected customers. For more information, please contact sales. + * @param {Array | null} [config.allowedApis] * @return {MapiRequest} * * @example @@ -168,7 +174,8 @@ Tokens.updateToken = function(config) { bundleId: v.string, platform: v.string }) - ) + ), + allowedApis: v.arrayOf(v.string), })(config); var body = {}; @@ -188,6 +195,9 @@ Tokens.updateToken = function(config) { if (config.allowedApplications || config.allowedApplications === null) { body.allowedApplications = config.allowedApplications; } + if (config.allowedApis || config.allowedApis === null) { + body.allowedApis = config.allowedApis; + } return this.client.createRequest({ method: 'PATCH',