shopq 0.4.0 → 0.4.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 (2) hide show
  1. package/dist/shopq.js +58 -3
  2. package/package.json +1 -1
package/dist/shopq.js CHANGED
@@ -232,6 +232,14 @@ function handleCommandError(err) {
232
232
  }
233
233
  throw new Error(String(err));
234
234
  }
235
+ function rejectHandleFlag(parsed, usage) {
236
+ if (parsed.args.length === 0 && parsed.flags.handle) {
237
+ formatError(`--handle is not a flag for this command. Pass the identifier as a positional argument: ${usage}`);
238
+ process.exitCode = 2;
239
+ return true;
240
+ }
241
+ return false;
242
+ }
235
243
  async function readFileText(path) {
236
244
  if (!existsSync(path)) {
237
245
  formatError(`File not found: ${path}`);
@@ -476,6 +484,8 @@ var PRODUCTS_QUERY = `query ProductList($first: Int!, $after: String, $sortKey:
476
484
  vendor
477
485
  variantsCount { count }
478
486
  totalInventory
487
+ category { id name }
488
+ featuredImage { url }
479
489
  }
480
490
  }
481
491
  pageInfo {
@@ -514,7 +524,9 @@ async function handleProductList(parsed) {
514
524
  productType: e.node.productType,
515
525
  vendor: e.node.vendor,
516
526
  variantsCount: e.node.variantsCount.count,
517
- totalInventory: e.node.totalInventory
527
+ totalInventory: e.node.totalInventory,
528
+ category: e.node.category?.name ?? null,
529
+ hasImage: e.node.featuredImage !== null
518
530
  }));
519
531
  const pageInfo = result.products.pageInfo;
520
532
  if (parsed.flags.json) {
@@ -532,9 +544,15 @@ async function handleProductList(parsed) {
532
544
  { key: "productType", header: "Type" },
533
545
  { key: "vendor", header: "Vendor" },
534
546
  { key: "variantsCount", header: "Variants" },
535
- { key: "totalInventory", header: "Inventory" }
547
+ { key: "totalInventory", header: "Inventory" },
548
+ { key: "category", header: "Category" },
549
+ { key: "hasImage", header: "Image" }
536
550
  ];
537
- formatOutput(products, columns, {
551
+ const tableData = products.map((p) => ({
552
+ ...p,
553
+ hasImage: p.hasImage ? "Yes" : "No"
554
+ }));
555
+ formatOutput(tableData, columns, {
538
556
  json: false,
539
557
  noColor: parsed.flags.noColor,
540
558
  pageInfo
@@ -552,6 +570,17 @@ var PRODUCT_GET_QUERY = `query ProductGet($id: ID!) {
552
570
  vendor
553
571
  tags
554
572
  descriptionHtml
573
+ category { id name }
574
+ metafields(first: 25) {
575
+ edges {
576
+ node {
577
+ namespace
578
+ key
579
+ type
580
+ value
581
+ }
582
+ }
583
+ }
555
584
  variants(first: 100) {
556
585
  edges {
557
586
  node {
@@ -602,6 +631,8 @@ function truncate(str, max) {
602
631
  return `${str.slice(0, max - 3)}...`;
603
632
  }
604
633
  async function handleProductGet(parsed) {
634
+ if (rejectHandleFlag(parsed, "shopq product get <id-or-title>"))
635
+ return;
605
636
  const idOrTitle = parsed.args.join(" ");
606
637
  if (!idOrTitle) {
607
638
  formatError("Usage: shopq product get <id-or-title>");
@@ -671,6 +702,12 @@ function outputProduct(product, parsed) {
671
702
  url: e.node.url,
672
703
  alt: e.node.altText ?? ""
673
704
  }));
705
+ const metafields = product.metafields.edges.map((e) => ({
706
+ namespace: e.node.namespace,
707
+ key: e.node.key,
708
+ type: e.node.type,
709
+ value: e.node.value
710
+ }));
674
711
  if (parsed.flags.json) {
675
712
  const data = {
676
713
  id: product.id,
@@ -680,6 +717,8 @@ function outputProduct(product, parsed) {
680
717
  vendor: product.vendor,
681
718
  tags: product.tags,
682
719
  description: stripHtml(product.descriptionHtml),
720
+ category: product.category,
721
+ metafields,
683
722
  variants: product.variants.edges.map((e) => ({
684
723
  id: e.node.id,
685
724
  sku: e.node.sku,
@@ -701,8 +740,18 @@ function outputProduct(product, parsed) {
701
740
  lines.push(`${label("Type")}: ${product.productType}`);
702
741
  lines.push(`${label("Vendor")}: ${product.vendor}`);
703
742
  lines.push(`${label("Tags")}: ${product.tags.join(", ")}`);
743
+ lines.push(`${label("Category")}: ${product.category?.name ?? ""}`);
704
744
  lines.push(`${label("Description")}: ${truncate(plainDesc, 80)}`);
705
745
  lines.push("");
746
+ lines.push(`${label("Metafields")}:`);
747
+ if (metafields.length === 0) {
748
+ lines.push(" (none)");
749
+ } else {
750
+ for (const mf of metafields) {
751
+ lines.push(` ${mf.namespace}.${mf.key}: ${mf.value}`);
752
+ }
753
+ }
754
+ lines.push("");
706
755
  lines.push(`${label("Variants")}:`);
707
756
  for (const v of variants) {
708
757
  lines.push(` SKU: ${v.sku} Price: ${v.price} Options: ${v.options} Qty: ${v.inventoryQuantity}`);
@@ -1103,6 +1152,8 @@ function flattenItems(items, depth, rows) {
1103
1152
  }
1104
1153
  }
1105
1154
  async function handleMenuGet(parsed) {
1155
+ if (rejectHandleFlag(parsed, "shopq menu get <id-or-handle>"))
1156
+ return;
1106
1157
  const idOrHandle = parsed.args.join(" ");
1107
1158
  if (!idOrHandle) {
1108
1159
  formatError("Usage: shopq menu get <id-or-handle>");
@@ -1549,6 +1600,8 @@ function resolvePageId(input) {
1549
1600
  return { type: "handle", handle: input };
1550
1601
  }
1551
1602
  async function handlePageGet(parsed) {
1603
+ if (rejectHandleFlag(parsed, "shopq page get <id-or-handle>"))
1604
+ return;
1552
1605
  const idOrHandle = parsed.args.join(" ");
1553
1606
  if (!idOrHandle) {
1554
1607
  formatError("Usage: shopq page get <id-or-handle>");
@@ -1844,6 +1897,8 @@ function truncate2(str, max) {
1844
1897
  return `${str.slice(0, max - 3)}...`;
1845
1898
  }
1846
1899
  async function handleCollectionGet(parsed) {
1900
+ if (rejectHandleFlag(parsed, "shopq collection get <id-or-handle>"))
1901
+ return;
1847
1902
  const idOrHandle = parsed.args.join(" ");
1848
1903
  if (!idOrHandle) {
1849
1904
  formatError("Usage: shopq collection get <id-or-handle>");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopq",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "A zero-dependency Shopify Admin CLI built on Bun",
5
5
  "type": "module",
6
6
  "license": "MIT",