From 09dccc34d62b610030da96d6af2b02884c520447 Mon Sep 17 00:00:00 2001 From: Jason Buchanan Date: Mon, 25 Mar 2024 08:10:38 -0600 Subject: [PATCH] fix: buffer typescript error in util.ts when parsing ArrayBuffer --- package-lock.json | 2 -- package.json | 2 -- src/libs/util.ts | 29 +++++++++++++++-------------- tsconfig.json | 47 +++++++++++++++++------------------------------ 4 files changed, 32 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index fef5d86..a6a37a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "@vueuse/core": "^10.9.0", "@zxing/text-encoding": "^0.9.0", "axios": "^1.6.8", - "buffer": "^6.0.3", "class-transformer": "^0.5.1", "dexie": "^3.2.7", "dexie-export-import": "^4.1.1", @@ -66,7 +65,6 @@ }, "devDependencies": { "@types/leaflet": "^1.9.8", - "@types/node": "^20.11.30", "@types/ramda": "^0.29.11", "@types/three": "^0.155.1", "@types/ua-parser-js": "^0.7.39", diff --git a/package.json b/package.json index 0bde793..acd4b8e 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "@vueuse/core": "^10.9.0", "@zxing/text-encoding": "^0.9.0", "axios": "^1.6.8", - "buffer": "^6.0.3", "class-transformer": "^0.5.1", "dexie": "^3.2.7", "dexie-export-import": "^4.1.1", @@ -67,7 +66,6 @@ }, "devDependencies": { "@types/leaflet": "^1.9.8", - "@types/node": "^20.11.30", "@types/ramda": "^0.29.11", "@types/three": "^0.155.1", "@types/ua-parser-js": "^0.7.39", diff --git a/src/libs/util.ts b/src/libs/util.ts index 598b8ff..28162dd 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -12,8 +12,6 @@ import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto"; import { GenericServerRecord, containsHiddenDid } from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer"; -import { Buffer } from "buffer/"; - // If you edit this, check that the numbers still line up on the side in the alert (on mobile, too), // and make sure they can take all actions while the notification shows. export const ONBOARD_MESSAGE = @@ -237,6 +235,19 @@ export const generateSaveAndActivateIdentity = async (): Promise => { return newId.did; }; +function getBase64(subscription: PushSubscription, key: PushEncryptionKeyName) { + const buffer = subscription.getKey(key); + if (!buffer) { + return null; + } + const value = Buffer.from(buffer); + return value + .toString("base64") + .replace(/\+/g, "-") + .replace(/\//g, "_") + .replace(/=+$/, ""); +} + export const sendTestThroughPushServer = async ( subscription: PushSubscription, skipFilter: boolean, @@ -253,18 +264,8 @@ export const sendTestThroughPushServer = async ( // Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213 const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION"; - const auth = Buffer.from(subscription.getKey("auth")); - const authB64 = auth - .toString("base64") - .replace(/\+/g, "-") - .replace(/\//g, "_") - .replace(/=+$/, ""); - const p256dh = Buffer.from(subscription.getKey("p256dh")); - const p256dhB64 = p256dh - .toString("base64") - .replace(/\+/g, "-") - .replace(/\//g, "_") - .replace(/=+$/, ""); + const authB64 = getBase64(subscription, "auth"); + const p256dhB64 = getBase64(subscription, "p256dh"); const newPayload = { endpoint: subscription.endpoint, keys: { diff --git a/tsconfig.json b/tsconfig.json index d74b0d8..256daeb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,48 +1,35 @@ { - "compilerOptions": { - "allowJs": true, - "resolveJsonModule": true, - "target": "ES2020", - "module": "ESNext", - "strict": true, - "strictPropertyInitialization": false, - "jsx": "preserve", - "moduleResolution": "bundler", + "compilerOptions": { + "target": "ES2020", // Latest ECMAScript features that are widely supported by modern browsers + "module": "ESNext", // Use ES modules + "strict": true, // Enable all strict type checking options + "jsx": "preserve", // Preserves JSX to be transformed by Babel or another transpiler + "moduleResolution": "node", // Use Node.js style module resolution "experimentalDecorators": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, // Enables compatibility with CommonJS modules for default imports + "allowSyntheticDefaultImports": true, // Allow default imports from modules with no default export + "forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file "useDefineForClassFields": true, "sourceMap": true, - "baseUrl": "./src", - "types": [ - "node" - ], + "baseUrl": "./src", // Base directory to resolve non-relative module names "paths": { "@/components/*": ["components/*"], "@/views/*": ["views/*"], "@/db/*": ["db/*"], "@/libs/*": ["libs/*"], "@/constants/*": ["constants/*"], - "@/store/*": ["store/*"], + "@/store/*": ["store/*"] }, - "lib": [ - "esnext", - "es2020", - "dom", - "dom.iterable", - "scripthost" - ] - }, - "include": [ + "lib": ["ES2020", "dom", "dom.iterable"], // Include typings for ES2020 and DOM APIs + }, + "include": [ "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx" - ], - "exclude": [ + ], + "exclude": [ "node_modules" - ] + ] }