@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,12 @@
|
|
|
1
|
+
import { SESSION_ID_PATTERN } from './chunk-3AW5B2WW.js';
|
|
2
|
+
|
|
3
|
+
// src/core/session.ts
|
|
4
|
+
var SESSION_HEADER = "x-starko-session-id";
|
|
5
|
+
function parseSessionHeader(value) {
|
|
6
|
+
const v = Array.isArray(value) ? value[0] : value;
|
|
7
|
+
if (typeof v !== "string") return void 0;
|
|
8
|
+
const id = v.trim();
|
|
9
|
+
return SESSION_ID_PATTERN.test(id) ? id : void 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { SESSION_HEADER, parseSessionHeader };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { createLogger, resolveConnection, NO_API_KEY_MESSAGE, createFileFilter, injectDebugId, errorMessage, runUpload, shouldDeleteSourcemaps, resolveReleaseInfo, findSourceMappingUrl, stripSourceMappingUrl, stripCssSourceMappingUrl, localMapReference } from './chunk-XOZIXBUK.js';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
var PLUGIN_NAME = "StarkoWebpackPlugin";
|
|
5
|
+
var INFO_KEY = "starkoDebugId";
|
|
6
|
+
function relatedSourceMaps(info) {
|
|
7
|
+
const related = info.related?.sourceMap;
|
|
8
|
+
return related === void 0 ? [] : Array.isArray(related) ? related : [related];
|
|
9
|
+
}
|
|
10
|
+
var StarkoWebpackPlugin = class {
|
|
11
|
+
constructor(options = {}, internals = {}) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.internals = internals;
|
|
14
|
+
this.logger = createLogger({ silent: options.silent, secrets: [resolveConnection(options).apiKey] });
|
|
15
|
+
}
|
|
16
|
+
apply(compiler) {
|
|
17
|
+
const options = this.options;
|
|
18
|
+
const logger = this.logger;
|
|
19
|
+
const enabled = options.enabled ?? compiler.options.mode === "production";
|
|
20
|
+
if (!enabled) return;
|
|
21
|
+
const connection = resolveConnection(options);
|
|
22
|
+
if (!connection.apiKey) {
|
|
23
|
+
logger.warn(NO_API_KEY_MESSAGE);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const devtool = compiler.options.devtool;
|
|
27
|
+
const userPlugin = findSourceMapPlugin(compiler);
|
|
28
|
+
let owner = this.internals.sourcemapOwner ?? "user";
|
|
29
|
+
let addedMaps = false;
|
|
30
|
+
if (userPlugin === "eval") {
|
|
31
|
+
logger.warn('an EvalSourceMapDevToolPlugin puts the source maps inside the bundle; use SourceMapDevToolPlugin or devtool "source-map". Nothing is injected or uploaded.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!devtool && !userPlugin) {
|
|
35
|
+
new compiler.webpack.SourceMapDevToolPlugin({ filename: "[file].map", append: false }).apply(compiler);
|
|
36
|
+
owner = "starko";
|
|
37
|
+
addedMaps = true;
|
|
38
|
+
} else if (typeof devtool === "string" && /eval|inline/.test(devtool)) {
|
|
39
|
+
logger.warn(`devtool "${devtool}" puts the source map inside the bundle; use "source-map" or "hidden-source-map". Nothing is injected or uploaded.`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const filter = createFileFilter(options);
|
|
43
|
+
const releases = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
const releaseFor = (compilation) => {
|
|
45
|
+
if (!releases.has(compilation)) releases.set(compilation, resolveReleaseInfo(options.release));
|
|
46
|
+
return releases.get(compilation);
|
|
47
|
+
};
|
|
48
|
+
const { Compilation: CompilationClass, sources, WebpackError } = compiler.webpack;
|
|
49
|
+
const before = /* @__PURE__ */ new WeakMap();
|
|
50
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
51
|
+
compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage: CompilationClass.PROCESS_ASSETS_STAGE_DEV_TOOLING - 1 }, () => {
|
|
52
|
+
before.set(compilation, new Set(compilation.getAssets().map((a) => a.name).filter((name) => name.endsWith(".map"))));
|
|
53
|
+
});
|
|
54
|
+
compilation.hooks.processAssets.tap(
|
|
55
|
+
{ name: PLUGIN_NAME, stage: CompilationClass.PROCESS_ASSETS_STAGE_DEV_TOOLING + 1 },
|
|
56
|
+
() => {
|
|
57
|
+
for (const chunk of compilation.chunks) {
|
|
58
|
+
for (const file of chunk.files) {
|
|
59
|
+
if (!filter(file)) continue;
|
|
60
|
+
try {
|
|
61
|
+
const asset = compilation.getAsset(file);
|
|
62
|
+
if (!asset || typeof asset.info[INFO_KEY] === "string") continue;
|
|
63
|
+
const mapName = relatedSourceMaps(asset.info)[0] ?? `${file}.map`;
|
|
64
|
+
const mapAsset = compilation.getAsset(mapName);
|
|
65
|
+
if (!mapAsset) continue;
|
|
66
|
+
const code = asset.source.source().toString();
|
|
67
|
+
const map = JSON.parse(mapAsset.source.source().toString());
|
|
68
|
+
const out = injectDebugId(code, map, { release: releaseFor(compilation)?.version });
|
|
69
|
+
if (out.injected) compilation.updateAsset(file, new sources.RawSource(out.code), { ...asset.info, [INFO_KEY]: out.debugId });
|
|
70
|
+
else compilation.updateAsset(file, asset.source, { ...asset.info, [INFO_KEY]: out.debugId });
|
|
71
|
+
compilation.updateAsset(mapName, new sources.RawSource(JSON.stringify(out.map)));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logger.warn(`could not inject ${file}: ${errorMessage(error)}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
if (options.upload === false) return;
|
|
81
|
+
const removeMapAssets = (compilation) => {
|
|
82
|
+
const preexisting = addedMaps ? before.get(compilation) : void 0;
|
|
83
|
+
const removed = new Set(
|
|
84
|
+
compilation.getAssets().map((a) => a.name).filter((name) => name.endsWith(".map") && !(preexisting && preexisting.has(name)))
|
|
85
|
+
);
|
|
86
|
+
for (const name of removed) compilation.deleteAsset(name);
|
|
87
|
+
if (removed.size === 0) return 0;
|
|
88
|
+
const pointsAtRemoved = (fileName, url) => {
|
|
89
|
+
const local = localMapReference(url);
|
|
90
|
+
return local !== void 0 && removed.has(path.posix.normalize(path.posix.join(path.posix.dirname(fileName), local)));
|
|
91
|
+
};
|
|
92
|
+
for (const asset of compilation.getAssets()) {
|
|
93
|
+
const js = /\.(?:m|c)?js$/.test(asset.name);
|
|
94
|
+
if (!js && !asset.name.endsWith(".css")) continue;
|
|
95
|
+
const code = asset.source.source().toString();
|
|
96
|
+
let next = code;
|
|
97
|
+
if (js) {
|
|
98
|
+
const ref = findSourceMappingUrl(code);
|
|
99
|
+
if (ref && pointsAtRemoved(asset.name, ref.url)) next = stripSourceMappingUrl(code, ref);
|
|
100
|
+
} else {
|
|
101
|
+
next = stripCssSourceMappingUrl(code, (url) => pointsAtRemoved(asset.name, url));
|
|
102
|
+
}
|
|
103
|
+
if (next !== code) compilation.updateAsset(asset.name, new sources.RawSource(next));
|
|
104
|
+
}
|
|
105
|
+
return removed.size;
|
|
106
|
+
};
|
|
107
|
+
compiler.hooks.emit.tapPromise(PLUGIN_NAME, async (compilation) => {
|
|
108
|
+
let failure;
|
|
109
|
+
try {
|
|
110
|
+
if (compilation.errors.length > 0) {
|
|
111
|
+
logger.warn("the compilation has errors; source maps are not uploaded");
|
|
112
|
+
} else {
|
|
113
|
+
const entries = [];
|
|
114
|
+
for (const asset of compilation.getAssets()) {
|
|
115
|
+
const chunkId = asset.info[INFO_KEY];
|
|
116
|
+
if (typeof chunkId !== "string") continue;
|
|
117
|
+
const mapName = relatedSourceMaps(asset.info)[0] ?? `${asset.name}.map`;
|
|
118
|
+
if (!compilation.getAsset(mapName)) continue;
|
|
119
|
+
entries.push({
|
|
120
|
+
chunkId,
|
|
121
|
+
fileName: asset.name,
|
|
122
|
+
// Read from the compilation when it is sent, not held here.
|
|
123
|
+
load: async () => {
|
|
124
|
+
const source = compilation.getAsset(mapName)?.source.source();
|
|
125
|
+
if (source === void 0) throw new Error(`${mapName} is no longer in the compilation`);
|
|
126
|
+
return typeof source === "string" ? source : Buffer.from(source);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const outcome = await runUpload(entries, {
|
|
131
|
+
apiKey: connection.apiKey,
|
|
132
|
+
host: connection.host,
|
|
133
|
+
release: releaseFor(compilation),
|
|
134
|
+
dryRun: options.dryRun,
|
|
135
|
+
uploadTimeoutMs: options.uploadTimeoutMs,
|
|
136
|
+
uploadConcurrency: options.uploadConcurrency,
|
|
137
|
+
uploadProtocol: options.uploadProtocol,
|
|
138
|
+
logger
|
|
139
|
+
});
|
|
140
|
+
if (!outcome.ok) failure = outcome.error ?? "source map upload failed";
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
failure = errorMessage(error);
|
|
144
|
+
logger.error(`source maps: ${failure}`);
|
|
145
|
+
} finally {
|
|
146
|
+
if (shouldDeleteSourcemaps(owner, options)) {
|
|
147
|
+
try {
|
|
148
|
+
const removed = removeMapAssets(compilation);
|
|
149
|
+
if (removed > 0) {
|
|
150
|
+
logger.info(
|
|
151
|
+
owner === "starko" ? `removed ${removed} source map(s) from the output (switched on for the upload only)` : `removed ${removed} source map(s) from the output`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
logger.error(`could not remove the source maps from the output: ${errorMessage(error)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (failure && options.failOnError) compilation.errors.push(new WebpackError(`[starko] ${failure}`));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
function findSourceMapPlugin(compiler) {
|
|
164
|
+
try {
|
|
165
|
+
const { SourceMapDevToolPlugin, EvalSourceMapDevToolPlugin } = compiler.webpack;
|
|
166
|
+
let found;
|
|
167
|
+
for (const p of compiler.options.plugins || []) {
|
|
168
|
+
if (!p || typeof p !== "object") continue;
|
|
169
|
+
const name = p.constructor?.name;
|
|
170
|
+
if (EvalSourceMapDevToolPlugin && p instanceof EvalSourceMapDevToolPlugin || name === "EvalSourceMapDevToolPlugin") return "eval";
|
|
171
|
+
if (SourceMapDevToolPlugin && p instanceof SourceMapDevToolPlugin || name === "SourceMapDevToolPlugin") found = "maps";
|
|
172
|
+
}
|
|
173
|
+
return found;
|
|
174
|
+
} catch {
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
var webpack_default = StarkoWebpackPlugin;
|
|
179
|
+
|
|
180
|
+
export { StarkoWebpackPlugin, webpack_default };
|