@kodelyth/line 2026.5.42 → 2026.6.1

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 +16 -4
  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,288 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import type { KlawConfig } from "klaw/plugin-sdk/config-contracts";
5
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
- import {
7
- resolveLineAccount,
8
- resolveDefaultLineAccountId,
9
- normalizeAccountId,
10
- DEFAULT_ACCOUNT_ID,
11
- } from "./accounts.js";
12
-
13
- describe("LINE accounts", () => {
14
- const tempDirs: string[] = [];
15
-
16
- const createSecretFile = (fileName: string, contents: string) => {
17
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "klaw-line-account-"));
18
- tempDirs.push(dir);
19
- const filePath = path.join(dir, fileName);
20
- fs.writeFileSync(filePath, contents, "utf8");
21
- return filePath;
22
- };
23
-
24
- beforeEach(() => {
25
- vi.stubEnv("LINE_CHANNEL_ACCESS_TOKEN", "");
26
- vi.stubEnv("LINE_CHANNEL_SECRET", "");
27
- });
28
-
29
- afterEach(() => {
30
- vi.unstubAllEnvs();
31
- for (const dir of tempDirs.splice(0)) {
32
- fs.rmSync(dir, { recursive: true, force: true });
33
- }
34
- });
35
-
36
- describe("resolveLineAccount", () => {
37
- it("resolves account from config", () => {
38
- const cfg: KlawConfig = {
39
- channels: {
40
- line: {
41
- enabled: true,
42
- channelAccessToken: "test-token",
43
- channelSecret: "test-secret",
44
- name: "Test Bot",
45
- },
46
- },
47
- };
48
-
49
- const account = resolveLineAccount({ cfg });
50
-
51
- expect(account.accountId).toBe(DEFAULT_ACCOUNT_ID);
52
- expect(account.enabled).toBe(true);
53
- expect(account.channelAccessToken).toBe("test-token");
54
- expect(account.channelSecret).toBe("test-secret");
55
- expect(account.name).toBe("Test Bot");
56
- expect(account.tokenSource).toBe("config");
57
- });
58
-
59
- it("resolves account from environment variables", () => {
60
- vi.stubEnv("LINE_CHANNEL_ACCESS_TOKEN", "env-token");
61
- vi.stubEnv("LINE_CHANNEL_SECRET", "env-secret");
62
-
63
- const cfg: KlawConfig = {
64
- channels: {
65
- line: {
66
- enabled: true,
67
- },
68
- },
69
- };
70
-
71
- const account = resolveLineAccount({ cfg });
72
-
73
- expect(account.channelAccessToken).toBe("env-token");
74
- expect(account.channelSecret).toBe("env-secret");
75
- expect(account.tokenSource).toBe("env");
76
- });
77
-
78
- it("resolves named account", () => {
79
- const cfg: KlawConfig = {
80
- channels: {
81
- line: {
82
- enabled: true,
83
- accounts: {
84
- business: {
85
- enabled: true,
86
- channelAccessToken: "business-token",
87
- channelSecret: "business-secret",
88
- name: "Business Bot",
89
- },
90
- },
91
- },
92
- },
93
- };
94
-
95
- const account = resolveLineAccount({ cfg, accountId: "business" });
96
-
97
- expect(account.accountId).toBe("business");
98
- expect(account.enabled).toBe(true);
99
- expect(account.channelAccessToken).toBe("business-token");
100
- expect(account.channelSecret).toBe("business-secret");
101
- expect(account.name).toBe("Business Bot");
102
- });
103
-
104
- it("uses configured defaultAccount when accountId is omitted", () => {
105
- const cfg: KlawConfig = {
106
- channels: {
107
- line: {
108
- defaultAccount: "business",
109
- accounts: {
110
- business: {
111
- enabled: true,
112
- channelAccessToken: "business-token",
113
- channelSecret: "business-secret",
114
- name: "Business Bot",
115
- },
116
- },
117
- },
118
- },
119
- };
120
-
121
- const account = resolveLineAccount({ cfg });
122
-
123
- expect(account.accountId).toBe("business");
124
- expect(account.enabled).toBe(true);
125
- expect(account.channelAccessToken).toBe("business-token");
126
- expect(account.channelSecret).toBe("business-secret");
127
- expect(account.name).toBe("Business Bot");
128
- });
129
-
130
- it("returns empty token when not configured", () => {
131
- const cfg: KlawConfig = {};
132
-
133
- const account = resolveLineAccount({ cfg });
134
-
135
- expect(account.channelAccessToken).toBe("");
136
- expect(account.channelSecret).toBe("");
137
- expect(account.tokenSource).toBe("none");
138
- });
139
-
140
- it("resolves default account credentials from files", () => {
141
- const cfg: KlawConfig = {
142
- channels: {
143
- line: {
144
- tokenFile: createSecretFile("token.txt", "file-token\n"),
145
- secretFile: createSecretFile("secret.txt", "file-secret\n"),
146
- },
147
- },
148
- };
149
-
150
- const account = resolveLineAccount({ cfg });
151
-
152
- expect(account.channelAccessToken).toBe("file-token");
153
- expect(account.channelSecret).toBe("file-secret");
154
- expect(account.tokenSource).toBe("file");
155
- });
156
-
157
- it("resolves named account credentials from account-level files", () => {
158
- const cfg: KlawConfig = {
159
- channels: {
160
- line: {
161
- accounts: {
162
- business: {
163
- tokenFile: createSecretFile("business-token.txt", "business-file-token\n"),
164
- secretFile: createSecretFile("business-secret.txt", "business-file-secret\n"),
165
- },
166
- },
167
- },
168
- },
169
- };
170
-
171
- const account = resolveLineAccount({ cfg, accountId: "business" });
172
-
173
- expect(account.channelAccessToken).toBe("business-file-token");
174
- expect(account.channelSecret).toBe("business-file-secret");
175
- expect(account.tokenSource).toBe("file");
176
- });
177
-
178
- it.runIf(process.platform !== "win32")("rejects symlinked token and secret files", () => {
179
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "klaw-line-account-"));
180
- tempDirs.push(dir);
181
- const tokenFile = path.join(dir, "token.txt");
182
- const tokenLink = path.join(dir, "token-link.txt");
183
- const secretFile = path.join(dir, "secret.txt");
184
- const secretLink = path.join(dir, "secret-link.txt");
185
- fs.writeFileSync(tokenFile, "file-token\n", "utf8");
186
- fs.writeFileSync(secretFile, "file-secret\n", "utf8");
187
- fs.symlinkSync(tokenFile, tokenLink);
188
- fs.symlinkSync(secretFile, secretLink);
189
-
190
- const cfg: KlawConfig = {
191
- channels: {
192
- line: {
193
- tokenFile: tokenLink,
194
- secretFile: secretLink,
195
- },
196
- },
197
- };
198
-
199
- const account = resolveLineAccount({ cfg });
200
- expect(account.channelAccessToken).toBe("");
201
- expect(account.channelSecret).toBe("");
202
- expect(account.tokenSource).toBe("none");
203
- });
204
- });
205
-
206
- describe("resolveDefaultLineAccountId", () => {
207
- it.each([
208
- {
209
- name: "prefers channels.line.defaultAccount when configured",
210
- cfg: {
211
- channels: {
212
- line: {
213
- defaultAccount: "business",
214
- accounts: {
215
- business: { enabled: true },
216
- support: { enabled: true },
217
- },
218
- },
219
- },
220
- } satisfies KlawConfig,
221
- expected: "business",
222
- },
223
- {
224
- name: "normalizes channels.line.defaultAccount before lookup",
225
- cfg: {
226
- channels: {
227
- line: {
228
- defaultAccount: "Business Ops",
229
- accounts: {
230
- "business-ops": { enabled: true },
231
- },
232
- },
233
- },
234
- } satisfies KlawConfig,
235
- expected: "business-ops",
236
- },
237
- {
238
- name: "returns first named account when default not configured",
239
- cfg: {
240
- channels: {
241
- line: {
242
- accounts: {
243
- business: { enabled: true },
244
- },
245
- },
246
- },
247
- } satisfies KlawConfig,
248
- expected: "business",
249
- },
250
- {
251
- name: "falls back when channels.line.defaultAccount is missing",
252
- cfg: {
253
- channels: {
254
- line: {
255
- defaultAccount: "missing",
256
- accounts: {
257
- business: { enabled: true },
258
- },
259
- },
260
- },
261
- } satisfies KlawConfig,
262
- expected: "business",
263
- },
264
- {
265
- name: "prefers the default account when base credentials are configured",
266
- cfg: {
267
- channels: {
268
- line: {
269
- channelAccessToken: "base-token",
270
- accounts: {
271
- business: { enabled: true },
272
- },
273
- },
274
- },
275
- } satisfies KlawConfig,
276
- expected: DEFAULT_ACCOUNT_ID,
277
- },
278
- ])("$name", ({ cfg, expected }) => {
279
- expect(resolveDefaultLineAccountId(cfg)).toBe(expected);
280
- });
281
- });
282
-
283
- describe("normalizeAccountId", () => {
284
- it("trims and lowercases account ids", () => {
285
- expect(normalizeAccountId(" Business ")).toBe("business");
286
- });
287
- });
288
- });
package/src/accounts.ts DELETED
@@ -1,187 +0,0 @@
1
- import {
2
- DEFAULT_ACCOUNT_ID,
3
- normalizeAccountId as normalizeSharedAccountId,
4
- normalizeOptionalAccountId,
5
- } from "klaw/plugin-sdk/account-id";
6
- import type { KlawConfig } from "klaw/plugin-sdk/account-resolution";
7
- import { resolveAccountEntry } from "klaw/plugin-sdk/account-resolution";
8
- import { tryReadSecretFileSync } from "klaw/plugin-sdk/core";
9
- import type {
10
- LineAccountConfig,
11
- LineConfig,
12
- LineTokenSource,
13
- ResolvedLineAccount,
14
- } from "./types.js";
15
-
16
- export { DEFAULT_ACCOUNT_ID } from "klaw/plugin-sdk/account-id";
17
-
18
- function readFileIfExists(filePath: string | undefined): string | undefined {
19
- return tryReadSecretFileSync(filePath, "LINE credential file", { rejectSymlink: true });
20
- }
21
-
22
- function resolveToken(params: {
23
- accountId: string;
24
- baseConfig?: LineConfig;
25
- accountConfig?: LineAccountConfig;
26
- }): { token: string; tokenSource: LineTokenSource } {
27
- const { accountId, baseConfig, accountConfig } = params;
28
-
29
- if (accountConfig?.channelAccessToken?.trim()) {
30
- return { token: accountConfig.channelAccessToken.trim(), tokenSource: "config" };
31
- }
32
-
33
- const accountFileToken = readFileIfExists(accountConfig?.tokenFile);
34
- if (accountFileToken) {
35
- return { token: accountFileToken, tokenSource: "file" };
36
- }
37
-
38
- if (accountId === DEFAULT_ACCOUNT_ID) {
39
- if (baseConfig?.channelAccessToken?.trim()) {
40
- return { token: baseConfig.channelAccessToken.trim(), tokenSource: "config" };
41
- }
42
-
43
- const baseFileToken = readFileIfExists(baseConfig?.tokenFile);
44
- if (baseFileToken) {
45
- return { token: baseFileToken, tokenSource: "file" };
46
- }
47
-
48
- const envToken = process.env.LINE_CHANNEL_ACCESS_TOKEN?.trim();
49
- if (envToken) {
50
- return { token: envToken, tokenSource: "env" };
51
- }
52
- }
53
-
54
- return { token: "", tokenSource: "none" };
55
- }
56
-
57
- function resolveSecret(params: {
58
- accountId: string;
59
- baseConfig?: LineConfig;
60
- accountConfig?: LineAccountConfig;
61
- }): string {
62
- const { accountId, baseConfig, accountConfig } = params;
63
-
64
- if (accountConfig?.channelSecret?.trim()) {
65
- return accountConfig.channelSecret.trim();
66
- }
67
-
68
- const accountFileSecret = readFileIfExists(accountConfig?.secretFile);
69
- if (accountFileSecret) {
70
- return accountFileSecret;
71
- }
72
-
73
- if (accountId === DEFAULT_ACCOUNT_ID) {
74
- if (baseConfig?.channelSecret?.trim()) {
75
- return baseConfig.channelSecret.trim();
76
- }
77
-
78
- const baseFileSecret = readFileIfExists(baseConfig?.secretFile);
79
- if (baseFileSecret) {
80
- return baseFileSecret;
81
- }
82
-
83
- const envSecret = process.env.LINE_CHANNEL_SECRET?.trim();
84
- if (envSecret) {
85
- return envSecret;
86
- }
87
- }
88
-
89
- return "";
90
- }
91
-
92
- export function resolveLineAccount(params: {
93
- cfg: KlawConfig;
94
- accountId?: string;
95
- }): ResolvedLineAccount {
96
- const cfg = params.cfg;
97
- const accountId = normalizeSharedAccountId(params.accountId ?? resolveDefaultLineAccountId(cfg));
98
- const lineConfig = cfg.channels?.line as LineConfig | undefined;
99
- const accounts = lineConfig?.accounts;
100
- const accountConfig =
101
- accountId !== DEFAULT_ACCOUNT_ID ? resolveAccountEntry(accounts, accountId) : undefined;
102
-
103
- const { token, tokenSource } = resolveToken({
104
- accountId,
105
- baseConfig: lineConfig,
106
- accountConfig,
107
- });
108
-
109
- const secret = resolveSecret({
110
- accountId,
111
- baseConfig: lineConfig,
112
- accountConfig,
113
- });
114
-
115
- const {
116
- accounts: _ignoredAccounts,
117
- defaultAccount: _ignoredDefaultAccount,
118
- ...lineBase
119
- } = (lineConfig ?? {}) as LineConfig & {
120
- accounts?: unknown;
121
- defaultAccount?: unknown;
122
- };
123
- const mergedConfig: LineConfig & LineAccountConfig = {
124
- ...lineBase,
125
- ...accountConfig,
126
- };
127
-
128
- const enabled =
129
- accountConfig?.enabled ??
130
- (accountId === DEFAULT_ACCOUNT_ID ? (lineConfig?.enabled ?? true) : false);
131
-
132
- const name =
133
- accountConfig?.name ?? (accountId === DEFAULT_ACCOUNT_ID ? lineConfig?.name : undefined);
134
-
135
- return {
136
- accountId,
137
- name,
138
- enabled,
139
- channelAccessToken: token,
140
- channelSecret: secret,
141
- tokenSource,
142
- config: mergedConfig,
143
- };
144
- }
145
-
146
- export function listLineAccountIds(cfg: KlawConfig): string[] {
147
- const lineConfig = cfg.channels?.line as LineConfig | undefined;
148
- const accounts = lineConfig?.accounts;
149
- const ids = new Set<string>();
150
-
151
- if (
152
- lineConfig?.channelAccessToken?.trim() ||
153
- lineConfig?.tokenFile ||
154
- process.env.LINE_CHANNEL_ACCESS_TOKEN?.trim()
155
- ) {
156
- ids.add(DEFAULT_ACCOUNT_ID);
157
- }
158
-
159
- if (accounts) {
160
- for (const id of Object.keys(accounts)) {
161
- ids.add(id);
162
- }
163
- }
164
-
165
- return Array.from(ids);
166
- }
167
-
168
- export function resolveDefaultLineAccountId(cfg: KlawConfig): string {
169
- const preferred = normalizeOptionalAccountId(
170
- (cfg.channels?.line as LineConfig | undefined)?.defaultAccount,
171
- );
172
- if (
173
- preferred &&
174
- listLineAccountIds(cfg).some((accountId) => normalizeSharedAccountId(accountId) === preferred)
175
- ) {
176
- return preferred;
177
- }
178
- const ids = listLineAccountIds(cfg);
179
- if (ids.includes(DEFAULT_ACCOUNT_ID)) {
180
- return DEFAULT_ACCOUNT_ID;
181
- }
182
- return ids[0] ?? DEFAULT_ACCOUNT_ID;
183
- }
184
-
185
- export function normalizeAccountId(accountId: string | undefined): string {
186
- return normalizeSharedAccountId(accountId);
187
- }
package/src/actions.ts DELETED
@@ -1,61 +0,0 @@
1
- import type { messagingApi } from "@line/bot-sdk";
2
-
3
- export type Action = messagingApi.Action;
4
-
5
- /**
6
- * Create a message action (sends text when tapped)
7
- */
8
- export function messageAction(label: string, text?: string): Action {
9
- return {
10
- type: "message",
11
- label: label.slice(0, 20),
12
- text: text ?? label,
13
- };
14
- }
15
-
16
- /**
17
- * Create a URI action (opens a URL when tapped)
18
- */
19
- export function uriAction(label: string, uri: string): Action {
20
- return {
21
- type: "uri",
22
- label: label.slice(0, 20),
23
- uri,
24
- };
25
- }
26
-
27
- /**
28
- * Create a postback action (sends data to webhook when tapped)
29
- */
30
- export function postbackAction(label: string, data: string, displayText?: string): Action {
31
- return {
32
- type: "postback",
33
- label: label.slice(0, 20),
34
- data: data.slice(0, 300),
35
- displayText: displayText?.slice(0, 300),
36
- };
37
- }
38
-
39
- /**
40
- * Create a datetime picker action
41
- */
42
- export function datetimePickerAction(
43
- label: string,
44
- data: string,
45
- mode: "date" | "time" | "datetime",
46
- options?: {
47
- initial?: string;
48
- max?: string;
49
- min?: string;
50
- },
51
- ): Action {
52
- return {
53
- type: "datetimepicker",
54
- label: label.slice(0, 20),
55
- data: data.slice(0, 300),
56
- mode,
57
- initial: options?.initial,
58
- max: options?.max,
59
- min: options?.min,
60
- };
61
- }