@uipath/maestro-builder-sdk 6.79.1 → 6.81.0
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/api-index.md +84 -79
- package/dist/api-members.md +266 -248
- package/dist/case/case-sdk.d.ts +129 -20
- package/dist/case/case-sdk.js +90 -1
- package/dist/case/check.js +17 -0
- package/dist/case/decompile-http-request.d.ts +29 -0
- package/dist/case/decompile-http-request.js +120 -0
- package/dist/case/decompile-script.d.ts +23 -0
- package/dist/case/decompile-script.js +53 -0
- package/dist/case/decompile.d.ts +6 -0
- package/dist/case/decompile.js +38 -0
- package/dist/case/http-request-metadata.json +49 -0
- package/dist/case/http-request.d.ts +143 -0
- package/dist/case/http-request.js +371 -0
- package/dist/case/load.js +12 -0
- package/dist/case/preserve.d.ts +11 -0
- package/dist/case/preserve.js +6 -0
- package/dist/case/script.d.ts +75 -0
- package/dist/case/script.js +124 -0
- package/dist/case/serialize.js +146 -0
- package/dist/core/refusals.d.ts +12 -0
- package/dist/core/refusals.js +18 -0
- package/dist/core/script-engine.d.ts +34 -0
- package/dist/core/script-engine.js +48 -0
- package/dist/nodes/script/flow/runtime.d.ts +1 -1
- package/dist/nodes/script/flow/runtime.js +5 -35
- package/dist/script-function-scope.js +44 -6
- package/package.json +2 -2
package/dist/case/case-sdk.d.ts
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* case-sdk — a fluent builder for UiPath Case Management plans (`caseplan.json`,
|
|
3
|
-
* schema V32).
|
|
4
|
-
*
|
|
5
|
-
* Like the Flow builder, this constructs a plain description of a case — its
|
|
6
|
-
* stages, the tasks inside them, and the entry/exit *conditions* that drive
|
|
7
|
-
* transitions — which `serialize()` turns into a real `caseplan.json`. A case is
|
|
8
|
-
* a hierarchy (stages → tasks), not a graph: there are **no edges**; flow
|
|
9
|
-
* between stages is expressed entirely through conditions (see `rule()`).
|
|
10
|
-
*
|
|
11
|
-
* This first cut is **reference-mode**: a task points at an already-published
|
|
12
|
-
* process/agent/rpa/workflow by name + folder. (Embedding an inline flow/bpmn
|
|
13
|
-
* body in a task is a later phase.) The builder uses callback closures for
|
|
14
|
-
* nesting, matching the Flow SDK's `.branch(name, cond, b => …)` style — so a
|
|
15
|
-
* `casePlan()` only ever exposes case methods, and each nested builder only its
|
|
16
|
-
* own.
|
|
17
|
-
*
|
|
18
|
-
* `casePlan` (not `case`) is the entry point: `case` is a reserved word.
|
|
19
|
-
*/
|
|
20
1
|
import type { TypeDesc } from '../core/expr.js';
|
|
21
2
|
import { type ActionSpec, type ConnectorOpts, type CaseEventFilter, type EventSubscription, type TriggerOptions } from '../core/actions.js';
|
|
22
3
|
import { type ConnectorDescriptor, type TriggerDescriptor } from '../core/connectors.js';
|
|
@@ -441,7 +422,7 @@ export interface BuiltCaseExitCondition {
|
|
|
441
422
|
marksCaseComplete?: boolean;
|
|
442
423
|
rules: CaseRule[][];
|
|
443
424
|
}
|
|
444
|
-
export type TaskKind = 'process' | 'agent' | 'rpa' | 'api-workflow' | 'case-management' | 'flow-process' | 'function' | 'business-rule' | 'external-agent' | 'external-workflow' | 'action' | 'connector' | 'wait-for-timer' | 'wait-for-connector';
|
|
425
|
+
export type TaskKind = 'process' | 'agent' | 'rpa' | 'api-workflow' | 'case-management' | 'flow-process' | 'function' | 'business-rule' | 'external-agent' | 'external-workflow' | 'action' | 'connector' | 'wait-for-timer' | 'wait-for-connector' | 'script' | 'http-request';
|
|
445
426
|
/**
|
|
446
427
|
* Task kinds that the Case schema permits as unresolved skeletons: the
|
|
447
428
|
* published-resource kinds, `action` (a human task whose Action App or form is
|
|
@@ -529,6 +510,78 @@ export interface CaseConnectorOpts extends ConnectorOpts {
|
|
|
529
510
|
*/
|
|
530
511
|
carriedFields?: readonly CarriedConnectorField[];
|
|
531
512
|
}
|
|
513
|
+
/** Options for a script task (`.script()`): the schemas the Designer keeps on its two outputs. */
|
|
514
|
+
export interface CaseScriptOptions {
|
|
515
|
+
/**
|
|
516
|
+
* The JSON schema of what the body returns, written as `scriptResponse`'s
|
|
517
|
+
* `_jsonSchema`. The Designer infers it from the body when it saves the plan;
|
|
518
|
+
* decompile carries the one it saved, so a recompile keeps it.
|
|
519
|
+
*/
|
|
520
|
+
responseSchema?: Record<string, unknown>;
|
|
521
|
+
/** The JSON schema of the `Error` output, which a Designer-saved task may carry. A new task has none. */
|
|
522
|
+
errorSchema?: Record<string, unknown>;
|
|
523
|
+
}
|
|
524
|
+
/** A built script task: the body as it runs (no leading `=`), and how it was authored. */
|
|
525
|
+
export interface CaseScriptSpec extends CaseScriptOptions {
|
|
526
|
+
/** The JavaScript body, as the engine runs it. */
|
|
527
|
+
body: string;
|
|
528
|
+
/** Whether the body was lowered from a TypeScript function (so the compiler checked it). */
|
|
529
|
+
fromFunction: boolean;
|
|
530
|
+
}
|
|
531
|
+
/** A method the HTTP request activity offers. */
|
|
532
|
+
export type HttpRequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
533
|
+
/**
|
|
534
|
+
* An HTTP request task's request (`.httpRequest()`). Without `connector` the
|
|
535
|
+
* request goes to `url` as written, unauthenticated; with one it reuses that
|
|
536
|
+
* connector's connection, and `path` is relative to the connector's base URL.
|
|
537
|
+
*/
|
|
538
|
+
export interface CaseHttpRequestSpec {
|
|
539
|
+
/** The HTTP method; a body goes only with POST, PUT or PATCH. */
|
|
540
|
+
method: HttpRequestMethod;
|
|
541
|
+
/** The full address, for a request without a connector. May be an `=` expression. */
|
|
542
|
+
url?: string;
|
|
543
|
+
/** The address relative to the connector's base URL, for a connector request. */
|
|
544
|
+
path?: string;
|
|
545
|
+
/**
|
|
546
|
+
* Request headers. Never a literal credential (`Authorization`, `Cookie`, an
|
|
547
|
+
* API key): the value is written into the case plan as authored. Authenticate
|
|
548
|
+
* through `connector` instead.
|
|
549
|
+
*
|
|
550
|
+
* @enforcedBy HTTP_REQUEST_CREDENTIAL_HEADER `check` reports a credential header with a literal value.
|
|
551
|
+
*/
|
|
552
|
+
headers?: Record<string, string>;
|
|
553
|
+
/**
|
|
554
|
+
* Query parameters. Never a literal credential (`api_key`, `access_token`, …),
|
|
555
|
+
* for the same reason as headers.
|
|
556
|
+
*
|
|
557
|
+
* @enforcedBy HTTP_REQUEST_CREDENTIAL_HEADER `check` reports a credential query parameter with a literal value.
|
|
558
|
+
*/
|
|
559
|
+
query?: Record<string, string>;
|
|
560
|
+
/**
|
|
561
|
+
* The request body, for POST, PUT or PATCH: an object, JSON text, or an `=`
|
|
562
|
+
* expression (`=js:vars.payload`). In an object, a value `=js:<expression>`
|
|
563
|
+
* or `=<reference>` (`=vars.id`) is sent as the value it reads.
|
|
564
|
+
*
|
|
565
|
+
* @enforcedBy HTTP_REQUEST_BODY_METHOD `check` reports a body on another method.
|
|
566
|
+
* @enforcedBy HTTP_REQUEST_BODY_FORM compile refuses text that is neither JSON nor an expression.
|
|
567
|
+
* @enforcedBy HTTP_REQUEST_BODY_EXPRESSION compile refuses an object value that is another kind of `=` expression.
|
|
568
|
+
*/
|
|
569
|
+
body?: string | Record<string, unknown> | unknown[];
|
|
570
|
+
/**
|
|
571
|
+
* Reuse a connector's authentication: its key (`uipath-atlassian-jira`) and
|
|
572
|
+
* the symbolic connection and folder bindings, as on `.connector()`.
|
|
573
|
+
*/
|
|
574
|
+
connector?: HttpRequestConnector;
|
|
575
|
+
}
|
|
576
|
+
/** The connection an HTTP request reuses the authentication of (`CaseHttpRequestSpec.connector`). */
|
|
577
|
+
export interface HttpRequestConnector {
|
|
578
|
+
/** The connector whose authentication the request reuses, e.g. `uipath-atlassian-jira`. */
|
|
579
|
+
key: string;
|
|
580
|
+
/** The symbolic connection binding, resolved through bindings.json like a connector task's. */
|
|
581
|
+
connection: string;
|
|
582
|
+
/** The symbolic folder binding of that connection. */
|
|
583
|
+
folder: string;
|
|
584
|
+
}
|
|
532
585
|
/**
|
|
533
586
|
* The external agent's or automation's `executionType`, as Integration Service
|
|
534
587
|
* reports it for the connector object.
|
|
@@ -813,6 +866,10 @@ export interface BuiltTask {
|
|
|
813
866
|
connector?: ConnectorSpecData;
|
|
814
867
|
/** Descriptor-resolved external agent/workflow configuration. */
|
|
815
868
|
external?: ExternalTaskSpecData;
|
|
869
|
+
/** script task: the body. */
|
|
870
|
+
script?: CaseScriptSpec;
|
|
871
|
+
/** http-request task: the request. */
|
|
872
|
+
http?: CaseHttpRequestSpec;
|
|
816
873
|
timer?: TimerSpecData;
|
|
817
874
|
/** wait-for-connector task: the event subscription (placeholder when key/operation omitted). */
|
|
818
875
|
waitConnector?: WaitConnectorSpec;
|
|
@@ -1070,6 +1127,8 @@ declare class TaskBuilder {
|
|
|
1070
1127
|
private _action?;
|
|
1071
1128
|
private _connector?;
|
|
1072
1129
|
private _external?;
|
|
1130
|
+
private _script?;
|
|
1131
|
+
private _http?;
|
|
1073
1132
|
private _timer?;
|
|
1074
1133
|
private _waitConnector?;
|
|
1075
1134
|
private _required?;
|
|
@@ -1315,6 +1374,56 @@ declare class TaskBuilder {
|
|
|
1315
1374
|
* @returns This builder, so calls chain.
|
|
1316
1375
|
*/
|
|
1317
1376
|
waitForTimer(spec: TimerSpecData): this;
|
|
1377
|
+
/**
|
|
1378
|
+
* A script task: a JavaScript body the engine runs, reading case state
|
|
1379
|
+
* through `vars` (the case variables) and `metadata` (the instance metadata).
|
|
1380
|
+
* The task writes two outputs: what the body returns, as `scriptResponse`
|
|
1381
|
+
* (`=result.response`), and `Error`. Map the return to a case variable with
|
|
1382
|
+
* `.outputs({ scriptResult: '=result.response' })`.
|
|
1383
|
+
*
|
|
1384
|
+
* Pass a TypeScript function and the compiler checks the body like the rest
|
|
1385
|
+
* of the module. It is never called: its body, exactly as written, becomes
|
|
1386
|
+
* the script, and its parameters are renamed to the runtime's `vars` and
|
|
1387
|
+
* `metadata` (take neither, `vars` alone, or both). It may read only what the
|
|
1388
|
+
* engine gives a script (the ES2020 built-ins and `console`), so a module
|
|
1389
|
+
* constant, an import or a library is refused, because in the run it would be
|
|
1390
|
+
* a `ReferenceError`.
|
|
1391
|
+
*
|
|
1392
|
+
* ```ts
|
|
1393
|
+
* .task('Double', (t) => t.script((vars: { amount: number }) => ({ total: vars.amount * 2 }))
|
|
1394
|
+
* .outputs({ scriptResult: '=result.response' }))
|
|
1395
|
+
* ```
|
|
1396
|
+
*
|
|
1397
|
+
* A string is the body as written, unchecked by the compiler.
|
|
1398
|
+
*
|
|
1399
|
+
* @param body - The script, as a function of the case variables and the instance metadata (or of fewer), or its JavaScript text.
|
|
1400
|
+
* @param options - The schemas the Designer keeps on the two outputs, which decompile carries.
|
|
1401
|
+
* @returns This builder, so calls chain.
|
|
1402
|
+
* @enforcedBy SCRIPT_FUNCTION_UNLOWERABLE A function that cannot be a script body is refused at the call.
|
|
1403
|
+
* @enforcedBy SCRIPT_TASK_NO_BODY `check` reports a blank body.
|
|
1404
|
+
* @enforcedBy SCRIPT_BODY_SYNTAX `check` reports a string body that does not parse as JavaScript.
|
|
1405
|
+
*/
|
|
1406
|
+
script<V, M = unknown>(body: ((vars: V, metadata: M) => unknown) | string, options?: CaseScriptOptions): this;
|
|
1407
|
+
/**
|
|
1408
|
+
* An HTTP request through Integration Service's generic HTTP connector, the
|
|
1409
|
+
* Case Designer's HTTP request task. The task writes four outputs, `code`,
|
|
1410
|
+
* `headers`, `body` and `Error`; map one to a case variable with
|
|
1411
|
+
* `.outputs({ reply: '=response.body' })`, or read it with
|
|
1412
|
+
* `taskOutput(stage, task, 'body')`.
|
|
1413
|
+
*
|
|
1414
|
+
* An `=` value inside an object body sends the value it reads, not its text:
|
|
1415
|
+
* `body: { probe: '=vars.id' }` is written `=js:( {"probe":vars.id})`, and
|
|
1416
|
+
* `'=js:vars.n * 2'` becomes `(vars.n * 2)`.
|
|
1417
|
+
*
|
|
1418
|
+
* ```ts
|
|
1419
|
+
* t.httpRequest({ method: 'POST', url: 'https://postman-echo.com/post', body: { probe: '=vars.id' } })
|
|
1420
|
+
* .outputs({ echoResponse: '=response.body' })
|
|
1421
|
+
* ```
|
|
1422
|
+
*
|
|
1423
|
+
* @param spec - The method, the address (`url`, or `path` with a `connector`), and optional headers, query and body.
|
|
1424
|
+
* @returns This builder, so calls chain.
|
|
1425
|
+
*/
|
|
1426
|
+
httpRequest(spec: CaseHttpRequestSpec): this;
|
|
1318
1427
|
/**
|
|
1319
1428
|
* Mark this task required, so its stage cannot complete without it.
|
|
1320
1429
|
*
|
package/dist/case/case-sdk.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* case-sdk — a fluent builder for UiPath Case Management plans (`caseplan.json`,
|
|
3
|
+
* schema V32).
|
|
4
|
+
*
|
|
5
|
+
* Like the Flow builder, this constructs a plain description of a case — its
|
|
6
|
+
* stages, the tasks inside them, and the entry/exit *conditions* that drive
|
|
7
|
+
* transitions — which `serialize()` turns into a real `caseplan.json`. A case is
|
|
8
|
+
* a hierarchy (stages → tasks), not a graph: there are **no edges**; flow
|
|
9
|
+
* between stages is expressed entirely through conditions (see `rule()`).
|
|
10
|
+
*
|
|
11
|
+
* This first cut is **reference-mode**: a task points at an already-published
|
|
12
|
+
* process/agent/rpa/workflow by name + folder. (Embedding an inline flow/bpmn
|
|
13
|
+
* body in a task is a later phase.) The builder uses callback closures for
|
|
14
|
+
* nesting, matching the Flow SDK's `.branch(name, cond, b => …)` style — so a
|
|
15
|
+
* `casePlan()` only ever exposes case methods, and each nested builder only its
|
|
16
|
+
* own.
|
|
17
|
+
*
|
|
18
|
+
* `casePlan` (not `case`) is the entry point: `case` is a reserved word.
|
|
19
|
+
*/
|
|
20
|
+
import { lowerScriptFunction } from '../core/script-function.js';
|
|
21
|
+
import { CASE_SCRIPT_RUNTIME } from './script.js';
|
|
1
22
|
import { ACTION_PASSTHROUGH_SETTINGS } from './action-settings.js';
|
|
2
23
|
import { connector as makeConnector, subscriptionFrom, } from '../core/actions.js';
|
|
3
24
|
import { isTriggerDescriptor } from '../core/connectors.js';
|
|
@@ -222,6 +243,8 @@ class TaskBuilder {
|
|
|
222
243
|
_action;
|
|
223
244
|
_connector;
|
|
224
245
|
_external;
|
|
246
|
+
_script;
|
|
247
|
+
_http;
|
|
225
248
|
_timer;
|
|
226
249
|
_waitConnector;
|
|
227
250
|
_required;
|
|
@@ -485,6 +508,68 @@ class TaskBuilder {
|
|
|
485
508
|
this._timer = spec;
|
|
486
509
|
return this;
|
|
487
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* A script task: a JavaScript body the engine runs, reading case state
|
|
513
|
+
* through `vars` (the case variables) and `metadata` (the instance metadata).
|
|
514
|
+
* The task writes two outputs: what the body returns, as `scriptResponse`
|
|
515
|
+
* (`=result.response`), and `Error`. Map the return to a case variable with
|
|
516
|
+
* `.outputs({ scriptResult: '=result.response' })`.
|
|
517
|
+
*
|
|
518
|
+
* Pass a TypeScript function and the compiler checks the body like the rest
|
|
519
|
+
* of the module. It is never called: its body, exactly as written, becomes
|
|
520
|
+
* the script, and its parameters are renamed to the runtime's `vars` and
|
|
521
|
+
* `metadata` (take neither, `vars` alone, or both). It may read only what the
|
|
522
|
+
* engine gives a script (the ES2020 built-ins and `console`), so a module
|
|
523
|
+
* constant, an import or a library is refused, because in the run it would be
|
|
524
|
+
* a `ReferenceError`.
|
|
525
|
+
*
|
|
526
|
+
* ```ts
|
|
527
|
+
* .task('Double', (t) => t.script((vars: { amount: number }) => ({ total: vars.amount * 2 }))
|
|
528
|
+
* .outputs({ scriptResult: '=result.response' }))
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* A string is the body as written, unchecked by the compiler.
|
|
532
|
+
*
|
|
533
|
+
* @param body - The script, as a function of the case variables and the instance metadata (or of fewer), or its JavaScript text.
|
|
534
|
+
* @param options - The schemas the Designer keeps on the two outputs, which decompile carries.
|
|
535
|
+
* @returns This builder, so calls chain.
|
|
536
|
+
* @enforcedBy SCRIPT_FUNCTION_UNLOWERABLE A function that cannot be a script body is refused at the call.
|
|
537
|
+
* @enforcedBy SCRIPT_TASK_NO_BODY `check` reports a blank body.
|
|
538
|
+
* @enforcedBy SCRIPT_BODY_SYNTAX `check` reports a string body that does not parse as JavaScript.
|
|
539
|
+
*/
|
|
540
|
+
script(body, options = {}) {
|
|
541
|
+
this.setKind('script');
|
|
542
|
+
const fromFunction = typeof body === 'function';
|
|
543
|
+
const text = fromFunction
|
|
544
|
+
? lowerScriptFunction(body, CASE_SCRIPT_RUNTIME, `task "${this._name}": .script(${body.name || 'function'})`)
|
|
545
|
+
: body;
|
|
546
|
+
this._script = { body: text, fromFunction, ...options };
|
|
547
|
+
return this;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* An HTTP request through Integration Service's generic HTTP connector, the
|
|
551
|
+
* Case Designer's HTTP request task. The task writes four outputs, `code`,
|
|
552
|
+
* `headers`, `body` and `Error`; map one to a case variable with
|
|
553
|
+
* `.outputs({ reply: '=response.body' })`, or read it with
|
|
554
|
+
* `taskOutput(stage, task, 'body')`.
|
|
555
|
+
*
|
|
556
|
+
* An `=` value inside an object body sends the value it reads, not its text:
|
|
557
|
+
* `body: { probe: '=vars.id' }` is written `=js:( {"probe":vars.id})`, and
|
|
558
|
+
* `'=js:vars.n * 2'` becomes `(vars.n * 2)`.
|
|
559
|
+
*
|
|
560
|
+
* ```ts
|
|
561
|
+
* t.httpRequest({ method: 'POST', url: 'https://postman-echo.com/post', body: { probe: '=vars.id' } })
|
|
562
|
+
* .outputs({ echoResponse: '=response.body' })
|
|
563
|
+
* ```
|
|
564
|
+
*
|
|
565
|
+
* @param spec - The method, the address (`url`, or `path` with a `connector`), and optional headers, query and body.
|
|
566
|
+
* @returns This builder, so calls chain.
|
|
567
|
+
*/
|
|
568
|
+
httpRequest(spec) {
|
|
569
|
+
this.setKind('http-request');
|
|
570
|
+
this._http = spec;
|
|
571
|
+
return this;
|
|
572
|
+
}
|
|
488
573
|
/**
|
|
489
574
|
* Mark this task required, so its stage cannot complete without it.
|
|
490
575
|
*
|
|
@@ -673,7 +758,9 @@ class TaskBuilder {
|
|
|
673
758
|
// more row after them, as `uip maestro case sdd convert` and `case splice`
|
|
674
759
|
// write an SDD row `app_id -> postAppId`.
|
|
675
760
|
const REF_IO = new Set(['process', 'agent', 'rpa', 'api-workflow', 'case-management', 'flow-process', 'function', 'business-rule']);
|
|
676
|
-
|
|
761
|
+
// A script task writes its two outputs, an http-request task the activity's
|
|
762
|
+
// four; an extract maps one to a variable.
|
|
763
|
+
const CONNECTOR_OUTPUTS = new Set(['connector', 'wait-for-connector', 'script', 'http-request']);
|
|
677
764
|
if (this._inputs && !REF_IO.has(this._kind))
|
|
678
765
|
throw new CompileRefusal('TASK_INPUTS_UNSUPPORTED', `task "${this._name}": .inputs() is only supported on reference-mode tasks (process/agent/rpa/api-workflow/case-management/flow-process/function/business-rule), not "${this._kind}". A connector task takes its inputs in .connector() / .waitForConnector().`);
|
|
679
766
|
// Which rows a kind accepts depends on the row: an extract reads the task's
|
|
@@ -705,6 +792,8 @@ class TaskBuilder {
|
|
|
705
792
|
action: this._action,
|
|
706
793
|
connector: this._connector,
|
|
707
794
|
external: this._external,
|
|
795
|
+
script: this._script,
|
|
796
|
+
http: this._http,
|
|
708
797
|
timer: this._timer,
|
|
709
798
|
waitConnector: this._waitConnector,
|
|
710
799
|
required: this._required,
|
package/dist/case/check.js
CHANGED
|
@@ -3,6 +3,8 @@ import { CASE_FORMAT_PROFILE, CASE_SCHEMA_VERSIONS, authoredCaseVersion } from '
|
|
|
3
3
|
import { schemaVersionRefusal } from '../schema-version.js';
|
|
4
4
|
import { EQUALS_EXPR_DIALECT, checkConnectorLookups, checkConnectorResources, checkConnectorSchema, } from '../core/connector-checks.js';
|
|
5
5
|
import { isConnectorPlaceholder } from './connector-placeholder.js';
|
|
6
|
+
import { scriptLint } from './script.js';
|
|
7
|
+
import { httpRequestLint } from './http-request.js';
|
|
6
8
|
import { checkRuleSemantics } from './check-rule-semantics.js';
|
|
7
9
|
import { serialize } from './serialize.js';
|
|
8
10
|
import { lintPlanFindings, planReport } from './plan-check/index.js';
|
|
@@ -207,6 +209,21 @@ export function check(built, opts = {}) {
|
|
|
207
209
|
refStage(r, 'case-exit');
|
|
208
210
|
refPlacement(r, 'case-exit', 'case-exit');
|
|
209
211
|
}
|
|
212
|
+
// A script body compile writes as authored but a person should fix (lint).
|
|
213
|
+
for (const stage of built.stages)
|
|
214
|
+
for (const lane of stage.lanes)
|
|
215
|
+
for (const t of lane)
|
|
216
|
+
if (t.kind === 'script' && t.script)
|
|
217
|
+
for (const f of scriptLint(`Script task "${t.name}"`, t.script))
|
|
218
|
+
diags.push({ level: 'error', code: f.code, message: f.message, ...(f.suggestion ? { suggestion: f.suggestion } : {}), where: t.name });
|
|
219
|
+
// An HTTP request compile writes as authored but a person should fix (lint;
|
|
220
|
+
// what it cannot write is the serializer's, through collect mode).
|
|
221
|
+
for (const stage of built.stages)
|
|
222
|
+
for (const lane of stage.lanes)
|
|
223
|
+
for (const t of lane)
|
|
224
|
+
if (t.kind === 'http-request' && t.http)
|
|
225
|
+
for (const f of httpRequestLint(`HTTP request task "${t.name}"`, t.http))
|
|
226
|
+
diags.push({ level: 'error', code: f.code, message: f.message, ...(f.suggestion ? { suggestion: f.suggestion } : {}), where: t.name });
|
|
210
227
|
checkRuleSemantics(built, diags);
|
|
211
228
|
checkLibraryConnectors(built, opts, diags);
|
|
212
229
|
diags.push(...serializerRefusals(built, opts, diags));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* case/decompile-http-request — the decompile half of the Case `http-request`
|
|
3
|
+
* task (`./http-request.ts` holds the shape compile writes). It lifts a saved
|
|
4
|
+
* task's `data` to the `.httpRequest()` spec that compiles back to it, and
|
|
5
|
+
* throws, naming the field, on anything a recompile would not write back.
|
|
6
|
+
* Decompile-side, so its refusals are plain Errors (FB017 scopes it out by name).
|
|
7
|
+
*/
|
|
8
|
+
import type { CaseHttpRequestSpec } from './case-sdk.js';
|
|
9
|
+
/** What decompile needs from the plan around one task. */
|
|
10
|
+
export interface HttpRequestLiftRefs {
|
|
11
|
+
/** The root binding with this id, or undefined. */
|
|
12
|
+
binding(id: string): Record<string, unknown> | undefined;
|
|
13
|
+
/** The symbolic label a recompile names the root binding `id` by. */
|
|
14
|
+
label(id: string): string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The `.httpRequest()` spec a saved `http-request` task's `data` lifts to, or a
|
|
18
|
+
* thrown Error naming what a recompile would not write back. The `metadata`
|
|
19
|
+
* entry is not lifted: compile writes `HTTP_REQUEST_METADATA` (`./http-request.ts`),
|
|
20
|
+
* and a saved body that differs from it (another connector version) is carried
|
|
21
|
+
* through preservation (`httpRequestMetadata`), so a round trip keeps it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function liftHttpRequest(owner: string, data: Record<string, unknown>, refs: HttpRequestLiftRefs): CaseHttpRequestSpec;
|
|
24
|
+
/** One of the activity's own output rows, which compile writes itself; a custom row is never one. */
|
|
25
|
+
export declare function isHttpRequestOwnOutput(row: {
|
|
26
|
+
custom?: unknown;
|
|
27
|
+
name?: unknown;
|
|
28
|
+
source?: unknown;
|
|
29
|
+
}): boolean;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { MANAGED_HTTP_CONNECTOR_KEY, MANAGED_HTTP_ENDPOINT, MANAGED_HTTP_ENDPOINT_METHOD, MANAGED_HTTP_OBJECT_NAME, } from '../core/managed-http.js';
|
|
2
|
+
import { HTTP_REQUEST_CONTEXT, HTTP_REQUEST_IMPLICIT_CONNECTION, HTTP_REQUEST_OUTPUTS, HTTP_REQUEST_SERVICE_TYPE, httpRequestBodySource, } from './http-request.js';
|
|
3
|
+
/** The `body` request keys compile writes; decompile lifts exactly these. */
|
|
4
|
+
const REQUEST_KEYS = new Set(['authentication', 'targetConnector', 'method', 'url', 'path', 'headers', 'query', 'requestBodyType', 'body']);
|
|
5
|
+
/**
|
|
6
|
+
* The `.httpRequest()` spec a saved `http-request` task's `data` lifts to, or a
|
|
7
|
+
* thrown Error naming what a recompile would not write back. The `metadata`
|
|
8
|
+
* entry is not lifted: compile writes `HTTP_REQUEST_METADATA` (`./http-request.ts`),
|
|
9
|
+
* and a saved body that differs from it (another connector version) is carried
|
|
10
|
+
* through preservation (`httpRequestMetadata`), so a round trip keeps it.
|
|
11
|
+
*/
|
|
12
|
+
export function liftHttpRequest(owner, data, refs) {
|
|
13
|
+
const fail = (why) => {
|
|
14
|
+
throw new Error(`${owner} ${why}`);
|
|
15
|
+
};
|
|
16
|
+
const unknownData = Object.keys(data).find((k) => !['serviceType', 'context', 'inputs', 'outputs', 'bindings'].includes(k));
|
|
17
|
+
if (unknownData)
|
|
18
|
+
fail(`has unsupported data field "${unknownData}".`);
|
|
19
|
+
if (data.serviceType !== HTTP_REQUEST_SERVICE_TYPE)
|
|
20
|
+
fail(`has serviceType ${JSON.stringify(data.serviceType ?? null)}; an HTTP request task is "${HTTP_REQUEST_SERVICE_TYPE}".`);
|
|
21
|
+
const context = Array.isArray(data.context) ? data.context : fail('has no context array.');
|
|
22
|
+
const names = context.map((row) => String(row?.name ?? ''));
|
|
23
|
+
const odd = names.find((n, at) => !HTTP_REQUEST_CONTEXT.includes(n) || names.indexOf(n) !== at);
|
|
24
|
+
if (odd !== undefined)
|
|
25
|
+
fail(`has unsupported or repeated context row "${odd}".`);
|
|
26
|
+
const absent = HTTP_REQUEST_CONTEXT.find((n) => !names.includes(n));
|
|
27
|
+
if (absent)
|
|
28
|
+
fail(`is missing context row "${absent}".`);
|
|
29
|
+
const value = (name) => context.find((row) => row.name === name)?.value;
|
|
30
|
+
const fixed = {
|
|
31
|
+
connectorKey: MANAGED_HTTP_CONNECTOR_KEY, method: MANAGED_HTTP_ENDPOINT_METHOD, path: MANAGED_HTTP_ENDPOINT,
|
|
32
|
+
objectName: MANAGED_HTTP_OBJECT_NAME, activityConfigurationVersion: 'v2',
|
|
33
|
+
};
|
|
34
|
+
for (const [name, expected] of Object.entries(fixed))
|
|
35
|
+
if (value(name) !== expected)
|
|
36
|
+
fail(`has context ${name} ${JSON.stringify(value(name) ?? null)}; the HTTP request activity's is "${expected}".`);
|
|
37
|
+
const bindingId = (name) => {
|
|
38
|
+
const v = value(name);
|
|
39
|
+
if (typeof v !== 'string' || !v.startsWith('=bindings.'))
|
|
40
|
+
fail(`context ${name} must reference a root binding.`);
|
|
41
|
+
const id = String(v).slice('=bindings.'.length);
|
|
42
|
+
if (!refs.binding(id))
|
|
43
|
+
fail(`context ${name} references missing root binding "${id}".`);
|
|
44
|
+
return id;
|
|
45
|
+
};
|
|
46
|
+
const inputs = Array.isArray(data.inputs) ? data.inputs : fail('has no inputs array.');
|
|
47
|
+
const inputNames = inputs.map((row) => String(row?.name ?? ''));
|
|
48
|
+
if (inputNames.join(',') !== 'pathParameters,queryParameters,body')
|
|
49
|
+
fail(`has inputs ${JSON.stringify(inputNames)}; an HTTP request task has pathParameters, queryParameters and body.`);
|
|
50
|
+
for (const container of inputs.slice(0, 2)) {
|
|
51
|
+
const b = container.body;
|
|
52
|
+
if (b !== undefined && !(typeof b === 'object' && b !== null && Object.keys(b).length === 0))
|
|
53
|
+
fail(`carries a value in its ${String(container.name)} input, which the activity does not read; the request is in body.`);
|
|
54
|
+
}
|
|
55
|
+
const request = inputs[2].body;
|
|
56
|
+
if (typeof request !== 'object' || request === null || Array.isArray(request))
|
|
57
|
+
fail('has no request in its body input.');
|
|
58
|
+
const r = request;
|
|
59
|
+
const unknownKey = Object.keys(r).find((k) => !REQUEST_KEYS.has(k));
|
|
60
|
+
if (unknownKey)
|
|
61
|
+
fail(`request has unsupported field "${unknownKey}".`);
|
|
62
|
+
const taskBindings = Array.isArray(data.bindings) ? data.bindings : [];
|
|
63
|
+
const spec = { method: r.method };
|
|
64
|
+
if (r.authentication === 'connector') {
|
|
65
|
+
if (typeof r.targetConnector !== 'string' || !r.targetConnector)
|
|
66
|
+
fail('reuses a connector but names no targetConnector.');
|
|
67
|
+
if (r.url !== undefined)
|
|
68
|
+
fail('reuses a connector but carries url; a connector request reads path.');
|
|
69
|
+
if (r.requestBodyType !== undefined)
|
|
70
|
+
fail('reuses a connector but carries requestBodyType, which only a manual request writes.');
|
|
71
|
+
const connection = bindingId('connection');
|
|
72
|
+
const folder = bindingId('folderKey');
|
|
73
|
+
// The Designer carries the pair on the task too; a recompile writes exactly those two.
|
|
74
|
+
const mirrored = taskBindings.length === 2
|
|
75
|
+
&& [connection, folder].every((id) => taskBindings.some((row) => row.id === id && JSON.stringify(row) === JSON.stringify(refs.binding(id))));
|
|
76
|
+
if (!mirrored)
|
|
77
|
+
fail('task bindings are not the connection and folder rows its context names.');
|
|
78
|
+
if (value('resourceKey') !== refs.binding(connection)?.resourceKey)
|
|
79
|
+
fail(`context resourceKey ${JSON.stringify(value('resourceKey') ?? null)} is not its connection binding's.`);
|
|
80
|
+
spec.connector = { key: String(r.targetConnector), connection: refs.label(connection), folder: refs.label(folder) };
|
|
81
|
+
if (r.path !== undefined)
|
|
82
|
+
spec.path = String(r.path);
|
|
83
|
+
}
|
|
84
|
+
else if (r.authentication === 'manual') {
|
|
85
|
+
if (r.targetConnector !== undefined || r.path !== undefined)
|
|
86
|
+
fail('is a manual request but carries targetConnector or path.');
|
|
87
|
+
if (refs.binding(bindingId('connection'))?.resourceKey !== HTTP_REQUEST_IMPLICIT_CONNECTION)
|
|
88
|
+
fail(`is a manual request whose connection binding is not "${HTTP_REQUEST_IMPLICIT_CONNECTION}".`);
|
|
89
|
+
if (value('resourceKey') !== null || value('folderKey') !== null)
|
|
90
|
+
fail('is a manual request but its context carries a resourceKey or folderKey.');
|
|
91
|
+
if (taskBindings.length)
|
|
92
|
+
fail('is a manual request but carries task bindings.');
|
|
93
|
+
if (r.url !== undefined)
|
|
94
|
+
spec.url = String(r.url);
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
fail(`has authentication ${JSON.stringify(r.authentication ?? null)}; it is "manual" or "connector".`);
|
|
98
|
+
if (r.headers !== undefined)
|
|
99
|
+
spec.headers = r.headers;
|
|
100
|
+
if (r.query !== undefined)
|
|
101
|
+
spec.query = r.query;
|
|
102
|
+
if (r.body !== undefined) {
|
|
103
|
+
if (typeof r.body !== 'string')
|
|
104
|
+
fail('request body must be text.');
|
|
105
|
+
if ((r.requestBodyType === 'raw') !== (spec.connector === undefined))
|
|
106
|
+
fail('request body\'s requestBodyType does not match its mode: a manual request writes "raw", a connector request none.');
|
|
107
|
+
spec.body = httpRequestBodySource(String(r.body));
|
|
108
|
+
}
|
|
109
|
+
else if (r.requestBodyType !== undefined)
|
|
110
|
+
fail('carries requestBodyType with no body.');
|
|
111
|
+
const outputs = Array.isArray(data.outputs) ? data.outputs : [];
|
|
112
|
+
const own = outputs.filter((o) => o.custom !== true).map((o) => String(o.name));
|
|
113
|
+
if (own.join(',') !== HTTP_REQUEST_OUTPUTS.map((o) => o.name).join(','))
|
|
114
|
+
fail(`has outputs ${JSON.stringify(own)}; an HTTP request task writes ${HTTP_REQUEST_OUTPUTS.map((o) => o.name).join(', ')}, in that order.`);
|
|
115
|
+
return spec;
|
|
116
|
+
}
|
|
117
|
+
/** One of the activity's own output rows, which compile writes itself; a custom row is never one. */
|
|
118
|
+
export function isHttpRequestOwnOutput(row) {
|
|
119
|
+
return row.custom !== true && HTTP_REQUEST_OUTPUTS.some((o) => o.name === row.name && o.source === row.source);
|
|
120
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* case/decompile-script — the decompile half of the Case `script` task
|
|
3
|
+
* (`./script.ts` holds the shape compile writes). It lifts a saved task's
|
|
4
|
+
* `data` to the `.script()` call that compiles back to it, and throws, naming
|
|
5
|
+
* the field, on anything a recompile would not write back. Decompile-side, so
|
|
6
|
+
* its refusals are plain Errors (FB017 scopes it out by name).
|
|
7
|
+
*
|
|
8
|
+
* The body is lifted as a string, exactly as stored: printing it as a typed
|
|
9
|
+
* function, as Flow's decompile can (`printAsFunction`), is a follow-up.
|
|
10
|
+
*/
|
|
11
|
+
import type { CaseScriptOptions } from './case-sdk.js';
|
|
12
|
+
/** What a script task's `data` lifts to: the body and the schemas the Designer kept on its outputs. */
|
|
13
|
+
export interface LiftedScript {
|
|
14
|
+
body: string;
|
|
15
|
+
options: CaseScriptOptions;
|
|
16
|
+
}
|
|
17
|
+
export declare function liftScript(owner: string, data: Record<string, unknown>): LiftedScript;
|
|
18
|
+
/** One of the task's own output rows, which compile writes itself; a custom row is never one. */
|
|
19
|
+
export declare function isScriptOwnOutput(row: {
|
|
20
|
+
custom?: unknown;
|
|
21
|
+
name?: unknown;
|
|
22
|
+
source?: unknown;
|
|
23
|
+
}): boolean;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SCRIPT_INPUTS, SCRIPT_OUTPUTS, scriptBody } from './script.js';
|
|
2
|
+
/** The output-row fields compile writes, per output; any other is refused. */
|
|
3
|
+
const OWN_FIELDS = new Map([
|
|
4
|
+
['scriptResponse', new Set(['name', 'type', 'source', 'id', 'var', 'value', 'elementId', 'target', 'originalVar', '_jsonSchema'])],
|
|
5
|
+
['Error', new Set(['name', 'displayName', 'type', 'source', 'id', 'var', 'value', 'elementId', 'target', 'originalVar', '_jsonSchema', 'body'])],
|
|
6
|
+
]);
|
|
7
|
+
export function liftScript(owner, data) {
|
|
8
|
+
const fail = (why) => {
|
|
9
|
+
throw new Error(`${owner} ${why}`);
|
|
10
|
+
};
|
|
11
|
+
const unknown = Object.keys(data).find((k) => !['script', 'inputs', 'outputs'].includes(k));
|
|
12
|
+
if (unknown)
|
|
13
|
+
fail(`has unsupported data field "${unknown}".`);
|
|
14
|
+
if (typeof data.script !== 'string')
|
|
15
|
+
fail('has no script body.');
|
|
16
|
+
const inputs = Array.isArray(data.inputs) ? data.inputs : [];
|
|
17
|
+
if (JSON.stringify(inputs) !== JSON.stringify(SCRIPT_INPUTS))
|
|
18
|
+
fail(`has inputs ${JSON.stringify(inputs)}; a script task's are exactly vars = "=vars" and metadata = "=metadata", which compile writes.`);
|
|
19
|
+
const outputs = (Array.isArray(data.outputs) ? data.outputs : []);
|
|
20
|
+
const own = outputs.filter((o) => o.custom !== true);
|
|
21
|
+
if (own.map((o) => `${String(o.name)}:${String(o.source)}`).join(',') !== SCRIPT_OUTPUTS.map((o) => `${o.name}:${o.source}`).join(','))
|
|
22
|
+
fail(`has outputs ${JSON.stringify(own.map((o) => o.name))}; a script task writes scriptResponse (=result.response) and Error (=Error), in that order.`);
|
|
23
|
+
const options = {};
|
|
24
|
+
for (const row of own) {
|
|
25
|
+
const name = String(row.name);
|
|
26
|
+
const fields = OWN_FIELDS.get(name) ?? new Set();
|
|
27
|
+
const odd = Object.keys(row).find((k) => !fields.has(k));
|
|
28
|
+
if (odd)
|
|
29
|
+
fail(`output "${name}" has field "${odd}", which compile does not write.`);
|
|
30
|
+
if (row.type !== 'jsonSchema')
|
|
31
|
+
fail(`output "${name}" has type ${JSON.stringify(row.type)}; it is "jsonSchema".`);
|
|
32
|
+
const schema = row._jsonSchema;
|
|
33
|
+
if (schema !== undefined && (typeof schema !== 'object' || schema === null || Array.isArray(schema)))
|
|
34
|
+
fail(`output "${name}" has a _jsonSchema that is not an object.`);
|
|
35
|
+
if (name === 'scriptResponse' && schema !== undefined)
|
|
36
|
+
options.responseSchema = schema;
|
|
37
|
+
if (name === 'Error') {
|
|
38
|
+
// Compile writes an Error schema as the Designer keeps it: `_jsonSchema`, `body` and `displayName`, together.
|
|
39
|
+
const carried = [schema !== undefined, row.body !== undefined, row.displayName === 'Error'];
|
|
40
|
+
if (carried.some(Boolean) && !carried.every(Boolean))
|
|
41
|
+
fail('output "Error" carries part of a schema; compile writes _jsonSchema, body and displayName together.');
|
|
42
|
+
if (schema !== undefined && JSON.stringify(schema) !== JSON.stringify(row.body))
|
|
43
|
+
fail('output "Error" has a body that is not its _jsonSchema; compile writes the one schema to both.');
|
|
44
|
+
if (schema !== undefined)
|
|
45
|
+
options.errorSchema = schema;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { body: scriptBody(String(data.script)), options };
|
|
49
|
+
}
|
|
50
|
+
/** One of the task's own output rows, which compile writes itself; a custom row is never one. */
|
|
51
|
+
export function isScriptOwnOutput(row) {
|
|
52
|
+
return row.custom !== true && SCRIPT_OUTPUTS.some((o) => o.name === row.name && o.source === row.source);
|
|
53
|
+
}
|
package/dist/case/decompile.d.ts
CHANGED
|
@@ -262,6 +262,12 @@ type Preservation = {
|
|
|
262
262
|
optionalConfiguration: Record<string, unknown>;
|
|
263
263
|
cachedFieldValues: Record<string, unknown>;
|
|
264
264
|
}>;
|
|
265
|
+
httpRequestMetadata?: Array<{
|
|
266
|
+
stage: string;
|
|
267
|
+
lane: number;
|
|
268
|
+
task: string;
|
|
269
|
+
metadata: Record<string, unknown>;
|
|
270
|
+
}>;
|
|
265
271
|
subscriptionFilters?: Array<{
|
|
266
272
|
owner: string;
|
|
267
273
|
expression?: 'inline';
|