@optisaas/opti-saas-lib
v0.1.9
Published
A shared library for Opti SaaS applications
Readme
@optisaas/opti-saas-lib
A shared TypeScript library for Opti SaaS applications, providing type-safe resource authorization management and shared utilities.
Installation
npm install @optisaas/opti-saas-lib
# or
yarn add @optisaas/opti-saas-lib
# or
pnpm add @optisaas/opti-saas-libFeatures
- 🔐 Type-safe Authorization System - Resource-based permissions with TypeScript type safety
- 🏥 Specialized Resources - Support for specialized resources with domain-specific authorizations
- 🎯 Client Helpers - Utility functions for authorization management
- 📦 Tree-shakeable - Optimized bundle size with ES modules
- 🔧 TypeScript First - Written in TypeScript with full type definitions
Usage
Resource Authorizations
import { getAuthorizationsOfResource, Resource } from '@optisaas/opti-saas-lib';
// Get all authorizations for a specific resource
const factureAuths = getAuthorizationsOfResource('FACTURE');
// Returns: ['FACTURE_CREATE', 'FACTURE_READ', 'FACTURE_UPDATE']
const avoirAuths = getAuthorizationsOfResource('AVOIR');
// Returns: ['AVOIR_IMPORT', 'AVOIR_EXPORT']Type Definitions
import type {
ResourceAuthorizations,
Resource,
Authorisation
} from '@optissaas/optis-saas-lib';
// Available resources
const resources: Resource[] = ['FACTURE', 'AVOIR'];
// Available authorizations
const authorizations: Authorisation[] = ['CREATE', 'READ', 'UPDATE', 'DELETE', 'EXPORT', 'IMPORT'];
// Type-safe resource authorizations
const auth: ResourceAuthorizations = 'FACTURE_CREATE'; // ✅ Valid
const invalid: ResourceAuthorizations = 'FACTURE_DELETE'; // ❌ TypeScript errorSpecialized Resources
import type {
SpecializedResourceAuthorizations,
SpecializedResource
} from '@optissaas/optis-saas-lib';
// Specialized resources with domain-specific permissions
const specializedAuth: SpecializedResourceAuthorizations =
'GENERAL_PRACTITIONER_HEALTH_RECORD_CREATE';Project Structure
src/
├── backoffice/ # Backoffice utilities
├── client/ # Client-side helpers
│ ├── helpers.ts # Authorization helper functions
│ └── dtos/ # Data transfer objects
├── shared/ # Shared types and configuration
│ ├── config.ts # Resource and authorization configuration
│ └── types.ts # TypeScript type definitions
└── index.ts # Main entry pointDevelopment
Commands
# Install dependencies
pnpm install
# Build the library
pnpm build
# Run in watch mode
pnpm start
# Run tests
pnpm test
# Lint code
pnpm lint
# Analyze bundle size
pnpm sizeBuilding
This library uses tsup for building. The output includes:
- CommonJS (CJS) format
- ES Module (ESM) format
- TypeScript type definitions
Testing
Tests are written using Jest. Run them with:
pnpm testPublishing
This library is automatically published to npm using GitHub Actions when changes are pushed to the main branch. The version is managed in package.json.
To publish a new version:
- Update the version in
package.json - Commit and push to main
- GitHub Actions will automatically build, test, and publish
License
MIT © aymankaddioui
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
