Skip to content

Commit 2b07715

Browse files
committed
refactor(line): remove dead card helpers
1 parent 75e815e commit 2b07715

6 files changed

Lines changed: 13 additions & 379 deletions

File tree

‎extensions/line/runtime-api.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,10 @@ export {
9191
type CarouselColumn,
9292
type CarouselTemplate,
9393
type ConfirmTemplate,
94-
createButtonMenu,
9594
createButtonTemplate,
9695
createCarouselColumn,
9796
createConfirmTemplate,
98-
createImageCarousel,
99-
createImageCarouselColumn,
100-
createLinkMenu,
101-
createProductCarousel,
10297
createTemplateCarousel,
103-
createYesNoConfirm,
104-
type ImageCarouselColumn,
105-
type ImageCarouselTemplate,
10698
type TemplateMessage,
10799
} from "./src/template-messages.js";
108100
export type {
@@ -125,14 +117,12 @@ export {
125117
createActionCard,
126118
createAgendaCard,
127119
createAppleTvRemoteCard,
128-
createCarousel,
129120
createDeviceControlCard,
130121
createEventCard,
131122
createImageCard,
132123
createInfoCard,
133124
createListCard,
134125
createMediaPlayerCard,
135-
createNotificationBubble,
136126
createReceiptCard,
137127
toFlexMessage,
138128
} from "./src/flex-templates.js";
@@ -141,7 +131,6 @@ export type {
141131
FlexBox,
142132
FlexBubble,
143133
FlexButton,
144-
FlexCarousel,
145134
FlexComponent,
146135
FlexContainer,
147136
FlexImage,

‎extensions/line/src/flex-templates.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Line plugin module implements flex templates behavior.
22
export {
33
createActionCard,
4-
createCarousel,
54
createImageCard,
65
createInfoCard,
76
createListCard,
8-
createNotificationBubble,
97
} from "./flex-templates/basic-cards.js";
108
export {
119
createAgendaCard,
@@ -24,7 +22,6 @@ export type {
2422
FlexBox,
2523
FlexBubble,
2624
FlexButton,
27-
FlexCarousel,
2825
FlexComponent,
2926
FlexContainer,
3027
FlexImage,

‎extensions/line/src/flex-templates/basic-cards.ts‎

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
FlexBox,
88
FlexBubble,
99
FlexButton,
10-
FlexCarousel,
1110
FlexComponent,
1211
FlexImage,
1312
FlexText,
@@ -306,92 +305,3 @@ export function createActionCard(
306305

307306
return bubble;
308307
}
309-
310-
/**
311-
* Create a carousel container from multiple bubbles
312-
* LINE allows max 12 bubbles in a carousel
313-
*/
314-
export function createCarousel(bubbles: FlexBubble[]): FlexCarousel {
315-
return {
316-
type: "carousel",
317-
contents: bubbles.slice(0, 12),
318-
};
319-
}
320-
321-
/**
322-
* Create a notification bubble (for alerts, status updates)
323-
*
324-
* Editorial design: Bold status indicator with accent color,
325-
* clear typography, optional icon for context.
326-
*/
327-
export function createNotificationBubble(
328-
text: string,
329-
options?: {
330-
icon?: string;
331-
type?: "info" | "success" | "warning" | "error";
332-
title?: string;
333-
},
334-
): FlexBubble {
335-
// Color based on notification type
336-
const colors = {
337-
info: { accent: "#3B82F6", bg: "#EFF6FF" },
338-
success: { accent: "#06C755", bg: "#F0FDF4" },
339-
warning: { accent: "#F59E0B", bg: "#FFFBEB" },
340-
error: { accent: "#EF4444", bg: "#FEF2F2" },
341-
};
342-
const typeColors = colors[options?.type ?? "info"];
343-
344-
const contents: FlexComponent[] = [];
345-
346-
// Accent bar
347-
contents.push({
348-
type: "box",
349-
layout: "vertical",
350-
contents: [],
351-
width: "4px",
352-
backgroundColor: typeColors.accent,
353-
cornerRadius: "2px",
354-
} as FlexBox);
355-
356-
// Content section
357-
const textContents: FlexComponent[] = [];
358-
359-
if (options?.title) {
360-
textContents.push({
361-
type: "text",
362-
text: options.title,
363-
size: "md",
364-
weight: "bold",
365-
color: "#111111",
366-
wrap: true,
367-
} as FlexText);
368-
}
369-
370-
textContents.push({
371-
type: "text",
372-
text,
373-
size: options?.title ? "sm" : "md",
374-
color: options?.title ? "#666666" : "#333333",
375-
wrap: true,
376-
margin: options?.title ? "sm" : undefined,
377-
} as FlexText);
378-
379-
contents.push({
380-
type: "box",
381-
layout: "vertical",
382-
contents: textContents,
383-
flex: 1,
384-
paddingStart: "lg",
385-
} as FlexBox);
386-
387-
return {
388-
type: "bubble",
389-
body: {
390-
type: "box",
391-
layout: "horizontal",
392-
contents,
393-
paddingAll: "xl",
394-
backgroundColor: typeColors.bg,
395-
},
396-
};
397-
}

‎extensions/line/src/flex-templates/types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { messagingApi } from "@line/bot-sdk";
33

44
export type FlexContainer = messagingApi.FlexContainer;
55
export type FlexBubble = messagingApi.FlexBubble;
6-
export type FlexCarousel = messagingApi.FlexCarousel;
76
export type FlexBox = messagingApi.FlexBox;
87
export type FlexText = messagingApi.FlexText;
98
export type FlexImage = messagingApi.FlexImage;

‎extensions/line/src/message-cards.test.ts‎

Lines changed: 12 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { registerLineCardCommand } from "./card-command.js";
1616
import {
1717
createActionCard,
1818
createAppleTvRemoteCard,
19-
createCarousel,
2019
createDeviceControlCard,
2120
createEventCard,
2221
createImageCard,
@@ -30,9 +29,6 @@ import {
3029
createButtonTemplate,
3130
createTemplateCarousel,
3231
createCarouselColumn,
33-
createImageCarousel,
34-
createImageCarouselColumn,
35-
createProductCarousel,
3632
} from "./template-messages.js";
3733

3834
const loneHighSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;
@@ -86,14 +82,6 @@ const lineTemplateMessageScenarios = [
8682
),
8783
bodyLimit: 120,
8884
},
89-
{
90-
kind: "image carousel",
91-
create: (altText: string) =>
92-
createImageCarousel(
93-
[createImageCarouselColumn("https://example.test/image.png", messageAction("Open"))],
94-
altText,
95-
),
96-
},
9785
] as const;
9886

9987
async function runLineFlexCardCommand(
@@ -340,97 +328,13 @@ describe("createCarouselColumn", () => {
340328
});
341329

342330
describe("carousel column limits", () => {
343-
it.each([
344-
{
345-
createTemplate: () =>
346-
createTemplateCarousel(
347-
Array.from({ length: 15 }, () =>
348-
createCarouselColumn({ text: "Text", actions: [messageAction("OK")] }),
349-
),
350-
),
351-
},
352-
{
353-
createTemplate: () =>
354-
createImageCarousel(
355-
Array.from({ length: 15 }, (_, i) =>
356-
createImageCarouselColumn(`https://example.com/${i}.jpg`, messageAction("View")),
357-
),
358-
),
359-
},
360-
])("limits columns to 10", ({ createTemplate }) => {
361-
const template = createTemplate();
362-
expect((template.template as { columns: unknown[] }).columns.length).toBe(10);
363-
});
364-
365-
it("drops a surrogate-pair emoji from image-carousel altText instead of splitting it", () => {
366-
const template = createImageCarousel(
367-
[createImageCarouselColumn("https://example.com/0.jpg", messageAction("View"))],
368-
`${"x".repeat(1499)}😀`,
369-
);
370-
371-
expect(template.altText).toBe("x".repeat(1499));
372-
expect(loneHighSurrogate.test(template.altText)).toBe(false);
373-
});
374-
375-
it("keeps unavailable action labels within the image-carousel cap", () => {
376-
const template = createImageCarousel([
377-
createImageCarouselColumn(
378-
"https://example.com/0.jpg",
379-
uriAction("Open", `https://example.com/?q=${"x".repeat(1200)}`),
331+
it("limits columns to 10", () => {
332+
const template = createTemplateCarousel(
333+
Array.from({ length: 15 }, () =>
334+
createCarouselColumn({ text: "Text", actions: [messageAction("OK")] }),
380335
),
381-
]);
382-
const column = (
383-
template.template as {
384-
columns: Array<{ action: { label?: string; text?: string; type: string } }>;
385-
}
386-
).columns[0];
387-
388-
expect(column?.action).toEqual({
389-
type: "message",
390-
label: "Unavailable",
391-
text: "Link unavailable: URL exceeds LINE's limit.",
392-
});
393-
expect(column?.action.label).toHaveLength(11);
394-
});
395-
});
396-
397-
describe("createProductCarousel", () => {
398-
it.each([
399-
{
400-
title: "Product",
401-
description: "Desc",
402-
actionLabel: "Buy",
403-
actionUrl: "https://shop.com/buy",
404-
expectedType: "uri",
405-
},
406-
{
407-
title: "Product",
408-
description: "Desc",
409-
actionLabel: "Select",
410-
actionData: "product_id=123",
411-
expectedType: "postback",
412-
},
413-
])("uses expected action type for product action", ({ expectedType, ...item }) => {
414-
const template = createProductCarousel([item]);
415-
const columns = (template.template as { columns: Array<{ actions: Array<{ type: string }> }> })
416-
.columns;
417-
const column = expectDefined(columns[0], "product carousel column");
418-
expect(expectDefined(column.actions[0], "product carousel action").type).toBe(expectedType);
419-
});
420-
421-
it("preserves the complete price when truncating a long description", () => {
422-
const template = createProductCarousel([
423-
{
424-
title: "Product",
425-
description: "x".repeat(59),
426-
price: "$12.99",
427-
},
428-
]);
429-
const columns = (template.template as { columns: Array<{ text: string }> }).columns;
430-
431-
const column = expectDefined(columns[0], "priced product carousel column");
432-
expect(column.text).toBe(`${"x".repeat(53)}\n$12.99`);
433-
expect(column.text.length).toBe(60);
336+
);
337+
expect((template.template as { columns: unknown[] }).columns.length).toBe(10);
434338
});
435339
});
436340

@@ -470,13 +374,6 @@ describe("flex cards", () => {
470374
expect(footer.contents.length).toBe(4);
471375
});
472376

473-
it("limits carousels to 12 bubbles", () => {
474-
const bubbles = Array.from({ length: 15 }, (_, i) => createInfoCard(`Card ${i}`, `Body ${i}`));
475-
const carousel = createCarousel(bubbles);
476-
477-
expect(carousel.contents.length).toBe(12);
478-
});
479-
480377
it("limits device controls to 6", () => {
481378
const card = createDeviceControlCard({
482379
deviceName: "Device",
@@ -700,8 +597,12 @@ describe("action label/data surrogate-safe truncation", () => {
700597
expect(received.every((request) => request.authenticated)).toBe(true);
701598
expect(received.every((request) => request.type === "template")).toBe(true);
702599
expect(received.every((request) => request.altText === altText)).toBe(true);
703-
expect(received.filter((request) => request.path.endsWith("/push"))).toHaveLength(4);
704-
expect(received.filter((request) => request.path.endsWith("/reply"))).toHaveLength(4);
600+
expect(received.filter((request) => request.path.endsWith("/push"))).toHaveLength(
601+
lineTemplateMessageScenarios.length,
602+
);
603+
expect(received.filter((request) => request.path.endsWith("/reply"))).toHaveLength(
604+
lineTemplateMessageScenarios.length,
605+
);
705606
});
706607
});
707608

@@ -841,11 +742,6 @@ describe("action label/data surrogate-safe truncation", () => {
841742
};
842743
expect(carousel.columns[0]?.actions).toEqual([unavailableAction]);
843744
expect(carousel.columns[0]?.defaultAction).toEqual(unavailableLink);
844-
845-
const imageCarousel = createImageCarousel([
846-
{ imageUrl: "https://e.example/image.jpg", action: oversizedPostback },
847-
]).template as { columns: Array<{ action: Action }> };
848-
expect(imageCarousel.columns[0]?.action).toEqual(unavailableAction);
849745
});
850746

851747
it("normalizes every length-constrained raw action field", () => {

0 commit comments

Comments
 (0)