@cimplify/sdk 0.9.10 → 0.10.1

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 (70) hide show
  1. package/dist/{ads-MkGm5l1T.d.mts → ads-BxbWrwqp.d.mts} +0 -8
  2. package/dist/{ads-MkGm5l1T.d.ts → ads-BxbWrwqp.d.ts} +0 -8
  3. package/dist/advanced.d.mts +2 -2
  4. package/dist/advanced.d.ts +2 -2
  5. package/dist/advanced.js +93 -80
  6. package/dist/advanced.mjs +93 -80
  7. package/dist/cli.js +184 -0
  8. package/dist/{client-BQ1gIg8t.d.mts → client-BSrq89H1.d.mts} +42 -374
  9. package/dist/{client-C3TQtGuy.d.ts → client-xBhdHLq4.d.ts} +42 -374
  10. package/dist/index.d.mts +6 -10
  11. package/dist/index.d.ts +6 -10
  12. package/dist/index.js +98 -126
  13. package/dist/index.mjs +98 -126
  14. package/dist/{payment-CTalZM5l.d.mts → payment-CrNyrc-D.d.mts} +145 -95
  15. package/dist/{payment-CTalZM5l.d.ts → payment-CrNyrc-D.d.ts} +145 -95
  16. package/dist/price-C9Z-hr49.d.mts +21 -0
  17. package/dist/price-RKKoTz-9.d.ts +21 -0
  18. package/dist/react.d.mts +1285 -35
  19. package/dist/react.d.ts +1285 -35
  20. package/dist/react.js +6596 -2598
  21. package/dist/react.mjs +6550 -2600
  22. package/dist/utils.d.mts +55 -2
  23. package/dist/utils.d.ts +55 -2
  24. package/dist/utils.js +23 -20
  25. package/dist/utils.mjs +23 -20
  26. package/package.json +13 -3
  27. package/registry/add-on-selector.json +15 -0
  28. package/registry/availability-badge.json +15 -0
  29. package/registry/booking-card.json +16 -0
  30. package/registry/booking-list.json +16 -0
  31. package/registry/booking-page.json +18 -0
  32. package/registry/bookings-page.json +17 -0
  33. package/registry/bundle-selector.json +15 -0
  34. package/registry/cart-page.json +17 -0
  35. package/registry/cart-summary.json +16 -0
  36. package/registry/catalogue-page.json +18 -0
  37. package/registry/category-filter.json +15 -0
  38. package/registry/category-grid.json +15 -0
  39. package/registry/checkout-page.json +15 -0
  40. package/registry/cn.json +13 -0
  41. package/registry/collection-page.json +16 -0
  42. package/registry/composite-selector.json +15 -0
  43. package/registry/date-slot-picker.json +16 -0
  44. package/registry/deal-banner.json +16 -0
  45. package/registry/deals-page.json +19 -0
  46. package/registry/discount-input.json +16 -0
  47. package/registry/index.json +411 -0
  48. package/registry/order-detail-page.json +16 -0
  49. package/registry/order-history-page.json +17 -0
  50. package/registry/order-history.json +16 -0
  51. package/registry/order-summary.json +16 -0
  52. package/registry/price.json +13 -0
  53. package/registry/product-card.json +17 -0
  54. package/registry/product-customizer.json +20 -0
  55. package/registry/product-grid.json +16 -0
  56. package/registry/product-image-gallery.json +13 -0
  57. package/registry/product-page.json +19 -0
  58. package/registry/product-sheet.json +18 -0
  59. package/registry/quantity-selector.json +13 -0
  60. package/registry/sale-badge.json +16 -0
  61. package/registry/search-input.json +15 -0
  62. package/registry/search-page.json +16 -0
  63. package/registry/service-card.json +16 -0
  64. package/registry/service-grid.json +16 -0
  65. package/registry/slot-picker.json +16 -0
  66. package/registry/staff-picker.json +15 -0
  67. package/registry/store-nav.json +15 -0
  68. package/registry/variant-selector.json +15 -0
  69. package/dist/index-B_25cFc1.d.ts +0 -320
  70. package/dist/index-Cd0shhZU.d.mts +0 -320
package/dist/advanced.mjs CHANGED
@@ -8,16 +8,15 @@ function err(error) {
8
8
 
9
9
  // src/types/common.ts
10
10
  function money(value) {
11
- return value;
11
+ return typeof value === "string" ? parseFloat(value) || 0 : value;
12
12
  }
13
13
  function moneyFromNumber(value) {
14
- return value.toFixed(2);
14
+ return value;
15
15
  }
16
16
  function currencyCode(value) {
17
17
  return value;
18
18
  }
19
19
  var ErrorCode = {
20
- // General
21
20
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
22
21
  NOT_FOUND: "NOT_FOUND"};
23
22
  var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
@@ -92,7 +91,6 @@ var CimplifyError = class extends Error {
92
91
  this.suggestion = suggestion;
93
92
  this.name = "CimplifyError";
94
93
  }
95
- /** User-friendly message safe to display */
96
94
  get userMessage() {
97
95
  return this.message;
98
96
  }
@@ -278,6 +276,7 @@ var CatalogueQueries = class {
278
276
  async getProducts(options) {
279
277
  const path = withQuery("/api/v1/catalogue/products", {
280
278
  category_id: options?.category,
279
+ taxonomy_id: options?.taxonomy,
281
280
  search: options?.search,
282
281
  page: options?.page,
283
282
  tags: options?.tags?.join(","),
@@ -410,6 +409,59 @@ var CatalogueQueries = class {
410
409
  )
411
410
  );
412
411
  }
412
+ async getTaxonomies(parentId) {
413
+ const path = withQuery("/api/v1/catalogue/taxonomies", { parent_id: parentId });
414
+ return safe(this.client.get(path));
415
+ }
416
+ async getTaxonomy(id) {
417
+ const encodedId = encodeURIComponent(id);
418
+ return safe(this.client.get(`/api/v1/catalogue/taxonomies/${encodedId}`));
419
+ }
420
+ async getTaxonomyPath(id) {
421
+ const encodedId = encodeURIComponent(id);
422
+ return safe(this.client.get(`/api/v1/catalogue/taxonomies/${encodedId}/path`));
423
+ }
424
+ async searchTaxonomies(query2, limit) {
425
+ const path = withQuery("/api/v1/catalogue/taxonomies/search", { q: query2, limit });
426
+ return safe(this.client.get(path));
427
+ }
428
+ async getProductSchedules(productId) {
429
+ const encodedId = encodeURIComponent(productId);
430
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/schedules`));
431
+ }
432
+ async checkProductAvailableNow(productId, locationId) {
433
+ const encodedId = encodeURIComponent(productId);
434
+ const path = withQuery(`/api/v1/catalogue/products/${encodedId}/available-now`, { location_id: locationId });
435
+ return safe(this.client.get(path));
436
+ }
437
+ async getDeals(locationId) {
438
+ const path = withQuery("/api/v1/catalogue/deals", { location_id: locationId });
439
+ return safe(this.client.get(path));
440
+ }
441
+ async getProductsOnSale() {
442
+ return safe(this.client.get("/api/v1/catalogue/deals/on-sale"));
443
+ }
444
+ async getProductDeals(productId) {
445
+ const encodedId = encodeURIComponent(productId);
446
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/deals`));
447
+ }
448
+ async getCategoryDeals(categoryId) {
449
+ const encodedId = encodeURIComponent(categoryId);
450
+ return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}/deals`));
451
+ }
452
+ async getCollectionDeals(collectionId) {
453
+ const encodedId = encodeURIComponent(collectionId);
454
+ return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}/deals`));
455
+ }
456
+ async validateDiscountCode(code, orderSubtotal, locationId) {
457
+ return safe(
458
+ this.client.post("/api/v1/catalogue/deals/validate", {
459
+ discount_code: code,
460
+ order_subtotal: orderSubtotal,
461
+ location_id: locationId
462
+ })
463
+ );
464
+ }
413
465
  async search(query2, options) {
414
466
  const result = await this.getProducts({
415
467
  search: query2,
@@ -437,6 +489,16 @@ var CatalogueQueries = class {
437
489
  const encodedId = encodeURIComponent(itemId);
438
490
  return safe(this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`));
439
491
  }
492
+ async getTags(options) {
493
+ const path = withQuery("/api/v1/catalogue/tags", {
494
+ tag_group: options?.tag_group,
495
+ search: options?.search,
496
+ min_usage: options?.min_usage,
497
+ limit: options?.limit,
498
+ offset: options?.offset
499
+ });
500
+ return safe(this.client.get(path));
501
+ }
440
502
  };
441
503
 
442
504
  // src/cart.ts
@@ -586,7 +648,8 @@ var PAYMENT_FAILURE_STATUSES = /* @__PURE__ */ new Set([
586
648
  "declined",
587
649
  "cancelled",
588
650
  "voided",
589
- "error"
651
+ "error",
652
+ "abandoned"
590
653
  ]);
591
654
  var PAYMENT_REQUIRES_ACTION_STATUSES = /* @__PURE__ */ new Set([
592
655
  "requires_action",
@@ -616,29 +679,34 @@ var PAYMENT_STATUS_ALIAS_MAP = {
616
679
  unresolved: "pending"
617
680
  };
618
681
  var KNOWN_PAYMENT_STATUSES = /* @__PURE__ */ new Set([
682
+ "initialized",
619
683
  "pending",
620
684
  "processing",
685
+ "authorized",
686
+ "captured",
687
+ "failed",
688
+ "cancelled",
689
+ "refunded",
690
+ "unknown",
691
+ "voided",
692
+ "requires_action",
693
+ "abandoned",
694
+ "reversed",
695
+ "disputed",
696
+ "refund_pending",
621
697
  "created",
622
698
  "pending_confirmation",
623
699
  "success",
624
700
  "succeeded",
625
- "failed",
626
701
  "declined",
627
- "authorized",
628
- "refunded",
629
702
  "partially_refunded",
630
703
  "partially_paid",
631
704
  "paid",
632
705
  "unpaid",
633
- "requires_action",
634
706
  "requires_payment_method",
635
707
  "requires_capture",
636
- "captured",
637
- "cancelled",
638
708
  "completed",
639
- "voided",
640
- "error",
641
- "unknown"
709
+ "error"
642
710
  ]);
643
711
  function normalizeStatusToken(status) {
644
712
  return status?.trim().toLowerCase().replace(/[\s-]+/g, "_") ?? "";
@@ -667,13 +735,15 @@ function normalizeStatusResponse(response) {
667
735
  return {
668
736
  status: "pending",
669
737
  paid: false,
738
+ amount: moneyFromNumber(0),
739
+ currency: "",
670
740
  message: "No status available"
671
741
  };
672
742
  }
673
743
  const res = response;
674
744
  const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
675
- const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : void 0;
676
- const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? currencyCode(res.currency) : void 0;
745
+ const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : moneyFromNumber(0);
746
+ const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? res.currency : "";
677
747
  const paidValue = res.paid === true;
678
748
  const derivedPaid = paidValue || [
679
749
  "success",
@@ -806,7 +876,8 @@ function isValidMobileMoneyProvider(value) {
806
876
  return VALID_MOBILE_MONEY_PROVIDERS.has(value);
807
877
  }
808
878
  function normalizeAuthorizationType(value) {
809
- const lower = value?.toLowerCase();
879
+ if (typeof value !== "string") return void 0;
880
+ const lower = value.toLowerCase();
810
881
  return lower === "otp" || lower === "pin" ? lower : void 0;
811
882
  }
812
883
  function formatMoney2(value) {
@@ -1512,7 +1583,7 @@ var CheckoutService = class {
1512
1583
  );
1513
1584
  const payCurrency = data.pay_currency?.trim().toUpperCase();
1514
1585
  const payCurrencyCode = payCurrency ? currencyCode(payCurrency) : void 0;
1515
- const cartTotalAmount = Number.parseFloat(cart.pricing.total_price || "0");
1586
+ const cartTotalAmount = typeof cart.pricing.total_price === "number" ? cart.pricing.total_price : Number.parseFloat(cart.pricing.total_price || "0");
1516
1587
  if (payCurrencyCode && payCurrencyCode !== baseCurrency && !checkoutData.fx_quote_id && Number.isFinite(cartTotalAmount) && cartTotalAmount > 0) {
1517
1588
  const fxQuoteResult = await this.client.fx.lockQuote({
1518
1589
  from: baseCurrency,
@@ -1677,7 +1748,7 @@ var LinkService = class {
1677
1748
  this.client.linkPost("/v1/link/auth/verify-otp", input)
1678
1749
  );
1679
1750
  if (result.ok && result.value.session_token) {
1680
- this.client.setSessionToken(result.value.session_token);
1751
+ this.client.setAccessToken(result.value.session_token);
1681
1752
  }
1682
1753
  return result;
1683
1754
  }
@@ -1791,30 +1862,6 @@ var LinkService = class {
1791
1862
  async revokeAllSessions() {
1792
1863
  return safe5(this.client.linkDelete("/v1/link/sessions"));
1793
1864
  }
1794
- async getAddressesRest() {
1795
- return this.getAddresses();
1796
- }
1797
- async createAddressRest(input) {
1798
- return this.createAddress(input);
1799
- }
1800
- async deleteAddressRest(addressId) {
1801
- return this.deleteAddress(addressId);
1802
- }
1803
- async setDefaultAddressRest(addressId) {
1804
- return this.setDefaultAddress(addressId);
1805
- }
1806
- async getMobileMoneyRest() {
1807
- return this.getMobileMoney();
1808
- }
1809
- async createMobileMoneyRest(input) {
1810
- return this.createMobileMoney(input);
1811
- }
1812
- async deleteMobileMoneyRest(mobileMoneyId) {
1813
- return this.deleteMobileMoney(mobileMoneyId);
1814
- }
1815
- async setDefaultMobileMoneyRest(mobileMoneyId) {
1816
- return this.setDefaultMobileMoney(mobileMoneyId);
1817
- }
1818
1865
  };
1819
1866
 
1820
1867
  // src/auth.ts
@@ -1906,9 +1953,6 @@ var BusinessService = class {
1906
1953
  async getSettings() {
1907
1954
  return safe7(this.client.get("/api/v1/business/settings"));
1908
1955
  }
1909
- async getTheme() {
1910
- return safe7(this.client.get("/api/v1/business/theme"));
1911
- }
1912
1956
  async getLocations() {
1913
1957
  return safe7(this.client.get("/api/v1/business/locations"));
1914
1958
  }
@@ -1962,9 +2006,6 @@ var InventoryService = class {
1962
2006
  const query2 = searchParams.toString();
1963
2007
  return query2 ? `${path}?${query2}` : path;
1964
2008
  }
1965
- async getStockLevels() {
1966
- return safe8(this.client.get("/api/v1/inventory/stock-levels"));
1967
- }
1968
2009
  async getProductStock(productId, locationId) {
1969
2010
  const encodedId = encodeURIComponent(productId);
1970
2011
  const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/stock`, {
@@ -2006,9 +2047,6 @@ var InventoryService = class {
2006
2047
  }
2007
2048
  return ok(results.map((r) => r.value));
2008
2049
  }
2009
- async getSummary() {
2010
- return safe8(this.client.get("/api/v1/inventory/summary"));
2011
- }
2012
2050
  async isInStock(productId, locationId) {
2013
2051
  const result = await this.checkProductAvailability(productId, 1, locationId);
2014
2052
  if (!result.ok) return result;
@@ -2045,16 +2083,6 @@ function withQuery2(path, params) {
2045
2083
  const query2 = searchParams.toString();
2046
2084
  return query2 ? `${path}?${query2}` : path;
2047
2085
  }
2048
- function normalizeServiceAvailability(result) {
2049
- if (Array.isArray(result.days) && result.days.length > 0) {
2050
- return result;
2051
- }
2052
- const days = Array.isArray(result.availability) ? result.availability.map((day) => ({
2053
- ...day,
2054
- is_fully_booked: day.is_fully_booked ?? (typeof day.has_availability === "boolean" ? !day.has_availability : void 0)
2055
- })) : [];
2056
- return { ...result, days };
2057
- }
2058
2086
  function firstScheduledTime(booking) {
2059
2087
  return booking.service_items.find((item) => typeof item.scheduled_start === "string")?.scheduled_start || booking.created_at;
2060
2088
  }
@@ -2065,13 +2093,9 @@ var SchedulingService = class {
2065
2093
  async getServices() {
2066
2094
  return safe9(this.client.get("/api/v1/scheduling/services"));
2067
2095
  }
2068
- /**
2069
- * Get a specific service by ID.
2070
- */
2071
2096
  async getService(serviceId) {
2072
- const result = await this.getServices();
2073
- if (!result.ok) return result;
2074
- return ok(result.value.find((service) => service.id === serviceId) || null);
2097
+ const encodedId = encodeURIComponent(serviceId);
2098
+ return safe9(this.client.get(`/api/v1/scheduling/services/${encodedId}`));
2075
2099
  }
2076
2100
  async getAvailableSlots(input) {
2077
2101
  const path = withQuery2("/api/v1/scheduling/slots", {
@@ -2099,9 +2123,7 @@ var SchedulingService = class {
2099
2123
  location_id: params.location_id,
2100
2124
  participant_count: params.participant_count
2101
2125
  });
2102
- return safe9(
2103
- this.client.get(path).then((result) => normalizeServiceAvailability(result))
2104
- );
2126
+ return safe9(this.client.get(path));
2105
2127
  }
2106
2128
  async getBooking(bookingId) {
2107
2129
  const encodedId = encodeURIComponent(bookingId);
@@ -2158,12 +2180,6 @@ var SchedulingService = class {
2158
2180
  if (!result.ok) return result;
2159
2181
  return ok(result.value.some((slot) => slot.is_available));
2160
2182
  }
2161
- // Compatibility alias for callers typed against the older Booking shape.
2162
- async getBookingLegacy(bookingId) {
2163
- const result = await this.getBooking(bookingId);
2164
- if (!result.ok) return result;
2165
- return ok(result.value);
2166
- }
2167
2183
  };
2168
2184
 
2169
2185
  // src/lite.ts
@@ -2237,7 +2253,6 @@ var ELEMENT_TYPES = {
2237
2253
  CHECKOUT: "checkout"
2238
2254
  };
2239
2255
  var MESSAGE_TYPES = {
2240
- // Parent → Iframe
2241
2256
  INIT: "init",
2242
2257
  SET_TOKEN: "set_token",
2243
2258
  SET_CART: "set_cart",
@@ -2246,7 +2261,6 @@ var MESSAGE_TYPES = {
2246
2261
  LOGOUT: "logout",
2247
2262
  PROCESS_CHECKOUT: "process_checkout",
2248
2263
  ABORT_CHECKOUT: "abort_checkout",
2249
- // Iframe → Parent
2250
2264
  READY: "ready",
2251
2265
  HEIGHT_CHANGE: "height_change",
2252
2266
  AUTHENTICATED: "authenticated",
@@ -2474,7 +2488,6 @@ var CimplifyElements = class {
2474
2488
  tip_amount: options.tip_amount,
2475
2489
  pay_currency: options.pay_currency,
2476
2490
  enroll_in_link: options.enroll_in_link ?? true,
2477
- // Unified checkout has its own address/customer state; only pass if available externally
2478
2491
  address: isUnifiedCheckout ? void 0 : this.addressData ?? void 0,
2479
2492
  customer: isUnifiedCheckout ? void 0 : this.customerData ? {
2480
2493
  name: this.customerData.name,
package/dist/cli.js ADDED
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+
7
+ var BOLD = "\x1B[1m";
8
+ var DIM = "\x1B[2m";
9
+ var GREEN = "\x1B[32m";
10
+ var YELLOW = "\x1B[33m";
11
+ var RED = "\x1B[31m";
12
+ var RESET = "\x1B[0m";
13
+ function error(msg) {
14
+ console.error(`${RED}error${RESET}: ${msg}`);
15
+ process.exit(1);
16
+ }
17
+ function registryDir() {
18
+ const fromDist = path.join(path.dirname(__dirname), "registry");
19
+ if (fs.existsSync(fromDist)) return fromDist;
20
+ const fromSrc = path.join(path.dirname(path.dirname(__dirname)), "registry");
21
+ if (fs.existsSync(fromSrc)) return fromSrc;
22
+ const fromFile = path.join(__dirname, "..", "registry");
23
+ if (fs.existsSync(fromFile)) return fromFile;
24
+ error(
25
+ "Registry not found. Run `bun run build` first to generate the registry."
26
+ );
27
+ }
28
+ function loadIndex(dir) {
29
+ const path$1 = path.join(dir, "index.json");
30
+ if (!fs.existsSync(path$1)) error("Registry index.json not found.");
31
+ return JSON.parse(fs.readFileSync(path$1, "utf8"));
32
+ }
33
+ function loadComponent(dir, name) {
34
+ const path$1 = path.join(dir, `${name}.json`);
35
+ if (!fs.existsSync(path$1)) {
36
+ error(
37
+ `Component "${name}" not found in registry. Run with --list to see available components.`
38
+ );
39
+ }
40
+ return JSON.parse(fs.readFileSync(path$1, "utf8"));
41
+ }
42
+ function listComponents(dir) {
43
+ const index = loadIndex(dir);
44
+ console.log(`
45
+ ${BOLD}Available components:${RESET}
46
+ `);
47
+ const maxName = Math.max(...index.components.map((c) => c.name.length));
48
+ for (const comp of index.components) {
49
+ const tag = comp.type === "utility" ? ` ${DIM}(utility)${RESET}` : "";
50
+ console.log(
51
+ ` ${GREEN}${comp.name.padEnd(maxName)}${RESET} ${comp.description}${tag}`
52
+ );
53
+ }
54
+ console.log(
55
+ `
56
+ ${DIM}Use SDK defaults to build quickly. Eject when you need full customization.${RESET}`
57
+ );
58
+ console.log(
59
+ ` ${DIM}npx @cimplify/sdk eject <name> [--dir <path>]${RESET}
60
+ `
61
+ );
62
+ }
63
+ function ejectComponent(dir, name, targetDir, force) {
64
+ const component = loadComponent(dir, name);
65
+ fs.mkdirSync(targetDir, { recursive: true });
66
+ for (const file of component.files) {
67
+ const targetPath = path.join(targetDir, file.path);
68
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
69
+ if (fs.existsSync(targetPath) && !force) {
70
+ console.log(
71
+ ` ${YELLOW}skip${RESET} ${file.path} (already exists, use --force to overwrite)`
72
+ );
73
+ continue;
74
+ }
75
+ fs.writeFileSync(targetPath, file.content);
76
+ console.log(` ${GREEN}wrote${RESET} ${file.path}`);
77
+ }
78
+ const sdkImports = /* @__PURE__ */ new Set();
79
+ for (const file of component.files) {
80
+ const matches = file.content.matchAll(
81
+ /from\s+["']((@cimplify\/sdk)(\/react)?)["']/g
82
+ );
83
+ for (const match of matches) {
84
+ sdkImports.add(match[1]);
85
+ }
86
+ }
87
+ if (sdkImports.size > 0) {
88
+ console.log(
89
+ `
90
+ ${DIM}SDK imports used: ${[...sdkImports].join(", ")}${RESET}`
91
+ );
92
+ }
93
+ if (component.registryDependencies.length > 0) {
94
+ console.log(
95
+ ` ${DIM}Uses: ${component.registryDependencies.join(", ")}${RESET}`
96
+ );
97
+ console.log(
98
+ ` ${DIM}These keep working as SDK defaults. Eject them only if you need to customize them too.${RESET}`
99
+ );
100
+ }
101
+ }
102
+ function ejectAll(dir, targetDir, force) {
103
+ const index = loadIndex(dir);
104
+ console.log(`
105
+ ${BOLD}Ejecting all ${index.components.length} components...${RESET}
106
+ `);
107
+ for (const comp of index.components) {
108
+ console.log(`${BOLD}${comp.name}${RESET}`);
109
+ ejectComponent(dir, comp.name, targetDir, force);
110
+ console.log();
111
+ }
112
+ console.log(`${GREEN}Done!${RESET} All components ejected to ${targetDir}`);
113
+ }
114
+ function main() {
115
+ const args = process.argv.slice(2);
116
+ if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
117
+ console.log(`
118
+ ${BOLD}@cimplify/sdk eject${RESET} \u2014 Copy SDK component source into your project.
119
+
120
+ Build storefronts quickly with SDK defaults. When you need full
121
+ control over a component's markup, styling, or behavior \u2014 eject it.
122
+ The ejected file is yours to modify. Hooks, types, and utilities
123
+ keep importing from @cimplify/sdk so you stay on the upgrade path.
124
+
125
+ ${BOLD}Usage:${RESET}
126
+ npx @cimplify/sdk eject <name> Copy one component
127
+ npx @cimplify/sdk eject --all Copy all components
128
+ npx @cimplify/sdk eject --list List available components
129
+
130
+ ${BOLD}Options:${RESET}
131
+ --dir <path> Target directory (default: src/components/cimplify)
132
+ --force Overwrite existing files
133
+ --list List available components
134
+ --all Eject everything
135
+ `);
136
+ return;
137
+ }
138
+ if (args[0] !== "eject") {
139
+ error(`Unknown command "${args[0]}". Use "eject" \u2014 see --help for usage.`);
140
+ }
141
+ const ejectArgs = args.slice(1);
142
+ let targetDir = path.resolve("src/components/cimplify");
143
+ let force = false;
144
+ let listMode = false;
145
+ let allMode = false;
146
+ const names = [];
147
+ for (let i = 0; i < ejectArgs.length; i++) {
148
+ const arg = ejectArgs[i];
149
+ if (arg === "--dir") {
150
+ i++;
151
+ if (!ejectArgs[i]) error("--dir requires a path argument.");
152
+ targetDir = path.resolve(ejectArgs[i]);
153
+ } else if (arg === "--force") {
154
+ force = true;
155
+ } else if (arg === "--list") {
156
+ listMode = true;
157
+ } else if (arg === "--all") {
158
+ allMode = true;
159
+ } else if (arg.startsWith("-")) {
160
+ error(`Unknown flag "${arg}". See --help for usage.`);
161
+ } else {
162
+ names.push(arg);
163
+ }
164
+ }
165
+ const dir = registryDir();
166
+ if (listMode) {
167
+ listComponents(dir);
168
+ return;
169
+ }
170
+ if (allMode) {
171
+ ejectAll(dir, targetDir, force);
172
+ return;
173
+ }
174
+ if (names.length === 0) {
175
+ error("No component name provided. Use --list to see available components.");
176
+ }
177
+ console.log();
178
+ for (const name of names) {
179
+ console.log(`${BOLD}${name}${RESET}`);
180
+ ejectComponent(dir, name, targetDir, force);
181
+ console.log();
182
+ }
183
+ }
184
+ main();