Skip to content

Commit

Permalink
feat(javascript): add replaceAllObjects
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#2768

Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Feb 26, 2024
1 parent f81a267 commit f778a5d
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"trailingComma": "es5",
"trailingComma": "all",
"singleQuote": true
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-terser": "0.4.4",
"@types/jest": "29.5.12",
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"@types/rollup-plugin-node-globals": "1.4.4",
"@types/semver": "7.5.7",
"@types/semver": "7.5.8",
"bundlesize2": "0.0.31",
"execa": "8.0.1",
"lerna": "8.0.0",
"nx": "18.0.4",
"nx": "18.0.5",
"rollup": "4.12.0",
"rollup-plugin-node-globals": "1.4.0",
"rollup-plugin-typescript2": "0.36.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/algoliasearch/lite/src/liteClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/algoliasearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3",
"@types/jest": "29.5.12",
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"jest": "29.7.0",
"rollup": "4.12.0",
"typescript": "5.3.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/client-abtesting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client-abtesting/src/abtestingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type { ABTest } from '../model/aBTest';
Expand Down
2 changes: 1 addition & 1 deletion packages/client-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client-analytics/src/analyticsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3",
"@types/jest": "29.5.12",
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"ts-jest": "29.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/client-insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client-insights/src/insightsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-personalization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-query-suggestions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type { BaseResponse } from '../model/baseResponse';
Expand Down
43 changes: 43 additions & 0 deletions packages/client-search/model/clientMethodProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,46 @@ export type WaitForApiKeyOptions = WaitForOptions & {
apiKey: Partial<ApiKey>;
}
);

export type GenerateSecuredApiKeyOptions = {
/**
* The base API key from which to generate the new secured one.
*/
parentApiKey: string;

/**
* A set of properties defining the restrictions of the secured API key.
*/
restrictions?: SecuredApiKeyRestrictions;
};

export type GetSecuredApiKeyRemainingValidityOptions = {
/**
* The secured API key generated with the `generateSecuredApiKey` method.
*/
securedApiKey: string;
};

export type SecuredApiKeyRestrictions = {
/**
* A Unix timestamp used to define the expiration date of the API key.
*/
validUntil?: number;

/**
* List of index names that can be queried.
*/
restrictIndices?: string[] | string;

/**
* IPv4 network allowed to use the generated key. This is used for more protection against API key leaking and reuse.
*/
restrictSources?: string;

/**
* Specify a user identifier. This is often used with rate limits.
*/
userToken?: string;

searchParams?: SearchParamsObject;
};
2 changes: 1 addition & 1 deletion packages/client-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
78 changes: 63 additions & 15 deletions packages/client-search/src/searchClient.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

import { createHmac } from 'crypto';

import {
createAuth,
createTransporter,
getAlgoliaAgent,
shuffle,
serializeQueryParameters,
createIterablePromise,
} from '@algolia/client-common';
import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
ApiError,
IterableOptions,
} from '@algolia/client-common';
Expand All @@ -25,8 +28,10 @@ import type { BatchResponse } from '../model/batchResponse';
import type { BrowseResponse } from '../model/browseResponse';
import type {
BrowseOptions,
WaitForTaskOptions,
GenerateSecuredApiKeyOptions,
GetSecuredApiKeyRemainingValidityOptions,
WaitForApiKeyOptions,
WaitForTaskOptions,
AddOrUpdateObjectProps,
AssignUserIdProps,
BatchProps,
Expand Down Expand Up @@ -222,7 +227,7 @@ export function createSearchClient({
* Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
*
* @summary Helper method that waits for a task to be published (completed).
* @param waitForTaskOptions - The waitForTaskOptions object.
* @param waitForTaskOptions - The `waitForTaskOptions` object.
* @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
* @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
* @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
Expand Down Expand Up @@ -258,7 +263,7 @@ export function createSearchClient({
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
*
* @summary Helper method that waits for an API key task to be processed.
* @param waitForApiKeyOptions - The waitForApiKeyOptions object.
* @param waitForApiKeyOptions - The `waitForApiKeyOptions` object.
* @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
* @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
* @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
Expand Down Expand Up @@ -332,7 +337,7 @@ export function createSearchClient({
* Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
*
* @summary Helper method that iterates on the `browse` method.
* @param browseObjects - The browseObjects object.
* @param browseObjects - The `browseObjects` object.
* @param browseObjects.indexName - The index in which to perform the request.
* @param browseObjects.browseParams - The `browse` parameters.
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is no `cursor` in the response.
Expand Down Expand Up @@ -369,11 +374,11 @@ export function createSearchClient({
* Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
*
* @summary Helper method that iterates on the `searchRules` method.
* @param browseObjects - The browseObjects object.
* @param browseObjects.indexName - The index in which to perform the request.
* @param browseObjects.searchRulesParams - The `searchRules` method parameters.
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
* @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param browseRules - The `browseRules` object.
* @param browseRules.indexName - The index in which to perform the request.
* @param browseRules.searchRulesParams - The `searchRules` method parameters.
* @param browseRules.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
* @param browseRules.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
*/
browseRules(
Expand Down Expand Up @@ -413,11 +418,11 @@ export function createSearchClient({
* Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
*
* @summary Helper method that iterates on the `searchSynonyms` method.
* @param browseObjects - The browseObjects object.
* @param browseObjects.indexName - The index in which to perform the request.
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
* @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param browseObjects.searchSynonymsParams - The `searchSynonyms` method parameters.
* @param browseSynonyms - The `browseSynonyms` object.
* @param browseSynonyms.indexName - The index in which to perform the request.
* @param browseSynonyms.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
* @param browseSynonyms.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
* @param browseSynonyms.searchSynonymsParams - The `searchSynonyms` method parameters.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
*/
browseSynonyms(
Expand Down Expand Up @@ -487,6 +492,49 @@ export function createSearchClient({
results: SearchForFacetValuesResponse[];
}>;
},

/**
* Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
*
* @summary Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
* @param generateSecuredApiKey - The `generateSecuredApiKey` object.
* @param generateSecuredApiKey.parentApiKey - The base API key from which to generate the new secured one.
* @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key.
*/
generateSecuredApiKey({
parentApiKey,
restrictions = {},
}: GenerateSecuredApiKeyOptions): string {
const queryParameters = serializeQueryParameters(restrictions);
return Buffer.from(
createHmac('sha256', parentApiKey)
.update(queryParameters)
.digest('hex') + queryParameters
).toString('base64');
},

/**
* Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `ValidUntil` parameter must have been provided.
*
* @summary Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
* @param getSecuredApiKeyRemainingValidity - The `getSecuredApiKeyRemainingValidity` object.
* @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method.
*/
getSecuredApiKeyRemainingValidity({
securedApiKey,
}: GetSecuredApiKeyRemainingValidityOptions): number {
const decodedString = Buffer.from(securedApiKey, 'base64').toString(
'ascii'
);
const regex = /validUntil=(\d+)/;
const match = decodedString.match(regex);

if (match === null) {
throw new Error('ValidUntil not found in given secured api key.');
}

return parseInt(match[1], 10) - Math.round(new Date().getTime() / 1000);
},
/**
* Add a new API key with specific permissions and restrictions. The request must be authenticated with the admin API key. The response returns an API key string.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/ingestion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ingestion/src/ingestionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type { Authentication } from '../model/authentication';
Expand Down
2 changes: 1 addition & 1 deletion packages/monitoring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@algolia/requester-node-http": "5.0.0-alpha.103"
},
"devDependencies": {
"@types/node": "20.11.19",
"@types/node": "20.11.20",
"rollup": "4.12.0",
"typescript": "5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/monitoring/src/monitoringClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
CreateClientOptions,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
QueryParameters,
} from '@algolia/client-common';

import type {
Expand Down
Loading

0 comments on commit f778a5d

Please sign in to comment.