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

nodejs-google-admin-sdk

v1.0.4

Published

Node.js library for Google's Admin SDK

Downloads

3

Readme

Nodejs Google Admin SDK

This is an unofficial Admin SDK

Initializing the library

The library support the following resources:

Installation

npm install nodejs-google-admin-sdk

To use the library, you must have a refresh token. It can be obtained from here, depending on the purposes you want.

const config = {
  client: {
    id: '1234567890-3ds5um9ecm6ecd3nc.apps.googleusercontent.com',
    secret: 'abcdefgh'
  },
  token: {
    refresh: 'your_refresh_token'
  }
};

The library is designed such that you can initialize and use any submodule independently of the other three. Any or all submodules can be initialized using the credentials above:

const adminSDK = require('nodejs-google-admin-sdk');
const userProvisioning = new adminSDK.UserProvisioning(config);

Example usage

const newUser = {
  name: {
    givenName: 'John',
    familyName: 'Doe',
  },
  password: 'password123456',
  primaryEmail: '[email protected]'
  fields: "kind,nextPageToken,users(id,kind,name,orgUnitPath,primaryEmail)"
};
userProvisioning.insert(newUser, function(err, body) {
  console.log("Received response: " + body);
});

Note: it is recommended to use Google's fields editor to construct queries with fields arguments.

const newUser = {
  name: {
    givenName: 'John',
    familyName: 'Doe',
  },
  password: 'password123456',
  primaryEmail: '[email protected]'
};
query = userProvisioning.insert(newUser);
query.exec(function(err, body){
  // Handle error and body
});

Group Provisioning

GroupProvisioning supports all functions supported by UserProvisioning except update. The function signatures and behaviors are identical, except they accept a unique groupkey instead of a unique userkey.

OrgUnitProvisioning

The following provide functionality for querying the orgunits endpoint of the Directory API. For information on constructing queries and parsing responses, see the official documentation.

OrgUnitProvisioning.findOrCreate(customer_id, org_unit[, cache, callback])

Creates an OrgUnit and any of its parents that need to be created. Accepts arguments:

  • customer_id: your Google customer id.
  • org_unit: an array of the form that specifies the path of the OrgUnit to create. For example, to create the OrgUnit "/Users/Admins/SuperAdmins", pass in `['Users', 'Admins', 'SuperAdmins'].
  • cache (optional): a map of strings representing OrgUnits that are known to exist. For example, `{'/': 1, 'Users':1, 'Admins':1}
  • callback (optional): function of the form callback(error, body) to call when the response is received.

Note that findOrCreate uses async.memoize. This can cause problems with tests that expect a fresh state at the beginning of each test. You can use async.unmemoize to reset state.

OrgUnitProvisioning.insert(customer_id, properties[, fields, callback])

Creates an OrgUnit. Accepts arguments:

  • customer_id: your Google customer id.
  • properties: an object that specifies the name of the OrgUnit to create. Uses the form { name: 'X', parent: 'Y' }. Note that the parent must already exist; to deep create an OrgUnit, use OrgUnitProvisioning.findOrCreate.
  • fields (optional): fields to return in the response.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

OrgUnitProvisioning.list(customer_id, params, [, callback])

Lists OrgUnits owned by a customer. Accepts arguments:

  • customer_id: your Google customer id.
  • params (optional): object containing querystring arguments.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

OrgUnitProvisioning.get(customer_id, org_unit_path, [, callback])

Gets a single OrgUnit owned by a customer. Accepts arguments:

  • customer_id: your Google customer id.
  • org_unit_path: String representation of the OrgUnit to find.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

OrgUnitProvisioning.patch(customer_id, org_unit_path[, body, fields, callback])

Updates an OrgUnit using patch semantics. Accepts arguments:

  • customer_id: your Google customer id.
  • org_unit_path: the full OrgUnit path to update.
  • body (optional): object containing the fields to update on the OrgUnit and their new values.
  • fields (optional): fields to return in the response.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

OrgUnitProvisioning.delete(customer_id, org_unit_path, [, callback])

Deletes an OrgUnit. Accepts arguments:

  • customer_id: your Google customer id.
  • org_unit_path: String representation of the OrgUnit to delete.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

User Provisioning

The following provide functionality for querying the Users endpoint of the Directory API. For information on constructing queries and parsing responses, see the official documentation.

UserProvisioning.insert(body[, fields, callback])

Creates a Google Apps user. Accepts arguments:

  • body: specifies the name, password, and primaryEmail of the user.
  • fields (optional): specifies which user fields are included in the response.
  • callback (optional): a function of the form callback(error, body) to be called when the response is received.

UserProvisioning.get(userkey[, callback])

Gets information for a single user. Accepts arguments:

  • userkey: the unique userkey of the user to find.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

UserProvisioning.list(params[, callback])

Lists Google Apps users. Accepts arguments:

  • params: user fields to query by
  • callback (optional): function of the form callback(error, body) to call when the response is received.

Example

// Get at most 200 users in the domain `example.com`
const params = {
  domain: 'example.com',
  max_results: 200
};

userProvisioning.list(params, function(err, body) {
  // Handle error and do something with users
});

UserProvisioning.patch(userkey, body[, fields, callback])

Updates a user using patch semantics. Accepts arguments:

  • userkey: the unique userkey of the user to update.
  • body: object containing fields to update on the user and their new values.
  • fields (optional): fields to return in the response.
  • callback (optional): function of the form callback(error, body) to call when the response is received.

UserProvisioning.update(userkey, body[, fields, callback])

Same as patch, but updates a user without using patch semantics.

UserProvisioning.delete(userkey[, callback])

Deletes a user. Accepts arguments:

  • userkey: the unique userkey of the user to delete.
  • callback (optional): function of the form callback(error, body) to call when the response is received.