@algolia/client-analytics 5.3.0 → 5.3.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.
@@ -1,6 +1,6 @@
1
1
  // src/analyticsClient.ts
2
2
  import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
3
- var apiClientVersion = "5.3.0";
3
+ var apiClientVersion = "5.3.2";
4
4
  var REGIONS = ["de", "us"];
5
5
  function getDefaultHosts(region) {
6
6
  const url = !region ? "analytics.algolia.com" : "analytics.{region}.algolia.com".replace("{region}", region);
@@ -15,25 +15,26 @@ function createAnalyticsClient({
15
15
  ...options
16
16
  }) {
17
17
  const auth = createAuth(appIdOption, apiKeyOption, authMode);
18
- return {
19
- transporter: createTransporter({
20
- hosts: getDefaultHosts(regionOption),
21
- ...options,
22
- algoliaAgent: getAlgoliaAgent({
23
- algoliaAgents,
24
- client: "Analytics",
25
- version: apiClientVersion
26
- }),
27
- baseHeaders: {
28
- "content-type": "text/plain",
29
- ...auth.headers(),
30
- ...options.baseHeaders
31
- },
32
- baseQueryParameters: {
33
- ...auth.queryParameters(),
34
- ...options.baseQueryParameters
35
- }
18
+ const transporter = createTransporter({
19
+ hosts: getDefaultHosts(regionOption),
20
+ ...options,
21
+ algoliaAgent: getAlgoliaAgent({
22
+ algoliaAgents,
23
+ client: "Analytics",
24
+ version: apiClientVersion
36
25
  }),
26
+ baseHeaders: {
27
+ "content-type": "text/plain",
28
+ ...auth.headers(),
29
+ ...options.baseHeaders
30
+ },
31
+ baseQueryParameters: {
32
+ ...auth.queryParameters(),
33
+ ...options.baseQueryParameters
34
+ }
35
+ });
36
+ return {
37
+ transporter,
37
38
  /**
38
39
  * The `appId` currently in use.
39
40
  */
@@ -42,15 +43,13 @@ function createAnalyticsClient({
42
43
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
43
44
  */
44
45
  clearCache() {
45
- return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
46
- () => void 0
47
- );
46
+ return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
48
47
  },
49
48
  /**
50
49
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
51
50
  */
52
51
  get _ua() {
53
- return this.transporter.algoliaAgent.value;
52
+ return transporter.algoliaAgent.value;
54
53
  },
55
54
  /**
56
55
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -59,7 +58,7 @@ function createAnalyticsClient({
59
58
  * @param version - The version of the agent.
60
59
  */
61
60
  addAlgoliaAgent(segment, version) {
62
- this.transporter.algoliaAgent.add({ segment, version });
61
+ transporter.algoliaAgent.add({ segment, version });
63
62
  },
64
63
  /**
65
64
  * Helper method to switch the API key used to authenticate the requests.
@@ -68,7 +67,11 @@ function createAnalyticsClient({
68
67
  * @param params.apiKey - The new API Key to use.
69
68
  */
70
69
  setClientApiKey({ apiKey }) {
71
- this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
70
+ if (!authMode || authMode === "WithinHeaders") {
71
+ transporter.baseHeaders["x-algolia-api-key"] = apiKey;
72
+ } else {
73
+ transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
74
+ }
72
75
  },
73
76
  /**
74
77
  * This method allow you to send requests to the Algolia REST API.
@@ -91,7 +94,7 @@ function createAnalyticsClient({
91
94
  queryParameters,
92
95
  headers
93
96
  };
94
- return this.transporter.request(request, requestOptions);
97
+ return transporter.request(request, requestOptions);
95
98
  },
96
99
  /**
97
100
  * This method allow you to send requests to the Algolia REST API.
@@ -114,7 +117,7 @@ function createAnalyticsClient({
114
117
  queryParameters,
115
118
  headers
116
119
  };
117
- return this.transporter.request(request, requestOptions);
120
+ return transporter.request(request, requestOptions);
118
121
  },
119
122
  /**
120
123
  * This method allow you to send requests to the Algolia REST API.
@@ -139,7 +142,7 @@ function createAnalyticsClient({
139
142
  headers,
140
143
  data: body ? body : {}
141
144
  };
142
- return this.transporter.request(request, requestOptions);
145
+ return transporter.request(request, requestOptions);
143
146
  },
144
147
  /**
145
148
  * This method allow you to send requests to the Algolia REST API.
@@ -164,7 +167,7 @@ function createAnalyticsClient({
164
167
  headers,
165
168
  data: body ? body : {}
166
169
  };
167
- return this.transporter.request(request, requestOptions);
170
+ return transporter.request(request, requestOptions);
168
171
  },
169
172
  /**
170
173
  * Retrieves the add-to-cart rate for all of your searches with at least one add-to-cart event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -204,7 +207,7 @@ function createAnalyticsClient({
204
207
  queryParameters,
205
208
  headers
206
209
  };
207
- return this.transporter.request(request, requestOptions);
210
+ return transporter.request(request, requestOptions);
208
211
  },
209
212
  /**
210
213
  * Retrieves the average click position of your search results, including a daily breakdown. The average click position is the average of all clicked search results\' positions. For example, if users only ever click on the first result for any search, the average click position is 1. By default, the analyzed period includes the last eight days including the current day.
@@ -244,7 +247,7 @@ function createAnalyticsClient({
244
247
  queryParameters,
245
248
  headers
246
249
  };
247
- return this.transporter.request(request, requestOptions);
250
+ return transporter.request(request, requestOptions);
248
251
  },
249
252
  /**
250
253
  * Retrieves the positions in the search results and their associated number of clicks. This lets you check how many clicks the first, second, or tenth search results receive.
@@ -284,7 +287,7 @@ function createAnalyticsClient({
284
287
  queryParameters,
285
288
  headers
286
289
  };
287
- return this.transporter.request(request, requestOptions);
290
+ return transporter.request(request, requestOptions);
288
291
  },
289
292
  /**
290
293
  * Retrieves the click-through rate for all of your searches with at least one click event, including a daily breakdown By default, the analyzed period includes the last eight days including the current day.
@@ -324,7 +327,7 @@ function createAnalyticsClient({
324
327
  queryParameters,
325
328
  headers
326
329
  };
327
- return this.transporter.request(request, requestOptions);
330
+ return transporter.request(request, requestOptions);
328
331
  },
329
332
  /**
330
333
  * Retrieves the conversion rate for all of your searches with at least one conversion event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -364,7 +367,7 @@ function createAnalyticsClient({
364
367
  queryParameters,
365
368
  headers
366
369
  };
367
- return this.transporter.request(request, requestOptions);
370
+ return transporter.request(request, requestOptions);
368
371
  },
369
372
  /**
370
373
  * Retrieves the fraction of searches that didn\'t lead to any click within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -404,7 +407,7 @@ function createAnalyticsClient({
404
407
  queryParameters,
405
408
  headers
406
409
  };
407
- return this.transporter.request(request, requestOptions);
410
+ return transporter.request(request, requestOptions);
408
411
  },
409
412
  /**
410
413
  * Retrieves the fraction of searches that didn\'t return any results within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -444,7 +447,7 @@ function createAnalyticsClient({
444
447
  queryParameters,
445
448
  headers
446
449
  };
447
- return this.transporter.request(request, requestOptions);
450
+ return transporter.request(request, requestOptions);
448
451
  },
449
452
  /**
450
453
  * Retrieves the purchase rate for all of your searches with at least one purchase event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -484,7 +487,7 @@ function createAnalyticsClient({
484
487
  queryParameters,
485
488
  headers
486
489
  };
487
- return this.transporter.request(request, requestOptions);
490
+ return transporter.request(request, requestOptions);
488
491
  },
489
492
  /**
490
493
  * Retrieves revenue-related metrics, such as the total revenue or the average order value. To retrieve revenue-related metrics, sent purchase events. By default, the analyzed period includes the last eight days including the current day.
@@ -524,7 +527,7 @@ function createAnalyticsClient({
524
527
  queryParameters,
525
528
  headers
526
529
  };
527
- return this.transporter.request(request, requestOptions);
530
+ return transporter.request(request, requestOptions);
528
531
  },
529
532
  /**
530
533
  * Retrieves the number of searches within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -564,7 +567,7 @@ function createAnalyticsClient({
564
567
  queryParameters,
565
568
  headers
566
569
  };
567
- return this.transporter.request(request, requestOptions);
570
+ return transporter.request(request, requestOptions);
568
571
  },
569
572
  /**
570
573
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -612,7 +615,7 @@ function createAnalyticsClient({
612
615
  queryParameters,
613
616
  headers
614
617
  };
615
- return this.transporter.request(request, requestOptions);
618
+ return transporter.request(request, requestOptions);
616
619
  },
617
620
  /**
618
621
  * Retrieves the most popular searches that didn\'t return any results.
@@ -660,7 +663,7 @@ function createAnalyticsClient({
660
663
  queryParameters,
661
664
  headers
662
665
  };
663
- return this.transporter.request(request, requestOptions);
666
+ return transporter.request(request, requestOptions);
664
667
  },
665
668
  /**
666
669
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -688,7 +691,7 @@ function createAnalyticsClient({
688
691
  queryParameters,
689
692
  headers
690
693
  };
691
- return this.transporter.request(request, requestOptions);
694
+ return transporter.request(request, requestOptions);
692
695
  },
693
696
  /**
694
697
  * Retrieves the countries with the most searches to your index.
@@ -736,7 +739,7 @@ function createAnalyticsClient({
736
739
  queryParameters,
737
740
  headers
738
741
  };
739
- return this.transporter.request(request, requestOptions);
742
+ return transporter.request(request, requestOptions);
740
743
  },
741
744
  /**
742
745
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -788,7 +791,7 @@ function createAnalyticsClient({
788
791
  queryParameters,
789
792
  headers
790
793
  };
791
- return this.transporter.request(request, requestOptions);
794
+ return transporter.request(request, requestOptions);
792
795
  },
793
796
  /**
794
797
  * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -844,7 +847,7 @@ function createAnalyticsClient({
844
847
  queryParameters,
845
848
  headers
846
849
  };
847
- return this.transporter.request(request, requestOptions);
850
+ return transporter.request(request, requestOptions);
848
851
  },
849
852
  /**
850
853
  * Retrieves the most frequently used filters for a search that didn\'t return any results. To get the most frequent searches without results, use the [Retrieve searches without results](#tag/search/operation/getSearchesNoResults) operation.
@@ -896,7 +899,7 @@ function createAnalyticsClient({
896
899
  queryParameters,
897
900
  headers
898
901
  };
899
- return this.transporter.request(request, requestOptions);
902
+ return transporter.request(request, requestOptions);
900
903
  },
901
904
  /**
902
905
  * Retrieves the object IDs of the most frequent search results.
@@ -956,7 +959,7 @@ function createAnalyticsClient({
956
959
  queryParameters,
957
960
  headers
958
961
  };
959
- return this.transporter.request(request, requestOptions);
962
+ return transporter.request(request, requestOptions);
960
963
  },
961
964
  /**
962
965
  * Returns the most popular search terms.
@@ -1031,7 +1034,7 @@ function createAnalyticsClient({
1031
1034
  queryParameters,
1032
1035
  headers
1033
1036
  };
1034
- return this.transporter.request(request, requestOptions);
1037
+ return transporter.request(request, requestOptions);
1035
1038
  },
1036
1039
  /**
1037
1040
  * Retrieves the number of unique users within a time range, including a daily breakdown. Since this endpoint returns the number of unique users, the sum of the daily values might be different from the total number. By default, Algolia distinguishes search users by their IP address, _unless_ you include a pseudonymous user identifier in your search requests with the `userToken` API parameter or `x-algolia-usertoken` request header. By default, the analyzed period includes the last eight days including the current day.
@@ -1071,7 +1074,7 @@ function createAnalyticsClient({
1071
1074
  queryParameters,
1072
1075
  headers
1073
1076
  };
1074
- return this.transporter.request(request, requestOptions);
1077
+ return transporter.request(request, requestOptions);
1075
1078
  }
1076
1079
  };
1077
1080
  }