scrapely 1.2.27 → 1.2.29

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/actor.d.ts CHANGED
@@ -459,6 +459,19 @@ export declare class Actor {
459
459
  * @param options - Record options
460
460
  */
461
461
  static setValue<T>(key: string, value: T | null, options?: RecordOptions): Promise<void>;
462
+ private static _debugCaptureCount;
463
+ static readonly DEBUG_CAPTURE_MAX_BYTES: number;
464
+ static readonly DEBUG_CAPTURE_MAX_RECORDS = 500;
465
+ /** The key-value store record name for a capture key (item URL or id). */
466
+ static debugCaptureRecordKey(key: string): Promise<string>;
467
+ /**
468
+ * Save the raw source payload (API JSON or HTML) an item was extracted from, keyed by the
469
+ * item's URL or id, for platform diagnostics. Does nothing unless the platform enabled
470
+ * capture for this run (SCRAPELY_DEBUG_CAPTURE=1 on its own diagnostic runs).
471
+ */
472
+ /** debugCapture for synchronous code: fire and forget. Does nothing unless capture is enabled for the run. */
473
+ static debugCaptureSync(key: string, payload: unknown): void;
474
+ static debugCapture(key: string, payload: unknown): Promise<void>;
462
475
  /**
463
476
  * Helper to resolve storage identifier to a string ID or name.
464
477
  * Supports: string, { id: '...' }, { name: '...' }, { alias: '...' }
package/dist/actor.js CHANGED
@@ -656,6 +656,39 @@ class Actor {
656
656
  const store = await KeyValueStore.open();
657
657
  await store.setValue(key, value, options);
658
658
  }
659
+ static _debugCaptureCount = 0;
660
+ static DEBUG_CAPTURE_MAX_BYTES = 256 * 1024;
661
+ static DEBUG_CAPTURE_MAX_RECORDS = 500;
662
+ /** The key-value store record name for a capture key (item URL or id). */
663
+ static async debugCaptureRecordKey(key) {
664
+ const { createHash } = await import('node:crypto');
665
+ return `DEBUG_CAPTURE_${createHash('sha1').update(String(key).trim(), 'utf8').digest('hex').slice(0, 24)}`;
666
+ }
667
+ /**
668
+ * Save the raw source payload (API JSON or HTML) an item was extracted from, keyed by the
669
+ * item's URL or id, for platform diagnostics. Does nothing unless the platform enabled
670
+ * capture for this run (SCRAPELY_DEBUG_CAPTURE=1 on its own diagnostic runs).
671
+ */
672
+ /** debugCapture for synchronous code: fire and forget. Does nothing unless capture is enabled for the run. */
673
+ static debugCaptureSync(key, payload) {
674
+ if (process.env.SCRAPELY_DEBUG_CAPTURE !== '1' || !key)
675
+ return;
676
+ void Actor.debugCapture(key, payload);
677
+ }
678
+ static async debugCapture(key, payload) {
679
+ if (process.env.SCRAPELY_DEBUG_CAPTURE !== '1' || !key)
680
+ return;
681
+ if (Actor._debugCaptureCount >= Actor.DEBUG_CAPTURE_MAX_RECORDS)
682
+ return;
683
+ try {
684
+ const text = (typeof payload === 'string' ? payload : JSON.stringify(payload) ?? '').slice(0, Actor.DEBUG_CAPTURE_MAX_BYTES);
685
+ Actor._debugCaptureCount++;
686
+ await Actor.setValue(await Actor.debugCaptureRecordKey(key), { key: String(key), payload: text });
687
+ }
688
+ catch {
689
+ // never break the run
690
+ }
691
+ }
659
692
  /**
660
693
  * Helper to resolve storage identifier to a string ID or name.
661
694
  * Supports: string, { id: '...' }, { name: '...' }, { alias: '...' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scrapely",
3
- "version": "1.2.27",
3
+ "version": "1.2.29",
4
4
  "description": "Scrapely SDK for building JavaScript and TypeScript Actors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",