Skip to content

chore: ie 11 support #1591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/algoliasearch/src/__tests__/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ describe('default preset', () => {
expect(() =>
// @ts-ignore
algoliasearch('APP_ID', 'API_KEY', { transformation: { region: 'cn' } })
).toThrow('`region` is required and must be one of the following: eu, us}`');
).toThrow('`region` is required and must be one of the following: eu, us');
});

test('throws when calling the transformation methods without init parameters', async () => {
await expect(
test('throws when calling the transformation methods without init parameters', () => {
expect(() =>
index.saveObjectsWithTransformation([{ objectID: 'bar', baz: 42 }], { waitForTasks: true })
).rejects.toThrow(
'`transformation.region` must be provided at client instantiation before calling this method.'
).toThrow(
'`options.transformation.region` must be provided at client instantiation before calling this method.'
);

await expect(
expect(() =>
index.partialUpdateObjectsWithTransformation([{ objectID: 'bar', baz: 42 }], {
waitForTasks: true,
})
).rejects.toThrow(
'`transformation.region` must be provided at client instantiation before calling this method.'
).toThrow(
'`options.transformation.region` must be provided at client instantiation before calling this method.'
);
});

Expand Down
5 changes: 4 additions & 1 deletion packages/algoliasearch/src/builds/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ import {
createIngestionClient,
partialUpdateObjectsWithTransformation,
saveObjectsWithTransformation,
transformationConfigurationError,
} from '../ingestion';
import {
AlgoliaSearchOptions,
Expand Down Expand Up @@ -261,7 +262,9 @@ export default function algoliasearch(

if (options && options.transformation) {
if (!options.transformation.region) {
throw new Error('`region` must be provided when leveraging the transformation pipeline');
throw transformationConfigurationError(
'`region` must be provided when leveraging the transformation pipeline'
);
}

ingestionTransporter = createIngestionClient({ ...options, ...commonOptions });
Expand Down
5 changes: 4 additions & 1 deletion packages/algoliasearch/src/builds/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ import {
createIngestionClient,
partialUpdateObjectsWithTransformation,
saveObjectsWithTransformation,
transformationConfigurationError,
} from '../ingestion';
import {
AlgoliaSearchOptions,
Expand Down Expand Up @@ -261,7 +262,9 @@ export default function algoliasearch(

if (options && options.transformation) {
if (!options.transformation.region) {
throw new Error('`region` must be provided when leveraging the transformation pipeline');
throw transformationConfigurationError(
'`region` must be provided when leveraging the transformation pipeline'
);
}

ingestionTransporter = createIngestionClient({ ...options, ...commonOptions });
Expand Down
53 changes: 36 additions & 17 deletions packages/algoliasearch/src/ingestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ export function createIngestionClient(
options: SearchClientOptions & ClientTransporterOptions & TransformationOptions
): IngestionClient {
if (!options || !options.transformation || !options.transformation.region) {
throw new Error('`region` must be provided when leveraging the transformation pipeline');
throw transformationConfigurationError(
'`region` must be provided when leveraging the transformation pipeline'
);
}

if (options.transformation.region !== 'eu' && options.transformation.region !== 'us') {
throw new Error('`region` is required and must be one of the following: eu, us');
throw transformationConfigurationError(
'`region` is required and must be one of the following: eu, us'
);
}

const appId = options.appId;
Expand Down Expand Up @@ -66,29 +70,37 @@ export function createIngestionClient(
transporter.responsesCache.clear(),
]).then(() => undefined);
},
async push(
push(
{ indexName, pushTaskPayload, watch }: PushProps,
requestOptions?: RequestOptions
): Promise<WatchResponse> {
): Readonly<Promise<WatchResponse>> {
if (!indexName) {
throw new Error('Parameter `indexName` is required when calling `push`.');
throw transformationConfigurationError(
'Parameter `indexName` is required when calling `push`.'
);
}

if (!pushTaskPayload) {
throw new Error('Parameter `pushTaskPayload` is required when calling `push`.');
throw transformationConfigurationError(
'Parameter `pushTaskPayload` is required when calling `push`.'
);
}

if (!pushTaskPayload.action) {
throw new Error('Parameter `pushTaskPayload.action` is required when calling `push`.');
throw transformationConfigurationError(
'Parameter `pushTaskPayload.action` is required when calling `push`.'
);
}

if (!pushTaskPayload.records) {
throw new Error('Parameter `pushTaskPayload.records` is required when calling `push`.');
throw transformationConfigurationError(
'Parameter `pushTaskPayload.records` is required when calling `push`.'
);
}

const opts: RequestOptions = requestOptions || { queryParameters: {} };

return await transporter.write<WatchResponse>(
return transporter.write<WatchResponse>(
{
method: MethodEnum.Post,
path: encode('1/push/%s', indexName),
Expand All @@ -107,12 +119,12 @@ export function createIngestionClient(
}

export function saveObjectsWithTransformation(indexName: string, client?: IngestionClient) {
return async (
return (
objects: ReadonlyArray<Readonly<Record<string, any>>>,
requestOptions?: RequestOptions & ChunkOptions & SaveObjectsOptions & PushOptions
): Promise<WatchResponse> => {
): Readonly<Promise<WatchResponse>> => {
if (!client) {
throw new Error(
throw transformationConfigurationError(
'`options.transformation.region` must be provided at client instantiation before calling this method.'
);
}
Expand All @@ -124,7 +136,7 @@ export function saveObjectsWithTransformation(indexName: string, client?: Ingest
: BatchActionEnum.UpdateObject;

/* eslint functional/immutable-data: "off" */
return await client.push(
return client.push(
{
indexName,
pushTaskPayload: { action, records: objects },
Expand All @@ -139,12 +151,12 @@ export function partialUpdateObjectsWithTransformation(
indexName: string,
client?: IngestionClient
) {
return async (
return (
objects: ReadonlyArray<Readonly<Record<string, any>>>,
requestOptions?: RequestOptions & ChunkOptions & PartialUpdateObjectsOptions & PushOptions
): Promise<WatchResponse> => {
): Readonly<Promise<WatchResponse>> => {
if (!client) {
throw new Error(
throw transformationConfigurationError(
'`options.transformation.region` must be provided at client instantiation before calling this method.'
);
}
Expand All @@ -156,7 +168,7 @@ export function partialUpdateObjectsWithTransformation(
: BatchActionEnum.PartialUpdateObjectNoCreate;

/* eslint functional/immutable-data: "off" */
return await client.push(
return client.push(
{
indexName,
pushTaskPayload: { action, records: objects },
Expand All @@ -166,3 +178,10 @@ export function partialUpdateObjectsWithTransformation(
);
};
}

export function transformationConfigurationError(message: string): Error {
return {
name: 'TransformationConfigurationError',
message,
};
}
6 changes: 3 additions & 3 deletions packages/algoliasearch/src/types/Ingestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type IngestionMethods = {
readonly saveObjectsWithTransformation: (
objects: ReadonlyArray<Readonly<Record<string, any>>>,
requestOptions?: RequestOptions & ChunkOptions & SaveObjectsOptions & PushOptions
) => Promise<WatchResponse>;
) => Readonly<Promise<WatchResponse>>;

/**
* Helper: Similar to the `partialUpdateObjects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must've been passed to the client instantiation method.
Expand All @@ -36,7 +36,7 @@ export type IngestionMethods = {
readonly partialUpdateObjectsWithTransformation: (
objects: ReadonlyArray<Readonly<Record<string, any>>>,
requestOptions?: RequestOptions & ChunkOptions & PartialUpdateObjectsOptions & PushOptions
) => Promise<WatchResponse>;
) => Readonly<Promise<WatchResponse>>;
};

export type WatchResponse = {
Expand Down Expand Up @@ -108,5 +108,5 @@ export type IngestionClient = BaseSearchClient & {
readonly push: (
{ indexName, pushTaskPayload, watch }: PushProps,
requestOptions?: RequestOptions
) => Promise<WatchResponse>;
) => Readonly<Promise<WatchResponse>>;
};