@common-grants/cli
Version:
The CommonGrants protocol CLI tool
99 lines (98 loc) • 3.73 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckApiOptionsSchema = exports.CheckSpecOptionsSchema = exports.CheckSpecArgsSchema = exports.CheckApiArgsSchema = exports.availableVersions = void 0;
const zod_1 = require("zod");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
/**
* Dynamically get available base spec versions from the openapi directory
* Returns versions sorted in reverse order (latest first)
*/
function getAvailableBaseVersions() {
const openapiDir = path.resolve(__dirname, "../../../lib/openapi");
if (!fs.existsSync(openapiDir)) {
return [];
}
const files = fs.readdirSync(openapiDir);
const versions = [];
for (const file of files) {
const match = file.match(/^openapi\.(.+)\.yaml$/);
if (match) {
versions.push(match[1]);
}
}
// Sort in reverse order so latest version comes first
return versions.sort().reverse();
}
exports.availableVersions = getAvailableBaseVersions();
/**
* Positional arguments that must be passed to the `check api` command.
*/
exports.CheckApiArgsSchema = zod_1.z.object({
apiUrl: zod_1.z.string().url(),
specPath: zod_1.z
.string()
.endsWith(".json")
.or(zod_1.z.string().endsWith(".yaml"))
.or(zod_1.z.string().endsWith(".yml")),
});
/**
* Positional arguments that must be passed to the `check spec` command.
*/
exports.CheckSpecArgsSchema = zod_1.z.object({
specPath: zod_1.z
.string()
.endsWith(".json")
.or(zod_1.z.string().endsWith(".yaml"))
.or(zod_1.z.string().endsWith(".yml")),
});
/**
* Optional arguments that can be passed to the `check spec` command using flags (e.g. `--base` or `--protocol-version`)
*/
exports.CheckSpecOptionsSchema = zod_1.z.object({
base: zod_1.z.string().optional(),
protocolVersion: exports.availableVersions.length > 0
? zod_1.z.enum(exports.availableVersions).optional()
: zod_1.z.string().optional(),
});
/**
* Optional arguments that can be passed to the `check api` command using flags (e.g. `--client` or `--report`)
*/
exports.CheckApiOptionsSchema = zod_1.z.object({
client: zod_1.z.string().optional(),
report: zod_1.z.enum(["json", "html"]).optional(),
auth: zod_1.z.string().optional(),
});