javascript-ampache 1.0.9 → 1.1.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 (86) hide show
  1. package/README.md +50 -47
  2. package/dist/albums/index.d.ts +7 -13
  3. package/dist/albums/types.d.ts +9 -4
  4. package/dist/artists/index.d.ts +8 -14
  5. package/dist/artists/types.d.ts +10 -5
  6. package/dist/auth/index.d.ts +1 -1
  7. package/dist/base.d.ts +5 -0
  8. package/dist/bookmarks/index.d.ts +20 -21
  9. package/dist/bookmarks/types.d.ts +7 -2
  10. package/dist/catalogs/index.d.ts +9 -11
  11. package/dist/catalogs/types.d.ts +8 -3
  12. package/dist/genres/index.d.ts +4 -6
  13. package/dist/genres/types.d.ts +6 -1
  14. package/dist/index.d.ts +19 -19
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.m.js +1 -1
  18. package/dist/index.m.js.map +1 -1
  19. package/dist/index.modern.mjs +1 -1
  20. package/dist/index.modern.mjs.map +1 -1
  21. package/dist/index.umd.js +1 -1
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/labels/index.d.ts +4 -6
  24. package/dist/labels/types.d.ts +6 -1
  25. package/dist/licenses/index.d.ts +4 -6
  26. package/dist/licenses/types.d.ts +6 -1
  27. package/dist/live-streams/index.d.ts +8 -10
  28. package/dist/live-streams/types.d.ts +6 -1
  29. package/dist/playlists/index.d.ts +15 -25
  30. package/dist/playlists/types.d.ts +7 -2
  31. package/dist/podcasts/index.d.ts +10 -16
  32. package/dist/podcasts/types.d.ts +20 -5
  33. package/dist/preferences/index.d.ts +8 -16
  34. package/dist/preferences/types.d.ts +6 -1
  35. package/dist/shares/index.d.ts +7 -9
  36. package/dist/shares/types.d.ts +6 -1
  37. package/dist/shouts/index.d.ts +4 -4
  38. package/dist/shouts/types.d.ts +1 -1
  39. package/dist/songs/index.d.ts +12 -28
  40. package/dist/songs/types.d.ts +12 -2
  41. package/dist/system/index.d.ts +24 -24
  42. package/dist/system/types.d.ts +9 -9
  43. package/dist/users/index.d.ts +10 -10
  44. package/dist/users/types.d.ts +7 -2
  45. package/dist/videos/index.d.ts +5 -9
  46. package/dist/videos/types.d.ts +12 -2
  47. package/package.json +38 -38
  48. package/src/albums/index.ts +86 -86
  49. package/src/albums/types.ts +38 -32
  50. package/src/artists/index.ts +88 -88
  51. package/src/artists/types.ts +38 -32
  52. package/src/auth/index.ts +103 -103
  53. package/src/auth/types.ts +25 -25
  54. package/src/base.ts +134 -119
  55. package/src/bookmarks/index.ts +116 -122
  56. package/src/bookmarks/types.ts +15 -9
  57. package/src/catalogs/index.ts +130 -119
  58. package/src/catalogs/types.ts +27 -15
  59. package/src/genres/index.ts +39 -40
  60. package/src/genres/types.ts +23 -17
  61. package/src/index.ts +63 -26
  62. package/src/labels/index.ts +43 -44
  63. package/src/labels/types.ts +20 -14
  64. package/src/licenses/index.ts +43 -44
  65. package/src/licenses/types.ts +14 -8
  66. package/src/live-streams/index.ts +104 -107
  67. package/src/live-streams/types.ts +16 -10
  68. package/src/playlists/index.ts +262 -269
  69. package/src/playlists/types.ts +20 -14
  70. package/src/podcasts/index.ts +174 -177
  71. package/src/podcasts/types.ts +85 -67
  72. package/src/preferences/index.ts +114 -116
  73. package/src/preferences/types.ts +18 -12
  74. package/src/shares/index.ts +100 -96
  75. package/src/shares/types.ts +25 -19
  76. package/src/shouts/index.ts +18 -22
  77. package/src/shouts/types.ts +9 -9
  78. package/src/songs/index.ts +208 -203
  79. package/src/songs/types.ts +77 -65
  80. package/src/system/index.ts +689 -572
  81. package/src/system/types.ts +33 -19
  82. package/src/users/index.ts +227 -245
  83. package/src/users/types.ts +38 -32
  84. package/src/utils.ts +25 -25
  85. package/src/videos/index.ts +49 -53
  86. 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,119 +1,134 @@
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 = this.url + "/server/json.server.php?action=" + endpoint + "&version=" + this.version;
52
-
53
- if (this.debug) {
54
- console.debug(
55
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
56
- "color: black; font-style: italic; background-color: orange;padding: 2px"
57
- );
58
- }
59
-
60
- return fetch(url, {
61
- method: "GET",
62
- headers: {
63
- 'Authorization': 'Bearer ' + this.sessionKey
64
- }
65
- }).then(r => {
66
- if (r.ok) {
67
- return r.json();
68
- }
69
- throw new Error(r.statusText);
70
- })
71
- }
72
-
73
- protected binary<T> (endpoint: string): Promise<Blob> {
74
- let url = this.url + "/server/json.server.php?action=" + endpoint + "&version=" + this.version;
75
-
76
- if (this.debug) {
77
- console.debug(
78
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
79
- "color: black; font-style: italic; background-color: orange;padding: 2px"
80
- );
81
- }
82
-
83
- return fetch(url,{
84
- method: "GET",
85
- headers: {
86
- 'Authorization': 'Bearer ' + this.sessionKey
87
- }
88
- })
89
- .then(response => response.blob())
90
- .then(r => {
91
- return r;
92
- })
93
- }
94
-
95
- public setSessionKey(sessionKey: string) {
96
- this.sessionKey = sessionKey;
97
- }
98
-
99
- /**
100
- * Construct and return a URL
101
- * @param endpoint
102
- * @param [params]
103
- */
104
- public rawURL(endpoint: string, params?: {}) {
105
- let query = endpoint;
106
- query += qs.stringify(params, '&');
107
-
108
- let url = this.url + "/server/json.server.php?action=" + query + "&version=" + this.version;
109
-
110
- if (this.debug) {
111
- console.debug(
112
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
113
- "color: black; font-style: italic; background-color: orange;padding: 2px"
114
- );
115
- }
116
-
117
- return url;
118
- }
119
- }
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
+ }