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