UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 920 B
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as parseConfigPathArrayIndex}from"./path-array-index-DO9QgC44.mjs"; //!src/secrets/json-pointer.ts function encodeJsonPointerToken(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}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}export{readJsonPointer as n,encodeJsonPointerToken as t};