mirror of
https://github.com/balzack/databag.git
synced 2025-05-04 15:35:16 +00:00
testing identity module
This commit is contained in:
parent
f8299dd78a
commit
d3dbeb5ffa
@ -20,7 +20,7 @@ export class MockIdentityModule implements Identity {
|
|||||||
this.emitter.off('profile', ev);
|
this.emitter.off('profile', ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
public close(): void {
|
public async close(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setRevision(rev: number): Promise<void> {
|
public async setRevision(rev: number): Promise<void> {
|
||||||
@ -33,7 +33,8 @@ export class MockIdentityModule implements Identity {
|
|||||||
public async setProfileImage(image: string): Promise<void> {
|
public async setProfileImage(image: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getHandleStatus(handle: string): Promise<void> {
|
public async getHandleStatus(handle: string): Promise<boolean> {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getProfileImageUrl(): string {
|
public getProfileImageUrl(): string {
|
||||||
|
@ -28,7 +28,7 @@ export interface Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Session {
|
export interface Session {
|
||||||
close(): { node: string, secure: boolean, token: string };
|
close(): Promise<{ node: string, secure: boolean, token: string }>;
|
||||||
|
|
||||||
getAccount(): Account;
|
getAccount(): Account;
|
||||||
getIdentity(): Identity;
|
getIdentity(): Identity;
|
||||||
@ -81,7 +81,7 @@ export interface Account {
|
|||||||
export interface Identity {
|
export interface Identity {
|
||||||
setProfileData(name: string, location: string, description: string): Promise<void>;
|
setProfileData(name: string, location: string, description: string): Promise<void>;
|
||||||
setProfileImage(image: string): Promise<void>;
|
setProfileImage(image: string): Promise<void>;
|
||||||
getHandleStatus(handle: string): Promise<void>;
|
getHandleStatus(handle: string): Promise<boolean>;
|
||||||
|
|
||||||
getProfileImageUrl(): string;
|
getProfileImageUrl(): string;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { Seal, Profile } from './types';
|
import type { Profile } from './types';
|
||||||
|
|
||||||
export type CardEntity = {
|
export type CardEntity = {
|
||||||
id: string,
|
id: string,
|
||||||
@ -142,6 +142,13 @@ export type ArticleEntity = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SealEntity = {
|
||||||
|
passwordSalt: string,
|
||||||
|
privateKeyIv: string,
|
||||||
|
privateKeyEncrypted: string,
|
||||||
|
publicKey: string,
|
||||||
|
}
|
||||||
|
|
||||||
export type AccountEntity = {
|
export type AccountEntity = {
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
storageUsed: number,
|
storageUsed: number,
|
||||||
@ -151,7 +158,7 @@ export type AccountEntity = {
|
|||||||
allowUnsealed: boolean,
|
allowUnsealed: boolean,
|
||||||
pushEnabled: boolean,
|
pushEnabled: boolean,
|
||||||
sealable: boolean,
|
sealable: boolean,
|
||||||
seal: Seal,
|
seal: SealEntity,
|
||||||
enableIce: boolean,
|
enableIce: boolean,
|
||||||
multiFactorAuth: boolean,
|
multiFactorAuth: boolean,
|
||||||
webPushKey: string,
|
webPushKey: string,
|
||||||
|
@ -6,6 +6,7 @@ import { getProfile } from './net/getProfile';
|
|||||||
import { getProfileImageUrl } from './net/getProfileImageUrl';
|
import { getProfileImageUrl } from './net/getProfileImageUrl';
|
||||||
import { setProfileData } from './net/setProfileData';
|
import { setProfileData } from './net/setProfileData';
|
||||||
import { setProfileImage } from './net/setProfileImage';
|
import { setProfileImage } from './net/setProfileImage';
|
||||||
|
import { getUsername } from './net/getUsername';
|
||||||
import { ProfileEntity, defaultProfileEntity } from './entities';
|
import { ProfileEntity, defaultProfileEntity } from './entities';
|
||||||
|
|
||||||
const CLOSE_POLL_MS = 100;
|
const CLOSE_POLL_MS = 100;
|
||||||
@ -63,6 +64,7 @@ export class IdentityModule implements Identity {
|
|||||||
const profile = await getProfile(node, secure, token);
|
const profile = await getProfile(node, secure, token);
|
||||||
await this.store.setProfileData(guid, profile);
|
await this.store.setProfileData(guid, profile);
|
||||||
await this.store.setProfileRevision(guid, nextRev);
|
await this.store.setProfileRevision(guid, nextRev);
|
||||||
|
this.profile = profile;
|
||||||
this.emitter.emit('profile', this.getProfile());
|
this.emitter.emit('profile', this.getProfile());
|
||||||
this.revision = nextRev;
|
this.revision = nextRev;
|
||||||
if (this.nextRevision === nextRev) {
|
if (this.nextRevision === nextRev) {
|
||||||
@ -94,7 +96,7 @@ export class IdentityModule implements Identity {
|
|||||||
this.emitter.off('profile', ev);
|
this.emitter.off('profile', ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async close(): void {
|
public async close(): Promise<void> {
|
||||||
this.closing = true;
|
this.closing = true;
|
||||||
while(this.syncing) {
|
while(this.syncing) {
|
||||||
await new Promise(r => setTimeout(r, CLOSE_POLL_MS));
|
await new Promise(r => setTimeout(r, CLOSE_POLL_MS));
|
||||||
@ -107,16 +109,23 @@ export class IdentityModule implements Identity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async setProfileData(name: string, location: string, description: string): Promise<void> {
|
public async setProfileData(name: string, location: string, description: string): Promise<void> {
|
||||||
|
const { node, secure, token } = this;
|
||||||
|
await setProfileData(node, secure, token, name, location, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setProfileImage(image: string): Promise<void> {
|
public async setProfileImage(image: string): Promise<void> {
|
||||||
|
const { node, secure, token } = this;
|
||||||
|
await setProfileImage(node, secure, token, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getHandleStatus(handle: string): Promise<void> {
|
public async getHandleStatus(handle: string): Promise<boolean> {
|
||||||
|
const { node, secure, token } = this;
|
||||||
|
return await getUsername(handle, token, node, secure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getProfileImageUrl(): string {
|
public getProfileImageUrl(): string {
|
||||||
return getProfileImageUrl(this.node, this.secure, this.token, this.revision);
|
const { node, secure, token, revision } = this;
|
||||||
|
return getProfileImageUrl(node, secure, token, revision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ export class DatabagSDK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async logout(session: Session, all: boolean): Promise<void> {
|
public async logout(session: Session, all: boolean): Promise<void> {
|
||||||
const params = session.close();
|
const params = await session.close();
|
||||||
try {
|
try {
|
||||||
const { node, secure, token } = params;
|
const { node, secure, token } = params;
|
||||||
await clearLogin(node, secure, token, all);
|
await clearLogin(node, secure, token, all);
|
||||||
|
@ -133,7 +133,7 @@ export class SessionModule implements Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async close(): { node: string, secure: boolean, token: string } {
|
public async close(): Promise<{ node: string, secure: boolean, token: string }> {
|
||||||
await this.content.close();
|
await this.content.close();
|
||||||
await this.attribute.close();
|
await this.attribute.close();
|
||||||
await this.alias.close();
|
await this.alias.close();
|
||||||
@ -142,7 +142,8 @@ export class SessionModule implements Session {
|
|||||||
await this.account.close();
|
await this.account.close();
|
||||||
await this.stream.close();
|
await this.stream.close();
|
||||||
this.connection.close();
|
this.connection.close();
|
||||||
return { node: this.node, secure: this.secure, token: this.token };
|
const { node, secure, token } = this;
|
||||||
|
return { node: node, secure: secure, token: token };
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAccount(): Account {
|
public getAccount(): Account {
|
||||||
|
@ -27,6 +27,6 @@ export class StreamModule implements Stream {
|
|||||||
this.emitter.off('channel', ev);
|
this.emitter.off('channel', ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async close(): void {
|
public async close(): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user