From 0b8f00aaa109e5944e04fec233009e52b053a562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Lemstr=C3=B6m?= Date: Thu, 17 Nov 2022 16:08:10 +0200 Subject: [PATCH] Add support for allowedApplications to Tokens.createToken and Tokens.updateToken (#460) * Support allowedApplications for Tokens.createToken * Use more recent Ubuntu distro for builds * Prepare 0.14.0 --- .travis.yml | 1 + CHANGELOG.md | 5 +++ docs/services.md | 4 ++- package-lock.json | 4 +-- package.json | 2 +- services/__tests__/tokens.test.js | 58 ++++++++++++++++++++++++++++--- services/tokens.js | 28 +++++++++++++-- 7 files changed, 91 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0107eb5c..005cdffd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: focal language: node_js node_js: - lts/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c4c9e30..72296263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 0.14.0 + +- **Add:** Config for `Tokens#createToken` and `Tokens#updateToken` can now include the `allowedApplications` property. + + ## 0.13.7 - **Add:** add additional EV values to the directions API request diff --git a/docs/services.md b/docs/services.md index 148562aa..6848f372 100644 --- a/docs/services.md +++ b/docs/services.md @@ -2028,6 +2028,7 @@ See the [corresponding HTTP service documentation][246]. * `config.scopes` **[Array][209]<[string][201]>?** * `config.resources` **[Array][209]<[string][201]>?** * `config.allowedUrls` **[Array][209]<[string][201]>?** + * `config.allowedApplications` **[Array][209]<{platform: [string][201], bundleId: [string][201]}>?** 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 @@ -2085,7 +2086,8 @@ See the [corresponding HTTP service documentation][248]. * `config.note` **[string][201]?** * `config.scopes` **[Array][209]<[string][201]>?** * `config.resources` **[Array][209]<[string][201]>?** - * `config.allowedUrls` **[Array][209]<[string][201]>?** + * `config.allowedUrls` **([Array][209]<[string][201]> | null)?** + * `config.allowedApplications` **([Array][209]<{platform: [string][201], bundleId: [string][201]}> | 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/package-lock.json b/package-lock.json index 8958c4d1..3abc3876 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mapbox/mapbox-sdk", - "version": "0.13.7", + "version": "0.14.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@mapbox/mapbox-sdk", - "version": "0.13.7", + "version": "0.14.0", "license": "BSD-2-Clause", "dependencies": { "@mapbox/fusspot": "^0.4.0", diff --git a/package.json b/package.json index a44e5521..b3a6d42f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mapbox/mapbox-sdk", - "version": "0.13.7", + "version": "0.14.0", "description": "JS SDK for accessing Mapbox APIs", "main": "index.js", "files": [ diff --git a/services/__tests__/tokens.test.js b/services/__tests__/tokens.test.js index 2ee53670..fbedbba0 100644 --- a/services/__tests__/tokens.test.js +++ b/services/__tests__/tokens.test.js @@ -73,6 +73,21 @@ describe('createToken', () => { }); }); + test('with allowedApplications', () => { + tokens.createToken({ + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] + }); + expect(tu.requestConfig(tokens)).toEqual({ + path: '/tokens/v2/:ownerId', + method: 'POST', + params: {}, + body: { + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }], + scopes: [] + } + }); + }); + test('with scopes', () => { tokens.createToken({ scopes: ['styles:read', 'styles:write'] }); expect(tu.requestConfig(tokens)).toEqual({ @@ -88,7 +103,8 @@ describe('createToken', () => { scopes: ['styles:list'], note: 'horseleg', resources: ['one', 'two'], - allowedUrls: ['boba.com', 'coffee.ca'] + allowedUrls: ['boba.com', 'coffee.ca'], + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] }); expect(tu.requestConfig(tokens)).toEqual({ path: '/tokens/v2/:ownerId', @@ -98,7 +114,8 @@ describe('createToken', () => { scopes: ['styles:list'], note: 'horseleg', resources: ['one', 'two'], - allowedUrls: ['boba.com', 'coffee.ca'] + allowedUrls: ['boba.com', 'coffee.ca'], + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] } }); }); @@ -215,6 +232,37 @@ describe('updateToken', () => { }); }); + test('with allowedApplications', () => { + tokens.updateToken({ + tokenId: 'foo', + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] + }); + + expect(tu.requestConfig(tokens)).toEqual({ + path: '/tokens/v2/:ownerId/:tokenId', + params: { tokenId: 'foo' }, + method: 'PATCH', + body: { + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] + } + }); + }); + + test('allowedApplications can be null', () => { + tokens.updateToken({ + tokenId: 'foo', + allowedApplications: null + }); + + expect(tu.requestConfig(tokens)).toEqual({ + path: '/tokens/v2/:ownerId/:tokenId', + params: { tokenId: 'foo' }, + method: 'PATCH', + body: { + allowedApplications: null + } + }); + }); test('with scopes', () => { tokens.updateToken({ @@ -235,7 +283,8 @@ describe('updateToken', () => { scopes: ['styles:list'], note: 'horseleg', resources: ['one', 'two'], - allowedUrls: ['boba.com', 'milk-tea.ca'] + allowedUrls: ['boba.com', 'milk-tea.ca'], + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] }); expect(tu.requestConfig(tokens)).toEqual({ path: '/tokens/v2/:ownerId/:tokenId', @@ -245,7 +294,8 @@ describe('updateToken', () => { scopes: ['styles:list'], note: 'horseleg', resources: ['one', 'two'], - allowedUrls: ['boba.com', 'milk-tea.ca'] + allowedUrls: ['boba.com', 'milk-tea.ca'], + allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }] } }); }); diff --git a/services/tokens.js b/services/tokens.js index b6575cb0..40e77e12 100644 --- a/services/tokens.js +++ b/services/tokens.js @@ -43,6 +43,7 @@ Tokens.listTokens = function() { * @param {Array} [config.scopes] * @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. * @return {MapiRequest} * * @example @@ -61,7 +62,13 @@ Tokens.createToken = function(config) { note: v.string, scopes: v.arrayOf(v.string), resources: v.arrayOf(v.string), - allowedUrls: v.arrayOf(v.string) + allowedUrls: v.arrayOf(v.string), + allowedApplications: v.arrayOf( + v.shape({ + bundleId: v.string, + platform: v.string + }) + ) })(config); var body = {}; @@ -76,6 +83,10 @@ Tokens.createToken = function(config) { body.allowedUrls = config.allowedUrls; } + if (config.allowedApplications) { + body.allowedApplications = config.allowedApplications; + } + return this.client.createRequest({ method: 'POST', path: '/tokens/v2/:ownerId', @@ -130,7 +141,8 @@ Tokens.createTemporaryToken = function(config) { * @param {string} [config.note] * @param {Array} [config.scopes] * @param {Array} [config.resources] - * @param {Array} [config.allowedUrls] + * @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. * @return {MapiRequest} * * @example @@ -150,7 +162,13 @@ Tokens.updateToken = function(config) { note: v.string, scopes: v.arrayOf(v.string), resources: v.arrayOf(v.string), - allowedUrls: v.arrayOf(v.string) + allowedUrls: v.arrayOf(v.string), + allowedApplications: v.arrayOf( + v.shape({ + bundleId: v.string, + platform: v.string + }) + ) })(config); var body = {}; @@ -167,6 +185,10 @@ Tokens.updateToken = function(config) { body.allowedUrls = config.allowedUrls; } + if (config.allowedApplications || config.allowedApplications === null) { + body.allowedApplications = config.allowedApplications; + } + return this.client.createRequest({ method: 'PATCH', path: '/tokens/v2/:ownerId/:tokenId',