@uipath/maestro-builder-sdk 6.79.1 → 6.80.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 +39 -36
- package/dist/api-members.md +193 -181
- package/dist/case/case-sdk.d.ts +78 -1
- package/dist/case/case-sdk.js +28 -1
- package/dist/case/check.js +9 -0
- package/dist/case/decompile-http-request.d.ts +29 -0
- package/dist/case/decompile-http-request.js +120 -0
- package/dist/case/decompile.d.ts +6 -0
- package/dist/case/decompile.js +23 -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/preserve.d.ts +11 -0
- package/dist/case/preserve.js +6 -0
- package/dist/case/serialize.js +105 -0
- package/dist/core/refusals.d.ts +10 -0
- package/dist/core/refusals.js +13 -0
- package/package.json +2 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* case/http-request — the Case `http-request` task: a call through Integration
|
|
3
|
+
* Service's generic HTTP connector, in the shape the Case Designer saves.
|
|
4
|
+
*
|
|
5
|
+
* Read from three alpha Designer saves (2026-10-13, UiPath/cli
|
|
6
|
+
* `packages/case-tool/tests/fixtures/http-request/designer-saved.json`) and the
|
|
7
|
+
* CLI's writer for them, `sdd convert` (`services/sdd-convert/http-request.ts`
|
|
8
|
+
* at UiPath/cli b37f32997c), which was read from PO.Frontend 35d579f94.
|
|
9
|
+
*
|
|
10
|
+
* The task is always the HTTP connector's own activity (`uipath-uipath-http`,
|
|
11
|
+
* `POST /http-request`, the fixed identity in `core/managed-http.ts` that Flow
|
|
12
|
+
* and BPMN share). What a person configures is the request, which rides in the
|
|
13
|
+
* `body` input's `body`: `authentication`, `method`, `url` (manual) or `path`
|
|
14
|
+
* (connector), `headers`, `query`, `body`. Two modes:
|
|
15
|
+
* - manual: the request goes to `url` as written, with no connection; the task
|
|
16
|
+
* names the plan's one `ImplicitConnection` binding;
|
|
17
|
+
* - connector: the request reuses a connection's authentication
|
|
18
|
+
* (`targetConnector`), and `path` is relative to that connector's base URL.
|
|
19
|
+
* The task carries the connection's `ConnectionId` and `folderKey`
|
|
20
|
+
* bindings, which are also at the root.
|
|
21
|
+
*
|
|
22
|
+
* Its refusals follow the check/compile contract: {@link httpRequestRefusal} is
|
|
23
|
+
* what compile cannot write as authored (`lowering`), and `serialize` throws
|
|
24
|
+
* it; {@link httpRequestLint} is what compile writes as authored and only
|
|
25
|
+
* `check` reports (`lint`).
|
|
26
|
+
*/
|
|
27
|
+
import type { CaseHttpRequestSpec, HttpRequestMethod, TaskOutputBinding } from './case-sdk.js';
|
|
28
|
+
/**
|
|
29
|
+
* The Designer's `metadata` context entry body, copied byte for byte from
|
|
30
|
+
* UiPath/cli `packages/case-tool/src/services/sdd-convert/http-request-metadata.json`
|
|
31
|
+
* (last changed in 06c4c1d01f, 2026-10-15; read at b37f32997c). It is the
|
|
32
|
+
* activity's configuration as Studio Web saves it; Studio Web reads it to show
|
|
33
|
+
* the task, so it is copied rather than rebuilt. `case-http-request.test.ts`
|
|
34
|
+
* pins its hash, and its activity identity to `core/managed-http.ts`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const HTTP_REQUEST_METADATA: Readonly<Record<string, unknown>>;
|
|
37
|
+
export declare const HTTP_REQUEST_METADATA_PROVENANCE: {
|
|
38
|
+
readonly repo: "UiPath/cli";
|
|
39
|
+
readonly path: "packages/case-tool/src/services/sdd-convert/http-request-metadata.json";
|
|
40
|
+
readonly commit: "06c4c1d01f1bcb0a196902aea0f9508d6cbf85f3";
|
|
41
|
+
readonly sha256: "b2a15368b204e5189d6aab1bfc1ea1db2a16e47710920025a43649f858388785";
|
|
42
|
+
};
|
|
43
|
+
export declare const HTTP_REQUEST_SERVICE_TYPE = "Intsvc.UnifiedHttpRequest";
|
|
44
|
+
/** The plan's one binding a manual request names: no resource, so no `bindings_v2.json` entry. */
|
|
45
|
+
export declare const HTTP_REQUEST_IMPLICIT_CONNECTION = "ImplicitConnection";
|
|
46
|
+
export declare const HTTP_REQUEST_IMPLICIT_BINDING_ID = "bHttpImplicit";
|
|
47
|
+
export declare const HTTP_REQUEST_CONNECTION_NAME = "uipath-uipath-http connection";
|
|
48
|
+
/** The methods the activity offers. */
|
|
49
|
+
export declare const HTTP_REQUEST_METHODS: readonly HttpRequestMethod[];
|
|
50
|
+
/** The activity's four outputs, in the order the Designer saves them: `[name, id base, source]`. */
|
|
51
|
+
export declare const HTTP_REQUEST_OUTPUTS: readonly [{
|
|
52
|
+
readonly name: "code";
|
|
53
|
+
readonly base: "code";
|
|
54
|
+
readonly displayName: "Response status code";
|
|
55
|
+
readonly type: "number";
|
|
56
|
+
readonly source: "=response.code";
|
|
57
|
+
}, {
|
|
58
|
+
readonly name: "headers";
|
|
59
|
+
readonly base: "headers";
|
|
60
|
+
readonly displayName: "Response headers";
|
|
61
|
+
readonly type: "object";
|
|
62
|
+
readonly source: "=response.headers";
|
|
63
|
+
}, {
|
|
64
|
+
readonly name: "body";
|
|
65
|
+
readonly base: "body";
|
|
66
|
+
readonly displayName: "Response body";
|
|
67
|
+
readonly type: "object";
|
|
68
|
+
readonly source: "=response.body";
|
|
69
|
+
}, {
|
|
70
|
+
readonly name: "Error";
|
|
71
|
+
readonly base: "error";
|
|
72
|
+
readonly displayName: "Error";
|
|
73
|
+
readonly type: "jsonSchema";
|
|
74
|
+
readonly source: "=Error";
|
|
75
|
+
}];
|
|
76
|
+
/** A refusal `check`, `serialize` and `decompile` raise alike. */
|
|
77
|
+
export interface HttpRequestRefusal {
|
|
78
|
+
code: string;
|
|
79
|
+
message: string;
|
|
80
|
+
suggestion?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Why compile cannot write `spec` as authored, or `undefined`: the request's
|
|
84
|
+
* `lowering` refusals (`docs/CHECK_COMPILE_CONTRACT_DESIGN.md` §3.1), each a
|
|
85
|
+
* case where the serializer would drop or rewrite what the source says.
|
|
86
|
+
* `serialize` throws it; `check` gets it through collect mode.
|
|
87
|
+
*
|
|
88
|
+
* @param owner - The task as messages name it, e.g. `HTTP request task "Fetch"`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function httpRequestRefusal(owner: string, spec: CaseHttpRequestSpec): HttpRequestRefusal | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* What `check` says about a request compile writes as authored: the `lint`
|
|
93
|
+
* findings (§3.1), each an error a person should fix and `compile` does not
|
|
94
|
+
* look for.
|
|
95
|
+
*
|
|
96
|
+
* @param owner - The task as messages name it, e.g. `HTTP request task "Fetch"`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function httpRequestLint(owner: string, spec: CaseHttpRequestSpec): HttpRequestRefusal[];
|
|
99
|
+
/**
|
|
100
|
+
* The request as the activity reads it from the `body` input, in the CLI's key
|
|
101
|
+
* order. A literal body is wrapped the way the Designer's editor wraps one,
|
|
102
|
+
* `=js:( … )`, with `requestBodyType: "raw"` in manual mode; an object body's
|
|
103
|
+
* `=` values are written as the JavaScript they stand for ({@link bodyLiteral});
|
|
104
|
+
* an expression body is kept as written.
|
|
105
|
+
*/
|
|
106
|
+
export declare function httpRequestBody(spec: CaseHttpRequestSpec): Record<string, unknown>;
|
|
107
|
+
/**
|
|
108
|
+
* The body as source writes it: the JSON text a `=js:( … )` body wraps, or the
|
|
109
|
+
* value itself, which compile writes as it stands, when it is an expression or
|
|
110
|
+
* wraps something other than JSON (an object body whose `=` values were
|
|
111
|
+
* written as JavaScript).
|
|
112
|
+
*/
|
|
113
|
+
export declare function httpRequestBodySource(value: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Which of the activity's outputs an `.outputs()` row writes to a case
|
|
116
|
+
* variable: its `source` must be one of the four, once each.
|
|
117
|
+
*/
|
|
118
|
+
export declare function httpRequestOutputMappings(owner: string, outputs: readonly TaskOutputBinding[] | undefined): Map<string, string> | HttpRequestRefusal;
|
|
119
|
+
/**
|
|
120
|
+
* The task's four output rows. `claim` gives each a document-unique id (the
|
|
121
|
+
* Designer's `code`, `code2`, … rule); a mapped output writes the case variable
|
|
122
|
+
* the author named instead, keeping its own id as `originalVar`, as the CLI does
|
|
123
|
+
* for an arrow row (`Body -> payload`).
|
|
124
|
+
*/
|
|
125
|
+
export declare function httpRequestOutputs(elementId: string, claim: (base: string) => string, mappings: ReadonlyMap<string, string>): Record<string, unknown>[];
|
|
126
|
+
/** A container input, with the `v` id the Designer writes (minted by the caller). */
|
|
127
|
+
export declare function httpRequestInputs(elementId: string, mint: (name: string) => string, request: Record<string, unknown>): Record<string, unknown>[];
|
|
128
|
+
/** The context rows, in the Designer's order; `connection` is a binding reference. */
|
|
129
|
+
export declare function httpRequestContext(connection: string, resourceKey: string | null, folderKey: string | null): Record<string, unknown>[];
|
|
130
|
+
/**
|
|
131
|
+
* The `metadata` body a saved http-request task carries when it is not the
|
|
132
|
+
* vendored copy compile writes (a Designer save from another connector
|
|
133
|
+
* version), or undefined. Decompile preserves it, so a round trip keeps the
|
|
134
|
+
* version the Designer saved instead of writing `HTTP_REQUEST_METADATA`.
|
|
135
|
+
*/
|
|
136
|
+
export declare function savedHttpRequestMetadata(data: unknown): Record<string, unknown> | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Write a preserved `metadata` body over the one compile wrote. False when
|
|
139
|
+
* `data` has no `metadata` row (the task is no longer an http-request task).
|
|
140
|
+
*/
|
|
141
|
+
export declare function writeHttpRequestMetadata(data: unknown, metadata: Record<string, unknown>): boolean;
|
|
142
|
+
/** The context row names, in order: decompile lifts exactly these. */
|
|
143
|
+
export declare const HTTP_REQUEST_CONTEXT: readonly string[];
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { MANAGED_HTTP_CONNECTOR_KEY, MANAGED_HTTP_ENDPOINT, MANAGED_HTTP_ENDPOINT_METHOD, MANAGED_HTTP_OBJECT_NAME, } from '../core/managed-http.js';
|
|
2
|
+
import { taskOutputRefs } from './task-output-ref.js';
|
|
3
|
+
import metadata from './http-request-metadata.json' with { type: 'json' };
|
|
4
|
+
/**
|
|
5
|
+
* The Designer's `metadata` context entry body, copied byte for byte from
|
|
6
|
+
* UiPath/cli `packages/case-tool/src/services/sdd-convert/http-request-metadata.json`
|
|
7
|
+
* (last changed in 06c4c1d01f, 2026-10-15; read at b37f32997c). It is the
|
|
8
|
+
* activity's configuration as Studio Web saves it; Studio Web reads it to show
|
|
9
|
+
* the task, so it is copied rather than rebuilt. `case-http-request.test.ts`
|
|
10
|
+
* pins its hash, and its activity identity to `core/managed-http.ts`.
|
|
11
|
+
*/
|
|
12
|
+
export const HTTP_REQUEST_METADATA = metadata;
|
|
13
|
+
export const HTTP_REQUEST_METADATA_PROVENANCE = {
|
|
14
|
+
repo: 'UiPath/cli',
|
|
15
|
+
path: 'packages/case-tool/src/services/sdd-convert/http-request-metadata.json',
|
|
16
|
+
commit: '06c4c1d01f1bcb0a196902aea0f9508d6cbf85f3',
|
|
17
|
+
sha256: 'b2a15368b204e5189d6aab1bfc1ea1db2a16e47710920025a43649f858388785',
|
|
18
|
+
};
|
|
19
|
+
export const HTTP_REQUEST_SERVICE_TYPE = 'Intsvc.UnifiedHttpRequest';
|
|
20
|
+
/** The plan's one binding a manual request names: no resource, so no `bindings_v2.json` entry. */
|
|
21
|
+
export const HTTP_REQUEST_IMPLICIT_CONNECTION = 'ImplicitConnection';
|
|
22
|
+
export const HTTP_REQUEST_IMPLICIT_BINDING_ID = 'bHttpImplicit';
|
|
23
|
+
export const HTTP_REQUEST_CONNECTION_NAME = `${MANAGED_HTTP_CONNECTOR_KEY} connection`;
|
|
24
|
+
/** The methods the activity offers. */
|
|
25
|
+
export const HTTP_REQUEST_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
|
|
26
|
+
/** The methods the activity sends a body with; it clears the body for the rest. */
|
|
27
|
+
const BODY_METHODS = new Set(['POST', 'PUT', 'PATCH']);
|
|
28
|
+
/**
|
|
29
|
+
* Headers that carry a credential. A header value is written into the plan as
|
|
30
|
+
* authored, and the plan is committed, packed and pulled, so a credential there
|
|
31
|
+
* has leaked. The GA skill's rule and grader use this list (`check_http_request_case.py`).
|
|
32
|
+
*/
|
|
33
|
+
const CREDENTIAL_HEADERS = new Set(['authorization', 'proxy-authorization', 'cookie', 'x-api-key', 'api-key']);
|
|
34
|
+
/**
|
|
35
|
+
* Query parameter names that carry a credential, in lower case. The query is
|
|
36
|
+
* written into the plan with the request, so a key here ships like a header.
|
|
37
|
+
*/
|
|
38
|
+
const CREDENTIAL_QUERY_KEYS = new Set([
|
|
39
|
+
'api_key', 'apikey', 'api-key', 'access_token', 'token', 'key', 'secret', 'client_secret', 'password', 'sig', 'signature',
|
|
40
|
+
]);
|
|
41
|
+
/** The activity's four outputs, in the order the Designer saves them: `[name, id base, source]`. */
|
|
42
|
+
export const HTTP_REQUEST_OUTPUTS = [
|
|
43
|
+
{ name: 'code', base: 'code', displayName: 'Response status code', type: 'number', source: '=response.code' },
|
|
44
|
+
{ name: 'headers', base: 'headers', displayName: 'Response headers', type: 'object', source: '=response.headers' },
|
|
45
|
+
{ name: 'body', base: 'body', displayName: 'Response body', type: 'object', source: '=response.body' },
|
|
46
|
+
{ name: 'Error', base: 'error', displayName: 'Error', type: 'jsonSchema', source: '=Error' },
|
|
47
|
+
];
|
|
48
|
+
/** The `Error` output's schema, as the Designer and the CLI write it. */
|
|
49
|
+
const ERROR_SCHEMA = {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
code: { type: 'string' }, message: { type: 'string' }, detail: { type: 'string' },
|
|
53
|
+
category: { type: 'string' }, status: { type: 'number' }, element: { type: 'string' },
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const isObjectOfText = (value) => typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
57
|
+
&& Object.values(value).every((v) => typeof v === 'string');
|
|
58
|
+
/**
|
|
59
|
+
* Why compile cannot write `spec` as authored, or `undefined`: the request's
|
|
60
|
+
* `lowering` refusals (`docs/CHECK_COMPILE_CONTRACT_DESIGN.md` §3.1), each a
|
|
61
|
+
* case where the serializer would drop or rewrite what the source says.
|
|
62
|
+
* `serialize` throws it; `check` gets it through collect mode.
|
|
63
|
+
*
|
|
64
|
+
* @param owner - The task as messages name it, e.g. `HTTP request task "Fetch"`.
|
|
65
|
+
*/
|
|
66
|
+
export function httpRequestRefusal(owner, spec) {
|
|
67
|
+
const connector = spec.connector;
|
|
68
|
+
if (connector !== undefined) {
|
|
69
|
+
// Nothing to bind the connection through.
|
|
70
|
+
const missing = ['key', 'connection', 'folder'].filter((k) => typeof connector[k] !== 'string' || !connector[k].trim());
|
|
71
|
+
if (missing.length)
|
|
72
|
+
return {
|
|
73
|
+
code: 'HTTP_REQUEST_CONNECTOR',
|
|
74
|
+
message: `${owner} reuses a connector's authentication but has no ${missing.join(', ')}.`,
|
|
75
|
+
suggestion: "Pass connector: { key: '<connector key>', connection: '<connection binding>', folder: '<folder binding>' }, or drop connector to call url directly.",
|
|
76
|
+
};
|
|
77
|
+
// A connector request is written with `path`, so a `url` would be dropped.
|
|
78
|
+
if (spec.url !== undefined)
|
|
79
|
+
return {
|
|
80
|
+
code: 'HTTP_REQUEST_TARGET',
|
|
81
|
+
message: `${owner} calls through a connector, which reads a path relative to the connector's base URL, so its url would be dropped.`,
|
|
82
|
+
suggestion: `Write the address as path (for example path: '/rest/api/3/myself'), or drop connector to call url directly.`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else if (spec.path !== undefined) {
|
|
86
|
+
// A request without a connector is written with `url`, so a `path` would be dropped.
|
|
87
|
+
return {
|
|
88
|
+
code: 'HTTP_REQUEST_TARGET',
|
|
89
|
+
message: `${owner} has path, which only a connector request reads, so it would be dropped; a request without a connector calls url.`,
|
|
90
|
+
suggestion: 'Put the full address in url, or add connector: { key, connection, folder }.',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Written by spreading the object, which would scramble anything but an object of text.
|
|
94
|
+
for (const [field, value] of [['headers', spec.headers], ['query', spec.query]])
|
|
95
|
+
if (value !== undefined && !isObjectOfText(value))
|
|
96
|
+
return { code: 'HTTP_REQUEST_FIELD', message: `${owner} ${field} must be an object of text values.` };
|
|
97
|
+
// Text that is neither JSON nor an expression would be wrapped as `=js:( … )`,
|
|
98
|
+
// which the activity evaluates: compile would turn the author's text into code.
|
|
99
|
+
if (typeof spec.body === 'string' && !spec.body.startsWith('=') && !parsesAsJson(spec.body))
|
|
100
|
+
return {
|
|
101
|
+
code: 'HTTP_REQUEST_BODY_FORM',
|
|
102
|
+
message: `${owner} body is neither JSON nor an \`=\` expression. The activity evaluates its body as JavaScript, so the text would be written as code.`,
|
|
103
|
+
suggestion: 'Pass the body as an object, JSON text, or an expression such as `=js:vars.payload`.',
|
|
104
|
+
};
|
|
105
|
+
if (spec.body !== undefined && typeof spec.body !== 'string') {
|
|
106
|
+
const leaf = unlowerableLeaf(spec.body);
|
|
107
|
+
if (leaf !== undefined)
|
|
108
|
+
return {
|
|
109
|
+
code: 'HTTP_REQUEST_BODY_EXPRESSION',
|
|
110
|
+
message: `${owner} body has the value ${JSON.stringify(leaf)}, an \`=\` expression compile cannot write as a JavaScript value inside the body.`,
|
|
111
|
+
suggestion: "Write the value as `=js:<expression>` (for example '=js:vars.amount * 2'), as a reference (`=vars.amount`), "
|
|
112
|
+
+ "or as another task's output (`=${taskOutput('Stage', 'Task', 'body')}`).",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const parsesAsJson = (text) => {
|
|
118
|
+
try {
|
|
119
|
+
JSON.parse(text);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/** A dotted reference such as `vars.customer.id`: JavaScript as written. */
|
|
127
|
+
const REFERENCE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/;
|
|
128
|
+
/** Property reads after a reference: `.field.sub`. */
|
|
129
|
+
const DOTTED_TAIL = /^(?:\.[A-Za-z_$][\w$]*)*$/;
|
|
130
|
+
/**
|
|
131
|
+
* Whether `text` is exactly one `taskOutput()` marker (`vars.$xref('S','T','body')`),
|
|
132
|
+
* optionally followed by property reads. It is a reference once lowered: the
|
|
133
|
+
* whole plan's markers are lowered to `vars.<output id>` after the body is
|
|
134
|
+
* written (`lowerPlanTaskOutputRefs` in `serialize.ts`), so the activity never
|
|
135
|
+
* sees `$xref`.
|
|
136
|
+
*/
|
|
137
|
+
function isTaskOutputReference(text) {
|
|
138
|
+
const refs = taskOutputRefs(text);
|
|
139
|
+
return refs.length === 1 && refs[0].index === 0 && DOTTED_TAIL.test(text.slice(refs[0].whole.length));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The JavaScript an `=` leaf of an object body stands for: `=js:<code>` is the
|
|
143
|
+
* code, parenthesized; `=<reference>` is the reference, a `taskOutput()`
|
|
144
|
+
* marker included. `undefined` for any other `=` text, which compile refuses
|
|
145
|
+
* (`HTTP_REQUEST_BODY_EXPRESSION`).
|
|
146
|
+
*/
|
|
147
|
+
function leafCode(value) {
|
|
148
|
+
if (value.startsWith('=js:')) {
|
|
149
|
+
const code = value.slice('=js:'.length).trim();
|
|
150
|
+
return code === '' ? undefined : `(${code})`;
|
|
151
|
+
}
|
|
152
|
+
const reference = value.slice(1).trim();
|
|
153
|
+
return REFERENCE.test(reference) || isTaskOutputReference(reference) ? reference : undefined;
|
|
154
|
+
}
|
|
155
|
+
const isExpressionLeaf = (value) => typeof value === 'string' && value.startsWith('=');
|
|
156
|
+
const childrenOf = (value) => Array.isArray(value) ? value : typeof value === 'object' && value !== null ? Object.values(value) : [];
|
|
157
|
+
function hasExpressionLeaf(value) {
|
|
158
|
+
return isExpressionLeaf(value) || childrenOf(value).some(hasExpressionLeaf);
|
|
159
|
+
}
|
|
160
|
+
/** The first `=` leaf compile cannot lower, or `undefined`. */
|
|
161
|
+
function unlowerableLeaf(value) {
|
|
162
|
+
if (isExpressionLeaf(value))
|
|
163
|
+
return leafCode(value) === undefined ? value : undefined;
|
|
164
|
+
for (const child of childrenOf(value)) {
|
|
165
|
+
const found = unlowerableLeaf(child);
|
|
166
|
+
if (found !== undefined)
|
|
167
|
+
return found;
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* An object body as the JavaScript literal the activity evaluates. Without an
|
|
173
|
+
* `=` leaf it is exactly `JSON.stringify`. An `=` leaf is written as the code it
|
|
174
|
+
* stands for (`{"probe":vars.id}`), so the request carries the value, not the
|
|
175
|
+
* expression's text. Keys are JSON-quoted; `__proto__` is computed, because a
|
|
176
|
+
* plain `"__proto__":` key would set the prototype instead of a field.
|
|
177
|
+
*/
|
|
178
|
+
function bodyLiteral(value) {
|
|
179
|
+
if (!hasExpressionLeaf(value))
|
|
180
|
+
return JSON.stringify(value);
|
|
181
|
+
if (isExpressionLeaf(value)) {
|
|
182
|
+
const code = leafCode(value);
|
|
183
|
+
if (code === undefined)
|
|
184
|
+
throw new Error(`internal SDK error: body value ${JSON.stringify(value)} reached the writer unrefused`);
|
|
185
|
+
return code;
|
|
186
|
+
}
|
|
187
|
+
if (Array.isArray(value))
|
|
188
|
+
return `[${value.map((item) => (item === undefined ? 'null' : bodyLiteral(item))).join(',')}]`;
|
|
189
|
+
const entries = Object.entries(value).filter(([, item]) => item !== undefined);
|
|
190
|
+
return `{${entries.map(([key, item]) => `${key === '__proto__' ? '["__proto__"]' : JSON.stringify(key)}:${bodyLiteral(item)}`).join(',')}}`;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* What `check` says about a request compile writes as authored: the `lint`
|
|
194
|
+
* findings (§3.1), each an error a person should fix and `compile` does not
|
|
195
|
+
* look for.
|
|
196
|
+
*
|
|
197
|
+
* @param owner - The task as messages name it, e.g. `HTTP request task "Fetch"`.
|
|
198
|
+
*/
|
|
199
|
+
export function httpRequestLint(owner, spec) {
|
|
200
|
+
const found = [];
|
|
201
|
+
if (!HTTP_REQUEST_METHODS.includes(spec.method))
|
|
202
|
+
found.push({ code: 'HTTP_REQUEST_METHOD', message: `${owner} has method ${JSON.stringify(spec.method)}; the activity offers ${HTTP_REQUEST_METHODS.join(', ')}.` });
|
|
203
|
+
if (spec.connector === undefined && (typeof spec.url !== 'string' || !spec.url.trim()))
|
|
204
|
+
found.push({
|
|
205
|
+
code: 'HTTP_REQUEST_NO_URL',
|
|
206
|
+
message: `${owner} names no connector, so it calls url directly, and has none.`,
|
|
207
|
+
suggestion: "Pass url (for example url: 'https://api.example.com/items'), or connector: { key, connection, folder } with a path.",
|
|
208
|
+
});
|
|
209
|
+
// A literal value is the secret itself, written into the plan; an `=` value is read at run time.
|
|
210
|
+
const literalCredential = (fields, names) => Object.entries(isObjectOfText(fields) ? fields : {}).find(([k, v]) => names.has(k.toLowerCase()) && !v.startsWith('='))?.[0];
|
|
211
|
+
const credentials = [
|
|
212
|
+
['header', literalCredential(spec.headers, CREDENTIAL_HEADERS)],
|
|
213
|
+
['query parameter', literalCredential(spec.query, CREDENTIAL_QUERY_KEYS)],
|
|
214
|
+
];
|
|
215
|
+
for (const [where, name] of credentials)
|
|
216
|
+
if (name !== undefined)
|
|
217
|
+
found.push({
|
|
218
|
+
code: 'HTTP_REQUEST_CREDENTIAL_HEADER',
|
|
219
|
+
message: `${owner} sends a "${name}" ${where}. Its value is written into the case plan as authored, so the credential `
|
|
220
|
+
+ 'ships in caseplan.case and in every pull and package of it.',
|
|
221
|
+
suggestion: 'Authenticate through a connection instead: connector: { key, connection, folder } reuses that connector\'s stored credential.',
|
|
222
|
+
});
|
|
223
|
+
if (spec.body !== undefined && !BODY_METHODS.has(spec.method))
|
|
224
|
+
found.push({
|
|
225
|
+
code: 'HTTP_REQUEST_BODY_METHOD',
|
|
226
|
+
message: `${owner} sends a body with ${spec.method}, which the activity sends without one: it clears the body.`,
|
|
227
|
+
suggestion: 'Use POST, PUT or PATCH to send a body, or drop body.',
|
|
228
|
+
});
|
|
229
|
+
return found;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The request as the activity reads it from the `body` input, in the CLI's key
|
|
233
|
+
* order. A literal body is wrapped the way the Designer's editor wraps one,
|
|
234
|
+
* `=js:( … )`, with `requestBodyType: "raw"` in manual mode; an object body's
|
|
235
|
+
* `=` values are written as the JavaScript they stand for ({@link bodyLiteral});
|
|
236
|
+
* an expression body is kept as written.
|
|
237
|
+
*/
|
|
238
|
+
export function httpRequestBody(spec) {
|
|
239
|
+
const body = { authentication: spec.connector ? 'connector' : 'manual' };
|
|
240
|
+
if (spec.connector)
|
|
241
|
+
body.targetConnector = spec.connector.key;
|
|
242
|
+
body.method = spec.method;
|
|
243
|
+
if (spec.connector && spec.path !== undefined)
|
|
244
|
+
body.path = spec.path;
|
|
245
|
+
if (!spec.connector && spec.url !== undefined)
|
|
246
|
+
body.url = spec.url;
|
|
247
|
+
if (spec.headers !== undefined)
|
|
248
|
+
body.headers = { ...spec.headers };
|
|
249
|
+
if (spec.query !== undefined)
|
|
250
|
+
body.query = { ...spec.query };
|
|
251
|
+
if (spec.body !== undefined) {
|
|
252
|
+
if (!spec.connector)
|
|
253
|
+
body.requestBodyType = 'raw';
|
|
254
|
+
const text = typeof spec.body === 'string' ? spec.body : bodyLiteral(spec.body);
|
|
255
|
+
body.body = text.startsWith('=') ? text : `=js:( ${text})`;
|
|
256
|
+
}
|
|
257
|
+
return body;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The body as source writes it: the JSON text a `=js:( … )` body wraps, or the
|
|
261
|
+
* value itself, which compile writes as it stands, when it is an expression or
|
|
262
|
+
* wraps something other than JSON (an object body whose `=` values were
|
|
263
|
+
* written as JavaScript).
|
|
264
|
+
*/
|
|
265
|
+
export function httpRequestBodySource(value) {
|
|
266
|
+
const wrapped = /^=js:\( ([\s\S]*)\)$/.exec(value);
|
|
267
|
+
return wrapped && parsesAsJson(wrapped[1]) ? wrapped[1] : value;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Which of the activity's outputs an `.outputs()` row writes to a case
|
|
271
|
+
* variable: its `source` must be one of the four, once each.
|
|
272
|
+
*/
|
|
273
|
+
export function httpRequestOutputMappings(owner, outputs) {
|
|
274
|
+
const bySource = new Map();
|
|
275
|
+
for (const o of outputs ?? []) {
|
|
276
|
+
// A custom `{ assign }` row reads no result: it is written beside the four, as on every kind.
|
|
277
|
+
if (o.custom)
|
|
278
|
+
continue;
|
|
279
|
+
const known = HTTP_REQUEST_OUTPUTS.find((row) => row.source === o.source);
|
|
280
|
+
if (known === undefined)
|
|
281
|
+
return {
|
|
282
|
+
code: 'HTTP_REQUEST_OUTPUT',
|
|
283
|
+
message: `${owner} output "${o.var}" reads ${JSON.stringify(o.source)}; an HTTP request has the activity's outputs only: `
|
|
284
|
+
+ `${HTTP_REQUEST_OUTPUTS.map((row) => row.source).join(', ')}.`,
|
|
285
|
+
suggestion: 'Map one of those to a case variable, for example .outputs({ reply: \'=response.body\' }), and read a field of the body as reply.<field>.',
|
|
286
|
+
};
|
|
287
|
+
if (bySource.has(o.source))
|
|
288
|
+
return { code: 'HTTP_REQUEST_OUTPUT', message: `${owner} writes ${o.source} to two variables, "${bySource.get(o.source)}" and "${o.var}".` };
|
|
289
|
+
bySource.set(o.source, o.var);
|
|
290
|
+
}
|
|
291
|
+
return bySource;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The task's four output rows. `claim` gives each a document-unique id (the
|
|
295
|
+
* Designer's `code`, `code2`, … rule); a mapped output writes the case variable
|
|
296
|
+
* the author named instead, keeping its own id as `originalVar`, as the CLI does
|
|
297
|
+
* for an arrow row (`Body -> payload`).
|
|
298
|
+
*/
|
|
299
|
+
export function httpRequestOutputs(elementId, claim, mappings) {
|
|
300
|
+
return HTTP_REQUEST_OUTPUTS.map((row) => {
|
|
301
|
+
const id = claim(row.base);
|
|
302
|
+
const variable = mappings.get(row.source);
|
|
303
|
+
const out = {
|
|
304
|
+
name: row.name, displayName: row.displayName, type: row.type, source: row.source,
|
|
305
|
+
...(row.name === 'Error' ? { _jsonSchema: structuredClone(ERROR_SCHEMA) } : {}),
|
|
306
|
+
id, var: variable ?? id, value: variable ?? id, elementId,
|
|
307
|
+
...(row.name === 'Error' ? { body: structuredClone(ERROR_SCHEMA) } : {}),
|
|
308
|
+
};
|
|
309
|
+
if (variable !== undefined) {
|
|
310
|
+
out.target = `=${id}`;
|
|
311
|
+
out.originalVar = id;
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** A container input, with the `v` id the Designer writes (minted by the caller). */
|
|
317
|
+
export function httpRequestInputs(elementId, mint, request) {
|
|
318
|
+
return ['pathParameters', 'queryParameters', 'body'].map((name) => {
|
|
319
|
+
const id = mint(name);
|
|
320
|
+
return { name, type: 'json', target: name, id, var: id, elementId, ...(name === 'body' ? { body: request } : {}) };
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/** The context rows, in the Designer's order; `connection` is a binding reference. */
|
|
324
|
+
export function httpRequestContext(connection, resourceKey, folderKey) {
|
|
325
|
+
const row = (name, value) => ({ name, value, type: 'string' });
|
|
326
|
+
return [
|
|
327
|
+
row('connectorKey', MANAGED_HTTP_CONNECTOR_KEY),
|
|
328
|
+
row('connection', connection),
|
|
329
|
+
row('resourceKey', resourceKey),
|
|
330
|
+
row('folderKey', folderKey),
|
|
331
|
+
row('method', MANAGED_HTTP_ENDPOINT_METHOD),
|
|
332
|
+
row('path', MANAGED_HTTP_ENDPOINT),
|
|
333
|
+
row('objectName', MANAGED_HTTP_OBJECT_NAME),
|
|
334
|
+
{ name: 'metadata', type: 'json', body: structuredClone(HTTP_REQUEST_METADATA) },
|
|
335
|
+
row('activityConfigurationVersion', 'v2'),
|
|
336
|
+
];
|
|
337
|
+
}
|
|
338
|
+
/** A task `data`'s `metadata` context row, or undefined. */
|
|
339
|
+
const metadataRow = (data) => {
|
|
340
|
+
const context = data?.context;
|
|
341
|
+
return Array.isArray(context)
|
|
342
|
+
? context.find((row) => row?.name === 'metadata' && row?.type === 'json')
|
|
343
|
+
: undefined;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* The `metadata` body a saved http-request task carries when it is not the
|
|
347
|
+
* vendored copy compile writes (a Designer save from another connector
|
|
348
|
+
* version), or undefined. Decompile preserves it, so a round trip keeps the
|
|
349
|
+
* version the Designer saved instead of writing `HTTP_REQUEST_METADATA`.
|
|
350
|
+
*/
|
|
351
|
+
export function savedHttpRequestMetadata(data) {
|
|
352
|
+
const body = metadataRow(data)?.body;
|
|
353
|
+
if (typeof body !== 'object' || body === null || Array.isArray(body))
|
|
354
|
+
return undefined;
|
|
355
|
+
return JSON.stringify(body) === JSON.stringify(HTTP_REQUEST_METADATA) ? undefined : body;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Write a preserved `metadata` body over the one compile wrote. False when
|
|
359
|
+
* `data` has no `metadata` row (the task is no longer an http-request task).
|
|
360
|
+
*/
|
|
361
|
+
export function writeHttpRequestMetadata(data, metadata) {
|
|
362
|
+
const row = metadataRow(data);
|
|
363
|
+
if (!row)
|
|
364
|
+
return false;
|
|
365
|
+
row.body = structuredClone(metadata);
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
/** The context row names, in order: decompile lifts exactly these. */
|
|
369
|
+
export const HTTP_REQUEST_CONTEXT = [
|
|
370
|
+
'connectorKey', 'connection', 'resourceKey', 'folderKey', 'method', 'path', 'objectName', 'metadata', 'activityConfigurationVersion',
|
|
371
|
+
];
|
package/dist/case/preserve.d.ts
CHANGED
|
@@ -87,6 +87,11 @@ export interface PreservedConnectorConfiguration extends PreservedTaskRef {
|
|
|
87
87
|
*/
|
|
88
88
|
cachedFieldValues?: Record<string, unknown>;
|
|
89
89
|
}
|
|
90
|
+
/** An HTTP request task's saved `metadata` context body, verbatim. */
|
|
91
|
+
export interface PreservedHttpRequestMetadata extends PreservedTaskRef {
|
|
92
|
+
/** The body as the Designer saved it. */
|
|
93
|
+
metadata: Record<string, unknown>;
|
|
94
|
+
}
|
|
90
95
|
/**
|
|
91
96
|
* The stage `data` fields the Case Designer owns: canvas nesting state and the
|
|
92
97
|
* primary-stage marker. None changes what the case does (the platform's
|
|
@@ -321,6 +326,12 @@ export interface CaseJsonPreservation {
|
|
|
321
326
|
taskFields?: PreservedTaskFields[];
|
|
322
327
|
/** Designer-saved connector `optionalConfiguration`s, by task. */
|
|
323
328
|
connectorConfigurations?: PreservedConnectorConfiguration[];
|
|
329
|
+
/**
|
|
330
|
+
* HTTP request tasks' Designer-saved `metadata` bodies, where they differ from
|
|
331
|
+
* the vendored copy compile writes (`HTTP_REQUEST_METADATA`), so a save from
|
|
332
|
+
* another connector version is written back instead of downgraded.
|
|
333
|
+
*/
|
|
334
|
+
httpRequestMetadata?: PreservedHttpRequestMetadata[];
|
|
324
335
|
/**
|
|
325
336
|
* Action tasks' Designer-owned `data` fields: the `context` rows the Designer
|
|
326
337
|
* saves with a form (its `hitlType`, quick-form schema ids, and a copy of the
|
package/dist/case/preserve.js
CHANGED
|
@@ -385,6 +385,12 @@ export function caseJsonPreservationErrors(payload) {
|
|
|
385
385
|
&& (!entry.cachedFieldValues || typeof entry.cachedFieldValues !== 'object' || Array.isArray(entry.cachedFieldValues)))
|
|
386
386
|
errors.push(`preserved connector configuration of task "${entry.task}" has cachedFieldValues that is not an object`);
|
|
387
387
|
}
|
|
388
|
+
for (const entry of payload.httpRequestMetadata ?? []) {
|
|
389
|
+
if (!Number.isInteger(entry?.lane) || entry.lane < 0)
|
|
390
|
+
errors.push(`preserved http-request metadata lane "${entry?.lane}" is not a non-negative integer`);
|
|
391
|
+
if (!entry?.metadata || typeof entry.metadata !== 'object' || Array.isArray(entry.metadata))
|
|
392
|
+
errors.push(`preserved http-request metadata of task "${entry?.task}" must be an object`);
|
|
393
|
+
}
|
|
388
394
|
for (const index of payload.manualTriggerServiceTypeNone ?? [])
|
|
389
395
|
if (!Number.isInteger(index) || index < 0)
|
|
390
396
|
errors.push(`manual trigger position "${index}" is not a non-negative integer`);
|