Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ staticClient.getStaticImage({
position: {
// position as a bounding box
bbox: [-77.04,38.8,-77.02,38.91],
},
},
padding: '4'
})
.send()
Expand Down Expand Up @@ -2041,6 +2041,7 @@ See the [corresponding HTTP service documentation][253].
* `config.scopes` **[Array][216]<[string][208]>?**&#x20;
* `config.resources` **[Array][216]<[string][208]>?**&#x20;
* `config.allowedUrls` **[Array][216]<[string][208]>?**&#x20;
* `config.allowedApis` **[Array][216]<[string][208]>?**&#x20;
* `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
Expand Down Expand Up @@ -2100,6 +2101,7 @@ See the [corresponding HTTP service documentation][255].
* `config.scopes` **[Array][216]<[string][208]>?**&#x20;
* `config.resources` **[Array][216]<[string][208]>?**&#x20;
* `config.allowedUrls` **([Array][216]<[string][208]> | null)?**&#x20;
* `config.allowedApis` **([Array][216]<[string][208]> | null)?**&#x20;
* `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
Expand Down
43 changes: 43 additions & 0 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 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' }]
Expand Down Expand Up @@ -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({
Expand All @@ -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' }]
}
});
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 12 additions & 2 deletions services/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Tokens.listTokens = function() {
* @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.
* @param {Array<string>} [config.allowedApis]
* @return {MapiRequest}
*
* @example
Expand All @@ -68,7 +69,8 @@ Tokens.createToken = function(config) {
bundleId: v.string,
platform: v.string
})
)
),
allowedApis: v.arrayOf(v.string),
})(config);

var body = {};
Expand All @@ -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',
Expand Down Expand Up @@ -143,6 +148,7 @@ Tokens.createTemporaryToken = function(config) {
* @param {Array<string>} [config.resources]
* @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.
* @param {Array<string> | null} [config.allowedApis]
* @return {MapiRequest}
*
* @example
Expand All @@ -168,7 +174,8 @@ Tokens.updateToken = function(config) {
bundleId: v.string,
platform: v.string
})
)
),
allowedApis: v.arrayOf(v.string),
})(config);

var body = {};
Expand All @@ -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',
Expand Down