snapapi-sdk 1.3.0 → 1.4.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/index.d.ts +25 -0
- package/index.js +60 -0
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -171,6 +171,31 @@ declare class SnapAPI {
|
|
|
171
171
|
|
|
172
172
|
/** Download a specific snapshot image. */
|
|
173
173
|
getSnapshot(monitorId: string, snapshotId: string): Promise<Buffer>;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Analyze a webpage — extract structured text, links, headings, and AI-ready content.
|
|
177
|
+
*/
|
|
178
|
+
analyze(url: string, options?: { screenshot?: boolean; selector?: string }): Promise<Record<string, unknown>>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Convert a webpage to PDF. Returns a Buffer containing the PDF binary.
|
|
182
|
+
*/
|
|
183
|
+
pdf(url: string, options?: {
|
|
184
|
+
format?: 'A4' | 'A3' | 'A5' | 'Letter' | 'Legal' | 'Tabloid';
|
|
185
|
+
landscape?: boolean;
|
|
186
|
+
printBackground?: boolean;
|
|
187
|
+
scale?: number;
|
|
188
|
+
marginTop?: number;
|
|
189
|
+
marginBottom?: number;
|
|
190
|
+
marginLeft?: number;
|
|
191
|
+
marginRight?: number;
|
|
192
|
+
delay?: number;
|
|
193
|
+
}): Promise<Buffer>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Process multiple URLs in a single request (batch mode).
|
|
197
|
+
*/
|
|
198
|
+
batch(urls: string[], endpoint?: 'screenshot' | 'analyze' | 'metadata', params?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
174
199
|
}
|
|
175
200
|
|
|
176
201
|
export = SnapAPI;
|
package/index.js
CHANGED
|
@@ -294,6 +294,66 @@ class SnapAPI {
|
|
|
294
294
|
});
|
|
295
295
|
return res.json();
|
|
296
296
|
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Analyze a webpage — extract structured text, links, headings, and AI-ready content.
|
|
300
|
+
* @param {string} url - The webpage URL to analyze
|
|
301
|
+
* @param {object} [options]
|
|
302
|
+
* @param {boolean} [options.screenshot] - Include a screenshot in the response
|
|
303
|
+
* @param {string} [options.selector] - CSS selector to scope extraction to
|
|
304
|
+
* @returns {Promise<object>}
|
|
305
|
+
*/
|
|
306
|
+
async analyze(url, options = {}) {
|
|
307
|
+
if (!url || typeof url !== 'string') {
|
|
308
|
+
throw new SnapAPIError('URL is required', 0, null);
|
|
309
|
+
}
|
|
310
|
+
const res = await this._request('GET', '/v1/analyze', { query: { url, ...options } });
|
|
311
|
+
return res.json();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Convert a webpage to PDF.
|
|
316
|
+
* @param {string} url - The webpage URL to convert
|
|
317
|
+
* @param {object} [options]
|
|
318
|
+
* @param {string} [options.format] - Paper format: "A4" | "Letter" | "A3" | "Legal" (default "A4")
|
|
319
|
+
* @param {boolean} [options.landscape] - Landscape orientation (default false)
|
|
320
|
+
* @param {boolean} [options.printBackground] - Print background graphics (default true)
|
|
321
|
+
* @param {number} [options.scale] - Page scale 0.1-2 (default 1)
|
|
322
|
+
* @param {number} [options.marginTop] - Top margin in px (default 20)
|
|
323
|
+
* @param {number} [options.marginBottom] - Bottom margin in px (default 20)
|
|
324
|
+
* @param {number} [options.marginLeft] - Left margin in px (default 20)
|
|
325
|
+
* @param {number} [options.marginRight] - Right margin in px (default 20)
|
|
326
|
+
* @returns {Promise<Buffer>}
|
|
327
|
+
*/
|
|
328
|
+
async pdf(url, options = {}) {
|
|
329
|
+
if (!url || typeof url !== 'string') {
|
|
330
|
+
throw new SnapAPIError('URL is required', 0, null);
|
|
331
|
+
}
|
|
332
|
+
const query = { url };
|
|
333
|
+
for (const [key, value] of Object.entries(options)) {
|
|
334
|
+
if (value !== undefined && value !== null) {
|
|
335
|
+
query[toSnakeCase(key)] = value;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const res = await this._request('GET', '/v1/pdf', { query });
|
|
339
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
340
|
+
return Buffer.from(arrayBuffer);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Process multiple URLs in a single request.
|
|
345
|
+
* @param {string[]} urls - Array of URLs to process
|
|
346
|
+
* @param {string} endpoint - Target endpoint: "screenshot" | "analyze" | "metadata" (default "analyze")
|
|
347
|
+
* @param {object} [params] - Options passed to the endpoint for every URL
|
|
348
|
+
* @returns {Promise<object>}
|
|
349
|
+
*/
|
|
350
|
+
async batch(urls, endpoint = 'analyze', params = {}) {
|
|
351
|
+
if (!Array.isArray(urls) || urls.length === 0) {
|
|
352
|
+
throw new SnapAPIError('urls must be a non-empty array', 0, null);
|
|
353
|
+
}
|
|
354
|
+
const res = await this._request('POST', '/v1/batch', { json: { urls, endpoint, params } });
|
|
355
|
+
return res.json();
|
|
356
|
+
}
|
|
297
357
|
}
|
|
298
358
|
|
|
299
359
|
module.exports = SnapAPI;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snapapi-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Official Node.js SDK for SnapAPI — screenshot, metadata
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Official Node.js SDK for SnapAPI — screenshot, analyze, PDF, metadata, monitors, and more",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"license": "MIT",
|