shop-cli 0.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/LICENSE +21 -0
- package/README.md +392 -0
- package/bin/shop-cli.js +17 -0
- package/bin/shop.js +16 -0
- package/dist/adminClient.d.ts +34 -0
- package/dist/adminClient.js +144 -0
- package/dist/cli/client.d.ts +10 -0
- package/dist/cli/client.js +56 -0
- package/dist/cli/command.d.ts +5 -0
- package/dist/cli/command.js +62 -0
- package/dist/cli/errors.d.ts +4 -0
- package/dist/cli/errors.js +35 -0
- package/dist/cli/gid.d.ts +3 -0
- package/dist/cli/gid.js +42 -0
- package/dist/cli/globalFlags.d.ts +15 -0
- package/dist/cli/globalFlags.js +100 -0
- package/dist/cli/headers.d.ts +2 -0
- package/dist/cli/headers.js +79 -0
- package/dist/cli/help/format.d.ts +8 -0
- package/dist/cli/help/format.js +78 -0
- package/dist/cli/help/registry.d.ts +5 -0
- package/dist/cli/help/registry.js +5651 -0
- package/dist/cli/help/render.d.ts +7 -0
- package/dist/cli/help/render.js +352 -0
- package/dist/cli/help/spec.d.ts +39 -0
- package/dist/cli/help/spec.js +17 -0
- package/dist/cli/input.d.ts +9 -0
- package/dist/cli/input.js +104 -0
- package/dist/cli/introspection/deprecations.d.ts +1 -0
- package/dist/cli/introspection/deprecations.js +83 -0
- package/dist/cli/introspection/format.d.ts +6 -0
- package/dist/cli/introspection/format.js +63 -0
- package/dist/cli/introspection/index.d.ts +14 -0
- package/dist/cli/introspection/index.js +89 -0
- package/dist/cli/introspection/resources.d.ts +1 -0
- package/dist/cli/introspection/resources.js +127 -0
- package/dist/cli/output/computedFields.d.ts +39 -0
- package/dist/cli/output/computedFields.js +104 -0
- package/dist/cli/output.d.ts +37 -0
- package/dist/cli/output.js +332 -0
- package/dist/cli/router.d.ts +29 -0
- package/dist/cli/router.js +480 -0
- package/dist/cli/selection/buildAllSelection.d.ts +13 -0
- package/dist/cli/selection/buildAllSelection.js +108 -0
- package/dist/cli/selection/graphqlSelection.d.ts +5 -0
- package/dist/cli/selection/graphqlSelection.js +301 -0
- package/dist/cli/selection/select.d.ts +13 -0
- package/dist/cli/selection/select.js +136 -0
- package/dist/cli/selection/stripDeprecated.d.ts +2 -0
- package/dist/cli/selection/stripDeprecated.js +63 -0
- package/dist/cli/userErrors.d.ts +4 -0
- package/dist/cli/userErrors.js +41 -0
- package/dist/cli/verbs/_shared.d.ts +38 -0
- package/dist/cli/verbs/_shared.js +180 -0
- package/dist/cli/verbs/abandoned-checkouts.d.ts +6 -0
- package/dist/cli/verbs/abandoned-checkouts.js +259 -0
- package/dist/cli/verbs/app-billing.d.ts +6 -0
- package/dist/cli/verbs/app-billing.js +452 -0
- package/dist/cli/verbs/apps.d.ts +6 -0
- package/dist/cli/verbs/apps.js +296 -0
- package/dist/cli/verbs/articles.d.ts +6 -0
- package/dist/cli/verbs/articles.js +251 -0
- package/dist/cli/verbs/backup.d.ts +6 -0
- package/dist/cli/verbs/backup.js +94 -0
- package/dist/cli/verbs/blogs.d.ts +6 -0
- package/dist/cli/verbs/blogs.js +273 -0
- package/dist/cli/verbs/bulk-operations.d.ts +6 -0
- package/dist/cli/verbs/bulk-operations.js +272 -0
- package/dist/cli/verbs/business-entities.d.ts +6 -0
- package/dist/cli/verbs/business-entities.js +102 -0
- package/dist/cli/verbs/carrier-services.d.ts +6 -0
- package/dist/cli/verbs/carrier-services.js +195 -0
- package/dist/cli/verbs/cart-transforms.d.ts +6 -0
- package/dist/cli/verbs/cart-transforms.js +141 -0
- package/dist/cli/verbs/cash-tracking.d.ts +6 -0
- package/dist/cli/verbs/cash-tracking.js +118 -0
- package/dist/cli/verbs/catalogs.d.ts +6 -0
- package/dist/cli/verbs/catalogs.js +267 -0
- package/dist/cli/verbs/channels.d.ts +6 -0
- package/dist/cli/verbs/channels.js +120 -0
- package/dist/cli/verbs/checkout-branding.d.ts +6 -0
- package/dist/cli/verbs/checkout-branding.js +144 -0
- package/dist/cli/verbs/checkout-profiles.d.ts +6 -0
- package/dist/cli/verbs/checkout-profiles.js +124 -0
- package/dist/cli/verbs/collections.d.ts +6 -0
- package/dist/cli/verbs/collections.js +485 -0
- package/dist/cli/verbs/comments.d.ts +6 -0
- package/dist/cli/verbs/comments.js +160 -0
- package/dist/cli/verbs/companies.d.ts +6 -0
- package/dist/cli/verbs/companies.js +313 -0
- package/dist/cli/verbs/company-contacts.d.ts +6 -0
- package/dist/cli/verbs/company-contacts.js +314 -0
- package/dist/cli/verbs/company-locations.d.ts +6 -0
- package/dist/cli/verbs/company-locations.js +467 -0
- package/dist/cli/verbs/customer-account-pages.d.ts +6 -0
- package/dist/cli/verbs/customer-account-pages.js +97 -0
- package/dist/cli/verbs/customer-payment-methods.d.ts +6 -0
- package/dist/cli/verbs/customer-payment-methods.js +358 -0
- package/dist/cli/verbs/customer-privacy.d.ts +6 -0
- package/dist/cli/verbs/customer-privacy.js +167 -0
- package/dist/cli/verbs/customer-segments.d.ts +6 -0
- package/dist/cli/verbs/customer-segments.js +193 -0
- package/dist/cli/verbs/customers.d.ts +6 -0
- package/dist/cli/verbs/customers.js +656 -0
- package/dist/cli/verbs/delegate-tokens.d.ts +6 -0
- package/dist/cli/verbs/delegate-tokens.js +95 -0
- package/dist/cli/verbs/delivery-customizations.d.ts +6 -0
- package/dist/cli/verbs/delivery-customizations.js +205 -0
- package/dist/cli/verbs/delivery-profile-locations.d.ts +6 -0
- package/dist/cli/verbs/delivery-profile-locations.js +90 -0
- package/dist/cli/verbs/delivery-profiles.d.ts +6 -0
- package/dist/cli/verbs/delivery-profiles.js +207 -0
- package/dist/cli/verbs/delivery-promises.d.ts +6 -0
- package/dist/cli/verbs/delivery-promises.js +262 -0
- package/dist/cli/verbs/delivery-settings.d.ts +6 -0
- package/dist/cli/verbs/delivery-settings.js +85 -0
- package/dist/cli/verbs/discount-nodes.d.ts +6 -0
- package/dist/cli/verbs/discount-nodes.js +169 -0
- package/dist/cli/verbs/discount-redeem-codes.d.ts +6 -0
- package/dist/cli/verbs/discount-redeem-codes.js +102 -0
- package/dist/cli/verbs/discount-saved-searches.d.ts +6 -0
- package/dist/cli/verbs/discount-saved-searches.js +113 -0
- package/dist/cli/verbs/discounts-automatic.d.ts +6 -0
- package/dist/cli/verbs/discounts-automatic.js +475 -0
- package/dist/cli/verbs/discounts-code.d.ts +6 -0
- package/dist/cli/verbs/discounts-code.js +523 -0
- package/dist/cli/verbs/disputes.d.ts +6 -0
- package/dist/cli/verbs/disputes.js +154 -0
- package/dist/cli/verbs/draft-orders.d.ts +6 -0
- package/dist/cli/verbs/draft-orders.js +429 -0
- package/dist/cli/verbs/events.d.ts +6 -0
- package/dist/cli/verbs/events.js +182 -0
- package/dist/cli/verbs/file-saved-searches.d.ts +6 -0
- package/dist/cli/verbs/file-saved-searches.js +83 -0
- package/dist/cli/verbs/files.d.ts +6 -0
- package/dist/cli/verbs/files.js +213 -0
- package/dist/cli/verbs/finance.d.ts +6 -0
- package/dist/cli/verbs/finance.js +115 -0
- package/dist/cli/verbs/flow.d.ts +6 -0
- package/dist/cli/verbs/flow.js +94 -0
- package/dist/cli/verbs/fulfillment-constraint-rules.d.ts +6 -0
- package/dist/cli/verbs/fulfillment-constraint-rules.js +139 -0
- package/dist/cli/verbs/fulfillment-orders.d.ts +6 -0
- package/dist/cli/verbs/fulfillment-orders.js +674 -0
- package/dist/cli/verbs/fulfillment-services.d.ts +6 -0
- package/dist/cli/verbs/fulfillment-services.js +212 -0
- package/dist/cli/verbs/fulfillments.d.ts +6 -0
- package/dist/cli/verbs/fulfillments.js +273 -0
- package/dist/cli/verbs/gift-cards.d.ts +6 -0
- package/dist/cli/verbs/gift-cards.js +359 -0
- package/dist/cli/verbs/graphql.d.ts +14 -0
- package/dist/cli/verbs/graphql.js +285 -0
- package/dist/cli/verbs/inventory-items.d.ts +6 -0
- package/dist/cli/verbs/inventory-items.js +164 -0
- package/dist/cli/verbs/inventory-shipments.d.ts +6 -0
- package/dist/cli/verbs/inventory-shipments.js +276 -0
- package/dist/cli/verbs/inventory-transfers.d.ts +6 -0
- package/dist/cli/verbs/inventory-transfers.js +396 -0
- package/dist/cli/verbs/inventory.d.ts +6 -0
- package/dist/cli/verbs/inventory.js +551 -0
- package/dist/cli/verbs/locales.d.ts +6 -0
- package/dist/cli/verbs/locales.js +61 -0
- package/dist/cli/verbs/locations.d.ts +6 -0
- package/dist/cli/verbs/locations.js +385 -0
- package/dist/cli/verbs/market-localizations.d.ts +6 -0
- package/dist/cli/verbs/market-localizations.js +291 -0
- package/dist/cli/verbs/market-web-presences.d.ts +6 -0
- package/dist/cli/verbs/market-web-presences.js +139 -0
- package/dist/cli/verbs/marketing-activities.d.ts +6 -0
- package/dist/cli/verbs/marketing-activities.js +353 -0
- package/dist/cli/verbs/marketing-events.d.ts +6 -0
- package/dist/cli/verbs/marketing-events.js +132 -0
- package/dist/cli/verbs/markets.d.ts +6 -0
- package/dist/cli/verbs/markets.js +324 -0
- package/dist/cli/verbs/menus.d.ts +6 -0
- package/dist/cli/verbs/menus.js +251 -0
- package/dist/cli/verbs/metafield-definition-tools.d.ts +6 -0
- package/dist/cli/verbs/metafield-definition-tools.js +289 -0
- package/dist/cli/verbs/metafield-definitions.d.ts +6 -0
- package/dist/cli/verbs/metafield-definitions.js +240 -0
- package/dist/cli/verbs/metafields.d.ts +6 -0
- package/dist/cli/verbs/metafields.js +112 -0
- package/dist/cli/verbs/metaobject-definition-tools.d.ts +6 -0
- package/dist/cli/verbs/metaobject-definition-tools.js +83 -0
- package/dist/cli/verbs/metaobject-definitions.d.ts +6 -0
- package/dist/cli/verbs/metaobject-definitions.js +176 -0
- package/dist/cli/verbs/metaobjects.d.ts +6 -0
- package/dist/cli/verbs/metaobjects.js +297 -0
- package/dist/cli/verbs/mobile-platform-applications.d.ts +6 -0
- package/dist/cli/verbs/mobile-platform-applications.js +247 -0
- package/dist/cli/verbs/order-edit.d.ts +6 -0
- package/dist/cli/verbs/order-edit.js +596 -0
- package/dist/cli/verbs/orders.d.ts +6 -0
- package/dist/cli/verbs/orders.js +781 -0
- package/dist/cli/verbs/pages.d.ts +6 -0
- package/dist/cli/verbs/pages.js +234 -0
- package/dist/cli/verbs/payment-customizations.d.ts +6 -0
- package/dist/cli/verbs/payment-customizations.js +193 -0
- package/dist/cli/verbs/payment-terms.d.ts +6 -0
- package/dist/cli/verbs/payment-terms.js +228 -0
- package/dist/cli/verbs/point-of-sale.d.ts +6 -0
- package/dist/cli/verbs/point-of-sale.js +57 -0
- package/dist/cli/verbs/price-lists.d.ts +6 -0
- package/dist/cli/verbs/price-lists.js +426 -0
- package/dist/cli/verbs/product-feeds.d.ts +6 -0
- package/dist/cli/verbs/product-feeds.js +187 -0
- package/dist/cli/verbs/product-variants.d.ts +6 -0
- package/dist/cli/verbs/product-variants.js +388 -0
- package/dist/cli/verbs/products.d.ts +6 -0
- package/dist/cli/verbs/products.js +1257 -0
- package/dist/cli/verbs/publications.d.ts +6 -0
- package/dist/cli/verbs/publications.js +256 -0
- package/dist/cli/verbs/publishables.d.ts +6 -0
- package/dist/cli/verbs/publishables.js +73 -0
- package/dist/cli/verbs/refunds.d.ts +6 -0
- package/dist/cli/verbs/refunds.js +226 -0
- package/dist/cli/verbs/resource-feedback.d.ts +6 -0
- package/dist/cli/verbs/resource-feedback.js +119 -0
- package/dist/cli/verbs/returnable-fulfillments.d.ts +6 -0
- package/dist/cli/verbs/returnable-fulfillments.js +102 -0
- package/dist/cli/verbs/returns.d.ts +6 -0
- package/dist/cli/verbs/returns.js +506 -0
- package/dist/cli/verbs/reverse-deliveries.d.ts +6 -0
- package/dist/cli/verbs/reverse-deliveries.js +203 -0
- package/dist/cli/verbs/reverse-fulfillment-orders.d.ts +6 -0
- package/dist/cli/verbs/reverse-fulfillment-orders.js +157 -0
- package/dist/cli/verbs/saved-searches.d.ts +6 -0
- package/dist/cli/verbs/saved-searches.js +150 -0
- package/dist/cli/verbs/script-tags.d.ts +6 -0
- package/dist/cli/verbs/script-tags.js +179 -0
- package/dist/cli/verbs/segments.d.ts +6 -0
- package/dist/cli/verbs/segments.js +343 -0
- package/dist/cli/verbs/selling-plan-group-products.d.ts +6 -0
- package/dist/cli/verbs/selling-plan-group-products.js +115 -0
- package/dist/cli/verbs/selling-plan-groups.d.ts +6 -0
- package/dist/cli/verbs/selling-plan-groups.js +208 -0
- package/dist/cli/verbs/server-pixels.d.ts +6 -0
- package/dist/cli/verbs/server-pixels.js +172 -0
- package/dist/cli/verbs/shipping-packages.d.ts +6 -0
- package/dist/cli/verbs/shipping-packages.js +107 -0
- package/dist/cli/verbs/shop-policies.d.ts +6 -0
- package/dist/cli/verbs/shop-policies.js +91 -0
- package/dist/cli/verbs/shop-utils.d.ts +6 -0
- package/dist/cli/verbs/shop-utils.js +147 -0
- package/dist/cli/verbs/shop.d.ts +6 -0
- package/dist/cli/verbs/shop.js +177 -0
- package/dist/cli/verbs/shopify-functions.d.ts +6 -0
- package/dist/cli/verbs/shopify-functions.js +127 -0
- package/dist/cli/verbs/shopify-payments.d.ts +6 -0
- package/dist/cli/verbs/shopify-payments.js +111 -0
- package/dist/cli/verbs/staff.d.ts +6 -0
- package/dist/cli/verbs/staff.js +127 -0
- package/dist/cli/verbs/staged-uploads.d.ts +6 -0
- package/dist/cli/verbs/staged-uploads.js +128 -0
- package/dist/cli/verbs/store-credit.d.ts +6 -0
- package/dist/cli/verbs/store-credit.js +209 -0
- package/dist/cli/verbs/storefront-access-tokens.d.ts +6 -0
- package/dist/cli/verbs/storefront-access-tokens.js +183 -0
- package/dist/cli/verbs/subscription-billing-cycles.d.ts +6 -0
- package/dist/cli/verbs/subscription-billing-cycles.js +391 -0
- package/dist/cli/verbs/subscription-billing.d.ts +6 -0
- package/dist/cli/verbs/subscription-billing.js +391 -0
- package/dist/cli/verbs/subscription-contracts.d.ts +6 -0
- package/dist/cli/verbs/subscription-contracts.js +391 -0
- package/dist/cli/verbs/subscription-drafts.d.ts +6 -0
- package/dist/cli/verbs/subscription-drafts.js +315 -0
- package/dist/cli/verbs/tags.d.ts +6 -0
- package/dist/cli/verbs/tags.js +73 -0
- package/dist/cli/verbs/tax.d.ts +6 -0
- package/dist/cli/verbs/tax.js +114 -0
- package/dist/cli/verbs/taxonomy.d.ts +6 -0
- package/dist/cli/verbs/taxonomy.js +99 -0
- package/dist/cli/verbs/tender-transactions.d.ts +6 -0
- package/dist/cli/verbs/tender-transactions.js +105 -0
- package/dist/cli/verbs/themes.d.ts +6 -0
- package/dist/cli/verbs/themes.js +297 -0
- package/dist/cli/verbs/translations.d.ts +6 -0
- package/dist/cli/verbs/translations.js +221 -0
- package/dist/cli/verbs/types.d.ts +4 -0
- package/dist/cli/verbs/types.js +224 -0
- package/dist/cli/verbs/url-redirects.d.ts +6 -0
- package/dist/cli/verbs/url-redirects.js +407 -0
- package/dist/cli/verbs/validations.d.ts +6 -0
- package/dist/cli/verbs/validations.js +181 -0
- package/dist/cli/verbs/web-pixels.d.ts +6 -0
- package/dist/cli/verbs/web-pixels.js +145 -0
- package/dist/cli/verbs/web-presences.d.ts +6 -0
- package/dist/cli/verbs/web-presences.js +186 -0
- package/dist/cli/verbs/webhooks.d.ts +6 -0
- package/dist/cli/verbs/webhooks.js +336 -0
- package/dist/cli/workflows/files/stagedUploads.d.ts +28 -0
- package/dist/cli/workflows/files/stagedUploads.js +175 -0
- package/dist/cli/workflows/inventory/resolveInventoryItemId.d.ts +6 -0
- package/dist/cli/workflows/inventory/resolveInventoryItemId.js +59 -0
- package/dist/cli/workflows/productVariants/upsert.d.ts +8 -0
- package/dist/cli/workflows/productVariants/upsert.js +110 -0
- package/dist/cli/workflows/products/metafieldsUpsert.d.ts +6 -0
- package/dist/cli/workflows/products/metafieldsUpsert.js +94 -0
- package/dist/cli/workflows/products/publishablePublish.d.ts +21 -0
- package/dist/cli/workflows/products/publishablePublish.js +131 -0
- package/dist/cli/workflows/publications/resolvePublicationId.d.ts +17 -0
- package/dist/cli/workflows/publications/resolvePublicationId.js +93 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +152 -0
- package/dist/defaults.d.ts +2 -0
- package/dist/defaults.js +38 -0
- package/dist/generated/admin-2026-04/index.d.ts +25 -0
- package/dist/generated/admin-2026-04/index.js +70 -0
- package/dist/generated/admin-2026-04/runtime/batcher.d.ts +105 -0
- package/dist/generated/admin-2026-04/runtime/batcher.js +203 -0
- package/dist/generated/admin-2026-04/runtime/createClient.d.ts +17 -0
- package/dist/generated/admin-2026-04/runtime/createClient.js +59 -0
- package/dist/generated/admin-2026-04/runtime/error.d.ts +18 -0
- package/dist/generated/admin-2026-04/runtime/error.js +44 -0
- package/dist/generated/admin-2026-04/runtime/fetcher.d.ts +10 -0
- package/dist/generated/admin-2026-04/runtime/fetcher.js +104 -0
- package/dist/generated/admin-2026-04/runtime/generateGraphqlOperation.d.ts +30 -0
- package/dist/generated/admin-2026-04/runtime/generateGraphqlOperation.js +191 -0
- package/dist/generated/admin-2026-04/runtime/index.d.ts +11 -0
- package/dist/generated/admin-2026-04/runtime/index.js +46 -0
- package/dist/generated/admin-2026-04/runtime/linkTypeMap.d.ts +9 -0
- package/dist/generated/admin-2026-04/runtime/linkTypeMap.js +142 -0
- package/dist/generated/admin-2026-04/runtime/typeSelection.d.ts +28 -0
- package/dist/generated/admin-2026-04/runtime/typeSelection.js +17 -0
- package/dist/generated/admin-2026-04/runtime/types.d.ts +55 -0
- package/dist/generated/admin-2026-04/runtime/types.js +17 -0
- package/dist/generated/admin-2026-04/schema.d.ts +102240 -0
- package/dist/generated/admin-2026-04/schema.graphql +91596 -0
- package/dist/generated/admin-2026-04/schema.js +20322 -0
- package/dist/generated/admin-2026-04/types.d.ts +24224 -0
- package/dist/generated/admin-2026-04/types.js +62299 -0
- package/dist/generated/help/schema-help.d.ts +30 -0
- package/dist/generated/help/schema-help.js +61833 -0
- package/dist/graphqlValidator.d.ts +17 -0
- package/dist/graphqlValidator.js +84 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -0
- package/package.json +65 -0
- package/schema/2026-04.graphql +61256 -0
- package/schema/2026-04.introspection.json +1 -0
|
@@ -0,0 +1,1257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var products_exports = {};
|
|
20
|
+
__export(products_exports, {
|
|
21
|
+
runProducts: () => runProducts
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(products_exports);
|
|
24
|
+
var import_errors = require("../errors");
|
|
25
|
+
var import_gid = require("../gid");
|
|
26
|
+
var import_input = require("../input");
|
|
27
|
+
var import_output = require("../output");
|
|
28
|
+
var import_computedFields = require("../output/computedFields");
|
|
29
|
+
var import_router = require("../router");
|
|
30
|
+
var import_select = require("../selection/select");
|
|
31
|
+
var import_userErrors = require("../userErrors");
|
|
32
|
+
var import_stagedUploads = require("../workflows/files/stagedUploads");
|
|
33
|
+
var import_metafieldsUpsert = require("../workflows/products/metafieldsUpsert");
|
|
34
|
+
var import_publishablePublish = require("../workflows/products/publishablePublish");
|
|
35
|
+
var import_resolvePublicationId = require("../workflows/publications/resolvePublicationId");
|
|
36
|
+
var import_shared = require("./_shared");
|
|
37
|
+
const productMediaSelection = {
|
|
38
|
+
id: true,
|
|
39
|
+
mediaContentType: true,
|
|
40
|
+
status: true,
|
|
41
|
+
alt: true,
|
|
42
|
+
preview: { status: true, image: { url: true } },
|
|
43
|
+
mediaErrors: { code: true, message: true },
|
|
44
|
+
mediaWarnings: { code: true, message: true }
|
|
45
|
+
};
|
|
46
|
+
const productSummarySelection = {
|
|
47
|
+
id: true,
|
|
48
|
+
title: true,
|
|
49
|
+
handle: true,
|
|
50
|
+
status: true,
|
|
51
|
+
updatedAt: true
|
|
52
|
+
};
|
|
53
|
+
const productSummarySelectionForGet = {
|
|
54
|
+
...productSummarySelection,
|
|
55
|
+
...import_computedFields.computedPublicationsSelection
|
|
56
|
+
};
|
|
57
|
+
const productFullSelection = {
|
|
58
|
+
...productSummarySelection,
|
|
59
|
+
createdAt: true,
|
|
60
|
+
tags: true
|
|
61
|
+
};
|
|
62
|
+
const productFullSelectionForGet = {
|
|
63
|
+
...productFullSelection,
|
|
64
|
+
...import_computedFields.computedPublicationsSelection
|
|
65
|
+
};
|
|
66
|
+
const getProductSelection = (view) => {
|
|
67
|
+
if (view === "ids") return { id: true };
|
|
68
|
+
if (view === "full") return productFullSelection;
|
|
69
|
+
if (view === "raw") return {};
|
|
70
|
+
return productSummarySelection;
|
|
71
|
+
};
|
|
72
|
+
const getProductSelectionForGet = (view) => {
|
|
73
|
+
if (view === "ids") return { id: true };
|
|
74
|
+
if (view === "full") return productFullSelectionForGet;
|
|
75
|
+
if (view === "raw") return {};
|
|
76
|
+
return productSummarySelectionForGet;
|
|
77
|
+
};
|
|
78
|
+
const parseTags = (tags) => {
|
|
79
|
+
if (!tags) throw new import_errors.CliError("Missing --tags", 2);
|
|
80
|
+
const parts = tags.split(",").map((t) => t.trim()).filter(Boolean);
|
|
81
|
+
if (parts.length === 0) throw new import_errors.CliError("--tags must include at least one tag", 2);
|
|
82
|
+
return parts;
|
|
83
|
+
};
|
|
84
|
+
const normalizeMediaContentType = (value) => {
|
|
85
|
+
if (!value) return "IMAGE";
|
|
86
|
+
const v = value.toUpperCase();
|
|
87
|
+
if (v === "IMAGE" || v === "VIDEO" || v === "MODEL_3D" || v === "EXTERNAL_VIDEO") return v;
|
|
88
|
+
throw new import_errors.CliError("--media-type must be IMAGE|VIDEO|MODEL_3D|EXTERNAL_VIDEO", 2);
|
|
89
|
+
};
|
|
90
|
+
const normalizeMediaId = (value) => {
|
|
91
|
+
const raw = value.trim();
|
|
92
|
+
if (!raw) throw new import_errors.CliError("Media ID cannot be empty", 2);
|
|
93
|
+
if (raw.startsWith("gid://")) return raw;
|
|
94
|
+
throw new import_errors.CliError(
|
|
95
|
+
`Numeric media ID "${raw}" is ambiguous. Use the full GID from "shop products media list" (e.g. gid://shopify/MediaImage/${raw})`,
|
|
96
|
+
2
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
const mediaTypeToStagedResource = (mediaType) => {
|
|
100
|
+
if (mediaType === "IMAGE") return "IMAGE";
|
|
101
|
+
if (mediaType === "VIDEO") return "VIDEO";
|
|
102
|
+
if (mediaType === "MODEL_3D") return "MODEL_3D";
|
|
103
|
+
throw new import_errors.CliError("--media-type EXTERNAL_VIDEO cannot be used with --file uploads", 2);
|
|
104
|
+
};
|
|
105
|
+
const stagedResourceToMediaType = (resource) => {
|
|
106
|
+
if (resource === "IMAGE") return "IMAGE";
|
|
107
|
+
if (resource === "VIDEO") return "VIDEO";
|
|
108
|
+
if (resource === "MODEL_3D") return "MODEL_3D";
|
|
109
|
+
throw new import_errors.CliError("Only IMAGE|VIDEO|MODEL_3D can be uploaded as product media", 2);
|
|
110
|
+
};
|
|
111
|
+
const runProducts = async ({
|
|
112
|
+
ctx,
|
|
113
|
+
verb,
|
|
114
|
+
argv
|
|
115
|
+
}) => {
|
|
116
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
117
|
+
console.log(
|
|
118
|
+
[
|
|
119
|
+
"Usage:",
|
|
120
|
+
" shop products <verb> [flags]",
|
|
121
|
+
"",
|
|
122
|
+
"Verbs:",
|
|
123
|
+
" create|get|list|count|update|delete|duplicate|set-status|archive|unarchive",
|
|
124
|
+
" by-handle|by-identifier|operation|duplicate-job",
|
|
125
|
+
" tags|types|vendors",
|
|
126
|
+
" change-status|set",
|
|
127
|
+
" join-selling-plan-groups|leave-selling-plan-groups",
|
|
128
|
+
" option-update|options-create|options-delete|options-reorder",
|
|
129
|
+
" combined-listing-update",
|
|
130
|
+
" add-tags|remove-tags|set-price",
|
|
131
|
+
" publish|unpublish|publish-all",
|
|
132
|
+
" bundle-create|bundle-update",
|
|
133
|
+
" metafields upsert",
|
|
134
|
+
" media add|media upload|media list|media remove|media reorder|media update",
|
|
135
|
+
" create-media|update-media|delete-media|reorder-media",
|
|
136
|
+
"",
|
|
137
|
+
"Common output flags:",
|
|
138
|
+
" --view summary|ids|full|raw",
|
|
139
|
+
" --select <path> (repeatable; dot paths; adds to base view selection)",
|
|
140
|
+
" --selection <graphql> (selection override; can be @file.gql)"
|
|
141
|
+
].join("\n")
|
|
142
|
+
);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (verb === "reorder-media") verb = "media reorder";
|
|
146
|
+
if (verb === "by-handle") {
|
|
147
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: { handle: { type: "string" } } });
|
|
148
|
+
const handle = args.handle;
|
|
149
|
+
if (!handle) throw new import_errors.CliError("Missing --handle", 2);
|
|
150
|
+
const selectValues = Array.isArray(args.select) ? args.select : args.select ? [args.select] : [];
|
|
151
|
+
const selectionOverride = typeof args.selection === "string" && args.selection.length > 0;
|
|
152
|
+
const select = !selectionOverride && ctx.view !== "raw" && ctx.view !== "ids" ? Array.from(/* @__PURE__ */ new Set([...selectValues, "resourcePublicationsV2.nodes.publication.name"])) : args.select;
|
|
153
|
+
const includeValues = Array.isArray(args.include) ? args.include : args.include ? [args.include] : [];
|
|
154
|
+
const include = ctx.view === "all" ? Array.from(/* @__PURE__ */ new Set([...includeValues, "resourcePublicationsV2"])) : args.include;
|
|
155
|
+
const selection = (0, import_select.resolveSelection)({
|
|
156
|
+
resource: "products",
|
|
157
|
+
view: ctx.view,
|
|
158
|
+
baseSelection: getProductSelectionForGet(ctx.view),
|
|
159
|
+
select,
|
|
160
|
+
selection: args.selection,
|
|
161
|
+
include,
|
|
162
|
+
ensureId: ctx.quiet,
|
|
163
|
+
defaultConnectionFirst: ctx.view === "all" ? 50 : 10
|
|
164
|
+
});
|
|
165
|
+
const result = await (0, import_router.runQuery)(ctx, { productByHandle: { __args: { handle }, ...selection } });
|
|
166
|
+
if (result === void 0) return;
|
|
167
|
+
const wantsResourcePublicationsV2 = Array.isArray(args.select) && args.select.some((p) => typeof p === "string" && p.startsWith("resourcePublicationsV2"));
|
|
168
|
+
const wantsResourcePublicationsV2ViaSelection = typeof args.selection === "string" && args.selection.includes("resourcePublicationsV2");
|
|
169
|
+
const stripResourcePublicationsV2 = !(wantsResourcePublicationsV2 || wantsResourcePublicationsV2ViaSelection);
|
|
170
|
+
const withComputed = (0, import_computedFields.applyComputedFieldsToNode)(result.productByHandle, {
|
|
171
|
+
view: ctx.view,
|
|
172
|
+
stripResourcePublicationsV2
|
|
173
|
+
});
|
|
174
|
+
(0, import_output.printNode)({ node: withComputed, format: ctx.format, quiet: ctx.quiet });
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (verb === "by-identifier") {
|
|
178
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: { identifier: { type: "string" } } });
|
|
179
|
+
const identifier = (0, import_shared.parseJsonArg)(args.identifier, "--identifier");
|
|
180
|
+
const selectValues = Array.isArray(args.select) ? args.select : args.select ? [args.select] : [];
|
|
181
|
+
const selectionOverride = typeof args.selection === "string" && args.selection.length > 0;
|
|
182
|
+
const select = !selectionOverride && ctx.view !== "raw" && ctx.view !== "ids" ? Array.from(/* @__PURE__ */ new Set([...selectValues, "resourcePublicationsV2.nodes.publication.name"])) : args.select;
|
|
183
|
+
const includeValues = Array.isArray(args.include) ? args.include : args.include ? [args.include] : [];
|
|
184
|
+
const include = ctx.view === "all" ? Array.from(/* @__PURE__ */ new Set([...includeValues, "resourcePublicationsV2"])) : args.include;
|
|
185
|
+
const selection = (0, import_select.resolveSelection)({
|
|
186
|
+
resource: "products",
|
|
187
|
+
view: ctx.view,
|
|
188
|
+
baseSelection: getProductSelectionForGet(ctx.view),
|
|
189
|
+
select,
|
|
190
|
+
selection: args.selection,
|
|
191
|
+
include,
|
|
192
|
+
ensureId: ctx.quiet,
|
|
193
|
+
defaultConnectionFirst: ctx.view === "all" ? 50 : 10
|
|
194
|
+
});
|
|
195
|
+
const result = await (0, import_router.runQuery)(ctx, { productByIdentifier: { __args: { identifier }, ...selection } });
|
|
196
|
+
if (result === void 0) return;
|
|
197
|
+
const wantsResourcePublicationsV2 = Array.isArray(args.select) && args.select.some((p) => typeof p === "string" && p.startsWith("resourcePublicationsV2"));
|
|
198
|
+
const wantsResourcePublicationsV2ViaSelection = typeof args.selection === "string" && args.selection.includes("resourcePublicationsV2");
|
|
199
|
+
const stripResourcePublicationsV2 = !(wantsResourcePublicationsV2 || wantsResourcePublicationsV2ViaSelection);
|
|
200
|
+
const withComputed = (0, import_computedFields.applyComputedFieldsToNode)(result.productByIdentifier, {
|
|
201
|
+
view: ctx.view,
|
|
202
|
+
stripResourcePublicationsV2
|
|
203
|
+
});
|
|
204
|
+
(0, import_output.printNode)({ node: withComputed, format: ctx.format, quiet: ctx.quiet });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (verb === "duplicate-job") {
|
|
208
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
209
|
+
const id = args.id;
|
|
210
|
+
if (typeof id !== "string" || !id) throw new import_errors.CliError("Missing --id", 2);
|
|
211
|
+
const selection = (0, import_select.resolveSelection)({
|
|
212
|
+
typeName: "ProductDuplicateJob",
|
|
213
|
+
view: ctx.view,
|
|
214
|
+
baseSelection: { id: true, done: true },
|
|
215
|
+
select: args.select,
|
|
216
|
+
selection: args.selection,
|
|
217
|
+
include: args.include,
|
|
218
|
+
ensureId: ctx.quiet
|
|
219
|
+
});
|
|
220
|
+
const result = await (0, import_router.runQuery)(ctx, { productDuplicateJob: { __args: { id }, ...selection } });
|
|
221
|
+
if (result === void 0) return;
|
|
222
|
+
(0, import_output.printNode)({ node: result.productDuplicateJob, format: ctx.format, quiet: ctx.quiet });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (verb === "operation") {
|
|
226
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
227
|
+
const id = args.id;
|
|
228
|
+
if (typeof id !== "string" || !id) throw new import_errors.CliError("Missing --id", 2);
|
|
229
|
+
const getProductOperationSelection = (view) => {
|
|
230
|
+
if (view === "raw") return {};
|
|
231
|
+
if (view === "ids") {
|
|
232
|
+
return {
|
|
233
|
+
__typename: true,
|
|
234
|
+
on_ProductBundleOperation: { id: true },
|
|
235
|
+
on_ProductDeleteOperation: { id: true },
|
|
236
|
+
on_ProductDuplicateOperation: { id: true, newProduct: { id: true }, product: { id: true } },
|
|
237
|
+
on_ProductSetOperation: { id: true, product: { id: true } }
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
__typename: true,
|
|
242
|
+
status: true,
|
|
243
|
+
product: { id: true, title: true, handle: true, status: true },
|
|
244
|
+
on_ProductBundleOperation: {
|
|
245
|
+
id: true,
|
|
246
|
+
status: true,
|
|
247
|
+
product: { id: true, title: true },
|
|
248
|
+
userErrors: { field: true, message: true }
|
|
249
|
+
},
|
|
250
|
+
on_ProductDeleteOperation: {
|
|
251
|
+
id: true,
|
|
252
|
+
status: true,
|
|
253
|
+
product: { id: true, title: true },
|
|
254
|
+
userErrors: { field: true, message: true }
|
|
255
|
+
},
|
|
256
|
+
on_ProductDuplicateOperation: {
|
|
257
|
+
id: true,
|
|
258
|
+
status: true,
|
|
259
|
+
product: { id: true, title: true },
|
|
260
|
+
newProduct: { id: true, title: true },
|
|
261
|
+
userErrors: { field: true, message: true }
|
|
262
|
+
},
|
|
263
|
+
on_ProductSetOperation: {
|
|
264
|
+
id: true,
|
|
265
|
+
status: true,
|
|
266
|
+
product: { id: true, title: true },
|
|
267
|
+
userErrors: { code: true, field: true, message: true }
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
const selection = (0, import_select.resolveSelection)({
|
|
272
|
+
typeName: "ProductOperation",
|
|
273
|
+
view: ctx.view,
|
|
274
|
+
baseSelection: getProductOperationSelection(ctx.view),
|
|
275
|
+
select: args.select,
|
|
276
|
+
selection: args.selection,
|
|
277
|
+
include: args.include,
|
|
278
|
+
ensureId: ctx.quiet
|
|
279
|
+
});
|
|
280
|
+
const result = await (0, import_router.runQuery)(ctx, { productOperation: { __args: { id }, ...selection } });
|
|
281
|
+
if (result === void 0) return;
|
|
282
|
+
(0, import_output.printNode)({ node: result.productOperation, format: ctx.format, quiet: ctx.quiet });
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (verb === "tags" || verb === "types" || verb === "vendors") {
|
|
286
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
287
|
+
const first = (0, import_shared.parseFirst)(args.first);
|
|
288
|
+
const after = args.after;
|
|
289
|
+
const reverse = args.reverse;
|
|
290
|
+
const field = verb === "tags" ? "productTags" : verb === "types" ? "productTypes" : "productVendors";
|
|
291
|
+
const result = await (0, import_router.runQuery)(ctx, {
|
|
292
|
+
[field]: {
|
|
293
|
+
__args: { first, after, reverse },
|
|
294
|
+
pageInfo: { hasNextPage: true, endCursor: true },
|
|
295
|
+
nodes: true
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
if (result === void 0) return;
|
|
299
|
+
const connection = result[field];
|
|
300
|
+
if (ctx.quiet) {
|
|
301
|
+
for (const value of connection?.nodes ?? []) {
|
|
302
|
+
if (typeof value === "string" && value) process.stdout.write(`${value}
|
|
303
|
+
`);
|
|
304
|
+
}
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
(0, import_output.printConnection)({
|
|
308
|
+
connection,
|
|
309
|
+
format: ctx.format,
|
|
310
|
+
quiet: false,
|
|
311
|
+
nextPageArgs: { base: `shop products ${verb}`, first, reverse: reverse === true }
|
|
312
|
+
});
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (verb === "change-status") {
|
|
316
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
317
|
+
const productId = (0, import_shared.requireId)(args.id, "Product");
|
|
318
|
+
const status = args.status;
|
|
319
|
+
if (!status) throw new import_errors.CliError("Missing --status (ACTIVE|DRAFT|ARCHIVED)", 2);
|
|
320
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
321
|
+
productChangeStatus: {
|
|
322
|
+
__args: { productId, status },
|
|
323
|
+
product: productSummarySelection,
|
|
324
|
+
userErrors: { field: true, message: true }
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
if (result === void 0) return;
|
|
328
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productChangeStatus, failOnUserErrors: ctx.failOnUserErrors });
|
|
329
|
+
if (ctx.quiet) return console.log(result.productChangeStatus?.product?.id ?? "");
|
|
330
|
+
(0, import_output.printJson)(result.productChangeStatus, ctx.format !== "raw");
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (verb === "set") {
|
|
334
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
335
|
+
argv,
|
|
336
|
+
extraOptions: {
|
|
337
|
+
identifier: { type: "string" },
|
|
338
|
+
synchronous: { type: "string" }
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
const built = (0, import_input.buildInput)({
|
|
342
|
+
inputArg: args.input,
|
|
343
|
+
setArgs: args.set,
|
|
344
|
+
setJsonArgs: args["set-json"]
|
|
345
|
+
});
|
|
346
|
+
if (!built.used) throw new import_errors.CliError("Missing --input or --set/--set-json", 2);
|
|
347
|
+
const identifier = args.identifier ? (0, import_shared.parseJsonArg)(args.identifier, "--identifier") : void 0;
|
|
348
|
+
const synchronousRaw = args.synchronous;
|
|
349
|
+
const synchronous = (() => {
|
|
350
|
+
if (synchronousRaw === void 0 || synchronousRaw === null || synchronousRaw === "") return void 0;
|
|
351
|
+
const v = String(synchronousRaw).toLowerCase();
|
|
352
|
+
if (v === "true" || v === "1") return true;
|
|
353
|
+
if (v === "false" || v === "0") return false;
|
|
354
|
+
throw new import_errors.CliError("--synchronous must be true|false", 2);
|
|
355
|
+
})();
|
|
356
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
357
|
+
productSet: {
|
|
358
|
+
__args: {
|
|
359
|
+
input: built.input,
|
|
360
|
+
...identifier !== void 0 ? { identifier } : {},
|
|
361
|
+
...synchronous !== void 0 ? { synchronous } : {}
|
|
362
|
+
},
|
|
363
|
+
product: productSummarySelection,
|
|
364
|
+
productSetOperation: {
|
|
365
|
+
id: true,
|
|
366
|
+
status: true,
|
|
367
|
+
product: productSummarySelection,
|
|
368
|
+
userErrors: { code: true, field: true, message: true }
|
|
369
|
+
},
|
|
370
|
+
userErrors: { code: true, field: true, message: true }
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
if (result === void 0) return;
|
|
374
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productSet, failOnUserErrors: ctx.failOnUserErrors });
|
|
375
|
+
if (ctx.quiet) {
|
|
376
|
+
const pid = result.productSet?.product?.id;
|
|
377
|
+
const opId = result.productSet?.productSetOperation?.id;
|
|
378
|
+
return console.log(pid ?? opId ?? "");
|
|
379
|
+
}
|
|
380
|
+
(0, import_output.printJson)(result.productSet, ctx.format !== "raw");
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (verb === "join-selling-plan-groups" || verb === "leave-selling-plan-groups") {
|
|
384
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: { "group-ids": { type: "string", multiple: true } } });
|
|
385
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
386
|
+
const sellingPlanGroupIds = (0, import_shared.parseIds)(args["group-ids"], "SellingPlanGroup");
|
|
387
|
+
const mutation = verb === "join-selling-plan-groups" ? "productJoinSellingPlanGroups" : "productLeaveSellingPlanGroups";
|
|
388
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
389
|
+
[mutation]: {
|
|
390
|
+
__args: { id, sellingPlanGroupIds },
|
|
391
|
+
product: { id: true, title: true },
|
|
392
|
+
userErrors: { field: true, message: true }
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
if (result === void 0) return;
|
|
396
|
+
const payload = result[mutation];
|
|
397
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload, failOnUserErrors: ctx.failOnUserErrors });
|
|
398
|
+
if (ctx.quiet) return console.log(payload?.product?.id ?? "");
|
|
399
|
+
(0, import_output.printJson)(payload, ctx.format !== "raw");
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (verb === "create-media" || verb === "update-media") {
|
|
403
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
404
|
+
argv,
|
|
405
|
+
extraOptions: {
|
|
406
|
+
"product-id": { type: "string" },
|
|
407
|
+
media: { type: "string" }
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const productId = (0, import_shared.requireId)(args["product-id"], "Product");
|
|
411
|
+
const media = (0, import_shared.parseJsonArg)(args.media, "--media");
|
|
412
|
+
if (!Array.isArray(media)) throw new import_errors.CliError("--media must be a JSON array", 2);
|
|
413
|
+
const mutation = verb === "create-media" ? "productCreateMedia" : "productUpdateMedia";
|
|
414
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
415
|
+
[mutation]: {
|
|
416
|
+
__args: { productId, media },
|
|
417
|
+
media: productMediaSelection,
|
|
418
|
+
mediaUserErrors: { code: true, field: true, message: true },
|
|
419
|
+
product: { id: true, title: true }
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
if (result === void 0) return;
|
|
423
|
+
const payload = result[mutation];
|
|
424
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload, failOnUserErrors: ctx.failOnUserErrors });
|
|
425
|
+
if (ctx.quiet) return console.log(payload?.product?.id ?? "");
|
|
426
|
+
(0, import_output.printJson)(payload, ctx.format !== "raw");
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (verb === "delete-media") {
|
|
430
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
431
|
+
argv,
|
|
432
|
+
extraOptions: {
|
|
433
|
+
"product-id": { type: "string" },
|
|
434
|
+
"media-ids": { type: "string", multiple: true }
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
const productId = (0, import_shared.requireId)(args["product-id"], "Product");
|
|
438
|
+
const mediaIds = (0, import_shared.parseStringList)(args["media-ids"], "--media-ids");
|
|
439
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
440
|
+
productDeleteMedia: {
|
|
441
|
+
__args: { productId, mediaIds },
|
|
442
|
+
deletedMediaIds: true,
|
|
443
|
+
deletedProductImageIds: true,
|
|
444
|
+
mediaUserErrors: { code: true, field: true, message: true },
|
|
445
|
+
product: { id: true, title: true }
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
if (result === void 0) return;
|
|
449
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productDeleteMedia, failOnUserErrors: ctx.failOnUserErrors });
|
|
450
|
+
if (ctx.quiet) return console.log(result.productDeleteMedia?.product?.id ?? "");
|
|
451
|
+
(0, import_output.printJson)(result.productDeleteMedia, ctx.format !== "raw");
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (verb === "option-update") {
|
|
455
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
456
|
+
argv,
|
|
457
|
+
extraOptions: {
|
|
458
|
+
"product-id": { type: "string" },
|
|
459
|
+
option: { type: "string" },
|
|
460
|
+
"option-values-to-add": { type: "string" },
|
|
461
|
+
"option-values-to-delete": { type: "string" },
|
|
462
|
+
"option-values-to-update": { type: "string" },
|
|
463
|
+
"variant-strategy": { type: "string" }
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
const productId = (0, import_shared.requireId)(args["product-id"], "Product");
|
|
467
|
+
const option = (0, import_shared.parseJsonArg)(args.option, "--option");
|
|
468
|
+
const optionValuesToAdd = args["option-values-to-add"] ? (0, import_shared.parseJsonArg)(args["option-values-to-add"], "--option-values-to-add") : void 0;
|
|
469
|
+
const optionValuesToDelete = args["option-values-to-delete"] ? (0, import_shared.parseJsonArg)(args["option-values-to-delete"], "--option-values-to-delete") : void 0;
|
|
470
|
+
const optionValuesToUpdate = args["option-values-to-update"] ? (0, import_shared.parseJsonArg)(args["option-values-to-update"], "--option-values-to-update") : void 0;
|
|
471
|
+
const variantStrategy = args["variant-strategy"];
|
|
472
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
473
|
+
productOptionUpdate: {
|
|
474
|
+
__args: {
|
|
475
|
+
productId,
|
|
476
|
+
option,
|
|
477
|
+
...optionValuesToAdd !== void 0 ? { optionValuesToAdd } : {},
|
|
478
|
+
...optionValuesToDelete !== void 0 ? { optionValuesToDelete } : {},
|
|
479
|
+
...optionValuesToUpdate !== void 0 ? { optionValuesToUpdate } : {},
|
|
480
|
+
...variantStrategy ? { variantStrategy } : {}
|
|
481
|
+
},
|
|
482
|
+
product: productSummarySelection,
|
|
483
|
+
userErrors: { code: true, field: true, message: true }
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
if (result === void 0) return;
|
|
487
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productOptionUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
488
|
+
if (ctx.quiet) return console.log(result.productOptionUpdate?.product?.id ?? "");
|
|
489
|
+
(0, import_output.printJson)(result.productOptionUpdate, ctx.format !== "raw");
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (verb === "options-create") {
|
|
493
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
494
|
+
argv,
|
|
495
|
+
extraOptions: {
|
|
496
|
+
"product-id": { type: "string" },
|
|
497
|
+
options: { type: "string" },
|
|
498
|
+
"variant-strategy": { type: "string" }
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
const productId = (0, import_shared.requireId)(args["product-id"], "Product");
|
|
502
|
+
const options = (0, import_shared.parseJsonArg)(args.options, "--options");
|
|
503
|
+
if (!Array.isArray(options)) throw new import_errors.CliError("--options must be a JSON array", 2);
|
|
504
|
+
const variantStrategy = args["variant-strategy"];
|
|
505
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
506
|
+
productOptionsCreate: {
|
|
507
|
+
__args: {
|
|
508
|
+
productId,
|
|
509
|
+
options,
|
|
510
|
+
...variantStrategy ? { variantStrategy } : {}
|
|
511
|
+
},
|
|
512
|
+
product: productSummarySelection,
|
|
513
|
+
userErrors: { code: true, field: true, message: true }
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
if (result === void 0) return;
|
|
517
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productOptionsCreate, failOnUserErrors: ctx.failOnUserErrors });
|
|
518
|
+
if (ctx.quiet) return console.log(result.productOptionsCreate?.product?.id ?? "");
|
|
519
|
+
(0, import_output.printJson)(result.productOptionsCreate, ctx.format !== "raw");
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (verb === "options-delete") {
|
|
523
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
524
|
+
argv,
|
|
525
|
+
extraOptions: {
|
|
526
|
+
"product-id": { type: "string" },
|
|
527
|
+
"option-ids": { type: "string", multiple: true },
|
|
528
|
+
strategy: { type: "string" }
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
const productId = (0, import_shared.requireId)(args["product-id"], "Product");
|
|
532
|
+
const options = (0, import_shared.parseStringList)(args["option-ids"], "--option-ids");
|
|
533
|
+
const strategy = args.strategy;
|
|
534
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
535
|
+
productOptionsDelete: {
|
|
536
|
+
__args: { productId, options, ...strategy ? { strategy } : {} },
|
|
537
|
+
deletedOptionsIds: true,
|
|
538
|
+
product: productSummarySelection,
|
|
539
|
+
userErrors: { code: true, field: true, message: true }
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
if (result === void 0) return;
|
|
543
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productOptionsDelete, failOnUserErrors: ctx.failOnUserErrors });
|
|
544
|
+
if (ctx.quiet) return console.log(result.productOptionsDelete?.product?.id ?? "");
|
|
545
|
+
(0, import_output.printJson)(result.productOptionsDelete, ctx.format !== "raw");
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (verb === "options-reorder") {
|
|
549
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
550
|
+
argv,
|
|
551
|
+
extraOptions: {
|
|
552
|
+
"product-id": { type: "string" },
|
|
553
|
+
options: { type: "string" }
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
const productId = (0, import_shared.requireId)(args["product-id"], "Product");
|
|
557
|
+
const options = (0, import_shared.parseJsonArg)(args.options, "--options");
|
|
558
|
+
if (!Array.isArray(options)) throw new import_errors.CliError("--options must be a JSON array", 2);
|
|
559
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
560
|
+
productOptionsReorder: {
|
|
561
|
+
__args: { productId, options },
|
|
562
|
+
product: productSummarySelection,
|
|
563
|
+
userErrors: { code: true, field: true, message: true }
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
if (result === void 0) return;
|
|
567
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productOptionsReorder, failOnUserErrors: ctx.failOnUserErrors });
|
|
568
|
+
if (ctx.quiet) return console.log(result.productOptionsReorder?.product?.id ?? "");
|
|
569
|
+
(0, import_output.printJson)(result.productOptionsReorder, ctx.format !== "raw");
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (verb === "combined-listing-update") {
|
|
573
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
574
|
+
argv,
|
|
575
|
+
extraOptions: {
|
|
576
|
+
"parent-product-id": { type: "string" },
|
|
577
|
+
title: { type: "string" },
|
|
578
|
+
"products-added": { type: "string" },
|
|
579
|
+
"products-edited": { type: "string" },
|
|
580
|
+
"products-removed-ids": { type: "string", multiple: true },
|
|
581
|
+
"options-and-values": { type: "string" }
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
const parentProductId = (0, import_shared.requireId)(args["parent-product-id"], "Product");
|
|
585
|
+
const optionsAndValues = args["options-and-values"] ? (0, import_shared.parseJsonArg)(args["options-and-values"], "--options-and-values") : void 0;
|
|
586
|
+
const productsAdded = args["products-added"] ? (0, import_shared.parseJsonArg)(args["products-added"], "--products-added") : void 0;
|
|
587
|
+
const productsEdited = args["products-edited"] ? (0, import_shared.parseJsonArg)(args["products-edited"], "--products-edited") : void 0;
|
|
588
|
+
const productsRemovedIds = args["products-removed-ids"] ? (0, import_shared.parseIds)(args["products-removed-ids"], "Product") : void 0;
|
|
589
|
+
const title = args.title;
|
|
590
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
591
|
+
combinedListingUpdate: {
|
|
592
|
+
__args: {
|
|
593
|
+
parentProductId,
|
|
594
|
+
...title ? { title } : {},
|
|
595
|
+
...optionsAndValues !== void 0 ? { optionsAndValues } : {},
|
|
596
|
+
...productsAdded !== void 0 ? { productsAdded } : {},
|
|
597
|
+
...productsEdited !== void 0 ? { productsEdited } : {},
|
|
598
|
+
...productsRemovedIds !== void 0 ? { productsRemovedIds } : {}
|
|
599
|
+
},
|
|
600
|
+
product: productSummarySelection,
|
|
601
|
+
userErrors: { code: true, field: true, message: true }
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
if (result === void 0) return;
|
|
605
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.combinedListingUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
606
|
+
if (ctx.quiet) return console.log(result.combinedListingUpdate?.product?.id ?? "");
|
|
607
|
+
(0, import_output.printJson)(result.combinedListingUpdate, ctx.format !== "raw");
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (verb === "bundle-create" || verb === "bundle-update") {
|
|
611
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
612
|
+
const built = (0, import_input.buildInput)({
|
|
613
|
+
inputArg: args.input,
|
|
614
|
+
setArgs: args.set,
|
|
615
|
+
setJsonArgs: args["set-json"]
|
|
616
|
+
});
|
|
617
|
+
if (!built.used) throw new import_errors.CliError("Missing --input or --set/--set-json", 2);
|
|
618
|
+
const mutation = verb === "bundle-create" ? "productBundleCreate" : "productBundleUpdate";
|
|
619
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
620
|
+
[mutation]: {
|
|
621
|
+
__args: { input: built.input },
|
|
622
|
+
productBundleOperation: {
|
|
623
|
+
id: true,
|
|
624
|
+
status: true,
|
|
625
|
+
product: { id: true, title: true },
|
|
626
|
+
userErrors: { field: true, message: true }
|
|
627
|
+
},
|
|
628
|
+
userErrors: { field: true, message: true }
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
if (result === void 0) return;
|
|
632
|
+
const payload = result[mutation];
|
|
633
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload, failOnUserErrors: ctx.failOnUserErrors });
|
|
634
|
+
if (ctx.quiet) return console.log(payload?.productBundleOperation?.id ?? "");
|
|
635
|
+
(0, import_output.printJson)(payload, ctx.format !== "raw");
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (verb === "count") {
|
|
639
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
640
|
+
argv,
|
|
641
|
+
extraOptions: {
|
|
642
|
+
limit: { type: "string" },
|
|
643
|
+
"saved-search-id": { type: "string" }
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
const query = args.query;
|
|
647
|
+
const limitRaw = args.limit;
|
|
648
|
+
const savedSearchIdRaw = args["saved-search-id"];
|
|
649
|
+
const limit = limitRaw === void 0 || limitRaw === null || limitRaw === "" ? void 0 : Number(limitRaw);
|
|
650
|
+
if (limit !== void 0 && (!Number.isFinite(limit) || limit <= 0)) {
|
|
651
|
+
throw new import_errors.CliError("--limit must be a positive number", 2);
|
|
652
|
+
}
|
|
653
|
+
const savedSearchId = savedSearchIdRaw ? (0, import_gid.coerceGid)(String(savedSearchIdRaw), "SavedSearch") : void 0;
|
|
654
|
+
const result = await (0, import_router.runQuery)(ctx, {
|
|
655
|
+
productsCount: {
|
|
656
|
+
__args: {
|
|
657
|
+
...query ? { query } : {},
|
|
658
|
+
...savedSearchId ? { savedSearchId } : {},
|
|
659
|
+
...limit !== void 0 ? { limit: Math.floor(limit) } : {}
|
|
660
|
+
},
|
|
661
|
+
count: true,
|
|
662
|
+
precision: true
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
if (result === void 0) return;
|
|
666
|
+
if (ctx.quiet) return console.log(result.productsCount?.count ?? "");
|
|
667
|
+
(0, import_output.printJson)(result.productsCount, ctx.format !== "raw");
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (verb === "publish" || verb === "unpublish") {
|
|
671
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
672
|
+
argv,
|
|
673
|
+
extraOptions: {
|
|
674
|
+
"publication-id": { type: "string", multiple: true },
|
|
675
|
+
publication: { type: "string", multiple: true },
|
|
676
|
+
at: { type: "string" },
|
|
677
|
+
now: { type: "boolean" }
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
const publicationIds = args["publication-id"] ?? [];
|
|
681
|
+
const publicationNames = args.publication ?? [];
|
|
682
|
+
const resolvedPublicationIds = await (0, import_publishablePublish.resolvePublicationIds)({
|
|
683
|
+
ctx,
|
|
684
|
+
publicationIds,
|
|
685
|
+
publicationNames
|
|
686
|
+
});
|
|
687
|
+
if (verb === "publish") {
|
|
688
|
+
const publishDate = (0, import_publishablePublish.parsePublishDate)({ at: args.at, now: args.now });
|
|
689
|
+
const payload2 = await (0, import_publishablePublish.publishProduct)({
|
|
690
|
+
ctx,
|
|
691
|
+
id: args.id,
|
|
692
|
+
publicationIds: resolvedPublicationIds,
|
|
693
|
+
publishDate
|
|
694
|
+
});
|
|
695
|
+
if (payload2 === void 0) return;
|
|
696
|
+
if (ctx.quiet) return console.log(payload2?.publishable?.id ?? "");
|
|
697
|
+
(0, import_output.printJson)(payload2);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const payload = await (0, import_publishablePublish.unpublishProduct)({
|
|
701
|
+
ctx,
|
|
702
|
+
id: args.id,
|
|
703
|
+
publicationIds: resolvedPublicationIds
|
|
704
|
+
});
|
|
705
|
+
if (payload === void 0) return;
|
|
706
|
+
if (ctx.quiet) return console.log(payload?.publishable?.id ?? "");
|
|
707
|
+
(0, import_output.printJson)(payload);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (verb === "publish-all") {
|
|
711
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
712
|
+
argv,
|
|
713
|
+
extraOptions: {
|
|
714
|
+
at: { type: "string" },
|
|
715
|
+
now: { type: "boolean" }
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
if (ctx.dryRun) {
|
|
719
|
+
await (0, import_resolvePublicationId.listPublications)(ctx);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const publishDate = (0, import_publishablePublish.parsePublishDate)({ at: args.at, now: args.now });
|
|
723
|
+
const publications = await (0, import_resolvePublicationId.listPublications)(ctx);
|
|
724
|
+
const publicationIds = publications.map((p) => p.id).filter(Boolean);
|
|
725
|
+
if (publicationIds.length === 0) throw new import_errors.CliError("No publications found to publish to", 2);
|
|
726
|
+
const payload = await (0, import_publishablePublish.publishProduct)({
|
|
727
|
+
ctx,
|
|
728
|
+
id: args.id,
|
|
729
|
+
publicationIds,
|
|
730
|
+
publishDate
|
|
731
|
+
});
|
|
732
|
+
if (payload === void 0) return;
|
|
733
|
+
if (ctx.quiet) return console.log(payload?.publishable?.id ?? "");
|
|
734
|
+
(0, import_output.printJson)(payload);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (verb === "metafields upsert") {
|
|
738
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
739
|
+
const built = (0, import_input.buildInput)({
|
|
740
|
+
inputArg: args.input,
|
|
741
|
+
setArgs: args.set,
|
|
742
|
+
setJsonArgs: args["set-json"]
|
|
743
|
+
});
|
|
744
|
+
if (!built.used) throw new import_errors.CliError("Missing --input or --set/--set-json", 2);
|
|
745
|
+
const result = await (0, import_metafieldsUpsert.metafieldsUpsert)({ ctx, id: args.id, input: built.input });
|
|
746
|
+
if (result === void 0) return;
|
|
747
|
+
(0, import_output.printJson)(result);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
if (verb === "get") {
|
|
751
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
752
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
753
|
+
const selectValues = Array.isArray(args.select) ? args.select : args.select ? [args.select] : [];
|
|
754
|
+
const selectionOverride = typeof args.selection === "string" && args.selection.length > 0;
|
|
755
|
+
const select = !selectionOverride && ctx.view !== "raw" && ctx.view !== "ids" ? Array.from(/* @__PURE__ */ new Set([...selectValues, "resourcePublicationsV2.nodes.publication.name"])) : args.select;
|
|
756
|
+
const includeValues = Array.isArray(args.include) ? args.include : args.include ? [args.include] : [];
|
|
757
|
+
const include = ctx.view === "all" ? Array.from(/* @__PURE__ */ new Set([...includeValues, "resourcePublicationsV2"])) : args.include;
|
|
758
|
+
const selection = (0, import_select.resolveSelection)({
|
|
759
|
+
resource: "products",
|
|
760
|
+
view: ctx.view,
|
|
761
|
+
baseSelection: getProductSelectionForGet(ctx.view),
|
|
762
|
+
select,
|
|
763
|
+
selection: args.selection,
|
|
764
|
+
include,
|
|
765
|
+
ensureId: ctx.quiet,
|
|
766
|
+
defaultConnectionFirst: ctx.view === "all" ? 50 : 10
|
|
767
|
+
});
|
|
768
|
+
const result = await (0, import_router.runQuery)(ctx, { product: { __args: { id }, ...selection } });
|
|
769
|
+
if (result === void 0) return;
|
|
770
|
+
const wantsResourcePublicationsV2 = Array.isArray(args.select) && args.select.some((p) => typeof p === "string" && p.startsWith("resourcePublicationsV2"));
|
|
771
|
+
const wantsResourcePublicationsV2ViaSelection = typeof args.selection === "string" && args.selection.includes("resourcePublicationsV2");
|
|
772
|
+
const stripResourcePublicationsV2 = !(wantsResourcePublicationsV2 || wantsResourcePublicationsV2ViaSelection);
|
|
773
|
+
const withComputed = (0, import_computedFields.applyComputedFieldsToNode)(result.product, {
|
|
774
|
+
view: ctx.view,
|
|
775
|
+
stripResourcePublicationsV2
|
|
776
|
+
});
|
|
777
|
+
(0, import_output.printNode)({ node: withComputed, format: ctx.format, quiet: ctx.quiet });
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
if (verb === "list") {
|
|
781
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
782
|
+
argv,
|
|
783
|
+
extraOptions: {
|
|
784
|
+
published: { type: "boolean" }
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
const first = (0, import_shared.parseFirst)(args.first);
|
|
788
|
+
const after = args.after;
|
|
789
|
+
const userQuery = typeof args.query === "string" && args.query.trim() ? args.query.trim() : void 0;
|
|
790
|
+
const published = args.published === true;
|
|
791
|
+
const publishedFilter = "published_status:published";
|
|
792
|
+
const query = published && typeof userQuery === "string" && userQuery.includes(publishedFilter) ? userQuery : published ? userQuery ? `${userQuery} ${publishedFilter}` : publishedFilter : userQuery;
|
|
793
|
+
const reverse = args.reverse;
|
|
794
|
+
const sortKey = args.sort;
|
|
795
|
+
const nodeSelection = (0, import_select.resolveSelection)({
|
|
796
|
+
resource: "products",
|
|
797
|
+
view: ctx.view,
|
|
798
|
+
baseSelection: getProductSelection(ctx.view),
|
|
799
|
+
select: args.select,
|
|
800
|
+
selection: args.selection,
|
|
801
|
+
include: args.include,
|
|
802
|
+
ensureId: ctx.quiet
|
|
803
|
+
});
|
|
804
|
+
const result = await (0, import_router.runQuery)(ctx, {
|
|
805
|
+
products: {
|
|
806
|
+
__args: { first, after, query, reverse, sortKey },
|
|
807
|
+
pageInfo: { hasNextPage: true, endCursor: true },
|
|
808
|
+
nodes: nodeSelection
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
if (result === void 0) return;
|
|
812
|
+
(0, import_output.printConnection)({
|
|
813
|
+
connection: result.products,
|
|
814
|
+
format: ctx.format,
|
|
815
|
+
quiet: ctx.quiet,
|
|
816
|
+
nextPageArgs: (0, import_shared.buildListNextPageArgs)(
|
|
817
|
+
"products",
|
|
818
|
+
{ first, query: userQuery, sort: sortKey, reverse },
|
|
819
|
+
published ? [{ flag: "--published", value: true }] : void 0
|
|
820
|
+
)
|
|
821
|
+
});
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (verb === "create") {
|
|
825
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
826
|
+
const built = (0, import_input.buildInput)({
|
|
827
|
+
inputArg: args.input,
|
|
828
|
+
setArgs: args.set,
|
|
829
|
+
setJsonArgs: args["set-json"]
|
|
830
|
+
});
|
|
831
|
+
if (!built.used) throw new import_errors.CliError("Missing --input or --set/--set-json", 2);
|
|
832
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
833
|
+
productCreate: {
|
|
834
|
+
__args: { input: built.input },
|
|
835
|
+
product: productSummarySelection,
|
|
836
|
+
userErrors: { field: true, message: true }
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
if (result === void 0) return;
|
|
840
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productCreate, failOnUserErrors: ctx.failOnUserErrors });
|
|
841
|
+
if (ctx.quiet) return console.log(result.productCreate?.product?.id ?? "");
|
|
842
|
+
(0, import_output.printJson)(result.productCreate, ctx.format !== "raw");
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (verb === "archive" || verb === "unarchive") {
|
|
846
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
847
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
848
|
+
const status = verb === "archive" ? "ARCHIVED" : args.status ?? "DRAFT";
|
|
849
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
850
|
+
productUpdate: {
|
|
851
|
+
__args: { input: { id, status } },
|
|
852
|
+
product: productSummarySelection,
|
|
853
|
+
userErrors: { field: true, message: true }
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
if (result === void 0) return;
|
|
857
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
858
|
+
if (ctx.quiet) return console.log(result.productUpdate?.product?.id ?? "");
|
|
859
|
+
(0, import_output.printJson)(result.productUpdate, ctx.format !== "raw");
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
if (verb === "update") {
|
|
863
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
864
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
865
|
+
const built = (0, import_input.buildInput)({
|
|
866
|
+
inputArg: args.input,
|
|
867
|
+
setArgs: args.set,
|
|
868
|
+
setJsonArgs: args["set-json"]
|
|
869
|
+
});
|
|
870
|
+
if (!built.used) throw new import_errors.CliError("Missing --input or --set/--set-json", 2);
|
|
871
|
+
const input = { ...built.input, id };
|
|
872
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
873
|
+
productUpdate: {
|
|
874
|
+
__args: { input },
|
|
875
|
+
product: productSummarySelection,
|
|
876
|
+
userErrors: { field: true, message: true }
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
if (result === void 0) return;
|
|
880
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
881
|
+
if (ctx.quiet) return console.log(result.productUpdate?.product?.id ?? "");
|
|
882
|
+
(0, import_output.printJson)(result.productUpdate, ctx.format !== "raw");
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
if (verb === "delete") {
|
|
886
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
887
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
888
|
+
if (!args.yes) throw new import_errors.CliError("Refusing to delete without --yes", 2);
|
|
889
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
890
|
+
productDelete: {
|
|
891
|
+
__args: { input: { id } },
|
|
892
|
+
deletedProductId: true,
|
|
893
|
+
userErrors: { field: true, message: true }
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
if (result === void 0) return;
|
|
897
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productDelete, failOnUserErrors: ctx.failOnUserErrors });
|
|
898
|
+
if (ctx.quiet) return console.log(result.productDelete?.deletedProductId ?? "");
|
|
899
|
+
(0, import_output.printJson)(result.productDelete, ctx.format !== "raw");
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (verb === "duplicate") {
|
|
903
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
904
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
905
|
+
const built = (0, import_input.buildInput)({
|
|
906
|
+
inputArg: void 0,
|
|
907
|
+
setArgs: args.set,
|
|
908
|
+
setJsonArgs: args["set-json"]
|
|
909
|
+
});
|
|
910
|
+
let newTitle = args["new-title"] ?? (built.used ? built.input?.newTitle : void 0);
|
|
911
|
+
if (!newTitle) {
|
|
912
|
+
const original = await (0, import_router.runQuery)(ctx, { product: { __args: { id }, title: true } });
|
|
913
|
+
if (original === void 0) return;
|
|
914
|
+
const title = original.product?.title;
|
|
915
|
+
if (!title) throw new import_errors.CliError("Could not resolve original product title to auto-generate newTitle", 2);
|
|
916
|
+
newTitle = `${title} (Copy)`;
|
|
917
|
+
}
|
|
918
|
+
const mutationArgs = {
|
|
919
|
+
productId: id,
|
|
920
|
+
newTitle,
|
|
921
|
+
...built.used ? built.input : {}
|
|
922
|
+
};
|
|
923
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
924
|
+
productDuplicate: {
|
|
925
|
+
__args: mutationArgs,
|
|
926
|
+
newProduct: productSummarySelection,
|
|
927
|
+
userErrors: { field: true, message: true }
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
if (result === void 0) return;
|
|
931
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productDuplicate, failOnUserErrors: ctx.failOnUserErrors });
|
|
932
|
+
if (ctx.quiet) return console.log(result.productDuplicate?.newProduct?.id ?? "");
|
|
933
|
+
(0, import_output.printJson)(result.productDuplicate, ctx.format !== "raw");
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (verb === "set-status") {
|
|
937
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
938
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
939
|
+
const status = args.status;
|
|
940
|
+
if (!status) throw new import_errors.CliError("Missing --status (ACTIVE|DRAFT|ARCHIVED)", 2);
|
|
941
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
942
|
+
productUpdate: {
|
|
943
|
+
__args: { input: { id, status } },
|
|
944
|
+
product: productSummarySelection,
|
|
945
|
+
userErrors: { field: true, message: true }
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
if (result === void 0) return;
|
|
949
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
950
|
+
if (ctx.quiet) return console.log(result.productUpdate?.product?.id ?? "");
|
|
951
|
+
(0, import_output.printJson)(result.productUpdate, ctx.format !== "raw");
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (verb === "set-price") {
|
|
955
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
956
|
+
argv,
|
|
957
|
+
extraOptions: {
|
|
958
|
+
"variant-id": { type: "string" },
|
|
959
|
+
price: { type: "string" },
|
|
960
|
+
"compare-at-price": { type: "string" },
|
|
961
|
+
"product-id": { type: "string" }
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
const variantId = (0, import_shared.requireId)(args["variant-id"], "ProductVariant");
|
|
965
|
+
const price = args.price;
|
|
966
|
+
if (!price) throw new import_errors.CliError("Missing --price", 2);
|
|
967
|
+
const compareAtPrice = args["compare-at-price"];
|
|
968
|
+
const explicitProductId = args["product-id"];
|
|
969
|
+
let productId;
|
|
970
|
+
if (explicitProductId) {
|
|
971
|
+
productId = (0, import_gid.coerceGid)(explicitProductId, "Product");
|
|
972
|
+
} else {
|
|
973
|
+
if (ctx.dryRun) {
|
|
974
|
+
throw new import_errors.CliError(
|
|
975
|
+
"In --dry-run mode, --product-id is required because resolving a productId from a variantId requires executing a query.",
|
|
976
|
+
2
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
const resolved = await (0, import_router.runQuery)(ctx, {
|
|
980
|
+
productVariant: { __args: { id: variantId }, product: { id: true } }
|
|
981
|
+
});
|
|
982
|
+
if (resolved === void 0) return;
|
|
983
|
+
const pid = resolved.productVariant?.product?.id;
|
|
984
|
+
if (!pid) throw new import_errors.CliError("Could not resolve productId from --variant-id", 2);
|
|
985
|
+
productId = pid;
|
|
986
|
+
}
|
|
987
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
988
|
+
productVariantsBulkUpdate: {
|
|
989
|
+
__args: {
|
|
990
|
+
productId,
|
|
991
|
+
variants: [
|
|
992
|
+
{
|
|
993
|
+
id: variantId,
|
|
994
|
+
price,
|
|
995
|
+
...compareAtPrice ? { compareAtPrice } : {}
|
|
996
|
+
}
|
|
997
|
+
]
|
|
998
|
+
},
|
|
999
|
+
userErrors: { field: true, message: true }
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
if (result === void 0) return;
|
|
1003
|
+
(0, import_userErrors.maybeFailOnUserErrors)({
|
|
1004
|
+
payload: result.productVariantsBulkUpdate,
|
|
1005
|
+
failOnUserErrors: ctx.failOnUserErrors
|
|
1006
|
+
});
|
|
1007
|
+
if (ctx.quiet) return console.log(variantId);
|
|
1008
|
+
(0, import_output.printJson)(result.productVariantsBulkUpdate, ctx.format !== "raw");
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (verb === "add-tags" || verb === "remove-tags") {
|
|
1012
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
1013
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
1014
|
+
const tags = parseTags(args.tags);
|
|
1015
|
+
const mutationField = verb === "add-tags" ? "tagsAdd" : "tagsRemove";
|
|
1016
|
+
const request = {
|
|
1017
|
+
[mutationField]: {
|
|
1018
|
+
__args: { id, tags },
|
|
1019
|
+
node: { id: true },
|
|
1020
|
+
userErrors: { field: true, message: true }
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
const result = await (0, import_router.runMutation)(ctx, request);
|
|
1024
|
+
if (result === void 0) return;
|
|
1025
|
+
const payload = result[mutationField];
|
|
1026
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload, failOnUserErrors: ctx.failOnUserErrors });
|
|
1027
|
+
if (ctx.quiet) return console.log(payload?.node?.id ?? "");
|
|
1028
|
+
(0, import_output.printJson)(payload, ctx.format !== "raw");
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
if (verb === "media add") {
|
|
1032
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
1033
|
+
argv,
|
|
1034
|
+
extraOptions: {
|
|
1035
|
+
url: { type: "string", multiple: true },
|
|
1036
|
+
alt: { type: "string" },
|
|
1037
|
+
"media-type": { type: "string" }
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
1041
|
+
const urls = args.url ?? [];
|
|
1042
|
+
if (urls.length === 0) throw new import_errors.CliError("Missing --url (repeatable)", 2);
|
|
1043
|
+
const mediaContentType = normalizeMediaContentType(args["media-type"]);
|
|
1044
|
+
const alt = args.alt;
|
|
1045
|
+
const media = urls.map((url) => ({
|
|
1046
|
+
originalSource: url,
|
|
1047
|
+
mediaContentType,
|
|
1048
|
+
...alt ? { alt } : {}
|
|
1049
|
+
}));
|
|
1050
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
1051
|
+
productUpdate: {
|
|
1052
|
+
__args: { product: { id }, media },
|
|
1053
|
+
product: productSummarySelection,
|
|
1054
|
+
userErrors: { field: true, message: true }
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
if (result === void 0) return;
|
|
1058
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
1059
|
+
if (ctx.quiet) return console.log(result.productUpdate?.product?.id ?? "");
|
|
1060
|
+
(0, import_output.printJson)(result.productUpdate);
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (verb === "media upload") {
|
|
1064
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
1065
|
+
argv,
|
|
1066
|
+
extraOptions: {
|
|
1067
|
+
file: { type: "string", multiple: true },
|
|
1068
|
+
alt: { type: "string" },
|
|
1069
|
+
"content-type": { type: "string" },
|
|
1070
|
+
"media-type": { type: "string" }
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
1074
|
+
const filePaths = args.file ?? [];
|
|
1075
|
+
if (filePaths.length === 0) throw new import_errors.CliError("Missing --file (repeatable)", 2);
|
|
1076
|
+
const forcedMediaType = args["media-type"];
|
|
1077
|
+
const forced = forcedMediaType ? normalizeMediaContentType(forcedMediaType) : void 0;
|
|
1078
|
+
const resourceOverride = forced ? mediaTypeToStagedResource(forced) : void 0;
|
|
1079
|
+
const localFiles = (0, import_stagedUploads.buildLocalFilesForStagedUpload)({
|
|
1080
|
+
filePaths,
|
|
1081
|
+
contentType: args["content-type"],
|
|
1082
|
+
resource: resourceOverride
|
|
1083
|
+
});
|
|
1084
|
+
const targets = await (0, import_stagedUploads.stagedUploadLocalFiles)(ctx, localFiles);
|
|
1085
|
+
if (targets === void 0) return;
|
|
1086
|
+
const alt = args.alt;
|
|
1087
|
+
const media = targets.map((t, i) => {
|
|
1088
|
+
const local = localFiles[i];
|
|
1089
|
+
if (!t.resourceUrl) throw new import_errors.CliError(`Missing staged target resourceUrl for ${local.filename}`, 2);
|
|
1090
|
+
return {
|
|
1091
|
+
originalSource: t.resourceUrl,
|
|
1092
|
+
mediaContentType: forced ?? stagedResourceToMediaType(local.resource),
|
|
1093
|
+
...alt ? { alt } : {}
|
|
1094
|
+
};
|
|
1095
|
+
});
|
|
1096
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
1097
|
+
productUpdate: {
|
|
1098
|
+
__args: { product: { id }, media },
|
|
1099
|
+
product: productSummarySelection,
|
|
1100
|
+
userErrors: { field: true, message: true }
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
if (result === void 0) return;
|
|
1104
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
1105
|
+
if (ctx.quiet) return console.log(result.productUpdate?.product?.id ?? "");
|
|
1106
|
+
(0, import_output.printJson)(result.productUpdate);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
if (verb === "media list") {
|
|
1110
|
+
const args = (0, import_router.parseStandardArgs)({ argv, extraOptions: {} });
|
|
1111
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
1112
|
+
const first = (0, import_shared.parseFirst)(args.first);
|
|
1113
|
+
const after = args.after;
|
|
1114
|
+
const result = await (0, import_router.runQuery)(ctx, {
|
|
1115
|
+
product: {
|
|
1116
|
+
__args: { id },
|
|
1117
|
+
media: {
|
|
1118
|
+
__args: { first, after },
|
|
1119
|
+
pageInfo: { hasNextPage: true, endCursor: true },
|
|
1120
|
+
nodes: productMediaSelection
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
if (result === void 0) return;
|
|
1125
|
+
const connection = result.product?.media ?? { nodes: [], pageInfo: void 0 };
|
|
1126
|
+
(0, import_output.printConnection)({
|
|
1127
|
+
connection,
|
|
1128
|
+
format: ctx.format,
|
|
1129
|
+
quiet: ctx.quiet,
|
|
1130
|
+
nextPageArgs: {
|
|
1131
|
+
base: "shop products media list",
|
|
1132
|
+
first,
|
|
1133
|
+
extraFlags: [{ flag: "--id", value: id }]
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
if (verb === "media remove") {
|
|
1139
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
1140
|
+
argv,
|
|
1141
|
+
extraOptions: {
|
|
1142
|
+
"media-id": { type: "string", multiple: true }
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
const productId = (0, import_shared.requireId)(args.id, "Product");
|
|
1146
|
+
const mediaIds = args["media-id"] ?? [];
|
|
1147
|
+
if (mediaIds.length === 0) throw new import_errors.CliError("Missing --media-id (repeatable)", 2);
|
|
1148
|
+
const files = mediaIds.map((id) => ({
|
|
1149
|
+
id: normalizeMediaId(id),
|
|
1150
|
+
referencesToRemove: [productId]
|
|
1151
|
+
}));
|
|
1152
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
1153
|
+
fileUpdate: {
|
|
1154
|
+
__args: { files },
|
|
1155
|
+
files: { id: true, alt: true, fileStatus: true, updatedAt: true },
|
|
1156
|
+
userErrors: { field: true, message: true }
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
if (result === void 0) return;
|
|
1160
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.fileUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
1161
|
+
if (ctx.quiet) return console.log(productId);
|
|
1162
|
+
(0, import_output.printJson)(result.fileUpdate, ctx.format !== "raw");
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
if (verb === "media update") {
|
|
1166
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
1167
|
+
argv,
|
|
1168
|
+
extraOptions: {
|
|
1169
|
+
"media-id": { type: "string" },
|
|
1170
|
+
alt: { type: "string" }
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
const mediaIdRaw = args["media-id"];
|
|
1174
|
+
if (!mediaIdRaw) throw new import_errors.CliError("Missing --media-id", 2);
|
|
1175
|
+
const alt = args.alt;
|
|
1176
|
+
if (alt === void 0) throw new import_errors.CliError("Missing --alt", 2);
|
|
1177
|
+
const files = [{ id: normalizeMediaId(mediaIdRaw), alt }];
|
|
1178
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
1179
|
+
fileUpdate: {
|
|
1180
|
+
__args: { files },
|
|
1181
|
+
files: { id: true, alt: true, fileStatus: true, updatedAt: true },
|
|
1182
|
+
userErrors: { field: true, message: true }
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
if (result === void 0) return;
|
|
1186
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.fileUpdate, failOnUserErrors: ctx.failOnUserErrors });
|
|
1187
|
+
if (ctx.quiet) return console.log(files[0].id);
|
|
1188
|
+
(0, import_output.printJson)(result.fileUpdate, ctx.format !== "raw");
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
if (verb === "media reorder") {
|
|
1192
|
+
const args = (0, import_router.parseStandardArgs)({
|
|
1193
|
+
argv,
|
|
1194
|
+
extraOptions: {
|
|
1195
|
+
moves: { type: "string" },
|
|
1196
|
+
move: { type: "string", multiple: true }
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
const id = (0, import_shared.requireId)(args.id, "Product");
|
|
1200
|
+
let moves = [];
|
|
1201
|
+
if (args.moves) {
|
|
1202
|
+
try {
|
|
1203
|
+
const parsed = JSON.parse(args.moves);
|
|
1204
|
+
if (!Array.isArray(parsed)) throw new import_errors.CliError("--moves must be a JSON array", 2);
|
|
1205
|
+
moves = parsed;
|
|
1206
|
+
} catch (err) {
|
|
1207
|
+
throw new import_errors.CliError(`--moves must be valid JSON: ${err.message}`, 2);
|
|
1208
|
+
}
|
|
1209
|
+
} else if (args.move) {
|
|
1210
|
+
const raw = args.move;
|
|
1211
|
+
const parsedMoves = [];
|
|
1212
|
+
for (const item of raw) {
|
|
1213
|
+
const parts = item.split(":");
|
|
1214
|
+
if (parts.length !== 2) throw new import_errors.CliError("--move must be <mediaId>:<newPosition>", 2);
|
|
1215
|
+
const mediaId = parts[0].trim();
|
|
1216
|
+
const pos = Number(parts[1].trim());
|
|
1217
|
+
if (!mediaId) throw new import_errors.CliError("--move mediaId cannot be empty", 2);
|
|
1218
|
+
if (!Number.isFinite(pos) || pos < 0) throw new import_errors.CliError("--move newPosition must be a non-negative number", 2);
|
|
1219
|
+
parsedMoves.push({ id: normalizeMediaId(mediaId), newPosition: Math.floor(pos) });
|
|
1220
|
+
}
|
|
1221
|
+
moves = parsedMoves;
|
|
1222
|
+
}
|
|
1223
|
+
if (moves.length === 0) {
|
|
1224
|
+
throw new import_errors.CliError("Missing moves: pass either --moves <json> or --move <mediaId>:<newPosition> (repeatable)", 2);
|
|
1225
|
+
}
|
|
1226
|
+
const normalizedMoves = moves.map((move, i) => {
|
|
1227
|
+
const id2 = move?.id;
|
|
1228
|
+
const newPosition = move?.newPosition;
|
|
1229
|
+
if (typeof id2 !== "string" || !id2.trim()) {
|
|
1230
|
+
throw new import_errors.CliError(`moves[${i}].id is required`, 2);
|
|
1231
|
+
}
|
|
1232
|
+
const pos = Number(newPosition);
|
|
1233
|
+
if (!Number.isFinite(pos) || pos < 0) {
|
|
1234
|
+
throw new import_errors.CliError(`moves[${i}].newPosition must be a non-negative number`, 2);
|
|
1235
|
+
}
|
|
1236
|
+
return { id: normalizeMediaId(id2), newPosition: Math.floor(pos) };
|
|
1237
|
+
});
|
|
1238
|
+
const result = await (0, import_router.runMutation)(ctx, {
|
|
1239
|
+
productReorderMedia: {
|
|
1240
|
+
__args: { id, moves: normalizedMoves },
|
|
1241
|
+
job: { id: true, done: true },
|
|
1242
|
+
userErrors: { field: true, message: true }
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
if (result === void 0) return;
|
|
1246
|
+
(0, import_userErrors.maybeFailOnUserErrors)({ payload: result.productReorderMedia, failOnUserErrors: ctx.failOnUserErrors });
|
|
1247
|
+
if (ctx.quiet) return console.log(result.productReorderMedia?.job?.id ?? "");
|
|
1248
|
+
(0, import_output.printJson)(result.productReorderMedia, ctx.format !== "raw");
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
throw new import_errors.CliError(`Unknown verb for products: ${verb}`, 2);
|
|
1252
|
+
};
|
|
1253
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1254
|
+
0 && (module.exports = {
|
|
1255
|
+
runProducts
|
|
1256
|
+
});
|
|
1257
|
+
//# sourceMappingURL=products.js.map
|