@builderbot/manager 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swagger.d.ts","sourceRoot":"","sources":["../src/swagger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0rBvB,CAAA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAqC3D"}
@@ -0,0 +1,116 @@
1
+ /** Flow type - using ReturnType to infer from addKeyword */
2
+ export type Flow = ReturnType<typeof import('@builderbot/bot').addKeyword>;
3
+ /**
4
+ * Provider class type - any class that can be used with createProvider
5
+ */
6
+ export type ProviderClass = new (...args: any[]) => any;
7
+ /**
8
+ * Database class type - any class that implements the database interface
9
+ */
10
+ export type DatabaseClass = new (...args: any[]) => any;
11
+ /**
12
+ * Provider factory function type
13
+ */
14
+ export type ProviderFactory = (options: Record<string, any>) => any;
15
+ /**
16
+ * Database factory function type
17
+ */
18
+ export type DatabaseFactory = (options: Record<string, any>) => any;
19
+ /**
20
+ * Configuration for creating a new tenant bot
21
+ */
22
+ export interface TenantConfig {
23
+ /** Unique identifier for the tenant */
24
+ tenantId: string;
25
+ /** Display name for the tenant */
26
+ name?: string;
27
+ /** Array of flows for this tenant's bot */
28
+ flows: Flow[];
29
+ /** Port for the HTTP server (optional, each tenant can have its own) */
30
+ port?: number;
31
+ /** Custom provider options */
32
+ providerOptions?: Record<string, any>;
33
+ /** Custom database options */
34
+ databaseOptions?: Record<string, any>;
35
+ /** Override provider class for this specific tenant */
36
+ providerClass?: ProviderClass;
37
+ /** Override database class for this specific tenant */
38
+ databaseClass?: DatabaseClass;
39
+ }
40
+ /**
41
+ * Represents a running bot instance for a tenant
42
+ */
43
+ export interface BotInstance {
44
+ /** Tenant identifier */
45
+ tenantId: string;
46
+ /** Display name */
47
+ name: string;
48
+ /** The provider instance */
49
+ provider: any;
50
+ /** The database instance */
51
+ database: any;
52
+ /** Context handler for HTTP requests */
53
+ handleCtx: (callback: (bot: any, req: any, res: any) => Promise<any>) => any;
54
+ /** HTTP server function */
55
+ httpServer: (port: number) => void;
56
+ /** Bot instance with sendMessage, dispatch, blacklist methods */
57
+ bot: any;
58
+ /** Port the HTTP server is running on */
59
+ port?: number;
60
+ /** Timestamp when the bot was created */
61
+ createdAt: Date;
62
+ /** Status of the bot */
63
+ status: BotStatus;
64
+ /** Provider class used */
65
+ providerType?: string;
66
+ /** Database class used */
67
+ databaseType?: string;
68
+ }
69
+ /**
70
+ * Status of a bot instance
71
+ */
72
+ export type BotStatus = 'initializing' | 'connected' | 'disconnected' | 'error';
73
+ /**
74
+ * Global configuration for the BotManager
75
+ */
76
+ export interface BotManagerConfig {
77
+ /** Base directory for session storage */
78
+ sessionsDir?: string;
79
+ /** Default provider options applied to all bots */
80
+ defaultProviderOptions?: Record<string, any>;
81
+ /** Default database options applied to all bots */
82
+ defaultDatabaseOptions?: Record<string, any>;
83
+ /** Default provider class to use (defaults to BaileysProvider if not specified) */
84
+ defaultProviderClass?: ProviderClass;
85
+ /** Default database class to use (defaults to MemoryDB if not specified) */
86
+ defaultDatabaseClass?: DatabaseClass;
87
+ /** Auto-reconnect configuration */
88
+ autoReconnect?: {
89
+ /** Enable auto-reconnect (default: true) */
90
+ enabled?: boolean;
91
+ /** Maximum retry attempts (default: 5) */
92
+ maxRetries?: number;
93
+ /** Initial delay in ms (default: 1000) */
94
+ initialDelay?: number;
95
+ /** Max delay in ms (default: 30000) */
96
+ maxDelay?: number;
97
+ };
98
+ }
99
+ /**
100
+ * Events emitted by the BotManager
101
+ */
102
+ export type BotManagerEvent = 'bot:created' | 'bot:removed' | 'bot:connected' | 'bot:disconnected' | 'bot:error' | 'bot:qr' | 'bot:reconnecting';
103
+ /**
104
+ * Event handler callback type
105
+ */
106
+ export type BotManagerEventHandler = (tenantId: string, data?: any) => void;
107
+ /**
108
+ * Reconnection state for a bot
109
+ */
110
+ export interface ReconnectState {
111
+ attempts: number;
112
+ lastAttempt: Date;
113
+ nextDelay: number;
114
+ is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jB,0CAA0C;QAC1C,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,0CAA0C;QAC1C,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,uCAAuC;QACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,aAAa,GACb,aAAa,GACb,eAAe,GACf,kBAAkB,GAClB,WAAW,GACX,QAAQ,GACR,kBAAkB,CAAA;AAEtB;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;AAE3E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,IAAI,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;CACxB"}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@builderbot/manager",
3
+ "version": "1.0.0",
4
+ "description": "Multi-tenant bot manager for BuilderBot",
5
+ "author": "Leifer Mendez <leifer33@gmail.com>",
6
+ "homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
7
+ "license": "ISC",
8
+ "main": "dist/index.cjs",
9
+ "types": "dist/index.d.ts",
10
+ "type": "module",
11
+ "scripts": {
12
+ "build": "rimraf dist && rollup --config",
13
+ "test": "npx uvu -r tsm ./__tests__",
14
+ "test:coverage": "npx c8 npm run test"
15
+ },
16
+ "files": [
17
+ "./dist/"
18
+ ],
19
+ "directories": {
20
+ "src": "src"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/codigoencasa/bot-whatsapp.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/codigoencasa/bot-whatsapp/issues"
28
+ },
29
+ "keywords": [
30
+ "builderbot",
31
+ "multi-tenant",
32
+ "whatsapp",
33
+ "bot-manager"
34
+ ],
35
+ "devDependencies": {
36
+ "@rollup/plugin-commonjs": "^25.0.8",
37
+ "@rollup/plugin-json": "^6.1.0",
38
+ "@rollup/plugin-node-resolve": "^15.3.1",
39
+ "@types/node": "^20.19.25",
40
+ "@types/polka": "^0.5.8",
41
+ "rimraf": "^5.0.10",
42
+ "rollup-plugin-typescript2": "^0.36.0",
43
+ "tslib": "^2.8.1",
44
+ "tsm": "^2.3.0",
45
+ "uvu": "^0.5.6",
46
+ "c8": "^9.1.0"
47
+ },
48
+ "dependencies": {
49
+ "polka": "^0.5.2",
50
+ "zod": "^3.23.8"
51
+ },
52
+ "peerDependencies": {
53
+ "@builderbot/bot": ">=1.0.0"
54
+ },
55
+ "peerDependenciesMeta": {
56
+ "@builderbot/provider-baileys": {
57
+ "optional": true
58
+ },
59
+ "@builderbot/provider-meta": {
60
+ "optional": true
61
+ },
62
+ "@builderbot/provider-twilio": {
63
+ "optional": true
64
+ },
65
+ "@builderbot/provider-venom": {
66
+ "optional": true
67
+ }
68
+ }
69
+ }
70
+