@t0.labs/daxta 1.2.0 → 1.2.1

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.
@@ -1957,6 +1957,17 @@
1957
1957
  .replace(/</g, "&lt;");
1958
1958
 
1959
1959
  const varNameFromHeader = (header) => {
1960
+ const lower = String(header).toLowerCase();
1961
+ const headerVars = (spec["x-viewer"] && spec["x-viewer"].headerVariables) || {};
1962
+ for (const [k, v] of Object.entries(headerVars)) {
1963
+ if (String(k).toLowerCase() === lower) {
1964
+ const m = String(v).match(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/);
1965
+ if (m) return m[1];
1966
+ }
1967
+ }
1968
+ if (spec["x-viewer"] && spec["x-viewer"].headerVarStyle === "upper-snake") {
1969
+ return String(header).toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_|_$/g, "");
1970
+ }
1960
1971
  const parts = String(header).replace(/^x-/, "").split("-").filter(Boolean);
1961
1972
  if (!parts.length) return String(header).replace(/[^a-zA-Z0-9]/g, "");
1962
1973
  return parts[0] + parts.slice(1).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
@@ -2987,12 +2998,16 @@
2987
2998
  const headerVarsLower = Object.fromEntries(
2988
2999
  Object.entries(headerVars).map(([k, v]) => [String(k).toLowerCase(), String(v)]),
2989
3000
  );
3001
+ const upperSnake = spec["x-viewer"] && spec["x-viewer"].headerVarStyle === "upper-snake";
2990
3002
  const byLower = new Map();
2991
3003
  const add = (key, value) => {
2992
3004
  if (!key) return;
2993
3005
  const lower = String(key).toLowerCase();
2994
3006
  if (lower === "host" || lower === "content-length") return;
2995
- const mapped = lower !== "content-type" ? headerVarsLower[lower] : undefined;
3007
+ let mapped = lower !== "content-type" ? headerVarsLower[lower] : undefined;
3008
+ if (!mapped && upperSnake && lower.startsWith("x-")) {
3009
+ mapped = "{{" + lower.toUpperCase().replace(/-/g, "_") + "}}";
3010
+ }
2996
3011
  byLower.set(lower, { key, value: mapped ?? (value != null ? String(value) : ""), type: "text" });
2997
3012
  };
2998
3013
  for (const param of operation.parameters || []) {
@@ -916,10 +916,34 @@ function viewerTemplateNewerThanHtml() {
916
916
  const newerThan = (filePath) => (0, fs_1.existsSync)(filePath) && (0, fs_1.statSync)(filePath).mtimeMs > htmlMtime;
917
917
  return newerThan((0, paths_1.getViewerAssetPath)()) || newerThan((0, paths_1.getFaviconAssetPath)()) || newerThan((0, paths_1.getFaviconLightAssetPath)());
918
918
  }
919
+ function resolveViewerMeta(spec) {
920
+ const viewer = { ...(0, catalog_1.viewerTreeConfig)() };
921
+ const fn = (0, config_1.getConfig)().headerVariable;
922
+ if (fn) {
923
+ const resolved = { ...(viewer.headerVariables ?? {}) };
924
+ for (const pathItem of Object.values(spec.paths ?? {})) {
925
+ for (const op of Object.values(pathItem ?? {})) {
926
+ for (const scenario of op?.['x-scenarios'] ?? []) {
927
+ for (const h of Object.keys(scenario.headers ?? {})) {
928
+ const lower = h.toLowerCase();
929
+ if (resolved[lower])
930
+ continue;
931
+ const mapped = fn(lower) ?? fn(h);
932
+ if (mapped)
933
+ resolved[lower] = mapped;
934
+ }
935
+ }
936
+ }
937
+ }
938
+ viewer.headerVariables = resolved;
939
+ }
940
+ return { ...spec, 'x-viewer': viewer };
941
+ }
919
942
  function applyViewerMeta(spec) {
920
943
  const info = specInfo();
944
+ const withViewer = resolveViewerMeta(spec);
921
945
  return {
922
- ...spec,
946
+ ...withViewer,
923
947
  info: {
924
948
  ...spec.info,
925
949
  title: info.title,
@@ -927,7 +951,6 @@ function applyViewerMeta(spec) {
927
951
  description: info.description,
928
952
  'x-workspace': info.workspace,
929
953
  },
930
- 'x-viewer': (0, catalog_1.viewerTreeConfig)(),
931
954
  servers: specServers(),
932
955
  };
933
956
  }
@@ -30,6 +30,7 @@ export declare function viewerTreeConfig(): {
30
30
  treePathOverrides: Record<string, string[]>;
31
31
  exampleLabelStyle: "status-case" | "status-title-case" | "full";
32
32
  envPresets: Record<string, import("../config").EnvPreset> | undefined;
33
+ headerVarStyle: "camel" | "upper-snake";
33
34
  headerVariables: Record<string, string>;
34
35
  };
35
36
  export declare function operationTag(pathTemplate: string, method: string): string;
@@ -139,6 +139,7 @@ function viewerTreeConfig() {
139
139
  treePathOverrides: config.treePathOverrides,
140
140
  exampleLabelStyle: config.exampleLabelStyle ?? 'status-title-case',
141
141
  envPresets: config.envPresets,
142
+ headerVarStyle: config.headerVarStyle ?? 'camel',
142
143
  headerVariables: config.headerVariables ?? {},
143
144
  };
144
145
  }
package/dist/config.d.ts CHANGED
@@ -97,6 +97,12 @@ export type DaxtaConfig = {
97
97
  operationTag?: (pathTemplate: string, method: string) => string | undefined;
98
98
  operationTitle?: (method: string, pathTemplate: string) => string | undefined;
99
99
  securitySchemeId?: (headerName: string) => string | undefined;
100
+ /**
101
+ * Naming style for auto-generated header template variables in Postman & Try-it:
102
+ * - camel → x-admin-id becomes {{adminId}} (default)
103
+ * - upper-snake → x-admin-id becomes {{X_ADMIN_ID}}
104
+ */
105
+ headerVarStyle?: 'camel' | 'upper-snake';
100
106
  /**
101
107
  * Map recorded header names to Postman/Try-it template values, e.g.:
102
108
  * `{ 'x-user-id': '{{X_USER_ID}}', authorization: 'Bearer {{AUTH_TOKEN}}' }`
package/dist/config.js CHANGED
@@ -56,6 +56,7 @@ const DEFAULTS = {
56
56
  treeSubResourceMode: 'nested',
57
57
  treePathOverrides: {},
58
58
  treeResourceAliases: {},
59
+ headerVarStyle: 'camel',
59
60
  headerVariables: {},
60
61
  exampleLabelStyle: 'status-title-case',
61
62
  writeMode: 'on-complete',
@@ -76,6 +76,12 @@ function resolveConfiguredHeaderValue(key) {
76
76
  if (k.toLowerCase() === lower)
77
77
  return v;
78
78
  }
79
+ if (config.headerVarStyle === 'upper-snake') {
80
+ if (lower === 'authorization')
81
+ return 'Bearer {{AUTH_TOKEN}}';
82
+ if (lower.startsWith('x-'))
83
+ return `{{${lower.toUpperCase().replace(/-/g, '_')}}}`;
84
+ }
79
85
  return undefined;
80
86
  }
81
87
  function buildHeaders(operation, scenarioHeaders, hasBody) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "DAxTA — Tested behavior. Trusted API docs. Generate API documentation from observed test execution.",
5
5
  "license": "MIT",
6
6
  "author": {