@novence/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/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/index.d.ts +398 -0
- package/dist/index.js +231 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Novence
|
|
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,110 @@
|
|
|
1
|
+
# @novence/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for [Novence](https://novence.ai) — static site hosting built for AI agents and the developers who wire them up.
|
|
4
|
+
|
|
5
|
+
Create a project, upload HTML/CSS/JS, run quality checks, and publish to the edge at `https://{suffix}.novence.ai/`.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @novence/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node 18+ (uses the global `fetch`).
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Novence, bootstrapAccount, verifyEmail } from "@novence/sdk";
|
|
17
|
+
|
|
18
|
+
// 1. Get an API key (emails a 6-digit OTP)
|
|
19
|
+
const { apiKey } = await bootstrapAccount("you@example.com");
|
|
20
|
+
|
|
21
|
+
// 2. Verify to unlock full Free quotas
|
|
22
|
+
await verifyEmail("you@example.com", process.env.VERIFY_CODE!);
|
|
23
|
+
|
|
24
|
+
// 3. Ship a site
|
|
25
|
+
const client = new Novence({ apiKey });
|
|
26
|
+
const { project, url } = await client.projects.create({ name: "launch" });
|
|
27
|
+
await client.files.uploadDir(project.id, "./site");
|
|
28
|
+
await client.deployments.create(project.id);
|
|
29
|
+
|
|
30
|
+
console.log(url); // https://{suffix}.novence.ai
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Deploys are asynchronous. Poll `deployments.latest` until it settles:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const { deployment } = await client.deployments.latest(project.id);
|
|
37
|
+
|
|
38
|
+
if (deployment.status === "live") {
|
|
39
|
+
console.log(deployment.liveUrl);
|
|
40
|
+
} else if (deployment.status === "failed") {
|
|
41
|
+
console.error(deployment.errorMessage);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`deployment.status` is a union — `pending | queued | checking | promoting | live | failed`
|
|
46
|
+
— so the compiler catches typos in status comparisons.
|
|
47
|
+
|
|
48
|
+
### Checks
|
|
49
|
+
|
|
50
|
+
`deployment.checksResults` carries the quality gate. When `skipped` is true
|
|
51
|
+
(unverified accounts) `passed` is `null` — do not treat that as a pass:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const checks = deployment.checksResults;
|
|
55
|
+
if (checks?.skipped) {
|
|
56
|
+
console.log("checks did not run:", checks.reason);
|
|
57
|
+
} else if (checks?.passed === false) {
|
|
58
|
+
console.error("quality gate failed");
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Every method returns a typed response. `Project`, `Deployment`, `ChecksResults`,
|
|
63
|
+
`Form`, `Quotas`, `Analytics`, `StagingFile` and the rest are exported for your own
|
|
64
|
+
signatures:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import type { Project, Deployment, ChecksResults } from "@novence/sdk";
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Configuration
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const client = new Novence({
|
|
74
|
+
apiKey: process.env.NOVENCE_API_KEY!,
|
|
75
|
+
baseUrl: "https://api.novence.ai", // optional
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`baseUrl` defaults to `https://api.novence.ai`. Set `NOVENCE_BASE_URL` to point every
|
|
80
|
+
call at a different control plane — useful when running the API locally.
|
|
81
|
+
|
|
82
|
+
## API
|
|
83
|
+
|
|
84
|
+
| Namespace | Methods |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `client.projects` | `create` · `list` · `get` · `update` · `usage` · `analytics` |
|
|
87
|
+
| `client.files` | `uploadDir` · `uploadBuffer` · `getUploadUrl` · `getUploadUrlsBatch` · `confirm` · `confirmBatch` |
|
|
88
|
+
| `client.deployments` | `create` · `latest` |
|
|
89
|
+
| `client.domains` | `configure` · `status` |
|
|
90
|
+
| `client.forms` | `create` · `list` · `get` · `update` · `delete` · `listSubmissions` · `deleteSubmission` |
|
|
91
|
+
| `client.billing` | `quotas` · `checkout` · `portal` · `mppUpgrade` |
|
|
92
|
+
| `client.account` | `get` · `consoleKit` · `createSession` · `revokeSession` |
|
|
93
|
+
| `client.apiKeys` | `revoke` |
|
|
94
|
+
|
|
95
|
+
Standalone helpers for the pre-auth flow: `bootstrapAccount`, `verifyEmail`,
|
|
96
|
+
`resendVerification`, `reissueApiKey`.
|
|
97
|
+
|
|
98
|
+
## Security
|
|
99
|
+
|
|
100
|
+
`nv_` keys are server-side credentials. Never ship one in browser HTML, a URL, or a git commit. Read it from the environment.
|
|
101
|
+
|
|
102
|
+
## Docs
|
|
103
|
+
|
|
104
|
+
- [Documentation](https://novence.ai/docs) · [FAQ](https://novence.ai/faq) · [Pricing](https://novence.ai/pricing)
|
|
105
|
+
- [OpenAPI spec](https://novence.ai/openapi.yaml)
|
|
106
|
+
- [MCP server](https://novence.ai/mcp) — drive the same API from Claude, Cursor, or any MCP client
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public control plane. Override per-call, or globally with NOVENCE_BASE_URL
|
|
3
|
+
* (useful when pointing the SDK at a local API during development).
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_BASE_URL: string;
|
|
6
|
+
export interface NovenceOptions {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Narrowed lifecycle used by `deployment.phase`. */
|
|
11
|
+
export type DeploymentPhase = "queued" | "checking" | "promoting" | "live" | "failed";
|
|
12
|
+
/** Raw `deployment.status`; `pending` collapses to the `queued` phase. */
|
|
13
|
+
export type DeploymentStatus = DeploymentPhase | "pending";
|
|
14
|
+
export interface Project {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
/** Subdomain label for https://{suffix}.novence.ai/ */
|
|
18
|
+
suffix: string;
|
|
19
|
+
url: string;
|
|
20
|
+
/** Project lifecycle (active/deleted/suspended) — NOT deploy status. */
|
|
21
|
+
status: string;
|
|
22
|
+
/** @deprecated Use `suffix`. */
|
|
23
|
+
randomSuffix?: string;
|
|
24
|
+
description?: string | null;
|
|
25
|
+
customDomain?: string | null;
|
|
26
|
+
customDomainStatus?: string;
|
|
27
|
+
analyticsEnabled?: boolean;
|
|
28
|
+
createdAt?: string;
|
|
29
|
+
updatedAt?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Quality-gate payload. When `skipped` is true (unverified accounts), `passed`
|
|
33
|
+
* is null — do not treat that as checks having passed.
|
|
34
|
+
*/
|
|
35
|
+
export interface ChecksResults {
|
|
36
|
+
passed: boolean | null;
|
|
37
|
+
skipped?: boolean;
|
|
38
|
+
reason?: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
export interface Deployment {
|
|
42
|
+
id: string;
|
|
43
|
+
status: DeploymentStatus;
|
|
44
|
+
phase?: DeploymentPhase;
|
|
45
|
+
checksResults?: ChecksResults | null;
|
|
46
|
+
checksUrl?: string;
|
|
47
|
+
errorMessage?: string | null;
|
|
48
|
+
previewUrl?: string;
|
|
49
|
+
liveUrl?: string | null;
|
|
50
|
+
createdAt?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface UploadPresign {
|
|
53
|
+
path: string;
|
|
54
|
+
uploadUrl: string;
|
|
55
|
+
s3Key: string;
|
|
56
|
+
contentType: string;
|
|
57
|
+
expiresIn: number;
|
|
58
|
+
}
|
|
59
|
+
export interface StagingFile {
|
|
60
|
+
id: string;
|
|
61
|
+
projectId: string;
|
|
62
|
+
path: string;
|
|
63
|
+
s3Key: string;
|
|
64
|
+
sizeBytes: number;
|
|
65
|
+
contentType: string;
|
|
66
|
+
etag?: string | null;
|
|
67
|
+
}
|
|
68
|
+
export interface ConfirmBatchResponse {
|
|
69
|
+
files: StagingFile[];
|
|
70
|
+
/** Failed paths. Empty on full success. Retry these only. */
|
|
71
|
+
errors: Array<{
|
|
72
|
+
path: string;
|
|
73
|
+
error: string;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
export type FormFieldType = "text" | "email" | "tel" | "url" | "textarea" | "number" | "select" | "checkbox" | "hidden";
|
|
77
|
+
export interface FormField {
|
|
78
|
+
name: string;
|
|
79
|
+
type: FormFieldType;
|
|
80
|
+
required?: boolean;
|
|
81
|
+
label?: string;
|
|
82
|
+
options?: string[];
|
|
83
|
+
}
|
|
84
|
+
export interface FormSubmitUrls {
|
|
85
|
+
edgePath: string;
|
|
86
|
+
edgeUrl: string;
|
|
87
|
+
publicApiUrl: string;
|
|
88
|
+
}
|
|
89
|
+
export interface Form {
|
|
90
|
+
id: string;
|
|
91
|
+
projectId: string;
|
|
92
|
+
name: string;
|
|
93
|
+
slug: string;
|
|
94
|
+
fields: FormField[];
|
|
95
|
+
notifyEmail: string | null;
|
|
96
|
+
honeypotField: string;
|
|
97
|
+
status: string;
|
|
98
|
+
createdAt: string;
|
|
99
|
+
updatedAt: string;
|
|
100
|
+
submit: FormSubmitUrls;
|
|
101
|
+
}
|
|
102
|
+
export interface FormSubmission {
|
|
103
|
+
id: string;
|
|
104
|
+
payload: Record<string, unknown>;
|
|
105
|
+
createdAt: string;
|
|
106
|
+
}
|
|
107
|
+
export interface Quotas {
|
|
108
|
+
projects: number;
|
|
109
|
+
storageGb: number;
|
|
110
|
+
bandwidthGb: number;
|
|
111
|
+
deploysPerMonth: number;
|
|
112
|
+
/** Included check MINUTES per month (same unit as usage.check_minutes). */
|
|
113
|
+
checkRuns: number;
|
|
114
|
+
customDomains: number;
|
|
115
|
+
formSubmissionsPerMonth: number;
|
|
116
|
+
/** Extra collaborators per project (owner excluded). Free/unverified is 0. */
|
|
117
|
+
teamSeats: number;
|
|
118
|
+
}
|
|
119
|
+
export interface ProjectUsage {
|
|
120
|
+
/** Prefer storage_bytes over storage_gb for exact accounting. */
|
|
121
|
+
storage_bytes: number;
|
|
122
|
+
storage_gb: number;
|
|
123
|
+
deploys_count: number;
|
|
124
|
+
check_minutes: number;
|
|
125
|
+
custom_domains_count: number;
|
|
126
|
+
form_submissions: number;
|
|
127
|
+
bandwidth_gb: number;
|
|
128
|
+
}
|
|
129
|
+
export interface Analytics {
|
|
130
|
+
projectId: string;
|
|
131
|
+
suffix: string;
|
|
132
|
+
enabled?: boolean;
|
|
133
|
+
period: {
|
|
134
|
+
from: string;
|
|
135
|
+
to: string;
|
|
136
|
+
};
|
|
137
|
+
retentionDays: number;
|
|
138
|
+
unavailable?: boolean;
|
|
139
|
+
reason?: string;
|
|
140
|
+
totals: {
|
|
141
|
+
pageviews: number;
|
|
142
|
+
notFound: number;
|
|
143
|
+
};
|
|
144
|
+
days?: Array<{
|
|
145
|
+
day: string;
|
|
146
|
+
pageviews: number;
|
|
147
|
+
}>;
|
|
148
|
+
topPages?: Array<{
|
|
149
|
+
path: string;
|
|
150
|
+
pageviews: number;
|
|
151
|
+
}>;
|
|
152
|
+
}
|
|
153
|
+
/** Not schematised in openapi.yaml — known fields only. */
|
|
154
|
+
export interface DomainConfigureResult {
|
|
155
|
+
hosts?: string[];
|
|
156
|
+
canonicalHost?: string;
|
|
157
|
+
redirect?: boolean;
|
|
158
|
+
primaryPreference?: "www" | "apex" | null;
|
|
159
|
+
instructions?: {
|
|
160
|
+
summary?: string;
|
|
161
|
+
maxRecords?: number;
|
|
162
|
+
cnameTarget?: string;
|
|
163
|
+
records?: Array<Record<string, unknown>>;
|
|
164
|
+
[key: string]: unknown;
|
|
165
|
+
};
|
|
166
|
+
[key: string]: unknown;
|
|
167
|
+
}
|
|
168
|
+
/** Not schematised in openapi.yaml — known fields only. */
|
|
169
|
+
export interface DomainStatus {
|
|
170
|
+
hostname?: string | null;
|
|
171
|
+
status?: string;
|
|
172
|
+
[key: string]: unknown;
|
|
173
|
+
}
|
|
174
|
+
/** Not schematised in openapi.yaml — known fields only. */
|
|
175
|
+
export interface AccountSnapshot {
|
|
176
|
+
plan?: string;
|
|
177
|
+
emailVerified?: boolean;
|
|
178
|
+
quotas?: Quotas;
|
|
179
|
+
usage?: Record<string, number>;
|
|
180
|
+
projects?: Array<Record<string, unknown>>;
|
|
181
|
+
subscription?: {
|
|
182
|
+
id: string;
|
|
183
|
+
status: string;
|
|
184
|
+
currentPeriodEnd: string | null;
|
|
185
|
+
cancelAtPeriodEnd: boolean;
|
|
186
|
+
} | null;
|
|
187
|
+
[key: string]: unknown;
|
|
188
|
+
}
|
|
189
|
+
/** Not schematised in openapi.yaml — known fields only. */
|
|
190
|
+
export interface ConsoleKit {
|
|
191
|
+
htmlTemplate?: string;
|
|
192
|
+
snapshot?: AccountSnapshot;
|
|
193
|
+
[key: string]: unknown;
|
|
194
|
+
}
|
|
195
|
+
export declare class Novence {
|
|
196
|
+
readonly apiKey: string;
|
|
197
|
+
readonly baseUrl: string;
|
|
198
|
+
constructor(opts: NovenceOptions);
|
|
199
|
+
private request;
|
|
200
|
+
projects: {
|
|
201
|
+
create: (input: {
|
|
202
|
+
name: string;
|
|
203
|
+
description?: string;
|
|
204
|
+
}) => Promise<{
|
|
205
|
+
project: Project;
|
|
206
|
+
projectApiKey: string;
|
|
207
|
+
url: string;
|
|
208
|
+
}>;
|
|
209
|
+
list: () => Promise<{
|
|
210
|
+
projects: Project[];
|
|
211
|
+
}>;
|
|
212
|
+
get: (id: string) => Promise<{
|
|
213
|
+
project: Project;
|
|
214
|
+
}>;
|
|
215
|
+
update: (id: string, input: {
|
|
216
|
+
name?: string;
|
|
217
|
+
description?: string;
|
|
218
|
+
checkThresholds?: Record<string, unknown>;
|
|
219
|
+
analyticsEnabled?: boolean;
|
|
220
|
+
}) => Promise<{
|
|
221
|
+
project: Project;
|
|
222
|
+
}>;
|
|
223
|
+
usage: (id: string) => Promise<{
|
|
224
|
+
projectId: string;
|
|
225
|
+
period: {
|
|
226
|
+
start: string;
|
|
227
|
+
};
|
|
228
|
+
usage: ProjectUsage;
|
|
229
|
+
quotas: Quotas;
|
|
230
|
+
bandwidthMetering: "live" | "pending";
|
|
231
|
+
}>;
|
|
232
|
+
analytics: (id: string, range?: {
|
|
233
|
+
from?: string;
|
|
234
|
+
to?: string;
|
|
235
|
+
}) => Promise<Analytics>;
|
|
236
|
+
};
|
|
237
|
+
files: {
|
|
238
|
+
getUploadUrl: (projectId: string, path: string, contentType?: string) => Promise<UploadPresign>;
|
|
239
|
+
getUploadUrlsBatch: (projectId: string, files: Array<{
|
|
240
|
+
path: string;
|
|
241
|
+
contentType?: string;
|
|
242
|
+
}>) => Promise<{
|
|
243
|
+
uploads: UploadPresign[];
|
|
244
|
+
}>;
|
|
245
|
+
confirm: (projectId: string, path: string, contentType?: string) => Promise<{
|
|
246
|
+
file: StagingFile;
|
|
247
|
+
}>;
|
|
248
|
+
confirmBatch: (projectId: string, files: Array<{
|
|
249
|
+
path: string;
|
|
250
|
+
contentType?: string;
|
|
251
|
+
}>) => Promise<ConfirmBatchResponse>;
|
|
252
|
+
uploadBuffer: (projectId: string, path: string, contentType: string | undefined, body: ArrayBuffer | Uint8Array) => Promise<{
|
|
253
|
+
file: StagingFile;
|
|
254
|
+
}>;
|
|
255
|
+
/** Node-only: upload every allowed file under `dir` with root-relative site paths. */
|
|
256
|
+
uploadDir: (projectId: string, dir: string) => Promise<{
|
|
257
|
+
uploaded: string[];
|
|
258
|
+
}>;
|
|
259
|
+
};
|
|
260
|
+
deployments: {
|
|
261
|
+
create: (projectId: string, opts?: {
|
|
262
|
+
force?: boolean;
|
|
263
|
+
}) => Promise<{
|
|
264
|
+
deployment: Deployment;
|
|
265
|
+
}>;
|
|
266
|
+
latest: (projectId: string) => Promise<{
|
|
267
|
+
deployment: Deployment;
|
|
268
|
+
}>;
|
|
269
|
+
};
|
|
270
|
+
domains: {
|
|
271
|
+
configure: (projectId: string, hostname: string) => Promise<DomainConfigureResult>;
|
|
272
|
+
status: (projectId: string) => Promise<DomainStatus>;
|
|
273
|
+
};
|
|
274
|
+
forms: {
|
|
275
|
+
create: (projectId: string, input: {
|
|
276
|
+
name: string;
|
|
277
|
+
slug?: string;
|
|
278
|
+
fields?: Array<{
|
|
279
|
+
name: string;
|
|
280
|
+
type: "text" | "email" | "tel" | "url" | "textarea" | "number" | "select" | "checkbox" | "hidden";
|
|
281
|
+
required?: boolean;
|
|
282
|
+
label?: string;
|
|
283
|
+
options?: string[];
|
|
284
|
+
}>;
|
|
285
|
+
notifyEmail?: string | null;
|
|
286
|
+
honeypotField?: string;
|
|
287
|
+
}) => Promise<{
|
|
288
|
+
form: Form;
|
|
289
|
+
}>;
|
|
290
|
+
list: (projectId: string) => Promise<{
|
|
291
|
+
forms: Form[];
|
|
292
|
+
}>;
|
|
293
|
+
get: (projectId: string, formId: string) => Promise<{
|
|
294
|
+
form: Form;
|
|
295
|
+
}>;
|
|
296
|
+
update: (projectId: string, formId: string, input: {
|
|
297
|
+
name?: string;
|
|
298
|
+
slug?: string;
|
|
299
|
+
fields?: FormField[];
|
|
300
|
+
notifyEmail?: string | null;
|
|
301
|
+
honeypotField?: string;
|
|
302
|
+
status?: "active" | "disabled";
|
|
303
|
+
}) => Promise<{
|
|
304
|
+
form: Form;
|
|
305
|
+
}>;
|
|
306
|
+
delete: (projectId: string, formId: string) => Promise<{
|
|
307
|
+
deleted: boolean;
|
|
308
|
+
formId: string;
|
|
309
|
+
}>;
|
|
310
|
+
listSubmissions: (projectId: string, formId: string, opts?: {
|
|
311
|
+
limit?: number;
|
|
312
|
+
offset?: number;
|
|
313
|
+
}) => Promise<{
|
|
314
|
+
formId: string;
|
|
315
|
+
total: number;
|
|
316
|
+
submissions: FormSubmission[];
|
|
317
|
+
}>;
|
|
318
|
+
deleteSubmission: (projectId: string, formId: string, submissionId: string) => Promise<{
|
|
319
|
+
deleted: boolean;
|
|
320
|
+
submissionId: string;
|
|
321
|
+
}>;
|
|
322
|
+
};
|
|
323
|
+
billing: {
|
|
324
|
+
quotas: () => Promise<{
|
|
325
|
+
plan: string;
|
|
326
|
+
emailVerified?: boolean;
|
|
327
|
+
quotas: Quotas;
|
|
328
|
+
usage: Record<string, number>;
|
|
329
|
+
bandwidthMetering?: string;
|
|
330
|
+
}>;
|
|
331
|
+
checkout: (input: {
|
|
332
|
+
successUrl?: string;
|
|
333
|
+
cancelUrl?: string;
|
|
334
|
+
plan?: "pro" | "scale";
|
|
335
|
+
}) => Promise<{
|
|
336
|
+
url: string | null;
|
|
337
|
+
id: string;
|
|
338
|
+
}>;
|
|
339
|
+
portal: (input?: {
|
|
340
|
+
returnUrl?: string;
|
|
341
|
+
}) => Promise<{
|
|
342
|
+
url: string;
|
|
343
|
+
}>;
|
|
344
|
+
/**
|
|
345
|
+
* Start MPP SPT subscription (returns 402 challenge for agents).
|
|
346
|
+
* Completing Payment creates the same monthly Stripe subscription as Checkout.
|
|
347
|
+
*/
|
|
348
|
+
mppUpgrade: (input?: {
|
|
349
|
+
plan?: "pro" | "scale";
|
|
350
|
+
}) => Promise<{
|
|
351
|
+
status: number;
|
|
352
|
+
wwwAuthenticate: string | null;
|
|
353
|
+
data: any;
|
|
354
|
+
}>;
|
|
355
|
+
};
|
|
356
|
+
account: {
|
|
357
|
+
get: () => Promise<AccountSnapshot>;
|
|
358
|
+
consoleKit: () => Promise<ConsoleKit>;
|
|
359
|
+
createSession: () => Promise<{
|
|
360
|
+
token: string;
|
|
361
|
+
expiresAt: string;
|
|
362
|
+
scopes: string[];
|
|
363
|
+
}>;
|
|
364
|
+
revokeSession: () => Promise<{
|
|
365
|
+
revoked: boolean;
|
|
366
|
+
}>;
|
|
367
|
+
};
|
|
368
|
+
apiKeys: {
|
|
369
|
+
revoke: (id: string) => Promise<{
|
|
370
|
+
id: string;
|
|
371
|
+
revoked: boolean;
|
|
372
|
+
}>;
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
export declare function bootstrapAccount(email: string, baseUrl?: string): Promise<{
|
|
376
|
+
accountId: string;
|
|
377
|
+
apiKey: string;
|
|
378
|
+
plan: string;
|
|
379
|
+
emailVerificationRequired?: boolean;
|
|
380
|
+
verificationCode?: string;
|
|
381
|
+
}>;
|
|
382
|
+
export declare function verifyEmail(email: string, code: string, baseUrl?: string): Promise<{
|
|
383
|
+
accountId: string;
|
|
384
|
+
emailVerified: boolean;
|
|
385
|
+
alreadyVerified?: boolean;
|
|
386
|
+
}>;
|
|
387
|
+
export declare function resendVerification(email: string, baseUrl?: string): Promise<{
|
|
388
|
+
sent?: boolean;
|
|
389
|
+
emailVerificationRequired: boolean;
|
|
390
|
+
alreadyVerified?: boolean;
|
|
391
|
+
verificationCode?: string;
|
|
392
|
+
}>;
|
|
393
|
+
/** Recover a lost account API key with email OTP (after resend-verification). */
|
|
394
|
+
export declare function reissueApiKey(email: string, code: string, baseUrl?: string): Promise<{
|
|
395
|
+
accountId: string;
|
|
396
|
+
apiKey: string;
|
|
397
|
+
emailVerified: boolean;
|
|
398
|
+
}>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, join, relative } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Public control plane. Override per-call, or globally with NOVENCE_BASE_URL
|
|
5
|
+
* (useful when pointing the SDK at a local API during development).
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_BASE_URL = process.env.NOVENCE_BASE_URL?.replace(/\/$/, "") || "https://api.novence.ai";
|
|
8
|
+
const MIME_BY_EXT = {
|
|
9
|
+
".html": "text/html; charset=utf-8",
|
|
10
|
+
".css": "text/css; charset=utf-8",
|
|
11
|
+
".js": "text/javascript; charset=utf-8",
|
|
12
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
13
|
+
".map": "application/json",
|
|
14
|
+
".json": "application/json",
|
|
15
|
+
".svg": "image/svg+xml",
|
|
16
|
+
".png": "image/png",
|
|
17
|
+
".jpg": "image/jpeg",
|
|
18
|
+
".jpeg": "image/jpeg",
|
|
19
|
+
".gif": "image/gif",
|
|
20
|
+
".webp": "image/webp",
|
|
21
|
+
".ico": "image/x-icon",
|
|
22
|
+
".woff": "font/woff",
|
|
23
|
+
".woff2": "font/woff2",
|
|
24
|
+
".ttf": "font/ttf",
|
|
25
|
+
".txt": "text/plain; charset=utf-8",
|
|
26
|
+
".xml": "application/xml",
|
|
27
|
+
".webmanifest": "application/manifest+json",
|
|
28
|
+
".mp4": "video/mp4",
|
|
29
|
+
".webm": "video/webm",
|
|
30
|
+
".mov": "video/quicktime",
|
|
31
|
+
};
|
|
32
|
+
export class Novence {
|
|
33
|
+
apiKey;
|
|
34
|
+
baseUrl;
|
|
35
|
+
constructor(opts) {
|
|
36
|
+
this.apiKey = opts.apiKey;
|
|
37
|
+
this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
38
|
+
}
|
|
39
|
+
async request(method, path, body) {
|
|
40
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
41
|
+
method,
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
},
|
|
46
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
47
|
+
});
|
|
48
|
+
const data = (await res.json());
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
projects = {
|
|
55
|
+
create: (input) => this.request("POST", "/v1/projects", input),
|
|
56
|
+
list: () => this.request("GET", "/v1/projects"),
|
|
57
|
+
get: (id) => this.request("GET", `/v1/projects/${id}`),
|
|
58
|
+
update: (id, input) => this.request("PATCH", `/v1/projects/${id}`, input),
|
|
59
|
+
usage: (id) => this.request("GET", `/v1/projects/${id}/usage`),
|
|
60
|
+
analytics: (id, range) => {
|
|
61
|
+
const q = new URLSearchParams();
|
|
62
|
+
if (range?.from)
|
|
63
|
+
q.set("from", range.from);
|
|
64
|
+
if (range?.to)
|
|
65
|
+
q.set("to", range.to);
|
|
66
|
+
const qs = q.toString();
|
|
67
|
+
return this.request("GET", `/v1/projects/${id}/analytics${qs ? `?${qs}` : ""}`);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
files = {
|
|
71
|
+
getUploadUrl: (projectId, path, contentType) => this.request("POST", `/v1/projects/${projectId}/uploads`, {
|
|
72
|
+
path,
|
|
73
|
+
contentType,
|
|
74
|
+
}),
|
|
75
|
+
getUploadUrlsBatch: (projectId, files) => this.request("POST", `/v1/projects/${projectId}/uploads/batch`, { files }),
|
|
76
|
+
confirm: (projectId, path, contentType) => this.request("POST", `/v1/projects/${projectId}/uploads/confirm`, { path, contentType }),
|
|
77
|
+
confirmBatch: (projectId, files) => this.request("POST", `/v1/projects/${projectId}/uploads/confirm-batch`, { files }),
|
|
78
|
+
uploadBuffer: async (projectId, path, contentType, body) => {
|
|
79
|
+
const type = contentType || MIME_BY_EXT[extname(path).toLowerCase()] || "application/octet-stream";
|
|
80
|
+
const { uploadUrl } = await this.files.getUploadUrl(projectId, path, type);
|
|
81
|
+
const bytes = body instanceof ArrayBuffer
|
|
82
|
+
? new Uint8Array(body)
|
|
83
|
+
: new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
|
84
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
85
|
+
copy.set(bytes);
|
|
86
|
+
const put = await fetch(uploadUrl, {
|
|
87
|
+
method: "PUT",
|
|
88
|
+
headers: { "Content-Type": type },
|
|
89
|
+
body: new Blob([copy], { type }),
|
|
90
|
+
});
|
|
91
|
+
if (!put.ok)
|
|
92
|
+
throw new Error(`Upload failed: ${put.status}`);
|
|
93
|
+
return this.files.confirm(projectId, path, type);
|
|
94
|
+
},
|
|
95
|
+
/** Node-only: upload every allowed file under `dir` with root-relative site paths. */
|
|
96
|
+
uploadDir: async (projectId, dir) => {
|
|
97
|
+
function walk(current) {
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const name of readdirSync(current)) {
|
|
100
|
+
if (name.startsWith("."))
|
|
101
|
+
continue;
|
|
102
|
+
const full = join(current, name);
|
|
103
|
+
if (statSync(full).isDirectory())
|
|
104
|
+
out.push(...walk(full));
|
|
105
|
+
else
|
|
106
|
+
out.push(full);
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
const uploaded = [];
|
|
111
|
+
for (const full of walk(dir)) {
|
|
112
|
+
const rel = "/" + relative(dir, full).split("\\").join("/");
|
|
113
|
+
const contentType = MIME_BY_EXT[extname(full).toLowerCase()];
|
|
114
|
+
if (!contentType)
|
|
115
|
+
continue;
|
|
116
|
+
const body = readFileSync(full);
|
|
117
|
+
await this.files.uploadBuffer(projectId, rel, contentType, body);
|
|
118
|
+
uploaded.push(rel);
|
|
119
|
+
}
|
|
120
|
+
return { uploaded };
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
deployments = {
|
|
124
|
+
create: (projectId, opts) => this.request("POST", `/v1/projects/${projectId}/deployments`, opts ?? {}),
|
|
125
|
+
latest: (projectId) => this.request("GET", `/v1/projects/${projectId}/deployments/latest`),
|
|
126
|
+
};
|
|
127
|
+
domains = {
|
|
128
|
+
configure: (projectId, hostname) => this.request("POST", `/v1/projects/${projectId}/domains`, {
|
|
129
|
+
hostname,
|
|
130
|
+
}),
|
|
131
|
+
status: (projectId) => this.request("GET", `/v1/projects/${projectId}/domains`),
|
|
132
|
+
};
|
|
133
|
+
forms = {
|
|
134
|
+
create: (projectId, input) => this.request("POST", `/v1/projects/${projectId}/forms`, input),
|
|
135
|
+
list: (projectId) => this.request("GET", `/v1/projects/${projectId}/forms`),
|
|
136
|
+
get: (projectId, formId) => this.request("GET", `/v1/projects/${projectId}/forms/${formId}`),
|
|
137
|
+
update: (projectId, formId, input) => this.request("PATCH", `/v1/projects/${projectId}/forms/${formId}`, input),
|
|
138
|
+
delete: (projectId, formId) => this.request("DELETE", `/v1/projects/${projectId}/forms/${formId}`),
|
|
139
|
+
listSubmissions: (projectId, formId, opts) => {
|
|
140
|
+
const q = new URLSearchParams();
|
|
141
|
+
if (opts?.limit != null)
|
|
142
|
+
q.set("limit", String(opts.limit));
|
|
143
|
+
if (opts?.offset != null)
|
|
144
|
+
q.set("offset", String(opts.offset));
|
|
145
|
+
const qs = q.toString();
|
|
146
|
+
return this.request("GET", `/v1/projects/${projectId}/forms/${formId}/submissions${qs ? `?${qs}` : ""}`);
|
|
147
|
+
},
|
|
148
|
+
deleteSubmission: (projectId, formId, submissionId) => this.request("DELETE", `/v1/projects/${projectId}/forms/${formId}/submissions/${submissionId}`),
|
|
149
|
+
};
|
|
150
|
+
billing = {
|
|
151
|
+
quotas: () => this.request("GET", "/v1/billing/quotas"),
|
|
152
|
+
checkout: (input) => this.request("POST", "/v1/billing/checkout", input),
|
|
153
|
+
portal: (input = {}) => this.request("POST", "/v1/billing/portal", input),
|
|
154
|
+
/**
|
|
155
|
+
* Start MPP SPT subscription (returns 402 challenge for agents).
|
|
156
|
+
* Completing Payment creates the same monthly Stripe subscription as Checkout.
|
|
157
|
+
*/
|
|
158
|
+
mppUpgrade: async (input = {}) => {
|
|
159
|
+
const res = await fetch(`${this.baseUrl}/v1/billing/mpp`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: {
|
|
162
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
Accept: "application/json",
|
|
165
|
+
},
|
|
166
|
+
body: JSON.stringify({ plan: input.plan ?? "pro" }),
|
|
167
|
+
});
|
|
168
|
+
const www = res.headers.get("www-authenticate");
|
|
169
|
+
const data = await res.json().catch(() => ({}));
|
|
170
|
+
return {
|
|
171
|
+
status: res.status,
|
|
172
|
+
wwwAuthenticate: www,
|
|
173
|
+
data,
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
account = {
|
|
178
|
+
get: () => this.request("GET", "/v1/account"),
|
|
179
|
+
consoleKit: () => this.request("GET", "/v1/account/console-kit"),
|
|
180
|
+
createSession: () => this.request("POST", "/v1/account/sessions"),
|
|
181
|
+
revokeSession: () => this.request("DELETE", "/v1/account/sessions/current"),
|
|
182
|
+
};
|
|
183
|
+
apiKeys = {
|
|
184
|
+
revoke: (id) => this.request("DELETE", `/v1/api-keys/${id}`),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export async function bootstrapAccount(email, baseUrl = DEFAULT_BASE_URL) {
|
|
188
|
+
const res = await fetch(`${baseUrl.replace(/\/$/, "")}/v1/bootstrap`, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers: { "Content-Type": "application/json" },
|
|
191
|
+
body: JSON.stringify({ email }),
|
|
192
|
+
});
|
|
193
|
+
const data = (await res.json());
|
|
194
|
+
if (!res.ok)
|
|
195
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
196
|
+
return data;
|
|
197
|
+
}
|
|
198
|
+
export async function verifyEmail(email, code, baseUrl = DEFAULT_BASE_URL) {
|
|
199
|
+
const res = await fetch(`${baseUrl.replace(/\/$/, "")}/v1/auth/verify-email`, {
|
|
200
|
+
method: "POST",
|
|
201
|
+
headers: { "Content-Type": "application/json" },
|
|
202
|
+
body: JSON.stringify({ email, code }),
|
|
203
|
+
});
|
|
204
|
+
const data = (await res.json());
|
|
205
|
+
if (!res.ok)
|
|
206
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
207
|
+
return data;
|
|
208
|
+
}
|
|
209
|
+
export async function resendVerification(email, baseUrl = DEFAULT_BASE_URL) {
|
|
210
|
+
const res = await fetch(`${baseUrl.replace(/\/$/, "")}/v1/auth/resend-verification`, {
|
|
211
|
+
method: "POST",
|
|
212
|
+
headers: { "Content-Type": "application/json" },
|
|
213
|
+
body: JSON.stringify({ email }),
|
|
214
|
+
});
|
|
215
|
+
const data = (await res.json());
|
|
216
|
+
if (!res.ok)
|
|
217
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
/** Recover a lost account API key with email OTP (after resend-verification). */
|
|
221
|
+
export async function reissueApiKey(email, code, baseUrl = DEFAULT_BASE_URL) {
|
|
222
|
+
const res = await fetch(`${baseUrl.replace(/\/$/, "")}/v1/auth/reissue-key`, {
|
|
223
|
+
method: "POST",
|
|
224
|
+
headers: { "Content-Type": "application/json" },
|
|
225
|
+
body: JSON.stringify({ email, code }),
|
|
226
|
+
});
|
|
227
|
+
const data = (await res.json());
|
|
228
|
+
if (!res.ok)
|
|
229
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
230
|
+
return data;
|
|
231
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@novence/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official TypeScript SDK for Novence — static site hosting for AI agents. Create projects, upload files, run quality checks, deploy to the edge.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://novence.ai/docs",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://novence.ai/support"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"novence",
|
|
30
|
+
"static-site-hosting",
|
|
31
|
+
"deploy",
|
|
32
|
+
"hosting",
|
|
33
|
+
"edge",
|
|
34
|
+
"mcp",
|
|
35
|
+
"ai-agents",
|
|
36
|
+
"lighthouse",
|
|
37
|
+
"axe"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
|
+
"prepublishOnly": "pnpm run build"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22.10.2",
|
|
49
|
+
"typescript": "^5.7.2"
|
|
50
|
+
}
|
|
51
|
+
}
|