steelseries-sonar-sdk 0.3.5 → 0.4.0

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.
package/dist/index.js CHANGED
@@ -4955,1713 +4955,1710 @@ function createResponseVolumeData(volumeData) {
4955
4955
  isMuted: volumeData.muted
4956
4956
  };
4957
4957
  }
4958
- // src/functions/custom-fetch.ts
4959
- import https2 from "node:https";
4958
+ // src/sonar/requests/volume-settings/request-volume-settings-streamer.ts
4959
+ async function requestVolumeSettingsStreamer(sonarEndpoint) {
4960
+ let response;
4961
+ try {
4962
+ const url = new URL(`${sonarEndpoint}/volumeSettings/streamer`);
4963
+ response = await fetch(url);
4964
+ } catch (error) {
4965
+ throw new SonarRequestException({ innerException: error });
4966
+ }
4967
+ if (response.ok) {
4968
+ const data = await response.json();
4969
+ if (data?.masters?.stream == null) {
4970
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
4971
+ }
4972
+ return data;
4973
+ } else {
4974
+ const data = await response.json();
4975
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
4976
+ }
4977
+ }
4960
4978
 
4961
- // node_modules/node-fetch/src/index.js
4962
- import http2 from "node:http";
4963
- import https from "node:https";
4964
- import zlib from "node:zlib";
4965
- import Stream2, { PassThrough as PassThrough2, pipeline as pump } from "node:stream";
4966
- import { Buffer as Buffer3 } from "node:buffer";
4979
+ // src/functions/audio/get-audio-data-stream.ts
4980
+ async function getAudioDataStream(sonarEndpoint) {
4981
+ const data = await requestVolumeSettingsStreamer(sonarEndpoint);
4982
+ const volumeData = {
4983
+ ["master" /* Master */]: createResponseVolumeData2(data.masters.stream),
4984
+ ["game" /* Game */]: data.devices.game && createResponseVolumeData2(data.devices.game.stream),
4985
+ ["chat" /* Chat */]: data.devices.chatRender && createResponseVolumeData2(data.devices.chatRender.stream),
4986
+ ["media" /* Media */]: data.devices.media && createResponseVolumeData2(data.devices.media.stream),
4987
+ ["aux" /* Aux */]: data.devices.aux && createResponseVolumeData2(data.devices.aux.stream),
4988
+ ["mic" /* Mic */]: data.devices.chatCapture && createResponseVolumeData2(data.devices.chatCapture.stream)
4989
+ };
4990
+ return volumeData;
4991
+ }
4992
+ function createResponseVolumeData2(volumeData) {
4993
+ return {
4994
+ ["streaming" /* Streaming */]: {
4995
+ volume: convertVolumeToUser(volumeData.streaming.volume),
4996
+ isMuted: volumeData.streaming.muted
4997
+ },
4998
+ ["monitoring" /* Monitoring */]: {
4999
+ volume: convertVolumeToUser(volumeData.monitoring.volume),
5000
+ isMuted: volumeData.monitoring.muted
5001
+ }
5002
+ };
5003
+ }
5004
+ // src/sonar/models/audio-settings/enums/audio-mode.ts
5005
+ var AudioMode2;
5006
+ ((AudioMode3) => {
5007
+ AudioMode3["Classic"] = "classic";
5008
+ AudioMode3["Streamer"] = "stream";
5009
+ })(AudioMode2 ||= {});
4967
5010
 
4968
- // node_modules/data-uri-to-buffer/dist/index.js
4969
- function dataUriToBuffer(uri) {
4970
- if (!/^data:/i.test(uri)) {
4971
- throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');
5011
+ // src/sonar/requests/mode/request-audio-mode.ts
5012
+ async function requestAudioMode(sonarEndpoint) {
5013
+ let response;
5014
+ const url = new URL(`${sonarEndpoint}/mode`);
5015
+ try {
5016
+ response = await fetch(url);
5017
+ } catch (error) {
5018
+ throw new SonarRequestException({ innerException: error });
4972
5019
  }
4973
- uri = uri.replace(/\r?\n/g, "");
4974
- const firstComma = uri.indexOf(",");
4975
- if (firstComma === -1 || firstComma <= 4) {
4976
- throw new TypeError("malformed data: URI");
5020
+ if (response.ok) {
5021
+ const data = await response.json();
5022
+ if (Object.values(AudioMode2).includes(data)) {
5023
+ return data;
5024
+ }
5025
+ throw new SonarRequestException({ message: "Received unhandled audio mode from Sonar server" });
5026
+ } else {
5027
+ const data = await response.text();
5028
+ throw new SonarRequestException({ innerException: new Error(data) });
4977
5029
  }
4978
- const meta = uri.substring(5, firstComma).split(";");
4979
- let charset = "";
4980
- let base64 = false;
4981
- const type = meta[0] || "text/plain";
4982
- let typeFull = type;
4983
- for (let i = 1;i < meta.length; i++) {
4984
- if (meta[i] === "base64") {
4985
- base64 = true;
4986
- } else if (meta[i]) {
4987
- typeFull += `;${meta[i]}`;
4988
- if (meta[i].indexOf("charset=") === 0) {
4989
- charset = meta[i].substring(8);
4990
- }
5030
+ }
5031
+
5032
+ // src/functions/audio/get-audio-mode.ts
5033
+ async function getAudioMode(sonarEndpoint) {
5034
+ return await requestAudioMode(sonarEndpoint);
5035
+ }
5036
+ // src/sonar/requests/mode/change-audio-mode.ts
5037
+ async function changeAudioMode(sonarEndpoint, audioMode) {
5038
+ let response;
5039
+ const url = new URL(`${sonarEndpoint}/mode/${audioMode}`);
5040
+ try {
5041
+ response = await fetch(url, {
5042
+ method: "PUT"
5043
+ });
5044
+ } catch (error) {
5045
+ throw new SonarRequestException({ innerException: error });
5046
+ }
5047
+ if (response.ok) {
5048
+ const data = await response.json();
5049
+ if (data !== audioMode) {
5050
+ throw new SonarRequestException({ message: "Returned audio mode does not match requested mode" });
4991
5051
  }
5052
+ return data;
5053
+ } else {
5054
+ const data = await response.text();
5055
+ throw new SonarRequestException({ innerException: new Error(data) });
4992
5056
  }
4993
- if (!meta[0] && !charset.length) {
4994
- typeFull += ";charset=US-ASCII";
4995
- charset = "US-ASCII";
5057
+ }
5058
+
5059
+ // src/functions/audio/set-audio-mode.ts
5060
+ async function setAudioMode(sonarEndpoint, audioMode) {
5061
+ return await changeAudioMode(sonarEndpoint, audioMode);
5062
+ }
5063
+ // src/functions/converters/convert-channel-to-api.ts
5064
+ function convertChannelToApi(channel) {
5065
+ switch (channel) {
5066
+ case "master" /* Master */:
5067
+ return "master" /* Master */;
5068
+ case "game" /* Game */:
5069
+ return "chatRender" /* ChatRender */;
5070
+ case "media" /* Media */:
5071
+ return "media" /* Media */;
5072
+ case "aux" /* Aux */:
5073
+ return "aux" /* Aux */;
5074
+ case "mic" /* Mic */:
5075
+ return "chatCapture" /* ChatCapture */;
5076
+ default:
5077
+ throw new Error(`Unsupported AudioChannel: ${channel}`);
4996
5078
  }
4997
- const encoding = base64 ? "base64" : "ascii";
4998
- const data = unescape(uri.substring(firstComma + 1));
4999
- const buffer = Buffer.from(data, encoding);
5000
- buffer.type = type;
5001
- buffer.typeFull = typeFull;
5002
- buffer.charset = charset;
5003
- return buffer;
5004
5079
  }
5005
- var dist_default = dataUriToBuffer;
5006
5080
 
5007
- // node_modules/node-fetch/src/body.js
5008
- init_fetch_blob();
5009
- init_esm_min();
5010
- import Stream, { PassThrough } from "node:stream";
5011
- import { types, deprecate, promisify } from "node:util";
5012
- import { Buffer as Buffer2 } from "node:buffer";
5081
+ // src/sonar/requests/volume-settings/change-volume-mute-classic.ts
5082
+ async function changeVolumeMuteClassic(sonarEndpoint, isMuted, deviceRole) {
5083
+ let response;
5084
+ try {
5085
+ const url = new URL(`${sonarEndpoint}/volumeSettings/classic/${deviceRole}/mute/${isMuted}`);
5086
+ response = await fetch(url, { method: "PUT" });
5087
+ } catch (error) {
5088
+ throw new SonarRequestException({ innerException: error });
5089
+ }
5090
+ if (response.ok) {
5091
+ const data = await response.json();
5092
+ if (data?.masters?.classic == null) {
5093
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
5094
+ }
5095
+ return data;
5096
+ } else {
5097
+ const data = await response.json();
5098
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
5099
+ }
5100
+ }
5013
5101
 
5014
- // node_modules/node-fetch/src/errors/base.js
5015
- class FetchBaseError extends Error {
5016
- constructor(message, type) {
5017
- super(message);
5018
- Error.captureStackTrace(this, this.constructor);
5019
- this.type = type;
5102
+ // src/functions/audio/set-channel-mute-classic.ts
5103
+ async function setChannelMuteClassic(sonarEndpoint, isMuted, channel) {
5104
+ const sonarChannel = convertChannelToApi(channel);
5105
+ const data = await changeVolumeMuteClassic(sonarEndpoint, isMuted, sonarChannel);
5106
+ const device = sonarChannel === "master" /* Master */ ? data.masters.classic : data.devices[sonarChannel]?.classic;
5107
+ if (!device) {
5108
+ throw new SonarRequestException({ message: `Missing device data in response.` });
5020
5109
  }
5021
- get name() {
5022
- return this.constructor.name;
5110
+ const result = {
5111
+ volume: convertVolumeToUser(device.volume),
5112
+ isMuted: device.muted
5113
+ };
5114
+ return result;
5115
+ }
5116
+ // src/sonar/requests/volume-settings/change-volume-mute-streamer.ts
5117
+ async function changeVolumeMuteStreamer(sonarEndpoint, isMuted, deviceRole, path) {
5118
+ let response;
5119
+ try {
5120
+ const url = new URL(`${sonarEndpoint}/volumeSettings/streamer/${path}/${deviceRole}/isMuted/${isMuted}`);
5121
+ response = await fetch(url, { method: "PUT" });
5122
+ } catch (error) {
5123
+ throw new SonarRequestException({ innerException: error });
5023
5124
  }
5024
- get [Symbol.toStringTag]() {
5025
- return this.constructor.name;
5125
+ if (response.ok) {
5126
+ const data = await response.json();
5127
+ if (data?.masters?.stream == null) {
5128
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
5129
+ }
5130
+ return data;
5131
+ } else {
5132
+ const data = await response.json();
5133
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
5026
5134
  }
5027
5135
  }
5028
5136
 
5029
- // node_modules/node-fetch/src/errors/fetch-error.js
5030
- class FetchError extends FetchBaseError {
5031
- constructor(message, type, systemError) {
5032
- super(message, type);
5033
- if (systemError) {
5034
- this.code = this.errno = systemError.code;
5035
- this.erroredSysCall = systemError.syscall;
5036
- }
5137
+ // src/functions/audio/set-channel-mute-streamer.ts
5138
+ async function setChannelMuteStreamer(sonarEndpoint, isMuted, channel, path) {
5139
+ const sonarChannel = convertChannelToApi(channel);
5140
+ const streamPath = path === "streaming" /* Streaming */ ? "streaming" /* Streaming */ : "monitoring" /* Monitoring */;
5141
+ const data = await changeVolumeMuteStreamer(sonarEndpoint, isMuted, sonarChannel, streamPath);
5142
+ const device = sonarChannel === "master" /* Master */ ? data.masters.stream : data.devices[sonarChannel]?.stream;
5143
+ if (!device) {
5144
+ throw new SonarRequestException({ message: `Missing device data in response.` });
5037
5145
  }
5146
+ const devicePath = path === "streaming" /* Streaming */ ? device.streaming : device.monitoring;
5147
+ const result = {
5148
+ volume: convertVolumeToUser(devicePath.volume),
5149
+ isMuted: devicePath.muted
5150
+ };
5151
+ return result;
5152
+ }
5153
+ // src/functions/converters/convert-volume-to-api.ts
5154
+ function convertVolumeToApi(value) {
5155
+ let result = value / 100;
5156
+ result = Math.min(Math.max(result, 0), 1);
5157
+ return result;
5038
5158
  }
5039
5159
 
5040
- // node_modules/node-fetch/src/utils/is.js
5041
- var NAME = Symbol.toStringTag;
5042
- var isURLSearchParameters = (object) => {
5043
- return typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && typeof object.sort === "function" && object[NAME] === "URLSearchParams";
5044
- };
5045
- var isBlob = (object) => {
5046
- return object && typeof object === "object" && typeof object.arrayBuffer === "function" && typeof object.type === "string" && typeof object.stream === "function" && typeof object.constructor === "function" && /^(Blob|File)$/.test(object[NAME]);
5047
- };
5048
- var isAbortSignal = (object) => {
5049
- return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
5050
- };
5051
- var isDomainOrSubdomain = (destination, original) => {
5052
- const orig = new URL(original).hostname;
5053
- const dest = new URL(destination).hostname;
5054
- return orig === dest || orig.endsWith(`.${dest}`);
5055
- };
5056
- var isSameProtocol = (destination, original) => {
5057
- const orig = new URL(original).protocol;
5058
- const dest = new URL(destination).protocol;
5059
- return orig === dest;
5060
- };
5061
-
5062
- // node_modules/node-fetch/src/body.js
5063
- var pipeline = promisify(Stream.pipeline);
5064
- var INTERNALS = Symbol("Body internals");
5065
-
5066
- class Body {
5067
- constructor(body, {
5068
- size = 0
5069
- } = {}) {
5070
- let boundary = null;
5071
- if (body === null) {
5072
- body = null;
5073
- } else if (isURLSearchParameters(body)) {
5074
- body = Buffer2.from(body.toString());
5075
- } else if (isBlob(body)) {} else if (Buffer2.isBuffer(body)) {} else if (types.isAnyArrayBuffer(body)) {
5076
- body = Buffer2.from(body);
5077
- } else if (ArrayBuffer.isView(body)) {
5078
- body = Buffer2.from(body.buffer, body.byteOffset, body.byteLength);
5079
- } else if (body instanceof Stream) {} else if (body instanceof FormData) {
5080
- body = formDataToBlob(body);
5081
- boundary = body.type.split("=")[1];
5082
- } else {
5083
- body = Buffer2.from(String(body));
5084
- }
5085
- let stream = body;
5086
- if (Buffer2.isBuffer(body)) {
5087
- stream = Stream.Readable.from(body);
5088
- } else if (isBlob(body)) {
5089
- stream = Stream.Readable.from(body.stream());
5090
- }
5091
- this[INTERNALS] = {
5092
- body,
5093
- stream,
5094
- boundary,
5095
- disturbed: false,
5096
- error: null
5097
- };
5098
- this.size = size;
5099
- if (body instanceof Stream) {
5100
- body.on("error", (error_) => {
5101
- const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
5102
- this[INTERNALS].error = error;
5103
- });
5104
- }
5105
- }
5106
- get body() {
5107
- return this[INTERNALS].stream;
5108
- }
5109
- get bodyUsed() {
5110
- return this[INTERNALS].disturbed;
5111
- }
5112
- async arrayBuffer() {
5113
- const { buffer, byteOffset, byteLength } = await consumeBody(this);
5114
- return buffer.slice(byteOffset, byteOffset + byteLength);
5160
+ // src/sonar/requests/volume-settings/change-volume-level-classic.ts
5161
+ async function changeVolumeLevelClassic(sonarEndpoint, volume, deviceRole) {
5162
+ let response;
5163
+ try {
5164
+ const url = new URL(`${sonarEndpoint}/volumeSettings/classic/${deviceRole}/volume/${volume}`);
5165
+ response = await fetch(url, { method: "PUT" });
5166
+ } catch (error) {
5167
+ throw new SonarRequestException({ innerException: error });
5115
5168
  }
5116
- async formData() {
5117
- const ct = this.headers.get("content-type");
5118
- if (ct.startsWith("application/x-www-form-urlencoded")) {
5119
- const formData = new FormData;
5120
- const parameters = new URLSearchParams(await this.text());
5121
- for (const [name, value] of parameters) {
5122
- formData.append(name, value);
5123
- }
5124
- return formData;
5169
+ if (response.ok) {
5170
+ const data = await response.json();
5171
+ if (data?.masters?.classic == null) {
5172
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
5125
5173
  }
5126
- const { toFormData: toFormData2 } = await Promise.resolve().then(() => (init_multipart_parser(), exports_multipart_parser));
5127
- return toFormData2(this.body, ct);
5128
- }
5129
- async blob() {
5130
- const ct = this.headers && this.headers.get("content-type") || this[INTERNALS].body && this[INTERNALS].body.type || "";
5131
- const buf = await this.arrayBuffer();
5132
- return new fetch_blob_default([buf], {
5133
- type: ct
5134
- });
5174
+ return data;
5175
+ } else {
5176
+ const data = await response.json();
5177
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
5135
5178
  }
5136
- async json() {
5137
- const text = await this.text();
5138
- return JSON.parse(text);
5179
+ }
5180
+
5181
+ // src/functions/audio/set-channel-volume-classic.ts
5182
+ async function setChannelVolumeClassic(sonarEndpoint, volumePercent, channel) {
5183
+ const sonarChannel = convertChannelToApi(channel);
5184
+ const formattedVolume = convertVolumeToApi(volumePercent);
5185
+ const data = await changeVolumeLevelClassic(sonarEndpoint, formattedVolume, sonarChannel);
5186
+ const device = sonarChannel === "master" /* Master */ ? data.masters.classic : data.devices[sonarChannel]?.classic;
5187
+ if (!device) {
5188
+ throw new SonarRequestException({ message: `Missing device data in response.` });
5139
5189
  }
5140
- async text() {
5141
- const buffer = await consumeBody(this);
5142
- return new TextDecoder().decode(buffer);
5190
+ const result = {
5191
+ volume: convertVolumeToUser(device.volume),
5192
+ isMuted: device.muted
5193
+ };
5194
+ return result;
5195
+ }
5196
+ // src/sonar/requests/volume-settings/change-volume-level-streamer.ts
5197
+ async function changeVolumeLevelStreamer(sonarEndpoint, volume, channel, path) {
5198
+ let response;
5199
+ try {
5200
+ const url = new URL(`${sonarEndpoint}/volumeSettings/streamer/${path}/${channel}/volume/${volume}`);
5201
+ response = await fetch(url, { method: "PUT" });
5202
+ } catch (error) {
5203
+ throw new SonarRequestException({ innerException: error });
5143
5204
  }
5144
- buffer() {
5145
- return consumeBody(this);
5205
+ if (response.ok) {
5206
+ const data = await response.json();
5207
+ if (data?.masters?.stream == null) {
5208
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
5209
+ }
5210
+ return data;
5211
+ } else {
5212
+ const data = await response.json();
5213
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
5146
5214
  }
5147
5215
  }
5148
- Body.prototype.buffer = deprecate(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
5149
- Object.defineProperties(Body.prototype, {
5150
- body: { enumerable: true },
5151
- bodyUsed: { enumerable: true },
5152
- arrayBuffer: { enumerable: true },
5153
- blob: { enumerable: true },
5154
- json: { enumerable: true },
5155
- text: { enumerable: true },
5156
- data: { get: deprecate(() => {}, "data doesn't exist, use json(), text(), arrayBuffer(), or body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (response)") }
5157
- });
5158
- async function consumeBody(data) {
5159
- if (data[INTERNALS].disturbed) {
5160
- throw new TypeError(`body used already for: ${data.url}`);
5161
- }
5162
- data[INTERNALS].disturbed = true;
5163
- if (data[INTERNALS].error) {
5164
- throw data[INTERNALS].error;
5216
+
5217
+ // src/functions/audio/set-channel-volume-streamer.ts
5218
+ async function setChannelVolumeStreamer(sonarEndpoint, volumePercent, channel, path) {
5219
+ const sonarChannel = convertChannelToApi(channel);
5220
+ const formattedVolume = convertVolumeToApi(volumePercent);
5221
+ const streamPath = path === "streaming" /* Streaming */ ? "streaming" /* Streaming */ : "monitoring" /* Monitoring */;
5222
+ const data = await changeVolumeLevelStreamer(sonarEndpoint, formattedVolume, sonarChannel, streamPath);
5223
+ const device = sonarChannel === "master" /* Master */ ? data.masters.stream : data.devices[sonarChannel]?.stream;
5224
+ if (!device) {
5225
+ throw new SonarRequestException({ message: `Missing device data in response.` });
5165
5226
  }
5166
- const { body } = data;
5167
- if (body === null) {
5168
- return Buffer2.alloc(0);
5227
+ const devicePath = path === "streaming" /* Streaming */ ? device.streaming : device.monitoring;
5228
+ const result = {
5229
+ volume: convertVolumeToUser(devicePath.volume),
5230
+ isMuted: devicePath.muted
5231
+ };
5232
+ return result;
5233
+ }
5234
+ // src/functions/converters/convert-chat-mix-balance-to-user.ts
5235
+ function convertChatMixBalanceToUser(balance) {
5236
+ let result = (balance + 1) / 2 * 100;
5237
+ result = Math.floor(result);
5238
+ result = Math.min(Math.max(result, 0), 100);
5239
+ return result;
5240
+ }
5241
+
5242
+ // src/sonar/requests/chatmix/request-chat-mix-state.ts
5243
+ async function requestChatMixState(sonarEndpoint) {
5244
+ const url = new URL(`${sonarEndpoint}/chatMix`);
5245
+ let response;
5246
+ try {
5247
+ response = await fetch(url);
5248
+ } catch (error) {
5249
+ throw new SonarRequestException({ innerException: error });
5169
5250
  }
5170
- if (!(body instanceof Stream)) {
5171
- return Buffer2.alloc(0);
5251
+ if (response.ok) {
5252
+ const data = await response.json();
5253
+ if (data?.balance == null || data?.state == null) {
5254
+ throw new SonarRequestException({ message: "Missing required data in response" });
5255
+ }
5256
+ return data;
5257
+ } else {
5258
+ const data = await response.text();
5259
+ throw new SonarRequestException({ innerException: new Error(data) });
5172
5260
  }
5173
- const accum = [];
5174
- let accumBytes = 0;
5261
+ }
5262
+
5263
+ // src/functions/chatmix/get-chat-mix-state.ts
5264
+ async function getChatMixState(sonarEndpoint) {
5265
+ const data = await requestChatMixState(sonarEndpoint);
5266
+ const chatMixData = {
5267
+ chatBalance: convertChatMixBalanceToUser(data.balance),
5268
+ state: data.state,
5269
+ isEnabled: data.state === "enabled" /* Enabled */
5270
+ };
5271
+ return chatMixData;
5272
+ }
5273
+ // src/functions/converters/convert-chat-mix-balance-to-api.ts
5274
+ function convertChatMixBalanceToApi(balance) {
5275
+ let result = balance / 100 * 2 - 1;
5276
+ result = Math.min(Math.max(result, -1), 1);
5277
+ return result;
5278
+ }
5279
+
5280
+ // src/sonar/requests/chatmix/change-chat-mix-balance.ts
5281
+ async function changeChatMixBalance(sonarEndpoint, chatBalance) {
5282
+ const url = new URL(`${sonarEndpoint}/chatMix?balance=${chatBalance}`);
5283
+ let response;
5175
5284
  try {
5176
- for await (const chunk of body) {
5177
- if (data.size > 0 && accumBytes + chunk.length > data.size) {
5178
- const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
5179
- body.destroy(error);
5180
- throw error;
5181
- }
5182
- accumBytes += chunk.length;
5183
- accum.push(chunk);
5184
- }
5285
+ response = await fetch(url, {
5286
+ method: "PUT"
5287
+ });
5185
5288
  } catch (error) {
5186
- const error_ = error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
5187
- throw error_;
5289
+ throw new SonarRequestException({ innerException: error });
5188
5290
  }
5189
- if (body.readableEnded === true || body._readableState.ended === true) {
5190
- try {
5191
- if (accum.every((c) => typeof c === "string")) {
5192
- return Buffer2.from(accum.join(""));
5193
- }
5194
- return Buffer2.concat(accum, accumBytes);
5195
- } catch (error) {
5196
- throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
5291
+ if (response.ok) {
5292
+ const data = await response.json();
5293
+ if (data?.balance == null || data?.state == null) {
5294
+ throw new SonarRequestException({ message: "Missing required data in response" });
5197
5295
  }
5296
+ return data;
5198
5297
  } else {
5199
- throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
5298
+ const data = await response.json();
5299
+ throw new SonarRequestException({ message: data.Message });
5200
5300
  }
5201
5301
  }
5202
- var clone = (instance, highWaterMark) => {
5203
- let p1;
5204
- let p2;
5205
- let { body } = instance[INTERNALS];
5206
- if (instance.bodyUsed) {
5207
- throw new Error("cannot clone body after it is used");
5302
+
5303
+ // src/functions/chatmix/set-chat-mix-balance.ts
5304
+ async function setChatMixBalance(sonarEndpoint, chatBalance) {
5305
+ const balance = convertChatMixBalanceToApi(chatBalance);
5306
+ const data = await changeChatMixBalance(sonarEndpoint, balance);
5307
+ const chatMixData = {
5308
+ chatBalance: convertChatMixBalanceToUser(data.balance),
5309
+ state: data.state,
5310
+ isEnabled: data.state === "enabled" /* Enabled */
5311
+ };
5312
+ return chatMixData;
5313
+ }
5314
+ // src/sonar/requests/audio-devices/request-audio-devices.ts
5315
+ async function requestAudioDevices(sonarEndpoint, params) {
5316
+ const { deviceDataFlow, onlySteelSeriesVAD = false, removeSteelSeriesVAD = false } = params;
5317
+ const url = new URL(`${sonarEndpoint}/audioDevices`);
5318
+ url.searchParams.append("onlySteelSeriesVAD", String(onlySteelSeriesVAD));
5319
+ url.searchParams.append("removeSteelSeriesVAD", String(removeSteelSeriesVAD));
5320
+ if (deviceDataFlow !== undefined) {
5321
+ url.searchParams.append("deviceDataFlow", deviceDataFlow.toString());
5208
5322
  }
5209
- if (body instanceof Stream && typeof body.getBoundary !== "function") {
5210
- p1 = new PassThrough({ highWaterMark });
5211
- p2 = new PassThrough({ highWaterMark });
5212
- body.pipe(p1);
5213
- body.pipe(p2);
5214
- instance[INTERNALS].stream = p1;
5215
- body = p2;
5323
+ let response;
5324
+ try {
5325
+ response = await fetch(url);
5326
+ } catch (error) {
5327
+ throw new SonarRequestException({
5328
+ innerException: error
5329
+ });
5216
5330
  }
5217
- return body;
5218
- };
5219
- var getNonSpecFormDataBoundary = deprecate((body) => body.getBoundary(), "form-data doesn't follow the spec and requires special treatment. Use alternative package", "https://github.com/node-fetch/node-fetch/issues/1167");
5220
- var extractContentType = (body, request) => {
5221
- if (body === null) {
5222
- return null;
5331
+ if (!response.ok) {
5332
+ const error = await response.text();
5333
+ throw new SonarRequestException({ message: `Failed to get audio devices: ${error}` });
5223
5334
  }
5224
- if (typeof body === "string") {
5225
- return "text/plain;charset=UTF-8";
5335
+ const data = await response.json();
5336
+ if (!Array.isArray(data)) {
5337
+ throw new SonarRequestException({ message: "Invalid audio devices response format." });
5226
5338
  }
5227
- if (isURLSearchParameters(body)) {
5228
- return "application/x-www-form-urlencoded;charset=UTF-8";
5339
+ return data;
5340
+ }
5341
+
5342
+ // src/functions/devices/get-audio-devices.ts
5343
+ async function getAudioDevices(sonarEndpoint, deviceType) {
5344
+ let deviceDataFlow;
5345
+ switch (deviceType) {
5346
+ case "input" /* Input */:
5347
+ deviceDataFlow = "capture" /* Capture */;
5348
+ break;
5349
+ case "output" /* Output */:
5350
+ deviceDataFlow = "render" /* Render */;
5351
+ break;
5352
+ case undefined:
5353
+ deviceDataFlow = "all" /* All */;
5354
+ break;
5229
5355
  }
5230
- if (isBlob(body)) {
5231
- return body.type || null;
5356
+ const data = await requestAudioDevices(sonarEndpoint, { deviceDataFlow, removeSteelSeriesVAD: true });
5357
+ const audioDevices = data.map((device) => ({
5358
+ id: device.id,
5359
+ name: device.friendlyName,
5360
+ type: getDeviceTypeFromDataFlow(device.dataFlow)
5361
+ }));
5362
+ return audioDevices;
5363
+ }
5364
+ function getDeviceTypeFromDataFlow(dataFlow) {
5365
+ switch (dataFlow) {
5366
+ case "capture" /* Capture */:
5367
+ return "input" /* Input */;
5368
+ case "render" /* Render */:
5369
+ return "output" /* Output */;
5370
+ default:
5371
+ throw new SonarRequestException({ message: `Unknown device data flow: ${dataFlow}` });
5232
5372
  }
5233
- if (Buffer2.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
5234
- return null;
5373
+ }
5374
+ // src/sonar/requests/audio-devices/change-audio-device.ts
5375
+ async function changeAudioDevice(sonarEndpoint, deviceChannel, deviceId) {
5376
+ let response;
5377
+ const url = new URL(`${sonarEndpoint}/classicRedirections/${deviceChannel}/deviceId/${deviceId}`);
5378
+ try {
5379
+ response = await fetch(url, { method: "PUT" });
5380
+ } catch (error) {
5381
+ throw new SonarRequestException({
5382
+ innerException: error
5383
+ });
5235
5384
  }
5236
- if (body instanceof FormData) {
5237
- return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
5385
+ if (!response.ok) {
5386
+ const error = await response.text();
5387
+ throw new SonarRequestException({ message: `Failed to get audio devices: ${error}` });
5238
5388
  }
5239
- if (body && typeof body.getBoundary === "function") {
5240
- return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
5389
+ const unknownData = await response.json();
5390
+ const data = Array.isArray(unknownData) ? unknownData : [unknownData];
5391
+ const devices = data.filter((x) => x?.deviceId === deviceId);
5392
+ if (devices.length === 0) {
5393
+ throw new SonarRequestException({ message: "The changed audio devices list is empty." });
5241
5394
  }
5242
- if (body instanceof Stream) {
5243
- return null;
5395
+ return devices;
5396
+ }
5397
+
5398
+ // src/functions/devices/set-audio-device.ts
5399
+ async function setAudioDevice(sonarEndpoint, deviceChannel, deviceId) {
5400
+ const data = await changeAudioDevice(sonarEndpoint, deviceChannel, deviceId);
5401
+ const result = data.map((x) => ({
5402
+ deviceId: x.deviceId,
5403
+ deviceChannel: x.id,
5404
+ isRunning: x.isRunning
5405
+ }));
5406
+ return result;
5407
+ }
5408
+ // src/functions/endpoint/get-app-endpoint.ts
5409
+ import { promises as fsAsync } from "node:fs";
5410
+ import { platform as getPlatform } from "node:os";
5411
+ import { join as joinPath } from "node:path";
5412
+ var WINDOWS_PATHS = ["SteelSeries", "SteelSeries Engine 3", "coreProps.json"];
5413
+ async function getAppEndpoint() {
5414
+ const appDataPath = getPath();
5415
+ const fileContents = await getContents(appDataPath);
5416
+ const data = parseContents(fileContents);
5417
+ if (data.ggEncryptedAddress) {
5418
+ return `https://${data.ggEncryptedAddress}`;
5244
5419
  }
5245
- return "text/plain;charset=UTF-8";
5246
- };
5247
- var getTotalBytes = (request) => {
5248
- const { body } = request[INTERNALS];
5249
- if (body === null) {
5250
- return 0;
5420
+ throw new SonarInitializationException({
5421
+ reason: "Bad Config" /* BadConfig */
5422
+ });
5423
+ }
5424
+ function getPath() {
5425
+ const os = getPlatform();
5426
+ switch (os) {
5427
+ case "win32": {
5428
+ const programData = process.env.ProgramData ?? "C:\\ProgramData";
5429
+ return joinPath(programData, ...WINDOWS_PATHS);
5430
+ }
5431
+ default:
5432
+ throw new SonarInitializationException({
5433
+ reason: "OS Unsupported" /* OSUnsupported */
5434
+ });
5251
5435
  }
5252
- if (isBlob(body)) {
5253
- return body.size;
5436
+ }
5437
+ async function getContents(path) {
5438
+ try {
5439
+ return await fsAsync.readFile(path, "utf8");
5440
+ } catch (error) {
5441
+ throw new SonarInitializationException({
5442
+ reason: "Bad Config" /* BadConfig */,
5443
+ innerException: error
5444
+ });
5254
5445
  }
5255
- if (Buffer2.isBuffer(body)) {
5256
- return body.length;
5446
+ }
5447
+ function parseContents(contents) {
5448
+ try {
5449
+ return JSON.parse(contents);
5450
+ } catch (error) {
5451
+ throw new SonarInitializationException({
5452
+ reason: "Bad Config" /* BadConfig */,
5453
+ innerException: error
5454
+ });
5257
5455
  }
5258
- if (body && typeof body.getLengthSync === "function") {
5259
- return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
5456
+ }
5457
+ // src/functions/endpoint/get-sonar-endpoint.ts
5458
+ import https2 from "node:https";
5459
+
5460
+ // node_modules/node-fetch/src/index.js
5461
+ import http2 from "node:http";
5462
+ import https from "node:https";
5463
+ import zlib from "node:zlib";
5464
+ import Stream2, { PassThrough as PassThrough2, pipeline as pump } from "node:stream";
5465
+ import { Buffer as Buffer3 } from "node:buffer";
5466
+
5467
+ // node_modules/data-uri-to-buffer/dist/index.js
5468
+ function dataUriToBuffer(uri) {
5469
+ if (!/^data:/i.test(uri)) {
5470
+ throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');
5260
5471
  }
5261
- return null;
5262
- };
5263
- var writeToStream = async (dest, { body }) => {
5264
- if (body === null) {
5265
- dest.end();
5266
- } else {
5267
- await pipeline(body, dest);
5472
+ uri = uri.replace(/\r?\n/g, "");
5473
+ const firstComma = uri.indexOf(",");
5474
+ if (firstComma === -1 || firstComma <= 4) {
5475
+ throw new TypeError("malformed data: URI");
5268
5476
  }
5269
- };
5270
-
5271
- // node_modules/node-fetch/src/headers.js
5272
- import { types as types2 } from "node:util";
5273
- import http from "node:http";
5274
- var validateHeaderName = typeof http.validateHeaderName === "function" ? http.validateHeaderName : (name) => {
5275
- if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
5276
- const error = new TypeError(`Header name must be a valid HTTP token [${name}]`);
5277
- Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
5278
- throw error;
5477
+ const meta = uri.substring(5, firstComma).split(";");
5478
+ let charset = "";
5479
+ let base64 = false;
5480
+ const type = meta[0] || "text/plain";
5481
+ let typeFull = type;
5482
+ for (let i = 1;i < meta.length; i++) {
5483
+ if (meta[i] === "base64") {
5484
+ base64 = true;
5485
+ } else if (meta[i]) {
5486
+ typeFull += `;${meta[i]}`;
5487
+ if (meta[i].indexOf("charset=") === 0) {
5488
+ charset = meta[i].substring(8);
5489
+ }
5490
+ }
5279
5491
  }
5280
- };
5281
- var validateHeaderValue = typeof http.validateHeaderValue === "function" ? http.validateHeaderValue : (name, value) => {
5282
- if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
5283
- const error = new TypeError(`Invalid character in header content ["${name}"]`);
5284
- Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
5285
- throw error;
5492
+ if (!meta[0] && !charset.length) {
5493
+ typeFull += ";charset=US-ASCII";
5494
+ charset = "US-ASCII";
5286
5495
  }
5287
- };
5496
+ const encoding = base64 ? "base64" : "ascii";
5497
+ const data = unescape(uri.substring(firstComma + 1));
5498
+ const buffer = Buffer.from(data, encoding);
5499
+ buffer.type = type;
5500
+ buffer.typeFull = typeFull;
5501
+ buffer.charset = charset;
5502
+ return buffer;
5503
+ }
5504
+ var dist_default = dataUriToBuffer;
5288
5505
 
5289
- class Headers extends URLSearchParams {
5290
- constructor(init) {
5291
- let result = [];
5292
- if (init instanceof Headers) {
5293
- const raw = init.raw();
5294
- for (const [name, values] of Object.entries(raw)) {
5295
- result.push(...values.map((value) => [name, value]));
5296
- }
5297
- } else if (init == null) {} else if (typeof init === "object" && !types2.isBoxedPrimitive(init)) {
5298
- const method = init[Symbol.iterator];
5299
- if (method == null) {
5300
- result.push(...Object.entries(init));
5301
- } else {
5302
- if (typeof method !== "function") {
5303
- throw new TypeError("Header pairs must be iterable");
5304
- }
5305
- result = [...init].map((pair) => {
5306
- if (typeof pair !== "object" || types2.isBoxedPrimitive(pair)) {
5307
- throw new TypeError("Each header pair must be an iterable object");
5308
- }
5309
- return [...pair];
5310
- }).map((pair) => {
5311
- if (pair.length !== 2) {
5312
- throw new TypeError("Each header pair must be a name/value tuple");
5313
- }
5314
- return [...pair];
5315
- });
5316
- }
5317
- } else {
5318
- throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
5319
- }
5320
- result = result.length > 0 ? result.map(([name, value]) => {
5321
- validateHeaderName(name);
5322
- validateHeaderValue(name, String(value));
5323
- return [String(name).toLowerCase(), String(value)];
5324
- }) : undefined;
5325
- super(result);
5326
- return new Proxy(this, {
5327
- get(target, p, receiver) {
5328
- switch (p) {
5329
- case "append":
5330
- case "set":
5331
- return (name, value) => {
5332
- validateHeaderName(name);
5333
- validateHeaderValue(name, String(value));
5334
- return URLSearchParams.prototype[p].call(target, String(name).toLowerCase(), String(value));
5335
- };
5336
- case "delete":
5337
- case "has":
5338
- case "getAll":
5339
- return (name) => {
5340
- validateHeaderName(name);
5341
- return URLSearchParams.prototype[p].call(target, String(name).toLowerCase());
5342
- };
5343
- case "keys":
5344
- return () => {
5345
- target.sort();
5346
- return new Set(URLSearchParams.prototype.keys.call(target)).keys();
5347
- };
5348
- default:
5349
- return Reflect.get(target, p, receiver);
5350
- }
5351
- }
5352
- });
5506
+ // node_modules/node-fetch/src/body.js
5507
+ init_fetch_blob();
5508
+ init_esm_min();
5509
+ import Stream, { PassThrough } from "node:stream";
5510
+ import { types, deprecate, promisify } from "node:util";
5511
+ import { Buffer as Buffer2 } from "node:buffer";
5512
+
5513
+ // node_modules/node-fetch/src/errors/base.js
5514
+ class FetchBaseError extends Error {
5515
+ constructor(message, type) {
5516
+ super(message);
5517
+ Error.captureStackTrace(this, this.constructor);
5518
+ this.type = type;
5353
5519
  }
5354
- get [Symbol.toStringTag]() {
5520
+ get name() {
5355
5521
  return this.constructor.name;
5356
5522
  }
5357
- toString() {
5358
- return Object.prototype.toString.call(this);
5359
- }
5360
- get(name) {
5361
- const values = this.getAll(name);
5362
- if (values.length === 0) {
5363
- return null;
5364
- }
5365
- let value = values.join(", ");
5366
- if (/^content-encoding$/i.test(name)) {
5367
- value = value.toLowerCase();
5368
- }
5369
- return value;
5370
- }
5371
- forEach(callback, thisArg = undefined) {
5372
- for (const name of this.keys()) {
5373
- Reflect.apply(callback, thisArg, [this.get(name), name, this]);
5374
- }
5375
- }
5376
- *values() {
5377
- for (const name of this.keys()) {
5378
- yield this.get(name);
5379
- }
5380
- }
5381
- *entries() {
5382
- for (const name of this.keys()) {
5383
- yield [name, this.get(name)];
5384
- }
5385
- }
5386
- [Symbol.iterator]() {
5387
- return this.entries();
5388
- }
5389
- raw() {
5390
- return [...this.keys()].reduce((result, key) => {
5391
- result[key] = this.getAll(key);
5392
- return result;
5393
- }, {});
5394
- }
5395
- [Symbol.for("nodejs.util.inspect.custom")]() {
5396
- return [...this.keys()].reduce((result, key) => {
5397
- const values = this.getAll(key);
5398
- if (key === "host") {
5399
- result[key] = values[0];
5400
- } else {
5401
- result[key] = values.length > 1 ? values : values[0];
5402
- }
5403
- return result;
5404
- }, {});
5523
+ get [Symbol.toStringTag]() {
5524
+ return this.constructor.name;
5405
5525
  }
5406
5526
  }
5407
- Object.defineProperties(Headers.prototype, ["get", "entries", "forEach", "values"].reduce((result, property) => {
5408
- result[property] = { enumerable: true };
5409
- return result;
5410
- }, {}));
5411
- function fromRawHeaders(headers = []) {
5412
- return new Headers(headers.reduce((result, value, index, array) => {
5413
- if (index % 2 === 0) {
5414
- result.push(array.slice(index, index + 2));
5415
- }
5416
- return result;
5417
- }, []).filter(([name, value]) => {
5418
- try {
5419
- validateHeaderName(name);
5420
- validateHeaderValue(name, String(value));
5421
- return true;
5422
- } catch {
5423
- return false;
5527
+
5528
+ // node_modules/node-fetch/src/errors/fetch-error.js
5529
+ class FetchError extends FetchBaseError {
5530
+ constructor(message, type, systemError) {
5531
+ super(message, type);
5532
+ if (systemError) {
5533
+ this.code = this.errno = systemError.code;
5534
+ this.erroredSysCall = systemError.syscall;
5424
5535
  }
5425
- }));
5536
+ }
5426
5537
  }
5427
5538
 
5428
- // node_modules/node-fetch/src/utils/is-redirect.js
5429
- var redirectStatus = new Set([301, 302, 303, 307, 308]);
5430
- var isRedirect = (code) => {
5431
- return redirectStatus.has(code);
5539
+ // node_modules/node-fetch/src/utils/is.js
5540
+ var NAME = Symbol.toStringTag;
5541
+ var isURLSearchParameters = (object) => {
5542
+ return typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && typeof object.sort === "function" && object[NAME] === "URLSearchParams";
5543
+ };
5544
+ var isBlob = (object) => {
5545
+ return object && typeof object === "object" && typeof object.arrayBuffer === "function" && typeof object.type === "string" && typeof object.stream === "function" && typeof object.constructor === "function" && /^(Blob|File)$/.test(object[NAME]);
5546
+ };
5547
+ var isAbortSignal = (object) => {
5548
+ return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
5549
+ };
5550
+ var isDomainOrSubdomain = (destination, original) => {
5551
+ const orig = new URL(original).hostname;
5552
+ const dest = new URL(destination).hostname;
5553
+ return orig === dest || orig.endsWith(`.${dest}`);
5554
+ };
5555
+ var isSameProtocol = (destination, original) => {
5556
+ const orig = new URL(original).protocol;
5557
+ const dest = new URL(destination).protocol;
5558
+ return orig === dest;
5432
5559
  };
5433
5560
 
5434
- // node_modules/node-fetch/src/response.js
5435
- var INTERNALS2 = Symbol("Response internals");
5561
+ // node_modules/node-fetch/src/body.js
5562
+ var pipeline = promisify(Stream.pipeline);
5563
+ var INTERNALS = Symbol("Body internals");
5436
5564
 
5437
- class Response extends Body {
5438
- constructor(body = null, options = {}) {
5439
- super(body, options);
5440
- const status = options.status != null ? options.status : 200;
5441
- const headers = new Headers(options.headers);
5442
- if (body !== null && !headers.has("Content-Type")) {
5443
- const contentType = extractContentType(body, this);
5444
- if (contentType) {
5445
- headers.append("Content-Type", contentType);
5446
- }
5565
+ class Body {
5566
+ constructor(body, {
5567
+ size = 0
5568
+ } = {}) {
5569
+ let boundary = null;
5570
+ if (body === null) {
5571
+ body = null;
5572
+ } else if (isURLSearchParameters(body)) {
5573
+ body = Buffer2.from(body.toString());
5574
+ } else if (isBlob(body)) {} else if (Buffer2.isBuffer(body)) {} else if (types.isAnyArrayBuffer(body)) {
5575
+ body = Buffer2.from(body);
5576
+ } else if (ArrayBuffer.isView(body)) {
5577
+ body = Buffer2.from(body.buffer, body.byteOffset, body.byteLength);
5578
+ } else if (body instanceof Stream) {} else if (body instanceof FormData) {
5579
+ body = formDataToBlob(body);
5580
+ boundary = body.type.split("=")[1];
5581
+ } else {
5582
+ body = Buffer2.from(String(body));
5447
5583
  }
5448
- this[INTERNALS2] = {
5449
- type: "default",
5450
- url: options.url,
5451
- status,
5452
- statusText: options.statusText || "",
5453
- headers,
5454
- counter: options.counter,
5455
- highWaterMark: options.highWaterMark
5584
+ let stream = body;
5585
+ if (Buffer2.isBuffer(body)) {
5586
+ stream = Stream.Readable.from(body);
5587
+ } else if (isBlob(body)) {
5588
+ stream = Stream.Readable.from(body.stream());
5589
+ }
5590
+ this[INTERNALS] = {
5591
+ body,
5592
+ stream,
5593
+ boundary,
5594
+ disturbed: false,
5595
+ error: null
5456
5596
  };
5597
+ this.size = size;
5598
+ if (body instanceof Stream) {
5599
+ body.on("error", (error_) => {
5600
+ const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
5601
+ this[INTERNALS].error = error;
5602
+ });
5603
+ }
5457
5604
  }
5458
- get type() {
5459
- return this[INTERNALS2].type;
5460
- }
5461
- get url() {
5462
- return this[INTERNALS2].url || "";
5463
- }
5464
- get status() {
5465
- return this[INTERNALS2].status;
5466
- }
5467
- get ok() {
5468
- return this[INTERNALS2].status >= 200 && this[INTERNALS2].status < 300;
5605
+ get body() {
5606
+ return this[INTERNALS].stream;
5469
5607
  }
5470
- get redirected() {
5471
- return this[INTERNALS2].counter > 0;
5608
+ get bodyUsed() {
5609
+ return this[INTERNALS].disturbed;
5472
5610
  }
5473
- get statusText() {
5474
- return this[INTERNALS2].statusText;
5611
+ async arrayBuffer() {
5612
+ const { buffer, byteOffset, byteLength } = await consumeBody(this);
5613
+ return buffer.slice(byteOffset, byteOffset + byteLength);
5475
5614
  }
5476
- get headers() {
5477
- return this[INTERNALS2].headers;
5478
- }
5479
- get highWaterMark() {
5480
- return this[INTERNALS2].highWaterMark;
5481
- }
5482
- clone() {
5483
- return new Response(clone(this, this.highWaterMark), {
5484
- type: this.type,
5485
- url: this.url,
5486
- status: this.status,
5487
- statusText: this.statusText,
5488
- headers: this.headers,
5489
- ok: this.ok,
5490
- redirected: this.redirected,
5491
- size: this.size,
5492
- highWaterMark: this.highWaterMark
5493
- });
5494
- }
5495
- static redirect(url, status = 302) {
5496
- if (!isRedirect(status)) {
5497
- throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
5615
+ async formData() {
5616
+ const ct = this.headers.get("content-type");
5617
+ if (ct.startsWith("application/x-www-form-urlencoded")) {
5618
+ const formData = new FormData;
5619
+ const parameters = new URLSearchParams(await this.text());
5620
+ for (const [name, value] of parameters) {
5621
+ formData.append(name, value);
5622
+ }
5623
+ return formData;
5498
5624
  }
5499
- return new Response(null, {
5500
- headers: {
5501
- location: new URL(url).toString()
5502
- },
5503
- status
5625
+ const { toFormData: toFormData2 } = await Promise.resolve().then(() => (init_multipart_parser(), exports_multipart_parser));
5626
+ return toFormData2(this.body, ct);
5627
+ }
5628
+ async blob() {
5629
+ const ct = this.headers && this.headers.get("content-type") || this[INTERNALS].body && this[INTERNALS].body.type || "";
5630
+ const buf = await this.arrayBuffer();
5631
+ return new fetch_blob_default([buf], {
5632
+ type: ct
5504
5633
  });
5505
5634
  }
5506
- static error() {
5507
- const response = new Response(null, { status: 0, statusText: "" });
5508
- response[INTERNALS2].type = "error";
5509
- return response;
5635
+ async json() {
5636
+ const text = await this.text();
5637
+ return JSON.parse(text);
5510
5638
  }
5511
- static json(data = undefined, init = {}) {
5512
- const body = JSON.stringify(data);
5513
- if (body === undefined) {
5514
- throw new TypeError("data is not JSON serializable");
5515
- }
5516
- const headers = new Headers(init && init.headers);
5517
- if (!headers.has("content-type")) {
5518
- headers.set("content-type", "application/json");
5519
- }
5520
- return new Response(body, {
5521
- ...init,
5522
- headers
5523
- });
5639
+ async text() {
5640
+ const buffer = await consumeBody(this);
5641
+ return new TextDecoder().decode(buffer);
5524
5642
  }
5525
- get [Symbol.toStringTag]() {
5526
- return "Response";
5643
+ buffer() {
5644
+ return consumeBody(this);
5527
5645
  }
5528
5646
  }
5529
- Object.defineProperties(Response.prototype, {
5530
- type: { enumerable: true },
5531
- url: { enumerable: true },
5532
- status: { enumerable: true },
5533
- ok: { enumerable: true },
5534
- redirected: { enumerable: true },
5535
- statusText: { enumerable: true },
5536
- headers: { enumerable: true },
5537
- clone: { enumerable: true }
5647
+ Body.prototype.buffer = deprecate(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
5648
+ Object.defineProperties(Body.prototype, {
5649
+ body: { enumerable: true },
5650
+ bodyUsed: { enumerable: true },
5651
+ arrayBuffer: { enumerable: true },
5652
+ blob: { enumerable: true },
5653
+ json: { enumerable: true },
5654
+ text: { enumerable: true },
5655
+ data: { get: deprecate(() => {}, "data doesn't exist, use json(), text(), arrayBuffer(), or body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (response)") }
5538
5656
  });
5539
-
5540
- // node_modules/node-fetch/src/request.js
5541
- import { format as formatUrl } from "node:url";
5542
- import { deprecate as deprecate2 } from "node:util";
5543
-
5544
- // node_modules/node-fetch/src/utils/get-search.js
5545
- var getSearch = (parsedURL) => {
5546
- if (parsedURL.search) {
5547
- return parsedURL.search;
5657
+ async function consumeBody(data) {
5658
+ if (data[INTERNALS].disturbed) {
5659
+ throw new TypeError(`body used already for: ${data.url}`);
5548
5660
  }
5549
- const lastOffset = parsedURL.href.length - 1;
5550
- const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
5551
- return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
5552
- };
5553
-
5554
- // node_modules/node-fetch/src/utils/referrer.js
5555
- import { isIP } from "node:net";
5556
- function stripURLForUseAsAReferrer(url, originOnly = false) {
5557
- if (url == null) {
5558
- return "no-referrer";
5661
+ data[INTERNALS].disturbed = true;
5662
+ if (data[INTERNALS].error) {
5663
+ throw data[INTERNALS].error;
5559
5664
  }
5560
- url = new URL(url);
5561
- if (/^(about|blob|data):$/.test(url.protocol)) {
5562
- return "no-referrer";
5665
+ const { body } = data;
5666
+ if (body === null) {
5667
+ return Buffer2.alloc(0);
5563
5668
  }
5564
- url.username = "";
5565
- url.password = "";
5566
- url.hash = "";
5567
- if (originOnly) {
5568
- url.pathname = "";
5569
- url.search = "";
5669
+ if (!(body instanceof Stream)) {
5670
+ return Buffer2.alloc(0);
5570
5671
  }
5571
- return url;
5572
- }
5573
- var ReferrerPolicy = new Set([
5574
- "",
5575
- "no-referrer",
5576
- "no-referrer-when-downgrade",
5577
- "same-origin",
5578
- "origin",
5579
- "strict-origin",
5580
- "origin-when-cross-origin",
5581
- "strict-origin-when-cross-origin",
5582
- "unsafe-url"
5583
- ]);
5584
- var DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
5585
- function validateReferrerPolicy(referrerPolicy) {
5586
- if (!ReferrerPolicy.has(referrerPolicy)) {
5587
- throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
5672
+ const accum = [];
5673
+ let accumBytes = 0;
5674
+ try {
5675
+ for await (const chunk of body) {
5676
+ if (data.size > 0 && accumBytes + chunk.length > data.size) {
5677
+ const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
5678
+ body.destroy(error);
5679
+ throw error;
5680
+ }
5681
+ accumBytes += chunk.length;
5682
+ accum.push(chunk);
5683
+ }
5684
+ } catch (error) {
5685
+ const error_ = error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
5686
+ throw error_;
5687
+ }
5688
+ if (body.readableEnded === true || body._readableState.ended === true) {
5689
+ try {
5690
+ if (accum.every((c) => typeof c === "string")) {
5691
+ return Buffer2.from(accum.join(""));
5692
+ }
5693
+ return Buffer2.concat(accum, accumBytes);
5694
+ } catch (error) {
5695
+ throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
5696
+ }
5697
+ } else {
5698
+ throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
5588
5699
  }
5589
- return referrerPolicy;
5590
5700
  }
5591
- function isOriginPotentiallyTrustworthy(url) {
5592
- if (/^(http|ws)s:$/.test(url.protocol)) {
5593
- return true;
5701
+ var clone = (instance, highWaterMark) => {
5702
+ let p1;
5703
+ let p2;
5704
+ let { body } = instance[INTERNALS];
5705
+ if (instance.bodyUsed) {
5706
+ throw new Error("cannot clone body after it is used");
5594
5707
  }
5595
- const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
5596
- const hostIPVersion = isIP(hostIp);
5597
- if (hostIPVersion === 4 && /^127\./.test(hostIp)) {
5598
- return true;
5708
+ if (body instanceof Stream && typeof body.getBoundary !== "function") {
5709
+ p1 = new PassThrough({ highWaterMark });
5710
+ p2 = new PassThrough({ highWaterMark });
5711
+ body.pipe(p1);
5712
+ body.pipe(p2);
5713
+ instance[INTERNALS].stream = p1;
5714
+ body = p2;
5599
5715
  }
5600
- if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) {
5601
- return true;
5716
+ return body;
5717
+ };
5718
+ var getNonSpecFormDataBoundary = deprecate((body) => body.getBoundary(), "form-data doesn't follow the spec and requires special treatment. Use alternative package", "https://github.com/node-fetch/node-fetch/issues/1167");
5719
+ var extractContentType = (body, request) => {
5720
+ if (body === null) {
5721
+ return null;
5602
5722
  }
5603
- if (url.host === "localhost" || url.host.endsWith(".localhost")) {
5604
- return false;
5723
+ if (typeof body === "string") {
5724
+ return "text/plain;charset=UTF-8";
5605
5725
  }
5606
- if (url.protocol === "file:") {
5607
- return true;
5726
+ if (isURLSearchParameters(body)) {
5727
+ return "application/x-www-form-urlencoded;charset=UTF-8";
5608
5728
  }
5609
- return false;
5610
- }
5611
- function isUrlPotentiallyTrustworthy(url) {
5612
- if (/^about:(blank|srcdoc)$/.test(url)) {
5613
- return true;
5729
+ if (isBlob(body)) {
5730
+ return body.type || null;
5614
5731
  }
5615
- if (url.protocol === "data:") {
5616
- return true;
5732
+ if (Buffer2.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
5733
+ return null;
5617
5734
  }
5618
- if (/^(blob|filesystem):$/.test(url.protocol)) {
5619
- return true;
5735
+ if (body instanceof FormData) {
5736
+ return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
5620
5737
  }
5621
- return isOriginPotentiallyTrustworthy(url);
5622
- }
5623
- function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
5624
- if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
5738
+ if (body && typeof body.getBoundary === "function") {
5739
+ return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
5740
+ }
5741
+ if (body instanceof Stream) {
5625
5742
  return null;
5626
5743
  }
5627
- const policy = request.referrerPolicy;
5628
- if (request.referrer === "about:client") {
5629
- return "no-referrer";
5744
+ return "text/plain;charset=UTF-8";
5745
+ };
5746
+ var getTotalBytes = (request) => {
5747
+ const { body } = request[INTERNALS];
5748
+ if (body === null) {
5749
+ return 0;
5630
5750
  }
5631
- const referrerSource = request.referrer;
5632
- let referrerURL = stripURLForUseAsAReferrer(referrerSource);
5633
- let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
5634
- if (referrerURL.toString().length > 4096) {
5635
- referrerURL = referrerOrigin;
5751
+ if (isBlob(body)) {
5752
+ return body.size;
5636
5753
  }
5637
- if (referrerURLCallback) {
5638
- referrerURL = referrerURLCallback(referrerURL);
5754
+ if (Buffer2.isBuffer(body)) {
5755
+ return body.length;
5639
5756
  }
5640
- if (referrerOriginCallback) {
5641
- referrerOrigin = referrerOriginCallback(referrerOrigin);
5757
+ if (body && typeof body.getLengthSync === "function") {
5758
+ return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
5642
5759
  }
5643
- const currentURL = new URL(request.url);
5644
- switch (policy) {
5645
- case "no-referrer":
5646
- return "no-referrer";
5647
- case "origin":
5648
- return referrerOrigin;
5649
- case "unsafe-url":
5650
- return referrerURL;
5651
- case "strict-origin":
5652
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
5653
- return "no-referrer";
5654
- }
5655
- return referrerOrigin.toString();
5656
- case "strict-origin-when-cross-origin":
5657
- if (referrerURL.origin === currentURL.origin) {
5658
- return referrerURL;
5659
- }
5660
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
5661
- return "no-referrer";
5662
- }
5663
- return referrerOrigin;
5664
- case "same-origin":
5665
- if (referrerURL.origin === currentURL.origin) {
5666
- return referrerURL;
5667
- }
5668
- return "no-referrer";
5669
- case "origin-when-cross-origin":
5670
- if (referrerURL.origin === currentURL.origin) {
5671
- return referrerURL;
5672
- }
5673
- return referrerOrigin;
5674
- case "no-referrer-when-downgrade":
5675
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
5676
- return "no-referrer";
5677
- }
5678
- return referrerURL;
5679
- default:
5680
- throw new TypeError(`Invalid referrerPolicy: ${policy}`);
5681
- }
5682
- }
5683
- function parseReferrerPolicyFromHeader(headers) {
5684
- const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
5685
- let policy = "";
5686
- for (const token of policyTokens) {
5687
- if (token && ReferrerPolicy.has(token)) {
5688
- policy = token;
5689
- }
5760
+ return null;
5761
+ };
5762
+ var writeToStream = async (dest, { body }) => {
5763
+ if (body === null) {
5764
+ dest.end();
5765
+ } else {
5766
+ await pipeline(body, dest);
5690
5767
  }
5691
- return policy;
5692
- }
5768
+ };
5693
5769
 
5694
- // node_modules/node-fetch/src/request.js
5695
- var INTERNALS3 = Symbol("Request internals");
5696
- var isRequest = (object) => {
5697
- return typeof object === "object" && typeof object[INTERNALS3] === "object";
5770
+ // node_modules/node-fetch/src/headers.js
5771
+ import { types as types2 } from "node:util";
5772
+ import http from "node:http";
5773
+ var validateHeaderName = typeof http.validateHeaderName === "function" ? http.validateHeaderName : (name) => {
5774
+ if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
5775
+ const error = new TypeError(`Header name must be a valid HTTP token [${name}]`);
5776
+ Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
5777
+ throw error;
5778
+ }
5779
+ };
5780
+ var validateHeaderValue = typeof http.validateHeaderValue === "function" ? http.validateHeaderValue : (name, value) => {
5781
+ if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
5782
+ const error = new TypeError(`Invalid character in header content ["${name}"]`);
5783
+ Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
5784
+ throw error;
5785
+ }
5698
5786
  };
5699
- var doBadDataWarn = deprecate2(() => {}, ".data is not a valid RequestInit property, use .body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (request)");
5700
5787
 
5701
- class Request extends Body {
5702
- constructor(input, init = {}) {
5703
- let parsedURL;
5704
- if (isRequest(input)) {
5705
- parsedURL = new URL(input.url);
5706
- } else {
5707
- parsedURL = new URL(input);
5708
- input = {};
5709
- }
5710
- if (parsedURL.username !== "" || parsedURL.password !== "") {
5711
- throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
5712
- }
5713
- let method = init.method || input.method || "GET";
5714
- if (/^(delete|get|head|options|post|put)$/i.test(method)) {
5715
- method = method.toUpperCase();
5716
- }
5717
- if (!isRequest(init) && "data" in init) {
5718
- doBadDataWarn();
5719
- }
5720
- if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
5721
- throw new TypeError("Request with GET/HEAD method cannot have body");
5722
- }
5723
- const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
5724
- super(inputBody, {
5725
- size: init.size || input.size || 0
5726
- });
5727
- const headers = new Headers(init.headers || input.headers || {});
5728
- if (inputBody !== null && !headers.has("Content-Type")) {
5729
- const contentType = extractContentType(inputBody, this);
5730
- if (contentType) {
5731
- headers.set("Content-Type", contentType);
5788
+ class Headers extends URLSearchParams {
5789
+ constructor(init) {
5790
+ let result = [];
5791
+ if (init instanceof Headers) {
5792
+ const raw = init.raw();
5793
+ for (const [name, values] of Object.entries(raw)) {
5794
+ result.push(...values.map((value) => [name, value]));
5795
+ }
5796
+ } else if (init == null) {} else if (typeof init === "object" && !types2.isBoxedPrimitive(init)) {
5797
+ const method = init[Symbol.iterator];
5798
+ if (method == null) {
5799
+ result.push(...Object.entries(init));
5800
+ } else {
5801
+ if (typeof method !== "function") {
5802
+ throw new TypeError("Header pairs must be iterable");
5803
+ }
5804
+ result = [...init].map((pair) => {
5805
+ if (typeof pair !== "object" || types2.isBoxedPrimitive(pair)) {
5806
+ throw new TypeError("Each header pair must be an iterable object");
5807
+ }
5808
+ return [...pair];
5809
+ }).map((pair) => {
5810
+ if (pair.length !== 2) {
5811
+ throw new TypeError("Each header pair must be a name/value tuple");
5812
+ }
5813
+ return [...pair];
5814
+ });
5732
5815
  }
5733
- }
5734
- let signal = isRequest(input) ? input.signal : null;
5735
- if ("signal" in init) {
5736
- signal = init.signal;
5737
- }
5738
- if (signal != null && !isAbortSignal(signal)) {
5739
- throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
5740
- }
5741
- let referrer = init.referrer == null ? input.referrer : init.referrer;
5742
- if (referrer === "") {
5743
- referrer = "no-referrer";
5744
- } else if (referrer) {
5745
- const parsedReferrer = new URL(referrer);
5746
- referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
5747
5816
  } else {
5748
- referrer = undefined;
5817
+ throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
5749
5818
  }
5750
- this[INTERNALS3] = {
5751
- method,
5752
- redirect: init.redirect || input.redirect || "follow",
5753
- headers,
5754
- parsedURL,
5755
- signal,
5756
- referrer
5757
- };
5758
- this.follow = init.follow === undefined ? input.follow === undefined ? 20 : input.follow : init.follow;
5759
- this.compress = init.compress === undefined ? input.compress === undefined ? true : input.compress : init.compress;
5760
- this.counter = init.counter || input.counter || 0;
5761
- this.agent = init.agent || input.agent;
5762
- this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
5763
- this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
5764
- this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
5765
- }
5766
- get method() {
5767
- return this[INTERNALS3].method;
5768
- }
5769
- get url() {
5770
- return formatUrl(this[INTERNALS3].parsedURL);
5771
- }
5772
- get headers() {
5773
- return this[INTERNALS3].headers;
5819
+ result = result.length > 0 ? result.map(([name, value]) => {
5820
+ validateHeaderName(name);
5821
+ validateHeaderValue(name, String(value));
5822
+ return [String(name).toLowerCase(), String(value)];
5823
+ }) : undefined;
5824
+ super(result);
5825
+ return new Proxy(this, {
5826
+ get(target, p, receiver) {
5827
+ switch (p) {
5828
+ case "append":
5829
+ case "set":
5830
+ return (name, value) => {
5831
+ validateHeaderName(name);
5832
+ validateHeaderValue(name, String(value));
5833
+ return URLSearchParams.prototype[p].call(target, String(name).toLowerCase(), String(value));
5834
+ };
5835
+ case "delete":
5836
+ case "has":
5837
+ case "getAll":
5838
+ return (name) => {
5839
+ validateHeaderName(name);
5840
+ return URLSearchParams.prototype[p].call(target, String(name).toLowerCase());
5841
+ };
5842
+ case "keys":
5843
+ return () => {
5844
+ target.sort();
5845
+ return new Set(URLSearchParams.prototype.keys.call(target)).keys();
5846
+ };
5847
+ default:
5848
+ return Reflect.get(target, p, receiver);
5849
+ }
5850
+ }
5851
+ });
5774
5852
  }
5775
- get redirect() {
5776
- return this[INTERNALS3].redirect;
5853
+ get [Symbol.toStringTag]() {
5854
+ return this.constructor.name;
5777
5855
  }
5778
- get signal() {
5779
- return this[INTERNALS3].signal;
5856
+ toString() {
5857
+ return Object.prototype.toString.call(this);
5780
5858
  }
5781
- get referrer() {
5782
- if (this[INTERNALS3].referrer === "no-referrer") {
5783
- return "";
5784
- }
5785
- if (this[INTERNALS3].referrer === "client") {
5786
- return "about:client";
5859
+ get(name) {
5860
+ const values = this.getAll(name);
5861
+ if (values.length === 0) {
5862
+ return null;
5787
5863
  }
5788
- if (this[INTERNALS3].referrer) {
5789
- return this[INTERNALS3].referrer.toString();
5864
+ let value = values.join(", ");
5865
+ if (/^content-encoding$/i.test(name)) {
5866
+ value = value.toLowerCase();
5790
5867
  }
5791
- return;
5868
+ return value;
5792
5869
  }
5793
- get referrerPolicy() {
5794
- return this[INTERNALS3].referrerPolicy;
5870
+ forEach(callback, thisArg = undefined) {
5871
+ for (const name of this.keys()) {
5872
+ Reflect.apply(callback, thisArg, [this.get(name), name, this]);
5873
+ }
5795
5874
  }
5796
- set referrerPolicy(referrerPolicy) {
5797
- this[INTERNALS3].referrerPolicy = validateReferrerPolicy(referrerPolicy);
5875
+ *values() {
5876
+ for (const name of this.keys()) {
5877
+ yield this.get(name);
5878
+ }
5798
5879
  }
5799
- clone() {
5800
- return new Request(this);
5880
+ *entries() {
5881
+ for (const name of this.keys()) {
5882
+ yield [name, this.get(name)];
5883
+ }
5801
5884
  }
5802
- get [Symbol.toStringTag]() {
5803
- return "Request";
5885
+ [Symbol.iterator]() {
5886
+ return this.entries();
5804
5887
  }
5805
- }
5806
- Object.defineProperties(Request.prototype, {
5807
- method: { enumerable: true },
5808
- url: { enumerable: true },
5809
- headers: { enumerable: true },
5810
- redirect: { enumerable: true },
5811
- clone: { enumerable: true },
5812
- signal: { enumerable: true },
5813
- referrer: { enumerable: true },
5814
- referrerPolicy: { enumerable: true }
5815
- });
5816
- var getNodeRequestOptions = (request) => {
5817
- const { parsedURL } = request[INTERNALS3];
5818
- const headers = new Headers(request[INTERNALS3].headers);
5819
- if (!headers.has("Accept")) {
5820
- headers.set("Accept", "*/*");
5888
+ raw() {
5889
+ return [...this.keys()].reduce((result, key) => {
5890
+ result[key] = this.getAll(key);
5891
+ return result;
5892
+ }, {});
5821
5893
  }
5822
- let contentLengthValue = null;
5823
- if (request.body === null && /^(post|put)$/i.test(request.method)) {
5824
- contentLengthValue = "0";
5894
+ [Symbol.for("nodejs.util.inspect.custom")]() {
5895
+ return [...this.keys()].reduce((result, key) => {
5896
+ const values = this.getAll(key);
5897
+ if (key === "host") {
5898
+ result[key] = values[0];
5899
+ } else {
5900
+ result[key] = values.length > 1 ? values : values[0];
5901
+ }
5902
+ return result;
5903
+ }, {});
5825
5904
  }
5826
- if (request.body !== null) {
5827
- const totalBytes = getTotalBytes(request);
5828
- if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
5829
- contentLengthValue = String(totalBytes);
5905
+ }
5906
+ Object.defineProperties(Headers.prototype, ["get", "entries", "forEach", "values"].reduce((result, property) => {
5907
+ result[property] = { enumerable: true };
5908
+ return result;
5909
+ }, {}));
5910
+ function fromRawHeaders(headers = []) {
5911
+ return new Headers(headers.reduce((result, value, index, array) => {
5912
+ if (index % 2 === 0) {
5913
+ result.push(array.slice(index, index + 2));
5914
+ }
5915
+ return result;
5916
+ }, []).filter(([name, value]) => {
5917
+ try {
5918
+ validateHeaderName(name);
5919
+ validateHeaderValue(name, String(value));
5920
+ return true;
5921
+ } catch {
5922
+ return false;
5923
+ }
5924
+ }));
5925
+ }
5926
+
5927
+ // node_modules/node-fetch/src/utils/is-redirect.js
5928
+ var redirectStatus = new Set([301, 302, 303, 307, 308]);
5929
+ var isRedirect = (code) => {
5930
+ return redirectStatus.has(code);
5931
+ };
5932
+
5933
+ // node_modules/node-fetch/src/response.js
5934
+ var INTERNALS2 = Symbol("Response internals");
5935
+
5936
+ class Response extends Body {
5937
+ constructor(body = null, options = {}) {
5938
+ super(body, options);
5939
+ const status = options.status != null ? options.status : 200;
5940
+ const headers = new Headers(options.headers);
5941
+ if (body !== null && !headers.has("Content-Type")) {
5942
+ const contentType = extractContentType(body, this);
5943
+ if (contentType) {
5944
+ headers.append("Content-Type", contentType);
5945
+ }
5830
5946
  }
5947
+ this[INTERNALS2] = {
5948
+ type: "default",
5949
+ url: options.url,
5950
+ status,
5951
+ statusText: options.statusText || "",
5952
+ headers,
5953
+ counter: options.counter,
5954
+ highWaterMark: options.highWaterMark
5955
+ };
5831
5956
  }
5832
- if (contentLengthValue) {
5833
- headers.set("Content-Length", contentLengthValue);
5957
+ get type() {
5958
+ return this[INTERNALS2].type;
5834
5959
  }
5835
- if (request.referrerPolicy === "") {
5836
- request.referrerPolicy = DEFAULT_REFERRER_POLICY;
5960
+ get url() {
5961
+ return this[INTERNALS2].url || "";
5837
5962
  }
5838
- if (request.referrer && request.referrer !== "no-referrer") {
5839
- request[INTERNALS3].referrer = determineRequestsReferrer(request);
5840
- } else {
5841
- request[INTERNALS3].referrer = "no-referrer";
5963
+ get status() {
5964
+ return this[INTERNALS2].status;
5842
5965
  }
5843
- if (request[INTERNALS3].referrer instanceof URL) {
5844
- headers.set("Referer", request.referrer);
5966
+ get ok() {
5967
+ return this[INTERNALS2].status >= 200 && this[INTERNALS2].status < 300;
5845
5968
  }
5846
- if (!headers.has("User-Agent")) {
5847
- headers.set("User-Agent", "node-fetch");
5969
+ get redirected() {
5970
+ return this[INTERNALS2].counter > 0;
5848
5971
  }
5849
- if (request.compress && !headers.has("Accept-Encoding")) {
5850
- headers.set("Accept-Encoding", "gzip, deflate, br");
5972
+ get statusText() {
5973
+ return this[INTERNALS2].statusText;
5851
5974
  }
5852
- let { agent } = request;
5853
- if (typeof agent === "function") {
5854
- agent = agent(parsedURL);
5975
+ get headers() {
5976
+ return this[INTERNALS2].headers;
5855
5977
  }
5856
- const search = getSearch(parsedURL);
5857
- const options = {
5858
- path: parsedURL.pathname + search,
5859
- method: request.method,
5860
- headers: headers[Symbol.for("nodejs.util.inspect.custom")](),
5861
- insecureHTTPParser: request.insecureHTTPParser,
5862
- agent
5863
- };
5864
- return {
5865
- parsedURL,
5866
- options
5867
- };
5868
- };
5869
-
5870
- // node_modules/node-fetch/src/errors/abort-error.js
5871
- class AbortError extends FetchBaseError {
5872
- constructor(message, type = "aborted") {
5873
- super(message, type);
5978
+ get highWaterMark() {
5979
+ return this[INTERNALS2].highWaterMark;
5874
5980
  }
5875
- }
5876
-
5877
- // node_modules/node-fetch/src/index.js
5878
- init_esm_min();
5879
- init_from();
5880
- var supportedSchemas = new Set(["data:", "http:", "https:"]);
5881
- async function fetch2(url, options_) {
5882
- return new Promise((resolve, reject) => {
5883
- const request = new Request(url, options_);
5884
- const { parsedURL, options } = getNodeRequestOptions(request);
5885
- if (!supportedSchemas.has(parsedURL.protocol)) {
5886
- throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
5887
- }
5888
- if (parsedURL.protocol === "data:") {
5889
- const data = dist_default(request.url);
5890
- const response2 = new Response(data, { headers: { "Content-Type": data.typeFull } });
5891
- resolve(response2);
5892
- return;
5981
+ clone() {
5982
+ return new Response(clone(this, this.highWaterMark), {
5983
+ type: this.type,
5984
+ url: this.url,
5985
+ status: this.status,
5986
+ statusText: this.statusText,
5987
+ headers: this.headers,
5988
+ ok: this.ok,
5989
+ redirected: this.redirected,
5990
+ size: this.size,
5991
+ highWaterMark: this.highWaterMark
5992
+ });
5993
+ }
5994
+ static redirect(url, status = 302) {
5995
+ if (!isRedirect(status)) {
5996
+ throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
5893
5997
  }
5894
- const send = (parsedURL.protocol === "https:" ? https : http2).request;
5895
- const { signal } = request;
5896
- let response = null;
5897
- const abort = () => {
5898
- const error = new AbortError("The operation was aborted.");
5899
- reject(error);
5900
- if (request.body && request.body instanceof Stream2.Readable) {
5901
- request.body.destroy(error);
5902
- }
5903
- if (!response || !response.body) {
5904
- return;
5905
- }
5906
- response.body.emit("error", error);
5907
- };
5908
- if (signal && signal.aborted) {
5909
- abort();
5910
- return;
5998
+ return new Response(null, {
5999
+ headers: {
6000
+ location: new URL(url).toString()
6001
+ },
6002
+ status
6003
+ });
6004
+ }
6005
+ static error() {
6006
+ const response = new Response(null, { status: 0, statusText: "" });
6007
+ response[INTERNALS2].type = "error";
6008
+ return response;
6009
+ }
6010
+ static json(data = undefined, init = {}) {
6011
+ const body = JSON.stringify(data);
6012
+ if (body === undefined) {
6013
+ throw new TypeError("data is not JSON serializable");
5911
6014
  }
5912
- const abortAndFinalize = () => {
5913
- abort();
5914
- finalize();
5915
- };
5916
- const request_ = send(parsedURL.toString(), options);
5917
- if (signal) {
5918
- signal.addEventListener("abort", abortAndFinalize);
6015
+ const headers = new Headers(init && init.headers);
6016
+ if (!headers.has("content-type")) {
6017
+ headers.set("content-type", "application/json");
5919
6018
  }
5920
- const finalize = () => {
5921
- request_.abort();
5922
- if (signal) {
5923
- signal.removeEventListener("abort", abortAndFinalize);
5924
- }
5925
- };
5926
- request_.on("error", (error) => {
5927
- reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
5928
- finalize();
5929
- });
5930
- fixResponseChunkedTransferBadEnding(request_, (error) => {
5931
- if (response && response.body) {
5932
- response.body.destroy(error);
5933
- }
6019
+ return new Response(body, {
6020
+ ...init,
6021
+ headers
5934
6022
  });
5935
- if (process.version < "v14") {
5936
- request_.on("socket", (s2) => {
5937
- let endedWithEventsCount;
5938
- s2.prependListener("end", () => {
5939
- endedWithEventsCount = s2._eventsCount;
5940
- });
5941
- s2.prependListener("close", (hadError) => {
5942
- if (response && endedWithEventsCount < s2._eventsCount && !hadError) {
5943
- const error = new Error("Premature close");
5944
- error.code = "ERR_STREAM_PREMATURE_CLOSE";
5945
- response.body.emit("error", error);
5946
- }
5947
- });
5948
- });
5949
- }
5950
- request_.on("response", (response_) => {
5951
- request_.setTimeout(0);
5952
- const headers = fromRawHeaders(response_.rawHeaders);
5953
- if (isRedirect(response_.statusCode)) {
5954
- const location = headers.get("Location");
5955
- let locationURL = null;
5956
- try {
5957
- locationURL = location === null ? null : new URL(location, request.url);
5958
- } catch {
5959
- if (request.redirect !== "manual") {
5960
- reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
5961
- finalize();
5962
- return;
5963
- }
5964
- }
5965
- switch (request.redirect) {
5966
- case "error":
5967
- reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
5968
- finalize();
5969
- return;
5970
- case "manual":
5971
- break;
5972
- case "follow": {
5973
- if (locationURL === null) {
5974
- break;
5975
- }
5976
- if (request.counter >= request.follow) {
5977
- reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
5978
- finalize();
5979
- return;
5980
- }
5981
- const requestOptions = {
5982
- headers: new Headers(request.headers),
5983
- follow: request.follow,
5984
- counter: request.counter + 1,
5985
- agent: request.agent,
5986
- compress: request.compress,
5987
- method: request.method,
5988
- body: clone(request),
5989
- signal: request.signal,
5990
- size: request.size,
5991
- referrer: request.referrer,
5992
- referrerPolicy: request.referrerPolicy
5993
- };
5994
- if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {
5995
- for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
5996
- requestOptions.headers.delete(name);
5997
- }
5998
- }
5999
- if (response_.statusCode !== 303 && request.body && options_.body instanceof Stream2.Readable) {
6000
- reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
6001
- finalize();
6002
- return;
6003
- }
6004
- if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
6005
- requestOptions.method = "GET";
6006
- requestOptions.body = undefined;
6007
- requestOptions.headers.delete("content-length");
6008
- }
6009
- const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
6010
- if (responseReferrerPolicy) {
6011
- requestOptions.referrerPolicy = responseReferrerPolicy;
6012
- }
6013
- resolve(fetch2(new Request(locationURL, requestOptions)));
6014
- finalize();
6015
- return;
6016
- }
6017
- default:
6018
- return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
6019
- }
6020
- }
6021
- if (signal) {
6022
- response_.once("end", () => {
6023
- signal.removeEventListener("abort", abortAndFinalize);
6024
- });
6025
- }
6026
- let body = pump(response_, new PassThrough2, (error) => {
6027
- if (error) {
6028
- reject(error);
6029
- }
6030
- });
6031
- if (process.version < "v12.10") {
6032
- response_.on("aborted", abortAndFinalize);
6033
- }
6034
- const responseOptions = {
6035
- url: request.url,
6036
- status: response_.statusCode,
6037
- statusText: response_.statusMessage,
6038
- headers,
6039
- size: request.size,
6040
- counter: request.counter,
6041
- highWaterMark: request.highWaterMark
6042
- };
6043
- const codings = headers.get("Content-Encoding");
6044
- if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
6045
- response = new Response(body, responseOptions);
6046
- resolve(response);
6047
- return;
6048
- }
6049
- const zlibOptions = {
6050
- flush: zlib.Z_SYNC_FLUSH,
6051
- finishFlush: zlib.Z_SYNC_FLUSH
6052
- };
6053
- if (codings === "gzip" || codings === "x-gzip") {
6054
- body = pump(body, zlib.createGunzip(zlibOptions), (error) => {
6055
- if (error) {
6056
- reject(error);
6057
- }
6058
- });
6059
- response = new Response(body, responseOptions);
6060
- resolve(response);
6061
- return;
6062
- }
6063
- if (codings === "deflate" || codings === "x-deflate") {
6064
- const raw = pump(response_, new PassThrough2, (error) => {
6065
- if (error) {
6066
- reject(error);
6067
- }
6068
- });
6069
- raw.once("data", (chunk) => {
6070
- if ((chunk[0] & 15) === 8) {
6071
- body = pump(body, zlib.createInflate(), (error) => {
6072
- if (error) {
6073
- reject(error);
6074
- }
6075
- });
6076
- } else {
6077
- body = pump(body, zlib.createInflateRaw(), (error) => {
6078
- if (error) {
6079
- reject(error);
6080
- }
6081
- });
6082
- }
6083
- response = new Response(body, responseOptions);
6084
- resolve(response);
6085
- });
6086
- raw.once("end", () => {
6087
- if (!response) {
6088
- response = new Response(body, responseOptions);
6089
- resolve(response);
6090
- }
6091
- });
6092
- return;
6093
- }
6094
- if (codings === "br") {
6095
- body = pump(body, zlib.createBrotliDecompress(), (error) => {
6096
- if (error) {
6097
- reject(error);
6098
- }
6099
- });
6100
- response = new Response(body, responseOptions);
6101
- resolve(response);
6102
- return;
6103
- }
6104
- response = new Response(body, responseOptions);
6105
- resolve(response);
6106
- });
6107
- writeToStream(request_, request).catch(reject);
6108
- });
6109
- }
6110
- function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6111
- const LAST_CHUNK = Buffer3.from(`0\r
6112
- \r
6113
- `);
6114
- let isChunkedTransfer = false;
6115
- let properLastChunkReceived = false;
6116
- let previousChunk;
6117
- request.on("response", (response) => {
6118
- const { headers } = response;
6119
- isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
6120
- });
6121
- request.on("socket", (socket) => {
6122
- const onSocketClose = () => {
6123
- if (isChunkedTransfer && !properLastChunkReceived) {
6124
- const error = new Error("Premature close");
6125
- error.code = "ERR_STREAM_PREMATURE_CLOSE";
6126
- errorCallback(error);
6127
- }
6128
- };
6129
- const onData = (buf) => {
6130
- properLastChunkReceived = Buffer3.compare(buf.slice(-5), LAST_CHUNK) === 0;
6131
- if (!properLastChunkReceived && previousChunk) {
6132
- properLastChunkReceived = Buffer3.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && Buffer3.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
6133
- }
6134
- previousChunk = buf;
6135
- };
6136
- socket.prependListener("close", onSocketClose);
6137
- socket.on("data", onData);
6138
- request.on("close", () => {
6139
- socket.removeListener("close", onSocketClose);
6140
- socket.removeListener("data", onData);
6141
- });
6142
- });
6023
+ }
6024
+ get [Symbol.toStringTag]() {
6025
+ return "Response";
6026
+ }
6143
6027
  }
6144
-
6145
- // src/functions/custom-fetch.ts
6146
- var httpsAgent = new https2.Agent({
6147
- rejectUnauthorized: false
6028
+ Object.defineProperties(Response.prototype, {
6029
+ type: { enumerable: true },
6030
+ url: { enumerable: true },
6031
+ status: { enumerable: true },
6032
+ ok: { enumerable: true },
6033
+ redirected: { enumerable: true },
6034
+ statusText: { enumerable: true },
6035
+ headers: { enumerable: true },
6036
+ clone: { enumerable: true }
6148
6037
  });
6149
- async function customFetch(url, init) {
6150
- if (typeof Bun !== "undefined") {
6151
- return await fetch(url.toString(), {
6152
- method: init?.method,
6153
- tls: {
6154
- rejectUnauthorized: false
6155
- }
6156
- });
6038
+
6039
+ // node_modules/node-fetch/src/request.js
6040
+ import { format as formatUrl } from "node:url";
6041
+ import { deprecate as deprecate2 } from "node:util";
6042
+
6043
+ // node_modules/node-fetch/src/utils/get-search.js
6044
+ var getSearch = (parsedURL) => {
6045
+ if (parsedURL.search) {
6046
+ return parsedURL.search;
6157
6047
  }
6158
- return await fetch2(url, { ...init, agent: httpsAgent });
6159
- }
6048
+ const lastOffset = parsedURL.href.length - 1;
6049
+ const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
6050
+ return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
6051
+ };
6160
6052
 
6161
- // src/sonar/requests/volume-settings/request-volume-settings-streamer.ts
6162
- async function requestVolumeSettingsStreamer(sonarEndpoint) {
6163
- let response;
6164
- try {
6165
- const url = new URL(`${sonarEndpoint}/volumeSettings/streamer`);
6166
- response = await customFetch(url);
6167
- } catch (error) {
6168
- throw new SonarRequestException({ innerException: error });
6053
+ // node_modules/node-fetch/src/utils/referrer.js
6054
+ import { isIP } from "node:net";
6055
+ function stripURLForUseAsAReferrer(url, originOnly = false) {
6056
+ if (url == null) {
6057
+ return "no-referrer";
6169
6058
  }
6170
- if (response.ok) {
6171
- const data = await response.json();
6172
- if (data?.masters?.stream == null) {
6173
- throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
6174
- }
6175
- return data;
6176
- } else {
6177
- const data = await response.json();
6178
- throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
6059
+ url = new URL(url);
6060
+ if (/^(about|blob|data):$/.test(url.protocol)) {
6061
+ return "no-referrer";
6179
6062
  }
6063
+ url.username = "";
6064
+ url.password = "";
6065
+ url.hash = "";
6066
+ if (originOnly) {
6067
+ url.pathname = "";
6068
+ url.search = "";
6069
+ }
6070
+ return url;
6180
6071
  }
6181
-
6182
- // src/functions/audio/get-audio-data-stream.ts
6183
- async function getAudioDataStream(sonarEndpoint) {
6184
- const data = await requestVolumeSettingsStreamer(sonarEndpoint);
6185
- const volumeData = {
6186
- ["master" /* Master */]: createResponseVolumeData2(data.masters.stream),
6187
- ["game" /* Game */]: data.devices.game && createResponseVolumeData2(data.devices.game.stream),
6188
- ["chat" /* Chat */]: data.devices.chatRender && createResponseVolumeData2(data.devices.chatRender.stream),
6189
- ["media" /* Media */]: data.devices.media && createResponseVolumeData2(data.devices.media.stream),
6190
- ["aux" /* Aux */]: data.devices.aux && createResponseVolumeData2(data.devices.aux.stream),
6191
- ["mic" /* Mic */]: data.devices.chatCapture && createResponseVolumeData2(data.devices.chatCapture.stream)
6192
- };
6193
- return volumeData;
6194
- }
6195
- function createResponseVolumeData2(volumeData) {
6196
- return {
6197
- ["streaming" /* Streaming */]: {
6198
- volume: convertVolumeToUser(volumeData.streaming.volume),
6199
- isMuted: volumeData.streaming.muted
6200
- },
6201
- ["monitoring" /* Monitoring */]: {
6202
- volume: convertVolumeToUser(volumeData.monitoring.volume),
6203
- isMuted: volumeData.monitoring.muted
6204
- }
6205
- };
6072
+ var ReferrerPolicy = new Set([
6073
+ "",
6074
+ "no-referrer",
6075
+ "no-referrer-when-downgrade",
6076
+ "same-origin",
6077
+ "origin",
6078
+ "strict-origin",
6079
+ "origin-when-cross-origin",
6080
+ "strict-origin-when-cross-origin",
6081
+ "unsafe-url"
6082
+ ]);
6083
+ var DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
6084
+ function validateReferrerPolicy(referrerPolicy) {
6085
+ if (!ReferrerPolicy.has(referrerPolicy)) {
6086
+ throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
6087
+ }
6088
+ return referrerPolicy;
6206
6089
  }
6207
- // src/sonar/models/audio-settings/enums/audio-mode.ts
6208
- var AudioMode2;
6209
- ((AudioMode3) => {
6210
- AudioMode3["Classic"] = "classic";
6211
- AudioMode3["Streamer"] = "stream";
6212
- })(AudioMode2 ||= {});
6213
-
6214
- // src/sonar/requests/mode/request-audio-mode.ts
6215
- async function requestAudioMode(sonarEndpoint) {
6216
- let response;
6217
- const url = new URL(`${sonarEndpoint}/mode`);
6218
- try {
6219
- response = await customFetch(url);
6220
- } catch (error) {
6221
- throw new SonarRequestException({ innerException: error });
6090
+ function isOriginPotentiallyTrustworthy(url) {
6091
+ if (/^(http|ws)s:$/.test(url.protocol)) {
6092
+ return true;
6222
6093
  }
6223
- if (response.ok) {
6224
- const data = await response.json();
6225
- if (Object.values(AudioMode2).includes(data)) {
6226
- return data;
6227
- }
6228
- throw new SonarRequestException({ message: "Received unhandled audio mode from Sonar server" });
6229
- } else {
6230
- const data = await response.text();
6231
- throw new SonarRequestException({ innerException: new Error(data) });
6094
+ const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
6095
+ const hostIPVersion = isIP(hostIp);
6096
+ if (hostIPVersion === 4 && /^127\./.test(hostIp)) {
6097
+ return true;
6232
6098
  }
6233
- }
6234
-
6235
- // src/functions/audio/get-audio-mode.ts
6236
- async function getAudioMode(sonarEndpoint) {
6237
- return await requestAudioMode(sonarEndpoint);
6238
- }
6239
- // src/sonar/requests/mode/change-audio-mode.ts
6240
- async function changeAudioMode(sonarEndpoint, audioMode) {
6241
- let response;
6242
- const url = new URL(`${sonarEndpoint}/mode/${audioMode}`);
6243
- try {
6244
- response = await customFetch(url, {
6245
- method: "PUT"
6246
- });
6247
- } catch (error) {
6248
- throw new SonarRequestException({ innerException: error });
6099
+ if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) {
6100
+ return true;
6249
6101
  }
6250
- if (response.ok) {
6251
- const data = await response.json();
6252
- if (data !== audioMode) {
6253
- throw new SonarRequestException({ message: "Returned audio mode does not match requested mode" });
6254
- }
6255
- return data;
6256
- } else {
6257
- const data = await response.text();
6258
- throw new SonarRequestException({ innerException: new Error(data) });
6102
+ if (url.host === "localhost" || url.host.endsWith(".localhost")) {
6103
+ return false;
6104
+ }
6105
+ if (url.protocol === "file:") {
6106
+ return true;
6259
6107
  }
6108
+ return false;
6260
6109
  }
6261
-
6262
- // src/functions/audio/set-audio-mode.ts
6263
- async function setAudioMode(sonarEndpoint, audioMode) {
6264
- return await changeAudioMode(sonarEndpoint, audioMode);
6110
+ function isUrlPotentiallyTrustworthy(url) {
6111
+ if (/^about:(blank|srcdoc)$/.test(url)) {
6112
+ return true;
6113
+ }
6114
+ if (url.protocol === "data:") {
6115
+ return true;
6116
+ }
6117
+ if (/^(blob|filesystem):$/.test(url.protocol)) {
6118
+ return true;
6119
+ }
6120
+ return isOriginPotentiallyTrustworthy(url);
6265
6121
  }
6266
- // src/functions/converters/convert-channel-to-api.ts
6267
- function convertChannelToApi(channel) {
6268
- switch (channel) {
6269
- case "master" /* Master */:
6270
- return "master" /* Master */;
6271
- case "game" /* Game */:
6272
- return "chatRender" /* ChatRender */;
6273
- case "media" /* Media */:
6274
- return "media" /* Media */;
6275
- case "aux" /* Aux */:
6276
- return "aux" /* Aux */;
6277
- case "mic" /* Mic */:
6278
- return "chatCapture" /* ChatCapture */;
6122
+ function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
6123
+ if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
6124
+ return null;
6125
+ }
6126
+ const policy = request.referrerPolicy;
6127
+ if (request.referrer === "about:client") {
6128
+ return "no-referrer";
6129
+ }
6130
+ const referrerSource = request.referrer;
6131
+ let referrerURL = stripURLForUseAsAReferrer(referrerSource);
6132
+ let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
6133
+ if (referrerURL.toString().length > 4096) {
6134
+ referrerURL = referrerOrigin;
6135
+ }
6136
+ if (referrerURLCallback) {
6137
+ referrerURL = referrerURLCallback(referrerURL);
6138
+ }
6139
+ if (referrerOriginCallback) {
6140
+ referrerOrigin = referrerOriginCallback(referrerOrigin);
6141
+ }
6142
+ const currentURL = new URL(request.url);
6143
+ switch (policy) {
6144
+ case "no-referrer":
6145
+ return "no-referrer";
6146
+ case "origin":
6147
+ return referrerOrigin;
6148
+ case "unsafe-url":
6149
+ return referrerURL;
6150
+ case "strict-origin":
6151
+ if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
6152
+ return "no-referrer";
6153
+ }
6154
+ return referrerOrigin.toString();
6155
+ case "strict-origin-when-cross-origin":
6156
+ if (referrerURL.origin === currentURL.origin) {
6157
+ return referrerURL;
6158
+ }
6159
+ if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
6160
+ return "no-referrer";
6161
+ }
6162
+ return referrerOrigin;
6163
+ case "same-origin":
6164
+ if (referrerURL.origin === currentURL.origin) {
6165
+ return referrerURL;
6166
+ }
6167
+ return "no-referrer";
6168
+ case "origin-when-cross-origin":
6169
+ if (referrerURL.origin === currentURL.origin) {
6170
+ return referrerURL;
6171
+ }
6172
+ return referrerOrigin;
6173
+ case "no-referrer-when-downgrade":
6174
+ if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
6175
+ return "no-referrer";
6176
+ }
6177
+ return referrerURL;
6279
6178
  default:
6280
- throw new Error(`Unsupported AudioChannel: ${channel}`);
6281
- }
6282
- }
6283
-
6284
- // src/sonar/requests/volume-settings/change-volume-mute-classic.ts
6285
- async function changeVolumeMuteClassic(sonarEndpoint, isMuted, deviceRole) {
6286
- let response;
6287
- try {
6288
- const url = new URL(`${sonarEndpoint}/volumeSettings/classic/${deviceRole}/mute/${isMuted}`);
6289
- response = await customFetch(url, { method: "PUT" });
6290
- } catch (error) {
6291
- throw new SonarRequestException({ innerException: error });
6292
- }
6293
- if (response.ok) {
6294
- const data = await response.json();
6295
- if (data?.masters?.classic == null) {
6296
- throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
6297
- }
6298
- return data;
6299
- } else {
6300
- const data = await response.json();
6301
- throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
6302
- }
6303
- }
6304
-
6305
- // src/functions/audio/set-channel-mute-classic.ts
6306
- async function setChannelMuteClassic(sonarEndpoint, isMuted, channel) {
6307
- const sonarChannel = convertChannelToApi(channel);
6308
- const data = await changeVolumeMuteClassic(sonarEndpoint, isMuted, sonarChannel);
6309
- const device = sonarChannel === "master" /* Master */ ? data.masters.classic : data.devices[sonarChannel]?.classic;
6310
- if (!device) {
6311
- throw new SonarRequestException({ message: `Missing device data in response.` });
6179
+ throw new TypeError(`Invalid referrerPolicy: ${policy}`);
6312
6180
  }
6313
- const result = {
6314
- volume: convertVolumeToUser(device.volume),
6315
- isMuted: device.muted
6316
- };
6317
- return result;
6318
6181
  }
6319
- // src/sonar/requests/volume-settings/change-volume-mute-streamer.ts
6320
- async function changeVolumeMuteStreamer(sonarEndpoint, isMuted, deviceRole, path) {
6321
- let response;
6322
- try {
6323
- const url = new URL(`${sonarEndpoint}/volumeSettings/streamer/${path}/${deviceRole}/isMuted/${isMuted}`);
6324
- response = await customFetch(url, { method: "PUT" });
6325
- } catch (error) {
6326
- throw new SonarRequestException({ innerException: error });
6327
- }
6328
- if (response.ok) {
6329
- const data = await response.json();
6330
- if (data?.masters?.stream == null) {
6331
- throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
6182
+ function parseReferrerPolicyFromHeader(headers) {
6183
+ const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
6184
+ let policy = "";
6185
+ for (const token of policyTokens) {
6186
+ if (token && ReferrerPolicy.has(token)) {
6187
+ policy = token;
6332
6188
  }
6333
- return data;
6334
- } else {
6335
- const data = await response.json();
6336
- throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
6337
6189
  }
6190
+ return policy;
6338
6191
  }
6339
6192
 
6340
- // src/functions/audio/set-channel-mute-streamer.ts
6341
- async function setChannelMuteStreamer(sonarEndpoint, isMuted, channel, path) {
6342
- const sonarChannel = convertChannelToApi(channel);
6343
- const streamPath = path === "streaming" /* Streaming */ ? "streaming" /* Streaming */ : "monitoring" /* Monitoring */;
6344
- const data = await changeVolumeMuteStreamer(sonarEndpoint, isMuted, sonarChannel, streamPath);
6345
- const device = sonarChannel === "master" /* Master */ ? data.masters.stream : data.devices[sonarChannel]?.stream;
6346
- if (!device) {
6347
- throw new SonarRequestException({ message: `Missing device data in response.` });
6348
- }
6349
- const devicePath = path === "streaming" /* Streaming */ ? device.streaming : device.monitoring;
6350
- const result = {
6351
- volume: convertVolumeToUser(devicePath.volume),
6352
- isMuted: devicePath.muted
6353
- };
6354
- return result;
6355
- }
6356
- // src/functions/converters/convert-volume-to-api.ts
6357
- function convertVolumeToApi(value) {
6358
- let result = value / 100;
6359
- result = Math.min(Math.max(result, 0), 1);
6360
- return result;
6361
- }
6193
+ // node_modules/node-fetch/src/request.js
6194
+ var INTERNALS3 = Symbol("Request internals");
6195
+ var isRequest = (object) => {
6196
+ return typeof object === "object" && typeof object[INTERNALS3] === "object";
6197
+ };
6198
+ var doBadDataWarn = deprecate2(() => {}, ".data is not a valid RequestInit property, use .body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (request)");
6362
6199
 
6363
- // src/sonar/requests/volume-settings/change-volume-level-classic.ts
6364
- async function changeVolumeLevelClassic(sonarEndpoint, volume, deviceRole) {
6365
- let response;
6366
- try {
6367
- const url = new URL(`${sonarEndpoint}/volumeSettings/classic/${deviceRole}/volume/${volume}`);
6368
- response = await customFetch(url, { method: "PUT" });
6369
- } catch (error) {
6370
- throw new SonarRequestException({ innerException: error });
6371
- }
6372
- if (response.ok) {
6373
- const data = await response.json();
6374
- if (data?.masters?.classic == null) {
6375
- throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
6200
+ class Request extends Body {
6201
+ constructor(input, init = {}) {
6202
+ let parsedURL;
6203
+ if (isRequest(input)) {
6204
+ parsedURL = new URL(input.url);
6205
+ } else {
6206
+ parsedURL = new URL(input);
6207
+ input = {};
6376
6208
  }
6377
- return data;
6378
- } else {
6379
- const data = await response.json();
6380
- throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
6209
+ if (parsedURL.username !== "" || parsedURL.password !== "") {
6210
+ throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
6211
+ }
6212
+ let method = init.method || input.method || "GET";
6213
+ if (/^(delete|get|head|options|post|put)$/i.test(method)) {
6214
+ method = method.toUpperCase();
6215
+ }
6216
+ if (!isRequest(init) && "data" in init) {
6217
+ doBadDataWarn();
6218
+ }
6219
+ if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
6220
+ throw new TypeError("Request with GET/HEAD method cannot have body");
6221
+ }
6222
+ const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
6223
+ super(inputBody, {
6224
+ size: init.size || input.size || 0
6225
+ });
6226
+ const headers = new Headers(init.headers || input.headers || {});
6227
+ if (inputBody !== null && !headers.has("Content-Type")) {
6228
+ const contentType = extractContentType(inputBody, this);
6229
+ if (contentType) {
6230
+ headers.set("Content-Type", contentType);
6231
+ }
6232
+ }
6233
+ let signal = isRequest(input) ? input.signal : null;
6234
+ if ("signal" in init) {
6235
+ signal = init.signal;
6236
+ }
6237
+ if (signal != null && !isAbortSignal(signal)) {
6238
+ throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
6239
+ }
6240
+ let referrer = init.referrer == null ? input.referrer : init.referrer;
6241
+ if (referrer === "") {
6242
+ referrer = "no-referrer";
6243
+ } else if (referrer) {
6244
+ const parsedReferrer = new URL(referrer);
6245
+ referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
6246
+ } else {
6247
+ referrer = undefined;
6248
+ }
6249
+ this[INTERNALS3] = {
6250
+ method,
6251
+ redirect: init.redirect || input.redirect || "follow",
6252
+ headers,
6253
+ parsedURL,
6254
+ signal,
6255
+ referrer
6256
+ };
6257
+ this.follow = init.follow === undefined ? input.follow === undefined ? 20 : input.follow : init.follow;
6258
+ this.compress = init.compress === undefined ? input.compress === undefined ? true : input.compress : init.compress;
6259
+ this.counter = init.counter || input.counter || 0;
6260
+ this.agent = init.agent || input.agent;
6261
+ this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
6262
+ this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
6263
+ this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
6381
6264
  }
6382
- }
6383
-
6384
- // src/functions/audio/set-channel-volume-classic.ts
6385
- async function setChannelVolumeClassic(sonarEndpoint, volumePercent, channel) {
6386
- const sonarChannel = convertChannelToApi(channel);
6387
- const formattedVolume = convertVolumeToApi(volumePercent);
6388
- const data = await changeVolumeLevelClassic(sonarEndpoint, formattedVolume, sonarChannel);
6389
- const device = sonarChannel === "master" /* Master */ ? data.masters.classic : data.devices[sonarChannel]?.classic;
6390
- if (!device) {
6391
- throw new SonarRequestException({ message: `Missing device data in response.` });
6265
+ get method() {
6266
+ return this[INTERNALS3].method;
6392
6267
  }
6393
- const result = {
6394
- volume: convertVolumeToUser(device.volume),
6395
- isMuted: device.muted
6396
- };
6397
- return result;
6398
- }
6399
- // src/sonar/requests/volume-settings/change-volume-level-streamer.ts
6400
- async function changeVolumeLevelStreamer(sonarEndpoint, volume, channel, path) {
6401
- let response;
6402
- try {
6403
- const url = new URL(`${sonarEndpoint}/volumeSettings/streamer/${path}/${channel}/volume/${volume}`);
6404
- response = await customFetch(url, { method: "PUT" });
6405
- } catch (error) {
6406
- throw new SonarRequestException({ innerException: error });
6268
+ get url() {
6269
+ return formatUrl(this[INTERNALS3].parsedURL);
6407
6270
  }
6408
- if (response.ok) {
6409
- const data = await response.json();
6410
- if (data?.masters?.stream == null) {
6411
- throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
6412
- }
6413
- return data;
6414
- } else {
6415
- const data = await response.json();
6416
- throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
6271
+ get headers() {
6272
+ return this[INTERNALS3].headers;
6417
6273
  }
6418
- }
6419
-
6420
- // src/functions/audio/set-channel-volume-streamer.ts
6421
- async function setChannelVolumeStreamer(sonarEndpoint, volumePercent, channel, path) {
6422
- const sonarChannel = convertChannelToApi(channel);
6423
- const formattedVolume = convertVolumeToApi(volumePercent);
6424
- const streamPath = path === "streaming" /* Streaming */ ? "streaming" /* Streaming */ : "monitoring" /* Monitoring */;
6425
- const data = await changeVolumeLevelStreamer(sonarEndpoint, formattedVolume, sonarChannel, streamPath);
6426
- const device = sonarChannel === "master" /* Master */ ? data.masters.stream : data.devices[sonarChannel]?.stream;
6427
- if (!device) {
6428
- throw new SonarRequestException({ message: `Missing device data in response.` });
6274
+ get redirect() {
6275
+ return this[INTERNALS3].redirect;
6429
6276
  }
6430
- const devicePath = path === "streaming" /* Streaming */ ? device.streaming : device.monitoring;
6431
- const result = {
6432
- volume: convertVolumeToUser(devicePath.volume),
6433
- isMuted: devicePath.muted
6434
- };
6435
- return result;
6436
- }
6437
- // src/functions/converters/convert-chat-mix-balance-to-user.ts
6438
- function convertChatMixBalanceToUser(balance) {
6439
- let result = (balance + 1) / 2 * 100;
6440
- result = Math.floor(result);
6441
- result = Math.min(Math.max(result, 0), 100);
6442
- return result;
6443
- }
6444
-
6445
- // src/sonar/requests/chatmix/request-chat-mix-state.ts
6446
- async function requestChatMixState(sonarEndpoint) {
6447
- const url = new URL(`${sonarEndpoint}/chatMix`);
6448
- let response;
6449
- try {
6450
- response = await customFetch(url);
6451
- } catch (error) {
6452
- throw new SonarRequestException({ innerException: error });
6277
+ get signal() {
6278
+ return this[INTERNALS3].signal;
6453
6279
  }
6454
- if (response.ok) {
6455
- const data = await response.json();
6456
- if (data?.balance == null || data?.state == null) {
6457
- throw new SonarRequestException({ message: "Missing required data in response" });
6280
+ get referrer() {
6281
+ if (this[INTERNALS3].referrer === "no-referrer") {
6282
+ return "";
6283
+ }
6284
+ if (this[INTERNALS3].referrer === "client") {
6285
+ return "about:client";
6458
6286
  }
6459
- return data;
6460
- } else {
6461
- const data = await response.text();
6462
- throw new SonarRequestException({ innerException: new Error(data) });
6287
+ if (this[INTERNALS3].referrer) {
6288
+ return this[INTERNALS3].referrer.toString();
6289
+ }
6290
+ return;
6463
6291
  }
6464
- }
6465
-
6466
- // src/functions/chatmix/get-chat-mix-state.ts
6467
- async function getChatMixState(sonarEndpoint) {
6468
- const data = await requestChatMixState(sonarEndpoint);
6469
- const chatMixData = {
6470
- chatBalance: convertChatMixBalanceToUser(data.balance),
6471
- state: data.state,
6472
- isEnabled: data.state === "enabled" /* Enabled */
6473
- };
6474
- return chatMixData;
6475
- }
6476
- // src/functions/converters/convert-chat-mix-balance-to-api.ts
6477
- function convertChatMixBalanceToApi(balance) {
6478
- let result = balance / 100 * 2 - 1;
6479
- result = Math.min(Math.max(result, -1), 1);
6480
- return result;
6481
- }
6482
-
6483
- // src/sonar/requests/chatmix/change-chat-mix-balance.ts
6484
- async function changeChatMixBalance(sonarEndpoint, chatBalance) {
6485
- const url = new URL(`${sonarEndpoint}/chatMix?balance=${chatBalance}`);
6486
- let response;
6487
- try {
6488
- response = await customFetch(url, {
6489
- method: "PUT"
6490
- });
6491
- } catch (error) {
6492
- throw new SonarRequestException({ innerException: error });
6292
+ get referrerPolicy() {
6293
+ return this[INTERNALS3].referrerPolicy;
6493
6294
  }
6494
- if (response.ok) {
6495
- const data = await response.json();
6496
- if (data?.balance == null || data?.state == null) {
6497
- throw new SonarRequestException({ message: "Missing required data in response" });
6498
- }
6499
- return data;
6500
- } else {
6501
- const data = await response.json();
6502
- throw new SonarRequestException({ message: data.Message });
6295
+ set referrerPolicy(referrerPolicy) {
6296
+ this[INTERNALS3].referrerPolicy = validateReferrerPolicy(referrerPolicy);
6297
+ }
6298
+ clone() {
6299
+ return new Request(this);
6300
+ }
6301
+ get [Symbol.toStringTag]() {
6302
+ return "Request";
6503
6303
  }
6504
6304
  }
6505
-
6506
- // src/functions/chatmix/set-chat-mix-balance.ts
6507
- async function setChatMixBalance(sonarEndpoint, chatBalance) {
6508
- const balance = convertChatMixBalanceToApi(chatBalance);
6509
- const data = await changeChatMixBalance(sonarEndpoint, balance);
6510
- const chatMixData = {
6511
- chatBalance: convertChatMixBalanceToUser(data.balance),
6512
- state: data.state,
6513
- isEnabled: data.state === "enabled" /* Enabled */
6514
- };
6515
- return chatMixData;
6516
- }
6517
- // src/sonar/requests/audio-devices/request-audio-devices.ts
6518
- async function requestAudioDevices(sonarEndpoint, params) {
6519
- const { deviceDataFlow, onlySteelSeriesVAD = false, removeSteelSeriesVAD = false } = params;
6520
- const url = new URL(`${sonarEndpoint}/audioDevices`);
6521
- url.searchParams.append("onlySteelSeriesVAD", String(onlySteelSeriesVAD));
6522
- url.searchParams.append("removeSteelSeriesVAD", String(removeSteelSeriesVAD));
6523
- if (deviceDataFlow !== undefined) {
6524
- url.searchParams.append("deviceDataFlow", deviceDataFlow.toString());
6305
+ Object.defineProperties(Request.prototype, {
6306
+ method: { enumerable: true },
6307
+ url: { enumerable: true },
6308
+ headers: { enumerable: true },
6309
+ redirect: { enumerable: true },
6310
+ clone: { enumerable: true },
6311
+ signal: { enumerable: true },
6312
+ referrer: { enumerable: true },
6313
+ referrerPolicy: { enumerable: true }
6314
+ });
6315
+ var getNodeRequestOptions = (request) => {
6316
+ const { parsedURL } = request[INTERNALS3];
6317
+ const headers = new Headers(request[INTERNALS3].headers);
6318
+ if (!headers.has("Accept")) {
6319
+ headers.set("Accept", "*/*");
6525
6320
  }
6526
- let response;
6527
- try {
6528
- response = await customFetch(url);
6529
- } catch (error) {
6530
- throw new SonarRequestException({
6531
- innerException: error
6532
- });
6321
+ let contentLengthValue = null;
6322
+ if (request.body === null && /^(post|put)$/i.test(request.method)) {
6323
+ contentLengthValue = "0";
6533
6324
  }
6534
- if (!response.ok) {
6535
- const error = await response.text();
6536
- throw new SonarRequestException({ message: `Failed to get audio devices: ${error}` });
6325
+ if (request.body !== null) {
6326
+ const totalBytes = getTotalBytes(request);
6327
+ if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
6328
+ contentLengthValue = String(totalBytes);
6329
+ }
6537
6330
  }
6538
- const data = await response.json();
6539
- if (!Array.isArray(data)) {
6540
- throw new SonarRequestException({ message: "Invalid audio devices response format." });
6331
+ if (contentLengthValue) {
6332
+ headers.set("Content-Length", contentLengthValue);
6541
6333
  }
6542
- return data;
6543
- }
6544
-
6545
- // src/functions/devices/get-audio-devices.ts
6546
- async function getAudioDevices(sonarEndpoint, deviceType) {
6547
- let deviceDataFlow;
6548
- switch (deviceType) {
6549
- case "input" /* Input */:
6550
- deviceDataFlow = "capture" /* Capture */;
6551
- break;
6552
- case "output" /* Output */:
6553
- deviceDataFlow = "render" /* Render */;
6554
- break;
6555
- case undefined:
6556
- deviceDataFlow = "all" /* All */;
6557
- break;
6334
+ if (request.referrerPolicy === "") {
6335
+ request.referrerPolicy = DEFAULT_REFERRER_POLICY;
6558
6336
  }
6559
- const data = await requestAudioDevices(sonarEndpoint, { deviceDataFlow, removeSteelSeriesVAD: true });
6560
- const audioDevices = data.map((device) => ({
6561
- id: device.id,
6562
- name: device.friendlyName,
6563
- type: getDeviceTypeFromDataFlow(device.dataFlow)
6564
- }));
6565
- return audioDevices;
6566
- }
6567
- function getDeviceTypeFromDataFlow(dataFlow) {
6568
- switch (dataFlow) {
6569
- case "capture" /* Capture */:
6570
- return "input" /* Input */;
6571
- case "render" /* Render */:
6572
- return "output" /* Output */;
6573
- default:
6574
- throw new SonarRequestException({ message: `Unknown device data flow: ${dataFlow}` });
6337
+ if (request.referrer && request.referrer !== "no-referrer") {
6338
+ request[INTERNALS3].referrer = determineRequestsReferrer(request);
6339
+ } else {
6340
+ request[INTERNALS3].referrer = "no-referrer";
6575
6341
  }
6576
- }
6577
- // src/sonar/requests/audio-devices/change-audio-device.ts
6578
- async function changeAudioDevice(sonarEndpoint, deviceChannel, deviceId) {
6579
- let response;
6580
- const url = new URL(`${sonarEndpoint}/classicRedirections/${deviceChannel}/deviceId/${deviceId}`);
6581
- try {
6582
- response = await customFetch(url, { method: "PUT" });
6583
- } catch (error) {
6584
- throw new SonarRequestException({
6585
- innerException: error
6586
- });
6342
+ if (request[INTERNALS3].referrer instanceof URL) {
6343
+ headers.set("Referer", request.referrer);
6587
6344
  }
6588
- if (!response.ok) {
6589
- const error = await response.text();
6590
- throw new SonarRequestException({ message: `Failed to get audio devices: ${error}` });
6345
+ if (!headers.has("User-Agent")) {
6346
+ headers.set("User-Agent", "node-fetch");
6591
6347
  }
6592
- const unknownData = await response.json();
6593
- const data = Array.isArray(unknownData) ? unknownData : [unknownData];
6594
- const devices = data.filter((x2) => x2?.deviceId === deviceId);
6595
- if (devices.length === 0) {
6596
- throw new SonarRequestException({ message: "The changed audio devices list is empty." });
6348
+ if (request.compress && !headers.has("Accept-Encoding")) {
6349
+ headers.set("Accept-Encoding", "gzip, deflate, br");
6597
6350
  }
6598
- return devices;
6599
- }
6351
+ let { agent } = request;
6352
+ if (typeof agent === "function") {
6353
+ agent = agent(parsedURL);
6354
+ }
6355
+ const search = getSearch(parsedURL);
6356
+ const options = {
6357
+ path: parsedURL.pathname + search,
6358
+ method: request.method,
6359
+ headers: headers[Symbol.for("nodejs.util.inspect.custom")](),
6360
+ insecureHTTPParser: request.insecureHTTPParser,
6361
+ agent
6362
+ };
6363
+ return {
6364
+ parsedURL,
6365
+ options
6366
+ };
6367
+ };
6600
6368
 
6601
- // src/functions/devices/set-audio-device.ts
6602
- async function setAudioDevice(sonarEndpoint, deviceChannel, deviceId) {
6603
- const data = await changeAudioDevice(sonarEndpoint, deviceChannel, deviceId);
6604
- const result = data.map((x2) => ({
6605
- deviceId: x2.deviceId,
6606
- deviceChannel: x2.id,
6607
- isRunning: x2.isRunning
6608
- }));
6609
- return result;
6610
- }
6611
- // src/functions/endpoint/get-app-endpoint.ts
6612
- import { promises as fsAsync } from "node:fs";
6613
- import { platform as getPlatform } from "node:os";
6614
- import { join as joinPath } from "node:path";
6615
- var WINDOWS_PATHS = ["SteelSeries", "SteelSeries Engine 3", "coreProps.json"];
6616
- async function getAppEndpoint() {
6617
- const appDataPath = getPath();
6618
- const fileContents = await getContents(appDataPath);
6619
- const data = parseContents(fileContents);
6620
- if (data.ggEncryptedAddress) {
6621
- return `https://${data.ggEncryptedAddress}`;
6369
+ // node_modules/node-fetch/src/errors/abort-error.js
6370
+ class AbortError extends FetchBaseError {
6371
+ constructor(message, type = "aborted") {
6372
+ super(message, type);
6622
6373
  }
6623
- throw new SonarInitializationException({
6624
- reason: "Bad Config" /* BadConfig */
6625
- });
6626
6374
  }
6627
- function getPath() {
6628
- const os = getPlatform();
6629
- switch (os) {
6630
- case "win32": {
6631
- const programData = process.env.ProgramData ?? "C:\\ProgramData";
6632
- return joinPath(programData, ...WINDOWS_PATHS);
6375
+
6376
+ // node_modules/node-fetch/src/index.js
6377
+ init_esm_min();
6378
+ init_from();
6379
+ var supportedSchemas = new Set(["data:", "http:", "https:"]);
6380
+ async function fetch2(url, options_) {
6381
+ return new Promise((resolve, reject) => {
6382
+ const request = new Request(url, options_);
6383
+ const { parsedURL, options } = getNodeRequestOptions(request);
6384
+ if (!supportedSchemas.has(parsedURL.protocol)) {
6385
+ throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
6386
+ }
6387
+ if (parsedURL.protocol === "data:") {
6388
+ const data = dist_default(request.url);
6389
+ const response2 = new Response(data, { headers: { "Content-Type": data.typeFull } });
6390
+ resolve(response2);
6391
+ return;
6392
+ }
6393
+ const send = (parsedURL.protocol === "https:" ? https : http2).request;
6394
+ const { signal } = request;
6395
+ let response = null;
6396
+ const abort = () => {
6397
+ const error = new AbortError("The operation was aborted.");
6398
+ reject(error);
6399
+ if (request.body && request.body instanceof Stream2.Readable) {
6400
+ request.body.destroy(error);
6401
+ }
6402
+ if (!response || !response.body) {
6403
+ return;
6404
+ }
6405
+ response.body.emit("error", error);
6406
+ };
6407
+ if (signal && signal.aborted) {
6408
+ abort();
6409
+ return;
6633
6410
  }
6634
- default:
6635
- throw new SonarInitializationException({
6636
- reason: "OS Unsupported" /* OSUnsupported */
6411
+ const abortAndFinalize = () => {
6412
+ abort();
6413
+ finalize();
6414
+ };
6415
+ const request_ = send(parsedURL.toString(), options);
6416
+ if (signal) {
6417
+ signal.addEventListener("abort", abortAndFinalize);
6418
+ }
6419
+ const finalize = () => {
6420
+ request_.abort();
6421
+ if (signal) {
6422
+ signal.removeEventListener("abort", abortAndFinalize);
6423
+ }
6424
+ };
6425
+ request_.on("error", (error) => {
6426
+ reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
6427
+ finalize();
6428
+ });
6429
+ fixResponseChunkedTransferBadEnding(request_, (error) => {
6430
+ if (response && response.body) {
6431
+ response.body.destroy(error);
6432
+ }
6433
+ });
6434
+ if (process.version < "v14") {
6435
+ request_.on("socket", (s2) => {
6436
+ let endedWithEventsCount;
6437
+ s2.prependListener("end", () => {
6438
+ endedWithEventsCount = s2._eventsCount;
6439
+ });
6440
+ s2.prependListener("close", (hadError) => {
6441
+ if (response && endedWithEventsCount < s2._eventsCount && !hadError) {
6442
+ const error = new Error("Premature close");
6443
+ error.code = "ERR_STREAM_PREMATURE_CLOSE";
6444
+ response.body.emit("error", error);
6445
+ }
6446
+ });
6637
6447
  });
6638
- }
6639
- }
6640
- async function getContents(path) {
6641
- try {
6642
- return await fsAsync.readFile(path, "utf8");
6643
- } catch (error) {
6644
- throw new SonarInitializationException({
6645
- reason: "Bad Config" /* BadConfig */,
6646
- innerException: error
6448
+ }
6449
+ request_.on("response", (response_) => {
6450
+ request_.setTimeout(0);
6451
+ const headers = fromRawHeaders(response_.rawHeaders);
6452
+ if (isRedirect(response_.statusCode)) {
6453
+ const location = headers.get("Location");
6454
+ let locationURL = null;
6455
+ try {
6456
+ locationURL = location === null ? null : new URL(location, request.url);
6457
+ } catch {
6458
+ if (request.redirect !== "manual") {
6459
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
6460
+ finalize();
6461
+ return;
6462
+ }
6463
+ }
6464
+ switch (request.redirect) {
6465
+ case "error":
6466
+ reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
6467
+ finalize();
6468
+ return;
6469
+ case "manual":
6470
+ break;
6471
+ case "follow": {
6472
+ if (locationURL === null) {
6473
+ break;
6474
+ }
6475
+ if (request.counter >= request.follow) {
6476
+ reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
6477
+ finalize();
6478
+ return;
6479
+ }
6480
+ const requestOptions = {
6481
+ headers: new Headers(request.headers),
6482
+ follow: request.follow,
6483
+ counter: request.counter + 1,
6484
+ agent: request.agent,
6485
+ compress: request.compress,
6486
+ method: request.method,
6487
+ body: clone(request),
6488
+ signal: request.signal,
6489
+ size: request.size,
6490
+ referrer: request.referrer,
6491
+ referrerPolicy: request.referrerPolicy
6492
+ };
6493
+ if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {
6494
+ for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
6495
+ requestOptions.headers.delete(name);
6496
+ }
6497
+ }
6498
+ if (response_.statusCode !== 303 && request.body && options_.body instanceof Stream2.Readable) {
6499
+ reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
6500
+ finalize();
6501
+ return;
6502
+ }
6503
+ if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
6504
+ requestOptions.method = "GET";
6505
+ requestOptions.body = undefined;
6506
+ requestOptions.headers.delete("content-length");
6507
+ }
6508
+ const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
6509
+ if (responseReferrerPolicy) {
6510
+ requestOptions.referrerPolicy = responseReferrerPolicy;
6511
+ }
6512
+ resolve(fetch2(new Request(locationURL, requestOptions)));
6513
+ finalize();
6514
+ return;
6515
+ }
6516
+ default:
6517
+ return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
6518
+ }
6519
+ }
6520
+ if (signal) {
6521
+ response_.once("end", () => {
6522
+ signal.removeEventListener("abort", abortAndFinalize);
6523
+ });
6524
+ }
6525
+ let body = pump(response_, new PassThrough2, (error) => {
6526
+ if (error) {
6527
+ reject(error);
6528
+ }
6529
+ });
6530
+ if (process.version < "v12.10") {
6531
+ response_.on("aborted", abortAndFinalize);
6532
+ }
6533
+ const responseOptions = {
6534
+ url: request.url,
6535
+ status: response_.statusCode,
6536
+ statusText: response_.statusMessage,
6537
+ headers,
6538
+ size: request.size,
6539
+ counter: request.counter,
6540
+ highWaterMark: request.highWaterMark
6541
+ };
6542
+ const codings = headers.get("Content-Encoding");
6543
+ if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
6544
+ response = new Response(body, responseOptions);
6545
+ resolve(response);
6546
+ return;
6547
+ }
6548
+ const zlibOptions = {
6549
+ flush: zlib.Z_SYNC_FLUSH,
6550
+ finishFlush: zlib.Z_SYNC_FLUSH
6551
+ };
6552
+ if (codings === "gzip" || codings === "x-gzip") {
6553
+ body = pump(body, zlib.createGunzip(zlibOptions), (error) => {
6554
+ if (error) {
6555
+ reject(error);
6556
+ }
6557
+ });
6558
+ response = new Response(body, responseOptions);
6559
+ resolve(response);
6560
+ return;
6561
+ }
6562
+ if (codings === "deflate" || codings === "x-deflate") {
6563
+ const raw = pump(response_, new PassThrough2, (error) => {
6564
+ if (error) {
6565
+ reject(error);
6566
+ }
6567
+ });
6568
+ raw.once("data", (chunk) => {
6569
+ if ((chunk[0] & 15) === 8) {
6570
+ body = pump(body, zlib.createInflate(), (error) => {
6571
+ if (error) {
6572
+ reject(error);
6573
+ }
6574
+ });
6575
+ } else {
6576
+ body = pump(body, zlib.createInflateRaw(), (error) => {
6577
+ if (error) {
6578
+ reject(error);
6579
+ }
6580
+ });
6581
+ }
6582
+ response = new Response(body, responseOptions);
6583
+ resolve(response);
6584
+ });
6585
+ raw.once("end", () => {
6586
+ if (!response) {
6587
+ response = new Response(body, responseOptions);
6588
+ resolve(response);
6589
+ }
6590
+ });
6591
+ return;
6592
+ }
6593
+ if (codings === "br") {
6594
+ body = pump(body, zlib.createBrotliDecompress(), (error) => {
6595
+ if (error) {
6596
+ reject(error);
6597
+ }
6598
+ });
6599
+ response = new Response(body, responseOptions);
6600
+ resolve(response);
6601
+ return;
6602
+ }
6603
+ response = new Response(body, responseOptions);
6604
+ resolve(response);
6647
6605
  });
6648
- }
6606
+ writeToStream(request_, request).catch(reject);
6607
+ });
6649
6608
  }
6650
- function parseContents(contents) {
6651
- try {
6652
- return JSON.parse(contents);
6653
- } catch (error) {
6654
- throw new SonarInitializationException({
6655
- reason: "Bad Config" /* BadConfig */,
6656
- innerException: error
6609
+ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6610
+ const LAST_CHUNK = Buffer3.from(`0\r
6611
+ \r
6612
+ `);
6613
+ let isChunkedTransfer = false;
6614
+ let properLastChunkReceived = false;
6615
+ let previousChunk;
6616
+ request.on("response", (response) => {
6617
+ const { headers } = response;
6618
+ isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
6619
+ });
6620
+ request.on("socket", (socket) => {
6621
+ const onSocketClose = () => {
6622
+ if (isChunkedTransfer && !properLastChunkReceived) {
6623
+ const error = new Error("Premature close");
6624
+ error.code = "ERR_STREAM_PREMATURE_CLOSE";
6625
+ errorCallback(error);
6626
+ }
6627
+ };
6628
+ const onData = (buf) => {
6629
+ properLastChunkReceived = Buffer3.compare(buf.slice(-5), LAST_CHUNK) === 0;
6630
+ if (!properLastChunkReceived && previousChunk) {
6631
+ properLastChunkReceived = Buffer3.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && Buffer3.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
6632
+ }
6633
+ previousChunk = buf;
6634
+ };
6635
+ socket.prependListener("close", onSocketClose);
6636
+ socket.on("data", onData);
6637
+ request.on("close", () => {
6638
+ socket.removeListener("close", onSocketClose);
6639
+ socket.removeListener("data", onData);
6657
6640
  });
6658
- }
6641
+ });
6659
6642
  }
6643
+
6660
6644
  // src/functions/endpoint/get-sonar-endpoint.ts
6661
6645
  async function getSonarEndpoint(appEndpoint) {
6662
6646
  let response;
6663
6647
  try {
6664
- response = await customFetch(`${appEndpoint}/subApps`);
6648
+ const url = `${appEndpoint}/subApps`;
6649
+ if (typeof Bun !== "undefined") {
6650
+ response = await fetch(url, {
6651
+ tls: {
6652
+ rejectUnauthorized: false
6653
+ }
6654
+ });
6655
+ } else {
6656
+ response = await fetch2(url, {
6657
+ agent: new https2.Agent({
6658
+ rejectUnauthorized: false
6659
+ })
6660
+ });
6661
+ }
6665
6662
  } catch (error) {
6666
6663
  throw new SonarInitializationException({
6667
6664
  reason: "Not Responding" /* NotResponding */,
@@ -6767,7 +6764,7 @@ function convertProfileChannelToUser(channel) {
6767
6764
  async function requestConfigs(sonarAddress, channel) {
6768
6765
  let response;
6769
6766
  try {
6770
- response = await customFetch(`${sonarAddress}/configs?vad=${channel}`);
6767
+ response = await fetch(`${sonarAddress}/configs?vad=${channel}`);
6771
6768
  } catch (error) {
6772
6769
  throw new SonarRequestException({ innerException: error });
6773
6770
  }
@@ -6803,7 +6800,7 @@ async function getChannelProfiles(sonarAddress, channel, favoritesOnly) {
6803
6800
  async function requestSelectedConfigs(sonarAddress) {
6804
6801
  let response;
6805
6802
  try {
6806
- response = await customFetch(`${sonarAddress}/configs/selected`);
6803
+ response = await fetch(`${sonarAddress}/configs/selected`);
6807
6804
  } catch (error) {
6808
6805
  throw new SonarRequestException({ innerException: error });
6809
6806
  }
@@ -6837,7 +6834,7 @@ async function getSelectedProfiles(sonarAddress) {
6837
6834
  async function changeSelectedConfig(sonarAddress, configId) {
6838
6835
  let response;
6839
6836
  try {
6840
- response = await customFetch(`${sonarAddress}/configs/${configId}/select`, {
6837
+ response = await fetch(`${sonarAddress}/configs/${configId}/select`, {
6841
6838
  method: "PUT"
6842
6839
  });
6843
6840
  } catch (error) {