wappa 0.1.0__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.
Potentially problematic release.
This version of wappa might be problematic. Click here for more details.
- wappa/__init__.py +85 -0
- wappa/api/__init__.py +1 -0
- wappa/api/controllers/__init__.py +10 -0
- wappa/api/controllers/webhook_controller.py +441 -0
- wappa/api/dependencies/__init__.py +15 -0
- wappa/api/dependencies/whatsapp_dependencies.py +220 -0
- wappa/api/dependencies/whatsapp_media_dependencies.py +26 -0
- wappa/api/middleware/__init__.py +7 -0
- wappa/api/middleware/error_handler.py +158 -0
- wappa/api/middleware/owner.py +99 -0
- wappa/api/middleware/request_logging.py +184 -0
- wappa/api/routes/__init__.py +6 -0
- wappa/api/routes/health.py +102 -0
- wappa/api/routes/webhooks.py +211 -0
- wappa/api/routes/whatsapp/__init__.py +15 -0
- wappa/api/routes/whatsapp/whatsapp_interactive.py +429 -0
- wappa/api/routes/whatsapp/whatsapp_media.py +440 -0
- wappa/api/routes/whatsapp/whatsapp_messages.py +195 -0
- wappa/api/routes/whatsapp/whatsapp_specialized.py +516 -0
- wappa/api/routes/whatsapp/whatsapp_templates.py +431 -0
- wappa/api/routes/whatsapp_combined.py +35 -0
- wappa/cli/__init__.py +9 -0
- wappa/cli/main.py +199 -0
- wappa/core/__init__.py +6 -0
- wappa/core/config/__init__.py +5 -0
- wappa/core/config/settings.py +161 -0
- wappa/core/events/__init__.py +41 -0
- wappa/core/events/default_handlers.py +642 -0
- wappa/core/events/event_dispatcher.py +244 -0
- wappa/core/events/event_handler.py +247 -0
- wappa/core/events/webhook_factory.py +219 -0
- wappa/core/factory/__init__.py +15 -0
- wappa/core/factory/plugin.py +68 -0
- wappa/core/factory/wappa_builder.py +326 -0
- wappa/core/logging/__init__.py +5 -0
- wappa/core/logging/context.py +100 -0
- wappa/core/logging/logger.py +343 -0
- wappa/core/plugins/__init__.py +34 -0
- wappa/core/plugins/auth_plugin.py +169 -0
- wappa/core/plugins/cors_plugin.py +128 -0
- wappa/core/plugins/custom_middleware_plugin.py +182 -0
- wappa/core/plugins/database_plugin.py +235 -0
- wappa/core/plugins/rate_limit_plugin.py +183 -0
- wappa/core/plugins/redis_plugin.py +224 -0
- wappa/core/plugins/wappa_core_plugin.py +261 -0
- wappa/core/plugins/webhook_plugin.py +253 -0
- wappa/core/types.py +108 -0
- wappa/core/wappa_app.py +546 -0
- wappa/database/__init__.py +18 -0
- wappa/database/adapter.py +107 -0
- wappa/database/adapters/__init__.py +17 -0
- wappa/database/adapters/mysql_adapter.py +187 -0
- wappa/database/adapters/postgresql_adapter.py +169 -0
- wappa/database/adapters/sqlite_adapter.py +174 -0
- wappa/domain/__init__.py +28 -0
- wappa/domain/builders/__init__.py +5 -0
- wappa/domain/builders/message_builder.py +189 -0
- wappa/domain/entities/__init__.py +5 -0
- wappa/domain/enums/messenger_platform.py +123 -0
- wappa/domain/factories/__init__.py +6 -0
- wappa/domain/factories/media_factory.py +450 -0
- wappa/domain/factories/message_factory.py +497 -0
- wappa/domain/factories/messenger_factory.py +244 -0
- wappa/domain/interfaces/__init__.py +32 -0
- wappa/domain/interfaces/base_repository.py +94 -0
- wappa/domain/interfaces/cache_factory.py +85 -0
- wappa/domain/interfaces/cache_interface.py +199 -0
- wappa/domain/interfaces/expiry_repository.py +68 -0
- wappa/domain/interfaces/media_interface.py +311 -0
- wappa/domain/interfaces/messaging_interface.py +523 -0
- wappa/domain/interfaces/pubsub_repository.py +151 -0
- wappa/domain/interfaces/repository_factory.py +108 -0
- wappa/domain/interfaces/shared_state_repository.py +122 -0
- wappa/domain/interfaces/state_repository.py +123 -0
- wappa/domain/interfaces/tables_repository.py +215 -0
- wappa/domain/interfaces/user_repository.py +114 -0
- wappa/domain/interfaces/webhooks/__init__.py +1 -0
- wappa/domain/models/media_result.py +110 -0
- wappa/domain/models/platforms/__init__.py +15 -0
- wappa/domain/models/platforms/platform_config.py +104 -0
- wappa/domain/services/__init__.py +11 -0
- wappa/domain/services/tenant_credentials_service.py +56 -0
- wappa/messaging/__init__.py +7 -0
- wappa/messaging/whatsapp/__init__.py +1 -0
- wappa/messaging/whatsapp/client/__init__.py +5 -0
- wappa/messaging/whatsapp/client/whatsapp_client.py +417 -0
- wappa/messaging/whatsapp/handlers/__init__.py +13 -0
- wappa/messaging/whatsapp/handlers/whatsapp_interactive_handler.py +653 -0
- wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +579 -0
- wappa/messaging/whatsapp/handlers/whatsapp_specialized_handler.py +434 -0
- wappa/messaging/whatsapp/handlers/whatsapp_template_handler.py +416 -0
- wappa/messaging/whatsapp/messenger/__init__.py +5 -0
- wappa/messaging/whatsapp/messenger/whatsapp_messenger.py +904 -0
- wappa/messaging/whatsapp/models/__init__.py +61 -0
- wappa/messaging/whatsapp/models/basic_models.py +65 -0
- wappa/messaging/whatsapp/models/interactive_models.py +287 -0
- wappa/messaging/whatsapp/models/media_models.py +215 -0
- wappa/messaging/whatsapp/models/specialized_models.py +304 -0
- wappa/messaging/whatsapp/models/template_models.py +261 -0
- wappa/persistence/cache_factory.py +93 -0
- wappa/persistence/json/__init__.py +14 -0
- wappa/persistence/json/cache_adapters.py +271 -0
- wappa/persistence/json/handlers/__init__.py +1 -0
- wappa/persistence/json/handlers/state_handler.py +250 -0
- wappa/persistence/json/handlers/table_handler.py +263 -0
- wappa/persistence/json/handlers/user_handler.py +213 -0
- wappa/persistence/json/handlers/utils/__init__.py +1 -0
- wappa/persistence/json/handlers/utils/file_manager.py +153 -0
- wappa/persistence/json/handlers/utils/key_factory.py +11 -0
- wappa/persistence/json/handlers/utils/serialization.py +121 -0
- wappa/persistence/json/json_cache_factory.py +76 -0
- wappa/persistence/json/storage_manager.py +285 -0
- wappa/persistence/memory/__init__.py +14 -0
- wappa/persistence/memory/cache_adapters.py +271 -0
- wappa/persistence/memory/handlers/__init__.py +1 -0
- wappa/persistence/memory/handlers/state_handler.py +250 -0
- wappa/persistence/memory/handlers/table_handler.py +280 -0
- wappa/persistence/memory/handlers/user_handler.py +213 -0
- wappa/persistence/memory/handlers/utils/__init__.py +1 -0
- wappa/persistence/memory/handlers/utils/key_factory.py +11 -0
- wappa/persistence/memory/handlers/utils/memory_store.py +317 -0
- wappa/persistence/memory/handlers/utils/ttl_manager.py +235 -0
- wappa/persistence/memory/memory_cache_factory.py +76 -0
- wappa/persistence/memory/storage_manager.py +235 -0
- wappa/persistence/redis/README.md +699 -0
- wappa/persistence/redis/__init__.py +11 -0
- wappa/persistence/redis/cache_adapters.py +285 -0
- wappa/persistence/redis/ops.py +880 -0
- wappa/persistence/redis/redis_cache_factory.py +71 -0
- wappa/persistence/redis/redis_client.py +231 -0
- wappa/persistence/redis/redis_handler/__init__.py +26 -0
- wappa/persistence/redis/redis_handler/state_handler.py +176 -0
- wappa/persistence/redis/redis_handler/table.py +158 -0
- wappa/persistence/redis/redis_handler/user.py +138 -0
- wappa/persistence/redis/redis_handler/utils/__init__.py +12 -0
- wappa/persistence/redis/redis_handler/utils/key_factory.py +32 -0
- wappa/persistence/redis/redis_handler/utils/serde.py +146 -0
- wappa/persistence/redis/redis_handler/utils/tenant_cache.py +268 -0
- wappa/persistence/redis/redis_manager.py +189 -0
- wappa/processors/__init__.py +6 -0
- wappa/processors/base_processor.py +262 -0
- wappa/processors/factory.py +550 -0
- wappa/processors/whatsapp_processor.py +810 -0
- wappa/schemas/__init__.py +6 -0
- wappa/schemas/core/__init__.py +71 -0
- wappa/schemas/core/base_message.py +499 -0
- wappa/schemas/core/base_status.py +322 -0
- wappa/schemas/core/base_webhook.py +312 -0
- wappa/schemas/core/types.py +253 -0
- wappa/schemas/core/webhook_interfaces/__init__.py +48 -0
- wappa/schemas/core/webhook_interfaces/base_components.py +293 -0
- wappa/schemas/core/webhook_interfaces/universal_webhooks.py +348 -0
- wappa/schemas/factory.py +754 -0
- wappa/schemas/webhooks/__init__.py +3 -0
- wappa/schemas/whatsapp/__init__.py +6 -0
- wappa/schemas/whatsapp/base_models.py +285 -0
- wappa/schemas/whatsapp/message_types/__init__.py +93 -0
- wappa/schemas/whatsapp/message_types/audio.py +350 -0
- wappa/schemas/whatsapp/message_types/button.py +267 -0
- wappa/schemas/whatsapp/message_types/contact.py +464 -0
- wappa/schemas/whatsapp/message_types/document.py +421 -0
- wappa/schemas/whatsapp/message_types/errors.py +195 -0
- wappa/schemas/whatsapp/message_types/image.py +424 -0
- wappa/schemas/whatsapp/message_types/interactive.py +430 -0
- wappa/schemas/whatsapp/message_types/location.py +416 -0
- wappa/schemas/whatsapp/message_types/order.py +372 -0
- wappa/schemas/whatsapp/message_types/reaction.py +271 -0
- wappa/schemas/whatsapp/message_types/sticker.py +328 -0
- wappa/schemas/whatsapp/message_types/system.py +317 -0
- wappa/schemas/whatsapp/message_types/text.py +411 -0
- wappa/schemas/whatsapp/message_types/unsupported.py +273 -0
- wappa/schemas/whatsapp/message_types/video.py +344 -0
- wappa/schemas/whatsapp/status_models.py +479 -0
- wappa/schemas/whatsapp/validators.py +454 -0
- wappa/schemas/whatsapp/webhook_container.py +438 -0
- wappa/webhooks/__init__.py +17 -0
- wappa/webhooks/core/__init__.py +71 -0
- wappa/webhooks/core/base_message.py +499 -0
- wappa/webhooks/core/base_status.py +322 -0
- wappa/webhooks/core/base_webhook.py +312 -0
- wappa/webhooks/core/types.py +253 -0
- wappa/webhooks/core/webhook_interfaces/__init__.py +48 -0
- wappa/webhooks/core/webhook_interfaces/base_components.py +293 -0
- wappa/webhooks/core/webhook_interfaces/universal_webhooks.py +441 -0
- wappa/webhooks/factory.py +754 -0
- wappa/webhooks/whatsapp/__init__.py +6 -0
- wappa/webhooks/whatsapp/base_models.py +285 -0
- wappa/webhooks/whatsapp/message_types/__init__.py +93 -0
- wappa/webhooks/whatsapp/message_types/audio.py +350 -0
- wappa/webhooks/whatsapp/message_types/button.py +267 -0
- wappa/webhooks/whatsapp/message_types/contact.py +464 -0
- wappa/webhooks/whatsapp/message_types/document.py +421 -0
- wappa/webhooks/whatsapp/message_types/errors.py +195 -0
- wappa/webhooks/whatsapp/message_types/image.py +424 -0
- wappa/webhooks/whatsapp/message_types/interactive.py +430 -0
- wappa/webhooks/whatsapp/message_types/location.py +416 -0
- wappa/webhooks/whatsapp/message_types/order.py +372 -0
- wappa/webhooks/whatsapp/message_types/reaction.py +271 -0
- wappa/webhooks/whatsapp/message_types/sticker.py +328 -0
- wappa/webhooks/whatsapp/message_types/system.py +317 -0
- wappa/webhooks/whatsapp/message_types/text.py +411 -0
- wappa/webhooks/whatsapp/message_types/unsupported.py +273 -0
- wappa/webhooks/whatsapp/message_types/video.py +344 -0
- wappa/webhooks/whatsapp/status_models.py +479 -0
- wappa/webhooks/whatsapp/validators.py +454 -0
- wappa/webhooks/whatsapp/webhook_container.py +438 -0
- wappa-0.1.0.dist-info/METADATA +269 -0
- wappa-0.1.0.dist-info/RECORD +211 -0
- wappa-0.1.0.dist-info/WHEEL +4 -0
- wappa-0.1.0.dist-info/entry_points.txt +2 -0
- wappa-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Webhook Plugin
|
|
3
|
+
|
|
4
|
+
Specialized plugin for adding webhook endpoints to Wappa applications.
|
|
5
|
+
Perfect for integrating payment providers like Wompi, Stripe, PayPal, etc.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from typing import TYPE_CHECKING, Any
|
|
10
|
+
|
|
11
|
+
from fastapi import APIRouter, Request
|
|
12
|
+
|
|
13
|
+
from ...core.logging.logger import get_app_logger
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from fastapi import FastAPI
|
|
17
|
+
|
|
18
|
+
from ...core.factory.wappa_builder import WappaBuilder
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WebhookPlugin:
|
|
22
|
+
"""
|
|
23
|
+
Plugin for adding specialized webhook endpoints.
|
|
24
|
+
|
|
25
|
+
This plugin makes it easy to add webhook endpoints for payment providers,
|
|
26
|
+
third-party services, or any custom webhook handlers. It provides a clean
|
|
27
|
+
interface for handling webhook requests with proper routing and error handling.
|
|
28
|
+
|
|
29
|
+
Perfect for your Wompi payment provider use case and other webhook integrations.
|
|
30
|
+
|
|
31
|
+
Example:
|
|
32
|
+
# Wompi webhook
|
|
33
|
+
wompi_plugin = WebhookPlugin(
|
|
34
|
+
"wompi",
|
|
35
|
+
wompi_webhook_handler,
|
|
36
|
+
prefix="/webhook/payment"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Stripe webhook
|
|
40
|
+
stripe_plugin = WebhookPlugin(
|
|
41
|
+
"stripe",
|
|
42
|
+
stripe_webhook_handler,
|
|
43
|
+
prefix="/webhook/payment"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Custom webhook
|
|
47
|
+
custom_plugin = WebhookPlugin(
|
|
48
|
+
"notifications",
|
|
49
|
+
notification_handler,
|
|
50
|
+
prefix="/webhook/custom"
|
|
51
|
+
)
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
provider: str,
|
|
57
|
+
handler: Callable,
|
|
58
|
+
prefix: str = None,
|
|
59
|
+
methods: list[str] = None,
|
|
60
|
+
include_tenant_id: bool = True,
|
|
61
|
+
**route_kwargs: Any,
|
|
62
|
+
):
|
|
63
|
+
"""
|
|
64
|
+
Initialize webhook plugin.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
provider: Provider name (e.g., 'wompi', 'stripe', 'paypal')
|
|
68
|
+
handler: Async callable to handle webhook requests
|
|
69
|
+
Signature: async def handler(request: Request, tenant_id: str, provider: str) -> dict
|
|
70
|
+
prefix: URL prefix for the webhook (defaults to /webhook/{provider})
|
|
71
|
+
methods: HTTP methods to accept (defaults to ['POST'])
|
|
72
|
+
include_tenant_id: Whether to include tenant_id in the URL path
|
|
73
|
+
**route_kwargs: Additional arguments for FastAPI route decorator
|
|
74
|
+
"""
|
|
75
|
+
self.provider = provider
|
|
76
|
+
self.handler = handler
|
|
77
|
+
self.prefix = prefix or f"/webhook/{provider}"
|
|
78
|
+
self.methods = methods or ["POST"]
|
|
79
|
+
self.include_tenant_id = include_tenant_id
|
|
80
|
+
self.route_kwargs = route_kwargs
|
|
81
|
+
|
|
82
|
+
self.router = APIRouter()
|
|
83
|
+
|
|
84
|
+
async def configure(self, builder: "WappaBuilder") -> None:
|
|
85
|
+
"""
|
|
86
|
+
Configure the webhook plugin with WappaBuilder.
|
|
87
|
+
|
|
88
|
+
This method creates the FastAPI router with the webhook endpoints
|
|
89
|
+
and adds it to the builder's router collection.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
builder: WappaBuilder instance
|
|
93
|
+
"""
|
|
94
|
+
logger = get_app_logger()
|
|
95
|
+
|
|
96
|
+
# Create webhook endpoint based on configuration
|
|
97
|
+
if self.include_tenant_id:
|
|
98
|
+
# Pattern: /webhook/{provider}/{tenant_id}
|
|
99
|
+
endpoint_path = "/{tenant_id}"
|
|
100
|
+
|
|
101
|
+
# Create the endpoint handler
|
|
102
|
+
@self.router.api_route(
|
|
103
|
+
endpoint_path,
|
|
104
|
+
methods=self.methods,
|
|
105
|
+
tags=[f"{self.provider.title()} Webhooks"],
|
|
106
|
+
**self.route_kwargs,
|
|
107
|
+
)
|
|
108
|
+
async def webhook_endpoint_with_tenant(request: Request, tenant_id: str):
|
|
109
|
+
"""Webhook endpoint with tenant ID in path."""
|
|
110
|
+
return await self.handler(request, tenant_id, self.provider)
|
|
111
|
+
|
|
112
|
+
else:
|
|
113
|
+
# Pattern: /webhook/{provider}
|
|
114
|
+
endpoint_path = "/"
|
|
115
|
+
|
|
116
|
+
# Create the endpoint handler
|
|
117
|
+
@self.router.api_route(
|
|
118
|
+
endpoint_path,
|
|
119
|
+
methods=self.methods,
|
|
120
|
+
tags=[f"{self.provider.title()} Webhooks"],
|
|
121
|
+
**self.route_kwargs,
|
|
122
|
+
)
|
|
123
|
+
async def webhook_endpoint_without_tenant(request: Request):
|
|
124
|
+
"""Webhook endpoint without tenant ID in path."""
|
|
125
|
+
# Call handler with None for tenant_id
|
|
126
|
+
return await self.handler(request, None, self.provider)
|
|
127
|
+
|
|
128
|
+
# Add status endpoint for webhook health checks
|
|
129
|
+
@self.router.get(
|
|
130
|
+
"/status" if not self.include_tenant_id else "/{tenant_id}/status",
|
|
131
|
+
tags=[f"{self.provider.title()} Webhooks"],
|
|
132
|
+
response_model=dict,
|
|
133
|
+
)
|
|
134
|
+
async def webhook_status(request: Request, tenant_id: str = None):
|
|
135
|
+
"""Get webhook status and configuration."""
|
|
136
|
+
return {
|
|
137
|
+
"status": "active",
|
|
138
|
+
"provider": self.provider,
|
|
139
|
+
"tenant_id": tenant_id,
|
|
140
|
+
"webhook_url": str(request.url).replace("/status", ""),
|
|
141
|
+
"methods": self.methods,
|
|
142
|
+
"plugin": "WebhookPlugin",
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Add the router to builder
|
|
146
|
+
builder.add_router(self.router, prefix=self.prefix)
|
|
147
|
+
|
|
148
|
+
logger.debug(
|
|
149
|
+
f"WebhookPlugin configured for {self.provider} - "
|
|
150
|
+
f"Prefix: {self.prefix}, Methods: {self.methods}, "
|
|
151
|
+
f"Include tenant: {self.include_tenant_id}"
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
async def startup(self, app: "FastAPI") -> None:
|
|
155
|
+
"""
|
|
156
|
+
Execute webhook plugin startup logic.
|
|
157
|
+
|
|
158
|
+
Currently no startup tasks needed for webhook endpoints,
|
|
159
|
+
but this provides a hook for future functionality like
|
|
160
|
+
webhook registration with external services.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
app: FastAPI application instance
|
|
164
|
+
"""
|
|
165
|
+
logger = get_app_logger()
|
|
166
|
+
|
|
167
|
+
# Log webhook registration for visibility
|
|
168
|
+
base_url = "https://your-domain.com" # This would be configurable
|
|
169
|
+
if self.include_tenant_id:
|
|
170
|
+
webhook_url = f"{base_url}{self.prefix}/{{tenant_id}}"
|
|
171
|
+
else:
|
|
172
|
+
webhook_url = f"{base_url}{self.prefix}/"
|
|
173
|
+
|
|
174
|
+
logger.info(
|
|
175
|
+
f"WebhookPlugin for {self.provider} ready - "
|
|
176
|
+
f"URL pattern: {webhook_url}, Methods: {self.methods}"
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
async def shutdown(self, app: "FastAPI") -> None:
|
|
180
|
+
"""
|
|
181
|
+
Execute webhook plugin cleanup logic.
|
|
182
|
+
|
|
183
|
+
Currently no cleanup needed for webhook endpoints,
|
|
184
|
+
but this provides a hook for future functionality like
|
|
185
|
+
webhook deregistration with external services.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
app: FastAPI application instance
|
|
189
|
+
"""
|
|
190
|
+
logger = get_app_logger()
|
|
191
|
+
logger.debug(f"WebhookPlugin for {self.provider} shutting down")
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# Convenience functions for common webhook patterns
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def create_payment_webhook_plugin(
|
|
198
|
+
provider: str, handler: Callable, **kwargs: Any
|
|
199
|
+
) -> WebhookPlugin:
|
|
200
|
+
"""
|
|
201
|
+
Create a webhook plugin optimized for payment providers.
|
|
202
|
+
|
|
203
|
+
Uses the pattern /webhook/payment/{tenant_id}/{provider} which matches
|
|
204
|
+
your existing payment webhook structure.
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
provider: Payment provider name (wompi, stripe, paypal, etc.)
|
|
208
|
+
handler: Webhook handler function
|
|
209
|
+
**kwargs: Additional WebhookPlugin arguments
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
Configured WebhookPlugin for payment webhooks
|
|
213
|
+
|
|
214
|
+
Example:
|
|
215
|
+
wompi_plugin = create_payment_webhook_plugin("wompi", wompi_handler)
|
|
216
|
+
"""
|
|
217
|
+
return WebhookPlugin(
|
|
218
|
+
provider=provider,
|
|
219
|
+
handler=handler,
|
|
220
|
+
prefix=f"/webhook/payment/{provider}",
|
|
221
|
+
include_tenant_id=True,
|
|
222
|
+
**kwargs,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def create_service_webhook_plugin(
|
|
227
|
+
service: str, handler: Callable, include_tenant: bool = False, **kwargs: Any
|
|
228
|
+
) -> WebhookPlugin:
|
|
229
|
+
"""
|
|
230
|
+
Create a webhook plugin for general service integrations.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
service: Service name
|
|
234
|
+
handler: Webhook handler function
|
|
235
|
+
include_tenant: Whether to include tenant ID in URL
|
|
236
|
+
**kwargs: Additional WebhookPlugin arguments
|
|
237
|
+
|
|
238
|
+
Returns:
|
|
239
|
+
Configured WebhookPlugin for service webhooks
|
|
240
|
+
|
|
241
|
+
Example:
|
|
242
|
+
notification_plugin = create_service_webhook_plugin(
|
|
243
|
+
"notifications",
|
|
244
|
+
notification_handler
|
|
245
|
+
)
|
|
246
|
+
"""
|
|
247
|
+
return WebhookPlugin(
|
|
248
|
+
provider=service,
|
|
249
|
+
handler=handler,
|
|
250
|
+
prefix=f"/webhook/{service}",
|
|
251
|
+
include_tenant_id=include_tenant,
|
|
252
|
+
**kwargs,
|
|
253
|
+
)
|
wappa/core/types.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core type definitions for Wappa framework.
|
|
3
|
+
|
|
4
|
+
This module contains common type definitions used throughout the Wappa framework.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Literal
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CacheType(Enum):
|
|
12
|
+
"""
|
|
13
|
+
Supported cache types for Wappa applications.
|
|
14
|
+
|
|
15
|
+
This enum defines the cache backends that Wappa can use for state management,
|
|
16
|
+
user data caching, and message logging.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
MEMORY = "memory"
|
|
20
|
+
"""In-memory caching (default) - Fast but not persistent across restarts."""
|
|
21
|
+
|
|
22
|
+
REDIS = "redis"
|
|
23
|
+
"""Redis-based caching - Persistent and scalable, requires Redis server."""
|
|
24
|
+
|
|
25
|
+
JSON = "json"
|
|
26
|
+
"""JSON file-based caching - Persistent but single-process only."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Type alias for user-friendly type hints
|
|
30
|
+
CacheTypeOptions = Literal["memory", "redis", "json"]
|
|
31
|
+
"""
|
|
32
|
+
Type alias for cache type options that provides IDE autocompletion.
|
|
33
|
+
|
|
34
|
+
Use this in function parameters and class constructors where users specify
|
|
35
|
+
cache types as strings.
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
def __init__(self, cache: CacheTypeOptions = "memory"):
|
|
39
|
+
pass
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def validate_cache_type(cache_type: str) -> CacheType:
|
|
44
|
+
"""
|
|
45
|
+
Validate and convert a cache type string to CacheType enum.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
cache_type: String representation of cache type
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Validated CacheType enum value
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
ValueError: If cache_type is not supported
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
>>> validate_cache_type("redis")
|
|
58
|
+
CacheType.REDIS
|
|
59
|
+
|
|
60
|
+
>>> validate_cache_type("invalid")
|
|
61
|
+
ValueError: Unsupported cache type: invalid. Supported types: memory, redis, json
|
|
62
|
+
"""
|
|
63
|
+
try:
|
|
64
|
+
return CacheType(cache_type.lower())
|
|
65
|
+
except ValueError:
|
|
66
|
+
supported_types = [ct.value for ct in CacheType]
|
|
67
|
+
raise ValueError(
|
|
68
|
+
f"Unsupported cache type: {cache_type}. "
|
|
69
|
+
f"Supported types: {', '.join(supported_types)}"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def get_supported_cache_types() -> list[str]:
|
|
74
|
+
"""
|
|
75
|
+
Get list of all supported cache type strings.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
List of supported cache type strings
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
>>> get_supported_cache_types()
|
|
82
|
+
['memory', 'redis', 'json']
|
|
83
|
+
"""
|
|
84
|
+
return [ct.value for ct in CacheType]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def is_cache_type_supported(cache_type: str) -> bool:
|
|
88
|
+
"""
|
|
89
|
+
Check if a cache type string is supported.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
cache_type: String to check
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
True if cache type is supported, False otherwise
|
|
96
|
+
|
|
97
|
+
Example:
|
|
98
|
+
>>> is_cache_type_supported("redis")
|
|
99
|
+
True
|
|
100
|
+
|
|
101
|
+
>>> is_cache_type_supported("invalid")
|
|
102
|
+
False
|
|
103
|
+
"""
|
|
104
|
+
try:
|
|
105
|
+
validate_cache_type(cache_type)
|
|
106
|
+
return True
|
|
107
|
+
except ValueError:
|
|
108
|
+
return False
|