From 5dd5778ee1a653f52ef9b5d178f3ef41f8ae3dfc Mon Sep 17 00:00:00 2001 From: Joy A Date: Tue, 28 Nov 2023 12:24:17 +0530 Subject: [PATCH] #1201 | Use 'uuid' package to generate random UUIDs --- packages/openchs-android/package-lock.json | 74 +++++++++++++++---- packages/openchs-android/package.json | 6 +- .../openchs-android/src/utility/General.js | 8 +- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/packages/openchs-android/package-lock.json b/packages/openchs-android/package-lock.json index 0d249c272..709923b99 100644 --- a/packages/openchs-android/package-lock.json +++ b/packages/openchs-android/package-lock.json @@ -33,7 +33,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.30.88", + "openchs-models": "1.30.91", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", @@ -49,6 +49,7 @@ "react-native-file-viewer": "2.1.5", "react-native-fs": "2.20.0", "react-native-geolocation-service": "5.3.0", + "react-native-get-random-values": "^1.10.0", "react-native-i18n": "^0.1.1", "react-native-image-picker": "5.3.1", "react-native-image-zoom-viewer": "3.0.1", @@ -72,7 +73,8 @@ "rn-fetch-blob": "0.13.0-beta-1", "rules-config": "github:openchs/rules-config#fe552da405368bfd138e2f38e605c1d307e3ebe4", "stacktrace-js": "2.0.2", - "transducers-js": "0.4.174" + "transducers-js": "0.4.174", + "uuid": "^9.0.1" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -16431,9 +16433,12 @@ } }, "node_modules/openchs-models": { - "version": "1.30.88", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.88.tgz", - "integrity": "sha512-ZHiQuPGyz+f7cf+jSQCti3wnGTIz53oZxI3rLMJ4H/IRMnfVQBeN14wtNlUE0UXkoItVqimL7fVog2q4apbY/g==", + "version": "1.30.91", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.91.tgz", + "integrity": "sha512-sgTeTKIjc51V3r8pli+xi0s1TtB9jwpeDzYEH+iXPCPCFw/wB3rX4nepsMzjclQgQMgcTDtMoWOthLvxyOR8nQ==", + "dependencies": { + "uuid": "^9.0.1" + }, "peerDependencies": { "lodash": "*", "moment": "*" @@ -17753,6 +17758,17 @@ "resolved": "https://registry.npmjs.org/react-native-geolocation-service/-/react-native-geolocation-service-5.3.0.tgz", "integrity": "sha512-imK/yjxqPMIydSjZLpqPh7U073Fpe1JAaZHiIzLzWnzv89OGey6t4Zj/POg3+xtmGcbDoMcEOx8hbNY/fXaD9Q==" }, + "node_modules/react-native-get-random-values": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/react-native-get-random-values/-/react-native-get-random-values-1.10.0.tgz", + "integrity": "sha512-gZ1zbXhbb8+Jy9qYTV8c4Nf45/VB4g1jmXuavY5rPfUn7x3ok9Vl3FTl0dnE92Z4FFtfbUNNwtSfcmomdtWg+A==", + "dependencies": { + "fast-base64-decode": "^1.0.0" + }, + "peerDependencies": { + "react-native": ">=0.56" + } + }, "node_modules/react-native-i18n": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/react-native-i18n/-/react-native-i18n-0.1.1.tgz", @@ -21447,9 +21463,13 @@ } }, "node_modules/uuid": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", - "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } @@ -22351,6 +22371,14 @@ "node": ">=10.0.0" } }, + "node_modules/xcode/node_modules/uuid": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", + "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/xml2js": { "version": "0.4.23", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", @@ -35131,9 +35159,12 @@ } }, "openchs-models": { - "version": "1.30.88", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.88.tgz", - "integrity": "sha512-ZHiQuPGyz+f7cf+jSQCti3wnGTIz53oZxI3rLMJ4H/IRMnfVQBeN14wtNlUE0UXkoItVqimL7fVog2q4apbY/g==" + "version": "1.30.91", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.30.91.tgz", + "integrity": "sha512-sgTeTKIjc51V3r8pli+xi0s1TtB9jwpeDzYEH+iXPCPCFw/wB3rX4nepsMzjclQgQMgcTDtMoWOthLvxyOR8nQ==", + "requires": { + "uuid": "^9.0.1" + } }, "opencollective-postinstall": { "version": "2.0.3", @@ -36328,6 +36359,14 @@ "resolved": "https://registry.npmjs.org/react-native-geolocation-service/-/react-native-geolocation-service-5.3.0.tgz", "integrity": "sha512-imK/yjxqPMIydSjZLpqPh7U073Fpe1JAaZHiIzLzWnzv89OGey6t4Zj/POg3+xtmGcbDoMcEOx8hbNY/fXaD9Q==" }, + "react-native-get-random-values": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/react-native-get-random-values/-/react-native-get-random-values-1.10.0.tgz", + "integrity": "sha512-gZ1zbXhbb8+Jy9qYTV8c4Nf45/VB4g1jmXuavY5rPfUn7x3ok9Vl3FTl0dnE92Z4FFtfbUNNwtSfcmomdtWg+A==", + "requires": { + "fast-base64-decode": "^1.0.0" + } + }, "react-native-i18n": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/react-native-i18n/-/react-native-i18n-0.1.1.tgz", @@ -39101,9 +39140,9 @@ "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, "uuid": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", - "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==" + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==" }, "v8-to-istanbul": { "version": "9.0.1", @@ -39846,6 +39885,13 @@ "requires": { "simple-plist": "^1.1.0", "uuid": "^7.0.3" + }, + "dependencies": { + "uuid": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", + "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==" + } } }, "xml2js": { diff --git a/packages/openchs-android/package.json b/packages/openchs-android/package.json index b0fc71853..bf94cd020 100644 --- a/packages/openchs-android/package.json +++ b/packages/openchs-android/package.json @@ -57,7 +57,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.30.88", + "openchs-models": "1.30.91", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", @@ -73,6 +73,7 @@ "react-native-file-viewer": "2.1.5", "react-native-fs": "2.20.0", "react-native-geolocation-service": "5.3.0", + "react-native-get-random-values": "^1.10.0", "react-native-i18n": "^0.1.1", "react-native-image-picker": "5.3.1", "react-native-image-zoom-viewer": "3.0.1", @@ -96,7 +97,8 @@ "rn-fetch-blob": "0.13.0-beta-1", "rules-config": "github:openchs/rules-config#fe552da405368bfd138e2f38e605c1d307e3ebe4", "stacktrace-js": "2.0.2", - "transducers-js": "0.4.174" + "transducers-js": "0.4.174", + "uuid": "^9.0.1" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/packages/openchs-android/src/utility/General.js b/packages/openchs-android/src/utility/General.js index 9cf0a5b54..a1c2637cc 100644 --- a/packages/openchs-android/src/utility/General.js +++ b/packages/openchs-android/src/utility/General.js @@ -2,6 +2,8 @@ import {Concept, Duration, Observation} from 'avni-models'; import _ from 'lodash'; import moment from "moment"; import EnvironmentConfig from "../framework/EnvironmentConfig"; +import 'react-native-get-random-values'; +import { v4 as uuidv4 } from 'uuid'; let currentLogLevel; @@ -178,12 +180,8 @@ class General { return dest; } - //http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript static randomUUID() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); + return uuidv4(); } static objectsShallowEquals(a: Object, b: Object): Boolean {