@usejourney/core 0.1.1 → 0.1.3

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.d.ts CHANGED
@@ -351,6 +351,10 @@ interface ConsoleLoggerOptions {
351
351
  /** Truncate logged response/request bodies past this many chars (default 1024). */
352
352
  maxBodyChars?: number;
353
353
  }
354
+ /** True when a response body in this content-type is safe to print as-is. No signal (empty/undefined) defaults to textual. */
355
+ declare function isTextualContentType(contentType: string | undefined): boolean;
356
+ /** `file[N bytes]` from a `content-length` header, or `file[]` when the length is unknown. */
357
+ declare function formatOpaqueBody(headers: Record<string, string>): string;
354
358
  declare function createConsoleLogger(opts?: ConsoleLoggerOptions): JourneyLogger;
355
359
  /**
356
360
  * Returns a console logger when DEBUG env var includes "journey" (or "*"),
@@ -693,4 +697,4 @@ type FetchResponse = Awaited<ReturnType<typeof globalThis.fetch>>;
693
697
  */
694
698
  declare function fetch$1(input: FetchInput, init?: FetchInit): Promise<FetchResponse>;
695
699
 
696
- export { AssertionError, type BuildRequestOptions, type CacheEntry, type CacheMode, type ConsoleLoggerOptions, DiskSubJourneyCache, type Endpoint, type EndpointDescriptor, type EndpointRef, type EntryJourneyOptions, type EnvValues, type Expectation, type GroupEndEvent, type GroupStartEvent, type HttpContext, type HttpMethod, type HttpResponse, type InvokeJourneyOptions, type JourneyConfig, JourneyConfigSchema, type JourneyDef, type JourneyHandle, type JourneyLogger, type JourneyOptions, type JourneyResult, type K6JourneyOptions, type LoadedConfig, type LogEvent, MemorySubJourneyCache, type PipelineNode, type PlannedNode, type RequestLog, type RequestSpec, type ResponseLog, type ResponseOf, type ReusableJourneyOptions, type RunEndEvent, type RunMeta, type RunPlannedEvent, type RunRecord, type RunStartEvent, type RunSummary, SECRET_HEADERS, type StepDef, type StepEndEvent, type StepOptions, type StepResult, type StepStartEvent, type SubJourneyCache, type SubJourneyCallDef, buildRequest, clearActiveEnvironment, clearRegistry, collectPipeline, collectSubPipeline, createConsoleLogger, createSubJourneyCache, describeError, env, execute, expect, fetch$1 as fetch, getCurrentCtx, getRegisteredJourneys, invokeJourney, isEndpointRef, journey, listEnvironments, listRuns, loadConfig, loadEnvironment, loggerFromEnv, maskHeaders, output, planJourney, pruneRuns, readRun, resolveBaseUrl, resolveConfigPaths, resolveUrl, runAllRegistered, runJourney, setActiveEnvironment, step, subJourneyCacheKey, tryEnv, writeRun };
700
+ export { AssertionError, type BuildRequestOptions, type CacheEntry, type CacheMode, type ConsoleLoggerOptions, DiskSubJourneyCache, type Endpoint, type EndpointDescriptor, type EndpointRef, type EntryJourneyOptions, type EnvValues, type Expectation, type GroupEndEvent, type GroupStartEvent, type HttpContext, type HttpMethod, type HttpResponse, type InvokeJourneyOptions, type JourneyConfig, JourneyConfigSchema, type JourneyDef, type JourneyHandle, type JourneyLogger, type JourneyOptions, type JourneyResult, type K6JourneyOptions, type LoadedConfig, type LogEvent, MemorySubJourneyCache, type PipelineNode, type PlannedNode, type RequestLog, type RequestSpec, type ResponseLog, type ResponseOf, type ReusableJourneyOptions, type RunEndEvent, type RunMeta, type RunPlannedEvent, type RunRecord, type RunStartEvent, type RunSummary, SECRET_HEADERS, type StepDef, type StepEndEvent, type StepOptions, type StepResult, type StepStartEvent, type SubJourneyCache, type SubJourneyCallDef, buildRequest, clearActiveEnvironment, clearRegistry, collectPipeline, collectSubPipeline, createConsoleLogger, createSubJourneyCache, describeError, env, execute, expect, fetch$1 as fetch, formatOpaqueBody, getCurrentCtx, getRegisteredJourneys, invokeJourney, isEndpointRef, isTextualContentType, journey, listEnvironments, listRuns, loadConfig, loadEnvironment, loggerFromEnv, maskHeaders, output, planJourney, pruneRuns, readRun, resolveBaseUrl, resolveConfigPaths, resolveUrl, runAllRegistered, runJourney, setActiveEnvironment, step, subJourneyCacheKey, tryEnv, writeRun };
package/dist/index.js CHANGED
@@ -333,8 +333,25 @@ function maskHeaders(headers, masks = SECRET_HEADERS) {
333
333
  }
334
334
  return out;
335
335
  }
336
- function fmtBody(body, max) {
336
+ var TEXTUAL_CONTENT_TYPE_RE = /json|^text\/|xml|html|javascript|x-www-form-urlencoded|csv|yaml/i;
337
+ function isTextualContentType(contentType) {
338
+ if (!contentType) return true;
339
+ return TEXTUAL_CONTENT_TYPE_RE.test(contentType);
340
+ }
341
+ function findHeader(headers, name) {
342
+ const lower2 = name.toLowerCase();
343
+ for (const [k, v] of Object.entries(headers)) {
344
+ if (k.toLowerCase() === lower2) return v;
345
+ }
346
+ return void 0;
347
+ }
348
+ function formatOpaqueBody(headers) {
349
+ const len = findHeader(headers, "content-length");
350
+ return len ? `file[${len} bytes]` : "file[]";
351
+ }
352
+ function fmtBody(body, max, headers) {
337
353
  if (body === void 0 || body === null) return "";
354
+ if (!isTextualContentType(findHeader(headers, "content-type"))) return formatOpaqueBody(headers);
338
355
  const s = typeof body === "string" ? body : JSON.stringify(body);
339
356
  return s.length > max ? `${s.slice(0, max)}\u2026 (${s.length - max} more chars)` : s;
340
357
  }
@@ -348,12 +365,12 @@ function createConsoleLogger(opts = {}) {
348
365
  const headers = mask ? maskHeaders(req.headers) : req.headers;
349
366
  const headerKeys = Object.keys(headers);
350
367
  if (headerKeys.length > 0) write(` headers ${JSON.stringify(headers)}`);
351
- const body = fmtBody(req.body, max);
368
+ const body = fmtBody(req.body, max, req.headers);
352
369
  if (body) write(` body ${body}`);
353
370
  },
354
371
  onResponse(req, res) {
355
372
  write(`\u2190 ${res.status} ${req.method} ${req.url} (${res.durationMs}ms)`);
356
- const body = fmtBody(res.body, max);
373
+ const body = fmtBody(res.body, max, res.headers);
357
374
  if (body) write(` body ${body}`);
358
375
  },
359
376
  onError(req, err, durationMs) {
@@ -1188,10 +1205,12 @@ export {
1188
1205
  execute,
1189
1206
  expect,
1190
1207
  fetch2 as fetch,
1208
+ formatOpaqueBody,
1191
1209
  getCurrentCtx,
1192
1210
  getRegisteredJourneys,
1193
1211
  invokeJourney,
1194
1212
  isEndpointRef,
1213
+ isTextualContentType,
1195
1214
  journey,
1196
1215
  listEnvironments,
1197
1216
  listRuns,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usejourney/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",