@pocketping/widget 1.1.0 → 1.3.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.
package/dist/index.d.cts CHANGED
@@ -65,17 +65,38 @@ interface PocketPingConfig {
65
65
  onVersionWarning?: (warning: VersionWarning) => void;
66
66
  }
67
67
  type MessageStatus = 'sending' | 'sent' | 'delivered' | 'read';
68
+ type AttachmentStatus = 'pending' | 'uploading' | 'ready' | 'failed';
69
+ interface Attachment {
70
+ id: string;
71
+ filename: string;
72
+ mimeType: string;
73
+ size: number;
74
+ url: string;
75
+ thumbnailUrl?: string;
76
+ status: AttachmentStatus;
77
+ }
78
+ /** Reply reference - either a string ID or embedded data from SSE */
79
+ interface ReplyToData {
80
+ id: string;
81
+ content: string;
82
+ sender: string;
83
+ deleted?: boolean;
84
+ }
68
85
  interface Message {
69
86
  id: string;
70
87
  sessionId: string;
71
88
  content: string;
72
89
  sender: 'visitor' | 'operator' | 'ai';
73
90
  timestamp: string;
74
- replyTo?: string;
91
+ /** Reply reference - string ID when sending, object with data from SSE */
92
+ replyTo?: string | ReplyToData;
75
93
  metadata?: Record<string, unknown>;
94
+ attachments?: Attachment[];
76
95
  status?: MessageStatus;
77
96
  deliveredAt?: string;
78
97
  readAt?: string;
98
+ editedAt?: string;
99
+ deletedAt?: string;
79
100
  }
80
101
  interface Session {
81
102
  sessionId: string;
@@ -191,10 +212,44 @@ declare class PocketPingClient {
191
212
  constructor(config: ResolvedPocketPingConfig);
192
213
  connect(): Promise<Session>;
193
214
  disconnect(): void;
194
- sendMessage(content: string): Promise<Message>;
215
+ sendMessage(content: string, attachmentIds?: string[], replyTo?: string): Promise<Message>;
216
+ /**
217
+ * Upload a file attachment
218
+ * Returns the attachment data after successful upload
219
+ * @param file - File object to upload
220
+ * @param onProgress - Optional callback for upload progress (0-100)
221
+ * @example
222
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
223
+ * console.log(`Upload ${progress}% complete`)
224
+ * })
225
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
226
+ */
227
+ uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
228
+ /**
229
+ * Upload multiple files at once
230
+ * @param files - Array of File objects to upload
231
+ * @param onProgress - Optional callback for overall progress (0-100)
232
+ * @returns Array of uploaded attachments
233
+ */
234
+ uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
235
+ /**
236
+ * Upload file to presigned URL with progress tracking
237
+ */
238
+ private uploadToPresignedUrl;
195
239
  fetchMessages(after?: string): Promise<Message[]>;
196
240
  sendTyping(isTyping?: boolean): Promise<void>;
197
241
  sendReadStatus(messageIds: string[], status: MessageStatus): Promise<void>;
242
+ /**
243
+ * Edit a message (visitor can only edit their own messages)
244
+ * @param messageId - ID of the message to edit
245
+ * @param content - New content for the message
246
+ */
247
+ editMessage(messageId: string, content: string): Promise<Message>;
248
+ /**
249
+ * Delete a message (soft delete - visitor can only delete their own messages)
250
+ * @param messageId - ID of the message to delete
251
+ */
252
+ deleteMessage(messageId: string): Promise<boolean>;
198
253
  getPresence(): Promise<PresenceResponse>;
199
254
  /**
200
255
  * Identify the current user with metadata
@@ -294,6 +349,7 @@ declare class PocketPingClient {
294
349
  private connectSSE;
295
350
  private handleWsFailure;
296
351
  private handleRealtimeEvent;
352
+ private getLastEventTimestamp;
297
353
  private handleWebSocketEvent;
298
354
  private handleVersionWarning;
299
355
  private scheduleReconnect;
@@ -315,7 +371,30 @@ declare function destroy(): void;
315
371
  declare function open(): void;
316
372
  declare function close(): void;
317
373
  declare function toggle(): void;
318
- declare function sendMessage(content: string): Promise<Message>;
374
+ declare function sendMessage(content: string, attachmentIds?: string[]): Promise<Message>;
375
+ /**
376
+ * Upload a file attachment
377
+ * Returns the attachment data after successful upload
378
+ * @param file - File object to upload
379
+ * @param onProgress - Optional callback for upload progress (0-100)
380
+ * @example
381
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
382
+ * console.log(`Upload ${progress}% complete`)
383
+ * })
384
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
385
+ */
386
+ declare function uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
387
+ /**
388
+ * Upload multiple files at once
389
+ * @param files - Array of File objects to upload
390
+ * @param onProgress - Optional callback for overall progress (0-100)
391
+ * @returns Array of uploaded attachments
392
+ * @example
393
+ * const attachments = await PocketPing.uploadFiles(files)
394
+ * const ids = attachments.map(a => a.id)
395
+ * await PocketPing.sendMessage('Here are the files', ids)
396
+ */
397
+ declare function uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
319
398
  /**
320
399
  * Trigger a custom event to the backend
321
400
  * @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
@@ -413,6 +492,8 @@ declare const _default: {
413
492
  close: typeof close;
414
493
  toggle: typeof toggle;
415
494
  sendMessage: typeof sendMessage;
495
+ uploadFile: typeof uploadFile;
496
+ uploadFiles: typeof uploadFiles;
416
497
  trigger: typeof trigger;
417
498
  onEvent: typeof onEvent;
418
499
  offEvent: typeof offEvent;
@@ -424,4 +505,4 @@ declare const _default: {
424
505
  getTrackedElements: typeof getTrackedElements;
425
506
  };
426
507
 
427
- export { type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type TrackedElement, type TriggerOptions, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, getTrackedElements, identify, init, offEvent, on, onEvent, open, reset, sendMessage, setupTrackedElements, toggle, trigger };
508
+ export { type Attachment, type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type ReplyToData, type TrackedElement, type TriggerOptions, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, getTrackedElements, identify, init, offEvent, on, onEvent, open, reset, sendMessage, setupTrackedElements, toggle, trigger, uploadFile, uploadFiles };
package/dist/index.d.ts CHANGED
@@ -65,17 +65,38 @@ interface PocketPingConfig {
65
65
  onVersionWarning?: (warning: VersionWarning) => void;
66
66
  }
67
67
  type MessageStatus = 'sending' | 'sent' | 'delivered' | 'read';
68
+ type AttachmentStatus = 'pending' | 'uploading' | 'ready' | 'failed';
69
+ interface Attachment {
70
+ id: string;
71
+ filename: string;
72
+ mimeType: string;
73
+ size: number;
74
+ url: string;
75
+ thumbnailUrl?: string;
76
+ status: AttachmentStatus;
77
+ }
78
+ /** Reply reference - either a string ID or embedded data from SSE */
79
+ interface ReplyToData {
80
+ id: string;
81
+ content: string;
82
+ sender: string;
83
+ deleted?: boolean;
84
+ }
68
85
  interface Message {
69
86
  id: string;
70
87
  sessionId: string;
71
88
  content: string;
72
89
  sender: 'visitor' | 'operator' | 'ai';
73
90
  timestamp: string;
74
- replyTo?: string;
91
+ /** Reply reference - string ID when sending, object with data from SSE */
92
+ replyTo?: string | ReplyToData;
75
93
  metadata?: Record<string, unknown>;
94
+ attachments?: Attachment[];
76
95
  status?: MessageStatus;
77
96
  deliveredAt?: string;
78
97
  readAt?: string;
98
+ editedAt?: string;
99
+ deletedAt?: string;
79
100
  }
80
101
  interface Session {
81
102
  sessionId: string;
@@ -191,10 +212,44 @@ declare class PocketPingClient {
191
212
  constructor(config: ResolvedPocketPingConfig);
192
213
  connect(): Promise<Session>;
193
214
  disconnect(): void;
194
- sendMessage(content: string): Promise<Message>;
215
+ sendMessage(content: string, attachmentIds?: string[], replyTo?: string): Promise<Message>;
216
+ /**
217
+ * Upload a file attachment
218
+ * Returns the attachment data after successful upload
219
+ * @param file - File object to upload
220
+ * @param onProgress - Optional callback for upload progress (0-100)
221
+ * @example
222
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
223
+ * console.log(`Upload ${progress}% complete`)
224
+ * })
225
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
226
+ */
227
+ uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
228
+ /**
229
+ * Upload multiple files at once
230
+ * @param files - Array of File objects to upload
231
+ * @param onProgress - Optional callback for overall progress (0-100)
232
+ * @returns Array of uploaded attachments
233
+ */
234
+ uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
235
+ /**
236
+ * Upload file to presigned URL with progress tracking
237
+ */
238
+ private uploadToPresignedUrl;
195
239
  fetchMessages(after?: string): Promise<Message[]>;
196
240
  sendTyping(isTyping?: boolean): Promise<void>;
197
241
  sendReadStatus(messageIds: string[], status: MessageStatus): Promise<void>;
242
+ /**
243
+ * Edit a message (visitor can only edit their own messages)
244
+ * @param messageId - ID of the message to edit
245
+ * @param content - New content for the message
246
+ */
247
+ editMessage(messageId: string, content: string): Promise<Message>;
248
+ /**
249
+ * Delete a message (soft delete - visitor can only delete their own messages)
250
+ * @param messageId - ID of the message to delete
251
+ */
252
+ deleteMessage(messageId: string): Promise<boolean>;
198
253
  getPresence(): Promise<PresenceResponse>;
199
254
  /**
200
255
  * Identify the current user with metadata
@@ -294,6 +349,7 @@ declare class PocketPingClient {
294
349
  private connectSSE;
295
350
  private handleWsFailure;
296
351
  private handleRealtimeEvent;
352
+ private getLastEventTimestamp;
297
353
  private handleWebSocketEvent;
298
354
  private handleVersionWarning;
299
355
  private scheduleReconnect;
@@ -315,7 +371,30 @@ declare function destroy(): void;
315
371
  declare function open(): void;
316
372
  declare function close(): void;
317
373
  declare function toggle(): void;
318
- declare function sendMessage(content: string): Promise<Message>;
374
+ declare function sendMessage(content: string, attachmentIds?: string[]): Promise<Message>;
375
+ /**
376
+ * Upload a file attachment
377
+ * Returns the attachment data after successful upload
378
+ * @param file - File object to upload
379
+ * @param onProgress - Optional callback for upload progress (0-100)
380
+ * @example
381
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
382
+ * console.log(`Upload ${progress}% complete`)
383
+ * })
384
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
385
+ */
386
+ declare function uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
387
+ /**
388
+ * Upload multiple files at once
389
+ * @param files - Array of File objects to upload
390
+ * @param onProgress - Optional callback for overall progress (0-100)
391
+ * @returns Array of uploaded attachments
392
+ * @example
393
+ * const attachments = await PocketPing.uploadFiles(files)
394
+ * const ids = attachments.map(a => a.id)
395
+ * await PocketPing.sendMessage('Here are the files', ids)
396
+ */
397
+ declare function uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
319
398
  /**
320
399
  * Trigger a custom event to the backend
321
400
  * @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
@@ -413,6 +492,8 @@ declare const _default: {
413
492
  close: typeof close;
414
493
  toggle: typeof toggle;
415
494
  sendMessage: typeof sendMessage;
495
+ uploadFile: typeof uploadFile;
496
+ uploadFiles: typeof uploadFiles;
416
497
  trigger: typeof trigger;
417
498
  onEvent: typeof onEvent;
418
499
  offEvent: typeof offEvent;
@@ -424,4 +505,4 @@ declare const _default: {
424
505
  getTrackedElements: typeof getTrackedElements;
425
506
  };
426
507
 
427
- export { type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type TrackedElement, type TriggerOptions, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, getTrackedElements, identify, init, offEvent, on, onEvent, open, reset, sendMessage, setupTrackedElements, toggle, trigger };
508
+ export { type Attachment, type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type ReplyToData, type TrackedElement, type TriggerOptions, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, getTrackedElements, identify, init, offEvent, on, onEvent, open, reset, sendMessage, setupTrackedElements, toggle, trigger, uploadFile, uploadFiles };