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