generated from thegrind/laravel-dockerized
299 lines
11 KiB
JavaScript
299 lines
11 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);
|
|
|
|
// lite/builds/node.ts
|
|
var node_exports = {};
|
|
__export(node_exports, {
|
|
apiClientVersion: () => apiClientVersion,
|
|
liteClient: () => liteClient
|
|
});
|
|
module.exports = __toCommonJS(node_exports);
|
|
var import_requester_node_http = require("@algolia/requester-node-http");
|
|
var import_client_common2 = require("@algolia/client-common");
|
|
|
|
// lite/src/liteClient.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 createLiteClient({
|
|
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: "Lite",
|
|
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: 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);
|
|
},
|
|
/**
|
|
* 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);
|
|
},
|
|
/**
|
|
* 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);
|
|
},
|
|
/**
|
|
* 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);
|
|
}
|
|
};
|
|
}
|
|
|
|
// lite/builds/node.ts
|
|
function liteClient(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 createLiteClient({
|
|
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,
|
|
liteClient
|
|
});
|
|
//# sourceMappingURL=node.cjs.map
|