dq-export-connector 0.1.0.dev26__tar.gz → 0.1.0.dev28__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 (69) hide show
  1. dq_export_connector-0.1.0.dev28/.gitignore +5 -0
  2. dq_export_connector-0.1.0.dev28/PKG-INFO +153 -0
  3. dq_export_connector-0.1.0.dev28/README.md +140 -0
  4. dq_export_connector-0.1.0.dev28/dq_export_connector/_models/destination_accounts.py +25 -0
  5. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/_models/export_connector_credentials.py +63 -2
  6. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/_models/export_receipt.py +127 -4
  7. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/_models/export_worker_config.py +128 -10
  8. dq_export_connector-0.1.0.dev28/dq_export_connector/_models/snap_validation_result.py +37 -0
  9. dq_export_connector-0.1.0.dev28/dq_export_connector/audience/classify.py +81 -0
  10. dq_export_connector-0.1.0.dev28/dq_export_connector/audience/http.py +237 -0
  11. dq_export_connector-0.1.0.dev28/dq_export_connector/audience/identifiers.py +121 -0
  12. dq_export_connector-0.1.0.dev28/dq_export_connector/audience/inputs.py +80 -0
  13. dq_export_connector-0.1.0.dev28/dq_export_connector/audience/sync.py +313 -0
  14. dq_export_connector-0.1.0.dev28/dq_export_connector/bucket/__init__.py +0 -0
  15. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/bucket/export.py +1 -1
  16. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/errors.py +33 -3
  17. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/models/__init__.py +7 -0
  18. dq_export_connector-0.1.0.dev28/dq_export_connector/models/snap.py +50 -0
  19. dq_export_connector-0.1.0.dev28/dq_export_connector/oauth.py +229 -0
  20. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/outcome.py +11 -6
  21. dq_export_connector-0.1.0.dev28/dq_export_connector/redact.py +123 -0
  22. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/runner.py +123 -14
  23. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/__init__.py +0 -0
  24. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/accounts.py +18 -0
  25. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/client.py +169 -0
  26. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/destination.py +118 -0
  27. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/export.py +127 -0
  28. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/session.py +103 -0
  29. dq_export_connector-0.1.0.dev28/dq_export_connector/snap/validate.py +29 -0
  30. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/pyproject.toml +11 -3
  31. dq_export_connector-0.1.0.dev28/scripts/_local.py +121 -0
  32. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/scripts/codegen-models.sh +2 -2
  33. dq_export_connector-0.1.0.dev28/scripts/run_local.py +54 -0
  34. dq_export_connector-0.1.0.dev28/tests/__init__.py +0 -0
  35. dq_export_connector-0.1.0.dev28/tests/conftest.py +37 -0
  36. dq_export_connector-0.1.0.dev28/tests/fakes/__init__.py +0 -0
  37. dq_export_connector-0.1.0.dev28/tests/fakes/snap_fake.py +285 -0
  38. dq_export_connector-0.1.0.dev28/tests/test_http_and_oauth.py +359 -0
  39. dq_export_connector-0.1.0.dev28/tests/test_identifiers_and_inputs.py +118 -0
  40. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/tests/test_live_buckets.py +2 -3
  41. dq_export_connector-0.1.0.dev28/tests/test_live_snap.py +137 -0
  42. dq_export_connector-0.1.0.dev28/tests/test_oauth.py +185 -0
  43. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/tests/test_redact.py +5 -0
  44. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/tests/test_runner.py +19 -0
  45. dq_export_connector-0.1.0.dev28/tests/test_scripts.py +22 -0
  46. dq_export_connector-0.1.0.dev28/tests/test_snap_runner.py +648 -0
  47. dq_export_connector-0.1.0.dev28/tests/test_sync_input.py +171 -0
  48. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/uv.lock +195 -4
  49. dq_export_connector-0.1.0.dev26/.gitignore +0 -63
  50. dq_export_connector-0.1.0.dev26/PKG-INFO +0 -61
  51. dq_export_connector-0.1.0.dev26/README.md +0 -50
  52. dq_export_connector-0.1.0.dev26/dq_export_connector/redact.py +0 -69
  53. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/.python-version +0 -0
  54. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/__init__.py +0 -0
  55. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/_models/__init__.py +0 -0
  56. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/_models/application_message.py +0 -0
  57. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/_models/bucket_validation_result.py +0 -0
  58. {dq_export_connector-0.1.0.dev26/dq_export_connector/bucket → dq_export_connector-0.1.0.dev28/dq_export_connector/audience}/__init__.py +0 -0
  59. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/bucket/paths.py +0 -0
  60. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/bucket/store.py +0 -0
  61. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/bucket/upload.py +0 -0
  62. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/bucket/validate.py +0 -0
  63. {dq_export_connector-0.1.0.dev26/dq_export_connector/bucket → dq_export_connector-0.1.0.dev28/dq_export_connector}/datasets.py +0 -0
  64. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/log.py +0 -0
  65. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/dq_export_connector/models/bucket.py +0 -0
  66. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/tests/test_models_are_current.py +0 -0
  67. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/tests/test_paths.py +0 -0
  68. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/tests/test_store.py +0 -0
  69. {dq_export_connector-0.1.0.dev26 → dq_export_connector-0.1.0.dev28}/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,153 @@
1
+ Metadata-Version: 2.5
2
+ Name: dq-export-connector
3
+ Version: 0.1.0.dev28
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 (set after consent, from
71
+ `ListDestinationAccounts`) and, per Input, a Segment, the identifier type its
72
+ lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
73
+ Grant of the Snap user who consented; each run turns it into an Access Token
74
+ with `dq_export_connector.oauth`. Decentriq's Snap app is the
75
+ `export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
76
+ mounted at `/input/oauth_app.json`. `ListDestinationAccounts` lists the ad
77
+ accounts of every organization the grant reaches.
78
+
79
+ A run looks each Segment up by name in the ad account and creates it when
80
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
81
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
82
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
83
+ is briefly empty. A run stops at the first Input that fails. When the failure
84
+ came after the Segment changed, the error says so; a rerun is safe in both
85
+ modes. Don't run one connector twice at the same time.
86
+
87
+ An Input is one file of values, or a stored ZIP holding one: one value per
88
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
89
+ empty lines skipped, no header.
90
+
91
+ ### Identifiers
92
+
93
+ | Type | Normalisation before SHA-256 | Snap schema |
94
+ |---|---|---|
95
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
96
+ | `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` |
97
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
98
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
99
+
100
+ A pre-hashed value only matches if it was hashed from the same form: for
101
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
102
+
103
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
104
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
105
+ and leaves its Segment as it was, in both modes.
106
+
107
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
108
+ warning or error message), never with the values themselves:
109
+
110
+ | Reason | Meaning |
111
+ |---|---|
112
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
113
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
114
+ | `PHONE_NO_DIGITS` | no digits at all |
115
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
116
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
117
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
118
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
119
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
120
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
121
+
122
+ ### Testing against Snap
123
+
124
+ The local files are gitignored in this directory:
125
+
126
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
127
+ - `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.
128
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
129
+
130
+ 1. Run:
131
+
132
+ ```sh
133
+ mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
134
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
135
+ --platform-secrets platform_secrets.json --mode validate
136
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
137
+ --platform-secrets platform_secrets.json
138
+ ```
139
+ 2. Live tests, including the check that Snap doesn't rotate refresh tokens:
140
+
141
+ ```sh
142
+ DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
143
+ ```
144
+
145
+ ## Releasing
146
+
147
+ Bump the version with `uv version <version> --no-sync`, which also updates
148
+ `uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
149
+ commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
150
+ uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
151
+ ddc then pins the new version, as
152
+ [ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
153
+ describes.
@@ -0,0 +1,140 @@
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 (set after consent, from
58
+ `ListDestinationAccounts`) and, per Input, a Segment, the identifier type its
59
+ lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
60
+ Grant of the Snap user who consented; each run turns it into an Access Token
61
+ with `dq_export_connector.oauth`. Decentriq's Snap app is the
62
+ `export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
63
+ mounted at `/input/oauth_app.json`. `ListDestinationAccounts` lists the ad
64
+ accounts of every organization the grant reaches.
65
+
66
+ A run looks each Segment up by name in the ad account and creates it when
67
+ there is none, marked `Managed by Decentriq`. It writes into a same-named
68
+ Segment whoever made it, with a `SEGMENT_NOT_MANAGED` warning when Decentriq
69
+ didn't. ADD adds the Input's values; REPLACE empties the Segment first, so it
70
+ is briefly empty. A run stops at the first Input that fails. When the failure
71
+ came after the Segment changed, the error says so; a rerun is safe in both
72
+ modes. Don't run one connector twice at the same time.
73
+
74
+ An Input is one file of values, or a stored ZIP holding one: one value per
75
+ line, UTF-8, optional BOM, LF or CRLF, surrounding double quotes removed,
76
+ empty lines skipped, no header.
77
+
78
+ ### Identifiers
79
+
80
+ | Type | Normalisation before SHA-256 | Snap schema |
81
+ |---|---|---|
82
+ | `EMAIL` | trim, lowercase; exactly one `@` with text on both sides | `EMAIL_SHA256` |
83
+ | `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` |
84
+ | `IDFA`, `GAID` | UUID form with hyphens, lowercased | `MOBILE_AD_ID_SHA256` |
85
+ | `*_SHA256` | must be 64 hex characters; lowercased, otherwise unchanged | as above |
86
+
87
+ A pre-hashed value only matches if it was hashed from the same form: for
88
+ `PHONE_SHA256`, the digits with country code and no `+` (`41791234567`).
89
+
90
+ Up to 25% invalid rows gives an `INVALID_ROWS` warning; more fails the run
91
+ before the Segment changes. An empty Input gives an `EMPTY_DATASET` warning
92
+ and leaves its Segment as it was, in both modes.
93
+
94
+ The receipt counts invalid rows by reason (`counts.invalidReasons`, and in the
95
+ warning or error message), never with the values themselves:
96
+
97
+ | Reason | Meaning |
98
+ |---|---|
99
+ | `EMAIL_NO_AT_SIGN`, `EMAIL_MULTIPLE_AT_SIGNS` | not exactly one `@` |
100
+ | `EMAIL_EMPTY_LOCAL_PART`, `EMAIL_EMPTY_DOMAIN` | nothing before or after the `@` |
101
+ | `PHONE_NO_DIGITS` | no digits at all |
102
+ | `PHONE_NATIONAL_FORMAT` | starts with `0` after dropping `00`, i.e. no country code |
103
+ | `PHONE_TOO_SHORT`, `PHONE_TOO_LONG` | fewer than 8 or more than 15 digits |
104
+ | `NOT_A_MOBILE_AD_ID` | not a UUID with hyphens |
105
+ | `NOT_SHA256_HEX` | a `*_SHA256` value that isn't 64 hex characters |
106
+ | `NOT_UTF8` | the line isn't valid UTF-8 |
107
+ | `CONTROL_CHARACTERS` | the value holds control characters or a byte order mark, usually because the file is UTF-16 |
108
+
109
+ ### Testing against Snap
110
+
111
+ The local files are gitignored in this directory:
112
+
113
+ - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
114
+ - `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.
115
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
116
+
117
+ 1. Run:
118
+
119
+ ```sh
120
+ mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
121
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
122
+ --platform-secrets platform_secrets.json --mode validate
123
+ uv run python scripts/run_local.py --config config.json --credentials credentials.json \
124
+ --platform-secrets platform_secrets.json
125
+ ```
126
+ 2. Live tests, including the check that Snap doesn't rotate refresh tokens:
127
+
128
+ ```sh
129
+ DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
130
+ ```
131
+
132
+ ## Releasing
133
+
134
+ Bump the version with `uv version <version> --no-sync`, which also updates
135
+ `uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
136
+ commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
137
+ uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
138
+ ddc then pins the new version, as
139
+ [ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
140
+ describes.
@@ -0,0 +1,25 @@
1
+ # generated by datamodel-codegen:
2
+ # filename: destination_accounts.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 DestinationAccounts(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