@condorinst/mobile-bridge 0.21.0 → 0.22.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/AGENTS.md +10 -1
- package/CHANGELOG.md +23 -0
- package/README.md +22 -6
- package/contract/bridge-contract.json +4 -3
- package/dist/cli.cjs +514 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +510 -11
- package/dist/cli.js.map +1 -1
- package/docs/agent-guide.md +3 -3
- package/docs/bridge-contract.md +1 -1
- package/docs/client-guide.md +7 -5
- package/docs/device-testing.md +52 -22
- package/docs/pilot-onboarding.md +10 -6
- package/examples/minimal-home/package.json +1 -1
- package/llms-full.txt +84 -39
- package/llms.txt +15 -15
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var import_node_fs4 = require("fs");
|
|
6
|
+
var import_node_path4 = require("path");
|
|
7
|
+
|
|
8
|
+
// package.json
|
|
9
|
+
var version = "0.22.0";
|
|
10
|
+
|
|
11
|
+
// src/canvas-admin/command.ts
|
|
12
|
+
var import_node_crypto2 = require("crypto");
|
|
13
|
+
var import_node_fs2 = require("fs");
|
|
14
|
+
var import_node_path2 = require("path");
|
|
7
15
|
|
|
8
16
|
// src/cli-core.ts
|
|
9
17
|
var import_node_crypto = require("crypto");
|
|
@@ -349,12 +357,15 @@ var USAGE = `condor-mobile-bridge \u2014 tooling for Condor Canvas client bundle
|
|
|
349
357
|
Usage:
|
|
350
358
|
npx condor-mobile-bridge build -i <html> [-o <zip>]
|
|
351
359
|
npx condor-mobile-bridge validate -i <zip|html> [--strict]
|
|
360
|
+
npx condor-mobile-bridge canvas publish|list|revoke ... (see: canvas --help)
|
|
352
361
|
npx condor-mobile-bridge dev -i <html|zip|dir> [--scenario <name>] [--native-version <v|null>] [--port <n>]
|
|
353
362
|
|
|
354
363
|
Commands:
|
|
355
364
|
build Inline a dist/index.html into a self-contained .zip.
|
|
356
365
|
validate Check a bundle against every rule the Canvas app enforces, plus
|
|
357
366
|
the APIs the sandbox and the CSP block at runtime.
|
|
367
|
+
canvas Publish, list and revoke the bundle of your company in the
|
|
368
|
+
Condor Canvas app (interactive login). See: canvas --help.
|
|
358
369
|
dev Serve the bundle in a browser harness that behaves like the app:
|
|
359
370
|
same sandbox, shell and policy, and a simulated native side.
|
|
360
371
|
Re-reads the input on every reload. Scenarios: default,
|
|
@@ -373,10 +384,477 @@ Options:
|
|
|
373
384
|
reach the native side.
|
|
374
385
|
-h, --help Show this help.`;
|
|
375
386
|
|
|
387
|
+
// src/canvas-admin/client.ts
|
|
388
|
+
var CANVAS_ADMIN_API = {
|
|
389
|
+
prod: "https://api.sleepdiary.condorapps.net",
|
|
390
|
+
dev: "https://dev.sleepdiary.condorapps.net"
|
|
391
|
+
};
|
|
392
|
+
var CanvasAdminError = class extends Error {
|
|
393
|
+
constructor(message, status, reason) {
|
|
394
|
+
super(message);
|
|
395
|
+
this.status = status;
|
|
396
|
+
this.reason = reason;
|
|
397
|
+
this.name = "CanvasAdminError";
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
function tokenFrom(headers) {
|
|
401
|
+
const values = typeof headers.getSetCookie === "function" ? headers.getSetCookie() : [headers.get("set-cookie") ?? ""];
|
|
402
|
+
for (const value of values) {
|
|
403
|
+
const match = /(?:^|[,;\s])token=([^;,\s]*)/.exec(value);
|
|
404
|
+
if (match?.[1]) return match[1];
|
|
405
|
+
}
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
async function reasonFrom(response) {
|
|
409
|
+
try {
|
|
410
|
+
const body = await response.json();
|
|
411
|
+
for (const key of ["error", "message", "description", "code"]) {
|
|
412
|
+
const value = body[key];
|
|
413
|
+
if (typeof value === "string" && value) return value;
|
|
414
|
+
}
|
|
415
|
+
} catch {
|
|
416
|
+
}
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
var CanvasAdminClient = class {
|
|
420
|
+
constructor(opts) {
|
|
421
|
+
this.token = null;
|
|
422
|
+
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
423
|
+
this.userAgent = opts.userAgent;
|
|
424
|
+
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
425
|
+
this.timeoutMs = opts.timeoutMs ?? 6e4;
|
|
426
|
+
}
|
|
427
|
+
async request(path, init = {}) {
|
|
428
|
+
const headers = new Headers(init.headers);
|
|
429
|
+
headers.set("user-agent", this.userAgent);
|
|
430
|
+
headers.set("accept", "application/json");
|
|
431
|
+
if (this.token) headers.set("cookie", `token=${this.token}`);
|
|
432
|
+
try {
|
|
433
|
+
return await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
434
|
+
...init,
|
|
435
|
+
headers,
|
|
436
|
+
redirect: "manual",
|
|
437
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
438
|
+
});
|
|
439
|
+
} catch (err) {
|
|
440
|
+
throw new CanvasAdminError(
|
|
441
|
+
`Could not reach ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,
|
|
442
|
+
0,
|
|
443
|
+
null
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async fail(response, what) {
|
|
448
|
+
const reason = await reasonFrom(response);
|
|
449
|
+
throw new CanvasAdminError(
|
|
450
|
+
`${what} failed (HTTP ${response.status})${reason ? `: ${reason}` : ""}`,
|
|
451
|
+
response.status,
|
|
452
|
+
reason
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Logs in. Resolves `{ needsCode: true }` when the company requires a
|
|
457
|
+
* two-factor code (sent by e-mail): call {@link verifyCode} next.
|
|
458
|
+
*/
|
|
459
|
+
async login(creds) {
|
|
460
|
+
const response = await this.request("/auth/login", {
|
|
461
|
+
method: "POST",
|
|
462
|
+
headers: { "content-type": "application/json" },
|
|
463
|
+
body: JSON.stringify({
|
|
464
|
+
company_id: creds.companyId,
|
|
465
|
+
user_id: creds.userId,
|
|
466
|
+
password: creds.password
|
|
467
|
+
})
|
|
468
|
+
});
|
|
469
|
+
if (!response.ok) await this.fail(response, "Login");
|
|
470
|
+
const token = tokenFrom(response.headers);
|
|
471
|
+
if (!token) throw new CanvasAdminError("Login answered without a session cookie", 200, null);
|
|
472
|
+
this.token = token;
|
|
473
|
+
const body = await response.json().catch(() => ({}));
|
|
474
|
+
return { needsCode: body.completed_auth_flow === false };
|
|
475
|
+
}
|
|
476
|
+
/** Sends the two-factor (or recovery) code; the server swaps the session cookie. */
|
|
477
|
+
async verifyCode(code) {
|
|
478
|
+
const response = await this.request("/auth/verify_2fa", {
|
|
479
|
+
method: "POST",
|
|
480
|
+
headers: { "content-type": "application/json" },
|
|
481
|
+
body: JSON.stringify({ otp_code: code })
|
|
482
|
+
});
|
|
483
|
+
if (!response.ok) await this.fail(response, "Two-factor verification");
|
|
484
|
+
const token = tokenFrom(response.headers);
|
|
485
|
+
if (token) this.token = token;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Publishes a bundle. **It goes live at once** for every user of the
|
|
489
|
+
* company: there is no draft. A version can be published only once per
|
|
490
|
+
* company (HTTP 409).
|
|
491
|
+
*/
|
|
492
|
+
async publish(input) {
|
|
493
|
+
const form = new FormData();
|
|
494
|
+
form.set(
|
|
495
|
+
"bundle",
|
|
496
|
+
new Blob([input.zipBytes], { type: "application/zip" }),
|
|
497
|
+
"bundle.zip"
|
|
498
|
+
);
|
|
499
|
+
form.set("version", input.version);
|
|
500
|
+
if (input.companyId !== void 0) form.set("company_id", String(input.companyId));
|
|
501
|
+
if (input.minAppVersion) form.set("min_app_version", input.minAppVersion);
|
|
502
|
+
const response = await this.request("/v2/condor_canvas/bundles", {
|
|
503
|
+
method: "POST",
|
|
504
|
+
body: form
|
|
505
|
+
});
|
|
506
|
+
if (!response.ok) await this.fail(response, "Publish");
|
|
507
|
+
const body = await response.json();
|
|
508
|
+
return body.data;
|
|
509
|
+
}
|
|
510
|
+
/** Lists the bundles of a company (a manager always sees their own). */
|
|
511
|
+
async list(companyId) {
|
|
512
|
+
const query = companyId === void 0 ? "" : `?company_id=${companyId}`;
|
|
513
|
+
const response = await this.request(`/v2/condor_canvas/bundles${query}`);
|
|
514
|
+
if (!response.ok) await this.fail(response, "List");
|
|
515
|
+
const body = await response.json();
|
|
516
|
+
return body.data;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Revokes a bundle. Without `fallbackVersion`, revoking the current bundle
|
|
520
|
+
* leaves the company with none: the app shows its default screen.
|
|
521
|
+
*/
|
|
522
|
+
async revoke(bundleId, fallbackVersion) {
|
|
523
|
+
const response = await this.request(`/v2/condor_canvas/bundles/${bundleId}/revoke`, {
|
|
524
|
+
method: "POST",
|
|
525
|
+
headers: { "content-type": "application/json" },
|
|
526
|
+
body: JSON.stringify(fallbackVersion ? { fallbackVersion } : {})
|
|
527
|
+
});
|
|
528
|
+
if (!response.ok) await this.fail(response, "Revoke");
|
|
529
|
+
const body = await response.json();
|
|
530
|
+
return body.data;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/canvas-admin/command.ts
|
|
535
|
+
var CANVAS_USAGE = `condor-mobile-bridge canvas \u2014 publish a bundle to the Condor Canvas app.
|
|
536
|
+
|
|
537
|
+
Usage:
|
|
538
|
+
npx condor-mobile-bridge canvas publish <dist/index.html|dir|bundle.zip> --version <v> [options]
|
|
539
|
+
npx condor-mobile-bridge canvas list [options]
|
|
540
|
+
npx condor-mobile-bridge canvas revoke <bundleId> [--fallback-version <v>] [options]
|
|
541
|
+
|
|
542
|
+
Publishing goes LIVE AT ONCE for every user of the company \u2014 there is no draft.
|
|
543
|
+
Use a test company, and see docs/device-testing.md.
|
|
544
|
+
|
|
545
|
+
Options:
|
|
546
|
+
--company <id> Company id, as in the Condor web login (or CONDOR_CANVAS_COMPANY).
|
|
547
|
+
--user <id> Your user id, as in the Condor web login (or CONDOR_CANVAS_USER).
|
|
548
|
+
Both are asked when not given.
|
|
549
|
+
--version <v> publish: bundle version, unique per company.
|
|
550
|
+
--min-app-version <v> publish: minimum app build that may load it.
|
|
551
|
+
--fallback-version <v> revoke: VERSION to serve instead (the version column of
|
|
552
|
+
canvas list, e.g. 0.0.8 \u2014 not the id).
|
|
553
|
+
--env prod|dev API environment (default: prod). dev is for Condor staff.
|
|
554
|
+
--base-url <url> Override the API URL.
|
|
555
|
+
--yes Do not ask for confirmation.
|
|
556
|
+
--json Print results as JSON.
|
|
557
|
+
|
|
558
|
+
Your password (and the two-factor code, when your company uses one) is asked
|
|
559
|
+
interactively, without echo, and never stored. There is no non-interactive login.`;
|
|
560
|
+
var intOrUndefined = (value) => {
|
|
561
|
+
if (value === void 0) return void 0;
|
|
562
|
+
const n = Number(value);
|
|
563
|
+
return Number.isInteger(n) && n > 0 ? n : Number.NaN;
|
|
564
|
+
};
|
|
565
|
+
function parseCanvasArgs(argv, env = {}) {
|
|
566
|
+
const [action, ...rest] = argv;
|
|
567
|
+
if (action !== "publish" && action !== "list" && action !== "revoke") {
|
|
568
|
+
return { error: `Unknown canvas command "${action ?? ""}". Use publish, list or revoke.` };
|
|
569
|
+
}
|
|
570
|
+
const args = {
|
|
571
|
+
action,
|
|
572
|
+
env: "prod",
|
|
573
|
+
yes: false,
|
|
574
|
+
json: false,
|
|
575
|
+
companyId: intOrUndefined(env.CONDOR_CANVAS_COMPANY),
|
|
576
|
+
userId: intOrUndefined(env.CONDOR_CANVAS_USER)
|
|
577
|
+
};
|
|
578
|
+
const positional = [];
|
|
579
|
+
for (let i = 0; i < rest.length; i++) {
|
|
580
|
+
const token = rest[i] ?? "";
|
|
581
|
+
const next = () => rest[++i];
|
|
582
|
+
switch (token) {
|
|
583
|
+
case "--env": {
|
|
584
|
+
const env2 = next();
|
|
585
|
+
if (env2 !== "prod" && env2 !== "dev") return { error: "--env must be prod or dev." };
|
|
586
|
+
args.env = env2;
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
case "--base-url":
|
|
590
|
+
args.baseUrl = next();
|
|
591
|
+
break;
|
|
592
|
+
case "--company":
|
|
593
|
+
args.companyId = intOrUndefined(next());
|
|
594
|
+
break;
|
|
595
|
+
case "--user":
|
|
596
|
+
args.userId = intOrUndefined(next());
|
|
597
|
+
break;
|
|
598
|
+
case "--version":
|
|
599
|
+
args.version = next();
|
|
600
|
+
break;
|
|
601
|
+
case "--min-app-version":
|
|
602
|
+
args.minAppVersion = next();
|
|
603
|
+
break;
|
|
604
|
+
case "--fallback-version":
|
|
605
|
+
args.fallbackVersion = next();
|
|
606
|
+
break;
|
|
607
|
+
case "--yes":
|
|
608
|
+
args.yes = true;
|
|
609
|
+
break;
|
|
610
|
+
case "--json":
|
|
611
|
+
args.json = true;
|
|
612
|
+
break;
|
|
613
|
+
case "--password":
|
|
614
|
+
return {
|
|
615
|
+
error: "There is no --password flag: the password is only read from the prompt."
|
|
616
|
+
};
|
|
617
|
+
default:
|
|
618
|
+
if (token.startsWith("-")) return { error: `Unknown option ${token}.` };
|
|
619
|
+
positional.push(token);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (Number.isNaN(args.companyId) || Number.isNaN(args.userId)) {
|
|
623
|
+
return {
|
|
624
|
+
error: "--company and --user (or CONDOR_CANVAS_COMPANY / CONDOR_CANVAS_USER) take a positive integer id."
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
if (action === "publish") {
|
|
628
|
+
args.input = positional[0];
|
|
629
|
+
if (!args.input)
|
|
630
|
+
return { error: "canvas publish needs the bundle: dist/index.html, a dir or a .zip." };
|
|
631
|
+
if (!args.version) return { error: "canvas publish needs --version." };
|
|
632
|
+
}
|
|
633
|
+
if (action === "revoke") {
|
|
634
|
+
args.bundleId = intOrUndefined(positional[0]);
|
|
635
|
+
if (!args.bundleId || Number.isNaN(args.bundleId)) {
|
|
636
|
+
return { error: "canvas revoke needs the bundle id (see canvas list)." };
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return args;
|
|
640
|
+
}
|
|
641
|
+
function loadZip(input) {
|
|
642
|
+
const path = (0, import_node_path2.resolve)(input);
|
|
643
|
+
if (!(0, import_node_fs2.existsSync)(path)) throw new Error(`${input}: not found.`);
|
|
644
|
+
let zipBytes;
|
|
645
|
+
if ((0, import_node_path2.extname)(path).toLowerCase() === ".zip") {
|
|
646
|
+
zipBytes = new Uint8Array((0, import_node_fs2.readFileSync)(path));
|
|
647
|
+
} else {
|
|
648
|
+
const html = (0, import_node_fs2.statSync)(path).isDirectory() ? (0, import_node_path2.join)(path, "index.html") : path;
|
|
649
|
+
zipBytes = buildBundle(html).zipBytes;
|
|
650
|
+
}
|
|
651
|
+
return { zipBytes, findings: validateZipBytes(zipBytes).findings };
|
|
652
|
+
}
|
|
653
|
+
async function askId(io, label, value) {
|
|
654
|
+
if (value !== void 0) return value;
|
|
655
|
+
const answer = (await io.ask(`${label}: `)).trim();
|
|
656
|
+
const n = Number(answer);
|
|
657
|
+
if (!Number.isInteger(n) || n <= 0) throw new Error(`${label} must be a positive integer.`);
|
|
658
|
+
return n;
|
|
659
|
+
}
|
|
660
|
+
async function confirm(io, args, question2) {
|
|
661
|
+
if (args.yes) return true;
|
|
662
|
+
const answer = (await io.ask(`${question2} [y/N] `)).trim().toLowerCase();
|
|
663
|
+
return answer === "y" || answer === "yes";
|
|
664
|
+
}
|
|
665
|
+
async function logIn(io, client, companyId, userId) {
|
|
666
|
+
io.print("");
|
|
667
|
+
io.print("Log in with your Condor web account (typing is hidden; press Enter when done).");
|
|
668
|
+
let password = "";
|
|
669
|
+
for (let attempt = 0; attempt < 3 && !password.trim(); attempt++) {
|
|
670
|
+
if (attempt > 0) io.printError("The password cannot be empty.");
|
|
671
|
+
password = await io.askSecret("Password: ");
|
|
672
|
+
}
|
|
673
|
+
if (!password.trim()) throw new Error("No password given. Nothing was sent.");
|
|
674
|
+
const { needsCode } = await client.login({ companyId, userId, password });
|
|
675
|
+
if (!needsCode) return;
|
|
676
|
+
io.print(
|
|
677
|
+
"Your company uses two-factor login: a code was sent to your e-mail. Type it below (hidden)."
|
|
678
|
+
);
|
|
679
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
680
|
+
const code = (await io.askSecret("Code (or a recovery code): ")).trim();
|
|
681
|
+
try {
|
|
682
|
+
await client.verifyCode(code);
|
|
683
|
+
return;
|
|
684
|
+
} catch (err) {
|
|
685
|
+
if (attempt === 2 || !(err instanceof CanvasAdminError) || err.status !== 400) throw err;
|
|
686
|
+
io.printError("That code was not accepted. Try once more.");
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function describeError(err) {
|
|
691
|
+
if (!(err instanceof CanvasAdminError)) return err instanceof Error ? err.message : String(err);
|
|
692
|
+
if (err.status === 400 && /fallback/i.test(err.reason ?? "")) {
|
|
693
|
+
return `${err.message}
|
|
694
|
+
--fallback-version takes the VERSION column of \`canvas list\` (e.g. 0.0.8), not the id.`;
|
|
695
|
+
}
|
|
696
|
+
switch (err.status) {
|
|
697
|
+
case 401:
|
|
698
|
+
return `${err.message}
|
|
699
|
+
Check the company id, user id and password.`;
|
|
700
|
+
case 403:
|
|
701
|
+
return `${err.message}
|
|
702
|
+
Your user cannot do this for that company: publishing needs a manager of the company.`;
|
|
703
|
+
case 409:
|
|
704
|
+
return `${err.message}
|
|
705
|
+
This version was already published for the company. Use a new --version.`;
|
|
706
|
+
case 413:
|
|
707
|
+
return `${err.message}
|
|
708
|
+
The .zip is over 2 MB.`;
|
|
709
|
+
default:
|
|
710
|
+
return err.message;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function table(rows) {
|
|
714
|
+
if (rows.length === 0) return ["No bundle published for this company."];
|
|
715
|
+
return [
|
|
716
|
+
"id version current revoked published_at min_app",
|
|
717
|
+
...rows.map(
|
|
718
|
+
(r) => `${String(r.id).padEnd(8)}${r.version.padEnd(15)}${(r.is_current ? "yes" : "").padEnd(9)}${(r.revoked ? "yes" : "").padEnd(9)}${(r.published_at ?? "").padEnd(28)}${r.min_app_version ?? ""}`
|
|
719
|
+
)
|
|
720
|
+
];
|
|
721
|
+
}
|
|
722
|
+
async function runCanvas(args, io, deps) {
|
|
723
|
+
const baseUrl = args.baseUrl ?? CANVAS_ADMIN_API[args.env];
|
|
724
|
+
const envLabel = args.baseUrl ? `custom (${baseUrl})` : `${args.env.toUpperCase()} (${baseUrl})`;
|
|
725
|
+
try {
|
|
726
|
+
let zip;
|
|
727
|
+
if (args.action === "publish") {
|
|
728
|
+
zip = loadZip(args.input ?? "");
|
|
729
|
+
const errors = zip.findings.filter((f) => f.severity === "error");
|
|
730
|
+
for (const f of zip.findings) {
|
|
731
|
+
(f.severity === "error" ? io.printError : io.print)(
|
|
732
|
+
`${f.severity.toUpperCase()} [${f.rule}] ${f.message}`
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
if (errors.length > 0) {
|
|
736
|
+
io.printError("The app would reject this bundle. Nothing was sent.");
|
|
737
|
+
return 1;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
if (!io.interactive) {
|
|
741
|
+
io.printError(
|
|
742
|
+
"canvas needs an interactive terminal: the password is only read from a prompt."
|
|
743
|
+
);
|
|
744
|
+
return 1;
|
|
745
|
+
}
|
|
746
|
+
const companyId = await askId(io, "Company id", args.companyId);
|
|
747
|
+
const userId = await askId(io, "User id", args.userId);
|
|
748
|
+
if (args.action === "publish" && zip) {
|
|
749
|
+
const hash = `sha256-${(0, import_node_crypto2.createHash)("sha256").update(zip.zipBytes).digest("hex")}`;
|
|
750
|
+
io.print("");
|
|
751
|
+
io.print(`Environment: ${envLabel}`);
|
|
752
|
+
io.print(`Company: ${companyId}`);
|
|
753
|
+
io.print(
|
|
754
|
+
`Version: ${args.version}${args.minAppVersion ? ` (min app ${args.minAppVersion})` : ""}`
|
|
755
|
+
);
|
|
756
|
+
io.print(`Bundle: ${zip.zipBytes.length} bytes, ${hash}`);
|
|
757
|
+
io.print("It goes LIVE AT ONCE for every user of this company.");
|
|
758
|
+
if (!await confirm(io, args, "Publish?")) {
|
|
759
|
+
io.print("Cancelled. Nothing was sent.");
|
|
760
|
+
return 1;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (args.action === "revoke") {
|
|
764
|
+
io.print("");
|
|
765
|
+
io.print(`Environment: ${envLabel}`);
|
|
766
|
+
io.print(`Revoke bundle ${args.bundleId} of company ${companyId}.`);
|
|
767
|
+
io.print(
|
|
768
|
+
args.fallbackVersion ? `The app switches to version ${args.fallbackVersion} (a version, not an id).` : "Without --fallback-version, revoking the current bundle leaves the company with none: the app shows its default screen."
|
|
769
|
+
);
|
|
770
|
+
if (!await confirm(io, args, "Revoke?")) {
|
|
771
|
+
io.print("Cancelled. Nothing was sent.");
|
|
772
|
+
return 1;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const client = new CanvasAdminClient({
|
|
776
|
+
baseUrl,
|
|
777
|
+
userAgent: deps.userAgent,
|
|
778
|
+
fetchImpl: deps.fetchImpl
|
|
779
|
+
});
|
|
780
|
+
await logIn(io, client, companyId, userId);
|
|
781
|
+
if (args.action === "publish" && zip) {
|
|
782
|
+
const record = await client.publish({
|
|
783
|
+
zipBytes: zip.zipBytes,
|
|
784
|
+
version: args.version ?? "",
|
|
785
|
+
companyId,
|
|
786
|
+
minAppVersion: args.minAppVersion
|
|
787
|
+
});
|
|
788
|
+
if (args.json) io.print(JSON.stringify(record));
|
|
789
|
+
else {
|
|
790
|
+
io.print(
|
|
791
|
+
`Published version ${record.version} (id ${record.id}) \u2014 current: ${record.is_current}.`
|
|
792
|
+
);
|
|
793
|
+
io.print(`bundleHash: ${record.bundle_hash}`);
|
|
794
|
+
io.print("Apps of this company load it the next time they come to the foreground.");
|
|
795
|
+
}
|
|
796
|
+
return 0;
|
|
797
|
+
}
|
|
798
|
+
if (args.action === "list") {
|
|
799
|
+
const rows = await client.list(companyId);
|
|
800
|
+
if (args.json) io.print(JSON.stringify(rows));
|
|
801
|
+
else for (const line of table(rows)) io.print(line);
|
|
802
|
+
return 0;
|
|
803
|
+
}
|
|
804
|
+
const result = await client.revoke(args.bundleId ?? 0, args.fallbackVersion);
|
|
805
|
+
io.print(args.json ? JSON.stringify(result) : `Revoked. ${JSON.stringify(result)}`);
|
|
806
|
+
return 0;
|
|
807
|
+
} catch (err) {
|
|
808
|
+
io.printError(describeError(err));
|
|
809
|
+
return 1;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// src/canvas-admin/tty.ts
|
|
814
|
+
var import_node_readline = require("readline");
|
|
815
|
+
var rl = null;
|
|
816
|
+
var mutedPrompt = null;
|
|
817
|
+
function reader() {
|
|
818
|
+
if (rl) return rl;
|
|
819
|
+
rl = (0, import_node_readline.createInterface)({ input: process.stdin, output: process.stderr, terminal: true });
|
|
820
|
+
const out = rl;
|
|
821
|
+
const write = out._writeToOutput.bind(rl);
|
|
822
|
+
out._writeToOutput = (s) => {
|
|
823
|
+
if (mutedPrompt === null || s.includes(mutedPrompt)) write(s);
|
|
824
|
+
};
|
|
825
|
+
return rl;
|
|
826
|
+
}
|
|
827
|
+
function question(prompt, secret) {
|
|
828
|
+
const r = reader();
|
|
829
|
+
return new Promise((resolve5) => {
|
|
830
|
+
mutedPrompt = secret ? prompt : null;
|
|
831
|
+
r.question(prompt, (answer) => {
|
|
832
|
+
if (secret) {
|
|
833
|
+
mutedPrompt = null;
|
|
834
|
+
process.stderr.write("\n");
|
|
835
|
+
}
|
|
836
|
+
resolve5(answer);
|
|
837
|
+
});
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
function terminalIo() {
|
|
841
|
+
return {
|
|
842
|
+
interactive: Boolean(process.stdin.isTTY),
|
|
843
|
+
ask: (q) => question(q, false),
|
|
844
|
+
askSecret: (q) => question(q, true),
|
|
845
|
+
print: (line) => console.log(line),
|
|
846
|
+
printError: (line) => console.error(line)
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function closeTerminalIo() {
|
|
850
|
+
rl?.close();
|
|
851
|
+
rl = null;
|
|
852
|
+
}
|
|
853
|
+
|
|
376
854
|
// src/cli-dev.ts
|
|
377
|
-
var
|
|
855
|
+
var import_node_fs3 = require("fs");
|
|
378
856
|
var import_node_http = require("http");
|
|
379
|
-
var
|
|
857
|
+
var import_node_path3 = require("path");
|
|
380
858
|
var import_node_url = require("url");
|
|
381
859
|
var import_fflate2 = require("fflate");
|
|
382
860
|
|
|
@@ -616,12 +1094,12 @@ var SCENARIOS = {
|
|
|
616
1094
|
// src/cli-dev.ts
|
|
617
1095
|
var import_meta = {};
|
|
618
1096
|
function readClientHtml(input) {
|
|
619
|
-
const path = (0,
|
|
620
|
-
if ((0,
|
|
621
|
-
return inlineHtml((0,
|
|
1097
|
+
const path = (0, import_node_path3.resolve)(input);
|
|
1098
|
+
if ((0, import_node_fs3.existsSync)(path) && (0, import_node_fs3.statSync)(path).isDirectory()) {
|
|
1099
|
+
return inlineHtml((0, import_node_path3.join)(path, "index.html"));
|
|
622
1100
|
}
|
|
623
|
-
if ((0,
|
|
624
|
-
const files = (0, import_fflate2.unzipSync)(new Uint8Array((0,
|
|
1101
|
+
if ((0, import_node_path3.extname)(path).toLowerCase() === ".zip") {
|
|
1102
|
+
const files = (0, import_fflate2.unzipSync)(new Uint8Array((0, import_node_fs3.readFileSync)(path)));
|
|
625
1103
|
const entry = files["index.html"];
|
|
626
1104
|
if (!entry) throw new Error(`${input}: no index.html at the root of the zip.`);
|
|
627
1105
|
return (0, import_fflate2.strFromU8)(entry);
|
|
@@ -692,8 +1170,8 @@ function harnessPage(scenario, nativeVersion) {
|
|
|
692
1170
|
</html>`;
|
|
693
1171
|
}
|
|
694
1172
|
function harnessScriptPath() {
|
|
695
|
-
const here = typeof __dirname !== "undefined" ? __dirname : (0,
|
|
696
|
-
return (0,
|
|
1173
|
+
const here = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path3.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
1174
|
+
return (0, import_node_path3.join)(here, "dev-harness.global.js");
|
|
697
1175
|
}
|
|
698
1176
|
function startDevServer(opts) {
|
|
699
1177
|
if (!(opts.scenario in SCENARIOS)) {
|
|
@@ -718,7 +1196,7 @@ function startDevServer(opts) {
|
|
|
718
1196
|
"content-type": "text/javascript; charset=utf-8",
|
|
719
1197
|
"cache-control": "no-store"
|
|
720
1198
|
});
|
|
721
|
-
res.end((0,
|
|
1199
|
+
res.end((0, import_node_fs3.readFileSync)(harnessScriptPath()));
|
|
722
1200
|
return;
|
|
723
1201
|
}
|
|
724
1202
|
if (url.pathname === "/") {
|
|
@@ -763,9 +1241,9 @@ function runDev(input, scenario, port, nativeVersion) {
|
|
|
763
1241
|
}
|
|
764
1242
|
function runBuild(htmlPath, outPath, maxBytes) {
|
|
765
1243
|
const result = buildBundle(htmlPath, maxBytes);
|
|
766
|
-
const resolvedOut = (0,
|
|
767
|
-
(0,
|
|
768
|
-
(0,
|
|
1244
|
+
const resolvedOut = (0, import_node_path4.resolve)(outPath);
|
|
1245
|
+
(0, import_node_fs4.mkdirSync)((0, import_node_path4.dirname)(resolvedOut), { recursive: true });
|
|
1246
|
+
(0, import_node_fs4.writeFileSync)(resolvedOut, result.zipBytes);
|
|
769
1247
|
const kb = (Buffer.byteLength(result.html) / 1024).toFixed(1);
|
|
770
1248
|
console.log(`Built ${outPath}`);
|
|
771
1249
|
console.log(` entry: index.html (${kb} KB self-contained)`);
|
|
@@ -813,7 +1291,28 @@ ${errors.length} error(s), ${warnings.length} warning(s).` + (result.size === nu
|
|
|
813
1291
|
);
|
|
814
1292
|
return 0;
|
|
815
1293
|
}
|
|
1294
|
+
async function runCanvasCommand(argv) {
|
|
1295
|
+
if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
|
|
1296
|
+
console.log(CANVAS_USAGE);
|
|
1297
|
+
process.exit(argv.length === 0 ? 1 : 0);
|
|
1298
|
+
}
|
|
1299
|
+
const parsed = parseCanvasArgs(argv, process.env);
|
|
1300
|
+
if ("error" in parsed) {
|
|
1301
|
+
console.error(parsed.error);
|
|
1302
|
+
console.error("Run `condor-mobile-bridge canvas --help`.");
|
|
1303
|
+
process.exit(1);
|
|
1304
|
+
}
|
|
1305
|
+
const code = await runCanvas(parsed, terminalIo(), {
|
|
1306
|
+
userAgent: `condor-mobile-bridge-cli/${version}`
|
|
1307
|
+
});
|
|
1308
|
+
closeTerminalIo();
|
|
1309
|
+
process.exit(code);
|
|
1310
|
+
}
|
|
816
1311
|
function main() {
|
|
1312
|
+
if (process.argv[2] === "canvas") {
|
|
1313
|
+
void runCanvasCommand(process.argv.slice(3));
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
817
1316
|
const args = parseArgs(process.argv.slice(2));
|
|
818
1317
|
if (args.help || !args.htmlPath) {
|
|
819
1318
|
console.log(USAGE);
|