@hendoi/henmesh 0.0.0-stage → 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 ADDED
@@ -0,0 +1,26 @@
1
+ LicenseRef-Proprietary
2
+
3
+ HENMESH JavaScript/TypeScript SDK (HM-JS-SDK-001)
4
+ Copyright (c) HENDOI TECHNOLOGIES PRIVATE LIMITED. All rights reserved.
5
+
6
+ This software and associated documentation files (the "Software") are the
7
+ proprietary property of HENDOI TECHNOLOGIES PRIVATE LIMITED ("HENDOI").
8
+
9
+ Permission to use the Software is granted only under a valid HENDOI
10
+ subscription, agreement, or other written authorization from HENDOI, and
11
+ solely for interacting with HENMESH / HENDOI services as permitted by that
12
+ authorization.
13
+
14
+ You may not copy, modify, merge, publish, distribute, sublicense, sell,
15
+ rent, lease, reverse engineer (except to the limited extent that applicable
16
+ law forbids this restriction), or otherwise exploit the Software except as
17
+ expressly allowed by HENDOI in writing.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL
22
+ HENDOI OR ITS LICENSORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
23
+ LIABILITY ARISING FROM USE OF THE SOFTWARE.
24
+
25
+ Contact: support@hendoi.com
26
+ Website: https://hendoi.com
package/README.md CHANGED
@@ -1,3 +1,70 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @hendoi/henmesh — JavaScript / TypeScript SDK (HM-JS-SDK-001)
2
+
3
+ Official headless HTTPS client for production [HENMESH](https://henmesh.hendoi.com). Same REST surface as the workspace.
4
+
5
+ **Version 0.1.0** · **Docs:** [https://api.hendoi.com/?doc=henmesh-overview](https://api.hendoi.com/?doc=henmesh-overview) · **npm:** [@hendoi/henmesh](https://www.npmjs.com/package/@hendoi/henmesh)
6
+
7
+ Header on every call: `X-Henmesh-Client: henmesh-js/0.1.0`.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @hendoi/henmesh
13
+ ```
14
+
15
+ Requires Node.js ≥ 18 (native `fetch`). License: **LicenseRef-Proprietary** (HENDOI).
16
+
17
+ ## Auth
18
+
19
+ Create a `hmk_…` key on HENMESH → **Developers**. Keys do not cross products.
20
+
21
+ ```bash
22
+ export HENMESH_API_KEY=hmk_…
23
+ # optional: export HENMESH_API_URL=https://henmesh.hendoi.com
24
+ # local: export HENMESH_API_URL=http://localhost:8005
25
+ ```
26
+
27
+ ## Example
28
+
29
+ ```ts
30
+ import { Client } from "@hendoi/henmesh";
31
+
32
+ const c = new Client(); // HENMESH_API_KEY
33
+ console.log(await c.usage());
34
+ console.log(await c.methods());
35
+
36
+ ```
37
+
38
+ ## What it cannot claim
39
+
40
+ Not HyperMesh / Pointwise certification meshing.
41
+
42
+ ## Client methods → REST
43
+
44
+ | Method | Route |
45
+ |---|---|
46
+ | `mesh2dAirfoil` / `mesh2dSection` | 2-D generate |
47
+ | `mesh2dQuality` / `mesh2dIndependence` | quality / GCI |
48
+ | `mesh3dWing` / `mesh3dQuality` | 3-D wing |
49
+ | `meshFsiMap` | FSI map |
50
+
51
+ Long solves often return a job; methods with `awaitJob=true` (default) poll `GET /api/v1/jobs/:id`.
52
+
53
+ ## Sister packages
54
+
55
+ | Python (PyPI) | JavaScript (npm) |
56
+ |---|---|
57
+ | `pip install henfoil` | `npm install @hendoi/henfoil` |
58
+ | `pip install hensynth` | `npm install @hendoi/hensynth` |
59
+ | `pip install henmesh` | `npm install @hendoi/henmesh` |
60
+ | `pip install henflow` | `npm install @hendoi/henflow` |
61
+ | `pip install henstruct` | `npm install @hendoi/henstruct` |
62
+
63
+ ## Links
64
+
65
+ | | |
66
+ |---|---|
67
+ | **npm** | https://www.npmjs.com/package/@hendoi/henmesh |
68
+ | Product | https://henmesh.hendoi.com |
69
+ | API docs | https://api.hendoi.com/?doc=henmesh-overview |
70
+ | Support | support@hendoi.com |
@@ -0,0 +1,49 @@
1
+ /** HTTP client for HENMESH /api/v1 — HM-JS-SDK-001 (0.1.0). */
2
+ export declare const CLIENT_VERSION = "0.1.0";
3
+ export type Json = Record<string, unknown>;
4
+ export declare class HenmeshError extends Error {
5
+ status: number;
6
+ body: unknown;
7
+ headers: Record<string, string>;
8
+ constructor(message: string, status?: number, body?: unknown, headers?: Record<string, string>);
9
+ get quotaExceeded(): boolean;
10
+ }
11
+ export type ClientOptions = {
12
+ apiKey?: string;
13
+ baseUrl?: string;
14
+ timeoutMs?: number;
15
+ pollIntervalMs?: number;
16
+ quotaWarnings?: boolean;
17
+ };
18
+ export declare class Client {
19
+ apiKey: string;
20
+ baseUrl: string;
21
+ timeoutMs: number;
22
+ pollIntervalMs: number;
23
+ quotaWarnings: boolean;
24
+ lastQuota: Record<string, unknown>;
25
+ private warned;
26
+ constructor(opts?: ClientOptions);
27
+ private headers;
28
+ private emitQuotaWarning;
29
+ private captureQuota;
30
+ private parse;
31
+ private get;
32
+ private post;
33
+ private awaitJob;
34
+ private maybeAwait;
35
+ usage(): Promise<Json>;
36
+ job(jobId: string): Promise<Json>;
37
+ cancelJob(jobId: string): Promise<Json>;
38
+ methods(): Promise<Json>;
39
+ projects(): Promise<Json>;
40
+ createProject(body: Record<string, unknown>): Promise<Json>;
41
+ mesh2dAirfoil(body: Record<string, unknown>, awaitJob?: boolean): Promise<Json>;
42
+ mesh2dSection(body: Record<string, unknown>, awaitJob?: boolean): Promise<Json>;
43
+ mesh2dQuality(body: Record<string, unknown>): Promise<Json>;
44
+ mesh2dIndependence(body: Record<string, unknown>, awaitJob?: boolean): Promise<Json>;
45
+ mesh3dWing(body: Record<string, unknown>, awaitJob?: boolean): Promise<Json>;
46
+ mesh3dQuality(body: Record<string, unknown>): Promise<Json>;
47
+ meshFsiMap(body: Record<string, unknown>, awaitJob?: boolean): Promise<Json>;
48
+ cadFormats(): Promise<Json>;
49
+ }
package/dist/client.js ADDED
@@ -0,0 +1,221 @@
1
+ /** HTTP client for HENMESH /api/v1 — HM-JS-SDK-001 (0.1.0). */
2
+ export const CLIENT_VERSION = "0.1.0";
3
+ const DEVELOPERS_HELP = "Create a hmk_… key: sign in at https://hendoi.com/login → open HENMESH → " +
4
+ "Developers (or Settings → API) → copy the key → export HENMESH_API_KEY=hmk_…";
5
+ export class HenmeshError extends Error {
6
+ status;
7
+ body;
8
+ headers;
9
+ constructor(message, status = 0, body = null, headers = {}) {
10
+ super(message);
11
+ this.name = "HenmeshError";
12
+ this.status = status;
13
+ this.body = body;
14
+ this.headers = headers;
15
+ }
16
+ get quotaExceeded() {
17
+ if (!this.body || typeof this.body !== "object")
18
+ return this.status === 403;
19
+ const b = this.body;
20
+ const meter = String(b.meter ?? "");
21
+ const code = String(b.code ?? b.error ?? "");
22
+ return (this.status === 403 &&
23
+ (meter === "apiRequests" || meter === "pythonSdk" || /QUOTA/i.test(code) || /quota/i.test(this.message)));
24
+ }
25
+ }
26
+ function env(name) {
27
+ return (typeof process !== "undefined" && process.env && process.env[name]) || "";
28
+ }
29
+ function headerInt(headers, ...names) {
30
+ for (const name of names) {
31
+ const v = headers.get(name);
32
+ if (v && v !== "unlimited") {
33
+ const n = Number.parseInt(v, 10);
34
+ if (!Number.isNaN(n))
35
+ return n;
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ function headerStr(headers, ...names) {
41
+ for (const name of names) {
42
+ const v = headers.get(name);
43
+ if (v)
44
+ return v;
45
+ }
46
+ return undefined;
47
+ }
48
+ function sleep(ms) {
49
+ return new Promise((r) => setTimeout(r, ms));
50
+ }
51
+ export class Client {
52
+ apiKey;
53
+ baseUrl;
54
+ timeoutMs;
55
+ pollIntervalMs;
56
+ quotaWarnings;
57
+ lastQuota = {};
58
+ warned = new Set();
59
+ constructor(opts = {}) {
60
+ this.apiKey = opts.apiKey || env("HENMESH_API_KEY") || "";
61
+ this.baseUrl = (opts.baseUrl || env("HENMESH_API_URL") || "https://henmesh.hendoi.com").replace(/\/$/, "");
62
+ this.timeoutMs = opts.timeoutMs ?? 120_000;
63
+ this.pollIntervalMs = opts.pollIntervalMs ?? 2_000;
64
+ this.quotaWarnings = opts.quotaWarnings ?? true;
65
+ if (!this.apiKey) {
66
+ throw new HenmeshError(`Missing API key. Set apiKey or HENMESH_API_KEY.\n${DEVELOPERS_HELP}\n` +
67
+ "There is no browser→terminal login yet — copy the key from Developers UI.");
68
+ }
69
+ }
70
+ headers() {
71
+ return {
72
+ Authorization: `Bearer ${this.apiKey}`,
73
+ "X-Henmesh-Key": this.apiKey,
74
+ "X-Henmesh-Client": `henmesh-js/${CLIENT_VERSION}`,
75
+ "User-Agent": `henmesh-js/${CLIENT_VERSION}`,
76
+ "Content-Type": "application/json",
77
+ Accept: "application/json",
78
+ };
79
+ }
80
+ emitQuotaWarning(text, key) {
81
+ if (!this.quotaWarnings || !text || this.warned.has(key))
82
+ return;
83
+ this.warned.add(key);
84
+ console.warn(`henmesh: ${text}`);
85
+ }
86
+ captureQuota(headers) {
87
+ const quota = {
88
+ apiLimit: headerInt(headers, "X-Henmesh-Api-Limit", "X-Api-Limit"),
89
+ apiRemaining: headerInt(headers, "X-Henmesh-Api-Remaining", "X-Api-Remaining"),
90
+ apiWarning: headerStr(headers, "X-Henmesh-Api-Warning", "X-Api-Warning"),
91
+ };
92
+ this.lastQuota = Object.fromEntries(Object.entries(quota).filter(([, v]) => v !== undefined));
93
+ if (quota.apiWarning)
94
+ this.emitQuotaWarning(String(quota.apiWarning), `api:${quota.apiRemaining}`);
95
+ }
96
+ async parse(res) {
97
+ this.captureQuota(res.headers);
98
+ let data = {};
99
+ const text = await res.text();
100
+ if (text) {
101
+ try {
102
+ data = JSON.parse(text);
103
+ }
104
+ catch {
105
+ data = { raw: text };
106
+ }
107
+ }
108
+ if (res.status >= 400) {
109
+ const body = data && typeof data === "object" ? data : {};
110
+ const msg = String(body.error ?? body.message ?? body.detail ?? "");
111
+ const err = new HenmeshError(msg || `HENMESH HTTP ${res.status}`, res.status, data, Object.fromEntries(res.headers.entries()));
112
+ if (err.quotaExceeded) {
113
+ this.emitQuotaWarning("Quota exceeded. Check plan limits or wait for monthly reset. See https://hendoi.com/pricing.", `exhausted:${res.status}`);
114
+ }
115
+ throw err;
116
+ }
117
+ if (!data || typeof data !== "object" || Array.isArray(data)) {
118
+ throw new HenmeshError("Expected JSON object response", res.status, data);
119
+ }
120
+ return data;
121
+ }
122
+ async get(path, params, timeoutMs) {
123
+ const url = new URL(`${this.baseUrl}${path}`);
124
+ if (params) {
125
+ for (const [k, v] of Object.entries(params)) {
126
+ if (v !== undefined && v !== null)
127
+ url.searchParams.set(k, String(v));
128
+ }
129
+ }
130
+ const ac = new AbortController();
131
+ const t = setTimeout(() => ac.abort(), timeoutMs ?? this.timeoutMs);
132
+ try {
133
+ const res = await fetch(url, { method: "GET", headers: this.headers(), signal: ac.signal });
134
+ return await this.parse(res);
135
+ }
136
+ finally {
137
+ clearTimeout(t);
138
+ }
139
+ }
140
+ async post(path, body, timeoutMs) {
141
+ const ac = new AbortController();
142
+ const t = setTimeout(() => ac.abort(), timeoutMs ?? this.timeoutMs);
143
+ try {
144
+ const res = await fetch(`${this.baseUrl}${path}`, {
145
+ method: "POST",
146
+ headers: this.headers(),
147
+ body: JSON.stringify(body),
148
+ signal: ac.signal,
149
+ });
150
+ return await this.parse(res);
151
+ }
152
+ finally {
153
+ clearTimeout(t);
154
+ }
155
+ }
156
+ async awaitJob(job, timeoutMs = 1_800_000) {
157
+ const jobId = String(job.jobId ?? job.id ?? "");
158
+ if (!jobId)
159
+ return job;
160
+ const deadline = Date.now() + timeoutMs;
161
+ while (Date.now() < deadline) {
162
+ const data = await this.job(jobId);
163
+ const status = String(data.status ?? data.state ?? "").toLowerCase();
164
+ if (["done", "completed", "succeeded", "success", "completed_with_warnings"].includes(status)) {
165
+ const result = data.result ?? data.payload ?? data;
166
+ return result && typeof result === "object" && !Array.isArray(result)
167
+ ? result
168
+ : { result, job: data };
169
+ }
170
+ if (["failed", "error", "cancelled"].includes(status)) {
171
+ throw new HenmeshError(`Job ${jobId} ${status}`, 0, data);
172
+ }
173
+ await sleep(this.pollIntervalMs);
174
+ }
175
+ throw new HenmeshError(`Job ${jobId} timed out after ${timeoutMs}ms`, 408, job);
176
+ }
177
+ async maybeAwait(out, awaitJob) {
178
+ if (awaitJob && (out.jobId || out.status === "queued"))
179
+ return this.awaitJob(out);
180
+ return out;
181
+ }
182
+ async usage() {
183
+ return this.get("/api/v1/usage");
184
+ }
185
+ async job(jobId) {
186
+ return this.get(`/api/v1/jobs/${jobId}`);
187
+ }
188
+ async cancelJob(jobId) {
189
+ return this.post(`/api/v1/jobs/${jobId}/cancel`, {});
190
+ }
191
+ async methods() { return this.get("/api/v1/mesh/methods"); }
192
+ async projects() { return this.get("/api/v1/projects"); }
193
+ async createProject(body) { return this.post("/api/v1/projects", body); }
194
+ async mesh2dAirfoil(body, awaitJob = true) {
195
+ const out = await this.post("/api/v1/mesh/2d/airfoil/generate", body, Math.max(this.timeoutMs, 600_000));
196
+ return this.maybeAwait(out, awaitJob);
197
+ }
198
+ async mesh2dSection(body, awaitJob = true) {
199
+ const out = await this.post("/api/v1/mesh/2d/section/generate", body, Math.max(this.timeoutMs, 600_000));
200
+ return this.maybeAwait(out, awaitJob);
201
+ }
202
+ async mesh2dQuality(body) {
203
+ return this.post("/api/v1/mesh/2d/quality", body);
204
+ }
205
+ async mesh2dIndependence(body, awaitJob = true) {
206
+ const out = await this.post("/api/v1/mesh/2d/independence", body, Math.max(this.timeoutMs, 900_000));
207
+ return this.maybeAwait(out, awaitJob);
208
+ }
209
+ async mesh3dWing(body, awaitJob = true) {
210
+ const out = await this.post("/api/v1/mesh/3d/wing/generate", body, Math.max(this.timeoutMs, 900_000));
211
+ return this.maybeAwait(out, awaitJob);
212
+ }
213
+ async mesh3dQuality(body) {
214
+ return this.post("/api/v1/mesh/3d/quality", body);
215
+ }
216
+ async meshFsiMap(body, awaitJob = true) {
217
+ const out = await this.post("/api/v1/mesh/fsi/map", body, Math.max(this.timeoutMs, 600_000));
218
+ return this.maybeAwait(out, awaitJob);
219
+ }
220
+ async cadFormats() { return this.get("/api/v1/cad/formats"); }
221
+ }
@@ -0,0 +1,2 @@
1
+ export { CLIENT_VERSION, Client, HenmeshError } from "./client.js";
2
+ export type { ClientOptions, Json } from "./client.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { CLIENT_VERSION, Client, HenmeshError } from "./client.js";
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
- {
2
- "name": "@hendoi/henmesh",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@hendoi/henmesh",
3
+ "version": "0.1.0",
4
+ "description": "Official HENMESH JavaScript/TypeScript SDK — 2-D/3-D mesh, quality, GCI, FSI map.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "LICENSE", "README.md"],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "test": "npm run build && node --test test/client.test.js",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "engines": { "node": ">=18" },
21
+ "keywords": ["henmesh", "hendoi", "aerospace", "sdk", "typescript"],
22
+ "author": "HENDOI TECHNOLOGIES PRIVATE LIMITED <support@hendoi.com>",
23
+ "license": "SEE LICENSE IN LICENSE",
24
+ "publishConfig": { "access": "public" },
25
+ "homepage": "https://henmesh.hendoi.com",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/hendoi/hendoi.git",
29
+ "directory": "henmesh-sdk/js"
30
+ },
31
+ "bugs": { "url": "https://hendoi.com/contact" },
32
+ "devDependencies": {
33
+ "typescript": "^5.6.0",
34
+ "@types/node": "^22.0.0"
35
+ }
36
+ }