@ollie-shop/cli 1.1.0 → 1.2.2

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/dist/index.js CHANGED
@@ -50,6 +50,18 @@ function HelpCommand() {
50
50
  /* @__PURE__ */ jsx(Box, { width: 24, children: /* @__PURE__ */ jsx(Text, { color: "green", children: "component create|list" }) }),
51
51
  /* @__PURE__ */ jsx(Text, { children: "Create or list components" })
52
52
  ] }),
53
+ /* @__PURE__ */ jsxs(Box, { children: [
54
+ /* @__PURE__ */ jsx(Box, { width: 24, children: /* @__PURE__ */ jsx(Text, { color: "green", children: "function create|list" }) }),
55
+ /* @__PURE__ */ jsx(Text, { children: "Create or list functions" })
56
+ ] }),
57
+ /* @__PURE__ */ jsxs(Box, { children: [
58
+ /* @__PURE__ */ jsx(Box, { width: 24, children: /* @__PURE__ */ jsx(Text, { color: "green", children: "deploy" }) }),
59
+ /* @__PURE__ */ jsx(Text, { children: "Bundle and upload a component/function build" })
60
+ ] }),
61
+ /* @__PURE__ */ jsxs(Box, { children: [
62
+ /* @__PURE__ */ jsx(Box, { width: 24, children: /* @__PURE__ */ jsx(Text, { color: "green", children: "status" }) }),
63
+ /* @__PURE__ */ jsx(Text, { children: "Check or poll a build status" })
64
+ ] }),
53
65
  /* @__PURE__ */ jsxs(Box, { children: [
54
66
  /* @__PURE__ */ jsx(Box, { width: 24, children: /* @__PURE__ */ jsx(Text, { color: "green", children: "schema" }) }),
55
67
  /* @__PURE__ */ jsx(Text, { children: "Introspect resource schemas (JSON Schema)" })
@@ -112,7 +124,10 @@ function HelpCommand() {
112
124
  "-o json"
113
125
  ] }),
114
126
  /* @__PURE__ */ jsx(Text, { dimColor: true, children: "$ ollieshop version create --store-id UUID --name v1 --active" }),
115
- /* @__PURE__ */ jsx(Text, { dimColor: true, children: "$ ollieshop init --store-id UUID --version-id UUID" })
127
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: "$ ollieshop init --store-id UUID --version-id UUID" }),
128
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: "$ ollieshop function create --version-id UUID --name myHook" }),
129
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: "$ ollieshop deploy --component-id UUID --name FreeShippingBar --wait" }),
130
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: "$ ollieshop status --build-id BUILD_ID --wait -o json" })
116
131
  ] })
117
132
  ] });
118
133
  }
@@ -1174,129 +1189,60 @@ function UnknownCommand({ command }) {
1174
1189
  ] });
1175
1190
  }
1176
1191
 
1177
- // src/core/schema.ts
1178
- import { z as z2 } from "zod";
1179
- import { zodToJsonSchema } from "zod-to-json-schema";
1180
- var PLATFORM_VENDORS = ["vtex", "shopify", "vnda", "custom"];
1181
- var storeCreateSchema = z2.object({
1182
- name: z2.string().min(1).describe("Store display name"),
1183
- platform: z2.enum(PLATFORM_VENDORS).describe("E-commerce platform vendor"),
1184
- platformStoreId: z2.string().min(1).describe("Platform-specific store identifier (e.g. account name)"),
1185
- logo: z2.string().url().optional().describe("Store logo URL"),
1186
- settings: z2.string().optional().describe("JSON settings string")
1187
- });
1188
- var storeListSchema = z2.object({}).describe("No parameters required");
1189
- var versionCreateSchema = z2.object({
1190
- storeId: z2.string().uuid().describe("Parent store UUID"),
1191
- name: z2.string().min(1).describe("Version name (e.g. v1, main)"),
1192
- active: z2.boolean().default(false).describe("Whether version is active"),
1193
- default: z2.boolean().default(false).describe("Whether this is the default version"),
1194
- template: z2.string().nullable().default(null).describe("Template name or null")
1195
- });
1196
- var versionListSchema = z2.object({
1197
- storeId: z2.string().uuid().describe("Store UUID to list versions for")
1198
- });
1199
- var componentCreateSchema = z2.object({
1200
- versionId: z2.string().uuid().describe("Parent version UUID"),
1201
- name: z2.string().min(1).describe("Component name (e.g. FreeShippingBar)"),
1202
- slot: z2.string().min(1).describe(
1203
- "Target slot (e.g. cart_header_full_page, shipping_address_details_form)"
1204
- ),
1205
- active: z2.boolean().default(true).describe("Whether component is active"),
1206
- props: z2.record(z2.unknown()).nullable().default(null).describe("Default component props as JSON object")
1207
- });
1208
- var componentListSchema = z2.object({
1209
- storeId: z2.string().uuid().describe("Store UUID"),
1210
- versionId: z2.string().uuid().optional().describe("Optional version UUID to filter by")
1211
- });
1212
- var functionCreateSchema = z2.object({
1213
- versionId: z2.string().uuid().describe("Parent version UUID"),
1214
- name: z2.string().min(1).describe("Function name"),
1215
- trigger: z2.string().min(1).describe("Function trigger (e.g. beforePayment, afterShipping)"),
1216
- active: z2.boolean().default(true).describe("Whether function is active")
1217
- });
1218
- var functionListSchema = z2.object({
1219
- versionId: z2.string().uuid().describe("Version UUID to list functions for")
1220
- });
1221
- var schemas = {
1222
- store: {
1223
- create: storeCreateSchema,
1224
- list: storeListSchema
1225
- },
1226
- version: {
1227
- create: versionCreateSchema,
1228
- list: versionListSchema
1229
- },
1230
- component: {
1231
- create: componentCreateSchema,
1232
- list: componentListSchema
1233
- },
1234
- function: {
1235
- create: functionCreateSchema,
1236
- list: functionListSchema
1237
- }
1238
- };
1239
- function getSchemaNames() {
1240
- const names = [];
1241
- for (const [resource, actions] of Object.entries(schemas)) {
1242
- names.push(resource);
1243
- for (const action of Object.keys(actions)) {
1244
- names.push(`${resource}.${action}`);
1245
- }
1192
+ // src/core/business-rule.ts
1193
+ var SELECT_FIELDS = "id, store_id, title, content, previous_content, versions_ids, components_ids, functions_ids, status, code_updated, created_at, updated_at";
1194
+ async function listBusinessRules(client, filters = {}) {
1195
+ let query = client.from("business_rules").select(SELECT_FIELDS).order("created_at", { ascending: false });
1196
+ if (filters.store_id !== void 0) {
1197
+ query = query.eq("store_id", filters.store_id);
1198
+ }
1199
+ if (filters.version_id !== void 0) {
1200
+ query = query.filter(
1201
+ "versions_ids",
1202
+ "cs",
1203
+ JSON.stringify([filters.version_id])
1204
+ );
1246
1205
  }
1247
- return names;
1248
- }
1249
- function getJsonSchema(name) {
1250
- const parts = name.split(".");
1251
- const resource = parts[0];
1252
- const action = parts[1];
1253
- if (!resource || !schemas[resource]) return null;
1254
- if (action) {
1255
- const schema = schemas[resource][action];
1256
- if (!schema) return null;
1257
- return zodToJsonSchema(schema, { name: `${resource}.${action}` });
1206
+ if (filters.code_updated !== void 0) {
1207
+ query = query.eq("code_updated", filters.code_updated);
1258
1208
  }
1259
- const result = {};
1260
- for (const [actionName, schema] of Object.entries(schemas[resource])) {
1261
- result[actionName] = zodToJsonSchema(schema, {
1262
- name: `${resource}.${actionName}`
1263
- });
1209
+ const { data, error } = await query;
1210
+ if (error) {
1211
+ return { error: { message: error.message } };
1264
1212
  }
1265
- return result;
1213
+ return { data };
1266
1214
  }
1267
-
1268
- // src/core/component.ts
1269
- async function createComponent(client, input) {
1270
- const parsed2 = componentCreateSchema.safeParse(input);
1271
- if (!parsed2.success) {
1272
- return {
1273
- error: { message: parsed2.error.issues.map((i) => i.message).join("; ") }
1274
- };
1275
- }
1276
- const { data, error } = await client.from("components").insert({
1277
- name: parsed2.data.name,
1278
- slot: parsed2.data.slot,
1279
- active: parsed2.data.active,
1280
- version_id: parsed2.data.versionId,
1281
- props: parsed2.data.props
1282
- }).select("id").single();
1215
+ async function getBusinessRule(client, id) {
1216
+ const { data, error } = await client.from("business_rules").select(SELECT_FIELDS).eq("id", id).single();
1283
1217
  if (error) {
1284
1218
  return { error: { message: error.message } };
1285
1219
  }
1286
- return { data: { id: data.id } };
1220
+ return { data };
1287
1221
  }
1288
- async function listComponents(client, storeId, versionId) {
1289
- let query = client.from("components").select(
1290
- "id, name, slot, active, version_id, props, created_at, versions!inner(id, name)"
1291
- ).eq("versions.store_id", storeId);
1292
- if (versionId) {
1293
- query = query.eq("versions.id", versionId);
1222
+ async function updateBusinessRule(client, id, input) {
1223
+ const { data: current, error: fetchError } = await client.from("business_rules").select("content").eq("id", id).single();
1224
+ if (fetchError) {
1225
+ return { error: { message: fetchError.message } };
1294
1226
  }
1295
- const { data, error } = await query;
1227
+ const updatePayload = {
1228
+ previous_content: current.content,
1229
+ content: input.content,
1230
+ code_updated: false
1231
+ };
1232
+ if (input.versions_ids !== void 0) {
1233
+ updatePayload.versions_ids = input.versions_ids;
1234
+ }
1235
+ if (input.components_ids !== void 0) {
1236
+ updatePayload.components_ids = input.components_ids;
1237
+ }
1238
+ if (input.functions_ids !== void 0) {
1239
+ updatePayload.functions_ids = input.functions_ids;
1240
+ }
1241
+ const { data, error } = await client.from("business_rules").update(updatePayload).eq("id", id).select("id").single();
1296
1242
  if (error) {
1297
1243
  return { error: { message: error.message } };
1298
1244
  }
1299
- return { data: data ?? [] };
1245
+ return { data: { id: data.id } };
1300
1246
  }
1301
1247
 
1302
1248
  // src/utils/output.ts
@@ -1451,22 +1397,13 @@ function getBoolFlag(flags, ...names) {
1451
1397
 
1452
1398
  // src/utils/supabase.ts
1453
1399
  import { createClient } from "@supabase/supabase-js";
1454
- function requireEnv(name) {
1455
- const value = process.env[name];
1456
- if (!value) {
1457
- throw new Error(
1458
- `Missing required environment variable: ${name}. Set it in your .env file or shell.`
1459
- );
1460
- }
1461
- return value;
1462
- }
1463
1400
  async function getAuthenticatedClient() {
1464
1401
  const credentials = await getCredentials();
1465
1402
  if (!credentials) {
1466
1403
  throw new Error("Not authenticated. Run `ollieshop login` first.");
1467
1404
  }
1468
- const supabaseUrl = requireEnv("OLLIE_SUPABASE_URL");
1469
- const supabaseAnonKey = requireEnv("OLLIE_SUPABASE_ANON_KEY");
1405
+ const supabaseUrl = process.env.OLLIE_SUPABASE_URL || "https://aazahtmqrhjqsyqoqdkm.supabase.co";
1406
+ const supabaseAnonKey = process.env.OLLIE_SUPABASE_ANON_KEY || "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhemFodG1xcmhqcXN5cW9xZGttIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDg2MzEwOTcsImV4cCI6MjA2NDIwNzA5N30.VuAbAyjDe0HcL09SZtQ-UmP1o7Z6qwGuOtvfFhnyAcM";
1470
1407
  const client = createClient(supabaseUrl, supabaseAnonKey, {
1471
1408
  auth: {
1472
1409
  autoRefreshToken: false,
@@ -1479,6 +1416,16 @@ async function getAuthenticatedClient() {
1479
1416
  });
1480
1417
  return client;
1481
1418
  }
1419
+ function getBuilderUrl() {
1420
+ return process.env.OLLIE_BUILDER_URL || "";
1421
+ }
1422
+ async function getAuthToken() {
1423
+ const credentials = await getCredentials();
1424
+ if (!credentials) {
1425
+ throw new Error("Not authenticated. Run `ollieshop login` first.");
1426
+ }
1427
+ return credentials.accessToken;
1428
+ }
1482
1429
  async function getOrganizationId(client) {
1483
1430
  const { data: org, error } = await client.from("organizations").select("id").order("created_at", { ascending: true }).limit(1).maybeSingle();
1484
1431
  if (error) {
@@ -1525,52 +1472,71 @@ function validateRequired(value, name) {
1525
1472
  }
1526
1473
  return rejectControlChars(value.trim(), name);
1527
1474
  }
1475
+ function validateInteger(value, name, opts) {
1476
+ const n = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : Number.NaN;
1477
+ if (!Number.isFinite(n) || !Number.isInteger(n)) {
1478
+ throw new Error(`Invalid ${name}: "${String(value)}". Must be an integer.`);
1479
+ }
1480
+ if (opts?.min !== void 0 && n < opts.min) {
1481
+ throw new Error(`Invalid ${name}: ${n}. Must be >= ${opts.min}.`);
1482
+ }
1483
+ return n;
1484
+ }
1485
+ function validateTriggerUrl(value, name) {
1486
+ rejectControlChars(value, name);
1487
+ const trimmed = value.trim();
1488
+ if (trimmed === "") {
1489
+ throw new Error(
1490
+ `Invalid ${name}: must be a non-empty absolute http(s) URL or a relative path starting with "/".`
1491
+ );
1492
+ }
1493
+ if (trimmed.startsWith("/")) {
1494
+ return trimmed;
1495
+ }
1496
+ try {
1497
+ const parsed2 = new URL(trimmed);
1498
+ if (parsed2.protocol !== "http:" && parsed2.protocol !== "https:") {
1499
+ throw new Error("unsupported protocol");
1500
+ }
1501
+ return trimmed;
1502
+ } catch {
1503
+ throw new Error(
1504
+ `Invalid ${name}: "${value}". Must be an absolute http(s) URL or a relative path starting with "/".`
1505
+ );
1506
+ }
1507
+ }
1528
1508
 
1529
- // src/commands/component-cmd.ts
1530
- async function componentCommand(parsed2) {
1509
+ // src/commands/business-rule-cmd.ts
1510
+ async function businessRuleCommand(parsed2) {
1531
1511
  const sub = parsed2.subcommand;
1532
- if (sub === "create") return componentCreateCommand(parsed2);
1533
- if (sub === "list" || sub === "ls") return componentListCommand(parsed2);
1512
+ if (sub === "list" || sub === "ls") return businessRuleListCommand(parsed2);
1513
+ if (sub === "get") return businessRuleGetCommand(parsed2);
1514
+ if (sub === "update") return businessRuleUpdateCommand(parsed2);
1534
1515
  console.error(
1535
- `Unknown component subcommand: ${sub}. Use: component create | component list`
1516
+ `Unknown business-rule subcommand: ${sub}. Use: business-rule list | business-rule get | business-rule update`
1536
1517
  );
1537
1518
  process.exit(1);
1538
1519
  }
1539
- async function componentCreateCommand(parsed2) {
1520
+ async function businessRuleListCommand(parsed2) {
1540
1521
  const format = detectOutputFormat(parsed2.global.output);
1541
1522
  try {
1542
- let input;
1543
- if (parsed2.global.data) {
1544
- const raw = JSON.parse(parsed2.global.data);
1545
- input = {
1546
- versionId: validateUuid(raw.versionId, "versionId"),
1547
- name: validateRequired(raw.name, "name"),
1548
- slot: validateRequired(raw.slot, "slot"),
1549
- active: raw.active ?? true,
1550
- props: raw.props ?? null
1551
- };
1552
- } else {
1553
- input = {
1554
- versionId: validateUuid(
1555
- validateRequired(getFlag(parsed2.flags, "version-id"), "version-id"),
1556
- "version-id"
1557
- ),
1558
- name: validateRequired(getFlag(parsed2.flags, "name", "n"), "name"),
1559
- slot: validateRequired(getFlag(parsed2.flags, "slot", "s"), "slot"),
1560
- active: getBoolFlag(parsed2.flags, "active") || !("active" in parsed2.flags),
1561
- props: null
1562
- };
1563
- }
1564
- if (parsed2.global.dryRun) {
1565
- outputDryRun(
1566
- "component.create",
1567
- input,
1568
- format
1569
- );
1570
- return;
1523
+ const storeId = getFlag(parsed2.flags, "store-id");
1524
+ const versionId = getFlag(parsed2.flags, "version-id");
1525
+ const codeUpdatedRaw = parsed2.flags["code-updated"];
1526
+ let codeUpdated;
1527
+ if (codeUpdatedRaw === "true" || codeUpdatedRaw === true) {
1528
+ codeUpdated = true;
1529
+ } else if (codeUpdatedRaw === "false") {
1530
+ codeUpdated = false;
1571
1531
  }
1532
+ if (storeId !== void 0) validateUuid(storeId, "store-id");
1533
+ if (versionId !== void 0) validateUuid(versionId, "version-id");
1572
1534
  const client = await getAuthenticatedClient();
1573
- const result = await createComponent(client, input);
1535
+ const result = await listBusinessRules(client, {
1536
+ store_id: storeId,
1537
+ version_id: versionId,
1538
+ code_updated: codeUpdated
1539
+ });
1574
1540
  outputResult(result, format, parsed2.global.fields);
1575
1541
  if (result.error) process.exit(1);
1576
1542
  } catch (err) {
@@ -1583,17 +1549,15 @@ async function componentCreateCommand(parsed2) {
1583
1549
  process.exit(1);
1584
1550
  }
1585
1551
  }
1586
- async function componentListCommand(parsed2) {
1552
+ async function businessRuleGetCommand(parsed2) {
1587
1553
  const format = detectOutputFormat(parsed2.global.output);
1588
1554
  try {
1589
- const storeId = validateUuid(
1590
- validateRequired(getFlag(parsed2.flags, "store-id"), "store-id"),
1591
- "store-id"
1555
+ const id = validateUuid(
1556
+ validateRequired(getFlag(parsed2.flags, "id"), "id"),
1557
+ "id"
1592
1558
  );
1593
- const versionId = getFlag(parsed2.flags, "version-id");
1594
- if (versionId) validateUuid(versionId, "version-id");
1595
1559
  const client = await getAuthenticatedClient();
1596
- const result = await listComponents(client, storeId, versionId);
1560
+ const result = await getBusinessRule(client, id);
1597
1561
  outputResult(result, format, parsed2.global.fields);
1598
1562
  if (result.error) process.exit(1);
1599
1563
  } catch (err) {
@@ -1606,37 +1570,50 @@ async function componentListCommand(parsed2) {
1606
1570
  process.exit(1);
1607
1571
  }
1608
1572
  }
1609
-
1610
- // src/commands/init-cmd.ts
1611
- async function initCommand(parsed2) {
1573
+ async function businessRuleUpdateCommand(parsed2) {
1612
1574
  const format = detectOutputFormat(parsed2.global.output);
1613
1575
  try {
1614
- const storeId = validateUuid(
1615
- validateRequired(getFlag(parsed2.flags, "store-id"), "store-id"),
1616
- "store-id"
1617
- );
1618
- const versionIdRaw = getFlag(parsed2.flags, "version-id");
1619
- const versionId = versionIdRaw ? validateUuid(versionIdRaw, "version-id") : void 0;
1620
- const stage = getFlag(parsed2.flags, "stage", "s");
1621
- await saveConfig(
1622
- {
1623
- storeId,
1624
- ...versionId ? { versionId } : {}
1625
- },
1626
- { stage }
1627
- );
1628
- const fileName = stage && stage !== "prod" ? `ollie.${stage}.json` : "ollie.json";
1629
- outputResult(
1630
- {
1631
- data: {
1632
- file: fileName,
1633
- storeId,
1634
- ...versionId ? { versionId } : {}
1635
- }
1636
- },
1637
- format,
1638
- parsed2.global.fields
1639
- );
1576
+ let id;
1577
+ let input;
1578
+ if (parsed2.global.data) {
1579
+ const raw = JSON.parse(parsed2.global.data);
1580
+ id = validateUuid(validateRequired(raw.id, "id"), "id");
1581
+ input = {
1582
+ content: validateRequired(raw.content, "content"),
1583
+ versions_ids: raw.versionsIds ?? void 0,
1584
+ components_ids: raw.componentsIds ?? void 0,
1585
+ functions_ids: raw.functionsIds ?? void 0
1586
+ };
1587
+ } else {
1588
+ id = validateUuid(
1589
+ validateRequired(getFlag(parsed2.flags, "id"), "id"),
1590
+ "id"
1591
+ );
1592
+ const versionsIdsRaw = getFlag(parsed2.flags, "versions-ids");
1593
+ const componentsIdsRaw = getFlag(parsed2.flags, "components-ids");
1594
+ const functionsIdsRaw = getFlag(parsed2.flags, "functions-ids");
1595
+ input = {
1596
+ content: validateRequired(
1597
+ getFlag(parsed2.flags, "content", "c"),
1598
+ "content"
1599
+ ),
1600
+ versions_ids: versionsIdsRaw ? JSON.parse(versionsIdsRaw) : void 0,
1601
+ components_ids: componentsIdsRaw ? JSON.parse(componentsIdsRaw) : void 0,
1602
+ functions_ids: functionsIdsRaw ? JSON.parse(functionsIdsRaw) : void 0
1603
+ };
1604
+ }
1605
+ if (parsed2.global.dryRun) {
1606
+ outputDryRun(
1607
+ "business-rule.update",
1608
+ { id, ...input },
1609
+ format
1610
+ );
1611
+ return;
1612
+ }
1613
+ const client = await getAuthenticatedClient();
1614
+ const result = await updateBusinessRule(client, id, input);
1615
+ outputResult(result, format, parsed2.global.fields);
1616
+ if (result.error) process.exit(1);
1640
1617
  } catch (err) {
1641
1618
  outputResult(
1642
1619
  {
@@ -1648,17 +1625,611 @@ async function initCommand(parsed2) {
1648
1625
  }
1649
1626
  }
1650
1627
 
1651
- // src/commands/schema-cmd.ts
1652
- async function schemaCommand(parsed2) {
1653
- const format = detectOutputFormat(parsed2.global.output);
1654
- const resourceName = parsed2.subcommand || parsed2.positional[0];
1655
- if (!resourceName) {
1656
- const names = getSchemaNames();
1657
- if (format === "json") {
1658
- process.stdout.write(`${JSON.stringify({ schemas: names })}
1659
- `);
1660
- } else {
1661
- console.log("\x1B[1mAvailable schemas:\x1B[0m");
1628
+ // src/core/schema.ts
1629
+ import { z as z2 } from "zod";
1630
+ import { zodToJsonSchema } from "zod-to-json-schema";
1631
+ var PLATFORM_VENDORS = ["vtex", "shopify", "vnda", "custom"];
1632
+ var storeCreateSchema = z2.object({
1633
+ name: z2.string().min(1).describe("Store display name"),
1634
+ platform: z2.enum(PLATFORM_VENDORS).describe("E-commerce platform vendor"),
1635
+ platformStoreId: z2.string().min(1).describe("Platform-specific store identifier (e.g. account name)"),
1636
+ logo: z2.string().url().optional().describe("Store logo URL"),
1637
+ settings: z2.string().optional().describe("JSON settings string")
1638
+ });
1639
+ var storeListSchema = z2.object({}).describe("No parameters required");
1640
+ var versionCreateSchema = z2.object({
1641
+ storeId: z2.string().uuid().describe("Parent store UUID"),
1642
+ name: z2.string().min(1).describe("Version name (e.g. v1, main)"),
1643
+ active: z2.boolean().default(false).describe("Whether version is active"),
1644
+ default: z2.boolean().default(false).describe("Whether this is the default version"),
1645
+ template: z2.string().nullable().default(null).describe("Template name or null")
1646
+ });
1647
+ var versionListSchema = z2.object({
1648
+ storeId: z2.string().uuid().describe("Store UUID to list versions for")
1649
+ });
1650
+ var componentCreateSchema = z2.object({
1651
+ versionId: z2.string().uuid().describe("Parent version UUID"),
1652
+ name: z2.string().min(1).describe("Component name (e.g. FreeShippingBar)"),
1653
+ slot: z2.string().min(1).describe(
1654
+ "Target slot (e.g. cart_header_full_page, shipping_address_details_form)"
1655
+ ),
1656
+ active: z2.boolean().default(true).describe("Whether component is active"),
1657
+ props: z2.record(z2.unknown()).nullable().default(null).describe("Default component props as JSON object")
1658
+ });
1659
+ var componentListSchema = z2.object({
1660
+ storeId: z2.string().uuid().describe("Store UUID"),
1661
+ versionId: z2.string().uuid().optional().describe("Optional version UUID to filter by")
1662
+ });
1663
+ var functionCreateSchema = z2.object({
1664
+ versionId: z2.string().uuid().describe("Parent version UUID"),
1665
+ name: z2.string().min(1).describe("Function name"),
1666
+ trigger: z2.string().min(1).optional().describe(
1667
+ "Function trigger URL \u2014 absolute http(s) URL or relative path starting with /"
1668
+ ),
1669
+ active: z2.boolean().default(false).describe("Whether function is active (default: false)"),
1670
+ onError: z2.enum(["throw", "skip"]).optional().describe("Error handling: throw (default) or skip"),
1671
+ priority: z2.number().int().min(0).optional().describe("Execution order priority (default: 0)")
1672
+ });
1673
+ var functionListSchema = z2.object({
1674
+ versionId: z2.string().uuid().describe("Version UUID to list functions for")
1675
+ });
1676
+ var schemas = {
1677
+ store: {
1678
+ create: storeCreateSchema,
1679
+ list: storeListSchema
1680
+ },
1681
+ version: {
1682
+ create: versionCreateSchema,
1683
+ list: versionListSchema
1684
+ },
1685
+ component: {
1686
+ create: componentCreateSchema,
1687
+ list: componentListSchema
1688
+ },
1689
+ function: {
1690
+ create: functionCreateSchema,
1691
+ list: functionListSchema
1692
+ }
1693
+ };
1694
+ function getSchemaNames() {
1695
+ const names = [];
1696
+ for (const [resource, actions] of Object.entries(schemas)) {
1697
+ names.push(resource);
1698
+ for (const action of Object.keys(actions)) {
1699
+ names.push(`${resource}.${action}`);
1700
+ }
1701
+ }
1702
+ return names;
1703
+ }
1704
+ function getJsonSchema(name) {
1705
+ const parts = name.split(".");
1706
+ const resource = parts[0];
1707
+ const action = parts[1];
1708
+ if (!resource || !schemas[resource]) return null;
1709
+ if (action) {
1710
+ const schema = schemas[resource][action];
1711
+ if (!schema) return null;
1712
+ return zodToJsonSchema(schema, { name: `${resource}.${action}` });
1713
+ }
1714
+ const result = {};
1715
+ for (const [actionName, schema] of Object.entries(schemas[resource])) {
1716
+ result[actionName] = zodToJsonSchema(schema, {
1717
+ name: `${resource}.${actionName}`
1718
+ });
1719
+ }
1720
+ return result;
1721
+ }
1722
+
1723
+ // src/core/component.ts
1724
+ async function createComponent(client, input) {
1725
+ const parsed2 = componentCreateSchema.safeParse(input);
1726
+ if (!parsed2.success) {
1727
+ return {
1728
+ error: { message: parsed2.error.issues.map((i) => i.message).join("; ") }
1729
+ };
1730
+ }
1731
+ const { data, error } = await client.from("components").insert({
1732
+ name: parsed2.data.name,
1733
+ slot: parsed2.data.slot,
1734
+ active: parsed2.data.active,
1735
+ version_id: parsed2.data.versionId,
1736
+ props: parsed2.data.props
1737
+ }).select("id").single();
1738
+ if (error) {
1739
+ return { error: { message: error.message } };
1740
+ }
1741
+ return { data: { id: data.id } };
1742
+ }
1743
+ async function listComponents(client, storeId, versionId) {
1744
+ let query = client.from("components").select(
1745
+ "id, name, slot, active, version_id, props, created_at, versions!inner(id, name)"
1746
+ ).eq("versions.store_id", storeId);
1747
+ if (versionId) {
1748
+ query = query.eq("versions.id", versionId);
1749
+ }
1750
+ const { data, error } = await query;
1751
+ if (error) {
1752
+ return { error: { message: error.message } };
1753
+ }
1754
+ return { data: data ?? [] };
1755
+ }
1756
+
1757
+ // src/commands/component-cmd.ts
1758
+ async function componentCommand(parsed2) {
1759
+ const sub = parsed2.subcommand;
1760
+ if (sub === "create") return componentCreateCommand(parsed2);
1761
+ if (sub === "list" || sub === "ls") return componentListCommand(parsed2);
1762
+ console.error(
1763
+ `Unknown component subcommand: ${sub}. Use: component create | component list`
1764
+ );
1765
+ process.exit(1);
1766
+ }
1767
+ async function componentCreateCommand(parsed2) {
1768
+ const format = detectOutputFormat(parsed2.global.output);
1769
+ try {
1770
+ let input;
1771
+ if (parsed2.global.data) {
1772
+ const raw = JSON.parse(parsed2.global.data);
1773
+ input = {
1774
+ versionId: validateUuid(raw.versionId, "versionId"),
1775
+ name: validateRequired(raw.name, "name"),
1776
+ slot: validateRequired(raw.slot, "slot"),
1777
+ active: raw.active ?? true,
1778
+ props: raw.props ?? null
1779
+ };
1780
+ } else {
1781
+ input = {
1782
+ versionId: validateUuid(
1783
+ validateRequired(getFlag(parsed2.flags, "version-id"), "version-id"),
1784
+ "version-id"
1785
+ ),
1786
+ name: validateRequired(getFlag(parsed2.flags, "name", "n"), "name"),
1787
+ slot: validateRequired(getFlag(parsed2.flags, "slot", "s"), "slot"),
1788
+ active: getBoolFlag(parsed2.flags, "active") || !("active" in parsed2.flags),
1789
+ props: null
1790
+ };
1791
+ }
1792
+ if (parsed2.global.dryRun) {
1793
+ outputDryRun(
1794
+ "component.create",
1795
+ input,
1796
+ format
1797
+ );
1798
+ return;
1799
+ }
1800
+ const client = await getAuthenticatedClient();
1801
+ const result = await createComponent(client, input);
1802
+ outputResult(result, format, parsed2.global.fields);
1803
+ if (result.error) process.exit(1);
1804
+ } catch (err) {
1805
+ outputResult(
1806
+ {
1807
+ error: { message: err instanceof Error ? err.message : String(err) }
1808
+ },
1809
+ format
1810
+ );
1811
+ process.exit(1);
1812
+ }
1813
+ }
1814
+ async function componentListCommand(parsed2) {
1815
+ const format = detectOutputFormat(parsed2.global.output);
1816
+ try {
1817
+ const storeId = validateUuid(
1818
+ validateRequired(getFlag(parsed2.flags, "store-id"), "store-id"),
1819
+ "store-id"
1820
+ );
1821
+ const versionId = getFlag(parsed2.flags, "version-id");
1822
+ if (versionId) validateUuid(versionId, "version-id");
1823
+ const client = await getAuthenticatedClient();
1824
+ const result = await listComponents(client, storeId, versionId);
1825
+ outputResult(result, format, parsed2.global.fields);
1826
+ if (result.error) process.exit(1);
1827
+ } catch (err) {
1828
+ outputResult(
1829
+ {
1830
+ error: { message: err instanceof Error ? err.message : String(err) }
1831
+ },
1832
+ format
1833
+ );
1834
+ process.exit(1);
1835
+ }
1836
+ }
1837
+
1838
+ // src/core/deploy.ts
1839
+ async function uploadBuild(input) {
1840
+ const builderUrl = getBuilderUrl();
1841
+ const token = await getAuthToken();
1842
+ const formData = new FormData();
1843
+ formData.append(
1844
+ "code",
1845
+ new Blob([input.zipBuffer], { type: "application/zip" }),
1846
+ "code.zip"
1847
+ );
1848
+ formData.append("type", input.type);
1849
+ formData.append("resource_id", input.resourceId);
1850
+ let response;
1851
+ try {
1852
+ response = await fetch(`${builderUrl}/`, {
1853
+ method: "POST",
1854
+ headers: {
1855
+ Authorization: `Bearer ${token}`
1856
+ },
1857
+ body: formData
1858
+ });
1859
+ } catch (err) {
1860
+ return {
1861
+ success: false,
1862
+ error: {
1863
+ message: `Cannot reach builder at ${builderUrl}: ${err instanceof Error ? err.message : String(err)}`
1864
+ }
1865
+ };
1866
+ }
1867
+ const body = await response.json();
1868
+ if (!response.ok || !body.success) {
1869
+ const msg = body.error?.message || body.error?.type || `Builder returned ${response.status}`;
1870
+ return { success: false, error: { message: msg } };
1871
+ }
1872
+ return { success: true, data: body.data };
1873
+ }
1874
+ async function fetchBuildStatus(buildId) {
1875
+ const builderUrl = getBuilderUrl();
1876
+ const token = await getAuthToken();
1877
+ let response;
1878
+ try {
1879
+ response = await fetch(`${builderUrl}/${encodeURIComponent(buildId)}`, {
1880
+ method: "GET",
1881
+ headers: {
1882
+ Authorization: `Bearer ${token}`
1883
+ }
1884
+ });
1885
+ } catch (err) {
1886
+ return {
1887
+ success: false,
1888
+ error: {
1889
+ message: `Cannot reach builder at ${builderUrl}: ${err instanceof Error ? err.message : String(err)}`
1890
+ }
1891
+ };
1892
+ }
1893
+ const body = await response.json();
1894
+ if (!response.ok || !body.success) {
1895
+ const msg = body.error?.message || body.error?.type || `Builder returned ${response.status}`;
1896
+ return { success: false, error: { message: msg } };
1897
+ }
1898
+ return { success: true, data: body.data };
1899
+ }
1900
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
1901
+ "SUCCEEDED",
1902
+ "FAILED",
1903
+ "STOPPED",
1904
+ "TIMED_OUT",
1905
+ "FAULT"
1906
+ ]);
1907
+ function isTerminalStatus(status) {
1908
+ return TERMINAL_STATUSES.has(status);
1909
+ }
1910
+ async function pollBuildStatus(buildId, options = {}) {
1911
+ const { intervalMs = 5e3, timeoutMs = 3e5, onPoll } = options;
1912
+ const deadline = Date.now() + timeoutMs;
1913
+ while (Date.now() < deadline) {
1914
+ const result = await fetchBuildStatus(buildId);
1915
+ if (!result.success) {
1916
+ return result;
1917
+ }
1918
+ if (onPoll) {
1919
+ onPoll(result.data);
1920
+ }
1921
+ if (isTerminalStatus(result.data.status)) {
1922
+ return result;
1923
+ }
1924
+ const remaining = deadline - Date.now();
1925
+ if (remaining <= 0) break;
1926
+ await new Promise(
1927
+ (resolve) => setTimeout(resolve, Math.min(intervalMs, remaining))
1928
+ );
1929
+ }
1930
+ return {
1931
+ success: false,
1932
+ error: { message: `Build ${buildId} timed out after ${timeoutMs / 1e3}s` }
1933
+ };
1934
+ }
1935
+
1936
+ // src/commands/deploy-cmd.ts
1937
+ async function deployCommand(parsed2) {
1938
+ const format = detectOutputFormat(parsed2.global.output);
1939
+ try {
1940
+ let resourceId;
1941
+ let componentName;
1942
+ let resourceType;
1943
+ let wait;
1944
+ let timeout;
1945
+ if (parsed2.global.data) {
1946
+ const raw = JSON.parse(parsed2.global.data);
1947
+ resourceId = validateUuid(
1948
+ raw.componentId || raw.functionId || raw.resourceId,
1949
+ "componentId or functionId"
1950
+ );
1951
+ componentName = validateRequired(raw.name, "name");
1952
+ resourceType = raw.type === "function" ? "function" : "component";
1953
+ wait = raw.wait ?? false;
1954
+ timeout = raw.timeout ?? 300;
1955
+ } else {
1956
+ const compId = getFlag(parsed2.flags, "component-id");
1957
+ const funcId = getFlag(parsed2.flags, "function-id");
1958
+ if (compId && funcId) {
1959
+ throw new Error(
1960
+ "Provide either --component-id or --function-id, not both."
1961
+ );
1962
+ }
1963
+ if (compId) {
1964
+ resourceId = validateUuid(compId, "component-id");
1965
+ resourceType = "component";
1966
+ } else if (funcId) {
1967
+ resourceId = validateUuid(funcId, "function-id");
1968
+ resourceType = "function";
1969
+ } else {
1970
+ throw new Error("Either --component-id or --function-id is required.");
1971
+ }
1972
+ componentName = validateRequired(
1973
+ getFlag(parsed2.flags, "name", "n"),
1974
+ "name"
1975
+ );
1976
+ wait = getBoolFlag(parsed2.flags, "wait");
1977
+ timeout = Number(getFlag(parsed2.flags, "timeout") ?? "300");
1978
+ }
1979
+ const stream = await createComponentBundle({
1980
+ componentName,
1981
+ cwd: process.cwd()
1982
+ });
1983
+ const chunks = [];
1984
+ for await (const chunk of stream) {
1985
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
1986
+ }
1987
+ const zipBuffer = Buffer.concat(chunks);
1988
+ if (parsed2.global.dryRun) {
1989
+ outputDryRun(
1990
+ "deploy",
1991
+ {
1992
+ resourceId,
1993
+ resourceType,
1994
+ componentName,
1995
+ bundleSizeBytes: zipBuffer.length,
1996
+ bundleSizeKB: Math.round(zipBuffer.length / 1024),
1997
+ wait,
1998
+ timeout
1999
+ },
2000
+ format
2001
+ );
2002
+ return;
2003
+ }
2004
+ const uploadResult = await uploadBuild({
2005
+ resourceId,
2006
+ type: resourceType,
2007
+ zipBuffer
2008
+ });
2009
+ if (!uploadResult.success) {
2010
+ outputResult(uploadResult, format);
2011
+ process.exit(1);
2012
+ }
2013
+ if (wait) {
2014
+ const isJson = format === "json";
2015
+ if (!isJson) {
2016
+ process.stderr.write(
2017
+ `Build ${uploadResult.data.id} started. Polling...
2018
+ `
2019
+ );
2020
+ }
2021
+ const pollResult = await pollBuildStatus(uploadResult.data.id, {
2022
+ timeoutMs: timeout * 1e3,
2023
+ onPoll: (build) => {
2024
+ if (!isJson) {
2025
+ process.stderr.write(` status: ${build.status}
2026
+ `);
2027
+ }
2028
+ }
2029
+ });
2030
+ outputResult(pollResult, format, parsed2.global.fields);
2031
+ if (!pollResult.success) process.exit(1);
2032
+ if (pollResult.success && isTerminalStatus(pollResult.data.status) && pollResult.data.status !== "SUCCEEDED") {
2033
+ process.exit(1);
2034
+ }
2035
+ } else {
2036
+ outputResult(uploadResult, format, parsed2.global.fields);
2037
+ }
2038
+ } catch (err) {
2039
+ outputResult(
2040
+ {
2041
+ success: false,
2042
+ error: { message: err instanceof Error ? err.message : String(err) }
2043
+ },
2044
+ format
2045
+ );
2046
+ process.exit(1);
2047
+ }
2048
+ }
2049
+
2050
+ // src/core/function.ts
2051
+ async function createFunction(client, input) {
2052
+ const parsed2 = functionCreateSchema.safeParse(input);
2053
+ if (!parsed2.success) {
2054
+ return {
2055
+ success: false,
2056
+ error: {
2057
+ message: parsed2.error.issues.map((i) => i.message).join("; ")
2058
+ }
2059
+ };
2060
+ }
2061
+ const { data, error } = await client.from("functions").insert({
2062
+ name: parsed2.data.name,
2063
+ active: parsed2.data.active,
2064
+ version_id: parsed2.data.versionId,
2065
+ trigger: parsed2.data.trigger ?? null,
2066
+ on_error: parsed2.data.onError ?? "throw",
2067
+ priority: parsed2.data.priority ?? 0
2068
+ }).select("id").single();
2069
+ if (error) {
2070
+ return { success: false, error: { message: error.message } };
2071
+ }
2072
+ return { success: true, data: { id: data.id } };
2073
+ }
2074
+ async function listFunctions(client, storeId, versionId) {
2075
+ let query = client.from("functions").select(
2076
+ "id, name, active, urn, on_error, priority, trigger, invocation, version_id, created_at, versions!inner(id, name)"
2077
+ ).eq("versions.store_id", storeId);
2078
+ if (versionId) {
2079
+ query = query.eq("versions.id", versionId);
2080
+ }
2081
+ const { data, error } = await query;
2082
+ if (error) {
2083
+ return { success: false, error: { message: error.message } };
2084
+ }
2085
+ return { success: true, data: data ?? [] };
2086
+ }
2087
+
2088
+ // src/commands/function-cmd.ts
2089
+ var ON_ERROR_VALUES = ["throw", "skip"];
2090
+ async function functionCommand(parsed2) {
2091
+ const sub = parsed2.subcommand;
2092
+ if (sub === "create") return functionCreateCommand(parsed2);
2093
+ if (sub === "list" || sub === "ls") return functionListCommand(parsed2);
2094
+ console.error(
2095
+ `Unknown function subcommand: ${sub}. Use: function create | function list`
2096
+ );
2097
+ process.exit(1);
2098
+ }
2099
+ async function functionCreateCommand(parsed2) {
2100
+ const format = detectOutputFormat(parsed2.global.output);
2101
+ try {
2102
+ let input;
2103
+ if (parsed2.global.data) {
2104
+ const raw = JSON.parse(parsed2.global.data);
2105
+ input = {
2106
+ versionId: validateUuid(raw.versionId, "versionId"),
2107
+ name: validateRequired(raw.name, "name"),
2108
+ trigger: raw.trigger !== void 0 && raw.trigger !== null ? validateTriggerUrl(String(raw.trigger), "trigger") : void 0,
2109
+ active: raw.active === true,
2110
+ onError: raw.onError !== void 0 && raw.onError !== null ? validateEnum(String(raw.onError), ON_ERROR_VALUES, "on-error") : "throw",
2111
+ priority: raw.priority !== void 0 && raw.priority !== null ? validateInteger(raw.priority, "priority", { min: 0 }) : 0
2112
+ };
2113
+ } else {
2114
+ const triggerFlag = getFlag(parsed2.flags, "trigger");
2115
+ const onErrorFlag = getFlag(parsed2.flags, "on-error");
2116
+ const priorityFlag = getFlag(parsed2.flags, "priority");
2117
+ input = {
2118
+ versionId: validateUuid(
2119
+ validateRequired(getFlag(parsed2.flags, "version-id"), "version-id"),
2120
+ "version-id"
2121
+ ),
2122
+ name: validateRequired(getFlag(parsed2.flags, "name", "n"), "name"),
2123
+ trigger: triggerFlag !== void 0 ? validateTriggerUrl(triggerFlag, "trigger") : void 0,
2124
+ active: getBoolFlag(parsed2.flags, "active"),
2125
+ onError: onErrorFlag !== void 0 ? validateEnum(onErrorFlag, ON_ERROR_VALUES, "on-error") : "throw",
2126
+ priority: priorityFlag !== void 0 ? validateInteger(priorityFlag, "priority", { min: 0 }) : 0
2127
+ };
2128
+ }
2129
+ const validated = functionCreateSchema.safeParse(input);
2130
+ if (!validated.success) {
2131
+ throw new Error(validated.error.issues.map((i) => i.message).join("; "));
2132
+ }
2133
+ if (parsed2.global.dryRun) {
2134
+ outputDryRun(
2135
+ "function.create",
2136
+ validated.data,
2137
+ format
2138
+ );
2139
+ return;
2140
+ }
2141
+ const client = await getAuthenticatedClient();
2142
+ const result = await createFunction(client, validated.data);
2143
+ outputResult(result, format, parsed2.global.fields);
2144
+ if (!result.success) process.exit(1);
2145
+ } catch (err) {
2146
+ outputResult(
2147
+ {
2148
+ success: false,
2149
+ error: { message: err instanceof Error ? err.message : String(err) }
2150
+ },
2151
+ format
2152
+ );
2153
+ process.exit(1);
2154
+ }
2155
+ }
2156
+ async function functionListCommand(parsed2) {
2157
+ const format = detectOutputFormat(parsed2.global.output);
2158
+ try {
2159
+ const storeId = validateUuid(
2160
+ validateRequired(getFlag(parsed2.flags, "store-id"), "store-id"),
2161
+ "store-id"
2162
+ );
2163
+ const versionId = getFlag(parsed2.flags, "version-id");
2164
+ if (versionId) validateUuid(versionId, "version-id");
2165
+ const client = await getAuthenticatedClient();
2166
+ const result = await listFunctions(client, storeId, versionId);
2167
+ outputResult(result, format, parsed2.global.fields);
2168
+ if (!result.success) process.exit(1);
2169
+ } catch (err) {
2170
+ outputResult(
2171
+ {
2172
+ success: false,
2173
+ error: { message: err instanceof Error ? err.message : String(err) }
2174
+ },
2175
+ format
2176
+ );
2177
+ process.exit(1);
2178
+ }
2179
+ }
2180
+
2181
+ // src/commands/init-cmd.ts
2182
+ async function initCommand(parsed2) {
2183
+ const format = detectOutputFormat(parsed2.global.output);
2184
+ try {
2185
+ const storeId = validateUuid(
2186
+ validateRequired(getFlag(parsed2.flags, "store-id"), "store-id"),
2187
+ "store-id"
2188
+ );
2189
+ const versionIdRaw = getFlag(parsed2.flags, "version-id");
2190
+ const versionId = versionIdRaw ? validateUuid(versionIdRaw, "version-id") : void 0;
2191
+ const stage = getFlag(parsed2.flags, "stage", "s");
2192
+ await saveConfig(
2193
+ {
2194
+ storeId,
2195
+ ...versionId ? { versionId } : {}
2196
+ },
2197
+ { stage }
2198
+ );
2199
+ const fileName = stage && stage !== "prod" ? `ollie.${stage}.json` : "ollie.json";
2200
+ outputResult(
2201
+ {
2202
+ data: {
2203
+ file: fileName,
2204
+ storeId,
2205
+ ...versionId ? { versionId } : {}
2206
+ }
2207
+ },
2208
+ format,
2209
+ parsed2.global.fields
2210
+ );
2211
+ } catch (err) {
2212
+ outputResult(
2213
+ {
2214
+ error: { message: err instanceof Error ? err.message : String(err) }
2215
+ },
2216
+ format
2217
+ );
2218
+ process.exit(1);
2219
+ }
2220
+ }
2221
+
2222
+ // src/commands/schema-cmd.ts
2223
+ async function schemaCommand(parsed2) {
2224
+ const format = detectOutputFormat(parsed2.global.output);
2225
+ const resourceName = parsed2.subcommand || parsed2.positional[0];
2226
+ if (!resourceName) {
2227
+ const names = getSchemaNames();
2228
+ if (format === "json") {
2229
+ process.stdout.write(`${JSON.stringify({ schemas: names })}
2230
+ `);
2231
+ } else {
2232
+ console.log("\x1B[1mAvailable schemas:\x1B[0m");
1662
2233
  for (const name of names) {
1663
2234
  const indent = name.includes(".") ? " " : " ";
1664
2235
  console.log(`${indent}\x1B[32m${name}\x1B[0m`);
@@ -1678,6 +2249,60 @@ async function schemaCommand(parsed2) {
1678
2249
  `);
1679
2250
  }
1680
2251
 
2252
+ // src/commands/status-cmd.ts
2253
+ async function statusCommand(parsed2) {
2254
+ const format = detectOutputFormat(parsed2.global.output);
2255
+ try {
2256
+ let buildId;
2257
+ let wait;
2258
+ let timeout;
2259
+ if (parsed2.global.data) {
2260
+ const raw = JSON.parse(parsed2.global.data);
2261
+ buildId = validateRequired(raw.buildId, "buildId");
2262
+ wait = raw.wait ?? false;
2263
+ timeout = raw.timeout ?? 300;
2264
+ } else {
2265
+ buildId = validateRequired(getFlag(parsed2.flags, "build-id"), "build-id");
2266
+ wait = getBoolFlag(parsed2.flags, "wait");
2267
+ timeout = Number(getFlag(parsed2.flags, "timeout") ?? "300");
2268
+ }
2269
+ if (wait) {
2270
+ const isJson = format === "json";
2271
+ if (!isJson) {
2272
+ process.stderr.write(`Polling build ${buildId}...
2273
+ `);
2274
+ }
2275
+ const result = await pollBuildStatus(buildId, {
2276
+ timeoutMs: timeout * 1e3,
2277
+ onPoll: (build) => {
2278
+ if (!isJson) {
2279
+ process.stderr.write(` status: ${build.status}
2280
+ `);
2281
+ }
2282
+ }
2283
+ });
2284
+ outputResult(result, format, parsed2.global.fields);
2285
+ if (!result.success) process.exit(1);
2286
+ if (result.success && isTerminalStatus(result.data.status) && result.data.status !== "SUCCEEDED") {
2287
+ process.exit(1);
2288
+ }
2289
+ } else {
2290
+ const result = await fetchBuildStatus(buildId);
2291
+ outputResult(result, format, parsed2.global.fields);
2292
+ if (!result.success) process.exit(1);
2293
+ }
2294
+ } catch (err) {
2295
+ outputResult(
2296
+ {
2297
+ success: false,
2298
+ error: { message: err instanceof Error ? err.message : String(err) }
2299
+ },
2300
+ format
2301
+ );
2302
+ process.exit(1);
2303
+ }
2304
+ }
2305
+
1681
2306
  // src/core/store.ts
1682
2307
  async function createStore(client, input) {
1683
2308
  const parsed2 = storeCreateSchema.safeParse(input);
@@ -1923,8 +2548,12 @@ var AGENT_COMMANDS = {
1923
2548
  store: storeCommand,
1924
2549
  version: versionCommand,
1925
2550
  component: componentCommand,
2551
+ "business-rule": businessRuleCommand,
2552
+ function: functionCommand,
1926
2553
  schema: schemaCommand,
1927
- init: initCommand
2554
+ init: initCommand,
2555
+ deploy: deployCommand,
2556
+ status: statusCommand
1928
2557
  };
1929
2558
  var parsed = parseArgs(process.argv);
1930
2559
  if (parsed.command in AGENT_COMMANDS) {