generate-ui-cli 1.0.0

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,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchPermissions = fetchPermissions;
7
+ exports.getPermissions = getPermissions;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const token_1 = require("./token");
12
+ const config_1 = require("../runtime/config");
13
+ const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.generateui');
14
+ const PERMISSIONS_PATH = path_1.default.join(CONFIG_DIR, 'permissions.json');
15
+ const DEV_OFFLINE_DAYS = 7;
16
+ const FREE_DEFAULT = {
17
+ plan: 'free',
18
+ features: {
19
+ intelligentGeneration: false,
20
+ safeRegeneration: false,
21
+ uiOverrides: false,
22
+ maxGenerations: 1
23
+ }
24
+ };
25
+ function ensureConfigDir() {
26
+ fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
27
+ }
28
+ function readCache() {
29
+ if (!fs_1.default.existsSync(PERMISSIONS_PATH))
30
+ return null;
31
+ try {
32
+ const parsed = JSON.parse(fs_1.default.readFileSync(PERMISSIONS_PATH, 'utf-8'));
33
+ if (!parsed.plan || !parsed.features)
34
+ return null;
35
+ return parsed;
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ }
41
+ function writeCache(response) {
42
+ ensureConfigDir();
43
+ const fetchedAt = new Date().toISOString();
44
+ const expiresAt = new Date(Date.now() + DEV_OFFLINE_DAYS * 24 * 60 * 60 * 1000).toISOString();
45
+ const payload = {
46
+ ...response,
47
+ fetchedAt,
48
+ expiresAt
49
+ };
50
+ fs_1.default.writeFileSync(PERMISSIONS_PATH, JSON.stringify(payload, null, 2));
51
+ }
52
+ async function fetchPermissions() {
53
+ const apiBase = (0, config_1.getApiBaseUrl)();
54
+ const token = (0, token_1.loadToken)();
55
+ const headers = {
56
+ 'Content-Type': 'application/json'
57
+ };
58
+ if (token?.accessToken) {
59
+ headers.Authorization = `Bearer ${token.accessToken}`;
60
+ }
61
+ const response = await fetch(`${apiBase}/me`, {
62
+ method: 'GET',
63
+ headers
64
+ });
65
+ if (!response.ok) {
66
+ throw new Error('Failed to fetch permissions');
67
+ }
68
+ const data = (await response.json());
69
+ writeCache(data);
70
+ return data;
71
+ }
72
+ function cacheIsValid(cache) {
73
+ const expiresAt = new Date(cache.expiresAt).getTime();
74
+ if (Number.isNaN(expiresAt))
75
+ return false;
76
+ return expiresAt > Date.now();
77
+ }
78
+ async function getPermissions() {
79
+ try {
80
+ return await fetchPermissions();
81
+ }
82
+ catch {
83
+ const tokenPresent = (0, token_1.tokenFileExists)();
84
+ const cache = readCache();
85
+ if (cache && cacheIsValid(cache)) {
86
+ return { plan: cache.plan, features: cache.features };
87
+ }
88
+ if (tokenPresent) {
89
+ throw new Error('Please reconnect to verify your license.');
90
+ }
91
+ return FREE_DEFAULT;
92
+ }
93
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tokenFileExists = tokenFileExists;
7
+ exports.loadToken = loadToken;
8
+ exports.saveToken = saveToken;
9
+ exports.clearToken = clearToken;
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const os_1 = __importDefault(require("os"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.generateui');
14
+ const TOKEN_PATH = path_1.default.join(CONFIG_DIR, 'token.json');
15
+ function ensureConfigDir() {
16
+ fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
17
+ }
18
+ function tokenFileExists() {
19
+ return fs_1.default.existsSync(TOKEN_PATH);
20
+ }
21
+ function loadToken() {
22
+ if (!tokenFileExists())
23
+ return null;
24
+ try {
25
+ const parsed = JSON.parse(fs_1.default.readFileSync(TOKEN_PATH, 'utf-8'));
26
+ if (!parsed.accessToken || !parsed.expiresAt)
27
+ return null;
28
+ const expiresAt = new Date(parsed.expiresAt).getTime();
29
+ if (Number.isNaN(expiresAt) || expiresAt <= Date.now()) {
30
+ return null;
31
+ }
32
+ return parsed;
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
38
+ function saveToken(token) {
39
+ ensureConfigDir();
40
+ fs_1.default.writeFileSync(TOKEN_PATH, JSON.stringify(token, null, 2));
41
+ }
42
+ function clearToken() {
43
+ if (fs_1.default.existsSync(TOKEN_PATH)) {
44
+ fs_1.default.rmSync(TOKEN_PATH);
45
+ }
46
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadOpenApi = loadOpenApi;
7
+ const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
8
+ async function loadOpenApi(path) {
9
+ return swagger_parser_1.default.dereference(path);
10
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncOverlay = syncOverlay;
4
+ function syncOverlay(base, overlay) {
5
+ if (!overlay)
6
+ return base;
7
+ return {
8
+ ...base,
9
+ layout: overlay.layout ?? base.layout,
10
+ actions: overlay.actions ?? base.actions,
11
+ fields: mergeFields(base.fields, overlay.fields)
12
+ };
13
+ }
14
+ function mergeFields(base, overlay = []) {
15
+ const overlayMap = new Map(overlay.map(f => [f.name, f]));
16
+ return base.map(baseField => {
17
+ const custom = overlayMap.get(baseField.name);
18
+ if (!custom)
19
+ return baseField;
20
+ return {
21
+ ...baseField,
22
+ ...custom,
23
+ required: baseField.required
24
+ };
25
+ });
26
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCliVersion = getCliVersion;
7
+ exports.getApiBaseUrl = getApiBaseUrl;
8
+ exports.getWebAuthUrl = getWebAuthUrl;
9
+ const package_json_1 = __importDefault(require("../../package.json"));
10
+ function getCliVersion() {
11
+ return package_json_1.default.version || '0.0.0';
12
+ }
13
+ function getApiBaseUrl() {
14
+ return (process.env.GENERATEUI_API_BASE_URL?.trim() ||
15
+ 'http://localhost:3000');
16
+ }
17
+ function getWebAuthUrl() {
18
+ return (process.env.GENERATEUI_WEB_AUTH_URL?.trim() ||
19
+ 'http://localhost:3001');
20
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openBrowser = openBrowser;
4
+ const child_process_1 = require("child_process");
5
+ function openBrowser(url) {
6
+ const platform = process.platform;
7
+ let command = '';
8
+ let args = [];
9
+ if (platform === 'darwin') {
10
+ command = 'open';
11
+ args = [url];
12
+ }
13
+ else if (platform === 'win32') {
14
+ command = 'cmd';
15
+ args = ['/c', 'start', '', url];
16
+ }
17
+ else {
18
+ command = 'xdg-open';
19
+ args = [url];
20
+ }
21
+ const child = (0, child_process_1.spawn)(command, args, {
22
+ stdio: 'ignore',
23
+ detached: true
24
+ });
25
+ child.unref();
26
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendTelemetry = sendTelemetry;
4
+ const config_1 = require("./runtime/config");
5
+ const device_1 = require("./license/device");
6
+ function getOsName() {
7
+ switch (process.platform) {
8
+ case 'darwin':
9
+ return 'macos';
10
+ case 'win32':
11
+ return 'windows';
12
+ default:
13
+ return 'linux';
14
+ }
15
+ }
16
+ async function sendTelemetry(command, enabled) {
17
+ if (!enabled)
18
+ return;
19
+ const apiBase = (0, config_1.getApiBaseUrl)();
20
+ const device = (0, device_1.loadDeviceIdentity)();
21
+ const payload = {
22
+ deviceId: device.deviceId,
23
+ command,
24
+ cliVersion: (0, config_1.getCliVersion)(),
25
+ os: getOsName(),
26
+ timestamp: new Date().toISOString()
27
+ };
28
+ try {
29
+ await fetch(`${apiBase}/telemetry`, {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/json'
33
+ },
34
+ body: JSON.stringify(payload)
35
+ });
36
+ }
37
+ catch {
38
+ // Telemetry must never block execution.
39
+ }
40
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "generate-ui-cli",
3
+ "version": "1.0.0",
4
+ "description": "Generate UI from OpenAPI locally with optional Dev unlocks.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/nicoleprevid/GenerateUI.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/nicoleprevid/GenerateUI/issues"
12
+ },
13
+ "homepage": "https://github.com/nicoleprevid/GenerateUI#readme",
14
+ "keywords": [
15
+ "openapi",
16
+ "cli",
17
+ "ui",
18
+ "generate-ui"
19
+ ],
20
+ "author": "",
21
+ "bin": {
22
+ "generate-ui": "dist/index.js"
23
+ },
24
+ "main": "dist/index.js",
25
+ "type": "commonjs",
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE*"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18.20.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.json",
39
+ "dev": "ts-node src/index.ts",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "dependencies": {
43
+ "@apidevtools/swagger-parser": "^12.1.0",
44
+ "commander": "^14.0.2",
45
+ "handlebars": "^4.7.8",
46
+ "yaml": "^2.8.2"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^25.0.2",
50
+ "ts-node": "^10.9.2",
51
+ "typescript": "^5.9.3"
52
+ }
53
+ }