@algolia/client-analytics 5.3.1 → 5.4.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.3.1";
13
+ var apiClientVersion = "5.4.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,25 +25,26 @@ function createAnalyticsClient({
25
25
  ...options
26
26
  }) {
27
27
  const auth = createAuth(appIdOption, apiKeyOption, authMode);
28
- return {
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
- }
28
+ const transporter = createTransporter({
29
+ hosts: getDefaultHosts(regionOption),
30
+ ...options,
31
+ algoliaAgent: getAlgoliaAgent({
32
+ algoliaAgents,
33
+ client: "Analytics",
34
+ version: apiClientVersion
46
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
+ return {
47
+ transporter,
47
48
  /**
48
49
  * The `appId` currently in use.
49
50
  */
@@ -52,15 +53,13 @@ function createAnalyticsClient({
52
53
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
53
54
  */
54
55
  clearCache() {
55
- return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
56
- () => void 0
57
- );
56
+ return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
58
57
  },
59
58
  /**
60
59
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
61
60
  */
62
61
  get _ua() {
63
- return this.transporter.algoliaAgent.value;
62
+ return transporter.algoliaAgent.value;
64
63
  },
65
64
  /**
66
65
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -69,7 +68,7 @@ function createAnalyticsClient({
69
68
  * @param version - The version of the agent.
70
69
  */
71
70
  addAlgoliaAgent(segment, version) {
72
- this.transporter.algoliaAgent.add({ segment, version });
71
+ transporter.algoliaAgent.add({ segment, version });
73
72
  },
74
73
  /**
75
74
  * Helper method to switch the API key used to authenticate the requests.
@@ -79,9 +78,9 @@ function createAnalyticsClient({
79
78
  */
80
79
  setClientApiKey({ apiKey }) {
81
80
  if (!authMode || authMode === "WithinHeaders") {
82
- this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
81
+ transporter.baseHeaders["x-algolia-api-key"] = apiKey;
83
82
  } else {
84
- this.transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
83
+ transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
85
84
  }
86
85
  },
87
86
  /**
@@ -105,7 +104,7 @@ function createAnalyticsClient({
105
104
  queryParameters,
106
105
  headers
107
106
  };
108
- return this.transporter.request(request, requestOptions);
107
+ return transporter.request(request, requestOptions);
109
108
  },
110
109
  /**
111
110
  * This method allow you to send requests to the Algolia REST API.
@@ -128,7 +127,7 @@ function createAnalyticsClient({
128
127
  queryParameters,
129
128
  headers
130
129
  };
131
- return this.transporter.request(request, requestOptions);
130
+ return transporter.request(request, requestOptions);
132
131
  },
133
132
  /**
134
133
  * This method allow you to send requests to the Algolia REST API.
@@ -153,7 +152,7 @@ function createAnalyticsClient({
153
152
  headers,
154
153
  data: body ? body : {}
155
154
  };
156
- return this.transporter.request(request, requestOptions);
155
+ return transporter.request(request, requestOptions);
157
156
  },
158
157
  /**
159
158
  * This method allow you to send requests to the Algolia REST API.
@@ -178,7 +177,7 @@ function createAnalyticsClient({
178
177
  headers,
179
178
  data: body ? body : {}
180
179
  };
181
- return this.transporter.request(request, requestOptions);
180
+ return transporter.request(request, requestOptions);
182
181
  },
183
182
  /**
184
183
  * 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.
@@ -218,7 +217,7 @@ function createAnalyticsClient({
218
217
  queryParameters,
219
218
  headers
220
219
  };
221
- return this.transporter.request(request, requestOptions);
220
+ return transporter.request(request, requestOptions);
222
221
  },
223
222
  /**
224
223
  * 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.
@@ -258,7 +257,7 @@ function createAnalyticsClient({
258
257
  queryParameters,
259
258
  headers
260
259
  };
261
- return this.transporter.request(request, requestOptions);
260
+ return transporter.request(request, requestOptions);
262
261
  },
263
262
  /**
264
263
  * 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.
@@ -298,7 +297,7 @@ function createAnalyticsClient({
298
297
  queryParameters,
299
298
  headers
300
299
  };
301
- return this.transporter.request(request, requestOptions);
300
+ return transporter.request(request, requestOptions);
302
301
  },
303
302
  /**
304
303
  * 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.
@@ -338,7 +337,7 @@ function createAnalyticsClient({
338
337
  queryParameters,
339
338
  headers
340
339
  };
341
- return this.transporter.request(request, requestOptions);
340
+ return transporter.request(request, requestOptions);
342
341
  },
343
342
  /**
344
343
  * 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.
@@ -378,7 +377,7 @@ function createAnalyticsClient({
378
377
  queryParameters,
379
378
  headers
380
379
  };
381
- return this.transporter.request(request, requestOptions);
380
+ return transporter.request(request, requestOptions);
382
381
  },
383
382
  /**
384
383
  * 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.
@@ -418,7 +417,7 @@ function createAnalyticsClient({
418
417
  queryParameters,
419
418
  headers
420
419
  };
421
- return this.transporter.request(request, requestOptions);
420
+ return transporter.request(request, requestOptions);
422
421
  },
423
422
  /**
424
423
  * 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.
@@ -458,7 +457,7 @@ function createAnalyticsClient({
458
457
  queryParameters,
459
458
  headers
460
459
  };
461
- return this.transporter.request(request, requestOptions);
460
+ return transporter.request(request, requestOptions);
462
461
  },
463
462
  /**
464
463
  * 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.
@@ -498,7 +497,7 @@ function createAnalyticsClient({
498
497
  queryParameters,
499
498
  headers
500
499
  };
501
- return this.transporter.request(request, requestOptions);
500
+ return transporter.request(request, requestOptions);
502
501
  },
503
502
  /**
504
503
  * 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.
@@ -538,7 +537,7 @@ function createAnalyticsClient({
538
537
  queryParameters,
539
538
  headers
540
539
  };
541
- return this.transporter.request(request, requestOptions);
540
+ return transporter.request(request, requestOptions);
542
541
  },
543
542
  /**
544
543
  * 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.
@@ -578,7 +577,7 @@ function createAnalyticsClient({
578
577
  queryParameters,
579
578
  headers
580
579
  };
581
- return this.transporter.request(request, requestOptions);
580
+ return transporter.request(request, requestOptions);
582
581
  },
583
582
  /**
584
583
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -626,7 +625,7 @@ function createAnalyticsClient({
626
625
  queryParameters,
627
626
  headers
628
627
  };
629
- return this.transporter.request(request, requestOptions);
628
+ return transporter.request(request, requestOptions);
630
629
  },
631
630
  /**
632
631
  * Retrieves the most popular searches that didn\'t return any results.
@@ -674,7 +673,7 @@ function createAnalyticsClient({
674
673
  queryParameters,
675
674
  headers
676
675
  };
677
- return this.transporter.request(request, requestOptions);
676
+ return transporter.request(request, requestOptions);
678
677
  },
679
678
  /**
680
679
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -702,7 +701,7 @@ function createAnalyticsClient({
702
701
  queryParameters,
703
702
  headers
704
703
  };
705
- return this.transporter.request(request, requestOptions);
704
+ return transporter.request(request, requestOptions);
706
705
  },
707
706
  /**
708
707
  * Retrieves the countries with the most searches to your index.
@@ -750,7 +749,7 @@ function createAnalyticsClient({
750
749
  queryParameters,
751
750
  headers
752
751
  };
753
- return this.transporter.request(request, requestOptions);
752
+ return transporter.request(request, requestOptions);
754
753
  },
755
754
  /**
756
755
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -802,7 +801,7 @@ function createAnalyticsClient({
802
801
  queryParameters,
803
802
  headers
804
803
  };
805
- return this.transporter.request(request, requestOptions);
804
+ return transporter.request(request, requestOptions);
806
805
  },
807
806
  /**
808
807
  * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -858,7 +857,7 @@ function createAnalyticsClient({
858
857
  queryParameters,
859
858
  headers
860
859
  };
861
- return this.transporter.request(request, requestOptions);
860
+ return transporter.request(request, requestOptions);
862
861
  },
863
862
  /**
864
863
  * 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.
@@ -910,7 +909,7 @@ function createAnalyticsClient({
910
909
  queryParameters,
911
910
  headers
912
911
  };
913
- return this.transporter.request(request, requestOptions);
912
+ return transporter.request(request, requestOptions);
914
913
  },
915
914
  /**
916
915
  * Retrieves the object IDs of the most frequent search results.
@@ -970,7 +969,7 @@ function createAnalyticsClient({
970
969
  queryParameters,
971
970
  headers
972
971
  };
973
- return this.transporter.request(request, requestOptions);
972
+ return transporter.request(request, requestOptions);
974
973
  },
975
974
  /**
976
975
  * Returns the most popular search terms.
@@ -1045,7 +1044,7 @@ function createAnalyticsClient({
1045
1044
  queryParameters,
1046
1045
  headers
1047
1046
  };
1048
- return this.transporter.request(request, requestOptions);
1047
+ return transporter.request(request, requestOptions);
1049
1048
  },
1050
1049
  /**
1051
1050
  * 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.
@@ -1085,7 +1084,7 @@ function createAnalyticsClient({
1085
1084
  queryParameters,
1086
1085
  headers
1087
1086
  };
1088
- return this.transporter.request(request, requestOptions);
1087
+ return transporter.request(request, requestOptions);
1089
1088
  }
1090
1089
  };
1091
1090
  }