@mongoosejs/studio 0.2.7 → 0.2.9

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.
@@ -66,7 +66,7 @@ module.exports = ({ db }) => async function getDashboard(params) {
66
66
  );
67
67
  });
68
68
 
69
- return { dashboard, dashboardResult };
69
+ return { dashboard, dashboardResult, result };
70
70
  } catch (error) {
71
71
  return { dashboard, error: { message: error.message } };
72
72
  }
package/backend/next.js CHANGED
@@ -5,9 +5,66 @@ const Backend = require('./');
5
5
  module.exports = function next(conn, options) {
6
6
  const backend = Backend(conn, options?.studioConnection, options);
7
7
 
8
- return function wrappedNextJSFunction(req, res) {
9
- const params = { ...req.query, ...req.body, ...req.params };
8
+ const mothershipUrl = options?._mothershipUrl || 'https://mongoose-js.netlify.app/.netlify/functions';
9
+ let workspace = null;
10
+
11
+ return async function wrappedNextJSFunction(req, res) {
12
+ const params = { ...req.query, ...req.body, ...req.params, authorization: req.headers.authorization };
10
13
  const actionName = params?.action;
14
+
15
+ const authorization = params?.authorization;
16
+ if (options?.apiKey) {
17
+ if (!authorization) {
18
+ throw new Error('Not authorized');
19
+ }
20
+
21
+ if (workspace == null) {
22
+ ({ workspace } = await fetch(`${mothershipUrl}/getWorkspace`, {
23
+ method: 'POST',
24
+ body: JSON.stringify({ apiKey: options.apiKey }),
25
+ headers: {
26
+ Authorization: `Bearer ${options.apiKey}`,
27
+ 'Content-Type': 'application/json'
28
+ }
29
+ })
30
+ .then(response => {
31
+ if (response.status < 200 || response.status >= 400) {
32
+ return response.json().then(data => {
33
+ throw new Error(`Error getting workspace ${response.status}: ${require('util').inspect(data)}`);
34
+ });
35
+ }
36
+ return response;
37
+ })
38
+ .then(res => res.json()));
39
+ }
40
+
41
+ const { user, roles } = await fetch(`${mothershipUrl}/me?`, {
42
+ method: 'POST',
43
+ body: JSON.stringify({ workspaceId: workspace._id }),
44
+ headers: {
45
+ Authorization: authorization,
46
+ 'Content-Type': 'application/json'
47
+ }
48
+ })
49
+ .then(response => {
50
+ if (response.status < 200 || response.status >= 400) {
51
+ return response.json().then(data => {
52
+ throw new Error(`Mongoose Studio API Key Error ${response.status}: ${require('util').inspect(data)}`);
53
+ });
54
+ }
55
+ return response;
56
+ })
57
+ .then(res => res.json());
58
+ if (!user || !roles) {
59
+ throw new Error('Not authorized');
60
+ }
61
+
62
+ params.$workspaceId = workspace._id;
63
+ params.roles = roles;
64
+ params.userId = user._id;
65
+ params.initiatedById = user._id;
66
+ }
67
+
11
68
  if (typeof actionName !== 'string') {
12
69
  throw new Error('No action specified');
13
70
  }
@@ -24,7 +81,10 @@ module.exports = function next(conn, options) {
24
81
  }
25
82
 
26
83
  return actionFn(params)
27
- .then(result => res.status(200).json(result))
84
+ .then(result => {
85
+ res.status(200).json(result);
86
+ return result;
87
+ })
28
88
  .catch(error => res.status(500).json({ message: error.message }));
29
89
  };
30
90
  };
@@ -1996,9 +1996,9 @@ module.exports = app => app.component('create-document', {
1996
1996
  })) {
1997
1997
  if (event?.textPart) {
1998
1998
  this.aiSuggestion += event.textPart;
1999
- this.editor.setValue(this.aiSuggestion);
2000
1999
  }
2001
2000
  }
2001
+ this.editor.setValue(this.aiSuggestion);
2002
2002
  this.aiSuggestionReady = true;
2003
2003
  } catch (err) {
2004
2004
  this.editor.setValue(this.aiOriginalDocument);
@@ -2597,7 +2597,7 @@ module.exports = {
2597
2597
  this.code = this.dashboard.code;
2598
2598
  this.title = this.dashboard.title;
2599
2599
  this.description = this.dashboard.description ?? '';
2600
- this.dashboardResults = dashboardResults;
2600
+ this.dashboardResults = Array.isArray(dashboardResults) ? dashboardResults : [];
2601
2601
  if (this.shouldEvaluateDashboard()) {
2602
2602
  await this.evaluateDashboard();
2603
2603
  return;
@@ -35732,7 +35732,7 @@ module.exports = FilterXSS;
35732
35732
  (module) {
35733
35733
 
35734
35734
  "use strict";
35735
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.2.7","description":"A Mongoose-native MongoDB UI with schema-aware autocomplete, AI-assisted queries, and dashboards that understand your models - not just your data.","homepage":"https://mongoosestudio.app/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"license":"Apache-2.0","dependencies":{"@ai-sdk/anthropic":"2.x","@ai-sdk/google":"2.x","@ai-sdk/openai":"2.x","ai":"5.x","archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"^0.2.0","marked":"15.0.12","node-inspect-extracted":"3.x","tailwindcss":"3.4.0","vue":"3.x","vue-toastification":"^2.0.0-rc.5","webpack":"5.x","xss":"^1.0.15"},"peerDependencies":{"mongoose":"7.x || 8.x || ^9.0.0"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","dedent":"^1.6.0","eslint":"9.30.0","express":"4.x","mocha":"10.2.0","mongoose":"9.x","sinon":"^21.0.1"},"scripts":{"lint":"eslint .","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js","test:frontend":"mocha test/frontend/*.test.js"}}');
35735
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.2.9","description":"A Mongoose-native MongoDB UI with schema-aware autocomplete, AI-assisted queries, and dashboards that understand your models - not just your data.","homepage":"https://mongoosestudio.app/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"license":"Apache-2.0","dependencies":{"@ai-sdk/anthropic":"2.x","@ai-sdk/google":"2.x","@ai-sdk/openai":"2.x","ai":"5.x","archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"^0.2.0","marked":"15.0.12","node-inspect-extracted":"3.x","tailwindcss":"3.4.0","vue":"3.x","vue-toastification":"^2.0.0-rc.5","webpack":"5.x","xss":"^1.0.15"},"peerDependencies":{"mongoose":"7.x || 8.x || ^9.0.0"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","dedent":"^1.6.0","eslint":"9.30.0","express":"4.x","mocha":"10.2.0","mongoose":"9.x","sinon":"^21.0.1"},"scripts":{"lint":"eslint .","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js","test:frontend":"mocha test/frontend/*.test.js"}}');
35736
35736
 
35737
35737
  /***/ }
35738
35738
 
@@ -54,9 +54,9 @@ module.exports = app => app.component('create-document', {
54
54
  })) {
55
55
  if (event?.textPart) {
56
56
  this.aiSuggestion += event.textPart;
57
- this.editor.setValue(this.aiSuggestion);
58
57
  }
59
58
  }
59
+ this.editor.setValue(this.aiSuggestion);
60
60
  this.aiSuggestionReady = true;
61
61
  } catch (err) {
62
62
  this.editor.setValue(this.aiOriginalDocument);
@@ -127,7 +127,7 @@ module.exports = {
127
127
  this.code = this.dashboard.code;
128
128
  this.title = this.dashboard.title;
129
129
  this.description = this.dashboard.description ?? '';
130
- this.dashboardResults = dashboardResults;
130
+ this.dashboardResults = Array.isArray(dashboardResults) ? dashboardResults : [];
131
131
  if (this.shouldEvaluateDashboard()) {
132
132
  await this.evaluateDashboard();
133
133
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "A Mongoose-native MongoDB UI with schema-aware autocomplete, AI-assisted queries, and dashboards that understand your models - not just your data.",
5
5
  "homepage": "https://mongoosestudio.app/",
6
6
  "repository": {