From 208073ce17fbbd78be32e507bc110c9f9ebc85f3 Mon Sep 17 00:00:00 2001 From: Daniel Rochetti Date: Thu, 21 Dec 2023 11:49:44 -0800 Subject: [PATCH] fix: react native uuid compatibility (#39) --- libs/client/package.json | 5 +++-- libs/client/src/function.spec.ts | 4 ++-- libs/client/src/realtime.ts | 5 +++-- libs/client/src/utils.spec.ts | 4 ++-- libs/client/tsconfig.lib.json | 1 + libs/client/tsconfig.spec.json | 1 + package-lock.json | 8 +++++++- package.json | 3 ++- 8 files changed, 21 insertions(+), 10 deletions(-) diff --git a/libs/client/package.json b/libs/client/package.json index eaaa688..3892690 100644 --- a/libs/client/package.json +++ b/libs/client/package.json @@ -1,7 +1,7 @@ { "name": "@fal-ai/serverless-client", "description": "The fal serverless JS/TS client", - "version": "0.7.3", + "version": "0.7.4", "license": "MIT", "repository": { "type": "git", @@ -17,7 +17,8 @@ ], "dependencies": { "@msgpack/msgpack": "^3.0.0-beta2", - "robot3": "^0.4.1" + "robot3": "^0.4.1", + "uuid-random": "^1.3.2" }, "engines": { "node": ">=18.0.0" diff --git a/libs/client/src/function.spec.ts b/libs/client/src/function.spec.ts index 66411fa..6c0e5e5 100644 --- a/libs/client/src/function.spec.ts +++ b/libs/client/src/function.spec.ts @@ -1,10 +1,10 @@ -import { randomUUID } from 'crypto'; +import uuid from 'uuid-random'; import { getConfig } from './config'; import { buildUrl } from './function'; describe('The function test suite', () => { it('should build the URL with a function UUIDv4', () => { - const id = randomUUID(); + const id = uuid(); const url = buildUrl(`12345/${id}`); expect(url).toMatch(`trigger/12345/${id}`); }); diff --git a/libs/client/src/realtime.ts b/libs/client/src/realtime.ts index ce0e79b..403b23c 100644 --- a/libs/client/src/realtime.ts +++ b/libs/client/src/realtime.ts @@ -12,6 +12,7 @@ import { state, transition, } from 'robot3'; +import uuid from 'uuid-random'; import { getConfig, getRestApiUrl } from './config'; import { dispatchRequest } from './request'; import { ApiError } from './response'; @@ -391,7 +392,7 @@ export const realtimeImpl: RealtimeClient = { const { // if running on React in the server, set clientOnly to true by default clientOnly = isReact() && !isBrowser(), - connectionKey = crypto.randomUUID(), + connectionKey = uuid(), maxBuffering, throttleInterval = DEFAULT_THROTTLE_INTERVAL, } = handler; @@ -530,7 +531,7 @@ export const realtimeImpl: RealtimeClient = { ? input : { ...input, - request_id: input['request_id'] ?? crypto.randomUUID(), + request_id: input['request_id'] ?? uuid(), }; stateMachine.throttledSend({ diff --git a/libs/client/src/utils.spec.ts b/libs/client/src/utils.spec.ts index efc37e5..0140d96 100644 --- a/libs/client/src/utils.spec.ts +++ b/libs/client/src/utils.spec.ts @@ -1,9 +1,9 @@ -import { randomUUID } from 'crypto'; +import uuid from 'uuid-random'; import { isUUIDv4 } from './utils'; describe('The utils test suite', () => { it('should match a valid v4 uuid', () => { - const id = randomUUID(); + const id = uuid(); expect(isUUIDv4(id)).toBe(true); }); diff --git a/libs/client/tsconfig.lib.json b/libs/client/tsconfig.lib.json index d241f70..c595e07 100644 --- a/libs/client/tsconfig.lib.json +++ b/libs/client/tsconfig.lib.json @@ -5,6 +5,7 @@ "outDir": "../../dist/out-tsc", "inlineSources": true, "declaration": true, + "esModuleInterop": true, "allowJs": true, "checkJs": false, "types": ["node"] diff --git a/libs/client/tsconfig.spec.json b/libs/client/tsconfig.spec.json index 26ef046..68c1012 100644 --- a/libs/client/tsconfig.spec.json +++ b/libs/client/tsconfig.spec.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "esModuleInterop": true, "outDir": "../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"] diff --git a/package-lock.json b/package-lock.json index d519c5d..7d3aa52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,8 @@ "regenerator-runtime": "0.13.7", "robot3": "^0.4.1", "ts-morph": "^17.0.1", - "tslib": "^2.3.0" + "tslib": "^2.3.0", + "uuid-random": "^1.3.2" }, "devDependencies": { "@commitlint/cli": "^17.0.0", @@ -27990,6 +27991,11 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/uuid-random": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/uuid-random/-/uuid-random-1.3.2.tgz", + "integrity": "sha512-UOzej0Le/UgkbWEO8flm+0y+G+ljUon1QWTEZOq1rnMAsxo2+SckbiZdKzAHHlVh6gJqI1TjC/xwgR50MuCrBQ==" + }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", diff --git a/package.json b/package.json index 209fb6d..62a84f2 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "regenerator-runtime": "0.13.7", "robot3": "^0.4.1", "ts-morph": "^17.0.1", - "tslib": "^2.3.0" + "tslib": "^2.3.0", + "uuid-random": "^1.3.2" }, "devDependencies": { "@commitlint/cli": "^17.0.0",