@oneaddress/setup 2.0.1 → 2.1.1
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/dist/index.js +124 -54
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -856,7 +856,7 @@ var _R = ["\u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 \u2588\u2588"
|
|
|
856
856
|
var _S = [" \u2588\u2588\u2588\u2588\u2588\u2588", "\u2588\u2588 ", "\u2588\u2588 ", " \u2588\u2588\u2588\u2588\u2588 ", " \u2588\u2588", " \u2588\u2588", "\u2588\u2588\u2588\u2588\u2588\u2588 "];
|
|
857
857
|
var ONE_ROWS = Array.from({ length: 7 }, (_3, i) => [_O[i], _N[i], _E[i]].join(" "));
|
|
858
858
|
var ADDR_ROWS = Array.from({ length: 7 }, (_3, i) => [_A[i], _D2[i], _D2[i], _R[i], _E[i], _S[i], _S[i]].join(" "));
|
|
859
|
-
var WIZARD_VERSION = true ? "2.
|
|
859
|
+
var WIZARD_VERSION = true ? "2.1.1" : "?";
|
|
860
860
|
function printCompactHeader() {
|
|
861
861
|
const INNER = 42;
|
|
862
862
|
const TOP = fn("\u250C") + dm("\u2500".repeat(INNER)) + fn("\u2510");
|
|
@@ -7990,7 +7990,7 @@ async function scaffold(platform, outputDir, partnerId, webhookSecret, webhookUr
|
|
|
7990
7990
|
|
|
7991
7991
|
// src/register.ts
|
|
7992
7992
|
var import_node_crypto = require("crypto");
|
|
7993
|
-
var PKG_VERSION = true ? "2.
|
|
7993
|
+
var PKG_VERSION = true ? "2.1.1" : "dev";
|
|
7994
7994
|
var REGISTER_URL = "https://partners.oneaddress.io/api/partner/installs";
|
|
7995
7995
|
function hmacSha256(secret, message) {
|
|
7996
7996
|
return (0, import_node_crypto.createHmac)("sha256", secret).update(message).digest("hex");
|
|
@@ -8228,8 +8228,63 @@ var COMMANDS2 = {
|
|
|
8228
8228
|
"java-spring": { cmd: "mvn", args: ["spring-boot:run"] }
|
|
8229
8229
|
// no mvnw wrapper is scaffolded
|
|
8230
8230
|
};
|
|
8231
|
+
var DASHBOARD_COMMANDS = {
|
|
8232
|
+
"ts-node": { cmd: "npx", args: ["tsx", "src/index.ts"] }
|
|
8233
|
+
};
|
|
8234
|
+
function platformHasDashboard(platform) {
|
|
8235
|
+
return Boolean(DASHBOARD_COMMANDS[platform]);
|
|
8236
|
+
}
|
|
8231
8237
|
var serverProcess = null;
|
|
8232
8238
|
var serverOutput = "";
|
|
8239
|
+
var PASSTHROUGH_KEYS = [
|
|
8240
|
+
"PATH",
|
|
8241
|
+
// every runtime resolves binaries from PATH
|
|
8242
|
+
"HOME",
|
|
8243
|
+
// pip/npm/composer caches, ~/.m2 for Maven
|
|
8244
|
+
"USERPROFILE",
|
|
8245
|
+
// Windows equivalent of HOME
|
|
8246
|
+
"APPDATA",
|
|
8247
|
+
"LOCALAPPDATA",
|
|
8248
|
+
// Windows config dirs
|
|
8249
|
+
"SystemRoot",
|
|
8250
|
+
"SYSTEMROOT",
|
|
8251
|
+
"ComSpec",
|
|
8252
|
+
"WINDIR",
|
|
8253
|
+
// cmd.exe needs these
|
|
8254
|
+
"TEMP",
|
|
8255
|
+
"TMP",
|
|
8256
|
+
"TMPDIR",
|
|
8257
|
+
// tempdir resolution for tsx/uvicorn
|
|
8258
|
+
"LANG",
|
|
8259
|
+
"LC_ALL",
|
|
8260
|
+
"LC_CTYPE",
|
|
8261
|
+
// utf-8 in subprocess output
|
|
8262
|
+
"JAVA_HOME",
|
|
8263
|
+
"GOPATH",
|
|
8264
|
+
"GOROOT",
|
|
8265
|
+
// toolchain locations if set
|
|
8266
|
+
"PORT"
|
|
8267
|
+
// partner might override port via .env or shell
|
|
8268
|
+
];
|
|
8269
|
+
function buildChildEnv(secrets) {
|
|
8270
|
+
const childEnv = {};
|
|
8271
|
+
for (const key of PASSTHROUGH_KEYS) {
|
|
8272
|
+
const v2 = process.env[key];
|
|
8273
|
+
if (typeof v2 === "string") childEnv[key] = v2;
|
|
8274
|
+
}
|
|
8275
|
+
for (const [key, value] of Object.entries(secrets)) {
|
|
8276
|
+
if (value) childEnv[key] = value;
|
|
8277
|
+
}
|
|
8278
|
+
return childEnv;
|
|
8279
|
+
}
|
|
8280
|
+
function spawnReceiver(spec, outputDir, stdio, secrets) {
|
|
8281
|
+
const isWin = process.platform === "win32";
|
|
8282
|
+
return (0, import_node_child_process2.spawn)(
|
|
8283
|
+
isWin ? "cmd.exe" : spec.cmd,
|
|
8284
|
+
isWin ? ["/c", spec.cmd, ...spec.args] : spec.args,
|
|
8285
|
+
{ cwd: outputDir, stdio, detached: false, shell: false, env: buildChildEnv(secrets) }
|
|
8286
|
+
);
|
|
8287
|
+
}
|
|
8233
8288
|
function stopServer() {
|
|
8234
8289
|
if (serverProcess) {
|
|
8235
8290
|
try {
|
|
@@ -8280,56 +8335,7 @@ async function startServer(platform, outputDir, port = 3001, secrets = {}) {
|
|
|
8280
8335
|
}
|
|
8281
8336
|
serverOutput = "";
|
|
8282
8337
|
const manualCommand = `cd ${outputDir} && ${spec.cmd} ${spec.args.join(" ")}`;
|
|
8283
|
-
|
|
8284
|
-
"PATH",
|
|
8285
|
-
// every runtime resolves binaries from PATH
|
|
8286
|
-
"HOME",
|
|
8287
|
-
// pip/npm/composer caches, ~/.m2 for Maven
|
|
8288
|
-
"USERPROFILE",
|
|
8289
|
-
// Windows equivalent of HOME
|
|
8290
|
-
"APPDATA",
|
|
8291
|
-
"LOCALAPPDATA",
|
|
8292
|
-
// Windows config dirs
|
|
8293
|
-
"SystemRoot",
|
|
8294
|
-
"SYSTEMROOT",
|
|
8295
|
-
"ComSpec",
|
|
8296
|
-
"WINDIR",
|
|
8297
|
-
// cmd.exe needs these
|
|
8298
|
-
"TEMP",
|
|
8299
|
-
"TMP",
|
|
8300
|
-
"TMPDIR",
|
|
8301
|
-
// tempdir resolution for tsx/uvicorn
|
|
8302
|
-
"LANG",
|
|
8303
|
-
"LC_ALL",
|
|
8304
|
-
"LC_CTYPE",
|
|
8305
|
-
// utf-8 in subprocess output
|
|
8306
|
-
"JAVA_HOME",
|
|
8307
|
-
"GOPATH",
|
|
8308
|
-
"GOROOT",
|
|
8309
|
-
// toolchain locations if set
|
|
8310
|
-
"PORT"
|
|
8311
|
-
// partner might override port via .env or shell
|
|
8312
|
-
];
|
|
8313
|
-
const childEnv = {};
|
|
8314
|
-
for (const key of PASSTHROUGH_KEYS) {
|
|
8315
|
-
const v2 = process.env[key];
|
|
8316
|
-
if (typeof v2 === "string") childEnv[key] = v2;
|
|
8317
|
-
}
|
|
8318
|
-
for (const [key, value] of Object.entries(secrets)) {
|
|
8319
|
-
if (value) childEnv[key] = value;
|
|
8320
|
-
}
|
|
8321
|
-
const isWin = process.platform === "win32";
|
|
8322
|
-
serverProcess = (0, import_node_child_process2.spawn)(
|
|
8323
|
-
isWin ? "cmd.exe" : spec.cmd,
|
|
8324
|
-
isWin ? ["/c", spec.cmd, ...spec.args] : spec.args,
|
|
8325
|
-
{
|
|
8326
|
-
cwd: outputDir,
|
|
8327
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
8328
|
-
detached: false,
|
|
8329
|
-
shell: false,
|
|
8330
|
-
env: childEnv
|
|
8331
|
-
}
|
|
8332
|
-
);
|
|
8338
|
+
serverProcess = spawnReceiver(spec, outputDir, ["ignore", "pipe", "pipe"], secrets);
|
|
8333
8339
|
serverProcess.stdout?.on("data", (d3) => {
|
|
8334
8340
|
serverOutput += d3.toString();
|
|
8335
8341
|
});
|
|
@@ -8343,6 +8349,51 @@ async function startServer(platform, outputDir, port = 3001, secrets = {}) {
|
|
|
8343
8349
|
const ok = await pollHealth(port, 15e3);
|
|
8344
8350
|
return { ok, output: serverOutput, manualCommand };
|
|
8345
8351
|
}
|
|
8352
|
+
async function waitForPortFree(port, timeoutMs = 8e3) {
|
|
8353
|
+
const deadline = Date.now() + timeoutMs;
|
|
8354
|
+
while (Date.now() < deadline) {
|
|
8355
|
+
try {
|
|
8356
|
+
await fetch(`http://localhost:${port}/health`, { signal: AbortSignal.timeout(1e3) });
|
|
8357
|
+
} catch {
|
|
8358
|
+
return true;
|
|
8359
|
+
}
|
|
8360
|
+
await new Promise((r2) => setTimeout(r2, 300));
|
|
8361
|
+
}
|
|
8362
|
+
return false;
|
|
8363
|
+
}
|
|
8364
|
+
async function handOverTerminal(platform, outputDir, port, secrets = {}) {
|
|
8365
|
+
const spec = DASHBOARD_COMMANDS[platform];
|
|
8366
|
+
const manualCommand = `cd ${outputDir} && npm start`;
|
|
8367
|
+
if (!spec) {
|
|
8368
|
+
return { ok: false, reason: `The ${platform} scaffold has no dashboard.`, manualCommand };
|
|
8369
|
+
}
|
|
8370
|
+
stopServer();
|
|
8371
|
+
if (!await waitForPortFree(port)) {
|
|
8372
|
+
return {
|
|
8373
|
+
ok: false,
|
|
8374
|
+
reason: `Port ${port} is still in use, so the dashboard could not take it over.`,
|
|
8375
|
+
manualCommand
|
|
8376
|
+
};
|
|
8377
|
+
}
|
|
8378
|
+
if (process.stdin.isTTY) {
|
|
8379
|
+
try {
|
|
8380
|
+
process.stdin.setRawMode(false);
|
|
8381
|
+
} catch {
|
|
8382
|
+
}
|
|
8383
|
+
}
|
|
8384
|
+
process.stdin.pause();
|
|
8385
|
+
const child = spawnReceiver(spec, outputDir, "inherit", secrets);
|
|
8386
|
+
serverProcess = child;
|
|
8387
|
+
return new Promise((resolve2) => {
|
|
8388
|
+
child.once("error", (err) => {
|
|
8389
|
+
resolve2({ ok: false, reason: err.message, manualCommand });
|
|
8390
|
+
});
|
|
8391
|
+
child.once("exit", () => {
|
|
8392
|
+
serverProcess = null;
|
|
8393
|
+
resolve2({ ok: true, manualCommand });
|
|
8394
|
+
});
|
|
8395
|
+
});
|
|
8396
|
+
}
|
|
8346
8397
|
|
|
8347
8398
|
// src/tunnel.ts
|
|
8348
8399
|
var import_node_child_process3 = require("child_process");
|
|
@@ -9210,7 +9261,7 @@ tunnel needing this wizard to stay open. Re-run once that URL loads in a browser
|
|
|
9210
9261
|
].join("\n");
|
|
9211
9262
|
const nextSteps = [
|
|
9212
9263
|
"1. Trigger a live event: update your address at oneaddress.io\n \u2192 src/store.ts will save it to data.db automatically",
|
|
9213
|
-
"2.
|
|
9264
|
+
"2. Watch it arrive: the dashboard shows each dispatch and the old-to-new change.\n Set a passphrase there and data.db is encrypted at rest, which also means\n DB Browser for SQLite will show you ciphertext rather than addresses.\n Skip the passphrase and the file stays readable in any SQLite viewer.",
|
|
9214
9265
|
"3. For production: swap src/store.ts for your real database (Postgres, MySQL, etc.)\n then deploy and update the webhook URL in the portal",
|
|
9215
9266
|
"4. Questions? partners.oneaddress.io or partners@oneaddress.io"
|
|
9216
9267
|
].join("\n\n");
|
|
@@ -9218,12 +9269,31 @@ tunnel needing this wizard to stay open. Re-run once that URL loads in a browser
|
|
|
9218
9269
|
Me(nextSteps, "Next steps");
|
|
9219
9270
|
Se("Setup complete! Welcome to the OneAddress Partner Network.");
|
|
9220
9271
|
if (serverRunning) {
|
|
9272
|
+
const openDashboard = platformHasDashboard(platform) ? await ye({ message: "Open the receiver dashboard now?", initialValue: true }) : false;
|
|
9273
|
+
if (openDashboard === true) {
|
|
9274
|
+
const handover = await handOverTerminal(platform, outDir, SERVER_PORT, {
|
|
9275
|
+
WEBHOOK_SECRET: secret,
|
|
9276
|
+
PARTNER_ID: pid,
|
|
9277
|
+
PARTNER_PRIVATE_KEY_PEM: privateKey,
|
|
9278
|
+
VERIFIES_ACCOUNT_REFERENCE: String(verifiesAccountReference)
|
|
9279
|
+
});
|
|
9280
|
+
if (!handover.ok) {
|
|
9281
|
+
M2.warn(
|
|
9282
|
+
`${handover.reason ?? "The dashboard could not start."}
|
|
9283
|
+
Your receiver is set up and working. Start it yourself with:
|
|
9284
|
+
${handover.manualCommand}`
|
|
9285
|
+
);
|
|
9286
|
+
}
|
|
9287
|
+
runCleanup();
|
|
9288
|
+
process.exit(0);
|
|
9289
|
+
}
|
|
9221
9290
|
console.log("");
|
|
9222
9291
|
console.log(` ${DIM2}\u250C${"\u2500".repeat(BOX_WIDTH)}\u2510${R3}`);
|
|
9223
9292
|
for (const inner of [
|
|
9224
9293
|
` ${GRN}\u25C8${R3} ${CRM2}Server live${R3} ${MID2}on http://localhost:3001/webhook${R3}`,
|
|
9225
9294
|
` ${AMB2}\u25C8${R3} ${MID2}Edit ${CRM2}src/store.ts${R3} ${MID2}to wire your database${R3}`,
|
|
9226
|
-
` ${MID2}Press Ctrl+C to stop the server and exit.${R3}
|
|
9295
|
+
` ${MID2}Press Ctrl+C to stop the server and exit.${R3}`,
|
|
9296
|
+
...platformHasDashboard(platform) ? [` ${MID2}Run ${CRM2}npm start${R3} ${MID2}here any time for the dashboard.${R3}`] : []
|
|
9227
9297
|
]) {
|
|
9228
9298
|
console.log(boxRow(inner, BOX_WIDTH, DIM2, R3));
|
|
9229
9299
|
}
|