mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 16:30:30 +00:00
28 lines
815 B
TypeScript
28 lines
815 B
TypeScript
type PendingState<TPending> = {
|
|
pendingById: Record<string, TPending>;
|
|
};
|
|
|
|
export async function rejectPendingPairingRequest<
|
|
TPending,
|
|
TState extends PendingState<TPending>,
|
|
TIdKey extends string,
|
|
>(params: {
|
|
requestId: string;
|
|
idKey: TIdKey;
|
|
loadState: () => Promise<TState>;
|
|
persistState: (state: TState) => Promise<void>;
|
|
getId: (pending: TPending) => string;
|
|
}): Promise<({ requestId: string } & Record<TIdKey, string>) | null> {
|
|
const state = await params.loadState();
|
|
const pending = state.pendingById[params.requestId];
|
|
if (!pending) {
|
|
return null;
|
|
}
|
|
delete state.pendingById[params.requestId];
|
|
await params.persistState(state);
|
|
return {
|
|
requestId: params.requestId,
|
|
[params.idKey]: params.getId(pending),
|
|
} as { requestId: string } & Record<TIdKey, string>;
|
|
}
|