@nimble-way/nimble-js 0.6.0 → 0.8.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/CHANGELOG.md +57 -0
- package/client.d.mts +14 -3
- package/client.d.mts.map +1 -1
- package/client.d.ts +14 -3
- package/client.d.ts.map +1 -1
- package/client.js +21 -17
- package/client.js.map +1 -1
- package/client.mjs +21 -17
- package/client.mjs.map +1 -1
- package/internal/utils/query.d.mts +5 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +5 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +23 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +20 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils.d.mts +1 -0
- package/internal/utils.d.ts +1 -0
- package/internal/utils.js +1 -0
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +1 -0
- package/package.json +7 -1
- package/resources/agent.d.mts +8 -6
- package/resources/agent.d.mts.map +1 -1
- package/resources/agent.d.ts +8 -6
- package/resources/agent.d.ts.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/tasks.d.mts +2 -2
- package/resources/tasks.d.mts.map +1 -1
- package/resources/tasks.d.ts +2 -2
- package/resources/tasks.d.ts.map +1 -1
- package/resources/top-level.d.mts +289 -6
- package/resources/top-level.d.mts.map +1 -1
- package/resources/top-level.d.ts +289 -6
- package/resources/top-level.d.ts.map +1 -1
- package/src/client.ts +32 -22
- package/src/internal/utils/query.ts +23 -0
- package/src/internal/utils.ts +1 -0
- package/src/resources/agent.ts +9 -4
- package/src/resources/index.ts +2 -0
- package/src/resources/tasks.ts +2 -2
- package/src/resources/top-level.ts +1231 -5
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
|
|
|
11
11
|
import { getPlatformHeaders } from './internal/detect-platform';
|
|
12
12
|
import * as Shims from './internal/shims';
|
|
13
13
|
import * as Opts from './internal/request-options';
|
|
14
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
14
15
|
import { VERSION } from './version';
|
|
15
16
|
import * as Errors from './core/error';
|
|
16
17
|
import * as Uploads from './core/uploads';
|
|
@@ -19,6 +20,8 @@ import * as TopLevelAPI from './resources/top-level';
|
|
|
19
20
|
import {
|
|
20
21
|
ExtractAsyncParams,
|
|
21
22
|
ExtractAsyncResponse,
|
|
23
|
+
ExtractBatchParams,
|
|
24
|
+
ExtractBatchResponse,
|
|
22
25
|
ExtractParams,
|
|
23
26
|
ExtractResponse,
|
|
24
27
|
MapParams,
|
|
@@ -258,6 +261,23 @@ export class Nimble {
|
|
|
258
261
|
return this.post('/v1/extract/async', { body, ...options });
|
|
259
262
|
}
|
|
260
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Extract Batch Endpoint
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* const response = await client.extractBatch({
|
|
270
|
+
* params: [{ url: 'url' }],
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
extractBatch(
|
|
275
|
+
body: TopLevelAPI.ExtractBatchParams,
|
|
276
|
+
options?: RequestOptions,
|
|
277
|
+
): APIPromise<TopLevelAPI.ExtractBatchResponse> {
|
|
278
|
+
return this.post('/v1/extract/batch', { body, ...options });
|
|
279
|
+
}
|
|
280
|
+
|
|
261
281
|
/**
|
|
262
282
|
* Create map task
|
|
263
283
|
*
|
|
@@ -309,21 +329,8 @@ export class Nimble {
|
|
|
309
329
|
/**
|
|
310
330
|
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
311
331
|
*/
|
|
312
|
-
protected stringifyQuery(query: Record<string, unknown>): string {
|
|
313
|
-
return
|
|
314
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
315
|
-
.map(([key, value]) => {
|
|
316
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
317
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
318
|
-
}
|
|
319
|
-
if (value === null) {
|
|
320
|
-
return `${encodeURIComponent(key)}=`;
|
|
321
|
-
}
|
|
322
|
-
throw new Errors.NimbleError(
|
|
323
|
-
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
324
|
-
);
|
|
325
|
-
})
|
|
326
|
-
.join('&');
|
|
332
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
333
|
+
return stringifyQuery(query);
|
|
327
334
|
}
|
|
328
335
|
|
|
329
336
|
private getUserAgent(): string {
|
|
@@ -355,12 +362,13 @@ export class Nimble {
|
|
|
355
362
|
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
356
363
|
|
|
357
364
|
const defaultQuery = this.defaultQuery();
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
366
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
367
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
360
368
|
}
|
|
361
369
|
|
|
362
370
|
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
363
|
-
url.search = this.stringifyQuery(query
|
|
371
|
+
url.search = this.stringifyQuery(query);
|
|
364
372
|
}
|
|
365
373
|
|
|
366
374
|
return url.toString();
|
|
@@ -665,9 +673,9 @@ export class Nimble {
|
|
|
665
673
|
}
|
|
666
674
|
}
|
|
667
675
|
|
|
668
|
-
// If the API asks us to wait a certain amount of time
|
|
669
|
-
//
|
|
670
|
-
if (
|
|
676
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
677
|
+
// says, but otherwise calculate a default
|
|
678
|
+
if (timeoutMillis === undefined) {
|
|
671
679
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
672
680
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
673
681
|
}
|
|
@@ -799,7 +807,7 @@ export class Nimble {
|
|
|
799
807
|
) {
|
|
800
808
|
return {
|
|
801
809
|
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
802
|
-
body: this.stringifyQuery(body
|
|
810
|
+
body: this.stringifyQuery(body),
|
|
803
811
|
};
|
|
804
812
|
} else {
|
|
805
813
|
return this.#encoder({ body, headers });
|
|
@@ -840,10 +848,12 @@ export declare namespace Nimble {
|
|
|
840
848
|
export {
|
|
841
849
|
type ExtractResponse as ExtractResponse,
|
|
842
850
|
type ExtractAsyncResponse as ExtractAsyncResponse,
|
|
851
|
+
type ExtractBatchResponse as ExtractBatchResponse,
|
|
843
852
|
type MapResponse as MapResponse,
|
|
844
853
|
type SearchResponse as SearchResponse,
|
|
845
854
|
type ExtractParams as ExtractParams,
|
|
846
855
|
type ExtractAsyncParams as ExtractAsyncParams,
|
|
856
|
+
type ExtractBatchParams as ExtractBatchParams,
|
|
847
857
|
type MapParams as MapParams,
|
|
848
858
|
type SearchParams as SearchParams,
|
|
849
859
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { NimbleError } from '../../core/error';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
7
|
+
*/
|
|
8
|
+
export function stringifyQuery(query: object | Record<string, unknown>) {
|
|
9
|
+
return Object.entries(query)
|
|
10
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
11
|
+
.map(([key, value]) => {
|
|
12
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
13
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
14
|
+
}
|
|
15
|
+
if (value === null) {
|
|
16
|
+
return `${encodeURIComponent(key)}=`;
|
|
17
|
+
}
|
|
18
|
+
throw new NimbleError(
|
|
19
|
+
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
20
|
+
);
|
|
21
|
+
})
|
|
22
|
+
.join('&');
|
|
23
|
+
}
|
package/src/internal/utils.ts
CHANGED
package/src/resources/agent.ts
CHANGED
|
@@ -79,7 +79,7 @@ export interface AgentGetResponse {
|
|
|
79
79
|
|
|
80
80
|
managed_by?: string | null;
|
|
81
81
|
|
|
82
|
-
output_schema?:
|
|
82
|
+
output_schema?: unknown | null;
|
|
83
83
|
|
|
84
84
|
vertical?: string | null;
|
|
85
85
|
}
|
|
@@ -479,9 +479,9 @@ export interface AgentListParams {
|
|
|
479
479
|
limit?: number;
|
|
480
480
|
|
|
481
481
|
/**
|
|
482
|
-
* Filter
|
|
482
|
+
* Filter templates by attribution
|
|
483
483
|
*/
|
|
484
|
-
managed_by?: 'nimble' | 'community' | null;
|
|
484
|
+
managed_by?: 'nimble' | 'community' | 'self_managed' | null;
|
|
485
485
|
|
|
486
486
|
/**
|
|
487
487
|
* Pagination offset
|
|
@@ -491,7 +491,12 @@ export interface AgentListParams {
|
|
|
491
491
|
/**
|
|
492
492
|
* Filter by privacy level
|
|
493
493
|
*/
|
|
494
|
-
privacy?: 'public' | 'private' | 'all';
|
|
494
|
+
privacy?: 'public' | 'private' | 'all' | null;
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Search templates by name, domain, or vertical
|
|
498
|
+
*/
|
|
499
|
+
search?: string | null;
|
|
495
500
|
}
|
|
496
501
|
|
|
497
502
|
export interface AgentRunParams {
|
package/src/resources/index.ts
CHANGED
|
@@ -30,10 +30,12 @@ export {
|
|
|
30
30
|
export {
|
|
31
31
|
type ExtractResponse,
|
|
32
32
|
type ExtractAsyncResponse,
|
|
33
|
+
type ExtractBatchResponse,
|
|
33
34
|
type MapResponse,
|
|
34
35
|
type SearchResponse,
|
|
35
36
|
type ExtractParams,
|
|
36
37
|
type ExtractAsyncParams,
|
|
38
|
+
type ExtractBatchParams,
|
|
37
39
|
type MapParams,
|
|
38
40
|
type SearchParams,
|
|
39
41
|
} from './top-level';
|
package/src/resources/tasks.ts
CHANGED
|
@@ -77,7 +77,7 @@ export namespace TaskListResponse {
|
|
|
77
77
|
*/
|
|
78
78
|
account_name?: string;
|
|
79
79
|
|
|
80
|
-
api_type?: 'web' | 'serp' | 'ecommerce' | 'social' | 'agent' | 'extract';
|
|
80
|
+
api_type?: 'web' | 'serp' | 'ecommerce' | 'social' | 'media' | 'agent' | 'extract';
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Batch ID if this task is part of a batch.
|
|
@@ -174,7 +174,7 @@ export namespace TaskGetResponse {
|
|
|
174
174
|
*/
|
|
175
175
|
account_name?: string;
|
|
176
176
|
|
|
177
|
-
api_type?: 'web' | 'serp' | 'ecommerce' | 'social' | 'agent' | 'extract';
|
|
177
|
+
api_type?: 'web' | 'serp' | 'ecommerce' | 'social' | 'media' | 'agent' | 'extract';
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
180
|
* Batch ID if this task is part of a batch.
|