@pushflodev/sdk 1.0.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.
@@ -0,0 +1,102 @@
1
+ import { a as ConnectionInfo, M as Message, C as ClientOptions, b as ConnectionState, e as SubscriptionOptions, S as Subscription } from './message-CVgilLwz.js';
2
+
3
+ /**
4
+ * Type-safe event emitter with zero dependencies
5
+ */
6
+ type EventMap = {
7
+ [key: string]: unknown[];
8
+ };
9
+ type EventHandler<T extends unknown[]> = (...args: T) => void;
10
+ declare class TypedEventEmitter<Events extends EventMap> {
11
+ private listeners;
12
+ /**
13
+ * Register an event listener
14
+ */
15
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
16
+ /**
17
+ * Register a one-time event listener
18
+ */
19
+ once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
20
+ /**
21
+ * Remove an event listener
22
+ */
23
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
24
+ /**
25
+ * Emit an event to all registered listeners
26
+ */
27
+ protected emit<K extends keyof Events>(event: K, ...args: Events[K]): boolean;
28
+ /**
29
+ * Remove all listeners for an event, or all listeners if no event specified
30
+ */
31
+ removeAllListeners<K extends keyof Events>(event?: K): this;
32
+ /**
33
+ * Get the number of listeners for an event
34
+ */
35
+ listenerCount<K extends keyof Events>(event: K): number;
36
+ /**
37
+ * Get all event names with registered listeners
38
+ */
39
+ eventNames(): (keyof Events)[];
40
+ }
41
+
42
+ interface PushFloClientEvents {
43
+ [key: string]: unknown[];
44
+ connected: [ConnectionInfo];
45
+ disconnected: [reason?: string];
46
+ message: [Message];
47
+ error: [Error];
48
+ }
49
+ /**
50
+ * Browser client for PushFlo real-time messaging
51
+ */
52
+ declare class PushFloClient extends TypedEventEmitter<PushFloClientEvents> {
53
+ private readonly wsManager;
54
+ private readonly subscriptions;
55
+ private readonly logger;
56
+ private connectionChangeListeners;
57
+ constructor(options: ClientOptions);
58
+ /**
59
+ * Get current connection state
60
+ */
61
+ get connectionState(): ConnectionState;
62
+ /**
63
+ * Get client ID (available after connected)
64
+ */
65
+ get clientId(): string | null;
66
+ /**
67
+ * Connect to PushFlo
68
+ */
69
+ connect(): Promise<void>;
70
+ /**
71
+ * Disconnect from PushFlo
72
+ */
73
+ disconnect(): void;
74
+ /**
75
+ * Clean up all resources
76
+ */
77
+ destroy(): void;
78
+ /**
79
+ * Subscribe to a channel
80
+ */
81
+ subscribe(channel: string, options?: SubscriptionOptions): Subscription;
82
+ /**
83
+ * Unsubscribe from a channel
84
+ */
85
+ unsubscribe(channel: string): void;
86
+ /**
87
+ * Register a connection state change listener
88
+ */
89
+ onConnectionChange(listener: (state: ConnectionState) => void): () => void;
90
+ /**
91
+ * Get list of subscribed channels
92
+ */
93
+ getSubscribedChannels(): string[];
94
+ /**
95
+ * Check if subscribed to a channel
96
+ */
97
+ isSubscribed(channel: string): boolean;
98
+ private setupEventHandlers;
99
+ private handleServerMessage;
100
+ }
101
+
102
+ export { PushFloClient as P };
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Base error class for all PushFlo SDK errors
3
+ */
4
+ declare class PushFloError extends Error {
5
+ /** Error code for programmatic handling */
6
+ readonly code: string;
7
+ /** Whether this error is potentially recoverable through retry */
8
+ readonly retryable: boolean;
9
+ /** Original error that caused this error, if any */
10
+ readonly cause?: Error;
11
+ constructor(message: string, code: string, options?: {
12
+ retryable?: boolean;
13
+ cause?: Error;
14
+ });
15
+ /**
16
+ * Convert error to JSON-serializable object
17
+ */
18
+ toJSON(): Record<string, unknown>;
19
+ /**
20
+ * Create a string representation
21
+ */
22
+ toString(): string;
23
+ }
24
+
25
+ /**
26
+ * Error thrown when authentication fails
27
+ */
28
+ declare class AuthenticationError extends PushFloError {
29
+ constructor(message: string, code?: string, options?: {
30
+ retryable?: boolean;
31
+ cause?: Error;
32
+ });
33
+ /**
34
+ * Create an invalid API key error
35
+ */
36
+ static invalidKey(keyType?: string): AuthenticationError;
37
+ /**
38
+ * Create an unauthorized error
39
+ */
40
+ static unauthorized(reason?: string): AuthenticationError;
41
+ /**
42
+ * Create a forbidden error
43
+ */
44
+ static forbidden(action?: string): AuthenticationError;
45
+ }
46
+
47
+ /**
48
+ * Error thrown for network-related failures
49
+ */
50
+ declare class NetworkError extends PushFloError {
51
+ /** HTTP status code, if applicable */
52
+ readonly statusCode?: number;
53
+ constructor(message: string, code?: string, options?: {
54
+ retryable?: boolean;
55
+ cause?: Error;
56
+ statusCode?: number;
57
+ });
58
+ /**
59
+ * Create a network error from fetch failure
60
+ */
61
+ static fromFetch(cause: Error): NetworkError;
62
+ /**
63
+ * Create a request timeout error
64
+ */
65
+ static timeout(timeoutMs: number): NetworkError;
66
+ /**
67
+ * Create an error from HTTP status code
68
+ */
69
+ static fromStatus(statusCode: number, message?: string): NetworkError;
70
+ private static getStatusMessage;
71
+ toJSON(): Record<string, unknown>;
72
+ }
73
+
74
+ /**
75
+ * A PushFlo channel
76
+ */
77
+ interface Channel {
78
+ /** Unique channel ID */
79
+ id: string;
80
+ /** Human-readable channel name */
81
+ name: string;
82
+ /** URL-safe channel identifier (used for subscriptions) */
83
+ slug: string;
84
+ /** Optional channel description */
85
+ description: string | null;
86
+ /** Whether the channel requires authentication */
87
+ isPrivate: boolean;
88
+ /** Custom metadata attached to the channel */
89
+ metadata: Record<string, unknown> | null;
90
+ /** Total number of messages in the channel */
91
+ messageCount: number;
92
+ /** ISO 8601 timestamp of creation */
93
+ createdAt: string;
94
+ /** ISO 8601 timestamp of last update */
95
+ updatedAt: string;
96
+ }
97
+ /**
98
+ * Input for creating a new channel
99
+ */
100
+ interface ChannelInput {
101
+ /** Human-readable channel name */
102
+ name: string;
103
+ /** URL-safe channel identifier */
104
+ slug: string;
105
+ /** Optional channel description */
106
+ description?: string;
107
+ /** Whether the channel requires authentication */
108
+ isPrivate?: boolean;
109
+ /** Custom metadata to attach to the channel */
110
+ metadata?: Record<string, unknown>;
111
+ }
112
+ /**
113
+ * Input for updating an existing channel
114
+ */
115
+ interface ChannelUpdateInput {
116
+ /** Human-readable channel name */
117
+ name?: string;
118
+ /** Optional channel description */
119
+ description?: string | null;
120
+ /** Whether the channel requires authentication */
121
+ isPrivate?: boolean;
122
+ /** Custom metadata to attach to the channel */
123
+ metadata?: Record<string, unknown> | null;
124
+ }
125
+ /**
126
+ * Options for listing channels
127
+ */
128
+ interface ListChannelsOptions {
129
+ /** Page number (1-indexed) */
130
+ page?: number;
131
+ /** Number of items per page */
132
+ pageSize?: number;
133
+ }
134
+
135
+ /**
136
+ * Pagination metadata for list responses
137
+ */
138
+ interface Pagination {
139
+ /** Current page number (1-indexed) */
140
+ page: number;
141
+ /** Number of items per page */
142
+ pageSize: number;
143
+ /** Total number of items */
144
+ total: number;
145
+ /** Total number of pages */
146
+ totalPages: number;
147
+ }
148
+
149
+ export { AuthenticationError as A, type Channel as C, type ListChannelsOptions as L, NetworkError as N, PushFloError as P, type ChannelInput as a, type ChannelUpdateInput as b, type Pagination as c };
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Base error class for all PushFlo SDK errors
3
+ */
4
+ declare class PushFloError extends Error {
5
+ /** Error code for programmatic handling */
6
+ readonly code: string;
7
+ /** Whether this error is potentially recoverable through retry */
8
+ readonly retryable: boolean;
9
+ /** Original error that caused this error, if any */
10
+ readonly cause?: Error;
11
+ constructor(message: string, code: string, options?: {
12
+ retryable?: boolean;
13
+ cause?: Error;
14
+ });
15
+ /**
16
+ * Convert error to JSON-serializable object
17
+ */
18
+ toJSON(): Record<string, unknown>;
19
+ /**
20
+ * Create a string representation
21
+ */
22
+ toString(): string;
23
+ }
24
+
25
+ /**
26
+ * Error thrown when authentication fails
27
+ */
28
+ declare class AuthenticationError extends PushFloError {
29
+ constructor(message: string, code?: string, options?: {
30
+ retryable?: boolean;
31
+ cause?: Error;
32
+ });
33
+ /**
34
+ * Create an invalid API key error
35
+ */
36
+ static invalidKey(keyType?: string): AuthenticationError;
37
+ /**
38
+ * Create an unauthorized error
39
+ */
40
+ static unauthorized(reason?: string): AuthenticationError;
41
+ /**
42
+ * Create a forbidden error
43
+ */
44
+ static forbidden(action?: string): AuthenticationError;
45
+ }
46
+
47
+ /**
48
+ * Error thrown for network-related failures
49
+ */
50
+ declare class NetworkError extends PushFloError {
51
+ /** HTTP status code, if applicable */
52
+ readonly statusCode?: number;
53
+ constructor(message: string, code?: string, options?: {
54
+ retryable?: boolean;
55
+ cause?: Error;
56
+ statusCode?: number;
57
+ });
58
+ /**
59
+ * Create a network error from fetch failure
60
+ */
61
+ static fromFetch(cause: Error): NetworkError;
62
+ /**
63
+ * Create a request timeout error
64
+ */
65
+ static timeout(timeoutMs: number): NetworkError;
66
+ /**
67
+ * Create an error from HTTP status code
68
+ */
69
+ static fromStatus(statusCode: number, message?: string): NetworkError;
70
+ private static getStatusMessage;
71
+ toJSON(): Record<string, unknown>;
72
+ }
73
+
74
+ /**
75
+ * A PushFlo channel
76
+ */
77
+ interface Channel {
78
+ /** Unique channel ID */
79
+ id: string;
80
+ /** Human-readable channel name */
81
+ name: string;
82
+ /** URL-safe channel identifier (used for subscriptions) */
83
+ slug: string;
84
+ /** Optional channel description */
85
+ description: string | null;
86
+ /** Whether the channel requires authentication */
87
+ isPrivate: boolean;
88
+ /** Custom metadata attached to the channel */
89
+ metadata: Record<string, unknown> | null;
90
+ /** Total number of messages in the channel */
91
+ messageCount: number;
92
+ /** ISO 8601 timestamp of creation */
93
+ createdAt: string;
94
+ /** ISO 8601 timestamp of last update */
95
+ updatedAt: string;
96
+ }
97
+ /**
98
+ * Input for creating a new channel
99
+ */
100
+ interface ChannelInput {
101
+ /** Human-readable channel name */
102
+ name: string;
103
+ /** URL-safe channel identifier */
104
+ slug: string;
105
+ /** Optional channel description */
106
+ description?: string;
107
+ /** Whether the channel requires authentication */
108
+ isPrivate?: boolean;
109
+ /** Custom metadata to attach to the channel */
110
+ metadata?: Record<string, unknown>;
111
+ }
112
+ /**
113
+ * Input for updating an existing channel
114
+ */
115
+ interface ChannelUpdateInput {
116
+ /** Human-readable channel name */
117
+ name?: string;
118
+ /** Optional channel description */
119
+ description?: string | null;
120
+ /** Whether the channel requires authentication */
121
+ isPrivate?: boolean;
122
+ /** Custom metadata to attach to the channel */
123
+ metadata?: Record<string, unknown> | null;
124
+ }
125
+ /**
126
+ * Options for listing channels
127
+ */
128
+ interface ListChannelsOptions {
129
+ /** Page number (1-indexed) */
130
+ page?: number;
131
+ /** Number of items per page */
132
+ pageSize?: number;
133
+ }
134
+
135
+ /**
136
+ * Pagination metadata for list responses
137
+ */
138
+ interface Pagination {
139
+ /** Current page number (1-indexed) */
140
+ page: number;
141
+ /** Number of items per page */
142
+ pageSize: number;
143
+ /** Total number of items */
144
+ total: number;
145
+ /** Total number of pages */
146
+ totalPages: number;
147
+ }
148
+
149
+ export { AuthenticationError as A, type Channel as C, type ListChannelsOptions as L, NetworkError as N, PushFloError as P, type ChannelInput as a, type ChannelUpdateInput as b, type Pagination as c };