@getexception/cli 0.1.23 → 0.1.25
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/README.md +56 -48
- package/dist/index.js +488 -69
- package/dist/integration.d.ts +44 -4
- package/dist/integration.js +215 -35
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,78 +1,86 @@
|
|
|
1
1
|
# @getexception/cli
|
|
2
2
|
|
|
3
|
-
Prepare and privately upload source maps
|
|
3
|
+
Prepare and privately upload browser JavaScript source maps. Node.js 20.19.6 or newer. No Git repository, CI/CD provider or deployment platform is required. Use matching SDK/server/CLI releases that include ADR-0009; these APIs are new and are not in earlier published packages.
|
|
4
4
|
|
|
5
|
-
```
|
|
5
|
+
```sh
|
|
6
6
|
yarn add --dev --exact @getexception/cli
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
In Settings → Source maps, the project Owner labels a key and selects **Production** or **Preview**. Each new key permits one environment: `production` or `preview`. To upload for both, create a separate key for each. There is no second project permission switch. The key label is only a name in the dashboard.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
yarn build
|
|
13
|
-
yarn getexception sourcemaps prepare --dir dist --output .getexception-maps --release "account@$CI_COMMIT_SHA"
|
|
14
|
-
yarn getexception sourcemaps upload --dir .getexception-maps --url https://sentry.frontend.sndsy.ru --project "$GETEXCEPTION_PROJECT_ID"
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
The Owner creates **Source map upload tokens** in the project's settings. Store the token in the CI secret `GETEXCEPTION_UPLOAD_TOKEN`. It expires after 90 days and can be revoked. Never pass it as a command-line argument or include it in the browser environment, repository, logs or public artifacts. Only trusted build jobs may read this secret.
|
|
18
|
-
|
|
19
|
-
For GitLab MR previews use short-lived `GETEXCEPTION_GITLAB_ID_TOKEN` instead, after the operator has configured the pinned GitLab trust policy. Run `getexception ci context --url <HTTPS dashboard origin> --project <UUID>` before building; use the returned release, deployment and asset prefix for the actual JavaScript output. Upload and release registration use that identity automatically. Never set both credential variables. See the [GitLab integration guide](../../docs/gitlab-ci.md) for server configuration, exact build isolation and production restrictions. Version 0.1.7 does not support this flow.
|
|
11
|
+
Store the key in private secret storage. Your script must read the key from your secret storage and pass it explicitly as `token` to `uploadSourceMaps`. The function does not read environment variables or `.env` files and has no default secret name. Never put the key in browser config, CLI arguments, Git, logs or public build output. It grants upload/release metadata rights only for its project and environment, expires within 90 days and can be revoked. Production keys must not be available to preview builds.
|
|
20
12
|
|
|
21
|
-
##
|
|
13
|
+
## Independent functions
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
```js
|
|
16
|
+
import {
|
|
17
|
+
prepareSourceMaps,
|
|
18
|
+
uploadSourceMaps,
|
|
19
|
+
assertPublicOutput,
|
|
20
|
+
} from "@getexception/cli/integration";
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
// MY_UPLOAD_KEY is your chosen secret variable, read by this script.
|
|
23
|
+
const uploadKey = process.env.MY_UPLOAD_KEY;
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
// Run your own build first with external/hidden JS maps and sourcesContent.
|
|
26
|
+
const prepared = await prepareSourceMaps({
|
|
27
|
+
directory: "dist",
|
|
28
|
+
output: "../private-maps", // a NEW private directory outside public output
|
|
29
|
+
release: "web-app@1.2.3",
|
|
30
|
+
buildId: "build-42",
|
|
31
|
+
format: "esm", // or classic for ordinary browser scripts
|
|
32
|
+
credentials: [uploadKey ?? ""], // reject this key in public files
|
|
33
|
+
});
|
|
34
|
+
await assertPublicOutput("dist", {
|
|
35
|
+
mapsEnabled: true,
|
|
36
|
+
credentials: [uploadKey ?? ""],
|
|
37
|
+
});
|
|
38
|
+
const result = await uploadSourceMaps({
|
|
39
|
+
directory: prepared.directory,
|
|
29
40
|
url: "https://monitor.example.com",
|
|
30
|
-
projectId:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
environment: "production",
|
|
34
|
-
environmentName: "production/app",
|
|
35
|
-
output: "packages/app/build",
|
|
36
|
-
runtimeEnv: {
|
|
37
|
-
release: "APP_GETEXCEPTION_RELEASE",
|
|
38
|
-
environment: "APP_GETEXCEPTION_ENVIRONMENT",
|
|
39
|
-
},
|
|
40
|
-
beforeBuild: async (safeEnv) => installAndSetUpDeployment(safeEnv),
|
|
41
|
-
build: async (safeEnv) => buildApplication(safeEnv),
|
|
42
|
-
deploy: async () => deployApplication(),
|
|
41
|
+
projectId: "<project UUID from Settings>",
|
|
42
|
+
environment: "preview",
|
|
43
|
+
token: uploadKey,
|
|
43
44
|
});
|
|
45
|
+
if (result.status !== "ready") {
|
|
46
|
+
console.warn("[getexception] Source maps unavailable", result.diagnostic);
|
|
47
|
+
}
|
|
44
48
|
```
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
The SDK must use the same `release`, `buildId` and upload `environment`. A version does not have to be a commit SHA. Change buildId for every rebuild; retain it when publishing the exact same files in another environment. The upload key must explicitly permit that environment. `buildId` is serialized as Sentry-compatible `dist`.
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
`prepareSourceMaps` changes JS by adding one Debug ID line, shifts mappings and removes `.js.map`/`.mjs.map` from public output. Run once before compression, SRI signing and publication. Classic scripts retain their directive prologue. Indexed maps, CSS maps and archives are unsupported. `urlPrefix` can prepend a deployment base path to artifact paths; paths must match actual browser JS URLs. Preparation fails closed on unsafe output, symlinks and private output inside the public directory. On failure, rebuild cleanly without maps and verify again before publication.
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
`uploadSourceMaps` does not build or deploy. It returns `{ status: "ready", batches }` only after every part validates, otherwise `{ status: "unavailable", diagnostic }`. Monitoring failure does not throw into your normal deployment. Production callers should make the warning prominent; preview callers can use one neutral log line. The default whole-delivery budget is 30 minutes, configurable via `timeoutMs` up to 60 minutes. Requests have bounded retries and timeouts. Both functions accept an optional `signal: AbortSignal` for cancellation.
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
Publish only the verified public directory. Keep private maps out of Git, CI artifacts/cache, image layers and public hosting. Use a private per-run workspace and delete it on success, failure and cancellation. A full `try/finally` example, separate manual upload and optional release registration are in the [project connection guide](../../docs/project-onboarding.md). Build, preparation, upload and deployment may be separate steps; moving private maps between hosts requires your own access-controlled temporary storage. No hosted provider artifact store is required or used automatically.
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
Retry with the same prepared maps; never prepare twice or rebuild just the maps. Existing files are reused by checksum within the project without sharing environment permissions. An immutable manifest receipt prevents replacing a build even after its map bytes expire. There is no fallback to the latest map or another environment. Late uploads reprocess retained matching events.
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
## Equivalent commands
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
```sh
|
|
63
|
+
yarn getexception sourcemaps prepare --dir dist --output ../private-maps --release web-app@1.2.3 --build-id build-42 --token-env MY_UPLOAD_KEY
|
|
64
|
+
yarn getexception sourcemaps check --dir dist --token-env MY_UPLOAD_KEY
|
|
65
|
+
yarn getexception sourcemaps deliver --dir ../private-maps/maps --url https://monitor.example.com --project "$GETEXCEPTION_PROJECT_ID" --environment preview --token-env MY_UPLOAD_KEY
|
|
66
|
+
```
|
|
59
67
|
|
|
60
|
-
|
|
68
|
+
`--token-env` explicitly names the private variable to read; it never contains the key value. Choose your own name. `deliver` does not select a variable automatically. For `prepare`/`check`, the selected key is used only to detect accidental leaks in public files.
|
|
61
69
|
|
|
62
|
-
|
|
70
|
+
`deliver` has the same optional-monitoring behavior as `uploadSourceMaps`. `prepare` and `check` exit nonzero for unsafe output. Never make all three commands unconditional success. Your ordinary compilation failures must also remain failures.
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
Limits: at most 4,096 maps per prepared build; 128 files and 128 MiB per upload batch; 16 MiB per map; 4 GiB per project; 8 GiB per installation; 5 GiB free-disk reserve. Large sets split into batches. Up to eight gzip-compressed maps upload concurrently, with compressed/uncompressed bounds and checksums. Source Map v3 JSON only, no remote downloads. Raw maps have no public download endpoint. Incomplete uploads expire after a day; ready maps follow the 30–60 day policy.
|
|
65
73
|
|
|
66
|
-
|
|
67
|
-
yarn getexception releases register --url https://sentry.frontend.sndsy.ru --project "$GETEXCEPTION_PROJECT_ID" --release "account@$CI_COMMIT_SHA" --environment staging --repository-id "$CI_MERGE_REQUEST_TARGET_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID"
|
|
68
|
-
```
|
|
74
|
+
## Compatibility
|
|
69
75
|
|
|
70
|
-
|
|
76
|
+
Only legacy credential-selection commands and `deployWithGetException` retain their published `GETEXCEPTION_UPLOAD_TOKEN` / GitLab identity convention. The independent functions and `sourcemaps deliver` do not use it.
|
|
71
77
|
|
|
72
|
-
|
|
78
|
+
The lower-level `sourcemaps upload` command retains strict failure exit status and accepts a single prepared manifest directory. Legacy preparation without `--build-id` remains available for earlier clients; new integrations should always send a build ID and explicit environment.
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
Existing keys keep their previously effective permissions, including existing environment names. The API retains support for one explicit environment name when creating a key; existing multi-environment keys remain valid until expiry or revocation. No names are automatically aliased to Production or Preview.
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
Existing GitLab identity clients and `deployWithGetException` remain supported with their former identity/namespace validation and legacy project policy. That policy does not control upload keys. These are optional compatibility APIs, not the onboarding path for new projects. See the [legacy GitLab guide](../../docs/gitlab-ci.md). Do not pass both legacy identity and permanent key variables to legacy credential-selection commands.
|
|
77
83
|
|
|
78
|
-
|
|
84
|
+
Permanent keys belong only in trusted execution contexts. An author who can change the script receiving a key can read it. A preview-only key does not make arbitrary external fork code safe to run with secrets.
|
|
85
|
+
|
|
86
|
+
MIT. See `THIRD-PARTY-NOTICES.md`.
|