intempt 1.0.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.
- intempt-1.0.0/.github/workflows/e2e.yml +76 -0
- intempt-1.0.0/.github/workflows/release.yml +80 -0
- intempt-1.0.0/.github/workflows/tests.yml +80 -0
- intempt-1.0.0/.gitignore +23 -0
- intempt-1.0.0/ARCHITECTURE.md +156 -0
- intempt-1.0.0/CHANGELOG.md +43 -0
- intempt-1.0.0/LICENSE +202 -0
- intempt-1.0.0/NOTICE +59 -0
- intempt-1.0.0/PKG-INFO +202 -0
- intempt-1.0.0/README.md +175 -0
- intempt-1.0.0/examples/README.md +64 -0
- intempt-1.0.0/examples/bare/send.py +122 -0
- intempt-1.0.0/examples/basic/app.py +191 -0
- intempt-1.0.0/pyproject.toml +80 -0
- intempt-1.0.0/scripts/e2e.py +312 -0
- intempt-1.0.0/scripts/mutation_gate.py +87 -0
- intempt-1.0.0/src/intempt/__init__.py +34 -0
- intempt-1.0.0/src/intempt/_buffer.py +330 -0
- intempt-1.0.0/src/intempt/_client.py +456 -0
- intempt-1.0.0/src/intempt/_config.py +212 -0
- intempt-1.0.0/src/intempt/_errors.py +60 -0
- intempt-1.0.0/src/intempt/_transport.py +211 -0
- intempt-1.0.0/src/intempt/_util.py +101 -0
- intempt-1.0.0/tests/__init__.py +10 -0
- intempt-1.0.0/tests/conftest.py +229 -0
- intempt-1.0.0/tests/test_bare_sample.py +161 -0
- intempt-1.0.0/tests/test_buffer.py +485 -0
- intempt-1.0.0/tests/test_client.py +331 -0
- intempt-1.0.0/tests/test_config.py +240 -0
- intempt-1.0.0/tests/test_credential_guard.py +88 -0
- intempt-1.0.0/tests/test_example_app.py +232 -0
- intempt-1.0.0/tests/test_messages.py +331 -0
- intempt-1.0.0/tests/test_thresholds.py +393 -0
- intempt-1.0.0/tests/test_transport.py +197 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Contract test against a real Intempt environment.
|
|
2
|
+
#
|
|
3
|
+
# Everything else in CI is offline: the unit suite runs against a loopback
|
|
4
|
+
# recording server. That proves the SDK sends what it intends to; it cannot prove
|
|
5
|
+
# the API accepts it. This job is the only thing that does.
|
|
6
|
+
#
|
|
7
|
+
# It is not on the PR path, because it writes real events into a real project and
|
|
8
|
+
# needs a credential. Run it manually, or let the nightly schedule catch drift in
|
|
9
|
+
# the ingestion contract.
|
|
10
|
+
#
|
|
11
|
+
# Required repository secrets:
|
|
12
|
+
# INTEMPT_E2E_API_KEY a PUBLIC key for a throwaway staging project
|
|
13
|
+
# INTEMPT_E2E_ORG
|
|
14
|
+
# INTEMPT_E2E_PROJECT
|
|
15
|
+
# INTEMPT_E2E_SOURCE_ID
|
|
16
|
+
# Optional but strongly recommended:
|
|
17
|
+
# INTEMPT_E2E_USER_ID a stable pre-existing test profile, so runs do not
|
|
18
|
+
# create a new throwaway profile every night
|
|
19
|
+
# INTEMPT_E2E_ACCOUNT_ID a stable test account
|
|
20
|
+
# INTEMPT_E2E_HOST defaults to api.staging.intempt.com if unset
|
|
21
|
+
# INTEMPT_E2E_FEED_ID a real feed id; recommend skips without it
|
|
22
|
+
# INTEMPT_E2E_PRODUCT_ID an id that exists in the catalog
|
|
23
|
+
#
|
|
24
|
+
# The same secret names as the Node SDK on purpose: one set of staging
|
|
25
|
+
# credentials serves all three server SDKs, and the three contract tests run the
|
|
26
|
+
# same steps so a divergence shows up as a different table.
|
|
27
|
+
name: E2E (staging)
|
|
28
|
+
|
|
29
|
+
on:
|
|
30
|
+
workflow_dispatch:
|
|
31
|
+
schedule:
|
|
32
|
+
- cron: '20 6 * * *'
|
|
33
|
+
|
|
34
|
+
permissions:
|
|
35
|
+
contents: read
|
|
36
|
+
|
|
37
|
+
jobs:
|
|
38
|
+
e2e:
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
42
|
+
|
|
43
|
+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
|
44
|
+
with:
|
|
45
|
+
python-version: '3.12'
|
|
46
|
+
|
|
47
|
+
- run: pip install -e .
|
|
48
|
+
|
|
49
|
+
# Skip rather than fail when the secret is absent, so a fork or a repo
|
|
50
|
+
# without staging credentials does not show a permanently red schedule.
|
|
51
|
+
- name: Check for credentials
|
|
52
|
+
id: creds
|
|
53
|
+
env:
|
|
54
|
+
KEY: ${{ secrets.INTEMPT_E2E_API_KEY }}
|
|
55
|
+
run: |
|
|
56
|
+
if [ -z "$KEY" ]; then
|
|
57
|
+
echo "::warning::INTEMPT_E2E_API_KEY is not set; skipping the E2E contract test."
|
|
58
|
+
echo "present=false" >> "$GITHUB_OUTPUT"
|
|
59
|
+
else
|
|
60
|
+
echo "present=true" >> "$GITHUB_OUTPUT"
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
- name: Run contract test
|
|
64
|
+
if: steps.creds.outputs.present == 'true'
|
|
65
|
+
env:
|
|
66
|
+
INTEMPT_E2E_HOST: ${{ secrets.INTEMPT_E2E_HOST || 'api.staging.intempt.com' }}
|
|
67
|
+
INTEMPT_E2E_ORG: ${{ secrets.INTEMPT_E2E_ORG }}
|
|
68
|
+
INTEMPT_E2E_PROJECT: ${{ secrets.INTEMPT_E2E_PROJECT }}
|
|
69
|
+
INTEMPT_E2E_API_KEY: ${{ secrets.INTEMPT_E2E_API_KEY }}
|
|
70
|
+
INTEMPT_E2E_SOURCE_ID: ${{ secrets.INTEMPT_E2E_SOURCE_ID }}
|
|
71
|
+
INTEMPT_E2E_USER_ID: ${{ secrets.INTEMPT_E2E_USER_ID }}
|
|
72
|
+
INTEMPT_E2E_ACCOUNT_ID: ${{ secrets.INTEMPT_E2E_ACCOUNT_ID }}
|
|
73
|
+
INTEMPT_E2E_FEED_ID: ${{ secrets.INTEMPT_E2E_FEED_ID }}
|
|
74
|
+
INTEMPT_E2E_FEED_FIELDS: ${{ secrets.INTEMPT_E2E_FEED_FIELDS }}
|
|
75
|
+
INTEMPT_E2E_PRODUCT_ID: ${{ secrets.INTEMPT_E2E_PRODUCT_ID }}
|
|
76
|
+
run: python scripts/e2e.py
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Publishes to PyPI, only on a version tag.
|
|
2
|
+
#
|
|
3
|
+
# Mirrors the Node SDK's release workflow, including the guard that cost that
|
|
4
|
+
# package 21 months of silence: a tag that disagrees with the version in the
|
|
5
|
+
# source puts a mislabelled artifact on the index forever, and PyPI will not let
|
|
6
|
+
# you replace it.
|
|
7
|
+
#
|
|
8
|
+
# Authenticates with an API token in `PYPI_API_TOKEN`, not Trusted Publishing.
|
|
9
|
+
# Trusted Publishing (OIDC) is the better default — nothing to leak, nothing to
|
|
10
|
+
# rotate — and the switch is a small one if it is ever preferred: drop the `with:`
|
|
11
|
+
# block below, add `id-token: write`, and register a pending publisher on PyPI for
|
|
12
|
+
# owner `intempt`, repo `intempt-python`, workflow `release.yml`, environment
|
|
13
|
+
# `pypi`.
|
|
14
|
+
#
|
|
15
|
+
# The token starts account-scoped, because a project-scoped token cannot be
|
|
16
|
+
# created for a project that does not exist yet. Narrow it to the `intempt`
|
|
17
|
+
# project after the first successful upload — an account-scoped token can publish
|
|
18
|
+
# to every project the owner has, which is more authority than this job needs.
|
|
19
|
+
name: Release
|
|
20
|
+
|
|
21
|
+
on:
|
|
22
|
+
push:
|
|
23
|
+
tags:
|
|
24
|
+
- 'v*.*.*'
|
|
25
|
+
|
|
26
|
+
permissions:
|
|
27
|
+
contents: read
|
|
28
|
+
|
|
29
|
+
jobs:
|
|
30
|
+
publish:
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
environment: pypi
|
|
33
|
+
permissions:
|
|
34
|
+
contents: write # create the GitHub Release
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
37
|
+
with:
|
|
38
|
+
fetch-depth: 0
|
|
39
|
+
|
|
40
|
+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
|
41
|
+
with:
|
|
42
|
+
python-version: '3.12'
|
|
43
|
+
|
|
44
|
+
- run: pip install -e ".[dev]" build
|
|
45
|
+
|
|
46
|
+
# The same gates the PR runs. A release is not the place to find out the
|
|
47
|
+
# suite is red.
|
|
48
|
+
- run: ruff check .
|
|
49
|
+
- run: ruff format --check .
|
|
50
|
+
- run: mypy
|
|
51
|
+
- run: pytest --cov --cov-report=term-missing --cov-fail-under=90
|
|
52
|
+
|
|
53
|
+
- name: Verify the tag matches the packaged version
|
|
54
|
+
run: |
|
|
55
|
+
TAG="${GITHUB_REF_NAME#v}"
|
|
56
|
+
PKG="$(python -c 'import re,pathlib; print(re.search(r"__version__\s*=\s*\"([^\"]+)\"", pathlib.Path("src/intempt/__init__.py").read_text()).group(1))')"
|
|
57
|
+
if [ "$TAG" != "$PKG" ]; then
|
|
58
|
+
echo "::error::Tag $GITHUB_REF_NAME does not match __version__ $PKG"
|
|
59
|
+
exit 1
|
|
60
|
+
fi
|
|
61
|
+
echo "version $PKG"
|
|
62
|
+
|
|
63
|
+
- run: python -m build
|
|
64
|
+
|
|
65
|
+
# Refuses malformed metadata before anything is uploaded, which is the
|
|
66
|
+
# only chance to catch it: PyPI accepts a bad long_description and then
|
|
67
|
+
# renders it as plain text on the project page permanently.
|
|
68
|
+
- run: pip install twine && twine check dist/*
|
|
69
|
+
|
|
70
|
+
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
|
|
71
|
+
with:
|
|
72
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
73
|
+
|
|
74
|
+
- name: Create GitHub Release
|
|
75
|
+
env:
|
|
76
|
+
GH_TOKEN: ${{ github.token }}
|
|
77
|
+
run: |
|
|
78
|
+
gh release create "$GITHUB_REF_NAME" \
|
|
79
|
+
--title "$GITHUB_REF_NAME" \
|
|
80
|
+
--generate-notes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
# Every runtime `requires-python = ">=3.9"` promises, not a sample of
|
|
18
|
+
# them. Testing 3 of 6 CPython versions meant 3.10, 3.12 and 3.14 were
|
|
19
|
+
# supported on paper and never executed. PyPy is here because the SDK
|
|
20
|
+
# has no dependencies and no C extensions, so it should work — and if it
|
|
21
|
+
# does not, that is worth knowing rather than assuming.
|
|
22
|
+
python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14', 'pypy3.11']
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
25
|
+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: ${{ matrix.python }}
|
|
28
|
+
- run: pip install -e ".[dev]"
|
|
29
|
+
- run: ruff check .
|
|
30
|
+
- run: ruff format --check .
|
|
31
|
+
# mypy refuses to run on PyPy ("Running mypy on PyPy is not supported yet").
|
|
32
|
+
# Skipping the step rather than the runtime: type checking on one
|
|
33
|
+
# interpreter is enough, and the point of the PyPy job is to exercise the
|
|
34
|
+
# SDK there, which it could not do while this step failed the whole matrix
|
|
35
|
+
# entry before the suite ran.
|
|
36
|
+
- run: mypy
|
|
37
|
+
if: "!startsWith(matrix.python, 'pypy')"
|
|
38
|
+
- run: pytest --cov --cov-report=term-missing --cov-fail-under=90
|
|
39
|
+
|
|
40
|
+
mutation:
|
|
41
|
+
# Pinned to one version on purpose. The mutants do not vary by runtime, so
|
|
42
|
+
# running this across the matrix triples a multi-minute job for no signal.
|
|
43
|
+
#
|
|
44
|
+
# 3.12 specifically: mutmut needs libcst, and libcst has no prebuilt wheel
|
|
45
|
+
# for 3.14 yet, so it tries to compile Rust and fails.
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
49
|
+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
|
50
|
+
with:
|
|
51
|
+
python-version: '3.12'
|
|
52
|
+
- run: pip install -e ".[dev,mutation]"
|
|
53
|
+
- name: Mutation score
|
|
54
|
+
# 70, not the 85 the Node SDK uses, because the two numbers are not
|
|
55
|
+
# comparable. Stryker and Infection leave string literals alone by
|
|
56
|
+
# default; mutmut rewrites every one of them twice — "track" becomes
|
|
57
|
+
# "XXtrackXX" and "TRACK" — so it generates 1524 mutants for 1404 lines
|
|
58
|
+
# of source. 240 of the survivors are log-message text and internal
|
|
59
|
+
# labels nothing reads.
|
|
60
|
+
#
|
|
61
|
+
# Measured on the same commit, same suite:
|
|
62
|
+
#
|
|
63
|
+
# Node Stryker 85.84%
|
|
64
|
+
# PHP Infection 95% (covered-code MSI 99%)
|
|
65
|
+
# Python mutmut 72.48%
|
|
66
|
+
#
|
|
67
|
+
# Raising this past ~75 means asserting the exact wording of every log
|
|
68
|
+
# line, which buys a number and costs a suite that fails on a reworded
|
|
69
|
+
# message. The rejection messages are already asserted in full, in
|
|
70
|
+
# tests/test_messages.py, because those are a contract callers see.
|
|
71
|
+
#
|
|
72
|
+
# 70 sits ~2.5 points under the measured score: low enough to be green,
|
|
73
|
+
# tight enough that a real regression trips it.
|
|
74
|
+
run: python scripts/mutation_gate.py --threshold 70
|
|
75
|
+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
|
76
|
+
if: always()
|
|
77
|
+
with:
|
|
78
|
+
name: mutation-report
|
|
79
|
+
path: mutants/
|
|
80
|
+
retention-days: 14
|
intempt-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
.coverage
|
|
3
|
+
.mutlogs/
|
|
4
|
+
.mutmut-cache
|
|
5
|
+
.mypy_cache/
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
.venv-mut/
|
|
9
|
+
.venv/
|
|
10
|
+
.venv312/
|
|
11
|
+
*.egg-info/
|
|
12
|
+
*.py.bak
|
|
13
|
+
*.py[cod]
|
|
14
|
+
build/
|
|
15
|
+
dist/
|
|
16
|
+
htmlcov/
|
|
17
|
+
mutants/
|
|
18
|
+
mutation-summary.json
|
|
19
|
+
setup.cfg
|
|
20
|
+
|
|
21
|
+
# Local staging credentials for scripts/e2e.* Never commit: these repos are public.
|
|
22
|
+
.env.local
|
|
23
|
+
.env
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Server SDK architecture
|
|
2
|
+
|
|
3
|
+
One contract, three implementations: `intempt-node`, `intempt-python`, `intempt-php`.
|
|
4
|
+
|
|
5
|
+
This file is the same in all three repos. Change it in one, change it in all, or the
|
|
6
|
+
SDKs drift and a customer switching languages gets different delivery semantics for
|
|
7
|
+
the same call.
|
|
8
|
+
|
|
9
|
+
## Where this came from
|
|
10
|
+
|
|
11
|
+
The shape is derived from [mixpanel-node] / [mixpanel-python] / [mixpanel-php]: the
|
|
12
|
+
consumer/buffer split, the chunking, the keep-alive connection reuse and the bounded
|
|
13
|
+
concurrency are theirs. Both projects are Apache 2.0 and this one retains their
|
|
14
|
+
notices; see `NOTICE`.
|
|
15
|
+
|
|
16
|
+
What is **not** inherited is the delivery guarantees. mixpanel-node has no request
|
|
17
|
+
timeout, no retry, and discards errors when no callback is passed
|
|
18
|
+
(`lib/mixpanel-node.js:80`, `callback = callback || function () {}`). mixpanel-python
|
|
19
|
+
is stronger — it has real backoff — but its retry policy is still not ours. Every
|
|
20
|
+
guarantee below was added deliberately.
|
|
21
|
+
|
|
22
|
+
[mixpanel-node]: https://github.com/mixpanel/mixpanel-node
|
|
23
|
+
[mixpanel-python]: https://github.com/mixpanel/mixpanel-python
|
|
24
|
+
[mixpanel-php]: https://github.com/mixpanel/mixpanel-php
|
|
25
|
+
|
|
26
|
+
## The surface
|
|
27
|
+
|
|
28
|
+
Identical across all three, allowing for language idiom (`snake_case` in Python,
|
|
29
|
+
`camelCase` in Node/PHP).
|
|
30
|
+
|
|
31
|
+
| call | endpoint |
|
|
32
|
+
| ---- | -------- |
|
|
33
|
+
| `track(event, options)` | `POST …/sources/{sourceId}/track` |
|
|
34
|
+
| `track_batch(events)` | same, chunked at `max_request_events` |
|
|
35
|
+
| `identify(options)` | same, reserved event `Identify` |
|
|
36
|
+
| `group(options)` | same, reserved event `Identify` |
|
|
37
|
+
| `alias(options)` | same, reserved event `Identify` |
|
|
38
|
+
| `consent.grant(options)` / `consent.revoke(options)` | `POST …/consents/data` |
|
|
39
|
+
| `ecommerce.product_viewed / added_to_cart / ordered` | `POST …/track` |
|
|
40
|
+
| `recommend(options)` | `POST …/feeds/{feedId}/data` |
|
|
41
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` | — |
|
|
42
|
+
| `flush()` / `close()` | — |
|
|
43
|
+
| `set_config(patch)` / `config` / `buffered` | — |
|
|
44
|
+
|
|
45
|
+
Base path is `{path}/v1/{org}/projects/{project}`. Without a `source_id` the track
|
|
46
|
+
path is `…/track` rather than `…/sources/{id}/track`.
|
|
47
|
+
|
|
48
|
+
### Deliberately absent
|
|
49
|
+
|
|
50
|
+
- **Experiments and personalizations.** They resolve a web experience against a page.
|
|
51
|
+
A server has no page. These belong to the browser SDK.
|
|
52
|
+
- **`profile_id` and `master_id`.** `profile_id` is the anonymous id the browser SDK
|
|
53
|
+
mints on the device; a server that invents one creates an orphan profile that never
|
|
54
|
+
stitches to a real visitor. `master_id` is assigned internally after identity
|
|
55
|
+
resolution, cannot be read from here, and breaks the moment two profiles merge.
|
|
56
|
+
The only identifiers are `user_id` and `account_id`, both values the caller owns.
|
|
57
|
+
- **Console and configuration operations.** Journeys, dashboards, segments and brand
|
|
58
|
+
belong to the CLI and MCP server, not to a data-plane SDK.
|
|
59
|
+
|
|
60
|
+
## Delivery guarantees
|
|
61
|
+
|
|
62
|
+
### Errors surface. Nothing is swallowed
|
|
63
|
+
|
|
64
|
+
Every method raises/rejects on failure. No callback-swallow, no silent discard. This
|
|
65
|
+
is the single biggest departure from mixpanel-node.
|
|
66
|
+
|
|
67
|
+
### Retry policy
|
|
68
|
+
|
|
69
|
+
| response | behaviour |
|
|
70
|
+
| -------- | --------- |
|
|
71
|
+
| 413, batch > 1 | halve the batch width, retry |
|
|
72
|
+
| 413, batch = 1 | drop the event, log it, return the width to full |
|
|
73
|
+
| 429 | honour `Retry-After`, else exponential backoff |
|
|
74
|
+
| 5xx, 408, timeout | exponential backoff, floored at 100ms, capped at 10 min |
|
|
75
|
+
| other 4xx | drop the batch, log status and body |
|
|
76
|
+
| 5 consecutive failures | stop batching, report how many events are stranded |
|
|
77
|
+
| 3 consecutive 413 drops | say the gateway body limit is the likely cause, once |
|
|
78
|
+
|
|
79
|
+
Two width rules that are easy to get wrong, and were:
|
|
80
|
+
|
|
81
|
+
1. **A reduced width must recover.** Compare successes against the *current* width,
|
|
82
|
+
not the full width — `batch` is sliced to the current width, so a comparison
|
|
83
|
+
against full is unreachable and the reduction becomes permanent. Widen by doubling
|
|
84
|
+
after 10 consecutive successful sends that filled the width.
|
|
85
|
+
2. **The drop tally must not change behaviour.** It is diagnostic only. Stopping on it
|
|
86
|
+
strands the queue; pinning the width to 1 on it caps throughput to one event per
|
|
87
|
+
round trip and loses more events than it saves requests.
|
|
88
|
+
|
|
89
|
+
### Timestamps
|
|
90
|
+
|
|
91
|
+
Client timestamps are honoured by the platform between 2010 and 2040. Below
|
|
92
|
+
`LOW_TIMESTAMP_LIMIT` the request is rejected; **above `UP_TIMESTAMP_LIMIT` the server
|
|
93
|
+
silently replaces the value with its own clock**. Send milliseconds. `/track` is
|
|
94
|
+
milliseconds, `/consents/data` is **seconds** — the consent path divides.
|
|
95
|
+
|
|
96
|
+
### Platform ids are strings, never numbers
|
|
97
|
+
|
|
98
|
+
A 19-digit snowflake exceeds every language's safe integer range.
|
|
99
|
+
`Number("1841710181319290880")` rounds to `1841710181319290900` and addresses a
|
|
100
|
+
different source. Never coerce an id numerically, in any language, at any layer.
|
|
101
|
+
|
|
102
|
+
### Delivery is at-least-once
|
|
103
|
+
|
|
104
|
+
Ingestion has no idempotency key. `event_id` travels in the payload but is not a
|
|
105
|
+
column in the events table, and the table is a plain `MergeTree` — nothing collapses
|
|
106
|
+
duplicates. A retry after a lost response therefore duplicates rows. Say so in the
|
|
107
|
+
README rather than letting callers infer exactly-once from the retry table.
|
|
108
|
+
|
|
109
|
+
### close() is bounded
|
|
110
|
+
|
|
111
|
+
`close()` drains for at most 30 seconds, then stops retrying and logs how many events
|
|
112
|
+
it abandoned. Unbounded, a shutdown hook blocks for minutes against a failing
|
|
113
|
+
endpoint. `flush()` is **not** bounded — a caller who is not shutting down has not
|
|
114
|
+
asked to give up.
|
|
115
|
+
|
|
116
|
+
Enforce the deadline in two places, because one leaks: before starting a backoff (the
|
|
117
|
+
first wait alone can exceed the whole budget) and at the top of each drain iteration
|
|
118
|
+
(sends that succeed but are slow never reach the backoff check).
|
|
119
|
+
|
|
120
|
+
### opt-out gates buffered events too
|
|
121
|
+
|
|
122
|
+
The gate lives in the send path, not only at the call site. Otherwise events captured
|
|
123
|
+
before `opt_out()` are still transmitted by a later `flush()`, `close()` or exit hook,
|
|
124
|
+
and a consent revocation between capture and flush is not honoured.
|
|
125
|
+
|
|
126
|
+
## Quality bar
|
|
127
|
+
|
|
128
|
+
Every implementation ships with:
|
|
129
|
+
|
|
130
|
+
| gate | threshold |
|
|
131
|
+
| ---- | --------- |
|
|
132
|
+
| unit tests, HTTP intercepted | full method surface |
|
|
133
|
+
| integration tests, real socket | framing, keep-alive, timeout, concurrency |
|
|
134
|
+
| statement coverage | 100% |
|
|
135
|
+
| mutation score | **≥ 85%, enforced in CI as its own job** |
|
|
136
|
+
| lint + format + type check | clean, tests included in the type check |
|
|
137
|
+
| contract test against production | every method, negative controls included |
|
|
138
|
+
|
|
139
|
+
Mutation testing is not optional decoration. On the Node SDK it found two defects that
|
|
140
|
+
100% statement coverage did not: a 413 that permanently halved throughput because the
|
|
141
|
+
recovery condition was unreachable, and four dead conditionals that could not fail.
|
|
142
|
+
It also found three assertions that were green and asserted nothing.
|
|
143
|
+
|
|
144
|
+
Read the mutation score from CI, never from a developer machine. A timed-out mutant is
|
|
145
|
+
scored as killed, so a loaded laptop inflates the number — 86.19% locally against
|
|
146
|
+
84.70% on CI for the same commit, with a gate at 85.
|
|
147
|
+
|
|
148
|
+
## Contract test inputs
|
|
149
|
+
|
|
150
|
+
Every id must be real. Ingestion returns **201 for unknown accounts and products**, so
|
|
151
|
+
a fabricated `product_id` is a green test that proves nothing. Any missing input makes
|
|
152
|
+
its step SKIP, never silently pass.
|
|
153
|
+
|
|
154
|
+
Read endpoints need a negative control. A missing feed and a real feed with no matches
|
|
155
|
+
both answer 200 with an empty array, so an empty result proves nothing on its own. A
|
|
156
|
+
bogus feed id answers 400, and that is what makes the 200 meaningful.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0 — unreleased
|
|
4
|
+
|
|
5
|
+
First release. Server-side SDK, Apache 2.0, derived from mixpanel-python; see
|
|
6
|
+
[NOTICE](./NOTICE) for what was taken and what changed.
|
|
7
|
+
|
|
8
|
+
### The surface
|
|
9
|
+
|
|
10
|
+
`track`, `track_batch`, `identify`, `group`, `alias`, `consent.grant/revoke`,
|
|
11
|
+
`ecommerce.product_viewed/added_to_cart/ordered`, `recommend`,
|
|
12
|
+
`opt_in`/`opt_out`/`is_opted_in`, `flush`, `close`, `set_config`, `config`,
|
|
13
|
+
`buffered`.
|
|
14
|
+
|
|
15
|
+
Identical to `intempt-node` and `intempt-php` allowing for language idiom, so a
|
|
16
|
+
customer switching languages gets the same delivery semantics for the same call.
|
|
17
|
+
The shared contract is in [ARCHITECTURE.md](./ARCHITECTURE.md).
|
|
18
|
+
|
|
19
|
+
### Deliberately absent
|
|
20
|
+
|
|
21
|
+
- **Experiments and personalizations.** They resolve a web experience against a
|
|
22
|
+
page, and a server has no page. Browser SDK territory.
|
|
23
|
+
- **`profile_id` and `master_id`.** The only identifiers are `user_id` and
|
|
24
|
+
`account_id`, both values the caller already owns.
|
|
25
|
+
- **Console and configuration operations.** Journeys, dashboards, segments and
|
|
26
|
+
brand belong to the CLI and MCP server.
|
|
27
|
+
|
|
28
|
+
### Delivery guarantees
|
|
29
|
+
|
|
30
|
+
- Every method raises on failure. Nothing is swallowed.
|
|
31
|
+
- Retry policy: 413 halves the batch width and recovers by doubling after ten
|
|
32
|
+
full-width successes; 429 honours `Retry-After`; 5xx/408/timeout back off
|
|
33
|
+
exponentially, floored at 100ms and capped at 10 minutes; other 4xx drop the
|
|
34
|
+
batch; five consecutive failures stop batching and report what is stranded.
|
|
35
|
+
- `close()` is bounded at 30 seconds and says how many events it abandoned.
|
|
36
|
+
`flush()` is unbounded.
|
|
37
|
+
- Opt-out is enforced in the send path, so events buffered before `opt_out()`
|
|
38
|
+
are discarded rather than transmitted by a later flush.
|
|
39
|
+
- A platform id never goes through `int()`. A 19-digit snowflake exceeds float
|
|
40
|
+
precision and a numeric round trip addresses a different source.
|
|
41
|
+
- Consent timestamps are epoch **seconds**; `/track` is milliseconds.
|
|
42
|
+
- Delivery is at-least-once. Ingestion has no idempotency key, so a retry after
|
|
43
|
+
a lost response duplicates rows.
|
intempt-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|