@vouchfor/sdk 1.1.38 → 1.1.40
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/baseService.js +1 -1
- package/lib/services/callbackService.js +5 -2
- package/lib/shared/tasks.js +30 -1
- package/package.json +1 -1
- package/.claude/settings.local.json +0 -10
- package/test-accounts.js +0 -16
- package/test-answers.js +0 -17
- package/test-assets.js +0 -17
- package/test-callback.js +0 -21
- package/test-campaigns.js +0 -20
- package/test-canva.js +0 -53
- package/test-commit.js +0 -11
- package/test-compositions.js +0 -15
- package/test-images.js +0 -41
- package/test-poll.js +0 -10
- package/test-search.js +0 -18
- package/test-upload.js +0 -17
- package/test.js +0 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const tasks = require('../shared/tasks');
|
|
2
2
|
|
|
3
3
|
class CallbackService {
|
|
4
|
-
|
|
4
|
+
respond(id, body) {
|
|
5
5
|
const { status = '', json } = body || {};
|
|
6
6
|
const statusCode = Number(status.split(' ')[0]);
|
|
7
7
|
if (!(id && status)) {
|
|
@@ -12,7 +12,10 @@ class CallbackService {
|
|
|
12
12
|
tasks.fail(id, body);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
response(id) {
|
|
17
|
+
return tasks.response(id);
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
module.exports = CallbackService;
|
|
18
|
-
|
package/lib/shared/tasks.js
CHANGED
|
@@ -8,12 +8,27 @@ function generateId() {
|
|
|
8
8
|
return id;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// make all results available for 5 minutes
|
|
12
|
+
// purge expired results every minute
|
|
13
|
+
const HISTORY_INTERVAL = 1 * 60 * 1000;
|
|
14
|
+
const HISTORY_EXPIRY = 5 * 60 * 1000;
|
|
15
|
+
|
|
16
|
+
const interval = setInterval(() => {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
for (const [id, { ts }] of broker.history) {
|
|
19
|
+
if (now - ts > HISTORY_EXPIRY) {
|
|
20
|
+
broker.history.delete(id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, HISTORY_INTERVAL);
|
|
24
|
+
|
|
11
25
|
class TaskBroker {
|
|
12
26
|
constructor() {
|
|
13
27
|
this.pending = new Map();
|
|
28
|
+
this.history = new Map();
|
|
14
29
|
}
|
|
15
30
|
|
|
16
|
-
create(timeoutMs =
|
|
31
|
+
create(timeoutMs = 30000) {
|
|
17
32
|
const id = generateId();
|
|
18
33
|
|
|
19
34
|
let resolveFn;
|
|
@@ -54,6 +69,10 @@ class TaskBroker {
|
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
respond(id, value) {
|
|
72
|
+
this.history.set(id, {
|
|
73
|
+
ts: Date.now(),
|
|
74
|
+
value
|
|
75
|
+
});
|
|
57
76
|
const entry = this.pending.get(id);
|
|
58
77
|
if (!entry) return false;
|
|
59
78
|
entry.resolve(value);
|
|
@@ -61,11 +80,21 @@ class TaskBroker {
|
|
|
61
80
|
}
|
|
62
81
|
|
|
63
82
|
fail(id, value) {
|
|
83
|
+
this.history.set(id, {
|
|
84
|
+
ts: Date.now(),
|
|
85
|
+
value
|
|
86
|
+
});
|
|
64
87
|
const entry = this.pending.get(id);
|
|
65
88
|
if (!entry) return false;
|
|
66
89
|
entry.reject(value);
|
|
67
90
|
return true;
|
|
68
91
|
}
|
|
92
|
+
|
|
93
|
+
response(id) {
|
|
94
|
+
const entry = this.history.get(id);
|
|
95
|
+
if (!entry) return;
|
|
96
|
+
return entry.value;
|
|
97
|
+
}
|
|
69
98
|
}
|
|
70
99
|
|
|
71
100
|
const broker = new TaskBroker()
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(grep -l \"Router\\\\\\(\\\\\\)\" /home/david/dev/vouch-new/amplify/backend/function/restapi/lib/controllers/*.ts | xargs grep -L \"@openapi\")",
|
|
5
|
-
"Bash(for f:*)",
|
|
6
|
-
"Bash(cd /home/david/dev/vouch-new/amplify/backend/function/restapi/openapi && node -e \"const s = require\\('./components/schemas'\\); console.log\\(Object.keys\\(s\\).join\\(', '\\)\\)\" 2>&1)",
|
|
7
|
-
"Bash(cd /home/david/dev/vouch-new/amplify/backend/function/restapi/openapi && node -e \"const r = require\\('./components/responses'\\); console.log\\(Object.keys\\(r\\).join\\(', '\\)\\)\" 2>&1)"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
10
|
-
}
|
package/test-accounts.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
const id = 'WncEfS4KgY';
|
|
10
|
-
|
|
11
|
-
(async () => {
|
|
12
|
-
const accounts = await vouchClient.accounts.list(apiKey).catch(() => undefined);
|
|
13
|
-
console.log(accounts);
|
|
14
|
-
const account = await vouchClient.accounts.get(id, apiKey).catch(() => undefined);
|
|
15
|
-
console.log(account);
|
|
16
|
-
})();
|
package/test-answers.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
|
|
10
|
-
(async () => {
|
|
11
|
-
const params = {
|
|
12
|
-
//query: 'clients',
|
|
13
|
-
limit: 5
|
|
14
|
-
};
|
|
15
|
-
const data = await vouchClient.answers.search(params, apiKey).catch(() => undefined);
|
|
16
|
-
console.log(data);
|
|
17
|
-
})();
|
package/test-assets.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
|
|
10
|
-
(async () => {
|
|
11
|
-
const params = {
|
|
12
|
-
//query: 'clients',
|
|
13
|
-
limit: 5
|
|
14
|
-
};
|
|
15
|
-
const data = await vouchClient.assets.search(params, apiKey).catch(() => undefined);
|
|
16
|
-
console.log(data);
|
|
17
|
-
})();
|
package/test-callback.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
callbackUrl: 'https://extrajudicial-melanie-unadministratively.ngrok-free.dev/callback'
|
|
7
|
-
}, console);
|
|
8
|
-
|
|
9
|
-
console.log(vouchClient);
|
|
10
|
-
|
|
11
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
12
|
-
|
|
13
|
-
(async () => {
|
|
14
|
-
const params = {
|
|
15
|
-
query: 'why',
|
|
16
|
-
limit: 2
|
|
17
|
-
};
|
|
18
|
-
const data = await vouchClient.campaigns.search(params, apiKey).catch(() => undefined);
|
|
19
|
-
console.log(data);
|
|
20
|
-
})();
|
|
21
|
-
|
package/test-campaigns.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
console.log(vouchClient);
|
|
9
|
-
|
|
10
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
11
|
-
|
|
12
|
-
(async () => {
|
|
13
|
-
const params = {
|
|
14
|
-
query: 'why',
|
|
15
|
-
limit: 2
|
|
16
|
-
};
|
|
17
|
-
const data = await vouchClient.campaigns.search(params, apiKey).catch(() => undefined);
|
|
18
|
-
console.log(data);
|
|
19
|
-
})();
|
|
20
|
-
|
package/test-canva.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
const Vouch = require("./lib/vouch");
|
|
3
|
-
|
|
4
|
-
const vouchClient = new Vouch({
|
|
5
|
-
env: 'dev',
|
|
6
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
7
|
-
}, console);
|
|
8
|
-
|
|
9
|
-
const VOUCH_APPLICATION_API_KEY = vouchClient.integrationKey;
|
|
10
|
-
|
|
11
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
12
|
-
|
|
13
|
-
const answerBaseUrl = vouchClient.vouches._baseUrl.replace('/vouches', '/answers');
|
|
14
|
-
const listAnswersUrl = answerBaseUrl;
|
|
15
|
-
const trackAnswerUrl = answerBaseUrl + '/track';
|
|
16
|
-
|
|
17
|
-
const listAssetsUrl = vouchClient.vouches._baseUrl.replace('/vouches', '/assets');
|
|
18
|
-
|
|
19
|
-
const listAnswers = (key, params) => {
|
|
20
|
-
return axios({
|
|
21
|
-
method: 'GET',
|
|
22
|
-
params,
|
|
23
|
-
url: listAnswersUrl,
|
|
24
|
-
headers: {
|
|
25
|
-
accept: 'application/json',
|
|
26
|
-
'content-type': 'application/json',
|
|
27
|
-
'x-integration-key': VOUCH_APPLICATION_API_KEY,
|
|
28
|
-
'x-api-key': key
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const listAssets = (key, params) => {
|
|
34
|
-
return axios({
|
|
35
|
-
method: 'GET',
|
|
36
|
-
params,
|
|
37
|
-
url: listAssetsUrl,
|
|
38
|
-
headers: {
|
|
39
|
-
accept: 'application/json',
|
|
40
|
-
'content-type': 'application/json',
|
|
41
|
-
'x-integration-key': VOUCH_APPLICATION_API_KEY,
|
|
42
|
-
'x-api-key': key
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
(async () => {
|
|
48
|
-
const params = {
|
|
49
|
-
query: 'clients'
|
|
50
|
-
};
|
|
51
|
-
const data = await listAnswers(apiKey, params).catch(() => undefined);
|
|
52
|
-
console.log(data.data);
|
|
53
|
-
})();
|
package/test-commit.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
(async () => {
|
|
9
|
-
vouchClient.utilities.commit().catch(() => undefined);
|
|
10
|
-
vouchClient.integrations.commit().catch(() => undefined);
|
|
11
|
-
})();
|
package/test-compositions.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
|
|
10
|
-
(async () => {
|
|
11
|
-
const data = await vouchClient.compositions.get('fMMsKxK9Ic', apiKey)
|
|
12
|
-
.then((data) => console.log('data', data))
|
|
13
|
-
.catch((err) => console.log('error', err));
|
|
14
|
-
})();
|
|
15
|
-
|
package/test-images.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
|
|
10
|
-
(async () => {
|
|
11
|
-
{
|
|
12
|
-
const params = {
|
|
13
|
-
query: 'why',
|
|
14
|
-
limit: 2
|
|
15
|
-
};
|
|
16
|
-
const data = await vouchClient.images.search(params, apiKey).catch(() => undefined);
|
|
17
|
-
console.log(data);
|
|
18
|
-
}
|
|
19
|
-
{
|
|
20
|
-
const params = {
|
|
21
|
-
account: {
|
|
22
|
-
email: 'david@vouchfor.com'
|
|
23
|
-
},
|
|
24
|
-
image: {
|
|
25
|
-
name: 'Image from Url',
|
|
26
|
-
externalid: '777888999000',
|
|
27
|
-
url: 'https://googlechrome.github.io/samples/picture-element/images/butterfly.webp',
|
|
28
|
-
sourceUrl: 'https://googlechrome.github.io/samples/picture-element/images/butterfly.webp',
|
|
29
|
-
source: 'TEST'
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const data = await vouchClient.images.upload(params, apiKey).catch(() => undefined);
|
|
33
|
-
console.log(data);
|
|
34
|
-
}
|
|
35
|
-
{
|
|
36
|
-
const id = '777888999000';
|
|
37
|
-
const data = await vouchClient.images.get(id, apiKey).catch(() => undefined);
|
|
38
|
-
console.log(data);
|
|
39
|
-
}
|
|
40
|
-
})();
|
|
41
|
-
|
package/test-poll.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
(async () => {
|
|
9
|
-
vouchClient.poll();
|
|
10
|
-
})();
|
package/test-search.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
|
|
10
|
-
(async () => {
|
|
11
|
-
const params = {
|
|
12
|
-
query: 'clients',
|
|
13
|
-
limit: 2
|
|
14
|
-
};
|
|
15
|
-
const data = await vouchClient.vouches.search(params, apiKey).catch(() => undefined);
|
|
16
|
-
console.log(data);
|
|
17
|
-
})();
|
|
18
|
-
|
package/test-upload.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const Vouch = require("./lib/vouch");
|
|
2
|
-
|
|
3
|
-
const vouchClient = new Vouch({
|
|
4
|
-
env: 'dev',
|
|
5
|
-
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
-
}, console);
|
|
7
|
-
|
|
8
|
-
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
-
const url = 'https://examplefiles.org/files/video/mp4-example-video-download-640x480.mp4'
|
|
10
|
-
const key1 = 'delete/file_example_MP4_480_1_5MG.mp4';
|
|
11
|
-
const key2 = 'delete/file_example_MP4_480_1_EXT';
|
|
12
|
-
|
|
13
|
-
(async () => {
|
|
14
|
-
const result = await vouchClient.files.proxy(url, key1, apiKey, { extract: true, extname: true }).catch(() => undefined);
|
|
15
|
-
console.log(result);
|
|
16
|
-
})();
|
|
17
|
-
|
package/test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
})();
|