@vidos-id/openid4vc-cli-common 0.0.0-rc.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.
@@ -0,0 +1,40 @@
1
+ import { ZodError, z } from "zod";
2
+
3
+ //#region src/errors.d.ts
4
+ declare function handleCliError(error: unknown): never;
5
+ declare function formatZodError(error: ZodError): string;
6
+ //#endregion
7
+ //#region src/io.d.ts
8
+ declare function readTextInput(value?: string, filePath?: string): Promise<string>;
9
+ declare function writeOptionalFile(filePath: string | undefined, value: unknown): Promise<void>;
10
+ declare function printResult(value: unknown, format: string): void;
11
+ //#endregion
12
+ //#region src/schemas.d.ts
13
+ declare const outputFormatSchema: z.ZodEnum<{
14
+ text: "text";
15
+ json: "json";
16
+ raw: "raw";
17
+ }>;
18
+ declare const textOutputFormatSchema: z.ZodEnum<{
19
+ text: "text";
20
+ json: "json";
21
+ }>;
22
+ declare const jsonOutputFormatSchema: z.ZodEnum<{
23
+ json: "json";
24
+ }>;
25
+ //#endregion
26
+ //#region src/verbose.d.ts
27
+ declare function setVerbose(enabled: boolean): void;
28
+ declare function isVerbose(): boolean;
29
+ declare function verbose(message: string): void;
30
+ //#endregion
31
+ //#region src/version.d.ts
32
+ declare function readPackageVersion(packageJsonPath: string): Promise<string>;
33
+ declare function resolveCliVersion(packageJsonPath: string): Promise<string>;
34
+ /**
35
+ * Resolve the package.json path relative to the caller's directory.
36
+ * Pass `import.meta.url` from the entry point.
37
+ */
38
+ declare function resolvePackageJsonPath(importMetaUrl: string): string;
39
+ //#endregion
40
+ export { formatZodError, handleCliError, isVerbose, jsonOutputFormatSchema, outputFormatSchema, printResult, readPackageVersion, readTextInput, resolveCliVersion, resolvePackageJsonPath, setVerbose, textOutputFormatSchema, verbose, writeOptionalFile };
package/dist/index.mjs ADDED
@@ -0,0 +1,85 @@
1
+ import { ZodError, z } from "zod";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ //#region src/errors.ts
5
+ function handleCliError(error) {
6
+ if (error instanceof ZodError) {
7
+ process.stderr.write(`${formatZodError(error)}\n`);
8
+ process.exit(1);
9
+ }
10
+ const message = error instanceof Error ? error.message : String(error);
11
+ process.stderr.write(`${message}\n`);
12
+ process.exit(1);
13
+ }
14
+ function formatZodError(error) {
15
+ return error.issues.map((issue) => {
16
+ return `${issue.path.length > 0 ? issue.path.join(".") : "input"}: ${issue.message}`;
17
+ }).join("\n");
18
+ }
19
+ //#endregion
20
+ //#region src/io.ts
21
+ async function readTextInput(value, filePath) {
22
+ if (value !== void 0) return value;
23
+ if (filePath !== void 0) return readFile(filePath, "utf8");
24
+ throw new Error("Expected inline value or file path");
25
+ }
26
+ async function writeOptionalFile(filePath, value) {
27
+ if (!filePath) return;
28
+ await mkdir(dirname(filePath), { recursive: true });
29
+ if (typeof value === "string") {
30
+ await writeFile(filePath, value, "utf8");
31
+ return;
32
+ }
33
+ await writeFile(filePath, JSON.stringify(value, null, 2), "utf8");
34
+ }
35
+ function printResult(value, format) {
36
+ if (format === "json") {
37
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
38
+ return;
39
+ }
40
+ process.stdout.write(`${String(value)}\n`);
41
+ }
42
+ //#endregion
43
+ //#region src/schemas.ts
44
+ const outputFormatSchema = z.enum([
45
+ "text",
46
+ "json",
47
+ "raw"
48
+ ]);
49
+ const textOutputFormatSchema = z.enum(["text", "json"]);
50
+ const jsonOutputFormatSchema = z.enum(["json"]);
51
+ //#endregion
52
+ //#region src/verbose.ts
53
+ let verboseEnabled = false;
54
+ function setVerbose(enabled) {
55
+ verboseEnabled = enabled;
56
+ }
57
+ function isVerbose() {
58
+ return verboseEnabled;
59
+ }
60
+ function verbose(message) {
61
+ if (verboseEnabled) process.stderr.write(`[verbose] ${message}\n`);
62
+ }
63
+ //#endregion
64
+ //#region src/version.ts
65
+ async function readPackageVersion(packageJsonPath) {
66
+ try {
67
+ const content = JSON.parse(await readFile(packageJsonPath, "utf8"));
68
+ return typeof content.version === "string" ? content.version : "0.0.0";
69
+ } catch {
70
+ return "0.0.0";
71
+ }
72
+ }
73
+ async function resolveCliVersion(packageJsonPath) {
74
+ if (typeof __CLI_VERSION__ === "string" && __CLI_VERSION__.length > 0) return __CLI_VERSION__;
75
+ return readPackageVersion(packageJsonPath);
76
+ }
77
+ /**
78
+ * Resolve the package.json path relative to the caller's directory.
79
+ * Pass `import.meta.url` from the entry point.
80
+ */
81
+ function resolvePackageJsonPath(importMetaUrl) {
82
+ return join(dirname(new URL(importMetaUrl).pathname), "..", "package.json");
83
+ }
84
+ //#endregion
85
+ export { formatZodError, handleCliError, isVerbose, jsonOutputFormatSchema, outputFormatSchema, printResult, readPackageVersion, readTextInput, resolveCliVersion, resolvePackageJsonPath, setVerbose, textOutputFormatSchema, verbose, writeOptionalFile };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vidos-id/openid4vc-cli-common",
3
+ "description": "Shared CLI utilities for the openid4vc-tools packages.",
4
+ "version": "0.0.0-rc.1",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/vidos-id/openid4vc-tools.git",
8
+ "directory": "packages/cli-common"
9
+ },
10
+ "type": "module",
11
+ "engines": {
12
+ "node": ">=20"
13
+ },
14
+ "main": "./dist/index.mjs",
15
+ "types": "./dist/index.d.mts",
16
+ "exports": {
17
+ ".": {
18
+ "development": {
19
+ "types": "./src/index.ts",
20
+ "default": "./src/index.ts"
21
+ },
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ }
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown",
28
+ "check-types": "tsc --noEmit --project ../../tsconfig.json",
29
+ "package-publish": "bun publish",
30
+ "test": "bun --conditions=development test --pass-with-no-tests"
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "publishConfig": {
36
+ "registry": "https://registry.npmjs.org/",
37
+ "access": "public"
38
+ },
39
+ "dependencies": {
40
+ "commander": "^14.0.3",
41
+ "zod": "^4.3.6"
42
+ }
43
+ }