pepr 0.1.27 → 0.1.29

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.
Files changed (62) hide show
  1. package/cli.ts +3 -0
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +4 -0
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.js +14 -0
  6. package/dist/package.json +76 -0
  7. package/dist/src/cli/banner.d.ts +1 -0
  8. package/dist/{pepr-cli.js → src/cli/banner.js} +4 -1251
  9. package/dist/src/cli/build.d.ts +7 -0
  10. package/dist/src/cli/build.js +102 -0
  11. package/dist/src/cli/capability.d.ts +2 -0
  12. package/dist/src/cli/capability.js +15 -0
  13. package/dist/src/cli/deploy.d.ts +2 -0
  14. package/dist/src/cli/deploy.js +55 -0
  15. package/dist/src/cli/dev.d.ts +2 -0
  16. package/dist/src/cli/dev.js +96 -0
  17. package/dist/src/cli/index.d.ts +1 -0
  18. package/dist/src/cli/index.js +33 -0
  19. package/dist/src/cli/init/index.d.ts +2 -0
  20. package/dist/src/cli/init/index.js +54 -0
  21. package/dist/src/cli/init/templates.d.ts +82 -0
  22. package/dist/src/cli/init/templates.js +229 -0
  23. package/dist/src/cli/init/utils.d.ts +20 -0
  24. package/dist/src/cli/init/utils.js +56 -0
  25. package/dist/src/cli/init/walkthrough.d.ts +7 -0
  26. package/dist/src/cli/init/walkthrough.js +84 -0
  27. package/dist/src/cli/root.d.ts +4 -0
  28. package/dist/src/cli/root.js +21 -0
  29. package/dist/src/cli/test.d.ts +2 -0
  30. package/dist/src/cli/test.js +51 -0
  31. package/dist/src/lib/capability.d.ts +26 -0
  32. package/dist/src/lib/capability.js +119 -0
  33. package/dist/src/lib/controller.d.ts +13 -0
  34. package/dist/src/lib/controller.js +84 -0
  35. package/dist/src/lib/filter.d.ts +10 -0
  36. package/dist/src/lib/filter.js +48 -0
  37. package/dist/src/lib/k8s/index.d.ts +4 -0
  38. package/dist/src/lib/k8s/index.js +38 -0
  39. package/dist/src/lib/k8s/kinds.d.ts +3 -0
  40. package/dist/src/lib/k8s/kinds.js +431 -0
  41. package/dist/src/lib/k8s/tls.d.ts +17 -0
  42. package/dist/src/lib/k8s/tls.js +74 -0
  43. package/dist/src/lib/k8s/types.d.ts +136 -0
  44. package/dist/src/lib/k8s/types.js +12 -0
  45. package/dist/src/lib/k8s/upstream.d.ts +1 -0
  46. package/dist/src/lib/k8s/upstream.js +47 -0
  47. package/dist/src/lib/k8s/webhook.d.ts +33 -0
  48. package/dist/src/lib/k8s/webhook.js +497 -0
  49. package/dist/src/lib/logger.d.ts +54 -0
  50. package/dist/{types-1709b44f.js → src/lib/logger.js} +6 -39
  51. package/dist/src/lib/module.d.ts +22 -0
  52. package/dist/src/lib/module.js +39 -0
  53. package/dist/src/lib/processor.d.ts +4 -0
  54. package/dist/src/lib/processor.js +73 -0
  55. package/dist/src/lib/request.d.ts +77 -0
  56. package/dist/src/lib/request.js +144 -0
  57. package/dist/src/lib/types.d.ts +187 -0
  58. package/dist/src/lib/types.js +34 -0
  59. package/package.json +8 -11
  60. package/tsconfig.build.json +4 -0
  61. package/dist/pepr-core.js +0 -949
  62. package/tsconfig.json +0 -17
@@ -0,0 +1,7 @@
1
+ import { RootCmd } from "./root";
2
+ export default function (program: RootCmd): void;
3
+ export declare function buildModule(moduleDir: string): Promise<{
4
+ path: string;
5
+ cfg: any;
6
+ uuid: any;
7
+ }>;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.buildModule = void 0;
9
+ const plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
10
+ const package_json_1 = require("../../package.json");
11
+ const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
12
+ const plugin_typescript_1 = __importDefault(require("@rollup/plugin-typescript"));
13
+ const fs_1 = require("fs");
14
+ const path_1 = require("path");
15
+ const rollup_1 = require("rollup");
16
+ const logger_1 = __importDefault(require("../lib/logger"));
17
+ const webhook_1 = require("../lib/k8s/webhook");
18
+ function default_1(program) {
19
+ program
20
+ .command("build")
21
+ .description("Build a Pepr Module for deployment")
22
+ .option("-d, --dir [directory]", "Pepr module directory", ".")
23
+ .action(async (opts) => {
24
+ // Build the module
25
+ const { cfg, path, uuid } = await buildModule(opts.dir);
26
+ // Read the compiled module code
27
+ const code = await fs_1.promises.readFile(path, { encoding: "utf-8" });
28
+ // Generate a secret for the module
29
+ const webhook = new webhook_1.Webhook({
30
+ ...cfg.pepr,
31
+ description: cfg.description,
32
+ });
33
+ const yamlFile = `pepr-module-${uuid}.yaml`;
34
+ const yamlPath = (0, path_1.resolve)("dist", yamlFile);
35
+ const yaml = webhook.allYaml(code);
36
+ const zarfPath = (0, path_1.resolve)("dist", "zarf.yaml");
37
+ const zarf = webhook.zarfYaml(yamlFile);
38
+ await fs_1.promises.writeFile(yamlPath, yaml);
39
+ await fs_1.promises.writeFile(zarfPath, zarf);
40
+ logger_1.default.debug(`Module compiled successfully at ${path}`);
41
+ logger_1.default.info(`K8s resource for the module saved to ${yamlPath}`);
42
+ });
43
+ }
44
+ exports.default = default_1;
45
+ // Create a list of external libraries to exclude from the bundle, these are already stored in the containe
46
+ const externalLibs = Object.keys(package_json_1.dependencies).map(dep => new RegExp(`^${dep}.*`));
47
+ // Add the pepr library to the list of external libraries
48
+ externalLibs.push("pepr");
49
+ async function buildModule(moduleDir) {
50
+ try {
51
+ // Resolve the path to the module's package.json file
52
+ const cfgPath = (0, path_1.resolve)(moduleDir, "package.json");
53
+ const input = (0, path_1.resolve)(moduleDir, "pepr.ts");
54
+ // Read the module's UUID from the package.json filel
55
+ const moduleText = await fs_1.promises.readFile(cfgPath, { encoding: "utf-8" });
56
+ const cfg = JSON.parse(moduleText);
57
+ const { uuid } = cfg.pepr;
58
+ const name = `pepr-${uuid}.js`;
59
+ // Exit if the module's UUID could not be found
60
+ if (!uuid) {
61
+ throw new Error("Could not load the uuid in package.json");
62
+ }
63
+ const plugins = [
64
+ (0, plugin_node_resolve_1.default)({
65
+ preferBuiltins: true,
66
+ }),
67
+ (0, plugin_json_1.default)(),
68
+ (0, plugin_typescript_1.default)({
69
+ tsconfig: "./tsconfig.json",
70
+ declaration: false,
71
+ removeComments: true,
72
+ sourceMap: false,
73
+ include: ["**/*.ts"],
74
+ }),
75
+ ];
76
+ // Build the module using Rollup
77
+ const bundle = await (0, rollup_1.rollup)({
78
+ plugins,
79
+ external: externalLibs,
80
+ treeshake: true,
81
+ input,
82
+ });
83
+ // Write the module to the dist directory
84
+ await bundle.write({
85
+ dir: "dist",
86
+ format: "cjs",
87
+ entryFileNames: name,
88
+ });
89
+ return {
90
+ path: (0, path_1.resolve)("dist", name),
91
+ cfg,
92
+ uuid,
93
+ };
94
+ }
95
+ catch (e) {
96
+ // On any other error, exit with a non-zero exit code
97
+ logger_1.default.debug(e);
98
+ logger_1.default.error(e.message);
99
+ process.exit(1);
100
+ }
101
+ }
102
+ exports.buildModule = buildModule;
@@ -0,0 +1,2 @@
1
+ import { RootCmd } from "./root";
2
+ export default function (program: RootCmd): void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ function default_1(program) {
6
+ program
7
+ .command("new")
8
+ .description("Create a new Pepr Capability")
9
+ .option("-d, --dir [directory]", "Pepr module directory", ".")
10
+ .action(() => {
11
+ // TODO: Create a new capability
12
+ console.log("new");
13
+ });
14
+ }
15
+ exports.default = default_1;
@@ -0,0 +1,2 @@
1
+ import { RootCmd } from "./root";
2
+ export default function (program: RootCmd): void;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const fs_1 = require("fs");
9
+ const webhook_1 = require("../lib/k8s/webhook");
10
+ const logger_1 = __importDefault(require("../lib/logger"));
11
+ const build_1 = require("./build");
12
+ const prompts_1 = require("prompts");
13
+ function default_1(program) {
14
+ program
15
+ .command("deploy")
16
+ .description("Deploy a Pepr Module")
17
+ .option("-d, --dir [directory]", "Pepr module directory", ".")
18
+ .option("-i, --image [image]", "Override the image tag")
19
+ .option("-f, --force", "Force redeployment")
20
+ .action(async (opts) => {
21
+ if (!opts.force) {
22
+ // Prompt the user to confirm
23
+ const confirm = await (0, prompts_1.prompt)({
24
+ type: "confirm",
25
+ name: "confirm",
26
+ message: "This will remove and redeploy the module. Continue?",
27
+ });
28
+ // Exit if the user doesn't confirm
29
+ if (!confirm.confirm) {
30
+ process.exit(0);
31
+ }
32
+ }
33
+ // Build the module
34
+ const { cfg, path } = await (0, build_1.buildModule)(opts.dir);
35
+ // Read the compiled module code
36
+ const code = await fs_1.promises.readFile(path, { encoding: "utf-8" });
37
+ // Generate a secret for the module
38
+ const webhook = new webhook_1.Webhook({
39
+ ...cfg.pepr,
40
+ description: cfg.description,
41
+ });
42
+ if (opts.image) {
43
+ webhook.image = opts.image;
44
+ }
45
+ try {
46
+ await webhook.deploy(code);
47
+ logger_1.default.info(`Module deployed successfully`);
48
+ }
49
+ catch (e) {
50
+ logger_1.default.error(`Error deploying module: ${e}`);
51
+ process.exit(1);
52
+ }
53
+ });
54
+ }
55
+ exports.default = default_1;
@@ -0,0 +1,2 @@
1
+ import { RootCmd } from "./root";
2
+ export default function (program: RootCmd): void;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const child_process_1 = require("child_process");
9
+ const chokidar_1 = require("chokidar");
10
+ const fs_1 = require("fs");
11
+ const path_1 = require("path");
12
+ const prompts_1 = require("prompts");
13
+ const webhook_1 = require("../lib/k8s/webhook");
14
+ const logger_1 = __importDefault(require("../lib/logger"));
15
+ const build_1 = require("./build");
16
+ function default_1(program) {
17
+ program
18
+ .command("dev")
19
+ .description("Setup a local webhook development environment")
20
+ .option("-d, --dir [directory]", "Pepr module directory", ".")
21
+ .option("-h, --host [host]", "Host to listen on", "host.docker.internal")
22
+ .action(async (opts) => {
23
+ // Prompt the user to confirm
24
+ const confirm = await (0, prompts_1.prompt)({
25
+ type: "confirm",
26
+ name: "confirm",
27
+ message: "This will remove and redeploy the module. Continue?",
28
+ });
29
+ // Exit if the user doesn't confirm
30
+ if (!confirm.confirm) {
31
+ process.exit(0);
32
+ }
33
+ // Build the module
34
+ const { cfg, path } = await (0, build_1.buildModule)(opts.dir);
35
+ // Read the compiled module code
36
+ const code = await fs_1.promises.readFile(path, { encoding: "utf-8" });
37
+ // Generate a secret for the module
38
+ const webhook = new webhook_1.Webhook({
39
+ ...cfg.pepr,
40
+ description: cfg.description,
41
+ }, opts.host);
42
+ // Write the TLS cert and key to disk
43
+ await fs_1.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
44
+ await fs_1.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
45
+ try {
46
+ await webhook.deploy(code);
47
+ logger_1.default.info(`Module deployed successfully`);
48
+ const moduleFiles = (0, path_1.resolve)(opts.dir, "**", "*.ts");
49
+ const watcher = (0, chokidar_1.watch)(moduleFiles);
50
+ const peprTS = (0, path_1.resolve)(opts.dir, "pepr.ts");
51
+ let program;
52
+ // Run the module once to start the server
53
+ runDev(peprTS);
54
+ // Watch for changes
55
+ watcher.on("ready", () => {
56
+ logger_1.default.info(`Watching for changes in ${moduleFiles}`);
57
+ watcher.on("all", async (event, path) => {
58
+ logger_1.default.debug({ event, path }, "File changed");
59
+ // Kill the running process
60
+ if (program) {
61
+ program.kill("SIGKILL");
62
+ }
63
+ // Start the process again
64
+ program = runDev(peprTS);
65
+ });
66
+ });
67
+ }
68
+ catch (e) {
69
+ logger_1.default.error(`Error deploying module: ${e}`);
70
+ process.exit(1);
71
+ }
72
+ });
73
+ }
74
+ exports.default = default_1;
75
+ function runDev(path) {
76
+ try {
77
+ const program = (0, child_process_1.spawn)("./node_modules/.bin/ts-node", [path], {
78
+ env: {
79
+ ...process.env,
80
+ SSL_KEY_PATH: "insecure-tls.key",
81
+ SSL_CERT_PATH: "insecure-tls.crt",
82
+ },
83
+ });
84
+ program.stdout.on("data", data => console.log(data.toString()));
85
+ program.stderr.on("data", data => console.error(data.toString()));
86
+ program.on("close", code => {
87
+ logger_1.default.info(`Process exited with code ${code}`);
88
+ });
89
+ return program;
90
+ }
91
+ catch (e) {
92
+ logger_1.default.debug(e);
93
+ logger_1.default.error(`Error running module: ${e}`);
94
+ process.exit(1);
95
+ }
96
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const package_json_1 = require("../../package.json");
9
+ const banner_1 = require("./banner");
10
+ const build_1 = __importDefault(require("./build"));
11
+ const capability_1 = __importDefault(require("./capability"));
12
+ const deploy_1 = __importDefault(require("./deploy"));
13
+ const dev_1 = __importDefault(require("./dev"));
14
+ const init_1 = __importDefault(require("./init"));
15
+ const root_1 = require("./root");
16
+ const test_1 = __importDefault(require("./test"));
17
+ const program = new root_1.RootCmd();
18
+ program
19
+ .version(package_json_1.version)
20
+ .description(`Pepr Kubernetes Thingy (v${package_json_1.version})`)
21
+ .action(() => {
22
+ if (program.args.length < 1) {
23
+ console.log(banner_1.banner);
24
+ program.help();
25
+ }
26
+ });
27
+ (0, init_1.default)(program);
28
+ (0, build_1.default)(program);
29
+ (0, capability_1.default)(program);
30
+ (0, test_1.default)(program);
31
+ (0, deploy_1.default)(program);
32
+ (0, dev_1.default)(program);
33
+ program.parse();
@@ -0,0 +1,2 @@
1
+ import { RootCmd } from "../root";
2
+ export default function (program: RootCmd): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const child_process_1 = require("child_process");
9
+ const path_1 = require("path");
10
+ const logger_1 = __importDefault(require("../../lib/logger"));
11
+ const templates_1 = require("./templates");
12
+ const utils_1 = require("./utils");
13
+ const walkthrough_1 = require("./walkthrough");
14
+ function default_1(program) {
15
+ program
16
+ .command("init")
17
+ .description("Initialize a new Pepr Module")
18
+ .action(async () => {
19
+ const response = await (0, walkthrough_1.walkthrough)();
20
+ const dirName = (0, utils_1.sanitizeName)(response.name);
21
+ const packageJSON = (0, templates_1.genPkgJSON)(response);
22
+ const peprTS = (0, templates_1.genPeprTS)();
23
+ const confirmed = await (0, walkthrough_1.confirm)(dirName, packageJSON, peprTS.path);
24
+ if (confirmed) {
25
+ console.log("Creating new Pepr module...");
26
+ try {
27
+ await (0, utils_1.createDir)(dirName);
28
+ await (0, utils_1.createDir)((0, path_1.resolve)(dirName, ".vscode"));
29
+ await (0, utils_1.createDir)((0, path_1.resolve)(dirName, "capabilities"));
30
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, templates_1.gitIgnore.path), templates_1.gitIgnore.data);
31
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, templates_1.prettierRC.path), templates_1.prettierRC.data);
32
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, packageJSON.path), packageJSON.data);
33
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, templates_1.readme.path), templates_1.readme.data);
34
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, templates_1.tsConfig.path), templates_1.tsConfig.data);
35
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, peprTS.path), peprTS.data);
36
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, ".vscode", templates_1.capabilitySnippet.path), templates_1.capabilitySnippet.data);
37
+ await (0, utils_1.write)((0, path_1.resolve)(dirName, "capabilities", templates_1.capabilityHelloPeprTS.path), templates_1.capabilityHelloPeprTS.data);
38
+ // run npm install from the new directory
39
+ process.chdir(dirName);
40
+ (0, child_process_1.execSync)("npm install", {
41
+ stdio: "inherit",
42
+ });
43
+ console.log(`New Pepr module created at ${dirName}`);
44
+ console.log(`Open VSCode or your editor of choice in ${dirName} to get started!`);
45
+ }
46
+ catch (e) {
47
+ logger_1.default.debug(e);
48
+ logger_1.default.error(e.message);
49
+ process.exit(1);
50
+ }
51
+ }
52
+ });
53
+ }
54
+ exports.default = default_1;
@@ -0,0 +1,82 @@
1
+ import { InitOptions } from "./walkthrough";
2
+ export declare function genPeprTS(): {
3
+ path: string;
4
+ data: string;
5
+ };
6
+ export declare function genPkgJSON(opts: InitOptions): {
7
+ data: {
8
+ name: string;
9
+ version: string;
10
+ description: any;
11
+ keywords: string[];
12
+ pepr: {
13
+ name: any;
14
+ version: string;
15
+ uuid: string;
16
+ onError: any;
17
+ alwaysIgnore: {
18
+ namespaces: any[];
19
+ labels: any[];
20
+ };
21
+ };
22
+ scripts: {
23
+ build: string;
24
+ start: string;
25
+ };
26
+ dependencies: {
27
+ pepr: string;
28
+ };
29
+ devDependencies: {
30
+ typescript: string;
31
+ };
32
+ };
33
+ path: string;
34
+ print: string;
35
+ };
36
+ export declare const tsConfig: {
37
+ path: string;
38
+ data: {
39
+ compilerOptions: {
40
+ esModuleInterop: boolean;
41
+ lib: string[];
42
+ moduleResolution: string;
43
+ resolveJsonModule: boolean;
44
+ rootDir: string;
45
+ strict: boolean;
46
+ target: string;
47
+ };
48
+ include: string[];
49
+ };
50
+ };
51
+ export declare const gitIgnore: {
52
+ path: string;
53
+ data: string;
54
+ };
55
+ export declare const prettierRC: {
56
+ path: string;
57
+ data: {
58
+ arrowParens: string;
59
+ bracketSameLine: boolean;
60
+ bracketSpacing: boolean;
61
+ embeddedLanguageFormatting: string;
62
+ insertPragma: boolean;
63
+ printWidth: number;
64
+ quoteProps: string;
65
+ requirePragma: boolean;
66
+ semi: boolean;
67
+ tabWidth: number;
68
+ useTabs: boolean;
69
+ };
70
+ };
71
+ export declare const readme: {
72
+ path: string;
73
+ data: string;
74
+ };
75
+ export declare const capabilityHelloPeprTS: {
76
+ path: string;
77
+ data: string;
78
+ };
79
+ export declare const capabilitySnippet: {
80
+ path: string;
81
+ data: string;
82
+ };