fortrip 4.0.0 → 4.2.0-rc.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/cli.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  unwrap,
27
27
  usageError,
28
28
  whoami
29
- } from "./chunk-3PTMRDQF.js";
29
+ } from "./chunk-LWFIUOYU.js";
30
30
 
31
31
  // src/commands.ts
32
32
  import { readFileSync } from "fs";
@@ -129,7 +129,8 @@ ${optionList(GLOBAL_FLAGS)}
129
129
  Output is compact text on stdout; --json prints it as one line of JSON.
130
130
  Errors go to stderr, as text or, with --json, as JSON.
131
131
  Exit codes: 0 ok, 1 error (retry once when the error says it is retryable),
132
- 2 invalid arguments, 3 not logged in, 4 rate limited.
132
+ 2 invalid arguments, or orders cancel without --max-penalty (nothing is
133
+ cancelled), 3 not signed in or sign-in not accepted, 4 rate limited.
133
134
 
134
135
  Environment:
135
136
  FORTRIP_TOKEN Use this token instead of the saved login (CI, sandboxes)
@@ -242,7 +243,8 @@ function cancelPreview(spec, argv) {
242
243
  if (positionals2.length !== 1) throw usageError(`Usage: ${usageLine(spec)}`);
243
244
  const input = { orderId: positionals2[0] };
244
245
  check({ ...spec, tool: "get_order" }, input, true, /* @__PURE__ */ new Map());
245
- return { method: "GET", path: API.order(input.orderId), flag: `--${flag.flag}` };
246
+ const orderId = input.orderId;
247
+ return { method: "GET", path: API.order(orderId), flag: `--${flag.flag}`, orderId };
246
248
  }
247
249
  function check(spec, input, isGet, fromEnv) {
248
250
  const schema = TOOLS.find((tool) => tool.name === spec.tool)?.input;
@@ -438,6 +440,684 @@ function readGuide(topic) {
438
440
  return renderGuide("cli", topic).replaceAll("fortrip@latest", `fortrip@${VERSION}`);
439
441
  }
440
442
 
443
+ // ../../node_modules/.pnpm/uqr@0.1.3/node_modules/uqr/dist/index.mjs
444
+ var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2) => {
445
+ QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
446
+ QrCodeDataType2[QrCodeDataType2["Data"] = 0] = "Data";
447
+ QrCodeDataType2[QrCodeDataType2["Function"] = 1] = "Function";
448
+ QrCodeDataType2[QrCodeDataType2["Position"] = 2] = "Position";
449
+ QrCodeDataType2[QrCodeDataType2["Timing"] = 3] = "Timing";
450
+ QrCodeDataType2[QrCodeDataType2["Alignment"] = 4] = "Alignment";
451
+ return QrCodeDataType2;
452
+ })(QrCodeDataType || {});
453
+ var LOW = [0, 1];
454
+ var MEDIUM = [1, 0];
455
+ var QUARTILE = [2, 3];
456
+ var HIGH = [3, 2];
457
+ var EccMap = {
458
+ L: LOW,
459
+ M: MEDIUM,
460
+ Q: QUARTILE,
461
+ H: HIGH
462
+ };
463
+ var NUMERIC_REGEX = /^\d*$/;
464
+ var ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+./:-]*$/;
465
+ var ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
466
+ var MIN_VERSION = 1;
467
+ var MAX_VERSION = 40;
468
+ var PENALTY_N1 = 3;
469
+ var PENALTY_N2 = 3;
470
+ var PENALTY_N3 = 40;
471
+ var PENALTY_N4 = 10;
472
+ var ECC_CODEWORDS_PER_BLOCK = [
473
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
474
+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
475
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
476
+ // Low
477
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
478
+ // Medium
479
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
480
+ // Quartile
481
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
482
+ // High
483
+ ];
484
+ var NUM_ERROR_CORRECTION_BLOCKS = [
485
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
486
+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
487
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
488
+ // Low
489
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
490
+ // Medium
491
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
492
+ // Quartile
493
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
494
+ // High
495
+ ];
496
+ var QrCode = class {
497
+ /* -- Constructor (low level) and fields -- */
498
+ // Creates a new QR Code with the given version number,
499
+ // error correction level, data codeword bytes, and mask number.
500
+ // This is a low-level API that most users should not use directly.
501
+ // A mid-level API is the encodeSegments() function.
502
+ constructor(version, ecc, dataCodewords, msk) {
503
+ this.version = version;
504
+ this.ecc = ecc;
505
+ if (version < MIN_VERSION || version > MAX_VERSION)
506
+ throw new RangeError("Version value out of range");
507
+ if (msk < -1 || msk > 7)
508
+ throw new RangeError("Mask value out of range");
509
+ this.size = version * 4 + 17;
510
+ const row = Array.from({ length: this.size }).fill(false);
511
+ for (let i = 0; i < this.size; i++) {
512
+ this.modules.push(row.slice());
513
+ this.types.push(row.map(() => 0));
514
+ }
515
+ this.drawFunctionPatterns();
516
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
517
+ this.drawCodewords(allCodewords);
518
+ if (msk === -1) {
519
+ let minPenalty = 1e9;
520
+ for (let i = 0; i < 8; i++) {
521
+ this.applyMask(i);
522
+ this.drawFormatBits(i);
523
+ const penalty = this.getPenaltyScore();
524
+ if (penalty < minPenalty) {
525
+ msk = i;
526
+ minPenalty = penalty;
527
+ }
528
+ this.applyMask(i);
529
+ }
530
+ }
531
+ this.mask = msk;
532
+ this.applyMask(msk);
533
+ this.drawFormatBits(msk);
534
+ }
535
+ /* -- Fields -- */
536
+ // The width and height of this QR Code, measured in modules, between
537
+ // 21 and 177 (inclusive). This is equal to version * 4 + 17.
538
+ size;
539
+ // The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
540
+ // Even if a QR Code is created with automatic masking requested (mask = -1),
541
+ // the resulting object still has a mask value between 0 and 7.
542
+ mask;
543
+ // The modules of this QR Code (false = light, true = dark).
544
+ // Immutable after constructor finishes. Accessed through getModule().
545
+ modules = [];
546
+ types = [];
547
+ /* -- Accessor methods -- */
548
+ // Returns the color of the module (pixel) at the given coordinates, which is false
549
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
550
+ // If the given coordinates are out of bounds, then false (light) is returned.
551
+ getModule(x, y) {
552
+ return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
553
+ }
554
+ /* -- Private helper methods for constructor: Drawing function modules -- */
555
+ // Reads this object's version field, and draws and marks all function modules.
556
+ drawFunctionPatterns() {
557
+ for (let i = 0; i < this.size; i++) {
558
+ this.setFunctionModule(6, i, i % 2 === 0, QrCodeDataType.Timing);
559
+ this.setFunctionModule(i, 6, i % 2 === 0, QrCodeDataType.Timing);
560
+ }
561
+ this.drawFinderPattern(3, 3);
562
+ this.drawFinderPattern(this.size - 4, 3);
563
+ this.drawFinderPattern(3, this.size - 4);
564
+ const alignPatPos = this.getAlignmentPatternPositions();
565
+ const numAlign = alignPatPos.length;
566
+ for (let i = 0; i < numAlign; i++) {
567
+ for (let j = 0; j < numAlign; j++) {
568
+ if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0))
569
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
570
+ }
571
+ }
572
+ this.drawFormatBits(0);
573
+ this.drawVersion();
574
+ }
575
+ // Draws two copies of the format bits (with its own error correction code)
576
+ // based on the given mask and this object's error correction level field.
577
+ drawFormatBits(mask) {
578
+ const data = this.ecc[1] << 3 | mask;
579
+ let rem = data;
580
+ for (let i = 0; i < 10; i++)
581
+ rem = rem << 1 ^ (rem >>> 9) * 1335;
582
+ const bits = (data << 10 | rem) ^ 21522;
583
+ for (let i = 0; i <= 5; i++)
584
+ this.setFunctionModule(8, i, getBit(bits, i));
585
+ this.setFunctionModule(8, 7, getBit(bits, 6));
586
+ this.setFunctionModule(8, 8, getBit(bits, 7));
587
+ this.setFunctionModule(7, 8, getBit(bits, 8));
588
+ for (let i = 9; i < 15; i++)
589
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
590
+ for (let i = 0; i < 8; i++)
591
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
592
+ for (let i = 8; i < 15; i++)
593
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
594
+ this.setFunctionModule(8, this.size - 8, true);
595
+ }
596
+ // Draws two copies of the version bits (with its own error correction code),
597
+ // based on this object's version field, iff 7 <= version <= 40.
598
+ drawVersion() {
599
+ if (this.version < 7)
600
+ return;
601
+ let rem = this.version;
602
+ for (let i = 0; i < 12; i++)
603
+ rem = rem << 1 ^ (rem >>> 11) * 7973;
604
+ const bits = this.version << 12 | rem;
605
+ for (let i = 0; i < 18; i++) {
606
+ const color = getBit(bits, i);
607
+ const a = this.size - 11 + i % 3;
608
+ const b = Math.floor(i / 3);
609
+ this.setFunctionModule(a, b, color);
610
+ this.setFunctionModule(b, a, color);
611
+ }
612
+ }
613
+ // Draws a 9*9 finder pattern including the border separator,
614
+ // with the center module at (x, y). Modules can be out of bounds.
615
+ drawFinderPattern(x, y) {
616
+ for (let dy = -4; dy <= 4; dy++) {
617
+ for (let dx = -4; dx <= 4; dx++) {
618
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
619
+ const xx = x + dx;
620
+ const yy = y + dy;
621
+ if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size)
622
+ this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4, QrCodeDataType.Position);
623
+ }
624
+ }
625
+ }
626
+ // Draws a 5*5 alignment pattern, with the center module
627
+ // at (x, y). All modules must be in bounds.
628
+ drawAlignmentPattern(x, y) {
629
+ for (let dy = -2; dy <= 2; dy++) {
630
+ for (let dx = -2; dx <= 2; dx++) {
631
+ this.setFunctionModule(
632
+ x + dx,
633
+ y + dy,
634
+ Math.max(Math.abs(dx), Math.abs(dy)) !== 1,
635
+ QrCodeDataType.Alignment
636
+ );
637
+ }
638
+ }
639
+ }
640
+ // Sets the color of a module and marks it as a function module.
641
+ // Only used by the constructor. Coordinates must be in bounds.
642
+ setFunctionModule(x, y, isDark, type = QrCodeDataType.Function) {
643
+ this.modules[y][x] = isDark;
644
+ this.types[y][x] = type;
645
+ }
646
+ /* -- Private helper methods for constructor: Codewords and masking -- */
647
+ // Returns a new byte string representing the given data with the appropriate error correction
648
+ // codewords appended to it, based on this object's version and error correction level.
649
+ addEccAndInterleave(data) {
650
+ const ver = this.version;
651
+ const ecl = this.ecc;
652
+ if (data.length !== getNumDataCodewords(ver, ecl))
653
+ throw new RangeError("Invalid argument");
654
+ const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
655
+ const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver];
656
+ const rawCodewords = Math.floor(getNumRawDataModules(ver) / 8);
657
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
658
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
659
+ const blocks = [];
660
+ const rsDiv = reedSolomonComputeDivisor(blockEccLen);
661
+ for (let i = 0, k = 0; i < numBlocks; i++) {
662
+ const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
663
+ k += dat.length;
664
+ const ecc = reedSolomonComputeRemainder(dat, rsDiv);
665
+ if (i < numShortBlocks)
666
+ dat.push(0);
667
+ blocks.push(dat.concat(ecc));
668
+ }
669
+ const result = [];
670
+ for (let i = 0; i < blocks[0].length; i++) {
671
+ blocks.forEach((block, j) => {
672
+ if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks)
673
+ result.push(block[i]);
674
+ });
675
+ }
676
+ return result;
677
+ }
678
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
679
+ // data area of this QR Code. Function modules need to be marked off before this is called.
680
+ drawCodewords(data) {
681
+ if (data.length !== Math.floor(getNumRawDataModules(this.version) / 8))
682
+ throw new RangeError("Invalid argument");
683
+ let i = 0;
684
+ for (let right = this.size - 1; right >= 1; right -= 2) {
685
+ if (right === 6)
686
+ right = 5;
687
+ for (let vert = 0; vert < this.size; vert++) {
688
+ for (let j = 0; j < 2; j++) {
689
+ const x = right - j;
690
+ const upward = (right + 1 & 2) === 0;
691
+ const y = upward ? this.size - 1 - vert : vert;
692
+ if (!this.types[y][x] && i < data.length * 8) {
693
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
694
+ i++;
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+ // XORs the codeword modules in this QR Code with the given mask pattern.
701
+ // The function modules must be marked and the codeword bits must be drawn
702
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
703
+ // the same mask value a second time will undo the mask. A final well-formed
704
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
705
+ applyMask(mask) {
706
+ if (mask < 0 || mask > 7)
707
+ throw new RangeError("Mask value out of range");
708
+ for (let y = 0; y < this.size; y++) {
709
+ for (let x = 0; x < this.size; x++) {
710
+ let invert;
711
+ switch (mask) {
712
+ case 0:
713
+ invert = (x + y) % 2 === 0;
714
+ break;
715
+ case 1:
716
+ invert = y % 2 === 0;
717
+ break;
718
+ case 2:
719
+ invert = x % 3 === 0;
720
+ break;
721
+ case 3:
722
+ invert = (x + y) % 3 === 0;
723
+ break;
724
+ case 4:
725
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
726
+ break;
727
+ case 5:
728
+ invert = x * y % 2 + x * y % 3 === 0;
729
+ break;
730
+ case 6:
731
+ invert = (x * y % 2 + x * y % 3) % 2 === 0;
732
+ break;
733
+ case 7:
734
+ invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
735
+ break;
736
+ default:
737
+ throw new Error("Unreachable");
738
+ }
739
+ if (!this.types[y][x] && invert)
740
+ this.modules[y][x] = !this.modules[y][x];
741
+ }
742
+ }
743
+ }
744
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
745
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
746
+ getPenaltyScore() {
747
+ let result = 0;
748
+ for (let y = 0; y < this.size; y++) {
749
+ let runColor = false;
750
+ let runX = 0;
751
+ const runHistory = [0, 0, 0, 0, 0, 0, 0];
752
+ for (let x = 0; x < this.size; x++) {
753
+ if (this.modules[y][x] === runColor) {
754
+ runX++;
755
+ if (runX === 5)
756
+ result += PENALTY_N1;
757
+ else if (runX > 5)
758
+ result++;
759
+ } else {
760
+ this.finderPenaltyAddHistory(runX, runHistory);
761
+ if (!runColor)
762
+ result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
763
+ runColor = this.modules[y][x];
764
+ runX = 1;
765
+ }
766
+ }
767
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
768
+ }
769
+ for (let x = 0; x < this.size; x++) {
770
+ let runColor = false;
771
+ let runY = 0;
772
+ const runHistory = [0, 0, 0, 0, 0, 0, 0];
773
+ for (let y = 0; y < this.size; y++) {
774
+ if (this.modules[y][x] === runColor) {
775
+ runY++;
776
+ if (runY === 5)
777
+ result += PENALTY_N1;
778
+ else if (runY > 5)
779
+ result++;
780
+ } else {
781
+ this.finderPenaltyAddHistory(runY, runHistory);
782
+ if (!runColor)
783
+ result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
784
+ runColor = this.modules[y][x];
785
+ runY = 1;
786
+ }
787
+ }
788
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
789
+ }
790
+ for (let y = 0; y < this.size - 1; y++) {
791
+ for (let x = 0; x < this.size - 1; x++) {
792
+ const color = this.modules[y][x];
793
+ if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1]) {
794
+ result += PENALTY_N2;
795
+ }
796
+ }
797
+ }
798
+ let dark = 0;
799
+ for (const row of this.modules)
800
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
801
+ const total = this.size * this.size;
802
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
803
+ result += k * PENALTY_N4;
804
+ return result;
805
+ }
806
+ /* -- Private helper functions -- */
807
+ // Returns an ascending list of positions of alignment patterns for this version number.
808
+ // Each position is in the range [0,177), and are used on both the x and y axes.
809
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
810
+ getAlignmentPatternPositions() {
811
+ if (this.version === 1) {
812
+ return [];
813
+ } else {
814
+ const numAlign = Math.floor(this.version / 7) + 2;
815
+ const step2 = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
816
+ const result = [6];
817
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step2)
818
+ result.splice(1, 0, pos);
819
+ return result;
820
+ }
821
+ }
822
+ // Can only be called immediately after a light run is added, and
823
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
824
+ finderPenaltyCountPatterns(runHistory) {
825
+ const n = runHistory[1];
826
+ const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
827
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
828
+ }
829
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
830
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
831
+ if (currentRunColor) {
832
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
833
+ currentRunLength = 0;
834
+ }
835
+ currentRunLength += this.size;
836
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
837
+ return this.finderPenaltyCountPatterns(runHistory);
838
+ }
839
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
840
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
841
+ if (runHistory[0] === 0)
842
+ currentRunLength += this.size;
843
+ runHistory.pop();
844
+ runHistory.unshift(currentRunLength);
845
+ }
846
+ };
847
+ function appendBits(val, len, bb) {
848
+ if (len < 0 || len > 31 || val >>> len !== 0)
849
+ throw new RangeError("Value out of range");
850
+ for (let i = len - 1; i >= 0; i--)
851
+ bb.push(val >>> i & 1);
852
+ }
853
+ function getBit(x, i) {
854
+ return (x >>> i & 1) !== 0;
855
+ }
856
+ var QrSegment = class {
857
+ // Creates a new QR Code segment with the given attributes and data.
858
+ // The character count (numChars) must agree with the mode and the bit buffer length,
859
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
860
+ constructor(mode, numChars, bitData) {
861
+ this.mode = mode;
862
+ this.numChars = numChars;
863
+ this.bitData = bitData;
864
+ if (numChars < 0)
865
+ throw new RangeError("Invalid argument");
866
+ this.bitData = bitData.slice();
867
+ }
868
+ /* -- Methods -- */
869
+ // Returns a new copy of the data bits of this segment.
870
+ getData() {
871
+ return this.bitData.slice();
872
+ }
873
+ };
874
+ var MODE_NUMERIC = [1, 10, 12, 14];
875
+ var MODE_ALPHANUMERIC = [2, 9, 11, 13];
876
+ var MODE_BYTE = [4, 8, 16, 16];
877
+ function numCharCountBits(mode, ver) {
878
+ return mode[Math.floor((ver + 7) / 17) + 1];
879
+ }
880
+ function makeBytes(data) {
881
+ const bb = [];
882
+ for (const b of data)
883
+ appendBits(b, 8, bb);
884
+ return new QrSegment(MODE_BYTE, data.length, bb);
885
+ }
886
+ function makeNumeric(digits) {
887
+ if (!isNumeric(digits))
888
+ throw new RangeError("String contains non-numeric characters");
889
+ const bb = [];
890
+ for (let i = 0; i < digits.length; ) {
891
+ const n = Math.min(digits.length - i, 3);
892
+ appendBits(Number.parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
893
+ i += n;
894
+ }
895
+ return new QrSegment(MODE_NUMERIC, digits.length, bb);
896
+ }
897
+ function makeAlphanumeric(text) {
898
+ if (!isAlphanumeric(text))
899
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
900
+ const bb = [];
901
+ let i;
902
+ for (i = 0; i + 2 <= text.length; i += 2) {
903
+ let temp = ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
904
+ temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
905
+ appendBits(temp, 11, bb);
906
+ }
907
+ if (i < text.length)
908
+ appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
909
+ return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
910
+ }
911
+ function makeSegments(text) {
912
+ if (text === "")
913
+ return [];
914
+ else if (isNumeric(text))
915
+ return [makeNumeric(text)];
916
+ else if (isAlphanumeric(text))
917
+ return [makeAlphanumeric(text)];
918
+ else
919
+ return [makeBytes(toUtf8ByteArray(text))];
920
+ }
921
+ function isNumeric(text) {
922
+ return NUMERIC_REGEX.test(text);
923
+ }
924
+ function isAlphanumeric(text) {
925
+ return ALPHANUMERIC_REGEX.test(text);
926
+ }
927
+ function getTotalBits(segs, version) {
928
+ let result = 0;
929
+ for (const seg of segs) {
930
+ const ccbits = numCharCountBits(seg.mode, version);
931
+ if (seg.numChars >= 1 << ccbits)
932
+ return Number.POSITIVE_INFINITY;
933
+ result += 4 + ccbits + seg.bitData.length;
934
+ }
935
+ return result;
936
+ }
937
+ function toUtf8ByteArray(str) {
938
+ str = encodeURI(str);
939
+ const result = [];
940
+ for (let i = 0; i < str.length; i++) {
941
+ if (str.charAt(i) !== "%") {
942
+ result.push(str.charCodeAt(i));
943
+ } else {
944
+ result.push(Number.parseInt(str.substring(i + 1, i + 3), 16));
945
+ i += 2;
946
+ }
947
+ }
948
+ return result;
949
+ }
950
+ function getNumRawDataModules(ver) {
951
+ if (ver < MIN_VERSION || ver > MAX_VERSION)
952
+ throw new RangeError("Version number out of range");
953
+ let result = (16 * ver + 128) * ver + 64;
954
+ if (ver >= 2) {
955
+ const numAlign = Math.floor(ver / 7) + 2;
956
+ result -= (25 * numAlign - 10) * numAlign - 55;
957
+ if (ver >= 7)
958
+ result -= 36;
959
+ }
960
+ return result;
961
+ }
962
+ function getNumDataCodewords(ver, ecl) {
963
+ return Math.floor(getNumRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
964
+ }
965
+ function reedSolomonComputeDivisor(degree) {
966
+ if (degree < 1 || degree > 255)
967
+ throw new RangeError("Degree out of range");
968
+ const result = [];
969
+ for (let i = 0; i < degree - 1; i++)
970
+ result.push(0);
971
+ result.push(1);
972
+ let root = 1;
973
+ for (let i = 0; i < degree; i++) {
974
+ for (let j = 0; j < result.length; j++) {
975
+ result[j] = reedSolomonMultiply(result[j], root);
976
+ if (j + 1 < result.length)
977
+ result[j] ^= result[j + 1];
978
+ }
979
+ root = reedSolomonMultiply(root, 2);
980
+ }
981
+ return result;
982
+ }
983
+ function reedSolomonComputeRemainder(data, divisor) {
984
+ const result = divisor.map((_) => 0);
985
+ for (const b of data) {
986
+ const factor = b ^ result.shift();
987
+ result.push(0);
988
+ divisor.forEach((coef, i) => result[i] ^= reedSolomonMultiply(coef, factor));
989
+ }
990
+ return result;
991
+ }
992
+ function reedSolomonMultiply(x, y) {
993
+ if (x >>> 8 !== 0 || y >>> 8 !== 0)
994
+ throw new RangeError("Byte out of range");
995
+ let z = 0;
996
+ for (let i = 7; i >= 0; i--) {
997
+ z = z << 1 ^ (z >>> 7) * 285;
998
+ z ^= (y >>> i & 1) * x;
999
+ }
1000
+ return z;
1001
+ }
1002
+ function encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
1003
+ if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) {
1004
+ throw new RangeError("Invalid value");
1005
+ }
1006
+ let version;
1007
+ let dataUsedBits;
1008
+ for (version = minVersion; ; version++) {
1009
+ const dataCapacityBits2 = getNumDataCodewords(version, ecl) * 8;
1010
+ const usedBits = getTotalBits(segs, version);
1011
+ if (usedBits <= dataCapacityBits2) {
1012
+ dataUsedBits = usedBits;
1013
+ break;
1014
+ }
1015
+ if (version >= maxVersion)
1016
+ throw new RangeError("Data too long");
1017
+ }
1018
+ for (const newEcl of [MEDIUM, QUARTILE, HIGH]) {
1019
+ if (boostEcl && dataUsedBits <= getNumDataCodewords(version, newEcl) * 8)
1020
+ ecl = newEcl;
1021
+ }
1022
+ const bb = [];
1023
+ for (const seg of segs) {
1024
+ appendBits(seg.mode[0], 4, bb);
1025
+ appendBits(seg.numChars, numCharCountBits(seg.mode, version), bb);
1026
+ for (const b of seg.getData())
1027
+ bb.push(b);
1028
+ }
1029
+ const dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
1030
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
1031
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
1032
+ for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
1033
+ appendBits(padByte, 8, bb);
1034
+ const dataCodewords = Array.from({ length: Math.ceil(bb.length / 8) }, () => 0);
1035
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
1036
+ return new QrCode(version, ecl, dataCodewords, mask);
1037
+ }
1038
+ function encode(data, options) {
1039
+ const {
1040
+ ecc = "L",
1041
+ boostEcc = false,
1042
+ minVersion = 1,
1043
+ maxVersion = 40,
1044
+ maskPattern = -1,
1045
+ border = 1
1046
+ } = options || {};
1047
+ const segment = typeof data === "string" ? makeSegments(data) : Array.isArray(data) ? [makeBytes(data)] : void 0;
1048
+ if (!segment)
1049
+ throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof data}`);
1050
+ const qr = encodeSegments(
1051
+ segment,
1052
+ EccMap[ecc],
1053
+ minVersion,
1054
+ maxVersion,
1055
+ maskPattern,
1056
+ boostEcc
1057
+ );
1058
+ const result = addBorder({
1059
+ version: qr.version,
1060
+ maskPattern: qr.mask,
1061
+ size: qr.size,
1062
+ data: qr.modules,
1063
+ types: qr.types
1064
+ }, border);
1065
+ if (options?.invert)
1066
+ result.data = result.data.map((row) => row.map((mod) => !mod));
1067
+ options?.onEncoded?.(result);
1068
+ return result;
1069
+ }
1070
+ function addBorder(input, border = 1) {
1071
+ if (!border)
1072
+ return input;
1073
+ const { size } = input;
1074
+ const newSize = size + border * 2;
1075
+ input.size = newSize;
1076
+ input.data.forEach((row) => {
1077
+ for (let i = 0; i < border; i++) {
1078
+ row.unshift(false);
1079
+ row.push(false);
1080
+ }
1081
+ });
1082
+ for (let i = 0; i < border; i++) {
1083
+ input.data.unshift(Array.from({ length: newSize }, (_) => false));
1084
+ input.data.push(Array.from({ length: newSize }, (_) => false));
1085
+ }
1086
+ const b = QrCodeDataType.Border;
1087
+ input.types.forEach((row) => {
1088
+ for (let i = 0; i < border; i++) {
1089
+ row.unshift(b);
1090
+ row.push(b);
1091
+ }
1092
+ });
1093
+ for (let i = 0; i < border; i++) {
1094
+ input.types.unshift(Array.from({ length: newSize }, (_) => b));
1095
+ input.types.push(Array.from({ length: newSize }, (_) => b));
1096
+ }
1097
+ return input;
1098
+ }
1099
+
1100
+ // src/qr.ts
1101
+ function halfBlocks(modules) {
1102
+ const lines = [];
1103
+ for (let y = 0; y < modules.length; y += 2) {
1104
+ const top = modules[y] ?? [];
1105
+ const bottom = modules[y + 1] ?? [];
1106
+ let line = "";
1107
+ for (let x = 0; x < top.length; x++) {
1108
+ line += top[x] ? bottom[x] ? "\u2588" : "\u2580" : bottom[x] ? "\u2584" : " ";
1109
+ }
1110
+ lines.push(line);
1111
+ }
1112
+ return lines;
1113
+ }
1114
+ function terminalQr(data, columns) {
1115
+ const { data: modules } = encode(data, { ecc: "M", border: 2 });
1116
+ const width = modules[0]?.length ?? 0;
1117
+ if (columns === void 0 || columns < width) return null;
1118
+ return halfBlocks(modules).map((line) => `\x1B[30;47m${line}\x1B[0m`).join("\n");
1119
+ }
1120
+
441
1121
  // src/cli.ts
442
1122
  function globalFlag(name) {
443
1123
  const option = GLOBAL_FLAGS.find((candidate) => candidate.flag === name);
@@ -528,7 +1208,7 @@ async function run(argv) {
528
1208
  case "mcp": {
529
1209
  parseOptions(spec, rest);
530
1210
  const mcpUrl = resolveMcpUrl(apiUrl);
531
- const { runMcpBridge } = await import("./mcp-bridge-NK65DPFT.js");
1211
+ const { runMcpBridge } = await import("./mcp-bridge-A7MBMCM6.js");
532
1212
  await runMcpBridge(mcpUrl, apiUrl);
533
1213
  return void 0;
534
1214
  }
@@ -537,21 +1217,20 @@ async function run(argv) {
537
1217
  const preview = cancelPreview(spec, rest);
538
1218
  if (preview) {
539
1219
  const order2 = unwrap(await authorizedRequest(apiUrl, preview.path, { method: preview.method }));
540
- throw usageError(notCancelled(spec, preview.flag, order2));
1220
+ throw usageError(notCancelled(spec, preview.flag, preview.orderId, order2));
541
1221
  }
542
1222
  const { method, path, body } = parseCommand(spec, rest, process.env);
543
1223
  const data = unwrap(await authorizedRequest(apiUrl, path, { method, body }));
544
- return { data, text: renderToolResult(spec.tool, data) };
1224
+ return { data, text: renderToolResult(spec.tool, data, "cli") };
545
1225
  }
546
- function notCancelled(spec, flag, order2) {
547
- const cancelLine = renderToolResult("get_order", order2).split("\n").filter((text) => text.startsWith("Cancel: "));
1226
+ function notCancelled(spec, flag, orderId, order2) {
1227
+ const lines = renderToolResult("get_order", order2, "cli").split("\n").filter((text) => text.startsWith("Hotel: ") || text.startsWith("Cancel: "));
548
1228
  const parsed = order.safeParse(order2);
549
1229
  const cancel = parsed.success ? parsed.data.cancel : void 0;
550
- return [
551
- `Not cancelled: ${commandInvocation(spec)} needs ${flag}, the penalty the user agreed to.`,
552
- ...cancelLine,
553
- ...cancel?.available && cancel.penalty ? [`Pass ${flag} ${cancel.penalty.amount} to cancel.`] : []
554
- ].join("\n");
1230
+ const next = cancel?.available && cancel.penalty ? [
1231
+ `Show the user the stay, this penalty and this refund, and ask them to confirm. Only after a clear yes, run \`${commandInvocation(spec)} ${orderId} ${flag} ${cancel.penalty.amount}\`.`
1232
+ ] : cancel ? [] : [`${commandInvocation(spec)} needs ${flag}, the penalty the user agreed to.`];
1233
+ return ["Not cancelled: nothing was sent.", ...lines, ...next].join("\n");
555
1234
  }
556
1235
  function account(data) {
557
1236
  const { apiUrl, userId, email, name } = data;
@@ -578,6 +1257,12 @@ function takeJson(argv) {
578
1257
  const kept = before.filter((arg) => arg !== JSON_FLAG);
579
1258
  return { json: kept.length < before.length, argv: [...kept, ...after] };
580
1259
  }
1260
+ function walletCode(argv, data) {
1261
+ if (argv[0] !== "orders" || argv[1] !== "pay" || !process.stdout.isTTY) return null;
1262
+ const wallets = data?.payment?.wallets;
1263
+ const qrData = wallets?.wechatPay?.qrData;
1264
+ return typeof qrData === "string" ? terminalQr(qrData, process.stdout.columns) : null;
1265
+ }
581
1266
  async function main() {
582
1267
  const { json, argv } = takeJson(process.argv.slice(2));
583
1268
  try {
@@ -590,6 +1275,10 @@ async function main() {
590
1275
  `);
591
1276
  } else {
592
1277
  process.stdout.write(`${[text, ...fieldLines(notices)].join("\n")}
1278
+ `);
1279
+ const code = walletCode(argv, data);
1280
+ if (code) process.stdout.write(`Or scan this WeChat Pay code:
1281
+ ${code}
593
1282
  `);
594
1283
  }
595
1284
  }