@line-harness/sdk 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.
@@ -0,0 +1,448 @@
1
+ interface HttpClientConfig {
2
+ baseUrl: string;
3
+ apiKey: string;
4
+ timeout: number;
5
+ }
6
+ declare class HttpClient {
7
+ private readonly baseUrl;
8
+ private readonly apiKey;
9
+ private readonly timeout;
10
+ constructor(config: HttpClientConfig);
11
+ get<T = unknown>(path: string): Promise<T>;
12
+ post<T = unknown>(path: string, body?: unknown): Promise<T>;
13
+ put<T = unknown>(path: string, body?: unknown): Promise<T>;
14
+ delete<T = unknown>(path: string): Promise<T>;
15
+ private request;
16
+ }
17
+
18
+ interface LineHarnessConfig {
19
+ apiUrl: string;
20
+ apiKey: string;
21
+ timeout?: number;
22
+ lineAccountId?: string;
23
+ }
24
+ interface ApiResponse<T> {
25
+ success: boolean;
26
+ data: T;
27
+ error?: string;
28
+ }
29
+ interface PaginatedData<T> {
30
+ items: T[];
31
+ total: number;
32
+ page: number;
33
+ limit: number;
34
+ hasNextPage: boolean;
35
+ }
36
+ type ScenarioTriggerType = 'friend_add' | 'tag_added' | 'manual';
37
+ type MessageType = 'text' | 'image' | 'flex';
38
+ type BroadcastStatus = 'draft' | 'scheduled' | 'sending' | 'sent';
39
+ interface Friend {
40
+ id: string;
41
+ lineUserId: string;
42
+ displayName: string | null;
43
+ pictureUrl: string | null;
44
+ statusMessage: string | null;
45
+ isFollowing: boolean;
46
+ metadata: Record<string, unknown>;
47
+ tags: Tag[];
48
+ createdAt: string;
49
+ updatedAt: string;
50
+ }
51
+ interface FriendListParams {
52
+ limit?: number;
53
+ offset?: number;
54
+ tagId?: string;
55
+ accountId?: string;
56
+ }
57
+ interface Tag {
58
+ id: string;
59
+ name: string;
60
+ color: string;
61
+ createdAt: string;
62
+ }
63
+ interface CreateTagInput {
64
+ name: string;
65
+ color?: string;
66
+ }
67
+ interface Scenario {
68
+ id: string;
69
+ name: string;
70
+ description: string | null;
71
+ triggerType: ScenarioTriggerType;
72
+ triggerTagId: string | null;
73
+ isActive: boolean;
74
+ createdAt: string;
75
+ updatedAt: string;
76
+ }
77
+ interface ScenarioListItem extends Scenario {
78
+ stepCount: number;
79
+ }
80
+ interface ScenarioWithSteps extends Scenario {
81
+ steps: ScenarioStep[];
82
+ }
83
+ interface ScenarioStep {
84
+ id: string;
85
+ scenarioId: string;
86
+ stepOrder: number;
87
+ delayMinutes: number;
88
+ messageType: MessageType;
89
+ messageContent: string;
90
+ conditionType: string | null;
91
+ conditionValue: string | null;
92
+ nextStepOnFalse: number | null;
93
+ createdAt: string;
94
+ }
95
+ interface CreateScenarioInput {
96
+ name: string;
97
+ description?: string;
98
+ triggerType: ScenarioTriggerType;
99
+ triggerTagId?: string;
100
+ isActive?: boolean;
101
+ }
102
+ interface CreateStepInput {
103
+ stepOrder: number;
104
+ delayMinutes: number;
105
+ messageType: MessageType;
106
+ messageContent: string;
107
+ conditionType?: string | null;
108
+ conditionValue?: string | null;
109
+ nextStepOnFalse?: number | null;
110
+ }
111
+ interface UpdateScenarioInput {
112
+ name?: string;
113
+ description?: string | null;
114
+ triggerType?: ScenarioTriggerType;
115
+ triggerTagId?: string | null;
116
+ isActive?: boolean;
117
+ }
118
+ interface UpdateStepInput {
119
+ stepOrder?: number;
120
+ delayMinutes?: number;
121
+ messageType?: MessageType;
122
+ messageContent?: string;
123
+ conditionType?: string | null;
124
+ conditionValue?: string | null;
125
+ nextStepOnFalse?: number | null;
126
+ }
127
+ interface FriendScenarioEnrollment {
128
+ id: string;
129
+ friendId: string;
130
+ scenarioId: string;
131
+ currentStepOrder: number;
132
+ status: 'active' | 'paused' | 'completed';
133
+ startedAt: string;
134
+ nextDeliveryAt: string | null;
135
+ updatedAt: string;
136
+ }
137
+ interface Broadcast {
138
+ id: string;
139
+ title: string;
140
+ messageType: MessageType;
141
+ messageContent: string;
142
+ targetType: 'all' | 'tag';
143
+ targetTagId: string | null;
144
+ status: BroadcastStatus;
145
+ scheduledAt: string | null;
146
+ sentAt: string | null;
147
+ totalCount: number;
148
+ successCount: number;
149
+ createdAt: string;
150
+ }
151
+ interface CreateBroadcastInput {
152
+ title: string;
153
+ messageType: MessageType;
154
+ messageContent: string;
155
+ targetType: 'all' | 'tag';
156
+ targetTagId?: string;
157
+ scheduledAt?: string;
158
+ }
159
+ interface UpdateBroadcastInput {
160
+ title?: string;
161
+ messageType?: MessageType;
162
+ messageContent?: string;
163
+ targetType?: 'all' | 'tag';
164
+ targetTagId?: string | null;
165
+ scheduledAt?: string | null;
166
+ }
167
+ interface RichMenuBounds {
168
+ x: number;
169
+ y: number;
170
+ width: number;
171
+ height: number;
172
+ }
173
+ type RichMenuAction = {
174
+ type: 'postback';
175
+ data: string;
176
+ displayText?: string;
177
+ label?: string;
178
+ } | {
179
+ type: 'message';
180
+ text: string;
181
+ label?: string;
182
+ } | {
183
+ type: 'uri';
184
+ uri: string;
185
+ label?: string;
186
+ } | {
187
+ type: 'datetimepicker';
188
+ data: string;
189
+ mode: 'date' | 'time' | 'datetime';
190
+ label?: string;
191
+ } | {
192
+ type: 'richmenuswitch';
193
+ richMenuAliasId: string;
194
+ data: string;
195
+ label?: string;
196
+ };
197
+ interface RichMenuArea {
198
+ bounds: RichMenuBounds;
199
+ action: RichMenuAction;
200
+ }
201
+ interface RichMenu {
202
+ richMenuId: string;
203
+ size: {
204
+ width: number;
205
+ height: number;
206
+ };
207
+ selected: boolean;
208
+ name: string;
209
+ chatBarText: string;
210
+ areas: RichMenuArea[];
211
+ }
212
+ interface CreateRichMenuInput {
213
+ size: {
214
+ width: number;
215
+ height: number;
216
+ };
217
+ selected: boolean;
218
+ name: string;
219
+ chatBarText: string;
220
+ areas: RichMenuArea[];
221
+ }
222
+ interface SegmentRule {
223
+ type: 'tag_exists' | 'tag_not_exists' | 'metadata_equals' | 'metadata_not_equals' | 'ref_code' | 'is_following';
224
+ value: string | boolean | {
225
+ key: string;
226
+ value: string;
227
+ };
228
+ }
229
+ interface SegmentCondition {
230
+ operator: 'AND' | 'OR';
231
+ rules: SegmentRule[];
232
+ }
233
+ interface TrackedLink {
234
+ id: string;
235
+ name: string;
236
+ originalUrl: string;
237
+ trackingUrl: string;
238
+ tagId: string | null;
239
+ scenarioId: string | null;
240
+ isActive: boolean;
241
+ clickCount: number;
242
+ createdAt: string;
243
+ updatedAt: string;
244
+ }
245
+ interface LinkClick {
246
+ id: string;
247
+ friendId: string | null;
248
+ friendDisplayName: string | null;
249
+ clickedAt: string;
250
+ }
251
+ interface TrackedLinkWithClicks extends TrackedLink {
252
+ clicks: LinkClick[];
253
+ }
254
+ interface CreateTrackedLinkInput {
255
+ name: string;
256
+ originalUrl: string;
257
+ tagId?: string | null;
258
+ scenarioId?: string | null;
259
+ }
260
+ interface FormField {
261
+ name: string;
262
+ label: string;
263
+ type: 'text' | 'email' | 'tel' | 'number' | 'textarea' | 'select' | 'radio' | 'checkbox' | 'date';
264
+ required?: boolean;
265
+ options?: string[];
266
+ placeholder?: string;
267
+ }
268
+ interface Form {
269
+ id: string;
270
+ name: string;
271
+ description: string | null;
272
+ fields: FormField[];
273
+ onSubmitTagId: string | null;
274
+ onSubmitScenarioId: string | null;
275
+ saveToMetadata: boolean;
276
+ isActive: boolean;
277
+ submitCount: number;
278
+ createdAt: string;
279
+ updatedAt: string;
280
+ }
281
+ interface CreateFormInput {
282
+ name: string;
283
+ description?: string;
284
+ fields: FormField[];
285
+ onSubmitTagId?: string | null;
286
+ onSubmitScenarioId?: string | null;
287
+ saveToMetadata?: boolean;
288
+ }
289
+ interface UpdateFormInput {
290
+ name?: string;
291
+ description?: string | null;
292
+ fields?: FormField[];
293
+ onSubmitTagId?: string | null;
294
+ onSubmitScenarioId?: string | null;
295
+ saveToMetadata?: boolean;
296
+ isActive?: boolean;
297
+ }
298
+ interface FormSubmission {
299
+ id: string;
300
+ formId: string;
301
+ friendId: string | null;
302
+ data: Record<string, unknown>;
303
+ createdAt: string;
304
+ }
305
+ interface StepDefinition {
306
+ delay: string;
307
+ type: MessageType;
308
+ content: string;
309
+ }
310
+
311
+ declare class FriendsResource {
312
+ private readonly http;
313
+ private readonly defaultAccountId?;
314
+ constructor(http: HttpClient, defaultAccountId?: string | undefined);
315
+ list(params?: FriendListParams): Promise<PaginatedData<Friend>>;
316
+ get(id: string): Promise<Friend>;
317
+ count(params?: {
318
+ accountId?: string;
319
+ }): Promise<number>;
320
+ addTag(friendId: string, tagId: string): Promise<void>;
321
+ removeTag(friendId: string, tagId: string): Promise<void>;
322
+ sendMessage(friendId: string, content: string, messageType?: MessageType): Promise<{
323
+ messageId: string;
324
+ }>;
325
+ setMetadata(friendId: string, fields: Record<string, unknown>): Promise<Friend>;
326
+ setRichMenu(friendId: string, richMenuId: string): Promise<void>;
327
+ removeRichMenu(friendId: string): Promise<void>;
328
+ }
329
+
330
+ declare class TagsResource {
331
+ private readonly http;
332
+ constructor(http: HttpClient);
333
+ list(): Promise<Tag[]>;
334
+ create(input: CreateTagInput): Promise<Tag>;
335
+ delete(id: string): Promise<void>;
336
+ }
337
+
338
+ declare class ScenariosResource {
339
+ private readonly http;
340
+ private readonly defaultAccountId?;
341
+ constructor(http: HttpClient, defaultAccountId?: string | undefined);
342
+ list(params?: {
343
+ accountId?: string;
344
+ }): Promise<ScenarioListItem[]>;
345
+ get(id: string): Promise<ScenarioWithSteps>;
346
+ create(input: CreateScenarioInput & {
347
+ lineAccountId?: string;
348
+ }): Promise<Scenario>;
349
+ update(id: string, input: UpdateScenarioInput): Promise<Scenario>;
350
+ delete(id: string): Promise<void>;
351
+ addStep(scenarioId: string, input: CreateStepInput): Promise<ScenarioStep>;
352
+ updateStep(scenarioId: string, stepId: string, input: UpdateStepInput): Promise<ScenarioStep>;
353
+ deleteStep(scenarioId: string, stepId: string): Promise<void>;
354
+ enroll(scenarioId: string, friendId: string): Promise<FriendScenarioEnrollment>;
355
+ }
356
+
357
+ declare class BroadcastsResource {
358
+ private readonly http;
359
+ private readonly defaultAccountId?;
360
+ constructor(http: HttpClient, defaultAccountId?: string | undefined);
361
+ list(params?: {
362
+ accountId?: string;
363
+ }): Promise<Broadcast[]>;
364
+ get(id: string): Promise<Broadcast>;
365
+ create(input: CreateBroadcastInput & {
366
+ lineAccountId?: string;
367
+ }): Promise<Broadcast>;
368
+ update(id: string, input: UpdateBroadcastInput): Promise<Broadcast>;
369
+ delete(id: string): Promise<void>;
370
+ send(id: string): Promise<Broadcast>;
371
+ sendToSegment(id: string, conditions: SegmentCondition): Promise<Broadcast>;
372
+ }
373
+
374
+ declare class RichMenusResource {
375
+ private readonly http;
376
+ constructor(http: HttpClient);
377
+ list(): Promise<RichMenu[]>;
378
+ create(menu: CreateRichMenuInput): Promise<{
379
+ richMenuId: string;
380
+ }>;
381
+ delete(richMenuId: string): Promise<void>;
382
+ setDefault(richMenuId: string): Promise<void>;
383
+ }
384
+
385
+ declare class TrackedLinksResource {
386
+ private readonly http;
387
+ constructor(http: HttpClient);
388
+ list(): Promise<TrackedLink[]>;
389
+ create(input: CreateTrackedLinkInput): Promise<TrackedLink>;
390
+ get(id: string): Promise<TrackedLinkWithClicks>;
391
+ delete(id: string): Promise<void>;
392
+ }
393
+
394
+ declare class FormsResource {
395
+ private readonly http;
396
+ constructor(http: HttpClient);
397
+ list(): Promise<Form[]>;
398
+ get(id: string): Promise<Form>;
399
+ create(input: CreateFormInput): Promise<Form>;
400
+ update(id: string, input: UpdateFormInput): Promise<Form>;
401
+ delete(id: string): Promise<void>;
402
+ getSubmissions(formId: string): Promise<FormSubmission[]>;
403
+ }
404
+
405
+ declare class LineHarness {
406
+ readonly friends: FriendsResource;
407
+ readonly tags: TagsResource;
408
+ readonly scenarios: ScenariosResource;
409
+ readonly broadcasts: BroadcastsResource;
410
+ readonly richMenus: RichMenusResource;
411
+ readonly trackedLinks: TrackedLinksResource;
412
+ readonly forms: FormsResource;
413
+ private readonly apiUrl;
414
+ private readonly defaultAccountId;
415
+ private readonly workflows;
416
+ readonly createStepScenario: (name: string, triggerType: ScenarioTriggerType, steps: StepDefinition[]) => Promise<ScenarioWithSteps>;
417
+ readonly broadcastText: (text: string) => Promise<Broadcast>;
418
+ readonly broadcastToTag: (tagId: string, messageType: MessageType, content: string) => Promise<Broadcast>;
419
+ readonly broadcastToSegment: (messageType: MessageType, content: string, conditions: SegmentCondition) => Promise<Broadcast>;
420
+ readonly sendTextToFriend: (friendId: string, text: string) => Promise<{
421
+ messageId: string;
422
+ }>;
423
+ readonly sendFlexToFriend: (friendId: string, flexJson: string) => Promise<{
424
+ messageId: string;
425
+ }>;
426
+ constructor(config: LineHarnessConfig);
427
+ /**
428
+ * Generate friend-add URL with OAuth (bot_prompt=aggressive)
429
+ * This URL does friend-add + UUID in one step.
430
+ *
431
+ * @param ref - Attribution code (e.g., 'lp-a', 'instagram', 'seminar-0322')
432
+ * @param redirect - URL to redirect after completion
433
+ */
434
+ getAuthUrl(options?: {
435
+ ref?: string;
436
+ redirect?: string;
437
+ }): string;
438
+ }
439
+
440
+ declare class LineHarnessError extends Error {
441
+ readonly status: number;
442
+ readonly endpoint: string;
443
+ constructor(message: string, status: number, endpoint: string);
444
+ }
445
+
446
+ declare function parseDelay(input: string): number;
447
+
448
+ export { type ApiResponse, type Broadcast, type BroadcastStatus, BroadcastsResource, type CreateBroadcastInput, type CreateFormInput, type CreateRichMenuInput, type CreateScenarioInput, type CreateStepInput, type CreateTagInput, type CreateTrackedLinkInput, type Form, type FormField, type FormSubmission, FormsResource, type Friend, type FriendListParams, type FriendScenarioEnrollment, FriendsResource, LineHarness, type LineHarnessConfig, LineHarnessError, type LinkClick, type MessageType, type PaginatedData, type RichMenu, type RichMenuAction, type RichMenuArea, type RichMenuBounds, RichMenusResource, type Scenario, type ScenarioListItem, type ScenarioStep, type ScenarioTriggerType, type ScenarioWithSteps, ScenariosResource, type SegmentCondition, type SegmentRule, type StepDefinition, type Tag, TagsResource, type TrackedLink, type TrackedLinkWithClicks, TrackedLinksResource, type UpdateBroadcastInput, type UpdateFormInput, type UpdateScenarioInput, type UpdateStepInput, parseDelay };