npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

m2-url

v1.0.0

Published

A NodeJS CLI tool to verify product URLs in Magento 2

Downloads

2

Readme

URL Verifier

npm Build Status codecov

This command line utility will show all of the URL rewrites set on a product. The CLI works by retrieving product data from Magento via its APIs. This tool can also save the retrieved information to a text file for easy sharing or record keeping purposes. This tool can also quickly verify if a product has a URL rewrite that matches a given URL.

Sample Output

$ npx m2-url --env PROD --sku EXPL001 --save

Example Cotton T-Shirt
EXPL001 (Magento ID: 117)

Environment:  PRODUCTION
Status:       Enabled
URL key:      example-cotton-t-shirt.html

Categories: (3)
└ Apparel
└ New Items
└ T-Shirts

Public URLs: (4)
└ https://example.com/example-cotton-t-shirt.html
└ https://example.com/apparel/example-cotton-t-shirt.html
└ https://example.com/apparel/t-shirts/example-cotton-t-shirt.html
└ https://example.com/new-items/example-cotton-t-shirt.html


✔ Saved results to /Users/usr/ProductData/Queries/logs/EXPL001--PRODUCTION-020121-135201.txt

The CLI will primarily call the GraphQL API. However, due to Magento core functionality that cannot be changed at this time, the GraphQL API can only respond with data for products that are enabled and fully visible. In the event that the product you are attempting to retrieve data about is disabled or not fully visible, the GraphQL API will respond with an empty result. As this isn't very helpful in figuring out if there are no results because the product doesn't actually exist or if the configuration just doesn't expose it to the GraphQL API, the CLI will attempt to call the REST API to retrieve data on the product. If there are results, the CLI will output basic product information and will display a warning that the product exists but may not be visible via the GraphQL API and the user may need to manually check the product setup in Magento. In order for the CLI to make calls to the REST API, you will need to add an access token from Magento, otherwise, the CLI will throw an error.

Installation


The CLI was built with NodeJS v15.8.0 and requires NodeJS and npm to be installed on your computer. If you do not have these installed, please visit NodeJS's official site for downloads. The installer should install both NodeJS and npm.

The URL verifier can be used straight from the command line without installing using npx:

$ npx m2-url <options...>

You can also install the URL verifier:

$ npm i -g m2-url
$ m2-url <options...>

Configuration


Before you can use the CLI, you will need to create a .env file with some environment variables. Put the .env file in the directory from which you'll run the CLI. (Example, if you put the .env in ~/.env, you will need to cd ~ before running the CLI)

Environment base URLs

The CLI is currently set up to have exactly three environments: SANDBOX (SAND), STAGING (STG), and PRODUCTION (PROD). You must explicitly define their base URLs in a .env file with the following format:

{environment-name}_BASE_URL={environment-URL}.

For example:

example .env

...
SANDBOX_BASE_URL=https://dev.example.com
STAGING_BASE_URL=https://staging.example.com
PRODUCTION_BASE_URL=https://example.com
...

Magento Access Token

If you don't already have a web API access token set up in the Magento Admin panel, follow the Magento Documentation for how to generate a new integration token. Once you have an integration token set up, you will want the Access Token value and add it to your .env in the following format:

MAGENTO_ACCESS_TOKEN={access-token}

For example:

example .env

...
MAGENTO_ACCESS_TOKEN=ujWnRVZpDfcgDiFHB8wFbZjLe89WpkP2
...

Usage


Usage: $ m2-url [options]

Options:
  -e, --env <env-name>            Environment to run query against. Valid options: ['PROD', 'STG', 'SAND']
  -s, --sku <sku>                 Product SKU to query
  -o, --output <dir/file-name>    Output path, including filename (default: "./logs/{sku}-{envName}-{timeStamp}.txt")
  -v, --verify <url>              URL to verify (Valid format examples:
                                    'https://some.website.com/page.html', 'page.html', '/page.html')
  --save                          Save results to file (default: false)