@paylobster/cli 4.5.0 → 4.6.1

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 (39) hide show
  1. package/EXAMPLES.md +61 -61
  2. package/dist/src/commands/alerts.d.ts +3 -0
  3. package/dist/src/commands/alerts.d.ts.map +1 -0
  4. package/dist/src/commands/alerts.js +181 -0
  5. package/dist/src/commands/alerts.js.map +1 -0
  6. package/dist/src/commands/init.d.ts +3 -0
  7. package/dist/src/commands/init.d.ts.map +1 -0
  8. package/dist/src/commands/init.js +232 -0
  9. package/dist/src/commands/init.js.map +1 -0
  10. package/dist/src/commands/link.d.ts +6 -0
  11. package/dist/src/commands/link.d.ts.map +1 -0
  12. package/dist/src/commands/link.js +188 -0
  13. package/dist/src/commands/link.js.map +1 -0
  14. package/dist/src/commands/refund.d.ts +6 -0
  15. package/dist/src/commands/refund.d.ts.map +1 -0
  16. package/dist/src/commands/refund.js +199 -0
  17. package/dist/src/commands/refund.js.map +1 -0
  18. package/dist/src/commands/swap.d.ts.map +1 -1
  19. package/dist/src/commands/swap.js +93 -1
  20. package/dist/src/commands/swap.js.map +1 -1
  21. package/dist/src/commands/webhook.d.ts +6 -0
  22. package/dist/src/commands/webhook.d.ts.map +1 -0
  23. package/dist/src/commands/webhook.js +208 -0
  24. package/dist/src/commands/webhook.js.map +1 -0
  25. package/dist/src/index.js +10 -0
  26. package/dist/src/index.js.map +1 -1
  27. package/dist/src/lib/contracts.d.ts +23 -161
  28. package/dist/src/lib/contracts.d.ts.map +1 -1
  29. package/dist/src/lib/contracts.js +6 -6
  30. package/dist/src/lib/contracts.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/commands/alerts.ts +210 -0
  33. package/src/commands/init.ts +256 -0
  34. package/src/commands/link.ts +240 -0
  35. package/src/commands/refund.ts +250 -0
  36. package/src/commands/swap.ts +120 -1
  37. package/src/commands/webhook.ts +260 -0
  38. package/src/index.ts +10 -0
  39. package/src/lib/contracts.ts +6 -6
@@ -0,0 +1,260 @@
1
+ import { Command } from 'commander';
2
+ import { success, error, info, withSpinner, outputJSON } from '../lib/display';
3
+ import type { OutputOptions } from '../lib/types';
4
+
5
+ const API_URL = process.env.PAYLOBSTER_API_URL || 'https://paylobster.com';
6
+
7
+ interface Webhook {
8
+ id: string;
9
+ url: string;
10
+ events: string[];
11
+ secret?: string;
12
+ createdAt: string;
13
+ status: 'active' | 'paused';
14
+ lastDeliveryAttempt?: string;
15
+ lastDeliveryStatus?: 'success' | 'failed';
16
+ }
17
+
18
+ /**
19
+ * Webhooks command
20
+ */
21
+ export function createWebhookCommand(): Command {
22
+ const cmd = new Command('webhooks')
23
+ .description('Register and manage webhooks');
24
+
25
+ // Register subcommand
26
+ cmd
27
+ .command('register')
28
+ .description('Register a new webhook')
29
+ .requiredOption('--url <url>', 'Webhook URL')
30
+ .requiredOption('--events <events>', 'Comma-separated event types')
31
+ .option('--secret <secret>', 'Webhook secret for signature verification')
32
+ .option('--json', 'Output as JSON')
33
+ .action(async (options: {
34
+ url: string;
35
+ events: string;
36
+ secret?: string;
37
+ } & OutputOptions) => {
38
+ try {
39
+ // Validate URL
40
+ try {
41
+ new URL(options.url);
42
+ } catch {
43
+ error('Invalid URL format');
44
+ process.exit(1);
45
+ }
46
+
47
+ // Parse events
48
+ const events = options.events.split(',').map(e => e.trim()).filter(Boolean);
49
+ if (events.length === 0) {
50
+ error('At least one event type is required');
51
+ process.exit(1);
52
+ }
53
+
54
+ const webhook = await withSpinner(
55
+ 'Registering webhook...',
56
+ async () => {
57
+ const response = await fetch(`${API_URL}/api/v3/webhooks`, {
58
+ method: 'POST',
59
+ headers: {
60
+ 'Content-Type': 'application/json',
61
+ },
62
+ body: JSON.stringify({
63
+ url: options.url,
64
+ events,
65
+ secret: options.secret,
66
+ }),
67
+ });
68
+
69
+ if (!response.ok) {
70
+ const err = await response.json() as { error?: string };
71
+ throw new Error(err.error || 'Failed to register webhook');
72
+ }
73
+
74
+ return response.json() as Promise<Webhook>;
75
+ }
76
+ );
77
+
78
+ if (outputJSON(webhook, options)) {
79
+ return;
80
+ }
81
+
82
+ success('Webhook registered!');
83
+ console.log();
84
+ console.log(' Webhook ID: ', webhook.id);
85
+ console.log(' URL: ', webhook.url);
86
+ console.log(' Events: ', webhook.events.join(', '));
87
+ console.log(' Status: ', webhook.status);
88
+ if (webhook.secret) {
89
+ console.log(' Secret: ', webhook.secret);
90
+ }
91
+ console.log();
92
+ info('Your webhook will receive notifications for the specified events');
93
+ } catch (err) {
94
+ error(`Failed to register webhook: ${(err as Error).message}`);
95
+ process.exit(1);
96
+ }
97
+ });
98
+
99
+ // List subcommand
100
+ cmd
101
+ .command('list')
102
+ .description('List all registered webhooks')
103
+ .option('--address <address>', 'Filter by address')
104
+ .option('--json', 'Output as JSON')
105
+ .action(async (options: {
106
+ address?: string;
107
+ } & OutputOptions) => {
108
+ try {
109
+ const result = await withSpinner(
110
+ 'Fetching webhooks...',
111
+ async () => {
112
+ const url = new URL(`${API_URL}/api/v3/webhooks`);
113
+ if (options.address) {
114
+ url.searchParams.set('address', options.address);
115
+ }
116
+
117
+ const response = await fetch(url.toString(), {
118
+ method: 'GET',
119
+ headers: {
120
+ 'Content-Type': 'application/json',
121
+ },
122
+ });
123
+
124
+ if (!response.ok) {
125
+ const err = await response.json() as { error?: string };
126
+ throw new Error(err.error || 'Failed to fetch webhooks');
127
+ }
128
+
129
+ return response.json() as Promise<{ webhooks: Webhook[] }>;
130
+ }
131
+ );
132
+
133
+ if (outputJSON(result, options)) {
134
+ return;
135
+ }
136
+
137
+ if (result.webhooks.length === 0) {
138
+ info('No webhooks registered');
139
+ return;
140
+ }
141
+
142
+ console.log();
143
+ console.log(`Found ${result.webhooks.length} webhook(s):`);
144
+ console.log();
145
+
146
+ for (const webhook of result.webhooks) {
147
+ console.log(` ${webhook.id}`);
148
+ console.log(` URL: ${webhook.url}`);
149
+ console.log(` Events: ${webhook.events.join(', ')}`);
150
+ console.log(` Status: ${webhook.status === 'active' ? '✅ Active' : '⏸️ Paused'}`);
151
+ if (webhook.lastDeliveryAttempt) {
152
+ const status = webhook.lastDeliveryStatus === 'success' ? '✅' : '❌';
153
+ console.log(` Last: ${status} ${new Date(webhook.lastDeliveryAttempt).toLocaleString()}`);
154
+ }
155
+ console.log();
156
+ }
157
+ } catch (err) {
158
+ error(`Failed to fetch webhooks: ${(err as Error).message}`);
159
+ process.exit(1);
160
+ }
161
+ });
162
+
163
+ // Get subcommand
164
+ cmd
165
+ .command('get <id>')
166
+ .description('Get webhook details')
167
+ .option('--include-secret', 'Include webhook secret in output')
168
+ .option('--json', 'Output as JSON')
169
+ .action(async (id: string, options: {
170
+ includeSecret?: boolean;
171
+ } & OutputOptions) => {
172
+ try {
173
+ const webhook = await withSpinner(
174
+ 'Fetching webhook...',
175
+ async () => {
176
+ const url = new URL(`${API_URL}/api/v3/webhooks/${id}`);
177
+ if (options.includeSecret) {
178
+ url.searchParams.set('includeSecret', 'true');
179
+ }
180
+
181
+ const response = await fetch(url.toString(), {
182
+ method: 'GET',
183
+ headers: {
184
+ 'Content-Type': 'application/json',
185
+ },
186
+ });
187
+
188
+ if (!response.ok) {
189
+ const err = await response.json() as { error?: string };
190
+ throw new Error(err.error || 'Failed to fetch webhook');
191
+ }
192
+
193
+ return response.json() as Promise<Webhook>;
194
+ }
195
+ );
196
+
197
+ if (outputJSON(webhook, options)) {
198
+ return;
199
+ }
200
+
201
+ console.log();
202
+ console.log('Webhook Details:');
203
+ console.log(' ID: ', webhook.id);
204
+ console.log(' URL: ', webhook.url);
205
+ console.log(' Events: ', webhook.events.join(', '));
206
+ console.log(' Status: ', webhook.status === 'active' ? '✅ Active' : '⏸️ Paused');
207
+ if (webhook.secret) {
208
+ console.log(' Secret: ', webhook.secret);
209
+ }
210
+ console.log(' Created: ', new Date(webhook.createdAt).toLocaleString());
211
+ if (webhook.lastDeliveryAttempt) {
212
+ const status = webhook.lastDeliveryStatus === 'success' ? '✅ Success' : '❌ Failed';
213
+ console.log(' Last: ', `${status} at ${new Date(webhook.lastDeliveryAttempt).toLocaleString()}`);
214
+ }
215
+ console.log();
216
+ } catch (err) {
217
+ error(`Failed to fetch webhook: ${(err as Error).message}`);
218
+ process.exit(1);
219
+ }
220
+ });
221
+
222
+ // Delete subcommand
223
+ cmd
224
+ .command('delete <id>')
225
+ .description('Delete a webhook')
226
+ .option('--json', 'Output as JSON')
227
+ .action(async (id: string, options: OutputOptions) => {
228
+ try {
229
+ const result = await withSpinner(
230
+ 'Deleting webhook...',
231
+ async () => {
232
+ const response = await fetch(`${API_URL}/api/v3/webhooks/${id}`, {
233
+ method: 'DELETE',
234
+ headers: {
235
+ 'Content-Type': 'application/json',
236
+ },
237
+ });
238
+
239
+ if (!response.ok) {
240
+ const err = await response.json() as { error?: string };
241
+ throw new Error(err.error || 'Failed to delete webhook');
242
+ }
243
+
244
+ return response.json() as Promise<{ success: boolean; message: string }>;
245
+ }
246
+ );
247
+
248
+ if (outputJSON(result, options)) {
249
+ return;
250
+ }
251
+
252
+ success('Webhook deleted successfully');
253
+ } catch (err) {
254
+ error(`Failed to delete webhook: ${(err as Error).message}`);
255
+ process.exit(1);
256
+ }
257
+ });
258
+
259
+ return cmd;
260
+ }
package/src/index.ts CHANGED
@@ -29,6 +29,11 @@ import { createHealthCommand } from './commands/health';
29
29
  import { createSearchCommand } from './commands/search';
30
30
  import { createExportCommand } from './commands/export';
31
31
  import { createTrustGraphCommand } from './commands/trust-graph';
32
+ import { createInitCommand } from './commands/init';
33
+ import { createLinkCommand } from './commands/link';
34
+ import { createWebhookCommand } from './commands/webhook';
35
+ import { createRefundCommand } from './commands/refund';
36
+ import { createAlertsCommand } from './commands/alerts';
32
37
  import chalk from 'chalk';
33
38
 
34
39
  // Load environment variables from .env file if present
@@ -83,6 +88,11 @@ program.addCommand(createHealthCommand());
83
88
  program.addCommand(createSearchCommand());
84
89
  program.addCommand(createExportCommand());
85
90
  program.addCommand(createTrustGraphCommand());
91
+ program.addCommand(createInitCommand());
92
+ program.addCommand(createLinkCommand());
93
+ program.addCommand(createWebhookCommand());
94
+ program.addCommand(createRefundCommand());
95
+ program.addCommand(createAlertsCommand());
86
96
  registerInvestCommand(program);
87
97
 
88
98
  // Handle errors
@@ -8,21 +8,21 @@ import type { Network, AgentInfo, Reputation, CreditStatus, EscrowInfo, Balance
8
8
  const CONTRACTS_MAINNET = {
9
9
  IDENTITY: '0xA174ee274F870631B3c330a85EBCad74120BE662' as Address,
10
10
  REPUTATION: '0x02bb4132a86134684976E2a52E43D59D89E64b29' as Address,
11
- CREDIT: '0xD9241Ce8a721Ef5fcCAc5A11983addC526eC80E1' as Address,
12
- ESCROW: '0x49EdEe04c78B7FeD5248A20706c7a6c540748806' as Address,
11
+ CREDIT: '0x4c22B52eacAB9eD2Ce018d032739a93eC68eD27a' as Address,
12
+ ESCROW: '0x703B528C1b07cd27992af9Ae11DD67bE685E489e' as Address,
13
13
  USDC: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' as Address,
14
- TRUST_GRAPH: '0x0000000000000000000000000000000000000000' as Address, // TODO: Deploy TrustGraph
14
+ TRUST_GRAPH: '0xbccd1d0a37ce981a13b3392d7881f94e28fa693b' as Address,
15
15
  };
16
16
 
17
17
  const CONTRACTS_SEPOLIA = {
18
18
  IDENTITY: '0x3dfA02Ed4F0e4F10E8031d7a4cB8Ea0bBbFbCB8c' as Address,
19
19
  // NOTE: Reputation address provided has 41 hex chars (invalid). Using placeholder.
20
- // Original (invalid): 0xb0033901e3b94f4F36dA0b3e396942C1e78205C7d
21
- REPUTATION: '0x0000000000000000000000000000000000000000' as Address, // TODO: Fix this address
20
+ // Was broken (41 hex chars) — fixed to correct address
21
+ REPUTATION: '0xb0033901e3b94f4F36dA0b3e59A1F4AD9f4f1697' as Address,
22
22
  CREDIT: '0xBA64e2b2F2a80D03A4B13b3396942C1e78205C7d' as Address,
23
23
  ESCROW: '0x78D1f50a1965dE34f6b5a3D3546C94FE1809Cd82' as Address,
24
24
  USDC: '0x036CbD53842c5426634e7929541eC2318f3dCF7e' as Address,
25
- TRUST_GRAPH: '0x0000000000000000000000000000000000000000' as Address, // TODO: Deploy TrustGraph
25
+ TRUST_GRAPH: '0xbccd1d0a37ce981a13b3392d7881f94e28fa693b' as Address,
26
26
  };
27
27
 
28
28
  // ABIs