Resetting utils subtree.

This commit is contained in:
2024-12-05 14:47:16 +05:30
parent 6e6e6be87c
commit 75b4bf541b
151 changed files with 139 additions and 125374 deletions
+9 -6
View File
@@ -101,6 +101,7 @@ class MailOAuthModel(BaseModel):
mongo_conn: AsyncMongo,
user_info: dict,
client_user_id: dict,
auth: dict,
service_client: Literal["gmail"],
auth_type: Literal["oauth"],
sync_freq: Literal[60, 300, 900] = 300,
@@ -114,6 +115,7 @@ class MailOAuthModel(BaseModel):
:param mongo_conn: The database connection (MongoDB) to use to perform the action.
:param user_info: The dictionary that has the user's session information.
:param client_user_id: The way the third-party client recognizes your user.
:param auth: The authentication details of the account.
:param service_client: The name of the company or brand that is providing this service that is being integrated.
:param auth_type: To identify the type of authentication being done here. This could indicate simple password
authentication, more advance OAuth2.0 authentication, etc.
@@ -149,6 +151,7 @@ class MailOAuthModel(BaseModel):
"authType": auth_type,
"user": user_info,
"clientUserId": client_user_id,
"auth": auth,
"token": None,
"firstRefreshTs": None,
"lastRefreshTs": None,
@@ -171,8 +174,8 @@ class MailOAuthModel(BaseModel):
proc_args = (
user_info["entityId"], # ............................................ 'p_entity_id'
service_client, # ................................................... 'p_provider'
"Auth Requested", # ................................................. 'p_current_status'
"Auth URL Generated", # ............................................. 'p_last_action'
"Pending", # ........................................................ 'p_current_status'
"Auth Requested", # ................................................. 'p_last_action'
None, # ............................................................. 'p_display_name'
None, # ............................................................. 'p_display_picture'
str(mongo_json["_id"]), # ........................................... 'p_token_id'
@@ -250,8 +253,8 @@ class MailOAuthModel(BaseModel):
if mongo_json is not None:
token_notes = {
"email": token["email"],
"displayName": token["displayName"],
"displayPictureUrl": token["displayPictureUrl"],
"displayName": token.get("displayName"),
"displayPictureUrl": token.get("displayPictureUrl"),
}
db_json = await self.call_procedure(
db_conn = db_conn,
@@ -259,8 +262,8 @@ class MailOAuthModel(BaseModel):
proc_args = (
mongo_json["user"]["entityId"], # ............................... 'p_entity_id'
mongo_json["client"], # ......................................... 'p_provider'
"Auth Granted", # ............................................... 'p_current_status'
"Set Token", # .................................................. 'p_last_action'
"Active", # ..................................................... 'p_current_status'
"Auth Granted", # ............................................... 'p_last_action'
token["displayName"], # ......................................... 'p_display_name'
token["displayPictureUrl"], # ................................... 'p_display_picture'
token_id, # ..................................................... 'p_token_id'
+5 -4
View File
@@ -124,9 +124,7 @@ class MailRetrieveModel(BaseModel):
"payload.bcc": True,
"payload.parts": True,
"payload.attachments": True,
"payload.labels": True,
"payload.snippet": True,
"payload.aiSnippet": True,
"payload.labels": True
}
)
@@ -185,7 +183,10 @@ class MailRetrieveModel(BaseModel):
mail_data["payload"]["ts"] = mail_data["payload"]["ts"].isoformat()
mail_data["payload"]["readTs"] = mail_data["payload"]["readTs"].isoformat()
if ai_snippet := mail_data["payload"].pop("aiSnippet"):
mail_data["payload"]["aiSnippet"] = ai_snippet["snippet"]
mail_data["payload"]["aiSnippet"] = {
"snippet": ai_snippet["snippet"],
"usage": ai_snippet["usage"]
}
# Done here:
return mails_list
+6 -1
View File
@@ -331,7 +331,12 @@ class MailSyncModel(BaseModel):
)
llm_json = {
"snippet": llm_response.content,
"usage": llm_response.usage_metadata
"usage": {
"input": llm_response.usage_metadata["input_tokens"],
"output": llm_response.usage_metadata["output_tokens"],
"total": llm_response.usage_metadata["total_tokens"],
},
"rawUsage": llm_response.usage_metadata
}
client_response.data["aiSnippet"] = llm_json
+26 -22
View File
@@ -94,25 +94,28 @@ class SMSAuthModel(BaseModel):
AUTH_COLLECTION = "_authTokens"
async def set_token(
async def set(
self,
db_conn: AsyncMySQL,
mongo_conn: AsyncMongo,
user_info: dict,
client_user_id: dict,
auth: dict,
token: dict,
service_client: Literal["nimbusSmsIndia", "savvyBulkSmsKenya"],
auth_type: Literal["auth"],
sync_freq: Literal[60, 300, 900] = 300,
session_token: str = None
) -> ObjectId:
) -> ObjectId | None:
"""
Stores params from the session info and gives an identifier to use in the authorization URL. Use this when the
user requests an authorization URL to link your service to another service (like GMail).
To store auth/tokens for a particular service to the database.
:param db_conn: The database connection (MariaDB) to use to perform the action.
:param mongo_conn: The database connection (MongoDB) to use to perform the action.
:param user_info: The dictionary that has the user's session information.
:param client_user_id: The way the third-party client recognizes your user.
:param auth: The authentication details of the account.
:param token: The token granted by the third-party service.
:param service_client: The name of the company or brand that is providing this service that is being integrated.
:param auth_type: To identify the type of authentication being done here. This could indicate simple password
authentication, more advance OAuth2.0 authentication, etc.
@@ -137,21 +140,22 @@ class SMSAuthModel(BaseModel):
}),
update = {
"$set": {
"lastRequestTs": request_ts
"lastRequestTs": request_ts,
"status": "active",
"syncFreq": max(sync_freq, 60)
},
"$setOnInsert": {
"version": "1.1.1",
"serviceType": "email",
"version": "1.0.0",
"serviceType": "sms",
"client": service_client,
"authType": auth_type,
"user": user_info,
"clientUserId": client_user_id,
"token": None,
"auth": auth,
"token": token,
"firstRefreshTs": None,
"lastRefreshTs": None,
"firstRequestTs": request_ts,
"status": "active",
"syncFreq": max(sync_freq, 60)
"firstRequestTs": request_ts
}
},
projection = {
@@ -168,15 +172,15 @@ class SMSAuthModel(BaseModel):
db_conn = db_conn,
proc_name = "entity_integration_save",
proc_args = (
user_info["entityId"], # ............................................ 'p_entity_id'
service_client, # ................................................... 'p_provider'
"Auth Requested", # ................................................. 'p_current_status'
"Auth URL Generated", # ............................................. 'p_last_action'
None, # ............................................................. 'p_display_name'
None, # ............................................................. 'p_display_picture'
str(mongo_json["_id"]), # ........................................... 'p_token_id'
json.to_string(python_data = {"email": None}, no_space = True), # ... 'p_notes'
user_info["userId"] # ............................................... 'p_created_by'
user_info["entityId"], # ........................................... 'p_entity_id'
service_client, # .................................................. 'p_provider'
"Active", # ........................................................ 'p_current_status'
"Auth Details Accepted", # ......................................... 'p_last_action'
None, # ............................................................ 'p_display_name'
None, # ............................................................ 'p_display_picture'
str(mongo_json["_id"]), # .......................................... 'p_token_id'
json.to_string(python_data = client_user_id, no_space = True), # ... 'p_notes'
user_info["userId"] # .............................................. 'p_created_by'
),
session_token = session_token
)
@@ -184,7 +188,7 @@ class SMSAuthModel(BaseModel):
# Done here:
return mongo_json["_id"] if mongo_json and db_json.get("status") == 1 else None
async def get_token(
async def get(
self,
mongo_conn: AsyncMongo,
token_id: ObjectId | str = None,
@@ -192,7 +196,7 @@ class SMSAuthModel(BaseModel):
) -> dict | None:
"""
To retrieve stored tokens from the database.
To retrieve stored auth/tokens from the database.
:param mongo_conn: The database connection (MongoDB) to use to perform the action.
:param token_id: The identifier granted providing auth details for the first time in 'set_token'.
:param kwargs: Any set of key-value pairs to build custom search criteria. This could be things like the user
+9 -1
View File
@@ -79,22 +79,26 @@ class NimbusSMSIndiaAuth(BaseModel):
entityId: str = Field(
description = "the entity id as registered with DLT",
min_length = 1,
frozen = True
)
senderId: str = Field(
description = "the 6-char code that you see in your SMS inbox",
min_length = 1,
frozen = True,
examples = ["HDFCBK", "NSESMS", "ZRODHA"]
)
userId: str = Field(
description = "the 6-digit id that Nimbus has assigned to you",
min_length = 1,
frozen = True
)
apiKey: str = Field(
description = "the key generated through Nimbus's portal",
min_length = 1,
frozen = True
)
@@ -114,16 +118,19 @@ class SavvyBulkSMSKenyaAuth(BaseModel):
apiKey: str = Field(
description = "the key generated through Savvy's portal",
min_length = 1,
frozen = True
)
partnerId: str = Field(
description = "the key generated through Savvy's portal",
min_length = 1,
frozen = True
)
shortCode: str = Field(
description = "your short code with Savvy",
min_length = 1,
frozen = True
)
@@ -165,7 +172,8 @@ class SMSAuthRequestHeaders(BaseModel):
class SMSAuthRequestData(BaseModel):
client: Union[NimbusSMSIndiaAuth, SavvyBulkSMSKenyaAuth]
messageClient: Literal["nimbusSmsIndia", "savvyBulkSmsKenya"]
auth: Union[NimbusSMSIndiaAuth, SavvyBulkSMSKenyaAuth]
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓