@ollie-shop/cli 1.0.2 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ollie-shop/cli",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Ollie Shop CLI - Development tools for custom checkouts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,6 +9,7 @@
9
9
  "ollieshop": "dist/index.js"
10
10
  },
11
11
  "dependencies": {
12
+ "@supabase/supabase-js": "^2.49.4",
12
13
  "archiver": "^7.0.1",
13
14
  "esbuild": "^0.24.0",
14
15
  "glob": "^11.0.0",
@@ -16,7 +17,8 @@
16
17
  "jwt-decode": "^4.0.0",
17
18
  "open": "^10.1.0",
18
19
  "react": "^18.3.1",
19
- "zod": "^3.24.2"
20
+ "zod": "^3.24.2",
21
+ "zod-to-json-schema": "^3.24.5"
20
22
  },
21
23
  "devDependencies": {
22
24
  "@types/archiver": "^6.0.3",
@@ -0,0 +1,107 @@
1
+ import { createComponent, listComponents } from "../core/component.js";
2
+ import {
3
+ detectOutputFormat,
4
+ outputDryRun,
5
+ outputResult,
6
+ } from "../utils/output.js";
7
+ import { type ParsedArgs, getBoolFlag, getFlag } from "../utils/parse-args.js";
8
+ import { getAuthenticatedClient } from "../utils/supabase.js";
9
+ import { validateRequired, validateUuid } from "../utils/validate.js";
10
+
11
+ export async function componentCommand(parsed: ParsedArgs): Promise<void> {
12
+ const sub = parsed.subcommand;
13
+ if (sub === "create") return componentCreateCommand(parsed);
14
+ if (sub === "list" || sub === "ls") return componentListCommand(parsed);
15
+
16
+ console.error(
17
+ `Unknown component subcommand: ${sub}. Use: component create | component list`,
18
+ );
19
+ process.exit(1);
20
+ }
21
+
22
+ async function componentCreateCommand(parsed: ParsedArgs): Promise<void> {
23
+ const format = detectOutputFormat(parsed.global.output);
24
+
25
+ try {
26
+ let input: {
27
+ versionId: string;
28
+ name: string;
29
+ slot: string;
30
+ active?: boolean;
31
+ props?: Record<string, unknown> | null;
32
+ };
33
+
34
+ if (parsed.global.data) {
35
+ const raw = JSON.parse(parsed.global.data);
36
+ input = {
37
+ versionId: validateUuid(raw.versionId, "versionId"),
38
+ name: validateRequired(raw.name, "name"),
39
+ slot: validateRequired(raw.slot, "slot"),
40
+ active: raw.active ?? true,
41
+ props: raw.props ?? null,
42
+ };
43
+ } else {
44
+ input = {
45
+ versionId: validateUuid(
46
+ validateRequired(getFlag(parsed.flags, "version-id"), "version-id"),
47
+ "version-id",
48
+ ),
49
+ name: validateRequired(getFlag(parsed.flags, "name", "n"), "name"),
50
+ slot: validateRequired(getFlag(parsed.flags, "slot", "s"), "slot"),
51
+ active:
52
+ getBoolFlag(parsed.flags, "active") || !("active" in parsed.flags),
53
+ props: null,
54
+ };
55
+ }
56
+
57
+ if (parsed.global.dryRun) {
58
+ outputDryRun(
59
+ "component.create",
60
+ input as Record<string, unknown>,
61
+ format,
62
+ );
63
+ return;
64
+ }
65
+
66
+ const client = await getAuthenticatedClient();
67
+ const result = await createComponent(client, input);
68
+
69
+ outputResult(result, format, parsed.global.fields);
70
+ if (result.error) process.exit(1);
71
+ } catch (err) {
72
+ outputResult(
73
+ {
74
+ error: { message: err instanceof Error ? err.message : String(err) },
75
+ },
76
+ format,
77
+ );
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ async function componentListCommand(parsed: ParsedArgs): Promise<void> {
83
+ const format = detectOutputFormat(parsed.global.output);
84
+
85
+ try {
86
+ const storeId = validateUuid(
87
+ validateRequired(getFlag(parsed.flags, "store-id"), "store-id"),
88
+ "store-id",
89
+ );
90
+ const versionId = getFlag(parsed.flags, "version-id");
91
+ if (versionId) validateUuid(versionId, "version-id");
92
+
93
+ const client = await getAuthenticatedClient();
94
+ const result = await listComponents(client, storeId, versionId);
95
+
96
+ outputResult(result, format, parsed.global.fields);
97
+ if (result.error) process.exit(1);
98
+ } catch (err) {
99
+ outputResult(
100
+ {
101
+ error: { message: err instanceof Error ? err.message : String(err) },
102
+ },
103
+ format,
104
+ );
105
+ process.exit(1);
106
+ }
107
+ }
@@ -16,29 +16,71 @@ export function HelpCommand() {
16
16
  </Box>
17
17
 
18
18
  <Box marginTop={1}>
19
- <Text bold>Commands:</Text>
19
+ <Text bold>Interactive Commands:</Text>
20
20
  </Box>
21
21
  <Box marginLeft={2} flexDirection="column" gap={0}>
22
22
  <Box>
23
- <Box width={16}>
23
+ <Box width={24}>
24
24
  <Text color="green">login</Text>
25
25
  </Box>
26
26
  <Text>Authenticate with your Ollie Shop account</Text>
27
27
  </Box>
28
28
  <Box>
29
- <Box width={16}>
29
+ <Box width={24}>
30
30
  <Text color="green">start</Text>
31
31
  </Box>
32
32
  <Text>Start the development server with hot reload</Text>
33
33
  </Box>
34
+ </Box>
35
+
36
+ <Box marginTop={1}>
37
+ <Text bold>Agent Commands:</Text>
38
+ </Box>
39
+ <Box marginLeft={2} flexDirection="column" gap={0}>
40
+ <Box>
41
+ <Box width={24}>
42
+ <Text color="green">whoami</Text>
43
+ </Box>
44
+ <Text>Show current user and organization</Text>
45
+ </Box>
46
+ <Box>
47
+ <Box width={24}>
48
+ <Text color="green">store create|list</Text>
49
+ </Box>
50
+ <Text>Create or list stores</Text>
51
+ </Box>
34
52
  <Box>
35
- <Box width={16}>
53
+ <Box width={24}>
54
+ <Text color="green">version create|list</Text>
55
+ </Box>
56
+ <Text>Create or list versions</Text>
57
+ </Box>
58
+ <Box>
59
+ <Box width={24}>
60
+ <Text color="green">component create|list</Text>
61
+ </Box>
62
+ <Text>Create or list components</Text>
63
+ </Box>
64
+ <Box>
65
+ <Box width={24}>
66
+ <Text color="green">schema</Text>
67
+ </Box>
68
+ <Text>Introspect resource schemas (JSON Schema)</Text>
69
+ </Box>
70
+ <Box>
71
+ <Box width={24}>
72
+ <Text color="green">init</Text>
73
+ </Box>
74
+ <Text>Write store/version IDs to ollie.json</Text>
75
+ </Box>
76
+ <Box>
77
+ <Box width={24}>
36
78
  <Text color="green">help</Text>
37
79
  </Box>
38
80
  <Text>Show this help message</Text>
39
81
  </Box>
40
82
  <Box>
41
- <Box width={16}>
83
+ <Box width={24}>
42
84
  <Text color="green">version</Text>
43
85
  </Box>
44
86
  <Text>Show CLI version</Text>
@@ -46,33 +88,64 @@ export function HelpCommand() {
46
88
  </Box>
47
89
 
48
90
  <Box marginTop={1}>
49
- <Text bold>Start Options:</Text>
91
+ <Text bold>Global Flags:</Text>
50
92
  </Box>
51
93
  <Box marginLeft={2} flexDirection="column" gap={0}>
52
94
  <Box>
53
- <Box width={20}>
95
+ <Box width={24}>
96
+ <Text color="yellow">--output json, -o json</Text>
97
+ </Box>
98
+ <Text>Force JSON output (auto when piped)</Text>
99
+ </Box>
100
+ <Box>
101
+ <Box width={24}>
102
+ <Text color="yellow">--dry-run</Text>
103
+ </Box>
104
+ <Text>Validate without executing mutations</Text>
105
+ </Box>
106
+ <Box>
107
+ <Box width={24}>
108
+ <Text color="yellow">--fields a,b,c</Text>
109
+ </Box>
110
+ <Text>Limit output fields</Text>
111
+ </Box>
112
+ <Box>
113
+ <Box width={24}>
114
+ <Text color="yellow">--data {`'{...}'`}</Text>
115
+ </Box>
116
+ <Text>Raw JSON payload for mutations</Text>
117
+ </Box>
118
+ <Box>
119
+ <Box width={24}>
54
120
  <Text color="yellow">--stage, -s</Text>
55
121
  </Box>
56
122
  <Text>Config stage (loads ollie.{"{stage}"}.json)</Text>
57
123
  </Box>
58
124
  </Box>
59
125
 
60
- <Box marginTop={1}>
61
- <Text bold>Configuration:</Text>
62
- </Box>
63
- <Box marginLeft={2} flexDirection="column">
64
- <Text dimColor>ollie.json - Default config (prod)</Text>
65
- <Text dimColor>ollie.dev.json - Dev stage config</Text>
66
- <Text dimColor>ollie.{"{stage}"}.json - Custom stage config</Text>
67
- </Box>
68
-
69
126
  <Box marginTop={1}>
70
127
  <Text bold>Examples:</Text>
71
128
  </Box>
72
129
  <Box marginLeft={2} flexDirection="column">
73
130
  <Text dimColor>$ ollieshop login</Text>
74
- <Text dimColor>$ ollieshop start</Text>
75
131
  <Text dimColor>$ ollieshop start --stage dev</Text>
132
+ <Text dimColor>$ ollieshop whoami -o json</Text>
133
+ <Text dimColor>$ ollieshop schema store.create</Text>
134
+ <Text dimColor>
135
+ $ ollieshop store create --name "My Store" --platform vtex
136
+ --platform-store-id mystore
137
+ </Text>
138
+ <Text dimColor>
139
+ $ ollieshop store create --data{" "}
140
+ {
141
+ '\'{"name":"My Store","platform":"vtex","platformStoreId":"mystore"}\''
142
+ }{" "}
143
+ -o json
144
+ </Text>
145
+ <Text dimColor>
146
+ $ ollieshop version create --store-id UUID --name v1 --active
147
+ </Text>
148
+ <Text dimColor>$ ollieshop init --store-id UUID --version-id UUID</Text>
76
149
  </Box>
77
150
  </Box>
78
151
  );
@@ -0,0 +1,53 @@
1
+ import { saveConfig } from "../utils/config.js";
2
+ import { detectOutputFormat, outputResult } from "../utils/output.js";
3
+ import { type ParsedArgs, getFlag } from "../utils/parse-args.js";
4
+ import { validateRequired, validateUuid } from "../utils/validate.js";
5
+
6
+ export async function initCommand(parsed: ParsedArgs): Promise<void> {
7
+ const format = detectOutputFormat(parsed.global.output);
8
+
9
+ try {
10
+ const storeId = validateUuid(
11
+ validateRequired(getFlag(parsed.flags, "store-id"), "store-id"),
12
+ "store-id",
13
+ );
14
+
15
+ const versionIdRaw = getFlag(parsed.flags, "version-id");
16
+ const versionId = versionIdRaw
17
+ ? validateUuid(versionIdRaw, "version-id")
18
+ : undefined;
19
+
20
+ const stage = getFlag(parsed.flags, "stage", "s");
21
+
22
+ await saveConfig(
23
+ {
24
+ storeId,
25
+ ...(versionId ? { versionId } : {}),
26
+ },
27
+ { stage },
28
+ );
29
+
30
+ const fileName =
31
+ stage && stage !== "prod" ? `ollie.${stage}.json` : "ollie.json";
32
+
33
+ outputResult(
34
+ {
35
+ data: {
36
+ file: fileName,
37
+ storeId,
38
+ ...(versionId ? { versionId } : {}),
39
+ },
40
+ },
41
+ format,
42
+ parsed.global.fields,
43
+ );
44
+ } catch (err) {
45
+ outputResult(
46
+ {
47
+ error: { message: err instanceof Error ? err.message : String(err) },
48
+ },
49
+ format,
50
+ );
51
+ process.exit(1);
52
+ }
53
+ }
@@ -0,0 +1,34 @@
1
+ import { getJsonSchema, getSchemaNames } from "../core/schema.js";
2
+ import { detectOutputFormat } from "../utils/output.js";
3
+ import type { ParsedArgs } from "../utils/parse-args.js";
4
+
5
+ export async function schemaCommand(parsed: ParsedArgs): Promise<void> {
6
+ const format = detectOutputFormat(parsed.global.output);
7
+ const resourceName = parsed.subcommand || parsed.positional[0];
8
+
9
+ if (!resourceName) {
10
+ // List all available schemas
11
+ const names = getSchemaNames();
12
+ if (format === "json") {
13
+ process.stdout.write(`${JSON.stringify({ schemas: names })}\n`);
14
+ } else {
15
+ console.log("\x1b[1mAvailable schemas:\x1b[0m");
16
+ for (const name of names) {
17
+ const indent = name.includes(".") ? " " : " ";
18
+ console.log(`${indent}\x1b[32m${name}\x1b[0m`);
19
+ }
20
+ console.log("\nUsage: ollieshop schema <resource[.action]>");
21
+ }
22
+ return;
23
+ }
24
+
25
+ const schema = getJsonSchema(resourceName);
26
+ if (!schema) {
27
+ console.error(
28
+ `Unknown schema: ${resourceName}. Run \`ollieshop schema\` to see available schemas.`,
29
+ );
30
+ process.exit(1);
31
+ }
32
+
33
+ process.stdout.write(`${JSON.stringify(schema, null, 2)}\n`);
34
+ }
@@ -0,0 +1,105 @@
1
+ import { PLATFORM_VENDORS } from "../core/schema.js";
2
+ import { createStore, listStores } from "../core/store.js";
3
+ import {
4
+ detectOutputFormat,
5
+ outputDryRun,
6
+ outputResult,
7
+ } from "../utils/output.js";
8
+ import { type ParsedArgs, getFlag } from "../utils/parse-args.js";
9
+ import { getAuthenticatedClient } from "../utils/supabase.js";
10
+ import { validateEnum, validateRequired } from "../utils/validate.js";
11
+
12
+ export async function storeCommand(parsed: ParsedArgs): Promise<void> {
13
+ const sub = parsed.subcommand;
14
+ if (sub === "create") return storeCreateCommand(parsed);
15
+ if (sub === "list" || sub === "ls") return storeListCommand(parsed);
16
+
17
+ console.error(
18
+ `Unknown store subcommand: ${sub}. Use: store create | store list`,
19
+ );
20
+ process.exit(1);
21
+ }
22
+
23
+ async function storeCreateCommand(parsed: ParsedArgs): Promise<void> {
24
+ const format = detectOutputFormat(parsed.global.output);
25
+
26
+ try {
27
+ let input: {
28
+ name: string;
29
+ platform: string;
30
+ platformStoreId: string;
31
+ logo?: string;
32
+ settings?: string;
33
+ };
34
+
35
+ if (parsed.global.data) {
36
+ // Raw JSON mode
37
+ const raw = JSON.parse(parsed.global.data);
38
+ input = {
39
+ name: validateRequired(raw.name, "name"),
40
+ platform: validateEnum(raw.platform, PLATFORM_VENDORS, "platform"),
41
+ platformStoreId: validateRequired(
42
+ raw.platformStoreId,
43
+ "platformStoreId",
44
+ ),
45
+ logo: raw.logo,
46
+ settings: raw.settings,
47
+ };
48
+ } else {
49
+ // Flag mode
50
+ input = {
51
+ name: validateRequired(getFlag(parsed.flags, "name", "n"), "name"),
52
+ platform: validateEnum(
53
+ validateRequired(getFlag(parsed.flags, "platform", "p"), "platform"),
54
+ PLATFORM_VENDORS,
55
+ "platform",
56
+ ),
57
+ platformStoreId: validateRequired(
58
+ getFlag(parsed.flags, "platform-store-id"),
59
+ "platform-store-id",
60
+ ),
61
+ logo: getFlag(parsed.flags, "logo"),
62
+ settings: getFlag(parsed.flags, "settings"),
63
+ };
64
+ }
65
+
66
+ if (parsed.global.dryRun) {
67
+ outputDryRun("store.create", input, format);
68
+ return;
69
+ }
70
+
71
+ const client = await getAuthenticatedClient();
72
+ const result = await createStore(client, input);
73
+
74
+ outputResult(result, format, parsed.global.fields);
75
+ if (result.error) process.exit(1);
76
+ } catch (err) {
77
+ outputResult(
78
+ {
79
+ error: { message: err instanceof Error ? err.message : String(err) },
80
+ },
81
+ format,
82
+ );
83
+ process.exit(1);
84
+ }
85
+ }
86
+
87
+ async function storeListCommand(parsed: ParsedArgs): Promise<void> {
88
+ const format = detectOutputFormat(parsed.global.output);
89
+
90
+ try {
91
+ const client = await getAuthenticatedClient();
92
+ const result = await listStores(client);
93
+
94
+ outputResult(result, format, parsed.global.fields);
95
+ if (result.error) process.exit(1);
96
+ } catch (err) {
97
+ outputResult(
98
+ {
99
+ error: { message: err instanceof Error ? err.message : String(err) },
100
+ },
101
+ format,
102
+ );
103
+ process.exit(1);
104
+ }
105
+ }
@@ -0,0 +1,100 @@
1
+ import { createVersion, listVersions } from "../core/version.js";
2
+ import {
3
+ detectOutputFormat,
4
+ outputDryRun,
5
+ outputResult,
6
+ } from "../utils/output.js";
7
+ import { type ParsedArgs, getBoolFlag, getFlag } from "../utils/parse-args.js";
8
+ import { getAuthenticatedClient } from "../utils/supabase.js";
9
+ import { validateRequired, validateUuid } from "../utils/validate.js";
10
+
11
+ export async function versionCommand(parsed: ParsedArgs): Promise<void> {
12
+ const sub = parsed.subcommand;
13
+ if (sub === "create") return versionCreateCommand(parsed);
14
+ if (sub === "list" || sub === "ls") return versionListCommand(parsed);
15
+
16
+ console.error(
17
+ `Unknown version subcommand: ${sub}. Use: version create | version list`,
18
+ );
19
+ process.exit(1);
20
+ }
21
+
22
+ async function versionCreateCommand(parsed: ParsedArgs): Promise<void> {
23
+ const format = detectOutputFormat(parsed.global.output);
24
+
25
+ try {
26
+ let input: {
27
+ storeId: string;
28
+ name: string;
29
+ active?: boolean;
30
+ default?: boolean;
31
+ template?: string | null;
32
+ };
33
+
34
+ if (parsed.global.data) {
35
+ const raw = JSON.parse(parsed.global.data);
36
+ input = {
37
+ storeId: validateUuid(raw.storeId, "storeId"),
38
+ name: validateRequired(raw.name, "name"),
39
+ active: raw.active ?? false,
40
+ default: raw.default ?? false,
41
+ template: raw.template ?? null,
42
+ };
43
+ } else {
44
+ input = {
45
+ storeId: validateUuid(
46
+ validateRequired(getFlag(parsed.flags, "store-id"), "store-id"),
47
+ "store-id",
48
+ ),
49
+ name: validateRequired(getFlag(parsed.flags, "name", "n"), "name"),
50
+ active: getBoolFlag(parsed.flags, "active"),
51
+ default: getBoolFlag(parsed.flags, "default"),
52
+ template: getFlag(parsed.flags, "template") ?? null,
53
+ };
54
+ }
55
+
56
+ if (parsed.global.dryRun) {
57
+ outputDryRun("version.create", input as Record<string, unknown>, format);
58
+ return;
59
+ }
60
+
61
+ const client = await getAuthenticatedClient();
62
+ const result = await createVersion(client, input);
63
+
64
+ outputResult(result, format, parsed.global.fields);
65
+ if (result.error) process.exit(1);
66
+ } catch (err) {
67
+ outputResult(
68
+ {
69
+ error: { message: err instanceof Error ? err.message : String(err) },
70
+ },
71
+ format,
72
+ );
73
+ process.exit(1);
74
+ }
75
+ }
76
+
77
+ async function versionListCommand(parsed: ParsedArgs): Promise<void> {
78
+ const format = detectOutputFormat(parsed.global.output);
79
+
80
+ try {
81
+ const storeId = validateUuid(
82
+ validateRequired(getFlag(parsed.flags, "store-id"), "store-id"),
83
+ "store-id",
84
+ );
85
+
86
+ const client = await getAuthenticatedClient();
87
+ const result = await listVersions(client, storeId);
88
+
89
+ outputResult(result, format, parsed.global.fields);
90
+ if (result.error) process.exit(1);
91
+ } catch (err) {
92
+ outputResult(
93
+ {
94
+ error: { message: err instanceof Error ? err.message : String(err) },
95
+ },
96
+ format,
97
+ );
98
+ process.exit(1);
99
+ }
100
+ }
@@ -0,0 +1,28 @@
1
+ import { getCurrentUser } from "../utils/auth.js";
2
+ import { detectOutputFormat, outputResult } from "../utils/output.js";
3
+ import type { ParsedArgs } from "../utils/parse-args.js";
4
+
5
+ export async function whoamiCommand(parsed: ParsedArgs): Promise<void> {
6
+ const format = detectOutputFormat(parsed.global.output);
7
+
8
+ const user = await getCurrentUser();
9
+ if (!user) {
10
+ outputResult(
11
+ {
12
+ error: { message: "Not logged in. Run `ollieshop login`." },
13
+ },
14
+ format,
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ outputResult(
20
+ {
21
+ data: {
22
+ email: user.email,
23
+ },
24
+ },
25
+ format,
26
+ parsed.global.fields,
27
+ );
28
+ }
@@ -0,0 +1,76 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ import { componentCreateSchema } from "./schema.js";
3
+
4
+ export interface CreateComponentInput {
5
+ versionId: string;
6
+ name: string;
7
+ slot: string;
8
+ active?: boolean;
9
+ props?: Record<string, unknown> | null;
10
+ }
11
+
12
+ export interface ComponentRecord {
13
+ id: string;
14
+ name: string;
15
+ slot: string | null;
16
+ active: boolean;
17
+ version_id: string;
18
+ props: Record<string, unknown> | null;
19
+ created_at: string;
20
+ versions?: { id: string; name: string };
21
+ }
22
+
23
+ export async function createComponent(
24
+ client: SupabaseClient,
25
+ input: CreateComponentInput,
26
+ ): Promise<{ data?: { id: string }; error?: { message: string } }> {
27
+ const parsed = componentCreateSchema.safeParse(input);
28
+ if (!parsed.success) {
29
+ return {
30
+ error: { message: parsed.error.issues.map((i) => i.message).join("; ") },
31
+ };
32
+ }
33
+
34
+ const { data, error } = await client
35
+ .from("components")
36
+ .insert({
37
+ name: parsed.data.name,
38
+ slot: parsed.data.slot,
39
+ active: parsed.data.active,
40
+ version_id: parsed.data.versionId,
41
+ props: parsed.data.props,
42
+ })
43
+ .select("id")
44
+ .single();
45
+
46
+ if (error) {
47
+ return { error: { message: error.message } };
48
+ }
49
+
50
+ return { data: { id: data.id } };
51
+ }
52
+
53
+ export async function listComponents(
54
+ client: SupabaseClient,
55
+ storeId: string,
56
+ versionId?: string,
57
+ ): Promise<{ data?: ComponentRecord[]; error?: { message: string } }> {
58
+ let query = client
59
+ .from("components")
60
+ .select(
61
+ "id, name, slot, active, version_id, props, created_at, versions!inner(id, name)",
62
+ )
63
+ .eq("versions.store_id", storeId);
64
+
65
+ if (versionId) {
66
+ query = query.eq("versions.id", versionId);
67
+ }
68
+
69
+ const { data, error } = await query;
70
+
71
+ if (error) {
72
+ return { error: { message: error.message } };
73
+ }
74
+
75
+ return { data: (data ?? []) as unknown as ComponentRecord[] };
76
+ }