@memberjunction/graphql-dataprovider 2.87.0 → 2.89.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/dist/index.cjs +12 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +9 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0});import{gql as R,GraphQLClient as ue}from"graphql-request";import{gql as Be}from"graphql-request";import{TransactionGroupBase as Se,TransactionResult as fe,ProviderConfigDataBase as he,ProviderBase as ge,LogError as m,UserInfo as le,ProviderType as
|
|
1
|
+
var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0});import{gql as R,GraphQLClient as ue}from"graphql-request";import{gql as Be}from"graphql-request";import{TransactionGroupBase as Se,TransactionResult as fe,ProviderConfigDataBase as he,ProviderBase as ge,LogError as m,UserInfo as le,ProviderType as Ie,BaseEntityResult as ce,EntityFieldTSType as p,TransactionItem as ye,UserRoleInfo as pe,SetProvider as Ee}from"@memberjunction/core";import{ViewInfo as me}from"@memberjunction/core-entities";import{openDB as Ne}from"@tempfix/idb";import{Observable as de}from"rxjs";import{createClient as De}from"graphql-ws";import{v4 as Ce}from"uuid";import{SafeJSONParse as C,MJGlobal as Ve,MJEventType as $e}from"@memberjunction/global";const K=class K{constructor(){this._fieldMap={__mj_CreatedAt:"_mj__CreatedAt",__mj_UpdatedAt:"_mj__UpdatedAt",__mj_DeletedAt:"_mj__DeletedAt"}}MapFields(e){if(e)for(const t in e)t in this._fieldMap&&(e[this._fieldMap[t]]=e[t],delete e[t]);return e}MapFieldName(e){return this._fieldMap[e]??e}ReverseMapFieldName(e){return Object.entries(this._fieldMap).find(([t,r])=>r===e)?.[0]??e}ReverseMapFields(e){const t=Object.fromEntries(Object.entries(this._fieldMap).map(([r,s])=>[s,r]));for(const r in e)r in t&&(e[t[r]]=e[r],delete e[r]);return e}};S(K,"FieldMapper");let N=K;const k=class k extends Se{constructor(e){super(),this._provider=e}async HandleSubmit(){const e=R`
|
|
2
2
|
mutation ExecuteTransactionGroup($group: TransactionInputType!) {
|
|
3
3
|
ExecuteTransactionGroup(group: $group) {
|
|
4
4
|
Success
|
|
@@ -44,7 +44,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
44
44
|
TotalRowCount
|
|
45
45
|
ExecutionTime
|
|
46
46
|
ErrorMessage
|
|
47
|
-
AppliedParameters`}TransformQueryPayload(e){try{return{QueryID:e.QueryID,QueryName:e.QueryName,Success:e.Success,Results:JSON.parse(e.Results),RowCount:e.RowCount,TotalRowCount:e.TotalRowCount,ExecutionTime:e.ExecutionTime,ErrorMessage:e.ErrorMessage,AppliedParameters:e.AppliedParameters?JSON.parse(e.AppliedParameters):void 0}}catch(t){return m(`Error transforming query payload: ${t}`),null}}async RunView(e,t){await this.PreProcessRunView(e,t);try{let r="",s="";if(e){const a={};let o,i;if(e.ViewEntity)i=e.ViewEntity,o=i.Entity;else{const{entityName:u,v:l}=await this.getEntityNameAndUserView(e,t);i=l,o=u}const n=this.Entities.find(u=>u.Name===o);if(!n)throw new Error(`Entity ${o} not found in metadata`);let y=!1;e.ViewID?(r=`Run${n.ClassName}ViewByID`,s="RunViewByIDInput",a.ViewID=e.ViewID):e.ViewName?(r=`Run${n.ClassName}ViewByName`,s="RunViewByNameInput",a.ViewName=e.ViewName):(y=!0,r=`Run${n.ClassName}DynamicView`,s="RunDynamicViewInput",a.EntityName=e.EntityName),a.ExtraFilter=e.ExtraFilter?e.ExtraFilter:"",a.OrderBy=e.OrderBy?e.OrderBy:"",a.UserSearchString=e.UserSearchString?e.UserSearchString:"",a.Fields=e.Fields,a.IgnoreMaxRows=e.IgnoreMaxRows?e.IgnoreMaxRows:!1,a.MaxRows=e.MaxRows
|
|
47
|
+
AppliedParameters`}TransformQueryPayload(e){try{return{QueryID:e.QueryID,QueryName:e.QueryName,Success:e.Success,Results:JSON.parse(e.Results),RowCount:e.RowCount,TotalRowCount:e.TotalRowCount,ExecutionTime:e.ExecutionTime,ErrorMessage:e.ErrorMessage,AppliedParameters:e.AppliedParameters?JSON.parse(e.AppliedParameters):void 0}}catch(t){return m(`Error transforming query payload: ${t}`),null}}async RunView(e,t){await this.PreProcessRunView(e,t);try{let r="",s="";if(e){const a={};let o,i;if(e.ViewEntity)i=e.ViewEntity,o=i.Entity;else{const{entityName:u,v:l}=await this.getEntityNameAndUserView(e,t);i=l,o=u}const n=this.Entities.find(u=>u.Name===o);if(!n)throw new Error(`Entity ${o} not found in metadata`);let y=!1;e.ViewID?(r=`Run${n.ClassName}ViewByID`,s="RunViewByIDInput",a.ViewID=e.ViewID):e.ViewName?(r=`Run${n.ClassName}ViewByName`,s="RunViewByNameInput",a.ViewName=e.ViewName):(y=!0,r=`Run${n.ClassName}DynamicView`,s="RunDynamicViewInput",a.EntityName=e.EntityName),a.ExtraFilter=e.ExtraFilter?e.ExtraFilter:"",a.OrderBy=e.OrderBy?e.OrderBy:"",a.UserSearchString=e.UserSearchString?e.UserSearchString:"",a.Fields=e.Fields,a.IgnoreMaxRows=e.IgnoreMaxRows?e.IgnoreMaxRows:!1,e.MaxRows!==void 0&&(a.MaxRows=e.MaxRows),e.StartRow!==void 0&&(a.StartRow=e.StartRow),a.ForceAuditLog=e.ForceAuditLog?e.ForceAuditLog:!1,a.ResultType=e.ResultType?e.ResultType:"simple",e.AuditLogDescription&&e.AuditLogDescription.length>0&&(a.AuditLogDescription=e.AuditLogDescription),y||(a.ExcludeUserViewRunID=e.ExcludeUserViewRunID?e.ExcludeUserViewRunID:"",a.ExcludeDataFromAllPriorViewRuns=e.ExcludeDataFromAllPriorViewRuns?e.ExcludeDataFromAllPriorViewRuns:!1,a.OverrideExcludeFilter=e.OverrideExcludeFilter?e.OverrideExcludeFilter:"",a.SaveViewResults=e.SaveViewResults?e.SaveViewResults:!1);const D=this.getViewRunTimeFieldList(n,i,e,y),d=R`
|
|
48
48
|
query RunViewQuery ($input: ${s}!) {
|
|
49
49
|
${r}(input: $input) {
|
|
50
50
|
Results {
|
|
@@ -58,7 +58,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
58
58
|
Success
|
|
59
59
|
ErrorMessage
|
|
60
60
|
}
|
|
61
|
-
}`,c=await this.ExecuteGQL(d,{input:a});if(c&&c[r]){const u=c[r].Results;if(u&&u.length>0){const f=n.Fields.filter(w=>w.CodeName!==w.Name&&w.CodeName!==void 0);u.forEach(w=>{this.ConvertBackToMJFields(w),f.forEach(
|
|
61
|
+
}`,c=await this.ExecuteGQL(d,{input:a});if(c&&c[r]){const u=c[r].Results;if(u&&u.length>0){const f=n.Fields.filter(w=>w.CodeName!==w.Name&&w.CodeName!==void 0);u.forEach(w=>{this.ConvertBackToMJFields(w),f.forEach(I=>{w[I.Name]=w[I.CodeName]})})}const l=c[r];return await this.PostProcessRunView(l,e,t),l}}else throw"No parameters passed to RunView";return null}catch(r){throw m(r),r}}async RunViews(e,t){await this.PreProcessRunViews(e,t);try{let r=[],s=[],a=[];for(const n of e){let y="",D="";const d={};let c=null,u=null;if(n.ViewEntity)u=n.ViewEntity,c=u.Get("Entity");else{const{entityName:w,v:I}=await this.getEntityNameAndUserView(n,t);u=I,c=w}const l=this.Entities.find(w=>w.Name===c);if(!l)throw new Error(`Entity ${c} not found in metadata`);s.push(l);let f=!1;n.ViewID?(y=`Run${l.ClassName}ViewByID`,D="RunViewByIDInput",d.ViewID=n.ViewID):n.ViewName?(y=`Run${l.ClassName}ViewByName`,D="RunViewByNameInput",d.ViewName=n.ViewName):(f=!0,y=`Run${l.ClassName}DynamicView`,D="RunDynamicViewInput",d.EntityName=n.EntityName),d.ExtraFilter=n.ExtraFilter||"",d.OrderBy=n.OrderBy||"",d.UserSearchString=n.UserSearchString||"",d.Fields=n.Fields,d.IgnoreMaxRows=n.IgnoreMaxRows||!1,n.MaxRows!==void 0&&(d.MaxRows=n.MaxRows),n.StartRow!==void 0&&(d.StartRow=n.StartRow),d.ForceAuditLog=n.ForceAuditLog||!1,d.ResultType=n.ResultType||"simple",n.AuditLogDescription&&n.AuditLogDescription.length>0&&(d.AuditLogDescription=n.AuditLogDescription),f||(d.ExcludeUserViewRunID=n.ExcludeUserViewRunID||"",d.ExcludeDataFromAllPriorViewRuns=n.ExcludeDataFromAllPriorViewRuns||!1,d.OverrideExcludeFilter=n.OverrideExcludeFilter||"",d.SaveViewResults=n.SaveViewResults||!1),r.push(d),a.push(...this.getViewRunTimeFieldList(l,u,n,f))}const o=R`
|
|
62
62
|
query RunViewsQuery ($input: [RunViewGenericInput!]!) {
|
|
63
63
|
RunViews(input: $input) {
|
|
64
64
|
Results {
|
|
@@ -73,7 +73,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
73
73
|
Success
|
|
74
74
|
ErrorMessage
|
|
75
75
|
}
|
|
76
|
-
}`,i=await this.ExecuteGQL(o,{input:r});if(i&&i.RunViews){const n=i.RunViews;for(const[y,D]of n.entries())D.Results=D.Results.map(d=>{let c=JSON.parse(d.Data);return this.ConvertBackToMJFields(c),c});return await this.PostProcessRunViews(n,e,t),n}return null}catch(r){throw m(r),r}}async getEntityNameAndUserView(e,t){let r,s;if(e.EntityName)r=e.EntityName;else if(e.ViewID)s=await me.GetViewEntity(e.ViewID,t),r=s.Entity;else if(e.ViewName)s=await me.GetViewEntityByName(e.ViewName,t),r=s.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:r,v:s}}getViewRunTimeFieldList(e,t,r,s){const a=[],o=new N;if(r.Fields){for(const i of e.PrimaryKeys)r.Fields.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);r.Fields.forEach(i=>{a.push(o.MapFieldName(i))})}else if(s)e.Fields.forEach(i=>{i.IsBinaryFieldType||a.push(o.MapFieldName(i.CodeName))});else{for(const i of e.PrimaryKeys)a.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);t.Columns.forEach(i=>{i.hidden===!1&&!a.find(n=>n.trim().toLowerCase()===i.EntityField?.Name.trim().toLowerCase())&&i.EntityField&&a.push(o.MapFieldName(i.EntityField.CodeName))})}return a}get ProviderType(){return
|
|
76
|
+
}`,i=await this.ExecuteGQL(o,{input:r});if(i&&i.RunViews){const n=i.RunViews;for(const[y,D]of n.entries())D.Results=D.Results.map(d=>{let c=JSON.parse(d.Data);return this.ConvertBackToMJFields(c),c});return await this.PostProcessRunViews(n,e,t),n}return null}catch(r){throw m(r),r}}async getEntityNameAndUserView(e,t){let r,s;if(e.EntityName)r=e.EntityName;else if(e.ViewID)s=await me.GetViewEntity(e.ViewID,t),r=s.Entity;else if(e.ViewName)s=await me.GetViewEntityByName(e.ViewName,t),r=s.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:r,v:s}}getViewRunTimeFieldList(e,t,r,s){const a=[],o=new N;if(r.Fields){for(const i of e.PrimaryKeys)r.Fields.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);r.Fields.forEach(i=>{a.push(o.MapFieldName(i))})}else if(s)e.Fields.forEach(i=>{i.IsBinaryFieldType||a.push(o.MapFieldName(i.CodeName))});else{for(const i of e.PrimaryKeys)a.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);t.Columns.forEach(i=>{i.hidden===!1&&!a.find(n=>n.trim().toLowerCase()===i.EntityField?.Name.trim().toLowerCase())&&i.EntityField&&a.push(o.MapFieldName(i.EntityField.CodeName))})}return a}get ProviderType(){return Ie.Network}async GetRecordChanges(e,t){try{const r={EntityName:"Record Changes",ExtraFilter:`RecordID = '${t.Values()}' AND Entity = '${e}'`},s=await this.RunView(r);return s?s.Results.sort((a,o)=>a.ChangedAt>o.ChangedAt?-1:1):null}catch(r){throw m(r),r}}async GetRecordDependencies(e,t){try{const r=R`query GetRecordDependenciesQuery ($entityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
77
77
|
GetRecordDependencies(entityName: $entityName, CompositeKey: $CompositeKey) {
|
|
78
78
|
EntityName
|
|
79
79
|
RelatedEntityName
|
|
@@ -130,7 +130,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
130
130
|
}`,d=R`mutation ${o}${e.EntityInfo.ClassName} ($input: ${i}Input!) {
|
|
131
131
|
${D}
|
|
132
132
|
}
|
|
133
|
-
`;for(let c=0;c<n.length;c++){const u=n[c];let l=u.Value;if(l)switch(u.EntityFieldInfo.TSType){case
|
|
133
|
+
`;for(let c=0;c<n.length;c++){const u=n[c];let l=u.Value;if(l)switch(u.EntityFieldInfo.TSType){case p.Date:l=l.getTime();break;case p.Boolean:typeof l!="boolean"&&(l=parseInt(l)!==0);break;case p.Number:if(typeof l!="number"){const f=Number(l);isNaN(f)||(l=f)}break}l===null&&u.EntityFieldInfo.AllowsNull===!1&&(u.EntityFieldInfo.DefaultValue!==null?l=u.EntityFieldInfo.DefaultValue:u.FieldType===p.Number||u.FieldType===p.Boolean?l=0:l=""),a.input[u.CodeName]=l}if(o.trim().toLowerCase()==="update"&&r.SkipOldValuesCheck===!1){const c=[];e.Fields.forEach(u=>{let l=null;u.OldValue!==null&&u.OldValue!==void 0&&(u.EntityFieldInfo.TSType===p.Date?l=u.OldValue.getTime().toString():u.EntityFieldInfo.TSType===p.Boolean?l=u.OldValue===!0?"1":"0":typeof u.OldValue!="string"?l=u.OldValue.toString():l=u.OldValue),c.push({Key:u.CodeName,Value:l})}),a.input.OldValues___=c}if(e.TransactionGroup){const c=[{varName:"input",inputType:i+"Input!"}];return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ye(e,s.Type==="create"?"Create":"Update",D,a,{mutationName:i,mutationInputTypes:c},(u,l)=>{s.EndedAt=new Date,l&&u?(s.Success=!0,s.NewValues=this.ConvertBackToMJFields(u)):(s.Success=!1,s.Message="Transaction failed")})),!0}else{const c=await this.ExecuteGQL(d,a);if(c&&c[o+e.EntityInfo.ClassName])return s.Success=!0,s.EndedAt=new Date,s.NewValues=this.ConvertBackToMJFields(c[o+e.EntityInfo.ClassName]),s.NewValues;throw new Error(`Save failed for ${e.EntityInfo.ClassName}`)}}catch(a){return s.Success=!1,s.EndedAt=new Date,s.Message=a.response?.errors?.length>0?a.response.errors[0].message:a.message,m(a),null}}async Load(e,t,r=null,s){try{const a={};let o="",i="";for(let c=0;c<t.KeyValuePairs.length;c++){const u=e.Fields.find(w=>w.Name.trim().toLowerCase()===t.KeyValuePairs[c].FieldName.trim().toLowerCase()).EntityFieldInfo,l=t.GetValueByIndex(c),f=u.GraphQLType;if(i.length>0&&(i+=", "),i+=`$${u.CodeName}: ${f}!`,o.length>0&&(o+=", "),o+=`${u.CodeName}: $${u.CodeName}`,u.TSType===p.Number){if(isNaN(t.GetValueByIndex(c)))throw new Error(`Primary Key value ${l} (${u.Name}) is not a valid number`);a[u.CodeName]=parseInt(l)}else a[u.CodeName]=l}const n=r&&r.length>0?this.getRelatedEntityString(e.EntityInfo,r):"",y=new N,D=R`query Single${e.EntityInfo.ClassName}${n.length>0?"Full":""} (${i}) {
|
|
134
134
|
${e.EntityInfo.ClassName}(${o}) {
|
|
135
135
|
${e.Fields.filter(c=>!c.EntityFieldInfo.IsBinaryFieldType).map(c=>c.EntityFieldInfo.Name.trim().toLowerCase().startsWith("__mj_")?c.CodeName.replace("__mj_","_mj__"):c.CodeName).join(`
|
|
136
136
|
`)}
|
|
@@ -149,7 +149,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
149
149
|
`,c=R`mutation ${D} (${n}, $options___: DeleteOptionsInput!) {
|
|
150
150
|
${d}
|
|
151
151
|
}
|
|
152
|
-
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ye(e,"Delete",d,a,{mutationName:D,mutationInputTypes:o},(u,l)=>{if(s.EndedAt=new Date,l&&u){let f=!0;for(const w of e.PrimaryKey.KeyValuePairs)w.Value!==u[w.FieldName]&&(f=!1);f?s.Success=!0:(s.Success=!1,s.Message="Transaction failed to commit")}else s.Success=!1,s.Message="Transaction failed to commit"})),!0;{const u=await this.ExecuteGQL(c,a);if(u&&u[D]){const l=u[D];for(let f of e.PrimaryKey.KeyValuePairs){let w=l[f.FieldName],
|
|
152
|
+
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ye(e,"Delete",d,a,{mutationName:D,mutationInputTypes:o},(u,l)=>{if(s.EndedAt=new Date,l&&u){let f=!0;for(const w of e.PrimaryKey.KeyValuePairs)w.Value!==u[w.FieldName]&&(f=!1);f?s.Success=!0:(s.Success=!1,s.Message="Transaction failed to commit")}else s.Success=!1,s.Message="Transaction failed to commit"})),!0;{const u=await this.ExecuteGQL(c,a);if(u&&u[D]){const l=u[D];for(let f of e.PrimaryKey.KeyValuePairs){let w=l[f.FieldName],I=f.Value;if(typeof I=="number"&&(I=I.toString()),typeof w=="number"&&(w=w.toString()),I!==w)throw new Error(`Primary key value mismatch in server Delete response. Field: ${f.FieldName}, Original: ${I}, Returned: ${w}`)}return s.Success=!0,s.EndedAt=new Date,!0}else throw new Error(`Delete failed for ${e.EntityInfo.Name}: ${e.PrimaryKey.ToString()} `)}}catch(a){return s.EndedAt=new Date,s.Success=!1,s.Message=a.response?.errors?.length>0?a.response.errors[0].message:a.message,m(a),!1}}async GetDatasetByName(e,t){const r=R`query GetDatasetByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
153
153
|
GetDatasetByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
154
154
|
DatasetID
|
|
155
155
|
DatasetName
|
|
@@ -207,7 +207,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
207
207
|
ErrorMessage
|
|
208
208
|
Result
|
|
209
209
|
}
|
|
210
|
-
}`,r=await this.ExecuteGQL(t,{DataContextItemID:e});if(r&&r.GetDataContextItemData){if(r.GetDataContextItemData.Success)return JSON.parse(r.GetDataContextItemData.Result);throw new Error(r.GetDataContextItemData.ErrorMessage)}else throw new Error("GraphQL query failed")}catch(t){throw m(t),t}}static async ExecuteGQL(e,t,r=!0){return h.Instance.ExecuteGQL(e,t,r)}async ExecuteGQL(e,t,r=!0){try{return await this._client.request(e,t)}catch(s){if(s&&s.response&&s.response.errors?.length>0)if(s.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(r)return await this.RefreshToken(),await this.ExecuteGQL(e,t,!1);throw m("JWT_EXPIRED and refreshTokenIfNeeded is false"),s}else throw s;else throw m(s),s}}async RefreshToken(){if(this._configData.Data.RefreshTokenFunction){const e=await this._configData.Data.RefreshTokenFunction();if(e)this._configData.Token=e,this._client=this.CreateNewGraphQLClient(this._configData.URL,this._configData.Token,this._sessionId,this._configData.MJAPIKey);else throw new Error("Refresh token function returned null or undefined token")}else throw new Error("No refresh token function provided")}static async RefreshToken(){return h.Instance.RefreshToken()}CreateNewGraphQLClient(e,t,r,s){const a={"x-session-id":r};return t&&(a.authorization="Bearer "+t),s&&(a["x-mj-api-key"]=s),new ue(e,{headers:a})}userInfoString(){return this.infoString(new le(null,null))}userRoleInfoString(){return this.infoString(new
|
|
210
|
+
}`,r=await this.ExecuteGQL(t,{DataContextItemID:e});if(r&&r.GetDataContextItemData){if(r.GetDataContextItemData.Success)return JSON.parse(r.GetDataContextItemData.Result);throw new Error(r.GetDataContextItemData.ErrorMessage)}else throw new Error("GraphQL query failed")}catch(t){throw m(t),t}}static async ExecuteGQL(e,t,r=!0){return h.Instance.ExecuteGQL(e,t,r)}async ExecuteGQL(e,t,r=!0){try{return await this._client.request(e,t)}catch(s){if(s&&s.response&&s.response.errors?.length>0)if(s.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(r)return await this.RefreshToken(),await this.ExecuteGQL(e,t,!1);throw m("JWT_EXPIRED and refreshTokenIfNeeded is false"),s}else throw s;else throw m(s),s}}async RefreshToken(){if(this._configData.Data.RefreshTokenFunction){const e=await this._configData.Data.RefreshTokenFunction();if(e)this._configData.Token=e,this._client=this.CreateNewGraphQLClient(this._configData.URL,this._configData.Token,this._sessionId,this._configData.MJAPIKey);else throw new Error("Refresh token function returned null or undefined token")}else throw new Error("No refresh token function provided")}static async RefreshToken(){return h.Instance.RefreshToken()}CreateNewGraphQLClient(e,t,r,s){const a={"x-session-id":r};return t&&(a.authorization="Bearer "+t),s&&(a["x-mj-api-key"]=s),new ue(e,{headers:a})}userInfoString(){return this.infoString(new le(null,null))}userRoleInfoString(){return this.infoString(new pe(null))}infoString(e){let t="";const r=Object.keys(e);for(const s of r)s.startsWith("__mj_")?t+=s.replace("__mj_","_mj__")+`
|
|
211
211
|
`:s.startsWith("_")||(t+=s+`
|
|
212
212
|
`);return t}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new G),this._localStorageProvider}get Metadata(){return this}subscribe(e,t){return this._wsClient||(this._wsClient=De({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}})),new de(r=>{const s=this._wsClient.subscribe({query:e,variables:t},{next:a=>{r.next(a.data)},error:a=>{r.error(a)},complete:()=>{r.complete()}});return()=>{s()}})}PushStatusUpdates(e=null){e||(e=this.sessionId),this._wsClient||(this._wsClient=De({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}}));const t=this._pushStatusRequests.find(a=>a.sessionId===e);if(t)return t.observable;const r=R`subscription StatusUpdates($sessionId: String!) {
|
|
213
213
|
statusUpdates(sessionId: $sessionId) {
|
|
@@ -216,7 +216,7 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
216
216
|
sessionId
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
`,s=new de(a=>(this._wsClient.subscribe({query:r,variables:{sessionId:e}},{next:o=>a.next(o.data.statusUpdates),error:o=>a.error(o),complete:()=>a.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:s}),s}};S(h,"GraphQLDataProvider");let $=h;const j=class j{constructor(){this._localStorage={}}async GetItem(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)?t(this._localStorage[e]):t(null)})}async SetItem(e,t){return new Promise(r=>{this._localStorage[e]=t,r()})}async Remove(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],t()})}};S(j,"BrowserStorageProviderBase");let P=j;const Qe="MJ_Metadata",E="Metadata_KVPairs",W=class W extends P{constructor(){super(),this.dbPromise=Ne(Qe,1,{upgrade(e){e.objectStoreNames.contains(E)||e.createObjectStore(E)}})}async setItem(e,t){const s=(await this.dbPromise).transaction(E,"readwrite");await s.objectStore(E).put(t,e),await s.done}async getItem(e){return await(await this.dbPromise).transaction(E).objectStore(E).get(e)}async remove(e){const r=(await this.dbPromise).transaction(E,"readwrite");await r.objectStore(E).delete(e),await r.done}};S(W,"BrowserIndexedDBStorageProvider");let G=W;async function Pe(g){const e=new $;return Ee(e),await e.Config(g),Ve.Instance.RaiseEvent({event:$e.LoggedIn,eventCode:null,component:this,args:null}),e}S(Pe,"setupGraphQLClient");const z=class z{};S(z,"SyncRolesAndUsersResult");let U=z;const H=class H{};S(H,"RoleInput");let
|
|
219
|
+
`,s=new de(a=>(this._wsClient.subscribe({query:r,variables:{sessionId:e}},{next:o=>a.next(o.data.statusUpdates),error:o=>a.error(o),complete:()=>a.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:s}),s}};S(h,"GraphQLDataProvider");let $=h;const j=class j{constructor(){this._localStorage={}}async GetItem(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)?t(this._localStorage[e]):t(null)})}async SetItem(e,t){return new Promise(r=>{this._localStorage[e]=t,r()})}async Remove(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],t()})}};S(j,"BrowserStorageProviderBase");let P=j;const Qe="MJ_Metadata",E="Metadata_KVPairs",W=class W extends P{constructor(){super(),this.dbPromise=Ne(Qe,1,{upgrade(e){e.objectStoreNames.contains(E)||e.createObjectStore(E)}})}async setItem(e,t){const s=(await this.dbPromise).transaction(E,"readwrite");await s.objectStore(E).put(t,e),await s.done}async getItem(e){return await(await this.dbPromise).transaction(E).objectStore(E).get(e)}async remove(e){const r=(await this.dbPromise).transaction(E,"readwrite");await r.objectStore(E).delete(e),await r.done}};S(W,"BrowserIndexedDBStorageProvider");let G=W;async function Pe(g){const e=new $;return Ee(e),await e.Config(g),Ve.Instance.RaiseEvent({event:$e.LoggedIn,eventCode:null,component:this,args:null}),e}S(Pe,"setupGraphQLClient");const z=class z{};S(z,"SyncRolesAndUsersResult");let U=z;const H=class H{};S(H,"RoleInput");let v=H;const X=class X{};S(X,"UserInput");let T=X;const Z=class Z{};S(Z,"RolesAndUsersInput");let x=Z;var Re=(g=>(g.Create="Create",g.Update="Update",g.CreateOrUpdate="CreateOrUpdate",g.Delete="Delete",g.DeleteWithFilter="DeleteWithFilter",g))(Re||{});const Y=class Y{};S(Y,"ActionItemInput");let F=Y;const ee=class ee{constructor(){this.Results=[]}};S(ee,"SyncDataResult");let M=ee;const te=class te{};S(te,"ActionItemOutput");let L=te;const re=class re{get Client(){return this._client}constructor(e,t,r,s){const a={"x-session-id":r};t&&(a.authorization="Bearer "+t),s&&(a["x-mj-api-key"]=s),this._client=new ue(e,{headers:a})}async GetData(e,t){try{const s=await this.Client.request(`query GetData($input: GetDataInputType!) {
|
|
220
220
|
GetData(input: $input) {
|
|
221
221
|
Success
|
|
222
222
|
ErrorMessages
|
|
@@ -385,7 +385,6 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
385
385
|
QueryID
|
|
386
386
|
EntityID
|
|
387
387
|
EntityName
|
|
388
|
-
Sequence
|
|
389
388
|
}
|
|
390
389
|
Permissions {
|
|
391
390
|
ID
|
|
@@ -457,5 +456,5 @@ var we=Object.defineProperty;var S=(g,e)=>we(g,"name",{value:e,configurable:!0})
|
|
|
457
456
|
ResultData
|
|
458
457
|
}
|
|
459
458
|
}
|
|
460
|
-
`;return await this._dataProvider.ExecuteGQL(t,{input:e})}processEntityActionResult(e){if(!e?.RunEntityAction)throw new Error("Invalid response from server");let t={};try{e.RunEntityAction.ResultData&&(t=JSON.parse(e.RunEntityAction.ResultData))}catch(r){m(`Failed to parse entity action result data: ${r}`)}return{Success:e.RunEntityAction.Success,Message:e.RunEntityAction.Message,RunParams:null,LogEntry:null,...t}}handleEntityActionError(e){const t=e;return m(`Error running entity action: ${t}`),{Success:!1,Message:`Error: ${t.message}`,RunParams:null,LogEntry:null}}};S(oe,"GraphQLActionClient");let O=oe;export{F as ActionItemInput,L as ActionItemOutput,N as FieldMapper,q as GetDataOutput,O as GraphQLActionClient,$ as GraphQLDataProvider,Q as GraphQLProviderConfigData,A as GraphQLSystemUserClient,V as GraphQLTransactionGroup,
|
|
459
|
+
`;return await this._dataProvider.ExecuteGQL(t,{input:e})}processEntityActionResult(e){if(!e?.RunEntityAction)throw new Error("Invalid response from server");let t={};try{e.RunEntityAction.ResultData&&(t=JSON.parse(e.RunEntityAction.ResultData))}catch(r){m(`Failed to parse entity action result data: ${r}`)}return{Success:e.RunEntityAction.Success,Message:e.RunEntityAction.Message,RunParams:null,LogEntry:null,...t}}handleEntityActionError(e){const t=e;return m(`Error running entity action: ${t}`),{Success:!1,Message:`Error: ${t.message}`,RunParams:null,LogEntry:null}}};S(oe,"GraphQLActionClient");let O=oe;export{F as ActionItemInput,L as ActionItemOutput,N as FieldMapper,q as GetDataOutput,O as GraphQLActionClient,$ as GraphQLDataProvider,Q as GraphQLProviderConfigData,A as GraphQLSystemUserClient,V as GraphQLTransactionGroup,v as RoleInput,x as RolesAndUsersInput,B as SimpleRemoteEntity,b as SimpleRemoteEntityField,_ as SimpleRemoteEntityOutput,Re as SyncDataAction,M as SyncDataResult,U as SyncRolesAndUsersResult,T as UserInput,Be as gql,Pe as setupGraphQLClient};
|
|
461
460
|
//# sourceMappingURL=index.mjs.map
|