polyapi-python 0.1.2__tar.gz → 0.2.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {polyapi-python-0.1.2/polyapi_python.egg-info → polyapi-python-0.2.0.dev1}/PKG-INFO +1 -1
  2. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/auth.py +0 -1
  3. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/generate.py +11 -0
  4. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/utils.py +1 -1
  5. polyapi-python-0.2.0.dev1/polyapi/webhook.py +82 -0
  6. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1/polyapi_python.egg-info}/PKG-INFO +1 -1
  7. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi_python.egg-info/SOURCES.txt +1 -0
  8. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/pyproject.toml +1 -1
  9. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/LICENSE +0 -0
  10. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/README.md +0 -0
  11. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/__init__.py +0 -0
  12. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/__main__.py +0 -0
  13. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/api.py +0 -0
  14. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/cli.py +0 -0
  15. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/config.py +0 -0
  16. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/constants.py +0 -0
  17. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/exceptions.py +0 -0
  18. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/execute.py +0 -0
  19. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/function_cli.py +0 -0
  20. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/py.typed +0 -0
  21. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/schema.py +0 -0
  22. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/server.py +0 -0
  23. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/typedefs.py +0 -0
  24. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi/variables.py +0 -0
  25. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi_python.egg-info/dependency_links.txt +0 -0
  26. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi_python.egg-info/requires.txt +0 -0
  27. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/polyapi_python.egg-info/top_level.txt +0 -0
  28. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/setup.cfg +0 -0
  29. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/tests/test_api.py +0 -0
  30. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/tests/test_auth.py +0 -0
  31. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/tests/test_function_cli.py +0 -0
  32. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/tests/test_server.py +0 -0
  33. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/tests/test_utils.py +0 -0
  34. {polyapi-python-0.1.2 → polyapi-python-0.2.0.dev1}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.1.2
3
+ Version: 0.2.0.dev1
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -13,7 +13,6 @@ from typing import List, Dict, Any, TypedDict, Optional
13
13
 
14
14
  GET_TOKEN_TEMPLATE = """
15
15
  import asyncio
16
- import socketio # type: ignore
17
16
  from polyapi.config import get_api_key_and_url
18
17
 
19
18
 
@@ -5,6 +5,7 @@ import shutil
5
5
  from typing import Any, Dict, List, Tuple
6
6
 
7
7
  from polyapi.auth import render_auth_function
8
+ from polyapi.webhook import render_webhook_handle
8
9
 
9
10
  from .typedefs import PropertySpecification, SpecificationDto, VariableSpecDto
10
11
  from .api import render_api_function
@@ -17,6 +18,7 @@ SUPPORTED_FUNCTION_TYPES = {
17
18
  "apiFunction",
18
19
  "authFunction",
19
20
  "serverFunction",
21
+ "webhookHandle",
20
22
  }
21
23
 
22
24
  SUPPORTED_TYPES = SUPPORTED_FUNCTION_TYPES | {"serverVariable"}
@@ -187,6 +189,15 @@ def add_function_file(
187
189
  arguments,
188
190
  return_type,
189
191
  )
192
+ elif function_type == "webhookHandle":
193
+ func_str, func_type_defs = render_webhook_handle(
194
+ function_type,
195
+ function_name,
196
+ function_id,
197
+ function_description,
198
+ arguments,
199
+ return_type,
200
+ )
190
201
 
191
202
  if func_str:
192
203
  # add function to init
@@ -9,7 +9,7 @@ from polyapi.schema import generate_schema_types, clean_title, map_primitive_typ
9
9
 
10
10
  # this string should be in every __init__ file.
11
11
  # it contains all the imports needed for the function or variable code to run
12
- CODE_IMPORTS = "from typing import List, Dict, Any, TypedDict, Optional\nimport requests\nfrom polyapi.execute import execute, execute_post, variable_get, variable_update\n\n"
12
+ CODE_IMPORTS = "from typing import List, Dict, Any, TypedDict, Optional\nimport requests\nimport socketio # type: ignore\nfrom polyapi.config import get_api_key_and_url\nfrom polyapi.execute import execute, execute_post, variable_get, variable_update\n\n"
13
13
 
14
14
 
15
15
  def init_the_init(full_path: str) -> None:
@@ -0,0 +1,82 @@
1
+ import uuid
2
+ from typing import Any, Dict, List, Tuple
3
+
4
+ from polyapi.typedefs import PropertySpecification
5
+
6
+ WEBHOOK_TEMPLATE = """
7
+ async def {function_name}(callback, options=None):
8
+ "{description}"
9
+ options = options or {{}}
10
+ eventsClientId = "{client_id}"
11
+ function_id = "{function_id}"
12
+
13
+ api_key, base_url = get_api_key_and_url()
14
+ socket = socketio.AsyncClient()
15
+ await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
16
+
17
+ def registerCallback(registered: bool):
18
+ nonlocal socket
19
+ if registered:
20
+ socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
21
+ else:
22
+ print("Could not set register webhook event handler for {function_id}")
23
+
24
+ async def handleEvent(data):
25
+ nonlocal api_key
26
+ nonlocal options
27
+ polyCustom = {{}}
28
+ resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
29
+ if resp and options.get("waitForResponse"):
30
+ await socket.emit('setWebhookListenerResponse', {{
31
+ "webhookHandleID": function_id,
32
+ "apiKey": api_key,
33
+ "clientID": eventsClientId,
34
+ "executionId": data.get("executionId"),
35
+ "response": {{
36
+ "data": resp,
37
+ "statusCode": polyCustom.get("responseStatusCode", 200),
38
+ "contentType": polyCustom.get("responseContentType", None),
39
+ }},
40
+ }}, namespace="/events")
41
+
42
+ data = {{
43
+ "clientID": eventsClientId,
44
+ "webhookHandleID": function_id,
45
+ "apiKey": api_key,
46
+ "waitForResponse": options.get("waitForResponse"),
47
+ }}
48
+ await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
49
+
50
+ async def closeEventHandler():
51
+ nonlocal socket
52
+ if not socket:
53
+ return
54
+
55
+ await socket.emit('unregisterWebhookEventHandler', {{
56
+ "clientID": eventsClientId,
57
+ "webhookHandleID": function_id,
58
+ "apiKey": api_key
59
+ }}, namespace="/events")
60
+
61
+ await socket.wait()
62
+
63
+ return closeEventHandler
64
+ """
65
+
66
+
67
+ def render_webhook_handle(
68
+ function_type: str,
69
+ function_name: str,
70
+ function_id: str,
71
+ function_description: str,
72
+ arguments: List[PropertySpecification],
73
+ return_type: Dict[str, Any],
74
+ ) -> Tuple[str, str]:
75
+ func_str = WEBHOOK_TEMPLATE.format(
76
+ description=function_description,
77
+ client_id=uuid.uuid4().hex,
78
+ function_id=function_id,
79
+ function_name=function_name,
80
+ )
81
+
82
+ return func_str, ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.1.2
3
+ Version: 0.2.0.dev1
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -18,6 +18,7 @@ polyapi/server.py
18
18
  polyapi/typedefs.py
19
19
  polyapi/utils.py
20
20
  polyapi/variables.py
21
+ polyapi/webhook.py
21
22
  polyapi_python.egg-info/PKG-INFO
22
23
  polyapi_python.egg-info/SOURCES.txt
23
24
  polyapi_python.egg-info/dependency_links.txt
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.1.2"
6
+ version = "0.2.0.dev1"
7
7
  description = "The PolyAPI Python Client"
8
8
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
9
9
  dependencies = ["requests", "typing_extensions", "jsonschema-gentypes", "pydantic>=2.5.3", "stdlib_list", "colorama", "python-socketio[asyncio_client]", "truststore"]