@emit-vision/sdk-js 0.2.0 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emit-vision/sdk-js",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Browser SDK for self-hosted emit-vision analytics and error tracking.",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  }
35
35
  },
36
36
  "scripts": {
37
- "build": "rm -rf dist && tsc -p tsconfig.build.json"
37
+ "build": "tsup --config tsup.config.ts",
38
+ "prepack": "pnpm run build"
38
39
  }
39
- }
40
+ }
package/dist/retry.d.ts DELETED
@@ -1,25 +0,0 @@
1
- export type FlushRetryOptions = {
2
- /** Initial backoff in ms after the first failure. Doubles each consecutive failure. Set to 0 to disable backoff. */
3
- initialMs: number;
4
- /** Maximum backoff in ms between retries. */
5
- maxMs: number;
6
- /** Hard-shutdown threshold: after this many consecutive failures the SDK disables itself permanently. Set to 0 to disable the cap. */
7
- failureCap: number;
8
- };
9
- export type RecordFailureResult = {
10
- backoffMs: number;
11
- consecutiveFailures: number;
12
- justDisabled: boolean;
13
- };
14
- export declare class FlushRetryController {
15
- private readonly opts;
16
- private consecutiveFailures;
17
- private backoffUntil;
18
- private disabled;
19
- constructor(opts: FlushRetryOptions);
20
- isDisabled(): boolean;
21
- isBackingOff(now?: number): boolean;
22
- msUntilReady(now?: number): number;
23
- reset(): void;
24
- recordFailure(now?: number): RecordFailureResult;
25
- }
package/dist/retry.js DELETED
@@ -1,56 +0,0 @@
1
- export class FlushRetryController {
2
- opts;
3
- consecutiveFailures = 0;
4
- backoffUntil = 0;
5
- disabled = false;
6
- constructor(opts) {
7
- this.opts = opts;
8
- }
9
- isDisabled() {
10
- return this.disabled;
11
- }
12
- isBackingOff(now = Date.now()) {
13
- return !this.disabled && now < this.backoffUntil;
14
- }
15
- msUntilReady(now = Date.now()) {
16
- if (this.disabled)
17
- return Infinity;
18
- return Math.max(0, this.backoffUntil - now);
19
- }
20
- reset() {
21
- this.consecutiveFailures = 0;
22
- this.backoffUntil = 0;
23
- }
24
- recordFailure(now = Date.now()) {
25
- this.consecutiveFailures += 1;
26
- if (this.opts.failureCap > 0 &&
27
- this.consecutiveFailures >= this.opts.failureCap) {
28
- const wasDisabled = this.disabled;
29
- this.disabled = true;
30
- this.backoffUntil = 0;
31
- return {
32
- backoffMs: 0,
33
- consecutiveFailures: this.consecutiveFailures,
34
- justDisabled: !wasDisabled,
35
- };
36
- }
37
- if (this.opts.initialMs <= 0) {
38
- this.backoffUntil = 0;
39
- return {
40
- backoffMs: 0,
41
- consecutiveFailures: this.consecutiveFailures,
42
- justDisabled: false,
43
- };
44
- }
45
- const exp = Math.min(this.opts.initialMs * Math.pow(2, this.consecutiveFailures - 1), this.opts.maxMs);
46
- // ±20% jitter so multiple clients don't synchronize their retries
47
- const jitter = exp * 0.2 * (Math.random() * 2 - 1);
48
- const backoffMs = Math.max(0, Math.floor(exp + jitter));
49
- this.backoffUntil = now + backoffMs;
50
- return {
51
- backoffMs,
52
- consecutiveFailures: this.consecutiveFailures,
53
- justDisabled: false,
54
- };
55
- }
56
- }