@logux/core
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -7,3 +7,3 @@ import { Unsubscribe } from 'nanoevents' | ||
interface Authentificator { | ||
(credentials: string, nodeId: string): Promise<boolean> | ||
(nodeId: string, token: string): Promise<boolean> | ||
} | ||
@@ -19,2 +19,6 @@ | ||
export interface TokenGenerator { | ||
(): string | Promise<string> | ||
} | ||
type NodeState = 'disconnected' | 'connecting' | 'sending' | 'synchronized' | ||
@@ -92,3 +96,3 @@ | ||
*/ | ||
credentials?: string | ||
token?: string | TokenGenerator | ||
@@ -95,0 +99,0 @@ /** |
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 0.5 ö | ||
* Change `auth` callback signature. | ||
* Rename `credentials` option to `token`. | ||
* User ID must be always a string. | ||
* Add support for dynamic tokens. | ||
## 0.4.2 | ||
@@ -5,0 +11,0 @@ * Fix types. |
import { LoguxError } from '../logux-error/index.js' | ||
async function auth (node, nodeId, credentials, callback) { | ||
async function auth (node, nodeId, token, callback) { | ||
if (!node.options.auth) { | ||
@@ -11,3 +11,3 @@ node.authenticated = true | ||
try { | ||
let access = await node.options.auth(credentials, nodeId) | ||
let access = await node.options.auth(nodeId, token) | ||
if (access) { | ||
@@ -62,3 +62,3 @@ node.authenticated = true | ||
function sendConnect () { | ||
async function sendConnect () { | ||
let message = [ | ||
@@ -72,4 +72,8 @@ 'connect', | ||
let options = { } | ||
if (this.options.credentials) { | ||
options.credentials = this.options.credentials | ||
if (this.options.token) { | ||
if (typeof this.options.token === 'function') { | ||
options.token = await this.options.token() | ||
} else { | ||
options.token = this.options.token | ||
} | ||
} | ||
@@ -86,3 +90,3 @@ if (this.options.subprotocol) { | ||
function sendConnected (start, end) { | ||
async function sendConnected (start, end) { | ||
let message = [ | ||
@@ -96,4 +100,8 @@ 'connected', | ||
let options = { } | ||
if (this.options.credentials) { | ||
options.credentials = this.options.credentials | ||
if (this.options.token) { | ||
if (typeof this.options.token === 'function') { | ||
options.token = await this.options.token() | ||
} else { | ||
options.token = this.options.token | ||
} | ||
} | ||
@@ -122,3 +130,3 @@ if (this.options.subprotocol) { | ||
auth(this, nodeId, options.credentials, () => { | ||
auth(this, nodeId, options.token, () => { | ||
this.baseTime = this.now() | ||
@@ -153,3 +161,3 @@ this.sendConnected(start, this.baseTime) | ||
auth(this, nodeId, options.credentials, () => { | ||
auth(this, nodeId, options.token, () => { | ||
this.syncSince(this.lastSent) | ||
@@ -156,0 +164,0 @@ }) |
export { Log, ID, Action, AnyAction, Meta, Store } from './log' | ||
export { BaseNode, Connection, TokenGenerator } from './base-node' | ||
export { LoguxError, LoguxErrorOptions } from './logux-error' | ||
export { BaseNode, Connection } from './base-node' | ||
export { ServerConnection } from './server-connection' | ||
@@ -5,0 +5,0 @@ export { eachStoreCheck } from './each-store-check' |
@@ -49,3 +49,3 @@ import { Unsubscribe } from 'nanoevents' | ||
*/ | ||
keepLast: string | ||
keepLast?: string | ||
@@ -52,0 +52,0 @@ [extra: string]: any |
{ | ||
"name": "@logux/core", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "Logux core components", | ||
@@ -45,2 +45,7 @@ "keywords": [ | ||
}, | ||
"./connect/package.json": "./connect/package.json", | ||
"./connect": { | ||
"require": "./connect/index.cjs", | ||
"import": "./connect/index.js" | ||
}, | ||
"./debug/package.json": "./debug/package.json", | ||
@@ -61,7 +66,2 @@ "./debug": { | ||
}, | ||
"./connect/package.json": "./connect/package.json", | ||
"./connect": { | ||
"require": "./connect/index.cjs", | ||
"import": "./connect/index.js" | ||
}, | ||
"./is-first-older/package.json": "./is-first-older/package.json", | ||
@@ -68,0 +68,0 @@ "./is-first-older": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152421
4872