synthos 0.7.1 → 0.7.2

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "synthos",
3
3
  "author": "Steven Ickman",
4
4
  "description": "An AI powered shell experience.",
5
- "version": "0.7.1",
5
+ "version": "0.7.2",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "synthos",
@@ -52,9 +52,11 @@
52
52
  "dist",
53
53
  "bin",
54
54
  "src",
55
+ "tests",
55
56
  "default-pages",
56
57
  "default-scripts",
57
58
  "default-themes",
59
+ "page-scripts",
58
60
  "required-pages",
59
61
  "images"
60
62
  ]
@@ -0,0 +1,121 @@
1
+ (function() {
2
+ if (window.__synthOSHelpers) return;
3
+ window.__synthOSHelpers = true;
4
+
5
+ function _json(method, url, body) {
6
+ var opts = {
7
+ method: method,
8
+ headers: { 'Content-Type': 'application/json' }
9
+ };
10
+ if (body !== undefined) {
11
+ opts.body = JSON.stringify(body);
12
+ }
13
+ return fetch(url, opts).then(function(res) {
14
+ var ct = res.headers.get('content-type') || '';
15
+ var isJson = ct.indexOf('application/json') !== -1;
16
+ return (isJson ? res.json() : res.text()).then(function(data) {
17
+ if (!res.ok) {
18
+ if (res.status === 404 && isJson && data && data.error === 'table_not_found') {
19
+ return null; // for data.get, return null if the table or row is not found instead of throwing an error
20
+ }
21
+ var err = new Error(isJson && data && data.error ? data.error : data);
22
+ err.status = res.status;
23
+ throw err;
24
+ }
25
+ return data;
26
+ });
27
+ });
28
+ }
29
+
30
+ function _pageName() {
31
+ return (window.pageInfo && window.pageInfo.name) || 'default';
32
+ }
33
+
34
+ window.synthos = {
35
+ data: {
36
+ list: function(table, opts) {
37
+ var url = '/api/data/' + encodeURIComponent(_pageName()) + '/' + encodeURIComponent(table);
38
+ if (opts && typeof opts.limit === 'number') {
39
+ url += '?limit=' + opts.limit;
40
+ if (typeof opts.offset === 'number') {
41
+ url += '&offset=' + opts.offset;
42
+ }
43
+ }
44
+ return _json('GET', url) || [];
45
+ },
46
+ get: function(table, id) {
47
+ return _json('GET', '/api/data/' + encodeURIComponent(_pageName()) + '/' + encodeURIComponent(table) + '/' + encodeURIComponent(id)) || null;
48
+ },
49
+ save: function(table, row) {
50
+ return _json('POST', '/api/data/' + encodeURIComponent(_pageName()) + '/' + encodeURIComponent(table), row);
51
+ },
52
+ remove: function(table, id) {
53
+ return _json('DELETE', '/api/data/' + encodeURIComponent(_pageName()) + '/' + encodeURIComponent(table) + '/' + encodeURIComponent(id));
54
+ }
55
+ },
56
+
57
+ generate: {
58
+ image: function(opts) {
59
+ return _json('POST', '/api/generate/image', opts);
60
+ },
61
+ completion: function(opts) {
62
+ return _json('POST', '/api/generate/completion', opts);
63
+ }
64
+ },
65
+
66
+ scripts: {
67
+ run: function(id, variables) {
68
+ return _json('POST', '/api/scripts/' + encodeURIComponent(id), variables || {});
69
+ }
70
+ },
71
+
72
+ pages: {
73
+ list: function() {
74
+ return _json('GET', '/api/pages');
75
+ },
76
+ get: function(name) {
77
+ return _json('GET', '/api/pages/' + encodeURIComponent(name));
78
+ },
79
+ update: function(name, metadata) {
80
+ return _json('POST', '/api/pages/' + encodeURIComponent(name), metadata);
81
+ },
82
+ remove: function(name) {
83
+ return _json('DELETE', '/api/pages/' + encodeURIComponent(name));
84
+ }
85
+ },
86
+
87
+ search: {
88
+ web: function(query, opts) {
89
+ var body = { query: query };
90
+ if (opts) {
91
+ if (opts.count) body.count = opts.count;
92
+ if (opts.country) body.country = opts.country;
93
+ if (opts.freshness) body.freshness = opts.freshness;
94
+ }
95
+ return _json('POST', '/api/search/web', body);
96
+ }
97
+ },
98
+
99
+ connectors: {
100
+ call: function(connector, method, path, opts) {
101
+ var body = { connector: connector, method: method, path: path };
102
+ if (opts) {
103
+ if (opts.headers) body.headers = opts.headers;
104
+ if (opts.body) body.body = opts.body;
105
+ if (opts.query) body.query = opts.query;
106
+ }
107
+ return _json('POST', '/api/connectors', body);
108
+ },
109
+ list: function(opts) {
110
+ var url = '/api/connectors';
111
+ var params = [];
112
+ if (opts) {
113
+ if (opts.category) params.push('category=' + encodeURIComponent(opts.category));
114
+ if (opts.id) params.push('id=' + encodeURIComponent(opts.id));
115
+ }
116
+ if (params.length) url += '?' + params.join('&');
117
+ return _json('GET', url);
118
+ }
119
+ }
120
+ };
121
+ })();