tockward 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tockward
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # tockward
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Heartbeat client for **[Tockward](https://tockward.com)**: know when your cron jobs, scripts and devices go silent.
4
+
5
+ Your job reports in each time it runs. If a report doesn't arrive on time, Tockward alerts you by email or Telegram.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install -g tockward # Node 18+
11
+ pip install tockward # Python 3.8+
12
+ ```
13
+
14
+ Both give you the same `tockward` command. No dependencies.
15
+
16
+ ## Command line
17
+
18
+ ```sh
19
+ tockward ping <token> # report a successful run
20
+ tockward fail <token> # report a failed run
21
+ tockward run <token> -- ./backup.sh # run a command, then report success or failure
22
+ ```
23
+
24
+ `tockward run` passes the command's output through, sends its duration along, and exits
25
+ with the command's own exit code, so it drops straight into a crontab:
26
+
27
+ ```cron
28
+ 0 3 * * * tockward run abc123 -- /usr/local/bin/backup.sh
29
+ ```
30
+
31
+ `<token>` is the monitor's token, or its full ping URL copied from the dashboard.
32
+
33
+ ## In code
34
+
35
+ ```js
36
+ const tockward = require('tockward');
37
+ await tockward.ping('abc123');
38
+ await tockward.fail('abc123');
39
+ ```
40
+
41
+ ```python
42
+ import tockward
43
+ tockward.ping("abc123")
44
+ tockward.fail("abc123")
45
+ ```
46
+
47
+ Delivery is retried twice with a 10-second timeout per attempt; an unknown token fails at once.
48
+
49
+ ## Without this package
50
+
51
+ It's just an HTTP request, so `curl` works too:
52
+
53
+ ```sh
54
+ curl -fsS https://ping.tockward.com/v1/beat/<token> # success
55
+ curl -fsS https://ping.tockward.com/v1/beat/<token>/fail # failure
56
+ ```
57
+
58
+ ## Settings
59
+
60
+ | Variable | Default | Meaning |
61
+ |---|---|---|
62
+ | `TOCKWARD_URL` | `https://ping.tockward.com` | server to report to |
63
+
64
+ ## License
65
+
66
+ MIT. Questions: support@tockward.com
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const { spawn } = require('child_process');
4
+ const { ping, fail } = require('..');
5
+ const { version } = require('../package.json');
6
+
7
+ const USAGE = `Tockward: know when your cron jobs, scripts and devices go silent.
8
+
9
+ Usage:
10
+ tockward ping <token> report a successful run
11
+ tockward fail <token> report a failed run
12
+ tockward run <token> -- <command> run a command, then report success or
13
+ failure (with its duration); exits with
14
+ the command's exit code
15
+
16
+ <token> is the monitor's token or its full ping URL.
17
+ Set TOCKWARD_URL to use another server. https://tockward.com`;
18
+
19
+ const warn = msg => process.stderr.write(`tockward: ${msg}\n`);
20
+
21
+ async function main(argv) {
22
+ const [cmd, token, ...rest] = argv;
23
+ if (!cmd || cmd === '-h' || cmd === '--help' || cmd === 'help') { console.log(USAGE); return 0; }
24
+ if (cmd === '-v' || cmd === '--version') { console.log(version); return 0; }
25
+ if (!token) { warn('missing token'); console.error(USAGE); return 2; }
26
+
27
+ if (cmd === 'ping' || cmd === 'fail') {
28
+ try { await (cmd === 'ping' ? ping : fail)(token); return 0; }
29
+ catch (err) { warn(`could not report: ${err.message}`); return 1; }
30
+ }
31
+
32
+ if (cmd === 'run') {
33
+ const command = rest[0] === '--' ? rest.slice(1) : rest;
34
+ if (!command.length) { warn('nothing to run; use: tockward run <token> -- <command>'); return 2; }
35
+ const started = Date.now();
36
+ const code = await new Promise(resolve => {
37
+ const child = spawn(command[0], command.slice(1), { stdio: 'inherit' });
38
+ child.on('error', err => { warn(`could not start ${command[0]}: ${err.message}`); resolve(127); });
39
+ child.on('exit', (c, signal) => resolve(signal ? 128 : c));
40
+ });
41
+ try { await (code === 0 ? ping : fail)(token, { ms: Date.now() - started }); }
42
+ catch (err) { warn(`could not report: ${err.message}`); }
43
+ return code;
44
+ }
45
+
46
+ warn(`unknown command: ${cmd}`); console.error(USAGE); return 2;
47
+ }
48
+
49
+ main(process.argv.slice(2)).then(code => process.exit(code));
package/index.js ADDED
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+ // Tockward heartbeat client. No dependencies; needs Node 18+ (built-in fetch).
3
+ //
4
+ // const tockward = require('tockward');
5
+ // await tockward.ping('abc123'); // "I ran"
6
+ // await tockward.fail('abc123'); // "I failed"
7
+ // await tockward.ping('abc123', { ms: 4200 }); // with the run's duration
8
+ //
9
+ // A token can also be a full ping URL (https://.../v1/beat/<token>), so URLs
10
+ // copied from the dashboard work as they are. TOCKWARD_URL overrides the base.
11
+
12
+ const DEFAULT_BASE = 'https://ping.tockward.com';
13
+
14
+ function beatUrl(token, ok, ms) {
15
+ if (!token || typeof token !== 'string') throw new Error('missing token');
16
+ let url;
17
+ if (/^https?:\/\//i.test(token)) {
18
+ url = token.replace(/\/+$/, '').replace(/\/fail$/, '');
19
+ } else {
20
+ const base = (process.env.TOCKWARD_URL || DEFAULT_BASE).replace(/\/+$/, '');
21
+ url = `${base}/v1/beat/${encodeURIComponent(token)}`;
22
+ }
23
+ if (!ok) url += '/fail';
24
+ if (Number.isFinite(ms)) url += `?ms=${Math.max(0, Math.round(ms))}`;
25
+ return url;
26
+ }
27
+
28
+ async function send(token, ok, { ms, timeout = 10000, retries = 2 } = {}) {
29
+ const url = beatUrl(token, ok, ms);
30
+ let lastError;
31
+ for (let attempt = 0; attempt <= retries; attempt++) {
32
+ if (attempt) await new Promise(r => setTimeout(r, 1000 * attempt));
33
+ try {
34
+ const res = await fetch(url, { method: 'POST', signal: AbortSignal.timeout(timeout) });
35
+ if (res.ok) return true;
36
+ if (res.status === 404) throw Object.assign(new Error('unknown monitor (check the token)'), { final: true });
37
+ lastError = new Error(`HTTP ${res.status}`);
38
+ } catch (err) {
39
+ if (err.final) throw err;
40
+ lastError = err;
41
+ }
42
+ }
43
+ throw lastError;
44
+ }
45
+
46
+ module.exports = {
47
+ ping: (token, opts) => send(token, true, opts),
48
+ fail: (token, opts) => send(token, false, opts),
49
+ beatUrl,
50
+ };
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "tockward",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Heartbeat client for Tockward: know when your cron jobs, scripts and devices go silent.",
5
+ "main": "index.js",
6
+ "bin": { "tockward": "bin/tockward.js" },
7
+ "files": ["index.js", "bin/", "README.md", "LICENSE"],
8
+ "engines": { "node": ">=18" },
9
+ "keywords": ["cron", "monitoring", "heartbeat", "dead-mans-switch", "cronjob", "uptime", "alerting"],
10
+ "homepage": "https://tockward.com",
11
+ "repository": { "type": "git", "url": "git+https://github.com/tockward/tockward-cli.git" },
12
+ "bugs": { "url": "https://github.com/tockward/tockward-cli/issues", "email": "support@tockward.com" },
13
+ "author": "Tockward <support@tockward.com>",
14
+ "license": "MIT"
15
+ }