Skip to content

Commit d2bbf99

Browse files
committed
Added typings.
1 parent 390c81a commit d2bbf99

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

index.d.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
declare module scjs {
2+
class ConManager {
3+
/**
4+
* A simple interface to Scala Content Manager web-services.
5+
*
6+
* This module is loosely modelled after the scws2 Python module, supporting the 2.x REST API.
7+
*
8+
* Example usage (set DEBUG=scjs for debug output):
9+
*
10+
* var scjs = require('scjs');
11+
*
12+
* var baseurl = "http://localhost/ContentManager";
13+
* var username = "user";
14+
* var password = "pass";
15+
* var cm = new scjs.ConManager(baseurl);
16+
* cm.login(username, password).then((resp) => {
17+
* cm.get('players', { 'limit': 0, 'offset': 0, 'fields': 'id,name,enabled,active,type' }).then((players) => {
18+
* console.log(players.list);
19+
* });
20+
* cm.get('media', { 'limit': 10, 'filters': '{"type":{"values":["IMAGE"]}}' }).then((media) => {
21+
* var p = Promise.resolve();
22+
* media.list.forEach((item) => {
23+
* p = p.then(cm.download(item.downloadPath, item.name));
24+
* });
25+
* });
26+
* cm.upload('LocalFolder/MyPicture.jpg', 'RemoteFolder/MyPicture.jpg').then((item) => {
27+
* console.log(item);
28+
* });
29+
* }).catch((e) => {
30+
* console.log(e);
31+
* });
32+
*
33+
* @param {string} baseurl - URL to Content Manager (http://server/ContentManager)
34+
* @param {string} token_name - (optional) Alternative token name, mainly for older (<10.2) Content Manager releases where token had a different name (token)
35+
* @return {function}
36+
* @api public
37+
*/
38+
constructor(baseurl: string, token_name?: string);
39+
40+
/**
41+
* Upload a Stream to Content Manager.
42+
*
43+
* @param {stream.Readable} rstream - Readable Stream
44+
* @param {string} cmpath - Relative path to file on Content Manager
45+
* @param {string} upload_type - (optional) Type of file upload (media_item|maint_item|auto) (defaults to auto)
46+
* @return {Promise}
47+
* @api public
48+
*/
49+
uploadStream(rstream: NodeJS.ReadableStream, cmpath: string, upload_type?: string): Promise<any>;
50+
51+
/**
52+
* Upload file to Content Manager.
53+
*
54+
* @param {string} file - Full path to local file
55+
* @param {string} cmpath - (optional) Relative path to file on Content Manager
56+
* @param {string} upload_type - (optional) Type of file upload (media_item|maint_item|auto) (defaults to auto)
57+
* @return {Promise}
58+
* @api public
59+
*/
60+
upload(file: string, cmpath?: string, upload_type?: string): Promise<any>;
61+
62+
/**
63+
* Download file from Content Manager as a Stream.
64+
*
65+
* @param {string} cmpath - Relative path to file on Content Manager
66+
* @return {stream.Readable}
67+
* @api public
68+
*/
69+
downloadStream(cmpath: string): NodeJS.ReadableStream;
70+
71+
/**
72+
* Download file from Content Manager.
73+
*
74+
* @param {string} cmpath - Relative path to file on Content Manager
75+
* @param {string} file - Local filename to store downloaded content in
76+
* @return {Promise}
77+
* @api public
78+
*/
79+
download(cmpath: string, file: string): Promise<any>;
80+
81+
/**
82+
* Log in to Content Manager (will automatically log out previously logged in user).
83+
*
84+
* @param {string} username
85+
* @param {string} password
86+
* @return {Promise}
87+
* @api public
88+
*/
89+
login(username: string, password: string): Promise<any>;
90+
91+
/**
92+
* API GET request.
93+
*
94+
* @param {string} endpoint - Endpoint path
95+
* @param {Object} data - Parameters
96+
* @return {Promise}
97+
* @api public
98+
*/
99+
get(endpoint: string, data: any): Promise<any>;
100+
101+
/**
102+
* API POST request.
103+
*
104+
* @param {string} endpoint - Endpoint path
105+
* @param {Object} data - Parameters
106+
* @return {Promise}
107+
* @api public
108+
*/
109+
post(endpoint: string, data: any): Promise<any>;
110+
111+
/**
112+
* API PUT request.
113+
*
114+
* @param {string} endpoint - Endpoint path
115+
* @param {Object} data - Parameters
116+
* @return {Promise}
117+
* @api public
118+
*/
119+
put(endpoint: string, data: any): Promise<any>;
120+
121+
/**
122+
* API DELETE request.
123+
*
124+
* @param {string} endpoint - Endpoint path
125+
* @param {Object} data - Parameters
126+
* @return {Promise}
127+
* @api public
128+
*/
129+
delete(endpoint: string, data: any): Promise<any>;
130+
131+
/**
132+
* Cached login response object.
133+
* @public
134+
*/
135+
login_response: any;
136+
}
137+
}
138+
139+
export = scjs;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scws2"
1010
],
1111
"main": "index.js",
12+
"typings": "index.d.ts",
1213
"author": "Sigbjørn Skjæret <[email protected]>",
1314
"repository": {
1415
"type": "git",

0 commit comments

Comments
 (0)