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

akamai-edgegrid

v3.5.2

Published

Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js

Downloads

139,411

Readme

EdgeGrid for Node.js

Build Status

This library implements an Authentication handler for the Akamai EdgeGrid Authentication scheme in Node.js for Node v14 and above.

You can find the most up-to-date package in NPM under akamai-edgegrid.

Install

npm install --save akamai-edgegrid

Authentication

You can obtain the authentication credentials through an API client. Requests to the API are marked with a timestamp and a signature and are executed immediately.

  1. Create authentication credentials.

  2. Place your credentials in an EdgeGrid file ~/.edgerc, in the [default] section.

    [default]
    client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
    host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
    access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
    client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj
  3. Use your local .edgerc by providing the path to your resource file and credentials' section header.

    var eg = new EdgeGrid({
      path: '/path/to/.edgerc',
      section: '<section-header>'
    });

    Alternatively, you can hard code your credentials by passing the credential values to the EdgeGrid() method.

    var clientToken = "akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj",
        clientSecret = "C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=",
        accessToken = "akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij",
        baseUri = "akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net";
    
    var eg = new EdgeGrid(clientToken, clientSecret, accessToken, baseUri);

Use

To use the library, provide the path to your .edgerc, your credentials section header, and the appropriate endpoint information.

var EdgeGrid = require('akamai-edgegrid');

var eg = new EdgeGrid({
  path: '/path/to/.edgerc',
  section: 'section-header'
});

eg.auth({
  path: '/identity-management/v3/user-profile',
  method: 'GET',
  headers: {
    'Accept': "application/json"
  },
  body: {}
});

eg.send(function(error, response, body) {
  console.log(body);
});

Chaining

You can also chain calls by combining the execution of auth and send methods.

eg.auth({
  path: '/identity-management/v3/user-profile',
  method: 'GET',
  headers: {},
  body: {}
}).send(function (error, response, body) {
  console.log(body);
});

Query string parameters

When entering query parameters use the qs property under the auth method. Set up the parameters as name-value pairs in a object.

eg.auth({
    path: '/identity-management/v3/user-profile',
    method: 'GET',
    headers: {},
    qs: {
        authGrants: true,
        notifications: true,
        actions: true
    },
    body: {}
})

Headers

Enter request headers as name-value pairs in an object.

Note: You don't need to include the Content-Type and Content-Length headers. The authentication layer adds these values.

eg.auth({
  path: '/identity-management/v3/user-profile',
  method: 'GET',
  headers: {
    'Accept': "application/json"
  }
});

Body data

Provide the request body as an object or as a POST data formatted string.

// Object
eg.auth({
    path: '/identity-management/v3/user-profile/basic-info',
    method: 'PUT',
    headers: {},
    body: {
        contactType: "Billing",
        country: "USA",
        firstName: "John",
        lastName: "Smith",
        phone: "3456788765",
        preferredLanguage: "English",
        sessionTimeOut: 30,
        timeZone: "GMT"
   }
});

Encoding

When interacting with binary data, such as during the retrieval of PDF invoices, specify the responseType as an arraybuffer in the auth method call. Omitting the responseType will cause an unreadable or blank response.

const fs = require('fs');

eg.auth({
  path : `/invoicing-api/v2/contracts/${contractId}/invoices/${invoiceNumber}/files/${fileName}`,
  method: 'GET',
  responseType: 'arraybuffer', // Important
}).send((err, response) => {
  if (err) {
    return console.log(err);
  }
  fs.writeFile(`./${fileName}`, response.data, 'binary', (err) => {
    if (err){
      return console.log(err);
    }
    console.log('File was saved!');
  });
});

Proxy

To use edgegrid with proxy, you can configure it with one of these methods:

  • Add the proxy argument to the EdgeGrid() method.

    eg.auth({
      path : `/identity-management/v3/user-profile`,
      method: 'GET',
      proxy: {
        host: 'my.proxy.com',
        protocol: "https",
        port: 3128,
        auth: {
          username: 'my-user',
          password: 'my-password'
        }
      }
    }).send((err, response) => {
      if (err) {
        return console.log(err);
      }
      console.log('Success!');
      // Do something with the response
    });
  • Set the HTTPS_PROXY environment variable.

    $ export HTTPS_PROXY=https://username:password@host:port
    $ node myapp.js

Debug

Enable debugging to get additional information about a request. You can configure this with one of these methods:

  • Add the debug argument to the EdgeGrid() method.

    var eg = new EdgeGrid({
      path: '/path/to/.edgerc',
      section: 'section-header'
      debug: true
    });
  • Set the EG_VERBOSE environment variable.

    $ export EG_VERBOSE=true
    $ node src/main.js

Reporting issues

To report an issue or make a suggestion, create a new GitHub issue.

License

Copyright 2024 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.