-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from MacFJA/update
Storage creation name + encrypted storage + serializer
- Loading branch information
Showing
25 changed files
with
6,352 additions
and
4,494 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
name: Storage that can update themselves | ||
order: 3 | ||
--- | ||
# Storage that can update themselves | ||
|
||
The **createSessionStorage** and **createLocalStorage** are able to listen changes made externally to the current Window. | ||
|
||
_**NOTE:** Change that are made from another browser window (browser tab) from the same website domain and same browser **ONLY**. | ||
Change made inside the same application instance (i.e. in another page of an SPA) are NOT considered as external changes!_ | ||
|
||
To activate this feature, just add `true` as the parameter of the `createLocalStorage` and `createSessionStorage`. | ||
|
||
## Examples | ||
|
||
### Local Storage | ||
|
||
```html | ||
<script> | ||
import { persist, createLocalStorage } from "@macfja/svelte-persistent-store" | ||
import { writable } from "svelte/store" | ||
const nickname = persist(writable('John'), createLocalStorage(true), 'myapp-nickname') | ||
// ^^^^ | ||
</script> | ||
``` | ||
|
||
If the another Window from the (same) browser change the value of the _createLocalStorage_ (from a Svelte application or not), the store will be updated. | ||
|
||
### Session Storage | ||
|
||
```html | ||
<script> | ||
import { persist, createSessionStorage } from "@macfja/svelte-persistent-store" | ||
import { writable } from "svelte/store" | ||
const unreadCount = persist(writable(0), createSessionStorage(true), 'myapp-unread') | ||
// ^^^^ | ||
</script> | ||
``` | ||
|
||
If the another Window from the (same) browser change the value of the _createSessionStorage_ (from a Svelte application or not), the store will be updated._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
name: Encrypt persisted data | ||
order: 4 | ||
--- | ||
# Encrypt persisted data | ||
|
||
You can encrypt data that are persisted. | ||
Both the key and the data are encrypted. | ||
|
||
_**NOTE:** The encryption is not well adapted for cookie storage, as the data is encrypted, its size greatly increase, you will rapidly get to the allowed cookie size._ | ||
|
||
## Examples | ||
|
||
```html | ||
<script> | ||
import { persist, createLocalStorage, createEncryptedStorage } from "@macfja/svelte-persistent-store" | ||
import { writable } from "svelte/store" | ||
const storage = createEncryptedStorage(createLocalStorage(), "5368566D597133743677397A24432646") | ||
const nickname = persist(writable("John"), storage, "myapp-nickname") | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.docs/07-Disable-Warnings.md → .docs/How-To/04-Disable-Warnings.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
name: Change behavior with missing encryption | ||
order: 5 | ||
--- | ||
# Change the behavior when the encryption is not possible | ||
|
||
The encryption library use the browser native WebCrypto library to work (or NodeJS Crypto library on a server). | ||
|
||
But there is case where the WebCrypto library may not be available, for example on a not secure URL. | ||
|
||
By default, this library will raise an exception. | ||
|
||
But you can change this with this code: | ||
|
||
```js | ||
import { noEncryptionBehavior, NO_ENCRYPTION_BEHAVIOR } from "@macfja/svelte-persistent-store"; | ||
noEncryptionBehavior(NO_ENCRYPTION_BEHAVIOR.NO_ENCRYPTION); | ||
``` | ||
|
||
Put this function call before calling the persistent storage or in the init/boot script. | ||
|
||
## List of behavior | ||
|
||
| Name | Numeric value | Comment | | ||
|-------------------------------------------|---------------|-------------------------------------------------------------------| | ||
| [[NO_ENCRYPTION_BEHAVIOR.EXCEPTION]] | `0` | **(default)** Raise an exception | | ||
| [[NO_ENCRYPTION_BEHAVIOR.NO_ENCRYPTION]] | `1` | Use the wrapped Storage as-is. Data will be saved not encrypted | | ||
| [[NO_ENCRYPTION_BEHAVIOR.NO_STORAGE]] | `2` | Don't use any storage, so no not encrypted data will be persisted | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "@tsconfig/svelte/tsconfig.json", | ||
|
||
"include": ["src/*"], | ||
"exclude": ["docs/*", "dist/*"], | ||
"compilerOptions": { | ||
"emitDeclarationOnly": true, | ||
"declaration": true, | ||
"declarationDir": "../types", | ||
"sourceMap": false | ||
}, | ||
"files": [ | ||
"../src/index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.