@starko-one/sdk 0.0.0-stage → 0.1.0-beta.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/CHANGELOG.md +248 -0
- package/LICENSE +17 -0
- package/NOTICE +58 -0
- package/README.md +81 -2
- package/dist/api-BAFm4Lxj.d.ts +558 -0
- package/dist/api-DNrctwJu.d.cts +558 -0
- package/dist/browser/index.cjs +168 -0
- package/dist/browser/index.d.cts +131 -0
- package/dist/browser/index.d.ts +131 -0
- package/dist/browser/index.js +7 -0
- package/dist/build/rollup.cjs +22 -0
- package/dist/build/rollup.d.cts +34 -0
- package/dist/build/rollup.d.ts +34 -0
- package/dist/build/rollup.js +3 -0
- package/dist/build/vite.cjs +51 -0
- package/dist/build/vite.d.cts +23 -0
- package/dist/build/vite.d.ts +23 -0
- package/dist/build/vite.js +46 -0
- package/dist/build/webpack.cjs +18 -0
- package/dist/build/webpack.d.cts +39 -0
- package/dist/build/webpack.d.ts +39 -0
- package/dist/build/webpack.js +3 -0
- package/dist/chunk-2PM4FRM5.cjs +431 -0
- package/dist/chunk-335HNCOJ.js +249 -0
- package/dist/chunk-3AW5B2WW.js +115 -0
- package/dist/chunk-3R5TQAWD.js +216 -0
- package/dist/chunk-6H5MOPTQ.cjs +1230 -0
- package/dist/chunk-7TKNT3QJ.cjs +2487 -0
- package/dist/chunk-A4WLNFMU.cjs +220 -0
- package/dist/chunk-ALYFFOPR.cjs +134 -0
- package/dist/chunk-BVVFVRMO.js +1113 -0
- package/dist/chunk-CIHNKN62.cjs +15 -0
- package/dist/chunk-CMGCH6HD.js +1212 -0
- package/dist/chunk-D6QAPQ7L.cjs +56 -0
- package/dist/chunk-DUO5V6WZ.js +213 -0
- package/dist/chunk-EC2WZ6PG.js +90 -0
- package/dist/chunk-EFURLFJT.cjs +187 -0
- package/dist/chunk-EROUORMY.js +53 -0
- package/dist/chunk-LXBXFOAP.cjs +96 -0
- package/dist/chunk-MF6SA6DB.js +563 -0
- package/dist/chunk-N5R6ORIB.js +413 -0
- package/dist/chunk-N6R6BWHK.cjs +142 -0
- package/dist/chunk-QAGGN2T7.cjs +225 -0
- package/dist/chunk-QV4HRIDD.cjs +659 -0
- package/dist/chunk-TKNDYQB3.cjs +583 -0
- package/dist/chunk-UI5YC4TH.js +131 -0
- package/dist/chunk-VEHZYLK6.cjs +1151 -0
- package/dist/chunk-VNCWOGTI.js +12 -0
- package/dist/chunk-VWNIOGE6.js +180 -0
- package/dist/chunk-WDKRKGYF.js +608 -0
- package/dist/chunk-XOZIXBUK.js +2462 -0
- package/dist/chunk-ZS3K3SDR.cjs +258 -0
- package/dist/cli/index.cjs +2780 -0
- package/dist/common-DLFAqL2d.d.cts +36 -0
- package/dist/common-DbSXkaw6.d.ts +36 -0
- package/dist/dedupe-Bh5riD8Z.d.cts +13 -0
- package/dist/dedupe-DoYiSx-9.d.ts +13 -0
- package/dist/handler-BcnsnvhF.d.cts +82 -0
- package/dist/handler-qHzilC9T.d.ts +82 -0
- package/dist/index.cjs +309 -0
- package/dist/index.d.cts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +4 -0
- package/dist/next/client.cjs +113 -0
- package/dist/next/client.d.cts +26 -0
- package/dist/next/client.d.ts +26 -0
- package/dist/next/client.js +41 -0
- package/dist/next/config.cjs +277 -0
- package/dist/next/config.d.cts +193 -0
- package/dist/next/config.d.ts +193 -0
- package/dist/next/config.js +263 -0
- package/dist/next/index.cjs +148 -0
- package/dist/next/index.d.cts +32 -0
- package/dist/next/index.d.ts +32 -0
- package/dist/next/index.js +59 -0
- package/dist/node/index.cjs +257 -0
- package/dist/node/index.d.cts +145 -0
- package/dist/node/index.d.ts +145 -0
- package/dist/node/index.js +83 -0
- package/dist/options-BUhWuWJX.d.cts +79 -0
- package/dist/options-BUhWuWJX.d.ts +79 -0
- package/dist/react/index.cjs +107 -0
- package/dist/react/index.d.cts +84 -0
- package/dist/react/index.d.ts +84 -0
- package/dist/react/index.js +103 -0
- package/dist/scope-D1ouJm2h.d.cts +628 -0
- package/dist/scope-D1ouJm2h.d.ts +628 -0
- package/dist/server-edge-7624N3WF.cjs +51 -0
- package/dist/server-edge-BEEXWL7T.js +48 -0
- package/dist/server-node-ET4LIPEC.cjs +27 -0
- package/dist/server-node-TQUVMZUC.js +24 -0
- package/dist/session-C_WzbEN2.d.cts +4 -0
- package/dist/session-C_WzbEN2.d.ts +4 -0
- package/dist/session-propagation-Pr0Zb9Zn.d.cts +30 -0
- package/dist/session-propagation-RM5py1bp.d.ts +30 -0
- package/dist/starko.min.js +6 -0
- package/docs/browser.md +386 -0
- package/docs/configuration.md +310 -0
- package/docs/nextjs.md +488 -0
- package/docs/node.md +427 -0
- package/docs/other-backends.md +232 -0
- package/docs/privacy.md +112 -0
- package/docs/react.md +187 -0
- package/docs/source-maps.md +482 -0
- package/docs/troubleshooting.md +263 -0
- package/docs/widget.md +84 -0
- package/docs/wire-format.md +547 -0
- package/package.json +191 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { originalOf, num, safeStringify, unref, utf8Length } from './chunk-WDKRKGYF.js';
|
|
2
|
+
import { PATHS } from './chunk-3AW5B2WW.js';
|
|
3
|
+
|
|
4
|
+
// src/browser/transport.ts
|
|
5
|
+
var KEEPALIVE_BUDGET = 60 * 1024;
|
|
6
|
+
var REQUEST_TIMEOUT_MS = 12e3;
|
|
7
|
+
function currentFetch() {
|
|
8
|
+
try {
|
|
9
|
+
const f = originalOf(globalThis, "fetch");
|
|
10
|
+
return typeof f === "function" ? f.bind(globalThis) : void 0;
|
|
11
|
+
} catch {
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var loadedFetch = currentFetch();
|
|
16
|
+
function parseRetryAfter(header, now = Date.now()) {
|
|
17
|
+
if (!header) return void 0;
|
|
18
|
+
const secs = Number(header);
|
|
19
|
+
if (!isNaN(secs)) return Math.max(0, secs);
|
|
20
|
+
const at = Date.parse(header);
|
|
21
|
+
return isNaN(at) ? void 0 : Math.max(0, Math.ceil((at - now) / 1e3));
|
|
22
|
+
}
|
|
23
|
+
function worst(results) {
|
|
24
|
+
const rank = (s) => s === 401 || s === 403 ? 6 : s === 413 ? 5 : s === 429 ? 4 : s === 0 || s >= 500 ? 3 : s >= 400 ? 2 : 1;
|
|
25
|
+
return results.reduce((a, b) => rank(b.status) > rank(a.status) ? b : a, { status: 200 });
|
|
26
|
+
}
|
|
27
|
+
function splitEnvelope(env, budget) {
|
|
28
|
+
const head = utf8Length(safeStringify({ ...env, events: [] }));
|
|
29
|
+
const out = [];
|
|
30
|
+
let cur = { ...env, events: [] };
|
|
31
|
+
let bytes = head;
|
|
32
|
+
for (const e of env.events) {
|
|
33
|
+
const size = utf8Length(safeStringify(e)) + 1;
|
|
34
|
+
if (cur.events.length && bytes + size > budget) {
|
|
35
|
+
out.push({ env: cur, bytes });
|
|
36
|
+
cur = { ...env, events: [] };
|
|
37
|
+
bytes = head;
|
|
38
|
+
}
|
|
39
|
+
cur.events.push(e);
|
|
40
|
+
bytes += size;
|
|
41
|
+
}
|
|
42
|
+
if (cur.events.length) out.push({ env: cur, bytes });
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
function makeFetchTransport(options) {
|
|
46
|
+
const host = options.host.replace(/\/+$/, "");
|
|
47
|
+
const timeoutMs = Math.max(1, num(options.timeoutMs, REQUEST_TIMEOUT_MS));
|
|
48
|
+
const getFetch = () => options.fetchImpl || loadedFetch || currentFetch();
|
|
49
|
+
let keepaliveBytes = 0;
|
|
50
|
+
const timed = (fallback, request) => {
|
|
51
|
+
const f = getFetch();
|
|
52
|
+
if (!f) return Promise.resolve(fallback);
|
|
53
|
+
let ctl;
|
|
54
|
+
try {
|
|
55
|
+
ctl = new AbortController();
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
let t;
|
|
59
|
+
let p;
|
|
60
|
+
try {
|
|
61
|
+
p = request(f, ctl && ctl.signal).catch(() => fallback);
|
|
62
|
+
} catch {
|
|
63
|
+
p = Promise.resolve(fallback);
|
|
64
|
+
}
|
|
65
|
+
const deadline = new Promise((r) => {
|
|
66
|
+
t = setTimeout(() => {
|
|
67
|
+
try {
|
|
68
|
+
if (ctl) ctl.abort();
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
r(fallback);
|
|
72
|
+
}, timeoutMs);
|
|
73
|
+
unref(t);
|
|
74
|
+
});
|
|
75
|
+
return Promise.race([p, deadline]).then((v) => {
|
|
76
|
+
clearTimeout(t);
|
|
77
|
+
return v;
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const post = (body, keepalive) => timed({ status: 0 }, async (f, signal) => {
|
|
81
|
+
const res = await f(host + PATHS.INGEST, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
body,
|
|
84
|
+
headers: { "Content-Type": "text/plain;charset=UTF-8" },
|
|
85
|
+
keepalive,
|
|
86
|
+
credentials: "omit",
|
|
87
|
+
redirect: "manual",
|
|
88
|
+
signal
|
|
89
|
+
});
|
|
90
|
+
const out = { status: res.type === "opaqueredirect" ? 302 : res.status };
|
|
91
|
+
try {
|
|
92
|
+
out.retryAfter = parseRetryAfter(res.headers.get("Retry-After"));
|
|
93
|
+
} catch {
|
|
94
|
+
}
|
|
95
|
+
if (out.status >= 400) {
|
|
96
|
+
try {
|
|
97
|
+
const reason = (await res.json())?.data?.reason;
|
|
98
|
+
if (typeof reason === "string") out.reason = reason;
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
async send(envelope, opts = {}) {
|
|
106
|
+
if (!opts || !opts.keepalive) return post(safeStringify(envelope), false);
|
|
107
|
+
const results = await Promise.all(
|
|
108
|
+
splitEnvelope(envelope, KEEPALIVE_BUDGET).map(({ env, bytes }) => {
|
|
109
|
+
const fits = keepaliveBytes + bytes <= KEEPALIVE_BUDGET;
|
|
110
|
+
if (fits) keepaliveBytes += bytes;
|
|
111
|
+
return post(safeStringify({ ...env, sent_at: Date.now() }), fits).then((r) => {
|
|
112
|
+
if (fits) keepaliveBytes -= bytes;
|
|
113
|
+
return r;
|
|
114
|
+
});
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
return worst(results);
|
|
118
|
+
},
|
|
119
|
+
fetchConfig() {
|
|
120
|
+
return timed(null, async (f, signal) => {
|
|
121
|
+
const res = await f(`${host}${PATHS.CONFIG}?workspace=${encodeURIComponent(options.workspaceKey)}`, { method: "GET", credentials: "omit", redirect: "manual", signal });
|
|
122
|
+
if (res.type === "opaqueredirect" || res.status >= 300 && res.status < 400) return null;
|
|
123
|
+
const json = await res.json();
|
|
124
|
+
const data = json && typeof json === "object" ? json.data : null;
|
|
125
|
+
return data && typeof data === "object" ? data : null;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { makeFetchTransport, parseRetryAfter };
|