@nvisy/sdk 0.2.0 → 0.4.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 +81 -3
- package/README.md +44 -32
- package/dist/auth/index.d.ts +76 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +106 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/client-yLrhST0r.d.ts +819 -0
- package/dist/client-yLrhST0r.d.ts.map +1 -0
- package/dist/config-BRQp8Cat.d.ts +83 -0
- package/dist/config-BRQp8Cat.d.ts.map +1 -0
- package/dist/datatypes/index.d.ts +2 -8
- package/dist/datatypes/index.js +0 -3
- package/dist/error-DmkKaDjI.js +199 -0
- package/dist/error-DmkKaDjI.js.map +1 -0
- package/dist/index-Cmm2g3SG.d.ts +11322 -0
- package/dist/index-Cmm2g3SG.d.ts.map +1 -0
- package/dist/index.d.ts +104 -230
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +282 -1433
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +2 -3
- package/dist/services/index.js +2 -955
- package/dist/services-Dh0FMDzU.js +1040 -0
- package/dist/services-Dh0FMDzU.js.map +1 -0
- package/package.json +19 -13
- package/dist/client-D6GtLRbO.d.ts +0 -823
- package/dist/datatypes/index.js.map +0 -1
- package/dist/services/index.js.map +0 -1
- package/dist/workspace-3RLqaMcj.d.ts +0 -7055
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,82 @@ and this project adheres to
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
-
## [0.
|
|
11
|
+
## [0.4.0] - 2026-07-12
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `contexts` service and datatypes (`Context`, `CreateContext`,
|
|
16
|
+
`UpdateContext`, `ContextEntry`, `ContextsPage`)
|
|
17
|
+
- `connections` service and datatypes (`Connection`, `CreateConnection`,
|
|
18
|
+
`UpdateConnection`, `ConnectionsQuery`, `ConnectionsPage`)
|
|
19
|
+
- `pipelines` service and datatypes (`Pipeline`, `CreatePipeline`,
|
|
20
|
+
`UpdatePipeline`, `PipelineDefinition`, `PipelineStatus`, `PipelineSummary`,
|
|
21
|
+
`PipelineSummariesPage`, and more)
|
|
22
|
+
- `policies` service and datatypes (`Policy`, `CreatePolicy`, `UpdatePolicy`,
|
|
23
|
+
`PolicyRule`, `PolicyAction`, `PoliciesPage`)
|
|
24
|
+
- `Health` datatypes for the health endpoint (`Health`, `HealthStatus`,
|
|
25
|
+
`ComponentHealth`, `CheckHealth`)
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Regenerated the API schema against the redacted-pipeline platform API
|
|
30
|
+
- **BREAKING**: `runs` is now a pipeline-run service: `listRuns(pipelineId)`,
|
|
31
|
+
`createRun(pipelineId)`, `getRun(runId)`, `getDetections(runId)`,
|
|
32
|
+
`redact(runId)` (was integration-run based)
|
|
33
|
+
- **BREAKING**: `status.checkHealth()` now returns `Health` (was
|
|
34
|
+
`MonitorStatus`)
|
|
35
|
+
- **BREAKING**: `NvisyApiError.resource` and `.suggestion` are now
|
|
36
|
+
`string | undefined` (were `string | null`)
|
|
37
|
+
|
|
38
|
+
### Removed
|
|
39
|
+
|
|
40
|
+
- **BREAKING**: `annotations`, `comments`, `documents`, and `integrations`
|
|
41
|
+
services and their datatypes (no longer part of the API)
|
|
42
|
+
|
|
43
|
+
## [0.3.0] - 2026-01-09
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- Logging middleware (`withLogging: true` in config) for request/response
|
|
48
|
+
logging
|
|
49
|
+
- Page types for all paginated responses: `ActivitiesPage`, `AnnotationsPage`,
|
|
50
|
+
`ApiTokensPage`, `CommentsPage`, `DocumentsPage`, `FilesPage`,
|
|
51
|
+
`IntegrationsPage`, `IntegrationRunsPage`, `InvitesPage`, `MembersPage`,
|
|
52
|
+
`NotificationsPage`, `WebhooksPage`, `WorkspacesPage`
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- Renamed `Client` class to `Nvisy`
|
|
57
|
+
- Renamed service classes from `*Service` (e.g. `WorkspacesService` →
|
|
58
|
+
`Workspaces`)
|
|
59
|
+
- Renamed service handler methods to include entity names (e.g. `list` →
|
|
60
|
+
`listWorkspaces`)
|
|
61
|
+
- Renamed `ClientError` to `NvisyError` and `ApiError` to `NvisyApiError`
|
|
62
|
+
- `NvisyApiError` now extends `NvisyError`
|
|
63
|
+
- **BREAKING**: API path parameters now use camelCase (`workspaceId` instead of
|
|
64
|
+
`workspace_id`)
|
|
65
|
+
- **BREAKING**: Pagination changed from offset-based to cursor-based
|
|
66
|
+
- Query params: `offset`/`limit` → `limit`/`after`
|
|
67
|
+
- Pagination type: `Pagination` → `CursorPagination`
|
|
68
|
+
- **BREAKING**: All list methods now return paginated response objects instead
|
|
69
|
+
of arrays
|
|
70
|
+
- Return type: `Promise<T[]>` → `Promise<TPage>` (e.g., `WorkspacesPage`)
|
|
71
|
+
- Response structure: `{ items: T[], total?: number, nextCursor?: string }`
|
|
72
|
+
- **BREAKING**: Comments service methods simplified
|
|
73
|
+
- `updateComment(fileId, commentId, ...)` → `updateComment(commentId, ...)`
|
|
74
|
+
- `deleteComment(fileId, commentId)` → `deleteComment(commentId)`
|
|
75
|
+
- Renamed query types to match schema (dropped `Query` suffix)
|
|
76
|
+
- Renamed request types (dropped `Request` suffix)
|
|
77
|
+
|
|
78
|
+
### Removed
|
|
79
|
+
|
|
80
|
+
- `ConfigError` and `NetworkError` classes (use `NvisyError` instead)
|
|
81
|
+
- Re-exports of datatypes and services from main entry point (use
|
|
82
|
+
`@nvisy/sdk/datatypes` and `@nvisy/sdk/services`)
|
|
83
|
+
- `DocumentStatus` type (removed from API)
|
|
84
|
+
- `ListIntegrationsQuery` type (integration type filter removed)
|
|
85
|
+
|
|
86
|
+
## [0.2.0] - 2025-06-15
|
|
12
87
|
|
|
13
88
|
### Added
|
|
14
89
|
|
|
@@ -31,7 +106,8 @@ and this project adheres to
|
|
|
31
106
|
|
|
32
107
|
- `ClientBuilder` class and `Client.builder()` method
|
|
33
108
|
- `Client.fromEnvironment()` method
|
|
34
|
-
- Environment variable support (`NVISY_API_TOKEN`, `NVISY_BASE_URL`,
|
|
109
|
+
- Environment variable support (`NVISY_API_TOKEN`, `NVISY_BASE_URL`,
|
|
110
|
+
`NVISY_USER_AGENT`)
|
|
35
111
|
- Manual type definitions in datatypes (now use schema re-exports)
|
|
36
112
|
|
|
37
113
|
## [0.1.0] - 2025-10-15
|
|
@@ -63,6 +139,8 @@ and this project adheres to
|
|
|
63
139
|
- Network error handling for timeouts, DNS resolution, and connection issues
|
|
64
140
|
- Configuration validation with detailed error messages
|
|
65
141
|
|
|
66
|
-
[Unreleased]: https://github.com/nvisycom/sdk-ts/compare/v0.
|
|
142
|
+
[Unreleased]: https://github.com/nvisycom/sdk-ts/compare/v0.4.0...HEAD
|
|
143
|
+
[0.4.0]: https://github.com/nvisycom/sdk-ts/compare/v0.3.0...v0.4.0
|
|
144
|
+
[0.3.0]: https://github.com/nvisycom/sdk-ts/compare/v0.2.0...v0.3.0
|
|
67
145
|
[0.2.0]: https://github.com/nvisycom/sdk-ts/compare/v0.1.0...v0.2.0
|
|
68
146
|
[0.1.0]: https://github.com/nvisycom/sdk-ts/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
# Nvisy
|
|
1
|
+
# Nvisy SDK for TypeScript
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@nvisy/sdk)
|
|
4
|
+
[](https://github.com/nvisycom/sdk-ts/actions/workflows/build.yml)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
TypeScript client for the [Nvisy](https://nvisy.com/) multimodal redaction platform.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Nvisy detects and removes sensitive information across documents, images, and audio.
|
|
9
|
+
It combines deterministic patterns, NER, computer vision, and LLM-driven classification
|
|
10
|
+
into auditable, policy-driven pipelines built for regulated industries such as
|
|
11
|
+
healthcare, legal, government, and financial services.
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
> [!WARNING]
|
|
14
|
+
> **Active development: API not stable.** This project is under active
|
|
15
|
+
> development. Public APIs, configuration shapes, and on-disk formats may change
|
|
16
|
+
> without notice between releases. Pin a specific version if you depend on this
|
|
17
|
+
> in production.
|
|
14
18
|
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
@@ -18,50 +22,58 @@ Official TypeScript SDK for the Nvisy AI-powered document processing platform. T
|
|
|
18
22
|
npm install @nvisy/sdk
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
### Basic Usage
|
|
24
|
-
|
|
25
|
-
Create a client with your API token:
|
|
25
|
+
## Quick Start
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
|
-
import {
|
|
28
|
+
import { Nvisy } from "@nvisy/sdk";
|
|
29
29
|
|
|
30
|
-
const client = new
|
|
30
|
+
const client = new Nvisy({ apiToken: "your-api-token" });
|
|
31
31
|
|
|
32
|
-
const account = await client.account.
|
|
33
|
-
const
|
|
32
|
+
const account = await client.account.getAccount();
|
|
33
|
+
const workspaces = await client.workspaces.listWorkspaces();
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
The client accepts additional options:
|
|
37
37
|
|
|
38
38
|
```typescript
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const client = new Client({
|
|
39
|
+
const client = new Nvisy({
|
|
42
40
|
apiToken: "your-api-token", // Required
|
|
43
|
-
baseUrl: "https://api.nvisy.com", // Optional
|
|
44
|
-
userAgent: "MyApp/1.0.0", // Optional
|
|
45
|
-
|
|
41
|
+
baseUrl: "https://api.nvisy.com", // Optional
|
|
42
|
+
userAgent: "MyApp/1.0.0", // Optional
|
|
43
|
+
withLogging: true, // Optional
|
|
44
|
+
headers: { // Optional
|
|
46
45
|
"X-Custom-Header": "value",
|
|
47
46
|
},
|
|
48
47
|
});
|
|
49
48
|
```
|
|
50
49
|
|
|
51
|
-
##
|
|
50
|
+
## Features
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
- Modern ES2022+ JavaScript target
|
|
53
|
+
- Full TypeScript support with strict typing
|
|
54
|
+
- Debug logging for development
|
|
55
|
+
- Individual module exports for optimal bundling
|
|
56
|
+
|
|
57
|
+
## Deployment
|
|
58
|
+
|
|
59
|
+
The fastest way to get started is with [Nvisy Cloud](https://nvisy.com).
|
|
60
|
+
|
|
61
|
+
To run locally, see the [nvisycom/runtime](https://github.com/nvisycom/runtime) and [nvisycom/server](https://github.com/nvisycom/server) repositories.
|
|
54
62
|
|
|
55
63
|
## Contributing
|
|
56
64
|
|
|
57
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
|
|
65
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and contribution guidelines.
|
|
66
|
+
|
|
67
|
+
## Changelog
|
|
68
|
+
|
|
69
|
+
See [CHANGELOG.md](CHANGELOG.md) for release notes and version history.
|
|
58
70
|
|
|
59
71
|
## License
|
|
60
72
|
|
|
61
|
-
MIT License
|
|
73
|
+
MIT License, see [LICENSE.txt](LICENSE.txt)
|
|
62
74
|
|
|
63
75
|
## Support
|
|
64
76
|
|
|
65
|
-
- Documentation
|
|
66
|
-
- Issues
|
|
67
|
-
- Email
|
|
77
|
+
- **Documentation**: [docs.nvisy.com](https://docs.nvisy.com)
|
|
78
|
+
- **Issues**: [github.com/nvisycom/sdk-ts/issues](https://github.com/nvisycom/sdk-ts/issues)
|
|
79
|
+
- **Email**: [support@nvisy.com](mailto:support@nvisy.com)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { t as ClientConfig } from "../config-BRQp8Cat.js";
|
|
2
|
+
import { At as Signup, Ot as AuthToken, kt as Login } from "../index-Cmm2g3SG.js";
|
|
3
|
+
//#region src/auth/config.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for standalone authentication functions.
|
|
6
|
+
*
|
|
7
|
+
* This type omits `apiToken` from {@link ClientConfig} since auth functions
|
|
8
|
+
* are used to obtain a token in the first place.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { login } from "@nvisy/sdk/auth";
|
|
13
|
+
*
|
|
14
|
+
* const token = await login(
|
|
15
|
+
* { email: "user@example.com", password: "..." },
|
|
16
|
+
* { baseUrl: "https://api.nvisy.com" }
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
type AuthConfig = Omit<ClientConfig, "apiToken">;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/auth/password.d.ts
|
|
23
|
+
/**
|
|
24
|
+
* Login with email and password to obtain an auth token.
|
|
25
|
+
*
|
|
26
|
+
* This is a standalone function that doesn't require an existing {@link Client}
|
|
27
|
+
* instance. Use the returned token to create an authenticated client.
|
|
28
|
+
*
|
|
29
|
+
* @param credentials - Login credentials (email and password)
|
|
30
|
+
* @param config - Optional configuration (baseUrl, headers, userAgent)
|
|
31
|
+
* @returns Promise that resolves with the auth token
|
|
32
|
+
* @throws {ApiError} If the credentials are invalid or the request fails
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { login } from "@nvisy/sdk/auth";
|
|
37
|
+
* import { Nvisy } from "@nvisy/sdk";
|
|
38
|
+
*
|
|
39
|
+
* const token = await login({
|
|
40
|
+
* email: "user@example.com",
|
|
41
|
+
* password: "your-password",
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* const nvisy = new Nvisy({ apiToken: token.accessToken });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function login(credentials: Login, config?: AuthConfig): Promise<AuthToken>;
|
|
48
|
+
/**
|
|
49
|
+
* Sign up a new account to obtain an auth token.
|
|
50
|
+
*
|
|
51
|
+
* This is a standalone function that doesn't require an existing {@link Client}
|
|
52
|
+
* instance. Use the returned token to create an authenticated client.
|
|
53
|
+
*
|
|
54
|
+
* @param details - Signup details (name, email, password, etc.)
|
|
55
|
+
* @param config - Optional configuration (baseUrl, headers, userAgent)
|
|
56
|
+
* @returns Promise that resolves with the auth token
|
|
57
|
+
* @throws {ApiError} If the signup fails (e.g., email already exists)
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { signup } from "@nvisy/sdk/auth";
|
|
62
|
+
* import { Nvisy } from "@nvisy/sdk";
|
|
63
|
+
*
|
|
64
|
+
* const token = await signup({
|
|
65
|
+
* name: "John Doe",
|
|
66
|
+
* email: "john@example.com",
|
|
67
|
+
* password: "secure-password",
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* const nvisy = new Nvisy({ apiToken: token.accessToken });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function signup(details: Signup, config?: AuthConfig): Promise<AuthToken>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type AuthConfig, login, signup };
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/auth/config.ts","../../src/auth/password.ts"],"mappings":";;;;;;;;;;;;;;;;;;;KA2BY,aAAa,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCiDR,MACrB,aAAa,OACb,SAAS,aACP,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiCW,OACrB,SAAS,QACT,SAAS,aACP,QAAQ"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { i as DEFAULTS, t as errorMiddleware } from "../error-DmkKaDjI.js";
|
|
2
|
+
import createClient from "openapi-fetch";
|
|
3
|
+
|
|
4
|
+
//#region src/auth/password.ts
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview Standalone password-based authentication functions.
|
|
7
|
+
*
|
|
8
|
+
* This module provides functions for login and signup that don't require
|
|
9
|
+
* an existing API token. Use these to obtain an auth token, then create
|
|
10
|
+
* an authenticated {@link Client} instance.
|
|
11
|
+
*
|
|
12
|
+
* @module auth/password
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { login, signup } from "@nvisy/sdk/auth";
|
|
17
|
+
* import { Nvisy } from "@nvisy/sdk";
|
|
18
|
+
*
|
|
19
|
+
* // Login to get a token
|
|
20
|
+
* const token = await login({ email: "user@example.com", password: "..." });
|
|
21
|
+
*
|
|
22
|
+
* // Create authenticated client
|
|
23
|
+
* const nvisy = new Nvisy({ apiToken: token.accessToken });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Creates an unauthenticated API client for auth operations.
|
|
28
|
+
*
|
|
29
|
+
* @param config - Optional configuration options
|
|
30
|
+
* @returns A configured openapi-fetch client without authentication
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
function createAuthClient(config) {
|
|
34
|
+
const headers = {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
"User-Agent": config?.userAgent ?? DEFAULTS.USER_AGENT,
|
|
37
|
+
...config?.headers
|
|
38
|
+
};
|
|
39
|
+
const client = createClient({
|
|
40
|
+
baseUrl: config?.baseUrl ?? DEFAULTS.BASE_URL,
|
|
41
|
+
headers
|
|
42
|
+
});
|
|
43
|
+
client.use(errorMiddleware);
|
|
44
|
+
return client;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Login with email and password to obtain an auth token.
|
|
48
|
+
*
|
|
49
|
+
* This is a standalone function that doesn't require an existing {@link Client}
|
|
50
|
+
* instance. Use the returned token to create an authenticated client.
|
|
51
|
+
*
|
|
52
|
+
* @param credentials - Login credentials (email and password)
|
|
53
|
+
* @param config - Optional configuration (baseUrl, headers, userAgent)
|
|
54
|
+
* @returns Promise that resolves with the auth token
|
|
55
|
+
* @throws {ApiError} If the credentials are invalid or the request fails
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { login } from "@nvisy/sdk/auth";
|
|
60
|
+
* import { Nvisy } from "@nvisy/sdk";
|
|
61
|
+
*
|
|
62
|
+
* const token = await login({
|
|
63
|
+
* email: "user@example.com",
|
|
64
|
+
* password: "your-password",
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* const nvisy = new Nvisy({ apiToken: token.accessToken });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async function login(credentials, config) {
|
|
71
|
+
const { data } = await createAuthClient(config).POST("/auth/login/", { body: credentials });
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sign up a new account to obtain an auth token.
|
|
76
|
+
*
|
|
77
|
+
* This is a standalone function that doesn't require an existing {@link Client}
|
|
78
|
+
* instance. Use the returned token to create an authenticated client.
|
|
79
|
+
*
|
|
80
|
+
* @param details - Signup details (name, email, password, etc.)
|
|
81
|
+
* @param config - Optional configuration (baseUrl, headers, userAgent)
|
|
82
|
+
* @returns Promise that resolves with the auth token
|
|
83
|
+
* @throws {ApiError} If the signup fails (e.g., email already exists)
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import { signup } from "@nvisy/sdk/auth";
|
|
88
|
+
* import { Nvisy } from "@nvisy/sdk";
|
|
89
|
+
*
|
|
90
|
+
* const token = await signup({
|
|
91
|
+
* name: "John Doe",
|
|
92
|
+
* email: "john@example.com",
|
|
93
|
+
* password: "secure-password",
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* const nvisy = new Nvisy({ apiToken: token.accessToken });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
async function signup(details, config) {
|
|
100
|
+
const { data } = await createAuthClient(config).POST("/auth/signup/", { body: details });
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { login, signup };
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/auth/password.ts"],"sourcesContent":["/**\n * @fileoverview Standalone password-based authentication functions.\n *\n * This module provides functions for login and signup that don't require\n * an existing API token. Use these to obtain an auth token, then create\n * an authenticated {@link Client} instance.\n *\n * @module auth/password\n *\n * @example\n * ```typescript\n * import { login, signup } from \"@nvisy/sdk/auth\";\n * import { Nvisy } from \"@nvisy/sdk\";\n *\n * // Login to get a token\n * const token = await login({ email: \"user@example.com\", password: \"...\" });\n *\n * // Create authenticated client\n * const nvisy = new Nvisy({ apiToken: token.accessToken });\n * ```\n */\n\nimport createClient from \"openapi-fetch\";\nimport type { AuthConfig } from \"@/auth/config.js\";\nimport { DEFAULTS } from \"@/config.js\";\nimport type { AuthToken, Login, Signup } from \"@/datatypes/index.js\";\nimport { errorMiddleware } from \"@/middleware/index.js\";\nimport type { paths } from \"@/schema/api.js\";\n\n/**\n * Creates an unauthenticated API client for auth operations.\n *\n * @param config - Optional configuration options\n * @returns A configured openapi-fetch client without authentication\n * @internal\n */\nfunction createAuthClient(config?: AuthConfig) {\n\tconst headers: Record<string, string> = {\n\t\t\"Content-Type\": \"application/json\",\n\t\t\"User-Agent\": config?.userAgent ?? DEFAULTS.USER_AGENT,\n\t\t...config?.headers,\n\t};\n\n\tconst client = createClient<paths>({\n\t\tbaseUrl: config?.baseUrl ?? DEFAULTS.BASE_URL,\n\t\theaders,\n\t});\n\n\tclient.use(errorMiddleware);\n\treturn client;\n}\n\n/**\n * Login with email and password to obtain an auth token.\n *\n * This is a standalone function that doesn't require an existing {@link Client}\n * instance. Use the returned token to create an authenticated client.\n *\n * @param credentials - Login credentials (email and password)\n * @param config - Optional configuration (baseUrl, headers, userAgent)\n * @returns Promise that resolves with the auth token\n * @throws {ApiError} If the credentials are invalid or the request fails\n *\n * @example\n * ```typescript\n * import { login } from \"@nvisy/sdk/auth\";\n * import { Nvisy } from \"@nvisy/sdk\";\n *\n * const token = await login({\n * email: \"user@example.com\",\n * password: \"your-password\",\n * });\n *\n * const nvisy = new Nvisy({ apiToken: token.accessToken });\n * ```\n */\nexport async function login(\n\tcredentials: Login,\n\tconfig?: AuthConfig,\n): Promise<AuthToken> {\n\tconst client = createAuthClient(config);\n\tconst { data } = await client.POST(\"/auth/login/\", {\n\t\tbody: credentials,\n\t});\n\treturn data!;\n}\n\n/**\n * Sign up a new account to obtain an auth token.\n *\n * This is a standalone function that doesn't require an existing {@link Client}\n * instance. Use the returned token to create an authenticated client.\n *\n * @param details - Signup details (name, email, password, etc.)\n * @param config - Optional configuration (baseUrl, headers, userAgent)\n * @returns Promise that resolves with the auth token\n * @throws {ApiError} If the signup fails (e.g., email already exists)\n *\n * @example\n * ```typescript\n * import { signup } from \"@nvisy/sdk/auth\";\n * import { Nvisy } from \"@nvisy/sdk\";\n *\n * const token = await signup({\n * name: \"John Doe\",\n * email: \"john@example.com\",\n * password: \"secure-password\",\n * });\n *\n * const nvisy = new Nvisy({ apiToken: token.accessToken });\n * ```\n */\nexport async function signup(\n\tdetails: Signup,\n\tconfig?: AuthConfig,\n): Promise<AuthToken> {\n\tconst client = createAuthClient(config);\n\tconst { data } = await client.POST(\"/auth/signup/\", {\n\t\tbody: details,\n\t});\n\treturn data!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAS,iBAAiB,QAAqB;CAC9C,MAAM,UAAkC;EACvC,gBAAgB;EAChB,cAAc,QAAQ,aAAa,SAAS;EAC5C,GAAG,QAAQ;CACZ;CAEA,MAAM,SAAS,aAAoB;EAClC,SAAS,QAAQ,WAAW,SAAS;EACrC;CACD,CAAC;CAED,OAAO,IAAI,eAAe;CAC1B,OAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,eAAsB,MACrB,aACA,QACqB;CAErB,MAAM,EAAE,SAAS,MADF,iBAAiB,MACJ,CAAC,CAAC,KAAK,gBAAgB,EAClD,MAAM,YACP,CAAC;CACD,OAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,eAAsB,OACrB,SACA,QACqB;CAErB,MAAM,EAAE,SAAS,MADF,iBAAiB,MACJ,CAAC,CAAC,KAAK,iBAAiB,EACnD,MAAM,QACP,CAAC;CACD,OAAO;AACR"}
|