@deliverart/sdk-js-company 2.1.49 → 2.1.51

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 (2) hide show
  1. package/README.md +516 -0
  2. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,516 @@
1
+ # @deliverart/sdk-js-company
2
+
3
+ Company management package for the DeliverArt JavaScript SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @deliverart/sdk-js-company @deliverart/sdk-js-core
9
+ # or
10
+ pnpm add @deliverart/sdk-js-company @deliverart/sdk-js-core
11
+ # or
12
+ yarn add @deliverart/sdk-js-company @deliverart/sdk-js-core
13
+ ```
14
+
15
+ ## Exported Types
16
+
17
+ ### Models
18
+
19
+ #### Company
20
+ ```typescript
21
+ interface Company {
22
+ id: string
23
+ businessName: string
24
+ vat: string
25
+ taxCode: string | null
26
+ operationalAddress: Address
27
+ createdAt: string
28
+ updatedAt: string
29
+ }
30
+ ```
31
+ Basic company information.
32
+
33
+ **Properties:**
34
+ - `id: string` - Unique company identifier
35
+ - `businessName: string` - Company business name (required)
36
+ - `vat: string` - VAT number (required)
37
+ - `taxCode: string | null` - Tax code (optional)
38
+ - `operationalAddress: Address` - Operational address (required)
39
+ - `createdAt: string` - Creation timestamp (ISO 8601)
40
+ - `updatedAt: string` - Last update timestamp (ISO 8601)
41
+
42
+ #### CompanyDetails
43
+ ```typescript
44
+ interface CompanyDetails extends Company {
45
+ billingAddress: Address
46
+ billingData: BillingData
47
+ adminBy: string
48
+ }
49
+ ```
50
+ Extended company information with billing details.
51
+
52
+ **Additional Properties:**
53
+ - `billingAddress: Address` - Billing address (required)
54
+ - `billingData: BillingData` - Billing information (required)
55
+ - `adminBy: string` - User IRI who administers the company (required)
56
+
57
+ #### CompaniesQueryParams
58
+ ```typescript
59
+ interface CompaniesQueryParams {
60
+ businessName?: string
61
+ vat?: string
62
+ taxCode?: string
63
+ 'billingAddress.city'?: string
64
+ 'billingAddress.postalCode'?: string
65
+ 'operationalAddress.city'?: string
66
+ 'operationalAddress.postalCode'?: string
67
+ 'order[businessName]'?: 'asc' | 'desc'
68
+ 'order[createdAt]'?: 'asc' | 'desc'
69
+ 'order[updatedAt]'?: 'asc' | 'desc'
70
+ page?: number
71
+ }
72
+ ```
73
+ Query parameters for filtering and sorting companies.
74
+
75
+ **Filter Parameters:**
76
+ - `businessName?: string` - Filter by business name (partial match)
77
+ - `vat?: string` - Filter by VAT number (exact match)
78
+ - `taxCode?: string` - Filter by tax code (exact match)
79
+ - `billingAddress.city?: string` - Filter by billing city
80
+ - `billingAddress.postalCode?: string` - Filter by billing postal code
81
+ - `operationalAddress.city?: string` - Filter by operational city
82
+ - `operationalAddress.postalCode?: string` - Filter by operational postal code
83
+
84
+ **Sort Parameters:**
85
+ - `order[businessName]?: 'asc' | 'desc'` - Sort by business name
86
+ - `order[createdAt]?: 'asc' | 'desc'` - Sort by creation date
87
+ - `order[updatedAt]?: 'asc' | 'desc'` - Sort by update date
88
+
89
+ **Pagination:**
90
+ - `page?: number` - Page number (default: 1)
91
+
92
+ ### IRI Types
93
+
94
+ #### CompanyIri
95
+ ```typescript
96
+ type CompanyIri = string
97
+ ```
98
+ Company IRI type (format: `/companies/:id`)
99
+
100
+ #### CompanyNullableIri
101
+ ```typescript
102
+ type CompanyNullableIri = string | null
103
+ ```
104
+ Nullable company IRI type
105
+
106
+ ## Available Requests
107
+
108
+ ### CreateCompany
109
+
110
+ Create a new company.
111
+
112
+ **Class:** `CreateCompany`
113
+
114
+ **Input Schema:**
115
+ ```typescript
116
+ {
117
+ businessName: string // Required, min 1 char
118
+ vat: string // Required
119
+ taxCode?: string | null // Optional
120
+ billingAddress: { // Required
121
+ street: string
122
+ city: string
123
+ postalCode: string
124
+ country: string
125
+ state?: string
126
+ province?: string
127
+ }
128
+ operationalAddress: { // Required
129
+ street: string
130
+ city: string
131
+ postalCode: string
132
+ country: string
133
+ state?: string
134
+ province?: string
135
+ }
136
+ billingData: { // Required
137
+ email: string
138
+ pec?: string
139
+ sdi?: string
140
+ }
141
+ adminBy: string // Required, User IRI (e.g., '/users/123')
142
+ }
143
+ ```
144
+
145
+ **Response:** `CompanyDetails`
146
+
147
+ **Example:**
148
+ ```typescript
149
+ import { CreateCompany } from '@deliverart/sdk-js-company';
150
+
151
+ const company = await sdk.call(new CreateCompany({
152
+ businessName: 'Acme Corporation',
153
+ vat: 'IT12345678901',
154
+ taxCode: 'ACME1234567890',
155
+ billingAddress: {
156
+ street: 'Via Roma 1',
157
+ city: 'Milano',
158
+ postalCode: '20100',
159
+ country: 'IT'
160
+ },
161
+ operationalAddress: {
162
+ street: 'Via Roma 1',
163
+ city: 'Milano',
164
+ postalCode: '20100',
165
+ country: 'IT'
166
+ },
167
+ billingData: {
168
+ email: 'billing@acme.com',
169
+ pec: 'acme@pec.it'
170
+ },
171
+ adminBy: '/users/123'
172
+ }));
173
+ ```
174
+
175
+ **Validation:**
176
+ - `businessName`: Required, minimum 1 character
177
+ - `vat`: Required
178
+ - `billingAddress`: Required, all address fields validated
179
+ - `operationalAddress`: Required, all address fields validated
180
+ - `billingData`: Required, email must be valid
181
+ - `adminBy`: Required, must be a valid User IRI
182
+
183
+ ---
184
+
185
+ ### GetCompanies
186
+
187
+ Get a paginated list of companies with optional filters.
188
+
189
+ **Class:** `GetCompanies`
190
+
191
+ **Constructor:**
192
+ ```typescript
193
+ new GetCompanies(options?: { query?: CompaniesQueryParams })
194
+ ```
195
+
196
+ **Query Parameters:** See `CompaniesQueryParams` above
197
+
198
+ **Response:** `Paginated<Company>`
199
+
200
+ **Example:**
201
+ ```typescript
202
+ import { GetCompanies } from '@deliverart/sdk-js-company';
203
+
204
+ // Get all companies
205
+ const companies = await sdk.call(new GetCompanies());
206
+
207
+ // Get companies with filters
208
+ const filtered = await sdk.call(new GetCompanies({
209
+ query: {
210
+ businessName: 'Acme',
211
+ 'operationalAddress.city': 'Milano',
212
+ 'order[createdAt]': 'desc',
213
+ page: 1
214
+ }
215
+ }));
216
+
217
+ // Access pagination info
218
+ console.log(filtered.pagination.totalItems);
219
+ console.log(filtered.pagination.currentPage);
220
+ console.log(filtered.pagination.itemsPerPage);
221
+
222
+ // Access data
223
+ filtered.data.forEach(company => {
224
+ console.log(company.businessName);
225
+ });
226
+ ```
227
+
228
+ **Validation:**
229
+ - `page`: Optional, must be a positive number
230
+ - All filter values are optional
231
+
232
+ ---
233
+
234
+ ### GetCompanyDetails
235
+
236
+ Get detailed information about a specific company.
237
+
238
+ **Class:** `GetCompanyDetails`
239
+
240
+ **Constructor:**
241
+ ```typescript
242
+ new GetCompanyDetails(companyId: string)
243
+ ```
244
+
245
+ **Parameters:**
246
+ - `companyId: string` - Company ID (required)
247
+
248
+ **Response:** `CompanyDetails`
249
+
250
+ **Example:**
251
+ ```typescript
252
+ import { GetCompanyDetails } from '@deliverart/sdk-js-company';
253
+
254
+ const company = await sdk.call(new GetCompanyDetails('company-123'));
255
+
256
+ console.log(company.businessName);
257
+ console.log(company.billingAddress);
258
+ console.log(company.billingData);
259
+ ```
260
+
261
+ **Validation:**
262
+ - `companyId`: Required, must be a non-empty string
263
+
264
+ ---
265
+
266
+ ### GetUserCompanies
267
+
268
+ Get companies administered by a specific user.
269
+
270
+ **Class:** `GetUserCompanies`
271
+
272
+ **Constructor:**
273
+ ```typescript
274
+ new GetUserCompanies(userId: string)
275
+ ```
276
+
277
+ **Parameters:**
278
+ - `userId: string` - User ID (required)
279
+
280
+ **Response:** `Company[]`
281
+
282
+ **Example:**
283
+ ```typescript
284
+ import { GetUserCompanies } from '@deliverart/sdk-js-company';
285
+
286
+ const companies = await sdk.call(new GetUserCompanies('user-123'));
287
+
288
+ companies.forEach(company => {
289
+ console.log(company.businessName);
290
+ });
291
+ ```
292
+
293
+ **Validation:**
294
+ - `userId`: Required, must be a non-empty string
295
+
296
+ ---
297
+
298
+ ### UpdateCompany
299
+
300
+ Update an existing company (partial update).
301
+
302
+ **Class:** `UpdateCompany`
303
+
304
+ **Constructor:**
305
+ ```typescript
306
+ new UpdateCompany(companyId: string, input: Partial<CompanyInput>)
307
+ ```
308
+
309
+ **Parameters:**
310
+ - `companyId: string` - Company ID (required)
311
+ - `input: Partial<CompanyInput>` - Fields to update (all optional)
312
+
313
+ **Input Schema:**
314
+ ```typescript
315
+ {
316
+ businessName?: string
317
+ vat?: string
318
+ taxCode?: string | null
319
+ billingAddress?: {
320
+ street: string
321
+ city: string
322
+ postalCode: string
323
+ country: string
324
+ state?: string
325
+ province?: string
326
+ }
327
+ operationalAddress?: {
328
+ street: string
329
+ city: string
330
+ postalCode: string
331
+ country: string
332
+ state?: string
333
+ province?: string
334
+ }
335
+ billingData?: {
336
+ email: string
337
+ pec?: string
338
+ sdi?: string
339
+ }
340
+ adminBy?: string // User IRI
341
+ }
342
+ ```
343
+
344
+ **Response:** `CompanyDetails`
345
+
346
+ **Example:**
347
+ ```typescript
348
+ import { UpdateCompany } from '@deliverart/sdk-js-company';
349
+
350
+ // Update single field
351
+ const updated = await sdk.call(new UpdateCompany('company-123', {
352
+ businessName: 'Acme Corp Updated'
353
+ }));
354
+
355
+ // Update multiple fields
356
+ const updated = await sdk.call(new UpdateCompany('company-123', {
357
+ businessName: 'New Name',
358
+ billingAddress: {
359
+ street: 'Via Nuova 10',
360
+ city: 'Roma',
361
+ postalCode: '00100',
362
+ country: 'IT'
363
+ }
364
+ }));
365
+ ```
366
+
367
+ **Validation:**
368
+ - `companyId`: Required, must be a non-empty string
369
+ - All input fields are optional but validated when provided
370
+ - Uses `application/merge-patch+json` content type for partial updates
371
+
372
+ ---
373
+
374
+ ### DeleteCompany
375
+
376
+ Delete a company.
377
+
378
+ **Class:** `DeleteCompany`
379
+
380
+ **Constructor:**
381
+ ```typescript
382
+ new DeleteCompany(companyId: string)
383
+ ```
384
+
385
+ **Parameters:**
386
+ - `companyId: string` - Company ID (required)
387
+
388
+ **Response:** `void`
389
+
390
+ **Example:**
391
+ ```typescript
392
+ import { DeleteCompany } from '@deliverart/sdk-js-company';
393
+
394
+ await sdk.call(new DeleteCompany('company-123'));
395
+ ```
396
+
397
+ **Validation:**
398
+ - `companyId`: Required, must be a non-empty string
399
+
400
+ ---
401
+
402
+ ## Complete Usage Example
403
+
404
+ ```typescript
405
+ import { sdk } from './lib/sdk';
406
+ import {
407
+ CreateCompany,
408
+ GetCompanies,
409
+ GetCompanyDetails,
410
+ GetUserCompanies,
411
+ UpdateCompany,
412
+ DeleteCompany
413
+ } from '@deliverart/sdk-js-company';
414
+
415
+ async function companyManagement() {
416
+ // Create a company
417
+ const newCompany = await sdk.call(new CreateCompany({
418
+ businessName: 'Tech Startup SRL',
419
+ vat: 'IT98765432109',
420
+ taxCode: null,
421
+ billingAddress: {
422
+ street: 'Via Innovation 42',
423
+ city: 'Milano',
424
+ postalCode: '20100',
425
+ country: 'IT'
426
+ },
427
+ operationalAddress: {
428
+ street: 'Via Innovation 42',
429
+ city: 'Milano',
430
+ postalCode: '20100',
431
+ country: 'IT'
432
+ },
433
+ billingData: {
434
+ email: 'billing@techstartup.it',
435
+ pec: 'techstartup@pec.it'
436
+ },
437
+ adminBy: '/users/456'
438
+ }));
439
+
440
+ console.log('Created company:', newCompany.id);
441
+
442
+ // Get all companies
443
+ const allCompanies = await sdk.call(new GetCompanies());
444
+ console.log(`Total companies: ${allCompanies.pagination.totalItems}`);
445
+
446
+ // Search companies
447
+ const milanCompanies = await sdk.call(new GetCompanies({
448
+ query: {
449
+ 'operationalAddress.city': 'Milano',
450
+ 'order[businessName]': 'asc'
451
+ }
452
+ }));
453
+
454
+ // Get company details
455
+ const details = await sdk.call(new GetCompanyDetails(newCompany.id));
456
+ console.log('Billing email:', details.billingData.email);
457
+
458
+ // Get user's companies
459
+ const userCompanies = await sdk.call(new GetUserCompanies('user-456'));
460
+ console.log(`User has ${userCompanies.length} companies`);
461
+
462
+ // Update company
463
+ const updated = await sdk.call(new UpdateCompany(newCompany.id, {
464
+ businessName: 'Tech Startup Updated SRL',
465
+ billingData: {
466
+ email: 'new-billing@techstartup.it',
467
+ pec: 'techstartup@pec.it',
468
+ sdi: 'ABC1234'
469
+ }
470
+ }));
471
+
472
+ // Delete company
473
+ await sdk.call(new DeleteCompany(newCompany.id));
474
+ console.log('Company deleted');
475
+ }
476
+ ```
477
+
478
+ ## Error Handling
479
+
480
+ ```typescript
481
+ import { ApiError } from '@deliverart/sdk-js-error-handler';
482
+ import { CreateCompany } from '@deliverart/sdk-js-company';
483
+
484
+ try {
485
+ await sdk.call(new CreateCompany({
486
+ businessName: '', // Invalid: too short
487
+ vat: 'INVALID',
488
+ // ... other fields
489
+ }));
490
+ } catch (error) {
491
+ if (error instanceof ApiError && error.data?.type === 'VALIDATION_ERROR') {
492
+ error.data.value.violations.forEach(violation => {
493
+ console.error(`${violation.propertyPath}: ${violation.message}`);
494
+ });
495
+ }
496
+ }
497
+ ```
498
+
499
+ ## TypeScript Types
500
+
501
+ All types are fully typed with TypeScript. Import them directly:
502
+
503
+ ```typescript
504
+ import type {
505
+ Company,
506
+ CompanyDetails,
507
+ CompaniesQueryParams,
508
+ CompanyIri,
509
+ CompanyNullableIri
510
+ } from '@deliverart/sdk-js-company';
511
+ ```
512
+
513
+ ## License
514
+
515
+ MIT
516
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deliverart/sdk-js-company",
3
3
  "description": "Deliverart JavaScript SDK for Company Management",
4
- "version": "2.1.49",
4
+ "version": "2.1.51",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "@deliverart/sdk-js-core": "2.1.49",
22
- "@deliverart/sdk-js-global-types": "2.1.49",
23
- "@deliverart/sdk-js-user": "2.1.49"
21
+ "@deliverart/sdk-js-core": "2.1.51",
22
+ "@deliverart/sdk-js-global-types": "2.1.51",
23
+ "@deliverart/sdk-js-user": "2.1.51"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"