@tidal-music/api 0.7.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +13047 -4319
  3. package/dist/index.js +163 -151
  4. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -1,161 +1,173 @@
1
- const G = /\{[^{}]+\}/g, J = () => typeof process == "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
2
- function _() {
1
+ const V = /\{[^{}]+\}/g, X = () => typeof process == "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
2
+ function Y() {
3
3
  return Math.random().toString(36).slice(2, 11);
4
4
  }
5
- function K(o) {
5
+ function Z(n) {
6
6
  let {
7
7
  baseUrl: t = "",
8
8
  Request: e = globalThis.Request,
9
- fetch: n = globalThis.fetch,
9
+ fetch: o = globalThis.fetch,
10
10
  querySerializer: r,
11
11
  bodySerializer: i,
12
- headers: l,
13
- requestInitExt: c = void 0,
14
- ...F
15
- } = { ...o };
16
- c = J() ? c : void 0, t = L(t);
12
+ pathSerializer: l,
13
+ headers: u,
14
+ requestInitExt: $ = void 0,
15
+ ...J
16
+ } = { ...n };
17
+ $ = X() ? $ : void 0, t = B(t);
17
18
  const g = [];
18
19
  async function p(a, s) {
19
20
  const {
20
21
  baseUrl: m,
21
- fetch: q = n,
22
- Request: O = e,
22
+ fetch: O = o,
23
+ Request: D = e,
23
24
  headers: I,
24
25
  params: w = {},
25
- parseAs: $ = "json",
26
- querySerializer: j,
27
- bodySerializer: H = i ?? X,
28
- body: D,
29
- middleware: N = [],
30
- ...C
26
+ parseAs: j = "json",
27
+ querySerializer: E,
28
+ bodySerializer: H = i ?? te,
29
+ pathSerializer: Q,
30
+ body: P,
31
+ middleware: G = [],
32
+ ...v
31
33
  } = s || {};
32
- let v = t;
33
- m && (v = L(m) ?? t);
34
- let U = typeof r == "function" ? r : P(r);
35
- j && (U = typeof j == "function" ? j : P({
34
+ let C = t;
35
+ m && (C = B(m) ?? t);
36
+ let x = typeof r == "function" ? r : M(r);
37
+ E && (x = typeof E == "function" ? E : M({
36
38
  ...typeof r == "object" ? r : {},
37
- ...j
39
+ ...E
38
40
  }));
39
- const x = D === void 0 ? void 0 : H(
40
- D,
41
+ const k = Q || l || ee, U = P === void 0 ? void 0 : H(
42
+ P,
41
43
  // Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
42
44
  // bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
43
45
  // the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
44
46
  // setting the content-type at the very beginning to be overwritten.
45
47
  // Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
46
- k(l, I, w.header)
47
- ), W = k(
48
+ N(u, I, w.header)
49
+ ), _ = N(
48
50
  // with no body, we should not to set Content-Type
49
- x === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
50
- x instanceof FormData ? {} : {
51
+ U === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
52
+ U instanceof FormData ? {} : {
51
53
  "Content-Type": "application/json"
52
54
  },
53
- l,
55
+ u,
54
56
  I,
55
57
  w.header
56
- ), y = [...g, ...N], Q = {
58
+ ), h = [...g, ...G], K = {
57
59
  redirect: "follow",
58
- ...F,
59
- ...C,
60
- body: x,
61
- headers: W
60
+ ...J,
61
+ ...v,
62
+ body: U,
63
+ headers: _
62
64
  };
63
- let E, T, h = new O(
64
- Y(a, { baseUrl: v, params: w, querySerializer: U }),
65
- Q
66
- ), f;
67
- for (const d in C)
68
- d in h || (h[d] = C[d]);
69
- if (y.length) {
70
- E = _(), T = Object.freeze({
71
- baseUrl: v,
72
- fetch: q,
73
- parseAs: $,
74
- querySerializer: U,
75
- bodySerializer: H
65
+ let S, T, y = new D(
66
+ re(a, { baseUrl: C, params: w, querySerializer: x, pathSerializer: k }),
67
+ K
68
+ ), c;
69
+ for (const d in v)
70
+ d in y || (y[d] = v[d]);
71
+ if (h.length) {
72
+ S = Y(), T = Object.freeze({
73
+ baseUrl: C,
74
+ fetch: O,
75
+ parseAs: j,
76
+ querySerializer: x,
77
+ bodySerializer: H,
78
+ pathSerializer: k
76
79
  });
77
- for (const d of y)
80
+ for (const d of h)
78
81
  if (d && typeof d == "object" && typeof d.onRequest == "function") {
79
- const u = await d.onRequest({
80
- request: h,
82
+ const f = await d.onRequest({
83
+ request: y,
81
84
  schemaPath: a,
82
85
  params: w,
83
86
  options: T,
84
- id: E
87
+ id: S
85
88
  });
86
- if (u)
87
- if (u instanceof O)
88
- h = u;
89
- else if (u instanceof Response) {
90
- f = u;
89
+ if (f)
90
+ if (f instanceof D)
91
+ y = f;
92
+ else if (f instanceof Response) {
93
+ c = f;
91
94
  break;
92
95
  } else
93
96
  throw new Error("onRequest: must return new Request() or Response() when modifying the request");
94
97
  }
95
98
  }
96
- if (!f) {
99
+ if (!c) {
97
100
  try {
98
- f = await q(h, c);
101
+ c = await O(y, $);
99
102
  } catch (d) {
100
- let u = d;
101
- if (y.length)
102
- for (let b = y.length - 1; b >= 0; b--) {
103
- const S = y[b];
104
- if (S && typeof S == "object" && typeof S.onError == "function") {
105
- const R = await S.onError({
106
- request: h,
107
- error: u,
103
+ let f = d;
104
+ if (h.length)
105
+ for (let b = h.length - 1; b >= 0; b--) {
106
+ const z = h[b];
107
+ if (z && typeof z == "object" && typeof z.onError == "function") {
108
+ const R = await z.onError({
109
+ request: y,
110
+ error: f,
108
111
  schemaPath: a,
109
112
  params: w,
110
113
  options: T,
111
- id: E
114
+ id: S
112
115
  });
113
116
  if (R) {
114
117
  if (R instanceof Response) {
115
- u = void 0, f = R;
118
+ f = void 0, c = R;
116
119
  break;
117
120
  }
118
121
  if (R instanceof Error) {
119
- u = R;
122
+ f = R;
120
123
  continue;
121
124
  }
122
125
  throw new Error("onError: must return new Response() or instance of Error");
123
126
  }
124
127
  }
125
128
  }
126
- if (u)
127
- throw u;
129
+ if (f)
130
+ throw f;
128
131
  }
129
- if (y.length)
130
- for (let d = y.length - 1; d >= 0; d--) {
131
- const u = y[d];
132
- if (u && typeof u == "object" && typeof u.onResponse == "function") {
133
- const b = await u.onResponse({
134
- request: h,
135
- response: f,
132
+ if (h.length)
133
+ for (let d = h.length - 1; d >= 0; d--) {
134
+ const f = h[d];
135
+ if (f && typeof f == "object" && typeof f.onResponse == "function") {
136
+ const b = await f.onResponse({
137
+ request: y,
138
+ response: c,
136
139
  schemaPath: a,
137
140
  params: w,
138
141
  options: T,
139
- id: E
142
+ id: S
140
143
  });
141
144
  if (b) {
142
145
  if (!(b instanceof Response))
143
146
  throw new Error("onResponse: must return new Response() when modifying the response");
144
- f = b;
147
+ c = b;
145
148
  }
146
149
  }
147
150
  }
148
151
  }
149
- if (f.status === 204 || h.method === "HEAD" || f.headers.get("Content-Length") === "0")
150
- return f.ok ? { data: void 0, response: f } : { error: void 0, response: f };
151
- if (f.ok)
152
- return $ === "stream" ? { data: f.body, response: f } : { data: await f[$](), response: f };
153
- let z = await f.text();
152
+ const L = c.headers.get("Content-Length");
153
+ if (c.status === 204 || y.method === "HEAD" || L === "0" && !c.headers.get("Transfer-Encoding")?.includes("chunked"))
154
+ return c.ok ? { data: void 0, response: c } : { error: void 0, response: c };
155
+ if (c.ok)
156
+ return { data: await (async () => {
157
+ if (j === "stream")
158
+ return c.body;
159
+ if (j === "json" && !L) {
160
+ const f = await c.text();
161
+ return f ? JSON.parse(f) : void 0;
162
+ }
163
+ return await c[j]();
164
+ })(), response: c };
165
+ let q = await c.text();
154
166
  try {
155
- z = JSON.parse(z);
167
+ q = JSON.parse(q);
156
168
  } catch {
157
169
  }
158
- return { error: z, response: f };
170
+ return { error: q, response: c };
159
171
  }
160
172
  return {
161
173
  request(a, s, m) {
@@ -211,71 +223,71 @@ function K(o) {
211
223
  }
212
224
  };
213
225
  }
214
- function A(o, t, e) {
226
+ function A(n, t, e) {
215
227
  if (t == null)
216
228
  return "";
217
229
  if (typeof t == "object")
218
230
  throw new Error(
219
231
  "Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
220
232
  );
221
- return `${o}=${e?.allowReserved === !0 ? t : encodeURIComponent(t)}`;
233
+ return `${n}=${e?.allowReserved === !0 ? t : encodeURIComponent(t)}`;
222
234
  }
223
- function M(o, t, e) {
235
+ function F(n, t, e) {
224
236
  if (!t || typeof t != "object")
225
237
  return "";
226
- const n = [], r = {
238
+ const o = [], r = {
227
239
  simple: ",",
228
240
  label: ".",
229
241
  matrix: ";"
230
242
  }[e.style] || "&";
231
243
  if (e.style !== "deepObject" && e.explode === !1) {
232
- for (const c in t)
233
- n.push(c, e.allowReserved === !0 ? t[c] : encodeURIComponent(t[c]));
234
- const l = n.join(",");
244
+ for (const u in t)
245
+ o.push(u, e.allowReserved === !0 ? t[u] : encodeURIComponent(t[u]));
246
+ const l = o.join(",");
235
247
  switch (e.style) {
236
248
  case "form":
237
- return `${o}=${l}`;
249
+ return `${n}=${l}`;
238
250
  case "label":
239
251
  return `.${l}`;
240
252
  case "matrix":
241
- return `;${o}=${l}`;
253
+ return `;${n}=${l}`;
242
254
  default:
243
255
  return l;
244
256
  }
245
257
  }
246
258
  for (const l in t) {
247
- const c = e.style === "deepObject" ? `${o}[${l}]` : l;
248
- n.push(A(c, t[l], e));
259
+ const u = e.style === "deepObject" ? `${n}[${l}]` : l;
260
+ o.push(A(u, t[l], e));
249
261
  }
250
- const i = n.join(r);
262
+ const i = o.join(r);
251
263
  return e.style === "label" || e.style === "matrix" ? `${r}${i}` : i;
252
264
  }
253
- function B(o, t, e) {
265
+ function W(n, t, e) {
254
266
  if (!Array.isArray(t))
255
267
  return "";
256
268
  if (e.explode === !1) {
257
- const i = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", l = (e.allowReserved === !0 ? t : t.map((c) => encodeURIComponent(c))).join(i);
269
+ const i = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", l = (e.allowReserved === !0 ? t : t.map((u) => encodeURIComponent(u))).join(i);
258
270
  switch (e.style) {
259
271
  case "simple":
260
272
  return l;
261
273
  case "label":
262
274
  return `.${l}`;
263
275
  case "matrix":
264
- return `;${o}=${l}`;
276
+ return `;${n}=${l}`;
265
277
  // case "spaceDelimited":
266
278
  // case "pipeDelimited":
267
279
  default:
268
- return `${o}=${l}`;
280
+ return `${n}=${l}`;
269
281
  }
270
282
  }
271
- const n = { simple: ",", label: ".", matrix: ";" }[e.style] || "&", r = [];
283
+ const o = { simple: ",", label: ".", matrix: ";" }[e.style] || "&", r = [];
272
284
  for (const i of t)
273
- e.style === "simple" || e.style === "label" ? r.push(e.allowReserved === !0 ? i : encodeURIComponent(i)) : r.push(A(o, i, e));
274
- return e.style === "label" || e.style === "matrix" ? `${n}${r.join(n)}` : r.join(n);
285
+ e.style === "simple" || e.style === "label" ? r.push(e.allowReserved === !0 ? i : encodeURIComponent(i)) : r.push(A(n, i, e));
286
+ return e.style === "label" || e.style === "matrix" ? `${o}${r.join(o)}` : r.join(o);
275
287
  }
276
- function P(o) {
288
+ function M(n) {
277
289
  return function(e) {
278
- const n = [];
290
+ const o = [];
279
291
  if (e && typeof e == "object")
280
292
  for (const r in e) {
281
293
  const i = e[r];
@@ -283,72 +295,72 @@ function P(o) {
283
295
  if (Array.isArray(i)) {
284
296
  if (i.length === 0)
285
297
  continue;
286
- n.push(
287
- B(r, i, {
298
+ o.push(
299
+ W(r, i, {
288
300
  style: "form",
289
301
  explode: !0,
290
- ...o?.array,
291
- allowReserved: o?.allowReserved || !1
302
+ ...n?.array,
303
+ allowReserved: n?.allowReserved || !1
292
304
  })
293
305
  );
294
306
  continue;
295
307
  }
296
308
  if (typeof i == "object") {
297
- n.push(
298
- M(r, i, {
309
+ o.push(
310
+ F(r, i, {
299
311
  style: "deepObject",
300
312
  explode: !0,
301
- ...o?.object,
302
- allowReserved: o?.allowReserved || !1
313
+ ...n?.object,
314
+ allowReserved: n?.allowReserved || !1
303
315
  })
304
316
  );
305
317
  continue;
306
318
  }
307
- n.push(A(r, i, o));
319
+ o.push(A(r, i, n));
308
320
  }
309
321
  }
310
- return n.join("&");
322
+ return o.join("&");
311
323
  };
312
324
  }
313
- function V(o, t) {
314
- let e = o;
315
- for (const n of o.match(G) ?? []) {
316
- let r = n.substring(1, n.length - 1), i = !1, l = "simple";
325
+ function ee(n, t) {
326
+ let e = n;
327
+ for (const o of n.match(V) ?? []) {
328
+ let r = o.substring(1, o.length - 1), i = !1, l = "simple";
317
329
  if (r.endsWith("*") && (i = !0, r = r.substring(0, r.length - 1)), r.startsWith(".") ? (l = "label", r = r.substring(1)) : r.startsWith(";") && (l = "matrix", r = r.substring(1)), !t || t[r] === void 0 || t[r] === null)
318
330
  continue;
319
- const c = t[r];
320
- if (Array.isArray(c)) {
321
- e = e.replace(n, B(r, c, { style: l, explode: i }));
331
+ const u = t[r];
332
+ if (Array.isArray(u)) {
333
+ e = e.replace(o, W(r, u, { style: l, explode: i }));
322
334
  continue;
323
335
  }
324
- if (typeof c == "object") {
325
- e = e.replace(n, M(r, c, { style: l, explode: i }));
336
+ if (typeof u == "object") {
337
+ e = e.replace(o, F(r, u, { style: l, explode: i }));
326
338
  continue;
327
339
  }
328
340
  if (l === "matrix") {
329
- e = e.replace(n, `;${A(r, c)}`);
341
+ e = e.replace(o, `;${A(r, u)}`);
330
342
  continue;
331
343
  }
332
- e = e.replace(n, l === "label" ? `.${encodeURIComponent(c)}` : encodeURIComponent(c));
344
+ e = e.replace(o, l === "label" ? `.${encodeURIComponent(u)}` : encodeURIComponent(u));
333
345
  }
334
346
  return e;
335
347
  }
336
- function X(o, t) {
337
- return o instanceof FormData ? o : t && (t.get instanceof Function ? t.get("Content-Type") ?? t.get("content-type") : t["Content-Type"] ?? t["content-type"]) === "application/x-www-form-urlencoded" ? new URLSearchParams(o).toString() : JSON.stringify(o);
348
+ function te(n, t) {
349
+ return n instanceof FormData ? n : t && (t.get instanceof Function ? t.get("Content-Type") ?? t.get("content-type") : t["Content-Type"] ?? t["content-type"]) === "application/x-www-form-urlencoded" ? new URLSearchParams(n).toString() : JSON.stringify(n);
338
350
  }
339
- function Y(o, t) {
340
- let e = `${t.baseUrl}${o}`;
341
- t.params?.path && (e = V(e, t.params.path));
342
- let n = t.querySerializer(t.params.query ?? {});
343
- return n.startsWith("?") && (n = n.substring(1)), n && (e += `?${n}`), e;
351
+ function re(n, t) {
352
+ let e = `${t.baseUrl}${n}`;
353
+ t.params?.path && (e = t.pathSerializer(e, t.params.path));
354
+ let o = t.querySerializer(t.params.query ?? {});
355
+ return o.startsWith("?") && (o = o.substring(1)), o && (e += `?${o}`), e;
344
356
  }
345
- function k(...o) {
357
+ function N(...n) {
346
358
  const t = new Headers();
347
- for (const e of o) {
359
+ for (const e of n) {
348
360
  if (!e || typeof e != "object")
349
361
  continue;
350
- const n = e instanceof Headers ? e.entries() : Object.entries(e);
351
- for (const [r, i] of n)
362
+ const o = e instanceof Headers ? e.entries() : Object.entries(e);
363
+ for (const [r, i] of o)
352
364
  if (i === null)
353
365
  t.delete(r);
354
366
  else if (Array.isArray(i))
@@ -358,20 +370,20 @@ function k(...o) {
358
370
  }
359
371
  return t;
360
372
  }
361
- function L(o) {
362
- return o.endsWith("/") ? o.substring(0, o.length - 1) : o;
373
+ function B(n) {
374
+ return n.endsWith("/") ? n.substring(0, n.length - 1) : n;
363
375
  }
364
- function Z(o) {
365
- const t = {
366
- async onRequest({ request: n }) {
367
- const r = await o.getCredentials();
368
- return n.headers.set("Authorization", `Bearer ${r.token}`), (n.method === "POST" || n.method === "PATCH" || n.method === "DELETE") && n.headers.set("Content-Type", "application/vnd.api+json"), n;
376
+ function ne(n, t = "https://openapi.tidal.com/v2/") {
377
+ const e = {
378
+ async onRequest({ request: r }) {
379
+ const i = await n.getCredentials();
380
+ return r.headers.set("Authorization", `Bearer ${i.token}`), (r.method === "POST" || r.method === "PATCH" || r.method === "DELETE") && r.headers.set("Content-Type", "application/vnd.api+json"), r;
369
381
  }
370
- }, e = K({
371
- baseUrl: "https://openapi.tidal.com/v2/"
382
+ }, o = Z({
383
+ baseUrl: t
372
384
  });
373
- return e.use(t), e;
385
+ return o.use(e), o;
374
386
  }
375
387
  export {
376
- Z as createAPIClient
388
+ ne as createAPIClient
377
389
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-music/api",
3
- "version": "0.7.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -17,19 +17,19 @@
17
17
  "default": "./dist/index.js"
18
18
  },
19
19
  "dependencies": {
20
- "openapi-fetch": "0.15.0",
21
- "@tidal-music/api": "0.7.0"
20
+ "openapi-fetch": "0.17.0",
21
+ "@tidal-music/api": "0.9.1"
22
22
  },
23
23
  "devDependencies": {
24
- "@vitest/coverage-v8": "4.0.14",
25
- "@vitest/ui": "4.0.14",
26
- "openapi-typescript": "7.10.1",
24
+ "@vitest/coverage-v8": "4.0.18",
25
+ "@vitest/ui": "4.0.18",
26
+ "openapi-typescript": "7.13.0",
27
27
  "typescript": "5.9.3",
28
- "vite": "7.2.6",
28
+ "vite": "7.3.1",
29
29
  "vite-plugin-dts": "4.5.4",
30
- "vitest": "4.0.14",
31
- "@tidal-music/common": "^0.2.0",
32
- "@tidal-music/auth": "^1.4.0"
30
+ "vitest": "4.0.18",
31
+ "@tidal-music/auth": "^1.4.0",
32
+ "@tidal-music/common": "^0.2.0"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "vite build",