Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-aws-ses-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitij-k-osmosys committed Sep 27, 2024
2 parents 1c297cc + 8e866be commit 6131d33
Show file tree
Hide file tree
Showing 11 changed files with 4,607 additions and 4,371 deletions.
4 changes: 3 additions & 1 deletion apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ CLEANUP_IDLE_RESOURCES=false # Cleans up idle queues if inactive for the specifi
IDLE_TIMEOUT=30m # How long the queue should be idle before being considered for deletion, default 30m
CLEANUP_INTERVAL=7d # Frequency for running the cleanup, use formats from https://github.com/vercel/ms, default 7d
JWT_SECRET=your-strong-secret-key-here # A strong secret key for signing your JWTs. This should be a long, random string.
JWT_EXPIRES_IN=30d #Common formats are '60s', '10m', '1h', '1d', etc
JWT_EXPIRES_IN=30d # Common formats are '60s', '10m', '1h', '1d', etc
SALT_ROUNDS=10 # Number of salt rounds for bcrypt
API_KEY_SECRET=your-secret # Replace with a strong, unique secret for API authentication

# Node env
NODE_ENV= # Use "development" for graphql playground to work
Expand Down
8,650 changes: 4,367 additions & 4,283 deletions apps/api/OsmoX.postman_collection.json

Large diffs are not rendered by default.

30 changes: 4 additions & 26 deletions apps/api/docs/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ Note: Only users with `Admin` role get list of all keys. Returns `null` for user
mutation LoginUser {
login(loginUserInput: { username: "admin", password: "mysecurepassword" }) {
token
user
allKeys {
apiKeyId
apiKey
applicationId
status
}
__typename
}
}
Expand All @@ -42,9 +35,9 @@ mutation LoginUser {
**cURL**

```sh
curl --location 'http://localhost:3000/graphql' \
curl --location 'localhost:3000/graphql' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation LoginUser {\n login(loginUserInput: { username: \"admin\", password: \"mysecurepassword\" }) {\n token\n user\n allKeys {\n apiKeyId\n apiKey\n applicationId\n status\n }\n __typename\n }\n}","variables":{}}'
--data '{"query":"mutation LoginUser {\n login(loginUserInput: { username: \"admin\", password: \"mysecurepassword\" }) {\n token\n __typename\n }\n}","variables":{}}'
```

**Sample response**
Expand All @@ -53,22 +46,7 @@ curl --location 'http://localhost:3000/graphql' \
{
"data": {
"login": {
"token": "mysecuretoken",
"user": "admin",
"allKeys": [
{
"apiKeyId": 1,
"apiKey": "test-api-key",
"applicationId": 1,
"status": 1
},
{
"apiKeyId": 2,
"apiKey": "test-api-key-2",
"applicationId": 2,
"status": 1
}
],
"token": "eymysecuretoken",
"__typename": "LoginResponse"
}
}
Expand Down Expand Up @@ -186,7 +164,7 @@ query {
sortBy: "createdOn"
sortOrder: DESC
search: "[email protected]"
filters: [{ field: "channelType", operator: "eq", value: "1" }]
filters: [{ field: "applicationId", operator: "eq", value: "1" }]
}
) {
notifications {
Expand Down
4 changes: 3 additions & 1 deletion apps/api/docs/development-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ sudo systemctl status mariadb
IDLE_TIMEOUT=30m # How long the queue should be idle before being considered for deletion, default 30m
CLEANUP_INTERVAL=7d # Frequency for running the cleanup, use formats from https://github.com/vercel/ms, default 7d
JWT_SECRET=your-strong-secret-key-here # A strong secret key for signing your JWTs. This should be a long, random string.
JWT_EXPIRES_IN=30d #Common formats are '60s', '10m', '1h', '1d', etc
JWT_EXPIRES_IN=30d # Common formats are '60s', '10m', '1h', '1d', etc
SALT_ROUNDS=10 # Number of salt rounds for bcrypt
API_KEY_SECRET=your-secret # Replace with a strong, unique secret for API authentication
# Node env
NODE_ENV=development
Expand Down
4 changes: 3 additions & 1 deletion apps/api/docs/production-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Make sure Redis and MariaDB server are up and running.
IDLE_TIMEOUT=30m # How long the queue should be idle before being considered for deletion, default 30m
CLEANUP_INTERVAL=7d # Frequency for running the cleanup, use formats from https://github.com/vercel/ms, default 7d
JWT_SECRET=your-strong-secret-key-here # A strong secret key for signing your JWTs. This should be a long, random string.
JWT_EXPIRES_IN=30d #Common formats are '60s', '10m', '1h', '1d', etc
JWT_EXPIRES_IN=30d # Common formats are '60s', '10m', '1h', '1d', etc
SALT_ROUNDS=10 # Number of salt rounds for bcrypt
API_KEY_SECRET=your-secret # Replace with a strong, unique secret for API authentication
# Node env
NODE_ENV=production # Use "development" for graphql playground to work
Expand Down
36 changes: 26 additions & 10 deletions apps/portal/src/app/graphql/graphql.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,36 @@ export const GetNotifications = gql`
}
`;

export const GetApplications = gql`
query GetApplications($limit: Int!, $offset: Int!, $filters: [UniversalFilter!]) {
applications(
options: {
limit: $limit
offset: $offset
sortBy: "createdOn"
sortOrder: ASC
filters: $filters
}
) {
applications {
applicationId
createdOn
name
status
updatedOn
userId
}
total
offset
limit
}
}
`;

export const LoginUser = gql`
mutation LoginUser($username: String!, $password: String!) {
login(loginUserInput: { username: $username, password: $password }) {
token
user
allKeys {
apiKeyId
apiKey
applicationId
applicationDetails {
name
}
status
}
}
}
`;
15 changes: 15 additions & 0 deletions apps/portal/src/app/views/applications/application.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface Application {
applicationId: number;
name: string;
userId: number;
createdOn: Date;
updatedOn: Date;
status: number;
}

export interface ApplicationResponse {
applications: Application[];
total: number;
offset: number;
limit: number;
}
61 changes: 61 additions & 0 deletions apps/portal/src/app/views/applications/applications.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Injectable } from '@angular/core';
import { Observable, catchError, map } from 'rxjs';
import { GraphqlService } from 'src/app/graphql/graphql.service';
import { GetApplications } from 'src/app/graphql/graphql.queries';
import { ApolloQueryResult } from '@apollo/client/core';
import { Application, ApplicationResponse } from './application.model';

interface GetApplicationsResponse {
applications: {
applications?: Application[];
total?: number;
offset?: number;
limit?: number;
};
}
@Injectable({
providedIn: 'root',
})
export class ApplicationsService {
constructor(private graphqlService: GraphqlService) {}

getApplications(variables, inputToken): Observable<ApplicationResponse> {
return this.graphqlService.query(GetApplications, variables, inputToken).pipe(
map((response: ApolloQueryResult<GetApplicationsResponse>) => {
const applicationArray = response.data?.applications.applications;

const applicationResponseObject: ApplicationResponse = {
applications: applicationArray,
total: response.data?.applications.total,
offset: response.data?.applications.offset,
limit: response.data?.applications.limit,
};
return applicationResponseObject;
}),
catchError((error) => {
const errorMessage: string = error.message;
throw new Error(errorMessage);
}),
);
}

// eslint-disable-next-line class-methods-use-this
decodeToken(token: string): string {
try {
// Split the JWT token into its parts (Header, Payload, Signature)
const tokenArray = token.split('.');

if (tokenArray.length !== 3) {
throw new Error('Invalid JWT token');
}

// Decode the payload (the second part of the token)
const decodedPayload = atob(tokenArray[1]);

// Parse the decoded payload as JSON
return JSON.parse(decodedPayload);
} catch (error) {
throw new Error(`Error decoding token payload: ${error.message}`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 class="p-col-12">Notifications</h2>
class="grid-dropdown"
[showClear]="false"
(onChange)="loadNotificationsLazy({ first: 0, rows: this.pageSize })"
*ngIf="allApplicationsList.length !== 0"
*ngIf="applications.length !== 0"
></p-dropdown>
</div>
<div class="p-col-12 p-md-3 filter-row">
Expand Down
Loading

0 comments on commit 6131d33

Please sign in to comment.