@sendlix/group 0.0.1
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/LICENSE +201 -0
- package/README.md +222 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +35 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/proof-of-work.d.ts +58 -0
- package/dist/proof-of-work.d.ts.map +1 -0
- package/dist/proof-of-work.js +308 -0
- package/dist/proof-of-work.js.map +1 -0
- package/dist/react/GroupIframe.d.ts +16 -0
- package/dist/react/GroupIframe.d.ts.map +1 -0
- package/dist/react/GroupIframe.js +62 -0
- package/dist/react/GroupIframe.js.map +1 -0
- package/dist/react/ProofOfWorkInput.d.ts +10 -0
- package/dist/react/ProofOfWorkInput.d.ts.map +1 -0
- package/dist/react/ProofOfWorkInput.js +90 -0
- package/dist/react/ProofOfWorkInput.js.map +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +17 -0
- package/dist/utils.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# @sendlix/group
|
|
2
|
+
|
|
3
|
+
> Subscribe users to Sendlix mailing groups – with optional Proof-of-Work bot protection and ready-made React components.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@sendlix/group)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @sendlix/group
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
React components are included in the same package and available via the `/react` sub-path:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# No extra install needed – React is a peer dependency
|
|
18
|
+
npm install react
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
### Subscribe an email address
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { subscribeToGroup } from "@sendlix/group";
|
|
29
|
+
|
|
30
|
+
const result = await subscribeToGroup({
|
|
31
|
+
id: "your-group-id",
|
|
32
|
+
email: "user@example.com",
|
|
33
|
+
});
|
|
34
|
+
// { success: true, code: 0, message: "Email added to group" }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### With Proof-of-Work bot protection
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { subscribeToGroup, ProofOfWork } from "@sendlix/group";
|
|
41
|
+
|
|
42
|
+
const pow = new ProofOfWork("your-group-id");
|
|
43
|
+
|
|
44
|
+
// Pre-warm the WebGPU pipeline (optional, call on page load)
|
|
45
|
+
pow.init();
|
|
46
|
+
|
|
47
|
+
const { token, nonce } = await pow.solve("user@example.com");
|
|
48
|
+
|
|
49
|
+
const result = await subscribeToGroup({
|
|
50
|
+
id: "your-group-id",
|
|
51
|
+
email: "user@example.com",
|
|
52
|
+
botProtection: { type: "proofOfWork", token, nonce },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Release resources when done
|
|
56
|
+
pow.close();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### With template placeholders
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
await subscribeToGroup({
|
|
63
|
+
id: "your-group-id",
|
|
64
|
+
email: "user@example.com",
|
|
65
|
+
substitute: {
|
|
66
|
+
"##First Name##": "Alice",
|
|
67
|
+
"##Last Name##": "Smith",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## React components
|
|
75
|
+
|
|
76
|
+
### `GroupIframe` – embed the hosted form
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { GroupIframe } from "@sendlix/group/react";
|
|
80
|
+
|
|
81
|
+
<GroupIframe
|
|
82
|
+
id="your-group-id"
|
|
83
|
+
appearance={{
|
|
84
|
+
primaryColor: "oklch(0.65 0.12 87)",
|
|
85
|
+
backgroundColor: "white",
|
|
86
|
+
textColor: "black",
|
|
87
|
+
name: "Newsletter",
|
|
88
|
+
info: "No spam, unsubscribe at any time.",
|
|
89
|
+
}}
|
|
90
|
+
/>;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The iframe resizes automatically when the hosted form changes height. All standard `<iframe>` attributes are forwarded.
|
|
94
|
+
|
|
95
|
+
| Prop | Type | Default | Description |
|
|
96
|
+
| ------------- | ------------ | ------- | --------------------------- |
|
|
97
|
+
| `id` | `string` | – | Group ID |
|
|
98
|
+
| `appearance` | `Appearance` | – | Visual customisation |
|
|
99
|
+
| `startHeight` | `number` | `500` | Initial iframe height in px |
|
|
100
|
+
|
|
101
|
+
### `ProofOfWorkInput` – drop-in email input with PoW
|
|
102
|
+
|
|
103
|
+
A replacement for `<input type="email">` that automatically runs the Proof-of-Work challenge on blur and injects hidden `pow-token` / `pow-nonce` fields into the surrounding `<form>`.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { ProofOfWorkInput } from "@sendlix/group/react";
|
|
107
|
+
|
|
108
|
+
function SubscribeForm() {
|
|
109
|
+
const [status, setStatus] = useState<string>();
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<form method="POST" action="https://group.sendlix.com/your-group-id">
|
|
113
|
+
<ProofOfWorkInput
|
|
114
|
+
sendlix={{ id: "your-group-id", onStatusChange: setStatus }}
|
|
115
|
+
placeholder="your@email.com"
|
|
116
|
+
required
|
|
117
|
+
/>
|
|
118
|
+
{status === "loading" && <span>Solving challenge…</span>}
|
|
119
|
+
{status === "processing" && <span>Renewing token…</span>}
|
|
120
|
+
{status === "success" && <span>Ready</span>}
|
|
121
|
+
{status === "error" && <span>PoW failed</span>}
|
|
122
|
+
<button type="submit">Subscribe</button>
|
|
123
|
+
</form>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
| Prop | Type | Description |
|
|
129
|
+
| ------------------------ | ----------------------------- | --------------------------------- |
|
|
130
|
+
| `sendlix.id` | `string` | Group ID |
|
|
131
|
+
| `sendlix.onStatusChange` | `(status: PowStatus) => void` | Called on every status transition |
|
|
132
|
+
|
|
133
|
+
All standard `<input>` attributes are forwarded to the underlying email input.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## API reference
|
|
138
|
+
|
|
139
|
+
### `subscribeToGroup(options)`
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
subscribeToGroup(options: {
|
|
143
|
+
id: string;
|
|
144
|
+
email: string;
|
|
145
|
+
substitute?: Record<string, string>;
|
|
146
|
+
botProtection?: { type: "proofOfWork"; token: string; nonce: string };
|
|
147
|
+
}): Promise<GroupResponse>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### `subscribeToGroupWithFormData(data, id, substitute?)`
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
subscribeToGroupWithFormData(
|
|
154
|
+
data: FormData,
|
|
155
|
+
id: string,
|
|
156
|
+
substitute?: Record<string, string>,
|
|
157
|
+
): Promise<GroupResponse>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Use this when you already have a native `<form>` and control the `FormData` yourself.
|
|
161
|
+
|
|
162
|
+
### `ProofOfWork`
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
const pow = new ProofOfWork(groupId: string, options?: PowOptions);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Options**
|
|
169
|
+
|
|
170
|
+
| Option | Type | Description |
|
|
171
|
+
| ---------------- | ----------------------------- | ------------------------------------------------------- |
|
|
172
|
+
| `onStatusChange` | `(status: PowStatus) => void` | Called on every status change |
|
|
173
|
+
| `onRenew` | `(result: PowResult) => void` | Called when the token is silently renewed before expiry |
|
|
174
|
+
|
|
175
|
+
**Methods**
|
|
176
|
+
|
|
177
|
+
| Method | Returns | Description |
|
|
178
|
+
| ------------------ | -------------------- | ---------------------------------------------------------------------- |
|
|
179
|
+
| `pow.solve(email)` | `Promise<PowResult>` | Requests a challenge and solves it. Schedules automatic renewal. |
|
|
180
|
+
| `pow.init()` | `void` | Pre-warms the WebGPU pipeline. Call on component mount. |
|
|
181
|
+
| `pow.close()` | `void` | Cancels the renewal timer and releases GPU resources. Call on unmount. |
|
|
182
|
+
|
|
183
|
+
Uses **WebGPU** when available for GPU-accelerated solving, with an automatic fallback to the **Web Crypto API** (CPU).
|
|
184
|
+
|
|
185
|
+
### Types
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
type PowResult = { token: string; nonce: string };
|
|
189
|
+
type PowStatus = "loading" | "processing" | "success" | "error";
|
|
190
|
+
|
|
191
|
+
type GroupResponse = {
|
|
192
|
+
success: boolean;
|
|
193
|
+
code: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
194
|
+
message: string;
|
|
195
|
+
};
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Development
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
npm install # install dependencies
|
|
204
|
+
npm test # run Jest test suite
|
|
205
|
+
npm run build # compile TypeScript → ./dist
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Releases
|
|
209
|
+
|
|
210
|
+
Releases are automated via [semantic-release](https://semantic-release.gitbook.io) on every push to `main`. Use [Conventional Commits](https://www.conventionalcommits.org) for your commit messages:
|
|
211
|
+
|
|
212
|
+
| Prefix | Release type |
|
|
213
|
+
| ----------------------------- | ------------- |
|
|
214
|
+
| `fix:` | Patch (0.0.x) |
|
|
215
|
+
| `feat:` | Minor (0.x.0) |
|
|
216
|
+
| `feat!:` / `BREAKING CHANGE:` | Major (x.0.0) |
|
|
217
|
+
|
|
218
|
+
Required repository secrets: `NPM_TOKEN`.
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
Apache License 2.0. See [LICENSE](LICENSE) for details.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GroupResponse } from "./types";
|
|
2
|
+
type BotProtection = {
|
|
3
|
+
type: "proofOfWork";
|
|
4
|
+
token: string;
|
|
5
|
+
nonce: string;
|
|
6
|
+
};
|
|
7
|
+
type SubscribeOptions = {
|
|
8
|
+
/** Group ID */
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
/** Key/value pairs that replace placeholders in the email template. */
|
|
12
|
+
substitute?: Record<string, string>;
|
|
13
|
+
botProtection?: BotProtection;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Submits a pre-built `FormData` object directly to the group endpoint.
|
|
17
|
+
* Use this when you already control the form (e.g. a native `<form>`).
|
|
18
|
+
*/
|
|
19
|
+
export declare function subscribeToGroupWithFormData(data: FormData, id: string, substitute?: Record<string, string>): Promise<GroupResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Subscribes an email address to a Sendlix group.
|
|
22
|
+
* Optionally includes a Proof-of-Work token to prevent bot submissions.
|
|
23
|
+
*/
|
|
24
|
+
export declare function subscribeToGroup(options: SubscribeOptions): Promise<GroupResponse>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,KAAK,aAAa,GAAG;IACjB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACpB,eAAe;IACf,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;CACjC,CAAC;AAEF;;;GAGG;AACH,wBAAsB,4BAA4B,CAC9C,IAAI,EAAE,QAAQ,EACd,EAAE,EAAE,MAAM,EACV,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACxC,OAAO,CAAC,aAAa,CAAC,CAaxB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAcxF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { toValidVarName } from "./utils";
|
|
2
|
+
/**
|
|
3
|
+
* Submits a pre-built `FormData` object directly to the group endpoint.
|
|
4
|
+
* Use this when you already control the form (e.g. a native `<form>`).
|
|
5
|
+
*/
|
|
6
|
+
export async function subscribeToGroupWithFormData(data, id, substitute = {}) {
|
|
7
|
+
if (!data.get("email")) {
|
|
8
|
+
throw new Error("Please fill in all fields");
|
|
9
|
+
}
|
|
10
|
+
for (const [key, value] of Object.entries(substitute)) {
|
|
11
|
+
data.append(toValidVarName(key), value);
|
|
12
|
+
}
|
|
13
|
+
return fetch(`https://group.sendlix.com/${id}?json=true`, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
body: data,
|
|
16
|
+
}).then((res) => res.json());
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Subscribes an email address to a Sendlix group.
|
|
20
|
+
* Optionally includes a Proof-of-Work token to prevent bot submissions.
|
|
21
|
+
*/
|
|
22
|
+
export async function subscribeToGroup(options) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (!options.id || !options.email) {
|
|
25
|
+
throw new Error("Please fill in all fields");
|
|
26
|
+
}
|
|
27
|
+
const formData = new FormData();
|
|
28
|
+
formData.append("email", options.email);
|
|
29
|
+
if (((_a = options.botProtection) === null || _a === void 0 ? void 0 : _a.type) === "proofOfWork") {
|
|
30
|
+
formData.append("token", options.botProtection.token);
|
|
31
|
+
formData.append("nonce", options.botProtection.nonce);
|
|
32
|
+
}
|
|
33
|
+
return subscribeToGroupWithFormData(formData, options.id, (_b = options.substitute) !== null && _b !== void 0 ? _b : {});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAiBzC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAC9C,IAAc,EACd,EAAU,EACV,aAAqC,EAAE;IAEvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,KAAK,CAAC,6BAA6B,EAAE,YAAY,EAAE;QACtD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI;KACb,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAA4B,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAyB;;IAC5D,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAExC,IAAI,CAAA,MAAA,OAAO,CAAC,aAAa,0CAAE,IAAI,MAAK,aAAa,EAAE,CAAC;QAChD,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACtD,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,4BAA4B,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,MAAA,OAAO,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC;AACxF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { subscribeToGroup, subscribeToGroupWithFormData } from "./client";
|
|
2
|
+
export { responseMessages } from "./types";
|
|
3
|
+
export type { GroupResponse } from "./types";
|
|
4
|
+
export { ProofOfWork } from "./proof-of-work";
|
|
5
|
+
export type { PowStatus, PowOptions, PowResult } from "./proof-of-work";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type PowStatus = "loading" | "processing" | "success" | "error";
|
|
2
|
+
export type PowOptions = {
|
|
3
|
+
/** Called whenever the solving status changes. */
|
|
4
|
+
onStatusChange?: (status: PowStatus) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Called automatically when the PoW token is renewed before it expires.
|
|
7
|
+
* Use this to keep hidden form fields up-to-date without user interaction.
|
|
8
|
+
*/
|
|
9
|
+
onRenew?: (result: {
|
|
10
|
+
token: string;
|
|
11
|
+
nonce: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
};
|
|
14
|
+
export type PowResult = {
|
|
15
|
+
token: string;
|
|
16
|
+
nonce: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class ProofOfWork {
|
|
19
|
+
private expiration;
|
|
20
|
+
private _solving;
|
|
21
|
+
private renewTimer;
|
|
22
|
+
private _gpu;
|
|
23
|
+
private _gpuSupported;
|
|
24
|
+
private readonly id;
|
|
25
|
+
private readonly onStatusChange;
|
|
26
|
+
private readonly onRenew;
|
|
27
|
+
constructor(id: string, options?: PowOptions);
|
|
28
|
+
private static _checkGpuSupport;
|
|
29
|
+
private _initGpu;
|
|
30
|
+
private _solveGpu;
|
|
31
|
+
private _solveCpu;
|
|
32
|
+
private _setStatus;
|
|
33
|
+
private _requestChallenge;
|
|
34
|
+
private _scheduleRenew;
|
|
35
|
+
private _renewInternal;
|
|
36
|
+
private _solveInternal;
|
|
37
|
+
/**
|
|
38
|
+
* Solves the Proof-of-Work challenge for the given email address.
|
|
39
|
+
* Returns `{ token, nonce }` which must be submitted alongside the form.
|
|
40
|
+
* Automatically schedules a silent token renewal before expiry.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const pow = new ProofOfWork(groupId);
|
|
45
|
+
* const { token, nonce } = await pow.solve("user@example.com");
|
|
46
|
+
* await subscribeToGroup({ id: groupId, email, botProtection: { type: "proofOfWork", token, nonce } });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
solve(email: string): Promise<PowResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Pre-warms the WebGPU pipeline so the first `solve()` call is faster.
|
|
52
|
+
* Safe to call on component mount; does nothing if WebGPU is unavailable.
|
|
53
|
+
*/
|
|
54
|
+
init(): void;
|
|
55
|
+
/** Cancels any pending renewal timer and releases GPU resources. */
|
|
56
|
+
close(): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=proof-of-work.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-of-work.d.ts","sourceRoot":"","sources":["../src/proof-of-work.ts"],"names":[],"mappings":"AAuFA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS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|
|
4
|
+
0x3956c25bu, 0x59f111f1u, 0x923f82a4u, 0xab1c5ed5u,
|
|
5
|
+
0xd807aa98u, 0x12835b01u, 0x243185beu, 0x550c7dc3u,
|
|
6
|
+
0x72be5d74u, 0x80deb1feu, 0x9bdc06a7u, 0xc19bf174u,
|
|
7
|
+
0xe49b69c1u, 0xefbe4786u, 0x0fc19dc6u, 0x240ca1ccu,
|
|
8
|
+
0x2de92c6fu, 0x4a7484aau, 0x5cb0a9dcu, 0x76f988dau,
|
|
9
|
+
0x983e5152u, 0xa831c66du, 0xb00327c8u, 0xbf597fc7u,
|
|
10
|
+
0xc6e00bf3u, 0xd5a79147u, 0x06ca6351u, 0x14292967u,
|
|
11
|
+
0x27b70a85u, 0x2e1b2138u, 0x4d2c6dfcu, 0x53380d13u,
|
|
12
|
+
0x650a7354u, 0x766a0abbu, 0x81c2c92eu, 0x92722c85u,
|
|
13
|
+
0xa2bfe8a1u, 0xa81a664bu, 0xc24b8b70u, 0xc76c51a3u,
|
|
14
|
+
0xd192e819u, 0xd6990624u, 0xf40e3585u, 0x106aa070u,
|
|
15
|
+
0x19a4c116u, 0x1e376c08u, 0x2748774cu, 0x34b0bcb5u,
|
|
16
|
+
0x391c0cb3u, 0x4ed8aa4au, 0x5b9cca4fu, 0x682e6ff3u,
|
|
17
|
+
0x748f82eeu, 0x78a5636fu, 0x84c87814u, 0x8cc70208u,
|
|
18
|
+
0x90befffau, 0xa4506cebu, 0xbef9a3f7u, 0xc67178f2u
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
struct Params { nonce_base : u32, difficulty : u32, _p0 : u32, _p1 : u32 }
|
|
22
|
+
struct TokenData { w : array<vec4<u32>, 2> }
|
|
23
|
+
struct Result { found : atomic<u32> }
|
|
24
|
+
|
|
25
|
+
@group(0) @binding(0) var<uniform> params : Params;
|
|
26
|
+
@group(0) @binding(1) var<uniform> tok : TokenData;
|
|
27
|
+
@group(0) @binding(2) var<storage, read_write> res : Result;
|
|
28
|
+
|
|
29
|
+
fn rotr(x : u32, n : u32) -> u32 { return (x >> n) | (x << (32u - n)); }
|
|
30
|
+
|
|
31
|
+
fn sha256_h0(nonce : u32) -> u32 {
|
|
32
|
+
var w : array<u32, 64>;
|
|
33
|
+
w[0] = tok.w[0].x; w[1] = tok.w[0].y; w[2] = tok.w[0].z; w[3] = tok.w[0].w;
|
|
34
|
+
w[4] = tok.w[1].x; w[5] = tok.w[1].y; w[6] = tok.w[1].z; w[7] = tok.w[1].w;
|
|
35
|
+
w[8] = nonce;
|
|
36
|
+
w[9] = 0x80000000u;
|
|
37
|
+
w[14] = 0u;
|
|
38
|
+
w[15] = 288u;
|
|
39
|
+
|
|
40
|
+
for (var i = 16u; i < 64u; i++) {
|
|
41
|
+
let s0 = rotr(w[i-15u], 7u) ^ rotr(w[i-15u], 18u) ^ (w[i-15u] >> 3u);
|
|
42
|
+
let s1 = rotr(w[i - 2u],17u) ^ rotr(w[i - 2u], 19u) ^ (w[i - 2u] >> 10u);
|
|
43
|
+
w[i] = w[i-16u] + s0 + w[i-7u] + s1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var a = 0x6a09e667u; var b = 0xbb67ae85u;
|
|
47
|
+
var c = 0x3c6ef372u; var d = 0xa54ff53au;
|
|
48
|
+
var e = 0x510e527fu; var f = 0x9b05688cu;
|
|
49
|
+
var g = 0x1f83d9abu; var h = 0x5be0cd19u;
|
|
50
|
+
|
|
51
|
+
for (var i = 0u; i < 64u; i++) {
|
|
52
|
+
let S1 = rotr(e, 6u) ^ rotr(e, 11u) ^ rotr(e, 25u);
|
|
53
|
+
let ch = (e & f) ^ (~e & g);
|
|
54
|
+
let t1 = h + S1 + ch + K[i] + w[i];
|
|
55
|
+
let S0 = rotr(a, 2u) ^ rotr(a, 13u) ^ rotr(a, 22u);
|
|
56
|
+
let maj = (a & b) ^ (a & c) ^ (b & c);
|
|
57
|
+
h = g; g = f; f = e; e = d + t1;
|
|
58
|
+
d = c; c = b; b = a; a = t1 + S0 + maj;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return 0x6a09e667u + a;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@compute @workgroup_size(256)
|
|
65
|
+
fn main(@builtin(global_invocation_id) gid : vec3<u32>) {
|
|
66
|
+
let nonce = params.nonce_base + gid.x;
|
|
67
|
+
let h0 = sha256_h0(nonce);
|
|
68
|
+
let shift = 32u - params.difficulty * 4u;
|
|
69
|
+
if ((h0 >> shift) == 0u) {
|
|
70
|
+
atomicMin(&res.found, nonce);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
function hexToTokenWords(hex) {
|
|
75
|
+
const u32 = new Uint32Array(8);
|
|
76
|
+
for (let i = 0; i < 8; i++)
|
|
77
|
+
u32[i] = parseInt(hex.slice(i * 8, i * 8 + 8), 16) >>> 0;
|
|
78
|
+
return u32.buffer;
|
|
79
|
+
}
|
|
80
|
+
function hexToBytes(hex) {
|
|
81
|
+
const bytes = new Uint8Array(32);
|
|
82
|
+
for (let i = 0; i < 32; i++)
|
|
83
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
84
|
+
return bytes;
|
|
85
|
+
}
|
|
86
|
+
export class ProofOfWork {
|
|
87
|
+
constructor(id, options = {}) {
|
|
88
|
+
this.expiration = null;
|
|
89
|
+
this._solving = false;
|
|
90
|
+
this.renewTimer = null;
|
|
91
|
+
this._gpu = null;
|
|
92
|
+
this._gpuSupported = null;
|
|
93
|
+
this.id = id;
|
|
94
|
+
this.onStatusChange = options.onStatusChange;
|
|
95
|
+
this.onRenew = options.onRenew;
|
|
96
|
+
}
|
|
97
|
+
static async _checkGpuSupport() {
|
|
98
|
+
try {
|
|
99
|
+
if (!navigator.gpu)
|
|
100
|
+
return false;
|
|
101
|
+
return !!(await navigator.gpu.requestAdapter());
|
|
102
|
+
}
|
|
103
|
+
catch (_a) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async _initGpu() {
|
|
108
|
+
if (this._gpu !== null)
|
|
109
|
+
return this._gpu;
|
|
110
|
+
try {
|
|
111
|
+
const adapter = await navigator.gpu.requestAdapter();
|
|
112
|
+
if (!adapter) {
|
|
113
|
+
this._gpu = false;
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const device = await adapter.requestDevice();
|
|
117
|
+
device.lost.then(() => { this._gpu = null; });
|
|
118
|
+
const shaderModule = device.createShaderModule({ code: SHADER_CODE });
|
|
119
|
+
const info = await shaderModule.getCompilationInfo();
|
|
120
|
+
if (info.messages.some((m) => m.type === "error")) {
|
|
121
|
+
console.warn("PoW WGSL errors:", info.messages);
|
|
122
|
+
this._gpu = false;
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const pipeline = await device.createComputePipelineAsync({
|
|
126
|
+
layout: "auto",
|
|
127
|
+
compute: { module: shaderModule, entryPoint: "main" },
|
|
128
|
+
});
|
|
129
|
+
const U = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
|
|
130
|
+
const S = GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
|
|
131
|
+
const R = GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST;
|
|
132
|
+
const paramsBuf = device.createBuffer({ size: 16, usage: U });
|
|
133
|
+
const tokenBuf = device.createBuffer({ size: 32, usage: U });
|
|
134
|
+
const resultBuf = device.createBuffer({ size: 16, usage: S });
|
|
135
|
+
const stagingBuf = device.createBuffer({ size: 4, usage: R });
|
|
136
|
+
const bindGroup = device.createBindGroup({
|
|
137
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
138
|
+
entries: [
|
|
139
|
+
{ binding: 0, resource: { buffer: paramsBuf } },
|
|
140
|
+
{ binding: 1, resource: { buffer: tokenBuf } },
|
|
141
|
+
{ binding: 2, resource: { buffer: resultBuf } },
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
this._gpu = { device, pipeline, bindGroup, paramsBuf, tokenBuf, resultBuf, stagingBuf };
|
|
145
|
+
return this._gpu;
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
console.warn("WebGPU init failed, using CPU fallback:", e);
|
|
149
|
+
this._gpu = false;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async _solveGpu(tokenHex, difficulty) {
|
|
154
|
+
const gpu = await this._initGpu();
|
|
155
|
+
if (!gpu)
|
|
156
|
+
return null;
|
|
157
|
+
const { device, pipeline, bindGroup, paramsBuf, tokenBuf, resultBuf, stagingBuf } = gpu;
|
|
158
|
+
const NOT_FOUND = 0xffffffff;
|
|
159
|
+
const WORKGROUPS = 4096;
|
|
160
|
+
const BATCH = WORKGROUPS * 256;
|
|
161
|
+
try {
|
|
162
|
+
device.queue.writeBuffer(tokenBuf, 0, hexToTokenWords(tokenHex));
|
|
163
|
+
for (let base = 0; base + BATCH <= NOT_FOUND; base += BATCH) {
|
|
164
|
+
device.queue.writeBuffer(paramsBuf, 0, new Uint32Array([base, difficulty, 0, 0]));
|
|
165
|
+
device.queue.writeBuffer(resultBuf, 0, new Uint32Array([NOT_FOUND, 0, 0, 0]));
|
|
166
|
+
const enc = device.createCommandEncoder();
|
|
167
|
+
const pass = enc.beginComputePass();
|
|
168
|
+
pass.setPipeline(pipeline);
|
|
169
|
+
pass.setBindGroup(0, bindGroup);
|
|
170
|
+
pass.dispatchWorkgroups(WORKGROUPS);
|
|
171
|
+
pass.end();
|
|
172
|
+
enc.copyBufferToBuffer(resultBuf, 0, stagingBuf, 0, 4);
|
|
173
|
+
device.queue.submit([enc.finish()]);
|
|
174
|
+
await stagingBuf.mapAsync(GPUMapMode.READ, 0, 4);
|
|
175
|
+
const found = new Uint32Array(stagingBuf.getMappedRange(0, 4))[0];
|
|
176
|
+
stagingBuf.unmap();
|
|
177
|
+
if (found !== NOT_FOUND)
|
|
178
|
+
return found || null;
|
|
179
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
console.warn("GPU solve error, falling back to CPU:", e);
|
|
185
|
+
this._gpu = null;
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async _solveCpu(tokenHex, difficulty) {
|
|
190
|
+
const prefix = "0".repeat(difficulty);
|
|
191
|
+
const tokenBytes = hexToBytes(tokenHex);
|
|
192
|
+
const input = new Uint8Array(36);
|
|
193
|
+
input.set(tokenBytes);
|
|
194
|
+
for (let nonce = 0; nonce <= 0xffffffff; nonce++) {
|
|
195
|
+
input[32] = (nonce >>> 24) & 0xff;
|
|
196
|
+
input[33] = (nonce >>> 16) & 0xff;
|
|
197
|
+
input[34] = (nonce >>> 8) & 0xff;
|
|
198
|
+
input[35] = nonce & 0xff;
|
|
199
|
+
const buf = await crypto.subtle.digest("SHA-256", input);
|
|
200
|
+
const hex = [...new Uint8Array(buf)]
|
|
201
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
202
|
+
.join("");
|
|
203
|
+
if (hex.startsWith(prefix))
|
|
204
|
+
return nonce;
|
|
205
|
+
if (nonce > 0 && nonce % 5000 === 0)
|
|
206
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
207
|
+
}
|
|
208
|
+
throw new Error("Nonce space exhausted");
|
|
209
|
+
}
|
|
210
|
+
_setStatus(status) {
|
|
211
|
+
var _a;
|
|
212
|
+
(_a = this.onStatusChange) === null || _a === void 0 ? void 0 : _a.call(this, status);
|
|
213
|
+
}
|
|
214
|
+
async _requestChallenge(email) {
|
|
215
|
+
const res = await fetch(`https://group.sendlix.com/${this.id}/pow`, {
|
|
216
|
+
method: "POST",
|
|
217
|
+
headers: { "Content-Type": "application/json" },
|
|
218
|
+
body: JSON.stringify({ email }),
|
|
219
|
+
});
|
|
220
|
+
if (!res.ok)
|
|
221
|
+
throw new Error(`Challenge request failed: ${res.status}`);
|
|
222
|
+
return res.json();
|
|
223
|
+
}
|
|
224
|
+
_scheduleRenew(email) {
|
|
225
|
+
if (this.renewTimer)
|
|
226
|
+
clearTimeout(this.renewTimer);
|
|
227
|
+
const now = Math.floor(Date.now() / 1000);
|
|
228
|
+
const renewIn = Math.max((this.expiration - now - 60) * 1000, 0);
|
|
229
|
+
this.renewTimer = setTimeout(() => void this._renewInternal(email), renewIn);
|
|
230
|
+
}
|
|
231
|
+
async _renewInternal(email) {
|
|
232
|
+
var _a;
|
|
233
|
+
if (this._solving)
|
|
234
|
+
return;
|
|
235
|
+
try {
|
|
236
|
+
const result = await this._solveInternal(email, true);
|
|
237
|
+
this._scheduleRenew(email);
|
|
238
|
+
(_a = this.onRenew) === null || _a === void 0 ? void 0 : _a.call(this, result);
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
console.error("PoW renewal error:", err);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async _solveInternal(email, isRenew = false) {
|
|
245
|
+
this._solving = true;
|
|
246
|
+
this._setStatus(isRenew ? "processing" : "loading");
|
|
247
|
+
try {
|
|
248
|
+
if (this._gpuSupported === null) {
|
|
249
|
+
this._gpuSupported = await ProofOfWork._checkGpuSupport();
|
|
250
|
+
}
|
|
251
|
+
const { token, expiration, difficulty } = await this._requestChallenge(email);
|
|
252
|
+
this.expiration = expiration;
|
|
253
|
+
let nonce = null;
|
|
254
|
+
if (this._gpuSupported) {
|
|
255
|
+
nonce = await this._solveGpu(token, difficulty);
|
|
256
|
+
}
|
|
257
|
+
if (nonce === null) {
|
|
258
|
+
nonce = await this._solveCpu(token, difficulty);
|
|
259
|
+
}
|
|
260
|
+
this._setStatus("success");
|
|
261
|
+
return { token, nonce: nonce.toString() };
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
this._setStatus("error");
|
|
265
|
+
throw err;
|
|
266
|
+
}
|
|
267
|
+
finally {
|
|
268
|
+
this._solving = false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Solves the Proof-of-Work challenge for the given email address.
|
|
273
|
+
* Returns `{ token, nonce }` which must be submitted alongside the form.
|
|
274
|
+
* Automatically schedules a silent token renewal before expiry.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const pow = new ProofOfWork(groupId);
|
|
279
|
+
* const { token, nonce } = await pow.solve("user@example.com");
|
|
280
|
+
* await subscribeToGroup({ id: groupId, email, botProtection: { type: "proofOfWork", token, nonce } });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
async solve(email) {
|
|
284
|
+
if (!email || !email.includes("@")) {
|
|
285
|
+
throw new Error("Invalid email address");
|
|
286
|
+
}
|
|
287
|
+
const result = await this._solveInternal(email);
|
|
288
|
+
this._scheduleRenew(email);
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Pre-warms the WebGPU pipeline so the first `solve()` call is faster.
|
|
293
|
+
* Safe to call on component mount; does nothing if WebGPU is unavailable.
|
|
294
|
+
*/
|
|
295
|
+
init() {
|
|
296
|
+
if (typeof navigator !== "undefined" && navigator.gpu) {
|
|
297
|
+
this._initGpu().catch(() => { });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/** Cancels any pending renewal timer and releases GPU resources. */
|
|
301
|
+
close() {
|
|
302
|
+
if (this.renewTimer)
|
|
303
|
+
clearTimeout(this.renewTimer);
|
|
304
|
+
this.renewTimer = null;
|
|
305
|
+
this._gpu = null;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=proof-of-work.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-of-work.js","sourceRoot":"","sources":["../src/proof-of-work.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAK,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACzB,MAAM,GAAG,CAAC;QACd,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAC1B,CAAC;IACL,CAAC;IAID;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,KAAK,CAAC,KAAa;QACrB,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAChD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,IAAI;QACA,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC;YACpD,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;IAED,oEAAoE;IACpE,KAAK;QACD,IAAI,IAAI,CAAC,UAAU;YAAE,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Appearance = {
|
|
2
|
+
primaryColor?: string;
|
|
3
|
+
backgroundColor?: string;
|
|
4
|
+
hoverColor?: string;
|
|
5
|
+
textColor?: string;
|
|
6
|
+
info?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
};
|
|
9
|
+
interface Props extends React.IframeHTMLAttributes<HTMLIFrameElement> {
|
|
10
|
+
id: string;
|
|
11
|
+
appearance?: Appearance;
|
|
12
|
+
startHeight?: number;
|
|
13
|
+
}
|
|
14
|
+
declare const GroupIframe: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<HTMLIFrameElement>>;
|
|
15
|
+
export default GroupIframe;
|
|
16
|
+
//# sourceMappingURL=GroupIframe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroupIframe.d.ts","sourceRoot":"","sources":["../../src/react/GroupIframe.tsx"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,UAAU,KAAM,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACjE,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,WAAW,qGAgDhB,CAAC;AAIF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
14
|
+
const GroupIframe = forwardRef(function GroupIframe(_a, forwardedRef) {
|
|
15
|
+
var { id, appearance, startHeight } = _a, rest = __rest(_a, ["id", "appearance", "startHeight"]);
|
|
16
|
+
const [height, setHeight] = useState(startHeight !== null && startHeight !== void 0 ? startHeight : 500);
|
|
17
|
+
const internalRef = useRef(null);
|
|
18
|
+
const setRef = (el) => {
|
|
19
|
+
internalRef.current = el;
|
|
20
|
+
if (typeof forwardedRef === "function")
|
|
21
|
+
forwardedRef(el);
|
|
22
|
+
else if (forwardedRef)
|
|
23
|
+
forwardedRef.current = el;
|
|
24
|
+
};
|
|
25
|
+
const queryParams = useMemo(() => {
|
|
26
|
+
const params = new URLSearchParams();
|
|
27
|
+
if (appearance) {
|
|
28
|
+
if (appearance.primaryColor)
|
|
29
|
+
params.append("primaryColor", appearance.primaryColor);
|
|
30
|
+
if (appearance.backgroundColor)
|
|
31
|
+
params.append("backgroundColor", appearance.backgroundColor);
|
|
32
|
+
if (appearance.hoverColor)
|
|
33
|
+
params.append("hoverColor", appearance.hoverColor);
|
|
34
|
+
if (appearance.textColor)
|
|
35
|
+
params.append("textColor", appearance.textColor);
|
|
36
|
+
if (appearance.info)
|
|
37
|
+
params.append("info", appearance.info);
|
|
38
|
+
if (appearance.name)
|
|
39
|
+
params.append("name", appearance.name);
|
|
40
|
+
}
|
|
41
|
+
return params.toString();
|
|
42
|
+
}, [appearance]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const handleMessage = (event) => {
|
|
45
|
+
if (event.origin !== "https://group.sendlix.com")
|
|
46
|
+
return;
|
|
47
|
+
const data = event.data;
|
|
48
|
+
if ((data === null || data === void 0 ? void 0 : data.type) === "formResized" && typeof data.height === "number") {
|
|
49
|
+
setHeight(data.height);
|
|
50
|
+
if (internalRef.current) {
|
|
51
|
+
internalRef.current.style.height = `${data.height + 7}px`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
window.addEventListener("message", handleMessage);
|
|
56
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
57
|
+
}, []);
|
|
58
|
+
return (_jsx("iframe", Object.assign({}, rest, { src: `https://group.sendlix.com/${id}?${queryParams}`, height: height, ref: setRef })));
|
|
59
|
+
});
|
|
60
|
+
GroupIframe.displayName = "GroupIframe";
|
|
61
|
+
export default GroupIframe;
|
|
62
|
+
//# sourceMappingURL=GroupIframe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroupIframe.js","sourceRoot":"","sources":["../../src/react/GroupIframe.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAiBzE,MAAM,WAAW,GAAG,UAAU,CAC1B,SAAS,WAAW,CAAC,EAAwC,EAAE,YAAY;QAAtD,EAAE,EAAE,EAAE,UAAU,EAAE,WAAW,OAAW,EAAN,IAAI,cAAtC,mCAAwC,CAAF;IACvD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAG,CAAC,EAA4B,EAAE,EAAE;QAC5C,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QACzB,IAAI,OAAO,YAAY,KAAK,UAAU;YAAE,YAAY,CAAC,EAAE,CAAC,CAAC;aACpD,IAAI,YAAY;YAAE,YAAY,CAAC,OAAO,GAAG,EAAE,CAAC;IACrD,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EA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,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC;gBAC9D,CAAC;YACL,CAAC;QACL,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAClD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACtE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACH,iCACQ,IAAI,IACR,GAAG,EAAE,6BAA6B,EAAE,IAAI,WAAW,EAAE,EACrD,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,IACb,CACL,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC;AAExC,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type PowOptions } from "../proof-of-work";
|
|
2
|
+
interface ProofOfWorkInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
3
|
+
sendlix: {
|
|
4
|
+
id: string;
|
|
5
|
+
onStatusChange?: PowOptions["onStatusChange"];
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
declare const ProofOfWorkInput: import("react").ForwardRefExoticComponent<ProofOfWorkInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
9
|
+
export default ProofOfWorkInput;
|
|
10
|
+
//# sourceMappingURL=ProofOfWorkInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProofOfWorkInput.d.ts","sourceRoot":"","sources":["../../src/react/ProofOfWorkInput.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEhE,UAAU,qBAAsB,SAAQ,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC;IAC/E,OAAO,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,cAAc,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;KACjD,CAAC;CACL;AAED,QAAA,MAAM,gBAAgB,oHA4FrB,CAAC;AAIF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef, useEffect, useRef, useState } from "react";
|
|
14
|
+
import { ProofOfWork } from "../proof-of-work";
|
|
15
|
+
const ProofOfWorkInput = forwardRef(function ProofOfWorkInput(_a, forwardedRef) {
|
|
16
|
+
var { sendlix, onBlur, onChange } = _a, rest = __rest(_a, ["sendlix", "onBlur", "onChange"]);
|
|
17
|
+
const [nonce, setNonce] = useState(null);
|
|
18
|
+
const [token, setToken] = useState(null);
|
|
19
|
+
const [email, setEmail] = useState("");
|
|
20
|
+
const powRef = useRef(null);
|
|
21
|
+
const internalRef = useRef(null);
|
|
22
|
+
const lastEmailRef = useRef(null);
|
|
23
|
+
const setRef = (el) => {
|
|
24
|
+
internalRef.current = el;
|
|
25
|
+
if (typeof forwardedRef === "function")
|
|
26
|
+
forwardedRef(el);
|
|
27
|
+
else if (forwardedRef)
|
|
28
|
+
forwardedRef.current = el;
|
|
29
|
+
};
|
|
30
|
+
// Clean up when the component unmounts
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
return () => { var _a; (_a = powRef.current) === null || _a === void 0 ? void 0 : _a.close(); };
|
|
33
|
+
}, []);
|
|
34
|
+
// Cancel renewal when the parent form is submitted
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
var _a;
|
|
37
|
+
const form = (_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.form;
|
|
38
|
+
if (!form)
|
|
39
|
+
return;
|
|
40
|
+
const handleSubmit = () => { var _a; return (_a = powRef.current) === null || _a === void 0 ? void 0 : _a.close(); };
|
|
41
|
+
form.addEventListener("submit", handleSubmit);
|
|
42
|
+
return () => form.removeEventListener("submit", handleSubmit);
|
|
43
|
+
}, []);
|
|
44
|
+
const handleBlur = (e) => {
|
|
45
|
+
var _a;
|
|
46
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
47
|
+
if (!email || !/\S+@\S+\.\S+/.test(email))
|
|
48
|
+
return;
|
|
49
|
+
// Skip if the email hasn't changed and we already have a valid token
|
|
50
|
+
if (email === lastEmailRef.current && nonce && token)
|
|
51
|
+
return;
|
|
52
|
+
(_a = powRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
53
|
+
powRef.current = null;
|
|
54
|
+
lastEmailRef.current = email;
|
|
55
|
+
setNonce(null);
|
|
56
|
+
setToken(null);
|
|
57
|
+
const pow = new ProofOfWork(sendlix.id, Object.assign(Object.assign({}, (sendlix.onStatusChange && { onStatusChange: sendlix.onStatusChange })), { onRenew: (result) => {
|
|
58
|
+
setToken(result.token);
|
|
59
|
+
setNonce(result.nonce);
|
|
60
|
+
} }));
|
|
61
|
+
powRef.current = pow;
|
|
62
|
+
pow.init();
|
|
63
|
+
pow.solve(email).then((result) => {
|
|
64
|
+
setToken(result.token);
|
|
65
|
+
setNonce(result.nonce);
|
|
66
|
+
}).catch((error) => {
|
|
67
|
+
console.error("Proof of Work error:", error);
|
|
68
|
+
setNonce(null);
|
|
69
|
+
setToken(null);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const handleChange = (e) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const newEmail = e.target.value;
|
|
75
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
76
|
+
setEmail(newEmail);
|
|
77
|
+
// Invalidate token/nonce when the email changes
|
|
78
|
+
if (newEmail !== lastEmailRef.current && (nonce || token)) {
|
|
79
|
+
(_a = powRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
80
|
+
powRef.current = null;
|
|
81
|
+
setNonce(null);
|
|
82
|
+
setToken(null);
|
|
83
|
+
lastEmailRef.current = null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", Object.assign({ type: "email" }, rest, { ref: setRef, value: email, onChange: handleChange, onBlur: handleBlur })), _jsx("input", { name: "pow-nonce", type: "hidden", value: nonce !== null && nonce !== void 0 ? nonce : "", readOnly: true }), _jsx("input", { name: "pow-token", type: "hidden", value: token !== null && token !== void 0 ? token : "", readOnly: true })] }));
|
|
87
|
+
});
|
|
88
|
+
ProofOfWorkInput.displayName = "ProofOfWorkInput";
|
|
89
|
+
export default ProofOfWorkInput;
|
|
90
|
+
//# sourceMappingURL=ProofOfWorkInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProofOfWorkInput.js","sourceRoot":"","sources":["../../src/react/ProofOfWorkInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,WAAW,EAAmB,MAAM,kBAAkB,CAAC;AAShE,MAAM,gBAAgB,GAAG,UAAU,CAC/B,SAAS,gBAAgB,CAAC,EAAsC,EAAE,YAAY;QAApD,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,OAAW,EAAN,IAAI,cAApC,iCAAsC,CAAF;IA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B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const responseMessages: {
|
|
2
|
+
readonly 0: "Email added to group";
|
|
3
|
+
readonly 1: "Email already in group";
|
|
4
|
+
readonly 2: "Invalid email address";
|
|
5
|
+
readonly 3: "Please fill in all fields";
|
|
6
|
+
readonly 4: "CAPTCHA verification failed";
|
|
7
|
+
readonly 5: "Error checking email";
|
|
8
|
+
readonly 6: "Error inserting email";
|
|
9
|
+
readonly 7: "Please complete the CAPTCHA";
|
|
10
|
+
readonly 8: "Not Found";
|
|
11
|
+
};
|
|
12
|
+
export type GroupResponse = {
|
|
13
|
+
success: boolean;
|
|
14
|
+
message: (typeof responseMessages)[keyof typeof responseMessages];
|
|
15
|
+
code: keyof typeof responseMessages;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;CAUnB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;IAClE,IAAI,EAAE,MAAM,OAAO,gBAAgB,CAAC;CACvC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const responseMessages = {
|
|
2
|
+
0: "Email added to group",
|
|
3
|
+
1: "Email already in group",
|
|
4
|
+
2: "Invalid email address",
|
|
5
|
+
3: "Please fill in all fields",
|
|
6
|
+
4: "CAPTCHA verification failed",
|
|
7
|
+
5: "Error checking email",
|
|
8
|
+
6: "Error inserting email",
|
|
9
|
+
7: "Please complete the CAPTCHA",
|
|
10
|
+
8: "Not Found",
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,CAAC,EAAE,sBAAsB;IACzB,CAAC,EAAE,wBAAwB;IAC3B,CAAC,EAAE,uBAAuB;IAC1B,CAAC,EAAE,2BAA2B;IAC9B,CAAC,EAAE,6BAA6B;IAChC,CAAC,EAAE,sBAAsB;IACzB,CAAC,EAAE,uBAAuB;IAC1B,CAAC,EAAE,6BAA6B;IAChC,CAAC,EAAE,WAAW;CACR,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAY1D"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a placeholder string (e.g. "##First Name##") into a valid
|
|
3
|
+
* JavaScript / form-field variable name (e.g. "FirstName").
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export function toValidVarName(placeholder) {
|
|
7
|
+
let varName = placeholder
|
|
8
|
+
.replace(/^#+|#+$/g, "") // Remove leading/trailing #
|
|
9
|
+
.replace(/[^a-zA-Z0-9_]/g, "_") // Replace invalid chars with _
|
|
10
|
+
.replace(/_+/g, "_") // Collapse multiple underscores
|
|
11
|
+
.replace(/^_|_$/g, ""); // Remove leading/trailing _
|
|
12
|
+
if (/^[0-9]/.test(varName)) {
|
|
13
|
+
varName = "_" + varName;
|
|
14
|
+
}
|
|
15
|
+
return varName || "param";
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,WAAmB;IAC9C,IAAI,OAAO,GAAG,WAAW;SACpB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAI,4BAA4B;SACvD,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,+BAA+B;SAC9D,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAY,gCAAgC;SAC/D,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAS,4BAA4B;IAEhE,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,GAAG,GAAG,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,OAAO,OAAO,IAAI,OAAO,CAAC;AAC9B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sendlix/group",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Sendlix Group SDK – subscribe users to mailing groups with optional Proof-of-Work bot protection.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/sendlix/group-subscription-sdk.git"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./ct": {
|
|
21
|
+
"import": "./dist/react/index.js",
|
|
22
|
+
"types": "./dist/react/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"sendlix",
|
|
30
|
+
"newsletter",
|
|
31
|
+
"mailing",
|
|
32
|
+
"group",
|
|
33
|
+
"subscribe",
|
|
34
|
+
"proof-of-work",
|
|
35
|
+
"spam-protection",
|
|
36
|
+
"react"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"test": "jest --forceExit",
|
|
44
|
+
"test:watch": "jest --watch",
|
|
45
|
+
"release": "semantic-release"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": ">=18"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
52
|
+
"@semantic-release/git": "^10.0.1",
|
|
53
|
+
"@types/jest": "^30.0.0",
|
|
54
|
+
"@types/react": "^19.2.14",
|
|
55
|
+
"@webgpu/types": "^0.1.69",
|
|
56
|
+
"jest": "^30.3.0",
|
|
57
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
58
|
+
"react": "^19.2.4",
|
|
59
|
+
"semantic-release": "^25.0.3",
|
|
60
|
+
"ts-jest": "^29.4.6",
|
|
61
|
+
"typescript": "^5.9.3"
|
|
62
|
+
}
|
|
63
|
+
}
|