@powerhousedao/reactor-workflow 6.2.3-dev.32 → 6.2.3-dev.34

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { H as authMethodFor, S as maxFileBytes, U as unsupportedAuth, V as UnsupportedPieceFeatureError, W as unsupportedTrigger, a as redactMessage, c as DEFAULT_EGRESS_POLICY, d as parseAddress, m as extractDedupeKey, n as containsRedactedMarker, o as rememberSecrets, r as redact, s as secretsFor, u as isPrivateAddress, y as FileTooLargeError } from "./redact-LRWHJGW9.js";
2
- import { A as expressionsIn, B as PieceWorker, C as describeBuiltinPiece, E as BoundConnectionResolver, F as parseSecretRef, G as sourcedResolver, H as PieceWorkerTimeoutError, I as secretRefFromId, J as npmRegistryBaseUrl, L as stepBlock, N as SecretDeletedError, O as declaredConnectionIds, P as SecretNotFoundError, R as triggerBlock, S as builtinPiece, T as CORE_PIECE_VERSION, U as bundleResolver, V as PieceWorkerError, W as pieceModuleRef, X as setPieceRegistryUrl, Y as pieceRegistrySource, _ as servesReactorPort, a as runWorkflow, b as unpinnedNote, c as stepConfigHash, d as ActivepiecesBlockExecutor, f as CompositeBlockExecutor, g as resolvedBlock, h as reactorHandlers, i as packagePieces, j as resolveExpressions, k as shapeConnection, l as DynamicPropertiesError, m as isHostBound, n as installedPiece, o as canonicalJson, p as REACTOR_PORT_PIECE, r as installedPieces, s as hashOf, t as PieceRegistry, u as checkDynamicProperties, v as storeHandlers, w as CORE_PIECE_NAME, x as blockPorts, y as blockLabel, z as PieceWorkerPool } from "./piece-registry-BAm8pRDY.js";
2
+ import { A as resolveStepInput, B as PieceWorker, C as describeBuiltinPiece, E as BoundConnectionResolver, F as parseSecretRef, G as sourcedResolver, H as PieceWorkerTimeoutError, I as secretRefFromId, J as npmRegistryBaseUrl, L as stepBlock, N as SecretDeletedError, O as declaredConnectionIds, P as SecretNotFoundError, R as triggerBlock, S as builtinPiece, T as CORE_PIECE_VERSION, U as bundleResolver, V as PieceWorkerError, W as pieceModuleRef, X as setPieceRegistryUrl, Y as pieceRegistrySource, _ as servesReactorPort, a as runWorkflow, b as unpinnedNote, c as stepConfigHash, d as ActivepiecesBlockExecutor, f as CompositeBlockExecutor, g as resolvedBlock, h as reactorHandlers, i as packagePieces, j as expressionsIn, k as shapeConnection, l as DynamicPropertiesError, m as isHostBound, n as installedPiece, o as canonicalJson, p as REACTOR_PORT_PIECE, r as installedPieces, s as hashOf, t as PieceRegistry, u as checkDynamicProperties, v as storeHandlers, w as CORE_PIECE_NAME, x as blockPorts, y as blockLabel, z as PieceWorkerPool } from "./piece-registry-CAMLtGeP.js";
3
3
  import { WebhookHandshakeStrategy } from "@powerhousedao/pieces-framework";
4
4
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { open, readFile, rm } from "node:fs/promises";
@@ -6864,8 +6864,47 @@ async function up(db) {
6864
6864
  try {
6865
6865
  await db.schema.dropTable("webhook_endpoint").ifExists().execute();
6866
6866
  } catch {}
6867
+ await migrateBlockType(db, "trigger_state", "trigger_name");
6868
+ await migrateBlockType(db, "step_execution", "block_name");
6867
6869
  return migrateTriggerStoreState(db);
6868
6870
  }
6871
+ const LEGACY_CORE_PIECE = "core";
6872
+ function legacyBlockIdentity(blockType) {
6873
+ const separator = blockType.lastIndexOf("#");
6874
+ if (separator <= 0) return {
6875
+ pieceName: blockType,
6876
+ name: ""
6877
+ };
6878
+ const spec = blockType.slice(0, separator);
6879
+ const fragment = blockType.slice(separator + 1);
6880
+ const name = fragment.startsWith("trigger:") ? fragment.slice(8) : fragment;
6881
+ const versionAt = spec.indexOf("@", 1);
6882
+ const pieceName = versionAt > 0 ? spec.slice(0, versionAt) : spec;
6883
+ return {
6884
+ pieceName: pieceName === LEGACY_CORE_PIECE ? CORE_PIECE_NAME : pieceName,
6885
+ name
6886
+ };
6887
+ }
6888
+ async function migrateBlockType(db, table, nameColumn) {
6889
+ const legacy = db;
6890
+ try {
6891
+ await legacy.schema.alterTable(table).alterColumn("block_type", (col) => col.dropNotNull()).execute();
6892
+ } catch {
6893
+ return;
6894
+ }
6895
+ for (const column of ["piece_name", nameColumn]) try {
6896
+ await legacy.schema.alterTable(table).addColumn(column, "text").execute();
6897
+ } catch {}
6898
+ const key = table === "trigger_state" ? "workflow_id" : "id";
6899
+ const rows = await legacy.selectFrom(table).select([key, "block_type"]).where((eb) => eb.or([eb("piece_name", "is", null), eb(nameColumn, "is", null)])).execute();
6900
+ for (const row of rows) {
6901
+ const { pieceName, name } = legacyBlockIdentity(row.block_type ?? "");
6902
+ await legacy.updateTable(table).set({
6903
+ piece_name: pieceName,
6904
+ [nameColumn]: name
6905
+ }).where(key, "=", row[key]).execute();
6906
+ }
6907
+ }
6869
6908
  async function migrateTriggerStoreState(db) {
6870
6909
  const unmigrated = /* @__PURE__ */ new Set();
6871
6910
  let rows;
@@ -8474,6 +8513,11 @@ var WorkflowRuntimeService = class {
8474
8513
  seedError;
8475
8514
  constructor(host) {
8476
8515
  this.host = host;
8516
+ this.blockResolver = new BlockResolver({
8517
+ local: installedPiece,
8518
+ timeoutMs: host.pieceVersionLookupMs ?? PIECE_VERSION_LOOKUP_TIMEOUT_MS,
8519
+ hasBlock: (ref, version, source) => this.versionHasBlock(ref, version, source)
8520
+ });
8477
8521
  this.logger = host.logger ?? logger;
8478
8522
  this.attachments = host.attachments ? createAttachmentPort(host.attachments, () => currentWorkflowId(), (documentId, ref) => host.canReadAttachmentRef?.(documentId, ref) ?? Promise.resolve(false)) : void 0;
8479
8523
  this.storePromise = WorkflowRunStore.create(host.relationalDb);
@@ -8746,11 +8790,7 @@ var WorkflowRuntimeService = class {
8746
8790
  }
8747
8791
  };
8748
8792
  }
8749
- blockResolver = new BlockResolver({
8750
- local: installedPiece,
8751
- timeoutMs: PIECE_VERSION_LOOKUP_TIMEOUT_MS,
8752
- hasBlock: (ref, version, source) => this.versionHasBlock(ref, version, source)
8753
- });
8793
+ blockResolver;
8754
8794
  async versionHasBlock(ref, version, source) {
8755
8795
  let descriptor;
8756
8796
  try {
@@ -9117,13 +9157,17 @@ var WorkflowRuntimeService = class {
9117
9157
  * undefined means the workflow is not armed, answered exactly as an unknown token is. */
9118
9158
  async webhookPolicy(workflowId) {
9119
9159
  await this.seedPromise;
9160
+ const registration = this.liveWebhook(workflowId);
9161
+ if (registration) {
9162
+ if (registration.kind === "piece-webhook") return {};
9163
+ return this.policyOf(registration.config, workflowId);
9164
+ }
9120
9165
  const test = this.webhookTests.get(workflowId);
9121
- if (test) return this.policyOf(test.config, workflowId);
9166
+ return test ? this.policyOf(test.config, workflowId) : void 0;
9167
+ }
9168
+ liveWebhook(workflowId) {
9122
9169
  const registration = this.registry.get(workflowId);
9123
- if (!registration) return void 0;
9124
- if (registration.kind === "piece-webhook") return {};
9125
- if (registration.kind !== "webhook") return void 0;
9126
- return this.policyOf(registration.config, workflowId);
9170
+ return registration?.kind === "piece-webhook" || registration?.kind === "webhook" ? registration : void 0;
9127
9171
  }
9128
9172
  async policyOf(config, workflowId) {
9129
9173
  return {
@@ -9167,17 +9211,16 @@ var WorkflowRuntimeService = class {
9167
9211
  * answered any challenge for; all that is left is deciding what it means. */
9168
9212
  async deliverWebhook(request) {
9169
9213
  const workflowId = request.key;
9214
+ const registration = this.liveWebhook(workflowId);
9170
9215
  const test = this.webhookTests.get(workflowId);
9171
9216
  if (test) {
9172
9217
  this.webhookTests.delete(workflowId);
9173
9218
  clearTimeout(test.timer);
9174
9219
  test.resolve(webhookPayload(request));
9175
- return { status: test.config.responseStatus };
9220
+ if (!registration) return { status: test.config.responseStatus };
9176
9221
  }
9177
- const registration = this.registry.get(workflowId);
9178
9222
  if (!registration) return UNAUTHORIZED;
9179
9223
  if (registration.kind === "piece-webhook") return this.deliverToPiece(registration.binding, request);
9180
- if (registration.kind !== "webhook") return UNAUTHORIZED;
9181
9224
  const { config } = registration;
9182
9225
  const payload = webhookPayload(request);
9183
9226
  if (config.responseMode === "async") {
@@ -10195,7 +10238,7 @@ var WorkflowRuntimeService = class {
10195
10238
  };
10196
10239
  let input;
10197
10240
  try {
10198
- input = resolveExpressions(step.config, {
10241
+ input = resolveStepInput(definition.steps[0], {
10199
10242
  trigger: { payload: upstream.triggerPayload },
10200
10243
  steps: upstream.priorSteps,
10201
10244
  variables: Object.fromEntries(variables.map((v) => [v.key, v.value]))
@@ -10420,38 +10463,18 @@ const WORKFLOW_TRIGGERS_READ_MODEL = "workflow-triggers";
10420
10463
  const WORKFLOW_TRIGGERS_READ_MODEL_STAGE = "post_ready";
10421
10464
  var WorkflowTriggersReadModel = class extends BaseReadModel {
10422
10465
  runtime;
10423
- freshRegistration = false;
10424
10466
  constructor(db, operationIndex, writeCache, consistencyTracker, runtime) {
10425
10467
  super(db, operationIndex, writeCache, consistencyTracker, {
10426
10468
  readModelId: WORKFLOW_TRIGGERS_READ_MODEL,
10427
10469
  rebuildStateOnInit: false,
10428
- indexing: defaultReadModelIndexingConfig
10470
+ indexing: defaultReadModelIndexingConfig,
10471
+ startFrom: "head"
10429
10472
  });
10430
10473
  this.runtime = runtime;
10431
10474
  }
10432
- async init() {
10433
- if (await this.loadState() === void 0) {
10434
- this.freshRegistration = true;
10435
- return;
10436
- }
10437
- this.freshRegistration = false;
10438
- await super.init();
10439
- }
10440
- async indexOperations(items) {
10441
- if (items.length === 0) return;
10442
- await super.indexOperations(items);
10443
- this.freshRegistration = false;
10444
- }
10445
10475
  async commitOperations(items) {
10446
10476
  await this.runtime.onOperations(items);
10447
10477
  }
10448
- async saveState(trx, items) {
10449
- if (this.freshRegistration) await trx.insertInto("ViewState").values({
10450
- readModelId: this.config.readModelId,
10451
- lastOrdinal: 0
10452
- }).onConflict((oc) => oc.column("readModelId").doNothing()).execute();
10453
- await super.saveState(trx, items);
10454
- }
10455
10478
  };
10456
10479
  //#endregion
10457
10480
  export { CORE_PIECE_NAME, CORE_PIECE_VERSION, InvalidRunCursorError, PieceRegistry, WORKFLOW_PACKAGE_NAME, WORKFLOW_SYNCING_MESSAGE, WORKFLOW_TRIGGERS_READ_MODEL, WORKFLOW_TRIGGERS_READ_MODEL_STAGE, WorkflowRuntimeService, WorkflowSyncingError, WorkflowTriggersReadModel, createAttachmentPort, createWorkflowRuntime, packagePieces, setPieceRegistryUrl };