@qr-platform/qr-code.js 0.8.17
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/.github/workflows/publish.yml +18 -0
- package/CHANGELOG.md +233 -0
- package/LICENSE.md +77 -0
- package/README.md +188 -0
- package/docs/advanced-examples.md +523 -0
- package/docs/api-reference-guide.md +254 -0
- package/docs/documentation.md +1592 -0
- package/docs/examples.md +322 -0
- package/docs/license-management.md +501 -0
- package/docs/typescript-types-definitions.md +372 -0
- package/docs/usage-guide.md +622 -0
- package/lib/core/qr-code-js.d.ts +48 -0
- package/lib/core/qr-constant.d.ts +9 -0
- package/lib/core/qr-options-validation.d.ts +13 -0
- package/lib/core/qr-svg.d.ts +76 -0
- package/lib/core/qr-templates.d.ts +6 -0
- package/lib/figures/corner-dot.d.ts +24 -0
- package/lib/figures/corner-square.d.ts +24 -0
- package/lib/figures/dot.d.ts +31 -0
- package/lib/index.d.ts +52 -0
- package/lib/lib/image/GIFImage.d.ts +19 -0
- package/lib/lib/io/Base64.d.ts +10 -0
- package/lib/lib/io/Base64DecodeInputStream.d.ts +15 -0
- package/lib/lib/io/Base64EncodeOutputStream.d.ts +17 -0
- package/lib/lib/io/ByteArrayInputStream.d.ts +12 -0
- package/lib/lib/io/ByteArrayOutputStream.d.ts +12 -0
- package/lib/lib/io/InputStream.d.ts +10 -0
- package/lib/lib/io/OutputStream.d.ts +12 -0
- package/lib/lib/qr-code.d.ts +5 -0
- package/lib/lib/qrcode/BitBuffer.d.ts +11 -0
- package/lib/lib/qrcode/ErrorCorrectLevel.d.ts +23 -0
- package/lib/lib/qrcode/MaskPattern.d.ts +39 -0
- package/lib/lib/qrcode/Mode.d.ts +23 -0
- package/lib/lib/qrcode/Polynomial.d.ts +15 -0
- package/lib/lib/qrcode/QR8BitByte.d.ts +13 -0
- package/lib/lib/qrcode/QRAlphaNum.d.ts +13 -0
- package/lib/lib/qrcode/QRCode.d.ts +22 -0
- package/lib/lib/qrcode/QRCodeMinimal.d.ts +58 -0
- package/lib/lib/qrcode/QRData.d.ts +17 -0
- package/lib/lib/qrcode/QRKanji.d.ts +13 -0
- package/lib/lib/qrcode/QRMath.d.ts +13 -0
- package/lib/lib/qrcode/QRNumber.d.ts +14 -0
- package/lib/lib/qrcode/QRUtil.d.ts +25 -0
- package/lib/lib/qrcode/RSBlock.d.ts +16 -0
- package/lib/lib/text/createStringToBytes.d.ts +9 -0
- package/lib/lib/text/stringToBytes_SJIS.d.ts +8 -0
- package/lib/lib/text/stringToBytes_UTF8.d.ts +7 -0
- package/lib/lib/zbar-wasm/index.d.ts +1 -0
- package/lib/lib/zxing-js/src/browser/BrowserCodeReader.d.ts +410 -0
- package/lib/lib/zxing-js/src/browser/BrowserQRCodeReader.d.ts +29 -0
- package/lib/lib/zxing-js/src/browser/BrowserQRCodeSvgWriter.d.ts +46 -0
- package/lib/lib/zxing-js/src/browser/BrowserSvgCodeWriter.d.ts +49 -0
- package/lib/lib/zxing-js/src/browser/DecodeContinuouslyCallback.d.ts +6 -0
- package/lib/lib/zxing-js/src/browser/HTMLCanvasElementLuminanceSource.d.ts +27 -0
- package/lib/lib/zxing-js/src/browser/HTMLVisualMediaElement.d.ts +4 -0
- package/lib/lib/zxing-js/src/browser/VideoInputDevice.d.ts +22 -0
- package/lib/lib/zxing-js/src/browser.d.ts +3 -0
- package/lib/lib/zxing-js/src/core/ArgumentException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/ArithmeticException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/ArrayIndexOutOfBoundsException.d.ts +10 -0
- package/lib/lib/zxing-js/src/core/BarcodeFormat.d.ts +42 -0
- package/lib/lib/zxing-js/src/core/Binarizer.d.ts +53 -0
- package/lib/lib/zxing-js/src/core/BinaryBitmap.d.ts +78 -0
- package/lib/lib/zxing-js/src/core/ChecksumException.d.ts +8 -0
- package/lib/lib/zxing-js/src/core/DecodeHintType.d.ts +91 -0
- package/lib/lib/zxing-js/src/core/Dimension.d.ts +13 -0
- package/lib/lib/zxing-js/src/core/EncodeHintType.d.ts +99 -0
- package/lib/lib/zxing-js/src/core/Exception.d.ts +17 -0
- package/lib/lib/zxing-js/src/core/FormatException.d.ts +8 -0
- package/lib/lib/zxing-js/src/core/HighContrastLuminanceSource.d.ts +27 -0
- package/lib/lib/zxing-js/src/core/IllegalArgumentException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/IllegalStateException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/IndexOutOfBoundsException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/InvertedLuminanceSource.d.ts +22 -0
- package/lib/lib/zxing-js/src/core/LuminanceSource.d.ts +84 -0
- package/lib/lib/zxing-js/src/core/NodeLuminanceSource.d.ts +36 -0
- package/lib/lib/zxing-js/src/core/NotFoundException.d.ts +8 -0
- package/lib/lib/zxing-js/src/core/NullPointerException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/OutOfMemoryError.d.ts +6 -0
- package/lib/lib/zxing-js/src/core/PlanarYUVLuminanceSource.d.ts +35 -0
- package/lib/lib/zxing-js/src/core/RGBLuminanceSource.d.ts +21 -0
- package/lib/lib/zxing-js/src/core/Reader.d.ts +49 -0
- package/lib/lib/zxing-js/src/core/ReaderException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/ReedSolomonException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/Result.d.ts +52 -0
- package/lib/lib/zxing-js/src/core/ResultMetadataType.d.ts +68 -0
- package/lib/lib/zxing-js/src/core/ResultPoint.d.ts +34 -0
- package/lib/lib/zxing-js/src/core/ResultPointCallback.d.ts +11 -0
- package/lib/lib/zxing-js/src/core/UniversalLuminanceSource.d.ts +46 -0
- package/lib/lib/zxing-js/src/core/UnsupportedOperationException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/Writer.d.ts +30 -0
- package/lib/lib/zxing-js/src/core/WriterException.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/common/BitArray.d.ts +111 -0
- package/lib/lib/zxing-js/src/core/common/BitMatrix.d.ts +98 -0
- package/lib/lib/zxing-js/src/core/common/BitSource.d.ts +38 -0
- package/lib/lib/zxing-js/src/core/common/CharacterSetECI.d.ts +89 -0
- package/lib/lib/zxing-js/src/core/common/DecoderResult.d.ts +64 -0
- package/lib/lib/zxing-js/src/core/common/DefaultGridSampler.d.ts +10 -0
- package/lib/lib/zxing-js/src/core/common/DetectorResult.d.ts +16 -0
- package/lib/lib/zxing-js/src/core/common/ECIEncoderSet.d.ts +37 -0
- package/lib/lib/zxing-js/src/core/common/ECIInput.d.ts +79 -0
- package/lib/lib/zxing-js/src/core/common/GlobalHistogramBinarizer.d.ts +29 -0
- package/lib/lib/zxing-js/src/core/common/GridSampler.d.ts +36 -0
- package/lib/lib/zxing-js/src/core/common/GridSamplerInstance.d.ts +18 -0
- package/lib/lib/zxing-js/src/core/common/HybridBinarizer.d.ts +54 -0
- package/lib/lib/zxing-js/src/core/common/MinimalECIInput.d.ts +123 -0
- package/lib/lib/zxing-js/src/core/common/PerspectiveTransform.d.ts +26 -0
- package/lib/lib/zxing-js/src/core/common/StringUtils.d.ts +48 -0
- package/lib/lib/zxing-js/src/core/common/detector/CornerDetector.d.ts +35 -0
- package/lib/lib/zxing-js/src/core/common/detector/MathUtils.d.ts +36 -0
- package/lib/lib/zxing-js/src/core/common/detector/WhiteRectangleDetector.d.ts +71 -0
- package/lib/lib/zxing-js/src/core/common/reedsolomon/AbstractGenericGF.d.ts +34 -0
- package/lib/lib/zxing-js/src/core/common/reedsolomon/AbstractGenericGFPoly.d.ts +36 -0
- package/lib/lib/zxing-js/src/core/common/reedsolomon/GenericGF.d.ts +58 -0
- package/lib/lib/zxing-js/src/core/common/reedsolomon/GenericGFPoly.d.ts +47 -0
- package/lib/lib/zxing-js/src/core/common/reedsolomon/ReedSolomonDecoder.d.ts +40 -0
- package/lib/lib/zxing-js/src/core/common/reedsolomon/ReedSolomonEncoder.d.ts +41 -0
- package/lib/lib/zxing-js/src/core/qrcode/QRCodeReader.d.ts +35 -0
- package/lib/lib/zxing-js/src/core/qrcode/QRCodeWriter.d.ts +13 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/BitMatrixParser.d.ts +58 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/DataBlock.d.ts +28 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/DataMask.d.ts +36 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/DecodedBitStreamParser.d.ts +30 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/Decoder.d.ts +44 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/ECB.d.ts +12 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/ECBlocks.d.ts +16 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/ErrorCorrectionLevel.d.ts +38 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/FormatInformation.d.ts +33 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/Mode.d.ts +56 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/QRCodeDecoderMetaData.d.ts +21 -0
- package/lib/lib/zxing-js/src/core/qrcode/decoder/Version.d.ts +44 -0
- package/lib/lib/zxing-js/src/core/qrcode/detector/AlignmentPattern.d.ts +21 -0
- package/lib/lib/zxing-js/src/core/qrcode/detector/AlignmentPatternFinder.d.ts +82 -0
- package/lib/lib/zxing-js/src/core/qrcode/detector/Detector.d.ts +87 -0
- package/lib/lib/zxing-js/src/core/qrcode/detector/FinderPattern.d.ts +26 -0
- package/lib/lib/zxing-js/src/core/qrcode/detector/FinderPatternFinder.d.ts +114 -0
- package/lib/lib/zxing-js/src/core/qrcode/detector/FinderPatternInfo.d.ts +16 -0
- package/lib/lib/zxing-js/src/core/qrcode/encoder/BlockPair.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/qrcode/encoder/ByteMatrix.d.ts +24 -0
- package/lib/lib/zxing-js/src/core/qrcode/encoder/Encoder.d.ts +85 -0
- package/lib/lib/zxing-js/src/core/qrcode/encoder/MaskUtil.d.ts +47 -0
- package/lib/lib/zxing-js/src/core/qrcode/encoder/MatrixUtil.d.ts +37 -0
- package/lib/lib/zxing-js/src/core/qrcode/encoder/QRCode.d.ts +29 -0
- package/lib/lib/zxing-js/src/core/util/Arrays.d.ts +45 -0
- package/lib/lib/zxing-js/src/core/util/ByteArrayOutputStream.d.ts +174 -0
- package/lib/lib/zxing-js/src/core/util/Charset.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/util/Collections.d.ts +11 -0
- package/lib/lib/zxing-js/src/core/util/Float.d.ts +14 -0
- package/lib/lib/zxing-js/src/core/util/Formatter.d.ts +28 -0
- package/lib/lib/zxing-js/src/core/util/Integer.d.ts +19 -0
- package/lib/lib/zxing-js/src/core/util/Long.d.ts +12 -0
- package/lib/lib/zxing-js/src/core/util/OutputStream.d.ts +106 -0
- package/lib/lib/zxing-js/src/core/util/StandardCharsets.d.ts +7 -0
- package/lib/lib/zxing-js/src/core/util/StringBuilder.d.ts +21 -0
- package/lib/lib/zxing-js/src/core/util/StringEncoding.d.ts +51 -0
- package/lib/lib/zxing-js/src/core/util/System.d.ts +10 -0
- package/lib/lib/zxing-js/src/customTypings.d.ts +16 -0
- package/lib/lib/zxing-js/src/index.d.ts +5 -0
- package/lib/lib/zxing-js/src/node.d.ts +1 -0
- package/lib/license/LicenseManager.d.ts +69 -0
- package/lib/license/LicenseManagerNode.d.ts +64 -0
- package/lib/node.d.ts +37 -0
- package/lib/options-demo.d.ts +239 -0
- package/lib/plugins/QRBorderHelpers.d.ts +32 -0
- package/lib/plugins/QRBorderPlugin.d.ts +35 -0
- package/lib/plugins/QRValidatorZbar.d.ts +38 -0
- package/lib/plugins/QRValidatorZbarNode.d.ts +60 -0
- package/lib/plugins/QRValidatorZbarNodeSharp.d.ts +83 -0
- package/lib/qr-code-js-node.js +1 -0
- package/lib/qr-code-js.js +1 -0
- package/lib/templates/borders-inner-outter.d.ts +129 -0
- package/lib/templates/borders-inner-scale-offset.d.ts +497 -0
- package/lib/templates/borders-inner.d.ts +129 -0
- package/lib/templates/borders-no-license.d.ts +129 -0
- package/lib/templates/borders-outter.d.ts +129 -0
- package/lib/templates/borders-text-auto-curved.d.ts +129 -0
- package/lib/templates/borders-text-full-curved.d.ts +133 -0
- package/lib/templates/borders.d.ts +129 -0
- package/lib/templates/scales.d.ts +130 -0
- package/lib/templates/scan-validators/index.d.ts +1 -0
- package/lib/templates/scan-validators/tests/cases/basic-inverted.d.ts +9 -0
- package/lib/templates/scan-validators/tests/cases/basic-no-license.d.ts +3 -0
- package/lib/templates/scan-validators/tests/cases/basic.d.ts +3 -0
- package/lib/templates/scan-validators/tests/cases/colors-inverted.d.ts +2 -0
- package/lib/templates/scan-validators/tests/cases/colors.d.ts +58 -0
- package/lib/templates/scan-validators/tests/cases/out-of-borders-inverted.d.ts +9 -0
- package/lib/templates/scan-validators/tests/cases/out-of-borders.d.ts +9 -0
- package/lib/templates/scan-validators/tests/cases/position-inverted.d.ts +9 -0
- package/lib/templates/scan-validators/tests/cases/position.d.ts +3 -0
- package/lib/templates/scan-validators/tests/index.d.ts +27 -0
- package/lib/tools/browser-image-tools.d.ts +7 -0
- package/lib/tools/browser-utils.d.ts +18 -0
- package/lib/types/helper.d.ts +23 -0
- package/lib/utils/canvas-options.d.ts +7 -0
- package/lib/utils/color.d.ts +4 -0
- package/lib/utils/gradient.d.ts +26 -0
- package/lib/utils/image.d.ts +16 -0
- package/lib/utils/merge.d.ts +5 -0
- package/lib/utils/options.d.ts +220 -0
- package/lib/utils/qrcode.d.ts +8 -0
- package/lib/utils/scan-validator-node.d.ts +15 -0
- package/lib/utils/scan-validators/abstract-scan-validator.d.ts +43 -0
- package/lib/utils/scan-validators/zbar-scan-validator.d.ts +8 -0
- package/lib/utils/scan-validators/zxing-canvas-scan-validator.d.ts +10 -0
- package/lib/utils/scan-validators/zxing-scan-validator.d.ts +8 -0
- package/lib/utils/svg.d.ts +2 -0
- package/lib/utils/token-validator.d.ts +19 -0
- package/package.json +80 -0
@@ -0,0 +1,501 @@
|
|
1
|
+
# QRCode.js License Management
|
2
|
+
<a id="start"></a>
|
3
|
+
|
4
|
+
## Introduction
|
5
|
+
<a id="introduction"></a>
|
6
|
+
|
7
|
+
QRCode.js uses a license key system to enable premium features. Activation involves validating a JSON Web Token (JWT) which contains details about your license grant. This validation happens client-side (in the browser) or server-side (in Node.js) against a public key embedded in the library.
|
8
|
+
|
9
|
+
### Premium Features
|
10
|
+
|
11
|
+
A valid license is required to use the following premium features:
|
12
|
+
|
13
|
+
- **Advanced Borders:**
|
14
|
+
- Inner borders, outer borders, and text integrated into borders (e.g., `borderOptions.inner`, `borderOptions.outer`, `borderOptions.text`)
|
15
|
+
- Custom border text without "QR-Platform" branding
|
16
|
+
- Ability to disable or customize specific border sides
|
17
|
+
- **Scan Validation:** Using the built-in scan validation features (`qrInstance.validateScanning()`)
|
18
|
+
|
19
|
+
### Free Usage
|
20
|
+
|
21
|
+
QRCode.js can be used for free without a license key or premium features. In its free mode, it allows you to create full-featured, styled QR codes without premium border features or built-in scan validation. No other restrictions are applied, meaning you can still customize colors, sizes, shapes, and other styling options available in the base library.
|
22
|
+
|
23
|
+
### Border Limitations in Free Version
|
24
|
+
|
25
|
+
When using the basic border features in the free version, the library will automatically add "QR-Platform" branding text in the bottom border. This branded text cannot be removed or modified without a valid license. With a premium license, you gain full control over border text and can use borders without any branding.
|
26
|
+
|
27
|
+
## Core Concepts
|
28
|
+
|
29
|
+
### Free vs. Premium Features
|
30
|
+
|
31
|
+
- **Free Features**: Basic QR code generation, styling options (colors, shapes, dot types), image embedding
|
32
|
+
- **Premium Features**:
|
33
|
+
- Advanced border customization (without branding)
|
34
|
+
- Scan validation tools
|
35
|
+
- Full control over border text
|
36
|
+
|
37
|
+
### Activation Timing
|
38
|
+
|
39
|
+
- **Purpose**: Determines when license activation should occur
|
40
|
+
- **Important**: License activation must be completed *before* you create any `QRCodeJs` instances
|
41
|
+
- **Reason**: The constructor checks the license status at the time of creation
|
42
|
+
- **Rule**: Activate first, then instantiate
|
43
|
+
|
44
|
+
### Initialization
|
45
|
+
|
46
|
+
- **Purpose**: Sets up the license manager
|
47
|
+
- **Behavior**: Initializes automatically when you first attempt activation or check the status
|
48
|
+
- **Manual Method**: `QRCodeJs.initializeIfNeeded()`
|
49
|
+
- **Example**:
|
50
|
+
```typescript
|
51
|
+
async function initializeOnLoad() {
|
52
|
+
const isActive = await QRCodeJs.initializeIfNeeded();
|
53
|
+
console.log('License active after init:', isActive);
|
54
|
+
}
|
55
|
+
```
|
56
|
+
|
57
|
+
### Persistence
|
58
|
+
|
59
|
+
#### Browser Environment
|
60
|
+
- **Storage**: `localStorage` under the key `QRCodeJsLicense`
|
61
|
+
- **Persistence**: License persists across page loads and sessions until token expiration
|
62
|
+
- **Content Stored**: Both JWT and license key (if used for activation)
|
63
|
+
|
64
|
+
#### Node.js Environment
|
65
|
+
- **Storage**: In-memory only (no persistent storage)
|
66
|
+
- **Persistence**: Requires reactivation when the application restarts
|
67
|
+
- **Alternative**: Manage token storage externally
|
68
|
+
|
69
|
+
#### Token Retrieval and Reuse
|
70
|
+
- **Purpose**: Obtain token for external storage
|
71
|
+
- **Method**: `QRCodeJs.license('YOUR-API-KEY')`
|
72
|
+
- **Return**: Promise resolving to `ValidationResult` with token string
|
73
|
+
- **Example**:
|
74
|
+
```typescript
|
75
|
+
// Get and store the token
|
76
|
+
const result = await QRCodeJs.license('YOUR-API-KEY');
|
77
|
+
if (result.isValid) {
|
78
|
+
await storeTokenInDatabase(result.token);
|
79
|
+
}
|
80
|
+
|
81
|
+
// Later, when you need to use the token
|
82
|
+
const storedToken = await retrieveTokenFromDatabase();
|
83
|
+
await QRCodeJs.token(storedToken); // Reactivate with stored token
|
84
|
+
```
|
85
|
+
|
86
|
+
## Activation Methods
|
87
|
+
|
88
|
+
### Using a License Key (`QRCodeJs.license()`)
|
89
|
+
|
90
|
+
- **Purpose**: Activate license using a license key
|
91
|
+
- **Type**: `function(licenseKey: string): Promise<ValidationResult>`
|
92
|
+
- **Process**:
|
93
|
+
1. Calls `QRCodeJs.license('YOUR-LICENSE-KEY')`
|
94
|
+
2. Library sends key to backend endpoint (default: `POST /api/get-token`)
|
95
|
+
3. Backend validates key and returns signed JWT
|
96
|
+
4. Library validates JWT signature and expiration date
|
97
|
+
5. If valid, token and key are stored
|
98
|
+
- **Return Value**: Promise resolving to `ValidationResult` object
|
99
|
+
- **Example** (async/await):
|
100
|
+
```typescript
|
101
|
+
await QRCodeJs.license('YOUR-LICENSE-KEY');
|
102
|
+
const qrInstance = new QRCodeJs({
|
103
|
+
data: 'https://example.com',
|
104
|
+
borderOptions: { inner: true }
|
105
|
+
});
|
106
|
+
```
|
107
|
+
- **Example** (promise chaining):
|
108
|
+
```typescript
|
109
|
+
QRCodeJs.license('YOUR-LICENSE-KEY')
|
110
|
+
.then(result => {
|
111
|
+
if (result.isValid) {
|
112
|
+
console.log('License activated!');
|
113
|
+
const qrInstance = new QRCodeJs({
|
114
|
+
data: 'https://example.com',
|
115
|
+
borderOptions: { outer: true }
|
116
|
+
});
|
117
|
+
document.getElementById('qr-container').appendChild(qrInstance.element);
|
118
|
+
} else {
|
119
|
+
console.error('License activation failed.');
|
120
|
+
}
|
121
|
+
})
|
122
|
+
.catch(error => {
|
123
|
+
console.error('Error during license activation:', error);
|
124
|
+
});
|
125
|
+
```
|
126
|
+
|
127
|
+
### Using a Pre-fetched Token (`QRCodeJs.token()`)
|
128
|
+
|
129
|
+
- **Purpose**: Activate license using a pre-fetched JWT token
|
130
|
+
- **Type**: `function(jwtToken: string | null): Promise<ValidationResult>`
|
131
|
+
- **Process**:
|
132
|
+
1. Calls `QRCodeJs.token('YOUR-JWT-STRING')`
|
133
|
+
2. Library validates JWT signature and expiration date
|
134
|
+
3. If valid, token is stored
|
135
|
+
- **Clearing License**: `QRCodeJs.token(null)` clears stored token and deactivates license
|
136
|
+
- **Example** (async/await):
|
137
|
+
```typescript
|
138
|
+
await QRCodeJs.token(token);
|
139
|
+
const qrInstance = new QRCodeJs({
|
140
|
+
data: 'https://example.com',
|
141
|
+
borderOptions: { outer: true }
|
142
|
+
});
|
143
|
+
```
|
144
|
+
- **Example** (promise chaining):
|
145
|
+
```typescript
|
146
|
+
const token = 'YOUR-JWT-STRING';
|
147
|
+
if (token) {
|
148
|
+
QRCodeJs.token(token)
|
149
|
+
.then(result => {
|
150
|
+
if (result.isValid) {
|
151
|
+
console.log('License activated with token!', result.license.plan);
|
152
|
+
const qrInstance = new QRCodeJs({
|
153
|
+
data: 'https://example.com',
|
154
|
+
borderOptions: { inner: true }
|
155
|
+
});
|
156
|
+
} else {
|
157
|
+
console.error('Provided token is invalid or expired.');
|
158
|
+
}
|
159
|
+
})
|
160
|
+
.catch(error => {
|
161
|
+
console.error('Error:', error);
|
162
|
+
});
|
163
|
+
}
|
164
|
+
```
|
165
|
+
|
166
|
+
## Domain Validation (Browser Only)
|
167
|
+
|
168
|
+
- **Purpose**: Ensures license is used on authorized domains
|
169
|
+
- **Scope**: Browser environments only (not applicable to Node.js)
|
170
|
+
- **`localhost` Exception**: Always permitted regardless of domains list
|
171
|
+
- **Validation Process**:
|
172
|
+
- Token contains `domains` array (e.g., `["example.com", "example.org"]`)
|
173
|
+
- Current browser hostname must match one of the entries
|
174
|
+
- If no match (and not localhost), activation fails with `reason: 'DOMAIN_MISMATCH'`
|
175
|
+
- **Example**:
|
176
|
+
```typescript
|
177
|
+
// Token with domain restriction
|
178
|
+
{
|
179
|
+
"domains": ["example.com", "myapp.org"],
|
180
|
+
// ... other token properties
|
181
|
+
}
|
182
|
+
|
183
|
+
// On wrong domain
|
184
|
+
const result = await QRCodeJs.token(restrictedToken);
|
185
|
+
console.log(result.isValid); // false
|
186
|
+
console.log(result.reason); // 'DOMAIN_MISMATCH'
|
187
|
+
```
|
188
|
+
|
189
|
+
## Configuration
|
190
|
+
|
191
|
+
### Setting License URL
|
192
|
+
|
193
|
+
- **Purpose**: Configure the endpoint for license key validation
|
194
|
+
- **Type**: `function(url: string): typeof QRCodeJs`
|
195
|
+
- **Default**: `/api/get-token`
|
196
|
+
- **Important**: Must be called before `QRCodeJs.license()`
|
197
|
+
- **Returns**: `QRCodeJs` class for chaining
|
198
|
+
- **Example**:
|
199
|
+
```typescript
|
200
|
+
QRCodeJs.setLicenseUrl('https://my-api.com/licenses/get-token');
|
201
|
+
await QRCodeJs.license('YOUR-LICENSE-KEY');
|
202
|
+
```
|
203
|
+
- **Example** (chaining):
|
204
|
+
```typescript
|
205
|
+
await QRCodeJs.setLicenseUrl('/my-api/get-license').license('YOUR-LICENSE-KEY');
|
206
|
+
```
|
207
|
+
|
208
|
+
### Custom License Fetcher
|
209
|
+
|
210
|
+
- **Purpose**: Implement custom token fetching logic
|
211
|
+
- **Type**: `function(fetcherFn: (licenseKey: string) => Promise<string>): void`
|
212
|
+
- **Use Cases**: Custom headers, authentication, or request format
|
213
|
+
- **Example**:
|
214
|
+
```typescript
|
215
|
+
QRCodeJs.configureLicenseFetcher(async (key) => {
|
216
|
+
const response = await fetch('/my/custom/endpoint', {
|
217
|
+
method: 'POST',
|
218
|
+
headers: { 'Authorization': 'Bearer ' + getAuthToken() },
|
219
|
+
body: JSON.stringify({ licKey: key })
|
220
|
+
});
|
221
|
+
if (!response.ok) throw new Error('Fetch failed');
|
222
|
+
const data = await response.json();
|
223
|
+
return data.token;
|
224
|
+
});
|
225
|
+
```
|
226
|
+
|
227
|
+
## Checking License Status
|
228
|
+
|
229
|
+
### Getting License Details
|
230
|
+
|
231
|
+
- **Purpose**: Retrieve current license information
|
232
|
+
- **Type**: `function(): DecodedLicenseToken | null`
|
233
|
+
- **Returns**: Decoded token object if license is active, otherwise `null`
|
234
|
+
- **Example**:
|
235
|
+
```typescript
|
236
|
+
const licenseDetails = QRCodeJs.getLicenseDetails();
|
237
|
+
if (licenseDetails) {
|
238
|
+
console.log('License active. Plan:', licenseDetails.plan);
|
239
|
+
console.log('Domains:', licenseDetails.domains);
|
240
|
+
console.log('Expires:', new Date(licenseDetails.exp * 1000));
|
241
|
+
} else {
|
242
|
+
console.log('License not active or expired.');
|
243
|
+
}
|
244
|
+
```
|
245
|
+
|
246
|
+
### Initializing License Manager
|
247
|
+
|
248
|
+
- **Purpose**: Ensure license manager loads from storage if available
|
249
|
+
- **Type**: `function(): Promise<boolean>`
|
250
|
+
- **Returns**: Promise resolving to boolean indicating license active status
|
251
|
+
- **Example**:
|
252
|
+
```typescript
|
253
|
+
async function checkStoredLicenseOnLoad() {
|
254
|
+
const isActive = await QRCodeJs.initializeIfNeeded();
|
255
|
+
console.log('License active after init:', isActive);
|
256
|
+
const details = QRCodeJs.getLicenseDetails();
|
257
|
+
if (details) console.log('Plan:', details.plan);
|
258
|
+
}
|
259
|
+
```
|
260
|
+
|
261
|
+
## Error Handling
|
262
|
+
|
263
|
+
- **Network Errors**: Result in a rejected Promise
|
264
|
+
- **Validation Errors**: Resolve with `ValidationResult` where `isValid: false`
|
265
|
+
- **Example**:
|
266
|
+
```typescript
|
267
|
+
try {
|
268
|
+
const result = await QRCodeJs.license('INVALID-KEY');
|
269
|
+
if (!result.isValid) {
|
270
|
+
console.error('Activation failed. Reason:', result.reason);
|
271
|
+
}
|
272
|
+
} catch (error) {
|
273
|
+
console.error('Network error:', error);
|
274
|
+
}
|
275
|
+
```
|
276
|
+
|
277
|
+
## Node.js Usage
|
278
|
+
|
279
|
+
### Key Differences from Browser
|
280
|
+
|
281
|
+
- **Import**: Use the Node.js entry point
|
282
|
+
```typescript
|
283
|
+
import { QRCodeJs } from '@qr-platform/qr-code.js/node';
|
284
|
+
```
|
285
|
+
- **No Persistence**: License state exists in memory only
|
286
|
+
- **URL Requirement**: Absolute URL must be set via `setLicenseUrl()`
|
287
|
+
|
288
|
+
### Node.js Examples
|
289
|
+
|
290
|
+
#### Using `license()` with `async/await`
|
291
|
+
|
292
|
+
```typescript
|
293
|
+
async function activateLicenseNode() {
|
294
|
+
try {
|
295
|
+
QRCodeJs.setLicenseUrl('https://your-license-api.com/get-token');
|
296
|
+
const result = await QRCodeJs.license('YOUR-NODE-LICENSE-KEY');
|
297
|
+
if (result.isValid) {
|
298
|
+
console.log('Node: License activated!', result.license.plan);
|
299
|
+
const qrInstance = new QRCodeJs({
|
300
|
+
data: 'https://example.com',
|
301
|
+
borderOptions: { inner: true }
|
302
|
+
});
|
303
|
+
} else {
|
304
|
+
console.error('Node: License activation failed.');
|
305
|
+
}
|
306
|
+
} catch (error) {
|
307
|
+
console.error('Node: Error:', error);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
```
|
311
|
+
|
312
|
+
#### Using `token()` with `async/await`
|
313
|
+
|
314
|
+
```typescript
|
315
|
+
async function activateWithTokenNode(token) {
|
316
|
+
try {
|
317
|
+
const result = await QRCodeJs.token(token);
|
318
|
+
if (result.isValid) {
|
319
|
+
console.log('Node: License activated!', result.license.plan);
|
320
|
+
const qrInstance = new QRCodeJs({
|
321
|
+
data: 'https://example.com',
|
322
|
+
borderOptions: { outer: true }
|
323
|
+
});
|
324
|
+
} else {
|
325
|
+
console.error('Node: Token invalid or expired.');
|
326
|
+
}
|
327
|
+
} catch (error) {
|
328
|
+
console.error('Node: Error:', error);
|
329
|
+
}
|
330
|
+
}
|
331
|
+
```
|
332
|
+
|
333
|
+
## Backend Implementation Guide
|
334
|
+
|
335
|
+
### Endpoint
|
336
|
+
|
337
|
+
- **Default Path**: `/api/get-token`
|
338
|
+
- **Method**: `POST`
|
339
|
+
- **Content-Type**: `application/json`
|
340
|
+
|
341
|
+
### Request Format
|
342
|
+
|
343
|
+
```json
|
344
|
+
{
|
345
|
+
"licenseKey": "THE_USER_PROVIDED_KEY"
|
346
|
+
}
|
347
|
+
```
|
348
|
+
|
349
|
+
### Processing Steps
|
350
|
+
|
351
|
+
1. Extract and validate `licenseKey`
|
352
|
+
2. Generate a JWT with this payload:
|
353
|
+
```json
|
354
|
+
{
|
355
|
+
"sub": "license-12345",
|
356
|
+
"client": "acme-corp",
|
357
|
+
"plan": "enterprise",
|
358
|
+
"email": "admin@acme.com",
|
359
|
+
"domains": ["acme.com", "acme.org"],
|
360
|
+
"iat": 1712668800,
|
361
|
+
"exp": 1744204800
|
362
|
+
}
|
363
|
+
```
|
364
|
+
3. Sign with your private key
|
365
|
+
|
366
|
+
### Response Format
|
367
|
+
|
368
|
+
- **Success**: Plain text JWT (`Content-Type: text/plain`)
|
369
|
+
- **Failure**: Error status (e.g., 400) with optional JSON:
|
370
|
+
```json
|
371
|
+
{ "error": "Invalid license key" }
|
372
|
+
```
|
373
|
+
|
374
|
+
### Security Best Practices
|
375
|
+
|
376
|
+
- Secure your private key
|
377
|
+
- Use HTTPS for all license endpoints
|
378
|
+
- Implement rate limiting
|
379
|
+
- Validate license keys against your database
|
380
|
+
|
381
|
+
## API Reference
|
382
|
+
|
383
|
+
### Static Methods
|
384
|
+
|
385
|
+
#### `license()`
|
386
|
+
|
387
|
+
- **Purpose**: Activate license using a key
|
388
|
+
- **Type**: `function(licenseKey: string): Promise<ValidationResult>`
|
389
|
+
- **Returns**: Promise resolving to validation result
|
390
|
+
|
391
|
+
#### `token()`
|
392
|
+
|
393
|
+
- **Purpose**: Activate license using pre-fetched JWT
|
394
|
+
- **Type**: `function(jwtToken: string | null): Promise<ValidationResult>`
|
395
|
+
- **Returns**: Promise resolving to validation result
|
396
|
+
|
397
|
+
#### `setLicenseUrl()`
|
398
|
+
|
399
|
+
- **Purpose**: Configure the license endpoint URL
|
400
|
+
- **Type**: `function(url: string): typeof QRCodeJs`
|
401
|
+
- **Returns**: QRCodeJs class for chaining
|
402
|
+
|
403
|
+
#### `configureLicenseFetcher()`
|
404
|
+
|
405
|
+
- **Purpose**: Set custom license fetching function
|
406
|
+
- **Type**: `function(fetcherFn: (licenseKey: string) => Promise<string>): void`
|
407
|
+
|
408
|
+
#### `getLicenseDetails()`
|
409
|
+
|
410
|
+
- **Purpose**: Get current license information
|
411
|
+
- **Type**: `function(): DecodedLicenseToken | null`
|
412
|
+
- **Returns**: Decoded token or null
|
413
|
+
|
414
|
+
#### `initializeIfNeeded()`
|
415
|
+
|
416
|
+
- **Purpose**: Initialize license manager if needed
|
417
|
+
- **Type**: `function(): Promise<boolean>`
|
418
|
+
- **Returns**: Promise resolving to license status
|
419
|
+
|
420
|
+
### Interfaces
|
421
|
+
|
422
|
+
#### `ValidationResult`
|
423
|
+
|
424
|
+
```typescript
|
425
|
+
interface ValidationResult {
|
426
|
+
isValid: boolean;
|
427
|
+
token: string | null;
|
428
|
+
license: DecodedLicenseToken | null;
|
429
|
+
reason?: LicenseReasonCode;
|
430
|
+
}
|
431
|
+
```
|
432
|
+
|
433
|
+
#### `DecodedLicenseToken`
|
434
|
+
|
435
|
+
```typescript
|
436
|
+
interface DecodedLicenseToken {
|
437
|
+
sub: string;
|
438
|
+
client: string;
|
439
|
+
plan: string;
|
440
|
+
email?: string;
|
441
|
+
domains?: string[];
|
442
|
+
iat: number;
|
443
|
+
exp: number;
|
444
|
+
}
|
445
|
+
```
|
446
|
+
|
447
|
+
## Troubleshooting and FAQ
|
448
|
+
|
449
|
+
### Activation Issues
|
450
|
+
|
451
|
+
- **Check network requests**: Examine browser developer tools for API call failures
|
452
|
+
- **Verify JWT validity**: Use [JWT.io](https://jwt.io/) to inspect token structure
|
453
|
+
- **Check storage**: Examine `localStorage` (browser) or memory state (Node.js)
|
454
|
+
- **Check console**: Look for warnings like domain mismatch or expired token
|
455
|
+
- **Licensed Features Not Working**: Ensure activation precedes instantiation. Check `getLicenseDetails()` for `plan` and `exp`.
|
456
|
+
|
457
|
+
### Common Questions
|
458
|
+
|
459
|
+
#### Can I use QRCode.js for free without a license?
|
460
|
+
|
461
|
+
Yes, QRCode.js can be used for free without a license key. This allows you to create full-featured, styled QR codes without premium features like advanced borders or built-in scan validation. There are no other restrictions in free mode.
|
462
|
+
|
463
|
+
#### What happens if I use border features in the free version?
|
464
|
+
|
465
|
+
When using border features without a license, the library will automatically add "QR-Platform" branding text in the bottom border of your QR code. This branding cannot be removed or customized in the free version. A premium license removes this restriction, allowing you to create custom border text or remove text entirely.
|
466
|
+
|
467
|
+
#### Can I modify or remove the QR-Platform branding in the free version?
|
468
|
+
|
469
|
+
No, the QR-Platform branding in the bottom border is automatically added when using border features in the free version and cannot be modified or removed. This is a limitation of the free version. Purchasing a license allows you to remove the branding and fully customize your border text.
|
470
|
+
|
471
|
+
#### Do I need to activate the license on every page load?
|
472
|
+
|
473
|
+
- **Browser**: No, license persists in `localStorage` until expiration
|
474
|
+
- **Node.js**: Yes, unless token is managed externally
|
475
|
+
|
476
|
+
#### What happens if the license expires?
|
477
|
+
|
478
|
+
`getLicenseDetails()` returns `null`; you'll need to renew with `license()` or `token()`.
|
479
|
+
|
480
|
+
#### Can I use this offline?
|
481
|
+
|
482
|
+
`token()` works offline with a valid JWT; `license()` requires internet connection.
|
483
|
+
|
484
|
+
#### How can I check which premium features are enabled?
|
485
|
+
|
486
|
+
Check `getLicenseDetails().plan` to determine which features should be available.
|
487
|
+
|
488
|
+
#### Why are premium features not working?
|
489
|
+
|
490
|
+
Ensure activation was completed before QRCode instances were created. Check for errors in the console or network requests. If using a token, ensure it is valid and not expired. If you are still having issues, please contact us for support.
|
491
|
+
|
492
|
+
---
|
493
|
+
|
494
|
+
### See Also
|
495
|
+
- [QRCode.js Documentation](./documentation.md#start)
|
496
|
+
- [Quick References Guide](./quick-references-guide.md#start)
|
497
|
+
- [API Reference Guide](./api-reference-guide.md#start)
|
498
|
+
- [TypeScript Types and Definitions](./typescript-types-definitions.md#start)
|
499
|
+
- [License Management](./license-management.md#start)
|
500
|
+
- [Basic Examples](./examples.md#start)
|
501
|
+
- [Advanced Examples](./advanced-examples.md#start)
|