@pocketping/widget 1.0.2 → 1.2.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,6 +65,16 @@ 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
+ }
68
78
  interface Message {
69
79
  id: string;
70
80
  sessionId: string;
@@ -73,9 +83,12 @@ interface Message {
73
83
  timestamp: string;
74
84
  replyTo?: string;
75
85
  metadata?: Record<string, unknown>;
86
+ attachments?: Attachment[];
76
87
  status?: MessageStatus;
77
88
  deliveredAt?: string;
78
89
  readAt?: string;
90
+ editedAt?: string;
91
+ deletedAt?: string;
79
92
  }
80
93
  interface Session {
81
94
  sessionId: string;
@@ -171,6 +184,7 @@ declare class PocketPingClient {
171
184
  private config;
172
185
  private session;
173
186
  private ws;
187
+ private sse;
174
188
  private isOpen;
175
189
  private listeners;
176
190
  private customEventHandlers;
@@ -182,7 +196,7 @@ declare class PocketPingClient {
182
196
  private maxPollingFailures;
183
197
  private wsConnectedAt;
184
198
  private quickFailureThreshold;
185
- private usePollingFallback;
199
+ private connectionMode;
186
200
  private trackedElementCleanups;
187
201
  private currentTrackedElements;
188
202
  private inspectorMode;
@@ -190,10 +204,44 @@ declare class PocketPingClient {
190
204
  constructor(config: ResolvedPocketPingConfig);
191
205
  connect(): Promise<Session>;
192
206
  disconnect(): void;
193
- sendMessage(content: string): Promise<Message>;
207
+ sendMessage(content: string, attachmentIds?: string[], replyTo?: string): Promise<Message>;
208
+ /**
209
+ * Upload a file attachment
210
+ * Returns the attachment data after successful upload
211
+ * @param file - File object to upload
212
+ * @param onProgress - Optional callback for upload progress (0-100)
213
+ * @example
214
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
215
+ * console.log(`Upload ${progress}% complete`)
216
+ * })
217
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
218
+ */
219
+ uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
220
+ /**
221
+ * Upload multiple files at once
222
+ * @param files - Array of File objects to upload
223
+ * @param onProgress - Optional callback for overall progress (0-100)
224
+ * @returns Array of uploaded attachments
225
+ */
226
+ uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
227
+ /**
228
+ * Upload file to presigned URL with progress tracking
229
+ */
230
+ private uploadToPresignedUrl;
194
231
  fetchMessages(after?: string): Promise<Message[]>;
195
232
  sendTyping(isTyping?: boolean): Promise<void>;
196
233
  sendReadStatus(messageIds: string[], status: MessageStatus): Promise<void>;
234
+ /**
235
+ * Edit a message (visitor can only edit their own messages)
236
+ * @param messageId - ID of the message to edit
237
+ * @param content - New content for the message
238
+ */
239
+ editMessage(messageId: string, content: string): Promise<Message>;
240
+ /**
241
+ * Delete a message (soft delete - visitor can only delete their own messages)
242
+ * @param messageId - ID of the message to delete
243
+ */
244
+ deleteMessage(messageId: string): Promise<boolean>;
197
245
  getPresence(): Promise<PresenceResponse>;
198
246
  /**
199
247
  * Identify the current user with metadata
@@ -288,8 +336,11 @@ declare class PocketPingClient {
288
336
  * Check if inspector mode is active
289
337
  */
290
338
  isInspectorModeActive(): boolean;
339
+ private connectRealtime;
291
340
  private connectWebSocket;
341
+ private connectSSE;
292
342
  private handleWsFailure;
343
+ private handleRealtimeEvent;
293
344
  private handleWebSocketEvent;
294
345
  private handleVersionWarning;
295
346
  private scheduleReconnect;
@@ -311,7 +362,30 @@ declare function destroy(): void;
311
362
  declare function open(): void;
312
363
  declare function close(): void;
313
364
  declare function toggle(): void;
314
- declare function sendMessage(content: string): Promise<Message>;
365
+ declare function sendMessage(content: string, attachmentIds?: string[]): Promise<Message>;
366
+ /**
367
+ * Upload a file attachment
368
+ * Returns the attachment data after successful upload
369
+ * @param file - File object to upload
370
+ * @param onProgress - Optional callback for upload progress (0-100)
371
+ * @example
372
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
373
+ * console.log(`Upload ${progress}% complete`)
374
+ * })
375
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
376
+ */
377
+ declare function uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
378
+ /**
379
+ * Upload multiple files at once
380
+ * @param files - Array of File objects to upload
381
+ * @param onProgress - Optional callback for overall progress (0-100)
382
+ * @returns Array of uploaded attachments
383
+ * @example
384
+ * const attachments = await PocketPing.uploadFiles(files)
385
+ * const ids = attachments.map(a => a.id)
386
+ * await PocketPing.sendMessage('Here are the files', ids)
387
+ */
388
+ declare function uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
315
389
  /**
316
390
  * Trigger a custom event to the backend
317
391
  * @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
@@ -409,6 +483,8 @@ declare const _default: {
409
483
  close: typeof close;
410
484
  toggle: typeof toggle;
411
485
  sendMessage: typeof sendMessage;
486
+ uploadFile: typeof uploadFile;
487
+ uploadFiles: typeof uploadFiles;
412
488
  trigger: typeof trigger;
413
489
  onEvent: typeof onEvent;
414
490
  offEvent: typeof offEvent;
@@ -420,4 +496,4 @@ declare const _default: {
420
496
  getTrackedElements: typeof getTrackedElements;
421
497
  };
422
498
 
423
- 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 };
499
+ export { type Attachment, 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, uploadFile, uploadFiles };
package/dist/index.d.ts CHANGED
@@ -65,6 +65,16 @@ 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
+ }
68
78
  interface Message {
69
79
  id: string;
70
80
  sessionId: string;
@@ -73,9 +83,12 @@ interface Message {
73
83
  timestamp: string;
74
84
  replyTo?: string;
75
85
  metadata?: Record<string, unknown>;
86
+ attachments?: Attachment[];
76
87
  status?: MessageStatus;
77
88
  deliveredAt?: string;
78
89
  readAt?: string;
90
+ editedAt?: string;
91
+ deletedAt?: string;
79
92
  }
80
93
  interface Session {
81
94
  sessionId: string;
@@ -171,6 +184,7 @@ declare class PocketPingClient {
171
184
  private config;
172
185
  private session;
173
186
  private ws;
187
+ private sse;
174
188
  private isOpen;
175
189
  private listeners;
176
190
  private customEventHandlers;
@@ -182,7 +196,7 @@ declare class PocketPingClient {
182
196
  private maxPollingFailures;
183
197
  private wsConnectedAt;
184
198
  private quickFailureThreshold;
185
- private usePollingFallback;
199
+ private connectionMode;
186
200
  private trackedElementCleanups;
187
201
  private currentTrackedElements;
188
202
  private inspectorMode;
@@ -190,10 +204,44 @@ declare class PocketPingClient {
190
204
  constructor(config: ResolvedPocketPingConfig);
191
205
  connect(): Promise<Session>;
192
206
  disconnect(): void;
193
- sendMessage(content: string): Promise<Message>;
207
+ sendMessage(content: string, attachmentIds?: string[], replyTo?: string): Promise<Message>;
208
+ /**
209
+ * Upload a file attachment
210
+ * Returns the attachment data after successful upload
211
+ * @param file - File object to upload
212
+ * @param onProgress - Optional callback for upload progress (0-100)
213
+ * @example
214
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
215
+ * console.log(`Upload ${progress}% complete`)
216
+ * })
217
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
218
+ */
219
+ uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
220
+ /**
221
+ * Upload multiple files at once
222
+ * @param files - Array of File objects to upload
223
+ * @param onProgress - Optional callback for overall progress (0-100)
224
+ * @returns Array of uploaded attachments
225
+ */
226
+ uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
227
+ /**
228
+ * Upload file to presigned URL with progress tracking
229
+ */
230
+ private uploadToPresignedUrl;
194
231
  fetchMessages(after?: string): Promise<Message[]>;
195
232
  sendTyping(isTyping?: boolean): Promise<void>;
196
233
  sendReadStatus(messageIds: string[], status: MessageStatus): Promise<void>;
234
+ /**
235
+ * Edit a message (visitor can only edit their own messages)
236
+ * @param messageId - ID of the message to edit
237
+ * @param content - New content for the message
238
+ */
239
+ editMessage(messageId: string, content: string): Promise<Message>;
240
+ /**
241
+ * Delete a message (soft delete - visitor can only delete their own messages)
242
+ * @param messageId - ID of the message to delete
243
+ */
244
+ deleteMessage(messageId: string): Promise<boolean>;
197
245
  getPresence(): Promise<PresenceResponse>;
198
246
  /**
199
247
  * Identify the current user with metadata
@@ -288,8 +336,11 @@ declare class PocketPingClient {
288
336
  * Check if inspector mode is active
289
337
  */
290
338
  isInspectorModeActive(): boolean;
339
+ private connectRealtime;
291
340
  private connectWebSocket;
341
+ private connectSSE;
292
342
  private handleWsFailure;
343
+ private handleRealtimeEvent;
293
344
  private handleWebSocketEvent;
294
345
  private handleVersionWarning;
295
346
  private scheduleReconnect;
@@ -311,7 +362,30 @@ declare function destroy(): void;
311
362
  declare function open(): void;
312
363
  declare function close(): void;
313
364
  declare function toggle(): void;
314
- declare function sendMessage(content: string): Promise<Message>;
365
+ declare function sendMessage(content: string, attachmentIds?: string[]): Promise<Message>;
366
+ /**
367
+ * Upload a file attachment
368
+ * Returns the attachment data after successful upload
369
+ * @param file - File object to upload
370
+ * @param onProgress - Optional callback for upload progress (0-100)
371
+ * @example
372
+ * const attachment = await PocketPing.uploadFile(file, (progress) => {
373
+ * console.log(`Upload ${progress}% complete`)
374
+ * })
375
+ * await PocketPing.sendMessage('Check this file', [attachment.id])
376
+ */
377
+ declare function uploadFile(file: File, onProgress?: (progress: number) => void): Promise<Attachment>;
378
+ /**
379
+ * Upload multiple files at once
380
+ * @param files - Array of File objects to upload
381
+ * @param onProgress - Optional callback for overall progress (0-100)
382
+ * @returns Array of uploaded attachments
383
+ * @example
384
+ * const attachments = await PocketPing.uploadFiles(files)
385
+ * const ids = attachments.map(a => a.id)
386
+ * await PocketPing.sendMessage('Here are the files', ids)
387
+ */
388
+ declare function uploadFiles(files: File[], onProgress?: (progress: number) => void): Promise<Attachment[]>;
315
389
  /**
316
390
  * Trigger a custom event to the backend
317
391
  * @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
@@ -409,6 +483,8 @@ declare const _default: {
409
483
  close: typeof close;
410
484
  toggle: typeof toggle;
411
485
  sendMessage: typeof sendMessage;
486
+ uploadFile: typeof uploadFile;
487
+ uploadFiles: typeof uploadFiles;
412
488
  trigger: typeof trigger;
413
489
  onEvent: typeof onEvent;
414
490
  offEvent: typeof offEvent;
@@ -420,4 +496,4 @@ declare const _default: {
420
496
  getTrackedElements: typeof getTrackedElements;
421
497
  };
422
498
 
423
- 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 };
499
+ export { type Attachment, 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, uploadFile, uploadFiles };