@jaws-developers-customers/consulca-types 1.0.7 → 1.1.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.
Files changed (5) hide show
  1. package/README.md +83 -83
  2. package/index.d.ts +268 -268
  3. package/index.js +149 -149
  4. package/index.mjs +31 -31
  5. package/package.json +51 -51
package/README.md CHANGED
@@ -1,84 +1,84 @@
1
- # @jaws-developers-customers/consulca-types
2
-
3
- Pacchetto NPM con tipi del dominio Consulca e helper pronti all'uso per date, valuta e oggetti principali derivati dallo schema MariaDB.
4
-
5
- ## Installazione
6
-
7
- ```bash
8
- npm install @jaws-developers-customers/consulca-types
9
- ```
10
-
11
- ## Pubblicazione automatica
12
-
13
- Ogni push su `main` esegue i test e pubblica automaticamente il pacchetto su npm tramite GitHub Actions.
14
-
15
- Prerequisito:
16
-
17
- - npm Trusted Publisher configurato per questo repository/workflow su npm
18
-
19
- Il workflow genera una versione unica per ogni run su `main`, così la pubblicazione non fallisce per versioni duplicate.
20
-
21
- ## Cosa esporta
22
-
23
- - tipi TypeScript per le entità principali (`User`, `Property`, `Lease`, `Inspection`, `Claim`, `Work`, ...)
24
- - cataloghi `ENUM` dello schema (`USER_ROLES`, `ACCESS_CHANNELS`, `PROPERTY_TYPES`, ...)
25
- - helper:
26
- - `formatDate`
27
- - `formatDateTime`
28
- - `formatCurrency`
29
- - `getUserFullName`
30
- - `formatAddress`
31
- - `hasUserRole`
32
- - `hasAccessChannel`
33
- - `Query.isSuccess`
34
-
35
- ## Esempio
36
-
37
- ```js
38
- const {
39
- formatCurrency,
40
- formatDate,
41
- getUserFullName,
42
- hasUserRole,
43
- } = require('@jaws-developers-customers/consulca-types');
44
-
45
- console.log(formatDate('2026-09-16T10:30:00Z'));
46
- console.log(formatCurrency(1250.5));
47
- console.log(getUserFullName({ first_name: 'Mario', last_name: 'Rossi' }));
48
- console.log(hasUserRole([{ role: 'manager' }], 'manager'));
49
- ```
50
-
51
- `Query.isSuccess(error_code)` restituisce `true` per i codici nel formato `xx.xx.xxx` il cui ultimo gruppo inizia con `0`.
52
-
53
- ### Esempio TypeScript
54
-
55
- ```ts
56
- import {
57
- formatDateTime,
58
- type Inspection,
59
- type User,
60
- } from '@jaws-developers-customers/consulca-types';
61
-
62
- const user: User = {
63
- id: 'uuid',
64
- email: 'mario.rossi@example.com',
65
- password_hash: 'hashed',
66
- first_name: 'Mario',
67
- last_name: 'Rossi',
68
- status: 'active',
69
- created_at: new Date(),
70
- updated_at: new Date(),
71
- };
72
-
73
- const inspection: Inspection = {
74
- id: 'uuid',
75
- lease_id: 'lease-id',
76
- inspector_id: user.id,
77
- inspection_type: 'move_in',
78
- status: 'draft',
79
- created_at: new Date(),
80
- updated_at: new Date(),
81
- };
82
-
83
- console.log(formatDateTime(inspection.created_at, 'it-CH'));
1
+ # @jaws-developers-customers/consulca-types
2
+
3
+ Pacchetto NPM con tipi del dominio Consulca e helper pronti all'uso per date, valuta e oggetti principali derivati dallo schema MariaDB.
4
+
5
+ ## Installazione
6
+
7
+ ```bash
8
+ npm install @jaws-developers-customers/consulca-types
9
+ ```
10
+
11
+ ## Pubblicazione automatica
12
+
13
+ Ogni push su `main` esegue i test e pubblica automaticamente il pacchetto su npm tramite GitHub Actions.
14
+
15
+ Prerequisito:
16
+
17
+ - npm Trusted Publisher configurato per questo repository/workflow su npm
18
+
19
+ Il workflow genera una versione unica per ogni run su `main`, così la pubblicazione non fallisce per versioni duplicate.
20
+
21
+ ## Cosa esporta
22
+
23
+ - tipi TypeScript per le entità principali (`User`, `Property`, `Lease`, `Inspection`, `Claim`, `Work`, ...)
24
+ - cataloghi `ENUM` dello schema (`USER_ROLES`, `ACCESS_CHANNELS`, `PROPERTY_TYPES`, ...)
25
+ - helper:
26
+ - `formatDate`
27
+ - `formatDateTime`
28
+ - `formatCurrency`
29
+ - `getUserFullName`
30
+ - `formatAddress`
31
+ - `hasUserRole`
32
+ - `hasAccessChannel`
33
+ - `Query.isSuccess`
34
+
35
+ ## Esempio
36
+
37
+ ```js
38
+ const {
39
+ formatCurrency,
40
+ formatDate,
41
+ getUserFullName,
42
+ hasUserRole,
43
+ } = require('@jaws-developers-customers/consulca-types');
44
+
45
+ console.log(formatDate('2026-09-16T10:30:00Z'));
46
+ console.log(formatCurrency(1250.5));
47
+ console.log(getUserFullName({ first_name: 'Mario', last_name: 'Rossi' }));
48
+ console.log(hasUserRole([{ role: 'manager' }], 'manager'));
49
+ ```
50
+
51
+ `Query.isSuccess(error_code)` restituisce `true` per i codici nel formato `xx.xx.xxx` il cui ultimo gruppo inizia con `0`.
52
+
53
+ ### Esempio TypeScript
54
+
55
+ ```ts
56
+ import {
57
+ formatDateTime,
58
+ type Inspection,
59
+ type User,
60
+ } from '@jaws-developers-customers/consulca-types';
61
+
62
+ const user: User = {
63
+ id: 'uuid',
64
+ email: 'mario.rossi@example.com',
65
+ password_hash: 'hashed',
66
+ first_name: 'Mario',
67
+ last_name: 'Rossi',
68
+ status: 'active',
69
+ created_at: new Date(),
70
+ updated_at: new Date(),
71
+ };
72
+
73
+ const inspection: Inspection = {
74
+ id: 'uuid',
75
+ lease_id: 'lease-id',
76
+ inspector_id: user.id,
77
+ inspection_type: 'move_in',
78
+ status: 'draft',
79
+ created_at: new Date(),
80
+ updated_at: new Date(),
81
+ };
82
+
83
+ console.log(formatDateTime(inspection.created_at, 'it-CH'));
84
84
  ```
package/index.d.ts CHANGED
@@ -1,268 +1,268 @@
1
- export type UserStatus = 'active' | 'invited' | 'suspended' | 'disabled';
2
- export type UserRole = 'lessor' | 'manager' | 'website_manager' | 'inspector';
3
- export type AccessChannel = 'intranet_dashboard' | 'mobile_app' | 'website_admin';
4
- export type AccessStatus = 'active' | 'revoked';
5
- export type PropertyStatus = 'active' | 'inactive' | 'archived';
6
- export type ManagementRole = 'primary' | 'secondary' | 'accounting' | 'technical' | 'other';
7
- export type LeaseStatus = 'planned' | 'active' | 'ended' | 'cancelled';
8
- export type InspectionType = 'move_in' | 'move_out';
9
- export type InspectionStatus = 'draft' | 'in_progress' | 'submitted' | 'approved' | 'rejected';
10
- export type ConditionStatus = 'good' | 'minor_damage' | 'major_damage' | 'not_checked';
11
- export type ClaimStatus = 'draft' | 'submitted' | 'in_review' | 'approved' | 'rejected' | 'closed';
12
- export type WorkStatus = 'planned' | 'assigned' | 'in_progress' | 'completed' | 'cancelled';
13
-
14
- export interface ColorPalette {
15
- primary: string;
16
- secondary: string;
17
- accent: string;
18
- background: string;
19
- text: string;
20
- }
21
-
22
- export interface Constants {
23
- API_DEV: string;
24
- API: string;
25
- ICON: string;
26
- }
27
-
28
- export interface QueryHelpers {
29
- isSuccess(errorCode: string): boolean;
30
- }
31
-
32
- export interface Addressable {
33
- address_line1?: string | null;
34
- address_line2?: string | null;
35
- postal_code?: string | null;
36
- city?: string | null;
37
- country_code?: string | null;
38
- }
39
-
40
- export interface User extends Addressable {
41
- id: string;
42
- email: string;
43
- password_hash: string;
44
- first_name: string;
45
- last_name: string;
46
- phone?: string | null;
47
- status: UserStatus;
48
- email_verified_at?: string | Date | null;
49
- last_login_at?: string | Date | null;
50
- created_at: string | Date;
51
- updated_at: string | Date;
52
- }
53
-
54
- export interface UserRoleAssignment {
55
- user_id: string;
56
- role: UserRole;
57
- created_at: string | Date;
58
- }
59
-
60
- export interface UserAccessChannel {
61
- user_id: string;
62
- channel: AccessChannel;
63
- status: AccessStatus;
64
- created_at: string | Date;
65
- revoked_at?: string | Date | null;
66
- }
67
-
68
- export interface Session {
69
- id: string;
70
- user_id: string;
71
- channel: AccessChannel;
72
- access_token_hash: string;
73
- refresh_token_hash?: string | null;
74
- expires_at: string | Date;
75
- refresh_expires_at?: string | Date | null;
76
- user_agent?: string | null;
77
- ip_address?: Uint8Array | string | null;
78
- created_at: string | Date;
79
- revoked_at?: string | Date | null;
80
- }
81
-
82
- export interface Building extends Addressable {
83
- id: string;
84
- name: string;
85
- created_at: string | Date;
86
- updated_at: string | Date;
87
- }
88
-
89
- export interface Property {
90
- id: string;
91
- building_id: string;
92
- property_number: string;
93
- floor?: string | null;
94
- area_m2?: number | null;
95
- status: PropertyStatus;
96
- created_at: string | Date;
97
- updated_at: string | Date;
98
- }
99
-
100
- export interface PropertyLessor {
101
- property_id: string;
102
- user_id: string;
103
- ownership_share?: number | null;
104
- is_primary: boolean | number;
105
- created_at: string | Date;
106
- }
107
-
108
- export interface PropertyManager {
109
- property_id: string;
110
- user_id: string;
111
- management_role: ManagementRole;
112
- valid_from?: string | Date | null;
113
- valid_until?: string | Date | null;
114
- created_at: string | Date;
115
- }
116
-
117
- export interface Lease {
118
- id: string;
119
- property_id: string;
120
- tenant_name?: string | null;
121
- tenant_email?: string | null;
122
- tenant_phone?: string | null;
123
- start_date: string | Date;
124
- end_date?: string | Date | null;
125
- status: LeaseStatus;
126
- created_at: string | Date;
127
- updated_at: string | Date;
128
- }
129
-
130
- export interface Inspection {
131
- id: string;
132
- lease_id: string;
133
- inspector_id: string;
134
- inspection_type: InspectionType;
135
- status: InspectionStatus;
136
- scheduled_at?: string | Date | null;
137
- started_at?: string | Date | null;
138
- submitted_at?: string | Date | null;
139
- notes?: string | null;
140
- created_at: string | Date;
141
- updated_at: string | Date;
142
- }
143
-
144
- export interface InspectionItem {
145
- id: string;
146
- inspection_id: string;
147
- room?: string | null;
148
- item_name: string;
149
- condition_status: ConditionStatus;
150
- comment?: string | null;
151
- created_at: string | Date;
152
- }
153
-
154
- export interface InspectionAttachment {
155
- id: string;
156
- inspection_id: string;
157
- item_id?: string | null;
158
- file_name: string;
159
- storage_key: string;
160
- mime_type?: string | null;
161
- file_size?: number | null;
162
- created_at: string | Date;
163
- }
164
-
165
- export interface Claim {
166
- id: string;
167
- property_id: string;
168
- submitted_by: string;
169
- status: ClaimStatus;
170
- incident_date?: string | Date | null;
171
- title: string;
172
- description: string;
173
- amount_estimate?: number | null;
174
- submitted_at?: string | Date | null;
175
- created_at: string | Date;
176
- updated_at: string | Date;
177
- }
178
-
179
- export interface ClaimAttachment {
180
- id: string;
181
- claim_id: string;
182
- file_name: string;
183
- storage_key: string;
184
- mime_type?: string | null;
185
- file_size?: number | null;
186
- created_at: string | Date;
187
- }
188
-
189
- export interface Manufacturer extends Addressable {
190
- id: string;
191
- name: string;
192
- country_code: string;
193
- email?: string | null;
194
- phone?: string | null;
195
- created_at: string | Date;
196
- updated_at: string | Date;
197
- }
198
-
199
- export interface Work {
200
- id: string;
201
- property_id: string;
202
- manufacturer_id?: string | null;
203
- created_by: string;
204
- title: string;
205
- description?: string | null;
206
- status: WorkStatus;
207
- scheduled_at?: string | Date | null;
208
- completed_at?: string | Date | null;
209
- created_at: string | Date;
210
- updated_at: string | Date;
211
- }
212
-
213
- export interface AuditLog {
214
- id: number;
215
- user_id?: string | null;
216
- channel?: AccessChannel | null;
217
- action: string;
218
- entity_type?: string | null;
219
- entity_id?: string | null;
220
- metadata?: Record<string, unknown> | null;
221
- created_at: string | Date;
222
- }
223
-
224
- export declare const USER_STATUSES: readonly UserStatus[];
225
- export declare const USER_ROLES: readonly UserRole[];
226
- export declare const ACCESS_CHANNELS: readonly AccessChannel[];
227
- export declare const ACCESS_STATUSES: readonly AccessStatus[];
228
- export declare const PROPERTY_STATUSES: readonly PropertyStatus[];
229
- export declare const MANAGEMENT_ROLES: readonly ManagementRole[];
230
- export declare const LEASE_STATUSES: readonly LeaseStatus[];
231
- export declare const INSPECTION_TYPES: readonly InspectionType[];
232
- export declare const INSPECTION_STATUSES: readonly InspectionStatus[];
233
- export declare const CONDITION_STATUSES: readonly ConditionStatus[];
234
- export declare const CLAIM_STATUSES: readonly ClaimStatus[];
235
- export declare const WORK_STATUSES: readonly WorkStatus[];
236
- export declare const COLOR_PALETTE: Readonly<ColorPalette>;
237
- export declare const CONSTANTS: Readonly<Constants>;
238
- export declare const Query: Readonly<QueryHelpers>;
239
-
240
- export declare function toDate(value: string | number | Date | null | undefined): Date | null;
241
- export declare function formatDate(
242
- value: string | number | Date | null | undefined,
243
- locales?: string | string[],
244
- options?: Intl.DateTimeFormatOptions
245
- ): string;
246
- export declare function formatDateTime(
247
- value: string | number | Date | null | undefined,
248
- locales?: string | string[],
249
- options?: Intl.DateTimeFormatOptions
250
- ): string;
251
- export declare function formatCurrency(
252
- amount: string | number | null | undefined,
253
- currency?: string,
254
- locales?: string | string[],
255
- options?: Intl.NumberFormatOptions
256
- ): string;
257
- export declare function getUserFullName(
258
- user: Pick<User, 'first_name' | 'last_name'> | Partial<Pick<User, 'first_name' | 'last_name'>> | null | undefined
259
- ): string;
260
- export declare function formatAddress(entity: Addressable | null | undefined): string;
261
- export declare function hasUserRole(
262
- userRoles: Array<UserRoleAssignment | UserRole> | null | undefined,
263
- role: UserRole
264
- ): boolean;
265
- export declare function hasAccessChannel(
266
- accessChannels: Array<UserAccessChannel | AccessChannel> | null | undefined,
267
- channel: AccessChannel
268
- ): boolean;
1
+ export type UserStatus = 'active' | 'invited' | 'suspended' | 'disabled';
2
+ export type UserRole = 'lessor' | 'manager' | 'website_manager' | 'inspector';
3
+ export type AccessChannel = 'intranet_dashboard' | 'mobile_app' | 'website_admin';
4
+ export type AccessStatus = 'active' | 'revoked';
5
+ export type PropertyStatus = 'active' | 'inactive' | 'archived';
6
+ export type ManagementRole = 'primary' | 'secondary' | 'accounting' | 'technical' | 'other';
7
+ export type LeaseStatus = 'planned' | 'active' | 'ended' | 'cancelled';
8
+ export type InspectionType = 'move_in' | 'move_out';
9
+ export type InspectionStatus = 'draft' | 'in_progress' | 'submitted' | 'approved' | 'rejected';
10
+ export type ConditionStatus = 'good' | 'minor_damage' | 'major_damage' | 'not_checked';
11
+ export type ClaimStatus = 'draft' | 'submitted' | 'in_review' | 'approved' | 'rejected' | 'closed';
12
+ export type WorkStatus = 'planned' | 'assigned' | 'in_progress' | 'completed' | 'cancelled';
13
+
14
+ export interface ColorPalette {
15
+ primary: string;
16
+ secondary: string;
17
+ accent: string;
18
+ background: string;
19
+ text: string;
20
+ }
21
+
22
+ export interface Constants {
23
+ API_DEV: string;
24
+ API: string;
25
+ ICON: string;
26
+ }
27
+
28
+ export interface QueryHelpers {
29
+ isSuccess(errorCode: string): boolean;
30
+ }
31
+
32
+ export interface Addressable {
33
+ address_line1?: string | null;
34
+ address_line2?: string | null;
35
+ postal_code?: string | null;
36
+ city?: string | null;
37
+ country_code?: string | null;
38
+ }
39
+
40
+ export interface User extends Addressable {
41
+ id: string;
42
+ email: string;
43
+ password_hash: string;
44
+ first_name: string;
45
+ last_name: string;
46
+ phone?: string | null;
47
+ status: UserStatus;
48
+ email_verified_at?: string | Date | null;
49
+ last_login_at?: string | Date | null;
50
+ created_at: string | Date;
51
+ updated_at: string | Date;
52
+ }
53
+
54
+ export interface UserRoleAssignment {
55
+ user_id: string;
56
+ role: UserRole;
57
+ created_at: string | Date;
58
+ }
59
+
60
+ export interface UserAccessChannel {
61
+ user_id: string;
62
+ channel: AccessChannel;
63
+ status: AccessStatus;
64
+ created_at: string | Date;
65
+ revoked_at?: string | Date | null;
66
+ }
67
+
68
+ export interface Session {
69
+ id: string;
70
+ user_id: string;
71
+ channel: AccessChannel;
72
+ access_token_hash: string;
73
+ refresh_token_hash?: string | null;
74
+ expires_at: string | Date;
75
+ refresh_expires_at?: string | Date | null;
76
+ user_agent?: string | null;
77
+ ip_address?: Uint8Array | string | null;
78
+ created_at: string | Date;
79
+ revoked_at?: string | Date | null;
80
+ }
81
+
82
+ export interface Building extends Addressable {
83
+ id: string;
84
+ name: string;
85
+ created_at: string | Date;
86
+ updated_at: string | Date;
87
+ }
88
+
89
+ export interface Property {
90
+ id: string;
91
+ building_id: string;
92
+ property_number: string;
93
+ floor?: string | null;
94
+ area_m2?: number | null;
95
+ status: PropertyStatus;
96
+ created_at: string | Date;
97
+ updated_at: string | Date;
98
+ }
99
+
100
+ export interface PropertyLessor {
101
+ property_id: string;
102
+ user_id: string;
103
+ ownership_share?: number | null;
104
+ is_primary: boolean | number;
105
+ created_at: string | Date;
106
+ }
107
+
108
+ export interface PropertyManager {
109
+ property_id: string;
110
+ user_id: string;
111
+ management_role: ManagementRole;
112
+ valid_from?: string | Date | null;
113
+ valid_until?: string | Date | null;
114
+ created_at: string | Date;
115
+ }
116
+
117
+ export interface Lease {
118
+ id: string;
119
+ property_id: string;
120
+ tenant_name?: string | null;
121
+ tenant_email?: string | null;
122
+ tenant_phone?: string | null;
123
+ start_date: string | Date;
124
+ end_date?: string | Date | null;
125
+ status: LeaseStatus;
126
+ created_at: string | Date;
127
+ updated_at: string | Date;
128
+ }
129
+
130
+ export interface Inspection {
131
+ id: string;
132
+ lease_id: string;
133
+ inspector_id: string;
134
+ inspection_type: InspectionType;
135
+ status: InspectionStatus;
136
+ scheduled_at?: string | Date | null;
137
+ started_at?: string | Date | null;
138
+ submitted_at?: string | Date | null;
139
+ notes?: string | null;
140
+ created_at: string | Date;
141
+ updated_at: string | Date;
142
+ }
143
+
144
+ export interface InspectionItem {
145
+ id: string;
146
+ inspection_id: string;
147
+ room?: string | null;
148
+ item_name: string;
149
+ condition_status: ConditionStatus;
150
+ comment?: string | null;
151
+ created_at: string | Date;
152
+ }
153
+
154
+ export interface InspectionAttachment {
155
+ id: string;
156
+ inspection_id: string;
157
+ item_id?: string | null;
158
+ file_name: string;
159
+ storage_key: string;
160
+ mime_type?: string | null;
161
+ file_size?: number | null;
162
+ created_at: string | Date;
163
+ }
164
+
165
+ export interface Claim {
166
+ id: string;
167
+ property_id: string;
168
+ submitted_by: string;
169
+ status: ClaimStatus;
170
+ incident_date?: string | Date | null;
171
+ title: string;
172
+ description: string;
173
+ amount_estimate?: number | null;
174
+ submitted_at?: string | Date | null;
175
+ created_at: string | Date;
176
+ updated_at: string | Date;
177
+ }
178
+
179
+ export interface ClaimAttachment {
180
+ id: string;
181
+ claim_id: string;
182
+ file_name: string;
183
+ storage_key: string;
184
+ mime_type?: string | null;
185
+ file_size?: number | null;
186
+ created_at: string | Date;
187
+ }
188
+
189
+ export interface Manufacturer extends Addressable {
190
+ id: string;
191
+ name: string;
192
+ country_code: string;
193
+ email?: string | null;
194
+ phone?: string | null;
195
+ created_at: string | Date;
196
+ updated_at: string | Date;
197
+ }
198
+
199
+ export interface Work {
200
+ id: string;
201
+ property_id: string;
202
+ manufacturer_id?: string | null;
203
+ created_by: string;
204
+ title: string;
205
+ description?: string | null;
206
+ status: WorkStatus;
207
+ scheduled_at?: string | Date | null;
208
+ completed_at?: string | Date | null;
209
+ created_at: string | Date;
210
+ updated_at: string | Date;
211
+ }
212
+
213
+ export interface AuditLog {
214
+ id: number;
215
+ user_id?: string | null;
216
+ channel?: AccessChannel | null;
217
+ action: string;
218
+ entity_type?: string | null;
219
+ entity_id?: string | null;
220
+ metadata?: Record<string, unknown> | null;
221
+ created_at: string | Date;
222
+ }
223
+
224
+ export declare const USER_STATUSES: readonly UserStatus[];
225
+ export declare const USER_ROLES: readonly UserRole[];
226
+ export declare const ACCESS_CHANNELS: readonly AccessChannel[];
227
+ export declare const ACCESS_STATUSES: readonly AccessStatus[];
228
+ export declare const PROPERTY_STATUSES: readonly PropertyStatus[];
229
+ export declare const MANAGEMENT_ROLES: readonly ManagementRole[];
230
+ export declare const LEASE_STATUSES: readonly LeaseStatus[];
231
+ export declare const INSPECTION_TYPES: readonly InspectionType[];
232
+ export declare const INSPECTION_STATUSES: readonly InspectionStatus[];
233
+ export declare const CONDITION_STATUSES: readonly ConditionStatus[];
234
+ export declare const CLAIM_STATUSES: readonly ClaimStatus[];
235
+ export declare const WORK_STATUSES: readonly WorkStatus[];
236
+ export declare const COLOR_PALETTE: Readonly<ColorPalette>;
237
+ export declare const CONSTANTS: Readonly<Constants>;
238
+ export declare const Query: Readonly<QueryHelpers>;
239
+
240
+ export declare function toDate(value: string | number | Date | null | undefined): Date | null;
241
+ export declare function formatDate(
242
+ value: string | number | Date | null | undefined,
243
+ locales?: string | string[],
244
+ options?: Intl.DateTimeFormatOptions
245
+ ): string;
246
+ export declare function formatDateTime(
247
+ value: string | number | Date | null | undefined,
248
+ locales?: string | string[],
249
+ options?: Intl.DateTimeFormatOptions
250
+ ): string;
251
+ export declare function formatCurrency(
252
+ amount: string | number | null | undefined,
253
+ currency?: string,
254
+ locales?: string | string[],
255
+ options?: Intl.NumberFormatOptions
256
+ ): string;
257
+ export declare function getUserFullName(
258
+ user: Pick<User, 'first_name' | 'last_name'> | Partial<Pick<User, 'first_name' | 'last_name'>> | null | undefined
259
+ ): string;
260
+ export declare function formatAddress(entity: Addressable | null | undefined): string;
261
+ export declare function hasUserRole(
262
+ userRoles: Array<UserRoleAssignment | UserRole> | null | undefined,
263
+ role: UserRole
264
+ ): boolean;
265
+ export declare function hasAccessChannel(
266
+ accessChannels: Array<UserAccessChannel | AccessChannel> | null | undefined,
267
+ channel: AccessChannel
268
+ ): boolean;
package/index.js CHANGED
@@ -1,149 +1,149 @@
1
- 'use strict';
2
-
3
- const USER_STATUSES = Object.freeze(['active', 'invited', 'suspended', 'disabled']);
4
- const USER_ROLES = Object.freeze(['lessor', 'manager', 'website_manager', 'inspector']);
5
- const ACCESS_CHANNELS = Object.freeze(['intranet_dashboard', 'mobile_app', 'website_admin']);
6
- const ACCESS_STATUSES = Object.freeze(['active', 'revoked']);
7
- const PROPERTY_STATUSES = Object.freeze(['active', 'inactive', 'archived']);
8
- const MANAGEMENT_ROLES = Object.freeze(['primary', 'secondary', 'accounting', 'technical', 'other']);
9
- const LEASE_STATUSES = Object.freeze(['planned', 'active', 'ended', 'cancelled']);
10
- const INSPECTION_TYPES = Object.freeze(['move_in', 'move_out']);
11
- const INSPECTION_STATUSES = Object.freeze(['draft', 'in_progress', 'submitted', 'approved', 'rejected']);
12
- const CONDITION_STATUSES = Object.freeze(['good', 'minor_damage', 'major_damage', 'not_checked']);
13
- const CLAIM_STATUSES = Object.freeze(['draft', 'submitted', 'in_review', 'approved', 'rejected', 'closed']);
14
- const WORK_STATUSES = Object.freeze(['planned', 'assigned', 'in_progress', 'completed', 'cancelled']);
15
- const COLOR_PALETTE = Object.freeze({
16
- primary: '#334E68',
17
- secondary: '#829AB1',
18
- accent: '#D64545',
19
- background: '#F7F9FB',
20
- text: '#102A43',
21
- });
22
- const CONSTANTS = Object.freeze({
23
- API_DEV: 'https://api.consulca.local',
24
- API: 'https://api.consulca.ch',
25
- ICON: 'https://www.consulca.ch/wp-content/themes/consulca_theme2020/img/default_user.png'
26
- });
27
- const Query = Object.freeze({
28
- isSuccess(errorCode) {
29
- return typeof errorCode === 'string' && /^\d{2}\.\d{2}\.0\d{2}$/.test(errorCode);
30
- },
31
- });
32
-
33
- function toDate(value) {
34
- if (value === null || value === undefined || value === '') {
35
- return null;
36
- }
37
-
38
- const date = value instanceof Date ? value : new Date(value);
39
- return Number.isNaN(date.getTime()) ? null : date;
40
- }
41
-
42
- function formatDate(value, locales = 'it-CH', options = {}) {
43
- const date = toDate(value);
44
- if (!date) {
45
- return '';
46
- }
47
-
48
- return new Intl.DateTimeFormat(locales, {
49
- year: 'numeric',
50
- month: '2-digit',
51
- day: '2-digit',
52
- ...options,
53
- }).format(date);
54
- }
55
-
56
- function formatDateTime(value, locales = 'it-CH', options = {}) {
57
- const date = toDate(value);
58
- if (!date) {
59
- return '';
60
- }
61
-
62
- return new Intl.DateTimeFormat(locales, {
63
- year: 'numeric',
64
- month: '2-digit',
65
- day: '2-digit',
66
- hour: '2-digit',
67
- minute: '2-digit',
68
- ...options,
69
- }).format(date);
70
- }
71
-
72
- function formatCurrency(amount, currency = 'CHF', locales = 'it-CH', options = {}) {
73
- if (amount === null || amount === undefined || amount === '') {
74
- return '';
75
- }
76
-
77
- const numericAmount = Number(amount);
78
- if (Number.isNaN(numericAmount)) {
79
- return '';
80
- }
81
-
82
- return new Intl.NumberFormat(locales, {
83
- style: 'currency',
84
- currency,
85
- ...options,
86
- }).format(numericAmount);
87
- }
88
-
89
- function getUserFullName(user) {
90
- return [user?.first_name, user?.last_name].filter(Boolean).join(' ').trim();
91
- }
92
-
93
- function formatAddress(entity) {
94
- if (!entity) {
95
- return '';
96
- }
97
-
98
- const line1 = [entity.address_line1, entity.address_line2].filter(Boolean).join(', ');
99
- const line2 = [entity.postal_code, entity.city].filter(Boolean).join(' ');
100
-
101
- return [line1, line2, entity.country_code].filter(Boolean).join(', ');
102
- }
103
-
104
- function hasUserRole(userRoles, role) {
105
- return (userRoles ?? []).some((userRole) => {
106
- if (typeof userRole === 'string') {
107
- return userRole === role;
108
- }
109
-
110
- return userRole?.role === role;
111
- });
112
- }
113
-
114
- function hasAccessChannel(accessChannels, channel) {
115
- return (accessChannels ?? []).some((accessChannel) => {
116
- if (typeof accessChannel === 'string') {
117
- return accessChannel === channel;
118
- }
119
-
120
- return accessChannel?.channel === channel && accessChannel?.status !== 'revoked';
121
- });
122
- }
123
-
124
-
125
- module.exports = {
126
- ACCESS_CHANNELS,
127
- ACCESS_STATUSES,
128
- CLAIM_STATUSES,
129
- COLOR_PALETTE,
130
- CONDITION_STATUSES,
131
- INSPECTION_STATUSES,
132
- INSPECTION_TYPES,
133
- LEASE_STATUSES,
134
- MANAGEMENT_ROLES,
135
- PROPERTY_STATUSES,
136
- USER_ROLES,
137
- USER_STATUSES,
138
- WORK_STATUSES,
139
- CONSTANTS,
140
- formatAddress,
141
- formatCurrency,
142
- formatDate,
143
- formatDateTime,
144
- getUserFullName,
145
- hasAccessChannel,
146
- hasUserRole,
147
- Query,
148
- toDate,
149
- };
1
+ 'use strict';
2
+
3
+ const USER_STATUSES = Object.freeze(['active', 'invited', 'suspended', 'disabled']);
4
+ const USER_ROLES = Object.freeze(['lessor', 'manager', 'website_manager', 'inspector']);
5
+ const ACCESS_CHANNELS = Object.freeze(['intranet_dashboard', 'mobile_app', 'website_admin']);
6
+ const ACCESS_STATUSES = Object.freeze(['active', 'revoked']);
7
+ const PROPERTY_STATUSES = Object.freeze(['active', 'inactive', 'archived']);
8
+ const MANAGEMENT_ROLES = Object.freeze(['primary', 'secondary', 'accounting', 'technical', 'other']);
9
+ const LEASE_STATUSES = Object.freeze(['planned', 'active', 'ended', 'cancelled']);
10
+ const INSPECTION_TYPES = Object.freeze(['move_in', 'move_out']);
11
+ const INSPECTION_STATUSES = Object.freeze(['draft', 'in_progress', 'submitted', 'approved', 'rejected']);
12
+ const CONDITION_STATUSES = Object.freeze(['good', 'minor_damage', 'major_damage', 'not_checked']);
13
+ const CLAIM_STATUSES = Object.freeze(['draft', 'submitted', 'in_review', 'approved', 'rejected', 'closed']);
14
+ const WORK_STATUSES = Object.freeze(['planned', 'assigned', 'in_progress', 'completed', 'cancelled']);
15
+ const COLOR_PALETTE = Object.freeze({
16
+ primary: '#334E68',
17
+ secondary: '#829AB1',
18
+ accent: '#D64545',
19
+ background: '#F7F9FB',
20
+ text: '#102A43',
21
+ });
22
+ const CONSTANTS = Object.freeze({
23
+ API_DEV: 'https://api.consulca.local',
24
+ API: 'https://api.consulca.ch',
25
+ ICON: 'https://www.consulca.ch/wp-content/themes/consulca_theme2020/img/default_user.png'
26
+ });
27
+ const Query = Object.freeze({
28
+ isSuccess(errorCode) {
29
+ return typeof errorCode === 'string' && /^\d{2}\.\d{2}\.0\d{2}$/.test(errorCode);
30
+ },
31
+ });
32
+
33
+ function toDate(value) {
34
+ if (value === null || value === undefined || value === '') {
35
+ return null;
36
+ }
37
+
38
+ const date = value instanceof Date ? value : new Date(value);
39
+ return Number.isNaN(date.getTime()) ? null : date;
40
+ }
41
+
42
+ function formatDate(value, locales = 'it-CH', options = {}) {
43
+ const date = toDate(value);
44
+ if (!date) {
45
+ return '';
46
+ }
47
+
48
+ return new Intl.DateTimeFormat(locales, {
49
+ year: 'numeric',
50
+ month: '2-digit',
51
+ day: '2-digit',
52
+ ...options,
53
+ }).format(date);
54
+ }
55
+
56
+ function formatDateTime(value, locales = 'it-CH', options = {}) {
57
+ const date = toDate(value);
58
+ if (!date) {
59
+ return '';
60
+ }
61
+
62
+ return new Intl.DateTimeFormat(locales, {
63
+ year: 'numeric',
64
+ month: '2-digit',
65
+ day: '2-digit',
66
+ hour: '2-digit',
67
+ minute: '2-digit',
68
+ ...options,
69
+ }).format(date);
70
+ }
71
+
72
+ function formatCurrency(amount, currency = 'CHF', locales = 'it-CH', options = {}) {
73
+ if (amount === null || amount === undefined || amount === '') {
74
+ return '';
75
+ }
76
+
77
+ const numericAmount = Number(amount);
78
+ if (Number.isNaN(numericAmount)) {
79
+ return '';
80
+ }
81
+
82
+ return new Intl.NumberFormat(locales, {
83
+ style: 'currency',
84
+ currency,
85
+ ...options,
86
+ }).format(numericAmount);
87
+ }
88
+
89
+ function getUserFullName(user) {
90
+ return [user?.first_name, user?.last_name].filter(Boolean).join(' ').trim();
91
+ }
92
+
93
+ function formatAddress(entity) {
94
+ if (!entity) {
95
+ return '';
96
+ }
97
+
98
+ const line1 = [entity.address_line1, entity.address_line2].filter(Boolean).join(', ');
99
+ const line2 = [entity.postal_code, entity.city].filter(Boolean).join(' ');
100
+
101
+ return [line1, line2, entity.country_code].filter(Boolean).join(', ');
102
+ }
103
+
104
+ function hasUserRole(userRoles, role) {
105
+ return (userRoles ?? []).some((userRole) => {
106
+ if (typeof userRole === 'string') {
107
+ return userRole === role;
108
+ }
109
+
110
+ return userRole?.role === role;
111
+ });
112
+ }
113
+
114
+ function hasAccessChannel(accessChannels, channel) {
115
+ return (accessChannels ?? []).some((accessChannel) => {
116
+ if (typeof accessChannel === 'string') {
117
+ return accessChannel === channel;
118
+ }
119
+
120
+ return accessChannel?.channel === channel && accessChannel?.status !== 'revoked';
121
+ });
122
+ }
123
+
124
+
125
+ module.exports = {
126
+ ACCESS_CHANNELS,
127
+ ACCESS_STATUSES,
128
+ CLAIM_STATUSES,
129
+ COLOR_PALETTE,
130
+ CONDITION_STATUSES,
131
+ INSPECTION_STATUSES,
132
+ INSPECTION_TYPES,
133
+ LEASE_STATUSES,
134
+ MANAGEMENT_ROLES,
135
+ PROPERTY_STATUSES,
136
+ USER_ROLES,
137
+ USER_STATUSES,
138
+ WORK_STATUSES,
139
+ CONSTANTS,
140
+ formatAddress,
141
+ formatCurrency,
142
+ formatDate,
143
+ formatDateTime,
144
+ getUserFullName,
145
+ hasAccessChannel,
146
+ hasUserRole,
147
+ Query,
148
+ toDate,
149
+ };
package/index.mjs CHANGED
@@ -1,31 +1,31 @@
1
- import pkg from './index.js';
2
-
3
- export const {
4
- ACCESS_CHANNELS,
5
- ACCESS_STATUSES,
6
- CLAIM_STATUSES,
7
- COLOR_PALETTE,
8
- CONDITION_STATUSES,
9
- INSPECTION_STATUSES,
10
- INSPECTION_TYPES,
11
- LEASE_STATUSES,
12
- MANAGEMENT_ROLES,
13
- PROPERTY_STATUSES,
14
- PROPERTY_TYPES,
15
- USER_ROLES,
16
- USER_STATUSES,
17
- WORK_STATUSES,
18
- CONSTANTS,
19
- formatAddress,
20
- formatCurrency,
21
- formatDate,
22
- formatDateTime,
23
- getColorPalette,
24
- getUserFullName,
25
- hasAccessChannel,
26
- hasUserRole,
27
- Query,
28
- toDate,
29
- } = pkg;
30
-
31
- export default pkg;
1
+ import pkg from './index.js';
2
+
3
+ export const {
4
+ ACCESS_CHANNELS,
5
+ ACCESS_STATUSES,
6
+ CLAIM_STATUSES,
7
+ COLOR_PALETTE,
8
+ CONDITION_STATUSES,
9
+ INSPECTION_STATUSES,
10
+ INSPECTION_TYPES,
11
+ LEASE_STATUSES,
12
+ MANAGEMENT_ROLES,
13
+ PROPERTY_STATUSES,
14
+ PROPERTY_TYPES,
15
+ USER_ROLES,
16
+ USER_STATUSES,
17
+ WORK_STATUSES,
18
+ CONSTANTS,
19
+ formatAddress,
20
+ formatCurrency,
21
+ formatDate,
22
+ formatDateTime,
23
+ getColorPalette,
24
+ getUserFullName,
25
+ hasAccessChannel,
26
+ hasUserRole,
27
+ Query,
28
+ toDate,
29
+ } = pkg;
30
+
31
+ export default pkg;
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
- {
2
- "name": "@jaws-developers-customers/consulca-types",
3
- "version": "1.0.7",
4
- "description": "Tipi e helper per il dominio Consulca.",
5
- "keywords": [
6
- "consulca",
7
- "mariadb",
8
- "types",
9
- "helpers",
10
- "formatter"
11
- ],
12
- "homepage": "https://github.com/JAWS-Developers-Customers/15-NPMPackage#readme",
13
- "bugs": {
14
- "url": "https://github.com/JAWS-Developers-Customers/15-NPMPackage/issues"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/JAWS-Developers-Customers/15-NPMPackage.git"
19
- },
20
- "license": "UNLICENSED",
21
- "author": "JAWS-Developers-Customers",
22
- "type": "commonjs",
23
- "exports": {
24
- ".": {
25
- "types": "./index.d.ts",
26
- "require": "./index.js",
27
- "import": "./index.mjs",
28
- "default": "./index.js"
29
- }
30
- },
31
- "main": "index.js",
32
- "types": "index.d.ts",
33
- "directories": {
34
- "test": "test"
35
- },
36
- "files": [
37
- "index.js",
38
- "index.mjs",
39
- "index.d.ts",
40
- "README.md"
41
- ],
42
- "scripts": {
43
- "test": "node --test"
44
- },
45
- "publishConfig": {
46
- "access": "public"
47
- },
48
- "devDependencies": {
49
- "jaws-helper": "^3.2.3"
50
- }
51
- }
1
+ {
2
+ "name": "@jaws-developers-customers/consulca-types",
3
+ "version": "1.1.0",
4
+ "description": "Tipi e helper per il dominio Consulca.",
5
+ "keywords": [
6
+ "consulca",
7
+ "mariadb",
8
+ "types",
9
+ "helpers",
10
+ "formatter"
11
+ ],
12
+ "homepage": "https://github.com/JAWS-Developers-Customers/15-NPMPackage#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/JAWS-Developers-Customers/15-NPMPackage/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/JAWS-Developers-Customers/15-NPMPackage.git"
19
+ },
20
+ "license": "UNLICENSED",
21
+ "author": "JAWS-Developers-Customers",
22
+ "type": "commonjs",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./index.d.ts",
26
+ "require": "./index.js",
27
+ "import": "./index.mjs",
28
+ "default": "./index.js"
29
+ }
30
+ },
31
+ "main": "index.js",
32
+ "types": "index.d.ts",
33
+ "directories": {
34
+ "test": "test"
35
+ },
36
+ "files": [
37
+ "index.js",
38
+ "index.mjs",
39
+ "index.d.ts",
40
+ "README.md"
41
+ ],
42
+ "scripts": {
43
+ "test": "node --test"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "devDependencies": {
49
+ "jaws-helper": "^3.2.3"
50
+ }
51
+ }