forest-cli 2.6.0 → 2.6.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [2.6.3](https://github.com/ForestAdmin/toolbelt/compare/v2.6.2...v2.6.3) (2022-03-28)
2
+
3
+ ## [2.6.2](https://github.com/ForestAdmin/toolbelt/compare/v2.6.1...v2.6.2) (2022-03-22)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * upgraded Mongoose version in order to resolve vulnerabilities ([#356](https://github.com/ForestAdmin/toolbelt/issues/356)) ([a1cbee1](https://github.com/ForestAdmin/toolbelt/commit/a1cbee17038d55728cf88e842ee320346ee46f47))
9
+
10
+ ## [2.6.1](https://github.com/ForestAdmin/toolbelt/compare/v2.6.0...v2.6.1) (2022-03-15)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **templates:** add link to performance doc in count route ([#355](https://github.com/ForestAdmin/toolbelt/issues/355)) ([f7ebd92](https://github.com/ForestAdmin/toolbelt/commit/f7ebd928121757a3c5f7ffa92327288b789a71ff))
16
+
1
17
  # [2.6.0](https://github.com/ForestAdmin/toolbelt/compare/v2.5.5...v2.6.0) (2022-02-21)
2
18
 
3
19
 
@@ -1 +1 @@
1
- {"version":"2.6.0","commands":{"branch":{"id":"branch","description":"Create a new branch or list your existing branches.","pluginName":"forest-cli","pluginType":"core","aliases":["branches"],"flags":{"projectId":{"name":"projectId","type":"option","description":"The id of the project to create a branch in."},"delete":{"name":"delete","type":"boolean","char":"d","description":"Delete the branch.","allowNo":false},"force":{"name":"force","type":"boolean","description":"When deleting a branch, skip confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the branch to create.","required":false}]},"deploy":{"id":"deploy","description":"Deploy layout changes of an environment to the reference one.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:deploy"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Skip deploy confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to deploy.","default":null}},"args":[{"name":"ENVIRONMENT_NAME","description":"The name of the environment containing the layout changes to deploy to the reference one.","required":false}]},"environments":{"id":"environments","description":"Manage environments.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:list"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"init":{"id":"init","description":"Set up your development environment in your current folder.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:init"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to init."}},"args":[]},"login":{"id":"login","description":"Sign in with an existing account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"email":{"name":"email","type":"option","char":"e","description":"Your Forest Admin account email."},"password":{"name":"password","type":"option","char":"P","description":"Your Forest Admin account password (ignored if token is set)."},"token":{"name":"token","type":"option","char":"t","description":"Your Forest Admin account token (replaces password)."}},"args":[]},"logout":{"id":"logout","description":"Sign out of your account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"projects":{"id":"projects","description":"Manage projects.","pluginName":"forest-cli","pluginType":"core","aliases":["projects:list"],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"push":{"id":"push","description":"Push layout changes of your current branch to a remote environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branches:push"],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to push onto."},"force":{"name":"force","type":"boolean","description":"Skip push changes confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"switch":{"id":"switch","description":"Switch to another branch in your local development environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branch:switch"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the local branch to set as current.","required":false}]},"user":{"id":"user","description":"Display the current logged in user.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"environments:copy-layout":{"id":"environments:copy-layout","description":"Copy the layout from one environment to another.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"force":{"name":"force","type":"boolean","char":"force","description":"Force copy.","allowNo":false}},"args":[{"name":"fromEnvironment","description":"Source environment ID.","required":true},{"name":"toEnvironment","description":"Target environment ID.","required":true}]},"environments:create":{"id":"environments:create","description":"Create a new environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"name":{"name":"name","type":"option","char":"n","description":"Environment name.","required":true},"url":{"name":"url","type":"option","char":"u","description":"Application URL.","required":true},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"environments:delete":{"id":"environments:delete","description":"Delete an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"force","description":"Force delete.","allowNo":false}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:get":{"id":"environments:get","description":"Get the configuration of an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Output format.","options":["table","json"],"default":"table"}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:reset":{"id":"environments:reset","description":"Reset a remote environment by removing all layout changes","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to reset."},"force":{"name":"force","type":"boolean","description":"Skip reset changes confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"environments:update":{"id":"environments:update","description":"Update an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environmentId":{"name":"environmentId","type":"option","char":"e","description":"The forest environment ID to update.","required":true},"name":{"name":"name","type":"option","char":"n","description":"To update the environment name.","required":false},"url":{"name":"url","type":"option","char":"u","description":"To update the application URL.","required":false}},"args":[]},"projects:create":{"id":"projects:create","description":"Create a Forest API.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"applicationHost":{"name":"applicationHost","type":"option","char":"H","description":"Hostname of your admin backend application.","required":false},"applicationPort":{"name":"applicationPort","type":"option","char":"P","description":"Port of your admin backend application.","required":false},"databaseConnectionURL":{"name":"databaseConnectionURL","type":"option","char":"c","description":"Enter the database credentials with a connection URL.","required":false},"databaseDialect":{"name":"databaseDialect","type":"option","char":"d","description":"Enter your database dialect.","required":false,"options":["mongodb","mssql","mysql","postgres"]},"databaseName":{"name":"databaseName","type":"option","char":"n","description":"Enter your database name.","required":false},"databaseHost":{"name":"databaseHost","type":"option","char":"h","description":"Enter your database host.","required":false},"databasePort":{"name":"databasePort","type":"option","char":"p","description":"Enter your database port.","required":false},"databaseUser":{"name":"databaseUser","type":"option","char":"u","description":"Enter your database user.","required":false},"databasePassword":{"name":"databasePassword","type":"option","description":"Enter your database password.","required":false},"databaseSchema":{"name":"databaseSchema","type":"option","char":"s","description":"Enter your database schema.","required":false},"databaseSSL":{"name":"databaseSSL","type":"boolean","description":"Use SSL for database connection.","required":false,"allowNo":false},"mongoDBSRV":{"name":"mongoDBSRV","type":"boolean","description":"Use SRV DNS record for mongoDB connection.","required":false,"allowNo":false}},"args":[{"name":"applicationName","description":"Name of the project to create.","required":true}]},"projects:get":{"id":"projects:get","description":"Get the configuration of a project.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[{"name":"projectId","description":"ID of a project.","required":true}]},"schema:apply":{"id":"schema:apply","description":"Apply the current schema of your repository to the specified environment (using your \".forestadmin-schema.json\" file).","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"secret":{"name":"secret","type":"option","char":"s","description":"Environment secret of the project (FOREST_ENV_SECRET).","required":false}},"args":[]},"schema:update":{"id":"schema:update","description":"Refresh your schema by generating files that do not currently exist.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Database configuration file to use.","required":false,"default":"config/databases.js"},"outputDirectory":{"name":"outputDirectory","type":"option","char":"o","description":"Output directory where to generate new files.","required":false}},"args":[]}}}
1
+ {"version":"2.6.3","commands":{"branch":{"id":"branch","description":"Create a new branch or list your existing branches.","pluginName":"forest-cli","pluginType":"core","aliases":["branches"],"flags":{"projectId":{"name":"projectId","type":"option","description":"The id of the project to create a branch in."},"delete":{"name":"delete","type":"boolean","char":"d","description":"Delete the branch.","allowNo":false},"force":{"name":"force","type":"boolean","description":"When deleting a branch, skip confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the branch to create.","required":false}]},"deploy":{"id":"deploy","description":"Deploy layout changes of an environment to the reference one.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:deploy"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Skip deploy confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to deploy.","default":null}},"args":[{"name":"ENVIRONMENT_NAME","description":"The name of the environment containing the layout changes to deploy to the reference one.","required":false}]},"environments":{"id":"environments","description":"Manage environments.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:list"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"init":{"id":"init","description":"Set up your development environment in your current folder.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:init"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to init."}},"args":[]},"login":{"id":"login","description":"Sign in with an existing account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"email":{"name":"email","type":"option","char":"e","description":"Your Forest Admin account email."},"password":{"name":"password","type":"option","char":"P","description":"Your Forest Admin account password (ignored if token is set)."},"token":{"name":"token","type":"option","char":"t","description":"Your Forest Admin account token (replaces password)."}},"args":[]},"logout":{"id":"logout","description":"Sign out of your account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"projects":{"id":"projects","description":"Manage projects.","pluginName":"forest-cli","pluginType":"core","aliases":["projects:list"],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"push":{"id":"push","description":"Push layout changes of your current branch to a remote environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branches:push"],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to push onto."},"force":{"name":"force","type":"boolean","description":"Skip push changes confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"switch":{"id":"switch","description":"Switch to another branch in your local development environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branch:switch"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the local branch to set as current.","required":false}]},"user":{"id":"user","description":"Display the current logged in user.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"environments:copy-layout":{"id":"environments:copy-layout","description":"Copy the layout from one environment to another.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"force":{"name":"force","type":"boolean","char":"force","description":"Force copy.","allowNo":false}},"args":[{"name":"fromEnvironment","description":"Source environment ID.","required":true},{"name":"toEnvironment","description":"Target environment ID.","required":true}]},"environments:create":{"id":"environments:create","description":"Create a new environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"name":{"name":"name","type":"option","char":"n","description":"Environment name.","required":true},"url":{"name":"url","type":"option","char":"u","description":"Application URL.","required":true},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"environments:delete":{"id":"environments:delete","description":"Delete an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"force","description":"Force delete.","allowNo":false}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:get":{"id":"environments:get","description":"Get the configuration of an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Output format.","options":["table","json"],"default":"table"}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:reset":{"id":"environments:reset","description":"Reset a remote environment by removing all layout changes","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to reset."},"force":{"name":"force","type":"boolean","description":"Skip reset changes confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"environments:update":{"id":"environments:update","description":"Update an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environmentId":{"name":"environmentId","type":"option","char":"e","description":"The forest environment ID to update.","required":true},"name":{"name":"name","type":"option","char":"n","description":"To update the environment name.","required":false},"url":{"name":"url","type":"option","char":"u","description":"To update the application URL.","required":false}},"args":[]},"projects:create":{"id":"projects:create","description":"Create a Forest API.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"applicationHost":{"name":"applicationHost","type":"option","char":"H","description":"Hostname of your admin backend application.","required":false},"applicationPort":{"name":"applicationPort","type":"option","char":"P","description":"Port of your admin backend application.","required":false},"databaseConnectionURL":{"name":"databaseConnectionURL","type":"option","char":"c","description":"Enter the database credentials with a connection URL.","required":false},"databaseDialect":{"name":"databaseDialect","type":"option","char":"d","description":"Enter your database dialect.","required":false,"options":["mongodb","mssql","mysql","postgres"]},"databaseName":{"name":"databaseName","type":"option","char":"n","description":"Enter your database name.","required":false},"databaseHost":{"name":"databaseHost","type":"option","char":"h","description":"Enter your database host.","required":false},"databasePort":{"name":"databasePort","type":"option","char":"p","description":"Enter your database port.","required":false},"databaseUser":{"name":"databaseUser","type":"option","char":"u","description":"Enter your database user.","required":false},"databasePassword":{"name":"databasePassword","type":"option","description":"Enter your database password.","required":false},"databaseSchema":{"name":"databaseSchema","type":"option","char":"s","description":"Enter your database schema.","required":false},"databaseSSL":{"name":"databaseSSL","type":"boolean","description":"Use SSL for database connection.","required":false,"allowNo":false},"mongoDBSRV":{"name":"mongoDBSRV","type":"boolean","description":"Use SRV DNS record for mongoDB connection.","required":false,"allowNo":false}},"args":[{"name":"applicationName","description":"Name of the project to create.","required":true}]},"projects:get":{"id":"projects:get","description":"Get the configuration of a project.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[{"name":"projectId","description":"ID of a project.","required":true}]},"schema:apply":{"id":"schema:apply","description":"Apply the current schema of your repository to the specified environment (using your \".forestadmin-schema.json\" file).","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"secret":{"name":"secret","type":"option","char":"s","description":"Environment secret of the project (FOREST_ENV_SECRET).","required":false}},"args":[]},"schema:update":{"id":"schema:update","description":"Refresh your schema by generating files that do not currently exist.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Database configuration file to use.","required":false,"default":"config/databases.js"},"outputDirectory":{"name":"outputDirectory","type":"option","char":"o","description":"Output directory where to generate new files.","required":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "forest-cli",
3
3
  "description": "The Lumberjacks' toolbelt is the Forest CLI which makes easy to manage your back office application directly from the terminal.",
4
- "version": "2.6.0",
4
+ "version": "2.6.3",
5
5
  "author": "Sandro Munda",
6
6
  "contributors": [
7
7
  "Arnaud Valensi <arnaud.valensi@gmail.com>",
@@ -82,12 +82,30 @@ class CreateCommand extends AbstractAuthenticatedCommand {
82
82
  this.exit(1);
83
83
  }
84
84
 
85
- const meta = {
85
+ this.eventSender.sessionToken = authenticationToken;
86
+ this.eventSender.meta = {
86
87
  dbDialect: dbConfig.dbDialect,
87
88
  agent: dbConfig.dbDialect === 'mongodb' ? 'express-mongoose' : 'express-sequelize',
88
- isLocal: ['localhost', '127.0.0.1', '::1'].includes(dbConfig.dbHostname),
89
+ isLocal: ['localhost', '127.0.0.1', '::1'].some((keyword) => (
90
+ dbConfig.dbHostname
91
+ ? dbConfig.dbHostname.includes(keyword)
92
+ : dbConfig.dbConnectionUrl.includes(keyword)
93
+ )),
89
94
  };
90
95
 
96
+ this.spinner.start({ text: 'Creating your project on Forest Admin' });
97
+ const projectCreationPromise = this.projectCreator.create(
98
+ authenticationToken, appConfig, this.eventSender.meta.agent,
99
+ );
100
+
101
+ const {
102
+ id, envSecret, authSecret,
103
+ } = await this.spinner.attachToPromise(projectCreationPromise);
104
+
105
+ this.eventSender.meta.projectId = id;
106
+ config.forestAuthSecret = authSecret;
107
+ config.forestEnvSecret = envSecret;
108
+
91
109
  let schema = {};
92
110
 
93
111
  this.spinner.start({ text: 'Connecting to your database' });
@@ -100,19 +118,6 @@ class CreateCommand extends AbstractAuthenticatedCommand {
100
118
  const disconnectPromise = this.database.disconnect(connection);
101
119
  await this.spinner.attachToPromise(disconnectPromise);
102
120
 
103
- this.spinner.start({ text: 'Creating your project on Forest Admin' });
104
- const projectCreationPromise = this.projectCreator.create(
105
- authenticationToken, appConfig, meta.agent,
106
- );
107
-
108
- const {
109
- id, envSecret, authSecret,
110
- } = await this.spinner.attachToPromise(projectCreationPromise);
111
-
112
- meta.projectId = id;
113
- config.forestAuthSecret = authSecret;
114
- config.forestEnvSecret = envSecret;
115
-
116
121
  this.spinner.start({ text: 'Creating your project files' });
117
122
  const dumperConfig = {
118
123
  ...dbConfig,
@@ -124,7 +129,7 @@ class CreateCommand extends AbstractAuthenticatedCommand {
124
129
  await this.spinner.attachToPromise(dumpPromise);
125
130
 
126
131
  this.logger.success(`Hooray, ${this.chalk.green('installation success')}!`);
127
- await this.eventSender.notifySuccess(authenticationToken, meta);
132
+ await this.eventSender.notifySuccess();
128
133
  }
129
134
 
130
135
  async analyzeDatabase(dbConfig, connection) {
@@ -62,7 +62,6 @@ function Api({
62
62
  try {
63
63
  newProject = await agent
64
64
  .post(`${this.endpoint()}/api/projects`)
65
- .set(HEADER_FOREST_ORIGIN, 'Lumber')
66
65
  .set(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_JSON)
67
66
  .set(HEADER_USER_AGENT, this.userAgent)
68
67
  .set('Authorization', `Bearer ${sessionToken}`)
@@ -79,7 +78,6 @@ function Api({
79
78
  newProject = await agent
80
79
  .get(`${this.endpoint()}/api/projects/${projectId}`)
81
80
  .set('Authorization', `Bearer ${sessionToken}`)
82
- .set(HEADER_FOREST_ORIGIN, 'Lumber')
83
81
  .set(HEADER_USER_AGENT, this.userAgent)
84
82
  .send()
85
83
  .then((response) => projectDeserializer.deserialize(response.body));
@@ -97,7 +95,6 @@ function Api({
97
95
  newProject.defaultEnvironment.apiEndpoint = `${protocol}${hostname}:${port}`;
98
96
  const updatedEnvironment = await agent
99
97
  .put(`${this.endpoint()}/api/environments/${newProject.defaultEnvironment.id}`)
100
- .set(HEADER_FOREST_ORIGIN, 'Lumber')
101
98
  .set(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_JSON)
102
99
  .set(HEADER_USER_AGENT, this.userAgent)
103
100
  .set('Authorization', `Bearer ${sessionToken}`)
@@ -126,7 +126,7 @@ class Dumper {
126
126
  dependencies.tedious = '^6.4.0';
127
127
  } else if (dbDialect === 'mongodb') {
128
128
  delete dependencies.sequelize;
129
- dependencies.mongoose = '~5.8.2';
129
+ dependencies.mongoose = '~5.13.9';
130
130
  }
131
131
  }
132
132
 
@@ -36,6 +36,7 @@ router.get('/{{ modelName }}', permissionMiddlewareCreator.list(), (request, res
36
36
  // Get a number of {{ modelNameReadablePlural }}
37
37
  router.get('/{{ modelName }}/count', permissionMiddlewareCreator.list(), (request, response, next) => {
38
38
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#get-a-number-of-records
39
+ // Improve peformances disabling pagination: https://docs.forestadmin.com/documentation/reference-guide/performance#disable-pagination-count
39
40
  next();
40
41
  });
41
42
 
@@ -1,63 +1,75 @@
1
- const superagent = require('superagent');
2
-
3
1
  class EventSender {
4
- constructor({ assertPresent, env }) {
5
- assertPresent({ env });
2
+ constructor({ assertPresent, env, superagent }) {
3
+ assertPresent({ env, superagent });
6
4
  this.env = env;
5
+ this.superagent = superagent;
7
6
 
8
7
  this.applicationName = null;
9
8
  this.command = null;
9
+ this.meta = null;
10
+ this.sessionToken = null;
10
11
  }
11
12
 
12
13
  async notifyError(code = 'unknown_error', message = null, context = undefined) {
13
14
  if (!this.applicationName || !this.command) { return; }
14
15
 
16
+ const attributes = {
17
+ code,
18
+ message,
19
+ project_name: this.applicationName,
20
+ command: this.command,
21
+ context,
22
+ };
23
+
24
+ if (this.command !== 'schema:update') {
25
+ attributes.project_id = this.meta.projectId || null;
26
+ attributes.db_dialect = this.meta.dbDialect;
27
+ attributes.agent = this.meta.agent;
28
+ attributes.is_local = this.meta.isLocal;
29
+ }
30
+
15
31
  try {
16
- await superagent.post(`${this.env.FOREST_URL}/api/lumber/error`, {
17
- data: {
18
- type: 'events',
19
- attributes: {
20
- code,
21
- message,
22
- project_name: this.applicationName,
23
- command: this.command,
24
- context,
32
+ if (this.sessionToken) {
33
+ await this.superagent.post(`${this.env.FOREST_URL}/api/lumber/error`, {
34
+ data: {
35
+ type: 'events',
36
+ attributes,
25
37
  },
26
- },
27
- });
38
+ }).set('Authorization', `Bearer ${this.sessionToken}`);
39
+ } else {
40
+ await this.superagent.post(`${this.env.FOREST_URL}/api/lumber/error`, {
41
+ data: {
42
+ type: 'events',
43
+ attributes,
44
+ },
45
+ });
46
+ }
28
47
  } catch (e) {
29
48
  // NOTICE: We want silent error because this is just for reporting error
30
49
  // and not not blocking if that does not work.
31
50
  }
32
51
  }
33
52
 
34
- async notifySuccess(sessionToken, {
35
- projectId, dbDialect, agent, isLocal,
36
- }) {
53
+ async notifySuccess() {
37
54
  if (
38
- !this.applicationName
39
- || !this.command
40
- || !projectId
41
- || !dbDialect
42
- || !agent
43
- || !!isLocal
55
+ !this.applicationName || !this.command || !this.sessionToken || !Object.keys(this.meta).length
44
56
  ) { return; }
45
57
 
46
58
  try {
47
- await superagent.post(`${this.env.FOREST_URL}/api/lumber/success`, {
59
+ await this.superagent.post(`${this.env.FOREST_URL}/api/lumber/success`, {
48
60
  data: {
49
61
  type: 'events',
50
62
  attributes: {
51
63
  command: this.command,
52
- project_id: projectId,
64
+ project_id: this.meta.projectId,
53
65
  project_name: this.applicationName,
54
- db_dialect: dbDialect,
55
- agent,
56
- is_local: isLocal,
66
+ db_dialect: this.meta.dbDialect,
67
+ agent: this.meta.agent,
68
+ is_local: this.meta.isLocal,
57
69
  },
58
70
  },
59
71
  })
60
- .set('Authorization', `Bearer ${sessionToken}`);
72
+ .set('Authorization', `Bearer ${this.sessionToken}`);
61
73
  } catch (e) {
62
74
  // NOTICE: We want silent error because this is just for reporting error
63
75
  // and not not blocking if that does not work.