Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Environment.ts Updates [ Work in Progress ] #127

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .docker/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create database if not exists involvemint;

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# environment file
environment.ts

# Ignore package lock files
package-lock.json

# compiled output
/dist
/tmp
Expand Down
122 changes: 98 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,115 @@
# Official involveMINT Web App Repository

## Setting Up Environment
## Build Prerequisites

Prerequisites:

- Nodejs
- Postgres database named `involvemint` running on localhost port 5432 with username `postgres` and password `1Qazxsw2`
- Visual Studio Code
- Node.js
- Docker

### Steps
## Steps to Set Up Environment

1. Clone repository
1. Fork and clone this repository. Ensure that you uncheck the "copy main branch only" checkbox. Once you forked the repository, clone it to a directory on your local machine and `cd` into it.

```sh
git clone [email protected]:v3/involvemint/involveMINT/involvemint2.0
```
2. Checkout the "develop" branch: `git checkout develop`.
3. Ensure you have Node.js installed. If you don't, please look at the section on [installing node.js](#installing-nodejs).
4. Ensure you have Docker installed. If you don't, please navigate to the [official website](https://docs.docker.com/get-docker/) and follow the instructions. Run `docker --version` in your terminal after it's installed to ensure you have installed everything correctly.

2. Change directory into repository
### Installing Node.js

```sh
cd involvemint2.0
```
Run the following commands.

3. Install dependencies
1. `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash`
2. `export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"`
3. `[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"`
4. Refresh your shell (close and reopen). If you're using zsh, here's a shortcut: `source ~/.zshrc`
5. If the following command does not throw an error, you're good so far: `nvm -v`
6. `nvm install --lts`
7. `nvm use --lts`

```sh
npm install
```
### Configuring Firebase

4. Start client
In order to run this code, you will need to navigate to [firebase](https://console.firebase.google.com/). You will see a screen that looks like ![firebase-landing](/assets/firebase-landing.png) and click "Create a project" (if you don't already have a GCP account and an existing project where you want to use Firebase). Once you have a project, you should see a screen like ![this](assets/firebase-dashboard.png) Once here, click the little gear and you'll see a screen that looks like ![this](assets/firebase-settings.png) Select the "Service accounts" tab and you'll see a screen that looks like ![this](assets/firebase-service-accounts.png) Hit the "Manage service account permissions" hyperlink which will take you to your GCP project. You will see a screen that looks like ![this](/assets/googlecloud-service-accounts.png). Click the account and then hit the "Keys" tab. You should see a screen that looks like ![this](/assets/service-account-keys.png). Click "Add Key" and then choose the "JSON" option to download it as a JSON file.

```sh
npx ng s
```
Ensure you are in the project directory (the directory that this file is in). Run the following command: `cp libs/shared/domain/src/lib/environments/environment.ts libs/shared/domain/src/lib/environments/environment.prod.ts` and open the new file (environment.prod.ts) in your editor. It should look like this at first:

```typescript
import { Env } from './environment.interface';

5. In another terminal, start server
const host = 'localhost';

```sh
npx ng s api
/** Develop environment variables. */
export const environment: Env = {
production: false,
test: false,
host,
apiUrl: `http://${host}:3335`,
appUrl: `http://${host}:4202`,
storageBucket: 'your storage bucket',
adminPasswordHash:
'sZfCJx5X3sGSwkokIs9IVFxDfxWd2lEKsAhkOSDfEK8u2YS98y5rJAmXmtrJs7AQ29xkHMmz0bDfLkXCKS9/+A==',
gcpApiKey: 'insert your key here',
typeOrmConfig: {
type: 'postgres',
host: '127.0.0.1',
port: 5432,
username: 'postgres',
password: '1Qazxsw2',
database: 'involvemint',
synchronize: true,
autoLoadEntities: true,
ssl: false,
},
firebaseEnv: {
apiKey: 'insert your key here',
authDomain: 'firebase auth domain',
databaseURL: '',
projectId: 'your project id',
storageBucket: 'Your project storage bucket', //your-something.appspot.com
messagingSenderId: '',
appId: 'your app id',
measurementId: 'Your measurementId',
},
// mailgun and twilio are optional
mailgun: {
apiKey: '',
domain: '',
},
twilio: {
accountSid: '',
authToken: '',
sendingPhone: '',
},
gcp: {
type: 'service_account',
project_id: 'project-id',
private_key_id: 'Your Private Key',
private_key: '-----BEGIN PRIVATE KEY-----\nYour Private Key\n-----END PRIVATE KEY-----\n',
client_email: 'Your client email',
client_id: 'client 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_x509_cert_url: 'cert url',
},
// I don't think this is used
scrypt: {
memCost: 14,
rounds: 8,
saltSeparator: 'Bw==',
signerKey: 'de/PQ/Gy53mgslvUgDUKDCgHJPArYqbFnGILLQZNe5My/CvqIThVL/CsndU8oudZ9lc4B7PT8w3sAar2/luQxA==',
},
};
```

Under the key "typeOrmConfig", please change the password field to "postgres". Under the key "gcp", please change the fields to match the fields in your service account JSON file that you just downloaded in the previous step.

### Starting the Containers

Run `docker compose up` in the root directory, which will spin up a PostgreSQL database on port 5432 and a PgAdmin UI on port 8889.

### Starting the Apps

Open a terminal and run `npm i` to install all the required packages. Once done, run `export NODE_OPTIONS=--openssl-legacy-provider` because otherwise there will be an error with OpenSSL. To start the client, run `npm run start:client`. To start the server, open a new terminal, export the same environment variable as before (`export NODE_OPTIONS=--openssl-legacy-provider`), run `npm run build`, and then `npm run start`.

For any issues, or to suggest improvements to this documentation, please contact Anish Sinha <<[email protected]>>
39 changes: 39 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@
"maximumError": "10kb"
}
]
},
"org": {
"fileReplacements":[
{
"replace": "libs/shared/domain/src/lib/environments/environment.ts",
"with": "libs/shared/domain/src/lib/environments/environment.org.ts"
}
]
}
}
},
Expand All @@ -115,6 +123,9 @@
},
"test": {
"browserTarget": "involvemint:build:test"
},
"org": {
"browserTarget": "involvemint:build:org"
}
}
},
Expand Down Expand Up @@ -158,6 +169,9 @@
},
"test": {
"devServerTarget": "involvemint:serve:test"
},
"org": {
"devServerTarget": "involvemint:serve"
}
}
},
Expand Down Expand Up @@ -192,6 +206,10 @@
{
"replace": "libs/shared/domain/src/lib/environments/environment.ts",
"with": "libs/shared/domain/src/lib/environments/environment.prod.ts"
},
{
"replace": "libs/shared/domain/src/lib/environments/environment.api.ts",
"with": "libs/shared/domain/src/lib/environments/environment.prod.api.ts"
}
]
},
Expand All @@ -203,6 +221,22 @@
{
"replace": "libs/shared/domain/src/lib/environments/environment.ts",
"with": "libs/shared/domain/src/lib/environments/environment.test.ts"
},
{
"replace": "libs/shared/domain/src/lib/environments/environment.api.ts",
"with": "libs/shared/domain/src/lib/environments/environment.test.api.ts"
}
]
},
"org": {
"fileReplacements":[
{
"replace": "libs/shared/domain/src/lib/environments/environment.ts",
"with": "libs/shared/domain/src/lib/environments/environment.org.ts"
},
{
"replace": "libs/shared/domain/src/lib/environments/environment.api.ts",
"with": "libs/shared/domain/src/lib/environments/environment.org.api.ts"
}
]
}
Expand All @@ -213,6 +247,11 @@
"options": {
"buildTarget": "api:build",
"port": 2324
},
"configurations": {
"org":{
"buildTarget": "api:build:org"
}
}
},
"lint": {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { environment } from '@involvemint/shared/domain';
import { apiEnvironment, environment } from '@involvemint/shared/domain';
import { NestFactory } from '@nestjs/core';
import * as admin from 'firebase-admin';
import {
Expand All @@ -10,7 +10,7 @@ import { AppModule } from './app/app.module';
initializeTransactionalContext();
patchTypeORMRepositoryWithBaseRepository();

admin.initializeApp({ credential: admin.credential.cert(environment.gcp) });
admin.initializeApp({ credential: admin.credential.cert(apiEnvironment.gcp) });

async function bootstrap() {
// const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
Expand Down
3 changes: 2 additions & 1 deletion apps/migrate/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '@involvemint/server/core/domain-services';
import {
Address,
apiEnvironment,
ChangeMaker,
Credit,
Enrollment,
Expand Down Expand Up @@ -855,7 +856,7 @@ export class AppService {
return null;
}

const geo = geocoder.default({ provider: 'google', apiKey: environment.gcpApiKey });
const geo = geocoder.default({ provider: 'google', apiKey: apiEnvironment.gcpApiKey });
const res = await geo.geocode(address);

const a = res[0];
Expand Down
Binary file added assets/firebase-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/firebase-landing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/firebase-service-accounts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/firebase-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/googlecloud-service-accounts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/service-account-keys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
postgres:
hostname: postgres
container_name: postgres
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_INITDB_ARGS: '-A md5'
ports:
- '5432:5432'
volumes:
- ./.docker/init.sql:/docker-entrypoint-initdb.d/init.sql
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: involvemint
ports:
- '8889:80'
hostname: pgadmin
depends_on:
- postgres
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
HandleRepository,
} from '@involvemint/server/core/domain-services';
import {
apiEnvironment,
BaSubmitEpApplicationDto,
defaultStorefrontListingStatus,
environment,
Expand Down Expand Up @@ -172,7 +173,7 @@ export class EpApplicationService {
user: { id: true, changeMaker: { firstName: true } },
});

const geo = geocoder.default({ provider: 'google', apiKey: environment.gcpApiKey });
const geo = geocoder.default({ provider: 'google', apiKey: apiEnvironment.gcpApiKey });
const res = await geo.geocode(Object.entries(epApp.address).join(' '));

const lat = Number(res[0]?.latitude?.toFixed(4));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExchangePartnerRepository } from '@involvemint/server/core/domain-services';
import {
apiEnvironment,
DeleteEpImageDto,
EditEpProfileDto,
environment,
Expand Down Expand Up @@ -79,7 +80,7 @@ export class ExchangePartnerService {
}

if (dto.changes.address) {
const geo = geocoder.default({ provider: 'google', apiKey: environment.gcpApiKey });
const geo = geocoder.default({ provider: 'google', apiKey: apiEnvironment.gcpApiKey });
const res = await geo.geocode(Object.entries(dto.changes.address).join(' '));
dto.changes.latitude = Number(res[0]?.latitude?.toFixed(4));
dto.changes.longitude = Number(res[0]?.longitude?.toFixed(4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SpApplicationRepository,
} from '@involvemint/server/core/domain-services';
import {
apiEnvironment,
environment,
ImConfig,
ProcessSpApplicationDto,
Expand Down Expand Up @@ -99,7 +100,7 @@ export class SpApplicationService {
user: { id: true, changeMaker: { firstName: true } },
});

const geo = geocoder.default({ provider: 'google', apiKey: environment.gcpApiKey });
const geo = geocoder.default({ provider: 'google', apiKey: apiEnvironment.gcpApiKey });
const res = await geo.geocode(Object.entries(spApp.address).join(' '));

const lat = Number(res[0]?.latitude?.toFixed(4));
Expand Down
5 changes: 4 additions & 1 deletion libs/shared/domain/src/lib/environments/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
environment.prod.ts
environment.prod.api.ts
environment.test.ts
environment.ts
environment.test.api.ts
environment.org.ts
environment.org.api.ts
20 changes: 20 additions & 0 deletions libs/shared/domain/src/lib/environments/environment.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ServiceEnv } from "./environment.interface.api";
/** Develop environment variables. */
export const apiEnvironment: ServiceEnv = {
gcp: {
type: 'service_account',
project_id: 'project-id',
private_key_id: 'Your Private Key',
private_key:
'-----BEGIN PRIVATE KEY-----\nYour Private Key\n-----END PRIVATE KEY-----\n',
client_email: 'Your client email',
client_id: 'client 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_x509_cert_url:
'cert url',
},
gcpApiKey: 'insert your key here',
production: false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Environment file for api
* @type {{production: boolean; gcpApiKey: string; gcp: {}}}
*/
export interface ServiceEnv {
production: boolean;
gcpApiKey: string;
// eslint-disable-next-line @typescript-eslint/ban-types
gcp: object;
}
Loading