diff --git a/src/schemas/SemanticTagType.ts b/src/schemas/SemanticTagType.ts new file mode 100644 index 0000000..c060117 --- /dev/null +++ b/src/schemas/SemanticTagType.ts @@ -0,0 +1,147 @@ +import Joi from "joi"; +import { RGB_HEX_COLOR_REGEX } from "./regexps"; + +/** + * These couple of structures are organized alphabetically, + * according to the order on the developer documentation. + * + * @see https://developer.apple.com/documentation/walletpasses/semantictagtype + */ + +/** + * @see https://developer.apple.com/documentation/walletpasses/semantictagtype/currencyamount-data.dictionary + */ +export interface CurrencyAmount { + currencyCode?: string; // ISO 4217 currency code + amount?: string; +} + +export const CurrencyAmount = Joi.object().keys({ + currencyCode: Joi.string(), + amount: Joi.string(), +}); + +/** + * For newly-introduced event tickets + * in iOS 18. + * + * @see \ + */ + +export interface EventDateInfo { + date: string; + ignoreTimeComponents?: boolean; + timeZone?: string; +} + +export const EventDateInfo = Joi.object().keys({ + date: Joi.string().isoDate().required(), + ignoreTimeComponents: Joi.boolean(), + timeZone: Joi.string(), +}); + +/** + * @see https://developer.apple.com/documentation/walletpasses/semantictagtype/location-data.dictionary + */ +export interface Location { + latitude: number; + longitude: number; +} + +export const Location = Joi.object().keys({ + latitude: Joi.number().required(), + longitude: Joi.number().required(), +}); + +/** + * @see https://developer.apple.com/documentation/walletpasses/semantictagtype/personnamecomponents-data.dictionary + */ +export interface PersonNameComponents { + familyName?: string; + givenName?: string; + middleName?: string; + namePrefix?: string; + nameSuffix?: string; + nickname?: string; + phoneticRepresentation?: string; +} + +export const PersonNameComponents = Joi.object().keys({ + givenName: Joi.string(), + familyName: Joi.string(), + middleName: Joi.string(), + namePrefix: Joi.string(), + nameSuffix: Joi.string(), + nickname: Joi.string(), + phoneticRepresentation: Joi.string(), +}); + +/** + * @see https://developer.apple.com/documentation/walletpasses/semantictagtype/seat-data.dictionary + */ +export interface Seat { + seatSection?: string; + seatRow?: string; + seatNumber?: string; + seatIdentifier?: string; + seatType?: string; + seatDescription?: string; + + /** + * For newly-introduced event tickets + * in iOS 18 + */ + seatAisle?: string; + + /** + * For newly-introduced event tickets + * in iOS 18 + */ + seatLevel?: string; + + /** + * For newly-introduced event tickets + * in iOS 18 + */ + seatSectionColor?: string; +} + +export const Seat = Joi.object().keys({ + seatSection: Joi.string(), + seatRow: Joi.string(), + seatNumber: Joi.string(), + seatIdentifier: Joi.string(), + seatType: Joi.string(), + seatDescription: Joi.string(), + + /** + * Newly-introduced in iOS 18 + * Used in poster event tickets + */ + seatAisle: Joi.string(), + + /** + * Newly-introduced in iOS 18 + * Used in poster event tickets + */ + seatLevel: Joi.string(), + + /** + * For newly-introduced event tickets + * in iOS 18 + */ + seatSectionColor: Joi.string().regex(RGB_HEX_COLOR_REGEX), +}); + +/** + * @see https://developer.apple.com/documentation/walletpasses/semantictagtype/wifinetwork-data.dictionary + */ +export interface WifiNetwork { + password: string; + ssid: string; +} + +export const WifiNetwork = Joi.object().keys({ + password: Joi.string().required(), + ssid: Joi.string().required(), +}); diff --git a/src/schemas/Semantics.ts b/src/schemas/Semantics.ts index 4dd4b42..124ee28 100644 --- a/src/schemas/Semantics.ts +++ b/src/schemas/Semantics.ts @@ -1,5 +1,5 @@ import Joi from "joi"; -import { RGB_HEX_COLOR_REGEX } from "./regexps"; +import * as SemanticTagType from "./SemanticTagType"; /** * For a better description of every single field, @@ -8,134 +8,6 @@ import { RGB_HEX_COLOR_REGEX } from "./regexps"; * @see https://developer.apple.com/documentation/walletpasses/semantictags */ -/** - * @see https://developer.apple.com/documentation/walletpasses/semantictagtype - */ - -declare namespace SemanticTagType { - interface PersonNameComponents { - familyName?: string; - givenName?: string; - middleName?: string; - namePrefix?: string; - nameSuffix?: string; - nickname?: string; - phoneticRepresentation?: string; - } - - interface CurrencyAmount { - currencyCode?: string; // ISO 4217 currency code - amount?: string; - } - - interface Location { - latitude: number; - longitude: number; - } - - interface Seat { - seatSection?: string; - seatRow?: string; - seatNumber?: string; - seatIdentifier?: string; - seatType?: string; - seatDescription?: string; - - /** - * For newly-introduced event tickets - * in iOS 18 - */ - seatAisle?: string; - - /** - * For newly-introduced event tickets - * in iOS 18 - */ - seatLevel?: string; - - /** - * For newly-introduced event tickets - * in iOS 18 - */ - seatSectionColor?: string; - } - - /** - * For newly-introduced event tickets - * in iOS 18. - */ - - interface EventDateInfo { - date: string; - ignoreTimeComponents?: boolean; - timeZone?: string; - } - - interface WifiNetwork { - password: string; - ssid: string; - } -} - -const CurrencyAmount = Joi.object().keys({ - currencyCode: Joi.string(), - amount: Joi.string(), -}); - -const PersonNameComponent = - Joi.object().keys({ - givenName: Joi.string(), - familyName: Joi.string(), - middleName: Joi.string(), - namePrefix: Joi.string(), - nameSuffix: Joi.string(), - nickname: Joi.string(), - phoneticRepresentation: Joi.string(), - }); - -const EventDateInfo = Joi.object().keys({ - date: Joi.string().isoDate().required(), - ignoreTimeComponents: Joi.boolean(), - timeZone: Joi.string(), -}); - -const SeatSemantics = Joi.object().keys({ - seatSection: Joi.string(), - seatRow: Joi.string(), - seatNumber: Joi.string(), - seatIdentifier: Joi.string(), - seatType: Joi.string(), - seatDescription: Joi.string(), - - /** - * Newly-introduced in iOS 18 - * Used in poster event tickets - */ - seatAisle: Joi.string(), - - /** - * Newly-introduced in iOS 18 - * Used in poster event tickets - */ - seatLevel: Joi.string(), - - /** - * For newly-introduced event tickets - * in iOS 18 - */ - seatSectionColor: Joi.string().regex(RGB_HEX_COLOR_REGEX), -}); - -const LocationSemantics = Joi.object().keys({ - latitude: Joi.number().required(), - longitude: Joi.number().required(), -}); - -const WifiNetwork = Joi.object().keys({ - password: Joi.string().required(), - ssid: Joi.string().required(), -}); - /** * Alphabetical order * @see https://developer.apple.com/documentation/walletpasses/semantictags @@ -226,7 +98,7 @@ export interface Semantics { /** * For newly-introduced event tickets * in iOS 18 - * + * * Shows a message in the live activity * when the activity starts. */ @@ -418,7 +290,7 @@ export const Semantics = Joi.object().keys({ additionalTicketAttributes: Joi.string(), - balance: CurrencyAmount, + balance: SemanticTagType.CurrencyAmount, boardingGroup: Joi.string(), boardingSequenceNumber: Joi.string(), @@ -431,7 +303,7 @@ export const Semantics = Joi.object().keys({ departureAirportCode: Joi.string(), departureAirportName: Joi.string(), departureGate: Joi.string(), - departureLocation: LocationSemantics, + departureLocation: SemanticTagType.Location, departureLocationDescription: Joi.string(), departurePlatform: Joi.string(), departureStationName: Joi.string(), @@ -439,7 +311,7 @@ export const Semantics = Joi.object().keys({ destinationAirportCode: Joi.string(), destinationAirportName: Joi.string(), destinationGate: Joi.string(), - destinationLocation: LocationSemantics, + destinationLocation: SemanticTagType.Location, destinationLocationDescription: Joi.string(), destinationPlatform: Joi.string(), destinationStationName: Joi.string(), @@ -458,7 +330,7 @@ export const Semantics = Joi.object().keys({ /** * For newly-introduced event tickets * in iOS 18 - * + * * Shows a message in the live activity * when the activity starts. */ @@ -474,7 +346,7 @@ export const Semantics = Joi.object().keys({ * a way to show the event guide, both * instead of `eventStartDate`. */ - eventStartDateInfo: EventDateInfo, + eventStartDateInfo: SemanticTagType.EventDateInfo, eventStartDate: Joi.string(), eventType: Joi.string().regex( @@ -499,20 +371,20 @@ export const Semantics = Joi.object().keys({ originalBoardingDate: Joi.string(), originalDepartureDate: Joi.string(), - passengerName: PersonNameComponent, + passengerName: SemanticTagType.PersonNameComponents, performerNames: Joi.array().items(Joi.string()), priorityStatus: Joi.string(), playlistIDs: Joi.array().items(Joi.string()), - seats: Joi.array().items(SeatSemantics), + seats: Joi.array().items(SemanticTagType.Seat), securityScreening: Joi.string(), silenceRequested: Joi.boolean(), sportName: Joi.string(), tailgatingAllowed: Joi.boolean(), - totalPrice: CurrencyAmount, + totalPrice: SemanticTagType.CurrencyAmount, transitProvider: Joi.string(), transitStatus: Joi.string(), transitStatusReason: Joi.string(), @@ -529,7 +401,7 @@ export const Semantics = Joi.object().keys({ */ venueGatesOpenDate: Joi.string(), - venueLocation: LocationSemantics, + venueLocation: SemanticTagType.Location, venueName: Joi.string(), /** @@ -589,5 +461,5 @@ export const Semantics = Joi.object().keys({ */ venueEntrancePortal: Joi.string(), - wifiAccess: Joi.array().items(WifiNetwork), + wifiAccess: Joi.array().items(SemanticTagType.WifiNetwork), });