alter-sdk-github 0.2.1__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,135 @@
1
+ """Provider-owned response schemas bound to the selected contract version."""
2
+
3
+ from functools import lru_cache
4
+ from typing import Any, TypeVar
5
+
6
+ from jsonschema import Draft202012Validator
7
+
8
+ from alter_sdk.exceptions import BackendError, ManagedOperationError
9
+ from alter_sdk.integrations import (
10
+ IntegrationCall as CoreCall,
11
+ IntegrationResult as CoreResult,
12
+ IntegrationClient,
13
+ ResponseContract,
14
+ IntegrationApprovalReference,
15
+ )
16
+ from alter_sdk.models import ApprovalResult, PendingApproval
17
+ from alter_sdk_github.contracts import CONTRACT
18
+
19
+
20
+ def has_fault(value: Any) -> bool:
21
+ if not isinstance(value, dict):
22
+ return False
23
+ if any(value.get(key) is not None for key in []) or any(
24
+ isinstance(value.get(key), list) and value[key] for key in []
25
+ ):
26
+ return True
27
+ for key in []:
28
+ children = value.get(key, [])
29
+ if not isinstance(children, list):
30
+ children = [children]
31
+ if any(has_fault(child) for child in children):
32
+ return True
33
+ return False
34
+
35
+
36
+ FAULT_RULES = {}
37
+
38
+
39
+ def matches_rule(value: Any, path: list[str], test: str, expected: Any = None) -> bool:
40
+ if not path:
41
+ if test == "equals":
42
+ return value == expected
43
+ return (
44
+ value is False
45
+ if test == "false"
46
+ else (value is not None and value is not False and value not in ("", [], {}))
47
+ )
48
+ head, *tail = path
49
+ if head == "**":
50
+ return (
51
+ isinstance(value, list)
52
+ and bool(value)
53
+ and all(matches_rule(item, tail, test, expected) for item in value)
54
+ )
55
+ if head == "*":
56
+ return isinstance(value, list) and any(
57
+ matches_rule(item, tail, test, expected) for item in value
58
+ )
59
+ return (
60
+ isinstance(value, dict)
61
+ and head in value
62
+ and matches_rule(value[head], tail, test, expected)
63
+ )
64
+
65
+
66
+ @lru_cache
67
+ def response_contract(operation: str, version: str) -> ResponseContract:
68
+ if version != CONTRACT["version"] or operation not in CONTRACT["operations"]:
69
+ raise BackendError("Selected managed response contract is not installed")
70
+ row = CONTRACT["operations"][operation]
71
+ validator = Draft202012Validator({**row["schema"], "$defs": CONTRACT["$defs"]})
72
+ return ResponseContract(
73
+ row["accept"],
74
+ validator.is_valid,
75
+ tuple(row.get("no_content_statuses", ())),
76
+ lambda value: (
77
+ has_fault(value)
78
+ or any(
79
+ matches_rule(value, rule["path"], rule["test"], rule.get("value"))
80
+ for rule in FAULT_RULES.get(operation, [])
81
+ )
82
+ ),
83
+ )
84
+
85
+
86
+ T = TypeVar("T")
87
+
88
+
89
+ class IntegrationCall(CoreCall[T]):
90
+ def __init__(
91
+ self,
92
+ client: IntegrationClient,
93
+ response: ApprovalResult | PendingApproval | IntegrationApprovalReference,
94
+ operation: str,
95
+ version: str,
96
+ ) -> None:
97
+ super().__init__(
98
+ client, response, operation, version, response_contract(operation, version)
99
+ )
100
+
101
+
102
+ class IntegrationResult(CoreResult[T]):
103
+ def __init__(self, response: ApprovalResult, operation: str, version: str) -> None:
104
+ super().__init__(response, operation, version, response_contract(operation, version))
105
+
106
+
107
+ async def resume_call(
108
+ client: IntegrationClient, approval_id: str, provider: str, version: str
109
+ ) -> IntegrationCall[Any]:
110
+ """Use the approval's server identity; never guess a decoder from the caller."""
111
+ resume = getattr(client.integrations, "resume", None)
112
+ if not callable(resume):
113
+ raise ManagedOperationError(
114
+ "managed_resume_unsupported",
115
+ "The installed core SDK does not support resuming managed approvals",
116
+ 409,
117
+ )
118
+ call = await client.integrations.resume(approval_id)
119
+ if call.provider != provider or call.version != version:
120
+ raise ManagedOperationError(
121
+ "managed_approval_contract_mismatch",
122
+ "Approval belongs to a different provider or contract version",
123
+ 409,
124
+ )
125
+ if call.operation not in CONTRACT["operations"]:
126
+ raise ManagedOperationError(
127
+ "managed_approval_operation_mismatch",
128
+ "Approval operation is absent from this installed publication",
129
+ 409,
130
+ )
131
+ if call.approval_id is None:
132
+ raise BackendError("Resumed approval has no identity")
133
+ return IntegrationCall(
134
+ client, IntegrationApprovalReference(call.approval_id), call.operation, call.version
135
+ )
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: alter-sdk-github
3
+ Version: 0.2.1
4
+ Summary: Typed github operations through Alter
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Author: Alter Team
8
+ Author-email: founders@alterauth.com
9
+ Requires-Python: >=3.11,<4.0
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Requires-Dist: alter-sdk (>=0.31.0,<0.32.0)
16
+ Requires-Dist: jsonschema (>=4.26,<5)
17
+ Description-Content-Type: text/markdown
18
+
19
+ # alter-sdk-github
20
+
21
+ Install `pip install alter-sdk-github`. Core `alter-sdk` is installed as a dependency.
22
+
23
+ Import `GitHubIntegration` from `alter_sdk_github` and construct it with an Alter `App`
24
+ and `{"grant_id": grant_id}`. All 1225 operations use
25
+ immutable contract `2026-11-01`. Await `call.wait()` for immediate or
26
+ approved execution, then decode with `result.body_json()`.
27
+ OAuth and managed-secret/API-key grants use the same binding and controls when
28
+ the provider supports that credential type.
29
+
30
+ [Public API reference](https://docs.alterauth.com/reference/managed-github-operations) includes every operation's input/output fields and both SDK examples.
31
+
32
+
33
+ ## Resume after a process restart
34
+
35
+ Persist the pending call's `approvalId` (TypeScript) or `approval_id` (Python)
36
+ in your durable job record. After restarting, construct a fresh provider client:
37
+
38
+ ```typescript
39
+ const resumed = await provider.resume(savedApprovalId);
40
+ const result = await resumed.wait();
41
+ const body = result.bodyJson();
42
+ ```
43
+
44
+ ```python
45
+ resumed = await provider.resume(saved_approval_id)
46
+ result = await resumed.wait()
47
+ body = result.body_json()
48
+ ```
49
+
50
+ The backend supplies the stored provider, operation and immutable contract version.
51
+ The provider package verifies provider/version and applies that operation's validator
52
+ and fault handling. Mismatches raise `ManagedOperationError` with
53
+ `managed_approval_contract_mismatch` or `managed_approval_operation_mismatch`.
54
+ The ID yields a union of operation outputs; TypeScript callers can narrow the call
55
+ by `resumed.operation`. No operation or version is accepted from the caller.
56
+
57
+ Generic `app.integrations.resume(id)` preserves raw response access and exact-number
58
+ decoding; use the provider package for its response validator. Both use the existing
59
+ approval poll's `proxy:execute` or `approvals:read` permissions and app/agent isolation.
60
+ Resume also works after execution while the result is retained. Denial, expiry,
61
+ execution failure and result purging retain the existing approval errors. Resume
62
+ never resubmits the request. Raw approvals or missing stored identities fail with
63
+ `managed_approval_identity_unavailable`.
64
+
@@ -0,0 +1,32 @@
1
+ alter_sdk_github/__init__.py,sha256=bgTFvbUR0fIm2h7U8acNASVd6Rff2bWa01NOAI_-XNo,220
2
+ alter_sdk_github/_github_models_00.py,sha256=vd_zk972sSvEmE-keGhWEma-MdbcpOFUvgpO9IeG-UE,148019
3
+ alter_sdk_github/_github_models_01.py,sha256=IjuNkbmwaDBvbQMbp-yNBgvBcFeQSNG7cX9EXdxZ0Q8,97687
4
+ alter_sdk_github/_github_models_02.py,sha256=wu7FT9pYwVhCnlKx7oIrgtRjxZLHJNW5AAKxUhnR8W0,92059
5
+ alter_sdk_github/_github_models_03.py,sha256=0Bdy2lEC7QL_YD4STQjKfdJlxc9Z-GUZ5Us-Tohq13s,172732
6
+ alter_sdk_github/_github_models_04.py,sha256=aNtAHmBx4ychgRbYkL4WR14PqwC70m26aUyYq1n9kE4,105078
7
+ alter_sdk_github/_github_models_05.py,sha256=QnErEsCSxDcBvUN45n70k6Gkc3KDVcNP7SAoZAwHu0w,102957
8
+ alter_sdk_github/_github_models_06.py,sha256=fC-TDWdJYV5vqHNfLHL-QoZT3jZyi5ILjMtDz6FmcqE,82123
9
+ alter_sdk_github/_github_models_07.py,sha256=fuoueJpMMr9OR6-ySJPDdWGdoRlUqKUJkJ-BS768_-Y,83204
10
+ alter_sdk_github/_github_models_08.py,sha256=87uvhdB3amkMyQ3RjrzDUKxuxVSP-5TVsZP3RUIJ0fk,83409
11
+ alter_sdk_github/_github_models_09.py,sha256=jURkrfwpkN6vli4IR9UI26xgpsd_TiBLOhRO5oZ0rwU,90531
12
+ alter_sdk_github/_github_models_10.py,sha256=4GKkInAFENo9BJE92mYbQjR62flHawTYFN1SY3Xc-HA,80782
13
+ alter_sdk_github/_github_models_11.py,sha256=9QVoSrPmPwwWEnFtar0_QdWoq_cXx75qUD5NLBidxfg,87748
14
+ alter_sdk_github/_github_models_12.py,sha256=BwAiYmfhOUq7CqdRpDb_iOdxdMsYuiFwGWGABnEcPsI,85906
15
+ alter_sdk_github/_github_models_13.py,sha256=IjQI4_pBf7D6mvoL-NiHLlhumIYVdZQeLiYAYSCbzQk,182647
16
+ alter_sdk_github/_github_models_14.py,sha256=9dcapbkduHoi5FnVExjt0u2sMffGFrxiD_PbqvfgzaQ,194339
17
+ alter_sdk_github/_github_models_15.py,sha256=Rn2keYaKw0zyN7_nDcq_B9BL8CaM-qKjKRJ6wHzAnfs,171003
18
+ alter_sdk_github/_github_models_16.py,sha256=FQZULSe8esjDTSPrEpZwUa5jgVMDRbtabln8bJLygCs,168963
19
+ alter_sdk_github/_github_models_17.py,sha256=cro2XGTe1Lk3Rp9xG85ymuscM-Vw0-N8hE8p0fdgsfs,279147
20
+ alter_sdk_github/_github_models_18.py,sha256=CgEqfRQFI7KQRXZaT3osjM1oiR_bQUgfphU273Uaf48,328195
21
+ alter_sdk_github/_github_models_19.py,sha256=jTxYguaSmXmc7eSKBqAtH7KItymfiZjZgUhQex1rGOA,360985
22
+ alter_sdk_github/_github_models_20.py,sha256=jfhpLHSsk9JaOK_QgzW5pCyklqerdc5wH754vXt18-k,377453
23
+ alter_sdk_github/_github_models_21.py,sha256=4VJpt2CYaZO5jJpqJvsrQ77tiu_wRwYYLohwzVazExY,295623
24
+ alter_sdk_github/_github_models_22.py,sha256=iEJJjXh2dx9KmxFG27Ydq4O-JaSJhr8cXiD9wzObleg,70738
25
+ alter_sdk_github/client.py,sha256=JJ4tIsDZhaZKUcTVDNnoNttGa6S8mWUIX95vgbWtLuQ,2396608
26
+ alter_sdk_github/contracts.py,sha256=16kD0w8l06YlZVwA1pwMMfL55a3QWxSqIWzpz2pSX-s,1303172
27
+ alter_sdk_github/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ alter_sdk_github/runtime.py,sha256=FlxrumVStoCYLGk2Q8uzoIVAzr9aHRVL-TcUM7UGfIY,4541
29
+ alter_sdk_github-0.2.1.dist-info/METADATA,sha256=vLySWQxhFiCkUjTO3I9AVJec4i46PTEDXieGbiTNm5M,2757
30
+ alter_sdk_github-0.2.1.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
31
+ alter_sdk_github-0.2.1.dist-info/licenses/LICENSE,sha256=r0DtRu8742Pi6xbXALkRMtxlltqEQQ-cpgaWOAKts6w,1071
32
+ alter_sdk_github-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alter AI, Inc.
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.