@gesagro/jaspion-sdk 1.0.10 → 2.0.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 +62 -3
- package/dist/index.d.mts +47 -12
- package/dist/index.d.ts +47 -12
- package/dist/index.js +185 -158
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -157
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
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,33 @@ declare class FarrowingCollectionForm extends Report implements PdfReport {
|
|
|
341
348
|
pdf(input: FarrowingCollectionFormInput): Promise<void>;
|
|
342
349
|
}
|
|
343
350
|
|
|
351
|
+
interface FarrowingListInput {
|
|
352
|
+
farmId: string;
|
|
353
|
+
calendarType: CalendarType;
|
|
354
|
+
dateRange: {
|
|
355
|
+
start: string;
|
|
356
|
+
end: string;
|
|
357
|
+
} | null;
|
|
358
|
+
femaleSwineId: string | null;
|
|
359
|
+
parity: number | null;
|
|
360
|
+
matingDateRange: {
|
|
361
|
+
start: string;
|
|
362
|
+
end: string;
|
|
363
|
+
} | null;
|
|
364
|
+
birthPlaceId: string | null;
|
|
365
|
+
originId: string | null;
|
|
366
|
+
breedId: string | null;
|
|
367
|
+
orderBy: OrderBy<'date' | 'parity' | 'liveborn' | 'stillborn' | 'mummified' | 'createdAt'>;
|
|
368
|
+
}
|
|
369
|
+
declare class FarrowingList extends Report implements PdfReport, CsvReport {
|
|
370
|
+
readonly template = "@pig-master/farrowing-list";
|
|
371
|
+
fileName: string;
|
|
372
|
+
pdf(input: FarrowingListInput): Promise<void>;
|
|
373
|
+
csv(input: FarrowingListInput): Promise<void>;
|
|
374
|
+
private getResources;
|
|
375
|
+
private getParameters;
|
|
376
|
+
}
|
|
377
|
+
|
|
344
378
|
interface FarrowingTypeListInput {
|
|
345
379
|
farmId: string;
|
|
346
380
|
language: Language;
|
|
@@ -1393,15 +1427,16 @@ declare class PigMaster {
|
|
|
1393
1427
|
readonly weaningCollectionForm: WeaningCollectionForm;
|
|
1394
1428
|
readonly maternityPigletDeathList: MaternityPigletDeathList;
|
|
1395
1429
|
readonly weaningList: WeaningList;
|
|
1430
|
+
readonly farrowingList: FarrowingList;
|
|
1396
1431
|
constructor(http: HttpClient);
|
|
1397
1432
|
}
|
|
1398
1433
|
|
|
1399
|
-
|
|
1400
|
-
|
|
1434
|
+
interface JaspionConfig {
|
|
1435
|
+
http: HttpClient;
|
|
1436
|
+
}
|
|
1437
|
+
declare class Jaspion {
|
|
1401
1438
|
readonly pigMaster: PigMaster;
|
|
1402
|
-
constructor(http:
|
|
1403
|
-
setAccessToken(token: string): void;
|
|
1439
|
+
constructor({ http }: JaspionConfig);
|
|
1404
1440
|
}
|
|
1405
|
-
declare function jaspion(baseUrl: string): JaspionClient;
|
|
1406
1441
|
|
|
1407
|
-
export {
|
|
1442
|
+
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,33 @@ declare class FarrowingCollectionForm extends Report implements PdfReport {
|
|
|
341
348
|
pdf(input: FarrowingCollectionFormInput): Promise<void>;
|
|
342
349
|
}
|
|
343
350
|
|
|
351
|
+
interface FarrowingListInput {
|
|
352
|
+
farmId: string;
|
|
353
|
+
calendarType: CalendarType;
|
|
354
|
+
dateRange: {
|
|
355
|
+
start: string;
|
|
356
|
+
end: string;
|
|
357
|
+
} | null;
|
|
358
|
+
femaleSwineId: string | null;
|
|
359
|
+
parity: number | null;
|
|
360
|
+
matingDateRange: {
|
|
361
|
+
start: string;
|
|
362
|
+
end: string;
|
|
363
|
+
} | null;
|
|
364
|
+
birthPlaceId: string | null;
|
|
365
|
+
originId: string | null;
|
|
366
|
+
breedId: string | null;
|
|
367
|
+
orderBy: OrderBy<'date' | 'parity' | 'liveborn' | 'stillborn' | 'mummified' | 'createdAt'>;
|
|
368
|
+
}
|
|
369
|
+
declare class FarrowingList extends Report implements PdfReport, CsvReport {
|
|
370
|
+
readonly template = "@pig-master/farrowing-list";
|
|
371
|
+
fileName: string;
|
|
372
|
+
pdf(input: FarrowingListInput): Promise<void>;
|
|
373
|
+
csv(input: FarrowingListInput): Promise<void>;
|
|
374
|
+
private getResources;
|
|
375
|
+
private getParameters;
|
|
376
|
+
}
|
|
377
|
+
|
|
344
378
|
interface FarrowingTypeListInput {
|
|
345
379
|
farmId: string;
|
|
346
380
|
language: Language;
|
|
@@ -1393,15 +1427,16 @@ declare class PigMaster {
|
|
|
1393
1427
|
readonly weaningCollectionForm: WeaningCollectionForm;
|
|
1394
1428
|
readonly maternityPigletDeathList: MaternityPigletDeathList;
|
|
1395
1429
|
readonly weaningList: WeaningList;
|
|
1430
|
+
readonly farrowingList: FarrowingList;
|
|
1396
1431
|
constructor(http: HttpClient);
|
|
1397
1432
|
}
|
|
1398
1433
|
|
|
1399
|
-
|
|
1400
|
-
|
|
1434
|
+
interface JaspionConfig {
|
|
1435
|
+
http: HttpClient;
|
|
1436
|
+
}
|
|
1437
|
+
declare class Jaspion {
|
|
1401
1438
|
readonly pigMaster: PigMaster;
|
|
1402
|
-
constructor(http:
|
|
1403
|
-
setAccessToken(token: string): void;
|
|
1439
|
+
constructor({ http }: JaspionConfig);
|
|
1404
1440
|
}
|
|
1405
|
-
declare function jaspion(baseUrl: string): JaspionClient;
|
|
1406
1441
|
|
|
1407
|
-
export {
|
|
1442
|
+
export { type HttpClient, type HttpMethod, type HttpRequest, type HttpResponse, Jaspion, type JaspionConfig };
|