@keystrokehq/posthog 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +237 -0
  2. package/dist/_official/index.d.mts +2 -0
  3. package/dist/_official/index.mjs +3 -0
  4. package/dist/_runtime/index.d.mts +7 -0
  5. package/dist/_runtime/index.mjs +3 -0
  6. package/dist/actions.d.mts +244 -0
  7. package/dist/actions.mjs +129 -0
  8. package/dist/annotations.d.mts +185 -0
  9. package/dist/annotations.mjs +141 -0
  10. package/dist/capture.d.mts +177 -0
  11. package/dist/capture.mjs +241 -0
  12. package/dist/client.d.mts +51 -0
  13. package/dist/client.mjs +200 -0
  14. package/dist/cohorts.d.mts +229 -0
  15. package/dist/cohorts.mjs +185 -0
  16. package/dist/connection.d.mts +2 -0
  17. package/dist/connection.mjs +3 -0
  18. package/dist/dashboards.d.mts +434 -0
  19. package/dist/dashboards.mjs +356 -0
  20. package/dist/decide.d.mts +74 -0
  21. package/dist/decide.mjs +75 -0
  22. package/dist/errors.d.mts +58 -0
  23. package/dist/errors.mjs +120 -0
  24. package/dist/events-management.d.mts +294 -0
  25. package/dist/events-management.mjs +242 -0
  26. package/dist/factory-DYDvHOGb.mjs +8 -0
  27. package/dist/feature-flags.d.mts +416 -0
  28. package/dist/feature-flags.mjs +317 -0
  29. package/dist/index.d.mts +1 -0
  30. package/dist/index.mjs +1 -0
  31. package/dist/insights.d.mts +409 -0
  32. package/dist/insights.mjs +346 -0
  33. package/dist/integration-CsCBBu4d.d.mts +53 -0
  34. package/dist/integration-Doy2Dwli.mjs +30 -0
  35. package/dist/organizations.d.mts +257 -0
  36. package/dist/organizations.mjs +219 -0
  37. package/dist/persons.d.mts +369 -0
  38. package/dist/persons.mjs +345 -0
  39. package/dist/projects.d.mts +348 -0
  40. package/dist/projects.mjs +287 -0
  41. package/dist/schemas.d.mts +351 -0
  42. package/dist/schemas.mjs +302 -0
  43. package/dist/session-recordings.d.mts +391 -0
  44. package/dist/session-recordings.mjs +308 -0
  45. package/dist/surveys.d.mts +287 -0
  46. package/dist/surveys.mjs +208 -0
  47. package/dist/triggers.d.mts +115 -0
  48. package/dist/triggers.mjs +330 -0
  49. package/dist/webhook-management.d.mts +188 -0
  50. package/dist/webhook-management.mjs +152 -0
  51. package/package.json +147 -0
@@ -0,0 +1,208 @@
1
+ import { createPosthogManagementClient } from "./client.mjs";
2
+ import { paginatedResponseSchema, projectIdInputShape, surveySchema } from "./schemas.mjs";
3
+ import { t as posthogOperation } from "./factory-DYDvHOGb.mjs";
4
+ import { z } from "zod";
5
+
6
+ //#region src/surveys.ts
7
+ /**
8
+ * posthog/surveys.ts
9
+ *
10
+ * Survey CRUD + activity. Uses the management client.
11
+ *
12
+ * Docs: https://posthog.com/docs/api/surveys
13
+ */
14
+ const idInput = {
15
+ ...projectIdInputShape,
16
+ id: z.string().min(1)
17
+ };
18
+ const writeShape = {
19
+ name: z.string().optional(),
20
+ description: z.string().nullable().optional(),
21
+ type: z.enum([
22
+ "popover",
23
+ "api",
24
+ "widget",
25
+ "button",
26
+ "full_screen",
27
+ "email"
28
+ ]).optional(),
29
+ questions: z.array(z.record(z.string(), z.unknown())).optional(),
30
+ conditions: z.record(z.string(), z.unknown()).nullable().optional(),
31
+ appearance: z.record(z.string(), z.unknown()).nullable().optional(),
32
+ targeting_flag_id: z.number().int().nullable().optional(),
33
+ start_date: z.string().nullable().optional(),
34
+ end_date: z.string().nullable().optional(),
35
+ responses_limit: z.number().int().nullable().optional(),
36
+ archived: z.boolean().optional()
37
+ };
38
+ const listSurveys = posthogOperation({
39
+ id: "posthog_surveys_list",
40
+ name: "PostHog List Surveys",
41
+ description: "List surveys in a project",
42
+ input: z.object({
43
+ ...projectIdInputShape,
44
+ limit: z.number().int().min(1).max(200).optional(),
45
+ offset: z.number().int().min(0).optional(),
46
+ search: z.string().optional()
47
+ }),
48
+ output: paginatedResponseSchema(surveySchema),
49
+ run: async (input, credentials) => {
50
+ const client = createPosthogManagementClient(credentials);
51
+ const projectId = client.projectId(input.projectId);
52
+ return client.request({
53
+ method: "GET",
54
+ path: `/api/projects/${projectId}/surveys/`,
55
+ query: {
56
+ limit: input.limit,
57
+ offset: input.offset,
58
+ search: input.search
59
+ }
60
+ });
61
+ }
62
+ });
63
+ const getSurvey = posthogOperation({
64
+ id: "posthog_surveys_get",
65
+ name: "PostHog Get Survey",
66
+ description: "Retrieve a survey by id",
67
+ input: z.object(idInput),
68
+ output: surveySchema,
69
+ run: async (input, credentials) => {
70
+ const client = createPosthogManagementClient(credentials);
71
+ const projectId = client.projectId(input.projectId);
72
+ return client.request({
73
+ method: "GET",
74
+ path: `/api/projects/${projectId}/surveys/${input.id}/`
75
+ });
76
+ }
77
+ });
78
+ const createSurvey = posthogOperation({
79
+ id: "posthog_surveys_create",
80
+ name: "PostHog Create Survey",
81
+ description: "Create a new survey",
82
+ input: z.object({
83
+ ...projectIdInputShape,
84
+ ...writeShape,
85
+ name: z.string().min(1)
86
+ }),
87
+ output: surveySchema,
88
+ needsApproval: true,
89
+ run: async (input, credentials) => {
90
+ const client = createPosthogManagementClient(credentials);
91
+ const projectId = client.projectId(input.projectId);
92
+ const { projectId: _pid, ...body } = input;
93
+ return client.request({
94
+ method: "POST",
95
+ path: `/api/projects/${projectId}/surveys/`,
96
+ body
97
+ });
98
+ }
99
+ });
100
+ const updateSurvey = posthogOperation({
101
+ id: "posthog_surveys_update",
102
+ name: "PostHog Update Survey",
103
+ description: "Partial update to a survey",
104
+ input: z.object({
105
+ ...idInput,
106
+ ...writeShape
107
+ }),
108
+ output: surveySchema,
109
+ needsApproval: true,
110
+ run: async (input, credentials) => {
111
+ const client = createPosthogManagementClient(credentials);
112
+ const projectId = client.projectId(input.projectId);
113
+ const { projectId: _pid, id, ...body } = input;
114
+ return client.request({
115
+ method: "PATCH",
116
+ path: `/api/projects/${projectId}/surveys/${id}/`,
117
+ body
118
+ });
119
+ }
120
+ });
121
+ const deleteSurvey = posthogOperation({
122
+ id: "posthog_surveys_delete",
123
+ name: "PostHog Delete Survey",
124
+ description: "Delete (archive) a survey",
125
+ input: z.object(idInput),
126
+ output: z.object({ success: z.boolean() }),
127
+ needsApproval: true,
128
+ run: async (input, credentials) => {
129
+ const client = createPosthogManagementClient(credentials);
130
+ const projectId = client.projectId(input.projectId);
131
+ await client.request({
132
+ method: "DELETE",
133
+ path: `/api/projects/${projectId}/surveys/${input.id}/`
134
+ });
135
+ return { success: true };
136
+ }
137
+ });
138
+ const getSurveyActivity = posthogOperation({
139
+ id: "posthog_surveys_activity",
140
+ name: "PostHog Survey Activity",
141
+ description: "Fetch activity log for a survey",
142
+ input: z.object({
143
+ ...idInput,
144
+ limit: z.number().int().min(1).max(200).optional()
145
+ }),
146
+ output: z.object({ results: z.array(z.record(z.string(), z.unknown())) }),
147
+ run: async (input, credentials) => {
148
+ const client = createPosthogManagementClient(credentials);
149
+ const projectId = client.projectId(input.projectId);
150
+ return client.request({
151
+ method: "GET",
152
+ path: `/api/projects/${projectId}/surveys/${input.id}/activity/`,
153
+ query: { limit: input.limit }
154
+ });
155
+ }
156
+ });
157
+ const getSurveysActivityFeed = posthogOperation({
158
+ id: "posthog_surveys_activity_feed",
159
+ name: "PostHog Surveys Activity Feed",
160
+ description: "Fetch project-wide survey activity feed",
161
+ input: z.object({
162
+ ...projectIdInputShape,
163
+ limit: z.number().int().min(1).max(200).optional()
164
+ }),
165
+ output: z.object({ results: z.array(z.record(z.string(), z.unknown())) }),
166
+ run: async (input, credentials) => {
167
+ const client = createPosthogManagementClient(credentials);
168
+ const projectId = client.projectId(input.projectId);
169
+ return client.request({
170
+ method: "GET",
171
+ path: `/api/projects/${projectId}/surveys/activity/`,
172
+ query: { limit: input.limit }
173
+ });
174
+ }
175
+ });
176
+ const getSurveyResponsesCount = posthogOperation({
177
+ id: "posthog_surveys_responses_count",
178
+ name: "PostHog Survey Responses Count",
179
+ description: "Fetch the responses count for all surveys",
180
+ input: z.object(projectIdInputShape),
181
+ output: z.record(z.string(), z.unknown()),
182
+ run: async (input, credentials) => {
183
+ const client = createPosthogManagementClient(credentials);
184
+ const projectId = client.projectId(input.projectId);
185
+ return client.request({
186
+ method: "GET",
187
+ path: `/api/projects/${projectId}/surveys/responses_count/`
188
+ });
189
+ }
190
+ });
191
+ const getSurveyStats = posthogOperation({
192
+ id: "posthog_surveys_stats",
193
+ name: "PostHog Survey Stats",
194
+ description: "Fetch aggregate statistics for a survey",
195
+ input: z.object(idInput),
196
+ output: z.record(z.string(), z.unknown()),
197
+ run: async (input, credentials) => {
198
+ const client = createPosthogManagementClient(credentials);
199
+ const projectId = client.projectId(input.projectId);
200
+ return client.request({
201
+ method: "GET",
202
+ path: `/api/projects/${projectId}/surveys/${input.id}/stats/`
203
+ });
204
+ }
205
+ });
206
+
207
+ //#endregion
208
+ export { createSurvey, deleteSurvey, getSurvey, getSurveyActivity, getSurveyResponsesCount, getSurveyStats, getSurveysActivityFeed, listSurveys, updateSurvey };
@@ -0,0 +1,115 @@
1
+ import { n as posthog } from "./integration-CsCBBu4d.mjs";
2
+ import { z } from "zod";
3
+ import { IntegrationTriggerBindingOptions, createPollingTriggerBindingFactory } from "@keystrokehq/integration-authoring";
4
+ import { BoundTrigger } from "@keystrokehq/core";
5
+ import { PollingTriggerManifest } from "@keystrokehq/core/trigger";
6
+
7
+ //#region src/triggers.d.ts
8
+ type PosthogCredentialSets = readonly [typeof posthog];
9
+ type Schedule = Parameters<typeof createPollingTriggerBindingFactory>[0]['schedule'];
10
+ type PosthogPollingBoundTrigger<TResponse extends z.ZodTypeAny, TOutput = z.output<TResponse>> = BoundTrigger<z.output<TResponse>, PosthogCredentialSets, PollingTriggerManifest, TOutput>;
11
+ interface PosthogPollingBindingOptions<TResponse extends z.ZodTypeAny, TOutput = z.output<TResponse>> extends IntegrationTriggerBindingOptions<z.output<TResponse>, TOutput> {
12
+ readonly schedule?: Schedule;
13
+ readonly idempotencyKey?: (response: z.output<TResponse>) => string | number;
14
+ }
15
+ declare const eventPageSchema: z.ZodObject<{
16
+ results: z.ZodArray<z.ZodObject<{
17
+ id: z.ZodOptional<z.ZodString>;
18
+ event: z.ZodOptional<z.ZodString>;
19
+ distinct_id: z.ZodOptional<z.ZodString>;
20
+ timestamp: z.ZodOptional<z.ZodString>;
21
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
22
+ }, z.core.$strip>>;
23
+ next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
24
+ }, z.core.$strip>;
25
+ declare const genericItemPageSchema: z.ZodObject<{
26
+ results: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
27
+ next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ count: z.ZodOptional<z.ZodNumber>;
29
+ }, z.core.$strip>;
30
+ interface NewEventParams {
31
+ readonly event?: string;
32
+ readonly distinctId?: string;
33
+ readonly projectId?: string | number;
34
+ readonly limit?: number;
35
+ }
36
+ interface NewRecordingParams {
37
+ readonly projectId?: string | number;
38
+ readonly limit?: number;
39
+ }
40
+ interface NewPersonParams {
41
+ readonly projectId?: string | number;
42
+ readonly limit?: number;
43
+ readonly search?: string;
44
+ }
45
+ interface CohortMemberParams {
46
+ readonly cohortId: number;
47
+ readonly projectId?: string | number;
48
+ readonly limit?: number;
49
+ }
50
+ interface InsightAlertParams {
51
+ readonly insightId: number;
52
+ readonly projectId?: string | number;
53
+ }
54
+ interface BatchExportRunParams {
55
+ readonly batchExportId: string;
56
+ readonly projectId?: string | number;
57
+ readonly limit?: number;
58
+ }
59
+ interface ExperimentResultParams {
60
+ readonly experimentId: number;
61
+ readonly projectId?: string | number;
62
+ }
63
+ interface FeatureFlagActivityParams {
64
+ readonly flagId: number;
65
+ readonly projectId?: string | number;
66
+ readonly limit?: number;
67
+ }
68
+ interface NewAnnotationParams {
69
+ readonly projectId?: string | number;
70
+ readonly limit?: number;
71
+ }
72
+ interface AppMetricFailureParams {
73
+ readonly projectId?: string | number;
74
+ readonly limit?: number;
75
+ }
76
+ interface SurveyResponseParams {
77
+ readonly surveyId: string;
78
+ readonly projectId?: string | number;
79
+ }
80
+ interface SubscriptionParams {
81
+ readonly projectId?: string | number;
82
+ readonly limit?: number;
83
+ }
84
+ declare function newEvent<TOutput = z.output<typeof eventPageSchema>>(input: NewEventParams & PosthogPollingBindingOptions<typeof eventPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof eventPageSchema, TOutput>;
85
+ declare function newSessionRecording<TOutput = z.output<typeof genericItemPageSchema>>(input?: NewRecordingParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
86
+ declare function newPerson<TOutput = z.output<typeof genericItemPageSchema>>(input?: NewPersonParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
87
+ declare function newCohortMember<TOutput = z.output<typeof genericItemPageSchema>>(input: CohortMemberParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
88
+ declare function insightAlert<TOutput = z.output<typeof genericItemPageSchema>>(input: InsightAlertParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
89
+ declare function batchExportRun<TOutput = z.output<typeof genericItemPageSchema>>(input: BatchExportRunParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
90
+ declare function experimentResult<TOutput = z.output<typeof genericItemPageSchema>>(input: ExperimentResultParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
91
+ declare function featureFlagActivity<TOutput = z.output<typeof genericItemPageSchema>>(input: FeatureFlagActivityParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
92
+ declare function newAnnotation<TOutput = z.output<typeof genericItemPageSchema>>(input?: NewAnnotationParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
93
+ declare function pluginFailure<TOutput = z.output<typeof genericItemPageSchema>>(input?: AppMetricFailureParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
94
+ declare function surveyResponse<TOutput = z.output<typeof genericItemPageSchema>>(input: SurveyResponseParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
95
+ declare function newSubscription<TOutput = z.output<typeof genericItemPageSchema>>(input?: SubscriptionParams & PosthogPollingBindingOptions<typeof genericItemPageSchema, TOutput>): PosthogPollingBoundTrigger<typeof genericItemPageSchema, TOutput>;
96
+ /**
97
+ * Namespace object for authored workflows. Prefer the individual
98
+ * exports for new code; `polling` is kept for authoring ergonomics.
99
+ */
100
+ declare const polling: Readonly<{
101
+ newEvent: typeof newEvent;
102
+ newSessionRecording: typeof newSessionRecording;
103
+ newPerson: typeof newPerson;
104
+ newCohortMember: typeof newCohortMember;
105
+ insightAlert: typeof insightAlert;
106
+ batchExportRun: typeof batchExportRun;
107
+ experimentResult: typeof experimentResult;
108
+ featureFlagActivity: typeof featureFlagActivity;
109
+ newAnnotation: typeof newAnnotation;
110
+ pluginFailure: typeof pluginFailure;
111
+ surveyResponse: typeof surveyResponse;
112
+ newSubscription: typeof newSubscription;
113
+ }>;
114
+ //#endregion
115
+ export { batchExportRun, experimentResult, featureFlagActivity, insightAlert, newAnnotation, newCohortMember, newEvent, newPerson, newSessionRecording, newSubscription, pluginFailure, polling, surveyResponse };
@@ -0,0 +1,330 @@
1
+ import { t as posthog } from "./integration-Doy2Dwli.mjs";
2
+ import { createPosthogManagementClient } from "./client.mjs";
3
+ import { z } from "zod";
4
+ import { createPollingTriggerBindingFactory } from "@keystrokehq/integration-authoring";
5
+
6
+ //#region src/triggers.ts
7
+ function withDefaultSchedule(schedule) {
8
+ if (schedule === void 0) return "1m";
9
+ return schedule;
10
+ }
11
+ function extractCredentials(ctx) {
12
+ return ctx.credentials.posthog;
13
+ }
14
+ function createPosthogPollingBindingFactory(config) {
15
+ return createPollingTriggerBindingFactory({
16
+ defaultName: config.defaultName,
17
+ defaultDescription: config.defaultDescription,
18
+ schedule: withDefaultSchedule(config.schedule),
19
+ credentialSets: [posthog],
20
+ response: config.responseSchema,
21
+ poll: async (ctx) => {
22
+ const creds = extractCredentials(ctx);
23
+ return config.callback(creds, ctx.lastPolledAt);
24
+ },
25
+ idempotencyKey: (response) => {
26
+ const key = config.idempotencyKey ? config.idempotencyKey(response) : config.defaultIdempotencyKey(response);
27
+ return String(key);
28
+ }
29
+ });
30
+ }
31
+ function splitOptions(input) {
32
+ return {
33
+ schedule: input?.schedule,
34
+ idempotencyKey: input?.idempotencyKey,
35
+ bindOptions: {
36
+ ...input?.name ? { name: input.name } : {},
37
+ ...input?.description ? { description: input.description } : {},
38
+ ...input?.filter ? { filter: input.filter } : {},
39
+ ...input?.transform ? { transform: input.transform } : {}
40
+ }
41
+ };
42
+ }
43
+ function bindTrigger(definition, params, input) {
44
+ const { schedule, idempotencyKey, bindOptions } = splitOptions(input);
45
+ return createPosthogPollingBindingFactory({
46
+ responseSchema: definition.responseSchema,
47
+ defaultName: definition.defaultName,
48
+ defaultDescription: definition.defaultDescription,
49
+ callback: (credentials, lastPolledAt) => definition.poll(params, credentials, lastPolledAt),
50
+ defaultIdempotencyKey: definition.defaultIdempotencyKey,
51
+ schedule,
52
+ idempotencyKey
53
+ })(bindOptions);
54
+ }
55
+ function defineTrigger(definition) {
56
+ return definition;
57
+ }
58
+ const eventPageSchema = z.object({
59
+ results: z.array(z.object({
60
+ id: z.string().optional(),
61
+ event: z.string().optional(),
62
+ distinct_id: z.string().optional(),
63
+ timestamp: z.string().optional(),
64
+ properties: z.record(z.string(), z.unknown()).optional()
65
+ })),
66
+ next: z.string().nullable().optional()
67
+ });
68
+ const genericItemPageSchema = z.object({
69
+ results: z.array(z.record(z.string(), z.unknown())),
70
+ next: z.string().nullable().optional(),
71
+ count: z.number().int().optional()
72
+ });
73
+ function isoMinusSeconds(value) {
74
+ if (!value) return void 0;
75
+ const parsed = Date.parse(value);
76
+ if (!Number.isFinite(parsed)) return void 0;
77
+ return new Date(parsed).toISOString();
78
+ }
79
+ const newEventDefinition = defineTrigger({
80
+ responseSchema: eventPageSchema,
81
+ defaultName: "PostHog New Event",
82
+ defaultDescription: "Poll for new analytics events matching a filter",
83
+ poll: async (params, credentials, lastPolledAt) => {
84
+ const client = createPosthogManagementClient(credentials);
85
+ const projectId = client.projectId(params.projectId);
86
+ const after = isoMinusSeconds(lastPolledAt);
87
+ return client.request({
88
+ method: "GET",
89
+ path: `/api/projects/${projectId}/events/`,
90
+ query: {
91
+ limit: params.limit ?? 100,
92
+ event: params.event,
93
+ distinct_id: params.distinctId,
94
+ after
95
+ }
96
+ });
97
+ },
98
+ defaultIdempotencyKey: (response) => response.results[0]?.id ?? "no-events"
99
+ });
100
+ const newRecordingDefinition = defineTrigger({
101
+ responseSchema: genericItemPageSchema,
102
+ defaultName: "PostHog New Session Recording",
103
+ defaultDescription: "Poll for new session recordings in a project",
104
+ poll: async (params, credentials, lastPolledAt) => {
105
+ const client = createPosthogManagementClient(credentials);
106
+ const projectId = client.projectId(params.projectId);
107
+ return client.request({
108
+ method: "GET",
109
+ path: `/api/projects/${projectId}/session_recordings/`,
110
+ query: {
111
+ limit: params.limit ?? 50,
112
+ date_from: isoMinusSeconds(lastPolledAt)
113
+ }
114
+ });
115
+ },
116
+ defaultIdempotencyKey: (response) => response.results[0]?.id ?? "no-recordings"
117
+ });
118
+ const newPersonDefinition = defineTrigger({
119
+ responseSchema: genericItemPageSchema,
120
+ defaultName: "PostHog New Person",
121
+ defaultDescription: "Poll for newly created or identified persons",
122
+ poll: async (params, credentials, _lastPolledAt) => {
123
+ const client = createPosthogManagementClient(credentials);
124
+ const projectId = client.projectId(params.projectId);
125
+ return client.request({
126
+ method: "GET",
127
+ path: `/api/projects/${projectId}/persons/`,
128
+ query: {
129
+ limit: params.limit ?? 100,
130
+ search: params.search
131
+ }
132
+ });
133
+ },
134
+ defaultIdempotencyKey: (response) => response.results[0]?.uuid ?? (response.results[0]?.id)?.toString() ?? "no-persons"
135
+ });
136
+ const newCohortMemberDefinition = defineTrigger({
137
+ responseSchema: genericItemPageSchema,
138
+ defaultName: "PostHog New Cohort Member",
139
+ defaultDescription: "Poll for newly added members of a cohort",
140
+ poll: async (params, credentials, _lastPolledAt) => {
141
+ const client = createPosthogManagementClient(credentials);
142
+ const projectId = client.projectId(params.projectId);
143
+ return client.request({
144
+ method: "GET",
145
+ path: `/api/projects/${projectId}/cohorts/${params.cohortId}/persons/`,
146
+ query: { limit: params.limit ?? 100 }
147
+ });
148
+ },
149
+ defaultIdempotencyKey: (response) => response.results[0]?.uuid ?? "no-members"
150
+ });
151
+ const insightAlertDefinition = defineTrigger({
152
+ responseSchema: genericItemPageSchema,
153
+ defaultName: "PostHog Insight Alert",
154
+ defaultDescription: "Poll an insight and emit on value changes (threshold-style)",
155
+ poll: async (params, credentials, _lastPolledAt) => {
156
+ const client = createPosthogManagementClient(credentials);
157
+ const projectId = client.projectId(params.projectId);
158
+ return { results: [await client.request({
159
+ method: "GET",
160
+ path: `/api/projects/${projectId}/insights/${params.insightId}/`
161
+ })] };
162
+ },
163
+ defaultIdempotencyKey: (response) => response.results[0]?.last_refresh ?? "no-refresh"
164
+ });
165
+ const batchExportRunDefinition = defineTrigger({
166
+ responseSchema: genericItemPageSchema,
167
+ defaultName: "PostHog Batch Export Run",
168
+ defaultDescription: "Poll for batch export run state transitions",
169
+ poll: async (params, credentials, lastPolledAt) => {
170
+ const client = createPosthogManagementClient(credentials);
171
+ const projectId = client.projectId(params.projectId);
172
+ return client.request({
173
+ method: "GET",
174
+ path: `/api/projects/${projectId}/batch_exports/${params.batchExportId}/runs/`,
175
+ query: {
176
+ limit: params.limit ?? 50,
177
+ cursor: lastPolledAt
178
+ }
179
+ });
180
+ },
181
+ defaultIdempotencyKey: (response) => response.results[0]?.id ?? "no-runs"
182
+ });
183
+ const experimentResultDefinition = defineTrigger({
184
+ responseSchema: genericItemPageSchema,
185
+ defaultName: "PostHog Experiment Significant Result",
186
+ defaultDescription: "Poll experiment results and emit when significance is reached",
187
+ poll: async (params, credentials, _lastPolledAt) => {
188
+ const client = createPosthogManagementClient(credentials);
189
+ const projectId = client.projectId(params.projectId);
190
+ return { results: [await client.request({
191
+ method: "GET",
192
+ path: `/api/projects/${projectId}/experiments/${params.experimentId}/results/`
193
+ })] };
194
+ },
195
+ defaultIdempotencyKey: (response) => (response.results[0]?.significant)?.toString() ?? "no-results"
196
+ });
197
+ const featureFlagActivityDefinition = defineTrigger({
198
+ responseSchema: genericItemPageSchema,
199
+ defaultName: "PostHog Feature Flag Rollout Change",
200
+ defaultDescription: "Poll the activity feed of a feature flag for rollout edits",
201
+ poll: async (params, credentials, _lastPolledAt) => {
202
+ const client = createPosthogManagementClient(credentials);
203
+ const projectId = client.projectId(params.projectId);
204
+ return client.request({
205
+ method: "GET",
206
+ path: `/api/projects/${projectId}/feature_flags/${params.flagId}/activity/`,
207
+ query: { limit: params.limit ?? 50 }
208
+ });
209
+ },
210
+ defaultIdempotencyKey: (response) => response.results[0]?.created_at ?? "no-activity"
211
+ });
212
+ const newAnnotationDefinition = defineTrigger({
213
+ responseSchema: genericItemPageSchema,
214
+ defaultName: "PostHog New Annotation",
215
+ defaultDescription: "Poll for newly created annotations",
216
+ poll: async (params, credentials, _lastPolledAt) => {
217
+ const client = createPosthogManagementClient(credentials);
218
+ const projectId = client.projectId(params.projectId);
219
+ return client.request({
220
+ method: "GET",
221
+ path: `/api/projects/${projectId}/annotations/`,
222
+ query: { limit: params.limit ?? 100 }
223
+ });
224
+ },
225
+ defaultIdempotencyKey: (response) => (response.results[0]?.id)?.toString() ?? "no-annotations"
226
+ });
227
+ const appMetricFailureDefinition = defineTrigger({
228
+ responseSchema: genericItemPageSchema,
229
+ defaultName: "PostHog Plugin Failure",
230
+ defaultDescription: "Poll app_metrics for pipeline / plugin failures",
231
+ poll: async (params, credentials, _lastPolledAt) => {
232
+ const client = createPosthogManagementClient(credentials);
233
+ const projectId = client.projectId(params.projectId);
234
+ return client.request({
235
+ method: "GET",
236
+ path: `/api/projects/${projectId}/app_metrics/`,
237
+ query: {
238
+ limit: params.limit ?? 50,
239
+ category: "error"
240
+ }
241
+ });
242
+ },
243
+ defaultIdempotencyKey: (response) => response.results[0]?.timestamp ?? "no-failures"
244
+ });
245
+ const surveyResponseDefinition = defineTrigger({
246
+ responseSchema: genericItemPageSchema,
247
+ defaultName: "PostHog Survey Response",
248
+ defaultDescription: "Poll survey stats and emit when response counts change",
249
+ poll: async (params, credentials, _lastPolledAt) => {
250
+ const client = createPosthogManagementClient(credentials);
251
+ const projectId = client.projectId(params.projectId);
252
+ return { results: [await client.request({
253
+ method: "GET",
254
+ path: `/api/projects/${projectId}/surveys/${params.surveyId}/stats/`
255
+ })] };
256
+ },
257
+ defaultIdempotencyKey: (response) => (response.results[0]?.total)?.toString() ?? "no-responses"
258
+ });
259
+ const newSubscriptionDefinition = defineTrigger({
260
+ responseSchema: genericItemPageSchema,
261
+ defaultName: "PostHog New Subscription",
262
+ defaultDescription: "Poll for newly scheduled subscriptions (insight/dashboard digests)",
263
+ poll: async (params, credentials, _lastPolledAt) => {
264
+ const client = createPosthogManagementClient(credentials);
265
+ const projectId = client.projectId(params.projectId);
266
+ return client.request({
267
+ method: "GET",
268
+ path: `/api/projects/${projectId}/subscriptions/`,
269
+ query: { limit: params.limit ?? 50 }
270
+ });
271
+ },
272
+ defaultIdempotencyKey: (response) => (response.results[0]?.id)?.toString() ?? "no-subscriptions"
273
+ });
274
+ function newEvent(input) {
275
+ return bindTrigger(newEventDefinition, input, input);
276
+ }
277
+ function newSessionRecording(input) {
278
+ return bindTrigger(newRecordingDefinition, input ?? {}, input);
279
+ }
280
+ function newPerson(input) {
281
+ return bindTrigger(newPersonDefinition, input ?? {}, input);
282
+ }
283
+ function newCohortMember(input) {
284
+ return bindTrigger(newCohortMemberDefinition, input, input);
285
+ }
286
+ function insightAlert(input) {
287
+ return bindTrigger(insightAlertDefinition, input, input);
288
+ }
289
+ function batchExportRun(input) {
290
+ return bindTrigger(batchExportRunDefinition, input, input);
291
+ }
292
+ function experimentResult(input) {
293
+ return bindTrigger(experimentResultDefinition, input, input);
294
+ }
295
+ function featureFlagActivity(input) {
296
+ return bindTrigger(featureFlagActivityDefinition, input, input);
297
+ }
298
+ function newAnnotation(input) {
299
+ return bindTrigger(newAnnotationDefinition, input ?? {}, input);
300
+ }
301
+ function pluginFailure(input) {
302
+ return bindTrigger(appMetricFailureDefinition, input ?? {}, input);
303
+ }
304
+ function surveyResponse(input) {
305
+ return bindTrigger(surveyResponseDefinition, input, input);
306
+ }
307
+ function newSubscription(input) {
308
+ return bindTrigger(newSubscriptionDefinition, input ?? {}, input);
309
+ }
310
+ /**
311
+ * Namespace object for authored workflows. Prefer the individual
312
+ * exports for new code; `polling` is kept for authoring ergonomics.
313
+ */
314
+ const polling = Object.freeze({
315
+ newEvent,
316
+ newSessionRecording,
317
+ newPerson,
318
+ newCohortMember,
319
+ insightAlert,
320
+ batchExportRun,
321
+ experimentResult,
322
+ featureFlagActivity,
323
+ newAnnotation,
324
+ pluginFailure,
325
+ surveyResponse,
326
+ newSubscription
327
+ });
328
+
329
+ //#endregion
330
+ export { batchExportRun, experimentResult, featureFlagActivity, insightAlert, newAnnotation, newCohortMember, newEvent, newPerson, newSessionRecording, newSubscription, pluginFailure, polling, surveyResponse };