opush-sdk 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 All Right LLC
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,352 @@
1
- # Temporary Holding Version
1
+ # opush-sdk
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
+ The official TypeScript SDK and command-line tool for [Opush](https://opu.sh): push notifications to your iPhone, Apple Watch, Mac and Android from scripts, CI, servers and AI agents.
4
+
5
+ - Push with titles, Markdown, images, files, buttons, sounds and urgency levels
6
+ - Schedule and repeat pushes, replace and recall them
7
+ - Live progress cards on the Lock Screen, Dynamic Island and Android status bar
8
+ - Ask a question and wait for the answer
9
+ - Escalating alerts with calls, texts and phone calls
10
+ - Heartbeat check-ins for cron jobs
11
+ - Shared-key (AES) and end-to-end (HPKE) encryption
12
+ - Works in Node.js 18+, Bun, Deno and Cloudflare Workers. One small dependency.
13
+ - An `opush` command for your shell
14
+
15
+ Full documentation: [opu.sh/docs](https://opu.sh/docs)
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install opush-sdk
21
+ ```
22
+
23
+ Command line only:
24
+
25
+ ```bash
26
+ npx opush-sdk "Hello from my terminal"
27
+ # or install it
28
+ npm install -g opush-sdk
29
+ brew install all-right-LLC/tap/opush
30
+ ```
31
+
32
+ ## Quick start
33
+
34
+ Find your push URL in the Opush app (or at [app.opu.sh](https://app.opu.sh)). It looks like `https://opu.sh/YOUR_KEY`.
35
+
36
+ ```ts
37
+ import { Opush } from "opush-sdk";
38
+
39
+ const opush = new Opush({ key: "YOUR_KEY" }); // or the full push URL
40
+
41
+ await opush.push("Backup done");
42
+
43
+ await opush.push({
44
+ title: "Deploy failed",
45
+ body: "main #128 · test job",
46
+ level: "timeSensitive",
47
+ url: "https://ci.example.com/builds/128",
48
+ });
49
+ ```
50
+
51
+ CommonJS works too: `const { Opush } = require("opush-sdk")`.
52
+
53
+ ## The client
54
+
55
+ ```ts
56
+ new Opush({
57
+ key: "YOUR_KEY", // a device key or a full push URL
58
+ // keys: ["KEY_ONE", "KEY_TWO"], // several devices at once
59
+ // channel: "CHANNEL_KEY", // a team channel (or https://opu.sh/c/CHANNEL_KEY)
60
+ server: "https://opu.sh", // default
61
+ basicAuth: "user:password", // enterprise servers behind Basic Auth
62
+ timeout: 30_000, // milliseconds
63
+ retries: 0, // retry 429, 503 and network errors, honoring Retry-After
64
+ fetch, // custom fetch
65
+ encrypt: { key: "..." }, // encrypt every push (see Encryption)
66
+ });
67
+ ```
68
+
69
+ Pass only one of `key`, `keys` or `channel`. When none is given, the client reads `OPUSH_KEY` (comma-separated for several keys) or `OPUSH_CHANNEL` from the environment, and `OPUSH_SERVER` for the server. Pass `env: false` to ignore the environment.
70
+
71
+ A full push URL carries its own server, so these are the same:
72
+
73
+ ```ts
74
+ new Opush({ key: "https://push.example.com/api/YOUR_KEY" });
75
+ new Opush({ key: "YOUR_KEY", server: "https://push.example.com/api" });
76
+ ```
77
+
78
+ ## Push
79
+
80
+ ```ts
81
+ await opush.push({
82
+ title: "Refund request #42",
83
+ subtitle: "Shop",
84
+ body: "$49.00 for order 1042", // or markdown: "**$49.00** for order 1042"
85
+ group: "refunds",
86
+ level: "timeSensitive", // active | timeSensitive | passive | critical
87
+ sound: "chime",
88
+ icon: "https://example.com/icon.png",
89
+ image: "https://example.com/chart.png",
90
+ url: "https://example.com/tickets/42",
91
+ copy: "1042",
92
+ badge: 1,
93
+ id: "ticket-42", // replace or recall it later
94
+ ttl: 3600, // remove after an hour
95
+ archive: true, // save in the inbox
96
+ });
97
+ ```
98
+
99
+ Every field is described in [Parameters](https://opu.sh/docs/push/parameters). `push()` returns:
100
+
101
+ ```ts
102
+ { message: "success", timestamp: 1793546000, data, schedule, escalation, results }
103
+ ```
104
+
105
+ ### Buttons
106
+
107
+ Up to two buttons. With `method`, the phone sends the request in the background instead of opening the link.
108
+
109
+ ```ts
110
+ await opush.push({
111
+ id: "ticket-42",
112
+ title: "Refund request #42",
113
+ buttons: [
114
+ { title: "Approve", url: "https://example.com/tickets/42/approve?token=SECRET", method: "POST" },
115
+ { title: "Reject", url: "https://example.com/tickets/42/reject?token=SECRET", method: "POST", style: "destructive" },
116
+ ],
117
+ });
118
+ ```
119
+
120
+ See [Buttons and actions](https://opu.sh/docs/push/buttons).
121
+
122
+ ### Files
123
+
124
+ Attach up to 5 files: paths (Node, Bun, Deno), `Blob`/`File`, `Uint8Array` or `ArrayBuffer`.
125
+
126
+ ```ts
127
+ await opush.push({
128
+ title: "Nightly report",
129
+ attachments: ["./report.pdf", { data: csvBytes, name: "orders.csv", type: "text/csv" }],
130
+ });
131
+ ```
132
+
133
+ Files can't be sent to several keys at once.
134
+
135
+ ### Schedule and repeat
136
+
137
+ ```ts
138
+ await opush.push({ title: "Standup", body: "Starts in 10 minutes", at: "09:50", repeat: "weekdays", tz: "Asia/Taipei", id: "standup" });
139
+ await opush.push({ title: "Drink water", delay: 3600, id: "water" });
140
+
141
+ const r = await opush.push({ body: "Later", at: new Date(Date.now() + 86_400_000) });
142
+ r.schedule; // { id: "sch_…", fireAt: "…", repeat: null }
143
+ ```
144
+
145
+ ### Replace and recall
146
+
147
+ ```ts
148
+ await opush.push({ id: "build-128", title: "Build running" });
149
+ await opush.push({ id: "build-128", title: "Build passed" }); // replaces it
150
+ await opush.recall("build-128"); // removes it, cancels a schedule or alert with that id
151
+ ```
152
+
153
+ ### Several devices and channels
154
+
155
+ ```ts
156
+ const team = new Opush({ keys: ["KEY_ONE", "KEY_TWO"] });
157
+ const r = await team.push({ title: "Release v2.0 is out" });
158
+ r.results; // [{ code: 200, deviceKey: "KEY_ONE", … }, { code: 503, deviceKey: "KEY_TWO", message: "…" }]
159
+
160
+ const ops = new Opush({ channel: "CHANNEL_KEY" });
161
+ await ops.push({ title: "Deploy finished", body: "api v2.4.1 is live" });
162
+ await ops.push({ title: "Database down", oncall: true, escalate: true }); // only the person on call
163
+ ```
164
+
165
+ See [Team channels](https://opu.sh/docs/teams/channels).
166
+
167
+ ## Urgent alerts
168
+
169
+ ```ts
170
+ const r = await opush.push({
171
+ title: "Database down",
172
+ level: "critical",
173
+ call: "voice", // ring like a phone call (true: repeat the sound for 30 seconds)
174
+ voice: "down", // recorded message: alert, down, recovered, failed, done, security
175
+ sms: true, // text your verified numbers
176
+ phone: true, // call your verified numbers
177
+ escalate: ["push", "voice", "sms", "phone"], // or true for all steps
178
+ escalateAfter: 3, // minutes between steps
179
+ callbackUrl: "https://example.com/ack",
180
+ });
181
+
182
+ const alertId = r.escalation!.alertId;
183
+ const alert = await opush.alerts.get(alertId); // status: active | acked | done | cancelled
184
+ await opush.alerts.cancel(alertId);
185
+ ```
186
+
187
+ See [Alert endpoints](https://opu.sh/docs/api/alerts).
188
+
189
+ ## Live progress
190
+
191
+ ```ts
192
+ await opush.progress.start({ id: "deploy-7", title: "Deploy api", status: "Building", progress: 10 });
193
+ await opush.progress.update({ id: "deploy-7", status: "Uploading", progress: 60 });
194
+ await opush.progress.end({ id: "deploy-7", status: "Done" }); // or state: "failed"
195
+ ```
196
+
197
+ Progress cards are never encrypted. See [Live progress](https://opu.sh/docs/push/live-progress).
198
+
199
+ ## Ask and wait for an answer
200
+
201
+ ```ts
202
+ const question = await opush.ask({
203
+ title: "Merge PR #42?",
204
+ body: "CI passed, 2 approvals",
205
+ options: ["Merge", "Close"],
206
+ allowText: true,
207
+ timeout: 3600, // seconds until it expires
208
+ });
209
+
210
+ const state = await question.wait({ timeout: 10 * 60_000 }); // milliseconds, long polling
211
+ if (state.status === "answered") {
212
+ console.log(state.answer?.option ?? state.answer?.text);
213
+ }
214
+
215
+ await question.cancel();
216
+ await opush.getQuestion(question.id);
217
+ ```
218
+
219
+ `wait()` returns the last state. It is still `pending` if your timeout ran out first. See [Ask endpoints](https://opu.sh/docs/api/ask).
220
+
221
+ ## Callbacks
222
+
223
+ Questions and alerts with a callback URL are POSTed to your server with an `X-Opush-Signature` header. Check it against the raw body:
224
+
225
+ ```ts
226
+ import { verifySignature } from "opush-sdk";
227
+
228
+ export default {
229
+ async fetch(request: Request) {
230
+ const raw = await request.text();
231
+ const valid = await verifySignature(raw, request.headers.get("x-opush-signature"), CALLBACK_SECRET);
232
+ if (!valid) return new Response("bad signature", { status: 401 });
233
+ const event = JSON.parse(raw);
234
+ // …
235
+ return new Response("ok");
236
+ },
237
+ };
238
+ ```
239
+
240
+ `CALLBACK_SECRET` is `question.callbackSecret` or `escalation.callbackSecret`.
241
+
242
+ ## Heartbeats
243
+
244
+ Heartbeats don't need a device key. Use the check ID or the full heartbeat URL.
245
+
246
+ ```ts
247
+ const hb = new Opush().heartbeat("CHECK_ID"); // or "https://opu.sh/hb/CHECK_ID"
248
+
249
+ await hb.start();
250
+ try {
251
+ await runBackup();
252
+ await hb.ok();
253
+ } catch (error) {
254
+ await hb.fail(String(error)); // first 1,000 characters show up in the push
255
+ }
256
+ ```
257
+
258
+ See [Heartbeats](https://opu.sh/docs/api/heartbeats).
259
+
260
+ ## Encryption
261
+
262
+ ### Shared key (AES)
263
+
264
+ Use the algorithm and key from the app's encryption settings. A new random IV is generated for every push.
265
+
266
+ ```ts
267
+ const opush = new Opush({
268
+ key: "YOUR_KEY",
269
+ encrypt: { key: "your-32-character-key-goes-here!", algorithm: "aes-256-gcm" },
270
+ });
271
+ ```
272
+
273
+ Algorithms: `aes-128-gcm`, `aes-192-gcm`, `aes-256-gcm` (default), `aes-128-cbc`, `aes-192-cbc`, `aes-256-cbc`. Cloudflare Workers doesn't support 192-bit keys.
274
+
275
+ ### End-to-end (HPKE)
276
+
277
+ Only the device with the private key can open the push.
278
+
279
+ ```ts
280
+ const opush = new Opush({ key: "YOUR_KEY", encrypt: { publicKey: "BASE64_PUBLIC_KEY_FROM_THE_APP" } });
281
+ ```
282
+
283
+ The public key is base64 of the 65-byte P-256 point, or PEM.
284
+
285
+ The content (`title`, `subtitle`, `body`, `markdown`, `url`, `copy`, `icon`, `image`, `action` and buttons) is encrypted. Fields the server needs to deliver the push (`level`, `id`, `group`, `sound`, schedule, calls and texts) stay outside. Pass `encrypt` on a single push to override the client, or `encrypt: false` to send one push in plain text. See [Encryption](https://opu.sh/docs/push/encryption).
286
+
287
+ ## Errors
288
+
289
+ Every method throws `OpushError` when a request fails:
290
+
291
+ ```ts
292
+ import { OpushError } from "opush-sdk";
293
+
294
+ try {
295
+ await opush.push("x");
296
+ } catch (error) {
297
+ if (error instanceof OpushError) {
298
+ error.status; // HTTP status, 0 for network errors and timeouts
299
+ error.code; // e.g. "invalid_request", "not_found"; null for push errors
300
+ error.message;
301
+ error.retryAfter; // seconds, on 429 and 503
302
+ }
303
+ }
304
+ ```
305
+
306
+ Requests aren't retried unless you set `retries`. Only `429`, `503` and network errors are retried, and the client waits for `Retry-After`.
307
+
308
+ ## Enterprise servers
309
+
310
+ Point the client at your server, including any path prefix:
311
+
312
+ ```ts
313
+ const opush = new Opush({
314
+ key: "https://push.example.com/api/YOUR_KEY",
315
+ basicAuth: { username: "ci", password: process.env.OPUSH_PASSWORD! },
316
+ });
317
+ ```
318
+
319
+ ## Command line
320
+
321
+ ```bash
322
+ opush "Backup done"
323
+ opush -t Deploy "v2 is live" --level timeSensitive --url https://example.com
324
+ opush send --title "Report" --body "Attached" --group reports --file report.pdf
325
+ echo "log output" | opush -t Nightly # body from stdin
326
+
327
+ opush recall deploy-7
328
+
329
+ opush ask "Merge PR #42?" --option Merge --option Close --wait
330
+ # prints the answer; exit code 0 answered, 2 expired, 3 cancelled, 4 still pending
331
+
332
+ opush progress start --id deploy-7 --title "Deploy api" --progress 10
333
+ opush progress update --id deploy-7 --progress 60 --status Uploading
334
+ opush progress end --id deploy-7
335
+
336
+ opush hb CHECK_ID # success
337
+ opush hb CHECK_ID --start
338
+ opush hb CHECK_ID --fail "pg_dump: connection refused"
339
+
340
+ opush run --title Backup -- ./backup.sh
341
+ # runs the command, then pushes success or failure, how long it took and the last lines of output
342
+
343
+ opush config set key YOUR_KEY # saved in ~/.config/opush/config.json (mode 0600)
344
+ opush config set server https://push.example.com/api
345
+ opush config get
346
+ ```
347
+
348
+ The key comes from `--key`, then `OPUSH_KEY`, then the config file (likewise `--server`/`OPUSH_SERVER` and `--basic-auth`/`OPUSH_BASIC_AUTH`). Add `--json` to print the raw response. Run `opush --help` or `opush <command> --help` for every option.
349
+
350
+ ## License
351
+
352
+ MIT © 2026 All Right LLC