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

bitbucket-connect

v0.4.4

Published

Helpers for building add-ons using Bitbucket Connect

Downloads

23

Readme

bitbucket-connect

Get started building Bitbucket Connect add-ons with the bitbucket-connect scaffolding tool.

Prerequisites

  1. Install ngrok and configure it to serve port 3000 (ngrok 3000)

Quick start

npm install -g bitbucket-connect

Generate scaffolding for your project:

bbconnect

Install your project's dependencies and create a test database:

cd <project dir>
npm install
npm run migrate

Run your app using your ngrok URL and OAuth consumer key:

CONNECT_BASE_URL=<ngrok url> npm run start

Registering a Connect module

You'll want to configure your add-on so that you can start displaying custom content inside of Bitbucket. First create a new file to serve as the template at server/views/hello.jade with the following contents:

extends base.jade

block content
  p #{message}

Now let's open server/routes.js and add a route handler to serve some content:

export function helloWorld(req, res) {
  res.render('hello', { message: 'Hello, world!' });
}

Next, let's open server/addon.js and register a web panel, binding it to our route handler we just added.

First, import the new route handler you just created:

import { helloWorld } from './routes';

Then, register your web panel just before the export default addon; line:

addon.registerWebPanelRoute('/hello-world', {
  location: Addon.WebPanelLocations.REPOSITORY_OVERVIEW_INFORMATION_PANEL,
}, helloWorld);

That's it! With these small additions to your add-on, you're now able to display custom content on the overview page for any repository owned by users of your add-on.

Installing your add-on

Let's install your add-on by going to Bitbucket, clicking our avatar in the top-right, selecting Bitbucket settings, then selecting Manage add-ons in the left sidebar and clicking Install add-on from URL.

Your add-on's descriptor is located at <ngrok url>/descriptor.json. Enter the descriptor URL in the text field and click "Install". You will be prompted to grant the add-on access to your account. Once granted, the add-on will be installed.

Go to the overview of one of your repositories to see your add-on in action!

HTTP client

It is possible to make server-side calls back to the Bitbucket API. First, in addon.js pass the addon to a handler factory function...

addon.registerFileViewsRoute(
  '/fileView?repoUuid={repo_uuid}&fileCset={file_cset}&filePath={file_path}',
  {...},
  createFileViewHandler(addon)
);

Then in routes.js define that handler factory method with API calls back to bitbucket...

export function createFileViewHandler(addon) {
  return (req, res) => {
    const httpClient = req.createHttpClient(addon);
    const { repoUuid, fileCset, filePath } = req.query;
    const url = `/api/1.0/repositories/{}/${repoUuid}/raw/${fileCset}/${filePath}`;
    httpClient.get(url).then(apiRes => {
      const content = transformRawSource(apiRes.data);
      res.render('base', { content });
    });
  };
}

API

Addon class

constructor(props[, options])

Create an instance of a Bitbucket Connect add-on

  • props (Object) - Connect descriptor properties
  • [options] (Object) - Options hash for add-on instance
    • options.logger (Function) - Custom logger function

registerContexts(contexts)

Validate and add contexts to add-on descriptor

  • contexts (Array) - Array of contexts to be added

Returns the current add-on instance

registerScopes(scopes)

Validate and add API scopes to add-on descriptor

  • scopes (Array) - Array of API scopes to be added

Returns the current add-on instance

registerLifecycle(lifecycle, url)

Validate and add a lifecycle hook to add-on descriptor

  • lifecycle (string) - Lifecycle hook name to be added
  • url (string) - URL the lifecycle hook should POST to

Returns the current add-on instance

registerModule(type, props)

Validate and add a module definition to add-on descriptor

This method is primarily used to assist other proxy methods in registering different types of modules

  • type (string) - Type of module being registered (webItem, repoPage, etc.)
  • props (Object) - Properties of module, as defined by Connect spec

Returns the current add-on instance

registerAdminPage(props)

Validate and add adminPage to add-on descriptor

  • props (Object) - Properties of adminPage, as defined by Connect spec

Returns the current add-on instance

registerConfigurePage(props)

Validate and add configurePage to add-on descriptor

  • props (Object) - Properties of configurePage, as defined by Connect spec

Returns the current add-on instance

registerFileViews(props)

Validate and add fileViews to add-on descriptor

  • props (Object) - Properties of fileViews, as defined by Connect spec

Returns the current add-on instance

registerOauthConsumer(props)

Validate and add oauthConsumer to add-on descriptor

  • props (Object) - Properties of oauthConsumer, as defined by Connect spec

Returns the current add-on instance

registerProfileTab(props)

Validate and add profileTab to add-on descriptor

  • props (Object) - Properties of profileTab, as defined by Connect spec

Returns the current add-on instance

registerRepoPage(props)

Validate and add repoPage to add-on descriptor

  • props (Object) - Properties of repoPage, as defined by Connect spec

Returns the current add-on instance

registerWebItem(props)

Validate and add webItem to add-on descriptor

  • props (Object) - Properties of webItem, as defined by Connect spec

Returns the current add-on instance

registerWebPanel(props)

Validate and add webPanel to add-on descriptor

  • props (Object) - Properties of webPanel, as defined by Connect spec

Returns the current add-on instance

registerWebhooks(props)

Validate and add webhooks to add-on descriptor

  • props (Object) - Properties of webhooks, as defined by Connect spec

Returns the current add-on instance

log(msg)

Log message through either custom logger (if defined) or console.log

  • msg (string) - Message to log

Returns the current add-on instance

get(key)

Get property value from add-on descriptor

  • key (string) - The key of the property to fetch

Returns the value of the requested property

set(key, value)

Set property value on add-on descriptor

  • key (string) - The key of the property to set
  • value (*) - the value of the property to set

Returns the current add-on instance

ExpressAddon class

Class representing an Express Bitbucket Connect add-on

The primary purpose of this class is to define an API for binding Connect modules to Express route handlers

constructor(props[, options])

Create an instance of an Express Bitbucket Connect add-on

  • props (Object) - Connect descriptor properties
  • [options] (Object) - Options hash for Express Bitbucket Connect add-on
    • options.logger (Function) - Custom logger function
    • options.routerBaseUrl (string) - The add-on's mount point in your Express app
    • options.middleware (Array) - Array of Express middleware for authenticated routes

registerLifecycleRoute(url, lifecycle, ...handlers)

Bind lifecycle hook to Express route handler

  • url (string) - Express URL for lifecycle hook to POST to
  • lifecycle (string) - Name of lifecycle hook, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that receive hook

Returns the current add-on instance

registerAdminPageRoute(url, props, ...handlers)

Bind adminPage module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of adminPage, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerConfigurePageRoute(url, props, ...handlers)

Bind configurePage module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of configurePage, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerFileViewsRoute(url, props, ...handlers)

Bind fileViews module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of fileViews, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerProfileTabRoute(url, props, ...handlers)

Bind profileTab module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of profileTab, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerRepoPageRoute(url, props, ...handlers)

Bind repoPage module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of repoPage, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerWebItemRoute(url, props, ...handlers)

Bind webItem module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of webItem, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerWebPanelRoute(url, props, ...handlers)

Bind webPanel module to Express route handler

  • url (string) - Express URL for module
  • props (Object) - Properties of webPanel, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that serve module

Returns the current add-on instance

registerWebhooksRoute(url, props, ...handlers)

Bind webhooks module to Express route handler

  • url (string) - Express URL for hook to POST to
  • props (Object) - Properties of webhooks, as defined by Connect spec
  • ...handlers (Function) - Express route handlers that receive the hook

Returns the current add-on instance

generateModuleProps(url, props[, keyPrefix])

Generate module properties object with auto-generated URL and key values based on arguments

  • url (string) - Express URL pattern
  • props (Object) - Connect module properties
  • [keyPrefix] (string) - Prefix for module keys in Connect descriptor

Returns the generated set of properties for the Connect module

validateJwtToken middleware

Express middleware generator used to validate JWT token

  • getSharedSecret (Function) - Promise-returning function to retrieve shared secret. Accepts client key as its only argument.

Returns Express middleware function