MCPcopy Create free account
hub / github.com/chhoumann/quickadd / fitSecretId

Function fitSecretId

src/utils/userScriptSecrets.ts:95–126  ·  view source on GitHub ↗
(
	commandPart: string,
	settingPart: string,
	suffixPart?: string,
)

Source from the content-addressed store, hash-verified

93}
94
95function fitSecretId(
96 commandPart: string,
97 settingPart: string,
98 suffixPart?: string,
99): string {
100 const rawParts = suffixPart
101 ? [USER_SCRIPT_SECRET_PREFIX, commandPart, settingPart, suffixPart]
102 : [USER_SCRIPT_SECRET_PREFIX, commandPart, settingPart];
103 const raw = rawParts.join("-");
104 if (raw.length <= MAX_SECRET_ID_LENGTH) return raw;
105
106 const hash = hashSecretId(
107 [commandPart, settingPart, suffixPart].filter(Boolean).join(":"),
108 );
109 const separatorBudget = suffixPart ? 4 : 3;
110 const partBudget =
111 MAX_SECRET_ID_LENGTH -
112 USER_SCRIPT_SECRET_PREFIX.length -
113 hash.length -
114 (suffixPart?.length ?? 0) -
115 separatorBudget;
116 const commandBudget = Math.max(8, Math.floor(partBudget * 0.6));
117 const settingBudget = Math.max(8, partBudget - commandBudget);
118
119 return [
120 USER_SCRIPT_SECRET_PREFIX,
121 truncateSecretIdPart(commandPart, commandBudget),
122 truncateSecretIdPart(settingPart, settingBudget),
123 ...(suffixPart ? [suffixPart] : []),
124 hash,
125 ].join("-");
126}
127
128function formatSecretError(error: unknown): string {
129 return (error as Error)?.message ?? String(error);

Callers 2

buildUserScriptSecretIdFunction · 0.85
buildAvailableSecretRefFunction · 0.85

Calls 2

hashSecretIdFunction · 0.85
truncateSecretIdPartFunction · 0.85

Tested by

no test coverage detected