1+ /**
2+ * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
3+ * SPDX-License-Identifier: AGPL-3.0-or-later
4+ */
5+
6+ type SignerLike = {
7+ me ?: boolean
8+ sign_request_uuid ?: string | null
9+ }
10+
11+ type DocumentSettingsLike = {
12+ isApprover ?: boolean
13+ }
14+
15+ type DocumentLike = {
16+ id ?: number | string | null
17+ uuid ?: string | null
18+ signers ?: SignerLike [ ] | null
19+ settings ?: DocumentSettingsLike | null
20+ }
21+
22+ function isNonEmptyString ( value : unknown ) : value is string {
23+ return typeof value === 'string' && value . length > 0
24+ }
25+
26+ export function getCurrentSigner ( document : DocumentLike | null | undefined ) : SignerLike | null {
27+ if ( ! Array . isArray ( document ?. signers ) ) {
28+ return null
29+ }
30+
31+ return document . signers . find ( ( signer ) => signer ?. me === true ) ?? null
32+ }
33+
34+ export function getCurrentSignerSignRequestUuid (
35+ document : DocumentLike | null | undefined ,
36+ fallbackUuid : string | null = null ,
37+ ) : string | null {
38+ const signer = getCurrentSigner ( document )
39+ if ( isNonEmptyString ( signer ?. sign_request_uuid ) ) {
40+ return signer . sign_request_uuid
41+ }
42+
43+ return isNonEmptyString ( fallbackUuid ) ? fallbackUuid : null
44+ }
45+
46+ export function getSigningRouteUuid (
47+ document : DocumentLike | null | undefined ,
48+ fallbackUuid : string | null = null ,
49+ ) : string | null {
50+ if ( document ?. settings ?. isApprover === true && isNonEmptyString ( document ?. uuid ) ) {
51+ return document . uuid
52+ }
53+
54+ return getCurrentSignerSignRequestUuid ( document , fallbackUuid )
55+ }
56+
57+ export function getValidationRouteUuid ( document : DocumentLike | null | undefined ) : string | number | null {
58+ if ( isNonEmptyString ( document ?. uuid ) ) {
59+ return document . uuid
60+ }
61+
62+ if ( typeof document ?. id === 'number' || typeof document ?. id === 'string' ) {
63+ return document . id
64+ }
65+
66+ return null
67+ }
0 commit comments