javascript-ampache 1.0.8 → 1.1.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.
Files changed (50) hide show
  1. package/README.md +50 -47
  2. package/dist/base.d.ts +6 -0
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.m.js +1 -1
  6. package/dist/index.m.js.map +1 -1
  7. package/dist/index.modern.mjs +1 -1
  8. package/dist/index.modern.mjs.map +1 -1
  9. package/dist/index.umd.js +1 -1
  10. package/dist/index.umd.js.map +1 -1
  11. package/package.json +38 -38
  12. package/src/albums/index.ts +86 -86
  13. package/src/albums/types.ts +38 -32
  14. package/src/artists/index.ts +88 -88
  15. package/src/artists/types.ts +38 -32
  16. package/src/auth/index.ts +103 -103
  17. package/src/auth/types.ts +25 -25
  18. package/src/base.ts +134 -97
  19. package/src/bookmarks/index.ts +115 -122
  20. package/src/bookmarks/types.ts +15 -9
  21. package/src/catalogs/index.ts +130 -119
  22. package/src/catalogs/types.ts +27 -15
  23. package/src/genres/index.ts +39 -40
  24. package/src/genres/types.ts +23 -17
  25. package/src/index.ts +63 -26
  26. package/src/labels/index.ts +43 -44
  27. package/src/labels/types.ts +20 -14
  28. package/src/licenses/index.ts +43 -44
  29. package/src/licenses/types.ts +14 -8
  30. package/src/live-streams/index.ts +104 -107
  31. package/src/live-streams/types.ts +16 -10
  32. package/src/playlists/index.ts +264 -269
  33. package/src/playlists/types.ts +20 -14
  34. package/src/podcasts/index.ts +174 -177
  35. package/src/podcasts/types.ts +85 -67
  36. package/src/preferences/index.ts +114 -116
  37. package/src/preferences/types.ts +18 -12
  38. package/src/shares/index.ts +100 -96
  39. package/src/shares/types.ts +25 -19
  40. package/src/shouts/index.ts +18 -22
  41. package/src/shouts/types.ts +9 -9
  42. package/src/songs/index.ts +208 -203
  43. package/src/songs/types.ts +77 -65
  44. package/src/system/index.ts +689 -572
  45. package/src/system/types.ts +33 -19
  46. package/src/users/index.ts +227 -245
  47. package/src/users/types.ts +38 -32
  48. package/src/utils.ts +25 -25
  49. package/src/videos/index.ts +49 -53
  50. package/src/videos/types.ts +42 -30
package/src/auth/index.ts CHANGED
@@ -1,103 +1,103 @@
1
- import JsSHA from "jssha/dist/sha256";
2
- import qs from 'querystringify';
3
- import fetch from "isomorphic-unfetch";
4
- import { Base, Success } from "../base";
5
- import { AuthResponse } from './types'
6
-
7
- export class Auth extends Base {
8
- /**
9
- * Handles verifying a new handshake
10
- * @remarks MINIMUM_API_VERSION=380001
11
- * @param params.auth encrypted apikey OR password if using password auth
12
- * @param [params.user] username
13
- * @param [params.timestamp] UNIXTIME()
14
- * @param [params.version] version of Ampache API to establish connection with
15
- * @see {@link https://ampache.org/api/api-json-methods#handshake}
16
- */
17
- handshake (params: {
18
- auth: string,
19
- user?: string,
20
- timestamp?: number,
21
- version?: string
22
- }) {
23
- // generate a timestamp if one wasn't provided
24
- if (!params.timestamp) {
25
- params.timestamp = Math.floor(new Date().getTime() / 1000);
26
- }
27
-
28
- // override the fallback API version with specified
29
- if (params.version) {
30
- this.version = params.version;
31
- }
32
-
33
- // drop timestamp if no user provided (i.e. logging in with API key)
34
- if (!params.user) {
35
- delete params.timestamp;
36
- }
37
-
38
- let query = this.url + "/server/json.server.php?action=handshake";
39
- query += qs.stringify(params, '&');
40
-
41
- return fetch(query)
42
- .then(response => response.json())
43
- .then(data => {
44
- if (data.auth) {
45
- this.sessionKey = data.auth;
46
- }
47
- return <AuthResponse>data;
48
- })
49
- }
50
-
51
- /**
52
- * This can be called without being authenticated, it is useful for determining if what the status
53
- * of the server is, and what version it is running/compatible with
54
- * @remarks MINIMUM_API_VERSION=380001
55
- * @param [params.auth] (Session ID) returns version information and extends the session if passed
56
- * @param [params.version] API Version that the application understands
57
- * @see {@link https://ampache.org/api/api-json-methods#ping}
58
- */
59
- ping (params?: { auth?: string, version?: string }) {
60
- let query = 'ping';
61
- query += qs.stringify(params, '&');
62
- return this.request<AuthResponse>(query);
63
- }
64
-
65
- /**
66
- * Destroy a session using the session auth parameter
67
- * @remarks MINIMUM_API_VERSION=400001
68
- * @param params.auth Session ID to destroy
69
- * @see {@link https://ampache.org/api/api-json-methods#goodbye}
70
- */
71
- goodbye (params: { auth: string }) {
72
- let query = 'goodbye';
73
- query += qs.stringify(params, '&');
74
- return this.request<Success>(query);
75
- }
76
-
77
- /**
78
- * Email a new password to the user (if allowed) using a reset token.
79
- * @remarks MINIMUM_API_VERSION=6.1.0
80
- * @param params.auth Password reset token
81
- * @see {@link https://ampache.org/api/api-json-methods#lost_password}
82
- */
83
- lostPassword (params: { auth: string }) {
84
- let query = 'lost_password';
85
- query += qs.stringify(params, '&');
86
- return this.request<Success>(query);
87
- }
88
-
89
- /**
90
- * Encrypt your password into the accepted format.
91
- */
92
- encryptPassword (params: { password: string, time: number }) {
93
- let key = getSHA256(params.password);
94
- return getSHA256(params.time + key);
95
-
96
- function getSHA256(text) {
97
- let shaObj = new JsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
98
- shaObj.update(text);
99
-
100
- return shaObj.getHash("HEX");
101
- }
102
- }
103
- }
1
+ import JsSHA from "jssha/dist/sha256";
2
+ import qs from "querystringify";
3
+ import fetch from "isomorphic-unfetch";
4
+ import { Base, Success } from "../base";
5
+ import { AuthResponse } from "./types";
6
+
7
+ export class Auth extends Base {
8
+ /**
9
+ * Handles verifying a new handshake
10
+ * @remarks MINIMUM_API_VERSION=380001
11
+ * @param params.auth encrypted apikey OR password if using password auth
12
+ * @param [params.user] username
13
+ * @param [params.timestamp] UNIXTIME()
14
+ * @param [params.version] version of Ampache API to establish connection with
15
+ * @see {@link https://ampache.org/api/api-json-methods#handshake}
16
+ */
17
+ handshake(params: {
18
+ auth: string;
19
+ user?: string;
20
+ timestamp?: number;
21
+ version?: string;
22
+ }) {
23
+ // generate a timestamp if one wasn't provided
24
+ if (!params.timestamp) {
25
+ params.timestamp = Math.floor(new Date().getTime() / 1000);
26
+ }
27
+
28
+ // override the fallback API version with specified
29
+ if (params.version) {
30
+ this.version = params.version;
31
+ }
32
+
33
+ // drop timestamp if no user provided (i.e. logging in with API key)
34
+ if (!params.user) {
35
+ delete params.timestamp;
36
+ }
37
+
38
+ let query = this.url + "/server/json.server.php?action=handshake";
39
+ query += qs.stringify(params, "&");
40
+
41
+ return fetch(query)
42
+ .then((response) => response.json())
43
+ .then((data) => {
44
+ if (data.auth) {
45
+ this.sessionKey = data.auth;
46
+ }
47
+ return <AuthResponse>data;
48
+ });
49
+ }
50
+
51
+ /**
52
+ * This can be called without being authenticated, it is useful for determining if what the status
53
+ * of the server is, and what version it is running/compatible with
54
+ * @remarks MINIMUM_API_VERSION=380001
55
+ * @param [params.auth] (Session ID) returns version information and extends the session if passed
56
+ * @param [params.version] API Version that the application understands
57
+ * @see {@link https://ampache.org/api/api-json-methods#ping}
58
+ */
59
+ ping(params?: { auth?: string; version?: string }) {
60
+ let query = "ping";
61
+ query += qs.stringify(params, "&");
62
+ return this.request<AuthResponse>(query);
63
+ }
64
+
65
+ /**
66
+ * Destroy a session using the session auth parameter
67
+ * @remarks MINIMUM_API_VERSION=400001
68
+ * @param params.auth Session ID to destroy
69
+ * @see {@link https://ampache.org/api/api-json-methods#goodbye}
70
+ */
71
+ goodbye(params: { auth: string }) {
72
+ let query = "goodbye";
73
+ query += qs.stringify(params, "&");
74
+ return this.request<Success>(query);
75
+ }
76
+
77
+ /**
78
+ * Email a new password to the user (if allowed) using a reset token.
79
+ * @remarks MINIMUM_API_VERSION=6.1.0
80
+ * @param params.auth Password reset token
81
+ * @see {@link https://ampache.org/api/api-json-methods#lost_password}
82
+ */
83
+ lostPassword(params: { auth: string }) {
84
+ let query = "lost_password";
85
+ query += qs.stringify(params, "&");
86
+ return this.request<Success>(query);
87
+ }
88
+
89
+ /**
90
+ * Encrypt your password into the accepted format.
91
+ */
92
+ encryptPassword(params: { password: string; time: number }) {
93
+ let key = getSHA256(params.password);
94
+ return getSHA256(params.time + key);
95
+
96
+ function getSHA256(text) {
97
+ let shaObj = new JsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
98
+ shaObj.update(text);
99
+
100
+ return shaObj.getHash("HEX");
101
+ }
102
+ }
103
+ }
package/src/auth/types.ts CHANGED
@@ -1,25 +1,25 @@
1
- export type AuthResponse = {
2
- add: string,
3
- albums: number,
4
- api: string,
5
- artists: number,
6
- auth: string,
7
- catalogs: number,
8
- compatible: string
9
- clean: string,
10
- genres: number,
11
- labels: number,
12
- licenses: number,
13
- live_streams: number,
14
- playlists: number,
15
- podcasts: number,
16
- podcast_episodes: number,
17
- server: string,
18
- session_expire: string,
19
- shares: number,
20
- songs: number,
21
- update: string,
22
- user: number,
23
- version: string,
24
- videos: number,
25
- }
1
+ export type AuthResponse = {
2
+ add: string;
3
+ albums: number;
4
+ api: string;
5
+ artists: number;
6
+ auth: string;
7
+ catalogs: number;
8
+ compatible: string;
9
+ clean: string;
10
+ genres: number;
11
+ labels: number;
12
+ licenses: number;
13
+ live_streams: number;
14
+ playlists: number;
15
+ podcasts: number;
16
+ podcast_episodes: number;
17
+ server: string;
18
+ session_expire: string;
19
+ shares: number;
20
+ songs: number;
21
+ update: string;
22
+ user: number;
23
+ version: string;
24
+ videos: number;
25
+ };
package/src/base.ts CHANGED
@@ -1,97 +1,134 @@
1
- import fetch from 'isomorphic-unfetch';
2
-
3
- type Config = {
4
- url: string,
5
- sessionKey?: string,
6
- debug?: boolean,
7
- }
8
-
9
- export type Success = {
10
- success: string,
11
- }
12
-
13
- /**
14
- * @param [offset] Return results starting from this index position
15
- * @param [limit] Maximum number of results to return
16
- */
17
- export type Pagination = {
18
- offset?: number,
19
- limit?: number,
20
- }
21
-
22
- /**
23
- * @param [offset] Return results starting from this index position
24
- * @param [limit] Maximum number of results to return
25
- * @param [cond] Apply additional filters to the browse using ; separated comma string pairs (e.g. 'filter1,value1;filter2,value2')
26
- * @param [sort] Sort name or comma-separated key pair. (e.g. 'name,order') Default order 'ASC' (e.g. 'name,ASC' == 'name')
27
- */
28
- export type ExtendedPagination = Pagination & {
29
- cond?: string,
30
- sort?: string,
31
- }
32
-
33
- export type BinaryBoolean = 0 | 1;
34
-
35
- export type UID = string | number;
36
-
37
- export abstract class Base {
38
- sessionKey: string;
39
- url: string;
40
- version: string = '6.3.0';// default to latest version
41
- debug: boolean;
42
-
43
- constructor(config: Config) {
44
- this.sessionKey = config.sessionKey || null;
45
- this.url = config.url;
46
- this.debug = config.debug || false;
47
- }
48
-
49
- protected request<T> (endpoint: string): Promise<T> {
50
- let url = this.url + "/server/json.server.php?action=" + endpoint + "&version=" + this.version;
51
-
52
- if (this.debug) {
53
- console.debug(
54
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
55
- "color: black; font-style: italic; background-color: orange;padding: 2px"
56
- );
57
- }
58
-
59
- return fetch(url, {
60
- method: "GET",
61
- headers: {
62
- 'Authorization': 'Bearer ' + this.sessionKey
63
- }
64
- }).then(r => {
65
- if (r.ok) {
66
- return r.json();
67
- }
68
- throw new Error(r.statusText);
69
- })
70
- }
71
-
72
- protected binary<T> (endpoint: string): Promise<Blob> {
73
- let url = this.url + "/server/json.server.php?action=" + endpoint + "&version=" + this.version;
74
-
75
- if (this.debug) {
76
- console.debug(
77
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
78
- "color: black; font-style: italic; background-color: orange;padding: 2px"
79
- );
80
- }
81
-
82
- return fetch(url,{
83
- method: "GET",
84
- headers: {
85
- 'Authorization': 'Bearer ' + this.sessionKey
86
- }
87
- })
88
- .then(response => response.blob())
89
- .then(r => {
90
- return r;
91
- })
92
- }
93
-
94
- public setSessionKey(sessionKey: string) {
95
- this.sessionKey = sessionKey;
96
- }
97
- }
1
+ import fetch from "isomorphic-unfetch";
2
+ import qs from "querystringify";
3
+
4
+ type Config = {
5
+ url: string;
6
+ sessionKey?: string;
7
+ debug?: boolean;
8
+ };
9
+
10
+ export type Success = {
11
+ success: string;
12
+ };
13
+
14
+ /**
15
+ * @param [offset] Return results starting from this index position
16
+ * @param [limit] Maximum number of results to return
17
+ */
18
+ export type Pagination = {
19
+ offset?: number;
20
+ limit?: number;
21
+ };
22
+
23
+ /**
24
+ * @param [offset] Return results starting from this index position
25
+ * @param [limit] Maximum number of results to return
26
+ * @param [cond] Apply additional filters to the browse using ; separated comma string pairs (e.g. 'filter1,value1;filter2,value2')
27
+ * @param [sort] Sort name or comma-separated key pair. (e.g. 'name,order') Default order 'ASC' (e.g. 'name,ASC' == 'name')
28
+ */
29
+ export type ExtendedPagination = Pagination & {
30
+ cond?: string;
31
+ sort?: string;
32
+ };
33
+
34
+ export type BinaryBoolean = 0 | 1;
35
+
36
+ export type UID = string | number;
37
+
38
+ export abstract class Base {
39
+ sessionKey: string;
40
+ url: string;
41
+ version: string = "6.3.0"; // default to latest version
42
+ debug: boolean;
43
+
44
+ constructor(config: Config) {
45
+ this.sessionKey = config.sessionKey || null;
46
+ this.url = config.url;
47
+ this.debug = config.debug || false;
48
+ }
49
+
50
+ protected request<T>(endpoint: string): Promise<T> {
51
+ let url =
52
+ this.url +
53
+ "/server/json.server.php?action=" +
54
+ endpoint +
55
+ "&version=" +
56
+ this.version;
57
+
58
+ if (this.debug) {
59
+ console.debug(
60
+ "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
61
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
62
+ );
63
+ }
64
+
65
+ return fetch(url, {
66
+ method: "GET",
67
+ headers: {
68
+ Authorization: "Bearer " + this.sessionKey,
69
+ },
70
+ }).then((r) => {
71
+ if (r.ok) {
72
+ return r.json();
73
+ }
74
+ throw new Error(r.statusText);
75
+ });
76
+ }
77
+
78
+ protected binary<T>(endpoint: string): Promise<Blob> {
79
+ let url =
80
+ this.url +
81
+ "/server/json.server.php?action=" +
82
+ endpoint +
83
+ "&version=" +
84
+ this.version;
85
+
86
+ if (this.debug) {
87
+ console.debug(
88
+ "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
89
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
90
+ );
91
+ }
92
+
93
+ return fetch(url, {
94
+ method: "GET",
95
+ headers: {
96
+ Authorization: "Bearer " + this.sessionKey,
97
+ },
98
+ })
99
+ .then((response) => response.blob())
100
+ .then((r) => {
101
+ return r;
102
+ });
103
+ }
104
+
105
+ public setSessionKey(sessionKey: string) {
106
+ this.sessionKey = sessionKey;
107
+ }
108
+
109
+ /**
110
+ * Construct and return a URL
111
+ * @param endpoint
112
+ * @param [params]
113
+ */
114
+ public rawURL(endpoint: string, params?: {}) {
115
+ let query = endpoint;
116
+ query += qs.stringify(params, "&");
117
+
118
+ let url =
119
+ this.url +
120
+ "/server/json.server.php?action=" +
121
+ query +
122
+ "&version=" +
123
+ this.version;
124
+
125
+ if (this.debug) {
126
+ console.debug(
127
+ "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
128
+ "color: black; font-style: italic; background-color: orange;padding: 2px",
129
+ );
130
+ }
131
+
132
+ return url;
133
+ }
134
+ }