create-openfort 0.0.6 → 0.0.7
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/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -59,7 +59,7 @@ Content-Type: ${c.type||"application/octet-stream"}\r
|
|
|
59
59
|
`,c,`\r
|
|
60
60
|
`)),s.push(`--${o}--`),new r(s,{type:"multipart/form-data; boundary="+o})}class Pr extends Error{constructor(r,o){super(r),Error.captureStackTrace(this,this.constructor),this.type=o}get name(){return this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}}class $e extends Pr{constructor(r,o,s){super(r,o),s&&(this.code=this.errno=s.code,this.erroredSysCall=s.syscall)}}const $r=Symbol.toStringTag,Yo=i=>typeof i=="object"&&typeof i.append=="function"&&typeof i.delete=="function"&&typeof i.get=="function"&&typeof i.getAll=="function"&&typeof i.has=="function"&&typeof i.set=="function"&&typeof i.sort=="function"&&i[$r]==="URLSearchParams",kr=i=>i&&typeof i=="object"&&typeof i.arrayBuffer=="function"&&typeof i.type=="string"&&typeof i.stream=="function"&&typeof i.constructor=="function"&&/^(Blob|File)$/.test(i[$r]),Dl=i=>typeof i=="object"&&(i[$r]==="AbortSignal"||i[$r]==="EventTarget"),fl=(i,r)=>{const o=new URL(r).hostname,s=new URL(i).hostname;return o===s||o.endsWith(`.${s}`)},dl=(i,r)=>{const o=new URL(r).protocol,s=new URL(i).protocol;return o===s},hl=Zs(Te.pipeline),fe=Symbol("Body internals");class Nt{constructor(r,{size:o=0}={}){let s=null;r===null?r=null:Yo(r)?r=re.from(r.toString()):kr(r)||re.isBuffer(r)||(Fr.isAnyArrayBuffer(r)?r=re.from(r):ArrayBuffer.isView(r)?r=re.from(r.buffer,r.byteOffset,r.byteLength):r instanceof Te||(r instanceof Tr?(r=cl(r),s=r.type.split("=")[1]):r=re.from(String(r))));let a=r;re.isBuffer(r)?a=Te.Readable.from(r):kr(r)&&(a=Te.Readable.from(r.stream())),this[fe]={body:r,stream:a,boundary:s,disturbed:!1,error:null},this.size=o,r instanceof Te&&r.on("error",c=>{const n=c instanceof Pr?c:new $e(`Invalid response body while trying to fetch ${this.url}: ${c.message}`,"system",c);this[fe].error=n})}get body(){return this[fe].stream}get bodyUsed(){return this[fe].disturbed}async arrayBuffer(){const{buffer:r,byteOffset:o,byteLength:s}=await An(this);return r.slice(o,o+s)}async formData(){const r=this.headers.get("content-type");if(r.startsWith("application/x-www-form-urlencoded")){const s=new Tr,a=new URLSearchParams(await this.text());for(const[c,n]of a)s.append(c,n);return s}const{toFormData:o}=await import("./chunks/multipart-parser.mjs");return o(this.body,r)}async blob(){const r=this.headers&&this.headers.get("content-type")||this[fe].body&&this[fe].body.type||"",o=await this.arrayBuffer();return new Ar([o],{type:r})}async json(){const r=await this.text();return JSON.parse(r)}async text(){const r=await An(this);return new TextDecoder().decode(r)}buffer(){return An(this)}}Nt.prototype.buffer=Er(Nt.prototype.buffer,"Please use 'response.arrayBuffer()' instead of 'response.buffer()'","node-fetch#buffer"),Object.defineProperties(Nt.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0},data:{get:Er(()=>{},"data doesn't exist, use json(), text(), arrayBuffer(), or body instead","https://github.com/node-fetch/node-fetch/issues/1000 (response)")}});async function An(i){if(i[fe].disturbed)throw new TypeError(`body used already for: ${i.url}`);if(i[fe].disturbed=!0,i[fe].error)throw i[fe].error;const{body:r}=i;if(r===null)return re.alloc(0);if(!(r instanceof Te))return re.alloc(0);const o=[];let s=0;try{for await(const a of r){if(i.size>0&&s+a.length>i.size){const c=new $e(`content size at ${i.url} over limit: ${i.size}`,"max-size");throw r.destroy(c),c}s+=a.length,o.push(a)}}catch(a){throw a instanceof Pr?a:new $e(`Invalid response body while trying to fetch ${i.url}: ${a.message}`,"system",a)}if(r.readableEnded===!0||r._readableState.ended===!0)try{return o.every(a=>typeof a=="string")?re.from(o.join("")):re.concat(o,s)}catch(a){throw new $e(`Could not create Buffer from response body for ${i.url}: ${a.message}`,"system",a)}else throw new $e(`Premature close of server response while trying to fetch ${i.url}`)}const Tn=(i,r)=>{let o,s,{body:a}=i[fe];if(i.bodyUsed)throw new Error("cannot clone body after it is used");return a instanceof Te&&typeof a.getBoundary!="function"&&(o=new Sr({highWaterMark:r}),s=new Sr({highWaterMark:r}),a.pipe(o),a.pipe(s),i[fe].stream=o,a=s),a},ml=Er(i=>i.getBoundary(),"form-data doesn't follow the spec and requires special treatment. Use alternative package","https://github.com/node-fetch/node-fetch/issues/1167"),Ho=(i,r)=>i===null?null:typeof i=="string"?"text/plain;charset=UTF-8":Yo(i)?"application/x-www-form-urlencoded;charset=UTF-8":kr(i)?i.type||null:re.isBuffer(i)||Fr.isAnyArrayBuffer(i)||ArrayBuffer.isView(i)?null:i instanceof Tr?`multipart/form-data; boundary=${r[fe].boundary}`:i&&typeof i.getBoundary=="function"?`multipart/form-data;boundary=${ml(i)}`:i instanceof Te?null:"text/plain;charset=UTF-8",pl=i=>{const{body:r}=i[fe];return r===null?0:kr(r)?r.size:re.isBuffer(r)?r.length:r&&typeof r.getLengthSync=="function"&&r.hasKnownLength&&r.hasKnownLength()?r.getLengthSync():null},bl=async(i,{body:r})=>{r===null?i.end():await hl(r,i)},Or=typeof Wt.validateHeaderName=="function"?Wt.validateHeaderName:i=>{if(!/^[\^`\-\w!#$%&'*+.|~]+$/.test(i)){const r=new TypeError(`Header name must be a valid HTTP token [${i}]`);throw Object.defineProperty(r,"code",{value:"ERR_INVALID_HTTP_TOKEN"}),r}},Pn=typeof Wt.validateHeaderValue=="function"?Wt.validateHeaderValue:(i,r)=>{if(/[^\t\u0020-\u007E\u0080-\u00FF]/.test(r)){const o=new TypeError(`Invalid character in header content ["${i}"]`);throw Object.defineProperty(o,"code",{value:"ERR_INVALID_CHAR"}),o}};class Le extends URLSearchParams{constructor(r){let o=[];if(r instanceof Le){const s=r.raw();for(const[a,c]of Object.entries(s))o.push(...c.map(n=>[a,n]))}else if(r!=null)if(typeof r=="object"&&!Fr.isBoxedPrimitive(r)){const s=r[Symbol.iterator];if(s==null)o.push(...Object.entries(r));else{if(typeof s!="function")throw new TypeError("Header pairs must be iterable");o=[...r].map(a=>{if(typeof a!="object"||Fr.isBoxedPrimitive(a))throw new TypeError("Each header pair must be an iterable object");return[...a]}).map(a=>{if(a.length!==2)throw new TypeError("Each header pair must be a name/value tuple");return[...a]})}}else throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");return o=o.length>0?o.map(([s,a])=>(Or(s),Pn(s,String(a)),[String(s).toLowerCase(),String(a)])):void 0,super(o),new Proxy(this,{get(s,a,c){switch(a){case"append":case"set":return(n,d)=>(Or(n),Pn(n,String(d)),URLSearchParams.prototype[a].call(s,String(n).toLowerCase(),String(d)));case"delete":case"has":case"getAll":return n=>(Or(n),URLSearchParams.prototype[a].call(s,String(n).toLowerCase()));case"keys":return()=>(s.sort(),new Set(URLSearchParams.prototype.keys.call(s)).keys());default:return Reflect.get(s,a,c)}}})}get[Symbol.toStringTag](){return this.constructor.name}toString(){return Object.prototype.toString.call(this)}get(r){const o=this.getAll(r);if(o.length===0)return null;let s=o.join(", ");return/^content-encoding$/i.test(r)&&(s=s.toLowerCase()),s}forEach(r,o=void 0){for(const s of this.keys())Reflect.apply(r,o,[this.get(s),s,this])}*values(){for(const r of this.keys())yield this.get(r)}*entries(){for(const r of this.keys())yield[r,this.get(r)]}[Symbol.iterator](){return this.entries()}raw(){return[...this.keys()].reduce((r,o)=>(r[o]=this.getAll(o),r),{})}[Symbol.for("nodejs.util.inspect.custom")](){return[...this.keys()].reduce((r,o)=>{const s=this.getAll(o);return o==="host"?r[o]=s[0]:r[o]=s.length>1?s:s[0],r},{})}}Object.defineProperties(Le.prototype,["get","entries","forEach","values"].reduce((i,r)=>(i[r]={enumerable:!0},i),{}));function gl(i=[]){return new Le(i.reduce((r,o,s,a)=>(s%2===0&&r.push(a.slice(s,s+2)),r),[]).filter(([r,o])=>{try{return Or(r),Pn(r,String(o)),!0}catch{return!1}}))}const yl=new Set([301,302,303,307,308]),Ko=i=>yl.has(i),ve=Symbol("Response internals");class ge extends Nt{constructor(r=null,o={}){super(r,o);const s=o.status!=null?o.status:200,a=new Le(o.headers);if(r!==null&&!a.has("Content-Type")){const c=Ho(r,this);c&&a.append("Content-Type",c)}this[ve]={type:"default",url:o.url,status:s,statusText:o.statusText||"",headers:a,counter:o.counter,highWaterMark:o.highWaterMark}}get type(){return this[ve].type}get url(){return this[ve].url||""}get status(){return this[ve].status}get ok(){return this[ve].status>=200&&this[ve].status<300}get redirected(){return this[ve].counter>0}get statusText(){return this[ve].statusText}get headers(){return this[ve].headers}get highWaterMark(){return this[ve].highWaterMark}clone(){return new ge(Tn(this,this.highWaterMark),{type:this.type,url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected,size:this.size,highWaterMark:this.highWaterMark})}static redirect(r,o=302){if(!Ko(o))throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');return new ge(null,{headers:{location:new URL(r).toString()},status:o})}static error(){const r=new ge(null,{status:0,statusText:""});return r[ve].type="error",r}static json(r=void 0,o={}){const s=JSON.stringify(r);if(s===void 0)throw new TypeError("data is not JSON serializable");const a=new Le(o&&o.headers);return a.has("content-type")||a.set("content-type","application/json"),new ge(s,{...o,headers:a})}get[Symbol.toStringTag](){return"Response"}}Object.defineProperties(ge.prototype,{type:{enumerable:!0},url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}});const Cl=i=>{if(i.search)return i.search;const r=i.href.length-1,o=i.hash||(i.href[r]==="#"?"#":"");return i.href[r-o.length]==="?"?"?":""};function Go(i,r=!1){return i==null||(i=new URL(i),/^(about|blob|data):$/.test(i.protocol))?"no-referrer":(i.username="",i.password="",i.hash="",r&&(i.pathname="",i.search=""),i)}const Qo=new Set(["","no-referrer","no-referrer-when-downgrade","same-origin","origin","strict-origin","origin-when-cross-origin","strict-origin-when-cross-origin","unsafe-url"]),Fl="strict-origin-when-cross-origin";function El(i){if(!Qo.has(i))throw new TypeError(`Invalid referrerPolicy: ${i}`);return i}function _l(i){if(/^(http|ws)s:$/.test(i.protocol))return!0;const r=i.host.replace(/(^\[)|(]$)/g,""),o=ua(r);return o===4&&/^127\./.test(r)||o===6&&/^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(r)?!0:i.host==="localhost"||i.host.endsWith(".localhost")?!1:i.protocol==="file:"}function St(i){return/^about:(blank|srcdoc)$/.test(i)||i.protocol==="data:"||/^(blob|filesystem):$/.test(i.protocol)?!0:_l(i)}function Sl(i,{referrerURLCallback:r,referrerOriginCallback:o}={}){if(i.referrer==="no-referrer"||i.referrerPolicy==="")return null;const s=i.referrerPolicy;if(i.referrer==="about:client")return"no-referrer";const a=i.referrer;let c=Go(a),n=Go(a,!0);c.toString().length>4096&&(c=n),r&&(c=r(c)),o&&(n=o(n));const d=new URL(i.url);switch(s){case"no-referrer":return"no-referrer";case"origin":return n;case"unsafe-url":return c;case"strict-origin":return St(c)&&!St(d)?"no-referrer":n.toString();case"strict-origin-when-cross-origin":return c.origin===d.origin?c:St(c)&&!St(d)?"no-referrer":n;case"same-origin":return c.origin===d.origin?c:"no-referrer";case"origin-when-cross-origin":return c.origin===d.origin?c:n;case"no-referrer-when-downgrade":return St(c)&&!St(d)?"no-referrer":c;default:throw new TypeError(`Invalid referrerPolicy: ${s}`)}}function wl(i){const r=(i.get("referrer-policy")||"").split(/[,\s]+/);let o="";for(const s of r)s&&Qo.has(s)&&(o=s);return o}const X=Symbol("Request internals"),Ut=i=>typeof i=="object"&&typeof i[X]=="object",vl=Er(()=>{},".data is not a valid RequestInit property, use .body instead","https://github.com/node-fetch/node-fetch/issues/1000 (request)");class Vt extends Nt{constructor(r,o={}){let s;if(Ut(r)?s=new URL(r.url):(s=new URL(r),r={}),s.username!==""||s.password!=="")throw new TypeError(`${s} is an url with embedded credentials.`);let a=o.method||r.method||"GET";if(/^(delete|get|head|options|post|put)$/i.test(a)&&(a=a.toUpperCase()),!Ut(o)&&"data"in o&&vl(),(o.body!=null||Ut(r)&&r.body!==null)&&(a==="GET"||a==="HEAD"))throw new TypeError("Request with GET/HEAD method cannot have body");const c=o.body?o.body:Ut(r)&&r.body!==null?Tn(r):null;super(c,{size:o.size||r.size||0});const n=new Le(o.headers||r.headers||{});if(c!==null&&!n.has("Content-Type")){const p=Ho(c,this);p&&n.set("Content-Type",p)}let d=Ut(r)?r.signal:null;if("signal"in o&&(d=o.signal),d!=null&&!Dl(d))throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");let f=o.referrer==null?r.referrer:o.referrer;if(f==="")f="no-referrer";else if(f){const p=new URL(f);f=/^about:(\/\/)?client$/.test(p)?"client":p}else f=void 0;this[X]={method:a,redirect:o.redirect||r.redirect||"follow",headers:n,parsedURL:s,signal:d,referrer:f},this.follow=o.follow===void 0?r.follow===void 0?20:r.follow:o.follow,this.compress=o.compress===void 0?r.compress===void 0?!0:r.compress:o.compress,this.counter=o.counter||r.counter||0,this.agent=o.agent||r.agent,this.highWaterMark=o.highWaterMark||r.highWaterMark||16384,this.insecureHTTPParser=o.insecureHTTPParser||r.insecureHTTPParser||!1,this.referrerPolicy=o.referrerPolicy||r.referrerPolicy||""}get method(){return this[X].method}get url(){return na(this[X].parsedURL)}get headers(){return this[X].headers}get redirect(){return this[X].redirect}get signal(){return this[X].signal}get referrer(){if(this[X].referrer==="no-referrer")return"";if(this[X].referrer==="client")return"about:client";if(this[X].referrer)return this[X].referrer.toString()}get referrerPolicy(){return this[X].referrerPolicy}set referrerPolicy(r){this[X].referrerPolicy=El(r)}clone(){return new Vt(this)}get[Symbol.toStringTag](){return"Request"}}Object.defineProperties(Vt.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}});const Bl=i=>{const{parsedURL:r}=i[X],o=new Le(i[X].headers);o.has("Accept")||o.set("Accept","*/*");let s=null;if(i.body===null&&/^(post|put)$/i.test(i.method)&&(s="0"),i.body!==null){const d=pl(i);typeof d=="number"&&!Number.isNaN(d)&&(s=String(d))}s&&o.set("Content-Length",s),i.referrerPolicy===""&&(i.referrerPolicy=Fl),i.referrer&&i.referrer!=="no-referrer"?i[X].referrer=Sl(i):i[X].referrer="no-referrer",i[X].referrer instanceof URL&&o.set("Referer",i.referrer),o.has("User-Agent")||o.set("User-Agent","node-fetch"),i.compress&&!o.has("Accept-Encoding")&&o.set("Accept-Encoding","gzip, deflate, br");let{agent:a}=i;typeof a=="function"&&(a=a(r));const c=Cl(r),n={path:r.pathname+c,method:i.method,headers:o[Symbol.for("nodejs.util.inspect.custom")](),insecureHTTPParser:i.insecureHTTPParser,agent:a};return{parsedURL:r,options:n}};class Rl extends Pr{constructor(r,o="aborted"){super(r,o)}}/*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */var $n,Jo;function Al(){if(Jo)return $n;if(Jo=1,!globalThis.DOMException)try{const{MessageChannel:i}=require("worker_threads"),r=new i().port1,o=new ArrayBuffer;r.postMessage(o,[o,o])}catch(i){i.constructor.name==="DOMException"&&(globalThis.DOMException=i.constructor)}return $n=globalThis.DOMException,$n}Al();const{stat:mc}=ta,Tl=new Set(["data:","http:","https:"]);async function Zo(i,r){return new Promise((o,s)=>{const a=new Vt(i,r),{parsedURL:c,options:n}=Bl(a);if(!Tl.has(c.protocol))throw new TypeError(`node-fetch cannot load ${i}. URL scheme "${c.protocol.replace(/:$/,"")}" is not supported.`);if(c.protocol==="data:"){const E=rl(a.url),U=new ge(E,{headers:{"Content-Type":E.typeFull}});o(U);return}const d=(c.protocol==="https:"?ra:Wt).request,{signal:f}=a;let p=null;const C=()=>{const E=new Rl("The operation was aborted.");s(E),a.body&&a.body instanceof Te.Readable&&a.body.destroy(E),!(!p||!p.body)&&p.body.emit("error",E)};if(f&&f.aborted){C();return}const y=()=>{C(),$()},b=d(c.toString(),n);f&&f.addEventListener("abort",y);const $=()=>{b.abort(),f&&f.removeEventListener("abort",y)};b.on("error",E=>{s(new $e(`request to ${a.url} failed, reason: ${E.message}`,"system",E)),$()}),Pl(b,E=>{p&&p.body&&p.body.destroy(E)}),process.version<"v14"&&b.on("socket",E=>{let U;E.prependListener("end",()=>{U=E._eventsCount}),E.prependListener("close",N=>{if(p&&U<E._eventsCount&&!N){const L=new Error("Premature close");L.code="ERR_STREAM_PREMATURE_CLOSE",p.body.emit("error",L)}})}),b.on("response",E=>{b.setTimeout(0);const U=gl(E.rawHeaders);if(Ko(E.statusCode)){const T=U.get("Location");let I=null;try{I=T===null?null:new URL(T,a.url)}catch{if(a.redirect!=="manual"){s(new $e(`uri requested responds with an invalid redirect URL: ${T}`,"invalid-redirect")),$();return}}switch(a.redirect){case"error":s(new $e(`uri requested responds with a redirect, redirect mode is set to error: ${a.url}`,"no-redirect")),$();return;case"manual":break;case"follow":{if(I===null)break;if(a.counter>=a.follow){s(new $e(`maximum redirect reached at: ${a.url}`,"max-redirect")),$();return}const M={headers:new Le(a.headers),follow:a.follow,counter:a.counter+1,agent:a.agent,compress:a.compress,method:a.method,body:Tn(a),signal:a.signal,size:a.size,referrer:a.referrer,referrerPolicy:a.referrerPolicy};if(!fl(a.url,I)||!dl(a.url,I))for(const se of["authorization","www-authenticate","cookie","cookie2"])M.headers.delete(se);if(E.statusCode!==303&&a.body&&r.body instanceof Te.Readable){s(new $e("Cannot follow redirect with body being a readable stream","unsupported-redirect")),$();return}(E.statusCode===303||(E.statusCode===301||E.statusCode===302)&&a.method==="POST")&&(M.method="GET",M.body=void 0,M.headers.delete("content-length"));const V=wl(U);V&&(M.referrerPolicy=V),o(Zo(new Vt(I,M))),$();return}default:return s(new TypeError(`Redirect option '${a.redirect}' is not a valid value of RequestRedirect`))}}f&&E.once("end",()=>{f.removeEventListener("abort",y)});let N=Et(E,new Sr,T=>{T&&s(T)});process.version<"v12.10"&&E.on("aborted",y);const L={url:a.url,status:E.statusCode,statusText:E.statusMessage,headers:U,size:a.size,counter:a.counter,highWaterMark:a.highWaterMark},J=U.get("Content-Encoding");if(!a.compress||a.method==="HEAD"||J===null||E.statusCode===204||E.statusCode===304){p=new ge(N,L),o(p);return}const ee={flush:_t.Z_SYNC_FLUSH,finishFlush:_t.Z_SYNC_FLUSH};if(J==="gzip"||J==="x-gzip"){N=Et(N,_t.createGunzip(ee),T=>{T&&s(T)}),p=new ge(N,L),o(p);return}if(J==="deflate"||J==="x-deflate"){const T=Et(E,new Sr,I=>{I&&s(I)});T.once("data",I=>{(I[0]&15)===8?N=Et(N,_t.createInflate(),M=>{M&&s(M)}):N=Et(N,_t.createInflateRaw(),M=>{M&&s(M)}),p=new ge(N,L),o(p)}),T.once("end",()=>{p||(p=new ge(N,L),o(p))});return}if(J==="br"){N=Et(N,_t.createBrotliDecompress(),T=>{T&&s(T)}),p=new ge(N,L),o(p);return}p=new ge(N,L),o(p)}),bl(b,a).catch(s)})}function Pl(i,r){const o=re.from(`0\r
|
|
61
61
|
\r
|
|
62
|
-
`);let s=!1,a=!1,c;i.on("response",n=>{const{headers:d}=n;s=d["transfer-encoding"]==="chunked"&&!d["content-length"]}),i.on("socket",n=>{const d=()=>{if(s&&!a){const p=new Error("Premature close");p.code="ERR_STREAM_PREMATURE_CLOSE",r(p)}},f=p=>{a=re.compare(p.slice(-5),o)===0,!a&&c&&(a=re.compare(c.slice(-3),o.slice(0,3))===0&&re.compare(p.slice(-2),o.slice(3))===0),c=p};n.prependListener("close",d),n.on("data",f),i.on("close",()=>{n.removeListener("close",d),n.removeListener("data",f)})})}const kn="0.0.
|
|
62
|
+
`);let s=!1,a=!1,c;i.on("response",n=>{const{headers:d}=n;s=d["transfer-encoding"]==="chunked"&&!d["content-length"]}),i.on("socket",n=>{const d=()=>{if(s&&!a){const p=new Error("Premature close");p.code="ERR_STREAM_PREMATURE_CLOSE",r(p)}},f=p=>{a=re.compare(p.slice(-5),o)===0,!a&&c&&(a=re.compare(c.slice(-3),o.slice(0,3))===0&&re.compare(p.slice(-2),o.slice(3))===0),c=p};n.prependListener("close",d),n.on("data",f),i.on("close",()=>{n.removeListener("close",d),n.removeListener("data",f)})})}const kn="0.0.7";let ne=!1,On=!1;function $l(i,r){ne=i||r,On=r}const kl=()=>{const i=`${Ks()}-${Gs().username}`;return Js("sha256").update(i).digest("hex").slice(0,16)};let Ol=class{anonymousId;enabled=!0;sessionId;projectId;constructor(){this.anonymousId=kl(),this.sessionId=Math.random().toString(36).substring(2,15)}send=async({properties:r={},status:o})=>{if(!this.enabled)return;const s=process.env.POSTHOG_KEY,a=process.env.POSTHOG_HOST;if(!s||!a)return;const c={session_id:this.sessionId,cli_version:kn,node_version:process.version,platform:process.platform,projectId:this.projectId,cli_status:o,...r},n=await Zo(`${a}/capture/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_key:s,event:"cli_tool_used",distinct_id:this.anonymousId,properties:c})}).catch(d=>{On&&z.error("Failed to send telemetry"+JSON.stringify(d,null,2))});On&&(n?.ok?console.log(`Telemetry sent: ${JSON.stringify(c,null,2)}`):console.error(`Failed to send telemetry: ${JSON.stringify(n,null,2)}`))}};const wt=new Ol;function Xo(i){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(i)}function In(i){return i.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function Il(i){const r=Q.readdirSync(i);return r.length===0||r.length===1&&r[0]===".git"}function xl(i){if(Q.existsSync(i))for(const r of Q.readdirSync(i))r!==".git"&&Q.rmSync(De.resolve(i,r),{recursive:!0,force:!0})}async function ei(i,r,{verbose:o}={}){return await new Promise((s,a)=>{o&&z.info(`Running: npx degit ${i} ${r}`);const c=ea("npx",["degit",i,r],{shell:!0});c.stdout.on("data",n=>{o&&process.stdout.write(`\r[CLONE_REPO stdout]: ${n}`)}),c.stderr.on("data",n=>{o&&process.stdout.write(`\r[CLONE_REPO stderr]: ${n}`)}),c.on("close",(n,d)=>{n===0?s():a(new Error(`Process exited with code ${n}`))}),c.on("error",n=>{a(n)})})}function ti(i,r,o=[]){Q.mkdirSync(r,{recursive:!0});for(const s of Q.readdirSync(i)){const a=De.resolve(i,s),c=De.resolve(r,s);Wl(a,c,o)}}function Wl(i,r,o=[]){o.some(s=>s===i)||(Q.statSync(i).isDirectory()?ti(i,r,o):Q.copyFileSync(i,r))}function ql(i,r){const o=Q.readFileSync(i,"utf-8");Q.writeFileSync(i,r(o),"utf-8")}function ri(i){return i.trim().replace(/\/+$/g,"")}class jl{root;cwd=process.cwd();targetDir;packageName;addSubfolders=!1;pkgInfo;pkgManager="npm";constructor(){this.pkgInfo=tl(),this.pkgManager=this.pkgInfo?.name??"npm",ne&&z.info(`Using ${this.pkgInfo?.name??"npm"} ${this.pkgInfo?.version??""}`)}async init({argTargetDir:r,argOverwrite:o,defaultTargetDir:s}){if(r)this.targetDir=r,z.success(`Project name: ${this.targetDir}`);else{const c=await Ze({message:"Project name:",defaultValue:s,placeholder:s});if(me(c))return ie();this.targetDir=ri(c)}if(Q.existsSync(this.targetDir)&&!Il(this.targetDir)){const c=o?"yes":await Lt({message:(this.targetDir==="."?"Current directory":`Target directory "${this.targetDir}"`)+" is not empty. Please choose how to proceed:",options:[{label:"Cancel operation",value:"no"},{label:"Remove existing files and continue",value:"yes"},{label:"Ignore files and continue",value:"ignore"}]});if(me(c))return ie();switch(c){case"yes":xl(this.targetDir);break;case"no":return ie()}}let a=De.basename(De.resolve(this.targetDir));if(!Xo(a)){const c=await Ze({message:"Package name:",defaultValue:In(a),placeholder:In(a),validate(n){if(n&&!Xo(n))return"Invalid package.json name"}});if(me(c))return ie();c?a=c:a=In(a)}return this.packageName=a,this.root=De.join(this.cwd,this.targetDir),Q.mkdirSync(this.root,{recursive:!0}),this}isInitialized(){return!!this.root}getFilePath(r){if(!this.root)throw new Error("FileManager not initialized");return De.join(this.root,this.addSubfolders?"frontend":"",r)}write(r,o){if(!this.root)throw new Error("FileManager not initialized");const s=this.getFilePath(r);o!==void 0&&Q.writeFileSync(s,o)}read(r){if(!this.root)throw new Error("FileManager not initialized");const o=this.getFilePath(r);return Q.readFileSync(o,"utf-8").toString()}async gitPick(r,o){if(!this.root)throw new Error("FileManager not initialized");const s=De.join(this.root,"tmp"),a=Wo();a.start("Downloading template...");try{ne&&z.info(`Cloning repo ${r} path ${o}`);const c=this.addSubfolders?De.join(this.root,"frontend"):this.root;await ei(r,s,{verbose:ne}),ne&&z.info(`Repo cloned. Copying path "${o}" to ${c}`),ti(De.join(s,o),c),Q.rmSync(s,{recursive:!0,force:!0}),ne&&z.info(`Cloned repo ${r}`),a.stop("Template download completed successfully! \u{1F680}")}catch(c){wt.send({properties:{error:JSON.stringify(c),repo:r,repoPath:o},status:"error"}),Q.existsSync(s)&&Q.rmSync(s,{recursive:!0,force:!0}),a.stop("Failed to download template: "+JSON.stringify(c))}}async createBackend({openfortSecretKey:r,shieldSecretKey:o,shieldApiKey:s,shieldEncryptionShare:a,port:c}){if(!this.root)throw new Error("FileManager not initialized");this.addSubfolders=!0;const n=Wo();n.start("Creating backend...");try{ne&&z.info("Creating backend folder from openfort-xyz/openfort-backend-quickstart"),await ei("openfort-xyz/openfort-backend-quickstart",this.addSubfolders?De.join(this.root,"backend"):this.root,{verbose:ne}),ne&&(z.info("Cloned backend folder"),z.info("Copying .env.example to .env"));const d=De.join(this.root,"backend",".env.example"),f=De.join(this.root,"backend",".env");ne&&z.info(`Reading .env.example from ${d}`);const p=Q.readFileSync(d,"utf-8").toString().replace(/OPENFORT_SECRET_KEY=/g,`OPENFORT_SECRET_KEY=${r}`).replace(/SHIELD_SECRET_KEY=/g,`SHIELD_SECRET_KEY=${o}`).replace(/SHIELD_API_KEY=/g,`SHIELD_API_KEY=${s}`).replace(/SHIELD_ENCRYPTION_SHARE=/g,`SHIELD_ENCRYPTION_SHARE=${a}`).replace(/PORT=/g,`PORT=${c}`);ne&&z.info(`Writing .env to ${f}`),Q.writeFileSync(f,p),n.stop("Backend creation completed successfully! \u{1F680}")}catch(d){n.stop("Failed to create backend: "+JSON.stringify(d)),wt.send({properties:{error:JSON.stringify(d)},status:"error"})}}editFile(r,o){if(!this.root)throw new Error("FileManager not initialized");const s=this.getFilePath(r);ql(s,o)}addEnv(r){if(!this.root)throw new Error("FileManager not initialized");ne&&z.info(`Filling .env with provided environment variables:
|
|
63
63
|
${JSON.stringify(r,null,2)}`);const o=this.getFilePath(".env.example"),s=this.getFilePath(".env");ne&&(z.info(`Reading .env.example from ${o}`),z.info(`Writing .env to ${s}`));const a=Q.readFileSync(o,"utf-8").split(`
|
|
64
64
|
`).map(c=>{if(!c.trim()||c.trim().startsWith("#"))return c;const[n]=c.split("=");if(!n)return c;const d=n.includes("_")?n.split("_").slice(1).join("_"):n,f=r[d];return f!==void 0?`${n}=${f}`:c});Q.writeFileSync(s,a.join(`
|
|
65
65
|
`),"utf-8")}outro(){let r="";const o=De.relative(this.cwd,this.root);r+=`Done.
|
|
@@ -75,7 +75,7 @@ For the backend project, run in one terminal.`,r+=`
|
|
|
75
75
|
cd backend`,s(),r+=`
|
|
76
76
|
|
|
77
77
|
Then run the frontend project in another terminal.`,r+=`
|
|
78
|
-
cd frontend`),s(),el(r)}}const{blue:
|
|
78
|
+
cd frontend`),s(),el(r)}}const{blue:bc,blueBright:gc,cyan:Ll,green:zl,greenBright:yc,magenta:Cc,red:Fc,redBright:Ec,reset:_c,yellow:Ml}=_,xn=[{name:"openfort-ui",display:"Openfort UI",hint:"default",color:Ll},{name:"headless",display:"Headless UI",hint:"custom, unstyled",color:zl},{name:"firebase",display:"Third party auth",hint:"with Firebase",color:Ml}],Nl=xn.map(i=>i.name);async function Ul({argTemplate:i,availableTemplates:r=Nl}){let o=i,s=!1;if(i&&(!xn.some(a=>a.name===i)||!r.includes(i))&&(o=void 0,s=!0),!o){const a=await Lt({message:s?`"${i}" isn't a valid template. Please choose from below: `:"Select a template:",options:xn.map(c=>({label:c.color(c.display||c.name),value:c,hint:c.hint}))});if(me(a))return ie();o=a.name}return o}Da.config({path:"./../.env",quiet:!0});const de=da(process.argv.slice(2),{alias:{h:"help",t:"template",o:"overwrite",d:"default",V:"verbose",v:"version"},boolean:["help","overwrite","verbose","validate","version","verbose-debug"],string:["dashboard","template"],default:{template:void 0,overwrite:!1,verbose:!1,validate:!0,default:!1,dashboard:!1,version:!1,telemetry:!0,"verbose-debug":!1}}),Vl=`Usage: create-openfort [OPTION]... [DIRECTORY]
|
|
79
79
|
|
|
80
80
|
Create a new Openfort project in TypeScript.
|
|
81
81
|
With no arguments, start the CLI in interactive mode.
|