From b1ab30222de6a2ea62d7135c6119535620517c3d Mon Sep 17 00:00:00 2001 From: Lalit Kapoor Date: Fri, 29 Nov 2024 12:41:26 -0500 Subject: [PATCH 1/6] support v18 --- packages/livekit-server-sdk/package.json | 2 +- packages/livekit-server-sdk/src/WebhookReceiver.ts | 4 ++-- packages/livekit-server-sdk/src/digest.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 packages/livekit-server-sdk/src/digest.ts diff --git a/packages/livekit-server-sdk/package.json b/packages/livekit-server-sdk/package.json index 129da7d3..64949776 100644 --- a/packages/livekit-server-sdk/package.json +++ b/packages/livekit-server-sdk/package.json @@ -53,6 +53,6 @@ "vitest": "^2.0.0" }, "engines": { - "node": ">=19" + "node": ">=18" } } diff --git a/packages/livekit-server-sdk/src/WebhookReceiver.ts b/packages/livekit-server-sdk/src/WebhookReceiver.ts index 37db2476..2cddac13 100644 --- a/packages/livekit-server-sdk/src/WebhookReceiver.ts +++ b/packages/livekit-server-sdk/src/WebhookReceiver.ts @@ -4,6 +4,7 @@ import type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf'; import { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol'; import { TokenVerifier } from './AccessToken.js'; +import digest from './digest.js'; export const authorizeHeader = 'Authorize'; @@ -66,8 +67,7 @@ export class WebhookReceiver { } const claims = await this.verifier.verify(authHeader); // confirm sha - const encoder = new TextEncoder(); - const hash = await crypto.subtle.digest('SHA-256', encoder.encode(body)); + const hash = await digest(body); const hashDecoded = btoa( Array.from(new Uint8Array(hash)) .map((v) => String.fromCharCode(v)) diff --git a/packages/livekit-server-sdk/src/digest.ts b/packages/livekit-server-sdk/src/digest.ts new file mode 100644 index 00000000..f843d165 --- /dev/null +++ b/packages/livekit-server-sdk/src/digest.ts @@ -0,0 +1,10 @@ +// Use the Web Crypto API if available, otherwise fallback to Node.js crypto +export default async function digest(data: string): Promise { + if (globalThis.crypto?.subtle) { + const encoder = new TextEncoder(); + return crypto.subtle.digest('SHA-256', encoder.encode(data)); + } else { + const nodeCrypto = await import('node:crypto'); + return nodeCrypto.createHash('sha256').update(data).digest(); + } +} From d32da344201026cff6dbd443d7cf47402cda7a84 Mon Sep 17 00:00:00 2001 From: Lalit Kapoor Date: Sat, 30 Nov 2024 17:13:20 -0500 Subject: [PATCH 2/6] add license --- packages/livekit-server-sdk/src/digest.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/livekit-server-sdk/src/digest.ts b/packages/livekit-server-sdk/src/digest.ts index f843d165..e0d41718 100644 --- a/packages/livekit-server-sdk/src/digest.ts +++ b/packages/livekit-server-sdk/src/digest.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2024 LiveKit, Inc. +// +// SPDX-License-Identifier: Apache-2.0 + // Use the Web Crypto API if available, otherwise fallback to Node.js crypto export default async function digest(data: string): Promise { if (globalThis.crypto?.subtle) { From a2454944dd160eb139d99287f821bc890273a329 Mon Sep 17 00:00:00 2001 From: Lalit Kapoor Date: Sat, 30 Nov 2024 17:20:34 -0500 Subject: [PATCH 3/6] test node v18 in ci --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa66c5e9..395b9208 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,9 @@ jobs: test: name: Test + strategy: + matrix: + node-version: [18, 20] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -77,7 +80,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: 20 + node-version: ${{ matrix.node-version }} cache: pnpm - name: Install dependencies run: pnpm install From 2e431b71b4bf7521ebdf20f21563f57897049250 Mon Sep 17 00:00:00 2001 From: Lalit Kapoor Date: Sat, 30 Nov 2024 17:27:09 -0500 Subject: [PATCH 4/6] changeset --- .changeset/flat-jeans-agree.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/flat-jeans-agree.md diff --git a/.changeset/flat-jeans-agree.md b/.changeset/flat-jeans-agree.md new file mode 100644 index 00000000..5c38cb73 --- /dev/null +++ b/.changeset/flat-jeans-agree.md @@ -0,0 +1,5 @@ +--- +'livekit-server-sdk': patch +--- + +support for node v18 From be00113f8394ffaee7b6407ccaff9f3fbc1243d7 Mon Sep 17 00:00:00 2001 From: Lalit Kapoor Date: Mon, 2 Dec 2024 12:35:23 -0500 Subject: [PATCH 5/6] test node v22 in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 395b9208..807bc1fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: name: Test strategy: matrix: - node-version: [18, 20] + node-version: [18, 20, 22] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 5801c0c99ed11447d354cc7fa522bc22e07069b3 Mon Sep 17 00:00:00 2001 From: Lalit Kapoor Date: Mon, 2 Dec 2024 13:29:31 -0500 Subject: [PATCH 6/6] test latest node version in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 807bc1fa..d224a586 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: name: Test strategy: matrix: - node-version: [18, 20, 22] + node-version: [18, 20, 22, latest] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4