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('preferencesManager', PreferencesManager)
.service('statusManager', StatusManager)
.service('storageManager', StorageManager)
.service('themeManager', ThemeManager);

View File

@@ -1,6 +1,6 @@
import {
SNApplication,
SNAlertManager,
SNAlertService,
Environments,
platformFromString
} from 'snjs';
@@ -20,7 +20,7 @@ export class Application extends SNApplication {
deviceInterface: deviceInterface,
swapClasses: [
{
swap: SNAlertManager,
swap: SNAlertService,
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
);
if (requiresPrivilege) {
@@ -645,7 +645,7 @@ class EditorCtrl extends PureCtrl {
});
/** Show privileges manager if protection is not yet set up */
this.application.privilegesManager.actionHasPrivilegesConfigured(
this.application.privilegesService.actionHasPrivilegesConfigured(
ProtectedActions.ViewProtectedNotes
).then((configured) => {
if (!configured) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,8 +1,8 @@
/* eslint-disable prefer-promise-reject-errors */
import { SNAlertManager } from 'snjs';
import { SNAlertService } from 'snjs';
import { SKAlert } from 'sn-stylekit';
export class AlertManager extends SNAlertManager {
export class AlertManager extends SNAlertService {
async alert({
title,
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, () => {
run();
});
@@ -58,7 +58,7 @@ export class ArchiveManager {
/** @private */
async itemsData(items, intent) {
const data = await this.application.protocolService.createBackupFile({
const data = await this.application.createBackupFile({
subItems: items,
intent: intent
});

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
import { isDesktopApplication, dictToArray } from '@/utils';
import {
ApplicationEvents,
SFPredicate,
SNPredicate,
ContentTypes,
CreateMaxPayloadFromAnyObject
} from 'snjs';
@@ -23,17 +23,17 @@ export class NativeExtManager {
get extManagerPred() {
const extManagerId = 'org.standardnotes.extensions-manager';
return SFPredicate.CompoundPredicate([
new SFPredicate('content_type', '=', ContentTypes.Component),
new SFPredicate('package_info.identifier', '=', extManagerId)
return SNPredicate.CompoundPredicate([
new SNPredicate('content_type', '=', ContentTypes.Component),
new SNPredicate('package_info.identifier', '=', extManagerId)
]);
}
get batchManagerPred() {
const batchMgrId = 'org.standardnotes.batch-manager';
return SFPredicate.CompoundPredicate([
new SFPredicate('content_type', '=', ContentTypes.Component),
new SFPredicate('package_info.identifier', '=', batchMgrId)
return SNPredicate.CompoundPredicate([
new SNPredicate('content_type', '=', ContentTypes.Component),
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 = {
TagsPanelWidth: 'tagsPanelWidth',
@@ -42,7 +42,7 @@ export class PreferencesManager {
async loadSingleton() {
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({
predicate: predicate,
createPayload: CreateMaxPayloadFromAnyObject({

View File

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

View File

@@ -44,7 +44,7 @@ module StandardNotes
block_all_mixed_content: false, # see http://www.w3.org/TR/mixed-content/
child_src: ["*", "blob:"],
frame_src: ["*", "blob:"],
connect_src: ["*"],
connect_src: ["*", 'data:'],
font_src: %w(* 'self'),
form_action: %w('self'),
frame_ancestors: ["*", "*.standardnotes.org"],
@@ -53,7 +53,7 @@ module StandardNotes
media_src: %w('self'),
object_src: %w('self'),
plugin_types: %w(),
script_src: %w('self' 'unsafe-inline'),
script_src: %w('self' 'unsafe-inline' 'wasm-eval' 'unsafe-eval'),
style_src: %w(* 'unsafe-inline'),
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",
"chai": "^4.2.0",
"connect": "^3.7.0",
"copy-webpack-plugin": "5.0.5",
"css-loader": "^3.4.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
@@ -47,7 +48,7 @@
"sass-loader": "^8.0.2",
"serve-static": "^1.14.1",
"sn-stylekit": "2.0.20",
"snjs": "file:~/Desktop/sn/dev/snjs",
"snjs": "github:standardnotes/snjs#b9d7b7939a8f123798e553ab705916e5251b0981",
"webpack": "^4.41.5",
"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="../dist/javascripts/app.js"></script>
<script>mocha.setup('bdd')</script>
<!-- <script type="module" src="models.test.js"></script> -->
<script>
// Object.assign(window, SNLibrary);

View File

@@ -1,7 +1,7 @@
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = {
entry: './app/assets/javascripts/index.js',
output: {
@@ -11,6 +11,10 @@ module.exports = {
new webpack.DefinePlugin({
__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({
// Options similar to the same options in webpackOptions.output
filename: './stylesheets/app.css',