pepr 0.15.0 → 0.17.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.
@@ -0,0 +1,37 @@
1
+ # Pepr Best Practices (WIP)
2
+
3
+ ## TOC
4
+
5
+ - [Store](#pepr-store)
6
+ - [OnSchedule](#onschedule)
7
+ - [Watch](#watch)
8
+
9
+
10
+ ## Pepr Store
11
+
12
+ The store is backed by ETCD in a `PeprStore` resource, and updates happen at 5-second intervals when an array of patches is sent to the Kubernetes API Server. The store is intentionally not designed to be `transactional`; instead, it is built to be eventually consistent, meaning that the last operation within the interval will be persisted, potentially overwriting other operations. In simpler terms, changes to the data are made without a guarantee that they will occur simultaneously, so caution is needed in managing errors and ensuring consistency.
13
+
14
+
15
+ ## OnSchedule
16
+
17
+ `OnSchedule` is supported by a `PeprStore` to safeguard against schedule loss following a pod restart. It is utilized at the top level, distinct from being within a `Validate`, `Mutate`, or `Watch`. Recommended intervals are 30 seconds or longer, and jobs are advised to be idempotent, meaning that if the code is applied or executed multiple times, the outcome should be the same as if it had been executed only once. A major use-case for `OnSchedule` is day 2 operations.
18
+
19
+ ## Watch
20
+
21
+ Pepr streamlines the process of receiving timely change notifications on resources by employing the `Watch` mechanism. It is advisable to opt for `Watch` over `Mutate` or `Validate` when dealing with more extended operations, as `Watch` does not face any [timeout limitations](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#timeouts). Additionally, `Watch` proves particularly advantageous for monitoring previously existing resources within a cluster. One compelling scenario for leveraging `Watch` is when there is a need to chain API calls together, allowing `Watch` operations to be sequentially executed following `Mutate` and `Validate` actions.
22
+
23
+ ```typescript
24
+ When(a.Pod)
25
+ .IsCreated()
26
+ .InNamespace("my-app")
27
+ .WithName("database")
28
+ .Mutate(pod => // .... )
29
+ .Validate(pod => // .... )
30
+ .Watch(async (pod, phase) => {
31
+ Log.info(pod, `Pod was ${phase}.`);
32
+
33
+ // do consecutive api calls
34
+ ```
35
+
36
+
37
+ [TOP](#pepr-best-practices)
package/README.md CHANGED
@@ -79,8 +79,10 @@ When(a.ConfigMap)
79
79
 
80
80
  ## Prerequisites
81
81
 
82
- - [Node.js](https://nodejs.org/en/) v18.0.0+ (even-numbered releases only).
83
- - To ensure compatability and optimal performance, it is recommended to use even-numbered releases of Node.js as they are stable releases and receive long-term support for three years. Odd-numbered releases are experimental and may not be supported by certain libraries utilized in Pepr.
82
+ - [Node.js](https://nodejs.org/en/) v18.0.0+ (even-numbered releases only)
83
+ - To ensure compatability and optimal performance, it is recommended to use even-numbered releases of Node.js as they are stable releases and receive long-term support for three years. Odd-numbered releases are experimental and may not be supported by certain libraries utilized in Pepr.
84
+
85
+ - [npm](https://www.npmjs.com/) v10.1.0+
84
86
 
85
87
  - Recommended (optional) tools:
86
88
  - [Visual Studio Code](https://code.visualstudio.com/) for inline debugging and [Pepr Capabilities](#capability) creation.
package/dist/cli.js CHANGED
@@ -106,7 +106,7 @@ var banner = `\x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[
106
106
  // src/cli/build.ts
107
107
  var import_child_process2 = require("child_process");
108
108
  var import_esbuild = require("esbuild");
109
- var import_fs6 = require("fs");
109
+ var import_fs7 = require("fs");
110
110
  var import_path = require("path");
111
111
 
112
112
  // src/lib/included-files.ts
@@ -187,7 +187,7 @@ function genCert(key, name2, issuer) {
187
187
 
188
188
  // src/lib/assets/deploy.ts
189
189
  var import_crypto = __toESM(require("crypto"));
190
- var import_fs2 = require("fs");
190
+ var import_fs3 = require("fs");
191
191
  var import_kubernetes_fluent_client2 = require("kubernetes-fluent-client");
192
192
 
193
193
  // src/lib/logger.ts
@@ -530,6 +530,7 @@ function moduleSecret(name2, data, hash) {
530
530
  }
531
531
 
532
532
  // src/lib/helpers.ts
533
+ var import_fs2 = require("fs");
533
534
  var createRBACMap = (capabilities) => {
534
535
  return capabilities.reduce((acc, capability) => {
535
536
  capability.bindings.forEach((binding) => {
@@ -548,6 +549,17 @@ var createRBACMap = (capabilities) => {
548
549
  return acc;
549
550
  }, {});
550
551
  };
552
+ async function createDirectoryIfNotExists(path) {
553
+ try {
554
+ await import_fs2.promises.access(path);
555
+ } catch (error) {
556
+ if (error.code === "ENOENT") {
557
+ await import_fs2.promises.mkdir(path, { recursive: true });
558
+ } else {
559
+ throw error;
560
+ }
561
+ }
562
+ }
551
563
 
552
564
  // src/lib/assets/rbac.ts
553
565
  function clusterRole(name2, capabilities, rbacMode = "") {
@@ -723,12 +735,16 @@ async function generateWebhookRules(assets, isMutateWebhook) {
723
735
  operations.push(event);
724
736
  }
725
737
  const resource = kind3.plural || `${kind3.kind.toLowerCase()}s`;
726
- rules.push({
738
+ const ruleObject = {
727
739
  apiGroups: [kind3.group],
728
740
  apiVersions: [kind3.version || "*"],
729
741
  operations,
730
742
  resources: [resource]
731
- });
743
+ };
744
+ if (resource === "pods") {
745
+ ruleObject.resources.push("pods/ephemeralcontainers");
746
+ }
747
+ rules.push(ruleObject);
732
748
  }
733
749
  }
734
750
  return (0, import_ramda.uniqWith)(import_ramda.equals, rules);
@@ -815,7 +831,7 @@ async function deploy(assets, webhookTimeout) {
815
831
  if (host) {
816
832
  return;
817
833
  }
818
- const code = await import_fs2.promises.readFile(path);
834
+ const code = await import_fs3.promises.readFile(path);
819
835
  const hash = import_crypto.default.createHash("sha256").update(code).digest("hex");
820
836
  if (code.length < 1) {
821
837
  throw new Error("No code provided");
@@ -897,7 +913,7 @@ function loadCapabilities(path) {
897
913
  // src/lib/assets/yaml.ts
898
914
  var import_client_node = require("@kubernetes/client-node");
899
915
  var import_crypto2 = __toESM(require("crypto"));
900
- var import_fs3 = require("fs");
916
+ var import_fs4 = require("fs");
901
917
  function zarfYaml({ name: name2, image, config }, path) {
902
918
  const zarfCfg = {
903
919
  kind: "ZarfPackageConfig",
@@ -926,7 +942,7 @@ function zarfYaml({ name: name2, image, config }, path) {
926
942
  }
927
943
  async function allYaml(assets, rbacMode) {
928
944
  const { name: name2, tls, apiToken, path } = assets;
929
- const code = await import_fs3.promises.readFile(path);
945
+ const code = await import_fs4.promises.readFile(path);
930
946
  const hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
931
947
  const mutateWebhook = await webhookConfig(assets, "mutate");
932
948
  const validateWebhook = await webhookConfig(assets, "validate");
@@ -1192,7 +1208,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
1192
1208
  var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
1193
1209
  var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
1194
1210
  var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
1195
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.15.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.8.0", pino: "8.16.1", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.2.0", "@commitlint/config-conventional": "18.1.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.6", "@types/express": "4.17.20", "@types/node": "18.x.x", "@types/node-forge": "1.3.8", "@types/prompts": "2.4.7", "@types/ramda": "0.29.7", "@types/uuid": "9.0.6", jest: "29.7.0", nock: "13.3.6", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
1211
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.17.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.29.9", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.8.4", pino: "8.16.2", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.4.3", "@commitlint/config-conventional": "18.4.3", "@jest/globals": "29.7.0", "@types/eslint": "8.44.7", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.10", "@types/prompts": "2.4.9", "@types/uuid": "9.0.7", jest: "29.7.0", nock: "13.3.8", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
1196
1212
 
1197
1213
  // src/templates/pepr.code-snippets.json
1198
1214
  var pepr_code_snippets_default = {
@@ -1250,7 +1266,7 @@ var tsconfig_module_default = {
1250
1266
  };
1251
1267
 
1252
1268
  // src/cli/init/utils.ts
1253
- var import_fs4 = require("fs");
1269
+ var import_fs5 = require("fs");
1254
1270
  function sanitizeName(name2) {
1255
1271
  let sanitized = name2.toLowerCase().replace(/[^a-z0-9-]+/gi, "-");
1256
1272
  sanitized = sanitized.replace(/^-+|-+$/g, "");
@@ -1259,7 +1275,7 @@ function sanitizeName(name2) {
1259
1275
  }
1260
1276
  async function createDir(dir) {
1261
1277
  try {
1262
- await import_fs4.promises.mkdir(dir);
1278
+ await import_fs5.promises.mkdir(dir);
1263
1279
  } catch (err) {
1264
1280
  if (err && err.code === "EEXIST") {
1265
1281
  throw new Error(`Directory ${dir} already exists`);
@@ -1272,7 +1288,7 @@ function write(path, data) {
1272
1288
  if (typeof data !== "string") {
1273
1289
  data = JSON.stringify(data, null, 2);
1274
1290
  }
1275
- return import_fs4.promises.writeFile(path, data);
1291
+ return import_fs5.promises.writeFile(path, data);
1276
1292
  }
1277
1293
 
1278
1294
  // src/cli/init/templates.ts
@@ -1360,7 +1376,7 @@ var eslint = {
1360
1376
 
1361
1377
  // src/cli/format.ts
1362
1378
  var import_eslint = require("eslint");
1363
- var import_fs5 = require("fs");
1379
+ var import_fs6 = require("fs");
1364
1380
  var import_prettier = require("prettier");
1365
1381
  function format_default(program2) {
1366
1382
  program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
@@ -1393,7 +1409,7 @@ async function peprFormat(validateOnly) {
1393
1409
  await import_eslint.ESLint.outputFixes(results);
1394
1410
  }
1395
1411
  for (const { filePath } of results) {
1396
- const content = await import_fs5.promises.readFile(filePath, "utf8");
1412
+ const content = await import_fs6.promises.readFile(filePath, "utf8");
1397
1413
  const cfg = await (0, import_prettier.resolveConfig)(filePath);
1398
1414
  const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
1399
1415
  if (validateOnly) {
@@ -1402,7 +1418,7 @@ async function peprFormat(validateOnly) {
1402
1418
  console.error(`File ${filePath} is not formatted correctly`);
1403
1419
  }
1404
1420
  } else {
1405
- await import_fs5.promises.writeFile(filePath, formatted);
1421
+ await import_fs6.promises.writeFile(filePath, formatted);
1406
1422
  }
1407
1423
  }
1408
1424
  return !hasFailure;
@@ -1416,18 +1432,25 @@ async function peprFormat(validateOnly) {
1416
1432
  // src/cli/build.ts
1417
1433
  var import_commander = require("commander");
1418
1434
  var peprTS2 = "pepr.ts";
1435
+ var outputDir = "dist";
1419
1436
  function build_default(program2) {
1420
- program2.command("build").description("Build a Pepr Module for deployment").option(
1421
- "-e, --entry-point [file]",
1422
- "Specify the entry point file to build with. Note that changing this disables embedding of NPM packages.",
1423
- peprTS2
1437
+ program2.command("build").description("Build a Pepr Module for deployment").option("-e, --entry-point [file]", "Specify the entry point file to build with.", peprTS2).option(
1438
+ "-n, --no-embed",
1439
+ "Disables embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM."
1424
1440
  ).option(
1425
1441
  "-r, --registry-info [<registry>/<username>]",
1426
1442
  "Registry Info: Image registry and username. Note: You must be signed into the registry"
1427
- ).addOption(
1443
+ ).option("-o, --output-dir [output directory]", "Define where to place build output").addOption(
1428
1444
  new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(["admin", "scoped"]).default("admin")
1429
1445
  ).action(async (opts) => {
1430
- const { cfg, path, uuid } = await buildModule(void 0, opts.entryPoint);
1446
+ if (opts.outputDir) {
1447
+ outputDir = opts.outputDir;
1448
+ createDirectoryIfNotExists(outputDir).catch((error) => {
1449
+ console.error(`Error creating output directory: ${error}`);
1450
+ process.exit(1);
1451
+ });
1452
+ }
1453
+ const { cfg, path, uuid } = await buildModule(void 0, opts.entryPoint, opts.embed);
1431
1454
  const { includedFiles } = cfg.pepr;
1432
1455
  let image = "";
1433
1456
  if (opts.registryInfo !== void 0) {
@@ -1439,7 +1462,7 @@ function build_default(program2) {
1439
1462
  (0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
1440
1463
  }
1441
1464
  }
1442
- if (opts.entryPoint !== peprTS2) {
1465
+ if (!opts.embed) {
1443
1466
  console.info(`\u2705 Module built successfully at ${path}`);
1444
1467
  return;
1445
1468
  }
@@ -1455,12 +1478,12 @@ function build_default(program2) {
1455
1478
  assets.image = image;
1456
1479
  }
1457
1480
  const yamlFile = `pepr-module-${uuid}.yaml`;
1458
- const yamlPath = (0, import_path.resolve)("dist", yamlFile);
1481
+ const yamlPath = (0, import_path.resolve)(outputDir, yamlFile);
1459
1482
  const yaml = await assets.allYaml(opts.rbacMode);
1460
- const zarfPath = (0, import_path.resolve)("dist", "zarf.yaml");
1483
+ const zarfPath = (0, import_path.resolve)(outputDir, "zarf.yaml");
1461
1484
  const zarf = assets.zarfYaml(yamlFile);
1462
- await import_fs6.promises.writeFile(yamlPath, yaml);
1463
- await import_fs6.promises.writeFile(zarfPath, zarf);
1485
+ await import_fs7.promises.writeFile(yamlPath, yaml);
1486
+ await import_fs7.promises.writeFile(zarfPath, zarf);
1464
1487
  console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
1465
1488
  });
1466
1489
  }
@@ -1468,18 +1491,19 @@ var externalLibs = Object.keys(dependencies);
1468
1491
  externalLibs.push("pepr");
1469
1492
  externalLibs.push("@kubernetes/client-node");
1470
1493
  async function loadModule(entryPoint = peprTS2) {
1471
- const cfgPath = (0, import_path.resolve)(".", "package.json");
1472
- const input = (0, import_path.resolve)(".", entryPoint);
1494
+ const entryPointPath = (0, import_path.resolve)(".", entryPoint);
1495
+ const modulePath = (0, import_path.dirname)(entryPointPath);
1496
+ const cfgPath = (0, import_path.resolve)(modulePath, "package.json");
1473
1497
  try {
1474
- await import_fs6.promises.access(cfgPath);
1475
- await import_fs6.promises.access(input);
1498
+ await import_fs7.promises.access(cfgPath);
1499
+ await import_fs7.promises.access(entryPointPath);
1476
1500
  } catch (e) {
1477
1501
  console.error(
1478
- `Could not find ${cfgPath} or ${input} in the current directory. Please run this command from the root of your module's directory.`
1502
+ `Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`
1479
1503
  );
1480
1504
  process.exit(1);
1481
1505
  }
1482
- const moduleText = await import_fs6.promises.readFile(cfgPath, { encoding: "utf-8" });
1506
+ const moduleText = await import_fs7.promises.readFile(cfgPath, { encoding: "utf-8" });
1483
1507
  const cfg = JSON.parse(moduleText);
1484
1508
  const { uuid } = cfg.pepr;
1485
1509
  const name2 = `pepr-${uuid}.js`;
@@ -1489,15 +1513,16 @@ async function loadModule(entryPoint = peprTS2) {
1489
1513
  }
1490
1514
  return {
1491
1515
  cfg,
1492
- input,
1516
+ entryPointPath,
1517
+ modulePath,
1493
1518
  name: name2,
1494
- path: (0, import_path.resolve)("dist", name2),
1519
+ path: (0, import_path.resolve)(outputDir, name2),
1495
1520
  uuid
1496
1521
  };
1497
1522
  }
1498
- async function buildModule(reloader, entryPoint = peprTS2) {
1523
+ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
1499
1524
  try {
1500
- const { cfg, path, uuid } = await loadModule(entryPoint);
1525
+ const { cfg, modulePath, path, uuid } = await loadModule(entryPoint);
1501
1526
  const validFormat = await peprFormat(true);
1502
1527
  if (!validFormat) {
1503
1528
  console.log(
@@ -1505,7 +1530,8 @@ async function buildModule(reloader, entryPoint = peprTS2) {
1505
1530
  "Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues."
1506
1531
  );
1507
1532
  }
1508
- (0, import_child_process2.execSync)("./node_modules/.bin/tsc", { stdio: "pipe" });
1533
+ const args = ["--project", `${modulePath}/tsconfig.json`, "--outdir", outputDir];
1534
+ (0, import_child_process2.execFileSync)("./node_modules/.bin/tsc", args);
1509
1535
  const ctxCfg = {
1510
1536
  bundle: true,
1511
1537
  entryPoints: [entryPoint],
@@ -1538,9 +1564,9 @@ async function buildModule(reloader, entryPoint = peprTS2) {
1538
1564
  if (reloader) {
1539
1565
  ctxCfg.minify = false;
1540
1566
  }
1541
- if (entryPoint !== peprTS2) {
1567
+ if (!embed) {
1542
1568
  ctxCfg.minify = false;
1543
- ctxCfg.outfile = (0, import_path.resolve)("dist", (0, import_path.basename)(entryPoint, (0, import_path.extname)(entryPoint))) + ".js";
1569
+ ctxCfg.outfile = (0, import_path.resolve)(outputDir, (0, import_path.basename)(entryPoint, (0, import_path.extname)(entryPoint))) + ".js";
1544
1570
  ctxCfg.packages = "external";
1545
1571
  ctxCfg.treeShaking = false;
1546
1572
  }
@@ -1622,7 +1648,7 @@ function deploy_default(program2) {
1622
1648
 
1623
1649
  // src/cli/dev.ts
1624
1650
  var import_child_process3 = require("child_process");
1625
- var import_fs7 = require("fs");
1651
+ var import_fs8 = require("fs");
1626
1652
  var import_prompts2 = __toESM(require("prompts"));
1627
1653
  function dev_default(program2) {
1628
1654
  program2.command("dev").description("Setup a local webhook development environment").option("-h, --host [host]", "Host to listen on", "host.k3d.internal").option("--confirm", "Skip confirmation prompt").action(async (opts) => {
@@ -1645,8 +1671,8 @@ function dev_default(program2) {
1645
1671
  path,
1646
1672
  opts.host
1647
1673
  );
1648
- await import_fs7.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
1649
- await import_fs7.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
1674
+ await import_fs8.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
1675
+ await import_fs8.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
1650
1676
  try {
1651
1677
  let program3;
1652
1678
  const runFork = async () => {
@@ -1690,7 +1716,7 @@ var import_path2 = require("path");
1690
1716
  var import_prompts4 = __toESM(require("prompts"));
1691
1717
 
1692
1718
  // src/cli/init/walkthrough.ts
1693
- var import_fs8 = require("fs");
1719
+ var import_fs9 = require("fs");
1694
1720
  var import_prompts3 = __toESM(require("prompts"));
1695
1721
 
1696
1722
  // src/lib/errors.ts
@@ -1710,7 +1736,7 @@ function walkthrough() {
1710
1736
  validate: async (val) => {
1711
1737
  try {
1712
1738
  const name2 = sanitizeName(val);
1713
- await import_fs8.promises.access(name2, import_fs8.promises.constants.F_OK);
1739
+ await import_fs9.promises.access(name2, import_fs9.promises.constants.F_OK);
1714
1740
  return "A directory with this name already exists";
1715
1741
  } catch (e) {
1716
1742
  return val.length > 2 || "The name must be at least 3 characters long";
@@ -1845,7 +1871,7 @@ var RootCmd = class extends import_commander2.Command {
1845
1871
 
1846
1872
  // src/cli/update.ts
1847
1873
  var import_child_process5 = require("child_process");
1848
- var import_fs9 = __toESM(require("fs"));
1874
+ var import_fs10 = __toESM(require("fs"));
1849
1875
  var import_path3 = require("path");
1850
1876
  var import_prompts5 = __toESM(require("prompts"));
1851
1877
  function update_default(program2) {
@@ -1885,12 +1911,12 @@ function update_default(program2) {
1885
1911
  await write((0, import_path3.resolve)(".vscode", snippet.path), snippet.data);
1886
1912
  await write((0, import_path3.resolve)(".vscode", codeSettings.path), codeSettings.data);
1887
1913
  const samplePath = (0, import_path3.resolve)("capabilities", samplesYaml.path);
1888
- if (import_fs9.default.existsSync(samplePath)) {
1889
- import_fs9.default.unlinkSync(samplePath);
1914
+ if (import_fs10.default.existsSync(samplePath)) {
1915
+ import_fs10.default.unlinkSync(samplePath);
1890
1916
  await write(samplePath, samplesYaml.data);
1891
1917
  }
1892
1918
  const tsPath = (0, import_path3.resolve)("capabilities", helloPepr.path);
1893
- if (import_fs9.default.existsSync(tsPath)) {
1919
+ if (import_fs10.default.existsSync(tsPath)) {
1894
1920
  await write(tsPath, helloPepr.data);
1895
1921
  }
1896
1922
  }
@@ -48,7 +48,7 @@ if (process.env.LOG_LEVEL) {
48
48
  var logger_default = Log;
49
49
 
50
50
  // src/templates/data.json
51
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.15.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.8.0", pino: "8.16.1", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.2.0", "@commitlint/config-conventional": "18.1.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.6", "@types/express": "4.17.20", "@types/node": "18.x.x", "@types/node-forge": "1.3.8", "@types/prompts": "2.4.7", "@types/ramda": "0.29.7", "@types/uuid": "9.0.6", jest: "29.7.0", nock: "13.3.6", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
51
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.17.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.29.9", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.8.4", pino: "8.16.2", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.4.3", "@commitlint/config-conventional": "18.4.3", "@jest/globals": "29.7.0", "@types/eslint": "8.44.7", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.10", "@types/prompts": "2.4.9", "@types/uuid": "9.0.7", jest: "29.7.0", nock: "13.3.8", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
52
52
 
53
53
  // src/runtime/controller.ts
54
54
  var { version } = packageJSON;
@@ -1 +1 @@
1
- {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/webhooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAW3B,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,mCA4ClF;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,QAAQ,GAAG,UAAU,EACvC,cAAc,SAAK,GAClB,OAAO,CAAC,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAkEzF"}
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/webhooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAW3B,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,mCAoDlF;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,QAAQ,GAAG,UAAU,EACvC,cAAc,SAAK,GAClB,OAAO,CAAC,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAkEzF"}
@@ -1,11 +1,20 @@
1
1
  import { GenericClass, GroupVersionKind } from "kubernetes-fluent-client";
2
2
  import { PeprStore, Storage } from "./storage";
3
+ import { Schedule } from "./schedule";
3
4
  import { Binding, CapabilityCfg, CapabilityExport, WhenSelector } from "./types";
4
5
  /**
5
6
  * A capability is a unit of functionality that can be registered with the Pepr runtime.
6
7
  */
7
8
  export declare class Capability implements CapabilityExport {
8
9
  #private;
10
+ hasSchedule: boolean;
11
+ /**
12
+ * Run code on a schedule with the capability.
13
+ *
14
+ * @param schedule The schedule to run the code on
15
+ * @returns
16
+ */
17
+ OnSchedule: (schedule: Schedule) => void;
9
18
  /**
10
19
  * Store is a key-value data store that can be used to persist data that should be shared
11
20
  * between requests. Each capability has its own store, and the data is persisted in Kubernetes
@@ -14,11 +23,27 @@ export declare class Capability implements CapabilityExport {
14
23
  * Note: You should only access the store from within an action.
15
24
  */
16
25
  Store: PeprStore;
26
+ /**
27
+ * ScheduleStore is a key-value data store used to persist schedule data that should be shared
28
+ * between intervals. Each Schedule shares store, and the data is persisted in Kubernetes
29
+ * in the `pepr-system` namespace.
30
+ *
31
+ * Note: There is no direct access to schedule store
32
+ */
33
+ ScheduleStore: PeprStore;
17
34
  get bindings(): Binding[];
18
35
  get name(): string;
19
36
  get description(): string;
20
37
  get namespaces(): string[];
21
38
  constructor(cfg: CapabilityCfg);
39
+ /**
40
+ * Register the store with the capability. This is called automatically by the Pepr controller.
41
+ *
42
+ * @param store
43
+ */
44
+ registerScheduleStore: () => {
45
+ scheduleStore: Storage;
46
+ };
22
47
  /**
23
48
  * Register the store with the capability. This is called automatically by the Pepr controller.
24
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/lib/capability.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAA2B,MAAM,0BAA0B,CAAC;AAMnG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,OAAO,EAGP,aAAa,EACb,gBAAgB,EAMhB,YAAY,EACb,MAAM,SAAS,CAAC;AAKjB;;GAEG;AACH,qBAAa,UAAW,YAAW,gBAAgB;;IAQjD;;;;;;OAMG;IACH,KAAK,EAAE,SAAS,CAOd;IAEF,IAAI,QAAQ,cAEX;IAED,IAAI,IAAI,WAEP;IAED,IAAI,WAAW,WAEd;IAED,IAAI,UAAU,aAEb;gBAEW,GAAG,EAAE,aAAa;IAS9B;;;;OAIG;IACH,aAAa;;MAaX;IAEF;;;;;;;;OAQG;IACH,IAAI,4CAA6C,gBAAgB,qBAqH/D;CACH"}
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/lib/capability.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAA2B,MAAM,0BAA0B,CAAC;AAMnG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAc,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EACL,OAAO,EAGP,aAAa,EACb,gBAAgB,EAMhB,YAAY,EACb,MAAM,SAAS,CAAC;AAKjB;;GAEG;AACH,qBAAa,UAAW,YAAW,gBAAgB;;IASjD,WAAW,EAAE,OAAO,CAAC;IAErB;;;;;OAKG;IACH,UAAU,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAqBtC;IAEF;;;;;;OAMG;IACH,KAAK,EAAE,SAAS,CAQd;IAEF;;;;;;OAMG;IACH,aAAa,EAAE,SAAS,CAQtB;IAEF,IAAI,QAAQ,cAEX;IAED,IAAI,IAAI,WAEP;IAED,IAAI,WAAW,WAEd;IAED,IAAI,UAAU,aAEb;gBAEW,GAAG,EAAE,aAAa;IAU9B;;;;OAIG;IACH,qBAAqB;;MAanB;IAEF;;;;OAIG;IACH,aAAa;;MAaX;IAEF;;;;;;;;OAQG;IACH,IAAI,4CAA6C,gBAAgB,qBAqH/D;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAoB,MAAM,QAAQ,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAKtD,qBAAa,UAAU;;gBAoBnB,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,EAC5C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,EACzC,OAAO,CAAC,EAAE,MAAM,IAAI;IA6BtB,+BAA+B;IAC/B,WAAW,SAAU,MAAM,UAqDzB;CAoKH"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAoB,MAAM,QAAQ,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAKtD,qBAAa,UAAU;;gBAoBnB,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,EAC5C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,EACzC,OAAO,CAAC,EAAE,MAAM,IAAI;IAiCtB,+BAA+B;IAC/B,WAAW,SAAU,MAAM,UAqDzB;CAoKH"}
@@ -1,7 +1,8 @@
1
1
  import { Capability } from "../capability";
2
2
  import { ModuleConfig } from "../module";
3
+ export declare const debounceBackoff = 5000;
3
4
  export declare class PeprControllerStore {
4
5
  #private;
5
- constructor(config: ModuleConfig, capabilities: Capability[], onReady?: () => void);
6
+ constructor(config: ModuleConfig, capabilities: Capability[], name: string, onReady?: () => void);
6
7
  }
7
8
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAMzC,qBAAa,mBAAmB;;gBAMlB,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;CA8KnF"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,qBAAa,mBAAmB;;gBAMlB,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;CAgMjG"}
@@ -7,5 +7,6 @@ type RBACMap = {
7
7
  };
8
8
  export declare const addVerbIfNotExists: (verbs: string[], verb: string) => void;
9
9
  export declare const createRBACMap: (capabilities: CapabilityExport[]) => RBACMap;
10
+ export declare function createDirectoryIfNotExists(path: string): Promise<void>;
10
11
  export {};
11
12
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,OAAO,GAAG;IACb,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,MAAM,EAAE,QAAQ,MAAM,SAI/D,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,gBAAgB,EAAE,KAAG,OAoBhE,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,KAAK,OAAO,GAAG;IACb,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,MAAM,EAAE,QAAQ,MAAM,SAI/D,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,gBAAgB,EAAE,KAAG,OAoBhE,CAAC;AAEF,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,MAAM,iBAU5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/lib/module.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI1F,iDAAiD;AACjD,MAAM,MAAM,YAAY,GAAG;IACzB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,YAAY,EAAE,aAAa,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,qHAAqH;IACrH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE7C,6GAA6G;IAC7G,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,GAAG,gBAAgB,KAAK,IAAI,CAAC;CAC9D,CAAC;AAGF,eAAO,MAAM,WAAW,eAA+C,CAAC;AAGxE,eAAO,MAAM,WAAW,eAA0C,CAAC;AAEnE,eAAO,MAAM,SAAS,eAAwC,CAAC;AAE/D,qBAAa,UAAU;;IAGrB;;;;;;OAMG;gBACS,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,YAAY,GAAE,UAAU,EAAO,EAAE,IAAI,GAAE,iBAAsB;IAgD7G;;;;;OAKG;IACH,KAAK,0BAEH;CACH"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/lib/module.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI1F,iDAAiD;AACjD,MAAM,MAAM,YAAY,GAAG;IACzB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,YAAY,EAAE,aAAa,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,qHAAqH;IACrH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE7C,6GAA6G;IAC7G,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,GAAG,gBAAgB,KAAK,IAAI,CAAC;CAC9D,CAAC;AAGF,eAAO,MAAM,WAAW,eAA+C,CAAC;AAGxE,eAAO,MAAM,WAAW,eAA0C,CAAC;AAEnE,eAAO,MAAM,SAAS,eAAwC,CAAC;AAE/D,qBAAa,UAAU;;IAGrB;;;;;;OAMG;gBACS,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,YAAY,GAAE,UAAU,EAAO,EAAE,IAAI,GAAE,iBAAsB;IAiD7G;;;;;OAKG;IACH,KAAK,0BAEH;CACH"}