Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.1.0"
".": "1.2.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 5
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-b7fdba3d3f97c7debc22c7ca30b828bce81bcd64648df8c94029b27a3321ebb9.yml
openapi_spec_hash: 03f1315f1d32ada42445ca920f047dff
config_hash: 1de8a243a3962065e289ca915dfc6127
config_hash: d9c1f7b95d5659724df3e026c4fab291
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.2.0 (2025-08-18)

Full Changelog: [v1.1.0...v1.2.0](https://github.com/CASParser/cas-parser-node/compare/v1.1.0...v1.2.0)

### Features

* **api:** manual updates ([f7c2421](https://github.com/CASParser/cas-parser-node/commit/f7c24211d125ede213446dea411d633f571c4c41))

## 1.1.0 (2025-08-18)

Full Changelog: [v1.0.0...v1.1.0](https://github.com/CASParser/cas-parser-node/compare/v1.0.0...v1.1.0)
Expand Down
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import CasParser from 'cas-parser-node';

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

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

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

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

const unifiedResponse: CasParser.UnifiedResponse = await client.casParser.camsKfintech();
const params: CasParser.CasParserSmartParseParams = {
password: 'ABCDF',
pdf_url: 'https://you-cas-pdf-url-here.com',
};
const unifiedResponse: CasParser.UnifiedResponse = await client.casParser.smartParse(params);
```

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

<!-- prettier-ignore -->
```ts
const unifiedResponse = await client.casParser.camsKfintech().catch(async (err) => {
if (err instanceof CasParser.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
const unifiedResponse = await client.casParser
.smartParse({ password: 'ABCDF', pdf_url: 'https://you-cas-pdf-url-here.com' })
.catch(async (err) => {
if (err instanceof CasParser.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
```

Error codes are as follows:
Expand Down Expand Up @@ -98,7 +105,7 @@ const client = new CasParser({
});

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

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

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

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

```ts
client.casParser.camsKfintech({
client.casParser.smartParse({
// ...
// @ts-expect-error baz is not yet public
baz: 'undocumented option',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cas-parser-node",
"version": "1.1.0",
"version": "1.2.0",
"description": "The official TypeScript library for the Cas Parser API",
"author": "Cas Parser <sameer@casparser.in>",
"types": "dist/index.d.ts",
Expand Down
4 changes: 1 addition & 3 deletions packages/mcp-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ You can run the MCP Server directly via `npx`:

```sh
export CAS_PARSER_API_KEY="My API Key"
export CAS_PARSER_ENVIRONMENT="production"
npx -y cas-parser-node-mcp@latest
```

Expand All @@ -28,8 +27,7 @@ For clients with a configuration JSON, it might look something like this:
"command": "npx",
"args": ["-y", "cas-parser-node-mcp", "--client=claude", "--tools=all"],
"env": {
"CAS_PARSER_API_KEY": "My API Key",
"CAS_PARSER_ENVIRONMENT": "production"
"CAS_PARSER_API_KEY": "My API Key"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cas-parser-node-mcp",
"version": "1.1.0",
"version": "1.2.0",
"description": "The official MCP Server for the Cas Parser API",
"author": "Cas Parser <sameer@casparser.in>",
"types": "dist/index.d.ts",
Expand Down
9 changes: 2 additions & 7 deletions packages/mcp-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const newMcpServer = () =>
new McpServer(
{
name: 'cas_parser_node_api',
version: '1.1.0',
version: '1.2.0',
},
{ capabilities: { tools: {}, logging: {} } },
);
Expand Down Expand Up @@ -80,12 +80,7 @@ export function init(params: {
};

const client =
params.client ||
new CasParser({
environment: (readEnv('CAS_PARSER_ENVIRONMENT') || undefined) as any,
defaultHeaders: { 'X-Stainless-MCP': 'true' },
logger: logger,
});
params.client || new CasParser({ defaultHeaders: { 'X-Stainless-MCP': 'true' }, logger: logger });

server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
Expand Down
32 changes: 4 additions & 28 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ import {
} from './internal/utils/log';
import { isEmptyObj } from './internal/utils/values';

const environments = {
production: 'https://portfolio-parser.api.casparser.in',
local: 'http://localhost:5000',
};
type Environment = keyof typeof environments;

export interface ClientOptions {
/**
* Your API key for authentication.
Expand All @@ -56,15 +50,6 @@ export interface ClientOptions {
*/
apiKey?: string | undefined;

/**
* Specifies the environment to use for the API.
*
* Each environment maps to a different base URL:
* - `production` corresponds to `https://portfolio-parser.api.casparser.in`
* - `local` corresponds to `http://localhost:5000`
*/
environment?: Environment | undefined;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
*
Expand Down Expand Up @@ -156,7 +141,6 @@ export class CasParser {
* API Client for interfacing with the Cas Parser API.
*
* @param {string | undefined} [opts.apiKey=process.env['CAS_PARSER_API_KEY'] ?? undefined]
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
* @param {string} [opts.baseURL=process.env['CAS_PARSER_BASE_URL'] ?? https://portfolio-parser.api.casparser.in] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
Expand All @@ -179,17 +163,10 @@ export class CasParser {
const options: ClientOptions = {
apiKey,
...opts,
baseURL,
environment: opts.environment ?? 'production',
baseURL: baseURL || `https://portfolio-parser.api.casparser.in`,
};

if (baseURL && opts.environment) {
throw new Errors.CasParserError(
'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',
);
}

this.baseURL = options.baseURL || environments[options.environment || 'production'];
this.baseURL = options.baseURL!;
this.timeout = options.timeout ?? CasParser.DEFAULT_TIMEOUT /* 1 minute */;
this.logger = options.logger ?? console;
const defaultLogLevel = 'warn';
Expand All @@ -215,8 +192,7 @@ export class CasParser {
withOptions(options: Partial<ClientOptions>): this {
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
...this._options,
environment: options.environment ? options.environment : undefined,
baseURL: options.environment ? undefined : this.baseURL,
baseURL: this.baseURL,
maxRetries: this.maxRetries,
timeout: this.timeout,
logger: this.logger,
Expand All @@ -233,7 +209,7 @@ export class CasParser {
* Check whether the base URL is set to its default.
*/
#baseURLOverridden(): boolean {
return this.baseURL !== environments[this._options.environment || 'production'];
return this.baseURL !== 'https://portfolio-parser.api.casparser.in';
}

protected defaultQuery(): Record<string, string | undefined> | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '1.1.0'; // x-release-please-version
export const VERSION = '1.2.0'; // x-release-please-version
13 changes: 0 additions & 13 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,6 @@ describe('instantiate client', () => {
expect(client.baseURL).toEqual('https://portfolio-parser.api.casparser.in');
});

test('env variable with environment', () => {
process.env['CAS_PARSER_BASE_URL'] = 'https://example.com/from_env';

expect(
() => new CasParser({ apiKey: 'My API Key', environment: 'production' }),
).toThrowErrorMatchingInlineSnapshot(
`"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"`,
);

const client = new CasParser({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
expect(client.baseURL).toEqual('https://portfolio-parser.api.casparser.in');
});

test('in request options', () => {
const client = new CasParser({ apiKey: 'My API Key' });
expect(client.buildURL('/foo', null, 'http://localhost:5000/option')).toEqual(
Expand Down