File tree Expand file tree Collapse file tree 6 files changed +38
-33
lines changed Expand file tree Collapse file tree 6 files changed +38
-33
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export class TestSuite {
41
41
appIdEnv : string = 'ALGOLIA_APPLICATION_ID_1' ,
42
42
apiKeyEnv : string = 'ALGOLIA_ADMIN_KEY_1'
43
43
) {
44
- let client = this . algoliasearch ( `${ process . env [ appIdEnv ] } ` , `${ process . env [ apiKeyEnv ] } ` ) ;
44
+ const client = this . algoliasearch ( `${ process . env [ appIdEnv ] } ` , `${ process . env [ apiKeyEnv ] } ` ) ;
45
45
46
46
// To ensure `Consistency` during the Common Test Suite, we
47
47
// force the transporter to work with a single host in the
@@ -59,8 +59,7 @@ export class TestSuite {
59
59
} ;
60
60
61
61
if ( testing . isBrowserLite ( ) ) {
62
- // @ts -ignore
63
- client = addMethods ( client , {
62
+ return addMethods ( client , {
64
63
multipleBatch,
65
64
multipleGetObjects,
66
65
} ) ;
@@ -77,11 +76,10 @@ export class TestSuite {
77
76
}
78
77
79
78
public makeIndex ( indexName ?: string ) {
80
- let index = this . makeSearchClient ( ) . initIndex ( indexName || this . makeIndexName ( ) ) ;
79
+ const index = this . makeSearchClient ( ) . initIndex ( indexName || this . makeIndexName ( ) ) ;
81
80
82
81
if ( testing . isBrowserLite ( ) ) {
83
- // @ts -ignore
84
- index = addMethods ( index , {
82
+ return addMethods ( index , {
85
83
saveObjects,
86
84
setSettings,
87
85
delete : deleteIndex ,
Original file line number Diff line number Diff line change @@ -13,27 +13,30 @@ export function shuffle<TData>(array: TData[]): TData[] {
13
13
return array ;
14
14
}
15
15
16
- export function addMethods <
17
- TBase ,
18
- TMethods extends {
19
- readonly [ key : string ] : ( base : TBase ) => ( ...args : any ) => any ;
20
- }
21
- > (
16
+ type Methods < TBase > = {
17
+ // eslint-disable-next-line functional/prefer-readonly-type
18
+ readonly [ key : string ] : ( base : TBase ) => ( ...args : any [ ] ) => any ;
19
+ } ;
20
+
21
+ type AddedMethods < TBase , TMethods extends Methods < TBase > > = TBase &
22
+ {
23
+ [ TKey in keyof TMethods extends string ? keyof TMethods : never ] : ReturnType < TMethods [ TKey ] > ;
24
+ } ;
25
+
26
+ export function addMethods < TBase extends { } , TMethods extends Methods < TBase > > (
22
27
base : TBase ,
23
28
methods ?: TMethods
24
- ) : TBase &
25
- {
26
- // eslint-disable-next-line @typescript-eslint/generic-type-naming
27
- [ key in keyof TMethods extends string ? keyof TMethods : never ] : ReturnType < TMethods [ key ] > ;
28
- } {
29
- Object . keys ( methods !== undefined ? methods : { } ) . forEach ( key => {
30
- // @ts -ignore
29
+ ) : AddedMethods < TBase , TMethods > {
30
+ if ( ! methods ) {
31
+ return base as AddedMethods < TBase , TMethods > ;
32
+ }
33
+
34
+ Object . keys ( methods ) . forEach ( key => {
31
35
// eslint-disable-next-line functional/immutable-data, no-param-reassign
32
- base [ key ] = methods [ key ] ( base ) ;
36
+ ( base as any ) [ key ] = methods [ key ] ( base ) ;
33
37
} ) ;
34
38
35
- // @ts -ignore
36
- return base ;
39
+ return base as AddedMethods < TBase , TMethods > ;
37
40
}
38
41
39
42
export function encode ( format : string , ...args : readonly any [ ] ) : string {
Original file line number Diff line number Diff line change @@ -35,17 +35,16 @@ export const updateApiKey = (base: SearchClient) => {
35
35
'description' ,
36
36
'maxQueriesPerIPPerHour' ,
37
37
'maxHitsPerQuery' ,
38
- ] ;
38
+ ] as const ;
39
39
40
40
const hasChanged = ( getApiKeyResponse : GetApiKeyResponse ) : boolean => {
41
41
return Object . keys ( updatedFields )
42
- . filter ( updatedField => apiKeyFields . indexOf ( updatedField ) !== - 1 )
42
+ . filter (
43
+ ( updatedField : any ) : updatedField is typeof apiKeyFields [ number ] =>
44
+ apiKeyFields . indexOf ( updatedField ) !== - 1
45
+ )
43
46
. every ( updatedField => {
44
- return (
45
- // @ts -ignore
46
-
47
- getApiKeyResponse [ updatedField ] === updatedFields [ updatedField ]
48
- ) ;
47
+ return getApiKeyResponse [ updatedField ] === updatedFields [ updatedField ] ;
49
48
} ) ;
50
49
} ;
51
50
Original file line number Diff line number Diff line change @@ -28,9 +28,8 @@ export const browseRules = (base: SearchIndex) => {
28
28
return {
29
29
...response ,
30
30
hits : response . hits . map ( rule => {
31
- // @ts -ignore
32
31
// eslint-disable-next-line functional/immutable-data,no-param-reassign
33
- delete rule . _highlightResult ;
32
+ delete ( rule as any ) . _highlightResult ;
34
33
35
34
return rule ;
36
35
} ) ,
Original file line number Diff line number Diff line change @@ -28,9 +28,8 @@ export const browseSynonyms = (base: SearchIndex) => {
28
28
return {
29
29
...response ,
30
30
hits : response . hits . map ( synonym => {
31
- // @ts -ignore
32
31
// eslint-disable-next-line functional/immutable-data,no-param-reassign
33
- delete synonym . _highlightResult ;
32
+ delete ( synonym as any ) . _highlightResult ;
34
33
35
34
return synonym ;
36
35
} ) ,
Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ export type GetApiKeyResponse = {
42
42
*/
43
43
referers ?: string [ ] ;
44
44
45
+ /**
46
+ * IPv4 network allowed to use the generated key.
47
+ * This is used for more protection against API key leaking and reuse.
48
+ * Note that you can only provide a single source, but you can specify a range of IPs (e.g., 192.168.1.0/24).
49
+ */
50
+ restrictSources ?: string ;
51
+
45
52
/**
46
53
* Specify the list of query parameters. You can force the query parameters for a query using the url string format.
47
54
*/
You can’t perform that action at this time.
0 commit comments