@qurvo/sdk-core 0.0.6 → 0.0.7
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/dist/fetch-transport.js +23 -25
- package/dist/fetch-transport.js.map +1 -1
- package/package.json +1 -1
package/dist/fetch-transport.js
CHANGED
|
@@ -7,33 +7,31 @@ class FetchTransport {
|
|
|
7
7
|
this.compress = compress;
|
|
8
8
|
}
|
|
9
9
|
async send(endpoint, apiKey, payload, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
headers['Content-Encoding'] = 'gzip';
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
body = json;
|
|
23
|
-
headers['Content-Type'] = 'application/json';
|
|
24
|
-
}
|
|
25
|
-
const response = await fetch(endpoint, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers,
|
|
28
|
-
body,
|
|
29
|
-
keepalive: options?.keepalive,
|
|
30
|
-
signal: options?.signal,
|
|
31
|
-
});
|
|
32
|
-
return response.ok || response.status === 202;
|
|
10
|
+
const json = JSON.stringify(payload);
|
|
11
|
+
const headers = {
|
|
12
|
+
'x-api-key': apiKey,
|
|
13
|
+
};
|
|
14
|
+
let body;
|
|
15
|
+
if (this.compress && !options?.keepalive) {
|
|
16
|
+
body = await this.compress(json);
|
|
17
|
+
headers['Content-Type'] = 'text/plain';
|
|
18
|
+
headers['Content-Encoding'] = 'gzip';
|
|
33
19
|
}
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
else {
|
|
21
|
+
body = json;
|
|
22
|
+
headers['Content-Type'] = 'application/json';
|
|
36
23
|
}
|
|
24
|
+
const response = await fetch(endpoint, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers,
|
|
27
|
+
body,
|
|
28
|
+
keepalive: options?.keepalive,
|
|
29
|
+
signal: options?.signal,
|
|
30
|
+
});
|
|
31
|
+
if (response.ok || response.status === 202)
|
|
32
|
+
return true;
|
|
33
|
+
const responseBody = await response.text().catch(() => '');
|
|
34
|
+
throw new Error(`HTTP ${response.status}: ${responseBody}`);
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
exports.FetchTransport = FetchTransport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-transport.js","sourceRoot":"","sources":["../src/fetch-transport.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IACI;IAA7B,YAA6B,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;IAAG,CAAC;IAEtD,KAAK,CAAC,IAAI,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAgB,EAAE,OAAqB;QAClF,
|
|
1
|
+
{"version":3,"file":"fetch-transport.js","sourceRoot":"","sources":["../src/fetch-transport.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IACI;IAA7B,YAA6B,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;IAAG,CAAC;IAEtD,KAAK,CAAC,IAAI,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAgB,EAAE,OAAqB;QAClF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,OAAO,GAA2B;YACtC,WAAW,EAAE,MAAM;SACpB,CAAC;QAEF,IAAI,IAAc,CAAC;QACnB,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC;YACzC,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC;YACvC,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,IAAI,CAAC;YACZ,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAC/C,CA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