@kodelyth/line 2026.5.42 → 2026.6.2

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 (90) hide show
  1. package/klaw.plugin.json +329 -2
  2. package/package.json +18 -6
  3. package/api.ts +0 -11
  4. package/channel-plugin-api.ts +0 -1
  5. package/contract-api.ts +0 -5
  6. package/index.ts +0 -53
  7. package/runtime-api.ts +0 -179
  8. package/secret-contract-api.ts +0 -4
  9. package/setup-api.ts +0 -2
  10. package/setup-entry.ts +0 -9
  11. package/src/account-helpers.ts +0 -16
  12. package/src/accounts.test.ts +0 -288
  13. package/src/accounts.ts +0 -187
  14. package/src/actions.ts +0 -61
  15. package/src/auto-reply-delivery.test.ts +0 -253
  16. package/src/auto-reply-delivery.ts +0 -200
  17. package/src/bindings.ts +0 -65
  18. package/src/bot-access.ts +0 -30
  19. package/src/bot-handlers.test.ts +0 -1094
  20. package/src/bot-handlers.ts +0 -620
  21. package/src/bot-message-context.test.ts +0 -420
  22. package/src/bot-message-context.ts +0 -586
  23. package/src/bot.ts +0 -66
  24. package/src/card-command.ts +0 -347
  25. package/src/channel-access-token.ts +0 -14
  26. package/src/channel-api.ts +0 -17
  27. package/src/channel-setup-status.contract.test.ts +0 -70
  28. package/src/channel-shared.ts +0 -48
  29. package/src/channel.logout.test.ts +0 -145
  30. package/src/channel.runtime.ts +0 -3
  31. package/src/channel.sendPayload.test.ts +0 -659
  32. package/src/channel.setup.ts +0 -11
  33. package/src/channel.status.test.ts +0 -63
  34. package/src/channel.ts +0 -155
  35. package/src/config-adapter.ts +0 -29
  36. package/src/config-schema.test.ts +0 -53
  37. package/src/config-schema.ts +0 -81
  38. package/src/download.test.ts +0 -164
  39. package/src/download.ts +0 -34
  40. package/src/flex-templates/basic-cards.ts +0 -395
  41. package/src/flex-templates/common.ts +0 -20
  42. package/src/flex-templates/media-control-cards.ts +0 -555
  43. package/src/flex-templates/message.ts +0 -13
  44. package/src/flex-templates/schedule-cards.ts +0 -467
  45. package/src/flex-templates/types.ts +0 -22
  46. package/src/flex-templates.ts +0 -32
  47. package/src/gateway.ts +0 -129
  48. package/src/group-keys.test.ts +0 -123
  49. package/src/group-keys.ts +0 -65
  50. package/src/group-policy.ts +0 -22
  51. package/src/markdown-to-line.test.ts +0 -348
  52. package/src/markdown-to-line.ts +0 -416
  53. package/src/message-cards.test.ts +0 -204
  54. package/src/monitor-durable.test.ts +0 -57
  55. package/src/monitor-durable.ts +0 -37
  56. package/src/monitor.lifecycle.test.ts +0 -499
  57. package/src/monitor.runtime.ts +0 -1
  58. package/src/monitor.ts +0 -507
  59. package/src/outbound-media.test.ts +0 -194
  60. package/src/outbound-media.ts +0 -120
  61. package/src/outbound.runtime.ts +0 -12
  62. package/src/outbound.ts +0 -427
  63. package/src/probe.contract.test.ts +0 -9
  64. package/src/probe.runtime.ts +0 -1
  65. package/src/probe.ts +0 -34
  66. package/src/quick-reply-fallback.ts +0 -10
  67. package/src/reply-chunks.test.ts +0 -180
  68. package/src/reply-chunks.ts +0 -110
  69. package/src/reply-payload-transform.test.ts +0 -392
  70. package/src/reply-payload-transform.ts +0 -317
  71. package/src/rich-menu.test.ts +0 -315
  72. package/src/rich-menu.ts +0 -326
  73. package/src/runtime.ts +0 -32
  74. package/src/send-receipt.ts +0 -32
  75. package/src/send.test.ts +0 -453
  76. package/src/send.ts +0 -531
  77. package/src/setup-core.ts +0 -149
  78. package/src/setup-runtime-api.ts +0 -9
  79. package/src/setup-surface.test.ts +0 -481
  80. package/src/setup-surface.ts +0 -229
  81. package/src/signature.test.ts +0 -34
  82. package/src/signature.ts +0 -24
  83. package/src/status.ts +0 -37
  84. package/src/template-messages.ts +0 -333
  85. package/src/types.ts +0 -130
  86. package/src/webhook-node.test.ts +0 -598
  87. package/src/webhook-node.ts +0 -155
  88. package/src/webhook-utils.ts +0 -10
  89. package/src/webhook.ts +0 -135
  90. package/tsconfig.json +0 -16
@@ -1,347 +0,0 @@
1
- import type { KlawPluginApi } from "klaw/plugin-sdk/core";
2
- import type { ReplyPayload } from "klaw/plugin-sdk/reply-runtime";
3
- import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-runtime";
4
- import {
5
- createActionCard,
6
- createImageCard,
7
- createInfoCard,
8
- createListCard,
9
- createReceiptCard,
10
- type CardAction,
11
- type ListItem,
12
- } from "./flex-templates.js";
13
- import type { LineChannelData } from "./types.js";
14
-
15
- const CARD_USAGE = `Usage: /card <type> "title" "body" [options]
16
-
17
- Types:
18
- info "Title" "Body" ["Footer"]
19
- image "Title" "Caption" --url <image-url>
20
- action "Title" "Body" --actions "Btn1|url1,Btn2|text2"
21
- list "Title" "Item1|Desc1,Item2|Desc2"
22
- receipt "Title" "Item1:$10,Item2:$20" --total "$30"
23
- confirm "Question?" --yes "Yes|data" --no "No|data"
24
- buttons "Title" "Text" --actions "Btn1|url1,Btn2|data2"
25
-
26
- Examples:
27
- /card info "Welcome" "Thanks for joining!"
28
- /card image "Product" "Check it out" --url https://example.com/img.jpg
29
- /card action "Menu" "Choose an option" --actions "Order|/order,Help|/help"`;
30
-
31
- function buildLineReply(lineData: LineChannelData): ReplyPayload {
32
- return {
33
- channelData: {
34
- line: lineData,
35
- },
36
- };
37
- }
38
-
39
- /**
40
- * Parse action string format: "Label|data,Label2|data2"
41
- * Data can be a URL (uri action) or plain text (message action) or key=value (postback)
42
- */
43
- function parseActions(actionsStr: string | undefined): CardAction[] {
44
- if (!actionsStr) {
45
- return [];
46
- }
47
-
48
- const results: CardAction[] = [];
49
-
50
- for (const part of actionsStr.split(",")) {
51
- const [label, data] = part
52
- .trim()
53
- .split("|")
54
- .map((s) => s.trim());
55
- if (!label) {
56
- continue;
57
- }
58
-
59
- const actionData = data || label;
60
-
61
- if (actionData.startsWith("http://") || actionData.startsWith("https://")) {
62
- results.push({
63
- label,
64
- action: { type: "uri", label: label.slice(0, 20), uri: actionData },
65
- });
66
- } else if (actionData.includes("=")) {
67
- results.push({
68
- label,
69
- action: {
70
- type: "postback",
71
- label: label.slice(0, 20),
72
- data: actionData.slice(0, 300),
73
- displayText: label,
74
- },
75
- });
76
- } else {
77
- results.push({
78
- label,
79
- action: { type: "message", label: label.slice(0, 20), text: actionData },
80
- });
81
- }
82
- }
83
-
84
- return results;
85
- }
86
-
87
- /**
88
- * Parse list items format: "Item1|Subtitle1,Item2|Subtitle2"
89
- */
90
- function parseListItems(itemsStr: string): ListItem[] {
91
- return itemsStr
92
- .split(",")
93
- .map((part) => {
94
- const [title, subtitle] = part
95
- .trim()
96
- .split("|")
97
- .map((s) => s.trim());
98
- return { title: title || "", subtitle };
99
- })
100
- .filter((item) => item.title);
101
- }
102
-
103
- /**
104
- * Parse receipt items format: "Item1:$10,Item2:$20"
105
- */
106
- function parseReceiptItems(itemsStr: string): Array<{ name: string; value: string }> {
107
- return itemsStr
108
- .split(",")
109
- .map((part) => {
110
- const colonIndex = part.lastIndexOf(":");
111
- if (colonIndex === -1) {
112
- return { name: part.trim(), value: "" };
113
- }
114
- return {
115
- name: part.slice(0, colonIndex).trim(),
116
- value: part.slice(colonIndex + 1).trim(),
117
- };
118
- })
119
- .filter((item) => item.name);
120
- }
121
-
122
- /**
123
- * Parse quoted arguments from command string
124
- * Supports: /card type "arg1" "arg2" "arg3" --flag value
125
- */
126
- function parseCardArgs(argsStr: string): {
127
- type: string;
128
- args: string[];
129
- flags: Record<string, string>;
130
- } {
131
- const result: { type: string; args: string[]; flags: Record<string, string> } = {
132
- type: "",
133
- args: [],
134
- flags: {},
135
- };
136
-
137
- // Extract type (first word)
138
- const typeMatch = argsStr.match(/^(\w+)/);
139
- if (typeMatch) {
140
- result.type = normalizeLowercaseStringOrEmpty(typeMatch[1]);
141
- argsStr = argsStr.slice(typeMatch[0].length).trim();
142
- }
143
-
144
- // Extract quoted arguments
145
- const quotedRegex = /"([^"]*?)"/g;
146
- let match;
147
- while ((match = quotedRegex.exec(argsStr)) !== null) {
148
- result.args.push(match[1]);
149
- }
150
-
151
- // Extract flags (--key value or --key "value")
152
- const flagRegex = /--(\w+)\s+(?:"([^"]*?)"|(\S+))/g;
153
- while ((match = flagRegex.exec(argsStr)) !== null) {
154
- result.flags[match[1]] = match[2] ?? match[3];
155
- }
156
-
157
- return result;
158
- }
159
-
160
- export function registerLineCardCommand(api: KlawPluginApi): void {
161
- api.registerCommand({
162
- name: "card",
163
- description: "Send a rich card message (LINE).",
164
- acceptsArgs: true,
165
- requireAuth: false,
166
- handler: async (ctx) => {
167
- const argsStr = ctx.args?.trim() ?? "";
168
- if (!argsStr) {
169
- return { text: CARD_USAGE };
170
- }
171
-
172
- const parsed = parseCardArgs(argsStr);
173
- const { type, args, flags } = parsed;
174
-
175
- if (!type) {
176
- return { text: CARD_USAGE };
177
- }
178
-
179
- // Only LINE supports rich cards; fallback to text elsewhere.
180
- if (ctx.channel !== "line") {
181
- const fallbackText = args.join(" - ");
182
- return { text: `[${type} card] ${fallbackText}`.trim() };
183
- }
184
-
185
- try {
186
- switch (type) {
187
- case "info": {
188
- const [title = "Info", body = "", footer] = args;
189
- const bubble = createInfoCard(title, body, footer);
190
- return buildLineReply({
191
- flexMessage: {
192
- altText: `${title}: ${body}`.slice(0, 400),
193
- contents: bubble,
194
- },
195
- });
196
- }
197
-
198
- case "image": {
199
- const [title = "Image", caption = ""] = args;
200
- const imageUrl = flags.url || flags.image;
201
- if (!imageUrl) {
202
- return { text: "Error: Image card requires --url <image-url>" };
203
- }
204
- const bubble = createImageCard(imageUrl, title, caption);
205
- return buildLineReply({
206
- flexMessage: {
207
- altText: `${title}: ${caption}`.slice(0, 400),
208
- contents: bubble,
209
- },
210
- });
211
- }
212
-
213
- case "action": {
214
- const [title = "Actions", body = ""] = args;
215
- const actions = parseActions(flags.actions);
216
- if (actions.length === 0) {
217
- return { text: 'Error: Action card requires --actions "Label1|data1,Label2|data2"' };
218
- }
219
- const bubble = createActionCard(title, body, actions, {
220
- imageUrl: flags.url || flags.image,
221
- });
222
- return buildLineReply({
223
- flexMessage: {
224
- altText: `${title}: ${body}`.slice(0, 400),
225
- contents: bubble,
226
- },
227
- });
228
- }
229
-
230
- case "list": {
231
- const [title = "List", itemsStr = ""] = args;
232
- const items = parseListItems(itemsStr || flags.items || "");
233
- if (items.length === 0) {
234
- return {
235
- text: 'Error: List card requires items. Usage: /card list "Title" "Item1|Desc1,Item2|Desc2"',
236
- };
237
- }
238
- const bubble = createListCard(title, items);
239
- return buildLineReply({
240
- flexMessage: {
241
- altText: `${title}: ${items.map((i) => i.title).join(", ")}`.slice(0, 400),
242
- contents: bubble,
243
- },
244
- });
245
- }
246
-
247
- case "receipt": {
248
- const [title = "Receipt", itemsStr = ""] = args;
249
- const items = parseReceiptItems(itemsStr || flags.items || "");
250
- const total = flags.total ? { label: "Total", value: flags.total } : undefined;
251
- const footer = flags.footer;
252
-
253
- if (items.length === 0) {
254
- return {
255
- text: 'Error: Receipt card requires items. Usage: /card receipt "Title" "Item1:$10,Item2:$20" --total "$30"',
256
- };
257
- }
258
-
259
- const bubble = createReceiptCard({ title, items, total, footer });
260
- return buildLineReply({
261
- flexMessage: {
262
- altText: `${title}: ${items.map((i) => `${i.name} ${i.value}`).join(", ")}`.slice(
263
- 0,
264
- 400,
265
- ),
266
- contents: bubble,
267
- },
268
- });
269
- }
270
-
271
- case "confirm": {
272
- const [question = "Confirm?"] = args;
273
- const yesStr = flags.yes || "Yes|yes";
274
- const noStr = flags.no || "No|no";
275
-
276
- const [yesLabel, yesData] = yesStr.split("|").map((s) => s.trim());
277
- const [noLabel, noData] = noStr.split("|").map((s) => s.trim());
278
-
279
- return buildLineReply({
280
- templateMessage: {
281
- type: "confirm",
282
- text: question,
283
- confirmLabel: yesLabel || "Yes",
284
- confirmData: yesData || "yes",
285
- cancelLabel: noLabel || "No",
286
- cancelData: noData || "no",
287
- altText: question,
288
- },
289
- });
290
- }
291
-
292
- case "buttons": {
293
- const [title = "Menu", text = "Choose an option"] = args;
294
- const actionsStr = flags.actions || "";
295
- const actionParts = parseActions(actionsStr);
296
-
297
- if (actionParts.length === 0) {
298
- return { text: 'Error: Buttons card requires --actions "Label1|data1,Label2|data2"' };
299
- }
300
-
301
- const templateActions: Array<{
302
- type: "message" | "uri" | "postback";
303
- label: string;
304
- data?: string;
305
- uri?: string;
306
- }> = actionParts.map((a) => {
307
- const action = a.action;
308
- const label = action.label ?? a.label;
309
- if (action.type === "uri") {
310
- return { type: "uri" as const, label, uri: (action as { uri: string }).uri };
311
- }
312
- if (action.type === "postback") {
313
- return {
314
- type: "postback" as const,
315
- label,
316
- data: (action as { data: string }).data,
317
- };
318
- }
319
- return {
320
- type: "message" as const,
321
- label,
322
- data: (action as { text: string }).text,
323
- };
324
- });
325
-
326
- return buildLineReply({
327
- templateMessage: {
328
- type: "buttons",
329
- title,
330
- text,
331
- thumbnailImageUrl: flags.url || flags.image,
332
- actions: templateActions,
333
- },
334
- });
335
- }
336
-
337
- default:
338
- return {
339
- text: `Unknown card type: "${type}". Available types: info, image, action, list, receipt, confirm, buttons`,
340
- };
341
- }
342
- } catch (err) {
343
- return { text: `Error creating card: ${String(err)}` };
344
- }
345
- },
346
- });
347
- }
@@ -1,14 +0,0 @@
1
- export function resolveLineChannelAccessToken(
2
- explicit: string | undefined,
3
- params: { accountId: string; channelAccessToken: string },
4
- ): string {
5
- if (explicit?.trim()) {
6
- return explicit.trim();
7
- }
8
- if (!params.channelAccessToken) {
9
- throw new Error(
10
- `LINE channel access token missing for account "${params.accountId}" (set channels.line.channelAccessToken or LINE_CHANNEL_ACCESS_TOKEN).`,
11
- );
12
- }
13
- return params.channelAccessToken.trim();
14
- }
@@ -1,17 +0,0 @@
1
- export { clearAccountEntryFields } from "klaw/plugin-sdk/core";
2
- import { DEFAULT_ACCOUNT_ID } from "klaw/plugin-sdk/account-id";
3
- import type { KlawConfig } from "klaw/plugin-sdk/account-resolution";
4
- import type { ChannelPlugin } from "klaw/plugin-sdk/core";
5
- import { listLineAccountIds, resolveDefaultLineAccountId, resolveLineAccount } from "./accounts.js";
6
- import { resolveExactLineGroupConfigKey } from "./group-keys.js";
7
- import type { LineConfig, ResolvedLineAccount } from "./types.js";
8
-
9
- export {
10
- DEFAULT_ACCOUNT_ID,
11
- listLineAccountIds,
12
- resolveDefaultLineAccountId,
13
- resolveExactLineGroupConfigKey,
14
- resolveLineAccount,
15
- };
16
-
17
- export type { ChannelPlugin, LineConfig, KlawConfig, ResolvedLineAccount };
@@ -1,70 +0,0 @@
1
- import {
2
- installChannelSetupContractSuite,
3
- installChannelStatusContractSuite,
4
- } from "klaw/plugin-sdk/channel-test-helpers";
5
- import type { KlawConfig } from "klaw/plugin-sdk/config-contracts";
6
- import { describe, expect } from "vitest";
7
- import { linePlugin, lineSetupPlugin } from "../api.js";
8
-
9
- describe("line setup contract", () => {
10
- installChannelSetupContractSuite({
11
- plugin: lineSetupPlugin,
12
- cases: [
13
- {
14
- name: "default account stores token and secret",
15
- cfg: {} as KlawConfig,
16
- input: {
17
- channelAccessToken: "line-token",
18
- channelSecret: "line-secret",
19
- } as never,
20
- expectedAccountId: "default",
21
- assertPatchedConfig: (cfg) => {
22
- expect(cfg.channels?.line?.enabled).toBe(true);
23
- expect(cfg.channels?.line?.channelAccessToken).toBe("line-token");
24
- expect(cfg.channels?.line?.channelSecret).toBe("line-secret");
25
- },
26
- },
27
- {
28
- name: "non-default env setup is rejected",
29
- cfg: {} as KlawConfig,
30
- accountId: "ops",
31
- input: {
32
- useEnv: true,
33
- },
34
- expectedAccountId: "ops",
35
- expectedValidation: "LINE_CHANNEL_ACCESS_TOKEN can only be used for the default account.",
36
- },
37
- ],
38
- });
39
- });
40
-
41
- describe("line status contract", () => {
42
- installChannelStatusContractSuite({
43
- plugin: linePlugin,
44
- cases: [
45
- {
46
- name: "configured account produces a webhook status snapshot",
47
- cfg: {
48
- channels: {
49
- line: {
50
- enabled: true,
51
- channelAccessToken: "line-token",
52
- channelSecret: "line-secret",
53
- },
54
- },
55
- } as KlawConfig,
56
- runtime: {
57
- accountId: "default",
58
- running: true,
59
- },
60
- probe: { ok: true },
61
- assertSnapshot: (snapshot) => {
62
- expect(snapshot.accountId).toBe("default");
63
- expect(snapshot.enabled).toBe(true);
64
- expect(snapshot.configured).toBe(true);
65
- expect(snapshot.mode).toBe("webhook");
66
- },
67
- },
68
- ],
69
- });
70
- });
@@ -1,48 +0,0 @@
1
- import { describeWebhookAccountSnapshot } from "klaw/plugin-sdk/account-helpers";
2
- import { hasLineCredentials } from "./account-helpers.js";
3
- import { type ChannelPlugin, type ResolvedLineAccount } from "./channel-api.js";
4
- import { lineConfigAdapter } from "./config-adapter.js";
5
- import { LineChannelConfigSchema } from "./config-schema.js";
6
-
7
- const lineChannelMeta = {
8
- id: "line",
9
- label: "LINE",
10
- selectionLabel: "LINE (Messaging API)",
11
- detailLabel: "LINE Bot",
12
- docsPath: "/channels/line",
13
- docsLabel: "line",
14
- blurb: "LINE Messaging API bot for Japan/Taiwan/Thailand markets.",
15
- systemImage: "message.fill",
16
- } as const;
17
-
18
- export const lineChannelPluginCommon = {
19
- meta: {
20
- ...lineChannelMeta,
21
- quickstartAllowFrom: true,
22
- },
23
- capabilities: {
24
- chatTypes: ["direct", "group"],
25
- reactions: false,
26
- threads: false,
27
- media: true,
28
- nativeCommands: false,
29
- blockStreaming: true,
30
- },
31
- reload: { configPrefixes: ["channels.line"] },
32
- configSchema: LineChannelConfigSchema,
33
- config: {
34
- ...lineConfigAdapter,
35
- isConfigured: (account: ResolvedLineAccount) => hasLineCredentials(account),
36
- describeAccount: (account: ResolvedLineAccount) =>
37
- describeWebhookAccountSnapshot({
38
- account,
39
- configured: hasLineCredentials(account),
40
- extra: {
41
- tokenSource: account.tokenSource ?? undefined,
42
- },
43
- }),
44
- },
45
- } satisfies Pick<
46
- ChannelPlugin<ResolvedLineAccount>,
47
- "meta" | "capabilities" | "reload" | "configSchema" | "config"
48
- >;
@@ -1,145 +0,0 @@
1
- import { createRuntimeEnv } from "klaw/plugin-sdk/plugin-test-runtime";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
- import type { KlawConfig, PluginRuntime, ResolvedLineAccount } from "../api.js";
4
- import { lineGatewayAdapter } from "./gateway.js";
5
- import { setLineRuntime } from "./runtime.js";
6
-
7
- const DEFAULT_ACCOUNT_ID = "default";
8
-
9
- type LineRuntimeMocks = {
10
- replaceConfigFile: ReturnType<typeof vi.fn>;
11
- resolveLineAccount: ReturnType<typeof vi.fn>;
12
- };
13
-
14
- function createRuntime(): { runtime: PluginRuntime; mocks: LineRuntimeMocks } {
15
- const replaceConfigFile = vi.fn(async () => {});
16
- const resolveLineAccount = vi.fn(
17
- ({ cfg, accountId }: { cfg: KlawConfig; accountId?: string }) => {
18
- const lineConfig = (cfg.channels?.line ?? {}) as {
19
- tokenFile?: string;
20
- secretFile?: string;
21
- channelAccessToken?: string;
22
- channelSecret?: string;
23
- accounts?: Record<string, Record<string, unknown>>;
24
- };
25
- const entry =
26
- accountId && accountId !== DEFAULT_ACCOUNT_ID
27
- ? (lineConfig.accounts?.[accountId] ?? {})
28
- : lineConfig;
29
- const hasToken =
30
- Boolean((entry as any).channelAccessToken) || Boolean((entry as any).tokenFile);
31
- const hasSecret = Boolean((entry as any).channelSecret) || Boolean((entry as any).secretFile);
32
- return { tokenSource: hasToken && hasSecret ? "config" : "none" };
33
- },
34
- );
35
-
36
- const runtime = {
37
- config: { replaceConfigFile },
38
- } as unknown as PluginRuntime;
39
-
40
- return { runtime, mocks: { replaceConfigFile, resolveLineAccount } };
41
- }
42
-
43
- function resolveAccount(
44
- resolveLineAccount: LineRuntimeMocks["resolveLineAccount"],
45
- cfg: KlawConfig,
46
- accountId: string,
47
- ): ResolvedLineAccount {
48
- const resolver = resolveLineAccount as unknown as (params: {
49
- cfg: KlawConfig;
50
- accountId?: string;
51
- }) => ResolvedLineAccount;
52
- return resolver({ cfg, accountId });
53
- }
54
-
55
- async function runLogoutScenario(params: { cfg: KlawConfig; accountId: string }): Promise<{
56
- result: Awaited<ReturnType<NonNullable<typeof lineGatewayAdapter.logoutAccount>>>;
57
- mocks: LineRuntimeMocks;
58
- }> {
59
- const { runtime, mocks } = createRuntime();
60
- setLineRuntime(runtime);
61
- const account = resolveAccount(mocks.resolveLineAccount, params.cfg, params.accountId);
62
- const result = await lineGatewayAdapter.logoutAccount!({
63
- accountId: params.accountId,
64
- cfg: params.cfg,
65
- account,
66
- runtime: createRuntimeEnv(),
67
- });
68
- return { result, mocks };
69
- }
70
-
71
- describe("linePlugin gateway.logoutAccount", () => {
72
- beforeEach(() => {
73
- setLineRuntime(createRuntime().runtime);
74
- });
75
-
76
- it("clears tokenFile/secretFile on default account logout", async () => {
77
- const cfg: KlawConfig = {
78
- channels: {
79
- line: {
80
- tokenFile: "/tmp/token",
81
- secretFile: "/tmp/secret",
82
- },
83
- },
84
- };
85
- const { result, mocks } = await runLogoutScenario({
86
- cfg,
87
- accountId: DEFAULT_ACCOUNT_ID,
88
- });
89
-
90
- expect(result.cleared).toBe(true);
91
- expect(result.loggedOut).toBe(true);
92
- expect(mocks.replaceConfigFile).toHaveBeenCalledWith({
93
- nextConfig: {},
94
- afterWrite: { mode: "auto" },
95
- });
96
- });
97
-
98
- it("clears tokenFile/secretFile on account logout", async () => {
99
- const cfg: KlawConfig = {
100
- channels: {
101
- line: {
102
- accounts: {
103
- primary: {
104
- tokenFile: "/tmp/token",
105
- secretFile: "/tmp/secret",
106
- },
107
- },
108
- },
109
- },
110
- };
111
- const { result, mocks } = await runLogoutScenario({
112
- cfg,
113
- accountId: "primary",
114
- });
115
-
116
- expect(result.cleared).toBe(true);
117
- expect(result.loggedOut).toBe(true);
118
- expect(mocks.replaceConfigFile).toHaveBeenCalledWith({
119
- nextConfig: {},
120
- afterWrite: { mode: "auto" },
121
- });
122
- });
123
-
124
- it("does not write config when account has no token/secret fields", async () => {
125
- const cfg: KlawConfig = {
126
- channels: {
127
- line: {
128
- accounts: {
129
- primary: {
130
- name: "Primary",
131
- },
132
- },
133
- },
134
- },
135
- };
136
- const { result, mocks } = await runLogoutScenario({
137
- cfg,
138
- accountId: "primary",
139
- });
140
-
141
- expect(result.cleared).toBe(false);
142
- expect(result.loggedOut).toBe(true);
143
- expect(mocks.replaceConfigFile).not.toHaveBeenCalled();
144
- });
145
- });
@@ -1,3 +0,0 @@
1
- export { monitorLineProvider } from "./monitor.js";
2
- export { probeLineBot } from "./probe.js";
3
- export { pushMessageLine } from "./send.js";