Skip to content

Commit

Permalink
chore(1-3230): use homebrew version of uuid generation (#240)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasheartman authored Jan 16, 2025
1 parent e204714 commit 40daee5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,6 +10,7 @@ import {
urlWithContextAsQuery,
} from './util';
import { sdkVersion } from './version';
import { uuidv4 } from './uuidv4';

const DEFINED_FIELDS = [
'userId',
Expand Down
14 changes: 14 additions & 0 deletions src/uuidv4.ts
Original file line number Diff line number Diff line change
@@ -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);
});
};

0 comments on commit 40daee5

Please sign in to comment.