pepr 0.3.2 → 0.4.0

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 (103) hide show
  1. package/dist/cli.d.ts +3 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +1420 -0
  4. package/dist/controller.js +157 -0
  5. package/dist/{src/lib → lib}/capability.d.ts +1 -1
  6. package/dist/lib/capability.d.ts.map +1 -0
  7. package/dist/lib/controller.d.ts.map +1 -0
  8. package/dist/{src/lib → lib}/fetch.d.ts +1 -2
  9. package/dist/lib/fetch.d.ts.map +1 -0
  10. package/dist/{src/lib → lib}/filter.d.ts +1 -1
  11. package/dist/lib/filter.d.ts.map +1 -0
  12. package/dist/lib/k8s/index.d.ts.map +1 -0
  13. package/dist/lib/k8s/kinds.d.ts.map +1 -0
  14. package/dist/lib/k8s/tls.d.ts.map +1 -0
  15. package/dist/lib/k8s/types.d.ts.map +1 -0
  16. package/dist/{src/lib → lib}/k8s/upstream.d.ts +2 -2
  17. package/dist/lib/k8s/upstream.d.ts.map +1 -0
  18. package/dist/{src/lib → lib}/k8s/webhook.d.ts +1 -1
  19. package/dist/lib/k8s/webhook.d.ts.map +1 -0
  20. package/dist/lib/logger.d.ts.map +1 -0
  21. package/dist/lib/module.d.ts.map +1 -0
  22. package/dist/lib/processor.d.ts.map +1 -0
  23. package/dist/{src/lib → lib}/request.d.ts +1 -1
  24. package/dist/lib/request.d.ts.map +1 -0
  25. package/dist/{src/lib → lib}/types.d.ts +5 -1
  26. package/dist/lib/types.d.ts.map +1 -0
  27. package/dist/{src/lib/index.d.ts → lib.d.ts} +8 -8
  28. package/dist/lib.d.ts.map +1 -0
  29. package/dist/lib.js +1150 -0
  30. package/dist/lib.js.map +7 -0
  31. package/package.json +8 -12
  32. package/src/cli.ts +37 -0
  33. package/src/lib/capability.ts +2 -1
  34. package/src/lib/controller.ts +15 -1
  35. package/src/lib/fetch.ts +3 -2
  36. package/src/lib/filter.ts +1 -1
  37. package/src/lib/k8s/upstream.ts +2 -2
  38. package/src/lib/k8s/webhook.ts +8 -3
  39. package/src/lib/module.ts +3 -2
  40. package/src/lib/processor.ts +2 -2
  41. package/src/lib/request.ts +4 -4
  42. package/src/lib/types.ts +6 -1
  43. package/src/{lib/index.ts → lib.ts} +7 -7
  44. package/dist/package.json +0 -66
  45. package/dist/src/cli/banner.js +0 -70
  46. package/dist/src/cli/build.js +0 -120
  47. package/dist/src/cli/capability.js +0 -14
  48. package/dist/src/cli/deploy.js +0 -54
  49. package/dist/src/cli/dev.js +0 -114
  50. package/dist/src/cli/index.js +0 -35
  51. package/dist/src/cli/init/index.js +0 -81
  52. package/dist/src/cli/init/templates/.prettierrc.json +0 -13
  53. package/dist/src/cli/init/templates/capabilities/hello-pepr.samples.json +0 -115
  54. package/dist/src/cli/init/templates/data.json +0 -1
  55. package/dist/src/cli/init/templates/pepr.code-snippets.json +0 -21
  56. package/dist/src/cli/init/templates/tsconfig.module.json +0 -12
  57. package/dist/src/cli/init/templates.js +0 -96
  58. package/dist/src/cli/init/utils.js +0 -56
  59. package/dist/src/cli/init/walkthrough.js +0 -84
  60. package/dist/src/cli/root.js +0 -21
  61. package/dist/src/cli/run.js +0 -58
  62. package/dist/src/cli/test.js +0 -50
  63. package/dist/src/cli/update.js +0 -58
  64. package/dist/src/lib/capability.d.ts.map +0 -1
  65. package/dist/src/lib/capability.js +0 -125
  66. package/dist/src/lib/controller.d.ts.map +0 -1
  67. package/dist/src/lib/controller.js +0 -108
  68. package/dist/src/lib/fetch.d.ts.map +0 -1
  69. package/dist/src/lib/fetch.js +0 -92
  70. package/dist/src/lib/filter.d.ts.map +0 -1
  71. package/dist/src/lib/filter.js +0 -77
  72. package/dist/src/lib/index.d.ts.map +0 -1
  73. package/dist/src/lib/index.js +0 -26
  74. package/dist/src/lib/k8s/index.d.ts.map +0 -1
  75. package/dist/src/lib/k8s/index.js +0 -39
  76. package/dist/src/lib/k8s/kinds.d.ts.map +0 -1
  77. package/dist/src/lib/k8s/kinds.js +0 -447
  78. package/dist/src/lib/k8s/tls.d.ts.map +0 -1
  79. package/dist/src/lib/k8s/tls.js +0 -74
  80. package/dist/src/lib/k8s/types.d.ts.map +0 -1
  81. package/dist/src/lib/k8s/types.js +0 -20
  82. package/dist/src/lib/k8s/upstream.d.ts.map +0 -1
  83. package/dist/src/lib/k8s/upstream.js +0 -50
  84. package/dist/src/lib/k8s/webhook.d.ts.map +0 -1
  85. package/dist/src/lib/k8s/webhook.js +0 -502
  86. package/dist/src/lib/logger.d.ts.map +0 -1
  87. package/dist/src/lib/logger.js +0 -125
  88. package/dist/src/lib/module.d.ts.map +0 -1
  89. package/dist/src/lib/module.js +0 -43
  90. package/dist/src/lib/processor.d.ts.map +0 -1
  91. package/dist/src/lib/processor.js +0 -85
  92. package/dist/src/lib/request.d.ts.map +0 -1
  93. package/dist/src/lib/request.js +0 -124
  94. package/dist/src/lib/types.d.ts.map +0 -1
  95. package/dist/src/lib/types.js +0 -34
  96. /package/dist/{src/lib → lib}/controller.d.ts +0 -0
  97. /package/dist/{src/lib → lib}/k8s/index.d.ts +0 -0
  98. /package/dist/{src/lib → lib}/k8s/kinds.d.ts +0 -0
  99. /package/dist/{src/lib → lib}/k8s/tls.d.ts +0 -0
  100. /package/dist/{src/lib → lib}/k8s/types.d.ts +0 -0
  101. /package/dist/{src/lib → lib}/logger.d.ts +0 -0
  102. /package/dist/{src/lib → lib}/module.d.ts +0 -0
  103. /package/dist/{src/lib → lib}/processor.d.ts +0 -0
@@ -1,70 +0,0 @@
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
- exports.banner = void 0;
6
- exports.banner = `                                                                                                                                           
7
-                                                                                                                                            
8
-                                                                                                                                            
9
-                                                                                                                                            
10
-                                                                                                                                            
11
-                                                      ............                                              .............               
12
-                                                        (..*(#%%#.....                                       ....,(%%((,../                 
13
-                                                           ..(((.%%%....                                   ....%%%.,((..                    
14
-                                                           /..(((%%%.%%..                                 ..(%.%%%(((..#                    
15
-                                                            ..((((/.%%%(..              ...              ..,%%%,.((((..                     
16
-                                                            ..((((%%%%%*...            ./%..            ....%%%%%((((..                     
17
-                                                            ...(((#%%%.*%...         #.((%%..          ...%%.%%%%(((...                     
18
-                                                            ..(((((%%%%%%%............((..%%............./%%%%%%#((((..                     
19
-                                                            ..((((#%%%%%%#.%..*..,*/..(..%..%.*/**../..#,.%%%%%%%((((..                     
20
-                                                            ....(((%%%%%/%%%...//.//....(%%....//.//*..%%%/%%%%%#((...*                     
21
-                                                             ...((,*%%%%%%%(..*/////...((%%%...//.//*...%%%%%%%%(((/..                      
22
-                                                  .          ..../(((#%%%#...*//////*.*((%%%%..//////*,..,#%%#((((....(         ..          
23
-                                                 .......    ...**.........***///////..(((%%%%(.///////***.........,**..   *,......          
24
-                                                 ...*,..........**********//////////,.*((%%%%*.///////////*********..........***..          
25
-                                                 ...///*********.,*///////////////////........///////////////////*.********////...          
26
-                                                  ...*////////////////////.......//////////////////.......,///////////////////...           
27
-                                                   *...////////////////../@@@.......////////////,......(@@@..///////////////....            
28
-                                                     /....////////////..@@@..%..**...//////////...#/..%%.@@@..*//////////.....              
29
-                                                        ......///////..*@@.,%..@@@@...////////*..@@@@..%%.@@@.*//////,....*                 
30
-                                                          ......,/////.%@@.%%..,@@*...////////.../@@...*%.@@@./////*.....,                  
31
-                                                       ,...///////////./@@./%.........////////.........#(.@@@.///////////...                
32
-                                                       .....//////////..@@@.(@@,......////////,......@@(.,@@(./////////.....                
33
-                                                           ,....///////...&@..(......./////////......(,.@@...///////..,#                    
34
-                                                              ..///////////////////**//////////***/////////////////...                      
35
-                                                   ....       *../////////////////////////////////////////////////...                       
36
-                                                ...*//,../      ...////////////////////////////,////////////////,...                        
37
-                                              ...////////...     ....///////////.//////*//////,////.//////////....                          
38
-                                           ,..*///.....///*,...     *....////////*.....*/////,.../////////,....%                            
39
-                    ...                   ..///...((./(...//***....   .........*///..####....///////.......&                                
40
-                 ,.,%(.                 ,../*..((((%.((((*...*****,.....,/****.....////,.*///////.....(..                                   
41
-                ..((%%%...             ../,..(#%%%%%./(%%(((/...,****...///////**,................((((,..                                   
42
-                ..((%%%%%..           ..*..#%%%%%%%%..(%%%%%((((/....../////////,*******..*(((((((%%%%...(                                  
43
-                ..(((%%%%....        ....%#........%%.(%%%%%%%%%%(...,///////////.******..((%%%%%%%%%%....*                                 
44
-             ..  ..((%%%.%(.%       ......%        ....%*....*#(....//////,///////..***...(#%%%%%%%%%%...*..                                
45
-             .(...(((%%%*%(..,      ..(              ....   ....****..////./////////.....((%%%%%%%%%%%(..//...                              
46
-             ..((%%%%%..#%%((..                           ...****/////////..//////////*..,(((%%%%%%%%%%..////..(                            
47
-              ...(#%%...../((..                          ...***////////////..*///////////*.../(((%%%%%%..,////..%                           
48
-                 ......//**...                         ....,**//////////////..*//////////////...(%%%%%%..,////...                           
49
-                      ,.*//***...,                /.....,..***///////////////..**/////////////...%%%%%%..*////...                           
50
-                        ..///****...................******.,*/////////////////..****/////////*..%%%%%%(..//**,..                            
51
-                         ...////********,,,,,***********,,..*//////////////////...**********...%%%%%%%..,***...                             
52
-                           ...//////*****************,...,...*//////////////////*.....,,,....#%%%%%%%.........                              
53
-                             ...,////////////////////..*****..///////////////////*,..((/#%%%%%%%%%%*../                                     
54
-                               /..../////////////////..**/////.//////////////////**...(((%%%%%%%%/...                                       
55
-                                   ...../////////////...////////////////////////***...(((%%%%%(....                                         
56
-                                       ,........,*////..*/////////////////////****...(((%,.....,*..*                                        
57
-                                               /(........//////////*....,*****............******//...                                       
58
-                                                       /..///////////**,..%/*(      ..,**//////////../                                      
59
-                                                        ..//////////////...         ...**//////////*..                                      
60
-                                                        ..///////////*///..%         ..**////////*//..(                                     
61
-                                                        ..////.//////..//../         ..**////.///.,*..*                                     
62
-                                                        ..////../////..//..#         ..**///*.///..*..                                      
63
-                                                       ..///**.,///**..*...         ,..**///..**.....                                       
64
-                                                       ..,**,..*****......           #...........#                                          
65
-                                                         ..., ,.......                                                                      
66
-                                                                                                                                            
67
-                                                                                                                                            
68
-                                                                                                                                            
69
-                                                                                                                                            
70
- `;
@@ -1,120 +0,0 @@
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 plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
11
- const plugin_typescript_1 = __importDefault(require("@rollup/plugin-typescript"));
12
- const fs_1 = require("fs");
13
- const path_1 = require("path");
14
- const rollup_1 = require("rollup");
15
- const package_json_1 = require("../../package.json");
16
- const webhook_1 = require("../../src/lib/k8s/webhook");
17
- const logger_1 = __importDefault(require("../../src/lib/logger"));
18
- function default_1(program) {
19
- program
20
- .command("build")
21
- .description("Build a Pepr Module for deployment")
22
- .action(async () => {
23
- // Build the module
24
- const { cfg, path, uuid } = await buildModule();
25
- // Read the compiled module code
26
- const code = await fs_1.promises.readFile(path);
27
- // Generate a secret for the module
28
- const webhook = new webhook_1.Webhook({
29
- ...cfg.pepr,
30
- description: cfg.description,
31
- });
32
- const yamlFile = `pepr-module-${uuid}.yaml`;
33
- const yamlPath = (0, path_1.resolve)("dist", yamlFile);
34
- const yaml = webhook.allYaml(code);
35
- const zarfPath = (0, path_1.resolve)("dist", "zarf.yaml");
36
- const zarf = webhook.zarfYaml(yamlFile);
37
- await fs_1.promises.writeFile(yamlPath, yaml);
38
- await fs_1.promises.writeFile(zarfPath, zarf);
39
- logger_1.default.debug(`Module compiled successfully at ${path}`);
40
- logger_1.default.info(`K8s resource for the module saved to ${yamlPath}`);
41
- });
42
- }
43
- exports.default = default_1;
44
- // Create a list of external libraries to exclude from the bundle, these are already stored in the containe
45
- const externalLibs = Object.keys(package_json_1.dependencies).map(dep => new RegExp(`^${dep}.*`));
46
- // Add the pepr library to the list of external libraries
47
- externalLibs.push("pepr");
48
- async function buildModule() {
49
- try {
50
- // Resolve the path to the module's package.json file
51
- const cfgPath = (0, path_1.resolve)(".", "package.json");
52
- const input = (0, path_1.resolve)(".", "pepr.ts");
53
- // Ensure the module's package.json and pepr.ts files exist
54
- try {
55
- await fs_1.promises.access(cfgPath);
56
- await fs_1.promises.access(input);
57
- }
58
- catch (e) {
59
- logger_1.default.error(`Could not find ${cfgPath} or ${input} in the current directory. Please run this command from the root of your module's directory.`);
60
- process.exit(1);
61
- }
62
- // Read the module's UUID from the package.json file
63
- const moduleText = await fs_1.promises.readFile(cfgPath, { encoding: "utf-8" });
64
- const cfg = JSON.parse(moduleText);
65
- const { uuid } = cfg.pepr;
66
- const name = `pepr-${uuid}.js`;
67
- // Read the module's version from the package.json file
68
- if (cfg.dependencies.pepr && !cfg.dependencies.pepr.includes("file:")) {
69
- const versionMatch = /(\d+\.\d+\.\d+)/.exec(cfg.dependencies.pepr);
70
- if (!versionMatch || versionMatch.length < 2) {
71
- throw new Error("Could not find the Pepr version in package.json");
72
- }
73
- cfg.pepr.version = versionMatch[1];
74
- }
75
- // Exit if the module's UUID could not be found
76
- if (!uuid) {
77
- throw new Error("Could not load the uuid in package.json");
78
- }
79
- const plugins = [
80
- (0, plugin_node_resolve_1.default)({
81
- preferBuiltins: true,
82
- }),
83
- (0, plugin_json_1.default)(),
84
- (0, plugin_typescript_1.default)({
85
- tsconfig: "./tsconfig.json",
86
- declaration: false,
87
- removeComments: true,
88
- sourceMap: false,
89
- include: ["**/*.ts"],
90
- }),
91
- ];
92
- // Build the module using Rollup
93
- const bundle = await (0, rollup_1.rollup)({
94
- plugins,
95
- external: externalLibs,
96
- treeshake: true,
97
- input,
98
- });
99
- // Write the module to the dist directory
100
- await bundle.write({
101
- dir: "dist",
102
- format: "cjs",
103
- entryFileNames: name,
104
- });
105
- return {
106
- path: (0, path_1.resolve)("dist", name),
107
- cfg,
108
- uuid,
109
- };
110
- }
111
- catch (e) {
112
- // On any other error, exit with a non-zero exit code
113
- logger_1.default.debug(e);
114
- if (e instanceof Error) {
115
- logger_1.default.error(e.message);
116
- }
117
- process.exit(1);
118
- }
119
- }
120
- exports.buildModule = buildModule;
@@ -1,14 +0,0 @@
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
- .action(() => {
10
- // TODO: Create a new capability
11
- console.log("new");
12
- });
13
- }
14
- exports.default = default_1;
@@ -1,54 +0,0 @@
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 prompts_1 = require("prompts");
10
- const webhook_1 = require("../../src/lib/k8s/webhook");
11
- const logger_1 = __importDefault(require("../../src/lib/logger"));
12
- const build_1 = require("./build");
13
- function default_1(program) {
14
- program
15
- .command("deploy")
16
- .description("Deploy a Pepr Module")
17
- .option("-i, --image [image]", "Override the image tag")
18
- .option("--confirm", "Skip confirmation prompt")
19
- .action(async (opts) => {
20
- if (!opts.confirm) {
21
- // Prompt the user to confirm
22
- const confirm = await (0, prompts_1.prompt)({
23
- type: "confirm",
24
- name: "confirm",
25
- message: "This will remove and redeploy the module. Continue?",
26
- });
27
- // Exit if the user doesn't confirm
28
- if (!confirm.confirm) {
29
- process.exit(0);
30
- }
31
- }
32
- // Build the module
33
- const { cfg, path } = await (0, build_1.buildModule)();
34
- // Read the compiled module code
35
- const code = await fs_1.promises.readFile(path);
36
- // Generate a secret for the module
37
- const webhook = new webhook_1.Webhook({
38
- ...cfg.pepr,
39
- description: cfg.description,
40
- });
41
- if (opts.image) {
42
- webhook.image = opts.image;
43
- }
44
- try {
45
- await webhook.deploy(code);
46
- logger_1.default.info(`Module deployed successfully`);
47
- }
48
- catch (e) {
49
- logger_1.default.error(`Error deploying module: ${e}`);
50
- process.exit(1);
51
- }
52
- });
53
- }
54
- exports.default = default_1;
@@ -1,114 +0,0 @@
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("../../src/lib/k8s/webhook");
14
- const logger_1 = __importDefault(require("../../src/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("-h, --host [host]", "Host to listen on", "host.k3d.internal")
21
- .option("--confirm", "Skip confirmation prompt")
22
- .action(async (opts) => {
23
- // Prompt the user to confirm if they didn't pass the --confirm flag
24
- if (!opts.confirm) {
25
- const confirm = await (0, prompts_1.prompt)({
26
- type: "confirm",
27
- name: "confirm",
28
- message: "This will remove and redeploy the module. Continue?",
29
- });
30
- // Exit if the user doesn't confirm
31
- if (!confirm.confirm) {
32
- process.exit(0);
33
- }
34
- }
35
- // Build the module
36
- const { cfg, path } = await (0, build_1.buildModule)();
37
- // Read the compiled module code
38
- const code = await fs_1.promises.readFile(path);
39
- // Generate a secret for the module
40
- const webhook = new webhook_1.Webhook({
41
- ...cfg.pepr,
42
- description: cfg.description,
43
- }, opts.host);
44
- // Write the TLS cert and key to disk
45
- await fs_1.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
46
- await fs_1.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
47
- try {
48
- await webhook.deploy(code);
49
- logger_1.default.info(`Module deployed successfully`);
50
- const moduleFiles = [
51
- (0, path_1.resolve)(".", "pepr.ts"),
52
- (0, path_1.resolve)(".", "capabilities", "*.ts"),
53
- (0, path_1.resolve)(".", "capabilities", "**", "*.ts"),
54
- ];
55
- const watcher = (0, chokidar_1.watch)(moduleFiles, {
56
- awaitWriteFinish: {
57
- stabilityThreshold: 3000,
58
- pollInterval: 500,
59
- },
60
- });
61
- // Watch for changes
62
- watcher.on("ready", async () => {
63
- let building = false;
64
- // Run the module once to start the server
65
- let program = await runDev();
66
- logger_1.default.info(`Watching for changes in ${moduleFiles}`);
67
- watcher.on("all", async (event, path) => {
68
- logger_1.default.debug({ event, path }, "File changed");
69
- // If we're already building, skip this event
70
- if (building) {
71
- return;
72
- }
73
- // Set building to true
74
- building = true;
75
- // Don't start a new process until the old one exits
76
- program.once("exit", async () => {
77
- program = await runDev();
78
- building = false;
79
- });
80
- // Kill the running process
81
- program.kill();
82
- });
83
- });
84
- }
85
- catch (e) {
86
- logger_1.default.error(`Error deploying module: ${e}`);
87
- process.exit(1);
88
- }
89
- });
90
- }
91
- exports.default = default_1;
92
- async function runDev() {
93
- try {
94
- const path = (0, path_1.resolve)(".", "pepr.ts");
95
- logger_1.default.info(`Running module ${path}`);
96
- const program = (0, child_process_1.fork)(path, {
97
- // Register ts-node
98
- execArgv: ["-r", "ts-node/register"],
99
- // Pass the environment variables
100
- env: {
101
- ...process.env,
102
- LOG_LEVEL: "debug",
103
- SSL_KEY_PATH: "insecure-tls.key",
104
- SSL_CERT_PATH: "insecure-tls.crt",
105
- },
106
- });
107
- return program;
108
- }
109
- catch (e) {
110
- logger_1.default.debug(e);
111
- logger_1.default.error(`Error running module: ${e}`);
112
- process.exit(1);
113
- }
114
- }