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

graph-service

v2.1.3

Published

A service for accessing the Microsoft Graph API.

Downloads

765

Readme

graph-service

A service for accessing the Microsoft Graph API.

Version 2.1.3

Exports the GraphService class allowing you to access the Microsoft Graph API at https://graph.microsoft.com. The GraphService class is subclassed from the HttpsService class. The GraphService class constructor requires a credentials object having a getAccessToken method to obtain the bearer token that is sent with each request. You can use a ClientCredentials instance or provide your own instance as long as it provides the getAccessToken method that returns a promise resolved with an access token.

The default Graph API version is v1.0. This can be overridded in the constructor (e.g., beta).

1. Installation

Install this package and, optionally, the client-credentials package.

$ npm install --save graph-service
$ npm install --save client-credentials

2. Usage

const GraphService = require('graph-service');
const ClientCredentials = require('client-credentials');

const tenant = 'my-company.com';
const clientId = '0b13aa29-ca6b-42e8-a083-89e5bccdf141';
const clientSecret = 'lsl2isRe99Flsj32elwe89234ljhasd8239jsad2sl=';

const credentials = new ClientCredentials(tenant, clientId, clientSecret);

const service = new GraphService(credentials);

service.all('/users').then(response => {
  console.log(response.data);
});

3. API

Since the GraphService class subclasses the HttpsService class, the API is identical to that class, with two exceptions. First, the constructor requires a credentials object (an object that provides the getAccessToken method). Second, the all method performs repeated GET requests, accumulating the results.

3.1 constructor

GraphService(credentials, version);

Creates a new GraphService instance using the specified credentials object. This normally is an instance of the ClientCredentials class. It can also be an object you create, as long as it provides the getAccessToken(resource) method where the resource is always set to the graph.microsoft.com endpoint. This method must return a promise that is resolved with a valid access token. For example, if you have your own token from a user who has already authenticated with Azure AD, then you can create a simple object that returns this token in a promise. Note that creating a GraphService instance is not expensive (no network traffic takes place) so you can create a new instance for every new user request without any significant performance impact.

As a special case (as of version 2.1.2), the credentials parameter can also be a string. In that case, it is assumed to be the access token and is used directly in requests to the Graph API. Please note that access tokens expire so this feature should only be used when a client provides current (and periodically refreshed) access tokens. You would then create a new GraphService instance for each request with the current access token being passed in as the credentials parameter in the constructor.

The version parameter defaults to the string v1.0 and is prepended to all paths. For example, calling service.get('/users') will send the request to the /v1.0/users resource. You must include the initial slash on all paths since the path is created using the /{version}{path} construction.

3.1 all (method)

all(path [, query])

Sends repeated GET requests to a resource that returns a list. This method accumulates the results from the value property and follows the @odata.nextLink property. Returns a promise that is resolved with the response from the last HttpsService GET request and the data property set to the concatenation of all of the retrieved objects.

4. License

The MIT License (MIT)

Copyright (c) 2018 Frank Hellwig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.