on master help sign in
It initializes
c177ad1iko
backend/Main.purs+11
@@ -4,6 +4,7 @@ import Prelude
4
4
5import BW as WB
5import BW as WB
6import Bridge (Sub(..))
6import Bridge (Sub(..))
7+import Data.Nullable (null)
7import Effect (Effect)
8import Effect (Effect)
8import Effect.Console (log)
9import Effect.Console (log)
9import Elm as Elm
10import Elm as Elm
@@ -13,6 +14,16 @@ import FFI as FFI
13main :: Effect Unit
14main :: Effect Unit
14main = do
15main = do
15 bwAPI <- WB.getAPI
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+
16 app <- FFI.startElm "elm"
27 app <- FFI.startElm "elm"
17 Elm.subscribe app \c -> log $ "Got cmd"
28 Elm.subscribe app \c -> log $ "Got cmd"
18 Elm.send app Hello
29 Elm.send app Hello
bw/src/BW.js+14−67
@@ -7,16 +7,19 @@ import { EnvironmentService } from "../../deps/bw/libs/shared/dist/src/services/
7import { StateMigrationService } from "../../deps/bw/libs/shared/dist/src/services/stateMigration.service";
7import { StateMigrationService } from "../../deps/bw/libs/shared/dist/src/services/stateMigration.service";
8import { TokenService } from "../../deps/bw/libs/shared/dist/src/services/token.service";
8import { TokenService } from "../../deps/bw/libs/shared/dist/src/services/token.service";
9import { WebCryptoFunctionService } from "../../deps/bw/libs/shared/dist/src/services/webCryptoFunction.service";
9import { WebCryptoFunctionService } from "../../deps/bw/libs/shared/dist/src/services/webCryptoFunction.service";
10+import { Account, AccountSettings } from "../../deps/bw/libs/shared/dist/src/models/domain/account";
10
11
11// import BrowserStorageService from "../../deps/bw/libs/shared/dist/src/services/browserStorage.service";
12// import BrowserStorageService from "../../deps/bw/libs/shared/dist/src/services/browserStorage.service";
12import { CryptoService } from "../../deps/bw/libs/shared/dist/src/abstractions/crypto.service";
13import { CryptoService } from "../../deps/bw/libs/shared/dist/src/abstractions/crypto.service";
13import { I18nService } from "../../deps/bw/libs/shared/dist/src/services/i18n.service";
14import { I18nService } from "../../deps/bw/libs/shared/dist/src/services/i18n.service";
14import { StateService } from "../../deps/bw/libs/shared/dist/src/services/state.service";
15import { StateService } from "../../deps/bw/libs/shared/dist/src/services/state.service";
15
16
16−export function getAPI() {
17+export function getAPI(urls) {
17 return function () {
18 return function () {
18 const bg = new MainBackground()
19 const bg = new MainBackground()
19
20
21+ bg.environmentService.setUrls(urls)
22+
20 return bg.apiService
23 return bg.apiService
21 }
24 }
22}
25}
@@ -38,11 +41,9 @@ class MainBackground {
38 stateMigrationService; //: StateMigrationService;
41 stateMigrationService; //: StateMigrationService;
39
42
40
43
41− constructor(isPrivateMode = false) {
44+ constructor() {
42
45
43− this.messagingService = isPrivateMode
44− ? new BrowserMessagingPrivateModeBackgroundService()
45− : new BrowserMessagingService();
46+ this.messagingService = new BrowserMessagingService();
46 this.storageService = new BrowserStorageService();
47 this.storageService = new BrowserStorageService();
47 this.logService = new ConsoleLogService(false);
48 this.logService = new ConsoleLogService(false);
48 this.stateMigrationService = new StateMigrationService(
49 this.stateMigrationService = new StateMigrationService(
@@ -79,7 +80,7 @@ class MainBackground {
79 }
80 }
80 }
81 }
81 );
82 );
82− this.i18nService = new I18nService(BrowserApi.getUILanguage(window));
83+ this.i18nService = new I18nService("en");
83 this.cryptoFunctionService = new WebCryptoFunctionService(window);
84 this.cryptoFunctionService = new WebCryptoFunctionService(window);
84 this.cryptoService = new BrowserCryptoService(
85 this.cryptoService = new BrowserCryptoService(
85 this.cryptoFunctionService,
86 this.cryptoFunctionService,
@@ -135,7 +136,7 @@ class BrowserStorageService {
135 }
136 }
136
137
137 async get(key) {
138 async get(key) {
138− return resolve(JSON.parse(this.storage.getItem(key)));
139+ return JSON.parse(this.storage.getItem(key));
139 }
140 }
140
141
141 async has(key) {
142 async has(key) {
@@ -175,13 +176,6 @@ class BrowserMessagingService {
175 }
176 }
176}
177}
177
178
178−class BrowserMessagingPrivateModeBackgroundService {
179− send(subscriber, arg = {}) {
180− const message = Object.assign({}, { command: subscriber }, arg);
181− window.bitwardenPopupMainMessageListener(message);
182− }
183−}
184−
185class BrowserPlatformUtilsService {
179class BrowserPlatformUtilsService {
186 constructor(messagingService, stateService, clipboardWriteCallback, biometricCallback) {
180 constructor(messagingService, stateService, clipboardWriteCallback, biometricCallback) {
187 this.messagingService = messagingService;
181 this.messagingService = messagingService;
@@ -194,31 +188,7 @@ class BrowserPlatformUtilsService {
194 this.prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
188 this.prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
195 }
189 }
196 getDevice() {
190 getDevice() {
197− if (this.deviceCache) {
191+ return 9; // Chrome
198− return this.deviceCache;
199− }
200− if (navigator.userAgent.indexOf(" Firefox/") !== -1 ||
201− navigator.userAgent.indexOf(" Gecko/") !== -1) {
202− this.deviceCache = DeviceType.FirefoxExtension;
203− }
204− else if ((!!window.opr && !!opr.addons) ||
205− !!window.opera ||
206− navigator.userAgent.indexOf(" OPR/") >= 0) {
207− this.deviceCache = DeviceType.OperaExtension;
208− }
209− else if (navigator.userAgent.indexOf(" Edg/") !== -1) {
210− this.deviceCache = DeviceType.EdgeExtension;
211− }
212− else if (navigator.userAgent.indexOf(" Vivaldi/") !== -1) {
213− this.deviceCache = DeviceType.VivaldiExtension;
214− }
215− else if (window.chrome && navigator.userAgent.indexOf(" Chrome/") !== -1) {
216− this.deviceCache = DeviceType.ChromeExtension;
217− }
218− else if (navigator.userAgent.indexOf(" Safari/") !== -1) {
219− this.deviceCache = DeviceType.SafariExtension;
220− }
221− return this.deviceCache;
222 }
192 }
223 getDeviceString() {
193 getDeviceString() {
224 const device = DeviceType[this.getDevice()].toLowerCase();
194 const device = DeviceType[this.getDevice()].toLowerCase();
@@ -252,33 +222,19 @@ class BrowserPlatformUtilsService {
252 return false;
222 return false;
253 }
223 }
254 isViewOpen() {
224 isViewOpen() {
255− return __awaiter(this, void 0, void 0, function* () {
256− if (yield BrowserApi.isPopupOpen()) {
257− return true;
225+ return true;
258− }
259− if (this.isSafari()) {
260− return false;
261− }
262− const sidebarView = this.sidebarViewName();
263− const sidebarOpen = sidebarView != null && chrome.extension.getViews({ type: sidebarView }).length > 0;
264− if (sidebarOpen) {
265− return true;
266− }
267− const tabOpen = chrome.extension.getViews({ type: "tab" }).length > 0;
268− return tabOpen;
269− });
270 }
226 }
271 lockTimeout() {
227 lockTimeout() {
272 return null;
228 return null;
273 }
229 }
274 launchUri(uri, options) {
230 launchUri(uri, options) {
275− BrowserApi.createNewTab(uri, options && options.extensionPage === true);
231+ // BrowserApi.createNewTab(uri, options && options.extensionPage === true);
276 }
232 }
277 saveFile(win, blobData, blobOptions, fileName) {
233 saveFile(win, blobData, blobOptions, fileName) {
278− BrowserApi.downloadFile(win, blobData, blobOptions, fileName);
234+ // BrowserApi.downloadFile(win, blobData, blobOptions, fileName);
279 }
235 }
280 getApplicationVersion() {
236 getApplicationVersion() {
281− return Promise.resolve(BrowserApi.getApplicationVersion());
237+ // return Promise.resolve(BrowserApi.getApplicationVersion());
282 }
238 }
283 supportsWebAuthn(win) {
239 supportsWebAuthn(win) {
284 return typeof PublicKeyCredential !== "undefined";
240 return typeof PublicKeyCredential !== "undefined";
@@ -452,16 +408,7 @@ class BrowserPlatformUtilsService {
452 });
408 });
453 }
409 }
454 supportsBiometric() {
410 supportsBiometric() {
455− return __awaiter(this, void 0, void 0, function* () {
456− const platformInfo = yield BrowserApi.getPlatformInfo();
457− if (platformInfo.os === "android") {
458− return false;
411+ return false;
459− }
460− if (this.isFirefox()) {
461− return parseInt((yield browser.runtime.getBrowserInfo()).version.split(".")[0], 10) >= 87;
462− }
463− return true;
464− });
465 }
412 }
466 authenticateBiometric() {
413 authenticateBiometric() {
467 return this.biometricCallback();
414 return this.biometricCallback();
bw/src/BW.purs+13−1
@@ -6,6 +6,7 @@ import Control.Promise (Promise)
6import Data.Argonaut.Core (Json)
6import Data.Argonaut.Core (Json)
7import Data.Date (Date)
7import Data.Date (Date)
8import Data.List (List)
8import Data.List (List)
9+import Data.Nullable (Nullable)
9import Effect (Effect)
10import Effect (Effect)
10
11
11type PreloginResponse = {
12type PreloginResponse = {
@@ -137,9 +138,20 @@ type ProviderUserType = Int
137
138
138type ProfileProviderOrganizationResponse = {}
139type ProfileProviderOrganizationResponse = {}
139
140
141+type Urls = {
142+ base :: Nullable String,
143+ webVault :: Nullable String,
144+ api :: Nullable String,
145+ identity :: Nullable String,
146+ icons :: Nullable String,
147+ notifications :: Nullable String,
148+ events :: Nullable String,
149+ keyConnector :: Nullable String
150+}
151+
140type ApiService = {
152type ApiService = {
141 postPrelogin :: PreloginRequest -> Promise PreloginResponse,
153 postPrelogin :: PreloginRequest -> Promise PreloginResponse,
142 getProfile :: Unit -> Promise ProfileResponse
154 getProfile :: Unit -> Promise ProfileResponse
143 }
155 }
144
156
145−foreign import getAPI :: Effect ApiService
157+foreign import getAPI :: Urls -> Effect ApiService
spago.dhall+1
@@ -23,6 +23,7 @@ to generate this file without the comments in this block.
23 , "either"
23 , "either"
24 , "maybe"
24 , "maybe"
25 , "newtype"
25 , "newtype"
26+ , "nullable"
26 , "prelude"
27 , "prelude"
27 ]
28 ]
28, packages = ./packages.dhall
29, packages = ./packages.dhall