2025-08-04 18:41:00 -04:00

2522 lines
117 KiB
JavaScript

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// builds/node.ts
var node_exports = {};
__export(node_exports, {
apiClientVersion: () => apiClientVersion,
searchClient: () => searchClient
});
module.exports = __toCommonJS(node_exports);
var import_node_crypto = require("crypto");
var import_requester_node_http = require("@algolia/requester-node-http");
var import_client_common2 = require("@algolia/client-common");
// src/searchClient.ts
var import_client_common = require("@algolia/client-common");
var apiClientVersion = "5.35.0";
function getDefaultHosts(appId) {
return [
{
url: `${appId}-dsn.algolia.net`,
accept: "read",
protocol: "https"
},
{
url: `${appId}.algolia.net`,
accept: "write",
protocol: "https"
}
].concat(
(0, import_client_common.shuffle)([
{
url: `${appId}-1.algolianet.com`,
accept: "readWrite",
protocol: "https"
},
{
url: `${appId}-2.algolianet.com`,
accept: "readWrite",
protocol: "https"
},
{
url: `${appId}-3.algolianet.com`,
accept: "readWrite",
protocol: "https"
}
])
);
}
function createSearchClient({
appId: appIdOption,
apiKey: apiKeyOption,
authMode,
algoliaAgents,
...options
}) {
const auth = (0, import_client_common.createAuth)(appIdOption, apiKeyOption, authMode);
const transporter = (0, import_client_common.createTransporter)({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: (0, import_client_common.getAlgoliaAgent)({
algoliaAgents,
client: "Search",
version: apiClientVersion
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
});
return {
transporter,
/**
* The `appId` currently in use.
*/
appId: appIdOption,
/**
* The `apiKey` currently in use.
*/
apiKey: apiKeyOption,
/**
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
*/
clearCache() {
return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
},
/**
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
*/
get _ua() {
return transporter.algoliaAgent.value;
},
/**
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
*
* @param segment - The algolia agent (user-agent) segment to add.
* @param version - The version of the agent.
*/
addAlgoliaAgent(segment, version) {
transporter.algoliaAgent.add({ segment, version });
},
/**
* Helper method to switch the API key used to authenticate the requests.
*
* @param params - Method params.
* @param params.apiKey - The new API Key to use.
*/
setClientApiKey({ apiKey }) {
if (!authMode || authMode === "WithinHeaders") {
transporter.baseHeaders["x-algolia-api-key"] = apiKey;
} else {
transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
}
},
/**
* Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
*
* @summary Helper method that waits for a task to be published (completed).
* @param waitForTaskOptions - The `waitForTaskOptions` object.
* @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
* @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
* @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
* @param waitForTaskOptions.timeout - The function to decide how long to wait between retries.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
waitForTask({
indexName,
taskID,
maxRetries = 50,
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
}, requestOptions) {
let retryCount = 0;
return (0, import_client_common.createIterablePromise)({
func: () => this.getTask({ indexName, taskID }, requestOptions),
validate: (response) => response.status === "published",
aggregator: () => retryCount += 1,
error: {
validate: () => retryCount >= maxRetries,
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`
},
timeout: () => timeout(retryCount)
});
},
/**
* Helper: Wait for an application-level task to complete for a given `taskID`.
*
* @summary Helper method that waits for a task to be published (completed).
* @param waitForAppTaskOptions - The `waitForTaskOptions` object.
* @param waitForAppTaskOptions.taskID - The `taskID` returned in the method response.
* @param waitForAppTaskOptions.maxRetries - The maximum number of retries. 50 by default.
* @param waitForAppTaskOptions.timeout - The function to decide how long to wait between retries.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
waitForAppTask({
taskID,
maxRetries = 50,
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
}, requestOptions) {
let retryCount = 0;
return (0, import_client_common.createIterablePromise)({
func: () => this.getAppTask({ taskID }, requestOptions),
validate: (response) => response.status === "published",
aggregator: () => retryCount += 1,
error: {
validate: () => retryCount >= maxRetries,
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`
},
timeout: () => timeout(retryCount)
});
},
/**
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
*
* @summary Helper method that waits for an API key task to be processed.
* @param waitForApiKeyOptions - The `waitForApiKeyOptions` object.
* @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
* @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
* @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
* @param waitForApiKeyOptions.maxRetries - The maximum number of retries. 50 by default.
* @param waitForApiKeyOptions.timeout - The function to decide how long to wait between retries.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
*/
waitForApiKey({
operation,
key,
apiKey,
maxRetries = 50,
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
}, requestOptions) {
let retryCount = 0;
const baseIteratorOptions = {
aggregator: () => retryCount += 1,
error: {
validate: () => retryCount >= maxRetries,
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`
},
timeout: () => timeout(retryCount)
};
if (operation === "update") {
if (!apiKey) {
throw new Error("`apiKey` is required when waiting for an `update` operation.");
}
return (0, import_client_common.createIterablePromise)({
...baseIteratorOptions,
func: () => this.getApiKey({ key }, requestOptions),
validate: (response) => {
for (const field of Object.keys(apiKey)) {
const value = apiKey[field];
const resValue = response[field];
if (Array.isArray(value) && Array.isArray(resValue)) {
if (value.length !== resValue.length || value.some((v, index) => v !== resValue[index])) {
return false;
}
} else if (value !== resValue) {
return false;
}
}
return true;
}
});
}
return (0, import_client_common.createIterablePromise)({
...baseIteratorOptions,
func: () => this.getApiKey({ key }, requestOptions).catch((error) => {
if (error.status === 404) {
return void 0;
}
throw error;
}),
validate: (response) => operation === "add" ? response !== void 0 : response === void 0
});
},
/**
* Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
*
* @summary Helper method that iterates on the `browse` method.
* @param browseObjects - The `browseObjects` object.
* @param browseObjects.indexName - The index in which to perform the request.
* @param browseObjects.browseParams - The `browse` parameters.
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is no `cursor` in the response.
* @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
*/
browseObjects({ indexName, browseParams, ...browseObjectsOptions }, requestOptions) {
return (0, import_client_common.createIterablePromise)({
func: (previousResponse) => {
return this.browse(
{
indexName,
browseParams: {
cursor: previousResponse ? previousResponse.cursor : void 0,
hitsPerPage: 1e3,
...browseParams
}
},
requestOptions
);
},
validate: (response) => response.cursor === void 0,
...browseObjectsOptions
});
},
/**
* Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
*
* @summary Helper method that iterates on the `searchRules` method.
* @param browseRules - The `browseRules` object.
* @param browseRules.indexName - The index in which to perform the request.
* @param browseRules.searchRulesParams - The `searchRules` method parameters.
* @param browseRules.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
* @param browseRules.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
*/
browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
const params = {
...searchRulesParams,
hitsPerPage: (searchRulesParams == null ? void 0 : searchRulesParams.hitsPerPage) || 1e3
};
return (0, import_client_common.createIterablePromise)({
func: (previousResponse) => {
return this.searchRules(
{
indexName,
searchRulesParams: {
...params,
page: previousResponse ? previousResponse.page + 1 : params.page || 0
}
},
requestOptions
);
},
validate: (response) => response.hits.length < params.hitsPerPage,
...browseRulesOptions
});
},
/**
* Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
*
* @summary Helper method that iterates on the `searchSynonyms` method.
* @param browseSynonyms - The `browseSynonyms` object.
* @param browseSynonyms.indexName - The index in which to perform the request.
* @param browseSynonyms.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
* @param browseSynonyms.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param browseSynonyms.searchSynonymsParams - The `searchSynonyms` method parameters.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
*/
browseSynonyms({
indexName,
searchSynonymsParams,
...browseSynonymsOptions
}, requestOptions) {
const params = {
...searchSynonymsParams,
page: (searchSynonymsParams == null ? void 0 : searchSynonymsParams.page) || 0,
hitsPerPage: 1e3
};
return (0, import_client_common.createIterablePromise)({
func: (_) => {
const resp = this.searchSynonyms(
{
indexName,
searchSynonymsParams: {
...params,
page: params.page
}
},
requestOptions
);
params.page += 1;
return resp;
},
validate: (response) => response.hits.length < params.hitsPerPage,
...browseSynonymsOptions
});
},
/**
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
*
* @summary Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
* @param chunkedBatch - The `chunkedBatch` object.
* @param chunkedBatch.indexName - The `indexName` to replace `objects` in.
* @param chunkedBatch.objects - The array of `objects` to store in the given Algolia `indexName`.
* @param chunkedBatch.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
* @param chunkedBatch.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
async chunkedBatch({ indexName, objects, action = "addObject", waitForTasks, batchSize = 1e3 }, requestOptions) {
let requests = [];
const responses = [];
const objectEntries = objects.entries();
for (const [i, obj] of objectEntries) {
requests.push({ action, body: obj });
if (requests.length === batchSize || i === objects.length - 1) {
responses.push(await this.batch({ indexName, batchWriteParams: { requests } }, requestOptions));
requests = [];
}
}
if (waitForTasks) {
for (const resp of responses) {
await this.waitForTask({ indexName, taskID: resp.taskID });
}
}
return responses;
},
/**
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
*
* @summary Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
* @param saveObjects - The `saveObjects` object.
* @param saveObjects.indexName - The `indexName` to save `objects` in.
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
* @param saveObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
* @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
*/
async saveObjects({ indexName, objects, waitForTasks, batchSize }, requestOptions) {
return await this.chunkedBatch(
{ indexName, objects, action: "addObject", waitForTasks, batchSize },
requestOptions
);
},
/**
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
*
* @summary Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
* @param deleteObjects - The `deleteObjects` object.
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
* @param deleteObjects.objectIDs - The objectIDs to delete.
* @param deleteObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
* @param deleteObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
*/
async deleteObjects({ indexName, objectIDs, waitForTasks, batchSize }, requestOptions) {
return await this.chunkedBatch(
{
indexName,
objects: objectIDs.map((objectID) => ({ objectID })),
action: "deleteObject",
waitForTasks,
batchSize
},
requestOptions
);
},
/**
* Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
*
* @summary Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
* @param partialUpdateObjects - The `partialUpdateObjects` object.
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
* @param partialUpdateObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
* @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
async partialUpdateObjects({ indexName, objects, createIfNotExists, waitForTasks, batchSize }, requestOptions) {
return await this.chunkedBatch(
{
indexName,
objects,
action: createIfNotExists ? "partialUpdateObject" : "partialUpdateObjectNoCreate",
batchSize,
waitForTasks
},
requestOptions
);
},
/**
* Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
* See https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation details.
*
* @summary Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
* @param replaceAllObjects - The `replaceAllObjects` object.
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
* @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
* @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch`, `operationIndex` and `getTask` method and merged with the transporter requestOptions.
*/
async replaceAllObjects({ indexName, objects, batchSize, scopes }, requestOptions) {
const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
if (scopes === void 0) {
scopes = ["settings", "rules", "synonyms"];
}
try {
let copyOperationResponse = await this.operationIndex(
{
indexName,
operationIndexParams: {
operation: "copy",
destination: tmpIndexName,
scope: scopes
}
},
requestOptions
);
const batchResponses = await this.chunkedBatch(
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
requestOptions
);
await this.waitForTask({
indexName: tmpIndexName,
taskID: copyOperationResponse.taskID
});
copyOperationResponse = await this.operationIndex(
{
indexName,
operationIndexParams: {
operation: "copy",
destination: tmpIndexName,
scope: scopes
}
},
requestOptions
);
await this.waitForTask({
indexName: tmpIndexName,
taskID: copyOperationResponse.taskID
});
const moveOperationResponse = await this.operationIndex(
{
indexName: tmpIndexName,
operationIndexParams: { operation: "move", destination: indexName }
},
requestOptions
);
await this.waitForTask({
indexName: tmpIndexName,
taskID: moveOperationResponse.taskID
});
return { copyOperationResponse, batchResponses, moveOperationResponse };
} catch (error) {
await this.deleteIndex({ indexName: tmpIndexName });
throw error;
}
},
async indexExists({ indexName }) {
try {
await this.getSettings({ indexName });
} catch (error) {
if (error instanceof import_client_common.ApiError && error.status === 404) {
return false;
}
throw error;
}
return true;
},
/**
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
* Disclaimer: We don't assert that the parameters you pass to this method only contains `hits` requests to prevent impacting search performances, this helper is purely for typing purposes.
*
* @summary Search multiple indices for `hits`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForHits(searchMethodParams, requestOptions) {
return this.search(searchMethodParams, requestOptions);
},
/**
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
* Disclaimer: We don't assert that the parameters you pass to this method only contains `facets` requests to prevent impacting search performances, this helper is purely for typing purposes.
*
* @summary Search multiple indices for `facets`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacets(searchMethodParams, requestOptions) {
return this.search(searchMethodParams, requestOptions);
},
/**
* Creates a new API key with specific permissions and restrictions.
*
* Required API Key ACLs:
* - admin
* @param apiKey - The apiKey object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
addApiKey(apiKey, requestOptions) {
if (!apiKey) {
throw new Error("Parameter `apiKey` is required when calling `addApiKey`.");
}
if (!apiKey.acl) {
throw new Error("Parameter `apiKey.acl` is required when calling `addApiKey`.");
}
const requestPath = "/1/keys";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: apiKey
};
return transporter.request(request, requestOptions);
},
/**
* If a record with the specified object ID exists, the existing record is replaced. Otherwise, a new record is added to the index. If you want to use auto-generated object IDs, use the [`saveObject` operation](#tag/Records/operation/saveObject). To update _some_ attributes of an existing record, use the [`partial` operation](#tag/Records/operation/partialUpdateObject) instead. To add, update, or replace multiple records, use the [`batch` operation](#tag/Records/operation/batch).
*
* Required API Key ACLs:
* - addObject
* @param addOrUpdateObject - The addOrUpdateObject object.
* @param addOrUpdateObject.indexName - Name of the index on which to perform the operation.
* @param addOrUpdateObject.objectID - Unique record identifier.
* @param addOrUpdateObject.body - The record. A schemaless object with attributes that are useful in the context of search and discovery.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
addOrUpdateObject({ indexName, objectID, body }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `addOrUpdateObject`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `addOrUpdateObject`.");
}
if (!body) {
throw new Error("Parameter `body` is required when calling `addOrUpdateObject`.");
}
const requestPath = "/1/indexes/{indexName}/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: body
};
return transporter.request(request, requestOptions);
},
/**
* Adds a source to the list of allowed sources.
*
* Required API Key ACLs:
* - admin
* @param source - Source to add.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
appendSource(source, requestOptions) {
if (!source) {
throw new Error("Parameter `source` is required when calling `appendSource`.");
}
if (!source.source) {
throw new Error("Parameter `source.source` is required when calling `appendSource`.");
}
const requestPath = "/1/security/sources/append";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: source
};
return transporter.request(request, requestOptions);
},
/**
* Assigns or moves a user ID to a cluster. The time it takes to move a user is proportional to the amount of data linked to the user ID.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param assignUserId - The assignUserId object.
* @param assignUserId.xAlgoliaUserID - Unique identifier of the user who makes the search request.
* @param assignUserId.assignUserIdParams - The assignUserIdParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
assignUserId({ xAlgoliaUserID, assignUserIdParams }, requestOptions) {
if (!xAlgoliaUserID) {
throw new Error("Parameter `xAlgoliaUserID` is required when calling `assignUserId`.");
}
if (!assignUserIdParams) {
throw new Error("Parameter `assignUserIdParams` is required when calling `assignUserId`.");
}
if (!assignUserIdParams.cluster) {
throw new Error("Parameter `assignUserIdParams.cluster` is required when calling `assignUserId`.");
}
const requestPath = "/1/clusters/mapping";
const headers = {};
const queryParameters = {};
if (xAlgoliaUserID !== void 0) {
headers["X-Algolia-User-ID"] = xAlgoliaUserID.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: assignUserIdParams
};
return transporter.request(request, requestOptions);
},
/**
* Adds, updates, or deletes records in one index with a single API request. Batching index updates reduces latency and increases data integrity. - Actions are applied in the order they\'re specified. - Actions are equivalent to the individual API requests of the same name. This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
* @param batch - The batch object.
* @param batch.indexName - Name of the index on which to perform the operation.
* @param batch.batchWriteParams - The batchWriteParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
batch({ indexName, batchWriteParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `batch`.");
}
if (!batchWriteParams) {
throw new Error("Parameter `batchWriteParams` is required when calling `batch`.");
}
if (!batchWriteParams.requests) {
throw new Error("Parameter `batchWriteParams.requests` is required when calling `batch`.");
}
const requestPath = "/1/indexes/{indexName}/batch".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: batchWriteParams
};
return transporter.request(request, requestOptions);
},
/**
* Assigns multiple user IDs to a cluster. **You can\'t move users with this operation**.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param batchAssignUserIds - The batchAssignUserIds object.
* @param batchAssignUserIds.xAlgoliaUserID - Unique identifier of the user who makes the search request.
* @param batchAssignUserIds.batchAssignUserIdsParams - The batchAssignUserIdsParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
batchAssignUserIds({ xAlgoliaUserID, batchAssignUserIdsParams }, requestOptions) {
if (!xAlgoliaUserID) {
throw new Error("Parameter `xAlgoliaUserID` is required when calling `batchAssignUserIds`.");
}
if (!batchAssignUserIdsParams) {
throw new Error("Parameter `batchAssignUserIdsParams` is required when calling `batchAssignUserIds`.");
}
if (!batchAssignUserIdsParams.cluster) {
throw new Error("Parameter `batchAssignUserIdsParams.cluster` is required when calling `batchAssignUserIds`.");
}
if (!batchAssignUserIdsParams.users) {
throw new Error("Parameter `batchAssignUserIdsParams.users` is required when calling `batchAssignUserIds`.");
}
const requestPath = "/1/clusters/mapping/batch";
const headers = {};
const queryParameters = {};
if (xAlgoliaUserID !== void 0) {
headers["X-Algolia-User-ID"] = xAlgoliaUserID.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: batchAssignUserIdsParams
};
return transporter.request(request, requestOptions);
},
/**
* Adds or deletes multiple entries from your plurals, segmentation, or stop word dictionaries.
*
* Required API Key ACLs:
* - editSettings
* @param batchDictionaryEntries - The batchDictionaryEntries object.
* @param batchDictionaryEntries.dictionaryName - Dictionary type in which to search.
* @param batchDictionaryEntries.batchDictionaryEntriesParams - The batchDictionaryEntriesParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
batchDictionaryEntries({ dictionaryName, batchDictionaryEntriesParams }, requestOptions) {
if (!dictionaryName) {
throw new Error("Parameter `dictionaryName` is required when calling `batchDictionaryEntries`.");
}
if (!batchDictionaryEntriesParams) {
throw new Error("Parameter `batchDictionaryEntriesParams` is required when calling `batchDictionaryEntries`.");
}
if (!batchDictionaryEntriesParams.requests) {
throw new Error(
"Parameter `batchDictionaryEntriesParams.requests` is required when calling `batchDictionaryEntries`."
);
}
const requestPath = "/1/dictionaries/{dictionaryName}/batch".replace(
"{dictionaryName}",
encodeURIComponent(dictionaryName)
);
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: batchDictionaryEntriesParams
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves records from an index, up to 1,000 per request. While searching retrieves _hits_ (records augmented with attributes for highlighting and ranking details), browsing _just_ returns matching records. This can be useful if you want to export your indices. - The Analytics API doesn\'t collect data when using `browse`. - Records are ranked by attributes and custom ranking. - There\'s no ranking for: typo-tolerance, number of matched words, proximity, geo distance. Browse requests automatically apply these settings: - `advancedSyntax`: `false` - `attributesToHighlight`: `[]` - `attributesToSnippet`: `[]` - `distinct`: `false` - `enablePersonalization`: `false` - `enableRules`: `false` - `facets`: `[]` - `getRankingInfo`: `false` - `ignorePlurals`: `false` - `optionalFilters`: `[]` - `typoTolerance`: `true` or `false` (`min` and `strict` evaluate to `true`) If you send these parameters with your browse requests, they\'ll be ignored.
*
* Required API Key ACLs:
* - browse
* @param browse - The browse object.
* @param browse.indexName - Name of the index on which to perform the operation.
* @param browse.browseParams - The browseParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
browse({ indexName, browseParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `browse`.");
}
const requestPath = "/1/indexes/{indexName}/browse".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: browseParams ? browseParams : {},
useReadTransporter: true
};
return transporter.request(request, requestOptions);
},
/**
* Deletes only the records from an index while keeping settings, synonyms, and rules. This operation is resource-intensive and subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - deleteIndex
* @param clearObjects - The clearObjects object.
* @param clearObjects.indexName - Name of the index on which to perform the operation.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
clearObjects({ indexName }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `clearObjects`.");
}
const requestPath = "/1/indexes/{indexName}/clear".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Deletes all rules from the index.
*
* Required API Key ACLs:
* - editSettings
* @param clearRules - The clearRules object.
* @param clearRules.indexName - Name of the index on which to perform the operation.
* @param clearRules.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
clearRules({ indexName, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `clearRules`.");
}
const requestPath = "/1/indexes/{indexName}/rules/clear".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Deletes all synonyms from the index.
*
* Required API Key ACLs:
* - editSettings
* @param clearSynonyms - The clearSynonyms object.
* @param clearSynonyms.indexName - Name of the index on which to perform the operation.
* @param clearSynonyms.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
clearSynonyms({ indexName, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `clearSynonyms`.");
}
const requestPath = "/1/indexes/{indexName}/synonyms/clear".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* This method lets you send requests to the Algolia REST API.
* @param customDelete - The customDelete object.
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
* @param customDelete.parameters - Query parameters to apply to the current query.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
customDelete({ path, parameters }, requestOptions) {
if (!path) {
throw new Error("Parameter `path` is required when calling `customDelete`.");
}
const requestPath = "/{path}".replace("{path}", path);
const headers = {};
const queryParameters = parameters ? parameters : {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* This method lets you send requests to the Algolia REST API.
* @param customGet - The customGet object.
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
* @param customGet.parameters - Query parameters to apply to the current query.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
customGet({ path, parameters }, requestOptions) {
if (!path) {
throw new Error("Parameter `path` is required when calling `customGet`.");
}
const requestPath = "/{path}".replace("{path}", path);
const headers = {};
const queryParameters = parameters ? parameters : {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* This method lets you send requests to the Algolia REST API.
* @param customPost - The customPost object.
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
* @param customPost.parameters - Query parameters to apply to the current query.
* @param customPost.body - Parameters to send with the custom request.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
customPost({ path, parameters, body }, requestOptions) {
if (!path) {
throw new Error("Parameter `path` is required when calling `customPost`.");
}
const requestPath = "/{path}".replace("{path}", path);
const headers = {};
const queryParameters = parameters ? parameters : {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: body ? body : {}
};
return transporter.request(request, requestOptions);
},
/**
* This method lets you send requests to the Algolia REST API.
* @param customPut - The customPut object.
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
* @param customPut.parameters - Query parameters to apply to the current query.
* @param customPut.body - Parameters to send with the custom request.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
customPut({ path, parameters, body }, requestOptions) {
if (!path) {
throw new Error("Parameter `path` is required when calling `customPut`.");
}
const requestPath = "/{path}".replace("{path}", path);
const headers = {};
const queryParameters = parameters ? parameters : {};
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: body ? body : {}
};
return transporter.request(request, requestOptions);
},
/**
* Deletes the API key.
*
* Required API Key ACLs:
* - admin
* @param deleteApiKey - The deleteApiKey object.
* @param deleteApiKey.key - API key.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteApiKey({ key }, requestOptions) {
if (!key) {
throw new Error("Parameter `key` is required when calling `deleteApiKey`.");
}
const requestPath = "/1/keys/{key}".replace("{key}", encodeURIComponent(key));
const headers = {};
const queryParameters = {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* This operation doesn\'t accept empty filters. This operation is resource-intensive. You should only use it if you can\'t get the object IDs of the records you want to delete. It\'s more efficient to get a list of object IDs with the [`browse` operation](#tag/Search/operation/browse), and then delete the records using the [`batch` operation](#tag/Records/operation/batch). This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - deleteIndex
* @param deleteBy - The deleteBy object.
* @param deleteBy.indexName - Name of the index on which to perform the operation.
* @param deleteBy.deleteByParams - The deleteByParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteBy({ indexName, deleteByParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `deleteBy`.");
}
if (!deleteByParams) {
throw new Error("Parameter `deleteByParams` is required when calling `deleteBy`.");
}
const requestPath = "/1/indexes/{indexName}/deleteByQuery".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: deleteByParams
};
return transporter.request(request, requestOptions);
},
/**
* Deletes an index and all its settings. - Deleting an index doesn\'t delete its analytics data. - If you try to delete a non-existing index, the operation is ignored without warning. - If the index you want to delete has replica indices, the replicas become independent indices. - If the index you want to delete is a replica index, you must first unlink it from its primary index before you can delete it. For more information, see [Delete replica indices](https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/how-to/deleting-replicas/).
*
* Required API Key ACLs:
* - deleteIndex
* @param deleteIndex - The deleteIndex object.
* @param deleteIndex.indexName - Name of the index on which to perform the operation.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteIndex({ indexName }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `deleteIndex`.");
}
const requestPath = "/1/indexes/{indexName}".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Deletes a record by its object ID. To delete more than one record, use the [`batch` operation](#tag/Records/operation/batch). To delete records matching a query, use the [`deleteBy` operation](#tag/Records/operation/deleteBy).
*
* Required API Key ACLs:
* - deleteObject
* @param deleteObject - The deleteObject object.
* @param deleteObject.indexName - Name of the index on which to perform the operation.
* @param deleteObject.objectID - Unique record identifier.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteObject({ indexName, objectID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `deleteObject`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `deleteObject`.");
}
const requestPath = "/1/indexes/{indexName}/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Deletes a rule by its ID. To find the object ID for rules, use the [`search` operation](#tag/Rules/operation/searchRules).
*
* Required API Key ACLs:
* - editSettings
* @param deleteRule - The deleteRule object.
* @param deleteRule.indexName - Name of the index on which to perform the operation.
* @param deleteRule.objectID - Unique identifier of a rule object.
* @param deleteRule.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteRule({ indexName, objectID, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `deleteRule`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `deleteRule`.");
}
const requestPath = "/1/indexes/{indexName}/rules/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Deletes a source from the list of allowed sources.
*
* Required API Key ACLs:
* - admin
* @param deleteSource - The deleteSource object.
* @param deleteSource.source - IP address range of the source.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteSource({ source }, requestOptions) {
if (!source) {
throw new Error("Parameter `source` is required when calling `deleteSource`.");
}
const requestPath = "/1/security/sources/{source}".replace("{source}", encodeURIComponent(source));
const headers = {};
const queryParameters = {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Deletes a synonym by its ID. To find the object IDs of your synonyms, use the [`search` operation](#tag/Synonyms/operation/searchSynonyms).
*
* Required API Key ACLs:
* - editSettings
* @param deleteSynonym - The deleteSynonym object.
* @param deleteSynonym.indexName - Name of the index on which to perform the operation.
* @param deleteSynonym.objectID - Unique identifier of a synonym object.
* @param deleteSynonym.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteSynonym({ indexName, objectID, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `deleteSynonym`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `deleteSynonym`.");
}
const requestPath = "/1/indexes/{indexName}/synonyms/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Gets the permissions and restrictions of an API key. When authenticating with the admin API key, you can request information for any of your application\'s keys. When authenticating with other API keys, you can only retrieve information for that key, with the description replaced by `<redacted>`.
* @param getApiKey - The getApiKey object.
* @param getApiKey.key - API key.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getApiKey({ key }, requestOptions) {
if (!key) {
throw new Error("Parameter `key` is required when calling `getApiKey`.");
}
const requestPath = "/1/keys/{key}".replace("{key}", encodeURIComponent(key));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Checks the status of a given application task.
*
* Required API Key ACLs:
* - editSettings
* @param getAppTask - The getAppTask object.
* @param getAppTask.taskID - Unique task identifier.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getAppTask({ taskID }, requestOptions) {
if (!taskID) {
throw new Error("Parameter `taskID` is required when calling `getAppTask`.");
}
const requestPath = "/1/task/{taskID}".replace("{taskID}", encodeURIComponent(taskID));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Lists supported languages with their supported dictionary types and number of custom entries.
*
* Required API Key ACLs:
* - settings
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getDictionaryLanguages(requestOptions) {
const requestPath = "/1/dictionaries/*/languages";
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves the languages for which standard dictionary entries are turned off.
*
* Required API Key ACLs:
* - settings
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getDictionarySettings(requestOptions) {
const requestPath = "/1/dictionaries/*/settings";
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* The request must be authenticated by an API key with the [`logs` ACL](https://www.algolia.com/doc/guides/security/api-keys/#access-control-list-acl). - Logs are held for the last seven days. - Up to 1,000 API requests per server are logged. - This request counts towards your [operations quota](https://support.algolia.com/hc/en-us/articles/4406981829777-How-does-Algolia-count-records-and-operations-) but doesn\'t appear in the logs itself.
*
* Required API Key ACLs:
* - logs
* @param getLogs - The getLogs object.
* @param getLogs.offset - First log entry to retrieve. The most recent entries are listed first.
* @param getLogs.length - Maximum number of entries to retrieve.
* @param getLogs.indexName - Index for which to retrieve log entries. By default, log entries are retrieved for all indices.
* @param getLogs.type - Type of log entries to retrieve. By default, all log entries are retrieved.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getLogs({ offset, length, indexName, type } = {}, requestOptions = void 0) {
const requestPath = "/1/logs";
const headers = {};
const queryParameters = {};
if (offset !== void 0) {
queryParameters["offset"] = offset.toString();
}
if (length !== void 0) {
queryParameters["length"] = length.toString();
}
if (indexName !== void 0) {
queryParameters["indexName"] = indexName.toString();
}
if (type !== void 0) {
queryParameters["type"] = type.toString();
}
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves one record by its object ID. To retrieve more than one record, use the [`objects` operation](#tag/Records/operation/getObjects).
*
* Required API Key ACLs:
* - search
* @param getObject - The getObject object.
* @param getObject.indexName - Name of the index on which to perform the operation.
* @param getObject.objectID - Unique record identifier.
* @param getObject.attributesToRetrieve - Attributes to include with the records in the response. This is useful to reduce the size of the API response. By default, all retrievable attributes are returned. `objectID` is always retrieved. Attributes included in `unretrievableAttributes` won\'t be retrieved unless the request is authenticated with the admin API key.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getObject({ indexName, objectID, attributesToRetrieve }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getObject`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `getObject`.");
}
const requestPath = "/1/indexes/{indexName}/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
if (attributesToRetrieve !== void 0) {
queryParameters["attributesToRetrieve"] = attributesToRetrieve.toString();
}
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves one or more records, potentially from different indices. Records are returned in the same order as the requests.
*
* Required API Key ACLs:
* - search
* @param getObjectsParams - Request object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getObjects(getObjectsParams, requestOptions) {
if (!getObjectsParams) {
throw new Error("Parameter `getObjectsParams` is required when calling `getObjects`.");
}
if (!getObjectsParams.requests) {
throw new Error("Parameter `getObjectsParams.requests` is required when calling `getObjects`.");
}
const requestPath = "/1/indexes/*/objects";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: getObjectsParams,
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves a rule by its ID. To find the object ID of rules, use the [`search` operation](#tag/Rules/operation/searchRules).
*
* Required API Key ACLs:
* - settings
* @param getRule - The getRule object.
* @param getRule.indexName - Name of the index on which to perform the operation.
* @param getRule.objectID - Unique identifier of a rule object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getRule({ indexName, objectID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getRule`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `getRule`.");
}
const requestPath = "/1/indexes/{indexName}/rules/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves an object with non-null index settings.
*
* Required API Key ACLs:
* - settings
* @param getSettings - The getSettings object.
* @param getSettings.indexName - Name of the index on which to perform the operation.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getSettings({ indexName }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getSettings`.");
}
const requestPath = "/1/indexes/{indexName}/settings".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves all allowed IP addresses with access to your application.
*
* Required API Key ACLs:
* - admin
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getSources(requestOptions) {
const requestPath = "/1/security/sources";
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves a synonym by its ID. To find the object IDs for your synonyms, use the [`search` operation](#tag/Synonyms/operation/searchSynonyms).
*
* Required API Key ACLs:
* - settings
* @param getSynonym - The getSynonym object.
* @param getSynonym.indexName - Name of the index on which to perform the operation.
* @param getSynonym.objectID - Unique identifier of a synonym object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getSynonym({ indexName, objectID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getSynonym`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `getSynonym`.");
}
const requestPath = "/1/indexes/{indexName}/synonyms/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Checks the status of a given task. Indexing tasks are asynchronous. When you add, update, or delete records or indices, a task is created on a queue and completed depending on the load on the server. The indexing tasks\' responses include a task ID that you can use to check the status.
*
* Required API Key ACLs:
* - addObject
* @param getTask - The getTask object.
* @param getTask.indexName - Name of the index on which to perform the operation.
* @param getTask.taskID - Unique task identifier.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getTask({ indexName, taskID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getTask`.");
}
if (!taskID) {
throw new Error("Parameter `taskID` is required when calling `getTask`.");
}
const requestPath = "/1/indexes/{indexName}/task/{taskID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{taskID}", encodeURIComponent(taskID));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Get the IDs of the 10 users with the highest number of records per cluster. Since it can take a few seconds to get the data from the different clusters, the response isn\'t real-time.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getTopUserIds(requestOptions) {
const requestPath = "/1/clusters/mapping/top";
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Returns the user ID data stored in the mapping. Since it can take a few seconds to get the data from the different clusters, the response isn\'t real-time.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param getUserId - The getUserId object.
* @param getUserId.userID - Unique identifier of the user who makes the search request.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getUserId({ userID }, requestOptions) {
if (!userID) {
throw new Error("Parameter `userID` is required when calling `getUserId`.");
}
const requestPath = "/1/clusters/mapping/{userID}".replace("{userID}", encodeURIComponent(userID));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* To determine when the time-consuming process of creating a large batch of users or migrating users from one cluster to another is complete, this operation retrieves the status of the process.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param hasPendingMappings - The hasPendingMappings object.
* @param hasPendingMappings.getClusters - Whether to include the cluster\'s pending mapping state in the response.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
hasPendingMappings({ getClusters } = {}, requestOptions = void 0) {
const requestPath = "/1/clusters/mapping/pending";
const headers = {};
const queryParameters = {};
if (getClusters !== void 0) {
queryParameters["getClusters"] = getClusters.toString();
}
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Lists all API keys associated with your Algolia application, including their permissions and restrictions.
*
* Required API Key ACLs:
* - admin
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
listApiKeys(requestOptions) {
const requestPath = "/1/keys";
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Lists the available clusters in a multi-cluster setup.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
listClusters(requestOptions) {
const requestPath = "/1/clusters";
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Lists all indices in the current Algolia application. The request follows any index restrictions of the API key you use to make the request.
*
* Required API Key ACLs:
* - listIndexes
* @param listIndices - The listIndices object.
* @param listIndices.page - Requested page of the API response. If `null`, the API response is not paginated.
* @param listIndices.hitsPerPage - Number of hits per page.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
listIndices({ page, hitsPerPage } = {}, requestOptions = void 0) {
const requestPath = "/1/indexes";
const headers = {};
const queryParameters = {};
if (page !== void 0) {
queryParameters["page"] = page.toString();
}
if (hitsPerPage !== void 0) {
queryParameters["hitsPerPage"] = hitsPerPage.toString();
}
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Lists the userIDs assigned to a multi-cluster application. Since it can take a few seconds to get the data from the different clusters, the response isn\'t real-time.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param listUserIds - The listUserIds object.
* @param listUserIds.page - Requested page of the API response. If `null`, the API response is not paginated.
* @param listUserIds.hitsPerPage - Number of hits per page.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
listUserIds({ page, hitsPerPage } = {}, requestOptions = void 0) {
const requestPath = "/1/clusters/mapping";
const headers = {};
const queryParameters = {};
if (page !== void 0) {
queryParameters["page"] = page.toString();
}
if (hitsPerPage !== void 0) {
queryParameters["hitsPerPage"] = hitsPerPage.toString();
}
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Adds, updates, or deletes records in multiple indices with a single API request. - Actions are applied in the order they are specified. - Actions are equivalent to the individual API requests of the same name. This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
* @param batchParams - The batchParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
multipleBatch(batchParams, requestOptions) {
if (!batchParams) {
throw new Error("Parameter `batchParams` is required when calling `multipleBatch`.");
}
if (!batchParams.requests) {
throw new Error("Parameter `batchParams.requests` is required when calling `multipleBatch`.");
}
const requestPath = "/1/indexes/*/batch";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: batchParams
};
return transporter.request(request, requestOptions);
},
/**
* Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for their analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. - This operation is resource-intensive. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keeps its original name, and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/). This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - addObject
* @param operationIndex - The operationIndex object.
* @param operationIndex.indexName - Name of the index on which to perform the operation.
* @param operationIndex.operationIndexParams - The operationIndexParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
operationIndex({ indexName, operationIndexParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `operationIndex`.");
}
if (!operationIndexParams) {
throw new Error("Parameter `operationIndexParams` is required when calling `operationIndex`.");
}
if (!operationIndexParams.operation) {
throw new Error("Parameter `operationIndexParams.operation` is required when calling `operationIndex`.");
}
if (!operationIndexParams.destination) {
throw new Error("Parameter `operationIndexParams.destination` is required when calling `operationIndex`.");
}
const requestPath = "/1/indexes/{indexName}/operation".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: operationIndexParams
};
return transporter.request(request, requestOptions);
},
/**
* Adds new attributes to a record, or updates existing ones. - If a record with the specified object ID doesn\'t exist, a new record is added to the index **if** `createIfNotExists` is true. - If the index doesn\'t exist yet, this method creates a new index. - You can use any first-level attribute but not nested attributes. If you specify a nested attribute, this operation replaces its first-level ancestor. To update an attribute without pushing the entire record, you can use these built-in operations. These operations can be helpful if you don\'t have access to your initial data. - Increment: increment a numeric attribute - Decrement: decrement a numeric attribute - Add: append a number or string element to an array attribute - Remove: remove all matching number or string elements from an array attribute made of numbers or strings - AddUnique: add a number or string element to an array attribute made of numbers or strings only if it\'s not already present - IncrementFrom: increment a numeric integer attribute only if the provided value matches the current value, and otherwise ignore the whole object update. For example, if you pass an IncrementFrom value of 2 for the version attribute, but the current value of the attribute is 1, the engine ignores the update. If the object doesn\'t exist, the engine only creates it if you pass an IncrementFrom value of 0. - IncrementSet: increment a numeric integer attribute only if the provided value is greater than the current value, and otherwise ignore the whole object update. For example, if you pass an IncrementSet value of 2 for the version attribute, and the current value of the attribute is 1, the engine updates the object. If the object doesn\'t exist yet, the engine only creates it if you pass an IncrementSet value greater than 0. You can specify an operation by providing an object with the attribute to update as the key and its value being an object with the following properties: - _operation: the operation to apply on the attribute - value: the right-hand side argument to the operation, for example, increment or decrement step, value to add or remove. When updating multiple attributes or using multiple operations targeting the same record, you should use a single partial update for faster processing. This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - addObject
* @param partialUpdateObject - The partialUpdateObject object.
* @param partialUpdateObject.indexName - Name of the index on which to perform the operation.
* @param partialUpdateObject.objectID - Unique record identifier.
* @param partialUpdateObject.attributesToUpdate - Attributes with their values.
* @param partialUpdateObject.createIfNotExists - Whether to create a new record if it doesn\'t exist.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
partialUpdateObject({ indexName, objectID, attributesToUpdate, createIfNotExists }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `partialUpdateObject`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `partialUpdateObject`.");
}
if (!attributesToUpdate) {
throw new Error("Parameter `attributesToUpdate` is required when calling `partialUpdateObject`.");
}
const requestPath = "/1/indexes/{indexName}/{objectID}/partial".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
if (createIfNotExists !== void 0) {
queryParameters["createIfNotExists"] = createIfNotExists.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: attributesToUpdate
};
return transporter.request(request, requestOptions);
},
/**
* Deletes a user ID and its associated data from the clusters.
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param removeUserId - The removeUserId object.
* @param removeUserId.userID - Unique identifier of the user who makes the search request.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
removeUserId({ userID }, requestOptions) {
if (!userID) {
throw new Error("Parameter `userID` is required when calling `removeUserId`.");
}
const requestPath = "/1/clusters/mapping/{userID}".replace("{userID}", encodeURIComponent(userID));
const headers = {};
const queryParameters = {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Replaces the list of allowed sources.
*
* Required API Key ACLs:
* - admin
* @param replaceSources - The replaceSources object.
* @param replaceSources.source - Allowed sources.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
replaceSources({ source }, requestOptions) {
if (!source) {
throw new Error("Parameter `source` is required when calling `replaceSources`.");
}
const requestPath = "/1/security/sources";
const headers = {};
const queryParameters = {};
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: source
};
return transporter.request(request, requestOptions);
},
/**
* Restores a deleted API key. Restoring resets the `validity` attribute to `0`. Algolia stores up to 1,000 API keys per application. If you create more, the oldest API keys are deleted and can\'t be restored.
*
* Required API Key ACLs:
* - admin
* @param restoreApiKey - The restoreApiKey object.
* @param restoreApiKey.key - API key.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
restoreApiKey({ key }, requestOptions) {
if (!key) {
throw new Error("Parameter `key` is required when calling `restoreApiKey`.");
}
const requestPath = "/1/keys/{key}/restore".replace("{key}", encodeURIComponent(key));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Adds a record to an index or replaces it. - If the record doesn\'t have an object ID, a new record with an auto-generated object ID is added to your index. - If a record with the specified object ID exists, the existing record is replaced. - If a record with the specified object ID doesn\'t exist, a new record is added to your index. - If you add a record to an index that doesn\'t exist yet, a new index is created. To update _some_ attributes of a record, use the [`partial` operation](#tag/Records/operation/partialUpdateObject). To add, update, or replace multiple records, use the [`batch` operation](#tag/Records/operation/batch). This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - addObject
* @param saveObject - The saveObject object.
* @param saveObject.indexName - Name of the index on which to perform the operation.
* @param saveObject.body - The record. A schemaless object with attributes that are useful in the context of search and discovery.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
saveObject({ indexName, body }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `saveObject`.");
}
if (!body) {
throw new Error("Parameter `body` is required when calling `saveObject`.");
}
const requestPath = "/1/indexes/{indexName}".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: body
};
return transporter.request(request, requestOptions);
},
/**
* If a rule with the specified object ID doesn\'t exist, it\'s created. Otherwise, the existing rule is replaced. To create or update more than one rule, use the [`batch` operation](#tag/Rules/operation/saveRules).
*
* Required API Key ACLs:
* - editSettings
* @param saveRule - The saveRule object.
* @param saveRule.indexName - Name of the index on which to perform the operation.
* @param saveRule.objectID - Unique identifier of a rule object.
* @param saveRule.rule - The rule object.
* @param saveRule.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
saveRule({ indexName, objectID, rule, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `saveRule`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `saveRule`.");
}
if (!rule) {
throw new Error("Parameter `rule` is required when calling `saveRule`.");
}
if (!rule.objectID) {
throw new Error("Parameter `rule.objectID` is required when calling `saveRule`.");
}
if (!rule.consequence) {
throw new Error("Parameter `rule.consequence` is required when calling `saveRule`.");
}
const requestPath = "/1/indexes/{indexName}/rules/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: rule
};
return transporter.request(request, requestOptions);
},
/**
* Create or update multiple rules. If a rule with the specified object ID doesn\'t exist, Algolia creates a new one. Otherwise, existing rules are replaced. This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - editSettings
* @param saveRules - The saveRules object.
* @param saveRules.indexName - Name of the index on which to perform the operation.
* @param saveRules.rules - The rules object.
* @param saveRules.forwardToReplicas - Whether changes are applied to replica indices.
* @param saveRules.clearExistingRules - Whether existing rules should be deleted before adding this batch.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
saveRules({ indexName, rules, forwardToReplicas, clearExistingRules }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `saveRules`.");
}
if (!rules) {
throw new Error("Parameter `rules` is required when calling `saveRules`.");
}
const requestPath = "/1/indexes/{indexName}/rules/batch".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
if (clearExistingRules !== void 0) {
queryParameters["clearExistingRules"] = clearExistingRules.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: rules
};
return transporter.request(request, requestOptions);
},
/**
* If a synonym with the specified object ID doesn\'t exist, Algolia adds a new one. Otherwise, the existing synonym is replaced. To add multiple synonyms in a single API request, use the [`batch` operation](#tag/Synonyms/operation/saveSynonyms).
*
* Required API Key ACLs:
* - editSettings
* @param saveSynonym - The saveSynonym object.
* @param saveSynonym.indexName - Name of the index on which to perform the operation.
* @param saveSynonym.objectID - Unique identifier of a synonym object.
* @param saveSynonym.synonymHit - The synonymHit object.
* @param saveSynonym.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
saveSynonym({ indexName, objectID, synonymHit, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `saveSynonym`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `saveSynonym`.");
}
if (!synonymHit) {
throw new Error("Parameter `synonymHit` is required when calling `saveSynonym`.");
}
if (!synonymHit.objectID) {
throw new Error("Parameter `synonymHit.objectID` is required when calling `saveSynonym`.");
}
if (!synonymHit.type) {
throw new Error("Parameter `synonymHit.type` is required when calling `saveSynonym`.");
}
const requestPath = "/1/indexes/{indexName}/synonyms/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: synonymHit
};
return transporter.request(request, requestOptions);
},
/**
* If a synonym with the `objectID` doesn\'t exist, Algolia adds a new one. Otherwise, existing synonyms are replaced. This operation is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).
*
* Required API Key ACLs:
* - editSettings
* @param saveSynonyms - The saveSynonyms object.
* @param saveSynonyms.indexName - Name of the index on which to perform the operation.
* @param saveSynonyms.synonymHit - The synonymHit object.
* @param saveSynonyms.forwardToReplicas - Whether changes are applied to replica indices.
* @param saveSynonyms.replaceExistingSynonyms - Whether to replace all synonyms in the index with the ones sent with this request.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
saveSynonyms({ indexName, synonymHit, forwardToReplicas, replaceExistingSynonyms }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `saveSynonyms`.");
}
if (!synonymHit) {
throw new Error("Parameter `synonymHit` is required when calling `saveSynonyms`.");
}
const requestPath = "/1/indexes/{indexName}/synonyms/batch".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
if (replaceExistingSynonyms !== void 0) {
queryParameters["replaceExistingSynonyms"] = replaceExistingSynonyms.toString();
}
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: synonymHit
};
return transporter.request(request, requestOptions);
},
/**
* Sends multiple search requests to one or more indices. This can be useful in these cases: - Different indices for different purposes, such as, one index for products, another one for marketing content. - Multiple searches to the same index—for example, with different filters. Use the helper `searchForHits` or `searchForFacets` to get the results in a more convenient format, if you already know the return type you want.
*
* Required API Key ACLs:
* - search
* @param searchMethodParams - Muli-search request body. Results are returned in the same order as the requests.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
search(searchMethodParams, requestOptions) {
if (searchMethodParams && Array.isArray(searchMethodParams)) {
const newSignatureRequest = {
requests: searchMethodParams.map(({ params, ...legacyRequest }) => {
if (legacyRequest.type === "facet") {
return {
...legacyRequest,
...params,
type: "facet"
};
}
return {
...legacyRequest,
...params,
facet: void 0,
maxFacetHits: void 0,
facetQuery: void 0
};
})
};
searchMethodParams = newSignatureRequest;
}
if (!searchMethodParams) {
throw new Error("Parameter `searchMethodParams` is required when calling `search`.");
}
if (!searchMethodParams.requests) {
throw new Error("Parameter `searchMethodParams.requests` is required when calling `search`.");
}
const requestPath = "/1/indexes/*/queries";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchMethodParams,
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Searches for standard and custom dictionary entries.
*
* Required API Key ACLs:
* - settings
* @param searchDictionaryEntries - The searchDictionaryEntries object.
* @param searchDictionaryEntries.dictionaryName - Dictionary type in which to search.
* @param searchDictionaryEntries.searchDictionaryEntriesParams - The searchDictionaryEntriesParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchDictionaryEntries({ dictionaryName, searchDictionaryEntriesParams }, requestOptions) {
if (!dictionaryName) {
throw new Error("Parameter `dictionaryName` is required when calling `searchDictionaryEntries`.");
}
if (!searchDictionaryEntriesParams) {
throw new Error(
"Parameter `searchDictionaryEntriesParams` is required when calling `searchDictionaryEntries`."
);
}
if (!searchDictionaryEntriesParams.query) {
throw new Error(
"Parameter `searchDictionaryEntriesParams.query` is required when calling `searchDictionaryEntries`."
);
}
const requestPath = "/1/dictionaries/{dictionaryName}/search".replace(
"{dictionaryName}",
encodeURIComponent(dictionaryName)
);
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchDictionaryEntriesParams,
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Searches for values of a specified facet attribute. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn\'t work if you have **more than 65 searchable facets and searchable attributes combined**.
*
* Required API Key ACLs:
* - search
* @param searchForFacetValues - The searchForFacetValues object.
* @param searchForFacetValues.indexName - Name of the index on which to perform the operation.
* @param searchForFacetValues.facetName - Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier.
* @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacetValues({ indexName, facetName, searchForFacetValuesRequest }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `searchForFacetValues`.");
}
if (!facetName) {
throw new Error("Parameter `facetName` is required when calling `searchForFacetValues`.");
}
const requestPath = "/1/indexes/{indexName}/facets/{facetName}/query".replace("{indexName}", encodeURIComponent(indexName)).replace("{facetName}", encodeURIComponent(facetName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchForFacetValuesRequest ? searchForFacetValuesRequest : {},
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Searches for rules in your index.
*
* Required API Key ACLs:
* - settings
* @param searchRules - The searchRules object.
* @param searchRules.indexName - Name of the index on which to perform the operation.
* @param searchRules.searchRulesParams - The searchRulesParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchRules({ indexName, searchRulesParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `searchRules`.");
}
const requestPath = "/1/indexes/{indexName}/rules/search".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchRulesParams ? searchRulesParams : {},
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Searches a single index and returns matching search results (_hits_). This method lets you retrieve up to 1,000 hits. If you need more, use the [`browse` operation](#tag/Search/operation/browse) or increase the `paginatedLimitedTo` index setting.
*
* Required API Key ACLs:
* - search
* @param searchSingleIndex - The searchSingleIndex object.
* @param searchSingleIndex.indexName - Name of the index on which to perform the operation.
* @param searchSingleIndex.searchParams - The searchParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchSingleIndex({ indexName, searchParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `searchSingleIndex`.");
}
const requestPath = "/1/indexes/{indexName}/query".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchParams ? searchParams : {},
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Searches for synonyms in your index.
*
* Required API Key ACLs:
* - settings
* @param searchSynonyms - The searchSynonyms object.
* @param searchSynonyms.indexName - Name of the index on which to perform the operation.
* @param searchSynonyms.searchSynonymsParams - Body of the `searchSynonyms` operation.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchSynonyms({ indexName, searchSynonymsParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `searchSynonyms`.");
}
const requestPath = "/1/indexes/{indexName}/synonyms/search".replace(
"{indexName}",
encodeURIComponent(indexName)
);
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchSynonymsParams ? searchSynonymsParams : {},
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Since it can take a few seconds to get the data from the different clusters, the response isn\'t real-time. To ensure rapid updates, the user IDs index isn\'t built at the same time as the mapping. Instead, it\'s built every 12 hours, at the same time as the update of user ID usage. For example, if you add or move a user ID, the search will show an old value until the next time the mapping is rebuilt (every 12 hours).
*
* Required API Key ACLs:
* - admin
*
* @deprecated
* @param searchUserIdsParams - The searchUserIdsParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchUserIds(searchUserIdsParams, requestOptions) {
if (!searchUserIdsParams) {
throw new Error("Parameter `searchUserIdsParams` is required when calling `searchUserIds`.");
}
if (!searchUserIdsParams.query) {
throw new Error("Parameter `searchUserIdsParams.query` is required when calling `searchUserIds`.");
}
const requestPath = "/1/clusters/mapping/search";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchUserIdsParams,
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Turns standard stop word dictionary entries on or off for a given language.
*
* Required API Key ACLs:
* - editSettings
* @param dictionarySettingsParams - The dictionarySettingsParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
setDictionarySettings(dictionarySettingsParams, requestOptions) {
if (!dictionarySettingsParams) {
throw new Error("Parameter `dictionarySettingsParams` is required when calling `setDictionarySettings`.");
}
if (!dictionarySettingsParams.disableStandardEntries) {
throw new Error(
"Parameter `dictionarySettingsParams.disableStandardEntries` is required when calling `setDictionarySettings`."
);
}
const requestPath = "/1/dictionaries/*/settings";
const headers = {};
const queryParameters = {};
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: dictionarySettingsParams
};
return transporter.request(request, requestOptions);
},
/**
* Update the specified index settings. Index settings that you don\'t specify are left unchanged. Specify `null` to reset a setting to its default value. For best performance, update the index settings before you add new records to your index.
*
* Required API Key ACLs:
* - editSettings
* @param setSettings - The setSettings object.
* @param setSettings.indexName - Name of the index on which to perform the operation.
* @param setSettings.indexSettings - The indexSettings object.
* @param setSettings.forwardToReplicas - Whether changes are applied to replica indices.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
setSettings({ indexName, indexSettings, forwardToReplicas }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `setSettings`.");
}
if (!indexSettings) {
throw new Error("Parameter `indexSettings` is required when calling `setSettings`.");
}
const requestPath = "/1/indexes/{indexName}/settings".replace("{indexName}", encodeURIComponent(indexName));
const headers = {};
const queryParameters = {};
if (forwardToReplicas !== void 0) {
queryParameters["forwardToReplicas"] = forwardToReplicas.toString();
}
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: indexSettings
};
return transporter.request(request, requestOptions);
},
/**
* Replaces the permissions of an existing API key. Any unspecified attribute resets that attribute to its default value.
*
* Required API Key ACLs:
* - admin
* @param updateApiKey - The updateApiKey object.
* @param updateApiKey.key - API key.
* @param updateApiKey.apiKey - The apiKey object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
updateApiKey({ key, apiKey }, requestOptions) {
if (!key) {
throw new Error("Parameter `key` is required when calling `updateApiKey`.");
}
if (!apiKey) {
throw new Error("Parameter `apiKey` is required when calling `updateApiKey`.");
}
if (!apiKey.acl) {
throw new Error("Parameter `apiKey.acl` is required when calling `updateApiKey`.");
}
const requestPath = "/1/keys/{key}".replace("{key}", encodeURIComponent(key));
const headers = {};
const queryParameters = {};
const request = {
method: "PUT",
path: requestPath,
queryParameters,
headers,
data: apiKey
};
return transporter.request(request, requestOptions);
}
};
}
// builds/node.ts
function searchClient(appId, apiKey, options) {
if (!appId || typeof appId !== "string") {
throw new Error("`appId` is missing.");
}
if (!apiKey || typeof apiKey !== "string") {
throw new Error("`apiKey` is missing.");
}
return {
...createSearchClient({
appId,
apiKey,
timeouts: {
connect: 2e3,
read: 5e3,
write: 3e4
},
logger: (0, import_client_common2.createNullLogger)(),
requester: (0, import_requester_node_http.createHttpRequester)(),
algoliaAgents: [{ segment: "Node.js", version: process.versions.node }],
responsesCache: (0, import_client_common2.createNullCache)(),
requestsCache: (0, import_client_common2.createNullCache)(),
hostsCache: (0, import_client_common2.createMemoryCache)(),
...options
}),
/**
* Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
*
* @summary Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
* @param generateSecuredApiKey - The `generateSecuredApiKey` object.
* @param generateSecuredApiKey.parentApiKey - The base API key from which to generate the new secured one.
* @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key.
*/
generateSecuredApiKey: ({ parentApiKey, restrictions = {} }) => {
let mergedRestrictions = restrictions;
if (restrictions.searchParams) {
mergedRestrictions = {
...restrictions,
...restrictions.searchParams
};
delete mergedRestrictions.searchParams;
}
mergedRestrictions = Object.keys(mergedRestrictions).sort().reduce(
(acc, key) => {
acc[key] = mergedRestrictions[key];
return acc;
},
{}
);
const queryParameters = (0, import_client_common2.serializeQueryParameters)(mergedRestrictions);
return Buffer.from(
(0, import_node_crypto.createHmac)("sha256", parentApiKey).update(queryParameters).digest("hex") + queryParameters
).toString("base64");
},
/**
* Helper: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
* See https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation details.
*
* @summary Helper: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
* @param accountCopyIndex - The `accountCopyIndex` object.
* @param accountCopyIndex.sourceIndexName - The name of the index to copy.
* @param accountCopyIndex.destinationAppID - The application ID to write the index to.
* @param accountCopyIndex.destinationApiKey - The API Key of the `destinationAppID` to write the index to, must have write ACLs.
* @param accountCopyIndex.destinationIndexName - The name of the index to write the copied index to.
* @param accountCopyIndex.batchSize - The size of the chunk of `objects`. Defaults to 1000.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `setSettings`, `saveRules`, `saveSynonyms` and `saveObjects` method and merged with the transporter requestOptions.
*/
async accountCopyIndex({
sourceIndexName,
destinationAppID,
destinationApiKey,
destinationIndexName,
batchSize
}, requestOptions) {
const responses = [];
if (this.appId === destinationAppID) {
throw new import_client_common2.IndicesInSameAppError();
}
if (!await this.indexExists({ indexName: sourceIndexName })) {
throw new import_client_common2.IndexNotFoundError(sourceIndexName);
}
const destinationClient = createSearchClient({
appId: destinationAppID,
apiKey: destinationApiKey,
timeouts: {
connect: 2e3,
read: 5e3,
write: 3e4
},
logger: (0, import_client_common2.createNullLogger)(),
requester: (0, import_requester_node_http.createHttpRequester)(),
algoliaAgents: [{ segment: "accountCopyIndex", version: process.versions.node }],
responsesCache: (0, import_client_common2.createNullCache)(),
requestsCache: (0, import_client_common2.createNullCache)(),
hostsCache: (0, import_client_common2.createMemoryCache)(),
...options
});
if (await destinationClient.indexExists({ indexName: destinationIndexName })) {
throw new import_client_common2.IndexAlreadyExistsError(destinationIndexName);
}
responses.push(
await destinationClient.setSettings(
{
indexName: destinationIndexName,
indexSettings: await this.getSettings({ indexName: sourceIndexName })
},
requestOptions
)
);
await this.browseRules({
indexName: sourceIndexName,
async aggregator(response) {
responses.push(
await destinationClient.saveRules(
{ indexName: destinationIndexName, rules: response.hits },
requestOptions
)
);
}
});
await this.browseSynonyms({
indexName: sourceIndexName,
async aggregator(response) {
responses.push(
await destinationClient.saveSynonyms(
{ indexName: destinationIndexName, synonymHit: response.hits },
requestOptions
)
);
}
});
await this.browseObjects({
indexName: sourceIndexName,
browseParams: batchSize ? { hitsPerPage: batchSize } : void 0,
async aggregator(response) {
responses.push(
...await destinationClient.saveObjects(
{ indexName: destinationIndexName, objects: response.hits, batchSize },
requestOptions
)
);
}
});
for (const response of responses) {
await destinationClient.waitForTask({ indexName: destinationIndexName, taskID: response.taskID });
}
},
/**
* Helper: Retrieves the remaining validity of the previous generated `securedApiKey`, the `ValidUntil` parameter must have been provided.
*
* @summary Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `ValidUntil` parameter must have been provided.
* @param getSecuredApiKeyRemainingValidity - The `getSecuredApiKeyRemainingValidity` object.
* @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method.
*/
getSecuredApiKeyRemainingValidity: ({ securedApiKey }) => {
const decodedString = atob(securedApiKey);
const regex = /validUntil=(\d+)/;
const match = decodedString.match(regex);
if (match === null) {
throw new Error("validUntil not found in given secured api key.");
}
return parseInt(match[1], 10) - Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
apiClientVersion,
searchClient
});
//# sourceMappingURL=node.cjs.map