@powerhousedao/reactor-workflow 6.2.3-dev.82 → 6.2.3-dev.84
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/README.md +73 -1
- package/dist/index.d.ts +47 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -54
- package/dist/index.js.map +1 -1
- package/dist/{telemetry-B_CWKtzb.js → telemetry-CSemNycC.js} +54 -3
- package/dist/{telemetry-B_CWKtzb.js.map → telemetry-CSemNycC.js.map} +1 -1
- package/dist/testing.js +1 -1
- package/dist/worker-entry.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $ as redact, A as AttachmentCache, B as SecretDeletedError, C as blockLabel, D as describeBuiltinPiece, E as builtinPiece, F as shapeConnection, G as stepBlock, H as SecretOwnerMismatchError, I as resolveStepInput, J as PieceWorker, K as triggerBlock, L as expressionsIn, N as declaredConnectionIds, O as CORE_PIECE_NAME, P as declaredReactorConnectionIds, Q as containsRedactedMarker, S as storeHandlers, St as isIndeterminateError, T as blockPorts, U as parseSecretRef, V as SecretNotFoundError, W as secretRefFromId, X as PieceWorkerError, Y as PieceWorkerDisposedError, Z as PieceWorkerTimeoutError, _ as effectiveRetryPolicy, a as PieceRegistry, at as parseAddress, b as isHostBound, bt as pieceRegistrySource, c as packagePieces, ct as maxFileBytes, d as runWorkflow, dt as sourcedResolver, et as redactMessage, f as canonicalJson, g as checkDynamicProperties, gt as unsupportedTrigger, h as DynamicPropertiesError, ht as unsupportedAuth, i as tracedSteps, it as isPrivateAddress, j as BoundConnectionResolver, k as CORE_PIECE_VERSION, lt as bundleResolver, m as stepConfigHash, mt as authMethodFor, n as WorkflowTelemetry, nt as secretsFor, o as installedPiece, ot as extractDedupeKey, p as hashOf, pt as UnsupportedPieceFeatureError, q as PieceWorkerPool, r as tracedMethods, rt as DEFAULT_EGRESS_POLICY, s as installedPieces, st as FileTooLargeError, t as TELEMETRY_SCOPE, tt as rememberSecrets, u as errorNameOf, ut as pieceModuleRef, v as ActivepiecesBlockExecutor, w as unpinnedNote, x as resolvedBlock, xt as setPieceRegistryUrl, y as CompositeBlockExecutor, yt as npmRegistryBaseUrl, z as SecretCreatorMismatchError } from "./telemetry-
|
|
1
|
+
import { $ as redact, A as AttachmentCache, B as SecretDeletedError, C as blockLabel, D as describeBuiltinPiece, E as builtinPiece, F as shapeConnection, G as stepBlock, H as SecretOwnerMismatchError, I as resolveStepInput, J as PieceWorker, K as triggerBlock, L as expressionsIn, N as declaredConnectionIds, O as CORE_PIECE_NAME, P as declaredReactorConnectionIds, Q as containsRedactedMarker, S as storeHandlers, St as isIndeterminateError, T as blockPorts, U as parseSecretRef, V as SecretNotFoundError, W as secretRefFromId, X as PieceWorkerError, Y as PieceWorkerDisposedError, Z as PieceWorkerTimeoutError, _ as effectiveRetryPolicy, a as PieceRegistry, at as parseAddress, b as isHostBound, bt as pieceRegistrySource, c as packagePieces, ct as maxFileBytes, d as runWorkflow, dt as sourcedResolver, et as redactMessage, f as canonicalJson, g as checkDynamicProperties, gt as unsupportedTrigger, h as DynamicPropertiesError, ht as unsupportedAuth, i as tracedSteps, it as isPrivateAddress, j as BoundConnectionResolver, k as CORE_PIECE_VERSION, lt as bundleResolver, m as stepConfigHash, mt as authMethodFor, n as WorkflowTelemetry, nt as secretsFor, o as installedPiece, ot as extractDedupeKey, p as hashOf, pt as UnsupportedPieceFeatureError, q as PieceWorkerPool, r as tracedMethods, rt as DEFAULT_EGRESS_POLICY, s as installedPieces, st as FileTooLargeError, t as TELEMETRY_SCOPE, tt as rememberSecrets, u as errorNameOf, ut as pieceModuleRef, v as ActivepiecesBlockExecutor, w as unpinnedNote, x as resolvedBlock, xt as setPieceRegistryUrl, y as CompositeBlockExecutor, yt as npmRegistryBaseUrl, z as SecretCreatorMismatchError } from "./telemetry-CSemNycC.js";
|
|
2
2
|
import { DENIED_ACTION_INDEXES, ReactorAccessDeniedError, ReactorAccessDeniedError as ReactorAccessDeniedError$1, ReactorJobFailedError, ReactorJobPendingError as ReactorJobPendingError$1, WebhookHandshakeStrategy, assertActionsApplied } from "@powerhousedao/pieces-framework";
|
|
3
3
|
import { mkdirSync, openAsBlob, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { open, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { childLogger, generateId } from "document-model";
|
|
7
|
-
import { DEFAULT_TIMEZONE, DOCUMENT_REF_KEY, ScheduleConfigError, checkTriggerStrategy, containsDocumentRef, documentRefsIn, expandDocumentRefs, isDocumentRefMarker, parseScheduleConfig, referenceDocuments } from "@powerhousedao/pieces-framework/workflow";
|
|
7
|
+
import { DEFAULT_TIMEZONE, DOCUMENT_REF_KEY, ScheduleConfigError, checkTriggerStrategy, coerceManualPayload, containsDocumentRef, documentRefsIn, expandDocumentRefs, isDocumentRefMarker, manualInputTypeName, parseManualInputs, parseScheduleConfig, referenceDocuments } from "@powerhousedao/pieces-framework/workflow";
|
|
8
8
|
import { Cron } from "croner";
|
|
9
9
|
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
10
10
|
import dns from "node:dns";
|
|
@@ -205,10 +205,11 @@ var OAuthError = class extends Error {
|
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
207
|
async function up$2(db) {
|
|
208
|
-
await db.schema.createTable("oauth_attempt").addColumn("state", "text", (col) => col.primaryKey()).addColumn("connection_id", "text", (col) => col.notNull()).addColumn("client_id", "text", (col) => col.notNull()).addColumn("client_secret_ref", "text"
|
|
208
|
+
await db.schema.createTable("oauth_attempt").addColumn("state", "text", (col) => col.primaryKey()).addColumn("connection_id", "text", (col) => col.notNull()).addColumn("client_id", "text", (col) => col.notNull()).addColumn("client_secret_ref", "text").addColumn("code_verifier", "text").addColumn("redirect_uri", "text", (col) => col.notNull()).addColumn("token_url", "text", (col) => col.notNull()).addColumn("authorization_method", "text").addColumn("return_url", "text").addColumn("created_by", "text").addColumn("status", "text", (col) => col.notNull()).addColumn("error", "text").addColumn("created_at", "text", (col) => col.notNull()).addColumn("expires_at", "text", (col) => col.notNull()).ifNotExists().execute();
|
|
209
209
|
try {
|
|
210
210
|
await db.schema.alterTable("oauth_attempt").addColumn("created_by", "text").execute();
|
|
211
211
|
} catch {}
|
|
212
|
+
await db.schema.alterTable("oauth_attempt").alterColumn("client_secret_ref", (col) => col.dropNotNull()).execute();
|
|
212
213
|
}
|
|
213
214
|
function fillOAuthUrl(template, props) {
|
|
214
215
|
const filled = template.replace(/\{(\w+)\}/g, (_match, name) => {
|
|
@@ -241,7 +242,8 @@ var OAuthAttemptStore = class OAuthAttemptStore {
|
|
|
241
242
|
const now = /* @__PURE__ */ new Date();
|
|
242
243
|
await this.db.deleteFrom("oauth_attempt").where("expires_at", "<", (/* @__PURE__ */ new Date(now.getTime() - 864e5)).toISOString()).execute();
|
|
243
244
|
const { method } = input;
|
|
244
|
-
const
|
|
245
|
+
const nonce = base64url(randomBytes(32));
|
|
246
|
+
const state = input.stateSuffix ? `${nonce}.${input.stateSuffix}` : nonce;
|
|
245
247
|
const verifier = method.pkce === true || input.pkce === true ? base64url(randomBytes(48)) : null;
|
|
246
248
|
const authUrl = new URL(fillOAuthUrl(method.authUrl, input.props));
|
|
247
249
|
const params = authUrl.searchParams;
|
|
@@ -268,7 +270,7 @@ var OAuthAttemptStore = class OAuthAttemptStore {
|
|
|
268
270
|
client_secret_ref: input.clientSecretRef,
|
|
269
271
|
code_verifier: verifier,
|
|
270
272
|
redirect_uri: input.redirectUri,
|
|
271
|
-
token_url: fillOAuthUrl(method.tokenUrl, input.props),
|
|
273
|
+
token_url: input.tokenUrl ?? fillOAuthUrl(method.tokenUrl, input.props),
|
|
272
274
|
authorization_method: method.authorizationMethod ?? null,
|
|
273
275
|
return_url: input.returnUrl ?? null,
|
|
274
276
|
created_by: input.createdBy?.toLowerCase() ?? null,
|
|
@@ -395,6 +397,10 @@ async function postTokenForm(url, form, headers, egress) {
|
|
|
395
397
|
return parsed;
|
|
396
398
|
}
|
|
397
399
|
function clientAuth$1(method, clientId, clientSecret) {
|
|
400
|
+
if (clientSecret === null) return {
|
|
401
|
+
form: { client_id: clientId },
|
|
402
|
+
headers: {}
|
|
403
|
+
};
|
|
398
404
|
if (method === "HEADER") return {
|
|
399
405
|
form: {},
|
|
400
406
|
headers: { authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}` }
|
|
@@ -426,6 +432,7 @@ function tokenSetFrom(response, context, previous) {
|
|
|
426
432
|
redirect_url: context.redirect_url,
|
|
427
433
|
...context.client_id ?? previous?.client_id ? { client_id: context.client_id ?? previous?.client_id } : {},
|
|
428
434
|
...context.client_secret_ref ?? previous?.client_secret_ref ? { client_secret_ref: context.client_secret_ref ?? previous?.client_secret_ref } : {},
|
|
435
|
+
...context.relayed ?? previous?.relayed ? { relayed: true } : {},
|
|
429
436
|
data: {
|
|
430
437
|
...previous?.data,
|
|
431
438
|
...response
|
|
@@ -447,8 +454,9 @@ async function exchangeCode(attempt, code, clientSecret, egress, fromRegistry =
|
|
|
447
454
|
redirect_url: attempt.redirect_uri,
|
|
448
455
|
...fromRegistry ? {
|
|
449
456
|
client_id: attempt.client_id,
|
|
450
|
-
client_secret_ref: attempt.client_secret_ref
|
|
451
|
-
} : {}
|
|
457
|
+
...attempt.client_secret_ref ? { client_secret_ref: attempt.client_secret_ref } : {}
|
|
458
|
+
} : {},
|
|
459
|
+
...clientSecret === null ? { relayed: true } : {}
|
|
452
460
|
});
|
|
453
461
|
}
|
|
454
462
|
function parseTokenSet(value) {
|
|
@@ -499,10 +507,16 @@ var StoreTokenRefresher = class {
|
|
|
499
507
|
const read = (ref) => store.get(ref, owner);
|
|
500
508
|
const tokens = parseTokenSet(await read(tokenRef));
|
|
501
509
|
if (!tokenDue(tokens, Math.round(Date.now() / 1e3))) return;
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
510
|
+
let auth;
|
|
511
|
+
if (tokens.relayed) {
|
|
512
|
+
if (!tokens.client_id) return;
|
|
513
|
+
auth = clientAuth$1(void 0, tokens.client_id, null);
|
|
514
|
+
} else {
|
|
515
|
+
const clientId = own?.clientId ?? tokens.client_id;
|
|
516
|
+
const secretRef = own?.secretRef ?? tokens.client_secret_ref;
|
|
517
|
+
if (!clientId || !secretRef) return;
|
|
518
|
+
auth = clientAuth$1(tokens.authorization_method, clientId, own ? await read(secretRef) : await store.get(secretRef, null));
|
|
519
|
+
}
|
|
506
520
|
let response;
|
|
507
521
|
try {
|
|
508
522
|
response = await postTokenForm(tokens.token_url, {
|
|
@@ -779,6 +793,9 @@ function webhookTriggerTree() {
|
|
|
779
793
|
leaf("body", "Unknown", "Parsed JSON or form fields; text otherwise")
|
|
780
794
|
];
|
|
781
795
|
}
|
|
796
|
+
function manualTriggerTree(inputs) {
|
|
797
|
+
return inputs.map((input) => leaf(input.name, manualInputTypeName(input), input.description));
|
|
798
|
+
}
|
|
782
799
|
function documentEventTree(actionInputChildren) {
|
|
783
800
|
return [
|
|
784
801
|
leaf("documentId", "PHID!"),
|
|
@@ -10288,10 +10305,41 @@ const OAUTH_APP = "oauth_app";
|
|
|
10288
10305
|
* for `calendar.readonly` where the piece would ask to edit too.
|
|
10289
10306
|
*/
|
|
10290
10307
|
const OAUTH_SCOPES = "oauth_scopes";
|
|
10308
|
+
function httpsUrl(raw) {
|
|
10309
|
+
if (typeof raw !== "string" || raw === "") return void 0;
|
|
10310
|
+
let url;
|
|
10311
|
+
try {
|
|
10312
|
+
url = new URL(raw);
|
|
10313
|
+
} catch {
|
|
10314
|
+
return;
|
|
10315
|
+
}
|
|
10316
|
+
if (url.protocol !== "https:" || url.username || url.password) return;
|
|
10317
|
+
return url.href;
|
|
10318
|
+
}
|
|
10319
|
+
/**
|
|
10320
|
+
* A relay as configured, or the reason it cannot be used: it needs a client
|
|
10321
|
+
* id and two absolute https URLs without credentials.
|
|
10322
|
+
*/
|
|
10323
|
+
function parseRelay(raw) {
|
|
10324
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return "not an object with clientId, redirectUri and tokenUrl";
|
|
10325
|
+
const { clientId, redirectUri, tokenUrl } = raw;
|
|
10326
|
+
if (typeof clientId !== "string" || clientId === "") return "no clientId";
|
|
10327
|
+
const redirect = httpsUrl(redirectUri);
|
|
10328
|
+
if (!redirect) return "redirectUri is not an absolute https URL";
|
|
10329
|
+
const token = httpsUrl(tokenUrl);
|
|
10330
|
+
if (!token) return "tokenUrl is not an absolute https URL";
|
|
10331
|
+
return {
|
|
10332
|
+
clientId,
|
|
10333
|
+
redirectUri: redirect,
|
|
10334
|
+
tokenUrl: token
|
|
10335
|
+
};
|
|
10336
|
+
}
|
|
10291
10337
|
var StaticOAuthAppRegistry = class {
|
|
10292
10338
|
entries;
|
|
10293
|
-
|
|
10339
|
+
relays;
|
|
10340
|
+
constructor(entries, relays = /* @__PURE__ */ new Map()) {
|
|
10294
10341
|
this.entries = entries;
|
|
10342
|
+
this.relays = relays;
|
|
10295
10343
|
}
|
|
10296
10344
|
client(appId, kind) {
|
|
10297
10345
|
return this.entries.find((e) => e.appId === appId && e.kind === kind);
|
|
@@ -10299,6 +10347,9 @@ var StaticOAuthAppRegistry = class {
|
|
|
10299
10347
|
clients(appId) {
|
|
10300
10348
|
return this.entries.filter((e) => e.appId === appId);
|
|
10301
10349
|
}
|
|
10350
|
+
relay(appId) {
|
|
10351
|
+
return this.relays.get(appId);
|
|
10352
|
+
}
|
|
10302
10353
|
};
|
|
10303
10354
|
const LOOPBACK = /* @__PURE__ */ new Set([
|
|
10304
10355
|
"localhost",
|
|
@@ -10316,6 +10367,22 @@ function clientKindFor(redirectUri) {
|
|
|
10316
10367
|
}
|
|
10317
10368
|
return LOOPBACK.has(host) ? "desktop" : "web";
|
|
10318
10369
|
}
|
|
10370
|
+
function oauthSignInFor(apps, appId, redirectUri) {
|
|
10371
|
+
const kind = clientKindFor(redirectUri);
|
|
10372
|
+
const client = apps.client(appId, kind);
|
|
10373
|
+
if (client) return {
|
|
10374
|
+
mode: kind,
|
|
10375
|
+
client
|
|
10376
|
+
};
|
|
10377
|
+
const relay = kind === "web" ? apps.relay(appId) : void 0;
|
|
10378
|
+
return relay ? {
|
|
10379
|
+
mode: "relay",
|
|
10380
|
+
relay
|
|
10381
|
+
} : {
|
|
10382
|
+
mode: "none",
|
|
10383
|
+
kind
|
|
10384
|
+
};
|
|
10385
|
+
}
|
|
10319
10386
|
/**
|
|
10320
10387
|
* Config key the runtime writes after a sign-in: the scopes the provider
|
|
10321
10388
|
* granted (its token response's `scope`, else the ones asked for). A
|
|
@@ -10364,39 +10431,49 @@ function clientSecretLabel(appId, kind) {
|
|
|
10364
10431
|
* Reads each configured client file and keeps its secret in the store under a
|
|
10365
10432
|
* fixed label: created the first time, rotated when the file changed, left
|
|
10366
10433
|
* alone otherwise. A client whose file cannot be read is skipped with the
|
|
10367
|
-
* reason, so one bad file does not take the others down.
|
|
10434
|
+
* reason, so one bad file does not take the others down. A relay without a
|
|
10435
|
+
* client id or with a URL that is not absolute https is dropped with the
|
|
10436
|
+
* reason.
|
|
10368
10437
|
*/
|
|
10369
10438
|
async function loadOAuthApps(definitions, store, options = {}) {
|
|
10370
10439
|
const read = options.read ?? ((path) => readFile(path, "utf8"));
|
|
10371
10440
|
const existing = new Map((await store.list()).filter((s) => s.status === "ACTIVE" && s.label && s.ownerId === null).map((s) => [s.label, s.ref]));
|
|
10372
10441
|
const entries = [];
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
if (
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
}
|
|
10380
|
-
|
|
10381
|
-
|
|
10442
|
+
const relays = /* @__PURE__ */ new Map();
|
|
10443
|
+
for (const app of definitions) {
|
|
10444
|
+
if (app.relay !== void 0) {
|
|
10445
|
+
const relay = parseRelay(app.relay);
|
|
10446
|
+
if (typeof relay === "string") options.onRelayDropped?.(app.id, relay);
|
|
10447
|
+
else relays.set(app.id, relay);
|
|
10448
|
+
}
|
|
10449
|
+
for (const kind of ["desktop", "web"]) {
|
|
10450
|
+
const path = app.clients[kind];
|
|
10451
|
+
if (!path) continue;
|
|
10452
|
+
let client;
|
|
10453
|
+
try {
|
|
10454
|
+
client = parseClientFile(await read(path));
|
|
10455
|
+
} catch (error) {
|
|
10456
|
+
options.onSkip?.(app.id, kind, `${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
10457
|
+
continue;
|
|
10458
|
+
}
|
|
10459
|
+
const label = clientSecretLabel(app.id, kind);
|
|
10460
|
+
let ref = existing.get(label);
|
|
10461
|
+
if (ref) {
|
|
10462
|
+
if (await store.get(ref, null) !== client.clientSecret) await store.rotate(ref, client.clientSecret);
|
|
10463
|
+
} else ref = (await store.create({
|
|
10464
|
+
value: client.clientSecret,
|
|
10465
|
+
label,
|
|
10466
|
+
ownerId: null
|
|
10467
|
+
})).ref;
|
|
10468
|
+
entries.push({
|
|
10469
|
+
appId: app.id,
|
|
10470
|
+
kind,
|
|
10471
|
+
clientId: client.clientId,
|
|
10472
|
+
clientSecretRef: ref
|
|
10473
|
+
});
|
|
10382
10474
|
}
|
|
10383
|
-
const label = clientSecretLabel(app.id, kind);
|
|
10384
|
-
let ref = existing.get(label);
|
|
10385
|
-
if (ref) {
|
|
10386
|
-
if (await store.get(ref, null) !== client.clientSecret) await store.rotate(ref, client.clientSecret);
|
|
10387
|
-
} else ref = (await store.create({
|
|
10388
|
-
value: client.clientSecret,
|
|
10389
|
-
label,
|
|
10390
|
-
ownerId: null
|
|
10391
|
-
})).ref;
|
|
10392
|
-
entries.push({
|
|
10393
|
-
appId: app.id,
|
|
10394
|
-
kind,
|
|
10395
|
-
clientId: client.clientId,
|
|
10396
|
-
clientSecretRef: ref
|
|
10397
|
-
});
|
|
10398
10475
|
}
|
|
10399
|
-
return new StaticOAuthAppRegistry(entries);
|
|
10476
|
+
return new StaticOAuthAppRegistry(entries, relays);
|
|
10400
10477
|
}
|
|
10401
10478
|
//#endregion
|
|
10402
10479
|
//#region src/reactor/service.ts
|
|
@@ -10769,7 +10846,10 @@ var WorkflowRuntimeService = class {
|
|
|
10769
10846
|
}
|
|
10770
10847
|
/** The host's OAuth2 apps, their client secrets loaded into the store once. */
|
|
10771
10848
|
oauthApps() {
|
|
10772
|
-
this.oauthAppsPromise ??= this.secrets().then((store) => loadOAuthApps(this.host.oauthApps ?? [], store, {
|
|
10849
|
+
this.oauthAppsPromise ??= this.secrets().then((store) => loadOAuthApps(this.host.oauthApps ?? [], store, {
|
|
10850
|
+
onSkip: (appId, kind, reason) => logger$1.warn(`OAuth2 app "${appId}" has no usable ${kind} client: ${reason}`),
|
|
10851
|
+
onRelayDropped: (appId, reason) => logger$1.warn(`OAuth2 app "${appId}" relay ignored: ${reason}`)
|
|
10852
|
+
}));
|
|
10773
10853
|
return this.oauthAppsPromise;
|
|
10774
10854
|
}
|
|
10775
10855
|
oauthRefresher() {
|
|
@@ -12163,6 +12243,9 @@ var WorkflowRuntimeService = class {
|
|
|
12163
12243
|
accountLabel: outcome.accountLabel ?? idTokenEmail(shapedAuth) ?? accountLabel
|
|
12164
12244
|
});
|
|
12165
12245
|
}
|
|
12246
|
+
async oauthSignInMode(appId, redirectUri) {
|
|
12247
|
+
return oauthSignInFor(await this.oauthApps(), appId, redirectUri).mode;
|
|
12248
|
+
}
|
|
12166
12249
|
async startOAuth(connectionId, ctx, options) {
|
|
12167
12250
|
await this.assertCanReadDocument(connectionId, ctx);
|
|
12168
12251
|
await this.assertCanWriteDocument(connectionId, ctx);
|
|
@@ -12173,13 +12256,25 @@ var WorkflowRuntimeService = class {
|
|
|
12173
12256
|
let clientId;
|
|
12174
12257
|
let clientSecretRef;
|
|
12175
12258
|
let pkce = false;
|
|
12259
|
+
let redirectUri = options.redirectUri;
|
|
12260
|
+
let tokenUrl;
|
|
12261
|
+
let stateSuffix;
|
|
12176
12262
|
if (typeof appId === "string" && appId !== "") {
|
|
12177
|
-
const
|
|
12178
|
-
|
|
12179
|
-
if (
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12263
|
+
const signIn = oauthSignInFor(await this.oauthApps(), appId, options.redirectUri);
|
|
12264
|
+
if (signIn.mode === "none") throw new OAuthError(`The app "${appId}" has no ${signIn.kind} client on this host; configure it in workflows.oauthApps`);
|
|
12265
|
+
if (signIn.mode === "relay") {
|
|
12266
|
+
const { relay } = signIn;
|
|
12267
|
+
clientId = relay.clientId;
|
|
12268
|
+
clientSecretRef = null;
|
|
12269
|
+
redirectUri = relay.redirectUri;
|
|
12270
|
+
tokenUrl = relay.tokenUrl;
|
|
12271
|
+
stateSuffix = Buffer.from(options.redirectUri, "utf8").toString("base64url");
|
|
12272
|
+
pkce = true;
|
|
12273
|
+
} else {
|
|
12274
|
+
clientId = signIn.client.clientId;
|
|
12275
|
+
clientSecretRef = signIn.client.clientSecretRef;
|
|
12276
|
+
pkce = signIn.mode === "desktop";
|
|
12277
|
+
}
|
|
12183
12278
|
} else {
|
|
12184
12279
|
if (typeof ownClientId !== "string" || ownClientId === "") throw new OAuthError("Set the client ID before connecting");
|
|
12185
12280
|
const ref = state.secretRefs.find((entry) => entry.name === OAUTH_CLIENT_SECRET)?.ref;
|
|
@@ -12204,10 +12299,12 @@ var WorkflowRuntimeService = class {
|
|
|
12204
12299
|
props,
|
|
12205
12300
|
clientId,
|
|
12206
12301
|
clientSecretRef,
|
|
12207
|
-
redirectUri
|
|
12302
|
+
redirectUri,
|
|
12303
|
+
...tokenUrl ? { tokenUrl } : {},
|
|
12208
12304
|
...options.returnUrl ? { returnUrl: options.returnUrl } : {},
|
|
12209
12305
|
...scopes ? { scopes } : {},
|
|
12210
12306
|
...pkce ? { pkce } : {},
|
|
12307
|
+
...stateSuffix ? { stateSuffix } : {},
|
|
12211
12308
|
createdBy: this.callerAddress(ctx)
|
|
12212
12309
|
});
|
|
12213
12310
|
}
|
|
@@ -12239,11 +12336,16 @@ var WorkflowRuntimeService = class {
|
|
|
12239
12336
|
const state = document.state.global;
|
|
12240
12337
|
const config = state.config ?? {};
|
|
12241
12338
|
const appId = config[OAUTH_APP];
|
|
12242
|
-
const
|
|
12243
|
-
|
|
12339
|
+
const relayed = attempt.client_secret_ref === null;
|
|
12340
|
+
let fromRegistry = false;
|
|
12341
|
+
if (typeof appId === "string" && appId !== "") {
|
|
12342
|
+
const apps = await this.oauthApps();
|
|
12343
|
+
fromRegistry = relayed ? apps.relay(appId)?.clientId === attempt.client_id : apps.clients(appId).some((c) => c.clientId === attempt.client_id);
|
|
12344
|
+
}
|
|
12345
|
+
if (state.authType !== "OAUTH2" || !fromRegistry && (relayed || config["client_id"] !== attempt.client_id)) return await fail("The connection changed during sign-in; try again");
|
|
12244
12346
|
const secrets = await this.secrets();
|
|
12245
12347
|
const connectionId = document.header.id;
|
|
12246
|
-
const tokens = await exchangeCode(attempt, callback.code, await secrets.get(attempt.client_secret_ref, fromRegistry ? null : {
|
|
12348
|
+
const tokens = await exchangeCode(attempt, callback.code, attempt.client_secret_ref === null ? null : await secrets.get(attempt.client_secret_ref, fromRegistry ? null : {
|
|
12247
12349
|
documentId: connectionId,
|
|
12248
12350
|
kind: "connection"
|
|
12249
12351
|
}), this.designEgress, fromRegistry);
|
|
@@ -12479,10 +12581,13 @@ var WorkflowRuntimeService = class {
|
|
|
12479
12581
|
async blockOutputTree(block, config) {
|
|
12480
12582
|
const record = config ?? {};
|
|
12481
12583
|
switch (blockKey(block)) {
|
|
12482
|
-
case MANUAL_BLOCK:
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12584
|
+
case MANUAL_BLOCK: {
|
|
12585
|
+
const nodes = manualTriggerTree(parseManualInputs(record));
|
|
12586
|
+
return {
|
|
12587
|
+
source: nodes.length > 0 ? "static" : "none",
|
|
12588
|
+
nodes
|
|
12589
|
+
};
|
|
12590
|
+
}
|
|
12486
12591
|
case SCHEDULE_BLOCK: return {
|
|
12487
12592
|
source: "static",
|
|
12488
12593
|
nodes: scheduleTriggerTree()
|
|
@@ -12866,6 +12971,16 @@ var WorkflowRuntimeService = class {
|
|
|
12866
12971
|
run.refused = true;
|
|
12867
12972
|
throw new Error(`Workflow is ${state.status}; only ENABLED workflows can fire`);
|
|
12868
12973
|
}
|
|
12974
|
+
if (triggerKind === "manual" && !resume && !enqueuedRunId) {
|
|
12975
|
+
const fired = runnableDefinition(state).trigger;
|
|
12976
|
+
const inputs = fired && blockKey(triggerBlock(fired)) === MANUAL_BLOCK ? parseManualInputs(configRecord(fired.config)) : [];
|
|
12977
|
+
if (inputs.length > 0) try {
|
|
12978
|
+
triggerPayload = coerceManualPayload(inputs, triggerPayload);
|
|
12979
|
+
} catch (error) {
|
|
12980
|
+
run.refused = true;
|
|
12981
|
+
throw error;
|
|
12982
|
+
}
|
|
12983
|
+
}
|
|
12869
12984
|
definition = toWorkflowDefinition(state);
|
|
12870
12985
|
const reactorConnections = declaredReactorConnectionIds(definition);
|
|
12871
12986
|
runUser = reactorConnections.size === 0 ? void 0 : await this.telemetry.phase("run_user", {}, () => assertReactorConnectionsReadable(this.host, workflowId, reactorConnections)).catch((error) => {
|
|
@@ -13859,6 +13974,6 @@ var WorkflowTriggersReadModel = class extends BaseReadModel {
|
|
|
13859
13974
|
}
|
|
13860
13975
|
};
|
|
13861
13976
|
//#endregion
|
|
13862
|
-
export { CORE_PIECE_NAME, CORE_PIECE_VERSION, InvalidRunCursorError, OAUTH_APP, OAUTH_GRANTED_SCOPES, OAUTH_SCOPES, PieceRegistry, SINGLETON_HEARTBEAT_MS, SINGLETON_LEASE_TTL_MS, SINGLETON_STALE_HEARTBEATS, StaticOAuthAppRegistry, TELEMETRY_SCOPE, WORKFLOW_PACKAGE_NAME, WORKFLOW_SINGLETON_OWNER_ENV, WORKFLOW_SYNCING_MESSAGE, WORKFLOW_TRIGGERS_READ_MODEL, WORKFLOW_TRIGGERS_READ_MODEL_STAGE, WorkflowRuntimeService, WorkflowSingletonConflictError, WorkflowSyncingError, WorkflowTriggersReadModel, acquireWorkflowSingletonLease, clientKindFor, createAttachmentPort, createWorkflowRuntime, grantedScopes, loadOAuthApps, packagePieces, parseClientFile, publishRunUser, scopesOverride, setPieceRegistryUrl, singletonOwnerName };
|
|
13977
|
+
export { CORE_PIECE_NAME, CORE_PIECE_VERSION, InvalidRunCursorError, OAUTH_APP, OAUTH_GRANTED_SCOPES, OAUTH_SCOPES, PieceRegistry, SINGLETON_HEARTBEAT_MS, SINGLETON_LEASE_TTL_MS, SINGLETON_STALE_HEARTBEATS, StaticOAuthAppRegistry, TELEMETRY_SCOPE, WORKFLOW_PACKAGE_NAME, WORKFLOW_SINGLETON_OWNER_ENV, WORKFLOW_SYNCING_MESSAGE, WORKFLOW_TRIGGERS_READ_MODEL, WORKFLOW_TRIGGERS_READ_MODEL_STAGE, WorkflowRuntimeService, WorkflowSingletonConflictError, WorkflowSyncingError, WorkflowTriggersReadModel, acquireWorkflowSingletonLease, clientKindFor, createAttachmentPort, createWorkflowRuntime, grantedScopes, loadOAuthApps, oauthSignInFor, packagePieces, parseClientFile, parseRelay, publishRunUser, scopesOverride, setPieceRegistryUrl, singletonOwnerName };
|
|
13863
13978
|
|
|
13864
13979
|
//# sourceMappingURL=index.js.map
|