Skip to content

Commit

Permalink
Add support for allowedApplications to Tokens.createToken and Tokens.…
Browse files Browse the repository at this point in the history
…updateToken (#460)

* Support allowedApplications for Tokens.createToken

* Use more recent Ubuntu distro for builds

* Prepare 0.14.0
  • Loading branch information
olemstrom authored Nov 17, 2022
1 parent 71ed2ac commit 0b8f00a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: focal
language: node_js
node_js:
- lts/*
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@ See the [corresponding HTTP service documentation][246].
* `config.scopes` **[Array][209]<[string][201]>?**&#x20;
* `config.resources` **[Array][209]<[string][201]>?**&#x20;
* `config.allowedUrls` **[Array][209]<[string][201]>?**&#x20;
* `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

Expand Down Expand Up @@ -2085,7 +2086,8 @@ See the [corresponding HTTP service documentation][248].
* `config.note` **[string][201]?**&#x20;
* `config.scopes` **[Array][209]<[string][201]>?**&#x20;
* `config.resources` **[Array][209]<[string][201]>?**&#x20;
* `config.allowedUrls` **[Array][209]<[string][201]>?**&#x20;
* `config.allowedUrls` **([Array][209]<[string][201]> | null)?**&#x20;
* `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

Expand Down
4 changes: 2 additions & 2 deletions 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": "@mapbox/mapbox-sdk",
"version": "0.13.7",
"version": "0.14.0",
"description": "JS SDK for accessing Mapbox APIs",
"main": "index.js",
"files": [
Expand Down
58 changes: 54 additions & 4 deletions services/__tests__/tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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',
Expand All @@ -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' }]
}
});
});
Expand Down Expand Up @@ -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({
Expand All @@ -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',
Expand All @@ -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' }]
}
});
});
Expand Down
28 changes: 25 additions & 3 deletions services/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Tokens.listTokens = function() {
* @param {Array<string>} [config.scopes]
* @param {Array<string>} [config.resources]
* @param {Array<string>} [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
Expand All @@ -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 = {};
Expand All @@ -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',
Expand Down Expand Up @@ -130,7 +141,8 @@ Tokens.createTemporaryToken = function(config) {
* @param {string} [config.note]
* @param {Array<string>} [config.scopes]
* @param {Array<string>} [config.resources]
* @param {Array<string>} [config.allowedUrls]
* @param {Array<string> | 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
Expand All @@ -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 = {};
Expand All @@ -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',
Expand Down

0 comments on commit 0b8f00a

Please sign in to comment.