Skip to content

Commit

Permalink
fix(search): fix wait method for updateApiKey request (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Jun 7, 2023
1 parent a4309c7 commit edc629d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -98,7 +98,7 @@
"bundlesize": [
{
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
"maxSize": "7.95KB"
"maxSize": "8KB"
},
{
"path": "packages/algoliasearch/dist/algoliasearch-lite.umd.js",
Expand Down
21 changes: 20 additions & 1 deletion packages/client-search/src/methods/client/updateApiKey.ts
Expand Up @@ -9,6 +9,7 @@ import { MethodEnum } from '@algolia/requester-common';
import { RequestOptions } from '@algolia/transporter';

import {
ApiKeyACLType,
getApiKey,
GetApiKeyResponse,
SearchClient,
Expand Down Expand Up @@ -37,14 +38,32 @@ export const updateApiKey = (base: SearchClient) => {
'maxHitsPerQuery',
] as const;

// Check that all the fields retrieved through getApiKey are the same as the ones we wanted to update
const hasChanged = (getApiKeyResponse: GetApiKeyResponse): boolean => {
return Object.keys(updatedFields)
.filter(
(updatedField: any): updatedField is typeof apiKeyFields[number] =>
apiKeyFields.indexOf(updatedField) !== -1
)
.every(updatedField => {
return getApiKeyResponse[updatedField] === updatedFields[updatedField];
// If the field is an array, we need to check that they are the same length and that all the values are the same
if (
Array.isArray(getApiKeyResponse[updatedField]) &&
Array.isArray(updatedFields[updatedField])
) {
const getApiKeyResponseArray = getApiKeyResponse[updatedField] as
| readonly ApiKeyACLType[]
| readonly string[];

return (
getApiKeyResponseArray.length === updatedFields[updatedField].length &&
getApiKeyResponseArray.every(
(value, index) => value === updatedFields[updatedField][index]
)
);
} else {
return getApiKeyResponse[updatedField] === updatedFields[updatedField];
}
});
};

Expand Down

0 comments on commit edc629d

Please sign in to comment.