@gesagro/jaspion-sdk 1.0.11 → 2.0.1
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 +62 -3
- package/dist/index.d.mts +88 -12
- package/dist/index.d.ts +88 -12
- package/dist/index.js +272 -160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +271 -159
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -1,7 +1,66 @@
|
|
|
1
|
+
# @gesagro/jaspion-sdk
|
|
2
|
+
|
|
3
|
+
SDK para o Jaspion.
|
|
4
|
+
|
|
5
|
+
O SDK é agnóstico de transporte: ele não faz requisições HTTP diretamente.
|
|
6
|
+
Em vez disso, você fornece uma implementação de `HttpClient`, que pode ser
|
|
7
|
+
construída sobre qualquer biblioteca HTTP.
|
|
8
|
+
|
|
9
|
+
## Instalação
|
|
10
|
+
|
|
1
11
|
```bash
|
|
2
|
-
npm
|
|
12
|
+
npm install @gesagro/jaspion-sdk
|
|
3
13
|
```
|
|
4
14
|
|
|
5
|
-
|
|
6
|
-
|
|
15
|
+
## Uso com axios
|
|
16
|
+
|
|
17
|
+
### 1. Implemente o `HttpClient`
|
|
18
|
+
|
|
19
|
+
O contrato é simples: receber um `HttpRequest` e devolver um `HttpResponse`.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import axios, { type AxiosInstance } from 'axios'
|
|
23
|
+
import type { HttpClient, HttpRequest, HttpResponse } from '@gesagro/jaspion-sdk'
|
|
24
|
+
|
|
25
|
+
export class AxiosHttpClient implements HttpClient {
|
|
26
|
+
constructor(private readonly instance: AxiosInstance) {}
|
|
27
|
+
|
|
28
|
+
async request<T>({
|
|
29
|
+
method,
|
|
30
|
+
path,
|
|
31
|
+
body,
|
|
32
|
+
headers,
|
|
33
|
+
}: HttpRequest): Promise<HttpResponse<T>> {
|
|
34
|
+
const response = await this.instance.request<T>({
|
|
35
|
+
method,
|
|
36
|
+
url: path,
|
|
37
|
+
data: body,
|
|
38
|
+
headers,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
status: response.status,
|
|
43
|
+
data: response.data,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Instancie o `Jaspion`
|
|
50
|
+
|
|
51
|
+
A `baseURL` e a autenticação ficam na instância do axios, mantendo o SDK
|
|
52
|
+
focado apenas nos recursos da API.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import axios from 'axios'
|
|
56
|
+
import { Jaspion } from '@gesagro/jaspion-sdk'
|
|
57
|
+
import { AxiosHttpClient } from './axios-http-client'
|
|
58
|
+
|
|
59
|
+
const instance = axios.create({
|
|
60
|
+
baseURL: 'https://api.jaspion.com',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const jaspion = new Jaspion({
|
|
64
|
+
http: new AxiosHttpClient(instance),
|
|
65
|
+
})
|
|
7
66
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
|
+
interface HttpRequest {
|
|
3
|
+
method: HttpMethod;
|
|
4
|
+
path: string;
|
|
5
|
+
body?: unknown;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
interface HttpResponse<T = unknown> {
|
|
9
|
+
status: number;
|
|
10
|
+
data: T;
|
|
11
|
+
}
|
|
12
|
+
interface HttpClient {
|
|
13
|
+
request<T = unknown>(request: HttpRequest): Promise<HttpResponse<T>>;
|
|
7
14
|
}
|
|
8
15
|
|
|
9
16
|
interface CsvReport {
|
|
@@ -341,6 +348,26 @@ declare class FarrowingCollectionForm extends Report implements PdfReport {
|
|
|
341
348
|
pdf(input: FarrowingCollectionFormInput): Promise<void>;
|
|
342
349
|
}
|
|
343
350
|
|
|
351
|
+
interface FarrowingForecastInput {
|
|
352
|
+
farmId: string;
|
|
353
|
+
dateRange: {
|
|
354
|
+
start: string;
|
|
355
|
+
end: string;
|
|
356
|
+
};
|
|
357
|
+
calendarType: CalendarType;
|
|
358
|
+
parity: number | null;
|
|
359
|
+
locationId: string | null;
|
|
360
|
+
pen: string | null;
|
|
361
|
+
}
|
|
362
|
+
declare class FarrowingForecast extends Report implements PdfReport, CsvReport {
|
|
363
|
+
readonly template = "@pig-master/farrowing-forecast";
|
|
364
|
+
fileName: string;
|
|
365
|
+
pdf(input: FarrowingForecastInput): Promise<void>;
|
|
366
|
+
csv(input: FarrowingForecastInput): Promise<void>;
|
|
367
|
+
private getResources;
|
|
368
|
+
private getParameters;
|
|
369
|
+
}
|
|
370
|
+
|
|
344
371
|
interface FarrowingListInput {
|
|
345
372
|
farmId: string;
|
|
346
373
|
calendarType: CalendarType;
|
|
@@ -724,6 +751,7 @@ declare class FemaleSwineRecord extends Report implements PdfReport {
|
|
|
724
751
|
|
|
725
752
|
interface FemaleSwineSalePlanningListInput {
|
|
726
753
|
farmId: string;
|
|
754
|
+
query: string | null;
|
|
727
755
|
dateRange: {
|
|
728
756
|
start: string;
|
|
729
757
|
end: string;
|
|
@@ -963,6 +991,29 @@ declare class MaternityPigletTransferCollectionForm extends Report implements Pd
|
|
|
963
991
|
pdf(input: MaternityPigletTransferCollectionFormInput): Promise<void>;
|
|
964
992
|
}
|
|
965
993
|
|
|
994
|
+
interface MaternityPigletTransferListInput {
|
|
995
|
+
dateRange: {
|
|
996
|
+
start: string;
|
|
997
|
+
end: string;
|
|
998
|
+
} | null;
|
|
999
|
+
calendarType: CalendarType;
|
|
1000
|
+
donorId: string | null;
|
|
1001
|
+
donorParity: number | null;
|
|
1002
|
+
donorContext: MaternityContext | null;
|
|
1003
|
+
recipientId: string | null;
|
|
1004
|
+
recipientParity: number | null;
|
|
1005
|
+
recipientContext: MaternityContext | null;
|
|
1006
|
+
farmId: string;
|
|
1007
|
+
}
|
|
1008
|
+
declare class MaternityPigletTransferList extends Report implements PdfReport, CsvReport {
|
|
1009
|
+
readonly template = "@pig-master/maternity-piglet-transfer-list";
|
|
1010
|
+
fileName: string;
|
|
1011
|
+
pdf(input: MaternityPigletTransferListInput): Promise<void>;
|
|
1012
|
+
csv(input: MaternityPigletTransferListInput): Promise<void>;
|
|
1013
|
+
private getResources;
|
|
1014
|
+
private getParameters;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
966
1017
|
type FemaleSwineArrivalReproductiveStatus = 'virgin' | 'pregnant' | 'empty';
|
|
967
1018
|
|
|
968
1019
|
type MatingContext = 'first' | 'normal' | 'estrus-return' | 'post-reproductive-failure';
|
|
@@ -1321,6 +1372,28 @@ declare class WeaningCollectionForm extends Report implements PdfReport {
|
|
|
1321
1372
|
pdf(input: WeaningCollectionFormInput): Promise<void>;
|
|
1322
1373
|
}
|
|
1323
1374
|
|
|
1375
|
+
interface WeaningForecastInput {
|
|
1376
|
+
farmId: string;
|
|
1377
|
+
weaningDate: string;
|
|
1378
|
+
calendarType: CalendarType;
|
|
1379
|
+
parity: number | null;
|
|
1380
|
+
locationId: string | null;
|
|
1381
|
+
pen: string | null;
|
|
1382
|
+
lactationLengthRange: {
|
|
1383
|
+
start: number;
|
|
1384
|
+
end: number;
|
|
1385
|
+
} | null;
|
|
1386
|
+
orderBy: OrderBy<'earTag' | 'lactatingLength' | 'parity' | 'locationName' | 'createdAt'>;
|
|
1387
|
+
}
|
|
1388
|
+
declare class WeaningForecast extends Report implements PdfReport, CsvReport {
|
|
1389
|
+
readonly template = "@pig-master/weaning-forecast";
|
|
1390
|
+
fileName: string;
|
|
1391
|
+
pdf(input: WeaningForecastInput): Promise<void>;
|
|
1392
|
+
csv(input: WeaningForecastInput): Promise<void>;
|
|
1393
|
+
private getResources;
|
|
1394
|
+
private getParameters;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1324
1397
|
interface WeaningListInput {
|
|
1325
1398
|
farmId: string;
|
|
1326
1399
|
dateRange: {
|
|
@@ -1421,15 +1494,18 @@ declare class PigMaster {
|
|
|
1421
1494
|
readonly maternityPigletDeathList: MaternityPigletDeathList;
|
|
1422
1495
|
readonly weaningList: WeaningList;
|
|
1423
1496
|
readonly farrowingList: FarrowingList;
|
|
1497
|
+
readonly maternityPigletTransferList: MaternityPigletTransferList;
|
|
1498
|
+
readonly weaningForecast: WeaningForecast;
|
|
1499
|
+
readonly farrowingForecast: FarrowingForecast;
|
|
1424
1500
|
constructor(http: HttpClient);
|
|
1425
1501
|
}
|
|
1426
1502
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1503
|
+
interface JaspionConfig {
|
|
1504
|
+
http: HttpClient;
|
|
1505
|
+
}
|
|
1506
|
+
declare class Jaspion {
|
|
1429
1507
|
readonly pigMaster: PigMaster;
|
|
1430
|
-
constructor(http:
|
|
1431
|
-
setAccessToken(token: string): void;
|
|
1508
|
+
constructor({ http }: JaspionConfig);
|
|
1432
1509
|
}
|
|
1433
|
-
declare function jaspion(baseUrl: string): JaspionClient;
|
|
1434
1510
|
|
|
1435
|
-
export {
|
|
1511
|
+
export { type HttpClient, type HttpMethod, type HttpRequest, type HttpResponse, Jaspion, type JaspionConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
|
+
interface HttpRequest {
|
|
3
|
+
method: HttpMethod;
|
|
4
|
+
path: string;
|
|
5
|
+
body?: unknown;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
interface HttpResponse<T = unknown> {
|
|
9
|
+
status: number;
|
|
10
|
+
data: T;
|
|
11
|
+
}
|
|
12
|
+
interface HttpClient {
|
|
13
|
+
request<T = unknown>(request: HttpRequest): Promise<HttpResponse<T>>;
|
|
7
14
|
}
|
|
8
15
|
|
|
9
16
|
interface CsvReport {
|
|
@@ -341,6 +348,26 @@ declare class FarrowingCollectionForm extends Report implements PdfReport {
|
|
|
341
348
|
pdf(input: FarrowingCollectionFormInput): Promise<void>;
|
|
342
349
|
}
|
|
343
350
|
|
|
351
|
+
interface FarrowingForecastInput {
|
|
352
|
+
farmId: string;
|
|
353
|
+
dateRange: {
|
|
354
|
+
start: string;
|
|
355
|
+
end: string;
|
|
356
|
+
};
|
|
357
|
+
calendarType: CalendarType;
|
|
358
|
+
parity: number | null;
|
|
359
|
+
locationId: string | null;
|
|
360
|
+
pen: string | null;
|
|
361
|
+
}
|
|
362
|
+
declare class FarrowingForecast extends Report implements PdfReport, CsvReport {
|
|
363
|
+
readonly template = "@pig-master/farrowing-forecast";
|
|
364
|
+
fileName: string;
|
|
365
|
+
pdf(input: FarrowingForecastInput): Promise<void>;
|
|
366
|
+
csv(input: FarrowingForecastInput): Promise<void>;
|
|
367
|
+
private getResources;
|
|
368
|
+
private getParameters;
|
|
369
|
+
}
|
|
370
|
+
|
|
344
371
|
interface FarrowingListInput {
|
|
345
372
|
farmId: string;
|
|
346
373
|
calendarType: CalendarType;
|
|
@@ -724,6 +751,7 @@ declare class FemaleSwineRecord extends Report implements PdfReport {
|
|
|
724
751
|
|
|
725
752
|
interface FemaleSwineSalePlanningListInput {
|
|
726
753
|
farmId: string;
|
|
754
|
+
query: string | null;
|
|
727
755
|
dateRange: {
|
|
728
756
|
start: string;
|
|
729
757
|
end: string;
|
|
@@ -963,6 +991,29 @@ declare class MaternityPigletTransferCollectionForm extends Report implements Pd
|
|
|
963
991
|
pdf(input: MaternityPigletTransferCollectionFormInput): Promise<void>;
|
|
964
992
|
}
|
|
965
993
|
|
|
994
|
+
interface MaternityPigletTransferListInput {
|
|
995
|
+
dateRange: {
|
|
996
|
+
start: string;
|
|
997
|
+
end: string;
|
|
998
|
+
} | null;
|
|
999
|
+
calendarType: CalendarType;
|
|
1000
|
+
donorId: string | null;
|
|
1001
|
+
donorParity: number | null;
|
|
1002
|
+
donorContext: MaternityContext | null;
|
|
1003
|
+
recipientId: string | null;
|
|
1004
|
+
recipientParity: number | null;
|
|
1005
|
+
recipientContext: MaternityContext | null;
|
|
1006
|
+
farmId: string;
|
|
1007
|
+
}
|
|
1008
|
+
declare class MaternityPigletTransferList extends Report implements PdfReport, CsvReport {
|
|
1009
|
+
readonly template = "@pig-master/maternity-piglet-transfer-list";
|
|
1010
|
+
fileName: string;
|
|
1011
|
+
pdf(input: MaternityPigletTransferListInput): Promise<void>;
|
|
1012
|
+
csv(input: MaternityPigletTransferListInput): Promise<void>;
|
|
1013
|
+
private getResources;
|
|
1014
|
+
private getParameters;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
966
1017
|
type FemaleSwineArrivalReproductiveStatus = 'virgin' | 'pregnant' | 'empty';
|
|
967
1018
|
|
|
968
1019
|
type MatingContext = 'first' | 'normal' | 'estrus-return' | 'post-reproductive-failure';
|
|
@@ -1321,6 +1372,28 @@ declare class WeaningCollectionForm extends Report implements PdfReport {
|
|
|
1321
1372
|
pdf(input: WeaningCollectionFormInput): Promise<void>;
|
|
1322
1373
|
}
|
|
1323
1374
|
|
|
1375
|
+
interface WeaningForecastInput {
|
|
1376
|
+
farmId: string;
|
|
1377
|
+
weaningDate: string;
|
|
1378
|
+
calendarType: CalendarType;
|
|
1379
|
+
parity: number | null;
|
|
1380
|
+
locationId: string | null;
|
|
1381
|
+
pen: string | null;
|
|
1382
|
+
lactationLengthRange: {
|
|
1383
|
+
start: number;
|
|
1384
|
+
end: number;
|
|
1385
|
+
} | null;
|
|
1386
|
+
orderBy: OrderBy<'earTag' | 'lactatingLength' | 'parity' | 'locationName' | 'createdAt'>;
|
|
1387
|
+
}
|
|
1388
|
+
declare class WeaningForecast extends Report implements PdfReport, CsvReport {
|
|
1389
|
+
readonly template = "@pig-master/weaning-forecast";
|
|
1390
|
+
fileName: string;
|
|
1391
|
+
pdf(input: WeaningForecastInput): Promise<void>;
|
|
1392
|
+
csv(input: WeaningForecastInput): Promise<void>;
|
|
1393
|
+
private getResources;
|
|
1394
|
+
private getParameters;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1324
1397
|
interface WeaningListInput {
|
|
1325
1398
|
farmId: string;
|
|
1326
1399
|
dateRange: {
|
|
@@ -1421,15 +1494,18 @@ declare class PigMaster {
|
|
|
1421
1494
|
readonly maternityPigletDeathList: MaternityPigletDeathList;
|
|
1422
1495
|
readonly weaningList: WeaningList;
|
|
1423
1496
|
readonly farrowingList: FarrowingList;
|
|
1497
|
+
readonly maternityPigletTransferList: MaternityPigletTransferList;
|
|
1498
|
+
readonly weaningForecast: WeaningForecast;
|
|
1499
|
+
readonly farrowingForecast: FarrowingForecast;
|
|
1424
1500
|
constructor(http: HttpClient);
|
|
1425
1501
|
}
|
|
1426
1502
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1503
|
+
interface JaspionConfig {
|
|
1504
|
+
http: HttpClient;
|
|
1505
|
+
}
|
|
1506
|
+
declare class Jaspion {
|
|
1429
1507
|
readonly pigMaster: PigMaster;
|
|
1430
|
-
constructor(http:
|
|
1431
|
-
setAccessToken(token: string): void;
|
|
1508
|
+
constructor({ http }: JaspionConfig);
|
|
1432
1509
|
}
|
|
1433
|
-
declare function jaspion(baseUrl: string): JaspionClient;
|
|
1434
1510
|
|
|
1435
|
-
export {
|
|
1511
|
+
export { type HttpClient, type HttpMethod, type HttpRequest, type HttpResponse, Jaspion, type JaspionConfig };
|