@bridgecord/sdk 1.0.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.
@@ -0,0 +1,263 @@
1
+ interface BridgecordOptions {
2
+ /** The embed ID from your Bridgecord dashboard. */
3
+ embedId: string;
4
+ /** Optional session token for pre-authenticated users. */
5
+ sessionToken?: string;
6
+ /**
7
+ * Guest display name. When provided, the SDK will automatically authenticate
8
+ * as a guest with this name, skipping the welcome/auth screen.
9
+ */
10
+ displayName?: string;
11
+ /** Base URL of the Bridgecord API. Defaults to https://api.bridgecord.io */
12
+ apiUrl?: string;
13
+ /** Base URL of the Bridgecord embed app. Defaults to https://embed.bridgecord.io */
14
+ embedUrl?: string;
15
+ }
16
+ interface ConnectOptions {
17
+ /** The embed ID from your Bridgecord dashboard. */
18
+ embedId: string;
19
+ /** Optional session token for pre-authenticated users. */
20
+ sessionToken?: string;
21
+ /**
22
+ * Guest display name. When provided, the SDK will automatically authenticate
23
+ * as a guest with this name, skipping the welcome/auth screen.
24
+ */
25
+ displayName?: string;
26
+ /** Base URL of the Bridgecord API. Defaults to https://api.bridgecord.io */
27
+ apiUrl?: string;
28
+ }
29
+ interface BridgecordAuthor {
30
+ id: string;
31
+ username: string;
32
+ avatar: string | null;
33
+ roles: BridgecordRole[];
34
+ }
35
+ interface BridgecordRole {
36
+ id: string;
37
+ name: string;
38
+ color: number;
39
+ position: number;
40
+ }
41
+ interface BridgecordMessage {
42
+ id: string;
43
+ channelId: string;
44
+ serverId: string;
45
+ author: BridgecordAuthor;
46
+ content: string;
47
+ timestamp: string;
48
+ attachments: BridgecordAttachment[];
49
+ embeds: BridgecordEmbed[];
50
+ }
51
+ interface BridgecordAttachment {
52
+ id: string;
53
+ filename: string;
54
+ url: string;
55
+ contentType: string | null;
56
+ size: number;
57
+ }
58
+ interface BridgecordEmbed {
59
+ title?: string;
60
+ description?: string;
61
+ url?: string;
62
+ color?: number;
63
+ thumbnail?: {
64
+ url: string;
65
+ width?: number;
66
+ height?: number;
67
+ };
68
+ image?: {
69
+ url: string;
70
+ width?: number;
71
+ height?: number;
72
+ };
73
+ author?: {
74
+ name: string;
75
+ url?: string;
76
+ iconUrl?: string;
77
+ };
78
+ fields?: {
79
+ name: string;
80
+ value: string;
81
+ inline?: boolean;
82
+ }[];
83
+ }
84
+ interface BridgecordUser {
85
+ id: string;
86
+ type: "discord" | "guest";
87
+ displayName: string;
88
+ avatarUrl: string | null;
89
+ discordUserId?: string;
90
+ }
91
+ interface BridgecordChannel {
92
+ id: string;
93
+ name: string;
94
+ position: number;
95
+ locked: boolean;
96
+ pricingTier?: {
97
+ id: string;
98
+ name: string;
99
+ priceMonthly: number;
100
+ } | null;
101
+ }
102
+ interface BridgecordRewardProfile {
103
+ userId: string;
104
+ points: number;
105
+ level: number;
106
+ totalMessages: number;
107
+ currentStreak: number;
108
+ longestStreak: number;
109
+ badges: {
110
+ id: string;
111
+ name: string;
112
+ description: string;
113
+ iconUrl: string | null;
114
+ earnedAt: string;
115
+ }[];
116
+ rank: number;
117
+ }
118
+ interface BridgecordLeaderboardEntry {
119
+ userId: string;
120
+ displayName: string;
121
+ avatarUrl: string | null;
122
+ points: number;
123
+ level: number;
124
+ rank: number;
125
+ }
126
+ interface BridgecordEmbedConfig {
127
+ id: string;
128
+ serverId: string;
129
+ name: string;
130
+ authMode: "PUBLIC" | "DISCORD_OAUTH" | "API_AUTH" | "VIEW_ONLY";
131
+ enabled: boolean;
132
+ channels: BridgecordChannel[];
133
+ theme: BridgecordTheme | null;
134
+ }
135
+ interface BridgecordTheme {
136
+ primary: string;
137
+ background: string;
138
+ surface: string;
139
+ text: string;
140
+ textSecondary: string;
141
+ font: string;
142
+ }
143
+ interface BridgecordEventMap {
144
+ message: BridgecordMessage;
145
+ "messages:initial": BridgecordMessage[];
146
+ auth: BridgecordUser;
147
+ reward: BridgecordRewardEvent;
148
+ ready: undefined;
149
+ error: Error;
150
+ "channel:changed": BridgecordChannel;
151
+ }
152
+ interface BridgecordRewardEvent {
153
+ pointsEarned: number;
154
+ newTotal: number;
155
+ levelUp: boolean;
156
+ newLevel: number;
157
+ badgesEarned: {
158
+ id: string;
159
+ name: string;
160
+ description: string;
161
+ iconUrl: string | null;
162
+ }[];
163
+ streakUpdated: boolean;
164
+ currentStreak: number;
165
+ }
166
+ interface BridgecordConnection {
167
+ /** Current embed configuration. */
168
+ config: BridgecordEmbedConfig;
169
+ /** Currently connected channel ID. */
170
+ currentChannel: string | null;
171
+ /** Join a channel to receive messages. */
172
+ joinChannel(channelId: string): void;
173
+ /** Leave the current channel. */
174
+ leaveChannel(): void;
175
+ /** Send a message to the current channel. */
176
+ sendMessage(content: string): Promise<BridgecordMessage>;
177
+ /** Subscribe to events. */
178
+ on<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
179
+ /** Unsubscribe from events. */
180
+ off<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
181
+ /** Fetch user's reward profile. */
182
+ fetchRewards(): Promise<BridgecordRewardProfile>;
183
+ /** Fetch leaderboard. */
184
+ fetchLeaderboard(limit?: number, offset?: number): Promise<{
185
+ entries: BridgecordLeaderboardEntry[];
186
+ total: number;
187
+ }>;
188
+ /** Disconnect and clean up. */
189
+ destroy(): void;
190
+ }
191
+
192
+ /**
193
+ * Framework-agnostic Bridgecord SDK.
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * const bc = new Bridgecord({ embedId: 'abc123' });
198
+ * bc.mount(document.getElementById('chat'));
199
+ * bc.on('message', (msg) => console.log(msg));
200
+ * // later...
201
+ * bc.destroy();
202
+ * ```
203
+ */
204
+ declare class Bridgecord {
205
+ private readonly embedId;
206
+ private sessionToken?;
207
+ private readonly displayName?;
208
+ private readonly apiUrl;
209
+ private readonly embedUrl;
210
+ private iframe;
211
+ private container;
212
+ private listeners;
213
+ private messageHandler;
214
+ constructor(options: BridgecordOptions);
215
+ /**
216
+ * Authenticate as a guest with the configured displayName.
217
+ * Called automatically by mount() if displayName is set and no sessionToken exists.
218
+ * Returns the session token.
219
+ */
220
+ authenticateGuest(displayName?: string): Promise<string>;
221
+ /**
222
+ * Mount the Bridgecord embed into a container element.
223
+ * Creates an iframe pointing to the embed app.
224
+ *
225
+ * If `displayName` was provided in the constructor and no `sessionToken` exists,
226
+ * the SDK will first authenticate as a guest, then mount the iframe with the session.
227
+ */
228
+ mount(container: HTMLElement, options?: {
229
+ height?: number;
230
+ className?: string;
231
+ }): Promise<void>;
232
+ /**
233
+ * Subscribe to Bridgecord events.
234
+ */
235
+ on<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
236
+ /**
237
+ * Unsubscribe from Bridgecord events.
238
+ */
239
+ off<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
240
+ /**
241
+ * Destroy the embed and clean up all resources.
242
+ */
243
+ destroy(): void;
244
+ /**
245
+ * Open a direct Socket.io connection (no iframe).
246
+ * For developers who want complete rendering control.
247
+ */
248
+ static connect(options: ConnectOptions): Promise<BridgecordConnection>;
249
+ private buildIframeUrl;
250
+ private buildIframeUrlWithView;
251
+ /**
252
+ * Mount a single-channel chat view.
253
+ */
254
+ mountChat(container: HTMLElement, options?: {
255
+ channelId?: string;
256
+ height?: number;
257
+ className?: string;
258
+ }): void;
259
+ private handleIframeMessage;
260
+ private emit;
261
+ }
262
+
263
+ export { Bridgecord, type BridgecordAttachment, type BridgecordAuthor, type BridgecordChannel, type BridgecordConnection, type BridgecordEmbed, type BridgecordEmbedConfig, type BridgecordEventMap, type BridgecordLeaderboardEntry, type BridgecordMessage, type BridgecordOptions, type BridgecordRewardEvent, type BridgecordRewardProfile, type BridgecordRole, type BridgecordTheme, type BridgecordUser, type ConnectOptions };
@@ -0,0 +1,263 @@
1
+ interface BridgecordOptions {
2
+ /** The embed ID from your Bridgecord dashboard. */
3
+ embedId: string;
4
+ /** Optional session token for pre-authenticated users. */
5
+ sessionToken?: string;
6
+ /**
7
+ * Guest display name. When provided, the SDK will automatically authenticate
8
+ * as a guest with this name, skipping the welcome/auth screen.
9
+ */
10
+ displayName?: string;
11
+ /** Base URL of the Bridgecord API. Defaults to https://api.bridgecord.io */
12
+ apiUrl?: string;
13
+ /** Base URL of the Bridgecord embed app. Defaults to https://embed.bridgecord.io */
14
+ embedUrl?: string;
15
+ }
16
+ interface ConnectOptions {
17
+ /** The embed ID from your Bridgecord dashboard. */
18
+ embedId: string;
19
+ /** Optional session token for pre-authenticated users. */
20
+ sessionToken?: string;
21
+ /**
22
+ * Guest display name. When provided, the SDK will automatically authenticate
23
+ * as a guest with this name, skipping the welcome/auth screen.
24
+ */
25
+ displayName?: string;
26
+ /** Base URL of the Bridgecord API. Defaults to https://api.bridgecord.io */
27
+ apiUrl?: string;
28
+ }
29
+ interface BridgecordAuthor {
30
+ id: string;
31
+ username: string;
32
+ avatar: string | null;
33
+ roles: BridgecordRole[];
34
+ }
35
+ interface BridgecordRole {
36
+ id: string;
37
+ name: string;
38
+ color: number;
39
+ position: number;
40
+ }
41
+ interface BridgecordMessage {
42
+ id: string;
43
+ channelId: string;
44
+ serverId: string;
45
+ author: BridgecordAuthor;
46
+ content: string;
47
+ timestamp: string;
48
+ attachments: BridgecordAttachment[];
49
+ embeds: BridgecordEmbed[];
50
+ }
51
+ interface BridgecordAttachment {
52
+ id: string;
53
+ filename: string;
54
+ url: string;
55
+ contentType: string | null;
56
+ size: number;
57
+ }
58
+ interface BridgecordEmbed {
59
+ title?: string;
60
+ description?: string;
61
+ url?: string;
62
+ color?: number;
63
+ thumbnail?: {
64
+ url: string;
65
+ width?: number;
66
+ height?: number;
67
+ };
68
+ image?: {
69
+ url: string;
70
+ width?: number;
71
+ height?: number;
72
+ };
73
+ author?: {
74
+ name: string;
75
+ url?: string;
76
+ iconUrl?: string;
77
+ };
78
+ fields?: {
79
+ name: string;
80
+ value: string;
81
+ inline?: boolean;
82
+ }[];
83
+ }
84
+ interface BridgecordUser {
85
+ id: string;
86
+ type: "discord" | "guest";
87
+ displayName: string;
88
+ avatarUrl: string | null;
89
+ discordUserId?: string;
90
+ }
91
+ interface BridgecordChannel {
92
+ id: string;
93
+ name: string;
94
+ position: number;
95
+ locked: boolean;
96
+ pricingTier?: {
97
+ id: string;
98
+ name: string;
99
+ priceMonthly: number;
100
+ } | null;
101
+ }
102
+ interface BridgecordRewardProfile {
103
+ userId: string;
104
+ points: number;
105
+ level: number;
106
+ totalMessages: number;
107
+ currentStreak: number;
108
+ longestStreak: number;
109
+ badges: {
110
+ id: string;
111
+ name: string;
112
+ description: string;
113
+ iconUrl: string | null;
114
+ earnedAt: string;
115
+ }[];
116
+ rank: number;
117
+ }
118
+ interface BridgecordLeaderboardEntry {
119
+ userId: string;
120
+ displayName: string;
121
+ avatarUrl: string | null;
122
+ points: number;
123
+ level: number;
124
+ rank: number;
125
+ }
126
+ interface BridgecordEmbedConfig {
127
+ id: string;
128
+ serverId: string;
129
+ name: string;
130
+ authMode: "PUBLIC" | "DISCORD_OAUTH" | "API_AUTH" | "VIEW_ONLY";
131
+ enabled: boolean;
132
+ channels: BridgecordChannel[];
133
+ theme: BridgecordTheme | null;
134
+ }
135
+ interface BridgecordTheme {
136
+ primary: string;
137
+ background: string;
138
+ surface: string;
139
+ text: string;
140
+ textSecondary: string;
141
+ font: string;
142
+ }
143
+ interface BridgecordEventMap {
144
+ message: BridgecordMessage;
145
+ "messages:initial": BridgecordMessage[];
146
+ auth: BridgecordUser;
147
+ reward: BridgecordRewardEvent;
148
+ ready: undefined;
149
+ error: Error;
150
+ "channel:changed": BridgecordChannel;
151
+ }
152
+ interface BridgecordRewardEvent {
153
+ pointsEarned: number;
154
+ newTotal: number;
155
+ levelUp: boolean;
156
+ newLevel: number;
157
+ badgesEarned: {
158
+ id: string;
159
+ name: string;
160
+ description: string;
161
+ iconUrl: string | null;
162
+ }[];
163
+ streakUpdated: boolean;
164
+ currentStreak: number;
165
+ }
166
+ interface BridgecordConnection {
167
+ /** Current embed configuration. */
168
+ config: BridgecordEmbedConfig;
169
+ /** Currently connected channel ID. */
170
+ currentChannel: string | null;
171
+ /** Join a channel to receive messages. */
172
+ joinChannel(channelId: string): void;
173
+ /** Leave the current channel. */
174
+ leaveChannel(): void;
175
+ /** Send a message to the current channel. */
176
+ sendMessage(content: string): Promise<BridgecordMessage>;
177
+ /** Subscribe to events. */
178
+ on<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
179
+ /** Unsubscribe from events. */
180
+ off<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
181
+ /** Fetch user's reward profile. */
182
+ fetchRewards(): Promise<BridgecordRewardProfile>;
183
+ /** Fetch leaderboard. */
184
+ fetchLeaderboard(limit?: number, offset?: number): Promise<{
185
+ entries: BridgecordLeaderboardEntry[];
186
+ total: number;
187
+ }>;
188
+ /** Disconnect and clean up. */
189
+ destroy(): void;
190
+ }
191
+
192
+ /**
193
+ * Framework-agnostic Bridgecord SDK.
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * const bc = new Bridgecord({ embedId: 'abc123' });
198
+ * bc.mount(document.getElementById('chat'));
199
+ * bc.on('message', (msg) => console.log(msg));
200
+ * // later...
201
+ * bc.destroy();
202
+ * ```
203
+ */
204
+ declare class Bridgecord {
205
+ private readonly embedId;
206
+ private sessionToken?;
207
+ private readonly displayName?;
208
+ private readonly apiUrl;
209
+ private readonly embedUrl;
210
+ private iframe;
211
+ private container;
212
+ private listeners;
213
+ private messageHandler;
214
+ constructor(options: BridgecordOptions);
215
+ /**
216
+ * Authenticate as a guest with the configured displayName.
217
+ * Called automatically by mount() if displayName is set and no sessionToken exists.
218
+ * Returns the session token.
219
+ */
220
+ authenticateGuest(displayName?: string): Promise<string>;
221
+ /**
222
+ * Mount the Bridgecord embed into a container element.
223
+ * Creates an iframe pointing to the embed app.
224
+ *
225
+ * If `displayName` was provided in the constructor and no `sessionToken` exists,
226
+ * the SDK will first authenticate as a guest, then mount the iframe with the session.
227
+ */
228
+ mount(container: HTMLElement, options?: {
229
+ height?: number;
230
+ className?: string;
231
+ }): Promise<void>;
232
+ /**
233
+ * Subscribe to Bridgecord events.
234
+ */
235
+ on<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
236
+ /**
237
+ * Unsubscribe from Bridgecord events.
238
+ */
239
+ off<K extends keyof BridgecordEventMap>(event: K, handler: (data: BridgecordEventMap[K]) => void): void;
240
+ /**
241
+ * Destroy the embed and clean up all resources.
242
+ */
243
+ destroy(): void;
244
+ /**
245
+ * Open a direct Socket.io connection (no iframe).
246
+ * For developers who want complete rendering control.
247
+ */
248
+ static connect(options: ConnectOptions): Promise<BridgecordConnection>;
249
+ private buildIframeUrl;
250
+ private buildIframeUrlWithView;
251
+ /**
252
+ * Mount a single-channel chat view.
253
+ */
254
+ mountChat(container: HTMLElement, options?: {
255
+ channelId?: string;
256
+ height?: number;
257
+ className?: string;
258
+ }): void;
259
+ private handleIframeMessage;
260
+ private emit;
261
+ }
262
+
263
+ export { Bridgecord, type BridgecordAttachment, type BridgecordAuthor, type BridgecordChannel, type BridgecordConnection, type BridgecordEmbed, type BridgecordEmbedConfig, type BridgecordEventMap, type BridgecordLeaderboardEntry, type BridgecordMessage, type BridgecordOptions, type BridgecordRewardEvent, type BridgecordRewardProfile, type BridgecordRole, type BridgecordTheme, type BridgecordUser, type ConnectOptions };