@powerhousedao/reactor-workflow 6.2.3-dev.33 → 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-Cy1a1UIa.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;
@@ -9118,13 +9157,17 @@ var WorkflowRuntimeService = class {
9118
9157
  * undefined means the workflow is not armed, answered exactly as an unknown token is. */
9119
9158
  async webhookPolicy(workflowId) {
9120
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
+ }
9121
9165
  const test = this.webhookTests.get(workflowId);
9122
- if (test) return this.policyOf(test.config, workflowId);
9166
+ return test ? this.policyOf(test.config, workflowId) : void 0;
9167
+ }
9168
+ liveWebhook(workflowId) {
9123
9169
  const registration = this.registry.get(workflowId);
9124
- if (!registration) return void 0;
9125
- if (registration.kind === "piece-webhook") return {};
9126
- if (registration.kind !== "webhook") return void 0;
9127
- return this.policyOf(registration.config, workflowId);
9170
+ return registration?.kind === "piece-webhook" || registration?.kind === "webhook" ? registration : void 0;
9128
9171
  }
9129
9172
  async policyOf(config, workflowId) {
9130
9173
  return {
@@ -9168,17 +9211,16 @@ var WorkflowRuntimeService = class {
9168
9211
  * answered any challenge for; all that is left is deciding what it means. */
9169
9212
  async deliverWebhook(request) {
9170
9213
  const workflowId = request.key;
9214
+ const registration = this.liveWebhook(workflowId);
9171
9215
  const test = this.webhookTests.get(workflowId);
9172
9216
  if (test) {
9173
9217
  this.webhookTests.delete(workflowId);
9174
9218
  clearTimeout(test.timer);
9175
9219
  test.resolve(webhookPayload(request));
9176
- return { status: test.config.responseStatus };
9220
+ if (!registration) return { status: test.config.responseStatus };
9177
9221
  }
9178
- const registration = this.registry.get(workflowId);
9179
9222
  if (!registration) return UNAUTHORIZED;
9180
9223
  if (registration.kind === "piece-webhook") return this.deliverToPiece(registration.binding, request);
9181
- if (registration.kind !== "webhook") return UNAUTHORIZED;
9182
9224
  const { config } = registration;
9183
9225
  const payload = webhookPayload(request);
9184
9226
  if (config.responseMode === "async") {
@@ -10196,7 +10238,7 @@ var WorkflowRuntimeService = class {
10196
10238
  };
10197
10239
  let input;
10198
10240
  try {
10199
- input = resolveExpressions(step.config, {
10241
+ input = resolveStepInput(definition.steps[0], {
10200
10242
  trigger: { payload: upstream.triggerPayload },
10201
10243
  steps: upstream.priorSteps,
10202
10244
  variables: Object.fromEntries(variables.map((v) => [v.key, v.value]))