@gesagro/jaspion-sdk 1.0.1 → 1.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ```bash
2
+ npm version x.x.x
3
+ ```
4
+
5
+ ```bash
6
+ npm publish
7
+ ```
package/dist/index.d.mts CHANGED
@@ -1,4 +1,10 @@
1
- import { AxiosInstance } from 'axios';
1
+ declare class HttpClient {
2
+ private readonly baseUrl;
3
+ private readonly headers;
4
+ constructor(baseUrl: string);
5
+ setHeader(key: string, value: string): void;
6
+ post(path: string, body: unknown): Promise<void>;
7
+ }
2
8
 
3
9
  type ContentType = 'application/pdf' | 'text/csv';
4
10
  interface Parameter {
@@ -19,9 +25,9 @@ interface RequestReportInput {
19
25
  resources: Resource[];
20
26
  }
21
27
  declare abstract class Report {
22
- protected readonly http: AxiosInstance;
28
+ protected readonly http: HttpClient;
23
29
  protected readonly config: ReportConfig;
24
- constructor(http: AxiosInstance, config: ReportConfig);
30
+ constructor(http: HttpClient, config: ReportConfig);
25
31
  protected request({ contentType, parameters, resources, }: RequestReportInput): Promise<void>;
26
32
  }
27
33
 
@@ -32,22 +38,22 @@ interface OriginListInput {
32
38
  language: LanguageCode;
33
39
  }
34
40
  declare class OriginList extends Report {
35
- constructor(http: AxiosInstance);
41
+ constructor(http: HttpClient);
36
42
  pdf(input: OriginListInput): Promise<void>;
37
43
  csv(input: OriginListInput): Promise<void>;
38
44
  }
39
45
 
40
46
  declare class PigMasterNamespace {
41
47
  readonly originList: OriginList;
42
- constructor(http: AxiosInstance);
48
+ constructor(http: HttpClient);
43
49
  }
44
50
 
45
51
  declare class JaspionClient {
46
52
  private readonly http;
47
53
  readonly pigMaster: PigMasterNamespace;
48
- constructor(http: AxiosInstance);
54
+ constructor(http: HttpClient);
49
55
  setAccessToken(token: string): void;
50
56
  }
51
- declare function jaspion(baseURL: string): JaspionClient;
57
+ declare function jaspion(baseUrl: string): JaspionClient;
52
58
 
53
59
  export { jaspion };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { AxiosInstance } from 'axios';
1
+ declare class HttpClient {
2
+ private readonly baseUrl;
3
+ private readonly headers;
4
+ constructor(baseUrl: string);
5
+ setHeader(key: string, value: string): void;
6
+ post(path: string, body: unknown): Promise<void>;
7
+ }
2
8
 
3
9
  type ContentType = 'application/pdf' | 'text/csv';
4
10
  interface Parameter {
@@ -19,9 +25,9 @@ interface RequestReportInput {
19
25
  resources: Resource[];
20
26
  }
21
27
  declare abstract class Report {
22
- protected readonly http: AxiosInstance;
28
+ protected readonly http: HttpClient;
23
29
  protected readonly config: ReportConfig;
24
- constructor(http: AxiosInstance, config: ReportConfig);
30
+ constructor(http: HttpClient, config: ReportConfig);
25
31
  protected request({ contentType, parameters, resources, }: RequestReportInput): Promise<void>;
26
32
  }
27
33
 
@@ -32,22 +38,22 @@ interface OriginListInput {
32
38
  language: LanguageCode;
33
39
  }
34
40
  declare class OriginList extends Report {
35
- constructor(http: AxiosInstance);
41
+ constructor(http: HttpClient);
36
42
  pdf(input: OriginListInput): Promise<void>;
37
43
  csv(input: OriginListInput): Promise<void>;
38
44
  }
39
45
 
40
46
  declare class PigMasterNamespace {
41
47
  readonly originList: OriginList;
42
- constructor(http: AxiosInstance);
48
+ constructor(http: HttpClient);
43
49
  }
44
50
 
45
51
  declare class JaspionClient {
46
52
  private readonly http;
47
53
  readonly pigMaster: PigMasterNamespace;
48
- constructor(http: AxiosInstance);
54
+ constructor(http: HttpClient);
49
55
  setAccessToken(token: string): void;
50
56
  }
51
- declare function jaspion(baseURL: string): JaspionClient;
57
+ declare function jaspion(baseUrl: string): JaspionClient;
52
58
 
53
59
  export { jaspion };
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -34,8 +24,28 @@ __export(index_exports, {
34
24
  });
35
25
  module.exports = __toCommonJS(index_exports);
36
26
 
37
- // src/client.ts
38
- var import_axios = __toESM(require("axios"));
27
+ // src/core/http-client.ts
28
+ var HttpClient = class {
29
+ constructor(baseUrl) {
30
+ this.baseUrl = baseUrl;
31
+ this.headers = {
32
+ "Content-Type": "application/json"
33
+ };
34
+ }
35
+ setHeader(key, value) {
36
+ this.headers[key] = value;
37
+ }
38
+ async post(path, body) {
39
+ const response = await fetch(`${this.baseUrl}${path}`, {
40
+ method: "POST",
41
+ headers: this.headers,
42
+ body: JSON.stringify(body)
43
+ });
44
+ if (!response.ok) {
45
+ throw new Error(`Request failed with status ${response.status}`);
46
+ }
47
+ }
48
+ };
39
49
 
40
50
  // src/core/report.ts
41
51
  var Report = class {
@@ -84,7 +94,7 @@ var OriginList = class extends Report {
84
94
  contentType: "text/csv",
85
95
  resources: [{ key: "FARM_ID", value: input.farmId }],
86
96
  parameters: [
87
- { key: "DATA_ONLY", value: false },
97
+ { key: "DATA_ONLY", value: true },
88
98
  { key: "LOCATE", value: input.language.replace("-", "_") }
89
99
  ]
90
100
  });
@@ -105,11 +115,11 @@ var JaspionClient = class {
105
115
  this.pigMaster = new PigMasterNamespace(http);
106
116
  }
107
117
  setAccessToken(token) {
108
- this.http.defaults.headers.common.Authorization = `Bearer ${token}`;
118
+ this.http.setHeader("Authorization", `Bearer ${token}`);
109
119
  }
110
120
  };
111
- function jaspion(baseURL) {
112
- const http = import_axios.default.create({ baseURL });
121
+ function jaspion(baseUrl) {
122
+ const http = new HttpClient(baseUrl);
113
123
  return new JaspionClient(http);
114
124
  }
115
125
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/core/report.ts","../src/namespaces/pig-master/reports/origin-list.ts","../src/namespaces/pig-master/index.ts"],"sourcesContent":["export { jaspion } from './client'\n","import axios, { type AxiosInstance } from 'axios'\nimport { PigMasterNamespace } from './namespaces/pig-master'\n\nexport class JaspionClient {\n public readonly pigMaster: PigMasterNamespace\n\n constructor(private readonly http: AxiosInstance) {\n this.pigMaster = new PigMasterNamespace(http)\n }\n\n setAccessToken(token: string) {\n this.http.defaults.headers.common.Authorization = `Bearer ${token}`\n }\n}\n\nexport function jaspion(baseURL: string) {\n const http = axios.create({ baseURL })\n\n return new JaspionClient(http)\n}\n","import type { AxiosInstance } from 'axios'\n\ntype ContentType = 'application/pdf' | 'text/csv'\n\nexport interface Parameter {\n key: string\n value: string | number | boolean | null\n}\n\nexport interface Resource {\n key: string\n value: string\n}\n\ninterface ReportConfig {\n template: string\n fileName: string\n}\n\ninterface RequestReportInput {\n contentType: ContentType\n parameters: Parameter[]\n resources: Resource[]\n}\n\nexport abstract class Report {\n constructor(\n protected readonly http: AxiosInstance,\n protected readonly config: ReportConfig,\n ) {}\n\n protected async request({\n contentType,\n parameters,\n resources,\n }: RequestReportInput) {\n const extension = contentType === 'application/pdf' ? '.pdf' : '.csv'\n const fileName = `${this.config.fileName}${extension}`\n\n await this.http.post('/reports', {\n template: this.config.template,\n fileName: fileName,\n parameters,\n resources,\n contentType,\n type: 'jasper-reports',\n })\n }\n}\n","import type { AxiosInstance } from 'axios'\nimport { Report } from '../../../core/report'\nimport { LanguageCode } from '../../../core/types'\n\ninterface OriginListInput {\n farmId: string\n language: LanguageCode\n}\n\nexport class OriginList extends Report {\n constructor(http: AxiosInstance) {\n super(http, {\n template: '@pig-master/origin-list',\n fileName: 'Listagem de origens',\n })\n }\n\n async pdf(input: OriginListInput) {\n return await this.request({\n contentType: 'application/pdf',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: false },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n\n async csv(input: OriginListInput) {\n return await this.request({\n contentType: 'text/csv',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: false },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n}\n","import type { AxiosInstance } from 'axios'\nimport { OriginList } from './reports/origin-list'\n\nexport class PigMasterNamespace {\n public readonly originList: OriginList\n\n constructor(http: AxiosInstance) {\n this.originList = new OriginList(http)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;;;ACyBnC,IAAe,SAAf,MAAsB;AAAA,EAC3B,YACqB,MACA,QACnB;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,MAAgB,QAAQ;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAuB;AACrB,UAAM,YAAY,gBAAgB,oBAAoB,SAAS;AAC/D,UAAM,WAAW,GAAG,KAAK,OAAO,QAAQ,GAAG,SAAS;AAEpD,UAAM,KAAK,KAAK,KAAK,YAAY;AAAA,MAC/B,UAAU,KAAK,OAAO;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,IACR,C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cAAc,IAAI;AAC/B;","names":["axios"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/core/http-client.ts","../src/core/report.ts","../src/namespaces/pig-master/reports/origin-list.ts","../src/namespaces/pig-master/index.ts","../src/client.ts"],"sourcesContent":["export { jaspion } from './client'\n","export class HttpClient {\n private readonly headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n constructor(private readonly baseUrl: string) {}\n\n setHeader(key: string, value: string) {\n this.headers[key] = value\n }\n\n async post(path: string, body: unknown) {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(body),\n })\n\n if (!response.ok) {\n throw new Error(`Request failed with status ${response.status}`)\n }\n }\n}\n","import type { HttpClient } from './http-client'\n\ntype ContentType = 'application/pdf' | 'text/csv'\n\nexport interface Parameter {\n key: string\n value: string | number | boolean | null\n}\n\nexport interface Resource {\n key: string\n value: string\n}\n\ninterface ReportConfig {\n template: string\n fileName: string\n}\n\ninterface RequestReportInput {\n contentType: ContentType\n parameters: Parameter[]\n resources: Resource[]\n}\n\nexport abstract class Report {\n constructor(\n protected readonly http: HttpClient,\n protected readonly config: ReportConfig,\n ) {}\n\n protected async request({\n contentType,\n parameters,\n resources,\n }: RequestReportInput) {\n const extension = contentType === 'application/pdf' ? '.pdf' : '.csv'\n const fileName = `${this.config.fileName}${extension}`\n\n await this.http.post('/reports', {\n template: this.config.template,\n fileName,\n parameters,\n resources,\n contentType,\n type: 'jasper-reports',\n })\n }\n}\n","import type { HttpClient } from '../../../core/http-client'\nimport { Report } from '../../../core/report'\nimport { LanguageCode } from '../../../core/types'\n\ninterface OriginListInput {\n farmId: string\n language: LanguageCode\n}\n\nexport class OriginList extends Report {\n constructor(http: HttpClient) {\n super(http, {\n template: '@pig-master/origin-list',\n fileName: 'Listagem de origens',\n })\n }\n\n async pdf(input: OriginListInput) {\n return await this.request({\n contentType: 'application/pdf',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: false },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n\n async csv(input: OriginListInput) {\n return await this.request({\n contentType: 'text/csv',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: true },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n}\n","import type { HttpClient } from '../../core/http-client'\nimport { OriginList } from './reports/origin-list'\n\nexport class PigMasterNamespace {\n public readonly originList: OriginList\n\n constructor(http: HttpClient) {\n this.originList = new OriginList(http)\n }\n}\n","import { HttpClient } from './core/http-client'\nimport { PigMasterNamespace } from './namespaces/pig-master'\n\nexport class JaspionClient {\n public readonly pigMaster: PigMasterNamespace\n\n constructor(private readonly http: HttpClient) {\n this.pigMaster = new PigMasterNamespace(http)\n }\n\n setAccessToken(token: string) {\n this.http.setHeader('Authorization', `Bearer ${token}`)\n }\n}\n\nexport function jaspion(baseUrl: string) {\n const http = new HttpClient(baseUrl)\n\n return new JaspionClient(http)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAA6B,SAAiB;AAAjB;AAJ7B,SAAiB,UAAkC;AAAA,MACjD,gBAAgB;AAAA,IAClB;AAAA,EAE+C;AAAA,EAE/C,UAAU,KAAa,OAAe;AACpC,SAAK,QAAQ,GAAG,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,KAAK,MAAc,MAAe;AACtC,UAAM,WAAW,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,MACrD,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,8BAA8B,SAAS,MAAM,EAAE;AAAA,IACjE;AAAA,EACF;AACF;;;ACGO,IAAe,S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YAAY,MAAkB;AAC5B,SAAK,aAAa,IAAI,WAAW,IAAI;AAAA,EACvC;AACF;;;ACNO,IAAM,gBAAN,MAAoB;AAAA,EAGzB,YAA6B,MAAkB;AAAlB;AAC3B,SAAK,YAAY,IAAI,mBAAmB,IAAI;AAAA,EAC9C;AAAA,EAEA,eAAe,OAAe;AAC5B,SAAK,KAAK,UAAU,iBAAiB,UAAU,KAAK,EAAE;AAAA,EACxD;AACF;AAEO,SAAS,QAAQ,SAAiB;AACvC,QAAM,OAAO,IAAI,WAAW,OAAO;AAEnC,SAAO,IAAI,cAAc,IAAI;AAC/B;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,5 +1,25 @@
1
- // src/client.ts
2
- import axios from "axios";
1
+ // src/core/http-client.ts
2
+ var HttpClient = class {
3
+ constructor(baseUrl) {
4
+ this.baseUrl = baseUrl;
5
+ this.headers = {
6
+ "Content-Type": "application/json"
7
+ };
8
+ }
9
+ setHeader(key, value) {
10
+ this.headers[key] = value;
11
+ }
12
+ async post(path, body) {
13
+ const response = await fetch(`${this.baseUrl}${path}`, {
14
+ method: "POST",
15
+ headers: this.headers,
16
+ body: JSON.stringify(body)
17
+ });
18
+ if (!response.ok) {
19
+ throw new Error(`Request failed with status ${response.status}`);
20
+ }
21
+ }
22
+ };
3
23
 
4
24
  // src/core/report.ts
5
25
  var Report = class {
@@ -48,7 +68,7 @@ var OriginList = class extends Report {
48
68
  contentType: "text/csv",
49
69
  resources: [{ key: "FARM_ID", value: input.farmId }],
50
70
  parameters: [
51
- { key: "DATA_ONLY", value: false },
71
+ { key: "DATA_ONLY", value: true },
52
72
  { key: "LOCATE", value: input.language.replace("-", "_") }
53
73
  ]
54
74
  });
@@ -69,11 +89,11 @@ var JaspionClient = class {
69
89
  this.pigMaster = new PigMasterNamespace(http);
70
90
  }
71
91
  setAccessToken(token) {
72
- this.http.defaults.headers.common.Authorization = `Bearer ${token}`;
92
+ this.http.setHeader("Authorization", `Bearer ${token}`);
73
93
  }
74
94
  };
75
- function jaspion(baseURL) {
76
- const http = axios.create({ baseURL });
95
+ function jaspion(baseUrl) {
96
+ const http = new HttpClient(baseUrl);
77
97
  return new JaspionClient(http);
78
98
  }
79
99
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/core/report.ts","../src/namespaces/pig-master/reports/origin-list.ts","../src/namespaces/pig-master/index.ts"],"sourcesContent":["import axios, { type AxiosInstance } from 'axios'\nimport { PigMasterNamespace } from './namespaces/pig-master'\n\nexport class JaspionClient {\n public readonly pigMaster: PigMasterNamespace\n\n constructor(private readonly http: AxiosInstance) {\n this.pigMaster = new PigMasterNamespace(http)\n }\n\n setAccessToken(token: string) {\n this.http.defaults.headers.common.Authorization = `Bearer ${token}`\n }\n}\n\nexport function jaspion(baseURL: string) {\n const http = axios.create({ baseURL })\n\n return new JaspionClient(http)\n}\n","import type { AxiosInstance } from 'axios'\n\ntype ContentType = 'application/pdf' | 'text/csv'\n\nexport interface Parameter {\n key: string\n value: string | number | boolean | null\n}\n\nexport interface Resource {\n key: string\n value: string\n}\n\ninterface ReportConfig {\n template: string\n fileName: string\n}\n\ninterface RequestReportInput {\n contentType: ContentType\n parameters: Parameter[]\n resources: Resource[]\n}\n\nexport abstract class Report {\n constructor(\n protected readonly http: AxiosInstance,\n protected readonly config: ReportConfig,\n ) {}\n\n protected async request({\n contentType,\n parameters,\n resources,\n }: RequestReportInput) {\n const extension = contentType === 'application/pdf' ? '.pdf' : '.csv'\n const fileName = `${this.config.fileName}${extension}`\n\n await this.http.post('/reports', {\n template: this.config.template,\n fileName: fileName,\n parameters,\n resources,\n contentType,\n type: 'jasper-reports',\n })\n }\n}\n","import type { AxiosInstance } from 'axios'\nimport { Report } from '../../../core/report'\nimport { LanguageCode } from '../../../core/types'\n\ninterface OriginListInput {\n farmId: string\n language: LanguageCode\n}\n\nexport class OriginList extends Report {\n constructor(http: AxiosInstance) {\n super(http, {\n template: '@pig-master/origin-list',\n fileName: 'Listagem de origens',\n })\n }\n\n async pdf(input: OriginListInput) {\n return await this.request({\n contentType: 'application/pdf',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: false },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n\n async csv(input: OriginListInput) {\n return await this.request({\n contentType: 'text/csv',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: false },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n}\n","import type { AxiosInstance } from 'axios'\nimport { OriginList } from './reports/origin-list'\n\nexport class PigMasterNamespace {\n public readonly originList: OriginList\n\n constructor(http: AxiosInstance) {\n this.originList = new OriginList(http)\n }\n}\n"],"mappings":";AAAA,OAAO,WAAmC;;;ACyBnC,IAAe,SAAf,MAAsB;AAAA,EAC3B,YACqB,MACA,QACnB;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,MAAgB,QAAQ;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAuB;AACrB,UAAM,YAAY,gBAAgB,oBAAoB,SAAS;AAC/D,UAAM,WAAW,GAAG,KAAK,OAAO,QAAQ,GAAG,SAAS;AAEpD,UAAM,KAAK,KAAK,KAAK,YAAY;AAAA,MAC/B,UAAU,KAAK,OAAO;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;;;ACvCO,IAAM,aAAN,cAAyB,OAAO;AAAA,EACrC,YAAY,MAAqB;AAC/B,UAAM,MAAM;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,OAAwB;AAChC,WAAO,MAAM,KAAK,QAAQ;AAAA,MACxB,aAAa;AAAA,MACb,WAAW,CAAC,EAAE,KAAK,WAAW,OAAO,MAAM,OAAO,CAAC;AAAA,MACnD,YAAY;AAAA,QACV,EAAE,KAAK,aAAa,OAAO,MAAM;AAAA,QACjC,EAAE,KAAK,UAAU,OAAO,MAAM,SAAS,QAAQ,KAAK,GAAG,EAAE;AAAA,MAC3D;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,OAAwB;AAChC,WAAO,MAAM,KAAK,QAAQ;AAAA,MACxB,aAAa;AAAA,MACb,WAAW,CAAC,EAAE,KAAK,WAAW,OAAO,MAAM,OAAO,CAAC;AAAA,MACnD,YAAY;AAAA,QACV,EAAE,KAAK,aAAa,OAAO,MAAM;AAAA,QACjC,EAAE,KAAK,UAAU,OAAO,MAAM,SAAS,QAAQ,KAAK,GAAG,EAAE;AAAA,MAC3D;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACnCO,IAAM,qBAAN,MAAyB;AAAA,EAG9B,YAAY,MAAqB;AAC/B,SAAK,aAAa,IAAI,WAAW,IAAI;AAAA,EACvC;AACF;;;AHNO,IAAM,gBAAN,MAAoB;AAAA,EAGzB,YAA6B,MAAqB;AAArB;AAC3B,SAAK,YAAY,IAAI,mBAAmB,IAAI;AAAA,EAC9C;AAAA,EAEA,eAAe,OAAe;AAC5B,SAAK,KAAK,SAAS,QAAQ,OAAO,gBAAgB,UAAU,KAAK;AAAA,EACnE;AACF;AAEO,SAAS,QAAQ,SAAiB;AACvC,QAAM,OAAO,MAAM,OAAO,EAAE,QAAQ,CAAC;AAErC,SAAO,IAAI,cAAc,IAAI;AAC/B;","names":[]}
1
+ {"version":3,"sources":["../src/core/http-client.ts","../src/core/report.ts","../src/namespaces/pig-master/reports/origin-list.ts","../src/namespaces/pig-master/index.ts","../src/client.ts"],"sourcesContent":["export class HttpClient {\n private readonly headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n constructor(private readonly baseUrl: string) {}\n\n setHeader(key: string, value: string) {\n this.headers[key] = value\n }\n\n async post(path: string, body: unknown) {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(body),\n })\n\n if (!response.ok) {\n throw new Error(`Request failed with status ${response.status}`)\n }\n }\n}\n","import type { HttpClient } from './http-client'\n\ntype ContentType = 'application/pdf' | 'text/csv'\n\nexport interface Parameter {\n key: string\n value: string | number | boolean | null\n}\n\nexport interface Resource {\n key: string\n value: string\n}\n\ninterface ReportConfig {\n template: string\n fileName: string\n}\n\ninterface RequestReportInput {\n contentType: ContentType\n parameters: Parameter[]\n resources: Resource[]\n}\n\nexport abstract class Report {\n constructor(\n protected readonly http: HttpClient,\n protected readonly config: ReportConfig,\n ) {}\n\n protected async request({\n contentType,\n parameters,\n resources,\n }: RequestReportInput) {\n const extension = contentType === 'application/pdf' ? '.pdf' : '.csv'\n const fileName = `${this.config.fileName}${extension}`\n\n await this.http.post('/reports', {\n template: this.config.template,\n fileName,\n parameters,\n resources,\n contentType,\n type: 'jasper-reports',\n })\n }\n}\n","import type { HttpClient } from '../../../core/http-client'\nimport { Report } from '../../../core/report'\nimport { LanguageCode } from '../../../core/types'\n\ninterface OriginListInput {\n farmId: string\n language: LanguageCode\n}\n\nexport class OriginList extends Report {\n constructor(http: HttpClient) {\n super(http, {\n template: '@pig-master/origin-list',\n fileName: 'Listagem de origens',\n })\n }\n\n async pdf(input: OriginListInput) {\n return await this.request({\n contentType: 'application/pdf',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: false },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n\n async csv(input: OriginListInput) {\n return await this.request({\n contentType: 'text/csv',\n resources: [{ key: 'FARM_ID', value: input.farmId }],\n parameters: [\n { key: 'DATA_ONLY', value: true },\n { key: 'LOCATE', value: input.language.replace('-', '_') },\n ],\n })\n }\n}\n","import type { HttpClient } from '../../core/http-client'\nimport { OriginList } from './reports/origin-list'\n\nexport class PigMasterNamespace {\n public readonly originList: OriginList\n\n constructor(http: HttpClient) {\n this.originList = new OriginList(http)\n }\n}\n","import { HttpClient } from './core/http-client'\nimport { PigMasterNamespace } from './namespaces/pig-master'\n\nexport class JaspionClient {\n public readonly pigMaster: PigMasterNamespace\n\n constructor(private readonly http: HttpClient) {\n this.pigMaster = new PigMasterNamespace(http)\n }\n\n setAccessToken(token: string) {\n this.http.setHeader('Authorization', `Bearer ${token}`)\n }\n}\n\nexport function jaspion(baseUrl: string) {\n const http = new HttpClient(baseUrl)\n\n return new JaspionClient(http)\n}\n"],"mappings":";AAAO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAA6B,SAAiB;AAAjB;AAJ7B,SAAiB,UAAkC;AAAA,MACjD,gBAAgB;AAAA,IAClB;AAAA,EAE+C;AAAA,EAE/C,UAAU,KAAa,OAAe;AACpC,SAAK,QAAQ,GAAG,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,KAAK,MAAc,MAAe;AACtC,UAAM,WAAW,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,MACrD,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,8BAA8B,SAAS,MAAM,EAAE;AAAA,IACjE;AAAA,EACF;AACF;;;ACGO,IAAe,SAAf,MAAsB;AAAA,EAC3B,YACqB,MACA,QACnB;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,MAAgB,QAAQ;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAuB;AACrB,UAAM,YAAY,gBAAgB,oBAAoB,SAAS;AAC/D,UAAM,WAAW,GAAG,KAAK,OAAO,QAAQ,GAAG,SAAS;AAEpD,UAAM,KAAK,KAAK,KAAK,YAAY;AAAA,MAC/B,UAAU,KAAK,OAAO;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;;;ACvCO,IAAM,aAAN,cAAyB,OAAO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@gesagro/jaspion-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "SDK for Jaspion",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -26,9 +26,6 @@
26
26
  "typecheck": "tsc --noEmit",
27
27
  "prepublishOnly": "npm run build"
28
28
  },
29
- "dependencies": {
30
- "axios": "^1.15.2"
31
- },
32
29
  "devDependencies": {
33
30
  "@biomejs/biome": "^2.4.13",
34
31
  "@types/node": "^25.6.0",