@memberjunction/graphql-dataprovider 2.39.0 → 2.41.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 +40 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/dist/index.d.mts +20 -1
- package/dist/index.mjs +36 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -84,6 +84,25 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
|
|
|
84
84
|
* normalized to remove special characters and replace anything other than alphanumeric characters with an underscore.
|
|
85
85
|
*/
|
|
86
86
|
protected get LocalStoragePrefix(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves the stored session ID from the LocalStorageProvider if available.
|
|
89
|
+
* If no session ID is found, returns null.
|
|
90
|
+
* The session ID is stored using the same storage mechanism as other persistent data
|
|
91
|
+
* with a key specific to the current URL to ensure uniqueness across different
|
|
92
|
+
* server connections.
|
|
93
|
+
*
|
|
94
|
+
* @returns The stored session ID or null if not found
|
|
95
|
+
*/
|
|
96
|
+
GetStoredSessionID(): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Stores the session ID using the configured LocalStorageProvider for persistence.
|
|
99
|
+
* Uses the same URL-specific key pattern as other storage methods to ensure
|
|
100
|
+
* proper isolation between different server connections.
|
|
101
|
+
*
|
|
102
|
+
* @param sessionId The session ID to store
|
|
103
|
+
*/
|
|
104
|
+
private SaveStoredSessionID;
|
|
105
|
+
GetPreferredUUID(forceRefreshSessionId?: boolean): Promise<string>;
|
|
87
106
|
/**
|
|
88
107
|
* This method configures the class instance. If separateConnection is false or not provided, the global/static variables are set that means that the Config() call
|
|
89
108
|
* will affect all callers to the GraphQLDataProvider including via wrappers like the Metadata class. If separateConnection is true, then the instance variables are set
|
|
@@ -94,7 +113,7 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
|
|
|
94
113
|
* @param separateConnection
|
|
95
114
|
* @returns
|
|
96
115
|
*/
|
|
97
|
-
Config(configData: GraphQLProviderConfigData, separateConnection?: boolean): Promise<boolean>;
|
|
116
|
+
Config(configData: GraphQLProviderConfigData, separateConnection?: boolean, forceRefreshSessionId?: boolean): Promise<boolean>;
|
|
98
117
|
get sessionId(): string;
|
|
99
118
|
protected get AllowRefresh(): boolean;
|
|
100
119
|
protected GetCurrentUser(): Promise<UserInfo>;
|
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,25 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
|
|
|
84
84
|
* normalized to remove special characters and replace anything other than alphanumeric characters with an underscore.
|
|
85
85
|
*/
|
|
86
86
|
protected get LocalStoragePrefix(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves the stored session ID from the LocalStorageProvider if available.
|
|
89
|
+
* If no session ID is found, returns null.
|
|
90
|
+
* The session ID is stored using the same storage mechanism as other persistent data
|
|
91
|
+
* with a key specific to the current URL to ensure uniqueness across different
|
|
92
|
+
* server connections.
|
|
93
|
+
*
|
|
94
|
+
* @returns The stored session ID or null if not found
|
|
95
|
+
*/
|
|
96
|
+
GetStoredSessionID(): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Stores the session ID using the configured LocalStorageProvider for persistence.
|
|
99
|
+
* Uses the same URL-specific key pattern as other storage methods to ensure
|
|
100
|
+
* proper isolation between different server connections.
|
|
101
|
+
*
|
|
102
|
+
* @param sessionId The session ID to store
|
|
103
|
+
*/
|
|
104
|
+
private SaveStoredSessionID;
|
|
105
|
+
GetPreferredUUID(forceRefreshSessionId?: boolean): Promise<string>;
|
|
87
106
|
/**
|
|
88
107
|
* This method configures the class instance. If separateConnection is false or not provided, the global/static variables are set that means that the Config() call
|
|
89
108
|
* will affect all callers to the GraphQLDataProvider including via wrappers like the Metadata class. If separateConnection is true, then the instance variables are set
|
|
@@ -94,7 +113,7 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
|
|
|
94
113
|
* @param separateConnection
|
|
95
114
|
* @returns
|
|
96
115
|
*/
|
|
97
|
-
Config(configData: GraphQLProviderConfigData, separateConnection?: boolean): Promise<boolean>;
|
|
116
|
+
Config(configData: GraphQLProviderConfigData, separateConnection?: boolean, forceRefreshSessionId?: boolean): Promise<boolean>;
|
|
98
117
|
get sessionId(): string;
|
|
99
118
|
protected get AllowRefresh(): boolean;
|
|
100
119
|
protected GetCurrentUser(): Promise<UserInfo>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0});import{gql as m,GraphQLClient as oe}from"graphql-request";import{gql as Be}from"graphql-request";import{TransactionGroupBase as fe,TransactionResult as he,ProviderConfigDataBase as pe,ProviderBase as Ee,LogError as D,UserInfo as ue,ProviderType as Re,BaseEntityResult as le,EntityFieldTSType as
|
|
1
|
+
var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0});import{gql as m,GraphQLClient as oe}from"graphql-request";import{gql as Be}from"graphql-request";import{TransactionGroupBase as fe,TransactionResult as he,ProviderConfigDataBase as pe,ProviderBase as Ee,LogError as D,UserInfo as ue,ProviderType as Re,BaseEntityResult as le,EntityFieldTSType as g,TransactionItem as ce,UserRoleInfo as we,SetProvider as ge}from"@memberjunction/core";import{ViewInfo as ye}from"@memberjunction/core-entities";import{openDB as Ne}from"@tempfix/idb";import{Observable as Se}from"rxjs";import{createClient as Ie}from"graphql-ws";import{v4 as Ce}from"uuid";import{SafeJSONParse as de,MJGlobal as Ve,MJEventType as Ge}from"@memberjunction/global";const q=class q{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,a])=>[a,s]));for(const s in e)s in t&&(e[t[s]]=e[s],delete e[s]);return e}};p(q,"FieldMapper");let I=q;const k=class k extends fe{constructor(e){super(),this._provider=e}async HandleSubmit(){const e=m`
|
|
2
2
|
mutation ExecuteTransactionGroup($group: TransactionInputType!) {
|
|
3
3
|
ExecuteTransactionGroup(group: $group) {
|
|
4
4
|
Success
|
|
@@ -6,7 +6,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
6
6
|
ResultsJSON
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,
|
|
9
|
+
`,t=[];for(const r of this.PendingTransactions)t.push({EntityName:r.BaseEntity.EntityInfo.Name,EntityObjectJSON:await r.BaseEntity.GetDataObjectJSON(),OperationType:r.OperationType});const s={group:{Items:t,Variables:this.Variables.map(r=>({Name:r.Name,ItemIndex:this.MapVariableEntityObjectToPosition(r),FieldName:r.FieldName,Type:r.Type}))}},a=await this._provider.ExecuteGQL(e,s);if(a&&a.ExecuteTransactionGroup){const r=a.ExecuteTransactionGroup,o=[];for(let n=0;n<this.PendingTransactions.length;n++){const i=r.ResultsJSON[n],f=de(i),h=this.PendingTransactions[n];o.push(new he(h,f,f!==null))}return o}else throw new Error("Failed to execute transaction group")}};p(k,"GraphQLTransactionGroup");let C=k;const b=class b extends pe{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,a,r,o,n,i){super({Token:e,URL:t,WSURL:s,MJAPIKey:i,RefreshTokenFunction:a},r,o,n)}};p(b,"GraphQLProviderConfigData");let G=b;const R=class R extends Ee{constructor(){super(),this._innerCurrentUserQueryString=`CurrentUser {
|
|
10
10
|
${this.userInfoString()}
|
|
11
11
|
UserRoles_UserIDArray {
|
|
12
12
|
${this.userRoleInfoString()}
|
|
@@ -14,7 +14,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
14
14
|
}
|
|
15
15
|
`,this._currentUserQuery=m`query CurrentUserAndRoles {
|
|
16
16
|
${this._innerCurrentUserQueryString}
|
|
17
|
-
}`,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 Ce()}get LocalStoragePrefix(){return this._configData.URL.replace(/[^a-zA-Z0-9]/g,"_")+"."}async
|
|
17
|
+
}`,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 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)):(R.Instance._configData=e,R.Instance._sessionId===void 0&&(R.Instance._sessionId=await this.GetPreferredUUID(s)),R.Instance._client||(R.Instance._client=this.CreateNewGraphQLClient(e.URL,e.Token,R.Instance._sessionId,e.MJAPIKey)),await R.Instance.SaveStoredSessionID(R.Instance._sessionId)),super.Config(e)}catch(a){throw D(a),a}}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(a=>this.ConvertBackToMJFields(a));return t.UserRoles_UserIDArray=s,new ue(this,{...t,UserRoles:s})}}async RunReport(e,t){const s=m`
|
|
18
18
|
query GetReportDataQuery ($ReportID: String!) {
|
|
19
19
|
GetReportData(ReportID: $ReportID) {
|
|
20
20
|
Success
|
|
@@ -23,28 +23,28 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
23
23
|
ExecutionTime
|
|
24
24
|
ErrorMessage
|
|
25
25
|
}
|
|
26
|
-
}`,
|
|
26
|
+
}`,a=await this.ExecuteGQL(s,{ReportID:e.ReportID});if(a&&a.GetReportData)return{ReportID:e.ReportID,Success:a.GetReportData.Success,Results:JSON.parse(a.GetReportData.Results),RowCount:a.GetReportData.RowCount,ExecutionTime:a.GetReportData.ExecutionTime,ErrorMessage:a.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,a){const r=m`
|
|
27
27
|
query GetQueryDataQuery($QueryID: String!, $CategoryID: String, $CategoryName: String) {
|
|
28
28
|
GetQueryData(QueryID: $QueryID, CategoryID: $CategoryID, CategoryName: $CategoryName) {
|
|
29
29
|
${this.QueryReturnFieldList}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
`,o={QueryID:e};
|
|
32
|
+
`,o={QueryID:e};t!==void 0&&(o.CategoryID=t),s!==void 0&&(o.CategoryName=s);const n=await this.ExecuteGQL(r,o);if(n&&n.GetQueryData)return this.TransformQueryPayload(n.GetQueryData)}async RunQueryByName(e,t,s,a){const r=m`
|
|
33
33
|
query GetQueryDataByNameQuery($QueryName: String!, $CategoryID: String, $CategoryName: String) {
|
|
34
34
|
GetQueryDataByName(QueryName: $QueryName, CategoryID: $CategoryID, CategoryName: $CategoryName) {
|
|
35
35
|
${this.QueryReturnFieldList}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,o={QueryName:e,CategoryID:
|
|
38
|
+
`,o={QueryName:e,CategoryID:t,CategoryName:s},n=await this.ExecuteGQL(r,o);if(n&&n.GetQueryDataByName)return this.TransformQueryPayload(n.GetQueryDataByName)}get QueryReturnFieldList(){return`
|
|
39
39
|
Success
|
|
40
40
|
QueryID
|
|
41
41
|
QueryName
|
|
42
42
|
Results
|
|
43
43
|
RowCount
|
|
44
44
|
ExecutionTime
|
|
45
|
-
ErrorMessage`}TransformQueryPayload(e){try{return{QueryID:e.QueryID,QueryName:e.QueryName,Success:e.Success,Results:JSON.parse(e.Results),RowCount:e.RowCount,ExecutionTime:e.ExecutionTime,ErrorMessage:e.ErrorMessage}}catch(
|
|
46
|
-
query RunViewQuery ($input: ${
|
|
47
|
-
${
|
|
45
|
+
ErrorMessage`}TransformQueryPayload(e){try{return{QueryID:e.QueryID,QueryName:e.QueryName,Success:e.Success,Results:JSON.parse(e.Results),RowCount:e.RowCount,ExecutionTime:e.ExecutionTime,ErrorMessage:e.ErrorMessage}}catch(t){return D(`Error transforming query payload: ${t}`),null}}async RunView(e,t){try{let s="",a="";if(e){const r={};let o,n;if(e.ViewEntity)n=e.ViewEntity,o=n.Entity;else{const{entityName:u,v:l}=await this.getEntityNameAndUserView(e,t);n=l,o=u}const i=this.Entities.find(u=>u.Name===o);if(!i)throw new Error(`Entity ${o} not found in metadata`);let f=!1;e.ViewID?(s=`Run${i.ClassName}ViewByID`,a="RunViewByIDInput",r.ViewID=e.ViewID):e.ViewName?(s=`Run${i.ClassName}ViewByName`,a="RunViewByNameInput",r.ViewName=e.ViewName):(f=!0,s=`Run${i.ClassName}DynamicView`,a="RunDynamicViewInput",r.EntityName=e.EntityName),r.ExtraFilter=e.ExtraFilter?e.ExtraFilter:"",r.OrderBy=e.OrderBy?e.OrderBy:"",r.UserSearchString=e.UserSearchString?e.UserSearchString:"",r.Fields=e.Fields,r.IgnoreMaxRows=e.IgnoreMaxRows?e.IgnoreMaxRows:!1,r.MaxRows=e.MaxRows?e.MaxRows:0,r.ForceAuditLog=e.ForceAuditLog?e.ForceAuditLog:!1,r.ResultType=e.ResultType?e.ResultType:"simple",e.AuditLogDescription&&e.AuditLogDescription.length>0&&(r.AuditLogDescription=e.AuditLogDescription),f||(r.ExcludeUserViewRunID=e.ExcludeUserViewRunID?e.ExcludeUserViewRunID:"",r.ExcludeDataFromAllPriorViewRuns=e.ExcludeDataFromAllPriorViewRuns?e.ExcludeDataFromAllPriorViewRuns:!1,r.OverrideExcludeFilter=e.OverrideExcludeFilter?e.OverrideExcludeFilter:"",r.SaveViewResults=e.SaveViewResults?e.SaveViewResults:!1);const h=this.getViewRunTimeFieldList(i,n,e,f),y=m`
|
|
46
|
+
query RunViewQuery ($input: ${a}!) {
|
|
47
|
+
${s}(input: $input) {
|
|
48
48
|
Results {
|
|
49
49
|
${h.join(`
|
|
50
50
|
`)}
|
|
@@ -56,7 +56,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
56
56
|
Success
|
|
57
57
|
ErrorMessage
|
|
58
58
|
}
|
|
59
|
-
}`,c=await this.ExecuteGQL(y,{input:r});if(c&&c[
|
|
59
|
+
}`,c=await this.ExecuteGQL(y,{input:r});if(c&&c[s]){const u=c[s].Results;if(u&&u.length>0){const l=i.Fields.filter(d=>d.CodeName!==d.Name&&d.CodeName!==void 0);u.forEach(d=>{this.ConvertBackToMJFields(d),l.forEach(E=>{d[E.Name]=d[E.CodeName]})})}return c[s]}}else throw"No parameters passed to RunView";return null}catch(s){throw D(s),s}}async RunViews(e,t){try{let s=[],a=[],r=[];for(const i of e){let f="",h="";const y={};let c=null,u=null;if(i.ViewEntity)u=i.ViewEntity,c=u.Get("Entity");else{const{entityName:E,v:S}=await this.getEntityNameAndUserView(i,t);u=S,c=E}const l=this.Entities.find(E=>E.Name===c);if(!l)throw new Error(`Entity ${c} not found in metadata`);a.push(l);let d=!1;i.ViewID?(f=`Run${l.ClassName}ViewByID`,h="RunViewByIDInput",y.ViewID=i.ViewID):i.ViewName?(f=`Run${l.ClassName}ViewByName`,h="RunViewByNameInput",y.ViewName=i.ViewName):(d=!0,f=`Run${l.ClassName}DynamicView`,h="RunDynamicViewInput",y.EntityName=i.EntityName),y.ExtraFilter=i.ExtraFilter||"",y.OrderBy=i.OrderBy||"",y.UserSearchString=i.UserSearchString||"",y.Fields=i.Fields,y.IgnoreMaxRows=i.IgnoreMaxRows||!1,y.MaxRows=i.MaxRows||0,y.ForceAuditLog=i.ForceAuditLog||!1,y.ResultType=i.ResultType||"simple",i.AuditLogDescription&&i.AuditLogDescription.length>0&&(y.AuditLogDescription=i.AuditLogDescription),d||(y.ExcludeUserViewRunID=i.ExcludeUserViewRunID||"",y.ExcludeDataFromAllPriorViewRuns=i.ExcludeDataFromAllPriorViewRuns||!1,y.OverrideExcludeFilter=i.OverrideExcludeFilter||"",y.SaveViewResults=i.SaveViewResults||!1),s.push(y),r.push(...this.getViewRunTimeFieldList(l,u,i,d))}const o=m`
|
|
60
60
|
query RunViewsQuery ($input: [RunViewGenericInput!]!) {
|
|
61
61
|
RunViews(input: $input) {
|
|
62
62
|
Results {
|
|
@@ -71,7 +71,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
71
71
|
Success
|
|
72
72
|
ErrorMessage
|
|
73
73
|
}
|
|
74
|
-
}`,n=await this.ExecuteGQL(o,{input:
|
|
74
|
+
}`,n=await this.ExecuteGQL(o,{input:s});if(n&&n.RunViews){const i=n.RunViews;for(const[f,h]of i.entries())h.Results=h.Results.map(y=>{let c=JSON.parse(y.Data);return this.ConvertBackToMJFields(c),c});return i}return null}catch(s){throw D(s),s}}async getEntityNameAndUserView(e,t){let s,a;if(e.EntityName)s=e.EntityName;else if(e.ViewID)a=await ye.GetViewEntity(e.ViewID,t),s=a.Entity;else if(e.ViewName)a=await ye.GetViewEntityByName(e.ViewName,t),s=a.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:s,v:a}}getViewRunTimeFieldList(e,t,s,a){const r=[],o=new I;if(s.Fields){for(const n of e.PrimaryKeys)s.Fields.find(i=>i.trim().toLowerCase()===n.Name.toLowerCase())===void 0&&r.push(n.Name);s.Fields.forEach(n=>{r.push(o.MapFieldName(n))})}else if(a)e.Fields.forEach(n=>{n.IsBinaryFieldType||r.push(o.MapFieldName(n.CodeName))});else{for(const n of e.PrimaryKeys)r.find(i=>i.trim().toLowerCase()===n.Name.toLowerCase())===void 0&&r.push(n.Name);t.Columns.forEach(n=>{n.hidden===!1&&!r.find(i=>i.trim().toLowerCase()===n.EntityField?.Name.trim().toLowerCase())&&n.EntityField&&r.push(o.MapFieldName(n.EntityField.CodeName))})}return r}get ProviderType(){return Re.Network}async GetRecordChanges(e,t){try{const s={EntityName:"Record Changes",ExtraFilter:`RecordID = '${t.Values()}' AND Entity = '${e}'`},a=await this.RunView(s);return a?a.Results.sort((r,o)=>r.ChangedAt>o.ChangedAt?-1:1):null}catch(s){throw D(s),s}}async GetRecordDependencies(e,t){try{const s=m`query GetRecordDependenciesQuery ($entityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
75
75
|
GetRecordDependencies(entityName: $entityName, CompositeKey: $CompositeKey) {
|
|
76
76
|
EntityName
|
|
77
77
|
RelatedEntityName
|
|
@@ -83,7 +83,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
}`,
|
|
86
|
+
}`,a={entityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}};return(await this.ExecuteGQL(s,a))?.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=m`query GetRecordDuplicatesQuery ($params: PotentialDuplicateRequestType!) {
|
|
87
87
|
GetRecordDuplicates(params: $params) {
|
|
88
88
|
Status
|
|
89
89
|
ErrorMessage
|
|
@@ -105,7 +105,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
}`;let
|
|
108
|
+
}`;let a={EntityID:e.EntityID,EntityDocumentID:e.EntityDocumentID,ListID:e.ListID,ProbabilityScore:e.ProbabilityScore,Options:e.Options,RecordIDs:e.RecordIDs.map(o=>o.Copy())};const r=await this.ExecuteGQL(s,{params:a});if(r&&r.GetRecordDuplicates)return r.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=m`mutation MergeRecordsMutation ($request: RecordMergeRequest!) {
|
|
109
109
|
MergeRecords(request: $request) {
|
|
110
110
|
Success
|
|
111
111
|
OverallStatus
|
|
@@ -122,32 +122,32 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
122
122
|
Message
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
}`,
|
|
125
|
+
}`,a={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:a}))?.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 a=new le;try{e.RegisterTransactionPreprocessing();const r={input:{}},o=e.IsSaved?"Update":"Create";a.StartedAt=new Date,a.Type=e.IsSaved?"update":"create",a.OriginalValues=e.Fields.map(c=>({FieldName:c.CodeName,Value:c.Value})),e.ResultHistory.push(a);const n=`${o}${e.EntityInfo.ClassName}`,i=e.Fields.filter(c=>!c.ReadOnly||c.IsPrimaryKey&&e.IsSaved),f=new I,h=` ${n}(input: $input) {
|
|
126
126
|
${e.Fields.map(c=>f.MapFieldName(c.CodeName)).join(`
|
|
127
127
|
`)}
|
|
128
128
|
}`,y=m`mutation ${o}${e.EntityInfo.ClassName} ($input: ${n}Input!) {
|
|
129
129
|
${h}
|
|
130
130
|
}
|
|
131
|
-
`;for(let c=0;c<i.length;c++){const u=i[c];let l=u.Value;if(l)switch(u.EntityFieldInfo.TSType){case
|
|
131
|
+
`;for(let c=0;c<i.length;c++){const u=i[c];let l=u.Value;if(l)switch(u.EntityFieldInfo.TSType){case g.Date:l=l.getTime();break;case g.Boolean:typeof l!="boolean"&&(l=parseInt(l)!==0);break;case g.Number:if(typeof l!="number"){const d=Number(l);isNaN(d)||(l=d)}break}l===null&&u.EntityFieldInfo.AllowsNull===!1&&(u.EntityFieldInfo.DefaultValue!==null?l=u.EntityFieldInfo.DefaultValue:u.FieldType===g.Number||u.FieldType===g.Boolean?l=0:l=""),r.input[u.CodeName]=l}if(o.trim().toLowerCase()==="update"&&s.SkipOldValuesCheck===!1){const c=[];e.Fields.forEach(u=>{let l=null;u.OldValue!==null&&u.OldValue!==void 0&&(u.EntityFieldInfo.TSType===g.Date?l=u.OldValue.getTime().toString():u.EntityFieldInfo.TSType===g.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})}),r.input.OldValues___=c}if(e.TransactionGroup){const c=[{varName:"input",inputType:n+"Input!"}];return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ce(e,a.Type==="create"?"Create":"Update",h,r,{mutationName:n,mutationInputTypes:c},(u,l)=>{a.EndedAt=new Date,l&&u?(a.Success=!0,a.NewValues=this.ConvertBackToMJFields(u)):(a.Success=!1,a.Message="Transaction failed")})),!0}else{const c=await this.ExecuteGQL(y,r);if(c&&c[o+e.EntityInfo.ClassName])return a.Success=!0,a.EndedAt=new Date,a.NewValues=this.ConvertBackToMJFields(c[o+e.EntityInfo.ClassName]),a.NewValues;throw new Error(`Save failed for ${e.EntityInfo.ClassName}`)}}catch(r){return a.Success=!1,a.EndedAt=new Date,a.Message=r.response?.errors?.length>0?r.response.errors[0].message:r.message,D(r),null}}async Load(e,t,s=null,a){try{const r={};let o="",n="";for(let c=0;c<t.KeyValuePairs.length;c++){const u=e.Fields.find(E=>E.Name.trim().toLowerCase()===t.KeyValuePairs[c].FieldName.trim().toLowerCase()).EntityFieldInfo,l=t.GetValueByIndex(c),d=u.GraphQLType;if(n.length>0&&(n+=", "),n+=`$${u.CodeName}: ${d}!`,o.length>0&&(o+=", "),o+=`${u.CodeName}: $${u.CodeName}`,u.TSType===g.Number){if(isNaN(t.GetValueByIndex(c)))throw new Error(`Primary Key value ${l} (${u.Name}) is not a valid number`);r[u.CodeName]=parseInt(l)}else r[u.CodeName]=l}const i=s&&s.length>0?this.getRelatedEntityString(e.EntityInfo,s):"",f=new I,h=m`query Single${e.EntityInfo.ClassName}${i.length>0?"Full":""} (${n}) {
|
|
132
132
|
${e.EntityInfo.ClassName}(${o}) {
|
|
133
133
|
${e.Fields.filter(c=>!c.EntityFieldInfo.IsBinaryFieldType).map(c=>c.EntityFieldInfo.Name.trim().toLowerCase().startsWith("__mj_")?c.CodeName.replace("__mj_","_mj__"):c.CodeName).join(`
|
|
134
134
|
`)}
|
|
135
135
|
${i}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
`,y=await this.ExecuteGQL(h,r);return y&&y[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(y[e.EntityInfo.ClassName]):null}catch(r){return D(r),null}}ConvertBackToMJFields(e){return new I().ReverseMapFields(e),e}getRelatedEntityString(e,
|
|
138
|
+
`,y=await this.ExecuteGQL(h,r);return y&&y[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(y[e.EntityInfo.ClassName]):null}catch(r){return D(r),null}}ConvertBackToMJFields(e){return new I().ReverseMapFields(e),e}getRelatedEntityString(e,t){let s="";for(let a=0;a<e.RelatedEntities.length;a++)if(t.indexOf(e.RelatedEntities[a].RelatedEntity)>=0){const r=e.RelatedEntities[a],o=this.Entities.find(i=>i.ID===r.RelatedEntityID);let n="";r.Type.toLowerCase().trim()==="many to many"?n=`${r.RelatedEntityCodeName}_${r.JoinEntityJoinField.replace(/\s/g,"")}`:n=`${r.RelatedEntityCodeName}_${r.RelatedEntityJoinField.replace(/\s/g,"")}`,s+=`
|
|
139
139
|
${n} {
|
|
140
140
|
${o.Fields.map(i=>i.CodeName).join(`
|
|
141
141
|
`)}
|
|
142
142
|
}
|
|
143
|
-
`}return
|
|
144
|
-
`),f+=`${l.CodeName}`}o.push({varName:"options___",inputType:"DeleteOptionsInput!"}),r.options___=
|
|
143
|
+
`}return s}async Delete(e,t,s){const a=new le;try{e.RegisterTransactionPreprocessing(),a.StartedAt=new Date,a.Type="delete",a.OriginalValues=e.Fields.map(u=>({FieldName:u.CodeName,Value:u.Value})),e.ResultHistory.push(a);const r={},o=[];let n="",i="",f="";for(let u of e.PrimaryKey.KeyValuePairs){const l=e.Fields.find(d=>d.Name.trim().toLowerCase()===u.FieldName.trim().toLowerCase());r[l.CodeName]=l.Value,o.push({varName:l.CodeName,inputType:l.EntityFieldInfo.GraphQLType+"!"}),n.length>0&&(n+=", "),n+=`${l.CodeName}: $${l.CodeName}`,i.length>0&&(i+=", "),i+=`$${l.CodeName}: ${l.EntityFieldInfo.GraphQLType}!`,f.length>0&&(f+=`
|
|
144
|
+
`),f+=`${l.CodeName}`}o.push({varName:"options___",inputType:"DeleteOptionsInput!"}),r.options___=t||{SkipEntityAIActions:!1,SkipEntityActions:!1};const h="Delete"+e.EntityInfo.ClassName,y=m`${h}(${n}, options___: $options___) {
|
|
145
145
|
${f}
|
|
146
146
|
}
|
|
147
147
|
`,c=m`mutation ${h} (${i}, $options___: DeleteOptionsInput!) {
|
|
148
148
|
${y}
|
|
149
149
|
}
|
|
150
|
-
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ce(e,"Delete",y,r,{mutationName:h,mutationInputTypes:o},(u,l)=>{if(
|
|
150
|
+
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new ce(e,"Delete",y,r,{mutationName:h,mutationInputTypes:o},(u,l)=>{if(a.EndedAt=new Date,l&&u){let d=!0;for(const E of e.PrimaryKey.KeyValuePairs)E.Value!==u[E.FieldName]&&(d=!1);d?a.Success=!0:(a.Success=!1,a.Message="Transaction failed to commit")}else a.Success=!1,a.Message="Transaction failed to commit"})),!0;{const u=await this.ExecuteGQL(c,r);if(u&&u[h]){const l=u[h];for(let d of e.PrimaryKey.KeyValuePairs){let E=l[d.FieldName],S=d.Value;if(typeof S=="number"&&(S=S.toString()),typeof E=="number"&&(E=E.toString()),S!==E)throw new Error(`Primary key value mismatch in server Delete response. Field: ${d.FieldName}, Original: ${S}, Returned: ${E}`)}return a.Success=!0,a.EndedAt=new Date,!0}else throw new Error(`Delete failed for ${e.EntityInfo.Name}: ${e.PrimaryKey.ToString()} `)}}catch(r){return a.EndedAt=new Date,a.Success=!1,a.Message=r.response?.errors?.length>0?r.response.errors[0].message:r.message,D(r),!1}}async GetDatasetByName(e,t){const s=m`query GetDatasetByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
151
151
|
GetDatasetByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
152
152
|
DatasetID
|
|
153
153
|
DatasetName
|
|
@@ -156,7 +156,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
156
156
|
LatestUpdateDate
|
|
157
157
|
Results
|
|
158
158
|
}
|
|
159
|
-
}`,
|
|
159
|
+
}`,a=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:t});return a&&a.GetDatasetByName&&a.GetDatasetByName.Success?{DatasetID:a.GetDatasetByName.DatasetID,DatasetName:a.GetDatasetByName.DatasetName,Success:a.GetDatasetByName.Success,Status:a.GetDatasetByName.Status,LatestUpdateDate:new Date(a.GetDatasetByName.LatestUpdateDate),Results:JSON.parse(a.GetDatasetByName.Results)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,Results:null}}async GetDatasetStatusByName(e,t){const s=m`query GetDatasetStatusByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
160
160
|
GetDatasetStatusByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
161
161
|
DatasetID
|
|
162
162
|
DatasetName
|
|
@@ -165,22 +165,22 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
165
165
|
LatestUpdateDate
|
|
166
166
|
EntityUpdateDates
|
|
167
167
|
}
|
|
168
|
-
}`,
|
|
168
|
+
}`,a=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:t});return a&&a.GetDatasetStatusByName&&a.GetDatasetStatusByName.Success?{DatasetID:a.GetDatasetStatusByName.DatasetID,DatasetName:a.GetDatasetStatusByName.DatasetName,Success:a.GetDatasetStatusByName.Success,Status:a.GetDatasetStatusByName.Status,LatestUpdateDate:new Date(a.GetDatasetStatusByName.LatestUpdateDate),EntityUpdateDates:JSON.parse(a.GetDatasetStatusByName.EntityUpdateDates)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,EntityUpdateDates:null}}async CreateTransactionGroup(){return new C(this)}async GetRecordFavoriteStatus(e,t,s){if(!s.Validate().IsValid)return!1;const r=this.Entities.find(i=>i.Name===t);if(!r)throw new Error(`Entity ${t} not found in metadata`);const o=m`query GetRecordFavoriteStatus($params: UserFavoriteSearchParams!) {
|
|
169
169
|
GetRecordFavoriteStatus(params: $params) {
|
|
170
170
|
Success
|
|
171
171
|
IsFavorite
|
|
172
172
|
}
|
|
173
|
-
}`,n=await this.ExecuteGQL(o,{params:{UserID:e,EntityID:r.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(
|
|
173
|
+
}`,n=await this.ExecuteGQL(o,{params:{UserID:e,EntityID:r.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)}}});if(n&&n.GetRecordFavoriteStatus&&n.GetRecordFavoriteStatus.Success)return n.GetRecordFavoriteStatus.IsFavorite}async SetRecordFavoriteStatus(e,t,s,a,r){const o=this.Entities.find(f=>f.Name===t);if(!o)throw new Error(`Entity ${t} not found in metadata`);const n=m`mutation SetRecordFavoriteStatus($params: UserFavoriteSetParams!) {
|
|
174
174
|
SetRecordFavoriteStatus(params: $params){
|
|
175
175
|
Success
|
|
176
176
|
}
|
|
177
|
-
}`,i=await this.ExecuteGQL(n,{params:{UserID:e,EntityID:o.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(
|
|
177
|
+
}`,i=await this.ExecuteGQL(n,{params:{UserID:e,EntityID:o.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)},IsFavorite:a}});if(i&&i.SetRecordFavoriteStatus!==null)return i.SetRecordFavoriteStatus.Success}async GetEntityRecordName(e,t){if(!e||!t||t.KeyValuePairs?.length===0)return null;const s=m`query GetEntityRecordNameQuery ($EntityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
178
178
|
GetEntityRecordName(EntityName: $EntityName, CompositeKey: $CompositeKey) {
|
|
179
179
|
Success
|
|
180
180
|
Status
|
|
181
181
|
RecordName
|
|
182
182
|
}
|
|
183
|
-
}`,
|
|
183
|
+
}`,a=await this.ExecuteGQL(s,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}});if(a&&a.GetEntityRecordName&&a.GetEntityRecordName.Success)return a.GetEntityRecordName.RecordName}async GetEntityRecordNames(e){if(!e)return null;const t=m`query GetEntityRecordNamesQuery ($info: [EntityRecordNameInput!]!) {
|
|
184
184
|
GetEntityRecordNames(info: $info) {
|
|
185
185
|
Success
|
|
186
186
|
Status
|
|
@@ -193,35 +193,35 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
193
193
|
EntityName
|
|
194
194
|
RecordName
|
|
195
195
|
}
|
|
196
|
-
}`,
|
|
196
|
+
}`,s=await this.ExecuteGQL(t,{info:e.map(a=>({EntityName:a.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.CompositeKey.KeyValuePairs)}}))});if(s&&s.GetEntityRecordNames)return s.GetEntityRecordNames}async GetDataContextData(e){try{const t=m`query GetDataContextData ($DataContextID: String!) {
|
|
197
197
|
GetDataContextData(DataContextID: $DataContextID) {
|
|
198
198
|
Success
|
|
199
199
|
ErrorMessages
|
|
200
200
|
Results
|
|
201
201
|
}
|
|
202
|
-
}`,
|
|
202
|
+
}`,s=await this.ExecuteGQL(t,{DataContextID:e});if(s&&s.GetDataContextData){if(s.GetDataContextData.Success)return s.GetDataContextData.Results.map(a=>JSON.parse(a));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=m`query GetDataContextItemData ($DataContextItemID: String!) {
|
|
203
203
|
GetDataContextItemData(DataContextItemID: $DataContextItemID) {
|
|
204
204
|
Success
|
|
205
205
|
ErrorMessage
|
|
206
206
|
Result
|
|
207
207
|
}
|
|
208
|
-
}`,
|
|
209
|
-
`:
|
|
210
|
-
`);return
|
|
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 D(t),t}}static async ExecuteGQL(e,t,s=!0){return R.Instance.ExecuteGQL(e,t,s)}async ExecuteGQL(e,t,s=!0){try{return await this._client.request(e,t)}catch(a){if(a&&a.response&&a.response.errors?.length>0)if(a.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"),a}else throw a;else throw D(a),a}}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 R.Instance.RefreshToken()}CreateNewGraphQLClient(e,t,s,a){const r={"x-session-id":s};return t&&(r.authorization="Bearer "+t),a&&(r["x-mj-api-key"]=a),new oe(e,{headers:r})}userInfoString(){return this.infoString(new ue(null,null))}userRoleInfoString(){return this.infoString(new we(null))}infoString(e){let t="";const s=Object.keys(e);for(const a of s)a.startsWith("__mj_")?t+=a.replace("__mj_","_mj__")+`
|
|
209
|
+
`:a.startsWith("_")||(t+=a+`
|
|
210
|
+
`);return t}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new $),this._localStorageProvider}get Metadata(){return this}PushStatusUpdates(e=null){e||(e=this.sessionId),this._wsClient||(this._wsClient=Ie({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}}));const t=this._pushStatusRequests.find(r=>r.sessionId===e);if(t)return t.observable;const s=m`subscription StatusUpdates($sessionId: String!) {
|
|
211
211
|
statusUpdates(sessionId: $sessionId) {
|
|
212
212
|
date
|
|
213
213
|
message
|
|
214
214
|
sessionId
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
`,
|
|
217
|
+
`,a=new Se(r=>(this._wsClient.subscribe({query:s,variables:{sessionId:e}},{next:o=>r.next(o.data.statusUpdates),error:o=>r.error(o),complete:()=>r.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:a}),a}};p(R,"GraphQLDataProvider");let V=R;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()})}};p(J,"BrowserStorageProviderBase");let F=J;const Fe="MJ_Metadata",N="Metadata_KVPairs",j=class j extends F{constructor(){super(),this.dbPromise=Ne(Fe,1,{upgrade(e){e.objectStoreNames.contains(N)||e.createObjectStore(N)}})}async setItem(e,t){const a=(await this.dbPromise).transaction(N,"readwrite");await a.objectStore(N).put(t,e),await a.done}async getItem(e){return await(await this.dbPromise).transaction(N).objectStore(N).get(e)}async remove(e){const s=(await this.dbPromise).transaction(N,"readwrite");await s.objectStore(N).delete(e),await s.done}};p(j,"BrowserIndexedDBStorageProvider");let $=j;async function $e(w){const e=new V;return ge(e),await e.Config(w),Ve.Instance.RaiseEvent({event:Ge.LoggedIn,eventCode:null,component:this,args:null}),e}p($e,"setupGraphQLClient");const W=class W{};p(W,"SyncRolesAndUsersResult");let T=W;const z=class z{};p(z,"RoleInput");let P=z;const H=class H{};p(H,"UserInput");let v=H;const X=class X{};p(X,"RolesAndUsersInput");let x=X;var me=(w=>(w.Create="Create",w.Update="Update",w.CreateOrUpdate="CreateOrUpdate",w.Delete="Delete",w.DeleteWithFilter="DeleteWithFilter",w))(me||{});const Z=class Z{};p(Z,"ActionItemInput");let L=Z;const Y=class Y{constructor(){this.Results=[]}};p(Y,"SyncDataResult");let M=Y;const ee=class ee{};p(ee,"ActionItemOutput");let A=ee;const te=class te{get Client(){return this._client}constructor(e,t,s,a){const r={"x-session-id":s};t&&(r.authorization="Bearer "+t),a&&(r["x-mj-api-key"]=a),this._client=new oe(e,{headers:r})}async GetData(e,t){try{const a=await this.Client.request(`query GetData($input: GetDataInputType!) {
|
|
218
218
|
GetData(input: $input) {
|
|
219
219
|
Success
|
|
220
220
|
ErrorMessages
|
|
221
221
|
Queries
|
|
222
222
|
Results
|
|
223
223
|
}
|
|
224
|
-
}`,{input:{Queries:e,Token:"nope"}});return
|
|
224
|
+
}`,{input:{Queries:e,Token:"nope"}});return a&&a.GetData?{Success:a.GetData.Success,Results:a.GetData.Results.map(r=>r?de(r):null),ErrorMessages:a.GetData.ErrorMessages,Queries:a.GetData.Queries}:{Success:!1,Results:[],ErrorMessages:a.GetData?.ErrorMessages??["Unknown error"],Queries:a.GetData?.Queries??e}}catch(s){const a=`GraphQLSystemUserClient::GetData - Error getting geta - ${s}`;return D(a),{Success:!1,Results:[],ErrorMessages:[a],Queries:e}}}async GetAllRemoteEntities(){try{const t=await this.Client.request(`query GetAllEntities {
|
|
225
225
|
GetAllEntities {
|
|
226
226
|
Success
|
|
227
227
|
ErrorMessage
|
|
@@ -244,7 +244,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
}`);return
|
|
247
|
+
}`);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
248
|
SyncData(items: $items) {
|
|
249
249
|
Success
|
|
250
250
|
Results {
|
|
@@ -268,11 +268,11 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
268
268
|
RecordJSON
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
-
}`,{items:e});return
|
|
271
|
+
}`,{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
272
|
SyncRolesAndUsers(data: $data) {
|
|
273
273
|
Success
|
|
274
274
|
}
|
|
275
|
-
}`,{data:e});return
|
|
275
|
+
}`,{data:e});return s&&s.SyncRolesAndUsers?s.SyncRolesAndUsers:{Success:!1}}catch(t){return D(`GraphQLSystemUserClient::SyncRolesAndUsers - Error syncing roles and users - ${t}`),{Success:!1}}}};p(te,"GraphQLSystemUserClient");let U=te;const se=class se{};p(se,"GetDataOutput");let _=se;const ae=class ae{};p(ae,"SimpleRemoteEntityOutput");let Q=ae;const re=class re{};p(re,"SimpleRemoteEntity");let K=re;const ne=class ne{};p(ne,"SimpleRemoteEntityField");let B=ne;const ie=class ie{constructor(e){this._dataProvider=e}async RunAction(e,t,s=!1){try{const a=this.serializeActionParameters(t),r=this.createActionVariables(e,a,s),o=await this.executeActionMutation(r);return this.processActionResult(o,t)}catch(a){return this.handleActionError(a,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=m`
|
|
276
276
|
mutation RunAction($input: RunActionInput!) {
|
|
277
277
|
RunAction(input: $input) {
|
|
278
278
|
Success
|
|
@@ -281,7 +281,7 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
281
281
|
ResultData
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
-
`;return await this._dataProvider.ExecuteGQL(
|
|
284
|
+
`;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(a){D(`Failed to parse action result data: ${a}`)}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=m`
|
|
285
285
|
mutation RunEntityAction($input: EntityActionInput!) {
|
|
286
286
|
RunEntityAction(input: $input) {
|
|
287
287
|
Success
|
|
@@ -289,5 +289,5 @@ var De=Object.defineProperty;var p=(w,e)=>De(w,"name",{value:e,configurable:!0})
|
|
|
289
289
|
ResultData
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
`;return await this._dataProvider.ExecuteGQL(
|
|
292
|
+
`;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}}};p(ie,"GraphQLActionClient");let O=ie;export{L as ActionItemInput,A as ActionItemOutput,I as FieldMapper,_ as GetDataOutput,O as GraphQLActionClient,V as GraphQLDataProvider,G as GraphQLProviderConfigData,U as GraphQLSystemUserClient,C as GraphQLTransactionGroup,P as RoleInput,x as RolesAndUsersInput,K as SimpleRemoteEntity,B as SimpleRemoteEntityField,Q as SimpleRemoteEntityOutput,me as SyncDataAction,M as SyncDataResult,T as SyncRolesAndUsersResult,v as UserInput,Be as gql,$e as setupGraphQLClient};
|
|
293
293
|
//# sourceMappingURL=index.mjs.map
|