@checkstack/backend-api 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/package.json +12 -11
  3. package/src/auth-strategy.ts +6 -3
  4. package/src/bearer-token.ts +13 -0
  5. package/src/collector-strategy.ts +9 -0
  6. package/src/config-versioning.test.ts +227 -0
  7. package/src/config-versioning.ts +172 -0
  8. package/src/core-services.ts +14 -0
  9. package/src/esm-script-runner.test.ts +55 -16
  10. package/src/esm-script-runner.ts +212 -55
  11. package/src/index.ts +3 -0
  12. package/src/render-templatable-config.test.ts +168 -0
  13. package/src/render-templatable-config.ts +193 -0
  14. package/src/schema-utils.ts +3 -0
  15. package/src/script-sandbox/capabilities.test.ts +122 -0
  16. package/src/script-sandbox/capabilities.ts +372 -0
  17. package/src/script-sandbox/capped-output.test.ts +116 -0
  18. package/src/script-sandbox/capped-output.ts +172 -0
  19. package/src/script-sandbox/env-guard.test.ts +105 -0
  20. package/src/script-sandbox/env-guard.ts +129 -0
  21. package/src/script-sandbox/filesystem.test.ts +437 -0
  22. package/src/script-sandbox/filesystem.ts +514 -0
  23. package/src/script-sandbox/forkbomb.it.test.ts +121 -0
  24. package/src/script-sandbox/global-default.test.ts +161 -0
  25. package/src/script-sandbox/global-default.ts +100 -0
  26. package/src/script-sandbox/index.ts +14 -0
  27. package/src/script-sandbox/network.test.ts +356 -0
  28. package/src/script-sandbox/network.ts +373 -0
  29. package/src/script-sandbox/observability.test.ts +210 -0
  30. package/src/script-sandbox/observability.ts +168 -0
  31. package/src/script-sandbox/output-truncation.test.ts +53 -0
  32. package/src/script-sandbox/output-truncation.ts +69 -0
  33. package/src/script-sandbox/policy.test.ts +189 -0
  34. package/src/script-sandbox/policy.ts +220 -0
  35. package/src/script-sandbox/provider.test.ts +61 -0
  36. package/src/script-sandbox/provider.ts +134 -0
  37. package/src/script-sandbox/readiness.test.ts +80 -0
  38. package/src/script-sandbox/readiness.ts +117 -0
  39. package/src/script-sandbox/report.ts +88 -0
  40. package/src/script-sandbox/rootless-egress.it.test.ts +86 -0
  41. package/src/script-sandbox/rootless-egress.test.ts +99 -0
  42. package/src/script-sandbox/rootless-egress.ts +218 -0
  43. package/src/script-sandbox/shell-quote.test.ts +32 -0
  44. package/src/script-sandbox/shell-quote.ts +10 -0
  45. package/src/script-sandbox/wrapper.test.ts +1194 -0
  46. package/src/script-sandbox/wrapper.ts +714 -0
  47. package/src/shell-script-runner.test.ts +243 -0
  48. package/src/shell-script-runner.ts +210 -45
  49. package/src/zod-config.test.ts +60 -0
  50. package/src/zod-config.ts +38 -14
  51. package/tsconfig.json +3 -0
package/src/zod-config.ts CHANGED
@@ -54,6 +54,20 @@ export interface ConfigMeta {
54
54
  * to the plain JSON editor.
55
55
  */
56
56
  "x-secret-env"?: boolean;
57
+ /**
58
+ * Mark a string field as templatable. Its value is rendered through the
59
+ * template engine (`{{ environment.* }}` / `{{ check.* }}` /
60
+ * `{{ system.* }}`) at execute time, per resolved environment, BEFORE the
61
+ * collector reads it. ONLY `x-templatable` fields are rendered; every other
62
+ * field is passed through verbatim (so a literal `{{` in a non-templatable
63
+ * field is never touched).
64
+ *
65
+ * A field MUST NOT carry both `x-secret` (or `x-secret-env`) and
66
+ * `x-templatable` — secrets and templating are resolved in separate ordered
67
+ * passes (secrets first) and must never combine. This is enforced at load
68
+ * time via {@link assertNoSecretTemplatableConflict}.
69
+ */
70
+ "x-templatable"?: boolean;
57
71
  }
58
72
 
59
73
  /**
@@ -71,23 +85,25 @@ export const configRegistry = z.registry<ConfigMeta>();
71
85
  * - ZodOptional
72
86
  * - ZodDefault
73
87
  * - ZodNullable
88
+ *
89
+ * Loops so that multi-level wrappers (e.g. `.optional().default()`) are fully
90
+ * peeled — a single-pass strip misses the inner wrapper and causes
91
+ * `getConfigMeta` to return `undefined` for deeply-wrapped `x-templatable`
92
+ * fields.
74
93
  */
75
94
  function unwrapSchema(schema: z.ZodTypeAny): z.ZodTypeAny {
76
- let unwrapped = schema;
77
-
78
- if (unwrapped instanceof z.ZodOptional) {
79
- unwrapped = unwrapped.unwrap() as z.ZodTypeAny;
95
+ let current = schema;
96
+ for (;;) {
97
+ if (current instanceof z.ZodOptional || current instanceof z.ZodNullable) {
98
+ current = current.unwrap() as z.ZodTypeAny;
99
+ continue;
100
+ }
101
+ if (current instanceof z.ZodDefault) {
102
+ current = current.def.innerType as z.ZodTypeAny;
103
+ continue;
104
+ }
105
+ return current;
80
106
  }
81
-
82
- if (unwrapped instanceof z.ZodDefault) {
83
- unwrapped = unwrapped.def.innerType as z.ZodTypeAny;
84
- }
85
-
86
- if (unwrapped instanceof z.ZodNullable) {
87
- unwrapped = unwrapped.unwrap() as z.ZodTypeAny;
88
- }
89
-
90
- return unwrapped;
91
107
  }
92
108
 
93
109
  /**
@@ -119,6 +135,14 @@ export function isHiddenSchema(schema: z.ZodTypeAny): boolean {
119
135
  return getConfigMeta(schema)?.["x-hidden"] === true;
120
136
  }
121
137
 
138
+ /**
139
+ * Check if a schema is marked templatable (its string value is rendered
140
+ * through the template engine before the collector reads it).
141
+ */
142
+ export function isTemplatableSchema(schema: z.ZodTypeAny): boolean {
143
+ return getConfigMeta(schema)?.["x-templatable"] === true;
144
+ }
145
+
122
146
  /**
123
147
  * Get options resolver metadata for a schema.
124
148
  */
package/tsconfig.json CHANGED
@@ -18,6 +18,9 @@
18
18
  },
19
19
  {
20
20
  "path": "../signal-common"
21
+ },
22
+ {
23
+ "path": "../template-engine"
21
24
  }
22
25
  ]
23
26
  }