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

apic-dp-js-policy

v3.4.0

Published

API Connect DataPower custom gatewayscript policy maker

Downloads

26

Readme

npm version

apic-dp-js-policy

API Connect DataPower custom gatewayscript policy maker

Installation

npm i -g apic-dp-js-policy

Usage

(1) Create a folder with the script's name (no spaces, all lowercase and hyphens), This name will be further referred as {projName} (for example: hello-world).

(2) Create a JavaScript file in that folder named {projName}.js (e.g. hello-world.js)

JavaScript file example:

// API Connect utility
const apic = require('local://isp/policy/apim.custom.js');
// helper module to manipulate headers
const hm = require('header-metadata');

// Get extension properties
const props = apic.getPolicyProperty();
const message = props.message;

// Set the response header
hm.current.set('X-Hello-World', message);

request.body

Note you cannot get the request body using apim.getvariable('request.body'). You should use apim.readInput or apim.readInputAs<Type> instead.

(3) Create a yaml file in that folder named {projName}.yaml (e.g. hello-world.yaml)

YAML file example:

policy: 1.0.0

info:
  title: hello-world
  name: hello-world
  version: 1.0.0
  description: Hello World Extension

attach:
  - rest
  - soap

gateways:
  - datapower-gateway

properties:
  $schema: "http://json-schema.org/draft-04/schema#"
  type: object
  properties:
    message:
      label: Message to be returned
      description: A message to be returned in the X-Hello-World header
      type: string
      default: oh-hi
  required:
    - message
  • Notice info.name must be the {projName}

(4) You will now have the following folder structure:

  hello-world/
    hello-world.js
    hello-world.yaml
  • Note: Any other file in that folder would be added to the policy's folder, so you could add js files to require from your code.

Run the following command from outside that folder:

apic-dp-js-policy --project {projName}

(e.g. apic-dp-js-policy -p hello-world)

Arguments

|Argument |Required|Default|Description |-------------|--------|-------|----------- |-p/--path|Yes | - |The project's path |-n/--name|No |path.basename(argv.path)| |-h/--hashLength|No | 6 | Number of characters from the hash of the main js file to add to the result file's name |-t/--timestamp|No |false| Use timestamp (i.e. 2019-07-17T12-00-00-000Z) instead of hash in the zip file name

e.g. The result file name would look like:

policy-hello-world_v1.0.0-x2GTXy.zip

Credits

Eli Sherer

License

MIT