divhunt 2.0.6 → 2.0.10
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/addons/core/commands/back/functions/expose.js +14 -0
- package/addons/core/commands/back/functions/find.js +1 -1
- package/addons/core/commands/back/functions/grpc/client.js +1 -1
- package/addons/core/commands/back/functions/grpc/server.js +1 -1
- package/addons/core/commands/back/functions/hide.js +14 -0
- package/addons/core/commands/back/functions/http/server.js +1 -1
- package/addons/core/commands/back/items/{many.js → self/many.js} +2 -4
- package/addons/core/commands/back/items/{one.js → self/one.js} +2 -4
- package/addons/core/commands/back/items/{run.js → self/run.js} +3 -7
- package/addons/core/commands/core/functions/run.js +13 -0
- package/addons/core/commands/{back → core}/item/functions/run.js +1 -1
- package/addons/core/commands/core/load.js +25 -0
- package/addons/core/commands/front/directives/run.js +90 -0
- package/addons/core/commands/front/directives/submit.js +152 -0
- package/addons/core/commands/front/functions/api.js +30 -0
- package/addons/render/assets/back/functions/import.js +2 -2
- package/addons/render/pages/{front/js/#register → core}/addon.js +4 -0
- package/addons/render/pages/core/load.js +3 -0
- package/addons/render/pages/front/items/directives/change.js +38 -0
- package/examples/basic-front/back/assets.js +12 -0
- package/examples/basic-front/back/index.js +13 -0
- package/examples/basic-front/back/items/commands/html.js +14 -0
- package/examples/basic-front/back/items/commands/test.js +19 -0
- package/examples/basic-front/back/items/html/fonts.js +12 -0
- package/examples/basic-front/front/pages/home.js +16 -0
- package/examples/basic-front/front/styles/main.css +31 -0
- package/examples/basic-front/front/test.js +7 -0
- package/examples/basic-front/package.json +7 -0
- package/lib/src/divhunt.js +2 -0
- package/lib/src/mixins/form.js +67 -0
- package/package.json +5 -3
- package/test/front/test.js +54 -0
- package/test.js +53 -0
- package/addons/core/commands/LICENSE.txt +0 -40
- package/addons/core/commands/README.md +0 -294
- package/addons/core/commands/back/load.js +0 -18
- package/addons/core/commands/front/#register/addon.js +0 -9
- package/addons/core/commands/front/functions/find.js +0 -22
- package/addons/core/commands/front/item/functions/run.js +0 -96
- package/addons/core/commands/front/items/elements/table/table.css +0 -18
- package/addons/core/commands/front/items/elements/table/table.js +0 -254
- package/addons/render/pages/front/js/items/commands/change.js +0 -41
- package/addons/render/pages/front/js/items/shortcuts/home.js +0 -9
- package/addons/render/pages/front/js/items/shortcuts/login.js +0 -9
- /package/addons/core/commands/{back → core}/addon.js +0 -0
- /package/addons/render/pages/front/{js/events → events}/click.js +0 -0
- /package/addons/render/pages/front/{js/events → events}/load.js +0 -0
- /package/addons/render/pages/front/{js/functions → functions}/change.js +0 -0
- /package/addons/render/pages/front/{js/functions → functions}/match.js +0 -0
- /package/addons/render/pages/front/{js/functions → functions}/open.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/catch/add.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/catch/remove.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/functions/enter.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/functions/leave.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/functions/render.js +0 -0
- /package/addons/render/pages/front/{css → styles}/page.css +0 -0
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
commands.Fn('item.run', function(item, properties = {}, context = {})
|
|
2
|
-
{
|
|
3
|
-
this.methods.resolve = null;
|
|
4
|
-
this.methods.reject = null;
|
|
5
|
-
|
|
6
|
-
this.methods.init = async (resolve, reject) =>
|
|
7
|
-
{
|
|
8
|
-
this.methods.resolve = resolve;
|
|
9
|
-
this.methods.reject = reject;
|
|
10
|
-
|
|
11
|
-
if(item.Get('in'))
|
|
12
|
-
{
|
|
13
|
-
try
|
|
14
|
-
{
|
|
15
|
-
properties = divhunt.DataDefine(properties, item.Get('in'));
|
|
16
|
-
}
|
|
17
|
-
catch(error)
|
|
18
|
-
{
|
|
19
|
-
return this.methods.resolve({data: error.message, message: 'Request contains invalid parameters.', code: 400});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if(item.Get('callback'))
|
|
24
|
-
{
|
|
25
|
-
await item.Get('callback').call(context, properties, {callback: this.methods.callback});
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
{
|
|
29
|
-
const options = {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json'
|
|
33
|
-
},
|
|
34
|
-
body: JSON.stringify({
|
|
35
|
-
id: item.Get('id'),
|
|
36
|
-
in: properties
|
|
37
|
-
})
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
try
|
|
41
|
-
{
|
|
42
|
-
const response = await fetch('/api/commands/run', options);
|
|
43
|
-
const result = await response.json();
|
|
44
|
-
|
|
45
|
-
if(result.code !== 200)
|
|
46
|
-
{
|
|
47
|
-
throw new Error(result.message);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return this.methods.callback(result.data.data, result.data.message, result.data.code);
|
|
51
|
-
}
|
|
52
|
-
catch(error)
|
|
53
|
-
{
|
|
54
|
-
return this.methods.callback(null, error.message, 500);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
this.methods.callback = (data, message = "Command '{{command}}' executed successfully.", code = 200) =>
|
|
60
|
-
{
|
|
61
|
-
if(message === null && code === 404)
|
|
62
|
-
{
|
|
63
|
-
message = 'The requested resource cannot be found.';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if(code >= 200 && code < 300 && item.Get('out'))
|
|
67
|
-
{
|
|
68
|
-
try
|
|
69
|
-
{
|
|
70
|
-
data = divhunt.DataDefine(data, item.Get('out'));
|
|
71
|
-
}
|
|
72
|
-
catch(error)
|
|
73
|
-
{
|
|
74
|
-
throw new Error('Command OUT Error. ' + error.message);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else if(code < 200 || code >= 300)
|
|
78
|
-
{
|
|
79
|
-
data = {};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.methods.resolve({data, message: message?.replace('{{command}}', item.Get('id')), code});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return new Promise((resolve, reject) =>
|
|
86
|
-
{
|
|
87
|
-
try
|
|
88
|
-
{
|
|
89
|
-
this.methods.init(resolve, reject);
|
|
90
|
-
}
|
|
91
|
-
catch(error)
|
|
92
|
-
{
|
|
93
|
-
this.methods.resolve({data: error.message, message: 'Internal server error.', code: 500});
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* Base */
|
|
2
|
-
.e-cmd-table > .holder
|
|
3
|
-
{
|
|
4
|
-
display: flex;
|
|
5
|
-
flex-direction: column;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.e-cmd-table > .holder > .error
|
|
9
|
-
{
|
|
10
|
-
display: flex;
|
|
11
|
-
align-items: center;
|
|
12
|
-
justify-content: center;
|
|
13
|
-
padding: var(--dh-spacing-l);
|
|
14
|
-
color: var(--dh-red);
|
|
15
|
-
font-size: var(--dh-size-m);
|
|
16
|
-
background: var(--dh-red-opacity);
|
|
17
|
-
border-radius: var(--dh-radius-m);
|
|
18
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
divhunt.AddonReady('elements', (elements) =>
|
|
2
|
-
{
|
|
3
|
-
elements.ItemAdd({
|
|
4
|
-
id: 'command-table',
|
|
5
|
-
icon: 'terminal',
|
|
6
|
-
name: 'Command Table',
|
|
7
|
-
description: 'Table that auto-generates columns and fetches data from a command.',
|
|
8
|
-
category: 'Display',
|
|
9
|
-
author: 'Divhunt',
|
|
10
|
-
config: {
|
|
11
|
-
command: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
value: 'commands:get:many'
|
|
14
|
-
},
|
|
15
|
-
key: {
|
|
16
|
-
type: 'string',
|
|
17
|
-
value: 'commands'
|
|
18
|
-
},
|
|
19
|
-
params: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
value: {}
|
|
22
|
-
},
|
|
23
|
-
variant: {
|
|
24
|
-
type: 'array',
|
|
25
|
-
value: ['border', 'hover', 'size-m'],
|
|
26
|
-
options: ['border', 'bg-1', 'bg-2', 'bg-3', 'striped', 'compact', 'hover', 'size-s', 'size-m', 'size-l']
|
|
27
|
-
},
|
|
28
|
-
sortable: {
|
|
29
|
-
type: 'boolean',
|
|
30
|
-
value: false
|
|
31
|
-
},
|
|
32
|
-
onRowClick: {
|
|
33
|
-
type: 'function'
|
|
34
|
-
},
|
|
35
|
-
onLoad: {
|
|
36
|
-
type: 'function'
|
|
37
|
-
},
|
|
38
|
-
onError: {
|
|
39
|
-
type: 'function'
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
render: function()
|
|
43
|
-
{
|
|
44
|
-
this.columns = [];
|
|
45
|
-
this.rows = [];
|
|
46
|
-
this.loading = true;
|
|
47
|
-
this.error = null;
|
|
48
|
-
|
|
49
|
-
// Helpers
|
|
50
|
-
this.label = (key) =>
|
|
51
|
-
{
|
|
52
|
-
return key.replace(/_/g, ' ').replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase()).trim();
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Schema parsing
|
|
56
|
-
this.parse = (schema) =>
|
|
57
|
-
{
|
|
58
|
-
if (!schema)
|
|
59
|
-
{
|
|
60
|
-
return { valid: false, columns: [] };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const target = this.key
|
|
64
|
-
? schema[this.key]
|
|
65
|
-
: Object.values(schema).find(f => f?.type === 'array');
|
|
66
|
-
|
|
67
|
-
if (!target || target.type !== 'array')
|
|
68
|
-
{
|
|
69
|
-
return { valid: false, columns: [] };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const config = target.each?.config || target.config || {};
|
|
73
|
-
const columns = [];
|
|
74
|
-
|
|
75
|
-
for (const [id, field] of Object.entries(config))
|
|
76
|
-
{
|
|
77
|
-
const type = Array.isArray(field) ? field[0] : field?.type;
|
|
78
|
-
|
|
79
|
-
if (type && type !== 'object' && type !== 'array')
|
|
80
|
-
{
|
|
81
|
-
columns.push({ id, label: this.label(id) });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return { valid: true, columns };
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// Data extraction
|
|
89
|
-
this.extract = (data) =>
|
|
90
|
-
{
|
|
91
|
-
if (!data)
|
|
92
|
-
{
|
|
93
|
-
return [];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (this.key)
|
|
97
|
-
{
|
|
98
|
-
return Array.isArray(data[this.key]) ? data[this.key] : [];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (Array.isArray(data))
|
|
102
|
-
{
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
for (const value of Object.values(data))
|
|
107
|
-
{
|
|
108
|
-
if (Array.isArray(value))
|
|
109
|
-
{
|
|
110
|
-
return value;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return [];
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// API calls
|
|
118
|
-
this.fetch = async (url, options = {}) =>
|
|
119
|
-
{
|
|
120
|
-
const response = await fetch(url, options);
|
|
121
|
-
return response.json();
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
this.info = async () =>
|
|
125
|
-
{
|
|
126
|
-
const data = await this.fetch('/api/commands/' + encodeURIComponent(this.command));
|
|
127
|
-
|
|
128
|
-
if (data.code !== 200)
|
|
129
|
-
{
|
|
130
|
-
throw new Error(data.message || 'Command not found');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!data.data.command.exposed)
|
|
134
|
-
{
|
|
135
|
-
throw new Error('Command is not exposed');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return data.data.command;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
this.run = async () =>
|
|
142
|
-
{
|
|
143
|
-
const response = await this.fetch('/api/commands/run', {
|
|
144
|
-
method: 'POST',
|
|
145
|
-
headers: { 'Content-Type': 'application/json' },
|
|
146
|
-
body: JSON.stringify({ id: this.command, in: this.params || {} })
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
if (response.code !== 200)
|
|
150
|
-
{
|
|
151
|
-
throw new Error(response.message || 'Command failed');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return response.data;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// Local command
|
|
158
|
-
this.local = async () =>
|
|
159
|
-
{
|
|
160
|
-
const commands = divhunt.Addon('commands');
|
|
161
|
-
const command = commands.ItemGet(this.command);
|
|
162
|
-
|
|
163
|
-
if (!command)
|
|
164
|
-
{
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const schema = command.Get('out');
|
|
169
|
-
const parsed = this.parse(schema);
|
|
170
|
-
|
|
171
|
-
if (!parsed.valid)
|
|
172
|
-
{
|
|
173
|
-
throw new Error('Command does not return array data');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
this.columns = parsed.columns;
|
|
177
|
-
|
|
178
|
-
const result = await command.Fn('run', this.params || {});
|
|
179
|
-
|
|
180
|
-
return result;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// Remote command
|
|
184
|
-
this.remote = async () =>
|
|
185
|
-
{
|
|
186
|
-
const command = await this.info();
|
|
187
|
-
const schema = command.data.out;
|
|
188
|
-
const parsed = this.parse(schema);
|
|
189
|
-
|
|
190
|
-
if (!parsed.valid)
|
|
191
|
-
{
|
|
192
|
-
throw new Error('Command does not return array data');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this.columns = parsed.columns;
|
|
196
|
-
|
|
197
|
-
const result = await this.run();
|
|
198
|
-
|
|
199
|
-
return result;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
// Main loader
|
|
203
|
-
this.load = async () =>
|
|
204
|
-
{
|
|
205
|
-
if (!this.command)
|
|
206
|
-
{
|
|
207
|
-
this.error = 'No command specified';
|
|
208
|
-
this.loading = false;
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
try
|
|
213
|
-
{
|
|
214
|
-
const result = await this.local() || await this.remote();
|
|
215
|
-
|
|
216
|
-
this.rows = this.extract(result?.data);
|
|
217
|
-
this.loading = false;
|
|
218
|
-
|
|
219
|
-
if (this.onLoad)
|
|
220
|
-
{
|
|
221
|
-
this.onLoad({ columns: this.columns, rows: this.rows });
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
catch (err)
|
|
225
|
-
{
|
|
226
|
-
this.error = err.message;
|
|
227
|
-
this.loading = false;
|
|
228
|
-
|
|
229
|
-
if (this.onError)
|
|
230
|
-
{
|
|
231
|
-
this.onError({ error: err.message });
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
this.load();
|
|
237
|
-
|
|
238
|
-
return `
|
|
239
|
-
<div class="holder">
|
|
240
|
-
<e-loader dh-if="loading"></e-loader>
|
|
241
|
-
<div dh-if="error" class="error">{{ error }}</div>
|
|
242
|
-
<e-table
|
|
243
|
-
dh-if="!loading && !error"
|
|
244
|
-
:columns="columns"
|
|
245
|
-
:rows="rows"
|
|
246
|
-
:variant="variant"
|
|
247
|
-
:sortable="sortable"
|
|
248
|
-
:onRowClick="onRowClick"
|
|
249
|
-
></e-table>
|
|
250
|
-
</div>
|
|
251
|
-
`;
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
divhunt.AddonReady('commands', (commands) =>
|
|
2
|
-
{
|
|
3
|
-
commands.Item({
|
|
4
|
-
id: 'pages:change',
|
|
5
|
-
method: 'POST',
|
|
6
|
-
endpoint: '/api/pages/change',
|
|
7
|
-
exposed: true,
|
|
8
|
-
description: 'Navigate to a page by ID or path',
|
|
9
|
-
in: {
|
|
10
|
-
id: ['string', null],
|
|
11
|
-
path: ['string', null],
|
|
12
|
-
parameters: ['object', {}],
|
|
13
|
-
push: ['boolean', true]
|
|
14
|
-
},
|
|
15
|
-
out: {
|
|
16
|
-
id: ['string'],
|
|
17
|
-
parameters: ['object'],
|
|
18
|
-
url: ['string']
|
|
19
|
-
},
|
|
20
|
-
callback: async function(props)
|
|
21
|
-
{
|
|
22
|
-
if(!props.id && !props.path)
|
|
23
|
-
{
|
|
24
|
-
throw new Error('Either id or path is required.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const target = props.path || props.id;
|
|
28
|
-
const result = await pages.Fn('change', target, props.parameters || {}, {
|
|
29
|
-
path: !!props.path,
|
|
30
|
-
push: props.push !== false
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if(result.code !== 200)
|
|
34
|
-
{
|
|
35
|
-
throw new Error(result.message);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return result.data;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|