1.1.57 • Published 4 months ago

@mybus/ticketing v1.1.57

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 months ago

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.

1.1.56

4 months ago

1.1.55

4 months ago

1.1.57

4 months ago

1.1.52

4 months ago

1.1.54

4 months ago

1.1.53

4 months ago

1.1.49

4 months ago

1.1.51

4 months ago

1.1.50

4 months ago

1.1.48

4 months ago

1.1.44

10 months ago

1.1.43

10 months ago

1.1.46

6 months ago

1.1.39

12 months ago

1.1.40

11 months ago

1.1.42

11 months ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.36

1 year ago

1.1.34

1 year ago

1.1.35

1 year ago

1.1.30

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.25

2 years ago

1.1.15

2 years ago

1.1.17

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago