@powerhousedao/reactor-workflow 6.2.3-dev.77 → 6.2.3-dev.79

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,4 +1,4 @@
1
- import { $ as rememberSecrets, A as AttachmentCache, B as SecretNotFoundError, C as blockLabel, D as describeBuiltinPiece, E as builtinPiece, F as shapeConnection, G as PieceWorkerPool, H as secretRefFromId, I as resolveStepInput, J as PieceWorkerError, K as PieceWorker, L as expressionsIn, N as declaredConnectionIds, O as CORE_PIECE_NAME, P as declaredReactorConnectionIds, Q as redactMessage, S as storeHandlers, T as blockPorts, U as stepBlock, V as parseSecretRef, W as triggerBlock, X as containsRedactedMarker, Y as PieceWorkerTimeoutError, Z as redact, _ as effectiveRetryPolicy, _t as npmRegistryBaseUrl, a as PieceRegistry, at as FileTooLargeError, b as isHostBound, bt as isIndeterminateError, c as packagePieces, ct as pieceModuleRef, d as runWorkflow, dt as UnsupportedPieceFeatureError, et as secretsFor, f as canonicalJson, ft as authMethodFor, g as checkDynamicProperties, h as DynamicPropertiesError, i as tracedSteps, it as extractDedupeKey, j as BoundConnectionResolver, k as CORE_PIECE_VERSION, lt as sourcedResolver, m as stepConfigHash, mt as unsupportedTrigger, n as WorkflowTelemetry, nt as isPrivateAddress, o as installedPiece, ot as maxFileBytes, p as hashOf, pt as unsupportedAuth, q as PieceWorkerDisposedError, r as tracedMethods, rt as parseAddress, s as installedPieces, st as bundleResolver, t as TELEMETRY_SCOPE, tt as DEFAULT_EGRESS_POLICY, u as errorNameOf, v as ActivepiecesBlockExecutor, vt as pieceRegistrySource, w as unpinnedNote, x as resolvedBlock, y as CompositeBlockExecutor, yt as setPieceRegistryUrl, z as SecretDeletedError } from "./telemetry-CohENxMR.js";
1
+ import { $ as rememberSecrets, A as AttachmentCache, B as SecretNotFoundError, C as blockLabel, D as describeBuiltinPiece, E as builtinPiece, F as shapeConnection, G as PieceWorkerPool, H as secretRefFromId, I as resolveStepInput, J as PieceWorkerError, K as PieceWorker, L as expressionsIn, N as declaredConnectionIds, O as CORE_PIECE_NAME, P as declaredReactorConnectionIds, Q as redactMessage, S as storeHandlers, T as blockPorts, U as stepBlock, V as parseSecretRef, W as triggerBlock, X as containsRedactedMarker, Y as PieceWorkerTimeoutError, Z as redact, _ as effectiveRetryPolicy, _t as npmRegistryBaseUrl, a as PieceRegistry, at as FileTooLargeError, b as isHostBound, bt as isIndeterminateError, c as packagePieces, ct as pieceModuleRef, d as runWorkflow, dt as UnsupportedPieceFeatureError, et as secretsFor, f as canonicalJson, ft as authMethodFor, g as checkDynamicProperties, h as DynamicPropertiesError, i as tracedSteps, it as extractDedupeKey, j as BoundConnectionResolver, k as CORE_PIECE_VERSION, lt as sourcedResolver, m as stepConfigHash, mt as unsupportedTrigger, n as WorkflowTelemetry, nt as isPrivateAddress, o as installedPiece, ot as maxFileBytes, p as hashOf, pt as unsupportedAuth, q as PieceWorkerDisposedError, r as tracedMethods, rt as parseAddress, s as installedPieces, st as bundleResolver, t as TELEMETRY_SCOPE, tt as DEFAULT_EGRESS_POLICY, u as errorNameOf, v as ActivepiecesBlockExecutor, vt as pieceRegistrySource, w as unpinnedNote, x as resolvedBlock, y as CompositeBlockExecutor, yt as setPieceRegistryUrl, z as SecretDeletedError } from "./telemetry-CJd29LsN.js";
2
2
  import { ReactorAccessDeniedError, ReactorAccessDeniedError as ReactorAccessDeniedError$1, ReactorActionsFailedError, ReactorJobFailedError, ReactorJobPendingError as ReactorJobPendingError$1, WebhookHandshakeStrategy } from "@powerhousedao/pieces-framework";
3
3
  import { mkdirSync, openAsBlob, readFileSync, writeFileSync } from "node:fs";
4
4
  import { open, readdir, rm, stat } from "node:fs/promises";
@@ -19,7 +19,7 @@ import { actions as actions$1 } from "@powerhousedao/workflow/document-models/wo
19
19
  import { Kind, parse } from "graphql";
20
20
  import { ReactorHostServer } from "@powerhousedao/reactor/rpc";
21
21
  import { SpanStatusCode, context } from "@opentelemetry/api";
22
- import { BaseReadModel, JobStatus, PropagationMode, defaultReadModelIndexingConfig, deleteDocumentAction, isPurgeMarker } from "@powerhousedao/reactor";
22
+ import { BaseReadModel, JobStatus, PropagationMode, createEmptyDocument, defaultReadModelIndexingConfig, deleteDocumentAction, isPurgeMarker } from "@powerhousedao/reactor";
23
23
  import { DOCUMENT_SCOPE_ACTION_TYPES, initializeAuth, normalizeDocumentModelVersion, withSignaturePolicy } from "@powerhousedao/shared/document-model";
24
24
  import { performance as performance$1 } from "node:perf_hooks";
25
25
  //#region src/pieces/activepieces/piece-versions.ts
@@ -1988,6 +1988,55 @@ function assertActionsApplied(job, actions) {
1988
1988
  });
1989
1989
  if (failed.length > 0) throw new ReactorError(ReactorActionsFailedError, failed.join("; "));
1990
1990
  }
1991
+ const DOCUMENT_DRIVE = "powerhouse/document-drive";
1992
+ const REACTOR_DRIVE = "powerhouse/reactor-drive";
1993
+ function isDriveType(documentType) {
1994
+ return documentType === DOCUMENT_DRIVE || documentType === REACTOR_DRIVE;
1995
+ }
1996
+ function fileCandidate(drive, document, parentFolder) {
1997
+ const { id, documentType, name } = document.header;
1998
+ if (drive.documentType === DOCUMENT_DRIVE) return {
1999
+ scope: "global",
2000
+ type: "ADD_FILE",
2001
+ input: {
2002
+ id,
2003
+ name: name || id,
2004
+ documentType,
2005
+ parentFolder
2006
+ }
2007
+ };
2008
+ return {
2009
+ scope: "document",
2010
+ type: "ADD_RELATIONSHIP",
2011
+ input: {
2012
+ sourceId: drive.id,
2013
+ targetId: id,
2014
+ relationshipType: "drive/child",
2015
+ metadata: {
2016
+ kind: "file",
2017
+ parentFolderId: parentFolder ?? null,
2018
+ documentType
2019
+ }
2020
+ }
2021
+ };
2022
+ }
2023
+ function folderCandidate(drive, name, parentFolder) {
2024
+ return drive.documentType === DOCUMENT_DRIVE ? {
2025
+ scope: "global",
2026
+ type: "ADD_FOLDER",
2027
+ input: {
2028
+ name,
2029
+ parentFolder
2030
+ }
2031
+ } : {
2032
+ scope: "document",
2033
+ type: "ADD_FOLDER",
2034
+ input: {
2035
+ name,
2036
+ parentFolderId: parentFolder ?? null
2037
+ }
2038
+ };
2039
+ }
1991
2040
  var RunScopedReactorClient = class {
1992
2041
  inner;
1993
2042
  scope;
@@ -2051,17 +2100,22 @@ var RunScopedReactorClient = class {
2051
2100
  const parentId = parentIdentifier === void 0 ? void 0 : await this.resolveReference(parentIdentifier, "main", abort);
2052
2101
  return this.createDocument(document, parentId, abort);
2053
2102
  }
2103
+ async newDocument(documentModelType, options, signal) {
2104
+ this.assertWritable("newDocument");
2105
+ const abort = this.signal(signal);
2106
+ const module = await this.modelModule(documentModelType, options?.documentModelVersion, abort);
2107
+ const parentId = options?.parentIdentifier === void 0 ? void 0 : await this.resolveReference(options.parentIdentifier, "main", abort);
2108
+ const base = await this.inner.getCreateProtocolVersions({
2109
+ documentType: documentModelType,
2110
+ parentIdentifier: parentId
2111
+ }, abort);
2112
+ return createEmptyDocument(module, options, await this.inner.getCreateSignaturePolicy(), base);
2113
+ }
2054
2114
  async createEmpty(documentModelType, options, signal) {
2055
2115
  this.assertWritable("createEmpty");
2056
2116
  const abort = this.signal(signal);
2057
- const module = await this.modelModule(documentModelType, options?.documentModelVersion, abort);
2117
+ const document = await this.newDocument(documentModelType, options, abort);
2058
2118
  const parentId = options?.parentIdentifier === void 0 ? void 0 : await this.resolveReference(options.parentIdentifier, "main", abort);
2059
- const base = await this.inner.getCreateProtocolVersions(parentId, abort);
2060
- const document = withSignaturePolicy(module.utils.createDocument(), await this.inner.getCreateSignaturePolicy(), { protocolVersions: {
2061
- ...base,
2062
- ...options?.protocolVersions
2063
- } });
2064
- document.state.document.version = normalizeDocumentModelVersion(module.version);
2065
2119
  return this.createDocument(document, parentId, abort);
2066
2120
  }
2067
2121
  async execute(documentIdentifier, branch, actions, signal, subject) {
@@ -2104,6 +2158,58 @@ var RunScopedReactorClient = class {
2104
2158
  throw error;
2105
2159
  }
2106
2160
  }
2161
+ drives = {
2162
+ getNode: (driveIdentifier, nodeId, signal) => this.getNode(driveIdentifier, nodeId, signal),
2163
+ listNodes: (driveIdentifier, parentFolder, paging, signal) => this.listNodes(driveIdentifier, parentFolder, paging, signal),
2164
+ addFile: (driveIdentifier, document, parentFolder, signal) => this.addFile(driveIdentifier, document, parentFolder, signal),
2165
+ addFolder: (driveIdentifier, name, parentFolder, signal) => this.addFolder(driveIdentifier, name, parentFolder, signal)
2166
+ };
2167
+ async getNode(driveIdentifier, nodeId, signal) {
2168
+ const abort = this.signal(signal);
2169
+ const drive = await this.readDrive(driveIdentifier, abort);
2170
+ return this.inner.drives.getNode(drive.id, nodeId, abort);
2171
+ }
2172
+ async listNodes(driveIdentifier, parentFolder, paging, signal) {
2173
+ const abort = this.signal(signal);
2174
+ const drive = await this.readDrive(driveIdentifier, abort);
2175
+ return this.inner.drives.listNodes(drive.id, parentFolder, this.paging(paging), abort);
2176
+ }
2177
+ async addFile(driveIdentifier, document, parentFolder, signal) {
2178
+ this.assertWritable("drives.addFile");
2179
+ const abort = this.signal(signal);
2180
+ const drive = await this.readDrive(driveIdentifier, abort);
2181
+ const prepared = withSignaturePolicy(document, await this.inner.getCreateSignaturePolicy());
2182
+ const documentId = prepared.header.id;
2183
+ await this.gateCandidates(drive.id, "main", [fileCandidate(drive, prepared, parentFolder)], abort);
2184
+ this.assertTimeLeft(`a ${prepared.header.documentType} document`);
2185
+ await this.scope.journal.recordDocuments([drive.id, documentId]);
2186
+ await this.inner.drives.addFile(drive.id, prepared, parentFolder, abort);
2187
+ try {
2188
+ await this.grantRunUser(documentId, abort);
2189
+ return await this.readBack(documentId, prepared.header.branch || "main", abort);
2190
+ } catch (error) {
2191
+ if (error instanceof Error) error.message = `Document ${documentId} was created, but: ${error.message}`;
2192
+ throw error;
2193
+ }
2194
+ }
2195
+ async addFolder(driveIdentifier, name, parentFolder, signal) {
2196
+ this.assertWritable("drives.addFolder");
2197
+ const abort = this.signal(signal);
2198
+ const drive = await this.readDrive(driveIdentifier, abort);
2199
+ await this.gateCandidates(drive.id, "main", [folderCandidate(drive, name, parentFolder)], abort);
2200
+ this.assertTimeLeft("a folder");
2201
+ await this.scope.journal.recordDocuments([drive.id]);
2202
+ return this.inner.drives.addFolder(drive.id, name, parentFolder, abort);
2203
+ }
2204
+ async readDrive(driveIdentifier, signal) {
2205
+ const { id, documentType } = (await this.inner.get(driveIdentifier, this.readView({ scopes: ["document"] }), signal)).header;
2206
+ if (!isDriveType(documentType)) throw accessDenied(`Document ${id} is a ${documentType}, not a drive`);
2207
+ await this.scope.journal.recordDocuments([id]);
2208
+ return {
2209
+ id,
2210
+ documentType
2211
+ };
2212
+ }
2107
2213
  get subject() {
2108
2214
  return this.scope.runUser?.subject;
2109
2215
  }
@@ -2134,12 +2240,14 @@ var RunScopedReactorClient = class {
2134
2240
  };
2135
2241
  }
2136
2242
  async gate(documentId, branch, actions, signal) {
2137
- if (!authEnforced(this.host) || actions.length === 0) return;
2138
- const candidates = actions.map((action) => ({
2243
+ await this.gateCandidates(documentId, branch, actions.map((action) => ({
2139
2244
  scope: action.scope,
2140
2245
  type: action.type,
2141
2246
  input: action.input
2142
- }));
2247
+ })), signal);
2248
+ }
2249
+ async gateCandidates(documentId, branch, candidates, signal) {
2250
+ if (!authEnforced(this.host) || candidates.length === 0) return;
2143
2251
  let answer;
2144
2252
  try {
2145
2253
  answer = await this.inner.evaluateActions(documentId, branch, candidates, this.subject, signal);
@@ -2280,12 +2388,27 @@ const SERVED = {
2280
2388
  getIncomingRelationships: true,
2281
2389
  getOutgoingRelationshipEdges: true,
2282
2390
  getIncomingRelationshipEdges: true,
2391
+ newDocument: true,
2283
2392
  create: true,
2284
2393
  createEmpty: true,
2285
2394
  execute: true,
2286
2395
  executeAsync: true,
2287
2396
  deleteDocument: true
2288
2397
  };
2398
+ const SERVED_DRIVES = {
2399
+ getNode: true,
2400
+ listNodes: true,
2401
+ addFile: true,
2402
+ addFolder: true
2403
+ };
2404
+ const REFUSED_DRIVES = {
2405
+ create: true,
2406
+ removeNode: true,
2407
+ renameNode: true,
2408
+ moveNode: true,
2409
+ copyNode: true,
2410
+ setPreferredEditorOnNode: true
2411
+ };
2289
2412
  const REFUSED = {
2290
2413
  getMany: true,
2291
2414
  createDocumentInDrive: true,
@@ -2311,11 +2434,15 @@ const REFUSED = {
2311
2434
  getCreateProtocolVersions: true
2312
2435
  };
2313
2436
  function servedClient(client) {
2437
+ const facade = served(client, SERVED, REFUSED, "");
2438
+ facade.drives = served(client.drives, SERVED_DRIVES, REFUSED_DRIVES, "drives.");
2439
+ return facade;
2440
+ }
2441
+ function served(methods, serve, refuse, prefix) {
2314
2442
  const facade = Object.create(null);
2315
- const methods = client;
2316
- for (const name of Object.keys(SERVED)) facade[name] = (...args) => methods[name](...args);
2317
- for (const name of Object.keys(REFUSED)) facade[name] = () => {
2318
- throw refusedMethod(name);
2443
+ for (const name of Object.keys(serve)) facade[name] = (...args) => methods[name](...args);
2444
+ for (const name of Object.keys(refuse)) facade[name] = () => {
2445
+ throw refusedMethod(prefix + name);
2319
2446
  };
2320
2447
  return facade;
2321
2448
  }
@@ -2344,7 +2471,7 @@ function reactorTap(host, base, journal, options = {}, telemetry) {
2344
2471
  journal
2345
2472
  }, host, clientOptions));
2346
2473
  const parent = context.active();
2347
- const server = new ReactorHostServer(telemetry ? tracedMethods(served, telemetry, "reactor", parent) : served, transport);
2474
+ const server = new ReactorHostServer(telemetry ? tracedMethods(served, telemetry, "reactor", parent, ["drives"]) : served, transport);
2348
2475
  server.start();
2349
2476
  return () => server.stop();
2350
2477
  }