Skip to content

CyberCRI/shared-projects-frontend

Repository files navigation

CC BY-NC-SA 4.0

shared-project-frontend

https://projects.directory.com

Front-end shared library for interacting with the projects-backend. This library centralizes API calls, data models, utility interfaces, and permission logic common to multiple applications.

📁 Project Structure

shared-project-frontend/

├── apis/                       # All backend API calls (TypeScript)
│   └── configureAPI   # Header and global config setup (via ofetch)
├── models/                  # Data models corresponding to the backend
├── interfaces/              # Utility interfaces shared throughout the application
└── lib/                         # Shared libraries (e.g., permission management)
    └── permissions.ts    # Access checks (modify/delete objects, organizations, etc.)

🚀 Installation

npm install shared-project-frontend
# or
yarn add shared-project-frontend

⚙️ API Configuration

Configure the ofetch instance before any usage:

import { configureOptionsAPI, configureClientAPI } from '@shared-projects-frontend/apis';

// optional, custom ofetch instance
const myofetch = ofetch.create(...)
configureClientAPI(myofetch)

// a callback called before each request
configureOptionsAPI(() => ({
  baseURL: 'my-base-url',
  headers: {
    'my default-header': 'my-default-value'
  }
}));

📦 Usage

API Call

import { getProjects, getUser, getOrganization, ... } from '@shared-projects-frontend/apis';

const projects = await getProjects();

Accessing Models

import type { Project, Organization, ... } from '@shared-projects-frontend/models';

const project: Project = /* ... */;

Utility Interfaces

import type { PaginatedResult, Query, .... } from '@shared-projects-frontend/interfaces';

Permissions

import { getAllProjects } from '@shared-projects-frontend/apis';
import { canEditProject, canDeleteOrganization, userRights } from '@shared-projects-frontend/lib';

const user = getUser()
const projects = getAllProjects()
const organization = getOrganization("LPI") 

const rights = userRights(user)

projects.forEach((project) => {
    if (canEditProject(rights, organization.id, project)) {
        // Allowed
    }
})

License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors