@vouchfor/sdk 1.1.17 → 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',
|
|
@@ -18,6 +20,11 @@ module.exports = {
|
|
|
18
20
|
FILE_APPROVAL_INTERNAL: 'file.approval_internal',
|
|
19
21
|
FILE_APPROVAL_ARCHIVED: 'file.approval_archived',
|
|
20
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',
|
|
21
28
|
VOUCH_CREATED: 'vouch.created',
|
|
22
29
|
VOUCH_SENT: 'vouch.sent',
|
|
23
30
|
VOUCH_PUBLISHED: 'vouch.published',
|
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;
|