From 8daf95e10a208f408e19eab4fdbc40c3870646a5 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Mon, 13 May 2024 08:49:24 +0200 Subject: [PATCH] chore: remove nanoid dependency --- apps/package-manager/packages/generic/package.json | 1 - .../packages/generic/src/credentials.ts | 14 +++++++++++--- yarn.lock | 10 ---------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/package-manager/packages/generic/package.json b/apps/package-manager/packages/generic/package.json index 38b05244..e1b0be50 100644 --- a/apps/package-manager/packages/generic/package.json +++ b/apps/package-manager/packages/generic/package.json @@ -21,7 +21,6 @@ "data-store": "^4.0.3", "deep-extend": "^0.6.0", "fast-clone": "^1.5.13", - "nanoid": "^3.3.4", "underscore": "^1.12.0" }, "devDependencies": { diff --git a/apps/package-manager/packages/generic/src/credentials.ts b/apps/package-manager/packages/generic/src/credentials.ts index a733a0ba..08eae47c 100644 --- a/apps/package-manager/packages/generic/src/credentials.ts +++ b/apps/package-manager/packages/generic/src/credentials.ts @@ -1,5 +1,4 @@ import { CoreCredentials, PeripheralDeviceId, protectString } from '@sofie-automation/server-core-integration' -import { nanoid } from 'nanoid' // eslint-disable-next-line @typescript-eslint/no-var-requires const DataStore = require('data-store') @@ -14,11 +13,20 @@ export function getCredentials(name: string): CoreCredentials { let credentials: CoreCredentials = store.get('CoreCredentials') if (!credentials) { credentials = { - deviceId: protectString(nanoid()), - deviceToken: nanoid(), + deviceId: protectString(randomString()), + deviceToken: randomString(), } store.set('CoreCredentials', credentials) } return credentials } + +function randomString(length = 20): string { + const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + let result = '' + for (let i = length; i > 0; --i) { + result += chars[Math.floor(Math.random() * chars.length)] + } + return result +} diff --git a/yarn.lock b/yarn.lock index be2407e2..75e9cf8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1655,7 +1655,6 @@ __metadata: deep-extend: "npm:^0.6.0" fast-clone: "npm:^1.5.13" jest: "npm:*" - nanoid: "npm:^3.3.4" rimraf: "npm:^5.0.5" underscore: "npm:^1.12.0" peerDependencies: @@ -8775,15 +8774,6 @@ __metadata: languageName: node linkType: hard -"nanoid@npm:^3.3.4": - version: 3.3.7 - resolution: "nanoid@npm:3.3.7" - bin: - nanoid: bin/nanoid.cjs - checksum: 10/ac1eb60f615b272bccb0e2b9cd933720dad30bf9708424f691b8113826bb91aca7e9d14ef5d9415a6ba15c266b37817256f58d8ce980c82b0ba3185352565679 - languageName: node - linkType: hard - "nanotimer@npm:^0.3.15": version: 0.3.15 resolution: "nanotimer@npm:0.3.15"