module API.Brig where

import API.BrigCommon
import API.Common
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Base64 as Base64
import qualified Data.CaseInsensitive as CI
import Data.Foldable
import Data.Function
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Vector as V
import GHC.Stack
import Testlib.Prelude

data AddUser = AddUser
  { AddUser -> Maybe String
name :: Maybe String,
    AddUser -> Maybe String
email :: Maybe String,
    AddUser -> Maybe String
teamCode :: Maybe String,
    AddUser -> Maybe String
password :: Maybe String
  }

instance Default AddUser where
  def :: AddUser
def = Maybe String
-> Maybe String -> Maybe String -> Maybe String -> AddUser
AddUser Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing

data NewProvider = NewProvider
  { NewProvider -> String
newProviderName :: String,
    NewProvider -> String
newProviderDesc :: String,
    NewProvider -> String
newProviderEmail :: String,
    NewProvider -> Maybe String
newProviderPassword :: Maybe String,
    NewProvider -> String
newProviderUrl :: String
  }

instance Default NewProvider where
  def :: NewProvider
def =
    String -> String -> String -> Maybe String -> String -> NewProvider
NewProvider
      String
"New Provider"
      String
"Just a provider"
      String
"provider@example.com"
      Maybe String
forall a. Maybe a
Nothing
      String
"https://example.com"

instance ToJSON NewProvider where
  toJSON :: NewProvider -> Value
toJSON NewProvider {String
Maybe String
$sel:newProviderName:NewProvider :: NewProvider -> String
$sel:newProviderDesc:NewProvider :: NewProvider -> String
$sel:newProviderEmail:NewProvider :: NewProvider -> String
$sel:newProviderPassword:NewProvider :: NewProvider -> Maybe String
$sel:newProviderUrl:NewProvider :: NewProvider -> String
newProviderName :: String
newProviderDesc :: String
newProviderEmail :: String
newProviderPassword :: Maybe String
newProviderUrl :: String
..} =
    [Pair] -> Value
Aeson.object
      [ String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newProviderName,
        String
"description" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newProviderDesc,
        String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newProviderEmail,
        String
"password" String -> Maybe String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Maybe String
newProviderPassword,
        String
"url" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newProviderUrl
      ]

data NewService = NewService
  { NewService -> String
newServiceName :: String,
    NewService -> String
newServiceSummary :: String,
    NewService -> String
newServiceDescr :: String,
    NewService -> String
newServiceUrl :: String,
    NewService -> ByteString
newServiceKey :: ByteString,
    NewService -> Maybe String
newServiceToken :: Maybe String,
    NewService -> [String]
newServiceAssets :: [String],
    NewService -> [String]
newServiceTags :: [String]
  }

instance Default NewService where
  def :: NewService
def =
    String
-> String
-> String
-> String
-> ByteString
-> Maybe String
-> [String]
-> [String]
-> NewService
NewService
      String
"New Service"
      String
"Just a service"
      String
"Just a service description"
      String
"https://example.com"
      ( Text -> ByteString
T.encodeUtf8 (Text -> ByteString)
-> ([String] -> Text) -> [String] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.unlines ([Text] -> Text) -> ([String] -> [Text]) -> [String] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack ([String] -> ByteString) -> [String] -> ByteString
forall a b. (a -> b) -> a -> b
$
          [ String
"-----BEGIN PUBLIC KEY-----",
            String
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu+Kg/PHHU3atXrUbKnw0",
            String
"G06FliXcNt3lMwl2os5twEDcPPFw/feGiAKymxp+7JqZDrseS5D9THGrW+OQRIPH",
            String
"WvUBdiLfGrZqJO223DB6D8K2Su/odmnjZJ2z23rhXoEArTplu+Dg9K+c2LVeXTKV",
            String
"VPOaOzgtAB21XKRiQ4ermqgi3/njr03rXyq/qNkuNd6tNcg+HAfGxfGvvCSYBfiS",
            String
"bUKr/BeArYRcjzr/h5m1In6fG/if9GEI6m8dxHT9JbY53wiksowy6ajCuqskIFg8",
            String
"7X883H+LA/d6X5CTiPv1VMxXdBUiGPuC9IT/6CNQ1/LFt0P37ax58+LGYlaFo7la",
            String
"nQIDAQAB",
            String
"-----END PUBLIC KEY-----"
          ]
      )
      (String -> Maybe String
forall a. a -> Maybe a
Just String
"secret-token")
      []
      [String
"music", String
"quiz", String
"weather"]

instance ToJSON NewService where
  toJSON :: NewService -> Value
toJSON NewService {String
[String]
Maybe String
ByteString
$sel:newServiceName:NewService :: NewService -> String
$sel:newServiceSummary:NewService :: NewService -> String
$sel:newServiceDescr:NewService :: NewService -> String
$sel:newServiceUrl:NewService :: NewService -> String
$sel:newServiceKey:NewService :: NewService -> ByteString
$sel:newServiceToken:NewService :: NewService -> Maybe String
$sel:newServiceAssets:NewService :: NewService -> [String]
$sel:newServiceTags:NewService :: NewService -> [String]
newServiceName :: String
newServiceSummary :: String
newServiceDescr :: String
newServiceUrl :: String
newServiceKey :: ByteString
newServiceToken :: Maybe String
newServiceAssets :: [String]
newServiceTags :: [String]
..} =
    [Pair] -> Value
Aeson.object
      [ String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newServiceName,
        String
"summary" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newServiceSummary,
        String
"description" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newServiceDescr,
        String
"base_url" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
newServiceUrl,
        String
"public_key" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= (Text -> String
T.unpack (Text -> String) -> (ByteString -> Text) -> ByteString -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
T.decodeUtf8) ByteString
newServiceKey,
        String
"auth_token" String -> Maybe String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Maybe String
newServiceToken,
        String
"assets" String -> Value -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Array -> Value
Aeson.Array ([Value] -> Array
forall a. [a] -> Vector a
V.fromList (Text -> Value
Aeson.String (Text -> Value) -> (String -> Text) -> String -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Value) -> [String] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String]
newServiceAssets)),
        String
"tags" String -> Value -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Array -> Value
Aeson.Array ([Value] -> Array
forall a. [a] -> Vector a
V.fromList (Text -> Value
Aeson.String (Text -> Value) -> (String -> Text) -> String -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Value) -> [String] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String]
newServiceTags))
      ]

addUser :: (HasCallStack, MakesValue dom) => dom -> AddUser -> App Response
addUser :: forall dom.
(HasCallStack, MakesValue dom) =>
dom -> AddUser -> App Response
addUser dom
dom AddUser
opts = do
  Request
req <- dom -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest dom
dom Service
Brig Versioned
Versioned String
"register"
  String
name <- App String -> (String -> App String) -> Maybe String -> App String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe App String
randomName String -> App String
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AddUser
opts.name
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject
        [ String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
name,
          String
"email" String -> Maybe String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddUser
opts.email,
          String
"team_code" String -> Maybe String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= AddUser
opts.teamCode,
          String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
defPassword AddUser
opts.password
        ]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_users__uid_domain___uid_
getUser ::
  (HasCallStack, MakesValue user, MakesValue target) =>
  user ->
  target ->
  App Response
getUser :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
getUser user
user target
target = do
  (String
domain, String
uid) <- target -> App (String, String)
forall a. (HasCallStack, MakesValue a) => a -> App (String, String)
objQid target
target
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"users", String
domain, String
uid]
  String -> Request -> App Response
submit String
"GET" Request
req

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/get_clients__client_
getClient ::
  (HasCallStack, MakesValue user, MakesValue client) =>
  user ->
  client ->
  App Response
getClient :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
getClient user
u client
cli = do
  String
c <- client -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make client
cli App Value -> (App Value -> App String) -> App String
forall a b. a -> (a -> b) -> b
& App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
u Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"clients", String
c]
  String -> Request -> App Response
submit String
"GET" Request
req

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_clients
getSelfClients ::
  (HasCallStack, MakesValue user) =>
  user ->
  App Response
getSelfClients :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getSelfClients user
u =
  user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
u Service
Brig Versioned
Versioned ([String] -> String
joinHttpPath [String
"clients"])
    App Request -> (Request -> App Response) -> App Response
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Request -> App Response
submit String
"GET"

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/delete_self
deleteUser :: (HasCallStack, MakesValue user) => user -> App Response
deleteUser :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
deleteUser user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/self"
  String -> Request -> App Response
submit String
"DELETE" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
defPassword]

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/post_clients
addClient ::
  (HasCallStack, MakesValue user) =>
  user ->
  AddClient ->
  App Response
addClient :: forall user.
(HasCallStack, MakesValue user) =>
user -> AddClient -> App Response
addClient user
user AddClient
args = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ String
"/clients"
  [Pair]
val <- AddClient -> App [Pair]
mkAddClientValue AddClient
args
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [Pair]
val

data UpdateClient = UpdateClient
  { UpdateClient -> [Value]
prekeys :: [Value],
    UpdateClient -> Maybe Value
lastPrekey :: Maybe Value,
    UpdateClient -> Maybe String
label :: Maybe String,
    UpdateClient -> Maybe [String]
capabilities :: Maybe [String],
    UpdateClient -> Maybe Value
mlsPublicKeys :: Maybe Value
  }

instance Default UpdateClient where
  def :: UpdateClient
def =
    UpdateClient
      { $sel:prekeys:UpdateClient :: [Value]
prekeys = [],
        $sel:lastPrekey:UpdateClient :: Maybe Value
lastPrekey = Maybe Value
forall a. Maybe a
Nothing,
        $sel:label:UpdateClient :: Maybe String
label = Maybe String
forall a. Maybe a
Nothing,
        $sel:capabilities:UpdateClient :: Maybe [String]
capabilities = Maybe [String]
forall a. Maybe a
Nothing,
        $sel:mlsPublicKeys:UpdateClient :: Maybe Value
mlsPublicKeys = Maybe Value
forall a. Maybe a
Nothing
      }

updateClient ::
  (HasCallStack) =>
  ClientIdentity ->
  UpdateClient ->
  App Response
updateClient :: HasCallStack => ClientIdentity -> UpdateClient -> App Response
updateClient ClientIdentity
cid UpdateClient
args = do
  Request
req <- ClientIdentity -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest ClientIdentity
cid Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ String
"/clients/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ClientIdentity
cid.client
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject
        ( [String
"prekeys" String -> [Value] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= UpdateClient
args.prekeys]
            [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [String
"lastkey" String -> Value -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Value
k | Value
k <- Maybe Value -> [Value]
forall a. Maybe a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList UpdateClient
args.lastPrekey]
            [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [String
"label" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
l | String
l <- Maybe String -> [String]
forall a. Maybe a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList UpdateClient
args.label]
            [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [String
"capabilities" String -> [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [String]
c | [String]
c <- Maybe [String] -> [[String]]
forall a. Maybe a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList UpdateClient
args.capabilities]
            [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [String
"mls_public_keys" String -> Value -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Value
k | Value
k <- Maybe Value -> [Value]
forall a. Maybe a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList UpdateClient
args.mlsPublicKeys]
        )

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/delete_clients__client_
deleteClient ::
  (HasCallStack, MakesValue user, MakesValue client) =>
  user ->
  client ->
  App Response
deleteClient :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
deleteClient user
user client
client = do
  String
cid <- client -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
objId client
client
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ String
"/clients/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
cid
  String -> Request -> App Response
submit String
"DELETE" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject
        [ String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
defPassword
        ]

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/get_users__uid_domain___uid__clients
getClientsQualified ::
  ( HasCallStack,
    MakesValue user,
    MakesValue domain,
    MakesValue otherUser
  ) =>
  user ->
  domain ->
  otherUser ->
  App Response
getClientsQualified :: forall user domain otherUser.
(HasCallStack, MakesValue user, MakesValue domain,
 MakesValue otherUser) =>
user -> domain -> otherUser -> App Response
getClientsQualified user
user domain
domain otherUser
otherUser = do
  String
ouid <- otherUser -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
objId otherUser
otherUser
  String
d <- domain -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
objDomain domain
domain
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      String
"/users/"
        String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
d
        String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/"
        String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
ouid
        String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/clients"
  String -> Request -> App Response
submit String
"GET" Request
req

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/post_users_list_clients
listUsersClients :: (HasCallStack, MakesValue user, MakesValue qualifiedUserIds) => user -> [qualifiedUserIds] -> App Response
listUsersClients :: forall user qualifiedUserIds.
(HasCallStack, MakesValue user, MakesValue qualifiedUserIds) =>
user -> [qualifiedUserIds] -> App Response
listUsersClients user
usr [qualifiedUserIds]
qualifiedUserIds = do
  [Value]
qUsers <- (qualifiedUserIds -> App Value)
-> [qualifiedUserIds] -> App [Value]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM qualifiedUserIds -> App Value
forall a. (HasCallStack, MakesValue a) => a -> App Value
objQidObject [qualifiedUserIds]
qualifiedUserIds
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
usr Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"users", String
"list-clients"]
  String -> Request -> App Response
submit String
"POST" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"qualified_users" String -> [Value] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [Value]
qUsers])

searchContacts ::
  ( MakesValue user,
    MakesValue searchTerm,
    MakesValue domain
  ) =>
  user ->
  searchTerm ->
  domain ->
  App Response
searchContacts :: forall user searchTerm domain.
(MakesValue user, MakesValue searchTerm, MakesValue domain) =>
user -> searchTerm -> domain -> App Response
searchContacts user
user searchTerm
searchTerm domain
domain = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/search/contacts"
  String
q <- searchTerm -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString searchTerm
searchTerm
  String
d <- domain -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
objDomain domain
domain
  String -> Request -> App Response
submit String
"GET" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams [(String
"q", String
q), (String
"domain", String
d)])

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_teams__tid__search
searchTeam :: (HasCallStack, MakesValue user) => user -> String -> App Response
searchTeam :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
searchTeam user
user String
q = do
  String
tid <- user
user user -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"team" App Value -> (App Value -> App String) -> App String
forall a b. a -> (a -> b) -> b
& App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"teams", String
tid, String
"search"]
  String -> Request -> App Response
submit String
"GET" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams [(String
"q", String
q)])

getAPIVersion :: (HasCallStack, MakesValue domain) => domain -> App Response
getAPIVersion :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getAPIVersion domain
domain = do
  Request
req <- domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest domain
domain Service
Brig Versioned
Unversioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ String
"/api-version"
  String -> Request -> App Response
submit String
"GET" Request
req

postConnection ::
  ( HasCallStack,
    MakesValue userFrom,
    MakesValue userTo
  ) =>
  userFrom ->
  userTo ->
  App Response
postConnection :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
postConnection userFrom
userFrom userTo
userTo = do
  (String
userToDomain, String
userToId) <- userTo -> App (String, String)
forall a. (HasCallStack, MakesValue a) => a -> App (String, String)
objQid userTo
userTo
  Request
req <-
    userFrom -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest userFrom
userFrom Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"/connections", String
userToDomain, String
userToId]
  String -> Request -> App Response
submit String
"POST" Request
req

getConnection ::
  ( HasCallStack,
    MakesValue userFrom,
    MakesValue userTo
  ) =>
  userFrom ->
  userTo ->
  App Response
getConnection :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
getConnection userFrom
userFrom userTo
userTo = do
  (String
userToDomain, String
userToId) <- userTo -> App (String, String)
forall a. (HasCallStack, MakesValue a) => a -> App (String, String)
objQid userTo
userTo
  Request
req <-
    userFrom -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest userFrom
userFrom Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"/connections", String
userToDomain, String
userToId]
  String -> Request -> App Response
submit String
"GET" Request
req

putConnection ::
  ( HasCallStack,
    MakesValue userFrom,
    MakesValue userTo,
    MakesValue status
  ) =>
  userFrom ->
  userTo ->
  status ->
  App Response
putConnection :: forall user domain otherUser.
(HasCallStack, MakesValue user, MakesValue domain,
 MakesValue otherUser) =>
user -> domain -> otherUser -> App Response
putConnection userFrom
userFrom userTo
userTo status
status = do
  (String
userToDomain, String
userToId) <- userTo -> App (String, String)
forall a. (HasCallStack, MakesValue a) => a -> App (String, String)
objQid userTo
userTo
  Request
req <-
    userFrom -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest userFrom
userFrom Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"/connections", String
userToDomain, String
userToId]
  String
statusS <- status -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString status
status
  String -> Request -> App Response
submit String
"PUT" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"status" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
statusS])

getConnections :: (HasCallStack, MakesValue user) => user -> App Response
getConnections :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getConnections user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/list-connections"
  String -> Request -> App Response
submit String
"POST" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"size" String -> Value -> Pair
forall a. ToJSON a => String -> a -> Pair
.= Scientific -> Value
Aeson.Number Scientific
500])

uploadKeyPackages :: ClientIdentity -> [ByteString] -> App Response
uploadKeyPackages :: ClientIdentity -> [ByteString] -> App Response
uploadKeyPackages ClientIdentity
cid [ByteString]
kps = do
  Request
req <-
    ClientIdentity -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest ClientIdentity
cid Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      String
"/mls/key-packages/self/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ClientIdentity
cid.client
  String -> Request -> App Response
submit
    String
"POST"
    (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"key_packages" String -> [Text] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= (ByteString -> Text) -> [ByteString] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (ByteString -> Text
T.decodeUtf8 (ByteString -> Text)
-> (ByteString -> ByteString) -> ByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Base64.encode) [ByteString]
kps])

claimKeyPackagesWithParams :: (MakesValue u, MakesValue v) => Ciphersuite -> u -> v -> [(String, String)] -> App Response
claimKeyPackagesWithParams :: forall u v.
(MakesValue u, MakesValue v) =>
Ciphersuite -> u -> v -> [(String, String)] -> App Response
claimKeyPackagesWithParams Ciphersuite
suite u
u v
v [(String, String)]
params = do
  (String
targetDom, String
targetUid) <- v -> App (String, String)
forall a. (HasCallStack, MakesValue a) => a -> App (String, String)
objQid v
v
  Request
req <-
    u -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest u
u Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      String
"/mls/key-packages/claim/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
targetDom String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
targetUid
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams ([(String
"ciphersuite", Ciphersuite
suite.code)] [(String, String)] -> [(String, String)] -> [(String, String)]
forall a. Semigroup a => a -> a -> a
<> [(String, String)]
params)

claimKeyPackages :: (HasCallStack, MakesValue u, MakesValue v) => Ciphersuite -> u -> v -> App Response
claimKeyPackages :: forall u v.
(HasCallStack, MakesValue u, MakesValue v) =>
Ciphersuite -> u -> v -> App Response
claimKeyPackages Ciphersuite
suite u
u v
v = Ciphersuite -> u -> v -> [(String, String)] -> App Response
forall u v.
(MakesValue u, MakesValue v) =>
Ciphersuite -> u -> v -> [(String, String)] -> App Response
claimKeyPackagesWithParams Ciphersuite
suite u
u v
v []

countKeyPackages :: Ciphersuite -> ClientIdentity -> App Response
countKeyPackages :: Ciphersuite -> ClientIdentity -> App Response
countKeyPackages Ciphersuite
suite ClientIdentity
cid = do
  Request
req <- ClientIdentity -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest ClientIdentity
cid Service
Brig Versioned
Versioned (String
"/mls/key-packages/self/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ClientIdentity
cid.client String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/count")
  String -> Request -> App Response
submit String
"GET" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams [(String
"ciphersuite", Ciphersuite
suite.code)]

deleteKeyPackages :: ClientIdentity -> [String] -> App Response
deleteKeyPackages :: ClientIdentity -> [String] -> App Response
deleteKeyPackages ClientIdentity
cid [String]
kps = do
  Request
req <- ClientIdentity -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest ClientIdentity
cid Service
Brig Versioned
Versioned (String
"/mls/key-packages/self/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ClientIdentity
cid.client)
  String -> Request -> App Response
submit String
"DELETE" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"key_packages" String -> [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [String]
kps]

replaceKeyPackages :: ClientIdentity -> Maybe [Ciphersuite] -> [ByteString] -> App Response
replaceKeyPackages :: ClientIdentity
-> Maybe [Ciphersuite] -> [ByteString] -> App Response
replaceKeyPackages ClientIdentity
cid Maybe [Ciphersuite]
mSuites [ByteString]
kps = do
  Request
req <-
    ClientIdentity -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest ClientIdentity
cid Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      String
"/mls/key-packages/self/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ClientIdentity
cid.client
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& (Request -> Request)
-> ([Ciphersuite] -> Request -> Request)
-> Maybe [Ciphersuite]
-> Request
-> Request
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Request -> Request
forall a. a -> a
id (\[Ciphersuite]
suites -> [(String, String)] -> Request -> Request
addQueryParams [(String
"ciphersuites", String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"," ((Ciphersuite -> String) -> [Ciphersuite] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (.code) [Ciphersuite]
suites))]) Maybe [Ciphersuite]
mSuites
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"key_packages" String -> [Text] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= (ByteString -> Text) -> [ByteString] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (ByteString -> Text
T.decodeUtf8 (ByteString -> Text)
-> (ByteString -> ByteString) -> ByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Base64.encode) [ByteString]
kps]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_self
getSelf :: (HasCallStack, MakesValue user) => user -> App Response
getSelf :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getSelf = Versioned -> user -> App Response
forall user.
(HasCallStack, MakesValue user) =>
Versioned -> user -> App Response
getSelfWithVersion Versioned
Versioned

getSelfWithVersion :: (HasCallStack, MakesValue user) => Versioned -> user -> App Response
getSelfWithVersion :: forall user.
(HasCallStack, MakesValue user) =>
Versioned -> user -> App Response
getSelfWithVersion Versioned
v user
user = user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
v String
"/self" App Request -> (Request -> App Response) -> App Response
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Request -> App Response
submit String
"GET"

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_self
-- this is a low-level version of `getSelf` for testing some error conditions.
getSelf' :: (HasCallStack) => String -> String -> App Response
getSelf' :: HasCallStack => String -> String -> App Response
getSelf' String
domain String
uid = Versioned -> Value -> App Response
forall user.
(HasCallStack, MakesValue user) =>
Versioned -> user -> App Response
getSelfWithVersion Versioned
Versioned (Value -> App Response) -> Value -> App Response
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [String
"domain" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
domain, String
"id" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
uid]

data PutSelf = PutSelf
  { PutSelf -> Maybe Int
accent :: Maybe Int,
    PutSelf -> Maybe [Value]
assets :: Maybe [Value], -- [{"key":"string", "size":"string", "type":"string"}]
    PutSelf -> Maybe String
name :: Maybe String,
    PutSelf -> Maybe [String]
picture :: Maybe [String]
  }

instance Default PutSelf where
  def :: PutSelf
def = Maybe Int
-> Maybe [Value] -> Maybe String -> Maybe [String] -> PutSelf
PutSelf Maybe Int
forall a. Maybe a
Nothing Maybe [Value]
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe [String]
forall a. Maybe a
Nothing

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/put_self
putSelf :: (HasCallStack, MakesValue caller) => caller -> PutSelf -> App Response
putSelf :: forall caller.
(HasCallStack, MakesValue caller) =>
caller -> PutSelf -> App Response
putSelf caller
caller PutSelf
body = do
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned String
"/self"
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject
        [ String
"accent_id" String -> Maybe Int -> Pair
forall a. ToJSON a => String -> a -> Pair
.= PutSelf
body.accent,
          String
"assets" String -> Maybe [Value] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= PutSelf
body.assets,
          String
"name" String -> Maybe String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= PutSelf
body.name,
          String
"picture" String -> Maybe [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= PutSelf
body.picture
        ]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/put_self_locale
putSelfLocale :: (HasCallStack, MakesValue caller) => caller -> String -> App Response
putSelfLocale :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
putSelfLocale caller
caller String
locale = do
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned String
"/self/locale"
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"locale" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
locale]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/put_users__uid__email
--
-- NOTE: the full process of changing (and confirming) the email address is more complicated.
-- see /services/brig/test/integration for details.
putSelfEmail :: (HasCallStack, MakesValue caller) => caller -> String -> App Response
putSelfEmail :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
putSelfEmail caller
caller String
emailAddress = do
  String
callerid <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ caller
caller caller -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"users", String
callerid, String
"email"]
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
emailAddress]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/delete_self_email
deleteSelfEmail :: (HasCallStack, MakesValue caller) => caller -> App Response
deleteSelfEmail :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
deleteSelfEmail caller
caller = do
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"self", String
"email"]
  String -> Request -> App Response
submit String
"DELETE" Request
req

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/put_self_handle
-- FUTUREWORK: rename to putSelfHandle for consistency
putHandle :: (HasCallStack, MakesValue user) => user -> String -> App Response
putHandle :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
putHandle user
user String
handle = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/self/handle"
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"handle" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
handle]

getUserSupportedProtocols ::
  (HasCallStack, MakesValue user, MakesValue target) =>
  user ->
  target ->
  App Response
getUserSupportedProtocols :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
getUserSupportedProtocols user
user target
target = do
  (String
domain, String
uid) <- target -> App (String, String)
forall a. (HasCallStack, MakesValue a) => a -> App (String, String)
objQid target
target
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"users", String
domain, String
uid, String
"supported-protocols"]
  String -> Request -> App Response
submit String
"GET" Request
req

putUserSupportedProtocols ::
  (HasCallStack, MakesValue user) =>
  user ->
  [String] ->
  App Response
putUserSupportedProtocols :: forall user.
(HasCallStack, MakesValue user) =>
user -> [String] -> App Response
putUserSupportedProtocols user
user [String]
ps = do
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"self", String
"supported-protocols"]
  String -> Request -> App Response
submit String
"PUT" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"supported_protocols" String -> [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [String]
ps])

data PostInvitation = PostInvitation
  { PostInvitation -> Maybe String
email :: Maybe String,
    PostInvitation -> Maybe String
role :: Maybe String
  }

instance Default PostInvitation where
  def :: PostInvitation
def = Maybe String -> Maybe String -> PostInvitation
PostInvitation Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing

postInvitation ::
  (HasCallStack, MakesValue user) =>
  user ->
  PostInvitation ->
  App Response
postInvitation :: forall user.
(HasCallStack, MakesValue user) =>
user -> PostInvitation -> App Response
postInvitation user
user PostInvitation
inv = do
  String
tid <- user
user user -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"team" App Value -> (App Value -> App String) -> App String
forall a b. a -> (a -> b) -> b
& App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"teams", String
tid, String
"invitations"]
  String
email <- App String -> (String -> App String) -> Maybe String -> App String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe App String
randomEmail String -> App String
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PostInvitation
inv.email
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject ([String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
email] [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [String
"role" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
r | String
r <- Maybe String -> [String]
forall a. Maybe a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList PostInvitation
inv.role])

getApiVersions :: (HasCallStack) => App Response
getApiVersions :: HasCallStack => App Response
getApiVersions = do
  Request
req <-
    Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Domain
OwnDomain Service
Brig Versioned
Unversioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"api-version"]
  String -> Request -> App Response
submit String
"GET" Request
req

getSwaggerPublicTOC :: (HasCallStack) => App Response
getSwaggerPublicTOC :: HasCallStack => App Response
getSwaggerPublicTOC = do
  Request
req <-
    Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Domain
OwnDomain Service
Brig Versioned
Unversioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"api", String
"swagger-ui"]
  String -> Request -> App Response
submit String
"GET" Request
req

getSwaggerPublicAllUI :: (HasCallStack) => Int -> App Response
getSwaggerPublicAllUI :: HasCallStack => Int -> App Response
getSwaggerPublicAllUI Int
version = do
  Request
req <-
    Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Domain
OwnDomain Service
Brig (Int -> Versioned
ExplicitVersion Int
version) (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"api", String
"swagger-ui"]
  String -> Request -> App Response
submit String
"GET" Request
req

getSwaggerPublicAllJson :: (HasCallStack) => Int -> App Response
getSwaggerPublicAllJson :: HasCallStack => Int -> App Response
getSwaggerPublicAllJson Int
version = do
  Request
req <-
    Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Domain
OwnDomain Service
Brig (Int -> Versioned
ExplicitVersion Int
version) (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"api", String
"swagger.json"]
  String -> Request -> App Response
submit String
"GET" Request
req

getSwaggerInternalUI :: (HasCallStack) => String -> App Response
getSwaggerInternalUI :: HasCallStack => String -> App Response
getSwaggerInternalUI String
service = do
  Request
req <-
    Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Domain
OwnDomain Service
Brig Versioned
Unversioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"api-internal", String
"swagger-ui", String
service]
  String -> Request -> App Response
submit String
"GET" Request
req

getSwaggerInternalJson :: (HasCallStack) => String -> App Response
getSwaggerInternalJson :: HasCallStack => String -> App Response
getSwaggerInternalJson String
service = do
  Request
req <-
    Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Domain
OwnDomain Service
Nginz Versioned
Unversioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"api-internal", String
"swagger-ui", String
service String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"-swagger.json"]
  String -> Request -> App Response
submit String
"GET" Request
req

newProvider ::
  ( HasCallStack,
    MakesValue provider,
    MakesValue user
  ) =>
  user ->
  provider ->
  App Value
newProvider :: forall provider user.
(HasCallStack, MakesValue provider, MakesValue user) =>
user -> provider -> App Value
newProvider user
user provider
provider = do
  Value
p <- provider -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make provider
provider
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"provider", String
"register"]
  String -> Request -> App Response
submit String
"POST" (Value -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON Value
p Request
req) App Response -> (Response -> App Value) -> App Value
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
`bindResponse` \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
201
    Response
resp.json

activateProvider ::
  ( HasCallStack,
    MakesValue dom
  ) =>
  dom ->
  String ->
  String ->
  App ()
activateProvider :: forall dom.
(HasCallStack, MakesValue dom) =>
dom -> String -> String -> App ()
activateProvider dom
dom String
key String
code = do
  Value
d <- dom -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make dom
dom
  Request
req <-
    Value -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest Value
d Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"provider", String
"activate"]
  let ps :: [(String, String)]
ps = [(String
"key", String
key), (String
"code", String
code)]
  String -> Request -> App Response
submit String
"GET" ([(String, String)] -> Request -> Request
addQueryParams [(String, String)]
ps Request
req) App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
`bindResponse` \Response
resp -> do
    Response
resp.status Int -> [Value] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatchOneOf` [Scientific -> Value
Number Scientific
200, Scientific -> Value
Number Scientific
204]

activateUserV5 :: (HasCallStack, MakesValue dom, MakesValue bdy) => dom -> bdy -> App Response
activateUserV5 :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
activateUserV5 dom
dom bdy
bdy = do
  Value
b <- bdy -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make bdy
bdy
  Request
req <- dom -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest dom
dom Service
Brig (Int -> Versioned
ExplicitVersion Int
5) (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"activate", String
"send"]
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ (Value -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON Value
b Request
req)

-- | Returns the value of the Set-Cookie header that is to be used to
-- authenticate to provider endpoints.
loginProvider ::
  ( HasCallStack,
    MakesValue dom
  ) =>
  dom ->
  String ->
  String ->
  App ByteString
loginProvider :: forall dom.
(HasCallStack, MakesValue dom) =>
dom -> String -> String -> App ByteString
loginProvider dom
dom String
email String
pass = do
  String
d <- dom -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString dom
dom
  Request
req <-
    String -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest String
d Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"provider", String
"login"]
  String -> Request -> App Response
submit String
"POST" ([Pair] -> Request -> Request
addJSONObject [String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
email, String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
pass] Request
req) App Response -> (Response -> App ByteString) -> App ByteString
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
`bindResponse` \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    let hs :: [Header]
hs = Response -> [Header]
headers Response
resp
        setCookieHeader :: HeaderName
setCookieHeader = ByteString -> HeaderName
forall s. FoldCase s => s -> CI s
CI.mk (Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> (String -> Text) -> String -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> ByteString) -> String -> ByteString
forall a b. (a -> b) -> a -> b
$ String
"Set-Cookie")
    ByteString -> App ByteString
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> App ByteString)
-> ([Header] -> ByteString) -> [Header] -> App ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe ByteString -> ByteString
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe ByteString -> ByteString)
-> ([Header] -> Maybe ByteString) -> [Header] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Header -> Maybe ByteString) -> [Header] -> Maybe ByteString
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(HeaderName
k, ByteString
v) -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (HeaderName
k HeaderName -> HeaderName -> Bool
forall a. Eq a => a -> a -> Bool
== HeaderName
setCookieHeader) Maybe () -> ByteString -> Maybe ByteString
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ByteString
v) ([Header] -> App ByteString) -> [Header] -> App ByteString
forall a b. (a -> b) -> a -> b
$ [Header]
hs

newService ::
  ( HasCallStack,
    MakesValue dom
  ) =>
  dom ->
  String ->
  NewService ->
  App Value
newService :: forall dom.
(HasCallStack, MakesValue dom) =>
dom -> String -> NewService -> App Value
newService dom
dom String
providerId NewService
service = do
  Value
s <- NewService -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make NewService
service
  String
domain <- dom -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString dom
dom
  Request
req <-
    String -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest String
domain Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"provider", String
"services"]
  let addHdrs :: Request -> Request
addHdrs =
        String -> String -> Request -> Request
addHeader String
"Z-Type" String
"provider"
          (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> Request -> Request
addHeader String
"Z-Provider" String
providerId
  String -> Request -> App Response
submit String
"POST" (Value -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON Value
s (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> Request
addHdrs (Request -> Request) -> Request -> Request
forall a b. (a -> b) -> a -> b
$ Request
req) App Response -> (Response -> App Value) -> App Value
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
`bindResponse` \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
201
    Response
resp.json

updateService ::
  ( HasCallStack,
    MakesValue dom,
    MakesValue serviceId
  ) =>
  dom ->
  String ->
  serviceId ->
  Maybe String ->
  Maybe String ->
  App Response
updateService :: forall dom serviceId.
(HasCallStack, MakesValue dom, MakesValue serviceId) =>
dom
-> String
-> serviceId
-> Maybe String
-> Maybe String
-> App Response
updateService dom
dom String
providerId serviceId
serviceId Maybe String
mAcceptHeader Maybe String
newName = do
  String
sId <- serviceId -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString serviceId
serviceId
  String
domain <- dom -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString dom
dom
  Request
req <-
    String -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest String
domain Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath [String
"provider", String
"services", String
sId]
  let addHdrs :: Request -> Request
addHdrs =
        String -> Request -> Request
zType String
"provider"
          (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Request -> Request
zProvider String
providerId
          (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Request -> Request)
-> (String -> Request -> Request)
-> Maybe String
-> Request
-> Request
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Request -> Request
forall a. a -> a
id (String -> String -> Request -> Request
addHeader String
"Accept") Maybe String
mAcceptHeader
  String -> Request -> App Response
submit String
"PUT"
    (Request -> App Response)
-> (Request -> Request) -> Request -> App Response
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> Request
addHdrs
    (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Pair] -> Request -> Request
addJSONObject [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
n | String
n <- Maybe String -> [String]
forall a. Maybe a -> [a]
maybeToList Maybe String
newName]
    (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req

updateServiceConn ::
  (MakesValue conn) =>
  -- | providerId
  String ->
  -- | serviceId
  String ->
  -- | connection update as a Json object, with an obligatory "password" field
  conn ->
  App Response
updateServiceConn :: forall conn.
MakesValue conn =>
String -> String -> conn -> App Response
updateServiceConn String
providerId String
serviceId conn
connectionUpdate = do
  Request
req <- Domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest Domain
OwnDomain Service
Brig Versioned
Versioned do
    [String] -> String
joinHttpPath [String
"provider", String
"services", String
serviceId, String
"connection"]
  Value
upd <- conn -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make conn
connectionUpdate
  String -> Request -> App Response
submit String
"PUT"
    (Request -> App Response)
-> (Request -> Request) -> Request -> App Response
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Request -> Request
zType String
"provider"
    (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Request -> Request
zProvider String
providerId
    (Request -> Request) -> (Request -> Request) -> Request -> Request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON Value
upd
    (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/get_users__uid_domain___uid__prekeys__client_
getUsersPrekeysClient :: (HasCallStack, MakesValue caller, MakesValue targetUser) => caller -> targetUser -> String -> App Response
getUsersPrekeysClient :: forall caller targetUser.
(HasCallStack, MakesValue caller, MakesValue targetUser) =>
caller -> targetUser -> String -> App Response
getUsersPrekeysClient caller
caller targetUser
targetUser String
targetClient = do
  String
dom <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ targetUser
targetUser targetUser -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"domain"
  String
uid <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ targetUser
targetUser targetUser -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"users", String
dom, String
uid, String
"prekeys", String
targetClient]
  String -> Request -> App Response
submit String
"GET" Request
req

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/get_users__uid_domain___uid__prekeys
getUsersPrekeyBundle :: (HasCallStack, MakesValue caller, MakesValue targetUser) => caller -> targetUser -> App Response
getUsersPrekeyBundle :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
getUsersPrekeyBundle caller
caller targetUser
targetUser = do
  String
dom <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ targetUser
targetUser targetUser -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"domain"
  String
uid <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ targetUser
targetUser targetUser -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"users", String
dom, String
uid, String
"prekeys"]
  String -> Request -> App Response
submit String
"GET" Request
req

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/post_users_list_prekeys
getMultiUserPrekeyBundle :: (HasCallStack, MakesValue caller, ToJSON userClients) => caller -> userClients -> App Response
getMultiUserPrekeyBundle :: forall caller userClients.
(HasCallStack, MakesValue caller, ToJSON userClients) =>
caller -> userClients -> App Response
getMultiUserPrekeyBundle caller
caller userClients
userClients = do
  Request
req <- caller -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest caller
caller Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"users", String
"list-prekeys"]
  String -> Request -> App Response
submit String
"POST" (userClients -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON userClients
userClients Request
req)

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/post_access
renewToken :: (HasCallStack, MakesValue uid) => uid -> String -> App Response
renewToken :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
renewToken uid
caller String
cookie = do
  Request
req <- uid -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest uid
caller Service
Brig Versioned
Versioned String
"access"
  String -> Request -> App Response
submit String
"POST" (String -> String -> Request -> Request
addHeader String
"Cookie" (String
"zuid=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
cookie) Request
req)

-- | https://staging-nginz-https.zinfra.io/v5/api/swagger-ui/#/default/get_calls_config_v2
getCallsConfigV2 :: (HasCallStack, MakesValue user) => user -> App Response
getCallsConfigV2 :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getCallsConfigV2 user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"calls", String
"config", String
"v2"]
  String -> Request -> App Response
submit String
"GET" Request
req

addBot :: (HasCallStack, MakesValue user) => user -> String -> String -> String -> App Response
addBot :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> String -> String -> App Response
addBot user
user String
providerId String
serviceId String
convId = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"bot", String
"conversations", String
convId]
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& String -> Request -> Request
zType String
"access"
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"provider" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
providerId, String
"service" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
serviceId]

setProperty :: (MakesValue user, ToJSON val) => user -> String -> val -> App Response
setProperty :: forall user val.
(MakesValue user, ToJSON val) =>
user -> String -> val -> App Response
setProperty user
user String
propName val
val = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"properties", String
propName]
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& val -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON val
val

getProperty :: (MakesValue user) => user -> String -> App Response
getProperty :: forall user. MakesValue user => user -> String -> App Response
getProperty user
user String
propName = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"properties", String
propName]
  String -> Request -> App Response
submit String
"GET" Request
req

deleteProperty :: (MakesValue user) => user -> String -> App Response
deleteProperty :: forall user. MakesValue user => user -> String -> App Response
deleteProperty user
user String
propName = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"properties", String
propName]
  String -> Request -> App Response
submit String
"DELETE" Request
req

getAllPropertyNames :: (MakesValue user) => user -> App Response
getAllPropertyNames :: forall user. MakesValue user => user -> App Response
getAllPropertyNames user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"properties"]
  String -> Request -> App Response
submit String
"GET" Request
req

getAllPropertyValues :: (MakesValue user) => user -> App Response
getAllPropertyValues :: forall user. MakesValue user => user -> App Response
getAllPropertyValues user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"properties-values"]
  String -> Request -> App Response
submit String
"GET" Request
req

clearProperties :: (MakesValue user) => user -> App Response
clearProperties :: forall user. MakesValue user => user -> App Response
clearProperties user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"properties"]
  String -> Request -> App Response
submit String
"DELETE" Request
req

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/post_oauth_authorization_codes
generateOAuthAuthorizationCode :: (HasCallStack, MakesValue user, MakesValue cid) => user -> cid -> [String] -> String -> App Response
generateOAuthAuthorizationCode :: forall user cid.
(HasCallStack, MakesValue user, MakesValue cid) =>
user -> cid -> [String] -> String -> App Response
generateOAuthAuthorizationCode user
user cid
cid [String]
scopes String
redirectUrl = do
  String
cidStr <- cid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString cid
cid
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/oauth/authorization/codes"
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject
        [ String
"client_id" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
cidStr,
          String
"scope" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [String] -> String
unwords [String]
scopes,
          String
"redirect_uri" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
redirectUrl,
          String
"code_challenge" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"G7CWLBqYDT8doT_oEIN3un_QwZWYKHmOqG91nwNzITc",
          String
"code_challenge_method" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"S256",
          String
"response_type" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"code",
          String
"state" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"abc"
        ]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/post_oauth_token
createOAuthAccessToken :: (HasCallStack, MakesValue user, MakesValue cid) => user -> cid -> String -> String -> App Response
createOAuthAccessToken :: forall user cid.
(HasCallStack, MakesValue user, MakesValue cid) =>
user -> cid -> String -> String -> App Response
createOAuthAccessToken user
user cid
cid String
code String
redirectUrl = do
  String
cidStr <- cid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString cid
cid
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/oauth/token"
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addUrlEncodedForm
        [ (String
"grant_type", String
"authorization_code"),
          (String
"client_id", String
cidStr),
          (String
"code_verifier", String
"nE3k3zykOmYki~kriKzAmeFiGT7cWugcuToFwo1YPgrZ1cFvaQqLa.dXY9MnDj3umAmG-8lSNIYIl31Cs_.fV5r2psa4WWZcB.Nlc3A-t3p67NDZaOJjIiH~8PvUH_hR"),
          (String
"code", String
code),
          (String
"redirect_uri", String
redirectUrl)
        ]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/post_oauth_token
createOAuthAccessTokenWithRefreshToken :: (HasCallStack, MakesValue user, MakesValue cid) => user -> cid -> String -> App Response
createOAuthAccessTokenWithRefreshToken :: forall caller targetUser.
(HasCallStack, MakesValue caller, MakesValue targetUser) =>
caller -> targetUser -> String -> App Response
createOAuthAccessTokenWithRefreshToken user
user cid
cid String
token = do
  String
cidStr <- cid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString cid
cid
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/oauth/token"
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addUrlEncodedForm
        [ (String
"grant_type", String
"refresh_token"),
          (String
"client_id", String
cidStr),
          (String
"refresh_token", String
token)
        ]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_oauth_applications
getOAuthApplications :: (HasCallStack, MakesValue user) => user -> App Response
getOAuthApplications :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getOAuthApplications user
user = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned String
"/oauth/applications"
  String -> Request -> App Response
submit String
"GET" Request
req

deleteOAuthSession :: (HasCallStack, MakesValue user, MakesValue cid) => user -> cid -> String -> String -> App Response
deleteOAuthSession :: forall user cid.
(HasCallStack, MakesValue user, MakesValue cid) =>
user -> cid -> String -> String -> App Response
deleteOAuthSession user
user cid
cid String
password String
tokenId = do
  String
cidStr <- cid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString cid
cid
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"oauth", String
"applications", String
cidStr, String
"sessions", String
tokenId]
  String -> Request -> App Response
submit String
"DELETE" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
password]

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/delete_oauth_applications__OAuthClientId_
revokeApplicationAccessV6 :: (HasCallStack, MakesValue user, MakesValue cid) => user -> cid -> App Response
revokeApplicationAccessV6 :: forall user target.
(HasCallStack, MakesValue user, MakesValue target) =>
user -> target -> App Response
revokeApplicationAccessV6 user
user cid
cid = do
  String
cidStr <- cid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString cid
cid
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig (Int -> Versioned
ExplicitVersion Int
6) (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"oauth", String
"applications", String
cidStr]
  String -> Request -> App Response
submit String
"DELETE" Request
req

revokeApplicationAccess :: (HasCallStack, MakesValue user, MakesValue cid) => user -> cid -> String -> App Response
revokeApplicationAccess :: forall caller targetUser.
(HasCallStack, MakesValue caller, MakesValue targetUser) =>
caller -> targetUser -> String -> App Response
revokeApplicationAccess user
user cid
cid String
password = do
  String
cidStr <- cid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString cid
cid
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"oauth", String
"applications", String
cidStr, String
"sessions"]
  String -> Request -> App Response
submit String
"DELETE" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
password]

registerUser :: (HasCallStack, MakesValue domain) => domain -> String -> String -> App Response
registerUser :: forall domain.
(HasCallStack, MakesValue domain) =>
domain -> String -> String -> App Response
registerUser domain
domain String
email String
inviteeCode = do
  Request
req <- domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest domain
domain Service
Brig Versioned
Versioned String
"register"
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject
        [ String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"Alice",
          String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
email,
          String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
defPassword,
          String
"team_code" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
inviteeCode
        ]

activate :: (HasCallStack, MakesValue domain) => domain -> String -> String -> App Response
activate :: forall domain.
(HasCallStack, MakesValue domain) =>
domain -> String -> String -> App Response
activate domain
domain String
key String
code = do
  Request
req <- domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
rawBaseRequest domain
domain Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"activate"]
  String -> Request -> App Response
submit String
"GET" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$
    Request
req
      Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams [(String
"key", String
key), (String
"code", String
code)]

acceptTeamInvitation :: (HasCallStack, MakesValue user) => user -> String -> Maybe String -> App Response
acceptTeamInvitation :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> Maybe String -> App Response
acceptTeamInvitation user
user String
code Maybe String
mPw = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"teams", String
"invitations", String
"accept"]
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject ([String
"code" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
code] [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> Maybe Pair -> [Pair]
forall a. Maybe a -> [a]
maybeToList ((String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
(.=) String
"password") (String -> Pair) -> Maybe String -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe String
mPw))

-- | https://staging-nginz-https.zinfra.io/v6/api/swagger-ui/#/default/get_teams__tid__invitations
listInvitations :: (HasCallStack, MakesValue user) => user -> String -> App Response
listInvitations :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
listInvitations user
user String
tid = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"teams", String
tid, String
"invitations"]
  String -> Request -> App Response
submit String
"GET" Request
req

-- | https://staging-nginz-https.zinfra.io/v7/api/swagger-ui/#/default/get-team-invitation-info
getInvitationByCode :: (HasCallStack, MakesValue user) => user -> String -> App Response
getInvitationByCode :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
getInvitationByCode user
user String
code = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"teams", String
"invitations", String
"info"]
  String -> Request -> App Response
submit String
"GET" (Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams [(String
"code", String
code)])

passwordReset :: (HasCallStack, MakesValue domain) => domain -> String -> App Response
passwordReset :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
passwordReset domain
domain String
email = do
  Request
req <- domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest domain
domain Service
Brig Versioned
Versioned String
"password-reset"
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
email]

completePasswordReset :: (HasCallStack, MakesValue domain) => domain -> String -> String -> String -> App Response
completePasswordReset :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> String -> String -> App Response
completePasswordReset domain
domain String
key String
code String
pw = do
  Request
req <- domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest domain
domain Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"password-reset", String
"complete"]
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"key" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
key, String
"code" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
code, String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
pw]

login :: (HasCallStack, MakesValue domain) => domain -> String -> String -> App Response
login :: forall domain.
(HasCallStack, MakesValue domain) =>
domain -> String -> String -> App Response
login domain
domain String
email String
password = do
  Request
req <- domain -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest domain
domain Service
Brig Versioned
Versioned String
"login"
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
email, String
"password" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
password] Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [(String, String)] -> Request -> Request
addQueryParams [(String
"persist", String
"true")]

updateEmail :: (HasCallStack, MakesValue user) => user -> String -> String -> String -> App Response
updateEmail :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> String -> String -> App Response
updateEmail user
user String
email String
cookie String
token = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"access", String
"self", String
"email"]
  String -> Request -> App Response
submit String
"PUT" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"email" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
email] Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& String -> Request -> Request
setCookie String
cookie Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& String -> String -> Request -> Request
addHeader String
"Authorization" (String
"Bearer " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
token)

upgradePersonalToTeam :: (HasCallStack, MakesValue user) => user -> String -> App Response
upgradePersonalToTeam :: forall user.
(HasCallStack, MakesValue user) =>
user -> String -> App Response
upgradePersonalToTeam user
user String
name = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ [String] -> String
joinHttpPath [String
"upgrade-personal-to-team"]
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Pair] -> Request -> Request
addJSONObject [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
name, String
"icon" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"default"]

postServiceWhitelist ::
  ( HasCallStack,
    MakesValue user,
    MakesValue tid,
    MakesValue update
  ) =>
  user ->
  tid ->
  update ->
  App Response
postServiceWhitelist :: forall user domain otherUser.
(HasCallStack, MakesValue user, MakesValue domain,
 MakesValue otherUser) =>
user -> domain -> otherUser -> App Response
postServiceWhitelist user
user tid
tid update
update = do
  String
tidStr <- tid -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString tid
tid
  Value
updateJson <- update -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make update
update
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Brig Versioned
Versioned (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$
      [String] -> String
joinHttpPath
        [ String
"teams",
          String
tidStr,
          String
"services",
          String
"whitelist"
        ]
  String -> Request -> App Response
submit String
"POST" (Value -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON Value
updateJson Request
req)