-
Notifications
You must be signed in to change notification settings - Fork 22
/
remove-document.js
executable file
·53 lines (44 loc) · 1.37 KB
/
remove-document.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
/**
* to run remove-document applet from the project root folder type in your console:
* > node bin/remove-document <client_id> <client_secret> <username> <password> <document_id>
* <client_id>, <client_secret>, <username>, <password>, <document_id> - are required params
* options:
* --cancel-invites - invites of document will be cancelled if exist
* --dev - request will be sent to developer sandbox API
*/
'use strict';
const args = process.argv.slice(2);
const flags = args.filter(arg => /^--/.test(arg));
const params = args.filter(arg => !/^--/.test(arg));
const [
clientId,
clientSecret,
username,
password,
documentId,
] = params;
const cancelInvites = flags.includes('--cancel-invites');
const dev = flags.includes('--dev');
const { promisify } = require('../utils');
const api = require('../lib')({
credentials: Buffer.from(`${clientId}:${clientSecret}`).toString('base64'),
production: !dev,
});
const {
oauth2: { requestToken: getAccessToken },
document: { remove: removeDocument },
} = api;
const getAccessToken$ = promisify(getAccessToken);
const removeDocument$ = promisify(removeDocument);
getAccessToken$({
username,
password,
})
.then(({ access_token: token }) => removeDocument$({
id: documentId,
options: { cancelInvites },
token,
}))
.then(res => console.log(res))
.catch(err => console.error(err));