proxylang 0.1.4 → 0.1.6

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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { R as requestSchema, a as explain, i as compile, l as targetCatalog, p as StaticRuleSetUnknownError, t as buildToDirectory } from "./host-BPBSZ-jw.js";
2
+ import { G as requestSchema, b as StaticRuleSetUnknownError, c as buildToDirectory, d as compile, f as explain, g as targetCatalog, n as runSurgeBuild, r as surgeBuildFailure } from "./surge-build-DbQ9Ddhc.js";
3
3
  import { open } from "node:fs/promises";
4
4
  import { resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
@@ -15,6 +15,7 @@ const failure = (code) => {
15
15
  return 1;
16
16
  };
17
17
  const usages = {
18
+ "surge-build": ["proxylang surge-build config.ts --out DIRECTORY [--validation]"],
18
19
  targets: ["proxylang targets"],
19
20
  check: ["proxylang check config.ts"],
20
21
  explain: ["proxylang explain config.ts --target ID --request JSON", "proxylang explain config.ts --target ID --request-file FILE"],
@@ -83,6 +84,7 @@ async function main(args) {
83
84
  });
84
85
  return 0;
85
86
  }
87
+ if (command === "surge-build") return surgeBuildCommand(file, rest);
86
88
  if (![
87
89
  "check",
88
90
  "explain",
@@ -163,6 +165,39 @@ async function main(args) {
163
165
  });
164
166
  return built.exitCode;
165
167
  }
168
+ async function surgeBuildCommand(file, args) {
169
+ const invalid = () => {
170
+ print(surgeBuildFailure("INVALID_ARGUMENTS"));
171
+ return 1;
172
+ };
173
+ if (!file?.trim() || file.startsWith("-")) return invalid();
174
+ let output;
175
+ let validation = false;
176
+ for (let i = 0; i < args.length; i++) {
177
+ const arg = args[i];
178
+ if (arg === "--out" && output === void 0) {
179
+ const value = args[++i];
180
+ if (!value?.trim() || value.startsWith("-")) return invalid();
181
+ output = value;
182
+ } else if (arg === "--validation" && !validation) validation = true;
183
+ else if (arg === "--" && output !== void 0 && !validation && i === args.length - 2 && args[i + 1] === "--validation") {
184
+ validation = true;
185
+ i++;
186
+ } else return invalid();
187
+ }
188
+ if (output === void 0) return invalid();
189
+ let config;
190
+ try {
191
+ const loaded = await tsImport(pathToFileURL(resolve(file)).href, import.meta.url);
192
+ config = loaded.default?.__esModule === true ? loaded.default.default : loaded.default;
193
+ } catch {
194
+ print(surgeBuildFailure("PROFILE_DEFINITION_FAILED", validation));
195
+ return 1;
196
+ }
197
+ const result = await runSurgeBuild(config, output, { validation });
198
+ print(result);
199
+ return result.exitCode;
200
+ }
166
201
  try {
167
202
  process.exitCode = await main(process.argv.slice(2));
168
203
  } catch (cause) {
package/dist/index.d.ts CHANGED
@@ -298,6 +298,202 @@ export type Explanation = {
298
298
  }[];
299
299
  };
300
300
  //#endregion
301
+ //#region src/surge-profile.d.ts
302
+ declare const policy$1: z.ZodUnion<readonly [z.ZodObject<{
303
+ ref: z.ZodString;
304
+ }, z.core.$strict>, z.ZodObject<{
305
+ builtin: z.ZodEnum<{
306
+ DIRECT: "DIRECT";
307
+ REJECT: "REJECT";
308
+ "REJECT-DROP": "REJECT-DROP";
309
+ "REJECT-NO-DROP": "REJECT-NO-DROP";
310
+ "REJECT-TINYGIF": "REJECT-TINYGIF";
311
+ }>;
312
+ }, z.core.$strict>]>;
313
+ type SurgePolicy = z.infer<typeof policy$1>;
314
+ declare const generalSchema: z.ZodObject<{
315
+ loglevel: z.ZodOptional<z.ZodEnum<{
316
+ info: "info";
317
+ notify: "notify";
318
+ verbose: "verbose";
319
+ warning: "warning";
320
+ }>>;
321
+ "dns-server": z.ZodOptional<z.ZodArray<z.ZodString>>;
322
+ "encrypted-dns-server": z.ZodOptional<z.ZodArray<z.ZodString>>;
323
+ "show-error-page-for-reject": z.ZodOptional<z.ZodBoolean>;
324
+ "exclude-simple-hostnames": z.ZodOptional<z.ZodBoolean>;
325
+ "internet-test-url": z.ZodOptional<z.ZodString>;
326
+ "skip-proxy": z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString, z.ZodString]>>>;
327
+ ipv6: z.ZodOptional<z.ZodBoolean>;
328
+ "ipv6-vif": z.ZodOptional<z.ZodEnum<{
329
+ always: "always";
330
+ auto: "auto";
331
+ disabled: "disabled";
332
+ }>>;
333
+ "bypass-system": z.ZodOptional<z.ZodBoolean>;
334
+ replica: z.ZodOptional<z.ZodBoolean>;
335
+ "tls-provider": z.ZodOptional<z.ZodEnum<{
336
+ default: "default";
337
+ openssl: "openssl";
338
+ }>>;
339
+ "bypass-tun": z.ZodOptional<z.ZodArray<z.ZodString>>;
340
+ "always-real-ip": z.ZodOptional<z.ZodArray<z.ZodString>>;
341
+ "http-api": z.ZodOptional<z.ZodObject<{
342
+ password: z.ZodObject<{
343
+ type: z.ZodLiteral<"env">;
344
+ name: z.ZodString;
345
+ }, z.core.$strict>;
346
+ listen: z.ZodString;
347
+ }, z.core.$strict>>;
348
+ "http-api-web-dashboard": z.ZodOptional<z.ZodBoolean>;
349
+ "external-controller-access": z.ZodOptional<z.ZodObject<{
350
+ password: z.ZodObject<{
351
+ type: z.ZodLiteral<"env">;
352
+ name: z.ZodString;
353
+ }, z.core.$strict>;
354
+ listen: z.ZodString;
355
+ }, z.core.$strict>>;
356
+ "hijack-dns": z.ZodOptional<z.ZodArray<z.ZodString>>;
357
+ "http-listen": z.ZodOptional<z.ZodString>;
358
+ "socks5-listen": z.ZodOptional<z.ZodString>;
359
+ "proxy-restricted-to-lan": z.ZodOptional<z.ZodBoolean>;
360
+ }, z.core.$strict>;
361
+ type SurgeGeneral = z.infer<typeof generalSchema>;
362
+ declare const hostSchema: z.ZodObject<{
363
+ pattern: z.ZodString;
364
+ address: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
365
+ server: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
366
+ }, z.core.$strict>;
367
+ type SurgeHost = z.infer<typeof hostSchema>;
368
+ declare const tunnelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
369
+ type: z.ZodLiteral<"tailscale">;
370
+ id: z.ZodString;
371
+ sectionName: z.ZodString;
372
+ authKey: z.ZodObject<{
373
+ type: z.ZodLiteral<"env">;
374
+ name: z.ZodString;
375
+ }, z.core.$strict>;
376
+ hostname: z.ZodString;
377
+ dnsServer: z.ZodOptional<z.ZodArray<z.ZodString>>;
378
+ autoAddMagicDnsRule: z.ZodOptional<z.ZodBoolean>;
379
+ idleKeepalive: z.ZodOptional<z.ZodNumber>;
380
+ }, z.core.$strict>, z.ZodObject<{
381
+ type: z.ZodLiteral<"wireguard">;
382
+ id: z.ZodString;
383
+ sectionName: z.ZodString;
384
+ privateKey: z.ZodObject<{
385
+ type: z.ZodLiteral<"env">;
386
+ name: z.ZodString;
387
+ }, z.core.$strict>;
388
+ selfIp: z.ZodString;
389
+ dnsServer: z.ZodOptional<z.ZodArray<z.ZodString>>;
390
+ mtu: z.ZodOptional<z.ZodNumber>;
391
+ peers: z.ZodArray<z.ZodObject<{
392
+ publicKey: z.ZodString;
393
+ endpoint: z.ZodString;
394
+ allowedIps: z.ZodArray<z.ZodString>;
395
+ presharedKey: z.ZodOptional<z.ZodObject<{
396
+ type: z.ZodLiteral<"env">;
397
+ name: z.ZodString;
398
+ }, z.core.$strict>>;
399
+ persistentKeepalive: z.ZodOptional<z.ZodNumber>;
400
+ }, z.core.$strict>>;
401
+ }, z.core.$strict>], "type">;
402
+ type SurgeTunnel = z.infer<typeof tunnelSchema>;
403
+ declare const groupSchema: z.ZodObject<{
404
+ id: z.ZodString;
405
+ type: z.ZodEnum<{
406
+ select: "select";
407
+ smart: "smart";
408
+ }>;
409
+ members: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
410
+ ref: z.ZodString;
411
+ }, z.core.$strict>, z.ZodObject<{
412
+ builtin: z.ZodEnum<{
413
+ DIRECT: "DIRECT";
414
+ REJECT: "REJECT";
415
+ "REJECT-DROP": "REJECT-DROP";
416
+ "REJECT-NO-DROP": "REJECT-NO-DROP";
417
+ "REJECT-TINYGIF": "REJECT-TINYGIF";
418
+ }>;
419
+ }, z.core.$strict>]>>;
420
+ url: z.ZodOptional<z.ZodString>;
421
+ intervalSeconds: z.ZodOptional<z.ZodNumber>;
422
+ timeoutSeconds: z.ZodOptional<z.ZodNumber>;
423
+ }, z.core.$strict>;
424
+ type SurgeGroup = z.infer<typeof groupSchema>;
425
+ type ConditionOptions = {
426
+ readonly noResolve?: boolean;
427
+ readonly extendedMatching?: boolean;
428
+ };
429
+ type SurgeCondition = ConditionOptions & ({
430
+ readonly type: "domain" | "domainSuffix" | "ipCidr" | "ipCidr6" | "sourceIp" | "processName" | "macAddress";
431
+ readonly value: string;
432
+ } | {
433
+ readonly type: "port" | "sourcePort";
434
+ readonly from: number;
435
+ readonly to?: number;
436
+ } | {
437
+ readonly type: "network";
438
+ readonly value: "tcp" | "udp";
439
+ } | {
440
+ readonly type: "all" | "any";
441
+ readonly conditions: readonly SurgeCondition[];
442
+ } | {
443
+ readonly type: "not";
444
+ readonly condition: SurgeCondition;
445
+ } | {
446
+ readonly type: "ruleSet";
447
+ readonly format: "rule-set" | "domain-set";
448
+ readonly url?: string;
449
+ readonly builtin?: "LAN" | "SYSTEM";
450
+ });
451
+ type SurgeRule = {
452
+ readonly when: SurgeCondition;
453
+ readonly then: SurgePolicy;
454
+ };
455
+ declare const managedSchema: z.ZodObject<{
456
+ url: z.ZodString;
457
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
458
+ type: z.ZodLiteral<"env">;
459
+ name: z.ZodString;
460
+ }, z.core.$strict>]>>>;
461
+ intervalSeconds: z.ZodNumber;
462
+ strict: z.ZodBoolean;
463
+ }, z.core.$strict>;
464
+ type SurgeProfileInput = {
465
+ readonly target: {
466
+ readonly engine: "surge";
467
+ readonly platform: "macos" | "ios";
468
+ readonly version: string;
469
+ };
470
+ readonly managed?: z.infer<typeof managedSchema>;
471
+ readonly general?: SurgeGeneral;
472
+ readonly hosts?: readonly SurgeHost[];
473
+ readonly nodes: readonly ProxyNode[];
474
+ readonly tunnels?: readonly SurgeTunnel[];
475
+ readonly groups: readonly SurgeGroup[];
476
+ readonly rules: readonly SurgeRule[];
477
+ readonly fallback: SurgePolicy;
478
+ readonly names?: Readonly<Record<string, string>>;
479
+ };
480
+ type SurgeProfileCompilation = {
481
+ readonly ok: boolean;
482
+ readonly artifactKind: "surge-profile";
483
+ readonly diagnostics: readonly Diagnostic[];
484
+ readonly bindings: readonly {
485
+ readonly id: string;
486
+ readonly nativeName: string;
487
+ }[];
488
+ };
489
+ type SurgeProfileArtifact = {
490
+ readonly artifactKind: "surge-profile";
491
+ readonly content: string;
492
+ };
493
+ export declare function compileSurgeProfile(input: unknown): SurgeProfileCompilation;
494
+ export declare function renderSurgeProfile(compilation: SurgeProfileCompilation, resolveSecret: (token: Secret) => string | undefined): SurgeProfileArtifact;
495
+ export declare function renderSurgeProfiles(compilations: readonly SurgeProfileCompilation[], resolveSecret: (token: Secret) => string | undefined): readonly SurgeProfileArtifact[];
496
+ //#endregion
301
497
  //#region src/proxy-builder.d.ts
302
498
  type ProxyBuilder<N extends ProxyNode> = {
303
499
  readonly via: (id: string) => ProxyBuilder<N>;
@@ -372,6 +568,63 @@ export declare const group: {
372
568
  }>;
373
569
  };
374
570
  export declare const surge: {
571
+ match: {
572
+ domain: (value: string, options?: {
573
+ readonly noResolve?: boolean;
574
+ readonly extendedMatching?: boolean;
575
+ }) => SurgeCondition;
576
+ domainSuffix: (value: string, options?: {
577
+ readonly noResolve?: boolean;
578
+ readonly extendedMatching?: boolean;
579
+ }) => SurgeCondition;
580
+ ipCidr: (value: string, options?: {
581
+ readonly noResolve?: boolean;
582
+ readonly extendedMatching?: boolean;
583
+ }) => SurgeCondition;
584
+ ipCidr6: (value: string, options?: {
585
+ readonly noResolve?: boolean;
586
+ readonly extendedMatching?: boolean;
587
+ }) => SurgeCondition;
588
+ sourceIp: (value: string, options?: {
589
+ readonly noResolve?: boolean;
590
+ readonly extendedMatching?: boolean;
591
+ }) => SurgeCondition;
592
+ processName: (value: string, options?: {
593
+ readonly noResolve?: boolean;
594
+ readonly extendedMatching?: boolean;
595
+ }) => SurgeCondition;
596
+ macAddress: (value: string, options?: {
597
+ readonly noResolve?: boolean;
598
+ readonly extendedMatching?: boolean;
599
+ }) => SurgeCondition;
600
+ network: (value: "tcp" | "udp", options?: {
601
+ readonly noResolve?: boolean;
602
+ readonly extendedMatching?: boolean;
603
+ }) => SurgeCondition;
604
+ port: (from: number, to?: number, options?: {
605
+ readonly noResolve?: boolean;
606
+ readonly extendedMatching?: boolean;
607
+ }) => SurgeCondition;
608
+ sourcePort: (from: number, to?: number, options?: {
609
+ readonly noResolve?: boolean;
610
+ readonly extendedMatching?: boolean;
611
+ }) => SurgeCondition;
612
+ all: (conditions: readonly SurgeCondition[], options?: {
613
+ readonly noResolve?: boolean;
614
+ readonly extendedMatching?: boolean;
615
+ }) => SurgeCondition;
616
+ any: (conditions: readonly SurgeCondition[], options?: {
617
+ readonly noResolve?: boolean;
618
+ readonly extendedMatching?: boolean;
619
+ }) => SurgeCondition;
620
+ not: (value: SurgeCondition, options?: {
621
+ readonly noResolve?: boolean;
622
+ readonly extendedMatching?: boolean;
623
+ }) => SurgeCondition;
624
+ ruleSet: (options: Omit<Extract<SurgeCondition, {
625
+ type: "ruleSet";
626
+ }>, "type">) => SurgeCondition;
627
+ };
375
628
  smart: () => Extract<GroupAlgorithm, {
376
629
  type: "surge-smart";
377
630
  }>;
@@ -591,202 +844,6 @@ type ProxyNodeArtifact = {
591
844
  export declare function compileProxyNodes(input: unknown): ProxyNodeCompilation;
592
845
  export declare function renderProxyNodes(compilation: ProxyNodeCompilation, resolveSecret: (token: Secret) => string | undefined): ProxyNodeArtifact;
593
846
  //#endregion
594
- //#region src/surge-profile.d.ts
595
- declare const policy$1: z.ZodUnion<readonly [z.ZodObject<{
596
- ref: z.ZodString;
597
- }, z.core.$strict>, z.ZodObject<{
598
- builtin: z.ZodEnum<{
599
- DIRECT: "DIRECT";
600
- REJECT: "REJECT";
601
- "REJECT-DROP": "REJECT-DROP";
602
- "REJECT-NO-DROP": "REJECT-NO-DROP";
603
- "REJECT-TINYGIF": "REJECT-TINYGIF";
604
- }>;
605
- }, z.core.$strict>]>;
606
- type SurgePolicy = z.infer<typeof policy$1>;
607
- declare const generalSchema: z.ZodObject<{
608
- loglevel: z.ZodOptional<z.ZodEnum<{
609
- info: "info";
610
- notify: "notify";
611
- verbose: "verbose";
612
- warning: "warning";
613
- }>>;
614
- "dns-server": z.ZodOptional<z.ZodArray<z.ZodString>>;
615
- "encrypted-dns-server": z.ZodOptional<z.ZodArray<z.ZodString>>;
616
- "show-error-page-for-reject": z.ZodOptional<z.ZodBoolean>;
617
- "exclude-simple-hostnames": z.ZodOptional<z.ZodBoolean>;
618
- "internet-test-url": z.ZodOptional<z.ZodString>;
619
- "skip-proxy": z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString, z.ZodString]>>>;
620
- ipv6: z.ZodOptional<z.ZodBoolean>;
621
- "ipv6-vif": z.ZodOptional<z.ZodEnum<{
622
- always: "always";
623
- auto: "auto";
624
- disabled: "disabled";
625
- }>>;
626
- "bypass-system": z.ZodOptional<z.ZodBoolean>;
627
- replica: z.ZodOptional<z.ZodBoolean>;
628
- "tls-provider": z.ZodOptional<z.ZodEnum<{
629
- default: "default";
630
- openssl: "openssl";
631
- }>>;
632
- "bypass-tun": z.ZodOptional<z.ZodArray<z.ZodString>>;
633
- "always-real-ip": z.ZodOptional<z.ZodArray<z.ZodString>>;
634
- "http-api": z.ZodOptional<z.ZodObject<{
635
- password: z.ZodObject<{
636
- type: z.ZodLiteral<"env">;
637
- name: z.ZodString;
638
- }, z.core.$strict>;
639
- listen: z.ZodString;
640
- }, z.core.$strict>>;
641
- "http-api-web-dashboard": z.ZodOptional<z.ZodBoolean>;
642
- "external-controller-access": z.ZodOptional<z.ZodObject<{
643
- password: z.ZodObject<{
644
- type: z.ZodLiteral<"env">;
645
- name: z.ZodString;
646
- }, z.core.$strict>;
647
- listen: z.ZodString;
648
- }, z.core.$strict>>;
649
- "hijack-dns": z.ZodOptional<z.ZodArray<z.ZodString>>;
650
- "http-listen": z.ZodOptional<z.ZodString>;
651
- "socks5-listen": z.ZodOptional<z.ZodString>;
652
- "proxy-restricted-to-lan": z.ZodOptional<z.ZodBoolean>;
653
- }, z.core.$strict>;
654
- type SurgeGeneral = z.infer<typeof generalSchema>;
655
- declare const hostSchema: z.ZodObject<{
656
- pattern: z.ZodString;
657
- address: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
658
- server: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
659
- }, z.core.$strict>;
660
- type SurgeHost = z.infer<typeof hostSchema>;
661
- declare const tunnelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
662
- type: z.ZodLiteral<"tailscale">;
663
- id: z.ZodString;
664
- sectionName: z.ZodString;
665
- authKey: z.ZodObject<{
666
- type: z.ZodLiteral<"env">;
667
- name: z.ZodString;
668
- }, z.core.$strict>;
669
- hostname: z.ZodString;
670
- dnsServer: z.ZodOptional<z.ZodArray<z.ZodString>>;
671
- autoAddMagicDnsRule: z.ZodOptional<z.ZodBoolean>;
672
- idleKeepalive: z.ZodOptional<z.ZodNumber>;
673
- }, z.core.$strict>, z.ZodObject<{
674
- type: z.ZodLiteral<"wireguard">;
675
- id: z.ZodString;
676
- sectionName: z.ZodString;
677
- privateKey: z.ZodObject<{
678
- type: z.ZodLiteral<"env">;
679
- name: z.ZodString;
680
- }, z.core.$strict>;
681
- selfIp: z.ZodString;
682
- dnsServer: z.ZodOptional<z.ZodArray<z.ZodString>>;
683
- mtu: z.ZodOptional<z.ZodNumber>;
684
- peers: z.ZodArray<z.ZodObject<{
685
- publicKey: z.ZodString;
686
- endpoint: z.ZodString;
687
- allowedIps: z.ZodArray<z.ZodString>;
688
- presharedKey: z.ZodOptional<z.ZodObject<{
689
- type: z.ZodLiteral<"env">;
690
- name: z.ZodString;
691
- }, z.core.$strict>>;
692
- persistentKeepalive: z.ZodOptional<z.ZodNumber>;
693
- }, z.core.$strict>>;
694
- }, z.core.$strict>], "type">;
695
- type SurgeTunnel = z.infer<typeof tunnelSchema>;
696
- declare const groupSchema: z.ZodObject<{
697
- id: z.ZodString;
698
- type: z.ZodEnum<{
699
- select: "select";
700
- smart: "smart";
701
- }>;
702
- members: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
703
- ref: z.ZodString;
704
- }, z.core.$strict>, z.ZodObject<{
705
- builtin: z.ZodEnum<{
706
- DIRECT: "DIRECT";
707
- REJECT: "REJECT";
708
- "REJECT-DROP": "REJECT-DROP";
709
- "REJECT-NO-DROP": "REJECT-NO-DROP";
710
- "REJECT-TINYGIF": "REJECT-TINYGIF";
711
- }>;
712
- }, z.core.$strict>]>>;
713
- url: z.ZodOptional<z.ZodString>;
714
- intervalSeconds: z.ZodOptional<z.ZodNumber>;
715
- timeoutSeconds: z.ZodOptional<z.ZodNumber>;
716
- }, z.core.$strict>;
717
- type SurgeGroup = z.infer<typeof groupSchema>;
718
- type ConditionOptions = {
719
- readonly noResolve?: boolean;
720
- readonly extendedMatching?: boolean;
721
- };
722
- type SurgeCondition = ConditionOptions & ({
723
- readonly type: "domain" | "domainSuffix" | "ipCidr" | "ipCidr6" | "sourceIp" | "processName" | "macAddress";
724
- readonly value: string;
725
- } | {
726
- readonly type: "port" | "sourcePort";
727
- readonly from: number;
728
- readonly to?: number;
729
- } | {
730
- readonly type: "network";
731
- readonly value: "tcp" | "udp";
732
- } | {
733
- readonly type: "all" | "any";
734
- readonly conditions: readonly SurgeCondition[];
735
- } | {
736
- readonly type: "not";
737
- readonly condition: SurgeCondition;
738
- } | {
739
- readonly type: "ruleSet";
740
- readonly format: "rule-set" | "domain-set";
741
- readonly url?: string;
742
- readonly builtin?: "LAN" | "SYSTEM";
743
- });
744
- type SurgeRule = {
745
- readonly when: SurgeCondition;
746
- readonly then: SurgePolicy;
747
- };
748
- declare const managedSchema: z.ZodObject<{
749
- url: z.ZodString;
750
- query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
751
- type: z.ZodLiteral<"env">;
752
- name: z.ZodString;
753
- }, z.core.$strict>]>>>;
754
- intervalSeconds: z.ZodNumber;
755
- strict: z.ZodBoolean;
756
- }, z.core.$strict>;
757
- type SurgeProfileInput = {
758
- readonly target: {
759
- readonly engine: "surge";
760
- readonly platform: "macos" | "ios";
761
- readonly version: string;
762
- };
763
- readonly managed?: z.infer<typeof managedSchema>;
764
- readonly general?: SurgeGeneral;
765
- readonly hosts?: readonly SurgeHost[];
766
- readonly nodes: readonly ProxyNode[];
767
- readonly tunnels?: readonly SurgeTunnel[];
768
- readonly groups: readonly SurgeGroup[];
769
- readonly rules: readonly SurgeRule[];
770
- readonly fallback: SurgePolicy;
771
- readonly names?: Readonly<Record<string, string>>;
772
- };
773
- type SurgeProfileCompilation = {
774
- readonly ok: boolean;
775
- readonly artifactKind: "surge-profile";
776
- readonly diagnostics: readonly Diagnostic[];
777
- readonly bindings: readonly {
778
- readonly id: string;
779
- readonly nativeName: string;
780
- }[];
781
- };
782
- type SurgeProfileArtifact = {
783
- readonly artifactKind: "surge-profile";
784
- readonly content: string;
785
- };
786
- export declare function compileSurgeProfile(input: unknown): SurgeProfileCompilation;
787
- export declare function renderSurgeProfile(compilation: SurgeProfileCompilation, resolveSecret: (token: Secret) => string | undefined): SurgeProfileArtifact;
788
- export declare function renderSurgeProfiles(compilations: readonly SurgeProfileCompilation[], resolveSecret: (token: Secret) => string | undefined): readonly SurgeProfileArtifact[];
789
- //#endregion
790
847
  //#region src/surge-compose.d.ts
791
848
  /** Bind shared names only for included resources; explicit input mappings remain compiler-checked. */
792
849
  export declare function surgeProfile(input: SurgeProfileInput, names?: Readonly<Record<string, string>>): SurgeProfileInput;
@@ -797,4 +854,87 @@ export declare function surgeMembers(nodes: readonly ProxyNode[], query?: Parame
797
854
  /** Complete-profile batches use the out symlink protocol; the Program host remains unchanged. */
798
855
  export declare function buildSurgeProfilesToDirectory(profiles: Readonly<Record<string, SurgeProfileInput>>, output: string, resolveSecret?: (token: Secret) => string | undefined): Promise<BuildResult>;
799
856
  //#endregion
800
- export type { Artifact, BuildResult, CaseResult, Compilation, ProxyBuilder, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, StrategyGroupCompilation, StrategyGroupInput, SurgeCondition, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };
857
+ //#region src/surge-definitions.d.ts
858
+ type Builtin = Extract<SurgePolicy, {
859
+ builtin: string;
860
+ }>;
861
+ type Destination = ProxyNode | ProxyGroupDefinition | SurgeTunnel | Builtin;
862
+ type ProxyGroupDefinition = {
863
+ readonly type: "proxy-group";
864
+ readonly id: string;
865
+ readonly name: string;
866
+ readonly algorithm: Extract<GroupAlgorithm, {
867
+ type: "select" | "surge-smart";
868
+ }>;
869
+ readonly members: readonly Destination[];
870
+ readonly url?: string;
871
+ readonly intervalSeconds?: number;
872
+ readonly timeoutSeconds?: number;
873
+ };
874
+ type RouteDefinition = {
875
+ readonly type: "route";
876
+ readonly when: SurgeCondition;
877
+ readonly to: Destination;
878
+ };
879
+ type SurgeProfileDefinition = Omit<SurgeProfileInput, "groups" | "rules" | "fallback"> & {
880
+ readonly groups: readonly ProxyGroupDefinition[];
881
+ readonly routes: readonly RouteDefinition[];
882
+ readonly fallback: Destination;
883
+ };
884
+ export declare class ProfileDefinitionError extends Error {
885
+ readonly code: string;
886
+ constructor(code: string);
887
+ }
888
+ export declare const outbound: {
889
+ direct: Readonly<{
890
+ readonly builtin: "DIRECT";
891
+ }>;
892
+ reject: Readonly<{
893
+ readonly builtin: "REJECT";
894
+ }>;
895
+ rejectDrop: Readonly<{
896
+ readonly builtin: "REJECT-DROP";
897
+ }>;
898
+ rejectNoDrop: Readonly<{
899
+ readonly builtin: "REJECT-NO-DROP";
900
+ }>;
901
+ rejectTinyGif: Readonly<{
902
+ readonly builtin: "REJECT-TINYGIF";
903
+ }>;
904
+ };
905
+ export declare function defineProxyGroup(input: Omit<ProxyGroupDefinition, "type">): ProxyGroupDefinition;
906
+ export declare function defineRoute(input: Omit<RouteDefinition, "type">): RouteDefinition;
907
+ export declare function defineRoutes(input: {
908
+ readonly when: readonly SurgeCondition[];
909
+ readonly to: Destination;
910
+ }): RouteDefinition[];
911
+ export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
912
+ ids?: readonly string[];
913
+ regions?: readonly string[];
914
+ providers?: readonly string[];
915
+ tags?: readonly string[];
916
+ }): ProxyNode[];
917
+ export declare function defineSurgeProfile(input: SurgeProfileDefinition): SurgeProfileInput;
918
+ //#endregion
919
+ //#region src/surge-build.d.ts
920
+ type SurgeBuildContext = {
921
+ readonly validation: boolean;
922
+ };
923
+ type SurgeBuildDefinition = {
924
+ readonly profiles: Readonly<Record<string, SurgeProfileInput>>;
925
+ readonly preflight?: () => readonly string[];
926
+ readonly resolveSecret?: (token: Secret, context: SurgeBuildContext) => string | undefined;
927
+ };
928
+ type SurgeBuildResult = BuildResult & {
929
+ readonly warnings: Readonly<Record<string, number>>;
930
+ readonly validation: boolean;
931
+ readonly profileCount: number;
932
+ };
933
+ /** Capture data and callback references before application preflight can change its source. */
934
+ export declare function defineSurgeBuild(input: SurgeBuildDefinition): SurgeBuildDefinition;
935
+ /** Pure orchestration result; the CLI owns stdout and process exit status. */
936
+ export declare function runSurgeBuild(input: SurgeBuildDefinition, output: string, options?: {
937
+ readonly validation?: boolean;
938
+ }): Promise<SurgeBuildResult>;
939
+ //#endregion
940
+ export type { Artifact, BuildResult, CaseResult, Compilation, Destination, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, StrategyGroupCompilation, StrategyGroupInput, SurgeBuildContext, SurgeBuildDefinition, SurgeBuildResult, SurgeCondition, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileDefinition, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };