@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,46 @@
|
|
|
1
|
+
import { createStarkoRollupPlugin } from '../chunk-3R5TQAWD.js';
|
|
2
|
+
import { resolveConnection, createLogger, NO_API_KEY_MESSAGE } from '../chunk-XOZIXBUK.js';
|
|
3
|
+
import '../chunk-3AW5B2WW.js';
|
|
4
|
+
|
|
5
|
+
// src/build/vite.ts
|
|
6
|
+
function starkoVitePlugin(options = {}) {
|
|
7
|
+
const connection = resolveConnection(options);
|
|
8
|
+
const logger = createLogger({ silent: options.silent, secrets: [connection.apiKey] });
|
|
9
|
+
let enabled = false;
|
|
10
|
+
let owner = "user";
|
|
11
|
+
let warnedNoKey = false;
|
|
12
|
+
const wanted = (command, mode, watch) => options.enabled ?? (command === "build" && mode === "production" && !watch);
|
|
13
|
+
const base = createStarkoRollupPlugin(options, {
|
|
14
|
+
name: "starko-vite-plugin",
|
|
15
|
+
isEnabled: () => enabled,
|
|
16
|
+
sourcemapOwner: () => owner
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
...base,
|
|
20
|
+
apply: "build",
|
|
21
|
+
enforce: "post",
|
|
22
|
+
config(userConfig, env) {
|
|
23
|
+
owner = "user";
|
|
24
|
+
if (!wanted(env.command, env.mode, userConfig.build?.watch) || !connection.apiKey) return;
|
|
25
|
+
if (!userConfig.build?.sourcemap) {
|
|
26
|
+
owner = "starko";
|
|
27
|
+
return { build: { sourcemap: "hidden" } };
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
},
|
|
31
|
+
configResolved(config) {
|
|
32
|
+
enabled = wanted(config.command, config.mode, config.build.watch);
|
|
33
|
+
if (enabled && !connection.apiKey) {
|
|
34
|
+
if (!warnedNoKey) logger.warn(NO_API_KEY_MESSAGE);
|
|
35
|
+
warnedNoKey = true;
|
|
36
|
+
enabled = false;
|
|
37
|
+
}
|
|
38
|
+
if (enabled && config.build.sourcemap === "inline") {
|
|
39
|
+
logger.warn("build.sourcemap is 'inline': inline source maps are not uploaded; use true or 'hidden'");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var vite_default = starkoVitePlugin;
|
|
45
|
+
|
|
46
|
+
export { vite_default as default, starkoVitePlugin };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var chunkEFURLFJT_cjs = require('../chunk-EFURLFJT.cjs');
|
|
6
|
+
require('../chunk-7TKNT3QJ.cjs');
|
|
7
|
+
require('../chunk-N6R6BWHK.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, "StarkoWebpackPlugin", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkEFURLFJT_cjs.StarkoWebpackPlugin; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "default", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkEFURLFJT_cjs.webpack_default; }
|
|
18
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
import { a as StarkoBuildOptions, S as SourcemapOwner } from '../options-BUhWuWJX.cjs';
|
|
3
|
+
|
|
4
|
+
interface StarkoWebpackPluginOptions extends StarkoBuildOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Upload before the output is written. Default true. Set false to only
|
|
7
|
+
* inject, when something else uploads the output (as `withStarko` does
|
|
8
|
+
* when Next runs its post-compile hook); nothing is deleted then either.
|
|
9
|
+
*/
|
|
10
|
+
upload?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** @internal Set by `withStarko`, which knows who asked Next for the maps. */
|
|
13
|
+
interface StarkoWebpackPluginInternals {
|
|
14
|
+
sourcemapOwner?: SourcemapOwner;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* webpack 5 plugin. Injects each emitted JS chunk with its debug id (snippet,
|
|
18
|
+
* trailing comment, `debugId` in its map) during asset processing, right after
|
|
19
|
+
* the source maps are made and before real content hashes, integrity
|
|
20
|
+
* manifests and emit; then uploads the maps from memory just before the
|
|
21
|
+
* output is written. `enabled` defaults to `mode: "production"`. Without an
|
|
22
|
+
* API key it changes nothing. Eval and inline devtools are not supported.
|
|
23
|
+
*
|
|
24
|
+
* Source maps: with no `devtool` and no source-map plugin of your own, the
|
|
25
|
+
* plugin adds hidden maps for the upload and deletes them (only those) from
|
|
26
|
+
* the compilation afterwards, whatever the upload's outcome, so they are
|
|
27
|
+
* never written. Maps your `devtool` or your own `SourceMapDevToolPlugin`
|
|
28
|
+
* produces are kept unless `deleteSourcemapsAfterUpload: true`; with an
|
|
29
|
+
* `EvalSourceMapDevToolPlugin` nothing is injected or uploaded.
|
|
30
|
+
*/
|
|
31
|
+
declare class StarkoWebpackPlugin {
|
|
32
|
+
private readonly options;
|
|
33
|
+
private readonly internals;
|
|
34
|
+
private readonly logger;
|
|
35
|
+
constructor(options?: StarkoWebpackPluginOptions, internals?: StarkoWebpackPluginInternals);
|
|
36
|
+
apply(compiler: Compiler): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { StarkoBuildOptions, StarkoWebpackPlugin, type StarkoWebpackPluginInternals, type StarkoWebpackPluginOptions, StarkoWebpackPlugin as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
import { a as StarkoBuildOptions, S as SourcemapOwner } from '../options-BUhWuWJX.js';
|
|
3
|
+
|
|
4
|
+
interface StarkoWebpackPluginOptions extends StarkoBuildOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Upload before the output is written. Default true. Set false to only
|
|
7
|
+
* inject, when something else uploads the output (as `withStarko` does
|
|
8
|
+
* when Next runs its post-compile hook); nothing is deleted then either.
|
|
9
|
+
*/
|
|
10
|
+
upload?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** @internal Set by `withStarko`, which knows who asked Next for the maps. */
|
|
13
|
+
interface StarkoWebpackPluginInternals {
|
|
14
|
+
sourcemapOwner?: SourcemapOwner;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* webpack 5 plugin. Injects each emitted JS chunk with its debug id (snippet,
|
|
18
|
+
* trailing comment, `debugId` in its map) during asset processing, right after
|
|
19
|
+
* the source maps are made and before real content hashes, integrity
|
|
20
|
+
* manifests and emit; then uploads the maps from memory just before the
|
|
21
|
+
* output is written. `enabled` defaults to `mode: "production"`. Without an
|
|
22
|
+
* API key it changes nothing. Eval and inline devtools are not supported.
|
|
23
|
+
*
|
|
24
|
+
* Source maps: with no `devtool` and no source-map plugin of your own, the
|
|
25
|
+
* plugin adds hidden maps for the upload and deletes them (only those) from
|
|
26
|
+
* the compilation afterwards, whatever the upload's outcome, so they are
|
|
27
|
+
* never written. Maps your `devtool` or your own `SourceMapDevToolPlugin`
|
|
28
|
+
* produces are kept unless `deleteSourcemapsAfterUpload: true`; with an
|
|
29
|
+
* `EvalSourceMapDevToolPlugin` nothing is injected or uploaded.
|
|
30
|
+
*/
|
|
31
|
+
declare class StarkoWebpackPlugin {
|
|
32
|
+
private readonly options;
|
|
33
|
+
private readonly internals;
|
|
34
|
+
private readonly logger;
|
|
35
|
+
constructor(options?: StarkoWebpackPluginOptions, internals?: StarkoWebpackPluginInternals);
|
|
36
|
+
apply(compiler: Compiler): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { StarkoBuildOptions, StarkoWebpackPlugin, type StarkoWebpackPluginInternals, type StarkoWebpackPluginOptions, StarkoWebpackPlugin as default };
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkCIHNKN62_cjs = require('./chunk-CIHNKN62.cjs');
|
|
4
|
+
var chunkQV4HRIDD_cjs = require('./chunk-QV4HRIDD.cjs');
|
|
5
|
+
|
|
6
|
+
// src/node/request.ts
|
|
7
|
+
var get = (o, k) => {
|
|
8
|
+
try {
|
|
9
|
+
return o && typeof o === "object" ? o[k] : void 0;
|
|
10
|
+
} catch {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var str = (v) => typeof v === "string" && v ? v : void 0;
|
|
15
|
+
function readHeader(headers, name) {
|
|
16
|
+
if (!headers || typeof headers !== "object") return void 0;
|
|
17
|
+
try {
|
|
18
|
+
const h = headers;
|
|
19
|
+
if (typeof h.get === "function") return h.get.call(headers, name) ?? void 0;
|
|
20
|
+
if (name in h) return h[name];
|
|
21
|
+
const lower = name.toLowerCase();
|
|
22
|
+
for (const k of Object.keys(h)) if (k.toLowerCase() === lower) return h[k];
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
function isRequestLike(v) {
|
|
28
|
+
if (!v || typeof v !== "object") return false;
|
|
29
|
+
const headers = get(v, "headers");
|
|
30
|
+
return !!headers && typeof headers === "object" && (typeof get(v, "method") === "string" || typeof get(v, "url") === "string");
|
|
31
|
+
}
|
|
32
|
+
var ROUTE_KEY = /* @__PURE__ */ Symbol.for("starko.sdk.route");
|
|
33
|
+
var joinRoute = (base, path) => (str(base) || "") + (Array.isArray(path) ? path.map(String).join("|") : String(path));
|
|
34
|
+
function trackRoute(req) {
|
|
35
|
+
try {
|
|
36
|
+
if (!req || typeof req !== "object" || Object.prototype.hasOwnProperty.call(req, ROUTE_KEY)) return;
|
|
37
|
+
const r = req;
|
|
38
|
+
let value = r.route;
|
|
39
|
+
r[ROUTE_KEY] = void 0;
|
|
40
|
+
Object.defineProperty(req, "route", {
|
|
41
|
+
configurable: true,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: () => value,
|
|
44
|
+
set(v) {
|
|
45
|
+
value = v;
|
|
46
|
+
try {
|
|
47
|
+
const path = get(v, "path");
|
|
48
|
+
if (path !== void 0 && path !== null) r[ROUTE_KEY] = joinRoute(r.baseUrl, path);
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function routeOf(req) {
|
|
57
|
+
const tracked = get(req, ROUTE_KEY);
|
|
58
|
+
if (typeof tracked === "string" && tracked) return tracked;
|
|
59
|
+
const route = get(req, "route");
|
|
60
|
+
const path = get(route, "path");
|
|
61
|
+
if (path === void 0 || path === null) return void 0;
|
|
62
|
+
return joinRoute(get(req, "baseUrl"), path);
|
|
63
|
+
}
|
|
64
|
+
function urlOf(req) {
|
|
65
|
+
const raw = str(get(req, "originalUrl")) || str(get(req, "url")) || str(get(req, "path"));
|
|
66
|
+
if (!raw) return void 0;
|
|
67
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)) return raw;
|
|
68
|
+
const headers = get(req, "headers");
|
|
69
|
+
const host = str(readHeader(headers, "host")) || str(readHeader(headers, ":authority"));
|
|
70
|
+
if (!host) return raw;
|
|
71
|
+
let protocol = str(get(req, "protocol"));
|
|
72
|
+
if (!protocol) protocol = str(readHeader(headers, ":scheme")) || (get(get(req, "socket"), "encrypted") ? "https" : "http");
|
|
73
|
+
return `${protocol.replace(/:$/, "")}://${host}${raw.startsWith("/") ? raw : `/${raw}`}`;
|
|
74
|
+
}
|
|
75
|
+
function requestDataFrom(req) {
|
|
76
|
+
const out = {};
|
|
77
|
+
try {
|
|
78
|
+
const method = str(get(req, "method"));
|
|
79
|
+
if (method) out.method = method.toUpperCase();
|
|
80
|
+
const url = urlOf(req);
|
|
81
|
+
if (url) out.url = url;
|
|
82
|
+
const route = routeOf(req);
|
|
83
|
+
if (route) out.route = route;
|
|
84
|
+
const sid = chunkCIHNKN62_cjs.parseSessionHeader(readHeader(get(req, "headers"), chunkCIHNKN62_cjs.SESSION_HEADER));
|
|
85
|
+
if (sid) out.sessionId = sid;
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/node/scope.ts
|
|
92
|
+
var KEY = /* @__PURE__ */ Symbol.for(`starko.sdk.node.scope.v3/${chunkQV4HRIDD_cjs.compatLine(chunkQV4HRIDD_cjs.SDK_VERSION)}`);
|
|
93
|
+
var alsClass;
|
|
94
|
+
var resourceFn;
|
|
95
|
+
function state() {
|
|
96
|
+
const g = globalThis;
|
|
97
|
+
let s = g[KEY];
|
|
98
|
+
if (!s) g[KEY] = s = { serving: false, byRequest: /* @__PURE__ */ new WeakMap() };
|
|
99
|
+
return s;
|
|
100
|
+
}
|
|
101
|
+
function isNode() {
|
|
102
|
+
try {
|
|
103
|
+
const v = typeof process !== "undefined" && process.versions;
|
|
104
|
+
return !!(v && v.node && !v.bun && !v.deno);
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function storage() {
|
|
110
|
+
const s = state();
|
|
111
|
+
if (s.als) return s.als;
|
|
112
|
+
try {
|
|
113
|
+
const C = alsClass || globalThis.AsyncLocalStorage;
|
|
114
|
+
if (typeof C === "function") {
|
|
115
|
+
const als = new C();
|
|
116
|
+
const hooksBased = "kResourceStore" in als;
|
|
117
|
+
if (typeof als.enterWith !== "function") s.mode = "process";
|
|
118
|
+
else if (hooksBased) s.mode = typeof resourceFn === "function" ? "resources" : "process";
|
|
119
|
+
else s.mode = isNode() ? "frames" : "process";
|
|
120
|
+
s.resource = s.mode === "resources" ? resourceFn : void 0;
|
|
121
|
+
s.als = als;
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
return s.als;
|
|
126
|
+
}
|
|
127
|
+
var syncStore;
|
|
128
|
+
var deref = (r) => r && typeof r.deref === "function" ? r.deref() : r;
|
|
129
|
+
function currentResource(s) {
|
|
130
|
+
try {
|
|
131
|
+
return s.resource ? s.resource() : void 0;
|
|
132
|
+
} catch {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function stale(s, c) {
|
|
137
|
+
return s.mode === "resources" && !c.live && c.res !== void 0 && deref(c.res) === currentResource(s);
|
|
138
|
+
}
|
|
139
|
+
function owned(s, c) {
|
|
140
|
+
return c.live && (s.mode !== "resources" || deref(c.res) === currentResource(s));
|
|
141
|
+
}
|
|
142
|
+
var currentStore = () => {
|
|
143
|
+
try {
|
|
144
|
+
const st = storage();
|
|
145
|
+
if (!st) return syncStore;
|
|
146
|
+
const store = st.getStore();
|
|
147
|
+
return store && store.confined && stale(state(), store.confined) ? void 0 : store;
|
|
148
|
+
} catch {
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
function beginServing() {
|
|
153
|
+
const s = state();
|
|
154
|
+
if (s.serving && s.base) return s.base;
|
|
155
|
+
const global = chunkQV4HRIDD_cjs.getGlobalScope();
|
|
156
|
+
const base = global.clone();
|
|
157
|
+
base.clearBreadcrumbs();
|
|
158
|
+
const init = s.initUser;
|
|
159
|
+
base.setUser(init && global.user === init ? init : null);
|
|
160
|
+
s.base = base;
|
|
161
|
+
s.serving = true;
|
|
162
|
+
return base;
|
|
163
|
+
}
|
|
164
|
+
var baseScope = () => beginServing();
|
|
165
|
+
function confine(from) {
|
|
166
|
+
try {
|
|
167
|
+
const s = state();
|
|
168
|
+
const st = storage();
|
|
169
|
+
if (!st || !st.enterWith || s.mode !== "frames" && s.mode !== "resources") return void 0;
|
|
170
|
+
const c = { live: true };
|
|
171
|
+
if (s.mode === "resources") {
|
|
172
|
+
const r = currentResource(s);
|
|
173
|
+
if (!r) return void 0;
|
|
174
|
+
c.res = typeof WeakRef === "function" ? new WeakRef(r) : r;
|
|
175
|
+
}
|
|
176
|
+
const scope = (from || baseScope()).clone();
|
|
177
|
+
st.enterWith({ scope, confined: c });
|
|
178
|
+
try {
|
|
179
|
+
queueMicrotask(() => {
|
|
180
|
+
c.live = false;
|
|
181
|
+
});
|
|
182
|
+
} catch {
|
|
183
|
+
c.live = false;
|
|
184
|
+
}
|
|
185
|
+
return scope;
|
|
186
|
+
} catch {
|
|
187
|
+
return void 0;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function unscopedRead(s) {
|
|
191
|
+
return s.mode === "process" || !s.als || !s.base ? chunkQV4HRIDD_cjs.getGlobalScope() : s.base;
|
|
192
|
+
}
|
|
193
|
+
function writableScope() {
|
|
194
|
+
const s = state();
|
|
195
|
+
const store = currentStore();
|
|
196
|
+
if (!s.serving) return store ? store.scope : chunkQV4HRIDD_cjs.getGlobalScope();
|
|
197
|
+
if (store && !store.confined) return store.scope;
|
|
198
|
+
if (store && store.confined && owned(s, store.confined)) return store.scope;
|
|
199
|
+
return confine(store ? store.scope : void 0) || (store ? store.scope : chunkQV4HRIDD_cjs.getGlobalScope());
|
|
200
|
+
}
|
|
201
|
+
var sameUser = (a, b) => {
|
|
202
|
+
if (!a || !b) return a === b;
|
|
203
|
+
try {
|
|
204
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var manager = {
|
|
210
|
+
getScope: writableScope,
|
|
211
|
+
peekScope() {
|
|
212
|
+
const s = state();
|
|
213
|
+
const store = currentStore();
|
|
214
|
+
if (store) return store.scope;
|
|
215
|
+
return s.serving ? unscopedRead(s) : chunkQV4HRIDD_cjs.getGlobalScope();
|
|
216
|
+
},
|
|
217
|
+
withScope(callback) {
|
|
218
|
+
const s = state();
|
|
219
|
+
const st = storage();
|
|
220
|
+
const current = st ? currentStore() : syncStore;
|
|
221
|
+
const from = current ? current.scope : s.serving ? unscopedRead(s) : chunkQV4HRIDD_cjs.getGlobalScope();
|
|
222
|
+
const store = { scope: from.clone(), request: current && current.request, source: current && current.source, key: current && current.key };
|
|
223
|
+
return st ? st.run(store, () => callback(store.scope)) : runSync(store, () => callback(store.scope));
|
|
224
|
+
},
|
|
225
|
+
scopeForUser(user) {
|
|
226
|
+
const s = state();
|
|
227
|
+
if (!s.serving) return writableScope();
|
|
228
|
+
const store = currentStore();
|
|
229
|
+
if (store && !store.confined) return store.scope;
|
|
230
|
+
if (s.mode === "process" || !s.als) {
|
|
231
|
+
if (!user) return chunkQV4HRIDD_cjs.getGlobalScope();
|
|
232
|
+
if (!s.warned) {
|
|
233
|
+
s.warned = true;
|
|
234
|
+
chunkQV4HRIDD_cjs.warnAlways(
|
|
235
|
+
"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."
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
if (user && store && store.confined && store.scope.user && !sameUser(store.scope.user, user)) {
|
|
241
|
+
return confine() || writableScope();
|
|
242
|
+
}
|
|
243
|
+
return writableScope();
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
function installAsyncScopeManager(cls, executionAsyncResource) {
|
|
247
|
+
if (typeof cls === "function") alsClass = cls;
|
|
248
|
+
if (typeof executionAsyncResource === "function") resourceFn = executionAsyncResource;
|
|
249
|
+
const s = state();
|
|
250
|
+
if (s.als && s.mode === "process" && typeof cls === "function" && typeof executionAsyncResource === "function") {
|
|
251
|
+
s.als = void 0;
|
|
252
|
+
s.mode = void 0;
|
|
253
|
+
}
|
|
254
|
+
chunkQV4HRIDD_cjs.setScopeManager(manager);
|
|
255
|
+
}
|
|
256
|
+
function markServing() {
|
|
257
|
+
try {
|
|
258
|
+
beginServing();
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function noteInit(user) {
|
|
263
|
+
try {
|
|
264
|
+
const s = state();
|
|
265
|
+
s.initUser = user;
|
|
266
|
+
if (s.serving && s.base) s.base.setUser(user);
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function getCurrentStore() {
|
|
271
|
+
return currentStore();
|
|
272
|
+
}
|
|
273
|
+
function readScope() {
|
|
274
|
+
return manager.peekScope();
|
|
275
|
+
}
|
|
276
|
+
function storeOf(req) {
|
|
277
|
+
try {
|
|
278
|
+
return req && typeof req === "object" ? state().byRequest.get(req) : void 0;
|
|
279
|
+
} catch {
|
|
280
|
+
return void 0;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function linkRequest(req, store) {
|
|
284
|
+
try {
|
|
285
|
+
state().byRequest.set(req, store);
|
|
286
|
+
} catch {
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function runInStore(store, fn) {
|
|
290
|
+
const st = storage();
|
|
291
|
+
return st ? st.run(store, fn) : runSync(store, fn);
|
|
292
|
+
}
|
|
293
|
+
function runSync(store, fn) {
|
|
294
|
+
const prev = syncStore;
|
|
295
|
+
syncStore = store;
|
|
296
|
+
try {
|
|
297
|
+
return fn();
|
|
298
|
+
} finally {
|
|
299
|
+
syncStore = prev;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
var asGetter = (request) => typeof request === "function" ? request : request ? () => request : void 0;
|
|
303
|
+
function openRequestScope(fn, request, source, from, key) {
|
|
304
|
+
let st;
|
|
305
|
+
let store;
|
|
306
|
+
try {
|
|
307
|
+
installAsyncScopeManager();
|
|
308
|
+
st = storage();
|
|
309
|
+
const base = beginServing();
|
|
310
|
+
store = { scope: (from || base).clone(), request: asGetter(request), source, key: key || source || {} };
|
|
311
|
+
if (source) state().byRequest.set(source, store);
|
|
312
|
+
} catch {
|
|
313
|
+
return fn(readScope());
|
|
314
|
+
}
|
|
315
|
+
if (!st) return runSync(store, () => fn(store.scope));
|
|
316
|
+
return st.run(store, () => fn(store.scope));
|
|
317
|
+
}
|
|
318
|
+
function runWithRequestScope(fn, request) {
|
|
319
|
+
return openRequestScope(fn, request);
|
|
320
|
+
}
|
|
321
|
+
function getRequestData() {
|
|
322
|
+
try {
|
|
323
|
+
const r = currentStore()?.request;
|
|
324
|
+
return r ? r() : void 0;
|
|
325
|
+
} catch {
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function currentRequestKey() {
|
|
330
|
+
try {
|
|
331
|
+
return currentStore()?.key;
|
|
332
|
+
} catch {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/node/handler.ts
|
|
338
|
+
function platformWaitUntil() {
|
|
339
|
+
try {
|
|
340
|
+
const g = globalThis;
|
|
341
|
+
for (const key of ["@next/request-context", "@vercel/request-context"]) {
|
|
342
|
+
const holder = g[Symbol.for(key)];
|
|
343
|
+
const ctx = holder && typeof holder.get === "function" ? holder.get() : void 0;
|
|
344
|
+
if (ctx && typeof ctx.waitUntil === "function") return ctx.waitUntil.bind(ctx);
|
|
345
|
+
}
|
|
346
|
+
const cf = g[/* @__PURE__ */ Symbol.for("__cloudflare-context__")];
|
|
347
|
+
const cfCtx = cf && cf.ctx;
|
|
348
|
+
if (cfCtx && typeof cfCtx.waitUntil === "function") return cfCtx.waitUntil.bind(cfCtx);
|
|
349
|
+
} catch {
|
|
350
|
+
}
|
|
351
|
+
return void 0;
|
|
352
|
+
}
|
|
353
|
+
function flushIfPending(timeoutMs, skipBusy = false) {
|
|
354
|
+
try {
|
|
355
|
+
const c = chunkQV4HRIDD_cjs.getClient();
|
|
356
|
+
const flush = chunkQV4HRIDD_cjs.clientMethod(c, "flush");
|
|
357
|
+
if (!flush) return Promise.resolve(true);
|
|
358
|
+
const pending = chunkQV4HRIDD_cjs.clientMethod(c, "hasPending");
|
|
359
|
+
if (pending && !pending()) return Promise.resolve(true);
|
|
360
|
+
const busy = chunkQV4HRIDD_cjs.clientMethod(c, "isSendBusy");
|
|
361
|
+
if (skipBusy && busy && busy()) return Promise.resolve(false);
|
|
362
|
+
return Promise.resolve(flush(timeoutMs)).catch(() => false);
|
|
363
|
+
} catch {
|
|
364
|
+
return Promise.resolve(false);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function wrapHandler(fn, options = {}) {
|
|
368
|
+
const timeout = typeof options.flushTimeout === "number" && options.flushTimeout >= 0 ? options.flushTimeout : 2e3;
|
|
369
|
+
const capture = (err) => {
|
|
370
|
+
try {
|
|
371
|
+
chunkQV4HRIDD_cjs.captureException(err, { mechanism: { type: "instrument", handled: false } });
|
|
372
|
+
} catch {
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
return function starkoWrappedHandler(...args) {
|
|
376
|
+
let data;
|
|
377
|
+
try {
|
|
378
|
+
data = options.getRequestData ? options.getRequestData(...args) : isRequestLike(args[0]) ? requestDataFrom(args[0]) : void 0;
|
|
379
|
+
} catch {
|
|
380
|
+
data = void 0;
|
|
381
|
+
}
|
|
382
|
+
return runWithRequestScope(() => {
|
|
383
|
+
let out;
|
|
384
|
+
try {
|
|
385
|
+
out = fn.apply(this, args);
|
|
386
|
+
} catch (err) {
|
|
387
|
+
capture(err);
|
|
388
|
+
void flushIfPending(timeout);
|
|
389
|
+
throw err;
|
|
390
|
+
}
|
|
391
|
+
if (!chunkQV4HRIDD_cjs.isThenable(out)) {
|
|
392
|
+
void flushIfPending(timeout);
|
|
393
|
+
return out;
|
|
394
|
+
}
|
|
395
|
+
const settle = async () => {
|
|
396
|
+
const waitUntil = platformWaitUntil();
|
|
397
|
+
if (waitUntil) waitUntil(flushIfPending(timeout));
|
|
398
|
+
else await flushIfPending(timeout);
|
|
399
|
+
};
|
|
400
|
+
return Promise.resolve(out).then(
|
|
401
|
+
async (value) => {
|
|
402
|
+
await settle();
|
|
403
|
+
return value;
|
|
404
|
+
},
|
|
405
|
+
async (err) => {
|
|
406
|
+
capture(err);
|
|
407
|
+
await settle();
|
|
408
|
+
throw err;
|
|
409
|
+
}
|
|
410
|
+
);
|
|
411
|
+
}, data);
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
exports.currentRequestKey = currentRequestKey;
|
|
416
|
+
exports.flushIfPending = flushIfPending;
|
|
417
|
+
exports.getCurrentStore = getCurrentStore;
|
|
418
|
+
exports.getRequestData = getRequestData;
|
|
419
|
+
exports.installAsyncScopeManager = installAsyncScopeManager;
|
|
420
|
+
exports.linkRequest = linkRequest;
|
|
421
|
+
exports.markServing = markServing;
|
|
422
|
+
exports.noteInit = noteInit;
|
|
423
|
+
exports.openRequestScope = openRequestScope;
|
|
424
|
+
exports.platformWaitUntil = platformWaitUntil;
|
|
425
|
+
exports.readScope = readScope;
|
|
426
|
+
exports.requestDataFrom = requestDataFrom;
|
|
427
|
+
exports.runInStore = runInStore;
|
|
428
|
+
exports.runWithRequestScope = runWithRequestScope;
|
|
429
|
+
exports.storeOf = storeOf;
|
|
430
|
+
exports.trackRoute = trackRoute;
|
|
431
|
+
exports.wrapHandler = wrapHandler;
|