Skip to content

Commit f7c2421

Browse files
feat(api): manual updates
1 parent fe083ed commit f7c2421

File tree

6 files changed

+36
-69
lines changed

6 files changed

+36
-69
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 5
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-b7fdba3d3f97c7debc22c7ca30b828bce81bcd64648df8c94029b27a3321ebb9.yml
33
openapi_spec_hash: 03f1315f1d32ada42445ca920f047dff
4-
config_hash: 1de8a243a3962065e289ca915dfc6127
4+
config_hash: d9c1f7b95d5659724df3e026c4fab291

README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import CasParser from 'cas-parser-node';
2424

2525
const client = new CasParser({
2626
apiKey: process.env['CAS_PARSER_API_KEY'], // This is the default and can be omitted
27-
environment: 'local', // defaults to 'production'
2827
});
2928

30-
const unifiedResponse = await client.casParser.camsKfintech();
29+
const unifiedResponse = await client.casParser.smartParse({
30+
password: 'ABCDF',
31+
pdf_url: 'https://your-cas-pdf-url-here.com',
32+
});
3133

3234
console.log(unifiedResponse.demat_accounts);
3335
```
@@ -42,10 +44,13 @@ import CasParser from 'cas-parser-node';
4244

4345
const client = new CasParser({
4446
apiKey: process.env['CAS_PARSER_API_KEY'], // This is the default and can be omitted
45-
environment: 'local', // defaults to 'production'
4647
});
4748

48-
const unifiedResponse: CasParser.UnifiedResponse = await client.casParser.camsKfintech();
49+
const params: CasParser.CasParserSmartParseParams = {
50+
password: 'ABCDF',
51+
pdf_url: 'https://you-cas-pdf-url-here.com',
52+
};
53+
const unifiedResponse: CasParser.UnifiedResponse = await client.casParser.smartParse(params);
4954
```
5055

5156
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -58,15 +63,17 @@ a subclass of `APIError` will be thrown:
5863

5964
<!-- prettier-ignore -->
6065
```ts
61-
const unifiedResponse = await client.casParser.camsKfintech().catch(async (err) => {
62-
if (err instanceof CasParser.APIError) {
63-
console.log(err.status); // 400
64-
console.log(err.name); // BadRequestError
65-
console.log(err.headers); // {server: 'nginx', ...}
66-
} else {
67-
throw err;
68-
}
69-
});
66+
const unifiedResponse = await client.casParser
67+
.smartParse({ password: 'ABCDF', pdf_url: 'https://you-cas-pdf-url-here.com' })
68+
.catch(async (err) => {
69+
if (err instanceof CasParser.APIError) {
70+
console.log(err.status); // 400
71+
console.log(err.name); // BadRequestError
72+
console.log(err.headers); // {server: 'nginx', ...}
73+
} else {
74+
throw err;
75+
}
76+
});
7077
```
7178

7279
Error codes are as follows:
@@ -98,7 +105,7 @@ const client = new CasParser({
98105
});
99106

100107
// Or, configure per-request:
101-
await client.casParser.camsKfintech({
108+
await client.casParser.smartParse({ password: 'ABCDF', pdf_url: 'https://you-cas-pdf-url-here.com' }, {
102109
maxRetries: 5,
103110
});
104111
```
@@ -115,7 +122,7 @@ const client = new CasParser({
115122
});
116123

117124
// Override per-request:
118-
await client.casParser.camsKfintech({
125+
await client.casParser.smartParse({ password: 'ABCDF', pdf_url: 'https://you-cas-pdf-url-here.com' }, {
119126
timeout: 5 * 1000,
120127
});
121128
```
@@ -138,11 +145,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
138145
```ts
139146
const client = new CasParser();
140147

141-
const response = await client.casParser.camsKfintech().asResponse();
148+
const response = await client.casParser
149+
.smartParse({ password: 'ABCDF', pdf_url: 'https://you-cas-pdf-url-here.com' })
150+
.asResponse();
142151
console.log(response.headers.get('X-My-Header'));
143152
console.log(response.statusText); // access the underlying Response object
144153

145-
const { data: unifiedResponse, response: raw } = await client.casParser.camsKfintech().withResponse();
154+
const { data: unifiedResponse, response: raw } = await client.casParser
155+
.smartParse({ password: 'ABCDF', pdf_url: 'https://you-cas-pdf-url-here.com' })
156+
.withResponse();
146157
console.log(raw.headers.get('X-My-Header'));
147158
console.log(unifiedResponse.demat_accounts);
148159
```
@@ -224,7 +235,7 @@ parameter. This library doesn't validate at runtime that the request matches the
224235
send will be sent as-is.
225236

226237
```ts
227-
client.casParser.camsKfintech({
238+
client.casParser.smartParse({
228239
// ...
229240
// @ts-expect-error baz is not yet public
230241
baz: 'undocumented option',

packages/mcp-server/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ You can run the MCP Server directly via `npx`:
1010

1111
```sh
1212
export CAS_PARSER_API_KEY="My API Key"
13-
export CAS_PARSER_ENVIRONMENT="production"
1413
npx -y cas-parser-node-mcp@latest
1514
```
1615

@@ -28,8 +27,7 @@ For clients with a configuration JSON, it might look something like this:
2827
"command": "npx",
2928
"args": ["-y", "cas-parser-node-mcp", "--client=claude", "--tools=all"],
3029
"env": {
31-
"CAS_PARSER_API_KEY": "My API Key",
32-
"CAS_PARSER_ENVIRONMENT": "production"
30+
"CAS_PARSER_API_KEY": "My API Key"
3331
}
3432
}
3533
}

packages/mcp-server/src/server.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ export function init(params: {
8080
};
8181

8282
const client =
83-
params.client ||
84-
new CasParser({
85-
environment: (readEnv('CAS_PARSER_ENVIRONMENT') || undefined) as any,
86-
defaultHeaders: { 'X-Stainless-MCP': 'true' },
87-
logger: logger,
88-
});
83+
params.client || new CasParser({ defaultHeaders: { 'X-Stainless-MCP': 'true' }, logger: logger });
8984

9085
server.setRequestHandler(ListToolsRequestSchema, async () => {
9186
return {

src/client.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ import {
4242
} from './internal/utils/log';
4343
import { isEmptyObj } from './internal/utils/values';
4444

45-
const environments = {
46-
production: 'https://portfolio-parser.api.casparser.in',
47-
local: 'http://localhost:5000',
48-
};
49-
type Environment = keyof typeof environments;
50-
5145
export interface ClientOptions {
5246
/**
5347
* Your API key for authentication.
@@ -56,15 +50,6 @@ export interface ClientOptions {
5650
*/
5751
apiKey?: string | undefined;
5852

59-
/**
60-
* Specifies the environment to use for the API.
61-
*
62-
* Each environment maps to a different base URL:
63-
* - `production` corresponds to `https://portfolio-parser.api.casparser.in`
64-
* - `local` corresponds to `http://localhost:5000`
65-
*/
66-
environment?: Environment | undefined;
67-
6853
/**
6954
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
7055
*
@@ -156,7 +141,6 @@ export class CasParser {
156141
* API Client for interfacing with the Cas Parser API.
157142
*
158143
* @param {string | undefined} [opts.apiKey=process.env['CAS_PARSER_API_KEY'] ?? undefined]
159-
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
160144
* @param {string} [opts.baseURL=process.env['CAS_PARSER_BASE_URL'] ?? https://portfolio-parser.api.casparser.in] - Override the default base URL for the API.
161145
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
162146
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
@@ -179,17 +163,10 @@ export class CasParser {
179163
const options: ClientOptions = {
180164
apiKey,
181165
...opts,
182-
baseURL,
183-
environment: opts.environment ?? 'production',
166+
baseURL: baseURL || `https://portfolio-parser.api.casparser.in`,
184167
};
185168

186-
if (baseURL && opts.environment) {
187-
throw new Errors.CasParserError(
188-
'Ambiguous URL; The `baseURL` option (or CAS_PARSER_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
189-
);
190-
}
191-
192-
this.baseURL = options.baseURL || environments[options.environment || 'production'];
169+
this.baseURL = options.baseURL!;
193170
this.timeout = options.timeout ?? CasParser.DEFAULT_TIMEOUT /* 1 minute */;
194171
this.logger = options.logger ?? console;
195172
const defaultLogLevel = 'warn';
@@ -215,8 +192,7 @@ export class CasParser {
215192
withOptions(options: Partial<ClientOptions>): this {
216193
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
217194
...this._options,
218-
environment: options.environment ? options.environment : undefined,
219-
baseURL: options.environment ? undefined : this.baseURL,
195+
baseURL: this.baseURL,
220196
maxRetries: this.maxRetries,
221197
timeout: this.timeout,
222198
logger: this.logger,
@@ -233,7 +209,7 @@ export class CasParser {
233209
* Check whether the base URL is set to its default.
234210
*/
235211
#baseURLOverridden(): boolean {
236-
return this.baseURL !== environments[this._options.environment || 'production'];
212+
return this.baseURL !== 'https://portfolio-parser.api.casparser.in';
237213
}
238214

239215
protected defaultQuery(): Record<string, string | undefined> | undefined {

tests/index.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,6 @@ describe('instantiate client', () => {
315315
expect(client.baseURL).toEqual('https://portfolio-parser.api.casparser.in');
316316
});
317317

318-
test('env variable with environment', () => {
319-
process.env['CAS_PARSER_BASE_URL'] = 'https://example.com/from_env';
320-
321-
expect(
322-
() => new CasParser({ apiKey: 'My API Key', environment: 'production' }),
323-
).toThrowErrorMatchingInlineSnapshot(
324-
`"Ambiguous URL; The \`baseURL\` option (or CAS_PARSER_BASE_URL env var) and the \`environment\` option are given. If you want to use the environment you must pass baseURL: null"`,
325-
);
326-
327-
const client = new CasParser({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
328-
expect(client.baseURL).toEqual('https://portfolio-parser.api.casparser.in');
329-
});
330-
331318
test('in request options', () => {
332319
const client = new CasParser({ apiKey: 'My API Key' });
333320
expect(client.buildURL('/foo', null, 'http://localhost:5000/option')).toEqual(

0 commit comments

Comments
 (0)