@audd/sdk 1.5.12 → 1.5.13

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.cjs CHANGED
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
25
25
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
26
26
 
27
27
  // src/version.ts
28
- var VERSION = "1.5.12";
28
+ var VERSION = "1.5.13";
29
29
 
30
30
  // src/errors.ts
31
31
  var AudDError = class extends Error {
@@ -339,13 +339,38 @@ function asObjectLenient(raw) {
339
339
  return asObject(raw) ?? {};
340
340
  }
341
341
  function asString(v) {
342
- return typeof v === "string" ? v : void 0;
342
+ if (typeof v === "string") return v;
343
+ if (typeof v === "number" || typeof v === "boolean") return String(v);
344
+ return void 0;
345
+ }
346
+ function toFiniteNumber(v) {
347
+ if (typeof v === "number") return Number.isFinite(v) ? v : void 0;
348
+ if (typeof v === "boolean") return v ? 1 : 0;
349
+ if (typeof v === "string") {
350
+ const t = v.trim();
351
+ if (t === "") return void 0;
352
+ const n = Number(t);
353
+ return Number.isFinite(n) ? n : void 0;
354
+ }
355
+ return void 0;
343
356
  }
344
357
  function asNumber(v) {
345
- return typeof v === "number" ? v : void 0;
358
+ return toFiniteNumber(v);
359
+ }
360
+ function asInteger(v) {
361
+ const n = toFiniteNumber(v);
362
+ return n === void 0 ? void 0 : Math.trunc(n);
346
363
  }
347
364
  function asBoolean(v) {
348
- return typeof v === "boolean" ? v : void 0;
365
+ if (typeof v === "boolean") return v;
366
+ if (typeof v === "number") return v !== 0;
367
+ if (typeof v === "string") {
368
+ const t = v.trim().toLowerCase();
369
+ if (t === "true" || t === "1" || t === "yes" || t === "on") return true;
370
+ if (t === "false" || t === "0" || t === "no" || t === "off" || t === "") return false;
371
+ return void 0;
372
+ }
373
+ return void 0;
349
374
  }
350
375
  function parseOffsetToSeconds(o) {
351
376
  if (o === void 0 || o === null) return void 0;
@@ -442,7 +467,7 @@ var RECOGNITION_KEYS = [
442
467
  function parseRecognitionResult(raw) {
443
468
  const r = asObjectLenient(raw);
444
469
  const timecode = asString(r.timecode);
445
- const audioId = asNumber(r.audio_id);
470
+ const audioId = asInteger(r.audio_id);
446
471
  const artist = asString(r.artist);
447
472
  const title = asString(r.title);
448
473
  const songLink = asString(r.song_link);
@@ -530,8 +555,8 @@ function parseEnterpriseMatch(raw) {
530
555
  isrc: asString(r.isrc),
531
556
  upc: asString(r.upc),
532
557
  songLink,
533
- startOffset: asNumber(r.start_offset),
534
- endOffset: asNumber(r.end_offset),
558
+ startOffset: asInteger(r.start_offset),
559
+ endOffset: asInteger(r.end_offset),
535
560
  startSeconds: void 0,
536
561
  endSeconds: void 0,
537
562
  extras: pickExtras(r, ENTERPRISE_MATCH_KEYS),
@@ -587,7 +612,7 @@ function parseEnterpriseChunkResult(raw) {
587
612
  var STREAM_KEYS = ["radio_id", "url", "stream_running", "longpoll_category"];
588
613
  function parseStream(raw) {
589
614
  const r = asObjectLenient(raw);
590
- const radioId = asNumber(r.radio_id);
615
+ const radioId = asInteger(r.radio_id);
591
616
  const url = asString(r.url);
592
617
  const streamRunning = asBoolean(r.stream_running);
593
618
  return {
@@ -647,14 +672,14 @@ var STREAM_CALLBACK_MATCH_KEYS = [
647
672
  ];
648
673
  function parseStreamCallbackMatch(raw) {
649
674
  const r = asObjectLenient(raw);
650
- const radioId = asNumber(r.radio_id);
675
+ const radioId = asInteger(r.radio_id);
651
676
  const resultsRaw = Array.isArray(r.results) ? r.results : [];
652
677
  const songs = resultsRaw.filter((x) => asObject(x) !== void 0).map(parseStreamCallbackSong);
653
678
  const [first, ...rest] = songs;
654
679
  return {
655
680
  radioId,
656
681
  timestamp: asString(r.timestamp),
657
- playLength: asNumber(r.play_length),
682
+ playLength: asInteger(r.play_length),
658
683
  song: first,
659
684
  alternatives: rest,
660
685
  extras: pickExtras(r, STREAM_CALLBACK_MATCH_KEYS),
@@ -669,8 +694,8 @@ var STREAM_CALLBACK_NOTIFICATION_KEYS = [
669
694
  ];
670
695
  function parseStreamCallbackNotification(raw) {
671
696
  const r = asObjectLenient(raw);
672
- const radioId = asNumber(r.radio_id);
673
- const code = asNumber(r.notification_code);
697
+ const radioId = asInteger(r.radio_id);
698
+ const code = asInteger(r.notification_code);
674
699
  const message = asString(r.notification_message);
675
700
  return {
676
701
  radioId,
@@ -699,9 +724,9 @@ function parseLyricsResult(raw) {
699
724
  artist,
700
725
  title,
701
726
  lyrics: asString(r.lyrics),
702
- songId: asNumber(r.song_id),
727
+ songId: asInteger(r.song_id),
703
728
  fullTitle: asString(r.full_title),
704
- artistId: asNumber(r.artist_id),
729
+ artistId: asInteger(r.artist_id),
705
730
  songLink: asString(r.song_link),
706
731
  media: asString(r.media),
707
732
  extras: pickExtras(r, LYRICS_KEYS),