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

apim-policy-utils

v0.0.1

Published

An XML file scripts maniputaling and debugging tool targeting to help working with Azure APIM Policy files in xml format.

Downloads

8

Readme

APIM Policy Utils

The apim-policy-utils is an npm package and CLI tool designed to extract C# code snippets from Azure APIM policy XML files, and combine them back into the policy XML file. This tool also handles named values.

This extractor is based on Ira Rainey's work: apim-script-extractor.

Setup

The apim-policy-utils tool can be set up locally.

Prerequisites

Installation

The apim-policy-utils tool can be installed using npm. To install globally, run the following command:

npm install -g apim-policy-utils

Alternatively, you can install it locally in your project folder by running:

npm install apim-policy-utils

Usage

The following methods are available for the npm package:

apim-policy-utils.extract(directoryPath: string)
apim-policy-utils.combine(directoryPath: string, destinationPath?: string)

The following options are available for CLI tool:

-h, --help       output usage information
-V, --version    output the version number
-c, --combine    combine C# code snippets back into APIM policy XML file
-e, --extract    extract C# code snippets from APIM policy XML file

You can use the apim-policy-utils tool to extract C# code snippets from an APIM policy XML file, debugging them and/or combine C# code snippets back into an APIM policy XML file.

Extract C# code 📜

To extract C# code snippets from an APIM policy XML file, run the following command:

apim-policy-utils -e|--extract <directory-path>

Where is the path to the directory containing the policy XML files. By default, the extracted code snippets will be saved to individual .csx files in a directory called scripts, located next to the directory containing the policy XML files.

Combine C# code back into XML 🔗

To combine C# code snippets back into an APIM policy XML file, run the following command:

apim-policy-utils -c|--combine <path-to-scripts-folder> <destination-path>(optional)

Where is the path to the directory containing the extracted .csx files. By default, the combined policy XML file will be saved in the same directory with the name same as directory name if destination-path is not provided. If destination-path is provided, the combiner will update the policy XML file in the destination path, or create one in the root folder if the original file doesn't exist. The mapping is through the file name.

Debug the extracted .csx files 🐛

  • Put the following code in .vscode/launch.json
    {
        "name": "Debug .NET Script",
        "type": "coreclr",
        "request": "launch",
        "program": "dotnet",
        "args": [
            "exec",
            "${userHome}/.dotnet/tools/.store/dotnet-script/1.4.0/dotnet-script/1.4.0/tools/net7.0/any/dotnet-script.dll",
            "${file}",
            "${fileDirname}"
        ],
        "cwd": "${workspaceRoot}",
        "stopAtEntry": false
    }
  • Go to Run and Debug tab in VS Code
  • Config the context.json file with values you want to use in the script, which will be passed in as context parameter
  • Put a break point in the .csx file and click Debug .NET Script

Folder structure

For the combine command, the directory structure should look like this:

.
├── scripts
|   ├── subfolder1
|   |   ├── block-001.csx
|   |   ├── inline-001.csx
|   |   ├── replaced.xml
|   |   ├── context.csx
|   |   └── context.json
|   ├── subfolder2
|   |   ├── block-001.csx
|   |   ├── inline-001.csx
|   |   ├── replaced.xml
|   |   ├── context.csx
|   |   └── context.json

For the extract command, the directory structure should look like this:

.
├── policies
|   ├── policy1.xml
|   ├── policy2.xml
|   └── policy3.xml

Contributing

We welcome contributions to the apim-policy-utils tool! If you encounter a bug 🐞 or have a feature request 🚀, please open an issue on the GitHub repository. If you would like to contribute code 💻, please fork the repository and submit a pull request with your changes. Please have a look at CONTRIBUTING.md

License

This project is licensed under the MIT License. 📝