openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.95 kB
JavaScript
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{i as isOpenClawCorrectionSemver,o as normalizeLegacyDotBetaVersion,r as compareValidSemver,s as parseOpenClawReleaseVersion,t as compareOpenClawReleaseVersions}from"./semver-Bem35wCz.mjs";import{prerelease,valid}from"semver";
//!src/infra/npm-registry-spec.ts
function buildNpmResolutionFields(e){return{resolvedName:e?.name,resolvedVersion:e?.version,resolvedSpec:e?.resolvedSpec,integrity:e?.integrity,shasum:e?.shasum,resolvedAt:e?.resolvedAt}}const DIST_TAG_RE=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function parseRegistryNpmSpecResult(e){const t=e.trim();if(!t)return{ok:false,error:`missing npm spec`};if(/\s/.test(t))return{ok:false,error:`unsupported npm spec: whitespace is not allowed`};if(t.includes(`://`))return{ok:false,error:`unsupported npm spec: URLs are not allowed`};if(t.includes(`#`))return{ok:false,error:`unsupported npm spec: git refs are not allowed`};if(t.includes(`:`))return{ok:false,error:`unsupported npm spec: protocol specs are not allowed`};const n=t.lastIndexOf(`@`);const r=n>0;const i=r?t.slice(0,n):t;const a=r?t.slice(n+1):``;if(!(i.startsWith(`@`)?/^@[a-z0-9][a-z0-9-._~]*\/[a-z0-9][a-z0-9-._~]*$/.test(i):/^[a-z0-9][a-z0-9-._~]*$/.test(i)))return{ok:false,error:`unsupported npm spec: expected <name> or <name>@<version> from the npm registry`};let o=null;if(r){if(!a)return{ok:false,error:`unsupported npm spec: missing version/tag after @`};if(/[\\/]/.test(a))return{ok:false,error:`unsupported npm spec: invalid version/tag`};o=valid(a);if(!o&&!DIST_TAG_RE.test(a))return{ok:false,error:`unsupported npm spec: use an exact version or dist-tag (ranges are not allowed)`}}return{ok:true,parsed:{name:i,raw:t,...r?{selector:a}:{},selectorKind:!r?`none`:o?`exact-version`:`tag`,selectorIsPrerelease:o!==null&&prerelease(o)!==null&&!isOpenClawStableCorrectionVersion(a)}}}function parseRegistryNpmSpec(e){const t=parseRegistryNpmSpecResult(e);return t.ok?t.parsed:null}function validateRegistryNpmSpec(e){const t=parseRegistryNpmSpecResult(e);return t.ok?null:t.error}function isExactSemverVersion(e){return valid(e.trim())!==null}function isOpenClawStableCorrectionVersion(e){const t=parseOpenClawReleaseVersion(e);return t!==null&&isOpenClawCorrectionSemver(t)}function resolveOpenClawReleaseCohortVersion(e){const t=e.trim();const n=parseOpenClawReleaseVersion(t);return n&&isOpenClawCorrectionSemver(n)?`${n.major}.${n.minor}.${n.patch}`:t}function compareSemverStrings(e,t){if(e&&t){const n=compareOpenClawReleaseVersions(e,t);if(n!=null)return n}const n=e?normalizeLegacyDotBetaVersion(e):null;const r=t?normalizeLegacyDotBetaVersion(t):null;return n&&r?compareValidSemver(n,r):null}function isPrereleaseSemverVersion(e){const t=e.trim();return prerelease(t)!==null&&!isOpenClawStableCorrectionVersion(t)}function isPrereleaseResolutionAllowed(e){if(!e.resolvedVersion||!isPrereleaseSemverVersion(e.resolvedVersion))return true;if(e.spec.selectorKind===`none`)return false;if(e.spec.selectorKind===`exact-version`)return e.spec.selectorIsPrerelease;return normalizeLowercaseStringOrEmpty(e.spec.selector)!==`latest`}function formatPrereleaseResolutionError(e){const t=e.spec.selectorKind===`none`||normalizeLowercaseStringOrEmpty(e.spec.selector)===`latest`?`Use "npm:${e.spec.name}@beta" (or another prerelease tag) or an exact prerelease version to opt in explicitly.`:`Use an explicit prerelease tag or exact prerelease version if you want prerelease installs.`;return`Resolved ${e.spec.raw} to prerelease version ${e.resolvedVersion}, but prereleases are only installed when explicitly requested. ${t}`}export{isPrereleaseResolutionAllowed as a,parseRegistryNpmSpecResult as c,isExactSemverVersion as i,resolveOpenClawReleaseCohortVersion as l,compareSemverStrings as n,isPrereleaseSemverVersion as o,formatPrereleaseResolutionError as r,parseRegistryNpmSpec as s,buildNpmResolutionFields as t,validateRegistryNpmSpec as u};