@sprucelabs/heartwood-view-controllers 112.1.8 → 112.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/auth/Authenticator.d.ts +8 -24
- package/build/auth/Authenticator.js +2 -1
- package/build/esm/auth/Authenticator.d.ts +8 -24
- package/build/esm/auth/Authenticator.js +3 -1
- package/build/esm/tests/StubStorage.d.ts +1 -1
- package/build/esm/types/heartwood.types.d.ts +9 -2
- package/build/tests/StubStorage.d.ts +1 -1
- package/build/types/heartwood.types.d.ts +9 -2
- package/package.json +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { Person } from '@sprucelabs/spruce-core-schemas';
|
|
3
|
+
import { Authenticator, AuthenticatorEventName, AuthenticatorEventPayloads, Storage } from '../types/heartwood.types';
|
|
3
4
|
export default class AuthenticatorImpl implements Authenticator {
|
|
5
|
+
static Class?: new (storage: Storage) => Authenticator;
|
|
4
6
|
private static instance;
|
|
5
7
|
private static storage;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
protected eventEmitter: EventEmitter;
|
|
9
|
+
protected storage: Storage;
|
|
10
|
+
protected constructor(storage: Storage);
|
|
9
11
|
static getInstance(): Authenticator;
|
|
10
12
|
static reset(): void;
|
|
11
13
|
static setStorage(storage: Storage | null): void;
|
|
@@ -14,23 +16,5 @@ export default class AuthenticatorImpl implements Authenticator {
|
|
|
14
16
|
getPerson(): any;
|
|
15
17
|
isLoggedIn(): boolean;
|
|
16
18
|
clearSession(): void;
|
|
17
|
-
addEventListener<N extends
|
|
19
|
+
addEventListener<N extends AuthenticatorEventName>(name: N, cb: AuthenticatorEventPayloads[N]): void;
|
|
18
20
|
}
|
|
19
|
-
type Person = SpruceSchemas.Spruce.v2020_07_22.Person;
|
|
20
|
-
type DidLoginPayload = (payload: {
|
|
21
|
-
token: string;
|
|
22
|
-
person: Person;
|
|
23
|
-
}) => void;
|
|
24
|
-
type DidLogoutPayload = (payload: {
|
|
25
|
-
person: Person;
|
|
26
|
-
}) => void;
|
|
27
|
-
export interface Storage {
|
|
28
|
-
removeItem(key: string): void;
|
|
29
|
-
setItem(key: string, value: string): void;
|
|
30
|
-
getItem(key: string): string | null;
|
|
31
|
-
}
|
|
32
|
-
interface Payloads {
|
|
33
|
-
'did-login': DidLoginPayload;
|
|
34
|
-
'did-logout': DidLogoutPayload;
|
|
35
|
-
}
|
|
36
|
-
export {};
|
|
@@ -15,7 +15,7 @@ class AuthenticatorImpl {
|
|
|
15
15
|
throw new SpruceError_1.default({ code: 'MISSING_STORAGE' });
|
|
16
16
|
}
|
|
17
17
|
if (!this.instance) {
|
|
18
|
-
this.instance = new this(this.storage);
|
|
18
|
+
this.instance = new (this.Class ?? this)(this.storage);
|
|
19
19
|
}
|
|
20
20
|
return this.instance;
|
|
21
21
|
}
|
|
@@ -43,6 +43,7 @@ class AuthenticatorImpl {
|
|
|
43
43
|
}
|
|
44
44
|
clearSession() {
|
|
45
45
|
const person = JSON.parse(this.storage.getItem('person') ?? '{}');
|
|
46
|
+
this.eventEmitter.emit('will-logout', { person });
|
|
46
47
|
this.storage.removeItem('sessionToken');
|
|
47
48
|
this.storage.removeItem('person');
|
|
48
49
|
this.eventEmitter.emit('did-logout', { person });
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { Person } from '@sprucelabs/spruce-core-schemas';
|
|
3
|
+
import { Authenticator, AuthenticatorEventName, AuthenticatorEventPayloads, Storage } from '../types/heartwood.types';
|
|
3
4
|
export default class AuthenticatorImpl implements Authenticator {
|
|
5
|
+
static Class?: new (storage: Storage) => Authenticator;
|
|
4
6
|
private static instance;
|
|
5
7
|
private static storage;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
protected eventEmitter: EventEmitter;
|
|
9
|
+
protected storage: Storage;
|
|
10
|
+
protected constructor(storage: Storage);
|
|
9
11
|
static getInstance(): Authenticator;
|
|
10
12
|
static reset(): void;
|
|
11
13
|
static setStorage(storage: Storage | null): void;
|
|
@@ -14,23 +16,5 @@ export default class AuthenticatorImpl implements Authenticator {
|
|
|
14
16
|
getPerson(): any;
|
|
15
17
|
isLoggedIn(): boolean;
|
|
16
18
|
clearSession(): void;
|
|
17
|
-
addEventListener<N extends
|
|
19
|
+
addEventListener<N extends AuthenticatorEventName>(name: N, cb: AuthenticatorEventPayloads[N]): void;
|
|
18
20
|
}
|
|
19
|
-
type Person = SpruceSchemas.Spruce.v2020_07_22.Person;
|
|
20
|
-
type DidLoginPayload = (payload: {
|
|
21
|
-
token: string;
|
|
22
|
-
person: Person;
|
|
23
|
-
}) => void;
|
|
24
|
-
type DidLogoutPayload = (payload: {
|
|
25
|
-
person: Person;
|
|
26
|
-
}) => void;
|
|
27
|
-
export interface Storage {
|
|
28
|
-
removeItem(key: string): void;
|
|
29
|
-
setItem(key: string, value: string): void;
|
|
30
|
-
getItem(key: string): string | null;
|
|
31
|
-
}
|
|
32
|
-
interface Payloads {
|
|
33
|
-
'did-login': DidLoginPayload;
|
|
34
|
-
'did-logout': DidLogoutPayload;
|
|
35
|
-
}
|
|
36
|
-
export {};
|
|
@@ -6,11 +6,12 @@ export default class AuthenticatorImpl {
|
|
|
6
6
|
this.storage = storage;
|
|
7
7
|
}
|
|
8
8
|
static getInstance() {
|
|
9
|
+
var _a;
|
|
9
10
|
if (!this.storage) {
|
|
10
11
|
throw new SpruceError({ code: 'MISSING_STORAGE' });
|
|
11
12
|
}
|
|
12
13
|
if (!this.instance) {
|
|
13
|
-
this.instance = new this(this.storage);
|
|
14
|
+
this.instance = new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(this.storage);
|
|
14
15
|
}
|
|
15
16
|
return this.instance;
|
|
16
17
|
}
|
|
@@ -40,6 +41,7 @@ export default class AuthenticatorImpl {
|
|
|
40
41
|
clearSession() {
|
|
41
42
|
var _a;
|
|
42
43
|
const person = JSON.parse((_a = this.storage.getItem('person')) !== null && _a !== void 0 ? _a : '{}');
|
|
44
|
+
this.eventEmitter.emit('will-logout', { person });
|
|
43
45
|
this.storage.removeItem('sessionToken');
|
|
44
46
|
this.storage.removeItem('person');
|
|
45
47
|
this.eventEmitter.emit('did-logout', { person });
|
|
@@ -51,17 +51,24 @@ type DidLoginPayload = (payload: {
|
|
|
51
51
|
type DidLogoutPayload = (payload: {
|
|
52
52
|
person: Person;
|
|
53
53
|
}) => void;
|
|
54
|
-
interface
|
|
54
|
+
export interface AuthenticatorEventPayloads {
|
|
55
55
|
'did-login': DidLoginPayload;
|
|
56
|
+
'will-logout': DidLoginPayload;
|
|
56
57
|
'did-logout': DidLogoutPayload;
|
|
57
58
|
}
|
|
59
|
+
export type AuthenticatorEventName = keyof AuthenticatorEventPayloads;
|
|
60
|
+
export interface Storage {
|
|
61
|
+
removeItem(key: string): void;
|
|
62
|
+
setItem(key: string, value: string): void;
|
|
63
|
+
getItem(key: string): string | null;
|
|
64
|
+
}
|
|
58
65
|
export interface Authenticator {
|
|
59
66
|
getPerson(): Person | null;
|
|
60
67
|
setSessionToken(token: string, person: Person): void;
|
|
61
68
|
getSessionToken(): string | null;
|
|
62
69
|
isLoggedIn(): boolean;
|
|
63
70
|
clearSession(): void;
|
|
64
|
-
addEventListener<N extends 'did-login' | 'did-logout'>(name: N, cb:
|
|
71
|
+
addEventListener<N extends 'did-login' | 'did-logout' | 'will-logout'>(name: N, cb: AuthenticatorEventPayloads[N]): void;
|
|
65
72
|
}
|
|
66
73
|
export interface AuthenticatorStatic {
|
|
67
74
|
getInstance(): Authenticator;
|
|
@@ -51,17 +51,24 @@ type DidLoginPayload = (payload: {
|
|
|
51
51
|
type DidLogoutPayload = (payload: {
|
|
52
52
|
person: Person;
|
|
53
53
|
}) => void;
|
|
54
|
-
interface
|
|
54
|
+
export interface AuthenticatorEventPayloads {
|
|
55
55
|
'did-login': DidLoginPayload;
|
|
56
|
+
'will-logout': DidLoginPayload;
|
|
56
57
|
'did-logout': DidLogoutPayload;
|
|
57
58
|
}
|
|
59
|
+
export type AuthenticatorEventName = keyof AuthenticatorEventPayloads;
|
|
60
|
+
export interface Storage {
|
|
61
|
+
removeItem(key: string): void;
|
|
62
|
+
setItem(key: string, value: string): void;
|
|
63
|
+
getItem(key: string): string | null;
|
|
64
|
+
}
|
|
58
65
|
export interface Authenticator {
|
|
59
66
|
getPerson(): Person | null;
|
|
60
67
|
setSessionToken(token: string, person: Person): void;
|
|
61
68
|
getSessionToken(): string | null;
|
|
62
69
|
isLoggedIn(): boolean;
|
|
63
70
|
clearSession(): void;
|
|
64
|
-
addEventListener<N extends 'did-login' | 'did-logout'>(name: N, cb:
|
|
71
|
+
addEventListener<N extends 'did-login' | 'did-logout' | 'will-logout'>(name: N, cb: AuthenticatorEventPayloads[N]): void;
|
|
65
72
|
}
|
|
66
73
|
export interface AuthenticatorStatic {
|
|
67
74
|
getInstance(): Authenticator;
|
package/package.json
CHANGED