@jars-lt/sdk 1.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 ADDED
@@ -0,0 +1,287 @@
1
+ # @jars-lt/sdk
2
+
3
+ Official Node.js SDK for [JARS.LT](https://jars.lt) - Lithuanian Company Registry API
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @jars-lt/sdk
9
+ # or
10
+ yarn add @jars-lt/sdk
11
+ # or
12
+ pnpm add @jars-lt/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { JarsClient } from '@jars-lt/sdk';
19
+
20
+ // Initialize the client
21
+ const client = new JarsClient({
22
+ apiKey: 'your_api_key_here'
23
+ });
24
+
25
+ // Search for companies
26
+ const companies = await client.searchCompanies({
27
+ q: 'UAB Maxima',
28
+ limit: 10
29
+ });
30
+
31
+ console.log(companies.results);
32
+ ```
33
+
34
+ ## API Key
35
+
36
+ Get your API key at [jars.lt](https://jars.lt). Available plans:
37
+ - **Free**: 300 requests/month
38
+ - **Starter**: 5,000 requests/month
39
+ - **Professional**: 50,000 requests/month
40
+ - **Enterprise**: 1,000,000 requests/month
41
+
42
+ ## Usage
43
+
44
+ ### Initialize Client
45
+
46
+ ```typescript
47
+ import { JarsClient } from '@jars-lt/sdk';
48
+
49
+ const client = new JarsClient({
50
+ apiKey: 'your_api_key_here',
51
+ // Optional: custom base URL
52
+ baseURL: 'https://api.jars.lt/api/v1',
53
+ // Optional: request timeout in ms
54
+ timeout: 30000
55
+ });
56
+ ```
57
+
58
+ ### Search Companies
59
+
60
+ Search for Lithuanian companies by name or code:
61
+
62
+ ```typescript
63
+ const results = await client.searchCompanies({
64
+ q: 'Maxima',
65
+ limit: 10,
66
+ offset: 0
67
+ });
68
+
69
+ console.log(`Found ${results.total} companies`);
70
+ results.results.forEach(company => {
71
+ console.log(`${company.name} (${company.code})`);
72
+ });
73
+ ```
74
+
75
+ ### Get Company by Code
76
+
77
+ Retrieve detailed information about a specific company:
78
+
79
+ ```typescript
80
+ const company = await client.getCompany('111111111');
81
+
82
+ console.log(company.name);
83
+ console.log(company.address);
84
+ console.log(company.status);
85
+ console.log(company.registrationDate);
86
+ ```
87
+
88
+ ### Search Addresses
89
+
90
+ Search for streets, settlements, and municipalities. Supports multi-word search:
91
+
92
+ ```typescript
93
+ const results = await client.searchAddresses({
94
+ q: 'kaunas basanavi',
95
+ limit: 5
96
+ });
97
+
98
+ // Streets
99
+ results.streets.forEach(street => {
100
+ console.log(`${street.name} ${street.typeAbbr}`);
101
+ if (street.settlement) {
102
+ console.log(` ${street.settlement.name}`);
103
+ }
104
+ });
105
+
106
+ // Settlements
107
+ results.settlements.forEach(settlement => {
108
+ console.log(`${settlement.name} ${settlement.typeAbbr}`);
109
+ });
110
+
111
+ // Municipalities
112
+ results.municipalities.forEach(municipality => {
113
+ console.log(municipality.name);
114
+ });
115
+ ```
116
+
117
+ ### Get Location by Postal Code
118
+
119
+ Get county, municipality, settlement, and streets for a postal code:
120
+
121
+ ```typescript
122
+ const location = await client.getByPostalCode('54306');
123
+ // or with LT- prefix
124
+ const location = await client.getByPostalCode('LT-54306');
125
+
126
+ console.log('County:', location.county.name);
127
+ console.log('Municipality:', location.municipality.name);
128
+ console.log('Settlement:', location.settlement.name);
129
+
130
+ // All streets with this postal code
131
+ location.streets?.forEach(street => {
132
+ console.log(`${street.name} ${street.typeAbbr}`);
133
+ });
134
+ ```
135
+
136
+ ### Get Usage Statistics
137
+
138
+ Check your current API usage and limits:
139
+
140
+ ```typescript
141
+ const usage = await client.getUsage();
142
+
143
+ console.log('Plan:', usage.plan);
144
+ console.log('Requests used:', usage.requestCount);
145
+ console.log('Requests remaining:', usage.remaining);
146
+ console.log('Monthly limit:', usage.limit);
147
+ console.log('Resets on:', usage.resetDate);
148
+ console.log('Rate limit:', usage.rateLimit, 'requests/minute');
149
+ ```
150
+
151
+ ## Error Handling
152
+
153
+ The SDK throws `JarsAPIError` for API errors:
154
+
155
+ ```typescript
156
+ import { JarsClient, JarsAPIError } from '@jars-lt/sdk';
157
+
158
+ try {
159
+ const company = await client.getCompany('invalid');
160
+ } catch (error) {
161
+ if (error instanceof JarsAPIError) {
162
+ console.error('API Error:', error.message);
163
+ console.error('Status Code:', error.statusCode);
164
+ console.error('Response:', error.response);
165
+ } else {
166
+ console.error('Network Error:', error);
167
+ }
168
+ }
169
+ ```
170
+
171
+ Common error codes:
172
+ - `400` - Invalid parameters
173
+ - `401` - Invalid API key
174
+ - `404` - Resource not found
175
+ - `429` - Rate limit exceeded
176
+ - `500` - Server error
177
+
178
+ ## TypeScript Support
179
+
180
+ The SDK is written in TypeScript and includes full type definitions:
181
+
182
+ ```typescript
183
+ import { JarsClient, Company, SubscriptionPlan } from '@jars-lt/sdk';
184
+
185
+ const client = new JarsClient({ apiKey: 'key' });
186
+
187
+ // Fully typed responses
188
+ const company: Company = await client.getCompany('111111111');
189
+ const usage = await client.getUsage();
190
+ const plan: SubscriptionPlan = usage.plan; // 'FREE' | 'STARTER' | 'PROFESSIONAL' | 'ENTERPRISE'
191
+ ```
192
+
193
+ ## Advanced Usage
194
+
195
+ ### Custom Axios Configuration
196
+
197
+ The SDK uses axios internally. You can access the underlying axios instance if needed:
198
+
199
+ ```typescript
200
+ import { JarsClient } from '@jars-lt/sdk';
201
+
202
+ const client = new JarsClient({
203
+ apiKey: 'key',
204
+ timeout: 60000, // 60 seconds
205
+ baseURL: 'https://custom-api.example.com/api/v1'
206
+ });
207
+ ```
208
+
209
+ ### Pagination
210
+
211
+ Handle large result sets with pagination:
212
+
213
+ ```typescript
214
+ async function getAllCompanies(query: string) {
215
+ const pageSize = 100; // Max allowed
216
+ let offset = 0;
217
+ let allCompanies = [];
218
+
219
+ while (true) {
220
+ const results = await client.searchCompanies({
221
+ q: query,
222
+ limit: pageSize,
223
+ offset
224
+ });
225
+
226
+ allCompanies.push(...results.results);
227
+
228
+ if (results.results.length < pageSize) {
229
+ break; // Last page
230
+ }
231
+
232
+ offset += pageSize;
233
+ }
234
+
235
+ return allCompanies;
236
+ }
237
+ ```
238
+
239
+ ## Examples
240
+
241
+ ### Find Company and Its Address
242
+
243
+ ```typescript
244
+ const companies = await client.searchCompanies({ q: 'Maxima' });
245
+ if (companies.results.length > 0) {
246
+ const company = await client.getCompany(companies.results[0].code);
247
+ console.log(`${company.name} is located at ${company.address}`);
248
+ }
249
+ ```
250
+
251
+ ### Search Streets in Kaunas
252
+
253
+ ```typescript
254
+ const results = await client.searchAddresses({ q: 'kaunas' });
255
+ console.log(`Found ${results.streets.length} streets in Kaunas`);
256
+ ```
257
+
258
+ ### Check if API Key is Valid
259
+
260
+ ```typescript
261
+ try {
262
+ const usage = await client.getUsage();
263
+ console.log('API key is valid. Plan:', usage.plan);
264
+ } catch (error) {
265
+ console.error('Invalid API key');
266
+ }
267
+ ```
268
+
269
+ ## Rate Limits
270
+
271
+ Respect rate limits based on your plan:
272
+ - **Free**: 30 requests/minute
273
+ - **Starter**: 60 requests/minute
274
+ - **Professional**: 300 requests/minute
275
+ - **Enterprise**: 1000 requests/minute
276
+
277
+ The API returns `429 Too Many Requests` when rate limit is exceeded.
278
+
279
+ ## Support
280
+
281
+ - Documentation: [jars.lt/docs](https://jars.lt/docs)
282
+ - Issues: [GitHub Issues](https://github.com/your-org/jars-lt-sdk/issues)
283
+ - Contact: [jars.lt/contact](https://jars.lt/contact)
284
+
285
+ ## License
286
+
287
+ MIT Ā© UAB Sistemium
@@ -0,0 +1,219 @@
1
+ import { Company, SubscriptionPlan } from '@jars-lt/types';
2
+ /**
3
+ * Configuration options for JARS.LT client
4
+ */
5
+ export interface JarsClientConfig {
6
+ /** API key for authentication */
7
+ apiKey: string;
8
+ /** Base URL for API (default: https://api.jars.lt/api/v1) */
9
+ baseURL?: string;
10
+ /** Request timeout in milliseconds (default: 30000) */
11
+ timeout?: number;
12
+ }
13
+ /**
14
+ * Search results response
15
+ */
16
+ export interface SearchCompaniesResponse {
17
+ results: Company[];
18
+ total: number;
19
+ limit: number;
20
+ offset: number;
21
+ }
22
+ /**
23
+ * Address search results
24
+ */
25
+ export interface SearchAddressesResponse {
26
+ streets: Array<{
27
+ code: number;
28
+ name: string;
29
+ typeAbbr: string;
30
+ settlementId: string;
31
+ buildings?: Array<{
32
+ number: string;
33
+ postalCode?: string;
34
+ }>;
35
+ settlement?: {
36
+ name: string;
37
+ typeAbbr: string;
38
+ };
39
+ }>;
40
+ settlements: Array<{
41
+ code: number;
42
+ name: string;
43
+ typeAbbr: string;
44
+ municipalityId: string;
45
+ }>;
46
+ municipalities: Array<{
47
+ code: number;
48
+ name: string;
49
+ }>;
50
+ total: number;
51
+ limit: number;
52
+ offset: number;
53
+ }
54
+ /**
55
+ * Postal code lookup response
56
+ */
57
+ export interface PostalCodeResponse {
58
+ postalCode: string;
59
+ streets?: Array<{
60
+ code: number;
61
+ name: string;
62
+ type: string;
63
+ typeAbbr: string;
64
+ }>;
65
+ settlement: {
66
+ code: number;
67
+ name: string;
68
+ type: string;
69
+ typeAbbr: string;
70
+ };
71
+ eldership?: {
72
+ code: number;
73
+ name: string;
74
+ };
75
+ municipality: {
76
+ code: number;
77
+ name: string;
78
+ };
79
+ county: {
80
+ code: number;
81
+ name: string;
82
+ };
83
+ }
84
+ /**
85
+ * Usage statistics response
86
+ */
87
+ export interface UsageResponse {
88
+ plan: SubscriptionPlan;
89
+ requestCount: number;
90
+ limit: number;
91
+ remaining: number;
92
+ resetDate: string;
93
+ dataDelay: number;
94
+ rateLimit: number;
95
+ webhooksEnabled: boolean;
96
+ }
97
+ /**
98
+ * API Error
99
+ */
100
+ export declare class JarsAPIError extends Error {
101
+ statusCode?: number | undefined;
102
+ response?: any | undefined;
103
+ constructor(message: string, statusCode?: number | undefined, response?: any | undefined);
104
+ }
105
+ /**
106
+ * Official JARS.LT API Client
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * import { JarsClient } from '@jars-lt/sdk';
111
+ *
112
+ * const client = new JarsClient({
113
+ * apiKey: 'your_api_key_here'
114
+ * });
115
+ *
116
+ * // Search companies
117
+ * const companies = await client.searchCompanies({ q: 'UAB Maxima' });
118
+ *
119
+ * // Get company by code
120
+ * const company = await client.getCompany('111111111');
121
+ * ```
122
+ */
123
+ export declare class JarsClient {
124
+ private client;
125
+ constructor(config: JarsClientConfig);
126
+ /**
127
+ * Search for companies by name, code, or other criteria
128
+ *
129
+ * @param params - Search parameters
130
+ * @param params.q - Search query (company name or code)
131
+ * @param params.limit - Number of results (max: 100, default: 20)
132
+ * @param params.offset - Skip results (default: 0)
133
+ * @returns Search results with companies
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const results = await client.searchCompanies({
138
+ * q: 'Maxima',
139
+ * limit: 10
140
+ * });
141
+ * console.log(results.total); // Total matching companies
142
+ * console.log(results.results); // Array of companies
143
+ * ```
144
+ */
145
+ searchCompanies(params: {
146
+ q: string;
147
+ limit?: number;
148
+ offset?: number;
149
+ }): Promise<SearchCompaniesResponse>;
150
+ /**
151
+ * Get company details by company code
152
+ *
153
+ * @param code - Company code (9 digits)
154
+ * @returns Company details
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const company = await client.getCompany('111111111');
159
+ * console.log(company.name); // Company name
160
+ * console.log(company.address); // Company address
161
+ * ```
162
+ */
163
+ getCompany(code: string): Promise<Company>;
164
+ /**
165
+ * Search for addresses (streets, settlements, municipalities)
166
+ * Supports multi-word search (e.g., "kaunas basanavi")
167
+ *
168
+ * @param params - Search parameters
169
+ * @param params.q - Search query (street, settlement, or municipality name)
170
+ * @param params.limit - Number of results (max: 100, default: 20)
171
+ * @param params.offset - Skip results (default: 0)
172
+ * @returns Search results grouped by type
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const results = await client.searchAddresses({
177
+ * q: 'kaunas basanavi',
178
+ * limit: 5
179
+ * });
180
+ * console.log(results.streets); // Matching streets
181
+ * console.log(results.settlements); // Matching settlements
182
+ * ```
183
+ */
184
+ searchAddresses(params: {
185
+ q: string;
186
+ limit?: number;
187
+ offset?: number;
188
+ }): Promise<SearchAddressesResponse>;
189
+ /**
190
+ * Get location information by postal code
191
+ *
192
+ * @param code - Postal code (5 digits, with or without "LT-" prefix)
193
+ * @returns Location details including county, municipality, settlement, and streets
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const location = await client.getByPostalCode('54306');
198
+ * console.log(location.county.name); // County name
199
+ * console.log(location.streets); // Streets with this postal code
200
+ * ```
201
+ */
202
+ getByPostalCode(code: string): Promise<PostalCodeResponse>;
203
+ /**
204
+ * Get current API usage statistics and limits
205
+ *
206
+ * @returns Usage information including request count and limits
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const usage = await client.getUsage();
211
+ * console.log(usage.plan); // Current subscription plan
212
+ * console.log(usage.remaining); // Remaining requests this month
213
+ * console.log(usage.resetDate); // When the counter resets
214
+ * ```
215
+ */
216
+ getUsage(): Promise<UsageResponse>;
217
+ }
218
+ export * from '@jars-lt/types';
219
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EA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,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAKhE;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;CAIzC;AAGD,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.JarsClient = exports.JarsAPIError = void 0;
21
+ const axios_1 = __importDefault(require("axios"));
22
+ /**
23
+ * API Error
24
+ */
25
+ class JarsAPIError extends Error {
26
+ constructor(message, statusCode, response) {
27
+ super(message);
28
+ this.statusCode = statusCode;
29
+ this.response = response;
30
+ this.name = 'JarsAPIError';
31
+ }
32
+ }
33
+ exports.JarsAPIError = JarsAPIError;
34
+ /**
35
+ * Official JARS.LT API Client
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { JarsClient } from '@jars-lt/sdk';
40
+ *
41
+ * const client = new JarsClient({
42
+ * apiKey: 'your_api_key_here'
43
+ * });
44
+ *
45
+ * // Search companies
46
+ * const companies = await client.searchCompanies({ q: 'UAB Maxima' });
47
+ *
48
+ * // Get company by code
49
+ * const company = await client.getCompany('111111111');
50
+ * ```
51
+ */
52
+ class JarsClient {
53
+ constructor(config) {
54
+ if (!config.apiKey) {
55
+ throw new Error('API key is required');
56
+ }
57
+ this.client = axios_1.default.create({
58
+ baseURL: config.baseURL || 'https://api.jars.lt/api/v1',
59
+ timeout: config.timeout || 30000,
60
+ headers: {
61
+ 'x-api-key': config.apiKey,
62
+ 'Content-Type': 'application/json',
63
+ },
64
+ });
65
+ // Add error interceptor
66
+ this.client.interceptors.response.use((response) => response, (error) => {
67
+ if (error.response) {
68
+ const message = error.response.data?.error || error.response.data?.message || error.message;
69
+ throw new JarsAPIError(message, error.response.status, error.response.data);
70
+ }
71
+ throw new JarsAPIError(error.message);
72
+ });
73
+ }
74
+ /**
75
+ * Search for companies by name, code, or other criteria
76
+ *
77
+ * @param params - Search parameters
78
+ * @param params.q - Search query (company name or code)
79
+ * @param params.limit - Number of results (max: 100, default: 20)
80
+ * @param params.offset - Skip results (default: 0)
81
+ * @returns Search results with companies
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const results = await client.searchCompanies({
86
+ * q: 'Maxima',
87
+ * limit: 10
88
+ * });
89
+ * console.log(results.total); // Total matching companies
90
+ * console.log(results.results); // Array of companies
91
+ * ```
92
+ */
93
+ async searchCompanies(params) {
94
+ const response = await this.client.get('/companies/search', { params });
95
+ return response.data;
96
+ }
97
+ /**
98
+ * Get company details by company code
99
+ *
100
+ * @param code - Company code (9 digits)
101
+ * @returns Company details
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const company = await client.getCompany('111111111');
106
+ * console.log(company.name); // Company name
107
+ * console.log(company.address); // Company address
108
+ * ```
109
+ */
110
+ async getCompany(code) {
111
+ const response = await this.client.get(`/companies/${code}`);
112
+ return response.data;
113
+ }
114
+ /**
115
+ * Search for addresses (streets, settlements, municipalities)
116
+ * Supports multi-word search (e.g., "kaunas basanavi")
117
+ *
118
+ * @param params - Search parameters
119
+ * @param params.q - Search query (street, settlement, or municipality name)
120
+ * @param params.limit - Number of results (max: 100, default: 20)
121
+ * @param params.offset - Skip results (default: 0)
122
+ * @returns Search results grouped by type
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const results = await client.searchAddresses({
127
+ * q: 'kaunas basanavi',
128
+ * limit: 5
129
+ * });
130
+ * console.log(results.streets); // Matching streets
131
+ * console.log(results.settlements); // Matching settlements
132
+ * ```
133
+ */
134
+ async searchAddresses(params) {
135
+ const response = await this.client.get('/addresses/search', { params });
136
+ return response.data;
137
+ }
138
+ /**
139
+ * Get location information by postal code
140
+ *
141
+ * @param code - Postal code (5 digits, with or without "LT-" prefix)
142
+ * @returns Location details including county, municipality, settlement, and streets
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const location = await client.getByPostalCode('54306');
147
+ * console.log(location.county.name); // County name
148
+ * console.log(location.streets); // Streets with this postal code
149
+ * ```
150
+ */
151
+ async getByPostalCode(code) {
152
+ const response = await this.client.get(`/addresses/postal/${code}`);
153
+ return response.data;
154
+ }
155
+ /**
156
+ * Get current API usage statistics and limits
157
+ *
158
+ * @returns Usage information including request count and limits
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const usage = await client.getUsage();
163
+ * console.log(usage.plan); // Current subscription plan
164
+ * console.log(usage.remaining); // Remaining requests this month
165
+ * console.log(usage.resetDate); // When the counter resets
166
+ * ```
167
+ */
168
+ async getUsage() {
169
+ const response = await this.client.get('/usage');
170
+ return response.data;
171
+ }
172
+ }
173
+ exports.JarsClient = JarsClient;
174
+ // Re-export types from @jars-lt/types for convenience
175
+ __exportStar(require("@jars-lt/types"), exports);
176
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kDAAyD;AAiGzD;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YACE,OAAe,EACR,UAAmB,EACnB,QAAc;QAErB,KAAK,CAA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;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACxE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,eAAe,CAAC,MAIrB;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACxE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,eAAe,CAAC,IAAY;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;QACpE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AAhJD,gCAgJC;AAED,sDAAsD;AACtD,iDAA+B"}
package/example.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Example usage of @jars-lt/sdk
3
+ *
4
+ * To run this example:
5
+ * 1. Set your API key: export JARS_API_KEY=your_api_key_here
6
+ * 2. Run: tsx example.ts
7
+ */
8
+
9
+ import { JarsClient, JarsAPIError } from './src/index';
10
+
11
+ async function main() {
12
+ // Initialize client with API key from environment
13
+ const apiKey = process.env.JARS_API_KEY || 'your_api_key_here';
14
+ const client = new JarsClient({ apiKey });
15
+
16
+ console.log('šŸ”‘ JARS.LT SDK Example\n');
17
+
18
+ try {
19
+ // Example 1: Get usage statistics
20
+ console.log('šŸ“Š Getting usage statistics...');
21
+ const usage = await client.getUsage();
22
+ console.log(`Plan: ${usage.plan}`);
23
+ console.log(`Requests used: ${usage.requestCount}/${usage.limit}`);
24
+ console.log(`Remaining: ${usage.remaining}`);
25
+ console.log(`Rate limit: ${usage.rateLimit} requests/minute\n`);
26
+
27
+ // Example 2: Search companies
28
+ console.log('šŸ¢ Searching companies...');
29
+ const companies = await client.searchCompanies({
30
+ q: 'Maxima',
31
+ limit: 3,
32
+ });
33
+ console.log(`Found ${companies.total} companies total`);
34
+ companies.results.forEach((company) => {
35
+ console.log(` - ${company.name} (${company.code})`);
36
+ });
37
+ console.log();
38
+
39
+ // Example 3: Get specific company
40
+ if (companies.results.length > 0) {
41
+ const companyCode = companies.results[0].code;
42
+ console.log(`šŸ“„ Getting details for company ${companyCode}...`);
43
+ const company = await client.getCompany(companyCode);
44
+ console.log(` Name: ${company.name}`);
45
+ console.log(` Address: ${company.address}`);
46
+ console.log(` Status: ${company.status}`);
47
+ console.log();
48
+ }
49
+
50
+ // Example 4: Search addresses
51
+ console.log('šŸ—ŗļø Searching addresses...');
52
+ const addresses = await client.searchAddresses({
53
+ q: 'kaunas basanavi',
54
+ limit: 3,
55
+ });
56
+ console.log(`Found ${addresses.streets.length} streets`);
57
+ addresses.streets.forEach((street) => {
58
+ console.log(` - ${street.name} ${street.typeAbbr}`);
59
+ if (street.settlement) {
60
+ console.log(` ${street.settlement.name}`);
61
+ }
62
+ });
63
+ console.log();
64
+
65
+ // Example 5: Get location by postal code
66
+ console.log('šŸ“® Getting location by postal code...');
67
+ const location = await client.getByPostalCode('54306');
68
+ console.log(`Postal Code: ${location.postalCode}`);
69
+ console.log(`County: ${location.county.name}`);
70
+ console.log(`Municipality: ${location.municipality.name}`);
71
+ console.log(`Settlement: ${location.settlement.name}`);
72
+ if (location.streets && location.streets.length > 0) {
73
+ console.log(`Streets (${location.streets.length} total):`);
74
+ location.streets.slice(0, 3).forEach((street) => {
75
+ console.log(` - ${street.name} ${street.typeAbbr}`);
76
+ });
77
+ if (location.streets.length > 3) {
78
+ console.log(` ... and ${location.streets.length - 3} more`);
79
+ }
80
+ }
81
+ } catch (error) {
82
+ if (error instanceof JarsAPIError) {
83
+ console.error('āŒ API Error:', error.message);
84
+ console.error('Status Code:', error.statusCode);
85
+ if (error.statusCode === 401) {
86
+ console.error('šŸ’” Make sure your API key is valid');
87
+ }
88
+ } else {
89
+ console.error('āŒ Error:', error);
90
+ }
91
+ process.exit(1);
92
+ }
93
+
94
+ console.log('\nāœ… Example completed successfully!');
95
+ }
96
+
97
+ main();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@jars-lt/sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official Node.js SDK for JARS.LT API - Lithuanian Company Registry",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "dev": "tsc --watch",
17
+ "clean": "rm -rf dist",
18
+ "prepublishOnly": "pnpm build"
19
+ },
20
+ "keywords": [
21
+ "jars",
22
+ "lithuania",
23
+ "company-registry",
24
+ "api",
25
+ "sdk",
26
+ "client"
27
+ ],
28
+ "author": "UAB Sistemium",
29
+ "license": "MIT",
30
+ "homepage": "https://jars.lt",
31
+ "dependencies": {
32
+ "@jars-lt/types": "^1.0.0",
33
+ "axios": "^1.6.2"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^20.10.0",
37
+ "typescript": "^5.3.3"
38
+ }
39
+ }