jso-protector 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +960 -0
- package/LICENSE +90 -0
- package/MIGRATION.md +207 -0
- package/README.md +1477 -0
- package/RELEASE.md +82 -0
- package/SECURITY.md +71 -0
- package/ai-cli.js +392 -0
- package/ai.js +176 -0
- package/bin/jso-protector.js +12066 -0
- package/browserify.d.ts +10 -0
- package/browserify.js +88 -0
- package/bun.d.ts +10 -0
- package/bun.js +41 -0
- package/ci/Jenkinsfile +82 -0
- package/ci/argo-workflows.yaml +121 -0
- package/ci/azure-pipelines.yml +56 -0
- package/ci/bitbucket-pipelines.yml +43 -0
- package/ci/buildkite.yml +50 -0
- package/ci/circleci.yml +60 -0
- package/ci/drone.yml +67 -0
- package/ci/github-actions.yml +51 -0
- package/ci/gitlab-ci.yml +39 -0
- package/ci/gocd.yaml +79 -0
- package/ci/teamcity.kts +79 -0
- package/ci/tekton.yaml +106 -0
- package/ci/verify-package.js +748 -0
- package/ci/verify-publish-metadata.js +147 -0
- package/ci/verify-templates.js +195 -0
- package/ci/woodpecker.yml +53 -0
- package/compliance/cli.js +204 -0
- package/compliance/evidence-forwarder.js +209 -0
- package/compliance/pci-dss-v4/controls.json +75 -0
- package/compliance/pci-dss-v4/index.js +2613 -0
- package/config/named-sets.js +185 -0
- package/esbuild.d.ts +16 -0
- package/esbuild.js +190 -0
- package/examples/README.md +78 -0
- package/examples/browserify/build.js +20 -0
- package/examples/bun/package.json +13 -0
- package/examples/bun/scripts/protect-release.js +28 -0
- package/examples/cli-basic/jso.config.cjs +23 -0
- package/examples/cli-basic/jso.config.json +15 -0
- package/examples/cli-basic/package.json +14 -0
- package/examples/cli-basic/scripts/build.js +10 -0
- package/examples/curl/README.md +55 -0
- package/examples/curl/protect.sh +106 -0
- package/examples/esbuild/build.js +19 -0
- package/examples/grunt/Gruntfile.js +29 -0
- package/examples/gulp/gulpfile.js +19 -0
- package/examples/helm/Chart.yaml +27 -0
- package/examples/helm/README.md +69 -0
- package/examples/helm/templates/_helpers.tpl +23 -0
- package/examples/helm/templates/_podtemplate.tpl +64 -0
- package/examples/helm/templates/job.yaml +39 -0
- package/examples/helm/templates/secret.yaml +17 -0
- package/examples/helm/values.yaml +54 -0
- package/examples/kubernetes/job.yaml +123 -0
- package/examples/metro.config.js +11 -0
- package/examples/nextjs/next.config.js +11 -0
- package/examples/node-api/protect-release.js +28 -0
- package/examples/node-api/release-summary.js +59 -0
- package/examples/parcel/package.json +13 -0
- package/examples/parcel/scripts/protect-release.js +28 -0
- package/examples/payment-page-script-inventory.json +62 -0
- package/examples/payment-page-security-headers.json +46 -0
- package/examples/pre-commit/.pre-commit-config.yaml +33 -0
- package/examples/pre-commit/README.md +45 -0
- package/examples/react-native/README.md +208 -0
- package/examples/react-native/metro.config.js +11 -0
- package/examples/rollup/rollup.config.js +20 -0
- package/examples/rspack/rspack.config.js +28 -0
- package/examples/turbopack/package.json +13 -0
- package/examples/turbopack/scripts/protect-release.js +28 -0
- package/examples/vite/vite.config.js +18 -0
- package/examples/webpack/webpack.config.js +21 -0
- package/examples/webpack-loader/webpack.config.js +22 -0
- package/governance/index.d.ts +18 -0
- package/governance/index.js +309 -0
- package/grunt.d.ts +4 -0
- package/grunt.js +111 -0
- package/gulp.d.ts +10 -0
- package/gulp.js +106 -0
- package/index.d.ts +879 -0
- package/index.js +607 -0
- package/jso.config.example.json +29 -0
- package/jso.config.schema.json +548 -0
- package/metro.d.ts +43 -0
- package/metro.js +117 -0
- package/next.d.ts +24 -0
- package/next.js +64 -0
- package/package.json +241 -0
- package/parcel.d.ts +10 -0
- package/parcel.js +40 -0
- package/react-native.d.ts +2 -0
- package/react-native.js +3 -0
- package/release-signer.js +245 -0
- package/rollup.d.ts +13 -0
- package/rollup.js +71 -0
- package/rspack-loader.d.ts +13 -0
- package/rspack-loader.js +11 -0
- package/rspack.d.ts +11 -0
- package/rspack.js +9 -0
- package/runtime/ai-script-governance.js +379 -0
- package/runtime/countermeasures.js +0 -0
- package/runtime/data-exfiltration-guard.d.ts +7 -0
- package/runtime/data-exfiltration-guard.js +161 -0
- package/runtime/environment-integrity.js +389 -0
- package/runtime/managed-integrity.d.ts +4 -0
- package/runtime/managed-integrity.js +108 -0
- package/runtime/third-party-inventory.js +437 -0
- package/turbopack.d.ts +10 -0
- package/turbopack.js +41 -0
- package/vite.d.ts +16 -0
- package/vite.js +78 -0
- package/watermark.js +126 -0
- package/webpack-loader.d.ts +15 -0
- package/webpack-loader.js +97 -0
- package/webpack.d.ts +13 -0
- package/webpack.js +143 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
JavaScript Obfuscator — jso-protector
|
|
2
|
+
Proprietary Software Licence
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 JavaScript Obfuscator. All rights reserved.
|
|
5
|
+
|
|
6
|
+
This software is licensed, not sold. It is made publicly installable through the
|
|
7
|
+
npm registry as a convenience for licensees and evaluators. Publication on a
|
|
8
|
+
public registry does not place it in the public domain and does not grant any
|
|
9
|
+
open-source licence.
|
|
10
|
+
|
|
11
|
+
1. GRANT
|
|
12
|
+
|
|
13
|
+
Subject to the terms below, you are granted a non-exclusive, non-transferable,
|
|
14
|
+
revocable licence to:
|
|
15
|
+
|
|
16
|
+
(a) download, install and execute this package; and
|
|
17
|
+
|
|
18
|
+
(b) use it to protect source code that you own or are authorised to modify.
|
|
19
|
+
|
|
20
|
+
2. RUNTIME COMPONENTS
|
|
21
|
+
|
|
22
|
+
The files under `runtime/` are designed to be incorporated into the output of
|
|
23
|
+
your own build. You may embed those components, in original or transformed
|
|
24
|
+
form, into your own applications and distribute them as an integral part of
|
|
25
|
+
those applications, including to your end users, with no obligation to
|
|
26
|
+
reproduce this licence in that output.
|
|
27
|
+
|
|
28
|
+
This permission covers distribution as part of a working application only. It
|
|
29
|
+
does not permit extracting, republishing, repackaging or offering the runtime
|
|
30
|
+
components on their own, or as part of any product whose purpose is code
|
|
31
|
+
protection, obfuscation, tamper detection or a substantially similar function.
|
|
32
|
+
|
|
33
|
+
3. RESTRICTIONS
|
|
34
|
+
|
|
35
|
+
Except as expressly permitted in Section 2, and except where the following
|
|
36
|
+
cannot lawfully be restricted in your jurisdiction, you may not:
|
|
37
|
+
|
|
38
|
+
(a) redistribute, sublicense, sell, rent, lease or host this package or any
|
|
39
|
+
part of it as a standalone offering;
|
|
40
|
+
|
|
41
|
+
(b) modify, adapt or create derivative works of this package;
|
|
42
|
+
|
|
43
|
+
(c) reverse engineer, decompile or disassemble it, or attempt to derive the
|
|
44
|
+
methods used by the runtime protection components, other than to the
|
|
45
|
+
extent required for interoperability where that right is granted by
|
|
46
|
+
applicable law;
|
|
47
|
+
|
|
48
|
+
(d) remove, obscure or alter any copyright, licence or attribution notice; or
|
|
49
|
+
|
|
50
|
+
(e) use it to protect code that you neither own nor are authorised to modify.
|
|
51
|
+
|
|
52
|
+
4. FEATURES REQUIRING A SUBSCRIPTION
|
|
53
|
+
|
|
54
|
+
Some functionality transmits source code to the JavaScript Obfuscator hosted
|
|
55
|
+
API and requires a valid, current subscription. Your use of those features is
|
|
56
|
+
additionally governed by the service terms published at
|
|
57
|
+
https://www.javascriptobfuscator.com/. Nothing in this licence grants access
|
|
58
|
+
to the hosted service.
|
|
59
|
+
|
|
60
|
+
5. NO WARRANTY
|
|
61
|
+
|
|
62
|
+
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
63
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
64
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
65
|
+
|
|
66
|
+
No representation is made that obfuscated or protected output cannot be
|
|
67
|
+
analysed, reverse engineered or recovered. Code protection raises the cost of
|
|
68
|
+
analysis; it does not make it impossible. Do not rely on this software as the
|
|
69
|
+
sole control protecting secrets, credentials or safety-critical logic.
|
|
70
|
+
|
|
71
|
+
6. LIMITATION OF LIABILITY
|
|
72
|
+
|
|
73
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
74
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
75
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
|
|
76
|
+
DEALINGS IN THE SOFTWARE.
|
|
77
|
+
|
|
78
|
+
7. TERMINATION
|
|
79
|
+
|
|
80
|
+
This licence terminates automatically if you breach any of its terms. On
|
|
81
|
+
termination you must cease all use and destroy all copies. Section 2
|
|
82
|
+
permissions already exercised in respect of applications distributed before
|
|
83
|
+
termination survive, so that your end users are not affected.
|
|
84
|
+
|
|
85
|
+
8. GOVERNING LAW
|
|
86
|
+
|
|
87
|
+
This licence is governed by the laws of the jurisdiction in which the
|
|
88
|
+
copyright holder is established, without regard to conflict-of-law rules.
|
|
89
|
+
|
|
90
|
+
Questions about licensing: https://www.javascriptobfuscator.com/
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Migrating from javascript-obfuscator
|
|
2
|
+
|
|
3
|
+
Use `jso-protector` when you want JavaScript Obfuscator account credentials, hosted HTTP API protection, CI guardrails, release manifests, and the same release workflow across the online tool, CLI, Node API, and build plugins.
|
|
4
|
+
|
|
5
|
+
Use a local-only obfuscator when source code cannot leave the build machine.
|
|
6
|
+
|
|
7
|
+
## Replace the package command
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm remove javascript-obfuscator
|
|
11
|
+
npm install --save-dev ./packages/jso-protector
|
|
12
|
+
npx jso-protector --init
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For an application in another folder, pin the local package with a `file:` dependency:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"jso-protector": "file:../packages/jso-protector"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For internal sharing without publishing to npm, install a private tarball produced by `npm pack --json`.
|
|
26
|
+
|
|
27
|
+
Set credentials from the JavaScript Obfuscator dashboard:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
set JSO_API_KEY=base64-api-key
|
|
31
|
+
set JSO_API_PASSWORD=base64-api-password
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Long aliases also work:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
set JAVASCRIPT_OBFUSCATOR_API_KEY=base64-api-key
|
|
38
|
+
set JAVASCRIPT_OBFUSCATOR_API_PASSWORD=base64-api-password
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Map familiar concepts
|
|
42
|
+
|
|
43
|
+
| javascript-obfuscator concept | jso-protector / HTTP API direction |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `stringArray`, `stringArrayEncoding` | `MoveStrings`, `EncodeStrings`, `EncryptStrings` |
|
|
46
|
+
| Identifier rename settings | `ReplaceNames`, `RenameGlobals`, `RenameMembers`, `IdentityStyle` |
|
|
47
|
+
| `reservedNames` | `reservedNames`, `--reserved-name`, or `VariableExclusion` |
|
|
48
|
+
| Control-flow and dead-code transforms | `DeepObfuscate`, `ReorderCode`, `FlatTransform`, `AddDeadCode`, `DeadcodeLevel` |
|
|
49
|
+
| Formatting and compact output | `SelfCompression`, `CompressionRatio`, `WriteFormats` |
|
|
50
|
+
| Domain and date restrictions | `domainLock` maps to `LockDomain` and `LockDomainList`; date locks use `LockDate`, `LockDateValue` |
|
|
51
|
+
|
|
52
|
+
The names are not a one-to-one copy. Run this before porting a large config:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
jso-protector --list-options --json
|
|
56
|
+
jso-protector --list-presets --json
|
|
57
|
+
jso-protector --list-migration-map --json
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`--list-migration-map` includes a summary with mapped, direct, approximate, review-only, and total known option counts. Use that summary in migration tooling to decide whether a project can be converted automatically or needs manual review first.
|
|
61
|
+
|
|
62
|
+
You can generate a starter config from a common `javascript-obfuscator` JSON or trusted CommonJS config file:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
jso-protector --migrate-javascript-obfuscator javascript-obfuscator.json --output jso.config.json
|
|
66
|
+
jso-protector --migrate-javascript-obfuscator javascript-obfuscator.config.cjs --output jso.config.json
|
|
67
|
+
jso-protector --config jso.config.json --release-check --json
|
|
68
|
+
jso-protector --config jso.config.json --competitor-gap-report --json
|
|
69
|
+
jso-protector --config jso.config.json --validate-config --json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use `--json` with the migration command when internal tooling needs the generated config plus a per-config summary, mapped options, review items, and unmapped option lists:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
jso-protector --migrate-javascript-obfuscator javascript-obfuscator.json --json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The converter maps familiar settings such as string arrays, control-flow flattening, dead-code insertion, identifier styles, `parseHtml`, `domainLock`, reserved names, and target runtime. When you protect inline scripts inside template files, add `markupExtensions` for the file types you ship such as `.php`, `.aspx`, or `.jsp`. The report summary includes source option, mapped, direct, approximate, review-only, unmapped, and automatic coverage counts, a review reference for every known review-only option, then prints the next validate, dry-run, doctor, release-check, competitor-gap-report, and protect commands. Use `--release-check --json` when you want those preflight checks in one CI report, and run `--competitor-gap-report --json` after migration to keep runtime-defense mapping, locks, source maps, identifier caches, and release-forensics review items visible. CommonJS source configs execute as Node.js code, so only migrate configs from your own repository or another trusted source.
|
|
79
|
+
|
|
80
|
+
You can also keep simple package scripts close to their old shape by using compatibility flags directly:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
jso-protector src/app.js
|
|
84
|
+
jso-protector dist --output dist-protected --options-preset high-obfuscation --control-flow-flattening --string-array-encoding rc4 --reserved-names "^PublicApi$"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For direct single-file scripts, `jso-protector src/app.js` writes `src/app-obfuscated.js` when no `--output` or config `output` is set. Folder and config-file workflows keep using the configured output folder, usually `dist-protected`.
|
|
88
|
+
|
|
89
|
+
Mapped compatibility flags include `--options-preset`, `--parse-html`, `--string-array`, `--string-array-encoding`, `--unicode-escape-sequence`, `--control-flow-flattening`, `--dead-code-injection`, `--dead-code-injection-threshold`, `--identifier-names-generator`, `--rename-globals`, `--rename-properties`, `--reserved-names`, `--domain-lock`, `--target`, and `--compact`. Config and Node API `domainLock` arrays map to `LockDomain` plus newline-delimited `LockDomainList`; review `domainLockRedirectUrl` separately because the hosted API lock message is not a redirect. `--options-preset default`, `low-obfuscation`, `vm-default`, and `vm-low-obfuscation` map to `standard`; `medium-obfuscation` and `vm-medium-obfuscation` map to `balanced`; `high-obfuscation`, `vm-high-obfuscation`, `vm-ultra-high-obfuscation`, and `vm-anti-llm` map to `maximum`.
|
|
90
|
+
|
|
91
|
+
The same mapped compatibility keys can live in `jso.config.json` while you are migrating. Explicit `options` values override the compatibility mapping, so you can start familiar and then tune exact hosted API fields without changing scripts.
|
|
92
|
+
|
|
93
|
+
The CLI also accepts common review-only flags such as `--source-map`, `--source-map-sources-mode`, `--identifier-names-cache`, `--identifier-names-cache-path`, `--identifiers-dictionary`, `--identifiers-prefix`, `--self-defending`, `--debug-protection`, `--disable-console-output`, `--reserved-strings`, `--rename-properties-mode`, `--strict-mode`, `--numbers-to-expressions`, `--seed`, `--simplify`, `--split-strings`, and string-array wrapper/index flags so older scripts do not fail immediately. `--ignore-imports` is handled directly and preserves import/export-from statements plus common static `require()` and `import()` statements before the remaining code is protected. Other review-only flags emit compatibility warnings when there is no one-to-one hosted API mapping. Run `jso-protector --explain-compat self-defending --json` or replace `self-defending` with any mapped or review-only option to see the recommended migration action.
|
|
94
|
+
|
|
95
|
+
## Start with a conservative config
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"$schema": "./node_modules/jso-protector/jso.config.schema.json",
|
|
100
|
+
"apiKey": "$JSO_API_KEY",
|
|
101
|
+
"apiPassword": "$JSO_API_PASSWORD",
|
|
102
|
+
"input": "dist",
|
|
103
|
+
"output": "dist-protected",
|
|
104
|
+
"preset": "balanced",
|
|
105
|
+
"exclude": ["**/*.map", "**/vendor/**", "**/polyfills-*.js"],
|
|
106
|
+
"parseHtml": false,
|
|
107
|
+
"honorConditionalComments": false,
|
|
108
|
+
"reservedNames": ["^PublicApi$", "^renderWidget$"],
|
|
109
|
+
"manifest": "dist-protected/jso-manifest.json",
|
|
110
|
+
"maxGrowthRatio": 8,
|
|
111
|
+
"options": {
|
|
112
|
+
"OptimizationMode": "Web",
|
|
113
|
+
"LockDomain": false
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Replace direct Node usage
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const { obfuscate, obfuscateMultiple, getOptionsByPreset, protectCode } = require("jso-protector");
|
|
122
|
+
|
|
123
|
+
const obfuscationResult = await obfuscate(sourceCode, {
|
|
124
|
+
apiKey: process.env.JSO_API_KEY,
|
|
125
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
126
|
+
controlFlowFlattening: true,
|
|
127
|
+
domainLock: ["example.com", "app.example.com"],
|
|
128
|
+
identifierNamesGenerator: "hexadecimal",
|
|
129
|
+
reservedNames: ["^PublicApi$"],
|
|
130
|
+
stringArrayEncoding: ["rc4"]
|
|
131
|
+
}, "app.js");
|
|
132
|
+
|
|
133
|
+
const protectedCode = obfuscationResult.getObfuscatedCode();
|
|
134
|
+
const alsoProtectedCode = obfuscationResult.toString();
|
|
135
|
+
|
|
136
|
+
const multipleResults = await obfuscateMultiple({
|
|
137
|
+
"foo.js": "var foo = 1;",
|
|
138
|
+
"bar.js": "var bar = 2;"
|
|
139
|
+
}, {
|
|
140
|
+
apiKey: process.env.JSO_API_KEY,
|
|
141
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
142
|
+
...getOptionsByPreset("balanced")
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`obfuscate(code, options, fileName)` and `obfuscateMultiple(sourceCodesObject, options)` are the closest replacements for `JavaScriptObfuscator.obfuscate(...)` and `JavaScriptObfuscator.obfuscateMultiple(...)`, but they return Promises because protection happens through the hosted HTTP API. They accept common `javascript-obfuscator` option names directly, including `stringArray`, `stringArrayEncoding`, `controlFlowFlattening`, `deadCodeInjection`, `deadCodeInjectionThreshold`, `identifierNamesGenerator`, `renameGlobals`, `renameProperties`, `reservedNames`, `compact`, and `target`.
|
|
147
|
+
|
|
148
|
+
Use `getOptionsByPreset("standard" | "balanced" | "maximum")` when replacing preset lookup helpers, and `translateJavascriptObfuscatorOptions(sourceOptions, overrides)` when migration tooling needs to inspect the mapped hosted API config before making the API call.
|
|
149
|
+
|
|
150
|
+
## JS-Confuser migration
|
|
151
|
+
|
|
152
|
+
Use the dedicated JS-Confuser helpers when the current project is built around `js-confuser` rather than `javascript-obfuscator`:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
jso-protector --list-js-confuser-migration-map --json
|
|
156
|
+
jso-protector --explain-js-confuser-compat lock.endDate --json
|
|
157
|
+
jso-protector --migrate-js-confuser js-confuser.config.cjs --output jso.config.json
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The current JS-Confuser migration path maps common preset, lock, identifier, string, minify, and control-flow settings into the nearest hosted API equivalents. Runtime-only features such as anti-debugging, integrity checks, self-defending locks, start-date gating, countermeasure hooks, and tamper protection are preserved in generated config as `jsConfuserLock*` review fields so teams can carry that intent forward explicitly. Custom locks, opaque predicates, dispatcher mode, and similar JS-Confuser-specific transforms are still surfaced as review items rather than guessed automatically.
|
|
161
|
+
|
|
162
|
+
Existing custom build scripts can also use `protectCode(options, code, fileName)` when they prefer the JavaScript Obfuscator API naming:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
const { protectCode } = require("jso-protector");
|
|
166
|
+
|
|
167
|
+
const protectedCode = await protectCode({
|
|
168
|
+
apiKey: process.env.JSO_API_KEY,
|
|
169
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
170
|
+
preset: "balanced",
|
|
171
|
+
reservedNames: ["^PublicApi$"]
|
|
172
|
+
}, sourceCode, "app.js");
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
For full build output, prefer the CLI or a bundle plugin so the release can remove stale source maps, write a manifest, and enforce size budgets.
|
|
176
|
+
|
|
177
|
+
## Replace bundler plugins
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
const jsoProtector = require("jso-protector/vite");
|
|
181
|
+
|
|
182
|
+
module.exports = {
|
|
183
|
+
plugins: [
|
|
184
|
+
jsoProtector({
|
|
185
|
+
apiKey: process.env.JSO_API_KEY,
|
|
186
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
187
|
+
preset: "balanced",
|
|
188
|
+
include: ["assets/*.js"],
|
|
189
|
+
exclude: ["**/vendor/**"],
|
|
190
|
+
manifest: "dist/jso-manifest.json",
|
|
191
|
+
maxGrowthRatio: 8
|
|
192
|
+
})
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Equivalent entrypoints are available for Rollup, Webpack, Webpack loader, Browserify, esbuild, React Native (`jso-protector/react-native`), Gulp, and Grunt.
|
|
198
|
+
|
|
199
|
+
## Checklist
|
|
200
|
+
|
|
201
|
+
1. Run `jso-protector --release-check --json` and confirm the file list.
|
|
202
|
+
2. Run `jso-protector --competitor-gap-report --json` and decide whether runtime-defense review items, source-map policy, or identifier-cache gaps block the migration.
|
|
203
|
+
3. Exclude vendor bundles, polyfills, generated framework runtime files, and source maps.
|
|
204
|
+
4. Add `reservedNames` for public globals, framework entry points, and names called by external code.
|
|
205
|
+
5. Protect into a separate output folder first, then run browser smoke tests.
|
|
206
|
+
6. Add `manifest`, `maxOutputBytes`, or `maxGrowthRatio` once the protected output is stable.
|
|
207
|
+
7. Verify the protected artifact with `jso-protector --verify-manifest dist-protected/jso-manifest.json` before publishing or after unpacking CI artifacts.
|