@lawrenceliang-btc/atel-sdk 1.1.19 → 1.1.20

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/bin/atel.mjs +68 -5
  2. package/package.json +1 -1
package/bin/atel.mjs CHANGED
@@ -6359,8 +6359,8 @@ async function cmdMilestoneFeedback(orderId) {
6359
6359
 
6360
6360
  async function cmdMilestoneSubmit(orderId, indexStr) {
6361
6361
  if (!orderId || indexStr === undefined) {
6362
- console.error('Usage: atel milestone-submit <orderId> <index> --result "结果描述"');
6363
- console.error(' atel milestone-submit <orderId> <index> --result ./file.pdf [--hash 0x...]');
6362
+ console.error('Usage: atel milestone-submit <orderId> <index> --result "结果描述" [--file <path>]');
6363
+ console.error(' atel milestone-submit <orderId> <index> --result ./file.pdf [--hash 0x...] [--file <path>]');
6364
6364
  process.exit(1);
6365
6365
  }
6366
6366
  const resultIdx = rawArgs.findIndex(a => a === '--result');
@@ -6394,11 +6394,35 @@ async function cmdMilestoneSubmit(orderId, indexStr) {
6394
6394
  resultHash = ethers.keccak256(ethers.toUtf8Bytes(result));
6395
6395
  }
6396
6396
 
6397
- console.log(`Submitting M${indexStr}: "${result.slice(0, 60)}${result.length > 60 ? '...' : ''}"`);
6397
+ // --file support: upload attachment before submitting
6398
+ let resultText = result;
6399
+ const filePath = rawArgs.find((a, i) => rawArgs[i - 1] === '--file');
6400
+ if (filePath) {
6401
+ const { execFileSync } = await import('child_process');
6402
+ const path = await import('path');
6403
+ try {
6404
+ const id = requireIdentity();
6405
+ const uploadResult = execFileSync('curl', ['-s', '-X', 'POST',
6406
+ `${PLATFORM_URL}/attachment/v1/upload`,
6407
+ '-F', `file=@${filePath}`,
6408
+ '-F', 'kind=file',
6409
+ '-F', `uploadedBy=${id.did}`
6410
+ ], { encoding: 'utf8' });
6411
+ const uploadData = JSON.parse(uploadResult);
6412
+ if (uploadData.attachmentId) {
6413
+ resultText += `\n[Attachment: ${uploadData.attachmentId} (${path.basename(filePath)})]`;
6414
+ console.error(`File uploaded: ${uploadData.attachmentId}`);
6415
+ }
6416
+ } catch (e) {
6417
+ console.error(`File upload failed: ${e.message}`);
6418
+ }
6419
+ }
6420
+
6421
+ console.log(`Submitting M${indexStr}: "${resultText.slice(0, 60)}${resultText.length > 60 ? '...' : ''}"`);
6398
6422
  console.log(`Hash: ${resultHash}`);
6399
6423
 
6400
6424
  const data = await signedFetch('POST', `/trade/v1/order/${orderId}/milestone/${indexStr}/submit`, {
6401
- resultSummary: result,
6425
+ resultSummary: resultText,
6402
6426
  resultHash,
6403
6427
  });
6404
6428
  console.log(JSON.stringify(data, null, 2));
@@ -6489,10 +6513,34 @@ async function cmdDispute(orderId, reason, description) {
6489
6513
  }
6490
6514
 
6491
6515
  async function cmdEvidence(disputeId, evidenceJson) {
6492
- if (!disputeId || !evidenceJson) { console.error('Usage: atel evidence <disputeId> <json>'); process.exit(1); }
6516
+ if (!disputeId || !evidenceJson) { console.error('Usage: atel evidence <disputeId> <json> [--file <path>]'); process.exit(1); }
6493
6517
  let evidence;
6494
6518
  try { evidence = JSON.parse(evidenceJson); } catch { console.error('Invalid JSON'); process.exit(1); }
6495
6519
 
6520
+ // --file support: upload attachment and attach to evidence
6521
+ const filePath = rawArgs.find((a, i) => rawArgs[i - 1] === '--file');
6522
+ if (filePath) {
6523
+ const { execFileSync } = await import('child_process');
6524
+ const path = await import('path');
6525
+ try {
6526
+ const id = requireIdentity();
6527
+ const uploadResult = execFileSync('curl', ['-s', '-X', 'POST',
6528
+ `${PLATFORM_URL}/attachment/v1/upload`,
6529
+ '-F', `file=@${filePath}`,
6530
+ '-F', 'kind=file',
6531
+ '-F', `uploadedBy=${id.did}`
6532
+ ], { encoding: 'utf8' });
6533
+ const uploadData = JSON.parse(uploadResult);
6534
+ if (uploadData.attachmentId) {
6535
+ evidence.attachmentId = uploadData.attachmentId;
6536
+ evidence.attachmentName = path.basename(filePath);
6537
+ console.error(`File uploaded: ${uploadData.attachmentId}`);
6538
+ }
6539
+ } catch (e) {
6540
+ console.error(`File upload failed: ${e.message}`);
6541
+ }
6542
+ }
6543
+
6496
6544
  // Submit to Platform API
6497
6545
  const data = await signedFetch('POST', `/dispute/v1/${disputeId}/evidence`, { evidence });
6498
6546
 
@@ -6548,6 +6596,21 @@ async function cmdCertStatus(did) {
6548
6596
  const text = await res.text(); console.error("DEBUG Response:", text); const data = JSON.parse(text);
6549
6597
  if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
6550
6598
  console.log(JSON.stringify(data, null, 2));
6599
+
6600
+ // Fetch and display certification requirements
6601
+ try {
6602
+ const reqResp = await fetch(`${PLATFORM_URL}/cert/v1/requirements`, { signal: AbortSignal.timeout(5000) });
6603
+ if (reqResp.ok) {
6604
+ const reqs = await reqResp.json();
6605
+ console.log('\nCertification Requirements:');
6606
+ if (reqs.certified) {
6607
+ console.log(` Certified: trust_score >= ${reqs.certified.minTrustScore}, cost: $${reqs.certified.cost}`);
6608
+ }
6609
+ if (reqs.enterprise) {
6610
+ console.log(` Enterprise: trust_score >= ${reqs.enterprise.minTrustScore}, cost: $${reqs.enterprise.cost}`);
6611
+ }
6612
+ }
6613
+ } catch {}
6551
6614
  }
6552
6615
 
6553
6616
  async function cmdCertRenew(level) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawrenceliang-btc/atel-sdk",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "description": "ATEL Protocol SDK - Agent Trust & Exchange Layer",
5
5
  "repository": {
6
6
  "type": "git",