Finish scoped plugin config review fixes

This commit is contained in:
Paperclip Bot 2026-06-03 14:14:42 +00:00
parent 0509d08f3c
commit 89cc5c4e20
2 changed files with 19631 additions and 6 deletions

File diff suppressed because it is too large Load diff

View file

@ -2034,7 +2034,9 @@ export function secretService(db: Db) {
required?: boolean;
label?: string | null;
}>,
options?: { db?: SecretBindingDb },
) => {
const bindingDb = options?.db ?? db;
const normalizedRefs: Array<{
secretId: string;
configPath: string;
@ -2043,7 +2045,7 @@ export function secretService(db: Db) {
label: string | null;
}> = [];
for (const ref of refs) {
await assertSecretInCompany(companyId, ref.secretId);
await assertSecretInCompany(companyId, ref.secretId, bindingDb);
normalizedRefs.push({
secretId: ref.secretId,
configPath: ref.configPath,
@ -2055,10 +2057,10 @@ export function secretService(db: Db) {
const pathPrefixes = [...new Set(normalizedRefs.map((ref) => ref.configPath.split(".")[0]))];
await db.transaction(async (tx) => {
const writeBindings = async (targetDb: SecretBindingDb) => {
if (pathPrefixes.length > 0) {
for (const pathPrefix of pathPrefixes) {
await tx
await targetDb
.delete(companySecretBindings)
.where(
and(
@ -2070,7 +2072,7 @@ export function secretService(db: Db) {
);
}
} else {
await tx
await targetDb
.delete(companySecretBindings)
.where(
and(
@ -2081,7 +2083,7 @@ export function secretService(db: Db) {
);
}
if (normalizedRefs.length === 0) return;
await tx.insert(companySecretBindings).values(
await targetDb.insert(companySecretBindings).values(
normalizedRefs.map((ref) => ({
companyId,
secretId: ref.secretId,
@ -2093,7 +2095,15 @@ export function secretService(db: Db) {
label: ref.label,
})),
);
});
};
if (options?.db) {
await writeBindings(bindingDb);
} else {
await db.transaction(async (tx) => {
await writeBindings(tx as SecretBindingDb);
});
}
return normalizedRefs;
},