bosa-connectors-binary 0.1.3__cp313-cp313-macosx_11_0_universal2.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.
- bosa_connectors/__init__.pyi +6 -0
- bosa_connectors/action.pyi +80 -0
- bosa_connectors/action_response.pyi +86 -0
- bosa_connectors/auth/__init__.pyi +4 -0
- bosa_connectors/auth/api_key.pyi +19 -0
- bosa_connectors/auth/base.pyi +12 -0
- bosa_connectors/connector.pyi +161 -0
- bosa_connectors/helpers/__init__.pyi +0 -0
- bosa_connectors/helpers/authenticator.pyi +45 -0
- bosa_connectors/helpers/integrations.pyi +49 -0
- bosa_connectors/helpers/model_request_generator.pyi +14 -0
- bosa_connectors/models/__init__.pyi +0 -0
- bosa_connectors/models/action.pyi +16 -0
- bosa_connectors/models/file.pyi +8 -0
- bosa_connectors/models/result.pyi +6 -0
- bosa_connectors/models/token.pyi +10 -0
- bosa_connectors/models/user.pyi +27 -0
- bosa_connectors/module.pyi +76 -0
- bosa_connectors/tool.pyi +46 -0
- bosa_connectors.build/.gitignore +1 -0
- bosa_connectors.cpython-313-darwin.so +0 -0
- bosa_connectors.pyi +31 -0
- bosa_connectors_binary-0.1.3.dist-info/METADATA +3 -0
- bosa_connectors_binary-0.1.3.dist-info/RECORD +26 -0
- bosa_connectors_binary-0.1.3.dist-info/WHEEL +5 -0
- bosa_connectors_binary-0.1.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
from .connector import BosaConnector as BosaConnector
|
2
|
+
from .module import BosaConnectorModule as BosaConnectorModule
|
3
|
+
from .tool import BOSAConnectorToolGenerator as BOSAConnectorToolGenerator
|
4
|
+
from bosa_connectors.helpers.authenticator import BosaAuthenticator as BosaAuthenticator
|
5
|
+
|
6
|
+
__all__ = ['BosaAuthenticator', 'BosaConnector', 'BosaConnectorModule', 'BOSAConnectorToolGenerator']
|
@@ -0,0 +1,80 @@
|
|
1
|
+
from bosa_connectors.action_response import ActionResponse as ActionResponse
|
2
|
+
from bosa_connectors.auth import BaseAuthenticator as BaseAuthenticator
|
3
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
4
|
+
from bosa_connectors.module import BosaConnectorModule as BosaConnectorModule
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
class ActionExecutor:
|
8
|
+
"""Represents a specific action execution for a service.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
# Direct execution with raw response
|
12
|
+
data, status = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .execute()
|
13
|
+
|
14
|
+
# Or with pagination support
|
15
|
+
response = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .run()
|
16
|
+
|
17
|
+
# Get data and handle pagination
|
18
|
+
data = response.get_data()
|
19
|
+
while response.has_next():
|
20
|
+
response = response.next_page()
|
21
|
+
data = response.get_data()
|
22
|
+
"""
|
23
|
+
DEFAULT_MAX_ATTEMPTS: int
|
24
|
+
DEFAULT_TIMEOUT: int
|
25
|
+
def __init__(self, module: BosaConnectorModule, authenticator: BaseAuthenticator, action: str) -> None:
|
26
|
+
"""Initialize the action executor.
|
27
|
+
|
28
|
+
Args:
|
29
|
+
module: The connector module to execute against
|
30
|
+
authenticator: The authenticator to use for requests
|
31
|
+
action: The action name to execute
|
32
|
+
"""
|
33
|
+
def params(self, params: dict[str, Any]) -> ActionExecutor:
|
34
|
+
"""Set additional parameters."""
|
35
|
+
def headers(self, headers: dict[str, str]) -> ActionExecutor:
|
36
|
+
"""Set request headers."""
|
37
|
+
def max_attempts(self, attempts: int) -> ActionExecutor:
|
38
|
+
"""Set maximum retry attempts."""
|
39
|
+
def token(self, token: str | None) -> ActionExecutor:
|
40
|
+
"""Set the BOSA user token for this action."""
|
41
|
+
def timeout(self, timeout: int | None) -> ActionExecutor:
|
42
|
+
"""Set the timeout for the request."""
|
43
|
+
def execute(self) -> tuple[dict[str, Any] | ConnectorFile, int]:
|
44
|
+
"""Execute request and return raw response.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
Tuple of (response_data, status_code)
|
48
|
+
"""
|
49
|
+
def run(self) -> ActionResponse:
|
50
|
+
"""Execute request and return paginated response.
|
51
|
+
|
52
|
+
Returns an ActionResponse that supports pagination for list responses.
|
53
|
+
For single item responses, pagination methods will return the same item.
|
54
|
+
|
55
|
+
Returns:
|
56
|
+
ActionResponse with pagination support
|
57
|
+
"""
|
58
|
+
|
59
|
+
class Action:
|
60
|
+
"""Base class for plugins to prepare action execution.
|
61
|
+
|
62
|
+
Example:
|
63
|
+
# Create a GitHub connector
|
64
|
+
github = bosa.connect('github')
|
65
|
+
|
66
|
+
# Execute with raw response
|
67
|
+
data, status = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .execute()
|
68
|
+
|
69
|
+
# Or with pagination support
|
70
|
+
response = github.action('list_pull_requests') .params({'owner': 'GDP-ADMIN', 'repo': 'bosa'}) .run()
|
71
|
+
"""
|
72
|
+
def __init__(self, module: BosaConnectorModule, authenticator: BaseAuthenticator) -> None:
|
73
|
+
"""Initialize the action builder.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
module: The connector module to use
|
77
|
+
authenticator: The authenticator to use for requests
|
78
|
+
"""
|
79
|
+
def action(self, action: str) -> ActionExecutor:
|
80
|
+
"""Create a new action executor for a service."""
|
@@ -0,0 +1,86 @@
|
|
1
|
+
from bosa_connectors.models.action import ActionResponseData as ActionResponseData, InitialExecutorRequest as InitialExecutorRequest
|
2
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
3
|
+
from typing import Any, Callable
|
4
|
+
|
5
|
+
class ActionResponse:
|
6
|
+
'''Represents the response from an action execution.
|
7
|
+
|
8
|
+
Currently supports 2 pagination modes:
|
9
|
+
1. Page-based pagination: Using page numbers (page=1, page=2, etc.)
|
10
|
+
2. Cursor-based pagination: Using cursor tokens for forwards and backwards navigation
|
11
|
+
|
12
|
+
The class automatically detects which pagination mode to use based on the response metadata:
|
13
|
+
- If "forwards_cursor" and "backwards_cursor" are present, cursor-based pagination is used
|
14
|
+
- Otherwise, it falls back to page-based pagination using "page" parameter
|
15
|
+
|
16
|
+
Common pagination attributes:
|
17
|
+
- total: Total number of items
|
18
|
+
- total_page: Total number of pages
|
19
|
+
- has_next: Whether there is a next page
|
20
|
+
- has_prev: Whether there is a previous page
|
21
|
+
|
22
|
+
Followed by optional attributes
|
23
|
+
Cursor-based pagination attributes:
|
24
|
+
- forwards_cursor: Cursor for next page
|
25
|
+
- backwards_cursor: Cursor for previous page
|
26
|
+
|
27
|
+
Page-based pagination attributes:
|
28
|
+
- page: Current page number
|
29
|
+
- limit: Number of items per page
|
30
|
+
|
31
|
+
If the response is ConnectorFile, it will not support pagination and will return the file directly.
|
32
|
+
'''
|
33
|
+
def __init__(self, response_data: dict[str, Any] | ConnectorFile | None, status: int, response_creator: Callable[..., 'ActionResponse'], initial_executor_request: dict[str, Any]) -> None:
|
34
|
+
'''Initialize response wrapper.
|
35
|
+
|
36
|
+
Args:
|
37
|
+
response_data: Response data which could be:
|
38
|
+
- List response: {"data": [...], "meta": {...}}
|
39
|
+
- Single item response: {"data": {...}, "meta": {...}}
|
40
|
+
status: HTTP status code
|
41
|
+
response_creator: Callable to create a new ActionResponse
|
42
|
+
initial_executor_request: Initial action request attributes as dict
|
43
|
+
'''
|
44
|
+
def get_data(self) -> list[dict[str, Any]] | dict[str, Any] | ConnectorFile:
|
45
|
+
"""Get the current page data.
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
List of objects for paginated responses, or
|
49
|
+
Single object for single item responses
|
50
|
+
"""
|
51
|
+
def get_meta(self) -> dict[str, Any]:
|
52
|
+
"""Get the meta data."""
|
53
|
+
def get_status(self) -> int:
|
54
|
+
"""Get the HTTP status code."""
|
55
|
+
def is_list(self) -> bool:
|
56
|
+
"""Check if the response data is a list."""
|
57
|
+
def has_next(self) -> bool:
|
58
|
+
"""Check if there is a next page.
|
59
|
+
|
60
|
+
Returns False if this is a single item response.
|
61
|
+
"""
|
62
|
+
def has_prev(self) -> bool:
|
63
|
+
"""Check if there is a previous page.
|
64
|
+
|
65
|
+
Returns False if this is a single item response.
|
66
|
+
"""
|
67
|
+
def next_page(self) -> ActionResponse:
|
68
|
+
"""Move to the next page and get the response.
|
69
|
+
|
70
|
+
Supports both page-based and cursor-based navigation:
|
71
|
+
1. If forwards_cursor is available, uses cursor-based navigation
|
72
|
+
2. Otherwise, falls back to page-based navigation
|
73
|
+
|
74
|
+
Returns self if this is a single item response or there is no next page.
|
75
|
+
"""
|
76
|
+
def prev_page(self) -> ActionResponse:
|
77
|
+
"""Move to the previous page and get the response.
|
78
|
+
|
79
|
+
Supports both page-based and cursor-based navigation:
|
80
|
+
1. If backwards_cursor is available, uses cursor-based navigation
|
81
|
+
2. Otherwise, falls back to page-based navigation
|
82
|
+
|
83
|
+
Returns self if this is a single item data or there is no previous page.
|
84
|
+
"""
|
85
|
+
def get_all_items(self) -> list[Any]:
|
86
|
+
"""Get all items from all pages."""
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth.base import BaseAuthenticator as BaseAuthenticator
|
3
|
+
|
4
|
+
class ApiKeyAuthenticator(BaseAuthenticator):
|
5
|
+
"""Injects API Key Headers to BOSA API for Authentication."""
|
6
|
+
API_KEY_HEADER: str
|
7
|
+
api_key: Incomplete
|
8
|
+
def __init__(self, api_key: str) -> None:
|
9
|
+
"""Initializes the ApiKeyAuthenticator with the provided API key.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
api_key (str): The API key for authentication.
|
13
|
+
"""
|
14
|
+
def authenticate(self):
|
15
|
+
"""Authenticates the request.
|
16
|
+
|
17
|
+
Raises:
|
18
|
+
AuthenticationError: If authentication fails.
|
19
|
+
"""
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import abc
|
2
|
+
from abc import ABC, abstractmethod
|
3
|
+
|
4
|
+
class BaseAuthenticator(ABC, metaclass=abc.ABCMeta):
|
5
|
+
"""Base authenticator for BOSA API."""
|
6
|
+
@abstractmethod
|
7
|
+
def authenticate(self):
|
8
|
+
"""Authenticates the request.
|
9
|
+
|
10
|
+
Raises:
|
11
|
+
AuthenticationError: If authentication fails.
|
12
|
+
"""
|
@@ -0,0 +1,161 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.action import Action as Action
|
3
|
+
from bosa_connectors.action_response import ActionResponse as ActionResponse
|
4
|
+
from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
|
5
|
+
from bosa_connectors.helpers.authenticator import BosaAuthenticator as BosaAuthenticator
|
6
|
+
from bosa_connectors.helpers.integrations import BosaIntegrationHelper as BosaIntegrationHelper
|
7
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
8
|
+
from bosa_connectors.models.result import ActionResult as ActionResult
|
9
|
+
from bosa_connectors.models.token import BosaToken as BosaToken
|
10
|
+
from bosa_connectors.models.user import BosaUser as BosaUser, CreateUserResponse as CreateUserResponse
|
11
|
+
from bosa_connectors.module import BosaConnectorError as BosaConnectorError, BosaConnectorModule as BosaConnectorModule
|
12
|
+
from typing import Any
|
13
|
+
|
14
|
+
class BosaConnector:
|
15
|
+
"""Main connector class that manages all BOSA connector modules."""
|
16
|
+
DEFAULT_TIMEOUT: int
|
17
|
+
DEFAULT_MAX_ATTEMPTS: int
|
18
|
+
OAUTH2_FLOW_ENDPOINT: str
|
19
|
+
INTEGRATION_CHECK_ENDPOINT: str
|
20
|
+
api_base_url: Incomplete
|
21
|
+
auth_scheme: Incomplete
|
22
|
+
bosa_authenticator: Incomplete
|
23
|
+
bosa_integration_helper: Incomplete
|
24
|
+
def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
|
25
|
+
"""Initialization."""
|
26
|
+
def get_available_modules(self) -> list[str]:
|
27
|
+
"""Scan and cache all available connector modules.
|
28
|
+
|
29
|
+
Returns:
|
30
|
+
List of available modules
|
31
|
+
"""
|
32
|
+
def create_bosa_user(self, identifier: str) -> CreateUserResponse:
|
33
|
+
"""Create a BOSA User in the scope of BOSA API.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
identifier: BOSA Username
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
BOSA User Data with the secret
|
40
|
+
"""
|
41
|
+
def authenticate_bosa_user(self, identifier: str, secret: str) -> BosaToken:
|
42
|
+
"""Triggers the authentication of the BOSA User in the scope of BOSA API.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
identifier: BOSA Username
|
46
|
+
secret: BOSA Password
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
BOSA User Token
|
50
|
+
"""
|
51
|
+
def initiate_connector_auth(self, app_name: str, token: str, callback_uri: str) -> str:
|
52
|
+
"""Triggers the OAuth2 flow for a connector for this API Key and User Token.
|
53
|
+
|
54
|
+
Args:
|
55
|
+
app_name: The name of the app/connector to use
|
56
|
+
token: The BOSA User Token
|
57
|
+
callback_uri: The callback URL to be used for the integration
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
The redirect URL to be used for the integration
|
61
|
+
"""
|
62
|
+
def get_user_info(self, token: str) -> BosaUser:
|
63
|
+
"""Gets the user information for a given token.
|
64
|
+
|
65
|
+
Args:
|
66
|
+
token: The BOSA User Token
|
67
|
+
|
68
|
+
Returns:
|
69
|
+
BOSA User
|
70
|
+
"""
|
71
|
+
def user_has_integration(self, app_name: str, token: str) -> bool:
|
72
|
+
"""Checks whether or not a user has an integration for a given app in this client.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
app_name: The name of the app/connector to use
|
76
|
+
token: The BOSA User Token
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
True if the user has an integration for the given app
|
80
|
+
"""
|
81
|
+
def remove_integration(self, app_name: str, token: str) -> ActionResult:
|
82
|
+
"""Removes a 3rd party integration for a user against a certain client.
|
83
|
+
|
84
|
+
Args:
|
85
|
+
app_name: The name of the app/connector to use
|
86
|
+
token: The BOSA User Token
|
87
|
+
|
88
|
+
Returns:
|
89
|
+
Result that contains an error message (if any), and the success status.
|
90
|
+
"""
|
91
|
+
def get_connector(self, app_name: str) -> BosaConnectorModule:
|
92
|
+
"""Get or create an instance of a connector module.
|
93
|
+
|
94
|
+
Args:
|
95
|
+
app_name: The name of the app/connector to use
|
96
|
+
|
97
|
+
Returns:
|
98
|
+
BosaConnectorModule: The connector module
|
99
|
+
"""
|
100
|
+
def refresh_connector(self, app_name: str) -> None:
|
101
|
+
"""Refresh the connector module."""
|
102
|
+
def connect(self, app_name: str) -> Action:
|
103
|
+
"""Connect to a specific module and prepare for action execution.
|
104
|
+
|
105
|
+
Creates an Action instance for the specified connector..
|
106
|
+
|
107
|
+
Example:
|
108
|
+
# Create action builders for different connectors
|
109
|
+
github = bosa.connect('github')
|
110
|
+
gdrive = bosa.connect('google_drive') # This is just an example
|
111
|
+
|
112
|
+
Args:
|
113
|
+
app_name: The name of the app/connector to use (eg: 'github', 'google_drive', etc)
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
Action: A new Action instance for the specified connector
|
117
|
+
"""
|
118
|
+
def execute(self, app_name: str, action: str, *, max_attempts: int = ..., input_: dict[str, Any] = None, token: str | None = None, headers: dict[str, str] | None = None, timeout: int | None = ..., **kwargs) -> tuple[dict[str, Any] | ConnectorFile, int]:
|
119
|
+
"""Execute an action on a specific module and return raw response.
|
120
|
+
|
121
|
+
The method supports both ways of passing parameters:
|
122
|
+
1. As a dictionary: execute(app_name, action, params_dict)
|
123
|
+
2. As keyword arguments: execute(app_name, action, param1=value1, param2=value2)
|
124
|
+
|
125
|
+
Args:
|
126
|
+
app_name: The name of the app/connector to use
|
127
|
+
action: The action to execute
|
128
|
+
input_: Optional input data for the action
|
129
|
+
token: The BOSA User Token
|
130
|
+
headers: Optional headers to include in the request
|
131
|
+
max_attempts: The number of times the request can be retried for. Default is 0 (does not retry). Note that
|
132
|
+
the backoff factor is 2^(N - 1) with the basic value being 1 second (1, 2, 4, 8, 16, 32, ...).
|
133
|
+
Maximum number of retries is 10 with a maximum of 64 seconds per retry.
|
134
|
+
timeout: Optional timeout for the request in seconds. Default is 30 seconds.
|
135
|
+
**kwargs: Optional keyword arguments
|
136
|
+
|
137
|
+
Returns:
|
138
|
+
Tuple of (response, status_code) where response is the API response and status_code is the HTTP status code
|
139
|
+
"""
|
140
|
+
def run(self, app_name: str, action: str, *, max_attempts: int = ..., input_: dict[str, Any] = None, token: str | None = None, headers: dict[str, str] | None = None, timeout: int | None = ..., **kwargs) -> ActionResponse:
|
141
|
+
"""Execute an action on a specific module and return paginated response.
|
142
|
+
|
143
|
+
The method supports both ways of passing parameters:
|
144
|
+
1. As a dictionary: execute(app_name, action, input_dict)
|
145
|
+
2. As keyword arguments: execute(app_name, action, param1=value1, param2=value2)
|
146
|
+
|
147
|
+
Args:
|
148
|
+
app_name: The name of the app/connector to use
|
149
|
+
action: The action to execute
|
150
|
+
input_: Optional input data for the action
|
151
|
+
token: The BOSA User Token
|
152
|
+
headers: Optional headers to include in the request
|
153
|
+
max_attempts: The number of times the request can be retried for. Default is 0 (does not retry). Note that
|
154
|
+
the backoff factor is 2^(N - 1) with the basic value being 1 second (1, 2, 4, 8, 16, 32, ...).
|
155
|
+
Maximum number of retries is 10 with a maximum of 64 seconds per retry.
|
156
|
+
timeout: Optional timeout for the request in seconds. Default is 30 seconds.
|
157
|
+
**kwargs: Optional keyword arguments
|
158
|
+
|
159
|
+
Returns:
|
160
|
+
ActionResponse: Response wrapper with pagination support
|
161
|
+
"""
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
|
3
|
+
from bosa_connectors.models.token import BosaToken as BosaToken
|
4
|
+
from bosa_connectors.models.user import BosaUser as BosaUser, CreateUserResponse as CreateUserResponse
|
5
|
+
|
6
|
+
class BosaAuthenticator:
|
7
|
+
"""Authenticator for BOSA API."""
|
8
|
+
DEFAULT_TIMEOUT: int
|
9
|
+
api_base_url: Incomplete
|
10
|
+
auth_scheme: Incomplete
|
11
|
+
def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
|
12
|
+
'''Initialize the BosaAuthenticator with the provided API key.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
api_base_url (str): The base URL for the BOSA API. Defaults to "https://api.bosa.id".
|
16
|
+
api_key (str): The API key for authentication. Defaults to "bosa".
|
17
|
+
'''
|
18
|
+
def register(self, identifier: str) -> CreateUserResponse:
|
19
|
+
"""Register a BOSA User in the scope of BOSA API.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
identifier: BOSA Username
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
BOSA User Data with the secret
|
26
|
+
"""
|
27
|
+
def authenticate(self, identifier: str, secret: str) -> BosaToken:
|
28
|
+
"""Authenticate a BOSA User in the scope of BOSA API.
|
29
|
+
|
30
|
+
Args:
|
31
|
+
identifier: BOSA Username
|
32
|
+
secret: BOSA Password
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
BOSA User Token
|
36
|
+
"""
|
37
|
+
def get_user(self, token: str) -> BosaUser:
|
38
|
+
"""Get the current user from BOSA API.
|
39
|
+
|
40
|
+
Args:
|
41
|
+
token: The BOSA User Token
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
BOSA User
|
45
|
+
"""
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth import ApiKeyAuthenticator as ApiKeyAuthenticator
|
3
|
+
from bosa_connectors.models.result import ActionResult as ActionResult
|
4
|
+
|
5
|
+
class BosaIntegrationHelper:
|
6
|
+
"""Helper class for BOSA API integrations."""
|
7
|
+
OAUTH2_FLOW_ENDPOINT: str
|
8
|
+
INTEGRATION_CHECK_ENDPOINT: str
|
9
|
+
DEFAULT_TIMEOUT: int
|
10
|
+
api_base_url: Incomplete
|
11
|
+
auth_scheme: Incomplete
|
12
|
+
def __init__(self, api_base_url: str = 'https://api.bosa.id', api_key: str = 'bosa') -> None:
|
13
|
+
'''Initializes the BosaIntegrationHelper with the provided API key.
|
14
|
+
|
15
|
+
Args:
|
16
|
+
api_base_url (str): The base URL for the BOSA API. Defaults to "https://api.bosa.id".
|
17
|
+
api_key (str): The API key for authentication. Defaults to "bosa".
|
18
|
+
'''
|
19
|
+
def user_has_integration(self, app_name: str, token: str) -> bool:
|
20
|
+
"""Checks whether or not a user has an integration for a given app in this client.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
app_name: The name of the app/connector to use
|
24
|
+
token: The BOSA User Token
|
25
|
+
|
26
|
+
Returns:
|
27
|
+
True if the user has an integration for the given app
|
28
|
+
"""
|
29
|
+
def initiate_integration(self, app_name: str, token: str, callback_uri: str) -> str:
|
30
|
+
"""Initiates a 3rd party integration for a user against a certain client.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
app_name: The name of the app/connector to use
|
34
|
+
token: The BOSA User Token
|
35
|
+
callback_uri: The callback URL to be used for the integration
|
36
|
+
|
37
|
+
Returns:
|
38
|
+
The integration URL
|
39
|
+
"""
|
40
|
+
def remove_integration(self, app_name: str, token: str) -> ActionResult:
|
41
|
+
"""Removes a 3rd party integration for a user against a certain client.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
app_name: The name of the app/connector to use
|
45
|
+
token: The BOSA User Token
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
Result that contains an error message (if any), and the success status.
|
49
|
+
"""
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
|
3
|
+
def create_request_model(endpoint_name: str, schema: dict, service_prefix: str = 'Google', requires_auth: bool = False) -> type[BaseModel]:
|
4
|
+
'''Create a Pydantic model for the request schema.
|
5
|
+
|
6
|
+
Args:
|
7
|
+
endpoint_name (str): The name of the endpoint.
|
8
|
+
schema (dict): The schema definition for the endpoint.
|
9
|
+
service_prefix (str, optional): The prefix for the service. Defaults to "Google".
|
10
|
+
requires_auth (bool, optional): Whether the endpoint requires authentication. Defaults to False.
|
11
|
+
|
12
|
+
Returns:
|
13
|
+
Type[BaseModel]: The generated Pydantic model.
|
14
|
+
'''
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
2
|
+
from pydantic import BaseModel
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
class ActionResponseData(BaseModel):
|
6
|
+
"""Response data model with data and meta information."""
|
7
|
+
data: list[Any] | dict[str, Any] | ConnectorFile
|
8
|
+
meta: dict[str, Any] | None
|
9
|
+
|
10
|
+
class InitialExecutorRequest(BaseModel):
|
11
|
+
"""Initial executor request model."""
|
12
|
+
params: dict[str, Any]
|
13
|
+
headers: dict[str, str] | None
|
14
|
+
max_attempts: int | None
|
15
|
+
token: str | None
|
16
|
+
timeout: int | None
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
class ThirdPartyIntegrationAuthBasic(BaseModel):
|
5
|
+
"""Basic model for a third party integration authentication."""
|
6
|
+
id: UUID
|
7
|
+
client_id: UUID
|
8
|
+
user_id: UUID
|
9
|
+
connector: str
|
10
|
+
user_identifier: str
|
11
|
+
|
12
|
+
class BosaUser(BaseModel):
|
13
|
+
"""Model for a BOSA User."""
|
14
|
+
id: UUID
|
15
|
+
client_id: UUID
|
16
|
+
identifier: str
|
17
|
+
secret_preview: str
|
18
|
+
is_active: bool
|
19
|
+
integrations: list[ThirdPartyIntegrationAuthBasic]
|
20
|
+
|
21
|
+
class CreateUserResponse(BaseModel):
|
22
|
+
"""Model for a BOSA User creation response."""
|
23
|
+
id: UUID
|
24
|
+
identifier: str
|
25
|
+
secret: str
|
26
|
+
secret_preview: str
|
27
|
+
is_active: bool
|
@@ -0,0 +1,76 @@
|
|
1
|
+
from _typeshed import Incomplete
|
2
|
+
from bosa_connectors.auth import BaseAuthenticator as BaseAuthenticator
|
3
|
+
from bosa_connectors.models.file import ConnectorFile as ConnectorFile
|
4
|
+
from pydantic import BaseModel as BaseModel
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
class BosaConnectorError(Exception):
|
8
|
+
"""Base exception for BOSA connector errors."""
|
9
|
+
|
10
|
+
class BosaConnectorModule:
|
11
|
+
"""Base class for all BOSA connector modules."""
|
12
|
+
app_name: str
|
13
|
+
DEFAULT_TIMEOUT: int
|
14
|
+
MAX_RETRY: int
|
15
|
+
MAX_BACKOFF_SECONDS: int
|
16
|
+
INFO_PATH: str
|
17
|
+
EXCLUDED_ENDPOINTS: Incomplete
|
18
|
+
@staticmethod
|
19
|
+
def is_retryable_error(status_code: int) -> bool:
|
20
|
+
"""Check if the status code indicates a retryable error (429 or 5xx).
|
21
|
+
|
22
|
+
Args:
|
23
|
+
status_code: HTTP status code to check
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
bool: True if the error is retryable
|
27
|
+
"""
|
28
|
+
api_base_url: Incomplete
|
29
|
+
info_path: Incomplete
|
30
|
+
def __init__(self, app_name: str, api_base_url: str = 'https://api.bosa.id', info_path: str = ...) -> None:
|
31
|
+
"""Initialize a new connector module.
|
32
|
+
|
33
|
+
This constructor should only be called by BosaConnector.
|
34
|
+
"""
|
35
|
+
def get_actions(self) -> list[tuple[str, str, str]]:
|
36
|
+
"""Return list of available actions for this module."""
|
37
|
+
def get_action_parameters(self, action: str):
|
38
|
+
"""Get flattened parameter information for an action.
|
39
|
+
|
40
|
+
Args:
|
41
|
+
action: The action endpoint
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
List of parameter info dicts with name, type, and required fields.
|
45
|
+
Nested objects are flattened using dot notation, e.g.:
|
46
|
+
object.attr1, object.attr2, object.attr3.attr21
|
47
|
+
"""
|
48
|
+
def validate_request(self, action: str, params: dict[str, Any]) -> tuple[dict[str, Any] | None, dict[str, str]]:
|
49
|
+
"""Validate and clean request parameters.
|
50
|
+
|
51
|
+
Args:
|
52
|
+
action: The action endpoint
|
53
|
+
params: Dict of parameter values
|
54
|
+
|
55
|
+
Returns:
|
56
|
+
Tuple of (cleaned_params, error_details) where error_details is empty if validation passed
|
57
|
+
"""
|
58
|
+
def execute(self, action: str, max_attempts: int, input_: dict = None, token: str | None = None, authenticator: BaseAuthenticator | None = None, headers: dict[str, str] | None = None, timeout: int | None = ...) -> tuple[dict[str, Any] | ConnectorFile, int]:
|
59
|
+
"""Execute an action with validated parameters and return typed response.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
action: The action to execute
|
63
|
+
max_attempts: Maximum number of attempts for failed requests (429 or 5xx errors). Must be at least 1.
|
64
|
+
Will be capped at MAX_RETRY (10) to prevent excessive retries.
|
65
|
+
input_: Optional dictionary of parameters
|
66
|
+
token: Optional BOSA User Token. If not provided, will use the default token
|
67
|
+
authenticator: Optional authenticator to use for the request
|
68
|
+
headers: Optional headers to include in the request
|
69
|
+
|
70
|
+
The method supports both ways of passing parameters:
|
71
|
+
1. As a dictionary: execute(action, params_dict)
|
72
|
+
2. As keyword arguments: execute(action, param1=value1, param2=value2)
|
73
|
+
|
74
|
+
Raises:
|
75
|
+
ValueError: If action is invalid, parameters are invalid, or max_attempts is less than 1
|
76
|
+
"""
|
bosa_connectors/tool.pyi
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
from .connector import BosaConnector as BosaConnector
|
2
|
+
from .helpers.model_request_generator import create_request_model as create_request_model
|
3
|
+
from _typeshed import Incomplete
|
4
|
+
from langchain_core.tools import BaseTool
|
5
|
+
from pydantic import BaseModel as BaseModel
|
6
|
+
|
7
|
+
class BosaConnectorToolError(Exception):
|
8
|
+
"""Base exception for BOSA connector errors."""
|
9
|
+
|
10
|
+
class BOSAConnectorToolGenerator:
|
11
|
+
"""Tool Generator for BOSA Connectors.
|
12
|
+
|
13
|
+
This class generates tools based on OpenAPI schemas for various services.
|
14
|
+
|
15
|
+
Attributes:
|
16
|
+
api_base_url (str): The base URL for the API.
|
17
|
+
api_key (str): The API key for authentication.
|
18
|
+
info_path (str): The path to the API information endpoint.
|
19
|
+
DEFAULT_TIMEOUT (int): Default timeout for API requests.
|
20
|
+
app_name (str): The name of the application.
|
21
|
+
schema_data (dict): The schema data for the services.
|
22
|
+
|
23
|
+
Methods:
|
24
|
+
generate_tools(): Generates tools for the specified services.
|
25
|
+
"""
|
26
|
+
api_base_url: str
|
27
|
+
api_key: str
|
28
|
+
INFO_PATH: str
|
29
|
+
DEFAULT_TIMEOUT: int
|
30
|
+
app_name: str
|
31
|
+
schema_data: dict
|
32
|
+
EXCLUDED_ENDPOINTS: Incomplete
|
33
|
+
def __init__(self, api_base_url: str, api_key: str, app_name: str) -> None:
|
34
|
+
"""Initialize the tool generator with API base URL, info path, and app name.
|
35
|
+
|
36
|
+
Args:
|
37
|
+
api_base_url (str): The base URL for the API.
|
38
|
+
api_key (str): The API key for authentication.
|
39
|
+
app_name (str): The name of the application.
|
40
|
+
"""
|
41
|
+
def generate_tools(self) -> list[BaseTool]:
|
42
|
+
"""Generate tools based on the BOSA API OpenAPI schemas.
|
43
|
+
|
44
|
+
Returns:
|
45
|
+
Dict[str, Type[BaseTool]]: A dictionary of generated tool classes.
|
46
|
+
"""
|
@@ -0,0 +1 @@
|
|
1
|
+
*
|
Binary file
|
bosa_connectors.pyi
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# This file was generated by Nuitka
|
2
|
+
|
3
|
+
# Stubs included by default
|
4
|
+
from bosa_connectors.helpers.authenticator import BosaAuthenticator
|
5
|
+
from module import BosaConnectorModule
|
6
|
+
from tool import BOSAConnectorToolGenerator
|
7
|
+
from connector import BosaConnector
|
8
|
+
|
9
|
+
|
10
|
+
__name__ = ...
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# Modules used internally, to allow implicit dependencies to be seen:
|
15
|
+
import os
|
16
|
+
import typing
|
17
|
+
import bosa_connectors.auth.BaseAuthenticator
|
18
|
+
import abc
|
19
|
+
import logging
|
20
|
+
import requests
|
21
|
+
import requests.exceptions
|
22
|
+
import bosa_connectors.auth.ApiKeyAuthenticator
|
23
|
+
import pydantic
|
24
|
+
import uuid
|
25
|
+
import random
|
26
|
+
import time
|
27
|
+
import cgi
|
28
|
+
import legacy_cgi
|
29
|
+
import inspect
|
30
|
+
import langchain_core
|
31
|
+
import langchain_core.tools
|
@@ -0,0 +1,26 @@
|
|
1
|
+
bosa_connectors.cpython-313-darwin.so,sha256=_kN-RzL07l2cgrDYncZl5XFMsHhNVK002J-L1LOivEA,952344
|
2
|
+
bosa_connectors.pyi,sha256=nHURoVUwcgMfcsbiXPeT96DBCaaiRIuNm0va3oT_wC8,676
|
3
|
+
bosa_connectors/__init__.pyi,sha256=WWB74z-l47ZA70CxIw75ElOnqFeKACWkcvTLA4ucqTw,384
|
4
|
+
bosa_connectors/action.pyi,sha256=zGqRYx9bD7H0V4cMKwF83OLlwuVaDd_Oi4LG7gp7Lfc,3358
|
5
|
+
bosa_connectors/action_response.pyi,sha256=8Dj8YZsgvS6hGS-wyb-4VUxZzNLZqisCouYe3V9_DKY,3674
|
6
|
+
bosa_connectors/connector.pyi,sha256=CARDA0JaXJkwbvHmqfAHq4VMhaQhPxgW6eH7ZmPxi20,7279
|
7
|
+
bosa_connectors/module.pyi,sha256=O72bNcKGdfDL5yZzkUOth4BXTDjyUg4YAhYn2TiEgKs,3277
|
8
|
+
bosa_connectors/tool.pyi,sha256=GeCDaOIUWutPLDYk61z7YwNPhWMYU8bV_lb62BUynp8,1725
|
9
|
+
bosa_connectors/auth/__init__.pyi,sha256=gpzI0J6hSddF7xEZ7j5M1Lcy-MaICCTj5dJFhcaqxXc,177
|
10
|
+
bosa_connectors/auth/api_key.pyi,sha256=uFKPef2dqRaQ-2N-3J1kYU3Oh-PsDuh4q2_3jB2KSNY,630
|
11
|
+
bosa_connectors/auth/base.pyi,sha256=hjN2euyXyAuFGsxClgIFz_pOy-Q9jV3-vUcinZ-3J-Q,317
|
12
|
+
bosa_connectors/helpers/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
+
bosa_connectors/helpers/authenticator.pyi,sha256=QwsQ1a0U4Ah2Wg4xnco9Rf2jIsF7EYPvhSyUxxPpStk,1521
|
14
|
+
bosa_connectors/helpers/integrations.pyi,sha256=v2PkmsotlT8eo3RAB7hiIC30BN3MN5BO8UjeCRoDu6Q,1961
|
15
|
+
bosa_connectors/helpers/model_request_generator.pyi,sha256=ZmFPKfku3HA7zuTwcUMZ5Ba4qvkzoC3-FmvtFRTWdJc,628
|
16
|
+
bosa_connectors/models/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
bosa_connectors/models/action.pyi,sha256=Ru4n0xZflIp8Pjoqq-9eJoaDCacrWIA0OvMXmFwOZ7w,531
|
18
|
+
bosa_connectors/models/file.pyi,sha256=PBZZkodDAeW1oysX5R5pJ9-d8yd5eKWVccAh1oYcjXM,237
|
19
|
+
bosa_connectors/models/result.pyi,sha256=ISmHBFlkyVzyAxeQXwVVEqNXd4SZQI4YV1vd8i8S-NM,136
|
20
|
+
bosa_connectors/models/token.pyi,sha256=NN7VfzoudeojK5oWVUmCi4Qo02RUjbveKzDpbh1RrGU,206
|
21
|
+
bosa_connectors/models/user.pyi,sha256=KsVrc0MYB1z6fikCv1qSrjnP8ISWChxr9Fx0T0nbsKw,661
|
22
|
+
bosa_connectors.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
23
|
+
bosa_connectors_binary-0.1.3.dist-info/METADATA,sha256=FB-z49dq7dlkBHlCLdmU0VDos_Tr_6AyIwtenrVc_Lc,66
|
24
|
+
bosa_connectors_binary-0.1.3.dist-info/WHEEL,sha256=Aa_QnnFX9DlX1bhwfX9qhtMl9nT6KT5RrQ7brstHKLw,109
|
25
|
+
bosa_connectors_binary-0.1.3.dist-info/top_level.txt,sha256=3UzTb-ce0A17T_gQLs-Bhq-ilOx6tosXQJkZbGsRWW8,16
|
26
|
+
bosa_connectors_binary-0.1.3.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
bosa_connectors
|