@vouchfor/sdk 1.1.37 → 1.1.39
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.
|
@@ -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
|
-
|
|
@@ -80,6 +80,13 @@ class CampaignService extends BaseRestService {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
clips(id, apiKey, opts = {}) {
|
|
84
|
+
return this._request({
|
|
85
|
+
apiKey,
|
|
86
|
+
path: `${id}/clips` + this._utils.queryString(opts)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
83
90
|
convert(id, params, apiKey) {
|
|
84
91
|
return this._request({
|
|
85
92
|
apiKey,
|
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);
|
|
@@ -66,6 +85,12 @@ class TaskBroker {
|
|
|
66
85
|
entry.reject(value);
|
|
67
86
|
return true;
|
|
68
87
|
}
|
|
88
|
+
|
|
89
|
+
response(id) {
|
|
90
|
+
const entry = this.history.get(id);
|
|
91
|
+
if (!entry) return;
|
|
92
|
+
return entry.value;
|
|
93
|
+
}
|
|
69
94
|
}
|
|
70
95
|
|
|
71
96
|
const broker = new TaskBroker()
|