@ollie-shop/cli 0.2.0 → 0.3.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.
- package/.turbo/turbo-build.log +2 -11
- package/CHANGELOG.md +13 -7
- package/CLAUDE_CLI.md +265 -0
- package/README.md +704 -8
- package/__tests__/mocks/console.ts +22 -0
- package/__tests__/mocks/core.ts +137 -0
- package/__tests__/mocks/index.ts +4 -0
- package/__tests__/mocks/inquirer.ts +16 -0
- package/__tests__/mocks/progress.ts +19 -0
- package/dist/__tests__/helpers/cli-test-helper.d.ts +89 -0
- package/dist/__tests__/helpers/cli-test-helper.d.ts.map +1 -0
- package/dist/__tests__/helpers/cli-test-helper.js +220 -0
- package/dist/__tests__/mocks/index.d.ts +69 -0
- package/dist/__tests__/mocks/index.d.ts.map +1 -0
- package/dist/__tests__/mocks/index.js +77 -0
- package/dist/actions/component.actions.d.ts +14 -0
- package/dist/actions/component.actions.d.ts.map +1 -0
- package/dist/actions/component.actions.js +273 -0
- package/dist/actions/function.actions.d.ts +15 -0
- package/dist/actions/function.actions.d.ts.map +1 -0
- package/dist/actions/function.actions.js +254 -0
- package/dist/actions/project.actions.d.ts +17 -0
- package/dist/actions/project.actions.d.ts.map +1 -0
- package/dist/actions/project.actions.js +97 -0
- package/dist/actions/version.actions.d.ts +19 -0
- package/dist/actions/version.actions.d.ts.map +1 -0
- package/dist/actions/version.actions.js +216 -0
- package/dist/commands/component.d.ts +3 -0
- package/dist/commands/component.d.ts.map +1 -0
- package/dist/commands/component.js +192 -0
- package/dist/commands/docs.d.ts +3 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +16 -0
- package/dist/commands/function.d.ts +3 -0
- package/dist/commands/function.d.ts.map +1 -0
- package/dist/commands/function.js +243 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +20 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +26 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +175 -0
- package/dist/commands/project.d.ts +3 -0
- package/dist/commands/project.d.ts.map +1 -0
- package/dist/commands/project.js +78 -0
- package/dist/commands/store-version.d.ts +3 -0
- package/dist/commands/store-version.d.ts.map +1 -0
- package/dist/commands/store-version.js +241 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +46 -0
- package/dist/commands/whoami.d.ts +3 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +41 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -478
- package/dist/prompts/component.prompts.d.ts +14 -0
- package/dist/prompts/component.prompts.d.ts.map +1 -0
- package/dist/prompts/component.prompts.js +75 -0
- package/dist/prompts/function.prompts.d.ts +21 -0
- package/dist/prompts/function.prompts.d.ts.map +1 -0
- package/dist/prompts/function.prompts.js +127 -0
- package/dist/schemas/command.schema.d.ts +516 -0
- package/dist/schemas/command.schema.d.ts.map +1 -0
- package/dist/schemas/command.schema.js +267 -0
- package/dist/types/index.d.ts +147 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/utils/auth.d.ts +4 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +26 -0
- package/dist/utils/cli-progress-reporter.d.ts +12 -0
- package/dist/utils/cli-progress-reporter.d.ts.map +1 -0
- package/dist/utils/cli-progress-reporter.js +77 -0
- package/dist/utils/command-builder.d.ts +22 -0
- package/dist/utils/command-builder.d.ts.map +1 -0
- package/dist/utils/command-builder.js +268 -0
- package/dist/utils/command-helpers.d.ts +19 -0
- package/dist/utils/command-helpers.d.ts.map +1 -0
- package/dist/utils/command-helpers.js +79 -0
- package/dist/utils/command-parser.d.ts +146 -0
- package/dist/utils/command-parser.d.ts.map +1 -0
- package/dist/utils/command-parser.js +179 -0
- package/dist/utils/command-suggestions.d.ts +35 -0
- package/dist/utils/command-suggestions.d.ts.map +1 -0
- package/dist/utils/command-suggestions.js +152 -0
- package/dist/utils/console.d.ts +44 -0
- package/dist/utils/console.d.ts.map +1 -0
- package/dist/utils/console.js +233 -0
- package/dist/utils/constants.d.ts +8 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +10 -0
- package/dist/utils/context-detector.d.ts +12 -0
- package/dist/utils/context-detector.d.ts.map +1 -0
- package/dist/utils/context-detector.js +155 -0
- package/dist/utils/enhanced-error-handler.d.ts +47 -0
- package/dist/utils/enhanced-error-handler.d.ts.map +1 -0
- package/dist/utils/enhanced-error-handler.js +221 -0
- package/dist/utils/error-handler.d.ts +3 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +55 -0
- package/dist/utils/errors.d.ts +44 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +76 -0
- package/dist/utils/interactive-builder.d.ts +22 -0
- package/dist/utils/interactive-builder.d.ts.map +1 -0
- package/dist/utils/interactive-builder.js +246 -0
- package/dist/utils/rich-progress.d.ts +59 -0
- package/dist/utils/rich-progress.d.ts.map +1 -0
- package/dist/utils/rich-progress.js +234 -0
- package/dist/utils/store.d.ts +11 -0
- package/dist/utils/store.d.ts.map +1 -0
- package/dist/utils/store.js +19 -0
- package/dist/utils/validation-error-formatter.d.ts +25 -0
- package/dist/utils/validation-error-formatter.d.ts.map +1 -0
- package/dist/utils/validation-error-formatter.js +258 -0
- package/dist/utils/validation-helpers.d.ts +60 -0
- package/dist/utils/validation-helpers.d.ts.map +1 -0
- package/dist/utils/validation-helpers.js +152 -0
- package/package.json +43 -11
- package/src/__tests__/helpers/cli-test-helper.ts +281 -0
- package/src/__tests__/mocks/index.ts +142 -0
- package/src/actions/component.actions.ts +334 -0
- package/src/actions/function.actions.ts +313 -0
- package/src/actions/project.actions.ts +126 -0
- package/src/actions/version.actions.ts +233 -0
- package/src/commands/__tests__/component-validation.test.ts +250 -0
- package/src/commands/__tests__/component.test.ts +321 -0
- package/src/commands/__tests__/function-validation.test.ts +220 -0
- package/src/commands/__tests__/function.test.ts +286 -0
- package/src/commands/__tests__/store-version-validation.test.ts +414 -0
- package/src/commands/__tests__/store-version.test.ts +405 -0
- package/src/commands/__tests__/version.test.ts +71 -0
- package/src/commands/component.ts +188 -0
- package/src/commands/docs.ts +11 -11
- package/src/commands/function.ts +252 -0
- package/src/commands/help.ts +8 -18
- package/src/commands/index.ts +14 -7
- package/src/commands/login.ts +19 -79
- package/src/commands/project.ts +107 -0
- package/src/commands/store-version.ts +242 -0
- package/src/commands/version.ts +45 -8
- package/src/commands/whoami.ts +8 -13
- package/src/index.ts +108 -34
- package/src/prompts/component.prompts.ts +94 -0
- package/src/prompts/function.prompts.ts +168 -0
- package/src/schemas/command.schema.ts +354 -0
- package/src/types/index.ts +183 -0
- package/src/utils/__tests__/command-parser.test.ts +159 -0
- package/src/utils/__tests__/command-suggestions.test.ts +185 -0
- package/src/utils/__tests__/console.test.ts +192 -0
- package/src/utils/__tests__/context-detector.test.ts +258 -0
- package/src/utils/__tests__/enhanced-error-handler.test.ts +137 -0
- package/src/utils/__tests__/error-handler.test.ts +107 -0
- package/src/utils/__tests__/rich-progress.test.ts +170 -0
- package/src/utils/__tests__/validation-error-formatter.test.ts +175 -0
- package/src/utils/__tests__/validation-helpers.test.ts +125 -0
- package/src/utils/auth.ts +0 -1
- package/src/utils/cli-progress-reporter.ts +84 -0
- package/src/utils/command-builder.ts +390 -0
- package/src/utils/command-helpers.ts +83 -0
- package/src/utils/command-parser.ts +250 -0
- package/src/utils/command-suggestions.ts +176 -0
- package/src/utils/console.ts +291 -0
- package/src/utils/context-detector.ts +177 -0
- package/src/utils/enhanced-error-handler.ts +264 -0
- package/src/utils/error-handler.ts +60 -0
- package/src/utils/errors.ts +125 -0
- package/src/utils/interactive-builder.ts +271 -0
- package/src/utils/rich-progress.ts +320 -0
- package/src/utils/validation-error-formatter.ts +337 -0
- package/src/utils/validation-helpers.ts +192 -0
- package/tsconfig.json +13 -7
- package/vitest.config.ts +28 -0
- package/vitest.setup.ts +29 -0
- package/src/commands/validate.ts +0 -62
- package/src/utils/core.ts +0 -105
- package/tsup.config.ts +0 -15
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ComponentSlot, type ComponentSlotType } from "@ollie-shop/core";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { validateComponentName } from "../utils/validation-helpers";
|
|
4
|
+
|
|
5
|
+
export interface ComponentCreationAnswers {
|
|
6
|
+
name: string;
|
|
7
|
+
slot: ComponentSlotType;
|
|
8
|
+
includeTests: boolean;
|
|
9
|
+
description?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ComponentDeploymentAnswers {
|
|
13
|
+
versionId: string;
|
|
14
|
+
confirm: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Generate component slot choices from core enum
|
|
18
|
+
const componentSlotChoices = ComponentSlot.options.map((slot) => ({
|
|
19
|
+
name: slot.charAt(0).toUpperCase() + slot.slice(1).replace(/-/g, " "),
|
|
20
|
+
value: slot,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
export async function promptComponentCreation(
|
|
24
|
+
name?: string,
|
|
25
|
+
slot?: string,
|
|
26
|
+
): Promise<ComponentCreationAnswers> {
|
|
27
|
+
const questions = [];
|
|
28
|
+
|
|
29
|
+
if (!name) {
|
|
30
|
+
questions.push({
|
|
31
|
+
type: "input",
|
|
32
|
+
name: "name",
|
|
33
|
+
message: "What's the name of your component?",
|
|
34
|
+
validate: (input: string) => {
|
|
35
|
+
return validateComponentName(input);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!slot) {
|
|
41
|
+
questions.push({
|
|
42
|
+
type: "list",
|
|
43
|
+
name: "slot",
|
|
44
|
+
message: "Which slot will this component occupy?",
|
|
45
|
+
choices: componentSlotChoices,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
questions.push(
|
|
50
|
+
{
|
|
51
|
+
type: "input",
|
|
52
|
+
name: "description",
|
|
53
|
+
message: "Enter a description (optional):",
|
|
54
|
+
default: "",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "confirm",
|
|
58
|
+
name: "includeTests",
|
|
59
|
+
message: "Include test files?",
|
|
60
|
+
default: true,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const answers = await inquirer.prompt(questions);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
name: name || answers.name,
|
|
68
|
+
slot: slot || answers.slot,
|
|
69
|
+
description: answers.description || undefined,
|
|
70
|
+
includeTests: answers.includeTests,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function promptComponentDeployment(): Promise<ComponentDeploymentAnswers> {
|
|
75
|
+
const answers = await inquirer.prompt([
|
|
76
|
+
{
|
|
77
|
+
type: "input",
|
|
78
|
+
name: "versionId",
|
|
79
|
+
message: "Enter the version ID to deploy to:",
|
|
80
|
+
validate: (input: string) => {
|
|
81
|
+
if (!input.trim()) return "Version ID is required";
|
|
82
|
+
return true;
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "confirm",
|
|
87
|
+
name: "confirm",
|
|
88
|
+
message: "Are you sure you want to deploy this component?",
|
|
89
|
+
default: false,
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
return answers;
|
|
94
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionInvocationType,
|
|
3
|
+
type FunctionInvocationTypeType,
|
|
4
|
+
OnErrorBehavior,
|
|
5
|
+
type OnErrorBehaviorType,
|
|
6
|
+
} from "@ollie-shop/core";
|
|
7
|
+
import inquirer from "inquirer";
|
|
8
|
+
import { validateFunctionName } from "../utils/validation-helpers";
|
|
9
|
+
|
|
10
|
+
export interface FunctionCreationAnswers {
|
|
11
|
+
name: string;
|
|
12
|
+
invocation: FunctionInvocationTypeType;
|
|
13
|
+
priority: number;
|
|
14
|
+
onError: OnErrorBehaviorType;
|
|
15
|
+
includeTests: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FunctionDeploymentAnswers {
|
|
20
|
+
versionId: string;
|
|
21
|
+
confirm: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FunctionTestAnswers {
|
|
25
|
+
pattern: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Generate function invocation choices from core enum
|
|
29
|
+
const invocationChoices = FunctionInvocationType.options.map((type) => ({
|
|
30
|
+
name:
|
|
31
|
+
type === "request"
|
|
32
|
+
? "Request (before forwarding to target)"
|
|
33
|
+
: "Response (after receiving from target)",
|
|
34
|
+
value: type,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
// Generate error behavior choices from core enum
|
|
38
|
+
const errorBehaviorChoices = OnErrorBehavior.options.map((behavior) => ({
|
|
39
|
+
name:
|
|
40
|
+
behavior === "throw"
|
|
41
|
+
? "Throw error and stop execution"
|
|
42
|
+
: "Skip and continue with next function",
|
|
43
|
+
value: behavior,
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
export async function promptFunctionCreation(
|
|
47
|
+
name?: string,
|
|
48
|
+
invocation?: string,
|
|
49
|
+
priority?: number,
|
|
50
|
+
onError?: string,
|
|
51
|
+
): Promise<FunctionCreationAnswers> {
|
|
52
|
+
const questions = [];
|
|
53
|
+
|
|
54
|
+
if (!name) {
|
|
55
|
+
questions.push({
|
|
56
|
+
type: "input",
|
|
57
|
+
name: "name",
|
|
58
|
+
message: "What's the name of your function?",
|
|
59
|
+
validate: (input: string) => {
|
|
60
|
+
return validateFunctionName(input);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!invocation) {
|
|
66
|
+
questions.push({
|
|
67
|
+
type: "list",
|
|
68
|
+
name: "invocation",
|
|
69
|
+
message: "When should this function execute?",
|
|
70
|
+
choices: invocationChoices,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (priority === undefined) {
|
|
75
|
+
questions.push({
|
|
76
|
+
type: "number",
|
|
77
|
+
name: "priority",
|
|
78
|
+
message: "Priority (0-100, higher = executes first):",
|
|
79
|
+
default: 0,
|
|
80
|
+
validate: (input: number) => {
|
|
81
|
+
if (input < 0 || input > 100)
|
|
82
|
+
return "Priority must be between 0 and 100";
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!onError) {
|
|
89
|
+
questions.push({
|
|
90
|
+
type: "list",
|
|
91
|
+
name: "onError",
|
|
92
|
+
message: "What should happen if this function fails?",
|
|
93
|
+
choices: errorBehaviorChoices,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
questions.push(
|
|
98
|
+
{
|
|
99
|
+
type: "input",
|
|
100
|
+
name: "description",
|
|
101
|
+
message: "Enter a description (optional):",
|
|
102
|
+
default: "",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: "confirm",
|
|
106
|
+
name: "includeTests",
|
|
107
|
+
message: "Include test files?",
|
|
108
|
+
default: true,
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const answers = await inquirer.prompt(questions);
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
name: name || answers.name,
|
|
116
|
+
invocation: invocation || answers.invocation,
|
|
117
|
+
priority: priority ?? answers.priority,
|
|
118
|
+
onError: onError || answers.onError,
|
|
119
|
+
description: answers.description || undefined,
|
|
120
|
+
includeTests: answers.includeTests,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function promptFunctionDeployment(): Promise<FunctionDeploymentAnswers> {
|
|
125
|
+
const answers = await inquirer.prompt([
|
|
126
|
+
{
|
|
127
|
+
type: "input",
|
|
128
|
+
name: "versionId",
|
|
129
|
+
message: "Enter the version ID to deploy to:",
|
|
130
|
+
validate: (input: string) => {
|
|
131
|
+
if (!input.trim()) return "Version ID is required";
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "confirm",
|
|
137
|
+
name: "confirm",
|
|
138
|
+
message: "Are you sure you want to deploy this function?",
|
|
139
|
+
default: false,
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
return answers;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function promptFunctionTest(): Promise<FunctionTestAnswers> {
|
|
147
|
+
const answers = await inquirer.prompt([
|
|
148
|
+
{
|
|
149
|
+
type: "input",
|
|
150
|
+
name: "pattern",
|
|
151
|
+
message: "Enter test file pattern:",
|
|
152
|
+
default: "**/*.test.{js,ts}",
|
|
153
|
+
},
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
return answers;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function getInvocationDescription(
|
|
160
|
+
invocation: FunctionInvocationTypeType,
|
|
161
|
+
): string {
|
|
162
|
+
const descriptions: Record<FunctionInvocationTypeType, string> = {
|
|
163
|
+
request: "Executes before forwarding request to target URL",
|
|
164
|
+
response: "Executes after receiving response from target URL",
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return descriptions[invocation] || "Custom invocation handler";
|
|
168
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// Following TypeScript Discipline: Import schemas from core instead of duplicating
|
|
2
|
+
import {
|
|
3
|
+
BuildStatus,
|
|
4
|
+
ComponentNameSchema,
|
|
5
|
+
ComponentSlot,
|
|
6
|
+
FunctionInvocationType,
|
|
7
|
+
FunctionNameSchema,
|
|
8
|
+
OnErrorBehavior,
|
|
9
|
+
Template,
|
|
10
|
+
} from "@ollie-shop/core";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
// Re-export schemas from core for CLI use
|
|
14
|
+
export { ComponentNameSchema, FunctionNameSchema };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CLI-specific schemas (only for CLI-specific concerns)
|
|
18
|
+
*/
|
|
19
|
+
export const PathSchema = z.string().min(1, "Path cannot be empty");
|
|
20
|
+
|
|
21
|
+
export const StoreIdSchema = z.string().uuid("Invalid store ID format");
|
|
22
|
+
|
|
23
|
+
export const VersionNameSchema = z
|
|
24
|
+
.string()
|
|
25
|
+
.min(1, "Version name is required")
|
|
26
|
+
.max(100, "Version name is too long (max 100 characters)");
|
|
27
|
+
|
|
28
|
+
export const PrioritySchema = z
|
|
29
|
+
.number()
|
|
30
|
+
.int("Priority must be a whole number")
|
|
31
|
+
.min(0, "Priority must be between 0 and 100")
|
|
32
|
+
.max(100, "Priority must be between 0 and 100");
|
|
33
|
+
|
|
34
|
+
export const UrlSchema = z
|
|
35
|
+
.string()
|
|
36
|
+
.min(1, "URL is required")
|
|
37
|
+
.refine((url) => {
|
|
38
|
+
// Allow URL patterns like /api/* or /*
|
|
39
|
+
if (url.startsWith("/")) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
// Validate full URLs
|
|
43
|
+
try {
|
|
44
|
+
const parsed = new URL(url);
|
|
45
|
+
return ["http:", "https:"].includes(parsed.protocol);
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}, "URL must be a valid URL or path pattern");
|
|
50
|
+
|
|
51
|
+
export const SemverSchema = z
|
|
52
|
+
.string()
|
|
53
|
+
.regex(
|
|
54
|
+
/^\d+\.\d+\.\d+$/,
|
|
55
|
+
"Version must follow semantic versioning format (e.g., 1.0.0)",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Component command schemas
|
|
60
|
+
*/
|
|
61
|
+
export const ComponentCreateOptionsSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
name: ComponentNameSchema.optional(), // Optional for interactive mode
|
|
64
|
+
slot: ComponentSlot.optional().default("main"),
|
|
65
|
+
tests: z.boolean().optional().default(true),
|
|
66
|
+
template: z.string().optional(),
|
|
67
|
+
interactive: z.boolean().optional(),
|
|
68
|
+
})
|
|
69
|
+
.refine((data) => data.interactive || data.name, {
|
|
70
|
+
message: "Component name is required when not in interactive mode",
|
|
71
|
+
path: ["name"],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const ComponentBuildOptionsSchema = z.object({
|
|
75
|
+
path: PathSchema.optional(),
|
|
76
|
+
watch: z.boolean().optional(),
|
|
77
|
+
minify: z.boolean().optional(),
|
|
78
|
+
sourcemap: z.boolean().optional(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export const ComponentValidateOptionsSchema = z.object({
|
|
82
|
+
path: PathSchema.optional(),
|
|
83
|
+
strict: z.boolean().optional(),
|
|
84
|
+
fix: z.boolean().optional(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export const ComponentDeployOptionsSchema = z.object({
|
|
88
|
+
path: PathSchema.optional(),
|
|
89
|
+
componentId: z.string().optional(),
|
|
90
|
+
id: z.string().optional(), // CLI uses --id flag
|
|
91
|
+
wait: z.boolean().optional(),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Function command schemas
|
|
96
|
+
*/
|
|
97
|
+
export const FunctionCreateOptionsSchema = z.object({
|
|
98
|
+
name: FunctionNameSchema,
|
|
99
|
+
invocation: FunctionInvocationType.optional().default("request"),
|
|
100
|
+
priority: PrioritySchema.optional().default(0),
|
|
101
|
+
onError: OnErrorBehavior.optional().default("throw"),
|
|
102
|
+
tests: z.boolean().optional().default(true),
|
|
103
|
+
template: z.string().optional(),
|
|
104
|
+
description: z.string().optional(),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const FunctionBuildOptionsSchema = z.object({
|
|
108
|
+
path: PathSchema.optional(),
|
|
109
|
+
watch: z.boolean().optional(),
|
|
110
|
+
minify: z.boolean().optional(),
|
|
111
|
+
target: z.enum(["node16", "node18", "node20"]).optional(),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export const FunctionValidateOptionsSchema = z.object({
|
|
115
|
+
path: PathSchema.optional(),
|
|
116
|
+
strict: z.boolean().optional(),
|
|
117
|
+
fix: z.boolean().optional(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const FunctionTestOptionsSchema = z.object({
|
|
121
|
+
path: PathSchema.optional(),
|
|
122
|
+
payload: z.string().optional(),
|
|
123
|
+
timeout: z.number().optional(),
|
|
124
|
+
coverage: z.boolean().optional(),
|
|
125
|
+
watch: z.boolean().optional(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const FunctionDeployOptionsSchema = z.object({
|
|
129
|
+
path: PathSchema.optional(),
|
|
130
|
+
functionId: z.string().optional(),
|
|
131
|
+
id: z.string().optional(), // CLI uses --id flag
|
|
132
|
+
wait: z.boolean().optional(),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Development server schemas
|
|
137
|
+
*/
|
|
138
|
+
export const DevServerOptionsSchema = z.object({
|
|
139
|
+
port: z.number().min(1000).max(65535).default(3000),
|
|
140
|
+
host: z.string().default("localhost"),
|
|
141
|
+
open: z.boolean().default(true),
|
|
142
|
+
component: PathSchema.optional(),
|
|
143
|
+
function: PathSchema.optional(),
|
|
144
|
+
mockData: PathSchema.optional(),
|
|
145
|
+
hot: z.boolean().default(true),
|
|
146
|
+
https: z.boolean().default(false),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Global CLI options schemas
|
|
151
|
+
*/
|
|
152
|
+
export const GlobalOptionsSchema = z.object({
|
|
153
|
+
verbose: z.boolean().default(false),
|
|
154
|
+
quiet: z.boolean().default(false),
|
|
155
|
+
color: z.boolean().default(true), // --no-color sets this to false
|
|
156
|
+
config: PathSchema.optional(),
|
|
157
|
+
logLevel: z.enum(["error", "warn", "info", "debug"]).default("info"),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Build command schemas
|
|
162
|
+
*/
|
|
163
|
+
export const BuildOptionsSchema = z.object({
|
|
164
|
+
path: PathSchema.optional(),
|
|
165
|
+
output: PathSchema.optional(),
|
|
166
|
+
minify: z.boolean().default(true),
|
|
167
|
+
sourcemap: z.boolean().default(true),
|
|
168
|
+
watch: z.boolean().default(false),
|
|
169
|
+
clean: z.boolean().default(true),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Login/Auth schemas
|
|
174
|
+
*/
|
|
175
|
+
export const LoginOptionsSchema = z.object({
|
|
176
|
+
token: z.string().optional(),
|
|
177
|
+
interactive: z.boolean().default(true),
|
|
178
|
+
save: z.boolean().default(true),
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Init project schemas
|
|
183
|
+
*/
|
|
184
|
+
export const InitOptionsSchema = z.object({
|
|
185
|
+
name: z.string().optional(),
|
|
186
|
+
template: Template.optional().default("default"),
|
|
187
|
+
git: z.boolean().default(true),
|
|
188
|
+
install: z.boolean().default(true),
|
|
189
|
+
path: PathSchema.optional(),
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Store version command schemas
|
|
194
|
+
*/
|
|
195
|
+
export const StoreVersionCreateOptionsSchema = z.object({
|
|
196
|
+
store: StoreIdSchema,
|
|
197
|
+
name: VersionNameSchema,
|
|
198
|
+
template: Template.optional(),
|
|
199
|
+
active: z.boolean().optional(),
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
export const StoreVersionListOptionsSchema = z.object({
|
|
203
|
+
store: StoreIdSchema,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
export const StoreVersionCloneOptionsSchema = z.object({
|
|
207
|
+
store: StoreIdSchema,
|
|
208
|
+
sourceId: z.string().uuid("Invalid source version ID"),
|
|
209
|
+
name: VersionNameSchema,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
export const StoreVersionActivateOptionsSchema = z.object({
|
|
213
|
+
store: StoreIdSchema,
|
|
214
|
+
versionId: z.string().uuid("Invalid version ID"),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
export const StoreVersionSetDefaultOptionsSchema = z.object({
|
|
218
|
+
store: StoreIdSchema,
|
|
219
|
+
versionId: z.string().uuid("Invalid version ID"),
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Type exports
|
|
223
|
+
export type ComponentCreateOptions = z.infer<
|
|
224
|
+
typeof ComponentCreateOptionsSchema
|
|
225
|
+
>;
|
|
226
|
+
export type ComponentBuildOptions = z.infer<typeof ComponentBuildOptionsSchema>;
|
|
227
|
+
export type ComponentValidateOptions = z.infer<
|
|
228
|
+
typeof ComponentValidateOptionsSchema
|
|
229
|
+
>;
|
|
230
|
+
export type ComponentDeployOptions = z.infer<
|
|
231
|
+
typeof ComponentDeployOptionsSchema
|
|
232
|
+
>;
|
|
233
|
+
|
|
234
|
+
export type FunctionCreateOptions = z.infer<typeof FunctionCreateOptionsSchema>;
|
|
235
|
+
export type FunctionBuildOptions = z.infer<typeof FunctionBuildOptionsSchema>;
|
|
236
|
+
export type FunctionValidateOptions = z.infer<
|
|
237
|
+
typeof FunctionValidateOptionsSchema
|
|
238
|
+
>;
|
|
239
|
+
export type FunctionTestOptions = z.infer<typeof FunctionTestOptionsSchema>;
|
|
240
|
+
export type FunctionDeployOptions = z.infer<typeof FunctionDeployOptionsSchema>;
|
|
241
|
+
|
|
242
|
+
export type DevServerOptions = z.infer<typeof DevServerOptionsSchema>;
|
|
243
|
+
export type GlobalOptions = z.infer<typeof GlobalOptionsSchema>;
|
|
244
|
+
export type BuildOptions = z.infer<typeof BuildOptionsSchema>;
|
|
245
|
+
export type LoginOptions = z.infer<typeof LoginOptionsSchema>;
|
|
246
|
+
export type InitOptions = z.infer<typeof InitOptionsSchema>;
|
|
247
|
+
|
|
248
|
+
export type StoreVersionCreateOptions = z.infer<
|
|
249
|
+
typeof StoreVersionCreateOptionsSchema
|
|
250
|
+
>;
|
|
251
|
+
export type StoreVersionListOptions = z.infer<
|
|
252
|
+
typeof StoreVersionListOptionsSchema
|
|
253
|
+
>;
|
|
254
|
+
export type StoreVersionCloneOptions = z.infer<
|
|
255
|
+
typeof StoreVersionCloneOptionsSchema
|
|
256
|
+
>;
|
|
257
|
+
export type StoreVersionActivateOptions = z.infer<
|
|
258
|
+
typeof StoreVersionActivateOptionsSchema
|
|
259
|
+
>;
|
|
260
|
+
export type StoreVersionSetDefaultOptions = z.infer<
|
|
261
|
+
typeof StoreVersionSetDefaultOptionsSchema
|
|
262
|
+
>;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Validation helper functions
|
|
266
|
+
*/
|
|
267
|
+
// NOTE: For component and function name validation, use validation functions from core:
|
|
268
|
+
// import { validateComponentName, validateFunctionName } from "@ollie-shop/core/schemas"
|
|
269
|
+
|
|
270
|
+
export function validatePath(path: string): boolean {
|
|
271
|
+
return PathSchema.safeParse(path).success;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function validateStoreId(storeId: string): boolean {
|
|
275
|
+
return StoreIdSchema.safeParse(storeId).success;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function validateVersionName(name: string): boolean {
|
|
279
|
+
return VersionNameSchema.safeParse(name).success;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function validatePriority(priority: number): boolean {
|
|
283
|
+
return PrioritySchema.safeParse(priority).success;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function validateUrl(url: string): boolean {
|
|
287
|
+
return UrlSchema.safeParse(url).success;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function validateSemver(version: string): boolean {
|
|
291
|
+
return SemverSchema.safeParse(version).success;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* CLI Data Display Schemas
|
|
296
|
+
* These schemas define the structure for data displayed in CLI commands
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
// Function list item schema for CLI display
|
|
300
|
+
export const FunctionListItemSchema = z.object({
|
|
301
|
+
id: z.string(),
|
|
302
|
+
name: z.string(),
|
|
303
|
+
runtime: z.string().optional(),
|
|
304
|
+
version: z.string().optional(),
|
|
305
|
+
enabled: z.boolean(),
|
|
306
|
+
createdAt: z.union([z.string(), z.date()]),
|
|
307
|
+
invocation: FunctionInvocationType.optional(),
|
|
308
|
+
priority: z.number().optional(),
|
|
309
|
+
onError: OnErrorBehavior.optional(),
|
|
310
|
+
description: z.string().optional(),
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Component list item schema for CLI display
|
|
314
|
+
export const ComponentListItemSchema = z.object({
|
|
315
|
+
id: z.string(),
|
|
316
|
+
name: z.string(),
|
|
317
|
+
slot: ComponentSlot,
|
|
318
|
+
version: z.string().optional(),
|
|
319
|
+
enabled: z.boolean(),
|
|
320
|
+
createdAt: z.union([z.string(), z.date()]),
|
|
321
|
+
description: z.string().optional(),
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Build status schema
|
|
325
|
+
export const BuildStatusSchema = z.object({
|
|
326
|
+
id: z.string(),
|
|
327
|
+
status: BuildStatus,
|
|
328
|
+
startTime: z.union([z.string(), z.date()]),
|
|
329
|
+
endTime: z.union([z.string(), z.date()]).optional(),
|
|
330
|
+
deploymentUrl: z.string().optional(),
|
|
331
|
+
artifactLocation: z.string().optional(),
|
|
332
|
+
logs: z.string().optional(),
|
|
333
|
+
error: z.string().optional(),
|
|
334
|
+
resourceId: z.string(),
|
|
335
|
+
resourceType: z.enum(["component", "function"]),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// Version list item schema for CLI display
|
|
339
|
+
export const VersionListItemSchema = z.object({
|
|
340
|
+
id: z.string(),
|
|
341
|
+
name: z.string(),
|
|
342
|
+
template: z.string().nullable().optional(),
|
|
343
|
+
active: z.boolean(),
|
|
344
|
+
default: z.boolean(),
|
|
345
|
+
createdAt: z.union([z.string(), z.date()]),
|
|
346
|
+
updatedAt: z.union([z.string(), z.date()]),
|
|
347
|
+
storeId: z.string(),
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Type exports derived from schemas
|
|
351
|
+
export type FunctionListItem = z.infer<typeof FunctionListItemSchema>;
|
|
352
|
+
export type ComponentListItem = z.infer<typeof ComponentListItemSchema>;
|
|
353
|
+
export type BuildStatusItem = z.infer<typeof BuildStatusSchema>;
|
|
354
|
+
export type VersionListItem = z.infer<typeof VersionListItemSchema>;
|