@t0.labs/daxta 0.4.7 → 0.4.9

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.
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.normalizeViewerEnvStore = normalizeViewerEnvStore;
37
+ exports.readViewerEnvStore = readViewerEnvStore;
38
+ exports.writeViewerEnvStore = writeViewerEnvStore;
39
+ exports.ensureViewerStoreSeeded = ensureViewerStoreSeeded;
40
+ const fs_1 = require("fs");
41
+ const path = __importStar(require("path"));
42
+ const config_1 = require("../config");
43
+ const paths_1 = require("./paths");
44
+ function isRow(value) {
45
+ return Boolean(value && typeof value === 'object' && typeof value.key === 'string');
46
+ }
47
+ function normalizeRows(value) {
48
+ if (!Array.isArray(value))
49
+ return [];
50
+ return value.filter(isRow).map((row) => ({ key: String(row.key || ''), value: String(row.value ?? '') }));
51
+ }
52
+ /** Validate / coerce UI store JSON. Returns null if unusable. */
53
+ function normalizeViewerEnvStore(raw) {
54
+ if (!raw || typeof raw !== 'object')
55
+ return null;
56
+ const input = raw;
57
+ const envsIn = input.envs;
58
+ if (!envsIn || typeof envsIn !== 'object')
59
+ return null;
60
+ const envs = {};
61
+ for (const [name, env] of Object.entries(envsIn)) {
62
+ if (!env || typeof env !== 'object')
63
+ continue;
64
+ const envObj = env;
65
+ const headerGroupsIn = envObj.headerGroups;
66
+ const headerGroups = {};
67
+ if (headerGroupsIn && typeof headerGroupsIn === 'object') {
68
+ for (const [group, rows] of Object.entries(headerGroupsIn)) {
69
+ headerGroups[group] = normalizeRows(rows);
70
+ }
71
+ }
72
+ if (!Object.keys(headerGroups).length) {
73
+ headerGroups.default = [{ key: 'content-type', value: 'application/json' }];
74
+ }
75
+ envs[name] = {
76
+ variables: normalizeRows(envObj.variables),
77
+ headerGroups,
78
+ };
79
+ }
80
+ if (!Object.keys(envs).length)
81
+ return null;
82
+ const activeEnv = typeof input.activeEnv === 'string' && envs[input.activeEnv] ? input.activeEnv : Object.keys(envs)[0];
83
+ const groups = Object.keys(envs[activeEnv].headerGroups);
84
+ const activeGroup = typeof input.activeGroup === 'string' && groups.includes(input.activeGroup) ? input.activeGroup : groups[0] || 'default';
85
+ return { activeEnv, activeGroup, envs };
86
+ }
87
+ function readViewerEnvStore() {
88
+ const filePath = (0, paths_1.getViewerStorePath)();
89
+ if (!(0, fs_1.existsSync)(filePath))
90
+ return null;
91
+ try {
92
+ return normalizeViewerEnvStore(JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8')));
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ }
98
+ function writeViewerEnvStore(raw) {
99
+ const store = normalizeViewerEnvStore(raw);
100
+ if (!store)
101
+ throw new Error('Invalid viewer env store');
102
+ const filePath = (0, paths_1.getViewerStorePath)();
103
+ (0, fs_1.mkdirSync)(path.dirname(filePath), { recursive: true });
104
+ (0, fs_1.writeFileSync)(filePath, `${JSON.stringify(store, null, 2)}\n`);
105
+ return store;
106
+ }
107
+ /**
108
+ * If viewer-store.json is missing, seed it from `envPresets` in daxta.config
109
+ * (local / staging / production baseUrls). Does not overwrite an existing file.
110
+ */
111
+ function ensureViewerStoreSeeded() {
112
+ const filePath = (0, paths_1.getViewerStorePath)();
113
+ if ((0, fs_1.existsSync)(filePath))
114
+ return null;
115
+ const config = (0, config_1.getConfig)();
116
+ const presets = config.envPresets ?? { local: { baseUrl: config.baseUrl } };
117
+ const envs = {};
118
+ for (const [name, preset] of Object.entries(presets)) {
119
+ const variables = [{ key: 'baseUrl', value: String(preset.baseUrl || config.baseUrl) }];
120
+ for (const [key, value] of Object.entries(preset.variables ?? {})) {
121
+ if (!key || key === 'baseUrl')
122
+ continue;
123
+ variables.push({ key, value: String(value ?? '') });
124
+ }
125
+ envs[name] = {
126
+ variables,
127
+ headerGroups: { default: [{ key: 'content-type', value: 'application/json' }] },
128
+ };
129
+ }
130
+ const names = Object.keys(envs);
131
+ if (!names.length)
132
+ return null;
133
+ writeViewerEnvStore({ activeEnv: names.includes('local') ? 'local' : names[0], activeGroup: 'default', envs });
134
+ return filePath;
135
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {