box-node-sdk
Version:
Official SDK for Box Platform APIs
340 lines • 13.1 kB
JavaScript
import { deserializeArchivesV2025R0 } from '../schemas/v2025R0/archivesV2025R0.js';
import { deserializeArchiveV2025R0 } from '../schemas/v2025R0/archiveV2025R0.js';
import { BoxSdkError } from '../box/errors.js';
import { NetworkSession } from '../networking/network.js';
import { FetchOptions } from '../networking/fetchOptions.js';
import { prepareParams } from '../internal/utils.js';
import { toString } from '../internal/utils.js';
import { sdIsString } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
export 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;
}
}
}
export 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;
}
}
}
export 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;
}
}
}
export 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;
}
}
}
export 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;
}
}
}
export 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;
}
}
}
export 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;
}
}
}
export class ArchivesManager {
auth;
networkSession = new 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 = prepareParams({
['limit']: toString(queryParams.limit),
['marker']: toString(queryParams.marker),
});
const headersMap = prepareParams({
...{ ['box-version']: toString(headers.boxVersion) },
...headers.extraHeaders,
});
const response = await this.networkSession.networkClient.fetch(new 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 {
...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 = prepareParams({
...{ ['box-version']: toString(headers.boxVersion) },
...headers.extraHeaders,
});
const response = await this.networkSession.networkClient.fetch(new 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 {
...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).
*
* <Danger>
* This endpoint is currently unavailable. Please contact support for assistance.
* </Danger>
* @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 = prepareParams({
...{ ['box-version']: toString(headers.boxVersion) },
...headers.extraHeaders,
});
const response = await this.networkSession.networkClient.fetch(new FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/archives/', 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 = prepareParams({
...{ ['box-version']: toString(headers.boxVersion) },
...headers.extraHeaders,
});
const response = await this.networkSession.networkClient.fetch(new FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/archives/', toString(archiveId)),
method: 'PUT',
headers: headersMap,
data: serializeUpdateArchiveByIdV2025R0RequestBody(requestBody),
contentType: 'application/json',
responseFormat: 'json',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return {
...deserializeArchiveV2025R0(response.data),
rawData: response.data,
};
}
}
export function serializeCreateArchiveV2025R0RequestBody(val) {
return {
['name']: val.name,
['description']: val.description,
['storage_policy_id']: val.storagePolicyId,
};
}
export function deserializeCreateArchiveV2025R0RequestBody(val) {
if (!sdIsMap(val)) {
throw new BoxSdkError({
message: 'Expecting a map for "CreateArchiveV2025R0RequestBody"',
});
}
if (val.name == void 0) {
throw new BoxSdkError({
message: 'Expecting "name" of type "CreateArchiveV2025R0RequestBody" to be defined',
});
}
if (!sdIsString(val.name)) {
throw new BoxSdkError({
message: 'Expecting string for "name" of type "CreateArchiveV2025R0RequestBody"',
});
}
const name = val.name;
if (!(val.description == void 0) && !sdIsString(val.description)) {
throw new 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) &&
!sdIsString(val.storage_policy_id)) {
throw new 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,
};
}
export function serializeUpdateArchiveByIdV2025R0RequestBody(val) {
return { ['name']: val.name, ['description']: val.description };
}
export function deserializeUpdateArchiveByIdV2025R0RequestBody(val) {
if (!sdIsMap(val)) {
throw new BoxSdkError({
message: 'Expecting a map for "UpdateArchiveByIdV2025R0RequestBody"',
});
}
if (!(val.name == void 0) && !sdIsString(val.name)) {
throw new BoxSdkError({
message: 'Expecting string for "name" of type "UpdateArchiveByIdV2025R0RequestBody"',
});
}
const name = val.name == void 0 ? void 0 : val.name;
if (!(val.description == void 0) && !sdIsString(val.description)) {
throw new 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