karboai 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +33 -0
- package/dist/core/httptoolkit.d.ts +10 -0
- package/dist/core/httptoolkit.d.ts.map +1 -0
- package/dist/core/httptoolkit.js +57 -0
- package/dist/core/karboai.d.ts +19 -0
- package/dist/core/karboai.d.ts.map +1 -0
- package/dist/core/karboai.js +54 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/schemas/configs.d.ts +33 -0
- package/dist/schemas/configs.d.ts.map +1 -0
- package/dist/schemas/configs.js +28 -0
- package/dist/schemas/enums.d.ts +7 -0
- package/dist/schemas/enums.d.ts.map +1 -0
- package/dist/schemas/enums.js +10 -0
- package/dist/schemas/error.d.ts +7 -0
- package/dist/schemas/error.d.ts.map +1 -0
- package/dist/schemas/error.js +8 -0
- package/dist/schemas/karboai/message.d.ts +32 -0
- package/dist/schemas/karboai/message.d.ts.map +1 -0
- package/dist/schemas/karboai/message.js +18 -0
- package/dist/schemas/karboai/users.d.ts +59 -0
- package/dist/schemas/karboai/users.d.ts.map +1 -0
- package/dist/schemas/karboai/users.js +35 -0
- package/dist/schemas/responses.d.ts +35 -0
- package/dist/schemas/responses.d.ts.map +1 -0
- package/dist/schemas/responses.js +35 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +29 -0
- package/dist/utils/logger.d.ts +5 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +19 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +5 -0
- package/package.json +15 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UndiciHeaders } from 'undici/types/dispatcher';
|
|
2
|
+
import { ErrorData } from './schemas/error';
|
|
3
|
+
export declare const KARBO_API = "https://api.karboai.com";
|
|
4
|
+
export declare const BASIC_HEADERS: UndiciHeaders;
|
|
5
|
+
export declare const ERRORS: Record<number, ErrorData>;
|
|
6
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAO,MAAM,SAAS,4BAA4B,CAAC;AAEnD,eAAO,MAAM,aAAa,EAAE,aAE3B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAyB5C,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERRORS = exports.BASIC_HEADERS = exports.KARBO_API = void 0;
|
|
4
|
+
exports.KARBO_API = 'https://api.karboai.com';
|
|
5
|
+
exports.BASIC_HEADERS = {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
};
|
|
8
|
+
exports.ERRORS = {
|
|
9
|
+
400: {
|
|
10
|
+
name: 'KarboAI.BadRequest',
|
|
11
|
+
message: 'May empty message, content too long, too many images',
|
|
12
|
+
},
|
|
13
|
+
401: {
|
|
14
|
+
name: 'KarboAI.Unauthorized',
|
|
15
|
+
message: 'Invalid bot token',
|
|
16
|
+
},
|
|
17
|
+
403: {
|
|
18
|
+
name: 'KarboAI.Forbidden',
|
|
19
|
+
message: 'Access denied',
|
|
20
|
+
},
|
|
21
|
+
404: {
|
|
22
|
+
name: 'KarboAI.NotFound',
|
|
23
|
+
message: "Content doesn't exist",
|
|
24
|
+
},
|
|
25
|
+
413: {
|
|
26
|
+
name: 'KarboAI.FileTooLarge',
|
|
27
|
+
message: 'Please upload files smaller than XX bytes length', // TODO: rewrite to accurate length
|
|
28
|
+
},
|
|
29
|
+
429: {
|
|
30
|
+
name: 'KarboAI.TooManyRequests',
|
|
31
|
+
message: 'Rate limit exceeded',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GetRequestConfig, MultipartRequestConfig, PostRequestConfig } from '../schemas/configs';
|
|
2
|
+
export declare class HttpToolKit {
|
|
3
|
+
private readonly headers;
|
|
4
|
+
constructor(token: string);
|
|
5
|
+
private handle;
|
|
6
|
+
get: <T>(config: GetRequestConfig) => Promise<T>;
|
|
7
|
+
post: <T>(config: PostRequestConfig) => Promise<T>;
|
|
8
|
+
multipart: <T>(config: MultipartRequestConfig) => Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=httptoolkit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httptoolkit.d.ts","sourceRoot":"","sources":["../../src/core/httptoolkit.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAI5B,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;gBAEpC,KAAK,EAAE,MAAM;IAOzB,OAAO,CAAC,MAAM,CAaZ;IAEK,GAAG,GAAU,CAAC,EAAE,QAAQ,gBAAgB,KAAG,OAAO,CAAC,CAAC,CAAC,CAO1D;IAEK,IAAI,GAAU,CAAC,EAAE,QAAQ,iBAAiB,KAAG,OAAO,CAAC,CAAC,CAAC,CAQ5D;IAEK,SAAS,GAAU,CAAC,EAAE,QAAQ,sBAAsB,KAAG,OAAO,CAAC,CAAC,CAAC,CAetE;CACH"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpToolKit = void 0;
|
|
7
|
+
const undici_1 = require("undici");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const logger_1 = require("../utils/logger");
|
|
11
|
+
const errors_1 = require("../utils/errors");
|
|
12
|
+
class HttpToolKit {
|
|
13
|
+
headers = { ...constants_1.BASIC_HEADERS };
|
|
14
|
+
constructor(token) {
|
|
15
|
+
this.headers = {
|
|
16
|
+
...this.headers,
|
|
17
|
+
'Bot-Token': token,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
handle = async (response, path, schema) => {
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
logger_1.LOGGER.child({ path }).error(response.status);
|
|
23
|
+
errors_1.KarboException.throw(response.status);
|
|
24
|
+
}
|
|
25
|
+
logger_1.LOGGER.child({ path }).info(response.status);
|
|
26
|
+
return schema.parse(await response.json());
|
|
27
|
+
};
|
|
28
|
+
get = async (config) => {
|
|
29
|
+
const response = await (0, undici_1.fetch)(`${constants_1.KARBO_API}${config.path}`, {
|
|
30
|
+
method: 'GET',
|
|
31
|
+
headers: this.headers,
|
|
32
|
+
});
|
|
33
|
+
return (await this.handle(response, config.path, config.schema));
|
|
34
|
+
};
|
|
35
|
+
post = async (config) => {
|
|
36
|
+
const response = await (0, undici_1.fetch)(`${constants_1.KARBO_API}${config.path}`, {
|
|
37
|
+
method: 'GET',
|
|
38
|
+
body: config.body,
|
|
39
|
+
headers: this.headers,
|
|
40
|
+
});
|
|
41
|
+
return (await this.handle(response, config.path, config.schema));
|
|
42
|
+
};
|
|
43
|
+
multipart = async (config) => {
|
|
44
|
+
const blob = new Blob([config.buffer], {
|
|
45
|
+
type: `image/${config.fileName.split('.').pop()}`,
|
|
46
|
+
});
|
|
47
|
+
const form = new undici_1.FormData();
|
|
48
|
+
form.append('file', blob, config.fileName);
|
|
49
|
+
const response = await (0, undici_1.fetch)(`${constants_1.KARBO_API}${config.path}`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
body: form,
|
|
52
|
+
headers: lodash_1.default.omit(this.headers, ['Content-Type']),
|
|
53
|
+
});
|
|
54
|
+
return (await this.handle(response, config.path, config.schema));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.HttpToolKit = HttpToolKit;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { KarboConfig } from '../schemas/configs';
|
|
2
|
+
import { MeResponse } from '../schemas/responses';
|
|
3
|
+
export declare class KarboAI {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly httptoolkit;
|
|
6
|
+
constructor(config: KarboConfig);
|
|
7
|
+
private sendMessage;
|
|
8
|
+
me: () => Promise<MeResponse>;
|
|
9
|
+
text: (chatId: string, content: string, replyMessageId?: string) => Promise<{
|
|
10
|
+
messageId: string;
|
|
11
|
+
createdAt: number;
|
|
12
|
+
}>;
|
|
13
|
+
image: (chatId: string, images: string[], replyMessageId?: string) => Promise<{
|
|
14
|
+
messageId: string;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
}>;
|
|
17
|
+
upload: (path: string) => Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=karboai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"karboai.d.ts","sourceRoot":"","sources":["../../src/core/karboai.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAqB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EACL,UAAU,EAMX,MAAM,sBAAsB,CAAC;AAK9B,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;gBAE9B,MAAM,EAAE,WAAW;IAO/B,OAAO,CAAC,WAAW,CAcd;IAEE,EAAE,QAAa,OAAO,CAAC,UAAU,CAAC,CAIpC;IAEE,IAAI,GACT,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,iBAAiB,MAAM;;;OAMpB;IAEE,KAAK,GACV,QAAQ,MAAM,EACd,QAAQ,MAAM,EAAE,EAChB,iBAAiB,MAAM;;;OAMpB;IAEE,MAAM,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAWnD;CACH"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.KarboAI = void 0;
|
|
7
|
+
const promises_1 = require("fs/promises");
|
|
8
|
+
const responses_1 = require("../schemas/responses");
|
|
9
|
+
const logger_1 = __importDefault(require("../utils/logger"));
|
|
10
|
+
const utils_1 = require("../utils/utils");
|
|
11
|
+
const httptoolkit_1 = require("./httptoolkit");
|
|
12
|
+
class KarboAI {
|
|
13
|
+
config;
|
|
14
|
+
httptoolkit;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.httptoolkit = new httptoolkit_1.HttpToolKit(config.token);
|
|
18
|
+
(0, logger_1.default)(!!config.enableLogging);
|
|
19
|
+
}
|
|
20
|
+
sendMessage = async (config) => await this.httptoolkit.post({
|
|
21
|
+
path: '/bot/send-message',
|
|
22
|
+
body: JSON.stringify((0, utils_1.clean)({
|
|
23
|
+
chat_id: config.chatId,
|
|
24
|
+
content: config.content,
|
|
25
|
+
reply_message_id: config.replyMessageId,
|
|
26
|
+
images: config.images,
|
|
27
|
+
})),
|
|
28
|
+
schema: responses_1.MessageResponseSchema,
|
|
29
|
+
});
|
|
30
|
+
me = async () => await this.httptoolkit.get({
|
|
31
|
+
path: '/bot/me',
|
|
32
|
+
schema: responses_1.MeResponseSchema,
|
|
33
|
+
});
|
|
34
|
+
text = async (chatId, content, replyMessageId) => await this.sendMessage({
|
|
35
|
+
chatId,
|
|
36
|
+
content,
|
|
37
|
+
replyMessageId,
|
|
38
|
+
});
|
|
39
|
+
image = async (chatId, images, replyMessageId) => await this.sendMessage({
|
|
40
|
+
chatId,
|
|
41
|
+
images,
|
|
42
|
+
replyMessageId,
|
|
43
|
+
});
|
|
44
|
+
upload = async (path) => {
|
|
45
|
+
const file = await (0, promises_1.readFile)(path);
|
|
46
|
+
return (await this.httptoolkit.multipart({
|
|
47
|
+
path: '/bot/upload/image',
|
|
48
|
+
buffer: file,
|
|
49
|
+
fileName: path.split('/').pop(),
|
|
50
|
+
schema: responses_1.UploadResponseSchema,
|
|
51
|
+
})).url;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.KarboAI = KarboAI;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { KarboAI } from './core/karboai';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const GetRequestConfigSchema: z.ZodObject<{
|
|
3
|
+
path: z.ZodString;
|
|
4
|
+
schema: z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export declare const PostRequestConfigSchema: z.ZodObject<{
|
|
7
|
+
body: z.ZodString;
|
|
8
|
+
path: z.ZodString;
|
|
9
|
+
schema: z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const MultipartRequestConfigSchema: z.ZodObject<{
|
|
12
|
+
buffer: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
|
|
13
|
+
fileName: z.ZodString;
|
|
14
|
+
path: z.ZodString;
|
|
15
|
+
schema: z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const KarboConfigSchema: z.ZodObject<{
|
|
18
|
+
token: z.ZodString;
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
enableLogging: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export declare const SendMessageConfigSchema: z.ZodObject<{
|
|
23
|
+
chatId: z.ZodString;
|
|
24
|
+
content: z.ZodOptional<z.ZodString>;
|
|
25
|
+
replyMessageId: z.ZodOptional<z.ZodString>;
|
|
26
|
+
images: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type GetRequestConfig = z.Infer<typeof GetRequestConfigSchema>;
|
|
29
|
+
export type PostRequestConfig = z.Infer<typeof PostRequestConfigSchema>;
|
|
30
|
+
export type MultipartRequestConfig = z.Infer<typeof MultipartRequestConfigSchema>;
|
|
31
|
+
export type KarboConfig = z.Infer<typeof KarboConfigSchema>;
|
|
32
|
+
export type SendMessageConfig = z.Infer<typeof SendMessageConfigSchema>;
|
|
33
|
+
//# sourceMappingURL=configs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/schemas/configs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAW,MAAM,KAAK,CAAC;AAEjC,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;iBAGlC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;iBAIvC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;iBAI5B,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;iBAKlC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACtE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SendMessageConfigSchema = exports.KarboConfigSchema = exports.MultipartRequestConfigSchema = exports.PostRequestConfigSchema = exports.GetRequestConfigSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.GetRequestConfigSchema = zod_1.z.object({
|
|
6
|
+
path: zod_1.z.string(),
|
|
7
|
+
schema: zod_1.z.instanceof(zod_1.ZodType),
|
|
8
|
+
});
|
|
9
|
+
exports.PostRequestConfigSchema = zod_1.z.object({
|
|
10
|
+
...exports.GetRequestConfigSchema.shape,
|
|
11
|
+
body: zod_1.z.string(),
|
|
12
|
+
});
|
|
13
|
+
exports.MultipartRequestConfigSchema = zod_1.z.object({
|
|
14
|
+
...exports.GetRequestConfigSchema.shape,
|
|
15
|
+
buffer: zod_1.z.instanceof(Buffer),
|
|
16
|
+
fileName: zod_1.z.string(),
|
|
17
|
+
});
|
|
18
|
+
exports.KarboConfigSchema = zod_1.z.object({
|
|
19
|
+
token: zod_1.z.string(),
|
|
20
|
+
id: zod_1.z.string(),
|
|
21
|
+
enableLogging: zod_1.z.boolean().optional(),
|
|
22
|
+
});
|
|
23
|
+
exports.SendMessageConfigSchema = zod_1.z.object({
|
|
24
|
+
chatId: zod_1.z.string(),
|
|
25
|
+
content: zod_1.z.string().optional(),
|
|
26
|
+
replyMessageId: zod_1.z.string().optional(),
|
|
27
|
+
images: zod_1.z.array(zod_1.z.string()).optional(),
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/schemas/enums.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,eAAO,MAAM,aAAa;;;;mEAEgB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BotStatusEnum = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
exports.BotStatusEnum = zod_1.default
|
|
9
|
+
.enum(['not_official', 'official', 'banned'])
|
|
10
|
+
.transform((data) => data.toUpperCase());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/schemas/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;;;iBAG1B,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const MessageSchema: z.ZodObject<{
|
|
3
|
+
message_id: z.ZodString;
|
|
4
|
+
chat_id: z.ZodString;
|
|
5
|
+
user_id: z.ZodString;
|
|
6
|
+
content: z.ZodString;
|
|
7
|
+
created_time: z.ZodString;
|
|
8
|
+
type: z.ZodNumber;
|
|
9
|
+
reply_message_id: z.ZodNullable<z.ZodString>;
|
|
10
|
+
audio: z.ZodNullable<z.ZodString>;
|
|
11
|
+
sticker: z.ZodNullable<z.ZodString>;
|
|
12
|
+
images: z.ZodArray<z.ZodString>;
|
|
13
|
+
author: z.ZodPipe<z.ZodObject<{
|
|
14
|
+
user_id: z.ZodString;
|
|
15
|
+
nickname: z.ZodString;
|
|
16
|
+
avatar: z.ZodString;
|
|
17
|
+
role: z.ZodNumber;
|
|
18
|
+
short_info: z.ZodString;
|
|
19
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
20
|
+
userId: string;
|
|
21
|
+
nickname: string;
|
|
22
|
+
avatar: string;
|
|
23
|
+
}, {
|
|
24
|
+
user_id: string;
|
|
25
|
+
nickname: string;
|
|
26
|
+
avatar: string;
|
|
27
|
+
role: number;
|
|
28
|
+
short_info: string;
|
|
29
|
+
}>>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export type Message = z.infer<typeof MessageSchema>;
|
|
32
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/schemas/karboai/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAYxB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const users_1 = require("./users");
|
|
6
|
+
exports.MessageSchema = zod_1.z.object({
|
|
7
|
+
message_id: zod_1.z.string(),
|
|
8
|
+
chat_id: zod_1.z.string(),
|
|
9
|
+
user_id: zod_1.z.string(),
|
|
10
|
+
content: zod_1.z.string(),
|
|
11
|
+
created_time: zod_1.z.string(),
|
|
12
|
+
type: zod_1.z.number(),
|
|
13
|
+
reply_message_id: zod_1.z.string().nullable(),
|
|
14
|
+
audio: zod_1.z.string().nullable(),
|
|
15
|
+
sticker: zod_1.z.string().nullable(),
|
|
16
|
+
images: zod_1.z.array(zod_1.z.string()),
|
|
17
|
+
author: users_1.AuthorSchema,
|
|
18
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const UserSchema: z.ZodPipe<z.ZodObject<{
|
|
3
|
+
user_id: z.ZodString;
|
|
4
|
+
nickname: z.ZodString;
|
|
5
|
+
avatar: z.ZodString;
|
|
6
|
+
role: z.ZodNumber;
|
|
7
|
+
short_info: z.ZodString;
|
|
8
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
9
|
+
userId: string;
|
|
10
|
+
nickname: string;
|
|
11
|
+
avatar: string;
|
|
12
|
+
role: number;
|
|
13
|
+
shortInfo: string;
|
|
14
|
+
}, {
|
|
15
|
+
user_id: string;
|
|
16
|
+
nickname: string;
|
|
17
|
+
avatar: string;
|
|
18
|
+
role: number;
|
|
19
|
+
short_info: string;
|
|
20
|
+
}>>;
|
|
21
|
+
export declare const MemberSchema: z.ZodPipe<z.ZodObject<{
|
|
22
|
+
user_id: z.ZodString;
|
|
23
|
+
nickname: z.ZodString;
|
|
24
|
+
avatar: z.ZodString;
|
|
25
|
+
role: z.ZodNumber;
|
|
26
|
+
short_info: z.ZodString;
|
|
27
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
28
|
+
userId: string;
|
|
29
|
+
nickname: string;
|
|
30
|
+
avatar: string;
|
|
31
|
+
role: number;
|
|
32
|
+
}, {
|
|
33
|
+
user_id: string;
|
|
34
|
+
nickname: string;
|
|
35
|
+
avatar: string;
|
|
36
|
+
role: number;
|
|
37
|
+
short_info: string;
|
|
38
|
+
}>>;
|
|
39
|
+
export declare const AuthorSchema: z.ZodPipe<z.ZodObject<{
|
|
40
|
+
user_id: z.ZodString;
|
|
41
|
+
nickname: z.ZodString;
|
|
42
|
+
avatar: z.ZodString;
|
|
43
|
+
role: z.ZodNumber;
|
|
44
|
+
short_info: z.ZodString;
|
|
45
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
46
|
+
userId: string;
|
|
47
|
+
nickname: string;
|
|
48
|
+
avatar: string;
|
|
49
|
+
}, {
|
|
50
|
+
user_id: string;
|
|
51
|
+
nickname: string;
|
|
52
|
+
avatar: string;
|
|
53
|
+
role: number;
|
|
54
|
+
short_info: string;
|
|
55
|
+
}>>;
|
|
56
|
+
export type User = z.infer<typeof UserSchema>;
|
|
57
|
+
export type Member = z.infer<typeof MemberSchema>;
|
|
58
|
+
export type Author = z.infer<typeof AuthorSchema>;
|
|
59
|
+
//# sourceMappingURL=users.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/schemas/karboai/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;GAQrB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;GAOvB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;GAMvB,CAAC;AAEH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAC9C,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAClD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorSchema = exports.MemberSchema = exports.UserSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const BasicUserSchema = zod_1.z.object({
|
|
6
|
+
user_id: zod_1.z.string(),
|
|
7
|
+
nickname: zod_1.z.string(),
|
|
8
|
+
avatar: zod_1.z.string(),
|
|
9
|
+
role: zod_1.z.number(),
|
|
10
|
+
short_info: zod_1.z.string(),
|
|
11
|
+
});
|
|
12
|
+
exports.UserSchema = BasicUserSchema.transform((data) => {
|
|
13
|
+
return {
|
|
14
|
+
userId: data.user_id,
|
|
15
|
+
nickname: data.nickname,
|
|
16
|
+
avatar: data.avatar,
|
|
17
|
+
role: data.role,
|
|
18
|
+
shortInfo: data.short_info,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
exports.MemberSchema = BasicUserSchema.transform((data) => {
|
|
22
|
+
return {
|
|
23
|
+
userId: data.user_id,
|
|
24
|
+
nickname: data.nickname,
|
|
25
|
+
avatar: data.avatar,
|
|
26
|
+
role: data.role,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
exports.AuthorSchema = BasicUserSchema.transform((data) => {
|
|
30
|
+
return {
|
|
31
|
+
userId: data.user_id,
|
|
32
|
+
nickname: data.nickname,
|
|
33
|
+
avatar: data.avatar,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export declare const MeResponseSchema: z.ZodPipe<z.ZodObject<{
|
|
3
|
+
bot_id: z.ZodString;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
status: z.ZodPipe<z.ZodEnum<{
|
|
6
|
+
not_official: "not_official";
|
|
7
|
+
official: "official";
|
|
8
|
+
banned: "banned";
|
|
9
|
+
}>, z.ZodTransform<string, "not_official" | "official" | "banned">>;
|
|
10
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
11
|
+
botId: string;
|
|
12
|
+
name: string;
|
|
13
|
+
status: string;
|
|
14
|
+
}, {
|
|
15
|
+
bot_id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
status: string;
|
|
18
|
+
}>>;
|
|
19
|
+
export declare const MessageResponseSchema: z.ZodPipe<z.ZodObject<{
|
|
20
|
+
message_id: z.ZodString;
|
|
21
|
+
created_time: z.ZodNumber;
|
|
22
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
23
|
+
messageId: string;
|
|
24
|
+
createdAt: number;
|
|
25
|
+
}, {
|
|
26
|
+
message_id: string;
|
|
27
|
+
created_time: number;
|
|
28
|
+
}>>;
|
|
29
|
+
export declare const UploadResponseSchema: z.ZodObject<{
|
|
30
|
+
url: z.ZodString;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type MeResponse = z.Infer<typeof MeResponseSchema>;
|
|
33
|
+
export type MessageResponse = z.Infer<typeof MessageResponseSchema>;
|
|
34
|
+
export type UploadResponse = z.Infer<typeof UploadResponseSchema>;
|
|
35
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/schemas/responses.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAIpB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;GAYzB,CAAC;AAEL,eAAO,MAAM,qBAAqB;;;;;;;;;GAU9B,CAAC;AAEL,eAAO,MAAM,oBAAoB;;iBAE/B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC1D,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UploadResponseSchema = exports.MessageResponseSchema = exports.MeResponseSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const enums_1 = require("./enums");
|
|
9
|
+
exports.MeResponseSchema = zod_1.default
|
|
10
|
+
.object({
|
|
11
|
+
bot_id: zod_1.default.string(),
|
|
12
|
+
name: zod_1.default.string(),
|
|
13
|
+
status: enums_1.BotStatusEnum,
|
|
14
|
+
})
|
|
15
|
+
.transform((data) => {
|
|
16
|
+
return {
|
|
17
|
+
botId: data.bot_id,
|
|
18
|
+
name: data.name,
|
|
19
|
+
status: data.status,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
exports.MessageResponseSchema = zod_1.default
|
|
23
|
+
.object({
|
|
24
|
+
message_id: zod_1.default.string(),
|
|
25
|
+
created_time: zod_1.default.number(),
|
|
26
|
+
})
|
|
27
|
+
.transform((data) => {
|
|
28
|
+
return {
|
|
29
|
+
messageId: data.message_id,
|
|
30
|
+
createdAt: data.created_time,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
exports.UploadResponseSchema = zod_1.default.object({
|
|
34
|
+
url: zod_1.default.string(),
|
|
35
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ErrorData } from '../schemas/error';
|
|
2
|
+
export declare class KarboException extends Error {
|
|
3
|
+
readonly code: number;
|
|
4
|
+
constructor(code: number, data: ErrorData);
|
|
5
|
+
static get(code: number): KarboException;
|
|
6
|
+
static throw(code: number): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS;IAWzC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc;IAWxC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAGjC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KarboException = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
class KarboException extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code, data) {
|
|
8
|
+
super(data.message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = data.name || `KarboAI.${code}`;
|
|
11
|
+
this.code = code;
|
|
12
|
+
if (Error.captureStackTrace) {
|
|
13
|
+
Error.captureStackTrace(this, KarboException);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
static get(code) {
|
|
17
|
+
const errorData = constants_1.ERRORS[code];
|
|
18
|
+
return errorData
|
|
19
|
+
? new KarboException(code, errorData)
|
|
20
|
+
: new KarboException(code, {
|
|
21
|
+
name: 'UnknownError',
|
|
22
|
+
message: 'Unknown error',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static throw(code) {
|
|
26
|
+
throw this.get(code);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.KarboException = KarboException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAa,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,eAAO,IAAI,MAAM,EAAE,MAAM,CAAC;AAE1B,QAAA,MAAM,UAAU,GAAI,eAAe,OAAO,KAAG,MAY5C,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LOGGER = void 0;
|
|
7
|
+
const pino_1 = __importDefault(require("pino"));
|
|
8
|
+
const pino_pretty_1 = __importDefault(require("pino-pretty"));
|
|
9
|
+
const initLogger = (enableLogging) => {
|
|
10
|
+
if (exports.LOGGER)
|
|
11
|
+
return exports.LOGGER;
|
|
12
|
+
return (exports.LOGGER = (0, pino_1.default)({
|
|
13
|
+
enabled: enableLogging,
|
|
14
|
+
}, (0, pino_pretty_1.default)({
|
|
15
|
+
colorize: true,
|
|
16
|
+
sync: true,
|
|
17
|
+
})));
|
|
18
|
+
};
|
|
19
|
+
exports.default = initLogger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAGjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "karboai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A powerful lib for https://karboai.com",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"karbo",
|
|
@@ -28,6 +28,19 @@
|
|
|
28
28
|
"author": "celt_is_god",
|
|
29
29
|
"type": "commonjs",
|
|
30
30
|
"scripts": {
|
|
31
|
-
"test": "
|
|
31
|
+
"test": "tsc && node dist/tests/main.js",
|
|
32
|
+
"start": "tsc && node dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@types/node": "^25.5.2",
|
|
36
|
+
"lodash": "^4.18.1",
|
|
37
|
+
"pino": "^10.3.1",
|
|
38
|
+
"pino-pretty": "^13.1.3",
|
|
39
|
+
"socket.io-client": "^4.8.3",
|
|
40
|
+
"undici": "^8.0.2",
|
|
41
|
+
"zod": "^4.3.6"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/lodash": "^4.17.24"
|
|
32
45
|
}
|
|
33
46
|
}
|