@truefoundry/tfy-infra-engine 0.1.3 → 0.1.4

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.
package/dist/index.mjs CHANGED
@@ -2,14 +2,12 @@
2
2
  var EngineErrorCode = /* @__PURE__ */ ((EngineErrorCode2) => {
3
3
  EngineErrorCode2["TEMPLATE_NOT_FOUND"] = "TEMPLATE_NOT_FOUND";
4
4
  EngineErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
5
- EngineErrorCode2["GITHUB_NOT_FOUND"] = "GITHUB_NOT_FOUND";
6
- EngineErrorCode2["GITHUB_RATE_LIMITED"] = "GITHUB_RATE_LIMITED";
7
5
  EngineErrorCode2["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
8
6
  EngineErrorCode2["HTTPS_AUTH_FAILED"] = "HTTPS_AUTH_FAILED";
9
7
  EngineErrorCode2["SCHEMA_INVALID"] = "SCHEMA_INVALID";
10
8
  EngineErrorCode2["INPUT_VALIDATION_FAILED"] = "INPUT_VALIDATION_FAILED";
11
- EngineErrorCode2["TEMPLATE_JSON_NOT_FOUND"] = "TEMPLATE_JSON_NOT_FOUND";
12
- EngineErrorCode2["TEMPLATE_JSON_INVALID"] = "TEMPLATE_JSON_INVALID";
9
+ EngineErrorCode2["BUNDLE_NOT_FOUND"] = "BUNDLE_NOT_FOUND";
10
+ EngineErrorCode2["BUNDLE_INVALID"] = "BUNDLE_INVALID";
13
11
  EngineErrorCode2["TEMPLATE_SYNTAX_ERROR"] = "TEMPLATE_SYNTAX_ERROR";
14
12
  EngineErrorCode2["TOFU_NOT_FOUND"] = "TOFU_NOT_FOUND";
15
13
  EngineErrorCode2["TOFU_FMT_FAILED"] = "TOFU_FMT_FAILED";
@@ -54,12 +52,12 @@ var EngineError = class _EngineError extends Error {
54
52
  // src/schema/validator.ts
55
53
  import Ajv from "ajv";
56
54
 
57
- // src/schema/template-json-schema.ts
58
- var templateJsonSchema = {
55
+ // src/schema/bundle-schema.ts
56
+ var bundleSchema = {
59
57
  $schema: "http://json-schema.org/draft-07/schema#",
60
58
  type: "object",
61
59
  properties: {
62
- template: {
60
+ metadata: {
63
61
  type: "object",
64
62
  properties: {
65
63
  name: { type: "string", minLength: 1 },
@@ -69,7 +67,7 @@ var templateJsonSchema = {
69
67
  required: ["name", "version"],
70
68
  additionalProperties: false
71
69
  },
72
- schema: {
70
+ jsonSchema: {
73
71
  type: "object",
74
72
  description: "JSON Schema Draft-07 defining template inputs",
75
73
  properties: {
@@ -80,7 +78,7 @@ var templateJsonSchema = {
80
78
  required: ["type", "properties"]
81
79
  }
82
80
  },
83
- required: ["template", "schema"]
81
+ required: ["metadata", "jsonSchema"]
84
82
  };
85
83
 
86
84
  // src/schema/validator.ts
@@ -89,54 +87,51 @@ var ajv = new Ajv({
89
87
  strict: false,
90
88
  validateSchema: false
91
89
  });
92
- var validate = ajv.compile(templateJsonSchema);
93
- function validateTemplateJson(data) {
90
+ var validate = ajv.compile(bundleSchema);
91
+ function validateBundle(data) {
94
92
  if (!data || typeof data !== "object" || Array.isArray(data)) {
95
- throw new EngineError(
96
- "template.json must be a JSON object",
97
- "TEMPLATE_JSON_INVALID" /* TEMPLATE_JSON_INVALID */
98
- );
93
+ throw new EngineError("bundle must be a JSON object", "BUNDLE_INVALID" /* BUNDLE_INVALID */);
99
94
  }
100
95
  const valid = validate(data);
101
96
  if (!valid) {
102
97
  const message = formatAjvErrors(validate.errors ?? []);
103
- throw new EngineError(message, "TEMPLATE_JSON_INVALID" /* TEMPLATE_JSON_INVALID */);
98
+ throw new EngineError(message, "BUNDLE_INVALID" /* BUNDLE_INVALID */);
104
99
  }
105
100
  const record = data;
106
- const templateBlock = record["template"];
101
+ const metadataBlock = record["metadata"];
107
102
  const metadata = {
108
- name: templateBlock["name"],
109
- version: templateBlock["version"],
110
- ...templateBlock["description"] !== void 0 ? { description: templateBlock["description"] } : {}
103
+ name: metadataBlock["name"],
104
+ version: metadataBlock["version"],
105
+ ...metadataBlock["description"] !== void 0 ? { description: metadataBlock["description"] } : {}
111
106
  };
112
- const jsonSchema = record["schema"];
107
+ const jsonSchema = record["jsonSchema"];
113
108
  return { metadata, jsonSchema };
114
109
  }
115
110
  function formatAjvErrors(errors) {
116
111
  const first = errors[0];
117
112
  if (!first) {
118
- return "template.json validation failed";
113
+ return "bundle validation failed";
119
114
  }
120
115
  const path = first.instancePath || "";
121
116
  if (first.keyword === "required") {
122
117
  const prop = first.params["missingProperty"];
123
- return `template.json must have a "${prop}" key`;
118
+ return `bundle must have a "${prop}" key`;
124
119
  }
125
120
  if (first.keyword === "type") {
126
121
  const expected = first.params["type"];
127
- return `template.json${path ? ` "${dotPath(path)}"` : ""} must be ${expected}`;
122
+ return `bundle${path ? ` "${dotPath(path)}"` : ""} must be ${expected}`;
128
123
  }
129
- if (first.keyword === "pattern" && path === "/template/version") {
130
- return `template.json "template.version" must be semver format (x.y.z)`;
124
+ if (first.keyword === "pattern" && path === "/metadata/version") {
125
+ return `bundle "metadata.version" must be semver format (x.y.z)`;
131
126
  }
132
- if (first.keyword === "minLength" && path === "/template/name") {
133
- return `template.json "template.name" must be a non-empty string`;
127
+ if (first.keyword === "minLength" && path === "/metadata/name") {
128
+ return `bundle "metadata.name" must be a non-empty string`;
134
129
  }
135
130
  if (first.keyword === "const") {
136
131
  const expected = first.params["allowedValue"];
137
- return `template.json "${dotPath(path)}" must be ${JSON.stringify(expected)}`;
132
+ return `bundle "${dotPath(path)}" must be ${JSON.stringify(expected)}`;
138
133
  }
139
- return `template.json validation failed at ${path || "/"}: ${first.message ?? "unknown error"}`;
134
+ return `bundle validation failed at ${path || "/"}: ${first.message ?? "unknown error"}`;
140
135
  }
141
136
  function dotPath(jsonPointer) {
142
137
  return jsonPointer.replace(/^\//, "").replace(/\//g, ".");
@@ -654,7 +649,7 @@ function computeAggregateHash(files) {
654
649
  }
655
650
 
656
651
  // src/render/manifest.ts
657
- var ENGINE_VERSION = "0.1.3";
652
+ var ENGINE_VERSION = "0.1.4";
658
653
  function generateManifest(opts) {
659
654
  const { files, template, inputs, formatted, intentId, platformPrefix = "tfy_" } = opts;
660
655
  const manifestFiles = [];
@@ -959,8 +954,11 @@ var HclEngineImpl = class {
959
954
  /**
960
955
  * Upgrade: Update an existing cluster to new templates.
961
956
  *
962
- * Pipeline: validate envelope → drift detection (FR-028) → if source mismatch,
963
- * short-circuit → validate inputs → render → format → hash + manifest.
957
+ * Pipeline: validate envelope → drift detection (FR-028) → validate inputs
958
+ * render → format → hash + manifest.
959
+ *
960
+ * The engine always renders new files regardless of source mismatch.
961
+ * Callers (CLI/Server) enforce blocking policy via `sourceBlocked` flag (FR-029).
964
962
  */
965
963
  async upgrade(envelope, currentFiles, previousManifest) {
966
964
  const validatedEnvelope = this.validateEnvelopeOrThrow(envelope);
@@ -969,14 +967,6 @@ var HclEngineImpl = class {
969
967
  const incomingSource = validatedEnvelope.template.source;
970
968
  const driftReport = buildDriftReport(currentFiles, previousManifest, prefix, incomingSource);
971
969
  const sourceBlocked = driftReport.summary.sourceMismatches > 0;
972
- if (sourceBlocked) {
973
- return {
974
- files: currentFiles,
975
- manifest: previousManifest,
976
- driftReport,
977
- sourceBlocked: true
978
- };
979
- }
980
970
  const { renderedFiles, template, formatted, inputsWithDefaults } = await this.renderPipeline(
981
971
  validatedEnvelope,
982
972
  options
@@ -989,7 +979,7 @@ var HclEngineImpl = class {
989
979
  formatted,
990
980
  prefix
991
981
  );
992
- return { files: fileMap, manifest, driftReport, sourceBlocked: false };
982
+ return { files: fileMap, manifest, driftReport, sourceBlocked };
993
983
  }
994
984
  /**
995
985
  * Verify: Check integrity of existing files against a Manifest.
@@ -1147,14 +1137,14 @@ export {
1147
1137
  DEFAULT_PREFIX,
1148
1138
  EngineError,
1149
1139
  EngineErrorCode,
1140
+ bundleSchema,
1150
1141
  canonicalHash,
1151
1142
  classifyFile,
1152
1143
  createEngine,
1153
1144
  getCanonicalHashScriptPath,
1154
1145
  isTofuAvailable,
1155
1146
  parseHeader,
1156
- templateJsonSchema,
1157
- validateJsonSchemaStructure,
1158
- validateTemplateJson
1147
+ validateBundle,
1148
+ validateJsonSchemaStructure
1159
1149
  };
1160
1150
  //# sourceMappingURL=index.mjs.map