GithubHelp home page GithubHelp logo

formio-cli's Introduction

The Form.io Command Line Interface

This project is the command line interface for Form.io, which allows you to quickly bootstrap full working projects as well as interface with the Form.io API.

Installation

Installation is easy... Simply type the following in your command line.

npm install -g @formio/cli

Commands

Migrate

formio migrate <source> [<transformer>] <destination> --src-key [SOURCE_API_KEY] --dst-key [DESTINATION_API_KEY]

The migrate command allows you to migrate submission data from one source to another using a simple command. You can either migrate data from a CSV into a form, or from a form into another form. This works by taking the data from <source>, sending it through a middleware function called <transformer> (which you provide) that transforms the data into the correct format, and then saving that data as a submission into the <destination> form. If you are migrating data from one form to the same form within two different projects, you will just provide form as your transform and your command would be as follows.

formio migrate <source> form <destination> --src-key [SOURCE_API_KEY] --dst-key [DESTINATION_API_KEY]

As an example, if you wish to move submission data from one form in a project to your remotely deployed project. You can use the following command.

formio migrate https://myproject.form.io/myform form https://formio.mydomain.com/myproject/myform --src-key abc1234 --dst-key cde2468

Where you would replace the domains of your from and to, but also need to replace the src-key and dst-key with the API Keys from the from project and API key of your destination project respectively.

Migrating an entire project

You can also migrate an entire project by using the "project" transform as follows.

formio migrate https://myproject.form.io project https://forms.mydomain.com/myproject --src-key=abc1234 --dst-key=cde2468

Migrating from CSV

In many cases, you may wish to migrate data from a local CSV file into a project submission table. This requires the transform middleware where you will map the columns of your CSV file into the Submission data going into Form.io.

Example: Let's suppose you have the following CSV file of data.

import.csv

First Name, Last Name, Email
Joe, Smith, [email protected]
Jane, Thompson, [email protected]
Terry, Jones, [email protected]

And now you wish to import all of that data into a form. You can create the transform file like the following.

transform.js

var header = true;
module.exports = function(record, next) {
  if (header) {
    // Ignore the header row.
    header = false;
    return next();
  }
  next(null, {
    data: {
      firstName: record[0],
      lastName: record[1],
      email: record[2]
    }
  });
};

This transform middleware file can be a complete Node.js middleware method and works asynchronously so if you need to perform asynchronous behavior, you can do that by only calling the next function when the record is ready.

You can now migrate that data into your form with the following command.

formio migrate import.csv transform.js https://myproject.form.io/myform --key [YOUR_API_KEY]

Migrate and Delete

In many cases, when you migrate, you may wish to delete previous submissions during the migration phase. You can do this by adding the following option to your command.

--delete-previous

For example, the following will perform a migration and delete any previous migration records during the migration.

formio migrate https://myproject.form.io project https://forms.mydomain.com/myproject --src-key=abc1234 --dst-key=cde2468 --delete-previous

Migrate and Delete Before and After

You can also provide a window of records that should be deleted using the --delete-after and --delete-before flags. The values should be in the format 2022-05-30T12:00:00.000Z. For example, if you wish to migrate your data, but also remove any records before 2022-05-30T09:00:00.000Z and 2022-05-30T12:00:00.000Z, you would provide the following command.

formio migrate https://myproject.form.io project https://forms.mydomain.com/myproject --src-key=abc1234 --dst-key=cde2468 --delete-after=2022-05-30T09:00:00.000Z --delete-before=2022-05-30T12:00:00.000Z --delete-previous

Clone

formio clone <source_db> <destination_db> --src-project=[PROJECT_ID]

Clones a project from one database into another, and includes all forms, submissions, and every other resources within the project. This command also retains any _id's from the source database.

Clone Multiple Projects

It is also possible to clone multiple projects at the same time by providing a comma separated list of the project ids, like this.

formio clone <source_db> <destination_db> --src-project=234234234234,345345345345345,45456456456456

Clone only records created after a certain date

You can also clone only the records that have been created after a certain ISO Timestamp. This is useful if you wish to perform multiple migrations and only wish to clone records since the last clone command was called.

formio clone <source_db> <destination_db> --src-project=[PROJECT_ID] --created-after=2342342342

Clone Submissions

formio clone -o <source_db> <destination_db> --src-project=[PROJECT_ID]

This command only clones the submissions from one environment to another.

Deploy

formio deploy [src] [dst]

You can deploy a project on a paid plan on form.io to a hosted server with this command. Specify the source and destination servers and the project will be created or updated on the destination server.

Examples:

// A project without a server is implied from https://form.io
formio deploy myproject http://myproject.localhost:3000

// Projects can be specified with a subdomain.
formio deploy https://myproject.form.io http://myproject.localhost:3000

// Projects can also be referred to with their project id which will need to be looked up.
formio deploy https://form.io/project/{projectId} http://localhost:3000/project/{projectId}

Each server will require authentication so you will be asked twice, once for the source and once for the destination. These can also be specified with --src-username, --src-password, --dst-username, --dst-password.

Copy

formio copy form [src] [dest]

This command will copy the components of a form into another form. This will overwrite all components within the destination form if that form exists. You can also chain together multiple source forms which will aggregate the components of those forms into the destination form.

Examples:

// Copy a form from one project to another.
formio copy form https://myapp.form.io/myform https://myotherapp.form.io/myform

// Aggregate multiple forms into the same form.
formio copy form https://myapp.form.io/form1,https://myapp.form.io/form2 https://myapp.form.io/allforms

formio-cli's People

Contributors

alexeydavyd avatar brendanbond avatar dependabot[bot] avatar lane-formio avatar mikekotikov avatar randallknutson avatar ryanformio avatar tmy2017 avatar travist avatar vinothsubramanian avatar zackurben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

formio-cli's Issues

[BUG] Error running deploy command

Environment

Please provide as many details as you can:

  • Hosting type
    • Form.io
    • On-premise environment
    • Local deployment
      • Version:
  • Formio.js version: 7.0.0-rc46

Steps to Reproduce

  1. Run
    ./bin/formio deploy --src-username USER --src-password PASSWORD --username USERNAME --password PASSWORD https://portal.form.io/project/5e861xxxxx20ec06daxxx5f2/ https://forms.example.com/project/5fa465b7bxxx9c7689xxxxd7/

Expected behavior

The deploy command finish sucessufly

Observed behavior

The following error:

Authenticating to https://form.io
Authentication successful

This action requires a login to DESTINATION::https://forms.example.com.

Authenticating to https://forms.example.com
Authentication successful
Exporting Template
Error: <html>
<head><title>404 Not Found</title></head>
<body>
<h1>404 Not Found</h1>
<ul>
<li>Code: NoSuchKey</li>
<li>Message: The specified key does not exist.</li>
<li>Key: project/5e8618469020xxx6da7xxxf2/export</li>
<li>RequestId: E4291F33333C167C</li>
<li>HostId: GhyHVmVqTxEKAVexxxxxxxxMmG+CHMVVUNTJKJ54vi+cF4xxxxxxxxxqrHnmMCpwjPK3+js=</li>
</ul>
<hr/>
</body>
</html>

Steps to Reproduce

If the web URL is used (notice the \#/ part added):
./bin/formio deploy --src-username USERNAME --src-password PASSWORD --username USERNAME --password PASSWORD https://portal.form.io/\#/project/xxxx18469020ec06daxxxxxx/ https://forms.example.com//\#/project/xxxxx5b7b39c9c7689xxxxxx/

Observed behavior

The following error:

This action requires a login to SOURCE::https://form.io#/project/xxxxxx469020ec06daxxxxxx/.

Authenticating to https://form.io#/project/xxxxxx469020ec06daxxxxxx/
Authentication successful

This action requires a login to DESTINATION::https://forms.example.com/#/project/5fa465b7b39c9c76893345d7/.

Authenticating to https://forms.example.com#/project/5fa465b7b39c9c76893345d7/
Authentication successful
Exporting Template
Importing Template
Updating Project
Error: Unexpected token " in JSON at position 0

[BUG] Error running migrate command

Environment

Please provide as many details as you can:

  • Hosting type
    • Form.io
    • On-premise environment
    • Local deployment
      • Version:
  • Formio.js version: 7.0.0-rc46

Steps to Reproduce

  1. Run
    ./bin/formio migrate https://portal.form.io/\#/project/xxxxxxxxx/form/aaaaaaa form https://forms.example.com/\#/project/xxxxxxxxx/form/aaaaaa/ --src-username USERNAME --src-password PASSWORD --username USERNAME --password PASSWORD

Expected behavior

The migrate command finish sucessufly

Observed behavior

The following error:

This action requires a login to SOURCE::https://form.io#/project/xxxxxxxx/form/aaaaaaaaa.

Authenticating to https://form.io#/project/5d95720e46ae113bad5db10b/form/5fa408bd2149cc648af23eb2
Authentication successful

This action requires a login to DESTINATION::https://forms.example.com#/project/xxxxxx/form/aaaaaaa/.

Authenticating to https://forms.example.com#/project/xxxxxx/form/aaaaaaa/
Authentication successful

Migrating to https://forms.example.com/#/project/xxxxxxxx/form/aaaaaaa/internal/streams/legacy.js:61
      throw er; // Unhandled stream error in pipe.
      ^

Error: Invalid JSON (Unexpected "!" at position 1 in state STOP)
    at Parser.proto.charError (/home/user/formio-cli/node_modules/jsonparse/jsonparse.js:90:16)
    at Parser.proto.write (/home/user/formio-cli/node_modules/jsonparse/jsonparse.js:267:27)
    at Stream.<anonymous> (/home/user/formio-cli/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/home/user/formio-cli/node_modules/through/index.js:26:11)
    at Request.ondata (internal/streams/legacy.js:19:31)
    at Request.emit (events.js:314:20)
    at IncomingMessage.<anonymous> (/home/user/formio-cli/node_modules/request/request.js:1073:12)
    at IncomingMessage.emit (events.js:314:20)
    at IncomingMessage.Readable.read (_stream_readable.js:508:10)
    at flow (_stream_readable.js:1008:34)

Error Upon Bind

Environment

Please provide as many details as you can: Trying to run the bind command as documented in the remote middleware docs.

  • Hosting type
    • Form.io
    • Local deployment
      • Version:
  • Formio.js version:
  • Frontend framework: N/A
  • Browser: N/A
  • Browser version: N/A

Steps to Reproduce

  1. Run the formio CLI bind command: formio bind POST https://project-slug.form.io/volunteerform/submission

Observed behavior

I am asks to authenticate and this works fine, however I then get an: Error: Unexpected server response: 400, and the remote middleware does not run. I also tried with simply https://project-slug.form.io/volunteerform (omitting the /submission).

Error: getaddrinfo ENOTFOUND formio.forms.example.com

When trying to run deploy or migrate commands I'm getting the error:

Error: getaddrinfo ENOTFOUND formio.forms.example.com

This is an on-premise formio environment, the url is i.e forms.example.com and the objective is to migrate a portal project (in portal.form.io) to an on-premise project but the script is adding the formio subdomain when trying to autheticate to the destination.

A workaround to this was to put an entry to the IP of the on-premise portal in /etc/hosts pointing to a domain with the formio part:

123.456.789.12	formio.forms.example.com

This way the destination authetication works and the deploy/migrate step starts. Is there a way to avoid the need to add the /etc/hosts entry?

[BUG] Error running migrate command

Environment

Please provide as many details as you can:

  • Hosting type
    • Form.io
    • On-premise environment
    • Local deployment
      • Version:
        • docker image: 7.0.0-rc.57
        • formio cli: 1.8.2
        • node version: v15.0.1
        • OS: MacOS 10.15.7 (19H15)

Steps to Reproduce

  1. run
    formio migrate https://project-x.form.io project https://forms.example.com/project-x --src-key API_KEY --dst-key API_KEY

Expected behavior

The migrate command finish sucessufly

Observed behavior

Migration fails with exception / error:

โžœ ~ formio migrate https://project-x.form.io project https://forms.example.com/project-x --src-key API_KEY --dst-key API_KEY

(node:46702) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)


/ / / | ___ _ __ _ __ ___ () ___ \
/ / | |_ / _ | '| '_ ` _ \ | |/ _ \ \
\ \ | | () | | | | | | | | _ | | () | / /
_|
| _
/|| || || ||()||___/ /_/

Welcome to the Form.io Command Line!

This action requires a login to SOURCE::https://form.io.
An API Key was provided. Authenticated as Project Owner.

This action requires a login to DESTINATION::https://example.com.
An API Key was provided. Authenticated as Project Owner.

Migrating to https://forms.example.com/project-x/admin
Migrating to https://forms.example.com/project-x/admin/login
Migrating to https://forms.example.com/project-x/csite........../usr/local/lib/node_modules/formio-cli/node_modules/async/dist/async.js:318
if (fn === null) throw new Error("Callback was already called.");
^

Error: Callback was already called.
at /usr/local/lib/node_modules/formio-cli/node_modules/async/dist/async.js:318:36
at Transformer. (/usr/local/lib/node_modules/formio-cli/src/migrate.js:152:16)
at Transformer.emit (node:events:327:20)
at finish (node:internal/streams/writable:734:10)
at processTicksAndRejections (node:internal/process/task_queues:80:21)

Separate credentials for destination are not used if source and destination are on same host

I want to copy data between forms on two different projects hosted on form.io. When running

formio migrate https://myprojecta.form.io/someform form https://myprojectb.form.io/someform --src-key abc1234 --dst-key cde2468

the CLI will use the src-key for both source and destination. The result is that reading the data from the source succeeds, but writing it to the destination results in "Unauthorized" errors.

The issue here is that the CLI currently assumes that all endpoints on the same hostname (in this case "form.io") use the same authentication (in src/authenticate.js line 200, the subdomain is not taken into account for the comparison).

I suggest that the whole URL is used in the comparison. If source and destination share the same credentials, the user can supply them twice as parameters.

bootstraping application outputs bad request

Hey,

I was trying to bootstrap an formion app using the following command.

formio bootstrap formio/formio-app-todo
formio bootstrap formio/formio-app-formio

I am getting bad request after I have enter the authentication information. Can you guys help me with this error ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.