telesink 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.
Files changed (4) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +93 -0
  3. package/index.js +69 -0
  4. package/package.json +31 -0
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ # The MIT License
2
+
3
+ Copyright © 2026 Telesink
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the 'Software'), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # Telesink SDK for JavaScript
2
+
3
+ **Know what your product is doing. Right now.**
4
+
5
+ Official JavaScript client for [telesink.com](https://telesink.com) - real-time
6
+ event tracking.
7
+
8
+ ## Requirements
9
+
10
+ - Node.js 18+
11
+ - Any modern browser (with native `fetch` and `AbortController`)
12
+
13
+ ## Getting started
14
+
15
+ ### Install
16
+
17
+ ```sh
18
+ npm install telesink
19
+ ```
20
+
21
+ ### Configuration
22
+
23
+ #### Node.js
24
+
25
+ Set the environment variable:
26
+
27
+ ```sh
28
+ export TELESINK_ENDPOINT=https://app.telesink.com/api/v1/sinks/your_sink_token_here/events
29
+ ```
30
+
31
+ #### Browsers
32
+
33
+ ```sh
34
+ window.TELESINK_ENDPOINT = "https://app.telesink.com/api/v1/sinks/your_sink_token_here/events";
35
+ ```
36
+
37
+ To disable tracking (e.g. in test/dev):
38
+
39
+ ```sh
40
+ export TELESINK_DISABLED=true
41
+ ```
42
+
43
+ (or `window.TELESINK_DISABLED = true` in the browser)
44
+
45
+ ### Usage
46
+
47
+ #### Node.js and modern bundlers
48
+
49
+ ```js
50
+ import telesink from "telesink";
51
+
52
+ telesink.track({
53
+ event: "user.signed.up",
54
+ text: "user@example.com",
55
+ emoji: "👤",
56
+ properties: {
57
+ user_id: 123,
58
+ email_address: "user@example.com",
59
+ },
60
+ occurredAt: new Date(),
61
+ idempotencyKey: "my-key",
62
+ });
63
+ ```
64
+
65
+ #### Browser without bundler (Import Maps)
66
+
67
+ ```html
68
+ <script type="importmap">
69
+ {
70
+ "imports": {
71
+ "telesink": "https://esm.sh/telesink"
72
+ }
73
+ }
74
+ </script>
75
+
76
+ <script type="module">
77
+ import telesink from "telesink";
78
+
79
+ telesink.track({
80
+ event: "page.viewed",
81
+ text: "Homepage visited",
82
+ });
83
+ </script>
84
+ ```
85
+
86
+ #### Returns
87
+
88
+ - `true` — event sent successfully
89
+ - `false` — disabled, missing endpoint, or network error
90
+
91
+ ### License
92
+
93
+ MIT (see [LICENSE.md](/LICENSE.md)).
package/index.js ADDED
@@ -0,0 +1,69 @@
1
+ const VERSION = "1.0.0";
2
+
3
+ const endpoint = () => {
4
+ if (typeof process !== "undefined") return process.env?.TELESINK_ENDPOINT;
5
+ if (typeof window !== "undefined") return window.TELESINK_ENDPOINT;
6
+ return null;
7
+ };
8
+
9
+ const enabled = () => {
10
+ if (typeof process !== "undefined") return !process.env?.TELESINK_DISABLED;
11
+ if (typeof window !== "undefined") return !window.TELESINK_DISABLED;
12
+ return true;
13
+ };
14
+
15
+ const uuid = () =>
16
+ typeof crypto !== "undefined" && crypto.randomUUID
17
+ ? crypto.randomUUID()
18
+ : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
19
+ const r = (Math.random() * 16) | 0;
20
+ return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
21
+ });
22
+
23
+ const track = async ({
24
+ event,
25
+ text,
26
+ emoji,
27
+ properties = {},
28
+ occurredAt,
29
+ idempotencyKey,
30
+ } = {}) => {
31
+ if (!enabled() || !endpoint()) return false;
32
+
33
+ const payload = Object.fromEntries(
34
+ Object.entries({
35
+ event,
36
+ text,
37
+ emoji,
38
+ properties,
39
+ occurred_at: new Date(occurredAt ?? Date.now()).toISOString(),
40
+ idempotency_key: idempotencyKey ?? uuid(),
41
+ sdk: { name: "telesink", version: VERSION },
42
+ }).filter(([, v]) => v != null),
43
+ );
44
+
45
+ const controller = new AbortController();
46
+ const timeout = setTimeout(() => controller.abort(), 3000);
47
+
48
+ try {
49
+ const res = await fetch(endpoint(), {
50
+ method: "POST",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "User-Agent": `telesink/${VERSION}`,
54
+ "Idempotency-Key": payload.idempotency_key,
55
+ },
56
+ body: JSON.stringify(payload),
57
+ signal: controller.signal,
58
+ });
59
+ return res.ok;
60
+ } catch (e) {
61
+ console.error(`[Telesink] ${e.constructor.name}: ${e.message}`);
62
+ return false;
63
+ } finally {
64
+ clearTimeout(timeout);
65
+ }
66
+ };
67
+
68
+ export { track };
69
+ export default { track };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "telesink",
3
+ "version": "1.0.0",
4
+ "description": "Official JavaScript SDK for Telesink — real-time event tracking",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.js"
8
+ },
9
+ "files": [
10
+ "index.js"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/telesink/telesink-javascript.git"
15
+ },
16
+ "keywords": [
17
+ "telesink",
18
+ "event-tracking",
19
+ "analytics",
20
+ "real-time",
21
+ "monitoring",
22
+ "notifications",
23
+ "sdk"
24
+ ],
25
+ "author": "Kyrylo Silin",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/telesink/telesink-javascript/issues"
29
+ },
30
+ "homepage": "https://github.com/telesink/telesink-javascript#readme"
31
+ }