Skip to content

Commit

Permalink
feat(app-ws): add call PublishCountersigningSession
Browse files Browse the repository at this point in the history
  • Loading branch information
jost-s committed Nov 12, 2024
1 parent 39aaf6c commit b9d9772
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ export type AbandonCountersigningSessionStateRequest = CellId;
*/
export type AbandonCountersigningSessionStateResponse = null;

/**
* Cell id for which the countersigning session should be published.
*
* @public
*/
export type PublishCountersigningSessionStateRequest = CellId;

/**
* @public
*/
export type PublishCountersigningSessionStateResponse = null;

export enum CountersigningSessionStateType {
Accepted = "Accepted",
SignaturesCollected = "SignaturesCollected",
Expand Down
53 changes: 53 additions & 0 deletions src/api/app/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
GetCountersigningSessionStateResponse,
AbandonCountersigningSessionStateRequest,
AbandonCountersigningSessionStateResponse,
PublishCountersigningSessionStateRequest,
PublishCountersigningSessionStateResponse,
} from "./types.js";
import {
getHostZomeCallSigner,
Expand Down Expand Up @@ -123,6 +125,10 @@ export class AppWebsocket implements AppClient {
AbandonCountersigningSessionStateRequest,
AbandonCountersigningSessionStateResponse
>;
private readonly publishCountersigningSessionRequester: Requester<
PublishCountersigningSessionStateRequest,
PublishCountersigningSessionStateResponse
>;

private constructor(
client: WsClient,
Expand Down Expand Up @@ -189,6 +195,11 @@ export class AppWebsocket implements AppClient {
"abandon_countersigning_session",
this.defaultTimeout
);
this.publishCountersigningSessionRequester = AppWebsocket.requester(
this.client,
"publish_countersigning_session",
this.defaultTimeout
);

// Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
// Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
Expand Down Expand Up @@ -481,6 +492,48 @@ export class AppWebsocket implements AppClient {
return this.abandonCountersigningSessionRequester(args);
}

/**
* Publish an unresolved countersigning session.
*
* If the current session has not been resolved automatically, it can be forcefully published.
* A condition for this call to succeed is that at least one attempt has been made to resolve
* it automatically.
*
* # Returns
*
* [`AppResponse::PublishCountersigningSessionTriggered`]
*
* The session is marked for publishing and the countersigning workflow was triggered. The session
* has not been published yet.
*
* Upon successful publishing the system signal [`SystemSignal::SuccessfulCountersigning`] will
* be emitted and the session removed from state, so that [`AppRequest::GetCountersigningSessionState`]
* would return `None`.
*
* In the countersigning workflow it will first be attempted to resolve the session with incoming
* signatures of the countersigned entries, before force-publishing the session. In a very rare event
* it could happen that in just the moment where the [`AppRequest::PublishCountersigningSession`]
* is made, signatures for this session come in. If they are valid, the session will be resolved and
* published as usual. Should they be invalid, however, the flag to publish the session is erased.
* In such cases this request can be retried until the session has been published successfully.
*
* # Errors
*
* [`CountersigningError::WorkspaceDoesNotExist`] likely indicates that an invalid cell id was
* passed in to the call.
*
* [`CountersigningError::SessionNotFound`] when no ongoing session could be found for the provided
* cell id.
*
* [`CountersigningError::SessionNotUnresolved`] when an attempt to resolve the session
* automatically has not been made.
*/
async publishCountersigningSession(
args: PublishCountersigningSessionStateRequest
) {
return this.publishCountersigningSessionRequester(args);
}

/**
* Register an event listener for signals.
*
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/app-websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,16 @@ test.only(
"there should not be a countersigning session"
);
}

try {
await appWs.publishCountersigningSession(cell_id);
t.fail("there should not be a countersigning session to be published");
} catch (error) {
assert(error instanceof Error);
t.assert(
error.message.includes("SessionNotFound"),
"there should not be a countersigning session"
);
}
})
);

0 comments on commit b9d9772

Please sign in to comment.