@zeph-to/hook-sdk 0.1.0 → 0.2.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 +99 -50
- package/dist/cli.js +183 -48
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/zeph-hook.d.ts +5 -1
- package/dist/zeph-hook.d.ts.map +1 -1
- package/dist/zeph-hook.js +42 -13
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -1,39 +1,124 @@
|
|
|
1
|
-
# @zeph/hook-sdk
|
|
1
|
+
# @zeph-to/hook-sdk
|
|
2
2
|
|
|
3
3
|
Push notification SDK + CLI for [Zeph](https://zeph.to). Zero dependencies — uses native `fetch`.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @zeph/hook-sdk
|
|
8
|
+
npm install @zeph-to/hook-sdk
|
|
9
|
+
# or
|
|
10
|
+
npx @zeph-to/hook-sdk notify --title "Hello"
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
## CLI Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Send a notification
|
|
17
|
+
zeph notify --title "Deploy done" --body "v2.1.0 shipped"
|
|
18
|
+
|
|
19
|
+
# Send with priority
|
|
20
|
+
zeph notify --title "Build failed" --priority high --url https://ci.example.com/123
|
|
21
|
+
|
|
22
|
+
# List recent pushes
|
|
23
|
+
zeph list
|
|
24
|
+
zeph list --limit 10 --type note
|
|
25
|
+
|
|
26
|
+
# Dismiss a push
|
|
27
|
+
zeph dismiss push_01JXY...
|
|
28
|
+
zeph dismiss --all
|
|
29
|
+
|
|
30
|
+
# Test connection
|
|
31
|
+
zeph test
|
|
32
|
+
|
|
33
|
+
# JSON output
|
|
34
|
+
zeph notify --title "Hello" --json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Commands
|
|
38
|
+
|
|
39
|
+
| Command | Description |
|
|
40
|
+
|---------|-------------|
|
|
41
|
+
| `notify` | Send a push notification |
|
|
42
|
+
| `list` | List recent push notifications |
|
|
43
|
+
| `dismiss <id>` | Dismiss a push (or `--all`) |
|
|
44
|
+
| `test` | Send a test notification to verify setup |
|
|
45
|
+
|
|
46
|
+
### Notify Options
|
|
47
|
+
|
|
48
|
+
| Flag | Description |
|
|
49
|
+
|------|-------------|
|
|
50
|
+
| `--title <text>` | Push title |
|
|
51
|
+
| `--body <text>` | Push body |
|
|
52
|
+
| `--url <url>` | URL to include |
|
|
53
|
+
| `--type <type>` | Push type: `note`, `link`, `file` |
|
|
54
|
+
| `--priority <p>` | Priority: `low`, `normal`, `high`, `urgent` |
|
|
55
|
+
| `--device <id>` | Target device ID |
|
|
56
|
+
|
|
57
|
+
### List Options
|
|
58
|
+
|
|
59
|
+
| Flag | Description |
|
|
60
|
+
|------|-------------|
|
|
61
|
+
| `--limit <n>` | Number of pushes (1-20, default 5) |
|
|
62
|
+
| `--type <type>` | Filter by push type |
|
|
63
|
+
|
|
64
|
+
### Global Options
|
|
65
|
+
|
|
66
|
+
| Flag | Description |
|
|
67
|
+
|------|-------------|
|
|
68
|
+
| `--key <api-key>` | API key (or set `ZEPH_API_KEY` env) |
|
|
69
|
+
| `--base-url <url>` | API base URL (or set `ZEPH_BASE_URL` env) |
|
|
70
|
+
| `--json` | Output JSON format |
|
|
71
|
+
| `--version` | Print version |
|
|
72
|
+
|
|
73
|
+
### Exit Codes
|
|
74
|
+
|
|
75
|
+
| Code | Meaning |
|
|
76
|
+
|------|---------|
|
|
77
|
+
| 0 | Success |
|
|
78
|
+
| 1 | General error |
|
|
79
|
+
| 2 | Quota exceeded |
|
|
80
|
+
| 3 | Authentication failed |
|
|
81
|
+
|
|
82
|
+
### Environment Variables
|
|
83
|
+
|
|
84
|
+
| Variable | Description |
|
|
85
|
+
|----------|-------------|
|
|
86
|
+
| `ZEPH_API_KEY` | API key (fallback when `--key` not provided) |
|
|
87
|
+
| `ZEPH_BASE_URL` | API base URL (default: `https://api.zeph.to/v1`) |
|
|
88
|
+
|
|
11
89
|
## SDK Usage
|
|
12
90
|
|
|
13
91
|
```typescript
|
|
14
|
-
import { ZephHook } from '@zeph/hook-sdk';
|
|
92
|
+
import { ZephHook } from '@zeph-to/hook-sdk';
|
|
15
93
|
|
|
16
94
|
const hook = new ZephHook({ apiKey: 'ak_...' });
|
|
17
95
|
|
|
96
|
+
// Notify
|
|
18
97
|
const result = await hook.notify({
|
|
19
98
|
title: 'Build Complete',
|
|
20
99
|
body: 'Deploy succeeded',
|
|
21
100
|
url: 'https://example.com/deploy/123',
|
|
101
|
+
priority: 'high',
|
|
22
102
|
});
|
|
23
|
-
|
|
24
103
|
console.log(result.pushId); // 'push_01JXY...'
|
|
25
|
-
```
|
|
26
104
|
|
|
27
|
-
|
|
105
|
+
// List
|
|
106
|
+
const list = await hook.list({ limit: 5 });
|
|
107
|
+
console.log(list.pushes);
|
|
28
108
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
baseUrl: 'https://...', // Optional — API base URL (default: https://api.zeph.to)
|
|
33
|
-
timeout: 30000, // Optional — request timeout in ms (default: 30000)
|
|
34
|
-
});
|
|
109
|
+
// Dismiss
|
|
110
|
+
await hook.dismiss('push_01JXY...');
|
|
111
|
+
await hook.dismissAll();
|
|
35
112
|
```
|
|
36
113
|
|
|
114
|
+
### Constructor Options
|
|
115
|
+
|
|
116
|
+
| Field | Type | Description |
|
|
117
|
+
|-------|------|-------------|
|
|
118
|
+
| `apiKey` | `string` | Required — API key from Zeph settings |
|
|
119
|
+
| `baseUrl` | `string?` | API base URL (default: `https://api.zeph.to/v1`) |
|
|
120
|
+
| `timeout` | `number?` | Request timeout in ms (default: 30000) |
|
|
121
|
+
|
|
37
122
|
### Notify Payload
|
|
38
123
|
|
|
39
124
|
| Field | Type | Description |
|
|
@@ -42,12 +127,13 @@ const hook = new ZephHook({
|
|
|
42
127
|
| `body` | `string?` | Push body |
|
|
43
128
|
| `url` | `string?` | URL to include |
|
|
44
129
|
| `type` | `'note' \| 'link' \| 'file'?` | Push type (default: `note`) |
|
|
130
|
+
| `priority` | `'low' \| 'normal' \| 'high' \| 'urgent'?` | Priority (default: `normal`) |
|
|
45
131
|
| `targetDeviceId` | `string?` | Send to specific device |
|
|
46
132
|
|
|
47
133
|
### Error Handling
|
|
48
134
|
|
|
49
135
|
```typescript
|
|
50
|
-
import { ZephHook, AuthenticationError, QuotaExceededError, ZephError } from '@zeph/hook-sdk';
|
|
136
|
+
import { ZephHook, AuthenticationError, QuotaExceededError, ZephError } from '@zeph-to/hook-sdk';
|
|
51
137
|
|
|
52
138
|
try {
|
|
53
139
|
await hook.notify({ title: 'Hello' });
|
|
@@ -58,43 +144,6 @@ try {
|
|
|
58
144
|
}
|
|
59
145
|
```
|
|
60
146
|
|
|
61
|
-
## CLI Usage
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
# With API key flag
|
|
65
|
-
zeph notify --key ak_... --title "Deploy done" --body "v2.1.0 shipped"
|
|
66
|
-
|
|
67
|
-
# With environment variable
|
|
68
|
-
export ZEPH_API_KEY=ak_...
|
|
69
|
-
zeph notify --title "Build failed" --url https://ci.example.com/123
|
|
70
|
-
|
|
71
|
-
# JSON output
|
|
72
|
-
zeph notify --title "Hello" --json
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### CLI Options
|
|
76
|
-
|
|
77
|
-
| Flag | Description |
|
|
78
|
-
|------|-------------|
|
|
79
|
-
| `--key <api-key>` | API key (or set `ZEPH_API_KEY` env) |
|
|
80
|
-
| `--title <text>` | Push title |
|
|
81
|
-
| `--body <text>` | Push body |
|
|
82
|
-
| `--url <url>` | URL to include |
|
|
83
|
-
| `--type <type>` | Push type: `note`, `link`, `file` |
|
|
84
|
-
| `--device <id>` | Target device ID |
|
|
85
|
-
| `--base-url <url>` | API base URL |
|
|
86
|
-
| `--json` | Output JSON format |
|
|
87
|
-
| `--version` | Print version |
|
|
88
|
-
|
|
89
|
-
### Exit Codes
|
|
90
|
-
|
|
91
|
-
| Code | Meaning |
|
|
92
|
-
|------|---------|
|
|
93
|
-
| 0 | Success |
|
|
94
|
-
| 1 | General error |
|
|
95
|
-
| 2 | Quota exceeded |
|
|
96
|
-
| 3 | Authentication failed |
|
|
97
|
-
|
|
98
147
|
## Requirements
|
|
99
148
|
|
|
100
149
|
- Node.js >= 18 (uses native `fetch`)
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ const fs_1 = require("fs");
|
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const zeph_hook_js_1 = require("./zeph-hook.js");
|
|
7
7
|
const errors_js_1 = require("./errors.js");
|
|
8
|
-
const
|
|
8
|
+
const VERSION = (() => {
|
|
9
9
|
try {
|
|
10
10
|
const pkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf-8'));
|
|
11
11
|
return pkg.version;
|
|
@@ -13,16 +13,16 @@ const getVersion = () => {
|
|
|
13
13
|
catch {
|
|
14
14
|
return '0.0.0';
|
|
15
15
|
}
|
|
16
|
-
};
|
|
16
|
+
})();
|
|
17
17
|
// ── Arg Parser ──────────────────────────────────────────────────
|
|
18
18
|
const parseArgs = (argv) => {
|
|
19
19
|
const result = {};
|
|
20
|
+
const positional = [];
|
|
20
21
|
const args = argv.slice(2);
|
|
21
22
|
for (let i = 0; i < args.length; i++) {
|
|
22
23
|
const arg = args[i];
|
|
23
24
|
if (!arg.startsWith('--')) {
|
|
24
|
-
|
|
25
|
-
result._command = arg;
|
|
25
|
+
positional.push(arg);
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
28
|
const key = arg.slice(2);
|
|
@@ -35,24 +35,44 @@ const parseArgs = (argv) => {
|
|
|
35
35
|
i++;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
result._command = positional[0] ?? '';
|
|
39
|
+
result._arg1 = positional[1] ?? '';
|
|
38
40
|
return result;
|
|
39
41
|
};
|
|
40
42
|
// ── Output ──────────────────────────────────────────────────────
|
|
41
43
|
const printUsage = () => {
|
|
42
|
-
console.log(`Usage: zeph
|
|
44
|
+
console.log(`Usage: zeph <command> [options]
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
Commands:
|
|
47
|
+
notify Send a push notification
|
|
48
|
+
list List recent push notifications
|
|
49
|
+
dismiss <id> Dismiss a push notification (or --all)
|
|
50
|
+
test Send a test notification to verify setup
|
|
51
|
+
|
|
52
|
+
Notify options:
|
|
46
53
|
--title <text> Push title
|
|
47
54
|
--body <text> Push body
|
|
48
55
|
--url <url> URL to include
|
|
49
56
|
--type <type> Push type (note|link|file) [default: note]
|
|
57
|
+
--priority <p> Priority (low|normal|high|urgent) [default: normal]
|
|
50
58
|
--device <id> Target device ID
|
|
51
|
-
|
|
59
|
+
|
|
60
|
+
List options:
|
|
61
|
+
--limit <n> Number of pushes (1-20, default 5)
|
|
62
|
+
--type <type> Filter by push type
|
|
63
|
+
|
|
64
|
+
Dismiss options:
|
|
65
|
+
--all Dismiss all notifications
|
|
66
|
+
|
|
67
|
+
Global options:
|
|
68
|
+
--key <api-key> API key (or set ZEPH_API_KEY env)
|
|
69
|
+
--base-url <url> API base URL (or set ZEPH_BASE_URL env)
|
|
52
70
|
--json Output JSON format
|
|
71
|
+
--version Show version
|
|
53
72
|
|
|
54
73
|
Environment:
|
|
55
|
-
ZEPH_API_KEY API key (fallback when --key not provided)
|
|
74
|
+
ZEPH_API_KEY API key (fallback when --key not provided)
|
|
75
|
+
ZEPH_BASE_URL API base URL (fallback when --base-url not provided)`);
|
|
56
76
|
};
|
|
57
77
|
const printError = (message, isJson) => {
|
|
58
78
|
if (isJson) {
|
|
@@ -62,67 +82,182 @@ const printError = (message, isJson) => {
|
|
|
62
82
|
console.error(`Error: ${message}`);
|
|
63
83
|
}
|
|
64
84
|
};
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
console.log(JSON.stringify({ pushId, status: 'ok' }));
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
console.log(`Push sent: ${pushId}`);
|
|
71
|
-
}
|
|
85
|
+
const printJson = (data) => {
|
|
86
|
+
console.log(JSON.stringify(data, null, 2));
|
|
72
87
|
};
|
|
73
|
-
// ──
|
|
74
|
-
const
|
|
75
|
-
const args = parseArgs(process.argv);
|
|
76
|
-
const command = args._command;
|
|
77
|
-
const isJson = args.json === true;
|
|
78
|
-
if (args.version === true) {
|
|
79
|
-
console.log(getVersion());
|
|
80
|
-
return 0;
|
|
81
|
-
}
|
|
82
|
-
if (!command || command === 'help') {
|
|
83
|
-
printUsage();
|
|
84
|
-
return 0;
|
|
85
|
-
}
|
|
86
|
-
if (command !== 'notify') {
|
|
87
|
-
printError(`Unknown command: ${command}`, isJson);
|
|
88
|
-
printUsage();
|
|
89
|
-
return 1;
|
|
90
|
-
}
|
|
88
|
+
// ── Commands ────────────────────────────────────────────────────
|
|
89
|
+
const createHook = (args) => {
|
|
91
90
|
const apiKey = args.key || process.env.ZEPH_API_KEY;
|
|
91
|
+
const isJson = args.json === true;
|
|
92
92
|
if (!apiKey) {
|
|
93
93
|
printError('API key required. Use --key or set ZEPH_API_KEY', isJson);
|
|
94
|
-
return
|
|
94
|
+
return null;
|
|
95
95
|
}
|
|
96
|
-
const
|
|
96
|
+
const baseUrl = args['base-url'] || process.env.ZEPH_BASE_URL;
|
|
97
|
+
return new zeph_hook_js_1.ZephHook({
|
|
97
98
|
apiKey,
|
|
98
|
-
baseUrl
|
|
99
|
+
...(baseUrl && { baseUrl }),
|
|
99
100
|
});
|
|
101
|
+
};
|
|
102
|
+
const handleNotify = async (args) => {
|
|
103
|
+
const isJson = args.json === true;
|
|
104
|
+
const hook = createHook(args);
|
|
105
|
+
if (!hook)
|
|
106
|
+
return 3;
|
|
100
107
|
try {
|
|
101
108
|
const result = await hook.notify({
|
|
102
109
|
title: args.title,
|
|
103
110
|
body: args.body,
|
|
104
111
|
url: args.url,
|
|
105
112
|
type: args.type || undefined,
|
|
113
|
+
priority: args.priority || undefined,
|
|
106
114
|
targetDeviceId: args.device,
|
|
107
115
|
});
|
|
108
|
-
|
|
116
|
+
if (isJson) {
|
|
117
|
+
printJson({ pushId: result.pushId, status: 'ok' });
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.log(`Push sent: ${result.pushId}`);
|
|
121
|
+
}
|
|
109
122
|
return 0;
|
|
110
123
|
}
|
|
111
124
|
catch (err) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
return handleError(err, isJson);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const handleList = async (args) => {
|
|
129
|
+
const isJson = args.json === true;
|
|
130
|
+
const hook = createHook(args);
|
|
131
|
+
if (!hook)
|
|
132
|
+
return 3;
|
|
133
|
+
try {
|
|
134
|
+
const limit = args.limit ? Number(args.limit) : undefined;
|
|
135
|
+
const result = await hook.list({
|
|
136
|
+
limit,
|
|
137
|
+
type: args.type,
|
|
138
|
+
});
|
|
139
|
+
if (isJson) {
|
|
140
|
+
printJson(result);
|
|
115
141
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
142
|
+
else {
|
|
143
|
+
if (result.pushes.length === 0) {
|
|
144
|
+
console.log('No pushes found.');
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
for (const p of result.pushes) {
|
|
148
|
+
const title = p.title ?? '(no title)';
|
|
149
|
+
const time = new Date(p.createdAt).toLocaleString();
|
|
150
|
+
console.log(` ${p.pushId} [${p.type}] ${title} (${time})`);
|
|
151
|
+
}
|
|
152
|
+
if (result.hasMore)
|
|
153
|
+
console.log(` ... more available (use --limit to increase)`);
|
|
154
|
+
}
|
|
119
155
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
return handleError(err, isJson);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const handleDismiss = async (args) => {
|
|
163
|
+
const isJson = args.json === true;
|
|
164
|
+
const hook = createHook(args);
|
|
165
|
+
if (!hook)
|
|
166
|
+
return 3;
|
|
167
|
+
try {
|
|
168
|
+
if (args.all === true) {
|
|
169
|
+
const result = await hook.dismissAll();
|
|
170
|
+
if (isJson) {
|
|
171
|
+
printJson({ dismissed: result.dismissed, status: 'ok' });
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.log(`Dismissed ${result.dismissed} pushes.`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const pushId = args._arg1;
|
|
179
|
+
if (!pushId) {
|
|
180
|
+
printError('Push ID required. Usage: zeph dismiss <push-id> or zeph dismiss --all', isJson);
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
await hook.dismiss(pushId);
|
|
184
|
+
if (isJson) {
|
|
185
|
+
printJson({ dismissed: true, pushId, status: 'ok' });
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
console.log(`Dismissed: ${pushId}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
return handleError(err, isJson);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const handleTest = async (args) => {
|
|
198
|
+
const isJson = args.json === true;
|
|
199
|
+
const hook = createHook(args);
|
|
200
|
+
if (!hook)
|
|
201
|
+
return 3;
|
|
202
|
+
try {
|
|
203
|
+
const result = await hook.notify({
|
|
204
|
+
title: 'Zeph Test',
|
|
205
|
+
body: `CLI connected successfully (v${VERSION})`,
|
|
206
|
+
});
|
|
207
|
+
if (isJson) {
|
|
208
|
+
printJson({ pushId: result.pushId, status: 'ok', message: 'Test notification sent' });
|
|
123
209
|
}
|
|
124
|
-
|
|
210
|
+
else {
|
|
211
|
+
console.log(`Test notification sent: ${result.pushId}`);
|
|
212
|
+
}
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
return handleError(err, isJson);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
// ── Error Handler ───────────────────────────────────────────────
|
|
220
|
+
const handleError = (err, isJson) => {
|
|
221
|
+
if (err instanceof errors_js_1.QuotaExceededError) {
|
|
222
|
+
printError(err.message, isJson);
|
|
223
|
+
return 2;
|
|
224
|
+
}
|
|
225
|
+
if (err instanceof errors_js_1.AuthenticationError) {
|
|
226
|
+
printError(err.message, isJson);
|
|
227
|
+
return 3;
|
|
228
|
+
}
|
|
229
|
+
if (err instanceof errors_js_1.ZephError) {
|
|
230
|
+
printError(err.message, isJson);
|
|
125
231
|
return 1;
|
|
126
232
|
}
|
|
233
|
+
printError(err instanceof Error ? err.message : 'Unknown error', isJson);
|
|
234
|
+
return 1;
|
|
235
|
+
};
|
|
236
|
+
// ── Main ────────────────────────────────────────────────────────
|
|
237
|
+
const main = async () => {
|
|
238
|
+
const args = parseArgs(process.argv);
|
|
239
|
+
const command = args._command;
|
|
240
|
+
if (args.version === true) {
|
|
241
|
+
console.log(VERSION);
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
if (!command || command === 'help') {
|
|
245
|
+
printUsage();
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
switch (command) {
|
|
249
|
+
case 'notify':
|
|
250
|
+
return handleNotify(args);
|
|
251
|
+
case 'list':
|
|
252
|
+
return handleList(args);
|
|
253
|
+
case 'dismiss':
|
|
254
|
+
return handleDismiss(args);
|
|
255
|
+
case 'test':
|
|
256
|
+
return handleTest(args);
|
|
257
|
+
default:
|
|
258
|
+
printError(`Unknown command: ${command}`, args.json === true);
|
|
259
|
+
printUsage();
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
127
262
|
};
|
|
128
263
|
main().then((code) => process.exit(code));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ZephHook } from './zeph-hook.js';
|
|
2
2
|
export { ZephError, AuthenticationError, QuotaExceededError } from './errors.js';
|
|
3
|
-
export type { ZephOptions, NotifyPayload, NotifyResult } from './types.js';
|
|
3
|
+
export type { ZephOptions, NotifyPayload, NotifyResult, ListParams, ListResult, DismissOneResult, DismissAllResult, PushItem } from './types.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjF,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjF,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -8,11 +8,34 @@ export interface NotifyPayload {
|
|
|
8
8
|
body?: string;
|
|
9
9
|
url?: string;
|
|
10
10
|
type?: 'note' | 'link' | 'file';
|
|
11
|
+
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
11
12
|
targetDeviceId?: string;
|
|
12
13
|
}
|
|
13
14
|
export interface NotifyResult {
|
|
14
15
|
pushId: string;
|
|
15
16
|
}
|
|
17
|
+
export interface ListParams {
|
|
18
|
+
limit?: number;
|
|
19
|
+
type?: 'note' | 'link' | 'file' | 'clipboard' | 'hook';
|
|
20
|
+
}
|
|
21
|
+
export interface PushItem {
|
|
22
|
+
pushId: string;
|
|
23
|
+
type: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
body?: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ListResult {
|
|
29
|
+
pushes: PushItem[];
|
|
30
|
+
count: number;
|
|
31
|
+
hasMore: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface DismissOneResult {
|
|
34
|
+
dismissed: true;
|
|
35
|
+
}
|
|
36
|
+
export interface DismissAllResult {
|
|
37
|
+
dismissed: number;
|
|
38
|
+
}
|
|
16
39
|
export interface ApiErrorResponse {
|
|
17
40
|
error: {
|
|
18
41
|
code: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;CACxD;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH"}
|
package/dist/zeph-hook.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { ZephOptions, NotifyPayload, NotifyResult } from './types.js';
|
|
1
|
+
import type { ZephOptions, NotifyPayload, NotifyResult, ListParams, ListResult, DismissOneResult, DismissAllResult } from './types.js';
|
|
2
2
|
export declare class ZephHook {
|
|
3
3
|
private readonly apiKey;
|
|
4
4
|
private readonly baseUrl;
|
|
5
5
|
private readonly timeoutMs;
|
|
6
6
|
constructor(options: ZephOptions);
|
|
7
7
|
notify(payload: NotifyPayload): Promise<NotifyResult>;
|
|
8
|
+
list(params?: ListParams): Promise<ListResult>;
|
|
9
|
+
dismiss(pushId: string): Promise<DismissOneResult>;
|
|
10
|
+
dismissAll(): Promise<DismissAllResult>;
|
|
11
|
+
private request;
|
|
8
12
|
private parseError;
|
|
9
13
|
}
|
|
10
14
|
//# sourceMappingURL=zeph-hook.d.ts.map
|
package/dist/zeph-hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zeph-hook.d.ts","sourceRoot":"","sources":["../src/zeph-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"zeph-hook.d.ts","sourceRoot":"","sources":["../src/zeph-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAY,gBAAgB,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAC;AAMnK,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,OAAO,EAAE,WAAW;IAS1B,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IASrD,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAmB9C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKlD,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;YAK/B,OAAO;IAiCrB,OAAO,CAAC,UAAU;CASnB"}
|
package/dist/zeph-hook.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZephHook = void 0;
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
|
-
const DEFAULT_BASE_URL = 'https://api.zeph.to';
|
|
5
|
+
const DEFAULT_BASE_URL = 'https://api.zeph.to/v1';
|
|
6
6
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
7
|
class ZephHook {
|
|
8
8
|
apiKey;
|
|
@@ -17,17 +17,50 @@ class ZephHook {
|
|
|
17
17
|
this.timeoutMs = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
18
18
|
}
|
|
19
19
|
async notify(payload) {
|
|
20
|
+
const json = await this.request('POST', '/pushes/send', payload);
|
|
21
|
+
const pushId = json.data?.pushId;
|
|
22
|
+
if (!pushId) {
|
|
23
|
+
throw new errors_js_1.ZephError('Server returned no pushId', 'INVALID_RESPONSE', 500);
|
|
24
|
+
}
|
|
25
|
+
return { pushId };
|
|
26
|
+
}
|
|
27
|
+
async list(params) {
|
|
28
|
+
const query = new URLSearchParams();
|
|
29
|
+
if (params?.limit)
|
|
30
|
+
query.set('limit', String(params.limit));
|
|
31
|
+
if (params?.type)
|
|
32
|
+
query.set('type', params.type);
|
|
33
|
+
const qs = query.toString();
|
|
34
|
+
const json = await this.request('GET', `/pushes${qs ? `?${qs}` : ''}`);
|
|
35
|
+
const pushes = json.data.map((p) => ({
|
|
36
|
+
pushId: p.pushId,
|
|
37
|
+
type: p.type,
|
|
38
|
+
title: p.title,
|
|
39
|
+
body: p.body?.slice(0, 100),
|
|
40
|
+
createdAt: p.createdAt,
|
|
41
|
+
}));
|
|
42
|
+
return { pushes, count: pushes.length, hasMore: json.pagination?.hasMore ?? false };
|
|
43
|
+
}
|
|
44
|
+
async dismiss(pushId) {
|
|
45
|
+
await this.request('POST', `/pushes/${encodeURIComponent(pushId)}/dismiss`);
|
|
46
|
+
return { dismissed: true };
|
|
47
|
+
}
|
|
48
|
+
async dismissAll() {
|
|
49
|
+
const json = await this.request('POST', '/pushes/dismiss-all');
|
|
50
|
+
return { dismissed: json.data?.dismissed ?? 0 };
|
|
51
|
+
}
|
|
52
|
+
async request(method, path, body) {
|
|
20
53
|
const controller = new AbortController();
|
|
21
54
|
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
55
|
+
const headers = { 'X-API-Key': this.apiKey };
|
|
56
|
+
if (body)
|
|
57
|
+
headers['Content-Type'] = 'application/json';
|
|
22
58
|
let response;
|
|
23
59
|
try {
|
|
24
|
-
response = await fetch(`${this.baseUrl}
|
|
25
|
-
method
|
|
26
|
-
headers
|
|
27
|
-
|
|
28
|
-
'X-API-Key': this.apiKey,
|
|
29
|
-
},
|
|
30
|
-
body: JSON.stringify(payload),
|
|
60
|
+
response = await fetch(`${this.baseUrl}${path}`, {
|
|
61
|
+
method,
|
|
62
|
+
headers,
|
|
63
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
31
64
|
signal: controller.signal,
|
|
32
65
|
});
|
|
33
66
|
}
|
|
@@ -44,11 +77,7 @@ class ZephHook {
|
|
|
44
77
|
if (!response.ok) {
|
|
45
78
|
throw this.parseError(response.status, json);
|
|
46
79
|
}
|
|
47
|
-
|
|
48
|
-
if (!pushId) {
|
|
49
|
-
throw new errors_js_1.ZephError('Server returned no pushId', 'INVALID_RESPONSE', response.status);
|
|
50
|
-
}
|
|
51
|
-
return { pushId };
|
|
80
|
+
return json;
|
|
52
81
|
}
|
|
53
82
|
parseError(status, body) {
|
|
54
83
|
const message = body.error?.message ?? `Request failed with status ${status}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeph-to/hook-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Zeph push notification SDK + CLI — zero dependencies",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,6 +30,16 @@
|
|
|
30
30
|
"directory": "libs/hook-sdk"
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/tak-bro/encl/tree/main/libs/hook-sdk",
|
|
33
|
-
"keywords": [
|
|
33
|
+
"keywords": [
|
|
34
|
+
"zeph",
|
|
35
|
+
"push",
|
|
36
|
+
"notification",
|
|
37
|
+
"cli",
|
|
38
|
+
"webhook",
|
|
39
|
+
"ai-agent",
|
|
40
|
+
"mcp",
|
|
41
|
+
"claude",
|
|
42
|
+
"devtools"
|
|
43
|
+
],
|
|
34
44
|
"license": "MIT"
|
|
35
45
|
}
|