dex-connector-microsoft-excel 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dex_connector_microsoft_excel-0.1.0/.gitignore +16 -0
- dex_connector_microsoft_excel-0.1.0/LICENSE +21 -0
- dex_connector_microsoft_excel-0.1.0/PKG-INFO +46 -0
- dex_connector_microsoft_excel-0.1.0/README.md +34 -0
- dex_connector_microsoft_excel-0.1.0/examples/__init__.py +3 -0
- dex_connector_microsoft_excel-0.1.0/examples/approval_decision/README.md +5 -0
- dex_connector_microsoft_excel-0.1.0/examples/approval_decision/__init__.py +3 -0
- dex_connector_microsoft_excel-0.1.0/examples/approval_decision/flow.py +181 -0
- dex_connector_microsoft_excel-0.1.0/examples/approval_decision/integration_test.py +145 -0
- dex_connector_microsoft_excel-0.1.0/examples/approval_decision/models.py +30 -0
- dex_connector_microsoft_excel-0.1.0/examples/approval_decision/worker.py +47 -0
- dex_connector_microsoft_excel-0.1.0/pyproject.toml +38 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/__init__.py +53 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/__init__.py +2 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/config.py +28 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/connection.py +219 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/definitions.py +99 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/mock.py +293 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/models.py +209 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/refresh.py +9 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/_generated/steps.py +252 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/client.py +240 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/connection.py +5 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/dex-connector.json +178 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/excelmock/__init__.py +6 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/models.py +5 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/operations.py +966 -0
- dex_connector_microsoft_excel-0.1.0/src/dex_connectors/microsoft_excel/steps.py +5 -0
- dex_connector_microsoft_excel-0.1.0/tests/refresh_agreement_cases.json +613 -0
- dex_connector_microsoft_excel-0.1.0/tests/test_conformance.py +45 -0
- dex_connector_microsoft_excel-0.1.0/tests/test_operations.py +90 -0
- dex_connector_microsoft_excel-0.1.0/tests/test_refresh_agreement.py +278 -0
- dex_connector_microsoft_excel-0.1.0/uv.lock +934 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
|
+
/.bin/dexcli
|
|
8
|
+
/.bin/dex-server-zd
|
|
9
|
+
/sdkpython/.dexcli-data/
|
|
10
|
+
site/.catalog.yaml
|
|
11
|
+
coverage/
|
|
12
|
+
*.out
|
|
13
|
+
*.test
|
|
14
|
+
go.work
|
|
15
|
+
go.work.sum
|
|
16
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
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,46 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-microsoft-excel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dex-native Python connector for Microsoft Excel
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.7.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Microsoft Excel Python connector
|
|
14
|
+
|
|
15
|
+
Install `dex-connector-microsoft-excel==0.1.0`. The import path is
|
|
16
|
+
`dex_connectors.microsoft_excel`. The package requires `dex-connectors-sdk==0.6.0`
|
|
17
|
+
and Dex Python SDK 1.28.0 or newer.
|
|
18
|
+
|
|
19
|
+
The package implements four Graph Excel operations: `getTableRows`, `getValues`,
|
|
20
|
+
`updateValues`, and `appendTableRows`. Use the operation-specific
|
|
21
|
+
`new_get_table_rows_step`, `new_get_values_step`, `new_update_values_step`, and
|
|
22
|
+
`new_append_table_rows_step` factories. The checked-in
|
|
23
|
+
[approval decision Flow](examples/approval_decision/flow.py) is the runnable
|
|
24
|
+
application example. Its static Dex Web `ConnectionName` is `approvals`.
|
|
25
|
+
|
|
26
|
+
Configure a Microsoft Entra work or school account using the
|
|
27
|
+
[connector authorization guide](../README.md#microsoft-setup). OAuth refresh,
|
|
28
|
+
private and shared credential decoding, and project connection binding are
|
|
29
|
+
generated from `connector.yaml`. Access and refresh tokens stay in the Dex
|
|
30
|
+
connection store; Flow input, Attributes, Results, and receipts contain no
|
|
31
|
+
credentials.
|
|
32
|
+
|
|
33
|
+
`getTableRows` and `getValues` read tables and ranges. `updateValues` writes
|
|
34
|
+
literal absolute values and safely retries an ambiguous response.
|
|
35
|
+
`appendTableRows` reads existing keys, records a heartbeat before sending one
|
|
36
|
+
append, and never sends that append again after a possibly accepted request.
|
|
37
|
+
An unresolved earlier append selects `uncertain`. Optional branches left
|
|
38
|
+
unwired in a Flow fail that Flow.
|
|
39
|
+
|
|
40
|
+
To verify locally, run `dexcli dev` with a free Dex port, set
|
|
41
|
+
`DEX_FLOW_SERVICE_ADDRESS` to that address, and run
|
|
42
|
+
`uv run pytest examples/approval_decision/integration_test.py` from this
|
|
43
|
+
directory. The test binds a local Graph stand-in on an OS-assigned port and
|
|
44
|
+
runs a real Dex Worker and Client. `uv run pytest tests` runs the Go-recorded
|
|
45
|
+
provider replay and generated OAuth refresh agreement. Real Microsoft
|
|
46
|
+
workbook reads and writes have not been verified.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Microsoft Excel Python connector
|
|
2
|
+
|
|
3
|
+
Install `dex-connector-microsoft-excel==0.1.0`. The import path is
|
|
4
|
+
`dex_connectors.microsoft_excel`. The package requires `dex-connectors-sdk==0.6.0`
|
|
5
|
+
and Dex Python SDK 1.28.0 or newer.
|
|
6
|
+
|
|
7
|
+
The package implements four Graph Excel operations: `getTableRows`, `getValues`,
|
|
8
|
+
`updateValues`, and `appendTableRows`. Use the operation-specific
|
|
9
|
+
`new_get_table_rows_step`, `new_get_values_step`, `new_update_values_step`, and
|
|
10
|
+
`new_append_table_rows_step` factories. The checked-in
|
|
11
|
+
[approval decision Flow](examples/approval_decision/flow.py) is the runnable
|
|
12
|
+
application example. Its static Dex Web `ConnectionName` is `approvals`.
|
|
13
|
+
|
|
14
|
+
Configure a Microsoft Entra work or school account using the
|
|
15
|
+
[connector authorization guide](../README.md#microsoft-setup). OAuth refresh,
|
|
16
|
+
private and shared credential decoding, and project connection binding are
|
|
17
|
+
generated from `connector.yaml`. Access and refresh tokens stay in the Dex
|
|
18
|
+
connection store; Flow input, Attributes, Results, and receipts contain no
|
|
19
|
+
credentials.
|
|
20
|
+
|
|
21
|
+
`getTableRows` and `getValues` read tables and ranges. `updateValues` writes
|
|
22
|
+
literal absolute values and safely retries an ambiguous response.
|
|
23
|
+
`appendTableRows` reads existing keys, records a heartbeat before sending one
|
|
24
|
+
append, and never sends that append again after a possibly accepted request.
|
|
25
|
+
An unresolved earlier append selects `uncertain`. Optional branches left
|
|
26
|
+
unwired in a Flow fail that Flow.
|
|
27
|
+
|
|
28
|
+
To verify locally, run `dexcli dev` with a free Dex port, set
|
|
29
|
+
`DEX_FLOW_SERVICE_ADDRESS` to that address, and run
|
|
30
|
+
`uv run pytest examples/approval_decision/integration_test.py` from this
|
|
31
|
+
directory. The test binds a local Graph stand-in on an OS-assigned port and
|
|
32
|
+
runs a real Dex Worker and Client. `uv run pytest tests` runs the Go-recorded
|
|
33
|
+
provider replay and generated OAuth refresh agreement. Real Microsoft
|
|
34
|
+
workbook reads and writes have not been verified.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Excel approval decision
|
|
2
|
+
|
|
3
|
+
This Flow reads a policy table and summary range, writes a literal summary row, and appends a decision row by `RequestId` once. It uses the static Dex connection name `approvals`.
|
|
4
|
+
|
|
5
|
+
Configure the Microsoft Excel OAuth connection in Dex Web using the connector's authorization guide. Choose a workbook with `ApprovalPolicy` and `Decisions` tables, a `Summary` worksheet, and a two-cell summary range such as `A1:B1`. Run `dexcli dev` and start the worker with `python -m examples.approval_decision.worker` from `python/`, setting `DEX_FLOW_SERVICE_ADDRESS` to the dev server's address. The checked-in integration test uses inert credentials and a provider stand-in with a real Dex Worker and Client.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Run all four Excel operations in a durable approval decision Flow."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import MutationResult, QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.microsoft_excel import (
|
|
9
|
+
AppendTableRowsInput,
|
|
10
|
+
AppendTableRowsOutput,
|
|
11
|
+
Connection,
|
|
12
|
+
GetTableRowsInput,
|
|
13
|
+
GetTableRowsOutput,
|
|
14
|
+
GetValuesInput,
|
|
15
|
+
GetValuesOutput,
|
|
16
|
+
UpdateValuesInput,
|
|
17
|
+
UpdateValuesOutput,
|
|
18
|
+
new_append_table_rows_step,
|
|
19
|
+
new_get_table_rows_step,
|
|
20
|
+
new_get_values_step,
|
|
21
|
+
new_update_values_step,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from .models import CONNECTION_NAME, ApprovalInput, ApprovalOutput
|
|
25
|
+
|
|
26
|
+
_REQUEST = dex.Attribute("excel-approval-request", ApprovalInput)
|
|
27
|
+
_POLICY_ROW_COUNT = dex.Attribute("excel-policy-row-count", int)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# dex:group group-id:excel group-label:"Excel approval"
|
|
31
|
+
# dex:explanation text:"Persist workbook locations and start the policy table read."
|
|
32
|
+
class PrepareDecision(dex.Step[ApprovalInput]):
|
|
33
|
+
"""Store the non-secret request before the first Graph call."""
|
|
34
|
+
|
|
35
|
+
async def execute(self, context: dex.AsyncContext, input: ApprovalInput) -> dex.StepDecision:
|
|
36
|
+
"""Route one validated application request to the policy read."""
|
|
37
|
+
if not input.request_id or input.amount < 0:
|
|
38
|
+
return dex.force_fail("request ID and nonnegative amount are required")
|
|
39
|
+
_REQUEST.set(context, input)
|
|
40
|
+
return dex.go_to(dex.StepRef("ReadPolicyRows"), input)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# dex:group group-id:excel group-label:"Excel approval"
|
|
44
|
+
# dex:explanation text:"Retain the policy row count and read the current summary cells."
|
|
45
|
+
class PolicyRowsRead(dex.Step[QueryResult[GetTableRowsOutput]]):
|
|
46
|
+
"""Continue after the policy table was read."""
|
|
47
|
+
|
|
48
|
+
async def execute(
|
|
49
|
+
self, context: dex.AsyncContext, input: QueryResult[GetTableRowsOutput]
|
|
50
|
+
) -> dex.StepDecision:
|
|
51
|
+
"""Persist the row count for the final decision result."""
|
|
52
|
+
_POLICY_ROW_COUNT.set(context, len(input.value.rows))
|
|
53
|
+
return dex.go_to(dex.StepRef("ReadSummaryValues"), _REQUEST.get(context))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# dex:group group-id:excel group-label:"Excel approval"
|
|
57
|
+
# dex:explanation text:"Write the literal decision after the summary range is readable."
|
|
58
|
+
class SummaryValuesRead(dex.Step[QueryResult[GetValuesOutput]]):
|
|
59
|
+
"""Continue after the summary range was read."""
|
|
60
|
+
|
|
61
|
+
async def execute(
|
|
62
|
+
self, context: dex.AsyncContext, input: QueryResult[GetValuesOutput]
|
|
63
|
+
) -> dex.StepDecision:
|
|
64
|
+
"""Route the stored application request to the absolute range write."""
|
|
65
|
+
return dex.go_to(dex.StepRef("WriteSummaryValues"), _REQUEST.get(context))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# dex:group group-id:excel group-label:"Excel approval"
|
|
69
|
+
# dex:explanation text:"Append the decision row after the absolute summary write succeeds."
|
|
70
|
+
class SummaryValuesUpdated(dex.Step[MutationResult[UpdateValuesOutput]]):
|
|
71
|
+
"""Continue after Excel confirms the summary write."""
|
|
72
|
+
|
|
73
|
+
async def execute(
|
|
74
|
+
self, context: dex.AsyncContext, input: MutationResult[UpdateValuesOutput]
|
|
75
|
+
) -> dex.StepDecision:
|
|
76
|
+
"""Route the stored request to the duplicate-safe append."""
|
|
77
|
+
return dex.go_to(dex.StepRef("AppendDecisionRow"), _REQUEST.get(context))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# dex:group group-id:excel group-label:"Excel approval"
|
|
81
|
+
# dex:explanation text:"Complete after the table contains the requested decision key."
|
|
82
|
+
class DecisionRowAppended(dex.Step[MutationResult[AppendTableRowsOutput]]):
|
|
83
|
+
"""Complete once Excel holds the decision row."""
|
|
84
|
+
|
|
85
|
+
async def execute(
|
|
86
|
+
self, context: dex.AsyncContext, input: MutationResult[AppendTableRowsOutput]
|
|
87
|
+
) -> dex.StepDecision:
|
|
88
|
+
"""Return only request identity and confirmed business effects."""
|
|
89
|
+
request = _REQUEST.get(context)
|
|
90
|
+
return dex.graceful_complete(
|
|
91
|
+
ApprovalOutput(
|
|
92
|
+
request.request_id, bool(input.value.appended_keys), _POLICY_ROW_COUNT.get(context)
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class ApprovalDecisionFlow(dex.Flow[ApprovalInput]):
|
|
98
|
+
"""Read policy and summary, then write and append with one named connection."""
|
|
99
|
+
|
|
100
|
+
def __init__(self, connection: Connection) -> None:
|
|
101
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
102
|
+
raise ValueError("approval Flow requires the static approvals connection")
|
|
103
|
+
self.prepare = PrepareDecision()
|
|
104
|
+
self.policy_rows_read = PolicyRowsRead()
|
|
105
|
+
self.summary_values_read = SummaryValuesRead()
|
|
106
|
+
self.summary_values_updated = SummaryValuesUpdated()
|
|
107
|
+
self.decision_row_appended = DecisionRowAppended()
|
|
108
|
+
annotations = {
|
|
109
|
+
"groupId": "excel",
|
|
110
|
+
"groupLabel": "Excel approval",
|
|
111
|
+
"explanation": "Read or write the selected Microsoft Excel workbook.",
|
|
112
|
+
}
|
|
113
|
+
self.policy = new_get_table_rows_step(
|
|
114
|
+
step_type="ReadPolicyRows",
|
|
115
|
+
step_input_type=ApprovalInput,
|
|
116
|
+
annotations=annotations,
|
|
117
|
+
connection=connection,
|
|
118
|
+
connection_name="approvals",
|
|
119
|
+
read=self.policy_rows_read,
|
|
120
|
+
map_to_operation_input=lambda value: GetTableRowsInput(
|
|
121
|
+
value.drive_id, value.workbook_id, value.policy_table
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
self.summary = new_get_values_step(
|
|
125
|
+
step_type="ReadSummaryValues",
|
|
126
|
+
step_input_type=ApprovalInput,
|
|
127
|
+
annotations=annotations,
|
|
128
|
+
connection=connection,
|
|
129
|
+
connection_name="approvals",
|
|
130
|
+
read=self.summary_values_read,
|
|
131
|
+
map_to_operation_input=lambda value: GetValuesInput(
|
|
132
|
+
value.drive_id, value.workbook_id, value.summary_worksheet, value.summary_address
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
self.write = new_update_values_step(
|
|
136
|
+
step_type="WriteSummaryValues",
|
|
137
|
+
step_input_type=ApprovalInput,
|
|
138
|
+
annotations=annotations,
|
|
139
|
+
connection=connection,
|
|
140
|
+
connection_name="approvals",
|
|
141
|
+
updated=self.summary_values_updated,
|
|
142
|
+
map_to_operation_input=lambda value: UpdateValuesInput(
|
|
143
|
+
value.drive_id,
|
|
144
|
+
value.workbook_id,
|
|
145
|
+
value.summary_worksheet,
|
|
146
|
+
value.summary_address,
|
|
147
|
+
((value.request_id, value.amount),),
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
self.append = new_append_table_rows_step(
|
|
151
|
+
step_type="AppendDecisionRow",
|
|
152
|
+
step_input_type=ApprovalInput,
|
|
153
|
+
annotations=annotations,
|
|
154
|
+
connection=connection,
|
|
155
|
+
connection_name="approvals",
|
|
156
|
+
appended=self.decision_row_appended,
|
|
157
|
+
map_to_operation_input=lambda value: AppendTableRowsInput(
|
|
158
|
+
value.drive_id,
|
|
159
|
+
value.workbook_id,
|
|
160
|
+
value.decision_table,
|
|
161
|
+
"RequestId",
|
|
162
|
+
({"RequestId": value.request_id, "Amount": value.amount},),
|
|
163
|
+
),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
def get_steps(self) -> dex.StepList[ApprovalInput]:
|
|
167
|
+
"""Register each Step once under a stable identity."""
|
|
168
|
+
return dex.StepList.start_step(self.prepare).other_steps(
|
|
169
|
+
self.policy,
|
|
170
|
+
self.policy_rows_read,
|
|
171
|
+
self.summary,
|
|
172
|
+
self.summary_values_read,
|
|
173
|
+
self.write,
|
|
174
|
+
self.summary_values_updated,
|
|
175
|
+
self.append,
|
|
176
|
+
self.decision_row_appended,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
180
|
+
"""Persist the non-secret request and policy row count across Steps."""
|
|
181
|
+
return dex.PersistenceSchema.of(_REQUEST, _POLICY_ROW_COUNT)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Real Dex Worker and Client verification of the checked-in Excel Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import threading
|
|
9
|
+
from datetime import timedelta
|
|
10
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from uuid import uuid4
|
|
13
|
+
|
|
14
|
+
import dex
|
|
15
|
+
import httpx
|
|
16
|
+
import pytest
|
|
17
|
+
from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
|
|
18
|
+
|
|
19
|
+
from dex_connectors.microsoft_excel import Client, Config, Credentials, new_connection
|
|
20
|
+
|
|
21
|
+
from .flow import ApprovalDecisionFlow
|
|
22
|
+
from .models import CONNECTION_NAME, ApprovalInput, ApprovalOutput
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _ExcelHandler(BaseHTTPRequestHandler):
|
|
26
|
+
requests: list[tuple[str, str]] = []
|
|
27
|
+
|
|
28
|
+
def log_message(self, format: str, *args: object) -> None:
|
|
29
|
+
"""Suppress HTTP transport details from test output."""
|
|
30
|
+
|
|
31
|
+
def do_GET(self) -> None:
|
|
32
|
+
"""Serve the two table reads and the summary range read."""
|
|
33
|
+
self._answer()
|
|
34
|
+
|
|
35
|
+
def do_PATCH(self) -> None:
|
|
36
|
+
"""Accept the absolute summary write."""
|
|
37
|
+
self._answer()
|
|
38
|
+
|
|
39
|
+
def do_POST(self) -> None:
|
|
40
|
+
"""Accept exactly one decision row append."""
|
|
41
|
+
self._answer()
|
|
42
|
+
|
|
43
|
+
def _answer(self) -> None:
|
|
44
|
+
path = self.path.split("?", 1)[0]
|
|
45
|
+
self.requests.append((self.command, path))
|
|
46
|
+
if self.command in ("POST", "PATCH"):
|
|
47
|
+
length = int(self.headers.get("Content-Length", "0"))
|
|
48
|
+
request = json.loads(self.rfile.read(length))
|
|
49
|
+
assert request["values"]
|
|
50
|
+
if path.endswith("/columns"):
|
|
51
|
+
body = {
|
|
52
|
+
"value": [
|
|
53
|
+
{"id": "col-key", "index": 0, "name": "RequestId"},
|
|
54
|
+
{"id": "col-amount", "index": 1, "name": "Amount"},
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
elif path.endswith("/dataBodyRange") and "/columns/" in path:
|
|
58
|
+
body = {"address": "Decisions!A2:A1", "rowCount": 0, "columnCount": 1, "values": []}
|
|
59
|
+
elif path.endswith("/dataBodyRange"):
|
|
60
|
+
body = {
|
|
61
|
+
"address": "ApprovalPolicy!A2:B2",
|
|
62
|
+
"rowCount": 1,
|
|
63
|
+
"columnCount": 2,
|
|
64
|
+
"values": [["travel", 500]],
|
|
65
|
+
}
|
|
66
|
+
elif self.command == "GET":
|
|
67
|
+
body = {
|
|
68
|
+
"address": "Summary!A1:B1",
|
|
69
|
+
"rowCount": 1,
|
|
70
|
+
"columnCount": 2,
|
|
71
|
+
"values": [["old", 0]],
|
|
72
|
+
"text": [["old", "0"]],
|
|
73
|
+
}
|
|
74
|
+
else:
|
|
75
|
+
body = {"address": "Summary!A1:B1"}
|
|
76
|
+
payload = json.dumps(body).encode()
|
|
77
|
+
self.send_response(200)
|
|
78
|
+
self.send_header("Content-Type", "application/json")
|
|
79
|
+
self.send_header("Content-Length", str(len(payload)))
|
|
80
|
+
self.end_headers()
|
|
81
|
+
self.wfile.write(payload)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@pytest.mark.asyncio
|
|
85
|
+
async def test_real_dex_excel_approval_flow(tmp_path: Path) -> None:
|
|
86
|
+
"""Run every Excel operation across a real Dex Worker and Client."""
|
|
87
|
+
server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
88
|
+
_ExcelHandler.requests = []
|
|
89
|
+
provider = ThreadingHTTPServer(("127.0.0.1", 0), _ExcelHandler)
|
|
90
|
+
provider_thread = threading.Thread(target=provider.serve_forever, daemon=True)
|
|
91
|
+
provider_thread.start()
|
|
92
|
+
reference = ConnectionRef("microsoft", CONNECTION_NAME)
|
|
93
|
+
credentials = StaticCredentialProvider({reference: Credentials(access_token=SecretString("inert-token"))})
|
|
94
|
+
try:
|
|
95
|
+
async with httpx.AsyncClient(timeout=20, follow_redirects=False) as http_client:
|
|
96
|
+
connector = Client(
|
|
97
|
+
Config(),
|
|
98
|
+
credentials,
|
|
99
|
+
http_client=http_client,
|
|
100
|
+
local_provider_url=f"http://127.0.0.1:{provider.server_port}",
|
|
101
|
+
)
|
|
102
|
+
flow = ApprovalDecisionFlow(new_connection(connector, reference))
|
|
103
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
104
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(tmp_path / "blobs"), 1 << 25))
|
|
105
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
|
|
106
|
+
client = dex.AsyncClient(registry, cache, dex.ClientOptions(server_address=server_address))
|
|
107
|
+
worker_task = asyncio.create_task(worker.start())
|
|
108
|
+
try:
|
|
109
|
+
await worker.wait_pull_registered(timeout=30)
|
|
110
|
+
flow_id = f"excel-python-approval-{uuid4().hex}"
|
|
111
|
+
await client.start_flow(
|
|
112
|
+
flow,
|
|
113
|
+
flow_id,
|
|
114
|
+
ApprovalInput(
|
|
115
|
+
"b!driveKey-123_abc",
|
|
116
|
+
"01BYE5RZ6QN3ZWBTUFOFD3GSPGOHDJD36K",
|
|
117
|
+
"ApprovalPolicy",
|
|
118
|
+
"Summary",
|
|
119
|
+
"A1:B1",
|
|
120
|
+
"Decisions",
|
|
121
|
+
"REQ-1",
|
|
122
|
+
42,
|
|
123
|
+
),
|
|
124
|
+
)
|
|
125
|
+
result = await client.wait_for_flow(flow_id, timeout=timedelta(seconds=40))
|
|
126
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
127
|
+
assert result.single_output(ApprovalOutput) == ApprovalOutput("REQ-1", True, 1)
|
|
128
|
+
assert [method for method, _ in _ExcelHandler.requests] == [
|
|
129
|
+
"GET",
|
|
130
|
+
"GET",
|
|
131
|
+
"GET",
|
|
132
|
+
"PATCH",
|
|
133
|
+
"GET",
|
|
134
|
+
"GET",
|
|
135
|
+
"POST",
|
|
136
|
+
]
|
|
137
|
+
finally:
|
|
138
|
+
await client.close()
|
|
139
|
+
await worker.close()
|
|
140
|
+
await worker_task
|
|
141
|
+
cache.close()
|
|
142
|
+
finally:
|
|
143
|
+
provider.shutdown()
|
|
144
|
+
provider.server_close()
|
|
145
|
+
provider_thread.join(timeout=5)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Flow input and output for one approval decision."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
CONNECTION_NAME = "approvals"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class ApprovalInput:
|
|
12
|
+
"""Workbook locations and literal decision values chosen by the application."""
|
|
13
|
+
|
|
14
|
+
drive_id: str
|
|
15
|
+
workbook_id: str
|
|
16
|
+
policy_table: str
|
|
17
|
+
summary_worksheet: str
|
|
18
|
+
summary_address: str
|
|
19
|
+
decision_table: str
|
|
20
|
+
request_id: str
|
|
21
|
+
amount: int
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True, slots=True)
|
|
25
|
+
class ApprovalOutput:
|
|
26
|
+
"""Confirmed table and summary effects without connection credentials."""
|
|
27
|
+
|
|
28
|
+
request_id: str
|
|
29
|
+
appended: bool
|
|
30
|
+
existing_policy_rows: int
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Excel approval decision Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.microsoft_excel import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import ApprovalDecisionFlow
|
|
16
|
+
from .models import CONNECTION_NAME
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def run_worker() -> None:
|
|
20
|
+
"""Load Dex Web's named connection and serve the approval Flow."""
|
|
21
|
+
project = await load_from_environment()
|
|
22
|
+
connection = None
|
|
23
|
+
cache = None
|
|
24
|
+
try:
|
|
25
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
26
|
+
registry = dex.Registry([ApprovalDecisionFlow(connection)], allow_async_handlers=True)
|
|
27
|
+
cache_directory = os.environ.get(
|
|
28
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-excel-blobs")
|
|
29
|
+
)
|
|
30
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 28))
|
|
31
|
+
worker = dex.AsyncWorker(
|
|
32
|
+
registry,
|
|
33
|
+
cache,
|
|
34
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
35
|
+
)
|
|
36
|
+
async with worker:
|
|
37
|
+
await worker.start()
|
|
38
|
+
finally:
|
|
39
|
+
if connection is not None:
|
|
40
|
+
await connection.aclose()
|
|
41
|
+
if cache is not None:
|
|
42
|
+
cache.close()
|
|
43
|
+
await project.close()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
asyncio.run(run_worker())
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-microsoft-excel"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Dex-native Python connector for Microsoft Excel"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["dex-connectors-sdk==0.7.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
14
|
+
|
|
15
|
+
[dependency-groups]
|
|
16
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "PyYAML>=6", "types-PyYAML>=6"]
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["src/dex_connectors"]
|
|
20
|
+
|
|
21
|
+
[tool.pytest.ini_options]
|
|
22
|
+
testpaths = ["tests"]
|
|
23
|
+
pythonpath = [".", "src"]
|
|
24
|
+
asyncio_mode = "auto"
|
|
25
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
python_version = "3.11"
|
|
29
|
+
strict = true
|
|
30
|
+
mypy_path = "src"
|
|
31
|
+
explicit_package_bases = true
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
target-version = "py311"
|
|
35
|
+
line-length = 110
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Microsoft Excel operations for Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials
|
|
6
|
+
from .connection import Connection, new_connection, new_project_connection
|
|
7
|
+
from .models import (
|
|
8
|
+
AppendTableRowsInput,
|
|
9
|
+
AppendTableRowsOutput,
|
|
10
|
+
GetTableRowsInput,
|
|
11
|
+
GetTableRowsOutput,
|
|
12
|
+
GetValuesInput,
|
|
13
|
+
GetValuesOutput,
|
|
14
|
+
UpdateValuesInput,
|
|
15
|
+
UpdateValuesOutput,
|
|
16
|
+
)
|
|
17
|
+
from .operations import (
|
|
18
|
+
AppendTableRowsOperation,
|
|
19
|
+
GetTableRowsOperation,
|
|
20
|
+
GetValuesOperation,
|
|
21
|
+
UpdateValuesOperation,
|
|
22
|
+
)
|
|
23
|
+
from .steps import (
|
|
24
|
+
new_append_table_rows_step,
|
|
25
|
+
new_get_table_rows_step,
|
|
26
|
+
new_get_values_step,
|
|
27
|
+
new_update_values_step,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"Client",
|
|
32
|
+
"Config",
|
|
33
|
+
"Credentials",
|
|
34
|
+
"Connection",
|
|
35
|
+
"new_connection",
|
|
36
|
+
"new_project_connection",
|
|
37
|
+
"AppendTableRowsInput",
|
|
38
|
+
"AppendTableRowsOutput",
|
|
39
|
+
"GetTableRowsInput",
|
|
40
|
+
"GetTableRowsOutput",
|
|
41
|
+
"GetValuesInput",
|
|
42
|
+
"GetValuesOutput",
|
|
43
|
+
"UpdateValuesInput",
|
|
44
|
+
"UpdateValuesOutput",
|
|
45
|
+
"AppendTableRowsOperation",
|
|
46
|
+
"GetTableRowsOperation",
|
|
47
|
+
"GetValuesOperation",
|
|
48
|
+
"UpdateValuesOperation",
|
|
49
|
+
"new_append_table_rows_step",
|
|
50
|
+
"new_get_table_rows_step",
|
|
51
|
+
"new_get_values_step",
|
|
52
|
+
"new_update_values_step",
|
|
53
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
max_response_bytes: int = 4194304
|
|
14
|
+
max_cells: int = 10000
|
|
15
|
+
|
|
16
|
+
setattr(Config, '__module__', 'dex_connectors.microsoft_excel.client')
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, slots=True)
|
|
20
|
+
class Credentials:
|
|
21
|
+
|
|
22
|
+
auth_method_id: str = "microsoft-oauth"
|
|
23
|
+
oauth_client_id: str | None = None
|
|
24
|
+
oauth_client_secret: SecretString | None = None
|
|
25
|
+
access_token: SecretString | None = None
|
|
26
|
+
refresh_token: SecretString | None = None
|
|
27
|
+
|
|
28
|
+
setattr(Credentials, '__module__', 'dex_connectors.microsoft_excel.client')
|