diff --git a/packages/client/integration/Loc.ts b/packages/client/integration/Loc.ts index 5a220e95..bbbbb5ed 100644 --- a/packages/client/integration/Loc.ts +++ b/packages/client/integration/Loc.ts @@ -46,10 +46,10 @@ export async function requestTransactionLoc(state: State, linkTarget: UUID) { const nameHash = Hash.of(metadataName); draftRequest = await draftRequest.addMetadata({ name: metadataName, - value: "Some value" + value: "Some invalid value" }) as DraftRequest; expect(draftRequest.data().metadata[0].name.validValue()).toBe(metadataName); - expect(draftRequest.data().metadata[0].value.validValue()).toBe("Some value"); + expect(draftRequest.data().metadata[0].value.validValue()).toBe("Some invalid value"); expect(draftRequest.data().metadata[0].addedOn).toBeUndefined(); expect(draftRequest.data().metadata[0].status).toBe("DRAFT"); @@ -77,19 +77,28 @@ export async function requestTransactionLoc(state: State, linkTarget: UUID) { const aliceClient = state.client.withCurrentAddress(aliceAccount); let aliceLocs = await aliceClient.locsState({ spec: { ownerAddress: alice.address, statuses: [ "REVIEW_PENDING", "OPEN" ], locTypes: [ "Transaction" ] } }); let alicePendingLoc = aliceLocs.findById(pendingRequest.data().id) as PendingRequest; + alicePendingLoc = await alicePendingLoc.legalOfficer.reviewMetadata({ nameHash, decision: "REJECT", rejectReason: "Invalid value" }); let aliceRejectedLoc = await alicePendingLoc.legalOfficer.reject("Because.") as RejectedRequest; let rejectedRequest = await pendingRequest.refresh() as RejectedRequest; expect(rejectedRequest).toBeInstanceOf(RejectedRequest); expect(rejectedRequest.data().metadata[0].status).toBe("REVIEW_REJECTED"); - expect(rejectedRequest.data().links[0].status).toBe("REVIEW_REJECTED"); + expect(rejectedRequest.data().links[0].status).toBe("REVIEW_PENDING"); draftRequest = await rejectedRequest.rework(); expect(draftRequest).toBeInstanceOf(DraftRequest); - expect(draftRequest.data().metadata[0].status).toBe("DRAFT"); - expect(draftRequest.data().links[0].status).toBe("DRAFT"); + expect(draftRequest.data().metadata[0].status).toBe("REVIEW_REJECTED"); + expect(draftRequest.data().links[0].status).toBe("REVIEW_PENDING"); + draftRequest = await draftRequest.deleteMetadata({ nameHash }) as DraftRequest; + draftRequest = await draftRequest.addMetadata({ + name: metadataName, + value: "Some value" + }) as DraftRequest; pendingRequest = await draftRequest.submit(); + expect(pendingRequest.data().metadata[0].status).toBe("REVIEW_PENDING"); alicePendingLoc = await aliceRejectedLoc.refresh() as PendingRequest; + alicePendingLoc = await alicePendingLoc.legalOfficer.reviewMetadata({ nameHash, decision: "ACCEPT" }); + expect(alicePendingLoc.data().metadata[0].status).toBe("REVIEW_ACCEPTED"); let aliceAcceptedLoc = await alicePendingLoc.legalOfficer.accept({ signer }) as AcceptedRequest; let acceptedLoc = await pendingRequest.refresh() as AcceptedRequest; expect(acceptedLoc).toBeInstanceOf(AcceptedRequest); @@ -97,10 +106,7 @@ export async function requestTransactionLoc(state: State, linkTarget: UUID) { checkData(locsState.acceptedRequests["Transaction"][0].data(), "REVIEW_ACCEPTED"); let openLoc = await acceptedLoc.open({ signer }); - let aliceOpenLoc = await aliceAcceptedLoc.refresh() as OpenLoc; - expect(openLoc).toBeInstanceOf(OpenLoc); - expect(openLoc.data().metadata[0].status).toBe("REVIEW_PENDING"); locsState = openLoc.locsState(); checkData(locsState.openLocs["Transaction"][0].data(), "OPEN"); @@ -128,6 +134,7 @@ export async function requestTransactionLoc(state: State, linkTarget: UUID) { openLoc = await openLoc.requestFileReview({ hash }) as OpenLoc; expect(openLoc.data().files[0].status).toBe("REVIEW_PENDING"); + let aliceOpenLoc = await aliceAcceptedLoc.refresh() as OpenLoc; aliceOpenLoc = await aliceOpenLoc.legalOfficer.reviewFile({ hash, decision: "ACCEPT" }) as OpenLoc; expect(aliceOpenLoc.data().files[0].status).toBe("REVIEW_ACCEPTED"); await waitFor({ @@ -147,23 +154,6 @@ export async function requestTransactionLoc(state: State, linkTarget: UUID) { expect(aliceOpenLoc.data().files[0].status).toBe("ACKNOWLEDGED"); // Continue with metadata - aliceOpenLoc = await aliceOpenLoc.refresh() as OpenLoc; - aliceOpenLoc = await aliceOpenLoc.legalOfficer.reviewMetadata({ nameHash, decision: "REJECT", rejectReason: "Because" }) as OpenLoc; - expect(aliceOpenLoc.data().metadata[0].status).toBe("REVIEW_REJECTED"); - expect(aliceOpenLoc.data().metadata[0].rejectReason).toBe("Because"); - await waitFor({ - producer: async state => state ? await state.refresh() : aliceOpenLoc, - predicate: state => state.data().metadata[0].reviewedOn !== undefined, - }); - openLoc = await openLoc.refresh() as OpenLoc; - openLoc = await openLoc.deleteMetadata({ nameHash }) as OpenLoc; - openLoc = await openLoc.addMetadata({ - name: metadataName, - value: "Some value" - }) as OpenLoc; - openLoc = await openLoc.requestMetadataReview({ nameHash }) as OpenLoc; - aliceOpenLoc = await aliceOpenLoc.refresh() as OpenLoc; - aliceOpenLoc = await aliceOpenLoc.legalOfficer.reviewMetadata({ nameHash, decision: "ACCEPT" }) as OpenLoc; openLoc = await openLoc.refresh() as OpenLoc; openLoc = await openLoc.publishMetadata({ nameHash, signer }); expect(openLoc.data().metadata[0].status).toBe("PUBLISHED"); diff --git a/packages/client/package.json b/packages/client/package.json index f7bacd9b..e3ce9304 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@logion/client", - "version": "0.32.0", + "version": "0.33.0-1", "description": "logion SDK for client applications", "main": "dist/index.js", "packageManager": "yarn@3.2.0", diff --git a/packages/client/src/Loc.ts b/packages/client/src/Loc.ts index 96b8cc85..7e77ede7 100644 --- a/packages/client/src/Loc.ts +++ b/packages/client/src/Loc.ts @@ -1031,13 +1031,15 @@ export abstract class LocRequestState extends State { } } -export abstract class LegalOfficerLocRequestCommands { +export interface LegalOfficerCommandsConstructorArgs { + locId: UUID; + client: AuthenticatedLocClient; + request: LocRequestState; +} - constructor(args: { - locId: UUID, - client: AuthenticatedLocClient, - request: LocRequestState, - }) { +export class LegalOfficerCommands { + + constructor(args: LegalOfficerCommandsConstructorArgs) { this.locId = args.locId; this.client = args.client; this.request = args.request; @@ -1048,6 +1050,22 @@ export abstract class LegalOfficerLocRequestCommands { protected client: AuthenticatedLocClient; protected request: LocRequestState; +} + +export interface LegalOfficerRestrictedDeliveryCommands { + setCollectionFileRestrictedDelivery(params: { + hash: Hash, + restrictedDelivery: boolean, + }): Promise; +} + +export class LegalOfficerRestrictedDeliveryCommandsImpl +extends LegalOfficerCommands +implements LegalOfficerRestrictedDeliveryCommands { + + constructor(args: LegalOfficerCommandsConstructorArgs) { + super(args); + } async setCollectionFileRestrictedDelivery(params: { hash: Hash, @@ -1151,45 +1169,46 @@ export abstract class EditableRequest extends LocRequestState { }); return await this.refresh() as EditableRequest; } +} - get legalOfficer(): LegalOfficerEditableRequestCommands { - return new LegalOfficerEditableRequestCommands({ - locId: this.locId, - client: this.locSharedState.client, - request: this, - }); - } +export type ReviewableRequest = OpenLoc | PendingRequest; + +export interface LegalOfficeReviewCommands { + + reviewFile(params: ReviewFileParams): Promise; + reviewMetadata(params: ReviewMetadataParams): Promise; + reviewLink(params: ReviewLinkParams): Promise; } -/** - * Encapsulated calls can be used only by a Logion Legal Officer. - */ -export class LegalOfficerEditableRequestCommands extends LegalOfficerLocRequestCommands { +export class LegalOfficeReviewCommandsImpl extends LegalOfficerCommands implements LegalOfficeReviewCommands { + + constructor(args: LegalOfficerCommandsConstructorArgs) { + super(args); + } - async reviewFile(params: ReviewFileParams): Promise { + async reviewFile(params: ReviewFileParams): Promise { await this.client.reviewFile({ ...params, locId: this.locId, }); - return await this.request.refresh() as EditableRequest; + return await this.request.refresh() as ReviewableRequest; } - async reviewMetadata(params: ReviewMetadataParams): Promise { + async reviewMetadata(params: ReviewMetadataParams): Promise { await this.client.reviewMetadata({ ...params, locId: this.locId, }); - return await this.request.refresh() as EditableRequest; + return await this.request.refresh() as ReviewableRequest; } - async reviewLink(params: ReviewLinkParams): Promise { + async reviewLink(params: ReviewLinkParams): Promise { await this.client.reviewLink({ ...params, locId: this.locId, }); - return await this.request.refresh() as EditableRequest; + return await this.request.refresh() as ReviewableRequest; } - } export interface IdenfyVerificationCreation { @@ -1267,23 +1286,16 @@ export class PendingRequest extends LocRequestState { } } -export class LegalOfficerPendingRequestCommands { +export class LegalOfficerPendingRequestCommands +extends LegalOfficerCommands +implements LegalOfficeReviewCommands { - constructor(args: { - locId: UUID, - client: AuthenticatedLocClient, - request: PendingRequest, - }) { - this.locId = args.locId; - this.client = args.client; - this.request = args.request; + constructor(args: LegalOfficerCommandsConstructorArgs) { + super(args); + this.reviewCommands = new LegalOfficeReviewCommandsImpl(args); } - private readonly locId: UUID; - - private client: AuthenticatedLocClient; - - private request: PendingRequest; + private reviewCommands: LegalOfficeReviewCommands; async reject(reason: string): Promise { await this.client.rejectLoc({ @@ -1346,6 +1358,18 @@ export class LegalOfficerPendingRequestCommands { return undefined; } } + + reviewFile(params: ReviewFileParams): Promise { + return this.reviewCommands.reviewFile(params) as Promise; + } + + reviewMetadata(params: ReviewMetadataParams): Promise { + return this.reviewCommands.reviewMetadata(params) as Promise; + } + + reviewLink(params: ReviewLinkParams): Promise { + return this.reviewCommands.reviewLink(params) as Promise; + } } export class ReviewedRequest extends LocRequestState { @@ -1663,7 +1687,7 @@ export class OpenLoc extends EditableRequest { }); } - override get legalOfficer(): LegalOfficerOpenRequestCommands { + get legalOfficer(): LegalOfficerOpenRequestCommands { return new LegalOfficerOpenRequestCommands({ locId: this.locId, client: this.locSharedState.client, @@ -1676,24 +1700,26 @@ export class OpenLoc extends EditableRequest { * Encapsulated calls can be used only by a Logion Legal Officer. */ export class LegalOfficerOpenRequestCommands -extends LegalOfficerEditableRequestCommands -implements LegalOfficerNonVoidedCommands, LegalOfficerLocWithSelectableIssuersCommands { +extends LegalOfficerCommands +implements LegalOfficeReviewCommands, LegalOfficerNonVoidedCommands, LegalOfficerLocWithSelectableIssuersCommands, LegalOfficerRestrictedDeliveryCommands { - constructor(args: { - locId: UUID, - client: AuthenticatedLocClient, - request: EditableRequest, - }) { + constructor(args: LegalOfficerCommandsConstructorArgs) { super(args); this.legalOfficerNonVoidedCommands = new LegalOfficerNonVoidedCommandsImpl(args); this.legalOfficerLocWithSelectableIssuersCommands = new LegalOfficerLocWithSelectableIssuersCommandsImpl(args); + this.reviewCommands = new LegalOfficeReviewCommandsImpl(args); + this.restrictedDeliveryCommands = new LegalOfficerRestrictedDeliveryCommandsImpl(args); } private legalOfficerNonVoidedCommands: LegalOfficerNonVoidedCommands; private legalOfficerLocWithSelectableIssuersCommands: LegalOfficerLocWithSelectableIssuersCommands; + private reviewCommands: LegalOfficeReviewCommands; + + private restrictedDeliveryCommands: LegalOfficerRestrictedDeliveryCommands; + async acknowledgeFile(parameters: AckFileParams): Promise { const file = this.request.data().files.find(file => file.hash.equalTo(parameters.hash) && file.status === "PUBLISHED"); if(!file) { @@ -1788,13 +1814,29 @@ implements LegalOfficerNonVoidedCommands, LegalOfficerLocWithSelectableIssuersCo async unselectIssuer(params: SelectUnselectIssuerParams): Promise { return this.legalOfficerLocWithSelectableIssuersCommands.unselectIssuer(params); } + + reviewFile(params: ReviewFileParams): Promise { + return this.reviewCommands.reviewFile(params); + } + + reviewMetadata(params: ReviewMetadataParams): Promise { + return this.reviewCommands.reviewMetadata(params); + } + + reviewLink(params: ReviewLinkParams): Promise { + return this.reviewCommands.reviewLink(params); + } + + setCollectionFileRestrictedDelivery(params: { hash: Hash; restrictedDelivery: boolean; }): Promise { + return this.restrictedDeliveryCommands.setCollectionFileRestrictedDelivery(params); + } } export interface LegalOfficerNonVoidedCommands { voidLoc(params: VoidParams): Promise; } -export class LegalOfficerNonVoidedCommandsImpl extends LegalOfficerLocRequestCommands implements LegalOfficerNonVoidedCommands { +export class LegalOfficerNonVoidedCommandsImpl extends LegalOfficerCommands implements LegalOfficerNonVoidedCommands { async voidLoc(params: VoidParams): Promise { await this.client.voidLoc({ @@ -1812,7 +1854,7 @@ export interface LegalOfficerLocWithSelectableIssuersCommands -extends LegalOfficerLocRequestCommands +extends LegalOfficerCommands implements LegalOfficerLocWithSelectableIssuersCommands { async getVerifiedIssuers(): Promise { @@ -2141,20 +2183,19 @@ export class ClosedCollectionLoc extends ClosedOrVoidCollectionLoc { export class LegalOfficerClosedCollectionLocCommands extends LegalOfficerNonVoidedCommandsImpl -implements LegalOfficerLocWithSelectableIssuersCommands { +implements LegalOfficerLocWithSelectableIssuersCommands, LegalOfficerRestrictedDeliveryCommands { - constructor(args: { - locId: UUID, - client: AuthenticatedLocClient, - request: ClosedCollectionLoc, - }) { + constructor(args: LegalOfficerCommandsConstructorArgs) { super(args); this.legalOfficerLocWithSelectableIssuersCommands = new LegalOfficerLocWithSelectableIssuersCommandsImpl(args); + this.restrictedDeliveryCommands = new LegalOfficerRestrictedDeliveryCommandsImpl(args); } private legalOfficerLocWithSelectableIssuersCommands: LegalOfficerLocWithSelectableIssuersCommands; + private restrictedDeliveryCommands: LegalOfficerRestrictedDeliveryCommandsImpl; + async getVerifiedIssuers(): Promise { return this.legalOfficerLocWithSelectableIssuersCommands.getVerifiedIssuers(); } @@ -2166,6 +2207,13 @@ implements LegalOfficerLocWithSelectableIssuersCommands { async unselectIssuer(params: SelectUnselectIssuerParams): Promise { return this.legalOfficerLocWithSelectableIssuersCommands.unselectIssuer(params); } + + setCollectionFileRestrictedDelivery(params: { + hash: Hash, + restrictedDelivery: boolean, + }): Promise { + return this.restrictedDeliveryCommands.setCollectionFileRestrictedDelivery(params); + } } async function requestSof(locSharedState: LocSharedState, locId: UUID, itemId?: Hash): Promise { diff --git a/packages/client/src/Token.ts b/packages/client/src/Token.ts index 7f970ada..37efef11 100644 --- a/packages/client/src/Token.ts +++ b/packages/client/src/Token.ts @@ -257,7 +257,7 @@ export function validatePsp34TokenId(tokenId: string): TokenValidationResult { } } -function isAnyNumber(value: any): boolean { +function isAnyNumber(value: any): boolean { // eslint-disable-line @typescript-eslint/no-explicit-any return typeof value === "number" || (typeof value === "string" && /[0-9]+/.test(value)) ; diff --git a/packages/crossmint/package.json b/packages/crossmint/package.json index 1d6afb9a..e4343b46 100644 --- a/packages/crossmint/package.json +++ b/packages/crossmint/package.json @@ -1,6 +1,6 @@ { "name": "@logion/crossmint", - "version": "0.1.26", + "version": "0.1.27-1", "description": "logion SDK for Crossmint", "main": "dist/index.js", "packageManager": "yarn@3.2.0", diff --git a/packages/extension/package.json b/packages/extension/package.json index 163f4950..ccb4b08e 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -1,6 +1,6 @@ { "name": "@logion/extension", - "version": "0.7.0", + "version": "0.7.1-1", "description": "logion SDK for Polkadot JS extension", "main": "dist/index.js", "packageManager": "yarn@3.2.0", diff --git a/packages/multiversx/package.json b/packages/multiversx/package.json index d45191de..a6b0f1e8 100644 --- a/packages/multiversx/package.json +++ b/packages/multiversx/package.json @@ -1,6 +1,6 @@ { "name": "@logion/multiversx", - "version": "0.1.7", + "version": "0.1.8-1", "description": "logion SDK for MultiversX", "main": "dist/index.js", "packageManager": "yarn@3.2.0",