box-node-sdk
Version:
Official SDK for Box Platform APIs
156 lines • 7.82 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryManager = exports.CreateQueryInsightV2026R0Headers = exports.CreateQueryV2026R0Headers = exports.CreateQueryInsightV2026R0Optionals = exports.CreateQueryV2026R0Optionals = void 0;
const queryResultsV2026R0_1 = require("../schemas/v2026R0/queryResultsV2026R0.js");
const queryRequestBodyV2026R0_1 = require("../schemas/v2026R0/queryRequestBodyV2026R0.js");
const queryInsightsV2026R0_1 = require("../schemas/v2026R0/queryInsightsV2026R0.js");
const queryInsightsRequestBodyV2026R0_1 = require("../schemas/v2026R0/queryInsightsRequestBodyV2026R0.js");
const network_1 = require("../networking/network.js");
const fetchOptions_1 = require("../networking/fetchOptions.js");
const utils_1 = require("../internal/utils.js");
const utils_2 = require("../internal/utils.js");
class CreateQueryV2026R0Optionals {
constructor(fields) {
this.headers = new CreateQueryV2026R0Headers({});
this.cancellationToken = void 0;
if (fields.headers !== undefined) {
this.headers = fields.headers;
}
if (fields.cancellationToken !== undefined) {
this.cancellationToken = fields.cancellationToken;
}
}
}
exports.CreateQueryV2026R0Optionals = CreateQueryV2026R0Optionals;
class CreateQueryInsightV2026R0Optionals {
constructor(fields) {
this.headers = new CreateQueryInsightV2026R0Headers({});
this.cancellationToken = void 0;
if (fields.headers !== undefined) {
this.headers = fields.headers;
}
if (fields.cancellationToken !== undefined) {
this.cancellationToken = fields.cancellationToken;
}
}
}
exports.CreateQueryInsightV2026R0Optionals = CreateQueryInsightV2026R0Optionals;
class CreateQueryV2026R0Headers {
constructor(fields) {
/**
* Version header. */
this.boxVersion = '2026.0';
/**
* Extra headers that will be included in the HTTP request. */
this.extraHeaders = {};
if (fields.boxVersion !== undefined) {
this.boxVersion = fields.boxVersion;
}
if (fields.extraHeaders !== undefined) {
this.extraHeaders = fields.extraHeaders;
}
}
}
exports.CreateQueryV2026R0Headers = CreateQueryV2026R0Headers;
class CreateQueryInsightV2026R0Headers {
constructor(fields) {
/**
* Version header. */
this.boxVersion = '2026.0';
/**
* Extra headers that will be included in the HTTP request. */
this.extraHeaders = {};
if (fields.boxVersion !== undefined) {
this.boxVersion = fields.boxVersion;
}
if (fields.extraHeaders !== undefined) {
this.extraHeaders = fields.extraHeaders;
}
}
}
exports.CreateQueryInsightV2026R0Headers = CreateQueryInsightV2026R0Headers;
class QueryManager {
constructor(fields) {
this.networkSession = new network_1.NetworkSession({});
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>}
*/
createQueryV2026R0(requestBody_1) {
return __awaiter(this, arguments, void 0, function* (requestBody, optionalsInput = {}) {
const optionals = new CreateQueryV2026R0Optionals({
headers: optionalsInput.headers,
cancellationToken: optionalsInput.cancellationToken,
});
const headers = optionals.headers;
const cancellationToken = optionals.cancellationToken;
const headersMap = (0, utils_1.prepareParams)(Object.assign({ ['box-version']: (0, utils_2.toString)(headers.boxVersion) }, headers.extraHeaders));
const response = yield this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/query'),
method: 'POST',
headers: headersMap,
data: (0, queryRequestBodyV2026R0_1.serializeQueryRequestBodyV2026R0)(requestBody),
contentType: 'application/json',
responseFormat: 'json',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return Object.assign(Object.assign({}, (0, queryResultsV2026R0_1.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>}
*/
createQueryInsightV2026R0(requestBody_1) {
return __awaiter(this, arguments, void 0, function* (requestBody, optionalsInput = {}) {
const optionals = new CreateQueryInsightV2026R0Optionals({
headers: optionalsInput.headers,
cancellationToken: optionalsInput.cancellationToken,
});
const headers = optionals.headers;
const cancellationToken = optionals.cancellationToken;
const headersMap = (0, utils_1.prepareParams)(Object.assign({ ['box-version']: (0, utils_2.toString)(headers.boxVersion) }, headers.extraHeaders));
const response = yield this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/query_insights'),
method: 'POST',
headers: headersMap,
data: (0, queryInsightsRequestBodyV2026R0_1.serializeQueryInsightsRequestBodyV2026R0)(requestBody),
contentType: 'application/json',
responseFormat: 'json',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return Object.assign(Object.assign({}, (0, queryInsightsV2026R0_1.deserializeQueryInsightsV2026R0)(response.data)), { rawData: response.data });
});
}
}
exports.QueryManager = QueryManager;
//# sourceMappingURL=query.js.map