box-node-sdk
Version:
Official SDK for Box Platform APIs
148 lines • 6.04 kB
JavaScript
import { deserializeQueryResultsV2026R0 } from '../schemas/v2026R0/queryResultsV2026R0.js';
import { serializeQueryRequestBodyV2026R0 } from '../schemas/v2026R0/queryRequestBodyV2026R0.js';
import { deserializeQueryInsightsV2026R0 } from '../schemas/v2026R0/queryInsightsV2026R0.js';
import { serializeQueryInsightsRequestBodyV2026R0 } from '../schemas/v2026R0/queryInsightsRequestBodyV2026R0.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';
export class CreateQueryV2026R0Optionals {
headers = new CreateQueryV2026R0Headers({});
cancellationToken = void 0;
constructor(fields) {
if (fields.headers !== undefined) {
this.headers = fields.headers;
}
if (fields.cancellationToken !== undefined) {
this.cancellationToken = fields.cancellationToken;
}
}
}
export class CreateQueryInsightV2026R0Optionals {
headers = new CreateQueryInsightV2026R0Headers({});
cancellationToken = void 0;
constructor(fields) {
if (fields.headers !== undefined) {
this.headers = fields.headers;
}
if (fields.cancellationToken !== undefined) {
this.cancellationToken = fields.cancellationToken;
}
}
}
export class CreateQueryV2026R0Headers {
/**
* Version header. */
boxVersion = '2026.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 CreateQueryInsightV2026R0Headers {
/**
* Version header. */
boxVersion = '2026.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 QueryManager {
auth;
networkSession = new NetworkSession({});
constructor(fields) {
if (fields.auth !== undefined) {
this.auth = fields.auth;
}
if (fields.networkSession !== undefined) {
this.networkSession = fields.networkSession;
}
}
/**
* Runs a query to discover Box items using a logical predicate that can filter
* across item fields and metadata templates. Results can be sorted, paginated,
* and shaped to include additional item or metadata fields.
* @param {QueryRequestBodyV2026R0} requestBody Request body of createQueryV2026R0 method
* @param {CreateQueryV2026R0OptionalsInput} optionalsInput
* @returns {Promise<QueryResultsV2026R0>}
*/
async createQueryV2026R0(requestBody, optionalsInput = {}) {
const optionals = new CreateQueryV2026R0Optionals({
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/query'),
method: 'POST',
headers: headersMap,
data: serializeQueryRequestBodyV2026R0(requestBody),
contentType: 'application/json',
responseFormat: 'json',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return {
...deserializeQueryResultsV2026R0(response.data),
rawData: response.data,
};
}
/**
* Computes aggregated metrics over Box items matching a query predicate.
* Filters are applied first, followed by optional grouping, after which the
* requested metrics (such as `sum`, `avg`, `min`, `max`, and `count`) are
* computed for each resulting group or over the entire filtered dataset.
* @param {QueryInsightsRequestBodyV2026R0} requestBody Request body of createQueryInsightV2026R0 method
* @param {CreateQueryInsightV2026R0OptionalsInput} optionalsInput
* @returns {Promise<QueryInsightsV2026R0>}
*/
async createQueryInsightV2026R0(requestBody, optionalsInput = {}) {
const optionals = new CreateQueryInsightV2026R0Optionals({
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/query_insights'),
method: 'POST',
headers: headersMap,
data: serializeQueryInsightsRequestBodyV2026R0(requestBody),
contentType: 'application/json',
responseFormat: 'json',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return {
...deserializeQueryInsightsV2026R0(response.data),
rawData: response.data,
};
}
}
//# sourceMappingURL=query.js.map