livekit-server-sdk 2.9.2 → 2.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/AccessToken.d.cts +80 -0
  2. package/dist/AgentDispatchClient.d.cts +50 -0
  3. package/dist/EgressClient.cjs +1 -0
  4. package/dist/EgressClient.cjs.map +1 -1
  5. package/dist/EgressClient.d.cts +168 -0
  6. package/dist/EgressClient.d.ts.map +1 -1
  7. package/dist/EgressClient.js +1 -0
  8. package/dist/EgressClient.js.map +1 -1
  9. package/dist/IngressClient.d.cts +136 -0
  10. package/dist/RoomServiceClient.d.cts +173 -0
  11. package/dist/ServiceBase.d.cts +21 -0
  12. package/dist/SipClient.d.cts +142 -0
  13. package/dist/TwirpRPC.d.cts +18 -0
  14. package/dist/WebhookReceiver.cjs +12 -2
  15. package/dist/WebhookReceiver.cjs.map +1 -1
  16. package/dist/WebhookReceiver.d.cts +29 -0
  17. package/dist/WebhookReceiver.d.ts.map +1 -1
  18. package/dist/WebhookReceiver.js +2 -2
  19. package/dist/WebhookReceiver.js.map +1 -1
  20. package/dist/digest.cjs +44 -0
  21. package/dist/digest.cjs.map +1 -0
  22. package/dist/digest.d.cts +3 -0
  23. package/dist/digest.d.ts +2 -0
  24. package/dist/digest.d.ts.map +1 -0
  25. package/dist/digest.js +14 -0
  26. package/dist/digest.js.map +1 -0
  27. package/dist/grants.d.cts +71 -0
  28. package/dist/index.d.cts +12 -0
  29. package/package.json +14 -6
  30. package/src/AccessToken.test.ts +6 -6
  31. package/src/EgressClient.ts +1 -0
  32. package/src/WebhookReceiver.ts +2 -2
  33. package/src/digest.ts +14 -0
  34. package/src/grants.test.ts +2 -2
  35. package/dist/AccessToken.test.cjs +0 -147
  36. package/dist/AccessToken.test.cjs.map +0 -1
  37. package/dist/AccessToken.test.js +0 -129
  38. package/dist/AccessToken.test.js.map +0 -1
  39. package/dist/WebhookReceiver.test.cjs +0 -38
  40. package/dist/WebhookReceiver.test.cjs.map +0 -1
  41. package/dist/WebhookReceiver.test.js +0 -37
  42. package/dist/WebhookReceiver.test.js.map +0 -1
  43. package/dist/grants.test.cjs +0 -27
  44. package/dist/grants.test.cjs.map +0 -1
  45. package/dist/grants.test.js +0 -26
  46. package/dist/grants.test.js.map +0 -1
@@ -0,0 +1,136 @@
1
+ import { IngressAudioOptions, IngressVideoOptions, IngressInput, IngressInfo } from '@livekit/protocol';
2
+ import { ServiceBase } from './ServiceBase.cjs';
3
+ import './grants.cjs';
4
+ import 'jose';
5
+
6
+ interface CreateIngressOptions {
7
+ /**
8
+ * ingress name. optional
9
+ */
10
+ name?: string;
11
+ /**
12
+ * name of the room to send media to. required
13
+ */
14
+ roomName?: string;
15
+ /**
16
+ * unique identity of the participant. required
17
+ */
18
+ participantIdentity: string;
19
+ /**
20
+ * participant display name
21
+ */
22
+ participantName?: string;
23
+ /**
24
+ * metadata to attach to the participant
25
+ */
26
+ participantMetadata?: string;
27
+ /**
28
+ * @deprecated use `enableTranscoding` instead.
29
+ * whether to skip transcoding and forward the input media directly. Only supported by WHIP
30
+ */
31
+ bypassTranscoding?: boolean;
32
+ /**
33
+ * whether to enable transcoding or forward the input media directly.
34
+ * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.
35
+ */
36
+ enableTranscoding?: boolean | undefined;
37
+ /**
38
+ * url of the media to pull for ingresses of type URL
39
+ */
40
+ url?: string;
41
+ /**
42
+ * custom audio encoding parameters. optional
43
+ */
44
+ audio?: IngressAudioOptions;
45
+ /**
46
+ * custom video encoding parameters. optional
47
+ */
48
+ video?: IngressVideoOptions;
49
+ }
50
+ interface UpdateIngressOptions {
51
+ /**
52
+ * ingress name. optional
53
+ */
54
+ name: string;
55
+ /**
56
+ * name of the room to send media to.
57
+ */
58
+ roomName?: string;
59
+ /**
60
+ * unique identity of the participant.
61
+ */
62
+ participantIdentity?: string;
63
+ /**
64
+ * participant display name
65
+ */
66
+ participantName?: string;
67
+ /**
68
+ * metadata to attach to the participant
69
+ */
70
+ participantMetadata?: string;
71
+ /**
72
+ * @deprecated use `enableTranscoding` instead
73
+ * whether to skip transcoding and forward the input media directly. Only supported by WHIP
74
+ */
75
+ bypassTranscoding?: boolean | undefined;
76
+ /**
77
+ * whether to enable transcoding or forward the input media directly.
78
+ * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.
79
+ */
80
+ enableTranscoding?: boolean | undefined;
81
+ /**
82
+ * custom audio encoding parameters. optional
83
+ */
84
+ audio?: IngressAudioOptions;
85
+ /**
86
+ * custom video encoding parameters. optional
87
+ */
88
+ video?: IngressVideoOptions;
89
+ }
90
+ interface ListIngressOptions {
91
+ /**
92
+ * list ingress for one room only
93
+ */
94
+ roomName?: string;
95
+ /**
96
+ * list ingress by ID
97
+ */
98
+ ingressId?: string;
99
+ }
100
+ /**
101
+ * Client to access Ingress APIs
102
+ */
103
+ declare class IngressClient extends ServiceBase {
104
+ private readonly rpc;
105
+ /**
106
+ * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
107
+ * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
108
+ * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
109
+ */
110
+ constructor(host: string, apiKey?: string, secret?: string);
111
+ /**
112
+ * @param inputType - protocol for the ingress
113
+ * @param opts - CreateIngressOptions
114
+ */
115
+ createIngress(inputType: IngressInput, opts: CreateIngressOptions): Promise<IngressInfo>;
116
+ /**
117
+ * @param ingressId - ID of the ingress to update
118
+ * @param opts - UpdateIngressOptions
119
+ */
120
+ updateIngress(ingressId: string, opts: UpdateIngressOptions): Promise<IngressInfo>;
121
+ /**
122
+ * @deprecated use `listIngress(opts)` or `listIngress(arg)` instead
123
+ * @param roomName - list ingress for one room only
124
+ */
125
+ listIngress(roomName?: string): Promise<Array<IngressInfo>>;
126
+ /**
127
+ * @param opts - list options
128
+ */
129
+ listIngress(opts?: ListIngressOptions): Promise<Array<IngressInfo>>;
130
+ /**
131
+ * @param ingressId - ingress to delete
132
+ */
133
+ deleteIngress(ingressId: string): Promise<IngressInfo>;
134
+ }
135
+
136
+ export { type CreateIngressOptions, IngressClient, type ListIngressOptions, type UpdateIngressOptions };
@@ -0,0 +1,173 @@
1
+ import { RoomEgress, ParticipantPermission, Room, ParticipantInfo, TrackInfo, DataPacket_Kind } from '@livekit/protocol';
2
+ import { ServiceBase } from './ServiceBase.cjs';
3
+ import './grants.cjs';
4
+ import 'jose';
5
+
6
+ /**
7
+ * Options for when creating a room
8
+ */
9
+ interface CreateOptions {
10
+ /**
11
+ * name of the room. required
12
+ */
13
+ name: string;
14
+ /**
15
+ * number of seconds to keep the room open before any participant joins
16
+ */
17
+ emptyTimeout?: number;
18
+ /**
19
+ * number of seconds to keep the room open after the last participant leaves
20
+ * this option is helpful to give a grace period for participants to re-join
21
+ */
22
+ departureTimeout?: number;
23
+ /**
24
+ * limit to the number of participants in a room at a time
25
+ */
26
+ maxParticipants?: number;
27
+ /**
28
+ * initial room metadata
29
+ */
30
+ metadata?: string;
31
+ /**
32
+ * add egress options
33
+ */
34
+ egress?: RoomEgress;
35
+ /**
36
+ * minimum playout delay in milliseconds
37
+ */
38
+ minPlayoutDelay?: number;
39
+ /**
40
+ * maximum playout delay in milliseconds
41
+ */
42
+ maxPlayoutDelay?: number;
43
+ /**
44
+ * improves A/V sync when min_playout_delay set to a value larger than 200ms.
45
+ * It will disables transceiver re-use -- this option is not recommended
46
+ * for rooms with frequent subscription changes
47
+ */
48
+ syncStreams?: boolean;
49
+ /**
50
+ * override the node room is allocated to, for debugging
51
+ * does not work with Cloud
52
+ */
53
+ nodeId?: string;
54
+ }
55
+ type SendDataOptions = {
56
+ /** If set, only deliver to listed participant identities */
57
+ destinationIdentities?: string[];
58
+ destinationSids?: string[];
59
+ topic?: string;
60
+ };
61
+ type UpdateParticipantOptions = {
62
+ /** only attributes you'd want to update should be set, set value to empty string to remove it */
63
+ attributes?: {
64
+ [key: string]: string;
65
+ };
66
+ metadata?: string;
67
+ /** permissions are updated atomically - all desired permissions would need to be set */
68
+ permission?: Partial<ParticipantPermission>;
69
+ name?: string;
70
+ };
71
+ /**
72
+ * Client to access Room APIs
73
+ */
74
+ declare class RoomServiceClient extends ServiceBase {
75
+ private readonly rpc;
76
+ /**
77
+ *
78
+ * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
79
+ * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
80
+ * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
81
+ */
82
+ constructor(host: string, apiKey?: string, secret?: string);
83
+ /**
84
+ * Creates a new room. Explicit room creation is not required, since rooms will
85
+ * be automatically created when the first participant joins. This method can be
86
+ * used to customize room settings.
87
+ * @param options -
88
+ */
89
+ createRoom(options: CreateOptions): Promise<Room>;
90
+ /**
91
+ * List active rooms
92
+ * @param names - when undefined or empty, list all rooms.
93
+ * otherwise returns rooms with matching names
94
+ * @returns
95
+ */
96
+ listRooms(names?: string[]): Promise<Room[]>;
97
+ deleteRoom(room: string): Promise<void>;
98
+ /**
99
+ * Update metadata of a room
100
+ * @param room - name of the room
101
+ * @param metadata - the new metadata for the room
102
+ */
103
+ updateRoomMetadata(room: string, metadata: string): Promise<Room>;
104
+ /**
105
+ * List participants in a room
106
+ * @param room - name of the room
107
+ */
108
+ listParticipants(room: string): Promise<ParticipantInfo[]>;
109
+ /**
110
+ * Get information on a specific participant, including the tracks that participant
111
+ * has published
112
+ * @param room - name of the room
113
+ * @param identity - identity of the participant to return
114
+ */
115
+ getParticipant(room: string, identity: string): Promise<ParticipantInfo>;
116
+ /**
117
+ * Removes a participant in the room. This will disconnect the participant
118
+ * and will emit a Disconnected event for that participant.
119
+ * Even after being removed, the participant can still re-join the room.
120
+ * @param room -
121
+ * @param identity -
122
+ */
123
+ removeParticipant(room: string, identity: string): Promise<void>;
124
+ /**
125
+ * Mutes a track that the participant has published.
126
+ * @param room -
127
+ * @param identity -
128
+ * @param trackSid - sid of the track to be muted
129
+ * @param muted - true to mute, false to unmute
130
+ */
131
+ mutePublishedTrack(room: string, identity: string, trackSid: string, muted: boolean): Promise<TrackInfo>;
132
+ /**
133
+ * Updates a participant's state or permissions
134
+ * @param room - target room
135
+ * @param identity - participant identity
136
+ * @param options - participant fields to update
137
+ */
138
+ updateParticipant(room: string, identity: string, options: UpdateParticipantOptions): Promise<ParticipantInfo>;
139
+ /**
140
+ * Updates a participant's state or permissions
141
+ * @param room - target room
142
+ * @param identity - participant identity
143
+ * @param options - participant fields to update
144
+ */
145
+ updateParticipant(room: string, identity: string, metadata?: string, permission?: Partial<ParticipantPermission>, name?: string): Promise<ParticipantInfo>;
146
+ /**
147
+ * Updates a participant's subscription to tracks
148
+ * @param room -
149
+ * @param identity -
150
+ * @param trackSids -
151
+ * @param subscribe - true to subscribe, false to unsubscribe
152
+ */
153
+ updateSubscriptions(room: string, identity: string, trackSids: string[], subscribe: boolean): Promise<void>;
154
+ /**
155
+ * Sends data message to participants in the room
156
+ * @param room -
157
+ * @param data - opaque payload to send
158
+ * @param kind - delivery reliability
159
+ * @param options - optionally specify a topic and destinationSids (when destinationSids is empty, message is sent to everyone)
160
+ */
161
+ sendData(room: string, data: Uint8Array, kind: DataPacket_Kind, options: SendDataOptions): Promise<void>;
162
+ /**
163
+ * Sends data message to participants in the room
164
+ * @deprecated use sendData(room, data, kind, options) instead
165
+ * @param room -
166
+ * @param data - opaque payload to send
167
+ * @param kind - delivery reliability
168
+ * @param destinationSids - optional. when empty, message is sent to everyone
169
+ */
170
+ sendData(room: string, data: Uint8Array, kind: DataPacket_Kind, destinationSids?: string[]): Promise<void>;
171
+ }
172
+
173
+ export { type CreateOptions, RoomServiceClient, type SendDataOptions, type UpdateParticipantOptions };
@@ -0,0 +1,21 @@
1
+ import { VideoGrant, SIPGrant } from './grants.cjs';
2
+ import '@livekit/protocol';
3
+ import 'jose';
4
+
5
+ /**
6
+ * Utilities to handle authentication
7
+ */
8
+ declare class ServiceBase {
9
+ private readonly apiKey?;
10
+ private readonly secret?;
11
+ private readonly ttl;
12
+ /**
13
+ * @param apiKey - API Key.
14
+ * @param secret - API Secret.
15
+ * @param ttl - token TTL
16
+ */
17
+ constructor(apiKey?: string, secret?: string, ttl?: string);
18
+ authHeader(grant: VideoGrant, sip?: SIPGrant): Promise<Record<string, string>>;
19
+ }
20
+
21
+ export { ServiceBase };
@@ -0,0 +1,142 @@
1
+ import { SIPTransport, SIPTrunkInfo, SIPInboundTrunkInfo, SIPOutboundTrunkInfo, SIPDispatchRuleInfo, SIPParticipantInfo } from '@livekit/protocol';
2
+ import { ServiceBase } from './ServiceBase.cjs';
3
+ import './grants.cjs';
4
+ import 'jose';
5
+
6
+ /**
7
+ * @deprecated use CreateSipInboundTrunkOptions or CreateSipOutboundTrunkOptions
8
+ */
9
+ interface CreateSipTrunkOptions {
10
+ name?: string;
11
+ metadata?: string;
12
+ inbound_addresses?: string[];
13
+ inbound_numbers?: string[];
14
+ inbound_username?: string;
15
+ inbound_password?: string;
16
+ outbound_address?: string;
17
+ outbound_username?: string;
18
+ outbound_password?: string;
19
+ }
20
+ interface CreateSipInboundTrunkOptions {
21
+ metadata?: string;
22
+ allowed_addresses?: string[];
23
+ allowed_numbers?: string[];
24
+ auth_username?: string;
25
+ auth_password?: string;
26
+ headers?: {
27
+ [key: string]: string;
28
+ };
29
+ headersToAttributes?: {
30
+ [key: string]: string;
31
+ };
32
+ }
33
+ interface CreateSipOutboundTrunkOptions {
34
+ metadata?: string;
35
+ transport: SIPTransport;
36
+ auth_username?: string;
37
+ auth_password?: string;
38
+ headers?: {
39
+ [key: string]: string;
40
+ };
41
+ headersToAttributes?: {
42
+ [key: string]: string;
43
+ };
44
+ }
45
+ interface SipDispatchRuleDirect {
46
+ type: 'direct';
47
+ roomName: string;
48
+ pin?: string;
49
+ }
50
+ interface SipDispatchRuleIndividual {
51
+ type: 'individual';
52
+ roomPrefix: string;
53
+ pin?: string;
54
+ }
55
+ interface CreateSipDispatchRuleOptions {
56
+ name?: string;
57
+ metadata?: string;
58
+ trunkIds?: string[];
59
+ hidePhoneNumber?: boolean;
60
+ }
61
+ interface CreateSipParticipantOptions {
62
+ participantIdentity?: string;
63
+ participantName?: string;
64
+ participantMetadata?: string;
65
+ dtmf?: string;
66
+ /** @deprecated - use `playDialtone` instead */
67
+ playRingtone?: boolean;
68
+ playDialtone?: boolean;
69
+ hidePhoneNumber?: boolean;
70
+ ringingTimeout?: number;
71
+ maxCallDuration?: number;
72
+ enableKrisp?: boolean;
73
+ }
74
+ interface TransferSipParticipantOptions {
75
+ playDialtone?: boolean;
76
+ }
77
+ /**
78
+ * Client to access Egress APIs
79
+ */
80
+ declare class SipClient extends ServiceBase {
81
+ private readonly rpc;
82
+ /**
83
+ * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
84
+ * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
85
+ * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
86
+ */
87
+ constructor(host: string, apiKey?: string, secret?: string);
88
+ /**
89
+ * @param number - phone number of the trunk
90
+ * @param opts - CreateSipTrunkOptions
91
+ * @deprecated use `createSipInboundTrunk` or `createSipOutboundTrunk`
92
+ */
93
+ createSipTrunk(number: string, opts?: CreateSipTrunkOptions): Promise<SIPTrunkInfo>;
94
+ /**
95
+ * @param name - human-readable name of the trunk
96
+ * @param numbers - phone numbers of the trunk
97
+ * @param opts - CreateSipTrunkOptions
98
+ */
99
+ createSipInboundTrunk(name: string, numbers: string[], opts?: CreateSipInboundTrunkOptions): Promise<SIPInboundTrunkInfo>;
100
+ /**
101
+ * @param name - human-readable name of the trunk
102
+ * @param address - hostname and port of the SIP server to dial
103
+ * @param numbers - phone numbers of the trunk
104
+ * @param opts - CreateSipTrunkOptions
105
+ */
106
+ createSipOutboundTrunk(name: string, address: string, numbers: string[], opts?: CreateSipOutboundTrunkOptions): Promise<SIPOutboundTrunkInfo>;
107
+ /**
108
+ * @deprecated use `listSipInboundTrunk` or `listSipOutboundTrunk`
109
+ */
110
+ listSipTrunk(): Promise<Array<SIPTrunkInfo>>;
111
+ listSipInboundTrunk(): Promise<Array<SIPInboundTrunkInfo>>;
112
+ listSipOutboundTrunk(): Promise<Array<SIPOutboundTrunkInfo>>;
113
+ /**
114
+ * @param sipTrunkId - sip trunk to delete
115
+ */
116
+ deleteSipTrunk(sipTrunkId: string): Promise<SIPTrunkInfo>;
117
+ /**
118
+ * @param rule - sip dispatch rule
119
+ * @param opts - CreateSipDispatchRuleOptions
120
+ */
121
+ createSipDispatchRule(rule: SipDispatchRuleDirect | SipDispatchRuleIndividual, opts?: CreateSipDispatchRuleOptions): Promise<SIPDispatchRuleInfo>;
122
+ listSipDispatchRule(): Promise<Array<SIPDispatchRuleInfo>>;
123
+ /**
124
+ * @param sipDispatchRuleId - sip trunk to delete
125
+ */
126
+ deleteSipDispatchRule(sipDispatchRuleId: string): Promise<SIPDispatchRuleInfo>;
127
+ /**
128
+ * @param sipTrunkId - sip trunk to use for the call
129
+ * @param number - number to dial
130
+ * @param roomName - room to attach the call to
131
+ * @param opts - CreateSipParticipantOptions
132
+ */
133
+ createSipParticipant(sipTrunkId: string, number: string, roomName: string, opts?: CreateSipParticipantOptions): Promise<SIPParticipantInfo>;
134
+ /**
135
+ * @param roomName - room the SIP participant to transfer is connectd to
136
+ * @param participantIdentity - identity of the SIP participant to transfer
137
+ * @param transferTo - SIP URL to transfer the participant to
138
+ */
139
+ transferSipParticipant(roomName: string, participantIdentity: string, transferTo: string, opts?: TransferSipParticipantOptions): Promise<void>;
140
+ }
141
+
142
+ export { type CreateSipDispatchRuleOptions, type CreateSipInboundTrunkOptions, type CreateSipOutboundTrunkOptions, type CreateSipParticipantOptions, type CreateSipTrunkOptions, SipClient, type SipDispatchRuleDirect, type SipDispatchRuleIndividual, type TransferSipParticipantOptions };
@@ -0,0 +1,18 @@
1
+ import { JsonValue } from '@bufbuild/protobuf';
2
+
3
+ declare const livekitPackage = "livekit";
4
+ interface Rpc {
5
+ request(service: string, method: string, data: JsonValue, headers?: any): Promise<string>;
6
+ }
7
+ /**
8
+ * JSON based Twirp V7 RPC
9
+ */
10
+ declare class TwirpRpc {
11
+ host: string;
12
+ pkg: string;
13
+ prefix: string;
14
+ constructor(host: string, pkg: string, prefix?: string);
15
+ request(service: string, method: string, data: any, headers?: any): Promise<any>;
16
+ }
17
+
18
+ export { type Rpc, TwirpRpc, livekitPackage };
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var WebhookReceiver_exports = {};
20
30
  __export(WebhookReceiver_exports, {
@@ -25,6 +35,7 @@ __export(WebhookReceiver_exports, {
25
35
  module.exports = __toCommonJS(WebhookReceiver_exports);
26
36
  var import_protocol = require("@livekit/protocol");
27
37
  var import_AccessToken = require("./AccessToken.cjs");
38
+ var import_digest = __toESM(require("./digest.cjs"), 1);
28
39
  const authorizeHeader = "Authorize";
29
40
  class WebhookEvent extends import_protocol.WebhookEvent {
30
41
  constructor() {
@@ -57,8 +68,7 @@ class WebhookReceiver {
57
68
  throw new Error("authorization header is empty");
58
69
  }
59
70
  const claims = await this.verifier.verify(authHeader);
60
- const encoder = new TextEncoder();
61
- const hash = await crypto.subtle.digest("SHA-256", encoder.encode(body));
71
+ const hash = await (0, import_digest.default)(body);
62
72
  const hashDecoded = btoa(
63
73
  Array.from(new Uint8Array(hash)).map((v) => String.fromCharCode(v)).join("")
64
74
  );
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/WebhookReceiver.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf';\nimport { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol';\nimport { TokenVerifier } from './AccessToken.js';\n\nexport const authorizeHeader = 'Authorize';\n\nexport class WebhookEvent extends ProtoWebhookEvent {\n event: WebhookEventNames = '';\n\n static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): WebhookEvent {\n return new WebhookEvent().fromBinary(bytes, options);\n }\n\n static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJson(jsonValue, options);\n }\n\n static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJsonString(jsonString, options);\n }\n}\n\nexport type WebhookEventNames =\n | 'room_started'\n | 'room_finished'\n | 'participant_joined'\n | 'participant_left'\n | 'track_published'\n | 'track_unpublished'\n | 'egress_started'\n | 'egress_updated'\n | 'egress_ended'\n | 'ingress_started'\n | 'ingress_ended'\n /**\n * @internal\n * @remarks only used as a default value, not a valid webhook event\n */\n | '';\n\nexport class WebhookReceiver {\n private verifier: TokenVerifier;\n\n constructor(apiKey: string, apiSecret: string) {\n this.verifier = new TokenVerifier(apiKey, apiSecret);\n }\n\n /**\n * @param body - string of the posted body\n * @param authHeader - `Authorization` header from the request\n * @param skipAuth - true to skip auth validation\n * @returns\n */\n async receive(\n body: string,\n authHeader?: string,\n skipAuth: boolean = false,\n ): Promise<WebhookEvent> {\n // verify token\n if (!skipAuth) {\n if (!authHeader) {\n throw new Error('authorization header is empty');\n }\n const claims = await this.verifier.verify(authHeader);\n // confirm sha\n const encoder = new TextEncoder();\n const hash = await crypto.subtle.digest('SHA-256', encoder.encode(body));\n const hashDecoded = btoa(\n Array.from(new Uint8Array(hash))\n .map((v) => String.fromCharCode(v))\n .join(''),\n );\n\n if (claims.sha256 !== hashDecoded) {\n throw new Error('sha256 checksum of body does not match');\n }\n }\n\n return WebhookEvent.fromJson(JSON.parse(body), { ignoreUnknownFields: true });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAkD;AAClD,yBAA8B;AAEvB,MAAM,kBAAkB;AAExB,MAAM,qBAAqB,gBAAAA,aAAkB;AAAA,EAA7C;AAAA;AACL,iBAA2B;AAAA;AAAA,EAE3B,OAAO,WAAW,OAAmB,SAAoD;AACvF,WAAO,IAAI,aAAa,EAAE,WAAW,OAAO,OAAO;AAAA,EACrD;AAAA,EAEA,OAAO,SAAS,WAAsB,SAAkD;AACtF,WAAO,IAAI,aAAa,EAAE,SAAS,WAAW,OAAO;AAAA,EACvD;AAAA,EAEA,OAAO,eAAe,YAAoB,SAAkD;AAC1F,WAAO,IAAI,aAAa,EAAE,eAAe,YAAY,OAAO;AAAA,EAC9D;AACF;AAoBO,MAAM,gBAAgB;AAAA,EAG3B,YAAY,QAAgB,WAAmB;AAC7C,SAAK,WAAW,IAAI,iCAAc,QAAQ,SAAS;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QACJ,MACA,YACA,WAAoB,OACG;AAEvB,QAAI,CAAC,UAAU;AACb,UAAI,CAAC,YAAY;AACf,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,YAAM,SAAS,MAAM,KAAK,SAAS,OAAO,UAAU;AAEpD,YAAM,UAAU,IAAI,YAAY;AAChC,YAAM,OAAO,MAAM,OAAO,OAAO,OAAO,WAAW,QAAQ,OAAO,IAAI,CAAC;AACvE,YAAM,cAAc;AAAA,QAClB,MAAM,KAAK,IAAI,WAAW,IAAI,CAAC,EAC5B,IAAI,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC,EACjC,KAAK,EAAE;AAAA,MACZ;AAEA,UAAI,OAAO,WAAW,aAAa;AACjC,cAAM,IAAI,MAAM,wCAAwC;AAAA,MAC1D;AAAA,IACF;AAEA,WAAO,aAAa,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,qBAAqB,KAAK,CAAC;AAAA,EAC9E;AACF;","names":["ProtoWebhookEvent"]}
1
+ {"version":3,"sources":["../src/WebhookReceiver.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf';\nimport { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol';\nimport { TokenVerifier } from './AccessToken.js';\nimport digest from './digest.js';\n\nexport const authorizeHeader = 'Authorize';\n\nexport class WebhookEvent extends ProtoWebhookEvent {\n event: WebhookEventNames = '';\n\n static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): WebhookEvent {\n return new WebhookEvent().fromBinary(bytes, options);\n }\n\n static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJson(jsonValue, options);\n }\n\n static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJsonString(jsonString, options);\n }\n}\n\nexport type WebhookEventNames =\n | 'room_started'\n | 'room_finished'\n | 'participant_joined'\n | 'participant_left'\n | 'track_published'\n | 'track_unpublished'\n | 'egress_started'\n | 'egress_updated'\n | 'egress_ended'\n | 'ingress_started'\n | 'ingress_ended'\n /**\n * @internal\n * @remarks only used as a default value, not a valid webhook event\n */\n | '';\n\nexport class WebhookReceiver {\n private verifier: TokenVerifier;\n\n constructor(apiKey: string, apiSecret: string) {\n this.verifier = new TokenVerifier(apiKey, apiSecret);\n }\n\n /**\n * @param body - string of the posted body\n * @param authHeader - `Authorization` header from the request\n * @param skipAuth - true to skip auth validation\n * @returns\n */\n async receive(\n body: string,\n authHeader?: string,\n skipAuth: boolean = false,\n ): Promise<WebhookEvent> {\n // verify token\n if (!skipAuth) {\n if (!authHeader) {\n throw new Error('authorization header is empty');\n }\n const claims = await this.verifier.verify(authHeader);\n // confirm sha\n const hash = await digest(body);\n const hashDecoded = btoa(\n Array.from(new Uint8Array(hash))\n .map((v) => String.fromCharCode(v))\n .join(''),\n );\n\n if (claims.sha256 !== hashDecoded) {\n throw new Error('sha256 checksum of body does not match');\n }\n }\n\n return WebhookEvent.fromJson(JSON.parse(body), { ignoreUnknownFields: true });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAkD;AAClD,yBAA8B;AAC9B,oBAAmB;AAEZ,MAAM,kBAAkB;AAExB,MAAM,qBAAqB,gBAAAA,aAAkB;AAAA,EAA7C;AAAA;AACL,iBAA2B;AAAA;AAAA,EAE3B,OAAO,WAAW,OAAmB,SAAoD;AACvF,WAAO,IAAI,aAAa,EAAE,WAAW,OAAO,OAAO;AAAA,EACrD;AAAA,EAEA,OAAO,SAAS,WAAsB,SAAkD;AACtF,WAAO,IAAI,aAAa,EAAE,SAAS,WAAW,OAAO;AAAA,EACvD;AAAA,EAEA,OAAO,eAAe,YAAoB,SAAkD;AAC1F,WAAO,IAAI,aAAa,EAAE,eAAe,YAAY,OAAO;AAAA,EAC9D;AACF;AAoBO,MAAM,gBAAgB;AAAA,EAG3B,YAAY,QAAgB,WAAmB;AAC7C,SAAK,WAAW,IAAI,iCAAc,QAAQ,SAAS;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QACJ,MACA,YACA,WAAoB,OACG;AAEvB,QAAI,CAAC,UAAU;AACb,UAAI,CAAC,YAAY;AACf,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,YAAM,SAAS,MAAM,KAAK,SAAS,OAAO,UAAU;AAEpD,YAAM,OAAO,UAAM,cAAAC,SAAO,IAAI;AAC9B,YAAM,cAAc;AAAA,QAClB,MAAM,KAAK,IAAI,WAAW,IAAI,CAAC,EAC5B,IAAI,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC,EACjC,KAAK,EAAE;AAAA,MACZ;AAEA,UAAI,OAAO,WAAW,aAAa;AACjC,cAAM,IAAI,MAAM,wCAAwC;AAAA,MAC1D;AAAA,IACF;AAEA,WAAO,aAAa,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,qBAAqB,KAAK,CAAC;AAAA,EAC9E;AACF;","names":["ProtoWebhookEvent","digest"]}
@@ -0,0 +1,29 @@
1
+ import { BinaryReadOptions, JsonValue, JsonReadOptions } from '@bufbuild/protobuf';
2
+ import { WebhookEvent as WebhookEvent$1 } from '@livekit/protocol';
3
+
4
+ declare const authorizeHeader = "Authorize";
5
+ declare class WebhookEvent extends WebhookEvent$1 {
6
+ event: WebhookEventNames;
7
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): WebhookEvent;
8
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): WebhookEvent;
9
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): WebhookEvent;
10
+ }
11
+ type WebhookEventNames = 'room_started' | 'room_finished' | 'participant_joined' | 'participant_left' | 'track_published' | 'track_unpublished' | 'egress_started' | 'egress_updated' | 'egress_ended' | 'ingress_started' | 'ingress_ended'
12
+ /**
13
+ * @internal
14
+ * @remarks only used as a default value, not a valid webhook event
15
+ */
16
+ | '';
17
+ declare class WebhookReceiver {
18
+ private verifier;
19
+ constructor(apiKey: string, apiSecret: string);
20
+ /**
21
+ * @param body - string of the posted body
22
+ * @param authHeader - `Authorization` header from the request
23
+ * @param skipAuth - true to skip auth validation
24
+ * @returns
25
+ */
26
+ receive(body: string, authHeader?: string, skipAuth?: boolean): Promise<WebhookEvent>;
27
+ }
28
+
29
+ export { WebhookEvent, type WebhookEventNames, WebhookReceiver, authorizeHeader };
@@ -1 +1 @@
1
- {"version":3,"file":"WebhookReceiver.d.ts","sourceRoot":"","sources":["../src/WebhookReceiver.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtE,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,KAAK,EAAE,iBAAiB,CAAM;IAE9B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,YAAY;IAIxF,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,YAAY;IAIvF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,YAAY;CAG5F;AAED,MAAM,MAAM,iBAAiB,GACzB,cAAc,GACd,eAAe,GACf,oBAAoB,GACpB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,GACnB,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,iBAAiB,GACjB,eAAe;AACjB;;;GAGG;GACD,EAAE,CAAC;AAEP,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAI7C;;;;;OAKG;IACG,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,YAAY,CAAC;CAuBzB"}
1
+ {"version":3,"file":"WebhookReceiver.d.ts","sourceRoot":"","sources":["../src/WebhookReceiver.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAItE,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,KAAK,EAAE,iBAAiB,CAAM;IAE9B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,YAAY;IAIxF,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,YAAY;IAIvF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,YAAY;CAG5F;AAED,MAAM,MAAM,iBAAiB,GACzB,cAAc,GACd,eAAe,GACf,oBAAoB,GACpB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,GACnB,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,iBAAiB,GACjB,eAAe;AACjB;;;GAGG;GACD,EAAE,CAAC;AAEP,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAI7C;;;;;OAKG;IACG,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,YAAY,CAAC;CAsBzB"}
@@ -1,5 +1,6 @@
1
1
  import { WebhookEvent as ProtoWebhookEvent } from "@livekit/protocol";
2
2
  import { TokenVerifier } from "./AccessToken.js";
3
+ import digest from "./digest.js";
3
4
  const authorizeHeader = "Authorize";
4
5
  class WebhookEvent extends ProtoWebhookEvent {
5
6
  constructor() {
@@ -32,8 +33,7 @@ class WebhookReceiver {
32
33
  throw new Error("authorization header is empty");
33
34
  }
34
35
  const claims = await this.verifier.verify(authHeader);
35
- const encoder = new TextEncoder();
36
- const hash = await crypto.subtle.digest("SHA-256", encoder.encode(body));
36
+ const hash = await digest(body);
37
37
  const hashDecoded = btoa(
38
38
  Array.from(new Uint8Array(hash)).map((v) => String.fromCharCode(v)).join("")
39
39
  );
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/WebhookReceiver.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf';\nimport { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol';\nimport { TokenVerifier } from './AccessToken.js';\n\nexport const authorizeHeader = 'Authorize';\n\nexport class WebhookEvent extends ProtoWebhookEvent {\n event: WebhookEventNames = '';\n\n static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): WebhookEvent {\n return new WebhookEvent().fromBinary(bytes, options);\n }\n\n static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJson(jsonValue, options);\n }\n\n static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJsonString(jsonString, options);\n }\n}\n\nexport type WebhookEventNames =\n | 'room_started'\n | 'room_finished'\n | 'participant_joined'\n | 'participant_left'\n | 'track_published'\n | 'track_unpublished'\n | 'egress_started'\n | 'egress_updated'\n | 'egress_ended'\n | 'ingress_started'\n | 'ingress_ended'\n /**\n * @internal\n * @remarks only used as a default value, not a valid webhook event\n */\n | '';\n\nexport class WebhookReceiver {\n private verifier: TokenVerifier;\n\n constructor(apiKey: string, apiSecret: string) {\n this.verifier = new TokenVerifier(apiKey, apiSecret);\n }\n\n /**\n * @param body - string of the posted body\n * @param authHeader - `Authorization` header from the request\n * @param skipAuth - true to skip auth validation\n * @returns\n */\n async receive(\n body: string,\n authHeader?: string,\n skipAuth: boolean = false,\n ): Promise<WebhookEvent> {\n // verify token\n if (!skipAuth) {\n if (!authHeader) {\n throw new Error('authorization header is empty');\n }\n const claims = await this.verifier.verify(authHeader);\n // confirm sha\n const encoder = new TextEncoder();\n const hash = await crypto.subtle.digest('SHA-256', encoder.encode(body));\n const hashDecoded = btoa(\n Array.from(new Uint8Array(hash))\n .map((v) => String.fromCharCode(v))\n .join(''),\n );\n\n if (claims.sha256 !== hashDecoded) {\n throw new Error('sha256 checksum of body does not match');\n }\n }\n\n return WebhookEvent.fromJson(JSON.parse(body), { ignoreUnknownFields: true });\n }\n}\n"],"mappings":"AAIA,SAAS,gBAAgB,yBAAyB;AAClD,SAAS,qBAAqB;AAEvB,MAAM,kBAAkB;AAExB,MAAM,qBAAqB,kBAAkB;AAAA,EAA7C;AAAA;AACL,iBAA2B;AAAA;AAAA,EAE3B,OAAO,WAAW,OAAmB,SAAoD;AACvF,WAAO,IAAI,aAAa,EAAE,WAAW,OAAO,OAAO;AAAA,EACrD;AAAA,EAEA,OAAO,SAAS,WAAsB,SAAkD;AACtF,WAAO,IAAI,aAAa,EAAE,SAAS,WAAW,OAAO;AAAA,EACvD;AAAA,EAEA,OAAO,eAAe,YAAoB,SAAkD;AAC1F,WAAO,IAAI,aAAa,EAAE,eAAe,YAAY,OAAO;AAAA,EAC9D;AACF;AAoBO,MAAM,gBAAgB;AAAA,EAG3B,YAAY,QAAgB,WAAmB;AAC7C,SAAK,WAAW,IAAI,cAAc,QAAQ,SAAS;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QACJ,MACA,YACA,WAAoB,OACG;AAEvB,QAAI,CAAC,UAAU;AACb,UAAI,CAAC,YAAY;AACf,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,YAAM,SAAS,MAAM,KAAK,SAAS,OAAO,UAAU;AAEpD,YAAM,UAAU,IAAI,YAAY;AAChC,YAAM,OAAO,MAAM,OAAO,OAAO,OAAO,WAAW,QAAQ,OAAO,IAAI,CAAC;AACvE,YAAM,cAAc;AAAA,QAClB,MAAM,KAAK,IAAI,WAAW,IAAI,CAAC,EAC5B,IAAI,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC,EACjC,KAAK,EAAE;AAAA,MACZ;AAEA,UAAI,OAAO,WAAW,aAAa;AACjC,cAAM,IAAI,MAAM,wCAAwC;AAAA,MAC1D;AAAA,IACF;AAEA,WAAO,aAAa,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,qBAAqB,KAAK,CAAC;AAAA,EAC9E;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/WebhookReceiver.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf';\nimport { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol';\nimport { TokenVerifier } from './AccessToken.js';\nimport digest from './digest.js';\n\nexport const authorizeHeader = 'Authorize';\n\nexport class WebhookEvent extends ProtoWebhookEvent {\n event: WebhookEventNames = '';\n\n static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): WebhookEvent {\n return new WebhookEvent().fromBinary(bytes, options);\n }\n\n static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJson(jsonValue, options);\n }\n\n static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): WebhookEvent {\n return new WebhookEvent().fromJsonString(jsonString, options);\n }\n}\n\nexport type WebhookEventNames =\n | 'room_started'\n | 'room_finished'\n | 'participant_joined'\n | 'participant_left'\n | 'track_published'\n | 'track_unpublished'\n | 'egress_started'\n | 'egress_updated'\n | 'egress_ended'\n | 'ingress_started'\n | 'ingress_ended'\n /**\n * @internal\n * @remarks only used as a default value, not a valid webhook event\n */\n | '';\n\nexport class WebhookReceiver {\n private verifier: TokenVerifier;\n\n constructor(apiKey: string, apiSecret: string) {\n this.verifier = new TokenVerifier(apiKey, apiSecret);\n }\n\n /**\n * @param body - string of the posted body\n * @param authHeader - `Authorization` header from the request\n * @param skipAuth - true to skip auth validation\n * @returns\n */\n async receive(\n body: string,\n authHeader?: string,\n skipAuth: boolean = false,\n ): Promise<WebhookEvent> {\n // verify token\n if (!skipAuth) {\n if (!authHeader) {\n throw new Error('authorization header is empty');\n }\n const claims = await this.verifier.verify(authHeader);\n // confirm sha\n const hash = await digest(body);\n const hashDecoded = btoa(\n Array.from(new Uint8Array(hash))\n .map((v) => String.fromCharCode(v))\n .join(''),\n );\n\n if (claims.sha256 !== hashDecoded) {\n throw new Error('sha256 checksum of body does not match');\n }\n }\n\n return WebhookEvent.fromJson(JSON.parse(body), { ignoreUnknownFields: true });\n }\n}\n"],"mappings":"AAIA,SAAS,gBAAgB,yBAAyB;AAClD,SAAS,qBAAqB;AAC9B,OAAO,YAAY;AAEZ,MAAM,kBAAkB;AAExB,MAAM,qBAAqB,kBAAkB;AAAA,EAA7C;AAAA;AACL,iBAA2B;AAAA;AAAA,EAE3B,OAAO,WAAW,OAAmB,SAAoD;AACvF,WAAO,IAAI,aAAa,EAAE,WAAW,OAAO,OAAO;AAAA,EACrD;AAAA,EAEA,OAAO,SAAS,WAAsB,SAAkD;AACtF,WAAO,IAAI,aAAa,EAAE,SAAS,WAAW,OAAO;AAAA,EACvD;AAAA,EAEA,OAAO,eAAe,YAAoB,SAAkD;AAC1F,WAAO,IAAI,aAAa,EAAE,eAAe,YAAY,OAAO;AAAA,EAC9D;AACF;AAoBO,MAAM,gBAAgB;AAAA,EAG3B,YAAY,QAAgB,WAAmB;AAC7C,SAAK,WAAW,IAAI,cAAc,QAAQ,SAAS;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QACJ,MACA,YACA,WAAoB,OACG;AAEvB,QAAI,CAAC,UAAU;AACb,UAAI,CAAC,YAAY;AACf,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,YAAM,SAAS,MAAM,KAAK,SAAS,OAAO,UAAU;AAEpD,YAAM,OAAO,MAAM,OAAO,IAAI;AAC9B,YAAM,cAAc;AAAA,QAClB,MAAM,KAAK,IAAI,WAAW,IAAI,CAAC,EAC5B,IAAI,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC,EACjC,KAAK,EAAE;AAAA,MACZ;AAEA,UAAI,OAAO,WAAW,aAAa;AACjC,cAAM,IAAI,MAAM,wCAAwC;AAAA,MAC1D;AAAA,IACF;AAEA,WAAO,aAAa,SAAS,KAAK,MAAM,IAAI,GAAG,EAAE,qBAAqB,KAAK,CAAC;AAAA,EAC9E;AACF;","names":[]}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var digest_exports = {};
30
+ __export(digest_exports, {
31
+ default: () => digest
32
+ });
33
+ module.exports = __toCommonJS(digest_exports);
34
+ async function digest(data) {
35
+ var _a;
36
+ if ((_a = globalThis.crypto) == null ? void 0 : _a.subtle) {
37
+ const encoder = new TextEncoder();
38
+ return crypto.subtle.digest("SHA-256", encoder.encode(data));
39
+ } else {
40
+ const nodeCrypto = await import("node:crypto");
41
+ return nodeCrypto.createHash("sha256").update(data).digest();
42
+ }
43
+ }
44
+ //# sourceMappingURL=digest.cjs.map