diff --git a/components/apiframe/apiframe.app.mjs b/components/apiframe/apiframe.app.mjs index e9ea57725f454..c6027ec3a22ed 100644 --- a/components/apiframe/apiframe.app.mjs +++ b/components/apiframe/apiframe.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/brand_dev/brand_dev.app.mjs b/components/brand_dev/brand_dev.app.mjs index 0dfee237e97da..d7046bafc7019 100644 --- a/components/brand_dev/brand_dev.app.mjs +++ b/components/brand_dev/brand_dev.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/contentdrips/contentdrips.app.mjs b/components/contentdrips/contentdrips.app.mjs index 3176c60f15372..d6aa0d3ef06c4 100644 --- a/components/contentdrips/contentdrips.app.mjs +++ b/components/contentdrips/contentdrips.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/cursor/cursor.app.mjs b/components/cursor/cursor.app.mjs index e201371cbc766..d6f25215fa77c 100644 --- a/components/cursor/cursor.app.mjs +++ b/components/cursor/cursor.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/emailchef/emailchef.app.mjs b/components/emailchef/emailchef.app.mjs index ea43e0f26fea1..7345b5ad7c4e7 100644 --- a/components/emailchef/emailchef.app.mjs +++ b/components/emailchef/emailchef.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/fynk/fynk.app.mjs b/components/fynk/fynk.app.mjs index 80e7e676b82ff..5b4c2ef06ccbf 100644 --- a/components/fynk/fynk.app.mjs +++ b/components/fynk/fynk.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/helicone/helicone.app.mjs b/components/helicone/helicone.app.mjs index 340f2162482ab..83f2f5a753e80 100644 --- a/components/helicone/helicone.app.mjs +++ b/components/helicone/helicone.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/iplocate/iplocate.app.mjs b/components/iplocate/iplocate.app.mjs index be8e8d529181a..84ec0bcbfe123 100644 --- a/components/iplocate/iplocate.app.mjs +++ b/components/iplocate/iplocate.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/magicalapi/magicalapi.app.mjs b/components/magicalapi/magicalapi.app.mjs index 9e769076d848e..2fca94fe7e06c 100644 --- a/components/magicalapi/magicalapi.app.mjs +++ b/components/magicalapi/magicalapi.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/neetokb/common/constants.mjs b/components/neetokb/common/constants.mjs new file mode 100644 index 0000000000000..ea830c15a04cb --- /dev/null +++ b/components/neetokb/common/constants.mjs @@ -0,0 +1 @@ +export const LIMIT = 100; diff --git a/components/neetokb/neetokb.app.mjs b/components/neetokb/neetokb.app.mjs index f4c9e4e01c647..eedb205c45c7c 100644 --- a/components/neetokb/neetokb.app.mjs +++ b/components/neetokb/neetokb.app.mjs @@ -1,11 +1,65 @@ +import { axios } from "@pipedream/platform"; +import { LIMIT } from "./common/constants.mjs"; + export default { type: "app", app: "neetokb", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _apiUrl() { + return `https://${this.$auth.organization_name}.neetokb.com/api/v1`; + }, + _getHeaders() { + return { + "Content-Type": "application/json", + "X-Api-Key": `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._apiUrl()}/${path}`, + headers: this._getHeaders(), + ...opts, + }); + }, + listArticles(args = {}) { + return this._makeRequest({ + path: "articles", + ...args, + }); + }, + async *paginate({ + fn, params = {}, maxResults = null, ...opts + }) { + let hasMore = false; + let count = 0; + let page = 0; + + do { + params.page_number = ++page; + params.page_size = LIMIT; + const { + articles, + pagination: { + total_pages: tPages, current_page_number: cPage, + }, + } = await fn({ + params, + ...opts, + }); + for (const d of articles) { + yield d; + + if (maxResults && ++count === maxResults) { + return count; + } + } + + hasMore = cPage < tPages; + + } while (hasMore); }, }, }; diff --git a/components/neetokb/package.json b/components/neetokb/package.json index e4fe50ad2b0a7..4970ff870d3fb 100644 --- a/components/neetokb/package.json +++ b/components/neetokb/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/neetokb", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream neetoKB Components", "main": "neetokb.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/components/neetokb/sources/new-published-article/new-published-article.mjs b/components/neetokb/sources/new-published-article/new-published-article.mjs new file mode 100644 index 0000000000000..1deb5e8f6413d --- /dev/null +++ b/components/neetokb/sources/new-published-article/new-published-article.mjs @@ -0,0 +1,69 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import neetokb from "../../neetokb.app.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "neetokb-new-published-article", + name: "New Published Article", + description: "Emit new event when a new article is published. [See the documentation](https://neetokb-apis.mintlify.app/api-reference/articles/list-articles).", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + neetokb, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getPublishedIds() { + return this.db.get("publishedIds") || []; + }, + _setPublishedIds(publishedIds) { + this.db.set("publishedIds", publishedIds); + }, + async emitEvent(maxResults = false) { + const publishedIds = this._getPublishedIds(); + const response = this.neetokb.paginate({ + fn: this.neetokb.listArticles, + params: { + status: "published", + }, + }); + + const responseArray = []; + for await (const item of response) { + responseArray.push(item); + } + + let newArticles = responseArray.filter((article) => !publishedIds.includes(article.id)); + + if (maxResults && newArticles.length > maxResults) { + newArticles = newArticles.slice(0, maxResults); + } + + for (const article of newArticles.reverse()) { + const ts = new Date(); + this.$emit(article, { + id: `${article.id}-${ts}`, + summary: `New Published Article: ${article.title}`, + ts, + }); + } + this._setPublishedIds(responseArray.map((article) => article.id)); + }, + }, + hooks: { + async deploy() { + await this.emitEvent(25); + }, + }, + async run() { + await this.emitEvent(); + }, + sampleEmit, +}; diff --git a/components/neetokb/sources/new-published-article/test-event.mjs b/components/neetokb/sources/new-published-article/test-event.mjs new file mode 100644 index 0000000000000..8fd1a0c3ef7aa --- /dev/null +++ b/components/neetokb/sources/new-published-article/test-event.mjs @@ -0,0 +1,12 @@ +export default { + "id": "0c8d8101-62cb-4227-9dd0-953fbf88e74d", + "slug": "article-title", + "title": "Article Title", + "state": "published", + "unique_views_count": 0, + "is_archived": false, + "category": { + "id": "ea665eb3-23a1-4cbd-9dff-0a585d6c8c53", + "name": "Getting Started" + } +} \ No newline at end of file diff --git a/components/relationcity/relationcity.app.mjs b/components/relationcity/relationcity.app.mjs index c55efdbd4f6b6..e36017576fc89 100644 --- a/components/relationcity/relationcity.app.mjs +++ b/components/relationcity/relationcity.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/shortpen/shortpen.app.mjs b/components/shortpen/shortpen.app.mjs index 2b574c2cd7638..5a8b4b4e5a5ba 100644 --- a/components/shortpen/shortpen.app.mjs +++ b/components/shortpen/shortpen.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/socket/socket.app.mjs b/components/socket/socket.app.mjs index 4b4392bc2996b..ed8ca54fe27c0 100644 --- a/components/socket/socket.app.mjs +++ b/components/socket/socket.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/turbosmtp/turbosmtp.app.mjs b/components/turbosmtp/turbosmtp.app.mjs index a3456395a7e60..5db64c72679c5 100644 --- a/components/turbosmtp/turbosmtp.app.mjs +++ b/components/turbosmtp/turbosmtp.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/validemail/validemail.app.mjs b/components/validemail/validemail.app.mjs index 16e67e492a93f..21f3df6cc61c2 100644 --- a/components/validemail/validemail.app.mjs +++ b/components/validemail/validemail.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/veryfi/veryfi.app.mjs b/components/veryfi/veryfi.app.mjs index d14f4f654d692..8550c22b23fd4 100644 --- a/components/veryfi/veryfi.app.mjs +++ b/components/veryfi/veryfi.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b8860c49f66be..6dc9e4933be48 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9692,7 +9692,11 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/neetokb: {} + components/neetokb: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/nele_ai: {}