@gudhub/core 1.1.110 → 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.
|
@@ -122,59 +122,94 @@ export default async function createAngularModuleInstance(gudhub, module_id, mod
|
|
|
122
122
|
importedClass = factoryReturns[module_id];
|
|
123
123
|
}
|
|
124
124
|
} else {
|
|
125
|
+
// --- Safe setter for globals ---
|
|
126
|
+
// Ensures properties are added to `global` without throwing in read-only / getter-only cases.
|
|
127
|
+
function setGlobal(name, value) {
|
|
128
|
+
const desc = Object.getOwnPropertyDescriptor(global, name);
|
|
129
|
+
|
|
130
|
+
// If the property doesn't exist yet — safely define it.
|
|
131
|
+
if (!desc) {
|
|
132
|
+
try {
|
|
133
|
+
Object.defineProperty(global, name, {
|
|
134
|
+
value,
|
|
135
|
+
writable: true,
|
|
136
|
+
configurable: true,
|
|
137
|
+
enumerable: true
|
|
138
|
+
});
|
|
139
|
+
} catch (_) {}
|
|
140
|
+
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// If it's writable or has a setter — direct assignment is fine.
|
|
145
|
+
if (desc.writable || typeof desc.set === 'function') {
|
|
146
|
+
try {
|
|
147
|
+
global[name] = value;
|
|
148
|
+
} catch (_) {}
|
|
149
|
+
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Otherwise (getter-only / non-writable / non-configurable) — skip setting.
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// --- Proxy for `window` that safely mirrors assignments into `global` ---
|
|
125
157
|
const proxy = new Proxy(nodeWindow, {
|
|
126
158
|
get: (target, property) => {
|
|
127
159
|
const value = target[property];
|
|
128
|
-
if (typeof value === 'symbol')
|
|
129
|
-
|
|
130
|
-
}
|
|
160
|
+
if (typeof value === 'symbol') return undefined;
|
|
161
|
+
|
|
131
162
|
return value;
|
|
132
163
|
},
|
|
133
164
|
set: (target, property, value) => {
|
|
134
|
-
if (typeof value === 'symbol')
|
|
135
|
-
|
|
136
|
-
}
|
|
165
|
+
if (typeof value === 'symbol') return false;
|
|
166
|
+
|
|
137
167
|
target[property] = value;
|
|
138
|
-
|
|
168
|
+
setGlobal(property, value); // safely reflect into `global`
|
|
169
|
+
|
|
139
170
|
return true;
|
|
140
171
|
}
|
|
141
172
|
});
|
|
142
|
-
|
|
143
|
-
if
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
global.
|
|
173
|
+
|
|
174
|
+
// Initialize only once, if `global.window` is not present.
|
|
175
|
+
if (!Object.prototype.hasOwnProperty.call(global, 'window')) {
|
|
176
|
+
setGlobal('window', proxy);
|
|
177
|
+
setGlobal('document', nodeWindow.document);
|
|
178
|
+
setGlobal('Element', nodeWindow.Element);
|
|
179
|
+
setGlobal('CharacterData', nodeWindow.CharacterData);
|
|
180
|
+
setGlobal('this', proxy);
|
|
181
|
+
setGlobal('self', proxy);
|
|
182
|
+
setGlobal('Blob', nodeWindow.Blob);
|
|
183
|
+
setGlobal('Node', nodeWindow.Node);
|
|
184
|
+
setGlobal('navigator', nodeWindow.navigator);
|
|
185
|
+
setGlobal('HTMLElement', nodeWindow.HTMLElement);
|
|
186
|
+
setGlobal('XMLHttpRequest', nodeWindow.XMLHttpRequest);
|
|
187
|
+
setGlobal('WebSocket', nodeWindow.WebSocket);
|
|
188
|
+
setGlobal('crypto', nodeWindow.crypto);
|
|
189
|
+
setGlobal('DOMParser', nodeWindow.DOMParser);
|
|
190
|
+
setGlobal('angular', angular);
|
|
191
|
+
|
|
192
|
+
// May be read-only in some environments — set cautiously.
|
|
193
|
+
if (global.document) {
|
|
194
|
+
try {
|
|
195
|
+
global.document.queryCommandSupported = () => false;
|
|
196
|
+
} catch (_) {}
|
|
197
|
+
}
|
|
163
198
|
}
|
|
164
|
-
|
|
199
|
+
|
|
165
200
|
// Downloading module's code and transforming it to a data URL.
|
|
166
201
|
try {
|
|
167
202
|
let response = await axios.get(module_url);
|
|
168
203
|
let code = response.data;
|
|
169
|
-
|
|
204
|
+
|
|
170
205
|
// Ensure code is properly encoded, excluding any symbols
|
|
171
206
|
let encodedCode = encodeURIComponent(code);
|
|
172
|
-
|
|
207
|
+
|
|
173
208
|
// Creating a data URL
|
|
174
209
|
encodedCode = 'data:text/javascript;charset=utf-8,' + encodedCode;
|
|
175
|
-
|
|
210
|
+
|
|
176
211
|
let module;
|
|
177
|
-
|
|
212
|
+
|
|
178
213
|
// Dynamically import the module from the data URL.
|
|
179
214
|
try {
|
|
180
215
|
module = await import(/* webpackIgnore: true */ encodedCode);
|
|
@@ -182,7 +217,7 @@ export default async function createAngularModuleInstance(gudhub, module_id, mod
|
|
|
182
217
|
console.log(`Error while importing module: ${module_id}`);
|
|
183
218
|
console.log(err);
|
|
184
219
|
}
|
|
185
|
-
|
|
220
|
+
|
|
186
221
|
if (module && module.default) {
|
|
187
222
|
importedClass = new module.default();
|
|
188
223
|
} else {
|
|
@@ -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',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gudhub/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.112",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"homepage": "https://bitbucket.org/AAtlas/gudhub#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^
|
|
27
|
+
"axios": "^1.12.2",
|
|
28
28
|
"canvas": "^3.2.0",
|
|
29
29
|
"date-fns": "^2.16.1",
|
|
30
30
|
"fuse.js": "^6.4.6",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"express": "^4.17.1",
|
|
38
|
-
"jsdom": "^
|
|
38
|
+
"jsdom": "^27.0.0",
|
|
39
39
|
"mocha": "^8.1.2",
|
|
40
40
|
"parcel-bundler": "^1.12.5",
|
|
41
41
|
"should": "^13.2.3",
|