@max1874/feishu 0.2.8 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/docx.ts +24 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@max1874/feishu",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Feishu/Lark channel plugin",
6
6
  "license": "MIT",
package/src/docx.ts CHANGED
@@ -157,16 +157,20 @@ function extractTableFromBlocks(blocks: any[]): { tables: TableData[]; otherBloc
157
157
  return { tables, otherBlocks };
158
158
  }
159
159
 
160
- /** Clean blocks for insertion (remove read-only fields) */
160
+ /** Clean blocks for insertion (remove read-only fields and unsupported nested structures) */
161
161
  function cleanBlocksForInsert(blocks: any[]): { cleaned: any[]; skipped: string[] } {
162
162
  const skipped: string[] = [];
163
163
  const cleaned = blocks.map((block) => {
164
- // Remove any read-only fields that might slip through
164
+ const { children, parent_id, block_id, ...rest } = block;
165
+
166
+ // Remove children from non-table blocks (nested lists not supported in create API)
167
+ // Table children are handled separately via table.cells
165
168
  if (block.block_type === TABLE_BLOCK_TYPE && block.table?.merge_info) {
166
169
  const { merge_info, ...tableRest } = block.table;
167
- return { ...block, table: tableRest };
170
+ return { ...rest, table: tableRest };
168
171
  }
169
- return block;
172
+
173
+ return rest;
170
174
  });
171
175
  return { cleaned, skipped };
172
176
  }
@@ -185,7 +189,7 @@ async function convertMarkdown(client: Lark.Client, markdown: string) {
185
189
  };
186
190
  }
187
191
 
188
- /** Insert blocks as children of a parent block */
192
+ /** Insert blocks as children of a parent block (with batching for >50 blocks) */
189
193
  async function insertBlocks(
190
194
  client: Lark.Client,
191
195
  docToken: string,
@@ -199,12 +203,21 @@ async function insertBlocks(
199
203
  return { children: [], skipped };
200
204
  }
201
205
 
202
- const res = await client.docx.documentBlockChildren.create({
203
- path: { document_id: docToken, block_id: blockId },
204
- data: { children: cleaned },
205
- });
206
- if (res.code !== 0) throw new Error(res.msg);
207
- return { children: res.data?.children ?? [], skipped };
206
+ // Feishu API limits to 50 blocks per request
207
+ const BATCH_SIZE = 50;
208
+ const allChildren: any[] = [];
209
+
210
+ for (let i = 0; i < cleaned.length; i += BATCH_SIZE) {
211
+ const batch = cleaned.slice(i, i + BATCH_SIZE);
212
+ const res = await client.docx.documentBlockChildren.create({
213
+ path: { document_id: docToken, block_id: blockId },
214
+ data: { children: batch },
215
+ });
216
+ if (res.code !== 0) throw new Error(res.msg);
217
+ allChildren.push(...(res.data?.children ?? []));
218
+ }
219
+
220
+ return { children: allChildren, skipped };
208
221
  }
209
222
 
210
223
  /** Delete all child blocks from a parent */