@serverkgg/bridge 0.0.10 → 0.0.12

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.
@@ -5,6 +5,7 @@ import {
5
5
  BridgeAction,
6
6
  BridgeConfirm,
7
7
  BridgeControl,
8
+ type BridgeField,
8
9
  BridgeFormTarget,
9
10
  BridgeKind,
10
11
  BridgeLayout,
@@ -457,6 +458,67 @@ describe("the upload mirror", () => {
457
458
  });
458
459
  });
459
460
 
461
+ const fieldManifest = (field: BridgeField): BridgeManifest => ({
462
+ version: "1.0.0",
463
+ panel: {
464
+ tabs: [
465
+ {
466
+ id: "license",
467
+ title: text("Licence"),
468
+ sections: [
469
+ {
470
+ layout: BridgeLayout.Form,
471
+ id: "license",
472
+ target: BridgeFormTarget.Variables,
473
+ fields: [
474
+ field,
475
+ ],
476
+ },
477
+ ],
478
+ },
479
+ ],
480
+ },
481
+ terminal: null,
482
+ setup: null,
483
+ modules: [],
484
+ events: [],
485
+ });
486
+
487
+ describe("secret fields", () => {
488
+ test("carries a secret control with its pattern and hint through unchanged", () => {
489
+ const source = fieldManifest({
490
+ key: "LICENSE_KEY",
491
+ control: BridgeControl.Secret,
492
+ label: text("Licence key"),
493
+ pattern: "^cfxk_\\w{1,60}_\\w{1,20}$",
494
+ patternHint: text("A licence key starts with cfxk_"),
495
+ });
496
+
497
+ expect(bridgeManifestSchema.parse(source)).toEqual(source);
498
+ });
499
+
500
+ test("refuses a control the platform does not know", () => {
501
+ const source = fieldManifest({
502
+ key: "LICENSE_KEY",
503
+ control: "password" as BridgeControl,
504
+ label: text("Licence key"),
505
+ });
506
+
507
+ expect(bridgeManifestSchema.safeParse(source).success).toBe(false);
508
+ });
509
+
510
+ test("refuses a pattern longer than the platform takes", () => {
511
+ const source = fieldManifest({
512
+ key: "LICENSE_KEY",
513
+ control: BridgeControl.Secret,
514
+ label: text("Licence key"),
515
+ pattern: `^${"a".repeat(256)}$`,
516
+ });
517
+
518
+ expect(bridgeManifestSchema.safeParse(source).success).toBe(false);
519
+ });
520
+ });
521
+
460
522
  const setupManifest = (setup: BridgeSetupManifest | null): BridgeManifest => ({
461
523
  version: "1.0.0",
462
524
  panel: null,
package/src/wire/panel.ts CHANGED
@@ -2,6 +2,7 @@ import { guideOpenTargetSchema } from "@serverkgg/bridge/guides";
2
2
  import {
3
3
  BRIDGE_ID_PATTERN,
4
4
  BRIDGE_MODULE_ID_PATTERN,
5
+ BRIDGE_PATTERN_LENGTH_LIMIT,
5
6
  BridgeAccess,
6
7
  BridgeConfirm,
7
8
  BridgeControl,
@@ -100,6 +101,8 @@ export const bridgeFieldSchema = z.object({
100
101
  max: z.number().optional(),
101
102
  step: z.number().optional(),
102
103
  maxLength: z.int().positive().optional(),
104
+ pattern: z.string().max(BRIDGE_PATTERN_LENGTH_LIMIT).optional(),
105
+ patternHint: panelTextSchema.optional(),
103
106
  options: z
104
107
  .union([
105
108
  z.array(bridgeOptionSchema).max(64),