dq-export-connector 0.1.0.dev25__tar.gz → 0.1.0.dev27__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.
Files changed (67) hide show
  1. dq_export_connector-0.1.0.dev27/.gitignore +5 -0
  2. dq_export_connector-0.1.0.dev27/PKG-INFO +158 -0
  3. dq_export_connector-0.1.0.dev27/README.md +145 -0
  4. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/_models/export_connector_credentials.py +25 -2
  5. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/_models/export_receipt.py +127 -4
  6. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/_models/export_worker_config.py +102 -8
  7. dq_export_connector-0.1.0.dev27/dq_export_connector/_models/snap_validation_result.py +37 -0
  8. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/classify.py +98 -0
  9. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/http.py +237 -0
  10. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/identifiers.py +121 -0
  11. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/inputs.py +80 -0
  12. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/oauth.py +321 -0
  13. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/sync.py +313 -0
  14. dq_export_connector-0.1.0.dev27/dq_export_connector/bucket/__init__.py +0 -0
  15. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/bucket/export.py +4 -4
  16. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/bucket/validate.py +2 -2
  17. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/errors.py +39 -5
  18. dq_export_connector-0.1.0.dev27/dq_export_connector/models/snap.py +50 -0
  19. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/outcome.py +15 -10
  20. dq_export_connector-0.1.0.dev27/dq_export_connector/redact.py +121 -0
  21. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/runner.py +80 -14
  22. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/__init__.py +0 -0
  23. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/client.py +143 -0
  24. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/destination.py +154 -0
  25. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/export.py +137 -0
  26. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/session.py +70 -0
  27. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/validate.py +37 -0
  28. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/pyproject.toml +11 -3
  29. dq_export_connector-0.1.0.dev27/scripts/_local.py +95 -0
  30. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/scripts/codegen-models.sh +2 -2
  31. dq_export_connector-0.1.0.dev27/scripts/consent.py +99 -0
  32. dq_export_connector-0.1.0.dev27/scripts/run_local.py +46 -0
  33. dq_export_connector-0.1.0.dev27/tests/__init__.py +0 -0
  34. dq_export_connector-0.1.0.dev27/tests/conftest.py +37 -0
  35. dq_export_connector-0.1.0.dev27/tests/fakes/__init__.py +0 -0
  36. dq_export_connector-0.1.0.dev27/tests/fakes/snap_fake.py +256 -0
  37. dq_export_connector-0.1.0.dev27/tests/test_http_and_oauth.py +398 -0
  38. dq_export_connector-0.1.0.dev27/tests/test_identifiers_and_inputs.py +118 -0
  39. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_live_buckets.py +2 -3
  40. dq_export_connector-0.1.0.dev27/tests/test_live_snap.py +115 -0
  41. dq_export_connector-0.1.0.dev27/tests/test_scripts.py +22 -0
  42. dq_export_connector-0.1.0.dev27/tests/test_snap_runner.py +612 -0
  43. dq_export_connector-0.1.0.dev27/tests/test_sync_input.py +171 -0
  44. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/uv.lock +195 -4
  45. dq_export_connector-0.1.0.dev25/.gitignore +0 -63
  46. dq_export_connector-0.1.0.dev25/PKG-INFO +0 -61
  47. dq_export_connector-0.1.0.dev25/README.md +0 -50
  48. dq_export_connector-0.1.0.dev25/dq_export_connector/redact.py +0 -69
  49. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/.python-version +0 -0
  50. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/__init__.py +0 -0
  51. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/_models/__init__.py +0 -0
  52. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/_models/application_message.py +0 -0
  53. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/_models/bucket_validation_result.py +0 -0
  54. {dq_export_connector-0.1.0.dev25/dq_export_connector/bucket → dq_export_connector-0.1.0.dev27/dq_export_connector/audience}/__init__.py +0 -0
  55. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/bucket/paths.py +0 -0
  56. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/bucket/store.py +0 -0
  57. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/bucket/upload.py +0 -0
  58. {dq_export_connector-0.1.0.dev25/dq_export_connector/bucket → dq_export_connector-0.1.0.dev27/dq_export_connector}/datasets.py +0 -0
  59. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/log.py +0 -0
  60. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/models/__init__.py +0 -0
  61. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/dq_export_connector/models/bucket.py +0 -0
  62. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_models_are_current.py +0 -0
  63. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_paths.py +0 -0
  64. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_redact.py +0 -0
  65. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_runner.py +0 -0
  66. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_store.py +0 -0
  67. {dq_export_connector-0.1.0.dev25 → dq_export_connector-0.1.0.dev27}/tests/test_upload.py +0 -0
@@ -0,0 +1,5 @@
1
+ # Local secrets for the consent CLI and the local runner.
2
+ credentials*.json
3
+ platform_secrets*.json
4
+ local/
5
+ /config*.json
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.5
2
+ Name: dq-export-connector
3
+ Version: 0.1.0.dev27
4
+ Summary: Worker logic for the Export Connector DCR.
5
+ Author: Decentriq
6
+ Requires-Python: >=3.12
7
+ Requires-Dist: pydantic<3,>=2.14
8
+ Provides-Extra: bucket
9
+ Requires-Dist: obstore<0.12,>=0.11.1; extra == 'bucket'
10
+ Provides-Extra: snap
11
+ Requires-Dist: requests<3,>=2.32; extra == 'snap'
12
+ Description-Content-Type: text/markdown
13
+
14
+ # dq-export-connector
15
+
16
+ Worker logic for the **Export Connector DCR**: one package for every
17
+ Connector Kind, each in its own sub-package with an extra of the same name for
18
+ its dependencies.
19
+
20
+ - The **bucket** kind uploads each Input's dataset to S3, Azure Blob or GCS
21
+ through [`obstore`](https://developmentseed.org/obstore/).
22
+ - The **snap** kind fills one Snap Segment per Input with hashed identifiers,
23
+ through Snap's Marketing API.
24
+
25
+ ddc pins this package by hash in a fully locked `requirements.txt` and runs
26
+ `dq_export_connector.runner.main` in the task's Python environment. It is
27
+ published to PyPI, since the compiled graph installs it from there.
28
+
29
+ - `dq_export_connector.runner`: the entry point. Reads `/input/config.json`,
30
+ `/input/credentials.json` and any platform secret under
31
+ `/input/platform_secrets/`, sets up logging, and dispatches on the Connector
32
+ Kind and the action, then writes what the action reports: a connection
33
+ test's result into `/output`, and an export's receipt and either action's
34
+ warnings and error under `/internal`, as the task's Task Report, Application
35
+ Warnings and Application Error. A run with an error fails.
36
+ - `dq_export_connector.errors`: the error and warning codes the worker
37
+ reports, and `ExportConnectorError`, which stops a run with an error code.
38
+ Codes are named for the situation, not the kind, so any kind can report them.
39
+ - `dq_export_connector.outcome`: collects a run's error, warnings and receipt
40
+ while it runs, and cuts each message to 1,000 characters, and a provider's
41
+ own error to 4,000, once redacted.
42
+ - `dq_export_connector.redact`: keeps every value from the sealed half, and
43
+ URL query strings, out of log lines and result messages. For the ad
44
+ platforms it also masks tokens, `key=secret` pairs, JWTs and SHA-256 hex.
45
+ - `dq_export_connector.datasets`: how an Input's dataset maps to files (a
46
+ stored ZIP, or one raw file).
47
+ - `dq_export_connector.bucket`: the bucket kind (`ValidateConnection` and
48
+ `Export`).
49
+ - `dq_export_connector.audience`: what the ad-platform kinds share: HTTPS to an
50
+ allowlist with retries by idempotency class, OAuth, identifier
51
+ normalisation, and the per-Input sync flow.
52
+ - `dq_export_connector.snap`: the snap kind.
53
+ - `dq_export_connector.models`: the types the worker reads and writes, those
54
+ of every Connector Kind directly in it and a kind's own in its submodule,
55
+ such as `models.bucket`. They are pydantic models generated in
56
+ `dq_export_connector._models` from ddc's JSON schemas, so the config the
57
+ worker reads and the receipt, messages and validation result it writes match
58
+ ddc's Rust types. Regenerate them with `scripts/codegen-models.sh` after the
59
+ types change and `decentriq_dcr_compiler` has been rebuilt; a test fails
60
+ while they are stale.
61
+
62
+ ```sh
63
+ uv run pytest # unit tests, against obstore's in-memory store and a fake Snap API
64
+ uv run pytest -m live # against real buckets and Snap, credentials from the environment
65
+ uv run mypy dq_export_connector tests scripts
66
+ ```
67
+
68
+ ## Snap
69
+
70
+ A Snap connector's config names the ad account and, per Input, a Segment, the
71
+ identifier type its lines hold and a Merge Mode. ddc validates it. The
72
+ credentials are the refresh token of the Snap user who consented; Decentriq's
73
+ Snap app is the `export_connector_snap_app` platform secret
74
+ (`{"clientId", "clientSecret"}`).
75
+
76
+ A run looks each Segment up by name in the ad account and creates it when
77
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
78
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
79
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
80
+ is briefly empty. A run stops at the first Input that fails. When the failure
81
+ came after the Segment changed, the error says so; a rerun is safe in both
82
+ modes. Don't run one connector twice at the same time.
83
+
84
+ An Input is one file of values, or a stored ZIP holding one: one value per
85
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
86
+ empty lines skipped, no header.
87
+
88
+ ### Identifiers
89
+
90
+ | Type | Normalisation before SHA-256 | Snap schema |
91
+ |---|---|---|
92
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
93
+ | `PHONE` | drop a `(0)` right after the country code (`+44 (0)20…`, `+44-(0)20…`), keep digits (any script's, as ASCII; drops `+`), drop a leading `00`; 8–15 digits, not starting with `0` | `PHONE_SHA256` |
94
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
95
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
96
+
97
+ A pre-hashed value only matches if it was hashed from the same form: for
98
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
99
+
100
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
101
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
102
+ and leaves its Segment as it was, in both modes.
103
+
104
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
105
+ warning or error message), never with the values themselves:
106
+
107
+ | Reason | Meaning |
108
+ |---|---|
109
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
110
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
111
+ | `PHONE_NO_DIGITS` | no digits at all |
112
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
113
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
114
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
115
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
116
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
117
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
118
+
119
+ ### Testing against Snap
120
+
121
+ The local files are gitignored in this directory:
122
+
123
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
124
+ - `credentials.json`: written by the consent CLI.
125
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "grantExpiresAt": null, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
126
+
127
+ 1. Consent, as the Snap user who has a role on the test ad account. The
128
+ redirect URI must be an https URI registered on the app; only the URL the
129
+ browser lands on matters.
130
+
131
+ ```sh
132
+ uv run python scripts/consent.py snap --platform-secrets platform_secrets.json \
133
+ --redirect-uri "$REDIRECT_URI" --out credentials.json --config config.json
134
+ ```
135
+ 2. Run:
136
+
137
+ ```sh
138
+ mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
139
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
140
+ --platform-secrets platform_secrets.json --mode validate
141
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
142
+ --platform-secrets platform_secrets.json
143
+ ```
144
+ 3. Live tests, including the check that Snap doesn't rotate refresh tokens:
145
+
146
+ ```sh
147
+ DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
148
+ ```
149
+
150
+ ## Releasing
151
+
152
+ Bump the version with `uv version <version> --no-sync`, which also updates
153
+ `uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
154
+ commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
155
+ uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
156
+ ddc then pins the new version, as
157
+ [ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
158
+ describes.
@@ -0,0 +1,145 @@
1
+ # dq-export-connector
2
+
3
+ Worker logic for the **Export Connector DCR**: one package for every
4
+ Connector Kind, each in its own sub-package with an extra of the same name for
5
+ its dependencies.
6
+
7
+ - The **bucket** kind uploads each Input's dataset to S3, Azure Blob or GCS
8
+ through [`obstore`](https://developmentseed.org/obstore/).
9
+ - The **snap** kind fills one Snap Segment per Input with hashed identifiers,
10
+ through Snap's Marketing API.
11
+
12
+ ddc pins this package by hash in a fully locked `requirements.txt` and runs
13
+ `dq_export_connector.runner.main` in the task's Python environment. It is
14
+ published to PyPI, since the compiled graph installs it from there.
15
+
16
+ - `dq_export_connector.runner`: the entry point. Reads `/input/config.json`,
17
+ `/input/credentials.json` and any platform secret under
18
+ `/input/platform_secrets/`, sets up logging, and dispatches on the Connector
19
+ Kind and the action, then writes what the action reports: a connection
20
+ test's result into `/output`, and an export's receipt and either action's
21
+ warnings and error under `/internal`, as the task's Task Report, Application
22
+ Warnings and Application Error. A run with an error fails.
23
+ - `dq_export_connector.errors`: the error and warning codes the worker
24
+ reports, and `ExportConnectorError`, which stops a run with an error code.
25
+ Codes are named for the situation, not the kind, so any kind can report them.
26
+ - `dq_export_connector.outcome`: collects a run's error, warnings and receipt
27
+ while it runs, and cuts each message to 1,000 characters, and a provider's
28
+ own error to 4,000, once redacted.
29
+ - `dq_export_connector.redact`: keeps every value from the sealed half, and
30
+ URL query strings, out of log lines and result messages. For the ad
31
+ platforms it also masks tokens, `key=secret` pairs, JWTs and SHA-256 hex.
32
+ - `dq_export_connector.datasets`: how an Input's dataset maps to files (a
33
+ stored ZIP, or one raw file).
34
+ - `dq_export_connector.bucket`: the bucket kind (`ValidateConnection` and
35
+ `Export`).
36
+ - `dq_export_connector.audience`: what the ad-platform kinds share: HTTPS to an
37
+ allowlist with retries by idempotency class, OAuth, identifier
38
+ normalisation, and the per-Input sync flow.
39
+ - `dq_export_connector.snap`: the snap kind.
40
+ - `dq_export_connector.models`: the types the worker reads and writes, those
41
+ of every Connector Kind directly in it and a kind's own in its submodule,
42
+ such as `models.bucket`. They are pydantic models generated in
43
+ `dq_export_connector._models` from ddc's JSON schemas, so the config the
44
+ worker reads and the receipt, messages and validation result it writes match
45
+ ddc's Rust types. Regenerate them with `scripts/codegen-models.sh` after the
46
+ types change and `decentriq_dcr_compiler` has been rebuilt; a test fails
47
+ while they are stale.
48
+
49
+ ```sh
50
+ uv run pytest # unit tests, against obstore's in-memory store and a fake Snap API
51
+ uv run pytest -m live # against real buckets and Snap, credentials from the environment
52
+ uv run mypy dq_export_connector tests scripts
53
+ ```
54
+
55
+ ## Snap
56
+
57
+ A Snap connector's config names the ad account and, per Input, a Segment, the
58
+ identifier type its lines hold and a Merge Mode. ddc validates it. The
59
+ credentials are the refresh token of the Snap user who consented; Decentriq's
60
+ Snap app is the `export_connector_snap_app` platform secret
61
+ (`{"clientId", "clientSecret"}`).
62
+
63
+ A run looks each Segment up by name in the ad account and creates it when
64
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
65
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
66
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
67
+ is briefly empty. A run stops at the first Input that fails. When the failure
68
+ came after the Segment changed, the error says so; a rerun is safe in both
69
+ modes. Don't run one connector twice at the same time.
70
+
71
+ An Input is one file of values, or a stored ZIP holding one: one value per
72
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
73
+ empty lines skipped, no header.
74
+
75
+ ### Identifiers
76
+
77
+ | Type | Normalisation before SHA-256 | Snap schema |
78
+ |---|---|---|
79
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
80
+ | `PHONE` | drop a `(0)` right after the country code (`+44 (0)20…`, `+44-(0)20…`), keep digits (any script's, as ASCII; drops `+`), drop a leading `00`; 8–15 digits, not starting with `0` | `PHONE_SHA256` |
81
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
82
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
83
+
84
+ A pre-hashed value only matches if it was hashed from the same form: for
85
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
86
+
87
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
88
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
89
+ and leaves its Segment as it was, in both modes.
90
+
91
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
92
+ warning or error message), never with the values themselves:
93
+
94
+ | Reason | Meaning |
95
+ |---|---|
96
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
97
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
98
+ | `PHONE_NO_DIGITS` | no digits at all |
99
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
100
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
101
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
102
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
103
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
104
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
105
+
106
+ ### Testing against Snap
107
+
108
+ The local files are gitignored in this directory:
109
+
110
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
111
+ - `credentials.json`: written by the consent CLI.
112
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "grantExpiresAt": null, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
113
+
114
+ 1. Consent, as the Snap user who has a role on the test ad account. The
115
+ redirect URI must be an https URI registered on the app; only the URL the
116
+ browser lands on matters.
117
+
118
+ ```sh
119
+ uv run python scripts/consent.py snap --platform-secrets platform_secrets.json \
120
+ --redirect-uri "$REDIRECT_URI" --out credentials.json --config config.json
121
+ ```
122
+ 2. Run:
123
+
124
+ ```sh
125
+ mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
126
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
127
+ --platform-secrets platform_secrets.json --mode validate
128
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
129
+ --platform-secrets platform_secrets.json
130
+ ```
131
+ 3. Live tests, including the check that Snap doesn't rotate refresh tokens:
132
+
133
+ ```sh
134
+ DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
135
+ ```
136
+
137
+ ## Releasing
138
+
139
+ Bump the version with `uv version <version> --no-sync`, which also updates
140
+ `uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
141
+ commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
142
+ uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
143
+ ddc then pins the new version, as
144
+ [ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
145
+ describes.
@@ -56,6 +56,19 @@ class BucketExportCredentials(
56
56
  ]
57
57
 
58
58
 
59
+ class SnapExportCredentials(BaseModel):
60
+ model_config = ConfigDict(
61
+ populate_by_name=True,
62
+ )
63
+ refresh_token: Annotated[
64
+ str,
65
+ Field(
66
+ alias='refreshToken',
67
+ description="The refresh token of the Snap user who consented. Snap doesn't rotate it.",
68
+ ),
69
+ ]
70
+
71
+
59
72
  class ExportConnectorCredentialsBucket(BaseModel):
60
73
  model_config = ConfigDict(
61
74
  populate_by_name=True,
@@ -64,9 +77,19 @@ class ExportConnectorCredentialsBucket(BaseModel):
64
77
  type: Literal['bucket']
65
78
 
66
79
 
67
- class ExportConnectorCredentials(RootModel[ExportConnectorCredentialsBucket]):
80
+ class ExportConnectorCredentialsSnap(BaseModel):
81
+ model_config = ConfigDict(
82
+ populate_by_name=True,
83
+ )
84
+ credentials: SnapExportCredentials
85
+ type: Literal['snap']
86
+
87
+
88
+ class ExportConnectorCredentials(
89
+ RootModel[ExportConnectorCredentialsBucket | ExportConnectorCredentialsSnap]
90
+ ):
68
91
  root: Annotated[
69
- ExportConnectorCredentialsBucket,
92
+ ExportConnectorCredentialsBucket | ExportConnectorCredentialsSnap,
70
93
  Field(
71
94
  description='Keyed by Connector Kind, in step with [`ExportConnectorKind`]. The worker\nreads it at `/input/credentials.json`.',
72
95
  title='ExportConnectorCredentials',
@@ -3,9 +3,11 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ from enum import Enum
6
7
  from typing import Annotated, Literal
7
8
 
8
9
  from pydantic import BaseModel, ConfigDict, Field, RootModel
10
+ from typing_extensions import TypeAliasType
9
11
 
10
12
 
11
13
  class BucketConnectionS3(BaseModel):
@@ -62,6 +64,70 @@ class ExportTotals(BaseModel):
62
64
  ] = None
63
65
 
64
66
 
67
+ class MergeMode(Enum):
68
+ add = 'ADD'
69
+ replace = 'REPLACE'
70
+
71
+
72
+ InvalidReasonsAdditionalProperty = TypeAliasType(
73
+ "InvalidReasonsAdditionalProperty", Annotated[int, Field(ge=0)]
74
+ )
75
+
76
+
77
+ class SegmentCounts(BaseModel):
78
+ model_config = ConfigDict(
79
+ populate_by_name=True,
80
+ )
81
+ invalid: Annotated[int, Field(ge=0)]
82
+ invalid_reasons: Annotated[
83
+ dict[str, InvalidReasonsAdditionalProperty],
84
+ Field(
85
+ alias='invalidReasons',
86
+ description='Invalid rows per reason, such as `EMAIL_NO_AT_SIGN`.',
87
+ ),
88
+ ]
89
+ rejected_by_platform: Annotated[
90
+ int | None,
91
+ Field(
92
+ alias='rejectedByPlatform',
93
+ description="`None` where the platform doesn't say.",
94
+ ge=0,
95
+ ),
96
+ ] = None
97
+ rows: Annotated[
98
+ int, Field(description='Non-empty lines read from the Input.', ge=0)
99
+ ]
100
+ submitted: Annotated[
101
+ int,
102
+ Field(
103
+ description='Values sent to the platform, also from an Input that failed partway.',
104
+ ge=0,
105
+ ),
106
+ ]
107
+ valid: Annotated[int, Field(ge=0)]
108
+
109
+
110
+ class SegmentTotals(BaseModel):
111
+ model_config = ConfigDict(
112
+ populate_by_name=True,
113
+ )
114
+ invalid: Annotated[int, Field(ge=0)]
115
+ rows: Annotated[int, Field(ge=0)]
116
+ submitted: Annotated[int, Field(ge=0)]
117
+ valid: Annotated[int, Field(ge=0)]
118
+
119
+
120
+ class SnapSegmentStatus(BaseModel):
121
+ model_config = ConfigDict(
122
+ populate_by_name=True,
123
+ )
124
+ approximate_number_users: Annotated[
125
+ int | None, Field(alias='approximateNumberUsers', ge=0)
126
+ ] = None
127
+ targetable_status: Annotated[str | None, Field(alias='targetableStatus')] = None
128
+ upload_status: Annotated[str | None, Field(alias='uploadStatus')] = None
129
+
130
+
65
131
  class BucketInputReceipt(BaseModel):
66
132
  model_config = ConfigDict(
67
133
  populate_by_name=True,
@@ -95,8 +161,29 @@ class ExportReceiptV0Bucket(BaseModel):
95
161
  type: Literal['BUCKET']
96
162
 
97
163
 
98
- class ExportReceiptV0(RootModel[ExportReceiptV0Bucket]):
99
- root: ExportReceiptV0Bucket
164
+ class SnapInputReceipt(BaseModel):
165
+ model_config = ConfigDict(
166
+ populate_by_name=True,
167
+ )
168
+ counts: SegmentCounts
169
+ created: Annotated[bool, Field(description='Whether this run created the Segment.')]
170
+ leaf_id: Annotated[str, Field(alias='leafId')]
171
+ merge_mode: Annotated[MergeMode, Field(alias='mergeMode')]
172
+ segment_id: Annotated[
173
+ str | None,
174
+ Field(
175
+ alias='segmentId',
176
+ description='`None` until the run found or created the Segment.',
177
+ ),
178
+ ] = None
179
+ segment_name: Annotated[str, Field(alias='segmentName')]
180
+ segment_status: Annotated[
181
+ SnapSegmentStatus | None,
182
+ Field(
183
+ alias='segmentStatus',
184
+ description='The Segment as Snap reported it after the upload.',
185
+ ),
186
+ ] = None
100
187
 
101
188
 
102
189
  class VersionedExportReceiptV0Bucket(BaseModel):
@@ -119,9 +206,22 @@ class VersionedExportReceiptV0Bucket(BaseModel):
119
206
  type: Literal['BUCKET']
120
207
 
121
208
 
122
- class ExportReceipt(RootModel[VersionedExportReceiptV0Bucket]):
209
+ class VersionedExportReceiptV0Snap(BaseModel):
210
+ model_config = ConfigDict(
211
+ populate_by_name=True,
212
+ )
213
+ version: Literal['V0']
214
+ ad_account_id: Annotated[str, Field(alias='adAccountId')]
215
+ inputs: list[SnapInputReceipt]
216
+ totals: SegmentTotals
217
+ type: Literal['SNAP']
218
+
219
+
220
+ class ExportReceipt(
221
+ RootModel[VersionedExportReceiptV0Bucket | VersionedExportReceiptV0Snap]
222
+ ):
123
223
  root: Annotated[
124
- VersionedExportReceiptV0Bucket,
224
+ VersionedExportReceiptV0Bucket | VersionedExportReceiptV0Snap,
125
225
  Field(
126
226
  description='What an Export Connector Run sent and where. api-platform reads it in\nplaintext, so it holds only metadata, never dataset values. A released\nversion never changes: a change is a new version, and readers keep reading\nevery version ever written.',
127
227
  title='ExportReceipt',
@@ -145,3 +245,26 @@ class BucketExportReceiptV0(BaseModel):
145
245
  ] = None
146
246
  inputs: list[BucketInputReceipt]
147
247
  totals: ExportTotals
248
+
249
+
250
+ class ExportReceiptV0Snap(BaseModel):
251
+ model_config = ConfigDict(
252
+ populate_by_name=True,
253
+ )
254
+ ad_account_id: Annotated[str, Field(alias='adAccountId')]
255
+ inputs: list[SnapInputReceipt]
256
+ totals: SegmentTotals
257
+ type: Literal['SNAP']
258
+
259
+
260
+ class ExportReceiptV0(RootModel[ExportReceiptV0Bucket | ExportReceiptV0Snap]):
261
+ root: ExportReceiptV0Bucket | ExportReceiptV0Snap
262
+
263
+
264
+ class SnapExportReceiptV0(BaseModel):
265
+ model_config = ConfigDict(
266
+ populate_by_name=True,
267
+ )
268
+ ad_account_id: Annotated[str, Field(alias='adAccountId')]
269
+ inputs: list[SnapInputReceipt]
270
+ totals: SegmentTotals
@@ -3,6 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ from enum import Enum
6
7
  from typing import Annotated, Literal
7
8
 
8
9
  from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel
@@ -72,10 +73,6 @@ class ExportConnectorKindBucket(BaseModel):
72
73
  type: Literal['bucket']
73
74
 
74
75
 
75
- class ExportConnectorKind(RootModel[ExportConnectorKindBucket]):
76
- root: ExportConnectorKindBucket
77
-
78
-
79
76
  class ExportParamsBucket(BaseModel):
80
77
  model_config = ConfigDict(
81
78
  populate_by_name=True,
@@ -83,8 +80,31 @@ class ExportParamsBucket(BaseModel):
83
80
  type: Literal['bucket']
84
81
 
85
82
 
86
- class ExportParams(RootModel[ExportParamsBucket]):
87
- root: ExportParamsBucket
83
+ class ExportParamsSnap(BaseModel):
84
+ model_config = ConfigDict(
85
+ populate_by_name=True,
86
+ )
87
+ type: Literal['snap']
88
+
89
+
90
+ class ExportParams(RootModel[ExportParamsBucket | ExportParamsSnap]):
91
+ root: ExportParamsBucket | ExportParamsSnap
92
+
93
+
94
+ class IdentifierType(Enum):
95
+ email = 'EMAIL'
96
+ email_sha256 = 'EMAIL_SHA256'
97
+ phone = 'PHONE'
98
+ phone_sha256 = 'PHONE_SHA256'
99
+ idfa = 'IDFA'
100
+ idfa_sha256 = 'IDFA_SHA256'
101
+ gaid = 'GAID'
102
+ gaid_sha256 = 'GAID_SHA256'
103
+
104
+
105
+ class MergeMode(Enum):
106
+ add = 'ADD'
107
+ replace = 'REPLACE'
88
108
 
89
109
 
90
110
  class ProvisionedPolicy(BaseModel):
@@ -105,6 +125,30 @@ class ProvisionedPolicy(BaseModel):
105
125
  ]
106
126
 
107
127
 
128
+ class SnapInput(BaseModel):
129
+ model_config = ConfigDict(
130
+ populate_by_name=True,
131
+ )
132
+ identifier_type: Annotated[IdentifierType, Field(alias='identifierType')]
133
+ leaf_id: Annotated[str, Field(alias='leafId')]
134
+ merge_mode: Annotated[MergeMode, Field(alias='mergeMode')]
135
+ retention_days: Annotated[
136
+ int | None,
137
+ Field(
138
+ alias='retentionDays',
139
+ description='Applied when the Segment is created.',
140
+ ge=0,
141
+ ),
142
+ ] = None
143
+ segment_name: Annotated[
144
+ str,
145
+ Field(
146
+ alias='segmentName',
147
+ description='The Segment is found by this name in the ad account, or created.',
148
+ ),
149
+ ]
150
+
151
+
108
152
  class ValidateConnectionParamsBucket(BaseModel):
109
153
  model_config = ConfigDict(
110
154
  populate_by_name=True,
@@ -112,8 +156,17 @@ class ValidateConnectionParamsBucket(BaseModel):
112
156
  type: Literal['bucket']
113
157
 
114
158
 
115
- class ValidateConnectionParams(RootModel[ValidateConnectionParamsBucket]):
116
- root: ValidateConnectionParamsBucket
159
+ class ValidateConnectionParamsSnap(BaseModel):
160
+ model_config = ConfigDict(
161
+ populate_by_name=True,
162
+ )
163
+ type: Literal['snap']
164
+
165
+
166
+ class ValidateConnectionParams(
167
+ RootModel[ValidateConnectionParamsBucket | ValidateConnectionParamsSnap]
168
+ ):
169
+ root: ValidateConnectionParamsBucket | ValidateConnectionParamsSnap
117
170
 
118
171
 
119
172
  class BucketExportConfig(BaseModel):
@@ -178,6 +231,47 @@ class ExportConnectorDcrComputeAction(
178
231
  ]
179
232
 
180
233
 
234
+ class ExportConnectorKindSnap(BaseModel):
235
+ model_config = ConfigDict(
236
+ populate_by_name=True,
237
+ )
238
+ ad_account_id: Annotated[
239
+ str, Field(alias='adAccountId', description='A canonical, lowercase UUID.')
240
+ ]
241
+ grant_expires_at: Annotated[
242
+ str | None,
243
+ Field(
244
+ alias='grantExpiresAt',
245
+ description='RFC 3339. When the grant behind the credentials expires; runs warn as\nit nears.',
246
+ ),
247
+ ] = None
248
+ inputs: list[SnapInput]
249
+ type: Literal['snap']
250
+
251
+
252
+ class ExportConnectorKind(
253
+ RootModel[ExportConnectorKindBucket | ExportConnectorKindSnap]
254
+ ):
255
+ root: ExportConnectorKindBucket | ExportConnectorKindSnap
256
+
257
+
258
+ class SnapExportConfig(BaseModel):
259
+ model_config = ConfigDict(
260
+ populate_by_name=True,
261
+ )
262
+ ad_account_id: Annotated[
263
+ str, Field(alias='adAccountId', description='A canonical, lowercase UUID.')
264
+ ]
265
+ grant_expires_at: Annotated[
266
+ str | None,
267
+ Field(
268
+ alias='grantExpiresAt',
269
+ description='RFC 3339. When the grant behind the credentials expires; runs warn as\nit nears.',
270
+ ),
271
+ ] = None
272
+ inputs: list[SnapInput]
273
+
274
+
181
275
  class ExportWorkerConfig(BaseModel):
182
276
  model_config = ConfigDict(
183
277
  populate_by_name=True,