svelte-session-manager
Advanced tools
Comparing version
{ | ||
"name": "svelte-session-manager", | ||
"version": "1.3.4", | ||
"version": "1.4.0", | ||
"publishConfig": { | ||
@@ -27,22 +27,22 @@ "access": "public" | ||
"test:cafe": "testcafe $BROWSER:headless tests/cafe/*.js -s build/test --app-init-delay 1000 --app \"rollup -c tests/app/rollup.config.mjs -w\"", | ||
"docs": "documentation readme ./src/index.mjs --section=API && documentation readme ./src/index.svelte --section=API", | ||
"docs": "documentation readme --section=API ./src/**/*.mjs", | ||
"lint": "documentation lint ./src/index.mjs && npm run lint:docs", | ||
"lint:docs": "documentation lint ./src/index.svelte", | ||
"lint:docs": "documentation lint ./src/**/*.mjs", | ||
"build": "rollup -c tests/app/rollup.config.mjs" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^11.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@rollup/plugin-virtual": "^2.0.3", | ||
"documentation": "github:arlac77/documentation", | ||
"documentation": "^13.2.5", | ||
"jsonwebtoken": "^8.5.1", | ||
"mf-styling": "arlac77/mf-styling", | ||
"postcss": "^8.2.2", | ||
"postcss-import": "^14.0.0", | ||
"rollup": "^2.36.1", | ||
"postcss": "^8.2.15", | ||
"postcss-import": "^14.0.2", | ||
"rollup": "^2.47.0", | ||
"rollup-plugin-dev": "^1.1.3", | ||
"rollup-plugin-postcss": "^4.0.0", | ||
"rollup-plugin-svelte": "^7.0.0", | ||
"semantic-release": "^17.3.1", | ||
"svelte": "^3.31.2", | ||
"testcafe": "^1.10.1" | ||
"rollup-plugin-svelte": "^7.1.0", | ||
"semantic-release": "^17.4.2", | ||
"svelte": "^3.38.2", | ||
"testcafe": "^1.14.0" | ||
}, | ||
@@ -49,0 +49,0 @@ "repository": { |
136
README.md
@@ -12,2 +12,3 @@ [](https://svelte.dev) | ||
[](https://coveralls.io/github/arlac77/svelte-session-manager) | ||
[](https://github.com/DevExpress/testcafe) | ||
[](https://app.netlify.com/sites/svelte-session-manager/deploys) | ||
@@ -64,3 +65,3 @@ | ||
- successful auth | ||
* successful auth | ||
@@ -73,3 +74,3 @@ ```sh | ||
- invalid credentials | ||
* invalid credentials | ||
@@ -90,4 +91,133 @@ ```sh | ||
## Table of Contents | ||
### Table of Contents | ||
* [login](#login) | ||
* [Parameters](#parameters) | ||
* [handleFailedResponse](#handlefailedresponse) | ||
* [Parameters](#parameters-1) | ||
* [SessionData](#sessiondata) | ||
* [Properties](#properties) | ||
* [Session](#session) | ||
* [Parameters](#parameters-2) | ||
* [Properties](#properties-1) | ||
* [clear](#clear) | ||
* [save](#save) | ||
* [authorizationHeader](#authorizationheader) | ||
* [isValid](#isvalid) | ||
* [invalidate](#invalidate) | ||
* [hasEntitlement](#hasentitlement) | ||
* [Parameters](#parameters-3) | ||
* [subscribe](#subscribe) | ||
* [Parameters](#parameters-4) | ||
## login | ||
Bring session into the valid state by calling the authorization endpoint | ||
and asking for a access_token. | ||
Executes a POST on the endpoint url expecting username, and password as json | ||
### Parameters | ||
* `session` **[Session](#session)** to be opened | ||
* `endpoint` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** authorization url | ||
* `username` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** id of the user | ||
* `password` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** user credentials | ||
* `tokenmap` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** token names in response to internal known values (optional, default `{access_token:"access_token",refresh_token:"refresh_token"}`) | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** error message in case of failure or undefined on success | ||
## handleFailedResponse | ||
Extract error description from response | ||
### Parameters | ||
* `response` **FetchResponse** | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
## SessionData | ||
Data as preserved in the backing store | ||
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | ||
### Properties | ||
* `username` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** user name (id) | ||
* `access_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** JWT token | ||
* `refresh_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** JWT token | ||
## Session | ||
User session | ||
To create as session backed by browser local storage | ||
```js | ||
let session = new Session(localStorage); | ||
``` | ||
or by browser session storage | ||
```js | ||
let session = new Session(sessionStorage); | ||
``` | ||
### Parameters | ||
* `data` **[SessionData](#sessiondata)** | ||
### Properties | ||
* `entitlements` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** | ||
* `subscriptions` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** store subscriptions | ||
* `expirationDate` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)** | ||
* `access_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** token itself | ||
* `refresh_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** refresh token | ||
* `store` **[SessionData](#sessiondata)** backing store to use for save same as data param | ||
### clear | ||
Invalidate session data. | ||
### save | ||
Persist into the backing store. | ||
### authorizationHeader | ||
Http header suitable for fetch. | ||
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** header The http header. | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** header.Authorization The Bearer access token. | ||
### isValid | ||
As long as the expirationTimer is running we must be valid. | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if session is valid (not expired) | ||
### invalidate | ||
Remove all tokens from the session and the backing store. | ||
### hasEntitlement | ||
Check presence of an entitlement. | ||
#### Parameters | ||
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of the entitlement | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if the named entitlement is present | ||
### subscribe | ||
Fired when the session changes. | ||
#### Parameters | ||
* `subscription` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** | ||
# install | ||
@@ -94,0 +224,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21502
37.94%267
15.09%230
130%