Skip to content

Commit 4cfcfc6

Browse files
New Components - grain (#14685)
* grain init * [Components] grain #14678 Sources - New Highlight (Instant) - New Story (Instant) - New Recording (Instant) - Updated Highlight (Instant) - Updated Story (Instant) - Updated Recording (Instant) - Deleted Highlight (Instant) - Deleted Story (Instant) - Deleted Recording (Instant) Actions - Get Recording * pnpm update * Update components/grain/grain.app.mjs Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com> * Update components/grain/sources/common/base.mjs Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com> * fix pnpm * pnpm update * Update components/grain/sources/common/base.mjs Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com> * Update components/grain/actions/get-recording/get-recording.mjs Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com> --------- Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com>
1 parent 15cbf13 commit 4cfcfc6

File tree

30 files changed

+705
-12
lines changed

30 files changed

+705
-12
lines changed

components/amazon_selling_partner/amazon_selling_partner.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/bigdatacorp/bigdatacorp.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/checkout_com/checkout_com.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
INTELLIGENCE_NOTES_FORMAT_OPTIONS,
3+
TRANSCRIPT_FORMAT_OPTIONS,
4+
} from "../../common/constants.mjs";
5+
import { parseObject } from "../../common/utils.mjs";
6+
import grain from "../../grain.app.mjs";
7+
8+
export default {
9+
key: "grain-get-recording",
10+
name: "Get Recording",
11+
description: "Fetches a specific recording by its ID from Grain, optionally including the transcript and intelligence notes. [See the documentation](https://grainhq.notion.site/grain-public-api-877184aa82b54c77a875083c1b560de9)",
12+
version: "0.0.1",
13+
type: "action",
14+
props: {
15+
grain,
16+
recordId: {
17+
propDefinition: [
18+
grain,
19+
"recordId",
20+
],
21+
},
22+
transcriptFormat: {
23+
type: "string",
24+
label: "Transcript Format",
25+
description: "Format for the transcript",
26+
options: TRANSCRIPT_FORMAT_OPTIONS,
27+
optional: true,
28+
},
29+
intelligenceNotesFormat: {
30+
type: "string",
31+
label: "Intelligence Notes Format",
32+
description: "Format for the intelligence notes",
33+
options: INTELLIGENCE_NOTES_FORMAT_OPTIONS,
34+
optional: true,
35+
},
36+
allowedIntelligenceNotes: {
37+
type: "string[]",
38+
label: "Allowed Intelligence Notes",
39+
description: "Whitelist of intelligence notes section titles",
40+
optional: true,
41+
},
42+
},
43+
async run({ $ }) {
44+
const response = await this.grain.fetchRecording({
45+
$,
46+
recordId: this.recordId,
47+
params: {
48+
transcript_format: this.transcriptFormat,
49+
intelligence_notes_format: this.intelligenceNotesFormat,
50+
allowed_intelligence_notes: parseObject(this.allowedIntelligenceNotes),
51+
},
52+
});
53+
54+
$.export("$summary", `Successfully fetched recording with ID ${this.recordId}`);
55+
return response;
56+
},
57+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const TRANSCRIPT_FORMAT_OPTIONS = [
2+
{
3+
label: "JSON",
4+
value: "json",
5+
},
6+
{
7+
label: "VTT",
8+
value: "vtt",
9+
},
10+
];
11+
12+
export const INTELLIGENCE_NOTES_FORMAT_OPTIONS = [
13+
{
14+
label: "JSON",
15+
value: "json",
16+
},
17+
{
18+
label: "Markdown",
19+
value: "md",
20+
},
21+
{
22+
label: "Text",
23+
value: "text",
24+
},
25+
];

components/grain/common/utils.mjs

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+
};

components/grain/grain.app.mjs

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,113 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "grain",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
recordId: {
8+
type: "string",
9+
label: "Record ID",
10+
description: "The ID of the recording to fetch",
11+
async options({ prevContext: { nextPage } }) {
12+
const {
13+
recordings, cursor,
14+
} = await this.listRecordings({
15+
params: {
16+
cursor: nextPage,
17+
},
18+
});
19+
return {
20+
options: recordings.map(({
21+
id: value, title: label,
22+
}) => ({
23+
value,
24+
label,
25+
})),
26+
context: {
27+
nextPage: cursor,
28+
},
29+
};
30+
},
31+
},
32+
viewId: {
33+
type: "string",
34+
label: "View ID",
35+
description: "The ID of the view to fetch",
36+
async options({
37+
type, prevContext: { nextPage },
38+
}) {
39+
const {
40+
views, cursor,
41+
} = await this.listViews({
42+
params: {
43+
type_filter: type,
44+
cursor: nextPage,
45+
},
46+
});
47+
return {
48+
options: views.map(({
49+
id: value, name: label,
50+
}) => ({
51+
value,
52+
label,
53+
})),
54+
context: {
55+
nextPage: cursor,
56+
},
57+
};
58+
},
59+
},
60+
},
561
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
62+
_baseUrl() {
63+
return "https://grain.com/_/public-api";
64+
},
65+
_headers() {
66+
return {
67+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
68+
};
69+
},
70+
_makeRequest({
71+
$ = this, path, ...opts
72+
}) {
73+
return axios($, {
74+
url: this._baseUrl() + path,
75+
headers: this._headers(),
76+
...opts,
77+
});
78+
},
79+
listRecordings(opts = {}) {
80+
return this._makeRequest({
81+
path: "/recordings",
82+
...opts,
83+
});
84+
},
85+
listViews(opts = {}) {
86+
return this._makeRequest({
87+
path: "/views",
88+
...opts,
89+
});
90+
},
91+
fetchRecording({
92+
recordId, ...opts
93+
}) {
94+
return this._makeRequest({
95+
path: `/recordings/${recordId}`,
96+
...opts,
97+
});
98+
},
99+
createWebhook(opts = {}) {
100+
return this._makeRequest({
101+
method: "POST",
102+
path: "/hooks",
103+
...opts,
104+
});
105+
},
106+
deleteWebhook(hookId) {
107+
return this._makeRequest({
108+
method: "DELETE",
109+
path: `/hooks/${hookId}`,
110+
});
9111
},
10112
},
11113
};

components/grain/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/grain",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Grain Components",
55
"main": "grain.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import grain from "../../grain.app.mjs";
2+
3+
export default {
4+
props: {
5+
grain,
6+
http: "$.interface.http",
7+
db: "$.service.db",
8+
},
9+
methods: {
10+
_getHookId() {
11+
return this.db.get("hookId");
12+
},
13+
_setHookId(hookId) {
14+
this.db.set("hookId", hookId);
15+
},
16+
},
17+
hooks: {
18+
async activate() {
19+
const response = await this.grain.createWebhook({
20+
data: {
21+
version: 2,
22+
hook_url: this.http.endpoint,
23+
view_id: this.viewId,
24+
actions: this.getAction(),
25+
},
26+
});
27+
this._setHookId(response.id);
28+
},
29+
async deactivate() {
30+
const webhookId = this._getHookId();
31+
await this.grain.deleteWebhook(webhookId);
32+
},
33+
},
34+
async run({ body }) {
35+
if (!body.data) return;
36+
37+
const ts = Date.parse(new Date());
38+
this.$emit(body, {
39+
id: `${body.data.id}-${ts}`,
40+
summary: this.getSummary(body),
41+
ts,
42+
});
43+
},
44+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "grain-new-highlight-instant",
7+
name: "New Highlight (Instant)",
8+
description: "Emit new event when a highlight that matches the filter is added.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
...common.props,
14+
viewId: {
15+
propDefinition: [
16+
common.props.grain,
17+
"viewId",
18+
() => ({
19+
type: "highlights",
20+
}),
21+
],
22+
},
23+
},
24+
methods: {
25+
...common.methods,
26+
getAction() {
27+
return [
28+
"added",
29+
];
30+
},
31+
getSummary({ data }) {
32+
return `New highlight added: ${data.id}`;
33+
},
34+
},
35+
sampleEmit,
36+
};

0 commit comments

Comments
 (0)