@paylobster/cli 4.0.1 → 4.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.
Files changed (45) hide show
  1. package/README.md +78 -249
  2. package/dist/src/commands/cascade.d.ts +3 -0
  3. package/dist/src/commands/cascade.d.ts.map +1 -0
  4. package/dist/src/commands/cascade.js +242 -0
  5. package/dist/src/commands/cascade.js.map +1 -0
  6. package/dist/src/commands/compliance.d.ts +3 -0
  7. package/dist/src/commands/compliance.d.ts.map +1 -0
  8. package/dist/src/commands/compliance.js +121 -0
  9. package/dist/src/commands/compliance.js.map +1 -0
  10. package/dist/src/commands/credit-score.d.ts +3 -0
  11. package/dist/src/commands/credit-score.d.ts.map +1 -0
  12. package/dist/src/commands/credit-score.js +174 -0
  13. package/dist/src/commands/credit-score.js.map +1 -0
  14. package/dist/src/commands/dispute.d.ts +3 -0
  15. package/dist/src/commands/dispute.d.ts.map +1 -0
  16. package/dist/src/commands/dispute.js +241 -0
  17. package/dist/src/commands/dispute.js.map +1 -0
  18. package/dist/src/commands/intent.d.ts +3 -0
  19. package/dist/src/commands/intent.d.ts.map +1 -0
  20. package/dist/src/commands/intent.js +227 -0
  21. package/dist/src/commands/intent.js.map +1 -0
  22. package/dist/src/commands/oracle.d.ts +3 -0
  23. package/dist/src/commands/oracle.d.ts.map +1 -0
  24. package/dist/src/commands/oracle.js +114 -0
  25. package/dist/src/commands/oracle.js.map +1 -0
  26. package/dist/src/commands/revenue-share.d.ts +3 -0
  27. package/dist/src/commands/revenue-share.d.ts.map +1 -0
  28. package/dist/src/commands/revenue-share.js +185 -0
  29. package/dist/src/commands/revenue-share.js.map +1 -0
  30. package/dist/src/commands/stream.d.ts +3 -0
  31. package/dist/src/commands/stream.d.ts.map +1 -0
  32. package/dist/src/commands/stream.js +213 -0
  33. package/dist/src/commands/stream.js.map +1 -0
  34. package/dist/src/index.js +16 -0
  35. package/dist/src/index.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/commands/cascade.ts +280 -0
  38. package/src/commands/compliance.ts +123 -0
  39. package/src/commands/credit-score.ts +193 -0
  40. package/src/commands/dispute.ts +274 -0
  41. package/src/commands/intent.ts +261 -0
  42. package/src/commands/oracle.ts +116 -0
  43. package/src/commands/revenue-share.ts +213 -0
  44. package/src/commands/stream.ts +244 -0
  45. package/src/index.ts +16 -0
@@ -0,0 +1,193 @@
1
+ import { Command } from 'commander';
2
+ import { success, error, info, warning, withSpinner, outputJSON, formatAddress, printReputation, createTable } from '../lib/display';
3
+ import { getWalletAddress } from '../lib/wallet';
4
+ import type { OutputOptions } from '../lib/types';
5
+ import chalk from 'chalk';
6
+
7
+ export function createCreditScoreCommand(): Command {
8
+ const cmd = new Command('credit-score')
9
+ .description('Check credit scores and manage credit lines')
10
+ .argument('[address]', 'Address to check (optional, defaults to your address)')
11
+ .option('--json', 'Output as JSON')
12
+ .action(async (address: string | undefined, options: OutputOptions) => {
13
+ try {
14
+ const targetAddress = address || getWalletAddress();
15
+
16
+ if (address && (!address.startsWith('0x') || address.length !== 42)) {
17
+ error('Invalid address format');
18
+ process.exit(1);
19
+ }
20
+
21
+ // Placeholder data
22
+ const creditData = {
23
+ address: targetAddress,
24
+ score: 750,
25
+ creditLine: '5000 USDC',
26
+ availableCredit: '3500 USDC',
27
+ usedCredit: '1500 USDC',
28
+ paymentHistory: 'Excellent',
29
+ onTimePayments: 45,
30
+ latePayments: 2,
31
+ totalTransactions: 47,
32
+ };
33
+
34
+ if (outputJSON(creditData, options)) {
35
+ return;
36
+ }
37
+
38
+ console.log();
39
+ console.log(chalk.bold.cyan('🦞 Credit Score Report'));
40
+ console.log(chalk.gray('─'.repeat(50)));
41
+ console.log('Address: ', formatAddress(creditData.address));
42
+ console.log('Credit Score: ', printReputation(creditData.score / 10)); // Convert to 0-100 scale
43
+ console.log();
44
+ console.log(chalk.bold('Credit Line'));
45
+ console.log(' Total: ', creditData.creditLine);
46
+ console.log(' Available: ', chalk.green(creditData.availableCredit));
47
+ console.log(' Used: ', chalk.yellow(creditData.usedCredit));
48
+ console.log();
49
+ console.log(chalk.bold('Payment History'));
50
+ console.log(' On-time: ', chalk.green(creditData.onTimePayments));
51
+ console.log(' Late: ', chalk.red(creditData.latePayments));
52
+ console.log(' Total: ', creditData.totalTransactions);
53
+ console.log(' Rating: ', chalk.green(creditData.paymentHistory));
54
+ console.log();
55
+ } catch (err) {
56
+ error(`Failed to get credit score: ${err}`);
57
+ process.exit(1);
58
+ }
59
+ });
60
+
61
+ // plob credit-score request
62
+ cmd
63
+ .command('request')
64
+ .description('Request a credit line')
65
+ .requiredOption('--amount <amount>', 'Credit line amount in USDC')
66
+ .option('--json', 'Output as JSON')
67
+ .action(async (options: { amount: string } & OutputOptions) => {
68
+ try {
69
+ const amount = parseFloat(options.amount);
70
+ if (isNaN(amount) || amount <= 0) {
71
+ error('Invalid amount. Must be a positive number');
72
+ process.exit(1);
73
+ }
74
+
75
+ info(`Requesting credit line: ${options.amount} USDC`);
76
+
77
+ const requestId = Math.floor(Math.random() * 1000000);
78
+
79
+ const txHash = await withSpinner(
80
+ 'Submitting credit line request...',
81
+ async () => {
82
+ // Placeholder - implement actual contract call
83
+ await new Promise(resolve => setTimeout(resolve, 2000));
84
+ return '0x' + Math.random().toString(16).substring(2, 66);
85
+ }
86
+ );
87
+
88
+ if (outputJSON({
89
+ requestId,
90
+ amount: options.amount,
91
+ txHash,
92
+ }, options)) {
93
+ return;
94
+ }
95
+
96
+ success('Credit line request submitted!');
97
+ info(`Request ID: ${requestId}`);
98
+ info(`Amount: ${options.amount} USDC`);
99
+ info(`Transaction: ${txHash}`);
100
+ console.log();
101
+ warning('Credit requests are subject to approval based on your credit score.');
102
+ } catch (err) {
103
+ error(`Failed to request credit line: ${err}`);
104
+ process.exit(1);
105
+ }
106
+ });
107
+
108
+ // plob credit-score draw
109
+ cmd
110
+ .command('draw')
111
+ .description('Draw from credit line')
112
+ .argument('<creditLineId>', 'Credit line ID')
113
+ .requiredOption('--amount <amount>', 'Amount to draw in USDC')
114
+ .option('--json', 'Output as JSON')
115
+ .action(async (creditLineId: string, options: { amount: string } & OutputOptions) => {
116
+ try {
117
+ const amount = parseFloat(options.amount);
118
+ if (isNaN(amount) || amount <= 0) {
119
+ error('Invalid amount. Must be a positive number');
120
+ process.exit(1);
121
+ }
122
+
123
+ const txHash = await withSpinner(
124
+ `Drawing ${options.amount} USDC from credit line...`,
125
+ async () => {
126
+ // Placeholder - implement actual contract call
127
+ await new Promise(resolve => setTimeout(resolve, 1500));
128
+ return '0x' + Math.random().toString(16).substring(2, 66);
129
+ }
130
+ );
131
+
132
+ if (outputJSON({
133
+ creditLineId,
134
+ amount: options.amount,
135
+ txHash,
136
+ }, options)) {
137
+ return;
138
+ }
139
+
140
+ success('Credit drawn successfully!');
141
+ info(`Credit Line ID: ${creditLineId}`);
142
+ info(`Amount: ${options.amount} USDC`);
143
+ info(`Transaction: ${txHash}`);
144
+ } catch (err) {
145
+ error(`Failed to draw credit: ${err}`);
146
+ process.exit(1);
147
+ }
148
+ });
149
+
150
+ // plob credit-score repay
151
+ cmd
152
+ .command('repay')
153
+ .description('Repay credit line')
154
+ .argument('<creditLineId>', 'Credit line ID')
155
+ .requiredOption('--amount <amount>', 'Amount to repay in USDC')
156
+ .option('--json', 'Output as JSON')
157
+ .action(async (creditLineId: string, options: { amount: string } & OutputOptions) => {
158
+ try {
159
+ const amount = parseFloat(options.amount);
160
+ if (isNaN(amount) || amount <= 0) {
161
+ error('Invalid amount. Must be a positive number');
162
+ process.exit(1);
163
+ }
164
+
165
+ const txHash = await withSpinner(
166
+ `Repaying ${options.amount} USDC to credit line...`,
167
+ async () => {
168
+ // Placeholder - implement actual contract call
169
+ await new Promise(resolve => setTimeout(resolve, 1500));
170
+ return '0x' + Math.random().toString(16).substring(2, 66);
171
+ }
172
+ );
173
+
174
+ if (outputJSON({
175
+ creditLineId,
176
+ amount: options.amount,
177
+ txHash,
178
+ }, options)) {
179
+ return;
180
+ }
181
+
182
+ success('Repayment successful!');
183
+ info(`Credit Line ID: ${creditLineId}`);
184
+ info(`Amount: ${options.amount} USDC`);
185
+ info(`Transaction: ${txHash}`);
186
+ } catch (err) {
187
+ error(`Failed to repay credit: ${err}`);
188
+ process.exit(1);
189
+ }
190
+ });
191
+
192
+ return cmd;
193
+ }
@@ -0,0 +1,274 @@
1
+ import { Command } from 'commander';
2
+ import { success, error, info, warning, withSpinner, outputJSON, formatAddress, confirm, createTable, formatStatus } from '../lib/display';
3
+ import type { OutputOptions } from '../lib/types';
4
+ import fs from 'fs/promises';
5
+ import path from 'path';
6
+
7
+ export function createDisputeCommand(): Command {
8
+ const cmd = new Command('dispute')
9
+ .description('Manage escrow disputes');
10
+
11
+ // plob dispute open
12
+ cmd
13
+ .command('open')
14
+ .description('Open a dispute for an escrow')
15
+ .requiredOption('--escrow <id>', 'Escrow ID')
16
+ .requiredOption('--reason <reason>', 'Dispute reason')
17
+ .option('--evidence <file>', 'Evidence file path')
18
+ .option('--json', 'Output as JSON')
19
+ .action(async (options: {
20
+ escrow: string;
21
+ reason: string;
22
+ evidence?: string;
23
+ } & OutputOptions) => {
24
+ try {
25
+ let evidenceHash = null;
26
+
27
+ // Handle evidence file if provided
28
+ if (options.evidence) {
29
+ const evidencePath = path.resolve(options.evidence);
30
+ try {
31
+ const evidenceData = await fs.readFile(evidencePath);
32
+ info(`Evidence file loaded: ${path.basename(evidencePath)} (${evidenceData.length} bytes)`);
33
+
34
+ // Placeholder: Upload to IPFS or similar
35
+ evidenceHash = '0x' + Math.random().toString(16).substring(2, 66);
36
+ info(`Evidence uploaded: ${evidenceHash}`);
37
+ } catch (err) {
38
+ error(`Failed to read evidence file: ${err}`);
39
+ process.exit(1);
40
+ }
41
+ }
42
+
43
+ const disputeId = Math.floor(Math.random() * 1000000);
44
+
45
+ const txHash = await withSpinner(
46
+ 'Opening dispute...',
47
+ async () => {
48
+ // Placeholder - implement actual contract call
49
+ await new Promise(resolve => setTimeout(resolve, 2000));
50
+ return '0x' + Math.random().toString(16).substring(2, 66);
51
+ }
52
+ );
53
+
54
+ if (outputJSON({
55
+ disputeId,
56
+ escrowId: options.escrow,
57
+ reason: options.reason,
58
+ evidenceHash,
59
+ txHash,
60
+ }, options)) {
61
+ return;
62
+ }
63
+
64
+ success('Dispute opened!');
65
+ info(`Dispute ID: ${disputeId}`);
66
+ info(`Escrow ID: ${options.escrow}`);
67
+ info(`Reason: ${options.reason}`);
68
+ if (evidenceHash) {
69
+ info(`Evidence: ${evidenceHash}`);
70
+ }
71
+ info(`Transaction: ${txHash}`);
72
+ } catch (err) {
73
+ error(`Failed to open dispute: ${err}`);
74
+ process.exit(1);
75
+ }
76
+ });
77
+
78
+ // plob dispute submit
79
+ cmd
80
+ .command('submit')
81
+ .description('Submit additional evidence for a dispute')
82
+ .argument('<disputeId>', 'Dispute ID')
83
+ .requiredOption('--evidence <file>', 'Evidence file path')
84
+ .option('--json', 'Output as JSON')
85
+ .action(async (disputeId: string, options: { evidence: string } & OutputOptions) => {
86
+ try {
87
+ const evidencePath = path.resolve(options.evidence);
88
+ const evidenceData = await fs.readFile(evidencePath);
89
+
90
+ info(`Submitting evidence: ${path.basename(evidencePath)} (${evidenceData.length} bytes)`);
91
+
92
+ const evidenceHash = '0x' + Math.random().toString(16).substring(2, 66);
93
+
94
+ const txHash = await withSpinner(
95
+ 'Submitting evidence...',
96
+ async () => {
97
+ // Placeholder - implement actual contract call
98
+ await new Promise(resolve => setTimeout(resolve, 1500));
99
+ return '0x' + Math.random().toString(16).substring(2, 66);
100
+ }
101
+ );
102
+
103
+ if (outputJSON({
104
+ disputeId,
105
+ evidenceHash,
106
+ txHash,
107
+ }, options)) {
108
+ return;
109
+ }
110
+
111
+ success('Evidence submitted!');
112
+ info(`Dispute ID: ${disputeId}`);
113
+ info(`Evidence: ${evidenceHash}`);
114
+ info(`Transaction: ${txHash}`);
115
+ } catch (err) {
116
+ error(`Failed to submit evidence: ${err}`);
117
+ process.exit(1);
118
+ }
119
+ });
120
+
121
+ // plob dispute get
122
+ cmd
123
+ .command('get')
124
+ .description('Get dispute details')
125
+ .argument('<disputeId>', 'Dispute ID')
126
+ .option('--json', 'Output as JSON')
127
+ .action(async (disputeId: string, options: OutputOptions) => {
128
+ try {
129
+ // Placeholder data
130
+ const dispute = {
131
+ id: disputeId,
132
+ escrowId: '123',
133
+ plaintiff: '0x1234567890123456789012345678901234567890',
134
+ defendant: '0x0987654321098765432109876543210987654321',
135
+ reason: 'Service not delivered as agreed',
136
+ status: 'pending',
137
+ evidence: [
138
+ '0xabcd1234...',
139
+ '0xef567890...',
140
+ ],
141
+ createdAt: new Date().toISOString(),
142
+ };
143
+
144
+ if (outputJSON(dispute, options)) {
145
+ return;
146
+ }
147
+
148
+ console.log();
149
+ console.log('Dispute ID: ', dispute.id);
150
+ console.log('Escrow ID: ', dispute.escrowId);
151
+ console.log('Plaintiff: ', dispute.plaintiff);
152
+ console.log('Defendant: ', dispute.defendant);
153
+ console.log('Reason: ', dispute.reason);
154
+ console.log('Status: ', formatStatus(dispute.status));
155
+ console.log('Evidence: ', dispute.evidence.length, 'file(s)');
156
+ console.log('Created: ', dispute.createdAt);
157
+ console.log();
158
+ } catch (err) {
159
+ error(`Failed to get dispute: ${err}`);
160
+ process.exit(1);
161
+ }
162
+ });
163
+
164
+ // plob dispute settle
165
+ cmd
166
+ .command('settle')
167
+ .description('Settle a dispute')
168
+ .argument('<disputeId>', 'Dispute ID')
169
+ .requiredOption('--terms <terms>', 'Settlement terms')
170
+ .option('--yes', 'Skip confirmation')
171
+ .option('--json', 'Output as JSON')
172
+ .action(async (disputeId: string, options: {
173
+ terms: string;
174
+ yes?: boolean;
175
+ } & OutputOptions) => {
176
+ try {
177
+ if (!options.yes) {
178
+ console.log();
179
+ console.log('Settlement terms:', options.terms);
180
+ console.log();
181
+
182
+ const confirmed = await confirm(`Settle dispute ${disputeId}?`);
183
+ if (!confirmed) {
184
+ info('Cancelled');
185
+ process.exit(0);
186
+ }
187
+ }
188
+
189
+ const txHash = await withSpinner(
190
+ 'Settling dispute...',
191
+ async () => {
192
+ // Placeholder - implement actual contract call
193
+ await new Promise(resolve => setTimeout(resolve, 2000));
194
+ return '0x' + Math.random().toString(16).substring(2, 66);
195
+ }
196
+ );
197
+
198
+ if (outputJSON({
199
+ disputeId,
200
+ terms: options.terms,
201
+ txHash,
202
+ }, options)) {
203
+ return;
204
+ }
205
+
206
+ success('Dispute settled!');
207
+ info(`Dispute ID: ${disputeId}`);
208
+ info(`Terms: ${options.terms}`);
209
+ info(`Transaction: ${txHash}`);
210
+ } catch (err) {
211
+ error(`Failed to settle dispute: ${err}`);
212
+ process.exit(1);
213
+ }
214
+ });
215
+
216
+ // plob dispute list
217
+ cmd
218
+ .command('list')
219
+ .description('List disputes')
220
+ .option('--json', 'Output as JSON')
221
+ .action(async (options: OutputOptions) => {
222
+ try {
223
+ // Placeholder data
224
+ const disputes = [
225
+ {
226
+ id: 1,
227
+ escrowId: 123,
228
+ plaintiff: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
229
+ defendant: '0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199',
230
+ reason: 'Service not delivered',
231
+ status: 'pending',
232
+ },
233
+ {
234
+ id: 2,
235
+ escrowId: 456,
236
+ plaintiff: '0x1234567890123456789012345678901234567890',
237
+ defendant: '0x0987654321098765432109876543210987654321',
238
+ reason: 'Quality issues',
239
+ status: 'settled',
240
+ },
241
+ ];
242
+
243
+ if (outputJSON(disputes, options)) {
244
+ return;
245
+ }
246
+
247
+ if (disputes.length === 0) {
248
+ info('No disputes found');
249
+ return;
250
+ }
251
+
252
+ const table = createTable({
253
+ head: ['ID', 'Escrow', 'Plaintiff', 'Defendant', 'Status'],
254
+ });
255
+
256
+ for (const dispute of disputes) {
257
+ table.push([
258
+ dispute.id,
259
+ dispute.escrowId,
260
+ formatAddress(dispute.plaintiff),
261
+ formatAddress(dispute.defendant),
262
+ formatStatus(dispute.status),
263
+ ]);
264
+ }
265
+
266
+ console.log(table.toString());
267
+ } catch (err) {
268
+ error(`Failed to list disputes: ${err}`);
269
+ process.exit(1);
270
+ }
271
+ });
272
+
273
+ return cmd;
274
+ }