Skip to content

Commit 37b13a8

Browse files
authored
Add Diligence API: Preview and Report (#12)
* Add configs * Add diligence to client * Update configs * Gen types * Add example
1 parent 6ab218d commit 37b13a8

File tree

9 files changed

+529
-2
lines changed

9 files changed

+529
-2
lines changed

packages/api/src/client/base.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import type {
3030
getProjectRecapResponse,
3131
getAssetListResponse,
3232
getAssetListParameters,
33+
getPreviewsResponse,
34+
getReportByAssetIDParameters,
35+
getReportByAssetIDResponse,
3336
getResearchReportsParameters,
3437
getResearchReportsResponse,
3538
getResearchReportByIdParameters,
@@ -228,6 +231,24 @@ export interface ResearchInterface {
228231
getResearchReportTags(options?: RequestOptions): Promise<getResearchReportTagsResponse>;
229232
}
230233

234+
/**
235+
* Interface for the Diligence API methods
236+
*/
237+
export interface DiligenceAPIInterface {
238+
/**
239+
* Gets a preview of the available diligence reports
240+
* @return The diligence reports
241+
*/
242+
getDiligencePreview(): Promise<getPreviewsResponse>;
243+
244+
/**
245+
* Gets a diligence report by asset ID
246+
* @param params The parameters for the diligence report
247+
* @return The diligence report
248+
*/
249+
getDiligenceReport(params: getReportByAssetIDParameters): Promise<getReportByAssetIDResponse>;
250+
}
251+
231252
/**
232253
* Abstract base class for the Messari client
233254
* Defines the structure and common functionality that all client implementations must provide

packages/api/src/client/client.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
getExchangeRecap,
1717
getExchangeRankingsRecap,
1818
getAssetList,
19+
getPreviews,
20+
getReportByAssetID,
1921
getResearchReports,
2022
getResearchReportById,
2123
getResearchReportTags,
@@ -53,6 +55,9 @@ import type {
5355
getExchangeRankingsRecapResponse,
5456
getAssetListParameters,
5557
getAssetListResponse,
58+
getPreviewsResponse,
59+
getReportByAssetIDResponse,
60+
getReportByAssetIDParameters,
5661
getResearchReportsParameters,
5762
getResearchReportsResponse,
5863
getResearchReportByIdParameters,
@@ -74,7 +79,16 @@ import type {
7479
RequestOptions,
7580
RequestParameters,
7681
} from "./types";
77-
import type { AIInterface, AssetInterface, IntelInterface, MarketsInterface, NewsInterface, RecapsAPIInterface, ResearchInterface } from "./base";
82+
import type {
83+
AIInterface,
84+
AssetInterface,
85+
DiligenceAPIInterface,
86+
IntelInterface,
87+
MarketsInterface,
88+
NewsInterface,
89+
RecapsAPIInterface,
90+
ResearchInterface,
91+
} from "./base";
7892
import { MessariClientBase } from "./base";
7993

8094
/**
@@ -745,4 +759,19 @@ export class MessariClient extends MessariClientBase {
745759
options,
746760
}),
747761
};
762+
763+
public readonly diligence: DiligenceAPIInterface = {
764+
getDiligencePreview: async () => {
765+
return this.request<getPreviewsResponse>({
766+
method: getPreviews.method,
767+
path: getPreviews.path(),
768+
});
769+
},
770+
getDiligenceReport: async (params: getReportByAssetIDParameters) => {
771+
return this.request<getReportByAssetIDResponse>({
772+
method: getReportByAssetID.method,
773+
path: getReportByAssetID.path(params),
774+
});
775+
},
776+
};
748777
}

packages/examples/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"start:chat": "tsx src/chatCompletion.ts",
1414
"start:marketdata": "tsx src/marketData.ts",
1515
"start:recaps": "tsx src/recaps.ts",
16+
"start:diligence": "tsx src/diligence.ts",
1617
"start:research": "tsx src/research.ts"
1718
},
1819
"dependencies": {

packages/examples/src/diligence.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { MessariClient } from "@messari-kit/api";
2+
import { printTable } from "console-table-printer";
3+
import type { getExchangeRecapParameters, getProjectRecapParameters } from "@messari-kit/types";
4+
import dotenv from "dotenv";
5+
6+
// Load environment variables from .env file
7+
dotenv.config();
8+
9+
// Get API key from environment variable
10+
const API_KEY = process.env.MESSARI_API_KEY;
11+
12+
// Check if API key is available
13+
if (!API_KEY) {
14+
console.error("Error: MESSARI_API_KEY environment variable is not set.");
15+
console.error("Please create a .env file with your API key or set it in your environment.");
16+
process.exit(1);
17+
}
18+
19+
// Initialize the Messari client
20+
const client = new MessariClient({
21+
apiKey: API_KEY,
22+
// Optional: Override the base URL if needed
23+
// baseUrl: "https://api.messari.io",
24+
});
25+
26+
async function main() {
27+
// Get preview of available reports
28+
try {
29+
const previews = await client.diligence.getDiligencePreview();
30+
console.log("\n--------------------------------");
31+
console.log("Diligence Previews");
32+
console.log("--------------------------------");
33+
const rows = [];
34+
for (const preview of previews) {
35+
if (rows.length > 5) break;
36+
rows.push({
37+
"AssetId": preview.assetId,
38+
"LastUpdated": preview.lastRevisedAt,
39+
"Project": preview.projectName,
40+
"Sector": preview.sector,
41+
});
42+
}
43+
printTable(rows);
44+
} catch (error) {
45+
console.error("Error calling getDiligencePreview:", error);
46+
}
47+
48+
// Get a report by asset ID
49+
try {
50+
const virtualsAssetId = "4eb07099-9d91-4318-a63f-6672e191ef43";
51+
const report = await client.diligence.getDiligenceReport({ assetId: virtualsAssetId });
52+
console.log("\n--------------------------------");
53+
console.log("Diligence Report");
54+
console.log("--------------------------------");
55+
56+
let excerpt = report.sections?.general_information?.markdown ?? "";
57+
excerpt = excerpt.length > 100 ? `${excerpt.substring(0, 100)}...` : excerpt;
58+
printTable([
59+
{
60+
"AssetId": report.assetId,
61+
"Project": report.projectName,
62+
"LastUpdated": report.lastRevisedAt,
63+
},
64+
]);
65+
console.log(excerpt);
66+
} catch (error) {
67+
console.error("Error calling getDiligenceReport:", error);
68+
}
69+
}
70+
71+
main().catch(console.error);

packages/types/src/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,35 @@ export const getResearchReportTags = {
316316
path: () => '/research/v1/reports/tags'
317317
} as const;
318318

319+
320+
export type getPreviewsResponse = components['schemas']['GetPreviewsResponse'];
321+
export type getPreviewsError = components['schemas']['APIError'];
322+
323+
export type getPreviewsParameters = { sector?: string; isDefaultIncluded?: boolean; isPublished?: boolean; isPurchased?: boolean; sort?: string; order?: string };
324+
325+
326+
export const getPreviews = {
327+
method: 'GET' as const,
328+
pathParams: [] as const,
329+
queryParams: ['sector', 'isDefaultIncluded', 'isPublished', 'isPurchased', 'sort', 'order'] as const,
330+
bodyParams: [] as const,
331+
path: () => '/diligence/v1/reports/preview'
332+
} as const;
333+
334+
335+
export type getReportByAssetIDResponse = components['schemas']['AssetReport'];
336+
export type getReportByAssetIDError = components['schemas']['APIError'];
337+
338+
export type getReportByAssetIDParameters = { assetId: string };
339+
340+
341+
export const getReportByAssetID = {
342+
method: 'GET' as const,
343+
pathParams: ['assetId'] as const,
344+
queryParams: [] as const,
345+
bodyParams: [] as const,
346+
path: (p: PathParams) => `/diligence/v1/report/asset/${p.assetId}`
347+
} as const;
348+
319349
// Re-export schema types
320350
export * from './schema';

packages/types/src/schema.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export type AssetMarketData = components['schemas']['AssetMarketData'];
2121

2222
export type AssetMarketcap = components['schemas']['AssetMarketcap'];
2323

24+
export type AssetReport = components['schemas']['AssetReport'];
25+
2426
export type AssetSupply = components['schemas']['AssetSupply'];
2527

2628
export type AssetWithATHData = components['schemas']['AssetWithATHData'];
@@ -75,6 +77,8 @@ export type GetAllEventsRequest = components['schemas']['GetAllEventsRequest'];
7577

7678
export type GetEventResponse = components['schemas']['GetEventResponse'];
7779

80+
export type GetPreviewsResponse = components['schemas']['GetPreviewsResponse'];
81+
7882
export type GetProjectRecapResponse = components['schemas']['GetProjectRecapResponse'];
7983

8084
export type GroupedEntity = components['schemas']['GroupedEntity'];
@@ -101,6 +105,10 @@ export type ROIData = components['schemas']['ROIData'];
101105

102106
export type RecapSlug = components['schemas']['RecapSlug'];
103107

108+
export type ReportResponse = components['schemas']['ReportResponse'];
109+
110+
export type ReportSection = components['schemas']['ReportSection'];
111+
104112
export type ResearchReport = components['schemas']['ResearchReport'];
105113

106114
export type ResearchResponse = components['schemas']['ResearchResponse'];

0 commit comments

Comments
 (0)