Skip to content

Commit 1c0387e

Browse files
chore: generated code for commit cefa6674. [skip ci]
algolia/api-clients-automation@cefa667 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent b275d77 commit 1c0387e

File tree

7 files changed

+55
-12
lines changed

7 files changed

+55
-12
lines changed

packages/algoliasearch/builds/node.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,29 @@ export function algoliasearch(
168168
parentApiKey,
169169
restrictions = {},
170170
}: GenerateSecuredApiKeyOptions): string {
171-
const queryParameters = serializeQueryParameters(restrictions);
171+
let mergedRestrictions = restrictions;
172+
if (restrictions.searchParams) {
173+
// merge searchParams with the root restrictions
174+
mergedRestrictions = {
175+
...restrictions,
176+
...restrictions.searchParams,
177+
};
178+
179+
delete mergedRestrictions.searchParams;
180+
}
181+
182+
mergedRestrictions = Object.keys(mergedRestrictions)
183+
.sort()
184+
.reduce(
185+
(acc, key) => {
186+
// eslint-disable-next-line no-param-reassign
187+
acc[key] = (mergedRestrictions as any)[key];
188+
return acc;
189+
},
190+
{} as Record<string, unknown>
191+
);
192+
193+
const queryParameters = serializeQueryParameters(mergedRestrictions);
172194
return Buffer.from(
173195
createHmac('sha256', parentApiKey)
174196
.update(queryParameters)

packages/client-common/src/transporter/helpers.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ export function serializeUrl(
4242
}
4343

4444
export function serializeQueryParameters(parameters: QueryParameters): string {
45-
const isObjectOrArray = (value: any): boolean =>
46-
Object.prototype.toString.call(value) === '[object Object]' ||
47-
Object.prototype.toString.call(value) === '[object Array]';
48-
4945
return Object.keys(parameters)
46+
.filter((key) => parameters[key] !== undefined)
47+
.sort()
5048
.map(
5149
(key) =>
5250
`${key}=${encodeURIComponent(
53-
isObjectOrArray(parameters[key])
54-
? JSON.stringify(parameters[key])
51+
Object.prototype.toString.call(parameters[key]) === '[object Array]'
52+
? parameters[key].join(',')
5553
: parameters[key]
5654
).replaceAll('+', '%20')}`
5755
)

packages/client-search/builds/node.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,29 @@ export function searchClient(
7070
parentApiKey,
7171
restrictions = {},
7272
}: GenerateSecuredApiKeyOptions): string {
73-
const queryParameters = serializeQueryParameters(restrictions);
73+
let mergedRestrictions = restrictions;
74+
if (restrictions.searchParams) {
75+
// merge searchParams with the root restrictions
76+
mergedRestrictions = {
77+
...restrictions,
78+
...restrictions.searchParams,
79+
};
80+
81+
delete mergedRestrictions.searchParams;
82+
}
83+
84+
mergedRestrictions = Object.keys(mergedRestrictions)
85+
.sort()
86+
.reduce(
87+
(acc, key) => {
88+
// eslint-disable-next-line no-param-reassign
89+
acc[key] = (mergedRestrictions as any)[key];
90+
return acc;
91+
},
92+
{} as Record<string, unknown>
93+
);
94+
95+
const queryParameters = serializeQueryParameters(mergedRestrictions);
7496
return Buffer.from(
7597
createHmac('sha256', parentApiKey)
7698
.update(queryParameters)

packages/client-search/model/clientMethodProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type { SearchParams } from './searchParams';
2525
import type { SearchParamsObject } from './searchParamsObject';
2626
import type { SearchRulesParams } from './searchRulesParams';
2727
import type { SearchSynonymsParams } from './searchSynonymsParams';
28-
import type { SecuredAPIKeyRestrictions } from './securedAPIKeyRestrictions';
28+
import type { SecuredApiKeyRestrictions } from './securedApiKeyRestrictions';
2929
import type { Source } from './source';
3030
import type { SynonymHit } from './synonymHit';
3131

@@ -796,7 +796,7 @@ export type GenerateSecuredApiKeyOptions = {
796796
/**
797797
* A set of properties defining the restrictions of the secured API key.
798798
*/
799-
restrictions?: SecuredAPIKeyRestrictions;
799+
restrictions?: SecuredApiKeyRestrictions;
800800
};
801801

802802
export type GetSecuredApiKeyRemainingValidityOptions = {

packages/client-search/model/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export * from './searchTypeDefault';
143143
export * from './searchTypeFacet';
144144
export * from './searchUserIdsParams';
145145
export * from './searchUserIdsResponse';
146-
export * from './securedAPIKeyRestrictions';
146+
export * from './securedApiKeyRestrictions';
147147
export * from './semanticSearch';
148148
export * from './snippetResult';
149149
export * from './snippetResultOption';

packages/client-search/model/securedAPIKeyRestrictions.ts renamed to packages/client-search/model/securedApiKeyRestrictions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import type { SearchParamsObject } from './searchParamsObject';
44

5-
export type SecuredAPIKeyRestrictions = {
5+
export type SecuredApiKeyRestrictions = {
66
searchParams?: SearchParamsObject;
77

88
/**

packages/client-search/src/searchClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ export function createSearchClient({
647647

648648
return { copyOperationResponse, batchResponses, moveOperationResponse };
649649
},
650+
650651
/**
651652
* Creates a new API key with specific permissions and restrictions.
652653
*

0 commit comments

Comments
 (0)