@vouchfor/sdk 1.1.16 → 1.1.18
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/lib/services/index.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const BaseRestService = require('./base');
|
|
2
|
+
|
|
3
|
+
class AdvocacyRequestService extends BaseRestService {
|
|
4
|
+
constructor(client, config, logger) {
|
|
5
|
+
super(client, config, 'advocacy/requests', logger);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get(id, apiKey) {
|
|
9
|
+
return this._request({
|
|
10
|
+
apiKey,
|
|
11
|
+
path: `${id}`
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
share(id, share, apiKey) {
|
|
16
|
+
return this._request({
|
|
17
|
+
apiKey,
|
|
18
|
+
body: { share },
|
|
19
|
+
path: `${id}/share`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = AdvocacyRequestService;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const BaseRestService = require('./base');
|
|
2
|
+
const AdvocacyRequestService = require('./advocacyRequestService');
|
|
3
|
+
|
|
4
|
+
class AdvocacyService extends BaseRestService {
|
|
5
|
+
constructor(client, config, logger) {
|
|
6
|
+
super(client, config, 'advocacy', logger);
|
|
7
|
+
this.requests = new AdvocacyRequestService(client, config, logger);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// advocacy has not methods yet
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = AdvocacyService;
|
package/lib/shared/events.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
+
ADVOCACY_REQUEST_REACT: 'advocacy.request.like', //TODO - rename
|
|
3
|
+
ADVOCACY_REQUEST_SHARE: 'advocacy.request.reshare',
|
|
2
4
|
APPLICATION_ACTION_INIT: 'application.action.init',
|
|
3
5
|
APPLICATION_ACTION_SUBMIT: 'application.action.submit',
|
|
4
6
|
APPLICATION_INSTALL: 'application.install',
|
|
@@ -12,6 +14,17 @@ module.exports = {
|
|
|
12
14
|
CAMPAIGN_STARTED: 'campaign.started',
|
|
13
15
|
CAMPAIGN_RESPONDED: 'campaign.responded',
|
|
14
16
|
CAMPAIGN_DELETED: 'campaign.deleted',
|
|
17
|
+
FILE_APPROVAL_APPROVED: 'file.approval_approved',
|
|
18
|
+
FILE_APPROVAL_REJECTED: 'file.approval_rejected',
|
|
19
|
+
FILE_APPROVAL_PENDING: 'file.approval_pending',
|
|
20
|
+
FILE_APPROVAL_INTERNAL: 'file.approval_internal',
|
|
21
|
+
FILE_APPROVAL_ARCHIVED: 'file.approval_archived',
|
|
22
|
+
FILE_APPROVAL_READY_FOR_REVIEW: 'file.approval_ready_for_review',
|
|
23
|
+
SHARE_CONFIGURE: 'share.configure',
|
|
24
|
+
SHARE_VOUCH: 'share.vouch',
|
|
25
|
+
SHARE_FILE: 'share.file',
|
|
26
|
+
SHARE_CAMPAIGN: 'share.campaign',
|
|
27
|
+
SHARE_ADVOCACY_REQUEST: 'share.advocacy.request',
|
|
15
28
|
VOUCH_CREATED: 'vouch.created',
|
|
16
29
|
VOUCH_SENT: 'vouch.sent',
|
|
17
30
|
VOUCH_PUBLISHED: 'vouch.published',
|
|
@@ -24,4 +37,10 @@ module.exports = {
|
|
|
24
37
|
VOUCH_RESPONDED: 'vouch.responded',
|
|
25
38
|
VOUCH_UPDATED: 'vouch.updated',
|
|
26
39
|
VOUCH_DELETED: 'vouch.deleted',
|
|
40
|
+
VOUCH_APPROVAL_APPROVED: 'vouch.approval_approved',
|
|
41
|
+
VOUCH_APPROVAL_REJECTED: 'vouch.approval_rejected',
|
|
42
|
+
VOUCH_APPROVAL_PENDING: 'vouch.approval_pending',
|
|
43
|
+
VOUCH_APPROVAL_INTERNAL: 'vouch.approval_internal',
|
|
44
|
+
VOUCH_APPROVAL_ARCHIVED: 'vouch.approval_archived',
|
|
45
|
+
VOUCH_APPROVAL_READY_FOR_REVIEW: 'vouch.approval_ready_for_review',
|
|
27
46
|
};
|
package/lib/shared/utils.js
CHANGED
|
@@ -4,6 +4,22 @@ const { http, https } = followRedirects;
|
|
|
4
4
|
followRedirects.maxRedirects = 10;
|
|
5
5
|
followRedirects.maxBodyLength = Infinity;
|
|
6
6
|
|
|
7
|
+
function parseHttpHeaders(headers) {
|
|
8
|
+
return headers
|
|
9
|
+
.split('\n')
|
|
10
|
+
.map(line => line.trim())
|
|
11
|
+
.filter(line => line.includes(':'))
|
|
12
|
+
.reduce((acc, line) => {
|
|
13
|
+
const i = line.indexOf(':');
|
|
14
|
+
if (i !== -1) {
|
|
15
|
+
const key = line.slice(0, i).trim().toLowerCase();
|
|
16
|
+
const value = line.slice(i + 1).trim();
|
|
17
|
+
acc[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
function logHttpResponse({ req, res, body, result, logger }) {
|
|
8
24
|
const { protocol, method, host, _header: header } = req._currentRequest;
|
|
9
25
|
const get = req.type === 'GET';
|
|
@@ -17,7 +33,7 @@ function logHttpResponse({ req, res, body, result, logger }) {
|
|
|
17
33
|
for (let i = 0; i < n; i += 2) {
|
|
18
34
|
headers.push(`${res.rawHeaders[i]}: ${res.rawHeaders[i+1]}`);
|
|
19
35
|
}
|
|
20
|
-
const content =
|
|
36
|
+
const content = type.split('/')[0];
|
|
21
37
|
const binary = [ 'image', 'audio', 'video' ].includes(content);
|
|
22
38
|
const payload = binary ? `<<< ${content} content} >>>` : result;
|
|
23
39
|
const response = `HTTP/${httpVersion} ${statusCode} ${statusMessage}\r\n`
|
|
@@ -32,6 +48,7 @@ function logHttpResponse({ req, res, body, result, logger }) {
|
|
|
32
48
|
|
|
33
49
|
function logHttpError({ req, err, body, logger }) {
|
|
34
50
|
const { protocol, method, host, _header: header } = req._currentRequest;
|
|
51
|
+
const res = { headers: parseHttpHeaders(header) };
|
|
35
52
|
const get = req.type === 'GET';
|
|
36
53
|
const type = res.headers['content-type'] ?? 'application/json';
|
|
37
54
|
const json = type.indexOf('application/json') !== -1;
|
package/package.json
CHANGED
package/test.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const Vouch = require("./lib/vouch");
|
|
2
|
+
|
|
3
|
+
const vouchClient = new Vouch({
|
|
4
|
+
env: 'dev',
|
|
5
|
+
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M'
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const response = await vouchClient.integrations.applications.list();
|
|
10
|
+
console.log(typeof response);
|
|
11
|
+
const items = await response.applications.reduce(async (ac, application) => {
|
|
12
|
+
const arr = await ac;
|
|
13
|
+
console.log(`id => ${application.id}`);
|
|
14
|
+
try {
|
|
15
|
+
const credentials = await vouchClient.integrations.authenticate({ entityId: application.entity.id });
|
|
16
|
+
arr.push(credentials);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error(`failed to get credentials ${err} - ${application.id}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return arr;
|
|
22
|
+
}, Promise.resolve([]));
|
|
23
|
+
})();
|