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

osb-node

v0.1.3

Published

OSB nodejs module

Downloads

24

Readme

atlassian / osb-node

Overview

A node library to implement an OSB broker which can register multiple OSB services

OSB Classes

  • api/OSB.js: broker class which allow clients to register OSB services.
    • app - REQUIRED: express app
    • osbPath - REQUIRED: base path for OSB endpoints
    • contextBuilder - OPTIONAL: function to build context for each requests
  • api/OSBService: represent an OSB service which handle OSB requests. Each OSBService needs to implement below functions to handle OSB requests for the service.
    • getServiceInfo: return service info
    • provisionServiceInstance: async function to provision service instance
    • updateServiceInstance: async function to update service instance
    • deprovisionServiceInstance: async function to deprovision service instance
    • bindService: async function to bind service
    • unbindService: async function to unbind service
    • pollLastOperation: async function to get last operation status
    • Each function must return in format:
{ 
  statusCode: 'the-http-status-code',
  data: 'the response'
}
  • api/model/*: model classes represent OSB responses
  • api/model/request/*: model classes represent OSB request params

Example usages

Create a broker and register a service

const express = require('express');
const osbNode = require('osb-node');
const OSB = osbNode.OSB;
const OSBService = osbNode.OSBService;

const app = express();
const broker = new OSB(app, {osbPath: osbPath, contextBuilder: function(httpRequest){
	return {key: 'value};
});
broker.registerService(new OSBService({
  getServiceInfo,
  provisionServiceInstance,
  updateServiceInstance,
  deprovisionServiceInstance,
  bindService,
  unbindService,
  pollLastOperation
}));
broker.start();

Handle OSB requests of a service

Get servie info

const Plan = osbOnode.modelPlan;
const Schemas = osbOnode.modelSchemas;
const ServiceBindingSchema = osbOnode.modelServiceBindingSchema;
const Service = osbOnode.modelService;
const ServiceInstanceSchema = osbOnode.modelServiceInstanceSchema;

function getServiceInfo(request, context) {
  return new Service({
    name: 'service-a',
    id: 'service-id',
    description: 'service A',
    tags: ['tag', 'osb'],
    requires: ['route_forwarding'],
    bindable: true,
    metadata: {
      displayName: 'Service 1',
      provider: {
        name: 'provider name'
      }
    },
    dashboard_client: new DashboardClient({
      id: '7545b455-9cdb-41d2-abf3-3a4bae383a43',
      secret: '277cabb0-XXXX-XXXX-XXXX-7822c0a90e5d',
      redirect_uri: 'http://localhost:1234'
    }),
    plan_updateable: true,
    plans: [new Plan({
      id: 'ab3eb1db-26d7-429a-850a-daeb667e0530',
      name: 'plan-1',
      description: 'description',
      metadata: {
        max_storage_tb: 5,
        costs: [{
          amount: {
            usd: 99.0
          },
          unit: 'MONTHLY'
        }, {
          amount: {
            usd: 0.99
          },
          unit: '1GB of messages over 20GB'
        }],
        bullets: [
          'Shared fake server',
          '5 TB storage',
          '40 concurrent connections'
        ]
      },
      schemas: new Schemas({
        service_instance: new ServiceInstanceSchema({
          create: new InputParameters({
            parameters: {
              '$schema': 'http://json-schema.org/draft-04/schema#',
              'type': 'object',
              'billing-account': {
                description: 'Billing account number used to charge use of shared fake server.',
                type: 'string'
              }
            }
          }),
          update: new InputParameters({
            parameters: {
              '$schema': 'http://json-schema.org/draft-04/schema#',
              'type': 'object',
              'billing-account': {
                description: 'Billing account number used to charge use of shared fake server.',
                type: 'string'
              }
            }
          })
        }),
        service_binding: new ServiceBindingSchema({
          create: new InputParameters({
            parameters: {
              '$schema': 'http://json-schema.org/draft-04/schema#',
              'type': 'object',
              'billing-account': {
                description: 'Billing account number used to charge use of shared fake server.',
                type: 'string'
              }
            }
          })
        })
      })
    }, new Plan({
      id: '11f48b05-e3f3-4265-bdf7-6a0c58dbc9bf',
      name: 'plan-2',
      description: 'Shared fake Server, 5tb persistent disk, 40 max concurrent connections. 100 async',
      free: false,
      metadata: {
        max_storage_tb: 5,
        costs: [{
          amount: {
            usd: 199.0
          },
          unit: 'MONTHLY'
        }, {
          amount: {
            usd: 0.99
          },
          unit: '1GB of messages over 20GB'
        }],
        bullets: [
          '40 concurrent connections'
        ]
      }
    }))]
  });
}

Handle provision request

const ProvisionResponse = osbNode.model.ProvisionResponse;
function provisionServiceInstance(request, context) {
  return {
    statusCode: '200',
    data: new ProvisionResponse({dashboard_url: 'https://service-dashboard', operation: 'provision'});
  }
}

Last operation

const LastOperation = osbNode.model.LastOperation;
new LastOperation({state: 'in progress', description: 'provisioning instance'});

Broker error

const BrokerError = osbNode.model.BrokerError;
new BrokerError({error: 'invalid request', description: 'service id is required'});

More details are in test-app.js

Code of Conduct

Please see CODE_OF_CONDUCT.md

Contributing

Please see CONTRIBUTING.md

License

We license this project under the Apache License 2.0, as per our LICENSE.txt