dq-export-connector 0.1.0.dev32__tar.gz → 0.1.0.dev34__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 (70) hide show
  1. dq_export_connector-0.1.0.dev34/.gitignore +5 -0
  2. dq_export_connector-0.1.0.dev34/PKG-INFO +158 -0
  3. dq_export_connector-0.1.0.dev34/README.md +145 -0
  4. dq_export_connector-0.1.0.dev34/dq_export_connector/_models/destination_account_listing.py +25 -0
  5. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/_models/export_connector_credentials.py +63 -2
  6. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/_models/export_receipt.py +127 -4
  7. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/_models/export_worker_config.py +130 -18
  8. dq_export_connector-0.1.0.dev34/dq_export_connector/audience/classify.py +81 -0
  9. dq_export_connector-0.1.0.dev34/dq_export_connector/audience/http.py +237 -0
  10. dq_export_connector-0.1.0.dev34/dq_export_connector/audience/identifiers.py +121 -0
  11. dq_export_connector-0.1.0.dev34/dq_export_connector/audience/inputs.py +80 -0
  12. dq_export_connector-0.1.0.dev34/dq_export_connector/audience/sync.py +312 -0
  13. dq_export_connector-0.1.0.dev34/dq_export_connector/bucket/__init__.py +0 -0
  14. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/bucket/export.py +1 -1
  15. {dq_export_connector-0.1.0.dev32/dq_export_connector/bucket → dq_export_connector-0.1.0.dev34/dq_export_connector}/datasets.py +5 -1
  16. dq_export_connector-0.1.0.dev34/dq_export_connector/errors.py +109 -0
  17. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/log.py +4 -4
  18. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/models/__init__.py +7 -0
  19. dq_export_connector-0.1.0.dev34/dq_export_connector/models/snap.py +48 -0
  20. dq_export_connector-0.1.0.dev34/dq_export_connector/oauth.py +235 -0
  21. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/outcome.py +8 -20
  22. dq_export_connector-0.1.0.dev34/dq_export_connector/redact.py +128 -0
  23. dq_export_connector-0.1.0.dev34/dq_export_connector/runner.py +263 -0
  24. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/__init__.py +0 -0
  25. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/accounts.py +18 -0
  26. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/client.py +169 -0
  27. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/destination.py +118 -0
  28. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/export.py +127 -0
  29. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/session.py +103 -0
  30. dq_export_connector-0.1.0.dev34/dq_export_connector/snap/validate.py +29 -0
  31. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/pyproject.toml +11 -8
  32. dq_export_connector-0.1.0.dev34/scripts/_local.py +115 -0
  33. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/scripts/codegen-models.sh +2 -2
  34. dq_export_connector-0.1.0.dev34/scripts/run_local.py +54 -0
  35. dq_export_connector-0.1.0.dev34/tests/__init__.py +0 -0
  36. dq_export_connector-0.1.0.dev34/tests/conftest.py +37 -0
  37. dq_export_connector-0.1.0.dev34/tests/fakes/__init__.py +0 -0
  38. dq_export_connector-0.1.0.dev34/tests/fakes/snap_fake.py +285 -0
  39. dq_export_connector-0.1.0.dev34/tests/test_http_and_oauth.py +359 -0
  40. dq_export_connector-0.1.0.dev34/tests/test_identifiers_and_inputs.py +118 -0
  41. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_live_buckets.py +44 -8
  42. dq_export_connector-0.1.0.dev34/tests/test_live_snap.py +137 -0
  43. dq_export_connector-0.1.0.dev34/tests/test_oauth.py +193 -0
  44. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_redact.py +9 -0
  45. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_runner.py +72 -46
  46. dq_export_connector-0.1.0.dev34/tests/test_scripts.py +22 -0
  47. dq_export_connector-0.1.0.dev34/tests/test_snap_runner.py +652 -0
  48. dq_export_connector-0.1.0.dev34/tests/test_sync_input.py +171 -0
  49. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/uv.lock +184 -238
  50. dq_export_connector-0.1.0.dev32/.gitignore +0 -63
  51. dq_export_connector-0.1.0.dev32/PKG-INFO +0 -64
  52. dq_export_connector-0.1.0.dev32/README.md +0 -53
  53. dq_export_connector-0.1.0.dev32/dq_export_connector/errors.py +0 -81
  54. dq_export_connector-0.1.0.dev32/dq_export_connector/redact.py +0 -69
  55. dq_export_connector-0.1.0.dev32/dq_export_connector/runner.py +0 -159
  56. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/.python-version +0 -0
  57. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/__init__.py +0 -0
  58. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/_models/__init__.py +0 -0
  59. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/_models/application_error.py +0 -0
  60. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/_models/application_warning.py +0 -0
  61. {dq_export_connector-0.1.0.dev32/dq_export_connector/bucket → dq_export_connector-0.1.0.dev34/dq_export_connector/audience}/__init__.py +0 -0
  62. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/bucket/paths.py +0 -0
  63. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/bucket/store.py +0 -0
  64. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/bucket/upload.py +0 -0
  65. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/bucket/validate.py +0 -0
  66. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/dq_export_connector/models/bucket.py +0 -0
  67. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_models_are_current.py +0 -0
  68. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_paths.py +0 -0
  69. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_store.py +0 -0
  70. {dq_export_connector-0.1.0.dev32 → dq_export_connector-0.1.0.dev34}/tests/test_upload.py +0 -0
@@ -0,0 +1,5 @@
1
+ # Local secrets for 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.dev34
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, for a kind that uses OAuth, the OAuth App at
31
+ `/input/oauth_app.json`, sets up logging, and dispatches on the Connector
32
+ Kind and the action. It writes a `list` mode connection test's Destination
33
+ Account Listing into `/output`, and under `/internal` an export's receipt,
34
+ and either action's warnings and error, as the task's Task Report,
35
+ Application Warnings and Application Error. An action with an error also
36
+ writes it as `/internal/safe_error`, `CODE: message`, which the container
37
+ worker shows as the task's `error`, and exits with 1.
38
+ - `dq_export_connector.errors`: the error and warning codes the worker
39
+ reports, `ExportConnectorError`, which stops an action with an error code,
40
+ and `ExportConnectorWarning`. Each becomes an Application Error or Warning
41
+ with its credentials masked, its message cut to 1,000 characters and a
42
+ provider's own error to 4,000. Codes are named for the situation, not the
43
+ kind, so any kind can report them.
44
+ - `dq_export_connector.outcome`: collects a run's error, warnings and receipt
45
+ while it runs.
46
+ - `dq_export_connector.redact`: keeps every value from the sealed half, and
47
+ URL query strings, out of log lines and result messages. For the ad
48
+ platforms it also masks tokens, `key=secret` pairs, JWTs and SHA-256 hex.
49
+ - `dq_export_connector.datasets`: how an Input's dataset maps to files (a
50
+ stored ZIP, or one raw file).
51
+ - `dq_export_connector.bucket`: the bucket kind (`ValidateConnection` and
52
+ `Export`).
53
+ - `dq_export_connector.audience`: what the ad-platform kinds share: HTTPS to an
54
+ allowlist with retries by idempotency class, OAuth, identifier
55
+ normalisation, and the per-Input sync flow.
56
+ - `dq_export_connector.snap`: the snap kind.
57
+ - `dq_export_connector.models`: the types the worker reads and writes, those
58
+ of every Connector Kind directly in it and a kind's own in its submodule,
59
+ such as `models.bucket`. They are pydantic models generated in
60
+ `dq_export_connector._models` from ddc's JSON schemas, so the config the
61
+ worker reads and the receipt, warnings and errors it writes match
62
+ ddc's Rust types. Regenerate them with `scripts/codegen-models.sh` after the
63
+ types change and `decentriq_dcr_compiler` has been rebuilt; a test fails
64
+ while they are stale.
65
+
66
+ ```sh
67
+ uv run pytest # unit tests, against obstore's in-memory store and a fake Snap API
68
+ uv run pytest -m live # against real buckets and Snap, credentials from the environment
69
+ uv run mypy dq_export_connector tests scripts
70
+ ```
71
+
72
+ ## Snap
73
+
74
+ A Snap connector's config names the ad account (set after consent, from a
75
+ `ValidateConnection` in `list` mode) and, per Input, a Segment, the identifier type its
76
+ lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
77
+ Grant of the Snap user who consented; each run turns it into an Access Token
78
+ with `dq_export_connector.oauth`. Decentriq's Snap app is the
79
+ `export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
80
+ mounted at `/input/oauth_app.json`. `ValidateConnection` in `list` mode lists
81
+ the ad accounts of every organization the grant reaches; in `check` mode it
82
+ reads the picked one.
83
+
84
+ A run looks each Segment up by name in the ad account and creates it when
85
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
86
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
87
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
88
+ is briefly empty. A run stops at the first Input that fails. When the failure
89
+ came after the Segment changed, the error says so; a rerun is safe in both
90
+ modes. Don't run one connector twice at the same time.
91
+
92
+ An Input is one file of values, or a stored ZIP holding one: one value per
93
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
94
+ empty lines skipped, no header.
95
+
96
+ ### Identifiers
97
+
98
+ | Type | Normalisation before SHA-256 | Snap schema |
99
+ |---|---|---|
100
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
101
+ | `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` |
102
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
103
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
104
+
105
+ A pre-hashed value only matches if it was hashed from the same form: for
106
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
107
+
108
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
109
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
110
+ and leaves its Segment as it was, in both modes.
111
+
112
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
113
+ warning or error message), never with the values themselves:
114
+
115
+ | Reason | Meaning |
116
+ |---|---|
117
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
118
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
119
+ | `PHONE_NO_DIGITS` | no digits at all |
120
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
121
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
122
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
123
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
124
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
125
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
126
+
127
+ ### Testing against Snap
128
+
129
+ The local files are gitignored in this directory:
130
+
131
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
132
+ - `credentials.json`: `{"type": "snap", "credentials": {"refreshToken": …}}`, a refresh token the owner got through consent on a dev environment. Snap doesn't rotate it, so it can be reused.
133
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
134
+
135
+ 1. 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
+ 2. 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, for a kind that uses OAuth, the OAuth App at
18
+ `/input/oauth_app.json`, sets up logging, and dispatches on the Connector
19
+ Kind and the action. It writes a `list` mode connection test's Destination
20
+ Account Listing into `/output`, and under `/internal` an export's receipt,
21
+ and either action's warnings and error, as the task's Task Report,
22
+ Application Warnings and Application Error. An action with an error also
23
+ writes it as `/internal/safe_error`, `CODE: message`, which the container
24
+ worker shows as the task's `error`, and exits with 1.
25
+ - `dq_export_connector.errors`: the error and warning codes the worker
26
+ reports, `ExportConnectorError`, which stops an action with an error code,
27
+ and `ExportConnectorWarning`. Each becomes an Application Error or Warning
28
+ with its credentials masked, its message cut to 1,000 characters and a
29
+ provider's own error to 4,000. Codes are named for the situation, not the
30
+ kind, so any kind can report them.
31
+ - `dq_export_connector.outcome`: collects a run's error, warnings and receipt
32
+ while it runs.
33
+ - `dq_export_connector.redact`: keeps every value from the sealed half, and
34
+ URL query strings, out of log lines and result messages. For the ad
35
+ platforms it also masks tokens, `key=secret` pairs, JWTs and SHA-256 hex.
36
+ - `dq_export_connector.datasets`: how an Input's dataset maps to files (a
37
+ stored ZIP, or one raw file).
38
+ - `dq_export_connector.bucket`: the bucket kind (`ValidateConnection` and
39
+ `Export`).
40
+ - `dq_export_connector.audience`: what the ad-platform kinds share: HTTPS to an
41
+ allowlist with retries by idempotency class, OAuth, identifier
42
+ normalisation, and the per-Input sync flow.
43
+ - `dq_export_connector.snap`: the snap kind.
44
+ - `dq_export_connector.models`: the types the worker reads and writes, those
45
+ of every Connector Kind directly in it and a kind's own in its submodule,
46
+ such as `models.bucket`. They are pydantic models generated in
47
+ `dq_export_connector._models` from ddc's JSON schemas, so the config the
48
+ worker reads and the receipt, warnings and errors it writes match
49
+ ddc's Rust types. Regenerate them with `scripts/codegen-models.sh` after the
50
+ types change and `decentriq_dcr_compiler` has been rebuilt; a test fails
51
+ while they are stale.
52
+
53
+ ```sh
54
+ uv run pytest # unit tests, against obstore's in-memory store and a fake Snap API
55
+ uv run pytest -m live # against real buckets and Snap, credentials from the environment
56
+ uv run mypy dq_export_connector tests scripts
57
+ ```
58
+
59
+ ## Snap
60
+
61
+ A Snap connector's config names the ad account (set after consent, from a
62
+ `ValidateConnection` in `list` mode) and, per Input, a Segment, the identifier type its
63
+ lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
64
+ Grant of the Snap user who consented; each run turns it into an Access Token
65
+ with `dq_export_connector.oauth`. Decentriq's Snap app is the
66
+ `export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
67
+ mounted at `/input/oauth_app.json`. `ValidateConnection` in `list` mode lists
68
+ the ad accounts of every organization the grant reaches; in `check` mode it
69
+ reads the picked one.
70
+
71
+ A run looks each Segment up by name in the ad account and creates it when
72
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
73
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
74
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
75
+ is briefly empty. A run stops at the first Input that fails. When the failure
76
+ came after the Segment changed, the error says so; a rerun is safe in both
77
+ modes. Don't run one connector twice at the same time.
78
+
79
+ An Input is one file of values, or a stored ZIP holding one: one value per
80
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
81
+ empty lines skipped, no header.
82
+
83
+ ### Identifiers
84
+
85
+ | Type | Normalisation before SHA-256 | Snap schema |
86
+ |---|---|---|
87
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
88
+ | `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` |
89
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
90
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
91
+
92
+ A pre-hashed value only matches if it was hashed from the same form: for
93
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
94
+
95
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
96
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
97
+ and leaves its Segment as it was, in both modes.
98
+
99
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
100
+ warning or error message), never with the values themselves:
101
+
102
+ | Reason | Meaning |
103
+ |---|---|
104
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
105
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
106
+ | `PHONE_NO_DIGITS` | no digits at all |
107
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
108
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
109
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
110
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
111
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
112
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
113
+
114
+ ### Testing against Snap
115
+
116
+ The local files are gitignored in this directory:
117
+
118
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
119
+ - `credentials.json`: `{"type": "snap", "credentials": {"refreshToken": …}}`, a refresh token the owner got through consent on a dev environment. Snap doesn't rotate it, so it can be reused.
120
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
121
+
122
+ 1. 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
+ 2. 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.
@@ -0,0 +1,25 @@
1
+ # generated by datamodel-codegen:
2
+ # filename: destination_account_listing.json
3
+
4
+ from __future__ import annotations
5
+
6
+ from typing import Annotated
7
+
8
+ from pydantic import BaseModel, ConfigDict, Field
9
+
10
+
11
+ class DestinationAccount(BaseModel):
12
+ model_config = ConfigDict(
13
+ populate_by_name=True,
14
+ )
15
+ id: str
16
+ name: str
17
+
18
+
19
+ class DestinationAccountListing(BaseModel):
20
+ model_config = ConfigDict(
21
+ populate_by_name=True,
22
+ )
23
+ destination_accounts: Annotated[
24
+ list[DestinationAccount], Field(alias='destinationAccounts')
25
+ ]
@@ -56,6 +56,57 @@ class BucketExportCredentials(
56
56
  ]
57
57
 
58
58
 
59
+ class GrantTokenRefreshToken(BaseModel):
60
+ model_config = ConfigDict(
61
+ populate_by_name=True,
62
+ )
63
+ type: Literal['refreshToken']
64
+ value: str
65
+
66
+
67
+ class GrantTokenAccessToken(BaseModel):
68
+ model_config = ConfigDict(
69
+ populate_by_name=True,
70
+ )
71
+ type: Literal['accessToken']
72
+ value: str
73
+
74
+
75
+ class GrantToken(RootModel[GrantTokenRefreshToken | GrantTokenAccessToken]):
76
+ root: GrantTokenRefreshToken | GrantTokenAccessToken
77
+
78
+
79
+ class OAuthGrant(BaseModel):
80
+ model_config = ConfigDict(
81
+ populate_by_name=True,
82
+ )
83
+ client_id: Annotated[
84
+ str,
85
+ Field(
86
+ alias='clientId',
87
+ description='The OAuth App the grant was issued to; it only works with that app.',
88
+ ),
89
+ ]
90
+ obtained_at: Annotated[
91
+ str, Field(alias='obtainedAt', description='RFC 3339, in UTC.')
92
+ ]
93
+ token: GrantToken
94
+
95
+
96
+ class SnapExportCredentialsOauth(BaseModel):
97
+ model_config = ConfigDict(
98
+ populate_by_name=True,
99
+ )
100
+ grant: OAuthGrant
101
+ type: Literal['oauth']
102
+
103
+
104
+ class SnapExportCredentials(RootModel[SnapExportCredentialsOauth]):
105
+ root: Annotated[
106
+ SnapExportCredentialsOauth, Field(description='What is sealed for Snap.')
107
+ ]
108
+
109
+
59
110
  class ExportConnectorCredentialsBucket(BaseModel):
60
111
  model_config = ConfigDict(
61
112
  populate_by_name=True,
@@ -64,9 +115,19 @@ class ExportConnectorCredentialsBucket(BaseModel):
64
115
  type: Literal['bucket']
65
116
 
66
117
 
67
- class ExportConnectorCredentials(RootModel[ExportConnectorCredentialsBucket]):
118
+ class ExportConnectorCredentialsSnap(BaseModel):
119
+ model_config = ConfigDict(
120
+ populate_by_name=True,
121
+ )
122
+ credentials: SnapExportCredentials
123
+ type: Literal['snap']
124
+
125
+
126
+ class ExportConnectorCredentials(
127
+ RootModel[ExportConnectorCredentialsBucket | ExportConnectorCredentialsSnap]
128
+ ):
68
129
  root: Annotated[
69
- ExportConnectorCredentialsBucket,
130
+ ExportConnectorCredentialsBucket | ExportConnectorCredentialsSnap,
70
131
  Field(
71
132
  description='Keyed by Connector Kind, in step with [`ExportConnectorKind`]. The worker\nreads it at `/input/credentials.json`.',
72
133
  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