@vouchfor/sdk 1.1.29 → 1.1.30
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.
|
@@ -66,6 +66,20 @@ class CampaignService extends BaseRestService {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
responses(id, apiKey, opts = {}) {
|
|
70
|
+
return this._request({
|
|
71
|
+
apiKey,
|
|
72
|
+
path: `${id}/responses` + this._utils.queryString(opts)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
keywords(id, apiKey, opts = {}) {
|
|
77
|
+
return this._request({
|
|
78
|
+
apiKey,
|
|
79
|
+
path: `${id}/keywords` + this._utils.queryString(opts)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
69
83
|
convert(id, params, apiKey) {
|
|
70
84
|
return this._request({
|
|
71
85
|
apiKey,
|
|
@@ -37,6 +37,14 @@ class EntityService extends BaseRestService {
|
|
|
37
37
|
return this._request({ apiKey, path: `${id}/brand` });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
tags(id, apiKey) {
|
|
41
|
+
return this._request({ apiKey, path: `${id}/tags` });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
templates(id, apiKey) {
|
|
45
|
+
return this._request({ apiKey, path: `${id}/templates` });
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
users(id, apiKey) {
|
|
41
49
|
return this._request({ apiKey, path: `${id}/users` });
|
|
42
50
|
}
|
package/lib/shared/utils.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports = {
|
|
|
82
82
|
).toString();
|
|
83
83
|
return query ? `?${query}` : '';
|
|
84
84
|
},
|
|
85
|
-
request({ body, headers, method, url, logger }) {
|
|
85
|
+
request({ body, headers, method, url, logger }, attempt = 1) {
|
|
86
86
|
const { protocol, hostname, port, pathname, search = '' } = new URL(url);
|
|
87
87
|
|
|
88
88
|
return new Promise((resolve, reject) => {
|
|
@@ -100,27 +100,40 @@ module.exports = {
|
|
|
100
100
|
res.on('data', (chunk) => {
|
|
101
101
|
result += chunk;
|
|
102
102
|
});
|
|
103
|
-
res.on('end', () => {
|
|
103
|
+
res.on('end', async () => {
|
|
104
104
|
try {
|
|
105
105
|
if (logger) {
|
|
106
106
|
logHttpResponse({ req, res, body, result, start, logger });
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
const errors = [
|
|
110
|
+
502, // bad gateway, the BE is deploying
|
|
111
|
+
504, // gatewat timeout, the BE will scale
|
|
112
|
+
];
|
|
113
|
+
const maxAttempts = 8;
|
|
114
|
+
const interval = 1000;
|
|
115
|
+
if (attempt < maxAttempts && errors.includes(res.statusCode)) {
|
|
116
|
+
await new Promise((resolve) => setTimeout(resolve, interval * attempt));
|
|
117
|
+
return resolve(
|
|
118
|
+
this.request({ body, headers, method, url, logger }, attempt + 1)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
109
122
|
if (res.statusCode >= 400) {
|
|
110
123
|
let error = res.statusMessage || 'error';
|
|
111
124
|
try {
|
|
112
125
|
error = JSON.parse(result)?.error || error;
|
|
113
126
|
} catch (_) {}
|
|
114
127
|
|
|
115
|
-
reject(error);
|
|
128
|
+
return reject(error);
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
const type = res.headers['content-type'] ?? 'application/json';
|
|
119
132
|
const json = type.indexOf('application/json') !== -1;
|
|
120
133
|
const data = !!result && json ? JSON.parse(result) : result;
|
|
121
|
-
resolve(data);
|
|
134
|
+
return resolve(data);
|
|
122
135
|
} catch (err) {
|
|
123
|
-
reject(err);
|
|
136
|
+
return reject(err);
|
|
124
137
|
}
|
|
125
138
|
});
|
|
126
139
|
},
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
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).catch(() => undefined);
|
|
12
|
+
console.log(data);
|
|
13
|
+
})();
|
|
14
|
+
|