# bend-sdk

> SDK for interacting with Bend data types

Latest version **0.1.0-alpha** (published 2021-12-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install bend-sdk
pnpm add bend-sdk
yarn add bend-sdk
bun add bend-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0-alpha |
| Published | 2021-12-28 |
| First published | 2021-12-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | thomasmost |

## Links

- npm: https://www.npmjs.com/package/bend-sdk
- Repository: https://github.com/Bend-Green/data-service
- Homepage: https://github.com/Bend-Green/data-service#readme
- Issues: https://github.com/Bend-Green/data-service/issues
- npm.io page: https://npm.io/package/bend-sdk

## Recent versions

- 0.1.0-alpha (latest) — 2021-12-28
- 0.1.3-alpha (alpha) — 2021-12-28
- 0.1.2-alpha — 2021-12-28
- 0.1.1-alpha — 2021-12-28

## README

## Development

Steps for new developers to get up and running with the Bend data-service

### Dependencies
You will need Rust, NodeJS, and a number of other tools to develop properly on the data-service and dash

1. Rust stable
2. NodeJS LTS
3. For formatting, you'll need `rustfmt`
  - `rustup component add rustfmt`

#### Setting up the database

1. Install Postgres
2. Install diesel for Postres: `cargo install diesel_cli --no-default-features --features postgres`
3. Copy `example.env` to `.env` (should just work with default local config)
4. Run `diesel setup`

#### Run the app

`cargo run`

## Dash

The Dash is a CRA app that can be used to interact with the API locally. It is not currently intended for production use. To get started, you'll need to run Quicktype to generate the schema.json file used by `processSchema.ts` and run the CRA app in a separate terminal from the one running the Rust back-end.

1. Start the server: `cargo.run`
2. In a separate terminal, run quicktype: `npm run quicktype`
3. Navigate to the dash: `cd dash`
4. Start the app: `npm run start`

## Publishing the Image

1. Install [Google Cloud SDK](https://cloud.google.com/sdk/docs/install)
2. Ensure you have access to the Container Registrar service account in GCP IAM & Admin
3. Run `gcloud auth login` using an account with access to the Container Registrar
4. Run `docker tag tcmoore/bend-api-service gcr.io/{PROJECT_ID}/api-service` (You can find the project id [here](https://console.cloud.google.com/home/dashboard))
5. Run `docker push gcr.io/bend-330614/api-service`

## DB Connectivity

Note that `bend-db` indicates the Cloud SQL instance, while `bend_db` indicates the postgres database name

### Setting up a new database

1. Create a new Postgres instance in Cloud SQL and store the root password somewhere secure
2. Wait for the instance to boot up, then connect:
3. Run `gcloud sql connect bend-db --user=postgres --project PROJECT_ID` and enter your password
4. You can now run `diesel setup`

- Using: `DATABASE_URL=postgres://postgres:{ROOT_PASSWORD}@{YOUR_DB_PUBLIC_IP}/bend_db`

### Running migrations

1. Run `gcloud sql connect bend-db --user=postgres --project PROJECT_ID` and enter your password
2. You can now run migrations for 5 minutes with Diesel with `diesel migration run`

- Using: `DATABASE_URL=postgres://postgres:{ROOT_PASSWORD}@{YOUR_DB_PUBLIC_IP}/bend-db`

### Connecting Cloud Run to Cloud SQL

Steps to connect to Cloud SQL from the api service in the cloud environment:

1. Ensure that a service account exists with the Cloud SQL Client permissions
2. Deploy a new revision of the Cloud Run instance with a Connection enabled (in the **Connections** tab) to the SQL instance
3. In Cloud Run, the DATABASE_URL must take a slightly different form to support the unix socket path

- `postgres://{USER}:{PASSWORD}@?host=/cloudsql/{CLOUD_SQL_CONNECTION_NAME}&dbname=bend_db`

See [Official Docs](https://cloud.google.com/sql/docs/postgres/connect-run) for additional details.

---
_Source: https://npm.io/package/bend-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
