A NodeJS SDK for the Delphi API
npm install delphi-node-sdkThe Delphi SDK provides an easy-to-use TypeScript interface for interacting with various analytics platforms such as dbt, Lightdash, Looker, Metabase, and Cube.js. It allows you to generate queries, refine them, obtain answers, create charts, search entities, and more.
To install the Delphi SDK, use the following command:
```
npm install delphi-node-sdk
First, import the DelphiApi class from the SDK:
`typescript`
import { DelphiApi } from 'delphi-node-sdk';
Create a new instance of the DelphiApi class with your credentials:
`typescript`
const delphi = new DelphiApi({
clientId: 'your-client-id',
apiKey: 'your-api-key',
});
The SDK will throw a DelphiError if there's a problem with the API request. To handle errors, use a try-catch block:
`typescript`
try {
const response = await delphi.someMethod(request);
} catch (error) {
console.error('An error occurred:', error);
}
The DelphiApi class provides the following methods.
Please refer to the types folder for details on the request and response objects of each method.
#### generateDbtMetricsQuery
`typescript`
generateDbtMetricsQuery(request: DbtMetricsQueryRequest): Promise
Generates a dbt metrics query based on the provided request.
#### generateLightdashQuery
`typescript`
generateLightdashQuery(request: LightdashQueryRequest): Promise
Generates a Lightdash query based on the provided request.
#### generateLookerQuery
`typescript`
generateLookerQuery(request: LookerQueryRequest): Promise
Generates a Looker query based on the provided request.
#### generateMetabaseQuery
`typescript`
generateMetabaseQuery(request: MetabaseQueryRequest): Promise
Generates a Metabase query based on the provided request.
#### generateCubeQuery
`typescript`
generateCubeQuery(request: CubeQueryRequest): Promise
Generates a Cube.js query based on the provided request.
#### summarizeQuery
`typescript`
summarizeQuery(request: SummarizeQueryRequest): Promise
Summarizes the given query to provide a human-readable summary.
#### refineQuery
`typescript`
refineQuery
Refines the given query based on the provided request, returning an optimized or more specific query.
#### answerFromData
`typescript`
answerFromData(request: GetAnswerRequest): Promise
Retrieves an answer from the data based on the provided request.
#### chartFromData
`typescript`
chartFromData(request: GetAnswerRequest): Promise
Generates a chart from the data based on the provided request.
#### searchEntities
`typescript`
searchEntities
Searches for entities in the data based on the provided request, returning a list of matching entities.
#### postValidatedQuery
`typescript`
postValidatedQuery(request: PostValidatedQueryRequest): Promise
Posts a validated query to the API, storing it for future reference.
#### getValidatedQueries
`typescript`
getValidatedQueries(request: GetValidatedQueryRequest): Promise
Retrieves a list of validated queries based on the provided request.
#### classifyMessage
`typescript`
classifyMessage(request: ClassifyMessageRequest): Promise
Classifies a given message based on the provided request, returning a classification result.
#### chat
`typescript`
chat(request: ChatRequest): Promise
Sends a chat request to the API and returns a chat response.
Here's an example of how to generate a Lightdash query:
`typescript
import { DelphiApi, LightdashQueryRequest } from 'delphi-sdk';
const delphi = new DelphiApi({
clientId: 'your-client-id',
apiKey: 'your-api-key',
});
async function generateQuery() {
const request: LightdashQueryRequest = {
// Your request data here
};
try {
const response = await delphi.generateLightdashQuery(request);
console.log('Generated Lightdash query:', response);
} catch (error) {
console.error('An error occurred:', error);
}
}
generateQuery();
`
Make sure to replace 'your-client-id' and 'your-api-key' with your actual credentials, and fill in the request object with the required data.
1. yarnyarn build
2. yarn link
3. yarn link delphi-node-sdk
4. (In the projects you are using this, such as the Delphi Frontend or Slack App) yarn build
5. After making any changes here, run again so that your applications get your changespackage.json` before pushing changes.
6. Bump the version number in