serviceAuthority.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. export const SERVICE_AUTHORITY_MODE_ENV = "ZCODE_SERVICE_AUTHORITY_MODE";
  2. export const serviceAuthorityModes = [
  3. "desktop-local",
  4. "desktop-attached-remote",
  5. "standalone-server",
  6. ] as const;
  7. export type ServiceAuthorityMode = (typeof serviceAuthorityModes)[number];
  8. export function isServiceAuthorityMode(value: unknown): value is ServiceAuthorityMode {
  9. return typeof value === "string" && serviceAuthorityModes.includes(value as ServiceAuthorityMode);
  10. }
  11. export function parseServiceAuthorityMode(env: Record<string, string | undefined>): {
  12. mode: ServiceAuthorityMode | undefined;
  13. invalidRawValue: string | undefined;
  14. } {
  15. const rawValue = env[SERVICE_AUTHORITY_MODE_ENV]?.trim();
  16. if (!rawValue) {
  17. return {
  18. mode: undefined,
  19. invalidRawValue: undefined,
  20. };
  21. }
  22. if (isServiceAuthorityMode(rawValue)) {
  23. return {
  24. mode: rawValue,
  25. invalidRawValue: undefined,
  26. };
  27. }
  28. return {
  29. mode: undefined,
  30. invalidRawValue: rawValue,
  31. };
  32. }
  33. export function shouldUseProviderRegistrySourceForAuthorityMode(
  34. mode: ServiceAuthorityMode | undefined,
  35. ): boolean {
  36. return mode !== "desktop-attached-remote";
  37. }