Skip to content

Commit 666f736

Browse files
committed
updates
1 parent 2cd9e3e commit 666f736

File tree

4 files changed

+158
-30
lines changed

4 files changed

+158
-30
lines changed

components/ironclad/actions/create-record/create-record.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default {
6565
? "boolean"
6666
: "string",
6767
label: properties[property].displayName,
68+
description: properties[property].description ?? `Value of ${properties[property].displayName}`,
6869
};
6970
}
7071
return props;

components/ironclad/actions/launch-workflow/launch-workflow.mjs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import ironclad from "../../ironclad.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import {
4+
getAttributeDescription, parseValue,
5+
} from "../../common/utils.mjs";
26

37
export default {
48
key: "ironclad-launch-workflow",
@@ -28,22 +32,28 @@ export default {
2832
key,
2933
value,
3034
] of Object.entries(schema)) {
31-
if (!value.readOnly && value?.type !== "document" && value?.elementType?.type !== "document") {
35+
if (!value.readOnly) {
3236
props[key] = {
3337
type: value.type === "boolean"
3438
? "boolean"
3539
: value.type === "array"
3640
? "string[]"
3741
: "string",
3842
label: value.displayName,
39-
optional: !(key === "counterpartyName"),
43+
description: getAttributeDescription(value),
44+
optional: (!(key === "counterpartyName") && !value.displayName.toLowerCase().includes("required")),
4045
};
4146
if (key === "paperSource") {
4247
props[key].options = [
4348
"Counterparty paper",
4449
"Our paper",
4550
];
4651
}
52+
if (key === "recordType") {
53+
const { recordTypes } = await this.ironclad.getRecordsSchema();
54+
props[key].options = Object.values(recordTypes)
55+
.map((recordType) => recordType.displayName);
56+
}
4757
}
4858
}
4959
return props;
@@ -55,16 +65,37 @@ export default {
5565
...attributes
5666
} = this;
5767

58-
const response = await ironclad.launchWorkflow({
59-
$,
60-
data: {
61-
template: templateId,
62-
attributes: {
63-
...attributes,
68+
const parsedAttributes = {};
69+
for (const [
70+
key,
71+
value,
72+
] of Object.entries(attributes)) {
73+
parsedAttributes[key] = parseValue(value);
74+
}
75+
76+
try {
77+
const response = await ironclad.launchWorkflow({
78+
$,
79+
params: {
80+
useDefaultValues: true,
6481
},
65-
},
66-
});
67-
$.export("$summary", `Workflow launched successfully with ID ${response.id}`);
68-
return response;
82+
data: {
83+
template: templateId,
84+
attributes: parsedAttributes,
85+
},
86+
});
87+
$.export("$summary", `Workflow launched successfully with ID ${response.id}`);
88+
return response;
89+
} catch (error) {
90+
const msg = JSON.parse(error.message);
91+
if (msg.code === "MISSING_PARAM") {
92+
const { schema } = await this.ironclad.getWorkflowSchema({
93+
templateId: this.templateId,
94+
});
95+
const paramNames = (JSON.parse(msg.param)).map((p) => `\`${schema[p].displayName}\``);
96+
throw new ConfigurationError(`Please enter or update the following required parameters: ${paramNames.join(", ")}`);
97+
}
98+
throw new ConfigurationError(msg.message);
99+
}
69100
},
70101
};

components/ironclad/actions/update-workflow/update-workflow.mjs

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import ironclad from "../../ironclad.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import {
4+
getAttributeDescription, parseValue,
5+
} from "../../common/utils.mjs";
26

37
export default {
48
key: "ironclad-update-workflow",
@@ -34,16 +38,23 @@ export default {
3438
key,
3539
value,
3640
] of Object.entries(schema)) {
37-
if (!value?.readOnly && value?.type !== "document" && value?.elementType?.type !== "document") {
41+
if (!value?.readOnly) {
3842
props[key] = {
3943
type: value.type === "boolean"
4044
? "boolean"
4145
: value.type === "array"
4246
? "string[]"
4347
: "string",
4448
label: value.displayName,
49+
description: getAttributeDescription(value),
4550
optional: true,
4651
};
52+
if (key === "paperSource") {
53+
props[key].options = [
54+
"Counterparty paper",
55+
"Our paper",
56+
];
57+
}
4758
}
4859
}
4960
return props;
@@ -55,22 +66,43 @@ export default {
5566
comment,
5667
...attributes
5768
} = this;
58-
const response = await ironclad.updateWorkflowMetadata({
59-
$,
60-
workflowId: workflowId,
61-
data: {
62-
updates: attributes && Object.entries(attributes).map(([
63-
key,
64-
value,
65-
]) => ({
66-
action: "set",
67-
path: key,
68-
value,
69-
})),
70-
comment: comment,
71-
},
72-
});
73-
$.export("$summary", `Workflow ${workflowId} updated successfully`);
74-
return response;
69+
70+
const parsedAttributes = {};
71+
for (const [
72+
key,
73+
value,
74+
] of Object.entries(attributes)) {
75+
parsedAttributes[key] = parseValue(value);
76+
}
77+
78+
try {
79+
const response = await ironclad.updateWorkflowMetadata({
80+
$,
81+
workflowId: workflowId,
82+
data: {
83+
updates: Object.entries(parsedAttributes).map(([
84+
key,
85+
value,
86+
]) => ({
87+
action: "set",
88+
path: key,
89+
value,
90+
})),
91+
comment: comment,
92+
},
93+
});
94+
$.export("$summary", `Workflow ${workflowId} updated successfully`);
95+
return response;
96+
} catch (error) {
97+
const msg = JSON.parse(error.message);
98+
if (msg.code === "MISSING_PARAM") {
99+
const { schema } = await this.ironclad.getWorkflowSchema({
100+
templateId: this.templateId,
101+
});
102+
const paramNames = (JSON.parse(msg.param)).map((p) => `\`${schema[p].displayName}\``);
103+
throw new ConfigurationError(`Please enter or update the following required parameters: ${paramNames.join(", ")}`);
104+
}
105+
throw new ConfigurationError(msg.message);
106+
}
75107
},
76108
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export function getAttributeDescription({
2+
type, displayName, elementType,
3+
}) {
4+
const description = `Value of ${displayName}`;
5+
if (type === "address") {
6+
return `${description}. Example: \`{
7+
"lines": [
8+
"325 5th Street",
9+
"Suite 200"
10+
],
11+
"locality": "San Francisco",
12+
"region": "California",
13+
"postcode": "94107",
14+
"country": "USA"
15+
}\``;
16+
}
17+
if (type === "monetaryAmount") {
18+
return `${description}. Example: \`{
19+
"currency": "USD",
20+
"amount": 25.37
21+
}\``;
22+
}
23+
if (type === "date") {
24+
return `${description}. Example: \`2021-05-11T17:16:53-07:00\``;
25+
}
26+
if (type === "duration") {
27+
return `${description}. Example \`{
28+
"years": 1,
29+
"months": 2,
30+
"weeks": 3,
31+
"days": 4
32+
}\``;
33+
}
34+
if (type === "email") {
35+
return `${description}. Example: \`[email protected]\``;
36+
}
37+
if (type === "array") {
38+
if (elementType.type === "document") {
39+
return `${description}. Array of type \`${elementType.type}\`. Example: \`{"url": "https://your.file.server.test/test-doc-1.docx"}\``;
40+
}
41+
if (elementType.type === "object") {
42+
return `${description}. Array of type \`${elementType.type}\`. See the [docs](https://developer.ironcladapp.com/docs/launch-a-workflow#32-create-request-body-attributes) for more information about field types.`;
43+
}
44+
return `${description}. Array of type \`${elementType.type}\`.`;
45+
}
46+
return description;
47+
}
48+
49+
export function parseValue(value) {
50+
if (!value) {
51+
return undefined;
52+
}
53+
try {
54+
if (typeof value === "string") {
55+
return JSON.parse(value);
56+
}
57+
if (Array.isArray(value)) {
58+
return value.map(JSON.parse);
59+
}
60+
return value;
61+
} catch {
62+
return value;
63+
}
64+
}

0 commit comments

Comments
 (0)