
    b?i0                         S SK r S SKrS SKrS SKJr  S SKJrJrJrJ	r	J
r
  S SKJrJr  S SKJr  S SKJr  S SKJrJrJrJr  Sr " S	 S
5      rg)    N)sha256)AnyDictListOptionalcast)NotRequired	TypedDict)request)PaginationHelper)VerifyWebhookOptionsWebhookWebhookEventWebhookStatusi,  c                      \ rS rSr " S S\5      r " S S\5      r " S S\5      r " S S	\5      r " S
 S\5      r	 " S S\5      r
 " S S\5      r\S\S\4S j5       r\S\S\4S j5       r\S\	S\
4S j5       r\SS\\   S\4S jj5       r\S\S\4S j5       r\S\SS4S j5       r\S\S\S\4S j5       rSrg) Webhooks   c                   J    \ rS rSr% \\   \S'    \\   \S'    \\   \S'   Srg)Webhooks.ListParams   limitafterbefore N)	__name__
__module____qualname____firstlineno__r	   int__annotations__str__static_attributes__r       ]/var/www/html/livechat/backend/venv/lib/python3.13/site-packages/resend/webhooks/_webhooks.py
ListParamsr      s6    3	 3	
 C  	r#   r%   c                   B    \ rS rSr% Sr\\S'    \\   \S'    \	\S'   Sr
g)Webhooks.ListResponse&   a  
ListResponse type that wraps a list of webhook objects with pagination metadata

Attributes:
    object (str): The object type, always "list"
    data (List[Webhook]): A list of webhook objects
    has_more (bool): Whether there are more results available
objectdatahas_morer   N)r   r   r   r   __doc__r!   r    r   r   boolr"   r   r#   r$   ListResponser'   &   s0    	 	 7m	 	r#   r.   c                   <    \ rS rSr% Sr\\S'    \\S'    \\S'   Srg)Webhooks.CreateWebhookResponse=   a  
CreateWebhookResponse is the type that wraps the response of the webhook that was created

Attributes:
    object (str): The object type, always "webhook"
    id (str): The ID of the created webhook
    signing_secret (str): The signing secret for webhook verification
r)   idsigning_secretr   Nr   r   r   r   r,   r!   r    r"   r   r#   r$   CreateWebhookResponser0   =   s,    	 	 	 	r#   r5   c                   2    \ rS rSr% \\S'    \\   \S'   Srg)Webhooks.CreateParamsT   endpointeventsr   N)	r   r   r   r   r!   r    r   r   r"   r   r#   r$   CreateParamsr7   T   s    	 \""	r#   r;   c                   \    \ rS rSr% \\S'    \\   \S'    \\\      \S'    \\	   \S'   Sr
g)Webhooks.UpdateParams_   
webhook_idr9   r:   statusr   N)r   r   r   r   r!   r    r	   r   r   r   r"   r   r#   r$   UpdateParamsr=   _   sG    	 c""	 D.//	 M**	r#   rA   c                   0    \ rS rSr% Sr\\S'    \\S'   Srg)Webhooks.UpdateWebhookResponseq   z
UpdateWebhookResponse is the type that wraps the response of the webhook that was updated

Attributes:
    object (str): The object type, always "webhook"
    id (str): The ID of the updated webhook
r)   r2   r   Nr4   r   r#   r$   UpdateWebhookResponserC   q   s    	 	 	r#   rE   c                   <    \ rS rSr% Sr\\S'    \\S'    \\S'   Srg)Webhooks.DeleteWebhookResponse   a	  
DeleteWebhookResponse is the type that wraps the response of the webhook that was deleted

Attributes:
    object (str): The object type, always "webhook"
    id (str): The ID of the deleted webhook
    deleted (bool): Whether the webhook was successfully deleted
r)   r2   deletedr   N)	r   r   r   r   r,   r!   r    r-   r"   r   r#   r$   DeleteWebhookResponserG      s+    	 	 	 	r#   rJ   paramsreturnc                     Sn[         R                  [        R                     " U[	        [
        [        [        4   U5      SS9R                  5       nU$ )a  
Create a webhook to receive real-time notifications about email events.
see more: https://resend.com/docs/api-reference/webhooks/create-webhook

Args:
    params (CreateParams): The webhook creation parameters
        - endpoint: The URL where webhook events will be sent
        - events: Array of event types to subscribe to

Returns:
    CreateWebhookResponse: The created webhook response with id and signing_secret
	/webhookspostpathrK   verb)r   Requestr   r5   r   r   r   perform_with_content)clsrK   rQ   resps       r$   createWebhooks.create   sK     x==>d4S>6:



  	 r#   r?   c                 f    SU 3n[         R                  [           " U0 SS9R                  5       nU$ )z
Retrieve a single webhook for the authenticated user.
see more: https://resend.com/docs/api-reference/webhooks/get-webhook

Args:
    webhook_id (str): The webhook ID

Returns:
    Webhook: The webhook object

/webhooks/getrP   )r   rS   r   rT   rU   r?   rQ   rV   s       r$   r[   Webhooks.get   s=     J<(w'bu



  	 r#   c                     US   nSU 3n[         R                  [        R                     " U[	        [
        [        [        4   U5      SS9R                  5       nU$ )a  
Update an existing webhook configuration.
see more: https://resend.com/docs/api-reference/webhooks/update-webhook

Args:
    params (UpdateParams): The webhook update parameters
        - webhook_id: The webhook ID
        - endpoint: (Optional) The URL where webhook events will be sent
        - events: (Optional) Array of event types to subscribe to
        - status: (Optional) The webhook status ("enabled" or "disabled")

Returns:
    UpdateWebhookResponse: The updated webhook response with id
r?   rZ   patchrP   )r   rS   r   rE   r   r   r   rT   )rU   rK   r?   rQ   rV   s        r$   updateWebhooks.update   s\      L)
J<(x==>d4S>6:



  	 r#   Nc                     SnU(       a  [        [        [        [        4   U5      OSn[        R                  " X#5      n[
        R                  [        R                     " U0 SS9R                  5       nU$ )a  
Retrieve a list of webhooks for the authenticated user.
see more: https://resend.com/docs/api-reference/webhooks/list-webhooks

Args:
    params (Optional[ListParams]): Optional pagination parameters
        - limit: Number of webhooks to retrieve (max 100, min 1).
          If not provided, all webhooks will be returned without pagination.
        - after: ID after which to retrieve more webhooks
        - before: ID before which to retrieve more webhooks

Returns:
    ListResponse: A list of webhook objects
rN   Nr[   rP   )
r   r   r   r   build_paginated_pathr   rS   r   r.   rT   )rU   rK   	base_pathquery_paramsrQ   rV   s         r$   listWebhooks.list   sd       	7=tDcNF3444YMx445bu



  	 r#   c                 z    SU 3n[         R                  [        R                     " U0 SS9R	                  5       nU$ )z
Remove an existing webhook.
see more: https://resend.com/docs/api-reference/webhooks/delete-webhook

Args:
    webhook_id (str): The webhook ID

Returns:
    DeleteWebhookResponse: The deleted webhook response
rZ   deleterP   )r   rS   r   rJ   rT   r\   s       r$   removeWebhooks.remove   sC     J<(x==>bx



  	 r#   optionsc                    U(       d  [        S5      eUR                  S5      (       d  [        S5      eUR                  S5      (       d  [        S5      eUR                  S5      nU(       d  [        S5      eUR                  S5      (       d  [        S	5      eUR                  S
5      (       d  [        S5      eUR                  S5      (       d  [        S5      e [        US
   5      n[        [        R                  " 5       5      nXS-
  nU[
        :  d  U[
        * :  a  [        SU S35      eUS    SUS
    SUS    3nUS   nUR                  S5      (       a  USS n [        R                  " U5      n	U R                  XR                  S5      5      n
US   R                  S5      nU HH  nUR                  SS5      n[        U5      S:w  a  M&  US   n[        R                  " X5      (       d  MH    g   [        S5      e! [         [        4 a  n[        SU 35      eSnAff = f! [         a  n[        SU 35      eSnAff = f)a  
Verify validates a webhook payload using HMAC-SHA256 signature verification.
This implements manual verification without external dependencies.
see more: https://docs.svix.com/receiving/verifying-payloads/how-manual

Args:
    options (VerifyWebhookOptions): The webhook verification parameters
        - payload: The raw request body as a string
        - headers: The Svix headers (svix-id, svix-timestamp, svix-signature)
        - webhook_secret: The webhook signing secret (starts with whsec_)

Raises:
    ValueError: If verification fails or required parameters are missing

Returns:
    None: Returns None on successful verification, raises ValueError otherwise
zoptions cannot be Nonepayloadzpayload cannot be emptywebhook_secretzwebhook_secret cannot be emptyheaderszheaders are requiredr2   zsvix-id header is required	timestampz!svix-timestamp header is required	signaturez!svix-signature header is requiredzinvalid timestamp format: Nz2timestamp outside tolerance window: difference of z seconds.whsec_   z!failed to decode webhook secret: utf-8 ,      zno matching signature found)
ValueErrorr[   r   	TypeErrortime!DEFAULT_WEBHOOK_TOLERANCE_SECONDS
startswithbase64	b64decode	Exception_generate_signatureencodesplitlenhmaccompare_digest)rU   rl   rp   rq   enowdiffsigned_contentsecretdecoded_secretexpected_signature
signaturessigpartsreceived_signatures                  r$   verifyWebhooks.verify  sX   ( 566{{9%%677{{+,,=>>++i(344{{4  9::{{;''@AA{{;''@AA	?GK01I $))+44888DTF(S 
 $DM?!GK,@+A79CUBVW )*X&&ABZF	F#--f5N
 !4411':
 [)//4
CIIc1%E5zQ!&q""#5JJ  677[ I& 	?9!=>>	?.  	F@DEE	Fs0   H $H- H*H%%H*-
I
7II
r   contentc                     [         R                  " X[        5      nUR                  5       n[        R
                  " U5      R                  S5      $ )z
Generate an HMAC-SHA256 signature and return it as base64.

Args:
    secret (bytes): The decoded webhook secret
    content (bytes): The content to sign

Returns:
    str: The base64-encoded signature
rv   )r   newr   digestr   	b64encodedecode)r   r   hrr   s       r$   r   Webhooks._generate_signature^  s;     HHVf-HHJ		*11'::r#   r   )N)r   r   r   r   r
   r%   r.   r5   r;   rA   rE   rJ   classmethodrW   r!   r   r[   r`   r   rf   rj   r   r   staticmethodbytesr   r"   r   r#   r$   r   r      sY   Y $y .	 .	y 	y $	 $	 . L -B  & S W  " L -B  . (:. ,  .  (=  " Y81 Y8d Y8 Y8v ;E ;E ;c ; ;r#   r   )r   r   r}   hashlibr   typingr   r   r   r   r   typing_extensionsr	   r
   resendr   resend.pagination_helperr   resend.webhooks._webhookr   r   r   r   r~   r   r   r#   r$   <module>r      s@        2 2 4  5C C %( !Z; Z;r#   