@nodatachat/sdk 1.0.0 → 2.0.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.
- package/LICENSE.md +105 -0
- package/README.md +152 -253
- package/dist/chunk-4VSHBCCU.mjs +1 -0
- package/dist/index.d.mts +818 -130
- package/dist/index.d.ts +818 -130
- package/dist/index.js +1 -628
- package/dist/index.mjs +1 -8
- package/dist/plugins/express.d.mts +1 -1
- package/dist/plugins/express.d.ts +1 -1
- package/dist/plugins/express.js +1 -663
- package/dist/plugins/express.mjs +1 -43
- package/dist/plugins/fastify.d.mts +1 -1
- package/dist/plugins/fastify.d.ts +1 -1
- package/dist/plugins/fastify.js +1 -667
- package/dist/plugins/fastify.mjs +1 -47
- package/dist/{types-DQh0UmSr.d.mts → types-BQZ_zF32.d.mts} +132 -3
- package/dist/{types-DQh0UmSr.d.ts → types-BQZ_zF32.d.ts} +132 -3
- package/package.json +28 -22
- package/dist/chunk-V6GUTSNO.mjs +0 -601
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=class extends Error{constructor(t,r,s,n){super(t);this.status=r;this.code=s;this.retryAfter=n;this.name="NoDataError"}};var G="https://www.nodatacapsule.com",O=3e4,I=2,C=class{apiKey;baseUrl;timeout;retries;customHeaders;onRequest;onResponse;onError;constructor(e){if(!e.apiKey)throw new Error("NoData SDK: apiKey is required. Get one at https://www.nodatacapsule.com/developers");this.apiKey=e.apiKey,this.baseUrl=(e.baseUrl||G).replace(/\/+$/,""),this.timeout=e.timeout||O,this.retries=e.retries??I,this.customHeaders=e.headers||{},this.onRequest=e.onRequest,this.onResponse=e.onResponse,this.onError=e.onError}async request(e,t,r,s){let n=`${this.baseUrl}${t}`;if(s){let v=new URLSearchParams(Object.fromEntries(Object.entries(s).filter(([,a])=>a!=null))).toString();v&&(n+=`?${v}`)}let o={method:e,headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json","User-Agent":"@nodatachat/sdk/1.0.0","X-SDK-Version":"1.0.0",...this.customHeaders},signal:AbortSignal.timeout(this.timeout)};r&&e!=="GET"&&(o.body=JSON.stringify(r)),this.onRequest?.(n,o);let u=null,_=1+this.retries;for(let p=1;p<=_;p++){let v=Date.now();try{let a=await fetch(n,o),U=Date.now()-v;if(this.onResponse?.(n,a.status,U),a.status===429&&p<_){let $=parseInt(a.headers.get("Retry-After")||"5",10);await M($*1e3);continue}if(a.status>=500&&p<_){await M(1e3*p);continue}let q=await a.json().catch(()=>({}));if(!a.ok)throw new c(q.error||`HTTP ${a.status}`,a.status,q.code,a.status===429?parseInt(a.headers.get("Retry-After")||"60",10):void 0);return q}catch(a){if(u=a instanceof Error?a:new Error(String(a)),this.onError?.(n,u),a instanceof c)throw a;if(p<_){await M(1e3*p);continue}}}throw u||new Error("Request failed")}get baseURL(){return this.baseUrl}get(e,t){return this.request("GET",e,void 0,t)}post(e,t){return this.request("POST",e,t)}del(e,t){return this.request("DELETE",e,t)}};function M(i){return new Promise(e=>setTimeout(e,i))}var l=class{constructor(e){this.http=e}async encrypt(e){return this.http.post("/api/v1/encrypt",{field:e.field,value:e.value,context:e.context})}async decrypt(e){return this.http.post("/api/v1/decrypt",{ciphertext:e.ciphertext,field:e.field,requester:e.requester,purpose:e.purpose})}async batchEncrypt(e,t){let s=(await Promise.allSettled(e.map(n=>this.encrypt({...n,context:n.context||t})))).map((n,o)=>n.status==="fulfilled"?n.value:{success:!1,ciphertext:"",field:e[o].field,audit_id:"",algorithm:"",error:n.reason?.message||"Encryption failed"});return{success:s.every(n=>n.success),results:s,ok:s.filter(n=>n.success).length,failed:s.filter(n=>!n.success).length}}async batchDecrypt(e,t){let s=(await Promise.allSettled(e.map(n=>this.decrypt({...n,requester:n.requester||t})))).map((n,o)=>n.status==="fulfilled"?n.value:{success:!1,value:"",field:e[o].field,audit_id:"",error:n.reason?.message||"Decryption failed"});return{success:s.every(n=>n.success),results:s,ok:s.filter(n=>n.success).length,failed:s.filter(n=>!n.success).length}}async batchNative(e,t){return this.http.post("/api/v1/batch",{items:e,context:t})}async encryptObject(e,t,r){return this.processObject(e,t,async(s,n)=>(await this.encrypt({field:n,value:s,context:r})).ciphertext)}async decryptObject(e,t,r){return this.processObject(e,t,async(s,n)=>(await this.decrypt({ciphertext:s,field:n,requester:r})).value)}async processObject(e,t,r){if(e==null)return e;if(Array.isArray(e))return Promise.all(e.map(s=>this.processObject(s,t,r)));if(typeof e=="object"){let s={};for(let[n,o]of Object.entries(e))t.includes(n)&&typeof o=="string"&&o.length>0?s[n]=await r(o,n):typeof o=="object"?s[n]=await this.processObject(o,t,r):s[n]=o;return s}return e}};var g=class{constructor(e){this.http=e}async registerTable(e){return this.http.post("/api/v1/governance/tables",{table_name:e.table,encrypted_columns:e.encryptedColumns??[],plaintext_columns:e.plaintextColumns??[],classification_column:e.classificationColumn,hkdf_prefix:e.hkdfPrefix,ui_label:e.uiLabel})}async listTables(){return this.http.get("/api/v1/governance/tables")}async grant(e){return this.http.post("/api/v1/governance/grant",{agent:e.agent,table:e.table,columns:e.columns,where:e.where,classifications:e.classifications,ttl_seconds:e.ttlSeconds})}async revoke(e){return this.http.post("/api/v1/governance/revoke",{handle:e.agent,jti:e.jti,reason:e.reason})}},d=class{constructor(e,t){this.baseURL=e;this.grantToken=t}async read(e){let t=e.handle??L(this.grantToken);if(!t)throw new c("AgentReader.read: could not derive agent handle from token; pass { handle }",400);let r=`${this.baseURL}/api/agents/${encodeURIComponent(t)}/read`,s=await fetch(r,{method:"POST",headers:{Authorization:`Bearer ${this.grantToken}`,"Content-Type":"application/json"},body:JSON.stringify({table:e.table,columns:e.columns,where:e.where,limit:e.limit})}),n=await s.json().catch(()=>({}));if(!s.ok)throw new c(n.error||`HTTP ${s.status}`,s.status,n.reason);return n}};function L(i){try{let t=(i.startsWith("ndca-")?i.slice(5):i).split(".")[1];if(!t)return null;let r=t.replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(atob(r)).handle??null}catch{return null}}var x=class{constructor(e,t){this.http=e;this.ref=t}add(e){let t=e.sections?.length?e.sections:[{label:e.title||"Document",classification:e.classification||"confidential",text:e.content??""}];return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.ref)}/documents`,{title:e.title,sections:t,recipients:e.recipients,zero_knowledge:e.zero_knowledge})}list(){return this.http.get(`/api/v1/capsules/${encodeURIComponent(this.ref)}/documents`)}},k=class{constructor(e,t){this.http=e;this.ref=t}add(e){return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.ref)}/members`,e)}list(){return this.http.get(`/api/v1/capsules/${encodeURIComponent(this.ref)}/members`)}},w=class{constructor(e,t){this.http=e;this.ref=t}get(e){let t={};return e?.from&&(t.from=e.from),e?.to&&(t.to=e.to),e?.limit&&(t.limit=String(e.limit)),this.http.get(`/api/v1/capsules/${encodeURIComponent(this.ref)}/audit`,Object.keys(t).length?t:void 0)}},E=class{constructor(e,t){this.http=e;this.ref=t}grant(e){return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.ref)}/ai-grants`,e)}list(){return this.http.get(`/api/v1/capsules/${encodeURIComponent(this.ref)}/ai-grants`)}revoke(e){return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.ref)}/ai-grants`,{action:"revoke",agent_id:e})}read(e){return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.ref)}/ai-read`,e)}},m=class{constructor(e,t){this.http=e;this.summary=t;this.documents=new x(e,t.slug),this.members=new k(e,t.slug),this.audit=new w(e,t.slug),this.ai=new E(e,t.slug)}documents;members;audit;ai;get id(){return this.summary.capsule_id}get slug(){return this.summary.slug}get status(){return this.summary.status}embed(e){return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.slug)}/embed-token`,e)}revoke(e){return this.http.post(`/api/v1/capsules/${encodeURIComponent(this.slug)}/revoke`,{reason:e?.reason})}},h=class{constructor(e){this.http=e}async create(e){let t=await this.http.post("/api/v1/capsules",e);return new m(this.http,t)}async get(e){let t=await this.http.get(`/api/v1/capsules/${encodeURIComponent(e)}`);return new m(this.http,t)}list(e){return this.http.get("/api/v1/capsules",e?.limit?{limit:String(e.limit)}:void 0)}overview(){return this.http.get("/api/v1/overview")}};var R=class{constructor(e){this.http=e}create(e){return this.http.post("/api/v1/tenants",e)}get(e){return this.http.get(`/api/v1/tenants/${encodeURIComponent(e)}`)}};var f=class{constructor(e){this.http=e}async orgId(){let e=await this.http.get("/api/v1/partner/me");if(!e?.org_id)throw new Error("nd.scan: could not resolve the org from this API key.");return e.org_id}async enable(e){let t=await this.orgId(),r=await this.http.post(`/api/v1/tenants/${encodeURIComponent(t)}/capsule/install-token`,{}),s=r.install_token??"",n=(e.api_base??this.http.baseURL).replace(/\/+$/,""),o=e.source==="folder"?`--source folder --path ${e.path??"./"}`:e.source==="drive"?`--source drive --folder ${e.folder_id??"<folder-id>"}`:`--source ${e.source}`,u=e.per_customer?` --per-customer ${e.per_customer}`:"";return{ok:!0,scan_id:s.slice(0,12),install_token:s,install_command:`npx @nodatachat/capsule-agent --token ${s} --vault-api --api ${n} ${o}${u}`,expires_at:r.expires_at??null}}async status(){let e=await this.orgId(),t=await this.http.get(`/api/v1/tenants/${encodeURIComponent(e)}`);return{deployments:t.capsule?.deployments??[],last_scan_at:t.capsule?.last_scan_at??null,open_findings_count:t.capsule?.open_findings_count??0}}findings(e){let t={};return e?.limit&&(t.limit=String(e.limit)),e?.all&&(t.all="true"),this.http.get("/api/v1/scan/findings",Object.keys(t).length?t:void 0)}approve(e){return this.http.post("/api/v1/scan/approve",{finding_ids:e})}execute(e){return this.http.post("/api/v1/scan/execute",{finding_ids:e})}};var A=class{constructor(e){this.http=e}async create(e={}){return this.http.post("/api/secure-channel/init",{label:e.label,ttl:e.ttl||"24h",max_transfers:e.maxTransfers||10,require_verification:e.requireVerification??!1})}async send(e){let t=typeof e.data=="string"?e.data:JSON.stringify(e.data);return this.http.post("/api/secure-channel/upload",{channel_token:e.token,content:t,content_type:e.contentType||"application/json",burn_after_read:e.burnAfterRead??!0})}async receive(e){return this.http.post("/api/secure-channel/download",{channel_token:e.token,verification_code:e.verificationCode})}async verify(e,t){return this.http.post("/api/secure-channel/verify-code",{channel_token:e,code:t})}async proof(e){return this.http.post("/api/secure-channel/delivery-proof",{channel_token:e})}};var S=class{constructor(e){this.http=e}async create(e={}){return this.http.post("/api/webhook/channel/create",{label:e.label,ttl:e.ttl||"30d",max_events:e.maxEvents||1e4,burn_after_read:e.burnAfterRead??!1})}async events(e,t){return this.http.post("/api/webhook/channel/events",{channel_token:e,limit:t?.limit||50,since:t?.since})}async list(){return this.http.get("/api/webhook/dashboard")}};var D=class{constructor(e){this.http=e}async send(e){return this.http.post("/api/v1/deliver",{content:e.content,to:e.to,ttl:e.ttl||"24h",burn:e.burn??!0,maxViews:e.maxViews||1})}async burn(e,t){return this.http.post("/api/burn/create",{content:e,ttl_hours:t?.ttlHours||24,burn_after_read:t?.burnAfterRead??!0,available_at:t?.availableAt})}async read(e){return this.http.post("/api/burn/read",{drop_id:e})}};var P=class{constructor(e){this.http=e}async query(e={}){return this.http.get("/api/v1/evidence",{from:e.from||"",to:e.to||"",action:e.action||"",field:e.field||"",limit:String(e.limit||100)})}async certificate(e){return this.http.post("/api/proof-certificate",{audit_id:e})}async verify(e){return this.http.post("/api/receipt/verify",{proof_hash:e})}};var T=class{constructor(e){this.http=e}async create(e){return this.http.post("/api/vault/create",e)}async read(e){return this.http.post("/api/vault/read",{vault_id:e})}async delete(e){return this.http.post("/api/vault/delete",{vault_id:e})}async status(){return this.http.get("/api/vault/status")}};var b=class{governance;blindRelay;channel;deliver;evidence;vault;webhook;constructor(e){this.governance=new g(e),this.blindRelay=new l(e),this.channel=new A(e),this.deliver=new D(e),this.evidence=new P(e),this.vault=new T(e),this.webhook=new S(e)}};var y=class{constructor(e){this.http=e}async run(e){let t=await this.http.post("/api/v1/documents/compute",{question:e.question,clearance:e.clearance??"internal",...e.sections?{sections:e.sections}:{},...e.text?{text:e.text}:{}}),r=(t.sections??[]).map(s=>({title:s.title??"",classification:s.classification??"internal",sent:!!s.sent}));return{decision:t.decision??(r.some(s=>s.sent)?"allow":"deny"),answer:t.answer??null,model:t.model??null,sections:r,proof:{id:t.proof?.receipt_id??t.proof?.id??null,hash:t.proof?.hash??null,persisted:!!t.proof?.persisted}}}async verify(e){let t=await this.http.post("/api/access/verify",{proof_id:e});return{authentic:!!t.authentic,unaltered:!!t.unaltered,signer:t.signer,surface:t.surface,decision:t.decision,issuedAt:t.issued_at}}};var H=class{http;_encrypt;capsules;tenants;scan;engines;_compute;constructor(e){this.http=new C(e),this._compute=new y(this.http),this._encrypt=new l(this.http),this.capsules=new h(this.http),this.tenants=new R(this.http),this.scan=new f(this.http),this.engines=new b(this.http)}compute(e){return this._compute.run(e)}verify(e){return this._compute.verify(e)}get channel(){return this.engines.channel}get webhook(){return this.engines.webhook}get deliver(){return this.engines.deliver}get evidence(){return this.engines.evidence}get vault(){return this.engines.vault}get governance(){return this.engines.governance}agent(e){return new d(this.http.baseURL,e)}encrypt(e){return this._encrypt.encrypt(e)}decrypt(e){return this._encrypt.decrypt(e)}batchEncrypt(e,t){return this._encrypt.batchEncrypt(e,t)}batchDecrypt(e,t){return this._encrypt.batchDecrypt(e,t)}batchNative(e,t){return this._encrypt.batchNative(e,t)}encryptObject(e,t,r){return this._encrypt.encryptObject(e,t,r)}decryptObject(e,t,r){return this._encrypt.decryptObject(e,t,r)}async ping(){let e=Date.now();return await this.http.get("/api/health"),{success:!0,latencyMs:Date.now()-e}}};export{c as a,g as b,d as c,x as d,k as e,w as f,E as g,m as h,h as i,R as j,f as k,b as l,y as m,H as n};
|