Skip to content

Commit 0b8f00a

Browse files
authored
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
1 parent 71ed2ac commit 0b8f00a

File tree

7 files changed

+91
-11
lines changed

7 files changed

+91
-11
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: focal
12
language: node_js
23
node_js:
34
- lts/*

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
## 0.14.0
6+
7+
- **Add:** Config for `Tokens#createToken` and `Tokens#updateToken` can now include the `allowedApplications` property.
8+
9+
510
## 0.13.7
611

712
- **Add:** add additional EV values to the directions API request

docs/services.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,7 @@ See the [corresponding HTTP service documentation][246].
20282028
* `config.scopes` **[Array][209]<[string][201]>?**&#x20;
20292029
* `config.resources` **[Array][209]<[string][201]>?**&#x20;
20302030
* `config.allowedUrls` **[Array][209]<[string][201]>?**&#x20;
2031+
* `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.
20312032

20322033
#### Examples
20332034

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

20902092
#### Examples
20912093

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mapbox/mapbox-sdk",
3-
"version": "0.13.7",
3+
"version": "0.14.0",
44
"description": "JS SDK for accessing Mapbox APIs",
55
"main": "index.js",
66
"files": [

services/__tests__/tokens.test.js

+54-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ describe('createToken', () => {
7373
});
7474
});
7575

76+
test('with allowedApplications', () => {
77+
tokens.createToken({
78+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
79+
});
80+
expect(tu.requestConfig(tokens)).toEqual({
81+
path: '/tokens/v2/:ownerId',
82+
method: 'POST',
83+
params: {},
84+
body: {
85+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }],
86+
scopes: []
87+
}
88+
});
89+
});
90+
7691
test('with scopes', () => {
7792
tokens.createToken({ scopes: ['styles:read', 'styles:write'] });
7893
expect(tu.requestConfig(tokens)).toEqual({
@@ -88,7 +103,8 @@ describe('createToken', () => {
88103
scopes: ['styles:list'],
89104
note: 'horseleg',
90105
resources: ['one', 'two'],
91-
allowedUrls: ['boba.com', 'coffee.ca']
106+
allowedUrls: ['boba.com', 'coffee.ca'],
107+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
92108
});
93109
expect(tu.requestConfig(tokens)).toEqual({
94110
path: '/tokens/v2/:ownerId',
@@ -98,7 +114,8 @@ describe('createToken', () => {
98114
scopes: ['styles:list'],
99115
note: 'horseleg',
100116
resources: ['one', 'two'],
101-
allowedUrls: ['boba.com', 'coffee.ca']
117+
allowedUrls: ['boba.com', 'coffee.ca'],
118+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
102119
}
103120
});
104121
});
@@ -215,6 +232,37 @@ describe('updateToken', () => {
215232
});
216233
});
217234

235+
test('with allowedApplications', () => {
236+
tokens.updateToken({
237+
tokenId: 'foo',
238+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
239+
});
240+
241+
expect(tu.requestConfig(tokens)).toEqual({
242+
path: '/tokens/v2/:ownerId/:tokenId',
243+
params: { tokenId: 'foo' },
244+
method: 'PATCH',
245+
body: {
246+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
247+
}
248+
});
249+
});
250+
251+
test('allowedApplications can be null', () => {
252+
tokens.updateToken({
253+
tokenId: 'foo',
254+
allowedApplications: null
255+
});
256+
257+
expect(tu.requestConfig(tokens)).toEqual({
258+
path: '/tokens/v2/:ownerId/:tokenId',
259+
params: { tokenId: 'foo' },
260+
method: 'PATCH',
261+
body: {
262+
allowedApplications: null
263+
}
264+
});
265+
});
218266

219267
test('with scopes', () => {
220268
tokens.updateToken({
@@ -235,7 +283,8 @@ describe('updateToken', () => {
235283
scopes: ['styles:list'],
236284
note: 'horseleg',
237285
resources: ['one', 'two'],
238-
allowedUrls: ['boba.com', 'milk-tea.ca']
286+
allowedUrls: ['boba.com', 'milk-tea.ca'],
287+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
239288
});
240289
expect(tu.requestConfig(tokens)).toEqual({
241290
path: '/tokens/v2/:ownerId/:tokenId',
@@ -245,7 +294,8 @@ describe('updateToken', () => {
245294
scopes: ['styles:list'],
246295
note: 'horseleg',
247296
resources: ['one', 'two'],
248-
allowedUrls: ['boba.com', 'milk-tea.ca']
297+
allowedUrls: ['boba.com', 'milk-tea.ca'],
298+
allowedApplications: [{ platform: 'iOS', bundleId: 'com.example.foo' }]
249299
}
250300
});
251301
});

services/tokens.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Tokens.listTokens = function() {
4343
* @param {Array<string>} [config.scopes]
4444
* @param {Array<string>} [config.resources]
4545
* @param {Array<string>} [config.allowedUrls]
46+
* @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.
4647
* @return {MapiRequest}
4748
*
4849
* @example
@@ -61,7 +62,13 @@ Tokens.createToken = function(config) {
6162
note: v.string,
6263
scopes: v.arrayOf(v.string),
6364
resources: v.arrayOf(v.string),
64-
allowedUrls: v.arrayOf(v.string)
65+
allowedUrls: v.arrayOf(v.string),
66+
allowedApplications: v.arrayOf(
67+
v.shape({
68+
bundleId: v.string,
69+
platform: v.string
70+
})
71+
)
6572
})(config);
6673

6774
var body = {};
@@ -76,6 +83,10 @@ Tokens.createToken = function(config) {
7683
body.allowedUrls = config.allowedUrls;
7784
}
7885

86+
if (config.allowedApplications) {
87+
body.allowedApplications = config.allowedApplications;
88+
}
89+
7990
return this.client.createRequest({
8091
method: 'POST',
8192
path: '/tokens/v2/:ownerId',
@@ -130,7 +141,8 @@ Tokens.createTemporaryToken = function(config) {
130141
* @param {string} [config.note]
131142
* @param {Array<string>} [config.scopes]
132143
* @param {Array<string>} [config.resources]
133-
* @param {Array<string>} [config.allowedUrls]
144+
* @param {Array<string> | null} [config.allowedUrls]
145+
* @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.
134146
* @return {MapiRequest}
135147
*
136148
* @example
@@ -150,7 +162,13 @@ Tokens.updateToken = function(config) {
150162
note: v.string,
151163
scopes: v.arrayOf(v.string),
152164
resources: v.arrayOf(v.string),
153-
allowedUrls: v.arrayOf(v.string)
165+
allowedUrls: v.arrayOf(v.string),
166+
allowedApplications: v.arrayOf(
167+
v.shape({
168+
bundleId: v.string,
169+
platform: v.string
170+
})
171+
)
154172
})(config);
155173

156174
var body = {};
@@ -167,6 +185,10 @@ Tokens.updateToken = function(config) {
167185
body.allowedUrls = config.allowedUrls;
168186
}
169187

188+
if (config.allowedApplications || config.allowedApplications === null) {
189+
body.allowedApplications = config.allowedApplications;
190+
}
191+
170192
return this.client.createRequest({
171193
method: 'PATCH',
172194
path: '/tokens/v2/:ownerId/:tokenId',

0 commit comments

Comments
 (0)