@flowrunner/cli 0.1.1 → 0.1.2
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/ai-docs/instructions/service-code-format/09-realtime-triggers.md +51 -8
- package/ai-docs/instructions/service-code-format/13-runtime-contracts.md +18 -5
- package/dist/cli.js +423 -235
- package/dist/cli.js.map +4 -4
- package/dist/index.js +420 -232
- package/dist/index.js.map +4 -4
- package/dist/types/flow-extension-runner/src/v2/realtime-triggers/system-params.d.ts +2 -0
- package/dist/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +6 -2
- package/dist/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +6 -1
- package/dist/types/flow-extension-runner/src/v2/realtime-triggers/verify.d.ts +1 -1
- package/dist/types/packages/cli/src/constants/testing.d.ts +9 -4
- package/dist/types/shared/src/constants/knowledge-base.d.ts +1 -0
- package/dist/types/shared/src/scheme/billing/java.dto.d.ts +19 -1
- package/dist/types/shared/src/scheme/crm/dto.d.ts +2 -2
- package/dist/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -1
- package/dist/types/shared/src/scheme/knowledge-base/dto.d.ts +156 -0
- package/dist/types/shared/src/scheme/workspace/dto.d.ts +1 -1
- package/package.json +3 -3
- package/runtime/index.js +39 -24
- package/runtime/index.js.map +2 -2
- package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/system-params.d.ts +2 -0
- package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +6 -2
- package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +6 -1
- package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/verify.d.ts +1 -1
- package/runtime/types/shared/src/constants/knowledge-base.d.ts +1 -0
- package/runtime/types/shared/src/scheme/billing/java.dto.d.ts +19 -1
- package/runtime/types/shared/src/scheme/crm/dto.d.ts +2 -2
- package/runtime/types/shared/src/scheme/flowrunner/java.dto.d.ts +1 -1
- package/runtime/types/shared/src/scheme/knowledge-base/dto.d.ts +156 -0
- package/runtime/types/shared/src/scheme/workspace/dto.d.ts +1 -1
package/runtime/index.js
CHANGED
|
@@ -6,7 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw mod = 0, e;
|
|
13
|
+
}
|
|
10
14
|
};
|
|
11
15
|
var __export = (target, all) => {
|
|
12
16
|
for (var name in all)
|
|
@@ -355,7 +359,7 @@ var require_error = __commonJS({
|
|
|
355
359
|
};
|
|
356
360
|
return _getPrototypeOf(o);
|
|
357
361
|
}
|
|
358
|
-
var ResponseError = exports2.ResponseError = /* @__PURE__ */ function(_Error) {
|
|
362
|
+
var ResponseError = exports2.ResponseError = /* @__PURE__ */ (function(_Error) {
|
|
359
363
|
_inherits(ResponseError2, _Error);
|
|
360
364
|
var _super = _createSuper(ResponseError2);
|
|
361
365
|
function ResponseError2(response) {
|
|
@@ -371,14 +375,14 @@ var require_error = __commonJS({
|
|
|
371
375
|
return _this;
|
|
372
376
|
}
|
|
373
377
|
return _createClass(ResponseError2);
|
|
374
|
-
}(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
378
|
+
})(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
375
379
|
function parseError(res) {
|
|
376
380
|
if (res.status === 502) {
|
|
377
381
|
return "No connection with server";
|
|
378
382
|
}
|
|
379
383
|
return res.body || "Status Code ".concat(res.status, " (").concat(res.statusText, ")");
|
|
380
384
|
}
|
|
381
|
-
var TLSError = exports2.TLSError = /* @__PURE__ */ function(_Error2) {
|
|
385
|
+
var TLSError = exports2.TLSError = /* @__PURE__ */ (function(_Error2) {
|
|
382
386
|
_inherits(TLSError2, _Error2);
|
|
383
387
|
var _super2 = _createSuper(TLSError2);
|
|
384
388
|
function TLSError2(reason, cause) {
|
|
@@ -393,7 +397,7 @@ var require_error = __commonJS({
|
|
|
393
397
|
return _this2;
|
|
394
398
|
}
|
|
395
399
|
return _createClass(TLSError2);
|
|
396
|
-
}(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
400
|
+
})(/* @__PURE__ */ _wrapNativeSuper(Error));
|
|
397
401
|
var SECURE_CONTEXT_REASONS = [{
|
|
398
402
|
match: /bad decrypt|bad password read|wrong final block length/i,
|
|
399
403
|
reason: "The private key could not be decrypted, the passphrase is missing or incorrect."
|
|
@@ -624,7 +628,7 @@ var require_event_emitter = __commonJS({
|
|
|
624
628
|
}
|
|
625
629
|
return (hint2 === "string" ? String : Number)(input);
|
|
626
630
|
}
|
|
627
|
-
var EventEmitter = exports2["default"] = /* @__PURE__ */ function() {
|
|
631
|
+
var EventEmitter = exports2["default"] = /* @__PURE__ */ (function() {
|
|
628
632
|
function EventEmitter2() {
|
|
629
633
|
_classCallCheck(this, EventEmitter2);
|
|
630
634
|
this.events = {};
|
|
@@ -666,7 +670,7 @@ var require_event_emitter = __commonJS({
|
|
|
666
670
|
}
|
|
667
671
|
}]);
|
|
668
672
|
return EventEmitter2;
|
|
669
|
-
}();
|
|
673
|
+
})();
|
|
670
674
|
}
|
|
671
675
|
});
|
|
672
676
|
|
|
@@ -884,7 +888,7 @@ var require_request = __commonJS({
|
|
|
884
888
|
var RESPONSE_EVENT = "response";
|
|
885
889
|
var ERROR_EVENT = "error";
|
|
886
890
|
var DONE_EVENT = "done";
|
|
887
|
-
var Request = exports2.Request = /* @__PURE__ */ function(_EventEmitter) {
|
|
891
|
+
var Request = exports2.Request = /* @__PURE__ */ (function(_EventEmitter) {
|
|
888
892
|
_inherits(Request2, _EventEmitter);
|
|
889
893
|
var _super = _createSuper(Request2);
|
|
890
894
|
function Request2(path2, method, body) {
|
|
@@ -1187,7 +1191,7 @@ var require_request = __commonJS({
|
|
|
1187
1191
|
}
|
|
1188
1192
|
}]);
|
|
1189
1193
|
return Request2;
|
|
1190
|
-
}(_eventEmitter["default"]);
|
|
1194
|
+
})(_eventEmitter["default"]);
|
|
1191
1195
|
function pickTLSOptions(tlsOptions) {
|
|
1192
1196
|
var result = {};
|
|
1193
1197
|
TLS_OPTION_KEYS.forEach(function(key) {
|
|
@@ -3569,11 +3573,11 @@ var ExecutionContext = class _ExecutionContext {
|
|
|
3569
3573
|
if (!this.#props.apiRequest) {
|
|
3570
3574
|
return void 0;
|
|
3571
3575
|
}
|
|
3572
|
-
this.#apiRequest ??= (arg) => this.#props.apiRequest({
|
|
3576
|
+
this.#apiRequest ??= ((arg) => this.#props.apiRequest({
|
|
3573
3577
|
...arg,
|
|
3574
3578
|
context: this.context,
|
|
3575
3579
|
logger: this.logger
|
|
3576
|
-
});
|
|
3580
|
+
}));
|
|
3577
3581
|
return this.#apiRequest;
|
|
3578
3582
|
}
|
|
3579
3583
|
// The bag every handler receives. Memoized: one bag per context, so the `helpers` factory runs once.
|
|
@@ -4245,11 +4249,13 @@ var RealtimeInboundInvocationSchema = z.looseObject({
|
|
|
4245
4249
|
queryParams: anyRecord().optional(),
|
|
4246
4250
|
body: z.unknown(),
|
|
4247
4251
|
rawBody: z.string().optional(),
|
|
4252
|
+
webhookData: anyRecord().nullish(),
|
|
4248
4253
|
connectionId: z.string().nullish()
|
|
4249
4254
|
});
|
|
4250
4255
|
var RealtimeSelectInvocationSchema = z.looseObject({
|
|
4251
4256
|
eventName: z.string().min(1),
|
|
4252
4257
|
eventData: z.unknown(),
|
|
4258
|
+
webhookData: anyRecord().nullish(),
|
|
4253
4259
|
triggers: z.array(z.looseObject({
|
|
4254
4260
|
id: z.string().min(1),
|
|
4255
4261
|
// A partially-configured instance is legal — `match` treats an empty param as "matches all".
|
|
@@ -4258,12 +4264,13 @@ var RealtimeSelectInvocationSchema = z.looseObject({
|
|
|
4258
4264
|
});
|
|
4259
4265
|
|
|
4260
4266
|
// ../../flow-extension-runner/src/v2/realtime-triggers/verify.ts
|
|
4261
|
-
function verifyDeclarative(verify, rawBody, headers, config) {
|
|
4267
|
+
function verifyDeclarative(verify, rawBody, headers, config, webhookData) {
|
|
4262
4268
|
const provided = headers[verify.header] ?? headers[verify.header.toLowerCase()];
|
|
4263
4269
|
if (!provided) {
|
|
4264
4270
|
return false;
|
|
4265
4271
|
}
|
|
4266
|
-
const
|
|
4272
|
+
const secret = verify.secret(config, { webhookData });
|
|
4273
|
+
const computed = Flowrunner.crypto.hmac(verify.algo, secret, rawBody ?? "", verify.encoding);
|
|
4267
4274
|
if (!Flowrunner.crypto.timingSafeEqual(provided, computed)) {
|
|
4268
4275
|
return false;
|
|
4269
4276
|
}
|
|
@@ -4397,8 +4404,9 @@ var RealtimeSetup = class {
|
|
|
4397
4404
|
const headers = invocation.headers ?? {};
|
|
4398
4405
|
const body = invocation.body;
|
|
4399
4406
|
const rawBody = invocation.rawBody;
|
|
4407
|
+
const webhookData = invocation.webhookData ?? null;
|
|
4400
4408
|
if (this.props.handshake) {
|
|
4401
|
-
const result = await this.props.handshake(ctx.bagWith({ requestBody: body, headers, rawBody }));
|
|
4409
|
+
const result = await this.props.handshake(ctx.bagWith({ requestBody: body, headers, rawBody, webhookData }));
|
|
4402
4410
|
if (result && (result.responseToExternalService !== void 0 || result.responseHeaders || result.responseToWebhook)) {
|
|
4403
4411
|
return {
|
|
4404
4412
|
handshake: true,
|
|
@@ -4411,7 +4419,7 @@ var RealtimeSetup = class {
|
|
|
4411
4419
|
if (isEmptyBody(body)) {
|
|
4412
4420
|
return { handshake: true, events: [] };
|
|
4413
4421
|
}
|
|
4414
|
-
if (!await this.#verify(rawBody, headers, ctx)) {
|
|
4422
|
+
if (!await this.#verify(rawBody, headers, webhookData, ctx)) {
|
|
4415
4423
|
ctx.logger.warn(`[flow-extension:${this.extension.id}] webhook signature verification failed \u2014 answering 401`);
|
|
4416
4424
|
return { events: [], responseToWebhook: { httpStatus: 401, rawBody: "" } };
|
|
4417
4425
|
}
|
|
@@ -4421,6 +4429,7 @@ var RealtimeSetup = class {
|
|
|
4421
4429
|
headers,
|
|
4422
4430
|
query: invocation.queryParams ?? {},
|
|
4423
4431
|
body,
|
|
4432
|
+
webhookData,
|
|
4424
4433
|
connectionId: invocation.connectionId
|
|
4425
4434
|
}));
|
|
4426
4435
|
return {
|
|
@@ -4449,12 +4458,12 @@ var RealtimeSetup = class {
|
|
|
4449
4458
|
return { events, eventScopeId, connectionId: invocation.connectionId };
|
|
4450
4459
|
}
|
|
4451
4460
|
// The author's own check wins; otherwise the declarative one; otherwise nothing was asked for.
|
|
4452
|
-
async #verify(rawBody, headers, ctx) {
|
|
4461
|
+
async #verify(rawBody, headers, webhookData, ctx) {
|
|
4453
4462
|
if (this.props.verifyRequest) {
|
|
4454
|
-
return !!await this.props.verifyRequest(ctx.bagWith({ rawBody, headers, config: ctx.config }));
|
|
4463
|
+
return !!await this.props.verifyRequest(ctx.bagWith({ rawBody, headers, webhookData, config: ctx.config }));
|
|
4455
4464
|
}
|
|
4456
4465
|
if (this.props.verify) {
|
|
4457
|
-
return verifyDeclarative(this.props.verify, rawBody, headers, ctx.config);
|
|
4466
|
+
return verifyDeclarative(this.props.verify, rawBody, headers, ctx.config, webhookData);
|
|
4458
4467
|
}
|
|
4459
4468
|
return true;
|
|
4460
4469
|
}
|
|
@@ -4474,8 +4483,9 @@ var RealtimeSetup = class {
|
|
|
4474
4483
|
return { ids: [], enrichedEventData: null };
|
|
4475
4484
|
}
|
|
4476
4485
|
const eventData = invocation.eventData;
|
|
4477
|
-
const
|
|
4478
|
-
const
|
|
4486
|
+
const webhookData = invocation.webhookData ?? null;
|
|
4487
|
+
const ids = (invocation.triggers ?? []).filter((instance) => trigger.matches(instance.data ?? {}, eventData, webhookData)).map((instance) => instance.id);
|
|
4488
|
+
const enrichedEventData = ids.length && trigger.hasExtendResult() ? await trigger.extendResult(eventData, ctx, webhookData) : null;
|
|
4479
4489
|
return { ids, enrichedEventData };
|
|
4480
4490
|
}
|
|
4481
4491
|
};
|
|
@@ -4536,14 +4546,18 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
|
|
|
4536
4546
|
* Whether one CONFIGURED INSTANCE of this trigger cares about an event. Declarative form: type-coerced
|
|
4537
4547
|
* equality per filled param, where an empty param means "any" — that is what lets a user leave a filter
|
|
4538
4548
|
* blank and receive everything. Predicate form: the author decides. No `match` at all: always fires.
|
|
4549
|
+
*
|
|
4550
|
+
* `webhookData` is handed to the predicate form to be READ — an instance filter that depends on what the
|
|
4551
|
+
* subscription registered (a tenant id, a resource the webhook was scoped to) has nowhere else to get it.
|
|
4552
|
+
* Returning a new document is not a thing this seam can do; only subscribe/refresh/unsubscribe persist.
|
|
4539
4553
|
*/
|
|
4540
|
-
matches(params, providerEventData) {
|
|
4554
|
+
matches(params, providerEventData, webhookData = null) {
|
|
4541
4555
|
const match = this.props.match;
|
|
4542
4556
|
if (!match) {
|
|
4543
4557
|
return true;
|
|
4544
4558
|
}
|
|
4545
4559
|
if (typeof match === "function") {
|
|
4546
|
-
return !!match({ params, providerEventData });
|
|
4560
|
+
return !!match({ params, providerEventData, webhookData });
|
|
4547
4561
|
}
|
|
4548
4562
|
for (const [paramKey, path2] of Object.entries(match)) {
|
|
4549
4563
|
const paramValue = params[paramKey];
|
|
@@ -4557,8 +4571,9 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
|
|
|
4557
4571
|
return true;
|
|
4558
4572
|
}
|
|
4559
4573
|
// Runs ONCE per event if any instance matched — the only per-event place that may call the provider API.
|
|
4560
|
-
|
|
4561
|
-
|
|
4574
|
+
// It reads `webhookData` (an access token or external id the subscription stored) but cannot change it.
|
|
4575
|
+
extendResult(providerEventData, ctx, webhookData = null) {
|
|
4576
|
+
return this.props.extendResult?.(ctx.bagWith({ providerEventData, webhookData }));
|
|
4562
4577
|
}
|
|
4563
4578
|
hasExtendResult() {
|
|
4564
4579
|
return typeof this.props.extendResult === "function";
|