@ollie-shop/cli 0.1.3 → 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.
Files changed (181) hide show
  1. package/.turbo/turbo-build.log +2 -11
  2. package/CHANGELOG.md +17 -5
  3. package/CLAUDE_CLI.md +265 -0
  4. package/README.md +704 -8
  5. package/__tests__/mocks/console.ts +22 -0
  6. package/__tests__/mocks/core.ts +137 -0
  7. package/__tests__/mocks/index.ts +4 -0
  8. package/__tests__/mocks/inquirer.ts +16 -0
  9. package/__tests__/mocks/progress.ts +19 -0
  10. package/dist/__tests__/helpers/cli-test-helper.d.ts +89 -0
  11. package/dist/__tests__/helpers/cli-test-helper.d.ts.map +1 -0
  12. package/dist/__tests__/helpers/cli-test-helper.js +220 -0
  13. package/dist/__tests__/mocks/index.d.ts +69 -0
  14. package/dist/__tests__/mocks/index.d.ts.map +1 -0
  15. package/dist/__tests__/mocks/index.js +77 -0
  16. package/dist/actions/component.actions.d.ts +14 -0
  17. package/dist/actions/component.actions.d.ts.map +1 -0
  18. package/dist/actions/component.actions.js +273 -0
  19. package/dist/actions/function.actions.d.ts +15 -0
  20. package/dist/actions/function.actions.d.ts.map +1 -0
  21. package/dist/actions/function.actions.js +254 -0
  22. package/dist/actions/project.actions.d.ts +17 -0
  23. package/dist/actions/project.actions.d.ts.map +1 -0
  24. package/dist/actions/project.actions.js +97 -0
  25. package/dist/actions/version.actions.d.ts +19 -0
  26. package/dist/actions/version.actions.d.ts.map +1 -0
  27. package/dist/actions/version.actions.js +216 -0
  28. package/dist/commands/component.d.ts +3 -0
  29. package/dist/commands/component.d.ts.map +1 -0
  30. package/dist/commands/component.js +192 -0
  31. package/dist/commands/docs.d.ts +3 -0
  32. package/dist/commands/docs.d.ts.map +1 -0
  33. package/dist/commands/docs.js +16 -0
  34. package/dist/commands/function.d.ts +3 -0
  35. package/dist/commands/function.d.ts.map +1 -0
  36. package/dist/commands/function.js +243 -0
  37. package/dist/commands/help.d.ts +3 -0
  38. package/dist/commands/help.d.ts.map +1 -0
  39. package/dist/commands/help.js +20 -0
  40. package/dist/commands/index.d.ts +3 -0
  41. package/dist/commands/index.d.ts.map +1 -0
  42. package/dist/commands/index.js +26 -0
  43. package/dist/commands/login.d.ts +3 -0
  44. package/dist/commands/login.d.ts.map +1 -0
  45. package/dist/commands/login.js +175 -0
  46. package/dist/commands/project.d.ts +3 -0
  47. package/dist/commands/project.d.ts.map +1 -0
  48. package/dist/commands/project.js +78 -0
  49. package/dist/commands/store-version.d.ts +3 -0
  50. package/dist/commands/store-version.d.ts.map +1 -0
  51. package/dist/commands/store-version.js +241 -0
  52. package/dist/commands/version.d.ts +3 -0
  53. package/dist/commands/version.d.ts.map +1 -0
  54. package/dist/commands/version.js +46 -0
  55. package/dist/commands/whoami.d.ts +3 -0
  56. package/dist/commands/whoami.d.ts.map +1 -0
  57. package/dist/commands/whoami.js +41 -0
  58. package/dist/index.d.ts +3 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +93 -226
  61. package/dist/prompts/component.prompts.d.ts +14 -0
  62. package/dist/prompts/component.prompts.d.ts.map +1 -0
  63. package/dist/prompts/component.prompts.js +75 -0
  64. package/dist/prompts/function.prompts.d.ts +21 -0
  65. package/dist/prompts/function.prompts.d.ts.map +1 -0
  66. package/dist/prompts/function.prompts.js +127 -0
  67. package/dist/schemas/command.schema.d.ts +516 -0
  68. package/dist/schemas/command.schema.d.ts.map +1 -0
  69. package/dist/schemas/command.schema.js +267 -0
  70. package/dist/types/index.d.ts +147 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +18 -0
  73. package/dist/utils/auth.d.ts +4 -0
  74. package/dist/utils/auth.d.ts.map +1 -0
  75. package/dist/utils/auth.js +26 -0
  76. package/dist/utils/cli-progress-reporter.d.ts +12 -0
  77. package/dist/utils/cli-progress-reporter.d.ts.map +1 -0
  78. package/dist/utils/cli-progress-reporter.js +77 -0
  79. package/dist/utils/command-builder.d.ts +22 -0
  80. package/dist/utils/command-builder.d.ts.map +1 -0
  81. package/dist/utils/command-builder.js +268 -0
  82. package/dist/utils/command-helpers.d.ts +19 -0
  83. package/dist/utils/command-helpers.d.ts.map +1 -0
  84. package/dist/utils/command-helpers.js +79 -0
  85. package/dist/utils/command-parser.d.ts +146 -0
  86. package/dist/utils/command-parser.d.ts.map +1 -0
  87. package/dist/utils/command-parser.js +179 -0
  88. package/dist/utils/command-suggestions.d.ts +35 -0
  89. package/dist/utils/command-suggestions.d.ts.map +1 -0
  90. package/dist/utils/command-suggestions.js +152 -0
  91. package/dist/utils/console.d.ts +44 -0
  92. package/dist/utils/console.d.ts.map +1 -0
  93. package/dist/utils/console.js +233 -0
  94. package/dist/utils/constants.d.ts +8 -0
  95. package/dist/utils/constants.d.ts.map +1 -0
  96. package/dist/utils/constants.js +10 -0
  97. package/dist/utils/context-detector.d.ts +12 -0
  98. package/dist/utils/context-detector.d.ts.map +1 -0
  99. package/dist/utils/context-detector.js +155 -0
  100. package/dist/utils/enhanced-error-handler.d.ts +47 -0
  101. package/dist/utils/enhanced-error-handler.d.ts.map +1 -0
  102. package/dist/utils/enhanced-error-handler.js +221 -0
  103. package/dist/utils/error-handler.d.ts +3 -0
  104. package/dist/utils/error-handler.d.ts.map +1 -0
  105. package/dist/utils/error-handler.js +55 -0
  106. package/dist/utils/errors.d.ts +44 -0
  107. package/dist/utils/errors.d.ts.map +1 -0
  108. package/dist/utils/errors.js +76 -0
  109. package/dist/utils/interactive-builder.d.ts +22 -0
  110. package/dist/utils/interactive-builder.d.ts.map +1 -0
  111. package/dist/utils/interactive-builder.js +246 -0
  112. package/dist/utils/rich-progress.d.ts +59 -0
  113. package/dist/utils/rich-progress.d.ts.map +1 -0
  114. package/dist/utils/rich-progress.js +234 -0
  115. package/dist/utils/store.d.ts +11 -0
  116. package/dist/utils/store.d.ts.map +1 -0
  117. package/dist/utils/store.js +19 -0
  118. package/dist/utils/validation-error-formatter.d.ts +25 -0
  119. package/dist/utils/validation-error-formatter.d.ts.map +1 -0
  120. package/dist/utils/validation-error-formatter.js +258 -0
  121. package/dist/utils/validation-helpers.d.ts +60 -0
  122. package/dist/utils/validation-helpers.d.ts.map +1 -0
  123. package/dist/utils/validation-helpers.js +152 -0
  124. package/package.json +44 -9
  125. package/src/__tests__/helpers/cli-test-helper.ts +281 -0
  126. package/src/__tests__/mocks/index.ts +142 -0
  127. package/src/actions/component.actions.ts +334 -0
  128. package/src/actions/function.actions.ts +313 -0
  129. package/src/actions/project.actions.ts +126 -0
  130. package/src/actions/version.actions.ts +233 -0
  131. package/src/commands/__tests__/component-validation.test.ts +250 -0
  132. package/src/commands/__tests__/component.test.ts +321 -0
  133. package/src/commands/__tests__/function-validation.test.ts +220 -0
  134. package/src/commands/__tests__/function.test.ts +286 -0
  135. package/src/commands/__tests__/store-version-validation.test.ts +414 -0
  136. package/src/commands/__tests__/store-version.test.ts +405 -0
  137. package/src/commands/__tests__/version.test.ts +71 -0
  138. package/src/commands/component.ts +188 -0
  139. package/src/commands/docs.ts +24 -0
  140. package/src/commands/function.ts +252 -0
  141. package/src/commands/help.ts +18 -0
  142. package/src/commands/index.ts +21 -7
  143. package/src/commands/login.ts +19 -79
  144. package/src/commands/project.ts +107 -0
  145. package/src/commands/store-version.ts +242 -0
  146. package/src/commands/version.ts +51 -0
  147. package/src/commands/whoami.ts +46 -0
  148. package/src/index.ts +110 -15
  149. package/src/prompts/component.prompts.ts +94 -0
  150. package/src/prompts/function.prompts.ts +168 -0
  151. package/src/schemas/command.schema.ts +354 -0
  152. package/src/types/index.ts +183 -0
  153. package/src/utils/__tests__/command-parser.test.ts +159 -0
  154. package/src/utils/__tests__/command-suggestions.test.ts +185 -0
  155. package/src/utils/__tests__/console.test.ts +192 -0
  156. package/src/utils/__tests__/context-detector.test.ts +258 -0
  157. package/src/utils/__tests__/enhanced-error-handler.test.ts +137 -0
  158. package/src/utils/__tests__/error-handler.test.ts +107 -0
  159. package/src/utils/__tests__/rich-progress.test.ts +170 -0
  160. package/src/utils/__tests__/validation-error-formatter.test.ts +175 -0
  161. package/src/utils/__tests__/validation-helpers.test.ts +125 -0
  162. package/src/utils/auth.ts +41 -0
  163. package/src/utils/cli-progress-reporter.ts +84 -0
  164. package/src/utils/command-builder.ts +390 -0
  165. package/src/utils/command-helpers.ts +83 -0
  166. package/src/utils/command-parser.ts +250 -0
  167. package/src/utils/command-suggestions.ts +176 -0
  168. package/src/utils/console.ts +291 -0
  169. package/src/utils/context-detector.ts +177 -0
  170. package/src/utils/enhanced-error-handler.ts +264 -0
  171. package/src/utils/error-handler.ts +60 -0
  172. package/src/utils/errors.ts +125 -0
  173. package/src/utils/interactive-builder.ts +271 -0
  174. package/src/utils/rich-progress.ts +320 -0
  175. package/src/utils/store.ts +23 -0
  176. package/src/utils/validation-error-formatter.ts +337 -0
  177. package/src/utils/validation-helpers.ts +192 -0
  178. package/tsconfig.json +13 -7
  179. package/vitest.config.ts +28 -0
  180. package/vitest.setup.ts +29 -0
  181. package/tsup.config.ts +0 -15
package/dist/index.js CHANGED
@@ -1,232 +1,99 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var commander = require('commander');
5
- var crypto = require('crypto');
6
- var fs = require('fs/promises');
7
- var http = require('http');
8
- var os = require('os');
9
- var path = require('path');
10
-
11
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
-
13
- var fs__default = /*#__PURE__*/_interopDefault(fs);
14
- var path__default = /*#__PURE__*/_interopDefault(path);
15
-
16
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
17
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
18
- }) : x)(function(x) {
19
- if (typeof require !== "undefined") return require.apply(this, arguments);
20
- throw Error('Dynamic require of "' + x + '" is not supported');
21
- });
22
- var DEFAULT_CALLBACK_PORT = 7777;
23
- var AUTH_ENDPOINT = "https://admin.ollie.shop/auth/login";
24
- function configureLoginCommand(program) {
25
- return program.command("login").description("Log in to your Ollie Shop account").option(
26
- "-p, --port <port>",
27
- "Port to use for the local callback server",
28
- DEFAULT_CALLBACK_PORT.toString()
29
- ).option("--auth-url <url>", "Custom authorization URL", AUTH_ENDPOINT).action(async (options) => {
30
- console.log("\u{1F510} Initiating Ollie Shop login flow...");
31
- try {
32
- const token = await startWebAuthFlow(options);
33
- if (token) {
34
- await saveCredentials(token);
35
- console.log("\u2705 Successfully logged in!");
36
- return;
37
- }
38
- console.error("\u274C Authentication failed. Please try again.");
39
- process.exit(1);
40
- } catch (error) {
41
- console.error(
42
- `\u274C Login failed: ${error instanceof Error ? error.message : "Unknown error"}`
43
- );
44
- process.exit(1);
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const extra_typings_1 = require("@commander-js/extra-typings");
8
+ const package_json_1 = __importDefault(require("../package.json"));
9
+ const commands_1 = require("./commands");
10
+ const command_schema_1 = require("./schemas/command.schema");
11
+ const console_1 = require("./utils/console");
12
+ class OllieShopCLI {
13
+ constructor() {
14
+ this.program = new extra_typings_1.Command();
15
+ this.setupProgram();
16
+ this.registerCommands();
45
17
  }
46
- });
47
- }
48
- async function handleAuthCallback(req, res, state, resolve, reject) {
49
- const socket = req.socket;
50
- const url = new URL(
51
- req.url || "/",
52
- `http://localhost:${socket.localPort || 3e3}`
53
- );
54
- const params = url.searchParams;
55
- const returnedState = params.get("state");
56
- if (returnedState !== state) {
57
- sendErrorResponse(
58
- res,
59
- 400,
60
- "Invalid state parameter",
61
- "Authentication failed. Please try again."
62
- );
63
- reject(new Error("Invalid state parameter"));
64
- return;
65
- }
66
- let formData = "";
67
- req.on("data", (chunk) => {
68
- formData += chunk.toString();
69
- });
70
- await new Promise((formResolve) => {
71
- req.on("end", () => {
72
- formResolve();
73
- });
74
- });
75
- const formParams = new URLSearchParams(formData);
76
- const accessToken = formParams.get("access_token");
77
- const refreshToken = formParams.get("refresh_token") || "";
78
- const expiresAt = formParams.get("expires_at") || new Date(Date.now() + 36e5).toISOString();
79
- if (!accessToken) {
80
- sendErrorResponse(
81
- res,
82
- 400,
83
- "Missing authentication token",
84
- "Authentication failed. Please try again."
85
- );
86
- reject(new Error("Missing authentication token"));
87
- return;
88
- }
89
- try {
90
- const token = {
91
- accessToken,
92
- refreshToken,
93
- expiresAt
94
- };
95
- sendSuccessResponse(res);
96
- resolve(token);
97
- } catch (error) {
98
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
99
- sendErrorResponse(
100
- res,
101
- 500,
102
- "Authentication failed",
103
- `Error: ${errorMessage}`
104
- );
105
- reject(new Error(errorMessage));
106
- }
107
- }
108
- function sendErrorResponse(res, statusCode, title, message) {
109
- res.writeHead(statusCode, { "Content-Type": "text/html" });
110
- res.end(`<h1>${title}</h1><p>${message}</p>`);
111
- }
112
- function sendSuccessResponse(res) {
113
- res.writeHead(200, { "Content-Type": "text/html" });
114
- res.end(
115
- "<h1>Authentication successful!</h1><p>You can now close this window and return to the CLI.</p>"
116
- );
117
- }
118
- function sendWaitingResponse(res) {
119
- res.writeHead(200, { "Content-Type": "text/html" });
120
- res.end(
121
- "<h1>Ollie Shop CLI Authentication</h1><p>Waiting for authentication response...</p>"
122
- );
123
- }
124
- async function startWebAuthFlow(options) {
125
- const state = crypto.randomBytes(16).toString("hex");
126
- const port = Number.parseInt(options.port, 10);
127
- const baseUrl = options.authUrl;
128
- return new Promise((resolve, reject) => {
129
- const server = http.createServer(async (req, res) => {
130
- try {
131
- const url = new URL(req.url || "/", `http://localhost:${port}`);
132
- if (url.pathname === "/callback") {
133
- await handleAuthCallback(
134
- req,
135
- res,
136
- state,
137
- (token) => {
138
- server.close(() => {
139
- console.log("\u{1F510} Local authentication server closed");
140
- resolve(token);
141
- });
142
- },
143
- (error) => {
144
- server.close(() => {
145
- console.log("\u{1F510} Local authentication server closed");
146
- reject(error);
147
- });
18
+ setupProgram() {
19
+ this.program
20
+ .name("ollieshop")
21
+ .description("Ollie Shop CLI - Build and manage your e-commerce components and functions")
22
+ .version(package_json_1.default.version)
23
+ .option("-v, --verbose", "Enable verbose logging", false)
24
+ .option("-q, --quiet", "Suppress non-essential output", false)
25
+ .option("--no-color", "Disable colored output", false)
26
+ .option("-c, --config <path>", "Path to configuration file")
27
+ .option("--log-level <level>", "Set log level (error|warn|info|debug)", "info")
28
+ .hook("preAction", (thisCommand) => {
29
+ this.setupGlobalOptions(thisCommand);
30
+ });
31
+ }
32
+ setupGlobalOptions(thisCommand) {
33
+ try {
34
+ const options = thisCommand.opts();
35
+ const parsedOptions = this.validateGlobalOptions(options);
36
+ console_1.console.setOptions({
37
+ quiet: parsedOptions.quiet,
38
+ verbose: parsedOptions.verbose,
39
+ noColor: !parsedOptions.color, // --no-color sets color to false
40
+ });
41
+ if (parsedOptions.verbose) {
42
+ process.env.DEBUG = "ollieshop:*";
148
43
  }
149
- );
150
- } else {
151
- sendWaitingResponse(res);
152
44
  }
153
- } catch (error) {
154
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
155
- sendErrorResponse(res, 500, "Server Error", errorMessage);
156
- server.close(() => {
157
- console.log("\u{1F510} Local authentication server closed");
158
- reject(new Error(errorMessage));
159
- });
160
- }
161
- });
162
- server.listen(port, async () => {
163
- const redirectUrl = `http://localhost:${port}/callback`;
164
- const authUrl = new URL(baseUrl);
165
- authUrl.searchParams.set("flow", "cli");
166
- authUrl.searchParams.set("state", state);
167
- authUrl.searchParams.set("redirect_to", redirectUrl);
168
- console.log("\n\u{1F512} Please authenticate in your browser...\n");
169
- console.log(`Opening: ${authUrl}
170
- `);
171
- const open = (await import('open')).default;
172
- open(authUrl.toString());
173
- });
174
- server.on("error", (err) => {
175
- if (err.code === "EADDRINUSE") {
176
- reject(
177
- new Error(
178
- `Port ${port} is already in use. Please specify a different port using the --port option.`
179
- )
180
- );
181
- } else {
182
- reject(err);
183
- }
184
- server.close();
185
- });
186
- const timeoutId = setTimeout(
187
- () => {
188
- server.close(() => {
189
- console.log("\u{1F510} Local authentication server closed due to timeout");
190
- reject(new Error("Authentication timed out. Please try again."));
191
- });
192
- },
193
- 5 * 60 * 1e3
194
- );
195
- server.on("close", () => {
196
- clearTimeout(timeoutId);
197
- });
198
- });
199
- }
200
- async function saveCredentials(token) {
201
- console.log("Saving credentials...");
202
- const configDir = path__default.default.join(os.homedir(), ".ollie-shop");
203
- const credentialsPath = path__default.default.join(configDir, "credentials.json");
204
- try {
205
- await fs__default.default.mkdir(configDir, { recursive: true });
206
- } catch (error) {
207
- if (!(error instanceof Error && "code" in error && error.code === "EEXIST")) {
208
- throw error;
45
+ catch (error) {
46
+ console_1.console.error("Invalid global options:");
47
+ if (error instanceof Error) {
48
+ console_1.console.error(error.message);
49
+ }
50
+ process.exit(1);
51
+ }
52
+ }
53
+ validateGlobalOptions(options) {
54
+ const result = command_schema_1.GlobalOptionsSchema.safeParse(options);
55
+ if (!result.success) {
56
+ const errors = result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`);
57
+ throw new Error(errors.join("\n"));
58
+ }
59
+ return result.data;
60
+ }
61
+ registerCommands() {
62
+ try {
63
+ (0, commands_1.registerCommands)(this.program);
64
+ }
65
+ catch (error) {
66
+ console_1.console.error("Failed to register commands:");
67
+ if (error instanceof Error) {
68
+ console_1.console.error(error.message);
69
+ }
70
+ process.exit(1);
71
+ }
72
+ }
73
+ async run() {
74
+ try {
75
+ // Show command suggestions if no args provided
76
+ if (process.argv.length <= 2) {
77
+ const { showCommandSuggestions } = await import("./utils/command-suggestions.js");
78
+ showCommandSuggestions(console_1.console);
79
+ return;
80
+ }
81
+ await this.program.parseAsync();
82
+ }
83
+ catch (error) {
84
+ console_1.console.error("CLI execution failed:");
85
+ if (error instanceof Error) {
86
+ console_1.console.error(error.message);
87
+ if (process.env.DEBUG) {
88
+ console_1.console.info(`Stack trace: ${error.stack || ""}`);
89
+ }
90
+ }
91
+ process.exit(1);
92
+ }
209
93
  }
210
- }
211
- await fs__default.default.writeFile(credentialsPath, JSON.stringify(token, null, 2));
212
- return true;
213
- }
214
-
215
- // src/commands/index.ts
216
- function registerCommands(program) {
217
- configureLoginCommand(program);
218
- }
219
-
220
- // src/index.ts
221
- function createProgram() {
222
- const program = new commander.Command();
223
- program.name("ollie").description("Ollie Shop CLI tools").version("0.1.0");
224
- registerCommands(program);
225
- return program;
226
- }
227
- if (__require.main === module) {
228
- const program = createProgram();
229
- program.parse();
230
94
  }
231
-
232
- exports.createProgram = createProgram;
95
+ const cli = new OllieShopCLI();
96
+ cli.run().catch((error) => {
97
+ console_1.console.error(`Unexpected error: ${error}`);
98
+ process.exit(1);
99
+ });
@@ -0,0 +1,14 @@
1
+ import { type ComponentSlotType } from "@ollie-shop/core";
2
+ export interface ComponentCreationAnswers {
3
+ name: string;
4
+ slot: ComponentSlotType;
5
+ includeTests: boolean;
6
+ description?: string;
7
+ }
8
+ export interface ComponentDeploymentAnswers {
9
+ versionId: string;
10
+ confirm: boolean;
11
+ }
12
+ export declare function promptComponentCreation(name?: string, slot?: string): Promise<ComponentCreationAnswers>;
13
+ export declare function promptComponentDeployment(): Promise<ComponentDeploymentAnswers>;
14
+ //# sourceMappingURL=component.prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.prompts.d.ts","sourceRoot":"","sources":["../../src/prompts/component.prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIzE,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAQD,wBAAsB,uBAAuB,CAC3C,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,wBAAwB,CAAC,CA8CnC;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,0BAA0B,CAAC,CAoBrF"}
@@ -0,0 +1,75 @@
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.promptComponentCreation = promptComponentCreation;
7
+ exports.promptComponentDeployment = promptComponentDeployment;
8
+ const core_1 = require("@ollie-shop/core");
9
+ const inquirer_1 = __importDefault(require("inquirer"));
10
+ const validation_helpers_1 = require("../utils/validation-helpers");
11
+ // Generate component slot choices from core enum
12
+ const componentSlotChoices = core_1.ComponentSlot.options.map((slot) => ({
13
+ name: slot.charAt(0).toUpperCase() + slot.slice(1).replace(/-/g, " "),
14
+ value: slot,
15
+ }));
16
+ async function promptComponentCreation(name, slot) {
17
+ const questions = [];
18
+ if (!name) {
19
+ questions.push({
20
+ type: "input",
21
+ name: "name",
22
+ message: "What's the name of your component?",
23
+ validate: (input) => {
24
+ return (0, validation_helpers_1.validateComponentName)(input);
25
+ },
26
+ });
27
+ }
28
+ if (!slot) {
29
+ questions.push({
30
+ type: "list",
31
+ name: "slot",
32
+ message: "Which slot will this component occupy?",
33
+ choices: componentSlotChoices,
34
+ });
35
+ }
36
+ questions.push({
37
+ type: "input",
38
+ name: "description",
39
+ message: "Enter a description (optional):",
40
+ default: "",
41
+ }, {
42
+ type: "confirm",
43
+ name: "includeTests",
44
+ message: "Include test files?",
45
+ default: true,
46
+ });
47
+ const answers = await inquirer_1.default.prompt(questions);
48
+ return {
49
+ name: name || answers.name,
50
+ slot: slot || answers.slot,
51
+ description: answers.description || undefined,
52
+ includeTests: answers.includeTests,
53
+ };
54
+ }
55
+ async function promptComponentDeployment() {
56
+ const answers = await inquirer_1.default.prompt([
57
+ {
58
+ type: "input",
59
+ name: "versionId",
60
+ message: "Enter the version ID to deploy to:",
61
+ validate: (input) => {
62
+ if (!input.trim())
63
+ return "Version ID is required";
64
+ return true;
65
+ },
66
+ },
67
+ {
68
+ type: "confirm",
69
+ name: "confirm",
70
+ message: "Are you sure you want to deploy this component?",
71
+ default: false,
72
+ },
73
+ ]);
74
+ return answers;
75
+ }
@@ -0,0 +1,21 @@
1
+ import { type FunctionInvocationTypeType, type OnErrorBehaviorType } from "@ollie-shop/core";
2
+ export interface FunctionCreationAnswers {
3
+ name: string;
4
+ invocation: FunctionInvocationTypeType;
5
+ priority: number;
6
+ onError: OnErrorBehaviorType;
7
+ includeTests: boolean;
8
+ description?: string;
9
+ }
10
+ export interface FunctionDeploymentAnswers {
11
+ versionId: string;
12
+ confirm: boolean;
13
+ }
14
+ export interface FunctionTestAnswers {
15
+ pattern: string;
16
+ }
17
+ export declare function promptFunctionCreation(name?: string, invocation?: string, priority?: number, onError?: string): Promise<FunctionCreationAnswers>;
18
+ export declare function promptFunctionDeployment(): Promise<FunctionDeploymentAnswers>;
19
+ export declare function promptFunctionTest(): Promise<FunctionTestAnswers>;
20
+ export declare function getInvocationDescription(invocation: FunctionInvocationTypeType): string;
21
+ //# sourceMappingURL=function.prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.prompts.d.ts","sourceRoot":"","sources":["../../src/prompts/function.prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAE/B,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAI1B,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,0BAA0B,CAAC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB;AAoBD,wBAAsB,sBAAsB,CAC1C,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,uBAAuB,CAAC,CAuElC;AAED,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAoBnF;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAWvE;AAED,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,0BAA0B,GACrC,MAAM,CAOR"}
@@ -0,0 +1,127 @@
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.promptFunctionCreation = promptFunctionCreation;
7
+ exports.promptFunctionDeployment = promptFunctionDeployment;
8
+ exports.promptFunctionTest = promptFunctionTest;
9
+ exports.getInvocationDescription = getInvocationDescription;
10
+ const core_1 = require("@ollie-shop/core");
11
+ const inquirer_1 = __importDefault(require("inquirer"));
12
+ const validation_helpers_1 = require("../utils/validation-helpers");
13
+ // Generate function invocation choices from core enum
14
+ const invocationChoices = core_1.FunctionInvocationType.options.map((type) => ({
15
+ name: type === "request"
16
+ ? "Request (before forwarding to target)"
17
+ : "Response (after receiving from target)",
18
+ value: type,
19
+ }));
20
+ // Generate error behavior choices from core enum
21
+ const errorBehaviorChoices = core_1.OnErrorBehavior.options.map((behavior) => ({
22
+ name: behavior === "throw"
23
+ ? "Throw error and stop execution"
24
+ : "Skip and continue with next function",
25
+ value: behavior,
26
+ }));
27
+ async function promptFunctionCreation(name, invocation, priority, onError) {
28
+ const questions = [];
29
+ if (!name) {
30
+ questions.push({
31
+ type: "input",
32
+ name: "name",
33
+ message: "What's the name of your function?",
34
+ validate: (input) => {
35
+ return (0, validation_helpers_1.validateFunctionName)(input);
36
+ },
37
+ });
38
+ }
39
+ if (!invocation) {
40
+ questions.push({
41
+ type: "list",
42
+ name: "invocation",
43
+ message: "When should this function execute?",
44
+ choices: invocationChoices,
45
+ });
46
+ }
47
+ if (priority === undefined) {
48
+ questions.push({
49
+ type: "number",
50
+ name: "priority",
51
+ message: "Priority (0-100, higher = executes first):",
52
+ default: 0,
53
+ validate: (input) => {
54
+ if (input < 0 || input > 100)
55
+ return "Priority must be between 0 and 100";
56
+ return true;
57
+ },
58
+ });
59
+ }
60
+ if (!onError) {
61
+ questions.push({
62
+ type: "list",
63
+ name: "onError",
64
+ message: "What should happen if this function fails?",
65
+ choices: errorBehaviorChoices,
66
+ });
67
+ }
68
+ questions.push({
69
+ type: "input",
70
+ name: "description",
71
+ message: "Enter a description (optional):",
72
+ default: "",
73
+ }, {
74
+ type: "confirm",
75
+ name: "includeTests",
76
+ message: "Include test files?",
77
+ default: true,
78
+ });
79
+ const answers = await inquirer_1.default.prompt(questions);
80
+ return {
81
+ name: name || answers.name,
82
+ invocation: invocation || answers.invocation,
83
+ priority: priority ?? answers.priority,
84
+ onError: onError || answers.onError,
85
+ description: answers.description || undefined,
86
+ includeTests: answers.includeTests,
87
+ };
88
+ }
89
+ async function promptFunctionDeployment() {
90
+ const answers = await inquirer_1.default.prompt([
91
+ {
92
+ type: "input",
93
+ name: "versionId",
94
+ message: "Enter the version ID to deploy to:",
95
+ validate: (input) => {
96
+ if (!input.trim())
97
+ return "Version ID is required";
98
+ return true;
99
+ },
100
+ },
101
+ {
102
+ type: "confirm",
103
+ name: "confirm",
104
+ message: "Are you sure you want to deploy this function?",
105
+ default: false,
106
+ },
107
+ ]);
108
+ return answers;
109
+ }
110
+ async function promptFunctionTest() {
111
+ const answers = await inquirer_1.default.prompt([
112
+ {
113
+ type: "input",
114
+ name: "pattern",
115
+ message: "Enter test file pattern:",
116
+ default: "**/*.test.{js,ts}",
117
+ },
118
+ ]);
119
+ return answers;
120
+ }
121
+ function getInvocationDescription(invocation) {
122
+ const descriptions = {
123
+ request: "Executes before forwarding request to target URL",
124
+ response: "Executes after receiving response from target URL",
125
+ };
126
+ return descriptions[invocation] || "Custom invocation handler";
127
+ }