
    g                         d dl mZmZmZmZmZ d dlmZ d dlm	Z	m
Z
 ddlmZmZ ddlmZmZmZmZmZ ddlmZ  G d d	      Zy
)    )AnyDictLiteralOptionalUnion)warn)	HTTPErrorResponse   )FunctionsHttpErrorFunctionsRelayError)AsyncClientFunctionRegionis_http_urlis_valid_jwtis_valid_str_arg)__version__c                       e Zd Z	 	 ddededededee   f
dZ	 	 dde	d	   dedeeeef      d
eee
e
f      def
dZdeddfdZ	 ddedee   deeef   fdZy)AsyncFunctionsClientNurlheaderstimeoutverifyproxyc           
          t        |      st        d       || _        ddt         i|| _        t        | j                  | j                  t        |      t        t        |            |dd      | _	        y )Nz#url must be a valid HTTP URL stringz
User-Agentzsupabase-py/functions-py vT)base_urlr   r   r   r   follow_redirectshttp2)
r   
ValueErrorr   r   r   r   boolintabs_client)selfr   r   r   r   r   s         U/var/www/openai/venv/lib/python3.12/site-packages/supafunc/_async/functions_client.py__init__zAsyncFunctionsClient.__init__   sr     3<=6{mD

 #XXLL<G%!
    method)GETOPTIONSHEADPOSTPUTPATCHDELETEjsonreturnc                 .  K   | j                   j                  ||||       d {   }	 |j                          |S 7 # t        $ rJ}t	        |j                         j                  d      xs d|j                  j                  d      |d }~ww xY ww)N)r0   r   errorz9An error occurred while requesting your edge function at .)r#   requestraise_for_statusr	   r   r0   getr   )r$   r(   r   r   r0   responseexcs          r%   _requestzAsyncFunctionsClient._request+   s      --fcg-VV	%%'  W  	$##G, dNs{{Naabc 	s/   #B=B? B	BABBBtokenc                 T    t        |      st        d       d| | j                  d<   y)zUpdates the authorization header

        Parameters
        ----------
        token : str
            the new jwt token sent in the authorization header
        z5token must be a valid JWT authorization token string.zBearer AuthorizationN)r   r   r   )r$   r;   s     r%   set_authzAsyncFunctionsClient.set_auth=   s*     E"NO*1%(9_%r'   function_nameinvoke_optionsc                 (  K   t        |      st        d      | j                  }d}d}||j                  |j	                  di              |j	                  dd      }|j	                  d      }|rHt        |t              st        d| d       t        |      }|j                  d	k7  r|j                  |d
<   |j	                  d      }t        |t              rd|d<   nt        |t              rd|d<   | j                  d| j                   d| ||       d{   }|j                  j	                  d      }|r-|dk(  r(t        |j                         j	                  d            |dk(  r|j                         }	|	S |j                  }	|	S 7 sw)a  Invokes a function

        Parameters
        ----------
        function_name : the name of the function to invoke
        invoke_options : object with the following properties
            `headers`: object representing the headers to send with the request
            `body`: the body of the request
            `responseType`: how the response should be parsed. The default is `json`
        z(function_name must a valid string value.Nz
text/plainr   responseTyperegionzUse FunctionRegion()anyzx-regionbodyzContent-Typezapplication/jsonr,   /)r   r0   zx-relay-headertruer3   r0   )r   r   r   updater7   
isinstancer   r   valuestrdictr:   r   r   r0   content)
r$   r?   r@   r   rF   response_typerC   r8   is_relay_errordatas
             r%   invokezAsyncFunctionsClient.invokeK   s      .GHH,,$%NN>--i<=*..~|LM#''1F!&.9.vha89+F3F<<5(*0,,GJ'!%%f-D$$*6'D$'*<'txxj-17 ' 
 
 "))--.>?n6%hmmo&9&9'&BCCF"==?D  ##D
s   DFFA4F)TN)NN)N)__name__
__module____qualname__rL   r   r!   r    r   r&   r   r   r
   r:   r>   r   bytesrR    r'   r%   r   r      s     #

 
 	

 
 }
: -1)-RS  $sCx.)	
 tCH~& 
$:c :d : DH1 12:4.1	tU{	1r'   r   N)typingr   r   r   r   r   warningsr   httpxr	   r
   errorsr   r   utilsr   r   r   r   r   versionr   r   rW   r'   r%   <module>r^      s/    6 6  % <  "k kr'   