@gudhub/core 1.1.111 → 1.1.112
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.
|
@@ -2,71 +2,115 @@ import axios from 'axios';
|
|
|
2
2
|
import { IS_WEB } from './../consts.js';
|
|
3
3
|
|
|
4
4
|
export default async function createClassInstance(gudhub, module_id, js_url, css_url, nodeWindow) {
|
|
5
|
-
|
|
6
5
|
try {
|
|
7
|
-
|
|
8
|
-
// Check if there is url to javascript file of module
|
|
9
|
-
|
|
10
6
|
if (!js_url) {
|
|
11
7
|
console.error(`JS link must be provided for this data type - ${module_id}`);
|
|
12
8
|
}
|
|
13
9
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
global
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
// Safe global setter (skips read-only / getter-only props)
|
|
11
|
+
function setGlobal(name, value) {
|
|
12
|
+
const desc = Object.getOwnPropertyDescriptor(global, name);
|
|
13
|
+
|
|
14
|
+
if (!desc) {
|
|
15
|
+
try {
|
|
16
|
+
Object.defineProperty(global, name, {
|
|
17
|
+
value,
|
|
18
|
+
writable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
enumerable: true
|
|
21
|
+
});
|
|
22
|
+
} catch (_) {}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (desc.writable || typeof desc.set === 'function') {
|
|
27
|
+
try { global[name] = value; } catch (_) {}
|
|
28
|
+
}
|
|
29
|
+
// Otherwise skip (non-writable / getter-only)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Proxy for window to safely mirror properties to global
|
|
33
|
+
const proxy = (!IS_WEB && nodeWindow)
|
|
34
|
+
? new Proxy(nodeWindow, {
|
|
35
|
+
get: (target, property) => {
|
|
36
|
+
const value = target[property];
|
|
37
|
+
if (typeof value === 'symbol') return undefined;
|
|
38
|
+
return value;
|
|
39
|
+
},
|
|
40
|
+
set: (target, property, value) => {
|
|
41
|
+
if (typeof value === 'symbol') return false;
|
|
42
|
+
target[property] = value;
|
|
43
|
+
setGlobal(property, value);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
: null;
|
|
48
|
+
|
|
49
|
+
// Load remote JS module and convert it to a data URI
|
|
50
|
+
const downloadModule = (url) => {
|
|
51
|
+
// Initialize globals once (Node environment only)
|
|
52
|
+
if (!IS_WEB && !Object.prototype.hasOwnProperty.call(global, 'window') && nodeWindow && proxy) {
|
|
53
|
+
setGlobal('window', proxy);
|
|
54
|
+
setGlobal('document', nodeWindow.document);
|
|
55
|
+
setGlobal('Element', nodeWindow.Element);
|
|
56
|
+
setGlobal('CharacterData', nodeWindow.CharacterData);
|
|
57
|
+
setGlobal('this', proxy);
|
|
58
|
+
setGlobal('self', proxy);
|
|
59
|
+
setGlobal('Blob', nodeWindow.Blob);
|
|
60
|
+
setGlobal('Node', nodeWindow.Node);
|
|
61
|
+
setGlobal('navigator', nodeWindow.navigator);
|
|
62
|
+
setGlobal('HTMLElement', nodeWindow.HTMLElement);
|
|
63
|
+
setGlobal('XMLHttpRequest', nodeWindow.XMLHttpRequest);
|
|
64
|
+
setGlobal('WebSocket', nodeWindow.WebSocket);
|
|
65
|
+
setGlobal('crypto', nodeWindow.crypto);
|
|
66
|
+
setGlobal('DOMParser', nodeWindow.DOMParser);
|
|
67
|
+
setGlobal('customElements', nodeWindow.customElements);
|
|
68
|
+
|
|
69
|
+
if (global.document) {
|
|
70
|
+
try {
|
|
71
|
+
global.document.queryCommandSupported = () => false;
|
|
72
|
+
} catch (_) {}
|
|
36
73
|
}
|
|
37
|
-
global.angular = angular;
|
|
38
74
|
}
|
|
39
|
-
return new Promise(async (resolve) => {
|
|
40
|
-
let moduleData = await axios.get(url).catch(err => {
|
|
41
|
-
console.log(`Failed to fetch: ${url} in ghconstructor. Module id: ${module_id}`);
|
|
42
|
-
})
|
|
43
75
|
|
|
44
|
-
|
|
76
|
+
return new Promise(async (resolve, reject) => {
|
|
77
|
+
let moduleResp;
|
|
78
|
+
try {
|
|
79
|
+
moduleResp = await axios.get(url);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.log(`Failed to fetch: ${url} in ghconstructor. Module id: ${module_id}`);
|
|
82
|
+
return reject(err);
|
|
83
|
+
}
|
|
45
84
|
|
|
46
|
-
|
|
85
|
+
if (!moduleResp || typeof moduleResp.data !== 'string') {
|
|
86
|
+
return reject(new Error(`Empty or invalid JS for ${module_id} from ${url}`));
|
|
87
|
+
}
|
|
47
88
|
|
|
89
|
+
const encodedJs = encodeURIComponent(moduleResp.data);
|
|
90
|
+
const dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs;
|
|
48
91
|
resolve(dataUri);
|
|
49
|
-
})
|
|
50
|
-
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
51
94
|
|
|
52
|
-
|
|
95
|
+
const moduleData = await downloadModule(js_url);
|
|
53
96
|
|
|
54
97
|
let module;
|
|
55
|
-
|
|
56
98
|
try {
|
|
57
|
-
module = await import(/* webpackIgnore: true */moduleData);
|
|
99
|
+
module = await import(/* webpackIgnore: true */ moduleData);
|
|
58
100
|
} catch (err) {
|
|
59
101
|
console.log(`Error while importing module: ${module_id}`);
|
|
60
102
|
console.log(err);
|
|
61
103
|
}
|
|
62
104
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
105
|
+
if (!module || !module.default) {
|
|
106
|
+
console.error(`Module ${module_id} didn't export a default class`);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
66
109
|
|
|
67
|
-
//
|
|
68
|
-
|
|
110
|
+
// Create class instance
|
|
111
|
+
const importedClass = new module.default(module_id);
|
|
69
112
|
|
|
113
|
+
// Inject CSS in browser
|
|
70
114
|
if (css_url && IS_WEB) {
|
|
71
115
|
const linkTag = document.createElement('link');
|
|
72
116
|
linkTag.href = css_url;
|
|
@@ -75,23 +119,19 @@ export default async function createClassInstance(gudhub, module_id, js_url, css
|
|
|
75
119
|
document.getElementsByTagName('head')[0].appendChild(linkTag);
|
|
76
120
|
}
|
|
77
121
|
|
|
78
|
-
|
|
122
|
+
const result = {
|
|
79
123
|
type: module_id,
|
|
80
124
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
getTemplate: function (ref, changeFieldName, displayFieldName, field_model, appId, itemId) {
|
|
84
|
-
let displayFieldNameChecked = displayFieldName === 'false' ? false : true;
|
|
125
|
+
getTemplate(ref, changeFieldName, displayFieldName, field_model, appId, itemId) {
|
|
126
|
+
const displayFieldNameChecked = displayFieldName === 'false' ? false : true;
|
|
85
127
|
return importedClass.getTemplate(ref, changeFieldName, displayFieldNameChecked, field_model, appId, itemId);
|
|
86
128
|
},
|
|
87
129
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
getDefaultValue: function (fieldModel, valuesArray, itemsList, currentAppId) {
|
|
130
|
+
getDefaultValue(fieldModel, valuesArray, itemsList, currentAppId) {
|
|
91
131
|
return new Promise(async (resolve) => {
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
132
|
+
const fn = importedClass.getDefaultValue;
|
|
133
|
+
if (fn) {
|
|
134
|
+
const value = await fn(fieldModel, valuesArray, itemsList, currentAppId);
|
|
95
135
|
resolve(value);
|
|
96
136
|
} else {
|
|
97
137
|
resolve(null);
|
|
@@ -99,24 +139,20 @@ export default async function createClassInstance(gudhub, module_id, js_url, css
|
|
|
99
139
|
});
|
|
100
140
|
},
|
|
101
141
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
getSettings: function (scope, settingType, fieldModels) {
|
|
142
|
+
getSettings(scope, settingType, fieldModels) {
|
|
105
143
|
return importedClass.getSettings(scope, settingType, fieldModels);
|
|
106
144
|
},
|
|
107
145
|
|
|
108
|
-
//*************** FILTER****************//
|
|
109
|
-
|
|
110
146
|
filter: {
|
|
111
|
-
getSearchOptions
|
|
112
|
-
|
|
147
|
+
getSearchOptions(fieldModel) {
|
|
148
|
+
const d_type = importedClass;
|
|
113
149
|
if (d_type.filter && d_type.filter.getSearchOptions) {
|
|
114
150
|
return importedClass.filter.getSearchOptions(fieldModel);
|
|
115
151
|
}
|
|
116
152
|
return [];
|
|
117
153
|
},
|
|
118
|
-
getDropdownValues
|
|
119
|
-
|
|
154
|
+
getDropdownValues() {
|
|
155
|
+
const d_type = importedClass;
|
|
120
156
|
if (d_type.filter && d_type.filter.getDropdownValues) {
|
|
121
157
|
return d_type.filter.getDropdownValues();
|
|
122
158
|
} else {
|
|
@@ -125,39 +161,32 @@ export default async function createClassInstance(gudhub, module_id, js_url, css
|
|
|
125
161
|
}
|
|
126
162
|
},
|
|
127
163
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
getInterpretation: function (value, interpretation_id, dataType, field, itemId, appId) {
|
|
164
|
+
getInterpretation(value, interpretation_id, dataType, field, itemId, appId) {
|
|
131
165
|
return new Promise(async (resolve) => {
|
|
132
|
-
|
|
166
|
+
const currentDataType = importedClass;
|
|
133
167
|
|
|
134
168
|
try {
|
|
135
|
-
|
|
136
|
-
|
|
169
|
+
const interpr_arr = await currentDataType.getInterpretation(gudhub, value, appId, itemId, field, dataType);
|
|
170
|
+
const data = interpr_arr.find((item) => item.id == interpretation_id) || interpr_arr.find((item) => item.id == 'default');
|
|
137
171
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
resolve({ html: result });
|
|
172
|
+
const html = await data.content();
|
|
173
|
+
resolve({ html });
|
|
141
174
|
} catch (error) {
|
|
142
175
|
console.log(`ERROR IN ${module_id}`, error);
|
|
143
|
-
resolve({ html: '<span>no interpretation</span>' })
|
|
176
|
+
resolve({ html: '<span>no interpretation</span>' });
|
|
144
177
|
}
|
|
145
178
|
});
|
|
146
179
|
},
|
|
147
180
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
getInterpretationsList: function (field_value, appId, itemId, field) {
|
|
181
|
+
getInterpretationsList(field_value, appId, itemId, field) {
|
|
151
182
|
return importedClass.getInterpretation(field_value, appId, itemId, field);
|
|
152
183
|
},
|
|
153
184
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
getInterpretatedValue: function (field_value, field_model, appId, itemId) {
|
|
185
|
+
getInterpretatedValue(field_value, field_model, appId, itemId) {
|
|
157
186
|
return new Promise(async (resolve) => {
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
|
|
187
|
+
const fn = importedClass.getInterpretatedValue;
|
|
188
|
+
if (fn) {
|
|
189
|
+
const value = await fn(field_value, field_model, appId, itemId);
|
|
161
190
|
resolve(value);
|
|
162
191
|
} else {
|
|
163
192
|
resolve(field_value);
|
|
@@ -165,47 +194,35 @@ export default async function createClassInstance(gudhub, module_id, js_url, css
|
|
|
165
194
|
});
|
|
166
195
|
},
|
|
167
196
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
onMessage: function(appId, userId, response) {
|
|
197
|
+
onMessage(appId, userId, response) {
|
|
171
198
|
return new Promise(async (resolve) => {
|
|
172
|
-
const
|
|
173
|
-
if(
|
|
174
|
-
const result = await
|
|
199
|
+
const fn = importedClass.onMessage;
|
|
200
|
+
if (fn) {
|
|
201
|
+
const result = await fn(appId, userId, response);
|
|
175
202
|
resolve(result);
|
|
176
203
|
}
|
|
177
204
|
resolve(null);
|
|
178
|
-
})
|
|
205
|
+
});
|
|
179
206
|
},
|
|
180
207
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
extendController: function (actionScope) {
|
|
208
|
+
extendController(actionScope) {
|
|
184
209
|
importedClass.getActionScope(actionScope);
|
|
185
210
|
},
|
|
186
211
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
runAction: function (scope) {
|
|
212
|
+
runAction(scope) {
|
|
190
213
|
try {
|
|
191
214
|
importedClass.runAction(scope);
|
|
192
|
-
} catch (e) {
|
|
193
|
-
|
|
194
|
-
}
|
|
215
|
+
} catch (e) {}
|
|
195
216
|
},
|
|
196
217
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
getWindowScope: function (windowScope) {
|
|
218
|
+
getWindowScope(windowScope) {
|
|
200
219
|
return importedClass.getWindowScope(windowScope);
|
|
201
220
|
},
|
|
202
221
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
getWindowHTML: function (scope) {
|
|
222
|
+
getWindowHTML(scope) {
|
|
206
223
|
return importedClass.getWindowHTML(scope);
|
|
207
224
|
},
|
|
208
|
-
}
|
|
225
|
+
};
|
|
209
226
|
|
|
210
227
|
return result;
|
|
211
228
|
|
|
@@ -1088,6 +1088,13 @@ export default function generateModulesList(async_modules_path, file_server_url,
|
|
|
1088
1088
|
type: 'automation',
|
|
1089
1089
|
icon: 'automation_chat_gpt_thread'
|
|
1090
1090
|
},
|
|
1091
|
+
{
|
|
1092
|
+
data_type: 'Deepseek',
|
|
1093
|
+
name: 'Deepseek',
|
|
1094
|
+
url: file_server_url + '/' + automation_modules_path + 'deepseek_node.js',
|
|
1095
|
+
type: 'automation',
|
|
1096
|
+
icon: 'automation_deepseek'
|
|
1097
|
+
},
|
|
1091
1098
|
{
|
|
1092
1099
|
data_type: 'UrlToMarkdown',
|
|
1093
1100
|
name: 'Url To Markdown',
|