@dataunlocker/script
v2.0.0
Published
A hook script installed to your website that enables DataUnlocker's proxy engine for scripts already present on the page.
Downloads
12
Maintainers
Readme
@dataunlocker/script
A sync "hook" script installed to your website that enables DataUnlocker's proxy engine synchronously (when page starts loading).
Installation
This package downloads a sync DataUnlocker's script that corresponds to your domain when being installed.
You will need to specify your DataUnlocker domain ID before installing the package. Follow the installation guide at admin.dataunlocker.com for more details.
Install with env variable
Available env variables:
# Required. ID of your DataUnlocker domain. This is a private information which must not be shared publicly.
DATAUNLOCKER_ID=000000000000000000000000
# Optional. When set, downloads DataUnlocker's legacy (v1) script which doesn't support Defender. Defaults to unset.
LEGACY_SCRIPT=1
.npmrc
Set the DATAUNLOCKER_ID
environment variable before running npm install
to define what domain should
it download the script for. For instance with npm, you can set it globally in the .npmrc
file.
# ...other contents of .npmrc file here...
DATAUNLOCKER_ID=000000000000000000000000
The script itself will be downloaded when you install the package.
npm install @dataunlocker/script
Manually set the env variable before npm install
Alternatively, set the variable in any way preferred but before running NPM install. For instance,
DATAUNLOCKER_ID=000000000000000000000000 npm install
Mind to change DATAUNLOCKER_ID
respectively to the environment you're installing DataUnlocker script for,
as it is domain-dependent.
Install for a single domain
If your web app has only one environment, you can also install this package for a single DataUnlocker ID by using an alias name:
npm install @dataunlocker/script~000000000000000000000000@npm:@dataunlocker/script
Incremental builds
Some app platforms (like Vercel) perform incremental builds, where each new deployment skips the module installation step if the module is installed. This makes it skip downloading the latest version of DataUnlocker's script as well.
To make your build re-fetch the new script on every new build, add the following to the postinstall
script to your
package.json
:
{
"scripts": {
"postinstall": "dataunlocker-script fetch"
}
}
Mind to also provide the DATAUNLOCKER_ID
env variable, if needed.
Usage
After installing the package, import the plain javascript into your web application page template with:
import { plainSyncScript } from '@dataunlocker/script'; // If your bundler supports tree-shaking
import script from '@dataunlocker/script/lib/plain.module.js'; // Import a specific module
// Inject {plainSyncScript} into your HTML template (all HTML pages) as a sync inline script.
// The injection method depends on the technology stack you're using.
The plain JavaScript as a file (if needed) is available at node_modules/@dataunlocker/script/lib/plain.js
.
Follow alternative guides for your front end stack if installing this package via the package manager doesn't work for you. Also try browsing issues here or add new for your stack.