@hailer/cli 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.
- package/dist/client.d.ts +22 -8
- package/dist/client.js +32 -11
- package/dist/client.js.map +1 -1
- package/dist/commands/file-upload.js +2 -4
- package/dist/commands/file-upload.js.map +1 -1
- package/package.json +3 -3
- package/.claude/settings.local.json +0 -11
- package/doc/example/getting-started/src/bot.ts +0 -68
- package/doc/example/getting-started/src/upload.ts +0 -82
package/dist/client.d.ts
CHANGED
|
@@ -9,30 +9,42 @@ export interface ClientOptions {
|
|
|
9
9
|
host?: string;
|
|
10
10
|
/** Whether to reject unauthorized SSL certificates. Defaults to true for security */
|
|
11
11
|
rejectUnauthorized?: boolean;
|
|
12
|
+
/** User API key for authentication (alternative to username/password). Passed via authorization header. */
|
|
13
|
+
userApiKey?: string;
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* # Hailer Client
|
|
15
17
|
*
|
|
16
18
|
* Connect to Hailer and write your own integrations, bots or scripts.
|
|
17
19
|
*
|
|
18
|
-
* Example usage:
|
|
20
|
+
* Example usage with username/password:
|
|
19
21
|
*
|
|
20
22
|
* const { Client } = require('@hailer/cli');
|
|
21
23
|
*
|
|
22
|
-
* // wrap for await to work
|
|
23
24
|
* (async () => {
|
|
24
|
-
* const
|
|
25
|
+
* const client = await Client.create({
|
|
25
26
|
* host: 'https://api.hailer.biz', // defaults to https://api.hailer.com
|
|
26
27
|
* username: 'set-this',
|
|
27
28
|
* password: 'set-this',
|
|
28
|
-
* };
|
|
29
|
-
*
|
|
30
|
-
* const client = await Client.create(options);
|
|
29
|
+
* });
|
|
31
30
|
*
|
|
32
31
|
* const post = await client.request('wall2.new_post', [{ subject: 'This is a wall post.', text: 'The content of my post' }]);
|
|
33
|
-
*
|
|
34
32
|
* console.log('Post created:', post);
|
|
35
33
|
* })();
|
|
34
|
+
*
|
|
35
|
+
* Example usage with User API key:
|
|
36
|
+
*
|
|
37
|
+
* const { Client } = require('@hailer/cli');
|
|
38
|
+
*
|
|
39
|
+
* (async () => {
|
|
40
|
+
* const client = await Client.create({
|
|
41
|
+
* host: 'https://api.hailer.biz',
|
|
42
|
+
* userApiKey: 'userapikey_xxxxxxxx_yyyyyyyyyyyyyyyyyyyyyyyy',
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const data = await client.request('v2.core.init', []);
|
|
46
|
+
* console.log('Connected as:', data.user.email);
|
|
47
|
+
* })();
|
|
36
48
|
*/
|
|
37
49
|
export declare class Client extends EventEmitter {
|
|
38
50
|
/** Session key from login. Same as `hlrkey`-header used for HTTP requests */
|
|
@@ -42,11 +54,13 @@ export declare class Client extends EventEmitter {
|
|
|
42
54
|
username?: string;
|
|
43
55
|
password?: string;
|
|
44
56
|
rejectUnauthorized: boolean;
|
|
57
|
+
/** User API key for authentication */
|
|
58
|
+
userApiKey?: string;
|
|
45
59
|
private requestId;
|
|
46
60
|
private callbacks;
|
|
47
61
|
private socket?;
|
|
48
62
|
private constructor();
|
|
49
|
-
/** Creates Cli instance and logs in if username and password are given */
|
|
63
|
+
/** Creates Cli instance and logs in if username and password are given, or connects with user API key */
|
|
50
64
|
static create(options: ClientOptions): Promise<Client>;
|
|
51
65
|
request(
|
|
52
66
|
/** Operator / Endpoint, eg. `login` or `v3.discussion.message.star` */
|
package/dist/client.js
CHANGED
|
@@ -23,24 +23,34 @@ const file_upload_1 = require("./commands/file-upload");
|
|
|
23
23
|
*
|
|
24
24
|
* Connect to Hailer and write your own integrations, bots or scripts.
|
|
25
25
|
*
|
|
26
|
-
* Example usage:
|
|
26
|
+
* Example usage with username/password:
|
|
27
27
|
*
|
|
28
28
|
* const { Client } = require('@hailer/cli');
|
|
29
29
|
*
|
|
30
|
-
* // wrap for await to work
|
|
31
30
|
* (async () => {
|
|
32
|
-
* const
|
|
31
|
+
* const client = await Client.create({
|
|
33
32
|
* host: 'https://api.hailer.biz', // defaults to https://api.hailer.com
|
|
34
33
|
* username: 'set-this',
|
|
35
34
|
* password: 'set-this',
|
|
36
|
-
* };
|
|
37
|
-
*
|
|
38
|
-
* const client = await Client.create(options);
|
|
35
|
+
* });
|
|
39
36
|
*
|
|
40
37
|
* const post = await client.request('wall2.new_post', [{ subject: 'This is a wall post.', text: 'The content of my post' }]);
|
|
41
|
-
*
|
|
42
38
|
* console.log('Post created:', post);
|
|
43
39
|
* })();
|
|
40
|
+
*
|
|
41
|
+
* Example usage with User API key:
|
|
42
|
+
*
|
|
43
|
+
* const { Client } = require('@hailer/cli');
|
|
44
|
+
*
|
|
45
|
+
* (async () => {
|
|
46
|
+
* const client = await Client.create({
|
|
47
|
+
* host: 'https://api.hailer.biz',
|
|
48
|
+
* userApiKey: 'userapikey_xxxxxxxx_yyyyyyyyyyyyyyyyyyyyyyyy',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const data = await client.request('v2.core.init', []);
|
|
52
|
+
* console.log('Connected as:', data.user.email);
|
|
53
|
+
* })();
|
|
44
54
|
*/
|
|
45
55
|
class Client extends events_1.default {
|
|
46
56
|
constructor() {
|
|
@@ -51,17 +61,19 @@ class Client extends events_1.default {
|
|
|
51
61
|
this.requestId = 0;
|
|
52
62
|
this.callbacks = {};
|
|
53
63
|
}
|
|
54
|
-
/** Creates Cli instance and logs in if username and password are given */
|
|
64
|
+
/** Creates Cli instance and logs in if username and password are given, or connects with user API key */
|
|
55
65
|
static create(options) {
|
|
56
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
67
|
const instance = new Client();
|
|
58
68
|
instance.host = options.host || 'api.hailer.com';
|
|
59
69
|
instance.rejectUnauthorized = options.rejectUnauthorized !== undefined ? options.rejectUnauthorized : true;
|
|
70
|
+
instance.userApiKey = options.userApiKey;
|
|
60
71
|
yield instance.connect(instance.host);
|
|
61
72
|
if (options.username && options.password) {
|
|
62
73
|
// automatically connect if username and password is given
|
|
63
74
|
yield instance.login(options.username, options.password);
|
|
64
75
|
}
|
|
76
|
+
// Note: userApiKey authentication happens via header in connect(), no login needed
|
|
65
77
|
return instance;
|
|
66
78
|
});
|
|
67
79
|
}
|
|
@@ -115,7 +127,16 @@ class Client extends events_1.default {
|
|
|
115
127
|
if (!hostname) {
|
|
116
128
|
hostname = this.host;
|
|
117
129
|
}
|
|
118
|
-
const options = {
|
|
130
|
+
const options = {
|
|
131
|
+
transports: ['websocket'],
|
|
132
|
+
rejectUnauthorized: this.rejectUnauthorized
|
|
133
|
+
};
|
|
134
|
+
// Add user API key to authorization header if provided
|
|
135
|
+
if (this.userApiKey) {
|
|
136
|
+
options.extraHeaders = {
|
|
137
|
+
authorization: this.userApiKey
|
|
138
|
+
};
|
|
139
|
+
}
|
|
119
140
|
if (!hostname.startsWith('http://') &&
|
|
120
141
|
!hostname.startsWith('https://')) {
|
|
121
142
|
hostname = 'https://' + hostname;
|
|
@@ -173,14 +194,14 @@ class Client extends events_1.default {
|
|
|
173
194
|
/** Upload file as stream, requires filename given separately */
|
|
174
195
|
uploadFileStream(stream, filename) {
|
|
175
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
return yield (0, file_upload_1.upload)(stream, { sessionKey: this.sessionKey, filename, url: this.host });
|
|
197
|
+
return yield (0, file_upload_1.upload)(stream, { sessionKey: this.sessionKey, filename, url: this.host, headers: this.userApiKey ? { authorization: this.userApiKey } : undefined });
|
|
177
198
|
});
|
|
178
199
|
}
|
|
179
200
|
/** Upload local file by name */
|
|
180
201
|
uploadFileByName(file) {
|
|
181
202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
203
|
const readStream = (0, fs_1.createReadStream)(file);
|
|
183
|
-
return yield (0, file_upload_1.upload)(readStream, { sessionKey: this.sessionKey, filename: (0, path_1.basename)(file), url: this.host });
|
|
204
|
+
return yield (0, file_upload_1.upload)(readStream, { sessionKey: this.sessionKey, filename: (0, path_1.basename)(file), url: this.host, headers: this.userApiKey ? { authorization: this.userApiKey } : undefined });
|
|
184
205
|
});
|
|
185
206
|
}
|
|
186
207
|
disconnect() {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2BAAsC;AACtC,+BAAgC;AAChC,oDAAkC;AAClC,uDAA8C;AAC9C,wDAAgD;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2BAAsC;AACtC,+BAAgC;AAChC,oDAAkC;AAClC,uDAA8C;AAC9C,wDAAgD;AAgBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAa,MAAO,SAAQ,gBAAY;IAepC;QACI,KAAK,EAAE,CAAC;QAbZ,UAAK,GAAG,KAAK,CAAC;QACd,SAAI,GAAG,gBAAgB,CAAC;QAGxB,uBAAkB,GAAG,IAAI,CAAC;QAIlB,cAAS,GAAG,CAAC,CAAC;QACd,cAAS,GAAyE,EAAE,CAAC;IAK7F,CAAC;IAED,yGAAyG;IACzG,MAAM,CAAO,MAAM,CAAC,OAAsB;;YACtC,MAAM,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;YAE9B,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAC;YACjD,QAAQ,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC;YAC3G,QAAQ,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YAEzC,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAEtC,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACvC,0DAA0D;gBAC1D,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,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,UAAU,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1L,CAAC;KAAA;IAED,UAAU;;QACN,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU,EAAE,CAAC;IAC9B,CAAC;IAAA,CAAC;CACL;AArLD,wBAqLC"}
|
|
@@ -20,11 +20,9 @@ function upload(readStream, options) {
|
|
|
20
20
|
const filename = (options === null || options === void 0 ? void 0 : options.filename) || 'file.bin';
|
|
21
21
|
// const filesize = options?.filesize;
|
|
22
22
|
const boundary = '----LeckingBoundary12341234';
|
|
23
|
-
const httpOptions = Object.assign({ path: '/upload', method: 'POST', headers: {
|
|
23
|
+
const httpOptions = Object.assign({ path: '/upload', method: 'POST', headers: Object.assign({
|
|
24
24
|
// ... filesize ? { 'content-length': filesize } : null,
|
|
25
|
-
['content-type']: 'multipart/form-data; boundary=' + boundary,
|
|
26
|
-
hlrkey: (options === null || options === void 0 ? void 0 : options.sessionKey) || '',
|
|
27
|
-
}, form: {
|
|
25
|
+
['content-type']: 'multipart/form-data; boundary=' + boundary, hlrkey: (options === null || options === void 0 ? void 0 : options.sessionKey) || '' }, options === null || options === void 0 ? void 0 : options.headers), form: {
|
|
28
26
|
file: filename
|
|
29
27
|
} }, options);
|
|
30
28
|
const response = yield new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.js","sourceRoot":"","sources":["../../src/commands/file-upload.ts"],"names":[],"mappings":";;;;;;;;;;;AAiBA,
|
|
1
|
+
{"version":3,"file":"file-upload.js","sourceRoot":"","sources":["../../src/commands/file-upload.ts"],"names":[],"mappings":";;;;;;;;;;;AAiBA,wBAsEC;AAtFD,iCAAgD;AAChD,+BAA8C;AAE9C,6BAA0B;AAY1B,+EAA+E;AAC/E,SAAsB,MAAM,CAAC,UAAoB,EAAE,OAAuB;;;QACtE,MAAM,QAAQ,GAAG,C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,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hailer/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Hailer CLI",
|
|
5
|
-
"main": "./dist/
|
|
6
|
-
"types": "./dist/
|
|
5
|
+
"main": "./dist/index",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"start": "tsc && cp -rp assets dist/ && node bin/hailer-cli",
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Client } from '@hailer/cli';
|
|
2
|
-
import { inspect } from 'util';
|
|
3
|
-
import { upload } from './upload';
|
|
4
|
-
|
|
5
|
-
const email = 'lreiudhnli@mailinator.com';
|
|
6
|
-
const password = 'asdf';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Hailer server to connect to
|
|
10
|
-
*
|
|
11
|
-
* Test enironment:
|
|
12
|
-
* https://testapi.hailer.biz/
|
|
13
|
-
* Staging enironment:
|
|
14
|
-
* https://api.hailer.biz/
|
|
15
|
-
* Production enironment:
|
|
16
|
-
* https://api.hailer.com/
|
|
17
|
-
**/
|
|
18
|
-
const host = 'https://testapi.hailer.biz/';
|
|
19
|
-
|
|
20
|
-
const initialTime = 1665221192400;
|
|
21
|
-
|
|
22
|
-
interface Sync {
|
|
23
|
-
messages: {
|
|
24
|
-
msg?: string;
|
|
25
|
-
_id: string;
|
|
26
|
-
/** Message sender UserId */
|
|
27
|
-
uid: string;
|
|
28
|
-
/** Discussion Id */
|
|
29
|
-
discussion: string;
|
|
30
|
-
replyMessage: any;
|
|
31
|
-
replyTo: string;
|
|
32
|
-
/** Timestamp of removal */
|
|
33
|
-
removed?: number;
|
|
34
|
-
}[]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class Bot {
|
|
38
|
-
static instance: Bot;
|
|
39
|
-
|
|
40
|
-
static async create() {
|
|
41
|
-
console.log('starting bot');
|
|
42
|
-
Bot.instance = new Bot();
|
|
43
|
-
|
|
44
|
-
// Hailer Server to connect to, Username Password
|
|
45
|
-
const cli = await Client.create({ host, username: email, password });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// fetch user object
|
|
49
|
-
const info = await cli.request('v2.core.init', [['user', 'processes']]);
|
|
50
|
-
|
|
51
|
-
const userId = info?.user?._id;
|
|
52
|
-
|
|
53
|
-
if (!userId) {
|
|
54
|
-
console.log('Failed getting bot user info.');
|
|
55
|
-
cli.disconnect();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const sync: Sync = await cli.request('v2.discussion.sync', [{ timestamp: initialTime }]);
|
|
59
|
-
|
|
60
|
-
// print out v2.discussion.sync response
|
|
61
|
-
console.log('sync', sync);
|
|
62
|
-
|
|
63
|
-
// print out processes (from v2.core.init)
|
|
64
|
-
console.log('processes:', inspect(info.processes, { colors: true, depth: 10 }));
|
|
65
|
-
|
|
66
|
-
cli.disconnect();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
import { request } from 'https';
|
|
3
|
-
|
|
4
|
-
interface UploadOptions {
|
|
5
|
-
sessionKey?: string;
|
|
6
|
-
filename?: string;
|
|
7
|
-
filesize?: number;
|
|
8
|
-
host?: string;
|
|
9
|
-
port?: string;
|
|
10
|
-
path?: string;
|
|
11
|
-
method?: 'POST',
|
|
12
|
-
headers?: { [header: string]: string | number },
|
|
13
|
-
form?: { file: string },
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function upload(readStream: Readable, options?: UploadOptions) {
|
|
17
|
-
const filename = options?.filename || 'file.bin';
|
|
18
|
-
// const filesize = options?.filesize;
|
|
19
|
-
const boundary = '----LeckingBoundary12341234';
|
|
20
|
-
|
|
21
|
-
options = {
|
|
22
|
-
host: 'api.hailer.com',
|
|
23
|
-
port: '443',
|
|
24
|
-
path: '/upload',
|
|
25
|
-
method: 'POST',
|
|
26
|
-
headers: {
|
|
27
|
-
// ... filesize ? { 'content-length': filesize } : null,
|
|
28
|
-
'content-type': 'multipart/form-data; boundary=' + boundary,
|
|
29
|
-
hlrkey: options.sessionKey,
|
|
30
|
-
},
|
|
31
|
-
form: {
|
|
32
|
-
file: filename
|
|
33
|
-
},
|
|
34
|
-
...options,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const response = await new Promise<Buffer>((resolve, reject) => {
|
|
38
|
-
const chunks: Buffer[] = [];
|
|
39
|
-
|
|
40
|
-
const req = request(options, function (res) {
|
|
41
|
-
//console.log(res);
|
|
42
|
-
res.on('data', function (chunk) {
|
|
43
|
-
// console.log('BODY: ' + chunk);
|
|
44
|
-
chunks.push(chunk);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
req.on('close', () => resolve(Buffer.concat(chunks)));
|
|
49
|
-
|
|
50
|
-
req.on('error', reject);
|
|
51
|
-
|
|
52
|
-
req.write('--' + boundary + '\r\n');
|
|
53
|
-
req.write('Content-Disposition: form-data; name="file"; filename="' + filename + '"\r\n\r\n');
|
|
54
|
-
|
|
55
|
-
readStream.pipe(req, { end: false });
|
|
56
|
-
|
|
57
|
-
readStream.on('end', () => {
|
|
58
|
-
req.write('--' + boundary + '\r\n');
|
|
59
|
-
req.write('Content-Disposition: form-data; name="button"\r\n\r\n');
|
|
60
|
-
req.write('Submit\r\n');
|
|
61
|
-
|
|
62
|
-
req.write('--' + boundary + '--\r\n');
|
|
63
|
-
req.end();
|
|
64
|
-
});
|
|
65
|
-
}).catch((error) => { console.log('oh fail....', error); });
|
|
66
|
-
|
|
67
|
-
if (!Buffer.isBuffer(response)) {
|
|
68
|
-
return 'this went wrong...';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
console.log('response:', response);
|
|
72
|
-
|
|
73
|
-
let fileId: string | null = null;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
fileId = JSON.parse(response.toString())?._id;
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.log('Failed getting file id from upload', response.toString());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return fileId;
|
|
82
|
-
}
|