altcha 1.5.1 → 2.0.0-beta.10
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 +146 -156
- package/dist/altcha.d.ts +8 -0
- package/dist/altcha.js +1833 -1574
- package/dist/altcha.umd.cjs +4 -4
- package/dist_external/altcha.css +1 -1
- package/dist_external/altcha.d.ts +8 -0
- package/dist_external/altcha.js +1769 -1510
- package/dist_external/altcha.umd.cjs +3 -3
- package/dist_i18n/af.js +21 -0
- package/dist_i18n/af.umd.cjs +1 -0
- package/dist_i18n/all.js +919 -0
- package/dist_i18n/all.umd.cjs +1 -0
- package/dist_i18n/americas.js +54 -0
- package/dist_i18n/americas.umd.cjs +1 -0
- package/dist_i18n/ar.js +21 -0
- package/dist_i18n/ar.umd.cjs +1 -0
- package/dist_i18n/asia.js +288 -0
- package/dist_i18n/asia.umd.cjs +1 -0
- package/dist_i18n/bg.js +21 -0
- package/dist_i18n/bg.umd.cjs +1 -0
- package/dist_i18n/bn.js +21 -0
- package/dist_i18n/bn.umd.cjs +1 -0
- package/dist_i18n/bs.js +21 -0
- package/dist_i18n/bs.umd.cjs +1 -0
- package/dist_i18n/ca.js +21 -0
- package/dist_i18n/ca.umd.cjs +1 -0
- package/dist_i18n/cs.js +21 -0
- package/dist_i18n/cs.umd.cjs +1 -0
- package/dist_i18n/da.js +21 -0
- package/dist_i18n/da.umd.cjs +1 -0
- package/dist_i18n/de.js +21 -0
- package/dist_i18n/de.umd.cjs +1 -0
- package/dist_i18n/el.js +21 -0
- package/dist_i18n/el.umd.cjs +1 -0
- package/dist_i18n/en.js +21 -0
- package/dist_i18n/en.umd.cjs +1 -0
- package/dist_i18n/es-419.js +21 -0
- package/dist_i18n/es-419.umd.cjs +1 -0
- package/dist_i18n/es-es.js +21 -0
- package/dist_i18n/es-es.umd.cjs +1 -0
- package/dist_i18n/et.js +21 -0
- package/dist_i18n/et.umd.cjs +1 -0
- package/dist_i18n/eu.js +21 -0
- package/dist_i18n/eu.umd.cjs +1 -0
- package/dist_i18n/europe.js +577 -0
- package/dist_i18n/europe.umd.cjs +1 -0
- package/dist_i18n/fi.js +21 -0
- package/dist_i18n/fi.umd.cjs +1 -0
- package/dist_i18n/fr-ca.js +21 -0
- package/dist_i18n/fr-ca.umd.cjs +1 -0
- package/dist_i18n/fr-fr.js +21 -0
- package/dist_i18n/fr-fr.umd.cjs +1 -0
- package/dist_i18n/ga.js +21 -0
- package/dist_i18n/ga.umd.cjs +1 -0
- package/dist_i18n/he.js +21 -0
- package/dist_i18n/he.umd.cjs +1 -0
- package/dist_i18n/hi.js +21 -0
- package/dist_i18n/hi.umd.cjs +1 -0
- package/dist_i18n/hr.js +21 -0
- package/dist_i18n/hr.umd.cjs +1 -0
- package/dist_i18n/hu.js +21 -0
- package/dist_i18n/hu.umd.cjs +1 -0
- package/dist_i18n/id.js +21 -0
- package/dist_i18n/id.umd.cjs +1 -0
- package/dist_i18n/is.js +21 -0
- package/dist_i18n/is.umd.cjs +1 -0
- package/dist_i18n/it.js +21 -0
- package/dist_i18n/it.umd.cjs +1 -0
- package/dist_i18n/ja.js +21 -0
- package/dist_i18n/ja.umd.cjs +1 -0
- package/dist_i18n/ko.js +21 -0
- package/dist_i18n/ko.umd.cjs +1 -0
- package/dist_i18n/lt.js +21 -0
- package/dist_i18n/lt.umd.cjs +1 -0
- package/dist_i18n/lv.js +21 -0
- package/dist_i18n/lv.umd.cjs +1 -0
- package/dist_i18n/mr.js +21 -0
- package/dist_i18n/mr.umd.cjs +1 -0
- package/dist_i18n/mt.js +21 -0
- package/dist_i18n/mt.umd.cjs +1 -0
- package/dist_i18n/nb.js +22 -0
- package/dist_i18n/nb.umd.cjs +1 -0
- package/dist_i18n/nl.js +21 -0
- package/dist_i18n/nl.umd.cjs +1 -0
- package/dist_i18n/pl.js +21 -0
- package/dist_i18n/pl.umd.cjs +1 -0
- package/dist_i18n/pt-br.js +21 -0
- package/dist_i18n/pt-br.umd.cjs +1 -0
- package/dist_i18n/pt-pt.js +21 -0
- package/dist_i18n/pt-pt.umd.cjs +1 -0
- package/dist_i18n/ro.js +21 -0
- package/dist_i18n/ro.umd.cjs +1 -0
- package/dist_i18n/ru.js +21 -0
- package/dist_i18n/ru.umd.cjs +1 -0
- package/dist_i18n/sk.js +21 -0
- package/dist_i18n/sk.umd.cjs +1 -0
- package/dist_i18n/sl.js +21 -0
- package/dist_i18n/sl.umd.cjs +1 -0
- package/dist_i18n/sr.js +21 -0
- package/dist_i18n/sr.umd.cjs +1 -0
- package/dist_i18n/sv.js +21 -0
- package/dist_i18n/sv.umd.cjs +1 -0
- package/dist_i18n/ta.js +21 -0
- package/dist_i18n/ta.umd.cjs +1 -0
- package/dist_i18n/te.js +21 -0
- package/dist_i18n/te.umd.cjs +1 -0
- package/dist_i18n/th.js +21 -0
- package/dist_i18n/th.umd.cjs +1 -0
- package/dist_i18n/tr.js +21 -0
- package/dist_i18n/tr.umd.cjs +1 -0
- package/dist_i18n/uk.js +21 -0
- package/dist_i18n/uk.umd.cjs +1 -0
- package/dist_i18n/ur.js +21 -0
- package/dist_i18n/ur.umd.cjs +1 -0
- package/dist_i18n/vi.js +21 -0
- package/dist_i18n/vi.umd.cjs +1 -0
- package/dist_i18n/zh-cn.js +21 -0
- package/dist_i18n/zh-cn.umd.cjs +1 -0
- package/dist_i18n/zh-tw.js +21 -0
- package/dist_i18n/zh-tw.umd.cjs +1 -0
- package/dist_plugins/obfuscation.js +10 -10
- package/dist_plugins/obfuscation.umd.cjs +1 -1
- package/dist_plugins/upload.js +145 -133
- package/dist_plugins/upload.umd.cjs +4 -4
- package/package.json +15 -12
- package/postinstall.js +0 -10
package/README.md
CHANGED
|
@@ -1,113 +1,147 @@
|
|
|
1
|
-
# ALTCHA
|
|
1
|
+
# ALTCHA
|
|
2
2
|
|
|
3
|
-
ALTCHA
|
|
3
|
+
ALTCHA is a self-hosted, privacy-first security solution that protects your websites, APIs, and online services from spam and abuse through an innovative proof-of-work mechanism. Unlike traditional CAPTCHAs that depend on intrusive methods like cookies or fingerprinting, ALTCHA delivers robust protection while respecting user privacy.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
ALTCHA is fully compliant with:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Global privacy regulations**: GDPR, HIPAA, CCPA, PIPEDA/CPPA, LGPD, and PIPL
|
|
8
|
+
- **Accessibility standards**: [WCAG 2.2 AA-level](https://altcha.org/docs/wcag/) and the [European Accessibility Act](https://altcha.org/docs/european-accessibility-act-2025/)
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
- **Cookie-Free Design**: Built to be GDPR-compliant by default, with no cookies or tracking.
|
|
11
|
-
- **Fully Accessible**: Meets WCAG 2.2 AA-level standards and complies with the European Accessibility Act (EAA).
|
|
12
|
-
- **Lightweight**: Minimal bundle size for fast page loads and optimal performance.
|
|
13
|
-
- **Self-Hosted**: Operates independently without depending on third-party services.
|
|
14
|
-
- **SaaS Option Available**: Get started quickly with the SaaS API at [altcha.org](https://altcha.org/).
|
|
10
|
+
For more details, visit [altcha.org](https://altcha.org).
|
|
15
11
|
|
|
16
|
-
##
|
|
12
|
+
## Features
|
|
17
13
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
14
|
+
- **Frictionless Experience**: Uses proof-of-work (PoW) instead of visual puzzles for a seamless user experience.
|
|
15
|
+
- **Code Challenge (New in v2)**: Supports accessible code challenges ("enter code from image") with an audio option.
|
|
16
|
+
- **Cookie-Free Design**: GDPR-compliant by default—no cookies or tracking.
|
|
17
|
+
- **Fully Accessible**: Meets WCAG 2.2 AA-level standards and complies with the European Accessibility Act (EAA).
|
|
18
|
+
- **Lightweight**: Minimal bundle size for fast page loads and optimal performance.
|
|
19
|
+
- **Self-Hosted**: No dependency on third-party services.
|
|
24
20
|
|
|
25
|
-
##
|
|
21
|
+
## What’s New in v2
|
|
26
22
|
|
|
27
|
-
-
|
|
28
|
-
- [PHP](https://github.com/altcha-org/altcha-lib-php)
|
|
29
|
-
- [Go](https://github.com/altcha-org/altcha-lib-go)
|
|
30
|
-
- [Python](https://github.com/altcha-org/altcha-lib-py)
|
|
31
|
-
- [Java](https://github.com/altcha-org/altcha-lib-java)
|
|
32
|
-
- [Ruby](https://github.com/altcha-org/altcha-lib-rb)
|
|
33
|
-
- [Elixir](https://github.com/altcha-org/altcha-lib-ex)
|
|
23
|
+
Version 2 introduces enhanced accessibility, expanded language support, and integration with **ALTCHA Sentinel**—a self-hosted anti-spam solution for websites, apps, and services.
|
|
34
24
|
|
|
35
|
-
|
|
25
|
+
### Key Improvements in v2
|
|
36
26
|
|
|
37
|
-
-
|
|
38
|
-
-
|
|
27
|
+
- **Built-in Internationalization (i18n)** for 48+ languages
|
|
28
|
+
- **Improved RTL (right-to-left) language support**
|
|
29
|
+
- **Enhanced WCAG accessibility**
|
|
30
|
+
- **Support for accessible code challenges** (image + audio options)
|
|
39
31
|
|
|
40
|
-
##
|
|
32
|
+
## Examples
|
|
41
33
|
|
|
42
|
-
|
|
34
|
+
Explore starter templates for popular frameworks:
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
- [React](https://github.com/altcha-org/altcha-starter-react-ts)
|
|
37
|
+
- [Vue](https://github.com/altcha-org/altcha-starter-vue-ts)
|
|
38
|
+
- [Svelte](https://github.com/altcha-org/altcha-starter-svelte-ts)
|
|
39
|
+
- [Solid](https://github.com/altcha-org/altcha-starter-solid-ts)
|
|
40
|
+
- [Lit](https://github.com/altcha-org/altcha-starter-lit-ts)
|
|
41
|
+
- [Angular](https://github.com/altcha-org/altcha-starter-angular)
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
## Server Integrations
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
- [TypeScript](https://github.com/altcha-org/altcha-lib)
|
|
46
|
+
- [PHP](https://github.com/altcha-org/altcha-lib-php)
|
|
47
|
+
- [Go](https://github.com/altcha-org/altcha-lib-go)
|
|
48
|
+
- [Python](https://github.com/altcha-org/altcha-lib-py)
|
|
49
|
+
- [Java](https://github.com/altcha-org/altcha-lib-java)
|
|
50
|
+
- [Ruby](https://github.com/altcha-org/altcha-lib-rb)
|
|
51
|
+
- [Elixir](https://github.com/altcha-org/altcha-lib-ex)
|
|
52
|
+
|
|
53
|
+
## Plugins & CMS
|
|
54
|
+
|
|
55
|
+
- [Libraries and plugins](https://altcha.org/docs/integrations/)
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
The ALTCHA widget is distributed as a **Web Component** and [supports all modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/Web_components#browser_compatibility).
|
|
60
|
+
|
|
61
|
+
### 1. Install ALTCHA
|
|
49
62
|
|
|
50
63
|
```sh
|
|
51
64
|
npm install altcha
|
|
52
65
|
```
|
|
53
66
|
|
|
54
|
-
|
|
67
|
+
Import in your main file:
|
|
55
68
|
|
|
56
69
|
```js
|
|
57
70
|
import 'altcha';
|
|
58
71
|
```
|
|
59
72
|
|
|
60
|
-
|
|
73
|
+
Or load via `<script>` tag:
|
|
61
74
|
|
|
62
75
|
```html
|
|
63
76
|
<script async defer src="/altcha.js" type="module"></script>
|
|
64
77
|
```
|
|
65
78
|
|
|
66
|
-
CDN
|
|
79
|
+
**CDN**:
|
|
80
|
+
```html
|
|
81
|
+
<script async defer src="https://cdn.jsdelivr.net/gh/altcha-org/altcha@main/dist/altcha.min.js" type="module"></script>
|
|
82
|
+
```
|
|
67
83
|
|
|
68
|
-
### 2.
|
|
84
|
+
### 2. Add `<altcha-widget>` to Your Forms
|
|
69
85
|
|
|
70
86
|
```html
|
|
71
87
|
<form>
|
|
72
|
-
<altcha-widget
|
|
73
|
-
challengeurl="https://..."
|
|
74
|
-
></altcha-widget>
|
|
88
|
+
<altcha-widget challengeurl="https://..."></altcha-widget>
|
|
75
89
|
</form>
|
|
76
90
|
```
|
|
77
91
|
|
|
78
|
-
See
|
|
92
|
+
See [configuration options](#configuration) or the [website integration docs](https://altcha.org/docs/website-integration).
|
|
93
|
+
|
|
94
|
+
### 3. Integrate with Your Server
|
|
79
95
|
|
|
80
|
-
|
|
96
|
+
Refer to the [server documentation](https://altcha.org/docs/server-integration) for implementation details.
|
|
81
97
|
|
|
82
|
-
|
|
98
|
+
## Supported Browsers
|
|
83
99
|
|
|
84
|
-
|
|
100
|
+
ALTCHA works on modern browsers with **Web Crypto API** support (specifically `crypto.subtle` - [caniuse.com](https://caniuse.com/?search=subtle)).
|
|
85
101
|
|
|
86
|
-
|
|
102
|
+
**Supported**:
|
|
87
103
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
- Chrome (desktop & Android)
|
|
105
|
+
- Edge
|
|
106
|
+
- Firefox (desktop & Android)
|
|
107
|
+
- Safari (macOS & iOS)
|
|
108
|
+
- Any browser supporting Web Components + Web Crypto
|
|
93
109
|
|
|
94
|
-
|
|
110
|
+
**Not Supported**:
|
|
95
111
|
|
|
96
|
-
|
|
112
|
+
- Internet Explorer 11 (or older)
|
|
97
113
|
|
|
98
|
-
##
|
|
114
|
+
## Bundle Size
|
|
115
|
+
|
|
116
|
+
ALTCHA is optimized for performance:
|
|
117
|
+
|
|
118
|
+
| Distribution | Size (GZIPped) |
|
|
119
|
+
|-------------------|----------------|
|
|
120
|
+
| ALTCHA (v2.x) | 28+ kB |
|
|
121
|
+
| hCaptcha | 48+ kB |
|
|
122
|
+
| reCAPTCHA | 270+ kB |
|
|
123
|
+
|
|
124
|
+
When GZIPped, it totals about 28 kB, making ALTCHA’s widget about 90% smaller than reCAPTCHA.
|
|
125
|
+
|
|
126
|
+
## Content Security Policy (CSP)
|
|
127
|
+
|
|
128
|
+
The default bundle includes styles and workers in a single file. For strict CSP compliance, use scripts from `/dist_external`. Learn more in the [documentation](https://altcha.org/docs/website-integration).
|
|
129
|
+
|
|
130
|
+
## Configuration
|
|
99
131
|
|
|
100
132
|
Required options (at least one is required):
|
|
101
133
|
|
|
102
|
-
- **challengeurl**:
|
|
103
|
-
- **challengejson**: JSON
|
|
134
|
+
- **challengeurl**: Server endpoint to fetch the challenge.
|
|
135
|
+
- **challengejson**: Preloaded JSON challenge data (avoids HTTP requests).
|
|
104
136
|
|
|
105
137
|
Additional options:
|
|
106
138
|
|
|
107
139
|
- **auto**: Automatically verify without user interaction (possible values: `off`, `onfocus`, `onload`, `onsubmit`).
|
|
140
|
+
- **credentials**: Whether to include [credentials](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#credentials) with the challenge request (possible values: `omit`, `same-origin`, `include`).
|
|
108
141
|
- **customfetch**: A custom `fetch` function for retrieving the challenge.
|
|
109
142
|
Accepts `url: string` and `init: RequestInit` as arguments and must return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
|
|
110
143
|
- **delay**: Artificial delay in milliseconds before verification (defaults to 0).
|
|
144
|
+
- **disableautofocus**: If true, prevents the code-challenge input from automatically receiving focus on render (defaults to `false`).
|
|
111
145
|
- **expire**: Challenge expiration duration in milliseconds.
|
|
112
146
|
- **floating**: Enable floating UI (possible values: `auto`, `top`, `bottom`).
|
|
113
147
|
- **floatinganchor**: CSS selector of the "anchor" to which the floating UI will be attached (defaults to the `button[type="submit"]` in the related form).
|
|
@@ -116,6 +150,7 @@ Additional options:
|
|
|
116
150
|
- **hidefooter**: Hide the footer (ALTCHA link).
|
|
117
151
|
- **hidelogo**: Hide the ALTCHA logo.
|
|
118
152
|
- **id**: The checkbox `id` attribute. Useful for multiple instances of the widget on the same page.
|
|
153
|
+
- **language**: The ISO alpha-2 code of the language to use (the language file be imported from `altcha/i18n/*`).
|
|
119
154
|
- **maxnumber**: Max number to iterate to (defaults to 1,000,000).
|
|
120
155
|
- **name**: Name of the hidden field containing the payload (defaults to "altcha").
|
|
121
156
|
- **strings**: JSON-encoded translation strings. Refer to [customization](https://altcha.org/docs/widget-customization).
|
|
@@ -123,12 +158,6 @@ Additional options:
|
|
|
123
158
|
- **workers**: Number of workers to utilize for PoW (defaults to `navigator.hardwareConcurrency || 8`, max value `16`).
|
|
124
159
|
- **workerurl**: URL of the Worker script (defaults to `./worker.js`, only works with `external` build).
|
|
125
160
|
|
|
126
|
-
Spam Filter-related options:
|
|
127
|
-
|
|
128
|
-
- **blockspam**: Only used with the `spamfilter` option. If enabled, it will block form submission and fail verification if the Spam Filter returns a negative classification. This prevents form submission.
|
|
129
|
-
- **spamfilter**: Enable [Spam Filter](#spam-filter).
|
|
130
|
-
- **verifyurl**: URL for server-side verification requests. This option is automatically configured when the `spamfilter` option is used. Override this setting only if using a custom server implementation.
|
|
131
|
-
|
|
132
161
|
Data Obfuscation options:
|
|
133
162
|
|
|
134
163
|
- **obfuscated**: The [obfuscated data](https://altcha.org/docs/obfuscation) provided as a base64-encoded string (requires `altcha/obfuscation` plugin). Use only without `challengeurl`/`challengejson`.
|
|
@@ -139,24 +168,48 @@ Development / Testing options:
|
|
|
139
168
|
- **mockerror**: Causes verification to always fail with a "mock" error.
|
|
140
169
|
- **test**: Generates a "mock" challenge within the widget, bypassing the request to `challengeurl`.
|
|
141
170
|
|
|
142
|
-
##
|
|
171
|
+
## Internationalization (i18n)
|
|
143
172
|
|
|
144
|
-
|
|
173
|
+
ALTCHA supports **48+ languages**. Import translations from `altcha/i18n/*`:
|
|
145
174
|
|
|
146
175
|
```js
|
|
147
|
-
import 'altcha/obfuscation';
|
|
148
176
|
import 'altcha';
|
|
177
|
+
import 'altcha/i18n/all'; // All languages
|
|
178
|
+
// Or import specific languages:
|
|
179
|
+
import 'altcha/i18n/de';
|
|
180
|
+
import 'altcha/i18n/fr-fr';
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The widget auto-detects language from `<html lang="...">` or `navigator.languages`. Override with the `language` attribute:
|
|
184
|
+
|
|
185
|
+
```html
|
|
186
|
+
<altcha-widget language="de"></altcha-widget>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Code Challenges
|
|
190
|
+
|
|
191
|
+
For additional verification, ALTCHA supports **image/audio code challenges** (e.g., "Enter the code from the image"). This feature requires **ALTCHA Sentinel** or a custom server implementation.
|
|
192
|
+
|
|
193
|
+
## Plugins
|
|
194
|
+
|
|
195
|
+
Extend functionality with plugins:
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import 'altcha/obfuscation'; // Data obfuscation
|
|
199
|
+
import 'altcha/upload'; // File uploads
|
|
200
|
+
import 'altcha'; // Main package
|
|
149
201
|
```
|
|
150
202
|
|
|
151
|
-
|
|
203
|
+
Enable plugins per widget:
|
|
152
204
|
|
|
153
|
-
|
|
205
|
+
```html
|
|
206
|
+
<altcha-widget plugins="upload,obfuscation"></altcha-widget>
|
|
207
|
+
```
|
|
154
208
|
|
|
155
|
-
|
|
156
|
-
- `altcha/obfuscation`: Enable [obfuscation](https://altcha.org/docs/obfuscation) for sensitive data such as email addresses or phone numbers.
|
|
157
|
-
- `altcha/upload`: Enable file upload from `type=file` fields to [ALTCHA Forms](https://altcha.org/forms/). See [HTML submissions documentation](https://altcha.org/docs/forms/features/html-submissions).
|
|
209
|
+
### Available Plugins
|
|
158
210
|
|
|
159
|
-
|
|
211
|
+
- **obfuscation**: Secure sensitive data (emails, phone numbers).
|
|
212
|
+
- **upload**: File uploads with ALTCHA Sentinel or a custom backend.
|
|
160
213
|
|
|
161
214
|
## Programmatic Configuration
|
|
162
215
|
|
|
@@ -182,6 +235,11 @@ Available configuration options:
|
|
|
182
235
|
export interface Configure {
|
|
183
236
|
auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
|
|
184
237
|
challenge?: {
|
|
238
|
+
codeChallenge?: {
|
|
239
|
+
audio?: string;
|
|
240
|
+
image: string;
|
|
241
|
+
length?: number;
|
|
242
|
+
};
|
|
185
243
|
algorithm: string;
|
|
186
244
|
challenge: string;
|
|
187
245
|
maxnumber?: number;
|
|
@@ -189,9 +247,11 @@ export interface Configure {
|
|
|
189
247
|
signature: string;
|
|
190
248
|
};
|
|
191
249
|
challengeurl?: string;
|
|
250
|
+
credentials?: 'omit' | 'same-origin' | 'include' | boolean;
|
|
192
251
|
customfetch?: string | ((url: string, init?: RequestInit) => Promise<Response>);
|
|
193
252
|
debug?: boolean;
|
|
194
253
|
delay?: number;
|
|
254
|
+
disableautofocus?: boolean;
|
|
195
255
|
expire?: number;
|
|
196
256
|
floating?: 'auto' | 'top' | 'bottom';
|
|
197
257
|
floatinganchor?: string;
|
|
@@ -204,12 +264,19 @@ export interface Configure {
|
|
|
204
264
|
name?: string;
|
|
205
265
|
obfuscated?: string;
|
|
206
266
|
refetchonexpire?: boolean;
|
|
207
|
-
spamfilter?: boolean | 'ipAddress' | SpamFilter;
|
|
267
|
+
spamfilter?: boolean | 'ipAddress' | SpamFilter; // deprecated
|
|
208
268
|
strings?: {
|
|
269
|
+
ariaLinkLabel: strin;
|
|
270
|
+
enterCode: string;
|
|
271
|
+
enterCodeAria: string;
|
|
209
272
|
error: string;
|
|
210
273
|
expired: string;
|
|
211
274
|
footer: string;
|
|
275
|
+
getAudioChallenge: string;
|
|
212
276
|
label: string;
|
|
277
|
+
loading: string;
|
|
278
|
+
reload: strin;
|
|
279
|
+
verificationRequired: string;
|
|
213
280
|
verified: string;
|
|
214
281
|
verifying: string;
|
|
215
282
|
waitAlert: string;
|
|
@@ -221,51 +288,18 @@ export interface Configure {
|
|
|
221
288
|
}
|
|
222
289
|
```
|
|
223
290
|
|
|
224
|
-
## Custom `fetch` Function
|
|
225
|
-
|
|
226
|
-
The widget does not send cookies (i.e., it does not use `credentials: 'include'`) when requesting the challenge from the server. To modify this behavior or add custom request headers, use the `customfetch` configuration option. This option lets you define a custom request function.
|
|
227
|
-
|
|
228
|
-
The custom function must return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
|
|
229
|
-
|
|
230
|
-
### Sending Cookies
|
|
231
|
-
|
|
232
|
-
To include cookies in the request, use `credentials: 'include'`:
|
|
233
|
-
|
|
234
|
-
```ts
|
|
235
|
-
function altchaCustomFetch(url: string, init: RequestInit) {
|
|
236
|
-
return fetch(url, {
|
|
237
|
-
...init,
|
|
238
|
-
credentials: 'include', // Include cookies with the request
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
For more details on possible request options, refer to the [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) documentation.
|
|
244
|
-
|
|
245
|
-
### Using `customfetch`
|
|
246
|
-
|
|
247
|
-
The `customfetch` option can accept either:
|
|
248
|
-
- A `string` (the name of a globally accessible function defined in the global context, such as `window`), or
|
|
249
|
-
- A function itself.
|
|
250
|
-
|
|
251
|
-
### Example Usage
|
|
252
|
-
|
|
253
|
-
```html
|
|
254
|
-
<altcha-widget
|
|
255
|
-
challengeurl="https://example.com/challenge"
|
|
256
|
-
customfetch="altchaCustomFetch"
|
|
257
|
-
></altcha-widget>
|
|
258
|
-
```
|
|
259
|
-
|
|
260
291
|
## Events
|
|
261
292
|
|
|
293
|
+
- **code** - Triggers when code-challenge verification is requested.
|
|
262
294
|
- **load** - Triggers when the widget loads. The exported methods become available after this event.
|
|
263
|
-
- **
|
|
295
|
+
- **sentinelverification** - Triggers upon a verification with ALTCHA Sentinel.
|
|
296
|
+
- **serververification** - (Deprecated) Triggers upon a server verification (only in conjunction with `spamfilter`).
|
|
264
297
|
- **statechange** - Triggers whenever an internal `state` changes.
|
|
265
298
|
- **verified** - Triggers when the challenge is verified.
|
|
266
299
|
|
|
267
300
|
```ts
|
|
268
301
|
enum State {
|
|
302
|
+
CODE = 'code',
|
|
269
303
|
ERROR = 'error',
|
|
270
304
|
VERIFIED = 'verified',
|
|
271
305
|
VERIFYING = 'verifying',
|
|
@@ -286,58 +320,14 @@ document.querySelector('#altcha').addEventListener('statechange', (ev) => {
|
|
|
286
320
|
> [!IMPORTANT]
|
|
287
321
|
> Both programmatic configuration and event listeners have to called/attached after the ALTCHA script loads, such as within `window.addEventListener('load', ...)`.
|
|
288
322
|
|
|
289
|
-
##
|
|
323
|
+
## Contributing
|
|
290
324
|
|
|
291
|
-
The widget integrates with ALTCHA's [Anti-Spam solution](https://altcha.org/anti-spam) to allow checking submitted form data for potential spam.
|
|
292
|
-
|
|
293
|
-
The Spam Filter API analyzes various signals in the submitted data to determine if it exhibits characteristics of spam. This non-invasive filtering helps reduce spam submissions without frustrating legitimate users.
|
|
294
|
-
|
|
295
|
-
### Spam Filter Configuration
|
|
296
|
-
|
|
297
|
-
The Spam Filter can be enabled with default configuration by setting the `spamfilter` option to `true`, or `ipAddress` to verify only the IP address and the time zone, or it can be customized using the following configuration schema:
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
interface SpamFilter {
|
|
301
|
-
blockedCountries?: string[];
|
|
302
|
-
classifier?: string;
|
|
303
|
-
disableRules?: string[];
|
|
304
|
-
email?: string | false;
|
|
305
|
-
expectedCountries?: string[];
|
|
306
|
-
expectedLanguages?: string[];
|
|
307
|
-
fields?: string[] | false;
|
|
308
|
-
ipAddress?: string | false;
|
|
309
|
-
text?: string | string[];
|
|
310
|
-
timeZone?: string | false;
|
|
311
|
-
}
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
SpamFilter configuration options:
|
|
315
|
-
|
|
316
|
-
- **blockedCountries** - An array of country codes (ISO 3166 alpha-2) that you want to block.
|
|
317
|
-
- **classifier** - Enforce a specific classifier.
|
|
318
|
-
- **disableRules** - An array of rules to disable.
|
|
319
|
-
- **email** - The name of the input field for the user's email. Disable email checking with `false`.
|
|
320
|
-
- **expectedCountries** - An array of expected countries as 2-letter codes (ISO 3166-1 alpha-2).
|
|
321
|
-
- **expectedLanguages** - An array of expected languages as 2-letter codes (ISO 639 alpha-2).
|
|
322
|
-
- **fields** - An array of input names to send to the spam filter.
|
|
323
|
-
- **ipAddress** - The user's IP is detected automatically but can be overridden or disabled with `false`.
|
|
324
|
-
- **text** - The text to classify. An array of strings can also be submitted.
|
|
325
|
-
- **timeZone** - The user's timezone is detected automatically but can be overridden or disabled with `false`.
|
|
326
|
-
|
|
327
|
-
To include the email field into `fields` (for easier server-side verification), configure the list of input names using the `spamfilter.fields: string[]` option.
|
|
328
|
-
|
|
329
|
-
### Exclude Inputs from Spam Checking
|
|
330
|
-
|
|
331
|
-
By default, all text inputs and textareas within the parent form are spam-checked. To exclude a specific input, add the `data-no-spamfilter` attribute. Alternatively, explicitly list the checked fields using the `fields` config option.
|
|
332
|
-
|
|
333
|
-
## Contributing
|
|
334
325
|
See [Contributing Guide](https://github.com/altcha-org/altcha/blob/main/CONTRIBUTING.md) and please follow our [Code of Conduct](https://github.com/altcha-org/altcha/blob/main/CODE_OF_CONDUCT.md).
|
|
335
326
|
|
|
336
327
|
## Sponsorship
|
|
337
328
|
|
|
338
|
-
This project is sponsored by [BAUSW.com - Digital Construction Site Diary](https://bausw.com/digital-construction-diary/), promoting transparency and trust in construction projects with real-time documentation.
|
|
339
|
-
|
|
340
|
-
## License
|
|
329
|
+
This project is sponsored by [BAUSW.com - Digital Construction Site Diary](https://bausw.com/digital-construction-diary/), promoting transparency and trust in construction projects with real-time documentation.
|
|
341
330
|
|
|
342
|
-
|
|
331
|
+
## License
|
|
343
332
|
|
|
333
|
+
**MIT**
|
package/dist/altcha.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ declare module 'altcha';
|
|
|
5
5
|
declare global {
|
|
6
6
|
var altchaCreateWorker: (url?: string) => Worker;
|
|
7
7
|
var altchaPlugins: any[];
|
|
8
|
+
var altchaI18n: Record<string, any> & {
|
|
9
|
+
register: (language: string, translation: Record<string, string>) => void;
|
|
10
|
+
};
|
|
8
11
|
|
|
9
12
|
type AltchaState = 'error' | 'expired' | 'verified' | 'verifying' | 'unverified';
|
|
10
13
|
|
|
@@ -21,12 +24,15 @@ declare global {
|
|
|
21
24
|
|
|
22
25
|
interface AltchaWidgetOptions {
|
|
23
26
|
auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
|
|
27
|
+
/** @deprecated */
|
|
24
28
|
blockspam?: boolean;
|
|
25
29
|
challengeurl?: string;
|
|
26
30
|
challengejson?: string;
|
|
31
|
+
credentials?: 'omit' | 'same-origin' | 'include' | boolean | undefined;
|
|
27
32
|
customfetch?: string | ((url: string, init?: RequestInit) => Promise<Response>);
|
|
28
33
|
debug?: boolean;
|
|
29
34
|
delay?: number;
|
|
35
|
+
disableautofocus?: boolean;
|
|
30
36
|
expire?: number;
|
|
31
37
|
floating?: 'auto' | 'top' | 'bottom' | 'false' | '' | boolean;
|
|
32
38
|
floatinganchor?: string;
|
|
@@ -35,6 +41,7 @@ declare global {
|
|
|
35
41
|
hidefooter?: boolean;
|
|
36
42
|
hidelogo?: boolean;
|
|
37
43
|
id?: string;
|
|
44
|
+
language?: string;
|
|
38
45
|
maxnumber?: number;
|
|
39
46
|
mockerror?: boolean;
|
|
40
47
|
name?: string;
|
|
@@ -48,6 +55,7 @@ declare global {
|
|
|
48
55
|
onuploadprogress?: (ev: CustomEvent) => void;
|
|
49
56
|
plugins?: string;
|
|
50
57
|
refetchonexpire?: boolean;
|
|
58
|
+
/** @deprecated */
|
|
51
59
|
spamfilter?: boolean | 'ipAddress';
|
|
52
60
|
strings?: string;
|
|
53
61
|
test?: boolean | number;
|