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

bam-ticketing-sdk

v7.19.0

Published

SDK for B.A.M Ticketing API

Downloads

1,016

Readme

BAM Ticketing SDK

SDK library for B.A.M Ticketing API.

Installation

npm i bam-ticketing-sdk

Usage

Create the main service object:

import { BAM } from  'bam-ticketing-sdk';

// Production API by default

// For development, use new BAM('https://develop.bam.fan');
const bam = new BAM();

// Set the appropriate organizer name
// NOTE: This is not needed for `bam.account` and `bam.auth` calls
await bam.useOrganizer('org1');

// List all events with ticket configurations and occurrences
const events =  await bam.event
.listEvents({
	with: {
		ticket_config:  true,
		occurrence:  true
	}
});

// Get single event with all details (occurrences, timeslot, ticket configurations, discounts, ...)
const singleEvent =  await bam.event.getEvent({ id:  1234 })

// Create an order with 3 tickets
await bam.order.createOrder({
	format:  'PDF',
	orderItem: [{
		quantity:  3,
		ticketConfigId:  12345
	}]
});

Caching

Caching options can be provided when initializing the SDK. The full list of options is available at https://axios-cache-interceptor.js.org/config Below is a simple example of how to enable caching for the SDK with the time to live of 5 minutes. By default there is no caching.

import { BAM, BaseUrl } from  'bam-ticketing-sdk';

const sdk = await BAM.build({
	baseUrl: BaseUrl.Dev,
	cache:{
		ttl: 5 * 60 * 1000, // 5 minutes caching time
	}
})

Retries

Requests are retried 3 times by default. You can change the number of retries and the time to wait between retries by providing the retry option. The full list of options is available at https://www.npmjs.com/package/axios-retry

import { BAM, BaseUrl } from  'bam-ticketing-sdk';

const sdk = await BAM.build({
	baseUrl: BaseUrl.Dev,
	retry: {
		retries: 5,
	}
})

Saving and loading the state

It is possible to save the state of the SDK and load it later. For example, when using the SDK in the browser, you could put the serialized state in the local storage and load it when the page is reloaded.

import { BAM, BaseUrl } from  'bam-ticketing-sdk';

const sdk = await BAM.build({
	baseUrl: BaseUrl.Dev,
})
// Do some operations with the SDK, set the authorization etc.

// Save the state
const state = sdk.serialize()

// Load the state
const sdk2 = await BAM.build(state)

Validators/Check-in application

How to initialize the SDK for a validator application: First, if you have the payload from the QR code, you can extract the required data from it.

import { extractAccessDataFromValidatorQrCode } from  'bam-ticketing-sdk';

const qrCodeContent =
	'{"url":"https://develop.bam.fan/account/v1/organizer/validator/c0ffeef2-b836-4a0f-9555-eeb99c9c99fd","organizer":"dnd"}'
const data = extractAccessDataFromValidatorQrCode(qrCodeContent)
import { BAM, WalletCredentials } from  'bam-ticketing-sdk';

// This is a part of the validator data you get in the QR code when you go to the Dashboard/Assign validator on an event
// Or you can extract it from the QR code content, as shown above
const accessToken = 'c0ffeef2-b836-4a0f-9555-eeb99c9c99fd'
const baseUrl = 'https://develop.bam.fan' // Or simply BaseUrl.EnvironmentName, ie. BaseUrl.Dev

// Initialize the SDK
const sdk = await BAM.build({
	baseUrl,
})

const validator = await sdk.validator.getValidatorByToken({
	token: accessToken,
})
const credentials = new WalletCredentials(validator.wallet)

// After this, the SDK is ready to be used for privileged calls
await sdk.authorize(credentials, validator.organizer)

After you fetch the credentials and initialize the SDK, you can fetch the QR codes for the tickets:

// initialize the SDK before this
const ticketList = await sdk.event.getQrCodes({
	organizer_id: validator.organizer,
	id: validator.eventId,
})

// Tickets are grouped by categories and have a sub-object with their QR code content
const ticketQrCodes = ticketList
	.flatMap((ticketCategory) => ticketCategory.ticket)
	.map((ticket) => ticket.ticketQrCode.content)

Authentication

BAM Ticketing API uses JWT based authentication and authorization. The account/v1/auth/login is used for users (or services) with credentials, i.e. username and password.

BAM SDK uses a global method for any type of authentication with authorize. After calling this method, the internal HTTP client updates the authorization headers and successive calls will use the resolved JWT from BAM's API.

import { BAM } from  'bam-ticketing-sdk';
const bam = new BAM();

// Authorize with username and password
// Permissions are based on the account and are loaded into the instance
await bam.authorize({ username: 'admin', password: 'S3cr3t123' });

// Log in as guest user with a short-living guest JWT
await bam.authorize();

Reference

The BAM instance contains all properties and methods for authorization, users, events, orders and tickets.

Constructor

Create a new BAM instance.

new BAM(url: 'http://api.bam.fan', version: 'v1')

or

await BAM.build({baseUrl: 'http://api.bam.fan', version: 'v1' }) // Other options are available

Properties

| Property | Description | | -------------- | ------------------------------------------ | | account | User, organizer and account management | | auth | Authorization endpoints | | blockchain | Wallet signing operations | | event | Event management | | order | Order, order contact and ticket management | | payment | Payment providers operations | | venue | Venue information and search |

License

ISC