@mailto.foo/sdk 1.0.0
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 +43 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
# @mailto.foo/sdk
|
|
3
|
+
|
|
4
|
+
The JavaScript SDK for mailto.foo — a headless email subscription and contact form service. Drop it in via script tag or npm, hand it your publish key, and it handles bot protection and delivers only verified submissions to your dashboard.
|
|
5
|
+
|
|
6
|
+
No backend code required on your end.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
``` bash
|
|
11
|
+
npm install @mailto.foo/sdk
|
|
12
|
+
```
|
|
13
|
+
Or via CDN (no npm needed):
|
|
14
|
+
``` html
|
|
15
|
+
<script src="https://cdn.mailto.foo/sdk.js"></script>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
### npm / ESM
|
|
20
|
+
|
|
21
|
+
``` js
|
|
22
|
+
import { MailtoWidget } from '@mailto.foo/sdk'
|
|
23
|
+
|
|
24
|
+
MailtoWidget.init('pk_your_publish_key')
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Script tag
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
<script
|
|
31
|
+
src="https://cdn.mailto.foo/sdk.js"
|
|
32
|
+
data-key="pk_your_publish_key"
|
|
33
|
+
></script>
|
|
34
|
+
```
|
|
35
|
+
That's it. The widget mounts, renders the bot protection challenge, and submits emails to your dashboard automatically.
|
|
36
|
+
|
|
37
|
+
### Publish Key
|
|
38
|
+
|
|
39
|
+
Your publish key (`pk_xxx`) is tied to your mailto.foo account and the domain you registered. It is safe to expose in frontend code — it only allows submissions, not reads.
|
|
40
|
+
Get your publish key from your mailto.foo dashboard.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
MIT
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Cap from "@cap.js/widget";
|
|
2
|
+
const getToken = () => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const cap = new Cap({
|
|
5
|
+
apiEndpoint: "https://captcha.mailto.foo/api/",
|
|
6
|
+
});
|
|
7
|
+
cap.solve()
|
|
8
|
+
.then((result) => {
|
|
9
|
+
cap.reset();
|
|
10
|
+
resolve(result.token);
|
|
11
|
+
})
|
|
12
|
+
.catch(reject);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export const Mailto = {
|
|
16
|
+
subscribe: async (email) => {
|
|
17
|
+
const token = await getToken();
|
|
18
|
+
const res = await fetch("https://api.mailto.foo/subscribe", {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/json" },
|
|
21
|
+
body: JSON.stringify({ email, token }),
|
|
22
|
+
});
|
|
23
|
+
if (!res.ok) {
|
|
24
|
+
throw new Error("Subscription failed");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,gBAAgB,CAAC;AAEjC,MAAM,QAAQ,GAAG,GAAoB,EAAE;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,GAAG,GAAG,IAAK,GAAW,CAAC;YAC3B,WAAW,EAAE,iCAAiC;SAC/C,CAAC,CAAC;QAEH,GAAG,CAAC,KAAK,EAAE;aACR,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE;YACpB,GAAG,CAAC,KAAK,EAAE,CAAC;YACZ,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC;aACD,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,SAAS,EAAE,KAAK,EAAE,KAAa,EAAiB,EAAE;QAChD,MAAM,KAAK,GAAG,MAAM,QAAQ,EAAE,CAAC;QAE/B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,kCAAkC,EAAE;YAC1D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;SACvC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mailto.foo/sdk",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Headless email subscription and contact form SDK for mailto.foo",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://gitlab.com/mailto.foo/sdk.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://gitlab.com/mailto.foo/sdk.git",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**/*"
|
|
15
|
+
],
|
|
16
|
+
"author": "saikksub<saikksub@gmail.com>",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@biomejs/biome": "1.8.3",
|
|
20
|
+
"@changesets/cli": "^2.27.7",
|
|
21
|
+
"@total-typescript/tsconfig": "^1.0.4",
|
|
22
|
+
"typescript": "^5.5.3"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://gitlab.com/mailto.foo/sdk/-/boards"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@cap.js/widget": "^0.1.53"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"check": "biome check --write ./src",
|
|
33
|
+
"workflow:check": "biome check ./src",
|
|
34
|
+
"release": "pnpm run build && changeset publish"
|
|
35
|
+
}
|
|
36
|
+
}
|