UNPKG

@datocms/cma-client

Version:
211 lines 7 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; var AccessToken = /** @class */ (function (_super) { __extends(AccessToken, _super); function AccessToken() { return _super !== null && _super.apply(this, arguments) || this; } /** * Create a new API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/create * * @throws {ApiError} * @throws {TimeoutError} */ AccessToken.prototype.create = function (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(function (body) { return 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} */ AccessToken.prototype.rawCreate = function (body) { return this.client.request({ method: 'POST', url: '/access_tokens', body: body, }); }; /** * Update an API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/update * * @throws {ApiError} * @throws {TimeoutError} */ AccessToken.prototype.update = function (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(function (body) { return 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} */ AccessToken.prototype.rawUpdate = function (accessTokenId, body) { return this.client.request({ method: 'PUT', url: "/access_tokens/".concat(accessTokenId), body: body, }); }; /** * List all API tokens * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/instances * * @throws {ApiError} * @throws {TimeoutError} */ AccessToken.prototype.list = function () { return this.rawList().then(function (body) { return 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} */ AccessToken.prototype.rawList = function () { 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} */ AccessToken.prototype.find = function (accessTokenId) { return this.rawFind(Utils.toId(accessTokenId)).then(function (body) { return 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} */ AccessToken.prototype.rawFind = function (accessTokenId) { return this.client.request({ method: 'GET', url: "/access_tokens/".concat(accessTokenId), }); }; /** * Rotate API token * * Read more: https://www.datocms.com/docs/content-management-api/resources/access-token/regenerate_token * * @throws {ApiError} * @throws {TimeoutError} */ AccessToken.prototype.regenerateToken = function (accessTokenId) { return this.rawRegenerateToken(Utils.toId(accessTokenId)).then(function (body) { return 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} */ AccessToken.prototype.rawRegenerateToken = function (accessTokenId) { return this.client.request({ method: 'POST', url: "/access_tokens/".concat(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} */ AccessToken.prototype.destroy = function (accessTokenId, queryParams) { return this.rawDestroy(Utils.toId(accessTokenId), queryParams).then(function (body) { return 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} */ AccessToken.prototype.rawDestroy = function (accessTokenId, queryParams) { return this.client.request({ method: 'DELETE', url: "/access_tokens/".concat(accessTokenId), queryParams: queryParams, }); }; AccessToken.TYPE = 'access_token'; return AccessToken; }(BaseResource)); export default AccessToken; //# sourceMappingURL=AccessToken.js.map