gstaccelerator 0.1.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/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/index.d.mts +173 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +286 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +242 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GST Accelerator
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# GST Accelerator JavaScript Client
|
|
2
|
+
|
|
3
|
+
JavaScript client for the GST Accelerator API — India GST HSN/SAC lookup, GSTIN validation, and condition resolver.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install gstaccelerator
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
### Node.js (CommonJS)
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const { GSTAccelerator } = require('gstaccelerator');
|
|
17
|
+
const gst = new GSTAccelerator({ apiKey: 'your_api_key' });
|
|
18
|
+
|
|
19
|
+
async function run() {
|
|
20
|
+
const result = await gst.hsn.get('84151010');
|
|
21
|
+
console.log(result);
|
|
22
|
+
}
|
|
23
|
+
run();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Browser fetch (ESM)
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
import { GSTAccelerator } from 'gstaccelerator';
|
|
30
|
+
const gst = new GSTAccelerator({ apiKey: 'your_api_key' });
|
|
31
|
+
|
|
32
|
+
// Note: Ensure your API keys are not exposed in client-side code in production.
|
|
33
|
+
gst.hsn.get('84151010').then(console.log);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### MCP Agent Use (Claude/GPT-4o)
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
import { GSTAcceleratorMCPTools } from 'gstaccelerator';
|
|
40
|
+
|
|
41
|
+
console.log(GSTAcceleratorMCPTools);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API Reference
|
|
45
|
+
|
|
46
|
+
| Resource | Method | Description |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `gst.hsn` | `get(code: string)` | HSN lookup |
|
|
49
|
+
| `gst.sac` | `get(code: string)` | SAC lookup |
|
|
50
|
+
| `gst` | `lookup(description: string, options?: LookupOptions)` | Description search |
|
|
51
|
+
| `gst` | `autocomplete(query: string)` | Autocomplete |
|
|
52
|
+
| `gst` | `bulk(descriptions: string[])` | Bulk lookup |
|
|
53
|
+
| `gst.gstin` | `validate(gstin: string)` | GSTIN validation |
|
|
54
|
+
| `gst.gstin` | `state(gstin: string)` | State info |
|
|
55
|
+
| `gst.gstin` | `pan(gstin: string)` | PAN info |
|
|
56
|
+
| `gst` | `health()` | Health check |
|
|
57
|
+
| `gst` | `meta()` | Meta data |
|
|
58
|
+
|
|
59
|
+
## Error Handling
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import { GSTAccelerator, RateLimitError, AuthenticationError } from 'gstaccelerator';
|
|
63
|
+
|
|
64
|
+
const gst = new GSTAccelerator({ apiKey: 'your_api_key' });
|
|
65
|
+
|
|
66
|
+
async function checkRate() {
|
|
67
|
+
try {
|
|
68
|
+
const result = await gst.hsn.get('84151010');
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof AuthenticationError) {
|
|
71
|
+
console.error('Auth failed:', error.message);
|
|
72
|
+
} else if (error instanceof RateLimitError) {
|
|
73
|
+
console.error('Rate limited. Retry after:', error.retryAfter);
|
|
74
|
+
} else {
|
|
75
|
+
console.error('Error:', error.message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For full documentation, visit: https://gstaccelerator.in/docs
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
interface GSTAcceleratorConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
maxRetries?: number;
|
|
6
|
+
}
|
|
7
|
+
interface TaxRates {
|
|
8
|
+
igst: number;
|
|
9
|
+
cgst: number;
|
|
10
|
+
sgst: number;
|
|
11
|
+
cess: number;
|
|
12
|
+
}
|
|
13
|
+
interface ApplicableRate {
|
|
14
|
+
intrastate: string;
|
|
15
|
+
interstate: string;
|
|
16
|
+
}
|
|
17
|
+
interface HSNResult {
|
|
18
|
+
hsn_code: string;
|
|
19
|
+
description: string;
|
|
20
|
+
tax_rates: TaxRates;
|
|
21
|
+
applicable_rate: ApplicableRate;
|
|
22
|
+
notification_ref: string;
|
|
23
|
+
confidence: number;
|
|
24
|
+
needs_review: boolean;
|
|
25
|
+
condition_applied?: string;
|
|
26
|
+
condition_warning?: string;
|
|
27
|
+
last_updated?: string;
|
|
28
|
+
}
|
|
29
|
+
interface GSTINValidationResult {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
gstin: string;
|
|
32
|
+
state_code?: string;
|
|
33
|
+
state_name?: string;
|
|
34
|
+
pan?: string;
|
|
35
|
+
entity_type_code?: string;
|
|
36
|
+
error_reason?: string;
|
|
37
|
+
}
|
|
38
|
+
interface LookupOptions {
|
|
39
|
+
supplyType?: 'B2B' | 'B2C';
|
|
40
|
+
branded?: boolean;
|
|
41
|
+
saleValueInr?: number;
|
|
42
|
+
stateOfSupply?: string;
|
|
43
|
+
}
|
|
44
|
+
interface MetaResponse {
|
|
45
|
+
total_hsn: number;
|
|
46
|
+
total_sac: number;
|
|
47
|
+
last_updated: string;
|
|
48
|
+
source: string;
|
|
49
|
+
db_version: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class HSNClient {
|
|
53
|
+
private client;
|
|
54
|
+
constructor(client: GSTAccelerator);
|
|
55
|
+
get(code: string): Promise<HSNResult>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class SACClient {
|
|
59
|
+
private client;
|
|
60
|
+
constructor(client: GSTAccelerator);
|
|
61
|
+
get(code: string): Promise<any>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class GSTINClient {
|
|
65
|
+
private client;
|
|
66
|
+
constructor(client: GSTAccelerator);
|
|
67
|
+
validate(gstin: string): Promise<GSTINValidationResult>;
|
|
68
|
+
state(gstin: string): Promise<any>;
|
|
69
|
+
pan(gstin: string): Promise<any>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class GSTAccelerator {
|
|
73
|
+
private apiKey;
|
|
74
|
+
private baseUrl;
|
|
75
|
+
private timeout;
|
|
76
|
+
maxRetries: number;
|
|
77
|
+
hsn: HSNClient;
|
|
78
|
+
sac: SACClient;
|
|
79
|
+
gstin: GSTINClient;
|
|
80
|
+
constructor(config: GSTAcceleratorConfig);
|
|
81
|
+
request<T>(method: string, path: string, body?: any): Promise<T>;
|
|
82
|
+
lookup(description: string, options?: LookupOptions): Promise<any[]>;
|
|
83
|
+
autocomplete(query: string): Promise<string[]>;
|
|
84
|
+
bulk(descriptions: string[]): Promise<any[][]>;
|
|
85
|
+
health(): Promise<Record<string, unknown>>;
|
|
86
|
+
meta(): Promise<MetaResponse>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class GSTAcceleratorError extends Error {
|
|
90
|
+
statusCode: number;
|
|
91
|
+
responseBody: Record<string, unknown>;
|
|
92
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
93
|
+
}
|
|
94
|
+
declare class AuthenticationError extends GSTAcceleratorError {
|
|
95
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
96
|
+
}
|
|
97
|
+
declare class RateLimitError extends GSTAcceleratorError {
|
|
98
|
+
retryAfter?: number;
|
|
99
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number);
|
|
100
|
+
}
|
|
101
|
+
declare class NotFoundError extends GSTAcceleratorError {
|
|
102
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
103
|
+
}
|
|
104
|
+
declare class ValidationError extends GSTAcceleratorError {
|
|
105
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
106
|
+
}
|
|
107
|
+
declare class ServerError extends GSTAcceleratorError {
|
|
108
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare const GSTAcceleratorMCPTools: ({
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
input_schema: {
|
|
115
|
+
type: string;
|
|
116
|
+
properties: {
|
|
117
|
+
code: {
|
|
118
|
+
type: string;
|
|
119
|
+
description: string;
|
|
120
|
+
};
|
|
121
|
+
description?: undefined;
|
|
122
|
+
supply_type?: undefined;
|
|
123
|
+
branded?: undefined;
|
|
124
|
+
sale_value_inr?: undefined;
|
|
125
|
+
gstin?: undefined;
|
|
126
|
+
};
|
|
127
|
+
required: string[];
|
|
128
|
+
};
|
|
129
|
+
} | {
|
|
130
|
+
name: string;
|
|
131
|
+
description: string;
|
|
132
|
+
input_schema: {
|
|
133
|
+
type: string;
|
|
134
|
+
properties: {
|
|
135
|
+
description: {
|
|
136
|
+
type: string;
|
|
137
|
+
};
|
|
138
|
+
supply_type: {
|
|
139
|
+
type: string;
|
|
140
|
+
enum: string[];
|
|
141
|
+
};
|
|
142
|
+
branded: {
|
|
143
|
+
type: string;
|
|
144
|
+
};
|
|
145
|
+
sale_value_inr: {
|
|
146
|
+
type: string;
|
|
147
|
+
};
|
|
148
|
+
code?: undefined;
|
|
149
|
+
gstin?: undefined;
|
|
150
|
+
};
|
|
151
|
+
required: string[];
|
|
152
|
+
};
|
|
153
|
+
} | {
|
|
154
|
+
name: string;
|
|
155
|
+
description: string;
|
|
156
|
+
input_schema: {
|
|
157
|
+
type: string;
|
|
158
|
+
properties: {
|
|
159
|
+
gstin: {
|
|
160
|
+
type: string;
|
|
161
|
+
description: string;
|
|
162
|
+
};
|
|
163
|
+
code?: undefined;
|
|
164
|
+
description?: undefined;
|
|
165
|
+
supply_type?: undefined;
|
|
166
|
+
branded?: undefined;
|
|
167
|
+
sale_value_inr?: undefined;
|
|
168
|
+
};
|
|
169
|
+
required: string[];
|
|
170
|
+
};
|
|
171
|
+
})[];
|
|
172
|
+
|
|
173
|
+
export { type ApplicableRate, AuthenticationError, GSTAccelerator, type GSTAcceleratorConfig, GSTAcceleratorError, GSTAcceleratorMCPTools, type GSTINValidationResult, type HSNResult, type LookupOptions, type MetaResponse, NotFoundError, RateLimitError, ServerError, type TaxRates, ValidationError, GSTAccelerator as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
interface GSTAcceleratorConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
maxRetries?: number;
|
|
6
|
+
}
|
|
7
|
+
interface TaxRates {
|
|
8
|
+
igst: number;
|
|
9
|
+
cgst: number;
|
|
10
|
+
sgst: number;
|
|
11
|
+
cess: number;
|
|
12
|
+
}
|
|
13
|
+
interface ApplicableRate {
|
|
14
|
+
intrastate: string;
|
|
15
|
+
interstate: string;
|
|
16
|
+
}
|
|
17
|
+
interface HSNResult {
|
|
18
|
+
hsn_code: string;
|
|
19
|
+
description: string;
|
|
20
|
+
tax_rates: TaxRates;
|
|
21
|
+
applicable_rate: ApplicableRate;
|
|
22
|
+
notification_ref: string;
|
|
23
|
+
confidence: number;
|
|
24
|
+
needs_review: boolean;
|
|
25
|
+
condition_applied?: string;
|
|
26
|
+
condition_warning?: string;
|
|
27
|
+
last_updated?: string;
|
|
28
|
+
}
|
|
29
|
+
interface GSTINValidationResult {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
gstin: string;
|
|
32
|
+
state_code?: string;
|
|
33
|
+
state_name?: string;
|
|
34
|
+
pan?: string;
|
|
35
|
+
entity_type_code?: string;
|
|
36
|
+
error_reason?: string;
|
|
37
|
+
}
|
|
38
|
+
interface LookupOptions {
|
|
39
|
+
supplyType?: 'B2B' | 'B2C';
|
|
40
|
+
branded?: boolean;
|
|
41
|
+
saleValueInr?: number;
|
|
42
|
+
stateOfSupply?: string;
|
|
43
|
+
}
|
|
44
|
+
interface MetaResponse {
|
|
45
|
+
total_hsn: number;
|
|
46
|
+
total_sac: number;
|
|
47
|
+
last_updated: string;
|
|
48
|
+
source: string;
|
|
49
|
+
db_version: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class HSNClient {
|
|
53
|
+
private client;
|
|
54
|
+
constructor(client: GSTAccelerator);
|
|
55
|
+
get(code: string): Promise<HSNResult>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class SACClient {
|
|
59
|
+
private client;
|
|
60
|
+
constructor(client: GSTAccelerator);
|
|
61
|
+
get(code: string): Promise<any>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class GSTINClient {
|
|
65
|
+
private client;
|
|
66
|
+
constructor(client: GSTAccelerator);
|
|
67
|
+
validate(gstin: string): Promise<GSTINValidationResult>;
|
|
68
|
+
state(gstin: string): Promise<any>;
|
|
69
|
+
pan(gstin: string): Promise<any>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class GSTAccelerator {
|
|
73
|
+
private apiKey;
|
|
74
|
+
private baseUrl;
|
|
75
|
+
private timeout;
|
|
76
|
+
maxRetries: number;
|
|
77
|
+
hsn: HSNClient;
|
|
78
|
+
sac: SACClient;
|
|
79
|
+
gstin: GSTINClient;
|
|
80
|
+
constructor(config: GSTAcceleratorConfig);
|
|
81
|
+
request<T>(method: string, path: string, body?: any): Promise<T>;
|
|
82
|
+
lookup(description: string, options?: LookupOptions): Promise<any[]>;
|
|
83
|
+
autocomplete(query: string): Promise<string[]>;
|
|
84
|
+
bulk(descriptions: string[]): Promise<any[][]>;
|
|
85
|
+
health(): Promise<Record<string, unknown>>;
|
|
86
|
+
meta(): Promise<MetaResponse>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class GSTAcceleratorError extends Error {
|
|
90
|
+
statusCode: number;
|
|
91
|
+
responseBody: Record<string, unknown>;
|
|
92
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
93
|
+
}
|
|
94
|
+
declare class AuthenticationError extends GSTAcceleratorError {
|
|
95
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
96
|
+
}
|
|
97
|
+
declare class RateLimitError extends GSTAcceleratorError {
|
|
98
|
+
retryAfter?: number;
|
|
99
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number);
|
|
100
|
+
}
|
|
101
|
+
declare class NotFoundError extends GSTAcceleratorError {
|
|
102
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
103
|
+
}
|
|
104
|
+
declare class ValidationError extends GSTAcceleratorError {
|
|
105
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
106
|
+
}
|
|
107
|
+
declare class ServerError extends GSTAcceleratorError {
|
|
108
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, unknown>);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare const GSTAcceleratorMCPTools: ({
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
input_schema: {
|
|
115
|
+
type: string;
|
|
116
|
+
properties: {
|
|
117
|
+
code: {
|
|
118
|
+
type: string;
|
|
119
|
+
description: string;
|
|
120
|
+
};
|
|
121
|
+
description?: undefined;
|
|
122
|
+
supply_type?: undefined;
|
|
123
|
+
branded?: undefined;
|
|
124
|
+
sale_value_inr?: undefined;
|
|
125
|
+
gstin?: undefined;
|
|
126
|
+
};
|
|
127
|
+
required: string[];
|
|
128
|
+
};
|
|
129
|
+
} | {
|
|
130
|
+
name: string;
|
|
131
|
+
description: string;
|
|
132
|
+
input_schema: {
|
|
133
|
+
type: string;
|
|
134
|
+
properties: {
|
|
135
|
+
description: {
|
|
136
|
+
type: string;
|
|
137
|
+
};
|
|
138
|
+
supply_type: {
|
|
139
|
+
type: string;
|
|
140
|
+
enum: string[];
|
|
141
|
+
};
|
|
142
|
+
branded: {
|
|
143
|
+
type: string;
|
|
144
|
+
};
|
|
145
|
+
sale_value_inr: {
|
|
146
|
+
type: string;
|
|
147
|
+
};
|
|
148
|
+
code?: undefined;
|
|
149
|
+
gstin?: undefined;
|
|
150
|
+
};
|
|
151
|
+
required: string[];
|
|
152
|
+
};
|
|
153
|
+
} | {
|
|
154
|
+
name: string;
|
|
155
|
+
description: string;
|
|
156
|
+
input_schema: {
|
|
157
|
+
type: string;
|
|
158
|
+
properties: {
|
|
159
|
+
gstin: {
|
|
160
|
+
type: string;
|
|
161
|
+
description: string;
|
|
162
|
+
};
|
|
163
|
+
code?: undefined;
|
|
164
|
+
description?: undefined;
|
|
165
|
+
supply_type?: undefined;
|
|
166
|
+
branded?: undefined;
|
|
167
|
+
sale_value_inr?: undefined;
|
|
168
|
+
};
|
|
169
|
+
required: string[];
|
|
170
|
+
};
|
|
171
|
+
})[];
|
|
172
|
+
|
|
173
|
+
export { type ApplicableRate, AuthenticationError, GSTAccelerator, type GSTAcceleratorConfig, GSTAcceleratorError, GSTAcceleratorMCPTools, type GSTINValidationResult, type HSNResult, type LookupOptions, type MetaResponse, NotFoundError, RateLimitError, ServerError, type TaxRates, ValidationError, GSTAccelerator as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AuthenticationError: () => AuthenticationError,
|
|
34
|
+
GSTAccelerator: () => GSTAccelerator,
|
|
35
|
+
GSTAcceleratorError: () => GSTAcceleratorError,
|
|
36
|
+
GSTAcceleratorMCPTools: () => GSTAcceleratorMCPTools,
|
|
37
|
+
NotFoundError: () => NotFoundError,
|
|
38
|
+
RateLimitError: () => RateLimitError,
|
|
39
|
+
ServerError: () => ServerError,
|
|
40
|
+
ValidationError: () => ValidationError,
|
|
41
|
+
default: () => index_default
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
|
|
45
|
+
// src/client.ts
|
|
46
|
+
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
47
|
+
|
|
48
|
+
// src/errors.ts
|
|
49
|
+
var GSTAcceleratorError = class extends Error {
|
|
50
|
+
constructor(message, statusCode, responseBody) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.statusCode = statusCode;
|
|
53
|
+
this.responseBody = responseBody;
|
|
54
|
+
this.name = "GSTAcceleratorError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var AuthenticationError = class extends GSTAcceleratorError {
|
|
58
|
+
constructor(message, statusCode, responseBody) {
|
|
59
|
+
super(message, statusCode, responseBody);
|
|
60
|
+
this.name = "AuthenticationError";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var RateLimitError = class extends GSTAcceleratorError {
|
|
64
|
+
constructor(message, statusCode, responseBody, retryAfter) {
|
|
65
|
+
super(message, statusCode, responseBody);
|
|
66
|
+
this.name = "RateLimitError";
|
|
67
|
+
this.retryAfter = retryAfter;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var NotFoundError = class extends GSTAcceleratorError {
|
|
71
|
+
constructor(message, statusCode, responseBody) {
|
|
72
|
+
super(message, statusCode, responseBody);
|
|
73
|
+
this.name = "NotFoundError";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var ValidationError = class extends GSTAcceleratorError {
|
|
77
|
+
constructor(message, statusCode, responseBody) {
|
|
78
|
+
super(message, statusCode, responseBody);
|
|
79
|
+
this.name = "ValidationError";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var ServerError = class extends GSTAcceleratorError {
|
|
83
|
+
constructor(message, statusCode, responseBody) {
|
|
84
|
+
super(message, statusCode, responseBody);
|
|
85
|
+
this.name = "ServerError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/resources/hsn.ts
|
|
90
|
+
var HSNClient = class {
|
|
91
|
+
constructor(client) {
|
|
92
|
+
this.client = client;
|
|
93
|
+
}
|
|
94
|
+
async get(code) {
|
|
95
|
+
return this.client.request("GET", `/api/v1/hsn/${code}`);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/resources/sac.ts
|
|
100
|
+
var SACClient = class {
|
|
101
|
+
constructor(client) {
|
|
102
|
+
this.client = client;
|
|
103
|
+
}
|
|
104
|
+
async get(code) {
|
|
105
|
+
return this.client.request("GET", `/api/v1/sac/${code}`);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/resources/gstin.ts
|
|
110
|
+
var GSTINClient = class {
|
|
111
|
+
constructor(client) {
|
|
112
|
+
this.client = client;
|
|
113
|
+
}
|
|
114
|
+
async validate(gstin) {
|
|
115
|
+
return this.client.request("GET", `/api/v1/gstin/${gstin}/validate`);
|
|
116
|
+
}
|
|
117
|
+
async state(gstin) {
|
|
118
|
+
return this.client.request("GET", `/api/v1/gstin/${gstin}/state`);
|
|
119
|
+
}
|
|
120
|
+
async pan(gstin) {
|
|
121
|
+
return this.client.request("GET", `/api/v1/gstin/${gstin}/pan`);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/client.ts
|
|
126
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
127
|
+
var fetchImpl = typeof fetch !== "undefined" ? fetch : import_cross_fetch.default;
|
|
128
|
+
var GSTAccelerator = class {
|
|
129
|
+
constructor(config) {
|
|
130
|
+
this.apiKey = config.apiKey || "";
|
|
131
|
+
this.baseUrl = config.baseUrl || "https://gstaccelerator.in";
|
|
132
|
+
this.timeout = config.timeout || 3e4;
|
|
133
|
+
this.maxRetries = config.maxRetries ?? 3;
|
|
134
|
+
this.hsn = new HSNClient(this);
|
|
135
|
+
this.sac = new SACClient(this);
|
|
136
|
+
this.gstin = new GSTINClient(this);
|
|
137
|
+
}
|
|
138
|
+
async request(method, path, body) {
|
|
139
|
+
const url = `${this.baseUrl}${path}`;
|
|
140
|
+
const headers = {
|
|
141
|
+
"Content-Type": "application/json",
|
|
142
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
143
|
+
};
|
|
144
|
+
if (!isBrowser) {
|
|
145
|
+
headers["User-Agent"] = `gstaccelerator-js/0.1.0`;
|
|
146
|
+
}
|
|
147
|
+
let attempt = 0;
|
|
148
|
+
while (attempt <= this.maxRetries) {
|
|
149
|
+
try {
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
152
|
+
const response = await fetchImpl(url, {
|
|
153
|
+
method,
|
|
154
|
+
headers,
|
|
155
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
156
|
+
signal: controller.signal
|
|
157
|
+
});
|
|
158
|
+
clearTimeout(timeoutId);
|
|
159
|
+
if (response.ok) {
|
|
160
|
+
const text = await response.text();
|
|
161
|
+
return text ? JSON.parse(text) : {};
|
|
162
|
+
}
|
|
163
|
+
const errText = await response.text();
|
|
164
|
+
const errJson = errText ? JSON.parse(errText) : {};
|
|
165
|
+
if (response.status === 401) {
|
|
166
|
+
throw new AuthenticationError("Authentication failed", 401, errJson);
|
|
167
|
+
} else if (response.status === 404) {
|
|
168
|
+
throw new NotFoundError("Resource not found", 404, errJson);
|
|
169
|
+
} else if (response.status === 400 || response.status === 422) {
|
|
170
|
+
throw new ValidationError("Validation error", response.status, errJson);
|
|
171
|
+
} else if (response.status === 429) {
|
|
172
|
+
if (attempt < this.maxRetries) {
|
|
173
|
+
const retryAfter2 = response.headers.get("Retry-After");
|
|
174
|
+
const delay = retryAfter2 ? parseInt(retryAfter2, 10) * 1e3 : 1e3 * Math.pow(2, attempt);
|
|
175
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
176
|
+
attempt++;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
180
|
+
throw new RateLimitError("Rate limit exceeded", 429, errJson, retryAfter ? parseInt(retryAfter, 10) : void 0);
|
|
181
|
+
} else if (response.status >= 500) {
|
|
182
|
+
if (attempt < this.maxRetries) {
|
|
183
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
184
|
+
attempt++;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
throw new ServerError(`Server error: ${response.status}`, response.status, errJson);
|
|
188
|
+
}
|
|
189
|
+
throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (err.name === "AbortError") {
|
|
192
|
+
if (attempt < this.maxRetries) {
|
|
193
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
194
|
+
attempt++;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
throw new GSTAcceleratorError("Request timeout", 0, {});
|
|
198
|
+
}
|
|
199
|
+
if (err instanceof GSTAcceleratorError) {
|
|
200
|
+
throw err;
|
|
201
|
+
}
|
|
202
|
+
if (attempt < this.maxRetries) {
|
|
203
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
204
|
+
attempt++;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
throw new GSTAcceleratorError(err.message || "Unknown error", 0, {});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
throw new GSTAcceleratorError("Max retries exceeded", 0, {});
|
|
211
|
+
}
|
|
212
|
+
async lookup(description, options) {
|
|
213
|
+
const payload = { description };
|
|
214
|
+
if (options?.supplyType) payload.supply_type = options.supplyType;
|
|
215
|
+
if (options?.branded !== void 0) payload.branded = options.branded;
|
|
216
|
+
if (options?.saleValueInr !== void 0) payload.sale_value_inr = options.saleValueInr;
|
|
217
|
+
if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;
|
|
218
|
+
return this.request("POST", "/api/v1/lookup", payload);
|
|
219
|
+
}
|
|
220
|
+
async autocomplete(query) {
|
|
221
|
+
const params = new URLSearchParams({ q: query });
|
|
222
|
+
return this.request("GET", `/api/v1/autocomplete?${params.toString()}`);
|
|
223
|
+
}
|
|
224
|
+
async bulk(descriptions) {
|
|
225
|
+
return this.request("POST", "/api/v1/bulk", { descriptions });
|
|
226
|
+
}
|
|
227
|
+
async health() {
|
|
228
|
+
return this.request("GET", "/api/v1/health");
|
|
229
|
+
}
|
|
230
|
+
async meta() {
|
|
231
|
+
return this.request("GET", "/api/v1/meta");
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/index.ts
|
|
236
|
+
var index_default = GSTAccelerator;
|
|
237
|
+
var GSTAcceleratorMCPTools = [
|
|
238
|
+
{
|
|
239
|
+
name: "hsn_lookup",
|
|
240
|
+
description: "Look up Indian GST rate for a specific HSN code",
|
|
241
|
+
input_schema: {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
code: { type: "string", description: "8-digit HSN code" }
|
|
245
|
+
},
|
|
246
|
+
required: ["code"]
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "gst_search",
|
|
251
|
+
description: "Search GST HSN codes by product description",
|
|
252
|
+
input_schema: {
|
|
253
|
+
type: "object",
|
|
254
|
+
properties: {
|
|
255
|
+
description: { type: "string" },
|
|
256
|
+
supply_type: { type: "string", enum: ["B2B", "B2C"] },
|
|
257
|
+
branded: { type: "boolean" },
|
|
258
|
+
sale_value_inr: { type: "number" }
|
|
259
|
+
},
|
|
260
|
+
required: ["description"]
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "gstin_validate",
|
|
265
|
+
description: "Validate an Indian GSTIN number and extract components",
|
|
266
|
+
input_schema: {
|
|
267
|
+
type: "object",
|
|
268
|
+
properties: {
|
|
269
|
+
gstin: { type: "string", description: "15-character GSTIN" }
|
|
270
|
+
},
|
|
271
|
+
required: ["gstin"]
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
];
|
|
275
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
276
|
+
0 && (module.exports = {
|
|
277
|
+
AuthenticationError,
|
|
278
|
+
GSTAccelerator,
|
|
279
|
+
GSTAcceleratorError,
|
|
280
|
+
GSTAcceleratorMCPTools,
|
|
281
|
+
NotFoundError,
|
|
282
|
+
RateLimitError,
|
|
283
|
+
ServerError,
|
|
284
|
+
ValidationError
|
|
285
|
+
});
|
|
286
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/errors.ts","../src/resources/hsn.ts","../src/resources/sac.ts","../src/resources/gstin.ts"],"sourcesContent":["import { GSTAccelerator } from './client';\n\nexport { GSTAccelerator };\nexport default GSTAccelerator;\n\nexport * from './types';\nexport * from './errors';\n\nexport const GSTAcceleratorMCPTools = [\n {\n name: \"hsn_lookup\",\n description: \"Look up Indian GST rate for a specific HSN code\",\n input_schema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"8-digit HSN code\" }\n },\n required: [\"code\"]\n }\n },\n {\n name: \"gst_search\",\n description: \"Search GST HSN codes by product description\",\n input_schema: {\n type: \"object\",\n properties: {\n description: { type: \"string\" },\n supply_type: { type: \"string\", enum: [\"B2B\", \"B2C\"] },\n branded: { type: \"boolean\" },\n sale_value_inr: { type: \"number\" }\n },\n required: [\"description\"]\n }\n },\n {\n name: \"gstin_validate\",\n description: \"Validate an Indian GSTIN number and extract components\",\n input_schema: {\n type: \"object\",\n properties: {\n gstin: { type: \"string\", description: \"15-character GSTIN\" }\n },\n required: [\"gstin\"]\n }\n }\n];\n","import crossFetch from 'cross-fetch';\nimport { GSTAcceleratorConfig, LookupOptions, MetaResponse } from './types';\nimport { AuthenticationError, NotFoundError, ValidationError, RateLimitError, ServerError, GSTAcceleratorError } from './errors';\nimport { HSNClient } from './resources/hsn';\nimport { SACClient } from './resources/sac';\nimport { GSTINClient } from './resources/gstin';\n\nconst isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nconst fetchImpl = typeof fetch !== 'undefined' ? fetch : crossFetch;\n\nexport class GSTAccelerator {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n public maxRetries: number;\n \n public hsn: HSNClient;\n public sac: SACClient;\n public gstin: GSTINClient;\n\n constructor(config: GSTAcceleratorConfig) {\n this.apiKey = config.apiKey || '';\n this.baseUrl = config.baseUrl || 'https://gstaccelerator.in';\n this.timeout = config.timeout || 30000;\n this.maxRetries = config.maxRetries ?? 3;\n \n this.hsn = new HSNClient(this);\n this.sac = new SACClient(this);\n this.gstin = new GSTINClient(this);\n }\n\n async request<T>(method: string, path: string, body?: any): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`\n };\n\n if (!isBrowser) {\n headers['User-Agent'] = `gstaccelerator-js/0.1.0`;\n }\n\n let attempt = 0;\n \n while (attempt <= this.maxRetries) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n \n const response = await fetchImpl(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal\n });\n \n clearTimeout(timeoutId);\n\n if (response.ok) {\n const text = await response.text();\n return text ? JSON.parse(text) : {} as T;\n }\n\n const errText = await response.text();\n const errJson = errText ? JSON.parse(errText) : {};\n\n if (response.status === 401) {\n throw new AuthenticationError('Authentication failed', 401, errJson);\n } else if (response.status === 404) {\n throw new NotFoundError('Resource not found', 404, errJson);\n } else if (response.status === 400 || response.status === 422) {\n throw new ValidationError('Validation error', response.status, errJson);\n } else if (response.status === 429) {\n if (attempt < this.maxRetries) {\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : 1000 * Math.pow(2, attempt);\n await new Promise(resolve => setTimeout(resolve, delay));\n attempt++;\n continue;\n }\n const retryAfter = response.headers.get('Retry-After');\n throw new RateLimitError('Rate limit exceeded', 429, errJson, retryAfter ? parseInt(retryAfter, 10) : undefined);\n } else if (response.status >= 500) {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new ServerError(`Server error: ${response.status}`, response.status, errJson);\n }\n\n throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);\n } catch (err: any) {\n if (err.name === 'AbortError') {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError('Request timeout', 0, {});\n }\n \n if (err instanceof GSTAcceleratorError) {\n throw err;\n }\n\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError(err.message || 'Unknown error', 0, {});\n }\n }\n \n throw new GSTAcceleratorError('Max retries exceeded', 0, {});\n }\n\n async lookup(description: string, options?: LookupOptions): Promise<any[]> {\n const payload: any = { description };\n if (options?.supplyType) payload.supply_type = options.supplyType;\n if (options?.branded !== undefined) payload.branded = options.branded;\n if (options?.saleValueInr !== undefined) payload.sale_value_inr = options.saleValueInr;\n if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;\n \n return this.request<any[]>('POST', '/api/v1/lookup', payload);\n }\n\n async autocomplete(query: string): Promise<string[]> {\n const params = new URLSearchParams({ q: query });\n return this.request<string[]>('GET', `/api/v1/autocomplete?${params.toString()}`);\n }\n\n async bulk(descriptions: string[]): Promise<any[][]> {\n return this.request<any[][]>('POST', '/api/v1/bulk', { descriptions });\n }\n\n async health(): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>('GET', '/api/v1/health');\n }\n\n async meta(): Promise<MetaResponse> {\n return this.request<MetaResponse>('GET', '/api/v1/meta');\n }\n}\n","export class GSTAcceleratorError extends Error {\n constructor(\n message: string,\n public statusCode: number,\n public responseBody: Record<string, unknown>\n ) {\n super(message);\n this.name = 'GSTAcceleratorError';\n }\n}\n\nexport class AuthenticationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'AuthenticationError';\n }\n}\n\nexport class RateLimitError extends GSTAcceleratorError {\n public retryAfter?: number;\n \n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number) {\n super(message, statusCode, responseBody);\n this.name = 'RateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\nexport class NotFoundError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'NotFoundError';\n }\n}\n\nexport class ValidationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ValidationError';\n }\n}\n\nexport class ServerError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ServerError';\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { HSNResult } from '../types';\n\nexport class HSNClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<HSNResult> {\n return this.client.request<HSNResult>('GET', `/api/v1/hsn/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\n\nexport class SACClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/sac/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { GSTINValidationResult } from '../types';\n\nexport class GSTINClient {\n constructor(private client: GSTAccelerator) {}\n\n async validate(gstin: string): Promise<GSTINValidationResult> {\n return this.client.request<GSTINValidationResult>('GET', `/api/v1/gstin/${gstin}/validate`);\n }\n\n async state(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/state`);\n }\n\n async pan(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/pan`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAAuB;;;ACAhB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACE,SACO,YACA,cACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OA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C,OAAO,gBAAgB;AAAA,EACtE;AAAA,EAEA,MAAM,OAA8B;AAClC,WAAO,KAAK,QAAsB,OAAO,cAAc;AAAA,EACzD;AACF;;;AD7IA,IAAO,gBAAQ;AAKR,IAAM,yBAAyB;AAAA,EACpC;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,UAAU,aAAa,mBAAmB;AAAA,MAC1D;AAAA,MACA,UAAU,CAAC,MAAM;AAAA,IACnB;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,aAAa,EAAE,MAAM,SAAS;AAAA,QAC9B,aAAa,EAAE,MAAM,UAAU,MAAM,CAAC,OAAO,KAAK,EAAE;AAAA,QACpD,SAAS,EAAE,MAAM,UAAU;AAAA,QAC3B,gBAAgB,EAAE,MAAM,SAAS;AAAA,MACnC;AAAA,MACA,UAAU,CAAC,aAAa;AAAA,IAC1B;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,OAAO,EAAE,MAAM,UAAU,aAAa,qBAAqB;AAAA,MAC7D;AAAA,MACA,UAAU,CAAC,OAAO;AAAA,IACpB;AAAA,EACF;AACF;","names":["crossFetch","retryAfter"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import crossFetch from "cross-fetch";
|
|
3
|
+
|
|
4
|
+
// src/errors.ts
|
|
5
|
+
var GSTAcceleratorError = class extends Error {
|
|
6
|
+
constructor(message, statusCode, responseBody) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.responseBody = responseBody;
|
|
10
|
+
this.name = "GSTAcceleratorError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var AuthenticationError = class extends GSTAcceleratorError {
|
|
14
|
+
constructor(message, statusCode, responseBody) {
|
|
15
|
+
super(message, statusCode, responseBody);
|
|
16
|
+
this.name = "AuthenticationError";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var RateLimitError = class extends GSTAcceleratorError {
|
|
20
|
+
constructor(message, statusCode, responseBody, retryAfter) {
|
|
21
|
+
super(message, statusCode, responseBody);
|
|
22
|
+
this.name = "RateLimitError";
|
|
23
|
+
this.retryAfter = retryAfter;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var NotFoundError = class extends GSTAcceleratorError {
|
|
27
|
+
constructor(message, statusCode, responseBody) {
|
|
28
|
+
super(message, statusCode, responseBody);
|
|
29
|
+
this.name = "NotFoundError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var ValidationError = class extends GSTAcceleratorError {
|
|
33
|
+
constructor(message, statusCode, responseBody) {
|
|
34
|
+
super(message, statusCode, responseBody);
|
|
35
|
+
this.name = "ValidationError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var ServerError = class extends GSTAcceleratorError {
|
|
39
|
+
constructor(message, statusCode, responseBody) {
|
|
40
|
+
super(message, statusCode, responseBody);
|
|
41
|
+
this.name = "ServerError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/resources/hsn.ts
|
|
46
|
+
var HSNClient = class {
|
|
47
|
+
constructor(client) {
|
|
48
|
+
this.client = client;
|
|
49
|
+
}
|
|
50
|
+
async get(code) {
|
|
51
|
+
return this.client.request("GET", `/api/v1/hsn/${code}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/resources/sac.ts
|
|
56
|
+
var SACClient = class {
|
|
57
|
+
constructor(client) {
|
|
58
|
+
this.client = client;
|
|
59
|
+
}
|
|
60
|
+
async get(code) {
|
|
61
|
+
return this.client.request("GET", `/api/v1/sac/${code}`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/resources/gstin.ts
|
|
66
|
+
var GSTINClient = class {
|
|
67
|
+
constructor(client) {
|
|
68
|
+
this.client = client;
|
|
69
|
+
}
|
|
70
|
+
async validate(gstin) {
|
|
71
|
+
return this.client.request("GET", `/api/v1/gstin/${gstin}/validate`);
|
|
72
|
+
}
|
|
73
|
+
async state(gstin) {
|
|
74
|
+
return this.client.request("GET", `/api/v1/gstin/${gstin}/state`);
|
|
75
|
+
}
|
|
76
|
+
async pan(gstin) {
|
|
77
|
+
return this.client.request("GET", `/api/v1/gstin/${gstin}/pan`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/client.ts
|
|
82
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
83
|
+
var fetchImpl = typeof fetch !== "undefined" ? fetch : crossFetch;
|
|
84
|
+
var GSTAccelerator = class {
|
|
85
|
+
constructor(config) {
|
|
86
|
+
this.apiKey = config.apiKey || "";
|
|
87
|
+
this.baseUrl = config.baseUrl || "https://gstaccelerator.in";
|
|
88
|
+
this.timeout = config.timeout || 3e4;
|
|
89
|
+
this.maxRetries = config.maxRetries ?? 3;
|
|
90
|
+
this.hsn = new HSNClient(this);
|
|
91
|
+
this.sac = new SACClient(this);
|
|
92
|
+
this.gstin = new GSTINClient(this);
|
|
93
|
+
}
|
|
94
|
+
async request(method, path, body) {
|
|
95
|
+
const url = `${this.baseUrl}${path}`;
|
|
96
|
+
const headers = {
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
99
|
+
};
|
|
100
|
+
if (!isBrowser) {
|
|
101
|
+
headers["User-Agent"] = `gstaccelerator-js/0.1.0`;
|
|
102
|
+
}
|
|
103
|
+
let attempt = 0;
|
|
104
|
+
while (attempt <= this.maxRetries) {
|
|
105
|
+
try {
|
|
106
|
+
const controller = new AbortController();
|
|
107
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
108
|
+
const response = await fetchImpl(url, {
|
|
109
|
+
method,
|
|
110
|
+
headers,
|
|
111
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
112
|
+
signal: controller.signal
|
|
113
|
+
});
|
|
114
|
+
clearTimeout(timeoutId);
|
|
115
|
+
if (response.ok) {
|
|
116
|
+
const text = await response.text();
|
|
117
|
+
return text ? JSON.parse(text) : {};
|
|
118
|
+
}
|
|
119
|
+
const errText = await response.text();
|
|
120
|
+
const errJson = errText ? JSON.parse(errText) : {};
|
|
121
|
+
if (response.status === 401) {
|
|
122
|
+
throw new AuthenticationError("Authentication failed", 401, errJson);
|
|
123
|
+
} else if (response.status === 404) {
|
|
124
|
+
throw new NotFoundError("Resource not found", 404, errJson);
|
|
125
|
+
} else if (response.status === 400 || response.status === 422) {
|
|
126
|
+
throw new ValidationError("Validation error", response.status, errJson);
|
|
127
|
+
} else if (response.status === 429) {
|
|
128
|
+
if (attempt < this.maxRetries) {
|
|
129
|
+
const retryAfter2 = response.headers.get("Retry-After");
|
|
130
|
+
const delay = retryAfter2 ? parseInt(retryAfter2, 10) * 1e3 : 1e3 * Math.pow(2, attempt);
|
|
131
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
132
|
+
attempt++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
136
|
+
throw new RateLimitError("Rate limit exceeded", 429, errJson, retryAfter ? parseInt(retryAfter, 10) : void 0);
|
|
137
|
+
} else if (response.status >= 500) {
|
|
138
|
+
if (attempt < this.maxRetries) {
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
140
|
+
attempt++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
throw new ServerError(`Server error: ${response.status}`, response.status, errJson);
|
|
144
|
+
}
|
|
145
|
+
throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);
|
|
146
|
+
} catch (err) {
|
|
147
|
+
if (err.name === "AbortError") {
|
|
148
|
+
if (attempt < this.maxRetries) {
|
|
149
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
150
|
+
attempt++;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
throw new GSTAcceleratorError("Request timeout", 0, {});
|
|
154
|
+
}
|
|
155
|
+
if (err instanceof GSTAcceleratorError) {
|
|
156
|
+
throw err;
|
|
157
|
+
}
|
|
158
|
+
if (attempt < this.maxRetries) {
|
|
159
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
160
|
+
attempt++;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
throw new GSTAcceleratorError(err.message || "Unknown error", 0, {});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
throw new GSTAcceleratorError("Max retries exceeded", 0, {});
|
|
167
|
+
}
|
|
168
|
+
async lookup(description, options) {
|
|
169
|
+
const payload = { description };
|
|
170
|
+
if (options?.supplyType) payload.supply_type = options.supplyType;
|
|
171
|
+
if (options?.branded !== void 0) payload.branded = options.branded;
|
|
172
|
+
if (options?.saleValueInr !== void 0) payload.sale_value_inr = options.saleValueInr;
|
|
173
|
+
if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;
|
|
174
|
+
return this.request("POST", "/api/v1/lookup", payload);
|
|
175
|
+
}
|
|
176
|
+
async autocomplete(query) {
|
|
177
|
+
const params = new URLSearchParams({ q: query });
|
|
178
|
+
return this.request("GET", `/api/v1/autocomplete?${params.toString()}`);
|
|
179
|
+
}
|
|
180
|
+
async bulk(descriptions) {
|
|
181
|
+
return this.request("POST", "/api/v1/bulk", { descriptions });
|
|
182
|
+
}
|
|
183
|
+
async health() {
|
|
184
|
+
return this.request("GET", "/api/v1/health");
|
|
185
|
+
}
|
|
186
|
+
async meta() {
|
|
187
|
+
return this.request("GET", "/api/v1/meta");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/index.ts
|
|
192
|
+
var index_default = GSTAccelerator;
|
|
193
|
+
var GSTAcceleratorMCPTools = [
|
|
194
|
+
{
|
|
195
|
+
name: "hsn_lookup",
|
|
196
|
+
description: "Look up Indian GST rate for a specific HSN code",
|
|
197
|
+
input_schema: {
|
|
198
|
+
type: "object",
|
|
199
|
+
properties: {
|
|
200
|
+
code: { type: "string", description: "8-digit HSN code" }
|
|
201
|
+
},
|
|
202
|
+
required: ["code"]
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: "gst_search",
|
|
207
|
+
description: "Search GST HSN codes by product description",
|
|
208
|
+
input_schema: {
|
|
209
|
+
type: "object",
|
|
210
|
+
properties: {
|
|
211
|
+
description: { type: "string" },
|
|
212
|
+
supply_type: { type: "string", enum: ["B2B", "B2C"] },
|
|
213
|
+
branded: { type: "boolean" },
|
|
214
|
+
sale_value_inr: { type: "number" }
|
|
215
|
+
},
|
|
216
|
+
required: ["description"]
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "gstin_validate",
|
|
221
|
+
description: "Validate an Indian GSTIN number and extract components",
|
|
222
|
+
input_schema: {
|
|
223
|
+
type: "object",
|
|
224
|
+
properties: {
|
|
225
|
+
gstin: { type: "string", description: "15-character GSTIN" }
|
|
226
|
+
},
|
|
227
|
+
required: ["gstin"]
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
];
|
|
231
|
+
export {
|
|
232
|
+
AuthenticationError,
|
|
233
|
+
GSTAccelerator,
|
|
234
|
+
GSTAcceleratorError,
|
|
235
|
+
GSTAcceleratorMCPTools,
|
|
236
|
+
NotFoundError,
|
|
237
|
+
RateLimitError,
|
|
238
|
+
ServerError,
|
|
239
|
+
ValidationError,
|
|
240
|
+
index_default as default
|
|
241
|
+
};
|
|
242
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/errors.ts","../src/resources/hsn.ts","../src/resources/sac.ts","../src/resources/gstin.ts","../src/index.ts"],"sourcesContent":["import crossFetch from 'cross-fetch';\nimport { GSTAcceleratorConfig, LookupOptions, MetaResponse } from './types';\nimport { AuthenticationError, NotFoundError, ValidationError, RateLimitError, ServerError, GSTAcceleratorError } from './errors';\nimport { HSNClient } from './resources/hsn';\nimport { SACClient } from './resources/sac';\nimport { GSTINClient } from './resources/gstin';\n\nconst isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nconst fetchImpl = typeof fetch !== 'undefined' ? fetch : crossFetch;\n\nexport class GSTAccelerator {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n public maxRetries: number;\n \n public hsn: HSNClient;\n public sac: SACClient;\n public gstin: GSTINClient;\n\n constructor(config: GSTAcceleratorConfig) {\n this.apiKey = config.apiKey || '';\n this.baseUrl = config.baseUrl || 'https://gstaccelerator.in';\n this.timeout = config.timeout || 30000;\n this.maxRetries = config.maxRetries ?? 3;\n \n this.hsn = new HSNClient(this);\n this.sac = new SACClient(this);\n this.gstin = new GSTINClient(this);\n }\n\n async request<T>(method: string, path: string, body?: any): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`\n };\n\n if (!isBrowser) {\n headers['User-Agent'] = `gstaccelerator-js/0.1.0`;\n }\n\n let attempt = 0;\n \n while (attempt <= this.maxRetries) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n \n const response = await fetchImpl(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal\n });\n \n clearTimeout(timeoutId);\n\n if (response.ok) {\n const text = await response.text();\n return text ? JSON.parse(text) : {} as T;\n }\n\n const errText = await response.text();\n const errJson = errText ? JSON.parse(errText) : {};\n\n if (response.status === 401) {\n throw new AuthenticationError('Authentication failed', 401, errJson);\n } else if (response.status === 404) {\n throw new NotFoundError('Resource not found', 404, errJson);\n } else if (response.status === 400 || response.status === 422) {\n throw new ValidationError('Validation error', response.status, errJson);\n } else if (response.status === 429) {\n if (attempt < this.maxRetries) {\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : 1000 * Math.pow(2, attempt);\n await new Promise(resolve => setTimeout(resolve, delay));\n attempt++;\n continue;\n }\n const retryAfter = response.headers.get('Retry-After');\n throw new RateLimitError('Rate limit exceeded', 429, errJson, retryAfter ? parseInt(retryAfter, 10) : undefined);\n } else if (response.status >= 500) {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new ServerError(`Server error: ${response.status}`, response.status, errJson);\n }\n\n throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);\n } catch (err: any) {\n if (err.name === 'AbortError') {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError('Request timeout', 0, {});\n }\n \n if (err instanceof GSTAcceleratorError) {\n throw err;\n }\n\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError(err.message || 'Unknown error', 0, {});\n }\n }\n \n throw new GSTAcceleratorError('Max retries exceeded', 0, {});\n }\n\n async lookup(description: string, options?: LookupOptions): Promise<any[]> {\n const payload: any = { description };\n if (options?.supplyType) payload.supply_type = options.supplyType;\n if (options?.branded !== undefined) payload.branded = options.branded;\n if (options?.saleValueInr !== undefined) payload.sale_value_inr = options.saleValueInr;\n if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;\n \n return this.request<any[]>('POST', '/api/v1/lookup', payload);\n }\n\n async autocomplete(query: string): Promise<string[]> {\n const params = new URLSearchParams({ q: query });\n return this.request<string[]>('GET', `/api/v1/autocomplete?${params.toString()}`);\n }\n\n async bulk(descriptions: string[]): Promise<any[][]> {\n return this.request<any[][]>('POST', '/api/v1/bulk', { descriptions });\n }\n\n async health(): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>('GET', '/api/v1/health');\n }\n\n async meta(): Promise<MetaResponse> {\n return this.request<MetaResponse>('GET', '/api/v1/meta');\n }\n}\n","export class GSTAcceleratorError extends Error {\n constructor(\n message: string,\n public statusCode: number,\n public responseBody: Record<string, unknown>\n ) {\n super(message);\n this.name = 'GSTAcceleratorError';\n }\n}\n\nexport class AuthenticationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'AuthenticationError';\n }\n}\n\nexport class RateLimitError extends GSTAcceleratorError {\n public retryAfter?: number;\n \n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number) {\n super(message, statusCode, responseBody);\n this.name = 'RateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\nexport class NotFoundError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'NotFoundError';\n }\n}\n\nexport class ValidationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ValidationError';\n }\n}\n\nexport class ServerError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ServerError';\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { HSNResult } from '../types';\n\nexport class HSNClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<HSNResult> {\n return this.client.request<HSNResult>('GET', `/api/v1/hsn/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\n\nexport class SACClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/sac/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { GSTINValidationResult } from '../types';\n\nexport class GSTINClient {\n constructor(private client: GSTAccelerator) {}\n\n async validate(gstin: string): Promise<GSTINValidationResult> {\n return this.client.request<GSTINValidationResult>('GET', `/api/v1/gstin/${gstin}/validate`);\n }\n\n async state(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/state`);\n }\n\n async pan(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/pan`);\n }\n}\n","import { GSTAccelerator } from './client';\n\nexport { GSTAccelerator };\nexport default GSTAccelerator;\n\nexport * from './types';\nexport * from './errors';\n\nexport const GSTAcceleratorMCPTools = [\n {\n name: \"hsn_lookup\",\n description: \"Look up Indian GST rate for a specific HSN code\",\n input_schema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"8-digit HSN code\" }\n },\n required: [\"code\"]\n }\n },\n {\n name: \"gst_search\",\n description: \"Search GST HSN codes by product description\",\n input_schema: {\n type: \"object\",\n properties: {\n description: { type: \"string\" },\n supply_type: { type: \"string\", enum: [\"B2B\", \"B2C\"] },\n branded: { type: \"boolean\" },\n sale_value_inr: { type: \"number\" }\n },\n required: [\"description\"]\n }\n },\n {\n name: \"gstin_validate\",\n description: \"Validate an Indian GSTIN number and extract components\",\n input_schema: {\n type: \"object\",\n properties: {\n gstin: { type: \"string\", description: \"15-character GSTIN\" }\n },\n required: [\"gstin\"]\n }\n }\n];\n"],"mappings":";AAAA,OAAO,gBAAgB;;;ACAhB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACE,SACO,YACA,cACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,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AAClC,WAAO,KAAK,QAAsB,OAAO,cAAc;AAAA,EACzD;AACF;;;AK7IA,IAAO,gBAAQ;AAKR,IAAM,yBAAyB;AAAA,EACpC;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,UAAU,aAAa,mBAAmB;AAAA,MAC1D;AAAA,MACA,UAAU,CAAC,MAAM;AAAA,IACnB;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,aAAa,EAAE,MAAM,SAAS;AAAA,QAC9B,aAAa,EAAE,MAAM,UAAU,MAAM,CAAC,OAAO,KAAK,EAAE;AAAA,QACpD,SAAS,EAAE,MAAM,UAAU;AAAA,QAC3B,gBAAgB,EAAE,MAAM,SAAS;AAAA,MACnC;AAAA,MACA,UAAU,CAAC,aAAa;AAAA,IAC1B;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,OAAO,EAAE,MAAM,UAAU,aAAa,qBAAqB;AAAA,MAC7D;AAAA,MACA,UAAU,CAAC,OAAO;AAAA,IACpB;AAAA,EACF;AACF;","names":["retryAfter"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gstaccelerator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript client for the GST Accelerator API — India GST HSN/SAC lookup, GSTIN validation",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"gst",
|
|
22
|
+
"hsn",
|
|
23
|
+
"sac",
|
|
24
|
+
"india",
|
|
25
|
+
"tax",
|
|
26
|
+
"gstin",
|
|
27
|
+
"gst-api",
|
|
28
|
+
"invoice",
|
|
29
|
+
"compliance",
|
|
30
|
+
"fintech"
|
|
31
|
+
],
|
|
32
|
+
"homepage": "https://gstaccelerator.in",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/thedivine1/gst-hsn-api.git"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsup": "^8.0.0",
|
|
42
|
+
"typescript": "^5.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"cross-fetch": "^4.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|