https://github.com/affinda/affinda-typescript
TypeScript client library for the Affinda API
https://github.com/affinda/affinda-typescript
affinda api javascript typescript
Last synced: 9 months ago
JSON representation
TypeScript client library for the Affinda API
- Host: GitHub
- URL: https://github.com/affinda/affinda-typescript
- Owner: affinda
- License: mit
- Created: 2021-08-09T05:19:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T07:54:39.000Z (almost 2 years ago)
- Last Synced: 2025-03-27T12:52:31.854Z (over 1 year ago)
- Topics: affinda, api, javascript, typescript
- Language: TypeScript
- Homepage: https://affinda.com
- Size: 14.9 MB
- Stars: 9
- Watchers: 6
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Typescript Client Library for Affinda Resume Parser API

[](https://choosealicense.com/licenses/mit/)
[](https://open.vscode.dev/affinda/affinda-typescript)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [API reference](#api-reference)
- [Samples](#samples)
- [Troubleshooting](#troubleshooting)
Generated using [autorest](https://github.com/Azure/autorest)
and [autorest.typescript](https://github.com/Azure/autorest.typescript).
[Package (NPM)](https://www.npmjs.com/package/@affinda/affinda)
## Installation
```bash
npm install @affinda/affinda
```
## API Version Compatibility
The Affinda API is currently on `v3`, with breaking changes meant the release of new versions of the client library.
Please see below for which versions are compatible with which API version.
| Affinda API version | `affinda-typescript` versions |
| ------------------- | ----------------------------- |
| v2 | 0.1.0 - 5.x.x |
| v3 | \>= 6.x.x |
## Quickstart
Before using the API, you need to create an account, setup a workspace, and obtain an API key. Follow the steps in our [documentation](https://docs.affinda.com/docs/getting-started-with-affinda).
### Currently supported environments
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
- Latest versions of Safari, Chrome, Edge, and Firefox.
### Install the `affinda` package
Install the Service client library for JavaScript with `npm`:
```bash
npm install @affinda/affinda
```
or build from source:
```shell
git clone git@github.com:affinda/affinda-typescript.git
npm install
npm build
```
Example parsing a resume:
```javascript
import { AffindaAPI, AffindaCredential } from "@affinda/affinda";
import * as fs from "fs";
const credential = new AffindaCredential("YOUR_API_KEY");
const client = new AffindaAPI(credential);
const file = fs.createReadStream("resume.pdf");
client
.createDocument({
file,
workspace: "YOUR_WORKSPACE_IDENTIFIER",
})
.then(doc => {
console.log("Parsed data:", doc.data);
})
.catch(err => console.error("Error:", err));
```
## Typescript interfaces
You can generate typescript interfaces to help with consuming the API response in a type-safe way.
Use the `affinda-generate-interfaces` command to auto-generate typescript interfaces from your document type configuration.
For example, this will generate typescript interfaces for your "Resume Parser" document type:
```bash
# Assuming your Resume Parser document type ID is "rLERIsHk"
npm exec affinda-generate-interfaces -- --document-type-id=rLERIsHk
```
You will be prompted for your API key, unless you already have the `AFFINDA_API_KEY` environment variable set.
The generated typescript interfaces will be in `./affinda-interfaces` by default.
For all the options you can use, run:
```bash
npm exec affinda-generate-interfaces -- --help
```
## API reference
A full API reference generated with [typedoc](https://github.com/TypeStrong/typedoc)
is [available here](./docs/globals.md)
## Troubleshooting
### Logging
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and
responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by
calling `setLogLevel` in the `@azure/logger`:
```javascript
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
```
For more detailed instructions on how to enable logs, you can look at
the [@azure/logger](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger) package docs.