Skip to content

Commit 8381c8e

Browse files
committed
updates
1 parent f07d31b commit 8381c8e

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

components/sanity/actions/create-document/create-document.mjs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sanity from "../../sanity.app.mjs";
2-
import { ConfigurationError } from "@pipedream/platform";
32
import { parseObject } from "../../common/utils.mjs";
43

54
export default {
@@ -21,32 +20,37 @@ export default {
2120
"dataset",
2221
],
2322
},
24-
publishId: {
23+
documentId: {
2524
type: "string",
26-
label: "Publish ID",
27-
description: "The publish ID of the document to create",
25+
label: "Document ID",
26+
description: "A unique identifier for the document to create",
2827
},
29-
document: {
28+
type: {
29+
type: "string",
30+
label: "Type",
31+
description: "The type of document to create. Example: `post`",
32+
},
33+
additionalFields: {
3034
type: "object",
31-
label: "Document",
32-
description: "The document to create. Must include `_type` and `_id` fields. Example: `{\"_type\":\"post\",\"_id\":\"drafts.post-123\",\"title\":\"My First Post\",\"slug\":{\"current\":\"my-first-post\"},\"body\":[{\"_type\":\"block\",\"children\":[{\"_type\":\"span\",\"text\":\"Hello world!\"}]}]}`",
35+
label: "Additional Fields",
36+
description: "Additional fields to add to the document. Example: `{\"title\":\"My First Post\",\"slug\":{\"current\":\"my-first-post\"},\"body\":[{\"_type\":\"block\",\"children\":[{\"_type\":\"span\",\"text\":\"Hello world!\"}]}]}`",
37+
optional: true,
3338
},
3439
},
3540
async run({ $ }) {
36-
const document = parseObject(this.document);
37-
if (!document._type || !document._id) {
38-
throw new ConfigurationError("Document must include `_type` and `_id` fields");
39-
}
40-
4141
const response = await this.sanity.createDocument({
4242
$,
4343
dataset: this.dataset,
4444
data: {
4545
actions: [
4646
{
4747
actionType: "sanity.action.document.create",
48-
publishedId: this.publishId,
49-
document,
48+
publishedId: this.documentId,
49+
document: {
50+
_id: `drafts.${this.documentId}`,
51+
_type: this.type,
52+
...parseObject(this.additionalFields),
53+
},
5054
},
5155
],
5256
},

0 commit comments

Comments
 (0)