btechworks-sdk 1.0.1 → 1.0.3

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
@@ -40,146 +40,148 @@ const client = new BTechWorksClient({
40
40
 
41
41
  ## Methods
42
42
 
43
- ### sendMessage
44
-
45
- Send a text message to a phone number. Contact and conversation are auto-created.
43
+ ### Messaging
46
44
 
47
45
  ```typescript
48
- const result = await client.sendMessage({
49
- phone: '+1234567890',
50
- message: 'Hello World!',
51
- });
52
- // { success: true, message: 'Message sent successfully' }
53
- ```
46
+ // Send text message
47
+ await client.sendMessage({ phone: '+1234567890', message: 'Hello!' });
54
48
 
55
- ### sendPhoto
49
+ // Send photo
50
+ await client.sendPhoto({ phone: '+1234567890', imageUrl: 'https://example.com/photo.jpg', caption: 'Photo' });
56
51
 
57
- Send an image with an optional caption.
52
+ // Send video
53
+ await client.sendVideo({ phone: '+1234567890', videoUrl: 'https://example.com/video.mp4', caption: 'Video' });
58
54
 
59
- ```typescript
60
- const result = await client.sendPhoto({
61
- phone: '+1234567890',
62
- imageUrl: 'https://example.com/photo.jpg',
63
- caption: 'Check out this photo!',
64
- });
65
- // { success: true, message: 'Photo sent successfully' }
55
+ // Send document
56
+ await client.sendDocument({ phone: '+1234567890', documentUrl: 'https://example.com/file.pdf', filename: 'file.pdf' });
66
57
  ```
67
58
 
68
- ### sendVideo
69
-
70
- Send a video with an optional caption.
59
+ ### Templates
71
60
 
72
61
  ```typescript
73
- const result = await client.sendVideo({
62
+ // Check template variables first
63
+ const check = await client.checkTemplate({ templateName: 'order_confirm' });
64
+ console.log(check.variables); // [{ name: 'name', example: 'John' }]
65
+
66
+ // Send template
67
+ const result = await client.sendTemplate({
74
68
  phone: '+1234567890',
75
- videoUrl: 'https://example.com/video.mp4',
76
- caption: 'Watch this video!',
69
+ templateName: 'order_confirm',
70
+ templateLanguage: 'en_US',
71
+ templateParams: ['John', 'Order #12345'],
77
72
  });
78
- // { success: true, message: 'Video sent successfully' }
73
+ // { success: true, sent_as: 'template', balance: 99 }
74
+ // OR if 24h window open:
75
+ // { success: true, sent_as: 'text', message: 'Service window open - sent as free text' }
79
76
  ```
80
77
 
81
- ### sendDocument
82
-
83
- Send a document (PDF, DOC, etc.) with an optional caption.
78
+ ### Broadcast
84
79
 
85
80
  ```typescript
86
- const result = await client.sendDocument({
87
- phone: '+1234567890',
88
- documentUrl: 'https://example.com/invoice.pdf',
89
- filename: 'invoice.pdf',
90
- caption: 'Your invoice for this month',
81
+ const result = await client.broadcast({
82
+ name: 'Summer Sale',
83
+ templateName: 'summer_offer',
84
+ templateLanguage: 'en_US',
85
+ recipients: ['+1234567890', '+0987654321'],
91
86
  });
92
- // { success: true, message: 'Document sent successfully' }
87
+ // { success: true, message: 'Template "summer_offer" processed: 20 sent, 5 failed' }
93
88
  ```
94
89
 
95
- ### sendTemplate
96
-
97
- Send a WhatsApp template message with variables.
90
+ ### Wallet
98
91
 
99
92
  ```typescript
100
- // Simple template with body variables
101
- const result = await client.sendTemplate({
102
- phone: '+1234567890',
103
- templateName: 'order_confirmation',
104
- templateLanguage: 'en_US',
105
- templateParams: ['John', 'Order #12345'],
93
+ // Check balance
94
+ const balance = await client.getBalance();
95
+ // { success: true, balance: 100, can_send: 100 }
96
+
97
+ // Estimate cost before sending
98
+ const estimate = await client.estimateCost(50);
99
+ // { success: true, balance: 100, can_send: 100, estimated_templates: 50 }
100
+
101
+ // Generate payment link (user opens link to pay)
102
+ const link = await client.rechargeViaLink({
103
+ amount: 500,
104
+ email: 'user@example.com',
105
+ phone: '+919999999999'
106
106
  });
107
- // { success: true, message: 'Template sent successfully' }
107
+ // { success: true, link_url: 'https://cashfree.com/pay/...', order_amount: 500 }
108
+ // User opens link_url and pays via Card/UPI
108
109
 
109
- // Template with header media and button params
110
- const result2 = await client.sendTemplate({
111
- phone: '+1234567890',
112
- templateName: 'promo_template',
113
- templateLanguage: 'en_US',
114
- templateMessageParams: {
115
- header: { type: 'image', url: 'https://example.com/promo.jpg' },
116
- body: ['John', '50%'],
117
- buttons: [{ type: 'url', suffix: 'promo50' }],
118
- },
119
- });
110
+ // Get transaction history
111
+ const txns = await client.getTransactions(10, 0);
112
+ // { success: true, transactions: [...] }
120
113
  ```
121
114
 
122
- ### broadcast
123
-
124
- Send a template message to multiple recipients.
115
+ ### Analytics
125
116
 
126
117
  ```typescript
127
- const result = await client.broadcast({
128
- name: 'Summer Sale Campaign',
129
- templateName: 'summer_sale',
130
- templateLanguage: 'en_US',
131
- templateVariables: { code: 'SUMMER50' },
132
- recipients: ['+1234567890', '+0987654321', '+1122334455'],
133
- });
134
- // { success: true, message: 'Template "summer_sale" processed: 20 sent, 5 failed' }
135
-
136
- // Or use audience filter by tags
137
- const result2 = await client.broadcast({
138
- name: 'VIP Customers',
139
- templateName: 'vip_offer',
140
- recipients: [],
141
- audienceFilter: { tags: ['vip', 'premium'] },
142
- });
143
- // { success: true, message: 'Template "vip_offer" processed: 50 sent, 10 skipped, 3 failed' }
118
+ const analytics = await client.getAnalytics();
119
+ // {
120
+ // success: true,
121
+ // analytics: {
122
+ // contacts: 1250,
123
+ // conversations: 890,
124
+ // messages: { today: 45, this_week: 312, this_month: 1250 },
125
+ // templates: 15,
126
+ // recent_broadcasts: [...]
127
+ // }
128
+ // }
144
129
  ```
145
130
 
146
131
  ## Response Format
147
132
 
148
- All methods return a simple response:
133
+ All methods return a simple response object. **No exceptions are thrown.**
149
134
 
150
135
  ```typescript
151
- // Single message
136
+ // Success
152
137
  { success: true, message: 'Message sent successfully' }
153
138
 
139
+ // Error
140
+ { success: false, message: 'Invalid phone number format' }
141
+
142
+ // Template with balance
143
+ { success: true, sent_as: 'template', balance: 99 }
144
+
154
145
  // Broadcast
155
146
  { success: true, message: 'Template "promo" processed: 20 sent, 10 skipped, 5 failed' }
156
-
157
- // Error (throws BTechWorksError)
158
- { success: false, message: 'Invalid phone number format' }
159
147
  ```
160
148
 
161
149
  ## Error Handling
162
150
 
163
- All methods throw `BTechWorksError` on failure:
151
+ All methods return response objects with `success: false` on error. No try-catch needed:
164
152
 
165
153
  ```typescript
166
- import { BTechWorksClient, BTechWorksError } from 'btechworks-sdk';
167
-
168
- try {
169
- await client.sendMessage({ phone: '+1234567890', message: 'Hello!' });
170
- } catch (error) {
171
- if (error instanceof BTechWorksError) {
172
- console.log(error.message); // Error message
173
- console.log(error.statusCode); // HTTP status code
174
- }
154
+ const result = await client.sendMessage({ phone: 'invalid', message: 'Hello!' });
155
+
156
+ if (result.success) {
157
+ console.log('Sent!');
158
+ } else {
159
+ console.log('Failed:', result.message);
175
160
  }
176
161
  ```
177
162
 
178
- ## How It Works
163
+ ## Template Flow
164
+
165
+ 1. **Check template** - See what variables are needed
166
+ 2. **Send template** - Auto-deducts balance OR sends as free text if 24h window open
167
+
168
+ ```typescript
169
+ // Step 1: Check
170
+ const check = await client.checkTemplate({ templateName: 'welcome' });
171
+ if (!check.ready_to_send) {
172
+ console.log('Missing variables:', check.variables);
173
+ }
179
174
 
180
- 1. **Phone number se sab kuch hota hai** - Contact aur conversation automatically create ho jaate hain
181
- 2. **API key + Secret key se auth hota hai** - Dashboard se API key banao, SDK mein daalo, kaam shuru
182
- 3. **Server sab handle karta hai** - Contact lookup, conversation creation, Meta API calls, message storage
175
+ // Step 2: Send (handles everything automatically)
176
+ const result = await client.sendTemplate({
177
+ phone: '+1234567890',
178
+ templateName: 'welcome',
179
+ templateParams: ['John']
180
+ });
181
+
182
+ // sent_as: 'text' = Free (24h window open)
183
+ // sent_as: 'template' = Paid (balance deducted)
184
+ ```
183
185
 
184
186
  ## Getting API Keys
185
187
 
package/dist/index.d.mts CHANGED
@@ -60,12 +60,113 @@ interface BroadcastResponse {
60
60
  success: boolean;
61
61
  message: string;
62
62
  }
63
-
64
- declare class BTechWorksError extends Error {
65
- statusCode: number;
66
- details?: Record<string, unknown>;
67
- constructor(message: string, statusCode: number, details?: Record<string, unknown>);
63
+ interface CheckTemplateOptions {
64
+ templateName: string;
65
+ templateLanguage?: string;
68
66
  }
67
+ interface TemplateVariable {
68
+ name: string;
69
+ example: string;
70
+ required: boolean;
71
+ }
72
+ interface CheckTemplateResponse {
73
+ success: boolean;
74
+ exists?: boolean;
75
+ template?: {
76
+ name: string;
77
+ language: string;
78
+ status: string;
79
+ };
80
+ variables?: TemplateVariable[];
81
+ ready_to_send?: boolean;
82
+ message: string;
83
+ }
84
+ interface WalletBalanceResponse {
85
+ success: boolean;
86
+ balance?: number;
87
+ template_rate?: number;
88
+ is_active?: boolean;
89
+ message: string;
90
+ }
91
+ interface AddCreditsOptions {
92
+ amount: number;
93
+ description?: string;
94
+ }
95
+ interface AddCreditsResponse {
96
+ success: boolean;
97
+ balance?: number;
98
+ message: string;
99
+ }
100
+ interface Transaction {
101
+ type: 'credit' | 'debit' | 'refund';
102
+ amount: number;
103
+ balance_after: number;
104
+ description: string;
105
+ created_at: string;
106
+ }
107
+ interface TransactionsResponse {
108
+ success: boolean;
109
+ transactions?: Transaction[];
110
+ message: string;
111
+ }
112
+ interface SendTemplateResponse {
113
+ success: boolean;
114
+ sent_as?: 'text' | 'template';
115
+ balance?: number;
116
+ message: string;
117
+ }
118
+ interface RechargeOptions {
119
+ amount: number;
120
+ email?: string;
121
+ phone?: string;
122
+ }
123
+ interface RechargeResponse {
124
+ success: boolean;
125
+ order_id?: string;
126
+ payment_session_id?: string;
127
+ order_amount?: number;
128
+ message: string;
129
+ }
130
+ interface RechargeViaLinkResponse {
131
+ success: boolean;
132
+ link_id?: string;
133
+ link_url?: string;
134
+ link_status?: string;
135
+ order_amount?: number;
136
+ message: string;
137
+ }
138
+ interface EstimateCostResponse {
139
+ success: boolean;
140
+ balance?: number;
141
+ template_rate?: number;
142
+ can_send?: number;
143
+ estimated_templates?: number;
144
+ message: string;
145
+ }
146
+ interface Broadcast {
147
+ name: string;
148
+ status: string;
149
+ sent_count: number;
150
+ failed_count: number;
151
+ created_at: string;
152
+ }
153
+ interface Analytics {
154
+ contacts: number;
155
+ conversations: number;
156
+ messages: {
157
+ today: number;
158
+ this_week: number;
159
+ this_month: number;
160
+ };
161
+ templates: number;
162
+ recent_broadcasts: Broadcast[];
163
+ }
164
+ interface AnalyticsResponse {
165
+ success: boolean;
166
+ analytics?: Analytics;
167
+ message: string;
168
+ }
169
+
69
170
  declare class BTechWorksClient {
70
171
  private apiKey;
71
172
  private secretKey;
@@ -73,12 +174,20 @@ declare class BTechWorksClient {
73
174
  private timeout;
74
175
  constructor(config: BTechWorksConfig);
75
176
  private request;
177
+ getAnalytics(): Promise<AnalyticsResponse>;
178
+ checkTemplate(options: CheckTemplateOptions): Promise<CheckTemplateResponse>;
76
179
  sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
77
180
  sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
78
181
  sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
79
182
  sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
80
- sendTemplate(options: SendTemplateOptions): Promise<ApiResponse>;
183
+ sendTemplate(options: SendTemplateOptions): Promise<SendTemplateResponse>;
81
184
  broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
185
+ getBalance(): Promise<WalletBalanceResponse>;
186
+ estimateCost(count?: number): Promise<EstimateCostResponse>;
187
+ addCredits(options: AddCreditsOptions): Promise<AddCreditsResponse>;
188
+ recharge(options: RechargeOptions): Promise<RechargeResponse>;
189
+ rechargeViaLink(options: RechargeOptions): Promise<RechargeViaLinkResponse>;
190
+ getTransactions(limit?: number, offset?: number): Promise<TransactionsResponse>;
82
191
  }
83
192
 
84
- export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
193
+ export { type AddCreditsOptions, type AddCreditsResponse, type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type CheckTemplateOptions, type CheckTemplateResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendTemplateResponse, type SendVideoOptions, type TemplateVariable, type Transaction, type TransactionsResponse, type WalletBalanceResponse };
package/dist/index.d.ts CHANGED
@@ -60,12 +60,113 @@ interface BroadcastResponse {
60
60
  success: boolean;
61
61
  message: string;
62
62
  }
63
-
64
- declare class BTechWorksError extends Error {
65
- statusCode: number;
66
- details?: Record<string, unknown>;
67
- constructor(message: string, statusCode: number, details?: Record<string, unknown>);
63
+ interface CheckTemplateOptions {
64
+ templateName: string;
65
+ templateLanguage?: string;
68
66
  }
67
+ interface TemplateVariable {
68
+ name: string;
69
+ example: string;
70
+ required: boolean;
71
+ }
72
+ interface CheckTemplateResponse {
73
+ success: boolean;
74
+ exists?: boolean;
75
+ template?: {
76
+ name: string;
77
+ language: string;
78
+ status: string;
79
+ };
80
+ variables?: TemplateVariable[];
81
+ ready_to_send?: boolean;
82
+ message: string;
83
+ }
84
+ interface WalletBalanceResponse {
85
+ success: boolean;
86
+ balance?: number;
87
+ template_rate?: number;
88
+ is_active?: boolean;
89
+ message: string;
90
+ }
91
+ interface AddCreditsOptions {
92
+ amount: number;
93
+ description?: string;
94
+ }
95
+ interface AddCreditsResponse {
96
+ success: boolean;
97
+ balance?: number;
98
+ message: string;
99
+ }
100
+ interface Transaction {
101
+ type: 'credit' | 'debit' | 'refund';
102
+ amount: number;
103
+ balance_after: number;
104
+ description: string;
105
+ created_at: string;
106
+ }
107
+ interface TransactionsResponse {
108
+ success: boolean;
109
+ transactions?: Transaction[];
110
+ message: string;
111
+ }
112
+ interface SendTemplateResponse {
113
+ success: boolean;
114
+ sent_as?: 'text' | 'template';
115
+ balance?: number;
116
+ message: string;
117
+ }
118
+ interface RechargeOptions {
119
+ amount: number;
120
+ email?: string;
121
+ phone?: string;
122
+ }
123
+ interface RechargeResponse {
124
+ success: boolean;
125
+ order_id?: string;
126
+ payment_session_id?: string;
127
+ order_amount?: number;
128
+ message: string;
129
+ }
130
+ interface RechargeViaLinkResponse {
131
+ success: boolean;
132
+ link_id?: string;
133
+ link_url?: string;
134
+ link_status?: string;
135
+ order_amount?: number;
136
+ message: string;
137
+ }
138
+ interface EstimateCostResponse {
139
+ success: boolean;
140
+ balance?: number;
141
+ template_rate?: number;
142
+ can_send?: number;
143
+ estimated_templates?: number;
144
+ message: string;
145
+ }
146
+ interface Broadcast {
147
+ name: string;
148
+ status: string;
149
+ sent_count: number;
150
+ failed_count: number;
151
+ created_at: string;
152
+ }
153
+ interface Analytics {
154
+ contacts: number;
155
+ conversations: number;
156
+ messages: {
157
+ today: number;
158
+ this_week: number;
159
+ this_month: number;
160
+ };
161
+ templates: number;
162
+ recent_broadcasts: Broadcast[];
163
+ }
164
+ interface AnalyticsResponse {
165
+ success: boolean;
166
+ analytics?: Analytics;
167
+ message: string;
168
+ }
169
+
69
170
  declare class BTechWorksClient {
70
171
  private apiKey;
71
172
  private secretKey;
@@ -73,12 +174,20 @@ declare class BTechWorksClient {
73
174
  private timeout;
74
175
  constructor(config: BTechWorksConfig);
75
176
  private request;
177
+ getAnalytics(): Promise<AnalyticsResponse>;
178
+ checkTemplate(options: CheckTemplateOptions): Promise<CheckTemplateResponse>;
76
179
  sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
77
180
  sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
78
181
  sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
79
182
  sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
80
- sendTemplate(options: SendTemplateOptions): Promise<ApiResponse>;
183
+ sendTemplate(options: SendTemplateOptions): Promise<SendTemplateResponse>;
81
184
  broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
185
+ getBalance(): Promise<WalletBalanceResponse>;
186
+ estimateCost(count?: number): Promise<EstimateCostResponse>;
187
+ addCredits(options: AddCreditsOptions): Promise<AddCreditsResponse>;
188
+ recharge(options: RechargeOptions): Promise<RechargeResponse>;
189
+ rechargeViaLink(options: RechargeOptions): Promise<RechargeViaLinkResponse>;
190
+ getTransactions(limit?: number, offset?: number): Promise<TransactionsResponse>;
82
191
  }
83
192
 
84
- export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
193
+ export { type AddCreditsOptions, type AddCreditsResponse, type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type CheckTemplateOptions, type CheckTemplateResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendTemplateResponse, type SendVideoOptions, type TemplateVariable, type Transaction, type TransactionsResponse, type WalletBalanceResponse };
package/dist/index.js CHANGED
@@ -20,20 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- BTechWorksClient: () => BTechWorksClient,
24
- BTechWorksError: () => BTechWorksError
23
+ BTechWorksClient: () => BTechWorksClient
25
24
  });
26
25
  module.exports = __toCommonJS(index_exports);
27
26
 
28
27
  // src/client.ts
29
- var BTechWorksError = class extends Error {
30
- constructor(message, statusCode, details) {
31
- super(message);
32
- this.name = "BTechWorksError";
33
- this.statusCode = statusCode;
34
- this.details = details;
35
- }
36
- };
37
28
  var BTechWorksClient = class {
38
29
  constructor(config) {
39
30
  if (!config.apiKey) {
@@ -66,26 +57,38 @@ var BTechWorksClient = class {
66
57
  });
67
58
  const data = await response.json();
68
59
  if (!response.ok) {
69
- throw new BTechWorksError(
70
- data.message || data.error || `Request failed with status ${response.status}`,
71
- response.status,
72
- data
73
- );
60
+ return {
61
+ success: false,
62
+ message: data.message || data.error || `Request failed with status ${response.status}`
63
+ };
74
64
  }
75
65
  return data;
76
66
  } catch (error) {
77
- if (error instanceof BTechWorksError) throw error;
78
67
  if (error instanceof DOMException && error.name === "AbortError") {
79
- throw new BTechWorksError("Request timeout", 408);
68
+ return { success: false, message: "Request timeout" };
80
69
  }
81
- throw new BTechWorksError(
82
- error instanceof Error ? error.message : "Unknown error",
83
- 500
84
- );
70
+ return {
71
+ success: false,
72
+ message: error instanceof Error ? error.message : "Unknown error"
73
+ };
85
74
  } finally {
86
75
  clearTimeout(timeoutId);
87
76
  }
88
77
  }
78
+ async getAnalytics() {
79
+ return this.request("/api/sdk/analytics", {
80
+ method: "GET"
81
+ });
82
+ }
83
+ async checkTemplate(options) {
84
+ return this.request("/api/sdk/check-template", {
85
+ method: "POST",
86
+ body: JSON.stringify({
87
+ template_name: options.templateName,
88
+ template_language: options.templateLanguage
89
+ })
90
+ });
91
+ }
89
92
  async sendMessage(options) {
90
93
  return this.request("/api/sdk/send-message", {
91
94
  method: "POST",
@@ -151,9 +154,57 @@ var BTechWorksClient = class {
151
154
  })
152
155
  });
153
156
  }
157
+ async getBalance() {
158
+ return this.request("/api/sdk/wallet/balance", {
159
+ method: "GET"
160
+ });
161
+ }
162
+ async estimateCost(count = 1) {
163
+ return this.request(`/api/sdk/wallet/balance?count=${count}`, {
164
+ method: "GET"
165
+ });
166
+ }
167
+ async addCredits(options) {
168
+ return this.request("/api/sdk/wallet/add-credits", {
169
+ method: "POST",
170
+ body: JSON.stringify({
171
+ amount: options.amount,
172
+ description: options.description
173
+ })
174
+ });
175
+ }
176
+ async recharge(options) {
177
+ return this.request("/api/sdk/wallet/recharge", {
178
+ method: "POST",
179
+ body: JSON.stringify({
180
+ amount: options.amount,
181
+ email: options.email,
182
+ phone: options.phone
183
+ })
184
+ });
185
+ }
186
+ async rechargeViaLink(options) {
187
+ return this.request("/api/sdk/wallet/recharge-via-link", {
188
+ method: "POST",
189
+ body: JSON.stringify({
190
+ amount: options.amount,
191
+ email: options.email,
192
+ phone: options.phone
193
+ })
194
+ });
195
+ }
196
+ async getTransactions(limit, offset) {
197
+ const params = new URLSearchParams();
198
+ if (limit) params.set("limit", limit.toString());
199
+ if (offset) params.set("offset", offset.toString());
200
+ const query = params.toString();
201
+ const path = `/api/sdk/wallet/transactions${query ? `?${query}` : ""}`;
202
+ return this.request(path, {
203
+ method: "GET"
204
+ });
205
+ }
154
206
  };
155
207
  // Annotate the CommonJS export names for ESM import in node:
156
208
  0 && (module.exports = {
157
- BTechWorksClient,
158
- BTechWorksError
209
+ BTechWorksClient
159
210
  });
package/dist/index.mjs CHANGED
@@ -1,12 +1,4 @@
1
1
  // src/client.ts
2
- var BTechWorksError = class extends Error {
3
- constructor(message, statusCode, details) {
4
- super(message);
5
- this.name = "BTechWorksError";
6
- this.statusCode = statusCode;
7
- this.details = details;
8
- }
9
- };
10
2
  var BTechWorksClient = class {
11
3
  constructor(config) {
12
4
  if (!config.apiKey) {
@@ -39,26 +31,38 @@ var BTechWorksClient = class {
39
31
  });
40
32
  const data = await response.json();
41
33
  if (!response.ok) {
42
- throw new BTechWorksError(
43
- data.message || data.error || `Request failed with status ${response.status}`,
44
- response.status,
45
- data
46
- );
34
+ return {
35
+ success: false,
36
+ message: data.message || data.error || `Request failed with status ${response.status}`
37
+ };
47
38
  }
48
39
  return data;
49
40
  } catch (error) {
50
- if (error instanceof BTechWorksError) throw error;
51
41
  if (error instanceof DOMException && error.name === "AbortError") {
52
- throw new BTechWorksError("Request timeout", 408);
42
+ return { success: false, message: "Request timeout" };
53
43
  }
54
- throw new BTechWorksError(
55
- error instanceof Error ? error.message : "Unknown error",
56
- 500
57
- );
44
+ return {
45
+ success: false,
46
+ message: error instanceof Error ? error.message : "Unknown error"
47
+ };
58
48
  } finally {
59
49
  clearTimeout(timeoutId);
60
50
  }
61
51
  }
52
+ async getAnalytics() {
53
+ return this.request("/api/sdk/analytics", {
54
+ method: "GET"
55
+ });
56
+ }
57
+ async checkTemplate(options) {
58
+ return this.request("/api/sdk/check-template", {
59
+ method: "POST",
60
+ body: JSON.stringify({
61
+ template_name: options.templateName,
62
+ template_language: options.templateLanguage
63
+ })
64
+ });
65
+ }
62
66
  async sendMessage(options) {
63
67
  return this.request("/api/sdk/send-message", {
64
68
  method: "POST",
@@ -124,8 +128,56 @@ var BTechWorksClient = class {
124
128
  })
125
129
  });
126
130
  }
131
+ async getBalance() {
132
+ return this.request("/api/sdk/wallet/balance", {
133
+ method: "GET"
134
+ });
135
+ }
136
+ async estimateCost(count = 1) {
137
+ return this.request(`/api/sdk/wallet/balance?count=${count}`, {
138
+ method: "GET"
139
+ });
140
+ }
141
+ async addCredits(options) {
142
+ return this.request("/api/sdk/wallet/add-credits", {
143
+ method: "POST",
144
+ body: JSON.stringify({
145
+ amount: options.amount,
146
+ description: options.description
147
+ })
148
+ });
149
+ }
150
+ async recharge(options) {
151
+ return this.request("/api/sdk/wallet/recharge", {
152
+ method: "POST",
153
+ body: JSON.stringify({
154
+ amount: options.amount,
155
+ email: options.email,
156
+ phone: options.phone
157
+ })
158
+ });
159
+ }
160
+ async rechargeViaLink(options) {
161
+ return this.request("/api/sdk/wallet/recharge-via-link", {
162
+ method: "POST",
163
+ body: JSON.stringify({
164
+ amount: options.amount,
165
+ email: options.email,
166
+ phone: options.phone
167
+ })
168
+ });
169
+ }
170
+ async getTransactions(limit, offset) {
171
+ const params = new URLSearchParams();
172
+ if (limit) params.set("limit", limit.toString());
173
+ if (offset) params.set("offset", offset.toString());
174
+ const query = params.toString();
175
+ const path = `/api/sdk/wallet/transactions${query ? `?${query}` : ""}`;
176
+ return this.request(path, {
177
+ method: "GET"
178
+ });
179
+ }
127
180
  };
128
181
  export {
129
- BTechWorksClient,
130
- BTechWorksError
182
+ BTechWorksClient
131
183
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btechworks-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Official BatchWorks WhatsApp CRM SDK - Send messages, photos, videos, documents, templates, and broadcasts via API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",