@kanonak-protocol/sdk 5.29.0 → 5.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/chunk-7UYXTYXC.js +1 -0
  3. package/dist/{chunk-HBG6SC5L.js → chunk-BS7RRG7D.js} +1 -1
  4. package/dist/chunk-BZ3YTI3C.js +2 -0
  5. package/dist/chunk-CR5QY3LJ.js +68 -0
  6. package/dist/{chunk-4SMQ7G23.js → chunk-EVMSO7HJ.js} +1 -1
  7. package/dist/chunk-F67UH4FD.js +1 -0
  8. package/dist/chunk-HF5FJBS2.js +1 -0
  9. package/dist/{chunk-JFBPQN6T.js → chunk-IS3AQKB4.js} +1 -1
  10. package/dist/{chunk-ZRCJGTEV.js → chunk-J4ZD6IF6.js} +1 -1
  11. package/dist/chunk-KIBR3HAT.js +1 -0
  12. package/dist/{chunk-GMK4YL3X.js → chunk-L2J7WD7E.js} +1 -1
  13. package/dist/chunk-PVUBHIU2.js +1 -0
  14. package/dist/{chunk-D66LUZDB.js → chunk-V3DH67P3.js} +1 -1
  15. package/dist/{chunk-ANJAHB4N.js → chunk-Z5Y4MCW5.js} +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/parsing/KanonakObjectParser.d.ts +9 -0
  19. package/dist/parsing/index.js +1 -1
  20. package/dist/reasoning/index.js +1 -1
  21. package/dist/repositories/PublisherIndex.d.ts +13 -1
  22. package/dist/repositories/browser.js +1 -1
  23. package/dist/repositories/buildLocalFirstRepository.d.ts +1 -0
  24. package/dist/repositories/index.js +1 -1
  25. package/dist/resolution/ResourceTypeClassifier.d.ts +9 -0
  26. package/dist/resolution/importMode.d.ts +26 -0
  27. package/dist/resolution/index.d.ts +1 -0
  28. package/dist/resolution/index.js +1 -1
  29. package/dist/search/index.js +1 -1
  30. package/dist/server/index.js +1 -1
  31. package/dist/transformations/index.js +1 -1
  32. package/dist/validation/KanonakObjectValidator.d.ts +5 -1
  33. package/dist/validation/index.d.ts +1 -1
  34. package/dist/validation/index.js +1 -1
  35. package/dist/validation/rules/repository/LinkTargetRule.d.ts +42 -0
  36. package/dist/validation/rules/repository/index.d.ts +1 -0
  37. package/package.json +2 -2
  38. package/dist/chunk-3DWEBQSD.js +0 -68
  39. package/dist/chunk-BRCVOR7A.js +0 -1
  40. package/dist/chunk-F3SGXIDP.js +0 -1
  41. package/dist/chunk-G3GKOJ5E.js +0 -1
  42. package/dist/chunk-KOWDHKBN.js +0 -1
  43. package/dist/chunk-P5VQEDBS.js +0 -2
  44. /package/dist/{chunk-PEB52US5.js → chunk-XK24CN3C.js} +0 -0
@@ -1,2 +0,0 @@
1
- import{a as m}from"./chunk-SC5M74NM.js";import{a as P}from"./chunk-KOWDHKBN.js";import{e as p,g as w,j as v}from"./chunk-QILEJIFU.js";var _="@kanonak-protocol/sdk (+https://kanonak.org)",y=_;function j(o){y=o}function B(){return y}function g(o){let t;try{t=typeof o=="string"?new URL(o):o}catch{throw new Error(`Kanonak requires an absolute https:// URL \u2014 got an unparseable or relative URL: ${String(o)}`)}if(t.protocol!=="https:")throw new Error(`Kanonak requires HTTPS \u2014 refusing to fetch ${t.href} (only https:// is supported).`)}var D=new Set([429,502,503,504]),U=4,K=500,R=2e4;function u(o,t){g(o);let e=new Headers(t?.headers);return e.has("User-Agent")||e.set("User-Agent",y),b(o,{...t,headers:e})}var d=U;function W(o){d=Math.max(0,o)}async function b(o,t){let e;for(let n=0;n<=d;n++){let r;try{r=await fetch(o,t)}catch(s){if(e=s,n>=d)throw s;await A(C(n,null));continue}if(!D.has(r.status)||n>=d)return r;await A(C(n,r.headers.get("retry-after")))}throw e??new Error("kanonakFetch: exhausted retries")}function C(o,t){let e=I(t);if(e!=null)return Math.min(e,R);let n=Math.min(R,K*2**o);return Math.floor(n/2+Math.random()*(n/2))}function I(o){if(!o)return null;let t=Number(o);if(Number.isFinite(t))return Math.max(0,t*1e3);let e=Date.parse(o);return Number.isNaN(e)?null:Math.max(0,e-Date.now())}function A(o){return new Promise(t=>setTimeout(t,o))}var T="https://{publisher}/{package}/{version}.kan.yml",x={version:1};function G(){return{version:1}}var k=class{constructor(t){this.fetchFn=t}fetchFn;cache=new Map;getConfig(t){let e=this.cache.get(t);return e||(e=this.fetchConfig(t),this.cache.set(t,e),e.catch(()=>{this.cache.get(t)===e&&this.cache.delete(t)})),e}async fetchConfig(t){let e=`https://${t}/.well-known/kanonak.json`,n;try{n=await(this.fetchFn?this.fetchFn(e,t):u(e))}catch{return x}if(n.status===404)return x;if(!n.ok)throw new Error(`Failed to fetch publisher config: ${e} (${n.status} ${n.statusText})`);let r=await n.json();if(typeof r.version!="number")throw new Error(`Invalid publisher config at ${e}: missing or invalid "version" field`);let s={version:r.version};return typeof r.package_url_template=="string"&&(M(e,"package_url_template",r.package_url_template),s.package_url_template=r.package_url_template),Array.isArray(r.featured_packages)&&r.featured_packages.every(a=>typeof a=="string")&&(s.featured_packages=r.featured_packages),s}resolvePackageUrl(t,e,n,r){let s=r.package_url_template??T,a=H(s,{publisher:t,package:e,version:n});return g(a),a}};function M(o,t,e){if(!e.startsWith("https://"))throw new Error(`Invalid publisher config at ${o}: ${t} must be an absolute https:// URL template (got "${e}").`)}function H(o,t){let e=o;for(let[r,s]of Object.entries(t))e=e.replaceAll(`{${r}}`,s);let n=e.match(/\{[a-z]+\}/);if(n)throw new Error(`Unresolved variable ${n[0]} in URL template: ${o}`);return e}import E from"js-yaml";var S=`# This file is generated by Kanonak CLI. Do not edit manually.
2
- `,O="sha256:";function $(o){let t=E.load(o);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??"",packages:t.packages??{}}}function Y(o){let t={};for(let n of Object.keys(o.packages).sort())t[n]=o.packages[n];let e=E.dump({...o,packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'});return S+e}async function J(o){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(o)),e=Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("");return`${O}${e}`}var f=class{configResolver;fetchFn;lockCache=new Map;constructor(t){this.configResolver=t?.configResolver??new k(t?.fetchFn),this.fetchFn=t?.fetchFn}getConfig(t){return this.configResolver.getConfig(t)}async getPackageUrl(t,e,n){let r=await this.configResolver.getConfig(t);return this.configResolver.resolvePackageUrl(t,e,n,r)}getLock(t){let e=this.lockCache.get(t);return e||(e=this.fetchLock(t),this.lockCache.set(t,e),e.catch(()=>{this.lockCache.get(t)===e&&this.lockCache.delete(t)})),e}async fetchLock(t){let e=`https://${t}/kanonak.lock`,n;try{n=this.fetchFn?await this.fetchFn(e,t):await u(e)}catch{return null}if(n.status===404)return null;if(!n.ok)throw new Error(`Failed to fetch publisher lock: ${e} (${n.status} ${n.statusText})`);return $(await n.text())}};import{VersionOperator as F}from"@kanonak-protocol/types/document/models/enums";function N(o,t){let e=w(o);return e?v(e,t):!1}var L=class{parser=new P;publisherIndex;documents=new Map;contentCache=new Map;fetchFn;onFetch;getFromCache;constructor(t){this.onFetch=t?.onFetch,this.getFromCache=t?.getFromCache,this.fetchFn=t?.fetchFn,this.publisherIndex=t?.fetchFn?new f({fetchFn:t.fetchFn}):new f}async getHighestCompatibleVersionAsync(t,e){if(e.versionOperator===F.Exact){let s=await this.fromMemoOrCache(t,e.packageName,p(e.version));if(s)return s}let r=(await this.publisherIndex.getLock(t))?.packages[`${t}/${e.packageName}`];return r&&N(r.version,e)?this.fetchPinned(t,e.packageName,r):r&&e.versionOperator!==F.Exact?null:this.resolveByDirectFetch(t,e)}async fetchPinned(t,e,n){let r=n.version,s=`${t}/${e}@${r}`,a=await this.fromMemoOrCache(t,e,r);if(a)return a;let i=n.resolved,c=this.fetchFn?await this.fetchFn(i,t):await u(i);if(!c.ok)throw new Error(`Failed to fetch Kanonak package: ${i} (${c.status} ${c.statusText})`);let l=await c.text(),h=this.parser.parse(l);return m(h,t,e,r),this.onFetch&&await this.onFetch(t,e,r,l),this.documents.set(s,h),this.contentCache.set(s,l),h}async fromMemoOrCache(t,e,n){let r=`${t}/${e}@${n}`,s=this.documents.get(r);if(s)return s;if(!this.getFromCache)return null;let a=await this.getFromCache(t,e,n);if(a==null)return null;let i;try{i=this.parser.parse(a),m(i,t,e,n)}catch(c){throw new Error(`Cached content for ${r} is not a usable copy of that package \u2014 refusing to fall through to a fetch that would hide it. ${c.message}`,{cause:c})}return this.documents.set(r,i),this.contentCache.set(r,a),i}async resolveByDirectFetch(t,e){let n=e.packageName,s=e.versionOperator===F.Exact?await this.publisherIndex.getPackageUrl(t,n,p(e.version)):`https://${t}/${n}.kan.yml`,a=await this.fetchFollowing(s,t);if(!a)return null;let i=this.parser.parse(a.content),c=i.metadata.namespace_;if(!c||!c.version)throw new Error(`Producer origin returned a package with no namespace/version for ${t}/${n}`);let l=p(c.version);m(i,t,n,l);let h=`${t}/${n}@${l}`;return this.onFetch&&await this.onFetch(t,n,l,a.content),this.documents.set(h,i),this.contentCache.set(h,a.content),i}async fetchFollowing(t,e,n=4){let r=t;for(let s=0;s<n;s++){g(r);let a=this.fetchFn?await this.fetchFn(r,e):await u(r,{redirect:"manual"});if(a.status===301||a.status===302){let i=a.headers.get("location");if(!i)throw new Error(`Redirect with no Location header from ${r}`);r=new URL(i,r).toString();continue}if(a.status===404)return null;if(!a.ok)throw new Error(`Failed to fetch Kanonak package: ${r} (${a.status} ${a.statusText})`);return{url:r,content:await a.text()}}throw new Error(`Too many redirects resolving ${t}`)}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(t){return this.documents.get(t)??null}async getDocumentsByNamespaceAsync(t,e){return Array.from(this.documents.values()).filter(n=>{let r=n.metadata.namespace_;return r&&r.publisher===t&&r.package_===e})}async saveDocumentAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async deleteDocumentAsync(t){throw new Error("HttpKanonakDocumentRepository is read-only")}async clearNamespaceAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(t){return this.contentCache.get(t)??null}async getDocumentUriAsync(t){let e=t.match(/^(.+?)\/(.+?)@(.+)$/);if(!e)return null;let[,n,r,s]=e;return this.publisherIndex.getPackageUrl(n,r,s)}};export{_ as a,j as b,B as c,g as d,u as e,W as f,G as g,k as h,O as i,$ as j,Y as k,J as l,f as m,L as n};
File without changes