@zeph-to/hook-sdk 0.2.0 → 0.3.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 (2) hide show
  1. package/dist/cli.js +82 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3,8 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
+ const readline_1 = require("readline");
6
7
  const zeph_hook_js_1 = require("./zeph-hook.js");
7
8
  const errors_js_1 = require("./errors.js");
9
+ const CONFIG_DIR = (0, path_1.join)(process.env.HOME ?? '~', '.zeph');
10
+ const CONFIG_FILE = (0, path_1.join)(CONFIG_DIR, 'config.json');
8
11
  const VERSION = (() => {
9
12
  try {
10
13
  const pkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf-8'));
@@ -44,6 +47,7 @@ const printUsage = () => {
44
47
  console.log(`Usage: zeph <command> [options]
45
48
 
46
49
  Commands:
50
+ setup Interactive configuration (API key, Hook ID)
47
51
  notify Send a push notification
48
52
  list List recent push notifications
49
53
  dismiss <id> Dismiss a push notification (or --all)
@@ -85,15 +89,37 @@ const printError = (message, isJson) => {
85
89
  const printJson = (data) => {
86
90
  console.log(JSON.stringify(data, null, 2));
87
91
  };
92
+ const loadConfig = () => {
93
+ try {
94
+ return JSON.parse((0, fs_1.readFileSync)(CONFIG_FILE, 'utf-8'));
95
+ }
96
+ catch {
97
+ return {};
98
+ }
99
+ };
100
+ const saveConfig = (config) => {
101
+ (0, fs_1.mkdirSync)(CONFIG_DIR, { recursive: true });
102
+ (0, fs_1.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2) + '\n');
103
+ };
104
+ const prompt = (question) => {
105
+ const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout });
106
+ return new Promise((resolve) => {
107
+ rl.question(question, (answer) => {
108
+ rl.close();
109
+ resolve(answer.trim());
110
+ });
111
+ });
112
+ };
88
113
  // ── Commands ────────────────────────────────────────────────────
89
114
  const createHook = (args) => {
90
- const apiKey = args.key || process.env.ZEPH_API_KEY;
115
+ const config = loadConfig();
116
+ const apiKey = args.key || process.env.ZEPH_API_KEY || config.apiKey;
91
117
  const isJson = args.json === true;
92
118
  if (!apiKey) {
93
- printError('API key required. Use --key or set ZEPH_API_KEY', isJson);
119
+ printError('API key required. Run "zeph setup" or set ZEPH_API_KEY', isJson);
94
120
  return null;
95
121
  }
96
- const baseUrl = args['base-url'] || process.env.ZEPH_BASE_URL;
122
+ const baseUrl = args['base-url'] || process.env.ZEPH_BASE_URL || config.baseUrl;
97
123
  return new zeph_hook_js_1.ZephHook({
98
124
  apiKey,
99
125
  ...(baseUrl && { baseUrl }),
@@ -216,6 +242,57 @@ const handleTest = async (args) => {
216
242
  return handleError(err, isJson);
217
243
  }
218
244
  };
245
+ const handleSetup = async () => {
246
+ console.log('\n Zeph Setup\n');
247
+ const existing = loadConfig();
248
+ // API Key
249
+ const currentKey = process.env.ZEPH_API_KEY || existing.apiKey;
250
+ if (currentKey) {
251
+ console.log(` API Key: ${currentKey.slice(0, 12)}... (already set)`);
252
+ }
253
+ const keyInput = await prompt(currentKey
254
+ ? ' New API Key (Enter to keep current): '
255
+ : ' API Key (from Settings > API Keys): ');
256
+ const apiKey = keyInput || currentKey;
257
+ if (!apiKey) {
258
+ console.error('\n Error: API key is required.');
259
+ return 1;
260
+ }
261
+ // Hook ID
262
+ const currentHook = process.env.ZEPH_HOOK_ID || existing.hookId;
263
+ if (currentHook) {
264
+ console.log(` Hook ID: ${currentHook} (already set)`);
265
+ }
266
+ const hookInput = await prompt(currentHook
267
+ ? ' New Hook ID (Enter to keep, "none" to remove): '
268
+ : ' Hook ID (optional, for prompt/input): ');
269
+ const hookId = hookInput === 'none' ? undefined : (hookInput || currentHook);
270
+ // Base URL
271
+ const currentUrl = process.env.ZEPH_BASE_URL || existing.baseUrl;
272
+ const urlInput = await prompt(` Base URL (Enter for ${currentUrl || 'https://api.zeph.to/v1'}): `);
273
+ const baseUrl = urlInput || currentUrl;
274
+ // Save config
275
+ const config = { apiKey, ...(hookId && { hookId }), ...(baseUrl && { baseUrl }) };
276
+ saveConfig(config);
277
+ console.log(`\n Config saved to ${CONFIG_FILE}`);
278
+ // Test connection
279
+ console.log(' Testing connection...');
280
+ try {
281
+ const hook = new zeph_hook_js_1.ZephHook({ apiKey, ...(baseUrl && { baseUrl }) });
282
+ const result = await hook.notify({
283
+ title: 'Zeph Setup',
284
+ body: `CLI configured successfully (v${VERSION})`,
285
+ });
286
+ console.log(` Test push sent: ${result.pushId}`);
287
+ }
288
+ catch (err) {
289
+ console.error(` Test failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
290
+ console.error(' Config saved but connection failed. Check your API key.');
291
+ return 1;
292
+ }
293
+ console.log('\n Done! Restart Claude Code to apply.\n');
294
+ return 0;
295
+ };
219
296
  // ── Error Handler ───────────────────────────────────────────────
220
297
  const handleError = (err, isJson) => {
221
298
  if (err instanceof errors_js_1.QuotaExceededError) {
@@ -246,6 +323,8 @@ const main = async () => {
246
323
  return 0;
247
324
  }
248
325
  switch (command) {
326
+ case 'setup':
327
+ return handleSetup();
249
328
  case 'notify':
250
329
  return handleNotify(args);
251
330
  case 'list':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeph-to/hook-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Zeph push notification SDK + CLI — zero dependencies",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",