imbi-plugin-posthog 2.60.0__tar.gz

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.
@@ -0,0 +1,30 @@
1
+ __pycache__
2
+ *.egg-info
3
+ *.pyc
4
+ *.env
5
+ .env
6
+ .env.test
7
+ build/
8
+ dist/
9
+ docs/site/
10
+ helm/imbi/charts/
11
+ runtime/state/
12
+ .venv/
13
+ .coverage
14
+ .mypy_cache/
15
+ .pytest_cache/
16
+ .ruff_cache/
17
+ coverage.xml
18
+ site/
19
+
20
+ # moon
21
+ .moon/cache
22
+ .moon/docker
23
+
24
+ # design-sync
25
+ .design-sync/sb-reference/
26
+ .design-sync/learnings/
27
+ .design-sync/.cache/
28
+ .design-sync/node_modules
29
+ .ds-sync/
30
+ ds-bundle/
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.5
2
+ Name: imbi-plugin-posthog
3
+ Version: 2.60.0
4
+ Summary: PostHog webhook plugin for Imbi
5
+ Author-email: Dave Shawley <daves@aweber.com>
6
+ License-Expression: BSD-3-Clause
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Natural Language :: English
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Requires-Python: >=3.14
14
+ Requires-Dist: imbi-common==2.60.0
15
+ Requires-Dist: pydantic>=2
16
+ Description-Content-Type: text/markdown
17
+
18
+ # imbi-plugin-posthog
19
+
20
+ The PostHog plugin for the [Imbi](https://github.com/AWeber-Imbi)
21
+ platform, distributed as a single Python package (`imbi.plugins.posthog`)
22
+ exposing one Integration (`posthog`) with one capability:
23
+
24
+ - **`webhook-actions`** — receives deliveries from a PostHog webhook
25
+ destination. imbi-gateway verifies the signature, finds the project,
26
+ and records each delivery as an event. The capability advertises no
27
+ custom actions.
28
+
29
+ The Imbi host discovers the package by scanning `imbi.plugins.*` and
30
+ reads the module-level `PLUGIN` attribute; there are no entry points.
31
+ All plugin base classes come from `imbi.common.plugins`.
32
+
33
+ ## The delivery
34
+
35
+ Configure the PostHog webhook destination with this JSON body:
36
+
37
+ ```json
38
+ {
39
+ "event": "{event}",
40
+ "person": "{person}"
41
+ }
42
+ ```
43
+
44
+ PostHog expands `{event}` and `{person}` to objects, so a delivery is:
45
+
46
+ ```json
47
+ {
48
+ "event": {
49
+ "uuid": "...",
50
+ "event": "$pageview",
51
+ "distinct_id": "...",
52
+ "properties": {},
53
+ "timestamp": "...",
54
+ "url": "https://us.posthog.com/project/1/events/..."
55
+ },
56
+ "person": {
57
+ "id": "...",
58
+ "name": "...",
59
+ "url": "https://us.posthog.com/project/1/person/...",
60
+ "properties": {}
61
+ }
62
+ }
63
+ ```
64
+
65
+ ## Signature
66
+
67
+ PostHog signs each request per the
68
+ [Standard Webhooks](https://www.standardwebhooks.com/) specification. The
69
+ destination sends three headers:
70
+
71
+ | Header | Value |
72
+ |---|---|
73
+ | `Webhook-Id` | The unique id of the message |
74
+ | `Webhook-Timestamp` | The send time, as integer seconds since the epoch |
75
+ | `Webhook-Signature` | Space-separated `v1,<base64>` tokens |
76
+
77
+ Each token is the base64 HMAC-SHA256 of
78
+ `<webhook-id>.<webhook-timestamp>.<body>`, keyed by the signing secret.
79
+ PostHog signs only when the destination's **Signing secret** is set, so
80
+ generate a Standard Webhooks key (a base64 string, optionally prefixed
81
+ with `whsec_`), enter it as the **Signing secret** of the PostHog
82
+ destination with **Signature format** set to **Standard Webhooks**, and
83
+ put the same key in the **Secret** field of the Imbi webhook. The
84
+ gateway drops a delivery whose signature is missing or does not match,
85
+ and a delivery whose timestamp is more than five minutes from the
86
+ gateway clock.
87
+ The header name and prefix are the `SIGNATURE_HEADER` and
88
+ `SIGNATURE_PREFIX` constants in `imbi.plugins.posthog.plugin`.
89
+
90
+ ## Development
91
+
92
+ ```bash
93
+ moon run root:setup # uv sync + pre-commit hooks
94
+ moon run posthog:test # coverage (fails under 85%)
95
+ moon run posthog:lint posthog:typecheck posthog:format # ruff + basedpyright + format check
96
+ ```
97
+
98
+ The plugin needs no credentials (`auth_type='none'`): it only receives.
99
+
100
+ ## License
101
+
102
+ BSD-3-Clause.
@@ -0,0 +1,85 @@
1
+ # imbi-plugin-posthog
2
+
3
+ The PostHog plugin for the [Imbi](https://github.com/AWeber-Imbi)
4
+ platform, distributed as a single Python package (`imbi.plugins.posthog`)
5
+ exposing one Integration (`posthog`) with one capability:
6
+
7
+ - **`webhook-actions`** — receives deliveries from a PostHog webhook
8
+ destination. imbi-gateway verifies the signature, finds the project,
9
+ and records each delivery as an event. The capability advertises no
10
+ custom actions.
11
+
12
+ The Imbi host discovers the package by scanning `imbi.plugins.*` and
13
+ reads the module-level `PLUGIN` attribute; there are no entry points.
14
+ All plugin base classes come from `imbi.common.plugins`.
15
+
16
+ ## The delivery
17
+
18
+ Configure the PostHog webhook destination with this JSON body:
19
+
20
+ ```json
21
+ {
22
+ "event": "{event}",
23
+ "person": "{person}"
24
+ }
25
+ ```
26
+
27
+ PostHog expands `{event}` and `{person}` to objects, so a delivery is:
28
+
29
+ ```json
30
+ {
31
+ "event": {
32
+ "uuid": "...",
33
+ "event": "$pageview",
34
+ "distinct_id": "...",
35
+ "properties": {},
36
+ "timestamp": "...",
37
+ "url": "https://us.posthog.com/project/1/events/..."
38
+ },
39
+ "person": {
40
+ "id": "...",
41
+ "name": "...",
42
+ "url": "https://us.posthog.com/project/1/person/...",
43
+ "properties": {}
44
+ }
45
+ }
46
+ ```
47
+
48
+ ## Signature
49
+
50
+ PostHog signs each request per the
51
+ [Standard Webhooks](https://www.standardwebhooks.com/) specification. The
52
+ destination sends three headers:
53
+
54
+ | Header | Value |
55
+ |---|---|
56
+ | `Webhook-Id` | The unique id of the message |
57
+ | `Webhook-Timestamp` | The send time, as integer seconds since the epoch |
58
+ | `Webhook-Signature` | Space-separated `v1,<base64>` tokens |
59
+
60
+ Each token is the base64 HMAC-SHA256 of
61
+ `<webhook-id>.<webhook-timestamp>.<body>`, keyed by the signing secret.
62
+ PostHog signs only when the destination's **Signing secret** is set, so
63
+ generate a Standard Webhooks key (a base64 string, optionally prefixed
64
+ with `whsec_`), enter it as the **Signing secret** of the PostHog
65
+ destination with **Signature format** set to **Standard Webhooks**, and
66
+ put the same key in the **Secret** field of the Imbi webhook. The
67
+ gateway drops a delivery whose signature is missing or does not match,
68
+ and a delivery whose timestamp is more than five minutes from the
69
+ gateway clock.
70
+ The header name and prefix are the `SIGNATURE_HEADER` and
71
+ `SIGNATURE_PREFIX` constants in `imbi.plugins.posthog.plugin`.
72
+
73
+ ## Development
74
+
75
+ ```bash
76
+ moon run root:setup # uv sync + pre-commit hooks
77
+ moon run posthog:test # coverage (fails under 85%)
78
+ moon run posthog:lint posthog:typecheck posthog:format # ruff + basedpyright + format check
79
+ ```
80
+
81
+ The plugin needs no credentials (`auth_type='none'`): it only receives.
82
+
83
+ ## License
84
+
85
+ BSD-3-Clause.
@@ -0,0 +1,22 @@
1
+ # yaml-language-server: $schema=https://moonrepo.dev/schemas/project.json
2
+ layer: 'library'
3
+ stack: 'backend'
4
+ language: 'python'
5
+ tags:
6
+ - 'python'
7
+
8
+ project:
9
+ name: 'imbi-plugin-posthog'
10
+ description: 'PostHog webhook plugin for Imbi'
11
+
12
+ dependsOn:
13
+ - 'common'
14
+
15
+ # Inherits lint / format / typecheck / test from .moon/tasks/python.yml. The
16
+ # shared test task points --cov-config at this member's pyproject, where
17
+ # [tool.coverage] scopes source + threshold to the member.
18
+ tasks:
19
+ test:
20
+ args:
21
+ - '--cov'
22
+ - '--cov-report=term-missing'
@@ -0,0 +1,44 @@
1
+ [project]
2
+ name = "imbi-plugin-posthog"
3
+ version = "2.60.0"
4
+ description = "PostHog webhook plugin for Imbi"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = "BSD-3-Clause"
8
+ authors = [
9
+ { name = "Dave Shawley", email = "daves@aweber.com" },
10
+ ]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Natural Language :: English",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.14",
18
+ ]
19
+ dependencies = [
20
+ "imbi-common==2.60.0",
21
+ "pydantic>=2",
22
+ ]
23
+
24
+ [build-system]
25
+ requires = ["hatchling"]
26
+ build-backend = "hatchling.build"
27
+
28
+ # Coverage for the per-member `moon run posthog:test` run. Scoped to this
29
+ # member so the report/threshold reflect only imbi.plugins.posthog; the aggregate
30
+ # `root:coverage` run uses the root pyproject config instead.
31
+ [tool.coverage.run]
32
+ branch = true
33
+ source_pkgs = ["imbi.plugins.posthog"]
34
+
35
+ [tool.coverage.report]
36
+ exclude_also = ["typing.TYPE_CHECKING"]
37
+ fail_under = 85
38
+ show_missing = true
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/imbi"]
42
+ include = [
43
+ "src/imbi/plugins/posthog/py.typed",
44
+ ]
@@ -0,0 +1,11 @@
1
+ """Imbi PostHog plugin: receive PostHog webhook deliveries."""
2
+
3
+ from importlib import metadata
4
+
5
+ from imbi.plugins.posthog.plugin import PostHogPlugin, PostHogWebhookActions
6
+
7
+ #: Discovered by the imbi-common registry's convention scan.
8
+ PLUGIN = PostHogPlugin
9
+
10
+ version = metadata.version('imbi-plugin-posthog')
11
+ __all__ = ['PLUGIN', 'PostHogPlugin', 'PostHogWebhookActions', 'version']
@@ -0,0 +1,76 @@
1
+ """The PostHog plugin (Plugin Architecture v3).
2
+
3
+ A PostHog *webhook destination* posts one request for each event that
4
+ passes its filters. The destination's body template is::
5
+
6
+ {"event": "{event}", "person": "{person}"}
7
+
8
+ so a delivery is ``{"event": {...}, "person": {...}}``, where ``event``
9
+ carries ``uuid``, ``event``, ``distinct_id``, ``properties``,
10
+ ``timestamp``, and ``url``, and ``person`` carries ``id``, ``name``,
11
+ ``url``, and ``properties``.
12
+
13
+ The gateway's built-in event recording captures each delivery, driven by
14
+ the Webhook's selectors (identifier, event type, user subject), so this
15
+ plugin declares an empty action catalog. It exists so a PostHog webhook
16
+ can be bound to an Integration and its deliveries verified: PostHog
17
+ signs each request per the `Standard Webhooks
18
+ <https://www.standardwebhooks.com/>`_ specification, keyed by the
19
+ ``Webhook.secret``.
20
+ """
21
+
22
+ from imbi.common import plugins
23
+ from imbi.common.plugins.base import WebhookSignature
24
+
25
+ #: The Standard Webhooks signature header, lower case.
26
+ SIGNATURE_HEADER = 'webhook-signature'
27
+ #: The prefix of each symmetric (HMAC-SHA256) Standard Webhooks token.
28
+ SIGNATURE_PREFIX = 'v1,'
29
+
30
+
31
+ class PostHogWebhookActions(plugins.WebhookActionsCapability):
32
+ """Webhook-actions capability for PostHog; it has no actions."""
33
+
34
+ @classmethod
35
+ def actions(cls) -> list[plugins.ActionDescriptor]:
36
+ return []
37
+
38
+ @classmethod
39
+ def signature(cls) -> WebhookSignature:
40
+ # Standard Webhooks: base64 HMAC-SHA256 of
41
+ # ``<webhook-id>.<webhook-timestamp>.<body>``, keyed by the
42
+ # ``whsec_`` secret the destination shows, stored as the
43
+ # Webhook.secret.
44
+ return WebhookSignature(
45
+ header=SIGNATURE_HEADER,
46
+ prefix=SIGNATURE_PREFIX,
47
+ secret='webhook',
48
+ scheme='standard-webhooks',
49
+ )
50
+
51
+
52
+ class PostHogPlugin(plugins.Plugin):
53
+ """PostHog Integration: receive webhook deliveries."""
54
+
55
+ manifest = plugins.PluginManifest(
56
+ slug='posthog',
57
+ name='PostHog',
58
+ icon='si-posthog',
59
+ description=(
60
+ 'Receive PostHog webhook destination deliveries, verify their '
61
+ 'signature, and record each event against its project.'
62
+ ),
63
+ auth_type='none',
64
+ capabilities=[
65
+ plugins.Capability(
66
+ kind='webhook-actions',
67
+ label='Webhook actions',
68
+ description=(
69
+ 'Receives PostHog webhook deliveries. The gateway '
70
+ 'records each as an event; the capability advertises '
71
+ 'no actions.'
72
+ ),
73
+ handler=PostHogWebhookActions,
74
+ )
75
+ ],
76
+ )
File without changes
@@ -0,0 +1,47 @@
1
+ """Tests for the PostHog plugin: manifest and webhook signature."""
2
+
3
+ import unittest
4
+
5
+ import imbi.plugins.posthog
6
+ from imbi.plugins.posthog import plugin
7
+
8
+
9
+ class ManifestTestCase(unittest.TestCase):
10
+ def test_manifest(self) -> None:
11
+ manifest = imbi.plugins.posthog.PLUGIN.manifest
12
+ self.assertEqual('posthog', manifest.slug)
13
+ self.assertEqual('none', manifest.auth_type)
14
+ self.assertEqual([], manifest.credentials)
15
+ self.assertEqual([], manifest.options)
16
+ capability = manifest.get_capability('webhook-actions')
17
+ self.assertIsNotNone(capability)
18
+ assert capability is not None
19
+ self.assertIs(capability.handler, plugin.PostHogWebhookActions)
20
+ self.assertEqual(
21
+ ['webhook-actions'], [c.kind for c in manifest.capabilities]
22
+ )
23
+
24
+ def test_version(self) -> None:
25
+ self.assertTrue(imbi.plugins.posthog.version)
26
+
27
+
28
+ class WebhookActionsTestCase(unittest.TestCase):
29
+ def test_actions_empty(self) -> None:
30
+ self.assertEqual(plugin.PostHogWebhookActions.actions(), [])
31
+
32
+ def test_instantiable(self) -> None:
33
+ self.assertIsInstance(
34
+ plugin.PostHogWebhookActions(), plugin.PostHogWebhookActions
35
+ )
36
+
37
+ def test_signature_is_standard_webhooks(self) -> None:
38
+ signature = plugin.PostHogWebhookActions.signature()
39
+ self.assertEqual(
40
+ (
41
+ signature.header,
42
+ signature.prefix,
43
+ signature.secret,
44
+ signature.scheme,
45
+ ),
46
+ ('webhook-signature', 'v1,', 'webhook', 'standard-webhooks'),
47
+ )