Skip to content

Commit edc629d

Browse files
authored
fix(search): fix wait method for updateApiKey request (#1464)
1 parent a4309c7 commit edc629d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"bundlesize": [
9999
{
100100
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
101-
"maxSize": "7.95KB"
101+
"maxSize": "8KB"
102102
},
103103
{
104104
"path": "packages/algoliasearch/dist/algoliasearch-lite.umd.js",

packages/client-search/src/methods/client/updateApiKey.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MethodEnum } from '@algolia/requester-common';
99
import { RequestOptions } from '@algolia/transporter';
1010

1111
import {
12+
ApiKeyACLType,
1213
getApiKey,
1314
GetApiKeyResponse,
1415
SearchClient,
@@ -37,14 +38,32 @@ export const updateApiKey = (base: SearchClient) => {
3738
'maxHitsPerQuery',
3839
] as const;
3940

41+
// Check that all the fields retrieved through getApiKey are the same as the ones we wanted to update
4042
const hasChanged = (getApiKeyResponse: GetApiKeyResponse): boolean => {
4143
return Object.keys(updatedFields)
4244
.filter(
4345
(updatedField: any): updatedField is typeof apiKeyFields[number] =>
4446
apiKeyFields.indexOf(updatedField) !== -1
4547
)
4648
.every(updatedField => {
47-
return getApiKeyResponse[updatedField] === updatedFields[updatedField];
49+
// If the field is an array, we need to check that they are the same length and that all the values are the same
50+
if (
51+
Array.isArray(getApiKeyResponse[updatedField]) &&
52+
Array.isArray(updatedFields[updatedField])
53+
) {
54+
const getApiKeyResponseArray = getApiKeyResponse[updatedField] as
55+
| readonly ApiKeyACLType[]
56+
| readonly string[];
57+
58+
return (
59+
getApiKeyResponseArray.length === updatedFields[updatedField].length &&
60+
getApiKeyResponseArray.every(
61+
(value, index) => value === updatedFields[updatedField][index]
62+
)
63+
);
64+
} else {
65+
return getApiKeyResponse[updatedField] === updatedFields[updatedField];
66+
}
4867
});
4968
};
5069

0 commit comments

Comments
 (0)