@lightworkai.official/debug-capture 0.6.0 → 0.7.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.
@@ -1,115 +0,0 @@
1
- /** A board column as the realm configured it. Only public lanes are returned. */
2
- export interface StatusColumn {
3
- key: string;
4
- label: string;
5
- description: string;
6
- color: string;
7
- bucket: "active" | "closed";
8
- awaitingReply: boolean;
9
- }
10
- export interface RealmConfig {
11
- realm: {
12
- id: string;
13
- slug: string;
14
- name: string;
15
- };
16
- timezone: string;
17
- statusColumns: StatusColumn[];
18
- featureFlags: {
19
- selfServiceReopen?: boolean;
20
- attachments?: boolean;
21
- conversation?: boolean;
22
- };
23
- locale: {
24
- default: string;
25
- labels: Record<string, string>;
26
- };
27
- }
28
- export interface TicketMessage {
29
- id: string;
30
- authorId: string | null;
31
- authorName: string | null;
32
- authorRole: "REPORTER" | "AGENT";
33
- body: string;
34
- createdAt: string;
35
- editedAt: string | null;
36
- }
37
- export interface TicketAttachment {
38
- id: string;
39
- objectKey: string;
40
- filename: string | null;
41
- contentType: string | null;
42
- sizeBytes: number | null;
43
- }
44
- export interface MyTicket {
45
- id: string;
46
- number: number;
47
- title: string;
48
- description: string | null;
49
- category: string | null;
50
- routeUrl: string | null;
51
- status: string;
52
- priority: string;
53
- resolutionNote: string | null;
54
- reopened: boolean;
55
- createdAt: string;
56
- updatedAt: string;
57
- }
58
- export interface MyTicketListItem extends MyTicket {
59
- messageCount: number;
60
- /** How many replies came from the team — "has anyone answered me yet". */
61
- agentReplyCount: number;
62
- lastMessage: {
63
- at: string;
64
- authorRole: "REPORTER" | "AGENT";
65
- preview: string;
66
- } | null;
67
- }
68
- export interface MyTicketDetail extends MyTicket {
69
- messages: TicketMessage[];
70
- attachments: TicketAttachment[];
71
- }
72
- /** One recorded status change. Internal lanes are already resolved server-side. */
73
- export interface StatusEvent {
74
- id: string;
75
- fromStatus: string | null;
76
- toStatus: string;
77
- via: string;
78
- createdAt: string;
79
- }
80
- /** Thrown with the server's own words, so a panel can say what went wrong. */
81
- export declare class TicketApiError extends Error {
82
- readonly status: number;
83
- constructor(message: string, status: number);
84
- }
85
- /** Raised when there is no signed-in reporter to ask about. */
86
- export declare class NoIdentityError extends Error {
87
- constructor();
88
- }
89
- export declare function listMyTickets(): Promise<MyTicketListItem[]>;
90
- export declare function getMyTicket(id: string): Promise<MyTicketDetail>;
91
- export declare function getMyTicketByNumber(num: number): Promise<MyTicketDetail>;
92
- /**
93
- * A short-lived URL for a file on one's own ticket.
94
- *
95
- * Fetched rather than pointed at: the endpoint needs the realm key and the
96
- * identity token, and an `<img>` or an `<a download>` cannot send a header.
97
- */
98
- export declare function getAttachmentUrl(attachmentId: string): Promise<{
99
- url: string;
100
- filename: string | null;
101
- }>;
102
- export declare function getMyTicketHistory(id: string): Promise<StatusEvent[]>;
103
- export declare function replyToTicket(id: string, body: string): Promise<TicketMessage>;
104
- /**
105
- * Rewrite one's own reply.
106
- *
107
- * The server refuses any message the caller did not write — authorship, not
108
- * role — so this cannot touch the team's side of the thread.
109
- */
110
- export declare function editMyMessage(ticketId: string, messageId: string, body: string): Promise<TicketMessage>;
111
- export declare function reopenMyTicket(id: string, note?: string): Promise<MyTicket>;
112
- export declare function uploadInlineImage(id: string, dataUri: string, filename?: string): Promise<{
113
- url: string;
114
- }>;
115
- export declare function fetchRealmConfig(): Promise<RealmConfig>;
@@ -1,84 +0,0 @@
1
- /**
2
- * The panel's decisions that are not DOM: how a ticket is named, dated, sorted,
3
- * searched and described. Pure, so they can be tested without a browser — which
4
- * matters here, because the DOM around them cannot be.
5
- */
6
- import type { MyTicketListItem, StatusColumn } from "./api";
7
- /**
8
- * `ROOT-1099`, from the realm's slug — the same key the board and the admin app
9
- * print, so a reporter quoting a number is quoting the one support will search
10
- * for. A realm with no usable slug falls back to `#1099` rather than inventing
11
- * a prefix.
12
- */
13
- export declare function ticketKey(slug: string | undefined, number: number): string;
14
- /**
15
- * `24 พ.ค. 2568 13:00` — the original's `DD MMM BBBB HH:mm`, from the platform's
16
- * own Intl rather than a date library this package will not depend on.
17
- *
18
- * Formatted in the REALM's timezone, not the reader's. A support desk in
19
- * Bangkok and a reporter travelling in Berlin must not disagree about which day
20
- * a ticket was filed, and the realm is the side that also runs the "today"
21
- * filters.
22
- */
23
- export declare function formatDateTime(iso: string | null | undefined, timezone: string, locale: "th" | "en" | undefined): string;
24
- /** Lookups over the realm's configured lanes, with sane answers for a key that isn't there. */
25
- export interface StatusMaps {
26
- labelOf: (key: string) => string;
27
- columnOf: (key: string) => StatusColumn | undefined;
28
- isAwaitingReply: (key: string) => boolean;
29
- isClosed: (key: string) => boolean;
30
- /** Board order, for sorting a column of statuses the way the board reads. */
31
- rankOf: (key: string) => number;
32
- options: {
33
- value: string;
34
- label: string;
35
- }[];
36
- }
37
- export declare function statusMaps(columns: StatusColumn[], allLabel: string): StatusMaps;
38
- /** Has the team written a solution note? */
39
- export declare function hasSolution(t: MyTicketListItem): boolean;
40
- /** Has anyone from the team replied at all? */
41
- export declare function hasTeamReply(t: MyTicketListItem): boolean;
42
- /** Solution beats a reply beats silence — the order the column sorts in. */
43
- export declare function responseRank(t: MyTicketListItem): number;
44
- export type SortKey = "number" | "title" | "module" | "status" | "response" | "createdAt" | "updatedAt";
45
- export interface Sort {
46
- key: SortKey;
47
- direction: "asc" | "desc";
48
- }
49
- /**
50
- * Filter by what the reporter SEES.
51
- *
52
- * The haystack is the rendered row — key, title, module, status label — because
53
- * that is what someone searching has in front of them. Searching the raw status
54
- * key would match `IN_PROGRESS` for a lane the reader only ever saw called
55
- * กำลังดำเนินการ.
56
- */
57
- export declare function matchesKeyword(t: MyTicketListItem, keyword: string, slug: string | undefined, labelOf: (key: string) => string): boolean;
58
- /**
59
- * Comparators for the orders a raw value compare gets wrong: status follows the
60
- * board rather than the alphabet, dates are chronological rather than
61
- * lexicographic, and the response column ranks by a signal that is not one field.
62
- */
63
- export declare function compareBy(sort: Sort, maps: StatusMaps, slug: string | undefined): (a: MyTicketListItem, b: MyTicketListItem) => number;
64
- /** Rows per page — the original's `defaultPageSize`. */
65
- export declare const PAGE_SIZE = 10;
66
- export declare function pageOf<T>(rows: T[], page: number, size?: number): T[];
67
- export declare function pageCount(total: number, size?: number): number;
68
- /**
69
- * The same ten colour tokens the board uses, as concrete pairs.
70
- *
71
- * A status arrives as DATA — a realm adds lanes whenever it likes — so a pill is
72
- * coloured with an inline style from this map rather than a class a stylesheet
73
- * could never know the name of. Keeping the values identical
74
- * to the app's own STATUS_TONES is the point: a reporter and an agent looking at
75
- * the same ticket should see the same colour for it.
76
- */
77
- export declare const STATUS_TONES: Record<string, {
78
- fg: string;
79
- bg: string;
80
- }>;
81
- export declare function statusTone(token: string | undefined): {
82
- fg: string;
83
- bg: string;
84
- };
@@ -1,66 +0,0 @@
1
- /**
2
- * Rendering a ticket body inside somebody else's app.
3
- *
4
- * Bodies are HTML — the composer's formatting and its inline screenshots are the
5
- * point of the thread, so stripping to text would lose what a reporter actually
6
- * came to read. But that HTML was written by other people, and this package
7
- * renders it inside a HOST application's page. Markup that ran there would run
8
- * with the host's origin, against the host's session. A support widget must not
9
- * be the way an app gets XSS.
10
- *
11
- * The support app solves this with DOMPurify. A package that every consumer
12
- * installs cannot take that dependency for one screen, so this is the same
13
- * POLICY over the platform's own parser: parse the string with DOMParser (never
14
- * a regex), walk the result, and delete every node and attribute not on the
15
- * list. Anything unrecognised is removed rather than escaped, and the walk is
16
- * over an inert document, so nothing loads or executes while it happens.
17
- */
18
- /** Tags an ordinary note actually uses. Everything else goes. */
19
- export declare const ALLOWED_TAGS: Set<string>;
20
- export declare const ALLOWED_ATTR: Set<string>;
21
- /** Links: ordinary web destinations only. No javascript:, no data:. */
22
- export declare function isAllowedHref(url: string): boolean;
23
- /**
24
- * Image sources: OUR inline images and nothing else.
25
- *
26
- * Not a tightening for its own sake. Any other src turns every ticket into a
27
- * tracking pixel aimed at whoever opens it — a body can be written by a stranger
28
- * who filed a report, and the reader here is the reporter, on the host's page.
29
- * Accepts the server-relative form and the same path already made absolute
30
- * against the configured host.
31
- */
32
- export declare function isAllowedImageSrc(url: string, host: string): boolean;
33
- export declare function looksLikeHtml(body: string): boolean;
34
- /** Tags out, line structure kept — for previews and anywhere text is all that fits. */
35
- export declare function toPlainText(body: string): string;
36
- /**
37
- * Fill `target` with a safe rendering of `body`.
38
- *
39
- * A node rather than a string, deliberately: handing back HTML invites a caller
40
- * to concatenate it with something else and re-parse the result, which is where
41
- * sanitisers stop holding.
42
- */
43
- export declare function renderBody(target: HTMLElement, body: string, host: string): void;
44
- /**
45
- * The same walk, but returning a string — for content going OUT.
46
- *
47
- * `renderBody` deliberately hands back a node, because handing back HTML invites
48
- * a caller to concatenate and re-parse it. This one exists for the single case
49
- * where a string is the only possible answer: the composer has to put what
50
- * somebody typed into a JSON body.
51
- *
52
- * It matters for the same reason the display side does, from the other
53
- * direction. A contenteditable takes whatever the clipboard had in it — a
54
- * pasted block of a web page arrives with its scripts, its styles and its
55
- * tracking pixels intact — and posting that unfiltered would store it for
56
- * every future reader of the thread.
57
- */
58
- export declare function cleanHtml(html: string, host: string): string;
59
- /**
60
- * True when there is nothing worth sending.
61
- *
62
- * An image alone counts as content — a screenshot with no words is the most
63
- * common reply a reporter makes — but a contenteditable that has been typed in
64
- * and cleared is full of empty tags and `&nbsp;`, and those are not.
65
- */
66
- export declare function htmlIsEmpty(html: string): boolean;
@@ -1,74 +0,0 @@
1
- /**
2
- * The tickets panel's own words, kept apart from the reporter dialog's so
3
- * neither grows the other's vocabulary. Thai wording is the original's, verbatim
4
- * where the original had one.
5
- */
6
- export interface TicketStrings {
7
- title: string;
8
- intro: string;
9
- searchPlaceholder: string;
10
- searchLabel: string;
11
- allStatuses: string;
12
- count: (n: number) => string;
13
- colNumber: string;
14
- colTitle: string;
15
- colModule: string;
16
- colStatus: string;
17
- colResponse: string;
18
- colCreated: string;
19
- colUpdated: string;
20
- awaitingReply: string;
21
- hasSolution: string;
22
- hasReply: string;
23
- noReply: string;
24
- empty: string;
25
- emptyFiltered: string;
26
- loading: string;
27
- listFailed: string;
28
- detailFailed: string;
29
- signedOut: string;
30
- back: string;
31
- reportedBy: string;
32
- conversation: string;
33
- resolution: string;
34
- noMessages: string;
35
- you: string;
36
- team: string;
37
- /** The role chip beside a reporter's name, as the original prints it. */
38
- reporterRole: string;
39
- edited: string;
40
- edit: string;
41
- saveEdit: string;
42
- cancel: string;
43
- replyPlaceholder: string;
44
- bold: string;
45
- italic: string;
46
- underline: string;
47
- strike: string;
48
- code: string;
49
- blockquote: string;
50
- bulletList: string;
51
- orderedList: string;
52
- link: string;
53
- linkPrompt: string;
54
- linkNeedsSelection: string;
55
- linkInvalid: string;
56
- attachImage: string;
57
- uploading: string;
58
- send: string;
59
- sending: string;
60
- sent: string;
61
- sendFailed: string;
62
- reopen: string;
63
- reopenHint: string;
64
- reopening: string;
65
- reopened: string;
66
- reopenFailed: string;
67
- close: string;
68
- retry: string;
69
- page: string;
70
- of: (page: number, pages: number) => string;
71
- prev: string;
72
- next: string;
73
- }
74
- export declare function ticketStrings(locale: "th" | "en" | undefined): TicketStrings;
@@ -1,17 +0,0 @@
1
- /**
2
- * Which controls a rich composer offers.
3
- *
4
- * A list rather than a fixed set, because the original itself has two —
5
- * `NOTE_TOOLBAR` for replies and a longer one for articles — and the support app's
6
- * admin composer wants a few more than a reporter's does. The alternative was a
7
- * second editor component, which is the thing this package exists to stop.
8
- */
9
- export type EditorTool = "bold" | "italic" | "underline" | "strike" | "code" | "bulletList" | "orderedList" | "blockquote" | "link" | "image";
10
- /** The original's own NOTE_TOOLBAR — what a reporter replying to a ticket gets. */
11
- export declare const NOTE_TOOLBAR: EditorTool[];
12
- /**
13
- * Everything, for a staff composer. Adds the three the admin side had grown on
14
- * its own — strike, code and blockquote — so adopting this component costs the
15
- * app nothing it already had.
16
- */
17
- export declare const FULL_TOOLBAR: EditorTool[];
@@ -1,226 +0,0 @@
1
- /**
2
- * The reporter's own tickets, read back from a Lightwork Support host.
3
- *
4
- * Everything here goes to `/ingest/me`, which needs two things: the realm's
5
- * public key (which app is asking) and a host-signed identity token (who is
6
- * asking). See `identity` in config.ts for why the second one exists — without
7
- * it a public key would be enough to read anybody's reports.
8
- */
9
- import { getConfig } from "../config";
10
-
11
- /** A board column as the realm configured it. Only public lanes are returned. */
12
- export interface StatusColumn {
13
- key: string;
14
- label: string;
15
- description: string;
16
- color: string;
17
- bucket: "active" | "closed";
18
- awaitingReply: boolean;
19
- }
20
-
21
- export interface RealmConfig {
22
- realm: { id: string; slug: string; name: string };
23
- timezone: string;
24
- statusColumns: StatusColumn[];
25
- featureFlags: { selfServiceReopen?: boolean; attachments?: boolean; conversation?: boolean };
26
- locale: { default: string; labels: Record<string, string> };
27
- }
28
-
29
- export interface TicketMessage {
30
- id: string;
31
- authorId: string | null;
32
- authorName: string | null;
33
- authorRole: "REPORTER" | "AGENT";
34
- body: string;
35
- createdAt: string;
36
- editedAt: string | null;
37
- }
38
-
39
- export interface TicketAttachment {
40
- id: string;
41
- objectKey: string;
42
- filename: string | null;
43
- contentType: string | null;
44
- sizeBytes: number | null;
45
- }
46
-
47
- export interface MyTicket {
48
- id: string;
49
- number: number;
50
- title: string;
51
- description: string | null;
52
- category: string | null;
53
- routeUrl: string | null;
54
- status: string;
55
- priority: string;
56
- resolutionNote: string | null;
57
- reopened: boolean;
58
- createdAt: string;
59
- updatedAt: string;
60
- }
61
-
62
- export interface MyTicketListItem extends MyTicket {
63
- messageCount: number;
64
- /** How many replies came from the team — "has anyone answered me yet". */
65
- agentReplyCount: number;
66
- lastMessage: { at: string; authorRole: "REPORTER" | "AGENT"; preview: string } | null;
67
- }
68
-
69
- export interface MyTicketDetail extends MyTicket {
70
- messages: TicketMessage[];
71
- attachments: TicketAttachment[];
72
- }
73
-
74
- /** One recorded status change. Internal lanes are already resolved server-side. */
75
- export interface StatusEvent {
76
- id: string;
77
- fromStatus: string | null;
78
- toStatus: string;
79
- via: string;
80
- createdAt: string;
81
- }
82
-
83
- /** Thrown with the server's own words, so a panel can say what went wrong. */
84
- export class TicketApiError extends Error {
85
- constructor(
86
- message: string,
87
- readonly status: number,
88
- ) {
89
- super(message);
90
- }
91
- }
92
-
93
- /** Raised when there is no signed-in reporter to ask about. */
94
- export class NoIdentityError extends Error {
95
- constructor() {
96
- super("[debug-capture] no reporter identity — configure `identity` to use the tickets panel");
97
- }
98
- }
99
-
100
- function base(): string {
101
- return getConfig().host.replace(/\/$/, "");
102
- }
103
-
104
- /**
105
- * The host's current identity token.
106
- *
107
- * Read per request rather than once at configure time: these are short-lived by
108
- * design, and a panel left open across lunch would otherwise hold a token that
109
- * expired an hour ago. Caching belongs on the host's side, where it knows when
110
- * it last minted one.
111
- */
112
- async function identityToken(): Promise<string> {
113
- const read = getConfig().identity;
114
- if (!read) throw new NoIdentityError();
115
- const token = await read();
116
- if (!token) throw new NoIdentityError();
117
- return token;
118
- }
119
-
120
- async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
121
- const token = await identityToken();
122
- const res = await fetch(`${base()}/ingest/me${path}`, {
123
- ...init,
124
- headers: {
125
- "x-realm-key": getConfig().realmKey,
126
- authorization: `Bearer ${token}`,
127
- ...(init.body ? { "content-type": "application/json" } : {}),
128
- ...(init.headers as Record<string, string> | undefined),
129
- },
130
- });
131
- if (!res.ok) {
132
- const detail = await res
133
- .json()
134
- .then((b: { error?: string }) => b.error)
135
- .catch(() => null);
136
- throw new TicketApiError(detail ?? `Request failed (${res.status})`, res.status);
137
- }
138
- return (await res.json()) as T;
139
- }
140
-
141
- export async function listMyTickets(): Promise<MyTicketListItem[]> {
142
- const { items } = await request<{ items: MyTicketListItem[] }>("/tickets");
143
- return items;
144
- }
145
-
146
- export function getMyTicket(id: string): Promise<MyTicketDetail> {
147
- return request<MyTicketDetail>(`/tickets/${encodeURIComponent(id)}`);
148
- }
149
-
150
- export function getMyTicketByNumber(num: number): Promise<MyTicketDetail> {
151
- return request<MyTicketDetail>(`/tickets/by-number/${num}`);
152
- }
153
-
154
- /**
155
- * A short-lived URL for a file on one's own ticket.
156
- *
157
- * Fetched rather than pointed at: the endpoint needs the realm key and the
158
- * identity token, and an `<img>` or an `<a download>` cannot send a header.
159
- */
160
- export function getAttachmentUrl(attachmentId: string): Promise<{ url: string; filename: string | null }> {
161
- return request<{ url: string; filename: string | null }>(`/attachments/${encodeURIComponent(attachmentId)}`);
162
- }
163
-
164
- export function getMyTicketHistory(id: string): Promise<StatusEvent[]> {
165
- return request<StatusEvent[]>(`/tickets/${encodeURIComponent(id)}/history`);
166
- }
167
-
168
- export function replyToTicket(id: string, body: string): Promise<TicketMessage> {
169
- return request<TicketMessage>(`/tickets/${encodeURIComponent(id)}/messages`, {
170
- method: "POST",
171
- body: JSON.stringify({ body }),
172
- });
173
- }
174
-
175
- /**
176
- * Rewrite one's own reply.
177
- *
178
- * The server refuses any message the caller did not write — authorship, not
179
- * role — so this cannot touch the team's side of the thread.
180
- */
181
- export function editMyMessage(ticketId: string, messageId: string, body: string): Promise<TicketMessage> {
182
- return request<TicketMessage>(
183
- `/tickets/${encodeURIComponent(ticketId)}/messages/${encodeURIComponent(messageId)}`,
184
- { method: "PUT", body: JSON.stringify({ body }) },
185
- );
186
- }
187
-
188
- export function reopenMyTicket(id: string, note?: string): Promise<MyTicket> {
189
- return request<MyTicket>(`/tickets/${encodeURIComponent(id)}/reopen`, {
190
- method: "POST",
191
- body: JSON.stringify({ note: note?.trim() || undefined }),
192
- });
193
- }
194
-
195
- export function uploadInlineImage(id: string, dataUri: string, filename?: string): Promise<{ url: string }> {
196
- return request<{ url: string }>(`/tickets/${encodeURIComponent(id)}/inline-image`, {
197
- method: "POST",
198
- body: JSON.stringify({ dataUri, filename }),
199
- });
200
- }
201
-
202
- /**
203
- * The realm's status vocabulary. Public config, so no identity token — and
204
- * cached for the life of the page, because it changes when an admin edits the
205
- * board and not between two clicks of a list.
206
- */
207
- let configPromise: Promise<RealmConfig> | null = null;
208
-
209
- export function fetchRealmConfig(): Promise<RealmConfig> {
210
- if (!configPromise) {
211
- const key = encodeURIComponent(getConfig().realmKey);
212
- configPromise = fetch(`${base()}/ingest/config?key=${key}`)
213
- .then((res) => {
214
- if (!res.ok) throw new TicketApiError(`Config failed (${res.status})`, res.status);
215
- return res.json() as Promise<RealmConfig>;
216
- })
217
- // A failed fetch must not be remembered as the answer: the next open
218
- // should try again rather than reuse a rejected promise forever.
219
- .catch((e) => {
220
- configPromise = null;
221
- throw e;
222
- });
223
- }
224
- return configPromise;
225
- }
226
-