algoliasearch 5.1.1 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/builds/browser.ts +48 -113
- package/builds/models.ts +2 -2
- package/builds/node.ts +51 -122
- package/dist/algoliasearch/builds/browser.d.ts +83 -84
- package/dist/algoliasearch/builds/browser.d.ts.map +1 -1
- package/dist/algoliasearch/builds/models.d.ts +2 -2
- package/dist/algoliasearch/builds/models.d.ts.map +1 -1
- package/dist/algoliasearch/builds/node.d.ts +83 -86
- package/dist/algoliasearch/builds/node.d.ts.map +1 -1
- package/dist/algoliasearch.cjs +27 -4353
- package/dist/algoliasearch.esm.browser.js +4477 -1437
- package/dist/algoliasearch.esm.node.js +28 -4354
- package/dist/algoliasearch.umd.js +2 -2
- package/dist/client-abtesting/model/clientMethodProps.d.ts +2 -2
- package/dist/client-abtesting/model/clientMethodProps.d.ts.map +1 -1
- package/dist/client-abtesting/model/customSearchParams.d.ts +1 -1
- package/dist/client-abtesting/model/customSearchParams.d.ts.map +1 -1
- package/dist/client-abtesting/model/effect.d.ts.map +1 -1
- package/dist/client-analytics/model/clientMethodProps.d.ts +2 -2
- package/dist/client-analytics/model/clientMethodProps.d.ts.map +1 -1
- package/dist/client-analytics/model/{currenciesValue.d.ts → currencyCode.d.ts} +2 -2
- package/dist/client-analytics/model/currencyCode.d.ts.map +1 -0
- package/dist/client-analytics/model/dailyRevenue.d.ts +2 -2
- package/dist/client-analytics/model/dailyRevenue.d.ts.map +1 -1
- package/dist/client-analytics/model/getRevenue.d.ts +2 -2
- package/dist/client-analytics/model/getRevenue.d.ts.map +1 -1
- package/dist/client-analytics/model/getTopHitsResponse.d.ts.map +1 -1
- package/dist/client-analytics/model/index.d.ts +1 -1
- package/dist/client-analytics/model/index.d.ts.map +1 -1
- package/dist/client-analytics/model/orderBy.d.ts.map +1 -1
- package/dist/client-analytics/model/topHitWithRevenueAnalytics.d.ts +2 -2
- package/dist/client-analytics/model/topHitWithRevenueAnalytics.d.ts.map +1 -1
- package/dist/client-analytics/model/topSearchWithRevenueAnalytics.d.ts +2 -2
- package/dist/client-analytics/model/topSearchWithRevenueAnalytics.d.ts.map +1 -1
- package/dist/client-personalization/model/clientMethodProps.d.ts +2 -2
- package/dist/client-personalization/model/clientMethodProps.d.ts.map +1 -1
- package/dist/client-personalization/model/getUserTokenResponse.d.ts +1 -1
- package/dist/client-personalization/model/getUserTokenResponse.d.ts.map +1 -1
- package/dist/client-search/model/alternativesAsExact.d.ts.map +1 -1
- package/dist/client-search/model/baseIndexSettings.d.ts +2 -2
- package/dist/client-search/model/baseIndexSettings.d.ts.map +1 -1
- package/dist/client-search/model/baseSearchResponse.d.ts +4 -4
- package/dist/client-search/model/baseSearchResponse.d.ts.map +1 -1
- package/dist/client-search/model/batchRequest.d.ts +1 -1
- package/dist/client-search/model/batchRequest.d.ts.map +1 -1
- package/dist/client-search/model/browseResponse.d.ts.map +1 -1
- package/dist/client-search/model/clientMethodProps.d.ts +5 -6
- package/dist/client-search/model/clientMethodProps.d.ts.map +1 -1
- package/dist/client-search/model/consequenceParams.d.ts.map +1 -1
- package/dist/client-search/model/{facetsStats.d.ts → facetStats.d.ts} +2 -2
- package/dist/client-search/model/facetStats.d.ts.map +1 -0
- package/dist/client-search/model/index.d.ts +1 -1
- package/dist/client-search/model/index.d.ts.map +1 -1
- package/dist/client-search/model/multipleBatchRequest.d.ts +1 -1
- package/dist/client-search/model/multipleBatchRequest.d.ts.map +1 -1
- package/dist/client-search/model/removeWordsIfNoResults.d.ts.map +1 -1
- package/dist/client-search/model/searchResponse.d.ts.map +1 -1
- package/dist/client-search/model/searchResult.d.ts.map +1 -1
- package/dist/client-search/model/synonymType.d.ts.map +1 -1
- package/dist/lite/builds/browser.d.ts +1 -1
- package/dist/lite/builds/browser.d.ts.map +1 -1
- package/dist/lite/builds/node.d.ts +1 -1
- package/dist/lite/builds/node.d.ts.map +1 -1
- package/dist/lite/lite.cjs +2 -5
- package/dist/lite/lite.esm.browser.js +11 -15
- package/dist/lite/lite.esm.node.js +2 -5
- package/dist/lite/lite.umd.js +2 -2
- package/dist/lite/model/alternativesAsExact.d.ts.map +1 -1
- package/dist/lite/model/baseIndexSettings.d.ts +2 -2
- package/dist/lite/model/baseIndexSettings.d.ts.map +1 -1
- package/dist/lite/model/baseSearchResponse.d.ts +4 -4
- package/dist/lite/model/baseSearchResponse.d.ts.map +1 -1
- package/dist/lite/model/boughtTogetherQuery.d.ts.map +1 -1
- package/dist/lite/model/browseResponse.d.ts.map +1 -1
- package/dist/lite/model/clientMethodProps.d.ts +1 -1
- package/dist/lite/model/clientMethodProps.d.ts.map +1 -1
- package/dist/lite/model/consequenceParams.d.ts.map +1 -1
- package/dist/lite/model/{facetsStats.d.ts → facetStats.d.ts} +2 -2
- package/dist/lite/model/facetStats.d.ts.map +1 -0
- package/dist/lite/model/fallbackParams.d.ts +1 -1
- package/dist/lite/model/fallbackParams.d.ts.map +1 -1
- package/dist/lite/model/index.d.ts +1 -1
- package/dist/lite/model/index.d.ts.map +1 -1
- package/dist/lite/model/recommendationsResults.d.ts.map +1 -1
- package/dist/lite/model/removeWordsIfNoResults.d.ts.map +1 -1
- package/dist/lite/model/searchParams.d.ts +1 -1
- package/dist/lite/model/searchParams.d.ts.map +1 -1
- package/dist/lite/model/searchResponse.d.ts.map +1 -1
- package/dist/lite/model/searchResult.d.ts.map +1 -1
- package/dist/lite/src/liteClient.d.ts +2 -2
- package/dist/lite/src/liteClient.d.ts.map +1 -1
- package/dist/recommend/model/alternativesAsExact.d.ts.map +1 -1
- package/dist/recommend/model/baseSearchResponse.d.ts +4 -4
- package/dist/recommend/model/baseSearchResponse.d.ts.map +1 -1
- package/dist/recommend/model/boughtTogetherQuery.d.ts.map +1 -1
- package/dist/recommend/model/clientMethodProps.d.ts +2 -2
- package/dist/recommend/model/clientMethodProps.d.ts.map +1 -1
- package/dist/recommend/model/{facetsStats.d.ts → facetStats.d.ts} +2 -2
- package/dist/recommend/model/facetStats.d.ts.map +1 -0
- package/dist/recommend/model/fallbackParams.d.ts +1 -1
- package/dist/recommend/model/fallbackParams.d.ts.map +1 -1
- package/dist/recommend/model/index.d.ts +1 -1
- package/dist/recommend/model/index.d.ts.map +1 -1
- package/dist/recommend/model/recommendModels.d.ts.map +1 -1
- package/dist/recommend/model/recommendationsResults.d.ts.map +1 -1
- package/dist/recommend/model/removeWordsIfNoResults.d.ts.map +1 -1
- package/dist/recommend/model/searchParams.d.ts +1 -1
- package/dist/recommend/model/searchParams.d.ts.map +1 -1
- package/lite/builds/browser.ts +2 -9
- package/lite/builds/node.ts +1 -5
- package/lite/model/alternativesAsExact.ts +1 -4
- package/lite/model/baseIndexSettings.ts +2 -2
- package/lite/model/baseSearchResponse.ts +4 -4
- package/lite/model/boughtTogetherQuery.ts +1 -2
- package/lite/model/browseResponse.ts +1 -4
- package/lite/model/clientMethodProps.ts +1 -1
- package/lite/model/consequenceParams.ts +1 -3
- package/lite/model/{facetsStats.ts → facetStats.ts} +1 -1
- package/lite/model/fallbackParams.ts +1 -1
- package/lite/model/index.ts +1 -1
- package/lite/model/recommendationsResults.ts +1 -3
- package/lite/model/removeWordsIfNoResults.ts +1 -5
- package/lite/model/searchParams.ts +1 -1
- package/lite/model/searchResponse.ts +1 -3
- package/lite/model/searchResult.ts +1 -3
- package/lite/src/liteClient.ts +17 -40
- package/package.json +14 -16
- package/dist/client-abtesting/src/abtestingClient.d.ts +0 -141
- package/dist/client-abtesting/src/abtestingClient.d.ts.map +0 -1
- package/dist/client-analytics/model/currenciesValue.d.ts.map +0 -1
- package/dist/client-analytics/src/analyticsClient.d.ts +0 -392
- package/dist/client-analytics/src/analyticsClient.d.ts.map +0 -1
- package/dist/client-personalization/src/personalizationClient.d.ts +0 -113
- package/dist/client-personalization/src/personalizationClient.d.ts.map +0 -1
- package/dist/client-search/model/facetsStats.d.ts.map +0 -1
- package/dist/client-search/src/searchClient.d.ts +0 -922
- package/dist/client-search/src/searchClient.d.ts.map +0 -1
- package/dist/lite/model/facetsStats.d.ts.map +0 -1
- package/dist/recommend/model/facetsStats.d.ts.map +0 -1
- package/dist/recommend/src/recommendClient.d.ts +0 -132
- package/dist/recommend/src/recommendClient.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<a href="https://npmjs.org/package/algoliasearch"><img src="https://img.shields.io/npm/v/algoliasearch.svg?style=flat-square" alt="NPM version"></img></a>
|
|
10
10
|
<a href="http://npm-stat.com/charts.html?package=algoliasearch"><img src="https://img.shields.io/npm/dm/algoliasearch.svg?style=flat-square" alt="NPM downloads"></a>
|
|
11
11
|
<a href="https://www.jsdelivr.com/package/npm/algoliasearch"><img src="https://data.jsdelivr.com/v1/package/npm/algoliasearch/badge" alt="jsDelivr Downloads"></img></a>
|
|
12
|
-
<a href="LICENSE
|
|
12
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg?style=flat-square" alt="License"></a>
|
|
13
13
|
</p>
|
|
14
14
|
</p>
|
|
15
15
|
|
package/builds/browser.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
// 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.
|
|
2
2
|
|
|
3
|
-
import type { AbtestingClient } from '@algolia/client-abtesting';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@algolia/client-abtesting/src/abtestingClient';
|
|
9
|
-
import type { AnalyticsClient } from '@algolia/client-analytics';
|
|
10
|
-
import {
|
|
11
|
-
createAnalyticsClient,
|
|
12
|
-
REGIONS as analyticsRegions,
|
|
13
|
-
} from '@algolia/client-analytics/src/analyticsClient';
|
|
14
|
-
import type { Region as AnalyticsRegion } from '@algolia/client-analytics/src/analyticsClient';
|
|
3
|
+
import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting';
|
|
4
|
+
import { abtestingClient } from '@algolia/client-abtesting';
|
|
5
|
+
import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics';
|
|
6
|
+
import { analyticsClient } from '@algolia/client-analytics';
|
|
7
|
+
import type { ClientOptions } from '@algolia/client-common';
|
|
15
8
|
import {
|
|
16
9
|
DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
17
10
|
DEFAULT_READ_TIMEOUT_BROWSER,
|
|
@@ -20,22 +13,11 @@ import {
|
|
|
20
13
|
createFallbackableCache,
|
|
21
14
|
createMemoryCache,
|
|
22
15
|
} from '@algolia/client-common';
|
|
23
|
-
import type {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from '@algolia/client-common';
|
|
27
|
-
import type { PersonalizationClient } from '@algolia/client-personalization';
|
|
28
|
-
import type { Region as PersonalizationRegion } from '@algolia/client-personalization/src/personalizationClient';
|
|
29
|
-
import {
|
|
30
|
-
createPersonalizationClient,
|
|
31
|
-
REGIONS as personalizationRegions,
|
|
32
|
-
} from '@algolia/client-personalization/src/personalizationClient';
|
|
33
|
-
import {
|
|
34
|
-
createSearchClient,
|
|
35
|
-
apiClientVersion as searchClientVersion,
|
|
36
|
-
} from '@algolia/client-search/src/searchClient';
|
|
16
|
+
import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization';
|
|
17
|
+
import { personalizationClient } from '@algolia/client-personalization';
|
|
18
|
+
import { searchClient, apiClientVersion as searchClientVersion } from '@algolia/client-search';
|
|
37
19
|
import type { RecommendClient } from '@algolia/recommend';
|
|
38
|
-
import {
|
|
20
|
+
import { recommendClient } from '@algolia/recommend';
|
|
39
21
|
import { createXhrRequester } from '@algolia/requester-browser-xhr';
|
|
40
22
|
|
|
41
23
|
import type { InitClientOptions, InitClientRegion } from './models';
|
|
@@ -50,11 +32,7 @@ export const apiClientVersion = searchClientVersion;
|
|
|
50
32
|
export type Algoliasearch = ReturnType<typeof algoliasearch>;
|
|
51
33
|
|
|
52
34
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
53
|
-
export function algoliasearch(
|
|
54
|
-
appId: string,
|
|
55
|
-
apiKey: string,
|
|
56
|
-
options?: ClientOptions
|
|
57
|
-
) {
|
|
35
|
+
export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions) {
|
|
58
36
|
if (!appId || typeof appId !== 'string') {
|
|
59
37
|
throw new Error('`appId` is missing.');
|
|
60
38
|
}
|
|
@@ -62,100 +40,57 @@ export function algoliasearch(
|
|
|
62
40
|
if (!apiKey || typeof apiKey !== 'string') {
|
|
63
41
|
throw new Error('`apiKey` is missing.');
|
|
64
42
|
}
|
|
65
|
-
const commonOptions: CreateClientOptions = {
|
|
66
|
-
apiKey,
|
|
67
|
-
appId,
|
|
68
|
-
timeouts: {
|
|
69
|
-
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
70
|
-
read: DEFAULT_READ_TIMEOUT_BROWSER,
|
|
71
|
-
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
|
|
72
|
-
},
|
|
73
|
-
requester: createXhrRequester(),
|
|
74
|
-
algoliaAgents: [{ segment: 'Browser' }],
|
|
75
|
-
authMode: 'WithinQueryParameters',
|
|
76
|
-
responsesCache: createMemoryCache(),
|
|
77
|
-
requestsCache: createMemoryCache({ serializable: false }),
|
|
78
|
-
hostsCache: createFallbackableCache({
|
|
79
|
-
caches: [
|
|
80
|
-
createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
|
|
81
|
-
createMemoryCache(),
|
|
82
|
-
],
|
|
83
|
-
}),
|
|
84
|
-
...options,
|
|
85
|
-
};
|
|
86
43
|
|
|
87
44
|
function initRecommend(initOptions: InitClientOptions = {}): RecommendClient {
|
|
88
|
-
return
|
|
89
|
-
...commonOptions,
|
|
90
|
-
...initOptions.options,
|
|
91
|
-
...initOptions,
|
|
92
|
-
});
|
|
45
|
+
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
|
|
93
46
|
}
|
|
94
47
|
|
|
95
|
-
function initAnalytics(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
initOptions.region
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
) {
|
|
103
|
-
throw new Error(
|
|
104
|
-
`\`region\` must be one of the following: ${analyticsRegions.join(', ')}`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return createAnalyticsClient({
|
|
109
|
-
...commonOptions,
|
|
110
|
-
...initOptions.options,
|
|
111
|
-
...initOptions,
|
|
112
|
-
});
|
|
48
|
+
function initAnalytics(initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient {
|
|
49
|
+
return analyticsClient(
|
|
50
|
+
initOptions.appId || appId,
|
|
51
|
+
initOptions.apiKey || apiKey,
|
|
52
|
+
initOptions.region,
|
|
53
|
+
initOptions.options,
|
|
54
|
+
);
|
|
113
55
|
}
|
|
114
56
|
|
|
115
|
-
function initAbtesting(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
initOptions.region
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
) {
|
|
123
|
-
throw new Error(
|
|
124
|
-
`\`region\` must be one of the following: ${abtestingRegions.join(', ')}`
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return createAbtestingClient({
|
|
129
|
-
...commonOptions,
|
|
130
|
-
...initOptions.options,
|
|
131
|
-
...initOptions,
|
|
132
|
-
});
|
|
57
|
+
function initAbtesting(initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient {
|
|
58
|
+
return abtestingClient(
|
|
59
|
+
initOptions.appId || appId,
|
|
60
|
+
initOptions.apiKey || apiKey,
|
|
61
|
+
initOptions.region,
|
|
62
|
+
initOptions.options,
|
|
63
|
+
);
|
|
133
64
|
}
|
|
134
65
|
|
|
135
66
|
function initPersonalization(
|
|
136
|
-
initOptions: InitClientOptions &
|
|
137
|
-
Required<InitClientRegion<PersonalizationRegion>>
|
|
67
|
+
initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
|
|
138
68
|
): PersonalizationClient {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
throw new Error(
|
|
146
|
-
`\`region\` is required and must be one of the following: ${personalizationRegions.join(', ')}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return createPersonalizationClient({
|
|
151
|
-
...commonOptions,
|
|
152
|
-
...initOptions.options,
|
|
153
|
-
...initOptions,
|
|
154
|
-
});
|
|
69
|
+
return personalizationClient(
|
|
70
|
+
initOptions.appId || appId,
|
|
71
|
+
initOptions.apiKey || apiKey,
|
|
72
|
+
initOptions.region,
|
|
73
|
+
initOptions.options,
|
|
74
|
+
);
|
|
155
75
|
}
|
|
156
76
|
|
|
157
77
|
return {
|
|
158
|
-
...
|
|
78
|
+
...searchClient(appId, apiKey, {
|
|
79
|
+
timeouts: {
|
|
80
|
+
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
81
|
+
read: DEFAULT_READ_TIMEOUT_BROWSER,
|
|
82
|
+
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
|
|
83
|
+
},
|
|
84
|
+
requester: createXhrRequester(),
|
|
85
|
+
algoliaAgents: [{ segment: 'Browser' }],
|
|
86
|
+
authMode: 'WithinQueryParameters',
|
|
87
|
+
responsesCache: createMemoryCache(),
|
|
88
|
+
requestsCache: createMemoryCache({ serializable: false }),
|
|
89
|
+
hostsCache: createFallbackableCache({
|
|
90
|
+
caches: [createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), createMemoryCache()],
|
|
91
|
+
}),
|
|
92
|
+
...options,
|
|
93
|
+
}),
|
|
159
94
|
/**
|
|
160
95
|
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
161
96
|
*/
|
package/builds/models.ts
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
FacetFilters,
|
|
34
34
|
FacetOrdering,
|
|
35
35
|
Facets,
|
|
36
|
-
|
|
36
|
+
FacetStats,
|
|
37
37
|
HighlightResult,
|
|
38
38
|
HighlightResultOption,
|
|
39
39
|
IgnorePlurals,
|
|
@@ -119,7 +119,7 @@ export {
|
|
|
119
119
|
FacetFilters,
|
|
120
120
|
FacetOrdering,
|
|
121
121
|
Facets,
|
|
122
|
-
|
|
122
|
+
FacetStats,
|
|
123
123
|
HighlightResult,
|
|
124
124
|
HighlightResultOption,
|
|
125
125
|
IgnorePlurals,
|
package/builds/node.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
// 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.
|
|
2
2
|
|
|
3
|
-
import { createHmac } from 'crypto';
|
|
3
|
+
import { createHmac } from 'node:crypto';
|
|
4
4
|
|
|
5
|
-
import type { AbtestingClient } from '@algolia/client-abtesting';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from '@algolia/client-abtesting/src/abtestingClient';
|
|
11
|
-
import type { AnalyticsClient } from '@algolia/client-analytics';
|
|
12
|
-
import {
|
|
13
|
-
createAnalyticsClient,
|
|
14
|
-
REGIONS as analyticsRegions,
|
|
15
|
-
} from '@algolia/client-analytics/src/analyticsClient';
|
|
16
|
-
import type { Region as AnalyticsRegion } from '@algolia/client-analytics/src/analyticsClient';
|
|
5
|
+
import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting';
|
|
6
|
+
import { abtestingClient } from '@algolia/client-abtesting';
|
|
7
|
+
import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics';
|
|
8
|
+
import { analyticsClient } from '@algolia/client-analytics';
|
|
9
|
+
import type { ClientOptions } from '@algolia/client-common';
|
|
17
10
|
import {
|
|
18
11
|
DEFAULT_CONNECT_TIMEOUT_NODE,
|
|
19
12
|
DEFAULT_READ_TIMEOUT_NODE,
|
|
@@ -22,22 +15,11 @@ import {
|
|
|
22
15
|
createNullCache,
|
|
23
16
|
serializeQueryParameters,
|
|
24
17
|
} from '@algolia/client-common';
|
|
25
|
-
import type {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from '@algolia/client-common';
|
|
29
|
-
import type { PersonalizationClient } from '@algolia/client-personalization';
|
|
30
|
-
import type { Region as PersonalizationRegion } from '@algolia/client-personalization/src/personalizationClient';
|
|
31
|
-
import {
|
|
32
|
-
createPersonalizationClient,
|
|
33
|
-
REGIONS as personalizationRegions,
|
|
34
|
-
} from '@algolia/client-personalization/src/personalizationClient';
|
|
35
|
-
import {
|
|
36
|
-
createSearchClient,
|
|
37
|
-
apiClientVersion as searchClientVersion,
|
|
38
|
-
} from '@algolia/client-search/src/searchClient';
|
|
18
|
+
import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization';
|
|
19
|
+
import { personalizationClient } from '@algolia/client-personalization';
|
|
20
|
+
import { searchClient, apiClientVersion as searchClientVersion } from '@algolia/client-search';
|
|
39
21
|
import type { RecommendClient } from '@algolia/recommend';
|
|
40
|
-
import {
|
|
22
|
+
import { recommendClient } from '@algolia/recommend';
|
|
41
23
|
import { createHttpRequester } from '@algolia/requester-node-http';
|
|
42
24
|
|
|
43
25
|
import type {
|
|
@@ -57,11 +39,7 @@ export const apiClientVersion = searchClientVersion;
|
|
|
57
39
|
export type Algoliasearch = ReturnType<typeof algoliasearch>;
|
|
58
40
|
|
|
59
41
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
60
|
-
export function algoliasearch(
|
|
61
|
-
appId: string,
|
|
62
|
-
apiKey: string,
|
|
63
|
-
options?: ClientOptions
|
|
64
|
-
) {
|
|
42
|
+
export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions) {
|
|
65
43
|
if (!appId || typeof appId !== 'string') {
|
|
66
44
|
throw new Error('`appId` is missing.');
|
|
67
45
|
}
|
|
@@ -69,94 +47,54 @@ export function algoliasearch(
|
|
|
69
47
|
if (!apiKey || typeof apiKey !== 'string') {
|
|
70
48
|
throw new Error('`apiKey` is missing.');
|
|
71
49
|
}
|
|
72
|
-
const commonOptions: CreateClientOptions = {
|
|
73
|
-
apiKey,
|
|
74
|
-
appId,
|
|
75
|
-
timeouts: {
|
|
76
|
-
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
|
|
77
|
-
read: DEFAULT_READ_TIMEOUT_NODE,
|
|
78
|
-
write: DEFAULT_WRITE_TIMEOUT_NODE,
|
|
79
|
-
},
|
|
80
|
-
requester: createHttpRequester(),
|
|
81
|
-
algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }],
|
|
82
|
-
responsesCache: createNullCache(),
|
|
83
|
-
requestsCache: createNullCache(),
|
|
84
|
-
hostsCache: createMemoryCache(),
|
|
85
|
-
...options,
|
|
86
|
-
};
|
|
87
50
|
|
|
88
51
|
function initRecommend(initOptions: InitClientOptions = {}): RecommendClient {
|
|
89
|
-
return
|
|
90
|
-
...commonOptions,
|
|
91
|
-
...initOptions.options,
|
|
92
|
-
...initOptions,
|
|
93
|
-
});
|
|
52
|
+
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
|
|
94
53
|
}
|
|
95
54
|
|
|
96
|
-
function initAnalytics(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
initOptions.region
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
`\`region\` must be one of the following: ${analyticsRegions.join(', ')}`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return createAnalyticsClient({
|
|
110
|
-
...commonOptions,
|
|
111
|
-
...initOptions.options,
|
|
112
|
-
...initOptions,
|
|
113
|
-
});
|
|
55
|
+
function initAnalytics(initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient {
|
|
56
|
+
return analyticsClient(
|
|
57
|
+
initOptions.appId || appId,
|
|
58
|
+
initOptions.apiKey || apiKey,
|
|
59
|
+
initOptions.region,
|
|
60
|
+
initOptions.options,
|
|
61
|
+
);
|
|
114
62
|
}
|
|
115
63
|
|
|
116
|
-
function initAbtesting(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
initOptions.region
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
) {
|
|
124
|
-
throw new Error(
|
|
125
|
-
`\`region\` must be one of the following: ${abtestingRegions.join(', ')}`
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return createAbtestingClient({
|
|
130
|
-
...commonOptions,
|
|
131
|
-
...initOptions.options,
|
|
132
|
-
...initOptions,
|
|
133
|
-
});
|
|
64
|
+
function initAbtesting(initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient {
|
|
65
|
+
return abtestingClient(
|
|
66
|
+
initOptions.appId || appId,
|
|
67
|
+
initOptions.apiKey || apiKey,
|
|
68
|
+
initOptions.region,
|
|
69
|
+
initOptions.options,
|
|
70
|
+
);
|
|
134
71
|
}
|
|
135
72
|
|
|
136
73
|
function initPersonalization(
|
|
137
|
-
initOptions: InitClientOptions &
|
|
138
|
-
Required<InitClientRegion<PersonalizationRegion>>
|
|
74
|
+
initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
|
|
139
75
|
): PersonalizationClient {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)
|
|
146
|
-
throw new Error(
|
|
147
|
-
`\`region\` is required and must be one of the following: ${personalizationRegions.join(', ')}`
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return createPersonalizationClient({
|
|
152
|
-
...commonOptions,
|
|
153
|
-
...initOptions.options,
|
|
154
|
-
...initOptions,
|
|
155
|
-
});
|
|
76
|
+
return personalizationClient(
|
|
77
|
+
initOptions.appId || appId,
|
|
78
|
+
initOptions.apiKey || apiKey,
|
|
79
|
+
initOptions.region,
|
|
80
|
+
initOptions.options,
|
|
81
|
+
);
|
|
156
82
|
}
|
|
157
83
|
|
|
158
84
|
return {
|
|
159
|
-
...
|
|
85
|
+
...searchClient(appId, apiKey, {
|
|
86
|
+
timeouts: {
|
|
87
|
+
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
|
|
88
|
+
read: DEFAULT_READ_TIMEOUT_NODE,
|
|
89
|
+
write: DEFAULT_WRITE_TIMEOUT_NODE,
|
|
90
|
+
},
|
|
91
|
+
requester: createHttpRequester(),
|
|
92
|
+
algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }],
|
|
93
|
+
responsesCache: createNullCache(),
|
|
94
|
+
requestsCache: createNullCache(),
|
|
95
|
+
hostsCache: createMemoryCache(),
|
|
96
|
+
...options,
|
|
97
|
+
}),
|
|
160
98
|
/**
|
|
161
99
|
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
162
100
|
*/
|
|
@@ -175,10 +113,7 @@ export function algoliasearch(
|
|
|
175
113
|
* @param generateSecuredApiKey.parentApiKey - The base API key from which to generate the new secured one.
|
|
176
114
|
* @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key.
|
|
177
115
|
*/
|
|
178
|
-
generateSecuredApiKey({
|
|
179
|
-
parentApiKey,
|
|
180
|
-
restrictions = {},
|
|
181
|
-
}: GenerateSecuredApiKeyOptions): string {
|
|
116
|
+
generateSecuredApiKey({ parentApiKey, restrictions = {} }: GenerateSecuredApiKeyOptions): string {
|
|
182
117
|
let mergedRestrictions = restrictions;
|
|
183
118
|
if (restrictions.searchParams) {
|
|
184
119
|
// merge searchParams with the root restrictions
|
|
@@ -198,14 +133,12 @@ export function algoliasearch(
|
|
|
198
133
|
acc[key] = (mergedRestrictions as any)[key];
|
|
199
134
|
return acc;
|
|
200
135
|
},
|
|
201
|
-
{} as Record<string, unknown
|
|
136
|
+
{} as Record<string, unknown>,
|
|
202
137
|
);
|
|
203
138
|
|
|
204
139
|
const queryParameters = serializeQueryParameters(mergedRestrictions);
|
|
205
140
|
return Buffer.from(
|
|
206
|
-
createHmac('sha256', parentApiKey)
|
|
207
|
-
.update(queryParameters)
|
|
208
|
-
.digest('hex') + queryParameters
|
|
141
|
+
createHmac('sha256', parentApiKey).update(queryParameters).digest('hex') + queryParameters,
|
|
209
142
|
).toString('base64');
|
|
210
143
|
},
|
|
211
144
|
|
|
@@ -216,12 +149,8 @@ export function algoliasearch(
|
|
|
216
149
|
* @param getSecuredApiKeyRemainingValidity - The `getSecuredApiKeyRemainingValidity` object.
|
|
217
150
|
* @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method.
|
|
218
151
|
*/
|
|
219
|
-
getSecuredApiKeyRemainingValidity({
|
|
220
|
-
securedApiKey,
|
|
221
|
-
}: GetSecuredApiKeyRemainingValidityOptions): number {
|
|
222
|
-
const decodedString = Buffer.from(securedApiKey, 'base64').toString(
|
|
223
|
-
'ascii'
|
|
224
|
-
);
|
|
152
|
+
getSecuredApiKeyRemainingValidity({ securedApiKey }: GetSecuredApiKeyRemainingValidityOptions): number {
|
|
153
|
+
const decodedString = Buffer.from(securedApiKey, 'base64').toString('ascii');
|
|
225
154
|
const regex = /validUntil=(\d+)/;
|
|
226
155
|
const match = decodedString.match(regex);
|
|
227
156
|
|