moontraze 1.0.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.
- moontraze-1.0.0/LICENSE +21 -0
- moontraze-1.0.0/PKG-INFO +35 -0
- moontraze-1.0.0/README.md +8 -0
- moontraze-1.0.0/moontraze/__init__.py +43 -0
- moontraze-1.0.0/moontraze/auth.py +111 -0
- moontraze-1.0.0/moontraze/client.py +114 -0
- moontraze-1.0.0/moontraze/database.py +70 -0
- moontraze-1.0.0/moontraze/notifications.py +111 -0
- moontraze-1.0.0/moontraze/storage.py +137 -0
- moontraze-1.0.0/moontraze.egg-info/PKG-INFO +35 -0
- moontraze-1.0.0/moontraze.egg-info/SOURCES.txt +14 -0
- moontraze-1.0.0/moontraze.egg-info/dependency_links.txt +1 -0
- moontraze-1.0.0/moontraze.egg-info/requires.txt +5 -0
- moontraze-1.0.0/moontraze.egg-info/top_level.txt +1 -0
- moontraze-1.0.0/pyproject.toml +44 -0
- moontraze-1.0.0/setup.cfg +4 -0
moontraze-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Moontraze
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
moontraze-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moontraze
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Moontraze SDK — Auth, Database, Storage, Notifications
|
|
5
|
+
Author-email: Moontraze <faisalrizwan0077@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://moontraze.com
|
|
8
|
+
Project-URL: Repository, https://github.com/moontraze/sdk-python
|
|
9
|
+
Project-URL: Documentation, https://docs.moontraze.com
|
|
10
|
+
Keywords: moontraze,backend,auth,database,storage,notifications,sdk
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: requests>=2.28.0
|
|
23
|
+
Requires-Dist: urllib3>=1.26.0
|
|
24
|
+
Provides-Extra: async
|
|
25
|
+
Requires-Dist: aiohttp>=3.8.0; extra == "async"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# moontraze
|
|
29
|
+
|
|
30
|
+
Official Moontraze Python SDK — Auth, Database, Storage, and Push Notifications.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install moontraze
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Moontraze SDK
|
|
3
|
+
Official Python SDK for Moontraze — Auth, Database, Storage, Notifications
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .client import MoonClient, MoonError, MoonConfig
|
|
7
|
+
from .auth import MoonAuth
|
|
8
|
+
from .database import MoonDatabase
|
|
9
|
+
from .storage import MoonStorage
|
|
10
|
+
from .notifications import MoonNotifications
|
|
11
|
+
|
|
12
|
+
__version__ = "1.0.0"
|
|
13
|
+
__author__ = "Moontraze"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MoonSDK:
|
|
17
|
+
"""Main Moontraze SDK client"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, config: MoonConfig):
|
|
20
|
+
self.config = config
|
|
21
|
+
self.auth = MoonAuth(config)
|
|
22
|
+
self.db = MoonDatabase(config)
|
|
23
|
+
self.storage = MoonStorage(config)
|
|
24
|
+
self.notifications = MoonNotifications(config)
|
|
25
|
+
|
|
26
|
+
def set_token(self, token: str | None):
|
|
27
|
+
"""Set auth token for subsequent requests"""
|
|
28
|
+
self.auth.set_token(token)
|
|
29
|
+
self.db.set_token(token)
|
|
30
|
+
self.storage.set_token(token)
|
|
31
|
+
self.notifications.set_token(token)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"MoonSDK",
|
|
36
|
+
"MoonClient",
|
|
37
|
+
"MoonError",
|
|
38
|
+
"MoonConfig",
|
|
39
|
+
"MoonAuth",
|
|
40
|
+
"MoonDatabase",
|
|
41
|
+
"MoonStorage",
|
|
42
|
+
"MoonNotifications",
|
|
43
|
+
]
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Authentication module"""
|
|
2
|
+
from typing import Optional, Dict, Any
|
|
3
|
+
from .client import MoonClient, MoonConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MoonAuth(MoonClient):
|
|
7
|
+
"""Authentication"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, config: MoonConfig):
|
|
10
|
+
super().__init__(config)
|
|
11
|
+
|
|
12
|
+
def register(
|
|
13
|
+
self,
|
|
14
|
+
email: str,
|
|
15
|
+
password: str,
|
|
16
|
+
name: Optional[str] = None,
|
|
17
|
+
) -> Dict[str, Any]:
|
|
18
|
+
"""Register a new user"""
|
|
19
|
+
data = self.request("POST", "/api/auth", {
|
|
20
|
+
"action": "register",
|
|
21
|
+
"email": email,
|
|
22
|
+
"password": password,
|
|
23
|
+
"name": name or email.split("@")[0],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if data.get("token"):
|
|
27
|
+
self.set_token(data["token"])
|
|
28
|
+
|
|
29
|
+
return data
|
|
30
|
+
|
|
31
|
+
def login(self, email: str, password: str) -> Dict[str, Any]:
|
|
32
|
+
"""Login a user"""
|
|
33
|
+
data = self.request("POST", "/api/auth", {
|
|
34
|
+
"action": "login",
|
|
35
|
+
"email": email,
|
|
36
|
+
"password": password,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
# Check if TOTP required
|
|
40
|
+
if data.get("requiresTotp"):
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
if data.get("token"):
|
|
44
|
+
self.set_token(data["token"])
|
|
45
|
+
|
|
46
|
+
return data
|
|
47
|
+
|
|
48
|
+
def verify_totp(self, login_ticket: str, code: str) -> Dict[str, Any]:
|
|
49
|
+
"""Verify TOTP code after login"""
|
|
50
|
+
data = self.request("POST", "/api/auth", {
|
|
51
|
+
"action": "login-verify",
|
|
52
|
+
"loginTicket": login_ticket,
|
|
53
|
+
"code": code,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if data.get("token"):
|
|
57
|
+
self.set_token(data["token"])
|
|
58
|
+
|
|
59
|
+
return data
|
|
60
|
+
|
|
61
|
+
def logout(self):
|
|
62
|
+
"""Logout current user"""
|
|
63
|
+
self.set_token(None)
|
|
64
|
+
|
|
65
|
+
def change_password(
|
|
66
|
+
self,
|
|
67
|
+
current_password: str,
|
|
68
|
+
new_password: str,
|
|
69
|
+
) -> Dict[str, Any]:
|
|
70
|
+
"""Change password (logged in)"""
|
|
71
|
+
return self.request("POST", "/api/auth", {
|
|
72
|
+
"action": "change-password",
|
|
73
|
+
"currentPassword": current_password,
|
|
74
|
+
"newPassword": new_password,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
def enroll_totp(self) -> Dict[str, Any]:
|
|
78
|
+
"""Enroll MON Authenticator (get QR)"""
|
|
79
|
+
return self.request("POST", "/api/authenticator/enroll", {})
|
|
80
|
+
|
|
81
|
+
def confirm_totp(self, code: str) -> Dict[str, Any]:
|
|
82
|
+
"""Confirm MON Authenticator enrollment"""
|
|
83
|
+
return self.request("POST", "/api/authenticator/confirm", {
|
|
84
|
+
"code": code,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
def forgot_password_verify(
|
|
88
|
+
self,
|
|
89
|
+
email: str,
|
|
90
|
+
code: str,
|
|
91
|
+
) -> Dict[str, Any]:
|
|
92
|
+
"""Forgot password — step 1 (verify TOTP)"""
|
|
93
|
+
return self.request("POST", "/api/authenticator/verify", {
|
|
94
|
+
"email": email,
|
|
95
|
+
"code": code,
|
|
96
|
+
"projectId": self.config.project_id,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
def forgot_password_reset(
|
|
100
|
+
self,
|
|
101
|
+
email: str,
|
|
102
|
+
verify_token: str,
|
|
103
|
+
new_password: str,
|
|
104
|
+
) -> Dict[str, Any]:
|
|
105
|
+
"""Forgot password — step 2 (reset)"""
|
|
106
|
+
return self.request("POST", "/api/auth", {
|
|
107
|
+
"action": "reset-password",
|
|
108
|
+
"email": email,
|
|
109
|
+
"verifyToken": verify_token,
|
|
110
|
+
"newPassword": new_password,
|
|
111
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Base HTTP client"""
|
|
2
|
+
import requests
|
|
3
|
+
from typing import Optional, Dict, Any, Union
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MoonError(Exception):
|
|
7
|
+
"""Moontraze SDK Error"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message: str, status: int = 0, code: Optional[str] = None):
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.message = message
|
|
12
|
+
self.status = status
|
|
13
|
+
self.code = code
|
|
14
|
+
|
|
15
|
+
def __repr__(self):
|
|
16
|
+
return f"MoonError(status={self.status}, code={self.code}, message={self.message})"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MoonConfig:
|
|
20
|
+
"""Moontraze SDK configuration"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
project_id: str,
|
|
25
|
+
api_key: str,
|
|
26
|
+
base_url: str = "https://api.moontraze.com",
|
|
27
|
+
token: Optional[str] = None,
|
|
28
|
+
timeout: int = 60,
|
|
29
|
+
):
|
|
30
|
+
self.project_id = project_id
|
|
31
|
+
self.api_key = api_key
|
|
32
|
+
self.base_url = base_url
|
|
33
|
+
self.token = token
|
|
34
|
+
self.timeout = timeout
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class MoonClient:
|
|
38
|
+
"""Base client for Moontraze SDK"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, config: MoonConfig):
|
|
41
|
+
self.config = config
|
|
42
|
+
self.token = config.token
|
|
43
|
+
self.session = requests.Session()
|
|
44
|
+
|
|
45
|
+
def set_token(self, token: Optional[str]):
|
|
46
|
+
"""Set auth token"""
|
|
47
|
+
self.token = token
|
|
48
|
+
|
|
49
|
+
def get_token(self) -> Optional[str]:
|
|
50
|
+
"""Get current token"""
|
|
51
|
+
return self.token
|
|
52
|
+
|
|
53
|
+
def _headers(self, extra: Optional[Dict[str, str]] = None) -> Dict[str, str]:
|
|
54
|
+
"""Build request headers"""
|
|
55
|
+
headers = {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
"X-Project-Id": self.config.project_id,
|
|
58
|
+
"X-API-Key": self.config.api_key,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if self.token:
|
|
62
|
+
headers["Authorization"] = f"Bearer {self.token}"
|
|
63
|
+
|
|
64
|
+
if extra:
|
|
65
|
+
headers.update(extra)
|
|
66
|
+
|
|
67
|
+
return headers
|
|
68
|
+
|
|
69
|
+
def request(
|
|
70
|
+
self,
|
|
71
|
+
method: str,
|
|
72
|
+
path: str,
|
|
73
|
+
body: Optional[Any] = None,
|
|
74
|
+
params: Optional[Dict[str, Any]] = None,
|
|
75
|
+
files: Optional[Dict] = None,
|
|
76
|
+
data: Optional[Dict] = None,
|
|
77
|
+
) -> Any:
|
|
78
|
+
"""Make HTTP request"""
|
|
79
|
+
url = f"{self.config.base_url}{path}"
|
|
80
|
+
|
|
81
|
+
headers = self._headers()
|
|
82
|
+
if files:
|
|
83
|
+
# Remove Content-Type for multipart (requests handles it)
|
|
84
|
+
headers.pop("Content-Type", None)
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
response = self.session.request(
|
|
88
|
+
method=method,
|
|
89
|
+
url=url,
|
|
90
|
+
json=body if not (files or data) else None,
|
|
91
|
+
data=data,
|
|
92
|
+
files=files,
|
|
93
|
+
params=params,
|
|
94
|
+
headers=headers,
|
|
95
|
+
timeout=self.config.timeout,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
data_resp = response.json()
|
|
99
|
+
|
|
100
|
+
if not response.ok:
|
|
101
|
+
raise MoonError(
|
|
102
|
+
data_resp.get("error", "Request failed"),
|
|
103
|
+
response.status_code,
|
|
104
|
+
data_resp.get("code"),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
return data_resp
|
|
108
|
+
|
|
109
|
+
except requests.exceptions.Timeout:
|
|
110
|
+
raise MoonError("Request timeout", 408, "TIMEOUT")
|
|
111
|
+
except requests.exceptions.ConnectionError:
|
|
112
|
+
raise MoonError("Connection error", 0, "CONNECTION_ERROR")
|
|
113
|
+
except requests.exceptions.RequestException as e:
|
|
114
|
+
raise MoonError(f"Request failed: {str(e)}", 0, "REQUEST_ERROR")
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Database module"""
|
|
2
|
+
from typing import Optional, Dict, Any, List
|
|
3
|
+
from .client import MoonClient, MoonConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MoonDatabase(MoonClient):
|
|
7
|
+
"""Database operations"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, config: MoonConfig):
|
|
10
|
+
super().__init__(config)
|
|
11
|
+
|
|
12
|
+
def get(self, path: str) -> Dict[str, Any]:
|
|
13
|
+
"""Get document(s) at path"""
|
|
14
|
+
return self.request("GET", "/api/db", params={"collection": path})
|
|
15
|
+
|
|
16
|
+
def get_field(self, path: str, field: str) -> Any:
|
|
17
|
+
"""Get specific field"""
|
|
18
|
+
return self.request("GET", "/api/db", params={
|
|
19
|
+
"collection": f"{path}/{field}",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
def set(self, path: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
|
23
|
+
"""Create or update document"""
|
|
24
|
+
return self.request("POST", "/api/db", {
|
|
25
|
+
"collection": path,
|
|
26
|
+
"data": data,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
def update_field(
|
|
30
|
+
self,
|
|
31
|
+
path: str,
|
|
32
|
+
field: str,
|
|
33
|
+
value: Any,
|
|
34
|
+
type: str = "string",
|
|
35
|
+
) -> Dict[str, Any]:
|
|
36
|
+
"""Update single field"""
|
|
37
|
+
return self.request("PUT", "/api/db",
|
|
38
|
+
body={
|
|
39
|
+
"oldKey": field,
|
|
40
|
+
"newKey": field,
|
|
41
|
+
"value": value,
|
|
42
|
+
"type": type,
|
|
43
|
+
},
|
|
44
|
+
params={"collection": path},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def update_fields(
|
|
48
|
+
self,
|
|
49
|
+
path: str,
|
|
50
|
+
fields: Dict[str, Dict[str, Any]],
|
|
51
|
+
) -> None:
|
|
52
|
+
"""Update multiple fields"""
|
|
53
|
+
for field, config in fields.items():
|
|
54
|
+
self.update_field(
|
|
55
|
+
path,
|
|
56
|
+
field,
|
|
57
|
+
config["value"],
|
|
58
|
+
config.get("type", "string"),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def delete(self, path: str) -> Dict[str, Any]:
|
|
62
|
+
"""Delete document"""
|
|
63
|
+
return self.request("DELETE", "/api/db", params={"collection": path})
|
|
64
|
+
|
|
65
|
+
def delete_field(self, path: str, field: str) -> Dict[str, Any]:
|
|
66
|
+
"""Delete field"""
|
|
67
|
+
return self.request("DELETE", "/api/db", params={
|
|
68
|
+
"collection": path,
|
|
69
|
+
"field": field,
|
|
70
|
+
})
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Notifications module"""
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional, Dict, Any, List
|
|
4
|
+
from .client import MoonClient, MoonConfig
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MoonNotifications(MoonClient):
|
|
8
|
+
"""Push notifications"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, config: MoonConfig):
|
|
11
|
+
super().__init__(config)
|
|
12
|
+
|
|
13
|
+
def register_token(
|
|
14
|
+
self,
|
|
15
|
+
token: str,
|
|
16
|
+
device_info: Optional[Dict[str, Any]] = None,
|
|
17
|
+
) -> Dict[str, Any]:
|
|
18
|
+
"""Register FCM device token"""
|
|
19
|
+
return self.request("POST", "/api/notifications/register", {
|
|
20
|
+
"token": token,
|
|
21
|
+
"deviceInfo": device_info or {},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
def unregister_token(self, token: str) -> Dict[str, Any]:
|
|
25
|
+
"""Unregister FCM token"""
|
|
26
|
+
return self.request("POST", "/api/notifications/unregister", {
|
|
27
|
+
"token": token,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
def send_to_project(
|
|
31
|
+
self,
|
|
32
|
+
project_id: str,
|
|
33
|
+
title: str,
|
|
34
|
+
body: str,
|
|
35
|
+
data: Optional[Dict[str, Any]] = None,
|
|
36
|
+
) -> Dict[str, Any]:
|
|
37
|
+
"""Send notification to all project users (owner only)"""
|
|
38
|
+
return self.request(
|
|
39
|
+
"POST",
|
|
40
|
+
f"/api/notifications/send-to-project/{project_id}",
|
|
41
|
+
{
|
|
42
|
+
"title": title,
|
|
43
|
+
"body": body,
|
|
44
|
+
"data": data or {},
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def send_to_user(
|
|
49
|
+
self,
|
|
50
|
+
user_id: str,
|
|
51
|
+
title: str,
|
|
52
|
+
body: str,
|
|
53
|
+
data: Optional[Dict[str, Any]] = None,
|
|
54
|
+
) -> Dict[str, Any]:
|
|
55
|
+
"""Send notification to specific user"""
|
|
56
|
+
return self.request(
|
|
57
|
+
"POST",
|
|
58
|
+
f"/api/notifications/send-to-user/{user_id}",
|
|
59
|
+
{
|
|
60
|
+
"title": title,
|
|
61
|
+
"body": body,
|
|
62
|
+
"data": data or {},
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def send_to_topic(
|
|
67
|
+
self,
|
|
68
|
+
topic: str,
|
|
69
|
+
title: str,
|
|
70
|
+
body: str,
|
|
71
|
+
data: Optional[Dict[str, Any]] = None,
|
|
72
|
+
) -> Dict[str, Any]:
|
|
73
|
+
"""Send notification to topic"""
|
|
74
|
+
return self.request("POST", "/api/notifications/send-to-topic", {
|
|
75
|
+
"topic": topic,
|
|
76
|
+
"title": title,
|
|
77
|
+
"body": body,
|
|
78
|
+
"data": data or {},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
def schedule(
|
|
82
|
+
self,
|
|
83
|
+
title: str,
|
|
84
|
+
body: str,
|
|
85
|
+
send_at: datetime,
|
|
86
|
+
data: Optional[Dict[str, Any]] = None,
|
|
87
|
+
) -> Dict[str, Any]:
|
|
88
|
+
"""Schedule notification"""
|
|
89
|
+
return self.request("POST", "/api/notifications/schedule", {
|
|
90
|
+
"title": title,
|
|
91
|
+
"body": body,
|
|
92
|
+
"sendAt": send_at.isoformat(),
|
|
93
|
+
"data": data or {},
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
def get_history(self, limit: int = 50) -> List[Dict[str, Any]]:
|
|
97
|
+
"""Get notification history"""
|
|
98
|
+
data = self.request(
|
|
99
|
+
"GET",
|
|
100
|
+
"/api/notifications/history",
|
|
101
|
+
params={"limit": limit},
|
|
102
|
+
)
|
|
103
|
+
return data.get("notifications", [])
|
|
104
|
+
|
|
105
|
+
def get_preferences(self) -> Dict[str, Any]:
|
|
106
|
+
"""Get notification preferences"""
|
|
107
|
+
return self.request("GET", "/api/notifications/preferences")
|
|
108
|
+
|
|
109
|
+
def update_preferences(self, **kwargs) -> Dict[str, Any]:
|
|
110
|
+
"""Update notification preferences"""
|
|
111
|
+
return self.request("PUT", "/api/notifications/preferences", kwargs)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Storage module"""
|
|
2
|
+
import os
|
|
3
|
+
from typing import Optional, Dict, Any, List, IO
|
|
4
|
+
from .client import MoonClient, MoonConfig
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MoonStorage(MoonClient):
|
|
8
|
+
"""Storage operations"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, config: MoonConfig):
|
|
11
|
+
super().__init__(config)
|
|
12
|
+
|
|
13
|
+
def upload(
|
|
14
|
+
self,
|
|
15
|
+
file: IO,
|
|
16
|
+
filename: str,
|
|
17
|
+
folder_id: Optional[str] = None,
|
|
18
|
+
content_type: str = "application/octet-stream",
|
|
19
|
+
) -> Dict[str, Any]:
|
|
20
|
+
"""Upload a file"""
|
|
21
|
+
url = f"/api/storage/{self.config.project_id}/upload"
|
|
22
|
+
|
|
23
|
+
files = {"file": (filename, file, content_type)}
|
|
24
|
+
data = {}
|
|
25
|
+
if folder_id:
|
|
26
|
+
data["folderId"] = folder_id
|
|
27
|
+
|
|
28
|
+
return self.request("POST", url, files=files, data=data)
|
|
29
|
+
|
|
30
|
+
def upload_from_path(
|
|
31
|
+
self,
|
|
32
|
+
file_path: str,
|
|
33
|
+
folder_id: Optional[str] = None,
|
|
34
|
+
) -> Dict[str, Any]:
|
|
35
|
+
"""Upload file from path"""
|
|
36
|
+
filename = os.path.basename(file_path)
|
|
37
|
+
|
|
38
|
+
with open(file_path, "rb") as f:
|
|
39
|
+
return self.upload(f, filename, folder_id)
|
|
40
|
+
|
|
41
|
+
def list(self, folder_id: Optional[str] = None) -> List[Dict[str, Any]]:
|
|
42
|
+
"""List files"""
|
|
43
|
+
params = {}
|
|
44
|
+
if folder_id:
|
|
45
|
+
params["folderId"] = folder_id
|
|
46
|
+
|
|
47
|
+
data = self.request(
|
|
48
|
+
"GET",
|
|
49
|
+
f"/api/storage/{self.config.project_id}/files",
|
|
50
|
+
params=params,
|
|
51
|
+
)
|
|
52
|
+
return data.get("files", [])
|
|
53
|
+
|
|
54
|
+
def delete(self, file_id: str) -> Dict[str, Any]:
|
|
55
|
+
"""Delete file"""
|
|
56
|
+
return self.request(
|
|
57
|
+
"DELETE",
|
|
58
|
+
f"/api/storage/{self.config.project_id}/files/{file_id}",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def create_folder(
|
|
62
|
+
self,
|
|
63
|
+
name: str,
|
|
64
|
+
parent_id: Optional[str] = None,
|
|
65
|
+
) -> Dict[str, Any]:
|
|
66
|
+
"""Create folder"""
|
|
67
|
+
return self.request(
|
|
68
|
+
"POST",
|
|
69
|
+
f"/api/storage/{self.config.project_id}/folders",
|
|
70
|
+
{"name": name, "parentId": parent_id},
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def list_folders(self, parent_id: Optional[str] = None) -> List[Dict[str, Any]]:
|
|
74
|
+
"""List folders"""
|
|
75
|
+
params = {}
|
|
76
|
+
if parent_id:
|
|
77
|
+
params["parentId"] = parent_id
|
|
78
|
+
|
|
79
|
+
data = self.request(
|
|
80
|
+
"GET",
|
|
81
|
+
f"/api/storage/{self.config.project_id}/folders",
|
|
82
|
+
params=params,
|
|
83
|
+
)
|
|
84
|
+
return data.get("folders", [])
|
|
85
|
+
|
|
86
|
+
def delete_folder(self, folder_id: str) -> Dict[str, Any]:
|
|
87
|
+
"""Delete folder (recursive)"""
|
|
88
|
+
return self.request(
|
|
89
|
+
"DELETE",
|
|
90
|
+
f"/api/storage/{self.config.project_id}/folders/{folder_id}",
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def get_presigned_url(
|
|
94
|
+
self,
|
|
95
|
+
file_id: str,
|
|
96
|
+
download: bool = True,
|
|
97
|
+
) -> Dict[str, Any]:
|
|
98
|
+
"""Get presigned download URL"""
|
|
99
|
+
params = {"download": "true"} if download else {}
|
|
100
|
+
return self.request(
|
|
101
|
+
"GET",
|
|
102
|
+
f"/api/storage/{self.config.project_id}/files/{file_id}/presign",
|
|
103
|
+
params=params,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def get_download_url(self, file_id: str) -> str:
|
|
107
|
+
"""Get direct download URL"""
|
|
108
|
+
result = self.get_presigned_url(file_id, True)
|
|
109
|
+
return result["url"]
|
|
110
|
+
|
|
111
|
+
def download(self, file_id: str, save_path: str) -> str:
|
|
112
|
+
"""Download file from presigned URL"""
|
|
113
|
+
import requests
|
|
114
|
+
|
|
115
|
+
url = self.get_download_url(file_id)
|
|
116
|
+
response = requests.get(url, stream=True)
|
|
117
|
+
response.raise_for_status()
|
|
118
|
+
|
|
119
|
+
with open(save_path, "wb") as f:
|
|
120
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
121
|
+
f.write(chunk)
|
|
122
|
+
|
|
123
|
+
return save_path
|
|
124
|
+
|
|
125
|
+
def get_quota(self) -> Dict[str, Any]:
|
|
126
|
+
"""Get storage quota"""
|
|
127
|
+
return self.request(
|
|
128
|
+
"GET",
|
|
129
|
+
f"/api/storage/{self.config.project_id}/quota",
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def get_size(self) -> Dict[str, Any]:
|
|
133
|
+
"""Get storage size"""
|
|
134
|
+
return self.request(
|
|
135
|
+
"GET",
|
|
136
|
+
f"/api/storage/{self.config.project_id}/size",
|
|
137
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moontraze
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Moontraze SDK — Auth, Database, Storage, Notifications
|
|
5
|
+
Author-email: Moontraze <faisalrizwan0077@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://moontraze.com
|
|
8
|
+
Project-URL: Repository, https://github.com/moontraze/sdk-python
|
|
9
|
+
Project-URL: Documentation, https://docs.moontraze.com
|
|
10
|
+
Keywords: moontraze,backend,auth,database,storage,notifications,sdk
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: requests>=2.28.0
|
|
23
|
+
Requires-Dist: urllib3>=1.26.0
|
|
24
|
+
Provides-Extra: async
|
|
25
|
+
Requires-Dist: aiohttp>=3.8.0; extra == "async"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# moontraze
|
|
29
|
+
|
|
30
|
+
Official Moontraze Python SDK — Auth, Database, Storage, and Push Notifications.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install moontraze
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
moontraze/__init__.py
|
|
5
|
+
moontraze/auth.py
|
|
6
|
+
moontraze/client.py
|
|
7
|
+
moontraze/database.py
|
|
8
|
+
moontraze/notifications.py
|
|
9
|
+
moontraze/storage.py
|
|
10
|
+
moontraze.egg-info/PKG-INFO
|
|
11
|
+
moontraze.egg-info/SOURCES.txt
|
|
12
|
+
moontraze.egg-info/dependency_links.txt
|
|
13
|
+
moontraze.egg-info/requires.txt
|
|
14
|
+
moontraze.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
moontraze
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "moontraze"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Official Moontraze SDK — Auth, Database, Storage, Notifications"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT" # ← Simple string (SPDX)
|
|
12
|
+
license-files = ["LICENSE"] # ← License file include karo
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Moontraze", email = "faisalrizwan0077@gmail.com" }
|
|
15
|
+
]
|
|
16
|
+
keywords = ["moontraze", "backend", "auth", "database", "storage", "notifications", "sdk"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.8",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
# "License :: OSI Approved :: MIT License", ← HATA DIYA
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
dependencies = [
|
|
30
|
+
"requests>=2.28.0",
|
|
31
|
+
"urllib3>=1.26.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
async = ["aiohttp>=3.8.0"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://moontraze.com"
|
|
39
|
+
Repository = "https://github.com/moontraze/sdk-python"
|
|
40
|
+
Documentation = "https://docs.moontraze.com"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["."]
|
|
44
|
+
include = ["moontraze*"]
|