From 40daee5a19b9f99dccd2b382a80502a54cb465b9 Mon Sep 17 00:00:00 2001
From: Thomas Heartman <thomas@getunleash.io>
Date: Thu, 16 Jan 2025 13:25:23 +0100
Subject: [PATCH 1/2] chore(1-3230): use homebrew version of uuid generation
 (#240)

The one from the uuid library relies on an underlying crypto library
which doesn't exist at least in certain GitHub runners and may also
cause issues for react native applications.

This impl sidesteps that issue.


The same uuid generation method that we're cutting out here is also being used in src/events-handler.ts. However, because we haven't received any complaints about that, I'll leave it in.
---
 src/index.ts  |  2 +-
 src/uuidv4.ts | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 src/uuidv4.ts

diff --git a/src/index.ts b/src/index.ts
index 748f00e..eff6f41 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,4 @@
 import { TinyEmitter } from 'tiny-emitter';
-import { v4 as uuidv4 } from 'uuid';
 import Metrics from './metrics';
 import type IStorageProvider from './storage-provider';
 import InMemoryStorageProvider from './storage-provider-inmemory';
@@ -11,6 +10,7 @@ import {
     urlWithContextAsQuery,
 } from './util';
 import { sdkVersion } from './version';
+import { uuidv4 } from './uuidv4';
 
 const DEFINED_FIELDS = [
     'userId',
diff --git a/src/uuidv4.ts b/src/uuidv4.ts
new file mode 100644
index 0000000..7929359
--- /dev/null
+++ b/src/uuidv4.ts
@@ -0,0 +1,14 @@
+/**
+ * This function generates a UUID using Math.random().
+ * The distribution of unique values is not guaranteed to be as robust
+ * as with a crypto module but works across all platforms (Node, React Native, browser JS).
+ *
+ * We use it for connection id generation which is not critical for security.
+ */
+export const uuidv4 = (): string => {
+    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
+        const r = (Math.random() * 16) | 0;
+        const v = c === 'x' ? r : (r & 0x3) | 0x8;
+        return v.toString(16);
+    });
+};

From bf26e94fb18b1b5d5b5cae4753bbee1f75ba9535 Mon Sep 17 00:00:00 2001
From: GitHub Actions Bot <>
Date: Thu, 16 Jan 2025 12:27:08 +0000
Subject: [PATCH 2/2] v3.7.2

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package.json b/package.json
index eb5828a..40ea932 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "unleash-proxy-client",
-  "version": "3.7.1",
+  "version": "3.7.2",
   "description": "A browser client that can be used together with Unleash Edge or the Unleash Frontend API.",
   "type": "module",
   "main": "./build/index.cjs",