mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-22 22:48:11 +00:00
refactor: unify extension allowlist resolver and directory scaffolding
This commit is contained in:
@@ -1,40 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
mapBasicAllowlistResolutionEntries,
|
||||
type BasicAllowlistResolutionEntry,
|
||||
} from "./allowlist-resolution.js";
|
||||
import { mapAllowlistResolutionInputs } from "./allowlist-resolution.js";
|
||||
|
||||
describe("mapBasicAllowlistResolutionEntries", () => {
|
||||
it("maps entries to normalized allowlist resolver output", () => {
|
||||
const entries: BasicAllowlistResolutionEntry[] = [
|
||||
{
|
||||
input: "alice",
|
||||
resolved: true,
|
||||
id: "U123",
|
||||
name: "Alice",
|
||||
note: "ok",
|
||||
describe("mapAllowlistResolutionInputs", () => {
|
||||
it("maps inputs sequentially and preserves order", async () => {
|
||||
const visited: string[] = [];
|
||||
const result = await mapAllowlistResolutionInputs({
|
||||
inputs: ["one", "two", "three"],
|
||||
mapInput: async (input) => {
|
||||
visited.push(input);
|
||||
return input.toUpperCase();
|
||||
},
|
||||
{
|
||||
input: "bob",
|
||||
resolved: false,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
expect(mapBasicAllowlistResolutionEntries(entries)).toEqual([
|
||||
{
|
||||
input: "alice",
|
||||
resolved: true,
|
||||
id: "U123",
|
||||
name: "Alice",
|
||||
note: "ok",
|
||||
},
|
||||
{
|
||||
input: "bob",
|
||||
resolved: false,
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
note: undefined,
|
||||
},
|
||||
]);
|
||||
expect(visited).toEqual(["one", "two", "three"]);
|
||||
expect(result).toEqual(["ONE", "TWO", "THREE"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,3 +17,14 @@ export function mapBasicAllowlistResolutionEntries(
|
||||
note: entry.note,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function mapAllowlistResolutionInputs<T>(params: {
|
||||
inputs: string[];
|
||||
mapInput: (input: string) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
const results: T[] = [];
|
||||
for (const input of params.inputs) {
|
||||
results.push(await params.mapInput(input));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ export { isDangerousNameMatchingEnabled } from "../config/dangerous-name-matchin
|
||||
export type { FileLockHandle, FileLockOptions } from "./file-lock.js";
|
||||
export { acquireFileLock, withFileLock } from "./file-lock.js";
|
||||
export {
|
||||
mapAllowlistResolutionInputs,
|
||||
mapBasicAllowlistResolutionEntries,
|
||||
type BasicAllowlistResolutionEntry,
|
||||
} from "./allowlist-resolution.js";
|
||||
@@ -515,6 +516,12 @@ export { optionalStringEnum, stringEnum } from "../agents/schema/typebox.js";
|
||||
export type { PollInput } from "../polls.js";
|
||||
|
||||
export { buildChannelConfigSchema } from "../channels/plugins/config-schema.js";
|
||||
export {
|
||||
listDirectoryGroupEntriesFromMapKeys,
|
||||
listDirectoryGroupEntriesFromMapKeysAndAllowFrom,
|
||||
listDirectoryUserEntriesFromAllowFrom,
|
||||
listDirectoryUserEntriesFromAllowFromAndMapKeys,
|
||||
} from "../channels/plugins/directory-config-helpers.js";
|
||||
export {
|
||||
clearAccountEntryFields,
|
||||
deleteAccountFromConfigSection,
|
||||
|
||||
Reference in New Issue
Block a user