@im-more/dsh-line 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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/cordis.patch.yml +12 -0
  3. package/lib/index.js +1701 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/types/bot.d.ts +55 -0
  6. package/lib/types/bot.d.ts.map +1 -0
  7. package/lib/types/bot.js +169 -0
  8. package/lib/types/bot.js.map +1 -0
  9. package/lib/types/config.d.ts +47 -0
  10. package/lib/types/config.d.ts.map +1 -0
  11. package/lib/types/config.js +77 -0
  12. package/lib/types/config.js.map +1 -0
  13. package/lib/types/decode.d.ts +60 -0
  14. package/lib/types/decode.d.ts.map +1 -0
  15. package/lib/types/decode.js +321 -0
  16. package/lib/types/decode.js.map +1 -0
  17. package/lib/types/errors.d.ts +47 -0
  18. package/lib/types/errors.d.ts.map +1 -0
  19. package/lib/types/errors.js +112 -0
  20. package/lib/types/errors.js.map +1 -0
  21. package/lib/types/identity.d.ts +17 -0
  22. package/lib/types/identity.d.ts.map +1 -0
  23. package/lib/types/identity.js +24 -0
  24. package/lib/types/identity.js.map +1 -0
  25. package/lib/types/index.d.ts +17 -0
  26. package/lib/types/index.d.ts.map +1 -0
  27. package/lib/types/index.js +16 -0
  28. package/lib/types/index.js.map +1 -0
  29. package/lib/types/media.d.ts +19 -0
  30. package/lib/types/media.d.ts.map +1 -0
  31. package/lib/types/media.js +55 -0
  32. package/lib/types/media.js.map +1 -0
  33. package/lib/types/modes/shared.d.ts +126 -0
  34. package/lib/types/modes/shared.d.ts.map +1 -0
  35. package/lib/types/modes/shared.js +316 -0
  36. package/lib/types/modes/shared.js.map +1 -0
  37. package/lib/types/modes/text.d.ts +13 -0
  38. package/lib/types/modes/text.d.ts.map +1 -0
  39. package/lib/types/modes/text.js +143 -0
  40. package/lib/types/modes/text.js.map +1 -0
  41. package/lib/types/request.d.ts +49 -0
  42. package/lib/types/request.d.ts.map +1 -0
  43. package/lib/types/request.js +162 -0
  44. package/lib/types/request.js.map +1 -0
  45. package/lib/types/send.d.ts +43 -0
  46. package/lib/types/send.d.ts.map +1 -0
  47. package/lib/types/send.js +74 -0
  48. package/lib/types/send.js.map +1 -0
  49. package/lib/types/signature.d.ts +19 -0
  50. package/lib/types/signature.d.ts.map +1 -0
  51. package/lib/types/signature.js +30 -0
  52. package/lib/types/signature.js.map +1 -0
  53. package/lib/types/transport/media.d.ts +62 -0
  54. package/lib/types/transport/media.d.ts.map +1 -0
  55. package/lib/types/transport/media.js +104 -0
  56. package/lib/types/transport/media.js.map +1 -0
  57. package/lib/types/transport/webhook.d.ts +62 -0
  58. package/lib/types/transport/webhook.d.ts.map +1 -0
  59. package/lib/types/transport/webhook.js +208 -0
  60. package/lib/types/transport/webhook.js.map +1 -0
  61. package/lib/types/types/definition.d.ts +1006 -0
  62. package/lib/types/types/definition.d.ts.map +1 -0
  63. package/lib/types/types/definition.js +2 -0
  64. package/lib/types/types/definition.js.map +1 -0
  65. package/lib/types/types/index.d.ts +542 -0
  66. package/lib/types/types/index.d.ts.map +1 -0
  67. package/lib/types/types/index.js +4 -0
  68. package/lib/types/types/index.js.map +1 -0
  69. package/lib/types/types/internal.d.ts +8 -0
  70. package/lib/types/types/internal.d.ts.map +1 -0
  71. package/lib/types/types/internal.js +234 -0
  72. package/lib/types/types/internal.js.map +1 -0
  73. package/lib/types/types/request.d.ts +341 -0
  74. package/lib/types/types/request.d.ts.map +1 -0
  75. package/lib/types/types/request.js +2 -0
  76. package/lib/types/types/request.js.map +1 -0
  77. package/package.json +61 -3
  78. package/src/bot.ts +229 -0
  79. package/src/config.ts +113 -0
  80. package/src/decode.ts +418 -0
  81. package/src/errors.ts +138 -0
  82. package/src/identity.ts +28 -0
  83. package/src/index.ts +60 -0
  84. package/src/media.ts +66 -0
  85. package/src/modes/shared.ts +408 -0
  86. package/src/modes/text.ts +177 -0
  87. package/src/request.ts +215 -0
  88. package/src/send.ts +104 -0
  89. package/src/signature.ts +32 -0
  90. package/src/transport/media.ts +117 -0
  91. package/src/transport/webhook.ts +266 -0
  92. package/src/types/.eslintrc.yml +2 -0
  93. package/src/types/definition.ts +1008 -0
  94. package/src/types/index.ts +593 -0
  95. package/src/types/internal.ts +233 -0
  96. package/src/types/request.ts +341 -0
  97. package/README.md +0 -3
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `text` mode: LINE message objects, which is the only outbound representation the Messaging API programs against.
3
+ *
4
+ * Text is sent verbatim — a LINE text message has no markup, so nothing is escaped. Images, videos and audio become
5
+ * message objects of their own; a video without a poster and an audio without a duration cannot be expressed (both
6
+ * fields are required by the platform), so they become a link the LINE client can open. Buttons become quick reply
7
+ * items. Everything else takes the core fallback and is reported as degraded.
8
+ */
9
+ import type { Mode } from '@deepseek-ai/cordis-plugin-im-core';
10
+ import type { LineModeTypes } from './shared.ts';
11
+ /** Build the `text` mode. */
12
+ export declare function createTextMode(): Mode<LineModeTypes>;
13
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/modes/text.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAiB,MAAM,oCAAoC,CAAA;AAS7E,OAAO,KAAK,EAAc,aAAa,EAAY,MAAM,aAAa,CAAA;AAmHtE,6BAA6B;AAC7B,wBAAgB,cAAc,IAAI,IAAI,CAAC,aAAa,CAAC,CAyCpD"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * `text` mode: LINE message objects, which is the only outbound representation the Messaging API programs against.
3
+ *
4
+ * Text is sent verbatim — a LINE text message has no markup, so nothing is escaped. Images, videos and audio become
5
+ * message objects of their own; a video without a poster and an audio without a duration cannot be expressed (both
6
+ * fields are required by the platform), so they become a link the LINE client can open. Buttons become quick reply
7
+ * items. Everything else takes the core fallback and is reported as degraded.
8
+ */
9
+ import { ElementRegistry } from '@deepseek-ai/cordis-plugin-im-core';
10
+ import { assembleDraft, checkDraft, LINE_LIMITS, reportMovedMedia, serializeDraft, } from "./shared.js";
11
+ /** The link text a media element the platform cannot send as its kind degrades to. */
12
+ function linkText(name, src) {
13
+ return name === undefined || name === '' ? src : `${name}: ${src}`;
14
+ }
15
+ /** The text run of rendered children and the media that cannot stay inside it. */
16
+ function textRun(nodes) {
17
+ let text = '';
18
+ const rest = [];
19
+ for (const node of nodes) {
20
+ if (node.type === 'text')
21
+ text += node.text;
22
+ else
23
+ rest.push(node);
24
+ }
25
+ return { text, nodes: rest };
26
+ }
27
+ /** One image message object, reported as moved when it stood inside a phrasing container. */
28
+ function imageNode(el, ctx) {
29
+ reportMovedMedia(el, ctx);
30
+ return {
31
+ type: 'media',
32
+ block: { type: 'image', ref: ctx.resource('image', el.attrs.src, {}) },
33
+ };
34
+ }
35
+ /** One video message object; without a poster the platform refuses the object, so the video becomes a link. */
36
+ function videoNode(el, ctx) {
37
+ const { src, poster, name } = el.attrs;
38
+ if (poster === undefined) {
39
+ // The message object requires a preview image, so the video playback is what the platform cannot carry while its
40
+ // link still is. A degraded entry would claim the element itself reached the platform.
41
+ ctx.report.dropped.push({
42
+ what: `video:${name ?? src}`,
43
+ reason: 'line-video-poster',
44
+ });
45
+ return { type: 'text', text: linkText(name, src) };
46
+ }
47
+ reportMovedMedia(el, ctx);
48
+ return {
49
+ type: 'media',
50
+ block: {
51
+ type: 'video',
52
+ ref: ctx.resource('video', src, name === undefined ? {} : { name }),
53
+ poster: ctx.resource('image', poster, {}),
54
+ },
55
+ };
56
+ }
57
+ /** One audio message object; the platform requires the duration, so an audio without one becomes a link. */
58
+ function audioNode(el, ctx) {
59
+ const { src, name, duration } = el.attrs;
60
+ if (duration === undefined) {
61
+ ctx.report.dropped.push({
62
+ what: `audio:${name ?? src}`,
63
+ reason: 'line-audio-duration',
64
+ });
65
+ return { type: 'text', text: linkText(name, src) };
66
+ }
67
+ reportMovedMedia(el, ctx);
68
+ return {
69
+ type: 'media',
70
+ block: {
71
+ type: 'audio',
72
+ ref: ctx.resource('audio', src, {
73
+ ...(name === undefined ? {} : { name }),
74
+ duration,
75
+ }),
76
+ duration,
77
+ },
78
+ };
79
+ }
80
+ /** The quick reply action of one button, by its type. */
81
+ function buttonAction(el, ctx) {
82
+ const label = ctx.text(el.children).trim();
83
+ switch (el.attrs.type) {
84
+ case 'link':
85
+ return {
86
+ type: 'uri',
87
+ label: label === '' ? el.attrs.href : label,
88
+ uri: el.attrs.href,
89
+ };
90
+ case 'input':
91
+ return {
92
+ type: 'message',
93
+ label: label === '' ? el.attrs.text : label,
94
+ text: el.attrs.text,
95
+ };
96
+ case 'action':
97
+ case 'submit':
98
+ return {
99
+ type: 'postback',
100
+ label: label === '' ? el.attrs.id : label,
101
+ data: el.attrs.id,
102
+ };
103
+ }
104
+ }
105
+ /** Build the `text` mode. */
106
+ export function createTextMode() {
107
+ const elements = new ElementRegistry()
108
+ .register('text', (el) => ({ type: 'text', text: el.attrs.content }))
109
+ .register('br', () => ({ type: 'text', text: '\n' }))
110
+ // Paragraphs hand their children through, so inline media reaches `assemble` instead of being flattened away.
111
+ .register('p', (el, ctx) => [
112
+ ...ctx.render(el.children),
113
+ { type: 'text', text: '\n\n' },
114
+ ])
115
+ .register('a', (el, ctx) => {
116
+ const run = textRun(ctx.render(el.children));
117
+ // LINE turns a bare URL into a tap target; a link's label keeps the URL visible when it would otherwise be lost.
118
+ const text = run.text.includes(el.attrs.href)
119
+ ? run.text
120
+ : run.text.trim() === ''
121
+ ? el.attrs.href
122
+ : `${run.text} (${el.attrs.href})`;
123
+ return [{ type: 'text', text }, ...run.nodes];
124
+ })
125
+ .register('img', (el, ctx) => imageNode(el, ctx), { variants: ['inline'] })
126
+ .register('video', (el, ctx) => videoNode(el, ctx))
127
+ .register('audio', (el, ctx) => audioNode(el, ctx))
128
+ .register('button', (el, ctx) => ({ type: 'button', action: buttonAction(el, ctx) }), { variants: ['action', 'link', 'input', 'submit', 'theme', 'inline'] })
129
+ .register('button-group', (el, ctx) => ctx.render(el.children));
130
+ return {
131
+ id: 'text',
132
+ elements,
133
+ limits: {
134
+ 'limit.text.chars': LINE_LIMITS.text,
135
+ 'limit.buttons.rows': LINE_LIMITS.quickReplies,
136
+ 'limit.payload.bytes': LINE_LIMITS.payloadBytes,
137
+ },
138
+ assemble: (nodes) => assembleDraft(nodes),
139
+ serialize: (prepared, ctx) => serializeDraft(prepared, ctx),
140
+ check: (draft) => checkDraft(draft),
141
+ };
142
+ }
143
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/modes/text.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAGpE,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAA;AAGpB,sFAAsF;AACtF,SAAS,QAAQ,CAAC,IAAwB,EAAE,GAAW;IACrD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,GAAG,EAAE,CAAA;AACpE,CAAC;AAED,kFAAkF;AAClF,SAAS,OAAO,CAAC,KAA0B;IAIzC,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,MAAM,IAAI,GAAe,EAAE,CAAA;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;YAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;;YACtC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACtB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AAC9B,CAAC;AAED,6FAA6F;AAC7F,SAAS,SAAS,CAChB,EAAkB,EAClB,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AO;QACL,EAAE,EAAE,MAAM;QACV,QAAQ;QACR,MAAM,EAAE;YACN,kBAAkB,EAAE,WAAW,CAAC,IAAI;YACpC,oBAAoB,EAAE,WAAW,CAAC,YAAY;YAC9C,qBAAqB,EAAE,WAAW,CAAC,YAAY;SAChD;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;QACzC,SAAS,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC;QAC3D,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;KACpC,CAAA;AACH,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The transport every LINE REST call shares: API root, bearer authentication, JSON unwrapping, the failure
3
+ * `errors.ts` classifies, and content download.
4
+ *
5
+ * The typed method surface lives on `Internal`; the generated route table calls {@link invoke}, so the migrated layer
6
+ * and the hand-written calls (identity, push, members, content download) cannot diverge in authentication or failure
7
+ * handling.
8
+ */
9
+ import type { Context } from '@deepseek-ai/cordis';
10
+ import type { Config } from './config.ts';
11
+ /** Root of the messaging API: every method except content download and the two audience uploads. */
12
+ export declare const LINE_API_ORIGIN = "https://api.line.me";
13
+ /** Root of the content API, which serves the bytes of an inbound message. */
14
+ export declare const LINE_DATA_ORIGIN = "https://api-data.line.me";
15
+ /** One request body, query and cancellation, as the generated route table describes it. */
16
+ export interface LineRequestConfig {
17
+ data?: object;
18
+ params?: Record<string, unknown> | undefined;
19
+ signal?: AbortSignal | undefined;
20
+ }
21
+ /** What one call needs from the adapter. */
22
+ export interface LineRequest {
23
+ readonly ctx: Context;
24
+ readonly config: Config;
25
+ }
26
+ /**
27
+ * Call one messaging API endpoint.
28
+ *
29
+ * @param request - the adapter whose credentials and context the call uses.
30
+ * @param method - HTTP method.
31
+ * @param path - endpoint path under {@link LINE_API_ORIGIN}.
32
+ * @param config - body, query parameters and cancellation of the call.
33
+ * @returns the unwrapped JSON answer.
34
+ * @throws LineApiError when the platform refused the call or did not answer with JSON.
35
+ */
36
+ export declare function invoke<T>(request: LineRequest, method: string, path: string, config?: LineRequestConfig): Promise<T>;
37
+ /**
38
+ * Download the bytes of one inbound message from the content API.
39
+ *
40
+ * The answer is returned as it arrived, whatever its status: the caller maps `200`/`202`/`404`/`410` to the inbound
41
+ * media contract. A request that never got an answer rejects.
42
+ *
43
+ * @param request - the adapter whose credentials and context the download uses.
44
+ * @param messageId - platform message id the bytes belong to.
45
+ * @param signal - cancellation.
46
+ * @returns the content API answer.
47
+ */
48
+ export declare function downloadContent(request: LineRequest, messageId: string, signal?: AbortSignal): Promise<Response>;
49
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIzC,oGAAoG;AACpG,eAAO,MAAM,eAAe,wBAAwB,CAAA;AAEpD,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,6BAA6B,CAAA;AAK1D,2FAA2F;AAC3F,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAC5C,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED,4CAA4C;AAC5C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAgED;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAC5B,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,CAAC,CAAC,CAqEZ;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,CAcnB"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The transport every LINE REST call shares: API root, bearer authentication, JSON unwrapping, the failure
3
+ * `errors.ts` classifies, and content download.
4
+ *
5
+ * The typed method surface lives on `Internal`; the generated route table calls {@link invoke}, so the migrated layer
6
+ * and the hand-written calls (identity, push, members, content download) cannot diverge in authentication or failure
7
+ * handling.
8
+ */
9
+ import { LineApiError } from "./errors.js";
10
+ /** Root of the messaging API: every method except content download and the two audience uploads. */
11
+ export const LINE_API_ORIGIN = 'https://api.line.me';
12
+ /** Root of the content API, which serves the bytes of an inbound message. */
13
+ export const LINE_DATA_ORIGIN = 'https://api-data.line.me';
14
+ /** How much of a body that carried no JSON is kept in the error and the log; enough to recognise a gateway page. */
15
+ const BODY_PREFIX_BYTES = 512;
16
+ /** Message of any caught value, for a log line. */
17
+ function messageOf(error) {
18
+ return error instanceof Error ? error.message : String(error);
19
+ }
20
+ /** Whether a failed `ctx.http` call was the caller's cancellation rather than a transport failure. */
21
+ function isCancellation(cause, signal) {
22
+ if (signal?.aborted === true)
23
+ return true;
24
+ if ((cause instanceof Error || cause instanceof DOMException) &&
25
+ cause.name === 'AbortError') {
26
+ return true;
27
+ }
28
+ return signal?.reason !== undefined && cause === signal.reason;
29
+ }
30
+ /** A cancelled request rejects with the signal's reason, so the classifier sees the cancellation itself. */
31
+ function cancellation(cause, signal) {
32
+ return signal?.aborted === true ? signal.reason : cause;
33
+ }
34
+ /** One JSON object, when the value is a plain object. */
35
+ function asRecord(value) {
36
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
37
+ ? value
38
+ : undefined;
39
+ }
40
+ /** The `details` array of a business refusal, keeping only the fields a log or a caller can name. */
41
+ function detailsOf(value) {
42
+ if (!Array.isArray(value))
43
+ return [];
44
+ const out = [];
45
+ for (const item of value) {
46
+ const record = asRecord(item);
47
+ if (record === undefined)
48
+ continue;
49
+ out.push({
50
+ ...(typeof record.property === 'string'
51
+ ? { property: record.property }
52
+ : {}),
53
+ ...(typeof record.message === 'string'
54
+ ? { message: record.message }
55
+ : {}),
56
+ });
57
+ }
58
+ return out;
59
+ }
60
+ /** The field names a business refusal names, for the error message. */
61
+ function propertiesOf(details) {
62
+ const names = details
63
+ .map((detail) => detail.property)
64
+ .filter((name) => name !== undefined && name !== '');
65
+ return names.length === 0 ? '' : ` (${names.join(', ')})`;
66
+ }
67
+ /**
68
+ * Call one messaging API endpoint.
69
+ *
70
+ * @param request - the adapter whose credentials and context the call uses.
71
+ * @param method - HTTP method.
72
+ * @param path - endpoint path under {@link LINE_API_ORIGIN}.
73
+ * @param config - body, query parameters and cancellation of the call.
74
+ * @returns the unwrapped JSON answer.
75
+ * @throws LineApiError when the platform refused the call or did not answer with JSON.
76
+ */
77
+ export async function invoke(request, method, path, config = {}) {
78
+ let response;
79
+ try {
80
+ response = await request.ctx.http(`${LINE_API_ORIGIN}${path}`, {
81
+ method,
82
+ headers: { authorization: `Bearer ${request.config.token}` },
83
+ ...(config.data === undefined ? {} : { data: config.data }),
84
+ ...(config.params === undefined ? {} : { params: config.params }),
85
+ ...(config.signal === undefined ? {} : { signal: config.signal }),
86
+ });
87
+ }
88
+ catch (cause) {
89
+ if (isCancellation(cause, config.signal)) {
90
+ throw cancellation(cause, config.signal);
91
+ }
92
+ throw new LineApiError(`line: ${method} ${path} request failed: ${messageOf(cause)}`, { cause });
93
+ }
94
+ let text;
95
+ try {
96
+ text = await response.text();
97
+ }
98
+ catch (cause) {
99
+ // Reading the body fails when the caller cancelled mid-answer; that is still a cancellation.
100
+ if (isCancellation(cause, config.signal)) {
101
+ throw cancellation(cause, config.signal);
102
+ }
103
+ throw new LineApiError(`line: ${method} ${path} answered ${response.status} but its body could not be read`, { status: response.status, cause });
104
+ }
105
+ let body;
106
+ let nonJson = false;
107
+ if (text !== '') {
108
+ try {
109
+ body = JSON.parse(text);
110
+ }
111
+ catch {
112
+ nonJson = true;
113
+ }
114
+ }
115
+ const record = asRecord(body);
116
+ const platformMessage = typeof record?.message === 'string'
117
+ ? record.message
118
+ : typeof record?.error_description === 'string'
119
+ ? record.error_description
120
+ : undefined;
121
+ const error = typeof record?.error === 'string' ? record.error : undefined;
122
+ const details = detailsOf(record?.details);
123
+ if (response.status < 200 || response.status >= 300 || nonJson) {
124
+ const suffix = (platformMessage === undefined ? '' : `: ${platformMessage}`) +
125
+ propertiesOf(details);
126
+ throw new LineApiError(`line: ${method} ${path} answered ${response.status}${suffix}`, {
127
+ status: response.status,
128
+ ...(platformMessage === undefined ? {} : { platformMessage }),
129
+ ...(error === undefined ? {} : { error }),
130
+ ...(details.length === 0 ? {} : { details }),
131
+ ...(text === '' ? {} : { bodyText: text.slice(0, BODY_PREFIX_BYTES) }),
132
+ nonJson,
133
+ });
134
+ }
135
+ return body;
136
+ }
137
+ /**
138
+ * Download the bytes of one inbound message from the content API.
139
+ *
140
+ * The answer is returned as it arrived, whatever its status: the caller maps `200`/`202`/`404`/`410` to the inbound
141
+ * media contract. A request that never got an answer rejects.
142
+ *
143
+ * @param request - the adapter whose credentials and context the download uses.
144
+ * @param messageId - platform message id the bytes belong to.
145
+ * @param signal - cancellation.
146
+ * @returns the content API answer.
147
+ */
148
+ export async function downloadContent(request, messageId, signal) {
149
+ try {
150
+ const response = await request.ctx.http(`${LINE_DATA_ORIGIN}/v2/bot/message/${encodeURIComponent(messageId)}/content`, {
151
+ headers: { authorization: `Bearer ${request.config.token}` },
152
+ ...(signal === undefined ? {} : { signal }),
153
+ });
154
+ return response;
155
+ }
156
+ catch (cause) {
157
+ if (isCancellation(cause, signal))
158
+ throw cancellation(cause, signal);
159
+ throw cause;
160
+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Q,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC;YAAE,MAAM,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QACpE,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Outbound: one push request per draft, and the member pages `im_members` reads.
3
+ *
4
+ * LINE has no reply API the DSH pipeline could use — a reply token lives one minute and is single-use, while a turn may
5
+ * run for minutes — so every send is a push. The reply token is still kept in the inbound referrer for a plugin that
6
+ * calls `bot.internal.replyMessage` itself.
7
+ */
8
+ import type { ChatRef, MembersPage, SendContext, SentPart, Target } from '@deepseek-ai/cordis-plugin-im-core';
9
+ import type { LinePayload } from './modes/shared.ts';
10
+ import type { Internal } from './types/internal.ts';
11
+ /** Everything `sendPayload` and `members` need from the adapter. */
12
+ export interface LineSendDeps {
13
+ readonly internal: Internal;
14
+ }
15
+ /**
16
+ * Send one serialized payload and report the parts the platform created.
17
+ *
18
+ * A refused push is a request-level failure: LINE has no partial send, and it documents that a request answered with an
19
+ * error sent nothing.
20
+ *
21
+ * @param deps - the adapter's API surface.
22
+ * @param payload - one push body.
23
+ * @param _target - the chat the payload goes to; the recipient already rides `payload.to`.
24
+ * @param _ctx - the core send context; this adapter keeps no per-part state.
25
+ * @returns the published part; its `aliases` are the remaining message ids of the same request.
26
+ * @throws PlatformError `invalid` when the answer carries no `sentMessages`, with an unknown outcome.
27
+ */
28
+ export declare function sendPayload(deps: LineSendDeps, payload: LinePayload, _target: Target, _ctx: SendContext): Promise<SentPart>;
29
+ /**
30
+ * One page of the members of a chat.
31
+ *
32
+ * A group or a room lists its member ids through the platform; a direct chat's only member is the peer, which the
33
+ * `chat.id` already names. Names are not filled in: the platform wants one profile request per member, and that
34
+ * request is refused for a user who has not agreed to the Official Accounts Terms of Use.
35
+ *
36
+ * @param deps - the adapter's API surface.
37
+ * @param chat - the chat to list.
38
+ * @param cursor - the previous page's `next` token, valid for 24 hours.
39
+ * @param _limit - unused; the platform fixes the page size at 100 and the host truncates the answer.
40
+ * @returns one page of member ids.
41
+ */
42
+ export declare function members(deps: LineSendDeps, chat: ChatRef, cursor?: string, _limit?: number): Promise<MembersPage>;
43
+ //# sourceMappingURL=send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/send.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,EACR,MAAM,EACP,MAAM,oCAAoC,CAAA;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,QAAQ,CAAC,CA4BnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,OAAO,EACb,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,CAYtB"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Outbound: one push request per draft, and the member pages `im_members` reads.
3
+ *
4
+ * LINE has no reply API the DSH pipeline could use — a reply token lives one minute and is single-use, while a turn may
5
+ * run for minutes — so every send is a push. The reply token is still kept in the inbound referrer for a plugin that
6
+ * calls `bot.internal.replyMessage` itself.
7
+ */
8
+ import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
9
+ import { parseChatId } from "./decode.js";
10
+ /**
11
+ * Send one serialized payload and report the parts the platform created.
12
+ *
13
+ * A refused push is a request-level failure: LINE has no partial send, and it documents that a request answered with an
14
+ * error sent nothing.
15
+ *
16
+ * @param deps - the adapter's API surface.
17
+ * @param payload - one push body.
18
+ * @param _target - the chat the payload goes to; the recipient already rides `payload.to`.
19
+ * @param _ctx - the core send context; this adapter keeps no per-part state.
20
+ * @returns the published part; its `aliases` are the remaining message ids of the same request.
21
+ * @throws PlatformError `invalid` when the answer carries no `sentMessages`, with an unknown outcome.
22
+ */
23
+ export async function sendPayload(deps, payload, _target, _ctx) {
24
+ const answer = await deps.internal.pushMessage({
25
+ to: payload.to,
26
+ messages: payload.messages,
27
+ });
28
+ const sent = answer.sentMessages ?? [];
29
+ const [head, ...rest] = sent;
30
+ if (head === undefined) {
31
+ // The request reached the platform and was accepted, but no message id came back: the outcome is not "unpublished".
32
+ throw new PlatformError('invalid', 'line: pushMessage answered without sentMessages', { published: 'unknown' });
33
+ }
34
+ return {
35
+ id: head.id,
36
+ kind: 'message',
37
+ time: Date.now(),
38
+ ...(rest.length === 0
39
+ ? {}
40
+ : { aliases: rest.map((message) => message.id) }),
41
+ // The quote tokens of this request are how a later reply can quote one of its own messages.
42
+ raw: {
43
+ ids: sent.map((message) => message.id),
44
+ quoteTokens: sent.map((message) => message.quoteToken),
45
+ },
46
+ };
47
+ }
48
+ /**
49
+ * One page of the members of a chat.
50
+ *
51
+ * A group or a room lists its member ids through the platform; a direct chat's only member is the peer, which the
52
+ * `chat.id` already names. Names are not filled in: the platform wants one profile request per member, and that
53
+ * request is refused for a user who has not agreed to the Official Accounts Terms of Use.
54
+ *
55
+ * @param deps - the adapter's API surface.
56
+ * @param chat - the chat to list.
57
+ * @param cursor - the previous page's `next` token, valid for 24 hours.
58
+ * @param _limit - unused; the platform fixes the page size at 100 and the host truncates the answer.
59
+ * @returns one page of member ids.
60
+ */
61
+ export async function members(deps, chat, cursor, _limit) {
62
+ const address = parseChatId(chat.id);
63
+ if (address.kind === 'user')
64
+ return { data: [{ id: address.id }] };
65
+ const query = cursor === undefined ? undefined : { start: cursor };
66
+ const answer = address.kind === 'group'
67
+ ? await deps.internal.getGroupMembersIds(address.id, query)
68
+ : await deps.internal.getRoomMembersIds(address.id, query);
69
+ return {
70
+ data: answer.memberIds.map((id) => ({ id })),
71
+ ...(answer.next === undefined ? {} : { next: answer.next }),
72
+ };
73
+ }
74
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.js","sourceRoot":"","sources":["../../src/send.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAQlE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AASzC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAkB,EAClB,OAAoB,EACpB,OAAe,EACf,IAAiB;IAEjB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;QAC7C,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC,CAAA;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAA;IACtC,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;IAC5B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,oHAAoH;QACpH,MAAM,IAAI,aAAa,CACrB,SAAS,EACT,iDAAiD,EACjD,EAAE,SAAS,EAAE,SAAS,EAAE,CACzB,CAAA;IACH,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAChB,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC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5C,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;KAC5D,CAAA;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The `x-line-signature` value of one webhook request.
3
+ *
4
+ * LINE signs the request body exactly as it arrived, keyed by the channel secret.
5
+ *
6
+ * @param secret - the channel secret.
7
+ * @param body - the raw request body, before any decoding.
8
+ * @returns base64 of `HMAC-SHA256(secret, body)`.
9
+ */
10
+ export declare function signatureOf(secret: string, body: string): string;
11
+ /**
12
+ * Compare a received signature with the computed one without leaking where they differ.
13
+ *
14
+ * @param expected - the signature computed from the body.
15
+ * @param received - the header value, if the request carried one.
16
+ * @returns whether the header matches.
17
+ */
18
+ export declare function matchesSignature(expected: string, received: string | undefined): boolean;
19
+ //# sourceMappingURL=signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,OAAO,CAMT"}
@@ -0,0 +1,30 @@
1
+ import { createHmac, timingSafeEqual } from 'node:crypto';
2
+ /**
3
+ * The `x-line-signature` value of one webhook request.
4
+ *
5
+ * LINE signs the request body exactly as it arrived, keyed by the channel secret.
6
+ *
7
+ * @param secret - the channel secret.
8
+ * @param body - the raw request body, before any decoding.
9
+ * @returns base64 of `HMAC-SHA256(secret, body)`.
10
+ */
11
+ export function signatureOf(secret, body) {
12
+ return createHmac('sha256', secret).update(body).digest('base64');
13
+ }
14
+ /**
15
+ * Compare a received signature with the computed one without leaking where they differ.
16
+ *
17
+ * @param expected - the signature computed from the body.
18
+ * @param received - the header value, if the request carried one.
19
+ * @returns whether the header matches.
20
+ */
21
+ export function matchesSignature(expected, received) {
22
+ if (received === undefined)
23
+ return false;
24
+ const left = Buffer.from(expected, 'utf8');
25
+ const right = Buffer.from(received, 'utf8');
26
+ if (left.length !== right.length)
27
+ return false;
28
+ return timingSafeEqual(left, right);
29
+ }
30
+ //# sourceMappingURL=signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,IAAY;IACtD,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACnE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAgB,EAChB,QAA4B;IAE5B,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,KAAK,CAAA;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC3C,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAC9C,OAAO,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACrC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Outbound media: the public route LINE fetches staged bytes from.
3
+ *
4
+ * The Messaging API has no endpoint that uploads message media; an image, video or audio message carries only HTTPS URLs
5
+ * that the LINE servers fetch themselves. The adapter therefore stages the bytes of every non-HTTPS source in memory
6
+ * and serves them from an anonymous, unguessable URL for the lifetime of the process.
7
+ */
8
+ import type { LineBot } from '../bot.ts';
9
+ import type { WebServerLike } from './webhook.ts';
10
+ /** One staged attachment. */
11
+ export interface StagedMedia {
12
+ data: Uint8Array;
13
+ mime?: string;
14
+ name?: string;
15
+ }
16
+ /**
17
+ * Staged bytes by opaque token.
18
+ *
19
+ * Entries live until the process exits: the platform may fetch a URL minutes after a send, and the W1 rule forbids
20
+ * inventing a TTL or a byte cap the platform does not document. The `prepare` cache means the same media is staged
21
+ * once, not once per send.
22
+ */
23
+ export declare class MediaStaging {
24
+ private readonly base;
25
+ private readonly prefix;
26
+ private readonly entries;
27
+ constructor(base: string, prefix: string);
28
+ /**
29
+ * Stage one attachment.
30
+ *
31
+ * @param media - the bytes, their MIME type and name.
32
+ * @returns the public URL LINE fetches the bytes from.
33
+ */
34
+ stage(media: StagedMedia): string;
35
+ /**
36
+ * Read staged bytes back.
37
+ *
38
+ * @param token - the last path segment of a URL returned by {@link stage}.
39
+ * @returns the staged attachment, or undefined for an unknown token.
40
+ */
41
+ get(token: string): StagedMedia | undefined;
42
+ /** The number of attachments currently staged, for tests and diagnostics. */
43
+ get size(): number;
44
+ }
45
+ /**
46
+ * The public media route.
47
+ *
48
+ * It is registered as a `prefix` resource, so the web server hands it a Fetch `Request` and takes the `Response` back;
49
+ * the route is anonymous because LINE's servers carry no DSH peer credential.
50
+ */
51
+ export declare class LineMediaRoute {
52
+ private readonly bot;
53
+ private readonly webServer;
54
+ private dispose;
55
+ constructor(bot: LineBot, webServer: WebServerLike);
56
+ /** Register the prefix route. */
57
+ start(): void;
58
+ /** Release the route. */
59
+ stop(): void;
60
+ private serve;
61
+ }
62
+ //# sourceMappingURL=media.d.ts.map