@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,413 @@
|
|
|
1
|
+
import { parseSessionHeader, SESSION_HEADER } from './chunk-VNCWOGTI.js';
|
|
2
|
+
import { compatLine, SDK_VERSION, setScopeManager, getClient, clientMethod, isThenable, captureException, getGlobalScope, warnAlways } from './chunk-WDKRKGYF.js';
|
|
3
|
+
|
|
4
|
+
// src/node/request.ts
|
|
5
|
+
var get = (o, k) => {
|
|
6
|
+
try {
|
|
7
|
+
return o && typeof o === "object" ? o[k] : void 0;
|
|
8
|
+
} catch {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var str = (v) => typeof v === "string" && v ? v : void 0;
|
|
13
|
+
function readHeader(headers, name) {
|
|
14
|
+
if (!headers || typeof headers !== "object") return void 0;
|
|
15
|
+
try {
|
|
16
|
+
const h = headers;
|
|
17
|
+
if (typeof h.get === "function") return h.get.call(headers, name) ?? void 0;
|
|
18
|
+
if (name in h) return h[name];
|
|
19
|
+
const lower = name.toLowerCase();
|
|
20
|
+
for (const k of Object.keys(h)) if (k.toLowerCase() === lower) return h[k];
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
function isRequestLike(v) {
|
|
26
|
+
if (!v || typeof v !== "object") return false;
|
|
27
|
+
const headers = get(v, "headers");
|
|
28
|
+
return !!headers && typeof headers === "object" && (typeof get(v, "method") === "string" || typeof get(v, "url") === "string");
|
|
29
|
+
}
|
|
30
|
+
var ROUTE_KEY = /* @__PURE__ */ Symbol.for("starko.sdk.route");
|
|
31
|
+
var joinRoute = (base, path) => (str(base) || "") + (Array.isArray(path) ? path.map(String).join("|") : String(path));
|
|
32
|
+
function trackRoute(req) {
|
|
33
|
+
try {
|
|
34
|
+
if (!req || typeof req !== "object" || Object.prototype.hasOwnProperty.call(req, ROUTE_KEY)) return;
|
|
35
|
+
const r = req;
|
|
36
|
+
let value = r.route;
|
|
37
|
+
r[ROUTE_KEY] = void 0;
|
|
38
|
+
Object.defineProperty(req, "route", {
|
|
39
|
+
configurable: true,
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: () => value,
|
|
42
|
+
set(v) {
|
|
43
|
+
value = v;
|
|
44
|
+
try {
|
|
45
|
+
const path = get(v, "path");
|
|
46
|
+
if (path !== void 0 && path !== null) r[ROUTE_KEY] = joinRoute(r.baseUrl, path);
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function routeOf(req) {
|
|
55
|
+
const tracked = get(req, ROUTE_KEY);
|
|
56
|
+
if (typeof tracked === "string" && tracked) return tracked;
|
|
57
|
+
const route = get(req, "route");
|
|
58
|
+
const path = get(route, "path");
|
|
59
|
+
if (path === void 0 || path === null) return void 0;
|
|
60
|
+
return joinRoute(get(req, "baseUrl"), path);
|
|
61
|
+
}
|
|
62
|
+
function urlOf(req) {
|
|
63
|
+
const raw = str(get(req, "originalUrl")) || str(get(req, "url")) || str(get(req, "path"));
|
|
64
|
+
if (!raw) return void 0;
|
|
65
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)) return raw;
|
|
66
|
+
const headers = get(req, "headers");
|
|
67
|
+
const host = str(readHeader(headers, "host")) || str(readHeader(headers, ":authority"));
|
|
68
|
+
if (!host) return raw;
|
|
69
|
+
let protocol = str(get(req, "protocol"));
|
|
70
|
+
if (!protocol) protocol = str(readHeader(headers, ":scheme")) || (get(get(req, "socket"), "encrypted") ? "https" : "http");
|
|
71
|
+
return `${protocol.replace(/:$/, "")}://${host}${raw.startsWith("/") ? raw : `/${raw}`}`;
|
|
72
|
+
}
|
|
73
|
+
function requestDataFrom(req) {
|
|
74
|
+
const out = {};
|
|
75
|
+
try {
|
|
76
|
+
const method = str(get(req, "method"));
|
|
77
|
+
if (method) out.method = method.toUpperCase();
|
|
78
|
+
const url = urlOf(req);
|
|
79
|
+
if (url) out.url = url;
|
|
80
|
+
const route = routeOf(req);
|
|
81
|
+
if (route) out.route = route;
|
|
82
|
+
const sid = parseSessionHeader(readHeader(get(req, "headers"), SESSION_HEADER));
|
|
83
|
+
if (sid) out.sessionId = sid;
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/node/scope.ts
|
|
90
|
+
var KEY = /* @__PURE__ */ Symbol.for(`starko.sdk.node.scope.v3/${compatLine(SDK_VERSION)}`);
|
|
91
|
+
var alsClass;
|
|
92
|
+
var resourceFn;
|
|
93
|
+
function state() {
|
|
94
|
+
const g = globalThis;
|
|
95
|
+
let s = g[KEY];
|
|
96
|
+
if (!s) g[KEY] = s = { serving: false, byRequest: /* @__PURE__ */ new WeakMap() };
|
|
97
|
+
return s;
|
|
98
|
+
}
|
|
99
|
+
function isNode() {
|
|
100
|
+
try {
|
|
101
|
+
const v = typeof process !== "undefined" && process.versions;
|
|
102
|
+
return !!(v && v.node && !v.bun && !v.deno);
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function storage() {
|
|
108
|
+
const s = state();
|
|
109
|
+
if (s.als) return s.als;
|
|
110
|
+
try {
|
|
111
|
+
const C = alsClass || globalThis.AsyncLocalStorage;
|
|
112
|
+
if (typeof C === "function") {
|
|
113
|
+
const als = new C();
|
|
114
|
+
const hooksBased = "kResourceStore" in als;
|
|
115
|
+
if (typeof als.enterWith !== "function") s.mode = "process";
|
|
116
|
+
else if (hooksBased) s.mode = typeof resourceFn === "function" ? "resources" : "process";
|
|
117
|
+
else s.mode = isNode() ? "frames" : "process";
|
|
118
|
+
s.resource = s.mode === "resources" ? resourceFn : void 0;
|
|
119
|
+
s.als = als;
|
|
120
|
+
}
|
|
121
|
+
} catch {
|
|
122
|
+
}
|
|
123
|
+
return s.als;
|
|
124
|
+
}
|
|
125
|
+
var syncStore;
|
|
126
|
+
var deref = (r) => r && typeof r.deref === "function" ? r.deref() : r;
|
|
127
|
+
function currentResource(s) {
|
|
128
|
+
try {
|
|
129
|
+
return s.resource ? s.resource() : void 0;
|
|
130
|
+
} catch {
|
|
131
|
+
return void 0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function stale(s, c) {
|
|
135
|
+
return s.mode === "resources" && !c.live && c.res !== void 0 && deref(c.res) === currentResource(s);
|
|
136
|
+
}
|
|
137
|
+
function owned(s, c) {
|
|
138
|
+
return c.live && (s.mode !== "resources" || deref(c.res) === currentResource(s));
|
|
139
|
+
}
|
|
140
|
+
var currentStore = () => {
|
|
141
|
+
try {
|
|
142
|
+
const st = storage();
|
|
143
|
+
if (!st) return syncStore;
|
|
144
|
+
const store = st.getStore();
|
|
145
|
+
return store && store.confined && stale(state(), store.confined) ? void 0 : store;
|
|
146
|
+
} catch {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
function beginServing() {
|
|
151
|
+
const s = state();
|
|
152
|
+
if (s.serving && s.base) return s.base;
|
|
153
|
+
const global = getGlobalScope();
|
|
154
|
+
const base = global.clone();
|
|
155
|
+
base.clearBreadcrumbs();
|
|
156
|
+
const init = s.initUser;
|
|
157
|
+
base.setUser(init && global.user === init ? init : null);
|
|
158
|
+
s.base = base;
|
|
159
|
+
s.serving = true;
|
|
160
|
+
return base;
|
|
161
|
+
}
|
|
162
|
+
var baseScope = () => beginServing();
|
|
163
|
+
function confine(from) {
|
|
164
|
+
try {
|
|
165
|
+
const s = state();
|
|
166
|
+
const st = storage();
|
|
167
|
+
if (!st || !st.enterWith || s.mode !== "frames" && s.mode !== "resources") return void 0;
|
|
168
|
+
const c = { live: true };
|
|
169
|
+
if (s.mode === "resources") {
|
|
170
|
+
const r = currentResource(s);
|
|
171
|
+
if (!r) return void 0;
|
|
172
|
+
c.res = typeof WeakRef === "function" ? new WeakRef(r) : r;
|
|
173
|
+
}
|
|
174
|
+
const scope = (from || baseScope()).clone();
|
|
175
|
+
st.enterWith({ scope, confined: c });
|
|
176
|
+
try {
|
|
177
|
+
queueMicrotask(() => {
|
|
178
|
+
c.live = false;
|
|
179
|
+
});
|
|
180
|
+
} catch {
|
|
181
|
+
c.live = false;
|
|
182
|
+
}
|
|
183
|
+
return scope;
|
|
184
|
+
} catch {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function unscopedRead(s) {
|
|
189
|
+
return s.mode === "process" || !s.als || !s.base ? getGlobalScope() : s.base;
|
|
190
|
+
}
|
|
191
|
+
function writableScope() {
|
|
192
|
+
const s = state();
|
|
193
|
+
const store = currentStore();
|
|
194
|
+
if (!s.serving) return store ? store.scope : getGlobalScope();
|
|
195
|
+
if (store && !store.confined) return store.scope;
|
|
196
|
+
if (store && store.confined && owned(s, store.confined)) return store.scope;
|
|
197
|
+
return confine(store ? store.scope : void 0) || (store ? store.scope : getGlobalScope());
|
|
198
|
+
}
|
|
199
|
+
var sameUser = (a, b) => {
|
|
200
|
+
if (!a || !b) return a === b;
|
|
201
|
+
try {
|
|
202
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
203
|
+
} catch {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var manager = {
|
|
208
|
+
getScope: writableScope,
|
|
209
|
+
peekScope() {
|
|
210
|
+
const s = state();
|
|
211
|
+
const store = currentStore();
|
|
212
|
+
if (store) return store.scope;
|
|
213
|
+
return s.serving ? unscopedRead(s) : getGlobalScope();
|
|
214
|
+
},
|
|
215
|
+
withScope(callback) {
|
|
216
|
+
const s = state();
|
|
217
|
+
const st = storage();
|
|
218
|
+
const current = st ? currentStore() : syncStore;
|
|
219
|
+
const from = current ? current.scope : s.serving ? unscopedRead(s) : getGlobalScope();
|
|
220
|
+
const store = { scope: from.clone(), request: current && current.request, source: current && current.source, key: current && current.key };
|
|
221
|
+
return st ? st.run(store, () => callback(store.scope)) : runSync(store, () => callback(store.scope));
|
|
222
|
+
},
|
|
223
|
+
scopeForUser(user) {
|
|
224
|
+
const s = state();
|
|
225
|
+
if (!s.serving) return writableScope();
|
|
226
|
+
const store = currentStore();
|
|
227
|
+
if (store && !store.confined) return store.scope;
|
|
228
|
+
if (s.mode === "process" || !s.als) {
|
|
229
|
+
if (!user) return getGlobalScope();
|
|
230
|
+
if (!s.warned) {
|
|
231
|
+
s.warned = true;
|
|
232
|
+
warnAlways(
|
|
233
|
+
"setUser()/identify() was called outside any request scope on a server that handles requests, in a runtime whose AsyncLocalStorage cannot confine it to the calling code: the user was NOT applied (it would reach other requests' errors). Call it inside the request (Starko.withScope, Starko.runWithRequestScope, Starko.wrapHandler), or pass `user` to init() for a process-wide user. This warning is printed once."
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
return void 0;
|
|
237
|
+
}
|
|
238
|
+
if (user && store && store.confined && store.scope.user && !sameUser(store.scope.user, user)) {
|
|
239
|
+
return confine() || writableScope();
|
|
240
|
+
}
|
|
241
|
+
return writableScope();
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
function installAsyncScopeManager(cls, executionAsyncResource) {
|
|
245
|
+
if (typeof cls === "function") alsClass = cls;
|
|
246
|
+
if (typeof executionAsyncResource === "function") resourceFn = executionAsyncResource;
|
|
247
|
+
const s = state();
|
|
248
|
+
if (s.als && s.mode === "process" && typeof cls === "function" && typeof executionAsyncResource === "function") {
|
|
249
|
+
s.als = void 0;
|
|
250
|
+
s.mode = void 0;
|
|
251
|
+
}
|
|
252
|
+
setScopeManager(manager);
|
|
253
|
+
}
|
|
254
|
+
function markServing() {
|
|
255
|
+
try {
|
|
256
|
+
beginServing();
|
|
257
|
+
} catch {
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function noteInit(user) {
|
|
261
|
+
try {
|
|
262
|
+
const s = state();
|
|
263
|
+
s.initUser = user;
|
|
264
|
+
if (s.serving && s.base) s.base.setUser(user);
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function getCurrentStore() {
|
|
269
|
+
return currentStore();
|
|
270
|
+
}
|
|
271
|
+
function readScope() {
|
|
272
|
+
return manager.peekScope();
|
|
273
|
+
}
|
|
274
|
+
function storeOf(req) {
|
|
275
|
+
try {
|
|
276
|
+
return req && typeof req === "object" ? state().byRequest.get(req) : void 0;
|
|
277
|
+
} catch {
|
|
278
|
+
return void 0;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function linkRequest(req, store) {
|
|
282
|
+
try {
|
|
283
|
+
state().byRequest.set(req, store);
|
|
284
|
+
} catch {
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function runInStore(store, fn) {
|
|
288
|
+
const st = storage();
|
|
289
|
+
return st ? st.run(store, fn) : runSync(store, fn);
|
|
290
|
+
}
|
|
291
|
+
function runSync(store, fn) {
|
|
292
|
+
const prev = syncStore;
|
|
293
|
+
syncStore = store;
|
|
294
|
+
try {
|
|
295
|
+
return fn();
|
|
296
|
+
} finally {
|
|
297
|
+
syncStore = prev;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
var asGetter = (request) => typeof request === "function" ? request : request ? () => request : void 0;
|
|
301
|
+
function openRequestScope(fn, request, source, from, key) {
|
|
302
|
+
let st;
|
|
303
|
+
let store;
|
|
304
|
+
try {
|
|
305
|
+
installAsyncScopeManager();
|
|
306
|
+
st = storage();
|
|
307
|
+
const base = beginServing();
|
|
308
|
+
store = { scope: (from || base).clone(), request: asGetter(request), source, key: key || source || {} };
|
|
309
|
+
if (source) state().byRequest.set(source, store);
|
|
310
|
+
} catch {
|
|
311
|
+
return fn(readScope());
|
|
312
|
+
}
|
|
313
|
+
if (!st) return runSync(store, () => fn(store.scope));
|
|
314
|
+
return st.run(store, () => fn(store.scope));
|
|
315
|
+
}
|
|
316
|
+
function runWithRequestScope(fn, request) {
|
|
317
|
+
return openRequestScope(fn, request);
|
|
318
|
+
}
|
|
319
|
+
function getRequestData() {
|
|
320
|
+
try {
|
|
321
|
+
const r = currentStore()?.request;
|
|
322
|
+
return r ? r() : void 0;
|
|
323
|
+
} catch {
|
|
324
|
+
return void 0;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function currentRequestKey() {
|
|
328
|
+
try {
|
|
329
|
+
return currentStore()?.key;
|
|
330
|
+
} catch {
|
|
331
|
+
return void 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/node/handler.ts
|
|
336
|
+
function platformWaitUntil() {
|
|
337
|
+
try {
|
|
338
|
+
const g = globalThis;
|
|
339
|
+
for (const key of ["@next/request-context", "@vercel/request-context"]) {
|
|
340
|
+
const holder = g[Symbol.for(key)];
|
|
341
|
+
const ctx = holder && typeof holder.get === "function" ? holder.get() : void 0;
|
|
342
|
+
if (ctx && typeof ctx.waitUntil === "function") return ctx.waitUntil.bind(ctx);
|
|
343
|
+
}
|
|
344
|
+
const cf = g[/* @__PURE__ */ Symbol.for("__cloudflare-context__")];
|
|
345
|
+
const cfCtx = cf && cf.ctx;
|
|
346
|
+
if (cfCtx && typeof cfCtx.waitUntil === "function") return cfCtx.waitUntil.bind(cfCtx);
|
|
347
|
+
} catch {
|
|
348
|
+
}
|
|
349
|
+
return void 0;
|
|
350
|
+
}
|
|
351
|
+
function flushIfPending(timeoutMs, skipBusy = false) {
|
|
352
|
+
try {
|
|
353
|
+
const c = getClient();
|
|
354
|
+
const flush = clientMethod(c, "flush");
|
|
355
|
+
if (!flush) return Promise.resolve(true);
|
|
356
|
+
const pending = clientMethod(c, "hasPending");
|
|
357
|
+
if (pending && !pending()) return Promise.resolve(true);
|
|
358
|
+
const busy = clientMethod(c, "isSendBusy");
|
|
359
|
+
if (skipBusy && busy && busy()) return Promise.resolve(false);
|
|
360
|
+
return Promise.resolve(flush(timeoutMs)).catch(() => false);
|
|
361
|
+
} catch {
|
|
362
|
+
return Promise.resolve(false);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function wrapHandler(fn, options = {}) {
|
|
366
|
+
const timeout = typeof options.flushTimeout === "number" && options.flushTimeout >= 0 ? options.flushTimeout : 2e3;
|
|
367
|
+
const capture = (err) => {
|
|
368
|
+
try {
|
|
369
|
+
captureException(err, { mechanism: { type: "instrument", handled: false } });
|
|
370
|
+
} catch {
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
return function starkoWrappedHandler(...args) {
|
|
374
|
+
let data;
|
|
375
|
+
try {
|
|
376
|
+
data = options.getRequestData ? options.getRequestData(...args) : isRequestLike(args[0]) ? requestDataFrom(args[0]) : void 0;
|
|
377
|
+
} catch {
|
|
378
|
+
data = void 0;
|
|
379
|
+
}
|
|
380
|
+
return runWithRequestScope(() => {
|
|
381
|
+
let out;
|
|
382
|
+
try {
|
|
383
|
+
out = fn.apply(this, args);
|
|
384
|
+
} catch (err) {
|
|
385
|
+
capture(err);
|
|
386
|
+
void flushIfPending(timeout);
|
|
387
|
+
throw err;
|
|
388
|
+
}
|
|
389
|
+
if (!isThenable(out)) {
|
|
390
|
+
void flushIfPending(timeout);
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
const settle = async () => {
|
|
394
|
+
const waitUntil = platformWaitUntil();
|
|
395
|
+
if (waitUntil) waitUntil(flushIfPending(timeout));
|
|
396
|
+
else await flushIfPending(timeout);
|
|
397
|
+
};
|
|
398
|
+
return Promise.resolve(out).then(
|
|
399
|
+
async (value) => {
|
|
400
|
+
await settle();
|
|
401
|
+
return value;
|
|
402
|
+
},
|
|
403
|
+
async (err) => {
|
|
404
|
+
capture(err);
|
|
405
|
+
await settle();
|
|
406
|
+
throw err;
|
|
407
|
+
}
|
|
408
|
+
);
|
|
409
|
+
}, data);
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export { currentRequestKey, flushIfPending, getCurrentStore, getRequestData, installAsyncScopeManager, linkRequest, markServing, noteInit, openRequestScope, platformWaitUntil, readScope, requestDataFrom, runInStore, runWithRequestScope, storeOf, trackRoute, wrapHandler };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/types/wire.ts
|
|
11
|
+
var WIRE_VERSION = 1;
|
|
12
|
+
var LIMITS = {
|
|
13
|
+
MAX_EVENTS_PER_ENVELOPE: 20,
|
|
14
|
+
/** Bytes of the request body as sent (after gzip when compressed). */
|
|
15
|
+
MAX_BODY_BYTES: 512 * 1024,
|
|
16
|
+
/** Bytes after decompression. */
|
|
17
|
+
MAX_INFLATED_BYTES: 2 * 1024 * 1024,
|
|
18
|
+
MAX_EXCEPTIONS: 10,
|
|
19
|
+
/** Beyond it the 25 most recent and the 25 oldest frames are kept (the middle of a deep recursion is dropped). */
|
|
20
|
+
MAX_FRAMES: 50,
|
|
21
|
+
/** Distinct `chunk_id`s the server resolves per event; frames of further chunks stay unresolved. */
|
|
22
|
+
MAX_CHUNK_IDS_PER_EVENT: 8,
|
|
23
|
+
/** Nesting depth of the JSON body; deeper bodies are rejected before any processing. */
|
|
24
|
+
MAX_JSON_DEPTH: 20,
|
|
25
|
+
MAX_TYPE: 200,
|
|
26
|
+
MAX_VALUE: 2e3,
|
|
27
|
+
MAX_FILENAME: 1e3,
|
|
28
|
+
MAX_FUNCTION: 300,
|
|
29
|
+
MAX_CONTEXT_LINE: 300,
|
|
30
|
+
/** Lines in each of pre_context / post_context. */
|
|
31
|
+
MAX_CONTEXT_LINES: 7,
|
|
32
|
+
MAX_BREADCRUMBS: 50,
|
|
33
|
+
/** Serialized bytes of all breadcrumbs. */
|
|
34
|
+
MAX_BREADCRUMB_BYTES: 32 * 1024,
|
|
35
|
+
MAX_TAGS: 50,
|
|
36
|
+
MAX_TAG_KEY: 64,
|
|
37
|
+
MAX_TAG_VALUE: 256,
|
|
38
|
+
/** Serialized bytes of `extra` and of `contexts`, each. */
|
|
39
|
+
MAX_EXTRA_BYTES: 16 * 1024,
|
|
40
|
+
MAX_FINGERPRINT: 128,
|
|
41
|
+
MAX_RELEASE: 128,
|
|
42
|
+
MAX_ENVIRONMENT: 64,
|
|
43
|
+
MAX_URL: 2048
|
|
44
|
+
};
|
|
45
|
+
var SESSION_ID_PATTERN = /^[A-Za-z0-9-]{8,70}$/;
|
|
46
|
+
var PATHS = {
|
|
47
|
+
INGEST: "/api/v1/ingest/errors",
|
|
48
|
+
CONFIG: "/api/v1/ingest/config",
|
|
49
|
+
SOURCEMAPS_CHECK: "/api/v1/sourcemaps/check",
|
|
50
|
+
SOURCEMAPS_UPLOAD: "/api/v1/sourcemaps/upload",
|
|
51
|
+
SOURCEMAPS_COMPLETE: "/api/v1/sourcemaps/complete",
|
|
52
|
+
/** Bulk upload (wire format v1, upload v2): see "Source-map bulk upload" below. */
|
|
53
|
+
SOURCEMAPS_BULK_CHECK: "/api/v1/sourcemaps/bulk/check",
|
|
54
|
+
SOURCEMAPS_BULK_START: "/api/v1/sourcemaps/bulk/start",
|
|
55
|
+
SOURCEMAPS_BULK_FINISH: "/api/v1/sourcemaps/bulk/finish"
|
|
56
|
+
};
|
|
57
|
+
var DEFAULT_HOST = "https://v2.starko.one";
|
|
58
|
+
var SENSITIVE_QUERY_PARAMS = [
|
|
59
|
+
"token",
|
|
60
|
+
"access_token",
|
|
61
|
+
"id_token",
|
|
62
|
+
"refresh_token",
|
|
63
|
+
"code",
|
|
64
|
+
"key",
|
|
65
|
+
"api_key",
|
|
66
|
+
"apikey",
|
|
67
|
+
"secret",
|
|
68
|
+
"password",
|
|
69
|
+
"passwd",
|
|
70
|
+
"pwd",
|
|
71
|
+
"auth",
|
|
72
|
+
"authorization",
|
|
73
|
+
"session",
|
|
74
|
+
"sessionid",
|
|
75
|
+
"sid",
|
|
76
|
+
"sig",
|
|
77
|
+
"signature",
|
|
78
|
+
"jwt",
|
|
79
|
+
"otp",
|
|
80
|
+
"pin",
|
|
81
|
+
"email",
|
|
82
|
+
"phone",
|
|
83
|
+
"ssn",
|
|
84
|
+
"x-amz-signature",
|
|
85
|
+
"x-amz-credential",
|
|
86
|
+
"x-amz-security-token"
|
|
87
|
+
];
|
|
88
|
+
var REDACTED = "[redacted]";
|
|
89
|
+
var SOURCEMAP_PART_BYTES = 3 * 1024 * 1024;
|
|
90
|
+
var SOURCEMAP_MAX_BYTES = 64 * 1024 * 1024;
|
|
91
|
+
var SOURCEMAP_MAX_PARTS = 32;
|
|
92
|
+
var SOURCEMAP_MAX_CHUNKS_PER_CHECK = 500;
|
|
93
|
+
var SOURCEMAP_MAX_FILE_NAME = 512;
|
|
94
|
+
var SOURCEMAP_ROUTE_MAX_SECONDS = {
|
|
95
|
+
CHECK: 30,
|
|
96
|
+
UPLOAD: 60,
|
|
97
|
+
COMPLETE: 60,
|
|
98
|
+
BULK_CHECK: 30,
|
|
99
|
+
BULK_START: 30,
|
|
100
|
+
BULK_FINISH: 120
|
|
101
|
+
};
|
|
102
|
+
var SOURCEMAP_BULK_MAX_CHECK = 1e3;
|
|
103
|
+
var SOURCEMAP_BULK_MAX_MAPS = 200;
|
|
104
|
+
var SOURCEMAP_BULK_MAX_OBJECT_BYTES = Math.ceil(SOURCEMAP_MAX_BYTES * 1.01);
|
|
105
|
+
var SOURCEMAP_BULK_UPLOAD_CONCURRENCY = 16;
|
|
106
|
+
var SOURCEMAP_BULK_REQUEST_CONCURRENCY = 2;
|
|
107
|
+
var SOURCEMAP_BULK_VERIFY_PER_WORKSPACE = 6;
|
|
108
|
+
var DEBUG_ID_GLOBAL = "_starkoDebugIds";
|
|
109
|
+
var NATIVE_DEBUG_ID_GLOBAL = "_debugIds";
|
|
110
|
+
var RELEASE_GLOBAL = "_starkoRelease";
|
|
111
|
+
var DEBUG_ID_COMMENT = "//# debugId=";
|
|
112
|
+
var DEBUG_ID_NAMESPACE = "6f2d3c1e-9b4a-4f07-8a55-7c1e0d9b2a41";
|
|
113
|
+
|
|
114
|
+
// package.json
|
|
115
|
+
var version = "0.1.0-beta.1";
|
|
116
|
+
|
|
117
|
+
exports.DEBUG_ID_COMMENT = DEBUG_ID_COMMENT;
|
|
118
|
+
exports.DEBUG_ID_GLOBAL = DEBUG_ID_GLOBAL;
|
|
119
|
+
exports.DEBUG_ID_NAMESPACE = DEBUG_ID_NAMESPACE;
|
|
120
|
+
exports.DEFAULT_HOST = DEFAULT_HOST;
|
|
121
|
+
exports.LIMITS = LIMITS;
|
|
122
|
+
exports.NATIVE_DEBUG_ID_GLOBAL = NATIVE_DEBUG_ID_GLOBAL;
|
|
123
|
+
exports.PATHS = PATHS;
|
|
124
|
+
exports.REDACTED = REDACTED;
|
|
125
|
+
exports.RELEASE_GLOBAL = RELEASE_GLOBAL;
|
|
126
|
+
exports.SENSITIVE_QUERY_PARAMS = SENSITIVE_QUERY_PARAMS;
|
|
127
|
+
exports.SESSION_ID_PATTERN = SESSION_ID_PATTERN;
|
|
128
|
+
exports.SOURCEMAP_BULK_MAX_CHECK = SOURCEMAP_BULK_MAX_CHECK;
|
|
129
|
+
exports.SOURCEMAP_BULK_MAX_MAPS = SOURCEMAP_BULK_MAX_MAPS;
|
|
130
|
+
exports.SOURCEMAP_BULK_MAX_OBJECT_BYTES = SOURCEMAP_BULK_MAX_OBJECT_BYTES;
|
|
131
|
+
exports.SOURCEMAP_BULK_REQUEST_CONCURRENCY = SOURCEMAP_BULK_REQUEST_CONCURRENCY;
|
|
132
|
+
exports.SOURCEMAP_BULK_UPLOAD_CONCURRENCY = SOURCEMAP_BULK_UPLOAD_CONCURRENCY;
|
|
133
|
+
exports.SOURCEMAP_BULK_VERIFY_PER_WORKSPACE = SOURCEMAP_BULK_VERIFY_PER_WORKSPACE;
|
|
134
|
+
exports.SOURCEMAP_MAX_BYTES = SOURCEMAP_MAX_BYTES;
|
|
135
|
+
exports.SOURCEMAP_MAX_CHUNKS_PER_CHECK = SOURCEMAP_MAX_CHUNKS_PER_CHECK;
|
|
136
|
+
exports.SOURCEMAP_MAX_FILE_NAME = SOURCEMAP_MAX_FILE_NAME;
|
|
137
|
+
exports.SOURCEMAP_MAX_PARTS = SOURCEMAP_MAX_PARTS;
|
|
138
|
+
exports.SOURCEMAP_PART_BYTES = SOURCEMAP_PART_BYTES;
|
|
139
|
+
exports.SOURCEMAP_ROUTE_MAX_SECONDS = SOURCEMAP_ROUTE_MAX_SECONDS;
|
|
140
|
+
exports.WIRE_VERSION = WIRE_VERSION;
|
|
141
|
+
exports.__require = __require;
|
|
142
|
+
exports.version = version;
|