javascript-ampache 1.1.9 → 1.2.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.
@@ -57,6 +57,7 @@ export declare class Playlists extends Base {
57
57
  * This returns a user's playlists based on the specified filter
58
58
  * @remarks MINIMUM_API_VERSION=6.3.0
59
59
  * @param [params.filter] Filter results to match this string
60
+ * @param [params.include] 0, 1 (include playlist items)
60
61
  * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
61
62
  * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
62
63
  * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
@@ -68,6 +69,7 @@ export declare class Playlists extends Base {
68
69
  */
69
70
  userPlaylists(params?: {
70
71
  filter?: string;
72
+ include?: BinaryBoolean;
71
73
  exact?: BinaryBoolean;
72
74
  add?: Date;
73
75
  update?: Date;
@@ -76,6 +78,7 @@ export declare class Playlists extends Base {
76
78
  * This returns a user's smartlists based on the specified filter
77
79
  * @remarks MINIMUM_API_VERSION=6.3.0
78
80
  * @param [params.filter] Filter results to match this string
81
+ * @param [params.include] 0, 1 (include playlist items)
79
82
  * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
80
83
  * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
81
84
  * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
@@ -87,6 +90,7 @@ export declare class Playlists extends Base {
87
90
  */
88
91
  userSmartlists(params?: {
89
92
  filter?: string;
93
+ include?: BinaryBoolean;
90
94
  exact?: BinaryBoolean;
91
95
  add?: Date;
92
96
  update?: Date;
@@ -108,10 +108,13 @@ export declare class Songs extends Base {
108
108
  /**
109
109
  * Get the full song file tags using VaInfo
110
110
  * This is used to get tags for remote catalogs to allow maximum data to be returned
111
- * @remarks MINIMUM_API_VERSION=7.5.0
111
+ * @remarks MINIMUM_API_VERSION=6.7.0
112
112
  * @param params.filter UID of song to fetch
113
113
  * @see {@link https://ampache.org/api/api-json-methods#song_tags}
114
114
  */
115
+ songTags(params: {
116
+ filter: UID;
117
+ }): Promise<unknown>;
115
118
  /**
116
119
  * This takes a URL and returns the song object in question
117
120
  * @remarks MINIMUM_API_VERSION=380001
@@ -1,5 +1,5 @@
1
1
  import { Base, BinaryBoolean, ExtendedPagination, Pagination, Success, UID } from "../base";
2
- import { IndexEntry, NowPlayingResponse } from "./types";
2
+ import { IndexEntry, NowPlayingResponse, RuleResponse } from "./types";
3
3
  export declare class System extends Base {
4
4
  /**
5
5
  * Check Ampache for updates and run the update if there is one.
@@ -102,6 +102,7 @@ export declare class System extends Base {
102
102
  catalog?: number;
103
103
  add?: Date;
104
104
  update?: Date;
105
+ cond?: string;
105
106
  } & ExtendedPagination): Promise<{
106
107
  browse: IndexEntry[];
107
108
  }>;
@@ -361,6 +362,17 @@ export declare class System extends Base {
361
362
  }): Promise<{
362
363
  now_playing: NowPlayingResponse[];
363
364
  }>;
365
+ /**
366
+ * Print a list of valid search rules for your search type
367
+ * @remarks MINIMUM_API_VERSION=6.8.0
368
+ * @param params.filter Object type
369
+ * @see {@link https://ampache.org/api/api-json-methods#search_rules}
370
+ */
371
+ searchRules(params: {
372
+ filter: "song" | "album" | "song_artist" | "album_artist" | "artist" | "label" | "playlist" | "podcast" | "podcast_episode" | "genre" | "user" | "video";
373
+ }): Promise<{
374
+ rule: RuleResponse[];
375
+ }>;
364
376
  /**
365
377
  * Perform an advanced search given passed rules.
366
378
  * You'll want to consult the docs for this.
@@ -22,3 +22,10 @@ export type NowPlayingResponse = {
22
22
  expire: number;
23
23
  user: UserSummary;
24
24
  };
25
+ export type RuleResponse = {
26
+ name: string;
27
+ label: string;
28
+ type: string;
29
+ title: string;
30
+ widget: string[];
31
+ };
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import { Base } from "./base";
1
2
  export declare function applyMixins(derivedCtor: any, baseCtors: any[]): void;
2
3
  export declare function encryptPassword(password: string, time: number): string;
4
+ export declare function outputDebugURL(url: string, config: Base): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-ampache",
3
- "version": "1.1.9",
3
+ "version": "1.2.0",
4
4
  "description": "A JS library for the Ampache API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.m.js",
package/src/auth/index.ts CHANGED
@@ -3,6 +3,7 @@ import qs from "querystringify";
3
3
  import fetch from "isomorphic-unfetch";
4
4
  import { Base, Success } from "../base";
5
5
  import { AuthResponse } from "./types";
6
+ import { outputDebugURL } from "../utils";
6
7
 
7
8
  export class Auth extends Base {
8
9
  /**
@@ -20,6 +21,8 @@ export class Auth extends Base {
20
21
  timestamp?: number;
21
22
  version?: string;
22
23
  }) {
24
+ let token = params.auth;
25
+
23
26
  // generate a timestamp if one wasn't provided
24
27
  if (!params.timestamp) {
25
28
  params.timestamp = Math.floor(new Date().getTime() / 1000);
@@ -35,10 +38,22 @@ export class Auth extends Base {
35
38
  delete params.timestamp;
36
39
  }
37
40
 
41
+ // not needed if using Bearer token
42
+ if (this.useBearerToken) {
43
+ delete params.auth;
44
+ }
45
+
38
46
  let query = this.url + "/server/json.server.php?action=handshake";
39
47
  query += qs.stringify(params, "&");
40
48
 
41
- return fetch(query)
49
+ if (this.debug) {
50
+ outputDebugURL(query, this);
51
+ }
52
+
53
+ return fetch(query, {
54
+ method: "GET",
55
+ headers: this.useBearerToken ? { Authorization: "Bearer " + token } : {},
56
+ })
42
57
  .then((response) => response.json())
43
58
  .then((data) => {
44
59
  if (data.auth) {
package/src/base.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import fetch from "isomorphic-unfetch";
2
2
  import qs from "querystringify";
3
+ import { outputDebugURL } from "./utils";
3
4
 
4
5
  type Config = {
5
6
  url: string;
6
7
  sessionKey?: string;
7
- useBearerToken: false;
8
+ useBearerToken?: boolean;
8
9
  debug?: boolean;
9
10
  };
10
11
 
@@ -51,7 +52,6 @@ export abstract class Base {
51
52
  }
52
53
 
53
54
  protected request<T>(endpoint: string): Promise<T> {
54
- let authString = "&auth=" + this.sessionKey;
55
55
  let url =
56
56
  this.url +
57
57
  "/server/json.server.php?action=" +
@@ -60,21 +60,16 @@ export abstract class Base {
60
60
  this.version;
61
61
 
62
62
  if (!this.useBearerToken) {
63
- url += authString;
63
+ url += "&auth=" + this.sessionKey;
64
64
  }
65
65
 
66
66
  if (this.debug) {
67
- console.debug(
68
- "javascript-ampache query URL %c" + url,
69
- "color: black; font-style: italic; background-color: orange;padding: 2px",
70
- );
67
+ outputDebugURL(url, this);
71
68
  }
72
69
 
73
70
  return fetch(url, {
74
71
  method: "GET",
75
- headers: {
76
- Authorization: this.useBearerToken ? "Bearer " + this.sessionKey : undefined,
77
- },
72
+ headers: this.useBearerToken ? { Authorization: "Bearer " + this.sessionKey } : {},
78
73
  }).then((r) => {
79
74
  if (r.ok) {
80
75
  return r.json();
@@ -84,28 +79,22 @@ export abstract class Base {
84
79
  }
85
80
 
86
81
  protected binary<T>(endpoint: string): Promise<Blob> {
87
- let authString = "&auth=" + this.sessionKey;
88
82
  let url =
89
83
  this.url +
90
84
  "/server/json.server.php?action=" + endpoint +
91
85
  "&version=" + this.version;
92
86
 
93
87
  if (!this.useBearerToken) {
94
- url += authString;
88
+ url += "&auth=" + this.sessionKey;
95
89
  }
96
90
 
97
91
  if (this.debug) {
98
- console.debug(
99
- "javascript-ampache query URL %c" + url,
100
- "color: black; font-style: italic; background-color: orange;padding: 2px",
101
- );
92
+ outputDebugURL(url, this);
102
93
  }
103
94
 
104
95
  return fetch(url, {
105
96
  method: "GET",
106
- headers: {
107
- Authorization: this.useBearerToken ? "Bearer " + this.sessionKey : undefined,
108
- },
97
+ headers: this.useBearerToken ? { Authorization: "Bearer " + this.sessionKey } : {},
109
98
  })
110
99
  .then((response) => response.blob())
111
100
  .then((r) => {
@@ -123,7 +112,6 @@ export abstract class Base {
123
112
  * @param [params]
124
113
  */
125
114
  public rawURL(endpoint: string, params?: {}) {
126
- let authString = "&auth=" + this.sessionKey;
127
115
  let query = endpoint;
128
116
  query += qs.stringify(params, "&");
129
117
 
@@ -133,14 +121,11 @@ export abstract class Base {
133
121
  "&version=" + this.version;
134
122
 
135
123
  if (!this.useBearerToken) {
136
- url += authString;
124
+ url += "&auth=" + this.sessionKey;
137
125
  }
138
126
 
139
127
  if (this.debug) {
140
- console.debug(
141
- "javascript-ampache query URL %c" + url,
142
- "color: black; font-style: italic; background-color: orange;padding: 2px",
143
- );
128
+ outputDebugURL(url, this);
144
129
  }
145
130
 
146
131
  return url;
@@ -89,6 +89,7 @@ export class Playlists extends Base {
89
89
  * This returns a user's playlists based on the specified filter
90
90
  * @remarks MINIMUM_API_VERSION=6.3.0
91
91
  * @param [params.filter] Filter results to match this string
92
+ * @param [params.include] 0, 1 (include playlist items)
92
93
  * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
93
94
  * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
94
95
  * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
@@ -101,6 +102,7 @@ export class Playlists extends Base {
101
102
  userPlaylists(
102
103
  params?: {
103
104
  filter?: string;
105
+ include?: BinaryBoolean;
104
106
  exact?: BinaryBoolean;
105
107
  add?: Date;
106
108
  update?: Date;
@@ -115,6 +117,7 @@ export class Playlists extends Base {
115
117
  * This returns a user's smartlists based on the specified filter
116
118
  * @remarks MINIMUM_API_VERSION=6.3.0
117
119
  * @param [params.filter] Filter results to match this string
120
+ * @param [params.include] 0, 1 (include playlist items)
118
121
  * @param [params.exact] 0, 1 (if true filter is exact = rather than fuzzy LIKE)
119
122
  * @param [params.add] ISO 8601 Date Format (2020-09-16) Find objects with an 'add' date newer than the specified date
120
123
  * @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
@@ -127,6 +130,7 @@ export class Playlists extends Base {
127
130
  userSmartlists(
128
131
  params?: {
129
132
  filter?: string;
133
+ include?: BinaryBoolean;
130
134
  exact?: BinaryBoolean;
131
135
  add?: Date;
132
136
  update?: Date;
@@ -165,15 +165,15 @@ export class Songs extends Base {
165
165
  /**
166
166
  * Get the full song file tags using VaInfo
167
167
  * This is used to get tags for remote catalogs to allow maximum data to be returned
168
- * @remarks MINIMUM_API_VERSION=7.5.0
168
+ * @remarks MINIMUM_API_VERSION=6.7.0
169
169
  * @param params.filter UID of song to fetch
170
170
  * @see {@link https://ampache.org/api/api-json-methods#song_tags}
171
171
  */
172
- // songTags(params: { filter: UID }) {
173
- // let query = "song_tags";
174
- // query += qs.stringify(params, "&");
175
- // return this.request<SongResponse>(query); // TODO update reponse
176
- // }
172
+ songTags(params: { filter: UID }) {
173
+ let query = "song_tags";
174
+ query += qs.stringify(params, "&");
175
+ return this.request(query); // TODO response type
176
+ }
177
177
 
178
178
  /**
179
179
  * This takes a URL and returns the song object in question
@@ -22,7 +22,7 @@ import { LiveStreamsResponse } from "../live-streams/types";
22
22
  import { LabelResponse, LabelsResponse } from "../labels/types";
23
23
  import { GenreResponse, GenresResponse } from "../genres/types";
24
24
  import { UserResponse, UsersResponse } from "../users/types";
25
- import { IndexEntry, NowPlayingResponse } from "./types";
25
+ import { IndexEntry, NowPlayingResponse, RuleResponse } from "./types";
26
26
 
27
27
  export class System extends Base {
28
28
  /**
@@ -209,6 +209,7 @@ export class System extends Base {
209
209
  catalog?: number;
210
210
  add?: Date;
211
211
  update?: Date;
212
+ cond?: string;
212
213
  } & ExtendedPagination,
213
214
  ) {
214
215
  let query = "browse";
@@ -637,6 +638,20 @@ export class System extends Base {
637
638
  return this.request<{ now_playing: NowPlayingResponse[] }>(query);
638
639
  }
639
640
 
641
+ /**
642
+ * Print a list of valid search rules for your search type
643
+ * @remarks MINIMUM_API_VERSION=6.8.0
644
+ * @param params.filter Object type
645
+ * @see {@link https://ampache.org/api/api-json-methods#search_rules}
646
+ */
647
+ searchRules(params: {
648
+ filter: "song" | "album" | "song_artist" | "album_artist" | "artist" | "label" | "playlist" | "podcast" | "podcast_episode" | "genre" | "user" | "video";
649
+ }) {
650
+ let query = "search_rules";
651
+ query += qs.stringify(params, "&");
652
+ return this.request<{ rule: RuleResponse[] }>(query);
653
+ }
654
+
640
655
  /**
641
656
  * Perform an advanced search given passed rules.
642
657
  * You'll want to consult the docs for this.
@@ -39,4 +39,12 @@ export type NowPlayingResponse = {
39
39
  client: string;
40
40
  expire: number;
41
41
  user: UserSummary;
42
+ }
43
+
44
+ export type RuleResponse = {
45
+ name: string;
46
+ label: string;
47
+ type: string;
48
+ title: string;
49
+ widget: string[];
42
50
  }
package/src/utils.ts CHANGED
@@ -1,25 +1,40 @@
1
- import JsSHA from "jssha/dist/sha256";
2
-
3
- export function applyMixins(derivedCtor: any, baseCtors: any[]) {
4
- baseCtors.forEach((baseCtor) => {
5
- Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
6
- Object.defineProperty(
7
- derivedCtor.prototype,
8
- name,
9
- Object.getOwnPropertyDescriptor(baseCtor.prototype, name),
10
- );
11
- });
12
- });
13
- }
14
-
15
- export function encryptPassword(password: string, time: number) {
16
- let key = getSHA256(password);
17
- return getSHA256(time + key);
18
-
19
- function getSHA256(text) {
20
- let shaObj = new JsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
21
- shaObj.update(text);
22
-
23
- return shaObj.getHash("HEX");
24
- }
25
- }
1
+ import JsSHA from "jssha/dist/sha256";
2
+ import { Base } from "./base";
3
+
4
+ export function applyMixins(derivedCtor: any, baseCtors: any[]) {
5
+ baseCtors.forEach((baseCtor) => {
6
+ Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
7
+ Object.defineProperty(
8
+ derivedCtor.prototype,
9
+ name,
10
+ Object.getOwnPropertyDescriptor(baseCtor.prototype, name),
11
+ );
12
+ });
13
+ });
14
+ }
15
+
16
+ export function encryptPassword(password: string, time: number) {
17
+ let key = getSHA256(password);
18
+ return getSHA256(time + key);
19
+
20
+ function getSHA256(text) {
21
+ let shaObj = new JsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
22
+ shaObj.update(text);
23
+
24
+ return shaObj.getHash("HEX");
25
+ }
26
+ }
27
+
28
+ export function outputDebugURL(url: string, config: Base) {
29
+ let label = "javascript-ampache query URL";
30
+
31
+ if (config.useBearerToken) {
32
+ label = "(Using Bearer token, auth added for debugging) - " + label;
33
+ url += "&auth=" + config.sessionKey;
34
+ }
35
+
36
+ console.debug(
37
+ label + " %c" + url,
38
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
39
+ );
40
+ }