Skip to content

Commit 8e71785

Browse files
authored
Merge pull request #134 from anam-org/fix/local-build-and-esm-id-support
fix: remove nanoid package for better compatibility
2 parents e885ffc + 4443b6e commit 8e71785

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

package-lock.json

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"webpack-cli": "^5.1.4"
6666
},
6767
"dependencies": {
68-
"buffer": "^6.0.3",
69-
"nanoid": "^5.1.5"
68+
"buffer": "^6.0.3"
7069
}
7170
}

src/AnamClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { nanoid } from 'nanoid';
21
import { ClientError, ErrorCode } from './lib/ClientError';
2+
import { generateCorrelationId } from './lib/correlationId';
33
import {
44
ClientMetricMeasurement,
55
DEFAULT_ANAM_API_VERSION,
@@ -276,7 +276,7 @@ export default class AnamClient {
276276
throw new Error('Already streaming');
277277
}
278278
// generate a new ID here to track the attempt
279-
const attemptCorrelationId = nanoid();
279+
const attemptCorrelationId = generateCorrelationId();
280280
setMetricsContext({
281281
attemptCorrelationId,
282282
sessionId: null, // reset sessionId
@@ -342,7 +342,7 @@ export default class AnamClient {
342342
userProvidedAudioStream?: MediaStream,
343343
): Promise<void> {
344344
// generate a new ID here to track the attempt
345-
const attemptCorrelationId = nanoid();
345+
const attemptCorrelationId = generateCorrelationId();
346346
setMetricsContext({
347347
attemptCorrelationId,
348348
sessionId: null, // reset sessionId

src/lib/correlationId.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function generateCorrelationId() {
2+
// Try native crypto.randomUUID() first (supported in modern browsers)
3+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
4+
return crypto.randomUUID();
5+
}
6+
7+
// Fallback for older environments and older react native
8+
return Date.now().toString(36) + Math.random().toString(36).substr(2, 9);
9+
}

0 commit comments

Comments
 (0)