@nvisy/sdk 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/CHANGELOG.md +49 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE.txt +21 -0
- package/README.md +108 -0
- package/dist/builder-BEUIGfoZ.d.ts +138 -0
- package/dist/builder.d.ts +2 -0
- package/dist/builder.js +424 -0
- package/dist/builder.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +424 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +124 -0
- package/dist/errors.js +201 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +555 -0
- package/dist/index.js.map +1 -0
- package/package.json +92 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to
|
|
7
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
## [0.1.0] - 2025-10-15
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- Initial release of the Nvisy SDK
|
|
24
|
+
- `Client` class for interacting with the Nvisy document redaction API
|
|
25
|
+
- `ClientBuilder` class for fluent configuration building
|
|
26
|
+
- Comprehensive error handling with `ClientError` and other error classes
|
|
27
|
+
- Configuration management with environment variable support
|
|
28
|
+
- TypeScript support with full type definitions
|
|
29
|
+
- Multiple export paths for individual modules
|
|
30
|
+
- Custom header support with validation
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
- Fluent API for client configuration
|
|
35
|
+
- Built-in validation for all configuration options
|
|
36
|
+
- Comprehensive test coverage
|
|
37
|
+
- Modern ES2022+ JavaScript target
|
|
38
|
+
- Tree-shakeable ESM builds
|
|
39
|
+
|
|
40
|
+
### Error Handling
|
|
41
|
+
|
|
42
|
+
- Structured error responses with `name`, `message`, and `context` fields
|
|
43
|
+
- Automatic retry logic for server errors and rate limiting
|
|
44
|
+
- HTTP status code classification (client vs server errors)
|
|
45
|
+
- Network error handling for timeouts, DNS resolution, and connection issues
|
|
46
|
+
- Configuration validation with detailed error messages
|
|
47
|
+
|
|
48
|
+
[Unreleased]: https://github.com/nvisycom/sdk/compare/v0.1.0...HEAD
|
|
49
|
+
[0.1.0]: https://github.com/nvisycom/sdk/releases/tag/v0.1.0
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to the Nvisy SDK.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 20.0.0 or higher
|
|
8
|
+
- TypeScript 5.9.0 or higher
|
|
9
|
+
- npm
|
|
10
|
+
|
|
11
|
+
## Development Setup
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git clone https://github.com/your-username/sdk.git
|
|
15
|
+
cd sdk
|
|
16
|
+
npm install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Development
|
|
20
|
+
|
|
21
|
+
### Scripts
|
|
22
|
+
|
|
23
|
+
- `npm run build` - Build the package for production
|
|
24
|
+
- `npm run dev` - Build in watch mode for development
|
|
25
|
+
- `npm test` - Run test suite
|
|
26
|
+
- `npm run test:coverage` - Run tests with coverage report
|
|
27
|
+
- `npm run test:watch` - Run tests in watch mode
|
|
28
|
+
- `npm run lint` - Check code style and quality
|
|
29
|
+
- `npm run format` - Format code with Biome
|
|
30
|
+
- `npm run check` - Run all linting and formatting checks
|
|
31
|
+
- `npm run typecheck` - Verify TypeScript types
|
|
32
|
+
- `npm run clean` - Remove build artifacts
|
|
33
|
+
|
|
34
|
+
### Quality Checks
|
|
35
|
+
|
|
36
|
+
Before submitting changes:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm run check # Lint, format, and type check
|
|
40
|
+
npm test # Run test suite
|
|
41
|
+
npm run build # Verify build works
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Pull Request Process
|
|
45
|
+
|
|
46
|
+
1. Fork the repository
|
|
47
|
+
2. Create a feature branch
|
|
48
|
+
3. Make your changes
|
|
49
|
+
4. Add tests for new functionality
|
|
50
|
+
5. Run quality checks: `npm run check`
|
|
51
|
+
6. Submit a pull request
|
|
52
|
+
|
|
53
|
+
### Pull Request Checklist
|
|
54
|
+
|
|
55
|
+
- [ ] Tests pass
|
|
56
|
+
- [ ] Code follows project style
|
|
57
|
+
- [ ] TypeScript types are correct
|
|
58
|
+
- [ ] Documentation updated if needed
|
|
59
|
+
- [ ] No breaking changes (or documented)
|
|
60
|
+
|
|
61
|
+
## Code Standards
|
|
62
|
+
|
|
63
|
+
- Follow existing TypeScript patterns
|
|
64
|
+
- Use native JavaScript private fields (`#`)
|
|
65
|
+
- Write tests for new features
|
|
66
|
+
- Include JSDoc for public APIs
|
|
67
|
+
- Follow semantic versioning for changes
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
By contributing, you agree your contributions will be licensed under the MIT
|
|
72
|
+
License.
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nvisy Redaction Software
|
|
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,108 @@
|
|
|
1
|
+
# JavaScript & TypeScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@nvisy/sdk)
|
|
4
|
+
[](https://github.com/nvisycom/sdk/actions/workflows/build.yml)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
Official JavaScript & TypeScript SDK for the Nvisy document redaction platform.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- Modern ES2022+ JavaScript with native private fields
|
|
13
|
+
- Full TypeScript support with strict typing
|
|
14
|
+
- Flexible configuration with constructor or builder pattern
|
|
15
|
+
- Built-in environment variable support
|
|
16
|
+
- Automatic retry logic with smart error handling
|
|
17
|
+
- Individual module exports for optimal bundling
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @nvisy/sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Direct Configuration
|
|
28
|
+
|
|
29
|
+
Create a client by passing configuration options directly to the constructor:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Client } from "@nvisy/sdk";
|
|
33
|
+
|
|
34
|
+
const client = new Client({
|
|
35
|
+
apiKey: "your-api-key", // Required: 10+ chars, alphanumeric with _ and -
|
|
36
|
+
baseUrl: "https://api.nvisy.com", // Optional: API endpoint (default shown)
|
|
37
|
+
timeout: 30000, // Optional: 1000-300000ms (default: 30000)
|
|
38
|
+
maxRetries: 3, // Optional: 0-5 attempts (default: 3)
|
|
39
|
+
headers: { // Optional: custom headers
|
|
40
|
+
"X-Custom-Header": "value",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Builder Pattern
|
|
46
|
+
|
|
47
|
+
Use the fluent builder API for more readable configuration:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Client } from "@nvisy/sdk";
|
|
51
|
+
|
|
52
|
+
const client = Client.builder()
|
|
53
|
+
.withApiKey("your-api-key") // Required: 10+ chars, alphanumeric with _ and -
|
|
54
|
+
.withBaseUrl("https://api.nvisy.com") // Optional: API endpoint (default shown)
|
|
55
|
+
.withTimeout(60000) // Optional: 1000-300000ms (default: 30000)
|
|
56
|
+
.withMaxRetries(5) // Optional: 0-5 attempts (default: 3)
|
|
57
|
+
.withHeader("X-Custom-Header", "value") // Optional: single custom header
|
|
58
|
+
.withHeaders({ "X-Another": "header" }) // Optional: multiple custom headers
|
|
59
|
+
.build();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### From Environment Variables
|
|
63
|
+
|
|
64
|
+
Load configuration from environment variables:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { Client, ClientBuilder } from "@nvisy/sdk";
|
|
68
|
+
|
|
69
|
+
// Using builder pattern from environment (allows additional configuration)
|
|
70
|
+
const client = ClientBuilder.fromEnvironment()
|
|
71
|
+
.withTimeout(60000) // Override or add to env config
|
|
72
|
+
.build();
|
|
73
|
+
|
|
74
|
+
// Or using Client directly
|
|
75
|
+
const client = Client.fromEnvironment();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Set these environment variables:
|
|
79
|
+
|
|
80
|
+
| Variable | Description | Required |
|
|
81
|
+
| ------------------- | -------------------------------- | -------- |
|
|
82
|
+
| `NVISY_API_KEY` | API key for authentication | Yes |
|
|
83
|
+
| `NVISY_BASE_URL` | Custom API endpoint URL | No |
|
|
84
|
+
| `NVISY_TIMEOUT` | Request timeout in milliseconds | No |
|
|
85
|
+
| `NVISY_MAX_RETRIES` | Maximum number of retry attempts | No |
|
|
86
|
+
|
|
87
|
+
## Requirements
|
|
88
|
+
|
|
89
|
+
- Node.js 20.0.0 or higher
|
|
90
|
+
- TypeScript 5.9.0 or higher (for development)
|
|
91
|
+
|
|
92
|
+
## Changelog
|
|
93
|
+
|
|
94
|
+
See [CHANGELOG.md](CHANGELOG.md) for release notes and version history.
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
|
|
98
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT License - see [LICENSE.txt](LICENSE.txt) for details.
|
|
103
|
+
|
|
104
|
+
## Support
|
|
105
|
+
|
|
106
|
+
- Documentation: [docs.nvisy.com](https://docs.nvisy.com)
|
|
107
|
+
- Issues: [GitHub Issues](https://github.com/nvisycom/sdk/issues)
|
|
108
|
+
- Email: [support@nvisy.com](mailto:support@nvisy.com)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import createClient from 'openapi-fetch';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Nvisy client
|
|
5
|
+
*/
|
|
6
|
+
interface ClientConfig {
|
|
7
|
+
/**
|
|
8
|
+
* API key for authentication
|
|
9
|
+
*/
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/**
|
|
12
|
+
* Base URL for the Nvisy API
|
|
13
|
+
* @default "https://api.nvisy.com"
|
|
14
|
+
*/
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Request timeout in milliseconds
|
|
18
|
+
* @default 30000
|
|
19
|
+
*/
|
|
20
|
+
timeout?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of retry attempts for failed requests
|
|
23
|
+
* @default 3
|
|
24
|
+
*/
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Custom headers to include with requests
|
|
28
|
+
*/
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Internal fully-resolved configuration
|
|
33
|
+
*/
|
|
34
|
+
type ResolvedClientConfig = Required<ClientConfig>;
|
|
35
|
+
/**
|
|
36
|
+
* Load configuration from environment variables
|
|
37
|
+
*/
|
|
38
|
+
declare function loadConfigFromEnv(): Partial<ClientConfig>;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve configuration with defaults
|
|
41
|
+
*/
|
|
42
|
+
declare function resolveConfig(userConfig: ClientConfig): ResolvedClientConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Get available environment variable names
|
|
45
|
+
*/
|
|
46
|
+
declare function getEnvironmentVariables(): Record<string, string>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Main client class for interacting with the Nvisy document redaction API
|
|
50
|
+
*/
|
|
51
|
+
declare class Client {
|
|
52
|
+
#private;
|
|
53
|
+
/**
|
|
54
|
+
* Create a new Nvisy client instance
|
|
55
|
+
*/
|
|
56
|
+
constructor(userConfig: ClientConfig);
|
|
57
|
+
/**
|
|
58
|
+
* Create a new ClientBuilder for fluent configuration
|
|
59
|
+
*/
|
|
60
|
+
static builder(): ClientBuilder;
|
|
61
|
+
/**
|
|
62
|
+
* Create a client from environment variables
|
|
63
|
+
*/
|
|
64
|
+
static fromEnvironment(): Client;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current configuration (readonly copy)
|
|
67
|
+
*/
|
|
68
|
+
getConfig(): Readonly<ResolvedClientConfig>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the underlying openapi-fetch client for advanced usage
|
|
71
|
+
*/
|
|
72
|
+
getOpenApiClient(): ReturnType<typeof createClient>;
|
|
73
|
+
/**
|
|
74
|
+
* Create a new client with modified configuration
|
|
75
|
+
*/
|
|
76
|
+
withConfig(configChanges: Partial<ClientConfig>): Client;
|
|
77
|
+
/**
|
|
78
|
+
* Create a new client with additional headers
|
|
79
|
+
*/
|
|
80
|
+
withHeaders(additionalHeaders: Record<string, string>): Client;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new client with a different timeout
|
|
83
|
+
*/
|
|
84
|
+
withTimeout(timeoutMs: number): Client;
|
|
85
|
+
/**
|
|
86
|
+
* Create a new client with different retry settings
|
|
87
|
+
*/
|
|
88
|
+
withMaxRetries(maxRetries: number): Client;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Builder class for constructing client instances with a fluent API
|
|
93
|
+
*/
|
|
94
|
+
declare class ClientBuilder {
|
|
95
|
+
#private;
|
|
96
|
+
/**
|
|
97
|
+
* Create a ClientBuilder instance with an API key
|
|
98
|
+
*/
|
|
99
|
+
static fromApiKey(apiKey: string): ClientBuilder;
|
|
100
|
+
/**
|
|
101
|
+
* Create a ClientBuilder instance from environment variables
|
|
102
|
+
*/
|
|
103
|
+
static fromEnvironment(): ClientBuilder;
|
|
104
|
+
/**
|
|
105
|
+
* Set the API key for authentication
|
|
106
|
+
*/
|
|
107
|
+
withApiKey(apiKey: string): this;
|
|
108
|
+
/**
|
|
109
|
+
* Set the base URL for the API
|
|
110
|
+
*/
|
|
111
|
+
withBaseUrl(baseUrl: string): this;
|
|
112
|
+
/**
|
|
113
|
+
* Set the request timeout in milliseconds
|
|
114
|
+
*/
|
|
115
|
+
withTimeout(timeoutMs: number): this;
|
|
116
|
+
/**
|
|
117
|
+
* Set the maximum number of retry attempts
|
|
118
|
+
*/
|
|
119
|
+
withMaxRetries(maxRetries: number): this;
|
|
120
|
+
/**
|
|
121
|
+
* Add a single custom header (merges with existing headers)
|
|
122
|
+
*/
|
|
123
|
+
withHeader(name: string, value: string): this;
|
|
124
|
+
/**
|
|
125
|
+
* Set custom headers (merges with existing headers)
|
|
126
|
+
*/
|
|
127
|
+
withHeaders(headers: Record<string, string>): this;
|
|
128
|
+
/**
|
|
129
|
+
* Build and return the configured client instance
|
|
130
|
+
*/
|
|
131
|
+
build(): Client;
|
|
132
|
+
/**
|
|
133
|
+
* Get the current configuration (for debugging/testing)
|
|
134
|
+
*/
|
|
135
|
+
getConfig(): Readonly<Partial<ClientConfig>>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { ClientBuilder as C, type ResolvedClientConfig as R, Client as a, type ClientConfig as b, getEnvironmentVariables as g, loadConfigFromEnv as l, resolveConfig as r };
|