feat(companysetting): add writeonly column and mask values for GUI

This commit is contained in:
seb
2026-09-15 08:48:24 +02:00
parent 2e16a22c99
commit e56f725bd9
10 changed files with 155 additions and 107 deletions

View File

@@ -11,16 +11,23 @@ export default function list(pool) {
/**
* Lists the settings of the user's selected company, optionally only frontend-visible ones.
*
* Write-only settings (such as `keys.tavily`, `keys.openrouter`) have their value masked
* with `'***'` by default for usergui presentation.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {object} [options] - Optional options.
* @param {boolean} [options.frontendOnly] - Only return frontend-visible settings.
* @returns {Promise<Array<{key: string, value: string, frontend: boolean}>>} The settings.
* @param {boolean} [options.maskWriteonly] - Whether to mask writeonly settings with '***'. Defaults to `true`.
* @returns {Promise<Array<{key: string, value: string, frontend: boolean, writeonly: boolean}>>} The settings.
*
* @example
* const settings = await store.companysetting.list(42, { frontendOnly: true });
* // => [{ key, value, frontend }]
* // => [{ key, value, frontend, writeonly }]
*/
return async (googleAuthId, { frontendOnly = false } = {}) => {
return async (
googleAuthId,
{ frontendOnly = false, maskWriteonly = true } = {},
) => {
const { companyId } = await access(googleAuthId);
const result = await pool
@@ -28,6 +35,8 @@ export default function list(pool) {
.input('companyId', companyId)
.query(frontendOnly ? LIST_BY_COMPANY_FRONTEND : LIST_BY_COMPANY);
return result.recordset.map(shapeSetting);
return result.recordset.map((row) =>
shapeSetting(row, { exposeValue: !maskWriteonly }),
);
};
}