@peerbit/server 1.0.3
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 +202 -0
- package/lib/esm/api.d.ts +33 -0
- package/lib/esm/api.js +370 -0
- package/lib/esm/api.js.map +1 -0
- package/lib/esm/aws.d.ts +9 -0
- package/lib/esm/aws.js +39 -0
- package/lib/esm/aws.js.map +1 -0
- package/lib/esm/bin.d.ts +2 -0
- package/lib/esm/bin.js +9 -0
- package/lib/esm/bin.js.map +1 -0
- package/lib/esm/cli.d.ts +9 -0
- package/lib/esm/cli.js +255 -0
- package/lib/esm/cli.js.map +1 -0
- package/lib/esm/client.d.ts +2 -0
- package/lib/esm/client.js +20 -0
- package/lib/esm/client.js.map +1 -0
- package/lib/esm/config.d.ts +5 -0
- package/lib/esm/config.js +17 -0
- package/lib/esm/config.js.map +1 -0
- package/lib/esm/docker.d.ts +2 -0
- package/lib/esm/docker.js +63 -0
- package/lib/esm/docker.js.map +1 -0
- package/lib/esm/domain.d.ts +10 -0
- package/lib/esm/domain.js +132 -0
- package/lib/esm/domain.js.map +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/nginx-template.conf +148 -0
- package/lib/esm/package.json +3 -0
- package/lib/ui/assets/index-5265c558.css +1 -0
- package/lib/ui/assets/index-b451191e.js +80 -0
- package/lib/ui/assets/index-bd766cd9.js +3 -0
- package/lib/ui/assets/logo192-5b1fb15f.png +0 -0
- package/lib/ui/favicon-128.png +0 -0
- package/lib/ui/favicon-16.png +0 -0
- package/lib/ui/favicon-256.png +0 -0
- package/lib/ui/favicon-32.png +0 -0
- package/lib/ui/favicon-48.png +0 -0
- package/lib/ui/favicon-96.png +0 -0
- package/lib/ui/favicon.ico +0 -0
- package/lib/ui/index.html +36 -0
- package/lib/ui/logo192.png +0 -0
- package/lib/ui/logo512.png +0 -0
- package/lib/ui/manifest.json +25 -0
- package/lib/ui/robots.txt +3 -0
- package/package.json +61 -0
- package/src/api.ts +433 -0
- package/src/aws.ts +48 -0
- package/src/bin.ts +7 -0
- package/src/cli.ts +266 -0
- package/src/client.ts +20 -0
- package/src/config.ts +20 -0
- package/src/docker.ts +67 -0
- package/src/domain.ts +179 -0
- package/src/index.ts +1 -0
- package/src/nginx-template.conf +148 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function pe(e,t){return function(){return e.apply(t,arguments)}}const{toString:Le}=Object.prototype,{getPrototypeOf:Z}=Object,I=(e=>t=>{const n=Le.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),R=e=>(e=e.toLowerCase(),t=>I(t)===e),M=e=>t=>typeof t===e,{isArray:C}=Array,F=M("undefined");function Ue(e){return e!==null&&!F(e)&&e.constructor!==null&&!F(e.constructor)&&b(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const he=R("ArrayBuffer");function ke(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&he(e.buffer),t}const je=M("string"),b=M("function"),me=M("number"),q=e=>e!==null&&typeof e=="object",He=e=>e===!0||e===!1,L=e=>{if(I(e)!=="object")return!1;const t=Z(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},Ie=R("Date"),Me=R("File"),qe=R("Blob"),$e=R("FileList"),ze=e=>q(e)&&b(e.pipe),Je=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||b(e.append)&&((t=I(e))==="formdata"||t==="object"&&b(e.toString)&&e.toString()==="[object FormData]"))},Ve=R("URLSearchParams"),We=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function D(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,s;if(typeof e!="object"&&(e=[e]),C(e))for(r=0,s=e.length;r<s;r++)t.call(null,e[r],r,e);else{const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let u;for(r=0;r<i;r++)u=o[r],t.call(null,e[u],u,e)}}function ye(e,t){t=t.toLowerCase();const n=Object.keys(e);let r=n.length,s;for(;r-- >0;)if(s=n[r],t===s.toLowerCase())return s;return null}const Ee=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),we=e=>!F(e)&&e!==Ee;function X(){const{caseless:e}=we(this)&&this||{},t={},n=(r,s)=>{const o=e&&ye(t,s)||s;L(t[o])&&L(r)?t[o]=X(t[o],r):L(r)?t[o]=X({},r):C(r)?t[o]=r.slice():t[o]=r};for(let r=0,s=arguments.length;r<s;r++)arguments[r]&&D(arguments[r],n);return t}const Ke=(e,t,n,{allOwnKeys:r}={})=>(D(t,(s,o)=>{n&&b(s)?e[o]=pe(s,n):e[o]=s},{allOwnKeys:r}),e),Ge=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Xe=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},ve=(e,t,n,r)=>{let s,o,i;const u={};if(t=t||{},e==null)return t;do{for(s=Object.getOwnPropertyNames(e),o=s.length;o-- >0;)i=s[o],(!r||r(i,e,t))&&!u[i]&&(t[i]=e[i],u[i]=!0);e=n!==!1&&Z(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Qe=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Ye=e=>{if(!e)return null;if(C(e))return e;let t=e.length;if(!me(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Ze=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Z(Uint8Array)),et=(e,t)=>{const r=(e&&e[Symbol.iterator]).call(e);let s;for(;(s=r.next())&&!s.done;){const o=s.value;t.call(e,o[0],o[1])}},tt=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},nt=R("HTMLFormElement"),rt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,s){return r.toUpperCase()+s}),re=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),st=R("RegExp"),be=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};D(n,(s,o)=>{t(s,o,e)!==!1&&(r[o]=s)}),Object.defineProperties(e,r)},ot=e=>{be(e,(t,n)=>{if(b(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(b(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},it=(e,t)=>{const n={},r=s=>{s.forEach(o=>{n[o]=!0})};return C(e)?r(e):r(String(e).split(t)),n},at=()=>{},ct=(e,t)=>(e=+e,Number.isFinite(e)?e:t),V="abcdefghijklmnopqrstuvwxyz",se="0123456789",Se={DIGIT:se,ALPHA:V,ALPHA_DIGIT:V+V.toUpperCase()+se},ut=(e=16,t=Se.ALPHA_DIGIT)=>{let n="";const{length:r}=t;for(;e--;)n+=t[Math.random()*r|0];return n};function lt(e){return!!(e&&b(e.append)&&e[Symbol.toStringTag]==="FormData"&&e[Symbol.iterator])}const ft=e=>{const t=new Array(10),n=(r,s)=>{if(q(r)){if(t.indexOf(r)>=0)return;if(!("toJSON"in r)){t[s]=r;const o=C(r)?[]:{};return D(r,(i,u)=>{const d=n(i,s+1);!F(d)&&(o[u]=d)}),t[s]=void 0,o}}return r};return n(e,0)},dt=R("AsyncFunction"),pt=e=>e&&(q(e)||b(e))&&b(e.then)&&b(e.catch),a={isArray:C,isArrayBuffer:he,isBuffer:Ue,isFormData:Je,isArrayBufferView:ke,isString:je,isNumber:me,isBoolean:He,isObject:q,isPlainObject:L,isUndefined:F,isDate:Ie,isFile:Me,isBlob:qe,isRegExp:st,isFunction:b,isStream:ze,isURLSearchParams:Ve,isTypedArray:Ze,isFileList:$e,forEach:D,merge:X,extend:Ke,trim:We,stripBOM:Ge,inherits:Xe,toFlatObject:ve,kindOf:I,kindOfTest:R,endsWith:Qe,toArray:Ye,forEachEntry:et,matchAll:tt,isHTMLForm:nt,hasOwnProperty:re,hasOwnProp:re,reduceDescriptors:be,freezeMethods:ot,toObjectSet:it,toCamelCase:rt,noop:at,toFiniteNumber:ct,findKey:ye,global:Ee,isContextDefined:we,ALPHABET:Se,generateString:ut,isSpecCompliantForm:lt,toJSONObject:ft,isAsyncFn:dt,isThenable:pt};function m(e,t,n,r,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s)}a.inherits(m,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:a.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const Oe=m.prototype,Re={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Re[e]={value:e}});Object.defineProperties(m,Re);Object.defineProperty(Oe,"isAxiosError",{value:!0});m.from=(e,t,n,r,s,o)=>{const i=Object.create(Oe);return a.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError"),m.call(i,e.message,t,n,r,s),i.cause=e,i.name=e.name,o&&Object.assign(i,o),i};const ht=null;function v(e){return a.isPlainObject(e)||a.isArray(e)}function Ae(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function oe(e,t,n){return e?e.concat(t).map(function(s,o){return s=Ae(s),!n&&o?"["+s+"]":s}).join(n?".":""):t}function mt(e){return a.isArray(e)&&!e.some(v)}const yt=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function $(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(h,A){return!a.isUndefined(A[h])});const r=n.metaTokens,s=n.visitor||l,o=n.dots,i=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(s))throw new TypeError("visitor must be a function");function c(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(!d&&a.isBlob(f))throw new m("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?d&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function l(f,h,A){let S=f;if(f&&!A&&typeof f=="object"){if(a.endsWith(h,"{}"))h=r?h:h.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&mt(f)||(a.isFileList(f)||a.endsWith(h,"[]"))&&(S=a.toArray(f)))return h=Ae(h),S.forEach(function(_,_e){!(a.isUndefined(_)||_===null)&&t.append(i===!0?oe([h],_e,o):i===null?h:h+"[]",c(_))}),!1}return v(f)?!0:(t.append(oe(A,h,o),c(f)),!1)}const p=[],w=Object.assign(yt,{defaultVisitor:l,convertValue:c,isVisitable:v});function y(f,h){if(!a.isUndefined(f)){if(p.indexOf(f)!==-1)throw Error("Circular reference detected in "+h.join("."));p.push(f),a.forEach(f,function(S,N){(!(a.isUndefined(S)||S===null)&&s.call(t,S,a.isString(N)?N.trim():N,h,w))===!0&&y(S,h?h.concat(N):[N])}),p.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return y(e),t}function ie(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ee(e,t){this._pairs=[],e&&$(e,this,t)}const Te=ee.prototype;Te.append=function(t,n){this._pairs.push([t,n])};Te.toString=function(t){const n=t?function(r){return t.call(this,r,ie)}:ie;return this._pairs.map(function(s){return n(s[0])+"="+n(s[1])},"").join("&")};function Et(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function xe(e,t,n){if(!t)return e;const r=n&&n.encode||Et,s=n&&n.serialize;let o;if(s?o=s(t,n):o=a.isURLSearchParams(t)?t.toString():new ee(t,n).toString(r),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class wt{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(r){r!==null&&t(r)})}}const ae=wt,Ne={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},bt=typeof URLSearchParams<"u"?URLSearchParams:ee,St=typeof FormData<"u"?FormData:null,Ot=typeof Blob<"u"?Blob:null,Rt=(()=>{let e;return typeof navigator<"u"&&((e=navigator.product)==="ReactNative"||e==="NativeScript"||e==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),At=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),O={isBrowser:!0,classes:{URLSearchParams:bt,FormData:St,Blob:Ot},isStandardBrowserEnv:Rt,isStandardBrowserWebWorkerEnv:At,protocols:["http","https","file","blob","url","data"]};function Tt(e,t){return $(e,new O.classes.URLSearchParams,Object.assign({visitor:function(n,r,s,o){return O.isNode&&a.isBuffer(n)?(this.append(r,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},t))}function xt(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Nt(e){const t={},n=Object.keys(e);let r;const s=n.length;let o;for(r=0;r<s;r++)o=n[r],t[o]=e[o];return t}function ge(e){function t(n,r,s,o){let i=n[o++];const u=Number.isFinite(+i),d=o>=n.length;return i=!i&&a.isArray(s)?s.length:i,d?(a.hasOwnProp(s,i)?s[i]=[s[i],r]:s[i]=r,!u):((!s[i]||!a.isObject(s[i]))&&(s[i]=[]),t(n,r,s[i],o)&&a.isArray(s[i])&&(s[i]=Nt(s[i])),!u)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(r,s)=>{t(xt(r),s,n,0)}),n}return null}const gt={"Content-Type":void 0};function Ct(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const z={transitional:Ne,adapter:["xhr","http"],transformRequest:[function(t,n){const r=n.getContentType()||"",s=r.indexOf("application/json")>-1,o=a.isObject(t);if(o&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return s&&s?JSON.stringify(ge(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let u;if(o){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Tt(t,this.formSerializer).toString();if((u=a.isFileList(t))||r.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return $(u?{"files[]":t}:t,d&&new d,this.formSerializer)}}return o||s?(n.setContentType("application/json",!1),Ct(t)):t}],transformResponse:[function(t){const n=this.transitional||z.transitional,r=n&&n.forcedJSONParsing,s=this.responseType==="json";if(t&&a.isString(t)&&(r&&!this.responseType||s)){const i=!(n&&n.silentJSONParsing)&&s;try{return JSON.parse(t)}catch(u){if(i)throw u.name==="SyntaxError"?m.from(u,m.ERR_BAD_RESPONSE,this,null,this.response):u}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:O.classes.FormData,Blob:O.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};a.forEach(["delete","get","head"],function(t){z.headers[t]={}});a.forEach(["post","put","patch"],function(t){z.headers[t]=a.merge(gt)});const te=z,Pt=a.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Ft=e=>{const t={};let n,r,s;return e&&e.split(`
|
|
2
|
+
`).forEach(function(i){s=i.indexOf(":"),n=i.substring(0,s).trim().toLowerCase(),r=i.substring(s+1).trim(),!(!n||t[n]&&Pt[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},ce=Symbol("internals");function P(e){return e&&String(e).trim().toLowerCase()}function U(e){return e===!1||e==null?e:a.isArray(e)?e.map(U):String(e)}function Dt(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const Bt=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function W(e,t,n,r,s){if(a.isFunction(r))return r.call(this,t,n);if(s&&(t=n),!!a.isString(t)){if(a.isString(r))return t.indexOf(r)!==-1;if(a.isRegExp(r))return r.test(t)}}function _t(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Lt(e,t){const n=a.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(s,o,i){return this[r].call(this,t,s,o,i)},configurable:!0})})}let J=class{constructor(t){t&&this.set(t)}set(t,n,r){const s=this;function o(u,d,c){const l=P(d);if(!l)throw new Error("header name must be a non-empty string");const p=a.findKey(s,l);(!p||s[p]===void 0||c===!0||c===void 0&&s[p]!==!1)&&(s[p||d]=U(u))}const i=(u,d)=>a.forEach(u,(c,l)=>o(c,l,d));return a.isPlainObject(t)||t instanceof this.constructor?i(t,n):a.isString(t)&&(t=t.trim())&&!Bt(t)?i(Ft(t),n):t!=null&&o(n,t,r),this}get(t,n){if(t=P(t),t){const r=a.findKey(this,t);if(r){const s=this[r];if(!n)return s;if(n===!0)return Dt(s);if(a.isFunction(n))return n.call(this,s,r);if(a.isRegExp(n))return n.exec(s);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=P(t),t){const r=a.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||W(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let s=!1;function o(i){if(i=P(i),i){const u=a.findKey(r,i);u&&(!n||W(r,r[u],u,n))&&(delete r[u],s=!0)}}return a.isArray(t)?t.forEach(o):o(t),s}clear(t){const n=Object.keys(this);let r=n.length,s=!1;for(;r--;){const o=n[r];(!t||W(this,this[o],o,t,!0))&&(delete this[o],s=!0)}return s}normalize(t){const n=this,r={};return a.forEach(this,(s,o)=>{const i=a.findKey(r,o);if(i){n[i]=U(s),delete n[o];return}const u=t?_t(o):String(o).trim();u!==o&&delete n[o],n[u]=U(s),r[u]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return a.forEach(this,(r,s)=>{r!=null&&r!==!1&&(n[s]=t&&a.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
3
|
+
`)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(s=>r.set(s)),r}static accessor(t){const r=(this[ce]=this[ce]={accessors:{}}).accessors,s=this.prototype;function o(i){const u=P(i);r[u]||(Lt(s,i),r[u]=!0)}return a.isArray(t)?t.forEach(o):o(t),this}};J.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);a.freezeMethods(J.prototype);a.freezeMethods(J);const T=J;function K(e,t){const n=this||te,r=t||n,s=T.from(r.headers);let o=r.data;return a.forEach(e,function(u){o=u.call(n,o,s.normalize(),t?t.status:void 0)}),s.normalize(),o}function Ce(e){return!!(e&&e.__CANCEL__)}function B(e,t,n){m.call(this,e??"canceled",m.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(B,m,{__CANCEL__:!0});function Ut(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new m("Request failed with status code "+n.status,[m.ERR_BAD_REQUEST,m.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}const kt=O.isStandardBrowserEnv?function(){return{write:function(n,r,s,o,i,u){const d=[];d.push(n+"="+encodeURIComponent(r)),a.isNumber(s)&&d.push("expires="+new Date(s).toGMTString()),a.isString(o)&&d.push("path="+o),a.isString(i)&&d.push("domain="+i),u===!0&&d.push("secure"),document.cookie=d.join("; ")},read:function(n){const r=document.cookie.match(new RegExp("(^|;\\s*)("+n+")=([^;]*)"));return r?decodeURIComponent(r[3]):null},remove:function(n){this.write(n,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}();function jt(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ht(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}function Pe(e,t){return e&&!jt(t)?Ht(e,t):t}const It=O.isStandardBrowserEnv?function(){const t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");let r;function s(o){let i=o;return t&&(n.setAttribute("href",i),i=n.href),n.setAttribute("href",i),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:n.pathname.charAt(0)==="/"?n.pathname:"/"+n.pathname}}return r=s(window.location.href),function(i){const u=a.isString(i)?s(i):i;return u.protocol===r.protocol&&u.host===r.host}}():function(){return function(){return!0}}();function Mt(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function qt(e,t){e=e||10;const n=new Array(e),r=new Array(e);let s=0,o=0,i;return t=t!==void 0?t:1e3,function(d){const c=Date.now(),l=r[o];i||(i=c),n[s]=d,r[s]=c;let p=o,w=0;for(;p!==s;)w+=n[p++],p=p%e;if(s=(s+1)%e,s===o&&(o=(o+1)%e),c-i<t)return;const y=l&&c-l;return y?Math.round(w*1e3/y):void 0}}function ue(e,t){let n=0;const r=qt(50,250);return s=>{const o=s.loaded,i=s.lengthComputable?s.total:void 0,u=o-n,d=r(u),c=o<=i;n=o;const l={loaded:o,total:i,progress:i?o/i:void 0,bytes:u,rate:d||void 0,estimated:d&&i&&c?(i-o)/d:void 0,event:s};l[t?"download":"upload"]=!0,e(l)}}const $t=typeof XMLHttpRequest<"u",zt=$t&&function(e){return new Promise(function(n,r){let s=e.data;const o=T.from(e.headers).normalize(),i=e.responseType;let u;function d(){e.cancelToken&&e.cancelToken.unsubscribe(u),e.signal&&e.signal.removeEventListener("abort",u)}a.isFormData(s)&&(O.isStandardBrowserEnv||O.isStandardBrowserWebWorkerEnv?o.setContentType(!1):o.setContentType("multipart/form-data;",!1));let c=new XMLHttpRequest;if(e.auth){const y=e.auth.username||"",f=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(y+":"+f))}const l=Pe(e.baseURL,e.url);c.open(e.method.toUpperCase(),xe(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout;function p(){if(!c)return;const y=T.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders()),h={data:!i||i==="text"||i==="json"?c.responseText:c.response,status:c.status,statusText:c.statusText,headers:y,config:e,request:c};Ut(function(S){n(S),d()},function(S){r(S),d()},h),c=null}if("onloadend"in c?c.onloadend=p:c.onreadystatechange=function(){!c||c.readyState!==4||c.status===0&&!(c.responseURL&&c.responseURL.indexOf("file:")===0)||setTimeout(p)},c.onabort=function(){c&&(r(new m("Request aborted",m.ECONNABORTED,e,c)),c=null)},c.onerror=function(){r(new m("Network Error",m.ERR_NETWORK,e,c)),c=null},c.ontimeout=function(){let f=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const h=e.transitional||Ne;e.timeoutErrorMessage&&(f=e.timeoutErrorMessage),r(new m(f,h.clarifyTimeoutError?m.ETIMEDOUT:m.ECONNABORTED,e,c)),c=null},O.isStandardBrowserEnv){const y=(e.withCredentials||It(l))&&e.xsrfCookieName&&kt.read(e.xsrfCookieName);y&&o.set(e.xsrfHeaderName,y)}s===void 0&&o.setContentType(null),"setRequestHeader"in c&&a.forEach(o.toJSON(),function(f,h){c.setRequestHeader(h,f)}),a.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),i&&i!=="json"&&(c.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&c.addEventListener("progress",ue(e.onDownloadProgress,!0)),typeof e.onUploadProgress=="function"&&c.upload&&c.upload.addEventListener("progress",ue(e.onUploadProgress)),(e.cancelToken||e.signal)&&(u=y=>{c&&(r(!y||y.type?new B(null,e,c):y),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(u),e.signal&&(e.signal.aborted?u():e.signal.addEventListener("abort",u)));const w=Mt(l);if(w&&O.protocols.indexOf(w)===-1){r(new m("Unsupported protocol "+w+":",m.ERR_BAD_REQUEST,e));return}c.send(s||null)})},k={http:ht,xhr:zt};a.forEach(k,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Jt={getAdapter:e=>{e=a.isArray(e)?e:[e];const{length:t}=e;let n,r;for(let s=0;s<t&&(n=e[s],!(r=a.isString(n)?k[n.toLowerCase()]:n));s++);if(!r)throw r===!1?new m(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT"):new Error(a.hasOwnProp(k,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`);if(!a.isFunction(r))throw new TypeError("adapter is not a function");return r},adapters:k};function G(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new B(null,e)}function le(e){return G(e),e.headers=T.from(e.headers),e.data=K.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Jt.getAdapter(e.adapter||te.adapter)(e).then(function(r){return G(e),r.data=K.call(e,e.transformResponse,r),r.headers=T.from(r.headers),r},function(r){return Ce(r)||(G(e),r&&r.response&&(r.response.data=K.call(e,e.transformResponse,r.response),r.response.headers=T.from(r.response.headers))),Promise.reject(r)})}const fe=e=>e instanceof T?e.toJSON():e;function g(e,t){t=t||{};const n={};function r(c,l,p){return a.isPlainObject(c)&&a.isPlainObject(l)?a.merge.call({caseless:p},c,l):a.isPlainObject(l)?a.merge({},l):a.isArray(l)?l.slice():l}function s(c,l,p){if(a.isUndefined(l)){if(!a.isUndefined(c))return r(void 0,c,p)}else return r(c,l,p)}function o(c,l){if(!a.isUndefined(l))return r(void 0,l)}function i(c,l){if(a.isUndefined(l)){if(!a.isUndefined(c))return r(void 0,c)}else return r(void 0,l)}function u(c,l,p){if(p in t)return r(c,l);if(p in e)return r(void 0,c)}const d={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:u,headers:(c,l)=>s(fe(c),fe(l),!0)};return a.forEach(Object.keys(Object.assign({},e,t)),function(l){const p=d[l]||s,w=p(e[l],t[l],l);a.isUndefined(w)&&p!==u||(n[l]=w)}),n}const Fe="1.4.0",ne={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ne[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const de={};ne.transitional=function(t,n,r){function s(o,i){return"[Axios v"+Fe+"] Transitional option '"+o+"'"+i+(r?". "+r:"")}return(o,i,u)=>{if(t===!1)throw new m(s(i," has been removed"+(n?" in "+n:"")),m.ERR_DEPRECATED);return n&&!de[i]&&(de[i]=!0,console.warn(s(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,i,u):!0}};function Vt(e,t,n){if(typeof e!="object")throw new m("options must be an object",m.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let s=r.length;for(;s-- >0;){const o=r[s],i=t[o];if(i){const u=e[o],d=u===void 0||i(u,o,e);if(d!==!0)throw new m("option "+o+" must be "+d,m.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new m("Unknown option "+o,m.ERR_BAD_OPTION)}}const Q={assertOptions:Vt,validators:ne},x=Q.validators;let H=class{constructor(t){this.defaults=t,this.interceptors={request:new ae,response:new ae}}request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=g(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:o}=n;r!==void 0&&Q.assertOptions(r,{silentJSONParsing:x.transitional(x.boolean),forcedJSONParsing:x.transitional(x.boolean),clarifyTimeoutError:x.transitional(x.boolean)},!1),s!=null&&(a.isFunction(s)?n.paramsSerializer={serialize:s}:Q.assertOptions(s,{encode:x.function,serialize:x.function},!0)),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i;i=o&&a.merge(o.common,o[n.method]),i&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete o[f]}),n.headers=T.concat(i,o);const u=[];let d=!0;this.interceptors.request.forEach(function(h){typeof h.runWhen=="function"&&h.runWhen(n)===!1||(d=d&&h.synchronous,u.unshift(h.fulfilled,h.rejected))});const c=[];this.interceptors.response.forEach(function(h){c.push(h.fulfilled,h.rejected)});let l,p=0,w;if(!d){const f=[le.bind(this),void 0];for(f.unshift.apply(f,u),f.push.apply(f,c),w=f.length,l=Promise.resolve(n);p<w;)l=l.then(f[p++],f[p++]);return l}w=u.length;let y=n;for(p=0;p<w;){const f=u[p++],h=u[p++];try{y=f(y)}catch(A){h.call(this,A);break}}try{l=le.call(this,y)}catch(f){return Promise.reject(f)}for(p=0,w=c.length;p<w;)l=l.then(c[p++],c[p++]);return l}getUri(t){t=g(this.defaults,t);const n=Pe(t.baseURL,t.url);return xe(n,t.params,t.paramsSerializer)}};a.forEach(["delete","get","head","options"],function(t){H.prototype[t]=function(n,r){return this.request(g(r||{},{method:t,url:n,data:(r||{}).data}))}});a.forEach(["post","put","patch"],function(t){function n(r){return function(o,i,u){return this.request(g(u||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}H.prototype[t]=n(),H.prototype[t+"Form"]=n(!0)});const j=H;let Wt=class De{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const r=this;this.promise.then(s=>{if(!r._listeners)return;let o=r._listeners.length;for(;o-- >0;)r._listeners[o](s);r._listeners=null}),this.promise.then=s=>{let o;const i=new Promise(u=>{r.subscribe(u),o=u}).then(s);return i.cancel=function(){r.unsubscribe(o)},i},t(function(o,i,u){r.reason||(r.reason=new B(o,i,u),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}static source(){let t;return{token:new De(function(s){t=s}),cancel:t}}};const Kt=Wt;function Gt(e){return function(n){return e.apply(null,n)}}function Xt(e){return a.isObject(e)&&e.isAxiosError===!0}const Y={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Y).forEach(([e,t])=>{Y[t]=e});const vt=Y;function Be(e){const t=new j(e),n=pe(j.prototype.request,t);return a.extend(n,j.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(s){return Be(g(e,s))},n}const E=Be(te);E.Axios=j;E.CanceledError=B;E.CancelToken=Kt;E.isCancel=Ce;E.VERSION=Fe;E.toFormData=$;E.AxiosError=m;E.Cancel=E.CanceledError;E.all=function(t){return Promise.all(t)};E.spread=Gt;E.isAxiosError=Xt;E.mergeConfig=g;E.AxiosHeaders=T;E.formToJSON=e=>ge(a.isHTMLForm(e)?new FormData(e):e);E.HttpStatusCode=vt;E.default=E;const Qt=E,{Axios:en,AxiosError:tn,CanceledError:nn,isCancel:rn,CancelToken:sn,VERSION:on,all:an,Cancel:cn,isAxiosError:un,spread:ln,toFormData:fn,AxiosHeaders:dn,HttpStatusCode:pn,formToJSON:hn,mergeConfig:mn}=Qt;export{en as Axios,tn as AxiosError,dn as AxiosHeaders,cn as Cancel,sn as CancelToken,nn as CanceledError,pn as HttpStatusCode,on as VERSION,an as all,Qt as default,hn as formToJSON,un as isAxiosError,rn as isCancel,mn as mergeConfig,ln as spread,fn as toFormData};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<link rel="icon" href="data:image/x-icon;base64,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" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
8
|
+
<meta name="theme-color" content="#000000" />
|
|
9
|
+
<meta name="description" content="Peerbit node" />
|
|
10
|
+
<link rel="apple-touch-icon" href="/assets/logo192-5b1fb15f.png" />
|
|
11
|
+
<!--
|
|
12
|
+
manifest.json provides metadata used when your web app is installed on a
|
|
13
|
+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
|
14
|
+
-->
|
|
15
|
+
<link rel="manifest" href="data:application/json;base64,ewoJInNob3J0X25hbWUiOiAiUGVlcmJpdCBub2RlIiwKCSJuYW1lIjogIlBlZXJiaXQgbm9kZSIsCgkiaWNvbnMiOiBbCgkJewoJCQkic3JjIjogImZhdmljb24uaWNvIiwKCQkJInNpemVzIjogIjY0eDY0IDMyeDMyIDI0eDI0IDE2eDE2IiwKCQkJInR5cGUiOiAiaW1hZ2UveC1pY29uIgoJCX0sCgkJewoJCQkic3JjIjogImxvZ28xOTIucG5nIiwKCQkJInR5cGUiOiAiaW1hZ2UvcG5nIiwKCQkJInNpemVzIjogIjE5MngxOTIiCgkJfSwKCQl7CgkJCSJzcmMiOiAibG9nbzUxMi5wbmciLAoJCQkidHlwZSI6ICJpbWFnZS9wbmciLAoJCQkic2l6ZXMiOiAiNTEyeDUxMiIKCQl9CgldLAoJInN0YXJ0X3VybCI6ICIuIiwKCSJkaXNwbGF5IjogInN0YW5kYWxvbmUiLAoJInRoZW1lX2NvbG9yIjogIiMwMDAwMDAiLAoJImJhY2tncm91bmRfY29sb3IiOiAiI2ZmZmZmZiIKfQo=" />
|
|
16
|
+
<!--
|
|
17
|
+
Notice the use of in the tags above.
|
|
18
|
+
It will be replaced with the URL of the `public` folder during the build.
|
|
19
|
+
Only files inside the `public` folder can be referenced from the HTML.
|
|
20
|
+
|
|
21
|
+
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
|
|
22
|
+
work correctly both with client-side routing and a non-root public URL.
|
|
23
|
+
Learn how to configure a non-root public URL by running `npm run build`.
|
|
24
|
+
-->
|
|
25
|
+
<title>Peerbit</title>
|
|
26
|
+
<script type="module" crossorigin src="/assets/index-b451191e.js"></script>
|
|
27
|
+
<link rel="stylesheet" href="/assets/index-5265c558.css">
|
|
28
|
+
</head>
|
|
29
|
+
|
|
30
|
+
<body>
|
|
31
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
32
|
+
<div id="root"></div>
|
|
33
|
+
|
|
34
|
+
</body>
|
|
35
|
+
|
|
36
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"short_name": "Peerbit node",
|
|
3
|
+
"name": "Peerbit node",
|
|
4
|
+
"icons": [
|
|
5
|
+
{
|
|
6
|
+
"src": "favicon.ico",
|
|
7
|
+
"sizes": "64x64 32x32 24x24 16x16",
|
|
8
|
+
"type": "image/x-icon"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"src": "logo192.png",
|
|
12
|
+
"type": "image/png",
|
|
13
|
+
"sizes": "192x192"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"src": "logo512.png",
|
|
17
|
+
"type": "image/png",
|
|
18
|
+
"sizes": "512x512"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"start_url": ".",
|
|
22
|
+
"display": "standalone",
|
|
23
|
+
"theme_color": "#000000",
|
|
24
|
+
"background_color": "#ffffff"
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peerbit/server",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"author": "dao.xyz",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/dao-xyz/peerbit"
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"bin": {
|
|
13
|
+
"peerbit": "./lib/esm/bin.js"
|
|
14
|
+
},
|
|
15
|
+
"module": "lib/esm/index.js",
|
|
16
|
+
"types": "lib/esm/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"import": "./lib/esm/index.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"lib",
|
|
22
|
+
"src",
|
|
23
|
+
"src/nginx-template.conf",
|
|
24
|
+
"!src/**/__tests__",
|
|
25
|
+
"!lib/**/__tests__",
|
|
26
|
+
"patches",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16.15.1"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "shx rm -rf lib/*",
|
|
37
|
+
"build": "yarn clean && yarn build-lib && yarn build-ui",
|
|
38
|
+
"build-lib": "tsc -p tsconfig.json",
|
|
39
|
+
"build-ui": "cd ../frontend && yarn build && cd ../node",
|
|
40
|
+
"postbuild": "cp src/nginx-template.conf lib/esm/ && echo '{\"type\":\"module\"} ' | node ../../../../node_modules/.bin/json > lib/esm/package.json && cp -r ../frontend/dist lib/ui",
|
|
41
|
+
"test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
|
|
42
|
+
"test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
|
|
43
|
+
"test:integration": "node ../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@peerbit/string": "1.0.2",
|
|
47
|
+
"@peerbit/test-lib": "^0.0.1",
|
|
48
|
+
"@peerbit/test-utils": "1.0.2",
|
|
49
|
+
"@types/yargs": "^17.0.24",
|
|
50
|
+
"aws-sdk": "^2.1259.0",
|
|
51
|
+
"dotenv": "^16.1.4"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@aws-sdk/client-route-53": "^3.345.0",
|
|
55
|
+
"@dao-xyz/libp2p-noise": "^12.0.1",
|
|
56
|
+
"axios": "^1.4.0",
|
|
57
|
+
"peerbit": "1.0.1",
|
|
58
|
+
"yargs": "^17.7.2"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "595db9f1efebf604393eddfff5f678f5d8f16142"
|
|
61
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
import { fromBase64, toBase64 } from "@peerbit/crypto";
|
|
3
|
+
import { serialize, deserialize } from "@dao-xyz/borsh";
|
|
4
|
+
import { Program, Address, ProgramClient } from "@peerbit/program";
|
|
5
|
+
import { multiaddr } from "@multiformats/multiaddr";
|
|
6
|
+
import { waitFor } from "@peerbit/time";
|
|
7
|
+
import { v4 as uuid } from "uuid";
|
|
8
|
+
import { Libp2p } from "libp2p";
|
|
9
|
+
import { getConfigDir, getCredentialsPath, NotFoundError } from "./config.js";
|
|
10
|
+
import { setMaxListeners } from "events";
|
|
11
|
+
import { create } from "./client.js";
|
|
12
|
+
|
|
13
|
+
export const SSL_PORT = 9002;
|
|
14
|
+
export const LOCAL_PORT = 8082;
|
|
15
|
+
|
|
16
|
+
export const getPort = (protocol: string) => {
|
|
17
|
+
if (protocol === "https:") {
|
|
18
|
+
return SSL_PORT;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (protocol === "http:") {
|
|
22
|
+
return LOCAL_PORT;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw new Error("Unsupported protocol: " + protocol);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const PEER_ID_PATH = "/peer/id";
|
|
29
|
+
const ADDRESS_PATH = "/peer/address";
|
|
30
|
+
const PROGRAM_PATH = "/program";
|
|
31
|
+
const LIBRARY_PATH = "/library";
|
|
32
|
+
|
|
33
|
+
export const checkExistPath = async (path: string) => {
|
|
34
|
+
const fs = await import("fs");
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
if (!fs.existsSync(path)) {
|
|
38
|
+
fs.accessSync(path, fs.constants.W_OK); // will throw if fails
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
} catch (err: any) {
|
|
43
|
+
if (err.message.indexOf("no such file")) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("Can not access path");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const createPassword = async (): Promise<string> => {
|
|
50
|
+
const fs = await import("fs");
|
|
51
|
+
const configDir = await getConfigDir();
|
|
52
|
+
const credentialsPath = await getCredentialsPath(configDir);
|
|
53
|
+
if (await checkExistPath(credentialsPath)) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"Config path for credentials: " + credentialsPath + ", already exist"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
console.log(`Creating config folder ${configDir}`);
|
|
59
|
+
|
|
60
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
61
|
+
await waitFor(() => fs.existsSync(configDir));
|
|
62
|
+
|
|
63
|
+
console.log(`Created config folder ${configDir}`);
|
|
64
|
+
|
|
65
|
+
const password = uuid();
|
|
66
|
+
fs.writeFileSync(
|
|
67
|
+
credentialsPath,
|
|
68
|
+
JSON.stringify({ username: "admin", password })
|
|
69
|
+
);
|
|
70
|
+
console.log(`Created credentials at ${credentialsPath}`);
|
|
71
|
+
return password;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const loadPassword = async (): Promise<string> => {
|
|
75
|
+
const fs = await import("fs");
|
|
76
|
+
const configDir = await getConfigDir();
|
|
77
|
+
const credentialsPath = await getCredentialsPath(configDir);
|
|
78
|
+
if (!(await checkExistPath(credentialsPath))) {
|
|
79
|
+
throw new NotFoundError("Credentials file does not exist");
|
|
80
|
+
}
|
|
81
|
+
const password = JSON.parse(
|
|
82
|
+
fs.readFileSync(credentialsPath, "utf-8")
|
|
83
|
+
).password;
|
|
84
|
+
if (!password || password.length === 0) {
|
|
85
|
+
throw new NotFoundError("Password not found");
|
|
86
|
+
}
|
|
87
|
+
return password;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const loadOrCreatePassword = async (): Promise<string> => {
|
|
91
|
+
try {
|
|
92
|
+
return await loadPassword();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (error instanceof NotFoundError) {
|
|
95
|
+
return createPassword();
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export const startServerWithNode = async (directory: string) => {
|
|
101
|
+
const peer = await create(directory);
|
|
102
|
+
const server = await startServer(peer);
|
|
103
|
+
const printNodeInfo = async () => {
|
|
104
|
+
console.log("Starting node with address(es): ");
|
|
105
|
+
const id = await (await client()).peer.id.get();
|
|
106
|
+
console.log("id: " + id);
|
|
107
|
+
console.log("Addresses: ");
|
|
108
|
+
for (const a of await (await client()).peer.addresses.get()) {
|
|
109
|
+
console.log(a.toString());
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
await printNodeInfo();
|
|
114
|
+
const shutDownHook = async (
|
|
115
|
+
controller: { stop: () => any },
|
|
116
|
+
server: {
|
|
117
|
+
close: () => void;
|
|
118
|
+
}
|
|
119
|
+
) => {
|
|
120
|
+
const { exit } = await import("process");
|
|
121
|
+
process.on("SIGINT", async () => {
|
|
122
|
+
console.log("Shutting down node");
|
|
123
|
+
await server.close();
|
|
124
|
+
await controller.stop();
|
|
125
|
+
exit();
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
await shutDownHook(peer, server);
|
|
129
|
+
};
|
|
130
|
+
export const startServer = async (
|
|
131
|
+
client: ProgramClient,
|
|
132
|
+
port: number = LOCAL_PORT
|
|
133
|
+
): Promise<http.Server> => {
|
|
134
|
+
const notPeerBitError =
|
|
135
|
+
"Client is just a Libp2p node, not a full Peerbit client. The command is not supported for this node type";
|
|
136
|
+
const notSupportedError = "Not implemted";
|
|
137
|
+
|
|
138
|
+
const password = await loadOrCreatePassword();
|
|
139
|
+
|
|
140
|
+
const adminACL = (req: http.IncomingMessage): boolean => {
|
|
141
|
+
const auth = req.headers["authorization"];
|
|
142
|
+
if (!auth?.startsWith("Basic ")) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const credentials = auth?.substring("Basic ".length);
|
|
146
|
+
const username = credentials.split(":")[0];
|
|
147
|
+
if (username !== "admin") {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (password !== credentials.substring(username.length + 1)) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const getProgramFromPath = (
|
|
157
|
+
req: http.IncomingMessage,
|
|
158
|
+
pathIndex: number
|
|
159
|
+
): Program | undefined => {
|
|
160
|
+
/* if (!req.url) {
|
|
161
|
+
throw new Error("Missing url");
|
|
162
|
+
}
|
|
163
|
+
const url = new URL(req.url, "http://localhost:" + port);
|
|
164
|
+
const path = url.pathname
|
|
165
|
+
.substring(Math.min(1, url.pathname.length), url.pathname.length)
|
|
166
|
+
.split("/");
|
|
167
|
+
if (path.length <= pathIndex) {
|
|
168
|
+
throw new Error("Invalid path");
|
|
169
|
+
}
|
|
170
|
+
const address = decodeURIComponent(path[pathIndex]);
|
|
171
|
+
const p = client.programs.get(address);
|
|
172
|
+
if (p) {
|
|
173
|
+
return p.program;
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
*/
|
|
177
|
+
throw new Error("Not supported");
|
|
178
|
+
};
|
|
179
|
+
const getBody = (
|
|
180
|
+
req: http.IncomingMessage,
|
|
181
|
+
callback: (body: string) => void
|
|
182
|
+
) => {
|
|
183
|
+
let body = "";
|
|
184
|
+
req.on("data", function (d) {
|
|
185
|
+
body += d;
|
|
186
|
+
});
|
|
187
|
+
req.on("end", function () {
|
|
188
|
+
callback(body);
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const e404 = "404";
|
|
193
|
+
const endpoints = (client: ProgramClient | Libp2p): http.RequestListener => {
|
|
194
|
+
return async (req, res) => {
|
|
195
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
196
|
+
res.setHeader("Access-Control-Request-Method", "*");
|
|
197
|
+
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
198
|
+
res.setHeader("Access-Control-Allow-Methods", "*");
|
|
199
|
+
const r404 = () => {
|
|
200
|
+
res.writeHead(404);
|
|
201
|
+
res.end(e404);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
if (req.url) {
|
|
206
|
+
if (
|
|
207
|
+
!req.url.startsWith(PEER_ID_PATH) &&
|
|
208
|
+
!req.url.startsWith(ADDRESS_PATH) &&
|
|
209
|
+
!(await adminACL(req))
|
|
210
|
+
) {
|
|
211
|
+
res.writeHead(401);
|
|
212
|
+
res.end("Not authorized");
|
|
213
|
+
return;
|
|
214
|
+
} else if (req.url.startsWith(PROGRAM_PATH)) {
|
|
215
|
+
if (true as any /* client instanceof Peerbit === false */) {
|
|
216
|
+
res.writeHead(400);
|
|
217
|
+
res.write(notSupportedError);
|
|
218
|
+
res.end();
|
|
219
|
+
} /* else {
|
|
220
|
+
switch (req.method) {
|
|
221
|
+
case "GET":
|
|
222
|
+
try {
|
|
223
|
+
const program = getProgramFromPath(req, 1);
|
|
224
|
+
if (program) {
|
|
225
|
+
res.writeHead(200);
|
|
226
|
+
res.write(toBase64(serialize(program)));
|
|
227
|
+
res.end();
|
|
228
|
+
} else {
|
|
229
|
+
res.writeHead(404);
|
|
230
|
+
res.end();
|
|
231
|
+
}
|
|
232
|
+
} catch (error: any) {
|
|
233
|
+
res.writeHead(404);
|
|
234
|
+
res.end(error.message);
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case "PUT":
|
|
239
|
+
getBody(req, (body) => {
|
|
240
|
+
try {
|
|
241
|
+
const parsed = deserialize(fromBase64(body), Program);
|
|
242
|
+
(client as Peerbit)
|
|
243
|
+
.open(parsed)
|
|
244
|
+
.then((program) => {
|
|
245
|
+
res.writeHead(200);
|
|
246
|
+
res.end(program.address.toString());
|
|
247
|
+
})
|
|
248
|
+
.catch((error) => {
|
|
249
|
+
res.writeHead(400);
|
|
250
|
+
res.end(
|
|
251
|
+
"Failed to open program: " + error.toString()
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
res.writeHead(400);
|
|
256
|
+
res.end("Invalid base64 program binary");
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
break;
|
|
260
|
+
|
|
261
|
+
default:
|
|
262
|
+
r404();
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
} */
|
|
266
|
+
} else if (req.url.startsWith(LIBRARY_PATH)) {
|
|
267
|
+
const url = new URL(req.url, "http://localhost:" + port);
|
|
268
|
+
switch (req.method) {
|
|
269
|
+
case "PUT":
|
|
270
|
+
getBody(req, (body) => {
|
|
271
|
+
const name = body;
|
|
272
|
+
if (name && name.length === 0) {
|
|
273
|
+
res.writeHead(400);
|
|
274
|
+
res.end("Invalid library: " + name);
|
|
275
|
+
} else {
|
|
276
|
+
import(/* webpackIgnore: true */ /* @vite-ignore */ name)
|
|
277
|
+
.then(() => {
|
|
278
|
+
res.writeHead(200);
|
|
279
|
+
res.end();
|
|
280
|
+
})
|
|
281
|
+
.catch((e) => {
|
|
282
|
+
res.writeHead(400);
|
|
283
|
+
res.end(e.message.toString?.());
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
default:
|
|
290
|
+
r404();
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
} else if (req.url.startsWith(PEER_ID_PATH)) {
|
|
294
|
+
res.writeHead(200);
|
|
295
|
+
res.end(client.peerId.toString());
|
|
296
|
+
} else if (req.url.startsWith(ADDRESS_PATH)) {
|
|
297
|
+
res.setHeader("Content-Type", "application/json");
|
|
298
|
+
res.writeHead(200);
|
|
299
|
+
const addresses = client.getMultiaddrs().map((x) => x.toString());
|
|
300
|
+
res.end(JSON.stringify(addresses));
|
|
301
|
+
} else {
|
|
302
|
+
r404();
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
r404();
|
|
306
|
+
}
|
|
307
|
+
} catch (error: any) {
|
|
308
|
+
res.writeHead(500);
|
|
309
|
+
console.error(error?.message);
|
|
310
|
+
res.end("Unexpected error");
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
setMaxListeners(Infinity); // TODO make this better (lower and large enough)
|
|
316
|
+
process.setMaxListeners(Infinity); // TODO make this better (lower and large enough)
|
|
317
|
+
|
|
318
|
+
const server = http.createServer(endpoints(client));
|
|
319
|
+
server.listen(port);
|
|
320
|
+
server.on("error", (e) => {
|
|
321
|
+
console.error("Server error: " + e?.message);
|
|
322
|
+
import("fs").then((fs) => {
|
|
323
|
+
fs.writeFile("error.log", JSON.stringify(e.message), function () {
|
|
324
|
+
/* void */ 0;
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
console.log("API available at port", port);
|
|
329
|
+
return server;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export const client = async (
|
|
333
|
+
endpoint: string = "http://localhost:" + LOCAL_PORT
|
|
334
|
+
) => {
|
|
335
|
+
const { default: axios } = await import("axios");
|
|
336
|
+
|
|
337
|
+
const validateStatus = (status: number) => {
|
|
338
|
+
return (status >= 200 && status < 300) || status == 404;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const throwIfNot200 = (resp: { status: number; data: any }) => {
|
|
342
|
+
if (resp.status !== 200) {
|
|
343
|
+
throw new Error(resp.data);
|
|
344
|
+
}
|
|
345
|
+
return resp;
|
|
346
|
+
};
|
|
347
|
+
const getBodyByStatus = <
|
|
348
|
+
D extends { toString(): string },
|
|
349
|
+
T extends { status: number; data: D }
|
|
350
|
+
>(
|
|
351
|
+
resp: T
|
|
352
|
+
): D | undefined => {
|
|
353
|
+
if (resp.status === 404) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (resp.status == 200) {
|
|
357
|
+
return resp.data;
|
|
358
|
+
}
|
|
359
|
+
throw new Error(
|
|
360
|
+
typeof resp.data === "string" ? resp.data : resp.data.toString()
|
|
361
|
+
);
|
|
362
|
+
};
|
|
363
|
+
const getId = async () =>
|
|
364
|
+
throwIfNot200(await axios.get(endpoint + PEER_ID_PATH, { validateStatus }))
|
|
365
|
+
.data;
|
|
366
|
+
const getHeaders = async () => {
|
|
367
|
+
const headers = {
|
|
368
|
+
authorization: "Basic admin:" + (await loadPassword()),
|
|
369
|
+
};
|
|
370
|
+
return headers;
|
|
371
|
+
};
|
|
372
|
+
return {
|
|
373
|
+
peer: {
|
|
374
|
+
id: {
|
|
375
|
+
get: getId,
|
|
376
|
+
},
|
|
377
|
+
addresses: {
|
|
378
|
+
get: async () => {
|
|
379
|
+
return (
|
|
380
|
+
throwIfNot200(
|
|
381
|
+
await axios.get(endpoint + ADDRESS_PATH, {
|
|
382
|
+
validateStatus,
|
|
383
|
+
headers: await getHeaders(),
|
|
384
|
+
})
|
|
385
|
+
).data as string[]
|
|
386
|
+
).map((x) => multiaddr(x));
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
program: {
|
|
391
|
+
get: async (address: Address | string): Promise<Program | undefined> => {
|
|
392
|
+
const result = getBodyByStatus<string, any>(
|
|
393
|
+
await axios.get(
|
|
394
|
+
endpoint +
|
|
395
|
+
PROGRAM_PATH +
|
|
396
|
+
"/" +
|
|
397
|
+
encodeURIComponent(address.toString()),
|
|
398
|
+
{ validateStatus, headers: await getHeaders() }
|
|
399
|
+
)
|
|
400
|
+
);
|
|
401
|
+
return !result ? undefined : deserialize(fromBase64(result), Program);
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @param program Program, or base64 string representation
|
|
406
|
+
* @param topic, topic
|
|
407
|
+
* @returns
|
|
408
|
+
*/
|
|
409
|
+
put: async (program: Program | string): Promise<Address> => {
|
|
410
|
+
const base64 =
|
|
411
|
+
program instanceof Program ? toBase64(serialize(program)) : program;
|
|
412
|
+
const resp = throwIfNot200(
|
|
413
|
+
await axios.put(endpoint + PROGRAM_PATH, base64, {
|
|
414
|
+
validateStatus,
|
|
415
|
+
headers: await getHeaders(),
|
|
416
|
+
})
|
|
417
|
+
);
|
|
418
|
+
return resp.data as string;
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
library: {
|
|
422
|
+
put: async (name: string): Promise<void> => {
|
|
423
|
+
throwIfNot200(
|
|
424
|
+
await axios.put(endpoint + LIBRARY_PATH, name, {
|
|
425
|
+
validateStatus,
|
|
426
|
+
headers: await getHeaders(),
|
|
427
|
+
})
|
|
428
|
+
);
|
|
429
|
+
return;
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
};
|