datadouble-salesforce 0.0.3__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.
- datadouble_salesforce-0.0.3/.gitignore +21 -0
- datadouble_salesforce-0.0.3/LICENSE +21 -0
- datadouble_salesforce-0.0.3/PKG-INFO +157 -0
- datadouble_salesforce-0.0.3/README.md +136 -0
- datadouble_salesforce-0.0.3/pyproject.toml +38 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/__init__.py +151 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/cassettes.py +181 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/fake.py +645 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/org.py +215 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/py.typed +0 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/record.py +188 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/soql.py +407 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/source.py +414 -0
- datadouble_salesforce-0.0.3/src/datadouble_salesforce/working.py +356 -0
- datadouble_salesforce-0.0.3/tests/cassettes/org-hidden.json +95 -0
- datadouble_salesforce-0.0.3/tests/cassettes/org.json +410 -0
- datadouble_salesforce-0.0.3/tests/org/Account-parents.json +114 -0
- datadouble_salesforce-0.0.3/tests/org/Account.json +313 -0
- datadouble_salesforce-0.0.3/tests/org/Case.json +644 -0
- datadouble_salesforce-0.0.3/tests/org/Contact.json +1382 -0
- datadouble_salesforce-0.0.3/tests/org/Opportunity.json +554 -0
- datadouble_salesforce-0.0.3/tests/org/Subscription__c.json +334 -0
- datadouble_salesforce-0.0.3/tests/org/plan-subscriptions.json +50 -0
- datadouble_salesforce-0.0.3/tests/org/plan.json +42 -0
- datadouble_salesforce-0.0.3/tests/test_salesforce_conformance.py +134 -0
- datadouble_salesforce-0.0.3/tests/test_salesforce_units.py +891 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.py[cod]
|
|
6
|
+
.venv/
|
|
7
|
+
.env
|
|
8
|
+
.coverage
|
|
9
|
+
.coverage.*
|
|
10
|
+
coverage.xml
|
|
11
|
+
.reports/
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.mypy_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
dist/
|
|
16
|
+
site/
|
|
17
|
+
.cache/
|
|
18
|
+
|
|
19
|
+
# The default work directory of `datadouble run`.
|
|
20
|
+
.datadouble/
|
|
21
|
+
node_modules/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026- Tight Line LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datadouble-salesforce
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Salesforce engine adapter for Datadouble
|
|
5
|
+
Project-URL: Homepage, https://datadouble.tightlinesoftware.com/
|
|
6
|
+
Project-URL: Source, https://github.com/datadouble/datadouble
|
|
7
|
+
Author: Tight Line LLC
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Classifier: Topic :: Database
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Requires-Dist: datadouble
|
|
19
|
+
Requires-Dist: httpx>=0.29.0
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# datadouble-salesforce
|
|
23
|
+
|
|
24
|
+
The Salesforce engine adapter for [Datadouble](https://datadouble.tightlinesoftware.com/).
|
|
25
|
+
|
|
26
|
+
It reads an org through its REST, Tooling and Bulk API 2.0 interfaces and
|
|
27
|
+
builds everything else locally: working copies are SQLite databases with a
|
|
28
|
+
table per object, anonymization runs there, and golden images are logical,
|
|
29
|
+
each object's records as JSON lines with a description of its fields.
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
sources:
|
|
33
|
+
app:
|
|
34
|
+
engine: salesforce
|
|
35
|
+
connection:
|
|
36
|
+
instance_url: # by reference, like the token
|
|
37
|
+
env: SHOP_SF_INSTANCE_URL
|
|
38
|
+
access_token:
|
|
39
|
+
env: SHOP_SF_ACCESS_TOKEN
|
|
40
|
+
api_version: "62.0" # the default
|
|
41
|
+
objects: [Account, Contact, Opportunity, "Acme__*"] # optional
|
|
42
|
+
hidden: [Contact.Pronouns] # optional: fields copies may go without
|
|
43
|
+
subset:
|
|
44
|
+
seeds:
|
|
45
|
+
Account: "Industry = 'Technology' AND CreatedDate <= :as_of" # SOQL; :as_of is the anchor
|
|
46
|
+
follow:
|
|
47
|
+
down:
|
|
48
|
+
- Account -> Contact
|
|
49
|
+
anonymize:
|
|
50
|
+
Contact:
|
|
51
|
+
Email:
|
|
52
|
+
faker: email
|
|
53
|
+
unique: true
|
|
54
|
+
LastName:
|
|
55
|
+
faker: last_name
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The token is an OAuth access token for a user who can read the objects and
|
|
59
|
+
the Tooling API (the "View Setup and Configuration" permission), which lists
|
|
60
|
+
the installed packages and every field of each object.
|
|
61
|
+
|
|
62
|
+
## Fields field-level security hides
|
|
63
|
+
|
|
64
|
+
Salesforce leaves fields that field-level security hides from the user out of
|
|
65
|
+
the object's description, so a copy would lack them without any error. The
|
|
66
|
+
catalog finds them instead: a field that the Tooling API's `FieldDefinition`
|
|
67
|
+
lists, that a profile or permission set grants (`FieldPermissions`), but that
|
|
68
|
+
the description leaves out is hidden from this user. Fields granted to no one
|
|
69
|
+
are internal, or belong to features the org does not use, and are never
|
|
70
|
+
described anywhere, so they do not count. A field a managed package
|
|
71
|
+
maintains, such as a rollup's result, is often hidden this way.
|
|
72
|
+
|
|
73
|
+
The catalog, and so the plan, fails before anything is extracted, naming each
|
|
74
|
+
hidden field. Give the user read access to them, or list them in `hidden`
|
|
75
|
+
(as `Object.Field`) to accept that copies go without them.
|
|
76
|
+
|
|
77
|
+
## The catalog
|
|
78
|
+
|
|
79
|
+
Each object is a table, its fields the columns and `Id` the key. The catalog
|
|
80
|
+
lists the objects that can be queried, read, created and replicated. It leaves
|
|
81
|
+
out history, feed, share and change-event objects, custom metadata types,
|
|
82
|
+
platform events, and external and big objects; `objects` narrows it further,
|
|
83
|
+
with `*`, `?` and `[...]` patterns. Compound address and location fields are
|
|
84
|
+
left out, since their parts are fields too, and so are base64 fields, which
|
|
85
|
+
the Bulk API cannot export.
|
|
86
|
+
|
|
87
|
+
A reference field that points at one object in the catalog is a foreign key
|
|
88
|
+
to its `Id`. Polymorphic references, such as a task's `WhoId` and `WhatId`,
|
|
89
|
+
can point at several objects and are not; declare them as virtual foreign
|
|
90
|
+
keys, with a `when` on the type where needed, if a subset must follow them.
|
|
91
|
+
|
|
92
|
+
## Consistency
|
|
93
|
+
|
|
94
|
+
An org has no snapshots. Each query and export sees the records as they are
|
|
95
|
+
when it runs, so a record changed during the extract may appear before or
|
|
96
|
+
after the change, and a child created mid-way may name a parent the extract
|
|
97
|
+
did not see. Extract outside busy hours, and check references with the
|
|
98
|
+
`references` verification. The extract fails if an object's fields changed
|
|
99
|
+
since the plan.
|
|
100
|
+
|
|
101
|
+
## Subsets
|
|
102
|
+
|
|
103
|
+
Seeds and `when` clauses are SOQL conditions. Subsets use the keys strategy:
|
|
104
|
+
Salesforce's semi-joins go only one level deep and cannot be combined with
|
|
105
|
+
`OR`, so nested selections are not offered. Long `IN` lists are split across
|
|
106
|
+
queries, and records chosen twice are written once.
|
|
107
|
+
|
|
108
|
+
Anonymization takes the faker, hash, format-preserving and null rules;
|
|
109
|
+
expression rules and hooks are not offered. Assertions are SOQL, run against
|
|
110
|
+
a restored copy: one object, plain fields, comparisons, `LIKE`, `IN`, `AND`,
|
|
111
|
+
`OR`, `NOT`, `ORDER BY` and `LIMIT`. As in Salesforce, comparing text
|
|
112
|
+
ignores case.
|
|
113
|
+
|
|
114
|
+
## Requirements
|
|
115
|
+
|
|
116
|
+
The adapter reports each installed package (`InstalledSubscriberPackage`) as
|
|
117
|
+
a `package` requirement, by namespace, at its version. Copies are local
|
|
118
|
+
databases that hold a package's objects and fields as ordinary tables and
|
|
119
|
+
columns, so they need none of them; the build does not check them, and the
|
|
120
|
+
lock records them so strict mode notices a package installed, removed or
|
|
121
|
+
upgraded.
|
|
122
|
+
|
|
123
|
+
## Images
|
|
124
|
+
|
|
125
|
+
Images are `logical` only, and there is no server to start, so they cannot be
|
|
126
|
+
replicated as running databases yet. Loading an image's records into an org
|
|
127
|
+
(a sandbox or scratch org) is planned.
|
|
128
|
+
|
|
129
|
+
## The fake org
|
|
130
|
+
|
|
131
|
+
`datadouble_salesforce.fake` serves a SQLite file over the same APIs, so the
|
|
132
|
+
whole adapter runs without an org:
|
|
133
|
+
|
|
134
|
+
```yaml
|
|
135
|
+
sources:
|
|
136
|
+
app:
|
|
137
|
+
engine: salesforce
|
|
138
|
+
connection:
|
|
139
|
+
fake: /path/to/org.sqlite
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`FakeOrg` builds the file (objects, fields, records and packages) and
|
|
143
|
+
`sample_org(path)` writes a small one with made-up records. The fake answers
|
|
144
|
+
the SOQL assertions use, and has no snapshots either.
|
|
145
|
+
|
|
146
|
+
## Recorded cassettes
|
|
147
|
+
|
|
148
|
+
`datadouble_salesforce.cassettes` records the adapter's HTTP interactions,
|
|
149
|
+
scrubs them and replays them. The scrubber keeps only the headers replay
|
|
150
|
+
needs and replaces access tokens, session IDs, the instance URL and other
|
|
151
|
+
Salesforce hosts, and org IDs. To re-record the committed cassette against a
|
|
152
|
+
development org:
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
sf org login web --alias datadouble-dev
|
|
156
|
+
make record-salesforce ORG=datadouble-dev
|
|
157
|
+
```
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# datadouble-salesforce
|
|
2
|
+
|
|
3
|
+
The Salesforce engine adapter for [Datadouble](https://datadouble.tightlinesoftware.com/).
|
|
4
|
+
|
|
5
|
+
It reads an org through its REST, Tooling and Bulk API 2.0 interfaces and
|
|
6
|
+
builds everything else locally: working copies are SQLite databases with a
|
|
7
|
+
table per object, anonymization runs there, and golden images are logical,
|
|
8
|
+
each object's records as JSON lines with a description of its fields.
|
|
9
|
+
|
|
10
|
+
```yaml
|
|
11
|
+
sources:
|
|
12
|
+
app:
|
|
13
|
+
engine: salesforce
|
|
14
|
+
connection:
|
|
15
|
+
instance_url: # by reference, like the token
|
|
16
|
+
env: SHOP_SF_INSTANCE_URL
|
|
17
|
+
access_token:
|
|
18
|
+
env: SHOP_SF_ACCESS_TOKEN
|
|
19
|
+
api_version: "62.0" # the default
|
|
20
|
+
objects: [Account, Contact, Opportunity, "Acme__*"] # optional
|
|
21
|
+
hidden: [Contact.Pronouns] # optional: fields copies may go without
|
|
22
|
+
subset:
|
|
23
|
+
seeds:
|
|
24
|
+
Account: "Industry = 'Technology' AND CreatedDate <= :as_of" # SOQL; :as_of is the anchor
|
|
25
|
+
follow:
|
|
26
|
+
down:
|
|
27
|
+
- Account -> Contact
|
|
28
|
+
anonymize:
|
|
29
|
+
Contact:
|
|
30
|
+
Email:
|
|
31
|
+
faker: email
|
|
32
|
+
unique: true
|
|
33
|
+
LastName:
|
|
34
|
+
faker: last_name
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The token is an OAuth access token for a user who can read the objects and
|
|
38
|
+
the Tooling API (the "View Setup and Configuration" permission), which lists
|
|
39
|
+
the installed packages and every field of each object.
|
|
40
|
+
|
|
41
|
+
## Fields field-level security hides
|
|
42
|
+
|
|
43
|
+
Salesforce leaves fields that field-level security hides from the user out of
|
|
44
|
+
the object's description, so a copy would lack them without any error. The
|
|
45
|
+
catalog finds them instead: a field that the Tooling API's `FieldDefinition`
|
|
46
|
+
lists, that a profile or permission set grants (`FieldPermissions`), but that
|
|
47
|
+
the description leaves out is hidden from this user. Fields granted to no one
|
|
48
|
+
are internal, or belong to features the org does not use, and are never
|
|
49
|
+
described anywhere, so they do not count. A field a managed package
|
|
50
|
+
maintains, such as a rollup's result, is often hidden this way.
|
|
51
|
+
|
|
52
|
+
The catalog, and so the plan, fails before anything is extracted, naming each
|
|
53
|
+
hidden field. Give the user read access to them, or list them in `hidden`
|
|
54
|
+
(as `Object.Field`) to accept that copies go without them.
|
|
55
|
+
|
|
56
|
+
## The catalog
|
|
57
|
+
|
|
58
|
+
Each object is a table, its fields the columns and `Id` the key. The catalog
|
|
59
|
+
lists the objects that can be queried, read, created and replicated. It leaves
|
|
60
|
+
out history, feed, share and change-event objects, custom metadata types,
|
|
61
|
+
platform events, and external and big objects; `objects` narrows it further,
|
|
62
|
+
with `*`, `?` and `[...]` patterns. Compound address and location fields are
|
|
63
|
+
left out, since their parts are fields too, and so are base64 fields, which
|
|
64
|
+
the Bulk API cannot export.
|
|
65
|
+
|
|
66
|
+
A reference field that points at one object in the catalog is a foreign key
|
|
67
|
+
to its `Id`. Polymorphic references, such as a task's `WhoId` and `WhatId`,
|
|
68
|
+
can point at several objects and are not; declare them as virtual foreign
|
|
69
|
+
keys, with a `when` on the type where needed, if a subset must follow them.
|
|
70
|
+
|
|
71
|
+
## Consistency
|
|
72
|
+
|
|
73
|
+
An org has no snapshots. Each query and export sees the records as they are
|
|
74
|
+
when it runs, so a record changed during the extract may appear before or
|
|
75
|
+
after the change, and a child created mid-way may name a parent the extract
|
|
76
|
+
did not see. Extract outside busy hours, and check references with the
|
|
77
|
+
`references` verification. The extract fails if an object's fields changed
|
|
78
|
+
since the plan.
|
|
79
|
+
|
|
80
|
+
## Subsets
|
|
81
|
+
|
|
82
|
+
Seeds and `when` clauses are SOQL conditions. Subsets use the keys strategy:
|
|
83
|
+
Salesforce's semi-joins go only one level deep and cannot be combined with
|
|
84
|
+
`OR`, so nested selections are not offered. Long `IN` lists are split across
|
|
85
|
+
queries, and records chosen twice are written once.
|
|
86
|
+
|
|
87
|
+
Anonymization takes the faker, hash, format-preserving and null rules;
|
|
88
|
+
expression rules and hooks are not offered. Assertions are SOQL, run against
|
|
89
|
+
a restored copy: one object, plain fields, comparisons, `LIKE`, `IN`, `AND`,
|
|
90
|
+
`OR`, `NOT`, `ORDER BY` and `LIMIT`. As in Salesforce, comparing text
|
|
91
|
+
ignores case.
|
|
92
|
+
|
|
93
|
+
## Requirements
|
|
94
|
+
|
|
95
|
+
The adapter reports each installed package (`InstalledSubscriberPackage`) as
|
|
96
|
+
a `package` requirement, by namespace, at its version. Copies are local
|
|
97
|
+
databases that hold a package's objects and fields as ordinary tables and
|
|
98
|
+
columns, so they need none of them; the build does not check them, and the
|
|
99
|
+
lock records them so strict mode notices a package installed, removed or
|
|
100
|
+
upgraded.
|
|
101
|
+
|
|
102
|
+
## Images
|
|
103
|
+
|
|
104
|
+
Images are `logical` only, and there is no server to start, so they cannot be
|
|
105
|
+
replicated as running databases yet. Loading an image's records into an org
|
|
106
|
+
(a sandbox or scratch org) is planned.
|
|
107
|
+
|
|
108
|
+
## The fake org
|
|
109
|
+
|
|
110
|
+
`datadouble_salesforce.fake` serves a SQLite file over the same APIs, so the
|
|
111
|
+
whole adapter runs without an org:
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
sources:
|
|
115
|
+
app:
|
|
116
|
+
engine: salesforce
|
|
117
|
+
connection:
|
|
118
|
+
fake: /path/to/org.sqlite
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`FakeOrg` builds the file (objects, fields, records and packages) and
|
|
122
|
+
`sample_org(path)` writes a small one with made-up records. The fake answers
|
|
123
|
+
the SOQL assertions use, and has no snapshots either.
|
|
124
|
+
|
|
125
|
+
## Recorded cassettes
|
|
126
|
+
|
|
127
|
+
`datadouble_salesforce.cassettes` records the adapter's HTTP interactions,
|
|
128
|
+
scrubs them and replays them. The scrubber keeps only the headers replay
|
|
129
|
+
needs and replaces access tokens, session IDs, the instance URL and other
|
|
130
|
+
Salesforce hosts, and org IDs. To re-record the committed cassette against a
|
|
131
|
+
development org:
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
sf org login web --alias datadouble-dev
|
|
135
|
+
make record-salesforce ORG=datadouble-dev
|
|
136
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
name = "datadouble-salesforce"
|
|
6
|
+
# All packages share one version until 1.0 (decision 38); scripts/make_tag.py
|
|
7
|
+
# sets it at release time.
|
|
8
|
+
version = "0.0.3"
|
|
9
|
+
description = "Salesforce engine adapter for Datadouble"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Tight Line LLC" }]
|
|
14
|
+
requires-python = ">=3.13"
|
|
15
|
+
dependencies = ["datadouble", "httpx>=0.29.0"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Programming Language :: Python :: 3.15",
|
|
22
|
+
"Topic :: Database",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://datadouble.tightlinesoftware.com/"
|
|
28
|
+
Source = "https://github.com/datadouble/datadouble"
|
|
29
|
+
|
|
30
|
+
[project.entry-points."datadouble.engines"]
|
|
31
|
+
salesforce = "datadouble_salesforce:engine"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["hatchling>=1.33.0"]
|
|
35
|
+
build-backend = "hatchling.build"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.wheel]
|
|
38
|
+
packages = ["src/datadouble_salesforce"]
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""The Salesforce engine adapter for Datadouble.
|
|
5
|
+
|
|
6
|
+
Spec settings::
|
|
7
|
+
|
|
8
|
+
sources:
|
|
9
|
+
app:
|
|
10
|
+
engine: salesforce
|
|
11
|
+
connection:
|
|
12
|
+
instance_url: {env: SHOP_SF_INSTANCE_URL} # by reference
|
|
13
|
+
access_token: {env: SHOP_SF_ACCESS_TOKEN}
|
|
14
|
+
api_version: "62.0" # the default
|
|
15
|
+
objects: [Account, Contact, "Acme__*"] # optional: only these objects
|
|
16
|
+
|
|
17
|
+
or, for the fake org (:mod:`datadouble_salesforce.fake`)::
|
|
18
|
+
|
|
19
|
+
connection:
|
|
20
|
+
fake: /path/to/org.sqlite
|
|
21
|
+
|
|
22
|
+
The adapter reads the org through its REST, Tooling and Bulk 2.0 APIs, and
|
|
23
|
+
builds its working copies, anonymization and images locally in SQLite: the
|
|
24
|
+
image is logical, each object's records as JSON lines.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import re
|
|
28
|
+
from collections.abc import Generator, Mapping
|
|
29
|
+
from contextlib import contextmanager
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
from typing import Annotated
|
|
32
|
+
|
|
33
|
+
import httpx
|
|
34
|
+
from pydantic import BaseModel, ConfigDict, Field, JsonValue, StringConstraints
|
|
35
|
+
|
|
36
|
+
from datadouble.engine import EngineError, ServerPlan, SourceSession, Tooling, WorkingDatabases
|
|
37
|
+
from datadouble.names import EngineName
|
|
38
|
+
from datadouble.planner import Capabilities
|
|
39
|
+
from datadouble.runtime import identity
|
|
40
|
+
from datadouble.secrets import resolve_secret
|
|
41
|
+
from datadouble.settings import NoSettings, parse_settings
|
|
42
|
+
from datadouble.spec import ImageFormat, SecretRef
|
|
43
|
+
from datadouble_salesforce.fake import FakeOrg, FakeTransport
|
|
44
|
+
from datadouble_salesforce.org import DEFAULT_API_VERSION, RestOrg
|
|
45
|
+
from datadouble_salesforce.source import ENGINE, SalesforceSource
|
|
46
|
+
from datadouble_salesforce.working import SalesforceWorking
|
|
47
|
+
|
|
48
|
+
FAKE_URL = "https://fake.example.com"
|
|
49
|
+
"""The instance URL requests to the fake org name."""
|
|
50
|
+
_TIMEOUT = httpx.Timeout(120.0, connect=15.0)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
type HiddenField = Annotated[str, StringConstraints(pattern=r"^[A-Za-z0-9_]+\.[A-Za-z0-9_]+$")]
|
|
54
|
+
"""A field as ``Object.Field``."""
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class OrgConnection(BaseModel):
|
|
58
|
+
"""The ``sources.<name>.connection`` settings for an org."""
|
|
59
|
+
|
|
60
|
+
model_config = ConfigDict(strict=True, frozen=True, extra="forbid")
|
|
61
|
+
|
|
62
|
+
instance_url: SecretRef
|
|
63
|
+
access_token: SecretRef
|
|
64
|
+
api_version: str = Field(default=DEFAULT_API_VERSION, pattern=re.compile(r"^\d+\.\d$"))
|
|
65
|
+
objects: tuple[str, ...] = ()
|
|
66
|
+
"""Patterns (``*``, ``?``, ``[...]``) for the objects to read; all, when empty."""
|
|
67
|
+
hidden: tuple[HiddenField, ...] = ()
|
|
68
|
+
"""Fields field-level security may hide from the user, which copies go without."""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class FakeConnection(BaseModel):
|
|
72
|
+
"""The ``sources.<name>.connection`` settings for the fake org."""
|
|
73
|
+
|
|
74
|
+
model_config = ConfigDict(strict=True, frozen=True, extra="forbid")
|
|
75
|
+
|
|
76
|
+
fake: str
|
|
77
|
+
api_version: str = Field(default=DEFAULT_API_VERSION, pattern=re.compile(r"^\d+\.\d$"))
|
|
78
|
+
objects: tuple[str, ...] = ()
|
|
79
|
+
hidden: tuple[HiddenField, ...] = ()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class SalesforceEngine:
|
|
83
|
+
"""Implements :class:`datadouble.engine.EngineAdapter` for Salesforce."""
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def name(self) -> EngineName:
|
|
87
|
+
"""``salesforce``."""
|
|
88
|
+
return ENGINE
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def owner(self) -> str:
|
|
92
|
+
"""Whoever runs Datadouble: copies are local files, served by no server."""
|
|
93
|
+
return identity()
|
|
94
|
+
|
|
95
|
+
def capabilities(self) -> Capabilities:
|
|
96
|
+
"""Logical images only; no expressions, nested strategy or hooks."""
|
|
97
|
+
return Capabilities(
|
|
98
|
+
formats=(ImageFormat.LOGICAL,), expressions=False, nested=False, hooks=False
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
@contextmanager
|
|
102
|
+
def connect(self, connection: Mapping[str, JsonValue]) -> Generator[SourceSession]:
|
|
103
|
+
"""Open the org, or the fake."""
|
|
104
|
+
settings: OrgConnection | FakeConnection
|
|
105
|
+
if "fake" in connection:
|
|
106
|
+
settings = parse_settings(FakeConnection, connection, "salesforce connection")
|
|
107
|
+
path = Path(settings.fake)
|
|
108
|
+
if not path.is_file():
|
|
109
|
+
message = f"the fake org {path} does not exist"
|
|
110
|
+
raise EngineError(message)
|
|
111
|
+
transport: httpx.BaseTransport = FakeTransport(FakeOrg(path))
|
|
112
|
+
url, token, poll = FAKE_URL, "fake", 0.0
|
|
113
|
+
else:
|
|
114
|
+
settings = parse_settings(OrgConnection, connection, "salesforce connection")
|
|
115
|
+
transport = httpx.HTTPTransport(retries=2)
|
|
116
|
+
url, token = (
|
|
117
|
+
resolve_secret(settings.instance_url),
|
|
118
|
+
resolve_secret(settings.access_token),
|
|
119
|
+
)
|
|
120
|
+
poll = 2.0
|
|
121
|
+
headers = {"Authorization": f"Bearer {token}", "Accept": "application/json"}
|
|
122
|
+
with httpx.Client(
|
|
123
|
+
base_url=url, headers=headers, transport=transport, timeout=_TIMEOUT
|
|
124
|
+
) as client:
|
|
125
|
+
org = RestOrg(client, settings.api_version, poll_seconds=poll)
|
|
126
|
+
yield SalesforceSource(
|
|
127
|
+
org, settings.api_version, settings.objects, frozenset(settings.hidden)
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
def working(self, scratch: Path, tooling: Tooling, source_version: str) -> WorkingDatabases: # noqa: ARG002 - copies are SQLite at every API version
|
|
131
|
+
"""SQLite copies under ``scratch``; no container image applies."""
|
|
132
|
+
parse_settings(NoSettings, tooling.server, "salesforce server")
|
|
133
|
+
if tooling.image is not None:
|
|
134
|
+
message = (
|
|
135
|
+
"Salesforce copies are local SQLite databases; sources.<name>.image does not apply"
|
|
136
|
+
)
|
|
137
|
+
raise EngineError(message)
|
|
138
|
+
return SalesforceWorking(scratch)
|
|
139
|
+
|
|
140
|
+
def server(self, image: Path, server_image: str | None) -> ServerPlan:
|
|
141
|
+
"""A Salesforce image has no server to start."""
|
|
142
|
+
message = (
|
|
143
|
+
f"{image.name}: a Salesforce image has no server to start, in"
|
|
144
|
+
f" {server_image or 'any'} image; its copies are records for an org"
|
|
145
|
+
)
|
|
146
|
+
raise EngineError(message)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def engine() -> SalesforceEngine:
|
|
150
|
+
"""The entry point named in ``datadouble.engines``."""
|
|
151
|
+
return SalesforceEngine()
|