-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add watch mode to start server cli command (#37)
* add watch mode to start server cli command * update tests * add changeset
- Loading branch information
1 parent
a57a1e8
commit 682012a
Showing
29 changed files
with
219 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@gateweaver/policies": patch | ||
"@gateweaver/server": patch | ||
"@gateweaver/cli": patch | ||
--- | ||
|
||
Update CLI and server with watch config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Command } from "commander"; | ||
import { generateApiKey, hashApiKey } from "@gateweaver/policies"; | ||
|
||
export const generateApiKeyCommand = (program: Command) => { | ||
program | ||
.command("generate-api-key") | ||
.description("Generate a new API key and hash") | ||
.action(() => { | ||
try { | ||
const apiKey = generateApiKey(); | ||
const apiKeyHash = hashApiKey(apiKey); | ||
|
||
console.log("API Key:", apiKey); | ||
console.log("\nHashed API Key:", apiKeyHash); | ||
|
||
console.log( | ||
"\nPlease store the API Key securely and add the hashed API Key to your config file.", // TODO: add link to docs | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { startServerCommand } from "./start"; | ||
export { validateConfigCommand } from "./validate"; | ||
export { generateApiKeyCommand } from "./generate-api-key"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Command } from "commander"; | ||
import { startServer } from "@gateweaver/server"; | ||
|
||
export const startServerCommand = (program: Command) => { | ||
program | ||
.command("start") | ||
.description("Start the gateweaver server") | ||
.option( | ||
"-c, --config <configPath>", | ||
"Path to the config file", | ||
"gateweaver", | ||
) | ||
.option( | ||
"-w, --watch", | ||
"Watch the config file for changes and restart the server", | ||
) | ||
.action((options) => { | ||
try { | ||
startServer(options.config, options.watch); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Command } from "commander"; | ||
import { parseConfig, InvalidConfigError } from "@gateweaver/server"; | ||
|
||
export const validateConfigCommand = (program: Command) => { | ||
program | ||
.command("validate") | ||
.description("Validate a gateweaver config file") | ||
.option( | ||
"-c, --config <configPath>", | ||
"Path to the config file", | ||
"gateweaver", | ||
) | ||
.action((options) => { | ||
try { | ||
parseConfig(options.config); | ||
console.log("✅ Config file is valid"); | ||
} catch (error) { | ||
if (error instanceof InvalidConfigError) { | ||
const validationErrors = error.message.split("\n"); | ||
|
||
console.log("❌ Config file validation errors:"); | ||
validationErrors.forEach((error) => console.log(`- ${error}`)); | ||
} else { | ||
console.log(error); | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./api-key.schema"; | ||
export * from "./api-key.middleware"; | ||
export * from "./utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import crypto from "crypto"; | ||
|
||
export const generateApiKey = (): string => { | ||
return crypto.randomUUID().replace(/-/g, ""); | ||
}; | ||
|
||
export const hashApiKey = (apiKey: string): string => { | ||
return crypto.createHash("sha256").update(apiKey).digest("hex"); | ||
}; | ||
|
||
export const isValidApiKey = ( | ||
apiKey: string | string[], | ||
apiKeyHashes: string[], | ||
) => { | ||
if (typeof apiKey !== "string") return false; | ||
|
||
const apiKeyHash = hashApiKey(apiKey); | ||
return apiKeyHashes.includes(apiKeyHash); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,4 @@ | ||
import { config } from "dotenv"; | ||
config({ path: ".env.gateweaver" }); | ||
import { startServer, logger, InvalidConfigError } from "./utils"; | ||
|
||
try { | ||
startServer(); | ||
} catch (error) { | ||
if (error instanceof InvalidConfigError) { | ||
const validationErrors = error.message.split("\n"); | ||
|
||
logger.error("Invalid config file"); | ||
logger.error(validationErrors); | ||
} else { | ||
logger.error(error); | ||
} | ||
} | ||
export { logger } from "./logger"; | ||
export { startServer } from "./server"; | ||
export { parseConfig } from "./config/parse-config"; | ||
export { InvalidConfigError } from "./config/validate-config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { config } from "dotenv"; | ||
config({ path: ".env.gateweaver" }); | ||
import { logger, startServer } from "."; | ||
|
||
try { | ||
startServer(); | ||
} catch (error) { | ||
logger.error(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.