Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/posthog/actions/capture-event/capture-event.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
53 changes: 53 additions & 0 deletions components/posthog/actions/create-query/create-query.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
47 changes: 47 additions & 0 deletions components/posthog/actions/get-cohorts/get-cohorts.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
63 changes: 63 additions & 0 deletions components/posthog/actions/get-persons/get-persons.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
56 changes: 56 additions & 0 deletions components/posthog/actions/get-surveys/get-surveys.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
4 changes: 2 additions & 2 deletions components/posthog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/posthog",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream PostHog Components",
"main": "posthog.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.4"
"@pipedream/platform": "^3.0.3"
}
}
65 changes: 65 additions & 0 deletions components/posthog/posthog.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}) {
Expand All @@ -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;
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
16 changes: 6 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading