Script loading module for VGS Collect.js
Explore the docs »
Report Bug
·
Request Feature
VGS Collect.js is a JavaScript library that allows you to securely collect data via any form. Instantly create custom forms that adhere to PCI, HIPAA, GDPR, or CCPA security requirements. VGS intercepts sensitive data before it hits your servers and replaces it with aliased versions while securing the original data in our vault. The form fields behave like traditional forms while preventing access to the unsecured data by injecting secure iframe components.
This module intended to simplify VGS Collect.js script loading process. To stay PCI Compliant it's a mandatory to load js from our js.verygoodvault.com domain as a consequence you need to find the best way to include our script, this small utility will solve the problem for you. You can still use the conventional way and just stick a reference to the script in the HEAD section of your page but you may lose some beneficial advantages the package provides:
- Error handling
- Fallback CDN managing
- Reduced latency of cross-origin requests
Install the package using npm:
npm install @vgs/collect-js
The imported function inserts the <script> tag to the document head or body and returns the Collect instance as the result of resolved Promise. The script won't be loaded until loadVGSCollect() invoked. In order to speed up cross-domain loading, dns-prefetch and preconnect were added as a side effect.
import { loadVGSCollect } from '@vgs/collect-js';
// load script
const collect = await loadVGSCollect({
vaultId: '<vault_id>', // required
environment: '<environment>',
version: '<x.x.x>'
}).catch((e) => {
// script was not loaded
});
// https://www.verygoodsecurity.com/docs/vgs-collect/js/integration#form-state
const form = collect.init(state => { console.log(state); });
// https://www.verygoodsecurity.com/docs/vgs-collect/js/integration#create-and-setup-form-fields
form.field({...});
form.field({...});
form.field({...});
// https://www.verygoodsecurity.com/docs/vgs-collect/js/integration#setup-form-submission
form.submit(...);or use Promise syntax as an alternative:
import { loadVGSCollect } from '@vgs/collect-js';
// load script
loadVGSCollect({
vaultId: '<vault_id>', // required
environment: '<environment>',
version: '<x.x.x>'
})
.then((collect) => {
const form = collect.create(state => { console.log(state); });
})
.catch((e) => {
// script was not loaded
});Available properties:
| Property | Type | Description | Default |
|---|---|---|---|
| vaultId | string | Every VGS vault has a unique vault id - it’s a string value beginning with the prefix tnt. |
required |
| environment | string | Vault environment. Can be sandbox, live, or one with a specified data region (e.g live-eu-1). |
'sandbox' |
| version | string | You can specify library version being loaded. Version must be >= 2.0. Please check our Changelog for more details. | 'canary' |
| integrity | string | Allows a browser to check the fetched script to ensure that the code is never loaded if the source has been manipulated. | not set |
| crossorigin | string | Defining how the element handles cross-origin requests. | not set |
| logLevel | string | Proxies the Collect.js log level configuration. Set to 'none' to disable Collect.js logs and suppress loader analytics trackEvent calls. |
not set |
A wrapper over original .create() method. As we have already received vault_id and environment from the loadVGSCollect() argument, there is no need to specify those params again. The method only returns the form state in the callback.You can still use .create() if necessary.
VGSCollect.init(state => { console.log(state); });Full abilities of VGS Collect.js and integration details you can find in our documentation.
We strongly recommend to add the CSP to your application. Content Security Policy (CSP) is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross Site Scripting (XSS) and data injection attacks. Please create CSP directives for the following domains:
connect-src https://js.verygoodvault.com https://js3.verygoodvault.com https://vgs-collect-keeper.apps.verygood.systems
frame-src https://js.verygoodvault.com https://js3.verygoodvault.com
script-src https://js.verygoodvault.com https://js3.verygoodvault.com
This repository ships a public AI skill at skills/vgs-collect-js-guide/SKILL.md for AI agents integrating VGS Collect through vanilla JavaScript, @vgs/collect-js, or a direct Collect.js CDN script.
Recommended: install the skill with skills.sh. This is the easiest way to give a compatible AI agent the repository-specific guidance it needs for non-React VGS Collect JavaScript integrations.
The installed skill bundle includes loader-specific and direct CDN references and examples. React wrapper guidance for @vgs/collect-js-react is packaged separately from this repository skill.
What the skill is useful for:
- integrating VGS Collect through
loadVGSCollectfrom@vgs/collect-js - loading the Collect core SDK from the public CDN when a direct script tag is the right integration path
- creating secure fields with
VGSCollect.create(...)orcollect.init(...) - submitting, tokenizing, creating aliases, and configuring common VGS Collect form behavior
- choosing public Collect core SDK versions without claiming an unverified latest version
- preserving the secure iframe collection model and avoiding examples that place PAN, CVC, SSN, passwords, OAuth tokens, client secrets, production route IDs, or production CNAME details in browser code
Install the skill with skills.sh:
npx skills add https://github.com/verygoodsecurity/vgs-collect-js --skill vgs-collect-js-guideIf you have any questions please reach out to support or open issue here.