botcast-sdk 1.0.7 → 1.0.9

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/README.md CHANGED
@@ -62,10 +62,12 @@ const { instance } = await admin.createInstance({
62
62
  platform: "whatsapp",
63
63
  type: "paid",
64
64
  plan_months: 12,
65
+ expires_at: "2027-12-31T23:59:59.000Z", // Optional exact expiration date
65
66
  });
66
67
 
67
- // Renew subscription
68
+ // Renew subscription (by months or exact date)
68
69
  await admin.renewInstance(instance.id, { months: 12 });
70
+ // or: await admin.setExpiration(instance.id, "2028-06-30T23:59:59.000Z");
69
71
  ```
70
72
 
71
73
  ---
@@ -271,7 +273,7 @@ await client.messages.delete("201012345678", msgKey);
271
273
  await client.messages.markAsRead(msgKey);
272
274
 
273
275
  // 4. Emoji reaction
274
- await client.messages.react("201012345678", msgKey, "👍");
276
+ await client.messages.react("201012345678", msgKey, "STAR");
275
277
 
276
278
  // 5. Pin message
277
279
  await client.messages.pin("201012345678", msgKey, 1, 86400);
@@ -284,7 +286,59 @@ await client.messages.forward("201012345678", {
284
286
 
285
287
  ---
286
288
 
287
- ### 4. Chats, Contacts, and History (`client.chats`)
289
+ ### 4. Real-Time Socket.io Event Gateway (`client.socket`)
290
+
291
+ Stream real-time instance events directly with zero latency over **Socket.io**:
292
+
293
+ ```typescript
294
+ import { BotcastClient } from "botcast-sdk";
295
+
296
+ const client = new BotcastClient({
297
+ baseUrl: "https://botcast.site",
298
+ instanceId: "your_instance_id",
299
+ instanceToken: "your_instance_token",
300
+ autoConnectSocket: true, // or call client.socket.connect() manually
301
+ });
302
+
303
+ // 1. Listen for new incoming/outgoing messages
304
+ client.socket.onMessage((msg) => {
305
+ console.log("Real-time message:", msg);
306
+ });
307
+
308
+ // 2. Listen for delivery status & read receipts
309
+ client.socket.onMessageStatus((status) => {
310
+ console.log("Message status update:", status);
311
+ });
312
+
313
+ // 3. Listen for emoji reactions
314
+ client.socket.onReaction((reaction) => {
315
+ console.log("Reaction event:", reaction);
316
+ });
317
+
318
+ // 4. Listen for deleted/revoked messages
319
+ client.socket.onMessageDeleted((del) => {
320
+ console.log("Message deleted:", del);
321
+ });
322
+
323
+ // 5. Listen for user presence (typing, recording, online state)
324
+ client.socket.onPresence((presence) => {
325
+ console.log("Presence update:", presence);
326
+ });
327
+
328
+ // 6. Listen for instance connection & QR updates
329
+ client.socket.onConnectionUpdate((conn) => {
330
+ console.log("Connection state:", conn.status, conn.qr || conn.pairingCode);
331
+ });
332
+
333
+ // 7. Generic event listener
334
+ client.socket.onEvent((event) => {
335
+ console.log("Instance event received:", event.event, event);
336
+ });
337
+ ```
338
+
339
+ ---
340
+
341
+ ### 5. Chats, Contacts, and History (`client.chats`)
288
342
 
289
343
  ```typescript
290
344
  // 1. List chats / dialogs
@@ -307,7 +361,7 @@ await client.chats.pin("201012345678@s.whatsapp.net");
307
361
 
308
362
  ---
309
363
 
310
- ### 5. Webhook Event Handling
364
+ ### 6. Webhook Event Handling
311
365
 
312
366
  The SDK includes a built-in event dispatcher and middleware for handling inbound webhooks from both WhatsApp and Telegram:
313
367
 
package/dist/admin.cjs CHANGED
@@ -65,6 +65,12 @@ class BotcastAdminClient {
65
65
  * Admins are zero-payment, so instances are provisioned as active paid instances.
66
66
  */
67
67
  async createInstance(options) {
68
+ const rawExp = options.expires_at || options.expiresAt;
69
+ const expires_at = rawExp
70
+ ? rawExp instanceof Date
71
+ ? rawExp.toISOString()
72
+ : new Date(rawExp).toISOString()
73
+ : undefined;
68
74
  return this.request('/api/instances', {
69
75
  method: 'POST',
70
76
  body: JSON.stringify({
@@ -75,29 +81,60 @@ class BotcastAdminClient {
75
81
  allowed_numbers: options.allowed_numbers || [],
76
82
  webhook_url: options.webhook_url || '',
77
83
  target_user_id: options.target_user_id,
84
+ expires_at,
78
85
  }),
79
86
  });
80
87
  }
81
88
  /**
82
89
  * Programmatically renews an instance's subscription without payment transactions.
90
+ * Supports either extending by months or setting an exact expiration date.
83
91
  */
84
92
  async renewInstance(instanceId, options) {
93
+ const rawExp = options?.expires_at || options?.expiresAt;
94
+ const expires_at = rawExp
95
+ ? rawExp instanceof Date
96
+ ? rawExp.toISOString()
97
+ : new Date(rawExp).toISOString()
98
+ : undefined;
85
99
  return this.request(`/api/instances/${instanceId}/renew`, {
86
100
  method: 'POST',
87
101
  body: JSON.stringify({
88
- months: options?.months || options?.plan_months || 12,
102
+ months: options?.months || options?.plan_months || (expires_at ? undefined : 12),
103
+ expires_at,
89
104
  }),
90
105
  });
91
106
  }
92
107
  /**
93
- * Updates instance configuration (name, webhook URL, allowed recipient numbers).
108
+ * Updates instance configuration (name, webhook URL, allowed recipient numbers, expiration date).
94
109
  */
95
110
  async updateInstance(instanceId, updates) {
111
+ const rawExp = updates.expires_at !== undefined ? updates.expires_at : updates.expiresAt;
112
+ let expires_at = undefined;
113
+ if (rawExp !== undefined) {
114
+ if (rawExp === null) {
115
+ expires_at = null;
116
+ }
117
+ else {
118
+ expires_at = rawExp instanceof Date ? rawExp.toISOString() : new Date(rawExp).toISOString();
119
+ }
120
+ }
96
121
  return this.request(`/api/instances/${instanceId}`, {
97
122
  method: 'PUT',
98
- body: JSON.stringify(updates),
123
+ body: JSON.stringify({
124
+ ...updates,
125
+ expires_at,
126
+ }),
99
127
  });
100
128
  }
129
+ /**
130
+ * Directly sets or clears the exact expiration date for an instance.
131
+ *
132
+ * @param instanceId Target instance ID (e.g. `ins_paid_...`)
133
+ * @param expiresAt Date instance, ISO string (e.g. `2027-01-01T00:00:00.000Z`), or `null` to remove expiry.
134
+ */
135
+ async setExpiration(instanceId, expiresAt) {
136
+ return this.updateInstance(instanceId, { expires_at: expiresAt });
137
+ }
101
138
  /**
102
139
  * Regenerates secret instance token for an instance.
103
140
  */
package/dist/admin.d.ts CHANGED
@@ -12,6 +12,8 @@ export interface CreateAdminInstanceOptions {
12
12
  allowed_numbers?: string[];
13
13
  webhook_url?: string;
14
14
  target_user_id?: number;
15
+ expires_at?: string | Date;
16
+ expiresAt?: string | Date;
15
17
  }
16
18
  export interface AdminInstanceRecord {
17
19
  id: string;
@@ -59,26 +61,41 @@ export declare class BotcastAdminClient {
59
61
  }>;
60
62
  /**
61
63
  * Programmatically renews an instance's subscription without payment transactions.
64
+ * Supports either extending by months or setting an exact expiration date.
62
65
  */
63
66
  renewInstance(instanceId: string, options?: {
64
67
  months?: number;
65
68
  plan_months?: number;
69
+ expires_at?: string | Date;
70
+ expiresAt?: string | Date;
66
71
  }): Promise<{
67
72
  success: boolean;
68
73
  message: string;
69
74
  instance: AdminInstanceRecord;
70
75
  }>;
71
76
  /**
72
- * Updates instance configuration (name, webhook URL, allowed recipient numbers).
77
+ * Updates instance configuration (name, webhook URL, allowed recipient numbers, expiration date).
73
78
  */
74
79
  updateInstance(instanceId: string, updates: {
75
80
  name?: string;
76
81
  webhook_url?: string;
77
82
  allowed_numbers?: string[];
83
+ expires_at?: string | Date | null;
84
+ expiresAt?: string | Date | null;
78
85
  }): Promise<{
79
86
  message: string;
80
87
  instance: AdminInstanceRecord;
81
88
  }>;
89
+ /**
90
+ * Directly sets or clears the exact expiration date for an instance.
91
+ *
92
+ * @param instanceId Target instance ID (e.g. `ins_paid_...`)
93
+ * @param expiresAt Date instance, ISO string (e.g. `2027-01-01T00:00:00.000Z`), or `null` to remove expiry.
94
+ */
95
+ setExpiration(instanceId: string, expiresAt: string | Date | null): Promise<{
96
+ message: string;
97
+ instance: AdminInstanceRecord;
98
+ }>;
82
99
  /**
83
100
  * Regenerates secret instance token for an instance.
84
101
  */
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/admin.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,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G,IAAI,GAAG,IAAI,GAC9B,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,mBAAmB,CAAA;KAAE,CAAC;IAI9D;;OAEG;IACU,uBAAuB,CAClC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IAMvD;;OAEG;IACU,cAAc,CACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAKpD"}
package/dist/admin.js CHANGED
@@ -62,6 +62,12 @@ export class BotcastAdminClient {
62
62
  * Admins are zero-payment, so instances are provisioned as active paid instances.
63
63
  */
64
64
  async createInstance(options) {
65
+ const rawExp = options.expires_at || options.expiresAt;
66
+ const expires_at = rawExp
67
+ ? rawExp instanceof Date
68
+ ? rawExp.toISOString()
69
+ : new Date(rawExp).toISOString()
70
+ : undefined;
65
71
  return this.request('/api/instances', {
66
72
  method: 'POST',
67
73
  body: JSON.stringify({
@@ -72,29 +78,60 @@ export class BotcastAdminClient {
72
78
  allowed_numbers: options.allowed_numbers || [],
73
79
  webhook_url: options.webhook_url || '',
74
80
  target_user_id: options.target_user_id,
81
+ expires_at,
75
82
  }),
76
83
  });
77
84
  }
78
85
  /**
79
86
  * Programmatically renews an instance's subscription without payment transactions.
87
+ * Supports either extending by months or setting an exact expiration date.
80
88
  */
81
89
  async renewInstance(instanceId, options) {
90
+ const rawExp = options?.expires_at || options?.expiresAt;
91
+ const expires_at = rawExp
92
+ ? rawExp instanceof Date
93
+ ? rawExp.toISOString()
94
+ : new Date(rawExp).toISOString()
95
+ : undefined;
82
96
  return this.request(`/api/instances/${instanceId}/renew`, {
83
97
  method: 'POST',
84
98
  body: JSON.stringify({
85
- months: options?.months || options?.plan_months || 12,
99
+ months: options?.months || options?.plan_months || (expires_at ? undefined : 12),
100
+ expires_at,
86
101
  }),
87
102
  });
88
103
  }
89
104
  /**
90
- * Updates instance configuration (name, webhook URL, allowed recipient numbers).
105
+ * Updates instance configuration (name, webhook URL, allowed recipient numbers, expiration date).
91
106
  */
92
107
  async updateInstance(instanceId, updates) {
108
+ const rawExp = updates.expires_at !== undefined ? updates.expires_at : updates.expiresAt;
109
+ let expires_at = undefined;
110
+ if (rawExp !== undefined) {
111
+ if (rawExp === null) {
112
+ expires_at = null;
113
+ }
114
+ else {
115
+ expires_at = rawExp instanceof Date ? rawExp.toISOString() : new Date(rawExp).toISOString();
116
+ }
117
+ }
93
118
  return this.request(`/api/instances/${instanceId}`, {
94
119
  method: 'PUT',
95
- body: JSON.stringify(updates),
120
+ body: JSON.stringify({
121
+ ...updates,
122
+ expires_at,
123
+ }),
96
124
  });
97
125
  }
126
+ /**
127
+ * Directly sets or clears the exact expiration date for an instance.
128
+ *
129
+ * @param instanceId Target instance ID (e.g. `ins_paid_...`)
130
+ * @param expiresAt Date instance, ISO string (e.g. `2027-01-01T00:00:00.000Z`), or `null` to remove expiry.
131
+ */
132
+ async setExpiration(instanceId, expiresAt) {
133
+ return this.updateInstance(instanceId, { expires_at: expiresAt });
134
+ }
98
135
  /**
99
136
  * Regenerates secret instance token for an instance.
100
137
  */
package/dist/client.cjs CHANGED
@@ -8,6 +8,7 @@ const groups_js_1 = require("./modules/groups.js");
8
8
  const profile_js_1 = require("./modules/profile.js");
9
9
  const broadcast_js_1 = require("./modules/broadcast.js");
10
10
  const index_js_1 = require("./webhooks/index.js");
11
+ const index_js_2 = require("./socket/index.js");
11
12
  class BotcastClient {
12
13
  config;
13
14
  /** Instance Lifecycle & Connection Management */
@@ -24,10 +25,13 @@ class BotcastClient {
24
25
  broadcast;
25
26
  /** Webhook Handler & Middleware */
26
27
  webhook;
28
+ /** Real-Time Socket.io Event Gateway Client */
29
+ socket;
27
30
  /**
28
31
  * Initializes a new Botcast API Client.
29
32
  *
30
33
  * @param config Client configuration options
34
+ * @param socketOptions Optional Socket.io client overrides
31
35
  *
32
36
  * @example
33
37
  * ```ts
@@ -39,11 +43,16 @@ class BotcastClient {
39
43
  * instanceToken: 'token_xyz789'
40
44
  * });
41
45
  *
46
+ * // Listen for real-time events via Socket.io
47
+ * botcast.socket.onMessage((msg) => {
48
+ * console.log('Incoming message:', msg);
49
+ * });
50
+ *
42
51
  * // Send a text message
43
52
  * await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK!');
44
53
  * ```
45
54
  */
46
- constructor(config) {
55
+ constructor(config, socketOptions) {
47
56
  if (!config.instanceId) {
48
57
  throw new Error('BotcastClient requires a valid "instanceId"');
49
58
  }
@@ -58,6 +67,7 @@ class BotcastClient {
58
67
  timeout: config.timeout || 30000,
59
68
  maxRetries: config.maxRetries ?? 2,
60
69
  headers: config.headers || {},
70
+ autoConnectSocket: config.autoConnectSocket ?? false,
61
71
  };
62
72
  this.instances = new instances_js_1.InstancesModule(this.config);
63
73
  this.messages = new messages_js_1.MessagesModule(this.config);
@@ -66,6 +76,10 @@ class BotcastClient {
66
76
  this.profile = new profile_js_1.ProfileModule(this.config);
67
77
  this.broadcast = new broadcast_js_1.BroadcastModule(this.config);
68
78
  this.webhook = new index_js_1.BotcastWebhook();
79
+ this.socket = new index_js_2.BotcastSocketClient(this.config, {
80
+ autoConnect: config.autoConnectSocket,
81
+ ...socketOptions,
82
+ });
69
83
  }
70
84
  // =========================================================================
71
85
  // Top-Level Convenience Shortcuts
package/dist/client.d.ts CHANGED
@@ -6,6 +6,7 @@ import { GroupsModule } from './modules/groups.js';
6
6
  import { ProfileModule } from './modules/profile.js';
7
7
  import { BroadcastModule } from './modules/broadcast.js';
8
8
  import { BotcastWebhook } from './webhooks/index.js';
9
+ import { BotcastSocketClient, BotcastSocketOptions } from './socket/index.js';
9
10
  export declare class BotcastClient {
10
11
  private config;
11
12
  /** Instance Lifecycle & Connection Management */
@@ -22,10 +23,13 @@ export declare class BotcastClient {
22
23
  broadcast: BroadcastModule;
23
24
  /** Webhook Handler & Middleware */
24
25
  webhook: BotcastWebhook;
26
+ /** Real-Time Socket.io Event Gateway Client */
27
+ socket: BotcastSocketClient;
25
28
  /**
26
29
  * Initializes a new Botcast API Client.
27
30
  *
28
31
  * @param config Client configuration options
32
+ * @param socketOptions Optional Socket.io client overrides
29
33
  *
30
34
  * @example
31
35
  * ```ts
@@ -37,11 +41,16 @@ export declare class BotcastClient {
37
41
  * instanceToken: 'token_xyz789'
38
42
  * });
39
43
  *
44
+ * // Listen for real-time events via Socket.io
45
+ * botcast.socket.onMessage((msg) => {
46
+ * console.log('Incoming message:', msg);
47
+ * });
48
+ *
40
49
  * // Send a text message
41
50
  * await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK!');
42
51
  * ```
43
52
  */
44
- constructor(config: BotcastClientConfig);
53
+ constructor(config: BotcastClientConfig, socketOptions?: BotcastSocketOptions);
45
54
  /**
46
55
  * Shortcut to send a text message.
47
56
  */
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgC;IAE9C,iDAAiD;IAC1C,SAAS,EAAE,eAAe,CAAC;IAElC,6EAA6E;IACtE,QAAQ,EAAE,cAAc,CAAC;IAEhC,0DAA0D;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AAmB,CAAC;AAE9E,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgC;IAE9C,iDAAiD;IAC1C,SAAS,EAAE,eAAe,CAAC;IAElC,6EAA6E;IACtE,QAAQ,EAAE,cAAc,CAAC;IAEhC,0DAA0D;IACnD,KAAK,EAAE,WAAW,CAAC;IAE1B,iDAAiD;IAC1C,MAAM,EAAE,YAAY,CAAC;IAE5B,0DAA0D;IACnD,OAAO,EAAE,aAAa,CAAC;IAE9B,gDAAgD;IACzC,SAAS,EAAE,eAAe,CAAC;IAElC,mCAAmC;IAC5B,OAAO,EAAE,cAAc,CAAC;IAE/B,+CAA+C;IACxC,MAAM,EAAE,mBAAmB,CAAC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;gBACS,MAAM,EAAE,mBAAmB,EAAE,aAAa,CAAC,EAAE,oBAAoB;IAoC7E;;OAEG;IACU,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAIrD;;OAEG;IACU,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;;;IAI7G;;OAEG;IACU,SAAS;IAItB;;OAEG;IACU,KAAK;IAIlB;;;;OAIG;IACU,YAAY,CAAC,WAAW,EAAE,MAAM;IAI7C;;;;OAIG;IACU,WAAW,CAAC,WAAW,EAAE,MAAM;CAG7C"}
package/dist/client.js CHANGED
@@ -5,6 +5,7 @@ import { GroupsModule } from './modules/groups.js';
5
5
  import { ProfileModule } from './modules/profile.js';
6
6
  import { BroadcastModule } from './modules/broadcast.js';
7
7
  import { BotcastWebhook } from './webhooks/index.js';
8
+ import { BotcastSocketClient } from './socket/index.js';
8
9
  export class BotcastClient {
9
10
  config;
10
11
  /** Instance Lifecycle & Connection Management */
@@ -21,10 +22,13 @@ export class BotcastClient {
21
22
  broadcast;
22
23
  /** Webhook Handler & Middleware */
23
24
  webhook;
25
+ /** Real-Time Socket.io Event Gateway Client */
26
+ socket;
24
27
  /**
25
28
  * Initializes a new Botcast API Client.
26
29
  *
27
30
  * @param config Client configuration options
31
+ * @param socketOptions Optional Socket.io client overrides
28
32
  *
29
33
  * @example
30
34
  * ```ts
@@ -36,11 +40,16 @@ export class BotcastClient {
36
40
  * instanceToken: 'token_xyz789'
37
41
  * });
38
42
  *
43
+ * // Listen for real-time events via Socket.io
44
+ * botcast.socket.onMessage((msg) => {
45
+ * console.log('Incoming message:', msg);
46
+ * });
47
+ *
39
48
  * // Send a text message
40
49
  * await botcast.messages.sendText('201000000000', 'Hello from Botcast SDK!');
41
50
  * ```
42
51
  */
43
- constructor(config) {
52
+ constructor(config, socketOptions) {
44
53
  if (!config.instanceId) {
45
54
  throw new Error('BotcastClient requires a valid "instanceId"');
46
55
  }
@@ -55,6 +64,7 @@ export class BotcastClient {
55
64
  timeout: config.timeout || 30000,
56
65
  maxRetries: config.maxRetries ?? 2,
57
66
  headers: config.headers || {},
67
+ autoConnectSocket: config.autoConnectSocket ?? false,
58
68
  };
59
69
  this.instances = new InstancesModule(this.config);
60
70
  this.messages = new MessagesModule(this.config);
@@ -63,6 +73,10 @@ export class BotcastClient {
63
73
  this.profile = new ProfileModule(this.config);
64
74
  this.broadcast = new BroadcastModule(this.config);
65
75
  this.webhook = new BotcastWebhook();
76
+ this.socket = new BotcastSocketClient(this.config, {
77
+ autoConnect: config.autoConnectSocket,
78
+ ...socketOptions,
79
+ });
66
80
  }
67
81
  // =========================================================================
68
82
  // Top-Level Convenience Shortcuts
package/dist/index.cjs CHANGED
@@ -14,13 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BotcastWebhook = exports.BotcastAdminClient = exports.BotcastClient = void 0;
17
+ exports.BotcastSocketClient = exports.BotcastWebhook = exports.BotcastAdminClient = exports.BotcastClient = void 0;
18
18
  var client_js_1 = require("./client.js");
19
19
  Object.defineProperty(exports, "BotcastClient", { enumerable: true, get: function () { return client_js_1.BotcastClient; } });
20
20
  var admin_js_1 = require("./admin.js");
21
21
  Object.defineProperty(exports, "BotcastAdminClient", { enumerable: true, get: function () { return admin_js_1.BotcastAdminClient; } });
22
22
  var index_js_1 = require("./webhooks/index.js");
23
23
  Object.defineProperty(exports, "BotcastWebhook", { enumerable: true, get: function () { return index_js_1.BotcastWebhook; } });
24
+ var index_js_2 = require("./socket/index.js");
25
+ Object.defineProperty(exports, "BotcastSocketClient", { enumerable: true, get: function () { return index_js_2.BotcastSocketClient; } });
24
26
  __exportStar(require("./errors.js"), exports);
25
27
  __exportStar(require("./types/index.js"), exports);
26
28
  // Default export
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { BotcastClient } from './client.js';
2
2
  export { BotcastAdminClient, BotcastAdminConfig, CreateAdminInstanceOptions, AdminInstanceRecord } from './admin.js';
3
3
  export { BotcastWebhook } from './webhooks/index.js';
4
+ export { BotcastSocketClient, BotcastSocketOptions } from './socket/index.js';
4
5
  export * from './errors.js';
5
6
  export * from './types/index.js';
6
7
  import { BotcastClient } from './client.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,eAAe,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { BotcastClient } from './client.js';
2
2
  export { BotcastAdminClient } from './admin.js';
3
3
  export { BotcastWebhook } from './webhooks/index.js';
4
+ export { BotcastSocketClient } from './socket/index.js';
4
5
  export * from './errors.js';
5
6
  export * from './types/index.js';
6
7
  // Default export