UNPKG

@datocms/cma-client

Version:
169 lines 5.28 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Utils = __importStar(require("@datocms/rest-client-utils")); const BaseResource_1 = __importDefault(require("../../BaseResource")); class User extends BaseResource_1.default { /** * Update a collaborator * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/update * * @throws {ApiError} * @throws {TimeoutError} */ update(userId, body) { return this.rawUpdate(Utils.toId(userId), Utils.serializeRequestBody(body, { id: Utils.toId(userId), type: 'user', attributes: ['is_active'], relationships: ['role'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Update a collaborator * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(userId, body) { return this.client.request({ method: 'PUT', url: `/users/${userId}`, body, }); } /** * List all collaborators * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/instances * * @throws {ApiError} * @throws {TimeoutError} */ list() { return this.rawList().then((body) => Utils.deserializeResponseBody(body)); } /** * List all collaborators * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList() { return this.client.request({ method: 'GET', url: '/users', }); } /** * Retrieve a collaborator * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/self * * @throws {ApiError} * @throws {TimeoutError} */ find(userId, queryParams) { return this.rawFind(Utils.toId(userId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve a collaborator * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(userId, queryParams) { return this.client.request({ method: 'GET', url: `/users/${userId}`, queryParams, }); } /** * Retrieve current signed-in user * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/me * * @throws {ApiError} * @throws {TimeoutError} */ findMe(queryParams) { return this.rawFindMe(queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve current signed-in user * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/me * * @throws {ApiError} * @throws {TimeoutError} */ rawFindMe(queryParams) { return this.client.request({ method: 'GET', url: '/users/me', queryParams, }); } /** * Delete a collaborator * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(userId, queryParams) { return this.rawDestroy(Utils.toId(userId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Delete a collaborator * * Read more: https://www.datocms.com/docs/content-management-api/resources/user/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(userId, queryParams) { return this.client.request({ method: 'DELETE', url: `/users/${userId}`, queryParams, }); } } exports.default = User; User.TYPE = 'user'; //# sourceMappingURL=User.js.map