Update with latest SNJS changes

This commit is contained in:
Mo Bitar
2020-03-01 16:12:29 -06:00
parent fc88ab9b2b
commit 444c18bbde
27 changed files with 192 additions and 104131 deletions

View File

@@ -1,90 +0,0 @@
import '../../../dist/javascripts/app.js';
import '../../../node_modules/chai/chai.js';
import '../vendor/chai-as-promised-built.js';
import LocalStorageManager from './localStorageManager.js';
const sf_default = new SNProtocolManager();
SFItem.AppDomain = "org.standardnotes.sn";
var _globalStorageManager = null;
var _globalHttpManager = null;
var _globalAuthManager = null;
var _globalModelManager = null;
var _globalCryptoManager = null;
export default class Factory {
static initialize() {
this.globalStorageManager();
this.globalHttpManager();
this.globalAuthManager();
this.globalModelManager();
}
static globalStorageManager() {
if(_globalStorageManager == null) { _globalStorageManager = new LocalStorageManager(); }
return _globalStorageManager;
}
static globalHttpManager() {
if(_globalHttpManager == null) {
_globalHttpManager = new SFHttpManager();
_globalHttpManager.setJWTRequestHandler(async () => {
return this.globalStorageManager().getItem("jwt");;
})
}
return _globalHttpManager;
}
static globalAuthManager() {
if(_globalAuthManager == null) { _globalAuthManager = new SFAuthManager(_globalStorageManager, _globalHttpManager); }
return _globalAuthManager;
}
static globalModelManager() {
if(_globalModelManager == null) { _globalModelManager = new SFModelManager(); }
return _globalModelManager;
}
static globalCryptoManager() {
if(_globalCryptoManager == null) { _globalCryptoManager = new SNProtocolManager(); }
return _globalCryptoManager;
}
static createModelManager() {
return new SFModelManager();
}
static yesterday() {
return new Date(new Date().setDate(new Date().getDate() - 1));
}
static createItemParams() {
var params = {
uuid: protocolManager.crypto.generateUUIDSync(),
content_type: "Note",
content: {
title: "hello",
text: "world"
}
};
return params;
}
static createItem() {
return new SFItem(this.createItemParams());
}
static serverURL() {
return "http://localhost:3000";
}
static async newRegisteredUser(email, password) {
let url = this.serverURL();
if(!email) email = sf_default.crypto.generateUUIDSync();
if(!password) password = sf_default.crypto.generateUUIDSync();
return this.globalAuthManager().register(url, email, password, false);
}
}
Factory.initialize();

View File

@@ -1,69 +0,0 @@
// A test StorageManager class using LocalStorage
export default class LocalStorageManager extends SFStorageManager {
/* Simple Key/Value Storage */
async setItem(key, value, vaultKey) {
localStorage.setItem(key, value);
}
async getItem(key, vault) {
return localStorage.getItem(key)
}
async removeItem(key, vault) {
localStorage.removeItem(key);
}
async clear() {
// clear only simple key/values
localStorage.clear();
}
/*
Model Storage
*/
async getAllModels() {
var models = [];
for(var key in localStorage) {
if(key.startsWith("item-")) {
models.push(JSON.parse(localStorage[key]))
}
}
return models;
}
async saveModel(item) {
return this.saveModels([item]);
}
async saveModels(items) {
return Promise.all(items.map((item) => {
return this.setItem(`item-${item.uuid}`, JSON.stringify(item));
}))
}
async deleteModel(item,) {
return this.removeItem(`item-${item.uuid}`);
}
async clearAllModels() {
// clear only models
for(var key in localStorage) {
if(key.startsWith("item-")) {
this.removeItem(key);
}
}
}
/* General */
clearAllData() {
return Promise.all([
this.clear(),
this.clearAllModels()
])
}
}

View File

@@ -15,7 +15,6 @@
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../dist/javascripts/app.js"></script>
<script>mocha.setup('bdd')</script>
<!-- <script type="module" src="models.test.js"></script> -->
<script>
// Object.assign(window, SNLibrary);