43 lines
1.6 KiB
JavaScript
43 lines
1.6 KiB
JavaScript
import {
|
|
LIST_BY_COMPANY,
|
|
LIST_BY_COMPANY_FRONTEND,
|
|
} from '../../sql/companysetting.js';
|
|
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
|
import shapeSetting from './shapeSetting.js';
|
|
|
|
export default function list(pool) {
|
|
const access = resolveSelectedCompanyAccess(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.
|
|
* @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, writeonly }]
|
|
*/
|
|
return async (
|
|
googleAuthId,
|
|
{ frontendOnly = false, maskWriteonly = true } = {},
|
|
) => {
|
|
const { companyId } = await access(googleAuthId);
|
|
|
|
const result = await pool
|
|
.request()
|
|
.input('companyId', companyId)
|
|
.query(frontendOnly ? LIST_BY_COMPANY_FRONTEND : LIST_BY_COMPANY);
|
|
|
|
return result.recordset.map((row) =>
|
|
shapeSetting(row, { exposeValue: !maskWriteonly }),
|
|
);
|
|
};
|
|
}
|