@nvisy/sdk 0.3.0 → 0.5.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 +62 -1
- package/README.md +43 -21
- package/dist/auth/index.d.ts +7 -36
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +96 -174
- package/dist/auth/index.js.map +1 -1
- package/dist/client-DAxwkjk3.d.ts +809 -0
- package/dist/client-DAxwkjk3.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 -9
- 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-DfNB2LNT.d.ts +10477 -0
- package/dist/index-DfNB2LNT.d.ts.map +1 -0
- package/dist/index.d.ts +86 -98
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +273 -1472
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +2 -5
- package/dist/services/index.js +2 -1066
- package/dist/services-DXP-jsLt.js +1087 -0
- package/dist/services-DXP-jsLt.js.map +1 -0
- package/package.json +13 -13
- package/dist/auth-CncOz2vx.d.ts +0 -7420
- package/dist/client-DQRisDAK.d.ts +0 -808
- package/dist/config-L7FKq_q5.d.ts +0 -81
- package/dist/datatypes/index.js.map +0 -1
- package/dist/services/index.js.map +0 -1
- package/dist/workspace-BjdbMWsa.d.ts +0 -118
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-DAxwkjk3.d.ts","names":[],"sources":["../src/services/account.ts","../src/services/activities.ts","../src/services/api-tokens.ts","../src/services/auth.ts","../src/services/connections.ts","../src/services/files.ts","../src/services/invites.ts","../src/services/members.ts","../src/services/notifications.ts","../src/services/pipelines.ts","../src/services/policies.ts","../src/services/runs.ts","../src/services/status.ts","../src/services/webhooks.ts","../src/services/workspaces.ts","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AAW;;;;MAOX,cAAc;;;;MAOd,aAAa;;;;MAOb,eAAe;;;;MAOf,SAAS;;;;MAOT,aAAa;;;;MAOb,YAAY;;;;MAOZ,WAAW;;;;MAOX,WAAW;;;;MAOX,iBAAiB;;;;MAOjB,QAAQ;;;;MAOR,YAAY;;;;MAOZ,cAAc"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region src/config.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Configuration types and constants for the Nvisy SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module provides configuration interfaces, default values, and environment
|
|
6
|
+
* variable names used throughout the SDK.
|
|
7
|
+
*
|
|
8
|
+
* @module config
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Current SDK version.
|
|
12
|
+
*
|
|
13
|
+
* Used in the default user agent string and for version tracking.
|
|
14
|
+
*/
|
|
15
|
+
declare const VERSION = "0.3.0";
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for creating a Nvisy client.
|
|
18
|
+
*
|
|
19
|
+
* The `apiToken` field is required for authentication. All other fields are optional
|
|
20
|
+
* and will use sensible defaults when omitted.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const config: ClientConfig = {
|
|
25
|
+
* apiToken: "your-api-token",
|
|
26
|
+
* baseUrl: "https://api.nvisy.com",
|
|
27
|
+
* headers: { "X-Custom-Header": "value" },
|
|
28
|
+
* };
|
|
29
|
+
* const client = new Client(config);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
interface ClientConfig {
|
|
33
|
+
/**
|
|
34
|
+
* API token for authentication.
|
|
35
|
+
*
|
|
36
|
+
* Tokens can be obtained from the Nvisy dashboard or via the auth endpoints.
|
|
37
|
+
*/
|
|
38
|
+
apiToken: string;
|
|
39
|
+
/**
|
|
40
|
+
* Base URL for the Nvisy API.
|
|
41
|
+
*
|
|
42
|
+
* @default "https://api.nvisy.com"
|
|
43
|
+
*/
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Custom headers to include with every request.
|
|
47
|
+
*
|
|
48
|
+
* These headers are merged with the default headers (Content-Type, User-Agent,
|
|
49
|
+
* and Authorization). Custom headers take precedence over defaults if there
|
|
50
|
+
* are conflicts.
|
|
51
|
+
*/
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
/**
|
|
54
|
+
* Custom user agent string to identify your application.
|
|
55
|
+
*
|
|
56
|
+
* @default "@nvisy/sdk v.{version}"
|
|
57
|
+
*/
|
|
58
|
+
userAgent?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Enable logging for requests and responses.
|
|
61
|
+
*
|
|
62
|
+
* When enabled, logs request method, URL, status, and timing to console.
|
|
63
|
+
*
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
withLogging?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Default configuration values used when options are not explicitly provided.
|
|
70
|
+
*/
|
|
71
|
+
declare const DEFAULTS: {
|
|
72
|
+
/**
|
|
73
|
+
* Default base URL for the Nvisy API.
|
|
74
|
+
*/
|
|
75
|
+
readonly BASE_URL: "https://api.nvisy.com";
|
|
76
|
+
/**
|
|
77
|
+
* Default user agent string.
|
|
78
|
+
*/
|
|
79
|
+
readonly USER_AGENT: "@nvisy/sdk v.0.3.0";
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { DEFAULTS as n, VERSION as r, ClientConfig as t };
|
|
83
|
+
//# sourceMappingURL=config-BRQp8Cat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-BRQp8Cat.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;;;;;;cAca;;;;;;;;;;;;;;;;;UAkBI;;;;;;EAMhB;;;;;;EAOA;;;;;;;;EASA,UAAU;;;;;;EAOV;;;;;;;;EASA;;;;;cAMY;;;;WAAA;;;;WAAA"}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { A as AuthToken, L as Login, S as Signup } from '../auth-CncOz2vx.js';
|
|
4
|
-
|
|
5
|
-
type Schemas = components["schemas"];
|
|
6
|
-
type ErrorResponse = Schemas["ErrorResponse"];
|
|
7
|
-
type ValidationErrorDetail = Schemas["ValidationErrorDetail"];
|
|
8
|
-
|
|
9
|
-
export type { ErrorResponse, ValidationErrorDetail };
|
|
1
|
+
import { $ as InvitePreview, A as PipelineFilter, At as ApiTokensPage, B as NotificationsPage, C as PolicyAction, Ct as UpdateConnection, D as CreatePipeline, Dt as ApiToken, E as UpdatePolicy, Et as Signup, F as UpdatePipeline, Ft as Activity, G as MemberSortField, H as UpdateNotificationSettings, I as CursorPagination, It as ActivityType, J as CreateInvite, K as MembersPage, L as Notification, Lt as Account, M as PipelineSummariesPage, Mt as TokenExpiration, N as PipelineSummary, Nt as UpdateApiToken, O as Pipeline, Ot as ApiTokenType, P as PipelineTriggerType, Pt as ActivitiesPage, Q as InviteExpiration, R as NotificationEvent, Rt as PublicAccount, S as Policy, St as CreateConnection, T as PolicyRule, Tt as Login, U as ListMembers, V as UnreadStatus, W as Member, X as Invite, Y as GenerateInviteCode, Z as InviteCode, _ as PipelineRun, _t as ErrorResponse, a as WorkspacesPage, at as ReplyInvite, b as CreatePolicy, bt as ConnectionsPage, c as UpdateWebhook, ct as ComponentHealth, d as WebhookEvent, dt as File, et as InviteSent, f as WebhookResult, ft as FileFormat, g as CreatePipelineRun, gt as UpdateFile, h as AnalyzedDocument, ht as ListFiles, i as WorkspaceRole, it as ListInvites, j as PipelineStatus, jt as CreateApiToken, k as PipelineDefinition, kt as ApiTokenWithJWT, l as Webhook, lt as Health, m as WebhooksPage, mt as FilesPage, n as UpdateWorkspace, nt as InviteStatus, o as CreateWebhook, ot as SortOrder, p as WebhookStatus, pt as FileSource, q as UpdateMember, r as Workspace, rt as InvitesPage, s as TestWebhook, st as CheckHealth, t as CreateWorkspace, tt as InviteSortField, u as WebhookCreated, ut as HealthStatus, v as PipelineRunStatus, vt as ValidationErrorDetail, w as PolicyDefinition, wt as AuthToken, x as PoliciesPage, xt as ConnectionsQuery, y as PipelineRunsPage, yt as Connection, z as NotificationSettings, zt as UpdateAccount } from "../index-DfNB2LNT.js";
|
|
2
|
+
export type { Account, ActivitiesPage, Activity, ActivityType, AnalyzedDocument, ApiToken, ApiTokenType, ApiTokenWithJWT, ApiTokensPage, AuthToken, CheckHealth, ComponentHealth, Connection, ConnectionsPage, ConnectionsQuery, CreateApiToken, CreateConnection, CreateInvite, CreatePipeline, CreatePipelineRun, CreatePolicy, CreateWebhook, CreateWorkspace, CursorPagination, ErrorResponse, File, FileFormat, FileSource, FilesPage, GenerateInviteCode, Health, HealthStatus, Invite, InviteCode, InviteExpiration, InvitePreview, InviteSent, InviteSortField, InviteStatus, InvitesPage, ListFiles, ListInvites, ListMembers, Login, Member, MemberSortField, MembersPage, Notification, NotificationEvent, NotificationSettings, NotificationsPage, Pipeline, PipelineDefinition, PipelineFilter, PipelineRun, PipelineRunStatus, PipelineRunsPage, PipelineStatus, PipelineSummariesPage, PipelineSummary, PipelineTriggerType, PoliciesPage, Policy, PolicyAction, PolicyDefinition, PolicyRule, PublicAccount, ReplyInvite, Signup, SortOrder, TestWebhook, TokenExpiration, UnreadStatus, UpdateAccount, UpdateApiToken, UpdateConnection, UpdateFile, UpdateMember, UpdateNotificationSettings, UpdatePipeline, UpdatePolicy, UpdateWebhook, UpdateWorkspace, ValidationErrorDetail, Webhook, WebhookCreated, WebhookEvent, WebhookResult, WebhookStatus, WebhooksPage, Workspace, WorkspaceRole, WorkspacesPage };
|
package/dist/datatypes/index.js
CHANGED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
//#region src/config.ts
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Configuration types and constants for the Nvisy SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module provides configuration interfaces, default values, and environment
|
|
6
|
+
* variable names used throughout the SDK.
|
|
7
|
+
*
|
|
8
|
+
* @module config
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Current SDK version.
|
|
12
|
+
*
|
|
13
|
+
* Used in the default user agent string and for version tracking.
|
|
14
|
+
*/
|
|
15
|
+
const VERSION = "0.3.0";
|
|
16
|
+
/**
|
|
17
|
+
* Default configuration values used when options are not explicitly provided.
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULTS = {
|
|
20
|
+
/**
|
|
21
|
+
* Default base URL for the Nvisy API.
|
|
22
|
+
*/
|
|
23
|
+
BASE_URL: "https://api.nvisy.com",
|
|
24
|
+
/**
|
|
25
|
+
* Default user agent string.
|
|
26
|
+
*/
|
|
27
|
+
USER_AGENT: `@nvisy/sdk v.${VERSION}`
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/errors.ts
|
|
32
|
+
/**
|
|
33
|
+
* Base error class for all Nvisy SDK errors.
|
|
34
|
+
*
|
|
35
|
+
* This class provides common functionality for all SDK errors.
|
|
36
|
+
* It ensures proper error naming and stack traces.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* try {
|
|
41
|
+
* const client = new Client({ apiToken: "" });
|
|
42
|
+
* } catch (error) {
|
|
43
|
+
* if (error instanceof NvisyError) {
|
|
44
|
+
* console.log("SDK error:", error.message);
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
var NvisyError = class extends Error {
|
|
50
|
+
/**
|
|
51
|
+
* The error class name.
|
|
52
|
+
*/
|
|
53
|
+
name;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new NvisyError.
|
|
56
|
+
*
|
|
57
|
+
* @param message - The error message
|
|
58
|
+
*/
|
|
59
|
+
constructor(message) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = this.constructor.name;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Error thrown when the Nvisy API returns an error response.
|
|
66
|
+
*
|
|
67
|
+
* This error class wraps the API's {@link ErrorResponse} format and adds
|
|
68
|
+
* the HTTP status code. It provides helper methods to categorize errors
|
|
69
|
+
* and determine if they are retryable.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* try {
|
|
74
|
+
* await client.account.getAccount();
|
|
75
|
+
* } catch (error) {
|
|
76
|
+
* if (error instanceof NvisyApiError) {
|
|
77
|
+
* console.log(`API Error: ${error.message}`);
|
|
78
|
+
* console.log(`Status: ${error.statusCode}`);
|
|
79
|
+
* if (error.isRetryable()) {
|
|
80
|
+
* // Implement retry logic
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
var NvisyApiError = class extends NvisyError {
|
|
87
|
+
/**
|
|
88
|
+
* The error type identifier (e.g., "ValidationError", "NotFoundError").
|
|
89
|
+
*/
|
|
90
|
+
name;
|
|
91
|
+
/**
|
|
92
|
+
* Human-readable error message safe for display to end users.
|
|
93
|
+
*/
|
|
94
|
+
message;
|
|
95
|
+
/**
|
|
96
|
+
* The resource type that the error relates to (e.g., "account", "project").
|
|
97
|
+
* May be undefined if the error is not resource-specific.
|
|
98
|
+
*/
|
|
99
|
+
resource;
|
|
100
|
+
/**
|
|
101
|
+
* A helpful suggestion for resolving the error.
|
|
102
|
+
* May be undefined if no suggestion is available.
|
|
103
|
+
*/
|
|
104
|
+
suggestion;
|
|
105
|
+
/**
|
|
106
|
+
* Field-specific validation errors.
|
|
107
|
+
* Present when the error is due to invalid input data.
|
|
108
|
+
*/
|
|
109
|
+
validation;
|
|
110
|
+
/**
|
|
111
|
+
* HTTP status code of the response (e.g., 400, 404, 500).
|
|
112
|
+
*/
|
|
113
|
+
statusCode;
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new NvisyApiError from an API error response.
|
|
116
|
+
*
|
|
117
|
+
* @param response - The error response from the API
|
|
118
|
+
* @param statusCode - The HTTP status code of the response
|
|
119
|
+
*/
|
|
120
|
+
constructor(response, statusCode) {
|
|
121
|
+
super(response.message);
|
|
122
|
+
this.name = response.name;
|
|
123
|
+
this.message = response.message;
|
|
124
|
+
this.resource = response.resource;
|
|
125
|
+
this.suggestion = response.suggestion;
|
|
126
|
+
this.validation = response.validation;
|
|
127
|
+
this.statusCode = statusCode;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Checks if this is a client error (4xx status code).
|
|
131
|
+
*
|
|
132
|
+
* Client errors indicate problems with the request itself, such as
|
|
133
|
+
* invalid input, missing authentication, or accessing non-existent resources.
|
|
134
|
+
*
|
|
135
|
+
* @returns True if the status code is in the 4xx range
|
|
136
|
+
*/
|
|
137
|
+
isClientError() {
|
|
138
|
+
return this.statusCode >= 400 && this.statusCode < 500;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Checks if this is a server error (5xx status code).
|
|
142
|
+
*
|
|
143
|
+
* Server errors indicate problems on the API side. These are typically
|
|
144
|
+
* transient and may succeed if retried.
|
|
145
|
+
*
|
|
146
|
+
* @returns True if the status code is in the 5xx range
|
|
147
|
+
*/
|
|
148
|
+
isServerError() {
|
|
149
|
+
return this.statusCode >= 500;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Determines if this error is safe to retry.
|
|
153
|
+
*
|
|
154
|
+
* An error is considered retryable if it's a server error (5xx),
|
|
155
|
+
* a request timeout (408), or rate limiting (429).
|
|
156
|
+
*
|
|
157
|
+
* @returns True if the request may succeed on retry
|
|
158
|
+
*/
|
|
159
|
+
isRetryable() {
|
|
160
|
+
return this.statusCode >= 500 || this.statusCode === 408 || this.statusCode === 429;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Converts the error to a plain {@link ErrorResponse} object.
|
|
164
|
+
*
|
|
165
|
+
* Useful for serialization or logging.
|
|
166
|
+
*
|
|
167
|
+
* @returns A plain object representation of the error
|
|
168
|
+
*/
|
|
169
|
+
toJSON() {
|
|
170
|
+
return {
|
|
171
|
+
name: this.name,
|
|
172
|
+
message: this.message,
|
|
173
|
+
resource: this.resource,
|
|
174
|
+
suggestion: this.suggestion,
|
|
175
|
+
validation: this.validation
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/middleware/error.ts
|
|
182
|
+
/**
|
|
183
|
+
* Middleware that automatically throws NvisyApiError for error responses.
|
|
184
|
+
* This replaces the need for manual checks in services.
|
|
185
|
+
*/
|
|
186
|
+
const errorMiddleware = {
|
|
187
|
+
async onResponse({ response }) {
|
|
188
|
+
if (!response.ok) throw new NvisyApiError(await response.clone().json(), response.status);
|
|
189
|
+
return response;
|
|
190
|
+
},
|
|
191
|
+
onError({ error }) {
|
|
192
|
+
if (error instanceof Error) throw new NvisyError(error.message);
|
|
193
|
+
throw new NvisyError("An unknown network error occurred");
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { VERSION as a, DEFAULTS as i, NvisyApiError as n, NvisyError as r, errorMiddleware as t };
|
|
199
|
+
//# sourceMappingURL=error-DmkKaDjI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-DmkKaDjI.js","names":[],"sources":["../src/config.ts","../src/errors.ts","../src/middleware/error.ts"],"sourcesContent":["/**\n * @fileoverview Configuration types and constants for the Nvisy SDK.\n *\n * This module provides configuration interfaces, default values, and environment\n * variable names used throughout the SDK.\n *\n * @module config\n */\n\n/**\n * Current SDK version.\n *\n * Used in the default user agent string and for version tracking.\n */\nexport const VERSION = \"0.3.0\";\n\n/**\n * Configuration options for creating a Nvisy client.\n *\n * The `apiToken` field is required for authentication. All other fields are optional\n * and will use sensible defaults when omitted.\n *\n * @example\n * ```typescript\n * const config: ClientConfig = {\n * apiToken: \"your-api-token\",\n * baseUrl: \"https://api.nvisy.com\",\n * headers: { \"X-Custom-Header\": \"value\" },\n * };\n * const client = new Client(config);\n * ```\n */\nexport interface ClientConfig {\n\t/**\n\t * API token for authentication.\n\t *\n\t * Tokens can be obtained from the Nvisy dashboard or via the auth endpoints.\n\t */\n\tapiToken: string;\n\n\t/**\n\t * Base URL for the Nvisy API.\n\t *\n\t * @default \"https://api.nvisy.com\"\n\t */\n\tbaseUrl?: string;\n\n\t/**\n\t * Custom headers to include with every request.\n\t *\n\t * These headers are merged with the default headers (Content-Type, User-Agent,\n\t * and Authorization). Custom headers take precedence over defaults if there\n\t * are conflicts.\n\t */\n\theaders?: Record<string, string>;\n\n\t/**\n\t * Custom user agent string to identify your application.\n\t *\n\t * @default \"@nvisy/sdk v.{version}\"\n\t */\n\tuserAgent?: string;\n\n\t/**\n\t * Enable logging for requests and responses.\n\t *\n\t * When enabled, logs request method, URL, status, and timing to console.\n\t *\n\t * @default false\n\t */\n\twithLogging?: boolean;\n}\n\n/**\n * Default configuration values used when options are not explicitly provided.\n */\nexport const DEFAULTS = {\n\t/**\n\t * Default base URL for the Nvisy API.\n\t */\n\tBASE_URL: \"https://api.nvisy.com\",\n\n\t/**\n\t * Default user agent string.\n\t */\n\tUSER_AGENT: `@nvisy/sdk v.${VERSION}`,\n} as const;\n","/**\n * @fileoverview Error types for the Nvisy SDK.\n *\n * This module defines the error hierarchy used throughout the SDK:\n * - {@link NvisyError} - Base error class for all SDK errors\n * - {@link NvisyApiError} - Errors returned by the Nvisy API (4xx/5xx responses)\n *\n * @module errors\n */\n\nimport type { ErrorResponse } from \"@/datatypes/index.js\";\n\n// Re-export ErrorResponse type for convenience\nexport type { ErrorResponse } from \"@/datatypes/index.js\";\n\n/**\n * Base error class for all Nvisy SDK errors.\n *\n * This class provides common functionality for all SDK errors.\n * It ensures proper error naming and stack traces.\n *\n * @example\n * ```typescript\n * try {\n * const client = new Client({ apiToken: \"\" });\n * } catch (error) {\n * if (error instanceof NvisyError) {\n * console.log(\"SDK error:\", error.message);\n * }\n * }\n * ```\n */\nexport class NvisyError extends Error {\n\t/**\n\t * The error class name.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Creates a new NvisyError.\n\t *\n\t * @param message - The error message\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = this.constructor.name;\n\t}\n}\n\n/**\n * Error thrown when the Nvisy API returns an error response.\n *\n * This error class wraps the API's {@link ErrorResponse} format and adds\n * the HTTP status code. It provides helper methods to categorize errors\n * and determine if they are retryable.\n *\n * @example\n * ```typescript\n * try {\n * await client.account.getAccount();\n * } catch (error) {\n * if (error instanceof NvisyApiError) {\n * console.log(`API Error: ${error.message}`);\n * console.log(`Status: ${error.statusCode}`);\n * if (error.isRetryable()) {\n * // Implement retry logic\n * }\n * }\n * }\n * ```\n */\nexport class NvisyApiError extends NvisyError implements ErrorResponse {\n\t/**\n\t * The error type identifier (e.g., \"ValidationError\", \"NotFoundError\").\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Human-readable error message safe for display to end users.\n\t */\n\tpublic readonly message: string;\n\n\t/**\n\t * The resource type that the error relates to (e.g., \"account\", \"project\").\n\t * May be undefined if the error is not resource-specific.\n\t */\n\tpublic readonly resource?: string;\n\n\t/**\n\t * A helpful suggestion for resolving the error.\n\t * May be undefined if no suggestion is available.\n\t */\n\tpublic readonly suggestion?: string;\n\n\t/**\n\t * Field-specific validation errors.\n\t * Present when the error is due to invalid input data.\n\t */\n\tpublic readonly validation?: ErrorResponse[\"validation\"];\n\n\t/**\n\t * HTTP status code of the response (e.g., 400, 404, 500).\n\t */\n\tpublic readonly statusCode: number;\n\n\t/**\n\t * Creates a new NvisyApiError from an API error response.\n\t *\n\t * @param response - The error response from the API\n\t * @param statusCode - The HTTP status code of the response\n\t */\n\tconstructor(response: ErrorResponse, statusCode: number) {\n\t\tsuper(response.message);\n\t\tthis.name = response.name;\n\t\tthis.message = response.message;\n\t\tthis.resource = response.resource;\n\t\tthis.suggestion = response.suggestion;\n\t\tthis.validation = response.validation;\n\t\tthis.statusCode = statusCode;\n\t}\n\n\t/**\n\t * Checks if this is a client error (4xx status code).\n\t *\n\t * Client errors indicate problems with the request itself, such as\n\t * invalid input, missing authentication, or accessing non-existent resources.\n\t *\n\t * @returns True if the status code is in the 4xx range\n\t */\n\tisClientError(): boolean {\n\t\treturn this.statusCode >= 400 && this.statusCode < 500;\n\t}\n\n\t/**\n\t * Checks if this is a server error (5xx status code).\n\t *\n\t * Server errors indicate problems on the API side. These are typically\n\t * transient and may succeed if retried.\n\t *\n\t * @returns True if the status code is in the 5xx range\n\t */\n\tisServerError(): boolean {\n\t\treturn this.statusCode >= 500;\n\t}\n\n\t/**\n\t * Determines if this error is safe to retry.\n\t *\n\t * An error is considered retryable if it's a server error (5xx),\n\t * a request timeout (408), or rate limiting (429).\n\t *\n\t * @returns True if the request may succeed on retry\n\t */\n\tisRetryable(): boolean {\n\t\treturn (\n\t\t\tthis.statusCode >= 500 || // Server errors\n\t\t\tthis.statusCode === 408 || // Request timeout\n\t\t\tthis.statusCode === 429 // Rate limited\n\t\t);\n\t}\n\n\t/**\n\t * Converts the error to a plain {@link ErrorResponse} object.\n\t *\n\t * Useful for serialization or logging.\n\t *\n\t * @returns A plain object representation of the error\n\t */\n\ttoJSON(): ErrorResponse {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tresource: this.resource,\n\t\t\tsuggestion: this.suggestion,\n\t\t\tvalidation: this.validation,\n\t\t};\n\t}\n}\n","import type { Middleware } from \"openapi-fetch\";\nimport type { ErrorResponse } from \"@/datatypes/index.js\";\nimport { NvisyApiError, NvisyError } from \"@/errors.js\";\n\n/**\n * Middleware that automatically throws NvisyApiError for error responses.\n * This replaces the need for manual checks in services.\n */\nexport const errorMiddleware: Middleware = {\n\tasync onResponse({ response }) {\n\t\tif (!response.ok) {\n\t\t\tconst error = (await response.clone().json()) as ErrorResponse;\n\t\t\tthrow new NvisyApiError(error, response.status);\n\t\t}\n\t\treturn response;\n\t},\n\n\tonError({ error }) {\n\t\t// Wrap fetch errors (network failures, CORS, etc.) in NvisyError\n\t\tif (error instanceof Error) {\n\t\t\tthrow new NvisyError(error.message);\n\t\t}\n\t\tthrow new NvisyError(\"An unknown network error occurred\");\n\t},\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,UAAU;;;;AA8DvB,MAAa,WAAW;;;;CAIvB,UAAU;;;;CAKV,YAAY,gBAAgB;AAC7B;;;;;;;;;;;;;;;;;;;;;ACtDA,IAAa,aAAb,cAAgC,MAAM;;;;CAIrC,AAAgB;;;;;;CAOhB,YAAY,SAAiB;EAC5B,MAAM,OAAO;EACb,KAAK,OAAO,KAAK,YAAY;CAC9B;AACD;;;;;;;;;;;;;;;;;;;;;;;AAwBA,IAAa,gBAAb,cAAmC,WAAoC;;;;CAItE,AAAgB;;;;CAKhB,AAAgB;;;;;CAMhB,AAAgB;;;;;CAMhB,AAAgB;;;;;CAMhB,AAAgB;;;;CAKhB,AAAgB;;;;;;;CAQhB,YAAY,UAAyB,YAAoB;EACxD,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO,SAAS;EACrB,KAAK,UAAU,SAAS;EACxB,KAAK,WAAW,SAAS;EACzB,KAAK,aAAa,SAAS;EAC3B,KAAK,aAAa,SAAS;EAC3B,KAAK,aAAa;CACnB;;;;;;;;;CAUA,gBAAyB;EACxB,OAAO,KAAK,cAAc,OAAO,KAAK,aAAa;CACpD;;;;;;;;;CAUA,gBAAyB;EACxB,OAAO,KAAK,cAAc;CAC3B;;;;;;;;;CAUA,cAAuB;EACtB,OACC,KAAK,cAAc,OACnB,KAAK,eAAe,OACpB,KAAK,eAAe;CAEtB;;;;;;;;CASA,SAAwB;EACvB,OAAO;GACN,MAAM,KAAK;GACX,SAAS,KAAK;GACd,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,YAAY,KAAK;EAClB;CACD;AACD;;;;;;;;ACzKA,MAAa,kBAA8B;C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