@parall/cli 1.58.0 → 1.58.2

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.
@@ -1,3 +1,3 @@
1
- import { Command } from 'commander';
1
+ import type { Command } from 'commander';
2
2
  export declare function registerFileCommands(program: Command): void;
3
3
  //# sourceMappingURL=files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/commands/files.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAkEpD"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/commands/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAsCpD"}
@@ -1,7 +1,6 @@
1
- import * as fs from 'node:fs';
2
- import * as path from 'node:path';
3
1
  import { resolveCredentials } from '../lib/client.js';
4
- import { printJson, printError, stripPrllScheme } from '../lib/output.js';
2
+ import { downloadAttachment } from '../lib/download-attachment.js';
3
+ import { printError, printJson, stripPrllScheme } from '../lib/output.js';
5
4
  import { uploadFile } from '../lib/upload.js';
6
5
  export function registerFileCommands(program) {
7
6
  const files = program.command('files').description('Upload and download files');
@@ -33,29 +32,7 @@ export function registerFileCommands(program) {
33
32
  try {
34
33
  const { client } = resolveCredentials();
35
34
  const id = stripPrllScheme(attachmentId);
36
- const fileInfo = await client.getFileUrl(id);
37
- // Download the file
38
- const res = await fetch(fileInfo.url);
39
- if (!res.ok) {
40
- throw new Error(`Download failed: ${res.status} ${res.statusText}`);
41
- }
42
- const buffer = Buffer.from(await res.arrayBuffer());
43
- // Sanitize server-provided filename to prevent path traversal
44
- const safeName = path.basename(fileInfo.file_name || id);
45
- // Determine output path
46
- const outputPath = opts.output ? path.resolve(opts.output) : path.resolve(safeName);
47
- // If output is a directory, write file inside it
48
- let finalPath = outputPath;
49
- if (fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()) {
50
- finalPath = path.join(outputPath, safeName);
51
- }
52
- fs.writeFileSync(finalPath, buffer);
53
- printJson({
54
- path: finalPath,
55
- file_name: fileInfo.file_name,
56
- file_size: fileInfo.file_size,
57
- mime_type: fileInfo.mime_type,
58
- });
35
+ printJson(await downloadAttachment(client, id, opts.output));
59
36
  }
60
37
  catch (err) {
61
38
  printError(err);
@@ -1,4 +1,4 @@
1
- import { Command } from 'commander';
1
+ import type { Command } from 'commander';
2
2
  /**
3
3
  * `parall wechat …` — the per-vendor platform verb for the personal-WeChat
4
4
  * protocol channel (wechatapi.net, tier B in the multi-channel
@@ -1 +1 @@
1
- {"version":3,"file":"wechat.d.ts","sourceRoot":"","sources":["../../src/commands/wechat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QA0KtD"}
1
+ {"version":3,"file":"wechat.d.ts","sourceRoot":"","sources":["../../src/commands/wechat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QA6LtD"}
@@ -1,4 +1,5 @@
1
1
  import { resolveCredentials } from '../lib/client.js';
2
+ import { downloadAttachment } from '../lib/download-attachment.js';
2
3
  import { printError, printJson } from '../lib/output.js';
3
4
  import { resolveMessageText, TEXT_FILE_OPTION_DESC, TEXT_OPTION_DESC } from '../lib/text-input.js';
4
5
  /**
@@ -80,6 +81,24 @@ export function registerWechatCommands(program) {
80
81
  printError(err);
81
82
  }
82
83
  });
84
+ const media = wechat
85
+ .command('media')
86
+ .description('Fetch WeChat media only when needed; the first successful fetch is cached');
87
+ media
88
+ .command('download')
89
+ .description('Download an image or completed file by external WeChat message id')
90
+ .requiredOption('--message <id>', 'External message id shown in the inbound event or history')
91
+ .option('-o, --output <path>', 'Output file path (default: ./{original_filename})')
92
+ .action(async (opts) => {
93
+ try {
94
+ const { client, orgId } = resolveCredentials();
95
+ const attachment = await client.materializeWechatMedia(orgId, opts.message);
96
+ printJson(await downloadAttachment(client, attachment.id, opts.output));
97
+ }
98
+ catch (err) {
99
+ printError(err);
100
+ }
101
+ });
83
102
  wechat
84
103
  .command('contacts')
85
104
  .description('List the account address book with display names: friends, saved groups, followed official accounts')
@@ -0,0 +1,13 @@
1
+ import type { FileUrlResponse } from '@parall/sdk';
2
+ interface AttachmentDownloaderClient {
3
+ getFileUrl(attachmentId: string): Promise<FileUrlResponse>;
4
+ }
5
+ export interface DownloadedAttachment {
6
+ path: string;
7
+ file_name: string;
8
+ file_size: number;
9
+ mime_type: string;
10
+ }
11
+ export declare function downloadAttachment(client: AttachmentDownloaderClient, attachmentId: string, output?: string): Promise<DownloadedAttachment>;
12
+ export {};
13
+ //# sourceMappingURL=download-attachment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-attachment.d.ts","sourceRoot":"","sources":["../../src/lib/download-attachment.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,UAAU,0BAA0B;IAClC,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CAoB/B"}
@@ -0,0 +1,22 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ export async function downloadAttachment(client, attachmentId, output) {
4
+ const fileInfo = await client.getFileUrl(attachmentId);
5
+ const response = await fetch(fileInfo.url);
6
+ if (!response.ok) {
7
+ throw new Error(`Download failed: ${response.status} ${response.statusText}`);
8
+ }
9
+ const buffer = Buffer.from(await response.arrayBuffer());
10
+ const safeName = path.basename(fileInfo.file_name || attachmentId);
11
+ const outputPath = output ? path.resolve(output) : path.resolve(safeName);
12
+ const finalPath = fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()
13
+ ? path.join(outputPath, safeName)
14
+ : outputPath;
15
+ fs.writeFileSync(finalPath, buffer);
16
+ return {
17
+ path: finalPath,
18
+ file_name: fileInfo.file_name,
19
+ file_size: fileInfo.file_size,
20
+ mime_type: fileInfo.mime_type,
21
+ };
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parall/cli",
3
- "version": "1.58.0",
3
+ "version": "1.58.2",
4
4
  "description": "CLI client for Parall — universal agent & human access to Parall API",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,14 +36,14 @@
36
36
  "diff": "^8.0.3",
37
37
  "js-yaml": "^4.1.0",
38
38
  "zod": "^4.3.6",
39
- "@parall/agent-core": "1.58.0",
40
- "@parall/sdk": "1.58.0"
39
+ "@parall/agent-core": "1.58.2",
40
+ "@parall/sdk": "1.58.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/js-yaml": "^4.0.9",
44
44
  "@types/node": "^22.0.0",
45
45
  "typescript": "^5.7.0",
46
- "@parall/agent-core": "1.58.0"
46
+ "@parall/agent-core": "1.58.2"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsc",