From 3e4c1802a5d013a0d0aaa17e5c560d2a2bd31cd9 Mon Sep 17 00:00:00 2001
From: Dhaya <154633+dhayab@users.noreply.github.com>
Date: Tue, 19 Dec 2023 11:40:22 +0100
Subject: [PATCH 1/2] feat(insights): update default version to support
 `authenticatedUserToken` (#1225)

---
 examples/playground/package.json                 |  2 +-
 .../query-suggestions-with-hits/package.json     |  2 +-
 examples/reshape/package.json                    |  2 +-
 examples/tags-in-searchbox/package.json          |  2 +-
 examples/tags-with-hits/package.json             |  2 +-
 package.json                                     |  2 +-
 .../createAlgoliaInsightsPlugin.test.ts          |  6 +++---
 .../src/createAlgoliaInsightsPlugin.ts           | 16 +++++++++++++---
 yarn.lock                                        |  8 ++++----
 9 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/examples/playground/package.json b/examples/playground/package.json
index fb50eeb8cc..56acbd7bba 100644
--- a/examples/playground/package.json
+++ b/examples/playground/package.json
@@ -17,7 +17,7 @@
     "@algolia/client-search": "4.16.0",
     "algoliasearch": "4.16.0",
     "preact": "10.13.2",
-    "search-insights": "2.6.0"
+    "search-insights": "2.13.0"
   },
   "devDependencies": {
     "parcel": "2.8.3"
diff --git a/examples/query-suggestions-with-hits/package.json b/examples/query-suggestions-with-hits/package.json
index 72d0764a45..c724d28e21 100644
--- a/examples/query-suggestions-with-hits/package.json
+++ b/examples/query-suggestions-with-hits/package.json
@@ -17,7 +17,7 @@
     "@algolia/client-search": "4.16.0",
     "algoliasearch": "4.16.0",
     "preact": "10.13.2",
-    "search-insights": "2.6.0"
+    "search-insights": "2.13.0"
   },
   "devDependencies": {
     "parcel": "2.8.3"
diff --git a/examples/reshape/package.json b/examples/reshape/package.json
index 5b814e2a23..8348b1c3cf 100644
--- a/examples/reshape/package.json
+++ b/examples/reshape/package.json
@@ -19,7 +19,7 @@
     "algoliasearch": "4.16.0",
     "preact": "10.13.2",
     "ramda": "0.27.1",
-    "search-insights": "2.6.0"
+    "search-insights": "2.13.0"
   },
   "devDependencies": {
     "@algolia/autocomplete-core": "1.12.2",
diff --git a/examples/tags-in-searchbox/package.json b/examples/tags-in-searchbox/package.json
index f4c4f41f5c..3269a76ae6 100644
--- a/examples/tags-in-searchbox/package.json
+++ b/examples/tags-in-searchbox/package.json
@@ -16,7 +16,7 @@
     "algoliasearch": "4.16.0",
     "preact": "10.13.2",
     "ramda": "0.27.1",
-    "search-insights": "2.6.0"
+    "search-insights": "2.13.0"
   },
   "devDependencies": {
     "parcel": "2.8.3"
diff --git a/examples/tags-with-hits/package.json b/examples/tags-with-hits/package.json
index 3a310a4387..833322ae5b 100644
--- a/examples/tags-with-hits/package.json
+++ b/examples/tags-with-hits/package.json
@@ -16,7 +16,7 @@
     "algoliasearch": "4.16.0",
     "preact": "10.13.2",
     "ramda": "0.27.1",
-    "search-insights": "2.6.0"
+    "search-insights": "2.13.0"
   },
   "devDependencies": {
     "parcel": "2.8.3"
diff --git a/package.json b/package.json
index 70c9418a27..3b3b3eaaca 100644
--- a/package.json
+++ b/package.json
@@ -80,7 +80,7 @@
     "rollup-plugin-license": "2.9.1",
     "rollup-plugin-terser": "7.0.2",
     "shipjs": "0.26.1",
-    "search-insights": "2.6.0",
+    "search-insights": "2.13.0",
     "start-server-and-test": "1.15.2",
     "stylelint": "13.13.1",
     "stylelint-a11y": "1.2.3",
diff --git a/packages/autocomplete-plugin-algolia-insights/src/__tests__/createAlgoliaInsightsPlugin.test.ts b/packages/autocomplete-plugin-algolia-insights/src/__tests__/createAlgoliaInsightsPlugin.test.ts
index 1ee77a35ff..079f494204 100644
--- a/packages/autocomplete-plugin-algolia-insights/src/__tests__/createAlgoliaInsightsPlugin.test.ts
+++ b/packages/autocomplete-plugin-algolia-insights/src/__tests__/createAlgoliaInsightsPlugin.test.ts
@@ -294,7 +294,7 @@ describe('createAlgoliaInsightsPlugin', () => {
       expect(document.body).toMatchInlineSnapshot(`
         <body>
           <script
-            src="https://cdn.jsdelivr.net/npm/search-insights@2.6.0/dist/search-insights.min.js"
+            src="https://cdn.jsdelivr.net/npm/search-insights@2.13.0/dist/search-insights.min.js"
           />
           <form>
             <input />
@@ -306,7 +306,7 @@ describe('createAlgoliaInsightsPlugin', () => {
       `);
       expect((window as any).AlgoliaAnalyticsObject).toBe('aa');
       expect((window as any).aa).toEqual(expect.any(Function));
-      expect((window as any).aa.version).toBe('2.6.0');
+      expect((window as any).aa.version).toBe('2.13.0');
     });
 
     it('notifies when the script fails to be added', () => {
@@ -867,7 +867,7 @@ describe('createAlgoliaInsightsPlugin', () => {
     test('sends a `clickedObjectIDsAfterSearch` event with additional parameters if client supports it', async () => {
       const insightsClient = jest.fn();
       // @ts-ignore
-      insightsClient.version = '2.6.0';
+      insightsClient.version = '2.13.0';
       const insightsPlugin = createAlgoliaInsightsPlugin({ insightsClient });
 
       const { inputElement } = createPlayground(createAutocomplete, {
diff --git a/packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts b/packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts
index c18b05a5ca..865f9b71b8 100644
--- a/packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts
+++ b/packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts
@@ -26,7 +26,7 @@ import {
 } from './types';
 
 const VIEW_EVENT_DELAY = 400;
-const ALGOLIA_INSIGHTS_VERSION = '2.6.0';
+const ALGOLIA_INSIGHTS_VERSION = '2.13.0';
 const ALGOLIA_INSIGHTS_SRC = `https://cdn.jsdelivr.net/npm/search-insights@${ALGOLIA_INSIGHTS_VERSION}/dist/search-insights.min.js`;
 
 type SendViewedObjectIDsParams = {
@@ -170,14 +170,16 @@ export function createAlgoliaInsightsPlugin(
   return {
     name: 'aa.algoliaInsightsPlugin',
     subscribe({ setContext, onSelect, onActive }) {
-      function setInsightsContext(userToken?: string) {
+      function setInsightsContext(userToken?: string | number) {
         setContext({
           algoliaInsightsPlugin: {
             __algoliaSearchParameters: {
               ...(__autocomplete_clickAnalytics
                 ? { clickAnalytics: true }
                 : {}),
-              ...(userToken ? { userToken } : {}),
+              ...(userToken
+                ? { userToken: normalizeUserToken(userToken) }
+                : {}),
             },
             insights,
           },
@@ -304,3 +306,11 @@ function loadInsights(environment: typeof window) {
     console.error(errorMessage);
   }
 }
+
+/**
+ * While `search-insights` supports both string and number user tokens,
+ * the Search API only accepts strings. This function normalizes the user token.
+ */
+function normalizeUserToken(userToken: string | number): string {
+  return typeof userToken === 'number' ? userToken.toString() : userToken;
+}
diff --git a/yarn.lock b/yarn.lock
index babc53aa17..f8c2ed8553 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -17380,10 +17380,10 @@ schema-utils@^3.0.0, schema-utils@^3.1.1:
     ajv "^6.12.5"
     ajv-keywords "^3.5.2"
 
-search-insights@2.6.0:
-  version "2.6.0"
-  resolved "https://registry.yarnpkg.com/search-insights/-/search-insights-2.6.0.tgz#bb8771a73b83c4a0f1f207c2f64fea01acd3e7d0"
-  integrity sha512-vU2/fJ+h/Mkm/DJOe+EaM5cafJv/1rRTZpGJTuFPf/Q5LjzgMDsqPdSaZsAe+GAWHHsfsu+rQSAn6c8IGtBEVw==
+search-insights@2.13.0:
+  version "2.13.0"
+  resolved "https://registry.yarnpkg.com/search-insights/-/search-insights-2.13.0.tgz#a79fdcf4b5dad2fba8975b06f2ebc37a865032b7"
+  integrity sha512-Orrsjf9trHHxFRuo9/rzm0KIWmgzE8RMlZMzuhZOJ01Rnz3D0YBAe+V6473t6/H6c7irs6Lt48brULAiRWb3Vw==
 
 search-insights@^2.1.0:
   version "2.2.1"

From 1c75231d69a79e5eecb05296d7f8231203e5dbdb Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Tue, 19 Dec 2023 10:41:16 +0000
Subject: [PATCH 2/2] chore(deps): update dependency prettier to v2.8.8

---
 package.json | 2 +-
 yarn.lock    | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/package.json b/package.json
index 3b3b3eaaca..f7cd76723a 100644
--- a/package.json
+++ b/package.json
@@ -72,7 +72,7 @@
     "postcss-color-rgb": "2.0.0",
     "postcss-preset-env": "8.3.0",
     "postcss-scss": "4.0.6",
-    "prettier": "2.8.7",
+    "prettier": "2.8.8",
     "rollup": "2.79.1",
     "rollup-plugin-babel": "4.4.0",
     "rollup-plugin-commonjs": "10.1.0",
diff --git a/yarn.lock b/yarn.lock
index f8c2ed8553..b07de7ea6c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -15970,7 +15970,12 @@ prettier-linter-helpers@^1.0.0:
   dependencies:
     fast-diff "^1.1.2"
 
-prettier@2.8.7, "prettier@^1.18.2 || ^2.0.0", prettier@^2.0.0:
+prettier@2.8.8:
+  version "2.8.8"
+  resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
+  integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
+
+"prettier@^1.18.2 || ^2.0.0", prettier@^2.0.0:
   version "2.8.7"
   resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.7.tgz#bb79fc8729308549d28fe3a98fce73d2c0656450"
   integrity sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==