Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
"peerDependenciesMeta": {
"@react-native-async-storage/async-storage": {
"optional": true
},
"react-native-get-random-values": {
"optional": true
}
},
"engines": {
Expand Down
24 changes: 21 additions & 3 deletions packages/core/src/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';

// `uuid` relies on a `crypto.getRandomValues` implementation, which React
// Native does not provide out of the box. `react-native-get-random-values` is
// the canonical polyfill, but it's an optional peer dependency: consumers may
// already polyfill `crypto.getRandomValues` themselves (e.g. via
// react-native-quick-crypto), so we don't want to force it on everyone.
try {
require('react-native-get-random-values');
} catch {
// No-op: a `crypto.getRandomValues` polyfill may already be installed globally.
}

export const getUUID = (): string => {
const UUID = uuidv4().toString();
return UUID;
try {
return uuidv4().toString();
} catch {
throw new Error(
"@segment/analytics-react-native requires a 'crypto.getRandomValues' " +
"polyfill, which doesn't appear to be installed. Install " +
"'react-native-get-random-values' and import before " +
'initializing the analytics client.'
);
}
};
3 changes: 3 additions & 0 deletions packages/sovran/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
"peerDependenciesMeta": {
"@react-native-async-storage/async-storage": {
"optional": true
},
"react-native-get-random-values": {
"optional": true
}
},
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4559,6 +4559,8 @@ __metadata:
peerDependenciesMeta:
"@react-native-async-storage/async-storage":
optional: true
react-native-get-random-values:
optional: true
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -4595,6 +4597,8 @@ __metadata:
peerDependenciesMeta:
"@react-native-async-storage/async-storage":
optional: true
react-native-get-random-values:
optional: true
languageName: unknown
linkType: soft

Expand Down
Loading