@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,170 @@
1
+ /**
2
+ * Platform failures of the WeCom REST surface and their mapping onto the core taxonomy.
3
+ *
4
+ * Almost every failure has one shape: HTTP 200 with `{ errcode, errmsg }`, where `errcode === 0` is success. The HTTP
5
+ * layer only fails for a transport problem or a gateway. `published: 'no'` is therefore reserved for a platform refusal
6
+ * this adapter can classify; an answer without a code, a non-JSON page and a 5xx leave the outcome open.
7
+ */
8
+ import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
9
+ /** One failed WeCom API call. */
10
+ export class WecomApiError extends Error {
11
+ status;
12
+ errcode;
13
+ errmsg;
14
+ bodyText;
15
+ nonJson;
16
+ constructor(message, init = {}) {
17
+ super(message, init.cause === undefined ? undefined : { cause: init.cause });
18
+ this.name = 'WecomApiError';
19
+ this.status = init.status;
20
+ this.errcode = init.errcode;
21
+ this.errmsg = init.errmsg;
22
+ this.bodyText = init.bodyText;
23
+ this.nonJson = init.nonJson ?? false;
24
+ }
25
+ }
26
+ const RATE_LIMIT = { kind: 'rate-limit', published: 'no' };
27
+ const LIMIT = { kind: 'limit', published: 'no' };
28
+ const PERMISSION = { kind: 'permission', published: 'no' };
29
+ const NOT_FOUND = { kind: 'not-found', published: 'no' };
30
+ const INVALID = { kind: 'invalid', published: 'no' };
31
+ const RETRYABLE = { kind: 'retryable', published: 'unknown' };
32
+ /**
33
+ * The codes of 全局错误码 this adapter actually meets.
34
+ *
35
+ * A refusal the platform names is a request it rejected before publishing anything, so every entry is `published: 'no'`.
36
+ */
37
+ const CODE_VERDICTS = new Map([
38
+ [40001, PERMISSION], // invalid secret
39
+ [40013, PERMISSION], // invalid corpId
40
+ [40014, PERMISSION], // invalid access_token
41
+ [42001, PERMISSION], // access_token expired
42
+ [40003, NOT_FOUND], // invalid userid
43
+ [40007, INVALID], // invalid media_id
44
+ [40008, INVALID], // invalid msgtype
45
+ [44001, INVALID], // empty media file
46
+ [45002, LIMIT], // message content over the limit
47
+ [45009, RATE_LIMIT], // API call rate limit
48
+ [45033, RATE_LIMIT], // API concurrency limit
49
+ [48002, PERMISSION], // API not enabled for the application
50
+ [60011, PERMISSION], // no permission for the member/department/tag
51
+ [81013, PERMISSION], // every userid/department/tag was invalid
52
+ [82001, INVALID], // touser/toparty/totag all empty
53
+ [830002, LIMIT], // downloaded file too large
54
+ ]);
55
+ /** Codes outside the documented table whose whole family has one verdict. */
56
+ const FAMILY_VERDICTS = new Map([
57
+ [41001, PERMISSION], // access_token missing
58
+ [48004, PERMISSION], // API forbidden
59
+ [60020, PERMISSION], // IP not in the trust list
60
+ [301002, PERMISSION], // no privilege for this API
61
+ ]);
62
+ /** Whether a code means the `access_token` was refused, so the token is re-minted and the call retried once. */
63
+ const TOKEN_FAILURE_CODES = new Set([42001, 40014]);
64
+ /**
65
+ * Verdict of one business code, by the documented table and then by family.
66
+ *
67
+ * @param errcode - the `errcode` of an answer.
68
+ * @returns its classification, or undefined for a code inside no family this adapter knows.
69
+ */
70
+ export function verdictOfCode(errcode) {
71
+ const exact = CODE_VERDICTS.get(errcode) ?? FAMILY_VERDICTS.get(errcode);
72
+ if (exact !== undefined)
73
+ return exact;
74
+ // `4xxxx` are parameter refusals, `5xxxx` gateway and retry classes, `6xxxx` authorization and `8xxxx` member and
75
+ // media refusals; the platform documents each family as one behaviour.
76
+ const family = Math.trunc(errcode / 10_000);
77
+ if (family === 4)
78
+ return INVALID;
79
+ if (family === 5)
80
+ return RETRYABLE;
81
+ if (family === 6)
82
+ return PERMISSION;
83
+ if (family === 8)
84
+ return INVALID;
85
+ return undefined;
86
+ }
87
+ /**
88
+ * Whether an `errcode` means the `access_token` was refused.
89
+ *
90
+ * @param errcode - the code of an answer, when it carried one.
91
+ * @returns true for the two codes the platform documents as "refresh and retry".
92
+ */
93
+ export function isTokenFailureCode(errcode) {
94
+ return errcode !== undefined && TOKEN_FAILURE_CODES.has(errcode);
95
+ }
96
+ /**
97
+ * Whether a failed call means the `access_token` was refused.
98
+ *
99
+ * @param error - the caught failure.
100
+ * @returns true for the two codes the platform documents as "refresh and retry".
101
+ */
102
+ export function isTokenFailure(error) {
103
+ return error instanceof WecomApiError && isTokenFailureCode(error.errcode);
104
+ }
105
+ /** Whether a caught value is an abort error, including the `DOMException` a signal produces. */
106
+ function isAbortError(error) {
107
+ return ((error instanceof Error || error instanceof DOMException) &&
108
+ error.name === 'AbortError');
109
+ }
110
+ /**
111
+ * Map any failure onto the core platform taxonomy.
112
+ *
113
+ * @param error - the caught failure.
114
+ * @returns the classified platform error.
115
+ */
116
+ export function classifyWecomError(error) {
117
+ if (error instanceof PlatformError)
118
+ return error;
119
+ if (error instanceof WecomApiError) {
120
+ const init = {
121
+ ...(error.status === undefined ? {} : { code: error.status }),
122
+ cause: error,
123
+ };
124
+ if (error.errcode !== undefined) {
125
+ const verdict = verdictOfCode(error.errcode) ?? RETRYABLE;
126
+ return new PlatformError(verdict.kind, error.message, {
127
+ ...init,
128
+ code: error.errcode,
129
+ published: verdict.published,
130
+ });
131
+ }
132
+ if (error.status === 429) {
133
+ // A rate limit refused the request; the platform publishes no retry delay, so none is invented.
134
+ return new PlatformError('rate-limit', error.message, {
135
+ ...init,
136
+ published: 'no',
137
+ });
138
+ }
139
+ // A body that is not JSON came from something in front of the API (a gateway page, a cut-off answer), and a 5xx or
140
+ // a transport failure may still have reached the platform.
141
+ if (error.status === undefined || error.nonJson || error.status >= 500) {
142
+ return new PlatformError('retryable', error.message, {
143
+ ...init,
144
+ published: 'unknown',
145
+ });
146
+ }
147
+ if (error.status !== undefined && error.status >= 400) {
148
+ return new PlatformError('invalid', error.message, {
149
+ ...init,
150
+ published: 'no',
151
+ });
152
+ }
153
+ return new PlatformError('retryable', error.message, {
154
+ ...init,
155
+ published: 'unknown',
156
+ });
157
+ }
158
+ if (isAbortError(error)) {
159
+ return new PlatformError('fatal', error.message, {
160
+ published: 'unknown',
161
+ cause: error,
162
+ });
163
+ }
164
+ const message = error instanceof Error ? error.message : String(error);
165
+ return new PlatformError('retryable', `wecom: request failed: ${message}`, {
166
+ published: 'unknown',
167
+ cause: error,
168
+ });
169
+ }
170
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAkBlE,iCAAiC;AACjC,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,MAAM,CAAoB;IAC1B,OAAO,CAAoB;IAC3B,MAAM,CAAoB;IAC1B,QAAQ,CAAoB;IAC5B,OAAO,CAAS;IAEzB,YAAY,OAAe,EAAE,OAA0B,EAAE;QACvD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;QAC5E,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAA;IACtC,CAAC;CACF;AAQD,MAAM,UAAU,GAAY,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AACnE,MAAM,KAAK,GAAY,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AACzD,MAAM,UAAU,GAAY,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AACnE,MAAM,SAAS,GAAY,EAAE,IAAI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,CAAA;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YACtD,OAAO,IAAI,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE;gBACjD,GAAG,IAAI;gBACP,SAAS,EAAE,IAAI;aAChB,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE;YACnD,GAAG,IAAI;YACP,SAAS,EAAE,SAAS;SACrB,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;YAC/C,SAAS,EAAE,SAAS;YACpB,KAAK,EAAE,KAAK;SACb,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACtE,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,0BAA0B,OAAO,EAAE,EAAE;QACzE,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { User } from '@deepseek-ai/cordis-plugin-im-core';
2
+ import type { AgentGetAnswer } from './internal.ts';
3
+ /** Failure to confirm the configured application identity. */
4
+ export declare class WecomIdentityError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ /**
8
+ * Verify an `agent/get` answer against the configured `AgentID` and turn it into `bot.user`.
9
+ *
10
+ * `bot.id` and `selfId` are fixed at construction, so the application is identified from configuration rather than
11
+ * discovered; this call proves the credentials belong to that application. A mismatch is a configuration error that no
12
+ * retry repairs.
13
+ *
14
+ * @param agentId - the configured `AgentID`.
15
+ * @param answer - the `GET /cgi-bin/agent/get` answer.
16
+ * @returns the bot's own user, with the name and logo the platform reports.
17
+ * @throws WecomIdentityError when the answer names another application.
18
+ */
19
+ export declare function verifyIdentity(agentId: string, answer: AgentGetAnswer): User;
20
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAA;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAEnD,8DAA8D;AAC9D,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAiB5E"}
@@ -0,0 +1,34 @@
1
+ /** Failure to confirm the configured application identity. */
2
+ export class WecomIdentityError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'WecomIdentityError';
6
+ }
7
+ }
8
+ /**
9
+ * Verify an `agent/get` answer against the configured `AgentID` and turn it into `bot.user`.
10
+ *
11
+ * `bot.id` and `selfId` are fixed at construction, so the application is identified from configuration rather than
12
+ * discovered; this call proves the credentials belong to that application. A mismatch is a configuration error that no
13
+ * retry repairs.
14
+ *
15
+ * @param agentId - the configured `AgentID`.
16
+ * @param answer - the `GET /cgi-bin/agent/get` answer.
17
+ * @returns the bot's own user, with the name and logo the platform reports.
18
+ * @throws WecomIdentityError when the answer names another application.
19
+ */
20
+ export function verifyIdentity(agentId, answer) {
21
+ if (answer.agentid === undefined ||
22
+ Number(answer.agentid) !== Number(agentId)) {
23
+ throw new WecomIdentityError(`wecom: agentId is ${agentId} but agent/get returned ${String(answer.agentid)}`);
24
+ }
25
+ return {
26
+ id: agentId,
27
+ ...(answer.name === undefined ? {} : { name: answer.name }),
28
+ ...(answer.square_logo_url === undefined
29
+ ? {}
30
+ : { avatar: answer.square_logo_url }),
31
+ isBot: true,
32
+ };
33
+ }
34
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAGA,8DAA8D;AAC9D,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,MAAsB;IACpE,IACE,MAAM,CAAC,OAAO,KAAK,SAAS;QAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,OAAO,CAAC,EAC1C,CAAC;QACD,MAAM,IAAI,kBAAkB,CAC1B,qBAAqB,OAAO,2BAA2B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAChF,CAAA;IACH,CAAC;IACD,OAAO;QACL,EAAE,EAAE,OAAO;QACX,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3D,GAAG,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS;YACtC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QACvC,KAAK,EAAE,IAAI;KACZ,CAAA;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ import * as Wecom from './types.ts';
2
+ export { WecomBot, WecomBot as default, type WecomModes } from './bot.ts';
3
+ export { AES_KEY_CHARS, Config, configError, routePath, TOKEN_MAX_CHARS, type Config as WecomConfig, } from './config.ts';
4
+ export { aesKeyOf, decryptPayload, matchesSignature, PKCS7_BLOCK_BYTES, signatureOf, WecomCryptoError, type DecryptedPayload, } from './crypto.ts';
5
+ export { chatOf, decodeMessage, decodeTemplateCardEvent, locationText, mediaSource, senderOf, type WecomCardReferrer, type WecomReferrer, } from './decode.ts';
6
+ export { classifyWecomError, isTokenFailure, isTokenFailureCode, verdictOfCode, WecomApiError, type WecomApiErrorInit, } from './errors.ts';
7
+ export { verifyIdentity, WecomIdentityError } from './identity.ts';
8
+ export { Internal, type AgentGetAnswer, type AppchatSendInput, type MediaUploadAnswer, type MessageSendAnswer, type UpdateTemplateCardInput, type UserGetAnswer, type WecomStatusAnswer, type WecomTokenAnswer, } from './internal.ts';
9
+ export { MEDIA_LIFETIME_MS, mediaTypeOf, serveMedia, uploadMedia, } from './media.ts';
10
+ export type { TemplateCard, TemplateCardButton, WecomCardButton, WecomDraft, WecomMediaKind, WecomModeTypes, WecomNode, WecomPayload, } from './modes/shared.ts';
11
+ export { assembleDraft, CARD_TITLE_FALLBACK, checkDraft, flattenNodes, hardCutBytes, nextTaskId, reportMovedMedia, serializeDraft, splitMarkdownBytes, WECOM_LIMITS, } from './modes/shared.ts';
12
+ export { createMarkdownMode } from './modes/markdown.ts';
13
+ export { download, endpointOf, invoke, type WecomRequestConfig, type WecomRequestEndpoint, } from './request.ts';
14
+ export { deletePart, members, sendPayload, type WecomSendDeps } from './send.ts';
15
+ export { AccessTokenCache } from './token.ts';
16
+ export { WecomWebhook, type WebHandlerRoute, type WebServerLike, } from './transport/webhook.ts';
17
+ export { fieldsOf, parseMessageXml, parseXml, WecomXmlError, type XmlFields, } from './xml.ts';
18
+ export { Wecom };
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE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D,OAAO,EACL,QAAQ,EACR,UAAU,EACV,MAAM,EACN,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,aAAa,EACb,KAAK,SAAS,GACf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,18 @@
1
+ import * as Wecom from "./types.js";
2
+ export { WecomBot, WecomBot as default } from "./bot.js";
3
+ export { AES_KEY_CHARS, Config, configError, routePath, TOKEN_MAX_CHARS, } from "./config.js";
4
+ export { aesKeyOf, decryptPayload, matchesSignature, PKCS7_BLOCK_BYTES, signatureOf, WecomCryptoError, } from "./crypto.js";
5
+ export { chatOf, decodeMessage, decodeTemplateCardEvent, locationText, mediaSource, senderOf, } from "./decode.js";
6
+ export { classifyWecomError, isTokenFailure, isTokenFailureCode, verdictOfCode, WecomApiError, } from "./errors.js";
7
+ export { verifyIdentity, WecomIdentityError } from "./identity.js";
8
+ export { Internal, } from "./internal.js";
9
+ export { MEDIA_LIFETIME_MS, mediaTypeOf, serveMedia, uploadMedia, } from "./media.js";
10
+ export { assembleDraft, CARD_TITLE_FALLBACK, checkDraft, flattenNodes, hardCutBytes, nextTaskId, reportMovedMedia, serializeDraft, splitMarkdownBytes, WECOM_LIMITS, } from "./modes/shared.js";
11
+ export { createMarkdownMode } from "./modes/markdown.js";
12
+ export { download, endpointOf, invoke, } from "./request.js";
13
+ export { deletePart, members, sendPayload } from "./send.js";
14
+ export { AccessTokenCache } from "./token.js";
15
+ export { WecomWebhook, } from "./transport/webhook.js";
16
+ export { fieldsOf, parseMessageXml, parseXml, WecomXmlError, } from "./xml.js";
17
+ export { Wecom };
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAAI,OAAO,EAAmB,MAAM,UAAU,CAAA;AACzE,OAAO,EACL,aAAa,EACb,MAAM,EACN,WAAW,EACX,SAAS,EACT,eAAe,GAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,GAEjB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,MAAM,EACN,aAAa,EACb,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,QAAQ,GAGT,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,aAAa,GAEd,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EACL,QAAQ,GAST,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAA;AAWnB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,YAAY,GACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EACL,QAAQ,EACR,UAAU,EACV,MAAM,GAGP,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAsB,MAAM,WAAW,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,YAAY,GAGb,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,aAAa,GAEd,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,154 @@
1
+ import type { WecomBot } from './bot.ts';
2
+ import type { WecomPayload } from './modes/shared.ts';
3
+ import type { WecomTokenAnswer } from './token.ts';
4
+ /** Answer of `GET /cgi-bin/gettoken`; the token cache reads it. */
5
+ export type { WecomTokenAnswer };
6
+ /** Answer of `GET /cgi-bin/agent/get`. */
7
+ export interface AgentGetAnswer {
8
+ errcode?: number;
9
+ errmsg?: string;
10
+ agentid?: number | string;
11
+ name?: string;
12
+ square_logo_url?: string;
13
+ }
14
+ /** Answer of `GET /cgi-bin/user/get`. */
15
+ export interface UserGetAnswer {
16
+ errcode?: number;
17
+ errmsg?: string;
18
+ userid?: string;
19
+ name?: string;
20
+ }
21
+ /** Answer of `POST /cgi-bin/message/send`. */
22
+ export interface MessageSendAnswer {
23
+ errcode?: number;
24
+ errmsg?: string;
25
+ /** `|`-separated userids that do not exist or are outside the application's visible range. */
26
+ invaliduser?: string;
27
+ invalidparty?: string;
28
+ invalidtag?: string;
29
+ /** `|`-separated userids inside the range but without a basic API licence. */
30
+ unlicenseduser?: string;
31
+ msgid?: string;
32
+ /** Only a card that may be updated later carries one. */
33
+ response_code?: string;
34
+ }
35
+ /** Answer of `POST /cgi-bin/media/upload`. */
36
+ export interface MediaUploadAnswer {
37
+ errcode?: number;
38
+ errmsg?: string;
39
+ type?: string;
40
+ media_id?: string;
41
+ created_at?: number;
42
+ }
43
+ /** Answer of `POST /cgi-bin/message/recall`, `update_template_card` and `appchat/send`. */
44
+ export interface WecomStatusAnswer {
45
+ errcode?: number;
46
+ errmsg?: string;
47
+ msgid?: string;
48
+ }
49
+ /** One `update_template_card` request. */
50
+ export interface UpdateTemplateCardInput {
51
+ userids: string[];
52
+ agentid: number;
53
+ response_code: string;
54
+ template_card?: object;
55
+ button?: {
56
+ replace_name: string;
57
+ };
58
+ }
59
+ /** One `appchat/send` request: the platform's group-chat surface, which no adapter hook uses. */
60
+ export interface AppchatSendInput {
61
+ chatid: string;
62
+ msgtype: string;
63
+ [field: string]: unknown;
64
+ }
65
+ /**
66
+ * The mapped WeCom REST surface: one method per platform endpoint of the adapter's scope, and nothing hand-written on
67
+ * top of it.
68
+ *
69
+ * Every method goes through `request.ts`, so `access_token` injection, `errcode` unwrapping and the refresh-and-retry of
70
+ * a refused token are identical for all of them.
71
+ */
72
+ export declare class Internal {
73
+ private readonly bot;
74
+ constructor(bot: WecomBot);
75
+ /**
76
+ * Exchange the enterprise credentials for an application `access_token`.
77
+ *
78
+ * @param input - the enterprise id and the application secret.
79
+ * @returns the token envelope, with `expires_in`.
80
+ */
81
+ getToken(input: {
82
+ corpid: string;
83
+ corpsecret: string;
84
+ }): Promise<WecomTokenAnswer>;
85
+ /**
86
+ * Read one application's own description.
87
+ *
88
+ * @param input - the numeric `AgentID`.
89
+ * @returns the application envelope, with `name` and `square_logo_url`.
90
+ */
91
+ agentGet(input: {
92
+ agentid: number;
93
+ }): Promise<AgentGetAnswer>;
94
+ /**
95
+ * Read one member of the enterprise address book.
96
+ *
97
+ * @param input - the member userid.
98
+ * @returns the member envelope, with `name` when the application may see it.
99
+ */
100
+ userGet(input: {
101
+ userid: string;
102
+ }): Promise<UserGetAnswer>;
103
+ /**
104
+ * Push one application message.
105
+ *
106
+ * @param input - the exact `message/send` body.
107
+ * @returns the send envelope, with `msgid` and the invalid-recipient lists.
108
+ */
109
+ messageSend(input: WecomPayload): Promise<MessageSendAnswer>;
110
+ /**
111
+ * Upload one temporary media file.
112
+ *
113
+ * @param input - the platform media type (`image`, `voice`, `video`, `file`) and the multipart form.
114
+ * @returns the upload envelope, with `media_id` and `created_at`.
115
+ */
116
+ mediaUpload(input: {
117
+ type: string;
118
+ media: FormData;
119
+ }, signal?: AbortSignal): Promise<MediaUploadAnswer>;
120
+ /**
121
+ * Download the bytes of one temporary media file.
122
+ *
123
+ * @param input - the `media_id` the callback carried.
124
+ * @param signal - cancellation.
125
+ * @returns the answer as it arrived: the bytes, or the platform's JSON refusal.
126
+ */
127
+ mediaGet(input: {
128
+ media_id: string;
129
+ }, signal?: AbortSignal): Promise<Response>;
130
+ /**
131
+ * Recall one published application message.
132
+ *
133
+ * @param input - the `msgid` the send answer carried.
134
+ * @returns the status envelope.
135
+ */
136
+ messageRecall(input: {
137
+ msgid: string;
138
+ }): Promise<WecomStatusAnswer>;
139
+ /**
140
+ * Update one button-interaction card, within the platform's 72-hour, single-use window.
141
+ *
142
+ * @param input - the recipients, the card identity and the new card or button.
143
+ * @returns the status envelope.
144
+ */
145
+ updateTemplateCard(input: UpdateTemplateCardInput): Promise<WecomStatusAnswer>;
146
+ /**
147
+ * Send one message into an application group chat.
148
+ *
149
+ * @param input - the group chat id and the message fields.
150
+ * @returns the send envelope.
151
+ */
152
+ appchatSend(input: AppchatSendInput): Promise<WecomStatusAnswer>;
153
+ }
154
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,mEAAmE;AACnE,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,GAAG,MAA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,EAAE,uBAAuB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAW7B;;;;;OAKG;IACG,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAUvE"}
@@ -0,0 +1,115 @@
1
+ import { download, invoke } from "./request.js";
2
+ /**
3
+ * The mapped WeCom REST surface: one method per platform endpoint of the adapter's scope, and nothing hand-written on
4
+ * top of it.
5
+ *
6
+ * Every method goes through `request.ts`, so `access_token` injection, `errcode` unwrapping and the refresh-and-retry of
7
+ * a refused token are identical for all of them.
8
+ */
9
+ export class Internal {
10
+ bot;
11
+ constructor(bot) {
12
+ this.bot = bot;
13
+ }
14
+ /**
15
+ * Exchange the enterprise credentials for an application `access_token`.
16
+ *
17
+ * @param input - the enterprise id and the application secret.
18
+ * @returns the token envelope, with `expires_in`.
19
+ */
20
+ async getToken(input) {
21
+ return await invoke(this.bot, 'GET', '/cgi-bin/gettoken', {
22
+ params: { corpid: input.corpid, corpsecret: input.corpsecret },
23
+ });
24
+ }
25
+ /**
26
+ * Read one application's own description.
27
+ *
28
+ * @param input - the numeric `AgentID`.
29
+ * @returns the application envelope, with `name` and `square_logo_url`.
30
+ */
31
+ async agentGet(input) {
32
+ return await invoke(this.bot, 'GET', '/cgi-bin/agent/get', {
33
+ params: { agentid: input.agentid },
34
+ });
35
+ }
36
+ /**
37
+ * Read one member of the enterprise address book.
38
+ *
39
+ * @param input - the member userid.
40
+ * @returns the member envelope, with `name` when the application may see it.
41
+ */
42
+ async userGet(input) {
43
+ return await invoke(this.bot, 'GET', '/cgi-bin/user/get', {
44
+ params: { userid: input.userid },
45
+ });
46
+ }
47
+ /**
48
+ * Push one application message.
49
+ *
50
+ * @param input - the exact `message/send` body.
51
+ * @returns the send envelope, with `msgid` and the invalid-recipient lists.
52
+ */
53
+ async messageSend(input) {
54
+ return await invoke(this.bot, 'POST', '/cgi-bin/message/send', {
55
+ data: input,
56
+ });
57
+ }
58
+ /**
59
+ * Upload one temporary media file.
60
+ *
61
+ * @param input - the platform media type (`image`, `voice`, `video`, `file`) and the multipart form.
62
+ * @returns the upload envelope, with `media_id` and `created_at`.
63
+ */
64
+ async mediaUpload(input, signal) {
65
+ return await invoke(this.bot, 'POST', '/cgi-bin/media/upload', {
66
+ params: { type: input.type },
67
+ data: input.media,
68
+ ...(signal === undefined ? {} : { signal }),
69
+ });
70
+ }
71
+ /**
72
+ * Download the bytes of one temporary media file.
73
+ *
74
+ * @param input - the `media_id` the callback carried.
75
+ * @param signal - cancellation.
76
+ * @returns the answer as it arrived: the bytes, or the platform's JSON refusal.
77
+ */
78
+ async mediaGet(input, signal) {
79
+ return await download(this.bot, '/cgi-bin/media/get', { media_id: input.media_id }, signal);
80
+ }
81
+ /**
82
+ * Recall one published application message.
83
+ *
84
+ * @param input - the `msgid` the send answer carried.
85
+ * @returns the status envelope.
86
+ */
87
+ async messageRecall(input) {
88
+ return await invoke(this.bot, 'POST', '/cgi-bin/message/recall', {
89
+ data: { msgid: input.msgid },
90
+ });
91
+ }
92
+ /**
93
+ * Update one button-interaction card, within the platform's 72-hour, single-use window.
94
+ *
95
+ * @param input - the recipients, the card identity and the new card or button.
96
+ * @returns the status envelope.
97
+ */
98
+ async updateTemplateCard(input) {
99
+ return await invoke(this.bot, 'POST', '/cgi-bin/message/update_template_card', {
100
+ data: input,
101
+ });
102
+ }
103
+ /**
104
+ * Send one message into an application group chat.
105
+ *
106
+ * @param input - the group chat id and the message fields.
107
+ * @returns the send envelope.
108
+ */
109
+ async appchatSend(input) {
110
+ return await invoke(this.bot, 'POST', '/cgi-bin/appchat/send', {
111
+ data: input,
112
+ });
113
+ }
114
+ }
115
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAsE/C;;;;;;GAMG;AACH,MAAM,OAA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AAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;SAC5C,CACF,CAAA;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CACZ,KAA2B,EAC3B,MAAoB;QAEpB,OAAO,MAAM,QAAQ,CACnB,IAAI,CAAC,GAAG,EACR,oBAAoB,EACpB,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EAC5B,MAAM,CACP,CAAA;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,KAAwB;QAC1C,OAAO,MAAM,MAAM,CACjB,IAAI,CAAC,GAAG,EACR,MAAM,EACN,yBAAyB,EACzB;YACE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;SAC7B,CACF,CAAA;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,kBAAkB,CACtB,KAA8B;QAE9B,OAAO,MAAM,MAAM,CACjB,IAAI,CAAC,GAAG,EACR,MAAM,EACN,uCAAuC,EACvC;YACE,IAAI,EAAE,KAAK;SACZ,CACF,CAAA;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CAAC,KAAuB;QACvC,OAAO,MAAM,MAAM,CACjB,IAAI,CAAC,GAAG,EACR,MAAM,EACN,uBAAuB,EACvB;YACE,IAAI,EAAE,KAAK;SACZ,CACF,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Media in both directions.
3
+ *
4
+ * Outbound, the platform has a real upload endpoint: the bytes are fetched, posted to `media/upload` as a multipart form
5
+ * and the returned `media_id` is what a `message/send` of type `image`/`voice`/`video`/`file` carries. The id lives three
6
+ * days, so the resolved resource carries an `expiresAt` and the core uploads the same content again after that instead of
7
+ * reusing an id the platform has already dropped.
8
+ *
9
+ * Inbound, the callback names only a `MediaId`; the bytes are read on demand from `media/get` through the bot's own
10
+ * `satori:` route.
11
+ */
12
+ import type { PrepareContext, ResolvedResource, ResourceKind, ResourceRef } from '@deepseek-ai/cordis-plugin-im-core';
13
+ import type { WecomBot } from './bot.ts';
14
+ /** How long a temporary `media_id` stays readable: the platform documents three days. */
15
+ export declare const MEDIA_LIFETIME_MS: number;
16
+ /**
17
+ * The platform upload type of one resource kind.
18
+ *
19
+ * @param kind - the resource kind of the element.
20
+ * @returns `image`, `voice`, `video` or `file`; the platform names audio `voice`.
21
+ */
22
+ export declare function mediaTypeOf(kind: ResourceKind): 'image' | 'voice' | 'video' | 'file';
23
+ /**
24
+ * Upload one outbound attachment and return the `media_id` a send references.
25
+ *
26
+ * @param bot - the adapter whose credentials the upload uses.
27
+ * @param ref - the unresolved resource.
28
+ * @param ctx - fetch context of the send pipeline.
29
+ * @returns the platform media key, with the three-day expiry the core caches against.
30
+ * @throws PlatformError with an unknown outcome when the platform accepted the upload without returning an id.
31
+ */
32
+ export declare function uploadMedia(bot: WecomBot, ref: ResourceRef, ctx: PrepareContext): Promise<ResolvedResource>;
33
+ /**
34
+ * Serve the bytes of one inbound media object.
35
+ *
36
+ * A `media_id` the platform no longer accepts (it lives three days), a file above the 20 MB the plain download serves and
37
+ * a transport failure all answer `502`: the stored element keeps its label, but its bytes are gone.
38
+ *
39
+ * @param bot - the receiving adapter.
40
+ * @param mediaId - the `MediaId` the callback carried.
41
+ * @returns the bytes with their own headers, or the refusal status.
42
+ */
43
+ export declare function serveMedia(bot: WecomBot, mediaId: string): Promise<Response>;
44
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACZ,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,yFAAyF;AACzF,eAAO,MAAM,iBAAiB,QAA2B,CAAA;AAOzD;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,YAAY,GACjB,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAWtC;AAcD;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAoC3B;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,QAAQ,CAAC,CA8BnB"}