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

@hrax/now-eslint

v0.0.3

Published

NodeJS command to lint update set changes on Service Now instances

Downloads

3

Readme

NOW ESLint Test

NodeJS CLI/Library to lint scripts in update set changes on Service Now instances based on the user table configuration. Offers independent lint configuration with possibility to utilize custom ESLint plugins compared to the solution provided by Service Now out-of-box.

Primary goal is to be utilized by user locally using CLI, however option to generate JSON should allow this to be utilized in mid server as an extension to automate release processes using Service Now instance.

Update sets need to be committed locally on the configured instance. Change in the committed update set is linted independently on the current version of the record on the instance. Update sets can be linted on instance utilizing custom/vanity url as long as the configuration allows for REST API access.

For latest changes see Patch Notes.

CLI

Installation

CLI is the primary usage of the package, and it is recommended to install the package globally using

npm i -g @hrax/now-eslint

The global installation required to have eslint and all its required plugins installed globally as well.

Setup

Setup for the CLI should be executed in the folder where you want your reports to be generated. Once you have selected the folder, execute command

now-eslint setup

You will be guided through a series of questions to set up your connection to the instance, test it and have a possibility of a table structure to be generated directly from the configured instance.

After the command has been completed, the folder you executed it in, should now contain 4 files: .ENV, config.json, tables.json and template.ejs.

Their usage is as follows

  • .ENV - This is where the connection information to your instance is saved
  • config.json - Tables and ESLint CLI configuration; tables in this file, override tables configured in tables.json
  • tables.json - Tables and field configuration, usually generated from the instance
  • template.ejs - HTML template used to generate the HTML Report. You can update this file as you wish to change the visual or functionality of the generated report

Execution

To generate an update set report, you should execute following command in the same folder you have set up step earlier.

Update set changes are linted against .eslintrc present in the configured folder or in user's profile directory. You can specify custom ESLint config file by using overrideConfigFile in the config.json eslint property.

now-eslint report

You will be guided through a series of questions to provide name, filename and update set query for your report.

Note that linter currently does not allow reporting on custom XML serialized Service Now records such as 'Workflows'. If you encounter such an error, you can specify the table to be skipped in the config.json tables property.

Library

Installation

Library is the secondary usage of the package, and it is recommended to install the package into your project using

npm i @hrax/now-eslint

ESLint and its dependencies should be installed in your project as well.

Examples

// Load the linter
const {NowLinter} = require("@hrax/now-eslint");

// Configure connection object
const connection = {
  domain: "",
  username: "",
  password: ""
};

// Configuration of the linter, only query is mandatory
// Tables property has the same format as const tables below
// See https://eslint.org/docs/developer-guide/nodejs-api#eslint-class for available options for eslint property
const config = {
  query: "",
  title: "",
  tables: {},
  eslint: {}
};

// Tables to be linted, in format "table_name"; [field1, field2]
const tables = {
  "sys_script_include": ["script"]
};

// Must, until the top-level awaits is enabled
(async () => {
  const linter = new NowLinter(connection, config, tables);
  // the JSON report on the updates in the update sets
  const report = await linter.report();
})();

Required Instance Access Rights

We use Service Now REST API to read necessary information from the instance. Easiest setup would be to give the account snc_read_only and admin roles. If that is by any chance not possible, make sure account has read access to the following tables as well as access to the REST API.

Load table-field and table-parent information/setup CLI

  • sys_dictionary
    fields:
    • name
    • element
  • sys_db_object
    fields:
    • name
    • super_class.name

Fetch update set data/report CLI

  • sys_update_xml
    fields:
    • name
    • sys_id
    • action
    • sys_created_by
    • sys_created_on
    • sys_updated_by
    • sys_updated_on
    • type
    • target_name
    • update_set
    • payload
  • sys_update_set
    fields:
    • sys_id

TODO/Nice to have

  • TODO: HTTPs Proxy; unauthorized requests should not be rejected anymore
  • TODO: Optimalize generated reports to minimize the file size
  • TODO: Allow to mark and skip changes that have field "active" = false
  • TODO: Allow to conditionally lint fields (e.g. if other_field is true/false or if other_field is empty/not empty)
  • TODO: setup to run against specific eslint config not the project one!
  • Nice to have: option to generate report as PDF
  • Nice to have: generate table conditional field configuration based on dictionary dependent field?
  • Nice to have: custom parse complex changes (e.g. workflow) to be able to lint selected nested complex records

Patch Notes

v0.0.3

  • Updated ESLint to v7.8.1
  • Removed use of deprecated ESLint CLI as a preparation for ESLint v8.
    This resulted in change of property cliEngine with eslint. Running now-eslint setup in new folder is recommended; you can then copy the new generated config.json to the old folder or keep using the new one.