@astralibx/email-analytics 2.0.0 → 2.0.2

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.
Files changed (2) hide show
  1. package/README.md +30 -37
  2. package/package.json +1 -2
package/README.md CHANGED
@@ -55,18 +55,18 @@ const overview = await analytics.query.getOverview(
55
55
 
56
56
  ## Features
57
57
 
58
- - **Event Recording** -- single and batch insert with automatic timestamps ([docs](docs/event-recording.md))
59
- - **Daily Aggregation** -- rolls up raw events into per-day stats by account, rule, template, and overall ([docs](docs/aggregation.md))
60
- - **Range Aggregation** -- backfill or re-aggregate any date range ([docs](docs/aggregation.md))
61
- - **Time-Series Queries** -- overview, timeline (daily/weekly/monthly), per-account, per-rule, per-template ([docs](docs/querying.md))
62
- - **REST API** -- six endpoints with date-range query params ([docs](docs/api-routes.md))
63
- - **TTL Cleanup** -- MongoDB TTL index auto-expires old events; manual purge also available ([docs](docs/event-recording.md#ttl-and-cleanup))
64
- - **Programmatic API** -- use services directly without HTTP ([docs](docs/programmatic-api.md))
65
- - **Error Handling** -- typed error classes for validation, date range, and aggregation failures ([docs](docs/error-handling.md))
58
+ - **Event Recording** -- single and batch insert with automatic timestamps ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/event-recording.md))
59
+ - **Daily Aggregation** -- rolls up raw events into per-day stats by account, rule, template, and overall ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/aggregation.md))
60
+ - **Range Aggregation** -- backfill or re-aggregate any date range ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/aggregation.md))
61
+ - **Time-Series Queries** -- overview, timeline (daily/weekly/monthly), per-account, per-rule, per-template ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/querying.md))
62
+ - **REST API** -- six endpoints with date-range query params ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/api-routes.md))
63
+ - **TTL Cleanup** -- MongoDB TTL index auto-expires old events; manual purge also available ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/event-recording.md#ttl-and-cleanup))
64
+ - **Programmatic API** -- use services directly without HTTP ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/programmatic-api.md))
65
+ - **Error Handling** -- typed error classes for validation, date range, and aggregation failures ([docs](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/error-handling.md))
66
66
 
67
67
  ## Integration with Other Packages
68
68
 
69
- Wire hooks from `@astralibx/email-account-manager` and `@astralibx/email-rule-engine` to automatically record analytics events. See the [integration guide](docs/integration.md) for full examples.
69
+ Wire hooks from `@astralibx/email-account-manager` and `@astralibx/email-rule-engine` to automatically record analytics events. See the [integration guide](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/integration.md) for full examples.
70
70
 
71
71
  ```typescript
72
72
  import { createEmailAccountManager } from '@astralibx/email-account-manager';
@@ -75,27 +75,20 @@ import { createEmailAnalytics } from '@astralibx/email-analytics';
75
75
 
76
76
  const analytics = createEmailAnalytics({ db: { connection: conn } });
77
77
  const accountManager = createEmailAccountManager({ db: { connection: conn } });
78
- const ruleEngine = createEmailRuleEngine({ db: { connection: conn } });
79
-
80
- // Record events from rule engine execution
81
- ruleEngine.on('emailSent', async (detail) => {
82
- await analytics.events.record({
83
- type: 'sent',
84
- accountId: detail.accountId,
85
- ruleId: detail.ruleId,
86
- templateId: detail.templateId,
87
- recipientEmail: detail.recipientEmail,
88
- });
89
- });
90
78
 
91
- ruleEngine.on('emailFailed', async (detail) => {
92
- await analytics.events.record({
93
- type: 'failed',
94
- accountId: detail.accountId,
95
- ruleId: detail.ruleId,
96
- recipientEmail: detail.recipientEmail,
97
- metadata: { error: detail.error },
98
- });
79
+ // Record events via rule engine hooks config
80
+ const ruleEngine = createEmailRuleEngine({
81
+ db: { connection: conn },
82
+ hooks: {
83
+ onSend: async ({ ruleId, ruleName, email, status }) => {
84
+ await analytics.events.record({
85
+ type: status === 'sent' ? 'sent' : 'failed',
86
+ accountId: '...', // from your send context
87
+ recipientEmail: email,
88
+ ruleId,
89
+ });
90
+ },
91
+ },
99
92
  });
100
93
  ```
101
94
 
@@ -103,14 +96,14 @@ ruleEngine.on('emailFailed', async (detail) => {
103
96
 
104
97
  | Guide | Description |
105
98
  |-------|-------------|
106
- | [Configuration](docs/configuration.md) | Full config reference |
107
- | [Event Recording](docs/event-recording.md) | Recording events, batch insert, TTL |
108
- | [Aggregation](docs/aggregation.md) | Daily aggregation, range backfill |
109
- | [Querying](docs/querying.md) | Overview, timeline, grouped stats |
110
- | [API Routes](docs/api-routes.md) | REST endpoints reference |
111
- | [Programmatic API](docs/programmatic-api.md) | Using services directly |
112
- | [Integration](docs/integration.md) | Wiring with account-manager and rule-engine |
113
- | [Error Handling](docs/error-handling.md) | Error classes and codes |
99
+ | [Configuration](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/configuration.md) | Full config reference |
100
+ | [Event Recording](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/event-recording.md) | Recording events, batch insert, TTL |
101
+ | [Aggregation](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/aggregation.md) | Daily aggregation, range backfill |
102
+ | [Querying](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/querying.md) | Overview, timeline, grouped stats |
103
+ | [API Routes](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/api-routes.md) | REST endpoints reference |
104
+ | [Programmatic API](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/programmatic-api.md) | Using services directly |
105
+ | [Integration](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/integration.md) | Wiring with account-manager and rule-engine |
106
+ | [Error Handling](https://github.com/Hariprakash1997/astralib/blob/main/packages/email-analytics/docs/error-handling.md) | Error classes and codes |
114
107
 
115
108
  ## Exported Types
116
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralibx/email-analytics",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Email analytics with event recording, aggregation, time-series, and querying",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -27,7 +27,6 @@
27
27
  "test:watch": "vitest",
28
28
  "test:coverage": "vitest run --coverage",
29
29
  "lint": "eslint src/",
30
- "prepublishOnly": "npm run build",
31
30
  "clean": "rm -rf dist"
32
31
  },
33
32
  "keywords": [