@atsail/browser 0.1.1 → 0.2.1
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 +21 -3
- package/dist/transport.d.ts +2 -1
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,13 +5,15 @@ var DEFAULT_MAX_BATCH_SIZE = 20;
|
|
|
5
5
|
|
|
6
6
|
class Transport {
|
|
7
7
|
publishableKey;
|
|
8
|
+
environment;
|
|
8
9
|
endpoint;
|
|
9
10
|
flushIntervalMs;
|
|
10
11
|
maxBatchSize;
|
|
11
12
|
queue = [];
|
|
12
13
|
timer = null;
|
|
13
|
-
constructor(publishableKey, endpoint = DEFAULT_ENDPOINT, flushIntervalMs = DEFAULT_FLUSH_INTERVAL_MS, maxBatchSize = DEFAULT_MAX_BATCH_SIZE) {
|
|
14
|
+
constructor(publishableKey, environment, endpoint = DEFAULT_ENDPOINT, flushIntervalMs = DEFAULT_FLUSH_INTERVAL_MS, maxBatchSize = DEFAULT_MAX_BATCH_SIZE) {
|
|
14
15
|
this.publishableKey = publishableKey;
|
|
16
|
+
this.environment = environment;
|
|
15
17
|
this.endpoint = endpoint;
|
|
16
18
|
this.flushIntervalMs = flushIntervalMs;
|
|
17
19
|
this.maxBatchSize = maxBatchSize;
|
|
@@ -32,7 +34,11 @@ class Transport {
|
|
|
32
34
|
return;
|
|
33
35
|
const events = this.queue;
|
|
34
36
|
this.queue = [];
|
|
35
|
-
const body = JSON.stringify({
|
|
37
|
+
const body = JSON.stringify({
|
|
38
|
+
publishableKey: this.publishableKey,
|
|
39
|
+
environment: this.environment,
|
|
40
|
+
events
|
|
41
|
+
});
|
|
36
42
|
if (useBeacon && navigator.sendBeacon) {
|
|
37
43
|
const blob = new Blob([body], { type: "application/json" });
|
|
38
44
|
navigator.sendBeacon(this.endpoint, blob);
|
|
@@ -130,12 +136,24 @@ function installXhrInterceptor(emit) {
|
|
|
130
136
|
|
|
131
137
|
// src/index.ts
|
|
132
138
|
var transport = null;
|
|
139
|
+
var LOCAL_LIKE_ENVIRONMENTS = /^(development|dev|local|test)$/i;
|
|
133
140
|
function init(options) {
|
|
134
141
|
if (transport)
|
|
135
142
|
return;
|
|
136
143
|
if (typeof window === "undefined")
|
|
137
144
|
return;
|
|
138
|
-
|
|
145
|
+
if (!options.environment) {
|
|
146
|
+
console.warn("[atsail] init() requires an `environment` option — SDK not started");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const isLocalLike = LOCAL_LIKE_ENVIRONMENTS.test(options.environment.trim());
|
|
150
|
+
if (isLocalLike && !options.enabled) {
|
|
151
|
+
console.warn(`[atsail] staying quiet in environment "${options.environment}" — pass enabled: true to capture anyway`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
transport = new Transport(options.publishableKey, options.environment, options.endpoint, options.flushIntervalMs, options.maxBatchSize);
|
|
155
|
+
transport.enqueue({ type: "init", timestamp: Date.now() });
|
|
156
|
+
transport.flush();
|
|
139
157
|
const emit = transport.enqueue.bind(transport);
|
|
140
158
|
installGlobalHandlers(emit);
|
|
141
159
|
installFetchInterceptor(emit);
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { AtsailEvent } from "./types";
|
|
2
2
|
export declare class Transport {
|
|
3
3
|
private readonly publishableKey;
|
|
4
|
+
private readonly environment;
|
|
4
5
|
private readonly endpoint;
|
|
5
6
|
private readonly flushIntervalMs;
|
|
6
7
|
private readonly maxBatchSize;
|
|
7
8
|
private queue;
|
|
8
9
|
private timer;
|
|
9
|
-
constructor(publishableKey: string, endpoint?: string, flushIntervalMs?: number, maxBatchSize?: number);
|
|
10
|
+
constructor(publishableKey: string, environment: string, endpoint?: string, flushIntervalMs?: number, maxBatchSize?: number);
|
|
10
11
|
enqueue(event: AtsailEvent): void;
|
|
11
12
|
flush(useBeacon?: boolean): void;
|
|
12
13
|
destroy(): void;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export type EventLevel = "info" | "warning" | "error";
|
|
2
2
|
export type AtsailEvent = {
|
|
3
|
+
type: "init";
|
|
4
|
+
timestamp: number;
|
|
5
|
+
} | {
|
|
3
6
|
type: "exception";
|
|
4
7
|
message: string;
|
|
5
8
|
stack?: string;
|
|
@@ -30,6 +33,8 @@ export type AtsailEvent = {
|
|
|
30
33
|
};
|
|
31
34
|
export type InitOptions = {
|
|
32
35
|
publishableKey: string;
|
|
36
|
+
environment: string;
|
|
37
|
+
enabled?: boolean;
|
|
33
38
|
endpoint?: string;
|
|
34
39
|
flushIntervalMs?: number;
|
|
35
40
|
maxBatchSize?: number;
|