From c9c8707e3998879345731fac170eb1d4a7f0ae0e Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Thu, 1 Aug 2024 17:44:51 +0530 Subject: [PATCH 1/2] feat: add analytics api Signed-off-by: Adithya Krishna --- src/client.ts | 105 ++++++++++++++++++++++++++++---------------------- src/types.ts | 14 ++++++- 2 files changed, 73 insertions(+), 46 deletions(-) diff --git a/src/client.ts b/src/client.ts index 9e4b2e9..8332397 100644 --- a/src/client.ts +++ b/src/client.ts @@ -15,6 +15,7 @@ import { IContent, IExtractResponse, IExtractedMetadata, + ExtractionGraphAnalytics, } from "./types"; import { v4 as uuidv4 } from "uuid"; import CryptoJS from "crypto-js"; @@ -450,6 +451,20 @@ class IndexifyClient { return resp.data; } + async getExtractionGraphAnalytics({ + namespace, + extractionGraph, + }: { + namespace: string; + extractionGraph: string; + }): Promise { + const response = await this.client.get( + `namespaces/${namespace}/extraction_graphs/${extractionGraph}/analytics` + ); + + return response.data; + } + async waitForExtraction(contentIds: string | string[]): Promise { const ids = Array.isArray(contentIds) ? contentIds : [contentIds]; @@ -525,51 +540,51 @@ class IndexifyClient { } async listContent( - extractionGraph: string, - namespace?: string, - params?: { - namespace: string; - extractionGraph: string; - source?: string; - ingestedContentId?: string; - parentId?: string; - labelsFilter?: string[]; - startId?: string; - limit?: number; - returnTotal?: boolean; - } -): Promise<{ contentList: IContentMetadata[]; total?: number }> { - const defaultParams = { - namespace: namespace || this.namespace, - extraction_graph: extractionGraph, - return_total: false, - }; - - const mergedParams = { - ...defaultParams, - ...params, - namespace: params?.namespace || namespace || this.namespace, - extraction_graph: params?.extractionGraph || extractionGraph, - labels_filter: params?.labelsFilter, - ingested_content_id: params?.ingestedContentId, - parent_id: params?.parentId, - start_id: params?.startId, - }; - - const response = await this.client.get( - `extraction_graphs/${mergedParams.extraction_graph}/content`, - { params: mergedParams } - ); - - const contentList = response.data.content_list.map((item: IBaseContentMetadata) => - this.baseContentToContentMetadata(item) - ); - - return { - contentList, - total: mergedParams.return_total ? response.data.total : undefined - }; -} + extractionGraph: string, + namespace?: string, + params?: { + namespace: string; + extractionGraph: string; + source?: string; + ingestedContentId?: string; + parentId?: string; + labelsFilter?: string[]; + startId?: string; + limit?: number; + returnTotal?: boolean; + } + ): Promise<{ contentList: IContentMetadata[]; total?: number }> { + const defaultParams = { + namespace: namespace || this.namespace, + extraction_graph: extractionGraph, + return_total: false, + }; + + const mergedParams = { + ...defaultParams, + ...params, + namespace: params?.namespace || namespace || this.namespace, + extraction_graph: params?.extractionGraph || extractionGraph, + labels_filter: params?.labelsFilter, + ingested_content_id: params?.ingestedContentId, + parent_id: params?.parentId, + start_id: params?.startId, + }; + + const response = await this.client.get( + `extraction_graphs/${mergedParams.extraction_graph}/content`, + { params: mergedParams } + ); + + const contentList = response.data.content_list.map((item: IBaseContentMetadata) => + this.baseContentToContentMetadata(item) + ); + + return { + contentList, + total: mergedParams.return_total ? response.data.total : undefined + }; + } async sqlQuery(query: string): Promise { const response = await this.client.post( diff --git a/src/types.ts b/src/types.ts index 693c906..1478549 100644 --- a/src/types.ts +++ b/src/types.ts @@ -160,4 +160,16 @@ export interface StateChange extends IBase { created_at: number; processed_at: number; refcnt_object_id: string | null; -} \ No newline at end of file +} + +export interface ExtractionPolicyStatus { + pending: number; + success: number; + failure: number; +} + +export interface ExtractionGraphAnalytics { + task_analytics: { + [policyName: string]: ExtractionPolicyStatus; + }; +} From 18f60f25deed2fbaba62a6fd085ddd3b5d1e2824 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Thu, 1 Aug 2024 17:45:48 +0530 Subject: [PATCH 2/2] Analytics API Signed-off-by: Adithya Krishna --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6846d2e..33be8f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "getindexify", - "version": "0.0.64", + "version": "0.0.65", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "getindexify", - "version": "0.0.64", + "version": "0.0.65", "license": "ISC", "dependencies": { "axios": "^1.7.2", diff --git a/package.json b/package.json index b12d616..389cbee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getindexify", - "version": "0.0.64", + "version": "0.0.65", "description": "This is the TypeScript client for interacting with the Indexify service.", "main": "./dist/index.js", "module": "./dist/index.mjs",