@noatgnu/cupcake-core 1.2.17 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -82
- package/fesm2022/noatgnu-cupcake-core.mjs +51 -31
- package/fesm2022/noatgnu-cupcake-core.mjs.map +1 -1
- package/index.d.ts +141 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,121 +1,163 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cupcake Core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `cupcake-core` library provides essential services, components, and models for building Angular applications that interact with a Cupcake backend. It simplifies authentication, API communication, and provides a set of reusable UI components.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
5
|
+
## Key Features
|
|
6
6
|
|
|
7
|
-
- **Authentication
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **Models
|
|
7
|
+
- **Authentication:** Simplified user authentication and session management.
|
|
8
|
+
- **API Service:** A robust API service with automatic request/response case transformation.
|
|
9
|
+
- **Guards & Interceptors:** Route guards and HTTP interceptors for securing your application.
|
|
10
|
+
- **Reusable Components:** A collection of pre-built components for common UI patterns.
|
|
11
|
+
- **Type-safe Models:** A comprehensive set of TypeScript interfaces for backend data structures.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
|
+
To install the `@noatgnu/cupcake-core` library, run the following command:
|
|
16
|
+
|
|
15
17
|
```bash
|
|
16
|
-
npm install cupcake-core
|
|
18
|
+
npm install @noatgnu/cupcake-core
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
Then, import the `CupcakeCoreModule` into your application's `AppModule` (or any other feature module):
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { CupcakeCoreModule } from '@noatgnu/cupcake-core';
|
|
25
|
+
|
|
26
|
+
@NgModule({
|
|
27
|
+
imports: [
|
|
28
|
+
// ... other modules
|
|
29
|
+
CupcakeCoreModule
|
|
30
|
+
],
|
|
31
|
+
// ...
|
|
32
|
+
})
|
|
33
|
+
export class AppModule { }
|
|
34
|
+
```
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
Additionally, you need to provide the `CUPCAKE_CORE_CONFIG` in your `AppModule` to configure the API URL:
|
|
22
37
|
|
|
23
38
|
```typescript
|
|
24
|
-
import {
|
|
25
|
-
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
26
|
-
import { authInterceptor, CUPCAKE_CORE_CONFIG } from 'cupcake-core';
|
|
39
|
+
import { CUPCAKE_CORE_CONFIG } from '@noatgnu/cupcake-core';
|
|
27
40
|
|
|
28
|
-
|
|
41
|
+
@NgModule({
|
|
42
|
+
// ...
|
|
29
43
|
providers: [
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// ... other providers
|
|
44
|
+
{
|
|
45
|
+
provide: CUPCAKE_CORE_CONFIG,
|
|
46
|
+
useValue: { apiUrl: 'YOUR_API_URL_HERE' }
|
|
47
|
+
}
|
|
35
48
|
]
|
|
36
|
-
}
|
|
49
|
+
})
|
|
50
|
+
export class AppModule { }
|
|
37
51
|
```
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
## Services
|
|
40
54
|
|
|
41
|
-
|
|
42
|
-
import { Routes } from '@angular/router';
|
|
43
|
-
import { LoginComponent, RegisterComponent, authGuard, adminGuard } from 'cupcake-core';
|
|
44
|
-
|
|
45
|
-
export const routes: Routes = [
|
|
46
|
-
{ path: 'login', component: LoginComponent },
|
|
47
|
-
{ path: 'register', component: RegisterComponent },
|
|
48
|
-
{ path: 'protected', component: YourComponent, canActivate: [authGuard] },
|
|
49
|
-
{ path: 'admin', component: AdminComponent, canActivate: [authGuard, adminGuard] },
|
|
50
|
-
];
|
|
51
|
-
```
|
|
55
|
+
### AuthService
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
The `AuthService` handles user authentication, including login, logout, and token management. It uses JWT for authentication and stores tokens in local storage.
|
|
58
|
+
|
|
59
|
+
**Usage:**
|
|
54
60
|
|
|
55
61
|
```typescript
|
|
56
|
-
import {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
import { AuthService } from '@noatgnu/cupcake-core';
|
|
63
|
+
|
|
64
|
+
@Component({ ... })
|
|
65
|
+
export class MyComponent {
|
|
66
|
+
constructor(private authService: AuthService) {
|
|
67
|
+
this.authService.isAuthenticated$.subscribe(isAuthenticated => {
|
|
68
|
+
// ...
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this.authService.currentUser$.subscribe(user => {
|
|
72
|
+
// ...
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
login() {
|
|
77
|
+
this.authService.login('username', 'password').subscribe(response => {
|
|
78
|
+
// ...
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
logout() {
|
|
83
|
+
this.authService.logout().subscribe(() => {
|
|
84
|
+
// ...
|
|
85
|
+
});
|
|
86
|
+
}
|
|
73
87
|
}
|
|
74
88
|
```
|
|
75
89
|
|
|
76
|
-
|
|
90
|
+
### ApiService
|
|
77
91
|
|
|
78
|
-
|
|
79
|
-
- `RegisterComponent` - User registration form
|
|
80
|
-
- `UserProfileComponent` - User profile management
|
|
81
|
-
- `UserManagementComponent` - Admin user management
|
|
82
|
-
- `LabGroupsComponent` - Lab group management
|
|
83
|
-
- `SiteConfigComponent` - Site configuration management
|
|
84
|
-
- `ToastContainerComponent` - Toast notification container
|
|
92
|
+
The `ApiService` is the primary service for communicating with the Cupcake backend. It provides methods for a wide range of functionalities, including user management, site configuration, and more.
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
**Automatic Case Transformation:**
|
|
87
95
|
|
|
88
|
-
|
|
89
|
-
- `ApiService` - API communication
|
|
90
|
-
- `SiteConfigService` - Site configuration
|
|
91
|
-
- `UserManagementService` - User management operations
|
|
92
|
-
- `ToastService` - Toast notifications
|
|
93
|
-
- `ResourceService` - Resource utilities
|
|
96
|
+
The `ApiService` automatically transforms request data from camelCase (frontend) to snake_case (backend) and response data from snake_case to camelCase. This eliminates the need for manual transformations in your components and services.
|
|
94
97
|
|
|
95
|
-
|
|
98
|
+
**Usage:**
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
```typescript
|
|
101
|
+
import { ApiService } from '@noatgnu/cupcake-core';
|
|
102
|
+
|
|
103
|
+
@Component({ ... })
|
|
104
|
+
export class MyComponent {
|
|
105
|
+
constructor(private apiService: ApiService) {
|
|
106
|
+
this.apiService.getUsers().subscribe(response => {
|
|
107
|
+
// `response` is already transformed to camelCase
|
|
108
|
+
console.log(response.results);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
99
113
|
|
|
100
|
-
##
|
|
114
|
+
## Guards
|
|
101
115
|
|
|
102
|
-
|
|
116
|
+
The library provides the following route guards:
|
|
103
117
|
|
|
104
|
-
|
|
118
|
+
- `AuthGuard`: Ensures that a route can only be accessed by authenticated users.
|
|
119
|
+
- `AdminGuard`: Ensures that a route can only be accessed by admin users.
|
|
105
120
|
|
|
106
|
-
|
|
121
|
+
**Usage (in your routing module):**
|
|
107
122
|
|
|
108
|
-
```
|
|
109
|
-
|
|
123
|
+
```typescript
|
|
124
|
+
import { AuthGuard, AdminGuard } from '@noatgnu/cupcake-core';
|
|
125
|
+
|
|
126
|
+
const routes: Routes = [
|
|
127
|
+
{
|
|
128
|
+
path: 'profile',
|
|
129
|
+
component: UserProfileComponent,
|
|
130
|
+
canActivate: [AuthGuard]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
path: 'admin',
|
|
134
|
+
component: AdminDashboardComponent,
|
|
135
|
+
canActivate: [AdminGuard]
|
|
136
|
+
}
|
|
137
|
+
];
|
|
110
138
|
```
|
|
111
139
|
|
|
112
|
-
|
|
140
|
+
## Interceptors
|
|
113
141
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
142
|
+
The `AuthInterceptor` automatically attaches the JWT access token to outgoing HTTP requests. It also handles token refreshing when the access token expires.
|
|
143
|
+
|
|
144
|
+
## Components
|
|
145
|
+
|
|
146
|
+
The `cupcake-core` library includes a variety of reusable components, such as:
|
|
147
|
+
|
|
148
|
+
- **Login Form:** A complete login form with username/password fields.
|
|
149
|
+
- **User Management:** Components for listing, creating, and editing users.
|
|
150
|
+
- **Color Picker:** A color selection component.
|
|
151
|
+
- **Toast Notifications:** A container for displaying toast messages.
|
|
152
|
+
- **Powered-by Footer:** A standard footer component.
|
|
153
|
+
|
|
154
|
+
## Models
|
|
155
|
+
|
|
156
|
+
The library defines a comprehensive set of TypeScript interfaces that correspond to the backend data models. These models provide type safety and autocompletion when working with API responses. Some of the key models include:
|
|
118
157
|
|
|
119
|
-
|
|
158
|
+
- `User`
|
|
159
|
+
- `SiteConfig`
|
|
160
|
+
- `Annotation`
|
|
161
|
+
- `ResourcePermission`
|
|
120
162
|
|
|
121
|
-
|
|
163
|
+
By leveraging the services, components, and models provided by `cupcake-core`, you can significantly accelerate the development of your Angular application and ensure consistency with the Cupcake backend.
|
|
@@ -89,6 +89,56 @@ var AnnotationType;
|
|
|
89
89
|
AnnotationType["Booking"] = "booking";
|
|
90
90
|
})(AnnotationType || (AnnotationType = {}));
|
|
91
91
|
|
|
92
|
+
var TaskStatus;
|
|
93
|
+
(function (TaskStatus) {
|
|
94
|
+
TaskStatus["QUEUED"] = "QUEUED";
|
|
95
|
+
TaskStatus["STARTED"] = "STARTED";
|
|
96
|
+
TaskStatus["SUCCESS"] = "SUCCESS";
|
|
97
|
+
TaskStatus["FAILURE"] = "FAILURE";
|
|
98
|
+
TaskStatus["CANCELLED"] = "CANCELLED";
|
|
99
|
+
})(TaskStatus || (TaskStatus = {}));
|
|
100
|
+
var TaskType;
|
|
101
|
+
(function (TaskType) {
|
|
102
|
+
TaskType["EXPORT_EXCEL"] = "EXPORT_EXCEL";
|
|
103
|
+
TaskType["EXPORT_SDRF"] = "EXPORT_SDRF";
|
|
104
|
+
TaskType["IMPORT_SDRF"] = "IMPORT_SDRF";
|
|
105
|
+
TaskType["IMPORT_EXCEL"] = "IMPORT_EXCEL";
|
|
106
|
+
TaskType["EXPORT_MULTIPLE_SDRF"] = "EXPORT_MULTIPLE_SDRF";
|
|
107
|
+
TaskType["EXPORT_MULTIPLE_EXCEL"] = "EXPORT_MULTIPLE_EXCEL";
|
|
108
|
+
TaskType["VALIDATE_TABLE"] = "VALIDATE_TABLE";
|
|
109
|
+
TaskType["REORDER_TABLE_COLUMNS"] = "REORDER_TABLE_COLUMNS";
|
|
110
|
+
TaskType["REORDER_TEMPLATE_COLUMNS"] = "REORDER_TEMPLATE_COLUMNS";
|
|
111
|
+
TaskType["TRANSCRIBE_AUDIO"] = "TRANSCRIBE_AUDIO";
|
|
112
|
+
TaskType["TRANSCRIBE_VIDEO"] = "TRANSCRIBE_VIDEO";
|
|
113
|
+
})(TaskType || (TaskType = {}));
|
|
114
|
+
const TASK_TYPE_LABELS = {
|
|
115
|
+
[TaskType.EXPORT_EXCEL]: 'Export Excel Template',
|
|
116
|
+
[TaskType.EXPORT_SDRF]: 'Export SDRF File',
|
|
117
|
+
[TaskType.IMPORT_SDRF]: 'Import SDRF File',
|
|
118
|
+
[TaskType.IMPORT_EXCEL]: 'Import Excel File',
|
|
119
|
+
[TaskType.EXPORT_MULTIPLE_SDRF]: 'Export Multiple SDRF Files',
|
|
120
|
+
[TaskType.EXPORT_MULTIPLE_EXCEL]: 'Export Multiple Excel Templates',
|
|
121
|
+
[TaskType.VALIDATE_TABLE]: 'Validate Metadata Table',
|
|
122
|
+
[TaskType.REORDER_TABLE_COLUMNS]: 'Reorder Table Columns',
|
|
123
|
+
[TaskType.REORDER_TEMPLATE_COLUMNS]: 'Reorder Template Columns',
|
|
124
|
+
[TaskType.TRANSCRIBE_AUDIO]: 'Transcribe Audio',
|
|
125
|
+
[TaskType.TRANSCRIBE_VIDEO]: 'Transcribe Video',
|
|
126
|
+
};
|
|
127
|
+
const TASK_STATUS_LABELS = {
|
|
128
|
+
[TaskStatus.QUEUED]: 'Queued',
|
|
129
|
+
[TaskStatus.STARTED]: 'In Progress',
|
|
130
|
+
[TaskStatus.SUCCESS]: 'Completed',
|
|
131
|
+
[TaskStatus.FAILURE]: 'Failed',
|
|
132
|
+
[TaskStatus.CANCELLED]: 'Cancelled',
|
|
133
|
+
};
|
|
134
|
+
const TASK_STATUS_COLORS = {
|
|
135
|
+
[TaskStatus.QUEUED]: 'secondary',
|
|
136
|
+
[TaskStatus.STARTED]: 'primary',
|
|
137
|
+
[TaskStatus.SUCCESS]: 'success',
|
|
138
|
+
[TaskStatus.FAILURE]: 'danger',
|
|
139
|
+
[TaskStatus.CANCELLED]: 'warning',
|
|
140
|
+
};
|
|
141
|
+
|
|
92
142
|
/**
|
|
93
143
|
* CUPCAKE Core (CCC) - Models barrel export
|
|
94
144
|
* User management, lab groups, and core functionality interfaces
|
|
@@ -1793,11 +1843,6 @@ const WEBSOCKET_ENDPOINTS = new InjectionToken('WEBSOCKET_ENDPOINTS');
|
|
|
1793
1843
|
class WebSocketEndpoints {
|
|
1794
1844
|
static CORE_NOTIFICATIONS = 'notifications';
|
|
1795
1845
|
static CORE_ADMIN = 'admin';
|
|
1796
|
-
static CCV_NOTIFICATIONS = 'ccv/notifications';
|
|
1797
|
-
static CCV_ADMIN = 'ccv/admin';
|
|
1798
|
-
static CCM_NOTIFICATIONS = 'ccm/notifications';
|
|
1799
|
-
static CCRV_NOTIFICATIONS = 'ccrv/notifications';
|
|
1800
|
-
static CCSC_NOTIFICATIONS = 'ccsc/notifications';
|
|
1801
1846
|
}
|
|
1802
1847
|
class WebSocketConfigService {
|
|
1803
1848
|
endpoints = new Map();
|
|
@@ -1815,31 +1860,6 @@ class WebSocketConfigService {
|
|
|
1815
1860
|
endpoint: WebSocketEndpoints.CORE_ADMIN,
|
|
1816
1861
|
description: 'Core admin notification endpoint'
|
|
1817
1862
|
});
|
|
1818
|
-
this.registerEndpoint({
|
|
1819
|
-
app: 'ccv',
|
|
1820
|
-
endpoint: WebSocketEndpoints.CCV_NOTIFICATIONS,
|
|
1821
|
-
description: 'CCV notification endpoint'
|
|
1822
|
-
});
|
|
1823
|
-
this.registerEndpoint({
|
|
1824
|
-
app: 'ccv',
|
|
1825
|
-
endpoint: WebSocketEndpoints.CCV_ADMIN,
|
|
1826
|
-
description: 'CCV admin notification endpoint'
|
|
1827
|
-
});
|
|
1828
|
-
this.registerEndpoint({
|
|
1829
|
-
app: 'ccm',
|
|
1830
|
-
endpoint: WebSocketEndpoints.CCM_NOTIFICATIONS,
|
|
1831
|
-
description: 'CCM notification endpoint'
|
|
1832
|
-
});
|
|
1833
|
-
this.registerEndpoint({
|
|
1834
|
-
app: 'ccrv',
|
|
1835
|
-
endpoint: WebSocketEndpoints.CCRV_NOTIFICATIONS,
|
|
1836
|
-
description: 'CCRV notification endpoint'
|
|
1837
|
-
});
|
|
1838
|
-
this.registerEndpoint({
|
|
1839
|
-
app: 'ccsc',
|
|
1840
|
-
endpoint: WebSocketEndpoints.CCSC_NOTIFICATIONS,
|
|
1841
|
-
description: 'CCSC notification endpoint'
|
|
1842
|
-
});
|
|
1843
1863
|
}
|
|
1844
1864
|
registerEndpoint(config) {
|
|
1845
1865
|
this.endpoints.set(config.endpoint, config);
|
|
@@ -3483,5 +3503,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImpor
|
|
|
3483
3503
|
* Generated bundle index. Do not edit.
|
|
3484
3504
|
*/
|
|
3485
3505
|
|
|
3486
|
-
export { AnnotationType, ApiService, AuthService, BaseApiService, CUPCAKE_CORE_CONFIG, CupcakeCoreModule, InvitationStatus, InvitationStatusLabels, LabGroupService, LabGroupsComponent, LoginComponent, NotificationService, PoweredByFooterComponent, RegisterComponent, ResourceRole, ResourceRoleLabels, ResourceService, ResourceType, ResourceTypeLabels, ResourceVisibility, ResourceVisibilityLabels, SiteConfigComponent, SiteConfigService, ThemeService, ToastContainerComponent, ToastService, UserManagementComponent, UserManagementService, UserProfileComponent, WEBSOCKET_ENDPOINT, WEBSOCKET_ENDPOINTS, WebSocketConfigService, WebSocketEndpoints, WebSocketService, adminGuard, authGuard, authInterceptor, resetRefreshState };
|
|
3506
|
+
export { AnnotationType, ApiService, AuthService, BaseApiService, CUPCAKE_CORE_CONFIG, CupcakeCoreModule, InvitationStatus, InvitationStatusLabels, LabGroupService, LabGroupsComponent, LoginComponent, NotificationService, PoweredByFooterComponent, RegisterComponent, ResourceRole, ResourceRoleLabels, ResourceService, ResourceType, ResourceTypeLabels, ResourceVisibility, ResourceVisibilityLabels, SiteConfigComponent, SiteConfigService, TASK_STATUS_COLORS, TASK_STATUS_LABELS, TASK_TYPE_LABELS, TaskStatus, TaskType, ThemeService, ToastContainerComponent, ToastService, UserManagementComponent, UserManagementService, UserProfileComponent, WEBSOCKET_ENDPOINT, WEBSOCKET_ENDPOINTS, WebSocketConfigService, WebSocketEndpoints, WebSocketService, adminGuard, authGuard, authInterceptor, resetRefreshState };
|
|
3487
3507
|
//# sourceMappingURL=noatgnu-cupcake-core.mjs.map
|