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

@@ -144,5 +144,4 @@ angular
.service('nativeExtManager', NativeExtManager) .service('nativeExtManager', NativeExtManager)
.service('preferencesManager', PreferencesManager) .service('preferencesManager', PreferencesManager)
.service('statusManager', StatusManager) .service('statusManager', StatusManager)
.service('storageManager', StorageManager)
.service('themeManager', ThemeManager); .service('themeManager', ThemeManager);

View File

@@ -1,6 +1,6 @@
import { import {
SNApplication, SNApplication,
SNAlertManager, SNAlertService,
Environments, Environments,
platformFromString platformFromString
} from 'snjs'; } from 'snjs';
@@ -20,7 +20,7 @@ export class Application extends SNApplication {
deviceInterface: deviceInterface, deviceInterface: deviceInterface,
swapClasses: [ swapClasses: [
{ {
swap: SNAlertManager, swap: SNAlertService,
with: AlertManager with: AlertManager
} }
] ]

View File

@@ -557,7 +557,7 @@ class EditorCtrl extends PureCtrl {
} }
}); });
}; };
const requiresPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const requiresPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.DeleteNote ProtectedActions.DeleteNote
); );
if (requiresPrivilege) { if (requiresPrivilege) {
@@ -645,7 +645,7 @@ class EditorCtrl extends PureCtrl {
}); });
/** Show privileges manager if protection is not yet set up */ /** Show privileges manager if protection is not yet set up */
this.application.privilegesManager.actionHasPrivilegesConfigured( this.application.privilegesService.actionHasPrivilegesConfigured(
ProtectedActions.ViewProtectedNotes ProtectedActions.ViewProtectedNotes
).then((configured) => { ).then((configured) => {
if (!configured) { if (!configured) {

View File

@@ -338,7 +338,7 @@ class FooterCtrl extends PureCtrl {
}; };
if (!room.showRoom) { if (!room.showRoom) {
const requiresPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const requiresPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ManageExtensions ProtectedActions.ManageExtensions
); );
if (requiresPrivilege) { if (requiresPrivilege) {

View File

@@ -287,7 +287,7 @@ class AccountMenuCtrl extends PureCtrl {
const run = () => { const run = () => {
this.godService.presentPrivilegesManagementModal(); this.godService.presentPrivilegesManagementModal();
}; };
const needsPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const needsPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ManagePrivileges ProtectedActions.ManagePrivileges
); );
if (needsPrivilege) { if (needsPrivilege) {
@@ -364,7 +364,7 @@ class AccountMenuCtrl extends PureCtrl {
await this.performImport(data, null); await this.performImport(data, null);
} }
}; };
const needsPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const needsPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ManageBackups ProtectedActions.ManageBackups
); );
if (needsPrivilege) { if (needsPrivilege) {
@@ -447,7 +447,7 @@ class AccountMenuCtrl extends PureCtrl {
await this.lockManager.setAutoLockInterval(interval); await this.lockManager.setAutoLockInterval(interval);
this.reloadAutoLockInterval(); this.reloadAutoLockInterval();
}; };
const needsPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const needsPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ManagePasscode ProtectedActions.ManagePasscode
); );
if (needsPrivilege) { if (needsPrivilege) {
@@ -493,7 +493,7 @@ class AccountMenuCtrl extends PureCtrl {
this.state.formData.changingPasscode = true; this.state.formData.changingPasscode = true;
this.addPasscodeClicked(); this.addPasscodeClicked();
}; };
const needsPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const needsPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ManagePasscode ProtectedActions.ManagePasscode
); );
if (needsPrivilege) { if (needsPrivilege) {
@@ -521,7 +521,7 @@ class AccountMenuCtrl extends PureCtrl {
} }
}); });
}; };
const needsPrivilege = await this.application.privilegesManager.actionRequiresPrivilege( const needsPrivilege = await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ManagePasscode ProtectedActions.ManagePasscode
); );
if (needsPrivilege) { if (needsPrivilege) {

View File

@@ -14,14 +14,14 @@ class PrivilegesAuthModalCtrl {
$onInit() { $onInit() {
this.authParameters = {}; this.authParameters = {};
this.sessionLengthOptions = this.application.privilegesManager.getSessionLengthOptions(); this.sessionLengthOptions = this.application.privilegesService.getSessionLengthOptions();
this.application.privilegesManager.getSelectedSessionLength() this.application.privilegesService.getSelectedSessionLength()
.then((length) => { .then((length) => {
this.$timeout(() => { this.$timeout(() => {
this.selectedSessionLength = length; this.selectedSessionLength = length;
}); });
}); });
this.application.privilegesManager.netCredentialsForAction(this.action) this.application.privilegesService.netCredentialsForAction(this.action)
.then((credentials) => { .then((credentials) => {
this.$timeout(() => { this.$timeout(() => {
this.requiredCredentials = credentials.sort(); this.requiredCredentials = credentials.sort();
@@ -34,7 +34,7 @@ class PrivilegesAuthModalCtrl {
} }
promptForCredential(credential) { promptForCredential(credential) {
return this.application.privilegesManager.displayInfoForCredential(credential).prompt; return this.application.privilegesService.displayInfoForCredential(credential).prompt;
} }
cancel() { cancel() {
@@ -67,13 +67,13 @@ class PrivilegesAuthModalCtrl {
if (!this.validate()) { if (!this.validate()) {
return; return;
} }
const result = await this.application.privilegesManager.authenticateAction( const result = await this.application.privilegesService.authenticateAction(
this.action, this.action,
this.authParameters this.authParameters
); );
this.$timeout(() => { this.$timeout(() => {
if (result.success) { if (result.success) {
this.application.privilegesManager.setSessionLength(this.selectedSessionLength); this.application.privilegesService.setSessionLength(this.selectedSessionLength);
this.onSuccess(); this.onSuccess();
this.dismiss(); this.dismiss();
} else { } else {

View File

@@ -24,7 +24,7 @@ class PrivilegesManagementModalCtrl extends PureCtrl {
} }
displayInfoForCredential(credential) { displayInfoForCredential(credential) {
const info = this.application.privilegesManager.displayInfoForCredential(credential); const info = this.application.privilegesService.displayInfoForCredential(credential);
if (credential === PrivilegeCredentials.LocalPasscode) { if (credential === PrivilegeCredentials.LocalPasscode) {
info.availability = this.hasPasscode; info.availability = this.hasPasscode;
} else if (credential === PrivilegeCredentials.AccountPassword) { } else if (credential === PrivilegeCredentials.AccountPassword) {
@@ -36,7 +36,7 @@ class PrivilegesManagementModalCtrl extends PureCtrl {
} }
displayInfoForAction(action) { displayInfoForAction(action) {
return this.application.privilegesManager.displayInfoForAction(action).label; return this.application.privilegesService.displayInfoForAction(action).label;
} }
isCredentialRequiredForAction(action, credential) { isCredentialRequiredForAction(action, credential) {
@@ -47,21 +47,21 @@ class PrivilegesManagementModalCtrl extends PureCtrl {
} }
async clearSession() { async clearSession() {
await this.application.privilegesManager.clearSession(); await this.application.privilegesService.clearSession();
this.reloadPrivileges(); this.reloadPrivileges();
} }
async reloadPrivileges() { async reloadPrivileges() {
this.availableActions = this.application.privilegesManager.getAvailableActions(); this.availableActions = this.application.privilegesService.getAvailableActions();
this.availableCredentials = this.application.privilegesManager.getAvailableCredentials(); this.availableCredentials = this.application.privilegesService.getAvailableCredentials();
const sessionEndDate = await this.application.privilegesManager.getSessionExpirey(); const sessionEndDate = await this.application.privilegesService.getSessionExpirey();
this.sessionExpirey = sessionEndDate.toLocaleString(); this.sessionExpirey = sessionEndDate.toLocaleString();
this.sessionExpired = new Date() >= sessionEndDate; this.sessionExpired = new Date() >= sessionEndDate;
this.credentialDisplayInfo = {}; this.credentialDisplayInfo = {};
for (const cred of this.availableCredentials) { for (const cred of this.availableCredentials) {
this.credentialDisplayInfo[cred] = this.displayInfoForCredential(cred); this.credentialDisplayInfo[cred] = this.displayInfoForCredential(cred);
} }
const privs = await this.application.privilegesManager.getPrivileges(); const privs = await this.application.privilegesService.getPrivileges();
this.$timeout(() => { this.$timeout(() => {
this.privileges = privs; this.privileges = privs;
}); });
@@ -69,7 +69,7 @@ class PrivilegesManagementModalCtrl extends PureCtrl {
checkboxValueChanged(action, credential) { checkboxValueChanged(action, credential) {
this.privileges.toggleCredentialForAction(action, credential); this.privileges.toggleCredentialForAction(action, credential);
this.application.privilegesManager.savePrivileges(); this.application.privilegesService.savePrivileges();
} }
cancel() { cancel() {

View File

@@ -1,8 +1,8 @@
/* eslint-disable prefer-promise-reject-errors */ /* eslint-disable prefer-promise-reject-errors */
import { SNAlertManager } from 'snjs'; import { SNAlertService } from 'snjs';
import { SKAlert } from 'sn-stylekit'; import { SKAlert } from 'sn-stylekit';
export class AlertManager extends SNAlertManager { export class AlertManager extends SNAlertService {
async alert({ async alert({
title, title,
text, text,

View File

@@ -36,7 +36,7 @@ export class ArchiveManager {
}); });
}; };
if (await this.application.privilegesManager.actionRequiresPrivilege(ProtectedActions.ManageBackups)) { if (await this.application.privilegesService.actionRequiresPrivilege(ProtectedActions.ManageBackups)) {
this.godService.presentPrivilegesModal(ProtectedActions.ManageBackups, () => { this.godService.presentPrivilegesModal(ProtectedActions.ManageBackups, () => {
run(); run();
}); });
@@ -58,7 +58,7 @@ export class ArchiveManager {
/** @private */ /** @private */
async itemsData(items, intent) { async itemsData(items, intent) {
const data = await this.application.protocolService.createBackupFile({ const data = await this.application.createBackupFile({
subItems: items, subItems: items,
intent: intent intent: intent
}); });

View File

@@ -193,7 +193,7 @@ export class DesktopManager {
} }
async desktop_requestBackupFile(callback) { async desktop_requestBackupFile(callback) {
const data = await this.application.protocolService.createBackupFile({ const data = await this.application.createBackupFile({
returnIfEmpty: true returnIfEmpty: true
}); });
callback(data); callback(data);

View File

@@ -16,7 +16,7 @@ export class GodService {
if (this.application.noAccount()) { if (this.application.noAccount()) {
return false; return false;
} }
const updateAvailable = await this.application.protocolService.upgradeAvailable(); const updateAvailable = await this.application.protocolUpgradeAvailable();
if (updateAvailable !== this.securityUpdateAvailable) { if (updateAvailable !== this.securityUpdateAvailable) {
this.securityUpdateAvailable = updateAvailable; this.securityUpdateAvailable = updateAvailable;
this.$rootScope.$broadcast("security-update-status-changed"); this.$rootScope.$broadcast("security-update-status-changed");

View File

@@ -1,7 +1,7 @@
import { isDesktopApplication, dictToArray } from '@/utils'; import { isDesktopApplication, dictToArray } from '@/utils';
import { import {
ApplicationEvents, ApplicationEvents,
SFPredicate, SNPredicate,
ContentTypes, ContentTypes,
CreateMaxPayloadFromAnyObject CreateMaxPayloadFromAnyObject
} from 'snjs'; } from 'snjs';
@@ -23,17 +23,17 @@ export class NativeExtManager {
get extManagerPred() { get extManagerPred() {
const extManagerId = 'org.standardnotes.extensions-manager'; const extManagerId = 'org.standardnotes.extensions-manager';
return SFPredicate.CompoundPredicate([ return SNPredicate.CompoundPredicate([
new SFPredicate('content_type', '=', ContentTypes.Component), new SNPredicate('content_type', '=', ContentTypes.Component),
new SFPredicate('package_info.identifier', '=', extManagerId) new SNPredicate('package_info.identifier', '=', extManagerId)
]); ]);
} }
get batchManagerPred() { get batchManagerPred() {
const batchMgrId = 'org.standardnotes.batch-manager'; const batchMgrId = 'org.standardnotes.batch-manager';
return SFPredicate.CompoundPredicate([ return SNPredicate.CompoundPredicate([
new SFPredicate('content_type', '=', ContentTypes.Component), new SNPredicate('content_type', '=', ContentTypes.Component),
new SFPredicate('package_info.identifier', '=', batchMgrId) new SNPredicate('package_info.identifier', '=', batchMgrId)
]); ]);
} }

View File

@@ -1,4 +1,4 @@
import { ApplicationEvents, SFPredicate, ContentTypes, CreateMaxPayloadFromAnyObject } from 'snjs'; import { ApplicationEvents, SNPredicate, ContentTypes, CreateMaxPayloadFromAnyObject } from 'snjs';
export const PrefKeys = { export const PrefKeys = {
TagsPanelWidth: 'tagsPanelWidth', TagsPanelWidth: 'tagsPanelWidth',
@@ -42,7 +42,7 @@ export class PreferencesManager {
async loadSingleton() { async loadSingleton() {
const contentType = ContentTypes.UserPrefs; const contentType = ContentTypes.UserPrefs;
const predicate = new SFPredicate('content_type', '=', contentType); const predicate = new SNPredicate('content_type', '=', contentType);
this.userPreferences = await this.application.singletonManager.findOrCreateSingleton({ this.userPreferences = await this.application.singletonManager.findOrCreateSingleton({
predicate: predicate, predicate: predicate,
createPayload: CreateMaxPayloadFromAnyObject({ createPayload: CreateMaxPayloadFromAnyObject({

View File

@@ -120,7 +120,7 @@ export class AppState {
); );
}; };
if (note && note.content.protected && if (note && note.content.protected &&
await this.application.privilegesManager.actionRequiresPrivilege( await this.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ViewProtectedNotes ProtectedActions.ViewProtectedNotes
)) { )) {
this.godService.presentPrivilegesModal( this.godService.presentPrivilegesModal(

View File

@@ -44,7 +44,7 @@ module StandardNotes
block_all_mixed_content: false, # see http://www.w3.org/TR/mixed-content/ block_all_mixed_content: false, # see http://www.w3.org/TR/mixed-content/
child_src: ["*", "blob:"], child_src: ["*", "blob:"],
frame_src: ["*", "blob:"], frame_src: ["*", "blob:"],
connect_src: ["*"], connect_src: ["*", 'data:'],
font_src: %w(* 'self'), font_src: %w(* 'self'),
form_action: %w('self'), form_action: %w('self'),
frame_ancestors: ["*", "*.standardnotes.org"], frame_ancestors: ["*", "*.standardnotes.org"],
@@ -53,7 +53,7 @@ module StandardNotes
media_src: %w('self'), media_src: %w('self'),
object_src: %w('self'), object_src: %w('self'),
plugin_types: %w(), plugin_types: %w(),
script_src: %w('self' 'unsafe-inline'), script_src: %w('self' 'unsafe-inline' 'wasm-eval' 'unsafe-eval'),
style_src: %w(* 'unsafe-inline'), style_src: %w(* 'unsafe-inline'),
upgrade_insecure_requests: false, # see https://www.w3.org/TR/upgrade-insecure-requests/ upgrade_insecure_requests: false, # see https://www.w3.org/TR/upgrade-insecure-requests/
} }

86287
dist/javascripts/app.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2652
dist/stylesheets/app.css vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

15122
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,7 @@
"babel-plugin-angularjs-annotate": "^0.10.0", "babel-plugin-angularjs-annotate": "^0.10.0",
"chai": "^4.2.0", "chai": "^4.2.0",
"connect": "^3.7.0", "connect": "^3.7.0",
"copy-webpack-plugin": "5.0.5",
"css-loader": "^3.4.2", "css-loader": "^3.4.2",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0", "eslint-config-prettier": "^6.10.0",
@@ -47,7 +48,7 @@
"sass-loader": "^8.0.2", "sass-loader": "^8.0.2",
"serve-static": "^1.14.1", "serve-static": "^1.14.1",
"sn-stylekit": "2.0.20", "sn-stylekit": "2.0.20",
"snjs": "file:~/Desktop/sn/dev/snjs", "snjs": "github:standardnotes/snjs#b9d7b7939a8f123798e553ab705916e5251b0981",
"webpack": "^4.41.5", "webpack": "^4.41.5",
"webpack-cli": "^3.3.10" "webpack-cli": "^3.3.10"
}, },

2
public/dist/libsodium.bundle.js vendored Normal file
View File

@@ -0,0 +1,2 @@
(window.webpackJsonpSNCrypto=window.webpackJsonpSNCrypto||[]).push([[0],{123:function(t,c){},124:function(t,c){},166:function(t,c,n){"use strict";n.r(c);var o=n(18);n.d(c,"ready",(function(){return o.ready})),n.d(c,"crypto_pwhash",(function(){return o.crypto_pwhash})),n.d(c,"crypto_pwhash_ALG_DEFAULT",(function(){return o.crypto_pwhash_ALG_DEFAULT})),n.d(c,"crypto_aead_xchacha20poly1305_ietf_encrypt",(function(){return o.crypto_aead_xchacha20poly1305_ietf_encrypt})),n.d(c,"crypto_aead_xchacha20poly1305_ietf_decrypt",(function(){return o.crypto_aead_xchacha20poly1305_ietf_decrypt}))},48:function(t,c){},88:function(t,c){},90:function(t,c){}}]);
//# sourceMappingURL=libsodium.bundle.js.map

File diff suppressed because one or more lines are too long

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

View File

@@ -1,7 +1,7 @@
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = { module.exports = {
entry: './app/assets/javascripts/index.js', entry: './app/assets/javascripts/index.js',
output: { output: {
@@ -11,6 +11,10 @@ module.exports = {
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__VERSION__: JSON.stringify(require('./package.json').version) __VERSION__: JSON.stringify(require('./package.json').version)
}), }),
new CopyPlugin([
{ from: 'node_modules/snjs/dist/libsodium.bundle.js', to: '../public/dist/libsodium.bundle.js' },
{ from: 'node_modules/snjs/dist/vendors~libsodium.bundle.js', to: '../public/dist/vendors~libsodium.bundle.js' },
]),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output // Options similar to the same options in webpackOptions.output
filename: './stylesheets/app.css', filename: './stylesheets/app.css',