Skip to content

Commit a01ea4c

Browse files
feat(javascript): add transformationOptions and fix ingestion config leak (generated)
algolia/api-clients-automation#6252 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
1 parent e5dbcd7 commit a01ea4c

5 files changed

Lines changed: 121 additions & 85 deletions

File tree

packages/algoliasearch/__tests__/algoliasearch.common.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ describe('api', () => {
144144
});
145145

146146
describe('bridge methods', () => {
147-
test('throws when missing transformation.region', () => {
147+
test('throws when missing transformationOptions.region', () => {
148148
//@ts-expect-error
149-
expect(() => algoliasearch('APP_ID', 'API_KEY', { transformation: {} })).toThrow(
150-
'`region` must be provided when leveraging the transformation pipeline',
149+
expect(() => algoliasearch('APP_ID', 'API_KEY', { transformationOptions: {} })).toThrow(
150+
'`region` is required in `transformationOptions`.',
151151
);
152152
});
153153

@@ -158,15 +158,15 @@ describe('api', () => {
158158
objects: [{ objectID: 'bar', baz: 42 }],
159159
waitForTasks: true,
160160
}),
161-
).rejects.toThrow('`transformation.region` must be provided at client instantiation before calling this method.');
161+
).rejects.toThrow('`transformationOptions` must be set in the client config before calling this method.');
162162

163163
await expect(
164164
client.partialUpdateObjectsWithTransformation({
165165
indexName: 'foo',
166166
objects: [{ objectID: 'bar', baz: 42 }],
167167
waitForTasks: true,
168168
}),
169-
).rejects.toThrow('`transformation.region` must be provided at client instantiation before calling this method.');
169+
).rejects.toThrow('`transformationOptions` must be set in the client config before calling this method.');
170170
});
171171
});
172172
});

packages/algoliasearch/builds/browser.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export type Algoliasearch = SearchClient & {
110110

111111
export type TransformationOptions = {
112112
// When provided, a second transporter will be created in order to leverage the `*WithTransformation` methods exposed by the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
113+
transformationOptions?: {
114+
region: IngestionRegion;
115+
} & ClientOptions;
116+
117+
/** @deprecated Use `transformationOptions` instead. */
113118
transformation?:
114119
| {
115120
// The region of your Algolia application ID, used to target the correct hosts of the transformation service.
@@ -133,14 +138,24 @@ export function algoliasearch(
133138

134139
const client = searchClient(appId, apiKey, options);
135140

136-
let ingestionTransporter: IngestionClient | undefined;
141+
let transformationConfig: ({ region: IngestionRegion } & ClientOptions) | undefined;
142+
143+
if (options?.transformationOptions) {
144+
transformationConfig = options.transformationOptions;
145+
} else if (options?.transformation) {
146+
transformationConfig = { region: options.transformation.region };
147+
}
137148

138-
if (options?.transformation) {
139-
if (!options.transformation.region) {
140-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
149+
let ingestionTransporter: IngestionClient | undefined;
150+
if (transformationConfig) {
151+
if (!transformationConfig.region) {
152+
throw new Error(
153+
'`region` is required in `transformationOptions`. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
154+
);
141155
}
142156

143-
ingestionTransporter = ingestionClient(appId, apiKey, options.transformation.region, options);
157+
const { region, ...ingestionOptions } = transformationConfig;
158+
ingestionTransporter = ingestionClient(appId, apiKey, region, ingestionOptions);
144159
}
145160

146161
return {
@@ -151,11 +166,9 @@ export function algoliasearch(
151166
requestOptions,
152167
): Promise<Array<WatchResponse>> {
153168
if (!ingestionTransporter) {
154-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
155-
}
156-
157-
if (!options?.transformation?.region) {
158-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
169+
throw new Error(
170+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
171+
);
159172
}
160173

161174
return ingestionTransporter.chunkedPush(
@@ -169,11 +182,9 @@ export function algoliasearch(
169182
requestOptions,
170183
): Promise<Array<WatchResponse>> {
171184
if (!ingestionTransporter) {
172-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
173-
}
174-
175-
if (!options?.transformation?.region) {
176-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
185+
throw new Error(
186+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
187+
);
177188
}
178189

179190
return ingestionTransporter.chunkedPush(
@@ -192,11 +203,9 @@ export function algoliasearch(
192203
requestOptions?: RequestOptions | undefined,
193204
): Promise<ReplaceAllObjectsWithTransformationResponse> {
194205
if (!ingestionTransporter) {
195-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
196-
}
197-
198-
if (!options?.transformation?.region) {
199-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
206+
throw new Error(
207+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
208+
);
200209
}
201210

202211
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;

packages/algoliasearch/builds/fetch.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export type Algoliasearch = SearchClient & {
110110

111111
export type TransformationOptions = {
112112
// When provided, a second transporter will be created in order to leverage the `*WithTransformation` methods exposed by the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
113+
transformationOptions?: {
114+
region: IngestionRegion;
115+
} & ClientOptions;
116+
117+
/** @deprecated Use `transformationOptions` instead. */
113118
transformation?:
114119
| {
115120
// The region of your Algolia application ID, used to target the correct hosts of the transformation service.
@@ -133,14 +138,24 @@ export function algoliasearch(
133138

134139
const client = searchClient(appId, apiKey, options);
135140

136-
let ingestionTransporter: IngestionClient | undefined;
141+
let transformationConfig: ({ region: IngestionRegion } & ClientOptions) | undefined;
142+
143+
if (options?.transformationOptions) {
144+
transformationConfig = options.transformationOptions;
145+
} else if (options?.transformation) {
146+
transformationConfig = { region: options.transformation.region };
147+
}
137148

138-
if (options?.transformation) {
139-
if (!options.transformation.region) {
140-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
149+
let ingestionTransporter: IngestionClient | undefined;
150+
if (transformationConfig) {
151+
if (!transformationConfig.region) {
152+
throw new Error(
153+
'`region` is required in `transformationOptions`. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
154+
);
141155
}
142156

143-
ingestionTransporter = ingestionClient(appId, apiKey, options.transformation.region, options);
157+
const { region, ...ingestionOptions } = transformationConfig;
158+
ingestionTransporter = ingestionClient(appId, apiKey, region, ingestionOptions);
144159
}
145160

146161
return {
@@ -151,11 +166,9 @@ export function algoliasearch(
151166
requestOptions,
152167
): Promise<Array<WatchResponse>> {
153168
if (!ingestionTransporter) {
154-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
155-
}
156-
157-
if (!options?.transformation?.region) {
158-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
169+
throw new Error(
170+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
171+
);
159172
}
160173

161174
return ingestionTransporter.chunkedPush(
@@ -169,11 +182,9 @@ export function algoliasearch(
169182
requestOptions,
170183
): Promise<Array<WatchResponse>> {
171184
if (!ingestionTransporter) {
172-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
173-
}
174-
175-
if (!options?.transformation?.region) {
176-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
185+
throw new Error(
186+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
187+
);
177188
}
178189

179190
return ingestionTransporter.chunkedPush(
@@ -192,11 +203,9 @@ export function algoliasearch(
192203
requestOptions?: RequestOptions | undefined,
193204
): Promise<ReplaceAllObjectsWithTransformationResponse> {
194205
if (!ingestionTransporter) {
195-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
196-
}
197-
198-
if (!options?.transformation?.region) {
199-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
206+
throw new Error(
207+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
208+
);
200209
}
201210

202211
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;

packages/algoliasearch/builds/node.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export type Algoliasearch = SearchClient & {
110110

111111
export type TransformationOptions = {
112112
// When provided, a second transporter will be created in order to leverage the `*WithTransformation` methods exposed by the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
113+
transformationOptions?: {
114+
region: IngestionRegion;
115+
} & ClientOptions;
116+
117+
/** @deprecated Use `transformationOptions` instead. */
113118
transformation?:
114119
| {
115120
// The region of your Algolia application ID, used to target the correct hosts of the transformation service.
@@ -133,14 +138,24 @@ export function algoliasearch(
133138

134139
const client = searchClient(appId, apiKey, options);
135140

136-
let ingestionTransporter: IngestionClient | undefined;
141+
let transformationConfig: ({ region: IngestionRegion } & ClientOptions) | undefined;
142+
143+
if (options?.transformationOptions) {
144+
transformationConfig = options.transformationOptions;
145+
} else if (options?.transformation) {
146+
transformationConfig = { region: options.transformation.region };
147+
}
137148

138-
if (options?.transformation) {
139-
if (!options.transformation.region) {
140-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
149+
let ingestionTransporter: IngestionClient | undefined;
150+
if (transformationConfig) {
151+
if (!transformationConfig.region) {
152+
throw new Error(
153+
'`region` is required in `transformationOptions`. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
154+
);
141155
}
142156

143-
ingestionTransporter = ingestionClient(appId, apiKey, options.transformation.region, options);
157+
const { region, ...ingestionOptions } = transformationConfig;
158+
ingestionTransporter = ingestionClient(appId, apiKey, region, ingestionOptions);
144159
}
145160

146161
return {
@@ -151,11 +166,9 @@ export function algoliasearch(
151166
requestOptions,
152167
): Promise<Array<WatchResponse>> {
153168
if (!ingestionTransporter) {
154-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
155-
}
156-
157-
if (!options?.transformation?.region) {
158-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
169+
throw new Error(
170+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
171+
);
159172
}
160173

161174
return ingestionTransporter.chunkedPush(
@@ -169,11 +182,9 @@ export function algoliasearch(
169182
requestOptions,
170183
): Promise<Array<WatchResponse>> {
171184
if (!ingestionTransporter) {
172-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
173-
}
174-
175-
if (!options?.transformation?.region) {
176-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
185+
throw new Error(
186+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
187+
);
177188
}
178189

179190
return ingestionTransporter.chunkedPush(
@@ -192,11 +203,9 @@ export function algoliasearch(
192203
requestOptions?: RequestOptions | undefined,
193204
): Promise<ReplaceAllObjectsWithTransformationResponse> {
194205
if (!ingestionTransporter) {
195-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
196-
}
197-
198-
if (!options?.transformation?.region) {
199-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
206+
throw new Error(
207+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
208+
);
200209
}
201210

202211
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;

packages/algoliasearch/builds/worker.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export type Algoliasearch = SearchClient & {
110110

111111
export type TransformationOptions = {
112112
// When provided, a second transporter will be created in order to leverage the `*WithTransformation` methods exposed by the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
113+
transformationOptions?: {
114+
region: IngestionRegion;
115+
} & ClientOptions;
116+
117+
/** @deprecated Use `transformationOptions` instead. */
113118
transformation?:
114119
| {
115120
// The region of your Algolia application ID, used to target the correct hosts of the transformation service.
@@ -133,14 +138,24 @@ export function algoliasearch(
133138

134139
const client = searchClient(appId, apiKey, options);
135140

136-
let ingestionTransporter: IngestionClient | undefined;
141+
let transformationConfig: ({ region: IngestionRegion } & ClientOptions) | undefined;
142+
143+
if (options?.transformationOptions) {
144+
transformationConfig = options.transformationOptions;
145+
} else if (options?.transformation) {
146+
transformationConfig = { region: options.transformation.region };
147+
}
137148

138-
if (options?.transformation) {
139-
if (!options.transformation.region) {
140-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
149+
let ingestionTransporter: IngestionClient | undefined;
150+
if (transformationConfig) {
151+
if (!transformationConfig.region) {
152+
throw new Error(
153+
'`region` is required in `transformationOptions`. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
154+
);
141155
}
142156

143-
ingestionTransporter = ingestionClient(appId, apiKey, options.transformation.region, options);
157+
const { region, ...ingestionOptions } = transformationConfig;
158+
ingestionTransporter = ingestionClient(appId, apiKey, region, ingestionOptions);
144159
}
145160

146161
return {
@@ -151,11 +166,9 @@ export function algoliasearch(
151166
requestOptions,
152167
): Promise<Array<WatchResponse>> {
153168
if (!ingestionTransporter) {
154-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
155-
}
156-
157-
if (!options?.transformation?.region) {
158-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
169+
throw new Error(
170+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
171+
);
159172
}
160173

161174
return ingestionTransporter.chunkedPush(
@@ -169,11 +182,9 @@ export function algoliasearch(
169182
requestOptions,
170183
): Promise<Array<WatchResponse>> {
171184
if (!ingestionTransporter) {
172-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
173-
}
174-
175-
if (!options?.transformation?.region) {
176-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
185+
throw new Error(
186+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
187+
);
177188
}
178189

179190
return ingestionTransporter.chunkedPush(
@@ -192,11 +203,9 @@ export function algoliasearch(
192203
requestOptions?: RequestOptions | undefined,
193204
): Promise<ReplaceAllObjectsWithTransformationResponse> {
194205
if (!ingestionTransporter) {
195-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
196-
}
197-
198-
if (!options?.transformation?.region) {
199-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
206+
throw new Error(
207+
'`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/',
208+
);
200209
}
201210

202211
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;

0 commit comments

Comments
 (0)