auth0
Version:
Auth0 Node.js SDK for the Management API v2.
250 lines (249 loc) • 16.8 kB
JavaScript
;
// This file was auto-generated by Fern from our API Definition.
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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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.LogsClient = void 0;
const BaseClient_js_1 = require("../../../../BaseClient.js");
const core = __importStar(require("../../../../core/index.js"));
const headers_js_1 = require("../../../../core/headers.js");
const environments = __importStar(require("../../../../environments.js"));
const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js");
const errors = __importStar(require("../../../../errors/index.js"));
const Management = __importStar(require("../../../index.js"));
class LogsClient {
constructor(options) {
this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
}
/**
* Retrieve log entries that match the specified search criteria (or all log entries if no criteria specified).
*
* Set custom search criteria using the <code>q</code> parameter, or search from a specific log ID (<i>"search from checkpoint"</i>).
*
* For more information on all possible event types, their respective acronyms, and descriptions, see <a href="https://auth0.com/docs/logs/log-event-type-codes">Log Event Type Codes</a>.
*
* <h5>To set custom search criteria, use the following parameters:</h5>
*
* <ul>
* <li><b>q:</b> Search Criteria using <a href="https://auth0.com/docs/logs/log-search-query-syntax">Query String Syntax</a></li>
* <li><b>page:</b> Page index of the results to return. First page is 0.</li>
* <li><b>per_page:</b> Number of results per page.</li>
* <li><b>sort:</b> Field to use for sorting appended with `:1` for ascending and `:-1` for descending. e.g. `date:-1`</li>
* <li><b>fields:</b> Comma-separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields.</li>
* <li><b>include_fields:</b> Whether specified fields are to be included (true) or excluded (false).</li>
* <li><b>include_totals:</b> Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). <b>Deprecated:</b> this field is deprecated and should be removed from use. See <a href="https://auth0.com/docs/product-lifecycle/deprecations-and-migrations/migrate-to-tenant-log-search-v3#pagination">Search Engine V3 Breaking Changes</a></li>
* </ul>
*
* For more information on the list of fields that can be used in <code>fields</code> and <code>sort</code>, see <a href="https://auth0.com/docs/logs/log-search-query-syntax#searchable-fields">Searchable Fields</a>.
*
* Auth0 <a href="https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#limitations">limits the number of logs</a> you can return by search criteria to 100 logs per request. Furthermore, you may paginate only through 1,000 search results. If you exceed this threshold, please redefine your search or use the <a href="https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#retrieve-logs-by-checkpoint">get logs by checkpoint method</a>.
*
* <h5>To search from a checkpoint log ID, use the following parameters:</h5>
* <ul>
* <li><b>from:</b> Log Event ID from which to start retrieving logs. You can limit the number of logs returned using the <code>take</code> parameter. If you use <code>from</code> at the same time as <code>q</code>, <code>from</code> takes precedence and <code>q</code> is ignored.</li>
* <li><b>take:</b> Number of entries to retrieve when using the <code>from</code> parameter.</li>
* </ul>
*
* <strong>Important:</strong> When fetching logs from a checkpoint log ID, any parameter other than <code>from</code> and <code>take</code> will be ignored, and date ordering is not guaranteed.
*
* @param {Management.ListLogsRequestParameters} request
* @param {LogsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Management.BadRequestError}
* @throws {@link Management.UnauthorizedError}
* @throws {@link Management.ForbiddenError}
* @throws {@link Management.TooManyRequestsError}
*
* @example
* await client.logs.list({
* page: 1,
* per_page: 1,
* sort: "sort",
* fields: "fields",
* include_fields: true,
* include_totals: true,
* search: "search"
* })
*/
list() {
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
const { page = 0, per_page: perPage = 50, sort, fields, include_fields: includeFields, include_totals: includeTotals = true, search, } = request;
const _queryParams = {};
if (page !== undefined) {
_queryParams["page"] = (_a = page === null || page === void 0 ? void 0 : page.toString()) !== null && _a !== void 0 ? _a : null;
}
if (perPage !== undefined) {
_queryParams["per_page"] = (_b = perPage === null || perPage === void 0 ? void 0 : perPage.toString()) !== null && _b !== void 0 ? _b : null;
}
if (sort !== undefined) {
_queryParams["sort"] = sort;
}
if (fields !== undefined) {
_queryParams["fields"] = fields;
}
if (includeFields !== undefined) {
_queryParams["include_fields"] = (_c = includeFields === null || includeFields === void 0 ? void 0 : includeFields.toString()) !== null && _c !== void 0 ? _c : null;
}
if (includeTotals !== undefined) {
_queryParams["include_totals"] = (_d = includeTotals === null || includeTotals === void 0 ? void 0 : includeTotals.toString()) !== null && _d !== void 0 ? _d : null;
}
if (search !== undefined) {
_queryParams["search"] = search;
}
const _authRequest = yield this._options.authProvider.getAuthRequest();
let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_e = this._options) === null || _e === void 0 ? void 0 : _e.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_f = this._options.fetcher) !== null && _f !== void 0 ? _f : core.fetcher)({
url: core.url.join((_h = (_g = (yield core.Supplier.get(this._options.baseUrl))) !== null && _g !== void 0 ? _g : (yield core.Supplier.get(this._options.environment))) !== null && _h !== void 0 ? _h : environments.ManagementEnvironment.Default, "logs"),
method: "GET",
headers: _headers,
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
timeoutMs: ((_l = (_j = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _j !== void 0 ? _j : (_k = this._options) === null || _k === void 0 ? void 0 : _k.timeoutInSeconds) !== null && _l !== void 0 ? _l : 60) * 1000,
maxRetries: (_m = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _m !== void 0 ? _m : (_o = this._options) === null || _o === void 0 ? void 0 : _o.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_p = this._options) === null || _p === void 0 ? void 0 : _p.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: _response.body,
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Management.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse);
case 403:
throw new Management.ForbiddenError(_response.error.body, _response.rawResponse);
case 429:
throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse);
default:
throw new errors.ManagementError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/logs");
}));
let _offset = (request === null || request === void 0 ? void 0 : request.page) != null ? request === null || request === void 0 ? void 0 : request.page : 0;
const dataWithRawResponse = yield list(request).withRawResponse();
return new core.Page({
response: dataWithRawResponse.data,
rawResponse: dataWithRawResponse.rawResponse,
hasNextPage: (response) => { var _a, _b; return ((_a = response === null || response === void 0 ? void 0 : response.logs) !== null && _a !== void 0 ? _a : []).length >= Math.floor((_b = request === null || request === void 0 ? void 0 : request.per_page) !== null && _b !== void 0 ? _b : 50); },
getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.logs) !== null && _a !== void 0 ? _a : []; },
loadPage: (_response) => {
_offset += 1;
return list(core.setObjectProperty(request, "page", _offset));
},
});
});
}
/**
* Retrieve an individual log event.
*
* @param {string} id - log_id of the log to retrieve.
* @param {LogsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Management.BadRequestError}
* @throws {@link Management.UnauthorizedError}
* @throws {@link Management.ForbiddenError}
* @throws {@link Management.NotFoundError}
* @throws {@link Management.TooManyRequestsError}
*
* @example
* await client.logs.get("id")
*/
get(id, requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__get(id, requestOptions));
}
__get(id, requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const _authRequest = yield this._options.authProvider.getAuthRequest();
let _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `logs/${core.url.encodePathParam(id)}`),
method: "GET",
headers: _headers,
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body, rawResponse: _response.rawResponse };
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Management.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse);
case 403:
throw new Management.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Management.NotFoundError(_response.error.body, _response.rawResponse);
case 429:
throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse);
default:
throw new errors.ManagementError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/logs/{id}");
});
}
}
exports.LogsClient = LogsClient;