mx-cloud 0.0.18 → 0.0.19

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.
@@ -59,6 +59,9 @@ export default class Interpreter extends EventEmitter {
59
59
  private blocker;
60
60
  private cumulativeResults;
61
61
  private autohealFailures;
62
+ private namedResults;
63
+ private screenshotCounter;
64
+ private serializableDataByType;
62
65
  constructor(workflow: WorkflowFile, options?: Partial<InterpreterOptions>);
63
66
  trackAutohealFailure(error: string): void;
64
67
  private applyAdBlocker;
@@ -67,6 +67,12 @@ class Interpreter extends events_1.EventEmitter {
67
67
  this.blocker = null;
68
68
  this.cumulativeResults = [];
69
69
  this.autohealFailures = [];
70
+ this.namedResults = {};
71
+ this.screenshotCounter = 0;
72
+ this.serializableDataByType = {
73
+ scrapeList: {},
74
+ scrapeSchema: {}
75
+ };
70
76
  this.workflow = workflow.workflow;
71
77
  this.initializedWorkflow = null;
72
78
  this.options = Object.assign({ maxRepeats: 5, maxConcurrency: 5, serializableCallback: (data) => {
@@ -348,13 +354,22 @@ class Interpreter extends events_1.EventEmitter {
348
354
  * Beware of false linter errors - here, we know better!
349
355
  */
350
356
  const wawActions = {
351
- screenshot: (params) => __awaiter(this, void 0, void 0, function* () {
357
+ screenshot: (params, nameOverride) => __awaiter(this, void 0, void 0, function* () {
352
358
  var _a;
353
359
  if ((_a = this.options.debugChannel) === null || _a === void 0 ? void 0 : _a.setActionType) {
354
- this.options.debugChannel.setActionType('screenshot');
360
+ this.options.debugChannel.setActionType("screenshot");
355
361
  }
356
362
  const screenshotBuffer = yield page.screenshot(Object.assign(Object.assign({}, params), { path: undefined }));
357
- yield this.options.binaryCallback(screenshotBuffer, 'image/png');
363
+ const baseName = nameOverride || "Screenshot";
364
+ // ✅ Use the typed class property
365
+ this.screenshotCounter += 1;
366
+ const screenshotName = `${baseName} ${this.screenshotCounter}`;
367
+ // ✅ Pass structured metadata to binaryCallback
368
+ yield this.options.binaryCallback({
369
+ name: screenshotName,
370
+ data: screenshotBuffer,
371
+ mimeType: "image/png",
372
+ }, "image/png");
358
373
  }),
359
374
  enqueueLinks: (selector) => __awaiter(this, void 0, void 0, function* () {
360
375
  var _a;
@@ -450,7 +465,31 @@ class Interpreter extends events_1.EventEmitter {
450
465
  }
451
466
  console.log("Total accumulated rows:", this.cumulativeResults.length);
452
467
  console.log("Current results:", this.cumulativeResults);
453
- yield this.options.serializableCallback(this.cumulativeResults);
468
+ // ✅ Append schema results under "scrapeSchema" → name
469
+ const actionType = "scrapeSchema";
470
+ const actionName = schema.__name || "Texts";
471
+ if (!this.namedResults[actionType])
472
+ this.namedResults[actionType] = {};
473
+ this.namedResults[actionType][actionName] = this.cumulativeResults;
474
+ if (!this.serializableDataByType[actionType])
475
+ this.serializableDataByType[actionType] = {};
476
+ if (!this.serializableDataByType[actionType])
477
+ this.serializableDataByType[actionType] = {};
478
+ if (!this.serializableDataByType[actionType][actionName]) {
479
+ this.serializableDataByType[actionType][actionName] = {};
480
+ }
481
+ for (const row of this.cumulativeResults) {
482
+ for (const [key, value] of Object.entries(row)) {
483
+ if (value !== undefined) {
484
+ this.serializableDataByType[actionType][actionName][key] = value;
485
+ }
486
+ }
487
+ }
488
+ // now emit full structured object
489
+ yield this.options.serializableCallback({
490
+ scrapeList: this.serializableDataByType.scrapeList,
491
+ scrapeSchema: this.serializableDataByType.scrapeSchema
492
+ });
454
493
  }),
455
494
  scrapeList: (config) => __awaiter(this, void 0, void 0, function* () {
456
495
  var _a, _b;
@@ -491,12 +530,29 @@ class Interpreter extends events_1.EventEmitter {
491
530
  scrapeResults = [];
492
531
  }
493
532
  console.log(`ScrapeList completed with ${scrapeResults.length} results`);
494
- yield this.options.serializableCallback(scrapeResults);
533
+ // ✅ Append list results under "scrapeList" → name
534
+ const actionType = "scrapeList";
535
+ const actionName = config.__name || "List";
536
+ if (!this.serializableDataByType[actionType])
537
+ this.serializableDataByType[actionType] = {};
538
+ if (!this.serializableDataByType[actionType][actionName]) {
539
+ this.serializableDataByType[actionType][actionName] = [];
540
+ }
541
+ this.serializableDataByType[actionType][actionName].push(...scrapeResults);
542
+ yield this.options.serializableCallback({
543
+ scrapeList: this.serializableDataByType.scrapeList,
544
+ scrapeSchema: this.serializableDataByType.scrapeSchema
545
+ });
495
546
  }
496
547
  catch (error) {
497
548
  console.error('ScrapeList action failed completely:', error.message);
498
549
  // Don't throw error, just return empty array
499
- yield this.options.serializableCallback([]);
550
+ const actionType = "scrapeList";
551
+ const actionName = config.__name || "List";
552
+ if (!this.namedResults[actionType])
553
+ this.namedResults[actionType] = {};
554
+ this.namedResults[actionType][actionName] = [];
555
+ yield this.options.serializableCallback(this.namedResults);
500
556
  }
501
557
  }),
502
558
  scrapeListAuto: (config) => __awaiter(this, void 0, void 0, function* () {
@@ -569,6 +625,41 @@ class Interpreter extends events_1.EventEmitter {
569
625
  return;
570
626
  }
571
627
  this.log(`Launching ${String(step.action)}`, logger_1.Level.LOG);
628
+ try {
629
+ const debug = this.options.debugChannel;
630
+ if (debug === null || debug === void 0 ? void 0 : debug.setActionType) {
631
+ debug.setActionType(String(step.action));
632
+ }
633
+ // Safely extract name for this step
634
+ let stepName = null;
635
+ // If the workflow step itself has a name
636
+ if (step === null || step === void 0 ? void 0 : step.name) {
637
+ stepName = step.name;
638
+ }
639
+ // If the first arg is an object with a __name property
640
+ else if (Array.isArray(step === null || step === void 0 ? void 0 : step.args) &&
641
+ step.args.length > 0 &&
642
+ typeof step.args[0] === "object" &&
643
+ "__name" in step.args[0]) {
644
+ stepName = step.args[0].__name;
645
+ }
646
+ // If args itself is an object with a __name property
647
+ else if (typeof (step === null || step === void 0 ? void 0 : step.args) === "object" &&
648
+ (step === null || step === void 0 ? void 0 : step.args) !== null &&
649
+ "__name" in step.args) {
650
+ stepName = step.args.__name;
651
+ }
652
+ // Default fallback
653
+ if (!stepName) {
654
+ stepName = String(step.action);
655
+ }
656
+ if (debug && typeof debug.setActionName === "function") {
657
+ debug.setActionName(stepName);
658
+ }
659
+ }
660
+ catch (err) {
661
+ this.log(`Failed to set action name/type: ${err.message}`, logger_1.Level.WARN);
662
+ }
572
663
  try {
573
664
  if (step.action in wawActions) {
574
665
  // "Arrayifying" here should not be needed (TS + syntax checker - only arrays; but why not)
@@ -34,6 +34,8 @@ class Preprocessor {
34
34
  what: joi_1.default.array().items({
35
35
  action: joi_1.default.string().required(),
36
36
  args: joi_1.default.array().items(joi_1.default.any()),
37
+ name: joi_1.default.string(),
38
+ actionId: joi_1.default.string()
37
39
  }).required(),
38
40
  })).required(),
39
41
  });
@@ -27,6 +27,8 @@ export type CustomFunctions = 'scrape' | 'scrapeSchema' | 'scroll' | 'screenshot
27
27
  export type What = {
28
28
  action: MethodNames<Page> | CustomFunctions;
29
29
  args?: any[];
30
+ name?: string;
31
+ actionId?: string;
30
32
  };
31
33
  export type PageState = Partial<BaseConditions>;
32
34
  export type ParamType = Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mx-cloud",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "mx cloud",
5
5
  "main": "build/index.js",
6
6
  "typings": "build/index.d.ts",