@runtimeai/qutonomous 1.0.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.
Files changed (2) hide show
  1. package/index.js +158 -0
  2. package/package.json +27 -0
package/index.js ADDED
@@ -0,0 +1,158 @@
1
+ // PQData Platform Node.js SDK
2
+ // R3-DP-004: Node.js SDK with real HTTP calls using built-in https/http.
3
+
4
+ "use strict";
5
+
6
+ const https = require("https");
7
+ const http = require("http");
8
+ const { URL } = require("url");
9
+
10
+ /**
11
+ * PQDataClient — Node.js client for the PQData Platform APIs.
12
+ *
13
+ * @example
14
+ * const { PQDataClient } = require("@pqdata/sdk");
15
+ * const client = new PQDataClient("http://localhost:8082", myToken);
16
+ * const secret = await client.getSecret("myapp/db-password");
17
+ */
18
+ class PQDataClient {
19
+ /**
20
+ * @param {string} baseUrl - Base URL of the PQData platform.
21
+ * @param {string} [token] - JWT bearer token for authentication.
22
+ */
23
+ constructor(baseUrl = "", token = "") {
24
+ if (!baseUrl) {
25
+ baseUrl = process.env.QUTONOMOUS_API_URL || process.env.PQDATA_API_URL || "http://localhost:8082";
26
+ }
27
+ this.baseUrl = baseUrl.replace(/\/$/, "");
28
+
29
+ if (!token) {
30
+ token = process.env.QUTONOMOUS_API_KEY || process.env.PQDATA_API_KEY || "";
31
+ }
32
+ this.token = token;
33
+ }
34
+
35
+ /**
36
+ * Perform an HTTP request.
37
+ * @private
38
+ */
39
+ _request(method, path, body) {
40
+ return new Promise((resolve, reject) => {
41
+ const url = new URL(this.baseUrl + path);
42
+ const isHttps = url.protocol === "https:";
43
+ const lib = isHttps ? https : http;
44
+
45
+ const bodyData = body !== undefined ? JSON.stringify(body) : undefined;
46
+
47
+ const options = {
48
+ hostname: url.hostname,
49
+ port: url.port || (isHttps ? 443 : 80),
50
+ path: url.pathname + url.search,
51
+ method: method,
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ Accept: "application/json",
55
+ },
56
+ };
57
+
58
+ if (this.token) {
59
+ options.headers["Authorization"] = `Bearer ${this.token}`;
60
+ }
61
+
62
+ if (bodyData) {
63
+ options.headers["Content-Length"] = Buffer.byteLength(bodyData);
64
+ }
65
+
66
+ const req = lib.request(options, (res) => {
67
+ let data = "";
68
+ res.on("data", (chunk) => { data += chunk; });
69
+ res.on("end", () => {
70
+ if (res.statusCode >= 400) {
71
+ let msg = `HTTP ${res.statusCode}`;
72
+ try {
73
+ const parsed = JSON.parse(data);
74
+ msg = parsed.error || parsed.message || msg;
75
+ } catch (_) {}
76
+ return reject(new Error(msg));
77
+ }
78
+ try {
79
+ resolve(JSON.parse(data));
80
+ } catch (_) {
81
+ resolve(data);
82
+ }
83
+ });
84
+ });
85
+
86
+ req.on("error", reject);
87
+
88
+ if (bodyData) {
89
+ req.write(bodyData);
90
+ }
91
+ req.end();
92
+ });
93
+ }
94
+
95
+ // ── Vault ─────────────────────────────────────────────────────────────────
96
+
97
+ /**
98
+ * Store a secret in QuantumVault.
99
+ * POST /vault/secrets
100
+ * @param {string} path
101
+ * @param {string} value
102
+ */
103
+ storeSecret(path, value) {
104
+ return this._request("POST", "/vault/secrets", { path, value });
105
+ }
106
+
107
+ /**
108
+ * Retrieve a secret from QuantumVault.
109
+ * GET /vault/secrets/{path}
110
+ * @param {string} path
111
+ */
112
+ getSecret(path) {
113
+ return this._request("GET", `/vault/secrets/${encodeURIComponent(path)}`);
114
+ }
115
+
116
+ // ── Sign ──────────────────────────────────────────────────────────────────
117
+
118
+ /**
119
+ * Sign a document using the pq-sign service.
120
+ * POST /api/v1/sign/document
121
+ * @param {object} data
122
+ */
123
+ signDocument(data) {
124
+ return this._request("POST", "/api/v1/sign/document", data);
125
+ }
126
+
127
+ // ── Tokenize ──────────────────────────────────────────────────────────────
128
+
129
+ /**
130
+ * Tokenize a value.
131
+ * POST /api/v1/tokenize
132
+ * @param {string} value
133
+ * @param {string} [format]
134
+ * @param {string} [keyRef]
135
+ */
136
+ tokenize(value, format = "", keyRef = "") {
137
+ const payload = { value };
138
+ if (format) payload.format = format;
139
+ if (keyRef) payload.key_ref = keyRef;
140
+ return this._request("POST", "/api/v1/tokenize", payload);
141
+ }
142
+
143
+ /**
144
+ * Reverse tokenization.
145
+ * POST /api/v1/detokenize
146
+ * @param {string} token
147
+ * @param {string} [format]
148
+ * @param {string} [keyRef]
149
+ */
150
+ detokenize(token, format = "", keyRef = "") {
151
+ const payload = { token };
152
+ if (format) payload.format_id = format;
153
+ if (keyRef) payload.key_ref = keyRef;
154
+ return this._request("POST", "/api/v1/detokenize", payload);
155
+ }
156
+ }
157
+
158
+ module.exports = { PQDataClient };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@runtimeai/qutonomous",
3
+ "version": "1.0.0",
4
+ "description": "Qutonomous Security Platform Node.js SDK — Post-Quantum Data Security",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node --test"
8
+ },
9
+ "keywords": [
10
+ "qutonomous",
11
+ "post-quantum",
12
+ "security",
13
+ "sdk",
14
+ "pqc"
15
+ ],
16
+ "license": "Apache-2.0",
17
+ "engines": {
18
+ "node": ">=18.0.0"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/runtimeai/qutonomous-sdk-nodejs.git"
26
+ }
27
+ }