openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.37 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as parseConfigPathArrayIndex } from "./path-array-index-qP-D1DoI.mjs";
//#region src/secrets/json-pointer.ts
/** JSON Pointer token helpers for file-backed secret refs. */
/**
* Encodes one JSON Pointer path token using RFC 6901 escaping.
*/
function encodeJsonPointerToken(e) {
return e.replace(/~/g, "~0").replace(/\//g, "~1");
}
/**
* Reads a value from a JSON-like document using an absolute JSON Pointer.
* Missing segments throw by default; `onMissing: "undefined"` is for optional probes.
*/
function readJsonPointer(e, t, n = {}) {
const r = n.onMissing ?? "throw";
const fail = (e) => {
if (r === "throw") throw new Error(e);
};
if (!t.startsWith("/")) return fail("File-backed secret ids must be absolute JSON pointers (for example: \"/providers/openai/apiKey\").");
let i = e;
for (const e of t.slice(1).split("/")) {
const t = e.replace(/~1/g, "/").replace(/~0/g, "~");
if (Array.isArray(i)) {
const e = parseConfigPathArrayIndex(t);
if (e === void 0 || e >= i.length) return fail(`JSON pointer segment "${t}" is out of bounds.`);
i = i[e];
continue;
}
if (!isRecord(i) || !Object.hasOwn(i, t)) return fail(`JSON pointer segment "${t}" does not exist.`);
i = i[t];
}
return i;
}
//#endregion
export { readJsonPointer as n, encodeJsonPointerToken as t };