@uncover/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@uncover/sdk",
3
+ "version": "0.1.0",
4
+ "description": "JavaScript SDK for Uncover API",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.js"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "dev": "tsc --watch"
16
+ },
17
+ "keywords": ["uncover", "api", "sdk"],
18
+ "author": "",
19
+ "license": "MIT",
20
+ "devDependencies": {
21
+ "@types/node": "^20.10.6",
22
+ "typescript": "^5.3.3"
23
+ }
24
+ }
package/src/client.ts ADDED
@@ -0,0 +1,75 @@
1
+ import type { SearchRequest, SearchResponse, SearchStatusResponse } from "./types.js";
2
+
3
+ export class Uncover {
4
+ private apiKey: string;
5
+ private baseUrl: string;
6
+
7
+ constructor(apiKey: string, baseUrl: string = "https://api.uncover.dev") {
8
+ this.apiKey = apiKey;
9
+ this.baseUrl = baseUrl;
10
+ }
11
+
12
+ /**
13
+ * Search for problems mentioned on Reddit/Twitter about a topic
14
+ */
15
+ async search(request: SearchRequest): Promise<SearchResponse> {
16
+ const response = await fetch(`${this.baseUrl}/api/search`, {
17
+ method: "POST",
18
+ headers: {
19
+ "Content-Type": "application/json",
20
+ Authorization: `Bearer ${this.apiKey}`,
21
+ },
22
+ body: JSON.stringify(request),
23
+ });
24
+
25
+ if (!response.ok) {
26
+ const error = await response.json();
27
+ throw new Error(`Search failed: ${error.error || "Unknown error"}`);
28
+ }
29
+
30
+ return response.json();
31
+ }
32
+
33
+ /**
34
+ * Get the status and results of a search request
35
+ */
36
+ async getSearchStatus(requestId: string): Promise<SearchStatusResponse> {
37
+ const response = await fetch(`${this.baseUrl}/api/search/${requestId}`, {
38
+ headers: {
39
+ Authorization: `Bearer ${this.apiKey}`,
40
+ },
41
+ });
42
+
43
+ if (!response.ok) {
44
+ const error = await response.json();
45
+ throw new Error(`Failed to get status: ${error.error || "Unknown error"}`);
46
+ }
47
+
48
+ return response.json();
49
+ }
50
+
51
+ /**
52
+ * Poll for search completion with timeout
53
+ */
54
+ async waitForSearch(
55
+ requestId: string,
56
+ timeoutMs: number = 30000,
57
+ pollIntervalMs: number = 1000
58
+ ): Promise<SearchStatusResponse> {
59
+ const startTime = Date.now();
60
+
61
+ while (Date.now() - startTime < timeoutMs) {
62
+ const status = await this.getSearchStatus(requestId);
63
+
64
+ if (status.status === "completed" || status.status === "failed") {
65
+ return status;
66
+ }
67
+
68
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
69
+ }
70
+
71
+ throw new Error("Search request timed out");
72
+ }
73
+ }
74
+
75
+ export default Uncover;
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export { Uncover, default } from "./client.js";
2
+ export type {
3
+ SearchRequest,
4
+ SearchResponse,
5
+ SearchStatusResponse,
6
+ Problem,
7
+ Source,
8
+ SignupResponse,
9
+ SigninResponse,
10
+ } from "./types.js";
package/src/types.ts ADDED
@@ -0,0 +1,61 @@
1
+ export type Source = "reddit" | "twitter";
2
+
3
+ export interface SearchRequest {
4
+ query: string;
5
+ sources: Source[];
6
+ limit?: number;
7
+ }
8
+
9
+ export interface Problem {
10
+ text: string;
11
+ frequency: number;
12
+ sentiment: string;
13
+ }
14
+
15
+ export interface SearchResponse {
16
+ requestId: string;
17
+ status: "pending" | "processing" | "completed" | "failed";
18
+ query: string;
19
+ sources: Source[];
20
+ problems?: Problem[];
21
+ summary?: string;
22
+ trends?: string[];
23
+ cost?: number;
24
+ }
25
+
26
+ export interface SearchStatusResponse {
27
+ requestId: string;
28
+ status: "pending" | "processing" | "completed" | "failed";
29
+ query: string;
30
+ sources: Source[];
31
+ problems?: Problem[];
32
+ summary?: string;
33
+ trends?: string[];
34
+ createdAt: string;
35
+ }
36
+
37
+ export interface SignupResponse {
38
+ user: {
39
+ id: string;
40
+ email: string;
41
+ name?: string;
42
+ };
43
+ apiKey: {
44
+ id: string;
45
+ key: string;
46
+ name: string;
47
+ };
48
+ }
49
+
50
+ export interface SigninResponse {
51
+ user: {
52
+ id: string;
53
+ email: string;
54
+ name?: string;
55
+ };
56
+ apiKeys: Array<{
57
+ id: string;
58
+ name: string;
59
+ createdAt: string;
60
+ }>;
61
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "moduleResolution": "node",
10
+ "target": "ES2020",
11
+ "module": "ES2020"
12
+ },
13
+ "include": ["src"],
14
+ "exclude": ["node_modules"]
15
+ }