-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcreate-document-group-template.js
executable file
·69 lines (59 loc) · 1.88 KB
/
create-document-group-template.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
/**
* to run create-document-group-template applet from the project root folder type in your console:
* > node bin/create-document-group-template <client_id> <client_secret> <username> <password> <template_group_name> <...template_ids> <routing_details>
* <client_id> <client_secret> <username> <password> <template_group_name> <...template_ids> <routing_details> - are required params
* <...template_ids> - ID(s) of one or more templates
* options:
* --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,
template_group_name,
...templateIDsWithRoutingDetails
] = params;
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 },
documentGroupTemplate: { create: createDocumentGroupTemplate },
} = api;
const getAccessToken$ = promisify(getAccessToken);
const createDocumentGroupTemplate$ = promisify(createDocumentGroupTemplate);
getAccessToken$({
username,
password,
})
.then(({ access_token: token }) => {
const template_ids = templateIDsWithRoutingDetails.slice(0, -1);
const routingDetailsStringified = templateIDsWithRoutingDetails.slice(-1);
const routing_details = JSON.parse(routingDetailsStringified);
return {
token,
template_ids,
routing_details,
};
})
.then(({
token,
template_ids,
routing_details,
}) => createDocumentGroupTemplate$({
token,
template_ids,
template_group_name,
routing_details,
}))
.then(res => console.log(res))
.catch(err => console.error(err));