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

455 lines
19 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,
recommendClient: () => recommendClient
});
module.exports = __toCommonJS(node_exports);
var import_requester_node_http = require("@algolia/requester-node-http");
var import_client_common2 = require("@algolia/client-common");
// src/recommendClient.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 createRecommendClient({
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: "Recommend",
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;
}
},
/**
* Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists. You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following: - Conditions `pattern` and `anchoring` are unavailable. - Condition `filters` triggers if the source item matches the specified filters. - Condition `filters` accepts numeric filters. - Consequence `params` only covers filtering parameters. - Consequence `automaticFacetFilters` doesn\'t require a facet value placeholder (it tries to match the data source item\'s attributes instead).
*
* Required API Key ACLs:
* - editSettings
* @param batchRecommendRules - The batchRecommendRules object.
* @param batchRecommendRules.indexName - Name of the index on which to perform the operation.
* @param batchRecommendRules.model - [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
* @param batchRecommendRules.recommendRule - The recommendRule object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
batchRecommendRules({ indexName, model, recommendRule }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `batchRecommendRules`.");
}
if (!model) {
throw new Error("Parameter `model` is required when calling `batchRecommendRules`.");
}
const requestPath = "/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}", encodeURIComponent(indexName)).replace("{model}", encodeURIComponent(model));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: recommendRule ? recommendRule : {}
};
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 a Recommend rule from a recommendation scenario.
*
* Required API Key ACLs:
* - editSettings
* @param deleteRecommendRule - The deleteRecommendRule object.
* @param deleteRecommendRule.indexName - Name of the index on which to perform the operation.
* @param deleteRecommendRule.model - [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
* @param deleteRecommendRule.objectID - Unique record identifier.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
deleteRecommendRule({ indexName, model, objectID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");
}
if (!model) {
throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");
}
const requestPath = "/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{model}", encodeURIComponent(model)).replace("{objectID}", encodeURIComponent(objectID));
const headers = {};
const queryParameters = {};
const request = {
method: "DELETE",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves a Recommend rule that you previously created in the Algolia dashboard.
*
* Required API Key ACLs:
* - settings
* @param getRecommendRule - The getRecommendRule object.
* @param getRecommendRule.indexName - Name of the index on which to perform the operation.
* @param getRecommendRule.model - [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
* @param getRecommendRule.objectID - Unique record identifier.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getRecommendRule({ indexName, model, objectID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");
}
if (!model) {
throw new Error("Parameter `model` is required when calling `getRecommendRule`.");
}
if (!objectID) {
throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");
}
const requestPath = "/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{model}", encodeURIComponent(model)).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. Deleting a Recommend rule is asynchronous. When you delete a rule, a task is created on a queue and completed depending on the load on the server. The API response includes a task ID that you can use to check the status.
*
* Required API Key ACLs:
* - editSettings
* @param getRecommendStatus - The getRecommendStatus object.
* @param getRecommendStatus.indexName - Name of the index on which to perform the operation.
* @param getRecommendStatus.model - [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
* @param getRecommendStatus.taskID - Unique task identifier.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getRecommendStatus({ indexName, model, taskID }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");
}
if (!model) {
throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");
}
if (!taskID) {
throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");
}
const requestPath = "/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}", encodeURIComponent(indexName)).replace("{model}", encodeURIComponent(model)).replace("{taskID}", encodeURIComponent(taskID));
const headers = {};
const queryParameters = {};
const request = {
method: "GET",
path: requestPath,
queryParameters,
headers
};
return transporter.request(request, requestOptions);
},
/**
* Retrieves recommendations from selected AI models.
*
* Required API Key ACLs:
* - search
* @param getRecommendationsParams - The getRecommendationsParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
getRecommendations(getRecommendationsParams, requestOptions) {
if (getRecommendationsParams && Array.isArray(getRecommendationsParams)) {
const newSignatureRequest = {
requests: getRecommendationsParams
};
getRecommendationsParams = newSignatureRequest;
}
if (!getRecommendationsParams) {
throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");
}
if (!getRecommendationsParams.requests) {
throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");
}
const requestPath = "/1/indexes/*/recommendations";
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: getRecommendationsParams,
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
},
/**
* Searches for Recommend rules. Use an empty query to list all rules for this recommendation scenario.
*
* Required API Key ACLs:
* - settings
* @param searchRecommendRules - The searchRecommendRules object.
* @param searchRecommendRules.indexName - Name of the index on which to perform the operation.
* @param searchRecommendRules.model - [Recommend model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
* @param searchRecommendRules.searchRecommendRulesParams - The searchRecommendRulesParams object.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchRecommendRules({ indexName, model, searchRecommendRulesParams }, requestOptions) {
if (!indexName) {
throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");
}
if (!model) {
throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");
}
const requestPath = "/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}", encodeURIComponent(indexName)).replace("{model}", encodeURIComponent(model));
const headers = {};
const queryParameters = {};
const request = {
method: "POST",
path: requestPath,
queryParameters,
headers,
data: searchRecommendRulesParams ? searchRecommendRulesParams : {},
useReadTransporter: true,
cacheable: true
};
return transporter.request(request, requestOptions);
}
};
}
// builds/node.ts
function recommendClient(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 {
...createRecommendClient({
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
})
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
apiClientVersion,
recommendClient
});
//# sourceMappingURL=node.cjs.map