relayed 0.0.1__tar.gz → 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.
- relayed-0.1.0/.gitignore +11 -0
- {relayed-0.0.1 → relayed-0.1.0}/LICENSE +186 -186
- {relayed-0.0.1 → relayed-0.1.0}/PKG-INFO +1 -1
- {relayed-0.0.1 → relayed-0.1.0}/README.md +56 -56
- {relayed-0.0.1 → relayed-0.1.0}/pyproject.toml +39 -32
- {relayed-0.0.1 → relayed-0.1.0}/src/relayed/__init__.py +8 -1
- {relayed-0.0.1 → relayed-0.1.0}/src/relayed/_client.py +114 -114
- {relayed-0.0.1 → relayed-0.1.0}/src/relayed/_errors.py +28 -23
- relayed-0.1.0/src/relayed/_webhooks.py +19 -0
- {relayed-0.0.1 → relayed-0.1.0}/tests/test_sdk.py +22 -22
- relayed-0.1.0/tests/test_webhooks.py +62 -0
- relayed-0.0.1/.gitignore +0 -6
relayed-0.1.0/.gitignore
ADDED
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship made available under
|
|
36
|
-
the License, as indicated by a copyright notice that is included in
|
|
37
|
-
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
-
|
|
39
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
-
form, that is based on (or derived from) the Work and for which the
|
|
41
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
-
of this License, Derivative Works shall not include works that remain
|
|
44
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
-
the Work and derivative works thereof.
|
|
46
|
-
|
|
47
|
-
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
-
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
-
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
-
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
-
or written communication sent to the Licensor or its representatives,
|
|
52
|
-
including but not limited to communication on electronic mailing lists,
|
|
53
|
-
source code control systems, and issue tracking systems that are managed
|
|
54
|
-
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
-
improving the Work, but excluding communication that is conspicuously
|
|
56
|
-
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
-
Contribution."
|
|
58
|
-
|
|
59
|
-
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
-
whom a Contribution has been received by the Licensor and incorporated
|
|
61
|
-
within the Work.
|
|
62
|
-
|
|
63
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
-
Work and such Derivative Works in Source or Object form.
|
|
69
|
-
|
|
70
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
-
(except as stated in this section) patent license to make, have made,
|
|
74
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
-
where such license applies only to those patent claims licensable
|
|
76
|
-
by such Contributor that are necessarily infringed by their
|
|
77
|
-
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
-
institute patent litigation against any entity (including a cross-claim
|
|
80
|
-
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
-
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
-
patent infringement, then any patent licenses granted to You under
|
|
83
|
-
this License for that Work shall terminate as of the date such
|
|
84
|
-
litigation is filed.
|
|
85
|
-
|
|
86
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
-
modifications, and in Source or Object form, provided that You
|
|
89
|
-
meet the following conditions:
|
|
90
|
-
|
|
91
|
-
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
-
Works a copy of this License; and
|
|
93
|
-
|
|
94
|
-
(b) You must cause any modified files to carry prominent notices
|
|
95
|
-
stating that You changed the files; and
|
|
96
|
-
|
|
97
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
-
that You distribute, all copyright, patent, trademark, and
|
|
99
|
-
attribution notices from the Source form of the Work,
|
|
100
|
-
excluding those notices that do not pertain to any part of
|
|
101
|
-
the Derivative Works; and
|
|
102
|
-
|
|
103
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
-
distribution, You must include a readable copy of the
|
|
105
|
-
attribution notices contained within such NOTICE file, in
|
|
106
|
-
at least one of the following places: within a NOTICE text
|
|
107
|
-
file distributed as part of the Derivative Works; within
|
|
108
|
-
the Source form or documentation, if provided along with the
|
|
109
|
-
Derivative Works; or, within a display generated by the
|
|
110
|
-
Derivative Works, if and wherever such third-party notices
|
|
111
|
-
normally appear. The contents of the NOTICE file are for
|
|
112
|
-
informational purposes only and do not modify the License.
|
|
113
|
-
You may add Your own attribution notices within Derivative
|
|
114
|
-
Works that You distribute, alongside or in addition to the
|
|
115
|
-
NOTICE text from the Work, provided that such additional
|
|
116
|
-
attribution notices cannot be construed as modifying the License.
|
|
117
|
-
|
|
118
|
-
You may add Your own license statement for Your modifications and
|
|
119
|
-
may provide additional grant of rights to use, copy, modify, merge,
|
|
120
|
-
publish, distribute, sublicense, and/or sell copies of the
|
|
121
|
-
Contribution, either on its own behalf or on behalf of the Licensor,
|
|
122
|
-
either alone or combined with the Work, provided Your use,
|
|
123
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
124
|
-
the conditions stated in this License.
|
|
125
|
-
|
|
126
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
127
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
128
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
129
|
-
this License, without any additional terms or conditions.
|
|
130
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
131
|
-
the terms of any separate license agreement you may have executed
|
|
132
|
-
with Licensor regarding such Contributions.
|
|
133
|
-
|
|
134
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
135
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
136
|
-
except as required for reasonable and customary use in describing the
|
|
137
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
138
|
-
|
|
139
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
140
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
141
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
142
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
143
|
-
implied, including, without limitation, any warranties or conditions
|
|
144
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
145
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
146
|
-
appropriateness of using or reproducing the Work and assume any
|
|
147
|
-
risks associated with Your exercise of permissions under this License.
|
|
148
|
-
|
|
149
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
150
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
151
|
-
unless required by applicable law (such as deliberate and grossly
|
|
152
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
153
|
-
liable to You for damages, including any direct, indirect, special,
|
|
154
|
-
incidental, or exemplary damages of any character arising as a
|
|
155
|
-
result of this License or out of the use or inability to use the
|
|
156
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
157
|
-
work stoppage, computer failure or malfunction, or all other
|
|
158
|
-
commercial damages or losses), even if such Contributor has been
|
|
159
|
-
advised of the possibility of such damages.
|
|
160
|
-
|
|
161
|
-
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
162
|
-
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
163
|
-
for, acceptance of support, warranty, indemnity, or other liability
|
|
164
|
-
obligations and/or rights consistent with this License. However, in
|
|
165
|
-
accepting such obligations, You may offer such obligations only on
|
|
166
|
-
Your own behalf and on Your sole responsibility, not on behalf of
|
|
167
|
-
any other Contributor, and only if You agree to indemnify, defend,
|
|
168
|
-
and hold each Contributor harmless for any liability incurred by,
|
|
169
|
-
or claims asserted against, such Contributor by reason of your
|
|
170
|
-
accepting any warranty or additional liability.
|
|
171
|
-
|
|
172
|
-
END OF TERMS AND CONDITIONS
|
|
173
|
-
|
|
174
|
-
Copyright 2026 Diaphora
|
|
175
|
-
|
|
176
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
177
|
-
you may not use this file except in compliance with the License.
|
|
178
|
-
You may obtain a copy of the License at
|
|
179
|
-
|
|
180
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
181
|
-
|
|
182
|
-
Unless required by applicable law or agreed to in writing, software
|
|
183
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
184
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
185
|
-
See the License for the specific language governing permissions and
|
|
186
|
-
limitations under the License.
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and derivative works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
120
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
121
|
+
Contribution, either on its own behalf or on behalf of the Licensor,
|
|
122
|
+
either alone or combined with the Work, provided Your use,
|
|
123
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
124
|
+
the conditions stated in this License.
|
|
125
|
+
|
|
126
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
127
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
128
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
129
|
+
this License, without any additional terms or conditions.
|
|
130
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
131
|
+
the terms of any separate license agreement you may have executed
|
|
132
|
+
with Licensor regarding such Contributions.
|
|
133
|
+
|
|
134
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
135
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
136
|
+
except as required for reasonable and customary use in describing the
|
|
137
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
138
|
+
|
|
139
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
140
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
141
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
142
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
143
|
+
implied, including, without limitation, any warranties or conditions
|
|
144
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
145
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
146
|
+
appropriateness of using or reproducing the Work and assume any
|
|
147
|
+
risks associated with Your exercise of permissions under this License.
|
|
148
|
+
|
|
149
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
150
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
151
|
+
unless required by applicable law (such as deliberate and grossly
|
|
152
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
153
|
+
liable to You for damages, including any direct, indirect, special,
|
|
154
|
+
incidental, or exemplary damages of any character arising as a
|
|
155
|
+
result of this License or out of the use or inability to use the
|
|
156
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
157
|
+
work stoppage, computer failure or malfunction, or all other
|
|
158
|
+
commercial damages or losses), even if such Contributor has been
|
|
159
|
+
advised of the possibility of such damages.
|
|
160
|
+
|
|
161
|
+
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
162
|
+
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
163
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
164
|
+
obligations and/or rights consistent with this License. However, in
|
|
165
|
+
accepting such obligations, You may offer such obligations only on
|
|
166
|
+
Your own behalf and on Your sole responsibility, not on behalf of
|
|
167
|
+
any other Contributor, and only if You agree to indemnify, defend,
|
|
168
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
169
|
+
or claims asserted against, such Contributor by reason of your
|
|
170
|
+
accepting any warranty or additional liability.
|
|
171
|
+
|
|
172
|
+
END OF TERMS AND CONDITIONS
|
|
173
|
+
|
|
174
|
+
Copyright 2026 Diaphora
|
|
175
|
+
|
|
176
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
177
|
+
you may not use this file except in compliance with the License.
|
|
178
|
+
You may obtain a copy of the License at
|
|
179
|
+
|
|
180
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
181
|
+
|
|
182
|
+
Unless required by applicable law or agreed to in writing, software
|
|
183
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
184
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
185
|
+
See the License for the specific language governing permissions and
|
|
186
|
+
limitations under the License.
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
# Relayed
|
|
2
|
-
|
|
3
|
-
A Python Client for Relayed, a Webhooks Delivery Service.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install relayed
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick start
|
|
12
|
-
|
|
13
|
-
```python
|
|
14
|
-
import uuid
|
|
15
|
-
from relayed import RelayedClient, RelayedClientError
|
|
16
|
-
|
|
17
|
-
client = RelayedClient(
|
|
18
|
-
api_key="your-api-key",
|
|
19
|
-
base_url="https://relayed.example.com",
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
subscription = client.create_subscription(
|
|
23
|
-
destination_url="https://example.com",
|
|
24
|
-
event_types=["invoice.paid", "invoice.unpaid"],
|
|
25
|
-
description="Subscription for a contractor to send webhook whether customer paid the invoice"
|
|
26
|
-
)
|
|
27
|
-
try:
|
|
28
|
-
response = client.send_event(
|
|
29
|
-
event_type="invoice.paid",
|
|
30
|
-
payload={"invoice_id": "inv_123", "amount": 4200},
|
|
31
|
-
idempotency_key=str(uuid.uuid4()), # use a stable value across retries
|
|
32
|
-
)
|
|
33
|
-
print(response) # {"event_id": "...", "delivery_ids": [...]}
|
|
34
|
-
except RelayedClientError as e:
|
|
35
|
-
print(f"Cannot send event: {e}")
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Error Handling
|
|
40
|
-
|
|
41
|
-
All errors raised by the SDK inherit from RelayedError, so you can catch everything with a single except clause, or catch specific subclasses for fine-grained handling.
|
|
42
|
-
|
|
43
|
-
```python
|
|
44
|
-
from relayed import (
|
|
45
|
-
RelayedError,
|
|
46
|
-
RelayedAuthError,
|
|
47
|
-
RelayedNotFoundError,
|
|
48
|
-
RelayedConflictError,
|
|
49
|
-
RelayedClientError,
|
|
50
|
-
RelayedServerError,
|
|
51
|
-
)
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Links
|
|
55
|
-
|
|
56
|
-
- Source: [Github URL](https://github.com/JoeCosta7/Relayed)
|
|
1
|
+
# Relayed
|
|
2
|
+
|
|
3
|
+
A Python Client for Relayed, a Webhooks Delivery Service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install relayed
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import uuid
|
|
15
|
+
from relayed import RelayedClient, RelayedClientError
|
|
16
|
+
|
|
17
|
+
client = RelayedClient(
|
|
18
|
+
api_key="your-api-key",
|
|
19
|
+
base_url="https://relayed.example.com",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
subscription = client.create_subscription(
|
|
23
|
+
destination_url="https://example.com",
|
|
24
|
+
event_types=["invoice.paid", "invoice.unpaid"],
|
|
25
|
+
description="Subscription for a contractor to send webhook whether customer paid the invoice"
|
|
26
|
+
)
|
|
27
|
+
try:
|
|
28
|
+
response = client.send_event(
|
|
29
|
+
event_type="invoice.paid",
|
|
30
|
+
payload={"invoice_id": "inv_123", "amount": 4200},
|
|
31
|
+
idempotency_key=str(uuid.uuid4()), # use a stable value across retries
|
|
32
|
+
)
|
|
33
|
+
print(response) # {"event_id": "...", "delivery_ids": [...]}
|
|
34
|
+
except RelayedClientError as e:
|
|
35
|
+
print(f"Cannot send event: {e}")
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Error Handling
|
|
40
|
+
|
|
41
|
+
All errors raised by the SDK inherit from RelayedError, so you can catch everything with a single except clause, or catch specific subclasses for fine-grained handling.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from relayed import (
|
|
45
|
+
RelayedError,
|
|
46
|
+
RelayedAuthError,
|
|
47
|
+
RelayedNotFoundError,
|
|
48
|
+
RelayedConflictError,
|
|
49
|
+
RelayedClientError,
|
|
50
|
+
RelayedServerError,
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Links
|
|
55
|
+
|
|
56
|
+
- Source: [Github URL](https://github.com/JoeCosta7/Relayed)
|
|
57
57
|
- Issues: [GitHub issues URL](https://github.com/JoeCosta7/Relayed/issues)
|
|
@@ -1,32 +1,39 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
3
|
-
build-backend = "hatchling.build"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "relayed"
|
|
7
|
-
|
|
8
|
-
authors = [
|
|
9
|
-
{ name = "Joseph Costa", email="joedc3711@gmail.com" },
|
|
10
|
-
]
|
|
11
|
-
description = "Python client for Relayed, a webhook delivery service"
|
|
12
|
-
readme = "README.md"
|
|
13
|
-
requires-python = ">=3.10"
|
|
14
|
-
dependencies = [
|
|
15
|
-
"httpx>=0.27,<1.0",
|
|
16
|
-
]
|
|
17
|
-
license = "Apache-2.0"
|
|
18
|
-
license-files = ["LICENSE"]
|
|
19
|
-
|
|
20
|
-
[project.urls]
|
|
21
|
-
Homepage = "https://github.com/JoeCosta7/Relayed"
|
|
22
|
-
|
|
23
|
-
[project.optional-dependencies]
|
|
24
|
-
dev = [
|
|
25
|
-
"pytest>=7.0",
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
[tool.hatch.build.targets.wheel]
|
|
29
|
-
packages = ["src/relayed"]
|
|
30
|
-
|
|
31
|
-
[tool.
|
|
32
|
-
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "relayed"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Joseph Costa", email="joedc3711@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Python client for Relayed, a webhook delivery service"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"httpx>=0.27,<1.0",
|
|
16
|
+
]
|
|
17
|
+
license = "Apache-2.0"
|
|
18
|
+
license-files = ["LICENSE"]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/JoeCosta7/Relayed"
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = [
|
|
25
|
+
"pytest>=7.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["src/relayed"]
|
|
30
|
+
|
|
31
|
+
[tool.hatch.version]
|
|
32
|
+
source = "vcs"
|
|
33
|
+
|
|
34
|
+
[tool.pytest.ini_options]
|
|
35
|
+
testpaths = ["tests"]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.version.raw-options]
|
|
38
|
+
root = ".."
|
|
39
|
+
relative_to = "pyproject.toml"
|
|
@@ -6,7 +6,10 @@ from relayed._errors import (
|
|
|
6
6
|
RelayedConflictError,
|
|
7
7
|
RelayedClientError,
|
|
8
8
|
RelayedServerError,
|
|
9
|
+
RelayedTimestampError,
|
|
10
|
+
RelayedSignatureError
|
|
9
11
|
)
|
|
12
|
+
from relayed._webhooks import verify_webhook
|
|
10
13
|
|
|
11
14
|
__all__ = [
|
|
12
15
|
"RelayedClient",
|
|
@@ -16,6 +19,10 @@ __all__ = [
|
|
|
16
19
|
"RelayedConflictError",
|
|
17
20
|
"RelayedClientError",
|
|
18
21
|
"RelayedServerError",
|
|
22
|
+
"RelayedTimestampError",
|
|
23
|
+
"RelayedSignatureError",
|
|
24
|
+
"verify_webhook"
|
|
19
25
|
]
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
from importlib.metadata import version
|
|
28
|
+
__version__ = version("relayed")
|
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
|
-
import httpx
|
|
6
|
-
|
|
7
|
-
from ._errors import (
|
|
8
|
-
RelayedError,
|
|
9
|
-
RelayedAuthError,
|
|
10
|
-
RelayedNotFoundError,
|
|
11
|
-
RelayedConflictError,
|
|
12
|
-
RelayedClientError,
|
|
13
|
-
RelayedServerError,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
_STATUS_EXCEPTIONS: dict[int, type[RelayedError]] = {
|
|
18
|
-
401: RelayedAuthError,
|
|
19
|
-
403: RelayedAuthError,
|
|
20
|
-
404: RelayedNotFoundError,
|
|
21
|
-
409: RelayedConflictError,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class RelayedClient:
|
|
26
|
-
|
|
27
|
-
def __init__(self, api_key: str, base_url: str, timeout: float = 30.0):
|
|
28
|
-
self.api_key = api_key
|
|
29
|
-
self.base_url = base_url
|
|
30
|
-
self._client = httpx.Client(
|
|
31
|
-
base_url=base_url,
|
|
32
|
-
headers={"Authorization": f"Bearer {api_key}"},
|
|
33
|
-
timeout=timeout,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
def close(self) -> None:
|
|
37
|
-
self._client.close()
|
|
38
|
-
|
|
39
|
-
def __enter__(self) -> "RelayedClient":
|
|
40
|
-
return self
|
|
41
|
-
|
|
42
|
-
def __exit__(self, *exc_info) -> None:
|
|
43
|
-
self.close()
|
|
44
|
-
|
|
45
|
-
def _request(self, method: str, path: str, **kwargs) -> Any:
|
|
46
|
-
response = self._client.request(method, path, **kwargs)
|
|
47
|
-
self._raise_for_status(response)
|
|
48
|
-
if response.status_code == 204 or not response.content:
|
|
49
|
-
return None
|
|
50
|
-
return response.json()
|
|
51
|
-
|
|
52
|
-
@staticmethod
|
|
53
|
-
def _raise_for_status(response: httpx.Response) -> None:
|
|
54
|
-
if 200 <= response.status_code < 300:
|
|
55
|
-
return
|
|
56
|
-
exc_cls = _STATUS_EXCEPTIONS.get(response.status_code)
|
|
57
|
-
if exc_cls is None:
|
|
58
|
-
exc_cls = RelayedServerError if response.status_code >= 500 else RelayedClientError
|
|
59
|
-
raise exc_cls(
|
|
60
|
-
f"Relayed API returned {response.status_code}: {response.text}",
|
|
61
|
-
status_code=response.status_code,
|
|
62
|
-
response_body=response.text,
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
def send_event(self, event_type: str, payload: dict[str, Any], idempotency_key: str) -> dict[str, Any]:
|
|
66
|
-
"""Returns {"event_id": str, "delivery_ids": list[str]}.
|
|
67
|
-
|
|
68
|
-
idempotency_key is required and not generated for you: if you retry after
|
|
69
|
-
a dropped connection, reusing the same key is what makes the retry safe.
|
|
70
|
-
Generating a fresh one per call would defeat that.
|
|
71
|
-
"""
|
|
72
|
-
return self._request(
|
|
73
|
-
"POST",
|
|
74
|
-
"/v1/events",
|
|
75
|
-
json={"event_type": event_type, "payload": payload},
|
|
76
|
-
headers={"idempotency-key": idempotency_key},
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
def list_dead_letters(self) -> list[dict[str, Any]]:
|
|
80
|
-
return self._request("GET", "/v1/deadletter")
|
|
81
|
-
|
|
82
|
-
def replay_dead_letter(self, dead_letter_id: str) -> str:
|
|
83
|
-
"""Returns the id of the new delivery created for the replay."""
|
|
84
|
-
result = self._request("POST", f"/v1/deadletter/{dead_letter_id}/replay")
|
|
85
|
-
return result["delivery_ids"][0]
|
|
86
|
-
|
|
87
|
-
def create_subscription(
|
|
88
|
-
self,
|
|
89
|
-
destination_url: str,
|
|
90
|
-
event_types: list[str],
|
|
91
|
-
description: str | None = None,
|
|
92
|
-
) -> dict[str, Any]:
|
|
93
|
-
"""Returns the created subscription, including webhook_secret.
|
|
94
|
-
|
|
95
|
-
webhook_secret is shown only here
|
|
96
|
-
"""
|
|
97
|
-
return self._request(
|
|
98
|
-
"POST",
|
|
99
|
-
"/v1/subscriptions",
|
|
100
|
-
json={
|
|
101
|
-
"destination_url": destination_url,
|
|
102
|
-
"event_types": event_types,
|
|
103
|
-
"description": description,
|
|
104
|
-
},
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
def list_subscriptions(self) -> list[dict[str, Any]]:
|
|
108
|
-
return self._request("GET", "/v1/subscriptions")
|
|
109
|
-
|
|
110
|
-
def get_subscription(self, subscription_id: str) -> dict[str, Any]:
|
|
111
|
-
return self._request("GET", f"/v1/subscriptions/{subscription_id}")
|
|
112
|
-
|
|
113
|
-
def delete_subscription(self, subscription_id: str) -> None:
|
|
114
|
-
self._request("DELETE", f"/v1/subscriptions/{subscription_id}")
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ._errors import (
|
|
8
|
+
RelayedError,
|
|
9
|
+
RelayedAuthError,
|
|
10
|
+
RelayedNotFoundError,
|
|
11
|
+
RelayedConflictError,
|
|
12
|
+
RelayedClientError,
|
|
13
|
+
RelayedServerError,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
_STATUS_EXCEPTIONS: dict[int, type[RelayedError]] = {
|
|
18
|
+
401: RelayedAuthError,
|
|
19
|
+
403: RelayedAuthError,
|
|
20
|
+
404: RelayedNotFoundError,
|
|
21
|
+
409: RelayedConflictError,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class RelayedClient:
|
|
26
|
+
|
|
27
|
+
def __init__(self, api_key: str, base_url: str, timeout: float = 30.0):
|
|
28
|
+
self.api_key = api_key
|
|
29
|
+
self.base_url = base_url
|
|
30
|
+
self._client = httpx.Client(
|
|
31
|
+
base_url=base_url,
|
|
32
|
+
headers={"Authorization": f"Bearer {api_key}"},
|
|
33
|
+
timeout=timeout,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def close(self) -> None:
|
|
37
|
+
self._client.close()
|
|
38
|
+
|
|
39
|
+
def __enter__(self) -> "RelayedClient":
|
|
40
|
+
return self
|
|
41
|
+
|
|
42
|
+
def __exit__(self, *exc_info) -> None:
|
|
43
|
+
self.close()
|
|
44
|
+
|
|
45
|
+
def _request(self, method: str, path: str, **kwargs) -> Any:
|
|
46
|
+
response = self._client.request(method, path, **kwargs)
|
|
47
|
+
self._raise_for_status(response)
|
|
48
|
+
if response.status_code == 204 or not response.content:
|
|
49
|
+
return None
|
|
50
|
+
return response.json()
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def _raise_for_status(response: httpx.Response) -> None:
|
|
54
|
+
if 200 <= response.status_code < 300:
|
|
55
|
+
return
|
|
56
|
+
exc_cls = _STATUS_EXCEPTIONS.get(response.status_code)
|
|
57
|
+
if exc_cls is None:
|
|
58
|
+
exc_cls = RelayedServerError if response.status_code >= 500 else RelayedClientError
|
|
59
|
+
raise exc_cls(
|
|
60
|
+
f"Relayed API returned {response.status_code}: {response.text}",
|
|
61
|
+
status_code=response.status_code,
|
|
62
|
+
response_body=response.text,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def send_event(self, event_type: str, payload: dict[str, Any], idempotency_key: str) -> dict[str, Any]:
|
|
66
|
+
"""Returns {"event_id": str, "delivery_ids": list[str]}.
|
|
67
|
+
|
|
68
|
+
idempotency_key is required and not generated for you: if you retry after
|
|
69
|
+
a dropped connection, reusing the same key is what makes the retry safe.
|
|
70
|
+
Generating a fresh one per call would defeat that.
|
|
71
|
+
"""
|
|
72
|
+
return self._request(
|
|
73
|
+
"POST",
|
|
74
|
+
"/v1/events",
|
|
75
|
+
json={"event_type": event_type, "payload": payload},
|
|
76
|
+
headers={"idempotency-key": idempotency_key},
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def list_dead_letters(self) -> list[dict[str, Any]]:
|
|
80
|
+
return self._request("GET", "/v1/deadletter")
|
|
81
|
+
|
|
82
|
+
def replay_dead_letter(self, dead_letter_id: str) -> str:
|
|
83
|
+
"""Returns the id of the new delivery created for the replay."""
|
|
84
|
+
result = self._request("POST", f"/v1/deadletter/{dead_letter_id}/replay")
|
|
85
|
+
return result["delivery_ids"][0]
|
|
86
|
+
|
|
87
|
+
def create_subscription(
|
|
88
|
+
self,
|
|
89
|
+
destination_url: str,
|
|
90
|
+
event_types: list[str],
|
|
91
|
+
description: str | None = None,
|
|
92
|
+
) -> dict[str, Any]:
|
|
93
|
+
"""Returns the created subscription, including webhook_secret.
|
|
94
|
+
|
|
95
|
+
webhook_secret is shown only here
|
|
96
|
+
"""
|
|
97
|
+
return self._request(
|
|
98
|
+
"POST",
|
|
99
|
+
"/v1/subscriptions",
|
|
100
|
+
json={
|
|
101
|
+
"destination_url": destination_url,
|
|
102
|
+
"event_types": event_types,
|
|
103
|
+
"description": description,
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def list_subscriptions(self) -> list[dict[str, Any]]:
|
|
108
|
+
return self._request("GET", "/v1/subscriptions")
|
|
109
|
+
|
|
110
|
+
def get_subscription(self, subscription_id: str) -> dict[str, Any]:
|
|
111
|
+
return self._request("GET", f"/v1/subscriptions/{subscription_id}")
|
|
112
|
+
|
|
113
|
+
def delete_subscription(self, subscription_id: str) -> None:
|
|
114
|
+
self._request("DELETE", f"/v1/subscriptions/{subscription_id}")
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
class RelayedError(Exception):
|
|
4
|
-
def __init__(self, message: str, status_code: int | None = None, response_body: str | None = None):
|
|
5
|
-
super().__init__(message)
|
|
6
|
-
self.status_code = status_code
|
|
7
|
-
self.response_body = response_body
|
|
8
|
-
|
|
9
|
-
class RelayedAuthError(RelayedError):
|
|
10
|
-
"""401/403 — missing or invalid API key."""
|
|
11
|
-
|
|
12
|
-
class RelayedNotFoundError(RelayedError):
|
|
13
|
-
"""404 — resource does not exist (or isn't owned by this customer)."""
|
|
14
|
-
|
|
15
|
-
class RelayedConflictError(RelayedError):
|
|
16
|
-
"""409 — e.g. dead letter already replayed, subscription no longer active."""
|
|
17
|
-
|
|
18
|
-
class RelayedClientError(RelayedError):
|
|
19
|
-
"""Other 4xx — e.g. 400/422 validation errors."""
|
|
20
|
-
|
|
21
|
-
class RelayedServerError(RelayedError):
|
|
22
|
-
"""5xx — something went wrong on Relayed's end."""
|
|
23
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
class RelayedError(Exception):
|
|
4
|
+
def __init__(self, message: str, status_code: int | None = None, response_body: str | None = None):
|
|
5
|
+
super().__init__(message)
|
|
6
|
+
self.status_code = status_code
|
|
7
|
+
self.response_body = response_body
|
|
8
|
+
|
|
9
|
+
class RelayedAuthError(RelayedError):
|
|
10
|
+
"""401/403 — missing or invalid API key."""
|
|
11
|
+
|
|
12
|
+
class RelayedNotFoundError(RelayedError):
|
|
13
|
+
"""404 — resource does not exist (or isn't owned by this customer)."""
|
|
14
|
+
|
|
15
|
+
class RelayedConflictError(RelayedError):
|
|
16
|
+
"""409 — e.g. dead letter already replayed, subscription no longer active."""
|
|
17
|
+
|
|
18
|
+
class RelayedClientError(RelayedError):
|
|
19
|
+
"""Other 4xx — e.g. 400/422 validation errors."""
|
|
20
|
+
|
|
21
|
+
class RelayedServerError(RelayedError):
|
|
22
|
+
"""5xx — something went wrong on Relayed's end."""
|
|
23
|
+
|
|
24
|
+
class RelayedTimestampError(RelayedError):
|
|
25
|
+
"""Raised when the timestamp of the webhook is outside the allowed tolerance."""
|
|
26
|
+
|
|
27
|
+
class RelayedSignatureError(RelayedError):
|
|
28
|
+
"""Raised when the signature of the webhook does not match the expected signature."""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
import hmac
|
|
4
|
+
|
|
5
|
+
from ._errors import RelayedTimestampError, RelayedSignatureError
|
|
6
|
+
|
|
7
|
+
def verify_webhook(body: bytes,signature: str,timestamp: str,secret: str,tolerance_seconds: int = 300,) -> None:
|
|
8
|
+
try:
|
|
9
|
+
timestamp_int = int(timestamp)
|
|
10
|
+
except (ValueError, TypeError):
|
|
11
|
+
raise RelayedTimestampError("Webhook timestamp is missing or invalid.")
|
|
12
|
+
current_timestamp = int(datetime.now(timezone.utc).timestamp())
|
|
13
|
+
if abs(current_timestamp - timestamp_int) > tolerance_seconds:
|
|
14
|
+
raise RelayedTimestampError("Webhook timestamp is outside the allowed tolerance.")
|
|
15
|
+
reconstructed_payload = str(timestamp_int).encode("utf-8") + b"." + body
|
|
16
|
+
expected_signature = hmac.new(secret.encode(), reconstructed_payload, digestmod="sha256").hexdigest()
|
|
17
|
+
if not hmac.compare_digest(expected_signature, signature):
|
|
18
|
+
raise RelayedSignatureError("Webhook signature does not match the expected signature.")
|
|
19
|
+
return None
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# import uuid
|
|
2
|
-
|
|
3
|
-
# from relayed.sdk.src.relayed.relayed_sdk import RelayedClient
|
|
4
|
-
# import os
|
|
5
|
-
# from dotenv import load_dotenv, find_dotenv
|
|
6
|
-
# from pathlib import Path
|
|
7
|
-
|
|
8
|
-
# load_dotenv(find_dotenv(), override=False)
|
|
9
|
-
# relayed = RelayedClient(os.getenv("API_KEY"), base_url="http://localhost:8000")
|
|
10
|
-
|
|
11
|
-
# subscription = relayed.create_subscription(
|
|
12
|
-
# destination_url="https://webhook.site/1a4b3201-2814-46b7-aa13-ababfa88b463",
|
|
13
|
-
# event_types=["test.event"],
|
|
14
|
-
# )
|
|
15
|
-
# print("subscription:", subscription["id"], "webhook_secret:", subscription["webhook_secret"])
|
|
16
|
-
|
|
17
|
-
# result = relayed.send_event(
|
|
18
|
-
# event_type="test.event",
|
|
19
|
-
# payload={"message": "Hello from the SDK", "source": "test_sdk.py"},
|
|
20
|
-
# idempotency_key=str(uuid.uuid4()),
|
|
21
|
-
# )
|
|
22
|
-
|
|
1
|
+
# import uuid
|
|
2
|
+
|
|
3
|
+
# from relayed.sdk.src.relayed.relayed_sdk import RelayedClient
|
|
4
|
+
# import os
|
|
5
|
+
# from dotenv import load_dotenv, find_dotenv
|
|
6
|
+
# from pathlib import Path
|
|
7
|
+
|
|
8
|
+
# load_dotenv(find_dotenv(), override=False)
|
|
9
|
+
# relayed = RelayedClient(os.getenv("API_KEY"), base_url="http://localhost:8000")
|
|
10
|
+
|
|
11
|
+
# subscription = relayed.create_subscription(
|
|
12
|
+
# destination_url="https://webhook.site/1a4b3201-2814-46b7-aa13-ababfa88b463",
|
|
13
|
+
# event_types=["test.event"],
|
|
14
|
+
# )
|
|
15
|
+
# print("subscription:", subscription["id"], "webhook_secret:", subscription["webhook_secret"])
|
|
16
|
+
|
|
17
|
+
# result = relayed.send_event(
|
|
18
|
+
# event_type="test.event",
|
|
19
|
+
# payload={"message": "Hello from the SDK", "source": "test_sdk.py"},
|
|
20
|
+
# idempotency_key=str(uuid.uuid4()),
|
|
21
|
+
# )
|
|
22
|
+
|
|
23
23
|
# print("event:", result["event_id"], "deliveries:", result["delivery_ids"])
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import hmac
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from relayed._webhooks import verify_webhook
|
|
7
|
+
from relayed import RelayedSignatureError, RelayedTimestampError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _sign(body: bytes, timestamp: int, secret: str) -> str:
|
|
11
|
+
"""Produce the signature the worker would produce for this timestamp+body."""
|
|
12
|
+
signed_payload = str(timestamp).encode("utf-8") + b"." + body
|
|
13
|
+
return hmac.new(secret.encode(), signed_payload, digestmod="sha256").hexdigest()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _now() -> int:
|
|
17
|
+
return int(datetime.now(timezone.utc).timestamp())
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
SECRET = "test-webhook-secret"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_verify_webhook_happy_path():
|
|
24
|
+
"""A correctly-signed webhook with a fresh timestamp verifies without raising."""
|
|
25
|
+
body = b'{"event": "delivery.succeeded"}'
|
|
26
|
+
timestamp = _now()
|
|
27
|
+
signature = _sign(body, timestamp, SECRET)
|
|
28
|
+
assert verify_webhook(body, signature, str(timestamp), SECRET) is None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.mark.parametrize("bad_timestamp", ["", "abc", "1234abc", None])
|
|
32
|
+
def test_verify_webhook_invalid_timestamp_format(bad_timestamp):
|
|
33
|
+
"""Malformed timestamp values raise RelayedTimestampError."""
|
|
34
|
+
body = b'{"event": "delivery.succeeded"}'
|
|
35
|
+
with pytest.raises(RelayedTimestampError):
|
|
36
|
+
verify_webhook(body, "0" * 64, bad_timestamp, SECRET)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_verify_webhook_timestamp_too_old():
|
|
40
|
+
"""A timestamp more than tolerance_seconds in the past raises RelayedTimestampError."""
|
|
41
|
+
body = b'{"event": "delivery.succeeded"}'
|
|
42
|
+
timestamp = _now() - 400
|
|
43
|
+
signature = _sign(body, timestamp, SECRET)
|
|
44
|
+
with pytest.raises(RelayedTimestampError):
|
|
45
|
+
verify_webhook(body, signature, str(timestamp), SECRET)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_verify_webhook_timestamp_too_new():
|
|
49
|
+
"""A timestamp more than tolerance_seconds in the future raises RelayedTimestampError."""
|
|
50
|
+
body = b'{"event": "delivery.succeeded"}'
|
|
51
|
+
timestamp = _now() + 400
|
|
52
|
+
signature = _sign(body, timestamp, SECRET)
|
|
53
|
+
with pytest.raises(RelayedTimestampError):
|
|
54
|
+
verify_webhook(body, signature, str(timestamp), SECRET)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_verify_webhook_bad_signature():
|
|
58
|
+
"""A well-formed but incorrect signature raises RelayedSignatureError."""
|
|
59
|
+
body = b'{"event": "delivery.succeeded"}'
|
|
60
|
+
timestamp = _now()
|
|
61
|
+
with pytest.raises(RelayedSignatureError):
|
|
62
|
+
verify_webhook(body, "0" * 64, str(timestamp), SECRET)
|