@memberjunction/graphql-dataprovider 2.73.0 → 2.75.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 +61 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +380 -19
- package/dist/index.d.mts +380 -19
- package/dist/index.mjs +69 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var we=Object.defineProperty;var f=(p,e)=>we(p,"name",{value:e,configurable:!0});import{gql as w,GraphQLClient as ue}from"graphql-request";import{gql as qe}from"graphql-request";import{TransactionGroupBase as fe,TransactionResult as Se,ProviderConfigDataBase as he,ProviderBase as pe,LogError as D,UserInfo as le,ProviderType as Ee,BaseEntityResult as ce,EntityFieldTSType as E,TransactionItem as ye,UserRoleInfo as ge,SetProvider as Ie}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 b=class b{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,s])=>s===e)?.[0]??e}ReverseMapFields(e){const t=Object.fromEntries(Object.entries(this._fieldMap).map(([s,r])=>[r,s]));for(const s in e)s in t&&(e[t[s]]=e[s],delete e[s]);return e}};f(b,"FieldMapper");let N=b;const k=class k extends fe{constructor(e){super(),this._provider=e}async HandleSubmit(){const e=w`
|
|
2
2
|
mutation ExecuteTransactionGroup($group: TransactionInputType!) {
|
|
3
3
|
ExecuteTransactionGroup(group: $group) {
|
|
4
4
|
Success
|
|
@@ -6,15 +6,15 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
6
6
|
ResultsJSON
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,t=[];for(const a of this.PendingTransactions)t.push({EntityName:a.BaseEntity.EntityInfo.Name,EntityObjectJSON:await a.BaseEntity.GetDataObjectJSON(),OperationType:a.OperationType});const s={group:{Items:t,Variables:this.Variables.map(a=>({Name:a.Name,ItemIndex:this.MapVariableEntityObjectToPosition(a),FieldName:a.FieldName,Type:a.Type}))}},r=await this._provider.ExecuteGQL(e,s);if(r&&r.ExecuteTransactionGroup){const a=r.ExecuteTransactionGroup,o=[];for(let
|
|
9
|
+
`,t=[];for(const a of this.PendingTransactions)t.push({EntityName:a.BaseEntity.EntityInfo.Name,EntityObjectJSON:await a.BaseEntity.GetDataObjectJSON(),OperationType:a.OperationType});const s={group:{Items:t,Variables:this.Variables.map(a=>({Name:a.Name,ItemIndex:this.MapVariableEntityObjectToPosition(a),FieldName:a.FieldName,Type:a.Type}))}},r=await this._provider.ExecuteGQL(e,s);if(r&&r.ExecuteTransactionGroup){const a=r.ExecuteTransactionGroup,o=[];for(let i=0;i<this.PendingTransactions.length;i++){const n=a.ResultsJSON[i],c=C(n),d=this.PendingTransactions[i];o.push(new Se(d,c,c!==null))}return o}else throw new Error("Failed to execute transaction group")}};f(k,"GraphQLTransactionGroup");let V=k;const J=class J extends he{get Token(){return this.Data.Token}set Token(e){this.Data.Token=e}get MJAPIKey(){return this.Data.MJAPIKey}set MJAPIKey(e){this.Data.MJAPIKey=e}get URL(){return this.Data.URL}get WSURL(){return this.Data.WSURL}get RefreshTokenFunction(){return this.Data.RefreshFunction}constructor(e,t,s,r,a,o,i,n){super({Token:e,URL:t,WSURL:s,MJAPIKey:n,RefreshTokenFunction:r},a,o,i)}};f(J,"GraphQLProviderConfigData");let G=J;const h=class h extends pe{constructor(){super(),this._innerCurrentUserQueryString=`CurrentUser {
|
|
10
10
|
${this.userInfoString()}
|
|
11
11
|
UserRoles_UserIDArray {
|
|
12
12
|
${this.userRoleInfoString()}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
`,this._currentUserQuery=
|
|
15
|
+
`,this._currentUserQuery=w`query CurrentUserAndRoles {
|
|
16
16
|
${this._innerCurrentUserQueryString}
|
|
17
|
-
}`,this._wsClient=null,this._pushStatusRequests=[],
|
|
17
|
+
}`,this._wsClient=null,this._pushStatusRequests=[],h._instance||(h._instance=this)}static get Instance(){return h._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 Ce()}get LocalStoragePrefix(){if(this._configData===void 0||this._configData.URL===void 0)throw new Error("GraphQLDataProvider: ConfigData is not set. Please call Config() first.");return this._configData.URL.replace(/[^a-zA-Z0-9]/g,"_")+"."}async GetStoredSessionID(){try{const e=this.LocalStorageProvider;if(e){const t=this.LocalStoragePrefix+"sessionId";return await e.GetItem(t)}return null}catch(e){return console.error("Error retrieving session ID from local storage:",e),null}}async SaveStoredSessionID(e){try{const t=this.LocalStorageProvider;if(t){const s=this.LocalStoragePrefix+"sessionId";await t.SetItem(s,e)}}catch{}}async GetPreferredUUID(e){const t=await this.GetStoredSessionID();return e||!t?this.GenerateUUID():t}async Config(e,t,s){try{return t?(this._configData=e,this._sessionId=await this.GetPreferredUUID(s),this._client=this.CreateNewGraphQLClient(e.URL,e.Token,this._sessionId,e.MJAPIKey),await this.SaveStoredSessionID(this._sessionId)):(h.Instance._configData=e,h.Instance._sessionId===void 0&&(h.Instance._sessionId=await this.GetPreferredUUID(s)),h.Instance._client||(h.Instance._client=this.CreateNewGraphQLClient(e.URL,e.Token,h.Instance._sessionId,e.MJAPIKey)),await h.Instance.SaveStoredSessionID(h.Instance._sessionId)),super.Config(e)}catch(r){throw D(r),r}}get sessionId(){return this._sessionId}get AllowRefresh(){return!0}async GetCurrentUser(){const e=await this.ExecuteGQL(this._currentUserQuery,null);if(e){const t=this.ConvertBackToMJFields(e.CurrentUser),s=t.UserRoles_UserIDArray.map(r=>this.ConvertBackToMJFields(r));return t.UserRoles_UserIDArray=s,new le(this,{...t,UserRoles:s})}}async RunReport(e,t){const s=w`
|
|
18
18
|
query GetReportDataQuery ($ReportID: String!) {
|
|
19
19
|
GetReportData(ReportID: $ReportID) {
|
|
20
20
|
Success
|
|
@@ -23,30 +23,32 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
23
23
|
ExecutionTime
|
|
24
24
|
ErrorMessage
|
|
25
25
|
}
|
|
26
|
-
}`,r=await this.ExecuteGQL(s,{ReportID:e.ReportID});if(r&&r.GetReportData)return{ReportID:e.ReportID,Success:r.GetReportData.Success,Results:JSON.parse(r.GetReportData.Results),RowCount:r.GetReportData.RowCount,ExecutionTime:r.GetReportData.ExecutionTime,ErrorMessage:r.GetReportData.ErrorMessage}}async RunQuery(e,t){if(e.QueryID)return this.RunQueryByID(e.QueryID,e.CategoryID,e.CategoryName,t);if(e.QueryName)return this.RunQueryByName(e.QueryName,e.CategoryID,e.CategoryName,t);throw new Error("No QueryID or QueryName provided to RunQuery")}async RunQueryByID(e,t,s,r){const
|
|
27
|
-
query GetQueryDataQuery($QueryID: String!, $CategoryID: String, $CategoryName: String) {
|
|
28
|
-
GetQueryData(QueryID: $QueryID, CategoryID: $CategoryID, CategoryName: $CategoryName) {
|
|
26
|
+
}`,r=await this.ExecuteGQL(s,{ReportID:e.ReportID});if(r&&r.GetReportData)return{ReportID:e.ReportID,Success:r.GetReportData.Success,Results:JSON.parse(r.GetReportData.Results),RowCount:r.GetReportData.RowCount,ExecutionTime:r.GetReportData.ExecutionTime,ErrorMessage:r.GetReportData.ErrorMessage}}async RunQuery(e,t){if(e.QueryID)return this.RunQueryByID(e.QueryID,e.CategoryID,e.CategoryName,t,e.Parameters,e.MaxRows,e.StartRow);if(e.QueryName)return this.RunQueryByName(e.QueryName,e.CategoryID,e.CategoryName,t,e.Parameters,e.MaxRows,e.StartRow);throw new Error("No QueryID or QueryName provided to RunQuery")}async RunQueryByID(e,t,s,r,a,o,i){const n=w`
|
|
27
|
+
query GetQueryDataQuery($QueryID: String!, $CategoryID: String, $CategoryName: String, $Parameters: JSONObject, $MaxRows: Int, $StartRow: Int) {
|
|
28
|
+
GetQueryData(QueryID: $QueryID, CategoryID: $CategoryID, CategoryName: $CategoryName, Parameters: $Parameters, MaxRows: $MaxRows, StartRow: $StartRow) {
|
|
29
29
|
${this.QueryReturnFieldList}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
`,
|
|
33
|
-
query GetQueryDataByNameQuery($QueryName: String!, $CategoryID: String, $CategoryName: String) {
|
|
34
|
-
GetQueryDataByName(QueryName: $QueryName, CategoryID: $CategoryID, CategoryName: $CategoryName) {
|
|
32
|
+
`,c={QueryID:e};t!==void 0&&(c.CategoryID=t),s!==void 0&&(c.CategoryName=s),a!==void 0&&(c.Parameters=a),o!==void 0&&(c.MaxRows=o),i!==void 0&&(c.StartRow=i);const d=await this.ExecuteGQL(n,c);if(d&&d.GetQueryData)return this.TransformQueryPayload(d.GetQueryData)}async RunQueryByName(e,t,s,r,a,o,i){const n=w`
|
|
33
|
+
query GetQueryDataByNameQuery($QueryName: String!, $CategoryID: String, $CategoryName: String, $Parameters: JSONObject, $MaxRows: Int, $StartRow: Int) {
|
|
34
|
+
GetQueryDataByName(QueryName: $QueryName, CategoryID: $CategoryID, CategoryName: $CategoryName, Parameters: $Parameters, MaxRows: $MaxRows, StartRow: $StartRow) {
|
|
35
35
|
${this.QueryReturnFieldList}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
38
|
+
`,c={QueryName:e};t!==void 0&&(c.CategoryID=t),s!==void 0&&(c.CategoryName=s),a!==void 0&&(c.Parameters=a),o!==void 0&&(c.MaxRows=o),i!==void 0&&(c.StartRow=i);const d=await this.ExecuteGQL(n,c);if(d&&d.GetQueryDataByName)return this.TransformQueryPayload(d.GetQueryDataByName)}get QueryReturnFieldList(){return`
|
|
39
39
|
Success
|
|
40
40
|
QueryID
|
|
41
41
|
QueryName
|
|
42
42
|
Results
|
|
43
43
|
RowCount
|
|
44
|
+
TotalRowCount
|
|
44
45
|
ExecutionTime
|
|
45
|
-
ErrorMessage
|
|
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 D(`Error transforming query payload: ${t}`),null}}async RunView(e,t){try{let s="",r="";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 c=!1;e.ViewID?(s=`Run${n.ClassName}ViewByID`,r="RunViewByIDInput",a.ViewID=e.ViewID):e.ViewName?(s=`Run${n.ClassName}ViewByName`,r="RunViewByNameInput",a.ViewName=e.ViewName):(c=!0,s=`Run${n.ClassName}DynamicView`,r="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?e.MaxRows:0,a.ForceAuditLog=e.ForceAuditLog?e.ForceAuditLog:!1,a.ResultType=e.ResultType?e.ResultType:"simple",e.AuditLogDescription&&e.AuditLogDescription.length>0&&(a.AuditLogDescription=e.AuditLogDescription),c||(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,c),m=w`
|
|
46
48
|
query RunViewQuery ($input: ${r}!) {
|
|
47
49
|
${s}(input: $input) {
|
|
48
50
|
Results {
|
|
49
|
-
${
|
|
51
|
+
${d.join(`
|
|
50
52
|
`)}
|
|
51
53
|
}
|
|
52
54
|
UserViewRunID
|
|
@@ -56,7 +58,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
56
58
|
Success
|
|
57
59
|
ErrorMessage
|
|
58
60
|
}
|
|
59
|
-
}`,
|
|
61
|
+
}`,y=await this.ExecuteGQL(m,{input:a});if(y&&y[s]){const u=y[s].Results;if(u&&u.length>0){const l=n.Fields.filter(R=>R.CodeName!==R.Name&&R.CodeName!==void 0);u.forEach(R=>{this.ConvertBackToMJFields(R),l.forEach(S=>{R[S.Name]=R[S.CodeName]})})}return y[s]}}else throw"No parameters passed to RunView";return null}catch(s){throw D(s),s}}async RunViews(e,t){try{let s=[],r=[],a=[];for(const n of e){let c="",d="";const m={};let y=null,u=null;if(n.ViewEntity)u=n.ViewEntity,y=u.Get("Entity");else{const{entityName:S,v:I}=await this.getEntityNameAndUserView(n,t);u=I,y=S}const l=this.Entities.find(S=>S.Name===y);if(!l)throw new Error(`Entity ${y} not found in metadata`);r.push(l);let R=!1;n.ViewID?(c=`Run${l.ClassName}ViewByID`,d="RunViewByIDInput",m.ViewID=n.ViewID):n.ViewName?(c=`Run${l.ClassName}ViewByName`,d="RunViewByNameInput",m.ViewName=n.ViewName):(R=!0,c=`Run${l.ClassName}DynamicView`,d="RunDynamicViewInput",m.EntityName=n.EntityName),m.ExtraFilter=n.ExtraFilter||"",m.OrderBy=n.OrderBy||"",m.UserSearchString=n.UserSearchString||"",m.Fields=n.Fields,m.IgnoreMaxRows=n.IgnoreMaxRows||!1,m.MaxRows=n.MaxRows||0,m.ForceAuditLog=n.ForceAuditLog||!1,m.ResultType=n.ResultType||"simple",n.AuditLogDescription&&n.AuditLogDescription.length>0&&(m.AuditLogDescription=n.AuditLogDescription),R||(m.ExcludeUserViewRunID=n.ExcludeUserViewRunID||"",m.ExcludeDataFromAllPriorViewRuns=n.ExcludeDataFromAllPriorViewRuns||!1,m.OverrideExcludeFilter=n.OverrideExcludeFilter||"",m.SaveViewResults=n.SaveViewResults||!1),s.push(m),a.push(...this.getViewRunTimeFieldList(l,u,n,R))}const o=w`
|
|
60
62
|
query RunViewsQuery ($input: [RunViewGenericInput!]!) {
|
|
61
63
|
RunViews(input: $input) {
|
|
62
64
|
Results {
|
|
@@ -71,7 +73,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
71
73
|
Success
|
|
72
74
|
ErrorMessage
|
|
73
75
|
}
|
|
74
|
-
}`,
|
|
76
|
+
}`,i=await this.ExecuteGQL(o,{input:s});if(i&&i.RunViews){const n=i.RunViews;for(const[c,d]of n.entries())d.Results=d.Results.map(m=>{let y=JSON.parse(m.Data);return this.ConvertBackToMJFields(y),y});return n}return null}catch(s){throw D(s),s}}async getEntityNameAndUserView(e,t){let s,r;if(e.EntityName)s=e.EntityName;else if(e.ViewID)r=await me.GetViewEntity(e.ViewID,t),s=r.Entity;else if(e.ViewName)r=await me.GetViewEntityByName(e.ViewName,t),s=r.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:s,v:r}}getViewRunTimeFieldList(e,t,s,r){const a=[],o=new N;if(s.Fields){for(const i of e.PrimaryKeys)s.Fields.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);s.Fields.forEach(i=>{a.push(o.MapFieldName(i))})}else if(r)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 Ee.Network}async GetRecordChanges(e,t){try{const s={EntityName:"Record Changes",ExtraFilter:`RecordID = '${t.Values()}' AND Entity = '${e}'`},r=await this.RunView(s);return r?r.Results.sort((a,o)=>a.ChangedAt>o.ChangedAt?-1:1):null}catch(s){throw D(s),s}}async GetRecordDependencies(e,t){try{const s=w`query GetRecordDependenciesQuery ($entityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
75
77
|
GetRecordDependencies(entityName: $entityName, CompositeKey: $CompositeKey) {
|
|
76
78
|
EntityName
|
|
77
79
|
RelatedEntityName
|
|
@@ -83,7 +85,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
|
-
}`,r={entityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}};return(await this.ExecuteGQL(s,r))?.GetRecordDependencies}catch(s){throw
|
|
88
|
+
}`,r={entityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}};return(await this.ExecuteGQL(s,r))?.GetRecordDependencies}catch(s){throw D(s),s}}ensureKeyValuePairValueIsString(e){return e.map(t=>({FieldName:t.FieldName,Value:t.Value.toString()}))}async GetRecordDuplicates(e,t){if(!e)return null;const s=w`query GetRecordDuplicatesQuery ($params: PotentialDuplicateRequestType!) {
|
|
87
89
|
GetRecordDuplicates(params: $params) {
|
|
88
90
|
Status
|
|
89
91
|
ErrorMessage
|
|
@@ -105,7 +107,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
}`;let r={EntityID:e.EntityID,EntityDocumentID:e.EntityDocumentID,ListID:e.ListID,ProbabilityScore:e.ProbabilityScore,Options:e.Options,RecordIDs:e.RecordIDs.map(o=>o.Copy())};const a=await this.ExecuteGQL(s,{params:r});if(a&&a.GetRecordDuplicates)return a.GetRecordDuplicates}async MergeRecords(e){const t=this.Entities.find(s=>s.Name.trim().toLowerCase()===e.EntityName.trim().toLowerCase());if(!t||!t.AllowRecordMerge)throw new Error(`Entity ${e.EntityName} does not allow record merging, check the AllowRecordMerge property in the entity metadata`);try{const s=
|
|
110
|
+
}`;let r={EntityID:e.EntityID,EntityDocumentID:e.EntityDocumentID,ListID:e.ListID,ProbabilityScore:e.ProbabilityScore,Options:e.Options,RecordIDs:e.RecordIDs.map(o=>o.Copy())};const a=await this.ExecuteGQL(s,{params:r});if(a&&a.GetRecordDuplicates)return a.GetRecordDuplicates}async MergeRecords(e){const t=this.Entities.find(s=>s.Name.trim().toLowerCase()===e.EntityName.trim().toLowerCase());if(!t||!t.AllowRecordMerge)throw new Error(`Entity ${e.EntityName} does not allow record merging, check the AllowRecordMerge property in the entity metadata`);try{const s=w`mutation MergeRecordsMutation ($request: RecordMergeRequest!) {
|
|
109
111
|
MergeRecords(request: $request) {
|
|
110
112
|
Success
|
|
111
113
|
OverallStatus
|
|
@@ -122,32 +124,32 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
122
124
|
Message
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
|
-
}`,r={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(o=>({FieldName:o.FieldName,Value:o.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(o=>o.Copy())};return(await this.ExecuteGQL(s,{request:r}))?.MergeRecords}catch(s){return
|
|
126
|
-
${e.Fields.map(c
|
|
127
|
+
}`,r={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(o=>({FieldName:o.FieldName,Value:o.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(o=>o.Copy())};return(await this.ExecuteGQL(s,{request:r}))?.MergeRecords}catch(s){return D(s),{Success:!1,OverallStatus:s&&s.message?s.message:s,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,t,s){const r=new ce;try{e.RegisterTransactionPreprocessing();const a={input:{}},o=e.IsSaved?"Update":"Create";r.StartedAt=new Date,r.Type=e.IsSaved?"update":"create",r.OriginalValues=e.Fields.map(y=>({FieldName:y.CodeName,Value:y.Value})),e.ResultHistory.push(r);const i=`${o}${e.EntityInfo.ClassName}`,n=e.Fields.filter(y=>!y.ReadOnly||y.IsPrimaryKey&&e.IsSaved),c=new N,d=` ${i}(input: $input) {
|
|
128
|
+
${e.Fields.map(y=>c.MapFieldName(y.CodeName)).join(`
|
|
127
129
|
`)}
|
|
128
|
-
}`,
|
|
129
|
-
${
|
|
130
|
+
}`,m=w`mutation ${o}${e.EntityInfo.ClassName} ($input: ${i}Input!) {
|
|
131
|
+
${d}
|
|
130
132
|
}
|
|
131
|
-
`;for(let
|
|
133
|
+
`;for(let y=0;y<n.length;y++){const u=n[y];let l=u.Value;if(l)switch(u.EntityFieldInfo.TSType){case E.Date:l=l.getTime();break;case E.Boolean:typeof l!="boolean"&&(l=parseInt(l)!==0);break;case E.Number:if(typeof l!="number"){const R=Number(l);isNaN(R)||(l=R)}break}l===null&&u.EntityFieldInfo.AllowsNull===!1&&(u.EntityFieldInfo.DefaultValue!==null?l=u.EntityFieldInfo.DefaultValue:u.FieldType===E.Number||u.FieldType===E.Boolean?l=0:l=""),a.input[u.CodeName]=l}if(o.trim().toLowerCase()==="update"&&s.SkipOldValuesCheck===!1){const y=[];e.Fields.forEach(u=>{let l=null;u.OldValue!==null&&u.OldValue!==void 0&&(u.EntityFieldInfo.TSType===E.Date?l=u.OldValue.getTime().toString():u.EntityFieldInfo.TSType===E.Boolean?l=u.OldValue===!0?"1":"0":typeof u.OldValue!="string"?l=u.OldValue.toString():l=u.OldValue),y.push({Key:u.CodeName,Value:l})}),a.input.OldValues___=y}if(e.TransactionGroup){const y=[{varName:"input",inputType:i+"Input!"}];return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ye(e,r.Type==="create"?"Create":"Update",d,a,{mutationName:i,mutationInputTypes:y},(u,l)=>{r.EndedAt=new Date,l&&u?(r.Success=!0,r.NewValues=this.ConvertBackToMJFields(u)):(r.Success=!1,r.Message="Transaction failed")})),!0}else{const y=await this.ExecuteGQL(m,a);if(y&&y[o+e.EntityInfo.ClassName])return r.Success=!0,r.EndedAt=new Date,r.NewValues=this.ConvertBackToMJFields(y[o+e.EntityInfo.ClassName]),r.NewValues;throw new Error(`Save failed for ${e.EntityInfo.ClassName}`)}}catch(a){return r.Success=!1,r.EndedAt=new Date,r.Message=a.response?.errors?.length>0?a.response.errors[0].message:a.message,D(a),null}}async Load(e,t,s=null,r){try{const a={};let o="",i="";for(let y=0;y<t.KeyValuePairs.length;y++){const u=e.Fields.find(S=>S.Name.trim().toLowerCase()===t.KeyValuePairs[y].FieldName.trim().toLowerCase()).EntityFieldInfo,l=t.GetValueByIndex(y),R=u.GraphQLType;if(i.length>0&&(i+=", "),i+=`$${u.CodeName}: ${R}!`,o.length>0&&(o+=", "),o+=`${u.CodeName}: $${u.CodeName}`,u.TSType===E.Number){if(isNaN(t.GetValueByIndex(y)))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=s&&s.length>0?this.getRelatedEntityString(e.EntityInfo,s):"",c=new N,d=w`query Single${e.EntityInfo.ClassName}${n.length>0?"Full":""} (${i}) {
|
|
132
134
|
${e.EntityInfo.ClassName}(${o}) {
|
|
133
|
-
${e.Fields.filter(
|
|
135
|
+
${e.Fields.filter(y=>!y.EntityFieldInfo.IsBinaryFieldType).map(y=>y.EntityFieldInfo.Name.trim().toLowerCase().startsWith("__mj_")?y.CodeName.replace("__mj_","_mj__"):y.CodeName).join(`
|
|
134
136
|
`)}
|
|
135
|
-
${
|
|
137
|
+
${n}
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
|
-
`,
|
|
139
|
-
${
|
|
140
|
-
${o.Fields.map(
|
|
140
|
+
`,m=await this.ExecuteGQL(d,a);return m&&m[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(m[e.EntityInfo.ClassName]):null}catch(a){return D(a),null}}ConvertBackToMJFields(e){return new N().ReverseMapFields(e),e}getRelatedEntityString(e,t){let s="";for(let r=0;r<e.RelatedEntities.length;r++)if(t.indexOf(e.RelatedEntities[r].RelatedEntity)>=0){const a=e.RelatedEntities[r],o=this.Entities.find(n=>n.ID===a.RelatedEntityID);let i="";a.Type.toLowerCase().trim()==="many to many"?i=`${a.RelatedEntityCodeName}_${a.JoinEntityJoinField.replace(/\s/g,"")}`:i=`${a.RelatedEntityCodeName}_${a.RelatedEntityJoinField.replace(/\s/g,"")}`,s+=`
|
|
141
|
+
${i} {
|
|
142
|
+
${o.Fields.map(n=>n.CodeName).join(`
|
|
141
143
|
`)}
|
|
142
144
|
}
|
|
143
|
-
`}return s}async Delete(e,t,s){const r=new ce;try{e.RegisterTransactionPreprocessing(),r.StartedAt=new Date,r.Type="delete",r.OriginalValues=e.Fields.map(u=>({FieldName:u.CodeName,Value:u.Value})),e.ResultHistory.push(r);const a={},o=[];let
|
|
144
|
-
`),
|
|
145
|
-
${
|
|
145
|
+
`}return s}async Delete(e,t,s){const r=new ce;try{e.RegisterTransactionPreprocessing(),r.StartedAt=new Date,r.Type="delete",r.OriginalValues=e.Fields.map(u=>({FieldName:u.CodeName,Value:u.Value})),e.ResultHistory.push(r);const a={},o=[];let i="",n="",c="";for(let u of e.PrimaryKey.KeyValuePairs){const l=e.Fields.find(R=>R.Name.trim().toLowerCase()===u.FieldName.trim().toLowerCase());a[l.CodeName]=l.Value,o.push({varName:l.CodeName,inputType:l.EntityFieldInfo.GraphQLType+"!"}),i.length>0&&(i+=", "),i+=`${l.CodeName}: $${l.CodeName}`,n.length>0&&(n+=", "),n+=`$${l.CodeName}: ${l.EntityFieldInfo.GraphQLType}!`,c.length>0&&(c+=`
|
|
146
|
+
`),c+=`${l.CodeName}`}o.push({varName:"options___",inputType:"DeleteOptionsInput!"}),a.options___=t||{SkipEntityAIActions:!1,SkipEntityActions:!1};const d="Delete"+e.EntityInfo.ClassName,m=w`${d}(${i}, options___: $options___) {
|
|
147
|
+
${c}
|
|
146
148
|
}
|
|
147
|
-
`,
|
|
148
|
-
${
|
|
149
|
+
`,y=w`mutation ${d} (${n}, $options___: DeleteOptionsInput!) {
|
|
150
|
+
${m}
|
|
149
151
|
}
|
|
150
|
-
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ye(e,"Delete",
|
|
152
|
+
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ye(e,"Delete",m,a,{mutationName:d,mutationInputTypes:o},(u,l)=>{if(r.EndedAt=new Date,l&&u){let R=!0;for(const S of e.PrimaryKey.KeyValuePairs)S.Value!==u[S.FieldName]&&(R=!1);R?r.Success=!0:(r.Success=!1,r.Message="Transaction failed to commit")}else r.Success=!1,r.Message="Transaction failed to commit"})),!0;{const u=await this.ExecuteGQL(y,a);if(u&&u[d]){const l=u[d];for(let R of e.PrimaryKey.KeyValuePairs){let S=l[R.FieldName],I=R.Value;if(typeof I=="number"&&(I=I.toString()),typeof S=="number"&&(S=S.toString()),I!==S)throw new Error(`Primary key value mismatch in server Delete response. Field: ${R.FieldName}, Original: ${I}, Returned: ${S}`)}return r.Success=!0,r.EndedAt=new Date,!0}else throw new Error(`Delete failed for ${e.EntityInfo.Name}: ${e.PrimaryKey.ToString()} `)}}catch(a){return r.EndedAt=new Date,r.Success=!1,r.Message=a.response?.errors?.length>0?a.response.errors[0].message:a.message,D(a),!1}}async GetDatasetByName(e,t){const s=w`query GetDatasetByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
151
153
|
GetDatasetByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
152
154
|
DatasetID
|
|
153
155
|
DatasetName
|
|
@@ -156,7 +158,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
156
158
|
LatestUpdateDate
|
|
157
159
|
Results
|
|
158
160
|
}
|
|
159
|
-
}`,r=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:t});return r&&r.GetDatasetByName&&r.GetDatasetByName.Success?{DatasetID:r.GetDatasetByName.DatasetID,DatasetName:r.GetDatasetByName.DatasetName,Success:r.GetDatasetByName.Success,Status:r.GetDatasetByName.Status,LatestUpdateDate:new Date(r.GetDatasetByName.LatestUpdateDate),Results:JSON.parse(r.GetDatasetByName.Results)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,Results:null}}async GetDatasetStatusByName(e,t){const s=
|
|
161
|
+
}`,r=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:t});return r&&r.GetDatasetByName&&r.GetDatasetByName.Success?{DatasetID:r.GetDatasetByName.DatasetID,DatasetName:r.GetDatasetByName.DatasetName,Success:r.GetDatasetByName.Success,Status:r.GetDatasetByName.Status,LatestUpdateDate:new Date(r.GetDatasetByName.LatestUpdateDate),Results:JSON.parse(r.GetDatasetByName.Results)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,Results:null}}async GetDatasetStatusByName(e,t){const s=w`query GetDatasetStatusByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
160
162
|
GetDatasetStatusByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
161
163
|
DatasetID
|
|
162
164
|
DatasetName
|
|
@@ -165,22 +167,22 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
165
167
|
LatestUpdateDate
|
|
166
168
|
EntityUpdateDates
|
|
167
169
|
}
|
|
168
|
-
}`,r=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:t});return r&&r.GetDatasetStatusByName&&r.GetDatasetStatusByName.Success?{DatasetID:r.GetDatasetStatusByName.DatasetID,DatasetName:r.GetDatasetStatusByName.DatasetName,Success:r.GetDatasetStatusByName.Success,Status:r.GetDatasetStatusByName.Status,LatestUpdateDate:new Date(r.GetDatasetStatusByName.LatestUpdateDate),EntityUpdateDates:JSON.parse(r.GetDatasetStatusByName.EntityUpdateDates)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,EntityUpdateDates:null}}async CreateTransactionGroup(){return new V(this)}async GetRecordFavoriteStatus(e,t,s){if(!s.Validate().IsValid)return!1;const a=this.Entities.find(
|
|
170
|
+
}`,r=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:t});return r&&r.GetDatasetStatusByName&&r.GetDatasetStatusByName.Success?{DatasetID:r.GetDatasetStatusByName.DatasetID,DatasetName:r.GetDatasetStatusByName.DatasetName,Success:r.GetDatasetStatusByName.Success,Status:r.GetDatasetStatusByName.Status,LatestUpdateDate:new Date(r.GetDatasetStatusByName.LatestUpdateDate),EntityUpdateDates:JSON.parse(r.GetDatasetStatusByName.EntityUpdateDates)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,EntityUpdateDates:null}}async CreateTransactionGroup(){return new V(this)}async GetRecordFavoriteStatus(e,t,s){if(!s.Validate().IsValid)return!1;const a=this.Entities.find(n=>n.Name===t);if(!a)throw new Error(`Entity ${t} not found in metadata`);const o=w`query GetRecordFavoriteStatus($params: UserFavoriteSearchParams!) {
|
|
169
171
|
GetRecordFavoriteStatus(params: $params) {
|
|
170
172
|
Success
|
|
171
173
|
IsFavorite
|
|
172
174
|
}
|
|
173
|
-
}`,
|
|
175
|
+
}`,i=await this.ExecuteGQL(o,{params:{UserID:e,EntityID:a.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)}}});if(i&&i.GetRecordFavoriteStatus&&i.GetRecordFavoriteStatus.Success)return i.GetRecordFavoriteStatus.IsFavorite}async SetRecordFavoriteStatus(e,t,s,r,a){const o=this.Entities.find(c=>c.Name===t);if(!o)throw new Error(`Entity ${t} not found in metadata`);const i=w`mutation SetRecordFavoriteStatus($params: UserFavoriteSetParams!) {
|
|
174
176
|
SetRecordFavoriteStatus(params: $params){
|
|
175
177
|
Success
|
|
176
178
|
}
|
|
177
|
-
}`,
|
|
179
|
+
}`,n=await this.ExecuteGQL(i,{params:{UserID:e,EntityID:o.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)},IsFavorite:r}});if(n&&n.SetRecordFavoriteStatus!==null)return n.SetRecordFavoriteStatus.Success}async GetEntityRecordName(e,t){if(!e||!t||t.KeyValuePairs?.length===0)return null;const s=w`query GetEntityRecordNameQuery ($EntityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
178
180
|
GetEntityRecordName(EntityName: $EntityName, CompositeKey: $CompositeKey) {
|
|
179
181
|
Success
|
|
180
182
|
Status
|
|
181
183
|
RecordName
|
|
182
184
|
}
|
|
183
|
-
}`,r=await this.ExecuteGQL(s,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}});if(r&&r.GetEntityRecordName&&r.GetEntityRecordName.Success)return r.GetEntityRecordName.RecordName}async GetEntityRecordNames(e){if(!e)return null;const t=
|
|
185
|
+
}`,r=await this.ExecuteGQL(s,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}});if(r&&r.GetEntityRecordName&&r.GetEntityRecordName.Success)return r.GetEntityRecordName.RecordName}async GetEntityRecordNames(e){if(!e)return null;const t=w`query GetEntityRecordNamesQuery ($info: [EntityRecordNameInput!]!) {
|
|
184
186
|
GetEntityRecordNames(info: $info) {
|
|
185
187
|
Success
|
|
186
188
|
Status
|
|
@@ -193,35 +195,35 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
193
195
|
EntityName
|
|
194
196
|
RecordName
|
|
195
197
|
}
|
|
196
|
-
}`,s=await this.ExecuteGQL(t,{info:e.map(r=>({EntityName:r.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(r.CompositeKey.KeyValuePairs)}}))});if(s&&s.GetEntityRecordNames)return s.GetEntityRecordNames}async GetDataContextData(e){try{const t=
|
|
198
|
+
}`,s=await this.ExecuteGQL(t,{info:e.map(r=>({EntityName:r.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(r.CompositeKey.KeyValuePairs)}}))});if(s&&s.GetEntityRecordNames)return s.GetEntityRecordNames}async GetDataContextData(e){try{const t=w`query GetDataContextData ($DataContextID: String!) {
|
|
197
199
|
GetDataContextData(DataContextID: $DataContextID) {
|
|
198
200
|
Success
|
|
199
201
|
ErrorMessages
|
|
200
202
|
Results
|
|
201
203
|
}
|
|
202
|
-
}`,s=await this.ExecuteGQL(t,{DataContextID:e});if(s&&s.GetDataContextData){if(s.GetDataContextData.Success)return s.GetDataContextData.Results.map(r=>JSON.parse(r));throw new Error(s.GetDataContextData.ErrorMessages.join(", "))}else throw new Error("GraphQL query failed")}catch(t){throw
|
|
204
|
+
}`,s=await this.ExecuteGQL(t,{DataContextID:e});if(s&&s.GetDataContextData){if(s.GetDataContextData.Success)return s.GetDataContextData.Results.map(r=>JSON.parse(r));throw new Error(s.GetDataContextData.ErrorMessages.join(", "))}else throw new Error("GraphQL query failed")}catch(t){throw D(t),t}}async GetDataContextItemData(e){try{const t=w`query GetDataContextItemData ($DataContextItemID: String!) {
|
|
203
205
|
GetDataContextItemData(DataContextItemID: $DataContextItemID) {
|
|
204
206
|
Success
|
|
205
207
|
ErrorMessage
|
|
206
208
|
Result
|
|
207
209
|
}
|
|
208
|
-
}`,s=await this.ExecuteGQL(t,{DataContextItemID:e});if(s&&s.GetDataContextItemData){if(s.GetDataContextItemData.Success)return JSON.parse(s.GetDataContextItemData.Result);throw new Error(s.GetDataContextItemData.ErrorMessage)}else throw new Error("GraphQL query failed")}catch(t){throw
|
|
210
|
+
}`,s=await this.ExecuteGQL(t,{DataContextItemID:e});if(s&&s.GetDataContextItemData){if(s.GetDataContextItemData.Success)return JSON.parse(s.GetDataContextItemData.Result);throw new Error(s.GetDataContextItemData.ErrorMessage)}else throw new Error("GraphQL query failed")}catch(t){throw D(t),t}}static async ExecuteGQL(e,t,s=!0){return h.Instance.ExecuteGQL(e,t,s)}async ExecuteGQL(e,t,s=!0){try{return await this._client.request(e,t)}catch(r){if(r&&r.response&&r.response.errors?.length>0)if(r.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(s)return await this.RefreshToken(),await this.ExecuteGQL(e,t,!1);throw D("JWT_EXPIRED and refreshTokenIfNeeded is false"),r}else throw r;else throw D(r),r}}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,s,r){const a={"x-session-id":s};return t&&(a.authorization="Bearer "+t),r&&(a["x-mj-api-key"]=r),new ue(e,{headers:a})}userInfoString(){return this.infoString(new le(null,null))}userRoleInfoString(){return this.infoString(new ge(null))}infoString(e){let t="";const s=Object.keys(e);for(const r of s)r.startsWith("__mj_")?t+=r.replace("__mj_","_mj__")+`
|
|
209
211
|
`:r.startsWith("_")||(t+=r+`
|
|
210
|
-
`);return t}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new
|
|
212
|
+
`);return t}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new x),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(s=>{const r=this._wsClient.subscribe({query:e,variables:t},{next:a=>{s.next(a.data)},error:a=>{s.error(a)},complete:()=>{s.complete()}});return()=>{r()}})}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 s=w`subscription StatusUpdates($sessionId: String!) {
|
|
211
213
|
statusUpdates(sessionId: $sessionId) {
|
|
212
214
|
date
|
|
213
215
|
message
|
|
214
216
|
sessionId
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
|
-
`,r=new de(a=>(this._wsClient.subscribe({query:s,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:r}),r}};
|
|
219
|
+
`,r=new de(a=>(this._wsClient.subscribe({query:s,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:r}),r}};f(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(s=>{this._localStorage[e]=t,s()})}async Remove(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],t()})}};f(j,"BrowserStorageProviderBase");let T=j;const Ge="MJ_Metadata",g="Metadata_KVPairs",W=class W extends T{constructor(){super(),this.dbPromise=Ne(Ge,1,{upgrade(e){e.objectStoreNames.contains(g)||e.createObjectStore(g)}})}async setItem(e,t){const r=(await this.dbPromise).transaction(g,"readwrite");await r.objectStore(g).put(t,e),await r.done}async getItem(e){return await(await this.dbPromise).transaction(g).objectStore(g).get(e)}async remove(e){const s=(await this.dbPromise).transaction(g,"readwrite");await s.objectStore(g).delete(e),await s.done}};f(W,"BrowserIndexedDBStorageProvider");let x=W;async function Te(p){const e=new $;return Ie(e),await e.Config(p),Ve.Instance.RaiseEvent({event:$e.LoggedIn,eventCode:null,component:this,args:null}),e}f(Te,"setupGraphQLClient");const z=class z{};f(z,"SyncRolesAndUsersResult");let Q=z;const H=class H{};f(H,"RoleInput");let P=H;const X=class X{};f(X,"UserInput");let U=X;const Z=class Z{};f(Z,"RolesAndUsersInput");let v=Z;var Re=(p=>(p.Create="Create",p.Update="Update",p.CreateOrUpdate="CreateOrUpdate",p.Delete="Delete",p.DeleteWithFilter="DeleteWithFilter",p))(Re||{});const Y=class Y{};f(Y,"ActionItemInput");let F=Y;const ee=class ee{constructor(){this.Results=[]}};f(ee,"SyncDataResult");let M=ee;const te=class te{};f(te,"ActionItemOutput");let L=te;const se=class se{get Client(){return this._client}constructor(e,t,s,r){const a={"x-session-id":s};t&&(a.authorization="Bearer "+t),r&&(a["x-mj-api-key"]=r),this._client=new ue(e,{headers:a})}async GetData(e,t){try{const r=await this.Client.request(`query GetData($input: GetDataInputType!) {
|
|
218
220
|
GetData(input: $input) {
|
|
219
221
|
Success
|
|
220
222
|
ErrorMessages
|
|
221
223
|
Queries
|
|
222
224
|
Results
|
|
223
225
|
}
|
|
224
|
-
}`,{input:{Queries:e,Token:"nope"}});return r&&r.GetData?{Success:r.GetData.Success,Results:r.GetData.Results.map(a=>a?C(a):null),ErrorMessages:r.GetData.ErrorMessages,Queries:r.GetData.Queries}:{Success:!1,Results:[],ErrorMessages:r.GetData?.ErrorMessages??["Unknown error"],Queries:r.GetData?.Queries??e}}catch(s){const r=`GraphQLSystemUserClient::GetData - Error getting geta - ${s}`;return
|
|
226
|
+
}`,{input:{Queries:e,Token:"nope"}});return r&&r.GetData?{Success:r.GetData.Success,Results:r.GetData.Results.map(a=>a?C(a):null),ErrorMessages:r.GetData.ErrorMessages,Queries:r.GetData.Queries}:{Success:!1,Results:[],ErrorMessages:r.GetData?.ErrorMessages??["Unknown error"],Queries:r.GetData?.Queries??e}}catch(s){const r=`GraphQLSystemUserClient::GetData - Error getting geta - ${s}`;return D(r),{Success:!1,Results:[],ErrorMessages:[r],Queries:e}}}async GetAllRemoteEntities(){try{const t=await this.Client.request(`query GetAllEntities {
|
|
225
227
|
GetAllEntities {
|
|
226
228
|
Success
|
|
227
229
|
ErrorMessage
|
|
@@ -244,7 +246,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
|
-
}`);return t&&t.GetAllEntities?t.GetAllEntities:{Success:!1,Results:[],ErrorMessage:t.GetAllEntities?.ErrorMessage??"Unknown error"}}catch(e){return
|
|
249
|
+
}`);return t&&t.GetAllEntities?t.GetAllEntities:{Success:!1,Results:[],ErrorMessage:t.GetAllEntities?.ErrorMessage??"Unknown error"}}catch(e){return D(`GraphQLSystemUserClient::GetAllRemoteEntities - Error getting remote entities - ${e}`),{Success:!1,Results:[],ErrorMessage:e}}}async SyncData(e){try{const s=await this.Client.request(`mutation SyncData($items: [ActionItemInputType!]!) {
|
|
248
250
|
SyncData(items: $items) {
|
|
249
251
|
Success
|
|
250
252
|
Results {
|
|
@@ -268,11 +270,11 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
268
270
|
RecordJSON
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
|
-
}`,{items:e});return s&&s.SyncData?s.SyncData:{Success:!1,Results:[]}}catch(t){return
|
|
273
|
+
}`,{items:e});return s&&s.SyncData?s.SyncData:{Success:!1,Results:[]}}catch(t){return D(`GraphQLSystemUserClient::SyncData - Error syncing data - ${t}`),{Success:!1,Results:[]}}}async SyncRolesAndUsers(e){try{const s=await this.Client.request(`mutation SyncRolesAndUsers($data: RolesAndUsersInputType!) {
|
|
272
274
|
SyncRolesAndUsers(data: $data) {
|
|
273
275
|
Success
|
|
274
276
|
}
|
|
275
|
-
}`,{data:e});return s&&s.SyncRolesAndUsers?s.SyncRolesAndUsers:{Success:!1}}catch(t){return
|
|
277
|
+
}`,{data:e});return s&&s.SyncRolesAndUsers?s.SyncRolesAndUsers:{Success:!1}}catch(t){return D(`GraphQLSystemUserClient::SyncRolesAndUsers - Error syncing roles and users - ${t}`),{Success:!1}}}async RunViewByNameSystemUser(e){try{const s=await this.Client.request(`query RunViewByNameSystemUser($input: RunViewByNameInput!) {
|
|
276
278
|
RunViewByNameSystemUser(input: $input) {
|
|
277
279
|
Results {
|
|
278
280
|
ID
|
|
@@ -286,7 +288,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
286
288
|
ErrorMessage
|
|
287
289
|
Success
|
|
288
290
|
}
|
|
289
|
-
}`,{input:e});return s&&s.RunViewByNameSystemUser?s.RunViewByNameSystemUser:{Results:[],Success:!1,ErrorMessage:"Failed to execute view by name"}}catch(t){return
|
|
291
|
+
}`,{input:e});return s&&s.RunViewByNameSystemUser?s.RunViewByNameSystemUser:{Results:[],Success:!1,ErrorMessage:"Failed to execute view by name"}}catch(t){return D(`GraphQLSystemUserClient::RunViewByNameSystemUser - Error running view by name - ${t}`),{Results:[],Success:!1,ErrorMessage:t.toString()}}}async RunViewByIDSystemUser(e){try{const s=await this.Client.request(`query RunViewByIDSystemUser($input: RunViewByIDInput!) {
|
|
290
292
|
RunViewByIDSystemUser(input: $input) {
|
|
291
293
|
Results {
|
|
292
294
|
ID
|
|
@@ -300,7 +302,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
300
302
|
ErrorMessage
|
|
301
303
|
Success
|
|
302
304
|
}
|
|
303
|
-
}`,{input:e});return s&&s.RunViewByIDSystemUser?s.RunViewByIDSystemUser:{Results:[],Success:!1,ErrorMessage:"Failed to execute view by ID"}}catch(t){return
|
|
305
|
+
}`,{input:e});return s&&s.RunViewByIDSystemUser?s.RunViewByIDSystemUser:{Results:[],Success:!1,ErrorMessage:"Failed to execute view by ID"}}catch(t){return D(`GraphQLSystemUserClient::RunViewByIDSystemUser - Error running view by ID - ${t}`),{Results:[],Success:!1,ErrorMessage:t.toString()}}}async RunDynamicViewSystemUser(e){try{const s=await this.Client.request(`query RunDynamicViewSystemUser($input: RunDynamicViewInput!) {
|
|
304
306
|
RunDynamicViewSystemUser(input: $input) {
|
|
305
307
|
Results {
|
|
306
308
|
ID
|
|
@@ -314,7 +316,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
314
316
|
ErrorMessage
|
|
315
317
|
Success
|
|
316
318
|
}
|
|
317
|
-
}`,{input:e});return s&&s.RunDynamicViewSystemUser?s.RunDynamicViewSystemUser:{Results:[],Success:!1,ErrorMessage:"Failed to execute dynamic view"}}catch(t){return
|
|
319
|
+
}`,{input:e});return s&&s.RunDynamicViewSystemUser?s.RunDynamicViewSystemUser:{Results:[],Success:!1,ErrorMessage:"Failed to execute dynamic view"}}catch(t){return D(`GraphQLSystemUserClient::RunDynamicViewSystemUser - Error running dynamic view - ${t}`),{Results:[],Success:!1,ErrorMessage:t.toString()}}}async RunViewsSystemUser(e){try{const s=await this.Client.request(`query RunViewsSystemUser($input: [RunViewGenericInput!]!) {
|
|
318
320
|
RunViewsSystemUser(input: $input) {
|
|
319
321
|
Results {
|
|
320
322
|
ID
|
|
@@ -328,27 +330,37 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
328
330
|
ErrorMessage
|
|
329
331
|
Success
|
|
330
332
|
}
|
|
331
|
-
}`,{input:e});return s&&s.RunViewsSystemUser?s.RunViewsSystemUser:[]}catch(t){return
|
|
332
|
-
GetQueryDataSystemUser(QueryID: $QueryID, CategoryID: $CategoryID, CategoryName: $CategoryName) {
|
|
333
|
+
}`,{input:e});return s&&s.RunViewsSystemUser?s.RunViewsSystemUser:[]}catch(t){return D(`GraphQLSystemUserClient::RunViewsSystemUser - Error running views - ${t}`),[]}}async GetQueryDataSystemUser(e,t,s,r,a,o){try{const i=`query GetQueryDataSystemUser($QueryID: String!, $CategoryID: String, $CategoryName: String, $Parameters: JSONObject, $MaxRows: Int, $StartRow: Int) {
|
|
334
|
+
GetQueryDataSystemUser(QueryID: $QueryID, CategoryID: $CategoryID, CategoryName: $CategoryName, Parameters: $Parameters, MaxRows: $MaxRows, StartRow: $StartRow) {
|
|
333
335
|
QueryID
|
|
334
336
|
QueryName
|
|
335
337
|
Success
|
|
336
338
|
Results
|
|
337
339
|
RowCount
|
|
340
|
+
TotalRowCount
|
|
338
341
|
ExecutionTime
|
|
339
342
|
ErrorMessage
|
|
343
|
+
AppliedParameters
|
|
340
344
|
}
|
|
341
|
-
}`,{QueryID:e
|
|
342
|
-
GetQueryDataByNameSystemUser(QueryName: $QueryName, CategoryID: $CategoryID, CategoryName: $CategoryName) {
|
|
345
|
+
}`,n={QueryID:e};t!==void 0&&(n.CategoryID=t),s!==void 0&&(n.CategoryName=s),r!==void 0&&(n.Parameters=r),a!==void 0&&(n.MaxRows=a),o!==void 0&&(n.StartRow=o);const c=await this.Client.request(i,n);return c&&c.GetQueryDataSystemUser?{...c.GetQueryDataSystemUser,Results:c.GetQueryDataSystemUser.Results?C(c.GetQueryDataSystemUser.Results):null}:{QueryID:e,QueryName:"",Success:!1,Results:null,RowCount:0,TotalRowCount:0,ExecutionTime:0,ErrorMessage:"Query execution failed"}}catch(i){return D(`GraphQLSystemUserClient::GetQueryDataSystemUser - Error executing query - ${i}`),{QueryID:e,QueryName:"",Success:!1,Results:null,RowCount:0,TotalRowCount:0,ExecutionTime:0,ErrorMessage:i.toString()}}}async GetQueryDataByNameSystemUser(e,t,s,r,a,o){try{const i=`query GetQueryDataByNameSystemUser($QueryName: String!, $CategoryID: String, $CategoryName: String, $Parameters: JSONObject, $MaxRows: Int, $StartRow: Int) {
|
|
346
|
+
GetQueryDataByNameSystemUser(QueryName: $QueryName, CategoryID: $CategoryID, CategoryName: $CategoryName, Parameters: $Parameters, MaxRows: $MaxRows, StartRow: $StartRow) {
|
|
343
347
|
QueryID
|
|
344
348
|
QueryName
|
|
345
349
|
Success
|
|
346
350
|
Results
|
|
347
351
|
RowCount
|
|
352
|
+
TotalRowCount
|
|
348
353
|
ExecutionTime
|
|
349
354
|
ErrorMessage
|
|
355
|
+
AppliedParameters
|
|
356
|
+
}
|
|
357
|
+
}`,n={QueryName:e};t!==void 0&&(n.CategoryID=t),s!==void 0&&(n.CategoryName=s),r!==void 0&&(n.Parameters=r),a!==void 0&&(n.MaxRows=a),o!==void 0&&(n.StartRow=o);const c=await this.Client.request(i,n);return c&&c.GetQueryDataByNameSystemUser?{...c.GetQueryDataByNameSystemUser,Results:c.GetQueryDataByNameSystemUser.Results?C(c.GetQueryDataByNameSystemUser.Results):null}:{QueryID:"",QueryName:e,Success:!1,Results:null,RowCount:0,TotalRowCount:0,ExecutionTime:0,ErrorMessage:"Query execution failed"}}catch(i){return D(`GraphQLSystemUserClient::GetQueryDataByNameSystemUser - Error executing query - ${i}`),{QueryID:"",QueryName:e,Success:!1,Results:null,RowCount:0,TotalRowCount:0,ExecutionTime:0,ErrorMessage:i.toString()}}}async CreateQuery(e){try{const s=await this.Client.request(`mutation CreateQuery($input: CreateQueryInputType!) {
|
|
358
|
+
CreateQuery(input: $input) {
|
|
359
|
+
Success
|
|
360
|
+
ErrorMessage
|
|
361
|
+
QueryData
|
|
350
362
|
}
|
|
351
|
-
}`,{
|
|
363
|
+
}`,{input:e});return s&&s.CreateQuery?s.CreateQuery.Success&&s.CreateQuery.QueryData?{...s.CreateQuery,QueryData:s.CreateQuery.QueryData}:s.CreateQuery:{Success:!1,ErrorMessage:"Failed to create query"}}catch(t){return D(`GraphQLSystemUserClient::CreateQuery - Error creating query - ${t}`),{Success:!1,ErrorMessage:t.toString()}}}};f(se,"GraphQLSystemUserClient");let A=se;const re=class re{};f(re,"GetDataOutput");let _=re;const ae=class ae{};f(ae,"SimpleRemoteEntityOutput");let B=ae;const ne=class ne{};f(ne,"SimpleRemoteEntity");let q=ne;const ie=class ie{};f(ie,"SimpleRemoteEntityField");let O=ie;const oe=class oe{constructor(e){this._dataProvider=e}async RunAction(e,t,s=!1){try{const r=this.serializeActionParameters(t),a=this.createActionVariables(e,r,s),o=await this.executeActionMutation(a);return this.processActionResult(o,t)}catch(r){return this.handleActionError(r,t)}}serializeActionParameters(e){if(e)return e.map(t=>{let s=t.Value;return s!=null&&typeof s=="object"&&(s=JSON.stringify(s)),{...t,Value:s}})}createActionVariables(e,t,s=!1){return{input:{ActionID:e,Params:t,SkipActionLog:s}}}async executeActionMutation(e){const t=w`
|
|
352
364
|
mutation RunAction($input: RunActionInput!) {
|
|
353
365
|
RunAction(input: $input) {
|
|
354
366
|
Success
|
|
@@ -357,7 +369,7 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
357
369
|
ResultData
|
|
358
370
|
}
|
|
359
371
|
}
|
|
360
|
-
`;return await this._dataProvider.ExecuteGQL(t,e)}processActionResult(e,t){if(!e?.RunAction)throw new Error("Invalid response from server");let s;try{e.RunAction.ResultData&&(s=JSON.parse(e.RunAction.ResultData))}catch(r){
|
|
372
|
+
`;return await this._dataProvider.ExecuteGQL(t,e)}processActionResult(e,t){if(!e?.RunAction)throw new Error("Invalid response from server");let s;try{e.RunAction.ResultData&&(s=JSON.parse(e.RunAction.ResultData))}catch(r){D(`Failed to parse action result data: ${r}`)}return{Success:e.RunAction.Success,Message:e.RunAction.Message,Result:s,LogEntry:null,Params:t||[],RunParams:null}}handleActionError(e,t){const s=e;return D(`Error running action: ${s}`),{Success:!1,Message:`Error: ${s.message}`,Result:null,LogEntry:null,Params:t||[],RunParams:null}}async RunEntityAction(e){try{const t=this.createEntityActionInput(e),s=await this.executeEntityActionMutation(t);return this.processEntityActionResult(s)}catch(t){return this.handleEntityActionError(t)}}createEntityActionInput(e){const t={EntityActionID:e.EntityAction.ID,InvocationType:e.InvocationType.Name,ListID:e.ListID,ViewID:e.ViewID};return e.Params&&(t.Params=this.convertActionParams(e.Params)),e.EntityObject&&this.addEntityInformation(t,e.EntityObject),t}convertActionParams(e){return e.map(t=>{let s=t.Value;return s!=null&&typeof s=="object"&&(s=JSON.stringify(s)),{Name:t.Name,Value:s,Type:t.Type}})}addEntityInformation(e,t){e.EntityName=t.EntityInfo?.Name,t.PrimaryKey&&(e.PrimaryKey=this.convertPrimaryKey(t.PrimaryKey))}convertPrimaryKey(e){return{KeyValuePairs:e.KeyValuePairs.map(t=>this.convertKeyValuePair(t))}}convertKeyValuePair(e){return{FieldName:e.FieldName,Value:e.Value!==null&&e.Value!==void 0?typeof e.Value=="object"?JSON.stringify(e.Value):e.Value.toString():null}}async executeEntityActionMutation(e){const t=w`
|
|
361
373
|
mutation RunEntityAction($input: EntityActionInput!) {
|
|
362
374
|
RunEntityAction(input: $input) {
|
|
363
375
|
Success
|
|
@@ -365,5 +377,5 @@ var fe=Object.defineProperty;var w=(g,e)=>fe(g,"name",{value:e,configurable:!0})
|
|
|
365
377
|
ResultData
|
|
366
378
|
}
|
|
367
379
|
}
|
|
368
|
-
`;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(s){
|
|
380
|
+
`;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(s){D(`Failed to parse entity action result data: ${s}`)}return{Success:e.RunEntityAction.Success,Message:e.RunEntityAction.Message,RunParams:null,LogEntry:null,...t}}handleEntityActionError(e){const t=e;return D(`Error running entity action: ${t}`),{Success:!1,Message:`Error: ${t.message}`,RunParams:null,LogEntry:null}}};f(oe,"GraphQLActionClient");let K=oe;export{F as ActionItemInput,L as ActionItemOutput,N as FieldMapper,_ as GetDataOutput,K as GraphQLActionClient,$ as GraphQLDataProvider,G as GraphQLProviderConfigData,A as GraphQLSystemUserClient,V as GraphQLTransactionGroup,P as RoleInput,v as RolesAndUsersInput,q as SimpleRemoteEntity,O as SimpleRemoteEntityField,B as SimpleRemoteEntityOutput,Re as SyncDataAction,M as SyncDataResult,Q as SyncRolesAndUsersResult,U as UserInput,qe as gql,Te as setupGraphQLClient};
|
|
369
381
|
//# sourceMappingURL=index.mjs.map
|