Skip to content

Commit f5630fc

Browse files
committed
first commit
0 parents  commit f5630fc

31 files changed

+6913
-0
lines changed

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
node_modules
3+
coverage
4+
*.json
5+
jest.config.js

.eslintrc.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"prettier"
7+
],
8+
"plugins": ["@typescript-eslint", "prettier"],
9+
"env": {
10+
"node": true,
11+
"jest": true,
12+
"es6": true
13+
},
14+
"rules": {
15+
"prettier/prettier": "error",
16+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
17+
"@typescript-eslint/explicit-function-return-type": "off",
18+
"@typescript-eslint/explicit-module-boundary-types": "off",
19+
"no-console": ["warn", { "allow": ["warn", "error", "info"] }]
20+
},
21+
"overrides": [
22+
{
23+
"files": ["**/test/**/*.ts", "**/*.test.ts"],
24+
"rules": {
25+
"@typescript-eslint/no-explicit-any": "off"
26+
}
27+
},
28+
{
29+
"files": ["**/openapi/**/*.ts"],
30+
"rules": {
31+
"@typescript-eslint/no-explicit-any": "off"
32+
}
33+
},
34+
{
35+
"files": ["**/core/logger.ts"],
36+
"rules": {
37+
"no-console": "off"
38+
}
39+
}
40+
],
41+
"ignorePatterns": ["dist/", "node_modules/", "coverage/"]
42+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
dist
3+
node_modules
4+
docs

.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dist
2+
node_modules
3+
coverage
4+
*.json
5+
*.yml
6+
*.yaml
7+
README.md
8+
LICENSE
9+
.gitignore

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"tabWidth": 2,
6+
"semi": true,
7+
"quoteProps": "consistent",
8+
"jsxSingleQuote": true,
9+
"arrowParens": "avoid"
10+
}

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Tadata Node SDK
2+
3+
A Node.js SDK for deploying MCP (Multi-Channel Proxy) servers with your OpenAPI specifications.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @tadata/node-sdk
9+
# or
10+
yarn add @tadata/node-sdk
11+
# or
12+
pnpm add @tadata/node-sdk
13+
```
14+
15+
## Quickstart
16+
17+
Deploy an MCP server with your OpenAPI specification:
18+
19+
```typescript
20+
import { TadataNodeSDK, OpenApiSource } from '@tadata/node-sdk';
21+
22+
// Initialize the SDK
23+
const tadata = new TadataNodeSDK({
24+
apiKey: process.env.TADATA_KEY!,
25+
dev: process.env.NODE_ENV !== 'production',
26+
version: '10-10-2024', // Optional: specify API version
27+
logger: pino(), // Optional: use custom logger
28+
});
29+
30+
// Create an OpenAPI source from various formats
31+
const source = await OpenApiSource.fromFile('./acme-openapi.yaml');
32+
33+
// Deploy the MCP server
34+
const deployment = await tadata.mcp.deploy({
35+
spec: source,
36+
specBaseUrl: 'https://acme.com/api',
37+
name: 'Acme API', // Optional
38+
});
39+
40+
console.log(`Deployed MCP server: ${deployment.url}`);
41+
```
42+
43+
## OpenAPI Source Formats
44+
45+
The SDK supports multiple ways to provide your OpenAPI specification:
46+
47+
```typescript
48+
// From a file (YAML or JSON)
49+
const source = await OpenApiSource.fromFile('./openapi.yaml');
50+
51+
// From a JSON string
52+
const source = OpenApiSource.fromJson(jsonString);
53+
54+
// From a YAML string
55+
const source = OpenApiSource.fromYaml(yamlString);
56+
57+
// From a JavaScript object
58+
const source = OpenApiSource.fromObject({
59+
openapi: '3.0.0',
60+
info: { title: 'Example API', version: '1.0.0' },
61+
paths: { /* ... */ }
62+
});
63+
64+
// From an Express application
65+
const source = OpenApiSource.fromExpress(app);
66+
67+
// From a Fastify instance
68+
const source = OpenApiSource.fromFastify(fastifyApp);
69+
```
70+
71+
## Error Handling
72+
73+
The SDK provides specific error classes for better error handling:
74+
75+
```typescript
76+
import { SpecInvalidError, AuthError, ApiError, NetworkError } from '@tadata/node-sdk';
77+
78+
try {
79+
await tadata.mcp.deploy({ /* ... */ });
80+
} catch (error) {
81+
if (error instanceof SpecInvalidError) {
82+
console.error('Invalid OpenAPI spec:', error.message, error.details);
83+
} else if (error instanceof AuthError) {
84+
console.error('Authentication failed:', error.message);
85+
} else if (error instanceof ApiError) {
86+
console.error('API error:', error.message, error.statusCode);
87+
} else if (error instanceof NetworkError) {
88+
console.error('Network error:', error.message);
89+
} else {
90+
console.error('Unexpected error:', error);
91+
}
92+
}
93+
```
94+
95+
## Custom Logging
96+
97+
You can provide your own logger implementation:
98+
99+
```typescript
100+
import pino from 'pino';
101+
import { TadataNodeSDK, Logger } from '@tadata/node-sdk';
102+
103+
// Use pino
104+
const pinoLogger = pino();
105+
106+
const tadata = new TadataNodeSDK({
107+
apiKey: 'your-api-key',
108+
logger: pinoLogger,
109+
});
110+
111+
// Or create a custom logger
112+
class CustomLogger implements Logger {
113+
debug(msg: string, ...meta: unknown[]): void {
114+
// Your implementation
115+
}
116+
info(msg: string, ...meta: unknown[]): void {
117+
// Your implementation
118+
}
119+
warn(msg: string, ...meta: unknown[]): void {
120+
// Your implementation
121+
}
122+
error(msg: string, ...meta: unknown[]): void {
123+
// Your implementation
124+
}
125+
}
126+
```
127+
128+
## License
129+
130+
MIT

jest.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
roots: ['<rootDir>/src', '<rootDir>/test'],
6+
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
7+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts', '!src/dev.ts'],
8+
coverageDirectory: 'coverage',
9+
coverageReporters: ['text', 'lcov'],
10+
transform: {
11+
'^.+\\.tsx?$': [
12+
'ts-jest',
13+
{
14+
tsconfig: 'tsconfig.json'
15+
}
16+
]
17+
},
18+
moduleFileExtensions: ['ts', 'js', 'json', 'node']
19+
};

package.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "@tadata/node-sdk",
3+
"version": "0.1.0",
4+
"description": "A fluent SDK for working with Tadata's API",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"types": "dist/types/index.d.ts",
8+
"exports": {
9+
".": {
10+
"require": "./dist/cjs/index.js",
11+
"import": "./dist/esm/index.js",
12+
"types": "./dist/types/index.d.ts"
13+
}
14+
},
15+
"files": [
16+
"dist",
17+
"LICENSE",
18+
"README.md"
19+
],
20+
"sideEffects": false,
21+
"scripts": {
22+
"clean": "rimraf dist",
23+
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types",
24+
"build:cjs": "tsc -p tsconfig.cjs.json",
25+
"build:esm": "tsc -p tsconfig.esm.json",
26+
"build:types": "tsc -p tsconfig.types.json",
27+
"dev": "ts-node src/dev.ts",
28+
"test": "jest",
29+
"test:watch": "jest --watch",
30+
"test:coverage": "jest --coverage",
31+
"lint": "eslint . --ext .ts",
32+
"lint:fix": "eslint . --ext .ts --fix",
33+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
34+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
35+
"prepare": "npm run build"
36+
},
37+
"keywords": [
38+
"tadata",
39+
"api",
40+
"sdk",
41+
"openapi",
42+
"mcp"
43+
],
44+
"author": "Tadata Inc.",
45+
"license": "MIT",
46+
"dependencies": {
47+
"@apidevtools/swagger-parser": "^10.1.0",
48+
"@ts-rest/core": "^3.30.5",
49+
"axios": "^1.6.2",
50+
"swagger-jsdoc": "^6.2.8",
51+
"yaml": "^2.3.4",
52+
"zod": "^3.22.4"
53+
},
54+
"peerDependencies": {
55+
"express": "^4.18.2",
56+
"fastify": "^4.24.3"
57+
},
58+
"devDependencies": {
59+
"@types/jest": "^29.5.5",
60+
"@types/node": "^20.10.0",
61+
"@types/swagger-jsdoc": "^6.0.4",
62+
"@typescript-eslint/eslint-plugin": "^5.62.0",
63+
"@typescript-eslint/parser": "^5.62.0",
64+
"eslint": "^8.56.0",
65+
"eslint-config-prettier": "^10.1.5",
66+
"eslint-plugin-prettier": "^5.0.0",
67+
"express": "^4.18.2",
68+
"fastify": "^4.24.3",
69+
"jest": "^29.7.0",
70+
"nock": "^13.3.0",
71+
"prettier": "^3.1.0",
72+
"rimraf": "^5.0.5",
73+
"ts-jest": "^29.1.1",
74+
"ts-node": "^10.9.1",
75+
"typescript": "^5.2.2"
76+
}
77+
}

0 commit comments

Comments
 (0)