@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.
@@ -26,7 +26,7 @@ __export(analyticsClient_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(analyticsClient_exports);
28
28
  var import_client_common = require("@algolia/client-common");
29
- var apiClientVersion = "5.2.5";
29
+ var apiClientVersion = "5.3.0";
30
30
  var REGIONS = ["de", "us"];
31
31
  function getDefaultHosts(region) {
32
32
  const url = !region ? "analytics.algolia.com" : "analytics.{region}.algolia.com".replace("{region}", region);
@@ -41,26 +41,25 @@ function createAnalyticsClient({
41
41
  ...options
42
42
  }) {
43
43
  const auth = (0, import_client_common.createAuth)(appIdOption, apiKeyOption, authMode);
44
- const transporter = (0, import_client_common.createTransporter)({
45
- hosts: getDefaultHosts(regionOption),
46
- ...options,
47
- algoliaAgent: (0, import_client_common.getAlgoliaAgent)({
48
- algoliaAgents,
49
- client: "Analytics",
50
- version: apiClientVersion
51
- }),
52
- baseHeaders: {
53
- "content-type": "text/plain",
54
- ...auth.headers(),
55
- ...options.baseHeaders
56
- },
57
- baseQueryParameters: {
58
- ...auth.queryParameters(),
59
- ...options.baseQueryParameters
60
- }
61
- });
62
44
  return {
63
- transporter,
45
+ transporter: (0, import_client_common.createTransporter)({
46
+ hosts: getDefaultHosts(regionOption),
47
+ ...options,
48
+ algoliaAgent: (0, import_client_common.getAlgoliaAgent)({
49
+ algoliaAgents,
50
+ client: "Analytics",
51
+ version: apiClientVersion
52
+ }),
53
+ baseHeaders: {
54
+ "content-type": "text/plain",
55
+ ...auth.headers(),
56
+ ...options.baseHeaders
57
+ },
58
+ baseQueryParameters: {
59
+ ...auth.queryParameters(),
60
+ ...options.baseQueryParameters
61
+ }
62
+ }),
64
63
  /**
65
64
  * The `appId` currently in use.
66
65
  */
@@ -69,13 +68,15 @@ function createAnalyticsClient({
69
68
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
70
69
  */
71
70
  clearCache() {
72
- return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
71
+ return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
72
+ () => void 0
73
+ );
73
74
  },
74
75
  /**
75
76
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
76
77
  */
77
78
  get _ua() {
78
- return transporter.algoliaAgent.value;
79
+ return this.transporter.algoliaAgent.value;
79
80
  },
80
81
  /**
81
82
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -84,7 +85,16 @@ function createAnalyticsClient({
84
85
  * @param version - The version of the agent.
85
86
  */
86
87
  addAlgoliaAgent(segment, version) {
87
- transporter.algoliaAgent.add({ segment, version });
88
+ this.transporter.algoliaAgent.add({ segment, version });
89
+ },
90
+ /**
91
+ * Helper method to switch the API key used to authenticate the requests.
92
+ *
93
+ * @param params - Method params.
94
+ * @param params.apiKey - The new API Key to use.
95
+ */
96
+ setClientApiKey({ apiKey }) {
97
+ this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
88
98
  },
89
99
  /**
90
100
  * This method allow you to send requests to the Algolia REST API.
@@ -107,7 +117,7 @@ function createAnalyticsClient({
107
117
  queryParameters,
108
118
  headers
109
119
  };
110
- return transporter.request(request, requestOptions);
120
+ return this.transporter.request(request, requestOptions);
111
121
  },
112
122
  /**
113
123
  * This method allow you to send requests to the Algolia REST API.
@@ -130,7 +140,7 @@ function createAnalyticsClient({
130
140
  queryParameters,
131
141
  headers
132
142
  };
133
- return transporter.request(request, requestOptions);
143
+ return this.transporter.request(request, requestOptions);
134
144
  },
135
145
  /**
136
146
  * This method allow you to send requests to the Algolia REST API.
@@ -155,7 +165,7 @@ function createAnalyticsClient({
155
165
  headers,
156
166
  data: body ? body : {}
157
167
  };
158
- return transporter.request(request, requestOptions);
168
+ return this.transporter.request(request, requestOptions);
159
169
  },
160
170
  /**
161
171
  * This method allow you to send requests to the Algolia REST API.
@@ -180,7 +190,7 @@ function createAnalyticsClient({
180
190
  headers,
181
191
  data: body ? body : {}
182
192
  };
183
- return transporter.request(request, requestOptions);
193
+ return this.transporter.request(request, requestOptions);
184
194
  },
185
195
  /**
186
196
  * 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.
@@ -220,7 +230,7 @@ function createAnalyticsClient({
220
230
  queryParameters,
221
231
  headers
222
232
  };
223
- return transporter.request(request, requestOptions);
233
+ return this.transporter.request(request, requestOptions);
224
234
  },
225
235
  /**
226
236
  * 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.
@@ -260,7 +270,7 @@ function createAnalyticsClient({
260
270
  queryParameters,
261
271
  headers
262
272
  };
263
- return transporter.request(request, requestOptions);
273
+ return this.transporter.request(request, requestOptions);
264
274
  },
265
275
  /**
266
276
  * 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.
@@ -300,7 +310,7 @@ function createAnalyticsClient({
300
310
  queryParameters,
301
311
  headers
302
312
  };
303
- return transporter.request(request, requestOptions);
313
+ return this.transporter.request(request, requestOptions);
304
314
  },
305
315
  /**
306
316
  * 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.
@@ -340,7 +350,7 @@ function createAnalyticsClient({
340
350
  queryParameters,
341
351
  headers
342
352
  };
343
- return transporter.request(request, requestOptions);
353
+ return this.transporter.request(request, requestOptions);
344
354
  },
345
355
  /**
346
356
  * 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.
@@ -380,7 +390,7 @@ function createAnalyticsClient({
380
390
  queryParameters,
381
391
  headers
382
392
  };
383
- return transporter.request(request, requestOptions);
393
+ return this.transporter.request(request, requestOptions);
384
394
  },
385
395
  /**
386
396
  * 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.
@@ -420,7 +430,7 @@ function createAnalyticsClient({
420
430
  queryParameters,
421
431
  headers
422
432
  };
423
- return transporter.request(request, requestOptions);
433
+ return this.transporter.request(request, requestOptions);
424
434
  },
425
435
  /**
426
436
  * 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.
@@ -460,7 +470,7 @@ function createAnalyticsClient({
460
470
  queryParameters,
461
471
  headers
462
472
  };
463
- return transporter.request(request, requestOptions);
473
+ return this.transporter.request(request, requestOptions);
464
474
  },
465
475
  /**
466
476
  * 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.
@@ -500,7 +510,7 @@ function createAnalyticsClient({
500
510
  queryParameters,
501
511
  headers
502
512
  };
503
- return transporter.request(request, requestOptions);
513
+ return this.transporter.request(request, requestOptions);
504
514
  },
505
515
  /**
506
516
  * 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.
@@ -540,7 +550,7 @@ function createAnalyticsClient({
540
550
  queryParameters,
541
551
  headers
542
552
  };
543
- return transporter.request(request, requestOptions);
553
+ return this.transporter.request(request, requestOptions);
544
554
  },
545
555
  /**
546
556
  * 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.
@@ -580,7 +590,7 @@ function createAnalyticsClient({
580
590
  queryParameters,
581
591
  headers
582
592
  };
583
- return transporter.request(request, requestOptions);
593
+ return this.transporter.request(request, requestOptions);
584
594
  },
585
595
  /**
586
596
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -628,7 +638,7 @@ function createAnalyticsClient({
628
638
  queryParameters,
629
639
  headers
630
640
  };
631
- return transporter.request(request, requestOptions);
641
+ return this.transporter.request(request, requestOptions);
632
642
  },
633
643
  /**
634
644
  * Retrieves the most popular searches that didn\'t return any results.
@@ -676,7 +686,7 @@ function createAnalyticsClient({
676
686
  queryParameters,
677
687
  headers
678
688
  };
679
- return transporter.request(request, requestOptions);
689
+ return this.transporter.request(request, requestOptions);
680
690
  },
681
691
  /**
682
692
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -704,7 +714,7 @@ function createAnalyticsClient({
704
714
  queryParameters,
705
715
  headers
706
716
  };
707
- return transporter.request(request, requestOptions);
717
+ return this.transporter.request(request, requestOptions);
708
718
  },
709
719
  /**
710
720
  * Retrieves the countries with the most searches to your index.
@@ -752,7 +762,7 @@ function createAnalyticsClient({
752
762
  queryParameters,
753
763
  headers
754
764
  };
755
- return transporter.request(request, requestOptions);
765
+ return this.transporter.request(request, requestOptions);
756
766
  },
757
767
  /**
758
768
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -804,7 +814,7 @@ function createAnalyticsClient({
804
814
  queryParameters,
805
815
  headers
806
816
  };
807
- return transporter.request(request, requestOptions);
817
+ return this.transporter.request(request, requestOptions);
808
818
  },
809
819
  /**
810
820
  * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -860,7 +870,7 @@ function createAnalyticsClient({
860
870
  queryParameters,
861
871
  headers
862
872
  };
863
- return transporter.request(request, requestOptions);
873
+ return this.transporter.request(request, requestOptions);
864
874
  },
865
875
  /**
866
876
  * 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.
@@ -912,7 +922,7 @@ function createAnalyticsClient({
912
922
  queryParameters,
913
923
  headers
914
924
  };
915
- return transporter.request(request, requestOptions);
925
+ return this.transporter.request(request, requestOptions);
916
926
  },
917
927
  /**
918
928
  * Retrieves the object IDs of the most frequent search results.
@@ -972,7 +982,7 @@ function createAnalyticsClient({
972
982
  queryParameters,
973
983
  headers
974
984
  };
975
- return transporter.request(request, requestOptions);
985
+ return this.transporter.request(request, requestOptions);
976
986
  },
977
987
  /**
978
988
  * Returns the most popular search terms.
@@ -1047,7 +1057,7 @@ function createAnalyticsClient({
1047
1057
  queryParameters,
1048
1058
  headers
1049
1059
  };
1050
- return transporter.request(request, requestOptions);
1060
+ return this.transporter.request(request, requestOptions);
1051
1061
  },
1052
1062
  /**
1053
1063
  * 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.
@@ -1087,7 +1097,7 @@ function createAnalyticsClient({
1087
1097
  queryParameters,
1088
1098
  headers
1089
1099
  };
1090
- return transporter.request(request, requestOptions);
1100
+ return this.transporter.request(request, requestOptions);
1091
1101
  }
1092
1102
  };
1093
1103
  }