@based/client 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  - [Upload files](#upload-files)
8
8
  - [Schema](#schema)
9
9
  - [Analytics](#analytics)
10
- - [Auth Systen](https://github.com/atelier-saulx/based/blob/main/packages/client/docs/auth.md)
10
+ - [Auth System](https://github.com/atelier-saulx/based/blob/main/packages/client/docs/auth.md)
11
11
 
12
12
  ---
13
13
 
@@ -264,14 +264,16 @@ One of the first things a Based user will have to do is set a schema for its dat
264
264
 
265
265
  ```js
266
266
  await client.updateSchema({
267
- types: {
268
- thing: {
269
- fields: {
270
- name: { type: 'string' },
271
- nested: {
272
- type: 'object',
273
- properties: {
274
- something: { type: 'string' },
267
+ schema: {
268
+ types: {
269
+ thing: {
270
+ fields: {
271
+ name: { type: 'string' },
272
+ nested: {
273
+ type: 'object',
274
+ properties: {
275
+ something: { type: 'string' },
276
+ },
275
277
  },
276
278
  },
277
279
  },
package/dist/index.js CHANGED
@@ -12,4 +12,4 @@ Found corrupt data while applying diff to subscription need to re-fetch
12
12
  `),console.warn(Y(o.query,2,!1,"Query").join(`
13
13
  `)+`
14
14
 
15
- `),delete t.cache[e],b(t,[Z.RequestTypes.SendSubscriptionData,e]);else{c.checksum=n;for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial&&(l.onInitial(null,Number(e),Number(u),c.value),delete l.onInitial,l.onData||S(t,e,Number(u))),l.onData&&l.onData(c.value,c.checksum)}}}}};var Me=(t,s)=>{for(let e of s[1]){delete t.cache[e];let r=t.subscriptions[e];if(r){let i={type:"AuthorizationError",name:r.name?`observe "${r.name}"`:"observe",message:"Unauthorized request",payload:r.query,auth:!0},n=w(i);r.authError={token:t.token,error:n};for(let o in r.subscribers){let c=r.subscribers[o];c.onError&&c.onError(n)}}}};var Ne=require("@based/types");var ft=0,y=(t,s,e,r,i,n,o)=>{let c=++ft;t.requestCallbacks[c]={resolve:r,reject:i,type:s,payload:e,name:n,isRetry:o},s===Ne.RequestTypes.Call?b(t,[s,n,c,e]):b(t,[s,c,e])};var He=(t,s)=>{let[,e,r,i]=s,n=t.requestCallbacks[e];n&&(delete t.requestCallbacks[e],i?n.reject(w(i)):n.resolve(r))};var k={};Be(k,{BasedClient:()=>x});var g=require("@based/types");var be=require("@based/types");var bt=t=>typeof t!="undefined"&&t!==null,mt=(t,s,e)=>{if(t.beingAuth=!0,s)t.token=s,t.sendTokenOptions=e;else{for(let r in t.cache)t.subscriptions[r]||delete t.cache[r];delete t.token,delete t.sendTokenOptions}if(t.connected){let r=s?[be.RequestTypes.Token,s,e].filter(bt):[be.RequestTypes.Token];t.connection.ws.send(JSON.stringify(r)),W(t),M(t,!0)}},E=mt;var B=require("@based/types");var me=0,_e=(t,s)=>{let e=++me;return b(t,[B.RequestTypes.Auth,B.AuthRequestTypes.Login,e,s]),new Promise((r,i)=>{t.authCallbacks[e]={resolve:n=>{n.id&&n.token?t.updateUserState(n.id,n.token,n.refreshToken):t.updateUserState(!1),r(n)},reject:i}})},ze=(t,s)=>new Promise((e,r)=>{y(t,B.RequestTypes.Call,s,i=>{i.id&&i.token?t.updateUserState(i.id,i.token,i.refreshToken):t.updateUserState(!1),e(i)},r,"registerUser")}),Je=(t,s)=>{let e=++me;return b(t,[B.RequestTypes.Auth,B.AuthRequestTypes.RenewToken,e,s]),new Promise((r,i)=>{t.authCallbacks[e]={resolve:r,reject:i}})},Ke=(t,s)=>{let[,e,r,i]=s,n=t.authCallbacks[e];n&&(delete t.authCallbacks[e],i?n.reject(w(i)):n.resolve(r))},We=t=>{let s=++me;return b(t,[B.RequestTypes.Auth,B.AuthRequestTypes.Logout,s]),new Promise((e,r)=>{t.authCallbacks[s]={resolve:i=>{t.updateUserState(!1),e(i)},reject:r}})};var Ve=(t,s)=>{let e=new Date,r=e.getHours()+":"+e.getMinutes()+":"+e.getSeconds()+":"+e.getMilliseconds();if(s==="incoming"){let i=`\u25BC ${r} -- `;console.info(i,t)}else{let i=`\u25B2 ${r} -- `;console.info(i,t)}};var he=require("@saulx/hash");p(k,require("@based/types"));var x=class{constructor(s){this.tokenToLocalStorage=!1;this.auth=[];this.subscriptions={};this.cache={};this.requestCallbacks={};this.authCallbacks={};this.connected=!1;this.subscriptionQueue=[];this.queue=[];this.drainInProgress=!1;this.based=s}get debug(){return this.debugInternal}set debug(s){s===!0?this.debugInternal=Ve:this.debugInternal=s}initUserState(){if(typeof window!="undefined"){if(this.based.opts){let s=(0,he.hash)({cluster:this.based.opts.cluster,project:this.based.opts.project,env:this.based.opts.project,org:this.based.opts.org});this.optsId=s}else this.optsId=(0,he.hash)("un-specified-env");try{let s=global.localStorage.getItem("based-"+this.optsId+"-uid");if(s){this.tokenToLocalStorage=!0;try{let[e,r,i]=JSON.parse(s);r&&e&&this.updateUserState(e,r,i)}catch(e){global.localStorage.removeItem("based-"+this.optsId+"-uid")}}}catch(s){}}}updateUserState(s,e,r){if(this.user=s,!this.tokenToLocalStorage&&typeof window!="undefined")try{global.localStorage.removeItem("based-"+this.optsId+"-uid")}catch(i){}if(e)r&&(this.renewOptions={refreshToken:r}),r&&(this.renewOptions=J(G({},this.renewOptions),{refreshToken:r})),E(this,e,{refreshToken:r}),this.auth.push(i=>{if(i){if(typeof window!="undefined")try{this.tokenToLocalStorage&&global.localStorage.setItem("based-"+this.optsId+"-uid",JSON.stringify([s,e,r]))}catch(n){}this.based.emit("auth",e)}else{if(typeof window!="undefined")try{this.tokenToLocalStorage&&global.localStorage.removeItem("based-"+this.optsId+"-uid")}catch(n){}this.based.emit("auth",!1)}});else{if(typeof window!="undefined"){this.user=!1;try{this.tokenToLocalStorage&&global.localStorage.removeItem("based-"+this.optsId+"-uid")}catch(i){}}E(this),this.based.emit("auth",!1)}}onClose(){this.connected=!1,Fe(this),xe(this),De(this),this.based.listeners.disconnect&&this.based.listeners.disconnect.forEach(s=>s())}onReconnect(){if(this.based.listeners.reconnect&&this.based.listeners.reconnect.forEach(s=>s()),this.tracking)for(let s of this.tracking)b(this,[g.RequestTypes.Track,{t:s}])}onOpen(){this.connected=!0,this.based.listeners.connect&&this.based.listeners.connect.forEach(s=>s()),this.token&&E(this,this.token,this.sendTokenOptions),M(this),de(this)}onData(s){var e,r;try{let i=JSON.parse(s.data);this.debugInternal&&this.debugInternal(i,"incoming");let[n,o,c,a,u]=i;if(n===g.RequestTypes.Token){this.retryingRenewToken=!1,o.length&&Me(this,i),!c&&typeof a=="string"&&this.user&&this.renewOptions.refreshToken&&(this.token=a);for(let l of this.auth)l(!c);this.beingAuth=!1,this.auth=[]}else if(n===g.RequestTypes.Auth)Ke(this,i);else if((((e=u||a)==null?void 0:e.code)===g.BasedErrorCodes.TokenExpired||((r=u||a)==null?void 0:r.message)==="Token expired")&&!this.retryingRenewToken){this.retryingRenewToken=!0;let l=this.user;Je(this,this.renewOptions).then(d=>{E(this,d.token,this.sendTokenOptions),n===g.RequestTypes.Subscription||n===g.RequestTypes.SubscriptionDiff?M(this):y(this,n,a==null?void 0:a.payload,this.requestCallbacks[o].resolve,this.requestCallbacks[o].reject),this.based.emit("renewToken",d),d&&this.updateUserState(l,d.token,this.renewOptions.refreshToken)}).catch(d=>{var f;(f=this.requestCallbacks[o])==null||f.reject(d)})}else n===g.RequestTypes.Set||n===g.RequestTypes.Get||n===g.RequestTypes.Configuration||n===g.RequestTypes.GetConfiguration||n===g.RequestTypes.Call||n===g.RequestTypes.Delete||n===g.RequestTypes.Copy||n===g.RequestTypes.Digest||n===g.RequestTypes.RemoveType||n===g.RequestTypes.RemoveField||n===g.RequestTypes.BulkUpdate?He(this,i):n===g.RequestTypes.Subscription?je(this,i):n===g.RequestTypes.SubscriptionDiff&&Le(this,i)}catch(i){console.error("Received incorrect data ",s.data)}}};var ge=(t,s)=>{let e;if(t.configuration&&t.configuration.schema)for(let r in t.configuration.schema){let i=t.configuration.schema[r];if(i.prefixToTypeMapping){for(let n in i.prefixToTypeMapping)if(i.prefixToTypeMapping[n]===s){e=n;break}}}return e};var Te=require("@saulx/hash");var Ye=require("@based/types"),Ze=require("@saulx/hash"),Xe=new Set,ht=t=>{if(typeof window!="undefined"){if(Xe.has(t))return!1;Xe.add(t);try{let s="_ba:"+(0,Ze.hashCompact)(t);return localStorage.getItem(s)?!1:(localStorage.setItem(s,"1"),!0)}catch(s){return!1}}return!1},ye=(t,s)=>{if(s){let e=`${t}`,r=Object.keys(s).sort();for(let i of r)e+="_"+i+"_"+s[i];return e}else return t},N=(t,s,e,r,i,n,o)=>{let c=ye(s,e),a={t:c};o&&(a.r=1),i&&(a.e=1,n&&(a.o=n)),r?(a.s=1,t.tracking.delete(c)):o||(i||(t.tracking||(t.tracking=new Set),t.tracking.add(c)),ht(c)&&(a.u=1)),b(t,[Ye.RequestTypes.Track,a])};var ve=class{constructor(s,e,r){this.closed=!1;this.client=s,this.subId=r,this.subscriberId=e}unsubscribe(){this.closed=!0,S(this.client,this.subId,this.subscriberId)}},Se=class{constructor(s,e){this.closed=!1;this.client=s,this.subs=e}unsubscribe(){if(!this.closed){this.closed=!0;for(let s of this.subs)s.unsubscribe()}}},ee=class{constructor(s,e){this.client=s,this.components=e}subscribe(s,e,r){let i={data:{}},n=[];for(let{key:o,obs:c}of this.components){let a=c.subscribe(u=>{if(o===""){Object.assign(i.data,u),s(i);return}i.data[o]=u,s(i)},e);n.push(a)}return new Se(this.client,n)}},C=class{constructor(s,e,r){this.client=s,this.subId=typeof e=="string"?P(r,e):P(e),this.name=typeof e=="string"?e:null,this.payload=typeof e=="string"?r:e}subscribe(s,e,r){let[,i]=I(this.client,this.payload,s,n=>{n&&(console.error(n),e&&e(n))},e,this.subId,this.name);return new ve(this.client,i,this.subId)}};var ke={},H={},gt=(t,s)=>{ke[t]||(ke[t]=!0,setTimeout(()=>{console.info("Drain file q"),ke[t]=!1;let e=H[t];H[t]=[];let r=new global.FormData;for(let i of e){let{raw:n,name:o,id:c,file:a,functionName:u}=i,l=`${u||""}|${n?1:0}|${c}|${a.size}${o?`|${o}`:""}`;r.append(l,a)}try{let i=new global.XMLHttpRequest;i.upload.onprogress=n=>{let o=100*(n.loaded||n.position)/(n.totalSize||n.total);console.info(o,"upload...")},i.onerror=n=>{console.error("error!",n,"flap",i.responseText)},i.timeout=1e3*60*60*24,i.onabort=n=>{console.error("abort",n)},i.ontimeout=n=>{console.error("on timeout",n)},i.onload=()=>{try{JSON.parse(i.response)}catch(n){console.error("something wrong with file upload",n)}},i.open("POST",t+"/file"),i.setRequestHeader("Content-Type","multipart/form-data"),i.setRequestHeader("Authorization",s),i.send(r)}catch(i){console.error("Something wrong with xhr upload",i)}},500))},et=async(t,s,e,r,i,n,o)=>{H[e]||(H[e]=[]),H[e].push({file:s,id:r,url:e,raw:i,name:n,functionName:o}),gt(e,t.getToken())};var tt=K(require("@based/get-service")),te={},se={},yt=async(t,s)=>{if(s.url)return typeof s.url=="string"?s.url:await s.url();if(!t.opts.env&&t.opts.url)return typeof t.opts.url=="string"?t.opts.url:await t.opts.url();let{env:e,project:r,org:i}=t.opts,n=e+"/"+r+"/"+i+"/"+t.opts.cluster;if(te[n])return te[n];if(se[n])return(await se[n]).url;let o=await(se[n]=(0,tt.default)({env:e,project:r,org:i,name:"@based/hub",key:"file-upload",optionalKey:!0},0,t.opts.cluster));return delete se[n],setTimeout(()=>{delete te[n]},2e3),te[n]=o.url},st=yt;var it=K(require("cross-fetch")),ie=(t,s,e)=>((0,it.default)(s,{method:"POST",cache:"no-cache",headers:{"Content-Type":e.mimeType||"text/plain","File-Id":e.id,"File-Is-Raw":e.raw?"1":"0","File-Name":e.name||"","Function-Name":e.functionName||"",Authorization:t.getToken()},body:e.contents}).then(r=>{}).catch(r=>{console.error("Error while uploading file",r)}),{id:e.id});var A=require("./file/stream"),re=typeof window!="undefined",vt=t=>"src"in t&&typeof t.src=="string",St=t=>"path"in t&&typeof t.path=="string",kt=t=>"contents"in t&&(0,A.isStream)(t.contents),rt=async(t,s)=>{if(vt(s)){let i=s.id?{$id:s.id}:{type:"file"};return s.src?(i.src=s.src,i.origin=s.src,s.size&&(i.size=s.size),s.name&&(i.name=s.name),s.parents&&(i.parents=s.parents),await t.set(i)):void 0}let e=s.id;if(!e){let i={type:"file",progress:0};s.name?i.name=s.name:global.File&&"contents"in s&&s.contents instanceof global.File&&(i.name=s.contents.name),s.parents&&(i.parents=s.parents),e=(await t.set(i)).id}s.id=e;let r=(await st(t,s)).replace(/^ws/,"http");if(St(s))return(0,A.uploadFilePath)(t,r,s),{id:e};if(kt(s))return(0,A.uploadFileStream)(t,r,s),{id:e};if(s.contents instanceof ArrayBuffer)return s.contents=re?new global.Blob([s.contents],{type:s.mimeType||"text/plain"}):global.Buffer.from(s.contents),ie(t,r+"/file",s);if(re&&s.contents instanceof global.Blob)return s.mimeType||(s.mimeType=s.contents.type),ie(t,r+"/file",s);if(typeof s.contents=="string"||!re&&s.contents instanceof global.Buffer)return ie(t,r+"/file",s);if(re&&s.contents instanceof File)return et(t,s.contents,r,s.id,s.raw||!1,s.name,s.functionName),{id:e};throw s.id||await t.delete({$id:e}),new Error(`Invalid contents for file api ${JSON.stringify(s,null,2)}`)};var oe=K(require("@based/get-service")),Oe=require("@saulx/utils"),T=require("@based/graphql");p(m,require("@based/types"),module.exports);var ne=class extends Re{constructor(e){super();this.client=new x(this),Object.defineProperty(this,"client",{enumerable:!1,writable:!0}),e&&e.url&&this.connect(e.url),this.graphql={query:this.gqlQuery.bind(this),live:this.gqlLive.bind(this)}}connect(e){!e&&this._url?this.client.connection||(this.client.connection=le(this.client,this._url)):(this._url=e,this.client.connection=le(this.client,e))}disconnect(){this.client.connection&&(this.client.connection.disconnected=!0,this.client.connection.destroy(),this.client.connection.ws&&this.client.connection.ws.close(),this.client.connected&&this.client.onClose(),delete this.client.connection),this.client.connected=!1}observeUntil(e,r,i){return new Promise((n,o)=>{let c,a=!1;this.observe(e,(u,l)=>{i&&i(u,l),r(u,l)&&(a=!0,c&&c(),n(u))}).then(u=>{a?c():c=u}).catch(u=>{o(u)})})}gql(e,...r){typeof e=="string"&&(e=[e]);let i=e[0];return r.forEach((n,o)=>{n&&n.kind==="Document"?i+=n.loc.source.body:i+=n,i+=e[o+1]}),(0,T.createOperations)({schemas:this.client.configuration.schema},(0,T.parseGraphql)(i))}gqlDb(e="default"){return(r,...i)=>{typeof r=="string"&&(r=[r]);let n=r[0];return i.forEach((o,c)=>{o&&o.kind==="Document"?n+=o.loc.source.body:n+=o,n+=r[c+1]}),(0,T.createOperations)({schemas:this.client.configuration.schema,db:e},(0,T.parseGraphql)(n))}}observe(e,r,i,n){return typeof e=="string"?new Promise((o,c)=>{let a=typeof r=="function",u=a?r:i,l=a?i:n;I(this.client,a?void 0:r,u,(d,f,h,O,R)=>{d&&!R?c(d):o(()=>{S(this.client,f,h)})},l,void 0,e)}):new Promise((o,c)=>{I(this.client,e,r,(a,u,l,d,f)=>{a&&!f?c(a):o(()=>{S(this.client,u,l)})},i)})}createObservable(e,r){return typeof e=="string"?new C(this.client,e,r):new C(this.client,e)}observeSchema(e,r,i){return new Promise((n,o)=>{let c=typeof e=="string"?e:"default",a=typeof e=="string"?r:e,u=typeof e=="string"?i:r;I(this.client,{$subscribe_schema:c},(l,d)=>{this.client.configuration||(this.client.configuration={dbs:[],schema:{},functions:{}}),this.client.configuration.schema[c]=l,a(l,d)},(l,d,f,h,O)=>{l&&!O?o(l):n(()=>{S(this.client,d,f)})},u)})}get(e,r){return typeof e=="string"?new Promise((i,n)=>{V(this.client,r,(o,c,a,u)=>{o?n(o):i(u)},0,e)}):new Promise((i,n)=>{y(this.client,v.RequestTypes.Get,e,i,n)})}file(e){return global.File&&e instanceof File&&(e={contents:e}),rt(this,e)}call(e,r){return new Promise((i,n)=>{y(this.client,v.RequestTypes.Call,r,i,n,e)})}async id(e,r){let i=ge(this.client,e);if(i||(await this.schema(),i=ge(this.client,e)),!i)throw w({message:`Type does not exist ${e}`,type:"Invalid type",payload:r?{type:e,opts:r}:{type:e}});if(r){let n=(0,Te.hashCompact)(r,8,!0);return i+n}else return i+(0,Te.hashCompact)(Math.floor(Math.random()*99999999999)+""+Date.now())}digest(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Digest,e,r,i)})}set(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Set,e,r,i)})}bulkUpdate(e,r){return new Promise((i,n)=>{y(this.client,v.RequestTypes.BulkUpdate,{payload:e,query:r},i,n)})}copy(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Copy,e,r,i)})}async gqlQuery(e,r={}){let i;typeof e=="string"?i=this.gql(e):i=e;try{if(i=(0,T.handleGraphqlVariables)(i,i,r),i.opType==="GET"){let o={$db:i.db},c=[];for(let u in i.ops){if(i.ops[u].fnObserve){let l=await this.get(i.ops[u].fnObserve.name,i.ops[u].fnObserve.payload);c.push({key:u,reply:l});continue}i.ops[u].get&&(o[u]=i.ops[u].get)}let a=await this.get(o);for(let{key:u,reply:l}of c)a[u]=l;return{data:a}}let n={};return await Promise.all(Object.entries(i.ops).map(async([o,c])=>{var d,f,h,O,R;if(c.delete){n[o]=await this.delete(c.delete);return}else if(c.fnCall){n[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set);if(!c.get){let Q={};Q.id=a;let we=(R=(O=(h=(f=(d=this.client)==null?void 0:d.configuration)==null?void 0:f.schema)==null?void 0:h[i.db])==null?void 0:O.prefixToTypeMapping)==null?void 0:R[a.slice(0,2)];we&&(Q.type=we),n[o]=Q;return}let u=(0,Oe.deepCopy)(c.get);u.$id=a;let l=await this.get(u);n[o]=l})),{data:n}}catch(n){return{errors:[{message:n.message,locations:n.locations}]}}}async gqlLive(e,r={}){let i;if(typeof e=="string"?i=this.gql(e):i=e,i=(0,T.handleGraphqlVariables)(i,i,r),i.opType==="GET"){let o=[],c={};for(let a in i.ops){if(i.ops[a].fnObserve){let{name:u,payload:l}=i.ops[a].fnObserve;o.push({key:a,fn:{name:u,payload:l}});continue}c[a]=i.ops[a].get}if(o!=null&&o.length){let a=o.map(l=>({obs:new C(this.client,l.fn.name,l.fn.payload),key:l.key})),u=new C(this.client,G({$db:i.db},c));return a.push({key:"",obs:u}),new ee(this.client,a)}return new C(this.client,{$db:i.db,data:c})}let n={};return await Promise.all(Object.entries(i.ops).map(async([o,c])=>{if(c.delete){n[o]=await this.delete(c.delete);return}else if(c.fnCall){n[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set),u=(0,Oe.deepCopy)(c.get);u.$id=a,n[o]=u})),new C(this.client,{$db:i.db,data:n})}analytics(e,r){return new Promise((i,n)=>{r?I(this.client,e,r,(o,c,a,u,l)=>{o&&!l?n(o):i(()=>{S(this.client,c,a)})},o=>console.error(o),void 0,"analytics"):V(this.client,e,(o,c,a,u)=>{o?n(o):((0,v.isAnalyticsHistoryOpts)(e)||(0,v.isAnalyticsTypesOpts)(e),i(u))},0,"analytics")})}track(e,r){N(this.client,e,r)}clearAnalytics(e,r){N(this.client,e,r,!1,!1,void 0,!0)}untrack(e,r){N(this.client,e,r,!0)}event(e,r,i){N(this.client,e,r,!1,!0,i)}delete(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Delete,e,r,i)})}schema(){return new Promise((e,r)=>{let i=n=>{this.client.configuration=n,e(n)};y(this.client,v.RequestTypes.GetConfiguration,0,i,r)})}removeType(e,r="default"){return new Promise((i,n)=>{y(this.client,v.RequestTypes.RemoveType,{type:e,db:r},i,n)})}removeField(e,r,i="default"){return new Promise((n,o)=>{!r||r.length===0?o(new Error("Path cannot be empty")):(Array.isArray(r)||(r=[r]),y(this.client,v.RequestTypes.RemoveField,{type:e,db:i,path:r},n,o))})}updateSchema(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Configuration,e,r,i)})}getToken(){return this.client.token}auth(e,r){return new Promise(i=>{if(e&&e===this.client.token)this.client.beingAuth?this.client.auth.push(o=>{i(o?e:!1)}):i(e);else if(this.client.auth.push(i),e&&e!==this.client.token||e===!1&&this.client.token)if(typeof e=="string"&&(r==null?void 0:r.id)&&r.refreshToken)r.localStorage===!1?this.client.tokenToLocalStorage=!1:this.client.tokenToLocalStorage=!0,this.client.updateUserState(r.id,e,r.refreshToken);else{if(typeof e=="string"){let n=r||{},{renewOptions:o,refreshToken:c}=n,a=qe(n,["renewOptions","refreshToken"]);o&&(this.client.renewOptions=o),c&&(this.client.renewOptions=J(G({},this.client.renewOptions),{refreshToken:c})),E(this.client,e,a)}else E(this.client);this.emit("auth",e)}})}async login(e){return e.localStorage===!1?this.client.tokenToLocalStorage=!1:this.client.tokenToLocalStorage=!0,_e(this.client,e)}async register(e){return e.localStorage===!1?this.client.tokenToLocalStorage=!1:this.client.tokenToLocalStorage=!0,ze(this.client,e)}logout(){return We(this.client)}observeAuth(e){return new Promise(r=>{this.client.user&&this.client.token?e({id:this.client.user,token:this.client.token}):e(!1);let i=n=>{n&&this.client.user&&this.client.token?e({id:this.client.user,token:this.client.token}):e(!1)};this.on("auth",i),r(()=>{this.removeListener("auth",i)})})}},Tt=(t,s)=>{if(s){let e;t+=/\?/.test(t)?"&":"?";for(let r in s){let i=s[r];t+=e?`&${r}=${i}`:`${r}=${i}`,e=!0}}return t},Ot=(t,s=ne)=>{let{env:e,project:r,org:i,url:n,key:o,name:c="@based/hub",cluster:a,params:u}=t;if(n||(a=t.cluster=(0,oe.getClusterUrl)(a),n=async()=>{let{url:l}=await(0,oe.default)({env:e,project:r,org:i,key:o,name:c},0,a);return Tt(l,u)}),n){let l=new s;return l.opts=t,l.client.initUserState(),l.connect(n),l}},wt=Ot;0&&(module.exports={Based,BasedClient,BasedGraphQL,Observable,addGetSubscriber,addRequest,addSubscriber,createGraphqlOperations,generateSubscriptionId,generateTrackingKey,handleGraphqlVariables,parseGraphql,removeSubscriber});
15
+ `),delete t.cache[e],b(t,[Z.RequestTypes.SendSubscriptionData,e]);else{c.checksum=n;for(let u in o.subscribers){let l=o.subscribers[u];l.onInitial&&(l.onInitial(null,Number(e),Number(u),c.value),delete l.onInitial,l.onData||S(t,e,Number(u))),l.onData&&l.onData(c.value,c.checksum)}}}}};var Me=(t,s)=>{for(let e of s[1]){delete t.cache[e];let r=t.subscriptions[e];if(r){let i={type:"AuthorizationError",name:r.name?`observe "${r.name}"`:"observe",message:"Unauthorized request",payload:r.query,auth:!0},n=w(i);r.authError={token:t.token,error:n};for(let o in r.subscribers){let c=r.subscribers[o];c.onError&&c.onError(n)}}}};var Ne=require("@based/types");var ft=0,y=(t,s,e,r,i,n,o)=>{let c=++ft;t.requestCallbacks[c]={resolve:r,reject:i,type:s,payload:e,name:n,isRetry:o},s===Ne.RequestTypes.Call?b(t,[s,n,c,e]):b(t,[s,c,e])};var He=(t,s)=>{let[,e,r,i]=s,n=t.requestCallbacks[e];n&&(delete t.requestCallbacks[e],i?n.reject(w(i)):n.resolve(r))};var k={};Be(k,{BasedClient:()=>x});var g=require("@based/types");var be=require("@based/types");var bt=t=>typeof t!="undefined"&&t!==null,mt=(t,s,e)=>{if(t.beingAuth=!0,s)t.token=s,t.sendTokenOptions=e;else{for(let r in t.cache)t.subscriptions[r]||delete t.cache[r];delete t.token,delete t.sendTokenOptions}if(t.connected){let r=s?[be.RequestTypes.Token,s,e].filter(bt):[be.RequestTypes.Token];t.connection.ws.send(JSON.stringify(r)),W(t),M(t,!0)}},E=mt;var B=require("@based/types");var me=0,_e=(t,s)=>{let e=++me;return b(t,[B.RequestTypes.Auth,B.AuthRequestTypes.Login,e,s]),new Promise((r,i)=>{t.authCallbacks[e]={resolve:n=>{n.id&&n.token?t.updateUserState(n.id,n.token,n.refreshToken):t.updateUserState(!1),r(n)},reject:i}})},ze=(t,s)=>new Promise((e,r)=>{y(t,B.RequestTypes.Call,s,i=>{i.id&&i.token?t.updateUserState(i.id,i.token,i.refreshToken):t.updateUserState(!1),e(i)},r,"registerUser")}),Je=(t,s)=>{let e=++me;return b(t,[B.RequestTypes.Auth,B.AuthRequestTypes.RenewToken,e,s]),new Promise((r,i)=>{t.authCallbacks[e]={resolve:r,reject:i}})},Ke=(t,s)=>{let[,e,r,i]=s,n=t.authCallbacks[e];n&&(delete t.authCallbacks[e],i?n.reject(w(i)):n.resolve(r))},We=t=>{let s=++me;return b(t,[B.RequestTypes.Auth,B.AuthRequestTypes.Logout,s]),new Promise((e,r)=>{t.authCallbacks[s]={resolve:i=>{t.updateUserState(!1),e(i)},reject:r}})};var Ve=(t,s)=>{let e=new Date,r=e.getHours()+":"+e.getMinutes()+":"+e.getSeconds()+":"+e.getMilliseconds();if(s==="incoming"){let i=`\u25BC ${r} -- `;console.info(i,t)}else{let i=`\u25B2 ${r} -- `;console.info(i,t)}};var he=require("@saulx/hash");p(k,require("@based/types"));var x=class{constructor(s){this.tokenToLocalStorage=!1;this.auth=[];this.subscriptions={};this.cache={};this.requestCallbacks={};this.authCallbacks={};this.connected=!1;this.subscriptionQueue=[];this.queue=[];this.drainInProgress=!1;this.based=s}get debug(){return this.debugInternal}set debug(s){s===!0?this.debugInternal=Ve:this.debugInternal=s}initUserState(){if(typeof window!="undefined"){if(this.based.opts){let s=(0,he.hash)({cluster:this.based.opts.cluster,project:this.based.opts.project,env:this.based.opts.project,org:this.based.opts.org});this.optsId=s}else this.optsId=(0,he.hash)("un-specified-env");try{let s=global.localStorage.getItem("based-"+this.optsId+"-uid");if(s){this.tokenToLocalStorage=!0;try{let[e,r,i]=JSON.parse(s);r&&e&&this.updateUserState(e,r,i)}catch(e){global.localStorage.removeItem("based-"+this.optsId+"-uid")}}}catch(s){}}}updateUserState(s,e,r){if(this.user=s,!this.tokenToLocalStorage&&typeof window!="undefined")try{global.localStorage.removeItem("based-"+this.optsId+"-uid")}catch(i){}if(e)r&&(this.renewOptions={refreshToken:r}),r&&(this.renewOptions=J(G({},this.renewOptions),{refreshToken:r})),E(this,e,{refreshToken:r}),this.auth.push(i=>{if(i){if(typeof window!="undefined")try{this.tokenToLocalStorage&&global.localStorage.setItem("based-"+this.optsId+"-uid",JSON.stringify([s,e,r]))}catch(n){}this.based.emit("auth",e)}else{if(typeof window!="undefined")try{this.tokenToLocalStorage&&global.localStorage.removeItem("based-"+this.optsId+"-uid")}catch(n){}this.based.emit("auth",!1)}});else{if(typeof window!="undefined"){this.user=!1;try{this.tokenToLocalStorage&&global.localStorage.removeItem("based-"+this.optsId+"-uid")}catch(i){}}E(this),this.based.emit("auth",!1)}}onClose(){this.connected=!1,Fe(this),xe(this),De(this),this.based.listeners.disconnect&&this.based.listeners.disconnect.forEach(s=>s())}onReconnect(){if(this.based.listeners.reconnect&&this.based.listeners.reconnect.forEach(s=>s()),this.tracking)for(let s of this.tracking)b(this,[g.RequestTypes.Track,{t:s}])}onOpen(){this.connected=!0,this.based.listeners.connect&&this.based.listeners.connect.forEach(s=>s()),this.token&&E(this,this.token,this.sendTokenOptions),M(this),de(this)}onData(s){var e,r;try{let i=JSON.parse(s.data);this.debugInternal&&this.debugInternal(i,"incoming");let[n,o,c,a,u]=i;if(n===g.RequestTypes.Token){this.retryingRenewToken=!1,o.length&&Me(this,i),!c&&typeof a=="string"&&this.user&&this.renewOptions.refreshToken&&(this.token=a);for(let l of this.auth)l(!c);this.beingAuth=!1,this.auth=[]}else if(n===g.RequestTypes.Auth)Ke(this,i);else if((((e=u||a)==null?void 0:e.code)===g.BasedErrorCodes.TokenExpired||((r=u||a)==null?void 0:r.message)==="Token expired")&&!this.retryingRenewToken){this.retryingRenewToken=!0;let l=this.user;Je(this,this.renewOptions).then(d=>{E(this,d.token,this.sendTokenOptions),n===g.RequestTypes.Subscription||n===g.RequestTypes.SubscriptionDiff?M(this):y(this,n,a==null?void 0:a.payload,this.requestCallbacks[o].resolve,this.requestCallbacks[o].reject),this.based.emit("renewToken",d),d&&this.updateUserState(l,d.token,this.renewOptions.refreshToken)}).catch(d=>{var f;(f=this.requestCallbacks[o])==null||f.reject(d)})}else n===g.RequestTypes.Set||n===g.RequestTypes.Get||n===g.RequestTypes.Configuration||n===g.RequestTypes.GetConfiguration||n===g.RequestTypes.Call||n===g.RequestTypes.Delete||n===g.RequestTypes.Copy||n===g.RequestTypes.Digest||n===g.RequestTypes.RemoveType||n===g.RequestTypes.RemoveField||n===g.RequestTypes.BulkUpdate?He(this,i):n===g.RequestTypes.Subscription?je(this,i):n===g.RequestTypes.SubscriptionDiff&&Le(this,i)}catch(i){console.error("Received incorrect data ",s.data)}}};var ge=(t,s)=>{let e;if(t.configuration&&t.configuration.schema)for(let r in t.configuration.schema){let i=t.configuration.schema[r];if(i.prefixToTypeMapping){for(let n in i.prefixToTypeMapping)if(i.prefixToTypeMapping[n]===s){e=n;break}}}return e};var Te=require("@saulx/hash");var Ye=require("@based/types"),Ze=require("@saulx/hash"),Xe=new Set,ht=t=>{if(typeof window!="undefined"){if(Xe.has(t))return!1;Xe.add(t);try{let s="_ba:"+(0,Ze.hashCompact)(t);return localStorage.getItem(s)?!1:(localStorage.setItem(s,"1"),!0)}catch(s){return!1}}return!1},ye=(t,s)=>{if(s){let e=`${t}`,r=Object.keys(s).sort();for(let i of r)e+="_"+i+"_"+s[i];return e}else return t},N=(t,s,e,r,i,n,o)=>{let c=ye(s,e),a={t:c};o&&(a.r=1),i&&(a.e=1,n&&(a.o=n)),r?(a.s=1,t.tracking.delete(c)):o||(i||(t.tracking||(t.tracking=new Set),t.tracking.add(c)),ht(c)&&(a.u=1)),b(t,[Ye.RequestTypes.Track,a])};var ve=class{constructor(s,e,r){this.closed=!1;this.client=s,this.subId=r,this.subscriberId=e}unsubscribe(){this.closed=!0,S(this.client,this.subId,this.subscriberId)}},Se=class{constructor(s,e){this.closed=!1;this.client=s,this.subs=e}unsubscribe(){if(!this.closed){this.closed=!0;for(let s of this.subs)s.unsubscribe()}}},ee=class{constructor(s,e){this.client=s,this.components=e}subscribe(s,e,r){let i={data:{}},n=[];for(let{key:o,obs:c}of this.components){let a=c.subscribe(u=>{if(o===""){Object.assign(i.data,u),s(i);return}i.data[o]=u,s(i)},e);n.push(a)}return new Se(this.client,n)}},C=class{constructor(s,e,r){this.client=s,this.subId=typeof e=="string"?P(r,e):P(e),this.name=typeof e=="string"?e:null,this.payload=typeof e=="string"?r:e}subscribe(s,e,r){let[,i]=I(this.client,this.payload,s,n=>{n&&(console.error(n),e&&e(n))},e,this.subId,this.name);return new ve(this.client,i,this.subId)}};var ke={},H={},gt=(t,s)=>{ke[t]||(ke[t]=!0,setTimeout(()=>{console.info("Drain file q"),ke[t]=!1;let e=H[t];H[t]=[];let r=new global.FormData;for(let i of e){let{raw:n,name:o,id:c,file:a,functionName:u}=i,l=`${u||""}|${n?1:0}|${c}|${a.size}${o?`|${o}`:""}`;r.append(l,a)}try{let i=new global.XMLHttpRequest;i.upload.onprogress=n=>{let o=100*(n.loaded||n.position)/(n.totalSize||n.total);console.info(o,"upload...")},i.onerror=n=>{console.error("error!",n,"flap",i.responseText)},i.timeout=1e3*60*60*24,i.onabort=n=>{console.error("abort",n)},i.ontimeout=n=>{console.error("on timeout",n)},i.onload=()=>{try{JSON.parse(i.response)}catch(n){console.error("something wrong with file upload",n)}},i.open("POST",t+"/file"),i.setRequestHeader("Content-Type","multipart/form-data"),i.setRequestHeader("Authorization",s),i.send(r)}catch(i){console.error("Something wrong with xhr upload",i)}},500))},et=async(t,s,e,r,i,n,o)=>{H[e]||(H[e]=[]),H[e].push({file:s,id:r,url:e,raw:i,name:n,functionName:o}),gt(e,t.getToken())};var tt=K(require("@based/get-service")),te={},se={},yt=async(t,s)=>{if(s.url)return typeof s.url=="string"?s.url:await s.url();if(!t.opts.env&&t.opts.url)return typeof t.opts.url=="string"?t.opts.url:await t.opts.url();let{env:e,project:r,org:i}=t.opts,n=e+"/"+r+"/"+i+"/"+t.opts.cluster;if(te[n])return te[n];if(se[n])return(await se[n]).url;let o=await(se[n]=(0,tt.default)({env:e,project:r,org:i,name:"@based/hub",key:"file-upload",optionalKey:!0},0,t.opts.cluster));return delete se[n],setTimeout(()=>{delete te[n]},2e3),te[n]=o.url},st=yt;var it=K(require("cross-fetch")),ie=(t,s,e)=>((0,it.default)(s,{method:"POST",cache:"no-cache",headers:{"Content-Type":e.mimeType||"text/plain","File-Id":e.id,"File-Is-Raw":e.raw?"1":"0","File-Name":e.name||"","Function-Name":e.functionName||"",Authorization:t.getToken()},body:e.contents}).then(r=>{}).catch(r=>{console.error("Error while uploading file",r)}),{id:e.id});var A=require("./file/stream"),re=typeof window!="undefined",vt=t=>"src"in t&&typeof t.src=="string",St=t=>"path"in t&&typeof t.path=="string",kt=t=>"contents"in t&&(0,A.isStream)(t.contents),rt=async(t,s)=>{if(vt(s)){let i=s.id?{$id:s.id}:{type:"file"};return s.src?(i.src=s.src,i.origin=s.src,s.size&&(i.size=s.size),s.name&&(i.name=s.name),s.parents&&(i.parents=s.parents),await t.set(i)):void 0}let e=s.id;if(!e){let i={type:"file",progress:0};s.name?i.name=s.name:global.File&&"contents"in s&&s.contents instanceof global.File&&(i.name=s.contents.name),s.parents&&(i.parents=s.parents),e=(await t.set(i)).id}s.id=e;let r=(await st(t,s)).replace(/^ws/,"http");if(St(s))return(0,A.uploadFilePath)(t,r,s),{id:e};if(kt(s))return(0,A.uploadFileStream)(t,r,s),{id:e};if(s.contents instanceof ArrayBuffer)return s.contents=re?new global.Blob([s.contents],{type:s.mimeType||"text/plain"}):global.Buffer.from(s.contents),ie(t,r+"/file",s);if(re&&s.contents instanceof global.Blob)return s.mimeType||(s.mimeType=s.contents.type),ie(t,r+"/file",s);if(typeof s.contents=="string"||!re&&s.contents instanceof global.Buffer)return ie(t,r+"/file",s);if(re&&s.contents instanceof File)return et(t,s.contents,r,s.id,s.raw||!1,s.name,s.functionName),{id:e};throw s.id||await t.delete({$id:e}),new Error(`Invalid contents for file api ${JSON.stringify(s,null,2)}`)};var oe=K(require("@based/get-service")),Oe=require("@saulx/utils"),T=require("@based/graphql");p(m,require("@based/types"),module.exports);var ne=class extends Re{constructor(e){super();this.client=new x(this),Object.defineProperty(this,"client",{enumerable:!1,writable:!0}),e&&e.url&&this.connect(e.url),this.graphql={query:this.gqlQuery.bind(this),live:this.gqlLive.bind(this)}}connect(e){!e&&this._url?this.client.connection||(this.client.connection=le(this.client,this._url)):(this._url=e,this.client.connection=le(this.client,e))}disconnect(){this.client.connection&&(this.client.connection.disconnected=!0,this.client.connection.destroy(),this.client.connection.ws&&this.client.connection.ws.close(),this.client.connected&&this.client.onClose(),delete this.client.connection),this.client.connected=!1}observeUntil(e,r,i){return new Promise((n,o)=>{let c,a=!1;this.observe(e,(u,l)=>{i&&i(u,l),r(u,l)&&(a=!0,c&&c(),n(u))}).then(u=>{a?c():c=u}).catch(u=>{o(u)})})}gql(e,...r){typeof e=="string"&&(e=[e]);let i=e[0];return r.forEach((n,o)=>{n&&n.kind==="Document"?i+=n.loc.source.body:i+=n,i+=e[o+1]}),(0,T.createOperations)({schemas:this.client.configuration.schema},(0,T.parseGraphql)(i))}gqlDb(e="default"){return(r,...i)=>{typeof r=="string"&&(r=[r]);let n=r[0];return i.forEach((o,c)=>{o&&o.kind==="Document"?n+=o.loc.source.body:n+=o,n+=r[c+1]}),(0,T.createOperations)({schemas:this.client.configuration.schema,db:e},(0,T.parseGraphql)(n))}}observe(e,r,i,n){return typeof e=="string"?new Promise((o,c)=>{let a=typeof r=="function",u=a?r:i,l=a?i:n;I(this.client,a?void 0:r,u,(d,f,h,O,R)=>{d&&!R?c(d):o(()=>{S(this.client,f,h)})},l,void 0,e)}):new Promise((o,c)=>{I(this.client,e,r,(a,u,l,d,f)=>{a&&!f?c(a):o(()=>{S(this.client,u,l)})},i)})}createObservable(e,r){return typeof e=="string"?new C(this.client,e,r):new C(this.client,e)}observeSchema(e,r,i){return new Promise((n,o)=>{let c=typeof e=="string"?e:"default",a=typeof e=="string"?r:e,u=typeof e=="string"?i:r;I(this.client,{$subscribe_schema:c},(l,d)=>{this.client.configuration||(this.client.configuration={dbs:[],schema:{},functions:{}}),this.client.configuration.schema[c]=l,a(l,d)},(l,d,f,h,O)=>{l&&!O?o(l):n(()=>{S(this.client,d,f)})},u)})}get(e,r){return typeof e=="string"?new Promise((i,n)=>{V(this.client,r,(o,c,a,u)=>{o?n(o):i(u)},0,e)}):new Promise((i,n)=>{y(this.client,v.RequestTypes.Get,e,i,n)})}file(e){return global.File&&e instanceof File&&(e={contents:e}),rt(this,e)}call(e,r){return new Promise((i,n)=>{y(this.client,v.RequestTypes.Call,r,i,n,e)})}async id(e,r){let i=ge(this.client,e);if(i||(await this.schema(),i=ge(this.client,e)),!i)throw w({message:`Type does not exist ${e}`,type:"Invalid type",payload:r?{type:e,opts:r}:{type:e}});if(r){let n=(0,Te.hashCompact)(r,8,!0);return i+n}else return i+(0,Te.hashCompact)(Math.floor(Math.random()*99999999999)+""+Date.now())}digest(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Digest,e,r,i)})}set(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Set,e,r,i)})}bulkUpdate(e,r){return new Promise((i,n)=>{y(this.client,v.RequestTypes.BulkUpdate,{payload:e,query:r},i,n)})}copy(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Copy,e,r,i)})}async gqlQuery(e,r={}){let i;typeof e=="string"?i=this.gql(e):i=e;try{if(i=(0,T.handleGraphqlVariables)(i,i,r),i.opType==="GET"){let o={$db:i.db},c=[];for(let u in i.ops){if(i.ops[u].fnObserve){let l=await this.get(i.ops[u].fnObserve.name,i.ops[u].fnObserve.payload);c.push({key:u,reply:l});continue}i.ops[u].get&&(o[u]=i.ops[u].get)}let a=await this.get(o);for(let{key:u,reply:l}of c)a[u]=l;return{data:a}}let n={};return await Promise.all(Object.entries(i.ops).map(async([o,c])=>{var d,f,h,O,R;if(c.delete){n[o]=await this.delete(c.delete);return}else if(c.fnCall){n[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set);if(!c.get){let Q={};Q.id=a;let we=(R=(O=(h=(f=(d=this.client)==null?void 0:d.configuration)==null?void 0:f.schema)==null?void 0:h[i.db])==null?void 0:O.prefixToTypeMapping)==null?void 0:R[a.slice(0,2)];we&&(Q.type=we),n[o]=Q;return}let u=(0,Oe.deepCopy)(c.get);u.$id=a;let l=await this.get(u);n[o]=l})),{data:n}}catch(n){return{errors:[{message:n.message,locations:n.locations}]}}}async gqlLive(e,r={}){let i;if(typeof e=="string"?i=this.gql(e):i=e,i=(0,T.handleGraphqlVariables)(i,i,r),i.opType==="GET"){let o=[],c={};for(let a in i.ops){if(i.ops[a].fnObserve){let{name:u,payload:l}=i.ops[a].fnObserve;o.push({key:a,fn:{name:u,payload:l}});continue}c[a]=i.ops[a].get}if(o!=null&&o.length){let a=o.map(l=>({obs:new C(this.client,l.fn.name,l.fn.payload),key:l.key})),u=new C(this.client,G({$db:i.db},c));return a.push({key:"",obs:u}),new ee(this.client,a)}return new C(this.client,{$db:i.db,data:c})}let n={};return await Promise.all(Object.entries(i.ops).map(async([o,c])=>{if(c.delete){n[o]=await this.delete(c.delete);return}else if(c.fnCall){n[o]=await this.call(c.fnCall.name,c.fnCall.payload);return}let{id:a}=await this.set(c.set),u=(0,Oe.deepCopy)(c.get);u.$id=a,n[o]=u})),new C(this.client,{$db:i.db,data:n})}analytics(e,r){return new Promise((i,n)=>{r?I(this.client,e,r,(o,c,a,u,l)=>{o&&!l?n(o):i(()=>{S(this.client,c,a)})},o=>console.error(o),void 0,"analytics"):V(this.client,e,(o,c,a,u)=>{o?n(o):((0,v.isAnalyticsHistoryOpts)(e)||(0,v.isAnalyticsTypesOpts)(e),i(u))},0,"analytics")})}track(e,r){N(this.client,e,r)}clearAnalytics(e,r){N(this.client,e,r,!1,!1,void 0,!0)}untrack(e,r){N(this.client,e,r,!0)}event(e,r,i){N(this.client,e,r,!1,!0,i)}delete(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Delete,e,r,i)})}schema(){return new Promise((e,r)=>{let i=n=>{this.client.configuration=n,e(n)};y(this.client,v.RequestTypes.GetConfiguration,0,i,r)})}removeType(e,r="default"){return new Promise((i,n)=>{y(this.client,v.RequestTypes.RemoveType,{type:e,db:r},i,n)})}removeField(e,r,i="default"){return new Promise((n,o)=>{!r||r.length===0?o(new Error("Path cannot be empty")):(Array.isArray(r)||(r=[r]),y(this.client,v.RequestTypes.RemoveField,{type:e,db:i,path:r},n,o))})}updateSchema(e){return new Promise((r,i)=>{y(this.client,v.RequestTypes.Configuration,e,r,i)})}getToken(){return this.client.token}auth(e,r){return new Promise(i=>{if(e&&e===this.client.token)this.client.beingAuth?this.client.auth.push(o=>{i(o?e:!1)}):i(e);else if(this.client.auth.push(i),e&&e!==this.client.token||e===!1&&this.client.token)if(typeof e=="string"&&(r==null?void 0:r.id)&&r.refreshToken)r.localStorage===!1?this.client.tokenToLocalStorage=!1:this.client.tokenToLocalStorage=!0,this.client.updateUserState(r.id,e,r.refreshToken);else{if(typeof e=="string"){let n=r||{},{renewOptions:o,refreshToken:c}=n,a=qe(n,["renewOptions","refreshToken"]);o&&(this.client.renewOptions=o),c&&(this.client.renewOptions=J(G({},this.client.renewOptions),{refreshToken:c})),E(this.client,e,a)}else E(this.client);this.emit("auth",e)}})}async login(e){return e.localStorage===!1?this.client.tokenToLocalStorage=!1:this.client.tokenToLocalStorage=!0,_e(this.client,e)}async register(e){return e.localStorage===!1?this.client.tokenToLocalStorage=!1:this.client.tokenToLocalStorage=!0,ze(this.client,e)}logout(){return We(this.client)}observeAuth(e){return new Promise(r=>{this.client.user&&this.client.token?e({id:this.client.user,token:this.client.token}):e(!1);let i=n=>{n&&this.client.user&&this.client.token?e({id:this.client.user,token:this.client.token}):e(!1)};this.on("auth",i),r(()=>{this.removeListener("auth",i)})})}},Tt=(t,s)=>{if(s){let e;t+=/\?/.test(t)?"&":"?";for(let r in s){let i=s[r];t+=e?`&${r}=${i}`:`${r}=${i}`,e=!0}}return t},Ot=(t,s=ne)=>{let{env:e,project:r,org:i,url:n,key:o,name:c="@based/hub",cluster:a,params:u}=t;if(n||(a=t.cluster=(0,oe.getClusterUrl)(a),n=async()=>{let{url:l}=await(0,oe.default)({env:e,project:r,org:i,key:o,name:c,optionalKey:!0},0,a);return Tt(l,u)}),n){let l=new s;return l.opts=t,l.client.initUserState(),l.connect(n),l}},wt=Ot;0&&(module.exports={Based,BasedClient,BasedGraphQL,Observable,addGetSubscriber,addRequest,addSubscriber,createGraphqlOperations,generateSubscriptionId,generateTrackingKey,handleGraphqlVariables,parseGraphql,removeSubscriber});
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA+B;AAC/B,4DAA0C;AAC1C,wCAyBqB;AACrB,mDAKwB;AA4BtB,8FAhCA,6BAAa,OAgCA;AAIb,uGAnCA,sCAAsB,OAmCA;AAHtB,iGA/BA,gCAAgB,OA+BA;AAChB,iGA/BA,gCAAgB,OA+BA;AA7BlB,uCAAsC;AA8BpC,2FA9BO,oBAAU,OA8BP;AA7BZ,qCAAsC;AA+BpC,4FA/BO,oBAAW,OA+BP;AA9Bb,8DAAqC;AACrC,gEAAuC;AACvC,sCAAyC;AACzC,oDAA+B;AAC/B,iDAA8D;AAoB5D,oGApBwB,cAAmB,OAoBxB;AAnBrB,6CAA0E;AA0BxE,2FA1BwC,uBAAU,OA0BxC;AAzBZ,iCAAgD;AAChD,kDAAyB;AACzB,kEAA8D;AAC9D,wCAAuC;AACvC,4CAKuB;AAMD,wGATpB,0BAAgB,OAS2B;AAC3C,6FATA,sBAAY,OASA;AACZ,uGATA,gCAAsB,OASA;AANxB,+CAA4B;AAgC5B,MAAa,KAAM,SAAQ,iBAAO;IAchC,YAAY,IAAgD;QAC1D,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAW,CAAC,IAAI,CAAC,CAAA;QACnC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE;YACpC,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,IAAI;SACf,CAAC,CAAA;QACF,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE;YACpB,IAAI,CAAC,O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,EAAE;IAC3D,IAAI,EACF,GAAG,EACH,OAAO,EACP,GAAG,EACH,GAAG,EACH,GAAG,EACH,IAAI,GAAG,YAAY,EACnB,OAAO,EACP,MAAM,GACP,GAAG,IAAI,CAAA;IAER;;;MAGE;IAEF,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,IAAA,2BAAa,EAAC,OAAO,CAAC,CAAA;QAE/C,GAAG,GAAG,KAAK,IAAI,EAAE;YACf,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAA,qBAAU,EAC9B;gBACE,GAAG;gBACH,OAAO;gBACP,GAAG;gBACH,GAAG;gBACH,IAAI;gBACJ,WAAW,EAAE,IAAI;aAClB,EACD,CAAC,EACD,OAAO,CACR,CAAA;YACD,OAAO,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACpC,CAAC,CAAA;KACF;IAED,IAAI,GAAG,EAAE;QACP,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAA;QAC/B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAA;QAClB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,CAAA;QAC7B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,MAAM,CAAA;KACd;AACH,CAAC,CAAA;AAED,kBAAe,KAAK,CAAA"}
@@ -0,0 +1,74 @@
1
+ ## JWT Auth Flow HowTo using based/ui
2
+
3
+ This guide shows how to implement authentication using [based/ui](https://github.com/atelier-saulx/ui) UI library and its authentication components.
4
+ The tutorial example files can be found in [this repository](https://github.com/atelier-saulx/auth-demo).
5
+
6
+ ### Imports
7
+
8
+ Components can be imported or required from the [`@based/ui`](https://www.npmjs.com/package/@based/ui) npm package.
9
+ ```bash
10
+ $ npm install @based/ui
11
+ ```
12
+
13
+ ```javascript
14
+ import { Provider, Authorize } from '@based/ui'
15
+ ```
16
+
17
+ ### Provider
18
+
19
+ The first step is to wrap the app with a `<Provider />` component. This will set up the app to handle third-party auth provider callbacks and handle overlays and themes from the `based/ui` library.
20
+ The `<Provider />` component expects the main app component as a child and a [based client](https://github.com/atelier-saulx/based/blob/main/packages/client/README.md) as the `client` argument.
21
+
22
+ ```javascript
23
+ const client = based(basedConfig)
24
+ render(
25
+ <Provider client={client}>
26
+ <App />
27
+ </Provider>,
28
+ rootEl
29
+ )
30
+ ```
31
+
32
+ ### Authorize component
33
+
34
+ The Authorize component renders other components only when a user is authenticated. If the user is not authenticated, it will show a login/register dialog.
35
+ Email, Google, Microsoft, and Github provider handler functions are installed in new environments by default. We encourage you to check these [templates](https://github.com/atelier-saulx/based/tree/main/packages/templates/jwtAuth/functions) and adapt them to your needs by adding the [data functions](https://github.com/atelier-saulx/based/tree/main/packages/templates/jwtAuth/functions) to your project and [deploying](https://github.com/atelier-saulx/based/blob/main/packages/cli/README.md#deploy) them with the [based CLI](https://github.com/atelier-saulx/based/blob/main/packages/cli/README.md).
36
+
37
+ ```javascript
38
+ <Authorize
39
+ // googleClientId="<your_google_client_id>"
40
+ // microsoftClientId="<your_microsoft_client_id>"
41
+ // githubClientId="<your_github_client_id>"
42
+ app={LoggedinBody}
43
+ />
44
+ ```
45
+
46
+ The protected sections of your site should be wrapped in a component passed to the `app` argument.
47
+ The component is passed as an argument instead of `children`, so the protected components are never rendered if the user is not authenticated.
48
+
49
+ ### Email provider
50
+
51
+ New environments came by default, with a `user` type ready to receive email registrations. The [`register` user data function](https://github.com/atelier-saulx/based/blob/main/packages/templates/jwtAuth/functions/registerUser/index.ts) registers new users using the name and email address, sends a confirmation email, and waits for the new user to click the email message he received confirming the email address.
52
+
53
+ ### Google provider
54
+
55
+ To enable the Sign In with Google provider and button, you need to configure the google client id and google client secret.
56
+ Follow the instructions in [this](https://developers.google.com/identity/sign-in/web/sign-in) page to the point where you have both.
57
+ The client id is configured in the `<Authorize />` component as the `googleClientId` argument.
58
+ The client secret should be saved as a [secret](https://github.com/atelier-saulx/based/tree/main/packages/cli#secrets) with the name `google-client-secret-<project>-<env>` where `<project>` and `<env>` should be replaced with the name of your project and environment.
59
+ The Google credential should be configured with your domain and `https://<your_domain>/auth-google` as the callback address.
60
+
61
+ ### Microsoft provider
62
+
63
+ To enable the Microsoft Identity Platform provider, you need to configure a Microsoft client id.
64
+ Follow the instructions in [this](https://docs.microsoft.com/en-us/azure/active-directory/develop/web-api-quickstart?pivots=devlang-aspnet) page until you have the Microsoft client id.
65
+ The client id is configured in the `<Authorize />` component with the `microsoftClientId` argument.
66
+ The Azure application should be configured with your domain and `https://<your_domain>/auth-microsoft` as the callback address.
67
+
68
+ ### GitHub provider
69
+
70
+ To enable the GitHub Oauth provider, your need to configure your GitHub client id and client secret.
71
+ Follow the instructions in [this](https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app) page to get both.
72
+ Be sure to de your domain name and user `https://<your_domain>/auth-github` as the callback address.
73
+ The client id should be configured in the `<Authorize />` component using the `githubClientId` argument. The client secret should be saved as a [secret](https://github.com/atelier-saulx/based/tree/main/packages/cli#secrets) with the name `github-client-secret-<project>-<env>` where `<project>` and `<env>` should be replaced with the name of your project and environment.
74
+
package/docs/auth.md CHANGED
@@ -18,27 +18,27 @@ This data function runs every time the based client tries to call, get, modify o
18
18
  It approves or denies the request depending on its context. See [`authorize`](https://github.com/atelier-saulx/based/blob/main/packages/client/docs/authorize.md)
19
19
  Returns boolean value allowing or disallowing the connection.
20
20
 
21
- Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/auth-templates/jwt/authorize/authorize.ts)
21
+ Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/templates/jwtAuth/functions/authorize/index.ts)
22
22
 
23
23
  ### `login`
24
24
 
25
25
  Called then the client [login()]() method is called. It should authenticate the user and generate the tokens. Authentication flow is up to the user.
26
26
  For example, in a JWT flow, this function will validate the user in the data, sign a token and refreshToken returning them to the client.
27
27
 
28
- Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/auth-templates/jwt/login/login.ts)
28
+ Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/templates/jwtAuth/functions/login/index.ts)
29
29
 
30
30
  ### `logout`
31
31
 
32
32
  When your app logs out a user, it should call the `client.logout()` method. This method calls this data function if it exists. It is meant to have token invalidation and any cleanup that should happen when a user logs out.
33
33
 
34
- Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/auth-templates/jwt/logout/logout.ts)
34
+ Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/templates/jwtAuth/functions/logout/index.ts)
35
35
 
36
36
  ### `renewToken`
37
37
 
38
38
  For auth flows that rely on token renewal. This data function runs when a specific error is triggered in the `authorize` function.
39
39
  The result is returned to the client using the `renewToken` client event.
40
40
 
41
- Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/auth-templates/jwt/renewToken/renewToken.ts)
41
+ Example: see [here](https://github.com/atelier-saulx/based/blob/main/packages/templates/jwtAuth/functions/renewToken/index.ts)
42
42
 
43
43
  ## Based client methods
44
44
 
@@ -88,4 +88,6 @@ This event is called when the renewToken data function is run. It is used to han
88
88
 
89
89
  ## How to use
90
90
 
91
- Check [this guide](https://github.com/atelier-saulx/based/blob/main/packages/client/docs/auth-howto.md) for an example of how the use.
91
+ Check the guides bellow for examples of how the use:
92
+ - [React](https://github.com/atelier-saulx/based/blob/main/packages/client/docs/auth-howto.md)
93
+ - [React with based/ui library](https://github.com/atelier-saulx/based/blob/main/packages/client/docs/auth-based-ui-howto.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/client",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "browser": {
@@ -42,8 +42,8 @@
42
42
  "@based/types": "^2.8.0",
43
43
  "@saulx/aristotle": "^4.0.14",
44
44
  "@saulx/hash": "^1.1.0",
45
- "@saulx/selva": "^14.0.0",
46
- "@saulx/selva-server": "^14.0.0",
45
+ "@saulx/selva": "^19.0.0",
46
+ "@saulx/selva-server": "^19.0.0",
47
47
  "@types/jsonwebtoken": "^8.5.6",
48
48
  "@types/node": "^17.0.23",
49
49
  "@types/ws": "^7.4.6",