@coasys/ad4m-connect 0.10.0-prerelease → 0.10.0-prerelease-fix-1
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/core.js +1 -1
- package/dist/utils.js +1 -1
- package/dist/web.js +2 -2
- package/package.json +13 -13
package/dist/core.js
CHANGED
|
@@ -1088,5 +1088,5 @@ type TriggeredNotification {
|
|
|
1088
1088
|
perspectiveId: String!
|
|
1089
1089
|
triggerMatch: String!
|
|
1090
1090
|
}
|
|
1091
|
-
`;function Du(t){return t?.length?t.length===1?t.toString():t.length===2?t.join(" and "):t.slice(0,-1).join(", ")+", and "+t.slice(-1):""}function kw(t){let e=t.can.includes("*")?["READ","WRITE","UPDATE"]:t.can,r=t.with.domain==="*"?"":t.with.domain,n=t.with.pointers.includes("*")?["all AD4M data"]:t.with.pointers;return`${Du(e)} your ${r} actions, with access to ${Du(n)}`}var lr=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},U=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Fe,ct,ta,fe,ku=class{constructor(t,e,r){Fe.set(this,void 0),ct.set(this,void 0),ta.set(this,void 0),fe.set(this,void 0),lr(this,Fe,e||vt.from(Gu(24)).toUrl(),"f"),lr(this,fe,t,"f"),lr(this,ta,r||"ad4m://self","f")}get baseExpression(){return U(this,Fe,"f")}async getData(t){let e=t??U(this,Fe,"f");console.log("SubjectEntity: getData");let r=await U(this,fe,"f").getSubjectData(U(this,ct,"f"),e);return console.log("SubjectEntity got data:",r),Object.assign(this,r),lr(this,Fe,e,"f"),this}async setProperty(key,value){let setters=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), property_setter(C, "${key}", Setter)`);if(setters&&setters.length>0){let actions=eval(setters[0].Setter),resolveLanguageResults=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), property_resolve_language(C, "${key}", Language)`),resolveLanguage;resolveLanguageResults&&resolveLanguageResults.length>0&&(resolveLanguage=resolveLanguageResults[0].Language),resolveLanguage&&(value=await U(this,fe,"f").createExpression(value,resolveLanguage)),await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}])}}async setCollectionSetter(key,value){let collectionSetters=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), collection_setter(C, "${Dt(key)}", Setter)`);if(collectionSetters||(collectionSetters=[]),collectionSetters.length>0){let actions=eval(collectionSetters[0].Setter);value&&(Array.isArray(value)?await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),value.map(t=>({name:"value",value:t}))):await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}]))}}async setCollectionAdder(key,value){let adders=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), collection_adder(C, "${Dt(key)}", Adder)`);if(adders||(adders=[]),adders.length>0){let actions=eval(adders[0].Adder);value&&(Array.isArray(value)?await Promise.all(value.map(t=>U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value:t}]))):await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}]))}}async setCollectionRemover(key,value){let removers=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), collection_remover(C, "${Dt(key)}", Remover)`);if(removers||(removers=[]),removers.length>0){let actions=eval(removers[0].Remover);value&&(Array.isArray(value)?await Promise.all(value.map(t=>U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value:t}]))):await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}]))}}async save(){lr(this,ct,await U(this,fe,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await U(this,fe,"f").createSubject(this,U(this,Fe,"f")),await U(this,fe,"f").add(new wr({source:U(this,ta,"f"),predicate:"ad4m://has_child",target:this.baseExpression})),await this.update()}async update(){lr(this,ct,await U(this,fe,"f").stringOrTemplateObjectToSubjectClass(this),"f");let t=Object.entries(this);for(let[e,r]of t)if(r!=null)if(r?.action)switch(r.action){case"setter":await this.setCollectionSetter(e,r.value);break;case"adder":await this.setCollectionAdder(e,r.value);break;case"remover":await this.setCollectionRemover(e,r.value);default:await this.setCollectionSetter(e,r.value);break}else Array.isArray(r)&&r.length>0?await this.setCollectionSetter(e,r):r!=null&&r!==""&&await this.setProperty(e,r);await this.getData()}async get(){return lr(this,ct,await U(this,fe,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await this.getData()}async delete(){await U(this,fe,"f").removeSubject(this,U(this,Fe,"f"))}static async all(t){let e=await t.stringOrTemplateObjectToSubjectClass(this),r=await t.getAllSubjectProxies(e),n=[];if(r){for(let i of r){let a=new this(t,i.X);n.push(await a.get())}return n}return[]}static async query(t,e){let r=e?.source||"ad4m://self",n=await t.stringOrTemplateObjectToSubjectClass(this),i=[];if(e)try{if((await t.infer(`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${r}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0].DataLength>=e.size){let s=`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${r}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${e.page}, ${e.size}, PageData).`;i=await t.infer(s),i=i[0].PageData.map(c=>({Base:c[1],Timestamp:c[0]}))}else i=await t.infer(`subject_class("${n}", C), instance(C, Base), triple("${r}", Predicate, Base).`)}catch(o){console.log("Query failed",o)}else i=await t.infer(`subject_class("${n}", C), instance(C, Base), triple("${r}", Predicate, Base).`);return i?await Promise.all(i.map(async o=>await new this(t,o.Base).get())):[]}};Fe=new WeakMap,ct=new WeakMap,ta=new WeakMap,fe=new WeakMap;function Hp(){let t=new AbortController;return setTimeout(()=>t.abort(),20),t}function cs(t,e=1e4){return Ae(this,null,function*(){return Promise.race([new Promise((r,n)=>{t.includes("localhost")||r(new WebSocket(t));let i=new WebSocket(t);i.onopen=()=>{r(i)},i.onerror=a=>{n(a)}}),new Promise((r,n)=>{setTimeout(()=>{n(new Error("WebSocket connection timed out"))},e)})])})}function us(t){return Ae(this,null,function*(){try{let e=yield fetch(`http://localhost:${t}/graphql/`,{signal:Hp().signal,mode:"no-cors"});if(e.status===400||e.status===0)return t;throw new Error(`Could not connect to port ${t}`)}catch(e){throw new Error(`Could not connect to port ${t}`)}})}var Yp=t=>{let e=new Set;do for(let r of Reflect.ownKeys(t))e.add([t,r]);while((t=Reflect.getPrototypeOf(t))&&t!==Object.prototype);return e};function ls(t,{include:e,exclude:r}={}){let n=i=>{let a=o=>typeof o=="string"?i===o:o.test(i);return e?e.some(a):r?!r.some(a):!0};for(let[i,a]of Yp(t.constructor.prototype)){if(a==="constructor"||!n(a))continue;let o=Reflect.getOwnPropertyDescriptor(i,a);o&&typeof o.value=="function"&&(t[a]=t[a].bind(t))}return t}var fs=class{constructor({appName:e,appDesc:r,appIconPath:n,appUrl:i,appDomain:a,capabilities:o,port:s,token:c,url:u}){this.activeSocket=null;this.requestedRestart=!1;this.authState="unauthenticated";this.connectionState="not_connected";this.port=12e3;this.capabilities=[];this.listeners={authstatechange:[],configstatechange:[],connectionstatechange:[]};ls(this);this.appName=e,this.appDesc=r,this.appDomain=a,this.appUrl=i,this.appIconPath=n,this.capabilities=o,this.port=s||this.port,this.url=u||`ws://localhost:${this.port}/graphql`,this.token=c||this.token,this.buildClient()}notifyConfigChange(e,r){this.listeners.configstatechange.forEach(n=>{n(e,r)})}notifyConnectionChange(e){this.connectionState!==e&&(this.connectionState=e,this.listeners.connectionstatechange.forEach(r=>{r(e)}))}notifyAuthChange(e){this.authState!==e&&(this.authState=e,this.listeners.authstatechange.forEach(r=>{r(e)}))}setPort(e){this.port!==e&&(this.port=e,this.setUrl(`ws://localhost:${this.port}/graphql`),this.notifyConfigChange("port",e))}setUrl(e){this.url!==e&&(this.url=e,this.notifyConfigChange("url",e))}setToken(e){this.token!==e&&(this.token=e,this.notifyConfigChange("token",e))}on(e,r){this.listeners[e].push(r)}connect(e){return Ae(this,null,function*(){try{if(e){yield cs(e,1e4),this.setUrl(e);let r=this.buildClient();return yield this.checkAuth(),r}else{let r=yield this.ensureConnection();return yield this.checkAuth(),r}}catch(r){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}loginToHosting(e,r){return Ae(this,null,function*(){try{let n=yield fetch("https://hosting.ad4m.dev/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:r})});if(n.status===200){let i=yield n.json();localStorage.setItem("hosting_token",i.token);let a=localStorage.getItem("hosting_token"),o=yield fetch("https://hosting.ad4m.dev/api/service/info",{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+a}});if(o.status===200){let s=yield o.json();s.serviceId&&(this.setPort(s.port),this.setUrl(`wss://${s.port}.hosting.ad4m.dev/graphql`))}}else if((yield n.json()).message==="Passwords did not match")throw new Error("Passwords did not match")}catch(n){throw console.log(n),new Error(`Error logging in ${n}`)}})}checkEmail(e){return Ae(this,null,function*(){try{return(yield fetch(`https://hosting.ad4m.dev/api/auth/check-email?email=${e}`,{method:"GET",headers:{"Content-Type":"application/json"}})).status===200}catch(r){console.log(r)}})}connectToPort(e){return Ae(this,null,function*(){try{if(e){let r=yield us(e);this.setPort(r)}else{let r=yield this.findPort();this.setPort(r)}return this.buildClient()}catch(r){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}ensureConnection(){return Ae(this,null,function*(){var r,n;if(((r=this.activeSocket)==null?void 0:r.readyState)===WebSocket.OPEN&&((n=this.activeSocket)==null?void 0:n.url)===this.url&&this.ad4mClient)return this.ad4mClient;try{return yield cs(this.url,1e4),this.buildClient()}catch(i){return this.connectToPort()}})}findPort(){return Ae(this,null,function*(){let e=[...Array(10).keys()].map((i,a)=>us(12e3+a)),n=(yield Promise.allSettled(e)).find(i=>i.status==="fulfilled");if(n)return n.value;throw Error("Couldn't find an open port")})}buildClient(){this.notifyConnectionChange("connecting");try{new WebSocket(this.url)}catch(e){this.notifyConnectionChange("not_connected")}return this.apolloClient&&this.wsClient&&(this.requestedRestart=!0,this.wsClient.dispose(),this.apolloClient.stop()),this.wsClient=ou({url:this.url,connectionParams:()=>Ae(this,null,function*(){return{headers:{authorization:this.token}}}),on:{connecting:()=>{this.requestedRestart||this.notifyConnectionChange("connecting")},opened:e=>{this.activeSocket=e},error:e=>{this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")},connected:()=>{this.notifyConnectionChange("connected")},closed:()=>{this.requestedRestart||setTimeout(()=>Ae(this,null,function*(){let e=yield this.connect();e?this.ad4mClient=e:(this.notifyConnectionChange(this.token?"disconnected":"not_connected"),this.notifyAuthChange("unauthenticated"),this.requestedRestart=!1)}),1e3)}}}),this.apolloClient=new Ao({link:new su(this.wsClient),cache:new Pi({resultCaching:!1,addTypename:!1}),defaultOptions:{watchQuery:{fetchPolicy:"no-cache"},query:{fetchPolicy:"no-cache"},mutate:{fetchPolicy:"no-cache"}}}),this.ad4mClient=new da(this.apolloClient),this.ad4mClient}checkAuth(){return Ae(this,null,function*(){try{return(yield this.ad4mClient.agent.isLocked())?this.notifyAuthChange("locked"):(yield this.ad4mClient.agent.status(),this.notifyAuthChange("authenticated")),!0}catch(e){return e.message==="Socket closed with event 4500 Cannot extractByTags from a ciphered wallet. You must unlock first."?(this.notifyAuthChange("locked"),!0):(this.notifyAuthChange("unauthenticated"),!1)}})}requestCapability(e=!1){return Ae(this,null,function*(){var r;return e&&this.setToken(null),this.requestId=yield(r=this.ad4mClient)==null?void 0:r.agent.requestCapability({appName:this.appName,appDesc:this.appDesc,appUrl:this.appUrl,appIconPath:this.appIconPath,appDomain:this.appDomain,capabilities:this.capabilities}),this.requestId})}verifyCode(e){return Ae(this,null,function*(){var n;let r=yield(n=this.ad4mClient)==null?void 0:n.agent.generateJwt(this.requestId,e);return this.setToken(r),yield this.buildClient(),yield this.checkAuth(),this.token})}};export{fs as default};
|
|
1091
|
+
`;function Du(t){return t?.length?t.length===1?t.toString():t.length===2?t.join(" and "):t.slice(0,-1).join(", ")+", and "+t.slice(-1):""}function kw(t){let e=t.can.includes("*")?["READ","WRITE","UPDATE"]:t.can,r=t.with.domain==="*"?"":t.with.domain,n=t.with.pointers.includes("*")?["all AD4M data"]:t.with.pointers;return`${Du(e)} your ${r} actions, with access to ${Du(n)}`}var lr=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},U=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Fe,ct,ta,fe,ku=class{constructor(t,e,r){Fe.set(this,void 0),ct.set(this,void 0),ta.set(this,void 0),fe.set(this,void 0),lr(this,Fe,e||vt.from(Gu(24)).toUrl(),"f"),lr(this,fe,t,"f"),lr(this,ta,r||"ad4m://self","f")}get baseExpression(){return U(this,Fe,"f")}async getData(t){let e=t??U(this,Fe,"f");console.log("SubjectEntity: getData");let r=await U(this,fe,"f").getSubjectData(U(this,ct,"f"),e);return console.log("SubjectEntity got data:",r),Object.assign(this,r),lr(this,Fe,e,"f"),this}async setProperty(key,value){let setters=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), property_setter(C, "${key}", Setter)`);if(setters&&setters.length>0){let actions=eval(setters[0].Setter),resolveLanguageResults=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), property_resolve_language(C, "${key}", Language)`),resolveLanguage;resolveLanguageResults&&resolveLanguageResults.length>0&&(resolveLanguage=resolveLanguageResults[0].Language),resolveLanguage&&(value=await U(this,fe,"f").createExpression(value,resolveLanguage)),await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}])}}async setCollectionSetter(key,value){let collectionSetters=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), collection_setter(C, "${Dt(key)}", Setter)`);if(collectionSetters||(collectionSetters=[]),collectionSetters.length>0){let actions=eval(collectionSetters[0].Setter);value&&(Array.isArray(value)?await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),value.map(t=>({name:"value",value:t}))):await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}]))}}async setCollectionAdder(key,value){let adders=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), collection_adder(C, "${Dt(key)}", Adder)`);if(adders||(adders=[]),adders.length>0){let actions=eval(adders[0].Adder);value&&(Array.isArray(value)?await Promise.all(value.map(t=>U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value:t}]))):await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}]))}}async setCollectionRemover(key,value){let removers=await U(this,fe,"f").infer(`subject_class("${U(this,ct,"f")}", C), collection_remover(C, "${Dt(key)}", Remover)`);if(removers||(removers=[]),removers.length>0){let actions=eval(removers[0].Remover);value&&(Array.isArray(value)?await Promise.all(value.map(t=>U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value:t}]))):await U(this,fe,"f").executeAction(actions,U(this,Fe,"f"),[{name:"value",value}]))}}async save(){lr(this,ct,await U(this,fe,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await U(this,fe,"f").createSubject(this,U(this,Fe,"f")),await U(this,fe,"f").add(new wr({source:U(this,ta,"f"),predicate:"ad4m://has_child",target:this.baseExpression})),await this.update()}async update(){lr(this,ct,await U(this,fe,"f").stringOrTemplateObjectToSubjectClass(this),"f");let t=Object.entries(this);for(let[e,r]of t)if(r!=null)if(r?.action)switch(r.action){case"setter":await this.setCollectionSetter(e,r.value);break;case"adder":await this.setCollectionAdder(e,r.value);break;case"remover":await this.setCollectionRemover(e,r.value);default:await this.setCollectionSetter(e,r.value);break}else Array.isArray(r)&&r.length>0?await this.setCollectionSetter(e,r):r!=null&&r!==""&&await this.setProperty(e,r);await this.getData()}async get(){return lr(this,ct,await U(this,fe,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await this.getData()}async delete(){await U(this,fe,"f").removeSubject(this,U(this,Fe,"f"))}static async all(t){let e=await t.stringOrTemplateObjectToSubjectClass(this),r=await t.getAllSubjectProxies(e),n=[];if(r){for(let i of r){let a=new this(t,i.X);n.push(await a.get())}return n}return[]}static async query(t,e){let r=e?.source||"ad4m://self",n=await t.stringOrTemplateObjectToSubjectClass(this),i=[];if(e)try{if((await t.infer(`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${r}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0].DataLength>=e.size){let s=`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${r}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${e.page}, ${e.size}, PageData).`;i=await t.infer(s),i=i[0].PageData.map(c=>({Base:c[1],Timestamp:c[0]}))}else i=await t.infer(`subject_class("${n}", C), instance(C, Base), triple("${r}", Predicate, Base).`)}catch(o){console.log("Query failed",o)}else i=await t.infer(`subject_class("${n}", C), instance(C, Base), triple("${r}", Predicate, Base).`);return i?await Promise.all(i.map(async o=>await new this(t,o.Base).get())):[]}};Fe=new WeakMap,ct=new WeakMap,ta=new WeakMap,fe=new WeakMap;function Hp(){let t=new AbortController;return setTimeout(()=>t.abort(),20),t}function cs(t,e=1e4){return Ae(this,null,function*(){return Promise.race([new Promise((r,n)=>{t.includes("localhost")||r(new WebSocket(t));let i=new WebSocket(t);i.onopen=()=>{r(i)},i.onerror=a=>{n(a)}}),new Promise((r,n)=>{setTimeout(()=>{n(new Error("WebSocket connection timed out"))},e)})])})}function us(t){return Ae(this,null,function*(){try{let e=yield fetch(`http://localhost:${t}/graphql/`,{signal:Hp().signal,mode:"no-cors"});if(e.status===400||e.status===0)return t;throw new Error(`Could not connect to port ${t}`)}catch(e){throw new Error(`Could not connect to port ${t}`)}})}var Yp=t=>{let e=new Set;do for(let r of Reflect.ownKeys(t))e.add([t,r]);while((t=Reflect.getPrototypeOf(t))&&t!==Object.prototype);return e};function ls(t,{include:e,exclude:r}={}){let n=i=>{let a=o=>typeof o=="string"?i===o:o.test(i);return e?e.some(a):r?!r.some(a):!0};for(let[i,a]of Yp(t.constructor.prototype)){if(a==="constructor"||!n(a))continue;let o=Reflect.getOwnPropertyDescriptor(i,a);o&&typeof o.value=="function"&&(t[a]=t[a].bind(t))}return t}var fs=class{constructor({appName:e,appDesc:r,appIconPath:n,appUrl:i,appDomain:a,capabilities:o,port:s,token:c,url:u}){this.activeSocket=null;this.requestedRestart=!1;this.authState="unauthenticated";this.connectionState="not_connected";this.port=12e3;this.capabilities=[];this.listeners={authstatechange:[],configstatechange:[],connectionstatechange:[]};ls(this);this.appName=e,this.appDesc=r,this.appDomain=a,this.appUrl=i,this.appIconPath=n,this.capabilities=o,this.port=s||this.port,this.url=u||`ws://localhost:${this.port}/graphql`,this.token=c||this.token,this.buildClient()}notifyConfigChange(e,r){this.listeners.configstatechange.forEach(n=>{n(e,r)})}notifyConnectionChange(e){this.connectionState!==e&&(this.connectionState=e,this.listeners.connectionstatechange.forEach(r=>{r(e)}))}notifyAuthChange(e){this.authState!==e&&(this.authState=e,this.listeners.authstatechange.forEach(r=>{r(e)}))}setPort(e){this.port!==e&&(this.port=e,this.setUrl(`ws://localhost:${this.port}/graphql`),this.notifyConfigChange("port",e))}setUrl(e){this.url!==e&&(this.url=e,this.notifyConfigChange("url",e))}setToken(e){this.token!==e&&(this.token=e,this.notifyConfigChange("token",e))}on(e,r){this.listeners[e].push(r)}connect(e){return Ae(this,null,function*(){try{if(e){yield cs(e,1e4),this.setUrl(e);let r=this.buildClient();return yield this.checkAuth(),r}else{let r=yield this.ensureConnection();return yield this.checkAuth(),r}}catch(r){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}loginToHosting(e,r){return Ae(this,null,function*(){try{let n=yield fetch("https://hosting.ad4m.dev/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:r})});if(n.status===200){let i=yield n.json();localStorage.setItem("hosting_token",i.token);let a=localStorage.getItem("hosting_token"),o=yield fetch("https://hosting.ad4m.dev/api/service/info",{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+a}});if(o.status===200){let s=yield o.json();s.serviceId&&(this.setPort(s.port),this.setUrl(`wss://${s.port}.hosting.ad4m.dev/graphql`),this.connect())}}else if((yield n.json()).message==="Passwords did not match")throw new Error("Passwords did not match")}catch(n){throw console.log(n),new Error(`Error logging in ${n}`)}})}checkEmail(e){return Ae(this,null,function*(){try{return(yield fetch(`https://hosting.ad4m.dev/api/auth/check-email?email=${e}`,{method:"GET",headers:{"Content-Type":"application/json"}})).status===200}catch(r){console.log(r)}})}connectToPort(e){return Ae(this,null,function*(){try{if(e){let r=yield us(e);this.setPort(r)}else{let r=yield this.findPort();this.setPort(r)}return this.buildClient()}catch(r){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}ensureConnection(){return Ae(this,null,function*(){var r,n;if(((r=this.activeSocket)==null?void 0:r.readyState)===WebSocket.OPEN&&((n=this.activeSocket)==null?void 0:n.url)===this.url&&this.ad4mClient)return this.ad4mClient;try{return yield cs(this.url,1e4),this.buildClient()}catch(i){return this.connectToPort()}})}findPort(){return Ae(this,null,function*(){let e=[...Array(10).keys()].map((i,a)=>us(12e3+a)),n=(yield Promise.allSettled(e)).find(i=>i.status==="fulfilled");if(n)return n.value;throw Error("Couldn't find an open port")})}buildClient(){this.notifyConnectionChange("connecting");try{new WebSocket(this.url)}catch(e){this.notifyConnectionChange("not_connected")}return this.apolloClient&&this.wsClient&&(this.requestedRestart=!0,this.wsClient.dispose(),this.apolloClient.stop()),this.wsClient=ou({url:this.url,connectionParams:()=>Ae(this,null,function*(){return{headers:{authorization:this.token}}}),on:{connecting:()=>{this.requestedRestart||this.notifyConnectionChange("connecting")},opened:e=>{this.activeSocket=e},error:e=>{this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")},connected:()=>{this.notifyConnectionChange("connected")},closed:()=>Ae(this,null,function*(){if(!this.requestedRestart)if(!this.url)console.log("meow 3"),this.notifyConnectionChange(this.token?"disconnected":"not_connected"),this.notifyAuthChange("unauthenticated"),this.requestedRestart=!1;else{let e=yield this.connect();e?this.ad4mClient=e:(this.notifyConnectionChange(this.token?"disconnected":"not_connected"),this.notifyAuthChange("unauthenticated"),this.requestedRestart=!1)}})}}),this.apolloClient=new Ao({link:new su(this.wsClient),cache:new Pi({resultCaching:!1,addTypename:!1}),defaultOptions:{watchQuery:{fetchPolicy:"no-cache"},query:{fetchPolicy:"no-cache"},mutate:{fetchPolicy:"no-cache"}}}),this.ad4mClient=new da(this.apolloClient),this.ad4mClient}checkAuth(){return Ae(this,null,function*(){try{return(yield this.ad4mClient.agent.isLocked())?this.notifyAuthChange("locked"):(yield this.ad4mClient.agent.status(),this.notifyAuthChange("authenticated")),!0}catch(e){return e.message==="Socket closed with event 4500 Cannot extractByTags from a ciphered wallet. You must unlock first."?(this.notifyAuthChange("locked"),!0):(this.notifyAuthChange("unauthenticated"),!1)}})}requestCapability(e=!1){return Ae(this,null,function*(){var r;return e&&this.setToken(null),this.requestId=yield(r=this.ad4mClient)==null?void 0:r.agent.requestCapability({appName:this.appName,appDesc:this.appDesc,appUrl:this.appUrl,appIconPath:this.appIconPath,appDomain:this.appDomain,capabilities:this.capabilities}),this.requestId})}verifyCode(e){return Ae(this,null,function*(){var n;let r=yield(n=this.ad4mClient)==null?void 0:n.agent.generateJwt(this.requestId,e);return this.setToken(r),yield this.buildClient(),yield this.checkAuth(),this.token})}};export{fs as default};
|
|
1092
1092
|
//! @fayeed - make it support node.js
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a=(e,t,o)=>new Promise((n,r)=>{var c=s=>{try{l(o.next(s))}catch(u){r(u)}},p=s=>{try{l(o.throw(s))}catch(u){r(u)}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(c,p);l((o=o.apply(e,t)).next())});var i="0.10.0-prerelease";function b(){let e=new AbortController;return setTimeout(()=>e.abort(),20),e}function w(e,t=1e4){return a(this,null,function*(){return Promise.race([new Promise((o,n)=>{e.includes("localhost")||o(new WebSocket(e));let r=new WebSocket(e);r.onopen=()=>{o(r)},r.onerror=c=>{n(c)}}),new Promise((o,n)=>{setTimeout(()=>{n(new Error("WebSocket connection timed out"))},t)})])})}function j(e){return a(this,null,function*(){try{let t=yield fetch(`http://localhost:${e}/graphql/`,{signal:b().signal,mode:"no-cors"});if(t.status===400||t.status===0)return e;throw new Error(`Could not connect to port ${e}`)}catch(t){throw new Error(`Could not connect to port ${e}`)}})}function v(){return new Promise((e,t)=>{let o=document.querySelector("ad4m-connect"),n=o==null?void 0:o.getAd4mClient();n?e(n):t("No Ad4mClient found")})}function y(e){let t=document.querySelector("ad4m-connect");t==null||t.addEventListener("authstatechange",o=>{e(o.detail)})}function S(){let e=navigator.userAgent,t="";return e.search("Windows")!==-1?t="Windows":e.search("Mac")!==-1?t="MacOS":e.search("X11")!==-1&&e.search("Linux")===-1?t="UNIX":e.search("Linux")!==-1&&e.search("X11")!==-1&&(t="Linux"),t}function d(){try{localStorage.setItem("test",""),localStorage.removeItem("test")}catch(e){return!1}return!0}function x(e,t){d()&&localStorage.setItem(`${i}/${e}`,t)}function A(e){return d()?localStorage.getItem(`${i}/${e}`):null}function C(e){d()&&localStorage.removeItem(`${i}/${e}`)}export{j as checkPort,w as connectWebSocket,S as detectOS,v as getAd4mClient,A as getForVersion,y as onAuthStateChanged,C as removeForVersion,x as setForVersion};
|
|
1
|
+
var a=(e,t,o)=>new Promise((n,r)=>{var c=s=>{try{l(o.next(s))}catch(u){r(u)}},p=s=>{try{l(o.throw(s))}catch(u){r(u)}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(c,p);l((o=o.apply(e,t)).next())});var i="0.10.0-prerelease-fix-1";function b(){let e=new AbortController;return setTimeout(()=>e.abort(),20),e}function w(e,t=1e4){return a(this,null,function*(){return Promise.race([new Promise((o,n)=>{e.includes("localhost")||o(new WebSocket(e));let r=new WebSocket(e);r.onopen=()=>{o(r)},r.onerror=c=>{n(c)}}),new Promise((o,n)=>{setTimeout(()=>{n(new Error("WebSocket connection timed out"))},t)})])})}function j(e){return a(this,null,function*(){try{let t=yield fetch(`http://localhost:${e}/graphql/`,{signal:b().signal,mode:"no-cors"});if(t.status===400||t.status===0)return e;throw new Error(`Could not connect to port ${e}`)}catch(t){throw new Error(`Could not connect to port ${e}`)}})}function v(){return new Promise((e,t)=>{let o=document.querySelector("ad4m-connect"),n=o==null?void 0:o.getAd4mClient();n?e(n):t("No Ad4mClient found")})}function y(e){let t=document.querySelector("ad4m-connect");t==null||t.addEventListener("authstatechange",o=>{e(o.detail)})}function S(){let e=navigator.userAgent,t="";return e.search("Windows")!==-1?t="Windows":e.search("Mac")!==-1?t="MacOS":e.search("X11")!==-1&&e.search("Linux")===-1?t="UNIX":e.search("Linux")!==-1&&e.search("X11")!==-1&&(t="Linux"),t}function d(){try{localStorage.setItem("test",""),localStorage.removeItem("test")}catch(e){return!1}return!0}function x(e,t){d()&&localStorage.setItem(`${i}/${e}`,t)}function A(e){return d()?localStorage.getItem(`${i}/${e}`):null}function C(e){d()&&localStorage.removeItem(`${i}/${e}`)}export{j as checkPort,w as connectWebSocket,S as detectOS,v as getAd4mClient,A as getForVersion,y as onAuthStateChanged,C as removeForVersion,x as setForVersion};
|
package/dist/web.js
CHANGED
|
@@ -1090,7 +1090,7 @@ type TriggeredNotification {
|
|
|
1090
1090
|
perspectiveId: String!
|
|
1091
1091
|
triggerMatch: String!
|
|
1092
1092
|
}
|
|
1093
|
-
`;function sp(r){return r?.length?r.length===1?r.toString():r.length===2?r.join(" and "):r.slice(0,-1).join(", ")+", and "+r.slice(-1):""}function xp(r){let e=r.can.includes("*")?["READ","WRITE","UPDATE"]:r.can,t=r.with.domain==="*"?"":r.with.domain,n=r.with.pointers.includes("*")?["all AD4M data"]:r.with.pointers;return`${sp(e)} your ${t} actions, with access to ${sp(n)}`}var Ir=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},B=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},Be,gt,La,ye,cp=class{constructor(r,e,t){Be.set(this,void 0),gt.set(this,void 0),La.set(this,void 0),ye.set(this,void 0),Ir(this,Be,e||Ot.from(Ep(24)).toUrl(),"f"),Ir(this,ye,r,"f"),Ir(this,La,t||"ad4m://self","f")}get baseExpression(){return B(this,Be,"f")}async getData(r){let e=r??B(this,Be,"f");console.log("SubjectEntity: getData");let t=await B(this,ye,"f").getSubjectData(B(this,gt,"f"),e);return console.log("SubjectEntity got data:",t),Object.assign(this,t),Ir(this,Be,e,"f"),this}async setProperty(key,value){let setters=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), property_setter(C, "${key}", Setter)`);if(setters&&setters.length>0){let actions=eval(setters[0].Setter),resolveLanguageResults=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), property_resolve_language(C, "${key}", Language)`),resolveLanguage;resolveLanguageResults&&resolveLanguageResults.length>0&&(resolveLanguage=resolveLanguageResults[0].Language),resolveLanguage&&(value=await B(this,ye,"f").createExpression(value,resolveLanguage)),await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}])}}async setCollectionSetter(key,value){let collectionSetters=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), collection_setter(C, "${$t(key)}", Setter)`);if(collectionSetters||(collectionSetters=[]),collectionSetters.length>0){let actions=eval(collectionSetters[0].Setter);value&&(Array.isArray(value)?await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),value.map(r=>({name:"value",value:r}))):await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}]))}}async setCollectionAdder(key,value){let adders=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), collection_adder(C, "${$t(key)}", Adder)`);if(adders||(adders=[]),adders.length>0){let actions=eval(adders[0].Adder);value&&(Array.isArray(value)?await Promise.all(value.map(r=>B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value:r}]))):await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}]))}}async setCollectionRemover(key,value){let removers=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), collection_remover(C, "${$t(key)}", Remover)`);if(removers||(removers=[]),removers.length>0){let actions=eval(removers[0].Remover);value&&(Array.isArray(value)?await Promise.all(value.map(r=>B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value:r}]))):await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}]))}}async save(){Ir(this,gt,await B(this,ye,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await B(this,ye,"f").createSubject(this,B(this,Be,"f")),await B(this,ye,"f").add(new jr({source:B(this,La,"f"),predicate:"ad4m://has_child",target:this.baseExpression})),await this.update()}async update(){Ir(this,gt,await B(this,ye,"f").stringOrTemplateObjectToSubjectClass(this),"f");let r=Object.entries(this);for(let[e,t]of r)if(t!=null)if(t?.action)switch(t.action){case"setter":await this.setCollectionSetter(e,t.value);break;case"adder":await this.setCollectionAdder(e,t.value);break;case"remover":await this.setCollectionRemover(e,t.value);default:await this.setCollectionSetter(e,t.value);break}else Array.isArray(t)&&t.length>0?await this.setCollectionSetter(e,t):t!=null&&t!==""&&await this.setProperty(e,t);await this.getData()}async get(){return Ir(this,gt,await B(this,ye,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await this.getData()}async delete(){await B(this,ye,"f").removeSubject(this,B(this,Be,"f"))}static async all(r){let e=await r.stringOrTemplateObjectToSubjectClass(this),t=await r.getAllSubjectProxies(e),n=[];if(t){for(let i of t){let a=new this(r,i.X);n.push(await a.get())}return n}return[]}static async query(r,e){let t=e?.source||"ad4m://self",n=await r.stringOrTemplateObjectToSubjectClass(this),i=[];if(e)try{if((await r.infer(`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${t}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0].DataLength>=e.size){let s=`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${t}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${e.page}, ${e.size}, PageData).`;i=await r.infer(s),i=i[0].PageData.map(c=>({Base:c[1],Timestamp:c[0]}))}else i=await r.infer(`subject_class("${n}", C), instance(C, Base), triple("${t}", Predicate, Base).`)}catch(o){console.log("Query failed",o)}else i=await r.infer(`subject_class("${n}", C), instance(C, Base), triple("${t}", Predicate, Base).`);return i?await Promise.all(i.map(async o=>await new this(r,o.Base).get())):[]}};Be=new WeakMap,gt=new WeakMap,La=new WeakMap,ye=new WeakMap;var ro="0.10.0-prerelease";function W1(){let r=new AbortController;return setTimeout(()=>r.abort(),20),r}function cc(r,e=1e4){return ue(this,null,function*(){return Promise.race([new Promise((t,n)=>{r.includes("localhost")||t(new WebSocket(r));let i=new WebSocket(r);i.onopen=()=>{t(i)},i.onerror=a=>{n(a)}}),new Promise((t,n)=>{setTimeout(()=>{n(new Error("WebSocket connection timed out"))},e)})])})}function uc(r){return ue(this,null,function*(){try{let e=yield fetch(`http://localhost:${r}/graphql/`,{signal:W1().signal,mode:"no-cors"});if(e.status===400||e.status===0)return r;throw new Error(`Could not connect to port ${r}`)}catch(e){throw new Error(`Could not connect to port ${r}`)}})}function K1(){return new Promise((r,e)=>{let t=document.querySelector("ad4m-connect"),n=t==null?void 0:t.getAd4mClient();n?r(n):e("No Ad4mClient found")})}function lc(){try{localStorage.setItem("test",""),localStorage.removeItem("test")}catch(r){return!1}return!0}function Op(r,e){lc()&&localStorage.setItem(`${ro}/${r}`,e)}function Wr(r){return lc()?localStorage.getItem(`${ro}/${r}`):null}function Tp(r){lc()&&localStorage.removeItem(`${ro}/${r}`)}var z1=r=>{let e=new Set;do for(let t of Reflect.ownKeys(r))e.add([r,t]);while((r=Reflect.getPrototypeOf(r))&&r!==Object.prototype);return e};function Ti(r,{include:e,exclude:t}={}){let n=i=>{let a=o=>typeof o=="string"?i===o:o.test(i);return e?e.some(a):t?!t.some(a):!0};for(let[i,a]of z1(r.constructor.prototype)){if(a==="constructor"||!n(a))continue;let o=Reflect.getOwnPropertyDescriptor(i,a);o&&typeof o.value=="function"&&(r[a]=r[a].bind(r))}return r}var Ii=class{constructor({appName:e,appDesc:t,appIconPath:n,appUrl:i,appDomain:a,capabilities:o,port:s,token:c,url:u}){this.activeSocket=null;this.requestedRestart=!1;this.authState="unauthenticated";this.connectionState="not_connected";this.port=12e3;this.capabilities=[];this.listeners={authstatechange:[],configstatechange:[],connectionstatechange:[]};Ti(this);this.appName=e,this.appDesc=t,this.appDomain=a,this.appUrl=i,this.appIconPath=n,this.capabilities=o,this.port=s||this.port,this.url=u||`ws://localhost:${this.port}/graphql`,this.token=c||this.token,this.buildClient()}notifyConfigChange(e,t){this.listeners.configstatechange.forEach(n=>{n(e,t)})}notifyConnectionChange(e){this.connectionState!==e&&(this.connectionState=e,this.listeners.connectionstatechange.forEach(t=>{t(e)}))}notifyAuthChange(e){this.authState!==e&&(this.authState=e,this.listeners.authstatechange.forEach(t=>{t(e)}))}setPort(e){this.port!==e&&(this.port=e,this.setUrl(`ws://localhost:${this.port}/graphql`),this.notifyConfigChange("port",e))}setUrl(e){this.url!==e&&(this.url=e,this.notifyConfigChange("url",e))}setToken(e){this.token!==e&&(this.token=e,this.notifyConfigChange("token",e))}on(e,t){this.listeners[e].push(t)}connect(e){return ue(this,null,function*(){try{if(e){yield cc(e,1e4),this.setUrl(e);let t=this.buildClient();return yield this.checkAuth(),t}else{let t=yield this.ensureConnection();return yield this.checkAuth(),t}}catch(t){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}loginToHosting(e,t){return ue(this,null,function*(){try{let n=yield fetch("https://hosting.ad4m.dev/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:t})});if(n.status===200){let i=yield n.json();localStorage.setItem("hosting_token",i.token);let a=localStorage.getItem("hosting_token"),o=yield fetch("https://hosting.ad4m.dev/api/service/info",{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+a}});if(o.status===200){let s=yield o.json();s.serviceId&&(this.setPort(s.port),this.setUrl(`wss://${s.port}.hosting.ad4m.dev/graphql`))}}else if((yield n.json()).message==="Passwords did not match")throw new Error("Passwords did not match")}catch(n){throw console.log(n),new Error(`Error logging in ${n}`)}})}checkEmail(e){return ue(this,null,function*(){try{return(yield fetch(`https://hosting.ad4m.dev/api/auth/check-email?email=${e}`,{method:"GET",headers:{"Content-Type":"application/json"}})).status===200}catch(t){console.log(t)}})}connectToPort(e){return ue(this,null,function*(){try{if(e){let t=yield uc(e);this.setPort(t)}else{let t=yield this.findPort();this.setPort(t)}return this.buildClient()}catch(t){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}ensureConnection(){return ue(this,null,function*(){var t,n;if(((t=this.activeSocket)==null?void 0:t.readyState)===WebSocket.OPEN&&((n=this.activeSocket)==null?void 0:n.url)===this.url&&this.ad4mClient)return this.ad4mClient;try{return yield cc(this.url,1e4),this.buildClient()}catch(i){return this.connectToPort()}})}findPort(){return ue(this,null,function*(){let e=[...Array(10).keys()].map((i,a)=>uc(12e3+a)),n=(yield Promise.allSettled(e)).find(i=>i.status==="fulfilled");if(n)return n.value;throw Error("Couldn't find an open port")})}buildClient(){this.notifyConnectionChange("connecting");try{new WebSocket(this.url)}catch(e){this.notifyConnectionChange("not_connected")}return this.apolloClient&&this.wsClient&&(this.requestedRestart=!0,this.wsClient.dispose(),this.apolloClient.stop()),this.wsClient=jl({url:this.url,connectionParams:()=>ue(this,null,function*(){return{headers:{authorization:this.token}}}),on:{connecting:()=>{this.requestedRestart||this.notifyConnectionChange("connecting")},opened:e=>{this.activeSocket=e},error:e=>{this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")},connected:()=>{this.notifyConnectionChange("connected")},closed:()=>{this.requestedRestart||setTimeout(()=>ue(this,null,function*(){let e=yield this.connect();e?this.ad4mClient=e:(this.notifyConnectionChange(this.token?"disconnected":"not_connected"),this.notifyAuthChange("unauthenticated"),this.requestedRestart=!1)}),1e3)}}}),this.apolloClient=new Ds({link:new Ul(this.wsClient),cache:new fa({resultCaching:!1,addTypename:!1}),defaultOptions:{watchQuery:{fetchPolicy:"no-cache"},query:{fetchPolicy:"no-cache"},mutate:{fetchPolicy:"no-cache"}}}),this.ad4mClient=new Ka(this.apolloClient),this.ad4mClient}checkAuth(){return ue(this,null,function*(){try{return(yield this.ad4mClient.agent.isLocked())?this.notifyAuthChange("locked"):(yield this.ad4mClient.agent.status(),this.notifyAuthChange("authenticated")),!0}catch(e){return e.message==="Socket closed with event 4500 Cannot extractByTags from a ciphered wallet. You must unlock first."?(this.notifyAuthChange("locked"),!0):(this.notifyAuthChange("unauthenticated"),!1)}})}requestCapability(e=!1){return ue(this,null,function*(){var t;return e&&this.setToken(null),this.requestId=yield(t=this.ad4mClient)==null?void 0:t.agent.requestCapability({appName:this.appName,appDesc:this.appDesc,appUrl:this.appUrl,appIconPath:this.appIconPath,appDomain:this.appDomain,capabilities:this.capabilities}),this.requestId})}verifyCode(e){return ue(this,null,function*(){var n;let t=yield(n=this.ad4mClient)==null?void 0:n.agent.generateJwt(this.requestId,e);return this.setToken(t),yield this.buildClient(),yield this.checkAuth(),this.token})}};function pc(){return q`
|
|
1093
|
+
`;function sp(r){return r?.length?r.length===1?r.toString():r.length===2?r.join(" and "):r.slice(0,-1).join(", ")+", and "+r.slice(-1):""}function xp(r){let e=r.can.includes("*")?["READ","WRITE","UPDATE"]:r.can,t=r.with.domain==="*"?"":r.with.domain,n=r.with.pointers.includes("*")?["all AD4M data"]:r.with.pointers;return`${sp(e)} your ${t} actions, with access to ${sp(n)}`}var Ir=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},B=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},Be,gt,La,ye,cp=class{constructor(r,e,t){Be.set(this,void 0),gt.set(this,void 0),La.set(this,void 0),ye.set(this,void 0),Ir(this,Be,e||Ot.from(Ep(24)).toUrl(),"f"),Ir(this,ye,r,"f"),Ir(this,La,t||"ad4m://self","f")}get baseExpression(){return B(this,Be,"f")}async getData(r){let e=r??B(this,Be,"f");console.log("SubjectEntity: getData");let t=await B(this,ye,"f").getSubjectData(B(this,gt,"f"),e);return console.log("SubjectEntity got data:",t),Object.assign(this,t),Ir(this,Be,e,"f"),this}async setProperty(key,value){let setters=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), property_setter(C, "${key}", Setter)`);if(setters&&setters.length>0){let actions=eval(setters[0].Setter),resolveLanguageResults=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), property_resolve_language(C, "${key}", Language)`),resolveLanguage;resolveLanguageResults&&resolveLanguageResults.length>0&&(resolveLanguage=resolveLanguageResults[0].Language),resolveLanguage&&(value=await B(this,ye,"f").createExpression(value,resolveLanguage)),await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}])}}async setCollectionSetter(key,value){let collectionSetters=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), collection_setter(C, "${$t(key)}", Setter)`);if(collectionSetters||(collectionSetters=[]),collectionSetters.length>0){let actions=eval(collectionSetters[0].Setter);value&&(Array.isArray(value)?await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),value.map(r=>({name:"value",value:r}))):await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}]))}}async setCollectionAdder(key,value){let adders=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), collection_adder(C, "${$t(key)}", Adder)`);if(adders||(adders=[]),adders.length>0){let actions=eval(adders[0].Adder);value&&(Array.isArray(value)?await Promise.all(value.map(r=>B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value:r}]))):await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}]))}}async setCollectionRemover(key,value){let removers=await B(this,ye,"f").infer(`subject_class("${B(this,gt,"f")}", C), collection_remover(C, "${$t(key)}", Remover)`);if(removers||(removers=[]),removers.length>0){let actions=eval(removers[0].Remover);value&&(Array.isArray(value)?await Promise.all(value.map(r=>B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value:r}]))):await B(this,ye,"f").executeAction(actions,B(this,Be,"f"),[{name:"value",value}]))}}async save(){Ir(this,gt,await B(this,ye,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await B(this,ye,"f").createSubject(this,B(this,Be,"f")),await B(this,ye,"f").add(new jr({source:B(this,La,"f"),predicate:"ad4m://has_child",target:this.baseExpression})),await this.update()}async update(){Ir(this,gt,await B(this,ye,"f").stringOrTemplateObjectToSubjectClass(this),"f");let r=Object.entries(this);for(let[e,t]of r)if(t!=null)if(t?.action)switch(t.action){case"setter":await this.setCollectionSetter(e,t.value);break;case"adder":await this.setCollectionAdder(e,t.value);break;case"remover":await this.setCollectionRemover(e,t.value);default:await this.setCollectionSetter(e,t.value);break}else Array.isArray(t)&&t.length>0?await this.setCollectionSetter(e,t):t!=null&&t!==""&&await this.setProperty(e,t);await this.getData()}async get(){return Ir(this,gt,await B(this,ye,"f").stringOrTemplateObjectToSubjectClass(this),"f"),await this.getData()}async delete(){await B(this,ye,"f").removeSubject(this,B(this,Be,"f"))}static async all(r){let e=await r.stringOrTemplateObjectToSubjectClass(this),t=await r.getAllSubjectProxies(e),n=[];if(t){for(let i of t){let a=new this(r,i.X);n.push(await a.get())}return n}return[]}static async query(r,e){let t=e?.source||"ad4m://self",n=await r.stringOrTemplateObjectToSubjectClass(this),i=[];if(e)try{if((await r.infer(`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${t}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0].DataLength>=e.size){let s=`findall([Timestamp, Base], (subject_class("${n}", C), instance(C, Base), link("${t}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${e.page}, ${e.size}, PageData).`;i=await r.infer(s),i=i[0].PageData.map(c=>({Base:c[1],Timestamp:c[0]}))}else i=await r.infer(`subject_class("${n}", C), instance(C, Base), triple("${t}", Predicate, Base).`)}catch(o){console.log("Query failed",o)}else i=await r.infer(`subject_class("${n}", C), instance(C, Base), triple("${t}", Predicate, Base).`);return i?await Promise.all(i.map(async o=>await new this(r,o.Base).get())):[]}};Be=new WeakMap,gt=new WeakMap,La=new WeakMap,ye=new WeakMap;var ro="0.10.0-prerelease-fix-1";function W1(){let r=new AbortController;return setTimeout(()=>r.abort(),20),r}function cc(r,e=1e4){return ue(this,null,function*(){return Promise.race([new Promise((t,n)=>{r.includes("localhost")||t(new WebSocket(r));let i=new WebSocket(r);i.onopen=()=>{t(i)},i.onerror=a=>{n(a)}}),new Promise((t,n)=>{setTimeout(()=>{n(new Error("WebSocket connection timed out"))},e)})])})}function uc(r){return ue(this,null,function*(){try{let e=yield fetch(`http://localhost:${r}/graphql/`,{signal:W1().signal,mode:"no-cors"});if(e.status===400||e.status===0)return r;throw new Error(`Could not connect to port ${r}`)}catch(e){throw new Error(`Could not connect to port ${r}`)}})}function K1(){return new Promise((r,e)=>{let t=document.querySelector("ad4m-connect"),n=t==null?void 0:t.getAd4mClient();n?r(n):e("No Ad4mClient found")})}function lc(){try{localStorage.setItem("test",""),localStorage.removeItem("test")}catch(r){return!1}return!0}function Op(r,e){lc()&&localStorage.setItem(`${ro}/${r}`,e)}function Wr(r){return lc()?localStorage.getItem(`${ro}/${r}`):null}function Tp(r){lc()&&localStorage.removeItem(`${ro}/${r}`)}var z1=r=>{let e=new Set;do for(let t of Reflect.ownKeys(r))e.add([r,t]);while((r=Reflect.getPrototypeOf(r))&&r!==Object.prototype);return e};function Ti(r,{include:e,exclude:t}={}){let n=i=>{let a=o=>typeof o=="string"?i===o:o.test(i);return e?e.some(a):t?!t.some(a):!0};for(let[i,a]of z1(r.constructor.prototype)){if(a==="constructor"||!n(a))continue;let o=Reflect.getOwnPropertyDescriptor(i,a);o&&typeof o.value=="function"&&(r[a]=r[a].bind(r))}return r}var Ii=class{constructor({appName:e,appDesc:t,appIconPath:n,appUrl:i,appDomain:a,capabilities:o,port:s,token:c,url:u}){this.activeSocket=null;this.requestedRestart=!1;this.authState="unauthenticated";this.connectionState="not_connected";this.port=12e3;this.capabilities=[];this.listeners={authstatechange:[],configstatechange:[],connectionstatechange:[]};Ti(this);this.appName=e,this.appDesc=t,this.appDomain=a,this.appUrl=i,this.appIconPath=n,this.capabilities=o,this.port=s||this.port,this.url=u||`ws://localhost:${this.port}/graphql`,this.token=c||this.token,this.buildClient()}notifyConfigChange(e,t){this.listeners.configstatechange.forEach(n=>{n(e,t)})}notifyConnectionChange(e){this.connectionState!==e&&(this.connectionState=e,this.listeners.connectionstatechange.forEach(t=>{t(e)}))}notifyAuthChange(e){this.authState!==e&&(this.authState=e,this.listeners.authstatechange.forEach(t=>{t(e)}))}setPort(e){this.port!==e&&(this.port=e,this.setUrl(`ws://localhost:${this.port}/graphql`),this.notifyConfigChange("port",e))}setUrl(e){this.url!==e&&(this.url=e,this.notifyConfigChange("url",e))}setToken(e){this.token!==e&&(this.token=e,this.notifyConfigChange("token",e))}on(e,t){this.listeners[e].push(t)}connect(e){return ue(this,null,function*(){try{if(e){yield cc(e,1e4),this.setUrl(e);let t=this.buildClient();return yield this.checkAuth(),t}else{let t=yield this.ensureConnection();return yield this.checkAuth(),t}}catch(t){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}loginToHosting(e,t){return ue(this,null,function*(){try{let n=yield fetch("https://hosting.ad4m.dev/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:t})});if(n.status===200){let i=yield n.json();localStorage.setItem("hosting_token",i.token);let a=localStorage.getItem("hosting_token"),o=yield fetch("https://hosting.ad4m.dev/api/service/info",{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+a}});if(o.status===200){let s=yield o.json();s.serviceId&&(this.setPort(s.port),this.setUrl(`wss://${s.port}.hosting.ad4m.dev/graphql`),this.connect())}}else if((yield n.json()).message==="Passwords did not match")throw new Error("Passwords did not match")}catch(n){throw console.log(n),new Error(`Error logging in ${n}`)}})}checkEmail(e){return ue(this,null,function*(){try{return(yield fetch(`https://hosting.ad4m.dev/api/auth/check-email?email=${e}`,{method:"GET",headers:{"Content-Type":"application/json"}})).status===200}catch(t){console.log(t)}})}connectToPort(e){return ue(this,null,function*(){try{if(e){let t=yield uc(e);this.setPort(t)}else{let t=yield this.findPort();this.setPort(t)}return this.buildClient()}catch(t){this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")}})}ensureConnection(){return ue(this,null,function*(){var t,n;if(((t=this.activeSocket)==null?void 0:t.readyState)===WebSocket.OPEN&&((n=this.activeSocket)==null?void 0:n.url)===this.url&&this.ad4mClient)return this.ad4mClient;try{return yield cc(this.url,1e4),this.buildClient()}catch(i){return this.connectToPort()}})}findPort(){return ue(this,null,function*(){let e=[...Array(10).keys()].map((i,a)=>uc(12e3+a)),n=(yield Promise.allSettled(e)).find(i=>i.status==="fulfilled");if(n)return n.value;throw Error("Couldn't find an open port")})}buildClient(){this.notifyConnectionChange("connecting");try{new WebSocket(this.url)}catch(e){this.notifyConnectionChange("not_connected")}return this.apolloClient&&this.wsClient&&(this.requestedRestart=!0,this.wsClient.dispose(),this.apolloClient.stop()),this.wsClient=jl({url:this.url,connectionParams:()=>ue(this,null,function*(){return{headers:{authorization:this.token}}}),on:{connecting:()=>{this.requestedRestart||this.notifyConnectionChange("connecting")},opened:e=>{this.activeSocket=e},error:e=>{this.notifyConnectionChange("not_connected"),this.notifyAuthChange("unauthenticated")},connected:()=>{this.notifyConnectionChange("connected")},closed:()=>ue(this,null,function*(){if(!this.requestedRestart)if(!this.url)console.log("meow 3"),this.notifyConnectionChange(this.token?"disconnected":"not_connected"),this.notifyAuthChange("unauthenticated"),this.requestedRestart=!1;else{let e=yield this.connect();e?this.ad4mClient=e:(this.notifyConnectionChange(this.token?"disconnected":"not_connected"),this.notifyAuthChange("unauthenticated"),this.requestedRestart=!1)}})}}),this.apolloClient=new Ds({link:new Ul(this.wsClient),cache:new fa({resultCaching:!1,addTypename:!1}),defaultOptions:{watchQuery:{fetchPolicy:"no-cache"},query:{fetchPolicy:"no-cache"},mutate:{fetchPolicy:"no-cache"}}}),this.ad4mClient=new Ka(this.apolloClient),this.ad4mClient}checkAuth(){return ue(this,null,function*(){try{return(yield this.ad4mClient.agent.isLocked())?this.notifyAuthChange("locked"):(yield this.ad4mClient.agent.status(),this.notifyAuthChange("authenticated")),!0}catch(e){return e.message==="Socket closed with event 4500 Cannot extractByTags from a ciphered wallet. You must unlock first."?(this.notifyAuthChange("locked"),!0):(this.notifyAuthChange("unauthenticated"),!1)}})}requestCapability(e=!1){return ue(this,null,function*(){var t;return e&&this.setToken(null),this.requestId=yield(t=this.ad4mClient)==null?void 0:t.agent.requestCapability({appName:this.appName,appDesc:this.appDesc,appUrl:this.appUrl,appIconPath:this.appIconPath,appDomain:this.appDomain,capabilities:this.capabilities}),this.requestId})}verifyCode(e){return ue(this,null,function*(){var n;let t=yield(n=this.ad4mClient)==null?void 0:n.agent.generateJwt(this.requestId,e);return this.setToken(t),yield this.buildClient(),yield this.checkAuth(),this.token})}};function pc(){return q`
|
|
1094
1094
|
<div>
|
|
1095
1095
|
<div class="lds-ring">
|
|
1096
1096
|
<div></div>
|
|
@@ -1836,7 +1836,7 @@ type TriggeredNotification {
|
|
|
1836
1836
|
width: 100vw;
|
|
1837
1837
|
object-fit: cover;
|
|
1838
1838
|
}
|
|
1839
|
-
`,le=class extends qt{constructor(){super(...arguments);this._code=null;this._isMobile=null;this._hasClickedDownload=null;this._isRemote=!1;this._isOpen=!1;this._hostingStep=0;this._email="";this._passowrd="";this._passwordError=null;this._isHostingLoading=!1;this.uiState="start";this.appName=null;this.appDesc=null;this.appDomain=null;this.appIconPath=null;this.capabilities=[];this.hosting=!1;this.token=Wr("ad4mToken")||"";this.port=parseInt(Wr("ad4mport"))||12e3;this.url=Wr("ad4murl")||""}get authState(){return this._client.authState}get connectionState(){return this._client.connectionState}connectedCallback(){super.connectedCallback(),Ti(this),this._isMobile=H1(),this._client=new Ii({appName:this.appName,appDesc:this.appDesc,appDomain:this.appDomain,appUrl:window.location.origin,appIconPath:this.appIconPath,capabilities:Array.isArray(this.capabilities)?this.capabilities:JSON.parse(this.capabilities),port:this.port||parseInt(Wr("ad4mport"))||12e3,token:this.token||Wr("ad4mtoken"),url:this.url||Wr("ad4murl")}),this._client.on("configstatechange",this.handleConfigChange),this._client.on("authstatechange",this.handleAuthChange),this._client.on("connectionstatechange",this.handleConnectionChange),this.loadFont()}checkEmail(){return ue(this,null,function*(){try{(yield this._client.checkEmail(this._email))?this._hostingStep=1:this._hostingStep=2}catch(t){console.log(t)}})}loginToHosting(){return ue(this,null,function*(){try{yield this._client.loginToHosting(this._email,this._passowrd),this.changeUIState("connected")}catch(t){this._passwordError="Passwords did not match"}})}changeEmail(t){this._email=t}changePassword(t){this._passowrd=t}unlockAgent(t,n=!0){return ue(this,null,function*(){yield this._client.ad4mClient.agent.unlock(t,n)})}verifyCode(t){this._client.verifyCode(t)}changeUrl(t){this._client.setUrl(t)}changePort(t){this._client.setPort(t)}changeUIState(t){this.uiState=t}changeIsRemote(t){this._isRemote=t}changeCode(t){this._code=t}onDownloaded(){this._hasClickedDownload=!0}handleAuthChange(t){let n=new CustomEvent("authstatechange",{detail:t});t==="locked"&&(this._isOpen=!0),this.dispatchEvent(n),this.requestUpdate()}handleConfigChange(t,n){this[t]=n,n?Op("ad4m"+t,n):Tp("ad4m"+t),this.requestUpdate()}handleConnectionChange(t){t==="connected"&&this.changeUIState("requestcap"),t==="disconnected"&&(this._isOpen=!0),t==="not_connected"&&this.changeUIState("start");let n=new CustomEvent("connectionstatechange",{detail:t});this.dispatchEvent(n),this.requestUpdate()}loadFont(){let t=document.createElement("link");t.rel="stylesheet",t.type="text/css",t.crossOrigin="anonymous",t.href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap",document.head.appendChild(t)}startCamera(t){return ue(this,null,function*(){try{window.BarcodeDetector.getSupportedFormats()}catch(n){window.BarcodeDetector=Bt}yield this.changeUIState("qr"),setTimeout(()=>ue(this,null,function*(){let n=this.shadowRoot.querySelector("video");if(!n)return;let i=yield navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:"environment"}});n.srcObject=i,n.autoplay=!0}),100)})}connect(){return ue(this,null,function*(){return this._isOpen=!0,this.requestUpdate(),yield this._client.connect()})}getAd4mClient(){return this._client.ad4mClient}connectRemote(t){return ue(this,null,function*(){try{let n=yield this._client.connect(t);return this.changeUIState("requestcap"),n}catch(n){n.message==="Socket closed with event 4500 Invalid Compact JWS"&&this.changeUIState("requestcap")}})}requestCapability(t){return ue(this,null,function*(){try{yield this._client.requestCapability(t),this.changeUIState("verifycode")}catch(n){console.warn(n)}})}isAuthenticated(){return ue(this,null,function*(){return this._client.checkAuth()})}setOpen(t){this._isOpen=t}setHostingStep(t){this._hostingStep=t}renderViews(){if(this.connectionState==="connecting")return pc();if(this.uiState==="hosting")return wc({email:this._email,password:this._passowrd,changeEmail:this.changeEmail,changePassword:this.changePassword,changeState:this.changeUIState,step:this._hostingStep,setHostingStep:this.setHostingStep,login:this.loginToHosting,checkEmail:this.checkEmail,passwordError:this._passwordError});if(this.uiState==="qr")return Cc({changeState:this.changeUIState,onSuccess:t=>{this.changeUrl(t),this._client.connect(t)},uiState:this.uiState});if(this.authState==="locked")return mc({unlockAgent:this.unlockAgent,reconnect:this.connect});if(this.uiState==="settings")return fc({port:this.port,changePort:this.changePort,isRemote:this._isRemote,changeIsRemote:this.changeIsRemote,url:this.url,changeState:this.changeUIState,changeUrl:this.changeUrl,connectToPort:this._client.connectToPort,connectRemote:this.connectRemote});if(this.connectionState==="not_connected")return dc({scanQrcode:this.startCamera,connect:this.connect,isMobile:this._isMobile,hasClickedDownload:this._hasClickedDownload,onDownloaded:this.onDownloaded,changeState:this.changeUIState,hosting:this.hosting});if(this.connectionState==="connected")return this.uiState==="verifycode"?vc({code:this._code,changeCode:this.changeCode,changeState:this.changeUIState,verifyCode:this.verifyCode}):yc({changeState:this.changeUIState,requestCapability:this.requestCapability,capabilities:this.capabilities,appname:this.appName,setOpen:this.setOpen,appiconpath:this.appIconPath});if(this.connectionState==="disconnected")return hc({reconnect:this.connect});if(this.connectionState==="port_not_found")return bc()}render(){return this._isOpen===!1||this.authState==="authenticated"?null:q`
|
|
1839
|
+
`,le=class extends qt{constructor(){super(...arguments);this._code=null;this._isMobile=null;this._hasClickedDownload=null;this._isRemote=!1;this._isOpen=!1;this._hostingStep=0;this._email="";this._passowrd="";this._passwordError=null;this._isHostingLoading=!1;this.uiState="start";this.appName=null;this.appDesc=null;this.appDomain=null;this.appIconPath=null;this.capabilities=[];this.hosting=!1;this.token=Wr("ad4mToken")||"";this.port=parseInt(Wr("ad4mport"))||12e3;this.url=Wr("ad4murl")||""}get authState(){return this._client.authState}get connectionState(){return this._client.connectionState}connectedCallback(){super.connectedCallback(),Ti(this),this._isMobile=H1(),this._client=new Ii({appName:this.appName,appDesc:this.appDesc,appDomain:this.appDomain,appUrl:window.location.origin,appIconPath:this.appIconPath,capabilities:Array.isArray(this.capabilities)?this.capabilities:JSON.parse(this.capabilities),port:this.port||parseInt(Wr("ad4mport"))||12e3,token:this.token||Wr("ad4mtoken"),url:this.url||Wr("ad4murl")}),this._client.on("configstatechange",this.handleConfigChange),this._client.on("authstatechange",this.handleAuthChange),this._client.on("connectionstatechange",this.handleConnectionChange),this.loadFont()}checkEmail(){return ue(this,null,function*(){try{(yield this._client.checkEmail(this._email))?this._hostingStep=1:this._hostingStep=2}catch(t){console.log(t)}})}loginToHosting(){return ue(this,null,function*(){try{yield this._client.loginToHosting(this._email,this._passowrd),this.changeUIState("connected")}catch(t){this._passwordError="Passwords did not match"}})}changeEmail(t){this._email=t}changePassword(t){this._passowrd=t}unlockAgent(t,n=!0){return ue(this,null,function*(){yield this._client.ad4mClient.agent.unlock(t,n)})}verifyCode(t){this._client.verifyCode(t)}changeUrl(t){this._client.setUrl(t)}changePort(t){this._client.setPort(t)}changeUIState(t){this.uiState=t}changeIsRemote(t){this._isRemote=t}changeCode(t){this._code=t}onDownloaded(){this._hasClickedDownload=!0}handleAuthChange(t){let n=new CustomEvent("authstatechange",{detail:t});t==="locked"&&(this._isOpen=!0),this.dispatchEvent(n),this.requestUpdate()}handleConfigChange(t,n){this[t]=n,n?Op("ad4m"+t,n):Tp("ad4m"+t),this.requestUpdate()}handleConnectionChange(t){console.log(t),t==="connected"&&this.changeUIState("requestcap"),t==="disconnected"&&(this._isOpen=!0),t==="not_connected"&&this.changeUIState("start");let n=new CustomEvent("connectionstatechange",{detail:t});this.dispatchEvent(n),this.requestUpdate()}loadFont(){let t=document.createElement("link");t.rel="stylesheet",t.type="text/css",t.crossOrigin="anonymous",t.href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap",document.head.appendChild(t)}startCamera(t){return ue(this,null,function*(){try{window.BarcodeDetector.getSupportedFormats()}catch(n){window.BarcodeDetector=Bt}yield this.changeUIState("qr"),setTimeout(()=>ue(this,null,function*(){let n=this.shadowRoot.querySelector("video");if(!n)return;let i=yield navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:"environment"}});n.srcObject=i,n.autoplay=!0}),100)})}connect(){return ue(this,null,function*(){return this._isOpen=!0,this.requestUpdate(),yield this._client.connect()})}getAd4mClient(){return this._client.ad4mClient}connectRemote(t){return ue(this,null,function*(){try{let n=yield this._client.connect(t);return this.changeUIState("requestcap"),n}catch(n){n.message==="Socket closed with event 4500 Invalid Compact JWS"&&this.changeUIState("requestcap")}})}requestCapability(t){return ue(this,null,function*(){try{yield this._client.requestCapability(t),this.changeUIState("verifycode")}catch(n){console.warn(n)}})}isAuthenticated(){return ue(this,null,function*(){return this._client.checkAuth()})}setOpen(t){this._isOpen=t}setHostingStep(t){this._hostingStep=t}renderViews(){if(this.connectionState==="connecting")return pc();if(this.uiState==="hosting")return wc({email:this._email,password:this._passowrd,changeEmail:this.changeEmail,changePassword:this.changePassword,changeState:this.changeUIState,step:this._hostingStep,setHostingStep:this.setHostingStep,login:this.loginToHosting,checkEmail:this.checkEmail,passwordError:this._passwordError});if(this.uiState==="qr")return Cc({changeState:this.changeUIState,onSuccess:t=>{this.changeUrl(t),this._client.connect(t)},uiState:this.uiState});if(this.authState==="locked")return mc({unlockAgent:this.unlockAgent,reconnect:this.connect});if(this.uiState==="settings")return fc({port:this.port,changePort:this.changePort,isRemote:this._isRemote,changeIsRemote:this.changeIsRemote,url:this.url,changeState:this.changeUIState,changeUrl:this.changeUrl,connectToPort:this._client.connectToPort,connectRemote:this.connectRemote});if(this.connectionState==="not_connected")return dc({scanQrcode:this.startCamera,connect:this.connect,isMobile:this._isMobile,hasClickedDownload:this._hasClickedDownload,onDownloaded:this.onDownloaded,changeState:this.changeUIState,hosting:this.hosting});if(this.connectionState==="connected")return this.uiState==="verifycode"?vc({code:this._code,changeCode:this.changeCode,changeState:this.changeUIState,verifyCode:this.verifyCode}):yc({changeState:this.changeUIState,requestCapability:this.requestCapability,capabilities:this.capabilities,appname:this.appName,setOpen:this.setOpen,appiconpath:this.appIconPath});if(this.connectionState==="disconnected")return hc({reconnect:this.connect});if(this.connectionState==="port_not_found")return bc()}render(){return console.log(this.authState,this.connectionState,this.uiState,this._isOpen),this._isOpen===!1||this.authState==="authenticated"?null:q`
|
|
1840
1840
|
<div class="wrapper">
|
|
1841
1841
|
<div class="dialog">
|
|
1842
1842
|
${Sc()}
|
package/package.json
CHANGED
|
@@ -30,17 +30,6 @@
|
|
|
30
30
|
"type": "module"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"release": "np --no-2fa --no-tests --tag=latest",
|
|
35
|
-
"release:beta": "np --no-2fa --no-tests --tag=beta --any-branch",
|
|
36
|
-
"dev": "NODE_ENV=dev && vite dev",
|
|
37
|
-
"serve": "npx serve",
|
|
38
|
-
"build": "pnpm run build:core && pnpm run build:web && pnpm run build:electron && pnpm run build:utils && tsc",
|
|
39
|
-
"build:core": "tsc --project tsconfig.json && node scripts/esbuild.js",
|
|
40
|
-
"build:web": "tsc --project tsconfig.json && node scripts/esbuild_web.js",
|
|
41
|
-
"build:utils": "tsc --project tsconfig.json && node scripts/esbuild_utils.js",
|
|
42
|
-
"build:electron": "tsc --project tsconfig.json && node scripts/esbuild_electron.js"
|
|
43
|
-
},
|
|
44
33
|
"author": {
|
|
45
34
|
"name": "Nicolas Luck",
|
|
46
35
|
"email": "nicolas@coasys.org"
|
|
@@ -66,5 +55,16 @@
|
|
|
66
55
|
"esbuild-plugin-replace": "^1.4.0",
|
|
67
56
|
"lit": "^2.3.1"
|
|
68
57
|
},
|
|
69
|
-
"version": "0.10.0-prerelease"
|
|
70
|
-
|
|
58
|
+
"version": "0.10.0-prerelease-fix-1",
|
|
59
|
+
"scripts": {
|
|
60
|
+
"release": "np --no-2fa --no-tests --tag=latest",
|
|
61
|
+
"release:beta": "np --no-2fa --no-tests --tag=beta --any-branch",
|
|
62
|
+
"dev": "NODE_ENV=dev && vite dev",
|
|
63
|
+
"serve": "npx serve",
|
|
64
|
+
"build": "pnpm run build:core && pnpm run build:web && pnpm run build:electron && pnpm run build:utils && tsc",
|
|
65
|
+
"build:core": "tsc --project tsconfig.json && node scripts/esbuild.js",
|
|
66
|
+
"build:web": "tsc --project tsconfig.json && node scripts/esbuild_web.js",
|
|
67
|
+
"build:utils": "tsc --project tsconfig.json && node scripts/esbuild_utils.js",
|
|
68
|
+
"build:electron": "tsc --project tsconfig.json && node scripts/esbuild_electron.js"
|
|
69
|
+
}
|
|
70
|
+
}
|