From f5f6a3b602d262f447b00b83d3ff63301be63807 Mon Sep 17 00:00:00 2001 From: Bnonni Date: Thu, 22 Aug 2024 10:56:51 -0400 Subject: [PATCH] implement idcxserver, dcxserver, issuerserver; todo - applicantserver --- package.json | 2 +- packages/server/src/applicant/index.ts | 2 +- packages/server/src/dcx-server.ts | 30 ++++++++++++------------ packages/server/src/issuer/index.ts | 2 +- packages/server/tests/dcx-server.spec.ts | 14 +++++------ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index f210405..b7c03d4 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "publish:all": "pnpm --filter applicant publish && pnpm --filter common publish && pnpm --filter issuer publish && pnpm --filter server publish", "test": "pnpm --recursive --stream test", "test:node": "pnpm --recursive --stream test:node", - "workflow": "pnpm install --frozen-lockfile && pnpm lint && pnpm build && pnpm build:tests:node", + "workflow": "pnpm lint && pnpm install --frozen-lockfile && pnpm lint && pnpm build && pnpm build:tests:node", "build-test": "pnpm --recursive --stream build && pnpm --recursive --stream build:tests:node && pnpm --recursive --stream test:node", "version": "tsx scripts/version.ts", "version:patch": "tsx scripts/version.ts patch", diff --git a/packages/server/src/applicant/index.ts b/packages/server/src/applicant/index.ts index 8a2f710..c8bc200 100644 --- a/packages/server/src/applicant/index.ts +++ b/packages/server/src/applicant/index.ts @@ -30,7 +30,7 @@ export class ApplicantServer extends DcxServer { */ constructor(params: { type: 'applicant', applicant: DcxApplicant; }) { super(params); - this.applicant = params.applicant ?? this.dcxActor as DcxApplicant ?? new DcxApplicant({}); + this.applicant = params.applicant ?? this.dcx as DcxApplicant ?? new DcxApplicant({}); } diff --git a/packages/server/src/dcx-server.ts b/packages/server/src/dcx-server.ts index a029586..36e7f54 100644 --- a/packages/server/src/dcx-server.ts +++ b/packages/server/src/dcx-server.ts @@ -8,7 +8,7 @@ import { IssuerServer } from './issuer/index.js'; export interface IDcxServer { isTest : boolean; isPolling : boolean; - dcxActor : DcxIssuer | DcxApplicant; + dcx : DcxIssuer | DcxApplicant; server : IssuerServer | ApplicantServer; use(path: string, ...args: any[]): void; @@ -21,33 +21,33 @@ export interface IDcxServer { } export interface DcxServerParams { - type?: 'issuer' | 'applicant'; issuer?: DcxIssuer; applicant?: DcxApplicant + type?: 'issuer' | 'applicant'; } export class DcxServer implements IDcxServer { isPolling : boolean = false; isTest : boolean = process.env.NODE_ENV?.includes('test') || argv.slice(2).some((arg) => ['--test', '-t'].includes(arg)); - dcxActor : DcxIssuer | DcxApplicant; + dcx : DcxIssuer | DcxApplicant; server : IssuerServer | ApplicantServer; constructor(params: DcxServerParams) { if(params.type === 'applicant' || params.applicant) { - this.dcxActor = params.applicant ?? new DcxApplicant({}); + this.dcx = params.applicant ?? new DcxApplicant({}); this.server = new ApplicantServer({ type : 'applicant', - applicant : this.dcxActor as DcxApplicant + applicant : this.dcx as DcxApplicant }); } else if (params.type === 'issuer' || params.issuer) { - this.dcxActor = params.issuer ?? new DcxIssuer({}); + this.dcx = params.issuer ?? new DcxIssuer({}); this.server = new IssuerServer({ type : 'issuer', - issuer : this.dcxActor as DcxIssuer + issuer : this.dcx as DcxIssuer }); } else { - throw new DcxServerError('Invalid server type: must be either "applicant" or "issuer"'); + throw new DcxServerError('Invalid server params: must be pass type "applicant" or "issuer" or must pass an applicant or issuer object'); } } @@ -69,7 +69,7 @@ export class DcxServer implements IDcxServer { ); } if (validPaths.includes(path)) { - this.dcxActor.options[path].push(...args); + this.dcx.options[path].push(...args); } else { throw new DcxServerError(`Invalid server.use() object: ${args}`); } @@ -85,7 +85,7 @@ export class DcxServer implements IDcxServer { * */ public useManifest(manifest: Manifest): void { - this.dcxActor.options.manifests.push(manifest); + this.dcx.options.manifests.push(manifest); } /** @@ -98,7 +98,7 @@ export class DcxServer implements IDcxServer { * */ public useHandler(handler: Handler): void { - this.dcxActor.options.handlers.push(handler); + this.dcx.options.handlers.push(handler); } /** @@ -111,7 +111,7 @@ export class DcxServer implements IDcxServer { * */ public useProvider(provider: Provider): void { - this.dcxActor.options.providers.push(provider); + this.dcx.options.providers.push(provider); } /** @@ -124,7 +124,7 @@ export class DcxServer implements IDcxServer { * */ public useIssuer(issuer: Issuer): void { - this.dcxActor.options.issuers.push(issuer); + this.dcx.options.issuers.push(issuer); } /** @@ -136,7 +136,7 @@ export class DcxServer implements IDcxServer { * */ public useDwn(dwn: string): void { - this.dcxActor.options.dwns.push(dwn); + this.dcx.options.dwns.push(dwn); } /** @@ -148,6 +148,6 @@ export class DcxServer implements IDcxServer { * */ public useGateway(gateway: string): void { - this.dcxActor.options.gateways.push(gateway); + this.dcx.options.gateways.push(gateway); } } \ No newline at end of file diff --git a/packages/server/src/issuer/index.ts b/packages/server/src/issuer/index.ts index 885b45f..e363e5f 100644 --- a/packages/server/src/issuer/index.ts +++ b/packages/server/src/issuer/index.ts @@ -25,7 +25,7 @@ export class IssuerServer extends DcxServer { */ constructor(params: { type: 'issuer', issuer: DcxIssuer; }) { super(params); - this.issuer = params.issuer ?? this.dcxActor as DcxIssuer ?? new DcxIssuer({}); + this.issuer = params.issuer ?? this.dcx as DcxIssuer ?? new DcxIssuer({}); } /** diff --git a/packages/server/tests/dcx-server.spec.ts b/packages/server/tests/dcx-server.spec.ts index df709e8..f971ea9 100644 --- a/packages/server/tests/dcx-server.spec.ts +++ b/packages/server/tests/dcx-server.spec.ts @@ -2,7 +2,7 @@ import { DcxAgent, dcxConfig, DcxIdentityVault, FileSystem, Mnemonic } from '@dc import { DcxIssuer } from '@dcx-protocol/issuer'; import { Web5 } from '@web5/api'; import { expect } from 'chai'; -import { DcxIssuerServer } from '../src/index.js'; +import { DcxServer } from '../src/index.js'; process.env.NODE_ENV = 'test'; @@ -18,7 +18,7 @@ const issuer = new DcxIssuer({ } } }); -const server: DcxIssuerServer = new DcxIssuerServer({ issuer }); +const server: DcxServer = new DcxServer({ issuer }); describe('DcxServer class', () => { afterEach(async () => { @@ -54,7 +54,7 @@ describe('DcxServer class', () => { }); it('should include property serverOptions as an object containing 6 entries', () => { - const serverOptions = server.issuer.options; + const serverOptions = server.dcx.options; expect(serverOptions).to.not.be.null.and.not.be.undefined; expect(Object.entries(serverOptions)).to.have.lengthOf.gte(5); }); @@ -62,8 +62,8 @@ describe('DcxServer class', () => { describe('.initialize()', () => { it('should initialize the server', async () => { - await server.issuer.initializeWeb5(); - expect(server.issuer.isInitialized).equals(true); + await server.dcx.initializeWeb5(); + expect(server.dcx.isInitialized).equals(true); }); it('should initialize the DcxManager', () => { @@ -80,8 +80,8 @@ describe('DcxServer class', () => { describe('.setupDwn()', () => { it('should setup the remote DWN', async () => { - await server.issuer.setupDwn(); - expect(server.issuer.isSetup).equals(true); + await server.dcx.setupDwn(); + expect(server.dcx.isSetup).equals(true); }); }); }); \ No newline at end of file