From fb043880dedddb45c07d2fb0ded5eafea544c6e1 Mon Sep 17 00:00:00 2001
From: Richard Herman <1429781+GeekyEggo@users.noreply.github.com>
Date: Fri, 16 Feb 2024 14:34:46 +0000
Subject: [PATCH] fix: update UUID validation

---
 src/commands/create.ts                    | 2 +-
 src/commands/link.ts                      | 4 +---
 src/stream-deck.ts                        | 2 +-
 src/validation/plugin/rules/path-input.ts | 4 ++--
 4 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/commands/create.ts b/src/commands/create.ts
index e2122f8..a0f30d6 100644
--- a/src/commands/create.ts
+++ b/src/commands/create.ts
@@ -94,7 +94,7 @@ async function promptForPluginInfo(): Promise<PluginInfo> {
 			default: ({ author, name }: PluginInfo): string | undefined => generatePluginId(author, name),
 			validate: (uuid: string): boolean | string => {
 				if (!isValidPluginId(uuid)) {
-					return "UUID must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), underscores (_), and periods (.).";
+					return "UUID must be in reverse DNS format, and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.).";
 				}
 
 				if (getPlugins().some((p) => p.uuid === uuid)) {
diff --git a/src/commands/link.ts b/src/commands/link.ts
index 10e7c53..3a7481a 100644
--- a/src/commands/link.ts
+++ b/src/commands/link.ts
@@ -27,9 +27,7 @@ export const link = command<LinkOptions>(
 			return feedback
 				.error("Linking failed")
 				.log(`Invalid directory name: ${basename(options.path)}`)
-				.log(
-					'Name should represent a reverse DNS format and have a suffix of ".sdPlugin". Name must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), underscores (_), and periods (.).'
-				)
+				.log('Name must be in reverse DNS format, be suffixed with ".sdPlugin", and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.).')
 				.log(`Examples: ${chalk.green("com.elgato.wave-link.sdPlugin")}, ${chalk.green("tv.twitch.studio.sdPlugin")}`)
 				.exit(1);
 		}
diff --git a/src/stream-deck.ts b/src/stream-deck.ts
index 49dd84a..a1f9613 100644
--- a/src/stream-deck.ts
+++ b/src/stream-deck.ts
@@ -139,7 +139,7 @@ export function isValidPluginId(uuid: string | undefined): boolean {
 		return false;
 	}
 
-	return /^([a-z0-9\-_]*[a-z0-9][a-z0-9\-_]*\.){2}[a-z0-9\-_]*[a-z0-9][a-z0-9\-_]*$/.test(uuid);
+	return /^([a-z0-9-]+)(\.[a-z0-9-]+)+$/.test(uuid);
 }
 
 /**
diff --git a/src/validation/plugin/rules/path-input.ts b/src/validation/plugin/rules/path-input.ts
index 1dab855..c174844 100644
--- a/src/validation/plugin/rules/path-input.ts
+++ b/src/validation/plugin/rules/path-input.ts
@@ -18,8 +18,8 @@ export const pathIsDirectoryAndUuid = rule<PluginContext>(function (plugin: Plug
 	}
 
 	if (!isValidPluginId(plugin.uuid)) {
-		this.addError(this.path, "Name must be a valid UUID in reverse DNS format", {
-			suggestion: "UUIDs must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), underscores (_), and periods (.), for example 'com.elgato.wave-link'"
+		this.addError(this.path, "Name must be in reverse DNS format, and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.)", {
+			suggestion: "Example: 'com.elgato.wave-link'"
 		});
 	}
 });