@cossistant/core 0.0.26 → 0.0.28
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/client.d.ts +37 -5
- package/client.d.ts.map +1 -1
- package/client.js +18 -0
- package/client.js.map +1 -1
- package/conversation.d.ts +3 -0
- package/conversation.d.ts.map +1 -1
- package/index.d.ts +6 -4
- package/index.js +3 -1
- package/package.json +1 -1
- package/realtime-events.d.ts +39 -0
- package/realtime-events.d.ts.map +1 -1
- package/rest-client.d.ts +32 -1
- package/rest-client.d.ts.map +1 -1
- package/rest-client.js +75 -0
- package/rest-client.js.map +1 -1
- package/schemas.d.ts +1 -0
- package/schemas.d.ts.map +1 -1
- package/store/conversations-store.d.ts +6 -6
- package/store/conversations-store.d.ts.map +1 -1
- package/store/conversations-store.js +2 -1
- package/store/conversations-store.js.map +1 -1
- package/store/typing-store.d.ts.map +1 -1
- package/store/typing-store.js +6 -6
- package/store/typing-store.js.map +1 -1
- package/typing-reporter.d.ts +71 -0
- package/typing-reporter.d.ts.map +1 -0
- package/typing-reporter.js +145 -0
- package/typing-reporter.js.map +1 -0
- package/upload-constants.d.ts +40 -0
- package/upload-constants.d.ts.map +1 -0
- package/upload-constants.js +70 -0
- package/upload-constants.js.map +1 -0
- package/upload.d.ts +47 -0
- package/upload.d.ts.map +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/upload-constants.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* File upload constants for cost/API protection.
|
|
4
|
+
* These limits are enforced on both client and server side.
|
|
5
|
+
*/
|
|
6
|
+
/** Maximum file size in bytes (5 MB) */
|
|
7
|
+
declare const MAX_FILE_SIZE: number;
|
|
8
|
+
/** Maximum number of files per message */
|
|
9
|
+
declare const MAX_FILES_PER_MESSAGE = 3;
|
|
10
|
+
/** Allowed MIME types for file uploads */
|
|
11
|
+
declare const ALLOWED_MIME_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "application/pdf", "text/plain", "text/csv", "text/markdown", "application/zip"];
|
|
12
|
+
/** Human-readable file type descriptions for error messages */
|
|
13
|
+
declare const ALLOWED_FILE_TYPES_DESCRIPTION = "images (JPEG, PNG, GIF, WebP), PDF, text files (TXT, CSV, MD), and ZIP archives";
|
|
14
|
+
/** Accept string for file input elements */
|
|
15
|
+
declare const FILE_INPUT_ACCEPT: string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a MIME type is allowed for upload
|
|
18
|
+
*/
|
|
19
|
+
declare function isAllowedMimeType(mimeType: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a file is an image based on MIME type
|
|
22
|
+
*/
|
|
23
|
+
declare function isImageMimeType(mimeType: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Format file size for display
|
|
26
|
+
*/
|
|
27
|
+
declare function formatFileSize(bytes: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Validate a file against upload constraints
|
|
30
|
+
* @returns null if valid, error message if invalid
|
|
31
|
+
*/
|
|
32
|
+
declare function validateFile(file: File): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Validate multiple files against upload constraints
|
|
35
|
+
* @returns null if all valid, error message if any invalid
|
|
36
|
+
*/
|
|
37
|
+
declare function validateFiles(files: File[]): string | null;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, formatFileSize, isAllowedMimeType, isImageMimeType, validateFile, validateFiles };
|
|
40
|
+
//# sourceMappingURL=upload-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-constants.d.ts","names":[],"sources":["../src/upload-constants.ts"],"sourcesContent":[],"mappings":";;AAMA;AAGA;AAGA;AAiBA;AAIa,cA3BA,aA2BgD,EAAA,MAAA;AAK7D;AAOgB,cApCH,qBAAA,GAoCkB,CAAA;AAO/B;AAcgB,cAtDH,kBAsD0B,EAAA,SAAA,CAAA,YAAA,EAAA,WAAA,EAAA,WAAA,EAAA,YAAA,EAAA,iBAAA,EAAA,YAAA,EAAA,UAAA,EAAA,eAAA,EAAA,iBAAA,CAAA;AAgBvC;cArDa,8BAAA;;cAIA;;;;iBAKG,iBAAA;;;;iBAOA,eAAA;;;;iBAOA,cAAA;;;;;iBAcA,YAAA,OAAmB;;;;;iBAgBnB,aAAA,QAAqB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/upload-constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* File upload constants for cost/API protection.
|
|
4
|
+
* These limits are enforced on both client and server side.
|
|
5
|
+
*/
|
|
6
|
+
/** Maximum file size in bytes (5 MB) */
|
|
7
|
+
const MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
8
|
+
/** Maximum number of files per message */
|
|
9
|
+
const MAX_FILES_PER_MESSAGE = 3;
|
|
10
|
+
/** Allowed MIME types for file uploads */
|
|
11
|
+
const ALLOWED_MIME_TYPES = [
|
|
12
|
+
"image/jpeg",
|
|
13
|
+
"image/png",
|
|
14
|
+
"image/gif",
|
|
15
|
+
"image/webp",
|
|
16
|
+
"application/pdf",
|
|
17
|
+
"text/plain",
|
|
18
|
+
"text/csv",
|
|
19
|
+
"text/markdown",
|
|
20
|
+
"application/zip"
|
|
21
|
+
];
|
|
22
|
+
/** Human-readable file type descriptions for error messages */
|
|
23
|
+
const ALLOWED_FILE_TYPES_DESCRIPTION = "images (JPEG, PNG, GIF, WebP), PDF, text files (TXT, CSV, MD), and ZIP archives";
|
|
24
|
+
/** Accept string for file input elements */
|
|
25
|
+
const FILE_INPUT_ACCEPT = ALLOWED_MIME_TYPES.join(",");
|
|
26
|
+
/**
|
|
27
|
+
* Check if a MIME type is allowed for upload
|
|
28
|
+
*/
|
|
29
|
+
function isAllowedMimeType(mimeType) {
|
|
30
|
+
return ALLOWED_MIME_TYPES.includes(mimeType);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a file is an image based on MIME type
|
|
34
|
+
*/
|
|
35
|
+
function isImageMimeType(mimeType) {
|
|
36
|
+
return mimeType.startsWith("image/");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Format file size for display
|
|
40
|
+
*/
|
|
41
|
+
function formatFileSize(bytes) {
|
|
42
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
43
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
44
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate a file against upload constraints
|
|
48
|
+
* @returns null if valid, error message if invalid
|
|
49
|
+
*/
|
|
50
|
+
function validateFile(file) {
|
|
51
|
+
if (file.size > MAX_FILE_SIZE) return `File "${file.name}" exceeds maximum size of ${formatFileSize(MAX_FILE_SIZE)}`;
|
|
52
|
+
if (!isAllowedMimeType(file.type)) return `File type "${file.type || "unknown"}" is not allowed. Allowed types: ${ALLOWED_FILE_TYPES_DESCRIPTION}`;
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate multiple files against upload constraints
|
|
57
|
+
* @returns null if all valid, error message if any invalid
|
|
58
|
+
*/
|
|
59
|
+
function validateFiles(files) {
|
|
60
|
+
if (files.length > MAX_FILES_PER_MESSAGE) return `Cannot attach more than ${MAX_FILES_PER_MESSAGE} files per message`;
|
|
61
|
+
for (const file of files) {
|
|
62
|
+
const error = validateFile(file);
|
|
63
|
+
if (error) return error;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, formatFileSize, isAllowedMimeType, isImageMimeType, validateFile, validateFiles };
|
|
70
|
+
//# sourceMappingURL=upload-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-constants.js","names":[],"sources":["../src/upload-constants.ts"],"sourcesContent":["/**\n * File upload constants for cost/API protection.\n * These limits are enforced on both client and server side.\n */\n\n/** Maximum file size in bytes (5 MB) */\nexport const MAX_FILE_SIZE = 5 * 1024 * 1024;\n\n/** Maximum number of files per message */\nexport const MAX_FILES_PER_MESSAGE = 3;\n\n/** Allowed MIME types for file uploads */\nexport const ALLOWED_MIME_TYPES = [\n\t// Images\n\t\"image/jpeg\",\n\t\"image/png\",\n\t\"image/gif\",\n\t\"image/webp\",\n\t// Documents\n\t\"application/pdf\",\n\t// Text files\n\t\"text/plain\",\n\t\"text/csv\",\n\t\"text/markdown\",\n\t// Archives\n\t\"application/zip\",\n] as const;\n\n/** Human-readable file type descriptions for error messages */\nexport const ALLOWED_FILE_TYPES_DESCRIPTION =\n\t\"images (JPEG, PNG, GIF, WebP), PDF, text files (TXT, CSV, MD), and ZIP archives\";\n\n/** Accept string for file input elements */\nexport const FILE_INPUT_ACCEPT = ALLOWED_MIME_TYPES.join(\",\");\n\n/**\n * Check if a MIME type is allowed for upload\n */\nexport function isAllowedMimeType(mimeType: string): boolean {\n\treturn (ALLOWED_MIME_TYPES as readonly string[]).includes(mimeType);\n}\n\n/**\n * Check if a file is an image based on MIME type\n */\nexport function isImageMimeType(mimeType: string): boolean {\n\treturn mimeType.startsWith(\"image/\");\n}\n\n/**\n * Format file size for display\n */\nexport function formatFileSize(bytes: number): string {\n\tif (bytes < 1024) {\n\t\treturn `${bytes} B`;\n\t}\n\tif (bytes < 1024 * 1024) {\n\t\treturn `${(bytes / 1024).toFixed(1)} KB`;\n\t}\n\treturn `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n\n/**\n * Validate a file against upload constraints\n * @returns null if valid, error message if invalid\n */\nexport function validateFile(file: File): string | null {\n\tif (file.size > MAX_FILE_SIZE) {\n\t\treturn `File \"${file.name}\" exceeds maximum size of ${formatFileSize(MAX_FILE_SIZE)}`;\n\t}\n\n\tif (!isAllowedMimeType(file.type)) {\n\t\treturn `File type \"${file.type || \"unknown\"}\" is not allowed. Allowed types: ${ALLOWED_FILE_TYPES_DESCRIPTION}`;\n\t}\n\n\treturn null;\n}\n\n/**\n * Validate multiple files against upload constraints\n * @returns null if all valid, error message if any invalid\n */\nexport function validateFiles(files: File[]): string | null {\n\tif (files.length > MAX_FILES_PER_MESSAGE) {\n\t\treturn `Cannot attach more than ${MAX_FILES_PER_MESSAGE} files per message`;\n\t}\n\n\tfor (const file of files) {\n\t\tconst error = validateFile(file);\n\t\tif (error) {\n\t\t\treturn error;\n\t\t}\n\t}\n\n\treturn null;\n}\n"],"mappings":";;;;;;AAMA,MAAa,gBAAgB,IAAI,OAAO;;AAGxC,MAAa,wBAAwB;;AAGrC,MAAa,qBAAqB;CAEjC;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CAEA;CACA;;AAGD,MAAa,iCACZ;;AAGD,MAAa,oBAAoB,mBAAmB,KAAK,IAAI;;;;AAK7D,SAAgB,kBAAkB,UAA2B;AAC5D,QAAQ,mBAAyC,SAAS,SAAS;;;;;AAMpE,SAAgB,gBAAgB,UAA2B;AAC1D,QAAO,SAAS,WAAW,SAAS;;;;;AAMrC,SAAgB,eAAe,OAAuB;AACrD,KAAI,QAAQ,KACX,QAAO,GAAG,MAAM;AAEjB,KAAI,QAAQ,OAAO,KAClB,QAAO,IAAI,QAAQ,MAAM,QAAQ,EAAE,CAAC;AAErC,QAAO,IAAI,SAAS,OAAO,OAAO,QAAQ,EAAE,CAAC;;;;;;AAO9C,SAAgB,aAAa,MAA2B;AACvD,KAAI,KAAK,OAAO,cACf,QAAO,SAAS,KAAK,KAAK,4BAA4B,eAAe,cAAc;AAGpF,KAAI,CAAC,kBAAkB,KAAK,KAAK,CAChC,QAAO,cAAc,KAAK,QAAQ,UAAU,mCAAmC;AAGhF,QAAO;;;;;;AAOR,SAAgB,cAAc,OAA8B;AAC3D,KAAI,MAAM,SAAS,sBAClB,QAAO,2BAA2B,sBAAsB;AAGzD,MAAK,MAAM,QAAQ,OAAO;EACzB,MAAM,QAAQ,aAAa,KAAK;AAChC,MAAI,MACH,QAAO;;AAIT,QAAO"}
|
package/upload.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
|
|
3
|
+
//#region ../types/src/api/upload.d.ts
|
|
4
|
+
|
|
5
|
+
declare const generateUploadUrlRequestSchema: z.ZodObject<{
|
|
6
|
+
contentType: z.ZodString;
|
|
7
|
+
websiteId: z.ZodString;
|
|
8
|
+
scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
9
|
+
type: z.ZodLiteral<"conversation">;
|
|
10
|
+
conversationId: z.ZodString;
|
|
11
|
+
organizationId: z.ZodString;
|
|
12
|
+
websiteId: z.ZodString;
|
|
13
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
14
|
+
type: z.ZodLiteral<"user">;
|
|
15
|
+
userId: z.ZodString;
|
|
16
|
+
organizationId: z.ZodString;
|
|
17
|
+
websiteId: z.ZodString;
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"contact">;
|
|
20
|
+
contactId: z.ZodString;
|
|
21
|
+
organizationId: z.ZodString;
|
|
22
|
+
websiteId: z.ZodString;
|
|
23
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
24
|
+
type: z.ZodLiteral<"visitor">;
|
|
25
|
+
visitorId: z.ZodString;
|
|
26
|
+
organizationId: z.ZodString;
|
|
27
|
+
websiteId: z.ZodString;
|
|
28
|
+
}, z.core.$strip>], "type">;
|
|
29
|
+
path: z.ZodOptional<z.ZodString>;
|
|
30
|
+
fileName: z.ZodOptional<z.ZodString>;
|
|
31
|
+
fileExtension: z.ZodOptional<z.ZodString>;
|
|
32
|
+
useCdn: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
expiresInSeconds: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
type GenerateUploadUrlRequest = z.infer<typeof generateUploadUrlRequestSchema>;
|
|
36
|
+
declare const generateUploadUrlResponseSchema: z.ZodObject<{
|
|
37
|
+
uploadUrl: z.ZodURL;
|
|
38
|
+
key: z.ZodString;
|
|
39
|
+
bucket: z.ZodString;
|
|
40
|
+
expiresAt: z.ZodString;
|
|
41
|
+
contentType: z.ZodString;
|
|
42
|
+
publicUrl: z.ZodURL;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
type GenerateUploadUrlResponse = z.infer<typeof generateUploadUrlResponseSchema>;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { GenerateUploadUrlRequest, GenerateUploadUrlResponse };
|
|
47
|
+
//# sourceMappingURL=upload.d.ts.map
|
package/upload.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","names":[],"sources":["../../types/src/api/upload.ts"],"sourcesContent":[],"mappings":";;;;AAkMY,cAvEC,8BAwEL,EAxEmC,CAAA,CAAA,SAwEnC,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAxCI,wBAAA,GAA2B,CAAA,CAAE,aACjC;cAGK,iCAA+B,CAAA,CAAA;;;;;;;;KAmChC,yBAAA,GAA4B,CAAA,CAAE,aAClC"}
|