Skip to content

Commit a78ddd2

Browse files
authored
New Components - evernote (#15945)
* evernote init * [Components] evernote #15892 Sources - New Note - New Tag - New Notebook Actions - Create Note - Update Note - Create Notebook * pnpm update
1 parent ec6b0b3 commit a78ddd2

File tree

15 files changed

+740
-8
lines changed

15 files changed

+740
-8
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import evernote from "../../evernote.app.mjs";
4+
5+
export default {
6+
key: "evernote-create-note",
7+
name: "Create Note",
8+
description: "Creates a new note in Evernote. [See the documentation](https://dev.evernote.com/doc/reference/NoteStore.html#Fn_NoteStore_createNote)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
evernote,
13+
title: {
14+
type: "string",
15+
label: "Title",
16+
description: "The subject of the note. Can't begin or end with a space.",
17+
},
18+
content: {
19+
type: "string",
20+
label: "Content",
21+
description: "The XHTML block that makes up the note. This is the canonical form of the note's contents, so will include abstract Evernote tags for internal resource references. A client may create a separate transformed version of this content for internal presentation, but the same canonical bytes should be used for transmission and comparison unless the user chooses to modify their content.",
22+
default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note></en-note>",
23+
optional: true,
24+
},
25+
active: {
26+
type: "boolean",
27+
label: "Active",
28+
description: "If the note is available for normal actions and viewing",
29+
optional: true,
30+
},
31+
notebookGuid: {
32+
propDefinition: [
33+
evernote,
34+
"notebookGuid",
35+
],
36+
optional: true,
37+
},
38+
tagGuids: {
39+
propDefinition: [
40+
evernote,
41+
"tagGuids",
42+
],
43+
optional: true,
44+
},
45+
attributes: {
46+
type: "object",
47+
label: "Attributes",
48+
description: "A list of the attributes for this note. [See the documentation](https://dev.evernote.com/doc/reference/Types.html#Struct_NoteAttributes) for further details.",
49+
optional: true,
50+
},
51+
noUpdateTitle: {
52+
type: "boolean",
53+
label: "No Update Title",
54+
description: "The client may not update the note's title.",
55+
optional: true,
56+
},
57+
noUpdateContent: {
58+
type: "boolean",
59+
label: "No Update Content",
60+
description: "The client may not update the note's content. Content includes `content` and `resources`, as well as the related fields `contentHash` and `contentLength`.",
61+
optional: true,
62+
},
63+
noUpdateEmail: {
64+
type: "boolean",
65+
label: "No Update Email",
66+
description: "The client may not email the note.",
67+
optional: true,
68+
},
69+
noUpdateShare: {
70+
type: "boolean",
71+
label: "No Update Share",
72+
description: "The client may not share the note with specific recipients.",
73+
optional: true,
74+
},
75+
noUpdateSharePublicly: {
76+
type: "boolean",
77+
label: "No Update Share Publicly",
78+
description: "The client may not make the note public.",
79+
optional: true,
80+
},
81+
},
82+
async run({ $ }) {
83+
try {
84+
const note = await this.evernote.createNote({
85+
title: this.title,
86+
content: this.content,
87+
active: this.active,
88+
notebookGuid: this.notebookGuid,
89+
tagGuids: this.tagGuids,
90+
resources: this.resources,
91+
attributes: parseObject(this.attributes),
92+
restrictions: {
93+
noUpdateTitle: this.noUpdateTitle,
94+
noUpdateContent: this.noUpdateContent,
95+
noUpdateEmail: this.noUpdateEmail,
96+
noUpdateShare: this.noUpdateShare,
97+
noUpdateSharePublicly: this.noUpdateSharePublicly,
98+
},
99+
});
100+
101+
$.export("$summary", `Created note "${note.title}" with ID ${note.guid}`);
102+
return note;
103+
} catch ({ parameter }) {
104+
throw new ConfigurationError(parameter);
105+
}
106+
},
107+
};
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import evernote from "../../evernote.app.mjs";
4+
5+
export default {
6+
key: "evernote-create-notebook",
7+
name: "Create Notebook",
8+
description: "Creates a new notebook in Evernote. [See the documentation](https://dev.evernote.com/doc/reference/NoteStore.html#Fn_NoteStore_createNotebook)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
evernote,
13+
name: {
14+
type: "string",
15+
label: "Name",
16+
description: "The name of the notebook.",
17+
},
18+
defaultNotebook: {
19+
type: "boolean",
20+
label: "Default Notebook",
21+
description: "If true, this notebook should be used for new notes whenever the user has not (or cannot) specify a desired target notebook.",
22+
optional: true,
23+
},
24+
published: {
25+
type: "boolean",
26+
label: "Published",
27+
description: "If this is set to true, then the Notebook will be accessible either to the public, or for business users to their business, via the 'publishing' or 'businessNotebook' specifications, which must also be set. If this is set to false, the Notebook will not be available to the public (or business).",
28+
optional: true,
29+
reloadProps: true,
30+
},
31+
publishing: {
32+
type: "object",
33+
label: "Publishing",
34+
description: "If the Notebook has been opened for public access, then this will point to the set of publishing information for the Notebook (URI, description, etc.). A Notebook cannot be published without providing this information, but it will persist for later use if publishing is ever disabled on the Notebook. [See the documentation](https://dev.evernote.com/doc/reference/Types.html#Struct_Publishing) for further details.",
35+
hidden: true,
36+
},
37+
stack: {
38+
type: "string",
39+
label: "Stack",
40+
description: "If this is set, then the notebook is visually contained within a stack of notebooks with this name. All notebooks in the same account with the same 'stack' field are considered to be in the same stack. Notebooks with no stack set are \"top level\" and not contained within a stack.",
41+
optional: true,
42+
},
43+
},
44+
async additionalProps(props) {
45+
props.publishing.hidden = !this.published;
46+
47+
return {};
48+
},
49+
async run({ $ }) {
50+
try {
51+
const data = {
52+
name: this.name,
53+
defaultNotebook: this.defaultNotebook,
54+
published: this.published,
55+
stack: this.stack,
56+
};
57+
const publishing = parseObject(this.publishing);
58+
if (publishing) data.publishing = publishing;
59+
const response = await this.evernote.createNotebook({
60+
...data,
61+
});
62+
63+
$.export("$summary", `Created notebook ${response.name} with ID: ${response.guid}`);
64+
return response;
65+
} catch ({ parameter }) {
66+
throw new ConfigurationError(parameter);
67+
}
68+
},
69+
};
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import evernote from "../../evernote.app.mjs";
4+
5+
export default {
6+
key: "evernote-update-note",
7+
name: "Update Note",
8+
description: "Updates an existing note in Evernote. [See the documentation](https://dev.evernote.com/doc/reference/NoteStore.html#Fn_NoteStore_updateNote)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
evernote,
13+
noteId: {
14+
propDefinition: [
15+
evernote,
16+
"noteId",
17+
],
18+
},
19+
title: {
20+
type: "string",
21+
label: "Title",
22+
description: "The subject of the note. Can't begin or end with a space.",
23+
optional: true,
24+
},
25+
content: {
26+
type: "string",
27+
label: "Content",
28+
description: "The XHTML block that makes up the note. This is the canonical form of the note's contents, so will include abstract Evernote tags for internal resource references. A client may create a separate transformed version of this content for internal presentation, but the same canonical bytes should be used for transmission and comparison unless the user chooses to modify their content.",
29+
default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note></en-note>",
30+
optional: true,
31+
},
32+
active: {
33+
type: "boolean",
34+
label: "Active",
35+
description: "If the note is available for normal actions and viewing",
36+
optional: true,
37+
},
38+
notebookGuid: {
39+
propDefinition: [
40+
evernote,
41+
"notebookGuid",
42+
],
43+
optional: true,
44+
},
45+
tagGuids: {
46+
propDefinition: [
47+
evernote,
48+
"tagGuids",
49+
],
50+
optional: true,
51+
},
52+
attributes: {
53+
type: "object",
54+
label: "Attributes",
55+
description: "A list of the attributes for this note. [See the documentation](https://dev.evernote.com/doc/reference/Types.html#Struct_NoteAttributes) for further details.",
56+
optional: true,
57+
},
58+
noUpdateTitle: {
59+
type: "boolean",
60+
label: "No Update Title",
61+
description: "The client may not update the note's title.",
62+
optional: true,
63+
},
64+
noUpdateContent: {
65+
type: "boolean",
66+
label: "No Update Content",
67+
description: "The client may not update the note's content. Content includes `content` and `resources`, as well as the related fields `contentHash` and `contentLength`.",
68+
optional: true,
69+
},
70+
noUpdateEmail: {
71+
type: "boolean",
72+
label: "No Update Email",
73+
description: "The client may not email the note.",
74+
optional: true,
75+
},
76+
noUpdateShare: {
77+
type: "boolean",
78+
label: "No Update Share",
79+
description: "The client may not share the note with specific recipients.",
80+
optional: true,
81+
},
82+
noUpdateSharePublicly: {
83+
type: "boolean",
84+
label: "No Update Share Publicly",
85+
description: "The client may not make the note public.",
86+
optional: true,
87+
},
88+
},
89+
async run({ $ }) {
90+
try {
91+
const response = await this.evernote.updateNote({
92+
guid: this.noteId,
93+
title: this.title,
94+
content: this.content,
95+
active: this.active,
96+
notebookGuid: this.notebookGuid,
97+
tagGuids: this.tagGuids,
98+
resources: this.resources,
99+
attributes: parseObject(this.attributes),
100+
restrictions: {
101+
noUpdateTitle: this.noUpdateTitle,
102+
noUpdateContent: this.noUpdateContent,
103+
noUpdateEmail: this.noUpdateEmail,
104+
noUpdateShare: this.noUpdateShare,
105+
noUpdateSharePublicly: this.noUpdateSharePublicly,
106+
},
107+
});
108+
$.export("$summary", `Note ${this.noteId} updated successfully.`);
109+
return response;
110+
} catch ({
111+
parameter, message,
112+
}) {
113+
throw new ConfigurationError(message || parameter);
114+
}
115+
},
116+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 100;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)