@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.
Files changed (182) hide show
  1. package/.turbo/turbo-build.log +2 -11
  2. package/CHANGELOG.md +13 -7
  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 +88 -478
  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 +43 -11
  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 +11 -11
  140. package/src/commands/function.ts +252 -0
  141. package/src/commands/help.ts +8 -18
  142. package/src/commands/index.ts +14 -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 +45 -8
  147. package/src/commands/whoami.ts +8 -13
  148. package/src/index.ts +108 -34
  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 +0 -1
  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/validation-error-formatter.ts +337 -0
  176. package/src/utils/validation-helpers.ts +192 -0
  177. package/tsconfig.json +13 -7
  178. package/vitest.config.ts +28 -0
  179. package/vitest.setup.ts +29 -0
  180. package/src/commands/validate.ts +0 -62
  181. package/src/utils/core.ts +0 -105
  182. package/tsup.config.ts +0 -15
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.registerFunctionCommands = registerFunctionCommands;
37
+ const functionActions = __importStar(require("../actions/function.actions"));
38
+ const command_schema_1 = require("../schemas/command.schema");
39
+ const command_builder_1 = require("../utils/command-builder");
40
+ const command_parser_1 = require("../utils/command-parser");
41
+ function registerFunctionCommands(program) {
42
+ const cmd = (0, command_builder_1.buildCommandGroup)(program, "function", "Manage Ollie Shop functions", ["func"]);
43
+ // Create function command
44
+ (0, command_builder_1.buildCommand)(cmd, {
45
+ name: "create",
46
+ description: "Create a new function",
47
+ options: [
48
+ command_parser_1.COMMON_OPTIONS.functionName,
49
+ command_parser_1.COMMON_OPTIONS.functionInvocation,
50
+ command_parser_1.COMMON_OPTIONS.priority,
51
+ {
52
+ flags: "--on-error <strategy>",
53
+ description: "Error handling strategy (throw|skip)",
54
+ defaultValue: "throw",
55
+ },
56
+ {
57
+ flags: "-d, --description <description>",
58
+ description: "Function description",
59
+ },
60
+ {
61
+ flags: "--template <template>",
62
+ description: "Function template to use",
63
+ },
64
+ command_parser_1.COMMON_OPTIONS.tests,
65
+ command_parser_1.COMMON_OPTIONS.noTests,
66
+ ],
67
+ schema: command_schema_1.FunctionCreateOptionsSchema,
68
+ examples: [
69
+ {
70
+ description: "Create a function to validate orders",
71
+ command: "ollieshop function create --name validate-order --event order --timing before",
72
+ },
73
+ {
74
+ description: "Create a discount function for cart",
75
+ command: "ollieshop function create --name apply-discount --event cart --description 'Apply bulk discounts'",
76
+ },
77
+ {
78
+ description: "Create a JavaScript function without tests",
79
+ command: "ollieshop function create --name check-inventory --language javascript --no-tests",
80
+ },
81
+ ],
82
+ handler: async (options, console) => {
83
+ await functionActions.createFunction(options, console);
84
+ },
85
+ });
86
+ // Validate function command
87
+ (0, command_builder_1.buildCommand)(cmd, {
88
+ name: "validate",
89
+ description: "Validate a function",
90
+ options: [command_parser_1.COMMON_OPTIONS.path],
91
+ schema: command_schema_1.FunctionValidateOptionsSchema,
92
+ examples: [
93
+ {
94
+ description: "Validate current directory",
95
+ command: "ollieshop function validate",
96
+ },
97
+ {
98
+ description: "Validate specific function",
99
+ command: "ollieshop function validate --path ./functions/validate-order",
100
+ },
101
+ ],
102
+ handler: async (options, console) => {
103
+ await functionActions.validateFunction({
104
+ path: options.path || process.cwd(),
105
+ strict: options.strict ?? false,
106
+ fix: options.fix ?? false,
107
+ }, console);
108
+ },
109
+ });
110
+ // Test function command
111
+ (0, command_builder_1.buildCommand)(cmd, {
112
+ name: "test",
113
+ description: "Test a function locally",
114
+ options: [
115
+ command_parser_1.COMMON_OPTIONS.path,
116
+ {
117
+ flags: "-w, --watch",
118
+ description: "Watch for changes",
119
+ defaultValue: false,
120
+ },
121
+ {
122
+ flags: "--payload <json>",
123
+ description: "Test payload (JSON string)",
124
+ },
125
+ {
126
+ flags: "--timeout <ms>",
127
+ description: "Timeout in milliseconds",
128
+ },
129
+ ],
130
+ schema: command_schema_1.FunctionTestOptionsSchema,
131
+ examples: [
132
+ {
133
+ description: "Test function in current directory",
134
+ command: "ollieshop function test",
135
+ },
136
+ {
137
+ description: "Test with custom payload",
138
+ command: `ollieshop function test --payload '{"items": [{"id": "123", "quantity": 2}]}'`,
139
+ },
140
+ {
141
+ description: "Test in watch mode",
142
+ command: "ollieshop function test --watch",
143
+ },
144
+ ],
145
+ handler: async (options, console) => {
146
+ await functionActions.testFunction({
147
+ path: options.path || process.cwd(),
148
+ payload: options.payload,
149
+ timeout: options.timeout,
150
+ watch: options.watch ?? false,
151
+ coverage: options.coverage ?? false,
152
+ }, console);
153
+ },
154
+ });
155
+ // Deploy function command
156
+ (0, command_builder_1.buildCommand)(cmd, {
157
+ name: "deploy",
158
+ description: "Build and deploy a function to cloud",
159
+ options: [
160
+ command_parser_1.COMMON_OPTIONS.path,
161
+ {
162
+ flags: "--id <id>",
163
+ description: "Function ID for deployment",
164
+ required: true,
165
+ },
166
+ command_parser_1.COMMON_OPTIONS.wait,
167
+ ],
168
+ schema: command_schema_1.FunctionDeployOptionsSchema,
169
+ examples: [
170
+ {
171
+ description: "Deploy current directory",
172
+ command: "ollieshop function deploy",
173
+ },
174
+ {
175
+ description: "Deploy specific function and wait",
176
+ command: "ollieshop function deploy --path ./my-function --wait",
177
+ },
178
+ {
179
+ description: "Deploy with function ID",
180
+ command: "ollieshop function deploy --id func_123abc",
181
+ },
182
+ ],
183
+ handler: async (options, console) => {
184
+ // Map id to functionId if provided
185
+ const deployOptions = {
186
+ path: options.path || process.cwd(),
187
+ functionId: options.id || options.functionId,
188
+ wait: options.wait,
189
+ };
190
+ await functionActions.deployFunction(deployOptions, console);
191
+ },
192
+ });
193
+ // List functions command
194
+ (0, command_builder_1.buildCommand)(cmd, {
195
+ name: "list",
196
+ description: "List all functions",
197
+ aliases: ["ls"],
198
+ examples: [
199
+ {
200
+ description: "List all functions",
201
+ command: "ollieshop function list",
202
+ },
203
+ ],
204
+ handler: async (_, console) => {
205
+ await functionActions.listFunctions(console);
206
+ },
207
+ });
208
+ // Deploy status command
209
+ cmd
210
+ .command("deploy-status <buildId>")
211
+ .description("Check the status of a function deployment")
212
+ .action(async (buildId) => {
213
+ try {
214
+ const { getBuildStatus } = await import("@ollie-shop/core");
215
+ const { console: cliConsole } = await import("../utils/console.js");
216
+ const spinner = cliConsole.spinner("Checking deployment status...");
217
+ const build = await getBuildStatus(buildId);
218
+ if (!build) {
219
+ spinner.fail("Build not found");
220
+ return;
221
+ }
222
+ spinner.succeed();
223
+ cliConsole.info("Deployment Status:");
224
+ cliConsole.log(` Build ID: ${build.id}`);
225
+ cliConsole.log(` Status: ${build.status}`);
226
+ cliConsole.log(` Started: ${new Date(build.startTime).toLocaleString()}`);
227
+ if (build.endTime) {
228
+ cliConsole.log(` Completed: ${new Date(build.endTime).toLocaleString()}`);
229
+ }
230
+ if (build.deploymentUrl) {
231
+ cliConsole.success(`\nFunction URL: ${build.deploymentUrl}`);
232
+ }
233
+ if (build.error) {
234
+ cliConsole.error(`\nError: ${build.error}`);
235
+ }
236
+ }
237
+ catch (error) {
238
+ const { console: cliConsole } = await import("../utils/console.js");
239
+ cliConsole.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
240
+ process.exit(1);
241
+ }
242
+ });
243
+ }
@@ -0,0 +1,3 @@
1
+ import type { Command } from "@commander-js/extra-typings";
2
+ export declare function configureHelpCommand(program: Command): void;
3
+ //# sourceMappingURL=help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/commands/help.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAG3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAc3D"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureHelpCommand = configureHelpCommand;
4
+ const console_1 = require("../utils/console");
5
+ function configureHelpCommand(program) {
6
+ program
7
+ .command("help [command]")
8
+ .description("Display help for a specific command or list all commands")
9
+ .action((cmdName) => {
10
+ if (cmdName) {
11
+ // For specific command help, show the program help with the command
12
+ console_1.console.info(`\nHelp for command: ${cmdName}`);
13
+ console_1.console.info("Use 'ollieshop <command> --help' for detailed help\n");
14
+ }
15
+ else {
16
+ // Show general help
17
+ program.help();
18
+ }
19
+ });
20
+ }
@@ -0,0 +1,3 @@
1
+ import type { Command } from "@commander-js/extra-typings";
2
+ export declare function registerCommands(program: Command): void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAW3D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAevD"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerCommands = registerCommands;
4
+ const component_1 = require("./component");
5
+ const docs_1 = require("./docs");
6
+ const function_1 = require("./function");
7
+ const help_1 = require("./help");
8
+ const login_1 = require("./login");
9
+ const project_1 = require("./project");
10
+ const store_version_1 = require("./store-version");
11
+ const version_1 = require("./version");
12
+ const whoami_1 = require("./whoami");
13
+ function registerCommands(program) {
14
+ // Register simple commands that don't need heavy services
15
+ (0, docs_1.configureDocsCommand)(program);
16
+ (0, help_1.configureHelpCommand)(program);
17
+ (0, login_1.configureLoginCommand)(program);
18
+ (0, whoami_1.configureWhoamiCommand)(program);
19
+ // Register new commands
20
+ (0, store_version_1.registerStoreVersionCommands)(program);
21
+ (0, version_1.configureVersionCommand)(program);
22
+ // Register complex commands with lazy service loading
23
+ (0, component_1.registerComponentCommands)(program);
24
+ (0, function_1.registerFunctionCommands)(program);
25
+ (0, project_1.registerProjectCommands)(program);
26
+ }
@@ -0,0 +1,3 @@
1
+ import type { Command } from "@commander-js/extra-typings";
2
+ export declare function configureLoginCommand(program: Command): Command;
3
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAO3D,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CA+B/D"}
@@ -0,0 +1,175 @@
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.configureLoginCommand = configureLoginCommand;
7
+ const node_crypto_1 = require("node:crypto");
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const node_http_1 = require("node:http");
10
+ const node_os_1 = require("node:os");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const types_1 = require("../types");
13
+ const console_1 = require("../utils/console");
14
+ const DEFAULT_CALLBACK_PORT = 7777;
15
+ const AUTH_ENDPOINT = "https://admin.ollie.shop/auth/login";
16
+ function configureLoginCommand(program) {
17
+ return program
18
+ .command("login")
19
+ .description("Log in to your Ollie Shop account")
20
+ .option("-p, --port <port>", "Port to use for the local callback server", DEFAULT_CALLBACK_PORT.toString())
21
+ .option("--auth-url <url>", "Custom authorization URL", AUTH_ENDPOINT)
22
+ .action(async (options) => {
23
+ console_1.console.info("šŸ” Initiating Ollie Shop login flow...");
24
+ try {
25
+ const token = await startWebAuthFlow(options);
26
+ if (token) {
27
+ await saveCredentials(token);
28
+ console_1.console.success("āœ… Successfully logged in!");
29
+ return;
30
+ }
31
+ console_1.console.error("āŒ Authentication failed. Please try again.");
32
+ process.exit(1);
33
+ }
34
+ catch (error) {
35
+ console_1.console.error(`āŒ Login failed: ${error instanceof Error ? error.message : "Unknown error"}`);
36
+ process.exit(1);
37
+ }
38
+ });
39
+ }
40
+ async function handleAuthCallback(req, res, state, resolve, reject) {
41
+ const socket = req.socket;
42
+ const url = new URL(req.url || "/", `http://localhost:${socket.localPort || 3000}`);
43
+ const params = url.searchParams;
44
+ const returnedState = params.get("state");
45
+ if (returnedState !== state) {
46
+ sendErrorResponse(res, 400, "Invalid state parameter", "Authentication failed. Please try again.");
47
+ reject(new Error("Invalid state parameter"));
48
+ return;
49
+ }
50
+ let formData = "";
51
+ req.on("data", (chunk) => {
52
+ formData += chunk.toString();
53
+ });
54
+ await new Promise((formResolve) => {
55
+ req.on("end", () => {
56
+ formResolve();
57
+ });
58
+ });
59
+ const formParams = new URLSearchParams(formData);
60
+ const accessToken = formParams.get("access_token");
61
+ const refreshToken = formParams.get("refresh_token") || "";
62
+ const expiresAt = formParams.get("expires_at") ||
63
+ new Date(Date.now() + 3600000).toISOString();
64
+ if (!accessToken) {
65
+ sendErrorResponse(res, 400, "Missing authentication token", "Authentication failed. Please try again.");
66
+ reject(new Error("Missing authentication token"));
67
+ return;
68
+ }
69
+ try {
70
+ const token = {
71
+ accessToken,
72
+ refreshToken,
73
+ expiresAt,
74
+ };
75
+ sendSuccessResponse(res);
76
+ resolve(token);
77
+ }
78
+ catch (error) {
79
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
80
+ sendErrorResponse(res, 500, "Authentication failed", `Error: ${errorMessage}`);
81
+ reject(new Error(errorMessage));
82
+ }
83
+ }
84
+ function sendErrorResponse(res, statusCode, title, message) {
85
+ res.writeHead(statusCode, { "Content-Type": "text/html" });
86
+ res.end(`<h1>${title}</h1><p>${message}</p>`);
87
+ }
88
+ function sendSuccessResponse(res) {
89
+ res.writeHead(200, { "Content-Type": "text/html" });
90
+ res.end("<h1>Authentication successful!</h1><p>You can now close this window and return to the CLI.</p>");
91
+ }
92
+ function sendWaitingResponse(res) {
93
+ res.writeHead(200, { "Content-Type": "text/html" });
94
+ res.end("<h1>Ollie Shop CLI Authentication</h1><p>Waiting for authentication response...</p>");
95
+ }
96
+ async function startWebAuthFlow(options) {
97
+ const state = (0, node_crypto_1.randomBytes)(16).toString("hex");
98
+ const port = Number.parseInt(options.port, 10);
99
+ const baseUrl = options.authUrl;
100
+ return new Promise((resolve, reject) => {
101
+ const server = (0, node_http_1.createServer)(async (req, res) => {
102
+ try {
103
+ const url = new URL(req.url || "/", `http://localhost:${port}`);
104
+ if (url.pathname === "/callback") {
105
+ await handleAuthCallback(req, res, state, (token) => {
106
+ server.close(() => {
107
+ console_1.console.debug("šŸ” Local authentication server closed");
108
+ resolve(token);
109
+ });
110
+ }, (error) => {
111
+ server.close(() => {
112
+ console_1.console.debug("šŸ” Local authentication server closed");
113
+ reject(error);
114
+ });
115
+ });
116
+ }
117
+ else {
118
+ sendWaitingResponse(res);
119
+ }
120
+ }
121
+ catch (error) {
122
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
123
+ sendErrorResponse(res, 500, "Server Error", errorMessage);
124
+ server.close(() => {
125
+ console_1.console.debug("šŸ” Local authentication server closed");
126
+ reject(new Error(errorMessage));
127
+ });
128
+ }
129
+ });
130
+ server.listen(port, async () => {
131
+ const redirectUrl = `http://localhost:${port}/callback`;
132
+ const authUrl = new URL(baseUrl);
133
+ authUrl.searchParams.set("flow", "cli");
134
+ authUrl.searchParams.set("state", state);
135
+ authUrl.searchParams.set("redirect_to", redirectUrl);
136
+ console_1.console.info("\nšŸ”’ Please authenticate in your browser...\n");
137
+ console_1.console.info(`Opening: ${authUrl}\n`);
138
+ const open = (await import("open")).default;
139
+ open(authUrl.toString());
140
+ });
141
+ server.on("error", (err) => {
142
+ if ((0, types_1.isNodeError)(err) && err.code === "EADDRINUSE") {
143
+ reject(new Error(`Port ${port} is already in use. Please specify a different port using the --port option.`));
144
+ }
145
+ else {
146
+ reject(err);
147
+ }
148
+ server.close();
149
+ });
150
+ const timeoutId = setTimeout(() => {
151
+ server.close(() => {
152
+ console_1.console.debug("šŸ” Local authentication server closed due to timeout");
153
+ reject(new Error("Authentication timed out. Please try again."));
154
+ });
155
+ }, 5 * 60 * 1000);
156
+ server.on("close", () => {
157
+ clearTimeout(timeoutId);
158
+ });
159
+ });
160
+ }
161
+ async function saveCredentials(token) {
162
+ console_1.console.debug("Saving credentials...");
163
+ const configDir = node_path_1.default.join((0, node_os_1.homedir)(), ".ollie-shop");
164
+ const credentialsPath = node_path_1.default.join(configDir, "credentials.json");
165
+ try {
166
+ await promises_1.default.mkdir(configDir, { recursive: true });
167
+ }
168
+ catch (error) {
169
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST")) {
170
+ throw error;
171
+ }
172
+ }
173
+ await promises_1.default.writeFile(credentialsPath, JSON.stringify(token, null, 2));
174
+ return true;
175
+ }
@@ -0,0 +1,3 @@
1
+ import type { Command } from "@commander-js/extra-typings";
2
+ export declare function registerProjectCommands(program: Command): void;
3
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/commands/project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAS3D,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAiG9D"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerProjectCommands = registerProjectCommands;
4
+ const project_actions_1 = require("../actions/project.actions");
5
+ const console_1 = require("../utils/console");
6
+ function registerProjectCommands(program) {
7
+ const projectCommand = program
8
+ .command("project")
9
+ .description("Project management commands");
10
+ projectCommand
11
+ .command("init")
12
+ .description("Initialize a new project")
13
+ .option("-n, --name <name>", "Project name")
14
+ .option("-t, --template <template>", "Project template")
15
+ .action(async (options) => {
16
+ try {
17
+ await (0, project_actions_1.initProject)({
18
+ name: options.name,
19
+ template: options.template || "default",
20
+ git: true,
21
+ install: true,
22
+ }, console_1.console);
23
+ }
24
+ catch (error) {
25
+ console_1.console.error(error instanceof Error ? error.message : "An error occurred");
26
+ process.exit(1);
27
+ }
28
+ });
29
+ projectCommand
30
+ .command("build")
31
+ .description("Build project")
32
+ .option("-p, --path <path>", "Project path")
33
+ .option("--watch", "Watch for changes")
34
+ .action(async (options) => {
35
+ try {
36
+ await (0, project_actions_1.buildProject)({
37
+ path: options.path,
38
+ watch: options.watch ?? false,
39
+ }, console_1.console);
40
+ }
41
+ catch (error) {
42
+ console_1.console.error(error instanceof Error ? error.message : "An error occurred");
43
+ process.exit(1);
44
+ }
45
+ });
46
+ projectCommand
47
+ .command("dev")
48
+ .description("Start development server")
49
+ .option("-p, --port <port>", "Port number", Number.parseInt)
50
+ .option("--open", "Open browser")
51
+ .action(async (options) => {
52
+ try {
53
+ await (0, project_actions_1.startDevServer)({
54
+ port: options.port ?? 3000,
55
+ open: options.open ?? false,
56
+ }, console_1.console);
57
+ }
58
+ catch (error) {
59
+ console_1.console.error(error instanceof Error ? error.message : "An error occurred");
60
+ process.exit(1);
61
+ }
62
+ });
63
+ projectCommand
64
+ .command("validate")
65
+ .description("Validate project")
66
+ .option("-p, --path <path>", "Project path")
67
+ .action(async (options) => {
68
+ try {
69
+ await (0, project_actions_1.validateProject)({
70
+ path: options.path,
71
+ }, console_1.console);
72
+ }
73
+ catch (error) {
74
+ console_1.console.error(error instanceof Error ? error.message : "An error occurred");
75
+ process.exit(1);
76
+ }
77
+ });
78
+ }
@@ -0,0 +1,3 @@
1
+ import type { Command } from "@commander-js/extra-typings";
2
+ export declare function registerStoreVersionCommands(program: Command): void;
3
+ //# sourceMappingURL=store-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-version.d.ts","sourceRoot":"","sources":["../../src/commands/store-version.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAkB3D,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA+NnE"}