|
1 | 1 | import { createApiClient } from '../contract'; |
2 | 2 | import { McpResource } from '../resources/mcp'; |
3 | | -import { Logger, createDefaultLogger } from './logger'; |
| 3 | +import { createDefaultLogger, Logger } from './logger'; |
4 | 4 |
|
5 | 5 | /** |
6 | | - * Options for initializing the Tadata Node SDK |
| 6 | + * Options for initializing the Tadata Node SDK. |
| 7 | + * These settings configure the behavior of the SDK client. |
| 8 | + * |
| 9 | + * @since 0.1.0 |
7 | 10 | */ |
8 | 11 | export interface TadataOptions { |
9 | 12 | /** |
10 | | - * API key for authentication |
| 13 | + * Your Tadata API key. This is required for authentication. |
| 14 | + * You can obtain an API key from the Tadata dashboard. |
11 | 15 | */ |
12 | 16 | apiKey: string; |
13 | 17 |
|
14 | 18 | /** |
15 | | - * Whether to use development mode (sandbox) |
| 19 | + * Specifies whether to use the development mode (sandbox environment). |
| 20 | + * Set to `true` to use the sandbox for testing purposes. |
16 | 21 | * @default false |
17 | 22 | */ |
18 | 23 | dev?: boolean; |
19 | 24 |
|
20 | 25 | /** |
21 | | - * API version to use |
22 | | - * @default latest |
| 26 | + * The API version to use for requests. |
| 27 | + * It's recommended to use a specific version for stability. |
| 28 | + * @default ApiVersion.LATEST |
23 | 29 | */ |
24 | | - version?: string; |
25 | | - |
| 30 | + version?: '05-2025' | 'latest'; |
26 | 31 | /** |
27 | | - * Custom logger instance |
| 32 | + * A custom logger instance that conforms to the {@link Logger} interface. |
| 33 | + * If not provided, a default console logger (`ConsoleLogger`) will be used. |
| 34 | + * This allows you to integrate SDK logging with your application's logging solution. |
28 | 35 | * @default ConsoleLogger |
29 | 36 | */ |
30 | 37 | logger?: Logger; |
31 | 38 | } |
32 | 39 |
|
33 | 40 | /** |
34 | | - * Main class for the Tadata Node SDK |
| 41 | + * The main class for interacting with the Tadata API. |
| 42 | + * This class provides access to various Tadata resources and functionalities. |
35 | 43 | * |
| 44 | + * @since 0.1.0 |
36 | 45 | * @example |
37 | | - * ```typescript |
38 | | - * import { TadataNodeSDK, OpenApiSource } from '@tadata/node-sdk'; |
| 46 | + * \`\`\`typescript |
| 47 | + * import { TadataNodeSDK, ApiVersion } from '@tadata/node-sdk'; |
| 48 | + * // Assumes pino is installed for custom logging, otherwise default logger is used. |
| 49 | + * // import pino from 'pino'; |
39 | 50 | * |
40 | 51 | * const tadata = new TadataNodeSDK({ |
41 | 52 | * apiKey: process.env.TADATA_KEY!, |
42 | 53 | * dev: process.env.NODE_ENV !== 'production', |
43 | | - * version: '10-10-2024', |
44 | | - * logger: pino(), // optional |
| 54 | + * version: ApiVersion.V_05_2025, // Optional: Defaults to ApiVersion.LATEST |
| 55 | + * // logger: pino(), // Optional: Provide a custom logger |
45 | 56 | * }); |
46 | 57 | * |
47 | | - * // Load from JSON file |
48 | | - * const source = await OpenApiSource.fromFile('./acme-openapi.json'); |
49 | | - * // Or from JSON string or object |
50 | | - * // const source = OpenApiSource.fromJson(jsonString); |
51 | | - * // const source = OpenApiSource.fromObject(specObject); |
| 58 | + * async function main() { |
| 59 | + * // Example usage (assuming OpenApiSource and MCP deployment) |
| 60 | + * // const source = await OpenApiSource.fromFile('./my-api-spec.json'); |
| 61 | + * // const deployment = await tadata.mcp.deploy({ |
| 62 | + * // spec: source, |
| 63 | + * // specBaseUrl: 'https://api.example.com', |
| 64 | + * // name: 'My API Proxy' |
| 65 | + * // }); |
| 66 | + * // console.log('Deployment URL:', deployment.url); |
| 67 | + * } |
52 | 68 | * |
53 | | - * await tadata.mcp.deploy({ |
54 | | - * spec: source, |
55 | | - * specBaseUrl: 'https://acme.com/api', |
56 | | - * }); |
57 | | - * ``` |
| 69 | + * main().catch(console.error); |
| 70 | + * \`\`\` |
58 | 71 | */ |
59 | 72 | export class TadataNodeSDK { |
60 | 73 | /** |
61 | | - * MCP resource for deploying and managing Multi-Channel Proxies |
| 74 | + * Access to Model Context Protocol (MCP) functionalities. |
| 75 | + * Use this resource to deploy and manage your Model Context Protocol instances. |
| 76 | + * @readonly |
62 | 77 | */ |
63 | 78 | public readonly mcp: McpResource; |
| 79 | + |
64 | 80 | /** |
65 | | - * Create a new Tadata Node SDK instance |
| 81 | + * Creates a new instance of the TadataNodeSDK. |
| 82 | + * |
| 83 | + * @param options Configuration options for the SDK. See {@link TadataOptions}. |
66 | 84 | */ |
67 | 85 | constructor(options: TadataOptions) { |
68 | 86 | const logger = options.logger || createDefaultLogger(); |
69 | 87 | const isDev = options.dev || false; |
70 | | - |
71 | | - // Always use http://localhost:3000 as the baseUrl |
72 | | - // This is a requirement for the current implementation |
73 | | - const baseUrl = 'http://localhost:3000'; |
| 88 | + const baseUrl = isDev ? 'https://api.stage.tadata.com' : 'https://api.tadata.com'; |
74 | 89 |
|
75 | 90 | const client = createApiClient(options.apiKey, { |
76 | 91 | baseUrl, |
|
0 commit comments