@keystrokehq/posthog 0.0.1 → 0.0.5

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.
package/dist/triggers.mjs CHANGED
@@ -9,11 +9,11 @@ function withDefaultSchedule(schedule) {
9
9
  return schedule;
10
10
  }
11
11
  function extractCredentials(ctx) {
12
- return ctx.credentials.posthog;
12
+ return ctx.credentials["keystroke:posthog"];
13
13
  }
14
14
  function createPosthogPollingBindingFactory(config) {
15
15
  return createPollingTriggerBindingFactory({
16
- defaultName: config.defaultName,
16
+ defaultId: config.defaultId,
17
17
  defaultDescription: config.defaultDescription,
18
18
  schedule: withDefaultSchedule(config.schedule),
19
19
  credentialSets: [posthog],
@@ -21,35 +21,27 @@ function createPosthogPollingBindingFactory(config) {
21
21
  poll: async (ctx) => {
22
22
  const creds = extractCredentials(ctx);
23
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
24
  }
29
25
  });
30
26
  }
31
27
  function splitOptions(input) {
32
28
  return {
33
29
  schedule: input?.schedule,
34
- idempotencyKey: input?.idempotencyKey,
35
30
  bindOptions: {
36
- ...input?.name ? { name: input.name } : {},
31
+ ...input?.id ? { id: input.id } : {},
37
32
  ...input?.description ? { description: input.description } : {},
38
- ...input?.filter ? { filter: input.filter } : {},
39
33
  ...input?.transform ? { transform: input.transform } : {}
40
34
  }
41
35
  };
42
36
  }
43
37
  function bindTrigger(definition, params, input) {
44
- const { schedule, idempotencyKey, bindOptions } = splitOptions(input);
38
+ const { schedule, bindOptions } = splitOptions(input);
45
39
  return createPosthogPollingBindingFactory({
46
40
  responseSchema: definition.responseSchema,
47
- defaultName: definition.defaultName,
41
+ defaultId: definition.defaultId,
48
42
  defaultDescription: definition.defaultDescription,
49
43
  callback: (credentials, lastPolledAt) => definition.poll(params, credentials, lastPolledAt),
50
- defaultIdempotencyKey: definition.defaultIdempotencyKey,
51
- schedule,
52
- idempotencyKey
44
+ schedule
53
45
  })(bindOptions);
54
46
  }
55
47
  function defineTrigger(definition) {
@@ -78,7 +70,7 @@ function isoMinusSeconds(value) {
78
70
  }
79
71
  const newEventDefinition = defineTrigger({
80
72
  responseSchema: eventPageSchema,
81
- defaultName: "PostHog New Event",
73
+ defaultId: "posthog.new-event",
82
74
  defaultDescription: "Poll for new analytics events matching a filter",
83
75
  poll: async (params, credentials, lastPolledAt) => {
84
76
  const client = createPosthogManagementClient(credentials);
@@ -94,12 +86,11 @@ const newEventDefinition = defineTrigger({
94
86
  after
95
87
  }
96
88
  });
97
- },
98
- defaultIdempotencyKey: (response) => response.results[0]?.id ?? "no-events"
89
+ }
99
90
  });
100
91
  const newRecordingDefinition = defineTrigger({
101
92
  responseSchema: genericItemPageSchema,
102
- defaultName: "PostHog New Session Recording",
93
+ defaultId: "posthog.new-session-recording",
103
94
  defaultDescription: "Poll for new session recordings in a project",
104
95
  poll: async (params, credentials, lastPolledAt) => {
105
96
  const client = createPosthogManagementClient(credentials);
@@ -112,12 +103,11 @@ const newRecordingDefinition = defineTrigger({
112
103
  date_from: isoMinusSeconds(lastPolledAt)
113
104
  }
114
105
  });
115
- },
116
- defaultIdempotencyKey: (response) => response.results[0]?.id ?? "no-recordings"
106
+ }
117
107
  });
118
108
  const newPersonDefinition = defineTrigger({
119
109
  responseSchema: genericItemPageSchema,
120
- defaultName: "PostHog New Person",
110
+ defaultId: "posthog.new-person",
121
111
  defaultDescription: "Poll for newly created or identified persons",
122
112
  poll: async (params, credentials, _lastPolledAt) => {
123
113
  const client = createPosthogManagementClient(credentials);
@@ -130,12 +120,11 @@ const newPersonDefinition = defineTrigger({
130
120
  search: params.search
131
121
  }
132
122
  });
133
- },
134
- defaultIdempotencyKey: (response) => response.results[0]?.uuid ?? (response.results[0]?.id)?.toString() ?? "no-persons"
123
+ }
135
124
  });
136
125
  const newCohortMemberDefinition = defineTrigger({
137
126
  responseSchema: genericItemPageSchema,
138
- defaultName: "PostHog New Cohort Member",
127
+ defaultId: "posthog.new-cohort-member",
139
128
  defaultDescription: "Poll for newly added members of a cohort",
140
129
  poll: async (params, credentials, _lastPolledAt) => {
141
130
  const client = createPosthogManagementClient(credentials);
@@ -145,12 +134,11 @@ const newCohortMemberDefinition = defineTrigger({
145
134
  path: `/api/projects/${projectId}/cohorts/${params.cohortId}/persons/`,
146
135
  query: { limit: params.limit ?? 100 }
147
136
  });
148
- },
149
- defaultIdempotencyKey: (response) => response.results[0]?.uuid ?? "no-members"
137
+ }
150
138
  });
151
139
  const insightAlertDefinition = defineTrigger({
152
140
  responseSchema: genericItemPageSchema,
153
- defaultName: "PostHog Insight Alert",
141
+ defaultId: "posthog.insight-alert",
154
142
  defaultDescription: "Poll an insight and emit on value changes (threshold-style)",
155
143
  poll: async (params, credentials, _lastPolledAt) => {
156
144
  const client = createPosthogManagementClient(credentials);
@@ -159,12 +147,11 @@ const insightAlertDefinition = defineTrigger({
159
147
  method: "GET",
160
148
  path: `/api/projects/${projectId}/insights/${params.insightId}/`
161
149
  })] };
162
- },
163
- defaultIdempotencyKey: (response) => response.results[0]?.last_refresh ?? "no-refresh"
150
+ }
164
151
  });
165
152
  const batchExportRunDefinition = defineTrigger({
166
153
  responseSchema: genericItemPageSchema,
167
- defaultName: "PostHog Batch Export Run",
154
+ defaultId: "posthog.batch-export-run",
168
155
  defaultDescription: "Poll for batch export run state transitions",
169
156
  poll: async (params, credentials, lastPolledAt) => {
170
157
  const client = createPosthogManagementClient(credentials);
@@ -177,12 +164,11 @@ const batchExportRunDefinition = defineTrigger({
177
164
  cursor: lastPolledAt
178
165
  }
179
166
  });
180
- },
181
- defaultIdempotencyKey: (response) => response.results[0]?.id ?? "no-runs"
167
+ }
182
168
  });
183
169
  const experimentResultDefinition = defineTrigger({
184
170
  responseSchema: genericItemPageSchema,
185
- defaultName: "PostHog Experiment Significant Result",
171
+ defaultId: "posthog.experiment-result",
186
172
  defaultDescription: "Poll experiment results and emit when significance is reached",
187
173
  poll: async (params, credentials, _lastPolledAt) => {
188
174
  const client = createPosthogManagementClient(credentials);
@@ -191,12 +177,11 @@ const experimentResultDefinition = defineTrigger({
191
177
  method: "GET",
192
178
  path: `/api/projects/${projectId}/experiments/${params.experimentId}/results/`
193
179
  })] };
194
- },
195
- defaultIdempotencyKey: (response) => (response.results[0]?.significant)?.toString() ?? "no-results"
180
+ }
196
181
  });
197
182
  const featureFlagActivityDefinition = defineTrigger({
198
183
  responseSchema: genericItemPageSchema,
199
- defaultName: "PostHog Feature Flag Rollout Change",
184
+ defaultId: "posthog.feature-flag-activity",
200
185
  defaultDescription: "Poll the activity feed of a feature flag for rollout edits",
201
186
  poll: async (params, credentials, _lastPolledAt) => {
202
187
  const client = createPosthogManagementClient(credentials);
@@ -206,12 +191,11 @@ const featureFlagActivityDefinition = defineTrigger({
206
191
  path: `/api/projects/${projectId}/feature_flags/${params.flagId}/activity/`,
207
192
  query: { limit: params.limit ?? 50 }
208
193
  });
209
- },
210
- defaultIdempotencyKey: (response) => response.results[0]?.created_at ?? "no-activity"
194
+ }
211
195
  });
212
196
  const newAnnotationDefinition = defineTrigger({
213
197
  responseSchema: genericItemPageSchema,
214
- defaultName: "PostHog New Annotation",
198
+ defaultId: "posthog.new-annotation",
215
199
  defaultDescription: "Poll for newly created annotations",
216
200
  poll: async (params, credentials, _lastPolledAt) => {
217
201
  const client = createPosthogManagementClient(credentials);
@@ -221,12 +205,11 @@ const newAnnotationDefinition = defineTrigger({
221
205
  path: `/api/projects/${projectId}/annotations/`,
222
206
  query: { limit: params.limit ?? 100 }
223
207
  });
224
- },
225
- defaultIdempotencyKey: (response) => (response.results[0]?.id)?.toString() ?? "no-annotations"
208
+ }
226
209
  });
227
210
  const appMetricFailureDefinition = defineTrigger({
228
211
  responseSchema: genericItemPageSchema,
229
- defaultName: "PostHog Plugin Failure",
212
+ defaultId: "posthog.plugin-failure",
230
213
  defaultDescription: "Poll app_metrics for pipeline / plugin failures",
231
214
  poll: async (params, credentials, _lastPolledAt) => {
232
215
  const client = createPosthogManagementClient(credentials);
@@ -239,12 +222,11 @@ const appMetricFailureDefinition = defineTrigger({
239
222
  category: "error"
240
223
  }
241
224
  });
242
- },
243
- defaultIdempotencyKey: (response) => response.results[0]?.timestamp ?? "no-failures"
225
+ }
244
226
  });
245
227
  const surveyResponseDefinition = defineTrigger({
246
228
  responseSchema: genericItemPageSchema,
247
- defaultName: "PostHog Survey Response",
229
+ defaultId: "posthog.survey-response",
248
230
  defaultDescription: "Poll survey stats and emit when response counts change",
249
231
  poll: async (params, credentials, _lastPolledAt) => {
250
232
  const client = createPosthogManagementClient(credentials);
@@ -253,12 +235,11 @@ const surveyResponseDefinition = defineTrigger({
253
235
  method: "GET",
254
236
  path: `/api/projects/${projectId}/surveys/${params.surveyId}/stats/`
255
237
  })] };
256
- },
257
- defaultIdempotencyKey: (response) => (response.results[0]?.total)?.toString() ?? "no-responses"
238
+ }
258
239
  });
259
240
  const newSubscriptionDefinition = defineTrigger({
260
241
  responseSchema: genericItemPageSchema,
261
- defaultName: "PostHog New Subscription",
242
+ defaultId: "posthog.new-subscription",
262
243
  defaultDescription: "Poll for newly scheduled subscriptions (insight/dashboard digests)",
263
244
  poll: async (params, credentials, _lastPolledAt) => {
264
245
  const client = createPosthogManagementClient(credentials);
@@ -268,8 +249,7 @@ const newSubscriptionDefinition = defineTrigger({
268
249
  path: `/api/projects/${projectId}/subscriptions/`,
269
250
  query: { limit: params.limit ?? 50 }
270
251
  });
271
- },
272
- defaultIdempotencyKey: (response) => (response.results[0]?.id)?.toString() ?? "no-subscriptions"
252
+ }
273
253
  });
274
254
  function newEvent(input) {
275
255
  return bindTrigger(newEventDefinition, input, input);
@@ -20,9 +20,9 @@ declare const listActionWebhooks: _keystrokehq_core0.Operation<z.ZodObject<{
20
20
  event: z.ZodOptional<z.ZodNullable<z.ZodString>>;
21
21
  url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
22
  url_matching: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
23
- exact: "exact";
24
23
  contains: "contains";
25
24
  regex: "regex";
25
+ exact: "exact";
26
26
  }>>>;
27
27
  text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
28
  href: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -34,7 +34,7 @@ declare const listActionWebhooks: _keystrokehq_core0.Operation<z.ZodObject<{
34
34
  deleted: z.ZodOptional<z.ZodBoolean>;
35
35
  is_calculating: z.ZodOptional<z.ZodBoolean>;
36
36
  }, z.core.$strip>>;
37
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"posthog", z.ZodObject<{
37
+ }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:posthog", z.ZodObject<{
38
38
  POSTHOG_PERSONAL_API_KEY: z.ZodString;
39
39
  POSTHOG_PROJECT_API_KEY: z.ZodOptional<z.ZodString>;
40
40
  POSTHOG_HOST: z.ZodDefault<z.ZodURL>;
@@ -61,9 +61,9 @@ declare const attachActionWebhook: _keystrokehq_core0.Operation<z.ZodObject<{
61
61
  event: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
62
  url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
63
63
  url_matching: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
64
- exact: "exact";
65
64
  contains: "contains";
66
65
  regex: "regex";
66
+ exact: "exact";
67
67
  }>>>;
68
68
  text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
69
  href: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -74,7 +74,7 @@ declare const attachActionWebhook: _keystrokehq_core0.Operation<z.ZodObject<{
74
74
  created_by: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
75
75
  deleted: z.ZodOptional<z.ZodBoolean>;
76
76
  is_calculating: z.ZodOptional<z.ZodBoolean>;
77
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"posthog", z.ZodObject<{
77
+ }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:posthog", z.ZodObject<{
78
78
  POSTHOG_PERSONAL_API_KEY: z.ZodString;
79
79
  POSTHOG_PROJECT_API_KEY: z.ZodOptional<z.ZodString>;
80
80
  POSTHOG_HOST: z.ZodDefault<z.ZodURL>;
@@ -100,9 +100,9 @@ declare const detachActionWebhook: _keystrokehq_core0.Operation<z.ZodObject<{
100
100
  event: z.ZodOptional<z.ZodNullable<z.ZodString>>;
101
101
  url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
102
  url_matching: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
103
- exact: "exact";
104
103
  contains: "contains";
105
104
  regex: "regex";
105
+ exact: "exact";
106
106
  }>>>;
107
107
  text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
108
108
  href: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -113,7 +113,7 @@ declare const detachActionWebhook: _keystrokehq_core0.Operation<z.ZodObject<{
113
113
  created_by: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
114
114
  deleted: z.ZodOptional<z.ZodBoolean>;
115
115
  is_calculating: z.ZodOptional<z.ZodBoolean>;
116
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"posthog", z.ZodObject<{
116
+ }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:posthog", z.ZodObject<{
117
117
  POSTHOG_PERSONAL_API_KEY: z.ZodString;
118
118
  POSTHOG_PROJECT_API_KEY: z.ZodOptional<z.ZodString>;
119
119
  POSTHOG_HOST: z.ZodDefault<z.ZodURL>;
@@ -134,7 +134,7 @@ declare const listPipelineDestinations: _keystrokehq_core0.Operation<z.ZodObject
134
134
  previous: z.ZodNullable<z.ZodString>;
135
135
  count: z.ZodNumber;
136
136
  results: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
137
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"posthog", z.ZodObject<{
137
+ }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:posthog", z.ZodObject<{
138
138
  POSTHOG_PERSONAL_API_KEY: z.ZodString;
139
139
  POSTHOG_PROJECT_API_KEY: z.ZodOptional<z.ZodString>;
140
140
  POSTHOG_HOST: z.ZodDefault<z.ZodURL>;
@@ -153,7 +153,7 @@ declare const createPipelineDestination: _keystrokehq_core0.Operation<z.ZodObjec
153
153
  order: z.ZodOptional<z.ZodNumber>;
154
154
  config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
155
155
  projectId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
156
- }, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>, readonly [_keystrokehq_core0.CredentialSet<"posthog", z.ZodObject<{
156
+ }, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:posthog", z.ZodObject<{
157
157
  POSTHOG_PERSONAL_API_KEY: z.ZodString;
158
158
  POSTHOG_PROJECT_API_KEY: z.ZodOptional<z.ZodString>;
159
159
  POSTHOG_HOST: z.ZodDefault<z.ZodURL>;
@@ -171,7 +171,7 @@ declare const deletePipelineDestination: _keystrokehq_core0.Operation<z.ZodObjec
171
171
  projectId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
172
172
  }, z.core.$strip>, z.ZodObject<{
173
173
  success: z.ZodBoolean;
174
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"posthog", z.ZodObject<{
174
+ }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:posthog", z.ZodObject<{
175
175
  POSTHOG_PERSONAL_API_KEY: z.ZodString;
176
176
  POSTHOG_PROJECT_API_KEY: z.ZodOptional<z.ZodString>;
177
177
  POSTHOG_HOST: z.ZodDefault<z.ZodURL>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keystrokehq/posthog",
3
- "version": "0.0.1",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -103,27 +103,21 @@
103
103
  "README.md",
104
104
  "LICENSE"
105
105
  ],
106
- "scripts": {
107
- "typecheck": "tsgo --build",
108
- "build": "tsdown",
109
- "lint": "biome check .",
110
- "test:unit": "vitest run --passWithNoTests --project unit",
111
- "prepublishOnly": "pnpm build && pnpm test:unit",
112
- "lint:fix": "biome check --write .",
113
- "test:int": "vitest run --passWithNoTests --project int"
114
- },
115
106
  "dependencies": {
116
- "@keystrokehq/integration-authoring": "^0.0.1",
117
- "@keystrokehq/core": "^0.0.5",
107
+ "@keystrokehq/integration-authoring": "^0.0.5",
118
108
  "zod": "^4.3.6"
119
109
  },
110
+ "peerDependencies": {
111
+ "@keystrokehq/core": ">=0.0.7 <0.1.0"
112
+ },
120
113
  "devDependencies": {
121
- "@types/node": "catalog:",
122
- "@keystrokehq/test-utils": "workspace:*",
123
- "@keystrokehq/typescript-config": "workspace:*",
124
- "tsdown": "catalog:",
125
- "typescript": "catalog:",
126
- "vitest": "catalog:"
114
+ "@types/node": "^22.19.11",
115
+ "tsdown": "^0.20.3",
116
+ "typescript": "^5.9.3",
117
+ "vitest": "^4.0.18",
118
+ "@keystrokehq/core": "^0.0.7",
119
+ "@keystrokehq/test-utils": "0.0.0",
120
+ "@keystrokehq/typescript-config": "0.0.0"
127
121
  },
128
122
  "keywords": [
129
123
  "posthog",
@@ -143,5 +137,13 @@
143
137
  "publishConfig": {
144
138
  "access": "public",
145
139
  "registry": "https://registry.npmjs.org/"
140
+ },
141
+ "scripts": {
142
+ "typecheck": "tsgo --build",
143
+ "build": "tsdown",
144
+ "lint": "biome check .",
145
+ "test:unit": "vitest run --passWithNoTests --project unit",
146
+ "lint:fix": "biome check --write .",
147
+ "test:int": "vitest run --passWithNoTests --project int"
146
148
  }
147
- }
149
+ }