@flareapp/vite 1.0.2 → 1.0.3
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/index.js +33 -10
- package/dist/index.mjs +33 -10
- package/package.json +1 -1
- package/src/flareApi.ts +47 -16
package/dist/index.js
CHANGED
|
@@ -39,26 +39,49 @@ var import_path = require("path");
|
|
|
39
39
|
|
|
40
40
|
// src/flareApi.ts
|
|
41
41
|
var import_axios = __toESM(require("axios"));
|
|
42
|
+
var import_https = __toESM(require("https"));
|
|
42
43
|
var import_zlib = require("zlib");
|
|
43
44
|
var FlareApi = class {
|
|
44
45
|
constructor(endpoint, key, version) {
|
|
45
46
|
this.endpoint = endpoint;
|
|
46
47
|
this.key = key;
|
|
47
48
|
this.version = version;
|
|
49
|
+
this.client = import_axios.default.create({
|
|
50
|
+
httpsAgent: new import_https.default.Agent({ keepAlive: false })
|
|
51
|
+
});
|
|
48
52
|
}
|
|
49
53
|
uploadSourcemap(sourcemap) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
sourcemap: base64GzipSourcemap
|
|
57
|
-
}).then(resolve2).catch((error) => {
|
|
58
|
-
return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
|
|
59
|
-
});
|
|
54
|
+
const base64GzipSourcemap = (0, import_zlib.deflateRawSync)(sourcemap.content).toString("base64");
|
|
55
|
+
return this.postWithRetry({
|
|
56
|
+
key: this.key,
|
|
57
|
+
version_id: this.version,
|
|
58
|
+
relative_filename: sourcemap.original_file,
|
|
59
|
+
sourcemap: base64GzipSourcemap
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
+
async postWithRetry(data, retries = 3) {
|
|
63
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
64
|
+
try {
|
|
65
|
+
return await this.client.post(this.endpoint, data);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
68
|
+
if (error.response) {
|
|
69
|
+
throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
|
|
70
|
+
}
|
|
71
|
+
if (attempt < retries) {
|
|
72
|
+
await this.delay(attempt * 1e3);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
throw `Network error: ${error.message}`;
|
|
76
|
+
}
|
|
77
|
+
throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
throw "Unexpected: retry loop exited without returning or throwing";
|
|
81
|
+
}
|
|
82
|
+
delay(ms) {
|
|
83
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
84
|
+
}
|
|
62
85
|
};
|
|
63
86
|
|
|
64
87
|
// src/util.ts
|
package/dist/index.mjs
CHANGED
|
@@ -5,26 +5,49 @@ import { resolve } from "path";
|
|
|
5
5
|
|
|
6
6
|
// src/flareApi.ts
|
|
7
7
|
import axios from "axios";
|
|
8
|
+
import https from "https";
|
|
8
9
|
import { deflateRawSync } from "zlib";
|
|
9
10
|
var FlareApi = class {
|
|
10
11
|
constructor(endpoint, key, version) {
|
|
11
12
|
this.endpoint = endpoint;
|
|
12
13
|
this.key = key;
|
|
13
14
|
this.version = version;
|
|
15
|
+
this.client = axios.create({
|
|
16
|
+
httpsAgent: new https.Agent({ keepAlive: false })
|
|
17
|
+
});
|
|
14
18
|
}
|
|
15
19
|
uploadSourcemap(sourcemap) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
sourcemap: base64GzipSourcemap
|
|
23
|
-
}).then(resolve2).catch((error) => {
|
|
24
|
-
return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
|
|
25
|
-
});
|
|
20
|
+
const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString("base64");
|
|
21
|
+
return this.postWithRetry({
|
|
22
|
+
key: this.key,
|
|
23
|
+
version_id: this.version,
|
|
24
|
+
relative_filename: sourcemap.original_file,
|
|
25
|
+
sourcemap: base64GzipSourcemap
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
async postWithRetry(data, retries = 3) {
|
|
29
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
30
|
+
try {
|
|
31
|
+
return await this.client.post(this.endpoint, data);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (axios.isAxiosError(error)) {
|
|
34
|
+
if (error.response) {
|
|
35
|
+
throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
|
|
36
|
+
}
|
|
37
|
+
if (attempt < retries) {
|
|
38
|
+
await this.delay(attempt * 1e3);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
throw `Network error: ${error.message}`;
|
|
42
|
+
}
|
|
43
|
+
throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw "Unexpected: retry loop exited without returning or throwing";
|
|
47
|
+
}
|
|
48
|
+
delay(ms) {
|
|
49
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
50
|
+
}
|
|
28
51
|
};
|
|
29
52
|
|
|
30
53
|
// src/util.ts
|
package/package.json
CHANGED
package/src/flareApi.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
1
|
+
import axios, { AxiosInstance } from 'axios';
|
|
2
|
+
import https from 'https';
|
|
2
3
|
import { deflateRawSync } from 'zlib';
|
|
3
4
|
|
|
4
5
|
import { Sourcemap } from './index';
|
|
@@ -7,28 +8,58 @@ export default class FlareApi {
|
|
|
7
8
|
endpoint: string;
|
|
8
9
|
key: string;
|
|
9
10
|
version: string;
|
|
11
|
+
private client: AxiosInstance;
|
|
10
12
|
|
|
11
13
|
constructor(endpoint: string, key: string, version: string) {
|
|
12
14
|
this.endpoint = endpoint;
|
|
13
15
|
this.key = key;
|
|
14
16
|
this.version = version;
|
|
17
|
+
this.client = axios.create({
|
|
18
|
+
httpsAgent: new https.Agent({ keepAlive: false }),
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
uploadSourcemap(sourcemap: Sourcemap) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
relative_filename: sourcemap.original_file,
|
|
26
|
-
sourcemap: base64GzipSourcemap,
|
|
27
|
-
})
|
|
28
|
-
.then(resolve)
|
|
29
|
-
.catch((error) => {
|
|
30
|
-
return reject(`${error.response.status}: ${JSON.stringify(error.response.data)}`);
|
|
31
|
-
});
|
|
22
|
+
uploadSourcemap(sourcemap: Sourcemap): Promise<unknown> {
|
|
23
|
+
const base64GzipSourcemap = deflateRawSync(sourcemap.content).toString('base64');
|
|
24
|
+
|
|
25
|
+
return this.postWithRetry({
|
|
26
|
+
key: this.key,
|
|
27
|
+
version_id: this.version,
|
|
28
|
+
relative_filename: sourcemap.original_file,
|
|
29
|
+
sourcemap: base64GzipSourcemap,
|
|
32
30
|
});
|
|
33
31
|
}
|
|
32
|
+
|
|
33
|
+
private async postWithRetry(data: Record<string, string>, retries = 3): Promise<unknown> {
|
|
34
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
35
|
+
try {
|
|
36
|
+
return await this.client.post(this.endpoint, data);
|
|
37
|
+
} catch (error: unknown) {
|
|
38
|
+
if (axios.isAxiosError(error)) {
|
|
39
|
+
if (error.response) {
|
|
40
|
+
// HTTP error (4xx/5xx) - do not retry
|
|
41
|
+
throw `${error.response.status}: ${JSON.stringify(error.response.data)}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Network error (no response) - retry if attempts remain
|
|
45
|
+
if (attempt < retries) {
|
|
46
|
+
await this.delay(attempt * 1000);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Exhausted retries for network error
|
|
51
|
+
throw `Network error: ${error.message}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Non-axios error - do not retry
|
|
55
|
+
throw `Request setup error: ${error instanceof Error ? error.message : String(error)}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
throw 'Unexpected: retry loop exited without returning or throwing';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private delay(ms: number): Promise<void> {
|
|
63
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
64
|
+
}
|
|
34
65
|
}
|