From a2247ad25635667115effb0619f17684ba98d3fe Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 5 May 2025 15:50:29 -0400 Subject: [PATCH 1/3] new components --- .../actions/capture-event/capture-event.mjs | 2 +- .../actions/create-query/create-query.mjs | 53 +++++++++++++++ .../actions/get-cohorts/get-cohorts.mjs | 47 ++++++++++++++ .../actions/get-persons/get-persons.mjs | 63 ++++++++++++++++++ .../actions/get-surveys/get-surveys.mjs | 56 ++++++++++++++++ components/posthog/package.json | 4 +- components/posthog/posthog.app.mjs | 65 +++++++++++++++++++ .../new-action-performed.mjs | 2 +- 8 files changed, 288 insertions(+), 4 deletions(-) create mode 100644 components/posthog/actions/create-query/create-query.mjs create mode 100644 components/posthog/actions/get-cohorts/get-cohorts.mjs create mode 100644 components/posthog/actions/get-persons/get-persons.mjs create mode 100644 components/posthog/actions/get-surveys/get-surveys.mjs diff --git a/components/posthog/actions/capture-event/capture-event.mjs b/components/posthog/actions/capture-event/capture-event.mjs index 78fb1ec60e861..fabe53d998fd0 100644 --- a/components/posthog/actions/capture-event/capture-event.mjs +++ b/components/posthog/actions/capture-event/capture-event.mjs @@ -4,7 +4,7 @@ export default { key: "posthog-capture-event", name: "Capture Event", description: "Captures a given event within the PostHog system. [See the documentation](https://posthog.com/docs/api/post-only-endpoints#single-event)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { posthog, diff --git a/components/posthog/actions/create-query/create-query.mjs b/components/posthog/actions/create-query/create-query.mjs new file mode 100644 index 0000000000000..17be8c4574d02 --- /dev/null +++ b/components/posthog/actions/create-query/create-query.mjs @@ -0,0 +1,53 @@ +import posthog from "../../posthog.app.mjs"; + +export default { + key: "posthog-create-query", + name: "Create Query", + description: "Create a HogQLQuery and return the results. [See the documentation](https://posthog.com/docs/api/queries#creating-a-query)", + version: "0.0.1", + type: "action", + props: { + posthog, + organizationId: { + propDefinition: [ + posthog, + "organizationId", + ], + }, + projectId: { + propDefinition: [ + posthog, + "projectId", + (c) => ({ + organizationId: c.organizationId, + }), + ], + }, + query: { + type: "string", + label: "Query", + description: "The query specifying what data to retrieve. Example: `select properties.email from persons where properties.email is not null`", + }, + name: { + type: "string", + label: "Name", + description: "A name for the query to better identify it in the query_log table", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.posthog.createQuery({ + $, + projectId: this.projectId, + data: { + query: { + kind: "HogQLQuery", + query: this.query, + name: this.name, + }, + }, + }); + $.export("$summary", "Successfully created and executed query"); + return response; + }, +}; diff --git a/components/posthog/actions/get-cohorts/get-cohorts.mjs b/components/posthog/actions/get-cohorts/get-cohorts.mjs new file mode 100644 index 0000000000000..a74eadbe3bad1 --- /dev/null +++ b/components/posthog/actions/get-cohorts/get-cohorts.mjs @@ -0,0 +1,47 @@ +import posthog from "../../posthog.app.mjs"; + +export default { + key: "posthog-get-cohorts", + name: "Get Cohorts", + description: "Retrieve a list of cohorts. [See the documentation](https://posthog.com/docs/api/cohorts#get-api-projects-project_id-cohorts)", + version: "0.0.1", + type: "action", + props: { + posthog, + organizationId: { + propDefinition: [ + posthog, + "organizationId", + ], + }, + projectId: { + propDefinition: [ + posthog, + "projectId", + (c) => ({ + organizationId: c.organizationId, + }), + ], + }, + maxResults: { + propDefinition: [ + posthog, + "maxResults", + ], + }, + }, + async run({ $ }) { + const cohorts = await this.posthog.iterateResults({ + fn: this.posthog.listCohorts, + args: { + $, + projectId: this.projectId, + max: this.maxResults, + }, + }); + $.export("$summary", `Successfully retrieved ${cohorts.length} cohort${cohorts.length === "1" + ? "" + : "s"}`); + return cohorts; + }, +}; diff --git a/components/posthog/actions/get-persons/get-persons.mjs b/components/posthog/actions/get-persons/get-persons.mjs new file mode 100644 index 0000000000000..f7809bc7dc69a --- /dev/null +++ b/components/posthog/actions/get-persons/get-persons.mjs @@ -0,0 +1,63 @@ +import posthog from "../../posthog.app.mjs"; + +export default { + key: "posthog-get-persons", + name: "Get Persons", + description: "Retrieve a list of persons. [See the documentation](https://posthog.com/docs/api/persons#get-api-projects-project_id-persons)", + version: "0.0.1", + type: "action", + props: { + posthog, + organizationId: { + propDefinition: [ + posthog, + "organizationId", + ], + }, + projectId: { + propDefinition: [ + posthog, + "projectId", + (c) => ({ + organizationId: c.organizationId, + }), + ], + }, + email: { + type: "string", + label: "Email", + description: "Filter persons by email (exact match)", + optional: true, + }, + search: { + type: "string", + label: "Search", + description: "Search persons, either by email (full text search) or distinct_id (exact match)", + optional: true, + }, + maxResults: { + propDefinition: [ + posthog, + "maxResults", + ], + }, + }, + async run({ $ }) { + const persons = await this.posthog.iterateResults({ + fn: this.posthog.listPersons, + args: { + $, + projectId: this.projectId, + params: { + email: this.email, + search: this.search, + }, + max: this.maxResults, + }, + }); + $.export("$summary", `Successfully retrieved ${persons.length} person${persons.length === "1" + ? "" + : "s"}`); + return persons; + }, +}; diff --git a/components/posthog/actions/get-surveys/get-surveys.mjs b/components/posthog/actions/get-surveys/get-surveys.mjs new file mode 100644 index 0000000000000..482690c4668e8 --- /dev/null +++ b/components/posthog/actions/get-surveys/get-surveys.mjs @@ -0,0 +1,56 @@ +import posthog from "../../posthog.app.mjs"; + +export default { + key: "posthog-get-surveys", + name: "Get Surveys", + description: "Retrieve a list of surveys. [See the documentation](https://posthog.com/docs/api/surveys#get-api-projects-project_id-surveys)", + version: "0.0.1", + type: "action", + props: { + posthog, + organizationId: { + propDefinition: [ + posthog, + "organizationId", + ], + }, + projectId: { + propDefinition: [ + posthog, + "projectId", + (c) => ({ + organizationId: c.organizationId, + }), + ], + }, + search: { + type: "string", + label: "Search", + description: "Enter a search term to filter results", + optional: true, + }, + maxResults: { + propDefinition: [ + posthog, + "maxResults", + ], + }, + }, + async run({ $ }) { + const surveys = await this.posthog.iterateResults({ + fn: this.posthog.listSurveys, + args: { + $, + projectId: this.projectId, + params: { + search: this.search, + }, + max: this.maxResults, + }, + }); + $.export("$summary", `Successfully retrieved ${surveys.length} survey${surveys.length === "1" + ? "" + : "s"}`); + return surveys; + }, +}; diff --git a/components/posthog/package.json b/components/posthog/package.json index 6d476e362c3d6..29b8f11fa722a 100644 --- a/components/posthog/package.json +++ b/components/posthog/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/posthog", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream PostHog Components", "main": "posthog.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.6.4" + "@pipedream/platform": "^3.0.3" } } diff --git a/components/posthog/posthog.app.mjs b/components/posthog/posthog.app.mjs index c52abc4e6696c..721e75f929491 100644 --- a/components/posthog/posthog.app.mjs +++ b/components/posthog/posthog.app.mjs @@ -60,6 +60,13 @@ export default { return results?.map(({ name }) => name ) || []; }, }, + maxResults: { + type: "integer", + label: "Max Results", + description: "The maximum number of results to return", + default: 100, + optional: true, + }, }, methods: { _baseUrl() { @@ -101,6 +108,30 @@ export default { ...opts, }); }, + listPersons({ + projectId, ...opts + }) { + return this._makeRequest({ + path: `/api/projects/${projectId}/persons`, + ...opts, + }); + }, + listCohorts({ + projectId, ...opts + }) { + return this._makeRequest({ + path: `/api/projects/${projectId}/cohorts`, + ...opts, + }); + }, + listSurveys({ + projectId, ...opts + }) { + return this._makeRequest({ + path: `/api/projects/${projectId}/surveys`, + ...opts, + }); + }, createQuery({ projectId, ...opts }) { @@ -117,5 +148,39 @@ export default { ...opts, }); }, + async *paginate({ + fn, args, max, + }) { + args = { + ...args, + params: { + ...args?.params, + limit: constants.DEFAULT_LIMIT, + offset: 0, + }, + }; + let hasMore, count = 0; + do { + const { + results, next, + } = await fn(args); + for (const result of results) { + yield result; + if (max && ++count >= max) { + return; + } + } + hasMore = next; + args.params.offset += args.params.limit; + } while (hasMore); + }, + async iterateResults(opts = {}) { + const results = []; + const items = this.paginate(opts); + for await (const item of items) { + results.push(item); + } + return results; + }, }, }; diff --git a/components/posthog/sources/new-action-performed/new-action-performed.mjs b/components/posthog/sources/new-action-performed/new-action-performed.mjs index 4944a99c71e73..e3427082820e1 100644 --- a/components/posthog/sources/new-action-performed/new-action-performed.mjs +++ b/components/posthog/sources/new-action-performed/new-action-performed.mjs @@ -5,7 +5,7 @@ export default { key: "posthog-new-action-performed", name: "New Action Performed", description: "Emit new event when an action is performed in a project. [See the documentation](https://posthog.com/docs/api/query#post-api-projects-project_id-query)", - version: "0.0.1", + version: "0.0.2", type: "source", dedupe: "unique", props: { From 031e534b5437ffaf335aa3e1a0517d22109b5b2d Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 5 May 2025 15:52:31 -0400 Subject: [PATCH 2/3] pnpm-lock.yaml --- pnpm-lock.yaml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0248a3592dd6a..402aae756511a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9221,8 +9221,7 @@ importers: components/osu: {} - components/oto: - specifiers: {} + components/oto: {} components/otter_waiver: dependencies: @@ -10075,8 +10074,8 @@ importers: components/posthog: dependencies: '@pipedream/platform': - specifier: ^1.6.4 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 components/postman: dependencies: @@ -13062,11 +13061,9 @@ importers: components/test_apps_for_checking_something_001: {} - components/test_apps_for_checking_something_005: - specifiers: {} + components/test_apps_for_checking_something_005: {} - components/test_apps_for_checking_something_006: - specifiers: {} + components/test_apps_for_checking_something_006: {} components/test_apps_for_switching_appslug_009: {} @@ -13440,8 +13437,7 @@ importers: components/translate_com: {} - components/transloadit: - specifiers: {} + components/transloadit: {} components/travis_ci: dependencies: From 9defd8da91e9a38e95f7ee755199da620371de08 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 5 May 2025 16:00:44 -0400 Subject: [PATCH 3/3] updates --- components/posthog/actions/get-cohorts/get-cohorts.mjs | 2 +- components/posthog/actions/get-persons/get-persons.mjs | 2 +- components/posthog/actions/get-surveys/get-surveys.mjs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/posthog/actions/get-cohorts/get-cohorts.mjs b/components/posthog/actions/get-cohorts/get-cohorts.mjs index a74eadbe3bad1..3e3f29d39112d 100644 --- a/components/posthog/actions/get-cohorts/get-cohorts.mjs +++ b/components/posthog/actions/get-cohorts/get-cohorts.mjs @@ -39,7 +39,7 @@ export default { max: this.maxResults, }, }); - $.export("$summary", `Successfully retrieved ${cohorts.length} cohort${cohorts.length === "1" + $.export("$summary", `Successfully retrieved ${cohorts.length} cohort${cohorts.length === 1 ? "" : "s"}`); return cohorts; diff --git a/components/posthog/actions/get-persons/get-persons.mjs b/components/posthog/actions/get-persons/get-persons.mjs index f7809bc7dc69a..561f8bffab6ba 100644 --- a/components/posthog/actions/get-persons/get-persons.mjs +++ b/components/posthog/actions/get-persons/get-persons.mjs @@ -55,7 +55,7 @@ export default { max: this.maxResults, }, }); - $.export("$summary", `Successfully retrieved ${persons.length} person${persons.length === "1" + $.export("$summary", `Successfully retrieved ${persons.length} person${persons.length === 1 ? "" : "s"}`); return persons; diff --git a/components/posthog/actions/get-surveys/get-surveys.mjs b/components/posthog/actions/get-surveys/get-surveys.mjs index 482690c4668e8..f1a9badeb2fc9 100644 --- a/components/posthog/actions/get-surveys/get-surveys.mjs +++ b/components/posthog/actions/get-surveys/get-surveys.mjs @@ -48,7 +48,7 @@ export default { max: this.maxResults, }, }); - $.export("$summary", `Successfully retrieved ${surveys.length} survey${surveys.length === "1" + $.export("$summary", `Successfully retrieved ${surveys.length} survey${surveys.length === 1 ? "" : "s"}`); return surveys;