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

apigee-proxy-template-replacer

v1.0.6

Published

Simple proxy creator based on json config file and proxy template.

Downloads

14

Readme

Apigee Proxy Template Replacer

This template replacer will take a JSON config alongside an Apigee API proxy template, and create a final API proxy with the config values replaced.

Example

var replacer = require("apigee-proxy-template-replacer");

var template_dir = "./proxy_templates/oauth2";
var answers_path = "./json_configs/answerExample.json";


replacer.createProxy(template_dir,answers_path, function(err, data){
    if(err){
        console.log(err);
    }else{
        //data returned as zip file
        //save to disk or use for uploading to a server
    }
});

Detailed Documentation

There are two libraries, lib/proxy-replacer.js and lib/proxy-generator.js. The replacer interacts directly with the XML to replace the sections and variables. Please see API Proxy Template Replacer below for more details. The generator leverages the replacer and will write the finished template to an output folder (currently output).

The template directory provided should point to an Apigee API proxy like the example examples/proxy_templates/oauth2/.

API Proxy Template Replacer

This replacer will read a json file with named key value pairs and alter an Apigee Edge API Proxy that contains template directives. Based on directives(detailed below) in the bundle's XML files, the replacer will utilities will remove and/or configure the API proxy.

For examples, please see the json config located in ./examples/json_configs directory and example usage of the replacer utilities in ./examples/app.js.

Remove complete sections from XML

    <!--START grantTypes==pw -->
    <Flow name="Accesstoken-PW">
        <Description>Password Grant</Description>
    </Flow>
    <!--END grantTypes==pw -->
    

If the answers json does not have a key named grantTypes with value of "pw" or ["pw"], this section will get removed when calling the with the cleanTemplateXml(xml, answersJson) method.

Replace variables located in XML

<ProxyEndpoint>
    <Description>__apiDescription__</Description>
</ProxyEndpoint>

Currently variable identifiers for the replacer are __, a double underscore. Use the following method to replace any variables: replaceTemplateValues(cleanedXml,answersJson). This results in:

<ProxyEndpoint>
    <Description>My Description that was replaced.</Description>
</ProxyEndpoint>

Replace snippets of XML in a loop

If you have an answer which contains an array (single of multidimensional), you can use the following syntax in your template:

<Attributes>
    <!--FOREACH ccTokenAttributes -->
    <Attribute name="__item[0]__" ref="__item[1]__">__item[2]__</Attribute>
    <!--FOREACH ccTokenAttributes -->
</Attributes>

The above means to replace the item[i] values in the XML snippet for each of the values in the ccTokenAttributes answer field. In this case, ccTokenAttributes is a multi-dimensional array.

TODO

  1. Provide documentation inline with the proxy template, explaining each of the template functions.

  2. Build a couple example templates and answer configuration JSON files.

  3. Revamp the remove section logic to parse template and answers better for doing nested array check on existance, containment, equality, etc.