@algolia/client-analytics 5.2.5 → 5.3.0

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.
@@ -10,7 +10,7 @@ import { createHttpRequester } from "@algolia/requester-node-http";
10
10
 
11
11
  // src/analyticsClient.ts
12
12
  import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
13
- var apiClientVersion = "5.2.5";
13
+ var apiClientVersion = "5.3.0";
14
14
  var REGIONS = ["de", "us"];
15
15
  function getDefaultHosts(region) {
16
16
  const url = !region ? "analytics.algolia.com" : "analytics.{region}.algolia.com".replace("{region}", region);
@@ -25,26 +25,25 @@ function createAnalyticsClient({
25
25
  ...options
26
26
  }) {
27
27
  const auth = createAuth(appIdOption, apiKeyOption, authMode);
28
- const transporter = createTransporter({
29
- hosts: getDefaultHosts(regionOption),
30
- ...options,
31
- algoliaAgent: getAlgoliaAgent({
32
- algoliaAgents,
33
- client: "Analytics",
34
- version: apiClientVersion
35
- }),
36
- baseHeaders: {
37
- "content-type": "text/plain",
38
- ...auth.headers(),
39
- ...options.baseHeaders
40
- },
41
- baseQueryParameters: {
42
- ...auth.queryParameters(),
43
- ...options.baseQueryParameters
44
- }
45
- });
46
28
  return {
47
- transporter,
29
+ transporter: createTransporter({
30
+ hosts: getDefaultHosts(regionOption),
31
+ ...options,
32
+ algoliaAgent: getAlgoliaAgent({
33
+ algoliaAgents,
34
+ client: "Analytics",
35
+ version: apiClientVersion
36
+ }),
37
+ baseHeaders: {
38
+ "content-type": "text/plain",
39
+ ...auth.headers(),
40
+ ...options.baseHeaders
41
+ },
42
+ baseQueryParameters: {
43
+ ...auth.queryParameters(),
44
+ ...options.baseQueryParameters
45
+ }
46
+ }),
48
47
  /**
49
48
  * The `appId` currently in use.
50
49
  */
@@ -53,13 +52,15 @@ function createAnalyticsClient({
53
52
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
54
53
  */
55
54
  clearCache() {
56
- return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
55
+ return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
56
+ () => void 0
57
+ );
57
58
  },
58
59
  /**
59
60
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
60
61
  */
61
62
  get _ua() {
62
- return transporter.algoliaAgent.value;
63
+ return this.transporter.algoliaAgent.value;
63
64
  },
64
65
  /**
65
66
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -68,7 +69,16 @@ function createAnalyticsClient({
68
69
  * @param version - The version of the agent.
69
70
  */
70
71
  addAlgoliaAgent(segment, version) {
71
- transporter.algoliaAgent.add({ segment, version });
72
+ this.transporter.algoliaAgent.add({ segment, version });
73
+ },
74
+ /**
75
+ * Helper method to switch the API key used to authenticate the requests.
76
+ *
77
+ * @param params - Method params.
78
+ * @param params.apiKey - The new API Key to use.
79
+ */
80
+ setClientApiKey({ apiKey }) {
81
+ this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
72
82
  },
73
83
  /**
74
84
  * This method allow you to send requests to the Algolia REST API.
@@ -91,7 +101,7 @@ function createAnalyticsClient({
91
101
  queryParameters,
92
102
  headers
93
103
  };
94
- return transporter.request(request, requestOptions);
104
+ return this.transporter.request(request, requestOptions);
95
105
  },
96
106
  /**
97
107
  * This method allow you to send requests to the Algolia REST API.
@@ -114,7 +124,7 @@ function createAnalyticsClient({
114
124
  queryParameters,
115
125
  headers
116
126
  };
117
- return transporter.request(request, requestOptions);
127
+ return this.transporter.request(request, requestOptions);
118
128
  },
119
129
  /**
120
130
  * This method allow you to send requests to the Algolia REST API.
@@ -139,7 +149,7 @@ function createAnalyticsClient({
139
149
  headers,
140
150
  data: body ? body : {}
141
151
  };
142
- return transporter.request(request, requestOptions);
152
+ return this.transporter.request(request, requestOptions);
143
153
  },
144
154
  /**
145
155
  * This method allow you to send requests to the Algolia REST API.
@@ -164,7 +174,7 @@ function createAnalyticsClient({
164
174
  headers,
165
175
  data: body ? body : {}
166
176
  };
167
- return transporter.request(request, requestOptions);
177
+ return this.transporter.request(request, requestOptions);
168
178
  },
169
179
  /**
170
180
  * 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 +214,7 @@ function createAnalyticsClient({
204
214
  queryParameters,
205
215
  headers
206
216
  };
207
- return transporter.request(request, requestOptions);
217
+ return this.transporter.request(request, requestOptions);
208
218
  },
209
219
  /**
210
220
  * 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 +254,7 @@ function createAnalyticsClient({
244
254
  queryParameters,
245
255
  headers
246
256
  };
247
- return transporter.request(request, requestOptions);
257
+ return this.transporter.request(request, requestOptions);
248
258
  },
249
259
  /**
250
260
  * 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 +294,7 @@ function createAnalyticsClient({
284
294
  queryParameters,
285
295
  headers
286
296
  };
287
- return transporter.request(request, requestOptions);
297
+ return this.transporter.request(request, requestOptions);
288
298
  },
289
299
  /**
290
300
  * 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 +334,7 @@ function createAnalyticsClient({
324
334
  queryParameters,
325
335
  headers
326
336
  };
327
- return transporter.request(request, requestOptions);
337
+ return this.transporter.request(request, requestOptions);
328
338
  },
329
339
  /**
330
340
  * 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 +374,7 @@ function createAnalyticsClient({
364
374
  queryParameters,
365
375
  headers
366
376
  };
367
- return transporter.request(request, requestOptions);
377
+ return this.transporter.request(request, requestOptions);
368
378
  },
369
379
  /**
370
380
  * 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 +414,7 @@ function createAnalyticsClient({
404
414
  queryParameters,
405
415
  headers
406
416
  };
407
- return transporter.request(request, requestOptions);
417
+ return this.transporter.request(request, requestOptions);
408
418
  },
409
419
  /**
410
420
  * 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 +454,7 @@ function createAnalyticsClient({
444
454
  queryParameters,
445
455
  headers
446
456
  };
447
- return transporter.request(request, requestOptions);
457
+ return this.transporter.request(request, requestOptions);
448
458
  },
449
459
  /**
450
460
  * 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 +494,7 @@ function createAnalyticsClient({
484
494
  queryParameters,
485
495
  headers
486
496
  };
487
- return transporter.request(request, requestOptions);
497
+ return this.transporter.request(request, requestOptions);
488
498
  },
489
499
  /**
490
500
  * 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 +534,7 @@ function createAnalyticsClient({
524
534
  queryParameters,
525
535
  headers
526
536
  };
527
- return transporter.request(request, requestOptions);
537
+ return this.transporter.request(request, requestOptions);
528
538
  },
529
539
  /**
530
540
  * 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 +574,7 @@ function createAnalyticsClient({
564
574
  queryParameters,
565
575
  headers
566
576
  };
567
- return transporter.request(request, requestOptions);
577
+ return this.transporter.request(request, requestOptions);
568
578
  },
569
579
  /**
570
580
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -612,7 +622,7 @@ function createAnalyticsClient({
612
622
  queryParameters,
613
623
  headers
614
624
  };
615
- return transporter.request(request, requestOptions);
625
+ return this.transporter.request(request, requestOptions);
616
626
  },
617
627
  /**
618
628
  * Retrieves the most popular searches that didn\'t return any results.
@@ -660,7 +670,7 @@ function createAnalyticsClient({
660
670
  queryParameters,
661
671
  headers
662
672
  };
663
- return transporter.request(request, requestOptions);
673
+ return this.transporter.request(request, requestOptions);
664
674
  },
665
675
  /**
666
676
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -688,7 +698,7 @@ function createAnalyticsClient({
688
698
  queryParameters,
689
699
  headers
690
700
  };
691
- return transporter.request(request, requestOptions);
701
+ return this.transporter.request(request, requestOptions);
692
702
  },
693
703
  /**
694
704
  * Retrieves the countries with the most searches to your index.
@@ -736,7 +746,7 @@ function createAnalyticsClient({
736
746
  queryParameters,
737
747
  headers
738
748
  };
739
- return transporter.request(request, requestOptions);
749
+ return this.transporter.request(request, requestOptions);
740
750
  },
741
751
  /**
742
752
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -788,7 +798,7 @@ function createAnalyticsClient({
788
798
  queryParameters,
789
799
  headers
790
800
  };
791
- return transporter.request(request, requestOptions);
801
+ return this.transporter.request(request, requestOptions);
792
802
  },
793
803
  /**
794
804
  * 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 +854,7 @@ function createAnalyticsClient({
844
854
  queryParameters,
845
855
  headers
846
856
  };
847
- return transporter.request(request, requestOptions);
857
+ return this.transporter.request(request, requestOptions);
848
858
  },
849
859
  /**
850
860
  * 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 +906,7 @@ function createAnalyticsClient({
896
906
  queryParameters,
897
907
  headers
898
908
  };
899
- return transporter.request(request, requestOptions);
909
+ return this.transporter.request(request, requestOptions);
900
910
  },
901
911
  /**
902
912
  * Retrieves the object IDs of the most frequent search results.
@@ -956,7 +966,7 @@ function createAnalyticsClient({
956
966
  queryParameters,
957
967
  headers
958
968
  };
959
- return transporter.request(request, requestOptions);
969
+ return this.transporter.request(request, requestOptions);
960
970
  },
961
971
  /**
962
972
  * Returns the most popular search terms.
@@ -1031,7 +1041,7 @@ function createAnalyticsClient({
1031
1041
  queryParameters,
1032
1042
  headers
1033
1043
  };
1034
- return transporter.request(request, requestOptions);
1044
+ return this.transporter.request(request, requestOptions);
1035
1045
  },
1036
1046
  /**
1037
1047
  * 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 +1081,7 @@ function createAnalyticsClient({
1071
1081
  queryParameters,
1072
1082
  headers
1073
1083
  };
1074
- return transporter.request(request, requestOptions);
1084
+ return this.transporter.request(request, requestOptions);
1075
1085
  }
1076
1086
  };
1077
1087
  }