Skip to content

Commit

Permalink
feat: [SC-25948] Add findCollectionsByString endpoint to NameGraph cl…
Browse files Browse the repository at this point in the history
…ass (#475)

* feat: [SC-25948] Add findCollectionsByString endpoint to NameGraph class

* feat: [SC-25948] Add changeset for new endpoint addition
  • Loading branch information
FrancoAguzzi authored Dec 4, 2024
1 parent 26d9ca2 commit 3663abc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-penguins-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@namehash/namegraph-sdk": minor
---

Adds findCollectionsByString endpoint to NameGraph SDK
59 changes: 59 additions & 0 deletions packages/namegraph-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ export interface NameGraphOptions {
namegraphEndpoint?: string;
}

export interface Collection {
collection_id: string;
title: string;
owner: string;
number_of_names: number;
last_updated_timestamp: number;
top_names: [
{
name: string;
namehash: string;
},
];
types: [string];
avatar_emoji: string;
avatar_image: string;
}

export interface FindCollectionsByStringResponse {
metadata: {
total_number_of_matched_collections: number;
processing_time_ms: number;
elasticsearch_processing_time_ms: number;
elasticsearch_communication_time_ms: number;
};
related_collections: Collection[];
other_collections: Collection[];
}

class NameGraphError extends Error {
constructor(
public status: number,
Expand All @@ -62,6 +90,37 @@ export class NameGraph {
this.abortController = new AbortController();
}

public findCollectionsByString(
query: string,
): Promise<FindCollectionsByStringResponse> {
const offset = 0;
const mode = "instant";
const limit_names = 10;
const max_per_type = 3;
const sort_order = "AI";
const min_other_collections = 0;
const max_other_collections = 3;
const max_total_collections = 6;
const name_diversity_ratio = 0.5;
const max_related_collections = 3;

const payload = {
limit_names,
offset,
sort_order,
max_related_collections,
max_per_type,
name_diversity_ratio,
min_other_collections,
max_other_collections,
max_total_collections,
query,
mode,
};

return this.rawRequest("find_collections_by_string", "POST", payload);
}

public groupedByCategory(
label: string,
): Promise<NamesGeneratedGroupedByCategory> {
Expand Down

0 comments on commit 3663abc

Please sign in to comment.