@yaoyuanchao/dingtalk 1.4.7 → 1.4.9

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.4.9] - 2026-01-30
9
+
10
+ ### Fixed
11
+
12
+ - **zod v4 compatibility** — upgraded zod dependency from `^3.22.0` to `^4.3.6` to match clawdbot's version; fixed `ZodError.errors` → `ZodError.issues` API change that caused "Cannot find module 'zod'" errors during `clawdbot plugins update`
13
+
14
+ ### Changed
15
+
16
+ - **Dependency alignment** — now uses same zod version as clawdbot core and clawdbot-feishu plugin, eliminating duplicate zod installations and version conflicts
17
+
8
18
  ## [1.3.6] - 2026-01-28
9
19
 
10
20
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "type": "module",
5
5
  "description": "DingTalk channel plugin for Clawdbot with Stream Mode support",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "dingtalk-stream": "^2.1.4",
42
- "zod": "^3.22.0"
42
+ "zod": "^4.3.6"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "clawdbot": ">=2026.1.24"
package/src/api.ts CHANGED
@@ -70,6 +70,29 @@ function httpGetBuffer(url: string, headers?: Record<string, string>): Promise<B
70
70
  });
71
71
  }
72
72
 
73
+ /** Retry wrapper for async functions */
74
+ async function withRetry<T>(
75
+ fn: () => Promise<T>,
76
+ maxRetries: number = 3,
77
+ delayMs: number = 1000,
78
+ backoffMultiplier: number = 2,
79
+ ): Promise<T> {
80
+ let lastError: Error | undefined;
81
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
82
+ try {
83
+ return await fn();
84
+ } catch (err) {
85
+ lastError = err instanceof Error ? err : new Error(String(err));
86
+ if (attempt < maxRetries) {
87
+ const delay = delayMs * Math.pow(backoffMultiplier, attempt - 1);
88
+ console.log(`[dingtalk] Retry ${attempt}/${maxRetries} after ${delay}ms: ${lastError.message}`);
89
+ await new Promise(resolve => setTimeout(resolve, delay));
90
+ }
91
+ }
92
+ }
93
+ throw lastError;
94
+ }
95
+
73
96
  export async function getDingTalkAccessToken(clientId: string, clientSecret: string): Promise<string> {
74
97
  const cached = tokenCache.get(clientId);
75
98
  if (cached && cached.expiresAt > Date.now() + 60_000) {
@@ -337,9 +360,14 @@ export async function downloadPicture(
337
360
  return { error: response.errmsg || "Download failed" };
338
361
  }
339
362
 
340
- // If response has a file URL, download it
363
+ // If response has a file URL, download it with retry
341
364
  if (response.downloadUrl) {
342
- const imageBuffer = await httpGetBuffer(response.downloadUrl);
365
+ const imageBuffer = await withRetry(
366
+ () => httpGetBuffer(response.downloadUrl),
367
+ 3, // maxRetries
368
+ 1000, // initial delay 1s
369
+ 2, // backoff multiplier
370
+ );
343
371
 
344
372
  // Convert to base64
345
373
  const base64 = imageBuffer.toString('base64');
@@ -404,7 +432,12 @@ export async function downloadMediaFile(
404
432
  }
405
433
 
406
434
  if (response.downloadUrl) {
407
- const mediaBuffer = await httpGetBuffer(response.downloadUrl);
435
+ const mediaBuffer = await withRetry(
436
+ () => httpGetBuffer(response.downloadUrl),
437
+ 3, // maxRetries
438
+ 1000, // initial delay 1s
439
+ 2, // backoff multiplier
440
+ );
408
441
 
409
442
  if (!fs.existsSync(TEMP_DIR)) {
410
443
  fs.mkdirSync(TEMP_DIR, { recursive: true });
@@ -87,11 +87,11 @@ export function validateDingTalkConfig(config: unknown): DingTalkConfig {
87
87
  return dingTalkConfigSchema.parse(config);
88
88
  } catch (error) {
89
89
  if (error instanceof z.ZodError) {
90
- const issues = error.errors.map(e => {
90
+ const formatted = error.issues.map(e => {
91
91
  const path = e.path.join('.');
92
92
  return ` - ${path || 'root'}: ${e.message}`;
93
93
  }).join('\n');
94
- throw new Error(`DingTalk config validation failed:\n${issues}`);
94
+ throw new Error(`DingTalk config validation failed:\n${formatted}`);
95
95
  }
96
96
  throw error;
97
97
  }
@@ -110,11 +110,11 @@ export function safeValidateDingTalkConfig(config: unknown):
110
110
  return { success: true, data };
111
111
  } catch (error) {
112
112
  if (error instanceof z.ZodError) {
113
- const issues = error.errors.map(e => {
113
+ const formatted = error.issues.map(e => {
114
114
  const path = e.path.join('.');
115
115
  return `${path || 'root'}: ${e.message}`;
116
116
  }).join('; ');
117
- return { success: false, error: issues };
117
+ return { success: false, error: formatted };
118
118
  }
119
119
  return { success: false, error: String(error) };
120
120
  }