@malloy-publisher/server 0.0.225 → 0.0.226

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 (38) hide show
  1. package/dist/app/api-doc.yaml +29 -24
  2. package/dist/app/assets/{EnvironmentPage-DYTeXDll.js → EnvironmentPage-DvOJ7L_b.js} +1 -1
  3. package/dist/app/assets/{HomePage-pDK2BPJY.js → HomePage-CXguJsXS.js} +1 -1
  4. package/dist/app/assets/{LightMode-C2bwGPY1.js → LightMode-ZsshUznu.js} +1 -1
  5. package/dist/app/assets/{MainPage-WtBulMH_.js → MainPage-BIe0VwBa.js} +2 -2
  6. package/dist/app/assets/{MaterializationsPage-hMgOtflG.js → MaterializationsPage-BuZ6UJVx.js} +1 -1
  7. package/dist/app/assets/{ModelPage-B2N5kYII.js → ModelPage-DsPf-s8B.js} +1 -1
  8. package/dist/app/assets/{PackagePage-CEN90nQG.js → PackagePage-CEVNAKZa.js} +1 -1
  9. package/dist/app/assets/{RouteError-BG2c5Zf0.js → RouteError-Chn7lL96.js} +1 -1
  10. package/dist/app/assets/{ThemeEditorPage-DNfeUwEZ.js → ThemeEditorPage-DWC_FdNU.js} +1 -1
  11. package/dist/app/assets/{WorkbookPage-NKI1BhFS.js → WorkbookPage-CGrsFz8p.js} +1 -1
  12. package/dist/app/assets/{core-C6anj5c0.es-DDLHqpzt.js → core-vVgoO8IR.es-BD_THWs_.js} +1 -1
  13. package/dist/app/assets/{index-DMQtnaf4.js → index-BioohWQj.js} +1 -1
  14. package/dist/app/assets/{index-CzNqKMVl.js → index-D6YtyiJ0.js} +1 -1
  15. package/dist/app/assets/{index-C6gZ6sSY.js → index-DNUZpnaa.js} +4 -4
  16. package/dist/app/assets/{index-JXgvyZna.js → index-gEWxu09x.js} +1 -1
  17. package/dist/app/index.html +1 -1
  18. package/dist/instrumentation.mjs +71 -15
  19. package/dist/package_load_worker.mjs +83 -16
  20. package/dist/server.mjs +128 -57
  21. package/package.json +1 -1
  22. package/src/controller/package.controller.spec.ts +17 -17
  23. package/src/controller/package.controller.ts +7 -6
  24. package/src/logger.spec.ts +193 -0
  25. package/src/logger.ts +115 -18
  26. package/src/mcp/skills/skills_bundle.json +1 -1
  27. package/src/package_load/package_load_pool.ts +5 -1
  28. package/src/package_load/package_load_worker.ts +7 -0
  29. package/src/package_load/protocol.ts +5 -1
  30. package/src/service/build_plan.spec.ts +42 -60
  31. package/src/service/build_plan.ts +37 -61
  32. package/src/service/environment.ts +4 -0
  33. package/src/service/materialization_test_fixtures.ts +6 -8
  34. package/src/service/package.ts +83 -44
  35. package/src/service/package_manifest.spec.ts +22 -1
  36. package/src/service/package_manifest.ts +29 -0
  37. package/src/service/persistence_policy.spec.ts +234 -0
  38. package/src/service/materialization_cron_gate.spec.ts +0 -181
@@ -18,7 +18,7 @@ describe("PackageController.addPackage explores validation", () => {
18
18
  "Invalid explores entry 'missing.malloy' in publisher.json: file not found";
19
19
  const mockPackage = {
20
20
  formatInvalidExplores: () => invalidMsg,
21
- formatInvalidSchedule: () => "",
21
+ formatInvalidPersistencePolicy: () => "",
22
22
  };
23
23
  const unloadPackage = sinon.stub().resolves(undefined);
24
24
  const deletePackage = sinon.stub().resolves(undefined);
@@ -55,7 +55,7 @@ describe("PackageController.addPackage explores validation", () => {
55
55
  "Invalid explores entry 'missing.malloy' in publisher.json: file not found";
56
56
  const mockPackage = {
57
57
  formatInvalidExplores: () => invalidMsg,
58
- formatInvalidSchedule: () => "",
58
+ formatInvalidPersistencePolicy: () => "",
59
59
  };
60
60
  // installPackage mimics the real contract: invoke the validator and, if it
61
61
  // returns a message, throw BadRequestError (after its internal rollback).
@@ -104,7 +104,7 @@ describe("PackageController.addPackage explores validation", () => {
104
104
  it("persists when explores are valid (no-location)", async () => {
105
105
  const mockPackage = {
106
106
  formatInvalidExplores: () => "",
107
- formatInvalidSchedule: () => "",
107
+ formatInvalidPersistencePolicy: () => "",
108
108
  };
109
109
  const addPackage = sinon.stub().resolves(mockPackage);
110
110
  const getEnvironment = sinon.stub().resolves({ addPackage });
@@ -127,22 +127,22 @@ describe("PackageController.addPackage explores validation", () => {
127
127
  });
128
128
  });
129
129
 
130
- describe("PackageController.addPackage cron schedule validation", () => {
130
+ describe("PackageController.addPackage persistence policy validation", () => {
131
131
  afterEach(() => {
132
132
  sinon.restore();
133
133
  });
134
134
 
135
- it("rejects a publish whose cron fails the private-only gate (no-location path)", async () => {
136
- // Valid explores but an invalid materialization cron: the publish must
137
- // still 400 (strict-at-publish, same split as explores — load merely
138
- // warns) and roll back via unloadPackage.
135
+ it("rejects a publish whose persistence policy is invalid (no-location path)", async () => {
136
+ // Valid explores but an invalid persistence policy (e.g. a schedule on a
137
+ // package-scoped package): the publish must still 400 (strict-at-publish,
138
+ // same split as explores — load merely warns) and roll back via
139
+ // unloadPackage.
139
140
  const cronMsg =
140
- "materialization.schedule (cron) in publisher.json requires every " +
141
- "persist source to declare '#@ persist ... sharing=private'; source " +
142
- "'orders' resolves to unset.";
141
+ 'materialization.schedule (cron) in publisher.json requires "scope": ' +
142
+ '"version".';
143
143
  const mockPackage = {
144
144
  formatInvalidExplores: () => "",
145
- formatInvalidSchedule: () => cronMsg,
145
+ formatInvalidPersistencePolicy: () => cronMsg,
146
146
  };
147
147
  const unloadPackage = sinon.stub().resolves(undefined);
148
148
  const addPackage = sinon.stub().resolves(mockPackage);
@@ -165,13 +165,13 @@ describe("PackageController.addPackage cron schedule validation", () => {
165
165
  expect(addPackageToDatabase.called).toBe(false);
166
166
  });
167
167
 
168
- it("location path: the cron gate runs inside installPackage's rollback window", async () => {
168
+ it("location path: the persistence-policy gate runs inside installPackage's rollback window", async () => {
169
169
  const cronMsg =
170
- "materialization.schedule (cron) in publisher.json requires every " +
171
- "persist source to declare '#@ persist ... sharing=private'.";
170
+ 'materialization.schedule (cron) in publisher.json requires "scope": ' +
171
+ '"version".';
172
172
  const mockPackage = {
173
173
  formatInvalidExplores: () => "",
174
- formatInvalidSchedule: () => cronMsg,
174
+ formatInvalidPersistencePolicy: () => cronMsg,
175
175
  };
176
176
  const installPackage = sinon
177
177
  .stub()
@@ -225,7 +225,7 @@ describe("PackageController.updatePackage explores validation", () => {
225
225
  const mockPackage = {
226
226
  formatInvalidExplores: (override?: string[]) =>
227
227
  override?.includes("nope.malloy") ? invalidMsg : "",
228
- formatInvalidSchedule: () => "",
228
+ formatInvalidPersistencePolicy: () => "",
229
229
  };
230
230
  const installPackage = sinon
231
231
  .stub()
@@ -8,21 +8,22 @@ type ApiPackage = components["schemas"]["Package"];
8
8
  /**
9
9
  * Everything that is strict-at-publish, joined into one 400 message (or
10
10
  * undefined when the package is publishable): invalid explores entries plus
11
- * the materialization cron gate (a package-level `schedule` requires every
12
- * persist source to resolve to explicit `sharing=private` — see
13
- * Package.scheduleWarnings). At startup/reload both are warn-only instead
14
- * (fail-safe; see Package.loadViaWorker).
11
+ * the Malloy Persistence policy gate (scope is package-level; a
12
+ * `materialization.schedule` is package-root-only + version-scope-only and
13
+ * mutually exclusive with freshness; per-source `sharing`/`schedule` are
14
+ * retired see Package.persistencePolicyWarnings). At startup/reload both are
15
+ * warn-only instead (fail-safe; see Package.loadViaWorker).
15
16
  */
16
17
  function formatPublishRejections(
17
18
  pkg: {
18
19
  formatInvalidExplores(exploresOverride?: string[]): string;
19
- formatInvalidSchedule(): string;
20
+ formatInvalidPersistencePolicy(): string;
20
21
  },
21
22
  exploresOverride?: string[],
22
23
  ): string | undefined {
23
24
  const message = [
24
25
  pkg.formatInvalidExplores(exploresOverride),
25
- pkg.formatInvalidSchedule(),
26
+ pkg.formatInvalidPersistencePolicy(),
26
27
  ]
27
28
  .filter(Boolean)
28
29
  .join("\n");
@@ -0,0 +1,193 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import type { AxiosError } from "axios";
3
+ import { buildAxiosErrorLog, redactSensitive } from "./logger";
4
+
5
+ describe("redactSensitive", () => {
6
+ it("masks every known credential field at the top level", () => {
7
+ const input = {
8
+ password: "hunter2",
9
+ connectionString: "postgresql://u:p@h/db",
10
+ serviceAccountKeyJson: '{"private_key":"-----BEGIN..."}',
11
+ privateKey: "-----BEGIN PRIVATE KEY-----",
12
+ privateKeyPass: "passphrase",
13
+ secret: "gcs-hmac-secret",
14
+ secretAccessKey: "aws-secret",
15
+ sessionToken: "aws-session",
16
+ sasUrl: "https://a.blob.core.windows.net/c?sig=abc",
17
+ clientSecret: "azure-client-secret",
18
+ oauthClientSecret: "databricks-oauth-secret",
19
+ peakaKey: "peaka-api-key",
20
+ token: "databricks-pat",
21
+ accessToken: "motherduck-token",
22
+ };
23
+ const out = redactSensitive(input) as Record<string, unknown>;
24
+ for (const key of Object.keys(input)) {
25
+ expect(out[key]).toBe("[REDACTED]");
26
+ }
27
+ });
28
+
29
+ it("keeps non-secret fields intact", () => {
30
+ const input = {
31
+ name: "bigquery",
32
+ type: "bigquery",
33
+ defaultProjectId: "my-project",
34
+ host: "db.example.com",
35
+ port: 5432,
36
+ };
37
+ expect(redactSensitive(input)).toEqual(input);
38
+ });
39
+
40
+ it("redacts secrets nested inside the environment PATCH payload shape", () => {
41
+ const input = {
42
+ name: "demo___malloy-samples",
43
+ connections: [
44
+ {
45
+ name: "bigquery",
46
+ type: "bigquery",
47
+ bigqueryConnection: {
48
+ defaultProjectId: "vscode-demo",
49
+ serviceAccountKeyJson: '{"private_key":"-----BEGIN..."}',
50
+ },
51
+ },
52
+ {
53
+ name: "warehouse",
54
+ type: "snowflake",
55
+ snowflakeConnection: {
56
+ account: "acct",
57
+ username: "svc",
58
+ password: "s3cret",
59
+ privateKey: "-----BEGIN PRIVATE KEY-----",
60
+ },
61
+ },
62
+ ],
63
+ };
64
+ expect(redactSensitive(input)).toEqual({
65
+ name: "demo___malloy-samples",
66
+ connections: [
67
+ {
68
+ name: "bigquery",
69
+ type: "bigquery",
70
+ bigqueryConnection: {
71
+ defaultProjectId: "vscode-demo",
72
+ serviceAccountKeyJson: "[REDACTED]",
73
+ },
74
+ },
75
+ {
76
+ name: "warehouse",
77
+ type: "snowflake",
78
+ snowflakeConnection: {
79
+ account: "acct",
80
+ username: "svc",
81
+ password: "[REDACTED]",
82
+ privateKey: "[REDACTED]",
83
+ },
84
+ },
85
+ ],
86
+ });
87
+ });
88
+
89
+ it("recurses through arrays of secrets", () => {
90
+ const out = redactSensitive([{ password: "a" }, { password: "b" }]);
91
+ expect(out).toEqual([
92
+ { password: "[REDACTED]" },
93
+ { password: "[REDACTED]" },
94
+ ]);
95
+ });
96
+
97
+ it("passes primitives through unchanged", () => {
98
+ expect(redactSensitive("plain")).toBe("plain");
99
+ expect(redactSensitive(42)).toBe(42);
100
+ expect(redactSensitive(null)).toBeNull();
101
+ expect(redactSensitive(undefined)).toBeUndefined();
102
+ });
103
+
104
+ it("preserves Date values instead of destructuring them", () => {
105
+ const d = new Date("2026-07-08T00:00:00.000Z");
106
+ const out = redactSensitive({ createdAt: d }) as { createdAt: Date };
107
+ expect(out.createdAt).toBeInstanceOf(Date);
108
+ expect(out.createdAt.getTime()).toBe(d.getTime());
109
+ });
110
+
111
+ it("does not mutate the input object", () => {
112
+ const input = { password: "hunter2", nested: { token: "abc" } };
113
+ redactSensitive(input);
114
+ expect(input.password).toBe("hunter2");
115
+ expect(input.nested.token).toBe("abc");
116
+ });
117
+
118
+ it("tolerates circular references", () => {
119
+ const input: Record<string, unknown> = { password: "hunter2" };
120
+ input.self = input;
121
+ const out = redactSensitive(input) as Record<string, unknown>;
122
+ expect(out.password).toBe("[REDACTED]");
123
+ expect(out.self).toBe("[Circular]");
124
+ });
125
+
126
+ it("matches credential keys case-insensitively", () => {
127
+ const out = redactSensitive({
128
+ Password: "hunter2",
129
+ Authorization: "Bearer abc",
130
+ }) as Record<string, unknown>;
131
+ expect(out.Password).toBe("[REDACTED]");
132
+ expect(out.Authorization).toBe("[REDACTED]");
133
+ });
134
+
135
+ it("masks credential HTTP headers", () => {
136
+ const out = redactSensitive({
137
+ "content-type": "application/json",
138
+ authorization: "Bearer secret-token",
139
+ cookie: "session=abc",
140
+ }) as Record<string, unknown>;
141
+ expect(out["content-type"]).toBe("application/json");
142
+ expect(out.authorization).toBe("[REDACTED]");
143
+ expect(out.cookie).toBe("[REDACTED]");
144
+ });
145
+ });
146
+
147
+ describe("buildAxiosErrorLog", () => {
148
+ it("redacts response data and headers on a server-side error", () => {
149
+ const error = {
150
+ response: {
151
+ config: { url: "http://worker/api" },
152
+ status: 500,
153
+ headers: { authorization: "Bearer abc", "content-type": "json" },
154
+ data: { connection: { serviceAccountKeyJson: "PRIVATE_KEY" } },
155
+ },
156
+ } as unknown as AxiosError;
157
+ const { message, meta } = buildAxiosErrorLog(error);
158
+ expect(message).toBe("Axios server-side error");
159
+ expect(meta).toEqual({
160
+ url: "http://worker/api",
161
+ status: 500,
162
+ headers: { authorization: "[REDACTED]", "content-type": "json" },
163
+ data: { connection: { serviceAccountKeyJson: "[REDACTED]" } },
164
+ });
165
+ });
166
+
167
+ it("never logs the raw request object on a client-side error", () => {
168
+ const error = {
169
+ request: { _header: "GET / HTTP/1.1\r\nAuthorization: Bearer abc" },
170
+ config: { method: "get", url: "http://worker/api" },
171
+ code: "ECONNABORTED",
172
+ } as unknown as AxiosError;
173
+ const { message, meta } = buildAxiosErrorLog(error);
174
+ expect(message).toBe("Axios client-side error");
175
+ expect(meta).toEqual({
176
+ method: "get",
177
+ url: "http://worker/api",
178
+ code: "ECONNABORTED",
179
+ });
180
+ expect(JSON.stringify(meta)).not.toContain("Bearer abc");
181
+ });
182
+
183
+ it("logs only the message on a setup error", () => {
184
+ const error = {
185
+ message: "getaddrinfo ENOTFOUND",
186
+ config: { headers: { Authorization: "Bearer abc" } },
187
+ } as unknown as AxiosError;
188
+ const { message, meta } = buildAxiosErrorLog(error);
189
+ expect(message).toBe("Axios unknown error");
190
+ expect(meta).toEqual({ message: "getaddrinfo ENOTFOUND" });
191
+ expect(JSON.stringify(meta)).not.toContain("Bearer abc");
192
+ });
193
+ });
package/src/logger.ts CHANGED
@@ -84,6 +84,73 @@ export function formatDuration(durationMs: number): string {
84
84
  return `${durationMs.toFixed(2)}ms`;
85
85
  }
86
86
 
87
+ // Connection endpoints carry provider credentials in their request/response
88
+ // bodies (BigQuery serviceAccountKeyJson, Snowflake privateKey/password, Postgres
89
+ // password/connectionString, S3 secretAccessKey/sessionToken, Azure clientSecret/
90
+ // sasUrl, Databricks token, ...), and axios error logs can carry credential HTTP
91
+ // headers (Authorization, Cookie). Those values are masked by key name before
92
+ // they reach a log transport. Matching is case-insensitive so header casing
93
+ // (Authorization vs authorization) does not slip through.
94
+ const SENSITIVE_KEY_NAMES = [
95
+ // connection config credentials
96
+ "password",
97
+ "connectionString",
98
+ "serviceAccountKeyJson",
99
+ "privateKey",
100
+ "privateKeyPass",
101
+ "secret",
102
+ "secretAccessKey",
103
+ "sessionToken",
104
+ "sasUrl",
105
+ "clientSecret",
106
+ "oauthClientSecret",
107
+ "peakaKey",
108
+ "token",
109
+ "accessToken",
110
+ // credential-bearing HTTP headers
111
+ "authorization",
112
+ "proxy-authorization",
113
+ "cookie",
114
+ "set-cookie",
115
+ "x-api-key",
116
+ ];
117
+ const SENSITIVE_KEYS: ReadonlySet<string> = new Set(
118
+ SENSITIVE_KEY_NAMES.map((name) => name.toLowerCase()),
119
+ );
120
+
121
+ const REDACTED = "[REDACTED]";
122
+
123
+ /**
124
+ * Deep-copy `value`, replacing any property whose key names a credential
125
+ * (SENSITIVE_KEYS) with a placeholder. The match is by key name (case-
126
+ * insensitive) and recurses through nested objects and arrays, since
127
+ * connections arrive nested under `connections[]`. Primitives and Dates pass
128
+ * through unchanged and the input is never mutated; used to keep secrets out of
129
+ * the request/response and axios-error logs.
130
+ */
131
+ export function redactSensitive(
132
+ value: unknown,
133
+ seen: WeakSet<object> = new WeakSet(),
134
+ ): unknown {
135
+ if (value === null || typeof value !== "object" || value instanceof Date) {
136
+ return value;
137
+ }
138
+ if (seen.has(value)) {
139
+ return "[Circular]";
140
+ }
141
+ seen.add(value);
142
+ if (Array.isArray(value)) {
143
+ return value.map((item) => redactSensitive(item, seen));
144
+ }
145
+ const result: Record<string, unknown> = {};
146
+ for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
147
+ result[key] = SENSITIVE_KEYS.has(key.toLowerCase())
148
+ ? REDACTED
149
+ : redactSensitive(val, seen);
150
+ }
151
+ return result;
152
+ }
153
+
87
154
  export const loggerMiddleware: RequestHandler = (req, res, next) => {
88
155
  const startTime = performance.now();
89
156
  const resJson = res.json;
@@ -102,14 +169,14 @@ export const loggerMiddleware: RequestHandler = (req, res, next) => {
102
169
  const logMetadata: Record<string, unknown> = {
103
170
  statusCode: res.statusCode,
104
171
  duration: formatDuration(durationMs),
105
- payload: req.body,
172
+ payload: redactSensitive(req.body),
106
173
  params: req.params,
107
174
  query: req.query,
108
175
  };
109
176
 
110
177
  // Only include response body if response logging is enabled
111
178
  if (!DISABLE_RESPONSE_LOGGING) {
112
- logMetadata.response = res.locals.body;
179
+ logMetadata.response = redactSensitive(res.locals.body);
113
180
  }
114
181
 
115
182
  // Add traceId to log metadata if present
@@ -130,23 +197,53 @@ export const loggerMiddleware: RequestHandler = (req, res, next) => {
130
197
  next();
131
198
  };
132
199
 
133
- export const logAxiosError = (error: AxiosError) => {
200
+ /**
201
+ * Build the message + metadata logged for an AxiosError, with secrets removed.
202
+ * A failing upstream call can echo a connection config in `response.data` or
203
+ * return credential headers, and the raw `error.request` / `error` objects hold
204
+ * the outgoing Authorization header. Response fields are redacted and the raw
205
+ * request object is reduced to a few safe descriptors, so credentials never
206
+ * reach the log. Split out from `logAxiosError` so it can be unit tested.
207
+ */
208
+ export function buildAxiosErrorLog(error: AxiosError): {
209
+ message: string;
210
+ meta: Record<string, unknown>;
211
+ } {
134
212
  if (error.response) {
135
213
  // The request was made and the server responded with a status code
136
- // that falls out of the range of 2xx
137
- logger.error("Axios server-side error", {
138
- url: error.response.config.url,
139
- status: error.response.status,
140
- headers: error.response.headers,
141
- data: error.response.data,
142
- });
143
- } else if (error.request) {
144
- // The request was made but no response was received
145
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
146
- // http.ClientRequest in node.js
147
- logger.error("Axios client-side error", { error: error.request });
148
- } else {
149
- // Something happened in setting up the request that triggered an Error
150
- logger.error("Axios unknown error", { error });
214
+ // that falls out of the range of 2xx.
215
+ return {
216
+ message: "Axios server-side error",
217
+ meta: {
218
+ url: error.response.config.url,
219
+ status: error.response.status,
220
+ headers: redactSensitive(error.response.headers),
221
+ data: redactSensitive(error.response.data),
222
+ },
223
+ };
224
+ }
225
+ if (error.request) {
226
+ // The request was made but no response was received. `error.request` is
227
+ // the raw ClientRequest/XHR and carries the outgoing headers (including
228
+ // Authorization), so log only safe descriptors from the config.
229
+ return {
230
+ message: "Axios client-side error",
231
+ meta: {
232
+ method: error.config?.method,
233
+ url: error.config?.url,
234
+ code: error.code,
235
+ },
236
+ };
151
237
  }
238
+ // Something happened setting up the request. The AxiosError still holds
239
+ // `config.headers`, so log only the message.
240
+ return {
241
+ message: "Axios unknown error",
242
+ meta: { message: error.message },
243
+ };
244
+ }
245
+
246
+ export const logAxiosError = (error: AxiosError) => {
247
+ const { message, meta } = buildAxiosErrorLog(error);
248
+ logger.error(message, meta);
152
249
  };