harvester_sdk 1.0.22 → 1.0.24
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/dist/index.d.ts +2 -0
- package/dist/index.js +7 -1
- package/dist/sdk.d.ts +294 -0
- package/dist/sdk.js +418 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.js +15 -1
- package/index.ts +4 -0
- package/package.json +1 -1
- package/sdk.ts +558 -0
- package/types.ts +18 -0
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
26
|
export * from './types';
|
|
27
|
+
export * from './sdk';
|
|
28
|
+
export { HarvesterSDK, createHarvesterSDK, HarvesterSDKError } from './sdk';
|
|
27
29
|
import { Schema } from 'mongoose';
|
|
28
30
|
export declare const MongoDataSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
29
31
|
versionKey: false;
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.MongoApiKeySchema = exports.MongoGeoSelectionSchema = exports.MongoGeoSchema = exports.MongoSourceSchema = exports.MongoSourceGroupSchema = exports.MongoRegionSchema = exports.MongoDataSchema = void 0;
|
|
17
|
+
exports.MongoApiKeySchema = exports.MongoGeoSelectionSchema = exports.MongoGeoSchema = exports.MongoSourceSchema = exports.MongoSourceGroupSchema = exports.MongoRegionSchema = exports.MongoDataSchema = exports.HarvesterSDKError = exports.createHarvesterSDK = exports.HarvesterSDK = void 0;
|
|
18
18
|
// Export types for consumers
|
|
19
19
|
__exportStar(require("./types"), exports);
|
|
20
|
+
// Export SDK
|
|
21
|
+
__exportStar(require("./sdk"), exports);
|
|
22
|
+
var sdk_1 = require("./sdk");
|
|
23
|
+
Object.defineProperty(exports, "HarvesterSDK", { enumerable: true, get: function () { return sdk_1.HarvesterSDK; } });
|
|
24
|
+
Object.defineProperty(exports, "createHarvesterSDK", { enumerable: true, get: function () { return sdk_1.createHarvesterSDK; } });
|
|
25
|
+
Object.defineProperty(exports, "HarvesterSDKError", { enumerable: true, get: function () { return sdk_1.HarvesterSDKError; } });
|
|
20
26
|
const mongoose_1 = require("mongoose");
|
|
21
27
|
const types_1 = require("./types");
|
|
22
28
|
exports.MongoDataSchema = new mongoose_1.Schema({
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { RegionType, GeoType, DataType, platformsList } from './types';
|
|
3
|
+
export interface HarvesterSDKConfig {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface TimeRange {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RelativeTimeRange {
|
|
14
|
+
value: number;
|
|
15
|
+
unit: 'minutes' | 'hours' | 'days' | 'weeks' | 'months';
|
|
16
|
+
}
|
|
17
|
+
export type Platform = (typeof platformsList)[number];
|
|
18
|
+
export interface PaginationParams {
|
|
19
|
+
page?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
sort_by?: string;
|
|
22
|
+
sort_order?: 'asc' | 'desc';
|
|
23
|
+
}
|
|
24
|
+
export interface GetRegionsParams extends PaginationParams {
|
|
25
|
+
status?: 'active' | 'inactive' | 'deleted';
|
|
26
|
+
search?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface GetGeosParams extends PaginationParams {
|
|
29
|
+
region_id?: string;
|
|
30
|
+
region?: string;
|
|
31
|
+
is_used?: boolean;
|
|
32
|
+
search?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface GetDataParams extends PaginationParams {
|
|
35
|
+
region_id?: string;
|
|
36
|
+
region_ids?: string[];
|
|
37
|
+
time_range?: TimeRange;
|
|
38
|
+
relative_time?: RelativeTimeRange;
|
|
39
|
+
platform?: Platform;
|
|
40
|
+
platforms?: Platform[];
|
|
41
|
+
source_id?: string;
|
|
42
|
+
source_ids?: string[];
|
|
43
|
+
source_group_id?: string;
|
|
44
|
+
data_geo?: string[];
|
|
45
|
+
source_dominant_geos?: string[];
|
|
46
|
+
data_original_type?: string;
|
|
47
|
+
data_language?: string;
|
|
48
|
+
data_sentiment?: 'positive' | 'negative' | 'neutral' | 'mixed';
|
|
49
|
+
search?: string;
|
|
50
|
+
processing_status?: 'raw' | 'processed' | 'analyzed' | 'error';
|
|
51
|
+
fields?: string[];
|
|
52
|
+
exclude_fields?: string[];
|
|
53
|
+
}
|
|
54
|
+
export interface PaginatedResponse<T> {
|
|
55
|
+
data: T[];
|
|
56
|
+
pagination: {
|
|
57
|
+
page: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
total: number;
|
|
60
|
+
total_pages: number;
|
|
61
|
+
has_next: boolean;
|
|
62
|
+
has_prev: boolean;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface SDKResponse<T> {
|
|
66
|
+
success: boolean;
|
|
67
|
+
data: T;
|
|
68
|
+
error?: string;
|
|
69
|
+
message?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Harvester SDK - Client for interacting with the Harvester API
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const harvester = new HarvesterSDK({
|
|
77
|
+
* baseUrl: 'https://api.harvester.io',
|
|
78
|
+
* apiKey: 'your-api-key'
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // Get all regions
|
|
82
|
+
* const regions = await harvester.getRegions();
|
|
83
|
+
*
|
|
84
|
+
* // Get geos by region
|
|
85
|
+
* const geos = await harvester.getGeosByRegion('region-id');
|
|
86
|
+
*
|
|
87
|
+
* // Get data with filters
|
|
88
|
+
* const data = await harvester.getData({
|
|
89
|
+
* region_id: 'region-id',
|
|
90
|
+
* platform: 'telegram',
|
|
91
|
+
* time_range: { start: Date.now() - 86400000, end: Date.now() }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare class HarvesterSDK {
|
|
96
|
+
private client;
|
|
97
|
+
private config;
|
|
98
|
+
constructor(config: HarvesterSDKConfig);
|
|
99
|
+
/**
|
|
100
|
+
* Set or update the API key
|
|
101
|
+
*/
|
|
102
|
+
setApiKey(apiKey: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Make a custom request to the API
|
|
105
|
+
*/
|
|
106
|
+
request<T>(config: AxiosRequestConfig): Promise<T>;
|
|
107
|
+
/**
|
|
108
|
+
* Get all regions
|
|
109
|
+
*
|
|
110
|
+
* @param params - Optional filter and pagination parameters
|
|
111
|
+
* @returns Paginated list of regions
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const regions = await harvester.getRegions({ status: 'active' });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
getRegions(params?: GetRegionsParams): Promise<PaginatedResponse<RegionType>>;
|
|
119
|
+
/**
|
|
120
|
+
* Get a single region by ID
|
|
121
|
+
*
|
|
122
|
+
* @param regionId - The region ID
|
|
123
|
+
* @returns The region object
|
|
124
|
+
*/
|
|
125
|
+
getRegionById(regionId: string): Promise<RegionType>;
|
|
126
|
+
/**
|
|
127
|
+
* Get a region by slug
|
|
128
|
+
*
|
|
129
|
+
* @param slug - The region slug (e.g., 'new-york')
|
|
130
|
+
* @returns The region object
|
|
131
|
+
*/
|
|
132
|
+
getRegionBySlug(slug: string): Promise<RegionType>;
|
|
133
|
+
/**
|
|
134
|
+
* Get all geographies
|
|
135
|
+
*
|
|
136
|
+
* @param params - Optional filter and pagination parameters
|
|
137
|
+
* @returns Paginated list of geographies
|
|
138
|
+
*/
|
|
139
|
+
getGeos(params?: GetGeosParams): Promise<PaginatedResponse<GeoType>>;
|
|
140
|
+
/**
|
|
141
|
+
* Get geographies by region ID
|
|
142
|
+
*
|
|
143
|
+
* @param regionId - The region ID
|
|
144
|
+
* @param params - Optional pagination parameters
|
|
145
|
+
* @returns Paginated list of geographies in the region
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const geos = await harvester.getGeosByRegion('region-id', { limit: 50 });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
getGeosByRegion(regionId: string, params?: PaginationParams): Promise<PaginatedResponse<GeoType>>;
|
|
153
|
+
/**
|
|
154
|
+
* Get a single geography by ID
|
|
155
|
+
*
|
|
156
|
+
* @param geoId - The geography ID
|
|
157
|
+
* @returns The geography object
|
|
158
|
+
*/
|
|
159
|
+
getGeoById(geoId: string): Promise<GeoType>;
|
|
160
|
+
/**
|
|
161
|
+
* Search geographies by text
|
|
162
|
+
*
|
|
163
|
+
* @param query - Search query
|
|
164
|
+
* @param params - Optional filter parameters
|
|
165
|
+
* @returns Paginated list of matching geographies
|
|
166
|
+
*/
|
|
167
|
+
searchGeos(query: string, params?: GetGeosParams): Promise<PaginatedResponse<GeoType>>;
|
|
168
|
+
/**
|
|
169
|
+
* Get data with filters
|
|
170
|
+
*
|
|
171
|
+
* @param params - Filter and pagination parameters
|
|
172
|
+
* @returns Paginated list of data items
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Get telegram data from a specific region in the last 24 hours
|
|
177
|
+
* const data = await harvester.getData({
|
|
178
|
+
* region_id: 'region-id',
|
|
179
|
+
* platform: 'telegram',
|
|
180
|
+
* relative_time: { value: 24, unit: 'hours' }
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
getData(params?: GetDataParams): Promise<PaginatedResponse<DataType>>;
|
|
185
|
+
/**
|
|
186
|
+
* Get data by region ID
|
|
187
|
+
*
|
|
188
|
+
* @param regionId - The region ID
|
|
189
|
+
* @param params - Optional filter parameters
|
|
190
|
+
* @returns Paginated list of data items from the region
|
|
191
|
+
*/
|
|
192
|
+
getDataByRegion(regionId: string, params?: Omit<GetDataParams, 'region_id'>): Promise<PaginatedResponse<DataType>>;
|
|
193
|
+
/**
|
|
194
|
+
* Get data by platform
|
|
195
|
+
*
|
|
196
|
+
* @param platform - The platform to filter by
|
|
197
|
+
* @param params - Optional filter parameters
|
|
198
|
+
* @returns Paginated list of data items from the platform
|
|
199
|
+
*/
|
|
200
|
+
getDataByPlatform(platform: Platform, params?: Omit<GetDataParams, 'platform'>): Promise<PaginatedResponse<DataType>>;
|
|
201
|
+
/**
|
|
202
|
+
* Get data within a time range
|
|
203
|
+
*
|
|
204
|
+
* @param timeRange - The time range (start and end timestamps)
|
|
205
|
+
* @param params - Optional filter parameters
|
|
206
|
+
* @returns Paginated list of data items within the time range
|
|
207
|
+
*/
|
|
208
|
+
getDataByTimeRange(timeRange: TimeRange, params?: Omit<GetDataParams, 'time_range'>): Promise<PaginatedResponse<DataType>>;
|
|
209
|
+
/**
|
|
210
|
+
* Get data from relative time (e.g., last 24 hours)
|
|
211
|
+
*
|
|
212
|
+
* @param relativeTime - Relative time specification
|
|
213
|
+
* @param params - Optional filter parameters
|
|
214
|
+
* @returns Paginated list of data items
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const data = await harvester.getDataFromRelativeTime(
|
|
219
|
+
* { value: 7, unit: 'days' },
|
|
220
|
+
* { platform: 'telegram' }
|
|
221
|
+
* );
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
getDataFromRelativeTime(relativeTime: RelativeTimeRange, params?: Omit<GetDataParams, 'relative_time'>): Promise<PaginatedResponse<DataType>>;
|
|
225
|
+
/**
|
|
226
|
+
* Get a single data item by ID
|
|
227
|
+
*
|
|
228
|
+
* @param dataId - The data item ID
|
|
229
|
+
* @returns The data object
|
|
230
|
+
*/
|
|
231
|
+
getDataById(dataId: string): Promise<DataType>;
|
|
232
|
+
/**
|
|
233
|
+
* Search data by text content
|
|
234
|
+
*
|
|
235
|
+
* @param query - Search query
|
|
236
|
+
* @param params - Optional filter parameters
|
|
237
|
+
* @returns Paginated list of matching data items
|
|
238
|
+
*/
|
|
239
|
+
searchData(query: string, params?: GetDataParams): Promise<PaginatedResponse<DataType>>;
|
|
240
|
+
/**
|
|
241
|
+
* Get data count by filters (without fetching all data)
|
|
242
|
+
*
|
|
243
|
+
* @param params - Filter parameters
|
|
244
|
+
* @returns Count of matching data items
|
|
245
|
+
*/
|
|
246
|
+
getDataCount(params?: GetDataParams): Promise<number>;
|
|
247
|
+
/**
|
|
248
|
+
* Get data aggregated by a field
|
|
249
|
+
*
|
|
250
|
+
* @param field - Field to aggregate by (e.g., 'platform', 'source_region_id')
|
|
251
|
+
* @param params - Optional filter parameters
|
|
252
|
+
* @returns Aggregation results
|
|
253
|
+
*/
|
|
254
|
+
getDataAggregation(field: string, params?: GetDataParams): Promise<{
|
|
255
|
+
_id: string;
|
|
256
|
+
count: number;
|
|
257
|
+
}[]>;
|
|
258
|
+
/**
|
|
259
|
+
* Convert relative time to absolute time range
|
|
260
|
+
*/
|
|
261
|
+
relativeToAbsoluteTime(relative: RelativeTimeRange): TimeRange;
|
|
262
|
+
/**
|
|
263
|
+
* Build query parameters, removing undefined values
|
|
264
|
+
*/
|
|
265
|
+
private buildQueryParams;
|
|
266
|
+
/**
|
|
267
|
+
* Build data-specific query parameters
|
|
268
|
+
*/
|
|
269
|
+
private buildDataQueryParams;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Custom error class for Harvester SDK errors
|
|
273
|
+
*/
|
|
274
|
+
export declare class HarvesterSDKError extends Error {
|
|
275
|
+
status?: number;
|
|
276
|
+
data?: any;
|
|
277
|
+
constructor(message: string, status?: number, data?: any);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Create a new Harvester SDK instance
|
|
281
|
+
*
|
|
282
|
+
* @param config - SDK configuration
|
|
283
|
+
* @returns HarvesterSDK instance
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* const harvester = createHarvesterSDK({
|
|
288
|
+
* baseUrl: 'https://api.harvester.io',
|
|
289
|
+
* apiKey: 'your-api-key'
|
|
290
|
+
* });
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
export declare function createHarvesterSDK(config: HarvesterSDKConfig): HarvesterSDK;
|
|
294
|
+
export default HarvesterSDK;
|