@memberjunction/graphql-dataprovider 2.18.1 → 2.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var
|
|
1
|
+
"use strict";var q=Object.defineProperty;var g=(I,e)=>q(I,"name",{value:e,configurable:!0});var w=require("graphql-request"),y=require("@memberjunction/core"),x=require("@memberjunction/core-entities"),M=require("@tempfix/idb"),Q=require("rxjs"),k=require("graphql-ws"),B=require("uuid"),U=require("@memberjunction/global");const $=class ${constructor(){this._fieldMap={__mj_CreatedAt:"_mj__CreatedAt",__mj_UpdatedAt:"_mj__UpdatedAt",__mj_DeletedAt:"_mj__DeletedAt"}}MapFields(e){if(e)for(const a in e)a in this._fieldMap&&(e[this._fieldMap[a]]=e[a],delete e[a]);return e}MapFieldName(e){return this._fieldMap[e]??e}ReverseMapFieldName(e){return Object.entries(this._fieldMap).find(([a,s])=>s===e)?.[0]??e}ReverseMapFields(e){const a=Object.fromEntries(Object.entries(this._fieldMap).map(([s,t])=>[t,s]));for(const s in e)s in a&&(e[a[s]]=e[s],delete e[s]);return e}};g($,"FieldMapper");let N=$;const G=class G extends y.ProviderConfigDataBase{get Token(){return this.Data.Token}set Token(e){this.Data.Token=e}get URL(){return this.Data.URL}get WSURL(){return this.Data.WSURL}get RefreshTokenFunction(){return this.Data.RefreshFunction}constructor(e,a,s,t,r,c,n){super({Token:e,URL:a,WSURL:s,RefreshTokenFunction:t},r,c,n)}};g(G,"GraphQLProviderConfigData");let V=G;const R=class R extends y.ProviderBase{constructor(){super(),this._innerCurrentUserQueryString=`CurrentUser {
|
|
2
2
|
${this.userInfoString()}
|
|
3
3
|
UserRoles_UserIDArray {
|
|
4
4
|
${this.userRoleInfoString()}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
}
|
|
7
7
|
`,this._currentUserQuery=w.gql`query CurrentUserAndRoles {
|
|
8
8
|
${this._innerCurrentUserQueryString}
|
|
9
|
-
}`,this._wsClient=null,this._pushStatusRequests=[],R._instance||(R._instance=this)}static get Instance(){return R._instance}get ConfigData(){return this._configData}get DatabaseConnection(){throw new Error("DatabaseConnection not implemented for the GraphQLDataProvider")}GenerateUUID(){return B.v4()}get LocalStoragePrefix(){return this._configData.URL.replace(/[^a-zA-Z0-9]/g,"_")+"."}async Config(e,a){try{const s=this.GenerateUUID();return a?(this._sessionId=s,this._configData=e,this._client=this.CreateNewGraphQLClient(e.URL,e.Token,this._sessionId)):(R.Instance._sessionId===void 0&&(R.Instance._sessionId=s),R.Instance._configData=e,R.Instance._client||(R.Instance._client=this.CreateNewGraphQLClient(e.URL,e.Token,R.Instance._sessionId))),super.Config(e)}catch(s){throw y.LogError(s),s}}get sessionId(){return this._sessionId}get AllowRefresh(){return!0}async GetCurrentUser(){const e=await this.ExecuteGQL(this._currentUserQuery,null);if(e){const a=this.ConvertBackToMJFields(e.CurrentUser),s=a.UserRoles_UserIDArray.map(t=>this.ConvertBackToMJFields(t));return a.UserRoles_UserIDArray=s,new y.UserInfo(this,{...a,UserRoles:s})}}async RunReport(e,a){const s=w.gql`
|
|
9
|
+
}`,this._wsClient=null,this._pushStatusRequests=[],R._instance||(R._instance=this)}static get Instance(){return R._instance}get ConfigData(){return this._configData}get DatabaseConnection(){throw new Error("DatabaseConnection not implemented for the GraphQLDataProvider")}get InstanceConnectionString(){return this._configData.URL}GenerateUUID(){return B.v4()}get LocalStoragePrefix(){return this._configData.URL.replace(/[^a-zA-Z0-9]/g,"_")+"."}async Config(e,a){try{const s=this.GenerateUUID();return a?(this._sessionId=s,this._configData=e,this._client=this.CreateNewGraphQLClient(e.URL,e.Token,this._sessionId)):(R.Instance._sessionId===void 0&&(R.Instance._sessionId=s),R.Instance._configData=e,R.Instance._client||(R.Instance._client=this.CreateNewGraphQLClient(e.URL,e.Token,R.Instance._sessionId))),super.Config(e)}catch(s){throw y.LogError(s),s}}get sessionId(){return this._sessionId}get AllowRefresh(){return!0}async GetCurrentUser(){const e=await this.ExecuteGQL(this._currentUserQuery,null);if(e){const a=this.ConvertBackToMJFields(e.CurrentUser),s=a.UserRoles_UserIDArray.map(t=>this.ConvertBackToMJFields(t));return a.UserRoles_UserIDArray=s,new y.UserInfo(this,{...a,UserRoles:s})}}async RunReport(e,a){const s=w.gql`
|
|
10
10
|
query GetReportDataQuery ($ReportID: String!) {
|
|
11
11
|
GetReportData(ReportID: $ReportID) {
|
|
12
12
|
Success
|
|
@@ -184,9 +184,9 @@
|
|
|
184
184
|
sessionId
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
`,t=new Q.Observable(r=>(this._wsClient.subscribe({query:s,variables:{sessionId:e}},{next:c=>r.next(c.data.statusUpdates),error:c=>r.error(c),complete:()=>r.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:t}),t}};
|
|
187
|
+
`,t=new Q.Observable(r=>(this._wsClient.subscribe({query:s,variables:{sessionId:e}},{next:c=>r.next(c.data.statusUpdates),error:c=>r.error(c),complete:()=>r.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:t}),t}};g(R,"GraphQLDataProvider");let S=R;const _=class _{constructor(){this._localStorage={}}async getItem(e){return new Promise(a=>{this._localStorage.hasOwnProperty(e)?a(this._localStorage[e]):a(null)})}async setItem(e,a){return new Promise(s=>{this._localStorage[e]=a,s()})}async remove(e){return new Promise(a=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],a()})}};g(_,"BrowserStorageProviderBase");let F=_;const A="MJ_Metadata",E="Metadata_KVPairs",v=class v extends F{constructor(){super(),this.dbPromise=M.openDB(A,1,{upgrade(e){e.objectStoreNames.contains(E)||e.createObjectStore(E)}})}async setItem(e,a){const t=(await this.dbPromise).transaction(E,"readwrite");await t.objectStore(E).put(a,e),await t.done}async getItem(e){return await(await this.dbPromise).transaction(E).objectStore(E).get(e)}async remove(e){const s=(await this.dbPromise).transaction(E,"readwrite");await s.objectStore(E).delete(e),await s.done}};g(v,"BrowserIndexedDBStorageProvider");let C=v;const L=class L extends y.TransactionGroupBase{constructor(e){super(),this._provider=e}async HandleSubmit(e){let a="",s="";const t={};for(let n=0;n<e.length;n++){const i=e[n];let p=i.Instruction;if(i.Vars){const f=Object.keys(i.Vars);for(let d=0;d<f.length;d++){const u=f[d],o=`${u}_${n}`;t[o]=i.Vars[u];const l=new RegExp("\\$"+u,"g");p=p.replace(l,"$"+o);const m=i.ExtraData.mutationInputTypes.find(h=>h.varName===u)?.inputType;s+=`$${o}: ${m}
|
|
188
188
|
`}}a+=`mutation_${n}: `+p+`
|
|
189
189
|
`}a=`mutation TransactionGroup(${s}){
|
|
190
190
|
`+a+`
|
|
191
|
-
}`;const r=await this._provider.ExecuteGQL(a,t),c=[];for(let n=0;n<e.length;n++){const i=r[`mutation_${n}`],p=e[n];c.push(new y.TransactionResult(p,i,i!==null))}return c}};
|
|
191
|
+
}`;const r=await this._provider.ExecuteGQL(a,t),c=[];for(let n=0;n<e.length;n++){const i=r[`mutation_${n}`],p=e[n];c.push(new y.TransactionResult(p,i,i!==null))}return c}};g(L,"GraphQLTransactionGroup");let T=L;async function K(I){const e=new S;return y.SetProvider(e),await e.Config(I),U.MJGlobal.Instance.RaiseEvent({event:U.MJEventType.LoggedIn,eventCode:null,component:this,args:null}),e}g(K,"setupGraphQLClient"),Object.defineProperty(exports,"gql",{enumerable:!0,get:function(){return w.gql}}),exports.FieldMapper=N,exports.GraphQLDataProvider=S,exports.GraphQLProviderConfigData=V,exports.setupGraphQLClient=K;
|
|
192
192
|
//# sourceMappingURL=index.cjs.map
|