total5 0.0.1-1

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.
Files changed (57) hide show
  1. package/503.html +65 -0
  2. package/CONTRIBUTING.md +55 -0
  3. package/LICENSE +211 -0
  4. package/README.md +32 -0
  5. package/api.js +289 -0
  6. package/bin/total5 +984 -0
  7. package/builders.js +1435 -0
  8. package/bundles.js +457 -0
  9. package/cache.js +58 -0
  10. package/changelog.txt +3 -0
  11. package/cluster.js +320 -0
  12. package/cms.js +625 -0
  13. package/controller.js +1419 -0
  14. package/cron.js +99 -0
  15. package/debug.js +539 -0
  16. package/edit.js +469 -0
  17. package/error.html +49 -0
  18. package/filestorage.js +1088 -0
  19. package/flow-flowstream.js +3152 -0
  20. package/flow.js +209 -0
  21. package/flowstream.js +1991 -0
  22. package/global.js +125 -0
  23. package/helpers/index.js +32 -0
  24. package/htmlparser.js +650 -0
  25. package/http.js +81 -0
  26. package/image.js +773 -0
  27. package/images.js +747 -0
  28. package/index.js +2658 -0
  29. package/jsonschema.js +691 -0
  30. package/ldap.js +792 -0
  31. package/mail.js +936 -0
  32. package/minificators.js +858 -0
  33. package/nosql-builder.js +440 -0
  34. package/nosql-querybuilder.js +316 -0
  35. package/nosql-reader.js +353 -0
  36. package/nosql-stream.js +617 -0
  37. package/nosql.js +763 -0
  38. package/openclient.js +219 -0
  39. package/package.json +32 -0
  40. package/pause.html +67 -0
  41. package/querybuilder.js +1361 -0
  42. package/release.js +167 -0
  43. package/routing.js +905 -0
  44. package/sourcemap.js +160 -0
  45. package/tangular.js +409 -0
  46. package/templates.js +145 -0
  47. package/templates.json +74 -0
  48. package/tms.js +384 -0
  49. package/tmsclient.js +125 -0
  50. package/todo.txt +7 -0
  51. package/tools/beta.sh +6 -0
  52. package/tools/release.sh +6 -0
  53. package/uibuilder.js +206 -0
  54. package/utils.js +6374 -0
  55. package/viewengine.js +880 -0
  56. package/websocket.js +1939 -0
  57. package/workers.js +129 -0
package/503.html ADDED
@@ -0,0 +1,65 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>@(Please wait)</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="format-detection" content="telephone=no" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
8
+ <meta name="robots" content="all,follow" />
9
+ <style type="text/css">
10
+ /*auto*/
11
+ html,body { font: normal normal 14px Arial; background-color: white; height: 100%; margin: 0; padding: 0; font-smoothing: antialiased; }
12
+ .table { display: table; width: 100%; height: 100%}
13
+ .cell { display:table-cell;vertical-align:middle;text-align:center}
14
+ table { max-width: 300px; margin: 20px auto; width: 100%; border:1px solid #E0E0E0; border-collapse: collapse; font-size: 12px; }
15
+ table td { border: 1px solid #E0E0E0; padding: 6px 8px; text-align: center; }
16
+ table td:first-child { text-align: left; width: 85%; }
17
+ .anim { animation: anim 2s infinite; }
18
+ .text { color: #A0A0A0; font-size: 10px; margin-bottom: 3px; text-transform: uppercase; }
19
+ #time { font-size: 60px; font-weight: bold; margin-bottom: 10px; background-color: black; color: white; padding: 3px 10px; min-width: 70px; text-align: center; border-radius: 2px; position: relative; display: inline-block; }
20
+
21
+ @keyframes anim {
22
+ 0% { transform:scale(1); }
23
+ 50%{ transform:scale(1.5) rotate(180deg); color:gray }
24
+ 100%{ transform:scale(1); }
25
+ }
26
+ </style>
27
+ </head>
28
+ <body>
29
+
30
+ <div class="table">
31
+ <div class="cell">
32
+ <div id="time" style="">10</div>
33
+ <div class="text">@(Please wait)</div>
34
+ <div>
35
+ <b>@(Application is starting &hellip;)</b>
36
+ </div>
37
+ <table>
38
+ @{foreach m in model}
39
+ <tr>
40
+ <td>@{m.key}</td>
41
+ <td class="anim">&#10711;</td>
42
+ </tr>
43
+ @{end}
44
+ </table>
45
+ </div>
46
+ </div>
47
+
48
+ <script>
49
+ var i = 10;
50
+ setInterval(function() {
51
+ i--;
52
+ if (i >= 0) {
53
+ var el = document.getElementById('time');
54
+ !i && (el.style.fontSize = '40px');
55
+ el.innerHTML = (i === 0 ? '@(REFRESHING)' : i);
56
+ } else if (i === -1) {
57
+ setTimeout(function() {
58
+ window.location.reload();
59
+ }, 1000);
60
+ }
61
+ }, 1000);
62
+ </script>
63
+
64
+ </body>
65
+ </html>
@@ -0,0 +1,55 @@
1
+ # Contributing to total.js framework
2
+
3
+ We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
4
+
5
+ - Reporting a bug
6
+ - Discussing the current state of the code
7
+ - Submitting a fix
8
+ - Proposing new features
9
+
10
+ ## We Develop with Github
11
+
12
+ We use github to host code, to track issues and feature requests, as well as accept pull requests.
13
+
14
+ ## We Use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow), So All Code Changes Happen Through Pull Requests
15
+
16
+ Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow)). We actively welcome your pull requests:
17
+
18
+ 1. Fork the repo and create your branch from `master`.
19
+ 2. If you've added code that should be tested, add tests.
20
+ 3. If you've changed APIs, update the documentation.
21
+ 4. Ensure the test suite passes.
22
+ 5. Make sure your code lints.
23
+ 6. Issue that pull request!
24
+
25
+ ## Any contributions you make will be under the MIT Software License
26
+
27
+ In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
28
+
29
+ ## Report bugs using Github's [issues](https://github.com/totaljs/framework5/issues)
30
+
31
+ We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/totaljs/framework4/issues); it's that easy!
32
+
33
+ ## Write bug reports with detail, background, and sample code
34
+
35
+ **Great Bug Reports** tend to have:
36
+
37
+ - A quick summary and/or background
38
+ - Steps to reproduce - be specific!
39
+ - What you expected would happen
40
+ - What actually happens
41
+ - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
42
+
43
+ People *love* thorough bug reports. I'm not even kidding.
44
+
45
+ ## Use a Consistent Coding Style
46
+
47
+ We use coding styel as described here (https://docs.totaljs.com/welcome/67b47001ty51c/)
48
+
49
+ ## License
50
+
51
+ By contributing, you agree that your contributions will be licensed under its MIT License.
52
+
53
+ ## References
54
+
55
+ This document was adapted from (https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62)
package/LICENSE ADDED
@@ -0,0 +1,211 @@
1
+ The MIT License
2
+ Copyright 2012-2024 (c) Peter Širka <petersirka@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a
5
+ copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ persons to whom the Software is furnished to do so, subject to the
10
+ following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ === Encrypt & Decrypt (index.js)
24
+
25
+ The MIT License (MIT)
26
+ Copyright (c) 2011 Jozef Gula <gula.jozef@gmail.com>
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a
29
+ copy of this software and associated documentation files (the
30
+ "Software"), to deal in the Software without restriction, including
31
+ without limitation the rights to use, copy, modify, merge, publish,
32
+ distribute, sublicense, and/or sell copies of the Software, and to permit
33
+ persons to whom the Software is furnished to do so, subject to the
34
+ following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included
37
+ in all copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
40
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
42
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
43
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
44
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
45
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
46
+
47
+ === WebSocket encode/decode (index.js, utils.js)
48
+
49
+ The MIT License (MIT)
50
+ Copyright (c) 2014 Jozef Gula <gula.jozef@gmail.com>
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a
53
+ copy of this software and associated documentation files (the
54
+ "Software"), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to permit
57
+ persons to whom the Software is furnished to do so, subject to the
58
+ following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be included
61
+ in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
64
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
66
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
67
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
68
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
69
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
70
+
71
+ === Get PNG/JPG image size (internal.js)
72
+
73
+ The MIT License (MIT)
74
+ Copyright (c) 2012 TJ Holowaychuk, visionmedia (http://tjholowaychuk.com)
75
+
76
+ Permission is hereby granted, free of charge, to any person obtaining a
77
+ copy of this software and associated documentation files (the
78
+ "Software"), to deal in the Software without restriction, including
79
+ without limitation the rights to use, copy, modify, merge, publish,
80
+ distribute, sublicense, and/or sell copies of the Software, and to permit
81
+ persons to whom the Software is furnished to do so, subject to the
82
+ following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be included
85
+ in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
88
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
90
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
91
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
92
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
93
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
94
+
95
+ === EE First (internal.js)
96
+
97
+ The MIT License (MIT)
98
+ Copyright (c) 2014 Jonathan Ong me@jongleberry.com
99
+
100
+ Permission is hereby granted, free of charge, to any person obtaining a copy
101
+ of this software and associated documentation files (the "Software"), to deal
102
+ in the Software without restriction, including without limitation the rights
103
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
104
+ copies of the Software, and to permit persons to whom the Software is
105
+ furnished to do so, subject to the following conditions:
106
+
107
+ The above copyright notice and this permission notice shall be included in
108
+ all copies or substantial portions of the Software.
109
+
110
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
111
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
112
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
113
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
114
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
115
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
116
+ THE SOFTWARE.
117
+
118
+ === on-finished (internal.js)
119
+
120
+ The MIT License (MIT)
121
+ Copyright (c) 2013 Jonathan Ong <me@jongleberry.com>
122
+ Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
123
+
124
+ Permission is hereby granted, free of charge, to any person obtaining
125
+ a copy of this software and associated documentation files (the
126
+ 'Software'), to deal in the Software without restriction, including
127
+ without limitation the rights to use, copy, modify, merge, publish,
128
+ distribute, sublicense, and/or sell copies of the Software, and to
129
+ permit persons to whom the Software is furnished to do so, subject to
130
+ the following conditions:
131
+
132
+ The above copyright notice and this permission notice shall be
133
+ included in all copies or substantial portions of the Software.
134
+
135
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
136
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
137
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
138
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
139
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
140
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
141
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
142
+
143
+ === Shellsort algorithm (utils.js)
144
+
145
+ Source: https://www.khanacademy.org/computer-programming/sort-algorithms/6199294078746624
146
+
147
+ The MIT License (MIT)
148
+ Copyright (c) 2014 Sean McCarren
149
+
150
+ Permission is hereby granted, free of charge, to any person obtaining
151
+ a copy of this software and associated documentation files (the
152
+ 'Software'), to deal in the Software without restriction, including
153
+ without limitation the rights to use, copy, modify, merge, publish,
154
+ distribute, sublicense, and/or sell copies of the Software, and to
155
+ permit persons to whom the Software is furnished to do so, subject to
156
+ the following conditions:
157
+
158
+ The above copyright notice and this permission notice shall be
159
+ included in all copies or substantial portions of the Software.
160
+
161
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
162
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
163
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
164
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
165
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
166
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
167
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
168
+
169
+ === LDAP utilities (ldap.js)
170
+
171
+ Copyright (c) 2011 Mark Cavage, All rights reserved.
172
+
173
+ Permission is hereby granted, free of charge, to any person obtaining a copy
174
+ of this software and associated documentation files (the "Software"), to deal
175
+ in the Software without restriction, including without limitation the rights
176
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
177
+ copies of the Software, and to permit persons to whom the Software is
178
+ furnished to do so, subject to the following conditions:
179
+
180
+ The above copyright notice and this permission notice shall be included in
181
+ all copies or substantial portions of the Software.
182
+
183
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
186
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
188
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
189
+ THE SOFTWARE
190
+
191
+ ---
192
+
193
+ Copyright (c) 2019 LDAPjs, All rights reserved.
194
+
195
+ Permission is hereby granted, free of charge, to any person obtaining a copy
196
+ of this software and associated documentation files (the "Software"), to deal
197
+ in the Software without restriction, including without limitation the rights
198
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
199
+ copies of the Software, and to permit persons to whom the Software is
200
+ furnished to do so, subject to the following conditions:
201
+
202
+ The above copyright notice and this permission notice shall be included in
203
+ all copies or substantial portions of the Software.
204
+
205
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
206
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
208
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
209
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
210
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
211
+ THE SOFTWARE
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Total.js framework 5
2
+ ====================
3
+
4
+ [![Made in EU](https://cdn.componentator.com/eu-small.png)](https://european-union.europa.eu/)
5
+
6
+ - [Website](https://www.totaljs.com/)
7
+ - [__Documentation__](https://docs.totaljs.com/total5/)
8
+ - [Chat support](https://platform.totaljs.com/?open=messenger)
9
+ - [Join __Total.js Telegram__](https://t.me/totalplatform)
10
+ - [Support](https://www.totaljs.com/support/)
11
+
12
+ __Total.js framework v5__ is the framework for Node.js platform written in `pure` JavaScript similar to PHP's Laravel or Python's Django or ASP.NET MVC. It can be used as a web, desktop, service, or IoT application.
13
+
14
+ ```bash
15
+ $ npm install total5
16
+ ```
17
+
18
+ ## Social networks
19
+
20
+ Please support the framework on social networks.
21
+
22
+ - [Follow Total.js on Gitter](https://gitter.im/totaljs/framework)
23
+ - [Follow Total.js on GitHub](https://github.com/totaljs)
24
+ - [Follow Total.js on Twitter - __@totalframework__](https://twitter.com/totalframework)
25
+ - [Follow Total.js on Facebook](https://www.facebook.com/totaljs.web.framework)
26
+ - [Follow Total.js on LinkedIn](https://www.linkedin.com/company/total-avengers/)
27
+
28
+ ## Contact
29
+
30
+ - Contact <https://www.totaljs.com/contact/>
31
+ - [Chat support](https://platform.totaljs.com/?open=messenger)
32
+ - [Join to __Total.js Telegram__](https://t.me/totalplatform)
package/api.js ADDED
@@ -0,0 +1,289 @@
1
+ // API caller
2
+ // The MIT License
3
+ // Copyright 2023 (c) Peter Širka <petersirka@gmail.com>
4
+
5
+ 'use strict';
6
+
7
+ var cache = {};
8
+
9
+ // Registers a new API type
10
+ exports.newapi = function(type, callback) {
11
+
12
+ if (typeof(type) === 'function') {
13
+ callback = type;
14
+ type = 'default';
15
+ }
16
+
17
+ if (type.indexOf(',') !== -1) {
18
+ var arr = type.split(',').trim();
19
+ for (var m of arr)
20
+ exports.newapi(m, callback);
21
+ return;
22
+ }
23
+
24
+ // It can be "camel case"
25
+ var lower = type.toLowerCase();
26
+ cache[type] = lower;
27
+ cache[lower] = lower;
28
+
29
+ if (callback)
30
+ F.apiservices[lower] = callback;
31
+ else
32
+ delete F.apiservices[lower];
33
+
34
+ };
35
+
36
+ function APICall() {
37
+ var t = this;
38
+ t.options = {};
39
+ }
40
+
41
+ const APICallProto = APICall.prototype;
42
+
43
+ APICallProto.output = function(type) {
44
+ this.options.output = type;
45
+ return this;
46
+ };
47
+
48
+ APICallProto.promise = function($) {
49
+ var t = this;
50
+ var promise = new Promise(function(resolve, reject) {
51
+ t.$callback = function(err, response) {
52
+ if (err) {
53
+ if ($ && $.invalid) {
54
+ $.invalid(err);
55
+ } else {
56
+ err.name = 'API(' + t.options.name + ' --> ' + t.options.schema + ')';
57
+ reject(err);
58
+ }
59
+ } else
60
+ resolve(response);
61
+ };
62
+ });
63
+
64
+ return promise;
65
+ };
66
+
67
+ APICallProto.audit = function($, message, type) {
68
+ var t = this;
69
+ t.$audit = function() {
70
+ // Dynamic arguments
71
+ if (message)
72
+ message = $.variables(message, t.options.data);
73
+ $.audit(message, type);
74
+ };
75
+ return t;
76
+ };
77
+
78
+ APICallProto.done = function($, callback) {
79
+ var t = this;
80
+ t.$callback = function(err, response) {
81
+ if (err)
82
+ $.invalid(err);
83
+ else if (callback)
84
+ callback(response);
85
+ t.free();
86
+ };
87
+ return t;
88
+ };
89
+
90
+ APICallProto.debug = function() {
91
+ this.$debug = true;
92
+ return this;
93
+ };
94
+
95
+ APICallProto.fail = function(cb) {
96
+ this.$callback_fail = cb;
97
+ return this;
98
+ };
99
+
100
+ APICallProto.data = function(cb) {
101
+ this.$callback_data = cb;
102
+ return this;
103
+ };
104
+
105
+ APICallProto.controller = function($) {
106
+ this.options.controller = $.controller || $;
107
+ return this;
108
+ };
109
+
110
+ APICallProto.file = function(filename, path, name) {
111
+
112
+ var t = this;
113
+
114
+ if (!t.options.files)
115
+ t.options.files = [];
116
+
117
+ var obj = { name: name || ('file' + t.options.files.length), filename: filename, path: path };
118
+
119
+ if (t.options.files)
120
+ t.options.files.push(obj);
121
+ else
122
+ t.options.files = [obj];
123
+
124
+ return t;
125
+ };
126
+
127
+ APICallProto.error = APICallProto.err = function(err, reverse) {
128
+ this.$error = err + '';
129
+ this.$error_reverse = reverse;
130
+ return this;
131
+ };
132
+
133
+ APICallProto.callback = function($) {
134
+ var t = this;
135
+ t.$callback = typeof($) === 'function' ? $ : $.callback;
136
+ return t;
137
+ };
138
+
139
+ APICallProto.evaluate = function(err, response) {
140
+
141
+ var t = this;
142
+ if (!err && t.$error) {
143
+ if (t.$error_reverse) {
144
+ if (response)
145
+ err = t.$error;
146
+ else if (response instanceof Array && response.length)
147
+ err = t.$error;
148
+ } else if (!response)
149
+ err = t.$error;
150
+ else if (response instanceof Array && !response.length)
151
+ err = t.$error;
152
+ }
153
+
154
+ if (err) {
155
+ t.$callback_fail && t.$callback_fail(err);
156
+ } else {
157
+ if (t.$audit) {
158
+ t.$audit();
159
+ t.$audit = null;
160
+ }
161
+ t.$callback_data && t.$callback_data(response);
162
+ }
163
+
164
+ t.$debug && console.log('--DEBUG-- API: ' + t.options.name + ' --> ' + t.options.schema, '|', 'Error:', err, '|', 'Response:', response);
165
+ t.$callback && t.$callback(err, response);
166
+ };
167
+
168
+ function execapi(api) {
169
+ var conn = F.apiservices[cache[api.options.name]] || F.apiservices['*'];
170
+ if (conn)
171
+ conn.call(api, api.options, (err, response) => api.evaluate(err, response));
172
+ else
173
+ api.evaluate('API is not initialized');
174
+ }
175
+
176
+ // Executes API
177
+ exports.exec = function(name, schema, data, $) {
178
+ var api = new APICall();
179
+ api.options.name = cache[name] || name;
180
+ api.options.schema = schema;
181
+ api.options.data = data;
182
+ api.options.controller = $;
183
+ setImmediate(execapi, api);
184
+ return api;
185
+ };
186
+
187
+ exports.newapi('TotalAPI,TAPI', function(opt, next) {
188
+
189
+ if (!F.config.$tapi && opt.schema !== 'check') {
190
+ next('totalapi_inactive');
191
+ return;
192
+ }
193
+
194
+ if (opt.data && typeof(opt.data) !== 'object')
195
+ opt.data = { value: opt.data };
196
+
197
+ var req = {};
198
+
199
+ req.method = 'POST';
200
+ req.url = 'https://' + F.config.$tapiurl + '.api.totaljs.com/' + opt.schema + '/';
201
+
202
+ if (opt.files) {
203
+ req.body = opt.data;
204
+ req.files = opt.files;
205
+ } else
206
+ req.body = JSON.stringify(opt.data);
207
+
208
+ req.type = 'json';
209
+ req.timeout = 60000;
210
+ req.keepalive = true;
211
+ req.headers = { 'x-token': opt.token || F.config.secret_totalapi || F.config.$tapisecret || '-', 'x-app': encodeURIComponent(F.config.name) };
212
+ req.custom = true;
213
+
214
+ req.callback = function(err, response) {
215
+
216
+ if (err) {
217
+ next(err.toString());
218
+ return;
219
+ }
220
+
221
+ var buffer = [];
222
+
223
+ // Error
224
+ if (response.status > 200) {
225
+ response.stream.on('data', chunk => buffer.push(chunk));
226
+ F.cleanup(response.stream, function() {
227
+ let output = Buffer.concat(buffer).toString('utf8');
228
+ let response = output.parseJSON();
229
+ next((response && response[0] && response[0].error) || output);
230
+ });
231
+ return;
232
+ }
233
+
234
+ if (!opt.output || opt.output === 'json' || opt.output === 'html' || opt.output === 'plain' || opt.output === 'text' || opt.output === 'base64' || opt.output === 'buffer' || opt.output === 'binary') {
235
+ response.stream.on('data', chunk => buffer.push(chunk));
236
+ F.cleanup(response.stream, function() {
237
+ let output = Buffer.concat(buffer);
238
+ if (opt.output === 'base64') {
239
+ output = output.toString('base64');
240
+ } else if (opt.output !== 'binary' && opt.output !== 'buffer') {
241
+ output = output.toString('utf8');
242
+ if (!opt.output || opt.output === 'json')
243
+ output = output.parseJSON(true);
244
+ }
245
+ next(null, output);
246
+ });
247
+ return;
248
+ }
249
+
250
+ if (opt.output === 'stream') {
251
+ next(null, response.stream);
252
+ return;
253
+ }
254
+
255
+ // FileStorage in the form: "#name id filename"
256
+ if (opt.output[0] === '#') {
257
+
258
+ var fsdata = null;
259
+ var fs = null;
260
+
261
+ if (opt.output[0] === '#') {
262
+ fsdata = opt.output.substring(1).split(' ');
263
+ fs = F.filestorage(fsdata[0]);
264
+ }
265
+
266
+ var type = (response.headers['content-type'] || '').toLowerCase();
267
+ var index = type.lastIndexOf(';');
268
+ if (index !== -1)
269
+ type = type.substring(0, index);
270
+
271
+ var ext = type ? F.TUtils.getExtensionFromContentType(type) : 'bin';
272
+ var id = fsdata[1] || UID();
273
+ var filename = fsdata[2] || id + '.' + ext;
274
+
275
+ response.stream.pause();
276
+ fs.save(id, filename, response.stream, next);
277
+ return;
278
+ }
279
+
280
+ var writer = F.Fs.createWriteStream(opt.output);
281
+ response.stream.pipe(writer);
282
+ F.cleanup(writer, function() {
283
+ opt.next(null, opt.output);
284
+ });
285
+
286
+ };
287
+
288
+ F.TUtils.request(req);
289
+ });