@mongoosejs/studio 0.0.99 → 0.0.101

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.
@@ -103,10 +103,7 @@ async function summarizeChatThread(messages, authorization) {
103
103
  return response;
104
104
  });
105
105
 
106
- return await response.json().then(res => {
107
- console.log('Response', res);
108
- return res;
109
- });
106
+ return await response.json();
110
107
  }
111
108
 
112
109
  async function createChatMessageCore(messages, modelDescriptions, authorization) {
@@ -130,8 +127,5 @@ async function createChatMessageCore(messages, modelDescriptions, authorization)
130
127
  return response;
131
128
  });
132
129
 
133
- return await response.json().then(res => {
134
- console.log('Response', res);
135
- return res;
136
- });
130
+ return await response.json();
137
131
  }
@@ -12,13 +12,19 @@ const GetDashboardParams = new Archetype({
12
12
  evaluate: {
13
13
  $type: 'boolean'
14
14
  },
15
+ authorization: {
16
+ $type: 'string'
17
+ },
18
+ $workspaceId: {
19
+ $type: 'string'
20
+ },
15
21
  roles: {
16
22
  $type: ['string']
17
23
  }
18
24
  }).compile('GetDashboardParams');
19
25
 
20
26
  module.exports = ({ db }) => async function getDashboard(params) {
21
- const { dashboardId, evaluate, roles } = new GetDashboardParams(params);
27
+ const { $workspaceId, authorization, dashboardId, evaluate, roles } = new GetDashboardParams(params);
22
28
  const Dashboard = db.model('__Studio_Dashboard');
23
29
 
24
30
  await authorize('Dashboard.getDashboard', roles);
@@ -26,14 +32,79 @@ module.exports = ({ db }) => async function getDashboard(params) {
26
32
  const dashboard = await Dashboard.findOne({ _id: dashboardId });
27
33
  if (evaluate) {
28
34
  let result = null;
35
+ const startExec = startDashboardExec(dashboardId, $workspaceId, authorization);
29
36
  try {
30
37
  result = await dashboard.evaluate();
31
38
  } catch (error) {
32
39
  return { dashboard, error: { message: error.message } };
33
40
  }
34
41
 
42
+ await startExec.then(({ dashboardResult }) => {
43
+ if (!dashboardResult) {
44
+ return;
45
+ }
46
+ return completeDashboardEvaluate(dashboardResult._id, $workspaceId, authorization, result);
47
+ });
48
+
35
49
  return { dashboard, result };
36
50
  }
37
51
 
38
52
  return { dashboard };
39
53
  };
54
+
55
+ async function completeDashboardEvaluate(dashboardResultId, workspaceId, authorization, result) {
56
+ if (!workspaceId) {
57
+ return {};
58
+ }
59
+ const headers = { 'Content-Type': 'application/json' };
60
+ if (authorization) {
61
+ headers.Authorization = authorization;
62
+ }
63
+ const response = await fetch('http://localhost:7777/.netlify/functions/completeDashboardEvaluate', {
64
+ method: 'POST',
65
+ headers,
66
+ body: JSON.stringify({
67
+ dashboardResultId,
68
+ workspaceId,
69
+ finishedEvaluatingAt: new Date(),
70
+ result
71
+ })
72
+ }).then(response => {
73
+ if (response.status < 200 || response.status >= 400) {
74
+ return response.json().then(data => {
75
+ throw new Error(`completeDashboardEvaluate error: ${data.message}`);
76
+ });
77
+ }
78
+ return response;
79
+ });
80
+
81
+ return await response.json();
82
+ }
83
+
84
+ async function startDashboardExec(dashboardId, workspaceId, authorization) {
85
+ if (!workspaceId) {
86
+ return {};
87
+ }
88
+ const headers = { 'Content-Type': 'application/json' };
89
+ if (authorization) {
90
+ headers.Authorization = authorization;
91
+ }
92
+ const response = await fetch('http://localhost:7777/.netlify/functions/startDashboardExec', {
93
+ method: 'POST',
94
+ headers,
95
+ body: JSON.stringify({
96
+ dashboardId,
97
+ workspaceId,
98
+ startedEvaluatingAt: new Date()
99
+ })
100
+ }).then(response => {
101
+ if (response.status < 200 || response.status >= 400) {
102
+ return response.json().then(data => {
103
+ throw new Error(`startDashboardExec error: ${data.message}`);
104
+ });
105
+ }
106
+ return response;
107
+ });
108
+
109
+ return await response.json();
110
+ }
@@ -24,7 +24,7 @@ const UpdateDocumentsParams = new Archetype({
24
24
  module.exports = ({ db }) => async function updateDocument(params) {
25
25
  const { model, _id, update, roles } = new UpdateDocumentsParams(params);
26
26
 
27
- await authorize('Document.updateDocument', roles);
27
+ await authorize('Model.updateDocument', roles);
28
28
 
29
29
  const Model = db.models[model];
30
30
  if (Model == null) {
@@ -58,6 +58,7 @@ module.exports = function netlify(conn, options) {
58
58
  throw new Error('Not authorized');
59
59
  }
60
60
 
61
+ params.$workspaceId = workspace._id;
61
62
  params.roles = roles;
62
63
  params.userId = user._id;
63
64
  }
package/express.js CHANGED
@@ -67,6 +67,7 @@ module.exports = async function(apiUrl, conn, options) {
67
67
  req._internals.authorization = authorization;
68
68
  req._internals.initiatedById = user._id;
69
69
  req._internals.roles = roles;
70
+ req._internals.$workspaceId = workspace._id;
70
71
 
71
72
  next();
72
73
  })
@@ -4005,7 +4005,7 @@ module.exports = "<div>\n <div class=\"mb-2\">\n <textarea class=\"border bo
4005
4005
  /***/ ((module) => {
4006
4006
 
4007
4007
  "use strict";
4008
- module.exports = "<div class=\"py-2 h-full\">\n <div v-if=\"header\" class=\"border-b border-gray-100 px-2 pb-2 text-xl font-bold\">\n {{header}}\n </div>\n <div class=\"text-xl py-2 h-full\">\n <canvas ref=\"chart\"></canvas>\n </div>\n</div>\n";
4008
+ module.exports = "<div>\n <div v-if=\"header\" class=\"border-b border-gray-100 px-2 pb-2 text-xl font-bold\">\n {{header}}\n </div>\n <div class=\"text-xl\">\n <canvas ref=\"chart\"></canvas>\n </div>\n</div>\n";
4009
4009
 
4010
4010
  /***/ }),
4011
4011
 
@@ -4038,7 +4038,7 @@ module.exports = "<div class=\"py-2\">\n <div v-if=\"header\" class=\"border-b
4038
4038
  /***/ ((module) => {
4039
4039
 
4040
4040
  "use strict";
4041
- module.exports = "<div>\n <div v-if=\"Array.isArray(result)\">\n <div v-for=\"el in result\">\n <component\n class=\"bg-white shadow-sm ring-1 ring-gray-900/5 sm:rounded-xl\"\n :is=\"getComponentForValue(res)\"\n :value=\"res\">\n </component>\n </div>\n </div>\n <div v-else>\n <component\n class=\"bg-white shadow-sm ring-1 ring-gray-900/5 sm:rounded-xl\"\n :is=\"getComponentForValue(result)\"\n :value=\"result\">\n </component>\n </div>\n</div>";
4041
+ module.exports = "<div>\n <div v-if=\"Array.isArray(result)\">\n <div v-for=\"el in result\">\n <component\n class=\"bg-white shadow-sm ring-1 ring-gray-900/5 sm:rounded-xl\"\n :is=\"getComponentForValue(res)\"\n :value=\"res\">\n </component>\n </div>\n </div>\n <div v-else>\n <component\n class=\"bg-white shadow-sm ring-1 ring-gray-900/5 sm:rounded-xl\"\n :is=\"getComponentForValue(result)\"\n :value=\"result\">\n </component>\n </div>\n</div>\n";
4042
4042
 
4043
4043
  /***/ }),
4044
4044
 
@@ -14574,7 +14574,7 @@ var bson = /*#__PURE__*/Object.freeze({
14574
14574
  /***/ ((module) => {
14575
14575
 
14576
14576
  "use strict";
14577
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.0.99","description":"A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.","homepage":"https://studio.mongoosejs.io/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"dependencies":{"archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"0.0.26","marked":"15.0.12","node-inspect-extracted":"3.x","tailwindcss":"3.4.0","vanillatoasts":"^1.6.0","vue":"3.x","webpack":"5.x"},"peerDependencies":{"bson":"^5.5.1 || 6.x","express":"4.x","mongoose":"7.x || 8.x"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","eslint":"9.30.0","express":"4.x","mocha":"10.2.0","mongoose":"8.x"},"scripts":{"lint":"eslint .","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js"}}');
14577
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.0.101","description":"A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.","homepage":"https://studio.mongoosejs.io/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"dependencies":{"archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"0.0.26","marked":"15.0.12","node-inspect-extracted":"3.x","tailwindcss":"3.4.0","vanillatoasts":"^1.6.0","vue":"3.x","webpack":"5.x"},"peerDependencies":{"bson":"^5.5.1 || 6.x","express":"4.x","mongoose":"7.x || 8.x"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","eslint":"9.30.0","express":"4.x","mocha":"10.2.0","mongoose":"8.x"},"scripts":{"lint":"eslint .","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js"}}');
14578
14578
 
14579
14579
  /***/ })
14580
14580
 
@@ -1,8 +1,8 @@
1
- <div class="py-2 h-full">
1
+ <div>
2
2
  <div v-if="header" class="border-b border-gray-100 px-2 pb-2 text-xl font-bold">
3
3
  {{header}}
4
4
  </div>
5
- <div class="text-xl py-2 h-full">
5
+ <div class="text-xl">
6
6
  <canvas ref="chart"></canvas>
7
7
  </div>
8
8
  </div>
@@ -15,4 +15,4 @@
15
15
  :value="result">
16
16
  </component>
17
17
  </div>
18
- </div>
18
+ </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.0.99",
3
+ "version": "0.0.101",
4
4
  "description": "A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.",
5
5
  "homepage": "https://studio.mongoosejs.io/",
6
6
  "repository": {