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

ang-soap

v1.0.10

Published

SOAP client

Downloads

30

Readme

ANG SOAP

This module provides the most reliable SOAP client. It is based on axios http client and fast-xml-parser, so you can customise and parse your request and response the way you want.

How to use

const SoapClient = require('ang-soap');

const url = 'https://example.com/yourService';

const options = { axios: { timeout: 5000 } };// See Default options section for more details.

const client = new SoapClient(options);
// you can use the default options as well, without parameters
// const client = new SoapClient();
client.setBasicAuthSecurity('usernameXXX', 'passwordXXX');

const data = {}; // here your json using fast-xml-parser format. For more details, see data section
try {
    const res = await client.performRequest(url, data);
} catch (error) {
    console.log(error); // See Error section
}

To enable and disable SSL, use:

client.enableSSL();
client.disableSSL();

By default, SSL is activated.

Url

WARNING: The url refers to the target SOAP API. This module does not use WSDL.

const url = 'https://example.com/yourService';

Default options

const options = {
    axios: {
        method: 'POST',
        headers: { 'Content-Type': 'application/soap+xml', Accept: '*/*' }
    },
    fastXmlParser: {
        jsonParser: {
            attributeNamePrefix: '@_',
            attrNodeName: false,
            textNodeName: '#text',
            ignoreAttributes: false,
            cdataTagName: '__cdata',
            cdataPositionChar: '\\c',
            format: true,
            indentBy: '  ',
            supressEmptyNode: true,
        },
        xmlParser: {
            attributeNamePrefix: '',
            attrNodeName: false,
            textNodeName: '#text',
            ignoreAttributes: false,
            ignoreNameSpace: true,
            allowBooleanAttributes: false,
            parseNodeValue: false,
            parseAttributeValue: false,
            trimValues: false,
            cdataTagName: false,
            cdataPositionChar: '\\c',
            parseTrueNumberOnly: true,
            arrayMode: false, // "strict"
            stopNodes: ['parse-me-as-string'],
        },
    },
    jsonPath: '',
    debug: false,
    isRequestDataXML: false,
    isResponseXML: false
};

Data

This is an example of data you pass as a parameter to performRequest() method :

const data = {
    'soap12:Envelope': {
        '@_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
        '@_xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
        '@_xmlns:soap12': 'http://www.w3.org/2003/05/soap-envelope',
        'soap12:Body': {
            ParentElement1: {
                '@_xmlns': 'http://www.namespace1.com',
                ChildElement : 'ElementValue',
            },
        },
    },
}

For more details about making and configuring the JSON parser, see fast-xml-parser node module.

XML instead of JSON

You can also send an XML data instead of JSON. In this case, you need to set options.isRequestDataXML to true The data should be as follow:

const data = `<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
                <soap12:Body>
                    <ParentElement1 xmlns="http://www.namespace1.com">
                        <ChildElement>ElementValue</ChildElement>
                    </ParentElement1>
                </soap12:Body>
              </soap12:Envelope>`;

If you need a raw response, set options.isResponseXML to true

Parsing the response

jsonPath

When you call multiple SOAP methods, each response probably has its own data structure. So if you use the jsonPath option, you may need to set it before performing each request.

const jsonPath = `$..Envelope.Body.YourTargetObject`;
client.setJsonPath(jsonPath);

For more details about jsonPath pattern, you can check the jsonpath node module.

arrayMode

By default,arrayMode is false. A tag with single occurrence is parsed as an object but as an array in case of multiple occurences. If you need to parse a specific tag as array only, you can set the option arrayMode using the following method:

const targetTag = `/^yourTagName$/`; 
client.setArrayMode(targetTag);

In the previous case, the setArrayMode() method accepts a regex. To learn more about arrayMode option, see fast-xml-parser node module.

Error

When you catch an error, it will be in this format:

{   
    message: <String>,
    error: <Error>
}

Debug

If you want to follow all the steps from creating the request to receiving the response, set options.debug to true. When debug is activated, you find in the console the result for each step.