databar-mcp-server 1.3.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/LICENSE +21 -0
- package/README.md +205 -0
- package/dist/audit.d.ts +15 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +33 -0
- package/dist/audit.js.map +1 -0
- package/dist/cache.d.ts +40 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +78 -0
- package/dist/cache.js.map +1 -0
- package/dist/databar-client.d.ts +47 -0
- package/dist/databar-client.d.ts.map +1 -0
- package/dist/databar-client.js +377 -0
- package/dist/databar-client.js.map +1 -0
- package/dist/guards.d.ts +42 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +108 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +637 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +240 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +65 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +226 -0
- package/dist/utils.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Databar.ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Databar MCP Server
|
|
2
|
+
|
|
3
|
+
A [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that enables AI assistants like Claude to interact with [Databar.ai](https://databar.ai)'s data enrichment API. Discover, configure, and run data enrichments across hundreds of data providers using natural language.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Smart Enrichment Discovery** — Search and filter enrichments by keyword or category
|
|
8
|
+
- **Natural Language Interface** — Ask "get David's LinkedIn profile" and the right enrichment runs automatically
|
|
9
|
+
- **Bulk Operations** — Enrich many records in a single call with bulk enrichment and bulk waterfall support
|
|
10
|
+
- **Table Management** — Create tables, manage columns, insert/update/upsert rows
|
|
11
|
+
- **Waterfall Support** — Try multiple data providers sequentially until one succeeds
|
|
12
|
+
- **Async Handling** — Automatic polling for results with no manual intervention
|
|
13
|
+
- **Intelligent Caching** — 24-hour result cache reduces API calls and costs
|
|
14
|
+
- **Error Handling** — Retries with exponential backoff and clear error messages
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Prerequisites
|
|
19
|
+
|
|
20
|
+
- Node.js 18+
|
|
21
|
+
- A Databar.ai API key ([get one here](https://databar.ai))
|
|
22
|
+
|
|
23
|
+
### Install & Build
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
git clone https://github.com/databar-ai/databar-mcp-server.git
|
|
27
|
+
cd databar-mcp-server
|
|
28
|
+
npm install
|
|
29
|
+
npm run build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Configure Claude Desktop
|
|
33
|
+
|
|
34
|
+
Edit your Claude Desktop config file:
|
|
35
|
+
|
|
36
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
37
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"databar": {
|
|
43
|
+
"command": "node",
|
|
44
|
+
"args": ["/absolute/path/to/databar-mcp-server/dist/index.js"],
|
|
45
|
+
"env": {
|
|
46
|
+
"DATABAR_API_KEY": "your-api-key-here"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Restart Claude Desktop. Verify by asking: *"What Databar tools do you have access to?"*
|
|
54
|
+
|
|
55
|
+
## Usage Examples
|
|
56
|
+
|
|
57
|
+
### Find someone's LinkedIn profile
|
|
58
|
+
|
|
59
|
+
> *"Get me David Abaev's LinkedIn profile"*
|
|
60
|
+
|
|
61
|
+
Claude searches for LinkedIn enrichments, picks the right one, runs it, and returns the profile data.
|
|
62
|
+
|
|
63
|
+
### Verify an email address
|
|
64
|
+
|
|
65
|
+
> *"Verify the email david@databar.ai"*
|
|
66
|
+
|
|
67
|
+
### Find an email using waterfall
|
|
68
|
+
|
|
69
|
+
> *"Find the email for John Smith at Google"*
|
|
70
|
+
|
|
71
|
+
Runs a waterfall that tries multiple providers until one returns a result.
|
|
72
|
+
|
|
73
|
+
### Bulk enrich a list
|
|
74
|
+
|
|
75
|
+
> *"Enrich these 10 emails with company data: [list]"*
|
|
76
|
+
|
|
77
|
+
Uses bulk enrichment to process all records in a single API call.
|
|
78
|
+
|
|
79
|
+
### Manage table data
|
|
80
|
+
|
|
81
|
+
> *"List my tables"*
|
|
82
|
+
> *"Create 5 rows in table abc-123 with columns name and email"*
|
|
83
|
+
> *"Get the columns for table abc-123"*
|
|
84
|
+
|
|
85
|
+
## Available Tools
|
|
86
|
+
|
|
87
|
+
### Enrichments
|
|
88
|
+
|
|
89
|
+
| Tool | Description |
|
|
90
|
+
|------|-------------|
|
|
91
|
+
| `search_enrichments` | Search enrichments by keyword or category |
|
|
92
|
+
| `get_enrichment_details` | Get parameters, pricing, and response fields for an enrichment |
|
|
93
|
+
| `run_enrichment` | Run a single enrichment (with auto-polling and caching) |
|
|
94
|
+
| `run_bulk_enrichment` | Run an enrichment on multiple inputs at once |
|
|
95
|
+
|
|
96
|
+
### Waterfalls
|
|
97
|
+
|
|
98
|
+
| Tool | Description |
|
|
99
|
+
|------|-------------|
|
|
100
|
+
| `search_waterfalls` | Search available waterfall enrichments |
|
|
101
|
+
| `run_waterfall` | Run a waterfall (tries providers sequentially) |
|
|
102
|
+
| `run_bulk_waterfall` | Run a waterfall on multiple inputs at once |
|
|
103
|
+
|
|
104
|
+
### Tables
|
|
105
|
+
|
|
106
|
+
| Tool | Description |
|
|
107
|
+
|------|-------------|
|
|
108
|
+
| `create_table` | Create a new empty table |
|
|
109
|
+
| `list_tables` | List all tables in your workspace |
|
|
110
|
+
| `get_table_columns` | Get column schema for a table |
|
|
111
|
+
| `get_table_rows` | Get rows with pagination |
|
|
112
|
+
| `get_table_enrichments` | List enrichments configured on a table |
|
|
113
|
+
| `add_table_enrichment` | Add an enrichment to a table with column mapping |
|
|
114
|
+
| `run_table_enrichment` | Trigger an enrichment on all rows in a table |
|
|
115
|
+
|
|
116
|
+
### Row Operations
|
|
117
|
+
|
|
118
|
+
| Tool | Description |
|
|
119
|
+
|------|-------------|
|
|
120
|
+
| `create_rows` | Insert up to 50 rows with deduplication options |
|
|
121
|
+
| `patch_rows` | Update fields on existing rows by ID |
|
|
122
|
+
| `upsert_rows` | Insert or update rows based on a matching key |
|
|
123
|
+
|
|
124
|
+
### Account
|
|
125
|
+
|
|
126
|
+
| Tool | Description |
|
|
127
|
+
|------|-------------|
|
|
128
|
+
| `get_user_balance` | Get credit balance and account info |
|
|
129
|
+
|
|
130
|
+
## Configuration
|
|
131
|
+
|
|
132
|
+
All settings are configurable via environment variables:
|
|
133
|
+
|
|
134
|
+
| Variable | Default | Description |
|
|
135
|
+
|----------|---------|-------------|
|
|
136
|
+
| `DATABAR_API_KEY` | *(required)* | Your Databar API key |
|
|
137
|
+
| `DATABAR_BASE_URL` | `https://api.databar.ai/v1` | API base URL |
|
|
138
|
+
| `CACHE_TTL_HOURS` | `24` | Result cache TTL in hours |
|
|
139
|
+
| `MAX_POLL_ATTEMPTS` | `150` | Max polling attempts for async tasks |
|
|
140
|
+
| `POLL_INTERVAL_MS` | `2000` | Polling interval in ms |
|
|
141
|
+
|
|
142
|
+
## How It Works
|
|
143
|
+
|
|
144
|
+
### Async Task Handling
|
|
145
|
+
|
|
146
|
+
1. Server sends a run request to the Databar API
|
|
147
|
+
2. API returns a `task_id`
|
|
148
|
+
3. Server automatically polls `/v1/tasks/{task_id}` every 2 seconds
|
|
149
|
+
4. When status is `completed`, results are returned
|
|
150
|
+
5. If data has expired (1-hour retention), `gone` status is handled gracefully
|
|
151
|
+
|
|
152
|
+
### Caching
|
|
153
|
+
|
|
154
|
+
- Results are cached for 24 hours by default
|
|
155
|
+
- Cache key: enrichment ID + serialized params
|
|
156
|
+
- Cached results don't consume credits
|
|
157
|
+
- Use `skip_cache: true` to force fresh data
|
|
158
|
+
|
|
159
|
+
### Smart Categorization
|
|
160
|
+
|
|
161
|
+
Enrichments are automatically categorized (People, Company, Email, Phone, Social, Financial, Verification) to help the AI assistant pick the right tool.
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm run dev # Run with tsx (hot reload)
|
|
167
|
+
npm run build # Compile TypeScript
|
|
168
|
+
npm start # Run compiled output
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Project Structure
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
databar-mcp-server/
|
|
175
|
+
├── src/
|
|
176
|
+
│ ├── index.ts # MCP server entry point & tool handlers
|
|
177
|
+
│ ├── databar-client.ts # Databar API client with polling
|
|
178
|
+
│ ├── cache.ts # In-memory cache with TTL
|
|
179
|
+
│ ├── types.ts # TypeScript type definitions
|
|
180
|
+
│ └── utils.ts # Helpers & categorization
|
|
181
|
+
├── dist/ # Compiled output (generated)
|
|
182
|
+
├── package.json
|
|
183
|
+
├── tsconfig.json
|
|
184
|
+
└── .gitignore
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Troubleshooting
|
|
188
|
+
|
|
189
|
+
| Problem | Solution |
|
|
190
|
+
|---------|----------|
|
|
191
|
+
| Server not connecting | Verify API key, rebuild (`npm run build`), restart Claude Desktop |
|
|
192
|
+
| "No enrichments found" | Try a broader search query; list cache refreshes every 5 minutes |
|
|
193
|
+
| "Task timed out" | Some enrichments take longer; increase `MAX_POLL_ATTEMPTS` |
|
|
194
|
+
| "Task data has expired" | Data is stored for 1 hour only; re-run the enrichment |
|
|
195
|
+
| "Invalid API key" | Check `.env` or Claude Desktop config for typos/extra spaces |
|
|
196
|
+
|
|
197
|
+
## Resources
|
|
198
|
+
|
|
199
|
+
- [Databar API Documentation](https://apiv3.databar.ai)
|
|
200
|
+
- [Databar Web App](https://databar.ai)
|
|
201
|
+
- [MCP Protocol Docs](https://modelcontextprotocol.io)
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit logging for tool calls.
|
|
3
|
+
* Logs to stderr (standard for MCP servers) and optionally to a file.
|
|
4
|
+
*/
|
|
5
|
+
interface AuditEntry {
|
|
6
|
+
timestamp: string;
|
|
7
|
+
tool: string;
|
|
8
|
+
params: Record<string, any>;
|
|
9
|
+
estimatedCost?: number;
|
|
10
|
+
result: 'success' | 'error' | 'blocked' | 'cached';
|
|
11
|
+
message?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function auditLog(entry: AuditEntry): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,UAAU,UAAU;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAaD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAgBhD"}
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit logging for tool calls.
|
|
3
|
+
* Logs to stderr (standard for MCP servers) and optionally to a file.
|
|
4
|
+
*/
|
|
5
|
+
import { appendFileSync } from 'fs';
|
|
6
|
+
const LOG_FILE = process.env.DATABAR_AUDIT_LOG || null;
|
|
7
|
+
function redactSensitive(params) {
|
|
8
|
+
const redacted = { ...params };
|
|
9
|
+
for (const key of Object.keys(redacted)) {
|
|
10
|
+
const lower = key.toLowerCase();
|
|
11
|
+
if (lower.includes('apikey') || lower.includes('api_key') || lower.includes('password') || lower.includes('secret') || lower.includes('token')) {
|
|
12
|
+
redacted[key] = '[REDACTED]';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return redacted;
|
|
16
|
+
}
|
|
17
|
+
export function auditLog(entry) {
|
|
18
|
+
const safeEntry = {
|
|
19
|
+
...entry,
|
|
20
|
+
params: redactSensitive(entry.params),
|
|
21
|
+
};
|
|
22
|
+
const line = JSON.stringify(safeEntry);
|
|
23
|
+
console.error(`[audit] ${line}`);
|
|
24
|
+
if (LOG_FILE) {
|
|
25
|
+
try {
|
|
26
|
+
appendFileSync(LOG_FILE, line + '\n');
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Don't crash the server if log file write fails
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,IAAI,CAAC;AAWvD,SAAS,eAAe,CAAC,MAA2B;IAClD,MAAM,QAAQ,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC/B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/I,QAAQ,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAiB;IACxC,MAAM,SAAS,GAAe;QAC5B,GAAG,KAAK;QACR,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC;KACtC,CAAC;IAEF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IAEjC,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,CAAC;YACH,cAAc,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,iDAAiD;QACnD,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple in-memory cache with TTL support
|
|
3
|
+
*/
|
|
4
|
+
export declare class Cache {
|
|
5
|
+
private cache;
|
|
6
|
+
private ttlMs;
|
|
7
|
+
constructor(ttlHours?: number);
|
|
8
|
+
/**
|
|
9
|
+
* Generate cache key from enrichment ID and parameters
|
|
10
|
+
*/
|
|
11
|
+
private generateKey;
|
|
12
|
+
/**
|
|
13
|
+
* Check if cached entry is still valid
|
|
14
|
+
*/
|
|
15
|
+
private isValid;
|
|
16
|
+
/**
|
|
17
|
+
* Get cached data if available and valid
|
|
18
|
+
*/
|
|
19
|
+
get(enrichmentId: number | string, params: Record<string, any>): any | null;
|
|
20
|
+
/**
|
|
21
|
+
* Store data in cache
|
|
22
|
+
*/
|
|
23
|
+
set(enrichmentId: number | string, params: Record<string, any>, data: any): void;
|
|
24
|
+
/**
|
|
25
|
+
* Clear all cached entries
|
|
26
|
+
*/
|
|
27
|
+
clear(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Remove expired entries (garbage collection)
|
|
30
|
+
*/
|
|
31
|
+
cleanup(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get cache statistics
|
|
34
|
+
*/
|
|
35
|
+
getStats(): {
|
|
36
|
+
size: number;
|
|
37
|
+
ttlHours: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,KAAK,CAAS;gBAEV,QAAQ,GAAE,MAAW;IAKjC;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACH,OAAO,CAAC,OAAO;IAKf;;OAEG;IACH,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI;IAgB3E;;OAEG;IACH,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;IAShF;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,OAAO,IAAI,IAAI;IASf;;OAEG;IACH,QAAQ,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;CAM/C"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple in-memory cache with TTL support
|
|
3
|
+
*/
|
|
4
|
+
export class Cache {
|
|
5
|
+
cache;
|
|
6
|
+
ttlMs;
|
|
7
|
+
constructor(ttlHours = 24) {
|
|
8
|
+
this.cache = new Map();
|
|
9
|
+
this.ttlMs = ttlHours * 60 * 60 * 1000;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generate cache key from enrichment ID and parameters
|
|
13
|
+
*/
|
|
14
|
+
generateKey(enrichmentId, params) {
|
|
15
|
+
const sortedParams = JSON.stringify(params, Object.keys(params).sort());
|
|
16
|
+
return `${enrichmentId}:${sortedParams}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check if cached entry is still valid
|
|
20
|
+
*/
|
|
21
|
+
isValid(entry) {
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
return (now - entry.timestamp) < this.ttlMs;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get cached data if available and valid
|
|
27
|
+
*/
|
|
28
|
+
get(enrichmentId, params) {
|
|
29
|
+
const key = this.generateKey(enrichmentId, params);
|
|
30
|
+
const entry = this.cache.get(key);
|
|
31
|
+
if (!entry) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (!this.isValid(entry)) {
|
|
35
|
+
this.cache.delete(key);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return entry.data;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Store data in cache
|
|
42
|
+
*/
|
|
43
|
+
set(enrichmentId, params, data) {
|
|
44
|
+
const key = this.generateKey(enrichmentId, params);
|
|
45
|
+
const entry = {
|
|
46
|
+
data,
|
|
47
|
+
timestamp: Date.now()
|
|
48
|
+
};
|
|
49
|
+
this.cache.set(key, entry);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clear all cached entries
|
|
53
|
+
*/
|
|
54
|
+
clear() {
|
|
55
|
+
this.cache.clear();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Remove expired entries (garbage collection)
|
|
59
|
+
*/
|
|
60
|
+
cleanup() {
|
|
61
|
+
const now = Date.now();
|
|
62
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
63
|
+
if (!this.isValid(entry)) {
|
|
64
|
+
this.cache.delete(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get cache statistics
|
|
70
|
+
*/
|
|
71
|
+
getStats() {
|
|
72
|
+
return {
|
|
73
|
+
size: this.cache.size,
|
|
74
|
+
ttlHours: this.ttlMs / (60 * 60 * 1000)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,OAAO,KAAK;IACR,KAAK,CAA0B;IAC/B,KAAK,CAAS;IAEtB,YAAY,WAAmB,EAAE;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACzC,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,YAA6B,EAAE,MAA2B;QAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,OAAO,GAAG,YAAY,IAAI,YAAY,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACK,OAAO,CAAC,KAAiB;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,YAA6B,EAAE,MAA2B;QAC5D,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE,CAAC;Y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API Client with async polling support
|
|
3
|
+
*/
|
|
4
|
+
import { DatabarConfig, Enrichment, EnrichmentRunResponse, TaskResponse, Table, Column, TableEnrichment, AddEnrichmentRequest, CreateRowsRequest, CreateRowsResponse, PatchRowsRequest, PatchRowsResponse, UpsertRowsRequest, UpsertRowsResponse, Waterfall, WaterfallTaskResponse, User } from './types.js';
|
|
5
|
+
export declare class DatabarClient {
|
|
6
|
+
private client;
|
|
7
|
+
private config;
|
|
8
|
+
constructor(config: DatabarConfig);
|
|
9
|
+
private sleep;
|
|
10
|
+
private handleError;
|
|
11
|
+
private withRetry;
|
|
12
|
+
getAllEnrichments(): Promise<Enrichment[]>;
|
|
13
|
+
getEnrichmentDetails(enrichmentId: number): Promise<Enrichment>;
|
|
14
|
+
runEnrichment(enrichmentId: number, params: Record<string, any>): Promise<EnrichmentRunResponse>;
|
|
15
|
+
runBulkEnrichment(enrichmentId: number, paramsList: Record<string, any>[]): Promise<EnrichmentRunResponse>;
|
|
16
|
+
getTaskStatus(taskId: string): Promise<TaskResponse>;
|
|
17
|
+
pollTaskUntilComplete(taskId: string): Promise<any>;
|
|
18
|
+
runEnrichmentSync(enrichmentId: number, params: Record<string, any>): Promise<any>;
|
|
19
|
+
runBulkEnrichmentSync(enrichmentId: number, paramsList: Record<string, any>[]): Promise<any>;
|
|
20
|
+
getAllWaterfalls(): Promise<Waterfall[]>;
|
|
21
|
+
getWaterfallDetails(identifier: string): Promise<Waterfall>;
|
|
22
|
+
runWaterfall(identifier: string, params: Record<string, any>, enrichmentIds?: number[], emailVerifier?: number): Promise<EnrichmentRunResponse>;
|
|
23
|
+
runBulkWaterfall(identifier: string, paramsList: Record<string, any>[], enrichmentIds?: number[], emailVerifier?: number): Promise<EnrichmentRunResponse>;
|
|
24
|
+
runWaterfallSync(identifier: string, params: Record<string, any>, enrichmentIds?: number[], emailVerifier?: number): Promise<WaterfallTaskResponse>;
|
|
25
|
+
runBulkWaterfallSync(identifier: string, paramsList: Record<string, any>[], enrichmentIds?: number[], emailVerifier?: number): Promise<any>;
|
|
26
|
+
createTable(): Promise<Table>;
|
|
27
|
+
getAllTables(): Promise<Table[]>;
|
|
28
|
+
getTableColumns(tableUuid: string): Promise<Column[]>;
|
|
29
|
+
getTableEnrichments(tableUuid: string): Promise<TableEnrichment[]>;
|
|
30
|
+
addTableEnrichment(tableUuid: string, data: AddEnrichmentRequest): Promise<any>;
|
|
31
|
+
runTableEnrichment(tableUuid: string, enrichmentId: string): Promise<any>;
|
|
32
|
+
getTableRows(tableUuid: string, page?: number, perPage?: number): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Insert rows, auto-batching into chunks of 50 (API limit).
|
|
35
|
+
*/
|
|
36
|
+
createRows(tableId: string, request: CreateRowsRequest): Promise<CreateRowsResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Patch rows, auto-batching into chunks of 50 (API limit).
|
|
39
|
+
*/
|
|
40
|
+
patchRows(tableId: string, request: PatchRowsRequest): Promise<PatchRowsResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Upsert rows, auto-batching into chunks of 50 (API limit).
|
|
43
|
+
*/
|
|
44
|
+
upsertRows(tableId: string, request: UpsertRowsRequest): Promise<UpsertRowsResponse>;
|
|
45
|
+
getUserInfo(): Promise<User>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=databar-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"databar-client.d.ts","sourceRoot":"","sources":["../src/databar-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,aAAa,EACb,UAAU,EAGV,qBAAqB,EACrB,YAAY,EAEZ,KAAK,EACL,MAAM,EACN,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EAGT,qBAAqB,EACrB,IAAI,EAEL,MAAM,YAAY,CAAC;AAYpB,qBAAa,aAAa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