web/packages/snjs
StandardNotes CI 6c73885d1f
chore(release): publish
- @standardnotes/api@1.24.2
 - @standardnotes/desktop@3.104.95
 - @standardnotes/encryption@1.21.2
 - @standardnotes/features@1.58.2
 - @standardnotes/filepicker@1.28.7
 - @standardnotes/files@1.14.17
 - @standardnotes/mobile@3.50.31
 - @standardnotes/models@1.42.4
 - @standardnotes/releases@1.4.118
 - @standardnotes/responses@1.13.2
 - @standardnotes/services@1.56.2
 - @standardnotes/snjs@2.164.2
 - @standardnotes/ui-services@1.24.6
 - @standardnotes/web@3.140.2
2023-01-19 23:32:24 +00:00
..
lib refactor: remove Uuid and RoleName from @standardnotes/common in favour of @standardnotes/domain-core value objects (#2167) 2023-01-19 16:17:59 +01:00
mocha fix(snjs): history revisions specs 2023-01-18 12:41:57 +01:00
.browserslistrc feat: add snjs package 2022-07-06 14:04:30 +02:00
.eslintrc.js chore: fix eslint crashing issues (#1951) 2022-11-04 17:09:54 -05:00
.gitignore feat: add building of SNJS Docker image for e2e testing purposes (#1225) 2022-07-08 11:36:12 +02:00
babel.config.js feat: add snjs package 2022-07-06 14:04:30 +02:00
CHANGELOG.md chore(release): publish 2023-01-19 23:32:24 +00:00
Dockerfile feat: add building of SNJS Docker image for e2e testing purposes (#1225) 2022-07-08 11:36:12 +02:00
e2e-server.js feat: add building of SNJS Docker image for e2e testing purposes (#1225) 2022-07-08 11:36:12 +02:00
jest-global.ts feat: add snjs package 2022-07-06 14:04:30 +02:00
jest.config.js chore: remove tsc build from local workspaces (#2020) 2022-11-16 18:13:28 -06:00
linter.tsconfig.json chore: fix snjs lint job; devDep structure 2022-07-06 08:39:43 -05:00
package.json chore(release): publish 2023-01-19 23:32:24 +00:00
README.md refactor: optimize delay between batches on mobile to allow UI interactivity during load (#2129) 2023-01-04 13:31:45 -06:00
specification.md feat: add snjs package 2022-07-06 14:04:30 +02:00
webpack.config.js feat: add snjs package 2022-07-06 14:04:30 +02:00
webpack.dev.js feat: add snjs package 2022-07-06 14:04:30 +02:00
webpack.prod.js feat: add snjs package 2022-07-06 14:04:30 +02:00

SNJS

SNJS is a client-side JavaScript library for Standard Notes that contains shared logic for all Standard Notes clients.

Introduction

SNJS is a shared library for use in all Standard Notes clients (desktop, web, and mobile). Its role is to extract any business or data logic from client code, so that clients are mostly responsible for UI-level code, and dont have to think about encryption and key management, or even authentication or storage specifics. Extracting the code into a shared library also prevents us from having to write the same critical code on multiple platforms.

The entry point of SNJS is the SNApplication class. The application class is a complete unit of application functionality. Theoretically, many instances of an application can be created, each with its own storage namespace and memory state. This can allow clients to support multiple user accounts.

An application must be supplied a custom subclass of DeviceInterface. This allows the library to generalize all behavior a client will need to perform throughout normal client operation, such as saving data to a local database store, saving key/values, and accessing the keychain.

On Web platforms SNJS interacts with sncrypto to perform operations as mentioned in the specification document. This includes operations like key generation and data encryption.

SNJS also interacts with a Standard Notes syncing server, which is a zero-knowledge data and sync store that deals with encrypted data, and never learns of client secrets or sensitive information.

Installation

yarn add snjs

Integrating in module environment

import { SNApplication } from 'snjs';

Integrating in non-module web environment

<script src="snjs.js"></script>
Object.assign(window, SNLibrary);

Building

  1. yarn install --pure-lockfile
  2. yarn start to start Webpack in development mode (watches changes), or yarn build to create dist files.

Tests

E2E Tests

To run a stable server environment for E2E tests that is up to date with production, clone the self-hosted repository, then run:

In self-hosted repo:

yarn && yarn start

Wait for the All services are up! message.

Once the server infrastructure is ready, and you've built all packages, you can run the test suite in the browser via:

In app repo:

yarn e2e

Once you are finished you can close the running local server on E2E repo by typing:

yarn stop:local-server

Unit Tests

From the root of the repository, run:

yarn run test