@preventive/triage 1.0.0-alpha.54 → 1.0.0-alpha.56
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/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/managed/report-filter.ts +17 -6
- package/common/managed/routes.js +6 -2
- package/common/managed/team-filters.js +26 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/out/activity.js +1 -1
- package/out/chunk-3K56AIDY.js +244 -0
- package/out/chunk-4TQKM3JC.js +42 -0
- package/out/chunk-5AXC5J2C.js +6 -0
- package/out/{chunk-VZMELPVL.js → chunk-CV74F3PY.js} +1 -1
- package/out/{chunk-L4CTEMRG.js → chunk-EVPQPPBG.js} +1 -1
- package/out/{chunk-I47TYPXO.js → chunk-EXL3LU6T.js} +1 -1
- package/out/{chunk-WHVXTJHK.js → chunk-HJG6J5O2.js} +1 -1
- package/out/{chunk-2K6UN3PC.js → chunk-IZ6MYRYB.js} +1 -1
- package/out/{chunk-DTM47KGS.js → chunk-J2FWBXFV.js} +1 -1
- package/out/{chunk-UBOCLLF2.js → chunk-MEVBIFRP.js} +1 -1
- package/out/chunk-PTFQKLKO.js +1 -0
- package/out/{chunk-ORIP5INC.js → chunk-SWJYGMWI.js} +1 -1
- package/out/{chunk-VC72ZO3P.js → chunk-VNEOBPBV.js} +1 -1
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +2 -2
- package/out/compare.js +1 -1
- package/out/dialogs.js +1 -1
- package/out/graph.js +8 -8
- package/out/index.html +8 -8
- package/out/scan.js +1 -1
- package/out/view.js +4 -4
- package/package.json +8 -3
- package/server-managed/bundle-build-worker.js +56 -35
- package/server-managed/github-issues.ts +5 -2
- package/server-managed/http.ts +9 -2
- package/server-managed/report-sources.ts +8 -1
- package/server-managed/stasis-config.ts +9 -0
- package/server-managed/team-reports.ts +5 -1
- package/out/chunk-FHIVVVUA.js +0 -6
- package/out/chunk-HT2SSA3V.js +0 -1
- package/out/chunk-J7A5OSZE.js +0 -244
- package/out/chunk-WNSVBOSO.js +0 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/triage",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.56",
|
|
4
4
|
"description": "Client & relay server for triaging of automated reports",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -278,6 +278,8 @@
|
|
|
278
278
|
"common/finding-id.js",
|
|
279
279
|
"common/finding-duplicates.js",
|
|
280
280
|
"common/finding-filters.js",
|
|
281
|
+
"common/finding-repo.d.ts",
|
|
282
|
+
"common/finding-repo.js",
|
|
281
283
|
"common/github-pr.ts",
|
|
282
284
|
"common/github-issue-labels.js",
|
|
283
285
|
"common/github-issue-labels.d.ts",
|
|
@@ -309,9 +311,12 @@
|
|
|
309
311
|
"common/managed/scan-models.ts",
|
|
310
312
|
"common/managed/team-app.js",
|
|
311
313
|
"common/managed/team-app.d.ts",
|
|
314
|
+
"common/managed/team-filters.js",
|
|
312
315
|
"common/managed/triage.ts",
|
|
313
316
|
"common/managed/upload-seal.ts",
|
|
314
317
|
"common/save-error-reason.ts",
|
|
318
|
+
"common/repo-commit.d.ts",
|
|
319
|
+
"common/repo-commit.js",
|
|
315
320
|
"common/revalidation-conflicts.js",
|
|
316
321
|
"common/revalidation-input-groups.js",
|
|
317
322
|
"common/server-info.ts",
|
|
@@ -419,8 +424,8 @@
|
|
|
419
424
|
"typescript": "^7.0.2"
|
|
420
425
|
},
|
|
421
426
|
"dependencies": {
|
|
422
|
-
"@exodus/stasis": "1.0.0-beta.
|
|
423
|
-
"@exodus/stasis-core": "1.0.0-beta.
|
|
427
|
+
"@exodus/stasis": "1.0.0-beta.17",
|
|
428
|
+
"@exodus/stasis-core": "1.0.0-beta.17",
|
|
424
429
|
"@preventive/archive": "^1.4.0",
|
|
425
430
|
"@preventive/compare": "^1.2.11",
|
|
426
431
|
"@preventive/diff": "^1.1.0",
|
|
@@ -7,18 +7,46 @@ import { brotliOptions } from '@exodus/stasis-core/brotli'
|
|
|
7
7
|
import { HttpError, createClient } from '@preventive/upstream/github.js'
|
|
8
8
|
import { githubBundleFilename } from './bundle-build.ts'
|
|
9
9
|
import { bundleBuildDiagnostic } from './bundle-build-diagnostics.js'
|
|
10
|
-
import { MAX_STASIS_CONFIG_BYTES, STASIS_CONFIG, parseStasisConfig } from './stasis-config.ts'
|
|
10
|
+
import { MAX_STASIS_CONFIG_BYTES, STASIS_CONFIG, namesLockfiles, parseStasisConfig } from './stasis-config.ts'
|
|
11
11
|
|
|
12
12
|
const regularFile = entry => entry.type === 'blob' && ['100644', '100755'].includes(entry.mode)
|
|
13
13
|
const parentOf = path => posix.dirname(path).replace(/^\.$/u, '')
|
|
14
14
|
|
|
15
|
+
// The listing of `directory` at the commit, null where the commit has no
|
|
16
|
+
// directory there: one only the tree a lockfile lays out holds, as a package in
|
|
17
|
+
// node_modules a stasis.config.json lists entries of. A read that fails of one
|
|
18
|
+
// it has, as the listing above it tells, fails.
|
|
19
|
+
async function directoryListing(input, github, client, directory) {
|
|
20
|
+
try {
|
|
21
|
+
return await client.listRepoDir({ repo: github, sha: input.commit, directory: directory || undefined })
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const above = directory ? await directoryListing(input, github, client, parentOf(directory)) : undefined
|
|
24
|
+
if (above === null || above?.some(entry => entry.path === posix.basename(directory) && entry.type === 'tree') === false) return null
|
|
25
|
+
throw error
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The text of the stasis.config.json in a directory, null where there is none,
|
|
30
|
+
// each read once a build.
|
|
31
|
+
function configReader(input, github, client) {
|
|
32
|
+
const read = new Map()
|
|
33
|
+
const configText = async directory => {
|
|
34
|
+
const listing = await directoryListing(input, github, client, directory)
|
|
35
|
+
if (!listing?.some(entry => entry.path === STASIS_CONFIG && regularFile(entry))) return null
|
|
36
|
+
return await client.getRepoFile({ repo: github, path: posix.join(directory, STASIS_CONFIG), ref: input.commit })
|
|
37
|
+
}
|
|
38
|
+
return directory => {
|
|
39
|
+
if (!read.has(directory)) read.set(directory, configText(directory))
|
|
40
|
+
return read.get(directory)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
15
44
|
// The entries the stasis.config.json in `directory` names (parseStasisConfig's),
|
|
16
45
|
// null where it has none. One whose entries Stasis can't tell is config-invalid.
|
|
17
|
-
async function directoryConfig(
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
46
|
+
async function directoryConfig(configText, directory) {
|
|
47
|
+
const text = await configText(directory)
|
|
48
|
+
if (text === null) return null
|
|
20
49
|
const path = posix.join(directory, STASIS_CONFIG)
|
|
21
|
-
const text = await client.getRepoFile({ repo: github, path, ref: input.commit })
|
|
22
50
|
try {
|
|
23
51
|
if (Buffer.byteLength(text) > MAX_STASIS_CONFIG_BYTES) throw new Error(`${path} is larger than ${MAX_STASIS_CONFIG_BYTES} bytes`)
|
|
24
52
|
return parseStasisConfig(text, directory)
|
|
@@ -32,15 +60,10 @@ async function directoryConfig(input, github, directory, client) {
|
|
|
32
60
|
// where none lists any. Stasis reads the one in the directory it builds from
|
|
33
61
|
// alone, and builds the entries it lists alone: with others, or with another
|
|
34
62
|
// file's, they are config-mixed.
|
|
35
|
-
async function listingConfig(input,
|
|
36
|
-
const configs = new Map()
|
|
37
|
-
const configAt = directory => {
|
|
38
|
-
if (!configs.has(directory)) configs.set(directory, directoryConfig(input, github, directory, client))
|
|
39
|
-
return configs.get(directory)
|
|
40
|
-
}
|
|
63
|
+
async function listingConfig(input, configText) {
|
|
41
64
|
const found = await Promise.all(input.entries.map(async entry => {
|
|
42
65
|
for (let directory = parentOf(entry); ; directory = parentOf(directory)) {
|
|
43
|
-
const config = await
|
|
66
|
+
const config = await directoryConfig(configText, directory)
|
|
44
67
|
if (config?.has(posix.relative(`/${directory}`, `/${entry}`))) return { entry, directory }
|
|
45
68
|
if (!directory) return { entry, directory: null }
|
|
46
69
|
}
|
|
@@ -60,8 +83,8 @@ async function projectDirectory(input, github, client) {
|
|
|
60
83
|
const manifests = input.entries[0].endsWith('.sol') ? ['foundry.toml', 'soldeer.toml', 'soldeer.lock'] : ['package.json']
|
|
61
84
|
if (!input.directory) return ''
|
|
62
85
|
for (let directory = input.directory; ; directory = posix.dirname(directory).replace(/^\.$/u, '')) {
|
|
63
|
-
const entries = await
|
|
64
|
-
if (entries
|
|
86
|
+
const entries = await directoryListing(input, github, client, directory)
|
|
87
|
+
if (entries?.some(entry => manifests.includes(entry.path) && regularFile(entry))) return directory
|
|
65
88
|
if (!directory) return input.directory
|
|
66
89
|
}
|
|
67
90
|
}
|
|
@@ -77,21 +100,6 @@ async function packageName(input, github, project, bundle, client) {
|
|
|
77
100
|
return typeof name === 'string' ? name : null
|
|
78
101
|
}
|
|
79
102
|
|
|
80
|
-
// Prisma Client is what `prisma generate` writes, not what the repo holds: for
|
|
81
|
-
// a JS project whose package.json depends on a @prisma/ package, Stasis
|
|
82
|
-
// generates it before the scan (generate: ['prisma']).
|
|
83
|
-
async function prismaGenerate(input, github, project, client) {
|
|
84
|
-
if (input.entries[0].endsWith('.sol')) return []
|
|
85
|
-
const listing = await client.listRepoDir({ repo: github, sha: input.commit, directory: project || undefined })
|
|
86
|
-
if (!listing.some(entry => entry.path === 'package.json' && regularFile(entry))) return []
|
|
87
|
-
const text = await client.getRepoFile({ repo: github, path: posix.join(project, 'package.json'), ref: input.commit })
|
|
88
|
-
let manifest
|
|
89
|
-
try { manifest = JSON.parse(text) } catch { return [] }
|
|
90
|
-
const named = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
|
|
91
|
-
.flatMap(field => manifest?.[field] !== null && typeof manifest?.[field] === 'object' ? Object.keys(manifest[field]) : [])
|
|
92
|
-
return named.some(name => name.startsWith('@prisma/')) ? ['prisma'] : []
|
|
93
|
-
}
|
|
94
|
-
|
|
95
103
|
export async function buildStasisBundle({ input, github, token, maxBytes, scopes, cacheDir = null }, client = createClient({ token }), progress = () => {}) {
|
|
96
104
|
const allowed = path => scopes.some(scope => !scope || path === scope || path.startsWith(scope + '/'))
|
|
97
105
|
// Reuse these immutable listings when Stasis discovers the lockfile root.
|
|
@@ -109,16 +117,23 @@ export async function buildStasisBundle({ input, github, token, maxBytes, scopes
|
|
|
109
117
|
// Entries stasis.config.json lists are built from its directory, where
|
|
110
118
|
// Stasis builds each with its options there, taking no conditions; others,
|
|
111
119
|
// from their project with the conditions chosen.
|
|
112
|
-
const
|
|
120
|
+
const configText = configReader(input, github, buildClient)
|
|
121
|
+
const configured = await listingConfig(input, configText)
|
|
113
122
|
if (configured !== null && input.conditions !== null) throw new Error('config-conditions')
|
|
114
123
|
if (configured === null && input.conditions === null && !input.entries[0].endsWith('.sol')) throw new Error('bad-conditions')
|
|
115
124
|
const project = configured ?? await projectDirectory(input, github, buildClient)
|
|
116
125
|
if (!allowed(project)) throw new Error('build-scope')
|
|
117
|
-
|
|
126
|
+
// Stasis lays out the lockfiles the stasis.config.json it builds from names,
|
|
127
|
+
// refusing a package manager given beside them: Soldeer is named only for a
|
|
128
|
+
// Solidity build of a project whose config names none. Stasis detects the
|
|
129
|
+
// rest itself: TypeScript, and the Prisma Clients the entries reach, as the
|
|
130
|
+
// config's generatePrisma leaves it.
|
|
131
|
+
const { packageManager, ...options } = input.options
|
|
132
|
+
const named = packageManager !== undefined && !namesLockfiles(await configText(project) ?? '{}')
|
|
118
133
|
const { bundle } = await buildGitHubBundle({
|
|
119
134
|
github, sha: input.commit, directory: project || undefined,
|
|
120
135
|
entries: input.entries.map(entry => posix.relative(project || '.', entry)),
|
|
121
|
-
...
|
|
136
|
+
...options, ...(named && { packageManager }), client: buildClient, ...(cacheDir === null && { cache: false }),
|
|
122
137
|
})
|
|
123
138
|
const directory = bundle.repo?.directory ?? ''
|
|
124
139
|
progress('scope')
|
|
@@ -139,14 +154,20 @@ export async function buildStasisBundle({ input, github, token, maxBytes, scopes
|
|
|
139
154
|
// the caller's grants: those stay in the diagnostic. A missing or ambiguous
|
|
140
155
|
// lockfile, or the named one missing, is the lockfile's. Stasis refuses a
|
|
141
156
|
// stasis.config.json entry setting an option that runs a program, whatever
|
|
142
|
-
// is given (nothing of the repo runs);
|
|
143
|
-
//
|
|
157
|
+
// is given (nothing of the repo runs); a bundle holding a path or package its
|
|
158
|
+
// allowedPaths, disallowedPaths, allowedModules or disallowedModules refuses,
|
|
159
|
+
// the config's or an entry's, is the policy's; one it can't read, build with
|
|
160
|
+
// its options, or lay out the lockfiles it names of, is the config's. A build
|
|
161
|
+
// the repository's stasis.lock.json disagrees with, or that its lock mode
|
|
162
|
+
// holds to one that isn't there, is the stasis.lock.json's.
|
|
144
163
|
export function buildErrorCode(error, message) {
|
|
145
164
|
if (['build-scope', 'too-large', 'bad-conditions', 'config-invalid', 'config-mixed', 'config-conditions'].includes(message)) return message
|
|
146
165
|
if (error instanceof HttpError) return error.status === 429 ? 'github-rate-limited' : 'github-build-failed'
|
|
147
166
|
if (/, which runs .+, and nothing of the project runs here$/u.test(message)) return 'config-runs-code'
|
|
148
167
|
if (message.endsWith(': bundle either the entries it names or others, not both')) return 'config-mixed'
|
|
149
|
-
if (/\bstasis\.config\.json(?:
|
|
168
|
+
if (/\bstasis\.config\.json(?:: entries .*?)?: (?:allowed|disallowed)(?:Paths|Modules) (?:refuses|does not allow|allows none of) /u.test(message)) return 'config-policy'
|
|
169
|
+
if (/\bstasis\.config\.json(?: is not valid JSON|: |'s lockfiles )/u.test(message)) return 'config-invalid'
|
|
170
|
+
if (/\bstasis\.lock\.json(?::| isn't there,| \(lock = )/u.test(message)) return 'stasis-lock'
|
|
150
171
|
return /no packageManager given|lockfile installs|no (?:pnpm-lock\.yaml|yarn\.lock|package-lock\.json|soldeer\.lock) found in /u.test(message) ? 'build-lockfile' : 'build-failed'
|
|
151
172
|
}
|
|
152
173
|
|
|
@@ -6,6 +6,7 @@ import { randomToken } from './crypto.ts'
|
|
|
6
6
|
import { githubIssueClosedReason } from '../common/github-pr.ts'
|
|
7
7
|
import { reportEntries, reportRepoGithub } from '@preventive/report'
|
|
8
8
|
import { newIssueLabels } from '../common/github-issue-labels.js'
|
|
9
|
+
import { ignoresOwnRepo } from '../common/finding-repo.js'
|
|
9
10
|
import { appJwt, githubAppConfigured, installUrl, publicRepositoryName } from './github-app.ts'
|
|
10
11
|
import { ISSUE_LOGIN_PATH, issueUserToken } from './github-issue-oauth.ts'
|
|
11
12
|
import { TeamReportsError, loadTeamReports, recheckTeam, teamSnapshot } from './team-reports.ts'
|
|
@@ -75,8 +76,10 @@ export async function prepareGithubIssue(config: ManagedConfig, db: ManagedDb, s
|
|
|
75
76
|
if (stored) return { ...referenceResult(stored, repoIds), labels, recheck }
|
|
76
77
|
// The target comes from this finding's own source, or the report's managed
|
|
77
78
|
// assignment. Team membership alone must not let a caller claim an unrelated
|
|
78
|
-
// repository's issue as the permanent reference for this finding.
|
|
79
|
-
|
|
79
|
+
// repository's issue as the permanent reference for this finding. One on an
|
|
80
|
+
// advisory naming the advised package's repository as its own is the
|
|
81
|
+
// report's (common/finding-repo.js).
|
|
82
|
+
const findingRepo = (ignoresOwnRepo(finding, report.repo.github) ? null : finding['repo']) as { github?: unknown } | null | undefined
|
|
80
83
|
const targetRepository = publicRepositoryName(reportRepoGithub({ repo: { github: findingRepo?.github || report.repo.github } }))
|
|
81
84
|
if (!targetRepository || targetRepository.toLowerCase() !== context.repository.toLowerCase()) throw new IssueError(400, 'bad-issue-repository')
|
|
82
85
|
const repository = snapshot.repositories.find(repo => repo.github.toLowerCase() === targetRepository.toLowerCase())
|
package/server-managed/http.ts
CHANGED
|
@@ -173,6 +173,7 @@ import type { OriginGate } from '../server-common/origin.ts'
|
|
|
173
173
|
import { isRole, roleAtLeast } from '../common/managed/roles.ts'
|
|
174
174
|
import { VISIBILITY_PERMISSIONS, parseTeamUserPermissions } from '../common/managed/permissions.ts'
|
|
175
175
|
import { filterReportData } from '../common/managed/report-filter.ts'
|
|
176
|
+
import { ourRepoSlugs, withoutStrayRepos } from '../common/finding-repo.js'
|
|
176
177
|
import type { TriageEntryPatch } from '../common/managed/triage.ts'
|
|
177
178
|
import { GITHUB_AGENTS } from '../common/managed/github-agents.ts'
|
|
178
179
|
import { MAX_FINDING_ID, MAX_TRIAGE_BODY_BYTES, MAX_TRIAGE_ENTRIES, MAX_TRIAGE_HISTORY, parseTriageEntryPatch } from '../common/managed/triage.ts'
|
|
@@ -4128,7 +4129,9 @@ async function handleViewReport(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
4128
4129
|
const { data } = readManagedReport(bytes.toString('utf8'), access.filename)
|
|
4129
4130
|
if (data == null) { sendJson(res, 422, { error: 'unreadable-report' }); return }
|
|
4130
4131
|
const links = mergeLinkGroups(snapshot.linkRevision ? await deps.db.getEnabledLinkGroups(snapshot.linkRevision) : [], await reportIds(data))
|
|
4131
|
-
|
|
4132
|
+
// Without a finding's `repo` none of ours (common/finding-repo.js isStrayRepo).
|
|
4133
|
+
const ours = ourRepoSlugs([...(await deps.db.listSelectedRepos()).map(repo => repo.fullName), access.repo.github])
|
|
4134
|
+
envelope = { data: withoutStrayRepos(data, ours), repo: access.repo, ...(links.length > 0 ? { links } : {}) }
|
|
4132
4135
|
}
|
|
4133
4136
|
// Link decryption and finding-ID backfill can outlast access or link changes.
|
|
4134
4137
|
const current = await deps.db.getReportAccessSnapshot(s.session.id, Date.now(), [id])
|
|
@@ -4166,6 +4169,9 @@ async function handleQueryReports(req: IncomingMessage, res: ServerResponse, dep
|
|
|
4166
4169
|
if (!snapshot || snapshot.user.id !== s.user.id) { sendJson(res, 401, { error: 'unauthenticated' }); return }
|
|
4167
4170
|
if (!roleAtLeast(snapshot.user.role, 'manage')) { sendJson(res, 404, { error: 'no-report' }); return }
|
|
4168
4171
|
const reports = new Map(snapshot.reports.map(report => [report.id, report]))
|
|
4172
|
+
// The repositories that are ours, for a finding's `repo` none of them
|
|
4173
|
+
// (common/finding-repo.js isStrayRepo), which every report sent leaves out.
|
|
4174
|
+
const selected = (await deps.db.listSelectedRepos()).map(repo => repo.fullName)
|
|
4169
4175
|
if (reports.size !== ids.length) { sendJson(res, 404, { error: 'no-report' }); return }
|
|
4170
4176
|
const storedBytes = snapshot.reports.reduce((total, report) => total + report.byteSize, 0)
|
|
4171
4177
|
if (storedBytes > MAX_REPORT_QUERY_BYTES) { sendJson(res, 413, { error: 'batch-too-large' }); return }
|
|
@@ -4203,7 +4209,8 @@ async function handleQueryReports(req: IncomingMessage, res: ServerResponse, dep
|
|
|
4203
4209
|
const { data } = readManagedReport(bytes.toString('utf8'), access.filename)
|
|
4204
4210
|
if (!data) return fail(422, 'unreadable-report')
|
|
4205
4211
|
for (const findingId of await reportIds(data)) findingIds.add(findingId)
|
|
4206
|
-
const
|
|
4212
|
+
const ours = ourRepoSlugs([...selected, access.repo.github])
|
|
4213
|
+
const part = Buffer.from(`${index > 0 ? ',' : ''}${JSON.stringify({ id, data: filterReportData(data, access.permissions, access.repo, undefined, ours), repo: access.repo })}`)
|
|
4207
4214
|
outputBytes += part.length
|
|
4208
4215
|
if (outputBytes > MAX_REPORT_QUERY_BYTES) return fail(413, 'batch-too-large')
|
|
4209
4216
|
// Completion order may differ from the requested report order.
|
|
@@ -8,6 +8,7 @@ import { bundleSourceLinkImports } from '../common/bundle-source-links.js'
|
|
|
8
8
|
import type { BundleDetails } from '../common/bundle-metadata.js'
|
|
9
9
|
import { loadManagedFindings, managedFindingSourcePaths } from '../common/managed/report-content.ts'
|
|
10
10
|
import { type ViewerPermissions, filterReportContent } from '../common/managed/report-filter.ts'
|
|
11
|
+
import { ourRepoSlugs } from '../common/finding-repo.js'
|
|
11
12
|
import { CacheMissError, type CacheStorage } from './cache-storage.ts'
|
|
12
13
|
import { readBundleDetails } from './bundle-cache.ts'
|
|
13
14
|
import type { BlobStore } from './blob-store.ts'
|
|
@@ -84,6 +85,12 @@ async function lendSourcemapEdges(details: BundleDetails, bundle: ManagedBundle,
|
|
|
84
85
|
// identity and visibility are part of the key: a broader viewer's sources must
|
|
85
86
|
// never populate a restricted response. Group derivatives by hash and filename
|
|
86
87
|
// format so each format's permissions can be removed after its last deletion.
|
|
88
|
+
// The repositories that are ours, so that a finding's `repo` none of them is
|
|
89
|
+
// left out (common/finding-repo.js isStrayRepo).
|
|
90
|
+
async function oursFor(db: ManagedDb, repo: { github: string | null }): Promise<Set<string>> {
|
|
91
|
+
return ourRepoSlugs([...(await db.listSelectedRepos()).map(selected => selected.fullName), repo.github])
|
|
92
|
+
}
|
|
93
|
+
|
|
87
94
|
export function createReportSourcesCache(storage: CacheStorage, db: ManagedDb, reports: BlobStore, bundles: BundleStore, sourcemapEdges?: SourcemapEdges) {
|
|
88
95
|
const pending = new Map<string, { reportId: string; job: Promise<boolean> }>()
|
|
89
96
|
let queue = Promise.resolve()
|
|
@@ -102,7 +109,7 @@ export function createReportSourcesCache(storage: CacheStorage, db: ManagedDb, r
|
|
|
102
109
|
if (!sourcePaths) {
|
|
103
110
|
const bytes = await reports.get(report.id)
|
|
104
111
|
if (!bytes) return false
|
|
105
|
-
const parsed = await loadManagedFindings(filterReportContent(bytes.toString('utf8'), permissions, report.filename, repo), report.filename)
|
|
112
|
+
const parsed = await loadManagedFindings(filterReportContent(bytes.toString('utf8'), permissions, report.filename, repo, await oursFor(db, repo)), report.filename)
|
|
106
113
|
if (!parsed) return false
|
|
107
114
|
sourcePaths = managedFindingSourcePaths(parsed.findings)
|
|
108
115
|
}
|
|
@@ -44,3 +44,12 @@ export function parseStasisConfig(text: string, directory = ''): Set<string> | n
|
|
|
44
44
|
}
|
|
45
45
|
return new Set(named.keys())
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
// Whether the stasis.config.json whose text is `text` names the lockfiles Stasis
|
|
49
|
+
// lays out (`lockfiles`), beside which it takes no package manager; false where
|
|
50
|
+
// Stasis can't read it, for the build to say why.
|
|
51
|
+
export function namesLockfiles(text: string): boolean {
|
|
52
|
+
let config: unknown
|
|
53
|
+
try { config = JSON.parse(text) } catch { return false }
|
|
54
|
+
return plainObject(config) && config['lockfiles'] !== undefined
|
|
55
|
+
}
|
|
@@ -17,6 +17,7 @@ import type { TeamWorkspaceSummary } from './team-app.ts'
|
|
|
17
17
|
import { triageWireEntry } from './triage-response.ts'
|
|
18
18
|
import { visibleManagedIssues } from './managed-issues.ts'
|
|
19
19
|
import { MAX_REPORT_QUERY_BYTES, MAX_REPORT_QUERY_COUNT } from './report-query.ts'
|
|
20
|
+
import { ourRepoSlugs } from '../common/finding-repo.js'
|
|
20
21
|
|
|
21
22
|
type Finding = Record<string, unknown>
|
|
22
23
|
type TeamReport = { id: string; filename: string; data: unknown; repo: { github: string | null; directory: string } }
|
|
@@ -167,7 +168,10 @@ async function buildTeamWorkspace(db: ManagedDb, store: BlobStore, snapshot: Tea
|
|
|
167
168
|
const allIds = new Set<string>(), visible: Visibility = new Map()
|
|
168
169
|
for (let i = 0; i < reports.length; i++) {
|
|
169
170
|
const access = snapshot.reports[i]!, report = reports[i]!
|
|
170
|
-
|
|
171
|
+
// A finding's `repo` none of the team's (common/finding-repo.js
|
|
172
|
+
// isStrayRepo) is removed before anything reads it.
|
|
173
|
+
const ours = ourRepoSlugs([...snapshot.repositories.map(repo => repo.github), access.repo.github])
|
|
174
|
+
report.data = filterReportData(report.data, access.permissions, access.repo, securityIds, ours)
|
|
171
175
|
if (report.data && typeof report.data === 'object' && ('think' in report.data || 'reportRepo' in report.data)) {
|
|
172
176
|
const { think: _think, reportRepo: _reportRepo, ...data } = report.data as Finding
|
|
173
177
|
report.data = data
|
package/out/chunk-FHIVVVUA.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./chunk-QRKFPLA4.js";import{b as t}from"./chunk-TUII34K2.js";var n=new Set([`module`,`commonjs`,`json`,`module-typescript`,`commonjs-typescript`]),r=new Set([`solidity`,`php`,`shell`,`rust`]),i=new Set([`java`,`kotlin`,`gradle`,`objc`,`objcpp`,`swift`,`c`,`cpp`,`c-header`,`cpp-header`,`ruby`,`python`,`cmake`,`podspec`,`podfile`,`podfile-lock`,`template`,`xml`,`env`,`fastlane`,`pbxproj`]),a=new Set([`resource`,`resource:base64`]),o=new Set([`stat:file`,`stat:directory`]),s=new Set([...n,...r,...i,...a,`patch`,`directory`,...o]),c=e=>o.has(e),l=e=>e===`directory`||e===`stat:directory`?`directory`:`file`;function u(e,t,n){if(e===t)return e;let r=c(e);if(r!==c(t)&&l(e)===l(t))return r?t:e;throw Error(`format conflict for '${n}' ('${t}' vs '${e}')`)}function d(e,t){return t===``?e:e===`.`?t:`${e}/${t}`}var f=/^(?=[A-Za-z0-9-]{1,39}\/)[A-Za-z0-9](?:-?[A-Za-z0-9])*\/(?!\.\.?$)[\w.-]{1,100}$/u,p=/^(?!\.\.?(?:\/|$))[\w.~@+-]+(?:\/(?!\.\.?(?:\/|$))[\w.~@+-]+)*$/u,m=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u,h={github:e=>typeof e==`string`&&f.test(e),directory:e=>typeof e==`string`&&e.length<=1024&&(e===``||p.test(e)),commit:e=>typeof e==`string`&&m.test(e)},ee=(e,t)=>e?.toLowerCase()===t?.toLowerCase(),g=(e,t,n)=>{if(e===void 0)return;C(e)||b(!1,`${n} must be an object`);for(let r of Object.keys(e))Object.hasOwn(t,r)||b(!1,`unknown ${n} key '${r}'`);let r=Object.entries(t).map(([t,r])=>typeof r==`object`?[t,g(e[t],r,`${n}.${t}`)]:(e[t]!==void 0&&!r(e[t])&&b(!1,`invalid ${n}.${t}: ${JSON.stringify(e[t])}`),[t,e[t]])).filter(([,e])=>e!==void 0);return r.length===0?void 0:Object.freeze(w(r))},te=(e,t=`bundle repo`)=>g(e,h,t),ne=(e,t)=>t??(O(e)?`npm`:void 0),re=(e,{ecosystem:t,repo:n},r)=>{if(n===void 0)return;ne(e,t)===void 0&&b(!1,`${r}: '${e}' is no dependency's bucket, and carries no repo`);let i=te(n,`${r} module '${e}' repo`);return i?.github===void 0&&b(!1,`${r} module '${e}' repo has no github`),i},ie=e=>typeof e==`string`&&/^[\w.+@/~'!()*-]+$/u.test(e),_={name:ie,version:ie},ae=e=>typeof e==`string`&&e!==``&&!e.includes(`\\`)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e!==`node_modules`),oe=(e,t,n)=>typeof e==`string`&&ae(n)&&e===`${t}/${n}`,v={vendored:()=>!0,subpackages:(e,t,n)=>oe(e.name,t,n)},se=(e,t)=>{for(let n=t.lastIndexOf(`/`);n>0;n=t.lastIndexOf(`/`,n-1))if(Object.hasOwn(e,t.slice(0,n)))return t.slice(0,n)};function ce(e,t){if(e===void 0)return;let n=new Set;for(let r of Object.keys(t)){let t=se(e,r);t!==void 0&&n.add(t)}return n.size===0?void 0:Object.freeze(w(x(n).map(t=>[t,e[t]])))}var le=(e,t,{name:n,ecosystem:r,files:i,[e]:a},o)=>{if(a===void 0)return;ne(t,r)===void 0&&b(!1,`${o}: '${t}' is no dependency's bucket, and carries no ${e}`),C(a)||b(!1,`${o} module '${t}' ${e} must be an object`);let s=w(Object.entries(a).map(([r,i])=>{ae(r)||b(!1,`${o} module '${t}' ${e}: invalid directory ${JSON.stringify(r)}`);let a=g(i,_,`${o} module '${t}' ${e} '${r}'`);return a?.name===void 0&&b(!1,`${o} module '${t}' ${e} '${r}' has no name`),v[e](a,n,r)||b(!1,`${o} module '${t}' ${e} '${r}' is named '${a.name}', not '${n}/${r}'`),[r,a]})),c=ce(s,i);for(let n of Object.keys(s))Object.hasOwn(c??{},n)||b(!1,`${o} module '${t}' ${e} '${n}' holds none of its files`);return c},y=({name:e,version:t,ecosystem:n,repo:r,vendored:i,subpackages:a,files:o})=>({name:e,version:t,...n===void 0?{}:{ecosystem:n},...r===void 0?{}:{repo:r},...i===void 0?{}:{vendored:i},...a===void 0?{}:{subpackages:a},files:o});function ue(e,t){let n=e.repo??t.repo,r=Object.keys(v).filter(n=>t[n]!==void 0&&Object.keys(t[n]).some(t=>!Object.hasOwn(e[n]??{},t)));if(n===e.repo&&r.length===0)return e;let i=w(r.map(n=>[n,Object.freeze(w([...Object.entries(t[n]),...Object.entries(e[n]??{})]))]));return y({...e,repo:n,...i})}var de=(e,t,n,r,i)=>w(Object.keys(v).map(a=>[a,i.includes(a)?le(a,e,{...t,files:n,[a]:ce(t[a],n)},r):void 0]));function fe({name:e,version:t,ecosystem:n,repo:r,vendored:i,subpackages:a,files:o},s,c){return b(n===void 0||typeof n==`string`),o=w(Object.entries(o)),y({name:e,version:t??void 0,ecosystem:n,repo:re(s,{ecosystem:n,repo:r},c),vendored:le(`vendored`,s,{name:e,ecosystem:n,files:o,vendored:i},c),subpackages:le(`subpackages`,s,{name:e,ecosystem:n,files:o,subpackages:a},c),files:o})}function pe(e,{scope:t=`full`}={}){let n=new Set;for(let[r,{files:i}]of e)if(t===`full`||O(r))for(let e of Object.keys(i))n.add(d(r,e));return n}function me(e,{what:t,files:n,formats:r,scope:i}){if(e.includes(`\\`))return`holds a '\\'`;if(E(e))return`escapes the root`;if(i!==`full`&&!O(e))return`is outside node_modules, which a '${i}'-scope ${t} does not record`;if(!n.has(e))return`names no file the ${t} records`;let a=r.get(e);return a===`directory`?`is a directory capture, not a file`:c(a)?`is a payload-free '${a}' record, not a file`:null}function he(e,{what:t,files:n,formats:r,scope:i}){for(let a of e){let e=me(a,{what:t,files:n,formats:r,scope:i});b(e===null,`${t}: executable entry '${a}' ${e}`)}}function ge(e,{what:t,files:n,formats:r,scope:i=`full`}){if(e===void 0)return new Set;let a=`${t}: executable`;b(Array.isArray(e),`${a} must be an array of file paths`);let o=new Set;for(let t of e)b(typeof t==`string`&&t!==``,`${a} entry must be a non-empty string`),b(!o.has(t),`${a} entry '${t}' is listed twice`),o.add(t);return he(o,{what:t,files:n,formats:r,scope:i}),o}function _e(e,{what:t,modules:n,formats:r,scope:i}){if(e.size!==0)return he(e,{what:t,files:pe(n,{scope:i}),formats:r,scope:i}),T(e)}function b(e,t){if(!e)throw Error(t)}var ve=e=>e.slice(e.lastIndexOf(`/`)+1).toLowerCase()===`stasis.lock.json`;function ye(e,t){let n=0;for(;n<e.length&&e[n]===t[n];)n++;let r=e.length-n,i=t.length-n;if(r===0&&i===0)return 0;if(r<2)return i<2&&(e[n]??``)>(t[n]??``)?1:-1;if(i<2)return 1;if(e[n]===`*`)return-1;if(t[n]===`*`||e[n]===`node_modules`)return 1;if(t[n]===`node_modules`)return-1;let a=e.slice(n).join(`\0`),o=t.slice(n).join(`\0`);if(a<o)return-1;if(a>o)return 1;throw Error(`Unreachable`)}var x=(e,t=e=>e)=>Array.from(e,e=>({item:e,segments:t(e).split(`/`)})).toSorted((e,t)=>ye(e.segments,t.segments)).map(({item:e})=>e),S=([e])=>e,C=e=>e&&[null,Object.prototype].includes(Object.getPrototypeOf(e)),w=e=>Object.setPrototypeOf(Object.fromEntries(e),null),T=e=>x(e),be=(e,{sorted:t=!0}={})=>w((t?x(e,S):[...e]).map(([e,n])=>[e,n instanceof Map?be(n,{sorted:t}):n])),xe=(e,t)=>e.get(t)??e.set(t,new Map).get(t),Se=e=>new Map(Object.entries(e).map(([e,t])=>[e,C(t)?Se(t):t]));function E(e){if(e.startsWith(`/`))return!0;if(!e.includes(`..`))return!1;let t=0;for(let n of e.split(`/`))if(n!==`.`&&n!==``){if(n!==`..`)t++;else if(--t<0)return!0}return!1}var Ce=e=>e.includes(`\\`)||E(e),D=(e,t)=>b(!Ce(e),`${t}: path '${e}' escapes the root or holds a '\\'`),we=(e,t)=>b(typeof e==`string`&&e!==``&&!Ce(e),`${t}: invalid entry ${JSON.stringify(e)}`);function Te(e,t){b(Array.isArray(e),`${t}: entries must be an array of file paths`);let n=new Set;for(let r of e)we(r,t),b(!n.has(r),`${t}: entry '${r}' is listed twice`),n.add(r);return n}function Ee(e,t){for(let n of e)we(n,t);return T(e)}function De(e,t){D(e,`formats`),b(s.has(t),`unknown format '${t}' for ${e}`)}function Oe(e){b(C(e));let t=new Map;for(let[n,r]of Object.entries(e)){De(n,r);let e=n===``?`.`:n;b(!t.has(e),`duplicate format key '${e}'`),t.set(e,r)}return t}function ke(e,t,n){for(let[r,i]of e)c(i)&&t.has(r)&&b(!1,`${n}: '${r}' is a payload-free '${i}' record, yet carries content`)}function Ae(e){for(let[t,n]of e)De(t,n);return be(e)}function je(e){for(let[,t]of e){b(t instanceof Map);for(let[e,n]of t){D(e,`imports`),b(n instanceof Map);for(let[,e]of n){if(typeof e==`string`){D(e,`imports`);continue}b(e instanceof Map&&e.size>0,`import target must be a file or a non-empty {platform: file} map`);for(let[t,n]of e)b(typeof t==`string`&&t.length>0&&!t.includes(`/`),`invalid platform key '${t}'`),b(typeof n==`string`),D(n,`imports`)}}}}function Me(e){b(C(e));let t=Se(e);return je(t),t}function Ne(e){return je(e),be(e)}function Pe(e,{skipEmpty:t=!1,metadata:n=!0,what:r}={}){let i=n===!0?[`repo`,...Object.keys(v)]:n===!1?[]:n,a={modules:[],sources:[]};for(let[n,o]of e){if(t&&Object.keys(o.files).length===0)continue;let e=O(n);e&&b(o.name&&o.version&&o.files);let s=w(x(Object.entries(o.files),S));a[e?`modules`:`sources`].push([n,y({...o,repo:i.includes(`repo`)?re(n,o,r):void 0,...de(n,o,s,r,i),files:s})])}return{modules:w(x(a.modules,S)),sources:w(x(a.sources,S))}}function Fe(e,t){let n=e instanceof Map;if(n!==t instanceof Map)return!1;if(!n)return e===t;if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0}var Ie=e=>e instanceof Map?`{${[...e].map(([e,t])=>`${e}: ${t}`).join(`, `)}}`:e;function Le(e,t,n){let r=new Map,i=e=>{for(let[t,i]of e){let e=xe(r,t);for(let[t,r]of i){let i=xe(e,t);for(let[e,a]of r)i.has(e)?b(Fe(i.get(e),a),`${n}: import '${e}' from '${t}' resolves differently ('${Ie(i.get(e))}' vs '${Ie(a)}')`):i.set(e,a instanceof Map?new Map(a):a)}}};return i(e),i(t),r}function Re(e,t,n){let r=new Map,i=e=>{for(let[t,i]of e){let e=r.get(t);if(e===void 0){r.set(t,i);continue}try{r.set(t,u(i,e,t))}catch(e){throw Error(`${n}: ${e.message}`,{cause:e})}}};return i(e),i(t),r}function ze(e,t,n,r){if(e.size===0)return new Set(t);let i=pe(n,{scope:r}),a=new Set(t);for(let t of e)i.has(t)||a.add(t);return a}var Be=/(?:^|\/)\.{0,2}(?:\/|$)/u;function Ve(e,t,n){let r=d(e,t);return(r!==`.`||t!==``)&&Be.test(r)&&b(!1,`${n}: non-canonical file key ${JSON.stringify(r)}`),r.includes(`\\`)&&b(!1,`${n}: file key '${r}' holds a '\\', which no path may`),r}function He(e,t,n){let r=new Map;for(let[i,{files:a}]of e){typeof i!=`string`&&b(!1,`${t}: bucket dir ${String(i)} is not a string`),D(i,t);for(let e of Object.keys(a)){let a=Ve(i,e,t),o=r.get(a);o!==void 0&&n(a,o,i),r.set(a,i)}}return r}var Ue=(e,t)=>n=>b(!1,`duplicate file key '${n}' across ${e} buckets -- module bucketing changed between writes (a workspace package without a version now owns its own bucket); regenerate the ${t}`);function We(e,t,n){let r=new Map,i=e=>{for(let[t,i]of e){let e=r.get(t);if(e===void 0){r.set(t,y({...i,files:Object.assign(Object.create(null),i.files)}));continue}b(e.name===i.name,`${n}: module '${t}' name mismatch ('${e.name}' vs '${i.name}')`),b(e.version===i.version,`${n}: module '${t}' version mismatch ('${e.version}' vs '${i.version}')`+(e.version==null==(i.version==null)?``:` -- an artifact from an older stasis may record a placeholder version for a workspace package without one; regenerate it (bundle=replace / lock=replace)`)),b(e.ecosystem===i.ecosystem,`${n}: module '${t}' ecosystem mismatch ('${e.ecosystem??`(none)`}' vs '${i.ecosystem??`(none)`}')`);let a=ue(e,i);a!==e&&r.set(t,a);for(let[r,a]of Object.entries(i.files))Object.hasOwn(e.files,r)?b(e.files[r]===a,`${n}: content mismatch for '${d(t,r)}'`):e.files[r]=a}};return i(e),i(t),He(r,n,(e,t,r)=>b(!1,`${n}: file '${e}' is bucketed under both '${t}' and '${r}' -- module bucketing changed between the artifacts (a workspace package without a version now owns its own bucket); regenerate the artifact (bundle=replace / lock=replace)`)),r}function O(e){return e.split(`/`).includes(`node_modules`)}function Ge(e){let t=e.length;for(;(t=e.lastIndexOf(`node_modules/`,t-1))!==-1;)if(t===0||e[t-1]===`/`)return t;return-1}function Ke(e){let t=Ge(e);if(t===-1)return null;let n=t+13,r=e.slice(n).split(`/`),i=r[0].startsWith(`@`)?2:1;if(r.length<=i||r.slice(0,i).some(e=>!e))return null;let a=r.slice(0,i).join(`/`);return{dir:e.slice(0,n)+a,rel:r.slice(i).join(`/`),name:a}}var k=1,qe=0,Je=Ue(`bundle`,`artifact (bundle=replace)`),Ye=e=>{for(let t of e)b(!ve(t),`bundle: ${t} is a stasis lockfile, which no bundle may carry`)},Xe=e=>Ke(e)??{dir:`.`,rel:e===`.`?``:e,name:null};function Ze(){throw Error(`bundle: file contents are not retained by this contents-free Bundle`)}var Qe=(e,{files:t,...n})=>{let r=Object.create(null);for(let[n,i]of Object.entries(t))typeof i!=`symbol`&&b(!1,`bundle: file '${d(e,n)}' is not a placeholder`),Object.defineProperty(r,n,{get:Ze,enumerable:!0});return{...n,files:Object.freeze(r)}},A=(e,t)=>{if(e===void 0&&t===void 0)return;let n=new Map;for(let r of[e,t])for(let[e,t]of Object.entries(r??{})){if(!Array.isArray(t))continue;let r=n.get(e);r===void 0&&n.set(e,r=new Set);for(let e of t)r.add(e)}return w([...n.keys()].toSorted().map(e=>[e,T(n.get(e))]))},$e=(e,t)=>Object.hasOwn(h,e)&&h[e](t),et=(e,t)=>e?.github===void 0||!ee(e.github,t?.github)?void 0:w(Object.keys(h).filter(n=>e[n]!==void 0&&(n===`github`||e[n]===t[n])).map(t=>[t,e[t]])),tt=e=>{if(!C(e)||e.root!==!0||Object.hasOwn(e,`directory`))return e;let{root:t,...n}=e;return n},nt={npm:_,composer:_,cargo:_},rt=(e,t)=>w(Object.keys(nt).map(n=>{let[r,i]=[e?.[n],t?.[n]];return[n,r?.name!==void 0&&r.name===i?.name?w(Object.entries(r).filter(([e,t])=>t===i[e])):void 0]})),j=class e{static VERSION=k;version=k;config;entries;modules;formats;imports;executable;reason;#e;get repo(){return this.#e}set repo(e){this.#e=te(e)}#t;get package(){return this.#t}set package(e){this.#t=g(e,nt,`bundle package`)}constructor({config:e={scope:`full`},entries:t,modules:n,formats:r,imports:i,executable:a,reason:o,repo:s,package:c,version:l=k}={}){b([qe,k].includes(l)),b([`node_modules`,`full`].includes(e.scope)),this.version=l,this.config=e,this.entries=t??new Set,this.modules=n??new Map,this.formats=r??new Map,this.imports=i??new Map,this.executable=a??new Set,this.reason=o,this.repo=s,this.package=c}get sources(){let e=new Map;for(let[t,{files:n}]of this.modules)for(let[r,i]of Object.entries(n))e.set(d(t,r),i);return e}static isResourceFormat(e){return e===`resource`||e===`resource:base64`||e===`directory`}get hasCode(){for(let[t,{files:n}]of this.modules)for(let r of Object.keys(n))if(!e.isResourceFormat(this.formats.get(d(t,r))))return!0;return!1}static parse(t){return e.fromJSON(JSON.parse(t))}static fileKeyAt(e){let[t,n,r,i]=e;if(typeof n==`string`){if(e.length===2&&t===`sources`){let e=Xe(n);return Ve(e.dir,e.rel,`bundle`)}if(e.length===4&&(t===`sources`||t===`modules`)&&r===`files`&&typeof i==`string`)return Ve(n,i,`bundle`)}}static fromJSON(t,{contents:n=!0}={}){b(t.version===k||t.version===qe),b([`node_modules`,`full`].includes(t.config?.scope));let r=Oe(t.formats),i=new Map,a=new Set;if(t.version===k){let e=t.config.scope===`full`;if(t.modules!==void 0){b(typeof t.modules==`object`&&t.modules!==null);for(let[e,n]of Object.entries(t.modules))b(O(e)),D(e,`bundle`),b(n?.name&&n.version&&n.files),i.set(e,fe(n,e,`bundle`))}if(e){b(t.sources&&typeof t.sources==`object`);for(let[e,n]of Object.entries(t.sources))b(!O(e)),D(e,`bundle`),b(n?.name&&n.files),i.set(e,fe(n,e,`bundle`));t.entries!==void 0&&(a=Te(t.entries,`bundle`))}else b(t.entries===void 0),b(t.sources===void 0)}else{b(t.sources);for(let[e,n]of Object.entries(t.sources)){D(e,`bundle`);let{dir:t,rel:r,name:a}=Xe(e);b(!E(t)&&!E(r)),i.has(t)||i.set(t,{name:a,version:null,files:Object.create(null)});let{files:o}=i.get(t);b(!Object.hasOwn(o,r),`bundle: duplicate file key '.' (v0 '' and '.')`),o[r]=n}}let o=He(i,`bundle`,Je);Ye(o.keys()),ke(r,o,`bundle`);let s=Me(t.imports);if(!n)for(let[e,t]of i)i.set(e,Qe(e,t));return new e({version:t.version,config:t.config,entries:a,modules:i,formats:r,imports:s,executable:t.version===k?ge(t.executable,{what:`bundle`,files:o,formats:r,scope:t.config.scope}):new Set,reason:C(t.reason)?t.reason:void 0,repo:tt(t.repo),package:t.package})}serialize(){let e=He(this.modules,`bundle`,Je);Ye(e.keys()),ke(this.formats,e,`bundle`);let{modules:t,sources:n}=Pe(this.modules,{skipEmpty:!0,what:`bundle`}),r=this.config.scope===`full`,i={version:k,config:this.config};this.repo!==void 0&&(i.repo=this.repo),this.package!==void 0&&(i.package=this.package),r&&(i.entries=Ee(this.entries,`bundle`)),i.formats=Ae(this.formats),i.imports=Ne(this.imports);let a=_e(this.executable,{what:`bundle`,modules:this.modules,formats:this.formats,scope:this.config.scope});return a!==void 0&&(i.executable=a),this.reason!==void 0&&(i.reason=A(this.reason,void 0)),r&&(i.sources=n),i.modules=t,JSON.stringify(i,void 0,2)}withReason(t,n=[...this.sources.keys()]){let{version:r,config:i,entries:a,modules:o,formats:s,imports:c,executable:l,repo:u,package:d}=this,f=A(this.reason,{[t]:n});return new e({version:r,config:i,entries:a,modules:o,formats:s,imports:c,executable:l,reason:f,repo:u,package:d})}merge(t){return b(this.config.scope===t.config.scope,`bundle merge: scope mismatch ('${this.config.scope}' vs '${t.config.scope}')`),new e({config:{scope:this.config.scope},entries:new Set([...this.entries,...t.entries]),modules:We(this.modules,t.modules,`bundle merge`),formats:Re(this.formats,t.formats,`bundle merge`),imports:Le(this.imports,t.imports,`bundle merge`),executable:ze(this.executable,t.executable,t.modules,this.config.scope),reason:A(this.reason,t.reason),repo:et(this.repo,t.repo),package:rt(this.package,t.package)})}},it={__proto__:null,js:`javascript`,mjs:`javascript`,cjs:`javascript`,jsx:`jsx`,ts:`typescript`,mts:`typescript`,cts:`typescript`,tsx:`tsx`,json:`json`,css:`css`,html:`markup`,htm:`markup`,xml:`markup`,svg:`markup`,yml:`yaml`,yaml:`yaml`,sh:`bash`,bash:`bash`,md:`markdown`,markdown:`markdown`,sol:`solidity`,php:`php`,phtml:`php`,rs:`rust`,rb:`ruby`,py:`python`,pyw:`python`,pyi:`python`,java:`java`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,"c++":`cpp`,hpp:`cpp`,hh:`cpp`,hxx:`cpp`,"h++":`cpp`,h:`cpp`,c:`c`,m:`objectivec`,mm:`objectivec`},at={__proto__:null,module:`javascript`,commonjs:`javascript`,"module-typescript":`typescript`,"commonjs-typescript":`typescript`,json:`json`,solidity:`solidity`,php:`php`,shell:`bash`,rust:`rust`,java:`java`,objc:`objectivec`,objcpp:`objectivec`,c:`c`,"c-header":`c`,cpp:`cpp`,"cpp-header":`cpp`,ruby:`ruby`,podspec:`ruby`,podfile:`ruby`,fastlane:`ruby`,"podfile-lock":`yaml`,xml:`markup`};function ot(e){if(typeof e!=`string`)return!1;let t=e.length-1,n=0;for(;n<t&&/\s/u.test(e[n]);)n++;for(;t>n&&/\s/u.test(e[t]);)t--;return n<t&&e[n]===`{`&&e[t]===`}`}function st(e,t,n){if(typeof t==`string`&&at[t])return at[t];if(typeof e!=`string`)return null;let r=e.slice(e.lastIndexOf(`/`)+1),i=r.lastIndexOf(`.`);if(i<=0)return null;let a=r.slice(i+1).toLowerCase();return a===`map`?ot(n)?`json`:null:it[a]??null}var ct=/^webpack(?:-internal)?:\/\/[^/]*\//u,lt=/^[a-z][\d+.a-z-]*:/iu,ut=/^file:/iu,dt=/^(?:file|ftp|https?|wss?):/iu,ft=/^(?:[a-z][\d+.a-z-]*:\/\/[^/]*\/?|\/\/[^/]+\/|[a-z]:\/|\/)?/iu,M=e=>ft.exec(e)[0],N=e=>M(e).includes(`://`),P=e=>e.replace(N(e)?/[#?].*$/su:/\?.*$/su,``),pt=e=>e.slice(e.lastIndexOf(`/`)+1),F=(e,t)=>URL.parse(e,t)?.href??null;function I(e){let t=M(e),n=t.includes(`://`)&&F(e);if(n)return n;let r=[];for(let n of e.slice(t.length).split(`/`))n===``||n===`.`||(n===`..`?r.length>0&&r.at(-1)!==`..`?r.pop():t||r.push(`..`):r.push(n));let i=/^[a-z]:\/$/iu.test(t)?t.toUpperCase():t.startsWith(`//`)?t.toLowerCase():t;return i?i.replace(/\/?$/u,`/`)+r.join(`/`):r.join(`/`)||`.`}function mt(e,t){let n=M(t);return N(e)&&!n.includes(`:`)?F(t,e)??I(`${e}/../${t}`):I(n===`/`?M(e).replace(/\/?$/u,``)+t:n?t:`${e}/../${t}`)}function ht(e){try{return decodeURIComponent(e)}catch{return e}}function L(e,t){let n=e.replaceAll(`\\`,`/`);if(ct.test(n))return I(n.replace(ct,``));let r=dt.test(n)?F(n)??n:n,i=/^file:\/\/([^/#]*)([^#]*)/isu.exec(r);if(i){let[,e,t]=i;return I(ht(e&&e.toLowerCase()!==`localhost`?`//${e}${t}`:t).replace(/^\/(?=[a-z]:\/)/iu,``))}if(lt.test(r)&&!M(r).includes(`:`))return r;if(t===void 0)return I(r);if(ut.test(t)&&!M(r))return L(F(r,t)??r);let a=L(t);return M(r)&&!N(a)?I(r):mt(a,r)}var gt=/^(?:@[\dA-Za-z~-][\w.~-]*\/)?[\dA-Za-z~-][\w.~-]*$/u;function R(e){let t=e.split(`/`).slice(0,e.startsWith(`@`)?2:1).join(`/`);return gt.test(t)?t:null}var _t=new Set([`.pnpm`,`.bun`,`.deno`]),vt=/^\d+\.\d+\.\d+(?:-[\d.a-z-]+)?(?:\+[\d.a-z-]+)?$/iu;function yt(e,t){let n=`${t.replace(`/`,`+`)}@`,r=e.startsWith(n)?e.slice(n.length).split(/[(_]/u)[0]:null;return vt.test(r)?r:null}function bt(e){let t=P(e).split(`/`),n=t.lastIndexOf(`node_modules`),r=n<0?null:R(t.slice(n+1).join(`/`));if(r===null)return null;let i=n+1+r.split(`/`).length;if(i>=t.length||t.slice(i).includes(``))return null;let a=t.slice(0,i).join(`/`);return{name:r,version:_t.has(t[n-2])?yt(t[n-1],r):null,root:a,path:e.slice(a.length+1)}}var xt=new Map([[`js`,`jsx`],[`mjs`,`jsx`],[`cjs`,`jsx`],[`jsx`,`jsx`],[`es`,`jsx`],[`es6`,`jsx`],[`ts`,`ts`],[`mts`,`ts`],[`cts`,`ts`],[`tsx`,`tsx`],[`json`,`json`]]);function St(e){let t=pt(P(e));return/^[\w-]+$/u.test(t)?`jsx`:xt.get(/\.([\da-z]+)$/iu.exec(t)?.[1].toLowerCase())??null}var Ct=[`.js`,`.mjs`,`.cjs`,`.jsx`,`.ts`,`.tsx`,`.mts`,`.cts`,`.json`],wt=[`.ios`,`.android`,`.web`];function Tt(e){let t=e.map(e=>/\.[a-z]+(?=\.\w+$)/u.exec(pt(P(e.path??``)))?.[0]),[[n,r],[,i]]=wt.map(e=>[e,t.filter(t=>t===e).length]).toSorted((e,t)=>t[1]-e[1]);return[...r===i?[]:[n],`.native`,``,`.browser`,`.node`]}var Et=new Map([[`.js`,[`.ts`,`.tsx`]],[`.jsx`,[`.tsx`]],[`.mjs`,[`.mts`]],[`.cjs`,[`.cts`]]]),Dt=[`index`,`main`,`browser`,`node`],Ot=[``,`src/`,`lib/`,`dist/`,`build/`],kt=new Set([`lib`,`dist`,`build`,`out`,`esm`,`cjs`]);function*At(e,t){yield e;let n=/\.[^./]+$/u.exec(e)?.[0];for(let t of Et.get(n)??[])yield e.slice(0,-n.length)+t;for(let n of e.endsWith(`/`)?[`${e}index`]:[e,`${e}/index`])for(let e of Ct)for(let r of t)yield n+r+e;if(n)for(let r of t.filter(Boolean))yield e.slice(0,-n.length)+r+n}function*jt(e){let t=e;for(;;){t.startsWith(`src/`)||(yield`src/${t}`),t!==e&&(yield t);let n=t.indexOf(`/`);if(n<0||!kt.has(t.slice(0,n)))return;t=t.slice(n+1)}}function Mt(e){let t=new Map,n=new Map,r=new Map;for(let i of e)i.path!==null&&t.set(i.path,i),i.package&&(n.set(i.package.name,(n.get(i.package.name)??new Set).add(i.package.root)),(r.get(i.package.root)??r.set(i.package.root,[]).get(i.package.root)).push(i));return{byPath:t,roots:n,byRoot:r,platforms:Tt(e),found:new Map}}function z(e,t){if(!e.found.has(t)){let n=P(t),r=At(n,e.platforms).map(e=>e+t.slice(n.length));e.found.set(t,e.byPath.get(r.find(t=>e.byPath.has(t)))??null)}return e.found.get(t)}function Nt(e,t,n){let r=e.roots.get(n);if(!r)return null;let i=t.path.split(`/`);for(let e=i.length-1;e>=0;e--){let t=[...i.slice(0,e),`node_modules`,n].join(`/`);if(r.has(t))return t}return r.size===1?[...r][0]:null}var Pt=new Set(`assert.async_hooks.buffer.child_process.cluster.console.constants.crypto.dgram.diagnostics_channel.dns.domain.events.fs.http.http2.https.inspector.module.net.os.path.perf_hooks.process.punycode.querystring.readline.repl.stream.string_decoder.sys.timers.tls.trace_events.tty.url.util.v8.vm.wasi.worker_threads.zlib._http_agent._http_client._http_common._http_incoming._http_outgoing._http_server._stream_duplex._stream_passthrough._stream_readable._stream_transform._stream_wrap._stream_writable._tls_common._tls_wrap.assert/strict.dns/promises.fs/promises.inspector/promises.path/posix.path/win32.readline/promises.stream/consumers.stream/promises.stream/web.timers/promises.util/types`.split(`.`));function Ft(e){if(e.startsWith(`node:`)||Pt.has(e))return{builtin:!0};let t=R(P(e));return t===null?{}:{package:t}}function It(){let e=[],t=new Map,n=(n,r,i)=>{let a=t.get(n)??t.set(n,new Set).get(n);a.has(r)||(a.add(r),e.push(i))};return{edges:e,add:n,link:(e,t,r)=>{e&&t&&t!==e&&n(e,t,{from:e,to:t,kind:r})}}}function Lt(e,t){for(let n of Dt)for(let r of Ot){let i=z(e,`${t}/${r}${n}`);if(i)return i}let n=e.byRoot.get(t);return n?.length===1?n[0]:null}function Rt(e,t,n,r){return/^\/[^?]/u.test(n)?z(e,t+n)??jt(n.slice(1)).map(n=>z(e,`${t}/${n}`)).find(Boolean):z(e,t+n)??r(e,t)}function zt(e,t,n,r=Lt){let i=/^(?:\.{1,2}|[a-z]:)?\\/iu.test(n)?n.replaceAll(`\\`,`/`):n,a=dt.test(i);if(a||/^(?:\.{1,2}(?:\/|$)|\/|[a-z]:\/)/iu.test(i)||N(i)){let n=a?L(i):mt(t.path,i),r=z(e,n);return r?{to:r}:{to:null,path:n}}if(lt.test(i)&&e.byPath.has(i))return{to:e.byPath.get(i)};let o=R(P(n)),s=o===null?null:Nt(e,t,o);if(s===null)return{to:null,...Ft(n)};let c=Rt(e,s,n.slice(o.length),r);return c?{to:c}:{to:null,package:o}}var B=class extends Error{name=`SourceMapError`},Bt=new Uint8Array(128).fill(255);for(let[e,t]of[...`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/,;`].entries())Bt[t.codePointAt(0)]=e;function Vt(e){let t=new Int32Array(e.length*2);return t.set(e),t}function Ht(e){let{starts:t,columns:n,sources:r,names:i}=e;for(let e=0;e+1<t.length;e++){let[a,o]=[t[e],t[e+1]],s=a+1;for(;s<o&&n[s-1]<=n[s];)s++;if(s>=o)continue;let c=Array.from(n.subarray(a,o),(e,t)=>[e,r[a+t],i[a+t]]).sort((e,t)=>e[0]-t[0]);for(let[e,[t,o,s]]of c.entries())[n[a+e],r[a+e],i[a+e]]=[t,o,s]}return e}function Ut(e){let t=[0],n=new Int32Array(1024),r=new Int32Array(1024),i=new Int32Array(1024),a=0;for(let{mappings:o,files:s,line:c,column:l,names:u,nameCount:d}of e){if(typeof o!=`string`)throw new B(`mappings is not a string`);for(;t.length<=c;)t.push(a);let e=[0,0,0,0,0],f=0,p=0,m=1,h=l;for(let c=0;c<=o.length;c++){let l=c<o.length?Bt[o.codePointAt(c)]??255:64;if(l<32){if(p+=l*m,f===5)throw new B(`mappings: a segment of more than 5 fields at ${c}`);e[f++]+=p%2?(1-p)/2:p/2,p=0,m=1;continue}if(l<64){if(p+=(l-32)*m,m*=32,m>2**30)throw new B(`mappings: a value at ${c} runs past 32 bits`);continue}if(l===255)throw new B(`mappings: ${JSON.stringify(o[c])} at ${c} is not a base64 digit`);if(m!==1)throw new B(`mappings: the value before ${c} is cut off`);if(f>0){if(f===2||f===3)throw new B(`mappings: a segment of ${f} fields before ${c}`);let t=f===1?-1:s[e[1]];if(t===void 0)throw new B(`mappings: source ${e[1]} before ${c} is not in sources`);if(e[0]<0)throw new B(`mappings: a negative generated column before ${c}`);a===n.length&&([n,r,i]=[Vt(n),Vt(r),Vt(i)]),n[a]=e[0]+h,r[a]=t,i[a++]=f===5&&e[4]>=0&&e[4]<d?u+e[4]:-1,f=0}l===65&&(t.push(a),e[0]=0,h=0)}}return t.push(a),Ht({starts:Int32Array.from(t),columns:n.slice(0,a),sources:r.slice(0,a),names:i.slice(0,a)})}var Wt=new WeakMap,Gt=e=>Wt.get(e),V=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function H(e,t){if(!e)throw new B(t)}function Kt(e,t){if(e===void 0)return[];H(Array.isArray(e),`${t} is not an array`);for(let n of e)H(typeof n==`string`||n===null,`${t} holds ${JSON.stringify(n)}`);return e}function qt(e,t,n,r){let i=e.bySource.get(t);if(i!==void 0)return e.files[i].content??=n,e.files[i].ignored||=r,i;let a=t===null?null:L(t,e.mapPath);return e.files.push({source:t,path:a,package:a===null?null:bt(a),content:n,ignored:r}),t!==null&&e.bySource.set(t,e.files.length-1),e.files.length-1}function Jt(e,t,n,r){H(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),H(e.sourceRoot===void 0||typeof e.sourceRoot==`string`,`sourceRoot is not a string`);let i=Kt(e.sources,`sources`),a=Kt(e.sourcesContent,`sourcesContent`),o=e.ignoreList??e.x_google_ignoreList??[];H(Array.isArray(o)&&o.every(e=>Number.isInteger(e)&&e>=0&&e<i.length),`ignoreList is not a list of indices into sources`);let s=new Set(o),c=e.sourceRoot?e.sourceRoot.replace(/\/?$/u,`/`):``,l=i.map((e,n)=>qt(t,e===null?null:c+e,a[n]??null,s.has(n))),u=Array.isArray(e.names)?e.names:[];t.parts.push({mappings:e.mappings,files:l,line:n,column:r,names:t.names.length,nameCount:u.length}),t.names.push(...u)}function Yt(e,t){H(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),H(Array.isArray(e.sections),`sections is not an array`);for(let[n,r]of e.sections.entries()){let{offset:i,map:a}=V(r)?r:{};H(V(i)&&[i.line,i.column].every(e=>Number.isInteger(e)&&e>=0),`sections[${n}].offset is not a line and a column`),H(V(a)&&a.sections===void 0,`sections[${n}].map is not a plain source map`);let o=e.sections[n-1]?.offset;H(!o||o.line<i.line||o.line===i.line&&o.column<=i.column,`sections[${n}] starts before sections[${n-1}]`),Jt(a,t,i.line,i.column)}}function Xt(e,t={}){if(!V(t))throw TypeError(`readSourceMap: options is not an object`);if(t.path!==void 0&&typeof t.path!=`string`)throw TypeError(`readSourceMap: options.path is not a string`);let n=e;if(typeof e==`string`||e instanceof Uint8Array)try{let t=typeof e==`string`?e:new TextDecoder(`utf-8`,{fatal:!0}).decode(e);n=JSON.parse(t.replace(/^\)\]\}'[^\n]*\n/u,``))}catch(e){throw new B(`not JSON: ${e.message}`,{cause:e})}H(V(n),`not a JSON object`);let r={files:[],bySource:new Map,mapPath:t.path,parts:[],names:[]};n.sections===void 0?Jt(n,r,0,0):Yt(n,r);let i={files:r.files};return Wt.set(i,{...Ut(r.parts),nameList:r.names}),i}var Zt=/\r\n?|[\n\u2028\u2029]/gu;function Qt(e){let t=[0];for(let n of e.matchAll(Zt))t.push(n.index+n[0].length);return t}function $t(e,t,n,r){let[i,a]=[t,n];for(;i<a;){let t=i+a>>1;e[t]<=r?i=t+1:a=t}return i-1}function U(e,t){let n=$t(e,0,e.length,t);return[n,t-e[n]]}function en(e,[t,n]){if(t>=e.starts.length-1)return-1;let r=e.starts[t],i=$t(e.columns,r,e.starts[t+1],n);return i<r?-1:i}function tn(e,t,n,r){let i=Gt(e),a=U(t,n),[o,s]=U(t,r),c=new Map,l=en(i,a);for(let e=a[0];e<=o&&e<i.starts.length-1;e++){let t=e===a[0]&&l>=0?l:i.starts[e];for(let n=t;n<i.starts[e+1];n++){let t=i.sources[n];if(e===o&&i.columns[n]>=s)break;t>=0&&c.set(t,(c.get(t)??0)+1)}}let[u]=[...c].reduce((e,t)=>t[1]>e[1]?t:e,[-1,0]);return u<0?null:e.files[u]}var W=/\s+/uy,nn=`
|
|
2
|
-
\r\u2028\u2029`,G=/[\n\r\u2028\u2029]/gu,rn=/[\n\r\u2028\u2029]/u,K=/[\w$\u0080-]+/uy,an=new Set([`return`,`typeof`,`instanceof`,`in`,`of`,`new`,`delete`,`void`,`throw`,`case`,`default`,`extends`,`do`,`else`,`yield`,`await`]),on=new Set([`if`,`while`,`for`,`with`]),sn=new Set([`break`,`continue`,`debugger`]),cn=new Set([`(`,`[`,"${",`,`,`=`,`:`,`?`,`!`,`~`,`+`,`-`,`*`,`/`,`%`,`&`,`|`,`^`,`<`,`>`]);function ln(e,t){return e?.type===`word`?t&&[`return`,`yield`].includes(e.value)?!1:an.has(e.value)&&![`do`,`else`].includes(e.value):cn.has(e?.value)}function un(e){let t=e.at(-1);return t?.type===`word`&&(on.has(t.value)||t.value===`await`&&e.at(-2)?.value===`for`)}function dn(e){return e?e.type===`word`?an.has(e.value)||sn.has(e.value)||e.label===!0:e.value===`)`?e.control:e.value===`}`?!e.object:e.type===`punctuator`&&![`++`,`--`,`]`].includes(e.value):!0}var fn=(e,t)=>e.startsWith(`\r
|
|
3
|
-
`,t+1)?3:2,pn=/\\(?:u\{([\da-f]+)\}|u([\da-f]{4})|x([\da-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(\r\n|[\n\r\u2028\u2029])|(.))/giu,mn={b:`\b`,f:`\f`,n:`
|
|
4
|
-
`,r:`\r`,t:` `,v:`\v`};function hn(e){return e.includes(`\\`)?e.replace(pn,(e,t,n,r,i,a,o)=>{if(a!==void 0)return``;if(i!==void 0)return String.fromCodePoint(Number.parseInt(i,8));let s=Number.parseInt(t??n??r,16);return Number.isNaN(s)?mn[o]??o:String.fromCodePoint(Math.min(s,1114111))}):e}function gn(e,t){let n=e[t],r=t+1;for(;r<e.length&&e[r]!==n&&!nn.includes(e[r]);)r+=e[r]===`\\`?fn(e,r):1;return[e[r]===n?hn(e.slice(t+1,r)):null,r+1]}function _n(e,t){let n=t+1,r=!1;for(;n<e.length&&!nn.includes(e[n])&&(r||e[n]!==`/`);)e[n]===`\\`?n++:e[n]===`[`?r=!0:e[n]===`]`&&(r=!1),n++;return K.lastIndex=n+1,K.test(e)?K.lastIndex:n+1}function vn(e,t,n){for(let r=t;r<e.length;r++)if(e[r]===`\\`)r++;else{if(e[r]==="`")return r+1;if(e[r]===`$`&&e[r+1]===`{`)return n.push(`template`),r+2}return e.length}function yn(e){let t=[],n=[],r=[],i=0,a=0;for(;i<e.length;){let o=t.length;if(W.lastIndex=i,W.test(e)&&(i=W.lastIndex),i>=e.length)break;let s=e[i],c=e[i+1];if(K.lastIndex=i,s===`/`&&c===`/`)G.lastIndex=i+2,i=G.test(e)?G.lastIndex-1:e.length;else if(s===`/`&&c===`*`){let t=e.indexOf(`*/`,i+2);i=t<0?e.length:t+2}else if(s===`"`||s===`'`){let[n,r]=gn(e,i);t.push({type:`string`,value:n}),i=r}else if(s==="`"||s===`}`&&n.at(-1)===`template`){s===`}`&&n.pop();let r=n.length,a=vn(e,i+1,n),o=s==="`"&&n.length===r&&e[a-1]==="`";t.push({type:`string`,value:o?hn(e.slice(i+1,a-1)):null}),n.length>r&&t.push({type:`punctuator`,value:"${"}),i=a}else if(s===`/`&&dn(t.at(-1)))i=_n(e,i),t.push({type:`regex`});else if(K.test(e)){let n=sn.has(t.at(-1)?.value)&&!rn.test(e.slice(a,i));t.push({type:`word`,value:e.slice(i,K.lastIndex),...n&&{label:n}}),i=K.lastIndex}else{s===`{`&&n.push(ln(t.at(-1),rn.test(e.slice(a,i)))?`object`:`block`);let o=s===`}`?n.pop():void 0;s===`(`&&r.push(un(t));let l=(s===`+`||s===`-`)&&c===s||s===`=`&&c===`>`?s+c:s;t.push({type:`punctuator`,value:l,...s===`)`&&{control:r.pop()===!0},...s===`}`&&{object:o===`object`}}),i+=l.length}t.length>o&&(a=i)}return t}var q=e=>e?.type===`string`&&e.value!==null,bn=new Set([`type`,`typeof`]),xn=(e,t)=>e[t+1]?.type===`word`&&(e[t+1].value!==`as`||e[t+2]?.type!==`word`||e[t+2].value===`as`);function Sn(e,t){let n=!1;for(let r=t+1;r<e.length&&e[r].value!==`}`;r++)if(!(r>t+1&&e[r-1].value!==`,`)){if(!bn.has(e[r].value)||!xn(e,r))return!1;n=!0}return n}function Cn(e,t){for(let n=t;n<e.length;n++){let{value:r}=e[n];if(r===`;`||n>t&&(r===`import`||r===`export`))return null;if(r===`from`&&q(e[n+1]))return e[n+1].value}return null}function wn(e,t){let[n,r,i]=[e[t].value,e[t+1],e[t+2]],a=n===`import`?`import`:`export-from`;if(n===`import`&&q(r))return{kind:a,specifier:r.value};if(bn.has(r?.value)&&![`,`,`from`].includes(i?.value)||r?.value===`{`&&Sn(e,t+1)||n===`export`&&![`{`,`*`].includes(r?.value)||n===`import`&&r?.type!==`word`&&![`{`,`*`].includes(r?.value))return null;let o=Cn(e,t+1);return o===null?null:{kind:a,specifier:o}}function Tn(e,t){let[n,r]=[e[t+2],e[t+3]];if(n?.value!==`)`)return q(n)&&[`)`,`,`].includes(r?.value)?n.value:null}function En(e,t=new Set){let n=yn(e),r=[];for(let[e,i]of n.entries()){if(i.type!==`word`||[`.`,`#`,`function`].includes(n[e-1]?.value)||n[e-1]?.value===`=`&&n[e-3]?.value===`type`&&n[e-4]?.value===`import`)continue;let a=n[e+1]?.value===`(`,o=a?Tn(n,e):void 0;if((i.value===`require`||t.has(i.value))&&o!==void 0)r.push({kind:`require`,specifier:o,...i.value!==`require`&&{callee:i.value}});else if(i.value===`import`&&a)o!==void 0&&r.push({kind:`dynamic-import`,specifier:o});else if(i.value===`import`||i.value===`export`){let t=wn(n,e);t&&r.push(t)}}return r}var Dn=/^[\w$]*__d\(/gmu,On=([e,t,n,...r])=>(typeof e==`number`||typeof e==`string`)&&(t===void 0||typeof t==`object`)&&(n===void 0||typeof n==`string`)&&r.length===0;function kn(e){let t=/\);?\s*$/u.exec(e)?.index,n=null,r=t===void 0?-1:e.lastIndexOf(`},`,t);for(;r>=0&&/[\d"]/u.test(e[r+2]);){let i;try{i=JSON.parse(`[${e.slice(r+2,t)}]`)}catch{break}if(!On(i))break;n=i,r=r>0?e.lastIndexOf(`},`,r-1):-1}return n}function An(e){let t=/^[^(]*\(\s*(?:function\s*[\w$]*\s*)?\(([^)]*)\)/u.exec(e)?.[1].split(`,`).slice(1,4).map(e=>e.trim().replaceAll(`$`,`\\$`));if(!t?.length)return[];let n=e.matchAll(RegExp(`(?<=[^\\w$.#]|\\.\\.\\.)(?:${t.join(`|`)})\\((\\d+|"(?:[^"\\\\]|\\\\.)*")[,)]`,`gu`));return[...new Set([...n].map(e=>JSON.parse(e[1])))]}function jn(e,t){if(Array.isArray(e))return e;let n=Object.entries(e??{}).filter(([e])=>/^\d+$/u.test(e)).map(([,e])=>e);return n.length>0?n:An(t)}function Mn(e,t){let n=new Map(t.files.map((e,t)=>[e,t])),r=e.flatMap((e,t)=>e.file?[{k:t,at:n.get(e.file)}]:[]);for(let n=0;n<(r[0]?.k??0);n++)e[n].file=t.files[r[0].at-r[0].k+n]??null;for(let[n,{k:i,at:a}]of r.entries()){let o=r[n+1];if(!(o&&o.at-a!==o.k-i))for(let n=i+1;n<(o?.k??e.length);n++)e[n].file=t.files[a+n-i]??null}}function Nn(e,t){let n=[...e.matchAll(Dn)].map(e=>e.index);if(n.length===0)return null;let r=Qt(e),i=t=>e.slice(r[t],r[t+1]),a=[];for(let[o,s]of n.entries()){let[c]=U(r,s),[l]=U(r,(n[o+1]??e.length)-1),u=kn(i(l));for(;!u&&l>c;)u=kn(i(--l));if(!u)throw Error(`bundleEdges: the Metro module at line ${c+1} ends in no define params`);let d=r[l+1]??e.length;a.push({id:u[0],file:tn(t,r,s,d),dependencies:jn(u[1],e.slice(s,d))})}Mn(a,t);let o=new Map(a.map(e=>[e.id,e])),{edges:s,link:c}=It();for(let{file:e,dependencies:t}of a)for(let n of t)c(e,o.get(n)?.file,`dependency`);return s}var Pn=e=>e.path!==null&&![`json`,null].includes(St(e.path)),Fn=e=>e.path!==null&&St(e.path)===null;function In(e){let t=/^_([A-Za-z]+)\d+$/u.exec(e)?.[1];if(t)return[t,`interopRequireDefault`];let n=/^_(interopRequire(?:Default|Wildcard)|jsx(?:Dev)?Runtime|callSuper)$/u.exec(e)?.[1];return n===`callSuper`?[`getPrototypeOf`,`possibleConstructorReturn`,`interopRequireDefault`]:n?[n]:[]}var Ln={jsxRuntime:`react/jsx-runtime`,jsxDevRuntime:`react/jsx-dev-runtime`};function Rn(e){let{sources:t,names:n,nameList:r}=Gt(e),i=new Map,a=new Map,o=e.files.map(()=>new Set);for(let e=0;e<n.length;e++)n[e]<0||t[e]<0||(a.has(n[e])||a.set(n[e],In(r[n[e]]).length>0),a.get(n[e])&&o[t[e]].add(r[n[e]]));for(let[t,n]of o.entries()){if(n.size===0)continue;let r=e.files[t],a=new Set(Array.from((r.content??``).matchAll(/(?:function|var|let|const)\s+(_[A-Za-z]+\d*)\b/gu),e=>e[1])),o=[...n].filter(e=>!a.has(e)&&!a.has(e.replace(/\d+$/u,``))).flatMap(In);o.length>0&&i.set(r,o.map(e=>Ln[e]??`@babel/runtime/helpers/${e}`))}return i}function zn(e,t){let n=new Map;for(let[r,i]of e){let e=n.get(r)??n.set(r,new Map).get(r);for(let n of i)e.set(n,zt(t,r,n,()=>null))}let r=new Set([...n.values()].flatMap(e=>[...e.values()].map(e=>e.to))),i=(e,n)=>t.byRoot.get(n).find(e=>!r.has(e))??t.byRoot.get(n)[0];return(e,r)=>{let a=n.get(e)?.get(r);return a?.to?a:zt(t,e,r,i)}}var Bn=e=>/(?:^|\/)__prelude__$/u.test(e.source??``),Vn=e=>e?.package?.name===`metro-runtime`&&e.package.path===`src/polyfills/require.js`;function Hn(e){if(!e.files.some(Bn)&&!Vn(e.files[0]))return null;if(!e.files.some(e=>e.content!==null&&!Bn(e)&&!Vn(e)))throw Error("bundleEdges: the Metro map carries no sourcesContent, which its edges are read from; pass the bundle as `code`");let t=Mt(e.files),n=e.files[e.files.findIndex(Fn)+1],r=e.files.find(e=>e.package?.name===`metro-runtime`&&e.package.path===`src/modules/asyncRequire.js`),i=new Map(e.files.filter(e=>e.content!==null&&Pn(e)).map(e=>[e,En(e.content)])),a=Rn(e),o=zn([...[...i].map(([e,t])=>[e,t.flatMap(({specifier:e})=>e===null?[]:[e])]),...a],t),{edges:s,add:c,link:l}=It();for(let t of e.files){Fn(t)&&l(t,n,`dependency`);for(let{kind:e,specifier:n}of i.get(t)??[]){let i=n===null?{to:null}:o(t,n);i.to!==t&&c(t,`${e}\0${JSON.stringify(n)}`,{from:t,kind:e,specifier:n,...i}),e===`dynamic-import`&&l(t,r,`dependency`)}for(let e of a.get(t)??[])l(t,o(t,e).to,`dependency`)}return s}var Un=(e,t)=>t==null?Hn(e):Nn(t,e);function Wn(e,t){let n=Un(e,t);if(!n)throw Error(`bundleEdges: not a Metro ${t==null?`map`:`bundle`}; edges-lite.js reads only those, edges.js reads others`);return{edges:n}}function Gn(e){let t=JSON.parse(e.replace(/^\)\]\}'[^\n]*\n/u,``)),n=Xt(t),r=t.sections?t.sections.reduce((e,t)=>e+(t.map.names?.length??0),0):t.names?.length??null;return{json:{version:t.version,file:t.file,sourceRoot:t.sourceRoot},map:n,namesCount:r}}function J(e){if(e.map)return e.map.files.flatMap(e=>e.source===null?[]:[[e.source,e.content]]);let t=e.json?.sourcesContent??[];return(e.json?.sources??[]).map((e,n)=>[e,t[n]??null])}function Kn(e,t){let n=new Map;for(let{from:r,to:i,specifier:a}of t(e).edges){if(r.source===null||i?.source==null||i.source===r.source)continue;let e=typeof a==`string`?[r.source,i.source,a]:[r.source,i.source];n.set(e.join(`\0`),e)}return[...n.values()]}function qn(e){try{return Wn(e)}catch{return{edges:[]}}}var Jn=Object.freeze([]);function Y(e){return e?.edges?e.edges:e?.map?(e.edges=Kn(e.map,qn),e.edges):Jn}var Yn=new WeakMap,Xn=new WeakMap;function Zn(e){let t=Y(e);if(!Yn.has(t)){let e=new Map;for(let[n,r]of t)e.has(n)||e.set(n,new Set),e.get(n).add(r);Yn.set(t,e)}return Yn.get(t)}function Qn(e){let t=Y(e);if(!Xn.has(t)){let e=new Map;for(let[n,r,i]of t)i!==void 0&&(e.has(n)||e.set(n,new Map),e.get(n).set(i,r));Xn.set(t,e)}return Xn.get(t)}var $n=new WeakMap,er=new WeakMap,tr=new WeakMap,nr=new WeakMap,X=new WeakMap,rr=new WeakMap;function Z(e){if(e?.metadataOnly)return new Map;let t=e?.bundle??e?.json;if(t&&$n.has(t))return $n.get(t);let n=new Map;if(!e)return n;if(e.kind===`stasis`){if(!e.bundle)return n;let t=e.bundle.formats;for(let[r,i]of e.bundle.sources)typeof i==`string`&&(j.isResourceFormat(t?.get(r))||n.set(r,i))}else if(e.kind===`sourcemap`)for(let[t,r]of J(e))typeof r==`string`&&n.set(t,r);return t&&$n.set(t,n),n}function ir(e){let t=1;for(let n=e.indexOf(`
|
|
5
|
-
`);n!==-1;n=e.indexOf(`
|
|
6
|
-
`,n+1))t++;return t}var ar=new WeakMap;function or(e){let t=ar.get(e);if(!t){let n=[...e.keys()].toSorted();t={paths:n,numbers:new Map(n.map((e,t)=>[e,t+1]))},ar.set(e,t)}return t}function sr(e,t){let n=Array.isArray(t)?t:[];return{integrity:e.integrity,kind:`sourcemap`,size:e.size,json:{version:3,sources:n.map(([e])=>e),sourcesContent:n.map(([,,e])=>typeof e==`string`?e:null)},fileSizes:new Map(n.map(([e,t])=>[e,t])),npmBinaries:new Map(n.filter(([,,e,t])=>typeof e!=`string`&&typeof t==`string`).map(([e,t,,n])=>[e,{size:t,digest:n}]))}}function cr(e){let t=e?.bundle??e?.json;if(t&&er.has(t))return er.get(t);let n=new Map(Z(e));for(let[t,r]of e?.npmBinaries??[])n.set(t,{format:`digest`,...r});if(e?.kind===`stasis`&&e.bundle){let t=e.bundle.formats;for(let[r,i]of e.bundle.sources){if(typeof i!=`string`)continue;let e=t?.get(r);e===`resource`?n.set(r,i):e===`resource:base64`&&n.set(r,{format:`base64`,data:i})}}return t&&er.set(t,n),n}var lr=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;function ur(e){let t=e.endsWith(`=`);if(t?e.length%4!=0||e.at(-3)===`=`:e.length%4==1)return null;let n=t?e.slice(0,e.endsWith(`==`)?-2:-1):e;if(/[^A-Za-z0-9+/]/u.test(n))return null;let r=n.length%4;return r>1&&lr.indexOf(n.at(-1))&(r===2?15:3)?null:Math.floor(n.length*3/4)}function dr(e){return typeof e==`string`?t(e):e?.format===`digest`?e.size:e?.format===`base64`?ur(e.data):null}function Q(e){if(e?.fileSizes)return e.fileSizes;let t=e?.bundle??e?.json;if(t&&tr.has(t))return tr.get(t);let n=new Map,r=cr(e),i=e?.kind===`stasis`?e.bundle?.sources.keys():e&&J(e).map(([e])=>e);for(let e of i??[])n.set(e,dr(r.get(e)));return t&&tr.set(t,n),n}function fr(e){if(e?.metadataOnly)return e.unsizedFiles??new Set;let t=Q(e);if(rr.has(t))return rr.get(t);let n=new Set;for(let r of cr(e).keys())t.get(r)===null&&n.add(r);return rr.set(t,n),n}function pr(e){let t=Q(e);if(X.has(t))return X.get(t);let n=fr(e),r=e?.kind===`stasis`?e.bundle?.formats:null,i=new Map;for(let[a,o]of t)o===null&&!n.has(a)||i.set(a,j.isResourceFormat(r?.get(a))||e?.npmBinaries?.has(a)?`resource`:`source`);return X.set(t,i),i}function mr(e){let t=Q(e),n=e?.kind===`stasis`?e.bundle?.formats:null;if(!n||n.size===0)return t;if(nr.has(t))return nr.get(t);let r=new Map;for(let[e,i]of t)j.isResourceFormat(n.get(e))||r.set(e,i);return nr.set(t,r),r}var hr=new WeakMap;function gr(e){if(e?.kind!==`stasis`||!e.bundle?.modules)return null;if(hr.has(e.bundle))return hr.get(e.bundle);let t=new Map;for(let[n,r]of e.bundle.modules)for(let e of Object.keys(r.files))t.set(n===`.`?e:`${n}/${e}`,n);return hr.set(e.bundle,t),t}function _r(e,t=null,n=(e,t)=>t.name){let r=new Map;if(e?.kind!==`stasis`||!e.bundle?.modules)return r;let i=t===null?null:gr(e),a=t===null?null:new Set([...t].map(e=>i?.get(e)));for(let[t,i]of e.bundle.modules){if(a&&!a.has(t)||!t.includes(`node_modules`)||!i?.name||typeof i.version!=`string`||!i.version)continue;let e=n(t,i),o=r.get(e);o||(o=new Set,r.set(e,o)),o.add(i.version)}return r}var vr=Object.freeze({javascript:`JavaScript`,jsx:`JSX`,typescript:`TypeScript`,tsx:`TSX`,json:`JSON`,css:`CSS`,markup:`HTML`,yaml:`YAML`,bash:`Shell`,markdown:`Markdown`,solidity:`Solidity`,php:`PHP`,rust:`Rust`,ruby:`Ruby`,java:`Java`,cpp:`C++`,c:`C`,objectivec:`Objective-C`,python:`Python`,go:`Go`,kotlin:`Kotlin`,swift:`Swift`,dart:`Dart`,sql:`SQL`,lua:`Lua`,csharp:`C#`,scala:`Scala`,vue:`Vue`,svelte:`Svelte`}),yr=Object.freeze({py:`python`,pyw:`python`,go:`go`,kt:`kotlin`,kts:`kotlin`,swift:`swift`,dart:`dart`,sql:`sql`,lua:`lua`,cs:`csharp`,scala:`scala`,sc:`scala`,vue:`vue`,svelte:`svelte`});function br(e){let t=typeof e==`string`?e.slice(e.lastIndexOf(`/`)+1):``,n=t.lastIndexOf(`.`),r=n>0?t.slice(n+1).trim().toLowerCase():``,i=st(e)??yr[r];return i?{key:i,label:vr[i]??i}:r?{key:`extension:${r}`,label:`.${r}`}:{key:`other`,label:`Other`}}function xr(e,t){let n=new Map,r=0,i=0;for(let[a,o]of e){let e=br(a),s=n.get(e.key)??{...e,files:0,lines:0,bytes:0};s.files++,s.lines+=o,s.bytes+=t.get(a)??0,n.set(e.key,s),i+=o,r+=t.get(a)??0}return{files:e.size,lines:i,bytes:r,languages:[...n.values()].toSorted((e,t)=>t.lines-e.lines||e.label.localeCompare(t.label))}}var Sr=6,$=new WeakMap,Cr=new Set([`terminal`,`code`,`search`,`compare`]);function wr(e,t=null){return!!t||Cr.has(e)}var Tr=/^sha512-[A-Za-z0-9+/]{86}==$/u;function Er(t){if(t.fileHashes)return Promise.resolve(t.fileHashes);if($.has(t))return $.get(t);let n=(async()=>{let n=[...Z(t)],r=new Map;for(let t=0;t<n.length;t+=32){let i=await Promise.all(n.slice(t,t+32).map(async([t,n])=>[t,await e(n)]));for(let[e,t]of i)r.set(e,t)}return t.fileHashes=r,r})();return $.set(t,n),n.catch(()=>$.delete(t)),n}function Dr(e){if(typeof e!=`string`)return 0;let t=/\S/gu,n=/[\r\n]/gu,r=0;for(;t.test(e)&&(r++,n.lastIndex=t.lastIndex,n.test(e));)t.lastIndex=n.lastIndex;return r}function Or(e){return e.lineCounts??=new Map([...Z(e)].map(([e,t])=>[e,Dr(t)]))}function kr(e){return e instanceof Map?Object.fromEntries([...e].map(([e,t])=>[e,kr(t)])):e}async function Ar(e){let n=await Er(e),r=Q(e),i=Or(e),a={version:Sr,integrity:e.integrity,kind:e.kind,size:e.size,codeStats:xr(i,r),files:[...r].map(([e,t])=>[e,t,n.get(e)??null,i.get(e)??null])},o=fr(e);if(o.size>0&&(a.unsized=[...o]),e.kind===`sourcemap`){let{version:n,file:r,sourceRoot:i,names:o}=e.json,s=J(e);a.json={version:n,file:r,sourceRoot:i,sources:s.map(([e])=>e)},a.sourceSizes=s.map(([,e])=>typeof e==`string`?t(e):null),a.namesCount=e.namesCount??o?.length??null;let c=new Map(a.files.map(([e],t)=>[e,t]));a.edges=Y(e).map(([e,t,...n])=>[c.get(e),c.get(t),...n])}else{let t=e.bundle,n={version:t.version,config:t.config,repo:t.repo,package:t.package,formats:kr(t.formats),imports:kr(t.imports),reason:t.reason,executable:[...t.executable]};if(t.version===0)n.sources=Object.fromEntries([...r.keys()].map(e=>[e,null]));else{let e={},r={};for(let[n,i]of t.modules){let t=n.split(`/`).includes(`node_modules`)?e:r;Object.defineProperty(t,n,{enumerable:!0,value:{name:i.name,version:i.version,ecosystem:i.ecosystem,repo:i.repo,files:Object.fromEntries(Object.keys(i.files).map(e=>[e,null]))}})}n.modules=e,t.config.scope===`full`&&(n.sources=r,n.entries=[...t.entries])}a.bundle=n}return a}function jr(e,t){if(![1,2,3,4,5,Sr].includes(e?.version)||e.integrity!==t||![`stasis`,`sourcemap`].includes(e.kind)||!Number.isSafeInteger(e.size)||e.size<0||!Array.isArray(e.files))throw Error(`Invalid bundle metadata`);let n=e.version!==Sr,r=e.version===1,i=new Map,a=new Map,o=new Map;for(let t of e.files){if(!Array.isArray(t)||t.length!==4&&!(r&&t.length===3))throw Error(`Invalid bundle metadata file`);let[e,n,s,c]=t;if(typeof e!=`string`||a.has(e)||n!==null&&(!Number.isSafeInteger(n)||n<0)||s!==null&&(typeof s!=`string`||!Tr.test(s))||n===null&&s!==null||r&&n!==null&&s===null||c!=null&&(!Number.isSafeInteger(c)||c<0))throw Error(`Invalid bundle metadata file`);a.set(e,n),s!==null&&i.set(e,s),c!=null&&o.set(e,c)}let s=new Set(e.unsized??[]);if(e.unsized!==void 0&&(r||!Array.isArray(e.unsized)||s.size!==e.unsized.length)||[...s].some(e=>typeof e!=`string`||!a.has(e)||a.get(e)!==null))throw Error(`Invalid bundle metadata`);let c={integrity:t,kind:e.kind,size:e.size,metadataOnly:!0,fileSizes:a,fileHashes:i,lineCounts:o,unsizedFiles:s,stale:n};if(e.kind===`stasis`){c.bundle=j.fromJSON(e.bundle);let t=c.bundle.sources;if(t.size!==a.size||[...t.keys()].some(e=>!a.has(e)))throw Error(`Invalid bundle metadata inventory`);let n=c.bundle.formats;if(!r&&[...a].some(([e,t])=>i.has(e)!==(t!==null&&!j.isResourceFormat(n.get(e))))||[...s].some(e=>n.get(e)!==`resource:base64`))throw Error(`Invalid bundle metadata inventory`)}else{if(!e.json||typeof e.json!=`object`||![null,void 0].includes(e.namesCount)&&(!Number.isSafeInteger(e.namesCount)||e.namesCount<0))throw Error(`Invalid sourcemap metadata`);if(!Array.isArray(e.json.sources)||e.json.sources.some(e=>!a.has(e))||!Array.isArray(e.sourceSizes)||e.sourceSizes.length!==e.json.sources.length||e.sourceSizes.some(e=>e!==null&&(!Number.isSafeInteger(e)||e<0))||[...a].some(([e,t])=>i.has(e)!==(t!==null))||s.size>0)throw Error(`Invalid sourcemap inventory`);c.json=e.json,c.sourceSizes=e.sourceSizes,c.namesCount=e.namesCount,e.edges!==void 0&&(c.edges=Mr(e.edges,e.files))}if(e.codeStats===void 0)c.codeStats=xr(o,a);else{let t=e.codeStats,n=e=>Number.isSafeInteger(e)&&e>=0;if(!t||![t.files,t.lines,t.bytes].every(n)||!Array.isArray(t.languages)||t.languages.some(e=>!e||typeof e.key!=`string`||typeof e.label!=`string`||![e.files,e.lines,e.bytes].every(n)))throw Error(`Invalid bundle code stats`);c.codeStats=t}return c}function Mr(e,t){if(!Array.isArray(e))throw Error(`Invalid sourcemap edges`);return e.map(e=>{if(!Array.isArray(e)||![2,3].includes(e.length)||e[0]===e[1]||e.length===3&&typeof e[2]!=`string`||e.slice(0,2).some(e=>!Number.isSafeInteger(e)||e<0||e>=t.length))throw Error(`Invalid sourcemap edges`);return[t[e[0]][0],t[e[1]][0],...e.slice(2)]})}function Nr(e,{integrity:t,kind:n,size:r}){if(n===`stasis`)return{integrity:t,kind:n,size:r,bundle:j.parse(e)};if(n!==`sourcemap`)throw Error(`Unsupported bundle format`);return{integrity:t,kind:n,size:r,...Gn(e)}}export{$e as a,j as b,st as c,Y as d,Zn as e,Qn as f,Z as g,ir as h,or as i,sr as j,cr as k,dr as l,Q as m,pr as n,mr as o,gr as p,_r as q,xr as r,wr as s,Er as t,Dr as u,Or as v,Ar as w,jr as x,Nr as y};
|
package/out/chunk-HT2SSA3V.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=new Set([`overview`,`graph`,`treemap`,`compare`,`advisories`,`issues`,`code`,`search`,`terminal`]),t=/^\d+$/u;function n(e){for(let t=0;t<e.length;t++){let n=e.codePointAt(t);if(n<32||n===127)return!0}return!1}var r=512;function i(e){return typeof e==`string`&&e.length>0&&e.length<=r&&!n(e)}function a(e){return i(e)&&!t.test(e)}var o=/^(?=.{1,214}$)(?:@[\w.-]+\/[\w-]|[\dA-Za-z])[\w.-]*$/u,s=/^(?=.{1,256}$)[\dA-Za-z][\w.+-]*$/u,c=/^@[\da-z~-][\w.~-]*$/u,l=/^(?:[\da-f]{64}|[2-7a-z]{26})$/u;function u(e){return typeof e==`string`&&o.test(e)}function d(e){return typeof e==`string`&&s.test(e)}function f(e){return typeof e==`string`&&l.test(e)}function p(e){return typeof e==`string`&&e.length>0&&e.length<=1024&&!/[\p{Cc}\\]/u.test(e)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`)}function m(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase(),n=t.startsWith(`@`)?t:`@${t}`;return n.length<=214&&c.test(n)?n:null}var h=new Set([`code`,`diff`]),g=e=>h.has(e)?`code`:`overview`,_=e=>h.has(e)?{compareMode:`code`}:{},v=e=>h.has(e)?`/code`:``,y=Object.freeze({manage:`/manage`,"manage-bundles":`/manage/bundle`,"manage-scans":`/manage/scans`,"manage-reports":`/manage/report`,"manage-repos":`/manage/repositories`,"manage-repo-risk":`/manage/repositories/risk`,"admin-users":`/manage/users`,"manage-teams":`/manage/team`,"manage-import":`/manage/import`,"manage-links":`/manage/links`,"manage-deduplication":`/manage/deduplication`,"manage-history":`/manage/history`}),b=new Set([`workspace-reports`,`workspace-bundles`,`workspace-repositories`,`workspace-dependencies`]),x=new Set([`pulls`,`versions`,`branch`,`reviews`]),S=e=>e.view===`workspace-dependencies`&&e.dependencyTab!=null?{dependencyTab:e.dependencyTab}:{};function C(e){if(!a(e)||e===`.`||e===`..`)return null;try{return`/finding/${encodeURIComponent(e)}`}catch{return null}}function w(t){if(!t)return null;if(t.view===`home`)return`/`;if(t.view===`reviews`)return`/my/reviews`;if(t.view===`profile`)return`/my/profile`;if(t.view===`npm`)return D(t);if(t.view===`repository-code`)return R(t);if(b.has(t.view)){let e=S(t).dependencyTab??`pulls`;return!/^[A-Za-z0-9_-]+$/u.test(t.teamSlug??``)||!x.has(e)?null:`/team/${t.teamSlug}/${t.view.slice(10)}${e===`pulls`?``:`/${e}`}`}if(t.view===`bundles`){if(!/^[A-Za-z0-9_-]+$/u.test(t.bundleSlug??``)||[t.teamSlug,t.compareSlug].some(e=>e!=null&&!/^[A-Za-z0-9_-]+$/u.test(e)))return null;let n=t.bundleTab??`overview`;if(!e.has(n))return null;let r=t.teamSlug?`/team/${t.teamSlug}`:`/manage`,i=n===`code`&&B(t.file)?`/${t.file}`:``,a=i&&B(t.line)?`#L${t.line}${B(t.endLine)&&t.endLine>t.line?`-L${t.endLine}`:``}`:``,o=n===`compare`&&t.compareSlug!=null?`/${t.compareSlug}${v(t.compareMode)}`:``;return`${r}/bundle/${t.bundleSlug}${n===`overview`?``:`/${n}`}${i}${o}${a}`}if(Object.hasOwn(y,t.view)){let e=y[t.view];return t.view===`manage-deduplication`&&t.linkId?`${e}?report=${encodeURIComponent(t.linkId)}`:t.view===`manage-bundles`&&Number.isSafeInteger(t.createRepoId)&&t.createRepoId>0?`${e}?createRepo=${t.createRepoId}`:t.view===`manage-scans`&&t.scanMode===`link`?`${e}?mode=link`:t.view===`manage-scans`&&t.bundleId?`${e}?bundle=${encodeURIComponent(t.bundleId)}${t.scanMode===`dependencies`?`&mode=dependencies`:``}`:t.view===`manage-history`&&t.actor?`${e}?actor=${encodeURIComponent(t.actor)}`:e}if(![`findings`,`files`].includes(t.view)||!t.teamSlug||[t.teamSlug,t.reportSlug].some(e=>e!=null&&!/^[A-Za-z0-9_-]+$/u.test(e)))return null;let n=`/team/${encodeURIComponent(t.teamSlug)}`,r=t.reportSlug?`/report/${encodeURIComponent(t.reportSlug)}`:``;if(t.finding){let e=C(t.finding.id);return t.view===`findings`&&e?`${n}${r}${e}`:null}return`${n}${r}${t.view===`files`?`/files`:``}`}var T=new Set([`overview`,`code`,`search`,`compare`,`review`,`treemap`]),E=e=>f(e?.hash)&&I(e.repoId)&&P.test(e.commit??``)&&p(e.path);function D(e){if(e.packageName==null)return`/npm`;let t=e.bundleTab??`overview`;if(!u(e.packageName)||e.packageSpec!=null&&!d(e.packageSpec)||!T.has(t)||e.compareSpec!=null&&!d(e.compareSpec))return null;if(t===`review`){if(e.reviewPackage!=null&&!u(e.reviewPackage)||e.reviewSpec!=null&&!d(e.reviewSpec)||e.patch!=null&&!E(e.patch))return null;let t=e.reviewPackage==null?``:`/${e.reviewPackage}${e.reviewSpec==null?``:`@${e.reviewSpec}`}`,n=e.patch==null?``:`?patch=${e.patch.hash}&repo=${e.patch.repoId}&commit=${e.patch.commit}&path=${e.patch.path.split(`/`).map(encodeURIComponent).join(`/`)}`;return`/npm/${e.packageName}${e.packageSpec==null?``:`@${e.packageSpec}`}/review${t}${n}`}let n=t===`code`&&B(e.file)?`/${e.file}`:``,r=n&&B(e.line)?`#L${e.line}${B(e.endLine)&&e.endLine>e.line?`-L${e.endLine}`:``}`:``,i=t===`compare`&&e.compareSpec!=null?`/${e.compareSpec}${v(e.compareMode)}`:``;return`/npm/${e.packageName}${e.packageSpec==null?``:`@${e.packageSpec}`}${t===`overview`?``:`/${t}`}${n}${i}${r}`}function O(e,t,n){let r=/^\/npm\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?\/review(?:\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?)?$/u.exec(e);if(r){if(!u(r[1])||r[2]!=null&&!d(r[2])||r[3]!=null&&!u(r[3])||r[4]!=null&&!d(r[4]))return null;let e=r[3]&&/^\d+\.\d+\.\d+(?:[-+].*)?$/u.test(r[3])&&r[4]==null,t=n.has(`patch`)?{hash:n.get(`patch`),repoId:/^[1-9]\d*$/u.test(n.get(`repo`)??``)?Number(n.get(`repo`)):null,commit:n.get(`commit`),path:n.get(`path`)}:null;return t&&!E(t)?null:{view:`npm`,packageName:r[1],packageSpec:r[2]??null,bundleTab:`review`,...r[3]?{reviewPackage:e?r[1]:r[3],reviewSpec:e?r[3]:r[4]??null}:{},...t?{patch:t}:{}}}let i=/^\/npm(?:\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(?:\/(code|search|compare|treemap)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u.exec(e);if(!i)return;if(i[1]==null)return{view:`npm`};if(!u(i[1])||i[2]!=null&&!d(i[2]))return null;let a={view:`npm`,packageName:i[1],packageSpec:i[2]??null,bundleTab:i[3]??`overview`};if(i[4]==null)return a;if(a.bundleTab===`compare`)return d(i[4])&&(i[5]==null||h.has(i[5]))?{...a,compareSpec:i[4],..._(i[5])}:null;if(a.bundleTab!==`code`)return null;let o=Number(i[4]);return!i[5]&&/^[1-9]\d*$/u.test(i[4])&&Number.isSafeInteger(o)?{...a,file:o,...V(t)}:null}var k=new Set([`code`,`search`,`treemap`,`compare`,`commits`,`issues`,`pulls`,`agents`,`pulse`,`replay`]),A=new Set([`commits`,`issues`,`pulls`,`agents`,`pulse`,`replay`]),j=new Map([[`issues`,new Set([`closed`])],[`pulls`,new Set([`closed`])],[`pulse`,new Set([`week`,`quarter`,`year`])],[`replay`,new Set([`100`,`1000`])]]),M=/^[a-z][a-z\d-]{0,31}$/u,N=(e,t)=>e===`agents`?typeof t==`string`&&M.test(t)&&t!==`all`:j.get(e)?.has(t)===!0,P=/^[a-f\d]{40}$/u,F=500,I=e=>Number.isSafeInteger(e)&&e>0;function L(e){return typeof e==`string`&&(e===``||e.length<=F&&!/[\p{Cc}\\]/u.test(e)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e===e.trim()))}function R(e){let t=e.bundleTab??`code`,n=e.path??``;if(!I(e.repoId)||e.commit!=null&&!P.test(e.commit)||!L(n)||!k.has(t)||e.compareCommit!=null&&!P.test(e.compareCommit))return null;let r=n?`?path=${n.split(`/`).map(encodeURIComponent).join(`/`)}`:``;if(e.commit==null)return`/repo/${e.repoId}${r}`;let i=t===`code`&&B(e.file)?`/code/${e.file}`:t===`code`?``:`/${t}`,a=t===`compare`&&e.compareCommit!=null?`/${e.compareCommit}${v(e.compareMode)}`:``,o=N(t,e.subtab)?`/${e.subtab}`:``,s=t===`code`&&B(e.file)&&B(e.line)?`#L${e.line}${B(e.endLine)&&e.endLine>e.line?`-L${e.endLine}`:``}`:``;return`/repo/${e.repoId}/${e.commit}${i}${a}${o}${r}${s}`}function z(e){let t=/^\/(?:repo|manage\/code)\/([1-9]\d*)(?:\/([a-f\d]{40})(?:\/(code|search|treemap|compare|commits|history|issues|pulls|agents|pulse|replay)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u.exec(e.pathname.replace(/\/$/u,``));if(!t)return;let n=Number(t[1]),r=e.searchParams.get(`path`)??``,i=t[3]===`history`?`commits`:t[3]??`code`;if(!I(n)||!L(r))return null;let a={view:`repository-code`,repoId:n,commit:t[2]??null,path:r,bundleTab:i};if(t[4]==null)return a;if(i===`compare`)return P.test(t[4])&&(t[5]==null||h.has(t[5]))?{...a,compareCommit:t[4],..._(t[5])}:null;if(A.has(i))return t[5]==null&&N(i,t[4])?{...a,subtab:t[4]}:null;let o=Number(t[4]);return i===`code`&&t[5]==null&&/^[1-9]\d*$/u.test(t[4])&&Number.isSafeInteger(o)?{...a,file:o,...V(e.hash)}:null}function B(e){return Number.isSafeInteger(e)&&e>0}function V(e){let t=/^#L([1-9]\d*)(?:-L([1-9]\d*))?$/u.exec(e),[n,r]=t?[Number(t[1]),Number(t[2]??t[1])]:[];return!B(n)||!B(r)?{}:n===r?{line:n}:{line:Math.min(n,r),endLine:Math.max(n,r)}}function H(t){let n=t.pathname.replace(/\/$/u,``)||`/`;if(n===`/`||n===`/index.html`)return{view:`home`};if(n===`/my/reviews`)return{view:`reviews`};if(n===`/my/profile`){let e=t.searchParams.get(`link-error`);return{view:`profile`,...e&&/^[a-z-]{1,64}$/u.test(e)?{linkError:e}:{}}}let i=Object.keys(y).find(e=>y[e]===n);if(i){let e=Number(t.searchParams.get(`createRepo`));return{view:i,...i===`manage-deduplication`&&t.searchParams.get(`report`)?{linkId:t.searchParams.get(`report`)}:{},...i===`manage-bundles`&&Number.isSafeInteger(e)&&e>0?{createRepoId:e}:{},...i===`manage-history`&&t.searchParams.get(`actor`)?{actor:t.searchParams.get(`actor`)}:{},...i===`manage-scans`?t.searchParams.get(`mode`)===`link`?{scanMode:`link`}:t.searchParams.get(`bundle`)?{bundleId:t.searchParams.get(`bundle`),...t.searchParams.get(`mode`)===`dependencies`?{scanMode:`dependencies`}:{}}:{}:{}}}let a=/^(?:\/team\/([A-Za-z0-9_-]+)|\/manage)\/bundle\/([A-Za-z0-9_-]+)(?:\/([a-z]+)(?:\/([A-Za-z0-9_-]+)(?:\/([a-z]+))?)?)?$/u.exec(n);if(a){let n=a[3]??`overview`;if(!e.has(n))return null;let r={view:`bundles`,teamSlug:a[1]??null,bundleSlug:a[2],bundleTab:n};if(a[4]==null)return r;if(n===`compare`)return a[5]==null||h.has(a[5])?{...r,compareSlug:a[4],..._(a[5])}:null;let i=Number(a[4]);return n!==`code`||a[5]||!/^[1-9]\d*$/u.test(a[4])||!Number.isSafeInteger(i)?null:{...r,file:i,...V(t.hash)}}let o=O(n,t.hash,t.searchParams);if(o!==void 0)return o;let s=z(t);if(s!==void 0)return s;let c=/^\/team\/([A-Za-z0-9_-]+)\/(reports|bundles|repositories|dependencies)$/u.exec(n);if(c)return{view:`workspace-${c[2]}`,teamSlug:c[1]};let l=/^\/team\/([A-Za-z0-9_-]+)\/dependencies\/([a-z]+)$/u.exec(n);if(l)return x.has(l[2])?{view:`workspace-dependencies`,teamSlug:l[1],dependencyTab:l[2]}:null;let u=/^\/team\/([^/]+)(?:\/report\/([^/]+))?(?:\/(files)|\/finding\/([^/]+))?$/u.exec(n);if(!u)return null;try{let e=decodeURIComponent(u[1]),t=u[2]?decodeURIComponent(u[2]):null;if([e,t].some(e=>e!=null&&!/^[A-Za-z0-9_-]+$/u.test(e))||u[4]?.length>r*9)return null;let n=u[4]?decodeURIComponent(u[4]):null;return n!=null&&!C(n)?null:{view:u[3]?`files`:`findings`,teamSlug:e,reportSlug:t,...n==null?{}:{finding:{id:n}}}}catch{return null}}function U(e,t,n=[]){if(b.has(e.view)){let n=t.filter(t=>t.slug===e.teamSlug);return n.length===1?{view:e.view,teamId:n[0].id,...S(e)}:null}if(e.view===`bundles`){let{teamSlug:r,bundleSlug:i,compareSlug:a,compareMode:o,...s}=e,c=r==null?[]:t.filter(e=>e.slug===r);if(r!=null&&c.length!==1)return null;let l=c[0],u=r==null?n:t.flatMap(e=>e.bundles??[]),d=e=>new Set(u.filter(t=>t.slug===e).map(e=>e.id)),f=d(i),p=(l?.bundles??n).find(e=>e.slug===i);if(!i||!p||f.size!==1)return null;let m=a==null?null:d(a),h=m?.size===1?{compareId:[...m][0],..._(o)}:{};return{...s,teamId:l?.id??null,bundleId:p.id,...h}}if(![`findings`,`files`].includes(e.view))return e;let{teamSlug:r,reportSlug:i,...a}=e,o=t.filter(e=>e.slug===r);if(!r||o.length!==1)return null;let s=o[0];if(i==null)return{...a,teamId:s.id,reportId:null};let c=t.flatMap(e=>e.reports??[]).filter(e=>e.slug===i),l=new Set(c.map(e=>e.id)),u=(s.reports??[]).find(e=>e.slug===i);return u&&l.size===1?{...a,teamId:s.id,reportId:u.id}:null}function W(e,t,n=[]){if(b.has(e.view)){let n=t.find(t=>t.id===e.teamId),r={view:e.view,teamSlug:n?.slug,...S(e)};return n?.slug&&U(r,t)?r:null}if(e.view===`bundles`){let{teamId:r,bundleId:i,compareId:a,compareMode:o,...s}=e,c=t.find(e=>e.id===r);if(r!=null&&!c?.slug)return null;let l=(c?.bundles??n).find(e=>e.id===i);if(!l?.slug)return null;let u=a==null?null:(r==null?n:t.flatMap(e=>e.bundles??[])).find(e=>e.id===a),d={...s,teamSlug:c?.slug??null,bundleSlug:l.slug,...u?.slug?{compareSlug:u.slug,..._(o)}:{}},f=U(d,t,n);if(!f)return null;if(d.compareSlug!=null&&f.compareId!==a){let{compareSlug:e,compareMode:t,...n}=d;return n}return d}if(![`findings`,`files`].includes(e.view))return e;let{teamId:r,reportId:i,...a}=e,o=t.find(e=>e.id===r),s=i==null?null:o?.reports?.find(e=>e.id===i);if(!o?.slug||i!=null&&!s?.slug)return null;let c={...a,teamSlug:o.slug,reportSlug:s?.slug??null};return U(c,t)?c:null}export{e as a,r as b,a as c,u as d,d as e,f,p as g,m as h,g as i,_ as j,y as k,x as l,w as m,T as n,k as o,A as p,N as q,H as r,U as s,W as t};
|