@usejourney/core 0.1.2 → 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.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 "*"),
@@ -396,7 +400,16 @@ interface HttpContext {
396
400
  subJourneyCache?: SubJourneyCache;
397
401
  /** Default TTL (ms) for sub-journey cache writes; per-call `cacheTtlMs` overrides. */
398
402
  subJourneyCacheTtlMs?: number;
403
+ /**
404
+ * Run-wide default request timeout (ms). Tri-state: `undefined` falls back
405
+ * to `DEFAULT_REQUEST_TIMEOUT_MS`; a number sets a custom default; `null`
406
+ * explicitly disables the default (no timeout). A step's own
407
+ * `timeoutMs` always overrides this.
408
+ */
409
+ defaultTimeoutMs?: number | null;
399
410
  }
411
+ /** Fallback request timeout (ms) when neither a step nor `HttpContext.defaultTimeoutMs` set one. */
412
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
400
413
  interface RequestSpec {
401
414
  method: HttpMethod;
402
415
  url: string;
@@ -693,4 +706,4 @@ type FetchResponse = Awaited<ReturnType<typeof globalThis.fetch>>;
693
706
  */
694
707
  declare function fetch$1(input: FetchInput, init?: FetchInit): Promise<FetchResponse>;
695
708
 
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 };
709
+ export { AssertionError, type BuildRequestOptions, type CacheEntry, type CacheMode, type ConsoleLoggerOptions, DEFAULT_REQUEST_TIMEOUT_MS, 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) {
@@ -375,6 +392,7 @@ function loggerFromEnv(env2 = process.env) {
375
392
  }
376
393
 
377
394
  // src/http.ts
395
+ var DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
378
396
  function resolveUrl(endpoint, ctx, params, query) {
379
397
  const base = isEndpointRef(endpoint) ? ctx.baseUrl : endpoint.baseUrl ?? ctx.baseUrl;
380
398
  if (!base) {
@@ -419,7 +437,8 @@ function buildRequest(opts, ctx) {
419
437
  }
420
438
  const spec = { method: opts.endpoint.method, url, headers };
421
439
  if (hasBody) spec.body = opts.body;
422
- if (opts.timeoutMs !== void 0) spec.timeoutMs = opts.timeoutMs;
440
+ const resolvedTimeout = opts.timeoutMs !== void 0 ? opts.timeoutMs : ctx.defaultTimeoutMs === null ? void 0 : ctx.defaultTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
441
+ if (resolvedTimeout !== void 0) spec.timeoutMs = resolvedTimeout;
423
442
  return spec;
424
443
  }
425
444
  function lower(h) {
@@ -1172,6 +1191,7 @@ function bodyForLog(body) {
1172
1191
  import { z as z2 } from "zod";
1173
1192
  export {
1174
1193
  AssertionError,
1194
+ DEFAULT_REQUEST_TIMEOUT_MS,
1175
1195
  DiskSubJourneyCache,
1176
1196
  JourneyConfigSchema,
1177
1197
  MemorySubJourneyCache,
@@ -1188,10 +1208,12 @@ export {
1188
1208
  execute,
1189
1209
  expect,
1190
1210
  fetch2 as fetch,
1211
+ formatOpaqueBody,
1191
1212
  getCurrentCtx,
1192
1213
  getRegisteredJourneys,
1193
1214
  invokeJourney,
1194
1215
  isEndpointRef,
1216
+ isTextualContentType,
1195
1217
  journey,
1196
1218
  listEnvironments,
1197
1219
  listRuns,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usejourney/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",