scrapely 1.2.27 → 1.2.28

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,17 @@ 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
+ static debugCapture(key: string, payload: unknown): Promise<void>;
462
473
  /**
463
474
  * Helper to resolve storage identifier to a string ID or name.
464
475
  * Supports: string, { id: '...' }, { name: '...' }, { alias: '...' }
package/dist/actor.js CHANGED
@@ -656,6 +656,33 @@ 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
+ static async debugCapture(key, payload) {
673
+ if (process.env.SCRAPELY_DEBUG_CAPTURE !== '1' || !key)
674
+ return;
675
+ if (Actor._debugCaptureCount >= Actor.DEBUG_CAPTURE_MAX_RECORDS)
676
+ return;
677
+ try {
678
+ const text = (typeof payload === 'string' ? payload : JSON.stringify(payload) ?? '').slice(0, Actor.DEBUG_CAPTURE_MAX_BYTES);
679
+ Actor._debugCaptureCount++;
680
+ await Actor.setValue(await Actor.debugCaptureRecordKey(key), { key: String(key), payload: text });
681
+ }
682
+ catch {
683
+ // never break the run
684
+ }
685
+ }
659
686
  /**
660
687
  * Helper to resolve storage identifier to a string ID or name.
661
688
  * 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.28",
4
4
  "description": "Scrapely SDK for building JavaScript and TypeScript Actors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",