Skip to content

curvegrid/multibaas-for-google-sheets

Repository files navigation

logo

MultiBaas for Google Sheets

This spreadsheet plugin was originally developed as part of the ETHGlobal HackMoney hackathon, where it was called Sunset Supreme Spreadsheet Blockchain Plugin. We made the following submissions as part of our entry:

Prerequisite

You should deploy a MultiBaas instance before following steps below.

Developing

  • node.js v12.16.0 or higher
  • clasp

Install clasp globally

yarn global add @google/clasp

or if you use npm

npm install @google/clasp -g

Login using clasp login

clasp login
Warning: You seem to already be logged in *globally*. You have a ~/.clasprc.json
Logging in globally...
🔑 Authorize clasp by visiting this url:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2...redirect_uri=http%3A%2F%2Flocalhost%3A54929

Install local node.js packages

yarn install

or

npm install

Testing in a command

Spreadsheet

You need to prepare for a spreadsheet with small configuration.

Sheet Step 0 Sheet Step 1

Link Apps Script to GCP

Before you go, you need to enable Google Apps Script API first from Apps Script settings.

In order to run tests you need to link Apps Script project to GCP project.

Copy a Project number from GCP project settings.

GAS Step 0

Link Apps Script project to GCP project.

GAS Step 1 GAS Step 2

Credentials and Environments Variables

You need to create .client-secret.json, .credentials.json, .clasp.json, and .testSheet.json files

  • .client-secret.json and .credentials.json are used in auth.js
  • .clasp.json and .testSheet.json files are used in mbSheetsAddOn.js

.client-secret.json is to set your GCP project. You should download form credential settings as follows:

GCP Step 0 GCP Step 1 GCP Step 2 GCP Step 3

You need to replace a file name with .client-secret.json after downloading it.

{
  "installed": {
    "client_id": "[YOUR GCP PROJECT CLIENT ID]",
    "project_id": "[YOUR GCP PROJECT PROJECT ID]",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "[YOUR GCP PROJECT CLIENT SECRET]",
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob",
      "http://localhost"
    ]
  }
}

.clasp.json is to set your Apps Script project after you create a new one.

{"scriptId": "[YOUR APPS SCRIPT ID]"}

.testSheet.json file in the project root is to set a test sheet URL.

{"url": "[YOUR SPREADSHEET URL]"}

Run yarn test.

yarn test

If you don't have .credentials.json then you will see this prompt:

yarn test
yarn run v1.22.10
$ clasp push && cd test && node mbSheetsAddOn.js
└─ appsscript.json
└─ src/Code.js
└─ src/Code.spec.js
└─ src/library/Build.js
└─ src/library/Property.js
└─ src/library/Query.js
└─ src/library/Util.js
└─ src/library/Validate.js
Pushed 8 files.
authorize this app by visiting this url: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fscript.external_request%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets&response_type=code&client_id=966627203108-e6125d7hosngl429qh6b52old6b7r98t.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob
Enter the code from that page here:

Just follow the URL and authenticate your account then you can retrieve a code to create .credentials.json file.

Linter

yarn lint