pepr 0.36.0 → 0.37.1

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 (99) hide show
  1. package/dist/cli/init/index.d.ts.map +1 -1
  2. package/dist/cli/init/templates.d.ts +4 -3
  3. package/dist/cli/init/templates.d.ts.map +1 -1
  4. package/dist/cli/init/utils.d.ts.map +1 -1
  5. package/dist/cli/init/walkthrough.d.ts +10 -3
  6. package/dist/cli/init/walkthrough.d.ts.map +1 -1
  7. package/dist/cli/types.d.ts +3 -0
  8. package/dist/cli/types.d.ts.map +1 -0
  9. package/dist/cli.js +253 -31
  10. package/dist/controller.js +138 -1
  11. package/dist/lib/adjudicators.d.ts +63 -0
  12. package/dist/lib/adjudicators.d.ts.map +1 -0
  13. package/dist/lib/adjudicators.test.d.ts +2 -0
  14. package/dist/lib/adjudicators.test.d.ts.map +1 -0
  15. package/dist/lib/assets/loader.d.ts.map +1 -1
  16. package/dist/lib/assets/pods.d.ts +1 -0
  17. package/dist/lib/assets/pods.d.ts.map +1 -1
  18. package/dist/lib/capability.d.ts +1 -0
  19. package/dist/lib/capability.d.ts.map +1 -1
  20. package/dist/lib/capability.test.d.ts +2 -0
  21. package/dist/lib/capability.test.d.ts.map +1 -0
  22. package/dist/lib/controller/index.d.ts.map +1 -1
  23. package/dist/lib/controller/store.d.ts +4 -0
  24. package/dist/lib/controller/store.d.ts.map +1 -1
  25. package/dist/lib/controller/store.test.d.ts +2 -0
  26. package/dist/lib/controller/store.test.d.ts.map +1 -0
  27. package/dist/lib/filter.d.ts +2 -3
  28. package/dist/lib/filter.d.ts.map +1 -1
  29. package/dist/lib/filter.test.d.ts +2 -1
  30. package/dist/lib/filter.test.d.ts.map +1 -1
  31. package/dist/lib/finalizer.d.ts +6 -0
  32. package/dist/lib/finalizer.d.ts.map +1 -0
  33. package/dist/lib/finalizer.test.d.ts +2 -0
  34. package/dist/lib/finalizer.test.d.ts.map +1 -0
  35. package/dist/lib/helpers.d.ts +2 -2
  36. package/dist/lib/helpers.d.ts.map +1 -1
  37. package/dist/lib/helpers.test.d.ts +1 -1
  38. package/dist/lib/helpers.test.d.ts.map +1 -1
  39. package/dist/lib/k8s.d.ts.map +1 -1
  40. package/dist/lib/module.d.ts +2 -1
  41. package/dist/lib/module.d.ts.map +1 -1
  42. package/dist/lib/mutate-processor.d.ts +2 -1
  43. package/dist/lib/mutate-processor.d.ts.map +1 -1
  44. package/dist/lib/mutate-request.d.ts +1 -2
  45. package/dist/lib/mutate-request.d.ts.map +1 -1
  46. package/dist/lib/schedule.d.ts +1 -2
  47. package/dist/lib/schedule.d.ts.map +1 -1
  48. package/dist/lib/storage.d.ts.map +1 -1
  49. package/dist/lib/types.d.ts +113 -6
  50. package/dist/lib/types.d.ts.map +1 -1
  51. package/dist/lib/validate-processor.d.ts +4 -2
  52. package/dist/lib/validate-processor.d.ts.map +1 -1
  53. package/dist/lib/validate-request.d.ts +1 -1
  54. package/dist/lib/validate-request.d.ts.map +1 -1
  55. package/dist/lib/watch-processor.d.ts +1 -1
  56. package/dist/lib/watch-processor.d.ts.map +1 -1
  57. package/dist/lib.js +383 -204
  58. package/dist/lib.js.map +4 -4
  59. package/package.json +13 -12
  60. package/src/cli/build.ts +3 -3
  61. package/src/cli/init/index.ts +20 -11
  62. package/src/cli/init/templates.ts +1 -1
  63. package/src/cli/init/utils.test.ts +11 -20
  64. package/src/cli/init/utils.ts +5 -0
  65. package/src/cli/init/walkthrough.test.ts +92 -11
  66. package/src/cli/init/walkthrough.ts +71 -16
  67. package/src/cli/monitor.ts +1 -1
  68. package/src/cli/types.ts +3 -0
  69. package/src/cli.ts +4 -2
  70. package/src/fixtures/data/create-pod.json +1 -1
  71. package/src/fixtures/data/delete-pod.json +1 -1
  72. package/src/lib/adjudicators.test.ts +1232 -0
  73. package/src/lib/adjudicators.ts +235 -0
  74. package/src/lib/assets/index.ts +1 -1
  75. package/src/lib/assets/loader.ts +1 -0
  76. package/src/lib/assets/webhooks.ts +1 -1
  77. package/src/lib/capability.test.ts +655 -0
  78. package/src/lib/capability.ts +104 -11
  79. package/src/lib/controller/index.ts +7 -4
  80. package/src/lib/controller/store.test.ts +131 -0
  81. package/src/lib/controller/store.ts +43 -5
  82. package/src/lib/filter.test.ts +194 -8
  83. package/src/lib/filter.ts +46 -107
  84. package/src/lib/finalizer.test.ts +236 -0
  85. package/src/lib/finalizer.ts +63 -0
  86. package/src/lib/helpers.test.ts +329 -69
  87. package/src/lib/helpers.ts +141 -100
  88. package/src/lib/k8s.ts +4 -0
  89. package/src/lib/module.ts +3 -3
  90. package/src/lib/mutate-processor.ts +5 -4
  91. package/src/lib/mutate-request.test.ts +1 -2
  92. package/src/lib/mutate-request.ts +1 -3
  93. package/src/lib/schedule.ts +1 -1
  94. package/src/lib/storage.ts +5 -6
  95. package/src/lib/types.ts +148 -5
  96. package/src/lib/validate-processor.ts +5 -2
  97. package/src/lib/validate-request.test.ts +1 -4
  98. package/src/lib/validate-request.ts +1 -1
  99. package/src/lib/watch-processor.ts +19 -5
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/init/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAiBlC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,QA0ExC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/init/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAkBlC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,QAkFxC"}
@@ -1,4 +1,4 @@
1
- import { InitOptions } from "./walkthrough";
1
+ import { InitOptions } from "../types";
2
2
  export declare const dependencies: {
3
3
  "@types/ramda": string;
4
4
  express: string;
@@ -19,13 +19,13 @@ export declare const dependencies: {
19
19
  "@types/json-pointer": string;
20
20
  "@types/node": string;
21
21
  "@types/node-forge": string;
22
- "@types/prompts": string;
23
22
  "@types/uuid": string;
24
23
  "fast-check": string;
25
24
  jest: string;
26
25
  "js-yaml": string;
27
26
  nock: string;
28
27
  "ts-jest": string;
28
+ husky: string;
29
29
  }, peerDependencies: {
30
30
  "@typescript-eslint/eslint-plugin": string;
31
31
  "@typescript-eslint/parser": string;
@@ -34,6 +34,7 @@ export declare const dependencies: {
34
34
  eslint: string;
35
35
  "node-forge": string;
36
36
  prettier: string;
37
+ "@types/prompts": string;
37
38
  prompts: string;
38
39
  typescript: string;
39
40
  uuid: string;
@@ -50,13 +51,13 @@ export declare const dependencies: {
50
51
  "test:journey:prep": string;
51
52
  "test:journey-wasm": string;
52
53
  "test:journey:k3d": string;
53
- "test:journey:build": string;
54
54
  "test:journey:image": string;
55
55
  "test:journey:run": string;
56
56
  "test:journey:run-wasm": string;
57
57
  "test:journey:upgrade": string;
58
58
  "format:check": string;
59
59
  "format:fix": string;
60
+ prepare: string;
60
61
  }, version: string;
61
62
  export declare function genPkgJSON(opts: InitOptions, pgkVerOverride?: string): {
62
63
  data: {
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/cli/init/templates.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAQ,YAAY;;;;;;;;;;GAAE,eAAe;;;;;;;;;;;;;;;;;GAAE,gBAAgB;;;;;;;;;;;GAAE,OAAO;;;;;;;;;;;;;;;;;;;;GAAE,OAAO,QAAgB,CAAC;AAEjG,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDpE;AAED,wBAAgB,SAAS;;;EAKxB;AAED,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AAEF,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAEF,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAEF,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;;;CAGnB,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;;;;CAGxB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;CAGpB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;CAGpB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;CAGlB,CAAC"}
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/cli/init/templates.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAQ,YAAY;;;;;;;;;;GAAE,eAAe;;;;;;;;;;;;;;;;;GAAE,gBAAgB;;;;;;;;;;;;GAAE,OAAO;;;;;;;;;;;;;;;;;;;;GAAE,OAAO,QAAgB,CAAC;AAEjG,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDpE;AAED,wBAAgB,SAAS;;;EAKxB;AAED,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AAEF,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAEF,eAAO,MAAM,SAAS;;;CAGrB,CAAC;AAEF,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;;;CAGnB,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;;;;CAGxB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;CAGpB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;CAGpB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;CAGlB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/cli/init/utils.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAWxC;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,iBAW1C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,iBAMhD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/cli/init/utils.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAgBxC;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,iBAW1C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,iBAMhD"}
@@ -1,8 +1,15 @@
1
1
  import { Answers } from "prompts";
2
- export type InitOptions = Answers<"name" | "description" | "errorBehavior">;
3
- export declare function walkthrough(): Promise<InitOptions>;
2
+ export type PromptOptions = {
3
+ name: string;
4
+ description: string;
5
+ errorBehavior: "audit" | "ignore" | "reject";
6
+ };
7
+ export type PartialPromptOptions = Partial<PromptOptions>;
8
+ export declare function walkthrough(opts?: PartialPromptOptions): Promise<PromptOptions>;
9
+ export declare function setName(name?: string): Promise<Answers<string>>;
10
+ export declare function setErrorBehavior(errorBehavior?: "audit" | "ignore" | "reject"): Promise<Answers<string>>;
4
11
  export declare function confirm(dirName: string, packageJSON: {
5
12
  path: string;
6
13
  print: string;
7
- }, peprTSPath: string): Promise<any>;
14
+ }, peprTSPath: string, skipPrompt?: boolean): Promise<boolean>;
8
15
  //# sourceMappingURL=walkthrough.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"walkthrough.d.ts","sourceRoot":"","sources":["../../../src/cli/init/walkthrough.ts"],"names":[],"mappings":"AAIA,OAAe,EAAE,OAAO,EAAgB,MAAM,SAAS,CAAC;AAMxD,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,aAAa,GAAG,eAAe,CAAC,CAAC;AAE5E,wBAAgB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAoDlD;AAED,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAC5C,UAAU,EAAE,MAAM,gBA0BnB"}
1
+ {"version":3,"file":"walkthrough.d.ts","sourceRoot":"","sources":["../../../src/cli/init/walkthrough.ts"],"names":[],"mappings":"AAIA,OAAe,EAAE,OAAO,EAAgB,MAAM,SAAS,CAAC;AAMxD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAE1D,wBAAsB,WAAW,CAAC,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAOrF;AAED,wBAAsB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CA6BrE;AAgBD,wBAAsB,gBAAgB,CACpC,aAAa,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAC5C,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAoC1B;AAED,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAC5C,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAAC,OAAO,CAAC,CAiClB"}
@@ -0,0 +1,3 @@
1
+ import { Answers } from "prompts";
2
+ export type InitOptions = Answers<"name" | "description" | "errorBehavior">;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cli/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,aAAa,GAAG,eAAe,CAAC,CAAC"}
package/dist/cli.js CHANGED
@@ -287,7 +287,151 @@ function sanitizeResourceName(name2) {
287
287
  return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
288
288
  }
289
289
 
290
+ // src/lib/adjudicators.ts
291
+ var import_ramda = require("ramda");
292
+ var declaredOperation = (0, import_ramda.pipe)((request) => request?.operation, (0, import_ramda.defaultTo)(""));
293
+ var declaredGroup = (0, import_ramda.pipe)((request) => request?.kind?.group, (0, import_ramda.defaultTo)(""));
294
+ var declaredVersion = (0, import_ramda.pipe)((request) => request?.kind?.version, (0, import_ramda.defaultTo)(""));
295
+ var declaredKind = (0, import_ramda.pipe)((request) => request?.kind?.kind, (0, import_ramda.defaultTo)(""));
296
+ var declaredUid = (0, import_ramda.pipe)((request) => request?.uid, (0, import_ramda.defaultTo)(""));
297
+ var carriesDeletionTimestamp = (0, import_ramda.pipe)((obj) => !!obj.metadata?.deletionTimestamp, (0, import_ramda.defaultTo)(false));
298
+ var missingDeletionTimestamp = (0, import_ramda.complement)(carriesDeletionTimestamp);
299
+ var carriedName = (0, import_ramda.pipe)((obj) => obj?.metadata?.name, (0, import_ramda.defaultTo)(""));
300
+ var carriesName = (0, import_ramda.pipe)(carriedName, (0, import_ramda.equals)(""), import_ramda.not);
301
+ var missingName = (0, import_ramda.complement)(carriesName);
302
+ var carriedNamespace = (0, import_ramda.pipe)((obj) => obj?.metadata?.namespace, (0, import_ramda.defaultTo)(""));
303
+ var carriesNamespace = (0, import_ramda.pipe)(carriedNamespace, (0, import_ramda.equals)(""), import_ramda.not);
304
+ var carriedAnnotations = (0, import_ramda.pipe)((obj) => obj?.metadata?.annotations, (0, import_ramda.defaultTo)({}));
305
+ var carriesAnnotations = (0, import_ramda.pipe)(carriedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
306
+ var carriedLabels = (0, import_ramda.pipe)((obj) => obj?.metadata?.labels, (0, import_ramda.defaultTo)({}));
307
+ var carriesLabels = (0, import_ramda.pipe)(carriedLabels, (0, import_ramda.equals)({}), import_ramda.not);
308
+ var definesDeletionTimestamp = (0, import_ramda.pipe)((binding) => binding?.filters?.deletionTimestamp, (0, import_ramda.defaultTo)(false));
309
+ var ignoresDeletionTimestamp = (0, import_ramda.complement)(definesDeletionTimestamp);
310
+ var definedName = (0, import_ramda.pipe)((binding) => binding?.filters?.name, (0, import_ramda.defaultTo)(""));
311
+ var definesName = (0, import_ramda.pipe)(definedName, (0, import_ramda.equals)(""), import_ramda.not);
312
+ var ignoresName = (0, import_ramda.complement)(definesName);
313
+ var definedNameRegex = (0, import_ramda.pipe)((binding) => binding?.filters?.regexName, (0, import_ramda.defaultTo)(""));
314
+ var definesNameRegex = (0, import_ramda.pipe)(definedNameRegex, (0, import_ramda.equals)(""), import_ramda.not);
315
+ var definedNamespaces = (0, import_ramda.pipe)((binding) => binding?.filters?.namespaces, (0, import_ramda.defaultTo)([]));
316
+ var definesNamespaces = (0, import_ramda.pipe)(definedNamespaces, (0, import_ramda.equals)([]), import_ramda.not);
317
+ var definedNamespaceRegexes = (0, import_ramda.pipe)((binding) => binding?.filters?.regexNamespaces, (0, import_ramda.defaultTo)([]));
318
+ var definesNamespaceRegexes = (0, import_ramda.pipe)(definedNamespaceRegexes, (0, import_ramda.equals)([]), import_ramda.not);
319
+ var definedAnnotations = (0, import_ramda.pipe)((binding) => binding?.filters?.annotations, (0, import_ramda.defaultTo)({}));
320
+ var definesAnnotations = (0, import_ramda.pipe)(definedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
321
+ var definedLabels = (0, import_ramda.pipe)((binding) => binding?.filters?.labels, (0, import_ramda.defaultTo)({}));
322
+ var definesLabels = (0, import_ramda.pipe)(definedLabels, (0, import_ramda.equals)({}), import_ramda.not);
323
+ var definedEvent = (0, import_ramda.pipe)((binding) => binding?.event, (0, import_ramda.defaultTo)(""));
324
+ var definesDelete = (0, import_ramda.pipe)(definedEvent, (0, import_ramda.equals)("DELETE" /* DELETE */));
325
+ var definedGroup = (0, import_ramda.pipe)((binding) => binding?.kind?.group, (0, import_ramda.defaultTo)(""));
326
+ var definesGroup = (0, import_ramda.pipe)(definedGroup, (0, import_ramda.equals)(""), import_ramda.not);
327
+ var definedVersion = (0, import_ramda.pipe)((binding) => binding?.kind?.version, (0, import_ramda.defaultTo)(""));
328
+ var definesVersion = (0, import_ramda.pipe)(definedVersion, (0, import_ramda.equals)(""), import_ramda.not);
329
+ var definedKind = (0, import_ramda.pipe)((binding) => binding?.kind?.kind, (0, import_ramda.defaultTo)(""));
330
+ var definesKind = (0, import_ramda.pipe)(definedKind, (0, import_ramda.equals)(""), import_ramda.not);
331
+ var definedCategory = (0, import_ramda.pipe)((binding) => {
332
+ return binding.isFinalize ? "Finalize" : binding.isWatch ? "Watch" : binding.isMutate ? "Mutate" : binding.isValidate ? "Validate" : "";
333
+ });
334
+ var definedCallback = (0, import_ramda.pipe)((binding) => {
335
+ return binding.isFinalize ? binding.finalizeCallback : binding.isWatch ? binding.watchCallback : binding.isMutate ? binding.mutateCallback : binding.isValidate ? binding.validateCallback : null;
336
+ });
337
+ var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (cb) => cb.name);
338
+ var mismatchedDeletionTimestamp = (0, import_ramda.allPass)([
339
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesDeletionTimestamp),
340
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), missingDeletionTimestamp)
341
+ ]);
342
+ var mismatchedName = (0, import_ramda.allPass)([
343
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesName),
344
+ (0, import_ramda.pipe)((bnd, obj) => definedName(bnd) !== carriedName(obj))
345
+ ]);
346
+ var mismatchedNameRegex = (0, import_ramda.allPass)([
347
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNameRegex),
348
+ (0, import_ramda.pipe)((bnd, obj) => new RegExp(definedNameRegex(bnd)).test(carriedName(obj)), import_ramda.not)
349
+ ]);
350
+ var bindsToKind = (0, import_ramda.curry)(
351
+ (0, import_ramda.allPass)([(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definedKind, (0, import_ramda.equals)(""), import_ramda.not), (0, import_ramda.pipe)((bnd, knd) => definedKind(bnd) === knd)])
352
+ );
353
+ var bindsToNamespace = (0, import_ramda.curry)((0, import_ramda.pipe)(bindsToKind(import_ramda.__, "Namespace")));
354
+ var misboundNamespace = (0, import_ramda.allPass)([bindsToNamespace, definesNamespaces]);
355
+ var mismatchedNamespace = (0, import_ramda.allPass)([
356
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaces),
357
+ (0, import_ramda.pipe)((bnd, obj) => definedNamespaces(bnd).includes(carriedNamespace(obj)), import_ramda.not)
358
+ ]);
359
+ var mismatchedNamespaceRegex = (0, import_ramda.allPass)([
360
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaceRegexes),
361
+ (0, import_ramda.pipe)(
362
+ (bnd, obj) => (0, import_ramda.pipe)(
363
+ (0, import_ramda.any)((rex) => new RegExp(rex).test(carriedNamespace(obj))),
364
+ import_ramda.not
365
+ )(definedNamespaceRegexes(bnd))
366
+ )
367
+ ]);
368
+ var metasMismatch = (0, import_ramda.pipe)(
369
+ (defined, carried) => {
370
+ const result = { defined, carried, unalike: {} };
371
+ result.unalike = Object.entries(result.defined).map(([key, val]) => {
372
+ const keyMissing = !Object.hasOwn(result.carried, key);
373
+ const noValue = !val;
374
+ const valMissing = !result.carried[key];
375
+ return keyMissing ? { [key]: val } : noValue ? {} : valMissing ? { [key]: val } : {};
376
+ }).reduce((acc, cur) => ({ ...acc, ...cur }), {});
377
+ return result.unalike;
378
+ },
379
+ (unalike) => Object.keys(unalike).length > 0
380
+ );
381
+ var mismatchedAnnotations = (0, import_ramda.allPass)([
382
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesAnnotations),
383
+ (0, import_ramda.pipe)((bnd, obj) => metasMismatch(definedAnnotations(bnd), carriedAnnotations(obj)))
384
+ ]);
385
+ var mismatchedLabels = (0, import_ramda.allPass)([
386
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesLabels),
387
+ (0, import_ramda.pipe)((bnd, obj) => metasMismatch(definedLabels(bnd), carriedLabels(obj)))
388
+ ]);
389
+ var uncarryableNamespace = (0, import_ramda.allPass)([
390
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
391
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
392
+ (0, import_ramda.pipe)((nss, obj) => nss.includes(carriedNamespace(obj)), import_ramda.not)
393
+ ]);
394
+ var carriesIgnoredNamespace = (0, import_ramda.allPass)([
395
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
396
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
397
+ (0, import_ramda.pipe)((nss, obj) => nss.includes(carriedNamespace(obj)))
398
+ ]);
399
+ var unbindableNamespaces = (0, import_ramda.allPass)([
400
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
401
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), definesNamespaces),
402
+ (0, import_ramda.pipe)((nss, bnd) => (0, import_ramda.difference)(definedNamespaces(bnd), nss), import_ramda.length, (0, import_ramda.equals)(0), import_ramda.not)
403
+ ]);
404
+ var misboundDeleteWithDeletionTimestamp = (0, import_ramda.allPass)([definesDelete, definesDeletionTimestamp]);
405
+ var operationMatchesEvent = (0, import_ramda.anyPass)([
406
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), (0, import_ramda.equals)("*" /* Any */)),
407
+ (0, import_ramda.pipe)((op, evt) => op === evt),
408
+ (0, import_ramda.pipe)((op, evt) => op ? evt.includes(op) : false)
409
+ ]);
410
+ var mismatchedEvent = (0, import_ramda.pipe)(
411
+ (binding, request) => operationMatchesEvent(declaredOperation(request), definedEvent(binding)),
412
+ import_ramda.not
413
+ );
414
+ var mismatchedGroup = (0, import_ramda.allPass)([
415
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesGroup),
416
+ (0, import_ramda.pipe)((binding, request) => definedGroup(binding) !== declaredGroup(request))
417
+ ]);
418
+ var mismatchedVersion = (0, import_ramda.allPass)([
419
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesVersion),
420
+ (0, import_ramda.pipe)((binding, request) => definedVersion(binding) !== declaredVersion(request))
421
+ ]);
422
+ var mismatchedKind = (0, import_ramda.allPass)([
423
+ (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesKind),
424
+ (0, import_ramda.pipe)((binding, request) => definedKind(binding) !== declaredKind(request))
425
+ ]);
426
+
290
427
  // src/lib/helpers.ts
428
+ function matchesRegex(pattern, testString) {
429
+ if (!pattern) {
430
+ return false;
431
+ }
432
+ const regex = new RegExp(pattern);
433
+ return regex.test(testString);
434
+ }
291
435
  var ValidationError = class extends Error {
292
436
  };
293
437
  function validateCapabilityNames(capabilities) {
@@ -370,6 +514,7 @@ function generateWatchNamespaceError(ignoredNamespaces, bindingNamespaces, capab
370
514
  function namespaceComplianceValidator(capability, ignoredNamespaces) {
371
515
  const { namespaces: capabilityNamespaces, bindings, name: name2 } = capability;
372
516
  const bindingNamespaces = bindings.flatMap((binding) => binding.filters.namespaces);
517
+ const bindingRegexNamespaces = bindings.flatMap((binding) => binding.filters.regexNamespaces || []);
373
518
  const namespaceError = generateWatchNamespaceError(
374
519
  ignoredNamespaces ? ignoredNamespaces : [],
375
520
  bindingNamespaces,
@@ -380,6 +525,33 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
380
525
  `Error in ${name2} capability. A binding violates namespace rules. Please check ignoredNamespaces and capability namespaces: ${namespaceError}`
381
526
  );
382
527
  }
528
+ if (bindingRegexNamespaces && bindingRegexNamespaces.length > 0 && capabilityNamespaces && capabilityNamespaces.length > 0) {
529
+ for (const regexNamespace of bindingRegexNamespaces) {
530
+ let matches = false;
531
+ for (const capabilityNamespace of capabilityNamespaces) {
532
+ if (regexNamespace !== "" && matchesRegex(regexNamespace, capabilityNamespace)) {
533
+ matches = true;
534
+ break;
535
+ }
536
+ }
537
+ if (!matches) {
538
+ throw new Error(
539
+ `Ignoring Watch Callback: Object namespace does not match any capability namespace with regex ${regexNamespace}.`
540
+ );
541
+ }
542
+ }
543
+ }
544
+ if (bindingRegexNamespaces && bindingRegexNamespaces.length > 0 && ignoredNamespaces && ignoredNamespaces.length > 0) {
545
+ for (const regexNamespace of bindingRegexNamespaces) {
546
+ for (const ignoredNS of ignoredNamespaces) {
547
+ if (matchesRegex(regexNamespace, ignoredNS)) {
548
+ throw new Error(
549
+ `Ignoring Watch Callback: Regex namespace: ${regexNamespace}, is an ignored namespace: ${ignoredNS}.`
550
+ );
551
+ }
552
+ }
553
+ }
554
+ }
383
555
  }
384
556
  async function checkDeploymentStatus(namespace2) {
385
557
  const deployments = await (0, import_kubernetes_fluent_client2.K8s)(import_kubernetes_fluent_client2.kind.Deployment).InNamespace(namespace2).Get();
@@ -946,7 +1118,7 @@ var peprStoreCRD = {
946
1118
  };
947
1119
 
948
1120
  // src/lib/assets/webhooks.ts
949
- var import_ramda = require("ramda");
1121
+ var import_ramda2 = require("ramda");
950
1122
  var peprIgnoreLabel = {
951
1123
  key: "pepr.dev",
952
1124
  operator: "NotIn",
@@ -985,12 +1157,12 @@ async function generateWebhookRules(assets, isMutateWebhook) {
985
1157
  rules.push(ruleObject);
986
1158
  }
987
1159
  }
988
- return (0, import_ramda.uniqWith)(import_ramda.equals, rules);
1160
+ return (0, import_ramda2.uniqWith)(import_ramda2.equals, rules);
989
1161
  }
990
1162
  async function webhookConfig(assets, mutateOrValidate, timeoutSeconds = 10) {
991
1163
  const ignore = [peprIgnoreLabel];
992
1164
  const { name: name2, tls, config, apiToken, host } = assets;
993
- const ignoreNS = (0, import_ramda.concat)(peprIgnoreNamespaces, config.alwaysIgnore.namespaces || []);
1165
+ const ignoreNS = (0, import_ramda2.concat)(peprIgnoreNamespaces, config?.alwaysIgnore?.namespaces || []);
994
1166
  if (ignoreNS) {
995
1167
  ignore.push({
996
1168
  key: "kubernetes.io/metadata.name",
@@ -1158,7 +1330,8 @@ function loadCapabilities(path) {
1158
1330
  env: {
1159
1331
  ...process.env,
1160
1332
  LOG_LEVEL: "warn",
1161
- PEPR_MODE: "build"
1333
+ PEPR_MODE: "build",
1334
+ NODE_OPTIONS: "--disable-warning=DEP0040"
1162
1335
  }
1163
1336
  });
1164
1337
  program2.on("message", (message) => {
@@ -1689,7 +1862,7 @@ var Assets = class {
1689
1862
  allYaml = async (rbacMode, imagePullSecret) => {
1690
1863
  this.capabilities = await loadCapabilities(this.path);
1691
1864
  for (const capability of this.capabilities) {
1692
- namespaceComplianceValidator(capability, this.alwaysIgnore.namespaces);
1865
+ namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
1693
1866
  }
1694
1867
  return allYaml(this, rbacMode, imagePullSecret);
1695
1868
  };
@@ -1987,7 +2160,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
1987
2160
  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';
1988
2161
  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';
1989
2162
  var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport nock from "nock";\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://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("chuck-norris")\n .Mutate(cm => cm.SetLabel("got-jokes", "true"))\n .Watch(async cm => {\n const jokeURL = "https://icanhazdadjoke.com/";\n\n // Set up Nock to mock the API calls globally with header matching\n nock(jokeURL).get("/").reply(200, {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n });\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error(error, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\n }\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';
1990
- 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" }, files: ["/dist", "/src"], version: "0.36.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", version: "node scripts/set-version.js", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./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:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "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 && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.2", express: "4.21.0", "fast-json-patch": "3.1.1", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.0.3", pino: "9.4.0", "pino-pretty": "11.2.2", "prom-client": "15.1.3", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "4.17.21", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", jest: "29.7.0", "js-yaml": "^4.1.0", nock: "^13.5.4", "ts-jest": "29.2.5" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", commander: "12.1.0", esbuild: "0.23.0", eslint: "8.57.0", "node-forge": "1.3.1", prettier: "3.3.3", prompts: "2.4.2", typescript: "5.3.3", uuid: "10.0.0" } };
2163
+ 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" }, files: ["/dist", "/src"], version: "0.37.1", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", version: "node scripts/set-version.js", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run 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:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "4.21.0", "fast-json-patch": "3.1.1", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.0.4", pino: "9.4.0", "pino-pretty": "11.2.2", "prom-client": "15.1.3", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.0", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", jest: "29.7.0", "js-yaml": "^4.1.0", nock: "^13.5.4", "ts-jest": "29.2.5", husky: "^9.1.6" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", commander: "12.1.0", esbuild: "0.23.0", eslint: "8.57.0", "node-forge": "1.3.1", prettier: "3.3.3", "@types/prompts": "2.4.9", prompts: "2.4.2", typescript: "5.3.3", uuid: "10.0.0" } };
1991
2164
 
1992
2165
  // src/templates/pepr.code-snippets.json
1993
2166
  var pepr_code_snippets_default = {
@@ -2048,6 +2221,11 @@ var tsconfig_module_default = {
2048
2221
  // src/cli/init/utils.ts
2049
2222
  var import_fs6 = require("fs");
2050
2223
  function sanitizeName(name2) {
2224
+ if (typeof name2 !== "string") {
2225
+ throw TypeError(
2226
+ `sanitizeName() was called with a non-string value. The value is: ${name2} of type ${typeof name2}`
2227
+ );
2228
+ }
2051
2229
  let sanitized = name2.toLowerCase().replace(/[^a-z0-9-]+/gi, "-");
2052
2230
  sanitized = sanitized.replace(/^-+|-+$/g, "");
2053
2231
  sanitized = sanitized.replace(/--+/g, "-");
@@ -2301,7 +2479,7 @@ function build_default(program2) {
2301
2479
  path
2302
2480
  );
2303
2481
  if (opts?.registry == "Iron Bank") {
2304
- console.warn(
2482
+ console.info(
2305
2483
  `
2306
2484
  This command assumes the latest release. Pepr's Iron Bank image release cycle is dictated by renovate and is typically released a few days after the GitHub release.
2307
2485
  As an alternative you may consider custom --custom-image to target a specific image and version.`
@@ -2446,7 +2624,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
2446
2624
  out.matchAll(pgkErrMatch);
2447
2625
  const conflicts = [...out.matchAll(pgkErrMatch)];
2448
2626
  if (conflicts.length < 1) {
2449
- console.warn(
2627
+ console.info(
2450
2628
  `
2451
2629
  One or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.
2452
2630
  Try updating your Pepr Capabilities to their latest versions.`,
@@ -2454,7 +2632,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
2454
2632
  );
2455
2633
  }
2456
2634
  conflicts.forEach((match) => {
2457
- console.warn(
2635
+ console.info(
2458
2636
  `
2459
2637
  Package '${match[1]}' seems to be incompatible with your current version of Pepr.
2460
2638
  Try updating to the latest version.`,
@@ -2674,8 +2852,6 @@ ${allowOrDeny} MUTATE ${name2} (${uid})`);
2674
2852
  }
2675
2853
  }
2676
2854
  } catch {
2677
- console.warn(`
2678
- IGNORED - Unable to parse line: ${line}.`);
2679
2855
  }
2680
2856
  }
2681
2857
  }
@@ -2708,26 +2884,52 @@ var Errors = {
2708
2884
  var ErrorList = Object.values(Errors);
2709
2885
 
2710
2886
  // src/cli/init/walkthrough.ts
2711
- function walkthrough() {
2887
+ async function walkthrough(opts) {
2888
+ const result = {
2889
+ ...await setName(opts?.name),
2890
+ ...await setDescription(opts?.description),
2891
+ ...await setErrorBehavior(opts?.errorBehavior)
2892
+ };
2893
+ return result;
2894
+ }
2895
+ async function setName(name2) {
2712
2896
  const askName = {
2713
2897
  type: "text",
2714
2898
  name: "name",
2715
2899
  message: "Enter a name for the new Pepr module. This will create a new directory based on the name.\n",
2716
2900
  validate: async (val) => {
2717
2901
  try {
2718
- const name2 = sanitizeName(val);
2719
- await import_fs10.promises.access(name2, import_fs10.promises.constants.F_OK);
2902
+ const name3 = sanitizeName(val);
2903
+ await import_fs10.promises.access(name3, import_fs10.promises.constants.F_OK);
2720
2904
  return "A directory with this name already exists";
2721
2905
  } catch (e) {
2722
2906
  return val.length > 2 || "The name must be at least 3 characters long";
2723
2907
  }
2724
2908
  }
2725
2909
  };
2910
+ if (name2 !== void 0) {
2911
+ if (name2.length < 3) {
2912
+ console.error(`Module name must be at least 3 characters long. Received '${name2}'`);
2913
+ const response = (0, import_prompts3.default)([askName]);
2914
+ return response;
2915
+ } else {
2916
+ return { name: name2 };
2917
+ }
2918
+ }
2919
+ return (0, import_prompts3.default)([askName]);
2920
+ }
2921
+ async function setDescription(description) {
2726
2922
  const askDescription = {
2727
2923
  type: "text",
2728
2924
  name: "description",
2729
2925
  message: "(Recommended) Enter a description for the new Pepr module.\n"
2730
2926
  };
2927
+ if (description !== void 0) {
2928
+ return { description };
2929
+ }
2930
+ return (0, import_prompts3.default)([askDescription]);
2931
+ }
2932
+ async function setErrorBehavior(errorBehavior) {
2731
2933
  const askErrorBehavior = {
2732
2934
  type: "select",
2733
2935
  name: "errorBehavior",
@@ -2751,11 +2953,21 @@ function walkthrough() {
2751
2953
  }
2752
2954
  ]
2753
2955
  };
2754
- return (0, import_prompts3.default)([askName, askDescription, askErrorBehavior]);
2956
+ if (errorBehavior !== void 0) {
2957
+ if (!ErrorList.includes(errorBehavior)) {
2958
+ return (0, import_prompts3.default)([askErrorBehavior]);
2959
+ }
2960
+ return { errorBehavior };
2961
+ }
2962
+ return (0, import_prompts3.default)([askErrorBehavior]);
2755
2963
  }
2756
- async function confirm(dirName, packageJSON2, peprTSPath) {
2757
- console.log(`
2758
- To be generated:
2964
+ async function confirm(dirName, packageJSON2, peprTSPath, skipPrompt) {
2965
+ const confirmationPrompt = {
2966
+ type: "confirm",
2967
+ name: "confirm",
2968
+ message: "Create the new Pepr module?"
2969
+ };
2970
+ const confirmationMessage = `To be generated:
2759
2971
 
2760
2972
  \x1B[1m${dirName}\x1B[0m
2761
2973
  \u251C\u2500\u2500 \x1B[1m${eslint.path}\x1B[0m
@@ -2769,28 +2981,35 @@ ${packageJSON2.print.replace(/^/gm, " \u2502 ")}
2769
2981
  \u251C\u2500\u2500 \x1B[1m${peprTSPath}\x1B[0m
2770
2982
  \u251C\u2500\u2500 \x1B[1m${readme.path}\x1B[0m
2771
2983
  \u2514\u2500\u2500 \x1B[1m${tsConfig.path}\x1B[0m
2772
- `);
2773
- const confirm2 = await (0, import_prompts3.default)({
2774
- type: "confirm",
2775
- name: "confirm",
2776
- message: "Create the new Pepr module?"
2777
- });
2778
- return confirm2.confirm;
2984
+ `;
2985
+ if (skipPrompt !== void 0) {
2986
+ return skipPrompt;
2987
+ } else {
2988
+ console.log(confirmationMessage);
2989
+ const confirm2 = await (0, import_prompts3.default)([confirmationPrompt]);
2990
+ const shouldCreateModule = confirm2.confirm === "y" || confirm2.confirm === "yes" || confirm2.confirm === true ? true : false;
2991
+ return shouldCreateModule;
2992
+ }
2779
2993
  }
2780
2994
 
2781
2995
  // src/cli/init/index.ts
2782
2996
  function init_default(program2) {
2783
- program2.command("init").description("Initialize a new Pepr Module").option("--skip-post-init", "Skip npm install, git init and VSCode launch").action(async (opts) => {
2784
- let pkgOverride = "";
2997
+ let response = {};
2998
+ let pkgOverride = "";
2999
+ program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set a errorBehavior.", Errors.reject).hook("preAction", async (thisCommand) => {
2785
3000
  if (process.env.TEST_MODE === "true") {
2786
3001
  import_prompts4.default.inject(["pepr-test-module", "A test module for Pepr", "ignore", "y"]);
2787
3002
  pkgOverride = "file:../pepr-0.0.0-development.tgz";
3003
+ response = await walkthrough();
3004
+ } else {
3005
+ response = await walkthrough(thisCommand.opts());
3006
+ Object.entries(response).map(([key, value]) => thisCommand.setOptionValue(key, value));
2788
3007
  }
2789
- const response = await walkthrough();
3008
+ }).action(async (opts) => {
2790
3009
  const dirName = sanitizeName(response.name);
2791
3010
  const packageJSON2 = genPkgJSON(response, pkgOverride);
2792
3011
  const peprTS3 = genPeprTS();
2793
- const confirmed = await confirm(dirName, packageJSON2, peprTS3.path);
3012
+ const confirmed = await confirm(dirName, packageJSON2, peprTS3.path, opts.confirm);
2794
3013
  if (confirmed) {
2795
3014
  console.log("Creating new Pepr module...");
2796
3015
  try {
@@ -2813,7 +3032,7 @@ function init_default(program2) {
2813
3032
  (0, import_child_process4.execSync)("npm install", {
2814
3033
  stdio: "inherit"
2815
3034
  });
2816
- (0, import_child_process4.execSync)("git init", {
3035
+ (0, import_child_process4.execSync)("git init --initial-branch=main", {
2817
3036
  stdio: "inherit"
2818
3037
  });
2819
3038
  try {
@@ -2959,9 +3178,12 @@ function kfc_default(program2) {
2959
3178
 
2960
3179
  // src/cli.ts
2961
3180
  if (process.env.npm_lifecycle_event !== "npx") {
2962
- console.warn("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
3181
+ console.info("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
2963
3182
  }
2964
3183
  var program = new RootCmd();
3184
+ if (!process.env.PEPR_NODE_WARNINGS) {
3185
+ process.removeAllListeners("warning");
3186
+ }
2965
3187
  program.version(version2).description(`Pepr (v${version2}) - Type safe K8s middleware for humans`).action(() => {
2966
3188
  if (program.args.length < 1) {
2967
3189
  console.log(banner);