@im-more/dsh-wecom 0.0.0-stage → 0.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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/cordis.patch.yml +13 -0
  3. package/lib/index.js +2077 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/types/bot.d.ts +50 -0
  6. package/lib/types/bot.d.ts.map +1 -0
  7. package/lib/types/bot.js +126 -0
  8. package/lib/types/bot.js.map +1 -0
  9. package/lib/types/config.d.ts +48 -0
  10. package/lib/types/config.d.ts.map +1 -0
  11. package/lib/types/config.js +68 -0
  12. package/lib/types/config.js.map +1 -0
  13. package/lib/types/crypto.d.ts +69 -0
  14. package/lib/types/crypto.d.ts.map +1 -0
  15. package/lib/types/crypto.js +129 -0
  16. package/lib/types/crypto.js.map +1 -0
  17. package/lib/types/decode.d.ts +58 -0
  18. package/lib/types/decode.d.ts.map +1 -0
  19. package/lib/types/decode.js +182 -0
  20. package/lib/types/decode.js.map +1 -0
  21. package/lib/types/errors.d.ts +67 -0
  22. package/lib/types/errors.d.ts.map +1 -0
  23. package/lib/types/errors.js +170 -0
  24. package/lib/types/errors.js.map +1 -0
  25. package/lib/types/identity.d.ts +20 -0
  26. package/lib/types/identity.d.ts.map +1 -0
  27. package/lib/types/identity.js +34 -0
  28. package/lib/types/identity.js.map +1 -0
  29. package/lib/types/index.d.ts +19 -0
  30. package/lib/types/index.d.ts.map +1 -0
  31. package/lib/types/index.js +18 -0
  32. package/lib/types/index.js.map +1 -0
  33. package/lib/types/internal.d.ts +154 -0
  34. package/lib/types/internal.d.ts.map +1 -0
  35. package/lib/types/internal.js +115 -0
  36. package/lib/types/internal.js.map +1 -0
  37. package/lib/types/media.d.ts +44 -0
  38. package/lib/types/media.d.ts.map +1 -0
  39. package/lib/types/media.js +116 -0
  40. package/lib/types/media.js.map +1 -0
  41. package/lib/types/modes/markdown.d.ts +20 -0
  42. package/lib/types/modes/markdown.d.ts.map +1 -0
  43. package/lib/types/modes/markdown.js +205 -0
  44. package/lib/types/modes/markdown.js.map +1 -0
  45. package/lib/types/modes/shared.d.ts +227 -0
  46. package/lib/types/modes/shared.d.ts.map +1 -0
  47. package/lib/types/modes/shared.js +487 -0
  48. package/lib/types/modes/shared.js.map +1 -0
  49. package/lib/types/request.d.ts +55 -0
  50. package/lib/types/request.d.ts.map +1 -0
  51. package/lib/types/request.js +202 -0
  52. package/lib/types/request.js.map +1 -0
  53. package/lib/types/send.d.ts +54 -0
  54. package/lib/types/send.d.ts.map +1 -0
  55. package/lib/types/send.js +124 -0
  56. package/lib/types/send.js.map +1 -0
  57. package/lib/types/token.d.ts +34 -0
  58. package/lib/types/token.d.ts.map +1 -0
  59. package/lib/types/token.js +61 -0
  60. package/lib/types/token.js.map +1 -0
  61. package/lib/types/transport/webhook.d.ts +41 -0
  62. package/lib/types/transport/webhook.d.ts.map +1 -0
  63. package/lib/types/transport/webhook.js +216 -0
  64. package/lib/types/transport/webhook.js.map +1 -0
  65. package/lib/types/types.d.ts +58 -0
  66. package/lib/types/types.d.ts.map +1 -0
  67. package/lib/types/types.js +2 -0
  68. package/lib/types/types.js.map +1 -0
  69. package/lib/types/xml.d.ts +40 -0
  70. package/lib/types/xml.d.ts.map +1 -0
  71. package/lib/types/xml.js +82 -0
  72. package/lib/types/xml.js.map +1 -0
  73. package/package.json +65 -3
  74. package/src/bot.ts +195 -0
  75. package/src/config.ts +117 -0
  76. package/src/crypto.ts +172 -0
  77. package/src/decode.ts +238 -0
  78. package/src/errors.ts +199 -0
  79. package/src/identity.ts +41 -0
  80. package/src/index.ts +101 -0
  81. package/src/internal.ts +237 -0
  82. package/src/media.ts +157 -0
  83. package/src/modes/markdown.ts +263 -0
  84. package/src/modes/shared.ts +618 -0
  85. package/src/request.ts +291 -0
  86. package/src/send.ts +172 -0
  87. package/src/token.ts +75 -0
  88. package/src/transport/webhook.ts +292 -0
  89. package/src/types.ts +74 -0
  90. package/src/xml.ts +89 -0
  91. package/README.md +0 -3
@@ -0,0 +1,487 @@
1
+ /**
2
+ * Shared types and the draft machinery of the single `markdown` mode.
3
+ *
4
+ * A WeCom application message is one `message/send` call, and its `msgtype` decides what it can carry: `markdown` holds
5
+ * the formatted body, `image`/`voice`/`video`/`file` hold one `media_id` each, and `template_card` holds the buttons.
6
+ * A draft is therefore exactly one platform message: the body is split at the documented 2,048 bytes, every media
7
+ * element becomes a message of its own, and a message with buttons gets a card message after its body.
8
+ */
9
+ import { randomBytes } from 'node:crypto';
10
+ import { INTERACTION_DROPPED } from '@deepseek-ai/cordis-plugin-im-core';
11
+ import { isPhrasingContainer } from '@deepseek-ai/satori-element';
12
+ /** The platform's documented bounds, and nothing else. */
13
+ export const WECOM_LIMITS = {
14
+ /** `text.content` and `markdown.content`: at most 2,048 bytes, counted as UTF-8. */
15
+ payloadBytes: 2_048,
16
+ /** `message/recall` accepts a message up to 24 hours after it was sent. */
17
+ deleteWindow: 24 * 60 * 60 * 1_000,
18
+ /** `button_list` of a `button_interaction` card holds at most six buttons. */
19
+ buttonsRow: 6,
20
+ /** The card has one button row. */
21
+ buttonRows: 1,
22
+ };
23
+ /** The word joiner a card title falls back to: the platform requires `main_title`, and content is never empty. */
24
+ export const CARD_TITLE_FALLBACK = '\u2060';
25
+ /** The process-wide random segment of every `task_id`, in base 36. */
26
+ let bootSalt = randomBytes(6).readUIntBE(0, 6).toString(36);
27
+ /** The sequence within this process; `task_id` must not repeat inside one application. */
28
+ let taskSequence = 0;
29
+ /**
30
+ * Pin the process-random segment of every `task_id`.
31
+ *
32
+ * The platform requires the id to be unique inside one application, so it is seeded from process entropy. A test that
33
+ * compares serialized request bodies pins the segment instead, so two runs produce the same payloads; the counter keeps
34
+ * advancing, because two cards of one run still must not share an id.
35
+ *
36
+ * @param salt - the segment to use: `0-9a-zA-Z_-`, at most 128 bytes together with the rest of the id.
37
+ */
38
+ export function pinTaskIdSalt(salt) {
39
+ bootSalt = salt;
40
+ }
41
+ /**
42
+ * The `task_id` of one card.
43
+ *
44
+ * The platform requires the id to be unique within the application, so a counter alone would collide with the ids of the
45
+ * previous process after a restart; the random boot segment makes the pair unique across restarts.
46
+ *
47
+ * @returns an id the platform accepts: `0-9a-zA-Z_-` only, at most 128 bytes.
48
+ */
49
+ export function nextTaskId() {
50
+ taskSequence += 1;
51
+ return `dsh-${bootSalt}-${taskSequence}`;
52
+ }
53
+ /**
54
+ * Report inline media that moves out of its text run into a message of its own.
55
+ *
56
+ * @param el - the media element.
57
+ * @param ctx - the render context.
58
+ */
59
+ export function reportMovedMedia(el, ctx) {
60
+ const parent = ctx.ancestors[ctx.ancestors.length - 1];
61
+ if (parent !== undefined && isPhrasingContainer(parent.type)) {
62
+ ctx.report.moved.push({
63
+ tag: el.type,
64
+ reason: 'wecom-media-split',
65
+ path: ctx.stableId(el),
66
+ });
67
+ }
68
+ }
69
+ /**
70
+ * Cut one line into pieces of at most `limit` bytes, never inside a surrogate pair.
71
+ *
72
+ * @param text - the line to cut.
73
+ * @param limit - the byte bound.
74
+ * @returns the pieces, in order; concatenating them reproduces the line.
75
+ */
76
+ export function hardCutBytes(text, limit) {
77
+ const pieces = [];
78
+ let piece = '';
79
+ let bytes = 0;
80
+ // `for…of` walks code points, so a surrogate pair is never split between two pieces.
81
+ for (const character of text) {
82
+ const size = Buffer.byteLength(character, 'utf8');
83
+ if (bytes + size > limit && piece !== '') {
84
+ pieces.push(piece);
85
+ piece = '';
86
+ bytes = 0;
87
+ }
88
+ piece += character;
89
+ bytes += size;
90
+ }
91
+ if (piece !== '')
92
+ pieces.push(piece);
93
+ return pieces;
94
+ }
95
+ /**
96
+ * Cut a body into chunks the platform accepts.
97
+ *
98
+ * Lines are accumulated while they fit; a line that would overflow closes the current chunk, and a line longer than the
99
+ * bound is cut by bytes. A cut can land inside a formatting mark (`**`, `` ` ``), which the client then shows as literal
100
+ * characters: the platform documents no escape syntax that would avoid it.
101
+ *
102
+ * @param text - the body of one logical message.
103
+ * @param limit - the byte bound of one `markdown` message.
104
+ * @returns one or more chunks, in order; never empty.
105
+ */
106
+ export function splitMarkdownBytes(text, limit = WECOM_LIMITS.payloadBytes) {
107
+ if (Buffer.byteLength(text, 'utf8') <= limit)
108
+ return [text];
109
+ const chunks = [];
110
+ let current = '';
111
+ let currentBytes = 0;
112
+ const close = () => {
113
+ if (current !== '')
114
+ chunks.push(current);
115
+ current = '';
116
+ currentBytes = 0;
117
+ };
118
+ for (const line of text.split(/(?<=\n)/)) {
119
+ const lineBytes = Buffer.byteLength(line, 'utf8');
120
+ if (currentBytes + lineBytes <= limit) {
121
+ current += line;
122
+ currentBytes += lineBytes;
123
+ continue;
124
+ }
125
+ close();
126
+ if (lineBytes <= limit) {
127
+ current = line;
128
+ currentBytes = lineBytes;
129
+ continue;
130
+ }
131
+ const pieces = hardCutBytes(line, limit);
132
+ // Everything but the last piece is one chunk of its own; the tail stays open for the next line.
133
+ for (const piece of pieces.slice(0, -1))
134
+ chunks.push(piece);
135
+ current = pieces[pieces.length - 1] ?? '';
136
+ currentBytes = Buffer.byteLength(current, 'utf8');
137
+ }
138
+ close();
139
+ return chunks.length === 0 ? [''] : chunks;
140
+ }
141
+ /** Strip the newlines a paragraph puts around the content of one list item. */
142
+ function trimEdges(nodes) {
143
+ const out = [...nodes];
144
+ while (out.length > 0) {
145
+ const first = out[0];
146
+ if (first.type !== 'text')
147
+ break;
148
+ const stripped = first.text.replace(/^\n+/, '');
149
+ if (stripped === '') {
150
+ out.shift();
151
+ continue;
152
+ }
153
+ out[0] = { type: 'text', text: stripped };
154
+ break;
155
+ }
156
+ while (out.length > 0) {
157
+ const last = out[out.length - 1];
158
+ if (last.type !== 'text')
159
+ break;
160
+ const stripped = last.text.replace(/\n+$/, '');
161
+ if (stripped === '') {
162
+ out.pop();
163
+ continue;
164
+ }
165
+ out[out.length - 1] = { type: 'text', text: stripped };
166
+ break;
167
+ }
168
+ return out;
169
+ }
170
+ /** Put a list marker at the start of the item's first line, or before its first media node. */
171
+ function applyMarker(nodes, marker) {
172
+ for (let index = 0; index < nodes.length; index++) {
173
+ const node = nodes[index];
174
+ if (node.type !== 'text') {
175
+ nodes.splice(index, 0, { type: 'text', text: marker.trimEnd() });
176
+ return;
177
+ }
178
+ const leading = /^\n*/.exec(node.text)?.[0].length ?? 0;
179
+ if (leading < node.text.length) {
180
+ nodes[index] = {
181
+ type: 'text',
182
+ text: `${node.text.slice(0, leading)}${marker}${node.text.slice(leading)}`,
183
+ };
184
+ return;
185
+ }
186
+ }
187
+ }
188
+ /** One list node, expanded into one line per item. */
189
+ function flattenList(node, depth) {
190
+ const out = [];
191
+ const indent = ' '.repeat(depth);
192
+ let number = node.start;
193
+ node.items.forEach((item, index) => {
194
+ const marker = node.ordered ? `${indent}${number++}. ` : `${indent}- `;
195
+ const inner = trimEdges(flattenAt(item.type === 'item' ? item.nodes : [item], depth + 1));
196
+ if (index > 0)
197
+ out.push({ type: 'text', text: '\n' });
198
+ if (inner.length === 0) {
199
+ out.push({ type: 'text', text: marker.trimEnd() });
200
+ return;
201
+ }
202
+ applyMarker(inner, marker);
203
+ out.push(...inner);
204
+ });
205
+ if (out.length > 0)
206
+ out.push({ type: 'text', text: '\n' });
207
+ return out;
208
+ }
209
+ /** Expand every list and item of one node stream. */
210
+ function flattenAt(nodes, depth) {
211
+ const out = [];
212
+ for (const node of nodes) {
213
+ switch (node.type) {
214
+ case 'text':
215
+ case 'media':
216
+ case 'button':
217
+ case 'link-button':
218
+ out.push(node);
219
+ break;
220
+ case 'item':
221
+ out.push(...flattenAt(node.nodes, depth));
222
+ break;
223
+ case 'list': {
224
+ const last = out[out.length - 1];
225
+ if (last !== undefined &&
226
+ !(last.type === 'text' && last.text.endsWith('\n'))) {
227
+ out.push({ type: 'text', text: '\n' });
228
+ }
229
+ out.push(...flattenList(node, depth));
230
+ break;
231
+ }
232
+ }
233
+ }
234
+ return out;
235
+ }
236
+ /**
237
+ * Expand list and item nodes into the flat node stream {@link assembleDraft} splits into messages.
238
+ *
239
+ * @param nodes - rendered nodes, in document order.
240
+ * @returns the same content with every list marker applied and media nodes kept in place.
241
+ */
242
+ export function flattenNodes(nodes) {
243
+ return flattenAt(nodes, 0);
244
+ }
245
+ /** The media draft of one media node. */
246
+ function mediaDraftOf(node) {
247
+ return {
248
+ kind: 'media',
249
+ media: node.media,
250
+ ref: node.ref,
251
+ ...(node.name === undefined ? {} : { name: node.name }),
252
+ };
253
+ }
254
+ /**
255
+ * Fold a node stream into platform messages.
256
+ *
257
+ * The text buffer is split by bytes and closed before every media element; the collected buttons become one card
258
+ * message after the body, and a seventh button onwards degrades to a `[label]` line in the body. The title of the
259
+ * envelope stays in the body as a bold line and becomes the card's `main_title` when there is a card, so a title is
260
+ * never lost on a message without buttons.
261
+ *
262
+ * @param nodes - rendered nodes, in document order.
263
+ * @param envelope - the root `<title>`, if the content carried one.
264
+ * @param ctx - the render context, for the split and drop reports.
265
+ * @returns one draft per platform message, in send order; never empty.
266
+ */
267
+ export function assembleDraft(nodes, envelope, ctx) {
268
+ const drafts = [];
269
+ const buttons = [];
270
+ let buffer = '';
271
+ let firstLine = '';
272
+ let split = 0;
273
+ const noteFirstLine = (text) => {
274
+ if (firstLine !== '')
275
+ return;
276
+ for (const line of text.split('\n')) {
277
+ const trimmed = line.trim();
278
+ if (trimmed !== '') {
279
+ firstLine = trimmed;
280
+ return;
281
+ }
282
+ }
283
+ };
284
+ const flushText = () => {
285
+ // The blank lines a paragraph puts around its text are separators inside the body, not at its edges.
286
+ const text = buffer.replace(/^\n+/, '').replace(/\n+$/, '');
287
+ buffer = '';
288
+ if (text === '')
289
+ return;
290
+ noteFirstLine(text);
291
+ const chunks = splitMarkdownBytes(text);
292
+ split += chunks.length - 1;
293
+ for (const chunk of chunks)
294
+ drafts.push({ kind: 'markdown', content: chunk });
295
+ };
296
+ const title = envelope.title;
297
+ const titleText = title === undefined ? '' : ctx.text(title.children).trim();
298
+ if (titleText !== '') {
299
+ buffer += `**${titleText}**`;
300
+ const subtitle = title?.attrs.subtitle;
301
+ if (subtitle !== undefined && subtitle !== '')
302
+ buffer += `\n${subtitle}`;
303
+ buffer += '\n';
304
+ }
305
+ for (const node of flattenNodes(nodes)) {
306
+ switch (node.type) {
307
+ case 'text':
308
+ buffer += node.text;
309
+ break;
310
+ case 'media':
311
+ flushText();
312
+ drafts.push(mediaDraftOf(node));
313
+ break;
314
+ case 'button':
315
+ buttons.push({ text: node.text, key: node.key });
316
+ break;
317
+ case 'link-button':
318
+ buttons.push({ text: node.text, href: node.href });
319
+ break;
320
+ default:
321
+ break;
322
+ }
323
+ }
324
+ if (buttons.length > WECOM_LIMITS.buttonsRow) {
325
+ // The platform refuses a seventh button, so the overflow becomes text instead of disappearing.
326
+ for (const button of buttons.splice(WECOM_LIMITS.buttonsRow)) {
327
+ const label = 'key' in button ? button.key : button.text;
328
+ ctx.report.dropped.push({
329
+ what: `button:${label}`,
330
+ reason: INTERACTION_DROPPED,
331
+ });
332
+ buffer += `[${button.text}]\n`;
333
+ }
334
+ }
335
+ if (buttons.length > 0) {
336
+ flushText();
337
+ drafts.push({
338
+ kind: 'card',
339
+ title: titleText !== ''
340
+ ? titleText
341
+ : firstLine !== ''
342
+ ? firstLine
343
+ : CARD_TITLE_FALLBACK,
344
+ taskId: nextTaskId(),
345
+ buttons: [...buttons],
346
+ });
347
+ // The card is an extra platform message after a body that already exists.
348
+ if (drafts.length > 1)
349
+ split += 1;
350
+ }
351
+ else {
352
+ flushText();
353
+ }
354
+ ctx.report.split += split;
355
+ if (drafts.length === 0)
356
+ drafts.push({ kind: 'markdown', content: CARD_TITLE_FALLBACK });
357
+ return drafts;
358
+ }
359
+ /** One resolved resource key of a prepared draft. */
360
+ function resolvedKey(prepared, ref) {
361
+ const resolved = prepared.resolved.get(ref);
362
+ if (resolved === undefined) {
363
+ throw new Error('wecom: media was not prepared before serialize');
364
+ }
365
+ return resolved.key;
366
+ }
367
+ /**
368
+ * Build the exact request body of one prepared draft.
369
+ *
370
+ * @param prepared - the draft with its resource keys resolved.
371
+ * @param ctx - the send context: the target chat names the `touser` recipient.
372
+ * @param agentId - the numeric `AgentID` every send carries.
373
+ * @returns the `message/send` body.
374
+ */
375
+ export function serializeDraft(prepared, ctx, agentId) {
376
+ const touser = ctx.target.chat.id;
377
+ const draft = prepared.draft;
378
+ switch (draft.kind) {
379
+ case 'markdown':
380
+ return {
381
+ touser,
382
+ agentid: agentId,
383
+ msgtype: 'markdown',
384
+ markdown: { content: draft.content },
385
+ };
386
+ case 'media': {
387
+ const mediaId = resolvedKey(prepared, draft.ref);
388
+ switch (draft.media) {
389
+ case 'image':
390
+ return {
391
+ touser,
392
+ agentid: agentId,
393
+ msgtype: 'image',
394
+ image: { media_id: mediaId },
395
+ };
396
+ case 'voice':
397
+ return {
398
+ touser,
399
+ agentid: agentId,
400
+ msgtype: 'voice',
401
+ voice: { media_id: mediaId },
402
+ };
403
+ case 'file':
404
+ return {
405
+ touser,
406
+ agentid: agentId,
407
+ msgtype: 'file',
408
+ file: { media_id: mediaId },
409
+ };
410
+ case 'video':
411
+ return {
412
+ touser,
413
+ agentid: agentId,
414
+ msgtype: 'video',
415
+ video: {
416
+ media_id: mediaId,
417
+ ...(draft.name === undefined ? {} : { title: draft.name }),
418
+ },
419
+ };
420
+ }
421
+ throw new Error('wecom: unknown media kind');
422
+ }
423
+ case 'card':
424
+ return {
425
+ touser,
426
+ agentid: agentId,
427
+ msgtype: 'template_card',
428
+ template_card: {
429
+ card_type: 'button_interaction',
430
+ main_title: { title: draft.title },
431
+ button_list: draft.buttons.map((button) => 'key' in button
432
+ ? { text: button.text, key: button.key }
433
+ : { text: button.text, type: 1, url: button.href }),
434
+ task_id: draft.taskId,
435
+ },
436
+ };
437
+ }
438
+ }
439
+ /**
440
+ * Hard platform limits of one draft, checked before any request.
441
+ *
442
+ * Splitting already keeps the body inside the byte bound and the card inside the button bound; the checks stay as the
443
+ * only place the adapter refuses a draft the platform would answer `45002` for.
444
+ *
445
+ * @param draft - the assembled draft.
446
+ * @returns every violation the platform would refuse.
447
+ */
448
+ export function checkDraft(draft) {
449
+ switch (draft.kind) {
450
+ case 'markdown': {
451
+ const bytes = Buffer.byteLength(draft.content, 'utf8');
452
+ if (bytes <= WECOM_LIMITS.payloadBytes)
453
+ return [];
454
+ return [
455
+ {
456
+ kind: 'size',
457
+ key: 'limit.payload.bytes',
458
+ limit: WECOM_LIMITS.payloadBytes,
459
+ actual: bytes,
460
+ message: `WeCom markdown accepts ${WECOM_LIMITS.payloadBytes} bytes, got ${bytes}`,
461
+ },
462
+ ];
463
+ }
464
+ case 'card': {
465
+ const violations = [];
466
+ if (draft.buttons.length > WECOM_LIMITS.buttonsRow) {
467
+ violations.push({
468
+ kind: 'size',
469
+ key: 'limit.buttons.row',
470
+ limit: WECOM_LIMITS.buttonsRow,
471
+ actual: draft.buttons.length,
472
+ message: `WeCom cards accept ${WECOM_LIMITS.buttonsRow} buttons, got ${draft.buttons.length}`,
473
+ });
474
+ }
475
+ if (draft.taskId === '') {
476
+ violations.push({
477
+ kind: 'shape',
478
+ message: 'WeCom cards need a task_id',
479
+ });
480
+ }
481
+ return violations;
482
+ }
483
+ case 'media':
484
+ return [];
485
+ }
486
+ }
487
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/modes/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAUxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAwFjE,0DAA0D;AAC1D,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,oFAAoF;IACpF,YAAY,EAAE,KAAK;IACnB,2EAA2E;IAC3E,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK;IAClC,8EAA8E;IAC9E,UAAU,EAAE,CAAC;IACb,mCA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d,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,4BAA4B;iBACtC,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,UAAU,CAAA;QACnB,CAAC;QACD,KAAK,OAAO;YACV,OAAO,EAAE,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { Config } from './config.ts';
3
+ /** One request body, query and cancellation. */
4
+ export interface WecomRequestConfig {
5
+ /** A JSON body, or the multipart form of the media upload. */
6
+ data?: object | FormData;
7
+ params?: Record<string, string | number | undefined>;
8
+ signal?: AbortSignal | undefined;
9
+ }
10
+ /** What one call needs from the adapter. */
11
+ export interface WecomRequestEndpoint {
12
+ readonly ctx: Context;
13
+ readonly config: Config;
14
+ readonly tokens: {
15
+ get(): Promise<string>;
16
+ invalidate(): void;
17
+ };
18
+ }
19
+ /**
20
+ * The absolute URL of one endpoint.
21
+ *
22
+ * @param config - the adapter configuration holding the API root.
23
+ * @param path - endpoint path under the root, e.g. `/cgi-bin/message/send`.
24
+ * @returns the absolute request URL.
25
+ */
26
+ export declare function endpointOf(config: Config, path: string): string;
27
+ /**
28
+ * Call one WeCom endpoint.
29
+ *
30
+ * A call refused for its `access_token` re-mints the token and is retried once; every other failure is thrown as the
31
+ * `WecomApiError` `classify` maps. A cancelled call rejects with the cancellation itself.
32
+ *
33
+ * @param endpoint - the adapter whose configuration and token cache the call uses.
34
+ * @param method - HTTP method.
35
+ * @param path - endpoint path under the API root.
36
+ * @param config - body, query parameters and cancellation of the call.
37
+ * @returns the unwrapped JSON answer.
38
+ * @throws WecomApiError when the platform refused the call or did not answer with JSON.
39
+ */
40
+ export declare function invoke<T>(endpoint: WecomRequestEndpoint, method: string, path: string, config?: WecomRequestConfig): Promise<T>;
41
+ /**
42
+ * Download the bytes of one inbound media object.
43
+ *
44
+ * `media/get` answers the bytes themselves on success and a JSON `{ errcode }` envelope on failure, so the answer is
45
+ * returned as it arrived and mapped by the caller. A refusal for the `access_token` re-mints it and retries once. A
46
+ * cancelled download rejects with the cancellation itself.
47
+ *
48
+ * @param endpoint - the adapter whose credentials the download uses.
49
+ * @param path - endpoint path under the API root.
50
+ * @param params - query parameters of the download.
51
+ * @param signal - cancellation.
52
+ * @returns the answer, status and headers included.
53
+ */
54
+ export declare function download(endpoint: WecomRequestEndpoint, path: string, params: Record<string, string | number | undefined>, signal?: AbortSignal): Promise<Response>;
55
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AASzC,gDAAgD;AAChD,MAAM,WAAW,kBAAkB;IACjC,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;IACpD,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED,4CAA4C;AAC5C,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE;QACf,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;QACtB,UAAU,IAAI,IAAI,CAAA;KACnB,CAAA;CACF;AAqCD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D;AAoHD;;;;;;;;;;;;GAYG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAC5B,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAA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