From 52a320a55fbbcfa170c9bfe5e2b338a43f0ba943 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 25 Jun 2026 21:39:21 +0100 Subject: [PATCH] chore: replace `uuid` with native `crypto` --- lib/builders/chat.ts | 7 +++---- lib/builders/fileshare.ts | 3 +-- lib/cot.ts | 3 +-- lib/data-package.ts | 9 ++++----- lib/parser/from_geojson.ts | 5 ++--- lib/parser/normalize_geojson.ts | 3 +-- lib/utils/util.ts | 3 +-- package.json | 1 - 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/builders/chat.ts b/lib/builders/chat.ts index 97d1297..aa83bb5 100644 --- a/lib/builders/chat.ts +++ b/lib/builders/chat.ts @@ -2,7 +2,6 @@ import Util from '../utils/util.js' import CoT from '../cot.js'; import type JSONCoT from '../types/types.js'; import type { Static } from '@sinclair/typebox'; -import { v4 as randomUUID } from 'uuid'; export type MissionChatMember = { uid: string; @@ -27,7 +26,7 @@ export type MissionChatInput = { export class MissionChat extends CoT { constructor(chat: MissionChatInput) { - const messageId = chat.messageId || randomUUID(); + const messageId = chat.messageId || crypto.randomUUID(); const cot: Static = { event: { @@ -113,7 +112,7 @@ export class DirectChat extends CoT { _attributes: { parent: chat.parent || 'RootContactGroup', groupOwner: chat.groupOwner ? 'true' : 'false', - messageId: chat.messageId || randomUUID(), + messageId: chat.messageId || crypto.randomUUID(), chatroom: chat.chatroom || chat.to.callsign, id: chat.to.uid, senderCallsign: chat.from.callsign @@ -130,7 +129,7 @@ export class DirectChat extends CoT { } } - cot.event._attributes.uid = `GeoChat.${chat.from.uid}.${chat.to.uid}.${randomUUID()}`; + cot.event._attributes.uid = `GeoChat.${chat.from.uid}.${chat.to.uid}.${crypto.randomUUID()}`; if (!cot.event.detail) cot.event.detail = {}; diff --git a/lib/builders/fileshare.ts b/lib/builders/fileshare.ts index 2f9eecf..780c2e2 100644 --- a/lib/builders/fileshare.ts +++ b/lib/builders/fileshare.ts @@ -1,5 +1,4 @@ import Util from '../utils/util.js' -import { v4 as randomUUID } from 'uuid'; import CoT from '../cot.js'; import type JSONCoT from '../types/types.js'; import type { FileShareAttributes } from '../types/types.js'; @@ -17,7 +16,7 @@ export class FileShare extends CoT { }, ackrequest: { _attributes: { - uid: randomUUID(), + uid: crypto.randomUUID(), tag: 'transfer', ackrequested: true } diff --git a/lib/cot.ts b/lib/cot.ts index 417305c..83d3c60 100644 --- a/lib/cot.ts +++ b/lib/cot.ts @@ -1,4 +1,3 @@ -import { v4 as randomUUID } from 'uuid'; import Err from '@openaddresses/batch-error'; import type { Static } from '@sinclair/typebox'; import type { @@ -198,7 +197,7 @@ export default class CoT { } else if (video.uid && connection && !connection.uid) { connection.uid = video.uid; } else if (!video.uid) { - video.uid = randomUUID(); + video.uid = crypto.randomUUID(); } detail.__video = { diff --git a/lib/data-package.ts b/lib/data-package.ts index 87347ae..7b0e2c0 100644 --- a/lib/data-package.ts +++ b/lib/data-package.ts @@ -6,7 +6,6 @@ import Err from '@openaddresses/batch-error'; import { ZipArchive } from '@archiver/archiver'; import StreamZip from 'node-stream-zip' import { Readable } from 'node:stream'; -import { v4 as randomUUID } from 'uuid'; import CoT from './cot.js'; import { CoTParser } from './parser.js'; import xmljs from 'xml-js'; @@ -94,7 +93,7 @@ async function materializeDataPackageInput( } const ext = path.parse(name || 'package.zip').ext || '.zip'; - const inputPath = path.resolve(os.tmpdir(), `${randomUUID()}${ext}`); + const inputPath = path.resolve(os.tmpdir(), `${crypto.randomUUID()}${ext}`); if (input instanceof Buffer) { await fsp.writeFile(inputPath, input); @@ -150,7 +149,7 @@ export class DataPackage { if (opts && opts.path) { this.path = opts.path; } else { - this.path = os.tmpdir() + '/' + randomUUID(); + this.path = os.tmpdir() + '/' + crypto.randomUUID(); } this.destroyed = false; @@ -160,7 +159,7 @@ export class DataPackage { this.version = '2'; this.unknown = {}; this.settings = { - uid: uid ?? randomUUID(), + uid: uid ?? crypto.randomUUID(), name: name ?? 'New Data Package' }; this.contents = []; @@ -535,7 +534,7 @@ export class DataPackage { if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed'); if (!opts.ignore) opts.ignore = false; - const uid = opts.uid ?? randomUUID(); + const uid = opts.uid ?? crypto.randomUUID(); this.#addContent(`${uid}/${opts.name}`, opts.attachment || uid, opts.name, opts.ignore); await fsp.mkdir(`${this.path}/raw/${uid}/`, { recursive: true }); diff --git a/lib/parser/from_geojson.ts b/lib/parser/from_geojson.ts index 98e120c..7462814 100644 --- a/lib/parser/from_geojson.ts +++ b/lib/parser/from_geojson.ts @@ -1,5 +1,4 @@ import Err from '@openaddresses/batch-error'; -import { v4 as randomUUID } from 'uuid'; import type { Static } from '@sinclair/typebox'; import type { LinkAttributes, @@ -68,7 +67,7 @@ export async function from_geojson( if (feature.id) { cot.event._attributes.uid = String(feature.id); } else { - cot.event._attributes.uid = randomUUID(); + cot.event._attributes.uid = crypto.randomUUID(); } if (!cot.event.detail) cot.event.detail = {}; @@ -490,7 +489,7 @@ export async function from_geojson( cot.event.detail.link.push({ _attributes: { type: 'b-m-p-c', - uid: randomUUID(), + uid: crypto.randomUUID(), callsign: "", point: `${coord[1]},${coord[0]}` } diff --git a/lib/parser/normalize_geojson.ts b/lib/parser/normalize_geojson.ts index 4a937e1..59bec5d 100644 --- a/lib/parser/normalize_geojson.ts +++ b/lib/parser/normalize_geojson.ts @@ -1,5 +1,4 @@ import Err from '@openaddresses/batch-error'; -import { v4 as randomUUID } from 'uuid'; import type { Static } from '@sinclair/typebox'; import { coordEach } from "@turf/meta"; import TypeValidator from '../type.js'; @@ -24,7 +23,7 @@ export async function normalize_geojson( } if (!feature.id) { - feature.id = randomUUID(); + feature.id = crypto.randomUUID(); } const props = feature.properties; diff --git a/lib/utils/util.ts b/lib/utils/util.ts index 1a90d96..1594381 100644 --- a/lib/utils/util.ts +++ b/lib/utils/util.ts @@ -1,4 +1,3 @@ -import { v4 as randomUUID } from 'uuid'; import type { Static } from '@sinclair/typebox'; import type { EventAttributes, @@ -73,7 +72,7 @@ export default class Util { * Generate a random UUID */ static cot_uuid(): string { - return randomUUID() + return crypto.randomUUID() } /** diff --git a/package.json b/package.json index c23139c..da73b83 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "milsymbol": "^3.0.2", "node-stream-zip": "^1.15.0", "protobufjs": "^8.0.0", - "uuid": "^14.0.0", "xml-js": "^1.6.11" }, "devDependencies": {