@audd/sdk 1.5.5 → 1.5.7

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/README.md CHANGED
@@ -286,9 +286,9 @@ callback URL set, and the preflight surfaces that as an actionable
286
286
  error. Pass `skipCallbackCheck: true` to bypass.
287
287
 
288
288
  ```ts
289
- const category = audd.streams.deriveLongpollCategory(12345); // pure, no network call
290
- const poll = await audd.streams.longpoll(category, { timeout: 30 });
289
+ const radioId = 1; // any integer you choose — your handle for this stream
291
290
 
291
+ const poll = await audd.streams.longpoll({ radioId, timeout: 30 });
292
292
  for await (const m of poll.matches) {
293
293
  console.log(m.song.artist, m.song.title);
294
294
  }
package/dist/index.cjs CHANGED
@@ -684,6 +684,8 @@ function shouldRetryResponse(resp, retryClass) {
684
684
  return s >= HTTP_SERVER_ERROR_FLOOR;
685
685
  case "mutating":
686
686
  return false;
687
+ case "none":
688
+ return false;
687
689
  }
688
690
  }
689
691
  function shouldRetryError(err, retryClass) {
@@ -694,6 +696,8 @@ function shouldRetryError(err, retryClass) {
694
696
  return isPreUploadConnectionError(err);
695
697
  case "mutating":
696
698
  return isPreUploadConnectionError(err);
699
+ case "none":
700
+ return false;
697
701
  }
698
702
  }
699
703
  function sleep(ms) {
@@ -1169,30 +1173,42 @@ var Streams = class {
1169
1173
  parseCallback(body) {
1170
1174
  return parseCallback(body);
1171
1175
  }
1172
- /**
1173
- * Long-poll the AudD subscription endpoint.
1174
- *
1175
- * Returns a {@link LongpollPoll} handle with three async-iterables —
1176
- * `matches`, `notifications`, `errors` — that are filled by a background
1177
- * loop. Iterate them independently or in parallel via `Promise.all([...])`.
1178
- *
1179
- * Before the first request the SDK runs a one-time `getCallbackUrl`
1180
- * preflight: AudD silently discards events for accounts that haven't set a
1181
- * callback URL, and the preflight surfaces that misconfiguration as an
1182
- * actionable {@link AudDInvalidRequestError}. Pass `skipCallbackCheck: true`
1183
- * to bypass.
1184
- */
1185
- async longpoll(category, opts = {}) {
1186
- if (opts.skipCallbackCheck !== true) {
1176
+ async longpoll(arg1, opts = {}) {
1177
+ let category;
1178
+ let effectiveOpts;
1179
+ if (typeof arg1 === "string") {
1180
+ category = arg1;
1181
+ effectiveOpts = opts;
1182
+ } else {
1183
+ effectiveOpts = arg1;
1184
+ const hasRadioId = arg1.radioId !== void 0;
1185
+ const hasCategory = arg1.category !== void 0;
1186
+ if (hasRadioId && hasCategory) {
1187
+ throw new AudDInvalidRequestError({
1188
+ errorCode: 0,
1189
+ message: "longpoll(): pass exactly one of `radioId` or `category` \u2014 got both.",
1190
+ httpStatus: 0
1191
+ });
1192
+ }
1193
+ if (!hasRadioId && !hasCategory) {
1194
+ throw new AudDInvalidRequestError({
1195
+ errorCode: 0,
1196
+ message: "longpoll(): pass exactly one of `radioId` or `category` \u2014 got neither.",
1197
+ httpStatus: 0
1198
+ });
1199
+ }
1200
+ category = hasRadioId ? this.deriveLongpollCategory(arg1.radioId) : arg1.category;
1201
+ }
1202
+ if (effectiveOpts.skipCallbackCheck !== true) {
1187
1203
  await this.preflightCallbackUrl();
1188
1204
  }
1189
- const timeoutSec = opts.timeout ?? 50;
1205
+ const timeoutSec = effectiveOpts.timeout ?? 50;
1190
1206
  const httpClient = this.http;
1191
1207
  const readPolicy = this.readPolicy;
1192
1208
  return startLongpoll({
1193
1209
  category,
1194
1210
  timeout: timeoutSec,
1195
- sinceTime: opts.sinceTime,
1211
+ sinceTime: effectiveOpts.sinceTime,
1196
1212
  fetchOnce: (params, signal) => runRetried(
1197
1213
  () => httpClient.get(`${API_BASE}/longpoll/`, params, { signal }),
1198
1214
  readPolicy
@@ -1254,12 +1270,12 @@ async function runRetried2(fn, policy) {
1254
1270
  }
1255
1271
  }
1256
1272
  var CustomCatalog = class {
1257
- constructor(http, mutatingPolicy) {
1273
+ constructor(http, noRetryPolicy) {
1258
1274
  this.http = http;
1259
- this.mutatingPolicy = mutatingPolicy;
1275
+ this.noRetryPolicy = noRetryPolicy;
1260
1276
  }
1261
1277
  http;
1262
- mutatingPolicy;
1278
+ noRetryPolicy;
1263
1279
  /**
1264
1280
  * **This is NOT how you submit audio for music recognition.** For
1265
1281
  * recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()` for
@@ -1271,6 +1287,11 @@ var CustomCatalog = class {
1271
1287
  * Calling this again with the same `audioId` re-fingerprints that slot.
1272
1288
  * There is no public list/delete endpoint; track `audioId` ↔ song
1273
1289
  * mappings on your side.
1290
+ *
1291
+ * **No automatic retry.** Custom-catalog upload is metered, and a transport
1292
+ * failure could otherwise cause a silent re-upload that double-charges. Any
1293
+ * 5xx or pre-upload connection error surfaces as a clean exception — the
1294
+ * caller decides whether to retry.
1274
1295
  */
1275
1296
  async add(opts) {
1276
1297
  const reopen = prepareSource(opts.source);
@@ -1279,7 +1300,7 @@ var CustomCatalog = class {
1279
1300
  const prepared = await reopen();
1280
1301
  const fields = { ...prepared.fields, audio_id: audioId };
1281
1302
  return this.http.postForm(UPLOAD_URL, fields);
1282
- }, this.mutatingPolicy);
1303
+ }, this.noRetryPolicy);
1283
1304
  decodeSuccess2(resp.jsonBody, resp.httpStatus, resp.requestId);
1284
1305
  }
1285
1306
  };
@@ -1523,7 +1544,7 @@ var AudD = class {
1523
1544
  /** Sub-namespace for the private fingerprint catalog. NOT for recognition. */
1524
1545
  get customCatalog() {
1525
1546
  if (this._customCatalog === void 0) {
1526
- this._customCatalog = new CustomCatalog(this._http, this.policyFor("mutating"));
1547
+ this._customCatalog = new CustomCatalog(this._http, this.policyFor("none"));
1527
1548
  }
1528
1549
  return this._customCatalog;
1529
1550
  }