UNPKG

box-node-sdk

Version:

Official SDK for Box Platform APIs

351 lines 14.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArchivesManager = exports.UpdateArchiveByIdV2025R0Headers = exports.DeleteArchiveByIdV2025R0Headers = exports.CreateArchiveV2025R0Headers = exports.GetArchivesV2025R0Headers = exports.UpdateArchiveByIdV2025R0Optionals = exports.DeleteArchiveByIdV2025R0Optionals = exports.CreateArchiveV2025R0Optionals = void 0; exports.serializeCreateArchiveV2025R0RequestBody = serializeCreateArchiveV2025R0RequestBody; exports.deserializeCreateArchiveV2025R0RequestBody = deserializeCreateArchiveV2025R0RequestBody; exports.serializeUpdateArchiveByIdV2025R0RequestBody = serializeUpdateArchiveByIdV2025R0RequestBody; exports.deserializeUpdateArchiveByIdV2025R0RequestBody = deserializeUpdateArchiveByIdV2025R0RequestBody; const archivesV2025R0_1 = require("../schemas/v2025R0/archivesV2025R0"); const archiveV2025R0_1 = require("../schemas/v2025R0/archiveV2025R0"); const errors_1 = require("../box/errors"); const network_1 = require("../networking/network"); const fetchOptions_1 = require("../networking/fetchOptions"); const utils_1 = require("../internal/utils"); const utils_2 = require("../internal/utils"); const json_1 = require("../serialization/json"); const json_2 = require("../serialization/json"); class CreateArchiveV2025R0Optionals { headers = new CreateArchiveV2025R0Headers({}); cancellationToken = void 0; constructor(fields) { if (fields.headers !== undefined) { this.headers = fields.headers; } if (fields.cancellationToken !== undefined) { this.cancellationToken = fields.cancellationToken; } } } exports.CreateArchiveV2025R0Optionals = CreateArchiveV2025R0Optionals; class DeleteArchiveByIdV2025R0Optionals { headers = new DeleteArchiveByIdV2025R0Headers({}); cancellationToken = void 0; constructor(fields) { if (fields.headers !== undefined) { this.headers = fields.headers; } if (fields.cancellationToken !== undefined) { this.cancellationToken = fields.cancellationToken; } } } exports.DeleteArchiveByIdV2025R0Optionals = DeleteArchiveByIdV2025R0Optionals; class UpdateArchiveByIdV2025R0Optionals { requestBody = {}; headers = new UpdateArchiveByIdV2025R0Headers({}); cancellationToken = void 0; constructor(fields) { if (fields.requestBody !== undefined) { this.requestBody = fields.requestBody; } if (fields.headers !== undefined) { this.headers = fields.headers; } if (fields.cancellationToken !== undefined) { this.cancellationToken = fields.cancellationToken; } } } exports.UpdateArchiveByIdV2025R0Optionals = UpdateArchiveByIdV2025R0Optionals; class GetArchivesV2025R0Headers { /** * Version header. */ boxVersion = '2025.0'; /** * Extra headers that will be included in the HTTP request. */ extraHeaders = {}; constructor(fields) { if (fields.boxVersion !== undefined) { this.boxVersion = fields.boxVersion; } if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } exports.GetArchivesV2025R0Headers = GetArchivesV2025R0Headers; class CreateArchiveV2025R0Headers { /** * Version header. */ boxVersion = '2025.0'; /** * Extra headers that will be included in the HTTP request. */ extraHeaders = {}; constructor(fields) { if (fields.boxVersion !== undefined) { this.boxVersion = fields.boxVersion; } if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } exports.CreateArchiveV2025R0Headers = CreateArchiveV2025R0Headers; class DeleteArchiveByIdV2025R0Headers { /** * Version header. */ boxVersion = '2025.0'; /** * Extra headers that will be included in the HTTP request. */ extraHeaders = {}; constructor(fields) { if (fields.boxVersion !== undefined) { this.boxVersion = fields.boxVersion; } if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } exports.DeleteArchiveByIdV2025R0Headers = DeleteArchiveByIdV2025R0Headers; class UpdateArchiveByIdV2025R0Headers { /** * Version header. */ boxVersion = '2025.0'; /** * Extra headers that will be included in the HTTP request. */ extraHeaders = {}; constructor(fields) { if (fields.boxVersion !== undefined) { this.boxVersion = fields.boxVersion; } if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } exports.UpdateArchiveByIdV2025R0Headers = UpdateArchiveByIdV2025R0Headers; class ArchivesManager { auth; networkSession = new network_1.NetworkSession({}); constructor(fields) { if (fields.auth !== undefined) { this.auth = fields.auth; } if (fields.networkSession !== undefined) { this.networkSession = fields.networkSession; } } /** * Retrieves archives for an enterprise. * * To learn more about the archive APIs, see the [Archive API Guide](https://developer.box.com/guides/archives). * @param {GetArchivesV2025R0QueryParams} queryParams Query parameters of getArchivesV2025R0 method * @param {GetArchivesV2025R0HeadersInput} headersInput Headers of getArchivesV2025R0 method * @param {CancellationToken} cancellationToken Token used for request cancellation. * @returns {Promise<ArchivesV2025R0>} */ async getArchivesV2025R0(queryParams = {}, headersInput = new GetArchivesV2025R0Headers({}), cancellationToken) { const headers = new GetArchivesV2025R0Headers({ boxVersion: headersInput.boxVersion, extraHeaders: headersInput.extraHeaders, }); const queryParamsMap = (0, utils_1.prepareParams)({ ['limit']: (0, utils_2.toString)(queryParams.limit), ['marker']: (0, utils_2.toString)(queryParams.marker), }); const headersMap = (0, utils_1.prepareParams)({ ...{ ['box-version']: (0, utils_2.toString)(headers.boxVersion) }, ...headers.extraHeaders, }); const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/archives'), method: 'GET', params: queryParamsMap, headers: headersMap, responseFormat: 'json', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return { ...(0, archivesV2025R0_1.deserializeArchivesV2025R0)(response.data), rawData: response.data, }; } /** * Creates an archive. * * To learn more about the archive APIs, see the [Archive API Guide](https://developer.box.com/guides/archives). * @param {CreateArchiveV2025R0RequestBody} requestBody Request body of createArchiveV2025R0 method * @param {CreateArchiveV2025R0OptionalsInput} optionalsInput * @returns {Promise<ArchiveV2025R0>} */ async createArchiveV2025R0(requestBody, optionalsInput = {}) { const optionals = new CreateArchiveV2025R0Optionals({ headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, }); const headers = optionals.headers; const cancellationToken = optionals.cancellationToken; const headersMap = (0, utils_1.prepareParams)({ ...{ ['box-version']: (0, utils_2.toString)(headers.boxVersion) }, ...headers.extraHeaders, }); const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/archives'), method: 'POST', headers: headersMap, data: serializeCreateArchiveV2025R0RequestBody(requestBody), contentType: 'application/json', responseFormat: 'json', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return { ...(0, archiveV2025R0_1.deserializeArchiveV2025R0)(response.data), rawData: response.data, }; } /** * Permanently deletes an archive. * * To learn more about the archive APIs, see the [Archive API Guide](https://developer.box.com/guides/archives). * @param {string} archiveId The ID of the archive. Example: "982312" * @param {DeleteArchiveByIdV2025R0OptionalsInput} optionalsInput * @returns {Promise<undefined>} */ async deleteArchiveByIdV2025R0(archiveId, optionalsInput = {}) { const optionals = new DeleteArchiveByIdV2025R0Optionals({ headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, }); const headers = optionals.headers; const cancellationToken = optionals.cancellationToken; const headersMap = (0, utils_1.prepareParams)({ ...{ ['box-version']: (0, utils_2.toString)(headers.boxVersion) }, ...headers.extraHeaders, }); const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/archives/', (0, utils_2.toString)(archiveId)), method: 'DELETE', headers: headersMap, responseFormat: 'no_content', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return void 0; } /** * Updates an archive. * * To learn more about the archive APIs, see the [Archive API Guide](https://developer.box.com/guides/archives). * @param {string} archiveId The ID of the archive. Example: "982312" * @param {UpdateArchiveByIdV2025R0OptionalsInput} optionalsInput * @returns {Promise<ArchiveV2025R0>} */ async updateArchiveByIdV2025R0(archiveId, optionalsInput = {}) { const optionals = new UpdateArchiveByIdV2025R0Optionals({ requestBody: optionalsInput.requestBody, headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, }); const requestBody = optionals.requestBody; const headers = optionals.headers; const cancellationToken = optionals.cancellationToken; const headersMap = (0, utils_1.prepareParams)({ ...{ ['box-version']: (0, utils_2.toString)(headers.boxVersion) }, ...headers.extraHeaders, }); const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/archives/', (0, utils_2.toString)(archiveId)), method: 'PUT', headers: headersMap, data: serializeUpdateArchiveByIdV2025R0RequestBody(requestBody), contentType: 'application/json', responseFormat: 'json', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return { ...(0, archiveV2025R0_1.deserializeArchiveV2025R0)(response.data), rawData: response.data, }; } } exports.ArchivesManager = ArchivesManager; function serializeCreateArchiveV2025R0RequestBody(val) { return { ['name']: val.name, ['description']: val.description, ['storage_policy_id']: val.storagePolicyId, }; } function deserializeCreateArchiveV2025R0RequestBody(val) { if (!(0, json_2.sdIsMap)(val)) { throw new errors_1.BoxSdkError({ message: 'Expecting a map for "CreateArchiveV2025R0RequestBody"', }); } if (val.name == void 0) { throw new errors_1.BoxSdkError({ message: 'Expecting "name" of type "CreateArchiveV2025R0RequestBody" to be defined', }); } if (!(0, json_1.sdIsString)(val.name)) { throw new errors_1.BoxSdkError({ message: 'Expecting string for "name" of type "CreateArchiveV2025R0RequestBody"', }); } const name = val.name; if (!(val.description == void 0) && !(0, json_1.sdIsString)(val.description)) { throw new errors_1.BoxSdkError({ message: 'Expecting string for "description" of type "CreateArchiveV2025R0RequestBody"', }); } const description = val.description == void 0 ? void 0 : val.description; if (!(val.storage_policy_id == void 0) && !(0, json_1.sdIsString)(val.storage_policy_id)) { throw new errors_1.BoxSdkError({ message: 'Expecting string for "storage_policy_id" of type "CreateArchiveV2025R0RequestBody"', }); } const storagePolicyId = val.storage_policy_id == void 0 ? void 0 : val.storage_policy_id; return { name: name, description: description, storagePolicyId: storagePolicyId, }; } function serializeUpdateArchiveByIdV2025R0RequestBody(val) { return { ['name']: val.name, ['description']: val.description }; } function deserializeUpdateArchiveByIdV2025R0RequestBody(val) { if (!(0, json_2.sdIsMap)(val)) { throw new errors_1.BoxSdkError({ message: 'Expecting a map for "UpdateArchiveByIdV2025R0RequestBody"', }); } if (!(val.name == void 0) && !(0, json_1.sdIsString)(val.name)) { throw new errors_1.BoxSdkError({ message: 'Expecting string for "name" of type "UpdateArchiveByIdV2025R0RequestBody"', }); } const name = val.name == void 0 ? void 0 : val.name; if (!(val.description == void 0) && !(0, json_1.sdIsString)(val.description)) { throw new errors_1.BoxSdkError({ message: 'Expecting string for "description" of type "UpdateArchiveByIdV2025R0RequestBody"', }); } const description = val.description == void 0 ? void 0 : val.description; return { name: name, description: description, }; } //# sourceMappingURL=archives.js.map