@powerhousedao/reactor-workflow 6.2.3-dev.77 → 6.2.3-dev.78
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 +130 -9
- package/dist/index.js.map +1 -1
- package/dist/{telemetry-CohENxMR.js → telemetry-CiXdMoVa.js} +12 -3
- package/dist/{telemetry-CohENxMR.js.map → telemetry-CiXdMoVa.js.map} +1 -1
- package/dist/testing.js +1 -1
- package/dist/worker-entry.js +25 -1
- package/dist/worker-entry.js.map +1 -1
- package/package.json +7 -7
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-
|
|
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-CiXdMoVa.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";
|
|
@@ -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;
|
|
@@ -2104,6 +2153,58 @@ var RunScopedReactorClient = class {
|
|
|
2104
2153
|
throw error;
|
|
2105
2154
|
}
|
|
2106
2155
|
}
|
|
2156
|
+
drives = {
|
|
2157
|
+
getNode: (driveIdentifier, nodeId, signal) => this.getNode(driveIdentifier, nodeId, signal),
|
|
2158
|
+
listNodes: (driveIdentifier, parentFolder, paging, signal) => this.listNodes(driveIdentifier, parentFolder, paging, signal),
|
|
2159
|
+
addFile: (driveIdentifier, document, parentFolder, signal) => this.addFile(driveIdentifier, document, parentFolder, signal),
|
|
2160
|
+
addFolder: (driveIdentifier, name, parentFolder, signal) => this.addFolder(driveIdentifier, name, parentFolder, signal)
|
|
2161
|
+
};
|
|
2162
|
+
async getNode(driveIdentifier, nodeId, signal) {
|
|
2163
|
+
const abort = this.signal(signal);
|
|
2164
|
+
const drive = await this.readDrive(driveIdentifier, abort);
|
|
2165
|
+
return this.inner.drives.getNode(drive.id, nodeId, abort);
|
|
2166
|
+
}
|
|
2167
|
+
async listNodes(driveIdentifier, parentFolder, paging, signal) {
|
|
2168
|
+
const abort = this.signal(signal);
|
|
2169
|
+
const drive = await this.readDrive(driveIdentifier, abort);
|
|
2170
|
+
return this.inner.drives.listNodes(drive.id, parentFolder, this.paging(paging), abort);
|
|
2171
|
+
}
|
|
2172
|
+
async addFile(driveIdentifier, document, parentFolder, signal) {
|
|
2173
|
+
this.assertWritable("drives.addFile");
|
|
2174
|
+
const abort = this.signal(signal);
|
|
2175
|
+
const drive = await this.readDrive(driveIdentifier, abort);
|
|
2176
|
+
const prepared = withSignaturePolicy(document, await this.inner.getCreateSignaturePolicy());
|
|
2177
|
+
const documentId = prepared.header.id;
|
|
2178
|
+
await this.gateCandidates(drive.id, "main", [fileCandidate(drive, prepared, parentFolder)], abort);
|
|
2179
|
+
this.assertTimeLeft(`a ${prepared.header.documentType} document`);
|
|
2180
|
+
await this.scope.journal.recordDocuments([drive.id, documentId]);
|
|
2181
|
+
await this.inner.drives.addFile(drive.id, prepared, parentFolder, abort);
|
|
2182
|
+
try {
|
|
2183
|
+
await this.grantRunUser(documentId, abort);
|
|
2184
|
+
return await this.readBack(documentId, prepared.header.branch || "main", abort);
|
|
2185
|
+
} catch (error) {
|
|
2186
|
+
if (error instanceof Error) error.message = `Document ${documentId} was created, but: ${error.message}`;
|
|
2187
|
+
throw error;
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
async addFolder(driveIdentifier, name, parentFolder, signal) {
|
|
2191
|
+
this.assertWritable("drives.addFolder");
|
|
2192
|
+
const abort = this.signal(signal);
|
|
2193
|
+
const drive = await this.readDrive(driveIdentifier, abort);
|
|
2194
|
+
await this.gateCandidates(drive.id, "main", [folderCandidate(drive, name, parentFolder)], abort);
|
|
2195
|
+
this.assertTimeLeft("a folder");
|
|
2196
|
+
await this.scope.journal.recordDocuments([drive.id]);
|
|
2197
|
+
return this.inner.drives.addFolder(drive.id, name, parentFolder, abort);
|
|
2198
|
+
}
|
|
2199
|
+
async readDrive(driveIdentifier, signal) {
|
|
2200
|
+
const { id, documentType } = (await this.inner.get(driveIdentifier, this.readView({ scopes: ["document"] }), signal)).header;
|
|
2201
|
+
if (!isDriveType(documentType)) throw accessDenied(`Document ${id} is a ${documentType}, not a drive`);
|
|
2202
|
+
await this.scope.journal.recordDocuments([id]);
|
|
2203
|
+
return {
|
|
2204
|
+
id,
|
|
2205
|
+
documentType
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2107
2208
|
get subject() {
|
|
2108
2209
|
return this.scope.runUser?.subject;
|
|
2109
2210
|
}
|
|
@@ -2134,12 +2235,14 @@ var RunScopedReactorClient = class {
|
|
|
2134
2235
|
};
|
|
2135
2236
|
}
|
|
2136
2237
|
async gate(documentId, branch, actions, signal) {
|
|
2137
|
-
|
|
2138
|
-
const candidates = actions.map((action) => ({
|
|
2238
|
+
await this.gateCandidates(documentId, branch, actions.map((action) => ({
|
|
2139
2239
|
scope: action.scope,
|
|
2140
2240
|
type: action.type,
|
|
2141
2241
|
input: action.input
|
|
2142
|
-
}));
|
|
2242
|
+
})), signal);
|
|
2243
|
+
}
|
|
2244
|
+
async gateCandidates(documentId, branch, candidates, signal) {
|
|
2245
|
+
if (!authEnforced(this.host) || candidates.length === 0) return;
|
|
2143
2246
|
let answer;
|
|
2144
2247
|
try {
|
|
2145
2248
|
answer = await this.inner.evaluateActions(documentId, branch, candidates, this.subject, signal);
|
|
@@ -2286,6 +2389,20 @@ const SERVED = {
|
|
|
2286
2389
|
executeAsync: true,
|
|
2287
2390
|
deleteDocument: true
|
|
2288
2391
|
};
|
|
2392
|
+
const SERVED_DRIVES = {
|
|
2393
|
+
getNode: true,
|
|
2394
|
+
listNodes: true,
|
|
2395
|
+
addFile: true,
|
|
2396
|
+
addFolder: true
|
|
2397
|
+
};
|
|
2398
|
+
const REFUSED_DRIVES = {
|
|
2399
|
+
create: true,
|
|
2400
|
+
removeNode: true,
|
|
2401
|
+
renameNode: true,
|
|
2402
|
+
moveNode: true,
|
|
2403
|
+
copyNode: true,
|
|
2404
|
+
setPreferredEditorOnNode: true
|
|
2405
|
+
};
|
|
2289
2406
|
const REFUSED = {
|
|
2290
2407
|
getMany: true,
|
|
2291
2408
|
createDocumentInDrive: true,
|
|
@@ -2311,11 +2428,15 @@ const REFUSED = {
|
|
|
2311
2428
|
getCreateProtocolVersions: true
|
|
2312
2429
|
};
|
|
2313
2430
|
function servedClient(client) {
|
|
2431
|
+
const facade = served(client, SERVED, REFUSED, "");
|
|
2432
|
+
facade.drives = served(client.drives, SERVED_DRIVES, REFUSED_DRIVES, "drives.");
|
|
2433
|
+
return facade;
|
|
2434
|
+
}
|
|
2435
|
+
function served(methods, serve, refuse, prefix) {
|
|
2314
2436
|
const facade = Object.create(null);
|
|
2315
|
-
const
|
|
2316
|
-
for (const name of Object.keys(
|
|
2317
|
-
|
|
2318
|
-
throw refusedMethod(name);
|
|
2437
|
+
for (const name of Object.keys(serve)) facade[name] = (...args) => methods[name](...args);
|
|
2438
|
+
for (const name of Object.keys(refuse)) facade[name] = () => {
|
|
2439
|
+
throw refusedMethod(prefix + name);
|
|
2319
2440
|
};
|
|
2320
2441
|
return facade;
|
|
2321
2442
|
}
|
|
@@ -2344,7 +2465,7 @@ function reactorTap(host, base, journal, options = {}, telemetry) {
|
|
|
2344
2465
|
journal
|
|
2345
2466
|
}, host, clientOptions));
|
|
2346
2467
|
const parent = context.active();
|
|
2347
|
-
const server = new ReactorHostServer(telemetry ? tracedMethods(served, telemetry, "reactor", parent) : served, transport);
|
|
2468
|
+
const server = new ReactorHostServer(telemetry ? tracedMethods(served, telemetry, "reactor", parent, ["drives"]) : served, transport);
|
|
2348
2469
|
server.start();
|
|
2349
2470
|
return () => server.stop();
|
|
2350
2471
|
}
|