@kortex-ai/hub-client 0.0.1 → 0.2.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.
package/README.md CHANGED
@@ -31,12 +31,12 @@ import { KortexClient } from '@kortex-ai/hub-client'
31
31
 
32
32
  // Initialize the client
33
33
  const client = new KortexClient({
34
- apiToken: 'your-api-token',
34
+ organizationToken: 'your-organization-token',
35
35
  baseUrl: 'https://kortex-dashboard.vercel.app', // Optional, this is the default
36
36
  })
37
37
 
38
38
  // Use the client with Result pattern (never throws)
39
- const result = await client.sendMessage({
39
+ const result = await client.sendTemplate({
40
40
  waId: '1234567890',
41
41
  message: {
42
42
  type: 'text',
@@ -60,26 +60,15 @@ if (result.error) {
60
60
  ```typescript
61
61
  interface KortexClientConfig {
62
62
  /**
63
- * API token for authentication (required)
63
+ * Kortex Organization token for authentication (required)
64
64
  */
65
- apiToken: string
65
+ organizationToken: string
66
66
 
67
67
  /**
68
68
  * Base URL of the Kortex Hub API
69
69
  * @default 'https://kortex-dashboard.vercel.app'
70
70
  */
71
71
  baseUrl?: string
72
-
73
- /**
74
- * Optional custom fetch implementation
75
- */
76
- fetch?: typeof fetch
77
-
78
- /**
79
- * Optional request timeout in milliseconds
80
- * @default 30000 (30 seconds)
81
- */
82
- timeout?: number
83
72
  }
84
73
  ```
85
74
 
@@ -136,13 +125,13 @@ await client.sendNotification({
136
125
 
137
126
  ---
138
127
 
139
- #### `sendMessage(payload)`
128
+ #### `sendTemplate(payload)`
140
129
 
141
130
  Send a message (text, note, or template) to a WhatsApp conversation.
142
131
 
143
132
  ```typescript
144
133
  // Send a text message
145
- await client.sendMessage({
134
+ await client.sendTemplate({
146
135
  waId: '1234567890',
147
136
  message: {
148
137
  type: 'text',
@@ -150,11 +139,10 @@ await client.sendMessage({
150
139
  text: 'Hello!',
151
140
  },
152
141
  },
153
- clientName: 'John Doe', // Optional
154
142
  })
155
143
 
156
144
  // Send a template message
157
- await client.sendMessage({
145
+ await client.sendTemplate({
158
146
  waId: '1234567890',
159
147
  message: {
160
148
  type: 'template',
@@ -173,9 +161,8 @@ await client.sendMessage({
173
161
  - `message` (object, required) - Message object with type and content
174
162
  - `type`: `'text'` | `'note'` | `'template'`
175
163
  - `content`: Varies by message type
176
- - `clientName` (string, optional) - Client name for context
177
164
 
178
- **Returns:** `Promise<Result<SendMessageResponse, KortexAPIError>>`
165
+ **Returns:** `Promise<Result<SendTemplateResponse, KortexAPIError>>`
179
166
 
180
167
  ---
181
168
 
@@ -247,11 +234,9 @@ const result = await client.sendMessage({
247
234
  if (result.error) {
248
235
  // Error - access error details
249
236
  console.error('Failed:', result.error.message)
250
- console.error('Status:', result.error.statusCode)
251
- console.error('Response:', result.error.response)
252
237
  } else {
253
238
  // Success - access data
254
- console.log('Message sent:', result.data.message)
239
+ console.log('Message sent:', result.data)
255
240
  }
256
241
 
257
242
  // Or destructure for cleaner code
@@ -267,76 +252,10 @@ if (error) {
267
252
  console.log('Success:', data)
268
253
  ```
269
254
 
270
- ## Advanced Usage
271
-
272
- ### Custom Fetch Implementation
273
-
274
- ```typescript
275
- import { KortexClient } from '@kortex-ai/hub-client'
276
- import fetch from 'node-fetch'
277
-
278
- const client = new KortexClient({
279
- apiToken: 'your-token',
280
- fetch: fetch as any, // Use node-fetch in Node.js < 18
281
- })
282
- ```
283
-
284
- ### Custom Timeout
285
-
286
- ```typescript
287
- const client = new KortexClient({
288
- apiToken: 'your-token',
289
- timeout: 60000, // 60 seconds
290
- })
291
- ```
292
-
293
- ### Using with Different Environments
294
-
295
- The package works seamlessly across different JavaScript environments:
296
-
297
- ```typescript
298
- // Node.js (18+)
299
- import { KortexClient } from '@kortex-ai/hub-client'
300
-
301
- // Node.js (< 18) - install node-fetch
302
- import fetch from 'node-fetch'
303
- const client = new KortexClient({
304
- apiToken: 'token',
305
- fetch: fetch as any,
306
- })
307
-
308
- // Deno
309
- import { KortexClient } from 'npm:@kortex-ai/hub-client'
310
-
311
- // Browser
312
- import { KortexClient } from '@kortex-ai/hub-client'
313
- ```
314
-
315
- ## Type Exports
316
-
317
- All TypeScript types and schemas are exported for your convenience:
318
-
319
- ```typescript
320
- import type {
321
- AssignTagsPayload,
322
- SendMessagePayload,
323
- SendNotificationPayload,
324
- ConversationWithTags,
325
- BareNotification,
326
- // ... and more
327
- } from '@kortex-ai/hub-client'
328
-
329
- import {
330
- AssignTagsSchema,
331
- SendMessageSchema,
332
- // ... Zod schemas for validation
333
- } from '@kortex-ai/hub-client'
334
- ```
335
-
336
255
  ## License
337
256
 
338
257
  MIT
339
258
 
340
259
  ## Support
341
260
 
342
- For issues and questions, please visit [GitHub Issues](https://github.com/kortex/kortex-dashboard/issues) or contact support.
261
+ For issues and questions, please contact support.
package/dist/index.d.mts CHANGED
@@ -68,32 +68,19 @@ type SendNotificationPayload = z.infer<typeof SendNotificationSchema>;
68
68
  type SendNotificationResponse = {
69
69
  message: string;
70
70
  };
71
- declare const SendMessageSchema: z.ZodObject<{
71
+ declare const SendTemplateSchema: z.ZodObject<{
72
72
  waId: z.ZodString;
73
- message: z.ZodDiscriminatedUnion<[z.ZodObject<{
74
- type: z.ZodLiteral<"text">;
75
- content: z.ZodObject<{
76
- text: z.ZodString;
77
- }, z.core.$strip>;
78
- }, z.core.$strip>, z.ZodObject<{
79
- type: z.ZodLiteral<"note">;
80
- content: z.ZodObject<{
81
- text: z.ZodString;
82
- }, z.core.$strip>;
83
- }, z.core.$strip>, z.ZodObject<{
84
- type: z.ZodLiteral<"template">;
85
- content: z.ZodObject<{
86
- name: z.ZodString;
87
- language: z.ZodString;
88
- header_variable: z.ZodOptional<z.ZodString>;
89
- body_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
90
- button_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
91
- }, z.core.$strip>;
92
- }, z.core.$strip>], "type">;
73
+ template: z.ZodObject<{
74
+ name: z.ZodString;
75
+ language: z.ZodOptional<z.ZodString>;
76
+ header_variable: z.ZodOptional<z.ZodString>;
77
+ body_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
78
+ button_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
79
+ }, z.core.$strip>;
93
80
  clientName: z.ZodOptional<z.ZodString>;
94
81
  }, z.core.$strip>;
95
- type SendMessagePayload = z.infer<typeof SendMessageSchema>;
96
- type SendMessageResponse = {
82
+ type SendTemplatePayload = z.infer<typeof SendTemplateSchema>;
83
+ type SendTemplateResponse = {
97
84
  message: string;
98
85
  };
99
86
  declare const StopConversationAiSchema: z.ZodObject<{
@@ -115,24 +102,22 @@ type UpsertConversationResponse = {
115
102
  };
116
103
 
117
104
  interface KortexClientConfig {
105
+ /**
106
+ * Kortex Organization token
107
+ */
108
+ organizationToken: string;
118
109
  /**
119
110
  * Base URL of the Kortex Hub API
120
111
  * @default 'https://kortex-dashboard.vercel.app'
121
112
  */
122
113
  baseUrl?: string;
123
- /**
124
- * API token for authentication
125
- */
126
- apiToken: string;
127
114
  }
128
115
  type KortexAPIError = {
129
116
  message: string;
130
- statusCode?: number;
131
- response?: unknown;
132
117
  };
133
118
  declare class KortexClient {
119
+ private readonly organizationToken;
134
120
  private readonly baseUrl;
135
- private readonly apiToken;
136
121
  constructor(config: KortexClientConfig);
137
122
  /**
138
123
  * Internal method to make API requests
@@ -155,7 +140,7 @@ declare class KortexClient {
155
140
  * @param payload - The message details (waId, message type and content)
156
141
  * @returns Result with the success message or error
157
142
  */
158
- sendMessage(payload: SendMessagePayload): Promise<Result<SendMessageResponse, KortexAPIError>>;
143
+ sendTemplate(payload: SendTemplatePayload): Promise<Result<SendTemplateResponse, KortexAPIError>>;
159
144
  /**
160
145
  * Stop or start AI for a conversation
161
146
  * @param payload - The waId and stopAi boolean
@@ -170,4 +155,4 @@ declare class KortexClient {
170
155
  upsertConversation(payload: UpsertConversationPayload): Promise<Result<UpsertConversationResponse, KortexAPIError>>;
171
156
  }
172
157
 
173
- export { type AssignTagsPayload, type AssignTagsResponse, AssignTagsSchema, type KortexAPIError, KortexClient, type KortexClientConfig, type SendMessagePayload, type SendMessageResponse, SendMessageSchema, type SendNotificationPayload, type SendNotificationResponse, SendNotificationSchema, type StopConversationAiPayload, type StopConversationAiResponse, StopConversationAiSchema, type UpsertConversationPayload, type UpsertConversationResponse, UpsertConversationSchema };
158
+ export { type AssignTagsPayload, type AssignTagsResponse, type KortexAPIError, KortexClient, type KortexClientConfig, type SendNotificationPayload, type SendNotificationResponse, type SendTemplatePayload, type SendTemplateResponse, type StopConversationAiPayload, type StopConversationAiResponse, type UpsertConversationPayload, type UpsertConversationResponse };
package/dist/index.d.ts CHANGED
@@ -68,32 +68,19 @@ type SendNotificationPayload = z.infer<typeof SendNotificationSchema>;
68
68
  type SendNotificationResponse = {
69
69
  message: string;
70
70
  };
71
- declare const SendMessageSchema: z.ZodObject<{
71
+ declare const SendTemplateSchema: z.ZodObject<{
72
72
  waId: z.ZodString;
73
- message: z.ZodDiscriminatedUnion<[z.ZodObject<{
74
- type: z.ZodLiteral<"text">;
75
- content: z.ZodObject<{
76
- text: z.ZodString;
77
- }, z.core.$strip>;
78
- }, z.core.$strip>, z.ZodObject<{
79
- type: z.ZodLiteral<"note">;
80
- content: z.ZodObject<{
81
- text: z.ZodString;
82
- }, z.core.$strip>;
83
- }, z.core.$strip>, z.ZodObject<{
84
- type: z.ZodLiteral<"template">;
85
- content: z.ZodObject<{
86
- name: z.ZodString;
87
- language: z.ZodString;
88
- header_variable: z.ZodOptional<z.ZodString>;
89
- body_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
90
- button_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
91
- }, z.core.$strip>;
92
- }, z.core.$strip>], "type">;
73
+ template: z.ZodObject<{
74
+ name: z.ZodString;
75
+ language: z.ZodOptional<z.ZodString>;
76
+ header_variable: z.ZodOptional<z.ZodString>;
77
+ body_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
78
+ button_variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
79
+ }, z.core.$strip>;
93
80
  clientName: z.ZodOptional<z.ZodString>;
94
81
  }, z.core.$strip>;
95
- type SendMessagePayload = z.infer<typeof SendMessageSchema>;
96
- type SendMessageResponse = {
82
+ type SendTemplatePayload = z.infer<typeof SendTemplateSchema>;
83
+ type SendTemplateResponse = {
97
84
  message: string;
98
85
  };
99
86
  declare const StopConversationAiSchema: z.ZodObject<{
@@ -115,24 +102,22 @@ type UpsertConversationResponse = {
115
102
  };
116
103
 
117
104
  interface KortexClientConfig {
105
+ /**
106
+ * Kortex Organization token
107
+ */
108
+ organizationToken: string;
118
109
  /**
119
110
  * Base URL of the Kortex Hub API
120
111
  * @default 'https://kortex-dashboard.vercel.app'
121
112
  */
122
113
  baseUrl?: string;
123
- /**
124
- * API token for authentication
125
- */
126
- apiToken: string;
127
114
  }
128
115
  type KortexAPIError = {
129
116
  message: string;
130
- statusCode?: number;
131
- response?: unknown;
132
117
  };
133
118
  declare class KortexClient {
119
+ private readonly organizationToken;
134
120
  private readonly baseUrl;
135
- private readonly apiToken;
136
121
  constructor(config: KortexClientConfig);
137
122
  /**
138
123
  * Internal method to make API requests
@@ -155,7 +140,7 @@ declare class KortexClient {
155
140
  * @param payload - The message details (waId, message type and content)
156
141
  * @returns Result with the success message or error
157
142
  */
158
- sendMessage(payload: SendMessagePayload): Promise<Result<SendMessageResponse, KortexAPIError>>;
143
+ sendTemplate(payload: SendTemplatePayload): Promise<Result<SendTemplateResponse, KortexAPIError>>;
159
144
  /**
160
145
  * Stop or start AI for a conversation
161
146
  * @param payload - The waId and stopAi boolean
@@ -170,4 +155,4 @@ declare class KortexClient {
170
155
  upsertConversation(payload: UpsertConversationPayload): Promise<Result<UpsertConversationResponse, KortexAPIError>>;
171
156
  }
172
157
 
173
- export { type AssignTagsPayload, type AssignTagsResponse, AssignTagsSchema, type KortexAPIError, KortexClient, type KortexClientConfig, type SendMessagePayload, type SendMessageResponse, SendMessageSchema, type SendNotificationPayload, type SendNotificationResponse, SendNotificationSchema, type StopConversationAiPayload, type StopConversationAiResponse, StopConversationAiSchema, type UpsertConversationPayload, type UpsertConversationResponse, UpsertConversationSchema };
158
+ export { type AssignTagsPayload, type AssignTagsResponse, type KortexAPIError, KortexClient, type KortexClientConfig, type SendNotificationPayload, type SendNotificationResponse, type SendTemplatePayload, type SendTemplateResponse, type StopConversationAiPayload, type StopConversationAiResponse, type UpsertConversationPayload, type UpsertConversationResponse };