@mraichelson/metaobjects-manager
v1.0.4
Published
A Node.js tool for managing Shopify Metaobjects via command line.
Maintainers
Readme
Metaobjects Manager
A Node.js CLI tool for managing Shopify Metaobject definitions via the GraphQL Admin API. This tool allows you to synchronize Metaobject definitions between your local JSON files and your Shopify store.
Features
- PUSH: Publish local Metaobject definitions to Shopify (create new or update existing)
- Handles field additions, updates, and deletions
- Optional auto-confirmation with
-y/--yesflag - Default prompt response is "yes" (just press Enter)
- PULL: Retrieve Metaobject definitions from Shopify to local JSON files
- Automatically filters out Shopify internal metaobjects and those from other apps
- Only pulls merchant-owned metaobjects by default
- VALIDATE: Validate local JSON files without syncing
- Selective Operations: All commands support optional file/type parameters to process specific definitions
Installation
npm install -g @mraichelson/metaobjects-managerOr use locally in your project:
npm install @mraichelson/metaobjects-managerSetup
Copy the example environment file:
cp env.example .envConfigure your
.envfile with your Shopify store credentials:SHOPIFY_STORE_URL=your-store-url.myshopify.com SHOPIFY_CLIENT_ID=your-client-id SHOPIFY_CLIENT_SECRET=your-client-secretGet your credentials from your custom app:
- Shopify Partner Dashboard: https://partners.shopify.com
- Navigate to: Apps → Develop apps → Your app → API credentials
- Copy the Client ID and Client Secret
- Ensure your app has the following Admin API access scopes enabled:
read_metaobject_definitions- Read metaobject definition schemaswrite_metaobject_definitions- Create and update metaobject definition schemasread_metaobjects- Read metaobject data instanceswrite_metaobjects- Create and update metaobject data instances
Usage
Push Command
Push local Metaobject definitions to Shopify:
metaobjects-manager push
# or
shopify-mom pushPush specific files:
metaobjects-manager push example.json dictionary.json
# or
metaobjects-manager push example dictionary
# (with or without .json extension)Auto-confirm all prompts (useful for CI/CD):
metaobjects-manager push -y
# or
metaobjects-manager push --yesThis command will:
- Read JSON files from
metaobjects(or configured directory)- If files are specified, only process those files
- If no files specified, process all files in the directory
- Validate each file's structure and field types
- Check if the definition exists in Shopify
- Compare local and remote definitions to detect field changes
- Prompt for confirmation before creating or updating (defaults to "yes")
- Use
-y/--yesto skip all prompts
- Use
- Handle field deletions: If a field is removed from a local JSON file, it will be deleted from Shopify during update
- Skip files with errors and continue with others
Pull Command
Pull Metaobject definitions from Shopify to local files:
metaobjects-manager pull
# or
shopify-mom pullPull specific metaobject types:
metaobjects-manager pull example dictionary
# (specify by type name, not filename)This command will:
- Fetch Metaobject definitions from your Shopify store
- Automatically filters out:
- Shopify internal metaobjects (prefixed with
shopify--) - Metaobjects from other apps (prefixed with
app--or$app:)
- Shopify internal metaobjects (prefixed with
- Only processes merchant-owned metaobjects
- If types are specified, only pull those types
- If no types specified, pull all merchant-owned definitions
- Automatically filters out:
- Create new local JSON files for definitions that don't exist locally
- Update existing local files with current definitions from Shopify
- Log all changes to the terminal
Validate Command
Validate local metaobject JSON files without pushing or pulling:
metaobjects-manager validate
# or
shopify-mom validateValidate specific files:
metaobjects-manager validate example.json dictionary.json
# or
metaobjects-manager validate example dictionary
# (with or without .json extension)This command will:
- Read JSON files from
metaobjects(or configured directory)- If files are specified, only validate those files
- If no files specified, validate all files in the directory
- Validate each file's structure and field types
- Report which files are valid or invalid
- Display detailed error messages for invalid files
- Exit with code 0 if all files are valid, code 1 if any are invalid
Use cases:
- Verify files that were pulled from a store instance
- Verify files that were written locally before pushing
- Validate changes made locally before pushing them
Configuration
Metaobjects Directory
By default, the tool looks for Metaobject definition files in metaobjects (project root). You can customize this by setting the METAOBJECTS_DIR environment variable:
METAOBJECTS_DIR=custom/path/to/metaobjectsJSON File Format
Each Metaobject definition should be stored as a JSON file named {type}.json. Example:
{
"type": "size_chart",
"name": "Size Chart",
"description": "Product sizing information",
"displayNameKey": "size",
"access": {
"admin": "MERCHANT_READ_WRITE",
"storefront": "PUBLIC_READ"
},
"capabilities": {
"publishable": {
"enabled": true
},
"translatable": {
"enabled": true
},
"renderable": {
"enabled": true,
"data": {
"metaTitleKey": "title",
"metaDescriptionKey": "description"
}
},
"onlineStore": {
"enabled": true,
"data": {
"urlHandle": "size-charts",
"canCreateRedirects": true
}
}
},
"fieldDefinitions": [
{
"key": "size",
"name": "Size",
"type": "single_line_text_field",
"description": "The size identifier",
"required": true,
"capabilities": {
"adminFilterable": {
"enabled": true
}
},
"validations": [
{
"name": "choices",
"value": ["XS", "S", "M", "L", "XL"]
}
]
},
{
"key": "chest_inches",
"name": "Chest (inches)",
"type": "number_decimal",
"required": false
}
]
}Metaobject Type Naming
⚠️ Important: Reserved Type Names
Metaobject types cannot conflict with Shopify's native content types. Do not use reserved type names such as:
article,page,blog,product,collection,customer,order,cart,checkout- Any type that matches Shopify's built-in content object types
Naming Patterns and Requirements:
For detailed information on naming conventions, ownership types, and type identifier requirements, see the official Shopify documentation:
- Ownership and Reserved Prefixes - Learn about app-owned vs merchant-owned metaobjects and the
$app:prefix - Manage Metaobject Definitions - Type identifier requirements and naming best practices
- About Metaobjects - Overview of metaobject ownership types and naming patterns
Available Options
Metaobject-level options:
type(required): Unique identifier for the metaobject type (see naming guidelines above)name(required): Human-readable namedescription(optional): Administrative descriptiondisplayNameKey(optional): Field key to use as display nameaccess(required): Access permissions (admin and storefront)capabilities(optional): Optional features:publishable: Enable draft/active status workflowtranslatable: Enable translation supportrenderable: Enable SEO metadata (requiresmetaTitleKeyand/ormetaDescriptionKey)onlineStore: Enable Online Store pages (requiresurlHandle)
Field-level options:
key(required): Unique field identifiername(required): Human-readable field nametype(required): Field data type (see valid types below)description(optional): Field descriptionrequired(optional): Whether field is requiredvalidations(optional): Validation rules (e.g., min/max, choices, regex)capabilities(optional): Field capabilities:adminFilterable: Enable filtering in Shopify admin
See metaobjects/example.json for a sample Metaobject definition.
Valid Field Types
Field types must match Shopify's Metaobject field types. See the official documentation for the complete list.
Common types include:
single_line_text_fieldmulti_line_text_fieldnumber_integernumber_decimaldatedate_timebooleanurlfile_referencecolor
Error Handling
The tool handles errors gracefully:
- Invalid JSON: Logs the error and skips the file
- Invalid field types: Lists invalid types and references valid types
- Missing required fields: Lists missing fields
- API errors: Displays user-friendly error messages from Shopify
- Network errors: Logs with retry suggestions
On any error, the tool skips the current operation and continues with remaining files.
Development
Building
npm run buildThis compiles TypeScript files from src/ to dist/.
Project Structure
.
├── src/
│ ├── cli/ # CLI command implementations
│ ├── files/ # File reading/writing utilities
│ ├── graphql/ # GraphQL queries and mutations
│ ├── shopify/ # Shopify API client and auth
│ ├── types/ # TypeScript type definitions
│ └── validators/ # JSON validation logic
├── metaobjects/ # Default directory for Metaobject JSON files
├── dist/ # Compiled JavaScript (generated)
└── package.jsonLicense
ISC
