Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request(options: any = {}): Request {
const headers: { readonly [key: string]: string } = {
'X-Default-Header': 'Default value',
};
if (options.url !== undefined) {
// eslint-disable-next-line no-param-reassign
options.url +=
(options.url.includes('?') ? '&' : '?') +
encode('%s=%s', 'x-algolia-agent', `Algolia for JavaScript (${version}); Browser`);
}
return {
data: '{}',
headers,
method: MethodEnum.Post,
connectTimeout: 1,
responseTimeout: 2,
...options,
};
},
};
return (
requestOptions?: ClearSynonymsOptions & RequestOptions
): Readonly> => {
const { forwardToReplicas, ...options } = requestOptions || {};
const mappedRequestOptions = createMappedRequestOptions(options);
if (forwardToReplicas) {
mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data
}
return createWaitablePromise(
base.transporter.write(
{
method: MethodEnum.Post,
path: encode('1/indexes/%s/synonyms/clear', base.indexName),
},
mappedRequestOptions
),
(response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
);
};
};
return (requestOptions?: RequestOptions): Readonly> => {
const mappedRequestOptions = createMappedRequestOptions(requestOptions);
// eslint-disable-next-line functional/immutable-data
mappedRequestOptions.queryParameters.getVersion = '2';
return base.transporter.read(
{
method: MethodEnum.Get,
path: encode('1/indexes/%s/settings', base.indexName),
},
mappedRequestOptions
);
};
};
return (
requestOptions?: ClearSynonymsOptions & RequestOptions
): Readonly> => {
const { forwardToReplicas, ...options } = requestOptions || {};
const mappedRequestOptions = createMappedRequestOptions(options);
if (forwardToReplicas) {
mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data
}
return createWaitablePromise(
base.transporter.write(
{
method: MethodEnum.Post,
path: encode('1/indexes/%s/synonyms/clear', base.indexName),
},
mappedRequestOptions
),
(response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
);
};
};
return (
objects: ReadonlyArray<{ readonly [key: string]: any }>,
requestOptions?: RequestOptions & ChunkOptions & SaveObjectsOptions
): Readonly> => {
const { autoGenerateObjectIDIfNotExist, ...options } = requestOptions || {};
const action = autoGenerateObjectIDIfNotExist
? BatchActionEnum.AddObject
: BatchActionEnum.UpdateObject;
if (action === BatchActionEnum.UpdateObject) {
// eslint-disable-next-line functional/no-loop-statement
for (const object of objects) {
if (object.objectID === undefined) {
return createWaitablePromise(Promise.reject(createMissingObjectIDError()));
}
}
}
return chunk(base)(objects, action, options);
};
};
return (
objectID: string,
requestOptions?: RequestOptions
): Readonly> => {
const { forwardToReplicas, ...options } = requestOptions || {};
const mappedRequestOptions = createMappedRequestOptions(options);
if (forwardToReplicas) {
mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data
}
return createWaitablePromise(
base.transporter.write(
{
method: MethodEnum.Delete,
path: encode('1/indexes/%s/rules/%s', base.indexName, objectID),
},
mappedRequestOptions
),
(response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
);
};
};
const transporter = createTransporter({
...options,
// No retry strategy on recommendation client
hostsCache: createNullCache(),
});
const appId = options.appId;
transporter.setHosts([{ url: `recommendation.${region}.algolia.com`, accept: CallEnum.Any }]);
transporter.addHeaders({
...auth.headers(),
...{ 'content-type': 'application/json' },
});
transporter.addQueryParameters(auth.queryParameters());
return addMethods({ appId, transporter }, options.methods);
};
const transporter = createTransporter({
...options,
// No retry strategy on recommendation client
hostsCache: createNullCache(),
});
const appId = options.appId;
transporter.setHosts([{ url: `analytics.${region}.algolia.com`, accept: CallEnum.Any }]);
transporter.addHeaders({
...auth.headers(),
...{ 'content-type': 'application/json' },
});
transporter.addQueryParameters(auth.queryParameters());
return addMethods({ appId, transporter }, options.methods);
};
> = options => {
const region = options.region || 'us';
const auth = createAuth(AuthMode.WithinHeaders, options.appId, options.apiKey);
const transporter = createTransporter({
...options,
// No retry strategy on recommendation client
hostsCache: createNullCache(),
});
const appId = options.appId;
transporter.setHosts([{ url: `analytics.${region}.algolia.com`, accept: CallEnum.Any }]);
transporter.addHeaders({
...auth.headers(),
...{ 'content-type': 'application/json' },
});
transporter.addQueryParameters(auth.queryParameters());
> = options => {
const region = options.region || 'us';
const auth = createAuth(AuthMode.WithinHeaders, options.appId, options.apiKey);
const transporter = createTransporter({
...options,
// No retry strategy on recommendation client
hostsCache: createNullCache(),
});
const appId = options.appId;
transporter.setHosts([{ url: `recommendation.${region}.algolia.com`, accept: CallEnum.Any }]);
transporter.addHeaders({
...auth.headers(),
...{ 'content-type': 'application/json' },
});
transporter.addQueryParameters(auth.queryParameters());