Skip to content

Commit 0225c21

Browse files
authored
Merge pull request #1 from anyparser/release/1.0.1
Release @anyparser/core@1.0.1
2 parents 6772d2a + 8860218 commit 0225c21

8 files changed

Lines changed: 40 additions & 16 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"ts"
3737
],
3838
"homepage": "https://github.com/anyparser/anyparserjs",
39-
"version": "1.0.0",
39+
"version": "1.0.1",
4040
"main": "dist/index.js",
4141
"exports": {
4242
".": {
@@ -80,7 +80,7 @@
8080
"test": "vitest run",
8181
"coverage": "vitest run --coverage",
8282
"check:state": "git diff --quiet && git diff --cached --quiet || { echo 'Git working directory is not clean. Please commit or stash changes before publishing.'; exit 1; }",
83-
"check:branch": "if [ $(git symbolic-ref --short HEAD) != 'master' ]; then echo 'You must be on the master branch to publish.'; exit 1; fi",
83+
"check:branch": "if [[ $(git symbolic-ref --short HEAD) != 'master' && ! $(git symbolic-ref --short HEAD) =~ ^release/ ]]; then echo 'You must be on the master branch or a release branch (release/...).'; exit 1; fi",
8484
"prepublishOnly": "npm run check:state && npm run check:branch && npm run build"
8585
},
8686
"engines": {

src/anyparser.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type { OcrPresetType, OcrLanguageType } from './config/hardcoded'
1+
import type { OcrPresetType, OcrLanguageType } from './config/hardcoded.ts'
22
export type AnyparserFormatType = 'json' | 'markdown' | 'html'
33
export type AnyparserModelType = 'text' | 'ocr' | 'vlm' | 'lam' | 'crawler'
44
export type AnyparserEncodingType = 'utf-8' | 'latin1'
@@ -117,3 +117,4 @@ export interface AnyparserCrawlResult {
117117

118118
export type AnyparserResult = AnyparserCrawlResult | AnyparserPdfResult | AnyparserResultBase
119119
export type Result = AnyparserResult[] | string
120+
export type { OcrPresetType, OcrLanguageType }

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* Anyparser main entry point
33
* @module anyparser
44
*/
5+
import { ANYPARSER_VERSION, version } from './version.ts'
6+
import { OCR_LANGUAGES, OCR_PRESETS } from './config/hardcoded.ts'
7+
import { Anyparser } from './parser.ts'
8+
import type { OcrLanguageType, OcrPresetType, AnyparserOption, AnyparserImageReference, AnyparserResultBase, AnyparserCrawlDirectiveBase, AnyparserCrawlDirective, AnyparserUrl, AnyparserRobotsTxtDirective, AnyparserPdfPage, AnyparserPdfResult, AnyparserCrawlResult, AnyparserResult, Result } from './anyparser.d.ts'
59

6-
export * from './parser.ts'
7-
8-
export { OCR_LANGUAGES, OCR_PRESETS } from './config/hardcoded.ts'
9-
10-
export type { OcrLanguageType, OcrPresetType, AnyparserOption, AnyparserImageReference, AnyparserResultBase, AnyparserCrawlDirectiveBase, AnyparserCrawlDirective, AnyparserUrl, AnyparserRobotsTxtDirective, AnyparserPdfPage, AnyparserPdfResult, AnyparserCrawlResult, AnyparserResult, Result } from './anyparser.d.ts'
10+
export { version, ANYPARSER_VERSION, OCR_LANGUAGES, OCR_PRESETS, Anyparser }
11+
export type { OcrLanguageType, OcrPresetType, AnyparserOption, AnyparserImageReference, AnyparserResultBase, AnyparserCrawlDirectiveBase, AnyparserCrawlDirective, AnyparserUrl, AnyparserRobotsTxtDirective, AnyparserPdfPage, AnyparserPdfResult, AnyparserCrawlResult, AnyparserResult, Result }

src/parser.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { wrappedFetch } from '@src/utils/fetcher.ts'
2-
import type { AnyparserOption, Result } from '@anyparser/core'
2+
import { ANYPARSER_VERSION } from '@anyparser/core'
33
import { buildForm } from './form.ts'
44
import { validateAndParse } from './validator/index.ts'
55
import { transformToCamel } from '@src/utils/camel-case.ts'
66

7+
import type { AnyparserOption, Result } from '@anyparser/core'
8+
79
/**
810
* Main class for parsing items using the Anyparser API.
911
*/
@@ -34,7 +36,12 @@ export class Anyparser {
3436
method: 'POST',
3537
body: formData,
3638
headers: {
37-
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {})
39+
...(apiKey ?
40+
{
41+
Authorization: `Bearer ${apiKey}`,
42+
'User-Agent': `@anyparser/core@${ANYPARSER_VERSION}` // eslint-disable-line @typescript-eslint/naming-convention
43+
} :
44+
{})
3845
}
3946
}
4047

src/version.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const ANYPARSER_VERSION = '1.0.1'
2+
export const version = ANYPARSER_VERSION

tests/parser.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Anyparser } from '@src/parser.ts'
33
import * as validator from '@src/validator/index.ts'
44
import * as form from '@src/form.ts'
55
import { wrappedFetch } from '@src/utils/fetcher.ts'
6+
import { ANYPARSER_VERSION } from '@src/version.ts'
67

78
// Mock dependencies
89
vi.mock('@src/validator')
@@ -53,7 +54,10 @@ describe('Anyparser', () => {
5354
{
5455
method: 'POST',
5556
body: mockFormData,
56-
headers: { Authorization: `Bearer ${mockApiKey}` }
57+
headers: {
58+
Authorization: `Bearer ${mockApiKey}`,
59+
'User-Agent': `@anyparser/core@${ANYPARSER_VERSION}` // eslint-disable-line @typescript-eslint/naming-convention
60+
}
5761
}
5862
)
5963

@@ -75,6 +79,7 @@ describe('Anyparser', () => {
7579
model: 'text',
7680
encoding: 'utf-8'
7781
})
82+
7883
mockBuildForm.mockReturnValue(mockFormData)
7984
mockWrappedFetch.mockResolvedValue(mockResponse)
8085

@@ -83,14 +88,19 @@ describe('Anyparser', () => {
8388

8489
expect(mockValidateAndParse).toHaveBeenCalledWith('test.pdf', mockOptions)
8590
expect(mockBuildForm).toHaveBeenCalled()
91+
8692
expect(mockWrappedFetch).toHaveBeenCalledWith(
8793
new URL('/parse/v1', mockApiUrl),
8894
{
8995
method: 'POST',
9096
body: mockFormData,
91-
headers: { Authorization: `Bearer ${mockApiKey}` }
97+
headers: {
98+
Authorization: `Bearer ${mockApiKey}`,
99+
'User-Agent': `@anyparser/core@${ANYPARSER_VERSION}` // eslint-disable-line @typescript-eslint/naming-convention
100+
}
92101
}
93102
)
103+
94104
expect(result).toBe(mockTextResponse)
95105
})
96106

tests/validator/option.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, test, describe } from 'vitest'
22
import { validateOption } from '@src/validator/option.ts'
33
import { OCR_LANGUAGES, OCR_PRESETS } from '@src/config/hardcoded.ts'
4+
import type { AnyparserOption } from '@src/anyparser.js'
45

56
describe('validateOption', () => {
67
test('should validate options with apiUrl', () => {
@@ -21,7 +22,8 @@ describe('validateOption', () => {
2122
const validOption = {
2223
apiUrl: new URL('https://api.example.com'),
2324
ocrLanguage: [Object.values(OCR_LANGUAGES)[0]]
24-
}
25+
} as AnyparserOption
26+
2527
expect(() => validateOption(validOption)).not.toThrow()
2628
})
2729

@@ -54,7 +56,8 @@ describe('validateOption', () => {
5456
apiUrl: new URL('https://api.example.com'),
5557
ocrLanguage: [Object.values(OCR_LANGUAGES)[0]],
5658
ocrPreset: Object.values(OCR_PRESETS)[0]
57-
}
59+
} as AnyparserOption
60+
5861
expect(() => validateOption(validOption)).not.toThrow()
5962
})
6063
})

0 commit comments

Comments
 (0)