@oneaddress/setup 2.0.1 → 2.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/dist/index.js +119 -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.0
|
|
859
|
+
var WIZARD_VERSION = true ? "2.1.0" : "?";
|
|
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.0
|
|
7993
|
+
var PKG_VERSION = true ? "2.1.0" : "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");
|
|
@@ -8230,6 +8230,55 @@ var COMMANDS2 = {
|
|
|
8230
8230
|
};
|
|
8231
8231
|
var serverProcess = null;
|
|
8232
8232
|
var serverOutput = "";
|
|
8233
|
+
var PASSTHROUGH_KEYS = [
|
|
8234
|
+
"PATH",
|
|
8235
|
+
// every runtime resolves binaries from PATH
|
|
8236
|
+
"HOME",
|
|
8237
|
+
// pip/npm/composer caches, ~/.m2 for Maven
|
|
8238
|
+
"USERPROFILE",
|
|
8239
|
+
// Windows equivalent of HOME
|
|
8240
|
+
"APPDATA",
|
|
8241
|
+
"LOCALAPPDATA",
|
|
8242
|
+
// Windows config dirs
|
|
8243
|
+
"SystemRoot",
|
|
8244
|
+
"SYSTEMROOT",
|
|
8245
|
+
"ComSpec",
|
|
8246
|
+
"WINDIR",
|
|
8247
|
+
// cmd.exe needs these
|
|
8248
|
+
"TEMP",
|
|
8249
|
+
"TMP",
|
|
8250
|
+
"TMPDIR",
|
|
8251
|
+
// tempdir resolution for tsx/uvicorn
|
|
8252
|
+
"LANG",
|
|
8253
|
+
"LC_ALL",
|
|
8254
|
+
"LC_CTYPE",
|
|
8255
|
+
// utf-8 in subprocess output
|
|
8256
|
+
"JAVA_HOME",
|
|
8257
|
+
"GOPATH",
|
|
8258
|
+
"GOROOT",
|
|
8259
|
+
// toolchain locations if set
|
|
8260
|
+
"PORT"
|
|
8261
|
+
// partner might override port via .env or shell
|
|
8262
|
+
];
|
|
8263
|
+
function buildChildEnv(secrets) {
|
|
8264
|
+
const childEnv = {};
|
|
8265
|
+
for (const key of PASSTHROUGH_KEYS) {
|
|
8266
|
+
const v2 = process.env[key];
|
|
8267
|
+
if (typeof v2 === "string") childEnv[key] = v2;
|
|
8268
|
+
}
|
|
8269
|
+
for (const [key, value] of Object.entries(secrets)) {
|
|
8270
|
+
if (value) childEnv[key] = value;
|
|
8271
|
+
}
|
|
8272
|
+
return childEnv;
|
|
8273
|
+
}
|
|
8274
|
+
function spawnReceiver(spec, outputDir, stdio, secrets) {
|
|
8275
|
+
const isWin = process.platform === "win32";
|
|
8276
|
+
return (0, import_node_child_process2.spawn)(
|
|
8277
|
+
isWin ? "cmd.exe" : spec.cmd,
|
|
8278
|
+
isWin ? ["/c", spec.cmd, ...spec.args] : spec.args,
|
|
8279
|
+
{ cwd: outputDir, stdio, detached: false, shell: false, env: buildChildEnv(secrets) }
|
|
8280
|
+
);
|
|
8281
|
+
}
|
|
8233
8282
|
function stopServer() {
|
|
8234
8283
|
if (serverProcess) {
|
|
8235
8284
|
try {
|
|
@@ -8280,56 +8329,7 @@ async function startServer(platform, outputDir, port = 3001, secrets = {}) {
|
|
|
8280
8329
|
}
|
|
8281
8330
|
serverOutput = "";
|
|
8282
8331
|
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
|
-
);
|
|
8332
|
+
serverProcess = spawnReceiver(spec, outputDir, ["ignore", "pipe", "pipe"], secrets);
|
|
8333
8333
|
serverProcess.stdout?.on("data", (d3) => {
|
|
8334
8334
|
serverOutput += d3.toString();
|
|
8335
8335
|
});
|
|
@@ -8343,6 +8343,49 @@ async function startServer(platform, outputDir, port = 3001, secrets = {}) {
|
|
|
8343
8343
|
const ok = await pollHealth(port, 15e3);
|
|
8344
8344
|
return { ok, output: serverOutput, manualCommand };
|
|
8345
8345
|
}
|
|
8346
|
+
async function waitForPortFree(port, timeoutMs = 8e3) {
|
|
8347
|
+
const deadline = Date.now() + timeoutMs;
|
|
8348
|
+
while (Date.now() < deadline) {
|
|
8349
|
+
try {
|
|
8350
|
+
await fetch(`http://localhost:${port}/health`, { signal: AbortSignal.timeout(1e3) });
|
|
8351
|
+
} catch {
|
|
8352
|
+
return true;
|
|
8353
|
+
}
|
|
8354
|
+
await new Promise((r2) => setTimeout(r2, 300));
|
|
8355
|
+
}
|
|
8356
|
+
return false;
|
|
8357
|
+
}
|
|
8358
|
+
async function handOverTerminal(platform, outputDir, port, secrets = {}) {
|
|
8359
|
+
const spec = COMMANDS2[platform];
|
|
8360
|
+
const manualCommand = spec ? `cd ${outputDir} && ${spec.cmd} ${spec.args.join(" ")}` : `cd ${outputDir} && npm start`;
|
|
8361
|
+
if (!spec) return { ok: false, reason: `No start command defined for platform: ${platform}`, manualCommand };
|
|
8362
|
+
stopServer();
|
|
8363
|
+
if (!await waitForPortFree(port)) {
|
|
8364
|
+
return {
|
|
8365
|
+
ok: false,
|
|
8366
|
+
reason: `Port ${port} is still in use, so the dashboard could not take it over.`,
|
|
8367
|
+
manualCommand
|
|
8368
|
+
};
|
|
8369
|
+
}
|
|
8370
|
+
if (process.stdin.isTTY) {
|
|
8371
|
+
try {
|
|
8372
|
+
process.stdin.setRawMode(false);
|
|
8373
|
+
} catch {
|
|
8374
|
+
}
|
|
8375
|
+
}
|
|
8376
|
+
process.stdin.pause();
|
|
8377
|
+
const child = spawnReceiver(spec, outputDir, "inherit", secrets);
|
|
8378
|
+
serverProcess = child;
|
|
8379
|
+
return new Promise((resolve2) => {
|
|
8380
|
+
child.once("error", (err) => {
|
|
8381
|
+
resolve2({ ok: false, reason: err.message, manualCommand });
|
|
8382
|
+
});
|
|
8383
|
+
child.once("exit", () => {
|
|
8384
|
+
serverProcess = null;
|
|
8385
|
+
resolve2({ ok: true, manualCommand });
|
|
8386
|
+
});
|
|
8387
|
+
});
|
|
8388
|
+
}
|
|
8346
8389
|
|
|
8347
8390
|
// src/tunnel.ts
|
|
8348
8391
|
var import_node_child_process3 = require("child_process");
|
|
@@ -9210,7 +9253,7 @@ tunnel needing this wizard to stay open. Re-run once that URL loads in a browser
|
|
|
9210
9253
|
].join("\n");
|
|
9211
9254
|
const nextSteps = [
|
|
9212
9255
|
"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.
|
|
9256
|
+
"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
9257
|
"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
9258
|
"4. Questions? partners.oneaddress.io or partners@oneaddress.io"
|
|
9216
9259
|
].join("\n\n");
|
|
@@ -9218,12 +9261,34 @@ tunnel needing this wizard to stay open. Re-run once that URL loads in a browser
|
|
|
9218
9261
|
Me(nextSteps, "Next steps");
|
|
9219
9262
|
Se("Setup complete! Welcome to the OneAddress Partner Network.");
|
|
9220
9263
|
if (serverRunning) {
|
|
9264
|
+
const openDashboard = await ye({
|
|
9265
|
+
message: "Open the receiver dashboard now?",
|
|
9266
|
+
initialValue: true
|
|
9267
|
+
});
|
|
9268
|
+
if (openDashboard === true) {
|
|
9269
|
+
const handover = await handOverTerminal(platform, outDir, SERVER_PORT, {
|
|
9270
|
+
WEBHOOK_SECRET: secret,
|
|
9271
|
+
PARTNER_ID: pid,
|
|
9272
|
+
PARTNER_PRIVATE_KEY_PEM: privateKey,
|
|
9273
|
+
VERIFIES_ACCOUNT_REFERENCE: String(verifiesAccountReference)
|
|
9274
|
+
});
|
|
9275
|
+
if (!handover.ok) {
|
|
9276
|
+
M2.warn(
|
|
9277
|
+
`${handover.reason ?? "The dashboard could not start."}
|
|
9278
|
+
Your receiver is set up and working. Start it yourself with:
|
|
9279
|
+
${handover.manualCommand}`
|
|
9280
|
+
);
|
|
9281
|
+
}
|
|
9282
|
+
runCleanup();
|
|
9283
|
+
process.exit(0);
|
|
9284
|
+
}
|
|
9221
9285
|
console.log("");
|
|
9222
9286
|
console.log(` ${DIM2}\u250C${"\u2500".repeat(BOX_WIDTH)}\u2510${R3}`);
|
|
9223
9287
|
for (const inner of [
|
|
9224
9288
|
` ${GRN}\u25C8${R3} ${CRM2}Server live${R3} ${MID2}on http://localhost:3001/webhook${R3}`,
|
|
9225
9289
|
` ${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}
|
|
9290
|
+
` ${MID2}Press Ctrl+C to stop the server and exit.${R3}`,
|
|
9291
|
+
` ${MID2}Run ${CRM2}npm start${R3} ${MID2}here any time for the dashboard.${R3}`
|
|
9227
9292
|
]) {
|
|
9228
9293
|
console.log(boxRow(inner, BOX_WIDTH, DIM2, R3));
|
|
9229
9294
|
}
|