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

@mybus/ticketing

v1.1.57

Published

[![Version](https://img.shields.io/npm/v/@mybus/ticketing?style=flat&colorA=FFA500&colorB=FFA500)](https://www.npmjs.com/package/@mybus/ticketing)

Downloads

85

Readme

Version

@mybus/ticketing provides several utilities for managing tickets for a user of a Monkey Factory application, including:

List of ticketing interfaces. Ticket validation rules Conversion of a ticket to ASN1 (barcode) format

  • List of interfaces of the ticketing part,
  • Rules for validating a ticket,
  • QrCode generation,
  • Conversion of a ticket to ASN1 format (barcode),
  • Information about the validity of a ticket at a given time

Validation Rules

When validating a ticket, it will go through several rules (functions that return a Boolean). Only if all rules are correctly passed will the ticket be considered valid.

AllowedNetwork(ticket: Ticket): boolean

Is the ticket being validated in a network where it can be used?

EnabledTicket(ticket: Ticket): boolean

Is the ticket enabled?

PassengerCount(ticket: Ticket): boolean

Does the ticket have the correct number of passengers? A ticket may not have any associated passengers. However, if it does, it must ensure that this does not exceed the allowed limit.

UserAge(ticket: Ticket): boolean

Does the user who wants to use the ticket have the required age?

UserId(ticket: Ticket): boolean

Is the user one of the passengers on the ticket?

UserProfiles(ticket: Ticket): boolean

Does the user have the correct profiles (e.g. "mulhouse:-26ans") to use this ticket?

ValidDate(ticket: Ticket): boolean

Is the ticket still valid (not expired) and still validatable?

ValidationCount(ticket: Ticket): boolean

Has the ticket reached its maximum number of possible validations?

ValidationDelay(ticket: Ticket): boolean

Has the ticket completed its last validation?


It is possible to use each rule independently.

AllowedTransfer(ticket: Ticket): boolean

Is not part of the validation rules but can be called to check if a ticket can be transferred or not.

Example for using the UserId rule independently:

import { UserId } from '@mybus/ticketing';

new UserId().validate(ticket, { userId: '9a8ab5c8-9f27-441e-bc96-3095fae38e0a' });

Getting ticket status

It is possible to request information about a ticket in use.

getTicketInformation(ticket: TicketDto): Information

/*
 * Returns
 * state: under validation, invalid, expired, ...
 * expireAt: date when the ticket will expire
 * countdown?: time remaining (in seconds) before expiration
 */

To only get the state of the ticket,

/*
 * returns: `UNDER_VALIDATION | COMPLETED | UNCOMPOSTED | COMING_SOON`
 */
getTicketState(ticket, validation?): TicketState`

Générer un QrCode pour un ticket

getQrCode(ticket: TicketDto): QrCodeOutput

/*
 * Returns
 * origin: QrCodeOrigin
 * internal?: QrCodeInternal
 * external?: QrCodeExternal
 */

ASN1 conversion

convertTicketToHex(ticket: Ticket): string

Returns a hexadecimal string representing the ticket in ASN1 format.

convertHexToTicketId(uicBarCodeHex: string): string | null

Provides the inverse transformation.

Testing rules

All unit tests in this library are done on the same date (the date is mocked with Jest). The arbitrarily chosen date is Friday, September 30, 2022 at 4:33 PM. All tickets used in tests from test.config.ts are generated around this date. In other words, when you are running tests, you should consider yourself at this date and modify the dates of tickets and validations accordingly.