UNPKG

@datocms/cma-client

Version:
178 lines 5.32 kB
import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; export default class AccessToken extends BaseResource { /** * Create a new API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/create * * @throws {ApiError} * @throws {TimeoutError} */ create(body) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'access_token', attributes: [ 'name', 'can_access_cda', 'can_access_cda_preview', 'can_access_cma', ], relationships: ['role'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Create a new API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/create * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate(body) { return this.client.request({ method: 'POST', url: '/access_tokens', body, }); } /** * Update an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/update * * @throws {ApiError} * @throws {TimeoutError} */ update(accessTokenId, body) { return this.rawUpdate(Utils.toId(accessTokenId), Utils.serializeRequestBody(body, { id: Utils.toId(accessTokenId), type: 'access_token', attributes: [ 'name', 'can_access_cda', 'can_access_cda_preview', 'can_access_cma', ], relationships: ['role'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Update an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(accessTokenId, body) { return this.client.request({ method: 'PUT', url: `/access_tokens/${accessTokenId}`, body, }); } /** * List all API tokens * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/instances * * @throws {ApiError} * @throws {TimeoutError} */ list() { return this.rawList().then((body) => Utils.deserializeResponseBody(body)); } /** * List all API tokens * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList() { return this.client.request({ method: 'GET', url: '/access_tokens', }); } /** * Retrieve an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/self * * @throws {ApiError} * @throws {TimeoutError} */ find(accessTokenId) { return this.rawFind(Utils.toId(accessTokenId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(accessTokenId) { return this.client.request({ method: 'GET', url: `/access_tokens/${accessTokenId}`, }); } /** * Rotate API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/regenerate_token * * @throws {ApiError} * @throws {TimeoutError} */ regenerateToken(accessTokenId) { return this.rawRegenerateToken(Utils.toId(accessTokenId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Rotate API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/regenerate_token * * @throws {ApiError} * @throws {TimeoutError} */ rawRegenerateToken(accessTokenId) { return this.client.request({ method: 'POST', url: `/access_tokens/${accessTokenId}/regenerate_token`, }); } /** * Delete an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(accessTokenId, queryParams) { return this.rawDestroy(Utils.toId(accessTokenId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Delete an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(accessTokenId, queryParams) { return this.client.request({ method: 'DELETE', url: `/access_tokens/${accessTokenId}`, queryParams, }); } } AccessToken.TYPE = 'access_token'; //# sourceMappingURL=AccessToken.js.map