@kortex-ai/hub-client 0.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.
package/dist/index.mjs ADDED
@@ -0,0 +1,1125 @@
1
+ import z, { z as z$1 } from 'zod';
2
+ import * as zCore from 'zod/v4/core';
3
+ import * as z2 from 'zod/v4';
4
+
5
+ // ../src/shared/errors/neverthrow.ts
6
+ function ok(data) {
7
+ return { data, error: null };
8
+ }
9
+ function err(error) {
10
+ return { data: null, error };
11
+ }
12
+
13
+ // ../src/shared/services/http/util.ts
14
+ function prepareFetchBodyAndHeaders(body, headers) {
15
+ const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
16
+ const isBlob = typeof Blob !== "undefined" && body instanceof Blob;
17
+ const isArrayBuffer = typeof ArrayBuffer !== "undefined" && (body instanceof ArrayBuffer || ArrayBuffer.isView && ArrayBuffer.isView(body));
18
+ const shouldStringify = !isFormData && !isBlob && !isArrayBuffer && typeof body === "object";
19
+ const headersObj = { ...headers ?? {} };
20
+ if (!headersObj["Content-Type"]) {
21
+ if (shouldStringify) {
22
+ headersObj["Content-Type"] = "application/json";
23
+ } else if (isBlob) {
24
+ const blobType = body.type;
25
+ if (blobType) headersObj["Content-Type"] = blobType;
26
+ }
27
+ }
28
+ const finalBody = isFormData || isBlob || isArrayBuffer ? body : shouldStringify ? JSON.stringify(body) : body;
29
+ return {
30
+ body: finalBody,
31
+ headers: Object.keys(headersObj).length ? headersObj : void 0
32
+ };
33
+ }
34
+
35
+ // ../src/shared/services/http/http.service.ts
36
+ var HttpService = class {
37
+ static async get(url, params, headers, responseType) {
38
+ try {
39
+ const queryParams = new URLSearchParams(params);
40
+ const apiUrl = queryParams.toString() ? `${url}?${queryParams.toString()}` : url;
41
+ const response = await fetch(apiUrl, {
42
+ method: "GET",
43
+ headers
44
+ });
45
+ if (!response.ok) {
46
+ const message = await response.text();
47
+ return err({ message });
48
+ }
49
+ if (responseType === "blob") {
50
+ return ok(await response.blob());
51
+ }
52
+ if (responseType === "text") {
53
+ return ok(await response.text());
54
+ }
55
+ return ok(await response.json());
56
+ } catch (error) {
57
+ return err({ message: error.message });
58
+ }
59
+ }
60
+ static async post(url, body, headers, credentials) {
61
+ try {
62
+ const { body: finalBody, headers: finalHeaders } = prepareFetchBodyAndHeaders(body, headers);
63
+ const response = await fetch(url, {
64
+ method: "POST",
65
+ headers: finalHeaders,
66
+ body: finalBody,
67
+ credentials
68
+ });
69
+ if (!response.ok) {
70
+ const message = await response.text();
71
+ return err({ message });
72
+ }
73
+ return ok(await response.json());
74
+ } catch (error) {
75
+ return err({ message: error.message });
76
+ }
77
+ }
78
+ static async put(url, body, headers) {
79
+ try {
80
+ const { body: finalBody, headers: finalHeaders } = prepareFetchBodyAndHeaders(body, headers);
81
+ const response = await fetch(url, {
82
+ method: "PUT",
83
+ headers: finalHeaders,
84
+ body: finalBody
85
+ });
86
+ if (!response.ok) {
87
+ const message = await response.text();
88
+ return err({ message });
89
+ }
90
+ return ok(await response.json());
91
+ } catch (error) {
92
+ return err({ message: error.message });
93
+ }
94
+ }
95
+ static async delete(url, params, headers) {
96
+ try {
97
+ const queryParams = new URLSearchParams(params);
98
+ const apiUrl = queryParams.toString() ? `${url}?${queryParams.toString()}` : url;
99
+ const response = await fetch(apiUrl, {
100
+ method: "DELETE",
101
+ headers
102
+ });
103
+ if (!response.ok) {
104
+ const message = await response.text();
105
+ return err({ message });
106
+ }
107
+ return ok(await response.json());
108
+ } catch (error) {
109
+ return err({ message: error.message });
110
+ }
111
+ }
112
+ };
113
+ var TextContent = z.object({
114
+ text: z.string()
115
+ });
116
+ z.object({
117
+ id: z.string(),
118
+ mime_type: z.string(),
119
+ sha256: z.string(),
120
+ caption: z.string().nullable()
121
+ });
122
+ z.object({
123
+ id: z.string(),
124
+ mime_type: z.string(),
125
+ sha256: z.string(),
126
+ caption: z.string().nullable()
127
+ });
128
+ z.object({
129
+ id: z.string(),
130
+ mime_type: z.string(),
131
+ sha256: z.string(),
132
+ animated: z.boolean().nullable()
133
+ });
134
+ z.object({
135
+ id: z.string(),
136
+ mime_type: z.string(),
137
+ sha256: z.string(),
138
+ voice: z.boolean()
139
+ });
140
+ z.object({
141
+ id: z.string(),
142
+ mime_type: z.string(),
143
+ sha256: z.string(),
144
+ filename: z.string(),
145
+ caption: z.string().nullable()
146
+ });
147
+ z.object({
148
+ latitude: z.number(),
149
+ longitude: z.number(),
150
+ name: z.string().nullable(),
151
+ address: z.string().nullable(),
152
+ url: z.string().nullable()
153
+ });
154
+ z.object({
155
+ name: z.object({
156
+ formatted_name: z.string().nullable(),
157
+ first_name: z.string().nullable(),
158
+ last_name: z.string().nullable(),
159
+ middle_name: z.string().nullable(),
160
+ suffix: z.string().nullable(),
161
+ prefix: z.string().nullable()
162
+ }),
163
+ phones: z.array(
164
+ z.object({
165
+ phone: z.string().nullable(),
166
+ type: z.string().nullable(),
167
+ wa_id: z.string().nullable()
168
+ })
169
+ ).nullable()
170
+ });
171
+ z.object({
172
+ emoji: z.string().nullable()
173
+ });
174
+ var TemplateContent = z.object({
175
+ name: z.string(),
176
+ language: z.string(),
177
+ renderedText: z.string(),
178
+ // The rendered template text with variables filled in.
179
+ header_variable: z.string().optional(),
180
+ // Single variable for header component (only {{1}} is supported). Not saved in DB.
181
+ body_variables: z.array(z.string()).optional(),
182
+ // Variables for the body component {{1}}, {{2}}, etc. Not saved in DB.
183
+ button_variables: z.array(z.string()).max(2).optional()
184
+ // Variables for URL buttons in order. Each URL button can have max 1 variable. Not saved in DB.
185
+ });
186
+
187
+ // ../node_modules/.pnpm/convex@1.31.6_react@19.2.0/node_modules/convex/dist/esm/values/base64.js
188
+ var lookup = [];
189
+ var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
190
+ for (i = 0, len = code.length; i < len; ++i) {
191
+ lookup[i] = code[i];
192
+ }
193
+ var i;
194
+ var len;
195
+ function tripletToBase64(num) {
196
+ return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
197
+ }
198
+ function encodeChunk(uint8, start, end) {
199
+ var tmp;
200
+ var output = [];
201
+ for (var i = start; i < end; i += 3) {
202
+ tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);
203
+ output.push(tripletToBase64(tmp));
204
+ }
205
+ return output.join("");
206
+ }
207
+ function fromByteArray(uint8) {
208
+ var tmp;
209
+ var len = uint8.length;
210
+ var extraBytes = len % 3;
211
+ var parts = [];
212
+ var maxChunkLength = 16383;
213
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
214
+ parts.push(
215
+ encodeChunk(
216
+ uint8,
217
+ i,
218
+ i + maxChunkLength > len2 ? len2 : i + maxChunkLength
219
+ )
220
+ );
221
+ }
222
+ if (extraBytes === 1) {
223
+ tmp = uint8[len - 1];
224
+ parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
225
+ } else if (extraBytes === 2) {
226
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
227
+ parts.push(
228
+ lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
229
+ );
230
+ }
231
+ return parts.join("");
232
+ }
233
+
234
+ // ../node_modules/.pnpm/convex@1.31.6_react@19.2.0/node_modules/convex/dist/esm/common/index.js
235
+ function isSimpleObject(value) {
236
+ const isObject = typeof value === "object";
237
+ const prototype = Object.getPrototypeOf(value);
238
+ const isSimple = prototype === null || prototype === Object.prototype || // Objects generated from other contexts (e.g. across Node.js `vm` modules) will not satisfy the previous
239
+ // conditions but are still simple objects.
240
+ prototype?.constructor?.name === "Object";
241
+ return isObject && isSimple;
242
+ }
243
+
244
+ // ../node_modules/.pnpm/convex@1.31.6_react@19.2.0/node_modules/convex/dist/esm/values/value.js
245
+ var LITTLE_ENDIAN = true;
246
+ var MIN_INT64 = BigInt("-9223372036854775808");
247
+ var MAX_INT64 = BigInt("9223372036854775807");
248
+ var ZERO = BigInt("0");
249
+ var EIGHT = BigInt("8");
250
+ BigInt("256");
251
+ function isSpecial(n) {
252
+ return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
253
+ }
254
+ function slowBigIntToBase64(value) {
255
+ if (value < ZERO) {
256
+ value -= MIN_INT64 + MIN_INT64;
257
+ }
258
+ let hex = value.toString(16);
259
+ if (hex.length % 2 === 1) hex = "0" + hex;
260
+ const bytes2 = new Uint8Array(new ArrayBuffer(8));
261
+ let i = 0;
262
+ for (const hexByte of hex.match(/.{2}/g).reverse()) {
263
+ bytes2.set([parseInt(hexByte, 16)], i++);
264
+ value >>= EIGHT;
265
+ }
266
+ return fromByteArray(bytes2);
267
+ }
268
+ function modernBigIntToBase64(value) {
269
+ if (value < MIN_INT64 || MAX_INT64 < value) {
270
+ throw new Error(
271
+ `BigInt ${value} does not fit into a 64-bit signed integer.`
272
+ );
273
+ }
274
+ const buffer = new ArrayBuffer(8);
275
+ new DataView(buffer).setBigInt64(0, value, true);
276
+ return fromByteArray(new Uint8Array(buffer));
277
+ }
278
+ var bigIntToBase64 = DataView.prototype.setBigInt64 ? modernBigIntToBase64 : slowBigIntToBase64;
279
+ var MAX_IDENTIFIER_LEN = 1024;
280
+ function validateObjectField(k) {
281
+ if (k.length > MAX_IDENTIFIER_LEN) {
282
+ throw new Error(
283
+ `Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`
284
+ );
285
+ }
286
+ if (k.startsWith("$")) {
287
+ throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
288
+ }
289
+ for (let i = 0; i < k.length; i += 1) {
290
+ const charCode = k.charCodeAt(i);
291
+ if (charCode < 32 || charCode >= 127) {
292
+ throw new Error(
293
+ `Field name ${k} has invalid character '${k[i]}': Field names can only contain non-control ASCII characters`
294
+ );
295
+ }
296
+ }
297
+ }
298
+ var MAX_VALUE_FOR_ERROR_LEN = 16384;
299
+ function stringifyValueForError(value) {
300
+ const str = JSON.stringify(value, (_key, value2) => {
301
+ if (value2 === void 0) {
302
+ return "undefined";
303
+ }
304
+ if (typeof value2 === "bigint") {
305
+ return `${value2.toString()}n`;
306
+ }
307
+ return value2;
308
+ });
309
+ if (str.length > MAX_VALUE_FOR_ERROR_LEN) {
310
+ const rest = "[...truncated]";
311
+ let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest.length;
312
+ const codePoint = str.codePointAt(truncateAt - 1);
313
+ if (codePoint !== void 0 && codePoint > 65535) {
314
+ truncateAt -= 1;
315
+ }
316
+ return str.substring(0, truncateAt) + rest;
317
+ }
318
+ return str;
319
+ }
320
+ function convexToJsonInternal(value, originalValue, context, includeTopLevelUndefined) {
321
+ if (value === void 0) {
322
+ const contextText = context && ` (present at path ${context} in original object ${stringifyValueForError(
323
+ originalValue
324
+ )})`;
325
+ throw new Error(
326
+ `undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`
327
+ );
328
+ }
329
+ if (value === null) {
330
+ return value;
331
+ }
332
+ if (typeof value === "bigint") {
333
+ if (value < MIN_INT64 || MAX_INT64 < value) {
334
+ throw new Error(
335
+ `BigInt ${value} does not fit into a 64-bit signed integer.`
336
+ );
337
+ }
338
+ return { $integer: bigIntToBase64(value) };
339
+ }
340
+ if (typeof value === "number") {
341
+ if (isSpecial(value)) {
342
+ const buffer = new ArrayBuffer(8);
343
+ new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);
344
+ return { $float: fromByteArray(new Uint8Array(buffer)) };
345
+ } else {
346
+ return value;
347
+ }
348
+ }
349
+ if (typeof value === "boolean") {
350
+ return value;
351
+ }
352
+ if (typeof value === "string") {
353
+ return value;
354
+ }
355
+ if (value instanceof ArrayBuffer) {
356
+ return { $bytes: fromByteArray(new Uint8Array(value)) };
357
+ }
358
+ if (Array.isArray(value)) {
359
+ return value.map(
360
+ (value2, i) => convexToJsonInternal(value2, originalValue, context + `[${i}]`)
361
+ );
362
+ }
363
+ if (value instanceof Set) {
364
+ throw new Error(
365
+ errorMessageForUnsupportedType(context, "Set", [...value], originalValue)
366
+ );
367
+ }
368
+ if (value instanceof Map) {
369
+ throw new Error(
370
+ errorMessageForUnsupportedType(context, "Map", [...value], originalValue)
371
+ );
372
+ }
373
+ if (!isSimpleObject(value)) {
374
+ const theType = value?.constructor?.name;
375
+ const typeName = theType ? `${theType} ` : "";
376
+ throw new Error(
377
+ errorMessageForUnsupportedType(context, typeName, value, originalValue)
378
+ );
379
+ }
380
+ const out = {};
381
+ const entries = Object.entries(value);
382
+ entries.sort(([k1, _v1], [k2, _v2]) => k1 === k2 ? 0 : k1 < k2 ? -1 : 1);
383
+ for (const [k, v2] of entries) {
384
+ if (v2 !== void 0) {
385
+ validateObjectField(k);
386
+ out[k] = convexToJsonInternal(v2, originalValue, context + `.${k}`);
387
+ }
388
+ }
389
+ return out;
390
+ }
391
+ function errorMessageForUnsupportedType(context, typeName, value, originalValue) {
392
+ if (context) {
393
+ return `${typeName}${stringifyValueForError(
394
+ value
395
+ )} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError(
396
+ originalValue
397
+ )}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;
398
+ } else {
399
+ return `${typeName}${stringifyValueForError(
400
+ value
401
+ )} is not a supported Convex type.`;
402
+ }
403
+ }
404
+ function convexToJson(value) {
405
+ return convexToJsonInternal(value, value, "");
406
+ }
407
+
408
+ // ../node_modules/.pnpm/convex@1.31.6_react@19.2.0/node_modules/convex/dist/esm/values/validators.js
409
+ var __defProp = Object.defineProperty;
410
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
411
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
412
+ var UNDEFINED_VALIDATOR_ERROR_URL = "https://docs.convex.dev/error#undefined-validator";
413
+ function throwUndefinedValidatorError(context, fieldName) {
414
+ const fieldInfo = fieldName !== void 0 ? ` for field "${fieldName}"` : "";
415
+ throw new Error(
416
+ `A validator is undefined${fieldInfo} in ${context}. This is often caused by circular imports. See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`
417
+ );
418
+ }
419
+ var BaseValidator = class {
420
+ constructor({ isOptional }) {
421
+ __publicField(this, "type");
422
+ __publicField(this, "fieldPaths");
423
+ __publicField(this, "isOptional");
424
+ __publicField(this, "isConvexValidator");
425
+ this.isOptional = isOptional;
426
+ this.isConvexValidator = true;
427
+ }
428
+ };
429
+ var VId = class _VId extends BaseValidator {
430
+ /**
431
+ * Usually you'd use `v.id(tableName)` instead.
432
+ */
433
+ constructor({
434
+ isOptional,
435
+ tableName
436
+ }) {
437
+ super({ isOptional });
438
+ __publicField(this, "tableName");
439
+ __publicField(this, "kind", "id");
440
+ if (typeof tableName !== "string") {
441
+ throw new Error("v.id(tableName) requires a string");
442
+ }
443
+ this.tableName = tableName;
444
+ }
445
+ /** @internal */
446
+ get json() {
447
+ return { type: "id", tableName: this.tableName };
448
+ }
449
+ /** @internal */
450
+ asOptional() {
451
+ return new _VId({
452
+ isOptional: "optional",
453
+ tableName: this.tableName
454
+ });
455
+ }
456
+ };
457
+ var VFloat64 = class _VFloat64 extends BaseValidator {
458
+ constructor() {
459
+ super(...arguments);
460
+ __publicField(this, "kind", "float64");
461
+ }
462
+ /** @internal */
463
+ get json() {
464
+ return { type: "number" };
465
+ }
466
+ /** @internal */
467
+ asOptional() {
468
+ return new _VFloat64({
469
+ isOptional: "optional"
470
+ });
471
+ }
472
+ };
473
+ var VInt64 = class _VInt64 extends BaseValidator {
474
+ constructor() {
475
+ super(...arguments);
476
+ __publicField(this, "kind", "int64");
477
+ }
478
+ /** @internal */
479
+ get json() {
480
+ return { type: "bigint" };
481
+ }
482
+ /** @internal */
483
+ asOptional() {
484
+ return new _VInt64({ isOptional: "optional" });
485
+ }
486
+ };
487
+ var VBoolean = class _VBoolean extends BaseValidator {
488
+ constructor() {
489
+ super(...arguments);
490
+ __publicField(this, "kind", "boolean");
491
+ }
492
+ /** @internal */
493
+ get json() {
494
+ return { type: this.kind };
495
+ }
496
+ /** @internal */
497
+ asOptional() {
498
+ return new _VBoolean({
499
+ isOptional: "optional"
500
+ });
501
+ }
502
+ };
503
+ var VBytes = class _VBytes extends BaseValidator {
504
+ constructor() {
505
+ super(...arguments);
506
+ __publicField(this, "kind", "bytes");
507
+ }
508
+ /** @internal */
509
+ get json() {
510
+ return { type: this.kind };
511
+ }
512
+ /** @internal */
513
+ asOptional() {
514
+ return new _VBytes({ isOptional: "optional" });
515
+ }
516
+ };
517
+ var VString = class _VString extends BaseValidator {
518
+ constructor() {
519
+ super(...arguments);
520
+ __publicField(this, "kind", "string");
521
+ }
522
+ /** @internal */
523
+ get json() {
524
+ return { type: this.kind };
525
+ }
526
+ /** @internal */
527
+ asOptional() {
528
+ return new _VString({
529
+ isOptional: "optional"
530
+ });
531
+ }
532
+ };
533
+ var VNull = class _VNull extends BaseValidator {
534
+ constructor() {
535
+ super(...arguments);
536
+ __publicField(this, "kind", "null");
537
+ }
538
+ /** @internal */
539
+ get json() {
540
+ return { type: this.kind };
541
+ }
542
+ /** @internal */
543
+ asOptional() {
544
+ return new _VNull({ isOptional: "optional" });
545
+ }
546
+ };
547
+ var VAny = class _VAny extends BaseValidator {
548
+ constructor() {
549
+ super(...arguments);
550
+ __publicField(this, "kind", "any");
551
+ }
552
+ /** @internal */
553
+ get json() {
554
+ return {
555
+ type: this.kind
556
+ };
557
+ }
558
+ /** @internal */
559
+ asOptional() {
560
+ return new _VAny({
561
+ isOptional: "optional"
562
+ });
563
+ }
564
+ };
565
+ var VObject = class _VObject extends BaseValidator {
566
+ /**
567
+ * Usually you'd use `v.object({ ... })` instead.
568
+ */
569
+ constructor({
570
+ isOptional,
571
+ fields
572
+ }) {
573
+ super({ isOptional });
574
+ __publicField(this, "fields");
575
+ __publicField(this, "kind", "object");
576
+ globalThis.Object.entries(fields).forEach(([fieldName, validator]) => {
577
+ if (validator === void 0) {
578
+ throwUndefinedValidatorError("v.object()", fieldName);
579
+ }
580
+ if (!validator.isConvexValidator) {
581
+ throw new Error("v.object() entries must be validators");
582
+ }
583
+ });
584
+ this.fields = fields;
585
+ }
586
+ /** @internal */
587
+ get json() {
588
+ return {
589
+ type: this.kind,
590
+ value: globalThis.Object.fromEntries(
591
+ globalThis.Object.entries(this.fields).map(([k, v2]) => [
592
+ k,
593
+ {
594
+ fieldType: v2.json,
595
+ optional: v2.isOptional === "optional" ? true : false
596
+ }
597
+ ])
598
+ )
599
+ };
600
+ }
601
+ /** @internal */
602
+ asOptional() {
603
+ return new _VObject({
604
+ isOptional: "optional",
605
+ fields: this.fields
606
+ });
607
+ }
608
+ /**
609
+ * Create a new VObject with the specified fields omitted.
610
+ * @param fields The field names to omit from this VObject.
611
+ */
612
+ omit(...fields) {
613
+ const newFields = { ...this.fields };
614
+ for (const field of fields) {
615
+ delete newFields[field];
616
+ }
617
+ return new _VObject({
618
+ isOptional: this.isOptional,
619
+ fields: newFields
620
+ });
621
+ }
622
+ /**
623
+ * Create a new VObject with only the specified fields.
624
+ * @param fields The field names to pick from this VObject.
625
+ */
626
+ pick(...fields) {
627
+ const newFields = {};
628
+ for (const field of fields) {
629
+ newFields[field] = this.fields[field];
630
+ }
631
+ return new _VObject({
632
+ isOptional: this.isOptional,
633
+ fields: newFields
634
+ });
635
+ }
636
+ /**
637
+ * Create a new VObject with all fields marked as optional.
638
+ */
639
+ partial() {
640
+ const newFields = {};
641
+ for (const [key, validator] of globalThis.Object.entries(this.fields)) {
642
+ newFields[key] = validator.asOptional();
643
+ }
644
+ return new _VObject({
645
+ isOptional: this.isOptional,
646
+ fields: newFields
647
+ });
648
+ }
649
+ /**
650
+ * Create a new VObject with additional fields merged in.
651
+ * @param fields An object with additional validators to merge into this VObject.
652
+ */
653
+ extend(fields) {
654
+ return new _VObject({
655
+ isOptional: this.isOptional,
656
+ fields: { ...this.fields, ...fields }
657
+ });
658
+ }
659
+ };
660
+ var VLiteral = class _VLiteral extends BaseValidator {
661
+ /**
662
+ * Usually you'd use `v.literal(value)` instead.
663
+ */
664
+ constructor({ isOptional, value }) {
665
+ super({ isOptional });
666
+ __publicField(this, "value");
667
+ __publicField(this, "kind", "literal");
668
+ if (typeof value !== "string" && typeof value !== "boolean" && typeof value !== "number" && typeof value !== "bigint") {
669
+ throw new Error("v.literal(value) must be a string, number, or boolean");
670
+ }
671
+ this.value = value;
672
+ }
673
+ /** @internal */
674
+ get json() {
675
+ return {
676
+ type: this.kind,
677
+ value: convexToJson(this.value)
678
+ };
679
+ }
680
+ /** @internal */
681
+ asOptional() {
682
+ return new _VLiteral({
683
+ isOptional: "optional",
684
+ value: this.value
685
+ });
686
+ }
687
+ };
688
+ var VArray = class _VArray extends BaseValidator {
689
+ /**
690
+ * Usually you'd use `v.array(element)` instead.
691
+ */
692
+ constructor({
693
+ isOptional,
694
+ element
695
+ }) {
696
+ super({ isOptional });
697
+ __publicField(this, "element");
698
+ __publicField(this, "kind", "array");
699
+ if (element === void 0) {
700
+ throwUndefinedValidatorError("v.array()");
701
+ }
702
+ this.element = element;
703
+ }
704
+ /** @internal */
705
+ get json() {
706
+ return {
707
+ type: this.kind,
708
+ value: this.element.json
709
+ };
710
+ }
711
+ /** @internal */
712
+ asOptional() {
713
+ return new _VArray({
714
+ isOptional: "optional",
715
+ element: this.element
716
+ });
717
+ }
718
+ };
719
+ var VRecord = class _VRecord extends BaseValidator {
720
+ /**
721
+ * Usually you'd use `v.record(key, value)` instead.
722
+ */
723
+ constructor({
724
+ isOptional,
725
+ key,
726
+ value
727
+ }) {
728
+ super({ isOptional });
729
+ __publicField(this, "key");
730
+ __publicField(this, "value");
731
+ __publicField(this, "kind", "record");
732
+ if (key === void 0) {
733
+ throwUndefinedValidatorError("v.record()", "key");
734
+ }
735
+ if (value === void 0) {
736
+ throwUndefinedValidatorError("v.record()", "value");
737
+ }
738
+ if (key.isOptional === "optional") {
739
+ throw new Error("Record validator cannot have optional keys");
740
+ }
741
+ if (value.isOptional === "optional") {
742
+ throw new Error("Record validator cannot have optional values");
743
+ }
744
+ if (!key.isConvexValidator || !value.isConvexValidator) {
745
+ throw new Error("Key and value of v.record() but be validators");
746
+ }
747
+ this.key = key;
748
+ this.value = value;
749
+ }
750
+ /** @internal */
751
+ get json() {
752
+ return {
753
+ type: this.kind,
754
+ // This cast is needed because TypeScript thinks the key type is too wide
755
+ keys: this.key.json,
756
+ values: {
757
+ fieldType: this.value.json,
758
+ optional: false
759
+ }
760
+ };
761
+ }
762
+ /** @internal */
763
+ asOptional() {
764
+ return new _VRecord({
765
+ isOptional: "optional",
766
+ key: this.key,
767
+ value: this.value
768
+ });
769
+ }
770
+ };
771
+ var VUnion = class _VUnion extends BaseValidator {
772
+ /**
773
+ * Usually you'd use `v.union(...members)` instead.
774
+ */
775
+ constructor({ isOptional, members }) {
776
+ super({ isOptional });
777
+ __publicField(this, "members");
778
+ __publicField(this, "kind", "union");
779
+ members.forEach((member, index) => {
780
+ if (member === void 0) {
781
+ throwUndefinedValidatorError("v.union()", `member at index ${index}`);
782
+ }
783
+ if (!member.isConvexValidator) {
784
+ throw new Error("All members of v.union() must be validators");
785
+ }
786
+ });
787
+ this.members = members;
788
+ }
789
+ /** @internal */
790
+ get json() {
791
+ return {
792
+ type: this.kind,
793
+ value: this.members.map((v2) => v2.json)
794
+ };
795
+ }
796
+ /** @internal */
797
+ asOptional() {
798
+ return new _VUnion({
799
+ isOptional: "optional",
800
+ members: this.members
801
+ });
802
+ }
803
+ };
804
+
805
+ // ../node_modules/.pnpm/convex@1.31.6_react@19.2.0/node_modules/convex/dist/esm/values/validator.js
806
+ var v = {
807
+ /**
808
+ * Validates that the value corresponds to an ID of a document in given table.
809
+ * @param tableName The name of the table.
810
+ */
811
+ id: (tableName) => {
812
+ return new VId({
813
+ isOptional: "required",
814
+ tableName
815
+ });
816
+ },
817
+ /**
818
+ * Validates that the value is of type Null.
819
+ */
820
+ null: () => {
821
+ return new VNull({ isOptional: "required" });
822
+ },
823
+ /**
824
+ * Validates that the value is of Convex type Float64 (Number in JS).
825
+ *
826
+ * Alias for `v.float64()`
827
+ */
828
+ number: () => {
829
+ return new VFloat64({ isOptional: "required" });
830
+ },
831
+ /**
832
+ * Validates that the value is of Convex type Float64 (Number in JS).
833
+ */
834
+ float64: () => {
835
+ return new VFloat64({ isOptional: "required" });
836
+ },
837
+ /**
838
+ * @deprecated Use `v.int64()` instead
839
+ */
840
+ bigint: () => {
841
+ return new VInt64({ isOptional: "required" });
842
+ },
843
+ /**
844
+ * Validates that the value is of Convex type Int64 (BigInt in JS).
845
+ */
846
+ int64: () => {
847
+ return new VInt64({ isOptional: "required" });
848
+ },
849
+ /**
850
+ * Validates that the value is of type Boolean.
851
+ */
852
+ boolean: () => {
853
+ return new VBoolean({ isOptional: "required" });
854
+ },
855
+ /**
856
+ * Validates that the value is of type String.
857
+ */
858
+ string: () => {
859
+ return new VString({ isOptional: "required" });
860
+ },
861
+ /**
862
+ * Validates that the value is of Convex type Bytes (constructed in JS via `ArrayBuffer`).
863
+ */
864
+ bytes: () => {
865
+ return new VBytes({ isOptional: "required" });
866
+ },
867
+ /**
868
+ * Validates that the value is equal to the given literal value.
869
+ * @param literal The literal value to compare against.
870
+ */
871
+ literal: (literal3) => {
872
+ return new VLiteral({ isOptional: "required", value: literal3 });
873
+ },
874
+ /**
875
+ * Validates that the value is an Array of the given element type.
876
+ * @param element The validator for the elements of the array.
877
+ */
878
+ array: (element) => {
879
+ return new VArray({ isOptional: "required", element });
880
+ },
881
+ /**
882
+ * Validates that the value is an Object with the given properties.
883
+ * @param fields An object specifying the validator for each property.
884
+ */
885
+ object: (fields) => {
886
+ return new VObject({ isOptional: "required", fields });
887
+ },
888
+ /**
889
+ * Validates that the value is a Record with keys and values that match the given types.
890
+ * @param keys The validator for the keys of the record. This cannot contain string literals.
891
+ * @param values The validator for the values of the record.
892
+ */
893
+ record: (keys, values) => {
894
+ return new VRecord({
895
+ isOptional: "required",
896
+ key: keys,
897
+ value: values
898
+ });
899
+ },
900
+ /**
901
+ * Validates that the value matches one of the given validators.
902
+ * @param members The validators to match against.
903
+ */
904
+ union: (...members) => {
905
+ return new VUnion({
906
+ isOptional: "required",
907
+ members
908
+ });
909
+ },
910
+ /**
911
+ * Does not validate the value.
912
+ */
913
+ any: () => {
914
+ return new VAny({ isOptional: "required" });
915
+ },
916
+ /**
917
+ * Allows not specifying a value for a property in an Object.
918
+ * @param value The property value validator to make optional.
919
+ *
920
+ * ```typescript
921
+ * const objectWithOptionalFields = v.object({
922
+ * requiredField: v.string(),
923
+ * optionalField: v.optional(v.string()),
924
+ * });
925
+ * ```
926
+ */
927
+ optional: (value) => {
928
+ return value.asOptional();
929
+ },
930
+ /**
931
+ * Allows specifying a value or null.
932
+ */
933
+ nullable: (value) => {
934
+ return v.union(value, v.null());
935
+ }
936
+ };
937
+
938
+ // ../node_modules/.pnpm/convex@1.31.6_react@19.2.0/node_modules/convex/dist/esm/values/compare_utf8.js
939
+ var arr = () => Array.from({ length: 4 }, () => 0);
940
+ arr();
941
+ arr();
942
+
943
+ // ../node_modules/.pnpm/convex-helpers@0.1.111_@sta_93c457dc952a51f4edfd5f2327f1d7a5/node_modules/convex-helpers/validators.js
944
+ v.string();
945
+ v.float64();
946
+ v.float64();
947
+ v.boolean();
948
+ v.int64();
949
+ v.int64();
950
+ v.any();
951
+ v.null();
952
+ v.bytes();
953
+ v.optional(v.any());
954
+
955
+ // ../node_modules/.pnpm/convex-helpers@0.1.111_@sta_93c457dc952a51f4edfd5f2327f1d7a5/node_modules/convex-helpers/server/zod4.js
956
+ var zid = (tableName) => {
957
+ const result = z2.custom((val) => typeof val === "string");
958
+ _zidRegistry.add(result, { tableName });
959
+ return result;
960
+ };
961
+ var _zidRegistry = zCore.registry();
962
+ var BaseDocumentSchema = (tableName) => z$1.object({
963
+ _id: zid(tableName),
964
+ _creationTime: z$1.number()
965
+ });
966
+
967
+ // ../src/shared/types/convex/notification/notification.ts
968
+ var BaseNotificationSchema = BaseDocumentSchema("notifications").extend({
969
+ organizationId: zid("organizations"),
970
+ read: z$1.boolean(),
971
+ title: z$1.string().min(1),
972
+ message: z$1.string()
973
+ });
974
+ var GeneralNotificationSchema = BaseNotificationSchema.extend({
975
+ category: z$1.literal("general"),
976
+ link: z$1.url().nullable()
977
+ });
978
+ var ChatNotificationSchema = BaseNotificationSchema.extend({
979
+ category: z$1.literal("chat"),
980
+ conversationId: zid("conversations")
981
+ });
982
+ var SpacesNotificationSchema = BaseNotificationSchema.extend({
983
+ category: z$1.literal("spaces"),
984
+ spaceUrlPath: z$1.string()
985
+ });
986
+ z$1.discriminatedUnion("category", [
987
+ GeneralNotificationSchema,
988
+ ChatNotificationSchema,
989
+ SpacesNotificationSchema
990
+ ]);
991
+ var omitFields = { _id: true, _creationTime: true, organizationId: true, read: true };
992
+ var BareGeneralNotificationSchema = GeneralNotificationSchema.omit(omitFields);
993
+ var BareChatNotificationSchema = ChatNotificationSchema.omit(omitFields);
994
+ var BareSpacesNotificationSchema = SpacesNotificationSchema.omit(omitFields);
995
+ var BareNotificationSchema = z.discriminatedUnion("category", [
996
+ BareGeneralNotificationSchema,
997
+ BareChatNotificationSchema,
998
+ BareSpacesNotificationSchema
999
+ ]);
1000
+ var AssignTagsSchema = z$1.object({
1001
+ waId: z$1.string().min(1, "WhatsApp ID is required"),
1002
+ tags: z$1.array(z$1.string()).min(1, "At least one tag is required")
1003
+ });
1004
+ var SEND_OPTIONS = ["dashboard", "email", "push"];
1005
+ var SendNotificationSchema = z$1.object({
1006
+ sendOptions: z$1.array(z$1.enum(SEND_OPTIONS)).min(1),
1007
+ notification: BareNotificationSchema
1008
+ });
1009
+ var SendMessageSchema = z$1.object({
1010
+ waId: z$1.string().min(1, "WhatsApp ID is required"),
1011
+ message: z$1.discriminatedUnion("type", [
1012
+ z$1.object({
1013
+ type: z$1.literal("text"),
1014
+ content: TextContent
1015
+ }),
1016
+ z$1.object({
1017
+ type: z$1.literal("note"),
1018
+ content: TextContent
1019
+ }),
1020
+ z$1.object({
1021
+ type: z$1.literal("template"),
1022
+ content: TemplateContent.omit({ renderedText: true })
1023
+ })
1024
+ ]),
1025
+ clientName: z$1.string().optional()
1026
+ });
1027
+ var StopConversationAiSchema = z$1.object({
1028
+ waId: z$1.string().min(1, "WhatsApp ID is required"),
1029
+ stopAi: z$1.boolean()
1030
+ });
1031
+ var UpsertConversationSchema = z$1.object({
1032
+ waId: z$1.string().min(1, "WhatsApp ID is required"),
1033
+ clientName: z$1.string().min(1, "Client name is required")
1034
+ });
1035
+
1036
+ // src/client.ts
1037
+ var KortexClient = class {
1038
+ constructor(config) {
1039
+ this.baseUrl = config.baseUrl || "https://kortex-dashboard.vercel.app";
1040
+ this.apiToken = config.apiToken;
1041
+ }
1042
+ /**
1043
+ * Internal method to make API requests
1044
+ */
1045
+ async request(endpoint, payload) {
1046
+ const result = await HttpService.post(`${this.baseUrl}${endpoint}`, payload, {
1047
+ Authorization: `Bearer ${this.apiToken}`
1048
+ });
1049
+ if (result.error) {
1050
+ return err({
1051
+ message: result.error.message
1052
+ });
1053
+ }
1054
+ return ok(result.data);
1055
+ }
1056
+ /**
1057
+ * Assign tags to a conversation
1058
+ * @param payload - The waId and tags to assign
1059
+ * @returns Result with the success message or error
1060
+ */
1061
+ async assignTags(payload) {
1062
+ try {
1063
+ const validated = AssignTagsSchema.parse(payload);
1064
+ return this.request("/api/external/assign-tags", validated);
1065
+ } catch (error) {
1066
+ return err({ message: error instanceof Error ? error.message : "Validation error" });
1067
+ }
1068
+ }
1069
+ /**
1070
+ * Send a notification through specified channels
1071
+ * @param payload - The notification and send options
1072
+ * @returns Result with the success message or error
1073
+ */
1074
+ async sendNotification(payload) {
1075
+ try {
1076
+ const validated = SendNotificationSchema.parse(payload);
1077
+ return this.request("/api/external/send-notification", validated);
1078
+ } catch (error) {
1079
+ return err({ message: error instanceof Error ? error.message : "Validation error" });
1080
+ }
1081
+ }
1082
+ /**
1083
+ * Send a message (text, note, or template) to a WhatsApp conversation
1084
+ * @param payload - The message details (waId, message type and content)
1085
+ * @returns Result with the success message or error
1086
+ */
1087
+ async sendMessage(payload) {
1088
+ try {
1089
+ const validated = SendMessageSchema.parse(payload);
1090
+ return this.request("/api/external/send-template", validated);
1091
+ } catch (error) {
1092
+ return err({ message: error instanceof Error ? error.message : "Validation error" });
1093
+ }
1094
+ }
1095
+ /**
1096
+ * Stop or start AI for a conversation
1097
+ * @param payload - The waId and stopAi boolean
1098
+ * @returns Result with the success message or error
1099
+ */
1100
+ async stopConversationAi(payload) {
1101
+ try {
1102
+ const validated = StopConversationAiSchema.parse(payload);
1103
+ return this.request("/api/external/stop-conversation-ai", validated);
1104
+ } catch (error) {
1105
+ return err({ message: error instanceof Error ? error.message : "Validation error" });
1106
+ }
1107
+ }
1108
+ /**
1109
+ * Create or update a conversation
1110
+ * @param payload - The waId and client name
1111
+ * @returns Result with the conversation data or error
1112
+ */
1113
+ async upsertConversation(payload) {
1114
+ try {
1115
+ const validated = UpsertConversationSchema.parse(payload);
1116
+ return this.request("/api/external/upsert-conversation", validated);
1117
+ } catch (error) {
1118
+ return err({ message: error instanceof Error ? error.message : "Validation error" });
1119
+ }
1120
+ }
1121
+ };
1122
+
1123
+ export { AssignTagsSchema, KortexClient, SendMessageSchema, SendNotificationSchema, StopConversationAiSchema, UpsertConversationSchema };
1124
+ //# sourceMappingURL=index.mjs.map
1125
+ //# sourceMappingURL=index.mjs.map