@novence/sdk 0.2.1 → 0.2.2

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.
@@ -2,6 +2,14 @@
2
2
  export declare const DEFAULT_BASE_URL = "https://api.novence.ai";
3
3
  /** True for a Novence client from any copy of this module. */
4
4
  export declare function isNovenceClient(value: unknown): value is Novence;
5
+ /**
6
+ * Thrown for any non-2xx API response. `status` lets callers distinguish 401
7
+ * from 402 from 429 without matching on message text.
8
+ */
9
+ export declare class NovenceError extends Error {
10
+ readonly status: number;
11
+ constructor(message: string, status: number);
12
+ }
5
13
  export interface NovenceOptions {
6
14
  apiKey: string;
7
15
  baseUrl?: string;
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Novence = exports.DEFAULT_BASE_URL = void 0;
3
+ exports.Novence = exports.NovenceError = exports.DEFAULT_BASE_URL = void 0;
4
4
  exports.isNovenceClient = isNovenceClient;
5
5
  exports.bootstrapAccount = bootstrapAccount;
6
6
  exports.verifyEmail = verifyEmail;
@@ -35,6 +35,19 @@ function isNovenceClient(value) {
35
35
  value !== null &&
36
36
  value[CLIENT_BRAND] === true);
37
37
  }
38
+ /**
39
+ * Thrown for any non-2xx API response. `status` lets callers distinguish 401
40
+ * from 402 from 429 without matching on message text.
41
+ */
42
+ class NovenceError extends Error {
43
+ status;
44
+ constructor(message, status) {
45
+ super(message);
46
+ this.name = "NovenceError";
47
+ this.status = status;
48
+ }
49
+ }
50
+ exports.NovenceError = NovenceError;
38
51
  const MIME_BY_EXT = {
39
52
  ".html": "text/html; charset=utf-8",
40
53
  ".css": "text/css; charset=utf-8",
@@ -82,7 +95,7 @@ class Novence {
82
95
  });
83
96
  const data = (await res.json());
84
97
  if (!res.ok) {
85
- throw new Error(data.error ?? `HTTP ${res.status}`);
98
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
86
99
  }
87
100
  return data;
88
101
  }
@@ -124,7 +137,7 @@ class Novence {
124
137
  body: new Blob([copy], { type }),
125
138
  });
126
139
  if (!put.ok)
127
- throw new Error(`Upload failed: ${put.status}`);
140
+ throw new NovenceError(`Upload failed for ${path}`, put.status);
128
141
  return this.files.confirm(projectId, path, type);
129
142
  },
130
143
  /** Node-only: upload every allowed file under `dir` with root-relative site paths. */
@@ -248,7 +261,7 @@ async function bootstrapAccount(email, baseUrl) {
248
261
  });
249
262
  const data = (await res.json());
250
263
  if (!res.ok)
251
- throw new Error(data.error ?? `HTTP ${res.status}`);
264
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
252
265
  return data;
253
266
  }
254
267
  async function verifyEmail(email, code, baseUrl) {
@@ -259,7 +272,7 @@ async function verifyEmail(email, code, baseUrl) {
259
272
  });
260
273
  const data = (await res.json());
261
274
  if (!res.ok)
262
- throw new Error(data.error ?? `HTTP ${res.status}`);
275
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
263
276
  return data;
264
277
  }
265
278
  async function resendVerification(email, baseUrl) {
@@ -270,7 +283,7 @@ async function resendVerification(email, baseUrl) {
270
283
  });
271
284
  const data = (await res.json());
272
285
  if (!res.ok)
273
- throw new Error(data.error ?? `HTTP ${res.status}`);
286
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
274
287
  return data;
275
288
  }
276
289
  /** Recover a lost account API key with email OTP (after resend-verification). */
@@ -282,6 +295,6 @@ async function reissueApiKey(email, code, baseUrl) {
282
295
  });
283
296
  const data = (await res.json());
284
297
  if (!res.ok)
285
- throw new Error(data.error ?? `HTTP ${res.status}`);
298
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
286
299
  return data;
287
300
  }
@@ -2,6 +2,14 @@
2
2
  export declare const DEFAULT_BASE_URL = "https://api.novence.ai";
3
3
  /** True for a Novence client from any copy of this module. */
4
4
  export declare function isNovenceClient(value: unknown): value is Novence;
5
+ /**
6
+ * Thrown for any non-2xx API response. `status` lets callers distinguish 401
7
+ * from 402 from 429 without matching on message text.
8
+ */
9
+ export declare class NovenceError extends Error {
10
+ readonly status: number;
11
+ constructor(message: string, status: number);
12
+ }
5
13
  export interface NovenceOptions {
6
14
  apiKey: string;
7
15
  baseUrl?: string;
package/dist/esm/index.js CHANGED
@@ -27,6 +27,18 @@ export function isNovenceClient(value) {
27
27
  value !== null &&
28
28
  value[CLIENT_BRAND] === true);
29
29
  }
30
+ /**
31
+ * Thrown for any non-2xx API response. `status` lets callers distinguish 401
32
+ * from 402 from 429 without matching on message text.
33
+ */
34
+ export class NovenceError extends Error {
35
+ status;
36
+ constructor(message, status) {
37
+ super(message);
38
+ this.name = "NovenceError";
39
+ this.status = status;
40
+ }
41
+ }
30
42
  const MIME_BY_EXT = {
31
43
  ".html": "text/html; charset=utf-8",
32
44
  ".css": "text/css; charset=utf-8",
@@ -74,7 +86,7 @@ export class Novence {
74
86
  });
75
87
  const data = (await res.json());
76
88
  if (!res.ok) {
77
- throw new Error(data.error ?? `HTTP ${res.status}`);
89
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
78
90
  }
79
91
  return data;
80
92
  }
@@ -116,7 +128,7 @@ export class Novence {
116
128
  body: new Blob([copy], { type }),
117
129
  });
118
130
  if (!put.ok)
119
- throw new Error(`Upload failed: ${put.status}`);
131
+ throw new NovenceError(`Upload failed for ${path}`, put.status);
120
132
  return this.files.confirm(projectId, path, type);
121
133
  },
122
134
  /** Node-only: upload every allowed file under `dir` with root-relative site paths. */
@@ -239,7 +251,7 @@ export async function bootstrapAccount(email, baseUrl) {
239
251
  });
240
252
  const data = (await res.json());
241
253
  if (!res.ok)
242
- throw new Error(data.error ?? `HTTP ${res.status}`);
254
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
243
255
  return data;
244
256
  }
245
257
  export async function verifyEmail(email, code, baseUrl) {
@@ -250,7 +262,7 @@ export async function verifyEmail(email, code, baseUrl) {
250
262
  });
251
263
  const data = (await res.json());
252
264
  if (!res.ok)
253
- throw new Error(data.error ?? `HTTP ${res.status}`);
265
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
254
266
  return data;
255
267
  }
256
268
  export async function resendVerification(email, baseUrl) {
@@ -261,7 +273,7 @@ export async function resendVerification(email, baseUrl) {
261
273
  });
262
274
  const data = (await res.json());
263
275
  if (!res.ok)
264
- throw new Error(data.error ?? `HTTP ${res.status}`);
276
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
265
277
  return data;
266
278
  }
267
279
  /** Recover a lost account API key with email OTP (after resend-verification). */
@@ -273,6 +285,6 @@ export async function reissueApiKey(email, code, baseUrl) {
273
285
  });
274
286
  const data = (await res.json());
275
287
  if (!res.ok)
276
- throw new Error(data.error ?? `HTTP ${res.status}`);
288
+ throw new NovenceError(data.error ?? `HTTP ${res.status}`, res.status);
277
289
  return data;
278
290
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novence/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Official TypeScript SDK for Novence \u2014 static site hosting for AI agents. Create projects, upload files, run quality checks, deploy to the edge.",
5
5
  "license": "MIT",
6
6
  "type": "module",