(20250625) - Implemented the ecommerce shopify auth integration.

with multiple files added new API for get token details
This commit is contained in:
yatmesh
2025-06-25 14:06:02 +05:30
parent 388b9bdd1b
commit c022844824
14 changed files with 1029 additions and 7 deletions
+141
View File
@@ -0,0 +1,141 @@
"""
AUTHOR:
Omkar Khandare
DATE:
Wednesday, 25th June., 2025.
OBJECTIVE:
To provide a structure to allow users to disable their third-party integration accounts.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from typing import Optional, Literal, List, Any
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
# To work with MongoDB:
from bson.objectid import ObjectId
# To work with date and time:
import datetime
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# RegEx Patterns:
REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class AuthTokenGetRequestHeaders(BaseModel):
sessionToken: str = Field(
description = "The session token of the user who is requesting the service.",
pattern = REGEX_SESSION_TOKEN,
frozen = True,
alias = "X-Session-Token"
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "allow"
def model_dump(self, *args, **kwargs):
return super().model_dump(*args, by_alias = True, **kwargs)
# ---------------------------------------------------------------------------------------------------------------------
class AuthTokenGetRequestData(BaseModel):
tokenKey: ObjectId = Field(
description = "The token identifier that tell you which account needs to be disabled.",
frozen = True,
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
arbitrary_types_allowed = True
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@field_validator("tokenKey", mode = "before")
def parse_oid(cls, value):
try: value = ObjectId(value)
except: value = None
return value
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+5 -4
View File
@@ -42,7 +42,7 @@ from typing import Optional, Literal, Union
# Other data models:
from models.software.tcaoff_ai.auth import TheCAOfficeAIAuth
from models.software.mikrotik.auth import MikroTikPPPoE1000Auth, MikroTikHotspot1000Auth
from models.software.ecommerce.auth import ShopifyAuth
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
@@ -105,8 +105,8 @@ class SoftwareAuthRequestHeaders(BaseModel):
class SoftwareAuthRequestData(BaseModel):
softwareClient: Literal["theCaOfficeAi", "mikrotikPPPoE1000", "mikrotikHotspot1000"] = Field(alias = "client")
auth: Union[TheCAOfficeAIAuth, MikroTikPPPoE1000Auth, MikroTikHotspot1000Auth]
softwareClient: Literal["theCaOfficeAi", "mikrotikPPPoE1000", "mikrotikHotspot1000", "shopify"] = Field(alias = "client")
auth: Union[TheCAOfficeAIAuth, MikroTikPPPoE1000Auth, MikroTikHotspot1000Auth, ShopifyAuth]
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
@@ -127,7 +127,8 @@ class SoftwareAuthRequestData(BaseModel):
harmony_map = {
"theCaOfficeAi": TheCAOfficeAIAuth,
"mikrotikPPPoE1000": MikroTikPPPoE1000Auth,
"mikrotikHotspot1000": MikroTikHotspot1000Auth
"mikrotikHotspot1000": MikroTikHotspot1000Auth,
"shopify": ShopifyAuth
}
if not isinstance(auth, harmony_map[client]):
raise ValueError(f"incorrect 'auth' for selected client '{client}'")
+14 -1
View File
@@ -99,6 +99,7 @@ class CoreAuthTokenModel(BaseModel):
"email", "sms", "chat", # ............. Message
"paymentGateway", "stockTrading", # ... Finstitutions
"software", # ......................... God knows
"ecommerce", # ......................... God knows
] = Field(
description = "the kind of service this message was sent/received from",
frozen = True
@@ -110,7 +111,8 @@ class CoreAuthTokenModel(BaseModel):
"nimbusSmsIndia", "savvyBulkSmsKenya", # ........................ SMS Clients
"razorpay", "safaricomMPesaExpress", # .......................... Payment Gateways
"zerodhaKite", "iciciBreeze", "paperTrading", # ................. Stock Brokers
"theCaOfficeAi", "mikrotikPPPoE1000", "mikrotikHotspot1000" # ... Software
"theCaOfficeAi", "mikrotikPPPoE1000", "mikrotikHotspot1000", # ... Software
"shopify"
] = Field(
description = "the third-part client that was used",
frozen = True
@@ -245,6 +247,17 @@ class CoreAuthTokenModel(BaseModel):
if value is None: value = {}
return value
# ┏┓ ┏┓
# ┃ ┓┏┏╋┏┓┏┳┓ ┣ ┓┏┏┓┏┏
# ┗┛┗┻┛┗┗┛┛┗┗ ┻ ┗┻┛┗┗┛
def to_json(self) -> dict:
dump = self.model_dump()
print(dump)
for key in ["batchId", "key", "_id"]:
dump[key] = str(dump[key])
return dump
# *****************************************************************************************************************
# ***** ****
+163
View File
@@ -0,0 +1,163 @@
"""
AUTHOR:
Omkar Khandare
DATE:
Tuesday, 24th Jun., 2025.
OBJECTIVE:
To provide a structure to receive auth details for ecommerce
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime, model_validator
from typing import Optional, Literal, Union, Any, List
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# RegEx Patterns:
REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
# Not Yet --
# *****************************************************************************************************************
# ***** ****
# *** CLASSES ***
# ***** ****
# *****************************************************************************************************************
class ShopifyAuth(BaseModel):
storeName: str = Field(
description = "Shopify store name or brand name",
frozen = True
)
storeUrl: str = Field(
description = "Shopify store URL",
frozen = True
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# ---------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------
class ShopifyAuthResponse(BaseModel):
success: bool = Field(
description = "To indicate whether or not, the action was a success",
frozen = False,
default = False
)
token_id : str = Field(
description="MongoDb object id",
frozen=False,
default=False
)
message: str = Field(
description = "To explain what happened in the process of handling the OAuth callback.",
frozen = False,
default = "ERR: Message not captured."
)
exception: Any = Field(
description = "To pass on any exception that occurred in the process.",
frozen = False,
default = None
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# ┏┓ ┏┓
# ┃ ┓┏┏╋┏┓┏┳┓ ┣ ┓┏┏┓┏┏
# ┗┛┗┻┛┗┗┛┛┗┗ ┻ ┗┻┛┗┗┛
pass
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
pass
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass