From 5e9e754b075334797b2241dfc606f9b72a3cb07a Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Tue, 2 Dec 2025 09:06:03 -0800 Subject: [PATCH 1/5] new slab components --- .../slab/actions/get-posts/get-posts.mjs | 67 ++++++++++ .../slab/actions/list-posts/list-posts.mjs | 111 +++++++++++++++++ .../actions/search-posts/search-posts.mjs | 116 ++++++++++++++++++ components/slab/package.json | 5 +- components/slab/slab.app.mjs | 105 +++++++++++++++- 5 files changed, 399 insertions(+), 5 deletions(-) create mode 100644 components/slab/actions/get-posts/get-posts.mjs create mode 100644 components/slab/actions/list-posts/list-posts.mjs create mode 100644 components/slab/actions/search-posts/search-posts.mjs diff --git a/components/slab/actions/get-posts/get-posts.mjs b/components/slab/actions/get-posts/get-posts.mjs new file mode 100644 index 0000000000000..0f0b953b95e85 --- /dev/null +++ b/components/slab/actions/get-posts/get-posts.mjs @@ -0,0 +1,67 @@ +import slab from "../../slab.app.mjs"; + +export default { + key: "slab-get-posts", + name: "Get Posts", + description: "Get posts by ID. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.posts)", + version: "0.0.1", + type: "action", + props: { + slab, + postIds: { + type: "string[]", + label: "Post IDs", + description: "Select one or more posts to retrieve", + options: async function({ prevContext }) { + return this.slab.listPostsForOptions({ + cursor: prevContext?.cursor, + }); + }, + }, + }, + async run({ $ }) { + const query = ` + query GetPosts($ids: [ID!]!) { + posts(ids: $ids) { + id + title + linkAccess + archivedAt + publishedAt + insertedAt + updatedAt + version + content + banner { + original + thumb + preset + } + owner { + id + name + email + } + topics { + id + name + } + } + } + `; + const variables = { + ids: this.postIds, + }; + const response = await this.slab._makeRequest({ + $, + data: { + query, + variables, + }, + }); + const posts = response.posts || []; + $.export("$summary", `Successfully retrieved ${posts.length} post(s)`); + return posts; + }, +}; + diff --git a/components/slab/actions/list-posts/list-posts.mjs b/components/slab/actions/list-posts/list-posts.mjs new file mode 100644 index 0000000000000..5f3ef13ad49ba --- /dev/null +++ b/components/slab/actions/list-posts/list-posts.mjs @@ -0,0 +1,111 @@ +import slab from "../../slab.app.mjs"; + +export default { + key: "slab-list-posts", + name: "List Posts", + description: "List posts in the organization. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.search)", + version: "0.0.1", + type: "action", + props: { + slab, + first: { + propDefinition: [ + slab, + "first", + ], + }, + after: { + propDefinition: [ + slab, + "after", + ], + }, + last: { + propDefinition: [ + slab, + "last", + ], + }, + before: { + propDefinition: [ + slab, + "before", + ], + }, + }, + async run({ $ }) { + const query = ` + query ListPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) { + search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) { + edges { + node { + ... on PostSearchResult { + title + highlight + content + post { + id + title + linkAccess + archivedAt + publishedAt + insertedAt + updatedAt + version + content + banner { + original + thumb + preset + } + owner { + id + name + email + } + topics { + id + name + } + } + } + } + cursor + } + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + } + } + `; + const variables = { + query: "", + ...(this.first && { first: parseInt(this.first) }), + ...(this.after && { after: this.after }), + ...(this.last && { last: parseInt(this.last) }), + ...(this.before && { before: this.before }), + }; + const response = await this.slab._makeRequest({ + $, + data: { + query, + variables, + }, + }); + const edges = response.search?.edges || []; + const posts = edges + .map((edge) => edge.node?.post) + .filter(Boolean); + const pageInfo = response.search?.pageInfo || {}; + $.export("$summary", `Successfully retrieved ${posts.length} post(s)`); + return { + posts, + pageInfo, + edges, + }; + }, +}; + diff --git a/components/slab/actions/search-posts/search-posts.mjs b/components/slab/actions/search-posts/search-posts.mjs new file mode 100644 index 0000000000000..d1fff11a7517f --- /dev/null +++ b/components/slab/actions/search-posts/search-posts.mjs @@ -0,0 +1,116 @@ +import slab from "../../slab.app.mjs"; + +export default { + key: "slab-search-posts", + name: "Search Posts", + description: "Search for posts based on query. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.search)", + version: "0.0.1", + type: "action", + props: { + slab, + query: { + type: "string", + label: "Query", + description: "Search query string", + }, + first: { + propDefinition: [ + slab, + "first", + ], + }, + after: { + propDefinition: [ + slab, + "after", + ], + }, + last: { + propDefinition: [ + slab, + "last", + ], + }, + before: { + propDefinition: [ + slab, + "before", + ], + }, + }, + async run({ $ }) { + const query = ` + query SearchPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) { + search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) { + edges { + node { + ... on PostSearchResult { + title + highlight + content + post { + id + title + linkAccess + archivedAt + publishedAt + insertedAt + updatedAt + version + content + banner { + original + thumb + preset + } + owner { + id + name + email + } + topics { + id + name + } + } + } + } + cursor + } + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + } + } + `; + const variables = { + query: this.query, + ...(this.first && { first: parseInt(this.first) }), + ...(this.after && { after: this.after }), + ...(this.last && { last: parseInt(this.last) }), + ...(this.before && { before: this.before }), + }; + const response = await this.slab._makeRequest({ + $, + data: { + query, + variables, + }, + }); + const edges = response.search?.edges || []; + const posts = edges + .map((edge) => edge.node?.post) + .filter(Boolean); + const pageInfo = response.search?.pageInfo || {}; + $.export("$summary", `Successfully found ${posts.length} post(s) matching "${this.query}"`); + return { + posts, + pageInfo, + edges, + }; + }, +}; + diff --git a/components/slab/package.json b/components/slab/package.json index 9f5cd3a7f748a..4d0adb2dfee44 100644 --- a/components/slab/package.json +++ b/components/slab/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/slab", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Slab Components", "main": "slab.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } \ No newline at end of file diff --git a/components/slab/slab.app.mjs b/components/slab/slab.app.mjs index 6c0ed067b2546..7f2f9dd4f0f6d 100644 --- a/components/slab/slab.app.mjs +++ b/components/slab/slab.app.mjs @@ -1,11 +1,108 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "slab", - propDefinitions: {}, + propDefinitions: { + first: { + type: "string", + label: "First", + description: "Number of items to retrieve when paginating forwards", + optional: true, + }, + after: { + type: "string", + label: "After", + description: "Cursor to continue pagination forwards", + optional: true, + }, + last: { + type: "string", + label: "Last", + description: "Number of items to retrieve when paginating backwards", + optional: true, + }, + before: { + type: "string", + label: "Before", + description: "Cursor to continue pagination backwards", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.slab.com/v1/graphql"; + }, + _getHeaders() { + return { + "Content-Type": "application/json", + "authorization": `${this.$auth.api_token}`, + }; + }, + async _makeRequest({ + $ = this, + ...opts + }) { + const config = { + method: "POST", + url: this._baseUrl(), + headers: this._getHeaders(), + ...opts, + }; + const response = await axios($, config); + if (response.data?.errors?.length) { + throw new Error(`GraphQL Error: ${response.data.errors[0].message}`); + } + return response.data || response; + }, + async listPostsForOptions({ + cursor, + }) { + const query = ` + query ListPosts($after: String, $first: Int) { + search(query: "", types: [POST], after: $after, first: $first) { + edges { + node { + ... on PostSearchResult { + post { + id + title + } + } + } + } + pageInfo { + hasNextPage + endCursor + } + } + } + `; + const variables = { + first: 20, + ...(cursor && { after: cursor }), + }; + const response = await this._makeRequest({ + data: { + query, + variables, + }, + }); + const edges = response.search?.edges || []; + const options = edges + .map((edge) => edge.node?.post) + .filter(Boolean) + .map((post) => ({ + label: post.title, + value: post.id, + })); + const pageInfo = response.search?.pageInfo || {}; + return { + options, + context: { + cursor: pageInfo.hasNextPage ? pageInfo.endCursor : undefined, + }, + }; }, }, }; \ No newline at end of file From ec1bc975d11bf7136bbbe7bc5f3cc2768cb91bd7 Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Tue, 2 Dec 2025 10:04:18 -0800 Subject: [PATCH 2/5] updated pnpm-lock --- pnpm-lock.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e3bbf0b93d14a..36486a0dccbea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13819,7 +13819,11 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/slab: {} + components/slab: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.1 components/slack: dependencies: @@ -31703,17 +31707,17 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.2.2: resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==} From edda732fd0800cb7e5ada231bcc155664e4bb2b0 Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Tue, 2 Dec 2025 10:25:56 -0800 Subject: [PATCH 3/5] fixing lints --- .../slab/actions/get-posts/get-posts.mjs | 5 +++++ .../slab/actions/list-posts/list-posts.mjs | 21 +++++++++++++++---- .../actions/search-posts/search-posts.mjs | 21 +++++++++++++++---- components/slab/package.json | 2 +- components/slab/slab.app.mjs | 14 +++++++------ 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/components/slab/actions/get-posts/get-posts.mjs b/components/slab/actions/get-posts/get-posts.mjs index 0f0b953b95e85..2091c568784f4 100644 --- a/components/slab/actions/get-posts/get-posts.mjs +++ b/components/slab/actions/get-posts/get-posts.mjs @@ -6,6 +6,11 @@ export default { description: "Get posts by ID. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.posts)", version: "0.0.1", type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, props: { slab, postIds: { diff --git a/components/slab/actions/list-posts/list-posts.mjs b/components/slab/actions/list-posts/list-posts.mjs index 5f3ef13ad49ba..db1472acfa615 100644 --- a/components/slab/actions/list-posts/list-posts.mjs +++ b/components/slab/actions/list-posts/list-posts.mjs @@ -5,6 +5,11 @@ export default { name: "List Posts", description: "List posts in the organization. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.search)", version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, type: "action", props: { slab, @@ -83,10 +88,18 @@ export default { `; const variables = { query: "", - ...(this.first && { first: parseInt(this.first) }), - ...(this.after && { after: this.after }), - ...(this.last && { last: parseInt(this.last) }), - ...(this.before && { before: this.before }), + ...(this.first && { + first: parseInt(this.first), + }), + ...(this.after && { + after: this.after, + }), + ...(this.last && { + last: parseInt(this.last), + }), + ...(this.before && { + before: this.before, + }), }; const response = await this.slab._makeRequest({ $, diff --git a/components/slab/actions/search-posts/search-posts.mjs b/components/slab/actions/search-posts/search-posts.mjs index d1fff11a7517f..e19db670f9013 100644 --- a/components/slab/actions/search-posts/search-posts.mjs +++ b/components/slab/actions/search-posts/search-posts.mjs @@ -5,6 +5,11 @@ export default { name: "Search Posts", description: "Search for posts based on query. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.search)", version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, type: "action", props: { slab, @@ -88,10 +93,18 @@ export default { `; const variables = { query: this.query, - ...(this.first && { first: parseInt(this.first) }), - ...(this.after && { after: this.after }), - ...(this.last && { last: parseInt(this.last) }), - ...(this.before && { before: this.before }), + ...(this.first && { + first: parseInt(this.first), + }), + ...(this.after && { + after: this.after, + }), + ...(this.last && { + last: parseInt(this.last), + }), + ...(this.before && { + before: this.before, + }), }; const response = await this.slab._makeRequest({ $, diff --git a/components/slab/package.json b/components/slab/package.json index 4d0adb2dfee44..84dcd679ca10b 100644 --- a/components/slab/package.json +++ b/components/slab/package.json @@ -15,4 +15,4 @@ "dependencies": { "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/slab/slab.app.mjs b/components/slab/slab.app.mjs index 7f2f9dd4f0f6d..60b509efcf539 100644 --- a/components/slab/slab.app.mjs +++ b/components/slab/slab.app.mjs @@ -55,9 +55,7 @@ export default { } return response.data || response; }, - async listPostsForOptions({ - cursor, - }) { + async listPostsForOptions({ cursor }) { const query = ` query ListPosts($after: String, $first: Int) { search(query: "", types: [POST], after: $after, first: $first) { @@ -80,7 +78,9 @@ export default { `; const variables = { first: 20, - ...(cursor && { after: cursor }), + ...(cursor && { + after: cursor, + }), }; const response = await this._makeRequest({ data: { @@ -100,9 +100,11 @@ export default { return { options, context: { - cursor: pageInfo.hasNextPage ? pageInfo.endCursor : undefined, + cursor: pageInfo.hasNextPage + ? pageInfo.endCursor + : undefined, }, }; }, }, -}; \ No newline at end of file +}; From dc68933e91ce541ee730e76ec7cd90d0a980b880 Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Tue, 2 Dec 2025 13:12:03 -0800 Subject: [PATCH 4/5] moved graphql queries to /common folder --- .../slab/actions/list-posts/list-posts.mjs | 49 +------------------ .../actions/search-posts/search-posts.mjs | 49 +------------------ 2 files changed, 4 insertions(+), 94 deletions(-) diff --git a/components/slab/actions/list-posts/list-posts.mjs b/components/slab/actions/list-posts/list-posts.mjs index db1472acfa615..07c53e8ad7ab9 100644 --- a/components/slab/actions/list-posts/list-posts.mjs +++ b/components/slab/actions/list-posts/list-posts.mjs @@ -1,4 +1,5 @@ import slab from "../../slab.app.mjs"; +import { LIST_POSTS_QUERY } from "../../common/queries.mjs"; export default { key: "slab-list-posts", @@ -39,53 +40,7 @@ export default { }, }, async run({ $ }) { - const query = ` - query ListPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) { - search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) { - edges { - node { - ... on PostSearchResult { - title - highlight - content - post { - id - title - linkAccess - archivedAt - publishedAt - insertedAt - updatedAt - version - content - banner { - original - thumb - preset - } - owner { - id - name - email - } - topics { - id - name - } - } - } - } - cursor - } - pageInfo { - hasNextPage - hasPreviousPage - startCursor - endCursor - } - } - } - `; + const query = LIST_POSTS_QUERY; const variables = { query: "", ...(this.first && { diff --git a/components/slab/actions/search-posts/search-posts.mjs b/components/slab/actions/search-posts/search-posts.mjs index e19db670f9013..190395f689092 100644 --- a/components/slab/actions/search-posts/search-posts.mjs +++ b/components/slab/actions/search-posts/search-posts.mjs @@ -1,4 +1,5 @@ import slab from "../../slab.app.mjs"; +import { SEARCH_POSTS_QUERY } from "../../common/queries.mjs"; export default { key: "slab-search-posts", @@ -44,53 +45,7 @@ export default { }, }, async run({ $ }) { - const query = ` - query SearchPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) { - search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) { - edges { - node { - ... on PostSearchResult { - title - highlight - content - post { - id - title - linkAccess - archivedAt - publishedAt - insertedAt - updatedAt - version - content - banner { - original - thumb - preset - } - owner { - id - name - email - } - topics { - id - name - } - } - } - } - cursor - } - pageInfo { - hasNextPage - hasPreviousPage - startCursor - endCursor - } - } - } - `; + const query = SEARCH_POSTS_QUERY; const variables = { query: this.query, ...(this.first && { From e98b5ec5447252cb9837bdba02dad2daab25fc49 Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Tue, 2 Dec 2025 13:23:54 -0800 Subject: [PATCH 5/5] addded common folder --- components/slab/common/queries.mjs | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 components/slab/common/queries.mjs diff --git a/components/slab/common/queries.mjs b/components/slab/common/queries.mjs new file mode 100644 index 0000000000000..89d4a7dfa144c --- /dev/null +++ b/components/slab/common/queries.mjs @@ -0,0 +1,96 @@ +export const SEARCH_POSTS_QUERY = ` + query SearchPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) { + search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) { + edges { + node { + ... on PostSearchResult { + title + highlight + content + post { + id + title + linkAccess + archivedAt + publishedAt + insertedAt + updatedAt + version + content + banner { + original + thumb + preset + } + owner { + id + name + email + } + topics { + id + name + } + } + } + } + cursor + } + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + } + } +`; + +export const LIST_POSTS_QUERY = ` + query ListPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) { + search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) { + edges { + node { + ... on PostSearchResult { + title + highlight + content + post { + id + title + linkAccess + archivedAt + publishedAt + insertedAt + updatedAt + version + content + banner { + original + thumb + preset + } + owner { + id + name + email + } + topics { + id + name + } + } + } + } + cursor + } + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + } + } +`; +