Skip to content

Commit 3f60273

Browse files
chore: ACLs (generated)
Co-authored-by: shortcuts <[email protected]>
1 parent f100296 commit 3f60273

File tree

9 files changed

+380
-5
lines changed

9 files changed

+380
-5
lines changed

clients/algoliasearch-client-javascript/packages/client-search/builds/fetch.ts

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ export type SearchClient = ReturnType<typeof createSearchClient> & SearchClientN
44

55
import { createHmac } from 'node:crypto';
66

7-
import { createMemoryCache, createNullCache, createNullLogger, serializeQueryParameters } from '@algolia/client-common';
7+
import {
8+
IndexAlreadyExistsError,
9+
IndexNotFoundError,
10+
IndicesInSameAppError,
11+
createMemoryCache,
12+
createNullCache,
13+
createNullLogger,
14+
serializeQueryParameters,
15+
} from '@algolia/client-common';
816
import { createFetchRequester } from '@algolia/requester-fetch';
17+
import { createHttpRequester } from '@algolia/requester-node-http';
918

10-
import type { ClientOptions } from '@algolia/client-common';
19+
import type { ClientOptions, RequestOptions } from '@algolia/client-common';
1120

1221
import { createSearchClient } from '../src/searchClient';
1322

@@ -16,9 +25,14 @@ export { apiClientVersion } from '../src/searchClient';
1625
export * from '../model';
1726

1827
import type {
28+
AccountCopyIndexOptions,
29+
BrowseResponse,
1930
GenerateSecuredApiKeyOptions,
2031
GetSecuredApiKeyRemainingValidityOptions,
2132
SearchClientNodeHelpers,
33+
SearchRulesResponse,
34+
SearchSynonymsResponse,
35+
UpdatedAtResponse,
2236
} from '../model';
2337

2438
export function searchClient(appId: string, apiKey: string, options?: ClientOptions): SearchClient {
@@ -82,6 +96,104 @@ export function searchClient(appId: string, apiKey: string, options?: ClientOpti
8296
createHmac('sha256', parentApiKey).update(queryParameters).digest('hex') + queryParameters,
8397
).toString('base64');
8498
},
99+
100+
/**
101+
* Helper: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
102+
* See https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation details.
103+
*
104+
* @summary Helper: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
105+
* @param accountCopyIndex - The `accountCopyIndex` object.
106+
* @param accountCopyIndex.sourceIndexName - The name of the index to copy.
107+
* @param accountCopyIndex.destinationAppID - The application ID to write the index to.
108+
* @param accountCopyIndex.destinationApiKey - The API Key of the `destinationAppID` to write the index to, must have write ACLs.
109+
* @param accountCopyIndex.destinationIndexName - The name of the index to write the copied index to.
110+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `setSettings`, `saveRules`, `saveSynonyms` and `saveObjects` method and merged with the transporter requestOptions.
111+
*/
112+
async accountCopyIndex(
113+
{ sourceIndexName, destinationAppID, destinationApiKey, destinationIndexName }: AccountCopyIndexOptions,
114+
requestOptions?: RequestOptions,
115+
): Promise<void> {
116+
const responses: Array<{ taskID: UpdatedAtResponse['taskID'] }> = [];
117+
118+
if (this.appId === destinationAppID) {
119+
throw new IndicesInSameAppError();
120+
}
121+
122+
if (!(await this.indexExists({ indexName: sourceIndexName }))) {
123+
throw new IndexNotFoundError(sourceIndexName);
124+
}
125+
126+
const destinationClient = createSearchClient({
127+
appId: destinationAppID,
128+
apiKey: destinationApiKey,
129+
timeouts: {
130+
connect: 2000,
131+
read: 5000,
132+
write: 30000,
133+
},
134+
logger: createNullLogger(),
135+
requester: createHttpRequester(),
136+
algoliaAgents: [{ segment: 'accountCopyIndex', version: process.versions.node }],
137+
responsesCache: createNullCache(),
138+
requestsCache: createNullCache(),
139+
hostsCache: createMemoryCache(),
140+
...options,
141+
});
142+
143+
if (await destinationClient.indexExists({ indexName: destinationIndexName })) {
144+
throw new IndexAlreadyExistsError(destinationIndexName);
145+
}
146+
147+
responses.push(
148+
await destinationClient.setSettings(
149+
{
150+
indexName: destinationIndexName,
151+
indexSettings: await this.getSettings({ indexName: sourceIndexName }),
152+
},
153+
requestOptions,
154+
),
155+
);
156+
157+
await this.browseRules({
158+
indexName: sourceIndexName,
159+
async aggregator(response: SearchRulesResponse) {
160+
responses.push(
161+
await destinationClient.saveRules(
162+
{ indexName: destinationIndexName, rules: response.hits },
163+
requestOptions,
164+
),
165+
);
166+
},
167+
});
168+
169+
await this.browseSynonyms({
170+
indexName: sourceIndexName,
171+
async aggregator(response: SearchSynonymsResponse) {
172+
responses.push(
173+
await destinationClient.saveSynonyms(
174+
{ indexName: destinationIndexName, synonymHit: response.hits },
175+
requestOptions,
176+
),
177+
);
178+
},
179+
});
180+
181+
await this.browseObjects({
182+
indexName: sourceIndexName,
183+
async aggregator(response: BrowseResponse) {
184+
responses.push(
185+
...(await destinationClient.saveObjects(
186+
{ indexName: destinationIndexName, objects: response.hits },
187+
requestOptions,
188+
)),
189+
);
190+
},
191+
});
192+
193+
for (const response of responses) {
194+
await destinationClient.waitForTask({ indexName: destinationIndexName, taskID: response.taskID });
195+
}
196+
},
85197
/**
86198
* Helper: Retrieves the remaining validity of the previous generated `securedApiKey`, the `ValidUntil` parameter must have been provided.
87199
*

clients/algoliasearch-client-javascript/packages/client-search/builds/node.ts

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ import { createHmac } from 'node:crypto';
66

77
import { createHttpRequester } from '@algolia/requester-node-http';
88

9-
import { createMemoryCache, createNullCache, createNullLogger, serializeQueryParameters } from '@algolia/client-common';
10-
11-
import type { ClientOptions } from '@algolia/client-common';
9+
import {
10+
IndexAlreadyExistsError,
11+
IndexNotFoundError,
12+
IndicesInSameAppError,
13+
createMemoryCache,
14+
createNullCache,
15+
createNullLogger,
16+
serializeQueryParameters,
17+
} from '@algolia/client-common';
18+
19+
import type { ClientOptions, RequestOptions } from '@algolia/client-common';
1220

1321
import { createSearchClient } from '../src/searchClient';
1422

@@ -17,9 +25,14 @@ export { apiClientVersion } from '../src/searchClient';
1725
export * from '../model';
1826

1927
import type {
28+
AccountCopyIndexOptions,
29+
BrowseResponse,
2030
GenerateSecuredApiKeyOptions,
2131
GetSecuredApiKeyRemainingValidityOptions,
2232
SearchClientNodeHelpers,
33+
SearchRulesResponse,
34+
SearchSynonymsResponse,
35+
UpdatedAtResponse,
2336
} from '../model';
2437

2538
export function searchClient(appId: string, apiKey: string, options?: ClientOptions): SearchClient {
@@ -83,6 +96,104 @@ export function searchClient(appId: string, apiKey: string, options?: ClientOpti
8396
createHmac('sha256', parentApiKey).update(queryParameters).digest('hex') + queryParameters,
8497
).toString('base64');
8598
},
99+
100+
/**
101+
* Helper: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
102+
* See https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation details.
103+
*
104+
* @summary Helper: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
105+
* @param accountCopyIndex - The `accountCopyIndex` object.
106+
* @param accountCopyIndex.sourceIndexName - The name of the index to copy.
107+
* @param accountCopyIndex.destinationAppID - The application ID to write the index to.
108+
* @param accountCopyIndex.destinationApiKey - The API Key of the `destinationAppID` to write the index to, must have write ACLs.
109+
* @param accountCopyIndex.destinationIndexName - The name of the index to write the copied index to.
110+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `setSettings`, `saveRules`, `saveSynonyms` and `saveObjects` method and merged with the transporter requestOptions.
111+
*/
112+
async accountCopyIndex(
113+
{ sourceIndexName, destinationAppID, destinationApiKey, destinationIndexName }: AccountCopyIndexOptions,
114+
requestOptions?: RequestOptions,
115+
): Promise<void> {
116+
const responses: Array<{ taskID: UpdatedAtResponse['taskID'] }> = [];
117+
118+
if (this.appId === destinationAppID) {
119+
throw new IndicesInSameAppError();
120+
}
121+
122+
if (!(await this.indexExists({ indexName: sourceIndexName }))) {
123+
throw new IndexNotFoundError(sourceIndexName);
124+
}
125+
126+
const destinationClient = createSearchClient({
127+
appId: destinationAppID,
128+
apiKey: destinationApiKey,
129+
timeouts: {
130+
connect: 2000,
131+
read: 5000,
132+
write: 30000,
133+
},
134+
logger: createNullLogger(),
135+
requester: createHttpRequester(),
136+
algoliaAgents: [{ segment: 'accountCopyIndex', version: process.versions.node }],
137+
responsesCache: createNullCache(),
138+
requestsCache: createNullCache(),
139+
hostsCache: createMemoryCache(),
140+
...options,
141+
});
142+
143+
if (await destinationClient.indexExists({ indexName: destinationIndexName })) {
144+
throw new IndexAlreadyExistsError(destinationIndexName);
145+
}
146+
147+
responses.push(
148+
await destinationClient.setSettings(
149+
{
150+
indexName: destinationIndexName,
151+
indexSettings: await this.getSettings({ indexName: sourceIndexName }),
152+
},
153+
requestOptions,
154+
),
155+
);
156+
157+
await this.browseRules({
158+
indexName: sourceIndexName,
159+
async aggregator(response: SearchRulesResponse) {
160+
responses.push(
161+
await destinationClient.saveRules(
162+
{ indexName: destinationIndexName, rules: response.hits },
163+
requestOptions,
164+
),
165+
);
166+
},
167+
});
168+
169+
await this.browseSynonyms({
170+
indexName: sourceIndexName,
171+
async aggregator(response: SearchSynonymsResponse) {
172+
responses.push(
173+
await destinationClient.saveSynonyms(
174+
{ indexName: destinationIndexName, synonymHit: response.hits },
175+
requestOptions,
176+
),
177+
);
178+
},
179+
});
180+
181+
await this.browseObjects({
182+
indexName: sourceIndexName,
183+
async aggregator(response: BrowseResponse) {
184+
responses.push(
185+
...(await destinationClient.saveObjects(
186+
{ indexName: destinationIndexName, objects: response.hits },
187+
requestOptions,
188+
)),
189+
);
190+
},
191+
});
192+
193+
for (const response of responses) {
194+
await destinationClient.waitForTask({ indexName: destinationIndexName, taskID: response.taskID });
195+
}
196+
},
86197
/**
87198
* Helper: Retrieves the remaining validity of the previous generated `securedApiKey`, the `ValidUntil` parameter must have been provided.
88199
*

clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ export type GetSecuredApiKeyRemainingValidityOptions = {
821821
};
822822

823823
export type SearchClientNodeHelpers = {
824+
accountCopyIndex: (opts: AccountCopyIndexOptions) => Promise<void>;
824825
generateSecuredApiKey: (opts: GenerateSecuredApiKeyOptions) => string;
825826
getSecuredApiKeyRemainingValidity: (opts: GetSecuredApiKeyRemainingValidityOptions) => number;
826827
};
@@ -877,3 +878,25 @@ export type ReplaceAllObjectsOptions = {
877878
*/
878879
scopes?: Array<ScopeType>;
879880
};
881+
882+
export type AccountCopyIndexOptions = {
883+
/**
884+
* The name of the index to copy to the `destinationClient`.
885+
*/
886+
sourceIndexName: string;
887+
888+
/**
889+
* The application ID to write the index to.
890+
*/
891+
destinationAppID: string;
892+
893+
/**
894+
* The API Key of the `destinationAppID` to write the index to, must have write ACLs.
895+
*/
896+
destinationApiKey: string;
897+
898+
/**
899+
* The name of the index to write the copy in.
900+
*/
901+
destinationIndexName: string;
902+
};

docs/bundled/search-snippets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,9 @@
22992299
"import": {
23002300
"default": "import { algoliasearch } from 'algoliasearch';"
23012301
},
2302+
"accountCopyIndex": {
2303+
"default": "const response = await client.accountCopyIndex({\n sourceIndexName: 'cts_e2e_account_copy_index_source_javascript',\n destinationAppID: 'test-app-id-destination',\n destinationApiKey: 'test-api-key-destination',\n destinationIndexName: 'cts_e2e_account_copy_index_destination_javascript',\n});"
2304+
},
23022305
"addApiKey": {
23032306
"minimal": "const response = await client.addApiKey({ acl: ['search', 'addObject'], description: 'my new api key' });",
23042307
"all": "const response = await client.addApiKey({\n acl: ['search', 'addObject'],\n description: 'my new api key',\n validity: 300,\n maxQueriesPerIPPerHour: 100,\n maxHitsPerQuery: 20,\n});"

docs/bundled/search.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23440,6 +23440,18 @@ components:
2344023440
properties:
2344123441
createdAt:
2344223442
$ref: '#/components/schemas/createdAt'
23443+
IndexInSameApp:
23444+
description: Indices are in the same application. Use operationIndex instead.
23445+
content:
23446+
application/json:
23447+
schema:
23448+
$ref: '#/components/schemas/ErrorBase'
23449+
IndexAlreadyExists:
23450+
description: Destination index already exists.
23451+
content:
23452+
application/json:
23453+
schema:
23454+
$ref: '#/components/schemas/ErrorBase'
2344323455
x-tagGroups:
2344423456
- name: Search and indexing
2344523457
tags:

docs/snippets/javascript/src/search.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44
import { algoliasearch } from 'algoliasearch';
55
// IMPORT<
66

7+
// Snippet for the accountCopyIndex method.
8+
//
9+
// call accountCopyIndex without error
10+
export async function snippetForAccountCopyIndex(): Promise<void> {
11+
// >SEPARATOR accountCopyIndex default
12+
// Initialize the client
13+
//
14+
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
15+
16+
// Call the API
17+
const response = await client.accountCopyIndex({
18+
sourceIndexName: 'cts_e2e_account_copy_index_source_javascript',
19+
destinationAppID: 'test-app-id-destination',
20+
destinationApiKey: 'test-api-key-destination',
21+
destinationIndexName: 'cts_e2e_account_copy_index_destination_javascript',
22+
});
23+
24+
// >LOG
25+
// use typed response
26+
console.log(response);
27+
// SEPARATOR<
28+
}
29+
730
// Snippet for the addApiKey method.
831
//
932
// minimal

0 commit comments

Comments
 (0)