@timmeck/marketing-brain 0.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/.mcp.json +9 -0
- package/README.md +342 -0
- package/dashboard.html +666 -0
- package/dist/api/server.d.ts +15 -0
- package/dist/api/server.js +73 -0
- package/dist/api/server.js.map +1 -0
- package/dist/cli/colors.d.ts +43 -0
- package/dist/cli/colors.js +54 -0
- package/dist/cli/colors.js.map +1 -0
- package/dist/cli/commands/campaign.d.ts +2 -0
- package/dist/cli/commands/campaign.js +62 -0
- package/dist/cli/commands/campaign.js.map +1 -0
- package/dist/cli/commands/config.d.ts +2 -0
- package/dist/cli/commands/config.js +164 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/dashboard.d.ts +2 -0
- package/dist/cli/commands/dashboard.js +147 -0
- package/dist/cli/commands/dashboard.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +2 -0
- package/dist/cli/commands/doctor.js +111 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/export.d.ts +2 -0
- package/dist/cli/commands/export.js +37 -0
- package/dist/cli/commands/export.js.map +1 -0
- package/dist/cli/commands/import.d.ts +2 -0
- package/dist/cli/commands/import.js +76 -0
- package/dist/cli/commands/import.js.map +1 -0
- package/dist/cli/commands/insights.d.ts +2 -0
- package/dist/cli/commands/insights.js +41 -0
- package/dist/cli/commands/insights.js.map +1 -0
- package/dist/cli/commands/learn.d.ts +2 -0
- package/dist/cli/commands/learn.js +22 -0
- package/dist/cli/commands/learn.js.map +1 -0
- package/dist/cli/commands/network.d.ts +2 -0
- package/dist/cli/commands/network.js +66 -0
- package/dist/cli/commands/network.js.map +1 -0
- package/dist/cli/commands/post.d.ts +2 -0
- package/dist/cli/commands/post.js +45 -0
- package/dist/cli/commands/post.js.map +1 -0
- package/dist/cli/commands/query.d.ts +2 -0
- package/dist/cli/commands/query.js +96 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/rules.d.ts +2 -0
- package/dist/cli/commands/rules.js +25 -0
- package/dist/cli/commands/rules.js.map +1 -0
- package/dist/cli/commands/start.d.ts +2 -0
- package/dist/cli/commands/start.js +91 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +2 -0
- package/dist/cli/commands/status.js +63 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +2 -0
- package/dist/cli/commands/stop.js +34 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/commands/suggest.d.ts +2 -0
- package/dist/cli/commands/suggest.js +57 -0
- package/dist/cli/commands/suggest.js.map +1 -0
- package/dist/cli/ipc-helper.d.ts +2 -0
- package/dist/cli/ipc-helper.js +26 -0
- package/dist/cli/ipc-helper.js.map +1 -0
- package/dist/cli/update-check.d.ts +2 -0
- package/dist/cli/update-check.js +58 -0
- package/dist/cli/update-check.js.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/dashboard/renderer.d.ts +11 -0
- package/dist/dashboard/renderer.js +112 -0
- package/dist/dashboard/renderer.js.map +1 -0
- package/dist/dashboard/server.d.ts +15 -0
- package/dist/dashboard/server.js +122 -0
- package/dist/dashboard/server.js.map +1 -0
- package/dist/db/connection.d.ts +2 -0
- package/dist/db/connection.js +19 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/migrations/001_core_schema.d.ts +2 -0
- package/dist/db/migrations/001_core_schema.js +62 -0
- package/dist/db/migrations/001_core_schema.js.map +1 -0
- package/dist/db/migrations/002_learning_schema.d.ts +2 -0
- package/dist/db/migrations/002_learning_schema.js +45 -0
- package/dist/db/migrations/002_learning_schema.js.map +1 -0
- package/dist/db/migrations/003_synapse_schema.d.ts +2 -0
- package/dist/db/migrations/003_synapse_schema.js +26 -0
- package/dist/db/migrations/003_synapse_schema.js.map +1 -0
- package/dist/db/migrations/004_insights_schema.d.ts +2 -0
- package/dist/db/migrations/004_insights_schema.js +37 -0
- package/dist/db/migrations/004_insights_schema.js.map +1 -0
- package/dist/db/migrations/005_fts_indexes.d.ts +2 -0
- package/dist/db/migrations/005_fts_indexes.js +76 -0
- package/dist/db/migrations/005_fts_indexes.js.map +1 -0
- package/dist/db/migrations/index.d.ts +2 -0
- package/dist/db/migrations/index.js +47 -0
- package/dist/db/migrations/index.js.map +1 -0
- package/dist/db/repositories/audience.repository.d.ts +18 -0
- package/dist/db/repositories/audience.repository.js +45 -0
- package/dist/db/repositories/audience.repository.js.map +1 -0
- package/dist/db/repositories/campaign.repository.d.ts +15 -0
- package/dist/db/repositories/campaign.repository.js +58 -0
- package/dist/db/repositories/campaign.repository.js.map +1 -0
- package/dist/db/repositories/engagement.repository.d.ts +26 -0
- package/dist/db/repositories/engagement.repository.js +83 -0
- package/dist/db/repositories/engagement.repository.js.map +1 -0
- package/dist/db/repositories/insight.repository.d.ts +18 -0
- package/dist/db/repositories/insight.repository.js +87 -0
- package/dist/db/repositories/insight.repository.js.map +1 -0
- package/dist/db/repositories/post.repository.d.ts +21 -0
- package/dist/db/repositories/post.repository.js +105 -0
- package/dist/db/repositories/post.repository.js.map +1 -0
- package/dist/db/repositories/rule.repository.d.ts +16 -0
- package/dist/db/repositories/rule.repository.js +71 -0
- package/dist/db/repositories/rule.repository.js.map +1 -0
- package/dist/db/repositories/strategy.repository.d.ts +16 -0
- package/dist/db/repositories/strategy.repository.js +69 -0
- package/dist/db/repositories/strategy.repository.js.map +1 -0
- package/dist/db/repositories/synapse.repository.d.ts +25 -0
- package/dist/db/repositories/synapse.repository.js +115 -0
- package/dist/db/repositories/synapse.repository.js.map +1 -0
- package/dist/db/repositories/template.repository.d.ts +16 -0
- package/dist/db/repositories/template.repository.js +61 -0
- package/dist/db/repositories/template.repository.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/client.d.ts +13 -0
- package/dist/ipc/client.js +93 -0
- package/dist/ipc/client.js.map +1 -0
- package/dist/ipc/protocol.d.ts +8 -0
- package/dist/ipc/protocol.js +29 -0
- package/dist/ipc/protocol.js.map +1 -0
- package/dist/ipc/router.d.ts +30 -0
- package/dist/ipc/router.js +88 -0
- package/dist/ipc/router.js.map +1 -0
- package/dist/ipc/server.d.ts +14 -0
- package/dist/ipc/server.js +130 -0
- package/dist/ipc/server.js.map +1 -0
- package/dist/learning/confidence-scorer.d.ts +17 -0
- package/dist/learning/confidence-scorer.js +26 -0
- package/dist/learning/confidence-scorer.js.map +1 -0
- package/dist/learning/learning-engine.d.ts +33 -0
- package/dist/learning/learning-engine.js +211 -0
- package/dist/learning/learning-engine.js.map +1 -0
- package/dist/marketing-core.d.ts +17 -0
- package/dist/marketing-core.js +233 -0
- package/dist/marketing-core.js.map +1 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +67 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +3 -0
- package/dist/mcp/tools.js +138 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/research/research-engine.d.ts +28 -0
- package/dist/research/research-engine.js +211 -0
- package/dist/research/research-engine.js.map +1 -0
- package/dist/services/analytics.service.d.ts +116 -0
- package/dist/services/analytics.service.js +69 -0
- package/dist/services/analytics.service.js.map +1 -0
- package/dist/services/audience.service.d.ts +20 -0
- package/dist/services/audience.service.js +30 -0
- package/dist/services/audience.service.js.map +1 -0
- package/dist/services/campaign.service.d.ts +27 -0
- package/dist/services/campaign.service.js +65 -0
- package/dist/services/campaign.service.js.map +1 -0
- package/dist/services/insight.service.d.ts +18 -0
- package/dist/services/insight.service.js +40 -0
- package/dist/services/insight.service.js.map +1 -0
- package/dist/services/post.service.d.ts +48 -0
- package/dist/services/post.service.js +93 -0
- package/dist/services/post.service.js.map +1 -0
- package/dist/services/rule.service.d.ts +29 -0
- package/dist/services/rule.service.js +67 -0
- package/dist/services/rule.service.js.map +1 -0
- package/dist/services/strategy.service.d.ts +17 -0
- package/dist/services/strategy.service.js +39 -0
- package/dist/services/strategy.service.js.map +1 -0
- package/dist/services/synapse.service.d.ts +22 -0
- package/dist/services/synapse.service.js +22 -0
- package/dist/services/synapse.service.js.map +1 -0
- package/dist/services/template.service.d.ts +17 -0
- package/dist/services/template.service.js +37 -0
- package/dist/services/template.service.js.map +1 -0
- package/dist/synapses/activation.d.ts +13 -0
- package/dist/synapses/activation.js +50 -0
- package/dist/synapses/activation.js.map +1 -0
- package/dist/synapses/decay.d.ts +11 -0
- package/dist/synapses/decay.js +27 -0
- package/dist/synapses/decay.js.map +1 -0
- package/dist/synapses/hebbian.d.ts +13 -0
- package/dist/synapses/hebbian.js +35 -0
- package/dist/synapses/hebbian.js.map +1 -0
- package/dist/synapses/pathfinder.d.ts +14 -0
- package/dist/synapses/pathfinder.js +50 -0
- package/dist/synapses/pathfinder.js.map +1 -0
- package/dist/synapses/synapse-manager.d.ts +32 -0
- package/dist/synapses/synapse-manager.js +76 -0
- package/dist/synapses/synapse-manager.js.map +1 -0
- package/dist/types/config.types.d.ts +69 -0
- package/dist/types/config.types.js +2 -0
- package/dist/types/config.types.js.map +1 -0
- package/dist/types/ipc.types.d.ts +11 -0
- package/dist/types/ipc.types.js +2 -0
- package/dist/types/ipc.types.js.map +1 -0
- package/dist/types/post.types.d.ts +141 -0
- package/dist/types/post.types.js +2 -0
- package/dist/types/post.types.js.map +1 -0
- package/dist/types/synapse.types.d.ts +23 -0
- package/dist/types/synapse.types.js +2 -0
- package/dist/types/synapse.types.js.map +1 -0
- package/dist/utils/events.d.ts +57 -0
- package/dist/utils/events.js +23 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/hash.d.ts +1 -0
- package/dist/utils/hash.js +5 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +39 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.js +18 -0
- package/dist/utils/paths.js.map +1 -0
- package/package.json +40 -0
- package/seed-data.json +78 -0
- package/src/api/server.ts +86 -0
- package/src/cli/colors.ts +59 -0
- package/src/cli/commands/campaign.ts +66 -0
- package/src/cli/commands/config.ts +168 -0
- package/src/cli/commands/dashboard.ts +165 -0
- package/src/cli/commands/doctor.ts +110 -0
- package/src/cli/commands/export.ts +40 -0
- package/src/cli/commands/import.ts +84 -0
- package/src/cli/commands/insights.ts +44 -0
- package/src/cli/commands/learn.ts +24 -0
- package/src/cli/commands/network.ts +71 -0
- package/src/cli/commands/post.ts +47 -0
- package/src/cli/commands/query.ts +108 -0
- package/src/cli/commands/rules.ts +27 -0
- package/src/cli/commands/start.ts +100 -0
- package/src/cli/commands/status.ts +73 -0
- package/src/cli/commands/stop.ts +33 -0
- package/src/cli/commands/suggest.ts +64 -0
- package/src/cli/ipc-helper.ts +22 -0
- package/src/cli/update-check.ts +63 -0
- package/src/config.ts +110 -0
- package/src/dashboard/renderer.ts +136 -0
- package/src/dashboard/server.ts +140 -0
- package/src/db/connection.ts +22 -0
- package/src/db/migrations/001_core_schema.ts +63 -0
- package/src/db/migrations/002_learning_schema.ts +46 -0
- package/src/db/migrations/003_synapse_schema.ts +27 -0
- package/src/db/migrations/004_insights_schema.ts +38 -0
- package/src/db/migrations/005_fts_indexes.ts +77 -0
- package/src/db/migrations/index.ts +62 -0
- package/src/db/repositories/audience.repository.ts +53 -0
- package/src/db/repositories/campaign.repository.ts +72 -0
- package/src/db/repositories/engagement.repository.ts +108 -0
- package/src/db/repositories/insight.repository.ts +100 -0
- package/src/db/repositories/post.repository.ts +123 -0
- package/src/db/repositories/rule.repository.ts +87 -0
- package/src/db/repositories/strategy.repository.ts +82 -0
- package/src/db/repositories/synapse.repository.ts +148 -0
- package/src/db/repositories/template.repository.ts +76 -0
- package/src/index.ts +69 -0
- package/src/ipc/client.ts +110 -0
- package/src/ipc/protocol.ts +35 -0
- package/src/ipc/router.ts +126 -0
- package/src/ipc/server.ts +140 -0
- package/src/learning/confidence-scorer.ts +36 -0
- package/src/learning/learning-engine.ts +254 -0
- package/src/marketing-core.ts +285 -0
- package/src/mcp/server.ts +72 -0
- package/src/mcp/tools.ts +216 -0
- package/src/research/research-engine.ts +226 -0
- package/src/services/analytics.service.ts +73 -0
- package/src/services/audience.service.ts +40 -0
- package/src/services/campaign.service.ts +80 -0
- package/src/services/insight.service.ts +54 -0
- package/src/services/post.service.ts +116 -0
- package/src/services/rule.service.ts +90 -0
- package/src/services/strategy.service.ts +53 -0
- package/src/services/synapse.service.ts +32 -0
- package/src/services/template.service.ts +50 -0
- package/src/synapses/activation.ts +80 -0
- package/src/synapses/decay.ts +38 -0
- package/src/synapses/hebbian.ts +68 -0
- package/src/synapses/pathfinder.ts +81 -0
- package/src/synapses/synapse-manager.ts +115 -0
- package/src/types/config.types.ts +79 -0
- package/src/types/ipc.types.ts +8 -0
- package/src/types/post.types.ts +156 -0
- package/src/types/synapse.types.ts +43 -0
- package/src/utils/events.ts +44 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/logger.ts +48 -0
- package/src/utils/paths.ts +19 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export type Platform = 'x' | 'reddit' | 'linkedin' | 'bluesky' | 'mastodon' | 'threads' | 'other';
|
|
2
|
+
export type PostFormat = 'text' | 'image' | 'video' | 'carousel' | 'thread' | 'article' | 'poll';
|
|
3
|
+
export type PostStatus = 'draft' | 'scheduled' | 'published' | 'archived';
|
|
4
|
+
|
|
5
|
+
export interface Post {
|
|
6
|
+
id: number;
|
|
7
|
+
campaign_id: number | null;
|
|
8
|
+
platform: Platform;
|
|
9
|
+
content: string;
|
|
10
|
+
format: PostFormat;
|
|
11
|
+
hashtags: string | null;
|
|
12
|
+
url: string | null;
|
|
13
|
+
published_at: string | null;
|
|
14
|
+
fingerprint: string;
|
|
15
|
+
status: PostStatus;
|
|
16
|
+
created_at: string;
|
|
17
|
+
updated_at: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PostCreate {
|
|
21
|
+
campaign_id?: number | null;
|
|
22
|
+
platform: Platform;
|
|
23
|
+
content: string;
|
|
24
|
+
format?: PostFormat;
|
|
25
|
+
hashtags?: string;
|
|
26
|
+
url?: string;
|
|
27
|
+
published_at?: string;
|
|
28
|
+
status?: PostStatus;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Engagement {
|
|
32
|
+
id: number;
|
|
33
|
+
post_id: number;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
likes: number;
|
|
36
|
+
comments: number;
|
|
37
|
+
shares: number;
|
|
38
|
+
impressions: number;
|
|
39
|
+
clicks: number;
|
|
40
|
+
saves: number;
|
|
41
|
+
reach: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface EngagementCreate {
|
|
45
|
+
post_id: number;
|
|
46
|
+
likes?: number;
|
|
47
|
+
comments?: number;
|
|
48
|
+
shares?: number;
|
|
49
|
+
impressions?: number;
|
|
50
|
+
clicks?: number;
|
|
51
|
+
saves?: number;
|
|
52
|
+
reach?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Campaign {
|
|
56
|
+
id: number;
|
|
57
|
+
name: string;
|
|
58
|
+
brand: string | null;
|
|
59
|
+
goal: string | null;
|
|
60
|
+
platform: string | null;
|
|
61
|
+
status: string;
|
|
62
|
+
created_at: string;
|
|
63
|
+
updated_at: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface CampaignCreate {
|
|
67
|
+
name: string;
|
|
68
|
+
brand?: string;
|
|
69
|
+
goal?: string;
|
|
70
|
+
platform?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Audience {
|
|
74
|
+
id: number;
|
|
75
|
+
name: string;
|
|
76
|
+
platform: Platform | null;
|
|
77
|
+
demographics: string | null;
|
|
78
|
+
interests: string | null;
|
|
79
|
+
created_at: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Strategy {
|
|
83
|
+
id: number;
|
|
84
|
+
post_id: number | null;
|
|
85
|
+
description: string;
|
|
86
|
+
approach: string | null;
|
|
87
|
+
outcome: string | null;
|
|
88
|
+
confidence: number;
|
|
89
|
+
created_at: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface StrategyCreate {
|
|
93
|
+
post_id?: number;
|
|
94
|
+
description: string;
|
|
95
|
+
approach?: string;
|
|
96
|
+
outcome?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ContentTemplate {
|
|
100
|
+
id: number;
|
|
101
|
+
name: string;
|
|
102
|
+
structure: string;
|
|
103
|
+
example: string | null;
|
|
104
|
+
platform: Platform | null;
|
|
105
|
+
avg_engagement: number;
|
|
106
|
+
use_count: number;
|
|
107
|
+
created_at: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ContentTemplateCreate {
|
|
111
|
+
name: string;
|
|
112
|
+
structure: string;
|
|
113
|
+
example?: string;
|
|
114
|
+
platform?: Platform;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface MarketingRule {
|
|
118
|
+
id: number;
|
|
119
|
+
pattern: string;
|
|
120
|
+
recommendation: string;
|
|
121
|
+
confidence: number;
|
|
122
|
+
trigger_count: number;
|
|
123
|
+
success_count: number;
|
|
124
|
+
active: number;
|
|
125
|
+
created_at: string;
|
|
126
|
+
updated_at: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface RuleCreate {
|
|
130
|
+
pattern: string;
|
|
131
|
+
recommendation: string;
|
|
132
|
+
confidence?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface Insight {
|
|
136
|
+
id: number;
|
|
137
|
+
type: string;
|
|
138
|
+
title: string;
|
|
139
|
+
description: string;
|
|
140
|
+
confidence: number;
|
|
141
|
+
priority: number;
|
|
142
|
+
campaign_id: number | null;
|
|
143
|
+
active: number;
|
|
144
|
+
expires_at: string | null;
|
|
145
|
+
created_at: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface InsightCreate {
|
|
149
|
+
type: string;
|
|
150
|
+
title: string;
|
|
151
|
+
description: string;
|
|
152
|
+
confidence?: number;
|
|
153
|
+
priority?: number;
|
|
154
|
+
campaign_id?: number | null;
|
|
155
|
+
expires_at?: string;
|
|
156
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type NodeType =
|
|
2
|
+
| 'post'
|
|
3
|
+
| 'campaign'
|
|
4
|
+
| 'strategy'
|
|
5
|
+
| 'template'
|
|
6
|
+
| 'rule'
|
|
7
|
+
| 'audience'
|
|
8
|
+
| 'insight';
|
|
9
|
+
|
|
10
|
+
export type SynapseType =
|
|
11
|
+
| 'belongs_to'
|
|
12
|
+
| 'similar_to'
|
|
13
|
+
| 'engages_with'
|
|
14
|
+
| 'improves'
|
|
15
|
+
| 'prevents'
|
|
16
|
+
| 'recommends'
|
|
17
|
+
| 'generated_from'
|
|
18
|
+
| 'cross_promotes'
|
|
19
|
+
| 'informs'
|
|
20
|
+
| 'co_occurs';
|
|
21
|
+
|
|
22
|
+
export interface SynapseRecord {
|
|
23
|
+
id: number;
|
|
24
|
+
source_type: NodeType;
|
|
25
|
+
source_id: number;
|
|
26
|
+
target_type: NodeType;
|
|
27
|
+
target_id: number;
|
|
28
|
+
synapse_type: SynapseType;
|
|
29
|
+
weight: number;
|
|
30
|
+
activation_count: number;
|
|
31
|
+
last_activated_at: string;
|
|
32
|
+
metadata: string | null;
|
|
33
|
+
created_at: string;
|
|
34
|
+
updated_at: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface NetworkStats {
|
|
38
|
+
totalNodes: number;
|
|
39
|
+
totalSynapses: number;
|
|
40
|
+
avgWeight: number;
|
|
41
|
+
nodesByType: Record<NodeType, number>;
|
|
42
|
+
synapsesByType: Record<SynapseType, number>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
export interface MarketingEvents {
|
|
4
|
+
'post:created': { postId: number; campaignId: number | null; platform: string };
|
|
5
|
+
'post:published': { postId: number; platform: string };
|
|
6
|
+
'engagement:updated': { postId: number; engagementId: number };
|
|
7
|
+
'strategy:reported': { strategyId: number; postId: number };
|
|
8
|
+
'rule:learned': { ruleId: number; pattern: string };
|
|
9
|
+
'rule:triggered': { ruleId: number; postId: number };
|
|
10
|
+
'template:created': { templateId: number; platform: string };
|
|
11
|
+
'campaign:created': { campaignId: number; name: string };
|
|
12
|
+
'insight:created': { insightId: number; type: string };
|
|
13
|
+
'synapse:created': { synapseId: number; sourceType: string; targetType: string };
|
|
14
|
+
'synapse:strengthened': { synapseId: number; newWeight: number };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type MarketingEventName = keyof MarketingEvents;
|
|
18
|
+
|
|
19
|
+
export class TypedEventBus extends EventEmitter {
|
|
20
|
+
emit<K extends MarketingEventName>(event: K, data: MarketingEvents[K]): boolean {
|
|
21
|
+
return super.emit(event, data);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
on<K extends MarketingEventName>(event: K, listener: (data: MarketingEvents[K]) => void): this {
|
|
25
|
+
return super.on(event, listener);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
once<K extends MarketingEventName>(event: K, listener: (data: MarketingEvents[K]) => void): this {
|
|
29
|
+
return super.once(event, listener);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
off<K extends MarketingEventName>(event: K, listener: (data: MarketingEvents[K]) => void): this {
|
|
33
|
+
return super.off(event, listener);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let busInstance: TypedEventBus | null = null;
|
|
38
|
+
|
|
39
|
+
export function getEventBus(): TypedEventBus {
|
|
40
|
+
if (!busInstance) {
|
|
41
|
+
busInstance = new TypedEventBus();
|
|
42
|
+
}
|
|
43
|
+
return busInstance;
|
|
44
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getDataDir } from './paths.js';
|
|
4
|
+
|
|
5
|
+
const { combine, timestamp, printf, colorize } = winston.format;
|
|
6
|
+
|
|
7
|
+
const logFormat = printf(({ level, message, timestamp, ...meta }) => {
|
|
8
|
+
const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : '';
|
|
9
|
+
return `${timestamp} [${level}]${metaStr} ${message}`;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
let loggerInstance: winston.Logger | null = null;
|
|
13
|
+
|
|
14
|
+
export function createLogger(opts?: { level?: string; file?: string; maxSize?: number; maxFiles?: number }): winston.Logger {
|
|
15
|
+
if (loggerInstance) return loggerInstance;
|
|
16
|
+
|
|
17
|
+
const level = opts?.level ?? process.env['MARKETING_BRAIN_LOG_LEVEL'] ?? 'info';
|
|
18
|
+
const logFile = opts?.file ?? path.join(getDataDir(), 'marketing-brain.log');
|
|
19
|
+
const maxSize = opts?.maxSize ?? 10 * 1024 * 1024;
|
|
20
|
+
const maxFiles = opts?.maxFiles ?? 3;
|
|
21
|
+
|
|
22
|
+
const transports: winston.transport[] = [
|
|
23
|
+
new winston.transports.File({
|
|
24
|
+
filename: logFile,
|
|
25
|
+
maxsize: maxSize,
|
|
26
|
+
maxFiles,
|
|
27
|
+
format: combine(timestamp(), logFormat),
|
|
28
|
+
}),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
32
|
+
transports.push(
|
|
33
|
+
new winston.transports.Console({
|
|
34
|
+
format: combine(colorize(), timestamp(), logFormat),
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
loggerInstance = winston.createLogger({ level, transports });
|
|
40
|
+
return loggerInstance;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getLogger(): winston.Logger {
|
|
44
|
+
if (!loggerInstance) {
|
|
45
|
+
return createLogger();
|
|
46
|
+
}
|
|
47
|
+
return loggerInstance;
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
|
|
4
|
+
export function normalizePath(filePath: string): string {
|
|
5
|
+
return filePath.replace(/\\/g, '/');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getDataDir(): string {
|
|
9
|
+
const envDir = process.env['MARKETING_BRAIN_DATA_DIR'];
|
|
10
|
+
if (envDir) return path.resolve(envDir);
|
|
11
|
+
return path.join(os.homedir(), '.marketing-brain');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getPipeName(name: string = 'marketing-brain'): string {
|
|
15
|
+
if (process.platform === 'win32') {
|
|
16
|
+
return `\\\\.\\pipe\\${name}`;
|
|
17
|
+
}
|
|
18
|
+
return path.join(os.tmpdir(), `${name}.sock`);
|
|
19
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"rootDir": "src",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|