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

@aerogear/unifiedpush-admin-client

v4.5.0

Published

Client library used to admin UPS with code

Downloads

532

Readme

UnifiedPush Server Admin Client

Build Coverage Status Codacy Badge

The UnifiedPush Server Admin library allows to admin the UPS by javascript or typescript code.

Supported features are:

Applications

  • create: allows to create an application initialised with all the provided properties
  • delete: allows to delete all the applications matching given criteria
  • update: allows to update a given application
  • search: allows to search for all the applications matching given criteria

Variants

  • create: allows to create a variant initialised with all the specified properties
  • delete: allows to delete all the variants matching given criteria
  • update: allows to update a given variant
  • search: allows to search for all the variants matching given criteria
  • renew secret: allows to renew the secret of a given variant

Getting started

Cloning the repository

git clone https://github.com/aerogear/unifiedpush-admin-client.git
cd unifiedpush-admin-client

Compiling the code

npm run compile

Running the tests

npm run test

Using the library

The entry point of the library is the UpsAdminClient class. Its constructor takes two arguments:

  1. serverURL: The URL of the UnifiedPushServer. The url must be complete of protocol and port.
    Example:
    http://localhost:9999
  2. credentials: This parameter is be used to authenticate before trying to call the UPS REST endpoints. Two types of credentials can be specified:
    • Basic: this is just username/password used for basic authentication
    • Keycloak: this is composed of username/password, realm, client_id and keycloak URL. Optionally, if you already have a valid bearer token, it can be specified here, so that the library won't try to authenticate again.

Example without credentials:

const upsadm = new UpsAdminClient('http://localhosrt:9999');

Example with basic authentication:

const upsadm = new UpsAdminClient('http://localhosrt:9999', 
        {username: 'username', password: 'password', type: 'basic'});

Example with keycloak authentication:

const upsadm = new UpsAdminClient('http://localhosrt:9999', 
        {
          kcUrl: 'http://172.18.0.2:8080',
          username: 'username',
          password: 'password',
          type: 'keycloak',
        });

You will notice that we didn't specify values for client_id and realm: they will default to unified-push-server-js and aerogear accordingly.

Managing applications

All the methods to be used to manage applications can be found inside the applications namespace. To get the list of the applications, we will use

const searchResult = await upsadm.applications.search().execute();
console.log(`Total number of applications: ${searchResult.total}`);
console.log('Applications:', searchResult.list)

The search provides a fluid interface that allows to filter the results. For example, to search all the applications named 'TEST' we can do:

const searchResult = await upsadm.applications.search()
    .withName('TEST')
    .execute();

More than one filter can be specified.

WARNING The result is returned one page at a time. Each page will contain 10 applications. To specify which page to return, the page parameter must be specified:

const searchResult = await upsadm.applications.search()
    .withName('TEST')
    .page(3)
    .execute();

The returned value will be a dictionary containing the following keys:

  • total: the total number of apps that match the given filter
  • list: the current result page

To create an application we will use the create method:

const app = await upsadm.applications.create('newApp').execute();

The returned app object will have all the id and pushApplicationId fields populated by the server.

To update an application we will use the update method:

const apps = await upsadm.applications.update(appId)
    .withName('newName')
    .execute();

Managing variants

All the methods to be used to manage variants can be found inside the variants namespace. To get the list of the variants, we will use

const apps = await upsadm.variants.search(appId).execute();

where appId is the id of the application owning the variants.

The search command provides a fluent interface that can be used to add filters to the search:

const apps = await upsadm.variants.search(appId)
    .withName('my variant')
    .execute();

NOTE You are not limited to use only one filter: if you specify more than one, they will be all applied. The only exception is the id filter: if specified, all the other filters will be ignored.

To create a variant we will use the create method:

const variant = upsadm.variants.android.
    create(appId)
    .withName('MyNewVariant')
    .withGoogleKey('googleKey')
    .withProjectNumber('12345')
    .execute();

The returned variant object will have all the pushApplicationID field populated by the server.

To delete variants, we will use the delete method:

const apps = upsadm.variants.delete(appId).execute();

If you don't want to delete all the variants, you can decide what to delete by using the fluent interface:

const apps = upsadm.variants.delete(appId)
    .withName('apptodelete')
    .execute();

If you want to work on variants of a specified type, you can use the scoped version of the delete method:

const apps = upsadm.variants.android.delete(appId)
    .withName('apptodelete')
    .execute();