on master help sign in
Prelogin works
commit1a5f0c18bd38995a38b8ef301183c24994344c1d authoriko <ilyakooo0@gmail.com> dateSat 23 Jul 2022, 18:29 (4 years ago) parent668b511
4 files changed+102−89
backend/Main.purs+26−14 bw/src/BW.js+2−2 bw/src/BW.purs+73−73 spago.dhall+1
backend/Main.purs+26−14
@@ -4,29 +4,41 @@ import Prelude
44
55import BW as WB
66import Bridge (Sub(..))
7−import Data.Nullable (null)
7+import Bridge as Bridge
8+import Control.Promise (toAff)
9+import Data.Argonaut as A
10+import Data.Either (Either(..))
11+import Data.Maybe (Maybe(..))
12+import Data.Nullable (null, toNullable)
813import Effect (Effect)
14+import Effect.Aff (joinFiber, runAff, runAff_)
915import Effect.Console (log)
1016import Elm as Elm
1117import FFI as FFI
18+import Foreign as F
1219
1320
1421main :: Effect Unit
1522main = do
16− bwAPI <- WB.getAPI
17− { base : null,
18− webVault : null,
19− api : null,
20− identity : null,
21− icons : null,
22− notifications : null,
23− events : null,
24− keyConnector : null
25− }
26−
2723 app <- FFI.startElm "elm"
28− Elm.subscribe app \c -> log $ "Got cmd"
29− Elm.send app Hello
24+ Elm.subscribe app \(Bridge.Login (Bridge.Cmd_Login {email, server})) -> do
25+ log $ "Got cmd"
26+ bwAPI <- WB.getAPI
27+ { base : toNullable $ Just server,
28+ webVault : null,
29+ api : null,
30+ identity : null,
31+ icons : null,
32+ notifications : null,
33+ events : null,
34+ keyConnector : null
35+ }
36+ runAff_ (\res -> case res of
37+ Left _ -> log "Error"
38+ Right x -> log $ show x
39+ ) $ toAff $ bwAPI.postPrelogin {email}
40+ pure unit
3041
42+ Elm.send app Hello
3143
3244 log "🍝"
bw/src/BW.js+2−2
@@ -195,7 +195,7 @@ class BrowserPlatformUtilsService {
195195 return device.replace("extension", "");
196196 }
197197 getClientType() {
198− return ClientType.Browser;
198+ return "browser";
199199 }
200200 isFirefox() {
201201 return this.getDevice() === DeviceType.FirefoxExtension;
@@ -266,7 +266,7 @@ class BrowserPlatformUtilsService {
266266 });
267267 }
268268 isDev() {
269− return process.env.ENV === "development";
269+ return false;
270270 }
271271 isSelfHost() {
272272 return false;
bw/src/BW.purs+73−73
@@ -9,8 +9,8 @@ import Data.Nullable (Nullable)
99import Effect (Effect)
1010
1111type PreloginResponse = {
12− "Kdf" :: Int, -- seems to be always PBKDF2_SHA256
13− "KdfIterations" :: Int
12+ kdf :: Int, -- seems to be always PBKDF2_SHA256
13+ kdfIterations :: Int
1414}
1515
1616type PreloginRequest = {
@@ -18,63 +18,63 @@ type PreloginRequest = {
1818}
1919
2020type ProfileResponse = {
21− "Id" :: String,
22− "Name" :: String,
23− "Email" :: String,
24− "EmailVerified" :: Boolean,
25− "MasterPasswordHint" :: String,
26− "Premium" :: Boolean,
27− "PremiumFromOrganization" :: Boolean,
28− "Culture" :: String,
29− "TwoFactorEnabled" :: Boolean,
30− "Key" :: String,
31− "PrivateKey" :: String,
32− "SecurityStamp" :: String,
33− "ForcePasswordReset" :: Boolean,
34− "UsesKeyConnector" :: Boolean,
35− "Organizations" :: List ProfileOrganizationResponse,
36− "Providers" :: List ProfileProviderResponse,
37− "ProviderOrganizations" :: List ProfileProviderOrganizationResponse
21+ id :: String,
22+ name :: String,
23+ email :: String,
24+ emailVerified :: Boolean,
25+ masterPasswordHint :: String,
26+ premiumPersonally :: Boolean,
27+ premiumFromOrganization :: Boolean,
28+ culture :: String,
29+ twoFactorEnabled :: Boolean,
30+ key :: String,
31+ privateKey :: String,
32+ securityStamp :: String,
33+ forcePasswordReset :: Boolean,
34+ usesKeyConnector :: Boolean,
35+ organizations :: List ProfileOrganizationResponse,
36+ providers :: List ProfileProviderResponse,
37+ providerOrganizations :: List ProfileProviderOrganizationResponse
3838}
3939
4040type ProfileOrganizationResponse = {
41− "Id" :: String,
42− "Name" :: String,
43− "UsePolicies" :: Boolean,
44− "UseGroups" :: Boolean,
45− "UseDirectory" :: Boolean,
46− "UseEvents" :: Boolean,
47− "UseTotp" :: Boolean,
48− "Use2fa" :: Boolean,
49− "UseApi" :: Boolean,
50− "UseSso" :: Boolean,
51− "UseKeyConnector" :: Boolean,
52− "UseResetPassword" :: Boolean,
53− "SelfHost" :: Boolean,
54− "UsersGetPremium" :: Boolean,
55− "Seats" :: Int,
56− "MaxCollections" :: Int,
57− "MaxStorageGb" :: Nullable Int,
58− "Key" :: String,
59− "HasPublicAndPrivateKeys" :: Boolean,
60− "Status" :: OrganizationUserStatusType,
61− "Type" :: OrganizationUserType,
62− "Enabled" :: Boolean,
63− "SsoBound" :: Boolean,
64− "Identifier" :: String,
65− "permissions" :: PermissionsApi,
66− "ResetPasswordEnrolled" :: Boolean,
67− "UserId" :: String,
68− "ProviderId" :: String,
69− "ProviderName" :: String,
70− "FamilySponsorshipFriendlyName" :: String,
71− "FamilySponsorshipAvailable" :: Boolean,
72− "PlanProductType" :: ProductType,
73− "KeyConnectorEnabled" :: Boolean,
74− "KeyConnectorUrl" :: String,
75− "FamilySponsorshipLastSyncDate" :: Nullable Date,
76− "FamilySponsorshipValidUntil" :: Nullable Date,
77− "FamilySponsorshipToDelete" :: Nullable Boolean
41+ id :: String,
42+ name :: String,
43+ usePolicies :: Boolean,
44+ useGroups :: Boolean,
45+ useDirectory :: Boolean,
46+ useEvents :: Boolean,
47+ useTotp :: Boolean,
48+ use2fa :: Boolean,
49+ useApi :: Boolean,
50+ useSso :: Boolean,
51+ useKeyConnector :: Boolean,
52+ useResetPassword :: Boolean,
53+ selfHost :: Boolean,
54+ usersGetPremium :: Boolean,
55+ seats :: Int,
56+ maxCollections :: Int,
57+ maxStorageGb :: Nullable Int,
58+ key :: String,
59+ hasPublicAndPrivateKeys :: Boolean,
60+ status :: OrganizationUserStatusType,
61+ type :: OrganizationUserType,
62+ enabled :: Boolean,
63+ ssoBound :: Boolean,
64+ identifier :: String,
65+ permissions :: PermissionsApi,
66+ resetPasswordEnrolled :: Boolean,
67+ userId :: String,
68+ providerId :: String,
69+ providerName :: String,
70+ familySponsorshipFriendlyName :: String,
71+ familySponsorshipAvailable :: Boolean,
72+ planProductType :: ProductType,
73+ keyConnectorEnabled :: Boolean,
74+ keyConnectorUrl :: String,
75+ familySponsorshipLastSyncDate :: Nullable Date,
76+ familySponsorshipValidUntil :: Nullable Date,
77+ familySponsorshipToDelete :: Nullable Boolean
7878 }
7979
8080organizationUserStatusTypeInvited = 0 :: OrganizationUserStatusType
@@ -90,22 +90,22 @@ organizationUserTypeCustom = 4 :: OrganizationUserType
9090type OrganizationUserType = Int
9191
9292type PermissionsApi = {
93− "AccessEventLogs" :: Boolean,
94− "AccessImportExport" :: Boolean,
95− "AccessReports" :: Boolean,
96− "ManageAllCollections" :: Boolean,
97− "ManageAssignedCollections" :: Boolean,
98− "CreateNewCollections" :: Boolean,
99− "EditAnyCollection" :: Boolean,
100− "DeleteAnyCollection" :: Boolean,
101− "EditAssignedCollections" :: Boolean,
102− "DeleteAssignedCollections" :: Boolean,
103− "ManageCiphers" :: Boolean,
104− "ManageGroups" :: Boolean,
105− "ManageSso" :: Boolean,
106− "ManagePolicies" :: Boolean,
107− "ManageUsers" :: Boolean,
108− "ManageResetPassword" :: Boolean
93+ accessEventLogs :: Boolean,
94+ accessImportExport :: Boolean,
95+ accessReports :: Boolean,
96+ manageAllCollections :: Boolean,
97+ createNewCollections :: Boolean,
98+ editAnyCollection :: Boolean,
99+ deleteAnyCollection :: Boolean,
100+ manageAssignedCollections :: Boolean,
101+ editAssignedCollections :: Boolean,
102+ deleteAssignedCollections :: Boolean,
103+ manageCiphers :: Boolean,
104+ manageGroups :: Boolean,
105+ manageSso :: Boolean,
106+ managePolicies :: Boolean,
107+ manageUsers :: Boolean,
108+ manageResetPassword :: Boolean
109109}
110110
111111productTypeFree = 0 :: ProductType
@@ -151,6 +151,6 @@ type Urls = {
151151type ApiService = {
152152 postPrelogin :: PreloginRequest -> Promise PreloginResponse,
153153 getProfile :: Unit -> Promise ProfileResponse
154− }
154+}
155155
156156foreign import getAPI :: Urls -> Effect ApiService
spago.dhall+1
@@ -21,6 +21,7 @@ to generate this file without the comments in this block.
2121 , "console"
2222 , "effect"
2323 , "either"
24+ , "foreign"
2425 , "maybe"
2526 , "newtype"
2627 , "nullable"