@docuninja/builder2.0 0.0.88 → 0.0.89

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.
@@ -131,3 +131,5 @@ export * as BuilderTypes from '../types/api';
131
131
  export type { Rectangle } from '../../builder/index';
132
132
  export * from '../pdf-worker';
133
133
  export * from '../password-files';
134
+ export * from '../websocket-manager';
135
+ export * from './websockets';
@@ -11,7 +11,7 @@ type Props = {
11
11
  * 3. Manages component lifecycle (connect/disconnect on mount/unmount)
12
12
  */
13
13
  export declare function WebSockets({ children, context }: Props): import("@emotion/react/jsx-runtime").JSX.Element | null;
14
- export declare const events: readonly ["App\\Events\\DocumentFile\\DocumentFilePreviewGenerated"];
14
+ export declare const events: readonly ["App\\Events\\DocumentFile\\DocumentFilePreviewGenerated", "App\\Events\\Document\\DocumentWasSigned"];
15
15
  export type Event = (typeof events)[number];
16
16
  export type Callbacks = Record<Event, (data: unknown) => unknown>;
17
17
  export type UsePrivateSocketEventsProps = {
@@ -35,4 +35,13 @@ export interface GenericMessage {
35
35
  message: string;
36
36
  link: string | null;
37
37
  }
38
+ export type UseWebSocketSubscriptionProps = {
39
+ events: Event[] | string[];
40
+ onEvent: (eventName: Event | string, data: unknown) => void;
41
+ token: string;
42
+ companyId: string;
43
+ endpoint: string;
44
+ context?: "builder" | "sign";
45
+ };
46
+ export declare function useWebSocketSubscription({ events, onEvent, token, companyId, endpoint, context, }: UseWebSocketSubscriptionProps): void;
38
47
  export {};
package/dist/builder.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Axios } from 'axios';
2
2
  import { Context } from 'react';
3
+ import { default as default_2 } from 'pusher-js';
3
4
  import { FieldValues } from 'react-hook-form';
4
5
  import { JSX as JSX_2 } from '@emotion/react/jsx-runtime';
5
6
  import * as lib from 'pdfjs-dist';
@@ -207,6 +208,13 @@ export declare namespace BuilderTypes {
207
208
  }
208
209
  }
209
210
 
211
+ export declare interface CallbackOptions<T> {
212
+ event: Event_2;
213
+ data: T;
214
+ }
215
+
216
+ export declare type Callbacks = Record<Event_2, (data: unknown) => unknown>;
217
+
210
218
  declare type CheckboxOperator = "checked" | "unchecked";
211
219
 
212
220
  export declare function checkPdfPassword(file: File, password: string): Promise<boolean>;
@@ -323,6 +331,14 @@ export declare type ConfirmationDialogProps = {
323
331
  action: React.ReactNode;
324
332
  };
325
333
 
334
+ export declare type ConnectionConfig = {
335
+ context: "builder" | "sign";
336
+ token: string;
337
+ endpoint?: string;
338
+ onConnected?: () => void;
339
+ onError?: (error: PusherError) => void;
340
+ };
341
+
326
342
  export declare type ConsentContinueButtonProps = {
327
343
  onClick: () => void;
328
344
  disabled: boolean;
@@ -517,6 +533,11 @@ export declare enum DocumentStatus {
517
533
  Voided = 8
518
534
  }
519
535
 
536
+ declare type Event_2 = (typeof events)[number];
537
+ export { Event_2 as Event }
538
+
539
+ export declare const events: readonly ["App\\Events\\DocumentFile\\DocumentFilePreviewGenerated", "App\\Events\\Document\\DocumentWasSigned"];
540
+
520
541
  export declare interface GenericManyResponse<T> {
521
542
  data: T[];
522
543
  links: {
@@ -541,12 +562,19 @@ export declare interface GenericManyResponse<T> {
541
562
  };
542
563
  }
543
564
 
565
+ export declare interface GenericMessage {
566
+ message: string;
567
+ link: string | null;
568
+ }
569
+
544
570
  export declare interface GenericSingleResponse<T> {
545
571
  data: T;
546
572
  }
547
573
 
548
574
  export declare function getPasswordForPdf(file: File): Promise<string | null>;
549
575
 
576
+ export declare const getWebSocketManager: () => WebSocketManager;
577
+
550
578
  export declare type ImportFromButtonProps = {
551
579
  onClick: () => void;
552
580
  isSubmitting: boolean;
@@ -595,6 +623,21 @@ export declare interface Plan {
595
623
  highlighted_features: string[];
596
624
  }
597
625
 
626
+ declare type Props = {
627
+ children: React.ReactNode;
628
+ context: "builder" | "sign";
629
+ };
630
+
631
+ declare type PusherError = {
632
+ error?: {
633
+ type: string;
634
+ data: {
635
+ code?: number;
636
+ message?: string;
637
+ };
638
+ };
639
+ };
640
+
598
641
  /** Hey there, you! So you want to add a prop onto this interface huh? No probs, but PLEASE notify upstream that this interface has changed so we can update the types in all repos :) */
599
642
  export declare type Rectangle = {
600
643
  id: string;
@@ -872,6 +915,13 @@ declare type SingleCondition = {
872
915
  value?: string | number | string[];
873
916
  };
874
917
 
918
+ export declare interface SocketEventProps<T> {
919
+ on: Event_2 | Event_2[];
920
+ callback: (options: CallbackOptions<T>) => unknown;
921
+ }
922
+
923
+ export declare function socketId(): number | null;
924
+
875
925
  export declare type StartSigningButtonProps = {
876
926
  onClick: () => void;
877
927
  };
@@ -958,6 +1008,12 @@ export declare function useOptionalSignContextPlus(): (Sign & {
958
1008
  http: Axios;
959
1009
  }) | null;
960
1010
 
1011
+ export declare function usePrivateSocketEvents({ context, }: UsePrivateSocketEventsProps): null;
1012
+
1013
+ export declare type UsePrivateSocketEventsProps = {
1014
+ context: "builder" | "sign";
1015
+ };
1016
+
961
1017
  export declare interface User {
962
1018
  id: string;
963
1019
  account_id: string | null;
@@ -990,6 +1046,19 @@ export declare function useSignContextPlus(): Sign & {
990
1046
  http: Axios;
991
1047
  };
992
1048
 
1049
+ export declare function useSocketEvent<T>({ on, callback }: SocketEventProps<T>): void;
1050
+
1051
+ export declare function useWebSocketSubscription({ events, onEvent, token, companyId, endpoint, context, }: UseWebSocketSubscriptionProps): void;
1052
+
1053
+ export declare type UseWebSocketSubscriptionProps = {
1054
+ events: Event_2[] | string[];
1055
+ onEvent: (eventName: Event_2 | string, data: unknown) => void;
1056
+ token: string;
1057
+ companyId: string;
1058
+ endpoint: string;
1059
+ context?: "builder" | "sign";
1060
+ };
1061
+
993
1062
  export declare interface ValidationBag {
994
1063
  message: string;
995
1064
  errors: Record<string, string[]>;
@@ -1001,9 +1070,81 @@ export declare type ValidationErrorsProps = {
1001
1070
 
1002
1071
  declare type ValidationRule = "none" | "length" | "ssn" | "ein" | "email" | "url" | "zip" | "numbers_only" | "letters_only" | "custom";
1003
1072
 
1073
+ /**
1074
+ * Singleton WebSocket Manager
1075
+ *
1076
+ * Ensures only one Pusher connection exists across the entire application.
1077
+ * Manages connections for both "builder" and "sign" contexts.
1078
+ *
1079
+ * Handles React StrictMode double-mounting by checking connection state before creating new instances.
1080
+ */
1081
+ declare class WebSocketManager {
1082
+ private static instance;
1083
+ private pusher;
1084
+ private activeContexts;
1085
+ private connectionConfig;
1086
+ private isConnecting;
1087
+ private readonly pusherKey;
1088
+ private readonly pusherUrl;
1089
+ private constructor();
1090
+ /**
1091
+ * Get the singleton instance
1092
+ */
1093
+ static getInstance(): WebSocketManager;
1094
+ /**
1095
+ * Connect to Pusher for a specific context
1096
+ *
1097
+ * This method is idempotent - calling it multiple times will reuse the existing connection.
1098
+ * Prevents race conditions from StrictMode double-mounting or rapid successive calls.
1099
+ */
1100
+ connect(config: ConnectionConfig): default_2;
1101
+ /**
1102
+ * Create a new Pusher connection
1103
+ */
1104
+ private createPusherConnection;
1105
+ /**
1106
+ * Disconnect from Pusher
1107
+ */
1108
+ disconnect(): void;
1109
+ /**
1110
+ * Get the current Pusher instance
1111
+ */
1112
+ getPusher(): default_2 | null;
1113
+ /**
1114
+ * Check if connected
1115
+ */
1116
+ isConnected(): boolean;
1117
+ /**
1118
+ * Remove a context from active contexts (for feedback/debugging only)
1119
+ *
1120
+ * NOTE: This method no longer disconnects the connection.
1121
+ * The singleton connection should persist across navigation.
1122
+ * Use disconnect() explicitly if you need to close the connection.
1123
+ */
1124
+ removeContext(context: "builder" | "sign"): void;
1125
+ /**
1126
+ * Update connection configuration (e.g., when token changes)
1127
+ */
1128
+ updateConnection(config: Partial<ConnectionConfig>): void;
1129
+ }
1130
+
1131
+ /**
1132
+ * WebSockets Component (Refactored to use Singleton Manager)
1133
+ *
1134
+ * This component now acts as a thin wrapper that:
1135
+ * 1. Initializes the singleton WebSocket manager
1136
+ * 2. Updates the Zustand store with the connection instance
1137
+ * 3. Manages component lifecycle (connect/disconnect on mount/unmount)
1138
+ */
1139
+ export declare function WebSockets({ children, context }: Props): JSX_2.Element | null;
1140
+
1004
1141
  export declare type WithSignerToken<T> = T & {
1005
1142
  "X-Signer-Token": string;
1006
1143
  "X-Signer-Token-Expires": string;
1007
1144
  };
1008
1145
 
1146
+ export declare type WithSocketId<T> = T & {
1147
+ "x-socket-id": string;
1148
+ };
1149
+
1009
1150
  export { }